Problem with protected mode jump

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Re: Problem with protected mode jump

Post 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.
Modular Interface Kernel With a lot of bugs ;)
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Problem with protected mode jump

Post 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? :)
If you have seen bad English in my words, tell me what's wrong, please.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Problem with protected mode jump

Post 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
If you have seen bad English in my words, tell me what's wrong, please.
Ferrarius
Member
Member
Posts: 69
Joined: Sun Oct 28, 2007 4:10 pm

Re: Problem with protected mode jump

Post 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.
Modular Interface Kernel With a lot of bugs ;)
Post Reply