如何将以下NASM代码转换为AT& T语法,以解决“无法处理jmp中的非绝对段"的问题.错误 [英] How to convert the following NASM code into AT&T syntax so as to fix the "cannot handle non-absolute segment in jmp" error

查看:103
本文介绍了如何将以下NASM代码转换为AT& T语法,以解决“无法处理jmp中的非绝对段"的问题.错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AT& T语法的新手.为了理解,我想将以下NASM语法代码转换为AT& T语法.

I am new at AT&T syntax. I want to convert the following NASM syntax code into AT&T syntax just for the sake of understanding.

我尝试将其转换为AT& T语法:

My try to convert it into AT&T syntax:

lgdt (gdtpointer)

jmp $gdtcode, $_start

gdt:
.quad 0x0000000000000000

gdtcode: 
.word .- gdt
.quad 0x0020980000000000                   

gdtdata: 
.word .- gdt
.quad 0x0000900000000000                   

gdtpointer:
.word .-gdt-1
.quad gdt   


Error: can't handle non absolute segment in `jmp'

NASM代码:

lgdt [gdt.pointer]          

jmp gdt.code:startLongMode

;Global Descriptor Table
gdt:
dq 0x0000000000000000               

.code equ $ - gdt
dq 0x0020980000000000                   

.data equ $ - gdt
dq 0x0000930000000000                   

.pointer:
dw $-gdt-1                  
dq gdt                  

                   ;Ref: Intel System Programming Manual V1 - 2.1.1.1

推荐答案

在GAS中,由于您的GDT的定义出现在 jmp $ gdtcode,$ _ start 之后,因此汇编程序将看到JMP ,并相信符号 gdtcode 是一个外部符号(将由链接器重定位),而不是一个常量.因此,它将抱怨非绝对引用.

In GAS since the definition of your GDT appears after the jmp $gdtcode, $_start, the assembler will see the JMP and believe the symbol gdtcode is an external symbol (that will be relocated by the linker) and not a constant. Because of that it will complain about the non-absolute references.

通过将 .word .- gdt 放在 gdtcode: gdtdata 之后,您还会不正确地定义GDT.这些行会在您不希望的地方向GDT发出一个16位字.

You also improperly define your GDT by placing .word .- gdt after gdtcode: and gdtdata. Those lines will emit a 16-bit word into GDT where you don't want them.

我相信您可能一直在尝试以下操作.GDT是在 JMP 之前的某个位置定义的:

I believe you might have been trying for something like the following. GDT is defined at some point before the JMP:

gdt:
.quad 0x0000000000000000

gdtcode:
.quad 0x0020980000000000

gdtdata:
.quad 0x0000900000000000

gdtpointer:
.word .-gdt-1
.quad gdt

CODE64_SEL = gdtcode-gdt
DATA64_SEL = gdtdata-gdt

然后在文件的稍后位置,可以使用FAR JMP ,如下所示:

And then at a later point in the file you can use a FAR JMP like this:

jmp $CODE64_SEL, $_start

这篇关于如何将以下NASM代码转换为AT& T语法,以解决“无法处理jmp中的非绝对段"的问题.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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