Statistics
| Branch: | Revision:

root / hw / pc.c @ c9a43af9

History | View | Annotate | Download (33.1 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 aa28b9bf Blue Swirl
#include "apic.h"
27 87ecb68b pbrook
#include "fdc.h"
28 87ecb68b pbrook
#include "pci.h"
29 18e08a55 Michael S. Tsirkin
#include "vmware_vga.h"
30 18e08a55 Michael S. Tsirkin
#include "usb-uhci.h"
31 18e08a55 Michael S. Tsirkin
#include "usb-ohci.h"
32 18e08a55 Michael S. Tsirkin
#include "prep_pci.h"
33 18e08a55 Michael S. Tsirkin
#include "apb_pci.h"
34 87ecb68b pbrook
#include "block.h"
35 87ecb68b pbrook
#include "sysemu.h"
36 87ecb68b pbrook
#include "audio/audio.h"
37 87ecb68b pbrook
#include "net.h"
38 87ecb68b pbrook
#include "smbus.h"
39 87ecb68b pbrook
#include "boards.h"
40 376253ec aliguori
#include "monitor.h"
41 3cce6243 blueswir1
#include "fw_cfg.h"
42 16b29ae1 aliguori
#include "hpet_emul.h"
43 9dd986cc Richard W.M. Jones
#include "watchdog.h"
44 b6f6e3d3 aliguori
#include "smbios.h"
45 ec82026c Gerd Hoffmann
#include "ide.h"
46 ca20cf32 Blue Swirl
#include "loader.h"
47 ca20cf32 Blue Swirl
#include "elf.h"
48 52001445 Adam Lackorzynski
#include "multiboot.h"
49 80cabfad bellard
50 b41a2cd1 bellard
/* output Bochs bios info messages */
51 b41a2cd1 bellard
//#define DEBUG_BIOS
52 b41a2cd1 bellard
53 80cabfad bellard
#define BIOS_FILENAME "bios.bin"
54 80cabfad bellard
55 7fb4fdcf balrog
#define PC_MAX_BIOS_SIZE (4 * 1024 * 1024)
56 7fb4fdcf balrog
57 a80274c3 pbrook
/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables.  */
58 a80274c3 pbrook
#define ACPI_DATA_SIZE       0x10000
59 3cce6243 blueswir1
#define BIOS_CFG_IOPORT 0x510
60 8a92ea2f aliguori
#define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
61 b6f6e3d3 aliguori
#define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
62 6b35e7bf Jes Sorensen
#define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
63 4c5b10b7 Jes Sorensen
#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
64 80cabfad bellard
65 e4bcb14c ths
#define MAX_IDE_BUS 2
66 e4bcb14c ths
67 5c02c033 Blue Swirl
static FDCtrl *floppy_controller;
68 b0a21b53 bellard
static RTCState *rtc_state;
69 ec844b96 bellard
static PITState *pit;
70 0a3bacf3 Juan Quintela
static PCII440FXState *i440fx_state;
71 80cabfad bellard
72 4c5b10b7 Jes Sorensen
#define E820_NR_ENTRIES                16
73 4c5b10b7 Jes Sorensen
74 4c5b10b7 Jes Sorensen
struct e820_entry {
75 4c5b10b7 Jes Sorensen
    uint64_t address;
76 4c5b10b7 Jes Sorensen
    uint64_t length;
77 4c5b10b7 Jes Sorensen
    uint32_t type;
78 4c5b10b7 Jes Sorensen
};
79 4c5b10b7 Jes Sorensen
80 4c5b10b7 Jes Sorensen
struct e820_table {
81 4c5b10b7 Jes Sorensen
    uint32_t count;
82 4c5b10b7 Jes Sorensen
    struct e820_entry entry[E820_NR_ENTRIES];
83 4c5b10b7 Jes Sorensen
};
84 4c5b10b7 Jes Sorensen
85 4c5b10b7 Jes Sorensen
static struct e820_table e820_table;
86 4c5b10b7 Jes Sorensen
87 1452411b Avi Kivity
typedef struct isa_irq_state {
88 1452411b Avi Kivity
    qemu_irq *i8259;
89 1632dc6a Avi Kivity
    qemu_irq *ioapic;
90 1452411b Avi Kivity
} IsaIrqState;
91 1452411b Avi Kivity
92 1452411b Avi Kivity
static void isa_irq_handler(void *opaque, int n, int level)
93 1452411b Avi Kivity
{
94 1452411b Avi Kivity
    IsaIrqState *isa = (IsaIrqState *)opaque;
95 1452411b Avi Kivity
96 1632dc6a Avi Kivity
    if (n < 16) {
97 1632dc6a Avi Kivity
        qemu_set_irq(isa->i8259[n], level);
98 1632dc6a Avi Kivity
    }
99 2c8d9340 Gerd Hoffmann
    if (isa->ioapic)
100 2c8d9340 Gerd Hoffmann
        qemu_set_irq(isa->ioapic[n], level);
101 1632dc6a Avi Kivity
};
102 1452411b Avi Kivity
103 b41a2cd1 bellard
static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
104 80cabfad bellard
{
105 80cabfad bellard
}
106 80cabfad bellard
107 f929aad6 bellard
/* MSDOS compatibility mode FPU exception support */
108 d537cf6c pbrook
static qemu_irq ferr_irq;
109 f929aad6 bellard
/* XXX: add IGNNE support */
110 f929aad6 bellard
void cpu_set_ferr(CPUX86State *s)
111 f929aad6 bellard
{
112 d537cf6c pbrook
    qemu_irq_raise(ferr_irq);
113 f929aad6 bellard
}
114 f929aad6 bellard
115 f929aad6 bellard
static void ioportF0_write(void *opaque, uint32_t addr, uint32_t data)
116 f929aad6 bellard
{
117 d537cf6c pbrook
    qemu_irq_lower(ferr_irq);
118 f929aad6 bellard
}
119 f929aad6 bellard
120 28ab0e2e bellard
/* TSC handling */
121 28ab0e2e bellard
uint64_t cpu_get_tsc(CPUX86State *env)
122 28ab0e2e bellard
{
123 4a1418e0 Anthony Liguori
    return cpu_get_ticks();
124 28ab0e2e bellard
}
125 28ab0e2e bellard
126 a5954d5c bellard
/* SMM support */
127 a5954d5c bellard
void cpu_smm_update(CPUState *env)
128 a5954d5c bellard
{
129 a5954d5c bellard
    if (i440fx_state && env == first_cpu)
130 a5954d5c bellard
        i440fx_set_smm(i440fx_state, (env->hflags >> HF_SMM_SHIFT) & 1);
131 a5954d5c bellard
}
132 a5954d5c bellard
133 a5954d5c bellard
134 3de388f6 bellard
/* IRQ handling */
135 3de388f6 bellard
int cpu_get_pic_interrupt(CPUState *env)
136 3de388f6 bellard
{
137 3de388f6 bellard
    int intno;
138 3de388f6 bellard
139 3de388f6 bellard
    intno = apic_get_interrupt(env);
140 3de388f6 bellard
    if (intno >= 0) {
141 3de388f6 bellard
        /* set irq request if a PIC irq is still pending */
142 3de388f6 bellard
        /* XXX: improve that */
143 5fafdf24 ths
        pic_update_irq(isa_pic);
144 3de388f6 bellard
        return intno;
145 3de388f6 bellard
    }
146 3de388f6 bellard
    /* read the irq from the PIC */
147 0e21e12b ths
    if (!apic_accept_pic_intr(env))
148 0e21e12b ths
        return -1;
149 0e21e12b ths
150 3de388f6 bellard
    intno = pic_read_irq(isa_pic);
151 3de388f6 bellard
    return intno;
152 3de388f6 bellard
}
153 3de388f6 bellard
154 d537cf6c pbrook
static void pic_irq_request(void *opaque, int irq, int level)
155 3de388f6 bellard
{
156 a5b38b51 aurel32
    CPUState *env = first_cpu;
157 a5b38b51 aurel32
158 d5529471 aurel32
    if (env->apic_state) {
159 d5529471 aurel32
        while (env) {
160 d5529471 aurel32
            if (apic_accept_pic_intr(env))
161 1a7de94a aurel32
                apic_deliver_pic_intr(env, level);
162 d5529471 aurel32
            env = env->next_cpu;
163 d5529471 aurel32
        }
164 d5529471 aurel32
    } else {
165 b614106a aurel32
        if (level)
166 b614106a aurel32
            cpu_interrupt(env, CPU_INTERRUPT_HARD);
167 b614106a aurel32
        else
168 b614106a aurel32
            cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
169 a5b38b51 aurel32
    }
170 3de388f6 bellard
}
171 3de388f6 bellard
172 b0a21b53 bellard
/* PC cmos mappings */
173 b0a21b53 bellard
174 80cabfad bellard
#define REG_EQUIPMENT_BYTE          0x14
175 80cabfad bellard
176 777428f2 bellard
static int cmos_get_fd_drive_type(int fd0)
177 777428f2 bellard
{
178 777428f2 bellard
    int val;
179 777428f2 bellard
180 777428f2 bellard
    switch (fd0) {
181 777428f2 bellard
    case 0:
182 777428f2 bellard
        /* 1.44 Mb 3"5 drive */
183 777428f2 bellard
        val = 4;
184 777428f2 bellard
        break;
185 777428f2 bellard
    case 1:
186 777428f2 bellard
        /* 2.88 Mb 3"5 drive */
187 777428f2 bellard
        val = 5;
188 777428f2 bellard
        break;
189 777428f2 bellard
    case 2:
190 777428f2 bellard
        /* 1.2 Mb 5"5 drive */
191 777428f2 bellard
        val = 2;
192 777428f2 bellard
        break;
193 777428f2 bellard
    default:
194 777428f2 bellard
        val = 0;
195 777428f2 bellard
        break;
196 777428f2 bellard
    }
197 777428f2 bellard
    return val;
198 777428f2 bellard
}
199 777428f2 bellard
200 5fafdf24 ths
static void cmos_init_hd(int type_ofs, int info_ofs, BlockDriverState *hd)
201 ba6c2377 bellard
{
202 ba6c2377 bellard
    RTCState *s = rtc_state;
203 ba6c2377 bellard
    int cylinders, heads, sectors;
204 ba6c2377 bellard
    bdrv_get_geometry_hint(hd, &cylinders, &heads, &sectors);
205 ba6c2377 bellard
    rtc_set_memory(s, type_ofs, 47);
206 ba6c2377 bellard
    rtc_set_memory(s, info_ofs, cylinders);
207 ba6c2377 bellard
    rtc_set_memory(s, info_ofs + 1, cylinders >> 8);
208 ba6c2377 bellard
    rtc_set_memory(s, info_ofs + 2, heads);
209 ba6c2377 bellard
    rtc_set_memory(s, info_ofs + 3, 0xff);
210 ba6c2377 bellard
    rtc_set_memory(s, info_ofs + 4, 0xff);
211 ba6c2377 bellard
    rtc_set_memory(s, info_ofs + 5, 0xc0 | ((heads > 8) << 3));
212 ba6c2377 bellard
    rtc_set_memory(s, info_ofs + 6, cylinders);
213 ba6c2377 bellard
    rtc_set_memory(s, info_ofs + 7, cylinders >> 8);
214 ba6c2377 bellard
    rtc_set_memory(s, info_ofs + 8, sectors);
215 ba6c2377 bellard
}
216 ba6c2377 bellard
217 6ac0e82d balrog
/* convert boot_device letter to something recognizable by the bios */
218 6ac0e82d balrog
static int boot_device2nibble(char boot_device)
219 6ac0e82d balrog
{
220 6ac0e82d balrog
    switch(boot_device) {
221 6ac0e82d balrog
    case 'a':
222 6ac0e82d balrog
    case 'b':
223 6ac0e82d balrog
        return 0x01; /* floppy boot */
224 6ac0e82d balrog
    case 'c':
225 6ac0e82d balrog
        return 0x02; /* hard drive boot */
226 6ac0e82d balrog
    case 'd':
227 6ac0e82d balrog
        return 0x03; /* CD-ROM boot */
228 6ac0e82d balrog
    case 'n':
229 6ac0e82d balrog
        return 0x04; /* Network boot */
230 6ac0e82d balrog
    }
231 6ac0e82d balrog
    return 0;
232 6ac0e82d balrog
}
233 6ac0e82d balrog
234 d9346e81 Markus Armbruster
static int set_boot_dev(RTCState *s, const char *boot_device, int fd_bootchk)
235 0ecdffbb aurel32
{
236 0ecdffbb aurel32
#define PC_MAX_BOOT_DEVICES 3
237 0ecdffbb aurel32
    int nbds, bds[3] = { 0, };
238 0ecdffbb aurel32
    int i;
239 0ecdffbb aurel32
240 0ecdffbb aurel32
    nbds = strlen(boot_device);
241 0ecdffbb aurel32
    if (nbds > PC_MAX_BOOT_DEVICES) {
242 1ecda02b Markus Armbruster
        error_report("Too many boot devices for PC");
243 0ecdffbb aurel32
        return(1);
244 0ecdffbb aurel32
    }
245 0ecdffbb aurel32
    for (i = 0; i < nbds; i++) {
246 0ecdffbb aurel32
        bds[i] = boot_device2nibble(boot_device[i]);
247 0ecdffbb aurel32
        if (bds[i] == 0) {
248 1ecda02b Markus Armbruster
            error_report("Invalid boot device for PC: '%c'",
249 1ecda02b Markus Armbruster
                         boot_device[i]);
250 0ecdffbb aurel32
            return(1);
251 0ecdffbb aurel32
        }
252 0ecdffbb aurel32
    }
253 0ecdffbb aurel32
    rtc_set_memory(s, 0x3d, (bds[1] << 4) | bds[0]);
254 d9346e81 Markus Armbruster
    rtc_set_memory(s, 0x38, (bds[2] << 4) | (fd_bootchk ? 0x0 : 0x1));
255 0ecdffbb aurel32
    return(0);
256 0ecdffbb aurel32
}
257 0ecdffbb aurel32
258 d9346e81 Markus Armbruster
static int pc_boot_set(void *opaque, const char *boot_device)
259 d9346e81 Markus Armbruster
{
260 d9346e81 Markus Armbruster
    return set_boot_dev(opaque, boot_device, 0);
261 d9346e81 Markus Armbruster
}
262 d9346e81 Markus Armbruster
263 ba6c2377 bellard
/* hd_table must contain 4 block drivers */
264 c227f099 Anthony Liguori
static void cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
265 f455e98c Gerd Hoffmann
                      const char *boot_device, DriveInfo **hd_table)
