entry.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
  3. * Copyright (C) 2004 Microtronix Datacom Ltd.
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. */
  9. #ifndef _ASM_NIOS2_ENTRY_H
  10. #define _ASM_NIOS2_ENTRY_H
  11. #ifdef __ASSEMBLY__
  12. #include <asm/processor.h>
  13. #include <asm/registers.h>
  14. #include <asm/asm-offsets.h>
  15. /*
  16. * Standard Nios2 interrupt entry and exit macros.
  17. * Must be called with interrupts disabled.
  18. */
  19. .macro SAVE_ALL
  20. rdctl r24, estatus
  21. andi r24, r24, ESTATUS_EU
  22. beq r24, r0, 1f /* In supervisor mode, already on kernel stack */
  23. movia r24, _current_thread /* Switch to current kernel stack */
  24. ldw r24, 0(r24) /* using the thread_info */
  25. addi r24, r24, THREAD_SIZE-PT_REGS_SIZE
  26. stw sp, PT_SP(r24) /* Save user stack before changing */
  27. mov sp, r24
  28. br 2f
  29. 1 : mov r24, sp
  30. addi sp, sp, -PT_REGS_SIZE /* Backup the kernel stack pointer */
  31. stw r24, PT_SP(sp)
  32. 2 : stw r1, PT_R1(sp)
  33. stw r2, PT_R2(sp)
  34. stw r3, PT_R3(sp)
  35. stw r4, PT_R4(sp)
  36. stw r5, PT_R5(sp)
  37. stw r6, PT_R6(sp)
  38. stw r7, PT_R7(sp)
  39. stw r8, PT_R8(sp)
  40. stw r9, PT_R9(sp)
  41. stw r10, PT_R10(sp)
  42. stw r11, PT_R11(sp)
  43. stw r12, PT_R12(sp)
  44. stw r13, PT_R13(sp)
  45. stw r14, PT_R14(sp)
  46. stw r15, PT_R15(sp)
  47. stw r2, PT_ORIG_R2(sp)
  48. stw r7, PT_ORIG_R7(sp)
  49. stw ra, PT_RA(sp)
  50. stw fp, PT_FP(sp)
  51. stw gp, PT_GP(sp)
  52. rdctl r24, estatus
  53. stw r24, PT_ESTATUS(sp)
  54. stw ea, PT_EA(sp)
  55. .endm
  56. .macro RESTORE_ALL
  57. ldw r1, PT_R1(sp) /* Restore registers */
  58. ldw r2, PT_R2(sp)
  59. ldw r3, PT_R3(sp)
  60. ldw r4, PT_R4(sp)
  61. ldw r5, PT_R5(sp)
  62. ldw r6, PT_R6(sp)
  63. ldw r7, PT_R7(sp)
  64. ldw r8, PT_R8(sp)
  65. ldw r9, PT_R9(sp)
  66. ldw r10, PT_R10(sp)
  67. ldw r11, PT_R11(sp)
  68. ldw r12, PT_R12(sp)
  69. ldw r13, PT_R13(sp)
  70. ldw r14, PT_R14(sp)
  71. ldw r15, PT_R15(sp)
  72. ldw ra, PT_RA(sp)
  73. ldw fp, PT_FP(sp)
  74. ldw gp, PT_GP(sp)
  75. ldw r24, PT_ESTATUS(sp)
  76. wrctl estatus, r24
  77. ldw ea, PT_EA(sp)
  78. ldw sp, PT_SP(sp) /* Restore sp last */
  79. .endm
  80. .macro SAVE_SWITCH_STACK
  81. addi sp, sp, -SWITCH_STACK_SIZE
  82. stw r16, SW_R16(sp)
  83. stw r17, SW_R17(sp)
  84. stw r18, SW_R18(sp)
  85. stw r19, SW_R19(sp)
  86. stw r20, SW_R20(sp)
  87. stw r21, SW_R21(sp)
  88. stw r22, SW_R22(sp)
  89. stw r23, SW_R23(sp)
  90. stw fp, SW_FP(sp)
  91. stw gp, SW_GP(sp)
  92. stw ra, SW_RA(sp)
  93. .endm
  94. .macro RESTORE_SWITCH_STACK
  95. ldw r16, SW_R16(sp)
  96. ldw r17, SW_R17(sp)
  97. ldw r18, SW_R18(sp)
  98. ldw r19, SW_R19(sp)
  99. ldw r20, SW_R20(sp)
  100. ldw r21, SW_R21(sp)
  101. ldw r22, SW_R22(sp)
  102. ldw r23, SW_R23(sp)
  103. ldw fp, SW_FP(sp)
  104. ldw gp, SW_GP(sp)
  105. ldw ra, SW_RA(sp)
  106. addi sp, sp, SWITCH_STACK_SIZE
  107. .endm
  108. #endif /* __ASSEMBLY__ */
  109. #endif /* _ASM_NIOS2_ENTRY_H */