flat assembler
Message board for the users of flat assembler.

Index > Main > Far jump in 64-bit mode.

Author
Thread Post new topic Reply to topic
allih



Joined: 03 Aug 2007
Posts: 1
allih
I'm having a problem with the intel manual and fasm.
What is the fasm way to do a far jump?
Like this: ?
Code:
jump_offset:
   dw segment_selector
   dq offset

code_Start: 
   mov   rax, jump_offset
   jmp    far [rax]
    


And I have another question:
Is there any other way to change the cs segment register? And in 64-bit mode, cs is the only segment register that has anything to do with the privilige level, right?
Post 25 Jan 2008, 20:00
View user's profile Send private message Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 464
Location: Czech republic, Slovak republic
Feryno
I prefer IRETQ
Code:
movzx eax,word [target_SS] ; you can use mov eax,selector if you know where it points into GDT
push rax
mov rax,qword [target_RSP]
push rax
push target_RFLAGS ; (usually 202h - interrupts enabled !!! else you may hang)
movzx eax,word [target_CS]
push rax
mov rax,qword [target_RIP]
push rax
iretq ; db 48h, 0CFh - note that iret (db 0CFh without 48h REX prefix) switches CPU into 32-bit compactibility submode of long mode where instructions are decoded as 32 bit - so don't forget to do IRETQ to keep 64-bit submode of long mode (I wasted a few hours to figure out the reasons of exceptions after iret instead of correct iretq, and note, FASM 1.66 didn't know iretq, you had to add manually db 48h as prefix, but newest FASM versions support IRETQ correctly)
    

the instruction you described should be:
Code:
jmp fword [target] ; this is translated to RIP-relative addressing, you don't need to waste instructions by lea rax,[target] jmp fword [rax]
target:
dd target_EIP ; yes, only 32-bit limit = EIP, no 64-bit RIP anymore...
dw target_CS    

because of 32-bit limitation, I prefer IRETQ and I don't like jmp far (I have never used/tested JMP instruction)
you can save 1 byte using perhaps 66h prefix and even limit the target to 16-bit IP
jmp far dword [target]
target:
dw target_IP
dw target_CS
Post 28 Jan 2008, 12:41
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4242
Location: 2018
edfed
one possibility of fasm:

Code:
farptr64 dt segment16:offset64
    

try all these possibilities, to know what works and what not.
Code:
mov rax,farptr
jmp far [rax]

jmp far [farptr]

call far [farptr]

    
Post 28 Jan 2008, 13:20
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.