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