proc-v7m.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * linux/arch/arm/mm/proc-v7m.S
  3. *
  4. * Copyright (C) 2008 ARM Ltd.
  5. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This is the "shell" of the ARMv7-M processor support.
  12. */
  13. #include <linux/linkage.h>
  14. #include <asm/assembler.h>
  15. #include <asm/memory.h>
  16. #include <asm/v7m.h>
  17. #include "proc-macros.S"
  18. ENTRY(cpu_v7m_proc_init)
  19. ret lr
  20. ENDPROC(cpu_v7m_proc_init)
  21. ENTRY(cpu_v7m_proc_fin)
  22. ret lr
  23. ENDPROC(cpu_v7m_proc_fin)
  24. /*
  25. * cpu_v7m_reset(loc)
  26. *
  27. * Perform a soft reset of the system. Put the CPU into the
  28. * same state as it would be if it had been reset, and branch
  29. * to what would be the reset vector.
  30. *
  31. * - loc - location to jump to for soft reset
  32. */
  33. .align 5
  34. ENTRY(cpu_v7m_reset)
  35. ret r0
  36. ENDPROC(cpu_v7m_reset)
  37. /*
  38. * cpu_v7m_do_idle()
  39. *
  40. * Idle the processor (eg, wait for interrupt).
  41. *
  42. * IRQs are already disabled.
  43. */
  44. ENTRY(cpu_v7m_do_idle)
  45. wfi
  46. ret lr
  47. ENDPROC(cpu_v7m_do_idle)
  48. ENTRY(cpu_v7m_dcache_clean_area)
  49. ret lr
  50. ENDPROC(cpu_v7m_dcache_clean_area)
  51. /*
  52. * There is no MMU, so here is nothing to do.
  53. */
  54. ENTRY(cpu_v7m_switch_mm)
  55. ret lr
  56. ENDPROC(cpu_v7m_switch_mm)
  57. .globl cpu_v7m_suspend_size
  58. .equ cpu_v7m_suspend_size, 0
  59. #ifdef CONFIG_ARM_CPU_SUSPEND
  60. ENTRY(cpu_v7m_do_suspend)
  61. ret lr
  62. ENDPROC(cpu_v7m_do_suspend)
  63. ENTRY(cpu_v7m_do_resume)
  64. ret lr
  65. ENDPROC(cpu_v7m_do_resume)
  66. #endif
  67. ENTRY(cpu_cm7_dcache_clean_area)
  68. dcache_line_size r2, r3
  69. movw r3, #:lower16:BASEADDR_V7M_SCB + V7M_SCB_DCCMVAC
  70. movt r3, #:upper16:BASEADDR_V7M_SCB + V7M_SCB_DCCMVAC
  71. 1: str r0, [r3] @ clean D entry
  72. add r0, r0, r2
  73. subs r1, r1, r2
  74. bhi 1b
  75. dsb
  76. ret lr
  77. ENDPROC(cpu_cm7_dcache_clean_area)
  78. ENTRY(cpu_cm7_proc_fin)
  79. movw r2, #:lower16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
  80. movt r2, #:upper16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
  81. ldr r0, [r2]
  82. bic r0, r0, #(V7M_SCB_CCR_DC | V7M_SCB_CCR_IC)
  83. str r0, [r2]
  84. ret lr
  85. ENDPROC(cpu_cm7_proc_fin)
  86. .section ".init.text", #alloc, #execinstr
  87. __v7m_cm7_setup:
  88. mov r8, #(V7M_SCB_CCR_DC | V7M_SCB_CCR_IC| V7M_SCB_CCR_BP)
  89. b __v7m_setup_cont
  90. /*
  91. * __v7m_setup
  92. *
  93. * This should be able to cover all ARMv7-M cores.
  94. */
  95. __v7m_setup:
  96. mov r8, 0
  97. __v7m_setup_cont:
  98. @ Configure the vector table base address
  99. ldr r0, =BASEADDR_V7M_SCB
  100. ldr r12, =vector_table
  101. str r12, [r0, V7M_SCB_VTOR]
  102. @ enable UsageFault, BusFault and MemManage fault.
  103. ldr r5, [r0, #V7M_SCB_SHCSR]
  104. orr r5, #(V7M_SCB_SHCSR_USGFAULTENA | V7M_SCB_SHCSR_BUSFAULTENA | V7M_SCB_SHCSR_MEMFAULTENA)
  105. str r5, [r0, #V7M_SCB_SHCSR]
  106. @ Lower the priority of the SVC and PendSV exceptions
  107. mov r5, #0x80000000
  108. str r5, [r0, V7M_SCB_SHPR2] @ set SVC priority
  109. mov r5, #0x00800000
  110. str r5, [r0, V7M_SCB_SHPR3] @ set PendSV priority
  111. @ SVC to switch to handler mode. Notice that this requires sp to
  112. @ point to writeable memory because the processor saves
  113. @ some registers to the stack.
  114. badr r1, 1f
  115. ldr r5, [r12, #11 * 4] @ read the SVC vector entry
  116. str r1, [r12, #11 * 4] @ write the temporary SVC vector entry
  117. dsb
  118. mov r6, lr @ save LR
  119. ldr sp, =init_thread_union + THREAD_START_SP
  120. cpsie i
  121. svc #0
  122. 1: cpsid i
  123. str r5, [r12, #11 * 4] @ restore the original SVC vector entry
  124. mov lr, r6 @ restore LR
  125. @ Special-purpose control register
  126. mov r1, #1
  127. msr control, r1 @ Thread mode has unpriviledged access
  128. @ Configure caches (if implemented)
  129. teq r8, #0
  130. stmneia sp, {r0-r6, lr} @ v7m_invalidate_l1 touches r0-r6
  131. blne v7m_invalidate_l1
  132. teq r8, #0 @ re-evalutae condition
  133. ldmneia sp, {r0-r6, lr}
  134. @ Configure the System Control Register to ensure 8-byte stack alignment
  135. @ Note the STKALIGN bit is either RW or RAO.
  136. ldr r0, [r0, V7M_SCB_CCR] @ system control register
  137. orr r0, #V7M_SCB_CCR_STKALIGN
  138. orr r0, r0, r8
  139. ret lr
  140. ENDPROC(__v7m_setup)
  141. /*
  142. * Cortex-M7 processor functions
  143. */
  144. globl_equ cpu_cm7_proc_init, cpu_v7m_proc_init
  145. globl_equ cpu_cm7_reset, cpu_v7m_reset
  146. globl_equ cpu_cm7_do_idle, cpu_v7m_do_idle
  147. globl_equ cpu_cm7_switch_mm, cpu_v7m_switch_mm
  148. define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
  149. define_processor_functions cm7, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
  150. .section ".rodata"
  151. string cpu_arch_name, "armv7m"
  152. string cpu_elf_name "v7m"
  153. string cpu_v7m_name "ARMv7-M"
  154. .section ".proc.info.init", #alloc
  155. .macro __v7m_proc name, initfunc, cache_fns = nop_cache_fns, hwcaps = 0, proc_fns = v7m_processor_functions
  156. .long 0 /* proc_info_list.__cpu_mm_mmu_flags */
  157. .long 0 /* proc_info_list.__cpu_io_mmu_flags */
  158. initfn \initfunc, \name
  159. .long cpu_arch_name
  160. .long cpu_elf_name
  161. .long HWCAP_HALF | HWCAP_THUMB | HWCAP_FAST_MULT | \hwcaps
  162. .long cpu_v7m_name
  163. .long \proc_fns
  164. .long 0 /* proc_info_list.tlb */
  165. .long 0 /* proc_info_list.user */
  166. .long \cache_fns
  167. .endm
  168. /*
  169. * Match ARM Cortex-M7 processor.
  170. */
  171. .type __v7m_cm7_proc_info, #object
  172. __v7m_cm7_proc_info:
  173. .long 0x410fc270 /* ARM Cortex-M7 0xC27 */
  174. .long 0xff0ffff0 /* Mask off revision, patch release */
  175. __v7m_proc __v7m_cm7_proc_info, __v7m_cm7_setup, hwcaps = HWCAP_EDSP, cache_fns = v7m_cache_fns, proc_fns = cm7_processor_functions
  176. .size __v7m_cm7_proc_info, . - __v7m_cm7_proc_info
  177. /*
  178. * Match ARM Cortex-M4 processor.
  179. */
  180. .type __v7m_cm4_proc_info, #object
  181. __v7m_cm4_proc_info:
  182. .long 0x410fc240 /* ARM Cortex-M4 0xC24 */
  183. .long 0xff0ffff0 /* Mask off revision, patch release */
  184. __v7m_proc __v7m_cm4_proc_info, __v7m_setup, hwcaps = HWCAP_EDSP
  185. .size __v7m_cm4_proc_info, . - __v7m_cm4_proc_info
  186. /*
  187. * Match ARM Cortex-M3 processor.
  188. */
  189. .type __v7m_cm3_proc_info, #object
  190. __v7m_cm3_proc_info:
  191. .long 0x410fc230 /* ARM Cortex-M3 0xC23 */
  192. .long 0xff0ffff0 /* Mask off revision, patch release */
  193. __v7m_proc __v7m_cm3_proc_info, __v7m_setup
  194. .size __v7m_cm3_proc_info, . - __v7m_cm3_proc_info
  195. /*
  196. * Match any ARMv7-M processor core.
  197. */
  198. .type __v7m_proc_info, #object
  199. __v7m_proc_info:
  200. .long 0x000f0000 @ Required ID value
  201. .long 0x000f0000 @ Mask for ID
  202. __v7m_proc __v7m_proc_info, __v7m_setup
  203. .size __v7m_proc_info, . - __v7m_proc_info