从16位实模式(x86)切换到32位保护模式

问题描述 投票:0回答:1

这是将cpu切换到32位模式的标准代码。

    cli   
    lgdt [gdt_descriptor] ; Assume a well-defined GDT

    mov eax, cr0
    or eax, 0x1 
    mov cr0, eax; Is this the exact moment when the processor switches to 32 bit mode?

    jmp CODE_SEG:pipeline_flush ; Here CODE_SEG is 0x08,i.e, the segment descriptor after the NULL descriptor in the GDT 
[bits 32] 
pipeline_flush:

这里,远跳转指令是16位(?)编码指令。...但是处理器处于32位模式。如果我将代码更改为:

[bits 32]
jmp CODE_SEG:pipeline_flush

该代码停止工作...

这是为什么?

assembly x86 operating-system bootloader osdev
1个回答
0
投票

设置CR0的位0之后,处理器处于16位保护模式,因此指令将作为16位指令执行。

BITS 32指令使jmp指令以32位的偏移量部分进行汇编。处理器将偏移量的高16位视为段。由于它不是有效的代码段,因此引发#GP。

© www.soinside.com 2019 - 2024. All rights reserved.