a pmode boot loader problem,
Posted: Fri May 23, 2003 10:26 am
i entering pmode is err,who can help me?
i use following code by nasm[some code download from net],but when enter pmode it has reboot:
;nasmw -o boot.com boot.asm
;copyboot boot.com 0 1
;i in real mode,it is right
bit 16
org 0
.....
a20msg db 'Setting A20 address line',13,10,0
pmodemsg db 'Setting CR0 -> Entering PMode',13,10,0
; Here's the locations of my IDT and GDT. Remember, Intel's are
; little endian processors, therefore, these are in reversed order.
; Also note that lidt and lgdt accept a 32-bit address and 16-bit
; limit, therefore, these are 48-bit variables.
pIDT dw 7FFh ; limit of 256 IDT slots
dd 0000h ; starting at 0000
pGDT dw 17FFh ; limit of 768 GDT slots
dd 0800h ; starting at 0800h (after IDT)
....
;reading kernel file
read_me:
xor ax, ax
int 0x13
mov eax,0x9000 ;
mov es,eax
xor bx,bx
mov ax,0x0204 ;
mov ch,0 ;
mov cl,2 ;
mov dh,0 ;
mov dl,[bootdrv] ;
int 0x13 ;
jc read_me ;
;seting a20
mov si, a20msg ;
call message
call enable_A20
; the A20 line is on now. Let's load in our ITD and GDT tables...
; Ideally, there will actually be data in their locations (by loading
; the kernel)
lidt [pIDT]
lgdt [pGDT]
; now let's enter pmode...
mov si, pmodemsg
call message
call getkey
mov eax, cr0 ; load the control register in
or al, 1 ; set bit 1: pmode bit
mov cr0, eax ; copy it back to the control register
jmp $+2 ; and clear the prefetch queue
nop
nop
;!!!!!!!!!!!!!!!now go here,the machine is reboot?why??????????
mov si, pmodemsg
call message
call getkey
enable_A20:
cli
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
ret
a20wait:
.l0: mov ecx,65536
.l1: in al,0x64
test al,2
jz .l2
loop .l1
jmp .l0
.l2: ret
a20wait2:
.l0: mov ecx,65536
.l1: in al,0x64
test al,1
jnz .l2
loop .l1
jmp .l0
.l2: ret
times 510-($-$$) db 0
dw 0xAA55
i use following code by nasm[some code download from net],but when enter pmode it has reboot:
;nasmw -o boot.com boot.asm
;copyboot boot.com 0 1
;i in real mode,it is right
bit 16
org 0
.....
a20msg db 'Setting A20 address line',13,10,0
pmodemsg db 'Setting CR0 -> Entering PMode',13,10,0
; Here's the locations of my IDT and GDT. Remember, Intel's are
; little endian processors, therefore, these are in reversed order.
; Also note that lidt and lgdt accept a 32-bit address and 16-bit
; limit, therefore, these are 48-bit variables.
pIDT dw 7FFh ; limit of 256 IDT slots
dd 0000h ; starting at 0000
pGDT dw 17FFh ; limit of 768 GDT slots
dd 0800h ; starting at 0800h (after IDT)
....
;reading kernel file
read_me:
xor ax, ax
int 0x13
mov eax,0x9000 ;
mov es,eax
xor bx,bx
mov ax,0x0204 ;
mov ch,0 ;
mov cl,2 ;
mov dh,0 ;
mov dl,[bootdrv] ;
int 0x13 ;
jc read_me ;
;seting a20
mov si, a20msg ;
call message
call enable_A20
; the A20 line is on now. Let's load in our ITD and GDT tables...
; Ideally, there will actually be data in their locations (by loading
; the kernel)
lidt [pIDT]
lgdt [pGDT]
; now let's enter pmode...
mov si, pmodemsg
call message
call getkey
mov eax, cr0 ; load the control register in
or al, 1 ; set bit 1: pmode bit
mov cr0, eax ; copy it back to the control register
jmp $+2 ; and clear the prefetch queue
nop
nop
;!!!!!!!!!!!!!!!now go here,the machine is reboot?why??????????
mov si, pmodemsg
call message
call getkey
enable_A20:
cli
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
ret
a20wait:
.l0: mov ecx,65536
.l1: in al,0x64
test al,2
jz .l2
loop .l1
jmp .l0
.l2: ret
a20wait2:
.l0: mov ecx,65536
.l1: in al,0x64
test al,1
jnz .l2
loop .l1
jmp .l0
.l2: ret
times 510-($-$$) db 0
dw 0xAA55