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