~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to hw/ppc405_boards.c

  • Committer: Blue Swirl
  • Date: 2009-08-31 15:14:40 UTC
  • Revision ID: git-v1:528e93a9787ccfc59582a44035f5f342caf5b84f
Fix breakage due to __thread

Thread-local storage is not supported on all hosts.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "sysemu.h"
30
30
#include "block.h"
31
31
#include "boards.h"
32
 
 
33
 
extern int loglevel;
34
 
extern FILE *logfile;
 
32
#include "qemu-log.h"
35
33
 
36
34
#define BIOS_FILENAME "ppc405_rom.bin"
37
 
#undef BIOS_SIZE
38
35
#define BIOS_SIZE (2048 * 1024)
39
36
 
40
37
#define KERNEL_LOAD_ADDR 0x00000000
56
53
 */
57
54
typedef struct ref405ep_fpga_t ref405ep_fpga_t;
58
55
struct ref405ep_fpga_t {
59
 
    uint32_t base;
60
56
    uint8_t reg0;
61
57
    uint8_t reg1;
62
58
};
67
63
    uint32_t ret;
68
64
 
69
65
    fpga = opaque;
70
 
    addr -= fpga->base;
71
66
    switch (addr) {
72
67
    case 0x0:
73
68
        ret = fpga->reg0;
89
84
    ref405ep_fpga_t *fpga;
90
85
 
91
86
    fpga = opaque;
92
 
    addr -= fpga->base;
93
87
    switch (addr) {
94
88
    case 0x0:
95
89
        /* Read only */
134
128
static void ref405ep_fpga_writel (void *opaque,
135
129
                                  target_phys_addr_t addr, uint32_t value)
136
130
{
137
 
    ref405ep_fpga_writel(opaque, addr, (value >> 24) & 0xFF);
138
 
    ref405ep_fpga_writel(opaque, addr + 1, (value >> 16) & 0xFF);
139
 
    ref405ep_fpga_writel(opaque, addr + 2, (value >> 8) & 0xFF);
 
131
    ref405ep_fpga_writeb(opaque, addr, (value >> 24) & 0xFF);
 
132
    ref405ep_fpga_writeb(opaque, addr + 1, (value >> 16) & 0xFF);
 
133
    ref405ep_fpga_writeb(opaque, addr + 2, (value >> 8) & 0xFF);
140
134
    ref405ep_fpga_writeb(opaque, addr + 3, value & 0xFF);
141
135
}
142
136
 
143
 
static CPUReadMemoryFunc *ref405ep_fpga_read[] = {
 
137
static CPUReadMemoryFunc * const ref405ep_fpga_read[] = {
144
138
    &ref405ep_fpga_readb,
145
139
    &ref405ep_fpga_readw,
146
140
    &ref405ep_fpga_readl,
147
141
};
148
142
 
149
 
static CPUWriteMemoryFunc *ref405ep_fpga_write[] = {
 
143
static CPUWriteMemoryFunc * const ref405ep_fpga_write[] = {
150
144
    &ref405ep_fpga_writeb,
151
145
    &ref405ep_fpga_writew,
152
146
    &ref405ep_fpga_writel,
167
161
    int fpga_memory;
168
162
 
169
163
    fpga = qemu_mallocz(sizeof(ref405ep_fpga_t));
170
 
    if (fpga != NULL) {
171
 
        fpga->base = base;
172
 
        fpga_memory = cpu_register_io_memory(0, ref405ep_fpga_read,
173
 
                                             ref405ep_fpga_write, fpga);
174
 
        cpu_register_physical_memory(base, 0x00000100, fpga_memory);
175
 
        ref405ep_fpga_reset(fpga);
176
 
        qemu_register_reset(&ref405ep_fpga_reset, fpga);
177
 
    }
 
164
    fpga_memory = cpu_register_io_memory(ref405ep_fpga_read,
 
165
                                         ref405ep_fpga_write, fpga);
 
166
    cpu_register_physical_memory(base, 0x00000100, fpga_memory);
 
167
    ref405ep_fpga_reset(fpga);
 
168
    qemu_register_reset(&ref405ep_fpga_reset, fpga);
178
169
}
179
170
 
180
 
static void ref405ep_init (ram_addr_t ram_size, int vga_ram_size,
181
 
                           const char *boot_device, DisplayState *ds,
 
171
static void ref405ep_init (ram_addr_t ram_size,
 
172
                           const char *boot_device,
182
173
                           const char *kernel_filename,
183
174
                           const char *kernel_cmdline,
184
175
                           const char *initrd_filename,
185
176
                           const char *cpu_model)
186
177
{
187
 
    char buf[1024];
 
178
    char *filename;
188
179
    ppc4xx_bd_info_t bd;
189
180
    CPUPPCState *env;
190
181
    qemu_irq *pic;
197
188
    int linux_boot;
198
189
    int fl_idx, fl_sectors, len;
199
190
    int ppc_boot_device = boot_device[0];
200
 
    int index;
 
191
    DriveInfo *dinfo;
201
192
 
202
193
    /* XXX: fix this */
203
 
    ram_bases[0] = 0x00000000;
 
194
    ram_bases[0] = qemu_ram_alloc(0x08000000);
204
195
    ram_sizes[0] = 0x08000000;
205
196
    ram_bases[1] = 0x00000000;
206
197
    ram_sizes[1] = 0x00000000;
208
199
#ifdef DEBUG_BOARD_INIT
209
200
    printf("%s: register cpu\n", __func__);
210
201
#endif
211
 
    env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic, &sram_offset,
 
202
    env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
212
203
                        kernel_filename == NULL ? 0 : 1);
213
204
    /* allocate SRAM */
 
205
    sram_size = 512 * 1024;
 
206
    sram_offset = qemu_ram_alloc(sram_size);
214
207
#ifdef DEBUG_BOARD_INIT
215
208
    printf("%s: register SRAM at offset %08lx\n", __func__, sram_offset);
216
209
#endif
217
 
    sram_size = 512 * 1024;
218
210
    cpu_register_physical_memory(0xFFF00000, sram_size,
219
211
                                 sram_offset | IO_MEM_RAM);
220
212
    /* allocate and load BIOS */
221
213
#ifdef DEBUG_BOARD_INIT
222
214
    printf("%s: register BIOS\n", __func__);
223
215
#endif
224
 
    bios_offset = sram_offset + sram_size;
225
216
    fl_idx = 0;
226
217
#ifdef USE_FLASH_BIOS
227
 
    index = drive_get_index(IF_PFLASH, 0, fl_idx);
228
 
    if (index != -1) {
229
 
        bios_size = bdrv_getlength(drives_table[index].bdrv);
 
218
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
 
219
    if (dinfo) {
 
220
        bios_size = bdrv_getlength(dinfo->bdrv);
 
221
        bios_offset = qemu_ram_alloc(bios_size);
230
222
        fl_sectors = (bios_size + 65535) >> 16;
231
223
#ifdef DEBUG_BOARD_INIT
232
 
        printf("Register parallel flash %d size " ADDRX " at offset %08lx "
233
 
               " addr " ADDRX " '%s' %d\n",
 
224
        printf("Register parallel flash %d size " TARGET_FMT_lx
 
225
               " at offset %08lx addr " TARGET_FMT_lx " '%s' %d\n",
234
226
               fl_idx, bios_size, bios_offset, -bios_size,
235
 
               bdrv_get_device_name(drives_table[index].bdrv), fl_sectors);
 
227
               bdrv_get_device_name(dinfo->bdrv), fl_sectors);
236
228
#endif
237
229
        pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
238
 
                              drives_table[index].bdrv, 65536, fl_sectors, 1,
 
230
                              dinfo->bdrv, 65536, fl_sectors, 1,
239
231
                              2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
240
232
        fl_idx++;
241
233
    } else
244
236
#ifdef DEBUG_BOARD_INIT
245
237
        printf("Load BIOS from file\n");
246
238
#endif
 
239
        bios_offset = qemu_ram_alloc(BIOS_SIZE);
247
240
        if (bios_name == NULL)
248
241
            bios_name = BIOS_FILENAME;
249
 
        snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
250
 
        bios_size = load_image(buf, phys_ram_base + bios_offset);
 
242
        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
 
243
        if (filename) {
 
244
            bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
 
245
            qemu_free(filename);
 
246
        } else {
 
247
            bios_size = -1;
 
248
        }
251
249
        if (bios_size < 0 || bios_size > BIOS_SIZE) {
252
 
            fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
 
250
            fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n",
 
251
                    bios_name);
253
252
            exit(1);
254
253
        }
255
254
        bios_size = (bios_size + 0xfff) & ~0xfff;
256
255
        cpu_register_physical_memory((uint32_t)(-bios_size),
257
256
                                     bios_size, bios_offset | IO_MEM_ROM);
258
257
    }
259
 
    bios_offset += bios_size;
260
258
    /* Register FPGA */
261
259
#ifdef DEBUG_BOARD_INIT
262
260
    printf("%s: register FPGA\n", __func__);
302
300
        env->gpr[3] = bdloc;
303
301
        kernel_base = KERNEL_LOAD_ADDR;
304
302
        /* now we can load the kernel */
305
 
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
 
303
        kernel_size = load_image_targphys(kernel_filename, kernel_base,
 
304
                                          ram_size - kernel_base);
306
305
        if (kernel_size < 0) {
307
306
            fprintf(stderr, "qemu: could not load kernel '%s'\n",
308
307
                    kernel_filename);
309
308
            exit(1);
310
309
        }
311
 
        printf("Load kernel size " TARGET_FMT_ld " at " TARGET_FMT_lx
312
 
               " %02x %02x %02x %02x\n", kernel_size, kernel_base,
313
 
               *(char *)(phys_ram_base + kernel_base),
314
 
               *(char *)(phys_ram_base + kernel_base + 1),
315
 
               *(char *)(phys_ram_base + kernel_base + 2),
316
 
               *(char *)(phys_ram_base + kernel_base + 3));
 
310
        printf("Load kernel size " TARGET_FMT_ld " at " TARGET_FMT_lx,
 
311
               kernel_size, kernel_base);
317
312
        /* load initrd */
318
313
        if (initrd_filename) {
319
314
            initrd_base = INITRD_LOAD_ADDR;
320
 
            initrd_size = load_image(initrd_filename,
321
 
                                     phys_ram_base + initrd_base);
 
315
            initrd_size = load_image_targphys(initrd_filename, initrd_base,
 
316
                                              ram_size - initrd_base);
322
317
            if (initrd_size < 0) {
323
318
                fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
324
319
                        initrd_filename);
334
329
        if (kernel_cmdline != NULL) {
335
330
            len = strlen(kernel_cmdline);
336
331
            bdloc -= ((len + 255) & ~255);
337
 
            memcpy(phys_ram_base + bdloc, kernel_cmdline, len + 1);
 
332
            cpu_physical_memory_write(bdloc, (void *)kernel_cmdline, len + 1);
338
333
            env->gpr[6] = bdloc;
339
334
            env->gpr[7] = bdloc + len;
340
335
        } else {
352
347
#ifdef DEBUG_BOARD_INIT
353
348
    printf("%s: Done\n", __func__);
354
349
#endif
355
 
    printf("bdloc %016lx %s\n",
356
 
           (unsigned long)bdloc, (char *)(phys_ram_base + bdloc));
 
350
    printf("bdloc %016lx\n", (unsigned long)bdloc);
357
351
}
358
352
 
359
 
QEMUMachine ref405ep_machine = {
360
 
    "ref405ep",
361
 
    "ref405ep",
362
 
    ref405ep_init,
363
 
    (128 * 1024 * 1024 + 4096 + 512 * 1024 + BIOS_SIZE) | RAMSIZE_FIXED,
 
353
static QEMUMachine ref405ep_machine = {
 
354
    .name = "ref405ep",
 
355
    .desc = "ref405ep",
 
356
    .init = ref405ep_init,
364
357
};
365
358
 
366
359
/*****************************************************************************/
384
377
 */
385
378
typedef struct taihu_cpld_t taihu_cpld_t;
386
379
struct taihu_cpld_t {
387
 
    uint32_t base;
388
380
    uint8_t reg0;
389
381
    uint8_t reg1;
390
382
};
395
387
    uint32_t ret;
396
388
 
397
389
    cpld = opaque;
398
 
    addr -= cpld->base;
399
390
    switch (addr) {
400
391
    case 0x0:
401
392
        ret = cpld->reg0;
417
408
    taihu_cpld_t *cpld;
418
409
 
419
410
    cpld = opaque;
420
 
    addr -= cpld->base;
421
411
    switch (addr) {
422
412
    case 0x0:
423
413
        /* Read only */
468
458
    taihu_cpld_writeb(opaque, addr + 3, value & 0xFF);
469
459
}
470
460
 
471
 
static CPUReadMemoryFunc *taihu_cpld_read[] = {
 
461
static CPUReadMemoryFunc * const taihu_cpld_read[] = {
472
462
    &taihu_cpld_readb,
473
463
    &taihu_cpld_readw,
474
464
    &taihu_cpld_readl,
475
465
};
476
466
 
477
 
static CPUWriteMemoryFunc *taihu_cpld_write[] = {
 
467
static CPUWriteMemoryFunc * const taihu_cpld_write[] = {
478
468
    &taihu_cpld_writeb,
479
469
    &taihu_cpld_writew,
480
470
    &taihu_cpld_writel,
495
485
    int cpld_memory;
496
486
 
497
487
    cpld = qemu_mallocz(sizeof(taihu_cpld_t));
498
 
    if (cpld != NULL) {
499
 
        cpld->base = base;
500
 
        cpld_memory = cpu_register_io_memory(0, taihu_cpld_read,
501
 
                                             taihu_cpld_write, cpld);
502
 
        cpu_register_physical_memory(base, 0x00000100, cpld_memory);
503
 
        taihu_cpld_reset(cpld);
504
 
        qemu_register_reset(&taihu_cpld_reset, cpld);
505
 
    }
 
488
    cpld_memory = cpu_register_io_memory(taihu_cpld_read,
 
489
                                         taihu_cpld_write, cpld);
 
490
    cpu_register_physical_memory(base, 0x00000100, cpld_memory);
 
491
    taihu_cpld_reset(cpld);
 
492
    qemu_register_reset(&taihu_cpld_reset, cpld);
506
493
}
507
494
 
508
 
static void taihu_405ep_init(ram_addr_t ram_size, int vga_ram_size,
509
 
                             const char *boot_device, DisplayState *ds,
 
495
static void taihu_405ep_init(ram_addr_t ram_size,
 
496
                             const char *boot_device,
510
497
                             const char *kernel_filename,
511
498
                             const char *kernel_cmdline,
512
499
                             const char *initrd_filename,
513
500
                             const char *cpu_model)
514
501
{
515
 
    char buf[1024];
 
502
    char *filename;
516
503
    CPUPPCState *env;
517
504
    qemu_irq *pic;
518
505
    ram_addr_t bios_offset;
522
509
    int linux_boot;
523
510
    int fl_idx, fl_sectors;
524
511
    int ppc_boot_device = boot_device[0];
525
 
    int index;
 
512
    DriveInfo *dinfo;
526
513
 
527
514
    /* RAM is soldered to the board so the size cannot be changed */
528
 
    ram_bases[0] = 0x00000000;
 
515
    ram_bases[0] = qemu_ram_alloc(0x04000000);
529
516
    ram_sizes[0] = 0x04000000;
530
 
    ram_bases[1] = 0x04000000;
 
517
    ram_bases[1] = qemu_ram_alloc(0x04000000);
531
518
    ram_sizes[1] = 0x04000000;
 
519
    ram_size = 0x08000000;
532
520
#ifdef DEBUG_BOARD_INIT
533
521
    printf("%s: register cpu\n", __func__);
534
522
#endif
535
 
    env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic, &bios_offset,
 
523
    env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
536
524
                        kernel_filename == NULL ? 0 : 1);
537
525
    /* allocate and load BIOS */
538
526
#ifdef DEBUG_BOARD_INIT
540
528
#endif
541
529
    fl_idx = 0;
542
530
#if defined(USE_FLASH_BIOS)
543
 
    index = drive_get_index(IF_PFLASH, 0, fl_idx);
544
 
    if (index != -1) {
545
 
        bios_size = bdrv_getlength(drives_table[index].bdrv);
 
531
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
 
532
    if (dinfo) {
 
533
        bios_size = bdrv_getlength(dinfo->bdrv);
546
534
        /* XXX: should check that size is 2MB */
547
535
        //        bios_size = 2 * 1024 * 1024;
548
536
        fl_sectors = (bios_size + 65535) >> 16;
 
537
        bios_offset = qemu_ram_alloc(bios_size);
549
538
#ifdef DEBUG_BOARD_INIT
550
 
        printf("Register parallel flash %d size " ADDRX " at offset %08lx "
551
 
               " addr " ADDRX " '%s' %d\n",
 
539
        printf("Register parallel flash %d size " TARGET_FMT_lx
 
540
               " at offset %08lx addr " TARGET_FMT_lx " '%s' %d\n",
552
541
               fl_idx, bios_size, bios_offset, -bios_size,
553
 
               bdrv_get_device_name(drives_table[index].bdrv), fl_sectors);
 
542
               bdrv_get_device_name(dinfo->bdrv), fl_sectors);
554
543
#endif
555
544
        pflash_cfi02_register((uint32_t)(-bios_size), bios_offset,
556
 
                              drives_table[index].bdrv, 65536, fl_sectors, 1,
 
545
                              dinfo->bdrv, 65536, fl_sectors, 1,
557
546
                              4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
558
547
        fl_idx++;
559
548
    } else
564
553
#endif
565
554
        if (bios_name == NULL)
566
555
            bios_name = BIOS_FILENAME;
567
 
        snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
568
 
        bios_size = load_image(buf, phys_ram_base + bios_offset);
 
556
        bios_offset = qemu_ram_alloc(BIOS_SIZE);
 
557
        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
 
558
        if (filename) {
 
559
            bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
 
560
        } else {
 
561
            bios_size = -1;
 
562
        }
569
563
        if (bios_size < 0 || bios_size > BIOS_SIZE) {
570
 
            fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
 
564
            fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n",
 
565
                    bios_name);
571
566
            exit(1);
572
567
        }
573
568
        bios_size = (bios_size + 0xfff) & ~0xfff;
574
569
        cpu_register_physical_memory((uint32_t)(-bios_size),
575
570
                                     bios_size, bios_offset | IO_MEM_ROM);
576
571
    }
577
 
    bios_offset += bios_size;
578
572
    /* Register Linux flash */
579
 
    index = drive_get_index(IF_PFLASH, 0, fl_idx);
580
 
    if (index != -1) {
581
 
        bios_size = bdrv_getlength(drives_table[index].bdrv);
 
573
    dinfo = drive_get(IF_PFLASH, 0, fl_idx);
 
574
    if (dinfo) {
 
575
        bios_size = bdrv_getlength(dinfo->bdrv);
582
576
        /* XXX: should check that size is 32MB */
583
577
        bios_size = 32 * 1024 * 1024;
584
578
        fl_sectors = (bios_size + 65535) >> 16;
585
579
#ifdef DEBUG_BOARD_INIT
586
 
        printf("Register parallel flash %d size " ADDRX " at offset %08lx "
587
 
               " addr " ADDRX " '%s'\n",
 
580
        printf("Register parallel flash %d size " TARGET_FMT_lx
 
581
               " at offset %08lx  addr " TARGET_FMT_lx " '%s'\n",
588
582
               fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000,
589
 
               bdrv_get_device_name(drives_table[index].bdrv));
 
583
               bdrv_get_device_name(dinfo->bdrv));
590
584
#endif
 
585
        bios_offset = qemu_ram_alloc(bios_size);
591
586
        pflash_cfi02_register(0xfc000000, bios_offset,
592
 
                              drives_table[index].bdrv, 65536, fl_sectors, 1,
 
587
                              dinfo->bdrv, 65536, fl_sectors, 1,
593
588
                              4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA);
594
589
        fl_idx++;
595
590
    }
606
601
#endif
607
602
        kernel_base = KERNEL_LOAD_ADDR;
608
603
        /* now we can load the kernel */
609
 
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
 
604
        kernel_size = load_image_targphys(kernel_filename, kernel_base,
 
605
                                          ram_size - kernel_base);
610
606
        if (kernel_size < 0) {
611
607
            fprintf(stderr, "qemu: could not load kernel '%s'\n",
612
608
                    kernel_filename);
615
611
        /* load initrd */
616
612
        if (initrd_filename) {
617
613
            initrd_base = INITRD_LOAD_ADDR;
618
 
            initrd_size = load_image(initrd_filename,
619
 
                                     phys_ram_base + initrd_base);
 
614
            initrd_size = load_image_targphys(initrd_filename, initrd_base,
 
615
                                              ram_size - initrd_base);
620
616
            if (initrd_size < 0) {
621
617
                fprintf(stderr,
622
618
                        "qemu: could not load initial ram disk '%s'\n",
639
635
#endif
640
636
}
641
637
 
642
 
QEMUMachine taihu_machine = {
643
 
    "taihu",
644
 
    "taihu",
645
 
    taihu_405ep_init,
646
 
    (128 * 1024 * 1024 + 4096 + BIOS_SIZE + 32 * 1024 * 1024) | RAMSIZE_FIXED,
 
638
static QEMUMachine taihu_machine = {
 
639
    .name = "taihu",
 
640
    .desc = "taihu",
 
641
    .init = taihu_405ep_init,
647
642
};
 
643
 
 
644
static void ppc405_machine_init(void)
 
645
{
 
646
    qemu_register_machine(&ref405ep_machine);
 
647
    qemu_register_machine(&taihu_machine);
 
648
}
 
649
 
 
650
machine_init(ppc405_machine_init);