我尝试编写自己的简单引导加载程序,我有以下代码:
.code16 # Generate 16 bit code
.globl set_protected_mode
.globl set_real_mode
__init:
call set_protected_mode
call set_real_mode
jmp __init
# jmp init # Jump to init function in init.c
set_real_mode:
cli
mov %cr0, %eax
and $0xfffffffe,%eax
mov %eax, %cr0
sti
jmp %cs:__set_another_mode_done
set_protected_mode:
cli # Disable interrupts
mov %cr0, %eax
or $0x1, %eax
mov %eax, %cr0
sti # Enable interrupts
jmp %cs:__set_another_mode_done
__set_another_mode_done:
ret # Back to calling function in protected or real mode
在保护模式下一段时间后它会崩溃。
我正在使用 GNU Assembler v2.24、Ubuntu 14.04 并在 bochs 中进行测试。
来自bochs的日志:
00014944437e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
========================================================================
Event type: ERROR
Device: [CPU0 ]
Message: interrupt(): gate descriptor is not valid sys seg (vector=0x01)
谁能解释为什么它崩溃了?
有什么办法可以解决吗?