far jump at protected 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
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

far jump at protected mode

Post by instance »

Hey,
I've tried to get the system to boot, and then I loaded the gdt. However, when I try a far jump, it jumps to a nonsensical location of 0 (absolute 0)
The following is the code-

Code: Select all

lgdt [gdtr] ;pointing to gdt 
	
	mov eax, cr0
	or al,1
    mov cr0, eax
	;At this point in protected mode
	jmp 0x08:protectedmode


[bits 32]
protectedmode:
	;Do stuff
	mov eax,5
	add eax,10
	
gdtr:
    dw 65535    
    dd 0x2000
I've loaded the gdt at location 0x2000 in memory, and it is 64 kb long. When I run the code through the debugger, I see that the far jump shows-
(0) [0x00001076] 0000:0000000000001076 (unk. ctxt): jmp far 0008:107b ; ea7b100800

And then, bochs jumps to physical memory location 0

Can some1 tell me what I'm doing wrong.
Thank you
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: far jump at protected mode

Post by Combuster »

Can some1 tell me what I'm doing wrong.
Giving us wrong information. jmp 8:label will not land you at 0 physical.

What's the next instruction to be executed after the jump? What messages does bochs give you.
"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 ]
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: far jump at protected mode

Post by xenos »

Looks like a linker problem... If you have a linker map, you can look up which address is assigned to your label protectedmode.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: far jump at protected mode

Post by Troy Martin »

It's not a linker problem, or false information. It's that your GDT isn't even complete. there's no 0x08, the null entry isn't a dq 0, etc.

EDIT: Twenty invisible tokens says that you have no GDT whatsoever at 0x2000.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

Re: far jump at protected mode

Post by instance »

Hey,
I just realized that its jumping not due to the jmp, rather, when I'm modifying the cr0 register. Here are screenshots I've taken of the debugger. You can see the physical dump of the GDT on the right pane (dumping the gdt also shows that the gdtr has been loaded properly)

Image
Image


EDIT:
The GDT has been loaded.... When I use the GDT dump feature of the bochs debugger, it shows alot of empty selectors, 1 code at 0x08 and 1 data at 0x10
um.... want a screenshot of that?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: far jump at protected mode

Post by Troy Martin »

*hands over the tokens*
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
instance
Posts: 16
Joined: Tue Mar 03, 2009 3:40 am

Re: far jump at protected mode

Post by instance »

Blah!! The debugger was the confusing thing.... When I go to protected mode, the asm dump just goes haywire for some reason. But I realized that by looking at IP (which remains proper) that code is getting executed properly. When I then jump (in debugger) to that location and step ahead, it seems to work like a charm..

heh.... weirdest thing ever :)
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: far jump at protected mode

Post by Combuster »

Glad that it's working.

And please do send a bug report to the devs - the debugger should just work. (In the meantime, you can still use the text debugger)
"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 ]
Post Reply