1 /* [ORIGIN: src/sys/arch/i386/include/... */ 2 /* $NetBSD: multiboot.h,v 1.8 2009/02/22 18:05:42 ahoka Exp $ */ 3 4 /*- 5 * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Julio M. Merino Vidal. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * multiboot.h 35 */ 36 37 #ifndef _MULTIBOOT_H 38 #define _MULTIBOOT_H 39 40 #include <stdint.h> 41 #include <types.h> 42 43 struct multiboot_info; 44 extern struct multiboot_info mbi; 45 46 /* 47 * Multiboot header structure. 48 */ 49 #define MULTIBOOT_HEADER_MAGIC 0x1BADB002 50 #define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001 51 #define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002 52 #define MULTIBOOT_HEADER_HAS_VBE 0x00000004 53 #define MULTIBOOT_HEADER_HAS_ADDR 0x00010000 54 55 #define MULTIBOOT_HEADER_ALIGN 4 56 #define MULTIBOOT_SEARCH 8192 57 58 #if !defined(_LOCORE) 59 struct multiboot_header { 60 uint32_t mh_magic; 61 uint32_t mh_flags; 62 uint32_t mh_checksum; 63 64 /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */ 65 uint32_t mh_header_addr; 66 uint32_t mh_load_addr; 67 uint32_t mh_load_end_addr; 68 uint32_t mh_bss_end_addr; 69 uint32_t mh_entry_addr; 70 71 /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */ 72 uint32_t mh_mode_type; 73 uint32_t mh_width; 74 uint32_t mh_height; 75 uint32_t mh_depth; 76 }; 77 #endif /* !defined(_LOCORE) */ 78 79 /* 80 * Symbols defined in locore.S. 81 */ 82 extern struct multiboot_header *Multiboot_Header; 83 84 /* 85 * Multiboot information structure. 86 */ 87 #define MULTIBOOT_INFO_MAGIC 0x2BADB002U 88 #define MULTIBOOT_INFO_HAS_MEMORY 0x00000001U 89 #define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002U 90 #define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004U 91 #define MULTIBOOT_INFO_HAS_MODS 0x00000008U 92 #define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010U 93 #define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020U 94 #define MULTIBOOT_INFO_HAS_MMAP 0x00000040U 95 #define MULTIBOOT_INFO_HAS_DRIVES 0x00000080U 96 #define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100U 97 #define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200U 98 #define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400U 99 #define MULTIBOOT_INFO_HAS_VBE 0x00000800U 100 101 #if !defined(_LOCORE) 102 struct multiboot_info { 103 uint32_t mi_flags; 104 105 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */ 106 uint32_t mi_mem_lower; 107 uint32_t mi_mem_upper; 108 109 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */ 110 uint8_t mi_boot_device_part3; 111 uint8_t mi_boot_device_part2; 112 uint8_t mi_boot_device_part1; 113 uint8_t mi_boot_device_drive; 114 115 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */ 116 uint32_t mi_cmdline; 117 118 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */ 119 uint32_t mi_mods_count; 120 uint32_t mi_mods_addr; 121 122 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */ 123 uint32_t mi_elfshdr_num; 124 uint32_t mi_elfshdr_size; 125 uint32_t mi_elfshdr_addr; 126 uint32_t mi_elfshdr_shndx; 127 128 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */ 129 uint32_t mi_mmap_length; 130 uint32_t mi_mmap_addr; 131 132 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */ 133 uint32_t mi_drives_length; 134 uint32_t mi_drives_addr; 135 136 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */ 137 uint32_t unused_mi_config_table; 138 139 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */ 140 uint32_t mi_loader_name; 141 142 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */ 143 uint32_t unused_mi_apm_table; 144 145 /* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */ 146 uint32_t unused_mi_vbe_control_info; 147 uint32_t unused_mi_vbe_mode_info; 148 uint32_t unused_mi_vbe_interface_seg; 149 uint32_t unused_mi_vbe_interface_off; 150 uint32_t unused_mi_vbe_interface_len; 151 }__aligned(8); 152 153 154 /* 155 * Memory mapping. This describes an entry in the memory mappings table 156 * as pointed to by mi_mmap_addr. 157 * 158 * Be aware that mm_size specifies the size of all other fields *except* 159 * for mm_size. In order to jump between two different entries, you 160 * have to count mm_size + 4 bytes. 161 */ 162 struct __attribute__((packed)) multiboot_mmap { 163 uint32_t mm_size; 164 uint64_t mm_base_addr; 165 uint64_t mm_length; 166 uint32_t mm_type; 167 }; 168 169 /* 170 * Modules. This describes an entry in the modules table as pointed 171 * to by mi_mods_addr. 172 */ 173 174 struct multiboot_module { 175 uint32_t mmo_start; 176 uint32_t mmo_end; 177 uint32_t mmo_string; 178 uint32_t mmo_reserved; 179 } __packed; 180 181 #endif /* !defined(_LOCORE) */ 182 183 struct multiboot2_header 184 { 185 uint32_t magic; 186 uint32_t architecture; 187 uint32_t header_length; 188 uint32_t checksum; 189 }; 190 191 #define MULTIBOOT2_SEARCH 32768 192 193 #define MULTIBOOT2_HEADER_ALIGN 8 194 195 #define MULTIBOOT2_HEADER_MAGIC 0xe85250d6U 196 197 /* This should be in %eax. */ 198 #define MULTIBOOT2_INFO_MAGIC 0x36d76289U 199 200 /* Alignment of the multiboot info structure. */ 201 #define MULTIBOOT2_INFO_ALIGN 0x00000008U 202 203 /* Flags set in the 'flags' member of the multiboot header. */ 204 205 #define MULTIBOOT2_TAG_ALIGN 8U 206 #define MULTIBOOT2_TAG_TYPE_END 0U 207 #define MULTIBOOT2_TAG_TYPE_CMDLINE 1U 208 #define MULTIBOOT2_TAG_TYPE_BOOT_LOADER_NAME 2U 209 #define MULTIBOOT2_TAG_TYPE_MODULE 3U 210 #define MULTIBOOT2_TAG_TYPE_BASIC_MEMINFO 4U 211 #define MULTIBOOT2_TAG_TYPE_BOOTDEV 5U 212 #define MULTIBOOT2_TAG_TYPE_MMAP 6U 213 #define MULTIBOOT2_TAG_TYPE_VBE 7U 214 #define MULTIBOOT2_TAG_TYPE_FRAMEBUFFER 8U 215 #define MULTIBOOT2_TAG_TYPE_ELF_SECTIONS 9U 216 #define MULTIBOOT2_TAG_TYPE_APM 10U 217 #define MULTIBOOT2_TAG_TYPE_EFI32 11U 218 #define MULTIBOOT2_TAG_TYPE_EFI64 12U 219 #define MULTIBOOT2_TAG_TYPE_SMBIOS 13U 220 #define MULTIBOOT2_TAG_TYPE_ACPI_OLD 14U 221 #define MULTIBOOT2_TAG_TYPE_ACPI_NEW 15U 222 #define MULTIBOOT2_TAG_TYPE_NETWORK 16U 223 #define MULTIBOOT2_TAG_TYPE_EFI_MMAP 17U 224 #define MULTIBOOT2_TAG_TYPE_EFI_BS 18U 225 #define MULTIBOOT2_TAG_TYPE_EFI32_IH 19U 226 #define MULTIBOOT2_TAG_TYPE_EFI64_IH 20U 227 #define MULTIBOOT2_TAG_TYPE_LOAD_BASE_ADDR 21U 228 229 #define MULTIBOOT2_HEADER_TAG_END 0 230 #define MULTIBOOT2_HEADER_TAG_INFORMATION_REQUEST 1 231 #define MULTIBOOT2_HEADER_TAG_ADDRESS 2 232 #define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS 3 233 #define MULTIBOOT2_HEADER_TAG_CONSOLE_FLAGS 4 234 #define MULTIBOOT2_HEADER_TAG_FRAMEBUFFER 5 235 #define MULTIBOOT2_HEADER_TAG_MODULE_ALIGN 6 236 #define MULTIBOOT2_HEADER_TAG_EFI_BS 7 237 #define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI32 8 238 #define MULTIBOOT2_HEADER_TAG_ENTRY_ADDRESS_EFI64 9 239 #define MULTIBOOT2_HEADER_TAG_RELOCATABLE 10 240 #define MULTIBOOT2_HEADER_TAG_OPTIONAL 1 241 242 #define MULTIBOOT2_ARCHITECTURE_I386 0 243 244 #ifndef ASSEMBLER 245 246 struct multiboot2_header_tag 247 { 248 uint16_t type; 249 uint16_t flags; 250 uint32_t size; 251 }; 252 253 struct multiboot2_header_tag_information_request 254 { 255 uint16_t type; 256 uint16_t flags; 257 uint32_t size; 258 uint32_t requests[0]; 259 }; 260 261 struct multiboot2_header_tag_address 262 { 263 uint16_t type; 264 uint16_t flags; 265 uint32_t size; 266 uint32_t header_addr; 267 uint32_t load_addr; 268 uint32_t load_end_addr; 269 uint32_t bss_end_addr; 270 }; 271 272 struct multiboot2_header_tag_entry_address 273 { 274 uint16_t type; 275 uint16_t flags; 276 uint32_t size; 277 uint32_t entry_addr; 278 }; 279 280 struct multiboot2_header_tag_console_flags 281 { 282 uint16_t type; 283 uint16_t flags; 284 uint32_t size; 285 uint32_t console_flags; 286 }; 287 288 struct multiboot2_header_tag_framebuffer 289 { 290 uint16_t type; 291 uint16_t flags; 292 uint32_t size; 293 uint32_t width; 294 uint32_t height; 295 uint32_t depth; 296 }; 297 298 struct multiboot2_header_tag_module_align 299 { 300 uint16_t type; 301 uint16_t flags; 302 uint32_t size; 303 }; 304 305 struct multiboot2_header_tag_relocatable 306 { 307 uint16_t type; 308 uint16_t flags; 309 uint32_t size; 310 uint32_t min_addr; 311 uint32_t max_addr; 312 uint32_t align; 313 uint32_t preference; 314 }; 315 316 struct multiboot2_mmap_entry 317 { 318 uint64_t addr; 319 uint64_t len; 320 uint32_t type; 321 uint32_t zero; 322 }; 323 324 struct multiboot2_tag 325 { 326 uint32_t type; 327 uint32_t size; 328 }; 329 330 struct multiboot2_tag_string 331 { 332 uint32_t type; 333 uint32_t size; 334 char string[0]; 335 }; 336 337 struct multiboot2_tag_module 338 { 339 uint32_t type; 340 uint32_t size; 341 uint32_t mod_start; 342 uint32_t mod_end; 343 char cmdline[0]; 344 }; 345 346 struct multiboot2_tag_mmap 347 { 348 uint32_t type; 349 uint32_t size; 350 uint32_t entry_size; 351 uint32_t entry_version; 352 struct multiboot2_mmap_entry entries[0]; 353 }; 354 355 struct multiboot2_tag_new_acpi 356 { 357 uint32_t type; 358 uint32_t size; 359 uint8_t rsdp[0]; 360 }; 361 362 struct multiboot2_tag_efi64 363 { 364 uint32_t type; 365 uint32_t size; 366 uint64_t pointer; 367 }; 368 369 struct multiboot2_tag_efi_mmap { 370 uint32_t type; 371 uint32_t size; 372 uint32_t descr_size; 373 uint32_t descr_vers; 374 uint8_t efi_mmap[0]; 375 }; 376 #endif 377 378 struct hv_mb2header_tag_list { 379 struct multiboot2_header_tag_information_request *info_req; 380 struct multiboot2_header_tag_address *addr; 381 struct multiboot2_header_tag_entry_address *entry; 382 struct multiboot2_header_tag_console_flags *console_flags; 383 struct multiboot2_header_tag_framebuffer *frbuf; 384 struct multiboot2_header_tag_module_align *modalign; 385 struct multiboot2_header_tag_relocatable *reloc; 386 }; 387 388 const struct multiboot_header *find_mb1header(const UINT8 *buffer, uint64_t len); 389 const struct multiboot2_header *find_mb2header(const UINT8 *buffer, uint64_t len); 390 int parse_mb2header(const struct multiboot2_header *header, struct hv_mb2header_tag_list *hv_tags); 391 392 #endif /* _MULTIBOOT_H */ 393