Page 1 of 1

Compare Bootloader and kernel pmode jump in

Posted: Mon Mar 10, 2003 1:34 pm
by Thunder
Hello again:
Pype.Clicker helped me with bootloader code that jumps to pmode,but i use bootloader that jums to kernel at 0x10000 linear and then loads pmode, but computer restarts, what's wrong? ???:
[bits 16]
mov ax, cs   ; set up segments
mov ds, ax
mov es, ax
mov fs, ax
mov sp, 0x10000


;---------- 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.

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:begin
begin:
jmp $

;------------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:

Bochs says that
jump_protected: S=1: descriptor not executable
Please, help to llama ::)
Thanks

Re:Compare Bootloader and kernel pmode jump in

Posted: Mon Mar 10, 2003 3:46 pm
by Pype.Clicker
you should make sure your code is setting up CS=DS=0 if you want LGDT [...] to work properly. For now, your bootstrap is assuming it will be loaded with CS=7C0, and starts at offset 0 in that segment (if not, you would have written ORG 7C00 at the start of your file)

When the processor sees LGDT [gdtr], it loads the GDT.base register with "GDT", but this is the *offset* of your GDT in the current segment, not its absolute location!

If you really want to use CS=7C0 (or have some code that is independent from the actual CS value), you should

Code: Select all

xor eax,eax
mov ax,ds
shl eax,4
add dword [gdtr.base], eax
so that your GDT base is an absolute location.