Page 1 of 1

Pmode HARD!!!

Posted: Sat Mar 08, 2003 10:17 am
by Thunder
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

Re:Pmode HARD!!!

Posted: Sat Mar 08, 2003 1:16 pm
by Slasher
check your stack pointer,
mov sp,0x200 is not a good place, ivt and other stuff is in that area. interrupts won't work ,you are messing them up, use addresses higher up
mov sp,0x7c00 is fine cause stack grows down to 0
code will start from 0x07c00 upwards for 512 bytes. address outside this range is better,
mov sp,0x9000 for example

Re:Pmode HARD!!!

Posted: Sat Mar 08, 2003 1:41 pm
by Thunder
I'll try THANKS A LOT

Re:Pmode HARD!!!

Posted: Sat Mar 08, 2003 2:46 pm
by Thunder
Still I've changed sp to 9000h but the same it resarts...
Any more suggestions? ???

Re:Pmode HARD!!!

Posted: Sat Mar 08, 2003 4:50 pm
by Slasher
you are calling CLS and PrtMsg in 16 bit code, CLS and PrtMsg are defined as 32 bit code. move them to 16 bit area.
then check your enable a20 line code

Re:Pmode HARD!!!

Posted: Sun Mar 09, 2003 5:49 am
by Thunder
I have removed these cls and print_msg I checked a20 ok but GDT
Bochs bochout say that:
load_seg_reg: GDT: ES: index(1700) > limit(000017)
I think here is problem

Re:Pmode HARD!!!

Posted: Sun Mar 09, 2003 7:14 am
by Pype.Clicker
what kind of code is located at 100000 (where you seems to jump to) ?

Re:Pmode HARD!!!

Posted: Sun Mar 09, 2003 8:09 am
by Thunder
mov bx,0b800h
mov es,bx
mov byte [es:0],'O'
mov byte [es:2],'K'
jmp $

Re:Pmode HARD!!!

Posted: Sun Mar 09, 2003 8:32 am
by Pype.Clicker
so the error message from BOCHS is clear: you cannot load ES with selector 0xB800 as your GDT is limited to 3 entries. Instead, you must load ES (or even just use DS) with the generic data selector and use a long offset:

mov dword [0xB8000],'O'+256*7+65536*'K'+256*65536*7

Re:Pmode HARD!!!

Posted: Sun Mar 09, 2003 10:45 am
by Thunder
Whank You very much ;D
If for you wasn't too much me to explain about es use, and how this work:
'O'+256*7+65536*'K'+256*65536*7
Thank again
P.S.Next suffer ;)

Re:Pmode HARD!!!

Posted: Sun Mar 09, 2003 4:27 pm
by Pype.Clicker
each even address in VRAM is for the ASCII code of the displayed character. odd addresses hold the attributes for the previous character.

Therefore, the

Code: Select all

mov [0xb8000],'O'+256*7+65536*'K'+256*65536*7
is equivalent to

Code: Select all

mov [0xb8000],'O'
mov [0xb8001],7 ;; LGREY on BLACK
mov [0xb8002],'K'
mov [0xb8003],7