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