x64架构上的实模式和保护模式有何不同?我正在尝试为Linux内核制作一个定制的引导加载程序。如何在程序集中启用保护模式?
发布于 2014-10-26 12:42:05
参见osdev real mode,protected mode。
由BIOS初始化的CPU以实模式启动。启用保护模式允许使用实模式无法访问的所有4 4GB内存。但是,它将阻止您使用大多数BIOS中断,因为这些中断在实模式下工作(除非您还编写了V86监视器)。
在切换到保护模式之前,您必须禁用中断,可能会启用A20行,并使用适用于代码、数据和堆栈的段描述符加载全局描述符表。
中央处理器处于实模式还是保护模式由CR0或MSW寄存器的最低位定义。
此示例将描述符表加载到处理器的GDTR寄存器中,然后设置CR0的最低位:
cli ; disable interrupts
lgdt [gdtr] ; load GDT register with start address of Global Descriptor Table
mov eax, cr0
or al, 1 ; set PE (Protection Enable) bit in CR0 (Control Register 0)
mov cr0, eax
; Perform far jump to selector 08h (offset into GDT, pointing at a 32bit PM code segment descriptor)
; to load CS with proper PM32 descriptor)
JMP 08h:PModeMain
; [...]
PModeMain:
; load DS, ES, FS, GS, SS, ESP.这会将您带到保护模式。
在此之后,您可以跳转到用C或汇编编写的内核代码。
https://stackoverflow.com/questions/17452664
复制相似问题