before start_kernel

本文详细介绍了arch/i386/kernel/head.S文件中如何启用分页机制,并为第一个进程准备执行环境的过程。文中解释了虚拟地址从PAGE_OFFSET+0x100000开始,物理地址从0x100000开始的情况。通过设置页表指针和分页位来实现地址转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

arch/i386/kernel/head.S is responsible for turning on paging mechnisam, and prepare execution envrionment for the first process. The virtual address is from PAGE_OFFSET + 0x100000, and physical address is from 0x100000.

 

 /* enable the paging mechnism, so later address is all virtual address which is physical address + PAGE_OFFSET*/

 movl $0x101000,%eax
 movl %eax,%cr3  /* set the page table pointer.. */
 movl %cr0,%eax
 orl $0x80000000,%eax
 movl %eax,%cr0  /* ..and set paging (PG) bit */
 jmp 1f   /* flush the prefetch-queue */
1:
 movl $1f,%eax
 jmp *%eax  /* make sure eip is relocated */
1:
 /* Set up the stack pointer */
 lss stack_start,%esp

 

/* set gdtr and idtr to the final one. */

 lgdt gdt_descr
 lidt idt_descr
 ljmp $(__KERNEL_CS),$1f
1: movl $(__KERNEL_DS),%eax # reload all the segment registers
 movl %ax,%ds  # after changing gdt.
 movl %ax,%es
 movl %ax,%fs
 movl %ax,%gs
#ifdef __SMP__
 movl $(__KERNEL_DS), %eax
 mov  %ax,%ss  # Reload the stack pointer (segment only)
#else
 lss stack_start,%esp # Load processor stack

 

/* move to start_kernel - the modern age. */

 xorl %eax,%eax
 lldt %ax
 cld   # gcc2 wants the direction flag cleared at all times
 call SYMBOL_NAME(start_kernel)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值