home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_07 / MARK_WC1.LZH / SRC / SETRTE.S < prev    next >
Text File  |  1988-04-27  |  3KB  |  87 lines

  1. / declare exception routine...
  2. / This routine is called as the first action in a routine that is to
  3. / be called from a 68000 exception -- It saves all of the unsafe registers
  4. / and causes the routine to exit through code that restores the registers
  5. / and exits with an RTE.
  6. /
  7. / Called with no parameters.
  8. /
  9. / Returns the old frame pointer (a6) in d0 so that the calling routine can
  10. / access the supervisor stack.  The offsets into the stack for most
  11. / exceptions are:
  12. /       Low Address     +-------------------------------+
  13. /            0.L    | Old A0 contents (high)    |
  14. /                   +-------------------------------+
  15. /            | Old A0 contents (low)        |
  16. /            +-------------------------------+
  17. /            4.W    | Old status register        |
  18. /            +-------------------------------+
  19. /            6.L    | Exception PC (high)        |
  20. /            +-------------------------------+
  21. /                | Exception PC (low)        |
  22. /            +-------------------------------+
  23. /
  24. / For a Bus or Address Error, the exception frame is as follows:
  25. /
  26. /       Low Address     +-------------------------------+
  27. /            0.L    | Old A0 contents (high)    |
  28. /                   +-------------------------------+
  29. /            | Old A0 contents (low)        |
  30. /            +-------------------------------+
  31. /            4.W    | Exception description *    |
  32. /            6.L    +-------------------------------+
  33. /            | Access Address (high)        |
  34. /            +-------------------------------+
  35. /           10.L    | Access address (low)        |
  36. /            +-------------------------------+
  37. /            | Instruction register        |
  38. /            +-------------------------------+
  39. /           14.W    | Old status register        |
  40. /            +-------------------------------+
  41. /           16.L    | Exception PC (high)        |
  42. /            +-------------------------------+
  43. /                | Exception PC (low)        |
  44. /            +-------------------------------+
  45. / * Bit 4: R/W, Bit 3: Instruction/Other, Bits 0-2: Function code
  46. /
  47. / Recovery from an address error or bus error should not attempt to
  48. / resume processing directly without some patchup...  On these errors,
  49. / the value of the exception PC is within 10 words of the offending
  50. / instruction, but it is not always possible to tell just where.
  51. /
  52.     .prvi
  53.     .globl    setrte_
  54.     .globl    retrte
  55.  
  56. setrte_:
  57.     move.l    a1,-(sp)    / save the munged registers on the stack
  58.     move.l    a0,-(sp)    / ...
  59.     movea.l    a7,a1        / save the current sp
  60.     suba.l    $28,a7        / extend the stack for 6 saved registers+ra
  61.     movea.l    a7,a0        / and get this as well...
  62. 1:
  63.     move    (a1)+,(a0)+    / we are now shifting the stack down 24 words
  64.     cmpa.l    a1,a6        / have we copied the entire frame?
  65.     bgt    1b        / if not, continue looping.
  66.  
  67.     move.l    (a6),(a0)    / copy the final (link) word...
  68.     movea.l    a6,a0        / save the value of the link
  69.     move.l    (sp)+,(a6)    / copy up saved A0
  70.     move.l    (sp)+,-(a6)    / now the saved A1
  71.     move.l    a2,-(a6)    / now save A2
  72.     move.l    d0,-(a6)    / save D0
  73.     move.l    d1,-(a6)    / save D1
  74.     move.l    d2,-(a6)    / save D2
  75.     move.l    $retrte,-(a6)    / put the RTE return address in
  76.     subq    $4,a6        / adjust the link...
  77.     move.l    a6,d0        / put the old link address into d0
  78.     rts            / return to caller...
  79. retrte:
  80.     move.l    (sp)+,d2    / Restore garbaged registers
  81.     move.l    (sp)+,d1    /
  82.     move.l    (sp)+,d0    /
  83.     movea.l    (sp)+,a2    /
  84.     movea.l    (sp)+,a1    /
  85.     movea.l    (sp)+,a0    / Done restoring registers
  86.     rte            / and the whole point of this mess...
  87.