我目前正在开发一个操作系统。我使用VMWare来模拟它。我在每一行使用int 0x16
进行调试,我发现当我将保护模式切换CR0
切换为1时,它只是三次故障。这是内核加载器的第2阶段:
bits 16
org 0x500
jmp main
%include "stdio.inc"
%include "Gdt.inc"
%include "A20.inc"
%include "Fat12.inc"
%include "common.inc"
LoadingMsg db "Please Wait . . .", 0x0D, 0x0A, 0x00
msgFailure db 0x0D, 0x0A, "Can't find Krnl. Press any key to retry", 0x0D, 0x0A, 0x0A, 0x00
main:
cli
xor ax, ax
mov ds, ax
mov es, ax
mov ax, 0x9000
mov ss, ax
mov sp, 0xFFFF
sti
call InstallGDT
call EnableA20_KKbrd_Out
mov si, LoadingMsg
call Puts16 ; nuts61
jmp EnterKernel
mov ah, 0
int 0x16
int 0x19
cli
hlt
EnterKernel:
cli
mov eax, cr0
or eax, 1
mov cr0, eax ; <= here is the damn triple fault
jmp CODE_DESC:KernelC
bits 32
KernelC:
mov ax, DATA_DESC
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 90000h
CopyImage:
mov eax, dword [ImageSize]
movzx ebx, word [bpbBytesPerSector]
mul ebx
mov ebx, 4
div ebx
cld
mov esi, IMAGE_RMODE_BASE
mov edi, IMAGE_PMODE_BASE
mov ecx, eax
rep movsd
jmp CODE_DESC:IMAGE_PMODE_BASE
cli
hlt
我标记了错误位置。我还发现了一些VMWare三重故障日志:
2016-01-14T17:30:00.613+01:00| vcpu-0| I120: Triple fault.
2016-01-14T17:30:00.613+01:00| vcpu-0| I120: MsgHint: msg.monitorEvent.tripleFault
2016-01-14T17:30:00.613+01:00| vcpu-0| I120+ A fault has occurred causing a virtual CPU to enter the shutdown state. If this fault had occurred outside of a virtual machine, it would have caused the physical machine to restart. The shutdown state can be reached by incorrectly configuring the virtual machine, a bug in the guest operating system, or a problem in VMware Player.
我该如何解决这个问题?有什么建议吗?