root / hw / ppc_chrp.c @ 36081602
History | View | Annotate | Download (20 kB)
1 | 64201201 | bellard | /*
|
---|---|---|---|
2 | 64201201 | bellard | * QEMU PPC CHRP/PMAC hardware System Emulator
|
3 | 5fafdf24 | ths | *
|
4 | 47103572 | j_mayer | * Copyright (c) 2004-2007 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 64201201 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 64201201 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 64201201 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 64201201 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 64201201 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 64201201 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 64201201 | bellard | *
|
13 | 64201201 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 64201201 | bellard | * all copies or substantial portions of the Software.
|
15 | 64201201 | bellard | *
|
16 | 64201201 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 64201201 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 64201201 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 64201201 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 64201201 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 64201201 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 64201201 | bellard | * THE SOFTWARE.
|
23 | 64201201 | bellard | */
|
24 | 64201201 | bellard | #include "vl.h" |
25 | 64201201 | bellard | |
26 | e9df014c | j_mayer | /* SMP is not enabled, for now */
|
27 | e9df014c | j_mayer | #define MAX_CPUS 1 |
28 | e9df014c | j_mayer | |
29 | 64201201 | bellard | #define BIOS_FILENAME "ppc_rom.bin" |
30 | d5295253 | bellard | #define VGABIOS_FILENAME "video.x" |
31 | 64201201 | bellard | #define NVRAM_SIZE 0x2000 |
32 | 64201201 | bellard | |
33 | b6b8bd18 | bellard | #define KERNEL_LOAD_ADDR 0x01000000 |
34 | b6b8bd18 | bellard | #define INITRD_LOAD_ADDR 0x01800000 |
35 | b6b8bd18 | bellard | |
36 | 267002cd | bellard | /* MacIO devices (mapped inside the MacIO address space): CUDA, DBDMA,
|
37 | e5733356 | bellard | NVRAM */
|
38 | 267002cd | bellard | |
39 | 267002cd | bellard | static int dbdma_mem_index; |
40 | 267002cd | bellard | static int cuda_mem_index; |
41 | 0aa6a4a2 | bellard | static int ide0_mem_index = -1; |
42 | 0aa6a4a2 | bellard | static int ide1_mem_index = -1; |
43 | 0aa6a4a2 | bellard | static int openpic_mem_index = -1; |
44 | 0aa6a4a2 | bellard | static int heathrow_pic_mem_index = -1; |
45 | e5733356 | bellard | static int macio_nvram_mem_index = -1; |
46 | 267002cd | bellard | |
47 | 267002cd | bellard | /* DBDMA: currently no op - should suffice right now */
|
48 | 267002cd | bellard | |
49 | 36081602 | j_mayer | static void dbdma_writeb (void *opaque, |
50 | 36081602 | j_mayer | target_phys_addr_t addr, uint32_t value) |
51 | 267002cd | bellard | { |
52 | e96efcfc | j_mayer | printf("%s: 0x" PADDRX " <= 0x%08x\n", __func__, addr, value); |
53 | 267002cd | bellard | } |
54 | 267002cd | bellard | |
55 | 36081602 | j_mayer | static void dbdma_writew (void *opaque, |
56 | 36081602 | j_mayer | target_phys_addr_t addr, uint32_t value) |
57 | 267002cd | bellard | { |
58 | 267002cd | bellard | } |
59 | 267002cd | bellard | |
60 | 36081602 | j_mayer | static void dbdma_writel (void *opaque, |
61 | 36081602 | j_mayer | target_phys_addr_t addr, uint32_t value) |
62 | 267002cd | bellard | { |
63 | 267002cd | bellard | } |
64 | 267002cd | bellard | |
65 | 267002cd | bellard | static uint32_t dbdma_readb (void *opaque, target_phys_addr_t addr) |
66 | 267002cd | bellard | { |
67 | e96efcfc | j_mayer | printf("%s: 0x" PADDRX " => 0x00000000\n", __func__, addr); |
68 | 36081602 | j_mayer | |
69 | 267002cd | bellard | return 0; |
70 | 267002cd | bellard | } |
71 | 267002cd | bellard | |
72 | 267002cd | bellard | static uint32_t dbdma_readw (void *opaque, target_phys_addr_t addr) |
73 | 267002cd | bellard | { |
74 | 267002cd | bellard | return 0; |
75 | 267002cd | bellard | } |
76 | 267002cd | bellard | |
77 | 267002cd | bellard | static uint32_t dbdma_readl (void *opaque, target_phys_addr_t addr) |
78 | 267002cd | bellard | { |
79 | 267002cd | bellard | return 0; |
80 | 267002cd | bellard | } |
81 | 267002cd | bellard | |
82 | 267002cd | bellard | static CPUWriteMemoryFunc *dbdma_write[] = {
|
83 | 267002cd | bellard | &dbdma_writeb, |
84 | 267002cd | bellard | &dbdma_writew, |
85 | 267002cd | bellard | &dbdma_writel, |
86 | 267002cd | bellard | }; |
87 | 267002cd | bellard | |
88 | 267002cd | bellard | static CPUReadMemoryFunc *dbdma_read[] = {
|
89 | 267002cd | bellard | &dbdma_readb, |
90 | 267002cd | bellard | &dbdma_readw, |
91 | 267002cd | bellard | &dbdma_readl, |
92 | 267002cd | bellard | }; |
93 | 267002cd | bellard | |
94 | e5733356 | bellard | /* macio style NVRAM device */
|
95 | e5733356 | bellard | typedef struct MacIONVRAMState { |
96 | e5733356 | bellard | uint8_t data[0x2000];
|
97 | e5733356 | bellard | } MacIONVRAMState; |
98 | e5733356 | bellard | |
99 | 36081602 | j_mayer | static void macio_nvram_writeb (void *opaque, |
100 | 36081602 | j_mayer | target_phys_addr_t addr, uint32_t value) |
101 | e5733356 | bellard | { |
102 | e5733356 | bellard | MacIONVRAMState *s = opaque; |
103 | e5733356 | bellard | addr = (addr >> 4) & 0x1fff; |
104 | e5733356 | bellard | s->data[addr] = value; |
105 | e5733356 | bellard | // printf("macio_nvram_writeb %04x = %02x\n", addr, value);
|
106 | e5733356 | bellard | } |
107 | e5733356 | bellard | |
108 | e5733356 | bellard | static uint32_t macio_nvram_readb (void *opaque, target_phys_addr_t addr) |
109 | e5733356 | bellard | { |
110 | e5733356 | bellard | MacIONVRAMState *s = opaque; |
111 | e5733356 | bellard | uint32_t value; |
112 | e5733356 | bellard | |
113 | e5733356 | bellard | addr = (addr >> 4) & 0x1fff; |
114 | e5733356 | bellard | value = s->data[addr]; |
115 | e5733356 | bellard | // printf("macio_nvram_readb %04x = %02x\n", addr, value);
|
116 | 36081602 | j_mayer | |
117 | e5733356 | bellard | return value;
|
118 | e5733356 | bellard | } |
119 | e5733356 | bellard | |
120 | e5733356 | bellard | static CPUWriteMemoryFunc *macio_nvram_write[] = {
|
121 | e5733356 | bellard | &macio_nvram_writeb, |
122 | e5733356 | bellard | &macio_nvram_writeb, |
123 | e5733356 | bellard | &macio_nvram_writeb, |
124 | e5733356 | bellard | }; |
125 | e5733356 | bellard | |
126 | e5733356 | bellard | static CPUReadMemoryFunc *macio_nvram_read[] = {
|
127 | e5733356 | bellard | &macio_nvram_readb, |
128 | e5733356 | bellard | &macio_nvram_readb, |
129 | e5733356 | bellard | &macio_nvram_readb, |
130 | e5733356 | bellard | }; |
131 | e5733356 | bellard | |
132 | 36081602 | j_mayer | static MacIONVRAMState *macio_nvram_init (void) |
133 | e5733356 | bellard | { |
134 | e5733356 | bellard | MacIONVRAMState *s; |
135 | e5733356 | bellard | s = qemu_mallocz(sizeof(MacIONVRAMState));
|
136 | e5733356 | bellard | if (!s)
|
137 | e5733356 | bellard | return NULL; |
138 | 5fafdf24 | ths | macio_nvram_mem_index = cpu_register_io_memory(0, macio_nvram_read,
|
139 | e5733356 | bellard | macio_nvram_write, s); |
140 | 36081602 | j_mayer | |
141 | e5733356 | bellard | return s;
|
142 | e5733356 | bellard | } |
143 | e5733356 | bellard | |
144 | 36081602 | j_mayer | static void macio_map (PCIDevice *pci_dev, int region_num, |
145 | 36081602 | j_mayer | uint32_t addr, uint32_t size, int type)
|
146 | 267002cd | bellard | { |
147 | 0aa6a4a2 | bellard | if (heathrow_pic_mem_index >= 0) { |
148 | 5fafdf24 | ths | cpu_register_physical_memory(addr + 0x00000, 0x1000, |
149 | 0aa6a4a2 | bellard | heathrow_pic_mem_index); |
150 | 0aa6a4a2 | bellard | } |
151 | 267002cd | bellard | cpu_register_physical_memory(addr + 0x08000, 0x1000, dbdma_mem_index); |
152 | 267002cd | bellard | cpu_register_physical_memory(addr + 0x16000, 0x2000, cuda_mem_index); |
153 | 0aa6a4a2 | bellard | if (ide0_mem_index >= 0) |
154 | 0aa6a4a2 | bellard | cpu_register_physical_memory(addr + 0x1f000, 0x1000, ide0_mem_index); |
155 | 0aa6a4a2 | bellard | if (ide1_mem_index >= 0) |
156 | 0aa6a4a2 | bellard | cpu_register_physical_memory(addr + 0x20000, 0x1000, ide1_mem_index); |
157 | 0aa6a4a2 | bellard | if (openpic_mem_index >= 0) { |
158 | 5fafdf24 | ths | cpu_register_physical_memory(addr + 0x40000, 0x40000, |
159 | 0aa6a4a2 | bellard | openpic_mem_index); |
160 | 0aa6a4a2 | bellard | } |
161 | e5733356 | bellard | if (macio_nvram_mem_index >= 0) |
162 | 36081602 | j_mayer | cpu_register_physical_memory(addr + 0x60000, 0x20000, |
163 | 36081602 | j_mayer | macio_nvram_mem_index); |
164 | 267002cd | bellard | } |
165 | 267002cd | bellard | |
166 | 36081602 | j_mayer | static void macio_init (PCIBus *bus, int device_id) |
167 | 267002cd | bellard | { |
168 | 267002cd | bellard | PCIDevice *d; |
169 | 267002cd | bellard | |
170 | 46e50e9d | bellard | d = pci_register_device(bus, "macio", sizeof(PCIDevice), |
171 | 46e50e9d | bellard | -1, NULL, NULL); |
172 | 267002cd | bellard | /* Note: this code is strongly inspirated from the corresponding code
|
173 | 267002cd | bellard | in PearPC */
|
174 | 267002cd | bellard | d->config[0x00] = 0x6b; // vendor_id |
175 | 267002cd | bellard | d->config[0x01] = 0x10; |
176 | e5733356 | bellard | d->config[0x02] = device_id;
|
177 | e5733356 | bellard | d->config[0x03] = device_id >> 8; |
178 | 267002cd | bellard | |
179 | 267002cd | bellard | d->config[0x0a] = 0x00; // class_sub = pci2pci |
180 | 267002cd | bellard | d->config[0x0b] = 0xff; // class_base = bridge |
181 | 267002cd | bellard | d->config[0x0e] = 0x00; // header_type |
182 | 267002cd | bellard | |
183 | 267002cd | bellard | d->config[0x3d] = 0x01; // interrupt on pin 1 |
184 | 3b46e624 | ths | |
185 | 267002cd | bellard | dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, NULL); |
186 | 267002cd | bellard | |
187 | 5fafdf24 | ths | pci_register_io_region(d, 0, 0x80000, |
188 | 267002cd | bellard | PCI_ADDRESS_SPACE_MEM, macio_map); |
189 | 267002cd | bellard | } |
190 | 267002cd | bellard | |
191 | 0aa6a4a2 | bellard | /* UniN device */
|
192 | 0aa6a4a2 | bellard | static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t value) |
193 | 0aa6a4a2 | bellard | { |
194 | 0aa6a4a2 | bellard | } |
195 | 0aa6a4a2 | bellard | |
196 | 0aa6a4a2 | bellard | static uint32_t unin_readl (void *opaque, target_phys_addr_t addr) |
197 | 0aa6a4a2 | bellard | { |
198 | 0aa6a4a2 | bellard | return 0; |
199 | 0aa6a4a2 | bellard | } |
200 | 0aa6a4a2 | bellard | |
201 | 0aa6a4a2 | bellard | static CPUWriteMemoryFunc *unin_write[] = {
|
202 | 0aa6a4a2 | bellard | &unin_writel, |
203 | 0aa6a4a2 | bellard | &unin_writel, |
204 | 0aa6a4a2 | bellard | &unin_writel, |
205 | 0aa6a4a2 | bellard | }; |
206 | 0aa6a4a2 | bellard | |
207 | 0aa6a4a2 | bellard | static CPUReadMemoryFunc *unin_read[] = {
|
208 | 0aa6a4a2 | bellard | &unin_readl, |
209 | 0aa6a4a2 | bellard | &unin_readl, |
210 | 0aa6a4a2 | bellard | &unin_readl, |
211 | 0aa6a4a2 | bellard | }; |
212 | 0aa6a4a2 | bellard | |
213 | 0aa6a4a2 | bellard | /* temporary frame buffer OSI calls for the video.x driver. The right
|
214 | 0aa6a4a2 | bellard | solution is to modify the driver to use VGA PCI I/Os */
|
215 | 36081602 | j_mayer | /* XXX: to be removed. This is no way related to emulation */
|
216 | 36081602 | j_mayer | static int vga_osi_call (CPUState *env) |
217 | 0aa6a4a2 | bellard | { |
218 | 0aa6a4a2 | bellard | static int vga_vbl_enabled; |
219 | 0aa6a4a2 | bellard | int linesize;
|
220 | 3b46e624 | ths | |
221 | 0aa6a4a2 | bellard | // printf("osi_call R5=%d\n", env->gpr[5]);
|
222 | 0aa6a4a2 | bellard | |
223 | 0aa6a4a2 | bellard | /* same handler as PearPC, coming from the original MOL video
|
224 | 0aa6a4a2 | bellard | driver. */
|
225 | 0aa6a4a2 | bellard | switch(env->gpr[5]) { |
226 | 0aa6a4a2 | bellard | case 4: |
227 | 0aa6a4a2 | bellard | break;
|
228 | 0aa6a4a2 | bellard | case 28: /* set_vmode */ |
229 | 0aa6a4a2 | bellard | if (env->gpr[6] != 1 || env->gpr[7] != 0) |
230 | 0aa6a4a2 | bellard | env->gpr[3] = 1; |
231 | 0aa6a4a2 | bellard | else
|
232 | 0aa6a4a2 | bellard | env->gpr[3] = 0; |
233 | 0aa6a4a2 | bellard | break;
|
234 | 0aa6a4a2 | bellard | case 29: /* get_vmode_info */ |
235 | 0aa6a4a2 | bellard | if (env->gpr[6] != 0) { |
236 | 0aa6a4a2 | bellard | if (env->gpr[6] != 1 || env->gpr[7] != 0) { |
237 | 0aa6a4a2 | bellard | env->gpr[3] = 1; |
238 | 0aa6a4a2 | bellard | break;
|
239 | 0aa6a4a2 | bellard | } |
240 | 0aa6a4a2 | bellard | } |
241 | 5fafdf24 | ths | env->gpr[3] = 0; |
242 | 0aa6a4a2 | bellard | env->gpr[4] = (1 << 16) | 1; /* num_vmodes, cur_vmode */ |
243 | 0aa6a4a2 | bellard | env->gpr[5] = (1 << 16) | 0; /* num_depths, cur_depth_mode */ |
244 | 0aa6a4a2 | bellard | env->gpr[6] = (graphic_width << 16) | graphic_height; /* w, h */ |
245 | 0aa6a4a2 | bellard | env->gpr[7] = 85 << 16; /* refresh rate */ |
246 | 0aa6a4a2 | bellard | env->gpr[8] = (graphic_depth + 7) & ~7; /* depth (round to byte) */ |
247 | 0aa6a4a2 | bellard | linesize = ((graphic_depth + 7) >> 3) * graphic_width; |
248 | 0aa6a4a2 | bellard | linesize = (linesize + 3) & ~3; |
249 | 0aa6a4a2 | bellard | env->gpr[9] = (linesize << 16) | 0; /* row_bytes, offset */ |
250 | 0aa6a4a2 | bellard | break;
|
251 | 0aa6a4a2 | bellard | case 31: /* set_video power */ |
252 | 0aa6a4a2 | bellard | env->gpr[3] = 0; |
253 | 0aa6a4a2 | bellard | break;
|
254 | 0aa6a4a2 | bellard | case 39: /* video_ctrl */ |
255 | 0aa6a4a2 | bellard | if (env->gpr[6] == 0 || env->gpr[6] == 1) |
256 | 0aa6a4a2 | bellard | vga_vbl_enabled = env->gpr[6];
|
257 | 0aa6a4a2 | bellard | env->gpr[3] = 0; |
258 | 0aa6a4a2 | bellard | break;
|
259 | 0aa6a4a2 | bellard | case 47: |
260 | 0aa6a4a2 | bellard | break;
|
261 | 0aa6a4a2 | bellard | case 59: /* set_color */ |
262 | 0aa6a4a2 | bellard | /* R6 = index, R7 = RGB */
|
263 | 0aa6a4a2 | bellard | env->gpr[3] = 0; |
264 | 0aa6a4a2 | bellard | break;
|
265 | 0aa6a4a2 | bellard | case 64: /* get color */ |
266 | 0aa6a4a2 | bellard | /* R6 = index */
|
267 | 5fafdf24 | ths | env->gpr[3] = 0; |
268 | 0aa6a4a2 | bellard | break;
|
269 | 0aa6a4a2 | bellard | case 116: /* set hwcursor */ |
270 | 0aa6a4a2 | bellard | /* R6 = x, R7 = y, R8 = visible, R9 = data */
|
271 | 0aa6a4a2 | bellard | break;
|
272 | 0aa6a4a2 | bellard | default:
|
273 | e96efcfc | j_mayer | fprintf(stderr, "unsupported OSI call R5=" REGX "\n", env->gpr[5]); |
274 | 0aa6a4a2 | bellard | break;
|
275 | 0aa6a4a2 | bellard | } |
276 | 36081602 | j_mayer | |
277 | 0aa6a4a2 | bellard | return 1; /* osi_call handled */ |
278 | 0aa6a4a2 | bellard | } |
279 | 0aa6a4a2 | bellard | |
280 | 36081602 | j_mayer | static uint8_t nvram_chksum (const uint8_t *buf, int n) |
281 | e5733356 | bellard | { |
282 | e5733356 | bellard | int sum, i;
|
283 | e5733356 | bellard | sum = 0;
|
284 | e5733356 | bellard | for(i = 0; i < n; i++) |
285 | e5733356 | bellard | sum += buf[i]; |
286 | e5733356 | bellard | return (sum & 0xff) + (sum >> 8); |
287 | e5733356 | bellard | } |
288 | e5733356 | bellard | |
289 | e5733356 | bellard | /* set a free Mac OS NVRAM partition */
|
290 | 36081602 | j_mayer | void pmac_format_nvram_partition (uint8_t *buf, int len) |
291 | e5733356 | bellard | { |
292 | e5733356 | bellard | char partition_name[12] = "wwwwwwwwwwww"; |
293 | 3b46e624 | ths | |
294 | e5733356 | bellard | buf[0] = 0x7f; /* free partition magic */ |
295 | e5733356 | bellard | buf[1] = 0; /* checksum */ |
296 | e5733356 | bellard | buf[2] = len >> 8; |
297 | e5733356 | bellard | buf[3] = len;
|
298 | e5733356 | bellard | memcpy(buf + 4, partition_name, 12); |
299 | e5733356 | bellard | buf[1] = nvram_chksum(buf, 16); |
300 | 3b46e624 | ths | } |
301 | e5733356 | bellard | |
302 | 0aa6a4a2 | bellard | /* PowerPC CHRP hardware initialisation */
|
303 | 94fc95cd | j_mayer | static void ppc_chrp_init (int ram_size, int vga_ram_size, int boot_device, |
304 | 94fc95cd | j_mayer | DisplayState *ds, const char **fd_filename, |
305 | 94fc95cd | j_mayer | int snapshot,
|
306 | 94fc95cd | j_mayer | const char *kernel_filename, |
307 | 94fc95cd | j_mayer | const char *kernel_cmdline, |
308 | 94fc95cd | j_mayer | const char *initrd_filename, |
309 | 94fc95cd | j_mayer | const char *cpu_model, |
310 | 94fc95cd | j_mayer | int is_heathrow)
|
311 | 64201201 | bellard | { |
312 | e9df014c | j_mayer | CPUState *env, *envs[MAX_CPUS]; |
313 | 64201201 | bellard | char buf[1024]; |
314 | e9df014c | j_mayer | qemu_irq *pic, **openpic_irqs; |
315 | 64201201 | bellard | m48t59_t *nvram; |
316 | aef445bd | pbrook | int unin_memory;
|
317 | d5295253 | bellard | int linux_boot, i;
|
318 | d5295253 | bellard | unsigned long bios_offset, vga_bios_offset; |
319 | b6b8bd18 | bellard | uint32_t kernel_base, kernel_size, initrd_base, initrd_size; |
320 | 3fc6c082 | bellard | ppc_def_t *def; |
321 | 46e50e9d | bellard | PCIBus *pci_bus; |
322 | 0aa6a4a2 | bellard | const char *arch_name; |
323 | d5295253 | bellard | int vga_bios_size, bios_size;
|
324 | d537cf6c | pbrook | qemu_irq *dummy_irq; |
325 | 46e50e9d | bellard | |
326 | 64201201 | bellard | linux_boot = (kernel_filename != NULL);
|
327 | 64201201 | bellard | |
328 | c68ea704 | bellard | /* init CPUs */
|
329 | c68ea704 | bellard | env = cpu_init(); |
330 | 0a032cbe | j_mayer | qemu_register_reset(&cpu_ppc_reset, env); |
331 | c68ea704 | bellard | register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); |
332 | c68ea704 | bellard | |
333 | 94fc95cd | j_mayer | /* Default CPU is a generic 74x/75x */
|
334 | 94fc95cd | j_mayer | if (cpu_model == NULL) |
335 | 94fc95cd | j_mayer | cpu_model = "750";
|
336 | c68ea704 | bellard | /* XXX: CPU model (or PVR) should be provided on command line */
|
337 | c68ea704 | bellard | // ppc_find_by_name("750gx", &def); // Linux boot OK
|
338 | c68ea704 | bellard | // ppc_find_by_name("750fx", &def); // Linux boot OK
|
339 | c68ea704 | bellard | /* Linux does not boot on 750cxe (and probably other 750cx based)
|
340 | c68ea704 | bellard | * because it assumes it has 8 IBAT & DBAT pairs as it only have 4.
|
341 | c68ea704 | bellard | */
|
342 | 94fc95cd | j_mayer | ppc_find_by_name(cpu_model, &def); |
343 | c68ea704 | bellard | if (def == NULL) { |
344 | c68ea704 | bellard | cpu_abort(env, "Unable to find PowerPC CPU definition\n");
|
345 | c68ea704 | bellard | } |
346 | e9df014c | j_mayer | for (i = 0; i < smp_cpus; i++) { |
347 | e9df014c | j_mayer | cpu_ppc_register(env, def); |
348 | e9df014c | j_mayer | /* Set time-base frequency to 100 Mhz */
|
349 | e9df014c | j_mayer | cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); |
350 | e9df014c | j_mayer | env->osi_call = vga_osi_call; |
351 | e9df014c | j_mayer | envs[i] = env; |
352 | e9df014c | j_mayer | } |
353 | c68ea704 | bellard | |
354 | 64201201 | bellard | /* allocate RAM */
|
355 | 64201201 | bellard | cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
|
356 | 64201201 | bellard | |
357 | 64201201 | bellard | /* allocate and load BIOS */
|
358 | 64201201 | bellard | bios_offset = ram_size + vga_ram_size; |
359 | 64201201 | bellard | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); |
360 | d5295253 | bellard | bios_size = load_image(buf, phys_ram_base + bios_offset); |
361 | d5295253 | bellard | if (bios_size < 0 || bios_size > BIOS_SIZE) { |
362 | 4a057712 | j_mayer | cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf);
|
363 | 64201201 | bellard | exit(1);
|
364 | 64201201 | bellard | } |
365 | d5295253 | bellard | bios_size = (bios_size + 0xfff) & ~0xfff; |
366 | 4a057712 | j_mayer | cpu_register_physical_memory((uint32_t)(-bios_size), |
367 | d5295253 | bellard | bios_size, bios_offset | IO_MEM_ROM); |
368 | 3b46e624 | ths | |
369 | d5295253 | bellard | /* allocate and load VGA BIOS */
|
370 | d5295253 | bellard | vga_bios_offset = bios_offset + bios_size; |
371 | d5295253 | bellard | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); |
372 | d5295253 | bellard | vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8);
|
373 | d5295253 | bellard | if (vga_bios_size < 0) { |
374 | d5295253 | bellard | /* if no bios is present, we can still work */
|
375 | d5295253 | bellard | fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf);
|
376 | d5295253 | bellard | vga_bios_size = 0;
|
377 | d5295253 | bellard | } else {
|
378 | d5295253 | bellard | /* set a specific header (XXX: find real Apple format for NDRV
|
379 | d5295253 | bellard | drivers) */
|
380 | d5295253 | bellard | phys_ram_base[vga_bios_offset] = 'N';
|
381 | d5295253 | bellard | phys_ram_base[vga_bios_offset + 1] = 'D'; |
382 | d5295253 | bellard | phys_ram_base[vga_bios_offset + 2] = 'R'; |
383 | d5295253 | bellard | phys_ram_base[vga_bios_offset + 3] = 'V'; |
384 | 5fafdf24 | ths | cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4),
|
385 | d5295253 | bellard | vga_bios_size); |
386 | d5295253 | bellard | vga_bios_size += 8;
|
387 | d5295253 | bellard | } |
388 | d5295253 | bellard | vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff; |
389 | 3b46e624 | ths | |
390 | b6b8bd18 | bellard | if (linux_boot) {
|
391 | b6b8bd18 | bellard | kernel_base = KERNEL_LOAD_ADDR; |
392 | b6b8bd18 | bellard | /* now we can load the kernel */
|
393 | b6b8bd18 | bellard | kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base); |
394 | b6b8bd18 | bellard | if (kernel_size < 0) { |
395 | 4a057712 | j_mayer | cpu_abort(env, "qemu: could not load kernel '%s'\n",
|
396 | 4a057712 | j_mayer | kernel_filename); |
397 | b6b8bd18 | bellard | exit(1);
|
398 | b6b8bd18 | bellard | } |
399 | b6b8bd18 | bellard | /* load initrd */
|
400 | b6b8bd18 | bellard | if (initrd_filename) {
|
401 | b6b8bd18 | bellard | initrd_base = INITRD_LOAD_ADDR; |
402 | b6b8bd18 | bellard | initrd_size = load_image(initrd_filename, |
403 | b6b8bd18 | bellard | phys_ram_base + initrd_base); |
404 | b6b8bd18 | bellard | if (initrd_size < 0) { |
405 | 4a057712 | j_mayer | cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
|
406 | 4a057712 | j_mayer | initrd_filename); |
407 | b6b8bd18 | bellard | exit(1);
|
408 | b6b8bd18 | bellard | } |
409 | b6b8bd18 | bellard | } else {
|
410 | b6b8bd18 | bellard | initrd_base = 0;
|
411 | b6b8bd18 | bellard | initrd_size = 0;
|
412 | b6b8bd18 | bellard | } |
413 | b6b8bd18 | bellard | boot_device = 'm';
|
414 | b6b8bd18 | bellard | } else {
|
415 | b6b8bd18 | bellard | kernel_base = 0;
|
416 | b6b8bd18 | bellard | kernel_size = 0;
|
417 | b6b8bd18 | bellard | initrd_base = 0;
|
418 | b6b8bd18 | bellard | initrd_size = 0;
|
419 | b6b8bd18 | bellard | } |
420 | 0aa6a4a2 | bellard | |
421 | 0aa6a4a2 | bellard | if (is_heathrow) {
|
422 | 0aa6a4a2 | bellard | isa_mem_base = 0x80000000;
|
423 | dd37a5e4 | j_mayer | |
424 | 0aa6a4a2 | bellard | /* Register 2 MB of ISA IO space */
|
425 | aef445bd | pbrook | isa_mmio_init(0xfe000000, 0x00200000); |
426 | aef445bd | pbrook | |
427 | 0aa6a4a2 | bellard | /* init basic PC hardware */
|
428 | dd37a5e4 | j_mayer | if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
|
429 | dd37a5e4 | j_mayer | cpu_abort(env, "Only 6xx bus is supported on heathrow machine\n");
|
430 | dd37a5e4 | j_mayer | exit(1);
|
431 | dd37a5e4 | j_mayer | } |
432 | 502a5395 | pbrook | pic = heathrow_pic_init(&heathrow_pic_mem_index); |
433 | 502a5395 | pbrook | pci_bus = pci_grackle_init(0xfec00000, pic);
|
434 | dd37a5e4 | j_mayer | pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, |
435 | 89b6b508 | bellard | ram_size, vga_ram_size, |
436 | 89b6b508 | bellard | vga_bios_offset, vga_bios_size); |
437 | 0aa6a4a2 | bellard | |
438 | 0aa6a4a2 | bellard | /* XXX: suppress that */
|
439 | d537cf6c | pbrook | dummy_irq = i8259_init(NULL);
|
440 | 3b46e624 | ths | |
441 | 0aa6a4a2 | bellard | /* XXX: use Mac Serial port */
|
442 | d537cf6c | pbrook | serial_init(0x3f8, dummy_irq[4], serial_hds[0]); |
443 | 3b46e624 | ths | |
444 | 0aa6a4a2 | bellard | for(i = 0; i < nb_nics; i++) { |
445 | a41b2ff2 | pbrook | if (!nd_table[i].model)
|
446 | a41b2ff2 | pbrook | nd_table[i].model = "ne2k_pci";
|
447 | abcebc7e | ths | pci_nic_init(pci_bus, &nd_table[i], -1);
|
448 | 0aa6a4a2 | bellard | } |
449 | 3b46e624 | ths | |
450 | 0aa6a4a2 | bellard | pci_cmd646_ide_init(pci_bus, &bs_table[0], 0); |
451 | 0aa6a4a2 | bellard | |
452 | 0aa6a4a2 | bellard | /* cuda also initialize ADB */
|
453 | d537cf6c | pbrook | cuda_mem_index = cuda_init(pic[0x12]);
|
454 | 3b46e624 | ths | |
455 | 0aa6a4a2 | bellard | adb_kbd_init(&adb_bus); |
456 | 0aa6a4a2 | bellard | adb_mouse_init(&adb_bus); |
457 | 3b46e624 | ths | |
458 | e5733356 | bellard | { |
459 | e5733356 | bellard | MacIONVRAMState *nvr; |
460 | e5733356 | bellard | nvr = macio_nvram_init(); |
461 | e5733356 | bellard | pmac_format_nvram_partition(nvr->data, 0x2000);
|
462 | e5733356 | bellard | } |
463 | e5733356 | bellard | |
464 | e5733356 | bellard | macio_init(pci_bus, 0x0017);
|
465 | 47103572 | j_mayer | |
466 | d537cf6c | pbrook | nvram = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59); |
467 | 47103572 | j_mayer | |
468 | 0aa6a4a2 | bellard | arch_name = "HEATHROW";
|
469 | 0aa6a4a2 | bellard | } else {
|
470 | 0aa6a4a2 | bellard | isa_mem_base = 0x80000000;
|
471 | 47103572 | j_mayer | |
472 | 0aa6a4a2 | bellard | /* Register 8 MB of ISA IO space */
|
473 | aef445bd | pbrook | isa_mmio_init(0xf2000000, 0x00800000); |
474 | 47103572 | j_mayer | |
475 | 0aa6a4a2 | bellard | /* UniN init */
|
476 | 0aa6a4a2 | bellard | unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL); |
477 | 0aa6a4a2 | bellard | cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory); |
478 | 0aa6a4a2 | bellard | |
479 | e9df014c | j_mayer | openpic_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *));
|
480 | e9df014c | j_mayer | openpic_irqs[0] =
|
481 | e9df014c | j_mayer | qemu_mallocz(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
|
482 | e9df014c | j_mayer | for (i = 0; i < smp_cpus; i++) { |
483 | e9df014c | j_mayer | /* Mac99 IRQ connection between OpenPIC outputs pins
|
484 | e9df014c | j_mayer | * and PowerPC input pins
|
485 | e9df014c | j_mayer | */
|
486 | dd37a5e4 | j_mayer | switch (PPC_INPUT(env)) {
|
487 | dd37a5e4 | j_mayer | case PPC_FLAGS_INPUT_6xx:
|
488 | dd37a5e4 | j_mayer | openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
|
489 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_INT] = |
490 | dd37a5e4 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; |
491 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_CINT] = |
492 | dd37a5e4 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]; |
493 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_MCK] = |
494 | dd37a5e4 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_MCP]; |
495 | dd37a5e4 | j_mayer | /* Not connected ? */
|
496 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL;
|
497 | dd37a5e4 | j_mayer | /* Check this */
|
498 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_RESET] = |
499 | dd37a5e4 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_HRESET]; |
500 | dd37a5e4 | j_mayer | break;
|
501 | dd37a5e4 | j_mayer | case PPC_FLAGS_INPUT_970:
|
502 | dd37a5e4 | j_mayer | openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
|
503 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_INT] = |
504 | dd37a5e4 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT]; |
505 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_CINT] = |
506 | dd37a5e4 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT]; |
507 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_MCK] = |
508 | dd37a5e4 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_MCP]; |
509 | dd37a5e4 | j_mayer | /* Not connected ? */
|
510 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL;
|
511 | dd37a5e4 | j_mayer | /* Check this */
|
512 | dd37a5e4 | j_mayer | openpic_irqs[i][OPENPIC_OUTPUT_RESET] = |
513 | dd37a5e4 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_HRESET]; |
514 | dd37a5e4 | j_mayer | break;
|
515 | dd37a5e4 | j_mayer | default:
|
516 | 36081602 | j_mayer | cpu_abort(env, "Bus model not supported on mac99 machine\n");
|
517 | dd37a5e4 | j_mayer | exit(1);
|
518 | dd37a5e4 | j_mayer | } |
519 | e9df014c | j_mayer | } |
520 | e9df014c | j_mayer | pic = openpic_init(NULL, &openpic_mem_index, smp_cpus,
|
521 | e9df014c | j_mayer | openpic_irqs, NULL);
|
522 | 502a5395 | pbrook | pci_bus = pci_pmac_init(pic); |
523 | 0aa6a4a2 | bellard | /* init basic PC hardware */
|
524 | 89b6b508 | bellard | pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, |
525 | 89b6b508 | bellard | ram_size, vga_ram_size, |
526 | 89b6b508 | bellard | vga_bios_offset, vga_bios_size); |
527 | 0aa6a4a2 | bellard | |
528 | 0aa6a4a2 | bellard | /* XXX: suppress that */
|
529 | d537cf6c | pbrook | dummy_irq = i8259_init(NULL);
|
530 | 3079c59a | j_mayer | |
531 | 0aa6a4a2 | bellard | /* XXX: use Mac Serial port */
|
532 | d537cf6c | pbrook | serial_init(0x3f8, dummy_irq[4], serial_hds[0]); |
533 | 0aa6a4a2 | bellard | for(i = 0; i < nb_nics; i++) { |
534 | 3079c59a | j_mayer | if (!nd_table[i].model)
|
535 | 3079c59a | j_mayer | nd_table[i].model = "ne2k_pci";
|
536 | 3079c59a | j_mayer | pci_nic_init(pci_bus, &nd_table[i], -1);
|
537 | 0aa6a4a2 | bellard | } |
538 | 0aa6a4a2 | bellard | #if 1 |
539 | d537cf6c | pbrook | ide0_mem_index = pmac_ide_init(&bs_table[0], pic[0x13]); |
540 | d537cf6c | pbrook | ide1_mem_index = pmac_ide_init(&bs_table[2], pic[0x14]); |
541 | 0aa6a4a2 | bellard | #else
|
542 | 0aa6a4a2 | bellard | pci_cmd646_ide_init(pci_bus, &bs_table[0], 0); |
543 | 0aa6a4a2 | bellard | #endif
|
544 | 0aa6a4a2 | bellard | /* cuda also initialize ADB */
|
545 | d537cf6c | pbrook | cuda_mem_index = cuda_init(pic[0x19]);
|
546 | 3b46e624 | ths | |
547 | 0aa6a4a2 | bellard | adb_kbd_init(&adb_bus); |
548 | 0aa6a4a2 | bellard | adb_mouse_init(&adb_bus); |
549 | 3b46e624 | ths | |
550 | e5733356 | bellard | macio_init(pci_bus, 0x0022);
|
551 | 3b46e624 | ths | |
552 | d537cf6c | pbrook | nvram = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59); |
553 | 3b46e624 | ths | |
554 | 0aa6a4a2 | bellard | arch_name = "MAC99";
|
555 | 64201201 | bellard | } |
556 | 0d92ed30 | pbrook | |
557 | 0d92ed30 | pbrook | if (usb_enabled) {
|
558 | e24ad6f1 | pbrook | usb_ohci_init_pci(pci_bus, 3, -1); |
559 | 0d92ed30 | pbrook | } |
560 | 0d92ed30 | pbrook | |
561 | b6b8bd18 | bellard | if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8) |
562 | b6b8bd18 | bellard | graphic_depth = 15;
|
563 | 64201201 | bellard | |
564 | 0aa6a4a2 | bellard | PPC_NVRAM_set_params(nvram, NVRAM_SIZE, arch_name, ram_size, boot_device, |
565 | b6b8bd18 | bellard | kernel_base, kernel_size, |
566 | b6b8bd18 | bellard | kernel_cmdline, |
567 | b6b8bd18 | bellard | initrd_base, initrd_size, |
568 | 64201201 | bellard | /* XXX: need an option to load a NVRAM image */
|
569 | b6b8bd18 | bellard | 0,
|
570 | b6b8bd18 | bellard | graphic_width, graphic_height, graphic_depth); |
571 | b6b8bd18 | bellard | /* No PCI init: the BIOS will do it */
|
572 | 0aa6a4a2 | bellard | |
573 | 0aa6a4a2 | bellard | /* Special port to get debug messages from Open-Firmware */
|
574 | 0aa6a4a2 | bellard | register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL); |
575 | 0aa6a4a2 | bellard | } |
576 | 0aa6a4a2 | bellard | |
577 | 94fc95cd | j_mayer | static void ppc_core99_init (int ram_size, int vga_ram_size, int boot_device, |
578 | 94fc95cd | j_mayer | DisplayState *ds, const char **fd_filename, |
579 | 94fc95cd | j_mayer | int snapshot,
|
580 | 94fc95cd | j_mayer | const char *kernel_filename, |
581 | 94fc95cd | j_mayer | const char *kernel_cmdline, |
582 | 94fc95cd | j_mayer | const char *initrd_filename, |
583 | 94fc95cd | j_mayer | const char *cpu_model) |
584 | 0aa6a4a2 | bellard | { |
585 | 0aa6a4a2 | bellard | ppc_chrp_init(ram_size, vga_ram_size, boot_device, |
586 | 0aa6a4a2 | bellard | ds, fd_filename, snapshot, |
587 | 0aa6a4a2 | bellard | kernel_filename, kernel_cmdline, |
588 | 94fc95cd | j_mayer | initrd_filename, cpu_model, 0);
|
589 | 64201201 | bellard | } |
590 | 3b46e624 | ths | |
591 | 94fc95cd | j_mayer | static void ppc_heathrow_init (int ram_size, int vga_ram_size, int boot_device, |
592 | 94fc95cd | j_mayer | DisplayState *ds, const char **fd_filename, |
593 | 94fc95cd | j_mayer | int snapshot,
|
594 | 94fc95cd | j_mayer | const char *kernel_filename, |
595 | 94fc95cd | j_mayer | const char *kernel_cmdline, |
596 | 94fc95cd | j_mayer | const char *initrd_filename, |
597 | 94fc95cd | j_mayer | const char *cpu_model) |
598 | 0aa6a4a2 | bellard | { |
599 | 0aa6a4a2 | bellard | ppc_chrp_init(ram_size, vga_ram_size, boot_device, |
600 | 0aa6a4a2 | bellard | ds, fd_filename, snapshot, |
601 | 0aa6a4a2 | bellard | kernel_filename, kernel_cmdline, |
602 | 94fc95cd | j_mayer | initrd_filename, cpu_model, 1);
|
603 | 0aa6a4a2 | bellard | } |
604 | 0aa6a4a2 | bellard | |
605 | 0aa6a4a2 | bellard | QEMUMachine core99_machine = { |
606 | 0289b2c1 | bellard | "mac99",
|
607 | 0289b2c1 | bellard | "Mac99 based PowerMAC",
|
608 | 0aa6a4a2 | bellard | ppc_core99_init, |
609 | 0aa6a4a2 | bellard | }; |
610 | 0aa6a4a2 | bellard | |
611 | 0aa6a4a2 | bellard | QEMUMachine heathrow_machine = { |
612 | 0289b2c1 | bellard | "g3bw",
|
613 | 0aa6a4a2 | bellard | "Heathrow based PowerMAC",
|
614 | 0aa6a4a2 | bellard | ppc_heathrow_init, |
615 | 0aa6a4a2 | bellard | }; |