Page 1 of 1

Problem with loader.

Posted: Sun May 15, 2011 10:37 am
by limonki
Hi everybody,
i have a little trouble with my asm loader.

I have this error code from linker:

Code: Select all

loader.o(.text+0x4):loader.o: relocation truncated to fit: 16 .text
loader.o(.text+0x11):loader.o: relocation truncated to fit: 16 .text
My linker script is from [url=kttp://www.osdever.net/tutorials/index]Bran's Kernel Development Tutorial[/url] with a little modification ( end = .; _end = .; __end = .; ):

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .; _end = .; __end = .;
}
And finally my loader.asm:

Code: Select all

[BITS 16]
[global start]
[extern _main]
start:
	cli
	lgdt [gdtr]
	mov	eax, cr0
	or	eax, 1
	mov	cr0, eax

	jmp	0x08:pmode32

gdtr:
	dw	gdt - gdtend - 1
	dd	gdt
gdt:
	dd	0x00000000, 0x00000000
	dd	0x0000FFFF, 0x00CF9A00
	dd	0x0000FFFF, 0x00CF9200
	dd	0x0000FFFF, 0x00CFFA00
	dd	0x0000FFFF, 0x00CFF200
gdtend:

[BITS 32]
pmode32:
	mov	ax, 0x10
	mov	ds, ax
	mov	es, ax
	mov	ss, ax
	xor	ax, ax
	mov	fs, ax
	mov	gs, ax
	mov	esp, 0x200000

	call	_main	
	
	jmp	$
If you can explain me what I'm doing wrong, I will be happy. Thanks for help.

Re: Problem with loader.

Posted: Sun May 15, 2011 2:37 pm
by DavidCooper
limonki wrote:

Code: Select all

gdtr:
	dw	gdt - gdtend - 1
	dd	gdt
Shouldn't it be gdtend - gdt - 1?

Re: Problem with loader.

Posted: Sun May 15, 2011 3:14 pm
by limonki
Thanks for reply.

I tried to modify this, but still the same error code:

Code: Select all

loader.o(.text+0x4):loader.o: relocation truncated to fit: 16 .text
loader.o(.text+0x11):loader.o: relocation truncated to fit: 16 .text
Any other ideas to fix this?

Re: Problem with loader.

Posted: Mon May 16, 2011 4:25 am
by Combuster
What is real-mode bootloader code doing above 1MB?

Re: Problem with loader.

Posted: Mon May 16, 2011 10:27 am
by limonki
berkus wrote:

Code: Select all

[BITS 16]
Thanks, that helped.
Combuster wrote:What is real-mode bootloader code doing above 1MB?
Ymmm...I don't know, but it works.

EDIT: I enjoyed too fast. It is linking, but it doesn't start the system. I don't know why. :(

Re: Problem with loader.

Posted: Mon May 16, 2011 11:13 am
by Combuster
I don't know, but it works.
It seems I'll have to anticipate a next thread from you then. Progamming is science, not magic :wink:

Re: Problem with loader.

Posted: Mon May 16, 2011 11:29 am
by limonki
Ok, I don't like assembler, but I know that it's needed to OS programming...Ehhhh

Re: Problem with loader.

Posted: Mon May 16, 2011 1:10 pm
by MDM
Are you by chance linking to an (incorrect) position and then loading it into a different position?

Re: Problem with loader.

Posted: Mon May 16, 2011 1:58 pm
by limonki
Yes, when i changed phys in linker from 0x00100000 to 0x8000 errors disappeared. But system still doesn't start.

Re: Problem with loader.

Posted: Mon May 16, 2011 2:07 pm
by Combuster
Something about trial-and-error work:
limonki wrote:I don't know, but it works.
Combuster wrote:It seems I'll have to anticipate a next thread from you then.
limonki wrote:EDIT: I enjoyed too fast.
I rest my case. :wink:

Anyway, you reference Bran's as the source of your linker script, but the other posted part of your code is definitely not from Bran's, and in fact is completely contrary to the design of the kernel. The only reason why it might work is only because of sheer luck, which makes it prone to come crashing down: the only unknown is "when".

So, for homework: Do you know what a bootloader is and does? Bran's kernel uses one: where is it, and what does it do in order for the kernel to start?
After that, ask yourself what and where your bootloader is and what you expect of it. Hopefully after that exercise you'll realize why your code is out of place.

Re: Problem with loader.

Posted: Mon May 16, 2011 2:33 pm
by limonki
Yes, my loader code is not from Barn's tutorial. I took only linker script. But i probably know why my system doesn't start.

Code: Select all

.read:
	[color=#FF0000]mov 	ah, 0x02
	mov 	al, 0x0A[/color]
	xor 	ch, ch
	mov 	cl, 0x02
	xor	dx, dx
	mov 	bx, 0x8000  			
	int    	0x13
	jc	.read	

	jmp	0x8000

In this code i load only 10 sectors from floppy then i jump to kernel loader. It isn't enough. My kernel has 12*1024 bytes.

EDIT: I do my homework tommorow, because now it's to late :)

Re: Problem with loader.

Posted: Tue May 17, 2011 6:40 am
by Bietje
Are you making a real mode bootloader using memory above 1mb? That doesn't work.

Re: Problem with loader.

Posted: Tue May 17, 2011 10:27 am
by limonki
I have to refresh my assembler.