[SOLVED] Jumps in protected mode with GDT - not working

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.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Jumps in protected mode with GDT - not works

Post by egos »

Correct pmode offset by the same way because you use flat segments in PM.

"jmp 8:10000h+pmode" isn't so good. Try this:

Code: Select all

   jmp 0x8:pmode
  org 10000h+$
BITS 32
pmode:
If you would put 16-bit code below 10000h (for example at 8000h) you could use unified linear space in RM/PM.
If you have seen bad English in my words, tell me what's wrong, please.
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

Re: Jumps in protected mode with GDT - not works

Post by HugeCode »

Ok. I created a new code similar to first one.

Code: Select all

org 0x8000
start:
	mov ax, 0x800
	mov ds, ax
	mov es, ax
	
	cli;
	lgdt [toc]
	mov bx, [toc]
	mov ebx, [toc+2]
	sti;
	
	cli;
	mov eax, cr0
	or eax, 1
	mov cr0, eax
	
	jmp 0x8:pmode

BITS 32
pmode:
	; code......
	
	hlt;
gdt_start: 
	dd 0 			
	dd 0 
 			
	dw 0FFFFh 			
	dw 0 			
	db 0 				
	db 10011010b 		
	db 11001111b 			
	db 0 				
 
	dw 0FFFFh 			
	dw 0 				
	db 0 				
	db 10010010b 		
	db 11001111b 		
	db 0				
toc: 
	dw toc - gdt_start - 1
	dd gdt_start 	

But jmp is still going to 0xfffffff0. Does anybody know where can be the problem now?
EDIT:
Finally works! I think I won't ever use org directive. I have removed ORG, and added 0x8000 to jump and "toc" of GDT. Now it works... mostly... But still thanks for navigating mi to the right way.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Jumps in protected mode with GDT - not works

Post by egos »

I can't understand why you try to use "org 8000h" and segment base 8000h (800h*10h) at same time. org directive is used to set up current offset within the segment, not segment base. Yes, this combination allows you to use same starting linear address 10000h, but in this case you should calculate linear addresses/FLAT offsets as I mentioned above: 8000h+gdt, 8000h+pmode, 8000h+$, and so on.
If you have seen bad English in my words, tell me what's wrong, please.
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

Re: [SOLVED] Jumps in protected mode with GDT - not working

Post by HugeCode »

I also found out that it wasn't fully the ORG fault.... I think that lgdt instruction also depends on DI/SI, not only on segment registers. Few days ago I had same problem again. I cleaned di and si.... Then, everything went perfectly.
Last edited by HugeCode on Sun May 12, 2013 6:01 am, edited 1 time in total.
User avatar
iansjack
Member
Member
Posts: 4711
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: [SOLVED] Jumps in protected mode with GDT - not working

Post by iansjack »

Probably better to read the reference manual rather than making wild guesses about how instructions work.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: [SOLVED] Jumps in protected mode with GDT - not working

Post by Combuster »

I think
Don't think, know.

Guesses are worth nothing in this business.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: [SOLVED] Jumps in protected mode with GDT - not working

Post by Mikemk »

Combuster wrote:
I think
Don't think, know.

Guesses are worth nothing in this business.
He's right.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
Post Reply