如何正确定位变量,AT& T公司装配? [英] How to locate a variable correctly in AT&T assembly?
问题描述
我在练写一个使用引导程序组件(在AT& T公司的语法和GNU /气体)。该小程序是汇编和链接,然后复制到虚拟磁盘的第一个扇区。 BIOS将其加载到 0000:7c00
,这里谈到的问题。在呼叫招呼
将由呼叫0010
翻译为呼叫7C10
运行中。但 MOVW $消息,如%
没有得到重新定位。在斧
还是 0026
,而不是 7c26
。其结果是,我不能让的Hello World
在屏幕上。相反,在 0000一些随机数据:0026
将显示在屏幕上
我怎样才能使它正确引导期间?我应该改变的ASM源$ C $ c。使用某些指令?或者我应该改变我的链接脚本?
感谢您!
的.text
。全球_start
。code16_开始:
MOVW%CS,斧头%
MOVW%斧,DS%
MOVW%斧,ES%
打电话问候
JMP。.ORG为0x10你好:
MOVW $消息,斧头%
MOVW%斧,BP%
MOVW $ 13%CX
MOVW $ 0x1301,斧头%
MOVW $ 0x000c,BX%
MOVB $ 0%DL
INT $为0x10
RET信息:
.ascii你好,世界!.ORG 0x01fe
将0x55 .BYTE
.BYTE和0xAA
我用下面的汇编和链接脚本
作为-o boot.o boot.s
//生成目标codeLD -Ttext为0x0 -e _start -o -s boot.out boot.o
//搬迁的.text为0x0
//条目是_startobjcopy把-O二进制-j的.text boot.out启动
//复制.text段启动vboxmanage convertfromraw启动boot.vdi --format VDI
//创建虚拟盒VDI
我看到的主要问题是在你编译你的code的方式。
正确的步骤,让您的code工作应该是:
作为boot.s -c -o boot.o
LD --oformat二进制--Ttext 0x7C00 -o BOOT.BIN boot.o
请注意,正如其他人所说,那我路过 - Ttext 0x7C00
参数 LD
,迫使其在该地址搬迁的code。
作为一个附加的建议,尝试构建您的code是这样的:
的.text
。全球_start
。code16_开始:
JMP stage1_start...stage1_start:<您的bootloader这里>
请注意,这是compiant与BIOS code如何看待硬盘驱动器,因为后2个字节(第一个跳转指令的长度),你应该把磁盘说明表。
此外,你可以重构你的最后一个指令的多个为
式的语法如下:
。 = _start + 0x0200 - 2
。短路0x0AA55
凡。
变量是位置计数器。看看对这个计数器是如何工作的详细信息页面(在上下文 LD
,而不是为
)。
希望这有助于!
I am practicing to write a bootstrap using assembly (in AT&T syntax, and gnu/gas). The small program is assembled and linked, then copied to the first sector of a virtual disk. BIOS will load it into 0000:7c00
, and here comes the problem. The call hello
will be translated from call 0010
to call 7c10
during running. But the movw $message, %as
doesn't get relocated. The ax
is still 0026
, not 7c26
. The result is that I can't make the Hello World
on the screen. Instead, some random data at 0000:0026
will be displayed on the screen.
How can I make it correct during booting? Should I change the asm source code using some directives? Or should I change my link script?
Thank you!
.text
.global _start
.code16
_start:
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
call hello
jmp .
.org 0x10
hello:
movw $message, %ax
movw %ax, %bp
movw $13, %cx
movw $0x1301, %ax
movw $0x000c, %bx
movb $0, %dl
int $0x10
ret
message:
.ascii "Hello, World!"
.org 0x01fe
.byte 0x55
.byte 0xaa
I use the following assemble and link scripts
as -o boot.o boot.s
//generate object code
ld -Ttext 0x0 -e _start -s -o boot.out boot.o
//relocate .text to 0x0
//entry is _start
objcopy -O binary -j .text boot.out boot
//copy .text section to boot
vboxmanage convertfromraw boot boot.vdi --format VDI
//create vdi for virtual box
I see that the main problem is in the way you are compiling your code.
The correct steps to get your code working should be:
as boot.s -c -o boot.o
ld --oformat binary --Ttext 0x7C00 -o boot.bin boot.o
Please note, as others have said, that I'm passing the --Ttext 0x7C00
parameter to ld
, to force it relocating your code at that address.
As an additional suggestion, try to structure your code like this:
.text
.global _start
.code16
_start:
jmp stage1_start
...
stage1_start:
<your bootloader here>
Note that this is compiant with how BIOS code looks at hard drives, since after 2 bytes (the length of the first jump instruction) you should place the Disk Description Table.
Additionally, you can refactor your last instructions in a more as
-like syntax like this:
. = _start + 0x0200 - 2
.short 0x0AA55
Where the .
variable is the location counter. Look at this page for further information on how this counter works (in the context of ld
, not as
).
Hope this helps!
这篇关于如何正确定位变量,AT&amp; T公司装配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!