1 |
/* |
2 |
* Copyright (C) 2005-2006 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 |
* $Id: machine_macppc.c,v 1.3 2006/02/02 19:30:14 debug Exp $ |
29 |
*/ |
30 |
|
31 |
#include <stdio.h> |
32 |
#include <string.h> |
33 |
|
34 |
#include "cpu.h" |
35 |
#include "device.h" |
36 |
#include "devices.h" |
37 |
#include "machine.h" |
38 |
#include "machine_interrupts.h" |
39 |
#include "memory.h" |
40 |
#include "misc.h" |
41 |
#include "of.h" |
42 |
|
43 |
|
44 |
MACHINE_SETUP(macppc) |
45 |
{ |
46 |
struct pci_data *pci_data; |
47 |
struct vfb_data *fb; |
48 |
uint64_t b, a; |
49 |
int i; |
50 |
|
51 |
/* |
52 |
* NetBSD/macppc (http://www.netbsd.org/Ports/macppc/) |
53 |
* OpenBSD/macppc (http://www.openbsd.org/macppc.html) |
54 |
*/ |
55 |
machine->machine_name = "Macintosh (PPC)"; |
56 |
if (machine->emulated_hz == 0) |
57 |
machine->emulated_hz = 40000000; |
58 |
|
59 |
machine->md_int.gc_data = dev_gc_init(machine, machine->memory, |
60 |
0xf3000000, 64); |
61 |
machine->md_interrupt = gc_interrupt; |
62 |
|
63 |
pci_data = dev_uninorth_init(machine, machine->memory, 0xe2000000, |
64 |
64 /* isa irq base */, 0 /* pci irq: TODO */); |
65 |
|
66 |
bus_pci_add(machine, pci_data, machine->memory, 0, 12, 0, "dec21143"); |
67 |
bus_pci_add(machine, pci_data, machine->memory, 0, 15, 0, "gc_obio"); |
68 |
|
69 |
if (machine->use_x11) |
70 |
bus_pci_add(machine, pci_data, machine->memory, 0, 16, 0, |
71 |
"ati_radeon_9200_2"); |
72 |
|
73 |
machine->main_console_handle = (size_t)device_add(machine, |
74 |
"z8530 addr=0xf3013000 irq=23 dma_irq=8 addr_mult=0x10"); |
75 |
|
76 |
fb = dev_fb_init(machine, machine->memory, 0xf1000000, |
77 |
VFB_GENERIC | VFB_REVERSE_START, 1024,768, 1024,768, 8, "ofb"); |
78 |
|
79 |
device_add(machine, "hammerhead addr=0xf2800000"); |
80 |
|
81 |
device_add(machine, "adb addr=0xf3016000 irq=1"); |
82 |
|
83 |
if (!machine->prom_emulation) |
84 |
return; |
85 |
|
86 |
|
87 |
b = 8 * 1048576; a = b - 0x800; |
88 |
|
89 |
of_emul_init(machine, fb, 0xf1000000, 1024, 768); |
90 |
of_emul_init_uninorth(machine); |
91 |
|
92 |
if (machine->use_x11) |
93 |
of_emul_init_adb(machine); |
94 |
else |
95 |
of_emul_init_zs(machine); |
96 |
|
97 |
/* |
98 |
* r3 = pointer to boot_args (for the Mach kernel). |
99 |
* See http://darwinsource.opendarwin.org/10.3/ |
100 |
* BootX-59/bootx.tproj/include.subproj/boot_args.h |
101 |
* for more info. |
102 |
*/ |
103 |
cpu->cd.ppc.gpr[3] = a; |
104 |
store_16bit_word(cpu, a + 0x0000, 1); /* revision */ |
105 |
store_16bit_word(cpu, a + 0x0002, 2); /* version */ |
106 |
store_buf(cpu, a + 0x0004, machine->boot_string_argument, 256); |
107 |
/* 26 dram banks; "long base; long size" */ |
108 |
store_32bit_word(cpu, a + 0x0104, 0); /* base */ |
109 |
store_32bit_word(cpu, a + 0x0108, machine->physical_ram_in_mb |
110 |
* 256); /* size (in pages) */ |
111 |
for (i=8; i<26*8; i+= 4) |
112 |
store_32bit_word(cpu, a + 0x0104 + i, 0); |
113 |
a += (0x104 + 26 * 8); |
114 |
/* Video info: */ |
115 |
store_32bit_word(cpu, a+0, 0xf1000000); /* video base */ |
116 |
store_32bit_word(cpu, a+4, 0); /* display code (?) */ |
117 |
store_32bit_word(cpu, a+8, 1024); /* bytes per pixel row */ |
118 |
store_32bit_word(cpu, a+12, 1024); /* width */ |
119 |
store_32bit_word(cpu, a+16, 768); /* height */ |
120 |
store_32bit_word(cpu, a+20, 8); /* pixel depth */ |
121 |
a += 24; |
122 |
store_32bit_word(cpu, a+0, 127); /* gestalt number (TODO) */ |
123 |
store_32bit_word(cpu, a+4, 0); /* device tree pointer (TODO)*/ |
124 |
store_32bit_word(cpu, a+8, 0); /* device tree length */ |
125 |
store_32bit_word(cpu, a+12, b); /* last address of kernel data area */ |
126 |
|
127 |
/* r4 = "MOSX" (0x4D4F5358) */ |
128 |
cpu->cd.ppc.gpr[4] = 0x4D4F5358; |
129 |
|
130 |
/* |
131 |
* r5 = OpenFirmware entry point. NOTE: See |
132 |
* cpu_ppc.c for the rest of this semi-ugly hack. |
133 |
*/ |
134 |
dev_ram_init(machine, cpu->cd.ppc.of_emul_addr, |
135 |
0x1000, DEV_RAM_RAM, 0x0); |
136 |
store_32bit_word(cpu, cpu->cd.ppc.of_emul_addr, |
137 |
0x44ee0002); |
138 |
cpu->cd.ppc.gpr[5] = cpu->cd.ppc.of_emul_addr; |
139 |
|
140 |
#if 0 |
141 |
/* r6 = args */ |
142 |
cpu->cd.ppc.gpr[1] -= 516; |
143 |
cpu->cd.ppc.gpr[6] = cpu->cd.ppc.gpr[1] + 4; |
144 |
store_string(cpu, cpu->cd.ppc.gpr[6], |
145 |
machine->boot_string_argument); |
146 |
/* should be something like '/controller/disk/bsd' */ |
147 |
|
148 |
/* r7 = length? TODO */ |
149 |
cpu->cd.ppc.gpr[7] = 5; |
150 |
#endif |
151 |
} |
152 |
|
153 |
|
154 |
MACHINE_DEFAULT_CPU(macppc) |
155 |
{ |
156 |
switch (machine->machine_subtype) { |
157 |
case MACHINE_MACPPC_G4: |
158 |
machine->cpu_name = strdup("PPC750"); |
159 |
break; |
160 |
case MACHINE_MACPPC_G5: |
161 |
machine->cpu_name = strdup("PPC970"); |
162 |
break; |
163 |
} |
164 |
} |
165 |
|
166 |
|
167 |
MACHINE_DEFAULT_RAM(macppc) |
168 |
{ |
169 |
machine->physical_ram_in_mb = 64; |
170 |
} |
171 |
|
172 |
|
173 |
MACHINE_REGISTER(macppc) |
174 |
{ |
175 |
MR_DEFAULT(macppc, "Macintosh", ARCH_PPC, MACHINE_MACPPC, 1, 2); |
176 |
me->aliases[0] = "macppc"; |
177 |
me->subtype[0] = machine_entry_subtype_new("MacPPC G4", |
178 |
MACHINE_MACPPC_G4, 1); |
179 |
me->subtype[0]->aliases[0] = "g4"; |
180 |
me->subtype[1] = machine_entry_subtype_new("MacPPC G5", |
181 |
MACHINE_MACPPC_G5, 1); |
182 |
me->subtype[1]->aliases[0] = "g5"; |
183 |
me->set_default_ram = machine_default_ram_macppc; |
184 |
machine_entry_add(me, ARCH_PPC); |
185 |
} |
186 |
|