如何改变“JMP”和“POPFD”到64位code? [英] how to change 'jmp' and 'popfd' to 64-bit code?

查看:521
本文介绍了如何改变“JMP”和“POPFD”到64位code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ NASM -f ELF64 -o thisfile.o thisfile.asm

它说 JMP POPFD 的指令在64位模式下不支持

这是整个code:

  SELECTOR_KERNEL_CS EQU 8EXTERN CSTARTEXTERN gdt_ptr[.bss段]
StackSpace RESB 2 * 1024
StackTop:[.text段]全球_start_开始:    MOV ESP,StackTop    SGDT [gdt_ptr]
    电话CSTART
    LGDT [gdt_ptr]    ;激光损伤阈值[idt_ptr]    JMP SELECTOR_KERNEL_CS:csinit
csinit:    推0
    POPFD;堆栈的顶部弹出EFLAGS成    HLT


解决方案

由于您在64位模式的时候,你需要使用 popfq 而不是 POPFD (或者,你可以使用 POPF )。

对于 JMP ,我相信你需要做的伎俩与 RETF

 推字SELECTOR_KERNEL_CS
    推四字csinit
    RETF
csinit:
    ...

这工作,因为 RETF 首先会弹出新的指令指针,然后弹出新的 CS 选择。

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

解决方案

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.

这篇关于如何改变“JMP”和“POPFD”到64位code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