Pmode HARD!!!
Posted: Sat Mar 08, 2003 10:17 am
Hello i have created my bootloader that enters pmode too:
[bits 16]
org 0x7c00
;---------------------Main Code--------------------;
mov ax,cs ; setup ds segment
mov ds,ax
mov es,ax
mov fs,ax
mov ss,ax ; align stack also
mov sp,0x200 ; 512 byte stack
;----------- Prints --------------
call cls
mov si,hello
call print_msg
;---------- Load kernel ----------
;read:
;xor ax,ax ; Floppy Reset BIOS Function
;mov dl,0 ; Select floppy that was booted from
;int 0x13
;jc read
;mov ax,0xffff
;mov es,ax ; Segment for data
;mov bx,0x10 ; Offset
;mov ah,2 ; Function to read disk
;mov al,1 ; Total sectors to read
;mov ch,0 ; Track 0
;mov cl,2 ; Sector 2
;mov dh,0 ; Head 0 | Drive is already loaded
;int 13h ; Call BIOS read disk function
;jc read ; motor error, try again
;mov dx,0x3f2 ; stop the motor
;mov al,0x0C ; from spinning
;out dx,al
mov si,load
call print_msg
;---------- Enabling A20 Line ---------
cli ; no more interuptions!
xor cx, cx
clear_buf:
in al, 64h ; get input from keyboard status port
test al, 02h ; test the buffer full flag
loopnz clear_buf ; loop until buffer is empty
mov al, 0D1h ; keyboard: write to output port
out 64h, al ; output command to keyboard
clear_buf2:
in al, 64h ; wait 'till buffer is empty again
test al, 02h
loopnz clear_buf2
mov al, 0dfh ; keyboard: set A20
out 60h, al ; send it to the keyboard controller
mov cx, 14h
wait_kbc: ; this is approx. a 25uS delay to wait
out 0edh, ax ; for the kb controler to execute our
loop wait_kbc ; command.
; a20 line is now on, set up GDT and IDT tables
lgdt[gdt_ptr]
mov eax, cr0 ; switch to pmode by
inc ax ; toggling last bit
mov cr0, eax
jmp codesel:flush
[bits 32]
flush:
mov ax,datasel ; setup segments to new selector
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov gs,ax
jmp codesel:0x100000
sti
mov ah,0
int 16h
cli
;======================================
cls:
mov ah, 02h
mov dx, 0000h
mov bh, 0
int 10h
mov ah,09h
mov bl, 14
mov al, ''
mov cx, 80*50
int 10h
ret
print_msg:
mov ah, 0eh
mov bh, 0
.1: lodsb
int 10h
cmp al, 0
jne .1
ret
;======================================
hello db 'Storm OS Boot Loader:',13,10,0
load db '1) Loading Kernel to RAM...',13,10
db '2) Enabling A20 Line...',13,10
db '3) Loading new GDT...',13,10
db '4) Entering Pmode...',13,10,0
entered db 'Entered !',0
;------------GDT Table---------------;
gdt_ptr:
dw gdt_end - gdt - 1
dd gdt
gdt:
; NULL descriptor
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; unused descriptor
dw 0
dw 0
db 0
db 0
db 0
db 0
codesel equ $-gdt
dw 0FFFFh ; segment limit
dw 0 ; base address
db 0
db 9Ah ; priv level 0, code
db 0CFh ; granurlarity
db 0 ; base address
datasel equ $-gdt
dw 0FFFFh ; segment limit
dw 0 ; base address
db 0
db 92h ; priv level 0, data
db 0CFh ; gran
db 0 ; base address
gdt_end:
TIMES 510-($-$$) DB 0
SIGNATURE DW 0xAA55
-------------------------------------------------------------------
BUT when i boot computer i just restarts
[bits 16]
org 0x7c00
;---------------------Main Code--------------------;
mov ax,cs ; setup ds segment
mov ds,ax
mov es,ax
mov fs,ax
mov ss,ax ; align stack also
mov sp,0x200 ; 512 byte stack
;----------- Prints --------------
call cls
mov si,hello
call print_msg
;---------- Load kernel ----------
;read:
;xor ax,ax ; Floppy Reset BIOS Function
;mov dl,0 ; Select floppy that was booted from
;int 0x13
;jc read
;mov ax,0xffff
;mov es,ax ; Segment for data
;mov bx,0x10 ; Offset
;mov ah,2 ; Function to read disk
;mov al,1 ; Total sectors to read
;mov ch,0 ; Track 0
;mov cl,2 ; Sector 2
;mov dh,0 ; Head 0 | Drive is already loaded
;int 13h ; Call BIOS read disk function
;jc read ; motor error, try again
;mov dx,0x3f2 ; stop the motor
;mov al,0x0C ; from spinning
;out dx,al
mov si,load
call print_msg
;---------- Enabling A20 Line ---------
cli ; no more interuptions!
xor cx, cx
clear_buf:
in al, 64h ; get input from keyboard status port
test al, 02h ; test the buffer full flag
loopnz clear_buf ; loop until buffer is empty
mov al, 0D1h ; keyboard: write to output port
out 64h, al ; output command to keyboard
clear_buf2:
in al, 64h ; wait 'till buffer is empty again
test al, 02h
loopnz clear_buf2
mov al, 0dfh ; keyboard: set A20
out 60h, al ; send it to the keyboard controller
mov cx, 14h
wait_kbc: ; this is approx. a 25uS delay to wait
out 0edh, ax ; for the kb controler to execute our
loop wait_kbc ; command.
; a20 line is now on, set up GDT and IDT tables
lgdt[gdt_ptr]
mov eax, cr0 ; switch to pmode by
inc ax ; toggling last bit
mov cr0, eax
jmp codesel:flush
[bits 32]
flush:
mov ax,datasel ; setup segments to new selector
mov ds,ax
mov es,ax
mov ss,ax
mov fs,ax
mov gs,ax
jmp codesel:0x100000
sti
mov ah,0
int 16h
cli
;======================================
cls:
mov ah, 02h
mov dx, 0000h
mov bh, 0
int 10h
mov ah,09h
mov bl, 14
mov al, ''
mov cx, 80*50
int 10h
ret
print_msg:
mov ah, 0eh
mov bh, 0
.1: lodsb
int 10h
cmp al, 0
jne .1
ret
;======================================
hello db 'Storm OS Boot Loader:',13,10,0
load db '1) Loading Kernel to RAM...',13,10
db '2) Enabling A20 Line...',13,10
db '3) Loading new GDT...',13,10
db '4) Entering Pmode...',13,10,0
entered db 'Entered !',0
;------------GDT Table---------------;
gdt_ptr:
dw gdt_end - gdt - 1
dd gdt
gdt:
; NULL descriptor
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; unused descriptor
dw 0
dw 0
db 0
db 0
db 0
db 0
codesel equ $-gdt
dw 0FFFFh ; segment limit
dw 0 ; base address
db 0
db 9Ah ; priv level 0, code
db 0CFh ; granurlarity
db 0 ; base address
datasel equ $-gdt
dw 0FFFFh ; segment limit
dw 0 ; base address
db 0
db 92h ; priv level 0, data
db 0CFh ; gran
db 0 ; base address
gdt_end:
TIMES 510-($-$$) DB 0
SIGNATURE DW 0xAA55
-------------------------------------------------------------------
BUT when i boot computer i just restarts