How to jump to specific location.

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
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

How to jump to specific location.

Post by kendfrey »

At the end of my boot sector code, I want to jump to my kernel, located at 0x1000:0x0000. The code is currently executing at about 0x0000:0x7d00. I am stumped. I currently have jmp dword ptr es:0000h (es contains 0x1000). Bochs keeps giving me something about prefetch EIP xxxxxxxx > CS.limit xxxxxxxx. What does the prefetch thing mean, and how do I fix it? I'm using MASM BTW.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: How to jump to specific location.

Post by DavidCooper »

kendfrey wrote:I currently have jmp dword ptr es:0000h (es contains 0x1000).
Why would you try to use ES for code? Try a more conventional jump.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: How to jump to specific location.

Post by kendfrey »

Like what?
User avatar
Coty
Member
Member
Posts: 286
Joined: Thu Feb 12, 2009 5:12 pm

Re: How to jump to specific location.

Post by Coty »

like "jmp 0x1000:0x0000" ??? Nasm won't even let me compile jmp es:0x0000...
My hero, is Mel.
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: How to jump to specific location.

Post by kendfrey »

MASM won't let me compile jmp 1000h:0000h. "error A2096: segment, group, or segment register expected"
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: How to jump to specific location.

Post by Combuster »

JMP es:0x0000 does not exist as an instruction: you should not load a code segment with a data segment. The closest variant is jmp [es:0x0000] which is a simple indirect jump and does not do what you want. NASM is right in that regard in refusing assembly.

Why people keep trying to use jmp far ds, address as an instruction is beyond me. It's not anywhere in the manuals after all (mov cs, xxx is another one).
"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 ]
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: How to jump to specific location.

Post by kendfrey »

As far as I know, mov cs, xx is not allowed by MASM either. There are workarounds (my bootloader makes use of one :)). Anyway, I found something about segments in MASM, and I did this:

Code: Select all

kernel segment at 1000h
org 0
start label far
kernel ends
and then jmp kernel:start worked. I don't know why MASM is so persnickety.
rdos
Member
Member
Posts: 3308
Joined: Wed Oct 01, 2008 1:55 pm

Re: How to jump to specific location.

Post by rdos »

When the assembler refuses to cooperate, read up on the opcodes and use db, dw, dd instead :mrgreen:
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: How to jump to specific location.

Post by Chandra »

kendfrey wrote:As far as I know, mov cs, xx is not allowed by MASM either.
Becuase that is not a valid way to set CS. Read the Manuals.
kendfrey wrote:There are workarounds (my bootloader makes use of one :)). Anyway, I found something about segments in MASM, and I did this:

Code: Select all

kernel segment at 1000h
org 0
start label far
kernel ends
and then jmp kernel:start worked. I don't know why MASM is so persnickety.
A simple workaround can be:

Code: Select all

push word 0x1000
push word 0x0000
retf
That's the Nasm Syntax though.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: How to jump to specific location.

Post by DavidCooper »

Coty made a suggestion:-
Coty wrote:like "jmp 0x1000:0x0000" ???
Did you actually try that? Your reply was:-
kendfrey wrote:MASM won't let me compile jmp 1000h:0000h. "error A2096: segment, group, or segment register expected"
I don't know the right syntax for a far jump in different assemblers, so you need to look up the MASM manual to see how it should be done. [In machine code terms you should end up with a far jump instruction (the single byte 234, which I think is EA in hex), followed by two bytes of address (if you're in real mode) and two more bytes to be loaded into CS. Unfortunately, that doesn't help you work out how an assembler will require you to formulate the instruction.]
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: How to jump to specific location.

Post by Gigasoft »

MASM does not have a way to specify a far jump with a numeric segment part. You have to define the instruction using db and dw.
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: How to jump to specific location.

Post by kendfrey »

Not an easy way, but see my previous post. (Yes it generates the same opcode as jmp xxxx:xxxx)
Post Reply