entry-v7m.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * linux/arch/arm/kernel/entry-v7m.S
  3. *
  4. * Copyright (C) 2008 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Low-level vector interface routines for the ARMv7-M architecture
  11. */
  12. #include <asm/memory.h>
  13. #include <asm/glue.h>
  14. #include <asm/thread_notify.h>
  15. #include <asm/v7m.h>
  16. #include "entry-header.S"
  17. #ifdef CONFIG_TRACE_IRQFLAGS
  18. #error "CONFIG_TRACE_IRQFLAGS not supported on the current ARMv7M implementation"
  19. #endif
  20. __invalid_entry:
  21. v7m_exception_entry
  22. #ifdef CONFIG_PRINTK
  23. adr r0, strerr
  24. mrs r1, ipsr
  25. mov r2, lr
  26. bl printk
  27. #endif
  28. mov r0, sp
  29. bl show_regs
  30. 1: b 1b
  31. ENDPROC(__invalid_entry)
  32. strerr: .asciz "\nUnhandled exception: IPSR = %08lx LR = %08lx\n"
  33. .align 2
  34. __irq_entry:
  35. v7m_exception_entry
  36. @
  37. @ Invoke the IRQ handler
  38. @
  39. mrs r0, ipsr
  40. ldr r1, =V7M_xPSR_EXCEPTIONNO
  41. and r0, r1
  42. sub r0, #16
  43. mov r1, sp
  44. stmdb sp!, {lr}
  45. @ routine called with r0 = irq number, r1 = struct pt_regs *
  46. bl nvic_handle_irq
  47. pop {lr}
  48. @
  49. @ Check for any pending work if returning to user
  50. @
  51. ldr r1, =BASEADDR_V7M_SCB
  52. ldr r0, [r1, V7M_SCB_ICSR]
  53. tst r0, V7M_SCB_ICSR_RETTOBASE
  54. beq 2f
  55. get_thread_info tsk
  56. ldr r2, [tsk, #TI_FLAGS]
  57. tst r2, #_TIF_WORK_MASK
  58. beq 2f @ no work pending
  59. mov r0, #V7M_SCB_ICSR_PENDSVSET
  60. str r0, [r1, V7M_SCB_ICSR] @ raise PendSV
  61. 2:
  62. @ registers r0-r3 and r12 are automatically restored on exception
  63. @ return. r4-r7 were not clobbered in v7m_exception_entry so for
  64. @ correctness they don't need to be restored. So only r8-r11 must be
  65. @ restored here. The easiest way to do so is to restore r0-r7, too.
  66. ldmia sp!, {r0-r11}
  67. add sp, #PT_REGS_SIZE-S_IP
  68. cpsie i
  69. bx lr
  70. ENDPROC(__irq_entry)
  71. __pendsv_entry:
  72. v7m_exception_entry
  73. ldr r1, =BASEADDR_V7M_SCB
  74. mov r0, #V7M_SCB_ICSR_PENDSVCLR
  75. str r0, [r1, V7M_SCB_ICSR] @ clear PendSV
  76. @ execute the pending work, including reschedule
  77. get_thread_info tsk
  78. mov why, #0
  79. b ret_to_user_from_irq
  80. ENDPROC(__pendsv_entry)
  81. /*
  82. * Register switch for ARMv7-M processors.
  83. * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
  84. * previous and next are guaranteed not to be the same.
  85. */
  86. ENTRY(__switch_to)
  87. .fnstart
  88. .cantunwind
  89. add ip, r1, #TI_CPU_SAVE
  90. stmia ip!, {r4 - r11} @ Store most regs on stack
  91. str sp, [ip], #4
  92. str lr, [ip], #4
  93. mov r5, r0
  94. add r4, r2, #TI_CPU_SAVE
  95. ldr r0, =thread_notify_head
  96. mov r1, #THREAD_NOTIFY_SWITCH
  97. bl atomic_notifier_call_chain
  98. mov ip, r4
  99. mov r0, r5
  100. ldmia ip!, {r4 - r11} @ Load all regs saved previously
  101. ldr sp, [ip]
  102. ldr pc, [ip, #4]!
  103. .fnend
  104. ENDPROC(__switch_to)
  105. .data
  106. #if CONFIG_CPU_V7M_NUM_IRQ <= 112
  107. .align 9
  108. #else
  109. .align 10
  110. #endif
  111. /*
  112. * Vector table (Natural alignment need to be ensured)
  113. */
  114. ENTRY(vector_table)
  115. .long 0 @ 0 - Reset stack pointer
  116. .long __invalid_entry @ 1 - Reset
  117. .long __invalid_entry @ 2 - NMI
  118. .long __invalid_entry @ 3 - HardFault
  119. .long __invalid_entry @ 4 - MemManage
  120. .long __invalid_entry @ 5 - BusFault
  121. .long __invalid_entry @ 6 - UsageFault
  122. .long __invalid_entry @ 7 - Reserved
  123. .long __invalid_entry @ 8 - Reserved
  124. .long __invalid_entry @ 9 - Reserved
  125. .long __invalid_entry @ 10 - Reserved
  126. .long vector_swi @ 11 - SVCall
  127. .long __invalid_entry @ 12 - Debug Monitor
  128. .long __invalid_entry @ 13 - Reserved
  129. .long __pendsv_entry @ 14 - PendSV
  130. .long __invalid_entry @ 15 - SysTick
  131. .rept CONFIG_CPU_V7M_NUM_IRQ
  132. .long __irq_entry @ External Interrupts
  133. .endr