我尝试编写自己的简单bootloader,我有这段代码:
.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)
任何人都可以解释它崩溃的原因吗?
我有什么办法可以解决它吗?