root / hw / pc.c @ 4870852c
History | View | Annotate | Download (32.9 kB)
1 | 80cabfad | bellard | /*
|
---|---|---|---|
2 | 80cabfad | bellard | * QEMU PC System Emulator
|
3 | 5fafdf24 | ths | *
|
4 | 80cabfad | bellard | * Copyright (c) 2003-2004 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 80cabfad | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 80cabfad | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 80cabfad | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 80cabfad | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 80cabfad | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 80cabfad | bellard | * furnished to do so, subject to the following conditions:
|
12 | 80cabfad | bellard | *
|
13 | 80cabfad | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 80cabfad | bellard | * all copies or substantial portions of the Software.
|
15 | 80cabfad | bellard | *
|
16 | 80cabfad | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 80cabfad | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 80cabfad | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 80cabfad | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 80cabfad | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 80cabfad | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 80cabfad | bellard | * THE SOFTWARE.
|
23 | 80cabfad | bellard | */
|
24 | 87ecb68b | pbrook | #include "hw.h" |
25 | 87ecb68b | pbrook | #include "pc.h" |
26 | 87ecb68b | pbrook | #include "fdc.h" |
27 | 87ecb68b | pbrook | #include "pci.h" |
28 | 87ecb68b | pbrook | #include "block.h" |
29 | 87ecb68b | pbrook | #include "sysemu.h" |
30 | 87ecb68b | pbrook | #include "audio/audio.h" |
31 | 87ecb68b | pbrook | #include "net.h" |
32 | 87ecb68b | pbrook | #include "smbus.h" |
33 | 87ecb68b | pbrook | #include "boards.h" |
34 | 376253ec | aliguori | #include "monitor.h" |
35 | 3cce6243 | blueswir1 | #include "fw_cfg.h" |
36 | 6e02c38d | aliguori | #include "virtio-blk.h" |
37 | bd322087 | aliguori | #include "virtio-balloon.h" |
38 | a2fa19f9 | aliguori | #include "virtio-console.h" |
39 | 16b29ae1 | aliguori | #include "hpet_emul.h" |
40 | b6f6e3d3 | aliguori | #include "smbios.h" |
41 | 80cabfad | bellard | |
42 | b41a2cd1 | bellard | /* output Bochs bios info messages */
|
43 | b41a2cd1 | bellard | //#define DEBUG_BIOS
|
44 | b41a2cd1 | bellard | |
45 | 80cabfad | bellard | #define BIOS_FILENAME "bios.bin" |
46 | 80cabfad | bellard | #define VGABIOS_FILENAME "vgabios.bin" |
47 | de9258a8 | bellard | #define VGABIOS_CIRRUS_FILENAME "vgabios-cirrus.bin" |
48 | 80cabfad | bellard | |
49 | 7fb4fdcf | balrog | #define PC_MAX_BIOS_SIZE (4 * 1024 * 1024) |
50 | 7fb4fdcf | balrog | |
51 | a80274c3 | pbrook | /* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */
|
52 | a80274c3 | pbrook | #define ACPI_DATA_SIZE 0x10000 |
53 | 3cce6243 | blueswir1 | #define BIOS_CFG_IOPORT 0x510 |
54 | 8a92ea2f | aliguori | #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0) |
55 | b6f6e3d3 | aliguori | #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1) |
56 | 80cabfad | bellard | |
57 | e4bcb14c | ths | #define MAX_IDE_BUS 2 |
58 | e4bcb14c | ths | |
59 | baca51fa | bellard | static fdctrl_t *floppy_controller;
|
60 | b0a21b53 | bellard | static RTCState *rtc_state;
|
61 | ec844b96 | bellard | static PITState *pit;
|
62 | d592d303 | bellard | static IOAPICState *ioapic;
|
63 | a5954d5c | bellard | static PCIDevice *i440fx_state;
|
64 | 80cabfad | bellard | |
65 | b41a2cd1 | bellard | static void ioport80_write(void *opaque, uint32_t addr, uint32_t data) |
66 | 80cabfad | bellard | { |
67 | 80cabfad | bellard | } |
68 | 80cabfad | bellard | |
69 | f929aad6 | bellard | /* MSDOS compatibility mode FPU exception support */
|
70 | d537cf6c | pbrook | static qemu_irq ferr_irq;
|
71 | f929aad6 | bellard | /* XXX: add IGNNE support */
|
72 | f929aad6 | bellard | void cpu_set_ferr(CPUX86State *s)
|
73 | f929aad6 | bellard | { |
74 | d537cf6c | pbrook | qemu_irq_raise(ferr_irq); |
75 | f929aad6 | bellard | } |
76 | f929aad6 | bellard | |
77 | f929aad6 | bellard | static void ioportF0_write(void *opaque, uint32_t addr, uint32_t data) |
78 | f929aad6 | bellard | { |
79 | d537cf6c | pbrook | qemu_irq_lower(ferr_irq); |
80 | f929aad6 | bellard | } |
81 | f929aad6 | bellard | |
82 | 28ab0e2e | bellard | /* TSC handling */
|
83 | 28ab0e2e | bellard | uint64_t cpu_get_tsc(CPUX86State *env) |
84 | 28ab0e2e | bellard | { |
85 | 1dce7c3c | bellard | /* Note: when using kqemu, it is more logical to return the host TSC
|
86 | 1dce7c3c | bellard | because kqemu does not trap the RDTSC instruction for
|
87 | 1dce7c3c | bellard | performance reasons */
|
88 | 640f42e4 | blueswir1 | #ifdef CONFIG_KQEMU
|
89 | 1dce7c3c | bellard | if (env->kqemu_enabled) {
|
90 | 1dce7c3c | bellard | return cpu_get_real_ticks();
|
91 | 5fafdf24 | ths | } else
|
92 | 1dce7c3c | bellard | #endif
|
93 | 1dce7c3c | bellard | { |
94 | 1dce7c3c | bellard | return cpu_get_ticks();
|
95 | 1dce7c3c | bellard | } |
96 | 28ab0e2e | bellard | } |
97 | 28ab0e2e | bellard | |
98 | a5954d5c | bellard | /* SMM support */
|
99 | a5954d5c | bellard | void cpu_smm_update(CPUState *env)
|
100 | a5954d5c | bellard | { |
101 | a5954d5c | bellard | if (i440fx_state && env == first_cpu)
|
102 | a5954d5c | bellard | i440fx_set_smm(i440fx_state, (env->hflags >> HF_SMM_SHIFT) & 1);
|
103 | a5954d5c | bellard | } |
104 | a5954d5c | bellard | |
105 | a5954d5c | bellard | |
106 | 3de388f6 | bellard | /* IRQ handling */
|
107 | 3de388f6 | bellard | int cpu_get_pic_interrupt(CPUState *env)
|
108 | 3de388f6 | bellard | { |
109 | 3de388f6 | bellard | int intno;
|
110 | 3de388f6 | bellard | |
111 | 3de388f6 | bellard | intno = apic_get_interrupt(env); |
112 | 3de388f6 | bellard | if (intno >= 0) { |
113 | 3de388f6 | bellard | /* set irq request if a PIC irq is still pending */
|
114 | 3de388f6 | bellard | /* XXX: improve that */
|
115 | 5fafdf24 | ths | pic_update_irq(isa_pic); |
116 | 3de388f6 | bellard | return intno;
|
117 | 3de388f6 | bellard | } |
118 | 3de388f6 | bellard | /* read the irq from the PIC */
|
119 | 0e21e12b | ths | if (!apic_accept_pic_intr(env))
|
120 | 0e21e12b | ths | return -1; |
121 | 0e21e12b | ths | |
122 | 3de388f6 | bellard | intno = pic_read_irq(isa_pic); |
123 | 3de388f6 | bellard | return intno;
|
124 | 3de388f6 | bellard | } |
125 | 3de388f6 | bellard | |
126 | d537cf6c | pbrook | static void pic_irq_request(void *opaque, int irq, int level) |
127 | 3de388f6 | bellard | { |
128 | a5b38b51 | aurel32 | CPUState *env = first_cpu; |
129 | a5b38b51 | aurel32 | |
130 | d5529471 | aurel32 | if (env->apic_state) {
|
131 | d5529471 | aurel32 | while (env) {
|
132 | d5529471 | aurel32 | if (apic_accept_pic_intr(env))
|
133 | 1a7de94a | aurel32 | apic_deliver_pic_intr(env, level); |
134 | d5529471 | aurel32 | env = env->next_cpu; |
135 | d5529471 | aurel32 | } |
136 | d5529471 | aurel32 | } else {
|
137 | b614106a | aurel32 | if (level)
|
138 | b614106a | aurel32 | cpu_interrupt(env, CPU_INTERRUPT_HARD); |
139 | b614106a | aurel32 | else
|
140 | b614106a | aurel32 | cpu_reset_interrupt(env, CPU_INTERRUPT_HARD); |
141 | a5b38b51 | aurel32 | } |
142 | 3de388f6 | bellard | } |
143 | 3de388f6 | bellard | |
144 | b0a21b53 | bellard | /* PC cmos mappings */
|
145 | b0a21b53 | bellard | |
146 | 80cabfad | bellard | #define REG_EQUIPMENT_BYTE 0x14 |
147 | 80cabfad | bellard | |
148 | 777428f2 | bellard | static int cmos_get_fd_drive_type(int fd0) |
149 | 777428f2 | bellard | { |
150 | 777428f2 | bellard | int val;
|
151 | 777428f2 | bellard | |
152 | 777428f2 | bellard | switch (fd0) {
|
153 | 777428f2 | bellard | case 0: |
154 | 777428f2 | bellard | /* 1.44 Mb 3"5 drive */
|
155 | 777428f2 | bellard | val = 4;
|
156 | 777428f2 | bellard | break;
|
157 | 777428f2 | bellard | case 1: |
158 | 777428f2 | bellard | /* 2.88 Mb 3"5 drive */
|
159 | 777428f2 | bellard | val = 5;
|
160 | 777428f2 | bellard | break;
|
161 | 777428f2 | bellard | case 2: |
162 | 777428f2 | bellard | /* 1.2 Mb 5"5 drive */
|
163 | 777428f2 | bellard | val = 2;
|
164 | 777428f2 | bellard | break;
|
165 | 777428f2 | bellard | default:
|
166 | 777428f2 | bellard | val = 0;
|
167 | 777428f2 | bellard | break;
|
168 | 777428f2 | bellard | } |
169 | 777428f2 | bellard | return val;
|
170 | 777428f2 | bellard | } |
171 | 777428f2 | bellard | |
172 | 5fafdf24 | ths | static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd) |
173 | ba6c2377 | bellard | { |
174 | ba6c2377 | bellard | RTCState *s = rtc_state; |
175 | ba6c2377 | bellard | int cylinders, heads, sectors;
|
176 | ba6c2377 | bellard | bdrv_get_geometry_hint(hd, &cylinders, &heads, §ors); |
177 | ba6c2377 | bellard | rtc_set_memory(s, type_ofs, 47);
|
178 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs, cylinders); |
179 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs + 1, cylinders >> 8); |
180 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs + 2, heads);
|
181 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs + 3, 0xff); |
182 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs + 4, 0xff); |
183 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs + 5, 0xc0 | ((heads > 8) << 3)); |
184 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs + 6, cylinders);
|
185 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs + 7, cylinders >> 8); |
186 | ba6c2377 | bellard | rtc_set_memory(s, info_ofs + 8, sectors);
|
187 | ba6c2377 | bellard | } |
188 | ba6c2377 | bellard | |
189 | 6ac0e82d | balrog | /* convert boot_device letter to something recognizable by the bios */
|
190 | 6ac0e82d | balrog | static int boot_device2nibble(char boot_device) |
191 | 6ac0e82d | balrog | { |
192 | 6ac0e82d | balrog | switch(boot_device) {
|
193 | 6ac0e82d | balrog | case 'a': |
194 | 6ac0e82d | balrog | case 'b': |
195 | 6ac0e82d | balrog | return 0x01; /* floppy boot */ |
196 | 6ac0e82d | balrog | case 'c': |
197 | 6ac0e82d | balrog | return 0x02; /* hard drive boot */ |
198 | 6ac0e82d | balrog | case 'd': |
199 | 6ac0e82d | balrog | return 0x03; /* CD-ROM boot */ |
200 | 6ac0e82d | balrog | case 'n': |
201 | 6ac0e82d | balrog | return 0x04; /* Network boot */ |
202 | 6ac0e82d | balrog | } |
203 | 6ac0e82d | balrog | return 0; |
204 | 6ac0e82d | balrog | } |
205 | 6ac0e82d | balrog | |
206 | 0ecdffbb | aurel32 | /* copy/pasted from cmos_init, should be made a general function
|
207 | 0ecdffbb | aurel32 | and used there as well */
|
208 | 3b4366de | blueswir1 | static int pc_boot_set(void *opaque, const char *boot_device) |
209 | 0ecdffbb | aurel32 | { |
210 | 376253ec | aliguori | Monitor *mon = cur_mon; |
211 | 0ecdffbb | aurel32 | #define PC_MAX_BOOT_DEVICES 3 |
212 | 3b4366de | blueswir1 | RTCState *s = (RTCState *)opaque; |
213 | 0ecdffbb | aurel32 | int nbds, bds[3] = { 0, }; |
214 | 0ecdffbb | aurel32 | int i;
|
215 | 0ecdffbb | aurel32 | |
216 | 0ecdffbb | aurel32 | nbds = strlen(boot_device); |
217 | 0ecdffbb | aurel32 | if (nbds > PC_MAX_BOOT_DEVICES) {
|
218 | 376253ec | aliguori | monitor_printf(mon, "Too many boot devices for PC\n");
|
219 | 0ecdffbb | aurel32 | return(1); |
220 | 0ecdffbb | aurel32 | } |
221 | 0ecdffbb | aurel32 | for (i = 0; i < nbds; i++) { |
222 | 0ecdffbb | aurel32 | bds[i] = boot_device2nibble(boot_device[i]); |
223 | 0ecdffbb | aurel32 | if (bds[i] == 0) { |
224 | 376253ec | aliguori | monitor_printf(mon, "Invalid boot device for PC: '%c'\n",
|
225 | 376253ec | aliguori | boot_device[i]); |
226 | 0ecdffbb | aurel32 | return(1); |
227 | 0ecdffbb | aurel32 | } |
228 | 0ecdffbb | aurel32 | } |
229 | 0ecdffbb | aurel32 | rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]); |
230 | 0ecdffbb | aurel32 | rtc_set_memory(s, 0x38, (bds[2] << 4)); |
231 | 0ecdffbb | aurel32 | return(0); |
232 | 0ecdffbb | aurel32 | } |
233 | 0ecdffbb | aurel32 | |
234 | ba6c2377 | bellard | /* hd_table must contain 4 block drivers */
|
235 | 00f82b8a | aurel32 | static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, |
236 | 00f82b8a | aurel32 | const char *boot_device, BlockDriverState **hd_table) |
237 | 80cabfad | bellard | { |
238 | b0a21b53 | bellard | RTCState *s = rtc_state; |
239 | 28c5af54 | j_mayer | int nbds, bds[3] = { 0, }; |
240 | 80cabfad | bellard | int val;
|
241 | b41a2cd1 | bellard | int fd0, fd1, nb;
|
242 | ba6c2377 | bellard | int i;
|
243 | b0a21b53 | bellard | |
244 | b0a21b53 | bellard | /* various important CMOS locations needed by PC/Bochs bios */
|
245 | 80cabfad | bellard | |
246 | 80cabfad | bellard | /* memory size */
|
247 | 333190eb | bellard | val = 640; /* base memory in K */ |
248 | 333190eb | bellard | rtc_set_memory(s, 0x15, val);
|
249 | 333190eb | bellard | rtc_set_memory(s, 0x16, val >> 8); |
250 | 333190eb | bellard | |
251 | 80cabfad | bellard | val = (ram_size / 1024) - 1024; |
252 | 80cabfad | bellard | if (val > 65535) |
253 | 80cabfad | bellard | val = 65535;
|
254 | b0a21b53 | bellard | rtc_set_memory(s, 0x17, val);
|
255 | b0a21b53 | bellard | rtc_set_memory(s, 0x18, val >> 8); |
256 | b0a21b53 | bellard | rtc_set_memory(s, 0x30, val);
|
257 | b0a21b53 | bellard | rtc_set_memory(s, 0x31, val >> 8); |
258 | 80cabfad | bellard | |
259 | 00f82b8a | aurel32 | if (above_4g_mem_size) {
|
260 | 00f82b8a | aurel32 | rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16); |
261 | 00f82b8a | aurel32 | rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24); |
262 | 00f82b8a | aurel32 | rtc_set_memory(s, 0x5d, (uint64_t)above_4g_mem_size >> 32); |
263 | 00f82b8a | aurel32 | } |
264 | 00f82b8a | aurel32 | |
265 | 9da98861 | bellard | if (ram_size > (16 * 1024 * 1024)) |
266 | 9da98861 | bellard | val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536); |
267 | 9da98861 | bellard | else
|
268 | 9da98861 | bellard | val = 0;
|
269 | 80cabfad | bellard | if (val > 65535) |
270 | 80cabfad | bellard | val = 65535;
|
271 | b0a21b53 | bellard | rtc_set_memory(s, 0x34, val);
|
272 | b0a21b53 | bellard | rtc_set_memory(s, 0x35, val >> 8); |
273 | 3b46e624 | ths | |
274 | 298e01b6 | aurel32 | /* set the number of CPU */
|
275 | 298e01b6 | aurel32 | rtc_set_memory(s, 0x5f, smp_cpus - 1); |
276 | 298e01b6 | aurel32 | |
277 | 6ac0e82d | balrog | /* set boot devices, and disable floppy signature check if requested */
|
278 | 28c5af54 | j_mayer | #define PC_MAX_BOOT_DEVICES 3 |
279 | 28c5af54 | j_mayer | nbds = strlen(boot_device); |
280 | 28c5af54 | j_mayer | if (nbds > PC_MAX_BOOT_DEVICES) {
|
281 | 28c5af54 | j_mayer | fprintf(stderr, "Too many boot devices for PC\n");
|
282 | 28c5af54 | j_mayer | exit(1);
|
283 | 28c5af54 | j_mayer | } |
284 | 28c5af54 | j_mayer | for (i = 0; i < nbds; i++) { |
285 | 28c5af54 | j_mayer | bds[i] = boot_device2nibble(boot_device[i]); |
286 | 28c5af54 | j_mayer | if (bds[i] == 0) { |
287 | 28c5af54 | j_mayer | fprintf(stderr, "Invalid boot device for PC: '%c'\n",
|
288 | 28c5af54 | j_mayer | boot_device[i]); |
289 | 28c5af54 | j_mayer | exit(1);
|
290 | 28c5af54 | j_mayer | } |
291 | 28c5af54 | j_mayer | } |
292 | 28c5af54 | j_mayer | rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]); |
293 | 28c5af54 | j_mayer | rtc_set_memory(s, 0x38, (bds[2] << 4) | (fd_bootchk ? 0x0 : 0x1)); |
294 | 80cabfad | bellard | |
295 | b41a2cd1 | bellard | /* floppy type */
|
296 | b41a2cd1 | bellard | |
297 | baca51fa | bellard | fd0 = fdctrl_get_drive_type(floppy_controller, 0);
|
298 | baca51fa | bellard | fd1 = fdctrl_get_drive_type(floppy_controller, 1);
|
299 | 80cabfad | bellard | |
300 | 777428f2 | bellard | val = (cmos_get_fd_drive_type(fd0) << 4) | cmos_get_fd_drive_type(fd1);
|
301 | b0a21b53 | bellard | rtc_set_memory(s, 0x10, val);
|
302 | 3b46e624 | ths | |
303 | b0a21b53 | bellard | val = 0;
|
304 | b41a2cd1 | bellard | nb = 0;
|
305 | 80cabfad | bellard | if (fd0 < 3) |
306 | 80cabfad | bellard | nb++; |
307 | 80cabfad | bellard | if (fd1 < 3) |
308 | 80cabfad | bellard | nb++; |
309 | 80cabfad | bellard | switch (nb) {
|
310 | 80cabfad | bellard | case 0: |
311 | 80cabfad | bellard | break;
|
312 | 80cabfad | bellard | case 1: |
313 | b0a21b53 | bellard | val |= 0x01; /* 1 drive, ready for boot */ |
314 | 80cabfad | bellard | break;
|
315 | 80cabfad | bellard | case 2: |
316 | b0a21b53 | bellard | val |= 0x41; /* 2 drives, ready for boot */ |
317 | 80cabfad | bellard | break;
|
318 | 80cabfad | bellard | } |
319 | b0a21b53 | bellard | val |= 0x02; /* FPU is there */ |
320 | b0a21b53 | bellard | val |= 0x04; /* PS/2 mouse installed */ |
321 | b0a21b53 | bellard | rtc_set_memory(s, REG_EQUIPMENT_BYTE, val); |
322 | b0a21b53 | bellard | |
323 | ba6c2377 | bellard | /* hard drives */
|
324 | ba6c2377 | bellard | |
325 | ba6c2377 | bellard | rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0)); |
326 | ba6c2377 | bellard | if (hd_table[0]) |
327 | ba6c2377 | bellard | cmos_init_hd(0x19, 0x1b, hd_table[0]); |
328 | 5fafdf24 | ths | if (hd_table[1]) |
329 | ba6c2377 | bellard | cmos_init_hd(0x1a, 0x24, hd_table[1]); |
330 | ba6c2377 | bellard | |
331 | ba6c2377 | bellard | val = 0;
|
332 | 40b6ecc6 | bellard | for (i = 0; i < 4; i++) { |
333 | ba6c2377 | bellard | if (hd_table[i]) {
|
334 | 46d4767d | bellard | int cylinders, heads, sectors, translation;
|
335 | 46d4767d | bellard | /* NOTE: bdrv_get_geometry_hint() returns the physical
|
336 | 46d4767d | bellard | geometry. It is always such that: 1 <= sects <= 63, 1
|
337 | 46d4767d | bellard | <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
|
338 | 46d4767d | bellard | geometry can be different if a translation is done. */
|
339 | 46d4767d | bellard | translation = bdrv_get_translation_hint(hd_table[i]); |
340 | 46d4767d | bellard | if (translation == BIOS_ATA_TRANSLATION_AUTO) {
|
341 | 46d4767d | bellard | bdrv_get_geometry_hint(hd_table[i], &cylinders, &heads, §ors); |
342 | 46d4767d | bellard | if (cylinders <= 1024 && heads <= 16 && sectors <= 63) { |
343 | 46d4767d | bellard | /* No translation. */
|
344 | 46d4767d | bellard | translation = 0;
|
345 | 46d4767d | bellard | } else {
|
346 | 46d4767d | bellard | /* LBA translation. */
|
347 | 46d4767d | bellard | translation = 1;
|
348 | 46d4767d | bellard | } |
349 | 40b6ecc6 | bellard | } else {
|
350 | 46d4767d | bellard | translation--; |
351 | ba6c2377 | bellard | } |
352 | ba6c2377 | bellard | val |= translation << (i * 2);
|
353 | ba6c2377 | bellard | } |
354 | 40b6ecc6 | bellard | } |
355 | ba6c2377 | bellard | rtc_set_memory(s, 0x39, val);
|
356 | 80cabfad | bellard | } |
357 | 80cabfad | bellard | |
358 | 59b8ad81 | bellard | void ioport_set_a20(int enable) |
359 | 59b8ad81 | bellard | { |
360 | 59b8ad81 | bellard | /* XXX: send to all CPUs ? */
|
361 | 59b8ad81 | bellard | cpu_x86_set_a20(first_cpu, enable); |
362 | 59b8ad81 | bellard | } |
363 | 59b8ad81 | bellard | |
364 | 59b8ad81 | bellard | int ioport_get_a20(void) |
365 | 59b8ad81 | bellard | { |
366 | 59b8ad81 | bellard | return ((first_cpu->a20_mask >> 20) & 1); |
367 | 59b8ad81 | bellard | } |
368 | 59b8ad81 | bellard | |
369 | e1a23744 | bellard | static void ioport92_write(void *opaque, uint32_t addr, uint32_t val) |
370 | e1a23744 | bellard | { |
371 | 59b8ad81 | bellard | ioport_set_a20((val >> 1) & 1); |
372 | e1a23744 | bellard | /* XXX: bit 0 is fast reset */
|
373 | e1a23744 | bellard | } |
374 | e1a23744 | bellard | |
375 | e1a23744 | bellard | static uint32_t ioport92_read(void *opaque, uint32_t addr) |
376 | e1a23744 | bellard | { |
377 | 59b8ad81 | bellard | return ioport_get_a20() << 1; |
378 | e1a23744 | bellard | } |
379 | e1a23744 | bellard | |
380 | 80cabfad | bellard | /***********************************************************/
|
381 | 80cabfad | bellard | /* Bochs BIOS debug ports */
|
382 | 80cabfad | bellard | |
383 | 9596ebb7 | pbrook | static void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val) |
384 | 80cabfad | bellard | { |
385 | a2f659ee | bellard | static const char shutdown_str[8] = "Shutdown"; |
386 | a2f659ee | bellard | static int shutdown_index = 0; |
387 | 3b46e624 | ths | |
388 | 80cabfad | bellard | switch(addr) {
|
389 | 80cabfad | bellard | /* Bochs BIOS messages */
|
390 | 80cabfad | bellard | case 0x400: |
391 | 80cabfad | bellard | case 0x401: |
392 | 80cabfad | bellard | fprintf(stderr, "BIOS panic at rombios.c, line %d\n", val);
|
393 | 80cabfad | bellard | exit(1);
|
394 | 80cabfad | bellard | case 0x402: |
395 | 80cabfad | bellard | case 0x403: |
396 | 80cabfad | bellard | #ifdef DEBUG_BIOS
|
397 | 80cabfad | bellard | fprintf(stderr, "%c", val);
|
398 | 80cabfad | bellard | #endif
|
399 | 80cabfad | bellard | break;
|
400 | a2f659ee | bellard | case 0x8900: |
401 | a2f659ee | bellard | /* same as Bochs power off */
|
402 | a2f659ee | bellard | if (val == shutdown_str[shutdown_index]) {
|
403 | a2f659ee | bellard | shutdown_index++; |
404 | a2f659ee | bellard | if (shutdown_index == 8) { |
405 | a2f659ee | bellard | shutdown_index = 0;
|
406 | a2f659ee | bellard | qemu_system_shutdown_request(); |
407 | a2f659ee | bellard | } |
408 | a2f659ee | bellard | } else {
|
409 | a2f659ee | bellard | shutdown_index = 0;
|
410 | a2f659ee | bellard | } |
411 | a2f659ee | bellard | break;
|
412 | 80cabfad | bellard | |
413 | 80cabfad | bellard | /* LGPL'ed VGA BIOS messages */
|
414 | 80cabfad | bellard | case 0x501: |
415 | 80cabfad | bellard | case 0x502: |
416 | 80cabfad | bellard | fprintf(stderr, "VGA BIOS panic, line %d\n", val);
|
417 | 80cabfad | bellard | exit(1);
|
418 | 80cabfad | bellard | case 0x500: |
419 | 80cabfad | bellard | case 0x503: |
420 | 80cabfad | bellard | #ifdef DEBUG_BIOS
|
421 | 80cabfad | bellard | fprintf(stderr, "%c", val);
|
422 | 80cabfad | bellard | #endif
|
423 | 80cabfad | bellard | break;
|
424 | 80cabfad | bellard | } |
425 | 80cabfad | bellard | } |
426 | 80cabfad | bellard | |
427 | 11c2fd3e | aliguori | extern uint64_t node_cpumask[MAX_NODES];
|
428 | 11c2fd3e | aliguori | |
429 | 9596ebb7 | pbrook | static void bochs_bios_init(void) |
430 | 80cabfad | bellard | { |
431 | 3cce6243 | blueswir1 | void *fw_cfg;
|
432 | b6f6e3d3 | aliguori | uint8_t *smbios_table; |
433 | b6f6e3d3 | aliguori | size_t smbios_len; |
434 | 11c2fd3e | aliguori | uint64_t *numa_fw_cfg; |
435 | 11c2fd3e | aliguori | int i, j;
|
436 | 3cce6243 | blueswir1 | |
437 | b41a2cd1 | bellard | register_ioport_write(0x400, 1, 2, bochs_bios_write, NULL); |
438 | b41a2cd1 | bellard | register_ioport_write(0x401, 1, 2, bochs_bios_write, NULL); |
439 | b41a2cd1 | bellard | register_ioport_write(0x402, 1, 1, bochs_bios_write, NULL); |
440 | b41a2cd1 | bellard | register_ioport_write(0x403, 1, 1, bochs_bios_write, NULL); |
441 | a2f659ee | bellard | register_ioport_write(0x8900, 1, 1, bochs_bios_write, NULL); |
442 | b41a2cd1 | bellard | |
443 | b41a2cd1 | bellard | register_ioport_write(0x501, 1, 2, bochs_bios_write, NULL); |
444 | b41a2cd1 | bellard | register_ioport_write(0x502, 1, 2, bochs_bios_write, NULL); |
445 | b41a2cd1 | bellard | register_ioport_write(0x500, 1, 1, bochs_bios_write, NULL); |
446 | b41a2cd1 | bellard | register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL); |
447 | 3cce6243 | blueswir1 | |
448 | 3cce6243 | blueswir1 | fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0); |
449 | 3cce6243 | blueswir1 | fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
|
450 | 905fdcb5 | blueswir1 | fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); |
451 | 80deece2 | blueswir1 | fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables, |
452 | 80deece2 | blueswir1 | acpi_tables_len); |
453 | b6f6e3d3 | aliguori | |
454 | b6f6e3d3 | aliguori | smbios_table = smbios_get_table(&smbios_len); |
455 | b6f6e3d3 | aliguori | if (smbios_table)
|
456 | b6f6e3d3 | aliguori | fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES, |
457 | b6f6e3d3 | aliguori | smbios_table, smbios_len); |
458 | 11c2fd3e | aliguori | |
459 | 11c2fd3e | aliguori | /* allocate memory for the NUMA channel: one (64bit) word for the number
|
460 | 11c2fd3e | aliguori | * of nodes, one word for each VCPU->node and one word for each node to
|
461 | 11c2fd3e | aliguori | * hold the amount of memory.
|
462 | 11c2fd3e | aliguori | */
|
463 | 11c2fd3e | aliguori | numa_fw_cfg = qemu_mallocz((1 + smp_cpus + nb_numa_nodes) * 8); |
464 | 11c2fd3e | aliguori | numa_fw_cfg[0] = cpu_to_le64(nb_numa_nodes);
|
465 | 11c2fd3e | aliguori | for (i = 0; i < smp_cpus; i++) { |
466 | 11c2fd3e | aliguori | for (j = 0; j < nb_numa_nodes; j++) { |
467 | 11c2fd3e | aliguori | if (node_cpumask[j] & (1 << i)) { |
468 | 11c2fd3e | aliguori | numa_fw_cfg[i + 1] = cpu_to_le64(j);
|
469 | 11c2fd3e | aliguori | break;
|
470 | 11c2fd3e | aliguori | } |
471 | 11c2fd3e | aliguori | } |
472 | 11c2fd3e | aliguori | } |
473 | 11c2fd3e | aliguori | for (i = 0; i < nb_numa_nodes; i++) { |
474 | 11c2fd3e | aliguori | numa_fw_cfg[smp_cpus + 1 + i] = cpu_to_le64(node_mem[i]);
|
475 | 11c2fd3e | aliguori | } |
476 | 11c2fd3e | aliguori | fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, (uint8_t *)numa_fw_cfg, |
477 | 11c2fd3e | aliguori | (1 + smp_cpus + nb_numa_nodes) * 8); |
478 | 80cabfad | bellard | } |
479 | 80cabfad | bellard | |
480 | 642a4f96 | ths | /* Generate an initial boot sector which sets state and jump to
|
481 | 642a4f96 | ths | a specified vector */
|
482 | 7ffa4767 | pbrook | static void generate_bootsect(target_phys_addr_t option_rom, |
483 | 4fc9af53 | aliguori | uint32_t gpr[8], uint16_t segs[6], uint16_t ip) |
484 | 642a4f96 | ths | { |
485 | 4fc9af53 | aliguori | uint8_t rom[512], *p, *reloc;
|
486 | 4fc9af53 | aliguori | uint8_t sum; |
487 | 642a4f96 | ths | int i;
|
488 | 642a4f96 | ths | |
489 | 4fc9af53 | aliguori | memset(rom, 0, sizeof(rom)); |
490 | 4fc9af53 | aliguori | |
491 | 4fc9af53 | aliguori | p = rom; |
492 | 4fc9af53 | aliguori | /* Make sure we have an option rom signature */
|
493 | 4fc9af53 | aliguori | *p++ = 0x55;
|
494 | 4fc9af53 | aliguori | *p++ = 0xaa;
|
495 | 642a4f96 | ths | |
496 | 4fc9af53 | aliguori | /* ROM size in sectors*/
|
497 | 4fc9af53 | aliguori | *p++ = 1;
|
498 | 642a4f96 | ths | |
499 | 4fc9af53 | aliguori | /* Hook int19 */
|
500 | 642a4f96 | ths | |
501 | 4fc9af53 | aliguori | *p++ = 0x50; /* push ax */ |
502 | 4fc9af53 | aliguori | *p++ = 0x1e; /* push ds */ |
503 | 4fc9af53 | aliguori | *p++ = 0x31; *p++ = 0xc0; /* xor ax, ax */ |
504 | 4fc9af53 | aliguori | *p++ = 0x8e; *p++ = 0xd8; /* mov ax, ds */ |
505 | 642a4f96 | ths | |
506 | 4fc9af53 | aliguori | *p++ = 0xc7; *p++ = 0x06; /* movvw _start,0x64 */ |
507 | 4fc9af53 | aliguori | *p++ = 0x64; *p++ = 0x00; |
508 | 4fc9af53 | aliguori | reloc = p; |
509 | 4fc9af53 | aliguori | *p++ = 0x00; *p++ = 0x00; |
510 | 4fc9af53 | aliguori | |
511 | 4fc9af53 | aliguori | *p++ = 0x8c; *p++ = 0x0e; /* mov cs,0x66 */ |
512 | 4fc9af53 | aliguori | *p++ = 0x66; *p++ = 0x00; |
513 | 4fc9af53 | aliguori | |
514 | 4fc9af53 | aliguori | *p++ = 0x1f; /* pop ds */ |
515 | 4fc9af53 | aliguori | *p++ = 0x58; /* pop ax */ |
516 | 4fc9af53 | aliguori | *p++ = 0xcb; /* lret */ |
517 | 4fc9af53 | aliguori | |
518 | 642a4f96 | ths | /* Actual code */
|
519 | 4fc9af53 | aliguori | *reloc = (p - rom); |
520 | 4fc9af53 | aliguori | |
521 | 642a4f96 | ths | *p++ = 0xfa; /* CLI */ |
522 | 642a4f96 | ths | *p++ = 0xfc; /* CLD */ |
523 | 642a4f96 | ths | |
524 | 642a4f96 | ths | for (i = 0; i < 6; i++) { |
525 | 642a4f96 | ths | if (i == 1) /* Skip CS */ |
526 | 642a4f96 | ths | continue;
|
527 | 642a4f96 | ths | |
528 | 642a4f96 | ths | *p++ = 0xb8; /* MOV AX,imm16 */ |
529 | 642a4f96 | ths | *p++ = segs[i]; |
530 | 642a4f96 | ths | *p++ = segs[i] >> 8;
|
531 | 642a4f96 | ths | *p++ = 0x8e; /* MOV <seg>,AX */ |
532 | 642a4f96 | ths | *p++ = 0xc0 + (i << 3); |
533 | 642a4f96 | ths | } |
534 | 642a4f96 | ths | |
535 | 642a4f96 | ths | for (i = 0; i < 8; i++) { |
536 | 642a4f96 | ths | *p++ = 0x66; /* 32-bit operand size */ |
537 | 642a4f96 | ths | *p++ = 0xb8 + i; /* MOV <reg>,imm32 */ |
538 | 642a4f96 | ths | *p++ = gpr[i]; |
539 | 642a4f96 | ths | *p++ = gpr[i] >> 8;
|
540 | 642a4f96 | ths | *p++ = gpr[i] >> 16;
|
541 | 642a4f96 | ths | *p++ = gpr[i] >> 24;
|
542 | 642a4f96 | ths | } |
543 | 642a4f96 | ths | |
544 | 642a4f96 | ths | *p++ = 0xea; /* JMP FAR */ |
545 | 642a4f96 | ths | *p++ = ip; /* IP */
|
546 | 642a4f96 | ths | *p++ = ip >> 8;
|
547 | 642a4f96 | ths | *p++ = segs[1]; /* CS */ |
548 | 642a4f96 | ths | *p++ = segs[1] >> 8; |
549 | 642a4f96 | ths | |
550 | 4fc9af53 | aliguori | /* sign rom */
|
551 | 4fc9af53 | aliguori | sum = 0;
|
552 | 4fc9af53 | aliguori | for (i = 0; i < (sizeof(rom) - 1); i++) |
553 | 4fc9af53 | aliguori | sum += rom[i]; |
554 | 4fc9af53 | aliguori | rom[sizeof(rom) - 1] = -sum; |
555 | 4fc9af53 | aliguori | |
556 | 7ffa4767 | pbrook | cpu_physical_memory_write_rom(option_rom, rom, sizeof(rom));
|
557 | 642a4f96 | ths | } |
558 | 80cabfad | bellard | |
559 | 642a4f96 | ths | static long get_file_size(FILE *f) |
560 | 642a4f96 | ths | { |
561 | 642a4f96 | ths | long where, size;
|
562 | 642a4f96 | ths | |
563 | 642a4f96 | ths | /* XXX: on Unix systems, using fstat() probably makes more sense */
|
564 | 642a4f96 | ths | |
565 | 642a4f96 | ths | where = ftell(f); |
566 | 642a4f96 | ths | fseek(f, 0, SEEK_END);
|
567 | 642a4f96 | ths | size = ftell(f); |
568 | 642a4f96 | ths | fseek(f, where, SEEK_SET); |
569 | 642a4f96 | ths | |
570 | 642a4f96 | ths | return size;
|
571 | 642a4f96 | ths | } |
572 | 642a4f96 | ths | |
573 | 7ffa4767 | pbrook | static void load_linux(target_phys_addr_t option_rom, |
574 | 4fc9af53 | aliguori | const char *kernel_filename, |
575 | 642a4f96 | ths | const char *initrd_filename, |
576 | 642a4f96 | ths | const char *kernel_cmdline) |
577 | 642a4f96 | ths | { |
578 | 642a4f96 | ths | uint16_t protocol; |
579 | 642a4f96 | ths | uint32_t gpr[8];
|
580 | 642a4f96 | ths | uint16_t seg[6];
|
581 | 642a4f96 | ths | uint16_t real_seg; |
582 | 642a4f96 | ths | int setup_size, kernel_size, initrd_size, cmdline_size;
|
583 | 642a4f96 | ths | uint32_t initrd_max; |
584 | 642a4f96 | ths | uint8_t header[1024];
|
585 | a37af289 | blueswir1 | target_phys_addr_t real_addr, prot_addr, cmdline_addr, initrd_addr; |
586 | 642a4f96 | ths | FILE *f, *fi; |
587 | 642a4f96 | ths | |
588 | 642a4f96 | ths | /* Align to 16 bytes as a paranoia measure */
|
589 | 642a4f96 | ths | cmdline_size = (strlen(kernel_cmdline)+16) & ~15; |
590 | 642a4f96 | ths | |
591 | 642a4f96 | ths | /* load the kernel header */
|
592 | 642a4f96 | ths | f = fopen(kernel_filename, "rb");
|
593 | 642a4f96 | ths | if (!f || !(kernel_size = get_file_size(f)) ||
|
594 | 642a4f96 | ths | fread(header, 1, 1024, f) != 1024) { |
595 | 642a4f96 | ths | fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
596 | 642a4f96 | ths | kernel_filename); |
597 | 642a4f96 | ths | exit(1);
|
598 | 642a4f96 | ths | } |
599 | 642a4f96 | ths | |
600 | 642a4f96 | ths | /* kernel protocol version */
|
601 | bc4edd79 | bellard | #if 0
|
602 | 642a4f96 | ths | fprintf(stderr, "header magic: %#x\n", ldl_p(header+0x202));
|
603 | bc4edd79 | bellard | #endif
|
604 | 642a4f96 | ths | if (ldl_p(header+0x202) == 0x53726448) |
605 | 642a4f96 | ths | protocol = lduw_p(header+0x206);
|
606 | 642a4f96 | ths | else
|
607 | 642a4f96 | ths | protocol = 0;
|
608 | 642a4f96 | ths | |
609 | 642a4f96 | ths | if (protocol < 0x200 || !(header[0x211] & 0x01)) { |
610 | 642a4f96 | ths | /* Low kernel */
|
611 | a37af289 | blueswir1 | real_addr = 0x90000;
|
612 | a37af289 | blueswir1 | cmdline_addr = 0x9a000 - cmdline_size;
|
613 | a37af289 | blueswir1 | prot_addr = 0x10000;
|
614 | 642a4f96 | ths | } else if (protocol < 0x202) { |
615 | 642a4f96 | ths | /* High but ancient kernel */
|
616 | a37af289 | blueswir1 | real_addr = 0x90000;
|
617 | a37af289 | blueswir1 | cmdline_addr = 0x9a000 - cmdline_size;
|
618 | a37af289 | blueswir1 | prot_addr = 0x100000;
|
619 | 642a4f96 | ths | } else {
|
620 | 642a4f96 | ths | /* High and recent kernel */
|
621 | a37af289 | blueswir1 | real_addr = 0x10000;
|
622 | a37af289 | blueswir1 | cmdline_addr = 0x20000;
|
623 | a37af289 | blueswir1 | prot_addr = 0x100000;
|
624 | 642a4f96 | ths | } |
625 | 642a4f96 | ths | |
626 | bc4edd79 | bellard | #if 0
|
627 | 642a4f96 | ths | fprintf(stderr,
|
628 | 526ccb7a | balrog | "qemu: real_addr = 0x" TARGET_FMT_plx "\n"
|
629 | 526ccb7a | balrog | "qemu: cmdline_addr = 0x" TARGET_FMT_plx "\n"
|
630 | 526ccb7a | balrog | "qemu: prot_addr = 0x" TARGET_FMT_plx "\n",
|
631 | a37af289 | blueswir1 | real_addr,
|
632 | a37af289 | blueswir1 | cmdline_addr,
|
633 | a37af289 | blueswir1 | prot_addr);
|
634 | bc4edd79 | bellard | #endif
|
635 | 642a4f96 | ths | |
636 | 642a4f96 | ths | /* highest address for loading the initrd */
|
637 | 642a4f96 | ths | if (protocol >= 0x203) |
638 | 642a4f96 | ths | initrd_max = ldl_p(header+0x22c);
|
639 | 642a4f96 | ths | else
|
640 | 642a4f96 | ths | initrd_max = 0x37ffffff;
|
641 | 642a4f96 | ths | |
642 | 642a4f96 | ths | if (initrd_max >= ram_size-ACPI_DATA_SIZE)
|
643 | 642a4f96 | ths | initrd_max = ram_size-ACPI_DATA_SIZE-1;
|
644 | 642a4f96 | ths | |
645 | 642a4f96 | ths | /* kernel command line */
|
646 | a37af289 | blueswir1 | pstrcpy_targphys(cmdline_addr, 4096, kernel_cmdline);
|
647 | 642a4f96 | ths | |
648 | 642a4f96 | ths | if (protocol >= 0x202) { |
649 | a37af289 | blueswir1 | stl_p(header+0x228, cmdline_addr);
|
650 | 642a4f96 | ths | } else {
|
651 | 642a4f96 | ths | stw_p(header+0x20, 0xA33F); |
652 | 642a4f96 | ths | stw_p(header+0x22, cmdline_addr-real_addr);
|
653 | 642a4f96 | ths | } |
654 | 642a4f96 | ths | |
655 | 642a4f96 | ths | /* loader type */
|
656 | 642a4f96 | ths | /* High nybble = B reserved for Qemu; low nybble is revision number.
|
657 | 642a4f96 | ths | If this code is substantially changed, you may want to consider
|
658 | 642a4f96 | ths | incrementing the revision. */
|
659 | 642a4f96 | ths | if (protocol >= 0x200) |
660 | 642a4f96 | ths | header[0x210] = 0xB0; |
661 | 642a4f96 | ths | |
662 | 642a4f96 | ths | /* heap */
|
663 | 642a4f96 | ths | if (protocol >= 0x201) { |
664 | 642a4f96 | ths | header[0x211] |= 0x80; /* CAN_USE_HEAP */ |
665 | 642a4f96 | ths | stw_p(header+0x224, cmdline_addr-real_addr-0x200); |
666 | 642a4f96 | ths | } |
667 | 642a4f96 | ths | |
668 | 642a4f96 | ths | /* load initrd */
|
669 | 642a4f96 | ths | if (initrd_filename) {
|
670 | 642a4f96 | ths | if (protocol < 0x200) { |
671 | 642a4f96 | ths | fprintf(stderr, "qemu: linux kernel too old to load a ram disk\n");
|
672 | 642a4f96 | ths | exit(1);
|
673 | 642a4f96 | ths | } |
674 | 642a4f96 | ths | |
675 | 642a4f96 | ths | fi = fopen(initrd_filename, "rb");
|
676 | 642a4f96 | ths | if (!fi) {
|
677 | 642a4f96 | ths | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
678 | 642a4f96 | ths | initrd_filename); |
679 | 642a4f96 | ths | exit(1);
|
680 | 642a4f96 | ths | } |
681 | 642a4f96 | ths | |
682 | 642a4f96 | ths | initrd_size = get_file_size(fi); |
683 | a37af289 | blueswir1 | initrd_addr = (initrd_max-initrd_size) & ~4095;
|
684 | 642a4f96 | ths | |
685 | 526ccb7a | balrog | fprintf(stderr, "qemu: loading initrd (%#x bytes) at 0x" TARGET_FMT_plx
|
686 | 526ccb7a | balrog | "\n", initrd_size, initrd_addr);
|
687 | 642a4f96 | ths | |
688 | a37af289 | blueswir1 | if (!fread_targphys_ok(initrd_addr, initrd_size, fi)) {
|
689 | 642a4f96 | ths | fprintf(stderr, "qemu: read error on initial ram disk '%s'\n",
|
690 | 642a4f96 | ths | initrd_filename); |
691 | 642a4f96 | ths | exit(1);
|
692 | 642a4f96 | ths | } |
693 | 642a4f96 | ths | fclose(fi); |
694 | 642a4f96 | ths | |
695 | a37af289 | blueswir1 | stl_p(header+0x218, initrd_addr);
|
696 | 642a4f96 | ths | stl_p(header+0x21c, initrd_size);
|
697 | 642a4f96 | ths | } |
698 | 642a4f96 | ths | |
699 | 642a4f96 | ths | /* store the finalized header and load the rest of the kernel */
|
700 | a37af289 | blueswir1 | cpu_physical_memory_write(real_addr, header, 1024);
|
701 | 642a4f96 | ths | |
702 | 642a4f96 | ths | setup_size = header[0x1f1];
|
703 | 642a4f96 | ths | if (setup_size == 0) |
704 | 642a4f96 | ths | setup_size = 4;
|
705 | 642a4f96 | ths | |
706 | 642a4f96 | ths | setup_size = (setup_size+1)*512; |
707 | 642a4f96 | ths | kernel_size -= setup_size; /* Size of protected-mode code */
|
708 | 642a4f96 | ths | |
709 | a37af289 | blueswir1 | if (!fread_targphys_ok(real_addr+1024, setup_size-1024, f) || |
710 | a37af289 | blueswir1 | !fread_targphys_ok(prot_addr, kernel_size, f)) { |
711 | 642a4f96 | ths | fprintf(stderr, "qemu: read error on kernel '%s'\n",
|
712 | 642a4f96 | ths | kernel_filename); |
713 | 642a4f96 | ths | exit(1);
|
714 | 642a4f96 | ths | } |
715 | 642a4f96 | ths | fclose(f); |
716 | 642a4f96 | ths | |
717 | 642a4f96 | ths | /* generate bootsector to set up the initial register state */
|
718 | a37af289 | blueswir1 | real_seg = real_addr >> 4;
|
719 | 642a4f96 | ths | seg[0] = seg[2] = seg[3] = seg[4] = seg[4] = real_seg; |
720 | 642a4f96 | ths | seg[1] = real_seg+0x20; /* CS */ |
721 | 642a4f96 | ths | memset(gpr, 0, sizeof gpr); |
722 | 642a4f96 | ths | gpr[4] = cmdline_addr-real_addr-16; /* SP (-16 is paranoia) */ |
723 | 642a4f96 | ths | |
724 | 4fc9af53 | aliguori | generate_bootsect(option_rom, gpr, seg, 0);
|
725 | 642a4f96 | ths | } |
726 | 642a4f96 | ths | |
727 | 59b8ad81 | bellard | static void main_cpu_reset(void *opaque) |
728 | 59b8ad81 | bellard | { |
729 | 59b8ad81 | bellard | CPUState *env = opaque; |
730 | 59b8ad81 | bellard | cpu_reset(env); |
731 | 59b8ad81 | bellard | } |
732 | 59b8ad81 | bellard | |
733 | b41a2cd1 | bellard | static const int ide_iobase[2] = { 0x1f0, 0x170 }; |
734 | b41a2cd1 | bellard | static const int ide_iobase2[2] = { 0x3f6, 0x376 }; |
735 | b41a2cd1 | bellard | static const int ide_irq[2] = { 14, 15 }; |
736 | b41a2cd1 | bellard | |
737 | b41a2cd1 | bellard | #define NE2000_NB_MAX 6 |
738 | b41a2cd1 | bellard | |
739 | 8d11df9e | bellard | static int ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 }; |
740 | b41a2cd1 | bellard | static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 }; |
741 | b41a2cd1 | bellard | |
742 | 8d11df9e | bellard | static int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; |
743 | 8d11df9e | bellard | static int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 }; |
744 | 8d11df9e | bellard | |
745 | 6508fe59 | bellard | static int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc }; |
746 | 6508fe59 | bellard | static int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 }; |
747 | 6508fe59 | bellard | |
748 | 6a36d84e | bellard | #ifdef HAS_AUDIO
|
749 | d537cf6c | pbrook | static void audio_init (PCIBus *pci_bus, qemu_irq *pic) |
750 | 6a36d84e | bellard | { |
751 | 6a36d84e | bellard | struct soundhw *c;
|
752 | 6a36d84e | bellard | int audio_enabled = 0; |
753 | 6a36d84e | bellard | |
754 | 6a36d84e | bellard | for (c = soundhw; !audio_enabled && c->name; ++c) {
|
755 | 6a36d84e | bellard | audio_enabled = c->enabled; |
756 | 6a36d84e | bellard | } |
757 | 6a36d84e | bellard | |
758 | 6a36d84e | bellard | if (audio_enabled) {
|
759 | 6a36d84e | bellard | AudioState *s; |
760 | 6a36d84e | bellard | |
761 | 6a36d84e | bellard | s = AUD_init (); |
762 | 6a36d84e | bellard | if (s) {
|
763 | 6a36d84e | bellard | for (c = soundhw; c->name; ++c) {
|
764 | 6a36d84e | bellard | if (c->enabled) {
|
765 | 6a36d84e | bellard | if (c->isa) {
|
766 | d537cf6c | pbrook | c->init.init_isa (s, pic); |
767 | 6a36d84e | bellard | } |
768 | 6a36d84e | bellard | else {
|
769 | 6a36d84e | bellard | if (pci_bus) {
|
770 | 6a36d84e | bellard | c->init.init_pci (pci_bus, s); |
771 | 6a36d84e | bellard | } |
772 | 6a36d84e | bellard | } |
773 | 6a36d84e | bellard | } |
774 | 6a36d84e | bellard | } |
775 | 6a36d84e | bellard | } |
776 | 6a36d84e | bellard | } |
777 | 6a36d84e | bellard | } |
778 | 6a36d84e | bellard | #endif
|
779 | 6a36d84e | bellard | |
780 | d537cf6c | pbrook | static void pc_init_ne2k_isa(NICInfo *nd, qemu_irq *pic) |
781 | a41b2ff2 | pbrook | { |
782 | a41b2ff2 | pbrook | static int nb_ne2k = 0; |
783 | a41b2ff2 | pbrook | |
784 | a41b2ff2 | pbrook | if (nb_ne2k == NE2000_NB_MAX)
|
785 | a41b2ff2 | pbrook | return;
|
786 | d537cf6c | pbrook | isa_ne2000_init(ne2000_io[nb_ne2k], pic[ne2000_irq[nb_ne2k]], nd); |
787 | a41b2ff2 | pbrook | nb_ne2k++; |
788 | a41b2ff2 | pbrook | } |
789 | a41b2ff2 | pbrook | |
790 | f753ff16 | pbrook | static int load_option_rom(const char *oprom, target_phys_addr_t start, |
791 | f753ff16 | pbrook | target_phys_addr_t end) |
792 | f753ff16 | pbrook | { |
793 | f753ff16 | pbrook | int size;
|
794 | f753ff16 | pbrook | |
795 | f753ff16 | pbrook | size = get_image_size(oprom); |
796 | f753ff16 | pbrook | if (size > 0 && start + size > end) { |
797 | f753ff16 | pbrook | fprintf(stderr, "Not enough space to load option rom '%s'\n",
|
798 | f753ff16 | pbrook | oprom); |
799 | f753ff16 | pbrook | exit(1);
|
800 | f753ff16 | pbrook | } |
801 | f753ff16 | pbrook | size = load_image_targphys(oprom, start, end - start); |
802 | f753ff16 | pbrook | if (size < 0) { |
803 | f753ff16 | pbrook | fprintf(stderr, "Could not load option rom '%s'\n", oprom);
|
804 | f753ff16 | pbrook | exit(1);
|
805 | f753ff16 | pbrook | } |
806 | f753ff16 | pbrook | /* Round up optiom rom size to the next 2k boundary */
|
807 | f753ff16 | pbrook | size = (size + 2047) & ~2047; |
808 | f753ff16 | pbrook | return size;
|
809 | f753ff16 | pbrook | } |
810 | f753ff16 | pbrook | |
811 | 80cabfad | bellard | /* PC hardware initialisation */
|
812 | 00f82b8a | aurel32 | static void pc_init1(ram_addr_t ram_size, int vga_ram_size, |
813 | 3023f332 | aliguori | const char *boot_device, |
814 | b5ff2d6e | bellard | const char *kernel_filename, const char *kernel_cmdline, |
815 | 3dbbdc25 | bellard | const char *initrd_filename, |
816 | a049de61 | bellard | int pci_enabled, const char *cpu_model) |
817 | 80cabfad | bellard | { |
818 | 80cabfad | bellard | char buf[1024]; |
819 | 642a4f96 | ths | int ret, linux_boot, i;
|
820 | b584726d | pbrook | ram_addr_t ram_addr, bios_offset, option_rom_offset; |
821 | 00f82b8a | aurel32 | ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
|
822 | f753ff16 | pbrook | int bios_size, isa_bios_size, oprom_area_size;
|
823 | 46e50e9d | bellard | PCIBus *pci_bus; |
824 | 5c3ff3a7 | pbrook | int piix3_devfn = -1; |
825 | 59b8ad81 | bellard | CPUState *env; |
826 | d537cf6c | pbrook | qemu_irq *cpu_irq; |
827 | d537cf6c | pbrook | qemu_irq *i8259; |
828 | e4bcb14c | ths | int index;
|
829 | e4bcb14c | ths | BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; |
830 | e4bcb14c | ths | BlockDriverState *fd[MAX_FD]; |
831 | 34b39c2b | aliguori | int using_vga = cirrus_vga_enabled || std_vga_enabled || vmsvga_enabled;
|
832 | d592d303 | bellard | |
833 | 00f82b8a | aurel32 | if (ram_size >= 0xe0000000 ) { |
834 | 00f82b8a | aurel32 | above_4g_mem_size = ram_size - 0xe0000000;
|
835 | 00f82b8a | aurel32 | below_4g_mem_size = 0xe0000000;
|
836 | 00f82b8a | aurel32 | } else {
|
837 | 00f82b8a | aurel32 | below_4g_mem_size = ram_size; |
838 | 00f82b8a | aurel32 | } |
839 | 00f82b8a | aurel32 | |
840 | 80cabfad | bellard | linux_boot = (kernel_filename != NULL);
|
841 | 80cabfad | bellard | |
842 | 59b8ad81 | bellard | /* init CPUs */
|
843 | a049de61 | bellard | if (cpu_model == NULL) { |
844 | a049de61 | bellard | #ifdef TARGET_X86_64
|
845 | a049de61 | bellard | cpu_model = "qemu64";
|
846 | a049de61 | bellard | #else
|
847 | a049de61 | bellard | cpu_model = "qemu32";
|
848 | a049de61 | bellard | #endif
|
849 | a049de61 | bellard | } |
850 | a049de61 | bellard | |
851 | 59b8ad81 | bellard | for(i = 0; i < smp_cpus; i++) { |
852 | aaed909a | bellard | env = cpu_init(cpu_model); |
853 | aaed909a | bellard | if (!env) {
|
854 | aaed909a | bellard | fprintf(stderr, "Unable to find x86 CPU definition\n");
|
855 | aaed909a | bellard | exit(1);
|
856 | aaed909a | bellard | } |
857 | 59b8ad81 | bellard | if (i != 0) |
858 | ce5232c5 | bellard | env->halted = 1;
|
859 | 59b8ad81 | bellard | if (smp_cpus > 1) { |
860 | 59b8ad81 | bellard | /* XXX: enable it in all cases */
|
861 | 59b8ad81 | bellard | env->cpuid_features |= CPUID_APIC; |
862 | 59b8ad81 | bellard | } |
863 | 59b8ad81 | bellard | qemu_register_reset(main_cpu_reset, env); |
864 | 59b8ad81 | bellard | if (pci_enabled) {
|
865 | 59b8ad81 | bellard | apic_init(env); |
866 | 59b8ad81 | bellard | } |
867 | 59b8ad81 | bellard | } |
868 | 59b8ad81 | bellard | |
869 | 26fb5e48 | aurel32 | vmport_init(); |
870 | 26fb5e48 | aurel32 | |
871 | 80cabfad | bellard | /* allocate RAM */
|
872 | 82b36dc3 | aliguori | ram_addr = qemu_ram_alloc(0xa0000);
|
873 | 82b36dc3 | aliguori | cpu_register_physical_memory(0, 0xa0000, ram_addr); |
874 | 82b36dc3 | aliguori | |
875 | 82b36dc3 | aliguori | /* Allocate, even though we won't register, so we don't break the
|
876 | 82b36dc3 | aliguori | * phys_ram_base + PA assumption. This range includes vga (0xa0000 - 0xc0000),
|
877 | 82b36dc3 | aliguori | * and some bios areas, which will be registered later
|
878 | 82b36dc3 | aliguori | */
|
879 | 82b36dc3 | aliguori | ram_addr = qemu_ram_alloc(0x100000 - 0xa0000); |
880 | 82b36dc3 | aliguori | ram_addr = qemu_ram_alloc(below_4g_mem_size - 0x100000);
|
881 | 82b36dc3 | aliguori | cpu_register_physical_memory(0x100000,
|
882 | 82b36dc3 | aliguori | below_4g_mem_size - 0x100000,
|
883 | 82b36dc3 | aliguori | ram_addr); |
884 | 00f82b8a | aurel32 | |
885 | 00f82b8a | aurel32 | /* above 4giga memory allocation */
|
886 | 00f82b8a | aurel32 | if (above_4g_mem_size > 0) { |
887 | 82b36dc3 | aliguori | ram_addr = qemu_ram_alloc(above_4g_mem_size); |
888 | 82b36dc3 | aliguori | cpu_register_physical_memory(0x100000000ULL,
|
889 | 526ccb7a | balrog | above_4g_mem_size, |
890 | 82b36dc3 | aliguori | ram_addr); |
891 | 00f82b8a | aurel32 | } |
892 | 80cabfad | bellard | |
893 | 82b36dc3 | aliguori | |
894 | 970ac5a3 | bellard | /* BIOS load */
|
895 | 1192dad8 | j_mayer | if (bios_name == NULL) |
896 | 1192dad8 | j_mayer | bios_name = BIOS_FILENAME; |
897 | 1192dad8 | j_mayer | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); |
898 | 7587cf44 | bellard | bios_size = get_image_size(buf); |
899 | 5fafdf24 | ths | if (bios_size <= 0 || |
900 | 970ac5a3 | bellard | (bios_size % 65536) != 0) { |
901 | 7587cf44 | bellard | goto bios_error;
|
902 | 7587cf44 | bellard | } |
903 | 970ac5a3 | bellard | bios_offset = qemu_ram_alloc(bios_size); |
904 | 44654490 | pbrook | ret = load_image(buf, qemu_get_ram_ptr(bios_offset)); |
905 | 7587cf44 | bellard | if (ret != bios_size) {
|
906 | 7587cf44 | bellard | bios_error:
|
907 | 970ac5a3 | bellard | fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", buf);
|
908 | 80cabfad | bellard | exit(1);
|
909 | 80cabfad | bellard | } |
910 | 7587cf44 | bellard | /* map the last 128KB of the BIOS in ISA space */
|
911 | 7587cf44 | bellard | isa_bios_size = bios_size; |
912 | 7587cf44 | bellard | if (isa_bios_size > (128 * 1024)) |
913 | 7587cf44 | bellard | isa_bios_size = 128 * 1024; |
914 | 5fafdf24 | ths | cpu_register_physical_memory(0x100000 - isa_bios_size,
|
915 | 5fafdf24 | ths | isa_bios_size, |
916 | 7587cf44 | bellard | (bios_offset + bios_size - isa_bios_size) | IO_MEM_ROM); |
917 | 9ae02555 | ths | |
918 | 4fc9af53 | aliguori | |
919 | f753ff16 | pbrook | |
920 | f753ff16 | pbrook | option_rom_offset = qemu_ram_alloc(0x20000);
|
921 | f753ff16 | pbrook | oprom_area_size = 0;
|
922 | f753ff16 | pbrook | cpu_register_physical_memory(0xc0000, 0x20000, |
923 | f753ff16 | pbrook | option_rom_offset | IO_MEM_ROM); |
924 | f753ff16 | pbrook | |
925 | f753ff16 | pbrook | if (using_vga) {
|
926 | f753ff16 | pbrook | /* VGA BIOS load */
|
927 | f753ff16 | pbrook | if (cirrus_vga_enabled) {
|
928 | f753ff16 | pbrook | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, |
929 | f753ff16 | pbrook | VGABIOS_CIRRUS_FILENAME); |
930 | f753ff16 | pbrook | } else {
|
931 | f753ff16 | pbrook | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); |
932 | 970ac5a3 | bellard | } |
933 | f753ff16 | pbrook | oprom_area_size = load_option_rom(buf, 0xc0000, 0xe0000); |
934 | f753ff16 | pbrook | } |
935 | f753ff16 | pbrook | /* Although video roms can grow larger than 0x8000, the area between
|
936 | f753ff16 | pbrook | * 0xc0000 - 0xc8000 is reserved for them. It means we won't be looking
|
937 | f753ff16 | pbrook | * for any other kind of option rom inside this area */
|
938 | f753ff16 | pbrook | if (oprom_area_size < 0x8000) |
939 | f753ff16 | pbrook | oprom_area_size = 0x8000;
|
940 | f753ff16 | pbrook | |
941 | f753ff16 | pbrook | if (linux_boot) {
|
942 | 7ffa4767 | pbrook | load_linux(0xc0000 + oprom_area_size,
|
943 | f753ff16 | pbrook | kernel_filename, initrd_filename, kernel_cmdline); |
944 | f753ff16 | pbrook | oprom_area_size += 2048;
|
945 | f753ff16 | pbrook | } |
946 | f753ff16 | pbrook | |
947 | f753ff16 | pbrook | for (i = 0; i < nb_option_roms; i++) { |
948 | f753ff16 | pbrook | oprom_area_size += load_option_rom(option_rom[i], |
949 | f753ff16 | pbrook | 0xc0000 + oprom_area_size, 0xe0000); |
950 | 9ae02555 | ths | } |
951 | 9ae02555 | ths | |
952 | 7587cf44 | bellard | /* map all the bios at the top of memory */
|
953 | 5fafdf24 | ths | cpu_register_physical_memory((uint32_t)(-bios_size), |
954 | 7587cf44 | bellard | bios_size, bios_offset | IO_MEM_ROM); |
955 | 3b46e624 | ths | |
956 | 80cabfad | bellard | bochs_bios_init(); |
957 | 80cabfad | bellard | |
958 | a5b38b51 | aurel32 | cpu_irq = qemu_allocate_irqs(pic_irq_request, NULL, 1); |
959 | d537cf6c | pbrook | i8259 = i8259_init(cpu_irq[0]);
|
960 | d537cf6c | pbrook | ferr_irq = i8259[13];
|
961 | d537cf6c | pbrook | |
962 | 69b91039 | bellard | if (pci_enabled) {
|
963 | d537cf6c | pbrook | pci_bus = i440fx_init(&i440fx_state, i8259); |
964 | 8f1c91d8 | ths | piix3_devfn = piix3_init(pci_bus, -1);
|
965 | 46e50e9d | bellard | } else {
|
966 | 46e50e9d | bellard | pci_bus = NULL;
|
967 | 69b91039 | bellard | } |
968 | 69b91039 | bellard | |
969 | 80cabfad | bellard | /* init basic PC hardware */
|
970 | b41a2cd1 | bellard | register_ioport_write(0x80, 1, 1, ioport80_write, NULL); |
971 | 80cabfad | bellard | |
972 | f929aad6 | bellard | register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL); |
973 | f929aad6 | bellard | |
974 | 1f04275e | bellard | if (cirrus_vga_enabled) {
|
975 | 1f04275e | bellard | if (pci_enabled) {
|
976 | b584726d | pbrook | pci_cirrus_vga_init(pci_bus, vga_ram_size); |
977 | 1f04275e | bellard | } else {
|
978 | b584726d | pbrook | isa_cirrus_vga_init(vga_ram_size); |
979 | 1f04275e | bellard | } |
980 | d34cab9f | ths | } else if (vmsvga_enabled) { |
981 | d34cab9f | ths | if (pci_enabled)
|
982 | b584726d | pbrook | pci_vmsvga_init(pci_bus, vga_ram_size); |
983 | d34cab9f | ths | else
|
984 | d34cab9f | ths | fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
|
985 | c2b3b41a | aliguori | } else if (std_vga_enabled) { |
986 | 89b6b508 | bellard | if (pci_enabled) {
|
987 | b584726d | pbrook | pci_vga_init(pci_bus, vga_ram_size, 0, 0); |
988 | 89b6b508 | bellard | } else {
|
989 | b584726d | pbrook | isa_vga_init(vga_ram_size); |
990 | 89b6b508 | bellard | } |
991 | 1f04275e | bellard | } |
992 | 80cabfad | bellard | |
993 | 42fc73a1 | aurel32 | rtc_state = rtc_init(0x70, i8259[8], 2000); |
994 | 80cabfad | bellard | |
995 | 3b4366de | blueswir1 | qemu_register_boot_set(pc_boot_set, rtc_state); |
996 | 3b4366de | blueswir1 | |
997 | e1a23744 | bellard | register_ioport_read(0x92, 1, 1, ioport92_read, NULL); |
998 | e1a23744 | bellard | register_ioport_write(0x92, 1, 1, ioport92_write, NULL); |
999 | e1a23744 | bellard | |
1000 | d592d303 | bellard | if (pci_enabled) {
|
1001 | d592d303 | bellard | ioapic = ioapic_init(); |
1002 | d592d303 | bellard | } |
1003 | d537cf6c | pbrook | pit = pit_init(0x40, i8259[0]); |
1004 | fd06c375 | bellard | pcspk_init(pit); |
1005 | 16b29ae1 | aliguori | if (!no_hpet) {
|
1006 | 16b29ae1 | aliguori | hpet_init(i8259); |
1007 | 16b29ae1 | aliguori | } |
1008 | d592d303 | bellard | if (pci_enabled) {
|
1009 | d592d303 | bellard | pic_set_alt_irq_func(isa_pic, ioapic_set_irq, ioapic); |
1010 | d592d303 | bellard | } |
1011 | b41a2cd1 | bellard | |
1012 | 8d11df9e | bellard | for(i = 0; i < MAX_SERIAL_PORTS; i++) { |
1013 | 8d11df9e | bellard | if (serial_hds[i]) {
|
1014 | b6cd0ea1 | aurel32 | serial_init(serial_io[i], i8259[serial_irq[i]], 115200,
|
1015 | b6cd0ea1 | aurel32 | serial_hds[i]); |
1016 | 8d11df9e | bellard | } |
1017 | 8d11df9e | bellard | } |
1018 | b41a2cd1 | bellard | |
1019 | 6508fe59 | bellard | for(i = 0; i < MAX_PARALLEL_PORTS; i++) { |
1020 | 6508fe59 | bellard | if (parallel_hds[i]) {
|
1021 | d537cf6c | pbrook | parallel_init(parallel_io[i], i8259[parallel_irq[i]], |
1022 | d537cf6c | pbrook | parallel_hds[i]); |
1023 | 6508fe59 | bellard | } |
1024 | 6508fe59 | bellard | } |
1025 | 6508fe59 | bellard | |
1026 | a41b2ff2 | pbrook | for(i = 0; i < nb_nics; i++) { |
1027 | cb457d76 | aliguori | NICInfo *nd = &nd_table[i]; |
1028 | cb457d76 | aliguori | |
1029 | cb457d76 | aliguori | if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0)) |
1030 | d537cf6c | pbrook | pc_init_ne2k_isa(nd, i8259); |
1031 | cb457d76 | aliguori | else
|
1032 | cb457d76 | aliguori | pci_nic_init(pci_bus, nd, -1, "ne2k_pci"); |
1033 | a41b2ff2 | pbrook | } |
1034 | b41a2cd1 | bellard | |
1035 | 5e3cb534 | aliguori | qemu_system_hot_add_init(); |
1036 | 5e3cb534 | aliguori | |
1037 | e4bcb14c | ths | if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
|
1038 | e4bcb14c | ths | fprintf(stderr, "qemu: too many IDE bus\n");
|
1039 | e4bcb14c | ths | exit(1);
|
1040 | e4bcb14c | ths | } |
1041 | e4bcb14c | ths | |
1042 | e4bcb14c | ths | for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { |
1043 | e4bcb14c | ths | index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS); |
1044 | e4bcb14c | ths | if (index != -1) |
1045 | e4bcb14c | ths | hd[i] = drives_table[index].bdrv; |
1046 | e4bcb14c | ths | else
|
1047 | e4bcb14c | ths | hd[i] = NULL;
|
1048 | e4bcb14c | ths | } |
1049 | e4bcb14c | ths | |
1050 | a41b2ff2 | pbrook | if (pci_enabled) {
|
1051 | e4bcb14c | ths | pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1, i8259);
|
1052 | a41b2ff2 | pbrook | } else {
|
1053 | e4bcb14c | ths | for(i = 0; i < MAX_IDE_BUS; i++) { |
1054 | d537cf6c | pbrook | isa_ide_init(ide_iobase[i], ide_iobase2[i], i8259[ide_irq[i]], |
1055 | e4bcb14c | ths | hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
|
1056 | 69b91039 | bellard | } |
1057 | b41a2cd1 | bellard | } |
1058 | 69b91039 | bellard | |
1059 | d537cf6c | pbrook | i8042_init(i8259[1], i8259[12], 0x60); |
1060 | 7c29d0c0 | bellard | DMA_init(0);
|
1061 | 6a36d84e | bellard | #ifdef HAS_AUDIO
|
1062 | d537cf6c | pbrook | audio_init(pci_enabled ? pci_bus : NULL, i8259);
|
1063 | fb065187 | bellard | #endif
|
1064 | 80cabfad | bellard | |
1065 | e4bcb14c | ths | for(i = 0; i < MAX_FD; i++) { |
1066 | e4bcb14c | ths | index = drive_get_index(IF_FLOPPY, 0, i);
|
1067 | e4bcb14c | ths | if (index != -1) |
1068 | e4bcb14c | ths | fd[i] = drives_table[index].bdrv; |
1069 | e4bcb14c | ths | else
|
1070 | e4bcb14c | ths | fd[i] = NULL;
|
1071 | e4bcb14c | ths | } |
1072 | e4bcb14c | ths | floppy_controller = fdctrl_init(i8259[6], 2, 0, 0x3f0, fd); |
1073 | b41a2cd1 | bellard | |
1074 | 00f82b8a | aurel32 | cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, hd); |
1075 | 69b91039 | bellard | |
1076 | bb36d470 | bellard | if (pci_enabled && usb_enabled) {
|
1077 | afcc3cdf | ths | usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
|
1078 | bb36d470 | bellard | } |
1079 | bb36d470 | bellard | |
1080 | 6515b203 | bellard | if (pci_enabled && acpi_enabled) {
|
1081 | 3fffc223 | ths | uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */ |
1082 | 0ff596d0 | pbrook | i2c_bus *smbus; |
1083 | 0ff596d0 | pbrook | |
1084 | 0ff596d0 | pbrook | /* TODO: Populate SPD eeprom data. */
|
1085 | cf7a2fe2 | aurel32 | smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, i8259[9]); |
1086 | 3fffc223 | ths | for (i = 0; i < 8; i++) { |
1087 | 0ff596d0 | pbrook | smbus_eeprom_device_init(smbus, 0x50 + i, eeprom_buf + (i * 256)); |
1088 | 3fffc223 | ths | } |
1089 | 6515b203 | bellard | } |
1090 | 3b46e624 | ths | |
1091 | a5954d5c | bellard | if (i440fx_state) {
|
1092 | a5954d5c | bellard | i440fx_init_memory_mappings(i440fx_state); |
1093 | a5954d5c | bellard | } |
1094 | e4bcb14c | ths | |
1095 | 7d8406be | pbrook | if (pci_enabled) {
|
1096 | e4bcb14c | ths | int max_bus;
|
1097 | e4bcb14c | ths | int bus, unit;
|
1098 | 7d8406be | pbrook | void *scsi;
|
1099 | 96d30e48 | ths | |
1100 | e4bcb14c | ths | max_bus = drive_get_max_bus(IF_SCSI); |
1101 | e4bcb14c | ths | |
1102 | e4bcb14c | ths | for (bus = 0; bus <= max_bus; bus++) { |
1103 | e4bcb14c | ths | scsi = lsi_scsi_init(pci_bus, -1);
|
1104 | e4bcb14c | ths | for (unit = 0; unit < LSI_MAX_DEVS; unit++) { |
1105 | e4bcb14c | ths | index = drive_get_index(IF_SCSI, bus, unit); |
1106 | e4bcb14c | ths | if (index == -1) |
1107 | e4bcb14c | ths | continue;
|
1108 | e4bcb14c | ths | lsi_scsi_attach(scsi, drives_table[index].bdrv, unit); |
1109 | e4bcb14c | ths | } |
1110 | e4bcb14c | ths | } |
1111 | 7d8406be | pbrook | } |
1112 | 6e02c38d | aliguori | |
1113 | 6e02c38d | aliguori | /* Add virtio block devices */
|
1114 | 6e02c38d | aliguori | if (pci_enabled) {
|
1115 | 6e02c38d | aliguori | int index;
|
1116 | 6e02c38d | aliguori | int unit_id = 0; |
1117 | 6e02c38d | aliguori | |
1118 | 6e02c38d | aliguori | while ((index = drive_get_index(IF_VIRTIO, 0, unit_id)) != -1) { |
1119 | 9b32d5a5 | aliguori | virtio_blk_init(pci_bus, drives_table[index].bdrv); |
1120 | 6e02c38d | aliguori | unit_id++; |
1121 | 6e02c38d | aliguori | } |
1122 | 6e02c38d | aliguori | } |
1123 | bd322087 | aliguori | |
1124 | bd322087 | aliguori | /* Add virtio balloon device */
|
1125 | bd322087 | aliguori | if (pci_enabled)
|
1126 | bd322087 | aliguori | virtio_balloon_init(pci_bus); |
1127 | a2fa19f9 | aliguori | |
1128 | a2fa19f9 | aliguori | /* Add virtio console devices */
|
1129 | a2fa19f9 | aliguori | if (pci_enabled) {
|
1130 | a2fa19f9 | aliguori | for(i = 0; i < MAX_VIRTIO_CONSOLES; i++) { |
1131 | a2fa19f9 | aliguori | if (virtcon_hds[i])
|
1132 | a2fa19f9 | aliguori | virtio_console_init(pci_bus, virtcon_hds[i]); |
1133 | a2fa19f9 | aliguori | } |
1134 | a2fa19f9 | aliguori | } |
1135 | 80cabfad | bellard | } |
1136 | b5ff2d6e | bellard | |
1137 | 00f82b8a | aurel32 | static void pc_init_pci(ram_addr_t ram_size, int vga_ram_size, |
1138 | 3023f332 | aliguori | const char *boot_device, |
1139 | 5fafdf24 | ths | const char *kernel_filename, |
1140 | 3dbbdc25 | bellard | const char *kernel_cmdline, |
1141 | 94fc95cd | j_mayer | const char *initrd_filename, |
1142 | 94fc95cd | j_mayer | const char *cpu_model) |
1143 | 3dbbdc25 | bellard | { |
1144 | 3023f332 | aliguori | pc_init1(ram_size, vga_ram_size, boot_device, |
1145 | 3dbbdc25 | bellard | kernel_filename, kernel_cmdline, |
1146 | a049de61 | bellard | initrd_filename, 1, cpu_model);
|
1147 | 3dbbdc25 | bellard | } |
1148 | 3dbbdc25 | bellard | |
1149 | 00f82b8a | aurel32 | static void pc_init_isa(ram_addr_t ram_size, int vga_ram_size, |
1150 | 3023f332 | aliguori | const char *boot_device, |
1151 | 5fafdf24 | ths | const char *kernel_filename, |
1152 | 3dbbdc25 | bellard | const char *kernel_cmdline, |
1153 | 94fc95cd | j_mayer | const char *initrd_filename, |
1154 | 94fc95cd | j_mayer | const char *cpu_model) |
1155 | 3dbbdc25 | bellard | { |
1156 | 3023f332 | aliguori | pc_init1(ram_size, vga_ram_size, boot_device, |
1157 | 3dbbdc25 | bellard | kernel_filename, kernel_cmdline, |
1158 | a049de61 | bellard | initrd_filename, 0, cpu_model);
|
1159 | 3dbbdc25 | bellard | } |
1160 | 3dbbdc25 | bellard | |
1161 | 0bacd130 | aliguori | /* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE)
|
1162 | 0bacd130 | aliguori | BIOS will read it and start S3 resume at POST Entry */
|
1163 | 0bacd130 | aliguori | void cmos_set_s3_resume(void) |
1164 | 0bacd130 | aliguori | { |
1165 | 0bacd130 | aliguori | if (rtc_state)
|
1166 | 0bacd130 | aliguori | rtc_set_memory(rtc_state, 0xF, 0xFE); |
1167 | 0bacd130 | aliguori | } |
1168 | 0bacd130 | aliguori | |
1169 | b5ff2d6e | bellard | QEMUMachine pc_machine = { |
1170 | a245f2e7 | aurel32 | .name = "pc",
|
1171 | a245f2e7 | aurel32 | .desc = "Standard PC",
|
1172 | a245f2e7 | aurel32 | .init = pc_init_pci, |
1173 | b2097003 | aliguori | .max_cpus = 255,
|
1174 | 3dbbdc25 | bellard | }; |
1175 | 3dbbdc25 | bellard | |
1176 | 3dbbdc25 | bellard | QEMUMachine isapc_machine = { |
1177 | a245f2e7 | aurel32 | .name = "isapc",
|
1178 | a245f2e7 | aurel32 | .desc = "ISA-only PC",
|
1179 | a245f2e7 | aurel32 | .init = pc_init_isa, |
1180 | b2097003 | aliguori | .max_cpus = 1,
|
1181 | b5ff2d6e | bellard | }; |