xref: /netbsd-src/sys/arch/i386/include/multiboot.h (revision b2a4053feb5e552b45ef84888077b01ae7ee0dba)
1 /*	$NetBSD: multiboot.h,v 1.11 2019/10/18 01:38:28 manu Exp $	*/
2 
3 /*-
4  * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Julio M. Merino Vidal.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /* --------------------------------------------------------------------- */
33 
34 /*
35  * Multiboot header structure.
36  */
37 #define MULTIBOOT_HEADER_MAGIC		0x1BADB002
38 #define MULTIBOOT_HEADER_MODS_ALIGNED	0x00000001
39 #define MULTIBOOT_HEADER_WANT_MEMORY	0x00000002
40 #define MULTIBOOT_HEADER_HAS_VBE	0x00000004
41 #define MULTIBOOT_HEADER_HAS_ADDR	0x00010000
42 
43 #if defined(_LOCORE)
44 #define MULTIBOOT2_HEADER_MAGIC		0xe85250d6
45 #define MULTIBOOT2_BOOTLOADER_MAGIC	0x36d76289
46 #define MULTIBOOT2_ARCHITECTURE_I386	0
47 #endif
48 
49 #if !defined(_LOCORE)
50 struct multiboot_header {
51 	uint32_t	mh_magic;
52 	uint32_t	mh_flags;
53 	uint32_t	mh_checksum;
54 
55 	/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
56 	paddr_t		mh_header_addr;
57 	paddr_t		mh_load_addr;
58 	paddr_t		mh_load_end_addr;
59 	paddr_t		mh_bss_end_addr;
60 	paddr_t		mh_entry_addr;
61 
62 	/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */
63 	uint32_t	mh_mode_type;
64 	uint32_t	mh_width;
65 	uint32_t	mh_height;
66 	uint32_t	mh_depth;
67 };
68 #endif /* !defined(_LOCORE) */
69 
70 /*
71  * Symbols defined in locore.S.
72  */
73 #if !defined(_LOCORE) && defined(_KERNEL)
74 extern struct multiboot_header *Multiboot_Header;
75 #endif /* !defined(_LOCORE) && defined(_KERNEL) */
76 
77 /* --------------------------------------------------------------------- */
78 
79 /*
80  * Multiboot information structure.
81  */
82 #define MULTIBOOT_INFO_MAGIC		0x2BADB002
83 #define MULTIBOOT_INFO_HAS_MEMORY	0x00000001
84 #define MULTIBOOT_INFO_HAS_BOOT_DEVICE	0x00000002
85 #define MULTIBOOT_INFO_HAS_CMDLINE	0x00000004
86 #define MULTIBOOT_INFO_HAS_MODS		0x00000008
87 #define MULTIBOOT_INFO_HAS_AOUT_SYMS	0x00000010
88 #define MULTIBOOT_INFO_HAS_ELF_SYMS	0x00000020
89 #define MULTIBOOT_INFO_HAS_MMAP		0x00000040
90 #define MULTIBOOT_INFO_HAS_DRIVES	0x00000080
91 #define MULTIBOOT_INFO_HAS_CONFIG_TABLE	0x00000100
92 #define MULTIBOOT_INFO_HAS_LOADER_NAME	0x00000200
93 #define MULTIBOOT_INFO_HAS_APM_TABLE	0x00000400
94 #define MULTIBOOT_INFO_HAS_VBE		0x00000800
95 #define MULTIBOOT_INFO_HAS_FRAMEBUFFER	0x00001000
96 
97 #if !defined(_LOCORE)
98 struct multiboot_info {
99 	uint32_t	mi_flags;
100 
101 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */
102 	uint32_t	mi_mem_lower;
103 	uint32_t	mi_mem_upper;
104 
105 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */
106 	uint8_t		mi_boot_device_part3;
107 	uint8_t		mi_boot_device_part2;
108 	uint8_t		mi_boot_device_part1;
109 	uint8_t		mi_boot_device_drive;
110 
111 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */
112 	char *		mi_cmdline;
113 
114 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */
115 	uint32_t	mi_mods_count;
116 	vaddr_t		mi_mods_addr;
117 
118 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */
119 	uint32_t	mi_elfshdr_num;
120 	uint32_t	mi_elfshdr_size;
121 	vaddr_t		mi_elfshdr_addr;
122 	uint32_t	mi_elfshdr_shndx;
123 
124 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */
125 	uint32_t	mi_mmap_length;
126 	vaddr_t		mi_mmap_addr;
127 
128 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */
129 	uint32_t	mi_drives_length;
130 	vaddr_t		mi_drives_addr;
131 
132 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */
133 	void *		unused_mi_config_table;
134 
135 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */
136 	char *		mi_loader_name;
137 
138 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */
139 	void *		unused_mi_apm_table;
140 
141 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */
142 	void *		unused_mi_vbe_control_info;
143 	void *		unused_mi_vbe_mode_info;
144 	uint16_t	unused_mi_vbe_mode;
145 	uint16_t	unused_mi_vbe_interface_seg;
146 	uint16_t	unused_mi_vbe_interface_off;
147 	uint16_t	unused_mi_vbe_interface_len;
148 
149 	/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_FRAMEBUFFER. */
150 	uint64_t	framebuffer_addr;
151 	uint32_t	framebuffer_pitch;
152 	uint32_t	framebuffer_width;
153 	uint32_t	framebuffer_height;
154 	uint8_t		framebuffer_bpp;
155 #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 	0
156 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB     	1
157 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT     2
158 	uint8_t framebuffer_type;
159 	union {
160 		struct {
161 			uint32_t framebuffer_palette_addr;
162 			uint16_t framebuffer_palette_num_colors;
163 		};
164 		struct {
165 			uint8_t framebuffer_red_field_position;
166 			uint8_t framebuffer_red_mask_size;
167 			uint8_t framebuffer_green_field_position;
168 			uint8_t framebuffer_green_mask_size;
169 			uint8_t framebuffer_blue_field_position;
170 			uint8_t framebuffer_blue_mask_size;
171 		};
172 	};
173 
174 };
175 
176 /* --------------------------------------------------------------------- */
177 
178 /*
179  * Drive information.  This describes an entry in the drives table as
180  * pointed to by mi_drives_addr.
181  */
182 struct multiboot_drive {
183 	uint32_t	md_length;
184 	uint8_t		md_number;
185 	uint8_t		md_mode;
186 	uint16_t	md_cylinders;
187 	uint8_t		md_heads;
188 	uint8_t		md_sectors;
189 
190 	/* The variable-sized 'ports' field comes here, so this structure
191 	 * can be longer. */
192 };
193 
194 /* --------------------------------------------------------------------- */
195 
196 /*
197  * Memory mapping.  This describes an entry in the memory mappings table
198  * as pointed to by mi_mmap_addr.
199  *
200  * Be aware that mm_size specifies the size of all other fields *except*
201  * for mm_size.  In order to jump between two different entries, you
202  * have to count mm_size + 4 bytes.
203  */
204 struct multiboot_mmap {
205 	uint32_t	mm_size;
206 	uint64_t	mm_base_addr;
207 	uint64_t	mm_length;
208 	uint32_t	mm_type;
209 };
210 
211 /*
212  * Modules. This describes an entry in the modules table as pointed
213  * to by mi_mods_addr.
214  */
215 
216 struct multiboot_module {
217 	uint32_t	mmo_start;
218 	uint32_t	mmo_end;
219 	char *		mmo_string;
220 	uint32_t	mmo_reserved;
221 };
222 
223 #endif /* !defined(_LOCORE) */
224 
225 /* --------------------------------------------------------------------- */
226 
227 /*
228  * Prototypes for public functions defined in multiboot.c and multiboot2.c
229  */
230 #if !defined(_LOCORE) && defined(_KERNEL)
231 void		multiboot1_pre_reloc(struct multiboot_info *);
232 void		multiboot1_post_reloc(void);
233 void		multiboot1_print_info(void);
234 bool		multiboot1_ksyms_addsyms_elf(void);
235 
236 void		multiboot2_pre_reloc(struct multiboot_info *);
237 void		multiboot2_post_reloc(void);
238 void		multiboot2_print_info(void);
239 bool		multiboot2_ksyms_addsyms_elf(void);
240 #endif /* !defined(_LOCORE) */
241 
242 /* --------------------------------------------------------------------- */
243