X86:保护模式、GDT、IDT
我尝试使用 kolibri 引导加载程序执行简单的内核。 它被加载到 1000:0000。 我不明白,这部分出了什么问题:
...
; switch to PM
mov eax, cr0
or al, 1
mov cr0, eax
use32
PROTECTED_ENTRY:
mov ax, 00010000b ; DATA
mov ds, ax
mov ss, ax
mov esp, 0xFFFF
jmp $
mov ax, 00011000b ; VIDEO
mov es, ax
mov edi, 0
mov esi, string
int 1
jmp $
因为在调试器中它看起来像这样
这是怎么回事?为什么 ES 和 DS 没有改变?
PS 我正在尝试让这个内核与 kolibri 加载器一起工作: http://wasm.ru/article.php?article=ia32int
I've tried to execute simple kernel with a kolibri bootloader.
It's being loaded into 1000:0000.
I don't understand, what's wrong in this part:
...
; switch to PM
mov eax, cr0
or al, 1
mov cr0, eax
use32
PROTECTED_ENTRY:
mov ax, 00010000b ; DATA
mov ds, ax
mov ss, ax
mov esp, 0xFFFF
jmp $
mov ax, 00011000b ; VIDEO
mov es, ax
mov edi, 0
mov esi, string
int 1
jmp $
'cause in debugger it looks like this
What's going on here? Why ES and DS aren't being changed?
P.S. i'm trying to get this kernel working with kolibri loader:
http://wasm.ru/article.php?article=ia32int
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您设置
cr0
中的受保护位时,处理器不会自动进入保护模式。此后当cs
发生更改时,它会进入保护模式。最简单的方法是在写入cr0
后立即插入远跳转。希望我做对了。 (我习惯了 AT&T 语法。)
.db
是一个操作数大小覆盖,以允许 32 位地址。The processor does not automatically enter protected mode when you set the protected bit in
cr0
. It enters protected mode whencs
is changed after that. The easiest way to do this is to insert a far jump immediately after writing tocr0
.Hopefully I got that right. (I'm used to AT&T syntax.) That
.db
is an operand size override to allow a 32 bit address.Tee 调试器确实将 32 位代码(您告诉汇编器使用
use32
伪操作生成 32 位代码)反汇编为 16 位代码。因此指令mov ax, 10h
被解释为mov eax, d88e0010h
,其中d88e
部分实际上是下一条指令的操作码,<代码>mov ds,ax。与
mov esp, 0xffff
类似,它被解释为mov sp, 0xffff
并且两个额外的零字节显示为虚假的add byte ptr...< /代码> 指令。
处理器实际执行的内容取决于其当前状态 - 是否处于保护模式、实模式、平面模式等。查看状态寄存器即可找到答案。也许您可以告诉调试器以不同的方式解释代码。
Tee debugger does disassemble the 32bit code (you told the assembler to generate 32 bit code with the
use32
pseudo op) as 16 bit code. So the instructionmov ax, 10h
is interpreted asmov eax, d88e0010h
, where thed88e
part is in reality the opcode for next instruction,mov ds,ax
.Similar for
mov esp, 0xffff
, which is interpreted asmov sp, 0xffff
and the two additional zero bytes show up as the spuriousadd byte ptr...
instruction.What the processor actually executes, depends on its current state - is it in protected mode, real mode, flat mode etc. Look at the status registers to find out. Possibly you can tell the debugger to interpret the code different.