title: Problems getting a bare metal ARM app to boot
body: <p>I am trying to use LLVM to generate code for baremetal ARM Cortex M4 development.
  The creation of the IR is going well and LLVM is generating (in my oppinion) correct ARM Thumb ASM.</p>
  
  <p>I have purchased an Arm dev kit to do some testing: an Atmel SAM4L-EK
  <a href="http://www.atmel.com/tools/SAM4L-EK.aspx">http://www.atmel.com/tools/SAM4L-EK.aspx</a></p>
  
  <p>I created an application that turns on the yellow led on the dev board.
  (I just want to get something out of the board)
  I ran an included app with Atmel Studio and the LED works fine.
  But my application seems to do nothing...</p>
  
  <p>Acording to the manual the LED is connected to PC10
  In the datasheet of the ATSAM4LC4C MCU it says that address of the GPIO ports is 0x400E1000, 
  one port takes 0x0200 byes of address space so port C is on 0x400E1000 + 0x0400.</p>
  
  <p>So this is the program output I have (LLVM Output):</p>
  
  <pre><code>.syntax unified
  .eabi_attribute 6, 10
  .eabi_attribute 9, 2
  .eabi_attribute 20, 1
  .eabi_attribute 21, 1
  .eabi_attribute 23, 3
  .eabi_attribute 24, 1
  .eabi_attribute 25, 1
  .eabi_attribute 44, 1
  .file   ""
  .text
  .globl  main
  .align  2
  .type   main,%function
  .code   16
  .thumb_func
  main:
  movw    r0, #5120
  movw    r2, #5184
  movw    r3, #5200
  mov.w   r1, #1024
  movt    r0, #16398
  movt    r2, #16398
  movt    r3, #16398
  .LBB0_1:
  str r1, [r0]
  str r1, [r2]
  str r1, [r3]
  b   .LBB0_1
  .Ltmp0:
  .size   main, .Ltmp0-main
  </code></pre>
  
  <p>This code sets bit 10 in GPIOEnableRegister to 1</p>
  
  <p>then bit 10 in OutputDriverEnableRegister to 1</p>
  
  <p>then bit 10 in OutputValueRegister to 1</p>
  
  <p>At that point the LED should turn on...</p>
  
  <p>This is the startup code I used:</p>
  
  <pre><code>.section INTERRUPT_VECTOR, "x"
  .global _Reset
  _Reset:
  B Reset_Handler /* Reset */
  B . /* Undefined */
  B . /* SWI */
  B . /* Prefetch Abort */
  B . /* Data Abort */
  B . /* reserved */
  B . /* IRQ */
  B . /* FIQ */
  
  Reset_Handler:
  #mov    r0, stack_top
  MOV sp,r0
  BL main
  B .
  </code></pre>
  
  <p>Both assembler files were compiled to object files like this:</p>
  
  <pre><code>as -mcpu=cortex-m4 -g startup.s -o startup.o
  </code></pre>
  
  <p>Using the GNU ARM assembler</p>
  
  <p>This is the linker script I used:</p>
  
  <pre><code>ENTRY(_Reset)
  OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
  OUTPUT_ARCH(arm)
  SEARCH_DIR(.)
  
  /* Memory Spaces Definitions */
  MEMORY
  {
       rom (rx)  : ORIGIN = 0x00000000, LENGTH = 0x00040000 /* flash, 256K */
       ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000 /* sram, 32K */
  }
  
  SECTIONS
  {
   . = 0x0;
   .text : {
   startup.o (INTERRUPT_VECTOR)
   *(.text)
  }
  .data : { *(.data) }
  .bss : { *(.bss COMMON) }
  . = ALIGN(8);0
  . = . + 0x1000; /* 4kB of stack memory */
  stack_top = .;
  }
  </code></pre>
  
  <p>Then the object files were linked to an ELF binary like this:</p>
  
  <pre><code>ld -T linkerscript.ld armtest.o startup.o -o armtest.elf
  </code></pre>
  
  <p>using the GNU Arm Linker</p>
  
  <p>I then uploaded the ELF binary to the board using Atmel Studio</p>
  
  <p>Bot nothing happens (also not after a reset)</p>
  
  <p>Any insights would greatly appreciated!</p>