mov si causes linking error

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
MDM
Member
Member
Posts: 57
Joined: Wed Jul 21, 2010 9:05 pm

mov si causes linking error

Post by MDM »

So I have this code

Code: Select all

;**********************ssbootloader.s**********************;
; The second stage bootloader

BITS 16
section .data
greeting   db 'Bootloader has loaded', 13, 10, 0
section .text
global ssblstart
ssblstart:
	; set up stack pointer
	mov ax, 0x7BFF
	mov sp, ax
	mov bp, sp
	mov si, greeting
	call printString
	hlt

printString:
	lodsb ; Load character of string
	or al, al ; Check to see if al is zero
	jz psreturn
	mov ah, 0x13
	int 0x10
	jmp printString
	psreturn:
	ret
It compiles fine, but when linked I get the error " In function `ssblstart':
ssbootloader.s:(.text+0x8): relocation truncated to fit: R_386_16 against `.data' "
When I comment out the mov si, greeting it links fine. I checked around, and it seems that most of the time when there is this problem it's because someone is using 32 bit code in 16 bit mode, or visa-versa. This is all 16 bit code though...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: mov si causes linking error

Post by Combuster »

To be precise, its caused by people using 32-bit addresses in real mode. Your linker is just saying you're stupid because you're using an address that's not between 0 and 64KB and thus won't fit in a 16-bit register. Fix that.

You might want to assemble directly to a binary instead of using LD in the process, which might help you get rid of unneeded complexity.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
MDM
Member
Member
Posts: 57
Joined: Wed Jul 21, 2010 9:05 pm

Re: mov si causes linking error

Post by MDM »

Doh, realized in the linker I was using the base address of 0x100000 instead of 0x500. Thanks for the help.
Post Reply