linux更新ld值为1的数据,linux-将.org指令与.data节中的数据一起使用:与ld有关

在努力了解如何使用GNU binutils使用以下命令构建简单的引导加载程序时:

gas我遇到了一个问题,如何在使用.org扩展位置计数器的文件中告诉链接器将数据放在何处,同时将文件大小保持在512字节.我似乎找不到解决方法.

尝试执行此操作的汇编程序为:

# Author: Matthew Hoggan

# Date Created: Tuesday, Mar 6, 2012

.code16 # Tell assembler to work in 16 bit mode

.section .data

msg: # Message to be printed to the screen

.asciz "hello, world"

.section .text

.globl _start # Help linker find start of program

_start:

xor %ax, %ax # Zero out ax register (ah used to specify bios function to Video Services)

movw %ax, %ds # Since ax is 0x00 0x00 use it to set data segment to 0

mov $msg, %si # Use source index as pointer to string

loop:

movb %ds:(%si), %al # Pass data to BIOS function in low nibble of ax

inc %si # Advance the pointer

or %al, %al # If byte stored in al is equal to zero then...

jz _hang # Zero signifies end of string

call print_char # Print current char in al

jmp loop # Repeat

#

# Function that uses bios function calls

# to print char to screen

#

print_char:

movb $0x0e, %ah # Function to print a character to the screen

movb $0x07, %bl # color/style to use for the character

int $0x10 # Video Service Request to Bios

ret

#

# Function used as infinite loop

#

_hang:

jmp _hang

.org 510

.byte 0x55, 0xAA

.end

更新

使用以下命令,我得到以下错误:

mehoggan@mehoggan-laptop:~/Code/svn_scripts/assembly/bootloader/gas$ld --oformat binary -o string string.o

string.o: In function `_start':

(.text+0x5): relocation truncated to fit: R_X86_64_16 against `.data'

解决方法:

对于这种工作,您应该编写自己的linker script.只需使用-T选项将其传递给链接器即可.

我针对几乎相同问题的脚本是:

SECTIONS

{

. = 0x1000;

bootsec :

{

*(.text)

*(.data)

*(.rodata)

*(.bss)

endbootsec = .;

. = 0x1FE;

SHORT(0xAA55)

}

endbootsecw = endbootsec / 2;

image = 0x1200;

}

有了这个技巧,您不必将0x55 0xAA放到汇编器中!

开头的0x1000:实际上所有跳转都是相对的,因此不使用,但是稍后需要进入跳转到保护模式…

endbootsecw,endbootsecw和image是代码中其他地方使用的符号.

标签:att,ld,gas,linux

来源: https://codeday.me/bug/20191101/1984863.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值