[FREELDR] Several changes regarding chainloading and Linux boot.
[reactos.git] / boot / freeldr / freeldr / include / arch / pc / pcbios.h
1 #ifndef _PCBIOS_H_
2 #define _PCBIOS_H_
3
4 #ifdef __ASM__
5 #define EFLAGS_CF HEX(01)
6 #define EFLAGS_ZF HEX(40)
7 #define EFLAGS_SF HEX(80)
8 #endif
9
10 #ifndef __ASM__
11
12 #define MAX_BIOS_DESCRIPTORS 80
13
14 typedef enum
15 {
16 // ACPI 1.0.
17 BiosMemoryUsable = 1,
18 BiosMemoryReserved = 2,
19 BiosMemoryAcpiReclaim = 3,
20 BiosMemoryAcpiNvs = 4,
21 // ACPI 3.0.
22 BiosMemoryUnusable = 5,
23 // ACPI 4.0.
24 BiosMemoryDisabled = 6,
25 // ACPI 6.0.
26 BiosMemoryPersistent = 7,
27 BiosMemoryUndefined08 = 8,
28 BiosMemoryUndefined09 = 9,
29 BiosMemoryUndefined10 = 10,
30 BiosMemoryUndefined11 = 11,
31 BiosMemoryOemDefined12 = 12
32 // BiosMemoryUndefinedNN = 13-0xEFFFFFFF
33 // BiosMemoryOemDefinedNN = 0xF0000000-0xFFFFFFFF
34 } BIOS_MEMORY_TYPE;
35
36 typedef struct
37 {
38 // ACPI 1.0.
39 ULONGLONG BaseAddress;
40 ULONGLONG Length;
41 ULONG Type;
42 // ACPI 3.0.
43 union
44 {
45 ULONG ExtendedAttributesAsULONG;
46
47 struct
48 {
49 // Bit 0. ACPI 3.0. As of ACPI 4.0, became "Reserved -> must be 1".
50 ULONG Enabled_Reserved : 1;
51 // Bit 1. ACPI 3.0. As of ACPI 6.1, became "Unimplemented -> Deprecated".
52 ULONG NonVolatile_Deprecated : 1;
53 // Bit 2. ACPI 4.0. As of ACPI 6.1, became "Unimplemented -> Deprecated".
54 ULONG SlowAccess_Deprecated : 1;
55 // Bit 3. ACPI 4.0. ACPI 5.0-A added "Used only on PC-AT BIOS" (not UEFI).
56 ULONG ErrorLog : 1;
57 // Bits 4-31. ACPI 3.0.
58 ULONG Reserved : 28;
59 } ExtendedAttributes;
60 };
61 } BIOS_MEMORY_MAP, *PBIOS_MEMORY_MAP;
62
63 /* Int 15h AX=E820h Entry minimal size. */
64 C_ASSERT(FIELD_OFFSET(BIOS_MEMORY_MAP, ExtendedAttributes) == 20);
65 /* Int 15h AX=E820h Entry maximal size. */
66 C_ASSERT(sizeof(BIOS_MEMORY_MAP) == 24);
67
68 /* FIXME: Should be moved to NDK, and respective ACPI header files */
69 typedef struct _ACPI_BIOS_DATA
70 {
71 PHYSICAL_ADDRESS RSDTAddress;
72 ULONGLONG Count;
73 BIOS_MEMORY_MAP MemoryMap[1]; /* Count of BIOS memory map entries */
74 } ACPI_BIOS_DATA, *PACPI_BIOS_DATA;
75
76 #include <pshpack1.h>
77 typedef struct
78 {
79 unsigned long eax;
80 unsigned long ebx;
81 unsigned long ecx;
82 unsigned long edx;
83
84 unsigned long esi;
85 unsigned long edi;
86 unsigned long ebp;
87
88 unsigned short ds;
89 unsigned short es;
90 unsigned short fs;
91 unsigned short gs;
92
93 unsigned long eflags;
94
95 } DWORDREGS;
96
97 typedef struct
98 {
99 unsigned short ax, _upper_ax;
100 unsigned short bx, _upper_bx;
101 unsigned short cx, _upper_cx;
102 unsigned short dx, _upper_dx;
103
104 unsigned short si, _upper_si;
105 unsigned short di, _upper_di;
106 unsigned short bp, _upper_bp;
107
108 unsigned short ds;
109 unsigned short es;
110 unsigned short fs;
111 unsigned short gs;
112
113 unsigned short flags, _upper_flags;
114
115 } WORDREGS;
116
117 typedef struct
118 {
119 unsigned char al;
120 unsigned char ah;
121 unsigned short _upper_ax;
122 unsigned char bl;
123 unsigned char bh;
124 unsigned short _upper_bx;
125 unsigned char cl;
126 unsigned char ch;
127 unsigned short _upper_cx;
128 unsigned char dl;
129 unsigned char dh;
130 unsigned short _upper_dx;
131
132 unsigned short si, _upper_si;
133 unsigned short di, _upper_di;
134 unsigned short bp, _upper_bp;
135
136 unsigned short ds;
137 unsigned short es;
138 unsigned short fs;
139 unsigned short gs;
140
141 unsigned short flags, _upper_flags;
142
143 } BYTEREGS;
144
145
146 typedef union
147 {
148 DWORDREGS x;
149 DWORDREGS d;
150 WORDREGS w;
151 BYTEREGS b;
152 } REGS;
153 #include <poppack.h>
154
155 // Int386()
156 //
157 // Real mode interrupt vector interface
158 //
159 // (E)FLAGS can *only* be returned by this function, not set.
160 // Make sure all memory pointers are in SEG:OFFS format and
161 // not linear addresses, unless the interrupt handler
162 // specifically handles linear addresses.
163 int __cdecl Int386(int ivec, REGS* in, REGS* out);
164
165 // This macro tests the Carry Flag
166 // If CF is set then the call failed (usually)
167 #define INT386_SUCCESS(regs) ((regs.x.eflags & EFLAGS_CF) == 0)
168
169 VOID __cdecl ChainLoadBiosBootSectorCode(
170 IN UCHAR BootDrive OPTIONAL,
171 IN ULONG BootPartition OPTIONAL);
172
173 VOID __cdecl Relocator16Boot(
174 IN REGS* In,
175 IN USHORT StackSegment,
176 IN USHORT StackPointer,
177 IN USHORT CodeSegment,
178 IN USHORT CodePointer);
179
180 VOID __cdecl Reboot(VOID);
181 VOID DetectHardware(VOID);
182
183 #endif /* ! __ASM__ */
184
185 /* Layout of the REGS structure */
186 #define REGS_EAX 0
187 #define REGS_EBX 4
188 #define REGS_ECX 8
189 #define REGS_EDX 12
190 #define REGS_ESI 16
191 #define REGS_EDI 20
192 #define REGS_EBP 24
193 #define REGS_DS 28
194 #define REGS_ES 30
195 #define REGS_FS 32
196 #define REGS_GS 34
197 #define REGS_EFLAGS 36
198 #define REGS_SIZE 40
199
200 #endif /* _PCBIOS_H_ */