entry.S 2.9 KB

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