root / hw / mips_r4k.c @ 9b595395
History | View | Annotate | Download (8.1 kB)
1 | e16fe40c | ths | /*
|
---|---|---|---|
2 | e16fe40c | ths | * QEMU/MIPS pseudo-board
|
3 | e16fe40c | ths | *
|
4 | e16fe40c | ths | * emulates a simple machine with ISA-like bus.
|
5 | e16fe40c | ths | * ISA IO space mapped to the 0x14000000 (PHYS) and
|
6 | e16fe40c | ths | * ISA memory at the 0x10000000 (PHYS, 16Mb in size).
|
7 | e16fe40c | ths | * All peripherial devices are attached to this "bus" with
|
8 | e16fe40c | ths | * the standard PC ISA addresses.
|
9 | e16fe40c | ths | */
|
10 | 87ecb68b | pbrook | #include "hw.h" |
11 | 87ecb68b | pbrook | #include "mips.h" |
12 | 87ecb68b | pbrook | #include "pc.h" |
13 | 87ecb68b | pbrook | #include "isa.h" |
14 | 87ecb68b | pbrook | #include "net.h" |
15 | 87ecb68b | pbrook | #include "sysemu.h" |
16 | 87ecb68b | pbrook | #include "boards.h" |
17 | 6af0bf9c | bellard | |
18 | 2909b29a | ths | #ifdef TARGET_WORDS_BIGENDIAN
|
19 | 6af0bf9c | bellard | #define BIOS_FILENAME "mips_bios.bin" |
20 | f7bcd4e3 | ths | #else
|
21 | f7bcd4e3 | ths | #define BIOS_FILENAME "mipsel_bios.bin" |
22 | f7bcd4e3 | ths | #endif
|
23 | 44cbbf18 | ths | |
24 | c6ee607c | pbrook | #define PHYS_TO_VIRT(x) ((x) | ~(target_ulong)0x7fffffff) |
25 | 6af0bf9c | bellard | |
26 | 5dc4b744 | ths | #define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000)) |
27 | 66a93e0f | bellard | |
28 | e4bcb14c | ths | #define MAX_IDE_BUS 2 |
29 | e4bcb14c | ths | |
30 | 58126404 | pbrook | static const int ide_iobase[2] = { 0x1f0, 0x170 }; |
31 | 58126404 | pbrook | static const int ide_iobase2[2] = { 0x3f6, 0x376 }; |
32 | 58126404 | pbrook | static const int ide_irq[2] = { 14, 15 }; |
33 | 58126404 | pbrook | |
34 | eddbd288 | ths | static int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; |
35 | eddbd288 | ths | static int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 }; |
36 | eddbd288 | ths | |
37 | 6af0bf9c | bellard | extern FILE *logfile;
|
38 | 6af0bf9c | bellard | |
39 | e16fe40c | ths | static PITState *pit; /* PIT i8254 */ |
40 | 697584ab | bellard | |
41 | 1b66074b | ths | /* i8254 PIT is attached to the IRQ0 at PIC i8259 */
|
42 | 6af0bf9c | bellard | |
43 | 7df526e3 | ths | static struct _loaderparams { |
44 | 7df526e3 | ths | int ram_size;
|
45 | 7df526e3 | ths | const char *kernel_filename; |
46 | 7df526e3 | ths | const char *kernel_cmdline; |
47 | 7df526e3 | ths | const char *initrd_filename; |
48 | 7df526e3 | ths | } loaderparams; |
49 | 7df526e3 | ths | |
50 | 6ae81775 | ths | static void mips_qemu_writel (void *opaque, target_phys_addr_t addr, |
51 | 6ae81775 | ths | uint32_t val) |
52 | 6ae81775 | ths | { |
53 | 6ae81775 | ths | if ((addr & 0xffff) == 0 && val == 42) |
54 | 6ae81775 | ths | qemu_system_reset_request (); |
55 | 6ae81775 | ths | else if ((addr & 0xffff) == 4 && val == 42) |
56 | 6ae81775 | ths | qemu_system_shutdown_request (); |
57 | 6ae81775 | ths | } |
58 | 6ae81775 | ths | |
59 | 6ae81775 | ths | static uint32_t mips_qemu_readl (void *opaque, target_phys_addr_t addr) |
60 | 6ae81775 | ths | { |
61 | 6ae81775 | ths | return 0; |
62 | 6ae81775 | ths | } |
63 | 6ae81775 | ths | |
64 | 6ae81775 | ths | static CPUWriteMemoryFunc *mips_qemu_write[] = {
|
65 | 6ae81775 | ths | &mips_qemu_writel, |
66 | 6ae81775 | ths | &mips_qemu_writel, |
67 | 6ae81775 | ths | &mips_qemu_writel, |
68 | 6ae81775 | ths | }; |
69 | 6ae81775 | ths | |
70 | 6ae81775 | ths | static CPUReadMemoryFunc *mips_qemu_read[] = {
|
71 | 6ae81775 | ths | &mips_qemu_readl, |
72 | 6ae81775 | ths | &mips_qemu_readl, |
73 | 6ae81775 | ths | &mips_qemu_readl, |
74 | 6ae81775 | ths | }; |
75 | 6ae81775 | ths | |
76 | 6ae81775 | ths | static int mips_qemu_iomemtype = 0; |
77 | 6ae81775 | ths | |
78 | 7df526e3 | ths | static void load_kernel (CPUState *env) |
79 | 6ae81775 | ths | { |
80 | 74287114 | ths | int64_t entry, kernel_low, kernel_high; |
81 | 6ae81775 | ths | long kernel_size, initrd_size;
|
82 | 74287114 | ths | ram_addr_t initrd_offset; |
83 | 6ae81775 | ths | |
84 | 7df526e3 | ths | kernel_size = load_elf(loaderparams.kernel_filename, VIRT_TO_PHYS_ADDEND, |
85 | 74287114 | ths | &entry, &kernel_low, &kernel_high); |
86 | c570fd16 | ths | if (kernel_size >= 0) { |
87 | c570fd16 | ths | if ((entry & ~0x7fffffffULL) == 0x80000000) |
88 | 5dc4b744 | ths | entry = (int32_t)entry; |
89 | ead9360e | ths | env->PC[env->current_tc] = entry; |
90 | c570fd16 | ths | } else {
|
91 | 9042c0e2 | ths | fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
92 | 7df526e3 | ths | loaderparams.kernel_filename); |
93 | 9042c0e2 | ths | exit(1);
|
94 | 6ae81775 | ths | } |
95 | 6ae81775 | ths | |
96 | 6ae81775 | ths | /* load initrd */
|
97 | 6ae81775 | ths | initrd_size = 0;
|
98 | 74287114 | ths | initrd_offset = 0;
|
99 | 7df526e3 | ths | if (loaderparams.initrd_filename) {
|
100 | 7df526e3 | ths | initrd_size = get_image_size (loaderparams.initrd_filename); |
101 | 74287114 | ths | if (initrd_size > 0) { |
102 | 74287114 | ths | initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; |
103 | 74287114 | ths | if (initrd_offset + initrd_size > ram_size) {
|
104 | 74287114 | ths | fprintf(stderr, |
105 | 74287114 | ths | "qemu: memory too small for initial ram disk '%s'\n",
|
106 | 7df526e3 | ths | loaderparams.initrd_filename); |
107 | 74287114 | ths | exit(1);
|
108 | 74287114 | ths | } |
109 | 7df526e3 | ths | initrd_size = load_image(loaderparams.initrd_filename, |
110 | 74287114 | ths | phys_ram_base + initrd_offset); |
111 | 74287114 | ths | } |
112 | 6ae81775 | ths | if (initrd_size == (target_ulong) -1) { |
113 | 6ae81775 | ths | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
114 | 7df526e3 | ths | loaderparams.initrd_filename); |
115 | 6ae81775 | ths | exit(1);
|
116 | 6ae81775 | ths | } |
117 | 6ae81775 | ths | } |
118 | 6ae81775 | ths | |
119 | 6ae81775 | ths | /* Store command line. */
|
120 | 6ae81775 | ths | if (initrd_size > 0) { |
121 | 6ae81775 | ths | int ret;
|
122 | 6ae81775 | ths | ret = sprintf(phys_ram_base + (16 << 20) - 256, |
123 | 3594c774 | ths | "rd_start=0x" TARGET_FMT_lx " rd_size=%li ", |
124 | 74287114 | ths | PHYS_TO_VIRT((uint32_t)initrd_offset), |
125 | 6ae81775 | ths | initrd_size); |
126 | 7df526e3 | ths | strcpy (phys_ram_base + (16 << 20) - 256 + ret, |
127 | 7df526e3 | ths | loaderparams.kernel_cmdline); |
128 | 6ae81775 | ths | } |
129 | 6ae81775 | ths | else {
|
130 | 7df526e3 | ths | strcpy (phys_ram_base + (16 << 20) - 256, |
131 | 7df526e3 | ths | loaderparams.kernel_cmdline); |
132 | 6ae81775 | ths | } |
133 | 6ae81775 | ths | |
134 | 44cbbf18 | ths | *(int32_t *)(phys_ram_base + (16 << 20) - 260) = tswap32 (0x12345678); |
135 | 44cbbf18 | ths | *(int32_t *)(phys_ram_base + (16 << 20) - 264) = tswap32 (ram_size); |
136 | 6ae81775 | ths | } |
137 | 6ae81775 | ths | |
138 | 6ae81775 | ths | static void main_cpu_reset(void *opaque) |
139 | 6ae81775 | ths | { |
140 | 6ae81775 | ths | CPUState *env = opaque; |
141 | 6ae81775 | ths | cpu_reset(env); |
142 | 6ae81775 | ths | |
143 | 7df526e3 | ths | if (loaderparams.kernel_filename)
|
144 | 7df526e3 | ths | load_kernel (env); |
145 | 6ae81775 | ths | } |
146 | 66a93e0f | bellard | |
147 | 70705261 | ths | static
|
148 | b881c2c6 | blueswir1 | void mips_r4k_init (int ram_size, int vga_ram_size, |
149 | b881c2c6 | blueswir1 | const char *boot_device, DisplayState *ds, |
150 | 6af0bf9c | bellard | const char *kernel_filename, const char *kernel_cmdline, |
151 | 94fc95cd | j_mayer | const char *initrd_filename, const char *cpu_model) |
152 | 6af0bf9c | bellard | { |
153 | 6af0bf9c | bellard | char buf[1024]; |
154 | 6af0bf9c | bellard | unsigned long bios_offset; |
155 | f7bcd4e3 | ths | int bios_size;
|
156 | c68ea704 | bellard | CPUState *env; |
157 | 153a08db | ths | RTCState *rtc_state; |
158 | 58126404 | pbrook | int i;
|
159 | d537cf6c | pbrook | qemu_irq *i8259; |
160 | e4bcb14c | ths | int index;
|
161 | e4bcb14c | ths | BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; |
162 | c68ea704 | bellard | |
163 | 33d68b5f | ths | /* init CPUs */
|
164 | 33d68b5f | ths | if (cpu_model == NULL) { |
165 | 60aa19ab | ths | #ifdef TARGET_MIPS64
|
166 | 33d68b5f | ths | cpu_model = "R4000";
|
167 | 33d68b5f | ths | #else
|
168 | 1c32f43e | ths | cpu_model = "24Kf";
|
169 | 33d68b5f | ths | #endif
|
170 | 33d68b5f | ths | } |
171 | aaed909a | bellard | env = cpu_init(cpu_model); |
172 | aaed909a | bellard | if (!env) {
|
173 | aaed909a | bellard | fprintf(stderr, "Unable to find CPU definition\n");
|
174 | aaed909a | bellard | exit(1);
|
175 | aaed909a | bellard | } |
176 | c68ea704 | bellard | register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); |
177 | 6ae81775 | ths | qemu_register_reset(main_cpu_reset, env); |
178 | c68ea704 | bellard | |
179 | 6af0bf9c | bellard | /* allocate RAM */
|
180 | 6af0bf9c | bellard | cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
|
181 | 66a93e0f | bellard | |
182 | 6ae81775 | ths | if (!mips_qemu_iomemtype) {
|
183 | 6ae81775 | ths | mips_qemu_iomemtype = cpu_register_io_memory(0, mips_qemu_read,
|
184 | 33d68b5f | ths | mips_qemu_write, NULL);
|
185 | 6ae81775 | ths | } |
186 | 6ae81775 | ths | cpu_register_physical_memory(0x1fbf0000, 0x10000, mips_qemu_iomemtype); |
187 | 6ae81775 | ths | |
188 | 66a93e0f | bellard | /* Try to load a BIOS image. If this fails, we continue regardless,
|
189 | 66a93e0f | bellard | but initialize the hardware ourselves. When a kernel gets
|
190 | 66a93e0f | bellard | preloaded we also initialize the hardware, since the BIOS wasn't
|
191 | 66a93e0f | bellard | run. */
|
192 | 6af0bf9c | bellard | bios_offset = ram_size + vga_ram_size; |
193 | 1192dad8 | j_mayer | if (bios_name == NULL) |
194 | 1192dad8 | j_mayer | bios_name = BIOS_FILENAME; |
195 | 1192dad8 | j_mayer | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); |
196 | f7bcd4e3 | ths | bios_size = load_image(buf, phys_ram_base + bios_offset); |
197 | 2909b29a | ths | if ((bios_size > 0) && (bios_size <= BIOS_SIZE)) { |
198 | 44cbbf18 | ths | cpu_register_physical_memory(0x1fc00000,
|
199 | 66a93e0f | bellard | BIOS_SIZE, bios_offset | IO_MEM_ROM); |
200 | 66a93e0f | bellard | } else {
|
201 | 66a93e0f | bellard | /* not fatal */
|
202 | 66a93e0f | bellard | fprintf(stderr, "qemu: Warning, could not load MIPS bios '%s'\n",
|
203 | 66a93e0f | bellard | buf); |
204 | 6af0bf9c | bellard | } |
205 | 66a93e0f | bellard | |
206 | 66a93e0f | bellard | if (kernel_filename) {
|
207 | 7df526e3 | ths | loaderparams.ram_size = ram_size; |
208 | 7df526e3 | ths | loaderparams.kernel_filename = kernel_filename; |
209 | 7df526e3 | ths | loaderparams.kernel_cmdline = kernel_cmdline; |
210 | 7df526e3 | ths | loaderparams.initrd_filename = initrd_filename; |
211 | 7df526e3 | ths | load_kernel (env); |
212 | 6af0bf9c | bellard | } |
213 | 6af0bf9c | bellard | |
214 | e16fe40c | ths | /* Init CPU internal devices */
|
215 | d537cf6c | pbrook | cpu_mips_irq_init_cpu(env); |
216 | c68ea704 | bellard | cpu_mips_clock_init(env); |
217 | 6af0bf9c | bellard | cpu_mips_irqctrl_init(); |
218 | 6af0bf9c | bellard | |
219 | d537cf6c | pbrook | /* The PIC is attached to the MIPS CPU INT0 pin */
|
220 | d537cf6c | pbrook | i8259 = i8259_init(env->irq[2]);
|
221 | d537cf6c | pbrook | |
222 | d537cf6c | pbrook | rtc_state = rtc_init(0x70, i8259[8]); |
223 | afdfa781 | ths | |
224 | 0699b548 | bellard | /* Register 64 KB of ISA IO space at 0x14000000 */
|
225 | aef445bd | pbrook | isa_mmio_init(0x14000000, 0x00010000); |
226 | 0699b548 | bellard | isa_mem_base = 0x10000000;
|
227 | 0699b548 | bellard | |
228 | d537cf6c | pbrook | pit = pit_init(0x40, i8259[0]); |
229 | afdfa781 | ths | |
230 | eddbd288 | ths | for(i = 0; i < MAX_SERIAL_PORTS; i++) { |
231 | eddbd288 | ths | if (serial_hds[i]) {
|
232 | d537cf6c | pbrook | serial_init(serial_io[i], i8259[serial_irq[i]], serial_hds[i]); |
233 | eddbd288 | ths | } |
234 | eddbd288 | ths | } |
235 | eddbd288 | ths | |
236 | 5fafdf24 | ths | isa_vga_init(ds, phys_ram_base + ram_size, ram_size, |
237 | 89b6b508 | bellard | vga_ram_size); |
238 | 9827e95c | bellard | |
239 | a41b2ff2 | pbrook | if (nd_table[0].vlan) { |
240 | a41b2ff2 | pbrook | if (nd_table[0].model == NULL |
241 | a41b2ff2 | pbrook | || strcmp(nd_table[0].model, "ne2k_isa") == 0) { |
242 | d537cf6c | pbrook | isa_ne2000_init(0x300, i8259[9], &nd_table[0]); |
243 | c4a7060c | blueswir1 | } else if (strcmp(nd_table[0].model, "?") == 0) { |
244 | c4a7060c | blueswir1 | fprintf(stderr, "qemu: Supported NICs: ne2k_isa\n");
|
245 | c4a7060c | blueswir1 | exit (1);
|
246 | a41b2ff2 | pbrook | } else {
|
247 | a41b2ff2 | pbrook | fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model); |
248 | a41b2ff2 | pbrook | exit (1);
|
249 | a41b2ff2 | pbrook | } |
250 | a41b2ff2 | pbrook | } |
251 | 58126404 | pbrook | |
252 | e4bcb14c | ths | if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
|
253 | e4bcb14c | ths | fprintf(stderr, "qemu: too many IDE bus\n");
|
254 | e4bcb14c | ths | exit(1);
|
255 | e4bcb14c | ths | } |
256 | e4bcb14c | ths | |
257 | e4bcb14c | ths | for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { |
258 | e4bcb14c | ths | index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS); |
259 | e4bcb14c | ths | if (index != -1) |
260 | e4bcb14c | ths | hd[i] = drives_table[index].bdrv; |
261 | e4bcb14c | ths | else
|
262 | e4bcb14c | ths | hd[i] = NULL;
|
263 | e4bcb14c | ths | } |
264 | e4bcb14c | ths | |
265 | e4bcb14c | ths | for(i = 0; i < MAX_IDE_BUS; i++) |
266 | d537cf6c | pbrook | isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], |
267 | e4bcb14c | ths | hd[MAX_IDE_DEVS * i], |
268 | e4bcb14c | ths | hd[MAX_IDE_DEVS * i + 1]);
|
269 | 70705261 | ths | |
270 | d537cf6c | pbrook | i8042_init(i8259[1], i8259[12], 0x60); |
271 | 6af0bf9c | bellard | } |
272 | 6af0bf9c | bellard | |
273 | 6af0bf9c | bellard | QEMUMachine mips_machine = { |
274 | 6af0bf9c | bellard | "mips",
|
275 | 6af0bf9c | bellard | "mips r4k platform",
|
276 | 6af0bf9c | bellard | mips_r4k_init, |
277 | 6af0bf9c | bellard | }; |