~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to hw/ppc_prep.c

  • Committer: blueswir1
  • Date: 2007-09-25 17:28:42 UTC
  • Revision ID: git-v1:c2efc95d45fd4c76d4650a34a2a2676b87a93ac4
 Fix monitor expressions


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3238 c046a42c-6fe2-441c-8c8c-71466251a162

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
 * THE SOFTWARE.
23
23
 */
24
 
#include "hw.h"
25
 
#include "nvram.h"
26
 
#include "pc.h"
27
 
#include "fdc.h"
28
 
#include "net.h"
29
 
#include "sysemu.h"
30
 
#include "isa.h"
31
 
#include "pci.h"
32
 
#include "ppc.h"
33
 
#include "boards.h"
34
 
#include "qemu-log.h"
 
24
#include "vl.h"
35
25
 
36
26
//#define HARD_DEBUG_PPC_IO
37
27
//#define DEBUG_PPC_IO
38
28
 
39
 
/* SMP is not enabled, for now */
40
 
#define MAX_CPUS 1
41
 
 
42
 
#define MAX_IDE_BUS 2
43
 
 
44
29
#define BIOS_FILENAME "ppc_rom.bin"
45
30
#define KERNEL_LOAD_ADDR 0x01000000
46
31
#define INITRD_LOAD_ADDR 0x01800000
47
32
 
 
33
extern int loglevel;
 
34
extern FILE *logfile;
 
35
 
48
36
#if defined (HARD_DEBUG_PPC_IO) && !defined (DEBUG_PPC_IO)
49
37
#define DEBUG_PPC_IO
50
38
#endif
84
72
/* ISA IO ports bridge */
85
73
#define PPC_IO_BASE 0x80000000
86
74
 
87
 
#if 0
88
75
/* Speaker port 0x61 */
89
 
static int speaker_data_on;
90
 
static int dummy_refresh_clock;
91
 
#endif
 
76
int speaker_data_on;
 
77
int dummy_refresh_clock;
92
78
 
93
79
static void speaker_ioport_write (void *opaque, uint32_t addr, uint32_t val)
94
80
{
115
101
static void _PPC_intack_write (void *opaque,
116
102
                               target_phys_addr_t addr, uint32_t value)
117
103
{
118
 
//    printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
 
104
    //    printf("%s: 0x%08x => 0x%08x\n", __func__, addr, value);
119
105
}
120
106
 
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)
122
108
{
123
109
    uint32_t retval = 0;
124
110
 
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);
128
114
 
129
115
    return retval;
130
116
}
194
180
static void PPC_XCSR_writeb (void *opaque,
195
181
                             target_phys_addr_t addr, uint32_t value)
196
182
{
197
 
    printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
 
183
    printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value);
198
184
}
199
185
 
200
186
static void PPC_XCSR_writew (void *opaque,
203
189
#ifdef TARGET_WORDS_BIGENDIAN
204
190
    value = bswap16(value);
205
191
#endif
206
 
    printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
 
192
    printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value);
207
193
}
208
194
 
209
195
static void PPC_XCSR_writel (void *opaque,
212
198
#ifdef TARGET_WORDS_BIGENDIAN
213
199
    value = bswap32(value);
214
200
#endif
215
 
    printf("%s: 0x" PADDRX " => 0x%08" PRIx32 "\n", __func__, addr, value);
 
201
    printf("%s: 0x%08lx => 0x%08x\n", __func__, (long)addr, value);
216
202
}
217
203
 
218
204
static uint32_t PPC_XCSR_readb (void *opaque, target_phys_addr_t addr)
219
205
{
220
206
    uint32_t retval = 0;
221
207
 
222
 
    printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
 
208
    printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval);
223
209
 
224
210
    return retval;
225
211
}
228
214
{
229
215
    uint32_t retval = 0;
230
216
 
231
 
    printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
 
217
    printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval);
232
218
#ifdef TARGET_WORDS_BIGENDIAN
233
219
    retval = bswap16(retval);
