aca8f433ef7cc3d94f525546e91c89f2ef8e4408
[lunaix-os.git] / lunaix-os / arch / i386 / includes / sys / boot / multiboot.h
1 #ifndef MULTIBOOT_HEADER
2 #define MULTIBOOT_HEADER 1
3
4 // References https://www.gnu.org/software/grub/manual/multiboot/multiboot.html
5
6 #define MULTIBOOT_MAGIC 0x1BADB002
7 #define CHECKSUM(flags) -(MULTIBOOT_MAGIC + flags)
8
9 /* This should be in %eax. */
10 #define MULTIBOOT_BOOTLOADER_MAGIC              0x2BADB002
11
12 /* Alignment of multiboot modules. */
13 #define MULTIBOOT_MOD_ALIGN                     0x00001000
14
15 /* Alignment of the multiboot info structure. */
16 #define MULTIBOOT_INFO_ALIGN                    0x00000004
17
18 /* Flags set in the ’flags’ member of the multiboot header. */
19
20 /* Align all boot modules on i386 page (4KB) boundaries. */
21 #define MULTIBOOT_PAGE_ALIGN                    0x00000001
22
23 /* Must pass memory information to OS. */
24 #define MULTIBOOT_MEMORY_INFO                   0x00000002
25
26 /* Must pass video information to OS. */
27 #define MULTIBOOT_VIDEO_MODE                    0x00000004
28
29 /* This flag indicates the use of the address fields in the header. */
30 #define MULTIBOOT_AOUT_KLUDGE                   0x00010000
31
32 /* Flags to be set in the ’flags’ member of the multiboot info structure. */
33
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
42
43 /* These next two are mutually exclusive */
44
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
49
50 /* is there a full memory map? */
51 #define MULTIBOOT_INFO_MEM_MAP                  0x00000040
52
53 /* Is there drive info? */
54 #define MULTIBOOT_INFO_DRIVE_INFO               0x00000080
55
56 /* Is there a config table? */
57 #define MULTIBOOT_INFO_CONFIG_TABLE             0x00000100
58
59 /* Is there a boot loader name? */
60 #define MULTIBOOT_INFO_BOOT_LOADER_NAME         0x00000200
61
62 /* Is there a APM table? */
63 #define MULTIBOOT_INFO_APM_TABLE                0x00000400
64
65 /* Is there video information? */
66 #define MULTIBOOT_INFO_VBE_INFO                 0x00000800
67 #define MULTIBOOT_INFO_FRAMEBUFFER_INFO         0x00001000
68
69 #define present(flags, info)      ((flags) & (info))
70
71 #ifndef __ASM__
72
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;
77
78 struct multiboot_symbol_table
79 {
80     multiboot_uint32_t tabsize;
81     multiboot_uint32_t strsize;
82     multiboot_uint32_t addr;
83     multiboot_uint32_t reserved;
84 };
85 typedef struct multiboot_symbol_table multiboot_symbol_table_t;
86
87 /* The section header table for ELF. */
88 struct multiboot_elf_section_header_table
89 {
90     multiboot_uint32_t num;
91     multiboot_uint32_t size;
92     multiboot_uint32_t addr;
93     multiboot_uint32_t shndx;
94 };
95 typedef struct multiboot_elf_section_header_table
96   multiboot_elf_section_header_table_t;
97
98 struct multiboot_info
99 {
100     /* Multiboot info version number */
101     multiboot_uint32_t flags;
102
103     /* Available memory from BIOS */
104     multiboot_uint32_t mem_lower;
105     multiboot_uint32_t mem_upper;
106
107     /* "root" partition */
108     multiboot_uint32_t boot_device;
109
110     /* Kernel command line */
111     multiboot_uint32_t cmdline;
112
113     /* Boot-Module list */
114     multiboot_uint32_t mods_count;
115     multiboot_uint32_t mods_addr;
116
117     union
118     {
119         multiboot_symbol_table_t aout_sym;
120         multiboot_elf_section_header_table_t elf_sec;
121     } u;
122
123     /* Memory Mapping buffer */
124     multiboot_uint32_t mmap_length;
125     multiboot_uint32_t mmap_addr;
126
127     /* Drive Info buffer */
128     multiboot_uint32_t drives_length;
129     multiboot_uint32_t drives_addr;
130
131     /* ROM configuration table */
132     multiboot_uint32_t config_table;
133
134     /* Boot Loader Name */
135     multiboot_uint32_t boot_loader_name;
136
137     /* APM table */
138     multiboot_uint32_t apm_table;
139
140     /* Video */
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;
147
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;
157     union
158     {
159         struct
160         {
161             multiboot_uint32_t framebuffer_palette_addr;
162             multiboot_uint16_t framebuffer_palette_num_colors;
163         };
164         struct
165         {
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;
172         };
173     };
174 };
175 typedef struct multiboot_info multiboot_info_t;
176
177 struct multiboot_color
178 {
179     multiboot_uint8_t red;
180     multiboot_uint8_t green;
181     multiboot_uint8_t blue;
182 };
183
184 struct multiboot_mmap_entry
185 {
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));
198
199 typedef struct multiboot_mmap_entry multiboot_memory_map_t;
200
201 struct multiboot_mod_list
202 {
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;
206
207     /* Module command line */
208     multiboot_uint32_t cmdline;
209
210     /* padding to take it to 16 bytes (must be zero) */
211     multiboot_uint32_t pad;
212 };
213 typedef struct multiboot_mod_list multiboot_module_t;
214
215 /* APM BIOS info. */
216 struct multiboot_apm_info
217 {
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;
227 };
228
229 #define MB_MMAP_ENTRY_SIZE      sizeof(multiboot_memory_map_t)
230
231 #endif
232 #endif