home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d02xx / d0230.lha / PrivHndlr / PrivHndlr.asm < prev    next >
Assembly Source File  |  1989-07-22  |  12KB  |  291 lines

  1. ****     A Privilige Violation handler for the 68010 CPU               ****
  2. ****     To use for traping those MOVE SR,ea instructions I went to use ***
  3. ****     Decigel but found it would not survive a reboot. I needed this ***
  4. ****     for those copy protected programs that run from boot. The idea ***
  5. ****     for the Violation code is from Scott Turner's Decigel program. I *
  6. ****     added the code that will allow it to survive a warm boot.     ****
  7. ****     To remove the handler press the left mouse button while       ****
  8. ****     rebooting. The screen will flash red to let you know the code ****
  9. ****     has gone. It allocates a port so that if you try to install   ****
  10. ****     it again it will tell you it is already there.                ****
  11. ****     The other way to get rid of it is to type Decigel -q          ****
  12. ****     I am placing this into the public domain for use by anyone    ****
  13. ****     John Veldthuis
  14. ****     21 Ngatai Street
  15. ****     Manaia, Taranaki
  16. ****     New Zealand
  17.  
  18. ****     Revision 1  3 April 1988
  19. ****     Added code to remove handler from Cli
  20.  
  21. ****     Revision 2  20 September 1988
  22. ****     Changed from using the CoolCapture Vector to using RomTAGS
  23. ****     This is the proper way to survive a reboot.
  24. ****     Took awhile to work out how to use them though
  25. ****     Will work with other RomTAGS
  26.  
  27. ****     Revision 3 23 September 1988
  28. ****     Changed memory allocation tactics when I found my program
  29. ****     got wiped out by an ADDMEM C00000 CFFFFF command
  30.  
  31.  
  32.  
  33. _LVOOpenLibrary   EQU   -$228
  34. _LVOCloseLibrary  EQU   -$19E
  35. _LVOFindPort      EQU   -$186
  36. _LVOAddPort       EQU   -$162
  37. _LVORemovePort    EQU   -$168
  38. _LVOSumKickData   EQU   -$264
  39. _LVOAllocMem      EQU   -$C6
  40. _LVOAllocAbs      EQU   -$CC
  41. _LVOFreeMem       EQU   -$D2
  42. _LVOOutput        EQU   -$3C
  43. _LVOWrite         EQU   -$30
  44.  
  45. Start:
  46.          movem.l  d0/a0,-(sp)
  47.          move.l   4,a6
  48.          lea      DosName(pc),a1
  49.          moveq.l  #0,d0
  50.          jsr      _LVOOpenLibrary(a6)         ;open dos library
  51.          tst.l    d0
  52.          bne.s    1$
  53.          moveq.l  #20,d0            ;error if no Dos
  54.          rts
  55. 1$       lea      DosBase(pc),a5
  56.          move.l   d0,(a5)
  57.          move.l   d0,a6
  58.          jsr      _LVOOutput(a6)
  59.          move.l   d0,4(a5)
  60.          movem.l  (sp)+,d0/a0       ;restore command line
  61.          move.b   #0,0(a0,d0.w)   ;zero end of line
  62.          move.l   4,a6
  63. Loop     move.b   (a0)+,d0
  64.          tst.b    d0
  65.          beq      NoQuit            ;if no command install handler
  66.          cmp.b    #'-',d0
  67.          bne.s    Loop              ;look for -q
  68.          move.b   (a0),d0           ;should now be a 'q'
  69.          cmp.b    #'q',d0
  70.          bne.s    Loop
  71.          lea      PortName(pc),a1
  72.          jsr      _LVOFindPort(a6)
  73.          tst.l    d0
  74.          bne.s    PortHere
  75.          lea      NoHandler(pc),a1
  76.          move.l   a1,d2
  77.          move.l   4(a5),d1
  78.          move.l   #23,d3
  79.          move.l   (a5),a6
  80.          bra      Q1
  81. PortHere move.l   d0,a4             ;a4 = pointer to port
  82.          move.l   -4(a4),d0         ;d0 = old exception handler
  83.          lea      $20,a0
  84.          move.l   d0,(a0)           ;put back old exception handler
  85.          move.l   a4,a1
  86.          jsr      _LVORemovePort(a6) ;remove port
  87.          move.w   #$4000,$DFF09A     ;disable interupts
  88.          addq.b   #1,$126(a6)        ;1 to disable count
  89.          move.l   $2A(a4),$226(a6)   ;retsore old pointer
  90.          beq.s    1$                 ;was there a pointer
  91.          bclr     #7,$226(a6)        ;yes, restore extension bit
  92. 1$       jsr      _LVOSumKickData(a6)
  93.          move.l   d0,$22A(a6)        ;restore new checksum
  94.          subq.b   #1,$126(a6)        ;one off disable count
  95.          bge.s    2$
  96.          move.w   #-$4000,$DFF09A   ;restore interupts
  97. 2$       lea      -(Port1-Install)(a4),a1 ;Start of memory
  98.          move.l   #EndProg-StartProg,d0   ;length of Memory
  99.          jsr      _LVOFreeMem(a6)         ;free the memory
  100.          lea      Remove(pc),a0
  101.          move.l   a0,d2
  102.          move.l   4(a5),d1
  103.          move.l   #17,d3
  104.          move.l   (a5),a6
  105.          bra.s    Q1
  106. NoQuit   move.l   4,a6
  107.          lea      PortName(pc),a1
  108.          jsr      _LVOFindPort(a6)         ;find port
  109.          tst.l    d0
  110.          beq.s    10$               ;if no port then go install handler
  111.          move.l   (a5),a6        ;otherwise print that handler installed
  112.          move.l   4(a5),d1
  113.          lea      Mess3(pc),a0
  114.          move.l   a0,d2
  115.          move.l   #27,d3
  116.          bra.s    Q1
  117.  
  118. 10$      move.l   #EndProg-StartProg,d0   ;length of memory we need
  119.          move.l   #$10003,d1              ;put it in Chip Memory + Clear Mem
  120.          jsr      _LVOAllocMem(a6)
  121.          tst.l    d0
  122.          beq.s    MemErr
  123.          bsr      MoveProg         ;move prog up into memory above normal
  124.          move.l   (a5),a6
  125.          lea      Mess2(pc),a0
  126.          move.l   a0,d2
  127.          move.l   4(a5),d1
  128.          move.l   #29,d3
  129. Q1       jsr      _LVOWrite(a6)    ;print installed message
  130. Quit     move.l   a6,a1
  131.          move.l   4,a6
  132.          jsr      _LVOCloseLibrary(a6)      ;close dos.library
  133.          moveq.l  #0,d0
  134.          rts
  135. MemErr   move.l   (a5),a6
  136.          lea      MemMess(pc),a0
  137.          move.l   a0,d2
  138.          move.l   4(a5),d1
  139.          move.l   #30,d3
  140.          bra.s    Q1                ;print Message and exit
  141.  
  142.  
  143. MoveProg:
  144.          move.l   d0,a1               ;d0 holds our memory Allocation
  145.          move.l   d0,a3
  146.          lea      StartProg(pc),a0
  147.          lea      EndProg(pc),a2
  148. 1$       move.b   (a0)+,(a1)+         ;move memory up
  149.          cmp.l    a0,a2
  150.          bne.s    1$
  151.          jmp      (a3)                 ;jump to install routine
  152.  
  153. StartProg:
  154. Install  bsr.s    Sub1
  155.          bsr      Sub2
  156.          rts
  157. Sub1     move.w   #$4000,$DFF09A       ;Interupts off
  158.          addq.b   #1,$126(a6)          ;add one to disable count
  159.          lea      Block(pc),a0
  160.          lea      8(a0),a1
  161.          move.l   a1,(a0)              ;pointer to our RomTAG
  162.          move.l   $226(a6),4(a0)       ;get old KickTagPtr
  163.          beq.s    1$                   ;Nothing there 
  164.          bset     #7,4(a0)             ;otherwise set bit to tell exec
  165. 1$       move.l   a0,$226(a6)          ;put our KickTagPtr in
  166.          move.w   #$4AFC,(a1)          ;magic number
  167.          move.l   a1,2(a1)             ;pointer to base of RomTAG
  168.          lea      $1a(a1),a2
  169.          move.l   a2,6(a1)             ;End of RomTAG
  170.          move.b   #1,$a(a1)            ;Flags (run program on reboot)
  171.          move.b   #$21,$b(a1)          ;version of the program
  172.          move.b   #0,$c(a1)            ;Type of module
  173.          move.b   #-$a,$d(a1)          ;pri of this program
  174.          move.l   #0,$e(a1)            ;pointer to node name
  175.          move.l   #0,$12(a1)           ;pointer to ID string
  176.          lea      Init(pc),a3
  177.          move.l   a3,$16(a1)           ;pointer to Init code (called at boot)
  178.          jsr      _LVOSumKickData(a6)  ;redo checksum
  179.          move.l   d0,$22a(a6)          ;put it into ExecBase
  180.          subq.b   #1,$126(a6)          ;one off disable count
  181.          bge.s    2$                   ;are we still disabled
  182.          move.w   #-$4000,$DFF09A      ;enable interupts
  183. 2$       rts
  184. Sub2:
  185.          lea      Port1(pc),a0         ;Message port address
  186.          moveq.l  #0,d0
  187.          move.l   d0,(a0)              ;zero successor
  188.          move.l   d0,4(a0)             ;zero predisessor
  189.          move.w   #$0400,8(a0)         ;type = messageport, pri = 0
  190.          move.w   d0,14(a0)            ;zero list header
  191.          move.l   d0,16(a0)            ;zero list tail
  192.          lea      PortName(pc),a1      ;name of this port
  193.          move.l   a1,10(a0)            ;put it in structure
  194.          lea      Port1(pc),a1         ;get port address
  195.          jsr      _LVOAddPort(a6)   ;addport to let every know we are here
  196.          lea      OpCode+2(pc),a0      ;get end of our patch code
  197.          lea      $20,a1               ;get address of priv violation
  198.          move.l   (a1),(A0)            ; Patch old vector into our handler
  199.          lea      PivVi(pc),a2
  200.          move.l   A2,(a1)              ; Patch us into the vector
  201.          rts                           ; Back to AmigaDOS, no error
  202.  
  203. Init     movem.l  d0-d7/a0-a6,-(sp) ;RomTag calls Here
  204.          move.l   4,a6
  205.          btst     #6,$BFE001        ;Test left mouse button
  206.          bne.s    2$
  207. 11$      lea      $DFF000,a5        ;custom chip base
  208.          move.w   #$F00,$180(a5)    ;move red into color 0
  209.          moveq    #$64,d0           ;delay loop
  210. 4$       cmpi.b   #0,6(a5)          ;flash screen to indicate
  211.          bne.s    4$                ;handler removed
  212. 5$       cmpi.b   #0,6(a5)
  213.          bne.s    5$
  214.          dbf      d0,4$             ;delay for a bit
  215.          move.w   #$00D,$180(a5)    ;put screen back to blue
  216.          move.w   #$4000,$9A(a5)    ;disable interupts
  217.          addq.b   #1,$126(a6)       ;1 to disable count
  218.          lea      Tag2(pc),a0       ;get old TagPtr
  219.          move.l   (a0),$226(a6)     ;restore pointer
  220.          beq.s    10$
  221.          bclr     #7,$226(a6)       ;reset continuation bit
  222. 10$      jsr      _LVOSumKickData(a6)
  223.          move.l   d0,$22A(a6)       ;put new checksum in
  224.          subq.b   #1,$126(a6)       ;1 from disable count
  225.          bge.s    6$
  226.          move.w   #-$4000,$9A(a5)   ;enable interupts
  227.          bra.s    6$                ;return to kickstart routine
  228. 2$       lea      Install(pc),a1    ;start of our program
  229.          move.l   #EndProg-StartProg,d0   ;number of byte to allocate
  230.          jsr      _LVOAllocAbs(a6)        ;alloc memory
  231.          tst.l    d0
  232.          beq.s    11$               ;dont install it if no memory
  233.          bsr      Sub2              ;addport and reset pointer to routine
  234. 6$       movem.l  (sp)+,d0-d7/a0-a6 ;restore regs for kickstart
  235.          rts
  236.  
  237. PivVi    movem.l  D0/A0,-(SP)       ; Save registers
  238.          move.l   8+2(SP),A0        ; Pointer to opcode
  239.          move.w   (A0),D0           ; Pickup opcode
  240.          andi.w   #~%111111,D0      ; Mask out EA field
  241.          cmpi.w   #$40C0,D0         ; Is it a MOVE SR,ea?
  242.          bne.s    NotOne
  243.          bset     #1,(A0)           ; Convert it to MOVE CCR,ea
  244.          movem.l  (SP)+,D0/A0       ; Restore regs
  245.          rte                        ; Rerun new opcode
  246.  
  247. NotOne   movem.l  (SP)+,D0/A0       ; Restore regs
  248. OpCode   jmp      $FC0000   ; To previous handler, patched by our install
  249.  
  250. Port1    dc.l     0              ;This is a message port structure
  251.          dc.l     0
  252.          dc.b     4              ;port type
  253.          dc.b     0
  254.          dc.l     0              ;port name
  255.          dc.b     0
  256.          dc.b     0
  257.          dc.l     0
  258.          ds.b     14
  259.          dc.l     0
  260. Block    dc.l     0              ;This is storage for the RomTag
  261. Tag2     dc.l     0
  262.          dc.l     0
  263.          dc.l     0
  264.          dc.l     0
  265.          dc.l     0
  266.          dc.l     0
  267.          dc.l     0
  268.          dc.l     0
  269.          dc.l     0
  270.          dc.l     0
  271.          dc.l     0
  272.          dc.l     0
  273.  
  274. DosBase  dc.l  0
  275. StdOut   dc.l  0
  276. DosName  dc.b  'dos.library',0
  277. Mess2    dc.b  'Privilige Handler Installed',10,0
  278. Mess3    dc.b  'Handler already Installed',10,0
  279. NoHandler dc.b 'Handler not Installed',10,0
  280. MemMess  dc.b  'Not Enough memory for Handler',10,0
  281. Remove   dc.b  'Handler Removed',10,0
  282. PortName dc.b  'PrivHandler',0
  283. NAME     dc.b  'John Veldthuis',0
  284.          dc.b  '21 Nagtai Steet',0
  285.          dc.b  'Manaia, Taranaki',0
  286.          dc.b  'New Zealand',0
  287. EndProg:
  288.  
  289.       end
  290.  
  291.