]>
Commit | Line | Data |
---|---|---|
9a64fbe4 | 1 | /* |
a541f297 | 2 | * QEMU PPC PREP hardware System Emulator |
5fafdf24 | 3 | * |
47103572 | 4 | * Copyright (c) 2003-2007 Jocelyn Mayer |
5fafdf24 | 5 | * |
a541f297 FB |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
9a64fbe4 | 23 | */ |
9a64fbe4 | 24 | #include "vl.h" |
9fddaa0c | 25 | |
9a64fbe4 | 26 | //#define HARD_DEBUG_PPC_IO |
a541f297 | 27 | //#define DEBUG_PPC_IO |
9a64fbe4 | 28 | |
fe33cc71 JM |
29 | /* SMP is not enabled, for now */ |
30 | #define MAX_CPUS 1 | |
31 | ||
b6b8bd18 FB |
32 | #define BIOS_FILENAME "ppc_rom.bin" |
33 | #define KERNEL_LOAD_ADDR 0x01000000 | |
34 | #define INITRD_LOAD_ADDR 0x01800000 | |
64201201 | 35 | |
9a64fbe4 FB |
36 | extern int loglevel; |
37 | extern FILE *logfile; | |
38 | ||
39 | #if defined (HARD_DEBUG_PPC_IO) && !defined (DEBUG_PPC_IO) | |
40 | #define DEBUG_PPC_IO | |
41 | #endif | |
42 | ||
43 | #if defined (HARD_DEBUG_PPC_IO) | |
44 | #define PPC_IO_DPRINTF(fmt, args...) \ | |
45 | do { \ | |
b6b8bd18 | 46 | if (loglevel & CPU_LOG_IOPORT) { \ |
9a64fbe4 FB |
47 | fprintf(logfile, "%s: " fmt, __func__ , ##args); \ |
48 | } else { \ | |
49 | printf("%s : " fmt, __func__ , ##args); \ | |
50 | } \ | |
51 | } while (0) | |
52 | #elif defined (DEBUG_PPC_IO) | |
53 | #define PPC_IO_DPRINTF(fmt, args...) \ | |
54 | do { \ | |
b6b8bd18 | 55 | if (loglevel & CPU_LOG_IOPORT) { \ |
9a64fbe4 FB |
56 | fprintf(logfile, "%s: " fmt, __func__ , ##args); \ |
57 | } \ | |
58 | } while (0) | |
59 | #else | |
60 | #define PPC_IO_DPRINTF(fmt, args...) do { } while (0) | |
61 | #endif | |
62 | ||
64201201 | 63 | /* Constants for devices init */ |
a541f297 FB |
64 | static const int ide_iobase[2] = { 0x1f0, 0x170 }; |
65 | static const int ide_iobase2[2] = { 0x3f6, 0x376 }; | |
66 | static const int ide_irq[2] = { 13, 13 }; | |
67 | ||
68 | #define NE2000_NB_MAX 6 | |
69 | ||
70 | static uint32_t ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 }; | |
71 | static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 }; | |
9a64fbe4 | 72 | |
64201201 FB |
73 | //static PITState *pit; |
74 | ||
75 | /* ISA IO ports bridge */ | |
9a64fbe4 FB |
76 | #define PPC_IO_BASE 0x80000000 |
77 | ||
64201201 FB |
78 | /* Speaker port 0x61 */ |
79 | int speaker_data_on; | |
80 | int dummy_refresh_clock; | |
81 | ||
36081602 | 82 | static void speaker_ioport_write (void *opaque, uint32_t addr, uint32_t val) |
9a64fbe4 | 83 | { |
a541f297 | 84 | #if 0 |
64201201 FB |
85 | speaker_data_on = (val >> 1) & 1; |
86 | pit_set_gate(pit, 2, val & 1); | |
a541f297 | 87 | #endif |
9a64fbe4 FB |
88 | } |
89 | ||
47103572 | 90 | static uint32_t speaker_ioport_read (void *opaque, uint32_t addr) |
9a64fbe4 | 91 | { |
a541f297 | 92 | #if 0 |
64201201 FB |
93 | int out; |
94 | out = pit_get_out(pit, 2, qemu_get_clock(vm_clock)); | |
95 | dummy_refresh_clock ^= 1; | |
96 | return (speaker_data_on << 1) | pit_get_gate(pit, 2) | (out << 5) | | |
47103572 | 97 | (dummy_refresh_clock << 4); |
a541f297 | 98 | #endif |
64201201 | 99 | return 0; |
9a64fbe4 FB |
100 | } |
101 | ||
64201201 FB |
102 | /* PCI intack register */ |
103 | /* Read-only register (?) */ | |
47103572 JM |
104 | static void _PPC_intack_write (void *opaque, |
105 | target_phys_addr_t addr, uint32_t value) | |
64201201 FB |
106 | { |
107 | // printf("%s: 0x%08x => 0x%08x\n", __func__, addr, value); | |
108 | } | |
109 | ||
110 | static inline uint32_t _PPC_intack_read (target_phys_addr_t addr) | |
111 | { | |
112 | uint32_t retval = 0; | |
113 | ||
114 | if (addr == 0xBFFFFFF0) | |
3de388f6 | 115 | retval = pic_intack_read(isa_pic); |
36081602 | 116 | // printf("%s: 0x%08x <= %d\n", __func__, addr, retval); |
64201201 FB |
117 | |
118 | return retval; | |
119 | } | |
120 | ||
a4193c8a | 121 | static uint32_t PPC_intack_readb (void *opaque, target_phys_addr_t addr) |
64201201 FB |
122 | { |
123 | return _PPC_intack_read(addr); | |
124 | } | |
125 | ||
a4193c8a | 126 | static uint32_t PPC_intack_readw (void *opaque, target_phys_addr_t addr) |
9a64fbe4 | 127 | { |
f658b4db | 128 | #ifdef TARGET_WORDS_BIGENDIAN |
64201201 FB |
129 | return bswap16(_PPC_intack_read(addr)); |
130 | #else | |
131 | return _PPC_intack_read(addr); | |
f658b4db | 132 | #endif |
9a64fbe4 FB |
133 | } |
134 | ||
a4193c8a | 135 | static uint32_t PPC_intack_readl (void *opaque, target_phys_addr_t addr) |
9a64fbe4 | 136 | { |
f658b4db | 137 | #ifdef TARGET_WORDS_BIGENDIAN |
64201201 FB |
138 | return bswap32(_PPC_intack_read(addr)); |
139 | #else | |
140 | return _PPC_intack_read(addr); | |
f658b4db | 141 | #endif |
9a64fbe4 FB |
142 | } |
143 | ||
64201201 FB |
144 | static CPUWriteMemoryFunc *PPC_intack_write[] = { |
145 | &_PPC_intack_write, | |
146 | &_PPC_intack_write, | |
147 | &_PPC_intack_write, | |
148 | }; | |
149 | ||
150 | static CPUReadMemoryFunc *PPC_intack_read[] = { | |
151 | &PPC_intack_readb, | |
152 | &PPC_intack_readw, | |
153 | &PPC_intack_readl, | |
154 | }; | |
155 | ||
156 | /* PowerPC control and status registers */ | |
157 | #if 0 // Not used | |
158 | static struct { | |
159 | /* IDs */ | |
160 | uint32_t veni_devi; | |
161 | uint32_t revi; | |
162 | /* Control and status */ | |
163 | uint32_t gcsr; | |
164 | uint32_t xcfr; | |
165 | uint32_t ct32; | |
166 | uint32_t mcsr; | |
167 | /* General purpose registers */ | |
168 | uint32_t gprg[6]; | |
169 | /* Exceptions */ | |
170 | uint32_t feen; | |
171 | uint32_t fest; | |
172 | uint32_t fema; | |
173 | uint32_t fecl; | |
174 | uint32_t eeen; | |
175 | uint32_t eest; | |
176 | uint32_t eecl; | |
177 | uint32_t eeint; | |
178 | uint32_t eemck0; | |
179 | uint32_t eemck1; | |
180 | /* Error diagnostic */ | |
181 | } XCSR; | |
64201201 | 182 | |
36081602 JM |
183 | static void PPC_XCSR_writeb (void *opaque, |
184 | target_phys_addr_t addr, uint32_t value) | |
64201201 FB |
185 | { |
186 | printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value); | |
187 | } | |
188 | ||
36081602 JM |
189 | static void PPC_XCSR_writew (void *opaque, |
190 | target_phys_addr_t addr, uint32_t value) | |
9a64fbe4 | 191 | { |
f658b4db | 192 | #ifdef TARGET_WORDS_BIGENDIAN |
64201201 | 193 | value = bswap16(value); |
f658b4db | 194 | #endif |
64201201 | 195 | printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value); |
9a64fbe4 FB |
196 | } |
197 | ||
36081602 JM |
198 | static void PPC_XCSR_writel (void *opaque, |
199 | target_phys_addr_t addr, uint32_t value) | |
9a64fbe4 | 200 | { |
f658b4db | 201 | #ifdef TARGET_WORDS_BIGENDIAN |
64201201 | 202 | value = bswap32(value); |
f658b4db | 203 | #endif |
64201201 | 204 | printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value); |
9a64fbe4 FB |
205 | } |
206 | ||
a4193c8a | 207 | static uint32_t PPC_XCSR_readb (void *opaque, target_phys_addr_t addr) |
64201201 FB |
208 | { |
209 | uint32_t retval = 0; | |
9a64fbe4 | 210 | |
64201201 | 211 | printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval); |
9a64fbe4 | 212 | |
64201201 FB |
213 | return retval; |
214 | } | |
215 | ||
a4193c8a | 216 | static uint32_t PPC_XCSR_readw (void *opaque, target_phys_addr_t addr) |
9a64fbe4 | 217 | { |
64201201 FB |
218 | uint32_t retval = 0; |
219 | ||
220 | printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval); | |
221 | #ifdef TARGET_WORDS_BIGENDIAN | |
222 | retval = bswap16(retval); | |
223 | #endif | |
224 | ||
225 | return retval; | |
9a64fbe4 FB |
226 | } |
227 | ||
a4193c8a | 228 | static uint32_t PPC_XCSR_readl (void *opaque, target_phys_addr_t addr) |
9a64fbe4 FB |
229 | { |
230 | uint32_t retval = 0; | |
231 | ||
64201201 FB |
232 | printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval); |
233 | #ifdef TARGET_WORDS_BIGENDIAN | |
234 | retval = bswap32(retval); | |
235 | #endif | |
9a64fbe4 FB |
236 | |
237 | return retval; | |
238 | } | |
239 | ||
64201201 FB |
240 | static CPUWriteMemoryFunc *PPC_XCSR_write[] = { |
241 | &PPC_XCSR_writeb, | |
242 | &PPC_XCSR_writew, | |
243 | &PPC_XCSR_writel, | |
9a64fbe4 FB |
244 | }; |
245 | ||
64201201 FB |
246 | static CPUReadMemoryFunc *PPC_XCSR_read[] = { |
247 | &PPC_XCSR_readb, | |
248 | &PPC_XCSR_readw, | |
249 | &PPC_XCSR_readl, | |
9a64fbe4 | 250 | }; |
b6b8bd18 | 251 | #endif |
9a64fbe4 | 252 | |
64201201 FB |
253 | /* Fake super-io ports for PREP platform (Intel 82378ZB) */ |
254 | typedef struct sysctrl_t { | |
255 | m48t59_t *nvram; | |
256 | uint8_t state; | |
257 | uint8_t syscontrol; | |
258 | uint8_t fake_io[2]; | |
da9b266b | 259 | int contiguous_map; |
fb3444b8 | 260 | int endian; |
64201201 | 261 | } sysctrl_t; |
9a64fbe4 | 262 | |
64201201 FB |
263 | enum { |
264 | STATE_HARDFILE = 0x01, | |
9a64fbe4 | 265 | }; |
9a64fbe4 | 266 | |
64201201 | 267 | static sysctrl_t *sysctrl; |
9a64fbe4 | 268 | |
a541f297 | 269 | static void PREP_io_write (void *opaque, uint32_t addr, uint32_t val) |
9a64fbe4 | 270 | { |
64201201 FB |
271 | sysctrl_t *sysctrl = opaque; |
272 | ||
273 | PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr - PPC_IO_BASE, val); | |
274 | sysctrl->fake_io[addr - 0x0398] = val; | |
9a64fbe4 FB |
275 | } |
276 | ||
a541f297 | 277 | static uint32_t PREP_io_read (void *opaque, uint32_t addr) |
9a64fbe4 | 278 | { |
64201201 | 279 | sysctrl_t *sysctrl = opaque; |
9a64fbe4 | 280 | |
64201201 FB |
281 | PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr - PPC_IO_BASE, |
282 | sysctrl->fake_io[addr - 0x0398]); | |
283 | return sysctrl->fake_io[addr - 0x0398]; | |
284 | } | |
9a64fbe4 | 285 | |
a541f297 | 286 | static void PREP_io_800_writeb (void *opaque, uint32_t addr, uint32_t val) |
9a64fbe4 | 287 | { |
64201201 FB |
288 | sysctrl_t *sysctrl = opaque; |
289 | ||
290 | PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr - PPC_IO_BASE, val); | |
9a64fbe4 FB |
291 | switch (addr) { |
292 | case 0x0092: | |
293 | /* Special port 92 */ | |
294 | /* Check soft reset asked */ | |
64201201 | 295 | if (val & 0x01) { |
47103572 | 296 | // cpu_interrupt(first_cpu, PPC_INTERRUPT_RESET); |
9a64fbe4 FB |
297 | } |
298 | /* Check LE mode */ | |
64201201 | 299 | if (val & 0x02) { |
fb3444b8 FB |
300 | sysctrl->endian = 1; |
301 | } else { | |
302 | sysctrl->endian = 0; | |
9a64fbe4 FB |
303 | } |
304 | break; | |
64201201 FB |
305 | case 0x0800: |
306 | /* Motorola CPU configuration register : read-only */ | |
307 | break; | |
308 | case 0x0802: | |
309 | /* Motorola base module feature register : read-only */ | |
310 | break; | |
311 | case 0x0803: | |
312 | /* Motorola base module status register : read-only */ | |
313 | break; | |
9a64fbe4 | 314 | case 0x0808: |
64201201 FB |
315 | /* Hardfile light register */ |
316 | if (val & 1) | |
317 | sysctrl->state |= STATE_HARDFILE; | |
318 | else | |
319 | sysctrl->state &= ~STATE_HARDFILE; | |
9a64fbe4 FB |
320 | break; |
321 | case 0x0810: | |
322 | /* Password protect 1 register */ | |
64201201 FB |
323 | if (sysctrl->nvram != NULL) |
324 | m48t59_toggle_lock(sysctrl->nvram, 1); | |
9a64fbe4 FB |
325 | break; |
326 | case 0x0812: | |
327 | /* Password protect 2 register */ | |
64201201 FB |
328 | if (sysctrl->nvram != NULL) |
329 | m48t59_toggle_lock(sysctrl->nvram, 2); | |
9a64fbe4 FB |
330 | break; |
331 | case 0x0814: | |
64201201 | 332 | /* L2 invalidate register */ |
c68ea704 | 333 | // tlb_flush(first_cpu, 1); |
9a64fbe4 FB |
334 | break; |
335 | case 0x081C: | |
336 | /* system control register */ | |
64201201 | 337 | sysctrl->syscontrol = val & 0x0F; |
9a64fbe4 FB |
338 | break; |
339 | case 0x0850: | |
340 | /* I/O map type register */ | |
da9b266b | 341 | sysctrl->contiguous_map = val & 0x01; |
9a64fbe4 FB |
342 | break; |
343 | default: | |
64201201 FB |
344 | printf("ERROR: unaffected IO port write: %04lx => %02x\n", |
345 | (long)addr, val); | |
9a64fbe4 FB |
346 | break; |
347 | } | |
348 | } | |
349 | ||
a541f297 | 350 | static uint32_t PREP_io_800_readb (void *opaque, uint32_t addr) |
9a64fbe4 | 351 | { |
64201201 | 352 | sysctrl_t *sysctrl = opaque; |
9a64fbe4 FB |
353 | uint32_t retval = 0xFF; |
354 | ||
355 | switch (addr) { | |
356 | case 0x0092: | |
357 | /* Special port 92 */ | |
64201201 FB |
358 | retval = 0x00; |
359 | break; | |
360 | case 0x0800: | |
361 | /* Motorola CPU configuration register */ | |
362 | retval = 0xEF; /* MPC750 */ | |
363 | break; | |
364 | case 0x0802: | |
365 | /* Motorola Base module feature register */ | |
366 | retval = 0xAD; /* No ESCC, PMC slot neither ethernet */ | |
367 | break; | |
368 | case 0x0803: | |
369 | /* Motorola base module status register */ | |
370 | retval = 0xE0; /* Standard MPC750 */ | |
9a64fbe4 FB |
371 | break; |
372 | case 0x080C: | |
373 | /* Equipment present register: | |
374 | * no L2 cache | |
375 | * no upgrade processor | |
376 | * no cards in PCI slots | |
377 | * SCSI fuse is bad | |
378 | */ | |
64201201 FB |
379 | retval = 0x3C; |
380 | break; | |
381 | case 0x0810: | |
382 | /* Motorola base module extended feature register */ | |
383 | retval = 0x39; /* No USB, CF and PCI bridge. NVRAM present */ | |
9a64fbe4 | 384 | break; |
da9b266b FB |
385 | case 0x0814: |
386 | /* L2 invalidate: don't care */ | |
387 | break; | |
9a64fbe4 FB |
388 | case 0x0818: |
389 | /* Keylock */ | |
390 | retval = 0x00; | |
391 | break; | |
392 | case 0x081C: | |
393 | /* system control register | |
394 | * 7 - 6 / 1 - 0: L2 cache enable | |
395 | */ | |
64201201 | 396 | retval = sysctrl->syscontrol; |
9a64fbe4 FB |
397 | break; |
398 | case 0x0823: | |
399 | /* */ | |
400 | retval = 0x03; /* no L2 cache */ | |
401 | break; | |
402 | case 0x0850: | |
403 | /* I/O map type register */ | |
da9b266b | 404 | retval = sysctrl->contiguous_map; |
9a64fbe4 FB |
405 | break; |
406 | default: | |
64201201 | 407 | printf("ERROR: unaffected IO port: %04lx read\n", (long)addr); |
9a64fbe4 FB |
408 | break; |
409 | } | |
64201201 | 410 | PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr - PPC_IO_BASE, retval); |
9a64fbe4 FB |
411 | |
412 | return retval; | |
413 | } | |
414 | ||
da9b266b FB |
415 | static inline target_phys_addr_t prep_IO_address (sysctrl_t *sysctrl, |
416 | target_phys_addr_t addr) | |
417 | { | |
418 | if (sysctrl->contiguous_map == 0) { | |
419 | /* 64 KB contiguous space for IOs */ | |
420 | addr &= 0xFFFF; | |
421 | } else { | |
422 | /* 8 MB non-contiguous space for IOs */ | |
423 | addr = (addr & 0x1F) | ((addr & 0x007FFF000) >> 7); | |
424 | } | |
425 | ||
426 | return addr; | |
427 | } | |
428 | ||
429 | static void PPC_prep_io_writeb (void *opaque, target_phys_addr_t addr, | |
430 | uint32_t value) | |
431 | { | |
432 | sysctrl_t *sysctrl = opaque; | |
433 | ||
434 | addr = prep_IO_address(sysctrl, addr); | |
435 | cpu_outb(NULL, addr, value); | |
436 | } | |
437 | ||
438 | static uint32_t PPC_prep_io_readb (void *opaque, target_phys_addr_t addr) | |
439 | { | |
440 | sysctrl_t *sysctrl = opaque; | |
441 | uint32_t ret; | |
442 | ||
443 | addr = prep_IO_address(sysctrl, addr); | |
444 | ret = cpu_inb(NULL, addr); | |
445 | ||
446 | return ret; | |
447 | } | |
448 | ||
449 | static void PPC_prep_io_writew (void *opaque, target_phys_addr_t addr, | |
450 | uint32_t value) | |
451 | { | |
452 | sysctrl_t *sysctrl = opaque; | |
453 | ||
454 | addr = prep_IO_address(sysctrl, addr); | |
455 | #ifdef TARGET_WORDS_BIGENDIAN | |
456 | value = bswap16(value); | |
457 | #endif | |
458 | PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr, value); | |
459 | cpu_outw(NULL, addr, value); | |
460 | } | |
461 | ||
462 | static uint32_t PPC_prep_io_readw (void *opaque, target_phys_addr_t addr) | |
463 | { | |
464 | sysctrl_t *sysctrl = opaque; | |
465 | uint32_t ret; | |
466 | ||
467 | addr = prep_IO_address(sysctrl, addr); | |
468 | ret = cpu_inw(NULL, addr); | |
469 | #ifdef TARGET_WORDS_BIGENDIAN | |
470 | ret = bswap16(ret); | |
471 | #endif | |
472 | PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr, ret); | |
473 | ||
474 | return ret; | |
475 | } | |
476 | ||
477 | static void PPC_prep_io_writel (void *opaque, target_phys_addr_t addr, | |
478 | uint32_t value) | |
479 | { | |
480 | sysctrl_t *sysctrl = opaque; | |
481 | ||
482 | addr = prep_IO_address(sysctrl, addr); | |
483 | #ifdef TARGET_WORDS_BIGENDIAN | |
484 | value = bswap32(value); | |
485 | #endif | |
486 | PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr, value); | |
487 | cpu_outl(NULL, addr, value); | |
488 | } | |
489 | ||
490 | static uint32_t PPC_prep_io_readl (void *opaque, target_phys_addr_t addr) | |
491 | { | |
492 | sysctrl_t *sysctrl = opaque; | |
493 | uint32_t ret; | |
494 | ||
495 | addr = prep_IO_address(sysctrl, addr); | |
496 | ret = cpu_inl(NULL, addr); | |
497 | #ifdef TARGET_WORDS_BIGENDIAN | |
498 | ret = bswap32(ret); | |
499 | #endif | |
500 | PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr, ret); | |
501 | ||
502 | return ret; | |
503 | } | |
504 | ||
505 | CPUWriteMemoryFunc *PPC_prep_io_write[] = { | |
506 | &PPC_prep_io_writeb, | |
507 | &PPC_prep_io_writew, | |
508 | &PPC_prep_io_writel, | |
509 | }; | |
510 | ||
511 | CPUReadMemoryFunc *PPC_prep_io_read[] = { | |
512 | &PPC_prep_io_readb, | |
513 | &PPC_prep_io_readw, | |
514 | &PPC_prep_io_readl, | |
515 | }; | |
516 | ||
64201201 | 517 | #define NVRAM_SIZE 0x2000 |
a541f297 | 518 | |
26aa7d72 | 519 | /* PowerPC PREP hardware initialisation */ |
94fc95cd JM |
520 | static void ppc_prep_init (int ram_size, int vga_ram_size, int boot_device, |
521 | DisplayState *ds, const char **fd_filename, | |
522 | int snapshot, const char *kernel_filename, | |
523 | const char *kernel_cmdline, | |
524 | const char *initrd_filename, | |
525 | const char *cpu_model) | |
a541f297 | 526 | { |
fe33cc71 | 527 | CPUState *env, *envs[MAX_CPUS]; |
a541f297 | 528 | char buf[1024]; |
64201201 | 529 | m48t59_t *nvram; |
a541f297 | 530 | int PPC_io_memory; |
4157a662 | 531 | int linux_boot, i, nb_nics1, bios_size; |
64201201 FB |
532 | unsigned long bios_offset; |
533 | uint32_t kernel_base, kernel_size, initrd_base, initrd_size; | |
3fc6c082 | 534 | ppc_def_t *def; |
46e50e9d | 535 | PCIBus *pci_bus; |
d537cf6c | 536 | qemu_irq *i8259; |
64201201 FB |
537 | |
538 | sysctrl = qemu_mallocz(sizeof(sysctrl_t)); | |
539 | if (sysctrl == NULL) | |
0a032cbe | 540 | return; |
a541f297 FB |
541 | |
542 | linux_boot = (kernel_filename != NULL); | |
0a032cbe | 543 | |
c68ea704 | 544 | /* init CPUs */ |
c68ea704 | 545 | env = cpu_init(); |
94fc95cd | 546 | if (cpu_model == NULL) |
d12f4c38 | 547 | cpu_model = "default"; |
94fc95cd | 548 | ppc_find_by_name(cpu_model, &def); |
c68ea704 FB |
549 | if (def == NULL) { |
550 | cpu_abort(env, "Unable to find PowerPC CPU definition\n"); | |
551 | } | |
fe33cc71 JM |
552 | for (i = 0; i < smp_cpus; i++) { |
553 | cpu_ppc_register(env, def); | |
554 | cpu_ppc_reset(env); | |
555 | /* Set time-base frequency to 100 Mhz */ | |
556 | cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); | |
557 | qemu_register_reset(&cpu_ppc_reset, env); | |
558 | register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); | |
559 | envs[i] = env; | |
560 | } | |
a541f297 FB |
561 | |
562 | /* allocate RAM */ | |
64201201 FB |
563 | cpu_register_physical_memory(0, ram_size, IO_MEM_RAM); |
564 | ||
565 | /* allocate and load BIOS */ | |
566 | bios_offset = ram_size + vga_ram_size; | |
1192dad8 JM |
567 | if (bios_name == NULL) |
568 | bios_name = BIOS_FILENAME; | |
569 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); | |
4157a662 FB |
570 | bios_size = load_image(buf, phys_ram_base + bios_offset); |
571 | if (bios_size < 0 || bios_size > BIOS_SIZE) { | |
4a057712 | 572 | cpu_abort(env, "qemu: could not load PPC PREP bios '%s'\n", buf); |
64201201 FB |
573 | exit(1); |
574 | } | |
4157a662 | 575 | bios_size = (bios_size + 0xfff) & ~0xfff; |
4a057712 | 576 | cpu_register_physical_memory((uint32_t)(-bios_size), |
4157a662 | 577 | bios_size, bios_offset | IO_MEM_ROM); |
26aa7d72 | 578 | |
a541f297 | 579 | if (linux_boot) { |
64201201 | 580 | kernel_base = KERNEL_LOAD_ADDR; |
a541f297 | 581 | /* now we can load the kernel */ |
64201201 FB |
582 | kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base); |
583 | if (kernel_size < 0) { | |
4a057712 JM |
584 | cpu_abort(env, "qemu: could not load kernel '%s'\n", |
585 | kernel_filename); | |
a541f297 FB |
586 | exit(1); |
587 | } | |
588 | /* load initrd */ | |
a541f297 | 589 | if (initrd_filename) { |
64201201 FB |
590 | initrd_base = INITRD_LOAD_ADDR; |
591 | initrd_size = load_image(initrd_filename, | |
592 | phys_ram_base + initrd_base); | |
a541f297 | 593 | if (initrd_size < 0) { |
4a057712 JM |
594 | cpu_abort(env, "qemu: could not load initial ram disk '%s'\n", |
595 | initrd_filename); | |
a541f297 FB |
596 | exit(1); |
597 | } | |
64201201 FB |
598 | } else { |
599 | initrd_base = 0; | |
600 | initrd_size = 0; | |
a541f297 | 601 | } |
64201201 | 602 | boot_device = 'm'; |
a541f297 | 603 | } else { |
64201201 FB |
604 | kernel_base = 0; |
605 | kernel_size = 0; | |
606 | initrd_base = 0; | |
607 | initrd_size = 0; | |
a541f297 FB |
608 | } |
609 | ||
64201201 | 610 | isa_mem_base = 0xc0000000; |
dd37a5e4 JM |
611 | if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { |
612 | cpu_abort(env, "Only 6xx bus is supported on PREP machine\n"); | |
613 | exit(1); | |
614 | } | |
24be5ae3 | 615 | i8259 = i8259_init(first_cpu->irq_inputs[PPC6xx_INPUT_INT]); |
d537cf6c | 616 | pci_bus = pci_prep_init(i8259); |
da9b266b FB |
617 | // pci_bus = i440fx_init(); |
618 | /* Register 8 MB of ISA IO space (needed for non-contiguous map) */ | |
619 | PPC_io_memory = cpu_register_io_memory(0, PPC_prep_io_read, | |
620 | PPC_prep_io_write, sysctrl); | |
621 | cpu_register_physical_memory(0x80000000, 0x00800000, PPC_io_memory); | |
64201201 | 622 | |
a541f297 | 623 | /* init basic PC hardware */ |
5fafdf24 | 624 | pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, ram_size, |
89b6b508 | 625 | vga_ram_size, 0, 0); |
64201201 | 626 | // openpic = openpic_init(0x00000000, 0xF0000000, 1); |
d537cf6c PB |
627 | // pit = pit_init(0x40, i8259[0]); |
628 | rtc_init(0x70, i8259[8]); | |
a541f297 | 629 | |
d537cf6c | 630 | serial_init(0x3f8, i8259[4], serial_hds[0]); |
a541f297 FB |
631 | nb_nics1 = nb_nics; |
632 | if (nb_nics1 > NE2000_NB_MAX) | |
633 | nb_nics1 = NE2000_NB_MAX; | |
634 | for(i = 0; i < nb_nics1; i++) { | |
a41b2ff2 PB |
635 | if (nd_table[0].model == NULL |
636 | || strcmp(nd_table[0].model, "ne2k_isa") == 0) { | |
d537cf6c | 637 | isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]); |
c4a7060c BS |
638 | } else if (strcmp(nd_table[0].model, "?") == 0) { |
639 | fprintf(stderr, "qemu: Supported NICs: ne2k_isa\n"); | |
640 | exit (1); | |
a41b2ff2 | 641 | } else { |
4a057712 JM |
642 | /* Why ? */ |
643 | cpu_abort(env, "qemu: Unsupported NIC: %s\n", nd_table[0].model); | |
a41b2ff2 PB |
644 | exit (1); |
645 | } | |
a541f297 | 646 | } |
a541f297 FB |
647 | |
648 | for(i = 0; i < 2; i++) { | |
d537cf6c | 649 | isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], |
69b91039 | 650 | bs_table[2 * i], bs_table[2 * i + 1]); |
a541f297 | 651 | } |
d537cf6c | 652 | i8042_init(i8259[1], i8259[12], 0x60); |
b6b8bd18 | 653 | DMA_init(1); |
64201201 | 654 | // AUD_init(); |
a541f297 FB |
655 | // SB16_init(); |
656 | ||
d537cf6c | 657 | fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table); |
a541f297 | 658 | |
64201201 FB |
659 | /* Register speaker port */ |
660 | register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL); | |
661 | register_ioport_write(0x61, 1, 1, speaker_ioport_write, NULL); | |
a541f297 | 662 | /* Register fake IO ports for PREP */ |
64201201 FB |
663 | register_ioport_read(0x398, 2, 1, &PREP_io_read, sysctrl); |
664 | register_ioport_write(0x398, 2, 1, &PREP_io_write, sysctrl); | |
a541f297 | 665 | /* System control ports */ |
64201201 FB |
666 | register_ioport_read(0x0092, 0x01, 1, &PREP_io_800_readb, sysctrl); |
667 | register_ioport_write(0x0092, 0x01, 1, &PREP_io_800_writeb, sysctrl); | |
668 | register_ioport_read(0x0800, 0x52, 1, &PREP_io_800_readb, sysctrl); | |
669 | register_ioport_write(0x0800, 0x52, 1, &PREP_io_800_writeb, sysctrl); | |
670 | /* PCI intack location */ | |
671 | PPC_io_memory = cpu_register_io_memory(0, PPC_intack_read, | |
a4193c8a | 672 | PPC_intack_write, NULL); |
a541f297 | 673 | cpu_register_physical_memory(0xBFFFFFF0, 0x4, PPC_io_memory); |
64201201 | 674 | /* PowerPC control and status register group */ |
b6b8bd18 | 675 | #if 0 |
36081602 JM |
676 | PPC_io_memory = cpu_register_io_memory(0, PPC_XCSR_read, PPC_XCSR_write, |
677 | NULL); | |
64201201 | 678 | cpu_register_physical_memory(0xFEFF0000, 0x1000, PPC_io_memory); |
b6b8bd18 | 679 | #endif |
a541f297 | 680 | |
0d92ed30 | 681 | if (usb_enabled) { |
e24ad6f1 | 682 | usb_ohci_init_pci(pci_bus, 3, -1); |
0d92ed30 PB |
683 | } |
684 | ||
d537cf6c | 685 | nvram = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59); |
64201201 FB |
686 | if (nvram == NULL) |
687 | return; | |
688 | sysctrl->nvram = nvram; | |
689 | ||
690 | /* Initialise NVRAM */ | |
691 | PPC_NVRAM_set_params(nvram, NVRAM_SIZE, "PREP", ram_size, boot_device, | |
692 | kernel_base, kernel_size, | |
b6b8bd18 | 693 | kernel_cmdline, |
64201201 FB |
694 | initrd_base, initrd_size, |
695 | /* XXX: need an option to load a NVRAM image */ | |
b6b8bd18 FB |
696 | 0, |
697 | graphic_width, graphic_height, graphic_depth); | |
c0e564d5 FB |
698 | |
699 | /* Special port to get debug messages from Open-Firmware */ | |
700 | register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL); | |
a541f297 | 701 | } |
c0e564d5 FB |
702 | |
703 | QEMUMachine prep_machine = { | |
704 | "prep", | |
705 | "PowerPC PREP platform", | |
706 | ppc_prep_init, | |
707 | }; |