【发布时间】:2019-02-20 00:13:02
【问题描述】:
当我尝试在 qemu 上启动时,我得到一个无休止的重启循环,我能够缩小范围
call 0x1000
这是我第一次深入研究 osdev,如果有任何其他我做错的事情,请通知我:) 提前谢谢!
[org 0x7c00]
[bits 16]
bootdrive db 0x00
xor ax,ax
mov ds, ax
mov ss, ax
mov sp, 0x9c00
mov bp, sp
mov [bootdrive], dl
mov bx, 0x1000
mov dh, 0x01
mov dl, bootdrive
loadkernel:
pusha
push dx
mov ah, 0x02
mov al, dh
mov ch, 0x00
mov dh, 0x00
mov cl, 0x02
int 0x13
pop dx
popa
setgdt:
cli
lgdt[gdtr]
call openA20
call EnablePmode
openA20:
push ax
mov ax, 0x2401
int 0x15
pop ax
ret
EnablePmode:
mov eax, cr0
or al, 1
mov cr0, eax
jmp (CODE_DESC - NULL_DESC) : Pmode
NULL_DESC:
dd 0
dd 0
CODE_DESC:
dw 0xffff
dw 0
db 0
db 10011010b
db 11001111b
db 0
DATA_DESC:
dw 0xffff
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdtr:
Limit dw gdtr - NULL_DESC - 1
Base dd NULL_DESC
[bits 32]
Pmode:
mov ax, DATA_DESC - NULL_DESC
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000
mov esp, ebp
call 0x1000
jmp $
times 510-($-$$) db 0
dw 0xaa55
【问题讨论】:
-
首先将数据放在代码之后和引导签名之前,否则数据将作为代码执行。
-
Int 13h/ah=2 需要将 ES 段寄存器设置为您打算在内存中读取扇区的段。 ES:BX 指向缓冲区。
-
bootdrive db 0x00是要执行的第一条指令... -
mov dl, bootdrive看起来不对。你的意思可能是mov dl, [bootdrive]