how to change 'jmp' and 'popfd' to 64-bit code?

▼魔方 西西 提交于 2020-01-05 05:48:05

问题


when

$ nasm -f elf64 -o thisfile.o thisfile.asm

it says the line of jmp and popfd "instruction not supported in 64-bit mode"

this is the whole code:

SELECTOR_KERNEL_CS  equ 8

extern  cstart

extern  gdt_ptr

[SECTION .bss]
StackSpace      resb    2 * 1024
StackTop:       

[section .text] 

global _start   

_start:

    mov esp, StackTop   

    sgdt    [gdt_ptr]   
    call    cstart       
    lgdt    [gdt_ptr]    

    ;lidt   [idt_ptr]

    jmp SELECTOR_KERNEL_CS:csinit
csinit:     

    push    0
    popfd   ; Pop top of stack into EFLAGS

    hlt

回答1:


Since you're in 64-bit mode, you'll need to use popfq instead of popfd (alternatively, you can just use popf).

As for the jmp, I believe you'll need to do a trick with retf:

    push word SELECTOR_KERNEL_CS
    push qword csinit
    retf
csinit:
    ...

This works because retf will first pop the new instruction pointer, then pop the new cs selector.



来源:https://stackoverflow.com/questions/17406054/how-to-change-jmp-and-popfd-to-64-bit-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!