]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/bootapp.h
1.1.07 release
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / bootapp.h
1 #ifndef _BOOTAPP_H
2 #define _BOOTAPP_H
3
4 /*
5 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23 /**
24 * @file
25 *
26 * Boot application data structures
27 *
28 */
29
30 #include <stdint.h>
31
32 /** A segment:offset address */
33 struct segoff {
34 /** Offset */
35 uint16_t offset;
36 /** Segment */
37 uint16_t segment;
38 } __attribute__ (( packed ));
39
40 /** A GUID */
41 struct guid {
42 /** 8 hex digits, big-endian */
43 uint32_t a;
44 /** 2 hex digits, big-endian */
45 uint16_t b;
46 /** 2 hex digits, big-endian */
47 uint16_t c;
48 /** 2 hex digits, big-endian */
49 uint16_t d;
50 /** 12 hex digits, big-endian */
51 uint8_t e[6];
52 } __attribute__ (( packed ));
53
54 /** Real-mode callback parameters */
55 struct bootapp_callback_params {
56 /** Vector */
57 union {
58 /** Interrupt number */
59 uint32_t interrupt;
60 /** Segment:offset address of real-mode function */
61 struct segoff function;
62 } vector;
63 /** %eax value */
64 union {
65 struct {
66 uint8_t al;
67 uint8_t ah;
68 } __attribute__ (( packed ));
69 uint16_t ax;
70 uint32_t eax;
71 };
72 /** %ebx value */
73 union {
74 struct {
75 uint8_t bl;
76 uint8_t bh;
77 } __attribute__ (( packed ));
78 uint16_t bx;
79 uint32_t ebx;
80 };
81 /** %ecx value */
82 union {
83 struct {
84 uint8_t cl;
85 uint8_t ch;
86 } __attribute__ (( packed ));
87 uint16_t cx;
88 uint32_t ecx;
89 };
90 /** %edx value */
91 union {
92 struct {
93 uint8_t dl;
94 uint8_t dh;
95 } __attribute__ (( packed ));
96 uint16_t dx;
97 uint32_t edx;
98 };
99 /** Placeholder (for %esp?) */
100 uint32_t unused_esp;
101 /** Placeholder (for %ebp?) */
102 uint32_t unused_ebp;
103 /** %esi value */
104 union {
105 uint16_t si;
106 uint32_t esi;
107 };
108 /** %edi value */
109 union {
110 uint16_t di;
111 uint32_t edi;
112 };
113 /** Placeholder (for %cs?) */
114 uint32_t unused_cs;
115 /** %ds value */
116 uint32_t ds;
117 /** Placeholder (for %ss?) */
118 uint32_t unused_ss;
119 /** %es value */
120 uint32_t es;
121 /** %fs value */
122 uint32_t fs;
123 /** %gs value */
124 uint32_t gs;
125 /** eflags value */
126 uint32_t eflags;
127 } __attribute__ (( packed ));
128
129 /** eflags bits */
130 enum eflags {
131 CF = ( 1 << 0 ),
132 PF = ( 1 << 2 ),
133 AF = ( 1 << 4 ),
134 ZF = ( 1 << 6 ),
135 SF = ( 1 << 7 ),
136 OF = ( 1 << 11 ),
137 };
138
139 /** Real-mode callback function table */
140 struct bootapp_callback_functions {
141 /**
142 * Call an arbitrary real-mode interrupt
143 *
144 * @v params Parameters
145 */
146 void ( * call_interrupt ) ( struct bootapp_callback_params *params );
147 /**
148 * Call an arbitrary real-mode function
149 *
150 * @v params Parameters
151 */
152 void ( * call_real ) ( struct bootapp_callback_params *params );
153 } __attribute__ (( packed ));
154
155 /** Real-mode callbacks */
156 struct bootapp_callback {
157 /** Real-mode callback function table */
158 struct bootapp_callback_functions *fns;
159 /** Drive number for INT13 calls */
160 uint32_t drive;
161 } __attribute__ (( packed ));
162
163 /** Boot application descriptor */
164 struct bootapp_descriptor {
165 /** Signature */
166 char signature[8];
167 /** Version */
168 uint32_t version;
169 /** Total length */
170 uint32_t len;
171 /** COFF machine type */
172 uint32_t arch;
173 /** Reserved */
174 uint32_t reserved_0x14;
175 /** Loaded PE image base address */
176 void *pe_base;
177 /** Reserved */
178 uint32_t reserved_0x1c;
179 /** Length of loaded PE image */
180 uint32_t pe_len;
181 /** Offset to memory descriptor */
182 uint32_t memory;
183 /** Offset to boot application entry descriptor */
184 uint32_t entry;
185 /** Offset to ??? */
186 uint32_t xxx;
187 /** Offset to callback descriptor */
188 uint32_t callback;
189 /** Offset to pointless descriptor */
190 uint32_t pointless;
191 /** Reserved */
192 uint32_t reserved_0x38;
193 } __attribute__ (( packed ));
194
195 /** "BOOT APP" magic signature */
196 #define BOOTAPP_SIGNATURE "BOOT APP"
197
198 /** Boot application descriptor version */
199 #define BOOTAPP_VERSION 2
200
201 /** i386 architecture */
202 #define BOOTAPP_ARCH_I386 0x014c
203
204 /** Memory region descriptor */
205 struct bootapp_memory_region {
206 /** Reserved (for struct list_head?) */
207 uint8_t reserved[8];
208 /** Start page address */
209 uint64_t start_page;
210 /** Reserved */
211 uint8_t reserved_0x10[8];
212 /** Number of pages */
213 uint64_t num_pages;
214 /** Reserved */
215 uint8_t reserved_0x20[4];
216 /** Flags */
217 uint32_t flags;
218 } __attribute__ (( packed ));
219
220 /** Memory descriptor */
221 struct bootapp_memory_descriptor {
222 /** Version */
223 uint32_t version;
224 /** Length of descriptor (excluding region descriptors) */
225 uint32_t len;
226 /** Number of regions */
227 uint32_t num_regions;
228 /** Length of each region descriptor */
229 uint32_t region_len;
230 /** Length of reserved area at start of each region descriptor */
231 uint32_t reserved_len;
232 } __attribute__ (( packed ));
233
234 /** Boot application memory descriptor version */
235 #define BOOTAPP_MEMORY_VERSION 1
236
237 /** Boot application entry descriptor */
238 struct bootapp_entry_descriptor {
239 /** Signature */
240 char signature[8];
241 /** Flags */
242 uint32_t flags;
243 /** GUID */
244 struct guid guid;
245 /** Reserved */
246 uint8_t reserved[16];
247 } __attribute__ (( packed ));
248
249 /** ??? */
250 struct bootapp_entry_wtf1_descriptor {
251 /** Flags */
252 uint32_t flags;
253 /** Length of descriptor */
254 uint32_t len;
255 /** Total length of following descriptors within BTAPENT */
256 uint32_t extra_len;
257 /** Reserved */
258 uint8_t reserved[12];
259 } __attribute__ (( packed ));
260
261 /** ??? */
262 struct bootapp_entry_wtf2_descriptor {
263 /** GUID */
264 struct guid guid;
265 } __attribute__ (( packed ));
266
267 /** ??? */
268 struct bootapp_entry_wtf3_descriptor {
269 /** Flags */
270 uint32_t flags;
271 /** Reserved */
272 uint32_t reserved_0x04;
273 /** Length of descriptor */
274 uint32_t len;
275 /** Reserved */
276 uint32_t reserved_0x0c;
277 /** Boot partition offset (in bytes) */
278 uint32_t boot_partition_offset;
279 /** Reserved */
280 uint8_t reserved_0x14[16];
281 /** MBR signature present? */
282 uint32_t xxx;
283 /** MBR signature */
284 uint32_t mbr_signature;
285 /** Reserved */
286 uint8_t reserved_0x2c[26];
287 } __attribute__ (( packed ));
288
289 /** "BTAPENT" magic signature */
290 #define BOOTAPP_ENTRY_SIGNATURE "BTAPENT\0"
291
292 /** Boot application entry flags
293 *
294 * pxeboot, etftboot, and fatboot all use a value of 0x21; I have no
295 * idea what it means.
296 */
297 #define BOOTAPP_ENTRY_FLAGS 0x21
298
299 /** Boot application callback descriptor */
300 struct bootapp_callback_descriptor {
301 /** Real-mode callbacks */
302 struct bootapp_callback *callback;
303 /** Reserved */
304 uint32_t reserved;
305 } __attribute__ (( packed ));
306
307 /** Boot application pointless descriptor */
308 struct bootapp_pointless_descriptor {
309 /** Version */
310 uint32_t version;
311 /** Reserved */
312 uint8_t reserved[24];
313 } __attribute__ (( packed ));
314
315 /** Boot application pointless descriptor version */
316 #define BOOTAPP_POINTLESS_VERSION 1
317
318 #endif /* _BOOTAPP_H */