程序集保护模式不适用于真实硬件
我尝试在汇编中创建自己的操作系统。 我学习了实模式(16 位),现在我正在
QEMU 模拟器中学习保护模式(32 位),操作系统运行完美,但是当我将其加载到计算机(32 位)上时,它无法运行。
这是代码:
[org 0x7c00]
xor ax, ax
mov ds, ax
mov es, ax
mov bp, 0x8000
mov sp, bp
mov ah, 0x0
mov al, 0x3
int 0x10
CODE_SEG equ GDT_code - GDT_start
DATA_SEG equ GDT_data - GDT_start
cli
lgdt [GDT_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp CODE_SEG:start_protected_mode
;jmp $
GDT_start: ; must be at the end of real mode code
GDT_null:
dd 0x0
dd 0x0
GDT_code:
dw 0xffff
dw 0x0
db 0x0
db 0b10011010
db 0b11001111
db 0x0
GDT_data:
dw 0xffff
dw 0x0
db 0x0
db 0b10010010
db 0b11001111
db 0x0
GDT_end:
GDT_descriptor:
dw GDT_end - GDT_start - 1
dd GDT_start
[bits 32]
start_protected_mode:
mov ax, DATA_SEG
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000
mov esp, ebp
mov al, 'A'
mov ah, byte 0x02
mov [0xb8000], ax
hlt
jmp $
times 510-($-$$) db 0
dw 0xaa55
对于编译,我使用这些命令:
nasm -f bin bootloader.asm -o boot.bin
qemu-system-x86_64 boot.bin
错误在哪里?
i've tryied to create my own OS in assembly.
i learned real mode (16 bit) and now i'm learning protected mode (32 bit)
in the QEMU emulator the OS works perfectly but when i load it on my computer (32 bit) it doesn't work.
this is the code:
[org 0x7c00]
xor ax, ax
mov ds, ax
mov es, ax
mov bp, 0x8000
mov sp, bp
mov ah, 0x0
mov al, 0x3
int 0x10
CODE_SEG equ GDT_code - GDT_start
DATA_SEG equ GDT_data - GDT_start
cli
lgdt [GDT_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp CODE_SEG:start_protected_mode
;jmp $
GDT_start: ; must be at the end of real mode code
GDT_null:
dd 0x0
dd 0x0
GDT_code:
dw 0xffff
dw 0x0
db 0x0
db 0b10011010
db 0b11001111
db 0x0
GDT_data:
dw 0xffff
dw 0x0
db 0x0
db 0b10010010
db 0b11001111
db 0x0
GDT_end:
GDT_descriptor:
dw GDT_end - GDT_start - 1
dd GDT_start
[bits 32]
start_protected_mode:
mov ax, DATA_SEG
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000
mov esp, ebp
mov al, 'A'
mov ah, byte 0x02
mov [0xb8000], ax
hlt
jmp $
times 510-($-$) db 0
dw 0xaa55
and for the compilation I use these commands:
nasm -f bin bootloader.asm -o boot.bin
qemu-system-x86_64 boot.bin
where is the mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论