Page 1 of 1

Bare metal beginner questions

Posted: Tue Dec 25, 2012 1:25 am
by Asion
Merry Christmas everyone !!

After following the beginners BakingPi lessons I wanted to re-implement what I learned there in C.
So after some searching I wrote this test program to see If everything compiled and linked correctly.

main.s

Code: Select all

.text
.global _start

_start:
mov sp, #0x00010000
bl notmain

hang:
b hang
notmain.c

Code: Select all

unsigned int apple;
unsigned int orange=5;
const unsigned int banana=9;
int notmain ( void )
{
	apple+=7;
}
I compiled this program on a mac with the yagarto toolchain and I used:

Code: Select all

arm-none-eabi-gcc -O2 -c notmain.c -o notmain.o
to compile the c file and :

Code: Select all

arm-none-eabi-ld main.o notmain.o -o test.elf -T kernel.ld
to compile the arm file. Then i linked everything together with:

Code: Select all

arm-none-eabi-ld --no-undefined main.o notmain.o -o hello.elf -T kernel.ld
This is the kernel.ld linker script that I copied straight from the BakingPi examples

Code: Select all

SECTIONS {
	/*
	* First and formost we need the .init section, containing the IVT.
	*/
	.init 0x0000 : {
		*(.init)
	}
	
	/* 
	* We allow room for the ATAGs and the stack and then start our code at
	* 0x8000.
	*/
	.text 0x8000 : {
		*(.text)
	}
	
	/* 
	* Next we put the data.
	*/
	.data : {
		*(.data)
	}

	/* 
	* Next we put the rodata.
	*/
	.rodata : {
		*(.rodata)
	}

	/* 
	* Next we put the bss.
	*/
	.bss : {
		*(.bss)
	}	
}
When I used objcopy to dump the file I noticed this two unexpected sections after .text .data .bss and .rodata

Code: Select all

Disassembly of section .ARM.attributes:

00000000 <.ARM.attributes>:
   0:	00002d41 	andeq	r2, r0, r1, asr #26
   4:	61656100 	cmnvs	r5, r0, lsl #2
   8:	01006962 	tsteq	r0, r2, ror #18
   c:	00000023 	andeq	r0, r0, r3, lsr #32
  10:	4d524105 	ldfmie	f4, [r2, #-20]	; 0xffffffec
  14:	4d445437 	cfstrdmi	mvd5, [r4, #-220]	; 0xffffff24
  18:	02060049 	andeq	r0, r6, #73	; 0x49
  1c:	01090108 	tsteq	r9, r8, lsl #2
  20:	01140412 	tsteq	r4, r2, lsl r4
  24:	03170115 	tsteq	r7, #1073741829	; 0x40000005
  28:	011a0118 	tsteq	sl, r8, lsl r1
  2c:	Address 0x000000000000002c is out of bounds.


Disassembly of section .comment:

00000000 <.comment>:
   0:	3a434347 	bcc	10d0d24 <banana+0x10c8cf8>
   4:	4e472820 	cdpmi	8, 4, cr2, cr7, cr0, {1}
   8:	34202955 	strtcc	r2, [r0], #-2389	; 0x955
   c:	312e372e 	teqcc	lr, lr, lsr #14
	...
Why are this sections in the assembled files ? Should I try to remove them ? Did I do something wrong ?
I'm a total noob with bare metal so excuse me if this question is stupid :D .

Re: Bare metal beginner questions

Posted: Tue Dec 25, 2012 6:15 am
by tufty
Don't worry about them, they're artefacts left by the compiler.

Re: Bare metal beginner questions

Posted: Wed Dec 26, 2012 3:03 am
by Asion
tufty wrote:Don't worry about them, they're artefacts left by the compiler.
Ok thanks, now It's time to light up a couple of leds :D.