列表 上一篇 下一篇

linux+v2.6.24/arch/x86/boot/main.c

void main(void) { /* First, copy the boot header into the "zeropage" */ copy_boot_params(); /* End of heap check */ if (boot_params.hdr.loadflags & CAN_USE_HEAP) { heap_end = (char *)(boot_params.hdr.heap_end_ptr +0x200-STACK_SIZE); } else { /* Boot protocol 2.00 only, no heap available */ puts("WARNING: Ancient bootloader, some functionality " "may be limited!\n"); } /* Make sure we have all the proper CPU support */ if (validate_cpu()) { puts("Unable to boot - please use a kernel appropriate " "for your CPU.\n"); die(); } /* Tell the BIOS what CPU mode we intend to run in. */ set_bios_mode(); /* Detect memory layout */ detect_memory(); /* Set keyboard repeat rate (why?) */ keyboard_set_repeat(); /* Set the video mode */ set_video(); /* Query MCA information */ query_mca(); /* Voyager */ #ifdef CONFIG_X86_VOYAGER query_voyager(); #endif /* Query Intel SpeedStep (IST) information */ query_ist(); /* Query APM information */ #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE) query_apm_bios(); #endif /* Query EDD information */ #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE) query_edd(); #endif /* Do the last things and invoke protected mode */ go_to_protected_mode(); } main函数的主要作用对硬件进行设置、通过memcpy或者硬件探测为内核启动准备参数放入boot_params结构体(main.c中定义的全局变量),然后跳转到保护模式。 boot_params结构体需要注意的部分有hdr、e820_map[E820MAX]、hdr.cmd_line_ptr,hdr是main函数调用copy_boot_params从kernel setup处拷贝过来,e820_map是main函数调用detect_memory得到,hdr.cmd_line_ptr是bootloader传递给内核的参数,所以bootloader会设置kernel setup处的hdr,bootloader把参数放在适当的位置,然后把参数的指针存放到hdr.cmd_line_ptr,需要注意的这个指针是32位保护模式下的线性地址。