问题
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