我寫了這個小引導程序,但是當我鏈接它,我得到這個錯誤:我不明白爲什麼LD給出rilocazione(搬遷)錯誤
boot.o: nella funzione "_start":
(.text+0xa): rilocazione adattata per troncamento: R_X86_64_16 contro ".data"
在英語中,錯誤的是:
boot.o: In function `_start':
(.text+0xa): relocation truncated to fit: R_X86_64_16 against `.data'
我的鏈接器命令是:寫在GNU彙編
ld -Ttext 0x7c00 --oformat=binary boot.o -o boot.bin
我的Bootloader代碼是:
code16
.data
prova: .string "questa è una prova"
.text
.globl _start
_start:
//now i try to print on the screen a string
//for do that i'm gonna to use int 0x10
mov $0x13,%ah
mov $0x0,%bh
mov $0x01,%bl
mov $20,%cx
push $[prova]
pop %es
int $0x10
jmp boot
boot:
.=_start+510
.byte 0x55
.byte 0xaa
'ld'想鏈接64位代碼。嘗試添加'-melf_i386'選項。 – Jester
也驚訝'code16'工程。通常你需要像'.code16'這樣的一段時間。即使在與Jester的更改成功鏈接後,您的代碼也不會像您期望的那樣運行。 –
我強烈建議如果您在GNU彙編程序中執行bootloader,爲了簡單起見,您可以在最後一段代碼之後和.byte 0x55 .byte之前刪除'data'部分並將數據放入'.text'部分0xaa'。 '。= _ start + 510'沒有做你認爲的事。既然你在鏈接器'-Ttext 0x7c00'上有這個,'_start'的值將是0x7c00而不是0x0000。 '。= _ start + 510'會將位置計數器設置爲0x7c00 + 510,這不是你想要的。試試這個,而不是'.space 510 - (。-_start)' –