smtc-asm.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Assembly Language Functions for MIPS MT SMTC support
  3. */
  4. /*
  5. * This file should be built into the kernel only if CONFIG_MIPS_MT_SMTC is set. */
  6. #include <asm/regdef.h>
  7. #include <asm/asmmacro.h>
  8. #include <asm/stackframe.h>
  9. #include <asm/irqflags.h>
  10. /*
  11. * "Software Interrupt" linkage.
  12. *
  13. * This is invoked when an "Interrupt" is sent from one TC to another,
  14. * where the TC to be interrupted is halted, has it's Restart address
  15. * and Status values saved by the "remote control" thread, then modified
  16. * to cause execution to begin here, in kenel mode. This code then
  17. * disguises the TC state as that of an exception and transfers
  18. * control to the general exception or vectored interrupt handler.
  19. */
  20. .set noreorder
  21. /*
  22. The __smtc_ipi_vector would use k0 and k1 as temporaries and
  23. 1) Set EXL (this is per-VPE, so this can't be done by proxy!)
  24. 2) Restore the K/CU and IXMT bits to the pre "exception" state
  25. (EXL means no interrupts and access to the kernel map).
  26. 3) Set EPC to be the saved value of TCRestart.
  27. 4) Jump to the exception handler entry point passed by the sender.
  28. CAN WE PROVE THAT WE WON'T DO THIS IF INTS DISABLED??
  29. */
  30. /*
  31. * Reviled and slandered vision: Set EXL and restore K/CU/IXMT
  32. * state of pre-halt thread, then save everything and call
  33. * thought some function pointer to imaginary_exception, which
  34. * will parse a register value or memory message queue to
  35. * deliver things like interprocessor interrupts. On return
  36. * from that function, jump to the global ret_from_irq code
  37. * to invoke the scheduler and return as appropriate.
  38. */
  39. #define PT_PADSLOT4 (PT_R0-8)
  40. #define PT_PADSLOT5 (PT_R0-4)
  41. .text
  42. .align 5
  43. FEXPORT(__smtc_ipi_vector)
  44. .set noat
  45. /* Disable thread scheduling to make Status update atomic */
  46. DMT 27 # dmt k1
  47. _ehb
  48. /* Set EXL */
  49. mfc0 k0,CP0_STATUS
  50. ori k0,k0,ST0_EXL
  51. mtc0 k0,CP0_STATUS
  52. _ehb
  53. /* Thread scheduling now inhibited by EXL. Restore TE state. */
  54. andi k1,k1,VPECONTROL_TE
  55. beqz k1,1f
  56. emt
  57. 1:
  58. /*
  59. * The IPI sender has put some information on the anticipated
  60. * kernel stack frame. If we were in user mode, this will be
  61. * built above the saved kernel SP. If we were already in the
  62. * kernel, it will be built above the current CPU SP.
  63. *
  64. * Were we in kernel mode, as indicated by CU0?
  65. */
  66. sll k1,k0,3
  67. .set noreorder
  68. bltz k1,2f
  69. move k1,sp
  70. .set reorder
  71. /*
  72. * If previously in user mode, set CU0 and use kernel stack.
  73. */
  74. li k1,ST0_CU0
  75. or k1,k1,k0
  76. mtc0 k1,CP0_STATUS
  77. _ehb
  78. get_saved_sp
  79. /* Interrupting TC will have pre-set values in slots in the new frame */
  80. 2: subu k1,k1,PT_SIZE
  81. /* Load TCStatus Value */
  82. lw k0,PT_TCSTATUS(k1)
  83. /* Write it to TCStatus to restore CU/KSU/IXMT state */
  84. mtc0 k0,$2,1
  85. _ehb
  86. lw k0,PT_EPC(k1)
  87. mtc0 k0,CP0_EPC
  88. /* Save all will redundantly recompute the SP, but use it for now */
  89. SAVE_ALL
  90. CLI
  91. TRACE_IRQS_OFF
  92. /* Function to be invoked passed stack pad slot 5 */
  93. lw t0,PT_PADSLOT5(sp)
  94. /* Argument from sender passed in stack pad slot 4 */
  95. lw a0,PT_PADSLOT4(sp)
  96. LONG_L s0, TI_REGS($28)
  97. LONG_S sp, TI_REGS($28)
  98. PTR_LA ra, ret_from_irq
  99. jr t0
  100. /*
  101. * Called from idle loop to provoke processing of queued IPIs
  102. * First IPI message in queue passed as argument.
  103. */
  104. LEAF(self_ipi)
  105. /* Before anything else, block interrupts */
  106. mfc0 t0,CP0_TCSTATUS
  107. ori t1,t0,TCSTATUS_IXMT
  108. mtc0 t1,CP0_TCSTATUS
  109. _ehb
  110. /* We know we're in kernel mode, so prepare stack frame */
  111. subu t1,sp,PT_SIZE
  112. sw ra,PT_EPC(t1)
  113. sw a0,PT_PADSLOT4(t1)
  114. la t2,ipi_decode
  115. sw t2,PT_PADSLOT5(t1)
  116. /* Save pre-disable value of TCStatus */
  117. sw t0,PT_TCSTATUS(t1)
  118. j __smtc_ipi_vector
  119. nop
  120. END(self_ipi)