blob: 5672812b93729eb1cf54e85630db8dd93f545a4d [file] [log] [blame]
swissChili9752ab32021-03-05 11:20:13 -08001#pragma once
2
swissChilida23a912021-03-12 16:07:50 -08003/* multiboot.h - Multiboot header file. */
4/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
19 * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25
swissChili9752ab32021-03-05 11:20:13 -080026#include "kint.h"
27
swissChilida23a912021-03-12 16:07:50 -080028/* How many bytes from the start of the file we search for the header. */
29#define MULTIBOOT_SEARCH 8192
30#define MULTIBOOT_HEADER_ALIGN 4
31
32/* The magic field should contain this. */
33#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
34
35/* This should be in %eax. */
36#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
37
38/* Alignment of multiboot modules. */
39#define MULTIBOOT_MOD_ALIGN 0x00001000
40
41/* Alignment of the multiboot info structure. */
42#define MULTIBOOT_INFO_ALIGN 0x00000004
43
44/* Flags set in the ’flags’ member of the multiboot header. */
45
46/* Align all boot modules on i386 page (4KB) boundaries. */
47#define MULTIBOOT_PAGE_ALIGN 0x00000001
48
49/* Must pass memory information to OS. */
50#define MULTIBOOT_MEMORY_INFO 0x00000002
51
52/* Must pass video information to OS. */
53#define MULTIBOOT_VIDEO_MODE 0x00000004
54
55/* This flag indicates the use of the address fields in the header. */
56#define MULTIBOOT_AOUT_KLUDGE 0x00010000
57
58/* Flags to be set in the ’flags’ member of the multiboot info structure. */
59
60/* is there basic lower/upper memory information? */
61#define MULTIBOOT_INFO_MEMORY 0x00000001
62/* is there a boot device set? */
63#define MULTIBOOT_INFO_BOOTDEV 0x00000002
64/* is the command-line defined? */
65#define MULTIBOOT_INFO_CMDLINE 0x00000004
66/* are there modules to do something with? */
67#define MULTIBOOT_INFO_MODS 0x00000008
68
69/* These next two are mutually exclusive */
70
71/* is there a symbol table loaded? */
72#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
73/* is there an ELF section header table? */
74#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
75
76/* is there a full memory map? */
77#define MULTIBOOT_INFO_MEM_MAP 0x00000040
78
79/* Is there drive info? */
80#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
81
82/* Is there a config table? */
83#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
84
85/* Is there a boot loader name? */
86#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
87
88/* Is there a APM table? */
89#define MULTIBOOT_INFO_APM_TABLE 0x00000400
90
91/* Is there video information? */
92#define MULTIBOOT_INFO_VBE_INFO 0x00000800
93#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
94
95#ifndef ASM_FILE
96
97struct multiboot_header
swissChili9752ab32021-03-05 11:20:13 -080098{
swissChilida23a912021-03-12 16:07:50 -080099 /* Must be MULTIBOOT_MAGIC - see above. */
100 uint magic;
101
102 /* Feature flags. */
swissChili9752ab32021-03-05 11:20:13 -0800103 uint flags;
swissChilida23a912021-03-12 16:07:50 -0800104
105 /* The above fields plus this one must equal 0 mod 2^32. */
106 uint checksum;
107
108 /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
109 uint header_addr;
110 uint load_addr;
111 uint load_end_addr;
112 uint bss_end_addr;
113 uint entry_addr;
114
115 /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
116 uint mode_type;
117 uint width;
118 uint height;
119 uint depth;
120};
121
122/* The symbol table for a.out. */
123struct multiboot_aout_symbol_table
124{
125 uint tabsize;
126 uint strsize;
127 uint addr;
128 uint reserved;
129};
130typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
131
132/* The section header table for ELF. */
133struct multiboot_elf_section_header_table
134{
swissChili9752ab32021-03-05 11:20:13 -0800135 uint num;
136 uint size;
137 uint addr;
138 uint shndx;
swissChilida23a912021-03-12 16:07:50 -0800139};
140typedef struct multiboot_elf_section_header_table
141 multiboot_elf_section_header_table_t;
142
143struct multiboot_info
144{
145 /* Multiboot info version number */
146 uint flags;
147
148 /* Available memory from BIOS */
149 uint mem_lower;
150 uint mem_upper;
151
152 /* "root" partition */
153 uint boot_device;
154
155 /* Kernel command line */
156 uint cmdline;
157
158 /* Boot-Module list */
159 uint mods_count;
160 uint mods_addr;
161
162 union {
163 multiboot_aout_symbol_table_t aout_sym;
164 multiboot_elf_section_header_table_t elf_sec;
165 } u;
166
167 /* Memory Mapping buffer */
swissChili9752ab32021-03-05 11:20:13 -0800168 uint mmap_length;
169 uint mmap_addr;
swissChilida23a912021-03-12 16:07:50 -0800170
171 /* Drive Info buffer */
swissChili9752ab32021-03-05 11:20:13 -0800172 uint drives_length;
173 uint drives_addr;
swissChilida23a912021-03-12 16:07:50 -0800174
175 /* ROM configuration table */
swissChili9752ab32021-03-05 11:20:13 -0800176 uint config_table;
swissChilida23a912021-03-12 16:07:50 -0800177
178 /* Boot Loader Name */
swissChili9752ab32021-03-05 11:20:13 -0800179 uint boot_loader_name;
swissChilida23a912021-03-12 16:07:50 -0800180
181 /* APM table */
swissChili9752ab32021-03-05 11:20:13 -0800182 uint apm_table;
swissChilida23a912021-03-12 16:07:50 -0800183
184 /* Video */
swissChili9752ab32021-03-05 11:20:13 -0800185 uint vbe_control_info;
186 uint vbe_mode_info;
swissChilida23a912021-03-12 16:07:50 -0800187 ushort vbe_mode;
188 ushort vbe_interface_seg;
189 ushort vbe_interface_off;
190 ushort vbe_interface_len;
191
192 uint framebuffer_addr_low;
193 uint framebuffer_addr_high;
194 uint framebuffer_pitch;
195 uint framebuffer_width;
196 uint framebuffer_height;
197 uchar framebuffer_bpp;
198#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
199#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
200#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
201 uchar framebuffer_type;
202 union {
203 struct
204 {
205 uint framebuffer_palette_addr;
206 ushort framebuffer_palette_num_colors;
207 };
208 struct
209 {
210 uchar framebuffer_red_field_position;
211 uchar framebuffer_red_mask_size;
212 uchar framebuffer_green_field_position;
213 uchar framebuffer_green_mask_size;
214 uchar framebuffer_blue_field_position;
215 uchar framebuffer_blue_mask_size;
216 };
217 };
218};
219typedef struct multiboot_info multiboot_info_t;
220
221struct multiboot_color
222{
223 uchar red;
224 uchar green;
225 uchar blue;
swissChili9752ab32021-03-05 11:20:13 -0800226};
227
swissChilida23a912021-03-12 16:07:50 -0800228/*struct multiboot_mmap_entry
229{
230 uint size;
231 multiboot_uint64_t addr;
232 multiboot_uint64_t len;
233#define MULTIBOOT_MEMORY_AVAILABLE 1
234#define MULTIBOOT_MEMORY_RESERVED 2
235#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
236#define MULTIBOOT_MEMORY_NVS 4
237#define MULTIBOOT_MEMORY_BADRAM 5
238 uint type;
239} __attribute__((packed));
240typedef struct multiboot_mmap_entry multiboot_memory_map_t; */
241
242struct multiboot_mod_list
243{
244 /* the memory used goes from bytes ’mod_start’ to ’mod_end-1’ inclusive */
245 uint mod_start;
246 uint mod_end;
247
248 /* Module command line */
249 uint cmdline;
250
251 /* padding to take it to 16 bytes (must be zero) */
252 uint pad;
253};
254typedef struct multiboot_mod_list multiboot_module_t;
255
256/* APM BIOS info. */
257struct multiboot_apm_info
258{
259 ushort version;
260 ushort cseg;
261 uint offset;
262 ushort cseg_16;
263 ushort dseg;
264 ushort flags;
265 ushort cseg_len;
266 ushort cseg_16_len;
267 ushort dseg_len;
268};
269
270struct multiboot_info make_multiboot_physical(struct multiboot_info *old);
271
272#endif // asm