root / hw / pc.c @ fb6cf1d0
History | View | Annotate | Download (11.6 kB)
1 | 80cabfad | bellard | /*
|
---|---|---|---|
2 | 80cabfad | bellard | * QEMU PC System Emulator
|
3 | 80cabfad | bellard | *
|
4 | 80cabfad | bellard | * Copyright (c) 2003-2004 Fabrice Bellard
|
5 | 80cabfad | bellard | *
|
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 | 80cabfad | bellard | #include "vl.h" |
25 | 80cabfad | bellard | |
26 | b41a2cd1 | bellard | /* output Bochs bios info messages */
|
27 | b41a2cd1 | bellard | //#define DEBUG_BIOS
|
28 | b41a2cd1 | bellard | |
29 | 80cabfad | bellard | #define BIOS_FILENAME "bios.bin" |
30 | 80cabfad | bellard | #define VGABIOS_FILENAME "vgabios.bin" |
31 | 80cabfad | bellard | #define LINUX_BOOT_FILENAME "linux_boot.bin" |
32 | 80cabfad | bellard | |
33 | 80cabfad | bellard | #define KERNEL_LOAD_ADDR 0x00100000 |
34 | 80cabfad | bellard | #define INITRD_LOAD_ADDR 0x00400000 |
35 | 80cabfad | bellard | #define KERNEL_PARAMS_ADDR 0x00090000 |
36 | 80cabfad | bellard | #define KERNEL_CMDLINE_ADDR 0x00099000 |
37 | 80cabfad | bellard | |
38 | 80cabfad | bellard | int speaker_data_on;
|
39 | 80cabfad | bellard | int dummy_refresh_clock;
|
40 | baca51fa | bellard | static fdctrl_t *floppy_controller;
|
41 | b0a21b53 | bellard | static RTCState *rtc_state;
|
42 | ec844b96 | bellard | static PITState *pit;
|
43 | 80cabfad | bellard | |
44 | b41a2cd1 | bellard | static void ioport80_write(void *opaque, uint32_t addr, uint32_t data) |
45 | 80cabfad | bellard | { |
46 | 80cabfad | bellard | } |
47 | 80cabfad | bellard | |
48 | b0a21b53 | bellard | /* PC cmos mappings */
|
49 | b0a21b53 | bellard | |
50 | 80cabfad | bellard | #define REG_EQUIPMENT_BYTE 0x14 |
51 | b0a21b53 | bellard | #define REG_IBM_CENTURY_BYTE 0x32 |
52 | b0a21b53 | bellard | #define REG_IBM_PS2_CENTURY_BYTE 0x37 |
53 | b0a21b53 | bellard | |
54 | b0a21b53 | bellard | |
55 | b0a21b53 | bellard | static inline int to_bcd(RTCState *s, int a) |
56 | b0a21b53 | bellard | { |
57 | b0a21b53 | bellard | return ((a / 10) << 4) | (a % 10); |
58 | b0a21b53 | bellard | } |
59 | 80cabfad | bellard | |
60 | 80cabfad | bellard | static void cmos_init(int ram_size, int boot_device) |
61 | 80cabfad | bellard | { |
62 | b0a21b53 | bellard | RTCState *s = rtc_state; |
63 | 80cabfad | bellard | int val;
|
64 | b41a2cd1 | bellard | int fd0, fd1, nb;
|
65 | b0a21b53 | bellard | time_t ti; |
66 | b0a21b53 | bellard | struct tm *tm;
|
67 | b0a21b53 | bellard | |
68 | b0a21b53 | bellard | /* set the CMOS date */
|
69 | b0a21b53 | bellard | time(&ti); |
70 | b0a21b53 | bellard | tm = gmtime(&ti); |
71 | b0a21b53 | bellard | rtc_set_date(s, tm); |
72 | b0a21b53 | bellard | |
73 | b0a21b53 | bellard | val = to_bcd(s, (tm->tm_year / 100) + 19); |
74 | b0a21b53 | bellard | rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val); |
75 | b0a21b53 | bellard | rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val); |
76 | 80cabfad | bellard | |
77 | b0a21b53 | bellard | /* various important CMOS locations needed by PC/Bochs bios */
|
78 | 80cabfad | bellard | |
79 | 80cabfad | bellard | /* memory size */
|
80 | 333190eb | bellard | val = 640; /* base memory in K */ |
81 | 333190eb | bellard | rtc_set_memory(s, 0x15, val);
|
82 | 333190eb | bellard | rtc_set_memory(s, 0x16, val >> 8); |
83 | 333190eb | bellard | |
84 | 80cabfad | bellard | val = (ram_size / 1024) - 1024; |
85 | 80cabfad | bellard | if (val > 65535) |
86 | 80cabfad | bellard | val = 65535;
|
87 | b0a21b53 | bellard | rtc_set_memory(s, 0x17, val);
|
88 | b0a21b53 | bellard | rtc_set_memory(s, 0x18, val >> 8); |
89 | b0a21b53 | bellard | rtc_set_memory(s, 0x30, val);
|
90 | b0a21b53 | bellard | rtc_set_memory(s, 0x31, val >> 8); |
91 | 80cabfad | bellard | |
92 | 80cabfad | bellard | val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536); |
93 | 80cabfad | bellard | if (val > 65535) |
94 | 80cabfad | bellard | val = 65535;
|
95 | b0a21b53 | bellard | rtc_set_memory(s, 0x34, val);
|
96 | b0a21b53 | bellard | rtc_set_memory(s, 0x35, val >> 8); |
97 | 80cabfad | bellard | |
98 | 80cabfad | bellard | switch(boot_device) {
|
99 | 80cabfad | bellard | case 'a': |
100 | 80cabfad | bellard | case 'b': |
101 | b0a21b53 | bellard | rtc_set_memory(s, 0x3d, 0x01); /* floppy boot */ |
102 | 80cabfad | bellard | break;
|
103 | 80cabfad | bellard | default:
|
104 | 80cabfad | bellard | case 'c': |
105 | b0a21b53 | bellard | rtc_set_memory(s, 0x3d, 0x02); /* hard drive boot */ |
106 | 80cabfad | bellard | break;
|
107 | 80cabfad | bellard | case 'd': |
108 | b0a21b53 | bellard | rtc_set_memory(s, 0x3d, 0x03); /* CD-ROM boot */ |
109 | 80cabfad | bellard | break;
|
110 | 80cabfad | bellard | } |
111 | 80cabfad | bellard | |
112 | b41a2cd1 | bellard | /* floppy type */
|
113 | b41a2cd1 | bellard | |
114 | baca51fa | bellard | fd0 = fdctrl_get_drive_type(floppy_controller, 0);
|
115 | baca51fa | bellard | fd1 = fdctrl_get_drive_type(floppy_controller, 1);
|
116 | 80cabfad | bellard | |
117 | b0a21b53 | bellard | val = 0;
|
118 | 80cabfad | bellard | switch (fd0) {
|
119 | 80cabfad | bellard | case 0: |
120 | 80cabfad | bellard | /* 1.44 Mb 3"5 drive */
|
121 | b0a21b53 | bellard | val |= 0x40;
|
122 | 80cabfad | bellard | break;
|
123 | 80cabfad | bellard | case 1: |
124 | 80cabfad | bellard | /* 2.88 Mb 3"5 drive */
|
125 | b0a21b53 | bellard | val |= 0x60;
|
126 | 80cabfad | bellard | break;
|
127 | 80cabfad | bellard | case 2: |
128 | 80cabfad | bellard | /* 1.2 Mb 5"5 drive */
|
129 | b0a21b53 | bellard | val |= 0x20;
|
130 | 80cabfad | bellard | break;
|
131 | 80cabfad | bellard | } |
132 | 80cabfad | bellard | switch (fd1) {
|
133 | 80cabfad | bellard | case 0: |
134 | 80cabfad | bellard | /* 1.44 Mb 3"5 drive */
|
135 | b0a21b53 | bellard | val |= 0x04;
|
136 | 80cabfad | bellard | break;
|
137 | 80cabfad | bellard | case 1: |
138 | 80cabfad | bellard | /* 2.88 Mb 3"5 drive */
|
139 | b0a21b53 | bellard | val |= 0x06;
|
140 | 80cabfad | bellard | break;
|
141 | 80cabfad | bellard | case 2: |
142 | 80cabfad | bellard | /* 1.2 Mb 5"5 drive */
|
143 | b0a21b53 | bellard | val |= 0x02;
|
144 | 80cabfad | bellard | break;
|
145 | 80cabfad | bellard | } |
146 | b0a21b53 | bellard | rtc_set_memory(s, 0x10, val);
|
147 | b0a21b53 | bellard | |
148 | b0a21b53 | bellard | val = 0;
|
149 | b41a2cd1 | bellard | nb = 0;
|
150 | 80cabfad | bellard | if (fd0 < 3) |
151 | 80cabfad | bellard | nb++; |
152 | 80cabfad | bellard | if (fd1 < 3) |
153 | 80cabfad | bellard | nb++; |
154 | 80cabfad | bellard | switch (nb) {
|
155 | 80cabfad | bellard | case 0: |
156 | 80cabfad | bellard | break;
|
157 | 80cabfad | bellard | case 1: |
158 | b0a21b53 | bellard | val |= 0x01; /* 1 drive, ready for boot */ |
159 | 80cabfad | bellard | break;
|
160 | 80cabfad | bellard | case 2: |
161 | b0a21b53 | bellard | val |= 0x41; /* 2 drives, ready for boot */ |
162 | 80cabfad | bellard | break;
|
163 | 80cabfad | bellard | } |
164 | b0a21b53 | bellard | val |= 0x02; /* FPU is there */ |
165 | b0a21b53 | bellard | val |= 0x04; /* PS/2 mouse installed */ |
166 | b0a21b53 | bellard | rtc_set_memory(s, REG_EQUIPMENT_BYTE, val); |
167 | b0a21b53 | bellard | |
168 | 80cabfad | bellard | } |
169 | 80cabfad | bellard | |
170 | b41a2cd1 | bellard | static void speaker_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
171 | 80cabfad | bellard | { |
172 | 80cabfad | bellard | speaker_data_on = (val >> 1) & 1; |
173 | ec844b96 | bellard | pit_set_gate(pit, 2, val & 1); |
174 | 80cabfad | bellard | } |
175 | 80cabfad | bellard | |
176 | b41a2cd1 | bellard | static uint32_t speaker_ioport_read(void *opaque, uint32_t addr) |
177 | 80cabfad | bellard | { |
178 | 80cabfad | bellard | int out;
|
179 | ec844b96 | bellard | out = pit_get_out(pit, 2, qemu_get_clock(vm_clock));
|
180 | 80cabfad | bellard | dummy_refresh_clock ^= 1;
|
181 | ec844b96 | bellard | return (speaker_data_on << 1) | pit_get_gate(pit, 2) | (out << 5) | |
182 | 80cabfad | bellard | (dummy_refresh_clock << 4);
|
183 | 80cabfad | bellard | } |
184 | 80cabfad | bellard | |
185 | e1a23744 | bellard | static void ioport92_write(void *opaque, uint32_t addr, uint32_t val) |
186 | e1a23744 | bellard | { |
187 | e1a23744 | bellard | cpu_x86_set_a20(cpu_single_env, (val >> 1) & 1); |
188 | e1a23744 | bellard | /* XXX: bit 0 is fast reset */
|
189 | e1a23744 | bellard | } |
190 | e1a23744 | bellard | |
191 | e1a23744 | bellard | static uint32_t ioport92_read(void *opaque, uint32_t addr) |
192 | e1a23744 | bellard | { |
193 | e1a23744 | bellard | return ((cpu_single_env->a20_mask >> 20) & 1) << 1; |
194 | e1a23744 | bellard | } |
195 | e1a23744 | bellard | |
196 | 80cabfad | bellard | /***********************************************************/
|
197 | 80cabfad | bellard | /* Bochs BIOS debug ports */
|
198 | 80cabfad | bellard | |
199 | b41a2cd1 | bellard | void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val) |
200 | 80cabfad | bellard | { |
201 | 80cabfad | bellard | switch(addr) {
|
202 | 80cabfad | bellard | /* Bochs BIOS messages */
|
203 | 80cabfad | bellard | case 0x400: |
204 | 80cabfad | bellard | case 0x401: |
205 | 80cabfad | bellard | fprintf(stderr, "BIOS panic at rombios.c, line %d\n", val);
|
206 | 80cabfad | bellard | exit(1);
|
207 | 80cabfad | bellard | case 0x402: |
208 | 80cabfad | bellard | case 0x403: |
209 | 80cabfad | bellard | #ifdef DEBUG_BIOS
|
210 | 80cabfad | bellard | fprintf(stderr, "%c", val);
|
211 | 80cabfad | bellard | #endif
|
212 | 80cabfad | bellard | break;
|
213 | 80cabfad | bellard | |
214 | 80cabfad | bellard | /* LGPL'ed VGA BIOS messages */
|
215 | 80cabfad | bellard | case 0x501: |
216 | 80cabfad | bellard | case 0x502: |
217 | 80cabfad | bellard | fprintf(stderr, "VGA BIOS panic, line %d\n", val);
|
218 | 80cabfad | bellard | exit(1);
|
219 | 80cabfad | bellard | case 0x500: |
220 | 80cabfad | bellard | case 0x503: |
221 | 80cabfad | bellard | #ifdef DEBUG_BIOS
|
222 | 80cabfad | bellard | fprintf(stderr, "%c", val);
|
223 | 80cabfad | bellard | #endif
|
224 | 80cabfad | bellard | break;
|
225 | 80cabfad | bellard | } |
226 | 80cabfad | bellard | } |
227 | 80cabfad | bellard | |
228 | 80cabfad | bellard | void bochs_bios_init(void) |
229 | 80cabfad | bellard | { |
230 | b41a2cd1 | bellard | register_ioport_write(0x400, 1, 2, bochs_bios_write, NULL); |
231 | b41a2cd1 | bellard | register_ioport_write(0x401, 1, 2, bochs_bios_write, NULL); |
232 | b41a2cd1 | bellard | register_ioport_write(0x402, 1, 1, bochs_bios_write, NULL); |
233 | b41a2cd1 | bellard | register_ioport_write(0x403, 1, 1, bochs_bios_write, NULL); |
234 | b41a2cd1 | bellard | |
235 | b41a2cd1 | bellard | register_ioport_write(0x501, 1, 2, bochs_bios_write, NULL); |
236 | b41a2cd1 | bellard | register_ioport_write(0x502, 1, 2, bochs_bios_write, NULL); |
237 | b41a2cd1 | bellard | register_ioport_write(0x500, 1, 1, bochs_bios_write, NULL); |
238 | b41a2cd1 | bellard | register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL); |
239 | 80cabfad | bellard | } |
240 | 80cabfad | bellard | |
241 | 80cabfad | bellard | |
242 | 80cabfad | bellard | int load_kernel(const char *filename, uint8_t *addr, |
243 | 80cabfad | bellard | uint8_t *real_addr) |
244 | 80cabfad | bellard | { |
245 | 80cabfad | bellard | int fd, size;
|
246 | 80cabfad | bellard | int setup_sects;
|
247 | 80cabfad | bellard | |
248 | 80cabfad | bellard | fd = open(filename, O_RDONLY); |
249 | 80cabfad | bellard | if (fd < 0) |
250 | 80cabfad | bellard | return -1; |
251 | 80cabfad | bellard | |
252 | 80cabfad | bellard | /* load 16 bit code */
|
253 | 80cabfad | bellard | if (read(fd, real_addr, 512) != 512) |
254 | 80cabfad | bellard | goto fail;
|
255 | 80cabfad | bellard | setup_sects = real_addr[0x1F1];
|
256 | 80cabfad | bellard | if (!setup_sects)
|
257 | 80cabfad | bellard | setup_sects = 4;
|
258 | 80cabfad | bellard | if (read(fd, real_addr + 512, setup_sects * 512) != |
259 | 80cabfad | bellard | setup_sects * 512)
|
260 | 80cabfad | bellard | goto fail;
|
261 | 80cabfad | bellard | |
262 | 80cabfad | bellard | /* load 32 bit code */
|
263 | 80cabfad | bellard | size = read(fd, addr, 16 * 1024 * 1024); |
264 | 80cabfad | bellard | if (size < 0) |
265 | 80cabfad | bellard | goto fail;
|
266 | 80cabfad | bellard | close(fd); |
267 | 80cabfad | bellard | return size;
|
268 | 80cabfad | bellard | fail:
|
269 | 80cabfad | bellard | close(fd); |
270 | 80cabfad | bellard | return -1; |
271 | 80cabfad | bellard | } |
272 | 80cabfad | bellard | |
273 | b41a2cd1 | bellard | static const int ide_iobase[2] = { 0x1f0, 0x170 }; |
274 | b41a2cd1 | bellard | static const int ide_iobase2[2] = { 0x3f6, 0x376 }; |
275 | b41a2cd1 | bellard | static const int ide_irq[2] = { 14, 15 }; |
276 | b41a2cd1 | bellard | |
277 | b41a2cd1 | bellard | #define NE2000_NB_MAX 6 |
278 | b41a2cd1 | bellard | |
279 | b41a2cd1 | bellard | static uint32_t ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 }; |
280 | b41a2cd1 | bellard | static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 }; |
281 | b41a2cd1 | bellard | |
282 | 80cabfad | bellard | /* PC hardware initialisation */
|
283 | 80cabfad | bellard | void pc_init(int ram_size, int vga_ram_size, int boot_device, |
284 | 80cabfad | bellard | DisplayState *ds, const char **fd_filename, int snapshot, |
285 | 80cabfad | bellard | const char *kernel_filename, const char *kernel_cmdline, |
286 | 80cabfad | bellard | const char *initrd_filename) |
287 | 80cabfad | bellard | { |
288 | 80cabfad | bellard | char buf[1024]; |
289 | b41a2cd1 | bellard | int ret, linux_boot, initrd_size, i, nb_nics1, fd;
|
290 | 80cabfad | bellard | |
291 | 80cabfad | bellard | linux_boot = (kernel_filename != NULL);
|
292 | 80cabfad | bellard | |
293 | 80cabfad | bellard | /* allocate RAM */
|
294 | 80cabfad | bellard | cpu_register_physical_memory(0, ram_size, 0); |
295 | 80cabfad | bellard | |
296 | 80cabfad | bellard | /* BIOS load */
|
297 | 80cabfad | bellard | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); |
298 | 80cabfad | bellard | ret = load_image(buf, phys_ram_base + 0x000f0000);
|
299 | 80cabfad | bellard | if (ret != 0x10000) { |
300 | 80cabfad | bellard | fprintf(stderr, "qemu: could not load PC bios '%s'\n", buf);
|
301 | 80cabfad | bellard | exit(1);
|
302 | 80cabfad | bellard | } |
303 | 80cabfad | bellard | |
304 | 80cabfad | bellard | /* VGA BIOS load */
|
305 | 80cabfad | bellard | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME); |
306 | 80cabfad | bellard | ret = load_image(buf, phys_ram_base + 0x000c0000);
|
307 | 80cabfad | bellard | |
308 | 80cabfad | bellard | /* setup basic memory access */
|
309 | 80cabfad | bellard | cpu_register_physical_memory(0xc0000, 0x10000, 0xc0000 | IO_MEM_ROM); |
310 | bb058620 | bellard | cpu_register_physical_memory(0xd0000, 0x20000, IO_MEM_UNASSIGNED); |
311 | 80cabfad | bellard | cpu_register_physical_memory(0xf0000, 0x10000, 0xf0000 | IO_MEM_ROM); |
312 | 80cabfad | bellard | |
313 | 80cabfad | bellard | bochs_bios_init(); |
314 | 80cabfad | bellard | |
315 | 80cabfad | bellard | if (linux_boot) {
|
316 | 80cabfad | bellard | uint8_t bootsect[512];
|
317 | 41b9be47 | bellard | uint8_t old_bootsect[512];
|
318 | 80cabfad | bellard | |
319 | 80cabfad | bellard | if (bs_table[0] == NULL) { |
320 | 80cabfad | bellard | fprintf(stderr, "A disk image must be given for 'hda' when booting a Linux kernel\n");
|
321 | 80cabfad | bellard | exit(1);
|
322 | 80cabfad | bellard | } |
323 | 80cabfad | bellard | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, LINUX_BOOT_FILENAME); |
324 | 80cabfad | bellard | ret = load_image(buf, bootsect); |
325 | 80cabfad | bellard | if (ret != sizeof(bootsect)) { |
326 | 80cabfad | bellard | fprintf(stderr, "qemu: could not load linux boot sector '%s'\n",
|
327 | 80cabfad | bellard | buf); |
328 | 80cabfad | bellard | exit(1);
|
329 | 80cabfad | bellard | } |
330 | 80cabfad | bellard | |
331 | 41b9be47 | bellard | if (bdrv_read(bs_table[0], 0, old_bootsect, 1) >= 0) { |
332 | 41b9be47 | bellard | /* copy the MSDOS partition table */
|
333 | 41b9be47 | bellard | memcpy(bootsect + 0x1be, old_bootsect + 0x1be, 0x40); |
334 | 41b9be47 | bellard | } |
335 | 41b9be47 | bellard | |
336 | 80cabfad | bellard | bdrv_set_boot_sector(bs_table[0], bootsect, sizeof(bootsect)); |
337 | 80cabfad | bellard | |
338 | 80cabfad | bellard | /* now we can load the kernel */
|
339 | 80cabfad | bellard | ret = load_kernel(kernel_filename, |
340 | 80cabfad | bellard | phys_ram_base + KERNEL_LOAD_ADDR, |
341 | 80cabfad | bellard | phys_ram_base + KERNEL_PARAMS_ADDR); |
342 | 80cabfad | bellard | if (ret < 0) { |
343 | 80cabfad | bellard | fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
344 | 80cabfad | bellard | kernel_filename); |
345 | 80cabfad | bellard | exit(1);
|
346 | 80cabfad | bellard | } |
347 | 80cabfad | bellard | |
348 | 80cabfad | bellard | /* load initrd */
|
349 | 80cabfad | bellard | initrd_size = 0;
|
350 | 80cabfad | bellard | if (initrd_filename) {
|
351 | 80cabfad | bellard | initrd_size = load_image(initrd_filename, phys_ram_base + INITRD_LOAD_ADDR); |
352 | 80cabfad | bellard | if (initrd_size < 0) { |
353 | 80cabfad | bellard | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
354 | 80cabfad | bellard | initrd_filename); |
355 | 80cabfad | bellard | exit(1);
|
356 | 80cabfad | bellard | } |
357 | 80cabfad | bellard | } |
358 | 80cabfad | bellard | if (initrd_size > 0) { |
359 | 80cabfad | bellard | stl_raw(phys_ram_base + KERNEL_PARAMS_ADDR + 0x218, INITRD_LOAD_ADDR);
|
360 | 80cabfad | bellard | stl_raw(phys_ram_base + KERNEL_PARAMS_ADDR + 0x21c, initrd_size);
|
361 | 80cabfad | bellard | } |
362 | 80cabfad | bellard | pstrcpy(phys_ram_base + KERNEL_CMDLINE_ADDR, 4096,
|
363 | 80cabfad | bellard | kernel_cmdline); |
364 | 80cabfad | bellard | stw_raw(phys_ram_base + KERNEL_PARAMS_ADDR + 0x20, 0xA33F); |
365 | 80cabfad | bellard | stw_raw(phys_ram_base + KERNEL_PARAMS_ADDR + 0x22,
|
366 | 80cabfad | bellard | KERNEL_CMDLINE_ADDR - KERNEL_PARAMS_ADDR); |
367 | 80cabfad | bellard | /* loader type */
|
368 | 80cabfad | bellard | stw_raw(phys_ram_base + KERNEL_PARAMS_ADDR + 0x210, 0x01); |
369 | 80cabfad | bellard | } |
370 | 80cabfad | bellard | |
371 | 80cabfad | bellard | /* init basic PC hardware */
|
372 | b41a2cd1 | bellard | register_ioport_write(0x80, 1, 1, ioport80_write, NULL); |
373 | 80cabfad | bellard | |
374 | 80cabfad | bellard | vga_initialize(ds, phys_ram_base + ram_size, ram_size, |
375 | 80cabfad | bellard | vga_ram_size); |
376 | 80cabfad | bellard | |
377 | b0a21b53 | bellard | rtc_state = rtc_init(0x70, 8); |
378 | b41a2cd1 | bellard | register_ioport_read(0x61, 1, 1, speaker_ioport_read, NULL); |
379 | b41a2cd1 | bellard | register_ioport_write(0x61, 1, 1, speaker_ioport_write, NULL); |
380 | 80cabfad | bellard | |
381 | e1a23744 | bellard | register_ioport_read(0x92, 1, 1, ioport92_read, NULL); |
382 | e1a23744 | bellard | register_ioport_write(0x92, 1, 1, ioport92_write, NULL); |
383 | e1a23744 | bellard | |
384 | 80cabfad | bellard | pic_init(); |
385 | ec844b96 | bellard | pit = pit_init(0x40, 0); |
386 | b41a2cd1 | bellard | |
387 | b41a2cd1 | bellard | fd = serial_open_device(); |
388 | b41a2cd1 | bellard | serial_init(0x3f8, 4, fd); |
389 | b41a2cd1 | bellard | |
390 | b41a2cd1 | bellard | nb_nics1 = nb_nics; |
391 | b41a2cd1 | bellard | if (nb_nics1 > NE2000_NB_MAX)
|
392 | b41a2cd1 | bellard | nb_nics1 = NE2000_NB_MAX; |
393 | b41a2cd1 | bellard | for(i = 0; i < nb_nics1; i++) { |
394 | b41a2cd1 | bellard | ne2000_init(ne2000_io[i], ne2000_irq[i], &nd_table[i]); |
395 | b41a2cd1 | bellard | } |
396 | b41a2cd1 | bellard | |
397 | b41a2cd1 | bellard | for(i = 0; i < 2; i++) { |
398 | b41a2cd1 | bellard | ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i], |
399 | b41a2cd1 | bellard | bs_table[2 * i], bs_table[2 * i + 1]); |
400 | b41a2cd1 | bellard | } |
401 | 80cabfad | bellard | kbd_init(); |
402 | 80cabfad | bellard | DMA_init(); |
403 | 67b915a5 | bellard | |
404 | 67b915a5 | bellard | #ifndef _WIN32
|
405 | aaaa7df6 | bellard | if (audio_enabled) {
|
406 | aaaa7df6 | bellard | /* no audio supported yet for win32 */
|
407 | aaaa7df6 | bellard | AUD_init(); |
408 | aaaa7df6 | bellard | SB16_init(); |
409 | aaaa7df6 | bellard | } |
410 | 67b915a5 | bellard | #endif
|
411 | 80cabfad | bellard | |
412 | baca51fa | bellard | floppy_controller = fdctrl_init(6, 2, 0, 0x3f0, fd_table); |
413 | b41a2cd1 | bellard | |
414 | b41a2cd1 | bellard | cmos_init(ram_size, boot_device); |
415 | 80cabfad | bellard | } |