115
101
static void _PPC_intack_write (void *opaque,
116
102
target_phys_addr_t addr, uint32_t value)
118
// printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
104
// printf("%s: 0x%08x => 0x%08x\n", __func__, addr, value);
121
static always_inline uint32_t _PPC_intack_read (target_phys_addr_t addr)
107
static inline uint32_t _PPC_intack_read (target_phys_addr_t addr)
123
109
uint32_t retval = 0;
125
111
if (addr == 0xBFFFFFF0)
126
112
retval = pic_intack_read(isa_pic);
127
// printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
113
// printf("%s: 0x%08x <= %d\n", __func__, addr, retval);
194
180
static void PPC_XCSR_writeb (void *opaque,
195
181
target_phys_addr_t addr, uint32_t value)
197
printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
183
printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value);
200
186
static void PPC_XCSR_writew (void *opaque,
212
198
#ifdef TARGET_WORDS_BIGENDIAN
213
199
value = bswap32(value);
215
printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
201
printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value);
218
204
static uint32_t PPC_XCSR_readb (void *opaque, target_phys_addr_t addr)
220
206
uint32_t retval = 0;
222
printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
208
printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval);
301
285
sysctrl_t *sysctrl = opaque;
303
PPC_IO_DPRINTF("0x%08" PRIx32 " => 0x%02" PRIx32 "\n",
304
addr - PPC_IO_BASE, val);
287
PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr - PPC_IO_BASE, val);
307
290
/* Special port 92 */
308
291
/* Check soft reset asked */
309
292
if (val & 0x01) {
310
qemu_irq_raise(sysctrl->reset_irq);
312
qemu_irq_lower(sysctrl->reset_irq);
293
// cpu_interrupt(first_cpu, PPC_INTERRUPT_RESET);
314
295
/* Check LE mode */
315
296
if (val & 0x02) {
420
401
retval = sysctrl->contiguous_map;
423
printf("ERROR: unaffected IO port: %04" PRIx32 " read\n", addr);
404
printf("ERROR: unaffected IO port: %04lx read\n", (long)addr);
426
PPC_IO_DPRINTF("0x%08" PRIx32 " <= 0x%02" PRIx32 "\n",
427
addr - PPC_IO_BASE, retval);
407
PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr - PPC_IO_BASE, retval);
432
static always_inline target_phys_addr_t prep_IO_address (sysctrl_t *sysctrl,
412
static inline target_phys_addr_t prep_IO_address (sysctrl_t *sysctrl,
413
target_phys_addr_t addr)
436
415
if (sysctrl->contiguous_map == 0) {
437
416
/* 64 KB contiguous space for IOs */
515
494
#ifdef TARGET_WORDS_BIGENDIAN
516
495
ret = bswap32(ret);
518
PPC_IO_DPRINTF("0x" PADDRX " <= 0x%08" PRIx32 "\n", addr, ret);
497
PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr, ret);
523
static CPUWriteMemoryFunc *PPC_prep_io_write[] = {
502
CPUWriteMemoryFunc *PPC_prep_io_write[] = {
524
503
&PPC_prep_io_writeb,
525
504
&PPC_prep_io_writew,
526
505
&PPC_prep_io_writel,
529
static CPUReadMemoryFunc *PPC_prep_io_read[] = {
508
CPUReadMemoryFunc *PPC_prep_io_read[] = {
530
509
&PPC_prep_io_readb,
531
510
&PPC_prep_io_readw,
532
511
&PPC_prep_io_readl,
535
514
#define NVRAM_SIZE 0x2000
537
516
/* PowerPC PREP hardware initialisation */
538
static void ppc_prep_init (ram_addr_t ram_size, int vga_ram_size,
539
const char *boot_device, DisplayState *ds,
540
const char *kernel_filename,
517
static void ppc_prep_init (int ram_size, int vga_ram_size, int boot_device,
518
DisplayState *ds, const char **fd_filename,
519
int snapshot, const char *kernel_filename,
541
520
const char *kernel_cmdline,
542
521
const char *initrd_filename,
543
522
const char *cpu_model)
545
CPUState *env = NULL, *envs[MAX_CPUS];
549
527
int PPC_io_memory;
550
528
int linux_boot, i, nb_nics1, bios_size;
551
529
unsigned long bios_offset;
552
530
uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
557
BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
558
BlockDriverState *fd[MAX_FD];
560
535
sysctrl = qemu_mallocz(sizeof(sysctrl_t));
561
536
if (sysctrl == NULL)
564
539
linux_boot = (kernel_filename != NULL);
544
qemu_register_reset(&cpu_ppc_reset, env);
545
register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
547
/* Default CPU is a 604 */
567
548
if (cpu_model == NULL)
568
cpu_model = "default";
569
for (i = 0; i < smp_cpus; i++) {
570
env = cpu_init(cpu_model);
572
fprintf(stderr, "Unable to find PowerPC CPU definition\n");
575
if (env->flags & POWERPC_FLAG_RTC_CLK) {
576
/* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */
577
cpu_ppc_tb_init(env, 7812500UL);
579
/* Set time-base frequency to 100 Mhz */
580
cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
582
qemu_register_reset(&cpu_ppc_reset, env);
550
ppc_find_by_name(cpu_model, &def);
552
cpu_abort(env, "Unable to find PowerPC CPU definition\n");
554
cpu_ppc_register(env, def);
555
/* Set time-base frequency to 100 Mhz */
556
cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
586
558
/* allocate RAM */
587
559
cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
589
561
/* allocate and load BIOS */
590
562
bios_offset = ram_size + vga_ram_size;
591
if (bios_name == NULL)
592
bios_name = BIOS_FILENAME;
593
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
563
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
594
564
bios_size = load_image(buf, phys_ram_base + bios_offset);
595
565
if (bios_size < 0 || bios_size > BIOS_SIZE) {
596
566
cpu_abort(env, "qemu: could not load PPC PREP bios '%s'\n", buf);
599
if (env->nip < 0xFFF80000 && bios_size < 0x00100000) {
600
cpu_abort(env, "PowerPC 601 / 620 / 970 need a 1MB BIOS\n");
602
569
bios_size = (bios_size + 0xfff) & ~0xfff;
603
570
cpu_register_physical_memory((uint32_t)(-bios_size),
604
571
bios_size, bios_offset | IO_MEM_ROM);
666
621
// pit = pit_init(0x40, i8259[0]);
667
622
rtc_init(0x70, i8259[8]);
669
serial_init(0x3f8, i8259[4], 115200, serial_hds[0]);
624
serial_init(0x3f8, i8259[4], serial_hds[0]);
670
625
nb_nics1 = nb_nics;
671
626
if (nb_nics1 > NE2000_NB_MAX)
672
627
nb_nics1 = NE2000_NB_MAX;
673
628
for(i = 0; i < nb_nics1; i++) {
674
if (nd_table[i].model == NULL
675
|| strcmp(nd_table[i].model, "ne2k_isa") == 0) {
629
if (nd_table[0].model == NULL
630
|| strcmp(nd_table[0].model, "ne2k_isa") == 0) {
676
631
isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
632
} else if (strcmp(nd_table[0].model, "?") == 0) {
633
fprintf(stderr, "qemu: Supported NICs: ne2k_isa\n");
678
pci_nic_init(pci_bus, &nd_table[i], -1);
637
cpu_abort(env, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
682
if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
683
fprintf(stderr, "qemu: too many IDE bus\n");
687
for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
688
index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
690
hd[i] = drives_table[index].bdrv;
695
for(i = 0; i < MAX_IDE_BUS; i++) {
642
for(i = 0; i < 2; i++) {
696
643
isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]],
644
bs_table[2 * i], bs_table[2 * i + 1]);
700
646
i8042_init(i8259[1], i8259[12], 0x60);
705
for(i = 0; i < MAX_FD; i++) {
706
index = drive_get_index(IF_FLOPPY, 0, i);
708
fd[i] = drives_table[index].bdrv;
712
fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
651
fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table);
714
653
/* Register speaker port */
715
654
register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL);
716
655
register_ioport_write(0x61, 1, 1, speaker_ioport_write, NULL);
717
656
/* Register fake IO ports for PREP */
718
sysctrl->reset_irq = first_cpu->irq_inputs[PPC6xx_INPUT_HRESET];
719
657
register_ioport_read(0x398, 2, 1, &PREP_io_read, sysctrl);
720
658
register_ioport_write(0x398, 2, 1, &PREP_io_write, sysctrl);
721
659
/* System control ports */
738
676
usb_ohci_init_pci(pci_bus, 3, -1);
741
m48t59 = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59);
679
nvram = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59);
744
sysctrl->nvram = m48t59;
682
sysctrl->nvram = nvram;
746
684
/* Initialise NVRAM */
747
nvram.opaque = m48t59;
748
nvram.read_fn = &m48t59_read;
749
nvram.write_fn = &m48t59_write;
750
PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,
685
PPC_NVRAM_set_params(nvram, NVRAM_SIZE, "PREP", ram_size, boot_device,
751
686
kernel_base, kernel_size,
753
688
initrd_base, initrd_size,