Page 2 of 2

Re: Jumps in protected mode with GDT - not works

Posted: Sat Mar 02, 2013 10:08 am
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.

Re: Jumps in protected mode with GDT - not works

Posted: Sat Mar 02, 2013 12:53 pm
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.

Re: Jumps in protected mode with GDT - not works

Posted: Sat Mar 02, 2013 1:30 pm
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.

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

Posted: Tue Apr 16, 2013 9:54 am
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.

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

Posted: Tue Apr 16, 2013 10:20 am
by iansjack
Probably better to read the reference manual rather than making wild guesses about how instructions work.

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

Posted: Tue Apr 16, 2013 3:41 pm
by Combuster
I think
Don't think, know.

Guesses are worth nothing in this business.

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

Posted: Tue Apr 16, 2013 4:46 pm
by Mikemk
Combuster wrote:
I think
Don't think, know.

Guesses are worth nothing in this business.
He's right.