Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / seabios / src / pnpbios.c
1 // PNP BIOS calls
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
6
7 #include "config.h" // BUILD_BIOS_ADDR
8 #include "farptr.h" // SET_FARVAR
9 #include "output.h" // dprintf
10 #include "std/pnpbios.h" // PNP_SIGNATURE
11 #include "string.h" // checksum
12 #include "util.h" // pnp_init
13
14 extern struct pnpheader PNPHEADER;
15 extern char pnp_string[];
16
17 #if CONFIG_PNPBIOS
18 struct pnpheader PNPHEADER __aligned(16) VARFSEG = {
19     .signature = PNP_SIGNATURE,
20     .version = 0x10,
21     .length = sizeof(PNPHEADER),
22     .real_cs = SEG_BIOS,
23     .prot_base = BUILD_BIOS_ADDR,
24     .real_ds = SEG_BIOS,
25     .prot_database = BUILD_BIOS_ADDR,
26 };
27 #else
28 // We need a copy of this string in the 0xf000 segment, but we are not
29 // actually a PnP BIOS, so make sure it is *not* aligned, so OSes will
30 // not see it if they scan.
31 char pnp_string[] __aligned(2) VARFSEG = " $PnP";
32 #endif
33
34 // BBS - Get Version and Installation Check
35 static u16
36 handle_pnp60(u16 *args)
37 {
38     u16 version_ptr = args[1];
39     u16 version_seg = args[2];
40     SET_FARVAR(version_seg, *(u16*)(version_ptr+0), 0x0101);
41     return 0;
42 }
43
44 static u16
45 handle_pnpXX(u16 *args)
46 {
47     return FUNCTION_NOT_SUPPORTED;
48 }
49
50 u16 VISIBLE16
51 handle_pnp(u16 *args)
52 {
53     if (! CONFIG_PNPBIOS)
54         return FUNCTION_NOT_SUPPORTED;
55
56     u16 arg1 = args[0];
57     dprintf(DEBUG_HDL_pnp, "pnp call arg1=%x\n", arg1);
58
59     switch (arg1) {
60     case 0x60: return handle_pnp60(args);
61     default:   return handle_pnpXX(args);
62     }
63 }
64
65 u16
66 get_pnp_offset(void)
67 {
68     if (! CONFIG_PNPBIOS)
69         return (u32)pnp_string + 1 - BUILD_BIOS_ADDR;
70     return (u32)&PNPHEADER - BUILD_BIOS_ADDR;
71 }
72
73 // romlayout.S
74 extern void entry_pnp_real(void);
75 extern void entry_pnp_prot(void);
76
77 void
78 pnp_init(void)
79 {
80     if (! CONFIG_PNPBIOS)
81         return;
82
83     dprintf(3, "init PNPBIOS table\n");
84
85     PNPHEADER.real_ip = (u32)entry_pnp_real - BUILD_BIOS_ADDR;
86     PNPHEADER.prot_ip = (u32)entry_pnp_prot - BUILD_BIOS_ADDR;
87     PNPHEADER.checksum -= checksum(&PNPHEADER, sizeof(PNPHEADER));
88 }