Page 2 of 2

Re: Problem with protected mode jump

Posted: Mon Oct 13, 2008 2:40 pm
by Ferrarius
Well, it started to work. I think the main problem was with

Code: Select all

LGDT [GDTDESC] 
not loading the GDT correctly. Because of that the processor just received descriptors that were total gibberish. Here follows the new code:

Code: Select all

[BITS 16]

main:

mov   ax,0xB800

mov   es,ax

mov   byte[es:0],'b'

cli

xor   ax,ax

mov   ds,ax

mov   es,ax

mov   fs,ax

mov   gs,ax

mov   ss,ax

sti

GDTDESC:

dw    0

dd    0



setGDT:

mov   word[GDTDESC],0x2F

mov   dword[GDTDESC + 2],0x00020096



lgdt  [GDTDESC]

cli

mov   eax,cr0

or    eax,1

mov   cr0,eax

jmp   dword 0x08:0x000200FA



times 150 - ($ - $$) db 0

%include "d:\vinitech\mik\gdt006.asm"





times 250 - ($ - $$) db 0



[BITS 32]

enter_pmode:

mov   eax, 0x10

mov   ds,ax



.print_char:

mov   byte[ds:0x000B8002],'a'

mov   byte[ds:0x000B8003],0x7F



.hang:

jmp .hang





times 512 - ($ - $$) db 0
As you can see there's still a lot of work to be done but now I can at least finally do the work. I'd like to thank everyone for their input. It certainly helped me a lot.

Re: Problem with protected mode jump

Posted: Mon Oct 13, 2008 10:59 pm
by egos

Code: Select all

mov   ss,ax
sti
GDTDESC:
dw    0
dd    0

setGDT:
mov   word[GDTDESC],0x2F
mov   dword[GDTDESC + 2],0x00020096
lgdt  [GDTDESC]
Is this really works? :)

Re: Problem with protected mode jump

Posted: Mon Oct 13, 2008 11:59 pm
by egos
Tell me which boot loader you are using? What values have been placed in registers before your code gets control? Why you are using so much displacement where your code is loading to?

For example, my kernel file loads at 0x8000. And the starting code sets the stack pointer to 0x8000.

Code: Select all

  org 0x8000
OSE:
  xor bx,bx
  mov si,OSE
  cli
  mov ss,bx
  mov sp,si
  sti
  jmp 0:@f
@@:
  ...
  mov ds,bx
  ...
  virtual ; check the size of 16-bit code
  rb 10000h-$
  end virtual

Re: Problem with protected mode jump

Posted: Wed Oct 15, 2008 5:19 am
by Ferrarius
I'm using Bootstrap Bill, which is a homebrew bootloader. The reason I load the kernel there is because I can, that's pretty much the end of reason. Anyway, because of this the displacement I programmed in my code works. It is quite likely I'll change my bootloader but that falls under my "When I've got nothing better to do" category of things to do.