Page 1 of 1

really need help--about protected mode

Posted: Wed Nov 28, 2001 1:10 am
by user4
This piece code is within my boot loader.
(CS=7c00,DS=0,ES=0,SS=0)
   cli
   lgdt qword ptr gdtr
   mov eax,cr0
   or al,1
   mov cr0,eax
   db 0eah    |Reset when reach here,jmp 0010:xxxx,now CPU should found
   dw do_pm   |out the 'gdt1',and the base address from gdt1 is 0,
   dw gdt1    |plus xxxx,then I got 0000xxxx, this should be right,but it seems not. ?
 do_pm:
   jmp $
Follow is the definition for GDT(I think the bug is hides here):
 gdtr:
   dw gdtend-gdt-1
   dd gdt    ;base
 gdt:  
   dq 0      ;NULL descriptor
 gdt0 equ $-gdt
   dw 0ffffh ;limit 4G
   dw 0      ;base addr L16
   db 0      ;base addr M8
   db 92h    ;(ds)data descriptor
   db 0cfh   ;G/D
   db 0      ;base addr H8
 gdt1 equ $-gdt
   dw 0ffffh
   dw 0 ;the address is wrong?
   db 0
   db 9ah    ;(cs)code descriptor
   db 0cfh
   db 0
 gdtend:


Thanks for any infomation.
I have studied Christopher Giese's example for a long time,but he's code is base on DOS,so I can't get any headway now:-(
user4

Re: really need help--about protected mode

Posted: Wed Nov 28, 2001 9:01 am
by mansonbound
the gdt is not loaded correctly. Do you know Y?
Look in the 2nd line of your post:
ds=0;
Now remember the real adress is segment:offset where segment is always ds (if not redefined fe: es:offset).
You load the gdtr with:
lgdt (qword ptr whatever) gdtr
Do you see the prob? lgdt gets this adress:
0:gdtr
BUT you defined the GDT @
0x7C00:gdtr ;BIOS loads your bootsector there.

By the way, when i started os-programming i made exactly the same mistake :-)

Re: really need help--about protected mode

Posted: Wed Nov 28, 2001 12:34 pm
by user4
Thanks for your reply.
I now checking my code.......

Re: really need help--about protected mode

Posted: Wed Nov 28, 2001 1:20 pm
by user4
Unfortunately, It seems work bad.
I've added two line before lgdt:
mov ax,7c00h (or 7c0h,I've tested it also)
mov ds,ax
but it resets still.
I think 'DS=0' is not the matter,because other code
like below works well:
   xor ax,ax
   mov ds,ax
   mov es,ax
   mov ax,1301h
   mov bx,7
   mov bp,offset msg_load ;while this offset is 0:msg_load,and it works.
   mov cx,24
   int 10h    
those code executed before CLI.

Re: really need help--about protected mode

Posted: Wed Nov 28, 2001 11:08 pm
by user4
oooh,yes, I forgot someting :
.org 7c00h
I had this line putted into the begining of my code.
so DS=0 isn't matter.
excuse me.
and...... , what goes wrong with my descriptors?