Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

288 lines
5.8 KiB

4 years ago
  1. #if defined(JAZZ) && defined(R3000)
  2. /*++
  3. Copyright (c) 1990 Microsoft Corporation
  4. Module Name:
  5. j3trap.s
  6. Abstract:
  7. This module will handle exceptions
  8. It will save the state of the processor, check jump table
  9. to see if it should dispatch somewhere, and then return to
  10. monitor.
  11. Author:
  12. John Cooper (johncoop) 4-Oct-90
  13. Environment:
  14. Kernel mode
  15. Revision History:
  16. --*/
  17. //
  18. // include header file
  19. //
  20. #include "ksmips.h"
  21. #include "selfmap.h"
  22. #include "led.h"
  23. #define PROM_BASE (KSEG1_BASE | 0x1fc00000)
  24. #define PROM_ENTRY(x) (PROM_BASE + ((x) * 8))
  25. .set noat
  26. .set noreorder
  27. .text
  28. .globl ExceptionDispatch
  29. ExceptionDispatch:
  30. /*++
  31. Routine Description:
  32. This routine will use a lookup table based on the exception
  33. cause, to call an exception handler. If the value in
  34. lookup table is zero, the state of the machine is saved,
  35. and control is passed to monitor.
  36. The return value of the exception handler indicates where
  37. control should go when the exception condition is cleared.
  38. Arguments:
  39. K1 - Contains the cause register.
  40. Return Value:
  41. None.
  42. --*/
  43. //
  44. // Need to save return address before calling an exec. handler.
  45. //
  46. li k0,GLOBAL_DATA_BASE // base of saved state
  47. sw ra, 0x7C(k0) // save ra
  48. //
  49. // Get jump vector from lookup table based on cause.
  50. // Call handler if value is non-zero
  51. //
  52. li k0,EXCEPTION_JUMP_TABLE // base of jump table
  53. addu k0,k0,k1 // add offset to base
  54. lw k1,0(k0) // get jump vector from tbl
  55. li k0,GOTO_MONITOR // go back to monitor by default
  56. beq k1,zero,ExceptionReturn // go save state and call mon.
  57. li ra,COMMONEXCEPTION // load this value into ra.
  58. // this will get passed as
  59. // argument to MonitorInit()
  60. // which will then print a message
  61. // saying a COMMONEXCEPTION occured.
  62. // COMMON EXCEPTION is an unaligned #.
  63. // if k1 != zero the jal reloads ra
  64. jal k1 // with the right value.
  65. nop // control will pass to the
  66. // Exception Return routine next.
  67. // return value from handler
  68. // should be returned in k0.
  69. // this is passed as argument
  70. // to ExceptionReturn.
  71. .globl ExceptionReturn
  72. ExceptionReturn:
  73. /*++
  74. Routine Description:
  75. This routine will restore any registers that have been modified
  76. by the trap handler. Control is then passed back to one
  77. of three places. Either the monitor, the location stored in the
  78. EPC, or the value supplied in the argumnet k0.
  79. Arguments:
  80. k0 - supplies indication of where to go after clearing exception.
  81. if bits [1:0] are 00B then go to location indicated
  82. in k0. if bits [1:0] are GOTO_MONITOR, then control
  83. is passed to MonitorReInit(). if bits are GOTO_EPC then
  84. control is returned to location where exception occured.
  85. Return Value:
  86. None.
  87. --*/
  88. //
  89. // Return value from exec. handler is in k0.
  90. // if low bits are 00, then return to value in k0
  91. // if low bits are 01, then return to Err PC
  92. // if low bits are 10, then return to monitor
  93. //
  94. andi k1,k0,3 // k1 = k0 & 3
  95. beq k1,zero,returntok0 // go if return code is 0
  96. andi k1,k0,GOTO_EPC // k1 = k0 & 1
  97. bne k1,zero,returntoEPC // if bit1=1 then GOTO_EPC
  98. andi k1,k0,GOTO_MONITOR // k1 = k0 & 2
  99. bne k1,zero,returntomonitor // if bit2=1 then GOTO_MONITOR
  100. nop
  101. b returntomonitor // default return action
  102. nop
  103. returntok0:
  104. //
  105. // restore value to ra
  106. //
  107. li k1,GLOBAL_DATA_BASE // base of saved state
  108. lw ra, 0x7C(k1) // restore ra
  109. //
  110. // return to value in k0 when clearing exception condition
  111. // do this by putting k0 in EPC
  112. //
  113. j k0 // return to k0
  114. rfe // restore pre-exc state
  115. returntoEPC:
  116. //
  117. // restore value to ra
  118. //
  119. li k1,GLOBAL_DATA_BASE // base of saved state
  120. //
  121. // return to location where exeception was caused
  122. //
  123. mfc0 k0,epc // get return PC from cop0
  124. lw ra, 0x7C(k1) // restore ra
  125. j k0 // jump to (EPC)
  126. rfe // clear exception condition
  127. returntomonitor:
  128. //
  129. // return to monitor by calling MonitorReInit()
  130. //
  131. //li k0,MONITOR_LINK_ADDRESS
  132. //j k0
  133. //rfe // restore pre-exc state
  134. li k0,PROM_ENTRY(14)
  135. lui a0,LED_BLINK
  136. jal k0
  137. ori a0,a0,0xFC
  138. .globl TLBMiss
  139. TLBMiss:
  140. /*++
  141. Routine Description:
  142. This routine will modifiy the TLB when a miss occurs.
  143. It will take the failed virtual address and place it
  144. in the TLB as a physical address. This will make
  145. a one to one mapping between virtual and physical.
  146. If the address is E2000000 - E3FFFFFF, then routine
  147. will subtract off 52000000 for eisa spaces.
  148. This routine is only expected to be used for the R3000
  149. Note that the control from the exception vector is passed
  150. to the dispatch routine. The dispatch routine calls this
  151. routine - control is passed back to the dispatch routine.
  152. Arguments:
  153. None.
  154. Return Value:
  155. None.
  156. --*/
  157. //
  158. // load bad virtual address - the address that missed in TLB
  159. //
  160. mfc0 k0,badvaddr
  161. //
  162. // mask out page offset to get virtual page number.
  163. // offset differs in size between R4000 and R3000
  164. //
  165. li k1,0xFFFFF000
  166. and k0,k0,k1
  167. //
  168. // store bad virtual address in the EntryHi register to
  169. //
  170. mtc0 k0,entryhi
  171. //
  172. // check if value is between E2000000 - E3FFFFFF
  173. // set bits in range (01FFFFFF) and compare to E3FFFFFF
  174. //
  175. li k1,0x01FFFFFF
  176. or k0,k0,k1
  177. li k1,0xE3FFFFFF
  178. bne k1,k0,noteisa
  179. //
  180. // subtract off 52000000
  181. //
  182. mfc0 k0,entryhi
  183. li k1,0x52000000
  184. sub k0,k0,k1
  185. nop
  186. noteisa:
  187. //
  188. // set non-cached, dirty, valid, and global bits
  189. //
  190. //
  191. li k1,(1<<ENTRYLO_D) + (1<<ENTRYLO_V) + (1<<ENTRYLO_G) + (1<<ENTRYLO_N)
  192. or k0,k0,k1
  193. mtc0 k0,entrylo
  194. //
  195. // set index to 63 to write the 63 entry. always replace this
  196. // entry to preserve all the other entries.
  197. //
  198. li k0,(63<<INDEX_INDEX)
  199. mtc0 k0,index
  200. nop
  201. //
  202. // write the tlb entry.
  203. //
  204. tlbwi
  205. nop
  206. //
  207. // return from exception - tell dispatch to go to EPC
  208. //
  209. j ra
  210. li k0,GOTO_EPC
  211. #endif // R3000 && JAZZ