266 80cabfad bellard
{
267 b0a21b53 bellard
    RTCState *s = rtc_state;
268 80cabfad bellard
    int val;
269 b41a2cd1 bellard
    int fd0, fd1, nb;
270 ba6c2377 bellard
    int i;
271 b0a21b53 bellard
272 b0a21b53 bellard
    /* various important CMOS locations needed by PC/Bochs bios */
273 80cabfad bellard
274 80cabfad bellard
    /* memory size */
275 333190eb bellard
    val = 640; /* base memory in K */
276 333190eb bellard
    rtc_set_memory(s, 0x15, val);
277 333190eb bellard
    rtc_set_memory(s, 0x16, val >> 8);
278 333190eb bellard
279 80cabfad bellard
    val = (ram_size / 1024) - 1024;
280 80cabfad bellard
    if (val > 65535)
281 80cabfad bellard
        val = 65535;
282 b0a21b53 bellard
    rtc_set_memory(s, 0x17, val);
283 b0a21b53 bellard
    rtc_set_memory(s, 0x18, val >> 8);
284 b0a21b53 bellard
    rtc_set_memory(s, 0x30, val);
285 b0a21b53 bellard
    rtc_set_memory(s, 0x31, val >> 8);
286 80cabfad bellard
287 00f82b8a aurel32
    if (above_4g_mem_size) {
288 00f82b8a aurel32
        rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16);
289 00f82b8a aurel32
        rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24);
290 00f82b8a aurel32
        rtc_set_memory(s, 0x5d, (uint64_t)above_4g_mem_size >> 32);
291 00f82b8a aurel32
    }
292 00f82b8a aurel32
293 9da98861 bellard
    if (ram_size > (16 * 1024 * 1024))
294 9da98861 bellard
        val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536);
295 9da98861 bellard
    else
296 9da98861 bellard
        val = 0;
297 80cabfad bellard
    if (val > 65535)
298 80cabfad bellard
        val = 65535;
299 b0a21b53 bellard
    rtc_set_memory(s, 0x34, val);
300 b0a21b53 bellard
    rtc_set_memory(s, 0x35, val >> 8);
301 3b46e624 ths
302 298e01b6 aurel32
    /* set the number of CPU */
303 298e01b6 aurel32
    rtc_set_memory(s, 0x5f, smp_cpus - 1);
304 298e01b6 aurel32
305 6ac0e82d balrog
    /* set boot devices, and disable floppy signature check if requested */
306 d9346e81 Markus Armbruster
    if (set_boot_dev(s, boot_device, fd_bootchk)) {
307 28c5af54 j_mayer
        exit(1);
308 28c5af54 j_mayer
    }
309 80cabfad bellard
310 b41a2cd1 bellard
    /* floppy type */
311 b41a2cd1 bellard
312 baca51fa bellard
    fd0 = fdctrl_get_drive_type(floppy_controller, 0);
313 baca51fa bellard
    fd1 = fdctrl_get_drive_type(floppy_controller, 1);
314 80cabfad bellard
315 777428f2 bellard
    val = (cmos_get_fd_drive_type(fd0) << 4) | cmos_get_fd_drive_type(fd1);
316 b0a21b53 bellard
    rtc_set_memory(s, 0x10, val);
317 3b46e624 ths
318 b0a21b53 bellard
    val = 0;
319 b41a2cd1 bellard
    nb = 0;
320 80cabfad bellard
    if (fd0 < 3)
321 80cabfad bellard
        nb++;
322 80cabfad bellard
    if (fd1 < 3)
323 80cabfad bellard
        nb++;
324 80cabfad bellard
    switch (nb) {
325 80cabfad bellard
    case 0:
326 80cabfad bellard
        break;
327 80cabfad bellard
    case 1:
328 b0a21b53 bellard
        val |= 0x01; /* 1 drive, ready for boot */
329 80cabfad bellard
        break;
330 80cabfad bellard
    case 2:
331 b0a21b53 bellard
        val |= 0x41; /* 2 drives, ready for boot */
332 80cabfad bellard
        break;
333 80cabfad bellard
    }
334 b0a21b53 bellard
    val |= 0x02; /* FPU is there */
335 b0a21b53 bellard
    val |= 0x04; /* PS/2 mouse installed */
