5.7 切换保护模式 (4)

1 首先是 设置 CR0

//读取cr0 寄存器
static inline uint32_t read_cr0() {
	uint32_t cr0;
	__asm__ __volatile__("mov %%cr0, %[v]":[v]"=r"(cr0));
	return cr0;
}
//写 cr0
static inline void write_cr0(uint32_t v) {
	__asm__ __volatile__("mov %[v], %%cr0"::[v]"r"(v));
}

然后是使用


//设置cr0 最低位
	uint32_t cr0 = read_cr0();
    write_cr0(cr0 | (1 << 0));

2 然后是 进行园跳转, 清空流水线


//进行远眺转
static inline void far_jump(uint32_t selector, uint32_t offset) {
	uint32_t addr[] = {offset, selector };
	__asm__ __volatile__("ljmpl *(%[a])"::[a]"r"(addr));

}

然后是使用

	far_jump(8, (uint32_t)protect_mode_entry);

然后还要再 start.s 中做一些设置。

	// 32位保护模式下的代码
	.code32
	.text
	.global protect_mode_entry
	.extern load_kernel
protect_mode_entry:
    jmp .

为了使C语言编译通过,还需要 加上一个函数定义

//仅仅为了使C 函数通过。
void protect_mode_entry (void);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值