home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / rsyssrc.lha / RSysTrap.asm < prev    next >
Assembly Source File  |  1993-07-18  |  2KB  |  81 lines

  1.  
  2.           far       code
  3.  
  4.           public   _geta4
  5.           public   __trapexception
  6.         public   __initfpu
  7.  
  8.         xref     __oldtrap
  9.         xref     __traphandler
  10.  
  11. DEFTRAP MACRO                                ;&signalnumber
  12.           cmp.w      \1,d0                  ;compare trap number
  13.           beq       _deftrap                ;branch to default traphandler
  14.           ENDM
  15.  
  16. MYTRAP  MACRO                                ;&signalnumber
  17.           cmp.w      \1,d0                  ;compare trap number
  18.           beq       _mytrap                ;branch to own traphandler
  19.           ENDM
  20.  
  21. __trapexception:
  22.           movem.l  d0/a4,-(sp)            ;need some registers
  23.           jsr       _geta4                 ;set up a4
  24.           move.l   8(sp),d0                ;get trap number
  25.           DEFTRAP  #1                        ;define the traphandler
  26.           DEFTRAP  #2
  27.           DEFTRAP  #3
  28.           MYTRAP   #4
  29.           MYTRAP   #5
  30.           MYTRAP   #6
  31.           DEFTRAP  #7
  32.           MYTRAP   #8
  33.           MYTRAP   #9
  34.           DEFTRAP  #10
  35.           DEFTRAP  #11
  36.           MYTRAP   #12
  37.           DEFTRAP  #13
  38.           DEFTRAP  #14
  39.           DEFTRAP  #15
  40.           MYTRAP   #16
  41.  
  42. _deftrap:
  43.           move.l   4(sp),d0                ;get a4 for later
  44.           move.l   __oldtrap,4(sp)     ;get regular handler
  45.           move.l   d0,a4                    ;set real a4 value
  46.           move.l   (sp)+,d0                ;restore d0 contents
  47.           rte                                 ;jump to it
  48.  
  49. _mytrap:
  50.           move.l   a0,-(sp)                ;save a0
  51.           move.l   usp,a0                 ;get user stack pointer
  52.           move.l   18(sp),-(a0)         ;save old pc
  53.           move.w   14(sp),-(a0)         ;save old sr
  54.           movem.l  d0-d7/a0-a6,-(a0)    ;save old registers
  55.           movem.l  (sp)+,d1/d2/d3        ;restore d0/a0/a4
  56.           move.l   d1,(a0)                ;set d0
  57.           move.l   d2,32(a0)             ;set a0
  58.           move.l   d3,48(a0)             ;set a4
  59.           move.l   d0,-(a0)                ;pass trap number on stack
  60.           lea       _conttrap,a1         ;get return in case they want to continue
  61.           move.l   a1,-(a0)                ;set return address
  62.           move.l   a0,usp                 ;set new user stack pointer
  63.           lea       __traphandler,a0    ;get trap handler
  64.           move.l   a0,6(sp)                ;modify rte address
  65.           addq      #4,sp                    ;remove trap #
  66.           rte                                 ;go and do the handler
  67.  
  68. _conttrap:
  69.           add.w      #4,sp                    ;pop arg
  70.           movem.l  (sp)+,d0-d7/a0-a6    ;restore old registers
  71.           move.w   (sp)+,ccr             ;restore old condition codes
  72.           rts                                 ;and continue where we left off
  73.  
  74. __initfpu:
  75.           mc68881
  76.  
  77.           fmove.l  FPCR,d0
  78.           or.w      #$1400,d0
  79.           fmove.l  d0,FPCR
  80.         rts
  81.