3 #include <ros/common.h>
5 /* multiboot.h - the header for Multiboot 0.6.96 (diff from MB2) */
6 /* Copyright (C) 1999,2003,2007,2008,2009 Free Software Foundation, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to
10 * deal in the Software without restriction, including without limitation the
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
21 * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 /* How many bytes from the start of the file we search for the header. */
28 #define MULTIBOOT_SEARCH 8192
30 /* The magic field should contain this. */
31 #define MULTIBOOT_HEADER_MAGIC 0x1BADB002
33 /* This should be in %eax. */
34 #define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
36 /* The bits in the required part of flags field we don't support. */
37 #define MULTIBOOT_UNSUPPORTED 0x0000fffc
39 /* Alignment of multiboot modules. */
40 #define MULTIBOOT_MOD_ALIGN 0x00001000
42 /* Alignment of the multiboot info structure. */
43 #define MULTIBOOT_INFO_ALIGN 0x00000004
45 /* Flags set in the 'flags' member of the multiboot header. */
47 /* Align all boot modules on i386 page (4KB) boundaries. */
48 #define MULTIBOOT_PAGE_ALIGN 0x00000001
50 /* Must pass memory information to OS. */
51 #define MULTIBOOT_MEMORY_INFO 0x00000002
53 /* Must pass video information to OS. */
54 #define MULTIBOOT_VIDEO_MODE 0x00000004
56 /* This flag indicates the use of the address fields in the header. */
57 #define MULTIBOOT_AOUT_KLUDGE 0x00010000
59 /* Flags to be set in the 'flags' member of the multiboot info structure. */
61 /* is there basic lower/upper memory information? */
62 #define MULTIBOOT_INFO_MEMORY 0x00000001
63 /* is there a boot device set? */
64 #define MULTIBOOT_INFO_BOOTDEV 0x00000002
65 /* is the command-line defined? */
66 #define MULTIBOOT_INFO_CMDLINE 0x00000004
67 /* are there modules to do something with? */
68 #define MULTIBOOT_INFO_MODS 0x00000008
70 /* These next two are mutually exclusive */
72 /* is there a symbol table loaded? */
73 #define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
74 /* is there an ELF section header table? */
75 #define MULTIBOOT_INFO_ELF_SHDR 0X00000020
77 /* is there a full memory map? */
78 #define MULTIBOOT_INFO_MEM_MAP 0x00000040
80 /* Is there drive info? */
81 #define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
83 /* Is there a config table? */
84 #define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
86 /* Is there a boot loader name? */
87 #define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
89 /* Is there a APM table? */
90 #define MULTIBOOT_INFO_APM_TABLE 0x00000400
92 /* Is there video information? */
93 #define MULTIBOOT_INFO_VIDEO_INFO 0x00000800
97 typedef unsigned short multiboot_uint16_t;
98 typedef unsigned int multiboot_uint32_t;
99 typedef unsigned long long multiboot_uint64_t;
101 struct multiboot_header
103 /* Must be MULTIBOOT_MAGIC - see above. */
104 multiboot_uint32_t magic;
107 multiboot_uint32_t flags;
109 /* The above fields plus this one must equal 0 mod 2^32. */
110 multiboot_uint32_t checksum;
112 /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
113 multiboot_uint32_t header_addr;
114 multiboot_uint32_t load_addr;
115 multiboot_uint32_t load_end_addr;
116 multiboot_uint32_t bss_end_addr;
117 multiboot_uint32_t entry_addr;
119 /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
120 multiboot_uint32_t mode_type;
121 multiboot_uint32_t width;
122 multiboot_uint32_t height;
123 multiboot_uint32_t depth;
126 /* The symbol table for a.out. */
127 struct multiboot_aout_symbol_table
129 multiboot_uint32_t tabsize;
130 multiboot_uint32_t strsize;
131 multiboot_uint32_t addr;
132 multiboot_uint32_t reserved;
134 typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
136 /* The section header table for ELF. */
137 struct multiboot_elf_section_header_table
139 multiboot_uint32_t num;
140 multiboot_uint32_t size;
141 multiboot_uint32_t addr;
142 multiboot_uint32_t shndx;
144 typedef struct multiboot_elf_section_header_table
145 multiboot_elf_section_header_table_t;
147 struct multiboot_info
149 /* Multiboot info version number */
150 multiboot_uint32_t flags;
152 /* Available memory from BIOS */
153 multiboot_uint32_t mem_lower;
154 multiboot_uint32_t mem_upper;
156 /* "root" partition */
157 multiboot_uint32_t boot_device;
159 /* Kernel command line */
160 multiboot_uint32_t cmdline;
162 /* Boot-Module list */
163 multiboot_uint32_t mods_count;
164 multiboot_uint32_t mods_addr;
167 multiboot_aout_symbol_table_t aout_sym;
168 multiboot_elf_section_header_table_t elf_sec;
171 /* Memory Mapping buffer */
172 multiboot_uint32_t mmap_length;
173 multiboot_uint32_t mmap_addr;
175 /* Drive Info buffer */
176 multiboot_uint32_t drives_length;
177 multiboot_uint32_t drives_addr;
179 /* ROM configuration table */
180 multiboot_uint32_t config_table;
182 /* Boot Loader Name */
183 multiboot_uint32_t boot_loader_name;
186 multiboot_uint32_t apm_table;
189 multiboot_uint32_t vbe_control_info;
190 multiboot_uint32_t vbe_mode_info;
191 multiboot_uint16_t vbe_mode;
192 multiboot_uint16_t vbe_interface_seg;
193 multiboot_uint16_t vbe_interface_off;
194 multiboot_uint16_t vbe_interface_len;
196 typedef struct multiboot_info multiboot_info_t;
198 /* The memory map. Be careful, the size value doesn't include itself... */
199 struct multiboot_mmap_entry
201 multiboot_uint32_t size;
202 multiboot_uint64_t addr;
203 multiboot_uint64_t len;
204 #define MULTIBOOT_MEMORY_AVAILABLE 1
205 #define MULTIBOOT_MEMORY_RESERVED 2
206 multiboot_uint32_t type;
207 } __attribute__((packed));
208 typedef struct multiboot_mmap_entry multiboot_memory_map_t;
210 struct multiboot_mod_list
212 /* the memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive */
213 multiboot_uint32_t mod_start;
214 multiboot_uint32_t mod_end;
216 /* Module command line */
217 multiboot_uint32_t cmdline;
219 /* padding to take it to 16 bytes (must be zero) */
220 multiboot_uint32_t pad;
222 typedef struct multiboot_mod_list multiboot_module_t;
224 #endif /* ! ASM_FILE */
226 typedef void (*mboot_foreach_t)(struct multiboot_mmap_entry*, void*);
228 bool mboot_has_mmaps(struct multiboot_info *mbi);
229 void mboot_detect_memory(struct multiboot_info *mbi);
230 void mboot_print_mmap(struct multiboot_info *mbi);
231 void mboot_foreach_mmap(struct multiboot_info *mbi, mboot_foreach_t func,
233 bool mboot_region_collides(struct multiboot_info *mbi, uintptr_t base,