336 b0a21b53 bellard
    rtc_set_memory(s, REG_EQUIPMENT_BYTE, val);
337 b0a21b53 bellard
338 ba6c2377 bellard
    /* hard drives */
339 ba6c2377 bellard
340 ba6c2377 bellard
    rtc_set_memory(s, 0x12, (hd_table[0] ? 0xf0 : 0) | (hd_table[1] ? 0x0f : 0));
341 ba6c2377 bellard
    if (hd_table[0])
342 f455e98c Gerd Hoffmann
        cmos_init_hd(0x19, 0x1b, hd_table[0]->bdrv);
343 5fafdf24 ths
    if (hd_table[1])
344 f455e98c Gerd Hoffmann
        cmos_init_hd(0x1a, 0x24, hd_table[1]->bdrv);
345 ba6c2377 bellard
346 ba6c2377 bellard
    val = 0;
347 40b6ecc6 bellard
    for (i = 0; i < 4; i++) {
348 ba6c2377 bellard
        if (hd_table[i]) {
349 46d4767d bellard
            int cylinders, heads, sectors, translation;
350 46d4767d bellard
            /* NOTE: bdrv_get_geometry_hint() returns the physical
351 46d4767d bellard
                geometry.  It is always such that: 1 <= sects <= 63, 1
352 46d4767d bellard
                <= heads <= 16, 1 <= cylinders <= 16383. The BIOS
353 46d4767d bellard
                geometry can be different if a translation is done. */
354 f455e98c Gerd Hoffmann
            translation = bdrv_get_translation_hint(hd_table[i]->bdrv);
355 46d4767d bellard
            if (translation == BIOS_ATA_TRANSLATION_AUTO) {
356 f455e98c Gerd Hoffmann
                bdrv_get_geometry_hint(hd_table[i]->bdrv, &cylinders, &heads, &sectors);
357 46d4767d bellard
                if (cylinders <= 1024 && heads <= 16 && sectors <= 63) {
358 46d4767d bellard
                    /* No translation. */
359 46d4767d bellard
                    translation = 0;
360 46d4767d bellard
                } else {
361 46d4767d bellard
                    /* LBA translation. */
362 46d4767d bellard
                    translation = 1;
363 46d4767d bellard
                }
364 40b6ecc6 bellard
            } else {
365 46d4767d bellard
                translation--;
366 ba6c2377 bellard
            }
367 ba6c2377 bellard
            val |= translation << (i * 2);
368 ba6c2377 bellard
        }
369 40b6ecc6 bellard
    }
370 ba6c2377 bellard
    rtc_set_memory(s, 0x39, val);
371 80cabfad bellard
}
372 80cabfad bellard
373 59b8ad81 bellard
void ioport_set_a20(int enable)
374 59b8ad81 bellard
{
375 59b8ad81 bellard
    /* XXX: send to all CPUs ? */
376 59b8ad81 bellard
    cpu_x86_set_a20(first_cpu, enable);
377 59b8ad81 bellard
}
378 59b8ad81 bellard
379 59b8ad81 bellard
int ioport_get_a20(void)
380 59b8ad81 bellard
{
381 59b8ad81 bellard
    return ((first_cpu->a20_mask >> 20) & 1);
382 59b8ad81 bellard
}
383 59b8ad81 bellard
384 e1a23744 bellard
static void ioport92_write(void *opaque, uint32_t addr, uint32_t val)
385 e1a23744 bellard
{
386 59b8ad81 bellard
    ioport_set_a20((val >> 1) & 1);
387 e1a23744 bellard
    /* XXX: bit 0 is fast reset */
388 e1a23744 bellard
}
389 e1a23744 bellard
390 e1a23744 bellard
static uint32_t ioport92_read(void *opaque, uint32_t addr)
391 e1a23744 bellard
{
392 59b8ad81 bellard
    return ioport_get_a20() << 1;
393 e1a23744 bellard
}
394 e1a23744 bellard
395 80cabfad bellard
/***********************************************************/
396 80cabfad bellard
/* Bochs BIOS debug ports */
397 80cabfad bellard
398 9596ebb7 pbrook
static void bochs_bios_write(void *opaque, uint32_t addr, uint32_t val)
399 80cabfad bellard
{
400 a2f659ee bellard
    static const char shutdown_str[8] = "Shutdown";
401 a2f659ee bellard
    static int shutdown_index = 0;
402 3b46e624 ths
403 80cabfad bellard
    switch(addr) {
404 80cabfad bellard
        /* Bochs BIOS messages */
405 80cabfad bellard
    case 0x400:
406 80cabfad bellard
    case 0x401:
407 80cabfad bellard
        fprintf(stderr, "BIOS panic at rombios.c, line %d\n", val);
408 80cabfad bellard
        exit(1);
409 80cabfad bellard
    case 0x402:
410 80cabfad bellard
    case 0x403:
411 80cabfad bellard
#ifdef DEBUG_BIOS
412 80cabfad bellard
        fprintf(stderr, "%c", val);
413 80cabfad bellard
#endif
414 80cabfad bellard
        break;
415 a2f659ee bellard
    case 0x8900:
416 a2f659ee bellard
        /* same as Bochs power off */
417 a2f659ee bellard
        if (val == shutdown_str[shutdown_index]) {
418 a2f659ee bellard
            shutdown_index++;
419 a2f659ee bellard
            if (shutdown_index == 8) {
420 a2f659ee bellard
                shutdown_index = 0;
421 a2f659ee bellard
                qemu_system_shutdown_request();
422 a2f659ee bellard
            }
423 a2f659ee bellard
        } else {
424 a2f659ee bellard
            shutdown_index = 0;
425 a2f659ee bellard
        }
426 a2f659ee bellard
        break;
427 80cabfad bellard
428 80cabfad bellard
        /* LGPL'ed VGA BIOS messages */
429 80cabfad bellard
    case 0x501:
430 80cabfad bellard
    case 0x502:
431 80cabfad bellard
        fprintf(stderr, "VGA BIOS panic, line %d\n", val);
432 80cabfad bellard
        exit(1);
433 80cabfad bellard
    case 0x500:
434 80cabfad bellard
    case 0x503:
435 80cabfad bellard
#ifdef DEBUG_BIOS
436 80cabfad bellard
        fprintf(stderr, "%c", val);
437 80cabfad bellard
#endif
438 80cabfad bellard
        break;
439 80cabfad bellard
    }
440 80cabfad bellard
}
441 80cabfad bellard
442 4c5b10b7 Jes Sorensen
int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
443 4c5b10b7 Jes Sorensen
{
444 4c5b10b7 Jes Sorensen
    int index = e820_table.count;
445 4c5b10b7 Jes Sorensen
    struct e820_entry *entry;
446 4c5b10b7 Jes Sorensen
447 4c5b10b7 Jes Sorensen
    if (index >= E820_NR_ENTRIES)
448 4c5b10b7 Jes Sorensen
        return -EBUSY;
449 4c5b10b7 Jes Sorensen
    entry = &e820_table.entry[index];
450 4c5b10b7 Jes Sorensen
451 4c5b10b7 Jes Sorensen
    entry->address = address;
452 4c5b10b7 Jes Sorensen
    entry->length = length;
453 4c5b10b7 Jes Sorensen
    entry->type = type;
454 4c5b10b7 Jes Sorensen
455 4c5b10b7 Jes Sorensen
    e820_table.count++;
456 4c5b10b7 Jes Sorensen
    return e820_table.count;
457 4c5b10b7 Jes Sorensen
}
458 4c5b10b7 Jes Sorensen
459 bf483392 Alexander Graf
static void *bochs_bios_init(void)
460 80cabfad bellard
{
461 3cce6243 blueswir1
    void *fw_cfg;
462 b6f6e3d3 aliguori
    uint8_t *smbios_table;
463 b6f6e3d3 aliguori
    size_t smbios_len;
464 11c2fd3e aliguori
    uint64_t *numa_fw_cfg;
465 11c2fd3e aliguori
    int i, j;
466 3cce6243 blueswir1
467 b41a2cd1 bellard
    register_ioport_write(0x400, 1, 2, bochs_bios_write, NULL);
468 b41a2cd1 bellard
    register_ioport_write(0x401, 1, 2, bochs_bios_write, NULL);
469 b41a2cd1 bellard
    register_ioport_write(0x402, 1, 1, bochs_bios_write, NULL);
470 b41a2cd1 bellard
    register_ioport_write(0x403, 1, 1, bochs_bios_write, NULL);
471 a2f659ee bellard
    register_ioport_write(0x8900, 1, 1, bochs_bios_write, NULL);
472 b41a2cd1 bellard
473 b41a2cd1 bellard
    register_ioport_write(0x501, 1, 2, bochs_bios_write, NULL);
474 b41a2cd1 bellard
    register_ioport_write(0x502, 1, 2, bochs_bios_write, NULL);
475 b41a2cd1 bellard
    register_ioport_write(0x500, 1, 1, bochs_bios_write, NULL);
476 b41a2cd1 bellard
    register_ioport_write(0x503, 1, 1, bochs_bios_write, NULL);
477 3cce6243 blueswir1
478 3cce6243 blueswir1
    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
479 bf483392 Alexander Graf
480 3cce6243 blueswir1
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
481 905fdcb5 blueswir1
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
482 80deece2 blueswir1
    fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, (uint8_t *)acpi_tables,
483 80deece2 blueswir1
                     acpi_tables_len);
