Page 1 of 1

CS vodoo  :o

Posted: Wed Aug 06, 2003 11:00 pm
by TexHawk
I have been experimenting with my bootsector code (along with the help of some people from this forum!) and after failure after failure I've come up with a pseudo-failure i.e. perhaps a glimmer of hope....

I was wondering if anyone has ever experienced this problem.  After loading the gdtr and setting the pmode bit, I made a jmp to my pmode code and this is where everything crashes.  Well after reviewing the register dump I see that the CS register correctly indexes its selector and is in full 32 bit mode however it still hiccups on the jump and crashes before I can reset the segment registers.  Anyone know why this would occur??  

Thanks,
Matt

RE:CS vodoo  :o

Posted: Thu Aug 07, 2003 11:00 pm
by HOS
i had a similar problem with my code and it was fixed by placing the bits 16 and bits 32 directives in the correct place. ie if you are jumping to a 32bit pmode code segment, make sure that the code there is under bits 32 but the code before the jump to pmode is in bits 16. this is what worked for me.

RE:CS vodoo  :o

Posted: Thu Aug 07, 2003 11:00 pm
by Xenos
Now I know what made my OS crash! After setting the PE bit, CS still contains a 16bit segment selector and I tried to use 32bit code...

RE:CS vodoo  :o

Posted: Thu Aug 07, 2003 11:00 pm
by TexHawk
Well I thought the jump to the pmode code reloaded the cs register to 32 bits by indexing into the GDT (?)  I tried moving the 'BITS 32' statement before the jump to pmode but I got some runtime error like 'jump_protected cs==0'But if move the 'BITS 32' statement after the jump the cs reloads correctly but everything else crashes.

Best Regards,
Matt

RE:CS vodoo  :o

Posted: Thu Aug 07, 2003 11:00 pm
by Adek336
do you fixup gdtr/gdt? the bootloader is loaded at linear adress 0x7c00, so the gdtr should be fixed by that value; also the gdts (at least the code segment) should be fixed by 0x7c000. You would probably only need to:

GDTR:
  dw GDT_end - GDT0 -1
  dd GDT + 0x7c00

...

GDT2: //code
  dw 0xffff
  dw 0x7c00
  db 0
  db 0x9a
  db 0xcf
  db 0

but I´m not sure.

Cheers,
Adrian