home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / bss / pup.arc / ABORT.ASM next >
Assembly Source File  |  1984-11-06  |  2KB  |  113 lines

  1. title Program Abort Functions
  2. name abort
  3. include model.ash
  4. include lattice.ash
  5. ;
  6. ;Multi-level program error return functions.
  7. ;
  8. ;set_abor()
  9. ;
  10. ;Set to return to after set_abort() if a
  11. ;function calls frc_abort(). This assumes
  12. ;that the first thing after set_abort() is
  13. ;was_abort(), like so:
  14. ;
  15. ;    set_abort(0);
  16. ;    if(was_abort()) {
  17. ;        do whatever ...
  18. ;    }
  19. ;    function();
  20. ;
  21. ;Where function() is presumably the actual
  22. ;function that invokes frc_abort, or one of
  23. ;its called functions.
  24. ;
  25. ; The argument to set_abort(arg) is necessary,
  26. ;otherwise Lattice will not put SP into BP
  27. ;(trying to be smart.)
  28. ;
  29. ;frc_abor()
  30. ;
  31. ;Does a jump to the abort address presumably
  32. ;set by set_abor(). 
  33. ;
  34. ;was_abor()
  35. ;
  36. ;Returns true if return from the function was
  37. ;done by the frc_abor function. Once read,
  38. ;it clears itself to zero.
  39. ;
  40. ;NOTE:
  41. ;    These are currently hardcoded for small
  42. ;and large models; 16 bit code addresses only.
  43. ;
  44. ;    Lattice puts SP into BP before calling
  45. ;a function; all we have to do to restore the
  46. ;original stack pointer is to save this BP
  47. ;value and use it later. 
  48. ;
  49. dseg
  50.  
  51. abflag    dw    (?)    ;1 == aborted
  52. rbp    dw    (?)    ;BP save
  53. rds    dw    (?)
  54. res    dw    (?)
  55. addr    dw    0    ;func address
  56.  
  57. endd
  58.  
  59. cseg
  60. ;
  61. ;Set the abort jump address to after func()
  62. ;(Cant use macros FUNC and ENDF since we mush
  63. ;BP etc.)
  64. ;
  65. public set_abor
  66.  
  67. set_abor proc
  68.     mov    dx,bp        ;orig. BP,
  69.     push    bp        ;into DX
  70.     mov    bp,sp
  71.     mov    bx,ds        ;orig. DS
  72.     push    ds        ;into BX
  73.     mov    ax,data
  74.     mov    ds,ax
  75.     mov    ax,[bp+2]    ;get our return
  76.     mov    addr,ax        ;address,
  77.     mov    rbp,dx        ;save BP,
  78.     mov    rds,bx        ;save DS,
  79.     mov    res,es        ;save ES,
  80.     mov    abflag,0    ;no abort
  81.     pop    ds
  82.     pop    bp
  83.     ret
  84. set_abor endp
  85. ;
  86. ;Execute an abort.
  87. ;
  88. public frc_abor
  89. frc_abor proc 
  90.     mov    ax,data
  91.     mov    ds,ax
  92.     push    addr        ;set ret addr
  93.     mov    abflag,1    ;flag abort,
  94.     mov    bp,rbp        ;get old BP,
  95.     mov    es,res        ;DS and ES
  96.     mov    ds,rds
  97.     ret            ;return old BP
  98. frc_abor endp
  99. ;
  100. ;Return true if the error abort was taken.
  101. ;
  102. func was_abor
  103.     mov    ax,data
  104.     mov    ds,ax
  105.     mov    ax,0
  106.     xchg    ax,abflag
  107.  
  108. endf was_abor
  109.  
  110. endc
  111.  
  112.     end
  113.