What's problem with this code?
Posted: Wed Sep 17, 2008 4:33 am
well, I cannot see any problem... Can you help me, please???
run at: 7000:0000 (16bit)
stack: 1000:ffff
(it does not return to rmode safely... but no problem at this stage)
Why the bochs emulator ends like that?
the resulte is:
[EDIT] Code tags added by Brendan [/EDIT]
run at: 7000:0000 (16bit)
stack: 1000:ffff
(it does not return to rmode safely... but no problem at this stage)
Why the bochs emulator ends like that?
Code: Select all
;-------------------start
[BITS 16]
;structures
struc gdt_adr
.limit resw 1
.base resd 1
endstruc
struc gdt_tbl
.dummy resb 8
.ks1code resb 8
.ks1video resb 8
.ks2code resb 8
endstruc
_ptr equ 0x0
;External functions
;the code
global start
start:
;write to the screen on rm
mov ax, 0xb800
mov es, ax
mov si, -2
dox:
add si, 2
mov ax, si
mov byte [es:si], Al
cmp si, 0xfe
jne dox
mov ax, 0
int 0x16
;where is this code? (16 bits)
mov ax, cs
mov ds, ax
;kernel stage 1 gdt.base
and eax, 0xFFFF
shl eax, 4
add ax, gdt + _ptr
mov [gdt + gdt_adr.base + _ptr], eax
;kernel stage 1 gdt.limit
mov Eax, gdt_tbl_finish - gdt_tbl_start
mov [gdt + gdt_adr.limit + _ptr], ax
;code
xor eax, eax
mov ax, cs
and eax, 0xFFFF
shl eax, 4
add ax, start + _ptr
mov word [gdt_tbl_start + gdt_tbl.ks1code + _ptr + 2], ax
shr eax,16
mov byte [gdt_tbl_start + gdt_tbl.ks1code + _ptr + 4], al
cli
;enable a20 gate
call Enable_A20
;load gdt
LGDT [gdt + _ptr]
;goto PM - no interrup, there's no IDT
mov eax, cr0
or eax, 1
mov cr0, eax
;jmp to PM code (clear buffer)
db 0xEA
dw pm_start + _ptr
dw 8 ; 00000000 00001000:x
; ||+-> 00=higest level
; |+--> 0=gdt
; +---> 1=selector 1
pm_start:
mov ax, 16 ; 00000000 00010000 (Video Memory)
; ||+-> 00=higest level
; |+--> 0=gdt
; +---> 10=selector 2
;write to the screen in pm
mov es, ax
mov si, -2
doy:
add si, 2
mov ax, si
mov byte [es:si], Al
cmp si, 0xfe
jne doy
;-------------Enable A20 Gate-----------------------------------------------
Enable_A20:
call a20wait
mov al,0xAD
out 0x64,al
call a20wait
mov al,0xD0
out 0x64,al
call a20wait2
in al,0x60
push eax
call a20wait
mov al,0xD1
out 0x64,al
call a20wait
pop eax
or al,2
out 0x60,al
call a20wait
mov al,0xAE
out 0x64,al
call a20wait
sti
ret
a20wait:
in al,0x64
test al,2
jnz a20wait
ret
a20wait2:
in al,0x64
test al,1
jz a20wait2
ret
;-------------Global Descriptor Table-----------------------------------------
gdt:
istruc gdt_adr
at gdt_adr.limit, dw 0x0000 ;at run-time
at gdt_adr.base, dd 0x00000000 ;at run-time
iend
gdt_tbl_start:
istruc gdt_tbl
at gdt_tbl.dummy, db 0 ;Empty
at gdt_tbl.ks1code, dw 0x0 ;size 1 e 2
dw 0x0 ;base 1 e 2
db 0x0 ;base 3
db 0xca ;flag1 > 1 10 0 1010 > [p=1 (in mem); dpl=10 (level); s=0 (system); segtype=1010]
db 0x1A ;flag2 > 0 0 0 1 1010 > [g=0 (len in byts); d/b=0 (); 0; avl=1; seg size nib=1010 (); ] 00011010
db 0x0 ;base4
; 00 00 00 00 (32 bits) (0000:0000)
; 04|03|01|02 (7000:0000)
at gdt_tbl.ks1video, dw 0x0FA0 ;at run-time:fixed/size 0fA0=4.000 bytes
dw 0x8000 ;base1 e 2
db 0x0B ;base3
db 0x92 ;flag1 > 1 00 1 0010 > [p=1 (in mem); dpl=00 (level); s=1 (not system); segtype=0010]
db 0x0 ;flag2 > 0 0 0 0 0000 > [g=0 (len in bytes); d/b=0 (data); 0; avl=0 (?); sg size nib=0000]
db 0x0 ;at run-time:fixed
;000B8000 32 bits (b800:0000 bits)
;04030102
at gdt_tbl.ks2code, dw 0x0 ; segment for C code
dw 0x0 ;
db 0x0 ;
db 0x0 ;
db 0x0 ;
db 0x0 ;
iend
gdt_tbl_finish:
;-------------end of Global Descriptor Table-----------------------------------
;-------------------end
Code: Select all
00032241352i[CPU0 ] CPU is in protected mode (active)
00032241352i[CPU0 ] CS.d_b = 16 bit
00032241352i[CPU0 ] SS.d_b = 16 bit
00032241352i[CPU0 ] EFER = 0x00000000
00032241352i[CPU0 ] | RAX=0000000060000011 RBX=0000000000000000
00032241352i[CPU0 ] | RCX=0000000000000002 RDX=0000000000000000
00032241352i[CPU0 ] | RSP=000000000000fffd RBP=0000000000000000
00032241352i[CPU0 ] | RSI=00000000ffff00fe RDI=000000000008ffac
00032241352i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00032241352i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00032241352i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00032241352i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00032241352i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df IF tf sf zf af PF cf
00032241352i[CPU0 ] | SEG selector base limit G D
00032241352i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00032241352i[CPU0 ] | CS:7000( 0004| 0| 0) 00070000 0000ffff 0 0
00032241352i[CPU0 ] | DS:7000( 0005| 0| 0) 00070000 0000ffff 0 0
00032241352i[CPU0 ] | SS:1000( 0005| 0| 0) 00010000 0000ffff 0 0
00032241352i[CPU0 ] | ES:b800( 0005| 0| 0) 000b8000 0000ffff 0 0
00032241352i[CPU0 ] | FS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00032241352i[CPU0 ] | GS:0000( 0005| 0| 0) 00000000 0000ffff 0 0
00032241352i[CPU0 ] | MSR_FS_BASE:0000000000000000
00032241352i[CPU0 ] | MSR_GS_BASE:0000000000000000
00032241352i[CPU0 ] | RIP=000000000000006b (000000000000006b)
00032241352i[CPU0 ] | CR0=0x60000011 CR1=0x0 CR2=0x0000000000000000
00032241352i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00032241352i[CPU0 ] >> jmp far 0008:0070 : EA70000800
00032241352e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown
status is 00h, resetting
[EDIT] Code tags added by Brendan [/EDIT]