entry.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. entry.s
  5. Abstract:
  6. This module implements the initial entry point into the ARMv7 firmware. Its
  7. job is to do essential initialization and call the C main function.
  8. Author:
  9. Evan Green 27-Feb-2014
  10. Environment:
  11. MBR
  12. --*/
  13. ##
  14. ## ------------------------------------------------------------------- Includes
  15. ##
  16. #include <minoca/kernel/arm.inc>
  17. ##
  18. ## ---------------------------------------------------------------- Definitions
  19. ##
  20. .equ STACK_SIZE, 0x4000
  21. ##
  22. ## ----------------------------------------------------------------------- Code
  23. ##
  24. ##
  25. ## .text specifies that this code belongs in the executable section. This is
  26. ## the only section in the MBR code, data also lives in the text section.
  27. ## .arm specifies that this code should be compiled in ARM mode.
  28. ##
  29. .text
  30. .arm
  31. ##
  32. ## .global allows this label to be visible to the linker. _start is the entry
  33. ## point to the MBR code, so it needs to be globally visible.
  34. ##
  35. .global _start
  36. ##
  37. ## This is the entry point for the ARM boot loader. It changes to SVC mode,
  38. ## sets up the initial stack, and jumps to the main loader.
  39. ##
  40. _start:
  41. ##
  42. ## Disable interrupts and switch to SVC mode.
  43. ##
  44. mov %r2, #(PSR_FLAG_IRQ | ARM_MODE_SVC)
  45. msr CPSR_c, %r2
  46. ##
  47. ## Flip some essential MMU bits allowing unaligned accesses.
  48. ##
  49. mrc p15, 0, %r0, %cr1, %cr0, 0
  50. bic %r0, %r0, #MMU_ALIGNMENT_FAULT_ENABLED
  51. orr %r0, %r0, #MMU_UNALIGNED_ACCESS_ENABLED
  52. mcr p15, 0, %r0, %cr1, %cr0, 0
  53. ##
  54. ## Zero out the BSS section.
  55. ##
  56. ldr %r1, =__bss_start__
  57. ldr %r2, =__bss_end__
  58. mov %r0, #0
  59. BssZeroLoop:
  60. str %r0, [%r1], #4
  61. cmp %r1, %r2
  62. blt BssZeroLoop
  63. ##
  64. ## The stack starts at the image base and works downwards.
  65. ##
  66. adr %r0, _start @ Get the current address for the stack top.
  67. ldr %r1, =STACK_SIZE @ Get the stack size.
  68. mov %sp, %r0 @ Set the stack.
  69. mov %r11, #0 @ Zero the ARM frame pointer.
  70. mov %r7, #0 @ Zero out the Thumb frame pointer.
  71. mov %r2, %r7 @ Zero out another temporary register.
  72. push {%r2, %r7} @ Create an empty stack frame for debugging.
  73. blx EfiPandaBoardMain
  74. LoopForever:
  75. b LoopForever