I did some copyediting whilst looking through Documentation/x86/boot.txt; this email contains a pull request as well as the inlined diff of all the changes squashed together. Documentation/x86/boot.txt | 396 ++++++++++++++++++++++---------------------- 1 files changed, 202 insertions(+), 194 deletions(-) If you don't want to read through all of the changes, then my advice is to commit them and wait for somebody to complain :-) After all, Wikipedia gets by all right with such a model. The changes apply cleanly to commit a6360dd37e1a144ed11e6548371bade559a1e4df: Linux 2.6.39-rc3 (2011-04-11 17:21:51 -0700) and are available here: git://github.com/mfwitten/linux-2.6.git trivial/docs/boot Squash them as desired: [00] Docs: boot.txt: `syssize' -> `sys_size' [01] Docs: Consistently use 2 spaces between sentences [02] Docs: Use the subjunctive mood [03] Docs: Clean up sentences [04] Docs: Add parentheses and a comma to improve flow [05] Docs: Remove bizarrely embedded tabs [06] Docs: Make protocol version descriptions consistent. [07] Docs: Remove commas [08] Docs: Use present tense [09] Docs: Remove awkward infinitive [10] Docs: Add periods to have consistent diagrams [11] Docs: Move definition of `X' upwards [12] Docs: Remove details described later [13] Docs: Better heap_end_ptr description [14] Docs: Clarify the meaning of a 0 value for setup_sects [15] Docs: Streamline introduction of `read' and `write' fields [16] Docs: Put `(obligatory)' in double quotes [17] Docs: `who' is reserved for humans; `that' should be used. [18] Docs: Put `(reloc)' in double quotes [19] Docs: `can' -> `may' [20] Docs: `littleendian' -> `little-endian' [21] Docs: Offset each modifier with a comma [22] Docs: `device device' is a little silly [23] Docs: Move period outside of parentheses [24] Docs: Add a subject to make a full sentence [25] Docs: `id' -> `ID' [26] Docs: Clarify code32_start description [27] Docs: `;' -> `,' [28] Docs: `uncompress' -> `decompress' [29] Docs: Remove superfluous `linear' [30] Docs: Add `;' to end of pseudo-code lines [31] Docs: Streamline discussion of the kernel command line [32] Docs: Streamline the real-mode allocation requirement [33] Docs: Use ISO units and consistent language [34] Docs: Use `neither...nor...' [35] Docs: Use `[Rr]eal-mode' consistently [36] Docs: Use quotes for grouping [37] Docs: `32-bit (non-real-mode)' -> `protected-mode' [38] Docs: Clean up discussion of the 32-bit protocol diff --git a/Documentation/x86/boot.txt b/Documentation/x86/boot.txt index 9b7221a..7696e20 100644 --- a/Documentation/x86/boot.txt +++ b/Documentation/x86/boot.txt @@ -2,9 +2,9 @@ --------------------------- On the x86 platform, the Linux kernel uses a rather complicated boot -convention. This has evolved partially due to historical aspects, as +convention. This has evolved partially due to historical aspects (as well as the desire in the early days to have the kernel itself be a -bootable image, the complicated PC memory model and due to changed +bootable image), the complicated PC memory model, and new expectations in the PC industry caused by the effective demise of real-mode DOS as a mainstream operating system. @@ -15,49 +15,49 @@ Old kernels: zImage/Image support only. Some very early kernels Protocol 2.00: (Kernel 1.3.73) Added bzImage and initrd support, as well as a formalized way to communicate between the - boot loader and the kernel. setup.S made relocatable, - although the traditional setup area still assumed + boot loader and the kernel. setup.S was made relocatable, + although the traditional setup area was still assumed to be writable. Protocol 2.01: (Kernel 1.3.76) Added a heap overrun warning. -Protocol 2.02: (Kernel 2.4.0-test3-pre3) New command line protocol. - Lower the conventional memory ceiling. No overwrite - of the traditional setup area, thus making booting +Protocol 2.02: (Kernel 2.4.0-test3-pre3) Added a new command line protocol, + lowered the conventional memory ceiling, stopped overwriting + the traditional setup area (thus making booting safe for systems which use the EBDA from SMM or 32-bit - BIOS entry points. zImage deprecated but still - supported. + BIOS entry points), and deprecated but still + supported zImage. -Protocol 2.03: (Kernel 2.4.18-pre1) Explicitly makes the highest possible +Protocol 2.03: (Kernel 2.4.18-pre1) Explicitly made the highest possible initrd address available to the bootloader. -Protocol 2.04: (Kernel 2.6.14) Extend the syssize field to four bytes. +Protocol 2.04: (Kernel 2.6.14) Extended the sys_size field to four bytes. -Protocol 2.05: (Kernel 2.6.20) Make protected mode kernel relocatable. - Introduce relocatable_kernel and kernel_alignment fields. +Protocol 2.05: (Kernel 2.6.20) Made the protected mode kernel relocatable, + and introduced relocatable_kernel and kernel_alignment fields. Protocol 2.06: (Kernel 2.6.22) Added a field that contains the size of the boot command line. -Protocol 2.07: (Kernel 2.6.24) Added paravirtualised boot protocol. - Introduced hardware_subarch and hardware_subarch_data - and KEEP_SEGMENTS flag in load_flags. +Protocol 2.07: (Kernel 2.6.24) Added paravirtualized boot protocol, + introduced hardware_subarch and hardware_subarch_data + fields, and added the KEEP_SEGMENTS flag in load_flags. -Protocol 2.08: (Kernel 2.6.26) Added crc32 checksum and ELF format - payload. Introduced payload_offset and payload_length - fields to aid in locating the payload. +Protocol 2.08: (Kernel 2.6.26) Added CRC32 checksum and ELF format + payload, and introduced payload_offset and payload_length + fields in order to aid in locating the payload. -Protocol 2.09: (Kernel 2.6.26) Added a field of 64-bit physical - pointer to single linked list of struct setup_data. +Protocol 2.09: (Kernel 2.6.26) Added a field for a 64-bit physical + pointer to point to a singly-linked list of struct setup_data. Protocol 2.10: (Kernel 2.6.31) Added a protocol for relaxed alignment - beyond the kernel_alignment added, new init_size and - pref_address fields. Added extended boot loader IDs. + beyond the kernel_alignment field, introduced the new fields + init_size and pref_address, and added extended boot loader IDs. **** MEMORY LAYOUT -The traditional memory map for the kernel loader, used for Image or -zImage kernels, typically looks like: +The traditional memory map for the kernel loader used for Image or +zImage kernels typically looks like: | | 0A0000 +------------------------+ @@ -82,39 +82,40 @@ zImage kernels, typically looks like: 000000 +------------------------+ -When using bzImage, the protected-mode kernel was relocated to +When using bzImage, the protected-mode kernel is relocated to 0x100000 ("high memory"), and the kernel real-mode block (boot sector, -setup, and stack/heap) was made relocatable to any address between -0x10000 and end of low memory. Unfortunately, in protocols 2.00 and -2.01 the 0x90000+ memory range is still used internally by the kernel; +setup, and stack/heap) is made relocatable to any address between +0x10000 and the end of low memory. Unfortunately, in protocols 2.00 and +2.01, the 0x90000+ memory range is still used internally by the kernel; the 2.02 protocol resolves that problem. It is desirable to keep the "memory ceiling" -- the highest point in low memory touched by the boot loader -- as low as possible, since some newer BIOSes have begun to allocate some rather large amounts of -memory, called the Extended BIOS Data Area, near the top of low -memory. The boot loader should use the "INT 12h" BIOS call to verify +memory (called the Extended BIOS Data Area) near the top of low +memory. The boot loader should use the "INT 12h" BIOS call to verify how much low memory is available. Unfortunately, if INT 12h reports that the amount of memory is too -low, there is usually nothing the boot loader can do but to report an +low, there is usually nothing the boot loader can do but report an error to the user. The boot loader should therefore be designed to take up as little space in low memory as it reasonably can. For zImage or old bzImage kernels, which need data written into the 0x90000 segment, the boot loader should make sure not to use memory -above the 0x9A000 point; too many BIOSes will break above that point. +above the 0x9A000 point; too many BIOSes break above that point. For a modern bzImage kernel with boot protocol version >= 2.02, a -memory layout like the following is suggested: +memory layout like the following is suggested (the address X is as +low as the design of the boot loader permits): ~ ~ | Protected-mode kernel | 100000 +------------------------+ | I/O memory hole | 0A0000 +------------------------+ - | Reserved for BIOS | Leave as much as possible unused + | Reserved for BIOS | Leave as much as possible unused. ~ ~ - | Command line | (Can also be below the X+10000 mark) + | Command line | (Can also be below the X+10000 mark). X+10000 +------------------------+ | Stack/heap | For use by the kernel real-mode code. X+08000 +------------------------+ @@ -130,9 +131,6 @@ X +------------------------+ | BIOS use only | 000000 +------------------------+ -... where the address X is as low as the design of the boot loader -permits. - **** THE REAL-MODE KERNEL HEADER @@ -153,7 +151,7 @@ Offset Proto Name Meaning 01F1/1 ALL(1 setup_sects The size of the setup in sectors 01F2/2 ALL root_flags If set, the root is mounted readonly -01F4/4 2.04+(2 syssize The size of the 32-bit code in 16-byte paras +01F4/4 2.04+(2 sys_size The size of the 32-bit code 01F8/2 ALL ram_size DO NOT USE - for bootsect.S use only 01FA/2 ALL vid_mode Video mode control 01FC/2 ALL root_dev Default root device number @@ -171,7 +169,7 @@ Offset Proto Name Meaning 0218/4 2.00+ ramdisk_image initrd load address (set by boot loader) 021C/4 2.00+ ramdisk_size initrd size (set by boot loader) 0220/4 2.00+ bootsect_kludge DO NOT USE - for bootsect.S use only -0224/2 2.01+ heap_end_ptr Free memory after setup end +0224/2 2.01+ heap_end_ptr Offset of the end of the setup stack/heap 0226/1 2.02+(3 ext_loader_ver Extended boot loader version 0227/1 2.02+(3 ext_loader_type Extended boot loader ID 0228/4 2.02+ cmd_line_ptr 32-bit pointer to the kernel command line @@ -190,10 +188,10 @@ Offset Proto Name Meaning 0258/8 2.10+ pref_address Preferred loading address 0260/4 2.10+ init_size Linear memory required during initialization -(1) For backwards compatibility, if the setup_sects field contains 0, the - real value is 4. +(1) For backwards compatibility, if the setup_sects field contains 0, then + it is treated as though the field contained 4. -(2) For boot protocol prior to 2.04, the upper two bytes of the syssize +(2) For boot protocol prior to 2.04, the upper two bytes of the sys_size field are unusable, which means the size of a bzImage kernel cannot be determined. @@ -207,33 +205,33 @@ following parameters should be assumed: initrd not supported Real-mode kernel must be located at 0x90000. -Otherwise, the "version" field contains the protocol version, -e.g. protocol version 2.01 will contain 0x0201 in this field. When +Otherwise, the "version" field contains the protocol version; for example, +protocol version 2.01 is represented by 0x0201 in this field. When setting fields in the header, you must make sure only to set fields supported by the protocol version in use. **** DETAILS OF HEADER FIELDS -For each field, some are information from the kernel to the bootloader -("read"), some are expected to be filled out by the bootloader -("write"), and some are expected to be read and modified by the -bootloader ("modify"). +Some fields provide information from the kernel for the bootloader +("read" fields), some fields provide information from the bootloader +for the kernel ("write" fields), and some are both read and write +fields ("modify" fields). All general purpose boot loaders should write the fields marked -(obligatory). Boot loaders who want to load the kernel at a -nonstandard address should fill in the fields marked (reloc); other -boot loaders can ignore those fields. +"(obligatory)". Boot loaders that want to load the kernel at a +nonstandard address should fill in the fields marked "(reloc)"; other +boot loaders may ignore those fields. -The byte order of all fields is littleendian (this is x86, after all.) +The byte order of all fields is little-endian (this is x86, after all.) Field name: setup_sects Type: read Offset/size: 0x1f1/1 Protocol: ALL - The size of the setup code in 512-byte sectors. If this field is - 0, the real value is 4. The real-mode code consists of the boot + The size of the setup code in 512-byte sectors. If this field is 0, then + it is treated as though it were 4. The real-mode code consists of the boot sector (always one 512-byte sector) plus the setup code. Field name: root_flags @@ -245,14 +243,14 @@ Protocol: ALL this field is deprecated; use the "ro" or "rw" options on the command line instead. -Field name: syssize +Field name: sys_size Type: read Offset/size: 0x1f4/4 (protocol 2.04+) 0x1f4/2 (protocol ALL) Protocol: 2.04+ The size of the protected-mode code in units of 16-byte paragraphs. - For protocol versions older than 2.04 this field is only two bytes - wide, and therefore cannot be trusted for the size of a kernel if + For protocol versions older than 2.04, this field is only two bytes + wide and therefore cannot be trusted for the size of a kernel if the LOAD_HIGH flag is set. Field name: ram_size @@ -273,8 +271,8 @@ Type: modify (optional) Offset/size: 0x1fc/2 Protocol: ALL - The default root device device number. The use of this field is - deprecated, use the "root=" option on the command line instead. + The default device number of the root device. The use of this field is + deprecated; use the "root=" option on the command line instead. Field name: boot_flag Type: read @@ -305,16 +303,16 @@ Type: read Offset/size: 0x206/2 Protocol: 2.00+ - Contains the boot protocol version, in (major << 8)+minor format, - e.g. 0x0204 for version 2.04, and 0x0a11 for a hypothetical version - 10.17. + Contains the boot protocol version in "(major << 8)+minor" format + (e.g. 0x0204 for version 2.04 and 0x0a11 for a hypothetical version + 10.17). Field name: realmode_swtch Type: modify (optional) Offset/size: 0x208/4 Protocol: 2.00+ - Boot loader hook (see ADVANCED BOOT LOADER HOOKS below.) + Boot loader hook (see ADVANCED BOOT LOADER HOOKS below). Field name: start_sys_seg Type: read @@ -328,7 +326,7 @@ Type: read Offset/size: 0x20e/2 Protocol: 2.00+ - If set to a nonzero value, contains a pointer to a NUL-terminated + If set to a nonzero value, it contains a pointer to a NUL-terminated human-readable kernel version number string, less 0x200. This can be used to display the kernel version to the user. This value should be less than (0x200*setup_sects). @@ -348,7 +346,7 @@ Type: write (obligatory) Offset/size: 0x210/1 Protocol: 2.00+ - If your boot loader has an assigned id (see table below), enter + If your boot loader has an assigned ID (see table below), enter 0xTV here, where T is an identifier for the boot loader and V is a version number. Otherwise, enter 0xFF here. @@ -363,7 +361,7 @@ Protocol: 2.00+ ext_loader_type <- 0x05 ext_loader_ver <- 0x23 - Assigned boot loader ids: + Assigned boot loader IDs: 0 LILO (0x00 reserved for pre-2.00 bootloader) 1 Loadlin 2 bootsect-loader (0x20, all other values reserved) @@ -389,15 +387,15 @@ Protocol: 2.00+ This field is a bitmask. - Bit 0 (read): LOADED_HIGH + Bit 0 (read): LOADED_HIGH - If 0, the protected-mode code is loaded at 0x10000. - If 1, the protected-mode code is loaded at 0x100000. Bit 5 (write): QUIET_FLAG - If 0, print early messages. - If 1, suppress early messages. - This requests to the kernel (decompressor and early - kernel) to not write early messages that require + This requests the kernel (decompressor and early + kernel) not write early messages that require accessing the display hardware directly. Bit 6 (write): KEEP_SEGMENTS @@ -410,7 +408,7 @@ Protocol: 2.00+ Bit 7 (write): CAN_USE_HEAP Set this bit to 1 to indicate that the value entered in the heap_end_ptr is valid. If this field is clear, some setup code - functionality will be disabled. + functionality is disabled. Field name: setup_move_size Type: modify (obligatory) @@ -425,7 +423,7 @@ Protocol: 2.00-2.01 The unit is bytes starting with the beginning of the boot sector. - This field is can be ignored when the protocol is 2.02 or higher, or + This field may be ignored when the protocol is 2.02 or higher, or if the real-mode code is loaded at 0x90000. Field name: code32_start @@ -433,7 +431,8 @@ Type: modify (optional, reloc) Offset/size: 0x214/4 Protocol: 2.00+ - The address to jump to in protected mode. This defaults to the load + The address to which control jumps immediately after entering protected + mode but before the kernel is decompressed. This defaults to the load address of the kernel, and can be used by the boot loader to determine the proper load address. @@ -442,7 +441,7 @@ Protocol: 2.00+ 1. as a boot loader hook (see ADVANCED BOOT LOADER HOOKS below.) 2. if a bootloader which does not install a hook loads a - relocatable kernel at a nonstandard address it will have to modify + relocatable kernel at a nonstandard address, it must modify this field to point to the load address. Field name: ramdisk_image @@ -538,25 +537,25 @@ Type: read/modify (reloc) Offset/size: 0x230/4 Protocol: 2.05+ (read), 2.10+ (modify) - Alignment unit required by the kernel (if relocatable_kernel is + The alignment unit required by the kernel (if relocatable_kernel is true.) A relocatable kernel that is loaded at an alignment - incompatible with the value in this field will be realigned during + incompatible with the value in this field is realigned during kernel initialization. - Starting with protocol version 2.10, this reflects the kernel + Starting with protocol version 2.10, this field reflects the kernel alignment preferred for optimal performance; it is possible for the loader to modify this field to permit a lesser alignment. See the - min_alignment and pref_address field below. + min_alignment and pref_address fields. Field name: relocatable_kernel Type: read (reloc) Offset/size: 0x234/1 Protocol: 2.05+ - If this field is nonzero, the protected-mode part of the kernel can + If this field is nonzero, the protected-mode part of the kernel may be loaded at any address that satisfies the kernel_alignment field. After loading, the boot loader must set the code32_start field to - point to the loaded code, or to a boot loader hook. + point to the loaded code or to a boot loader hook. Field name: min_alignment Type: read (reloc) @@ -564,9 +563,9 @@ Offset/size: 0x235/1 Protocol: 2.10+ This field, if nonzero, indicates as a power of two the minimum - alignment required, as opposed to preferred, by the kernel to boot. + alignment required (as opposed to preferred) for the kernel to boot. If a boot loader makes use of this field, it should update the - kernel_alignment field with the alignment unit desired; typically: + kernel_alignment field with the alignment unit desired, typically: kernel_alignment = 1 << min_alignment @@ -580,20 +579,20 @@ Offset/size: 0x238/4 Protocol: 2.06+ The maximum size of the command line without the terminating - zero. This means that the command line can contain at most - cmdline_size characters. With protocol version 2.05 and earlier, the - maximum size was 255. + zero. This means that the command line may contain at most + cmdline_size characters. With protocol version 2.05 and earlier, the + maximum size is 255. Field name: hardware_subarch Type: write (optional, defaults to x86/PC) Offset/size: 0x23c/4 Protocol: 2.07+ - In a paravirtualized environment the hardware low level architectural - pieces such as interrupt handling, page table handling, and - accessing process control registers needs to be done differently. + In a paravirtualized environment, the low-level architectural hardware + pieces (such as interrupt handling, page table handling, and + accessing process control registers) need to be done differently. - This field allows the bootloader to inform the kernel we are in one + This field allows the bootloader to inform the kernel that it is in one one of those environments. 0x00000000 The default x86/PC environment @@ -607,7 +606,7 @@ Type: write (subarch-dependent) Offset/size: 0x240/8 Protocol: 2.07+ - A pointer to data that is specific to hardware subarch + A pointer to data that is specific to a hardware subarchitecture. This field is currently unused for the default x86/PC environment, do not modify. @@ -619,11 +618,11 @@ Protocol: 2.08+ If non-zero then this field contains the offset from the beginning of the protected-mode code to the payload. - The payload may be compressed. The format of both the compressed and - uncompressed data should be determined using the standard magic + The payload may be compressed. The format of both the compressed and + decompressed data should be determined using the standard magic numbers. The currently supported compression formats are gzip (magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A), LZMA - (magic number 5D 00), and XZ (magic number FD 37). The uncompressed + (magic number 5D 00), and XZ (magic number FD 37). The decompressed payload is currently always ELF (magic number 7F 45 4C 46). Field name: payload_length @@ -638,10 +637,9 @@ Type: write (special) Offset/size: 0x250/8 Protocol: 2.09+ - The 64-bit physical pointer to NULL terminated single linked list of - struct setup_data. This is used to define a more extensible boot - parameters passing mechanism. The definition of struct setup_data is - as follow: + A 64-bit physical pointer to point to a NULL-terminated singly-linked list of + struct setup_data. This is used to define a more extensible mechanism for + passing boot parameters. The definition of struct setup_data is as follows: struct setup_data { u64 next; @@ -650,13 +648,16 @@ Protocol: 2.09+ u8 data[0]; }; - Where, the next is a 64-bit physical pointer to the next node of - linked list, the next field of the last node is 0; the type is used - to identify the contents of data; the len is the length of data - field; the data holds the real payload. + where: + + "next" is a 64-bit physical pointer that points to the next node of the + linked list (the "next" field of the last node is NULL). + "type" is used to identify the contents of "data". + "len" is the length of the "data". + "data" is the real payload. - This list may be modified at a number of points during the bootup - process. Therefore, when modifying this list one should always make + This singly-linked list may be modified at a number of points during the bootup + process. Therefore, when modifying this list, one should always make sure to consider the case where the linked list already contains entries. @@ -669,15 +670,15 @@ Protocol: 2.10+ kernel. A relocating bootloader should attempt to load at this address if possible. - A non-relocatable kernel will unconditionally move itself and to run + A non-relocatable kernel unconditionally moves itself to run at this address. Field name: init_size Type: read Offset/size: 0x25c/4 - This field indicates the amount of linear contiguous memory starting - at the kernel runtime start address that the kernel needs before it + This field indicates the amount of contiguous memory (starting + at the kernel runtime start address) needed before the kernel is capable of examining its memory map. This is not the same thing as the total amount of memory the kernel needs to boot, but it can be used by a relocating boot loader to help select a safe load @@ -686,35 +687,35 @@ Offset/size: 0x25c/4 The kernel runtime start address is determined by the following algorithm: if (relocatable_kernel) - runtime_start = align_up(load_address, kernel_alignment) + runtime_start = align_up(load_address, kernel_alignment); else - runtime_start = pref_address + runtime_start = pref_address; **** THE IMAGE CHECKSUM -From boot protocol version 2.08 onwards the CRC-32 is calculated over +From boot protocol version 2.08 onwards, the CRC-32 is calculated over the entire file using the characteristic polynomial 0x04C11DB7 and an initial remainder of 0xffffffff. The checksum is appended to the -file; therefore the CRC of the file up to the limit specified in the -syssize field of the header is always 0. +file; therefore, the CRC of the file up to the limit specified in the +sys_size field of the header is always 0. **** THE KERNEL COMMAND LINE The kernel command line has become an important way for the boot loader to communicate with the kernel. Some of its options are also -relevant to the boot loader itself, see "special command line options" -below. +relevant to the boot loader itself (see "special command line options"). -The kernel command line is a null-terminated string. The maximum -length can be retrieved from the field cmdline_size. Before protocol -version 2.06, the maximum was 255 characters. A string that is too -long will be automatically truncated by the kernel. +The kernel command line is a null-terminated string, the maximum length +of which (excluding the terminating null character) can be retrieved +from the field cmdline_size. For protocols prior to version 2.06, the +maximum is 255 characters; a string that is too long is automatically +truncated. If the boot protocol version is 2.02 or later, the address of the -kernel command line is given by the header field cmd_line_ptr (see -above.) This address can be anywhere between the end of the setup +kernel command line is given by the header field cmd_line_ptr. +This address can be anywhere between the end of the setup heap and 0xA0000. If the protocol version is *not* 2.02 or higher, the kernel @@ -731,16 +732,15 @@ command line is entered using the following protocol: covered by setup_move_size, so you may need to adjust this field. - **** MEMORY LAYOUT OF THE REAL-MODE CODE -The real-mode code requires a stack/heap to be set up, as well as -memory allocated for the kernel command line. This needs to be done -in the real-mode accessible memory in bottom megabyte. +The real-mode code requires that memory be allocated for both a stack/heap +and the kernel command line; the allocated memory needs to be accessible +while in real mode (basically, it needs to be within the bottom mebibyte). It should be noted that modern machines often have a sizable Extended BIOS Data Area (EBDA). As a result, it is advisable to use as little -of the low megabyte as possible. +of the bottom mebibyte as possible. Unfortunately, under the following circumstances the 0x90000 memory segment has to be used: @@ -749,41 +749,41 @@ segment has to be used: - When loading a 2.01 or earlier boot protocol kernel. -> For the 2.00 and 2.01 boot protocols, the real-mode code - can be loaded at another address, but it is internally + may be loaded at another address, but it is internally relocated to 0x90000. For the "old" protocol, the real-mode code must be loaded at 0x90000. When loading at 0x90000, avoid using memory above 0x9a000. For boot protocol 2.02 or higher, the command line does not have to be -located in the same 64K segment as the real-mode setup code; it is -thus permitted to give the stack/heap the full 64K segment and locate +located in the same 64KiB segment as the real-mode setup code; it is +thus permitted to give the stack/heap the full 64KiB segment and locate the command line above it. -The kernel command line should not be located below the real-mode -code, nor should it be located in high memory. +The kernel command line should be located neither below the real-mode +code nor in high memory. **** SAMPLE BOOT CONFIGURATION -As a sample configuration, assume the following layout of the real -mode segment: +As a sample configuration, assume the following layout of the real-mode +segment: When loading below 0x90000, use the entire segment: - 0x0000-0x7fff Real mode kernel + 0x0000-0x7fff Real-mode kernel 0x8000-0xdfff Stack and heap 0xe000-0xffff Kernel command line When loading at 0x90000 OR the protocol version is 2.01 or earlier: - 0x0000-0x7fff Real mode kernel + 0x0000-0x7fff Real-mode kernel 0x8000-0x97ff Stack and heap 0x9800-0x9fff Kernel command line Such a boot loader should enter the following fields in the header: - unsigned long base_ptr; /* base address for real-mode segment */ + unsigned long base_ptr; /* base address for real-mode segment */ if ( setup_sects == 0 ) { setup_sects = 4; @@ -810,7 +810,7 @@ Such a boot loader should enter the following fields in the header: cmd_line_ptr = base_ptr + heap_end; strcpy(cmd_line_ptr, cmdline); } else { - cmd_line_magic = 0xA33F; + cmd_line_magic = 0xA33F; cmd_line_offset = heap_end; setup_move_size = heap_end + strlen(cmdline)+1; strcpy(base_ptr+cmd_line_offset, cmdline); @@ -820,7 +820,7 @@ Such a boot loader should enter the following fields in the header: heap_end = 0x9800; - cmd_line_magic = 0xA33F; + cmd_line_magic = 0xA33F; cmd_line_offset = heap_end; /* A very old kernel MUST have its real-mode code @@ -829,7 +829,7 @@ Such a boot loader should enter the following fields in the header: if ( base_ptr != 0x90000 ) { /* Copy the real-mode kernel */ memcpy(0x90000, base_ptr, (setup_sects+1)*512); - base_ptr = 0x90000; /* Relocated */ + base_ptr = 0x90000; /* Relocated */ } strcpy(0x90000+cmd_line_offset, cmdline); @@ -842,21 +842,21 @@ Such a boot loader should enter the following fields in the header: **** LOADING THE REST OF THE KERNEL -The 32-bit (non-real-mode) kernel starts at offset (setup_sects+1)*512 -in the kernel file (again, if setup_sects == 0 the real value is 4.) -It should be loaded at address 0x10000 for Image/zImage kernels and +The protected-mode kernel starts at offset "(setup_sects+1)*512" +in the kernel file (again, if (setup_sects == 0) { setup_sects = 4; }). +It should be loaded at address 0x10000 for Image/zImage kernels and at 0x100000 for bzImage kernels. The kernel is a bzImage kernel if the protocol >= 2.00 and the 0x01 -bit (LOAD_HIGH) in the loadflags field is set: +bit (LOAD_HIGH) is set in the loadflags field: is_bzImage = (protocol >= 0x0200) && (loadflags & 0x01); load_address = is_bzImage ? 0x100000 : 0x10000; -Note that Image/zImage kernels can be up to 512K in size, and thus use +Note that Image/zImage kernels may be up to 512KiB in size and thus use the entire 0x10000-0x90000 range of memory. This means it is pretty much a requirement for these kernels to load the real-mode part at -0x90000. bzImage kernels allow much more flexibility. +0x90000; bzImage kernels allow much more flexibility. **** SPECIAL COMMAND LINE OPTIONS @@ -879,11 +879,11 @@ conflict with actual kernel options now or in the future. line is parsed. mem=<size> - <size> is an integer in C notation optionally followed by + <size> is an integer in C notation, optionally followed by (case insensitive) K, M, G, T, P or E (meaning << 10, << 20, << 30, << 40, << 50 or << 60). This specifies the end of - memory to the kernel. This affects the possible placement of - an initrd, since an initrd should be placed near end of + memory to the kernel. This affects the possible placement of + an initrd because an initrd should be placed near the end of memory. Note that this is an option to *both* the kernel and the bootloader! @@ -892,34 +892,34 @@ conflict with actual kernel options now or in the future. obviously bootloader-dependent, and some boot loaders (e.g. LILO) do not have such a command. -In addition, some boot loaders add the following options to the +In addition, some boot loaders allow the following options on the user-specified command line: BOOT_IMAGE=<file> - The boot image which was loaded. Again, the meaning of <file> + The boot image which is loaded. Again, the meaning of <file> is obviously bootloader-dependent. auto - The kernel was booted without explicit user intervention. + The kernel is booted without explicit user intervention. If these options are added by the boot loader, it is highly -recommended that they are located *first*, before the user-specified -or configuration-specified command line. Otherwise, "init=/bin/sh" +recommended that they be located *first* (before the user-specified +or configuration-specified command line). Otherwise, "init=/bin/sh" gets confused by the "auto" option. **** RUNNING THE KERNEL The kernel is started by jumping to the kernel entry point, which is -located at *segment* offset 0x20 from the start of the real mode -kernel. This means that if you loaded your real-mode kernel code at +located at *segment* offset 0x20 from the start of the real-mode +kernel. This means that if you load your real-mode kernel code at 0x90000, the kernel entry point is 9020:0000. At entry, ds = es = ss should point to the start of the real-mode kernel code (0x9000 if the code is loaded at 0x90000), sp should be set up properly, normally pointing to the top of the heap, and interrupts should be disabled. Furthermore, to guard against bugs in -the kernel, it is recommended that the boot loader sets fs = gs = ds = +the kernel, it is recommended that the boot loader set fs = gs = ds = es = ss. In our example from above, we would do: @@ -929,17 +929,17 @@ In our example from above, we would do: seg = base_ptr >> 4; - cli(); /* Enter with interrupts disabled! */ + cli(); /* Enter with interrupts disabled! */ /* Set up the real-mode kernel stack */ _SS = seg; _SP = heap_end; _DS = _ES = _FS = _GS = seg; - jmp_far(seg+0x20, 0); /* Run the kernel */ + jmp_far(seg+0x20, 0); /* Run the kernel */ -If your boot sector accesses a floppy drive, it is recommended to -switch off the floppy motor before running the kernel, since the +If the boot sector accesses a floppy drive, it is recommended that +the floppy motor be switched off before running the kernel, because the kernel boot leaves interrupts off and thus the motor will not be switched off, especially if the loaded kernel has the floppy driver as a demand-loaded module! @@ -951,21 +951,21 @@ If the boot loader runs in a particularly hostile environment (such as LOADLIN, which runs under DOS) it may be impossible to follow the standard memory location requirements. Such a boot loader may use the following hooks that, if set, are invoked by the kernel at the -appropriate time. The use of these hooks should probably be +appropriate times. The use of these hooks should probably be considered an absolutely last resort! IMPORTANT: All the hooks are required to preserve %esp, %ebp, %esi and %edi across invocation. realmode_swtch: - A 16-bit real mode far subroutine invoked immediately before + A 16-bit real-mode far subroutine invoked immediately before entering protected mode. The default routine disables NMI, so your routine should probably do so, too. code32_start: - A 32-bit flat-mode routine *jumped* to immediately after the - transition to protected mode, but before the kernel is - uncompressed. No segments, except CS, are guaranteed to be + A 32-bit flat-mode routine to which control *jumps* immediately + after the transition to protected mode but before the kernel is + decompressed. No segments (except CS) are guaranteed to be set up (current kernels do, but older ones do not); you should set them up to BOOT_DS (0x18) yourself. @@ -976,37 +976,45 @@ IMPORTANT: All the hooks are required to preserve %esp, %ebp, %esi and **** 32-bit BOOT PROTOCOL -For machine with some new BIOS other than legacy BIOS, such as EFI, -LinuxBIOS, etc, and kexec, the 16-bit real mode setup code in kernel -based on legacy BIOS can not be used, so a 32-bit boot protocol needs -to be defined. +For a machine with some non-legacy BIOS (such as EFI, LinuxBIOS, kexec, etc.), +the 16-bit real-mode setup code in the kernel (based on legacy BIOSes) cannot +be used, so a 32-bit boot protocol has been defined. -In 32-bit boot protocol, the first step in loading a Linux kernel -should be to setup the boot parameters (struct boot_params, -traditionally known as "zero page"). The memory for struct boot_params -should be allocated and initialized to all zero. Then the setup header -from offset 0x01f1 of kernel image on should be loaded into struct -boot_params and examined. The end of setup header can be calculated as -follow: +Using the 32-bit boot protocol, the first step in loading a Linux kernel is to +set up the boot parameters in struct boot_params (traditionally known as the +"zero page"). The memory for boot_params must be allocated and initialized to +all zeros. Then, the setup header starting at offset 0x01f1 of the kernel image +must be loaded into boot_params for examination; the end of the setup header +can be calculated as follows: 0x0202 + byte value at offset 0x0201 -In addition to read/modify/write the setup header of the struct -boot_params as that of 16-bit boot protocol, the boot loader should -also fill the additional fields of the struct boot_params as that -described in zero-page.txt. - -After setupping the struct boot_params, the boot loader can load the -32/64-bit kernel in the same way as that of 16-bit boot protocol. - -In 32-bit boot protocol, the kernel is started by jumping to the -32-bit kernel entry point, which is the start address of loaded -32/64-bit kernel. - -At entry, the CPU must be in 32-bit protected mode with paging -disabled; a GDT must be loaded with the descriptors for selectors -__BOOT_CS(0x10) and __BOOT_DS(0x18); both descriptors must be 4G flat -segment; __BOOS_CS must have execute/read permission, and __BOOT_DS -must have read/write permission; CS must be __BOOT_CS and DS, ES, SS -must be __BOOT_DS; interrupt must be disabled; %esi must hold the base -address of the struct boot_params; %ebp, %edi and %ebx must be zero. +In addition to filling modify/write fields in the loaded setup header (as +described for the 16-bit boot protocols), the boot loader must also fill the +additional fields that are described in Documentation/x86/zero-page.txt. + +After setting up boot_params, the boot loader may load the 32/64-bit kernel in +the same way as described for the 16-bit boot protocols. + +Next, the kernel is started by jumping to the 32-bit kernel entry point, which +is the start address of the loaded 32/64-bit kernel; the following conditions +must hold upon entry: + + * The CPU must be in 32-bit protected mode with paging disabled + + * Interrupts must be disabled + + * Descriptors for 4GiB flat segments must be loaded in the following + GDT selectors: + + __BOOT_CS (0x10) + __BOOT_DS (0x18) + + * __BOOS_CS must have execute/read permissions + * __BOOT_DS must have read/write permissions + + * CS = __BOOT_CS + * DS = ES = SS = __BOOT_DS + + * %esi = &boot_params + * %ebp = %edi = %ebx = 0 -- -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html