1
0

kernxfr.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. kernxfr.S
  5. Abstract:
  6. This module implements the code necessary to transfer execution from the
  7. loader to the kernel on ARM systems.
  8. Author:
  9. Evan Green 15-Aug-2012
  10. Environment:
  11. Boot
  12. --*/
  13. ##
  14. ## ------------------------------------------------------------------ Includes
  15. ##
  16. #include <minoca/kernel/arm.inc>
  17. ##
  18. ## --------------------------------------------------------------- Definitions
  19. ##
  20. ##
  21. ## ----------------------------------------------------------------------- Code
  22. ##
  23. ASSEMBLY_FILE_HEADER
  24. ##
  25. ## VOID
  26. ## BoEnablePaging (
  27. ## VOID
  28. ## )
  29. ##
  30. /*++
  31. Routine Description:
  32. This routine turns paging on in the processor.
  33. Arguments:
  34. None.
  35. Return Value:
  36. None.
  37. --*/
  38. FUNCTION BoEnablePaging
  39. stmdb %sp!, {%lr}
  40. bl BoInvalidateEntireCache
  41. mov %r0, #0
  42. ##
  43. ## Write to CP15, register 8 to clear the entire instruction and data TLB.
  44. ##
  45. mcr p15, 0, %r0, c8, c7, 0 @ TLBIALL, Clear entire TLB.
  46. ##
  47. ## Write to CONTEXTIDR to set the ASID to 0, which must be consistent
  48. ## across all processors.
  49. ##
  50. mcr p15, 0, %r0, c13, c0, 1 @ Clear CONTEXTIDR
  51. mcr p15, 0, %r0, c2, c0, 1 @ Clear TTBR1
  52. mcr p15, 0, %r0, c5, c0, 0 @ Clear DFSR
  53. mcr p15, 0, %r0, c5, c0, 1 @ Clear IFSR
  54. mcr p15, 0, %r0, c6, c0, 0 @ Clear DFAR
  55. mcr p15, 0, %r0, c6, c0, 2 @ Clear IFAR
  56. ##
  57. ## Write to CP15, register 3 to set up domain access control for domain 0
  58. ## as a client, which means use the translation table's access control.
  59. ##
  60. mov %r0, #1
  61. mcr p15, 0, %r0, %cr3, %cr0, 0
  62. ##
  63. ## Write to CP15, register 2 to set up the first level table base.
  64. ## An opcode2 of 2 sets the control register (TTBCR), which is being set to
  65. ## 0 to always use TTBR0. An opcode2 of 0 sets TTBR0, the Translation Table
  66. ## Base Register.
  67. ##
  68. mov %r0, #0
  69. mcr p15, 0, %r0, %cr2, %cr0, 2
  70. ldr %r0, =BoFirstLevelTable
  71. ldr %r0, [%r0]
  72. ldr %r1, =TTBR_ADDRESS_MASK
  73. bic %r0, %r0, %r1
  74. ldr %r1, =BoTtbrCacheAttributes
  75. ldr %r1, [%r1]
  76. orr %r0, %r0, %r1
  77. mcr p15, 0, %r0, %cr2, %cr0, 0
  78. ##
  79. ## Enable the MMU.
  80. ##
  81. ldr %r0, =MMU_CONTROL_DEFAULT_VALUE
  82. mcr p15, 0, %r0, %cr1, %cr0, 0
  83. bl ArSerializeExecution
  84. ##
  85. ## Invalidate instruction caches and flush the branch target cache.
  86. ##
  87. mcr p15, 0, %r0, c7, c5, 0 @ Write to ICIALLU, flush I-cache.
  88. ##
  89. ## Paging is now enabled. Return.
  90. ##
  91. ldmia %sp!, {%lr}
  92. bx %lr
  93. END_FUNCTION BoEnablePaging
  94. ##
  95. ## VOID
  96. ## BoTransferToKernelAsm (
  97. ## PVOID Parameters,
  98. ## PVOID EntryPoint,
  99. ## PVOID StackAddress
  100. ## )
  101. ##
  102. /*++
  103. Routine Description:
  104. This routine transfers control of execution to the kernel.
  105. Arguments:
  106. Parameters - Supplies the parameter block to pass on to the kernel for its
  107. initialization.
  108. EntryPoint - Supplies the entry point of the kernel. The function will end
  109. with a jump to here.
  110. StackAddress - Supplies the top of the kernel stack. The stack pointer will
  111. get set to this value just before the kernel is launched.
  112. Return Value:
  113. None. This function does not return.
  114. --*/
  115. FUNCTION BoTransferToKernelAsm
  116. mov %sp, %r2 @ Switch to the new stack.
  117. mov %fp, #0 @ Reset the ARM frame pointer.
  118. mov %r7, #0 @ Reset the Thumb frame pointer.
  119. mov %lr, #0 @ Reset the link register.
  120. bx %r1 @ Jump to the entry point.
  121. END_FUNCTION BoTransferToKernelAsm