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