Jump to kernel
Posted: Wed Mar 26, 2003 12:00 am
I am trying to jump to a simple kernel (a empty for loop) yet jump causes a
crash. Could someone please look at my code and if they can find anything
wrong could they tell me
The kernel is a c file that is compiled to load at 1000h and is a plain
binary
//////////////START OF CODE/////////
[bits 16]
[org 07c00h]
jmp main ; put all data here
loading: db "Loading...", 13, 10, 0
copyright: db "ZY (C) 2003", 13, 10, 0
a20gate: db "PS/2 A20 gate enabled >> 1mb available", 13, 10, 0
switching: db "In pmode, cs=4gb, ds=4g flat", 13, 10, 0
reading: db "Reading kernel...", 13, 10, 0
read: db "read", 13, 10, 0
done: db "__DONE__", 13, 10, 0
gdt:
gdt_null_desc:
dd 0 ;null desc required as first entry in gdt
dd 0
gdt_code_desc: ;CODE CODE CODE CODE
dw 0xffff ;limit set to max
dw 0 ;big block start at 0!!! base
db 0 ; base cont
db 10011010b ; type and other flags (type field = 1010 = code+read only)
db 11001111b ;last limit add (highest nibble) plus other flags granularity
set so we have 4gb desc here!!!!!!
db 0 ;last of base address
gdt_data_desc ;DATA DATA DATA
dw 0xffff ;full 4b
dw 0 ;start
db 0
db 10010010b ; low nibble sets data read/write access expand down
db 11001111b ;4gb
db 0
;gdt_video_desc ;DATA DATA DATA easy access to the video ram for outputting
stuff to screen
gdt_end:
gdt_descriptor:
dw gdt_end-gdt-1 ; calculate size of gdt
dd gdt ; set address
;main code;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main:
mov ax, 0000h ;set segment
mov ds, ax
mov ax, 0x9000
mov ss, ax ;stack
mov si, loading ;disp messages
call dispMSG
mov si, copyright
call dispMSG
mov si, reading
call dispMSG
call readKernel
mov si, read
call dispMSG
call enableA20Gate
mov si, a20gate
call dispMSG
cli ;stop interrupts
lgdt[gdt_descriptor] ;load it!! TODO align on 8 byte boundary for
performance reasons
mov si, switching
call dispMSG
mov eax, cr0
or eax, 1
mov cr0, eax
jmp 0x08:BITCODE ; load code segment from descriptor 1 and jump
[BITS 32]
BITCODE:
mov ax, 0x10
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 0x9000
mov byte [ds:0B8000h], '_'
mov byte [ds:0B8001h], 1Ch
mov byte [ds:0B8002h], '_'
mov byte [ds:0B8003h], 1Ch
mov byte [ds:0B8004h], 'D'
mov byte [ds:0B8005h], 1Ch
mov byte [ds:0B8006h], 'O'
mov byte [ds:0B8007h], 1Ch
mov byte [ds:0B8008h], 'N'
mov byte [ds:0B8009h], 1Ch
mov byte [ds:0B800Ah], 'E'
mov byte [ds:0B800Bh], 1Ch
mov byte [ds:0B800Ch], '_'
mov byte [ds:0B800Dh], 1Ch
mov byte [ds:0B800Eh], '_'
mov byte [ds:0B800Fh], 1Ch
jmp 0x08:0x1000 ;pass control to KERNEL
;CAUSES A CRASH;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
readKernel:
;ah = 02h
;al = no. sectors to read
;ch = cylinders
;cl = sector no to start read from
;dh = head
;dl = drive
;es:bx = destination of data
.reset
mov ax, 0x0000
mov es, ax
mov ax, 0x1000
mov bx, ax
;done buffer setup
mov ah, 0x2
mov al, 0x2
mov ch, 0x0
mov cl, 0x2
mov dh, 0x0
mov dl, 0x0
int 0x13
or ah, ah
jnz .reset
ret
enableA20Gate: ;PS/2 only not old AT keyboard
cli ;disable interupts
in al, 0x92 ;read in status
mov ax, 0x02 ;0x02 = 0000, 0010 binary we are setting bit 1
out 92h, al
sti
ret
dispMSG: ;ret from this as u SHOULD use CALL only
mov ah, 0eh
mov bh, 00h
.loopmsg
lodsb
or al, al
jz .stop
int 10h
jmp .loopmsg
.stop
ret
times 510-($-$$) db 0
dw 0xaa55
crash. Could someone please look at my code and if they can find anything
wrong could they tell me
The kernel is a c file that is compiled to load at 1000h and is a plain
binary
//////////////START OF CODE/////////
[bits 16]
[org 07c00h]
jmp main ; put all data here
loading: db "Loading...", 13, 10, 0
copyright: db "ZY (C) 2003", 13, 10, 0
a20gate: db "PS/2 A20 gate enabled >> 1mb available", 13, 10, 0
switching: db "In pmode, cs=4gb, ds=4g flat", 13, 10, 0
reading: db "Reading kernel...", 13, 10, 0
read: db "read", 13, 10, 0
done: db "__DONE__", 13, 10, 0
gdt:
gdt_null_desc:
dd 0 ;null desc required as first entry in gdt
dd 0
gdt_code_desc: ;CODE CODE CODE CODE
dw 0xffff ;limit set to max
dw 0 ;big block start at 0!!! base
db 0 ; base cont
db 10011010b ; type and other flags (type field = 1010 = code+read only)
db 11001111b ;last limit add (highest nibble) plus other flags granularity
set so we have 4gb desc here!!!!!!
db 0 ;last of base address
gdt_data_desc ;DATA DATA DATA
dw 0xffff ;full 4b
dw 0 ;start
db 0
db 10010010b ; low nibble sets data read/write access expand down
db 11001111b ;4gb
db 0
;gdt_video_desc ;DATA DATA DATA easy access to the video ram for outputting
stuff to screen
gdt_end:
gdt_descriptor:
dw gdt_end-gdt-1 ; calculate size of gdt
dd gdt ; set address
;main code;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main:
mov ax, 0000h ;set segment
mov ds, ax
mov ax, 0x9000
mov ss, ax ;stack
mov si, loading ;disp messages
call dispMSG
mov si, copyright
call dispMSG
mov si, reading
call dispMSG
call readKernel
mov si, read
call dispMSG
call enableA20Gate
mov si, a20gate
call dispMSG
cli ;stop interrupts
lgdt[gdt_descriptor] ;load it!! TODO align on 8 byte boundary for
performance reasons
mov si, switching
call dispMSG
mov eax, cr0
or eax, 1
mov cr0, eax
jmp 0x08:BITCODE ; load code segment from descriptor 1 and jump
[BITS 32]
BITCODE:
mov ax, 0x10
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 0x9000
mov byte [ds:0B8000h], '_'
mov byte [ds:0B8001h], 1Ch
mov byte [ds:0B8002h], '_'
mov byte [ds:0B8003h], 1Ch
mov byte [ds:0B8004h], 'D'
mov byte [ds:0B8005h], 1Ch
mov byte [ds:0B8006h], 'O'
mov byte [ds:0B8007h], 1Ch
mov byte [ds:0B8008h], 'N'
mov byte [ds:0B8009h], 1Ch
mov byte [ds:0B800Ah], 'E'
mov byte [ds:0B800Bh], 1Ch
mov byte [ds:0B800Ch], '_'
mov byte [ds:0B800Dh], 1Ch
mov byte [ds:0B800Eh], '_'
mov byte [ds:0B800Fh], 1Ch
jmp 0x08:0x1000 ;pass control to KERNEL
;CAUSES A CRASH;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
readKernel:
;ah = 02h
;al = no. sectors to read
;ch = cylinders
;cl = sector no to start read from
;dh = head
;dl = drive
;es:bx = destination of data
.reset
mov ax, 0x0000
mov es, ax
mov ax, 0x1000
mov bx, ax
;done buffer setup
mov ah, 0x2
mov al, 0x2
mov ch, 0x0
mov cl, 0x2
mov dh, 0x0
mov dl, 0x0
int 0x13
or ah, ah
jnz .reset
ret
enableA20Gate: ;PS/2 only not old AT keyboard
cli ;disable interupts
in al, 0x92 ;read in status
mov ax, 0x02 ;0x02 = 0000, 0010 binary we are setting bit 1
out 92h, al
sti
ret
dispMSG: ;ret from this as u SHOULD use CALL only
mov ah, 0eh
mov bh, 00h
.loopmsg
lodsb
or al, al
jz .stop
int 10h
jmp .loopmsg
.stop
ret
times 510-($-$$) db 0
dw 0xaa55