234
220
#endif
240
226
{
241
227
    uint32_t retval = 0;
242
228
 
243
 
    printf("%s: 0x" PADDRX " <= %08" PRIx32 "\n", __func__, addr, retval);
 
229
    printf("%s: 0x%08lx <= %d\n", __func__, (long)addr, retval);
244
230
#ifdef TARGET_WORDS_BIGENDIAN
245
231
    retval = bswap32(retval);
246
232
#endif
263
249
 
264
250
/* Fake super-io ports for PREP platform (Intel 82378ZB) */
265
251
typedef struct sysctrl_t {
266
 
    qemu_irq reset_irq;
267
252
    m48t59_t *nvram;
268
253
    uint8_t state;
269
254
    uint8_t syscontrol;
282
267
{
283
268
    sysctrl_t *sysctrl = opaque;
284
269
 
285
 
    PPC_IO_DPRINTF("0x%08" PRIx32 " => 0x%02" PRIx32 "\n", addr - PPC_IO_BASE,
286
 
                   val);
 
270
    PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr - PPC_IO_BASE, val);
287
271
    sysctrl->fake_io[addr - 0x0398] = val;
288
272
}
289
273
 
291
275
{
292
276
    sysctrl_t *sysctrl = opaque;
293
277
 
294
 
    PPC_IO_DPRINTF("0x%08" PRIx32 " <= 0x%02" PRIx32 "\n", addr - PPC_IO_BASE,
 
278
    PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr - PPC_IO_BASE,
295
279
                   sysctrl->fake_io[addr - 0x0398]);
296
280
    return sysctrl->fake_io[addr - 0x0398];
297
281
}
300
284
{
301
285
    sysctrl_t *sysctrl = opaque;
302
286
 
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);
305
288
    switch (addr) {
306
289
    case 0x0092:
307
290
        /* Special port 92 */
308
291
        /* Check soft reset asked */
309
292
        if (val & 0x01) {
310
 
            qemu_irq_raise(sysctrl->reset_irq);
311
 
        } else {
312
 
            qemu_irq_lower(sysctrl->reset_irq);
 
293
            //            cpu_interrupt(first_cpu, PPC_INTERRUPT_RESET);
313
294
        }
314
295
        /* Check LE mode */
315
296
        if (val & 0x02) {
357
338
        sysctrl->contiguous_map = val & 0x01;
358
339
        break;
359
340
    default:
360
 
        printf("ERROR: unaffected IO port write: %04" PRIx32
361
 
               " => %02" PRIx32"\n", addr, val);
 
341
        printf("ERROR: unaffected IO port write: %04lx => %02x\n",
 
342
               (long)addr, val);
362
343
        break;
363
344
    }
364
345
}
420
401
        retval = sysctrl->contiguous_map;
421
402
        break;
422
403
    default:
423
 
        printf("ERROR: unaffected IO port: %04" PRIx32 " read\n", addr);
 
404
        printf("ERROR: unaffected IO port: %04lx read\n", (long)addr);
424
405
        break;
425
406
    }
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);
428
408
 
429
409
    return retval;
430
410
}
431
411
 
432
 
static always_inline target_phys_addr_t prep_IO_address (sysctrl_t *sysctrl,
433
 
                                                         target_phys_addr_t
434
 
                                                         addr)
 
412
static inline target_phys_addr_t prep_IO_address (sysctrl_t *sysctrl,
 
413
                                                  target_phys_addr_t addr)
435
414
{
436
415
    if (sysctrl->contiguous_map == 0) {
437
416
        /* 64 KB contiguous space for IOs */
473
452
#ifdef TARGET_WORDS_BIGENDIAN
474
453
    value = bswap16(value);
475
454
#endif
476
 
    PPC_IO_DPRINTF("0x" PADDRX " => 0x%08" PRIx32 "\n", addr, value);
 
455
    PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr, value);
477
456
    cpu_outw(NULL, addr, value);
478
457
}
479
458
 
487
466
#ifdef TARGET_WORDS_BIGENDIAN
488
467
    ret = bswap16(ret);
489
468
#endif
490
 
    PPC_IO_DPRINTF("0x" PADDRX " <= 0x%08" PRIx32 "\n", addr, ret);
 
469
    PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr, ret);
491
470
 
492
471
    return ret;
493
472
}
501
480
#ifdef TARGET_WORDS_BIGENDIAN
502
481
    value = bswap32(value);
503
482
#endif
504
 
    PPC_IO_DPRINTF("0x" PADDRX " => 0x%08" PRIx32 "\n", addr, value);
 
483
    PPC_IO_DPRINTF("0x%08lx => 0x%08x\n", (long)addr, value);
505
484
    cpu_outl(NULL, addr, value);
506
485
}
507
486
 
515
494
#ifdef TARGET_WORDS_BIGENDIAN
516
495
    ret = bswap32(ret);
517
496
#endif
518
 
    PPC_IO_DPRINTF("0x" PADDRX " <= 0x%08" PRIx32 "\n", addr, ret);
 
497
    PPC_IO_DPRINTF("0x%08lx <= 0x%08x\n", (long)addr, ret);
519
498
 
520
499
    return ret;
521
500
}
522
501
 
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,
527
506
};
528
507
 
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
536
515
 
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)
544
523
{
545
 
    CPUState *env = NULL, *envs[MAX_CPUS];
 
524
    CPUState *env;
546
525
    char buf[1024];
547
 
    nvram_t nvram;
548
 
    m48t59_t *m48t59;
 
526
    m48t59_t *nvram;
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;
 
531
    ppc_def_t *def;
553
532
    PCIBus *pci_bus;
554
533
    qemu_irq *i8259;
555
 
    int ppc_boot_device;
556
 
    int index;
557
 
    BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
558
 
    BlockDriverState *fd[MAX_FD];
559
534
 
560
535
    sysctrl = qemu_mallocz(sizeof(sysctrl_t));
561
536
    if (sysctrl == NULL)
564
539
    linux_boot = (kernel_filename != NULL);
565
540
 
566
541
    /* init CPUs */
 
542
 
 
543
    env = cpu_init();
 
544
    qemu_register_reset(&cpu_ppc_reset, env);
 
545
    register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
 
546
 
 
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);
571
 
        if (!env) {
572
 
            fprintf(stderr, "Unable to find PowerPC CPU definition\n");
573
 
            exit(1);
574
 
        }
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);
578
 
        } else {
579
 
            /* Set time-base frequency to 100 Mhz */
580
 
            cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
581
 
        }
