Kernel Stack Fault... can't find it.
Posted: Thu Jul 31, 2008 2:16 pm
Bootsector failing...
I fixed all my issues with triple faulting and the like and got my bootloader to get me into protected mode, but now I'm getting 'kernel stack fault (hardware reset)' messages in VMware. I know it doesn't have debugging capabilities (as far as I know)... but there's not much choice when you're developing on a mac.
Anyways, here is my code so far; problem is at the end of it all.
BOOT.ASM
GDT.ASM
DISPLAY.ASM
Whenever I try to call CLEAR_SCREEN from BOOT.ASM after my stack and everything is set, I get a kernel stack fault right where the movs are. If I comment out the movs, the bootloader works as expected. Really confused.
Edit: Memory map (so far) if it helps...
I fixed all my issues with triple faulting and the like and got my bootloader to get me into protected mode, but now I'm getting 'kernel stack fault (hardware reset)' messages in VMware. I know it doesn't have debugging capabilities (as far as I know)... but there's not much choice when you're developing on a mac.
Anyways, here is my code so far; problem is at the end of it all.
BOOT.ASM
Code: Select all
; --------------------------------------------------------------------------------
; Celeriter Operating System
;
; This bootsector boots into protected mode and prepares the system.
; --------------------------------------------------------------------------------
[BITS 16]
[ORG 0x7C00]
JMP START
%INCLUDE "DISPLAY.ASM"
%INCLUDE "GDT.ASM"
; --------------------------------------------------------------------------------
; Code for the boot sector actually starts here, after the data.
; --------------------------------------------------------------------------------
START:
[BITS 16]
CLI
CLD
; --------------------------------------------------------------------------------
; Copy the global descriptor table to memory, starting at 0x1000.
; --------------------------------------------------------------------------------
XOR AX, AX
MOV DS, AX
MOV SI, GDT
MOV ES, AX
MOV DI, 0x1000
MOV CX, 3*8
COPY:
LODSW
STOSW
LOOP COPY
; --------------------------------------------------------------------------------
; Clear out DS register, enable A20, enable protected mode, and jump to it.
; --------------------------------------------------------------------------------
MOV DS, CX
ENABLE_A20:
CALL A20WAIT1
MOV AL, 0xAD
OUT 0x64, AL
CALL A20WAIT1
MOV AL, 0xD0
OUT 0x64, AL
CALL A20WAIT2
IN AL, 0x60
PUSH EAX
CALL A20WAIT1
POP EAX
OR AL, 0x02
OUT 0x60, AL
CALL A20WAIT1
MOV AL, 0xAE
OUT 0x64, AL
CALL A20WAIT1
ENABLE_PMODE:
LGDT [GDT_D]
MOV CR0, EAX
OR AL, 0x01
MOV EAX, CR0
JMP GDT_CODE:PMODE
A20WAIT1:
IN AL, 0x64
TEST AL, 0x02
JNZ A20WAIT1
RET
A20WAIT2:
IN AL, 0x64
TEST AL, 0x01
JZ A20WAIT2
RET
; --------------------------------------------------------------------------------
; System is now in protected mode, update segment registers quickly.
; --------------------------------------------------------------------------------
PMODE:
[BITS 32]
MOV AX, 0x10
MOV DS, AX
MOV SS, AX
; --------------------------------------------------------------------------------
; For now, a 4k stack is reserved at the beginning of memory.
; --------------------------------------------------------------------------------
MOV ESP, 0x00001000
; --------------------------------------------------------------------------------
; Print a message and let the user know all is well in protected land.
; --------------------------------------------------------------------------------
CALL CLEAR_SCREEN
MOV BYTE[0x000B8002], 'X'
MOV BYTE[0x000B8003], 0x0F
HANG:
JMP HANG
; --------------------------------------------------------------------------------
; Needs to be at the end of the boot sector in order to work properly.
; --------------------------------------------------------------------------------
TIMES 510-($-$$) DB 0x00
SIGNATURE DW 0xAA55Code: Select all
; --------------------------------------------------------------------------------
; GDT File
;
; Contains the global descriptor table and entries for protected mode.
; --------------------------------------------------------------------------------
; --------------------------------------------------------------------------------
; Global descriptor table entries (copied to 0x00000000).
; --------------------------------------------------------------------------------
GDT:
GDT_NULL
GDT_NULL_ENTRY:
DD 0x00000000
DD 0x00000000
GDT_CODE EQU $-GDT_NULL
GDT_CODE_ENTRY:
DW 0xFFFF
DW 0x0000
DB 0x00
DB 10011010b
DB 11001111b
DB 0x00
GDT_DATA EQU $-GDT_NULL
GDT_DATA_ENTRY:
DW 0xFFFF
DW 0x0000
DB 0x00
DB 10010010b
DB 11001111b
DB 0x00
GDT_END:
; --------------------------------------------------------------------------------
; Global descriptor table.
; --------------------------------------------------------------------------------
GDT_D:
DW GDT_END - GDT - 1
DD 0x00001000Code: Select all
; --------------------------------------------------------------------------------
; General purpose display routines
;
; Display routines for clearing the display, writing text, et cetera.
; --------------------------------------------------------------------------------
CLEAR_SCREEN:
MOV BYTE[DS:0x000B8000], 'X' ;Crashes
MOV BYTE[DS:0x000B8001], 0x0F ;Here
PUSH AX
POP AX
RETEdit: Memory map (so far) if it helps...
Code: Select all
; --------------------------------------------------------------------------------
; Celeriter's memory map
;
; Assuming the processor made it to protected mode.
; --------------------------------------------------------------------------------
0x0000 ---------------------- 0x0000
System Stack
4096 Bytes
0x1000 ---------------------- 0x1000
16 GDT/IDT Entries
0128 Bytes
0x1080 ---------------------- 0x1080
Kernel Image
???? Bytes
0x???? ---------------------- 0x????