1 #ifndef MULTIBOOT_HEADER
2 #define MULTIBOOT_HEADER 1
4 // References https://www.gnu.org/software/grub/manual/multiboot/multiboot.html
6 #define MULTIBOOT_MAGIC 0x1BADB002
7 #define CHECKSUM(flags) -(MULTIBOOT_MAGIC + flags)
9 /* This should be in %eax. */
10 #define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
12 /* Alignment of multiboot modules. */
13 #define MULTIBOOT_MOD_ALIGN 0x00001000
15 /* Alignment of the multiboot info structure. */
16 #define MULTIBOOT_INFO_ALIGN 0x00000004
18 /* Flags set in the ’flags’ member of the multiboot header. */
20 /* Align all boot modules on i386 page (4KB) boundaries. */
21 #define MULTIBOOT_PAGE_ALIGN 0x00000001
23 /* Must pass memory information to OS. */
24 #define MULTIBOOT_MEMORY_INFO 0x00000002
26 /* Must pass video information to OS. */
27 #define MULTIBOOT_VIDEO_MODE 0x00000004
29 /* This flag indicates the use of the address fields in the header. */
30 #define MULTIBOOT_AOUT_KLUDGE 0x00010000
32 /* Flags to be set in the ’flags’ member of the multiboot info structure. */
34 /* is there basic lower/upper memory information? */
35 #define MULTIBOOT_INFO_MEMORY 0x00000001
36 /* is there a boot device set? */
37 #define MULTIBOOT_INFO_BOOTDEV 0x00000002
38 /* is the command-line defined? */
39 #define MULTIBOOT_INFO_CMDLINE 0x00000004
40 /* are there modules to do something with? */
41 #define MULTIBOOT_INFO_MODS 0x00000008
43 /* These next two are mutually exclusive */
45 /* is there a symbol table loaded? */
46 #define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
47 /* is there an ELF section header table? */
48 #define MULTIBOOT_INFO_ELF_SHDR 0X00000020
50 /* is there a full memory map? */
51 #define MULTIBOOT_INFO_MEM_MAP 0x00000040
53 /* Is there drive info? */
54 #define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
56 /* Is there a config table? */
57 #define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
59 /* Is there a boot loader name? */
60 #define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
62 /* Is there a APM table? */
63 #define MULTIBOOT_INFO_APM_TABLE 0x00000400
65 /* Is there video information? */
66 #define MULTIBOOT_INFO_VBE_INFO 0x00000800
67 #define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
69 #define present(flags, info) ((flags) & (info))
73 typedef unsigned char multiboot_uint8_t;
74 typedef unsigned short multiboot_uint16_t;
75 typedef unsigned int multiboot_uint32_t;
76 typedef unsigned long long multiboot_uint64_t;
78 struct multiboot_symbol_table
80 multiboot_uint32_t tabsize;
81 multiboot_uint32_t strsize;
82 multiboot_uint32_t addr;
83 multiboot_uint32_t reserved;
85 typedef struct multiboot_symbol_table multiboot_symbol_table_t;
87 /* The section header table for ELF. */
88 struct multiboot_elf_section_header_table
90 multiboot_uint32_t num;
91 multiboot_uint32_t size;
92 multiboot_uint32_t addr;
93 multiboot_uint32_t shndx;
95 typedef struct multiboot_elf_section_header_table
96 multiboot_elf_section_header_table_t;
100 /* Multiboot info version number */
101 multiboot_uint32_t flags;
103 /* Available memory from BIOS */
104 multiboot_uint32_t mem_lower;
105 multiboot_uint32_t mem_upper;
107 /* "root" partition */
108 multiboot_uint32_t boot_device;
110 /* Kernel command line */
111 multiboot_uint32_t cmdline;
113 /* Boot-Module list */
114 multiboot_uint32_t mods_count;
115 multiboot_uint32_t mods_addr;
119 multiboot_symbol_table_t aout_sym;
120 multiboot_elf_section_header_table_t elf_sec;
123 /* Memory Mapping buffer */
124 multiboot_uint32_t mmap_length;
125 multiboot_uint32_t mmap_addr;
127 /* Drive Info buffer */
128 multiboot_uint32_t drives_length;
129 multiboot_uint32_t drives_addr;
131 /* ROM configuration table */
132 multiboot_uint32_t config_table;
134 /* Boot Loader Name */
135 multiboot_uint32_t boot_loader_name;
138 multiboot_uint32_t apm_table;
141 multiboot_uint32_t vbe_control_info;
142 multiboot_uint32_t vbe_mode_info;
143 multiboot_uint16_t vbe_mode;
144 multiboot_uint16_t vbe_interface_seg;
145 multiboot_uint16_t vbe_interface_off;
146 multiboot_uint16_t vbe_interface_len;
148 multiboot_uint64_t framebuffer_addr;
149 multiboot_uint32_t framebuffer_pitch;
150 multiboot_uint32_t framebuffer_width;
151 multiboot_uint32_t framebuffer_height;
152 multiboot_uint8_t framebuffer_bpp;
153 #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
154 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
155 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
156 multiboot_uint8_t framebuffer_type;
161 multiboot_uint32_t framebuffer_palette_addr;
162 multiboot_uint16_t framebuffer_palette_num_colors;
166 multiboot_uint8_t framebuffer_red_field_position;
167 multiboot_uint8_t framebuffer_red_mask_size;
168 multiboot_uint8_t framebuffer_green_field_position;
169 multiboot_uint8_t framebuffer_green_mask_size;
170 multiboot_uint8_t framebuffer_blue_field_position;
171 multiboot_uint8_t framebuffer_blue_mask_size;
175 typedef struct multiboot_info multiboot_info_t;
177 struct multiboot_color
179 multiboot_uint8_t red;
180 multiboot_uint8_t green;
181 multiboot_uint8_t blue;
184 struct multiboot_mmap_entry
186 multiboot_uint32_t size;
187 multiboot_uint32_t addr_low;
188 multiboot_uint32_t addr_high;
189 multiboot_uint32_t len_low;
190 multiboot_uint32_t len_high;
191 #define MULTIBOOT_MEMORY_AVAILABLE 1
192 #define MULTIBOOT_MEMORY_RESERVED 2
193 #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
194 #define MULTIBOOT_MEMORY_NVS 4
195 #define MULTIBOOT_MEMORY_BADRAM 5
196 multiboot_uint32_t type;
197 } __attribute__((packed));
199 typedef struct multiboot_mmap_entry multiboot_memory_map_t;
201 struct multiboot_mod_list
203 /* the memory used goes from bytes ’mod_start’ to ’mod_end-1’ inclusive */
204 multiboot_uint32_t mod_start;
205 multiboot_uint32_t mod_end;
207 /* Module command line */
208 multiboot_uint32_t cmdline;
210 /* padding to take it to 16 bytes (must be zero) */
211 multiboot_uint32_t pad;
213 typedef struct multiboot_mod_list multiboot_module_t;
216 struct multiboot_apm_info
218 multiboot_uint16_t version;
219 multiboot_uint16_t cseg;
220 multiboot_uint32_t offset;
221 multiboot_uint16_t cseg_16;
222 multiboot_uint16_t dseg;
223 multiboot_uint16_t flags;
224 multiboot_uint16_t cseg_len;
225 multiboot_uint16_t cseg_16_len;
226 multiboot_uint16_t dseg_len;
229 #define MB_MMAP_ENTRY_SIZE sizeof(multiboot_memory_map_t)