xref: /illumos-gate/usr/src/uts/common/sys/multiboot2.h (revision 5731521745dc11ccaf7d72311f428d64dd49727e)
1 /*
2  * Copyright (C) 1999,2003,2007,2008,2009,2010  Free Software Foundation, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL ANY
17  * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
19  * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  */
21 
22 /*
23  * Copyright 2016 Toomas Soome <tsoome@me.com>
24  */
25 
26 /*
27  * This header contains definitions for Multiboot 2 boot protocol, based on
28  * the reference implementation by grub 2.
29  *
30  * At the time this was written (Jan 2017), the Multiboot 2 documentation is in
31  * process of being rewritten and the information in the specification is not
32  * entirely correct. Instead, you must rely on grub 2 source code.
33  *
34  * This header provides essential support for the Multiboot 2 specification
35  * for illumos and makes it possible to pass the needed structures from the
36  * boot loader to the kernel.
37  */
38 
39 #ifndef	_SYS_MULTIBOOT2_H
40 #define	_SYS_MULTIBOOT2_H
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /* How many bytes from the start of the file we search for the header.  */
47 #define	MULTIBOOT_SEARCH			32768
48 #define	MULTIBOOT_HEADER_ALIGN			8
49 
50 /* The magic field should contain this.  */
51 #define	MULTIBOOT2_HEADER_MAGIC			0xe85250d6
52 
53 /* This should be in %eax.  */
54 #define	MULTIBOOT2_BOOTLOADER_MAGIC		0x36d76289
55 
56 /* Alignment of multiboot modules.  */
57 #define	MULTIBOOT_MOD_ALIGN			0x00001000
58 
59 /* Alignment of the multiboot info structure.  */
60 #define	MULTIBOOT_INFO_ALIGN			0x00000008
61 
62 /* Flags set in the 'flags' member of the multiboot header.  */
63 
64 #define	MULTIBOOT_TAG_ALIGN			8
65 #define	MULTIBOOT_TAG_TYPE_END			0
66 #define	MULTIBOOT_TAG_TYPE_CMDLINE		1
67 #define	MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME	2
68 #define	MULTIBOOT_TAG_TYPE_MODULE		3
69 #define	MULTIBOOT_TAG_TYPE_BASIC_MEMINFO	4
70 #define	MULTIBOOT_TAG_TYPE_BOOTDEV		5
71 #define	MULTIBOOT_TAG_TYPE_MMAP			6
72 #define	MULTIBOOT_TAG_TYPE_VBE			7
73 #define	MULTIBOOT_TAG_TYPE_FRAMEBUFFER		8
74 #define	MULTIBOOT_TAG_TYPE_ELF_SECTIONS		9
75 #define	MULTIBOOT_TAG_TYPE_APM			10
76 #define	MULTIBOOT_TAG_TYPE_EFI32		11
77 #define	MULTIBOOT_TAG_TYPE_EFI64		12
78 #define	MULTIBOOT_TAG_TYPE_SMBIOS		13
79 #define	MULTIBOOT_TAG_TYPE_ACPI_OLD		14
80 #define	MULTIBOOT_TAG_TYPE_ACPI_NEW		15
81 #define	MULTIBOOT_TAG_TYPE_NETWORK		16
82 #define	MULTIBOOT_TAG_TYPE_EFI_MMAP		17
83 #define	MULTIBOOT_TAG_TYPE_EFI_BS		18
84 #define	MULTIBOOT_TAG_TYPE_EFI32_IH		19
85 #define	MULTIBOOT_TAG_TYPE_EFI64_IH		20
86 #define	MULTIBOOT_TAG_TYPE_LOAD_BASE_ADDR	21
87 
88 #define	MULTIBOOT_HEADER_TAG_END			0
89 #define	MULTIBOOT_HEADER_TAG_INFORMATION_REQUEST	1
90 #define	MULTIBOOT_HEADER_TAG_ADDRESS			2
91 #define	MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS		3
92 #define	MULTIBOOT_HEADER_TAG_CONSOLE_FLAGS		4
93 #define	MULTIBOOT_HEADER_TAG_FRAMEBUFFER		5
94 #define	MULTIBOOT_HEADER_TAG_MODULE_ALIGN		6
95 #define	MULTIBOOT_HEADER_TAG_EFI_BS			7
96 #define	MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI32	8
97 #define	MULTIBOOT_HEADER_TAG_ENTRY_ADDRESS_EFI64	9
98 #define	MULTIBOOT_HEADER_TAG_RELOCATABLE		10
99 
100 #define	MULTIBOOT_ARCHITECTURE_I386	0
101 #define	MULTIBOOT_ARCHITECTURE_MIPS32	4
102 #define	MULTIBOOT_HEADER_TAG_OPTIONAL	1
103 
104 /* Hints for relocatable kernel load preference */
105 #define	MULTIBOOT_LOAD_PREFERENCE_NONE	0
106 #define	MULTIBOOT_LOAD_PREFERENCE_LOW	1
107 #define	MULTIBOOT_LOAD_PREFERENCE_HIGH	2
108 
109 /* Values for console_flags field in tag multiboot_header_tag_console_flags. */
110 #define	MULTIBOOT_CONSOLE_FLAGS_CONSOLE_REQUIRED	1
111 #define	MULTIBOOT_CONSOLE_FLAGS_EGA_TEXT_SUPPORTED	2
112 
113 #ifndef _ASM
114 
115 #include <sys/stdint.h>
116 
117 #pragma pack(1)
118 
119 typedef struct multiboot_header_tag {
120 	uint16_t mbh_type;
121 	uint16_t mbh_flags;
122 	uint32_t mbh_size;
123 } multiboot_header_tag_t;
124 
125 typedef struct multiboot2_header {
126 	/* Must be MULTIBOOT2_MAGIC - see above.  */
127 	uint32_t mb2_magic;
128 
129 	/* ISA */
130 	uint32_t mb2_architecture;
131 
132 	/* Total header length.  */
133 	uint32_t mb2_header_length;
134 
135 	/* The above fields plus this one must equal 0 mod 2^32. */
136 	uint32_t mb2_checksum;
137 	multiboot_header_tag_t mb2_tags[];
138 } multiboot2_header_t;
139 
140 typedef struct multiboot_header_tag_information_request {
141 	uint16_t mbh_type;
142 	uint16_t mbh_flags;
143 	uint32_t mbh_size;
144 	uint32_t mbh_requests[];
145 } multiboot_header_tag_information_request_t;
146 
147 typedef struct multiboot_header_tag_address {
148 	uint16_t mbh_type;
149 	uint16_t mbh_flags;
150 	uint32_t mbh_size;
151 	uint32_t mbh_header_addr;
152 	uint32_t mbh_load_addr;
153 	uint32_t mbh_load_end_addr;
154 	uint32_t mbh_bss_end_addr;
155 } multiboot_header_tag_address_t;
156 
157 typedef struct multiboot_header_tag_entry_address {
158 	uint16_t mbh_type;
159 	uint16_t mbh_flags;
160 	uint32_t mbh_size;
161 	uint32_t mbh_entry_addr;
162 } multiboot_header_tag_entry_address_t;
163 
164 typedef struct multiboot_header_tag_console_flags {
165 	uint16_t mbh_type;
166 	uint16_t mbh_flags;
167 	uint32_t mbh_size;
168 	uint32_t mbh_console_flags;
169 } multiboot_header_tag_console_flags_t;
170 
171 typedef struct multiboot_header_tag_framebuffer {
172 	uint16_t mbh_type;
173 	uint16_t mbh_flags;
174 	uint32_t mbh_size;
175 	uint32_t mbh_width;
176 	uint32_t mbh_height;
177 	uint32_t mbh_depth;
178 } multiboot_header_tag_framebuffer_t;
179 
180 typedef struct multiboot_header_tag_module_align {
181 	uint16_t mbh_type;
182 	uint16_t mbh_flags;
183 	uint32_t mbh_size;
184 } multiboot_header_tag_module_align_t;
185 
186 typedef struct multiboot_header_tag_relocatable {
187 	uint16_t mbh_type;
188 	uint16_t mbh_flags;
189 	uint32_t mbh_size;
190 	uint32_t mbh_min_addr;
191 	uint32_t mbh_max_addr;
192 	uint32_t mbh_align;
193 	uint32_t mbh_preference;
194 } multiboot_header_tag_relocatable_t;
195 
196 typedef struct multiboot_color {
197 	uint8_t mb_red;
198 	uint8_t mb_green;
199 	uint8_t mb_blue;
200 } multiboot_color_t;
201 
202 typedef struct multiboot_mmap_entry {
203 	uint64_t mmap_addr;
204 	uint64_t mmap_len;
205 #define	MULTIBOOT_MEMORY_AVAILABLE		1
206 #define	MULTIBOOT_MEMORY_RESERVED		2
207 #define	MULTIBOOT_MEMORY_ACPI_RECLAIMABLE	3
208 #define	MULTIBOOT_MEMORY_NVS			4
209 #define	MULTIBOOT_MEMORY_BADRAM			5
210 	uint32_t mmap_type;
211 	uint32_t mmap_reserved;
212 } multiboot_mmap_entry_t;
213 
214 typedef struct multiboot_tag {
215 	uint32_t mb_type;
216 	uint32_t mb_size;
217 } multiboot_tag_t;
218 
219 typedef struct multiboot2_info_header {
220 	uint32_t mbi_total_size;
221 	uint32_t mbi_reserved;
222 	multiboot_tag_t mbi_tags[];
223 } multiboot2_info_header_t;
224 
225 typedef struct multiboot_tag_string {
226 	uint32_t mb_type;
227 	uint32_t mb_size;
228 	char mb_string[];
229 } multiboot_tag_string_t;
230 
231 typedef struct multiboot_tag_module {
232 	uint32_t mb_type;
233 	uint32_t mb_size;
234 	uint32_t mb_mod_start;
235 	uint32_t mb_mod_end;
236 	char mb_cmdline[];
237 } multiboot_tag_module_t;
238 
239 typedef struct multiboot_tag_basic_meminfo {
240 	uint32_t mb_type;
241 	uint32_t mb_size;
242 	uint32_t mb_mem_lower;
243 	uint32_t mb_mem_upper;
244 } multiboot_tag_basic_meminfo_t;
245 
246 typedef struct multiboot_tag_bootdev {
247 	uint32_t mb_type;
248 	uint32_t mb_size;
249 	uint32_t mb_biosdev;
250 	uint32_t mb_slice;
251 	uint32_t mb_part;
252 } multiboot_tag_bootdev_t;
253 
254 typedef struct multiboot_tag_mmap {
255 	uint32_t mb_type;
256 	uint32_t mb_size;
257 	uint32_t mb_entry_size;
258 	uint32_t mb_entry_version;
259 	uint8_t mb_entries[];
260 } multiboot_tag_mmap_t;
261 
262 struct multiboot_vbe_info_block {
263 	uint8_t vbe_external_specification[512];
264 };
265 
266 struct multiboot_vbe_mode_info_block {
267 	uint8_t vbe_external_specification[256];
268 };
269 
270 typedef struct multiboot_tag_vbe {
271 	uint32_t mb_type;
272 	uint32_t mb_size;
273 
274 	uint16_t vbe_mode;
275 	uint16_t vbe_interface_seg;
276 	uint16_t vbe_interface_off;
277 	uint16_t vbe_interface_len;
278 
279 	struct multiboot_vbe_info_block vbe_control_info;
280 	struct multiboot_vbe_mode_info_block vbe_mode_info;
281 } multiboot_tag_vbe_t;
282 
283 struct multiboot_tag_framebuffer_common {
284 	uint32_t mb_type;
285 	uint32_t mb_size;
286 
287 	uint64_t framebuffer_addr;
288 	uint32_t framebuffer_pitch;
289 	uint32_t framebuffer_width;
290 	uint32_t framebuffer_height;
291 	uint8_t framebuffer_bpp;
292 #define	MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED	0
293 #define	MULTIBOOT_FRAMEBUFFER_TYPE_RGB		1
294 #define	MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT	2
295 	uint8_t framebuffer_type;
296 	uint16_t mb_reserved;
297 };
298 
299 typedef struct multiboot_tag_framebuffer {
300 	struct multiboot_tag_framebuffer_common framebuffer_common;
301 
302 	union {
303 		struct {
304 			uint16_t framebuffer_palette_num_colors;
305 			multiboot_color_t framebuffer_palette[];
306 		} fb1;
307 		struct {
308 			uint8_t framebuffer_red_field_position;
309 			uint8_t framebuffer_red_mask_size;
310 			uint8_t framebuffer_green_field_position;
311 			uint8_t framebuffer_green_mask_size;
312 			uint8_t framebuffer_blue_field_position;
313 			uint8_t framebuffer_blue_mask_size;
314 		} fb2;
315 	} u;
316 } multiboot_tag_framebuffer_t;
317 
318 typedef struct multiboot_tag_elf_sections {
319 	uint32_t mb_type;
320 	uint32_t mb_size;
321 	uint32_t mb_num;
322 	uint32_t mb_entsize;
323 	uint32_t mb_shndx;
324 	char mb_sections[];
325 } multiboot_tag_elf_sections_t;
326 
327 typedef struct multiboot_tag_apm {
328 	uint32_t mb_type;
329 	uint32_t mb_size;
330 	uint16_t mb_version;
331 	uint16_t mb_cseg;
332 	uint32_t mb_offset;
333 	uint16_t mb_cseg_16;
334 	uint16_t mb_dseg;
335 	uint16_t mb_flags;
336 	uint16_t mb_cseg_len;
337 	uint16_t mb_cseg_16_len;
338 	uint16_t mb_dseg_len;
339 } multiboot_tag_apm_t;
340 
341 typedef struct multiboot_tag_efi32 {
342 	uint32_t mb_type;
343 	uint32_t mb_size;
344 	uint32_t mb_pointer;
345 } multiboot_tag_efi32_t;
346 
347 typedef struct multiboot_tag_efi64 {
348 	uint32_t mb_type;
349 	uint32_t mb_size;
350 	uint64_t mb_pointer;
351 } multiboot_tag_efi64_t;
352 
353 typedef struct multiboot_tag_smbios {
354 	uint32_t mb_type;
355 	uint32_t mb_size;
356 	uint8_t mb_major;
357 	uint8_t mb_minor;
358 	uint8_t mb_reserved[6];
359 	uint8_t mb_tables[];
360 } multiboot_tag_smbios_t;
361 
362 typedef struct multiboot_tag_old_acpi {
363 	uint32_t mb_type;
364 	uint32_t mb_size;
365 	uint8_t mb_rsdp[];
366 } multiboot_tag_old_acpi_t;
367 
368 typedef struct multiboot_tag_new_acpi {
369 	uint32_t mb_type;
370 	uint32_t mb_size;
371 	uint8_t mb_rsdp[];
372 } multiboot_tag_new_acpi_t;
373 
374 typedef struct multiboot_tag_network {
375 	uint32_t mb_type;
376 	uint32_t mb_size;
377 	uint8_t mb_dhcpack[];
378 } multiboot_tag_network_t;
379 
380 typedef struct multiboot_tag_efi_mmap {
381 	uint32_t mb_type;
382 	uint32_t mb_size;
383 	uint32_t mb_descr_size;
384 	uint32_t mb_descr_vers;
385 	uint8_t mb_efi_mmap[];
386 } multiboot_tag_efi_mmap_t;
387 
388 typedef struct multiboot_tag_efi32_ih {
389 	uint32_t mb_type;
390 	uint32_t mb_size;
391 	uint32_t mb_pointer;
392 } multiboot_tag_efi32_ih_t;
393 
394 typedef struct multiboot_tag_efi64_ih {
395 	uint32_t mb_type;
396 	uint32_t mb_size;
397 	uint64_t mb_pointer;
398 } multiboot_tag_efi64_ih_t;
399 
400 typedef struct multiboot_tag_load_base_addr {
401 	uint32_t mb_type;
402 	uint32_t mb_size;
403 	uint32_t mb_load_base_addr;
404 } multiboot_tag_load_base_addr_t;
405 
406 #pragma pack()
407 
408 #endif /* !_ASM */
409 
410 #ifdef	__cplusplus
411 }
412 #endif
413 
414 #endif /* !_SYS_MULTIBOOT2_H */
415