Problem with loader.

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
limonki
Posts: 7
Joined: Sun May 15, 2011 4:15 am

Problem with loader.

Post 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.
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Problem with loader.

Post by DavidCooper »

limonki wrote:

Code: Select all

gdtr:
	dw	gdt - gdtend - 1
	dd	gdt
Shouldn't it be gdtend - gdt - 1?
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
limonki
Posts: 7
Joined: Sun May 15, 2011 4:15 am

Re: Problem with loader.

Post 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?
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: Problem with loader.

Post by Combuster »

What is real-mode bootloader code doing above 1MB?
"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 ]
limonki
Posts: 7
Joined: Sun May 15, 2011 4:15 am

Re: Problem with loader.

Post 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. :(
Last edited by limonki on Mon May 16, 2011 11:25 am, edited 1 time in total.
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: Problem with loader.

Post 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:
"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 ]
limonki
Posts: 7
Joined: Sun May 15, 2011 4:15 am

Re: Problem with loader.

Post by limonki »

Ok, I don't like assembler, but I know that it's needed to OS programming...Ehhhh
User avatar
MDM
Member
Member
Posts: 57
Joined: Wed Jul 21, 2010 9:05 pm

Re: Problem with loader.

Post by MDM »

Are you by chance linking to an (incorrect) position and then loading it into a different position?
limonki
Posts: 7
Joined: Sun May 15, 2011 4:15 am

Re: Problem with loader.

Post by limonki »

Yes, when i changed phys in linker from 0x00100000 to 0x8000 errors disappeared. But system still doesn't start.
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: Problem with loader.

Post 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.
"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 ]
limonki
Posts: 7
Joined: Sun May 15, 2011 4:15 am

Re: Problem with loader.

Post 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 :)
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Problem with loader.

Post by Bietje »

Are you making a real mode bootloader using memory above 1mb? That doesn't work.
limonki
Posts: 7
Joined: Sun May 15, 2011 4:15 am

Re: Problem with loader.

Post by limonki »

I have to refresh my assembler.
Post Reply