bootapp.h 6.98 KB
Newer Older
longpanda's avatar
longpanda committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#ifndef _BOOTAPP_H
#define _BOOTAPP_H

/*
 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

/**
 * @file
 *
 * Boot application data structures
 *
 */

#include <stdint.h>

/** A segment:offset address */
struct segoff {
	/** Offset */
	uint16_t offset;
	/** Segment */
	uint16_t segment;
} __attribute__ (( packed ));

/** A GUID */
struct guid {
	/** 8 hex digits, big-endian */
	uint32_t a;
	/** 2 hex digits, big-endian */
	uint16_t b;
	/** 2 hex digits, big-endian */
	uint16_t c;
	/** 2 hex digits, big-endian */
	uint16_t d;
	/** 12 hex digits, big-endian */
	uint8_t e[6];
} __attribute__ (( packed ));

/** Real-mode callback parameters */
struct bootapp_callback_params {
	/** Vector */
	union {
		/** Interrupt number */
		uint32_t interrupt;
		/** Segment:offset address of real-mode function */
		struct segoff function;
	} vector;
	/** %eax value */
	union {
		struct {
			uint8_t al;
			uint8_t ah;
		} __attribute__ (( packed ));
		uint16_t ax;
		uint32_t eax;
	};
	/** %ebx value */
	union {
		struct {
			uint8_t bl;
			uint8_t bh;
		} __attribute__ (( packed ));
		uint16_t bx;
		uint32_t ebx;
	};
	/** %ecx value */
	union {
		struct {
			uint8_t cl;
			uint8_t ch;
		} __attribute__ (( packed ));
		uint16_t cx;
		uint32_t ecx;
	};
	/** %edx value */
	union {
		struct {
			uint8_t dl;
			uint8_t dh;
		} __attribute__ (( packed ));
		uint16_t dx;
		uint32_t edx;
	};
	/** Placeholder (for %esp?) */
	uint32_t unused_esp;
	/** Placeholder (for %ebp?) */
	uint32_t unused_ebp;
	/** %esi value */
	union {
		uint16_t si;
		uint32_t esi;
	};
	/** %edi value */
	union {
		uint16_t di;
		uint32_t edi;
	};
	/** Placeholder (for %cs?) */
	uint32_t unused_cs;
	/** %ds value */
	uint32_t ds;
	/** Placeholder (for %ss?) */
	uint32_t unused_ss;
	/** %es value */
	uint32_t es;
	/** %fs value */
	uint32_t fs;
	/** %gs value */
	uint32_t gs;
	/** eflags value */
	uint32_t eflags;
} __attribute__ (( packed ));

/** eflags bits */
enum eflags {
	CF = ( 1 << 0 ),
	PF = ( 1 << 2 ),
	AF = ( 1 << 4 ),
	ZF = ( 1 << 6 ),
	SF = ( 1 << 7 ),
	OF = ( 1 << 11 ),
};

/** Real-mode callback function table */
struct bootapp_callback_functions {
	/**
	 * Call an arbitrary real-mode interrupt
	 *
	 * @v params		Parameters
	 */
	void ( * call_interrupt ) ( struct bootapp_callback_params *params );
	/**
	 * Call an arbitrary real-mode function
	 *
	 * @v params		Parameters
	 */
	void ( * call_real ) ( struct bootapp_callback_params *params );
} __attribute__ (( packed ));

/** Real-mode callbacks */
struct bootapp_callback {
	/** Real-mode callback function table */
	struct bootapp_callback_functions *fns;
	/** Drive number for INT13 calls */
	uint32_t drive;
} __attribute__ (( packed ));

/** Boot application descriptor */
struct bootapp_descriptor {
	/** Signature */
	char signature[8];
	/** Version */
	uint32_t version;
	/** Total length */
	uint32_t len;
	/** COFF machine type */
	uint32_t arch;
	/** Reserved */
	uint32_t reserved_0x14;
	/** Loaded PE image base address */
	void *pe_base;
	/** Reserved */
	uint32_t reserved_0x1c;
	/** Length of loaded PE image */
	uint32_t pe_len;
	/** Offset to memory descriptor */
	uint32_t memory;
	/** Offset to boot application entry descriptor */
	uint32_t entry;
	/** Offset to ??? */
	uint32_t xxx;
	/** Offset to callback descriptor */
	uint32_t callback;
	/** Offset to pointless descriptor */
	uint32_t pointless;
	/** Reserved */
	uint32_t reserved_0x38;
} __attribute__ (( packed ));

