NASM:发出的非标量(链接时)MSW值 [英] NASM: emit MSW of non-scalar (link-time) value
问题描述
我试图定义一个常量 IDT(中断描述符表)中的作品=http://www.nasm.us/相对=nofollow> NASM 以及这样做,我需要发射到一个数据表中的双字地址的高字的未得到解决,直到链接时的。有没有办法做到这一点?
I am attempting to define a constant IDT (Interrupt Descriptor Table) entry in NASM, and to do so, I need to emit into a data table the high word of a double-word address that is not resolved until link time. Is there a way to do it?
下面的中断处理程序:
;;; Interrupt 3 (breakpoint) handler. For now, just poke the screen and halt.
align 8
int3:
mov [0xb8000],dword '* * '
hlt
和这里引用它的IDT入口。的偏移需要最-显著和最显著字被分别地和非连续存储
And here's the IDT entry that references it. The most-significant and least-significant words of the offset need to be stored separately and non-contiguously:
;; Interrupt 3 - breakpoint
dw int3 ; offset (low) <---- WORKS
dw codesel ; code selector
db 0 ; unused
db 0b10001111 ; present, ring 0, 32-bit trap gate
dw int3 >> 16 ; offset (high) <---- ASSEMBLY ERROR
NASM正确导致LD发出INT3地址的低字,但高字在装配失败,此错误:
NASM correctly causes ld to emit the low word of int3's address, but the high word fails at assembly with this error:
pgm.asm:240: error: shift operator may only be applied to scalar values
NASM不会做的数学与被直到链接时定义的值。我理解,但我需要一种方法来解决这个问题。我可以:
NASM won't do math with a value that isn't defined until link time. I understand, but I need a way to work around this. I could:
- 找到INT3绝对
- 构建IDT在运行时,而不是组装时间
我可能会最终建立IDT在运行,但它会是不错知道是否有一种方法可以使汇编器/连接器发射到数据表中的地址的高位字未解决直到链接时。
I'll probably end up building the IDT at runtime, but it'd be good to know if there is a way to cause the assembler/linker to emit into a data table the high word of an address that is not resolved until link time.
情况:
- NASM 01年2月20日
- NASM输出格式AOUT
- LD 2.22版
- 32位模式(NASM32位发出指令)
推荐答案
嗯......你可能知道,NASM会屈尊做两个标签之间的差异的转变。通常的结构是这样的:
Well... as you probably know, Nasm will condescend to do a shift on the difference between two labels. The usual construct is something like:
DW(INT3 - $$)GT;&GT; 16
其中, $
指节的开头。此计算文件偏移。这可能不是你想要转移的价值。
where $$
refers to the beginning of the section. This calculates the "file offset". This is probably not the value you want to shift.
DW(INT3 - $$ + ORIGIN)GT;&GT; 16
可以做你想做的......其中, ORIGIN
...嗯,我们告诉NASM为组织
如果我们使用平的二进制。我假设你要组装 -f ELF32
或 -f ELF64
,告诉LD - -oformat =二进制
,并告诉LD无论是在链接脚本或者您想要的.text
是在命令行上(?)。这似乎工作。
我做了一个有趣的发现:如果你告诉LD -oformat =二进制
(一个连字符),而不是 - oformat =二进制
(两个连字符),LD默默输出什么!不这样做 - !你浪费了很多时间。
may do what you want... where ORIGIN
is... well, what we told Nasm for org
, if we were using flat binary. I ASSume you're assembling to -f elf32
or -f elf64
, telling ld --oformat=binary
, and telling ld either in a linker script or on the command line where you want .text
to be (?). This seems to work.
I made an interesting discovery: if you tell ld -oformat=binary
(one hyphen) instead of --oformat=binary
(two hyphens), ld silently outputs nothing! Don't do this - you waste a lot of time!
这篇关于NASM:发出的非标量(链接时)MSW值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!