保护模式准备活动,上一章是假的准备,这次玩真的了
go_to_protected_mode
=>realmode_switch_hook(); //关中断
=>move_kernel_around(); //如果不是大内核,从0x10000挪到0x1000
=>enable_a20()
=>reset_coprocessor();
=>mask_all_interrupts();
=>setup_idt();
setup_gdt();
=>protected_mode_jump(boot_params.hdr.code32_start,
(u32)&boot_params + (ds() << 4));
对于code32_start,是解压缩内核的起始地址
code32_start: # here loaders can put a different
# start address for 32-bit code.
#ifndef __BIG_KERNEL__
.long 0x1000 # 0x1000 = default for zImage
#else
.long 0x100000 # 0x100000 = default for big kernel
#endif
我纵情一跳
.code16
/*
* void protected_mode_jump(u32 entrypoint, u32 bootparams);
*/
protected_mode_jump:
=>movw $__BOOT_DS, %cx
movl %cr0, %edx
orb $1, %dl # Protected mode (PE) bit
movl %edx, %cr0 //关键是设置cr0的 PE位
movw %cx, %ds //各类段寄存器设置合适的置
movw %cx, %es
movw %cx, %fs
movw %cx, %gs
movw %cx, %ss
# Jump to the 32-bit entrypoint //我挥一挥手,不带走一片云彩
.byte 0x66, 0xea # ljmpl opcode
2: .long 0 # offset
.word __BOOT_CS # segment
参考
Linux kernel boot process——从实模式(real mode)到保护模式(protected mode),再到分页(paging)
http://blog.csdn.net/bokee/article/details/6900361