traps.nr 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. .SN 9
  2. .VS 1 0
  3. .BP
  4. .S1 "TRAPS AND INTERRUPTS"
  5. EM provides a means for the user program to catch all traps
  6. generated by the program itself, the hardware, or external conditions.
  7. This mechanism uses five instructions: LIM, SIM, SIG, TRP and RTT.
  8. This section of the manual may be omitted on the first reading since it
  9. presupposes knowledge of the EM instruction set.
  10. .P
  11. The action taken when a trap occurs is determined by the value
  12. of an internal EM trap register.
  13. This register contains a pointer to a procedure.
  14. Initially the pointer used is zero and all traps halt the
  15. program with, hopefully, a useful message to the outside world.
  16. The SIG instruction can be used to alter the trap register,
  17. it pops a procedure pointer from the
  18. stack into the trap register.
  19. When a trap occurs after storing a nonzero value in the trap
  20. register, the procedure pointed to by the trap register
  21. is called with the trap number
  22. as the only parameter (see below).
  23. SIG returns the previous value of the trap register on the
  24. stack.
  25. Two consecutive SIGs are a no-op.
  26. When a trap occurs, the trap register is reset to its initial
  27. condition, to prevent recursive traps from hanging the machine up,
  28. e.g. stack overflow in the stack overflow handling procedure.
  29. .P
  30. The runtime systems for some languages need to ignore some EM
  31. traps.
  32. EM offers a feature called the ignore mask.
  33. It contains one bit for each of the lowest 16 trap numbers.
  34. The bits are numbered 0 to 15, with the least significant bit
  35. having number 0.
  36. If a certain bit is 1 the corresponding trap never
  37. occurs and processing simply continues.
  38. The actions performed by the offending instruction are
  39. described by the Pascal program in appendix A.
  40. .N
  41. If the bit is 0, traps are not ignored.
  42. The instructions LIM and SIM allow copying and replacement of
  43. the ignore mask.~
  44. .P
  45. The TRP instruction generates a trap, the trap number being found on the
  46. stack.
  47. This is, among other things,
  48. useful for library procedures and runtime systems.
  49. It can also be used by a low level trap procedure to pass the trap to a
  50. higher level one (see example below).
  51. .P
  52. The RTT instruction returns from the trap procedure and continues after the
  53. trap.
  54. In the list below all traps marked with an asterisk ('*') are
  55. considered to be fatal and it is explicitly undefined what happens if
  56. you try to restart after the trap.
  57. .P
  58. The way a trap procedure is called is completely compatible
  59. with normal calling conventions. The only way a trap procedure
  60. differs from normal procedures is the return. It has to use RTT instead
  61. of RET. This is necessary because the complete runtime status is saved on the
  62. stack before calling the procedure and all this status has to be reloaded.
  63. Error numbers are in the range 0 to 252.
  64. The trap numbers are divided into three categories:
  65. .IS 4
  66. .N 1
  67. .PS - 10
  68. .PT ~~0\-~63
  69. EM machine errors, e.g. illegal instruction.
  70. .PS - 8
  71. .PT ~0\-15
  72. maskable
  73. .PT 16\-63
  74. not maskable
  75. .PE
  76. .PT ~64\-127
  77. Reserved for use by compilers, run time systems, etc.
  78. .PT 128\-252
  79. Available for user programs.
  80. .PE 1
  81. .IE
  82. EM machine errors are numbered as follows:
  83. .DS I 5
  84. .TS
  85. tab(@);
  86. n l l.
  87. 0@EARRAY@Array bound error
  88. 1@ERANGE@Range bound error
  89. 2@ESET@Set bound error
  90. 3@EIOVFL@Integer overflow
  91. 4@EFOVFL@Floating overflow
  92. 5@EFUNFL@Floating underflow
  93. 6@EIDIVZ@Divide by 0
  94. 7@EFDIVZ@Divide by 0.0
  95. 8@EIUND@Undefined integer
  96. 9@EFUND@Undefined float
  97. 10@ECONV@Conversion error
  98. 16*@ESTACK@Stack overflow
  99. 17@EHEAP@Heap overflow
  100. 18*@EILLINS@Illegal instruction
  101. 19*@EODDZ@Illegal size argument
  102. 20*@ECASE@Case error
  103. 21*@EMEMFLT@Addressing non existent memory
  104. 22*@EBADPTR@Bad pointer used
  105. 23*@EBADPC@Program counter out of range
  106. 24@EBADLAE@Bad argument of LAE
  107. 25@EBADMON@Bad monitor call
  108. 26@EBADLIN@Argument of LIN too high
  109. 27@EBADGTO@GTO descriptor error
  110. .TE
  111. .DE 0
  112. .P
  113. As an example,
  114. suppose a subprocedure has to be written to do a numeric
  115. calculation.
  116. When an overflow occurs the computation has to be stopped and
  117. the higher level procedure must be resumed.
  118. This can be programmed as follows using the mechanism described above:
  119. .DS B
  120. .ta 1n 24n
  121. mes 2,2,2 ; set sizes
  122. ersave
  123. bss 2,0,0 ; Room to save previous value of trap procedure
  124. msave
  125. bss 2,0,0 ; Room to save previous value of trap mask
  126. pro $calcule,0 ; entry point
  127. lxl 0 ; fill in non-local goto descriptor with LB
  128. ste jmpbuf+4
  129. lor 1 ; and SP
  130. ste jmpbuf+2
  131. lim ; get current ignore mask
  132. ste msave ; save it
  133. lim
  134. loc 16 ; bit for EFOVFL
  135. ior 2 ; set in mask
  136. sim ; ignore EFOVFL from now on
  137. lpi $catch ; load procedure identifier
  138. sig ; catch wil get all traps now
  139. ste ersave ; save previous trap procedure identifier
  140. ; perform calculation now, possibly generating overflow
  141. 1 ; label jumped to by catch procedure
  142. loe ersave ; get old trap procedure
  143. sig ; refer all following trap to old procedure
  144. asp 2 ; remove result of sig
  145. loe msave ; restore previous mask
  146. sim ; done now
  147. ; load result of calculation
  148. ret 2 ; return result
  149. jmpbuf
  150. con *1,0,0
  151. end
  152. .DE 0
  153. .VS
  154. .DS
  155. Example of catch procedure
  156. .ta 1n 24n
  157. pro $catch,0 ; Local procedure that must catch the overflow trap
  158. lol 2 ; Load trap number
  159. loc 4 ; check for overflow
  160. bne *1 ; if other trap, call higher trap procedure
  161. gto jmpbuf ; return to procedure calcule
  162. 1 ; other trap has occurred
  163. loe ersave ; previous trap procedure
  164. sig ; other procedure will get the traps now
  165. asp 2 ; remove the result of sig
  166. lol 2 ; stack trap number
  167. trp ; call other trap procedure
  168. rtt ; if other procedure returns, do the same
  169. end
  170. .DE