Page 1 of 1

How to jump to specific location.

Posted: Thu Oct 27, 2011 11:21 am
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.

Re: How to jump to specific location.

Posted: Thu Oct 27, 2011 12:03 pm
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.

Re: How to jump to specific location.

Posted: Thu Oct 27, 2011 12:31 pm
by kendfrey
Like what?

Re: How to jump to specific location.

Posted: Thu Oct 27, 2011 12:39 pm
by Coty
like "jmp 0x1000:0x0000" ??? Nasm won't even let me compile jmp es:0x0000...

Re: How to jump to specific location.

Posted: Thu Oct 27, 2011 12:43 pm
by kendfrey
MASM won't let me compile jmp 1000h:0000h. "error A2096: segment, group, or segment register expected"

Re: How to jump to specific location.

Posted: Thu Oct 27, 2011 4:47 pm
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).

Re: How to jump to specific location.

Posted: Thu Oct 27, 2011 4:57 pm
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.

Re: How to jump to specific location.

Posted: Fri Oct 28, 2011 2:22 am
by rdos
When the assembler refuses to cooperate, read up on the opcodes and use db, dw, dd instead :mrgreen:

Re: How to jump to specific location.

Posted: Fri Oct 28, 2011 4:01 am
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.

Re: How to jump to specific location.

Posted: Fri Oct 28, 2011 1:30 pm
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.]

Re: How to jump to specific location.

Posted: Sat Oct 29, 2011 4:47 pm
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.

Re: How to jump to specific location.

Posted: Sat Oct 29, 2011 4:49 pm
by kendfrey
Not an easy way, but see my previous post. (Yes it generates the same opcode as jmp xxxx:xxxx)