Page 1 of 1
ELF or BIN Kernel???
Posted: Wed Jul 11, 2007 8:16 pm
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
, in plain binary files , does the BSS section exist ?
Posted: Wed Jul 11, 2007 8:34 pm
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.
Posted: Wed Jul 11, 2007 8:50 pm
by d4n1l0d
But do you use C code ??
If you do , what is your linker script??
Posted: Wed Jul 11, 2007 8:50 pm
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.
Posted: Wed Jul 11, 2007 8:57 pm
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.