m68k/ColdFire system emulation.
[qemu] / hw / an5206.c
1 /* 
2  * Arnewsh 5206 ColdFire system emulation.
3  *
4  * Copyright (c) 2007 CodeSourcery.
5  *
6  * This code is licenced under the GPL
7  */
8
9 #include "vl.h"
10
11 #define KERNEL_LOAD_ADDR 0x10000
12 #define AN5206_MBAR_ADDR 0x10000000
13 #define AN5206_RAMBAR_ADDR 0x20000000
14
15 /* Stub functions for hardware that doesn't exist.  */
16 void pic_info(void)
17 {
18 }
19
20 void irq_info(void)
21 {
22 }
23
24 void DMA_run (void)
25 {
26 }
27
28 /* Board init.  */
29
30 static void an5206_init(int ram_size, int vga_ram_size, int boot_device,
31                      DisplayState *ds, const char **fd_filename, int snapshot,
32                      const char *kernel_filename, const char *kernel_cmdline,
33                      const char *initrd_filename, const char *cpu_model)
34 {
35     CPUState *env;
36     int kernel_size;
37     uint64_t elf_entry;
38     target_ulong entry;
39
40     env = cpu_init();
41     if (!cpu_model)
42         cpu_model = "m5206";
43     cpu_m68k_set_model(env, cpu_model);
44
45     /* Initialize CPU registers.  */
46     env->vbr = 0;
47     /* TODO: allow changing MBAR and RAMBAR.  */
48     env->mbar = AN5206_MBAR_ADDR | 1;
49     env->rambar0 = AN5206_RAMBAR_ADDR | 1;
50
51     /* DRAM at address zero */
52     cpu_register_physical_memory(0, ram_size,
53         qemu_ram_alloc(ram_size) | IO_MEM_RAM);
54
55     /* Internal SRAM.  */
56     cpu_register_physical_memory(AN5206_RAMBAR_ADDR, 512,
57         qemu_ram_alloc(512) | IO_MEM_RAM);
58
59     mcf5206_init(AN5206_MBAR_ADDR, env);
60
61     /* Load kernel.  */
62     if (!kernel_filename) {
63         fprintf(stderr, "Kernel image must be specified\n");
64         exit(1);
65     }
66
67     kernel_size = load_elf(kernel_filename, 0, &elf_entry, NULL, NULL);
68     entry = elf_entry;
69     if (kernel_size < 0) {
70         kernel_size = load_uboot(kernel_filename, &entry, NULL);
71     }
72     if (kernel_size < 0) {
73         kernel_size = load_image(kernel_filename,
74                                  phys_ram_base + KERNEL_LOAD_ADDR);
75         entry = KERNEL_LOAD_ADDR;
76     }
77     if (kernel_size < 0) {
78         fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
79         exit(1);
80     }
81
82     env->pc = entry;
83 }
84
85 QEMUMachine an5206_machine = {
86     "an5206",
87     "Arnewsh 5206",
88     an5206_init,
89 };