134
128
static void ref405ep_fpga_writel (void *opaque,
135
129
target_phys_addr_t addr, uint32_t value)
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);
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,
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,
169
163
fpga = qemu_mallocz(sizeof(ref405ep_fpga_t));
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);
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);
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)
188
179
ppc4xx_bd_info_t bd;
189
180
CPUPPCState *env;
198
189
int fl_idx, fl_sectors, len;
199
190
int ppc_boot_device = boot_device[0];
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__);
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);
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__);
224
bios_offset = sram_offset + sram_size;
226
217
#ifdef USE_FLASH_BIOS
227
index = drive_get_index(IF_PFLASH, 0, fl_idx);
229
bios_size = bdrv_getlength(drives_table[index].bdrv);
218
dinfo = drive_get(IF_PFLASH, 0, fl_idx);
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);
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);
244
236
#ifdef DEBUG_BOARD_INIT
245
237
printf("Load BIOS from file\n");
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);
244
bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
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",
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);
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);
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;
352
347
#ifdef DEBUG_BOARD_INIT
353
348
printf("%s: Done\n", __func__);
355
printf("bdloc %016lx %s\n",
356
(unsigned long)bdloc, (char *)(phys_ram_base + bdloc));
350
printf("bdloc %016lx\n", (unsigned long)bdloc);
359
QEMUMachine ref405ep_machine = {
363
(128 * 1024 * 1024 + 4096 + 512 * 1024 + BIOS_SIZE) | RAMSIZE_FIXED,
353
static QEMUMachine ref405ep_machine = {
356
.init = ref405ep_init,
366
359
/*****************************************************************************/
497
487
cpld = qemu_mallocz(sizeof(taihu_cpld_t));
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);
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);
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)
516
503
CPUPPCState *env;
518
505
ram_addr_t bios_offset;
523
510
int fl_idx, fl_sectors;
524
511
int ppc_boot_device = boot_device[0];
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__);
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
542
530
#if defined(USE_FLASH_BIOS)
543
index = drive_get_index(IF_PFLASH, 0, fl_idx);
545
bios_size = bdrv_getlength(drives_table[index].bdrv);
531
dinfo = drive_get(IF_PFLASH, 0, fl_idx);
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);
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);
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);
559
bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset));
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",
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);
577
bios_offset += bios_size;
578
572
/* Register Linux flash */
579
index = drive_get_index(IF_PFLASH, 0, fl_idx);
581
bios_size = bdrv_getlength(drives_table[index].bdrv);
573
dinfo = drive_get(IF_PFLASH, 0, fl_idx);
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));
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);
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) {
622
618
"qemu: could not load initial ram disk '%s'\n",
642
QEMUMachine taihu_machine = {
646
(128 * 1024 * 1024 + 4096 + BIOS_SIZE + 32 * 1024 * 1024) | RAMSIZE_FIXED,
638
static QEMUMachine taihu_machine = {
641
.init = taihu_405ep_init,
644
static void ppc405_machine_init(void)
646
qemu_register_machine(&ref405ep_machine);
647
qemu_register_machine(&taihu_machine);
650
machine_init(ppc405_machine_init);