484 6b35e7bf Jes Sorensen
    fw_cfg_add_bytes(fw_cfg, FW_CFG_IRQ0_OVERRIDE, &irq0override, 1);
485 b6f6e3d3 aliguori
486 b6f6e3d3 aliguori
    smbios_table = smbios_get_table(&smbios_len);
487 b6f6e3d3 aliguori
    if (smbios_table)
488 b6f6e3d3 aliguori
        fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
489 b6f6e3d3 aliguori
                         smbios_table, smbios_len);
490 4c5b10b7 Jes Sorensen
    fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)&e820_table,
491 4c5b10b7 Jes Sorensen
                     sizeof(struct e820_table));
492 11c2fd3e aliguori
493 11c2fd3e aliguori
    /* allocate memory for the NUMA channel: one (64bit) word for the number
494 11c2fd3e aliguori
     * of nodes, one word for each VCPU->node and one word for each node to
495 11c2fd3e aliguori
     * hold the amount of memory.
496 11c2fd3e aliguori
     */
497 11c2fd3e aliguori
    numa_fw_cfg = qemu_mallocz((1 + smp_cpus + nb_numa_nodes) * 8);
498 11c2fd3e aliguori
    numa_fw_cfg[0] = cpu_to_le64(nb_numa_nodes);
499 11c2fd3e aliguori
    for (i = 0; i < smp_cpus; i++) {
500 11c2fd3e aliguori
        for (j = 0; j < nb_numa_nodes; j++) {
501 11c2fd3e aliguori
            if (node_cpumask[j] & (1 << i)) {
502 11c2fd3e aliguori
                numa_fw_cfg[i + 1] = cpu_to_le64(j);
503 11c2fd3e aliguori
                break;
504 11c2fd3e aliguori
            }
505 11c2fd3e aliguori
        }
506 11c2fd3e aliguori
    }
507 11c2fd3e aliguori
    for (i = 0; i < nb_numa_nodes; i++) {
508 11c2fd3e aliguori
        numa_fw_cfg[smp_cpus + 1 + i] = cpu_to_le64(node_mem[i]);
509 11c2fd3e aliguori
    }
510 11c2fd3e aliguori
    fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, (uint8_t *)numa_fw_cfg,
511 11c2fd3e aliguori
                     (1 + smp_cpus + nb_numa_nodes) * 8);
512 bf483392 Alexander Graf
513 bf483392 Alexander Graf
    return fw_cfg;
514 80cabfad bellard
}
515 80cabfad bellard
516 642a4f96 ths
static long get_file_size(FILE *f)
517 642a4f96 ths
{
518 642a4f96 ths
    long where, size;
519 642a4f96 ths
520 642a4f96 ths
    /* XXX: on Unix systems, using fstat() probably makes more sense */
521 642a4f96 ths
522 642a4f96 ths
    where = ftell(f);
523 642a4f96 ths
    fseek(f, 0, SEEK_END);
524 642a4f96 ths
    size = ftell(f);
525 642a4f96 ths
    fseek(f, where, SEEK_SET);
526 642a4f96 ths
527 642a4f96 ths
    return size;
528 642a4f96 ths
}
529 642a4f96 ths
530 f16408df Alexander Graf
static void load_linux(void *fw_cfg,
531 4fc9af53 aliguori
                       const char *kernel_filename,
532 642a4f96 ths
                       const char *initrd_filename,
533 e6ade764 Glauber Costa
                       const char *kernel_cmdline,
534 45a50b16 Gerd Hoffmann
                       target_phys_addr_t max_ram_size)
535 642a4f96 ths
{
536 642a4f96 ths
    uint16_t protocol;
537 5cea8590 Paul Brook
    int setup_size, kernel_size, initrd_size = 0, cmdline_size;
538 642a4f96 ths
    uint32_t initrd_max;
539 57a46d05 Alexander Graf
    uint8_t header[8192], *setup, *kernel, *initrd_data;
540 c227f099 Anthony Liguori
    target_phys_addr_t real_addr, prot_addr, cmdline_addr, initrd_addr = 0;
541 45a50b16 Gerd Hoffmann
    FILE *f;
542 bf4e5d92 Pascal Terjan
    char *vmode;
543 642a4f96 ths
544 642a4f96 ths
    /* Align to 16 bytes as a paranoia measure */
545 642a4f96 ths
    cmdline_size = (strlen(kernel_cmdline)+16) & ~15;
546 642a4f96 ths
547 642a4f96 ths
    /* load the kernel header */
548 642a4f96 ths
    f = fopen(kernel_filename, "rb");
549 642a4f96 ths
    if (!f || !(kernel_size = get_file_size(f)) ||
550 f16408df Alexander Graf
        fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) !=
551 f16408df Alexander Graf
        MIN(ARRAY_SIZE(header), kernel_size)) {
552 850810d0 Justin M. Forbes
        fprintf(stderr, "qemu: could not load kernel '%s': %s\n",
553 850810d0 Justin M. Forbes
                kernel_filename, strerror(errno));
554 642a4f96 ths
        exit(1);
555 642a4f96 ths
    }
556 642a4f96 ths
557 642a4f96 ths
    /* kernel protocol version */
558 bc4edd79 bellard
#if 0
559 642a4f96 ths
    fprintf(stderr, "header magic: %#x\n", ldl_p(header+0x202));
560 bc4edd79 bellard
#endif
561 642a4f96 ths
    if (ldl_p(header+0x202) == 0x53726448)
562 642a4f96 ths
        protocol = lduw_p(header+0x206);
563 f16408df Alexander Graf
    else {
564 f16408df Alexander Graf
        /* This looks like a multiboot kernel. If it is, let's stop
565 f16408df Alexander Graf
           treating it like a Linux kernel. */
566 52001445 Adam Lackorzynski
        if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename,
567 52001445 Adam Lackorzynski
                           kernel_cmdline, kernel_size, header))
568 82663ee2 Blue Swirl
            return;
569 642a4f96 ths
        protocol = 0;
570 f16408df Alexander Graf
    }
571 642a4f96 ths
572 642a4f96 ths
    if (protocol < 0x200 || !(header[0x211] & 0x01)) {
573 642a4f96 ths
        /* Low kernel */
574 a37af289 blueswir1
        real_addr    = 0x90000;
575 a37af289 blueswir1
        cmdline_addr = 0x9a000 - cmdline_size;
576 a37af289 blueswir1
        prot_addr    = 0x10000;
577 642a4f96 ths
    } else if (protocol < 0x202) {
578 642a4f96 ths
        /* High but ancient kernel */
579 a37af289 blueswir1
        real_addr    = 0x90000;
580 a37af289 blueswir1
        cmdline_addr = 0x9a000 - cmdline_size;
581 a37af289 blueswir1
        prot_addr    = 0x100000;
582 642a4f96 ths
    } else {
583 642a4f96 ths
        /* High and recent kernel */
584 a37af289 blueswir1
        real_addr    = 0x10000;
585 a37af289 blueswir1
        cmdline_addr = 0x20000;
586 a37af289 blueswir1
        prot_addr    = 0x100000;
587 642a4f96 ths
    }
588 642a4f96 ths
589 bc4edd79 bellard
#if 0
590 642a4f96 ths
    fprintf(stderr,
591 526ccb7a balrog
            "qemu: real_addr     = 0x" TARGET_FMT_plx "\n"
592 526ccb7a balrog
            "qemu: cmdline_addr  = 0x" TARGET_FMT_plx "\n"
593 526ccb7a balrog
            "qemu: prot_addr     = 0x" TARGET_FMT_plx "\n",
594 a37af289 blueswir1
            real_addr,
595 a37af289 blueswir1
            cmdline_addr,
596 a37af289 blueswir1
            prot_addr);
597 bc4edd79 bellard
#endif
598 642a4f96 ths
599 642a4f96 ths
    /* highest address for loading the initrd */
600 642a4f96 ths
    if (protocol >= 0x203)
601 642a4f96 ths
        initrd_max = ldl_p(header+0x22c);
602 642a4f96 ths
    else
603 642a4f96 ths
        initrd_max = 0x37ffffff;
604 642a4f96 ths
605 e6ade764 Glauber Costa
    if (initrd_max >= max_ram_size-ACPI_DATA_SIZE)
606 e6ade764 Glauber Costa
            initrd_max = max_ram_size-ACPI_DATA_SIZE-1;
607 642a4f96 ths
608 57a46d05 Alexander Graf
    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
609 57a46d05 Alexander Graf
    fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, strlen(kernel_cmdline)+1);
610 57a46d05 Alexander Graf
    fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
611 57a46d05 Alexander Graf
                     (uint8_t*)strdup(kernel_cmdline),
612 57a46d05 Alexander Graf
                     strlen(kernel_cmdline)+1);
613 642a4f96 ths
614 642a4f96 ths
    if (protocol >= 0x202) {
615 a37af289 blueswir1
        stl_p(header+0x228, cmdline_addr);
616 642a4f96 ths
    } else {
617 642a4f96 ths
        stw_p(header+0x20, 0xA33F);
618 642a4f96 ths
        stw_p(header+0x22, cmdline_addr-real_addr);
619 642a4f96 ths
    }
620 642a4f96 ths
621 bf4e5d92 Pascal Terjan
    /* handle vga= parameter */
622 bf4e5d92 Pascal Terjan
    vmode = strstr(kernel_cmdline, "vga=");