/** "BOOT APP" magic signature */
#define BOOTAPP_SIGNATURE "BOOT APP"

/** Boot application descriptor version */
#define BOOTAPP_VERSION 2

/** i386 architecture */
#define BOOTAPP_ARCH_I386 0x014c

/** Memory region descriptor */
struct bootapp_memory_region {
	/** Reserved (for struct list_head?) */
	uint8_t reserved[8];
	/** Start page address */
	uint64_t start_page;
	/** Reserved */
	uint8_t reserved_0x10[8];
	/** Number of pages */
	uint64_t num_pages;
	/** Reserved */
	uint8_t reserved_0x20[4];
	/** Flags */
	uint32_t flags;
} __attribute__ (( packed ));

/** Memory descriptor */
struct bootapp_memory_descriptor {
	/** Version */
	uint32_t version;
	/** Length of descriptor (excluding region descriptors) */
	uint32_t len;
	/** Number of regions */
	uint32_t num_regions;
	/** Length of each region descriptor */
	uint32_t region_len;
	/** Length of reserved area at start of each region descriptor */
	uint32_t reserved_len;
} __attribute__ (( packed ));

/** Boot application memory descriptor version */
#define BOOTAPP_MEMORY_VERSION 1

/** Boot application entry descriptor */
struct bootapp_entry_descriptor {
	/** Signature */
	char signature[8];
	/** Flags */
	uint32_t flags;
	/** GUID */
	struct guid guid;
	/** Reserved */
	uint8_t reserved[16];
} __attribute__ (( packed ));

/** ??? */
struct bootapp_entry_wtf1_descriptor {
	/** Flags */
	uint32_t flags;
	/** Length of descriptor */
	uint32_t len;
	/** Total length of following descriptors within BTAPENT */
	uint32_t extra_len;
	/** Reserved */
	uint8_t reserved[12];
} __attribute__ (( packed ));

/** ??? */
struct bootapp_entry_wtf2_descriptor {
	/** GUID */
	struct guid guid;
} __attribute__ (( packed ));

/** ??? */
struct bootapp_entry_wtf3_descriptor {
	/** Flags */
	uint32_t flags;
	/** Reserved */
	uint32_t reserved_0x04;
	/** Length of descriptor */
	uint32_t len;
	/** Reserved */
	uint32_t reserved_0x0c;
	/** Boot partition offset (in bytes) */
	uint32_t boot_partition_offset;
	/** Reserved */
	uint8_t reserved_0x14[16];
	/** MBR signature present? */
	uint32_t xxx;
	/** MBR signature */
	uint32_t mbr_signature;
	/** Reserved */
	uint8_t reserved_0x2c[26];
} __attribute__ (( packed ));

/** "BTAPENT" magic signature */
#define BOOTAPP_ENTRY_SIGNATURE "BTAPENT\0"

/** Boot application entry flags
 *
 * pxeboot, etftboot, and fatboot all use a value of 0x21; I have no
 * idea what it means.
 */
#define BOOTAPP_ENTRY_FLAGS 0x21

/** Boot application callback descriptor */
struct bootapp_callback_descriptor {
	/** Real-mode callbacks */
	struct bootapp_callback *callback;
	/** Reserved */
	uint32_t reserved;
} __attribute__ (( packed ));

/** Boot application pointless descriptor */
struct bootapp_pointless_descriptor {
	/** Version */
	uint32_t version;
	/** Reserved */
	uint8_t reserved[24];
} __attribute__ (( packed ));

/** Boot application pointless descriptor version */
#define BOOTAPP_POINTLESS_VERSION 1

#endif /* _BOOTAPP_H */