entry-v7m.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. adr r0, strerr
  23. mrs r1, ipsr
  24. mov r2, lr
  25. bl printk
  26. mov r0, sp
  27. bl show_regs
  28. 1: b 1b
  29. ENDPROC(__invalid_entry)
  30. strerr: .asciz "\nUnhandled exception: IPSR = %08lx LR = %08lx\n"
  31. .align 2
  32. __irq_entry:
  33. v7m_exception_entry
  34. @
  35. @ Invoke the IRQ handler
  36. @
  37. mrs r0, ipsr
  38. ldr r1, =V7M_xPSR_EXCEPTIONNO
  39. and r0, r1
  40. sub r0, #16
  41. mov r1, sp
  42. stmdb sp!, {lr}
  43. @ routine called with r0 = irq number, r1 = struct pt_regs *
  44. bl nvic_handle_irq
  45. pop {lr}
  46. @
  47. @ Check for any pending work if returning to user
  48. @
  49. ldr r1, =BASEADDR_V7M_SCB
  50. ldr r0, [r1, V7M_SCB_ICSR]
  51. tst r0, V7M_SCB_ICSR_RETTOBASE
  52. beq 2f
  53. get_thread_info tsk
  54. ldr r2, [tsk, #TI_FLAGS]
  55. tst r2, #_TIF_WORK_MASK
  56. beq 2f @ no work pending
  57. mov r0, #V7M_SCB_ICSR_PENDSVSET
  58. str r0, [r1, V7M_SCB_ICSR] @ raise PendSV
  59. 2:
  60. @ registers r0-r3 and r12 are automatically restored on exception
  61. @ return. r4-r7 were not clobbered in v7m_exception_entry so for
  62. @ correctness they don't need to be restored. So only r8-r11 must be
  63. @ restored here. The easiest way to do so is to restore r0-r7, too.
  64. ldmia sp!, {r0-r11}
  65. add sp, #S_FRAME_SIZE-S_IP
  66. cpsie i
  67. bx lr
  68. ENDPROC(__irq_entry)
  69. __pendsv_entry:
  70. v7m_exception_entry
  71. ldr r1, =BASEADDR_V7M_SCB
  72. mov r0, #V7M_SCB_ICSR_PENDSVCLR
  73. str r0, [r1, V7M_SCB_ICSR] @ clear PendSV
  74. @ execute the pending work, including reschedule
  75. get_thread_info tsk
  76. mov why, #0
  77. b ret_to_user
  78. ENDPROC(__pendsv_entry)
  79. /*
  80. * Register switch for ARMv7-M processors.
  81. * r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info
  82. * previous and next are guaranteed not to be the same.
  83. */
  84. ENTRY(__switch_to)
  85. .fnstart
  86. .cantunwind
  87. add ip, r1, #TI_CPU_SAVE
  88. stmia ip!, {r4 - r11} @ Store most regs on stack
  89. str sp, [ip], #4
  90. str lr, [ip], #4
  91. mov r5, r0
  92. add r4, r2, #TI_CPU_SAVE
  93. ldr r0, =thread_notify_head
  94. mov r1, #THREAD_NOTIFY_SWITCH
  95. bl atomic_notifier_call_chain
  96. mov ip, r4
  97. mov r0, r5
  98. ldmia ip!, {r4 - r11} @ Load all regs saved previously
  99. ldr sp, [ip]
  100. ldr pc, [ip, #4]!
  101. .fnend
  102. ENDPROC(__switch_to)
  103. .data
  104. .align 8
  105. /*
  106. * Vector table (64 words => 256 bytes natural alignment)
  107. */
  108. ENTRY(vector_table)
  109. .long 0 @ 0 - Reset stack pointer
  110. .long __invalid_entry @ 1 - Reset
  111. .long __invalid_entry @ 2 - NMI
  112. .long __invalid_entry @ 3 - HardFault
  113. .long __invalid_entry @ 4 - MemManage
  114. .long __invalid_entry @ 5 - BusFault
  115. .long __invalid_entry @ 6 - UsageFault
  116. .long __invalid_entry @ 7 - Reserved
  117. .long __invalid_entry @ 8 - Reserved
  118. .long __invalid_entry @ 9 - Reserved
  119. .long __invalid_entry @ 10 - Reserved
  120. .long vector_swi @ 11 - SVCall
  121. .long __invalid_entry @ 12 - Debug Monitor
  122. .long __invalid_entry @ 13 - Reserved
  123. .long __pendsv_entry @ 14 - PendSV
  124. .long __invalid_entry @ 15 - SysTick
  125. .rept 64 - 16
  126. .long __irq_entry @ 16..64 - External Interrupts
  127. .endr