623 bf4e5d92 Pascal Terjan
    if (vmode) {
624 bf4e5d92 Pascal Terjan
        unsigned int video_mode;
625 bf4e5d92 Pascal Terjan
        /* skip "vga=" */
626 bf4e5d92 Pascal Terjan
        vmode += 4;
627 bf4e5d92 Pascal Terjan
        if (!strncmp(vmode, "normal", 6)) {
628 bf4e5d92 Pascal Terjan
            video_mode = 0xffff;
629 bf4e5d92 Pascal Terjan
        } else if (!strncmp(vmode, "ext", 3)) {
630 bf4e5d92 Pascal Terjan
            video_mode = 0xfffe;
631 bf4e5d92 Pascal Terjan
        } else if (!strncmp(vmode, "ask", 3)) {
632 bf4e5d92 Pascal Terjan
            video_mode = 0xfffd;
633 bf4e5d92 Pascal Terjan
        } else {
634 bf4e5d92 Pascal Terjan
            video_mode = strtol(vmode, NULL, 0);
635 bf4e5d92 Pascal Terjan
        }
636 bf4e5d92 Pascal Terjan
        stw_p(header+0x1fa, video_mode);
637 bf4e5d92 Pascal Terjan
    }
638 bf4e5d92 Pascal Terjan
639 642a4f96 ths
    /* loader type */
640 642a4f96 ths
    /* High nybble = B reserved for Qemu; low nybble is revision number.
641 642a4f96 ths
       If this code is substantially changed, you may want to consider
642 642a4f96 ths
       incrementing the revision. */
643 642a4f96 ths
    if (protocol >= 0x200)
644 642a4f96 ths
        header[0x210] = 0xB0;
645 642a4f96 ths
646 642a4f96 ths
    /* heap */
647 642a4f96 ths
    if (protocol >= 0x201) {
648 642a4f96 ths
        header[0x211] |= 0x80;        /* CAN_USE_HEAP */
649 642a4f96 ths
        stw_p(header+0x224, cmdline_addr-real_addr-0x200);
650 642a4f96 ths
    }
651 642a4f96 ths
652 642a4f96 ths
    /* load initrd */
653 642a4f96 ths
    if (initrd_filename) {
654 642a4f96 ths
        if (protocol < 0x200) {
655 642a4f96 ths
            fprintf(stderr, "qemu: linux kernel too old to load a ram disk\n");
656 642a4f96 ths
            exit(1);
657 642a4f96 ths
        }
658 642a4f96 ths
659 45a50b16 Gerd Hoffmann
        initrd_size = get_image_size(initrd_filename);
660 45a50b16 Gerd Hoffmann
        initrd_addr = (initrd_max-initrd_size) & ~4095;
661 57a46d05 Alexander Graf
662 57a46d05 Alexander Graf
        initrd_data = qemu_malloc(initrd_size);
663 57a46d05 Alexander Graf
        load_image(initrd_filename, initrd_data);
664 57a46d05 Alexander Graf
665 57a46d05 Alexander Graf
        fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
666 57a46d05 Alexander Graf
        fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
667 57a46d05 Alexander Graf
        fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data, initrd_size);
668 642a4f96 ths
669 a37af289 blueswir1
        stl_p(header+0x218, initrd_addr);
670 642a4f96 ths
        stl_p(header+0x21c, initrd_size);
671 642a4f96 ths
    }
672 642a4f96 ths
673 45a50b16 Gerd Hoffmann
    /* load kernel and setup */
674 642a4f96 ths
    setup_size = header[0x1f1];
675 642a4f96 ths
    if (setup_size == 0)
676 642a4f96 ths
        setup_size = 4;
677 642a4f96 ths
    setup_size = (setup_size+1)*512;
678 45a50b16 Gerd Hoffmann
    kernel_size -= setup_size;
679 642a4f96 ths
680 45a50b16 Gerd Hoffmann
    setup  = qemu_malloc(setup_size);
681 45a50b16 Gerd Hoffmann
    kernel = qemu_malloc(kernel_size);
682 45a50b16 Gerd Hoffmann
    fseek(f, 0, SEEK_SET);
683 5a41ecc5 Kirill A. Shutemov
    if (fread(setup, 1, setup_size, f) != setup_size) {
684 5a41ecc5 Kirill A. Shutemov
        fprintf(stderr, "fread() failed\n");
685 5a41ecc5 Kirill A. Shutemov
        exit(1);
686 5a41ecc5 Kirill A. Shutemov
    }
687 5a41ecc5 Kirill A. Shutemov
    if (fread(kernel, 1, kernel_size, f) != kernel_size) {
688 5a41ecc5 Kirill A. Shutemov
        fprintf(stderr, "fread() failed\n");
689 5a41ecc5 Kirill A. Shutemov
        exit(1);
690 5a41ecc5 Kirill A. Shutemov
    }
691 642a4f96 ths
    fclose(f);
692 45a50b16 Gerd Hoffmann
    memcpy(setup, header, MIN(sizeof(header), setup_size));
693 57a46d05 Alexander Graf
694 57a46d05 Alexander Graf
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, prot_addr);
695 57a46d05 Alexander Graf
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
696 57a46d05 Alexander Graf
    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
697 57a46d05 Alexander Graf
698 57a46d05 Alexander Graf
    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_ADDR, real_addr);
699 57a46d05 Alexander Graf
    fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, setup_size);
700 57a46d05 Alexander Graf
    fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA, setup, setup_size);
701 57a46d05 Alexander Graf
702 57a46d05 Alexander Graf
    option_rom[nb_option_roms] = "linuxboot.bin";
703 57a46d05 Alexander Graf
    nb_option_roms++;
704 642a4f96 ths
}
705 642a4f96 ths
706 b41a2cd1 bellard
static const int ide_iobase[2] = { 0x1f0, 0x170 };
707 b41a2cd1 bellard
static const int ide_iobase2[2] = { 0x3f6, 0x376 };
708 b41a2cd1 bellard
static const int ide_irq[2] = { 14, 15 };
709 b41a2cd1 bellard
710 b41a2cd1 bellard
#define NE2000_NB_MAX 6
711 b41a2cd1 bellard
712 675d6f82 Blue Swirl
static const int ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360,
713 675d6f82 Blue Swirl
                                              0x280, 0x380 };
714 675d6f82 Blue Swirl
static const int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
715 b41a2cd1 bellard
716 675d6f82 Blue Swirl
static const int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
717 675d6f82 Blue Swirl
static const int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
718 6508fe59 bellard
719 6a36d84e bellard
#ifdef HAS_AUDIO
720 d537cf6c pbrook
static void audio_init (PCIBus *pci_bus, qemu_irq *pic)
721 6a36d84e bellard
{
722 6a36d84e bellard
    struct soundhw *c;
723 6a36d84e bellard
724 3a8bae3e malc
    for (c = soundhw; c->name; ++c) {
725 3a8bae3e malc
        if (c->enabled) {
726 3a8bae3e malc
            if (c->isa) {
727 3a8bae3e malc
                c->init.init_isa(pic);
728 3a8bae3e malc
            } else {
729 3a8bae3e malc
                if (pci_bus) {
730 3a8bae3e malc
                    c->init.init_pci(pci_bus);
731 6a36d84e bellard
                }
732 6a36d84e bellard
            }
733 6a36d84e bellard
        }
734 6a36d84e bellard
    }
735 6a36d84e bellard
}
736 6a36d84e bellard
#endif
737 6a36d84e bellard
738 3a38d437 Jes Sorensen
static void pc_init_ne2k_isa(NICInfo *nd)
739 a41b2ff2 pbrook
{
740 a41b2ff2 pbrook
    static int nb_ne2k = 0;
741 a41b2ff2 pbrook
742 a41b2ff2 pbrook
    if (nb_ne2k == NE2000_NB_MAX)
743 a41b2ff2 pbrook
        return;
744 3a38d437 Jes Sorensen
    isa_ne2000_init(ne2000_io[nb_ne2k],
745 9453c5bc Gerd Hoffmann
                    ne2000_irq[nb_ne2k], nd);
746 a41b2ff2 pbrook
    nb_ne2k++;
747 a41b2ff2 pbrook
}
748 a41b2ff2 pbrook
749 678e12cc Gleb Natapov
int cpu_is_bsp(CPUState *env)
750 678e12cc Gleb Natapov
{
751 6cb2996c Jan Kiszka
    /* We hard-wire the BSP to the first CPU. */
752 6cb2996c Jan Kiszka
    return env->cpu_index == 0;
753 678e12cc Gleb Natapov
}
754 678e12cc Gleb Natapov
755 3a31f36a Jan Kiszka
static CPUState *pc_new_cpu(const char *cpu_model)
756 3a31f36a Jan Kiszka
{
757 3a31f36a Jan Kiszka
    CPUState *env;
758 3a31f36a Jan Kiszka
759 3a31f36a Jan Kiszka
    env = cpu_init(cpu_model);
760 3a31f36a Jan Kiszka
    if (!env) {
761 3a31f36a Jan Kiszka
        fprintf(stderr, "Unable to find x86 CPU definition\n");
762 3a31f36a Jan Kiszka
        exit(1);
763 3a31f36a Jan Kiszka
    }
764 3a31f36a Jan Kiszka
    if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
765 3a31f36a Jan Kiszka
        env->cpuid_apic_id = env->cpu_index;
766 3a31f36a Jan Kiszka
        /* APIC reset callback resets cpu */
767 3a31f36a Jan Kiszka
        apic_init(env);
768 3a31f36a Jan Kiszka
    } else {
769 3a31f36a Jan Kiszka
        qemu_register_reset((QEMUResetHandler*)cpu_reset, env);
770 3a31f36a Jan Kiszka
    }
