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