簡(jiǎn)單的引導(dǎo)示例在示例中,我們假設(shè)有實(shí)模式內(nèi)存段布局:
當(dāng)加載內(nèi)核實(shí)模式部分到0x90000后,該內(nèi)存段中的內(nèi)容為:
0x0000-0x7fff 內(nèi)核實(shí)模式部分 0x8000-0xdfff 堆棧 0xe000-0xffff 內(nèi)核命令行
當(dāng)加載內(nèi)核實(shí)模式部分到0x90000或者引導(dǎo)協(xié)議為2.01及之前的版本:
0x0000-0x7fff 內(nèi)核實(shí)模式部分 0x8000-0x97ff 堆棧 0x9800-0x9fff 內(nèi)核命令行
內(nèi)核加載程序應(yīng)該對(duì)數(shù)據(jù)頭做以下檢查:
unsigned long base_ptr; /* base address for real-mode segment */
if ( setup_sects == 0 ) { setup_sects = 4; }
if ( protocol >= 0x0200 ) { type_of_loader = <type code>; if ( loading_initrd ) { ramdisk_image = <initrd_address>; ramdisk_size = <initrd_size>; }
if ( protocol >= 0x0202 && loadflags & 0x01 ) heap_end = 0xe000; else heap_end = 0x9800;
if ( protocol >= 0x0201 ) { heap_end_ptr = heap_end - 0x200; loadflags |= 0x80; /* CAN_USE_HEAP */ }
if ( protocol >= 0x0202 ) { cmd_line_ptr = base_ptr + heap_end; strcpy(cmd_line_ptr, cmdline); } else { cmd_line_magic = 0xA33F; cmd_line_offset = heap_end; setup_move_size = heap_end + strlen(cmdline)+1; strcpy(base_ptr+cmd_line_offset, cmdline); } } else { /* Very old kernel */
heap_end = 0x9800;
cmd_line_magic = 0xA33F; cmd_line_offset = heap_end;
/* A very old kernel MUST have its real-mode code loaded at 0x90000 */
if ( base_ptr != 0x90000 ) { /* Copy the real-mode kernel */ memcpy(0x90000, base_ptr, (setup_sects+1)*512); base_ptr = 0x90000; /* Relocated */ }
strcpy(0x90000+cmd_line_offset, cmdline);
/* It is recommended to clear memory up to the 32K mark */ memset(0x90000 + (setup_sects+1)*512, 0, (64-(setup_sects+1))*512); } 加載內(nèi)核的其余部分內(nèi)核的32位(非實(shí)模式)部分處于內(nèi)核文件的(setup_sects+1)*512偏移處(再次提醒一下,如果setup_sects == 0,其真實(shí)值是4)。如果是Image/zImage類(lèi)型的內(nèi)核,它需要被加載到0x10000處。如果是bzImage類(lèi)型的內(nèi)核則需要加載到0x100000。 如果引導(dǎo)一些大于等于2.00并且loadflags的LOAD_HIGH位置位的話(huà),那么內(nèi)核肯定是bzImage類(lèi)型的。也就是說(shuō),代碼可以寫(xiě)成: 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 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. 需要特別留意的幾個(gè)命令行選項(xiàng)If the command line provided by the boot loader is entered by the user, the user may expect the following command line options to work. They should normally not be deleted from the kernel command line even though not all of them are actually meaningful to the kernel. Boot loader authors who need additional command line options for the boot loader itself should get them registered in Documentation/kernel-parameters.txt to make sure they will not conflict with actual kernel options now or in the future.
vga=<mode> <mode> here is either an integer (in C notation, either decimal, octal, or hexadecimal) or one of the strings "normal" (meaning 0xFFFF), "ext" (meaning 0xFFFE) or "ask" (meaning 0xFFFD). This value should be entered into the vid_mode field, as it is used by the kernel before the command line is parsed.
mem=<size> <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. Note that this is an option to *both* the kernel and the bootloader!
initrd=<file> An initrd should be loaded. The meaning of <file> is 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 user-specified command line:
BOOT_IMAGE=<file> The boot image which was loaded. Again, the meaning of <file> is obviously bootloader-dependent.
auto The kernel was 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" gets confused by the "auto" option. |
|
|