771 3a31f36a Jan Kiszka
    return env;
772 3a31f36a Jan Kiszka
}
773 3a31f36a Jan Kiszka
774 80cabfad bellard
/* PC hardware initialisation */
775 c227f099 Anthony Liguori
static void pc_init1(ram_addr_t ram_size,
776 3023f332 aliguori
                     const char *boot_device,
777 e8b2a1c6 Mark McLoughlin
                     const char *kernel_filename,
778 e8b2a1c6 Mark McLoughlin
                     const char *kernel_cmdline,
779 3dbbdc25 bellard
                     const char *initrd_filename,
780 e8b2a1c6 Mark McLoughlin
                     const char *cpu_model,
781 caea79a9 Mark McLoughlin
                     int pci_enabled)
782 80cabfad bellard
{
783 5cea8590 Paul Brook
    char *filename;
784 642a4f96 ths
    int ret, linux_boot, i;
785 c227f099 Anthony Liguori
    ram_addr_t ram_addr, bios_offset, option_rom_offset;
786 c227f099 Anthony Liguori
    ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
787 45a50b16 Gerd Hoffmann
    int bios_size, isa_bios_size;
788 46e50e9d bellard
    PCIBus *pci_bus;
789 b3999638 Gerd Hoffmann
    ISADevice *isa_dev;
790 5c3ff3a7 pbrook
    int piix3_devfn = -1;
791 59b8ad81 bellard
    CPUState *env;
792 d537cf6c pbrook
    qemu_irq *cpu_irq;
793 1452411b Avi Kivity
    qemu_irq *isa_irq;
794 d537cf6c pbrook
    qemu_irq *i8259;
795 1452411b Avi Kivity
    IsaIrqState *isa_irq_state;
796 f455e98c Gerd Hoffmann
    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
797 fd8014e1 Gerd Hoffmann
    DriveInfo *fd[MAX_FD];
798 bf483392 Alexander Graf
    void *fw_cfg;
799 d592d303 bellard
800 00f82b8a aurel32
    if (ram_size >= 0xe0000000 ) {
801 00f82b8a aurel32
        above_4g_mem_size = ram_size - 0xe0000000;
802 00f82b8a aurel32
        below_4g_mem_size = 0xe0000000;
803 00f82b8a aurel32
    } else {
804 00f82b8a aurel32
        below_4g_mem_size = ram_size;
805 00f82b8a aurel32
    }
806 00f82b8a aurel32
807 80cabfad bellard
    linux_boot = (kernel_filename != NULL);
808 80cabfad bellard
809 59b8ad81 bellard
    /* init CPUs */
810 a049de61 bellard
    if (cpu_model == NULL) {
811 a049de61 bellard
#ifdef TARGET_X86_64
812 a049de61 bellard
        cpu_model = "qemu64";
813 a049de61 bellard
#else
814 a049de61 bellard
        cpu_model = "qemu32";
815 a049de61 bellard
#endif
816 a049de61 bellard
    }
817 3a31f36a Jan Kiszka
818 3a31f36a Jan Kiszka
    for (i = 0; i < smp_cpus; i++) {
819 3a31f36a Jan Kiszka
        env = pc_new_cpu(cpu_model);
820 59b8ad81 bellard
    }
821 59b8ad81 bellard
822 26fb5e48 aurel32
    vmport_init();
823 26fb5e48 aurel32
824 80cabfad bellard
    /* allocate RAM */
825 60e4c631 Avi Kivity
    ram_addr = qemu_ram_alloc(below_4g_mem_size);
826 82b36dc3 aliguori
    cpu_register_physical_memory(0, 0xa0000, ram_addr);
827 82b36dc3 aliguori
    cpu_register_physical_memory(0x100000,
828 82b36dc3 aliguori
                 below_4g_mem_size - 0x100000,
829 60e4c631 Avi Kivity
                 ram_addr + 0x100000);
830 00f82b8a aurel32
831 00f82b8a aurel32
    /* above 4giga memory allocation */
832 00f82b8a aurel32
    if (above_4g_mem_size > 0) {
833 8a637d44 Paul Brook
#if TARGET_PHYS_ADDR_BITS == 32
834 8a637d44 Paul Brook
        hw_error("To much RAM for 32-bit physical address");
835 8a637d44 Paul Brook
#else
836 82b36dc3 aliguori
        ram_addr = qemu_ram_alloc(above_4g_mem_size);
837 82b36dc3 aliguori
        cpu_register_physical_memory(0x100000000ULL,
838 526ccb7a balrog
                                     above_4g_mem_size,
839 82b36dc3 aliguori
                                     ram_addr);
840 8a637d44 Paul Brook
#endif
841 00f82b8a aurel32
    }
842 80cabfad bellard
843 82b36dc3 aliguori
844 970ac5a3 bellard
    /* BIOS load */
845 1192dad8 j_mayer
    if (bios_name == NULL)
846 1192dad8 j_mayer
        bios_name = BIOS_FILENAME;
847 5cea8590 Paul Brook
    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
848 5cea8590 Paul Brook
    if (filename) {
849 5cea8590 Paul Brook
        bios_size = get_image_size(filename);
850 5cea8590 Paul Brook
    } else {
851 5cea8590 Paul Brook
        bios_size = -1;
852 5cea8590 Paul Brook
    }
853 5fafdf24 ths
    if (bios_size <= 0 ||
854 970ac5a3 bellard
        (bios_size % 65536) != 0) {
855 7587cf44 bellard
        goto bios_error;
856 7587cf44 bellard
    }
857 970ac5a3 bellard
    bios_offset = qemu_ram_alloc(bios_size);
858 51edd4e6 Gerd Hoffmann
    ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size));
859 51edd4e6 Gerd Hoffmann
    if (ret != 0) {
860 7587cf44 bellard
    bios_error:
861 5cea8590 Paul Brook
        fprintf(stderr, "qemu: could not load PC BIOS '%s'\n", bios_name);
862 80cabfad bellard
        exit(1);
863 80cabfad bellard
    }
864 5cea8590 Paul Brook
    if (filename) {
865 5cea8590 Paul Brook
        qemu_free(filename);
866 5cea8590 Paul Brook
    }
867 7587cf44 bellard
    /* map the last 128KB of the BIOS in ISA space */
868 7587cf44 bellard
    isa_bios_size = bios_size;
869 7587cf44 bellard
    if (isa_bios_size > (128 * 1024))
870 7587cf44 bellard
        isa_bios_size = 128 * 1024;
871 5fafdf24 ths
    cpu_register_physical_memory(0x100000 - isa_bios_size,
872 5fafdf24 ths
                                 isa_bios_size,
873 7587cf44 bellard
                                 (bios_offset + bios_size - isa_bios_size) | IO_MEM_ROM);
874 9ae02555 ths
875 45a50b16 Gerd Hoffmann
    option_rom_offset = qemu_ram_alloc(PC_ROM_SIZE);
876 45a50b16 Gerd Hoffmann
    cpu_register_physical_memory(PC_ROM_MIN_VGA, PC_ROM_SIZE, option_rom_offset);
877 f753ff16 pbrook
878 1d108d97 Alexander Graf
    /* map all the bios at the top of memory */
879 1d108d97 Alexander Graf
    cpu_register_physical_memory((uint32_t)(-bios_size),
880 1d108d97 Alexander Graf
                                 bios_size, bios_offset | IO_MEM_ROM);
881 1d108d97 Alexander Graf
882 bf483392 Alexander Graf
    fw_cfg = bochs_bios_init();
883 8832cb80 Gerd Hoffmann
    rom_set_fw(fw_cfg);
884 1d108d97 Alexander Graf
885 f753ff16 pbrook
    if (linux_boot) {
886 45a50b16 Gerd Hoffmann
        load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
887 f753ff16 pbrook
    }
888 f753ff16 pbrook
889 f753ff16 pbrook
    for (i = 0; i < nb_option_roms; i++) {
890 45a50b16 Gerd Hoffmann
        rom_add_option(option_rom[i]);
891 406c8df3 Glauber Costa
    }
892 406c8df3 Glauber Costa
893 a5b38b51 aurel32
    cpu_irq = qemu_allocate_irqs(pic_irq_request, NULL, 1);
894 d537cf6c pbrook
    i8259 = i8259_init(cpu_irq[0]);
895 1452411b Avi Kivity
    isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
896 1452411b Avi Kivity
    isa_irq_state->i8259 = i8259;
897 1632dc6a Avi Kivity
    isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
898 d537cf6c pbrook
899 69b91039 bellard
    if (pci_enabled) {
900 85a750ca Juan Quintela
        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq);
901 46e50e9d bellard
    } else {
902 46e50e9d bellard
        pci_bus = NULL;
903 2091ba23 Gerd Hoffmann
        isa_bus_new(NULL);
904 69b91039 bellard
    }
905 2091ba23 Gerd Hoffmann
    isa_bus_irqs(isa_irq);
906 69b91039 bellard
907 3a38d437 Jes Sorensen
    ferr_irq = isa_reserve_irq(13);
908 3a38d437 Jes Sorensen
909 80cabfad bellard
    /* init basic PC hardware */
910 b41a2cd1 bellard
    register_ioport_write(0x80, 1, 1, ioport80_write, NULL);
