@@ -95,26 +95,26 @@ Memory Layout
9595The traditional memory map for the kernel loader, used for Image or
9696zImage kernels, typically looks like::
9797
98- | |
98+ | |
9999 0A0000 +------------------------+
100- | Reserved for BIOS | Do not use. Reserved for BIOS EBDA.
100+ | Reserved for BIOS | Do not use. Reserved for BIOS EBDA.
101101 09A000 +------------------------+
102- | Command line |
103- | Stack/heap | For use by the kernel real-mode code.
102+ | Command line |
103+ | Stack/heap | For use by the kernel real-mode code.
104104 098000 +------------------------+
105- | Kernel setup | The kernel real-mode code.
105+ | Kernel setup | The kernel real-mode code.
106106 090200 +------------------------+
107- | Kernel boot sector | The kernel legacy boot sector.
107+ | Kernel boot sector | The kernel legacy boot sector.
108108 090000 +------------------------+
109- | Protected-mode kernel | The bulk of the kernel image.
109+ | Protected-mode kernel | The bulk of the kernel image.
110110 010000 +------------------------+
111- | Boot loader | <- Boot sector entry point 0000:7C00
111+ | Boot loader | <- Boot sector entry point 0000:7C00
112112 001000 +------------------------+
113- | Reserved for MBR/BIOS |
113+ | Reserved for MBR/BIOS |
114114 000800 +------------------------+
115- | Typically used by MBR |
115+ | Typically used by MBR |
116116 000600 +------------------------+
117- | BIOS use only |
117+ | BIOS use only |
118118 000000 +------------------------+
119119
120120When using bzImage, the protected-mode kernel was relocated to
@@ -142,27 +142,27 @@ above the 0x9A000 point; too many BIOSes will break above that point.
142142For a modern bzImage kernel with boot protocol version >= 2.02, a
143143memory layout like the following is suggested::
144144
145- ~ ~
146- | Protected-mode kernel |
145+ ~ ~
146+ | Protected-mode kernel |
147147 100000 +------------------------+
148- | I/O memory hole |
148+ | I/O memory hole |
149149 0A0000 +------------------------+
150- | Reserved for BIOS | Leave as much as possible unused
151- ~ ~
152- | Command line | (Can also be below the X+10000 mark)
150+ | Reserved for BIOS | Leave as much as possible unused
151+ ~ ~
152+ | Command line | (Can also be below the X+10000 mark)
153153 X+10000 +------------------------+
154- | Stack/heap | For use by the kernel real-mode code.
154+ | Stack/heap | For use by the kernel real-mode code.
155155 X+08000 +------------------------+
156- | Kernel setup | The kernel real-mode code.
157- | Kernel boot sector | The kernel legacy boot sector.
156+ | Kernel setup | The kernel real-mode code.
157+ | Kernel boot sector | The kernel legacy boot sector.
158158 X +------------------------+
159- | Boot loader | <- Boot sector entry point 0000:7C00
159+ | Boot loader | <- Boot sector entry point 0000:7C00
160160 001000 +------------------------+
161- | Reserved for MBR/BIOS |
161+ | Reserved for MBR/BIOS |
162162 000800 +------------------------+
163- | Typically used by MBR |
163+ | Typically used by MBR |
164164 000600 +------------------------+
165- | BIOS use only |
165+ | BIOS use only |
166166 000000 +------------------------+
167167
168168 ... where the address X is as low as the design of the boot loader permits.
@@ -433,7 +433,7 @@ Protocol: 2.00+
433433
434434 Assigned boot loader IDs:
435435
436- == =======================================
436+ ==== =======================================
437437 0x0 LILO
438438 (0x00 reserved for pre-2.00 bootloader)
439439 0x1 Loadlin
@@ -456,7 +456,7 @@ Protocol: 2.00+
456456 <http://sebastian-plotz.blogspot.de>
457457 0x12 OVMF UEFI virtualization stack
458458 0x13 barebox
459- == =======================================
459+ ==== =======================================
460460
461461 Please contact <hpa@zytor.com> if you need a bootloader ID value assigned.
462462
@@ -809,12 +809,12 @@ Protocol: 2.09+
809809 as follow::
810810
811811 struct setup_data {
812- __u64 next;
813- __u32 type;
814- __u32 len;
815- __u8 data[];
812+ __u64 next;
813+ __u32 type;
814+ __u32 len;
815+ __u8 data[];
816816 }
817-
817+
818818 Where, the next is a 64-bit physical pointer to the next node of
819819 linked list, the next field of the last node is 0; the type is used
820820 to identify the contents of data; the len is the length of data
@@ -835,10 +835,10 @@ Protocol: 2.09+
835835 protocol 2.15::
836836
837837 struct setup_indirect {
838- __u32 type;
839- __u32 reserved; /* Reserved, must be set to zero. */
840- __u64 len;
841- __u64 addr;
838+ __u32 type;
839+ __u32 reserved; /* Reserved, must be set to zero. */
840+ __u64 len;
841+ __u64 addr;
842842 };
843843
844844 The type member is a SETUP_INDIRECT | SETUP_* type. However, it cannot be
@@ -850,15 +850,15 @@ Protocol: 2.09+
850850 In this case setup_data and setup_indirect will look like this::
851851
852852 struct setup_data {
853- .next = 0, /* or <addr_of_next_setup_data_struct> */
854- .type = SETUP_INDIRECT,
855- .len = sizeof(setup_indirect),
856- .data[sizeof(setup_indirect)] = (struct setup_indirect) {
857- .type = SETUP_INDIRECT | SETUP_E820_EXT,
858- .reserved = 0,
859- .len = <len_of_SETUP_E820_EXT_data>,
860- .addr = <addr_of_SETUP_E820_EXT_data>,
861- },
853+ .next = 0, /* or <addr_of_next_setup_data_struct> */
854+ .type = SETUP_INDIRECT,
855+ .len = sizeof(setup_indirect),
856+ .data[sizeof(setup_indirect)] = (struct setup_indirect) {
857+ .type = SETUP_INDIRECT | SETUP_E820_EXT,
858+ .reserved = 0,
859+ .len = <len_of_SETUP_E820_EXT_data>,
860+ .addr = <addr_of_SETUP_E820_EXT_data>,
861+ },
862862 }
863863
864864.. note ::
@@ -897,11 +897,11 @@ Offset/size: 0x260/4
897897 The kernel runtime start address is determined by the following algorithm::
898898
899899 if (relocatable_kernel) {
900- if (load_address < pref_address)
901- load_address = pref_address;
902- runtime_start = align_up(load_address, kernel_alignment);
900+ if (load_address < pref_address)
901+ load_address = pref_address;
902+ runtime_start = align_up(load_address, kernel_alignment);
903903 } else {
904- runtime_start = pref_address;
904+ runtime_start = pref_address;
905905 }
906906
907907Hence the necessary memory window location and size can be estimated by
@@ -975,22 +975,22 @@ after kernel_info_var_len_data label. Each chunk of variable size data has to
975975be prefixed with header/magic and its size, e.g.::
976976
977977 kernel_info:
978- .ascii "LToP" /* Header, Linux top (structure). */
979- .long kernel_info_var_len_data - kernel_info
980- .long kernel_info_end - kernel_info
981- .long 0x01234567 /* Some fixed size data for the bootloaders. */
978+ .ascii "LToP" /* Header, Linux top (structure). */
979+ .long kernel_info_var_len_data - kernel_info
980+ .long kernel_info_end - kernel_info
981+ .long 0x01234567 /* Some fixed size data for the bootloaders. */
982982 kernel_info_var_len_data:
983983 example_struct: /* Some variable size data for the bootloaders. */
984- .ascii "0123" /* Header/Magic. */
985- .long example_struct_end - example_struct
986- .ascii "Struct"
987- .long 0x89012345
984+ .ascii "0123" /* Header/Magic. */
985+ .long example_struct_end - example_struct
986+ .ascii "Struct"
987+ .long 0x89012345
988988 example_struct_end:
989989 example_strings: /* Some variable size data for the bootloaders. */
990- .ascii "ABCD" /* Header/Magic. */
991- .long example_strings_end - example_strings
992- .asciz "String_0"
993- .asciz "String_1"
990+ .ascii "ABCD" /* Header/Magic. */
991+ .long example_strings_end - example_strings
992+ .asciz "String_0"
993+ .asciz "String_1"
994994 example_strings_end:
995995 kernel_info_end:
996996
@@ -1132,53 +1132,53 @@ Such a boot loader should enter the following fields in the header::
11321132 unsigned long base_ptr; /* base address for real-mode segment */
11331133
11341134 if (setup_sects == 0)
1135- setup_sects = 4;
1135+ setup_sects = 4;
11361136
11371137 if (protocol >= 0x0200) {
1138- type_of_loader = <type code>;
1139- if (loading_initrd) {
1140- ramdisk_image = <initrd_address>;
1141- ramdisk_size = <initrd_size>;
1142- }
1143-
1144- if (protocol >= 0x0202 && loadflags & 0x01)
1145- heap_end = 0xe000;
1146- else
1147- heap_end = 0x9800;
1148-
1149- if (protocol >= 0x0201) {
1150- heap_end_ptr = heap_end - 0x200;
1151- loadflags |= 0x80; /* CAN_USE_HEAP */
1152- }
1153-
1154- if (protocol >= 0x0202) {
1155- cmd_line_ptr = base_ptr + heap_end;
1156- strcpy(cmd_line_ptr, cmdline);
1157- } else {
1158- cmd_line_magic = 0xA33F;
1159- cmd_line_offset = heap_end;
1160- setup_move_size = heap_end + strlen(cmdline) + 1;
1161- strcpy(base_ptr + cmd_line_offset, cmdline);
1162- }
1138+ type_of_loader = <type code>;
1139+ if (loading_initrd) {
1140+ ramdisk_image = <initrd_address>;
1141+ ramdisk_size = <initrd_size>;
1142+ }
1143+
1144+ if (protocol >= 0x0202 && loadflags & 0x01)
1145+ heap_end = 0xe000;
1146+ else
1147+ heap_end = 0x9800;
1148+
1149+ if (protocol >= 0x0201) {
1150+ heap_end_ptr = heap_end - 0x200;
1151+ loadflags |= 0x80; /* CAN_USE_HEAP */
1152+ }
1153+
1154+ if (protocol >= 0x0202) {
1155+ cmd_line_ptr = base_ptr + heap_end;
1156+ strcpy(cmd_line_ptr, cmdline);
1157+ } else {
1158+ cmd_line_magic = 0xA33F;
1159+ cmd_line_offset = heap_end;
1160+ setup_move_size = heap_end + strlen(cmdline) + 1;
1161+ strcpy(base_ptr + cmd_line_offset, cmdline);
1162+ }
11631163 } else {
1164- /* Very old kernel */
1164+ /* Very old kernel */
11651165
1166- heap_end = 0x9800;
1166+ heap_end = 0x9800;
11671167
1168- cmd_line_magic = 0xA33F;
1169- cmd_line_offset = heap_end;
1168+ cmd_line_magic = 0xA33F;
1169+ cmd_line_offset = heap_end;
11701170
1171- /* A very old kernel MUST have its real-mode code loaded at 0x90000 */
1172- if (base_ptr != 0x90000) {
1173- / * Copy the real-mode kernel */
1174- memcpy(0x90000, base_ptr, (setup_sects + 1) * 512);
1175- base_ptr = 0x90000; / * Relocated */
1176- }
1171+ /* A very old kernel MUST have its real-mode code loaded at 0x90000 */
1172+ if (base_ptr != 0x90000) {
1173+ / * Copy the real-mode kernel */
1174+ memcpy(0x90000, base_ptr, (setup_sects + 1) * 512);
1175+ base_ptr = 0x90000; / * Relocated */
1176+ }
11771177
1178- strcpy(0x90000 + cmd_line_offset, cmdline);
1178+ strcpy(0x90000 + cmd_line_offset, cmdline);
11791179
1180- /* It is recommended to clear memory up to the 32K mark */
1181- memset(0x90000 + (setup_sects + 1) * 512, 0, (64 - (setup_sects + 1)) * 512);
1180+ /* It is recommended to clear memory up to the 32K mark */
1181+ memset(0x90000 + (setup_sects + 1) * 512, 0, (64 - (setup_sects + 1)) * 512);
11821182 }
11831183
11841184
0 commit comments