Author Topic: 64bit mode: Absolute JMP encoding  (Read 11997 times)

nobody

  • Guest
64bit mode: Absolute JMP encoding
« on: December 17, 2008, 01:31:54 AM »
Hello,

What is the syntax for a 64-bit absolute jump in NASM?

For instance what I want to do is this:
[BITS 64]
jmp 0x1234567890ABCDEF

According to the Intel manuals this should be encoded with opcode 0xFF (followed by a 64-bit address) but NASM keeps using opcode 0xE9 (with a 32-bit offset address).

How can I get NASM to encode a 64-bit absolute jump?

Thanks,
-Ian

Nathan

  • Guest
Re: 64bit mode: Absolute JMP encoding
« Reply #1 on: December 18, 2008, 04:07:19 AM »
I think you might need to twiddle the DEFAULT directive.  Read about it here:

http://www.nasm.us/doc/nasmdoc6.html#section-6.2

My conclusion from early experiments (using version 2.06rc1) is that 'DEFAULT REL' is active unless an alternative is specified.  The docs seem to have a different opinion.

Nathan.

nobody

  • Guest
Re: 64bit mode: Absolute JMP encoding
« Reply #2 on: December 18, 2008, 04:16:42 PM »
Looking at the NASM source code by default it is set to use absolute address.

globalrel is set to 0 in nasm.c
setting DEFAULT REL sets globalrel to 1 and DEFAULT ABS sets globalrel to 0

So the source code reads that ABS is the default way (So the docs are correct).

Using either the REL or ABS options don't make any difference that I can see in the binary it generates.

With this as my source:
[BITS 64]
[ORG 0x0000000000100000]

kernel_start:

jmp start

The binary shows up as (JMP rel32 as per the Intel docs where RIP = RIP + 32-bit displacement):
0xE9 0xDB 0x00 0x00 0x00

What I am expecting is something like this (JMP r/m64 as per the Intel docs where RIP = 64-bit offset from register or memory):
0xFF 0x?? 0xDB 0x00 0x00 0x00 0x00 0x00 0x00 0x00 (or something like that.. a full 64-bit address)

-Ian

nobody

  • Guest
Re: 64bit mode: Absolute JMP encoding
« Reply #3 on: December 18, 2008, 09:11:34 PM »
Oh!  I've been talking about linker output.  You are looking at the '-f bin' format which probably, until now, has not been tested by anyone.