Bochs - Bootloader error
Posted: Wed Nov 07, 2007 12:30 pm
When i have compiled and linked my kernel, i have tried to start it on Bochs...
After the bootloader has deactivated interupts and NMI, activated the A20 line, loaded the GDT and switched to PMode, it loads the segments registers DS, ES and SS to 0x10. Then it try to read the sectors from the floppy that contains the kernel. When it load the content of AX in ES it crashes with this bochs error:
Why it doesn't works?
Please, help me!!!
After the bootloader has deactivated interupts and NMI, activated the A20 line, loaded the GDT and switched to PMode, it loads the segments registers DS, ES and SS to 0x10. Then it try to read the sectors from the floppy that contains the kernel. When it load the content of AX in ES it crashes with this bochs error:
My code is:00028801846i[BIOS ] Booting from 0000:7C00
00028963558e[CPU0 ] fetch_raw_descriptor: GDT: index (1007)200 > limit (17)
00028963558i[CPU0 ] protected mode
00028963558i[CPU0 ] CS.d_b = 32 bit
00028963558i[CPU0 ] SS.d_b = 16 bit
00028963558i[CPU0 ] EFER = 0x00000000
00028963558i[CPU0 ] | RAX=0000000000000010 RBX=0000000000007e00
00028963558i[CPU0 ] | RCX=0000000000001000 RDX=0000000000000000
00028963558i[CPU0 ] | RSP=0000000000007c00 RBP=0000000000000000
00028963558i[CPU0 ] | RSI=00000000ffff88ca RDI=0000000000080000
00028963558i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00028963558i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00028963558i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00028963558i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00028963558i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af PF cf
00028963558i[CPU0 ] | SEG selector base limit G D
00028963558i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00028963558i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00028963558i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00028963558i[CPU0 ] | SS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00028963558i[CPU0 ] | ES:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00028963558i[CPU0 ] | FS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00028963558i[CPU0 ] | GS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00028963558i[CPU0 ] | MSR_FS_BASE:0000000000000000
00028963558i[CPU0 ] | MSR_GS_BASE:0000000000000000
00028963558i[CPU0 ] | RIP=0000000000007e8f (0000000000007e8f)
00028963558i[CPU0 ] | CR0=0x00000011 CR1=0x0 CR2=0x0000000000000000
00028963558i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00028963558i[CPU0 ] >> mov es, cx : 8EC1
00028963558e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Code: Select all
%define BODY_SEC_LENGTH ((BodyEnd - Body) / 512) + 1
%include "kernelSize.inc"
BITS 16
ORG 0x7C00
Boot:
XOR AX, AX ;Loads the segment registers
MOV DS, AX
MOV ES, AX
MOV SS, AX
MOV SP, 7C00h
MOV AX, 200h + BODY_SEC_LENGTH
MOV CX, 2
XOR DX, DX
MOV BX, 7E00h
INT 13h ;Read the bootloader from sector 2
JMP 0000h:7E00h ;Jump to the bootloader code
times (510 - ($ - Boot)) DB 0 ;filler
DW 0AA55h ;bootloader magic number
Body:
PUSH WORD MsgWelcome
CALL Print
CLI ;disable interrupts
IN AL, 70h
OR AL, 80h
OUT 70h, AL ;disable NMI
CALL A20Enable ;enable A20 line
PUSH WORD MsgGDT
CALL Print
LGDT [GDTInfo] ;loads GDT
PUSH WORD MsgPE
CALL Print
MOV EAX, CR0
OR AL, 1
MOV CR0, EAX ;switch to PM
JMP DWORD 8:Main32 ;Jump to PM code
A20Enable:
PUSH AX
PUSH WORD MsgA20
CALL Print
CALL KbdWaitOutput
MOV AL, 0D0h
OUT 64h, AL
CALL KbdWaitInput
XOR AX, AX
IN AL, 60h
OR AL, 2
PUSH AX
CALL KbdWaitOutput
MOV AL, 0D1h
OUT 64h, AL
CALL KbdWaitOutput
POP AX
OUT 60h, AL
POP AX
RET
KbdWaitOutput:
IN AL, 64h
TEST AL, 2
JNZ SHORT KbdWaitOutput
RET
KbdWaitInput:
IN AL, 64h
TEST AL, 1
JZ SHORT KbdWaitInput
RET
Print:
%define Message BP + 4
PUSH BP
MOV BP, SP
PUSH AX
PUSH BX
PUSH SI
MOV SI, WORD [Message]
MOV AH, 0Eh
XOR BX, BX
NextChar:
LODSB
TEST AL, AL
JZ SHORT Done
INT 10h
JMP SHORT NextChar
Done:
POP SI
POP BX
POP AX
MOV SP, BP
POP BP
RET 2
%undef Message
BITS 32
Main32:
MOV AX, 10h ;Loads segment registers
MOV DS, AX
MOV ES, AX
MOV SS, AX
ReadFloppy:
MOV SI, KRNL_SIZE
XOR BX, BX
MOV AX, 1000h :HERE IS THE PROBLEM
MOV ES, AX ;WHILE MOVING AX TO ES
MOV CX, 3
XOR DX, DX
Again:
PUSH AX
PUSH BX
MOV AX, 0E00h + '.'
MOV BX, 7
INT 10h
POP BX
POP AX
MOV AX, 0201h
INT 13h ;Read the kernel from the floppy
JC SHORT Error
MOV AX, ES
ADD AX, 32
MOV ES, AX
DEC SI
JZ SHORT ReadOK
INC CX
CMP CL, 18
JBE SHORT Again
MOV CL, 1
INC DH
CMP DH, 2
JNE SHORT Again
MOV DH, 0
INC CH
JMP SHORT Again
Error:
MOV AX, 0E00h + 'e'
MOV BX, 7
INT 10h
XOR AX, AX
INT 16h
INT 19h
ReadOK:
MOV EDX, 3F2h
MOV AL, 0Ch
OUT DX, AL ;Shut down the floppy motor
MOV AX, 1000h ;Start the kernel
JMP AX
JMP $
CLI
HLT
GDT:
DD 0, 0
DW 0FFFFh
DW 0
DB 0
DB 9Ah
DB 0CFh
DB 0
DW 0FFFFh
DW 0
DB 0
DB 92h
DB 0CFh
DB 0
GDTEnd:
GDTInfo:
DW GDTEnd - GDT - 1
DD GDT
FloppyOff:
MOV DX, 3F2h
MOV AL, 0Ch
OUT DX, AL
RET
MsgWelcome:
times 80 DB '-'
DB "Boot process", 13, 10
times 80 DB '-'
DB 0
MsgA20 DB "A20...", 10, 13, 0
MsgGDT DB "GDT...", 10, 13, 0
MsgPE DB "PM...", 13, 10, 0
BodyEnd:
length EQU ((((BodyEnd-Boot) / 512) + 1) * 512)
length2 EQU (BodyEnd-Boot)
times (length - length2) DB 0
Please, help me!!!