582
 
        qemu_register_reset(&cpu_ppc_reset, env);
583
 
        envs[i] = env;
 
549
        cpu_model = "604";
 
550
    ppc_find_by_name(cpu_model, &def);
 
551
    if (def == NULL) {
 
552
        cpu_abort(env, "Unable to find PowerPC CPU definition\n");
584
553
    }
 
554
    cpu_ppc_register(env, def);
 
555
    /* Set time-base frequency to 100 Mhz */
 
556
    cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
585
557
 
586
558
    /* allocate RAM */
587
559
    cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
588
560
 
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);
597
567
        exit(1);
598
568
    }
599
 
    if (env->nip < 0xFFF80000 && bios_size < 0x00100000) {
600
 
        cpu_abort(env, "PowerPC 601 / 620 / 970 need a 1MB BIOS\n");
601
 
    }
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);
626
593
            initrd_base = 0;
627
594
            initrd_size = 0;
628
595
        }
629
 
        ppc_boot_device = 'm';
 
596
        boot_device = 'm';
630
597
    } else {
631
598
        kernel_base = 0;
632
599
        kernel_size = 0;
633
600
        initrd_base = 0;
634
601
        initrd_size = 0;
635
 
        ppc_boot_device = '\0';
636
 
        /* For now, OHW cannot boot from the network. */
637
 
        for (i = 0; boot_device[i] != '\0'; i++) {
638
 
            if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {
639
 
                ppc_boot_device = boot_device[i];
640
 
                break;
641
 
            }
642
 
        }
643
 
        if (ppc_boot_device == '\0') {
644
 
            fprintf(stderr, "No valid boot device for Mac99 machine\n");
645
 
            exit(1);
646
 
        }
647
602
    }
648
603
 
649
604
    isa_mem_base = 0xc0000000;
666
621
    //    pit = pit_init(0x40, i8259[0]);
667
622
    rtc_init(0x70, i8259[8]);
668
623
 
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");
 
634
            exit (1);
677
635
        } else {
678
 
            pci_nic_init(pci_bus, &nd_table[i], -1);
 
636
            /* Why ? */
 
637
            cpu_abort(env, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
 
638
            exit (1);
679
639
        }
680
640
    }
681
641
 
682
 
    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
683
 
        fprintf(stderr, "qemu: too many IDE bus\n");
684
 
        exit(1);
685
 
    }
686
 
 
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);
689
 
        if (index != -1)
690
 
            hd[i] = drives_table[index].bdrv;
691
 
        else
692
 
            hd[i] = NULL;
693
 
    }
694
 
 
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]],
697
 
                     hd[2 * i],
698
 
                     hd[2 * i + 1]);
 
644
                     bs_table[2 * i], bs_table[2 * i + 1]);
699
645
    }
700
646
    i8042_init(i8259[1], i8259[12], 0x60);
701
647
    DMA_init(1);
702
648
    //    AUD_init();
703
649
    //    SB16_init();
704
650
 
705
 
    for(i = 0; i < MAX_FD; i++) {
706
 
        index = drive_get_index(IF_FLOPPY, 0, i);
707
 
        if (index != -1)
708
 
            fd[i] = drives_table[index].bdrv;
709
 
        else
710
 
            fd[i] = NULL;
711
 
    }
712
 
    fdctrl_init(i8259[6], 2, 0, 0x3f0, fd);
 
651
    fdctrl_init(i8259[6], 2, 0, 0x3f0, fd_table);
713
652
 
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);
739
677
    }
740
678
 
741
 
    m48t59 = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59);
742
 
    if (m48t59 == NULL)
 
679
    nvram = m48t59_init(i8259[8], 0, 0x0074, NVRAM_SIZE, 59);
 
680
    if (nvram == NULL)
743
681
        return;
744
 
    sysctrl->nvram = m48t59;
 
682
    sysctrl->nvram = nvram;
745
683
 
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,
752
687
                         kernel_cmdline,
753
688
                         initrd_base, initrd_size,
760
695
}
761
696
 
762
697
QEMUMachine prep_machine = {
763
 
    .name = "prep",
764
 
    .desc = "PowerPC PREP platform",
765
 
    .init = ppc_prep_init,
766
 
    .ram_require = BIOS_SIZE + VGA_RAM_SIZE,
767
 
    .max_cpus = MAX_CPUS,
 
698
    "prep",
 
699
    "PowerPC PREP platform",
 
700
    ppc_prep_init,
768
701
};