911 80cabfad bellard
912 f929aad6 bellard
    register_ioport_write(0xf0, 1, 1, ioportF0_write, NULL);
913 f929aad6 bellard
914 1f04275e bellard
    if (cirrus_vga_enabled) {
915 1f04275e bellard
        if (pci_enabled) {
916 fbe1b595 Paul Brook
            pci_cirrus_vga_init(pci_bus);
917 1f04275e bellard
        } else {
918 fbe1b595 Paul Brook
            isa_cirrus_vga_init();
919 1f04275e bellard
        }
920 d34cab9f ths
    } else if (vmsvga_enabled) {
921 d34cab9f ths
        if (pci_enabled)
922 fbe1b595 Paul Brook
            pci_vmsvga_init(pci_bus);
923 d34cab9f ths
        else
924 d34cab9f ths
            fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
925 c2b3b41a aliguori
    } else if (std_vga_enabled) {
926 89b6b508 bellard
        if (pci_enabled) {
927 fbe1b595 Paul Brook
            pci_vga_init(pci_bus, 0, 0);
928 89b6b508 bellard
        } else {
929 fbe1b595 Paul Brook
            isa_vga_init();
930 89b6b508 bellard
        }
931 1f04275e bellard
    }
932 80cabfad bellard
933 32e0c826 Gerd Hoffmann
    rtc_state = rtc_init(2000);
934 80cabfad bellard
935 3b4366de blueswir1
    qemu_register_boot_set(pc_boot_set, rtc_state);
936 3b4366de blueswir1
937 e1a23744 bellard
    register_ioport_read(0x92, 1, 1, ioport92_read, NULL);
938 e1a23744 bellard
    register_ioport_write(0x92, 1, 1, ioport92_write, NULL);
939 e1a23744 bellard
940 d592d303 bellard
    if (pci_enabled) {
941 1632dc6a Avi Kivity
        isa_irq_state->ioapic = ioapic_init();
942 d592d303 bellard
    }
943 3a38d437 Jes Sorensen
    pit = pit_init(0x40, isa_reserve_irq(0));
944 fd06c375 bellard
    pcspk_init(pit);
945 16b29ae1 aliguori
    if (!no_hpet) {
946 1452411b Avi Kivity
        hpet_init(isa_irq);
947 16b29ae1 aliguori
    }
948 b41a2cd1 bellard
949 8d11df9e bellard
    for(i = 0; i < MAX_SERIAL_PORTS; i++) {
950 8d11df9e bellard
        if (serial_hds[i]) {
951 ac0be998 Gerd Hoffmann
            serial_isa_init(i, serial_hds[i]);
952 8d11df9e bellard
        }
953 8d11df9e bellard
    }
954 b41a2cd1 bellard
955 6508fe59 bellard
    for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
956 6508fe59 bellard
        if (parallel_hds[i]) {
957 021f0674 Gerd Hoffmann
            parallel_init(i, parallel_hds[i]);
958 6508fe59 bellard
        }
959 6508fe59 bellard
    }
960 6508fe59 bellard
961 a41b2ff2 pbrook
    for(i = 0; i < nb_nics; i++) {
962 cb457d76 aliguori
        NICInfo *nd = &nd_table[i];
963 cb457d76 aliguori
964 cb457d76 aliguori
        if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
965 3a38d437 Jes Sorensen
            pc_init_ne2k_isa(nd);
966 cb457d76 aliguori
        else
967 07caea31 Markus Armbruster
            pci_nic_init_nofail(nd, "e1000", NULL);
968 a41b2ff2 pbrook
    }
969 b41a2cd1 bellard
970 e4bcb14c ths
    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
971 e4bcb14c ths
        fprintf(stderr, "qemu: too many IDE bus\n");
972 e4bcb14c ths
        exit(1);
973 e4bcb14c ths
    }
974 e4bcb14c ths
975 e4bcb14c ths
    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
976 f455e98c Gerd Hoffmann
        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
977 e4bcb14c ths
    }
978 e4bcb14c ths
979 a41b2ff2 pbrook
    if (pci_enabled) {
980 ae027ad3 Stefan Weil
        pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
981 a41b2ff2 pbrook
    } else {
982 e4bcb14c ths
        for(i = 0; i < MAX_IDE_BUS; i++) {
983 dea21e97 Gerd Hoffmann
            isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
984 e4bcb14c ths
                         hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
985 69b91039 bellard
        }
986 b41a2cd1 bellard
    }
987 69b91039 bellard
988 2e15e23b Gerd Hoffmann
    isa_dev = isa_create_simple("i8042");
989 7c29d0c0 bellard
    DMA_init(0);
990 6a36d84e bellard
#ifdef HAS_AUDIO
991 1452411b Avi Kivity
    audio_init(pci_enabled ? pci_bus : NULL, isa_irq);
992 fb065187 bellard
#endif
993 80cabfad bellard
994 e4bcb14c ths
    for(i = 0; i < MAX_FD; i++) {
995 fd8014e1 Gerd Hoffmann
        fd[i] = drive_get(IF_FLOPPY, 0, i);
996 e4bcb14c ths
    }
997 86c86157 Gerd Hoffmann
    floppy_controller = fdctrl_init_isa(fd);
998 b41a2cd1 bellard
999 00f82b8a aurel32
    cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device, hd);
1000 69b91039 bellard
1001 bb36d470 bellard
    if (pci_enabled && usb_enabled) {
1002 afcc3cdf ths
        usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
1003 bb36d470 bellard
    }
1004 bb36d470 bellard
1005 6515b203 bellard
    if (pci_enabled && acpi_enabled) {
1006 3fffc223 ths
        uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
1007 0ff596d0 pbrook
        i2c_bus *smbus;
1008 0ff596d0 pbrook
1009 0ff596d0 pbrook
        /* TODO: Populate SPD eeprom data.  */
1010 3a38d437 Jes Sorensen
        smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
1011 3a38d437 Jes Sorensen
                              isa_reserve_irq(9));
1012 3fffc223 ths
        for (i = 0; i < 8; i++) {
1013 1ea96673 Paul Brook
            DeviceState *eeprom;
1014 02e2da45 Paul Brook
            eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
1015 5b7f5327 Juan Quintela
            qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
1016 ee6847d1 Gerd Hoffmann
            qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
1017 e23a1b33 Markus Armbruster
            qdev_init_nofail(eeprom);
1018 3fffc223 ths
        }
1019 3f84865a Gerd Hoffmann
        piix4_acpi_system_hot_add_init(pci_bus);
1020 6515b203 bellard
    }
1021 3b46e624 ths
1022 a5954d5c bellard
    if (i440fx_state) {
1023 a5954d5c bellard
        i440fx_init_memory_mappings(i440fx_state);
1024 a5954d5c bellard
    }
1025 e4bcb14c ths
1026 7d8406be pbrook
    if (pci_enabled) {
1027 e4bcb14c ths
        int max_bus;
1028 9be5dafe Paul Brook
        int bus;
1029 96d30e48 ths
1030 e4bcb14c ths
        max_bus = drive_get_max_bus(IF_SCSI);
1031 e4bcb14c ths
        for (bus = 0; bus <= max_bus; bus++) {
1032 9be5dafe Paul Brook
            pci_create_simple(pci_bus, -1, "lsi53c895a");
1033 e4bcb14c ths
        }
1034 7d8406be pbrook
    }
1035 80cabfad bellard
}
1036 b5ff2d6e bellard
1037 c227f099 Anthony Liguori
static void pc_init_pci(ram_addr_t ram_size,
1038 3023f332 aliguori
                        const char *boot_device,
1039 5fafdf24 ths
                        const char *kernel_filename,
1040 3dbbdc25 bellard
                        const char *kernel_cmdline,
1041 94fc95cd j_mayer
                        const char *initrd_filename,
1042 94fc95cd j_mayer
                        const char *cpu_model)
1043 3dbbdc25 bellard
{
1044 fbe1b595 Paul Brook
    pc_init1(ram_size, boot_device,
1045 3dbbdc25 bellard
             kernel_filename, kernel_cmdline,
1046 caea79a9 Mark McLoughlin
             initrd_filename, cpu_model, 1);
1047 3dbbdc25 bellard
}
1048 3dbbdc25 bellard
1049 c227f099 Anthony Liguori
static void pc_init_isa(ram_addr_t ram_size,
1050 3023f332 aliguori
                        const char *boot_device,
1051 5fafdf24 ths
                        const char *kernel_filename,
1052 3dbbdc25 bellard
                        const char *kernel_cmdline,
1053 94fc95cd j_mayer
                        const char *initrd_filename,
1054 94fc95cd j_mayer
                        const char *cpu_model)
1055 3dbbdc25 bellard
{
1056 679a37af Gerd Hoffmann
    if (cpu_model == NULL)
1057 679a37af Gerd Hoffmann
        cpu_model = "486";
1058 fbe1b595 Paul Brook
    pc_init1(ram_size, boot_device,
1059 3dbbdc25 bellard
             kernel_filename, kernel_cmdline,
1060 caea79a9 Mark McLoughlin
             initrd_filename, cpu_model, 0);
1061 3dbbdc25 bellard
}
1062 3dbbdc25 bellard
1063 0bacd130 aliguori
/* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE)
1064 0bacd130 aliguori
   BIOS will read it and start S3 resume at POST Entry */
