Page 1 of 1

mov si causes linking error

Posted: Thu Aug 26, 2010 4:01 pm
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...

Re: mov si causes linking error

Posted: Thu Aug 26, 2010 5:01 pm
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.

Re: mov si causes linking error

Posted: Thu Aug 26, 2010 5:30 pm
by MDM
Doh, realized in the linker I was using the base address of 0x100000 instead of 0x500. Thanks for the help.