github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/boot/bzimage/header.go (about)

     1  // Copyright 2015-2018 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package bzimage
     6  
     7  // These are the semi-documented things that define a bzImage
     8  // Thanks to coreboot for documenting the basic layout.
     9  
    10  const (
    11  	Ram      e820type = 1
    12  	Reserved e820type = 2
    13  	ACPI     e820type = 3
    14  	NVS      e820type = 4
    15  )
    16  
    17  const (
    18  	NotSet    boottype = 0
    19  	LoadLin   boottype = 1
    20  	BootSect  boottype = 2
    21  	SysLinux  boottype = 3
    22  	EtherBoot boottype = 4
    23  	Kernel    boottype = 5
    24  )
    25  
    26  const (
    27  	RamdiskStartMask = 0x07FF
    28  	Prompt           = 0x8000
    29  	Load             = 0x4000
    30  
    31  	CommandLineMagic = 0x7ff
    32  	CommandLineSize  = 256
    33  
    34  	DefaultInitrdAddrMax  = 0x37FFFFFF
    35  	DefaultBzimageAddrMax = 0x37FFFFFF
    36  
    37  	E820Max = 128
    38  	E820Map = 0x2d0
    39  	E820NR  = 0x1e8
    40  )
    41  
    42  // what's an EDD? No idea.
    43  /*
    44   * EDD stuff
    45   */
    46  
    47  const (
    48  	EDDMBRSigMax       = 16
    49  	EDDMaxNR           = 6 /* number of edd_info structs starting at EDDBUF  */
    50  	EDDDeviceParamSize = 74
    51  )
    52  
    53  const (
    54  	EDDExtFixedDiskAccess = 1 << iota
    55  	EDDExtDeviceLockingAndEjecting
    56  	EDDExtEnhancedDiskDriveSupport
    57  	EDDExt64BitExtensions
    58  )
    59  
    60  type EDDInfo struct {
    61  	Device                uint8
    62  	Version               uint8
    63  	InterfaceSupport      uint16
    64  	LegacyMaxCylinder     uint16
    65  	LegacyMaxHead         uint8
    66  	LegacySectorsPerTrace uint8
    67  	EDDDeviceParams       [EDDDeviceParamSize]uint8
    68  }
    69  
    70  type e820type uint32
    71  type boottype uint8
    72  type E820Entry struct {
    73  	Addr    uint64
    74  	Size    uint64
    75  	MemType e820type
    76  }
    77  
    78  // The header of Linux/i386 kernel
    79  type LinuxHeader struct {
    80  	MBRCode         [0xc0]uint8         `offset:"0x000"`
    81  	ExtRamdiskImage uint32              `offset:"0xc0"`
    82  	ExtRamdiskSize  uint32              `offset:"0xc4"`
    83  	ExtCmdlinePtr   uint32              `offset:"0xc8"`
    84  	O               [0x1f1 - 0xcc]uint8 `offset:"0xcc"`
    85  	SetupSects      uint8               `offset:"0x1f1"`
    86  	RootFlags       uint16              `offset:"0x1f2"`
    87  	Syssize         uint32              `offset:"0x1f4"` //(2.04+)
    88  	RamSize         uint16              `offset:"0x1f8"`
    89  	Vidmode         uint16              `offset:"0x1fa"`
    90  	RootDev         uint16              `offset:"0x1fc"`
    91  	Bootsectormagic uint16              `offset:"0x1fe"`
    92  	// 0.00+
    93  	Jump            uint16   `offset:"0x200"`
    94  	HeaderMagic     [4]uint8 `offset:"0x202"`
    95  	Protocolversion uint16   `offset:"0x206"`
    96  	RealModeSwitch  uint32   `offset:"0x208"`
    97  	StartSys        uint16   `offset:"0x20c"`
    98  	Kveraddr        uint16   `offset:"0x20e"`
    99  	TypeOfLoader    uint8    `offset:"0x210"`
   100  	Loadflags       uint8    `offset:"0x211"`
   101  	Setupmovesize   uint16   `offset:"0x212"`
   102  	Code32Start     uint32   `offset:"0x214"`
   103  	RamDiskImage    uint32   `offset:"0x218"`
   104  	RamDiskSize     uint32   `offset:"0x21c"`
   105  	BootSectKludge  [4]uint8 `offset:"0x220"`
   106  	// 2.01+
   107  	Heapendptr    uint16 `offset:"0x224"`
   108  	ExtLoaderVer  uint8  `offset:"0x226"`
   109  	ExtLoaderType uint8  `offset:"0x227"`
   110  	// 2.02+
   111  	Cmdlineptr uint32 `offset:"0x228"`
   112  	// 2.03+
   113  	InitrdAddrMax uint32 `offset:"0x22c"`
   114  	// 2.05+
   115  	Kernelalignment   uint32 `offset:"0x230"`
   116  	RelocatableKernel uint8  `offset:"0x234"`
   117  	MinAlignment      uint8  `offset:"0x235"` //(2.10+)
   118  	XLoadFlags        uint16 `offset:"0x236"`
   119  	// 2.06+
   120  	CmdLineSize uint32 `offset:"0x238"`
   121  	// 2.07+
   122  	HardwareSubArch     uint32 `offset:"0x23c"`
   123  	HardwareSubArchData uint64 `offset:"0x240"`
   124  	// 2.08+
   125  	PayloadOffset uint32 `offset:"0x248"`
   126  	PayloadSize   uint32 `offset:"0x24c"`
   127  	// 2.09+
   128  	SetupData uint64 `offset:"0x250"`
   129  	// 2.10+
   130  	PrefAddress    uint64 `offset:"0x258"`
   131  	InitSize       uint32 `offset:"0x260"`
   132  	HandoverOffset uint32 `offset:"0x264"`
   133  }
   134  
   135  // Parameters passed to 32-bit part of Linux
   136  type LinuxParams struct {
   137  	Origx           uint8  `offset:"0x00"`
   138  	Origy           uint8  `offset:"0x01"`
   139  	ExtMemK         uint16 `offset:"0x02"` //-- EXTMEMK sits here
   140  	OrigVideoPage   uint16 `offset:"0x04"`
   141  	OrigVideoMode   uint8  `offset:"0x06"`
   142  	OrigVideoCols   uint8  `offset:"0x07"`
   143  	_               uint16 `offset:"0x08"`
   144  	OrigVideoeGabx  uint16 `offset:"0x0a"`
   145  	_               uint16 `offset:"0x0c"`
   146  	OrigVideoLines  uint8  `offset:"0x0e"`
   147  	OrigVideoIsVGA  uint8  `offset:"0x0f"`
   148  	OrigVideoPoints uint16 `offset:"0x10"`
   149  
   150  	// VESA graphic mode -- linear frame buffer
   151  	Lfbwidth      uint16    `offset:"0x12"`
   152  	Lfbheight     uint16    `offset:"0x14"`
   153  	Lfbdepth      uint16    `offset:"0x16"`
   154  	Lfbbase       uint32    `offset:"0x18"`
   155  	Lfbsize       uint32    `offset:"0x1c"`
   156  	CLMagic       uint16    `offset:"0x20"` // DON'T USE
   157  	CLOffset      uint16    `offset:"0x22"` // DON'T USE
   158  	Lfblinelength uint16    `offset:"0x24"`
   159  	Redsize       uint8     `offset:"0x26"`
   160  	Redpos        uint8     `offset:"0x27"`
   161  	Greensize     uint8     `offset:"0x28"`
   162  	Greenpos      uint8     `offset:"0x29"`
   163  	Bluesize      uint8     `offset:"0x2a"`
   164  	Bluepos       uint8     `offset:"0x2b"`
   165  	Rsvdsize      uint8     `offset:"0x2c"`
   166  	Rsvdpos       uint8     `offset:"0x2d"`
   167  	Vesapmseg     uint16    `offset:"0x2e"`
   168  	Vesapmoff     uint16    `offset:"0x30"`
   169  	Pages         uint16    `offset:"0x32"`
   170  	_             [12]uint8 `offset:"0x34"` //-- 0x3f reserved for future expansion
   171  
   172  	//struct apmbiosinfo apmbiosinfo;
   173  	Apmbiosinfo [0x40]uint8 `offset:"0x40"`
   174  	//struct driveinfostruct driveinfo;
   175  	Driveinfo [0x20]uint8 `offset:"0x80"`
   176  	//struct sysdesctable sysdesctable;
   177  	Sysdesctable        [0x140]uint8 `offset:"0xa0"`
   178  	Altmemk             uint32       `offset:"0x1e0"`
   179  	_                   [4]uint8     `offset:"0x1e4"`
   180  	E820MapNr           uint8        `offset:"0x1e8"`
   181  	_                   [9]uint8     `offset:"0x1e9"`
   182  	MountRootReadonly   uint16       `offset:"0x1f2"`
   183  	_                   [4]uint8     `offset:"0x1f4"`
   184  	Ramdiskflags        uint16       `offset:"0x1f8"`
   185  	_                   [2]uint8     `offset:"0x1fa"`
   186  	OrigRootDev         uint16       `offset:"0x1fc"`
   187  	_                   [1]uint8     `offset:"0x1fe"`
   188  	Auxdeviceinfo       uint8        `offset:"0x1ff"`
   189  	_                   [2]uint8     `offset:"0x200"`
   190  	Paramblocksignature [4]uint8     `offset:"0x202"`
   191  	Paramblockversion   uint16       `offset:"0x206"`
   192  	_                   [8]uint8     `offset:"0x208"`
   193  	LoaderType          uint8        `offset:"0x210"`
   194  	Loaderflags         uint8        `offset:"0x211"`
   195  	_                   [2]uint8     `offset:"0x212"`
   196  	KernelStart         uint32       `offset:"0x214"`
   197  	Initrdstart         uint32       `offset:"0x218"`
   198  	Initrdsize          uint32       `offset:"0x21c"`
   199  	_                   [8]uint8     `offset:"0x220"`
   200  	CLPtr               uint32       `offset:"0x228"` // USE THIS.
   201  	InitrdAddrMax       uint32       `offset:"0x22c"`
   202  	/* 2.04+ */
   203  	KernelAlignment     uint32               `offset:"0x230"`
   204  	RelocatableKernel   uint8                `offset:"0x234"`
   205  	MinAlignment        uint8                `offset:"0x235"`
   206  	XLoadFlags          uint16               `offset:"0x236"`
   207  	CmdLineSize         uint32               `offset:"0x238"`
   208  	HardwareSubarch     uint32               `offset:"0x23C"`
   209  	HardwareSubarchData uint64               `offset:"0x240"`
   210  	Payload_Ofset       uint32               `offset:"0x248"`
   211  	PayloadLength       uint32               `offset:"0x24C"`
   212  	SetupData           uint64               `offset:"0x250"`
   213  	PrefAddress         uint64               `offset:"0x258"`
   214  	InitSize            uint32               `offset:"0x260"`
   215  	HandoverOffset      uint32               `offset:"0x264"`
   216  	_                   [0x290 - 0x268]uint8 `offset:"0x268"`
   217  	EDDMBRSigBuffer     [EDDMBRSigMax]uint32 `offset:"0x290"`
   218  	// e820map is another cockup from the usual suspects.
   219  	// Go rounds the size to something reasonable. Oh well. No checking for you.
   220  	// So the next two offsets are bogus, sorry about that.
   221  	E820Map [E820Max]E820Entry `offset:"0x2d0"`
   222  	// we lie.
   223  	_      [48]uint8         `offset:"0xed0"` // `offset:"0xcd0"`
   224  	EDDBuf [EDDMaxNR]EDDInfo `offset:"0xf00"` // `offset:"0xd00"`
   225  
   226  }
   227  
   228  var (
   229  	LoaderType = map[boottype]string{
   230  		NotSet:    "Not set",
   231  		LoadLin:   "loadlin",
   232  		BootSect:  "bootsector",
   233  		SysLinux:  "syslinux",
   234  		EtherBoot: "etherboot",
   235  		Kernel:    "kernel (kexec)",
   236  	}
   237  	E820 = map[e820type]string{
   238  		Ram:      "Ram",
   239  		Reserved: "Reserved",
   240  		ACPI:     "ACPI",
   241  		NVS:      "NVS",
   242  	}
   243  	HeaderMagic = [4]uint8{'H', 'd', 'r', 'S'}
   244  )
   245  
   246  type BzImage struct {
   247  	Header       LinuxHeader
   248  	BootCode     []byte
   249  	HeadCode     []byte
   250  	KernelCode   []byte
   251  	TailCode     []byte
   252  	KernelBase   uintptr
   253  	KernelOffset uintptr
   254  	compressed   []byte
   255  }