New '-bios' option, used to select an alternate BIOS image from bios_dir.
[qemu] / hw / ppc_prep.c
1 /*
2  * QEMU PPC PREP hardware System Emulator
3  *
4  * Copyright (c) 2003-2007 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.
23  */
24 #include "vl.h"
25
26 //#define HARD_DEBUG_PPC_IO
27 //#define DEBUG_PPC_IO
28
29 /* SMP is not enabled, for now */
30 #define MAX_CPUS 1
31
32 #define BIOS_FILENAME "ppc_rom.bin"
33 #define KERNEL_LOAD_ADDR 0x01000000
34 #define INITRD_LOAD_ADDR 0x01800000
35
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 {                                                     \
46     if (loglevel & CPU_LOG_IOPORT) {                     \
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 {                                                     \
55     if (loglevel & CPU_LOG_IOPORT) {                     \
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
63 /* Constants for devices init */
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 };
72
73 //static PITState *pit;
74
75 /* ISA IO ports bridge */
76 #define PPC_IO_BASE 0x80000000
77
78 /* Speaker port 0x61 */
79 int speaker_data_on;
80 int dummy_refresh_clock;
81
82 static void speaker_ioport_write (void *opaque, uint32_t addr, uint32_t val)
83 {
84 #if 0
85     speaker_data_on = (val >> 1) & 1;
86     pit_set_gate(pit, 2, val & 1);
87 #endif
88 }
89
90 static uint32_t speaker_ioport_read (void *opaque, uint32_t addr)
91 {
92 #if 0
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) |
97         (dummy_refresh_clock << 4);
98 #endif
99     return 0;
100 }
101
102 /* PCI intack register */
103 /* Read-only register (?) */
104 static void _PPC_intack_write (void *opaque,
105                                target_phys_addr_t addr, uint32_t value)
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)
115         retval = pic_intack_read(isa_pic);
116     //   printf("%s: 0x%08x <= %d\n", __func__, addr, retval);
117
118     return retval;
119 }
120
121 static uint32_t PPC_intack_readb (void *opaque, target_phys_addr_t addr)
122 {
123     return _PPC_intack_read(addr);
124 }
125
126 static uint32_t PPC_intack_readw (void *opaque, target_phys_addr_t addr)
127 {
128 #ifdef TARGET_WORDS_BIGENDIAN
129     return bswap16(_PPC_intack_read(addr));
130 #else
131     return _PPC_intack_read(addr);
132 #endif
133 }
134
135 static uint32_t PPC_intack_readl (void *opaque, target_phys_addr_t addr)
136 {
137 #ifdef TARGET_WORDS_BIGENDIAN
138     return bswap32(_PPC_intack_read(addr));
139 #else
140     return _PPC_intack_read(addr);
141 #endif
142 }
143
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;
182
183 static void PPC_XCSR_writeb (void *opaque,
184                              target_phys_addr_t addr, uint32_t value)
185 {
186     printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value);
187 }
188
189 static void PPC_XCSR_writew (void *opaque,
190                              target_phys_addr_t addr, uint32_t value)
191 {
192 #ifdef TARGET_WORDS_BIGENDIAN
193     value = bswap16(value);
194 #endif
195     printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value);
196 }
197
198 static void PPC_XCSR_writel (void *opaque,
199                              target_phys_addr_t addr, uint32_t value)
200 {
201 #ifdef TARGET_WORDS_BIGENDIAN
202     value = bswap32(value);
203 #endif
204     printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value);
205 }
206
207 static uint32_t PPC_XCSR_readb (void *opaque, target_phys_addr_t addr)
208 {
209     uint32_t retval = 0;
210
211     printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval);
212
213     return retval;
214 }
215
216 static uint32_t PPC_XCSR_readw (void *opaque, target_phys_addr_t addr)
217 {
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;
226 }
227
228 static uint32_t PPC_XCSR_readl (void *opaque, target_phys_addr_t addr)
229 {
230     uint32_t retval = 0;
231
232     printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval);
233 #ifdef TARGET_WORDS_BIGENDIAN
234     retval = bswap32(retval);
235 #endif
236
237     return retval;
238 }
239
240 static CPUWriteMemoryFunc *PPC_XCSR_write[] = {
241     &PPC_XCSR_writeb,
242     &PPC_XCSR_writew,
243     &PPC_XCSR_writel,
244 };
245
246 static CPUReadMemoryFunc *PPC_XCSR_read[] = {
247     &PPC_XCSR_readb,
248     &PPC_XCSR_readw,
249     &PPC_XCSR_readl,
250 };
251 #endif
252
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];
259     int contiguous_map;
260     int endian;
261 } sysctrl_t;
262
263 enum {
264     STATE_HARDFILE = 0x01,
265 };
266
267 static sysctrl_t *sysctrl;
268
269 static void PREP_io_write (void *opaque, uint32_t addr, uint32_t val)
270 {
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;
275 }
276
277 static uint32_t PREP_io_read (void *opaque, uint32_t addr)
278 {
279     sysctrl_t *sysctrl = opaque;
280
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 }
285
286 static void PREP_io_800_writeb (void *opaque, uint32_t addr, uint32_t val)
287 {
288     sysctrl_t *sysctrl = opaque;
289
290     PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr - PPC_IO_BASE, val);
291     switch (addr) {
292     case 0x0092:
293         /* Special port 92 */
294         /* Check soft reset asked */
295         if (val & 0x01) {
296             //            cpu_interrupt(first_cpu, PPC_INTERRUPT_RESET);
297         }
298         /* Check LE mode */
299         if (val & 0x02) {
300             sysctrl->endian = 1;
301         } else {
302             sysctrl->endian = 0;
303         }
304         break;
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;
314     case 0x0808:
315         /* Hardfile light register */
316         if (val & 1)
317             sysctrl->state |= STATE_HARDFILE;
318         else
319             sysctrl->state &= ~STATE_HARDFILE;
320         break;
321     case 0x0810:
322         /* Password protect 1 register */
323         if (sysctrl->nvram != NULL)
324             m48t59_toggle_lock(sysctrl->nvram, 1);
325         break;
326     case 0x0812:
327         /* Password protect 2 register */
328         if (sysctrl->nvram != NULL)
329             m48t59_toggle_lock(sysctrl->nvram, 2);
330         break;
331     case 0x0814:
332         /* L2 invalidate register */
333         //        tlb_flush(first_cpu, 1);
334         break;
335     case 0x081C:
336         /* system control register */
337         sysctrl->syscontrol = val & 0x0F;
338         break;
339     case 0x0850:
340         /* I/O map type register */
341         sysctrl->contiguous_map = val & 0x01;
342         break;
343     default:
344         printf("ERROR: unaffected IO port write: %04lx => %02x\n",
345                (long)addr, val);
346         break;
347     }
348 }
349
350 static uint32_t PREP_io_800_readb (void *opaque, uint32_t addr)
351 {
352     sysctrl_t *sysctrl = opaque;
353     uint32_t retval = 0xFF;
354
355     switch (addr) {
356     case 0x0092:
357         /* Special port 92 */
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 */
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          */
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 */
384         break;
385     case 0x0814:
386         /* L2 invalidate: don't care */
387         break;
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          */
396         retval = sysctrl->syscontrol;
397         break;
398     case 0x0823:
399         /* */
400         retval = 0x03; /* no L2 cache */
401         break;
402     case 0x0850:
403         /* I/O map type register */
404         retval = sysctrl->contiguous_map;
405         break;
406     default:
407         printf("ERROR: unaffected IO port: %04lx read\n", (long)addr);
408         break;
409     }
410     PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr - PPC_IO_BASE, retval);
411
412     return retval;
413 }
414
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
517 #define NVRAM_SIZE        0x2000
518
519 /* PowerPC PREP hardware initialisation */
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)
526 {
527     CPUState *env, *envs[MAX_CPUS];
528     char buf[1024];
529     m48t59_t *nvram;
530     int PPC_io_memory;
531     int linux_boot, i, nb_nics1, bios_size;
532     unsigned long bios_offset;
533     uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
534     ppc_def_t *def;
535     PCIBus *pci_bus;
536     qemu_irq *i8259;
537
538     sysctrl = qemu_mallocz(sizeof(sysctrl_t));
539     if (sysctrl == NULL)
540         return;
541
542     linux_boot = (kernel_filename != NULL);
543
544     /* init CPUs */
545     env = cpu_init();
546     if (cpu_model == NULL)
547         cpu_model = "default";
548     ppc_find_by_name(cpu_model, &def);
549     if (def == NULL) {
550         cpu_abort(env, "Unable to find PowerPC CPU definition\n");
551     }
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     }
561
562     /* allocate RAM */
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;
567     if (bios_name == NULL)
568         bios_name = BIOS_FILENAME;
569     snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
570     bios_size = load_image(buf, phys_ram_base + bios_offset);
571     if (bios_size < 0 || bios_size > BIOS_SIZE) {
572         cpu_abort(env, "qemu: could not load PPC PREP bios '%s'\n", buf);
573         exit(1);
574     }
575     bios_size = (bios_size + 0xfff) & ~0xfff;
576     cpu_register_physical_memory((uint32_t)(-bios_size),
577                                  bios_size, bios_offset | IO_MEM_ROM);
578
579     if (linux_boot) {
580         kernel_base = KERNEL_LOAD_ADDR;
581         /* now we can load the kernel */
582         kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
583         if (kernel_size < 0) {
584             cpu_abort(env, "qemu: could not load kernel '%s'\n",
585                       kernel_filename);
586             exit(1);
587         }
588         /* load initrd */
589         if (initrd_filename) {
590             initrd_base = INITRD_LOAD_ADDR;
591             initrd_size = load_image(initrd_filename,
592                                      phys_ram_base + initrd_base);
593             if (initrd_size < 0) {
594                 cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
595                           initrd_filename);
596                 exit(1);
597             }
598         } else {
599             initrd_base = 0;
600             initrd_size = 0;
601         }
602         boot_device = 'm';
603     } else {
604         kernel_base = 0;
605         kernel_size = 0;
606         initrd_base = 0;
607         initrd_size = 0;
608     }
609
610     isa_mem_base = 0xc0000000;
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     }
615     i8259 = i8259_init(first_cpu->irq_inputs[PPC6xx_INPUT_INT]);
616     pci_bus = pci_prep_init(i8259);
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);
622
623     /* init basic PC hardware */
624     pci_vga_init(pci_bus, ds, phys_ram_base + ram_size, ram_size,
625                  vga_ram_size, 0, 0);
626     //    openpic = openpic_init(0x00000000, 0xF0000000, 1);
627     //    pit = pit_init(0x40, i8259[0]);
628     rtc_init(0x70, i8259[8]);
629
630     serial_init(0x3f8, i8259[4], serial_hds[0]);
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++) {
635         if (nd_table[0].model == NULL
636             || strcmp(nd_table[0].model, "ne2k_isa") == 0) {
637             isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
638         } else if (strcmp(nd_table[0].model, "?") == 0) {
639             fprintf(stderr, "qemu: Supported NICs: ne2k_isa\n");
640             exit (1);
641         } else {
642             /* Why ? */
643             cpu_abort(env, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
644             exit (1);
645         }
646     }
647
648     for(i = 0; i < 2; i++) {
649         isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
650                      bs_table[2 * i], bs_table[2 * i + 1]);
651     }
652     i8042_init(i8259[1], i8259[12], 0x60);
653     DMA_init(1);
654     //    AUD_init();
655     //    SB16_init();
656
657     fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table);
658
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);
662     /* Register fake IO ports for PREP */
663     register_ioport_read(0x398, 2, 1, &PREP_io_read, sysctrl);
664     register_ioport_write(0x398, 2, 1, &PREP_io_write, sysctrl);
665     /* System control ports */
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,
672                                            PPC_intack_write, NULL);
673     cpu_register_physical_memory(0xBFFFFFF0, 0x4, PPC_io_memory);
674     /* PowerPC control and status register group */
675 #if 0
676     PPC_io_memory = cpu_register_io_memory(0, PPC_XCSR_read, PPC_XCSR_write,
677                                            NULL);
678     cpu_register_physical_memory(0xFEFF0000, 0x1000, PPC_io_memory);
679 #endif
680
681     if (usb_enabled) {
682         usb_ohci_init_pci(pci_bus, 3, -1);
683     }
684
685     nvram = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59);
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,
693                          kernel_cmdline,
694                          initrd_base, initrd_size,
695                          /* XXX: need an option to load a NVRAM image */
696                          0,
697                          graphic_width, graphic_height, graphic_depth);
698
699     /* Special port to get debug messages from Open-Firmware */
700     register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
701 }
702
703 QEMUMachine prep_machine = {
704     "prep",
705     "PowerPC PREP platform",
706     ppc_prep_init,
707 };