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