1065 0bacd130 aliguori
void cmos_set_s3_resume(void)
1066 0bacd130 aliguori
{
1067 0bacd130 aliguori
    if (rtc_state)
1068 0bacd130 aliguori
        rtc_set_memory(rtc_state, 0xF, 0xFE);
1069 0bacd130 aliguori
}
1070 0bacd130 aliguori
1071 f80f9ec9 Anthony Liguori
static QEMUMachine pc_machine = {
1072 d76fa62d Amit Shah
    .name = "pc-0.13",
1073 95747581 Mark McLoughlin
    .alias = "pc",
1074 a245f2e7 aurel32
    .desc = "Standard PC",
1075 a245f2e7 aurel32
    .init = pc_init_pci,
1076 b2097003 aliguori
    .max_cpus = 255,
1077 0c257437 Anthony Liguori
    .is_default = 1,
1078 3dbbdc25 bellard
};
1079 3dbbdc25 bellard
1080 d76fa62d Amit Shah
static QEMUMachine pc_machine_v0_12 = {
1081 d76fa62d Amit Shah
    .name = "pc-0.12",
1082 d76fa62d Amit Shah
    .desc = "Standard PC",
1083 d76fa62d Amit Shah
    .init = pc_init_pci,
1084 d76fa62d Amit Shah
    .max_cpus = 255,
1085 8bfbde6d Amit Shah
    .compat_props = (GlobalProperty[]) {
1086 8bfbde6d Amit Shah
        {
1087 8bfbde6d Amit Shah
            .driver   = "virtio-serial-pci",
1088 8bfbde6d Amit Shah
            .property = "max_nr_ports",
1089 8bfbde6d Amit Shah
            .value    = stringify(1),
1090 8bfbde6d Amit Shah
        },{
1091 8bfbde6d Amit Shah
            .driver   = "virtio-serial-pci",
1092 8bfbde6d Amit Shah
            .property = "vectors",
1093 8bfbde6d Amit Shah
            .value    = stringify(0),
1094 8bfbde6d Amit Shah
        },
1095 8bfbde6d Amit Shah
        { /* end of list */ }
1096 8bfbde6d Amit Shah
    }
1097 d76fa62d Amit Shah
};
1098 d76fa62d Amit Shah
1099 2cae6f5e Gerd Hoffmann
static QEMUMachine pc_machine_v0_11 = {
1100 2cae6f5e Gerd Hoffmann
    .name = "pc-0.11",
1101 2cae6f5e Gerd Hoffmann
    .desc = "Standard PC, qemu 0.11",
1102 2cae6f5e Gerd Hoffmann
    .init = pc_init_pci,
1103 2cae6f5e Gerd Hoffmann
    .max_cpus = 255,
1104 2cae6f5e Gerd Hoffmann
    .compat_props = (GlobalProperty[]) {
1105 2cae6f5e Gerd Hoffmann
        {
1106 2cae6f5e Gerd Hoffmann
            .driver   = "virtio-blk-pci",
1107 2cae6f5e Gerd Hoffmann
            .property = "vectors",
1108 2cae6f5e Gerd Hoffmann
            .value    = stringify(0),
1109 20a86364 Gerd Hoffmann
        },{
1110 8bfbde6d Amit Shah
            .driver   = "virtio-serial-pci",
1111 8bfbde6d Amit Shah
            .property = "max_nr_ports",
1112 8bfbde6d Amit Shah
            .value    = stringify(1),
1113 8bfbde6d Amit Shah
        },{
1114 8bfbde6d Amit Shah
            .driver   = "virtio-serial-pci",
1115 8bfbde6d Amit Shah
            .property = "vectors",
1116 8bfbde6d Amit Shah
            .value    = stringify(0),
1117 8bfbde6d Amit Shah
        },{
1118 374ef704 Gerd Hoffmann
            .driver   = "ide-drive",
1119 374ef704 Gerd Hoffmann
            .property = "ver",
1120 374ef704 Gerd Hoffmann
            .value    = "0.11",
1121 374ef704 Gerd Hoffmann
        },{
1122 374ef704 Gerd Hoffmann
            .driver   = "scsi-disk",
1123 374ef704 Gerd Hoffmann
            .property = "ver",
1124 374ef704 Gerd Hoffmann
            .value    = "0.11",
1125 374ef704 Gerd Hoffmann
        },{
1126 20a86364 Gerd Hoffmann
            .driver   = "PCI",
1127 20a86364 Gerd Hoffmann
            .property = "rombar",
1128 20a86364 Gerd Hoffmann
            .value    = stringify(0),
1129 2cae6f5e Gerd Hoffmann
        },
1130 2cae6f5e Gerd Hoffmann
        { /* end of list */ }
1131 2cae6f5e Gerd Hoffmann
    }
1132 2cae6f5e Gerd Hoffmann
};
1133 2cae6f5e Gerd Hoffmann
1134 96cc1810 Gerd Hoffmann
static QEMUMachine pc_machine_v0_10 = {
1135 96cc1810 Gerd Hoffmann
    .name = "pc-0.10",
1136 96cc1810 Gerd Hoffmann
    .desc = "Standard PC, qemu 0.10",
1137 96cc1810 Gerd Hoffmann
    .init = pc_init_pci,
1138 96cc1810 Gerd Hoffmann
    .max_cpus = 255,
1139 458fb679 Gerd Hoffmann
    .compat_props = (GlobalProperty[]) {
1140 ab73ff29 Gerd Hoffmann
        {
1141 ab73ff29 Gerd Hoffmann
            .driver   = "virtio-blk-pci",
1142 ab73ff29 Gerd Hoffmann
            .property = "class",
1143 ab73ff29 Gerd Hoffmann
            .value    = stringify(PCI_CLASS_STORAGE_OTHER),
1144 d6beee99 Gerd Hoffmann
        },{
1145 98b19252 Amit Shah
            .driver   = "virtio-serial-pci",
1146 d6beee99 Gerd Hoffmann
            .property = "class",
1147 d6beee99 Gerd Hoffmann
            .value    = stringify(PCI_CLASS_DISPLAY_OTHER),
1148 a1e0fea5 Gerd Hoffmann
        },{
1149 8bfbde6d Amit Shah
            .driver   = "virtio-serial-pci",
1150 8bfbde6d Amit Shah
            .property = "max_nr_ports",
1151 8bfbde6d Amit Shah
            .value    = stringify(1),
1152 8bfbde6d Amit Shah
        },{
1153 8bfbde6d Amit Shah
            .driver   = "virtio-serial-pci",
1154 8bfbde6d Amit Shah
            .property = "vectors",
1155 8bfbde6d Amit Shah
            .value    = stringify(0),
1156 8bfbde6d Amit Shah
        },{
1157 a1e0fea5 Gerd Hoffmann
            .driver   = "virtio-net-pci",
1158 a1e0fea5 Gerd Hoffmann
            .property = "vectors",
1159 a1e0fea5 Gerd Hoffmann
            .value    = stringify(0),
1160 177539e0 Gerd Hoffmann
        },{
1161 177539e0 Gerd Hoffmann
            .driver   = "virtio-blk-pci",
1162 177539e0 Gerd Hoffmann
            .property = "vectors",
1163 177539e0 Gerd Hoffmann
            .value    = stringify(0),
1164 20a86364 Gerd Hoffmann
        },{
1165 374ef704 Gerd Hoffmann
            .driver   = "ide-drive",
1166 374ef704 Gerd Hoffmann
            .property = "ver",
1167 374ef704 Gerd Hoffmann
            .value    = "0.10",
1168 374ef704 Gerd Hoffmann
        },{
1169 374ef704 Gerd Hoffmann
            .driver   = "scsi-disk",
1170 374ef704 Gerd Hoffmann
            .property = "ver",
1171 374ef704 Gerd Hoffmann
            .value    = "0.10",
1172 374ef704 Gerd Hoffmann
        },{
1173 20a86364 Gerd Hoffmann
            .driver   = "PCI",
1174 20a86364 Gerd Hoffmann
            .property = "rombar",
1175 20a86364 Gerd Hoffmann
            .value    = stringify(0),
1176 ab73ff29 Gerd Hoffmann
        },
1177 96cc1810 Gerd Hoffmann
        { /* end of list */ }
1178 96cc1810 Gerd Hoffmann
    },
1179 96cc1810 Gerd Hoffmann
};
1180 96cc1810 Gerd Hoffmann
1181 f80f9ec9 Anthony Liguori
static QEMUMachine isapc_machine = {
1182 a245f2e7 aurel32
    .name = "isapc",
1183 a245f2e7 aurel32
    .desc = "ISA-only PC",
1184 a245f2e7 aurel32
    .init = pc_init_isa,
1185 b2097003 aliguori
    .max_cpus = 1,
1186 b5ff2d6e bellard
};
1187 f80f9ec9 Anthony Liguori
1188 f80f9ec9 Anthony Liguori
static void pc_machine_init(void)
1189 f80f9ec9 Anthony Liguori
{
1190 f80f9ec9 Anthony Liguori
    qemu_register_machine(&pc_machine);
1191 d76fa62d Amit Shah
    qemu_register_machine(&pc_machine_v0_12);
1192 2cae6f5e Gerd Hoffmann
    qemu_register_machine(&pc_machine_v0_11);
1193 96cc1810 Gerd Hoffmann
    qemu_register_machine(&pc_machine_v0_10);
1194 f80f9ec9 Anthony Liguori
    qemu_register_machine(&isapc_machine);
1195 f80f9ec9 Anthony Liguori
}
1196 f80f9ec9 Anthony Liguori
1197 f80f9ec9 Anthony Liguori
machine_init(pc_machine_init);