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