ELF or BIN Kernel???

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
d4n1l0d
Member
Member
Posts: 42
Joined: Sat Dec 02, 2006 4:12 pm

ELF or BIN Kernel???

Post by d4n1l0d »

Hi!
I wrote my own bootloader and it works ok loading a plain binary kernel ( Totally written in asm ). But now I want to use C code and I want to know if it's better a BIN or an ELF kernel?

--------

Edit: Another thing :D , in plain binary files , does the BSS section exist ?
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Right now I use a homemade bootloader and a plain binary kernel. Using ELF would mean that you would have to add extra code to work with the file format instead of just loading it and jumping to it. In my kernel the BSS does not get written out to the binary.
User avatar
d4n1l0d
Member
Member
Posts: 42
Joined: Sat Dec 02, 2006 4:12 pm

Post by d4n1l0d »

But do you use C code ??
If you do , what is your linker script??
Last edited by d4n1l0d on Wed Jul 11, 2007 8:56 pm, edited 2 times in total.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

The BSS section can exist where ever you want it to. It can exist in the image with the tool chain clearing that area to zeros, or somewhere in memory where you clear it to zeros after booting.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Yes I have C/C++ kernel. My linker script:

Code: Select all

ENTRY( kernel_start )

OUTPUT_FORMAT( binary )

SECTIONS
{
        . = 0x1000;

        startup_start = .;
        
        .start :
        {
                *(.start)

                . = ALIGN( 4096 );
        }
        
        startup_end = .;
        
        kernel_start = 0xD0000000;

        .text 0xD0000000 + SIZEOF( .start ) : AT( ADDR( .start ) + SIZEOF( .start ) )
        {
                *(.text) 
                *(.text.*)
                *(.gnu.linkonce.t*)
                *(.const*)
                *(.ro*)
                *(.gnu.linkonce.r*)

                . = ALIGN( 4096 );

        }
        
        .data ADDR( .text ) + SIZEOF( .text ) : AT( LOADADDR( .text ) + SIZEOF( .text ) )
        {
                *(.data)
                
				. = ALIGN( 32 );

                /* constructors */
                __CTOR_LIST__ = .;
                
                /* the number of constructors */
                LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)

                *(SORT(.ctors.*))
                *(.ctor)
                *(.ctors)

                LONG(0)
                
                __CTOR_END__ = .;
                
   				. = ALIGN( 32 );
                
                
                /* deconstructors */
                __DTOR_LIST__ = .;
                
                /* number of deconstructors */
                LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
                
                *(SORT(.dtors.*))
                *(.dtor)
                *(.dtors)

                LONG(0)
                
                __DTOR_END__ = .;

                *(.gnu.linkonce.d*)

        }
        
        . = ALIGN( 4096 );
        
        .bss ALIGN( ADDR( .data ) + SIZEOF( .data ), 4096 ): AT( LOADADDR( .data ) + SIZEOF( .data ) )
        {
                bss_start = ABSOLUTE( . );
                
                *(.bss .bss.* .gnu.linkonce.b.*)

                *(COMMON)

                . = ALIGN( 4096 );

                bss_end = ABSOLUTE( . );
                
                bss_length = bss_end - bss_start;

        }

        kernel_end = .;
        
        kernel_len = kernel_end - kernel_start;
        
        DISCARD :
        {
                *(.comment)
        }
}
It is a little weird at the beginning because when I transfer control to the kernel it is still is real mode.
Post Reply