blob: 20837e370725c8dfabc10d07aa4ee2f603a56edd [file] [log] [blame]
Patrick Georgide36d332013-08-27 20:22:21 +02001/*
2 * This file is part of coreboot..
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18/*
19 * Linux/i386 loader
20 * Supports bzImage, zImage and Image format.
21 *
22 * Based on work by Steve Gehlbach.
23 * Portions are taken from mkelfImage.
24 *
25 * 2003-09 by SONE Takeshi
26 */
27
28#include <stdint.h>
29
30typedef uint8_t u8;
31typedef uint16_t u16;
32typedef uint32_t u32;
33typedef uint64_t u64;
34
35#define LINUX_PARAM_LOC 0x90000
36#define COMMAND_LINE_LOC 0x91000
37#define GDT_LOC 0x92000
38#define STACK_LOC 0x93000
39
40#define E820MAX 32 /* number of entries in E820MAP */
41struct e820entry {
42 unsigned long long addr; /* start of memory segment */
43 unsigned long long size; /* size of memory segment */
44 unsigned long type; /* type of memory segment */
45#define E820_RAM 1
46#define E820_RESERVED 2
47#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */
48#define E820_NVS 4
49};
50
51/* The header of Linux/i386 kernel */
52struct linux_header {
53 u8 reserved1[0x1f1]; /* 0x000 */
54 u8 setup_sects; /* 0x1f1 */
55 u16 root_flags; /* 0x1f2 */
56 u32 syssize; /* 0x1f4 (2.04+) */
57 u8 reserved2[2]; /* 0x1f8 */
58 u16 vid_mode; /* 0x1fa */
59 u16 root_dev; /* 0x1fc */
60 u16 boot_sector_magic; /* 0x1fe */
61 /* 2.00+ */
62 u8 reserved3[2]; /* 0x200 */
63 u8 header_magic[4]; /* 0x202 */
64 u16 protocol_version; /* 0x206 */
65 u32 realmode_swtch; /* 0x208 */
66 u16 start_sys; /* 0x20c */
67 u16 kver_addr; /* 0x20e */
68 u8 type_of_loader; /* 0x210 */
69 u8 loadflags; /* 0x211 */
70 u16 setup_move_size; /* 0x212 */
71 u32 code32_start; /* 0x214 */
72 u32 ramdisk_image; /* 0x218 */
73 u32 ramdisk_size; /* 0x21c */
74 u8 reserved4[4]; /* 0x220 */
75 /* 2.01+ */
76 u16 heap_end_ptr; /* 0x224 */
77 u8 reserved5[2]; /* 0x226 */
78 /* 2.02+ */
79 u32 cmd_line_ptr; /* 0x228 */
80 /* 2.03+ */
81 u32 initrd_addr_max; /* 0x22c */
82 /* 2.05+ */
83 u32 kernel_alignment; /* 0x230 */
84 u8 relocatable_kernel; /* 0x234 */
85 u8 min_alignment; /* 0x235 (2.10+) */
86 u8 reserved6[2]; /* 0x236 */
87 /* 2.06+ */
88 u32 cmdline_size; /* 0x238 */
89 /* 2.07+ */
90 u32 hardware_subarch; /* 0x23c */
91 u64 hardware_subarch_data;/* 0x240 */
92 /* 2.08+ */
93 u32 payload_offset; /* 0x248 */
94 u32 payload_length; /* 0x24c */
95 /* 2.09+ */
96 u64 setup_data; /* 0x250 */
97 /* 2.10+ */
98 u64 pref_address; /* 0x258 */
99 u32 init_size; /* 0x260 */
100} __attribute__ ((packed));
101
102/* Paramters passed to 32-bit part of Linux
103 * This is another view of the structure above.. */
104struct linux_params {
105 u8 orig_x; /* 0x00 */
106 u8 orig_y; /* 0x01 */
107 u16 ext_mem_k; /* 0x02 -- EXT_MEM_K sits here */
108 u16 orig_video_page; /* 0x04 */
109 u8 orig_video_mode; /* 0x06 */
110 u8 orig_video_cols; /* 0x07 */
111 u16 unused2; /* 0x08 */
112 u16 orig_video_ega_bx; /* 0x0a */
113 u16 unused3; /* 0x0c */
114 u8 orig_video_lines; /* 0x0e */
115 u8 orig_video_isVGA; /* 0x0f */
116 u16 orig_video_points; /* 0x10 */
117
118 /* VESA graphic mode -- linear frame buffer */
119 u16 lfb_width; /* 0x12 */
120 u16 lfb_height; /* 0x14 */
121 u16 lfb_depth; /* 0x16 */
122 u32 lfb_base; /* 0x18 */
123 u32 lfb_size; /* 0x1c */
124 u16 cl_magic; /* 0x20 */
125#define CL_MAGIC_VALUE 0xA33F
126 u16 cl_offset; /* 0x22 */
127 u16 lfb_linelength; /* 0x24 */
128 u8 red_size; /* 0x26 */
129 u8 red_pos; /* 0x27 */
130 u8 green_size; /* 0x28 */
131 u8 green_pos; /* 0x29 */
132 u8 blue_size; /* 0x2a */
133 u8 blue_pos; /* 0x2b */
134 u8 rsvd_size; /* 0x2c */
135 u8 rsvd_pos; /* 0x2d */
136 u16 vesapm_seg; /* 0x2e */
137 u16 vesapm_off; /* 0x30 */
138 u16 pages; /* 0x32 */
139 u8 reserved4[12]; /* 0x34 -- 0x3f reserved for future expansion */
140
141 //struct apm_bios_info apm_bios_info; /* 0x40 */
142 u8 apm_bios_info[0x40];
143 //struct drive_info_struct drive_info; /* 0x80 */
144 u8 drive_info[0x20];
145 //struct sys_desc_table sys_desc_table; /* 0xa0 */
146 u8 sys_desc_table[0x140];
147 u32 alt_mem_k; /* 0x1e0 */
148 u8 reserved5[4]; /* 0x1e4 */
149 u8 e820_map_nr; /* 0x1e8 */
150 u8 reserved6[9]; /* 0x1e9 */
151 u16 mount_root_rdonly; /* 0x1f2 */
152 u8 reserved7[4]; /* 0x1f4 */
153 u16 ramdisk_flags; /* 0x1f8 */
154#define RAMDISK_IMAGE_START_MASK 0x07FF
155#define RAMDISK_PROMPT_FLAG 0x8000
156#define RAMDISK_LOAD_FLAG 0x4000
157 u8 reserved8[2]; /* 0x1fa */
158 u16 orig_root_dev; /* 0x1fc */
159 u8 reserved9[1]; /* 0x1fe */
160 u8 aux_device_info; /* 0x1ff */
161 u8 reserved10[2]; /* 0x200 */
162 u8 param_block_signature[4]; /* 0x202 */
163 u16 param_block_version; /* 0x206 */
164 u8 reserved11[8]; /* 0x208 */
165 u8 loader_type; /* 0x210 */
166#define LOADER_TYPE_LOADLIN 1
167#define LOADER_TYPE_BOOTSECT_LOADER 2
168#define LOADER_TYPE_SYSLINUX 3
169#define LOADER_TYPE_ETHERBOOT 4
170#define LOADER_TYPE_KERNEL 5
171 u8 loader_flags; /* 0x211 */
172 u8 reserved12[2]; /* 0x212 */
173 u32 kernel_start; /* 0x214 */
174 u32 initrd_start; /* 0x218 */
175 u32 initrd_size; /* 0x21c */
176 u8 reserved12_5[8]; /* 0x220 */
177 u32 cmd_line_ptr; /* 0x228 */
178 u32 initrd_addr_max; /* 0x22c */
179 u32 kernel_alignment; /* 0x230 */
180 u8 relocatable_kernel; /* 0x234 */
181 u8 reserved13[155]; /* 0x22c */
182 struct e820entry e820_map[E820MAX]; /* 0x2d0 */
183 u8 reserved16[688]; /* 0x550 */
184#define COMMAND_LINE_SIZE 256
185 /* Command line is copied here by 32-bit i386/kernel/head.S.
186 * So I will follow the boot protocol, rather than putting it
187 * directly here. --ts1 */
188 u8 command_line[COMMAND_LINE_SIZE]; /* 0x800 */
189 u8 reserved17[1792]; /* 0x900 - 0x1000 */
190};
191