flat assembler
Message board for the users of flat assembler.

Index > OS Construction > elf format, symbols and ld linker script

Author
Thread Post new topic Reply to topic
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
I´m about to move my kernel to the elf format, but as always this isn´t as easy as I thought Sad

1st problem is I use the addresses of labels for things like that:
Code:
foo1 dw bar and 0xffff
foo2 dw bar shr 16
    


2nd problem is that I defined a constant for the size of the kernel:
Code:
kernel_size= bss_end - init

section '.text' executable align 16
init:
...
mov ecx,(kernel_size shr 12) + 3
...
section '.data' writeable align 4096
...
mem_stack_4kb dd (kernel_size and 0xfffff000) + 0xc0012000
...
section '.bss' writeable align 4096
...
bss_end:
    


This wont work anymore! What have I to do to make it work again?

The next problem I have is the linker script for ld. I want to specifiy that the pma is 0x100000 and the vma is 0xc0000000. How can I do this? At the moment I use the org command for setting the address, but this doesn´t work right Sad

Maybe there is a tutorial for using linker scripts?
Post 22 May 2006, 10:11
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
Ok, I found a sample script and modified it a little bit for my needs!

Code:
/* Link.ld */
OUTPUT_FORMAT("elf32-i386")
OUTPUT(kernel.so)
ENTRY(init)
SECTIONS
{
    .text 0xc0100000 : AT ( 0x100000 )
    {
        _code = .;
        *(.text)
        . = ALIGN(4096);
    }

    .data : AT ( 0x100000 + ( ADDR(.data) - ADDR(.text) ) )
    {
        _data = .;
        *(.data)
        . = ALIGN(4096);
    }

    .bss : AT ( 0x100000 + ( ADDR(.bss) - ADDR(.text) ) )
    {
        _bss = .;
        *(.bss)
        . = ALIGN(4096);
    }

    _end = .;
}
    


I haven´t tested if the code works alright.
Post 22 May 2006, 10:47
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
Ok, the script and the kernel are working now Razz

I have only one problem left Wink

How can it be made that all sections except .text, .data and .bss come direct after the elf header and then these 3 section come?
Post 22 May 2006, 12:13
View user's profile Send private message Reply with quote
MarcoAlves



Joined: 09 Jun 2006
Posts: 30
MarcoAlves
FlashBurn, I've tried to use your ld script but with no success. I'm using
djgpp under windows. When I try to link the linker says that it can't recognize elf32-i386 format.

Please, help me.
Thx in advance.

Best regards,
Marco Alves.
Post 19 Jun 2006, 13:10
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
Show me your kernel source and then maybe I can help you.
Post 19 Jun 2006, 14:36
View user's profile Send private message Reply with quote
MarcoAlves



Joined: 09 Jun 2006
Posts: 30
MarcoAlves
The kernel is attached.

It's SO simple. I'm noob yet. Smile


Description:
Download
Filename: main.rar
Filesize: 1.02 KB
Downloaded: 120 Time(s)

Post 19 Jun 2006, 14:44
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
1st thing is that you use djgpp and with this compiler you can´t compile for elf format! And my script isn´t something for someone who don´t have enough knowledge. I think you should use grub as bootloader and I don´t know but I think it should load coff files.
Post 19 Jun 2006, 19:11
View user's profile Send private message Reply with quote
MarcoAlves



Joined: 09 Jun 2006
Posts: 30
MarcoAlves
FlashBurn, I've understood entirely your script. Smile I'm new on asm, but senior C# .NET programmer, so I think that I can acquire the "enough knowlege" just reading, and reading and reading. Smile

I just didn't understood why the error happens because djgpp's ld was not linking. Now, i get it.

Nevertheless, thank you.
Post 19 Jun 2006, 19:38
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
Either you make yourself a crosscompiler or you use grub + coff kernel. djgpp isn´t the best solution for os deving!
Post 21 Jun 2006, 18:01
View user's profile Send private message Reply with quote
MarcoAlves



Joined: 09 Jun 2006
Posts: 30
MarcoAlves
I'm downloading cygwin. Hope it help me.
Post 22 Jun 2006, 12:41
View user's profile Send private message Reply with quote
FlashBurn



Joined: 06 Jan 2005
Posts: 87
FlashBurn
I don´t know if I used mingw or cygwin for creating my crosscompiler, but I think it was mingw and I also onyl needed ld for linking, because I´m only writing in asm.
Post 23 Jun 2006, 14:49
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.