blob: ae747e6c5ecb5fea964c15f0cefbadb0c88e6ade [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>
Curt Brune3c12cb02014-08-29 10:43:36 -070029#include "linux_trampoline.h"
Patrick Georgide36d332013-08-27 20:22:21 +020030
31typedef uint8_t u8;
32typedef uint16_t u16;
33typedef uint32_t u32;
34typedef uint64_t u64;
35
Patrick Georgide36d332013-08-27 20:22:21 +020036#define E820MAX 32 /* number of entries in E820MAP */
37struct e820entry {
38 unsigned long long addr; /* start of memory segment */
39 unsigned long long size; /* size of memory segment */
40 unsigned long type; /* type of memory segment */
41#define E820_RAM 1
42#define E820_RESERVED 2
43#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */
44#define E820_NVS 4
45};
46
47/* The header of Linux/i386 kernel */
48struct linux_header {
49 u8 reserved1[0x1f1]; /* 0x000 */
50 u8 setup_sects; /* 0x1f1 */
51 u16 root_flags; /* 0x1f2 */
52 u32 syssize; /* 0x1f4 (2.04+) */
53 u8 reserved2[2]; /* 0x1f8 */
54 u16 vid_mode; /* 0x1fa */
55 u16 root_dev; /* 0x1fc */
56 u16 boot_sector_magic; /* 0x1fe */
57 /* 2.00+ */
58 u8 reserved3[2]; /* 0x200 */
59 u8 header_magic[4]; /* 0x202 */
60 u16 protocol_version; /* 0x206 */
61 u32 realmode_swtch; /* 0x208 */
62 u16 start_sys; /* 0x20c */
63 u16 kver_addr; /* 0x20e */
64 u8 type_of_loader; /* 0x210 */
65 u8 loadflags; /* 0x211 */
66 u16 setup_move_size; /* 0x212 */
67 u32 code32_start; /* 0x214 */
68 u32 ramdisk_image; /* 0x218 */
69 u32 ramdisk_size; /* 0x21c */
70 u8 reserved4[4]; /* 0x220 */
71 /* 2.01+ */
72 u16 heap_end_ptr; /* 0x224 */
73 u8 reserved5[2]; /* 0x226 */
74 /* 2.02+ */
75 u32 cmd_line_ptr; /* 0x228 */
76 /* 2.03+ */
77 u32 initrd_addr_max; /* 0x22c */
78 /* 2.05+ */
79 u32 kernel_alignment; /* 0x230 */
80 u8 relocatable_kernel; /* 0x234 */
81 u8 min_alignment; /* 0x235 (2.10+) */
82 u8 reserved6[2]; /* 0x236 */
83 /* 2.06+ */
84 u32 cmdline_size; /* 0x238 */
85 /* 2.07+ */
86 u32 hardware_subarch; /* 0x23c */
87 u64 hardware_subarch_data;/* 0x240 */
88 /* 2.08+ */
89 u32 payload_offset; /* 0x248 */
90 u32 payload_length; /* 0x24c */
91 /* 2.09+ */
92 u64 setup_data; /* 0x250 */
93 /* 2.10+ */
94 u64 pref_address; /* 0x258 */
95 u32 init_size; /* 0x260 */
96} __attribute__ ((packed));
97
98/* Paramters passed to 32-bit part of Linux
99 * This is another view of the structure above.. */
100struct linux_params {
101 u8 orig_x; /* 0x00 */
102 u8 orig_y; /* 0x01 */
103 u16 ext_mem_k; /* 0x02 -- EXT_MEM_K sits here */
104 u16 orig_video_page; /* 0x04 */
105 u8 orig_video_mode; /* 0x06 */
106 u8 orig_video_cols; /* 0x07 */
107 u16 unused2; /* 0x08 */
108 u16 orig_video_ega_bx; /* 0x0a */
109 u16 unused3; /* 0x0c */
110 u8 orig_video_lines; /* 0x0e */
111 u8 orig_video_isVGA; /* 0x0f */
112 u16 orig_video_points; /* 0x10 */
113
114 /* VESA graphic mode -- linear frame buffer */
115 u16 lfb_width; /* 0x12 */
116 u16 lfb_height; /* 0x14 */
117 u16 lfb_depth; /* 0x16 */
118 u32 lfb_base; /* 0x18 */
119 u32 lfb_size; /* 0x1c */
120 u16 cl_magic; /* 0x20 */
121#define CL_MAGIC_VALUE 0xA33F
122 u16 cl_offset; /* 0x22 */
123 u16 lfb_linelength; /* 0x24 */
124 u8 red_size; /* 0x26 */
125 u8 red_pos; /* 0x27 */
126 u8 green_size; /* 0x28 */
127 u8 green_pos; /* 0x29 */
128 u8 blue_size; /* 0x2a */
129 u8 blue_pos; /* 0x2b */
130 u8 rsvd_size; /* 0x2c */
131 u8 rsvd_pos; /* 0x2d */
132 u16 vesapm_seg; /* 0x2e */
133 u16 vesapm_off; /* 0x30 */
134 u16 pages; /* 0x32 */
135 u8 reserved4[12]; /* 0x34 -- 0x3f reserved for future expansion */
136
137 //struct apm_bios_info apm_bios_info; /* 0x40 */
138 u8 apm_bios_info[0x40];
139 //struct drive_info_struct drive_info; /* 0x80 */
140 u8 drive_info[0x20];
141 //struct sys_desc_table sys_desc_table; /* 0xa0 */
142 u8 sys_desc_table[0x140];
143 u32 alt_mem_k; /* 0x1e0 */
144 u8 reserved5[4]; /* 0x1e4 */
145 u8 e820_map_nr; /* 0x1e8 */
146 u8 reserved6[9]; /* 0x1e9 */
147 u16 mount_root_rdonly; /* 0x1f2 */
148 u8 reserved7[4]; /* 0x1f4 */
149 u16 ramdisk_flags; /* 0x1f8 */
150#define RAMDISK_IMAGE_START_MASK 0x07FF
151#define RAMDISK_PROMPT_FLAG 0x8000
152#define RAMDISK_LOAD_FLAG 0x4000
153 u8 reserved8[2]; /* 0x1fa */
154 u16 orig_root_dev; /* 0x1fc */
155 u8 reserved9[1]; /* 0x1fe */
156 u8 aux_device_info; /* 0x1ff */
157 u8 reserved10[2]; /* 0x200 */
158 u8 param_block_signature[4]; /* 0x202 */
159 u16 param_block_version; /* 0x206 */
160 u8 reserved11[8]; /* 0x208 */
161 u8 loader_type; /* 0x210 */
162#define LOADER_TYPE_LOADLIN 1
163#define LOADER_TYPE_BOOTSECT_LOADER 2
164#define LOADER_TYPE_SYSLINUX 3
165#define LOADER_TYPE_ETHERBOOT 4
166#define LOADER_TYPE_KERNEL 5
167 u8 loader_flags; /* 0x211 */
168 u8 reserved12[2]; /* 0x212 */
169 u32 kernel_start; /* 0x214 */
170 u32 initrd_start; /* 0x218 */
171 u32 initrd_size; /* 0x21c */
172 u8 reserved12_5[8]; /* 0x220 */
173 u32 cmd_line_ptr; /* 0x228 */
174 u32 initrd_addr_max; /* 0x22c */
175 u32 kernel_alignment; /* 0x230 */
176 u8 relocatable_kernel; /* 0x234 */
177 u8 reserved13[155]; /* 0x22c */
178 struct e820entry e820_map[E820MAX]; /* 0x2d0 */
179 u8 reserved16[688]; /* 0x550 */
180#define COMMAND_LINE_SIZE 256
181 /* Command line is copied here by 32-bit i386/kernel/head.S.
182 * So I will follow the boot protocol, rather than putting it
183 * directly here. --ts1 */
184 u8 command_line[COMMAND_LINE_SIZE]; /* 0x800 */
185 u8 reserved17[1792]; /* 0x900 - 0x1000 */
186};
187