proc-v7m.S 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. /* Calculate exc_ret */
  124. orr r10, lr, #EXC_RET_THREADMODE_PROCESSSTACK
  125. ldmia sp, {r0-r3, r12}
  126. str r5, [r12, #11 * 4] @ restore the original SVC vector entry
  127. mov lr, r6 @ restore LR
  128. @ Special-purpose control register
  129. mov r1, #1
  130. msr control, r1 @ Thread mode has unpriviledged access
  131. @ Configure caches (if implemented)
  132. teq r8, #0
  133. stmneia sp, {r0-r6, lr} @ v7m_invalidate_l1 touches r0-r6
  134. blne v7m_invalidate_l1
  135. teq r8, #0 @ re-evalutae condition
  136. ldmneia sp, {r0-r6, lr}
  137. @ Configure the System Control Register to ensure 8-byte stack alignment
  138. @ Note the STKALIGN bit is either RW or RAO.
  139. ldr r0, [r0, V7M_SCB_CCR] @ system control register
  140. orr r0, #V7M_SCB_CCR_STKALIGN
  141. orr r0, r0, r8
  142. ret lr
  143. ENDPROC(__v7m_setup)
  144. /*
  145. * Cortex-M7 processor functions
  146. */
  147. globl_equ cpu_cm7_proc_init, cpu_v7m_proc_init
  148. globl_equ cpu_cm7_reset, cpu_v7m_reset
  149. globl_equ cpu_cm7_do_idle, cpu_v7m_do_idle
  150. globl_equ cpu_cm7_switch_mm, cpu_v7m_switch_mm
  151. define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
  152. define_processor_functions cm7, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
  153. .section ".rodata"
  154. string cpu_arch_name, "armv7m"
  155. string cpu_elf_name "v7m"
  156. string cpu_v7m_name "ARMv7-M"
  157. .section ".proc.info.init", #alloc
  158. .macro __v7m_proc name, initfunc, cache_fns = nop_cache_fns, hwcaps = 0, proc_fns = v7m_processor_functions
  159. .long 0 /* proc_info_list.__cpu_mm_mmu_flags */
  160. .long 0 /* proc_info_list.__cpu_io_mmu_flags */
  161. initfn \initfunc, \name
  162. .long cpu_arch_name
  163. .long cpu_elf_name
  164. .long HWCAP_HALF | HWCAP_THUMB | HWCAP_FAST_MULT | \hwcaps
  165. .long cpu_v7m_name
  166. .long \proc_fns
  167. .long 0 /* proc_info_list.tlb */
  168. .long 0 /* proc_info_list.user */
  169. .long \cache_fns
  170. .endm
  171. /*
  172. * Match ARM Cortex-M7 processor.
  173. */
  174. .type __v7m_cm7_proc_info, #object
  175. __v7m_cm7_proc_info:
  176. .long 0x410fc270 /* ARM Cortex-M7 0xC27 */
  177. .long 0xff0ffff0 /* Mask off revision, patch release */
  178. __v7m_proc __v7m_cm7_proc_info, __v7m_cm7_setup, hwcaps = HWCAP_EDSP, cache_fns = v7m_cache_fns, proc_fns = cm7_processor_functions
  179. .size __v7m_cm7_proc_info, . - __v7m_cm7_proc_info
  180. /*
  181. * Match ARM Cortex-M4 processor.
  182. */
  183. .type __v7m_cm4_proc_info, #object
  184. __v7m_cm4_proc_info:
  185. .long 0x410fc240 /* ARM Cortex-M4 0xC24 */
  186. .long 0xff0ffff0 /* Mask off revision, patch release */
  187. __v7m_proc __v7m_cm4_proc_info, __v7m_setup, hwcaps = HWCAP_EDSP
  188. .size __v7m_cm4_proc_info, . - __v7m_cm4_proc_info
  189. /*
  190. * Match ARM Cortex-M3 processor.
  191. */
  192. .type __v7m_cm3_proc_info, #object
  193. __v7m_cm3_proc_info:
  194. .long 0x410fc230 /* ARM Cortex-M3 0xC23 */
  195. .long 0xff0ffff0 /* Mask off revision, patch release */
  196. __v7m_proc __v7m_cm3_proc_info, __v7m_setup
  197. .size __v7m_cm3_proc_info, . - __v7m_cm3_proc_info
  198. /*
  199. * Match any ARMv7-M processor core.
  200. */
  201. .type __v7m_proc_info, #object
  202. __v7m_proc_info:
  203. .long 0x000f0000 @ Required ID value
  204. .long 0x000f0000 @ Mask for ID
  205. __v7m_proc __v7m_proc_info, __v7m_setup
  206. .size __v7m_proc_info, . - __v7m_proc_info