Problem unreal mode

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.
Post Reply
FlashBurn

Problem unreal mode

Post by FlashBurn »

My loader uses the unreal mode to load my kernel and move it at 0x100000. I?ve tested this now and I had to recognize that it isn?t working :( I need the unreal mode, because I load more than one file and the files all together will be larger than 640kb! So I need to move the data behind the 0x100000 mark! Maybe someone know the reason why this isn?t working and has an idea how I can solve the problem.
Slasher

Re:Problem unreal mode

Post by Slasher »

We can't help without seeing the code you are executing
FlashBurn

Re:Problem unreal mode

Post by FlashBurn »

I?ve forgotten to say that I have a AMD XP CPU.

This is the code:

Code: Select all

;----------------------------
unreal_mode:
   cli

   lgdt [GDTR]

   mov eax,cr0
   or al,1
   mov cr0,eax

   db 66h,0eah
   dd 10000h + .pmode
   dw 8h

.pmode
[BITS 32]
   mov eax,10h
   mov ds,eax
   mov es,eax

   mov eax,cr0
   and al,0feh
   mov cr0,eax

   jmp 1000h:.rmode

[BITS 16]
.rmode
   mov ax,1000h
   mov ds,ax
   mov es,ax

   sti

   ret
;----------------------------
ASHLEY4

Re:Problem unreal mode

Post by ASHLEY4 »

Hi
1)Have you enabled a20.
2)If you have then take at look here:

http://www.karig.net/0004.html

ASHLEY4.
Slasher

Re:Problem unreal mode

Post by Slasher »

Besides enabling A20 line, you set up the Ds and Es segment with selectors that span 0 - 4Gb before switching back to real mode
FlashBurn

Re:Problem unreal mode

Post by FlashBurn »

I enabled the a20 gate!

This is my new code, which now tripple faults on my pc, but works in bochs!

Code: Select all

;----------------------------
unreal_mode:
   cli

   lgdt [GDTR]

   mov eax,cr0
   or al,1
   mov cr0,eax

   db 66h,0eah
   dd 10000h + .pmode
   dw 8h

.pmode
[BITS 32]
   mov eax,10h
   mov ds,eax
   mov es,eax

   db 0eah
   dd .rmode1
   dw 18h

.rmode1
   mov eax,cr0
   and al,0feh
   mov cr0,eax

[BITS 16]
   jmp 1000h:.rmode

.rmode
   mov ax,1000h
   mov ds,ax
   mov es,ax

   sti

   ret
;----------------------------
And this is my GDT:

Code: Select all

GDT:
   ;null descriptor
   dw 0
   dw 0
   dw 0
   dw 0

   ;code descriptor
   dw 0ffffh
   dw 0
   dw 9a00h
   dw 0cfh

   ;data descriptor
   dw 0ffffh
   dw 0
   dw 9200h
   dw 0cfh

   ;code 16bit descriptor
   dw 0ffffh
   dw 0
   dw 9a01h
   dw 0
GDT_END:
Maybe someone has the same problem and solved it already?!
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Problem unreal mode

Post by Candy »

Don't reload your ds & es registers in realmode or they won't work as unreal anymore.
Tim

Re:Problem unreal mode

Post by Tim »

Candy: No, that's fine. Updating segment registers in real mode only changes the base address and doesn't touch any of the other parts (like the limit).

FlashBurn: I think the problem is that you're switching to full real mode. The point of unreal mode is that you don't go all the way into protected mode.
What you should do is:

1. LGDT
2. Set CR0.PE
3. Do NOT touch CS. Do NOT JMP.
4. Load DS, ES, etc.
5. Clear CR0.PE
FlashBurn

Re:Problem unreal mode

Post by FlashBurn »

Thanks to all for the help. The loader is now working.
ASHLEY4

Re:Problem unreal mode

Post by ASHLEY4 »

What was the problem ?
FlashBurn

Re:Problem unreal mode

Post by FlashBurn »

I don?t realy know what the problems, because there seems to be another problem with my kernel. All of the version I posted here, without my first version are working. So I think the problem was that the CS reg was also init with an 32bit segment.
Post Reply