Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 1 | /* |
| 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 Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 12 | */ |
| 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 Brune | 3c12cb0 | 2014-08-29 10:43:36 -0700 | [diff] [blame] | 25 | #include "linux_trampoline.h" |
Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 26 | |
| 27 | typedef uint8_t u8; |
| 28 | typedef uint16_t u16; |
| 29 | typedef uint32_t u32; |
| 30 | typedef uint64_t u64; |
| 31 | |
Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 32 | #define E820MAX 32 /* number of entries in E820MAP */ |
| 33 | struct e820entry { |
Werner Zeh | ebf732b | 2016-03-02 17:55:31 +0100 | [diff] [blame] | 34 | u64 addr; /* start of memory segment */ |
| 35 | u64 size; /* size of memory segment */ |
| 36 | u32 type; /* type of memory segment */ |
Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 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 */ |
| 44 | struct 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 */ |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 92 | } __packed; |
Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 93 | |
Elyes HAOUAS | 3db0198 | 2018-08-23 18:08:20 +0200 | [diff] [blame] | 94 | /* Parameters passed to 32-bit part of Linux |
Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 95 | * This is another view of the structure above.. */ |
| 96 | struct 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 */ |
Ronald G. Minnich | fa74e47 | 2016-09-28 10:43:12 -0700 | [diff] [blame] | 142 | u8 reserved6[8]; /* 0x1e9 */ |
| 143 | /* This next variable is to show where |
| 144 | * in this struct the Linux setup_hdr |
| 145 | * is located. It does not get filled in. |
| 146 | * We may someday find it useful to use |
| 147 | * its address. */ |
| 148 | u8 setup_hdr; /* 0x1f1 */ |
Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 149 | u16 mount_root_rdonly; /* 0x1f2 */ |
| 150 | u8 reserved7[4]; /* 0x1f4 */ |
| 151 | u16 ramdisk_flags; /* 0x1f8 */ |
Elyes HAOUAS | 5bc61da | 2018-05-29 22:27:51 +0200 | [diff] [blame] | 152 | #define RAMDISK_IMAGE_START_MASK 0x07FF |
Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 153 | #define RAMDISK_PROMPT_FLAG 0x8000 |
| 154 | #define RAMDISK_LOAD_FLAG 0x4000 |
| 155 | u8 reserved8[2]; /* 0x1fa */ |
| 156 | u16 orig_root_dev; /* 0x1fc */ |
| 157 | u8 reserved9[1]; /* 0x1fe */ |
| 158 | u8 aux_device_info; /* 0x1ff */ |
| 159 | u8 reserved10[2]; /* 0x200 */ |
| 160 | u8 param_block_signature[4]; /* 0x202 */ |
| 161 | u16 param_block_version; /* 0x206 */ |
| 162 | u8 reserved11[8]; /* 0x208 */ |
| 163 | u8 loader_type; /* 0x210 */ |
| 164 | #define LOADER_TYPE_LOADLIN 1 |
| 165 | #define LOADER_TYPE_BOOTSECT_LOADER 2 |
| 166 | #define LOADER_TYPE_SYSLINUX 3 |
| 167 | #define LOADER_TYPE_ETHERBOOT 4 |
| 168 | #define LOADER_TYPE_KERNEL 5 |
| 169 | u8 loader_flags; /* 0x211 */ |
| 170 | u8 reserved12[2]; /* 0x212 */ |
| 171 | u32 kernel_start; /* 0x214 */ |
| 172 | u32 initrd_start; /* 0x218 */ |
| 173 | u32 initrd_size; /* 0x21c */ |
| 174 | u8 reserved12_5[8]; /* 0x220 */ |
| 175 | u32 cmd_line_ptr; /* 0x228 */ |
| 176 | u32 initrd_addr_max; /* 0x22c */ |
| 177 | u32 kernel_alignment; /* 0x230 */ |
| 178 | u8 relocatable_kernel; /* 0x234 */ |
Ronald G. Minnich | fa74e47 | 2016-09-28 10:43:12 -0700 | [diff] [blame] | 179 | u8 reserved13[0x2b]; /* 0x235 */ |
| 180 | u32 init_size; /* 0x260 */ |
| 181 | u8 reserved14[0x6c]; /* 0x264 */ |
Patrick Georgi | de36d33 | 2013-08-27 20:22:21 +0200 | [diff] [blame] | 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 | }; |