_trap.s 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #
  2. ! $Source$
  3. ! $State$
  4. ! $Revision$
  5. ! Declare segments (the order is important).
  6. .sect .text
  7. .sect .rom
  8. .sect .data
  9. .sect .bss
  10. .define .trp
  11. .define earray, erange, eset, eiovfl, efovfl, efunfl, eidivz, eidivz
  12. .define efdivz, eiund, efund, econv, estack, eheap, eillins, eoddz
  13. .define ecase, ememflt, ebadptr, ebadpc, ebadlae, ebadmon, ebadlin, ebadgto
  14. .define eunimpl
  15. .sect .text
  16. ! Trap routine
  17. ! Expects trap number on stack.
  18. ! Just returns if trap has to be ignored.
  19. ! Otherwise it calls a user-defined trap handler if provided.
  20. ! When no user-defined trap handler is provided or when the user-defined
  21. ! trap handler causes a new trap, a message is printed
  22. ! and control is returned to the monitor.
  23. EARRAY = 0
  24. ERANGE = 1
  25. ESET = 2
  26. EIOVFL = 3
  27. EFOVFL = 4
  28. EFUNFL = 5
  29. EIDIVZ = 6
  30. EFDIVZ = 7
  31. EIUND = 8
  32. EFUND = 9
  33. ECONV = 10
  34. ESTACK = 16
  35. EHEAP = 17
  36. EILLINS = 18
  37. EODDZ = 19
  38. ECASE = 20
  39. EMEMFLT = 21
  40. EBADPTR = 22
  41. EBADPC = 23
  42. EBADLAE = 24
  43. EBADMON = 25
  44. EBADLIN = 26
  45. EBADGTO = 27
  46. EUNIMPL = 63 ! unimplemented em-instruction called
  47. earray: lxi h,EARRAY
  48. push h
  49. call .trp
  50. ret
  51. erange: lxi h,ERANGE
  52. push h
  53. call .trp
  54. ret
  55. eset: lxi h,ESET
  56. push h
  57. call .trp
  58. ret
  59. eiovfl: lxi h,EIOVFL
  60. push h
  61. call .trp
  62. ret
  63. efovfl: lxi h,EFOVFL
  64. push h
  65. call .trp
  66. ret
  67. efunfl: lxi h,EFUNFL
  68. push h
  69. call .trp
  70. ret
  71. eidivz: lxi h,EIDIVZ
  72. push h
  73. call .trp
  74. ret
  75. efdivz: lxi h,EFDIVZ
  76. push h
  77. call .trp
  78. ret
  79. eiund: lxi h,EIUND
  80. push h
  81. call .trp
  82. ret
  83. efund: lxi h,EFUND
  84. push h
  85. call .trp
  86. ret
  87. econv: lxi h,ECONV
  88. push h
  89. call .trp
  90. ret
  91. estack: lxi h,ESTACK
  92. push h
  93. call .trp
  94. ret
  95. eheap: lxi h,EHEAP
  96. push h
  97. call .trp
  98. ret
  99. eillins:lxi h,EILLINS
  100. push h
  101. call .trp
  102. ret
  103. eoddz: lxi h,EODDZ
  104. push h
  105. call .trp
  106. ret
  107. ecase: lxi h,ECASE
  108. push h
  109. call .trp
  110. ret
  111. ememflt:lxi h,EMEMFLT
  112. push h
  113. call .trp
  114. ret
  115. ebadptr:lxi h,EBADPTR
  116. push h
  117. call .trp
  118. ret
  119. ebadpc: lxi h,EBADPC
  120. push h
  121. call .trp
  122. ret
  123. ebadlae:lxi h,EBADLAE
  124. push h
  125. call .trp
  126. ret
  127. ebadmon:lxi h,EBADMON
  128. push h
  129. call .trp
  130. ret
  131. ebadlin:lxi h,EBADLIN
  132. push h
  133. call .trp
  134. ret
  135. ebadgto:lxi h,EBADGTO
  136. push h
  137. call .trp
  138. ret
  139. eunimpl:lxi h,EUNIMPL
  140. push h
  141. call .trp
  142. ret
  143. .trp:
  144. pop h
  145. xthl
  146. push h ! trap number and return address exchanged
  147. mov a,l
  148. cpi 16
  149. jnc 3f ! jump if trap cannot be ignored
  150. ! check if trap has to be ignored
  151. xchg ! de = trap number
  152. lhld .ignmask
  153. push h ! hl = set to be tested
  154. push d
  155. call .inn2 ! de = 1 if bit is set, 0 otherwise
  156. mov a,e
  157. rar
  158. jnc 3f ! jump if trap should not be ignored
  159. pop h ! remove trap number
  160. ret ! OGEN DICHT EN ... SPRING!!!
  161. 3:
  162. lhld .trapproc ! user defined trap handler?
  163. mov a,l
  164. ora h
  165. jz 1f ! jump if there was not
  166. xra a
  167. sta .trapproc ! .trapproc := 0
  168. sta .trapproc+1
  169. lxi d,2f
  170. push d
  171. pchl ! call user defined trap handler
  172. 2:
  173. pop d
  174. ret
  175. 1:
  176. lxi h, 1
  177. push h
  178. lxi h, text
  179. push h
  180. lxi h, 6
  181. push h
  182. call _write
  183. jmp EXIT
  184. .sect .rom
  185. text: .ascii "TRAP!\n"