machine_macppc.cc Source File

Back to the index.

machine_macppc.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2009 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * COMMENT: Generic PowerPC-based Macintosh machines
29  *
30  * See also:
31  *
32  * NetBSD/macppc (http://www.netbsd.org/ports/macppc/)
33  * OpenBSD/macppc (http://www.openbsd.org/macppc.html)
34  *
35  * Currently, these are skeletons for generic PowerMac G3, G4, and G5 systems.
36  * They do not model real PowerMacs, but should be enough to begin
37  * experimenting with running NetBSD/macppc and OpenBSD/macppc.
38  */
39 
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 
44 #include "bus_pci.h"
45 #include "cpu.h"
46 #include "device.h"
47 #include "devices.h"
48 #include "machine.h"
49 #include "memory.h"
50 #include "misc.h"
51 #include "of.h"
52 
53 
55 {
56  char tmpstr[300];
57  struct pci_data *pci_data;
58  struct vfb_data *fb;
59  uint64_t b, a;
60  int i;
61 
62  machine->machine_name = strdup("Macintosh (PPC)");
63  if (machine->emulated_hz == 0)
64  machine->emulated_hz = 40000000;
65 
66  device_add(machine, "gc addr=0xf3000000");
67 
68  pci_data = dev_uninorth_init(machine, machine->memory, 0xe2000000,
69  64 /* isa irq base */, 0 /* pci irq: TODO */);
70 
71  /* bus_pci_add(
72  machine, pci_data, machine->memory, 0, 12, 0, "dec21143"); */
73  bus_pci_add(machine, pci_data, machine->memory, 0, 15, 0, "gc_obio");
74 
75  if (machine->x11_md.in_use)
76  bus_pci_add(machine, pci_data, machine->memory, 0, 16, 0,
77  "ati_radeon_9200_2");
78 
79  snprintf(tmpstr, sizeof(tmpstr), "z8530 addr=0xf3013000 irq="
80  "%s.cpu[%i].gc.lo.23 addr_mult=0x10",
82  machine->main_console_handle = (size_t)device_add(machine, tmpstr);
83 
84  fb = dev_fb_init(machine, machine->memory, 0xf1000000,
85  VFB_GENERIC | VFB_REVERSE_START, 1024,768, 1024,768, 8, "ofb");
86 
87  device_add(machine, "hammerhead addr=0xf2800000");
88 
89  snprintf(tmpstr, sizeof(tmpstr), "adb addr=0xf3016000 irq="
90  "%s.cpu[%i].gc.lo.1", machine->path, machine->bootstrap_cpu);
91  device_add(machine, tmpstr);
92 
93  if (!machine->prom_emulation)
94  return;
95 
96 
97  b = 8 * 1048576; a = b - 0x800;
98 
99  of_emul_init(machine, fb, 0xf1000000, 1024, 768);
101 
102  if (machine->x11_md.in_use)
104  else
106 
107  /*
108  * r3 = pointer to boot_args (for the Mach kernel).
109  * See http://darwinsource.opendarwin.org/10.3/
110  * BootX-59/bootx.tproj/include.subproj/boot_args.h
111  * for more info.
112  */
113  cpu->cd.ppc.gpr[3] = a;
114  store_16bit_word(cpu, a + 0x0000, 1); /* revision */
115  store_16bit_word(cpu, a + 0x0002, 2); /* version */
116  store_buf(cpu, a + 0x0004, machine->boot_string_argument, 256);
117  /* 26 dram banks; "long base; long size" */
118  store_32bit_word(cpu, a + 0x0104, 0); /* base */
120  * 256); /* size (in pages) */
121  for (i=8; i<26*8; i+= 4)
122  store_32bit_word(cpu, a + 0x0104 + i, 0);
123  a += (0x104 + 26 * 8);
124  /* Video info: */
125  store_32bit_word(cpu, a+0, 0xf1000000); /* video base */
126  store_32bit_word(cpu, a+4, 0); /* display code (?) */
127  store_32bit_word(cpu, a+8, 1024); /* bytes per pixel row */
128  store_32bit_word(cpu, a+12, 1024); /* width */
129  store_32bit_word(cpu, a+16, 768); /* height */
130  store_32bit_word(cpu, a+20, 8); /* pixel depth */
131  a += 24;
132  store_32bit_word(cpu, a+0, 127); /* gestalt number (TODO) */
133  store_32bit_word(cpu, a+4, 0); /* device tree pointer (TODO)*/
134  store_32bit_word(cpu, a+8, 0); /* device tree length */
135  store_32bit_word(cpu, a+12, b); /* last address of kernel data area */
136 
137  /* r4 = "MOSX" (0x4D4F5358) */
138  cpu->cd.ppc.gpr[4] = 0x4D4F5358;
139 
140  /*
141  * r5 = OpenFirmware entry point. NOTE: See
142  * cpu_ppc.c for the rest of this semi-ugly hack.
143  */
145  0x1000, DEV_RAM_RAM, 0x0);
147  0x44ee0002);
148  cpu->cd.ppc.gpr[5] = cpu->cd.ppc.of_emul_addr;
149 
150 #if 0
151  /* r6 = args */
152  cpu->cd.ppc.gpr[1] -= 516;
153  cpu->cd.ppc.gpr[6] = cpu->cd.ppc.gpr[1] + 4;
154  store_string(cpu, cpu->cd.ppc.gpr[6],
156  /* should be something like '/controller/disk/bsd' */
157 
158  /* r7 = length? TODO */
159  cpu->cd.ppc.gpr[7] = 5;
160 #endif
161 }
162 
163 
165 {
166  switch (machine->machine_subtype) {
167  case MACHINE_MACPPC_G3:
168  machine->cpu_name = strdup("PPC750");
169  break;
170  case MACHINE_MACPPC_G4:
171  machine->cpu_name = strdup("MPC7400");
172  break;
173  case MACHINE_MACPPC_G5:
174  machine->cpu_name = strdup("PPC970");
175  break;
176  }
177 }
178 
179 
181 {
183 }
184 
185 
187 {
188  MR_DEFAULT(macppc, "Macintosh", ARCH_PPC, MACHINE_MACPPC);
189 
190  machine_entry_add_alias(me, "macppc");
191 
193  "g3", NULL);
194 
196  "g4", NULL);
197 
199  "g5", NULL);
200 
201  me->set_default_ram = machine_default_ram_macppc;
202 }
203 
int emulated_hz
Definition: machine.h:165
#define MACHINE_MACPPC_G3
Definition: machine.h:318
int prom_emulation
Definition: machine.h:149
char * cpu_name
Definition: machine.h:133
int main_console_handle
Definition: machine.h:128
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32)
Definition: memory.cc:783
#define ARCH_PPC
Definition: machine.h:204
#define DEV_RAM_RAM
Definition: devices.h:364
struct vfb_data * dev_fb_init(struct machine *machine, struct memory *mem, uint64_t baseaddr, int vfb_type, int visible_xsize, int visible_ysize, int xsize, int ysize, int bit_depth, const char *name)
Definition: dev_fb.cc:834
struct ppc_cpu ppc
Definition: cpu.h:444
union cpu::@1 cd
#define VFB_GENERIC
Definition: devices.h:190
void store_string(struct cpu *cpu, uint64_t addr, const char *s)
Definition: memory.cc:695
struct memory * memory
Definition: machine.h:126
void bus_pci_add(struct machine *machine, struct pci_data *pci_data, struct memory *mem, int bus, int device, int function, const char *name)
Definition: bus_pci.cc:217
#define MACHINE_MACPPC_G4
Definition: machine.h:319
void * device_add(struct machine *machine, const char *name_and_params)
Definition: device.cc:252
struct pci_data * dev_uninorth_init(struct machine *machine, struct memory *mem, uint64_t addr, int isa_irqbase, int pciirq)
int physical_ram_in_mb
Definition: machine.h:147
char * boot_string_argument
Definition: machine.h:171
char * path
Definition: machine.h:108
int bootstrap_cpu
Definition: machine.h:136
MACHINE_DEFAULT_RAM(macppc)
MACHINE_DEFAULT_CPU(macppc)
void dev_ram_init(struct machine *machine, uint64_t baseaddr, uint64_t length, int mode, uint64_t otheraddress, const char *name)
Definition: dev_ram.cc:134
uint64_t of_emul_addr
Definition: cpu_ppc.h:113
void machine_entry_add_subtype(struct machine_entry *me, const char *name, int oldstyle_subtype,...)
Definition: machine.cc:717
#define VFB_REVERSE_START
Definition: devices.h:197
void machine_entry_add_alias(struct machine_entry *me, const char *name)
Definition: machine.cc:697
void of_emul_init_adb(struct machine *)
Definition: of.cc:743
struct x11_md x11_md
Definition: machine.h:179
void of_emul_init_uninorth(struct machine *)
Definition: of.cc:839
Definition: cpu.h:326
struct of_data * of_emul_init(struct machine *machine, struct vfb_data *, uint64_t fb_addr, int fb_xsize, int fb_ysize)
Definition: of.cc:940
#define MACHINE_MACPPC_G5
Definition: machine.h:320
int in_use
Definition: machine.h:82
int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16)
Definition: memory.cc:807
MACHINE_SETUP(macppc)
void store_buf(struct cpu *cpu, uint64_t addr, const char *s, size_t len)
Definition: memory.cc:826
int machine_subtype
Definition: machine.h:112
MACHINE_REGISTER(macppc)
#define MR_DEFAULT(x, name, arch, type)
Definition: machine.h:370
const char * machine_name
Definition: machine.h:115
void of_emul_init_zs(struct machine *)
Definition: of.cc:775
uint64_t gpr[PPC_NGPRS]
Definition: cpu_ppc.h:124
#define MACHINE_MACPPC
Definition: machine.h:229

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13