home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Src / programs / FindAccess.asm < prev    next >
Assembly Source File  |  1999-01-17  |  8KB  |  420 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    FindAccess.asm
  3. ;  :Contents.    Search for access to a given address
  4. ;  :Author.    Bert Jahn
  5. ;  :EMail.    wepl@kagi.com
  6. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  7. ;  :Version.    $Id: FindAccess.asm 1.2 1999/01/17 14:18:12 jah Exp jah $
  8. ;  :History.    08.02.96
  9. ;        31.03.97 bug removed, scanning out of range
  10. ;        17.01.99 recompile because error.i changed
  11. ;  :Requires.    OS V37+
  12. ;  :Copyright.    Public Domain
  13. ;  :Language.    68000 Assembler
  14. ;  :Translator.    Barfly V1.131
  15. ;---------------------------------------------------------------------------*
  16. ;##########################################################################
  17.  
  18.     INCDIR    Includes:
  19.     INCLUDE    lvo/exec.i
  20.     INCLUDE    exec/execbase.i
  21.     INCLUDE    exec/memory.i
  22.     INCLUDE    lvo/dos.i
  23.     INCLUDE    dos/dos.i
  24.  
  25.     INCLUDE    macros/ntypes.i
  26.  
  27. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  28.  
  29. GL    EQUR    A4        ;a4 ptr to Globals
  30. LOC    EQUR    A5        ;a5 for local vars
  31.  
  32.     STRUCTURE    ReadArgsArray,0
  33.         ULONG    rda_input
  34.         ULONG    rda_adr
  35.         ULONG    rda_org
  36.         LABEL    rda_SIZEOF
  37.  
  38.     NSTRUCTURE    Globals,0
  39.         NAPTR    gl_execbase
  40.         NAPTR    gl_dosbase
  41.         NAPTR    gl_rdargs
  42.         NSTRUCT    gl_rdarray,rda_SIZEOF
  43.         NALIGNLONG
  44.         NLABEL    gl_SIZEOF
  45.  
  46. ;##########################################################################
  47.  
  48.     PURE
  49.     SECTION    "",CODE
  50.     OUTPUT    C:FindAccess
  51.  
  52.  
  53. VER    MACRO
  54.         dc.b    "FindAccess 1.2 "
  55.     DOSCMD    "WDate >t:date"
  56.     INCBIN    "t:date"
  57.         dc.b    " by Bert Jahn"
  58.     ENDM
  59.  
  60.         bra    .start
  61.         dc.b    "$VER: "
  62.         VER
  63.         dc.b    " V37+"
  64.     CNOP 0,2
  65. .start
  66.  
  67. ;##########################################################################
  68.  
  69.         link    GL,#gl_SIZEOF        ;GL = PubMem
  70.         move.l    (4),(gl_execbase,GL)
  71.         clr.l    (rda_org+gl_rdarray,GL)
  72.  
  73.         move.l    #37,d0
  74.         lea    (_dosname),a1
  75.         move.l    (gl_execbase,GL),a6
  76.         jsr    _LVOOpenLibrary(a6)
  77.         move.l    d0,(gl_dosbase,GL)
  78.         beq    .nodoslib
  79.  
  80.         lea    (_ver),a0
  81.         bsr    _Print
  82.  
  83.         lea    (_template),a0
  84.         move.l    a0,d1
  85.         lea    (gl_rdarray,GL),a0
  86.         move.l    a0,d2
  87.         moveq    #0,d3
  88.         move.l    (gl_dosbase,GL),a6
  89.         jsr    (_LVOReadArgs,a6)
  90.         move.l    d0,(gl_rdargs,GL)
  91.         bne    .argsok
  92.         lea    (_readargs),a0
  93.         bsr    _PrintErrorDOS
  94.         bra    .noargs
  95. .argsok
  96.         move.l    (gl_rdarray+rda_adr,GL),a0
  97.         bsr    _etoi
  98.         tst.b    (a0)
  99.         bne    .a_badnum
  100.         move.l    d0,(gl_rdarray+rda_adr,GL)
  101.  
  102.         move.l    (gl_rdarray+rda_org,GL),d0
  103.         beq    .a_ok
  104.         move.l    d0,a0
  105.         bsr    _etoi
  106.         tst.b    (a0)
  107.         bne    .a_badnum
  108.         move.l    d0,(gl_rdarray+rda_org,GL)
  109.         bra    .a_ok
  110.  
  111. .a_badnum    moveq    #ERROR_BAD_NUMBER,d1
  112.         moveq    #0,d2
  113.         move.l    (gl_dosbase,GL),a6
  114.         jsr    (_LVOPrintFault,a6)
  115.         bra    .opend
  116. .a_ok
  117.         bsr    _Main
  118. .opend
  119.         move.l    (gl_rdargs,GL),d1
  120.         move.l    (gl_dosbase,GL),a6
  121.         jsr    (_LVOFreeArgs,a6)
  122. .noargs
  123.         move.l    (gl_dosbase,GL),a1
  124.         move.l    (gl_execbase,GL),a6
  125.         jsr    (_LVOCloseLibrary,a6)
  126. .nodoslib
  127.         unlk    GL
  128.         moveq    #0,d0
  129.         rts
  130.  
  131. ;##########################################################################
  132.  
  133.     NSTRUCTURE    LocalMain,0
  134.         NALIGNLONG
  135.         NLABEL    lm_SIZEOF
  136.  
  137. _Main        link    LOC,#lm_SIZEOF
  138.         move.l    (gl_rdarray+rda_input,GL),a0
  139.         bsr    _LoadFileMsg
  140.         move.l    d0,D6            ;D6 = src ptr
  141.         beq    .end
  142.         move.l    d1,d7            ;D7 = src size
  143.         
  144.         lea    (_msg),a0
  145.         move.l    (gl_rdarray+rda_org,GL),-(a7)
  146.         add.l    d7,(a7)
  147.         move.l    (gl_rdarray+rda_org,GL),-(a7)
  148.         move.l    (gl_rdarray+rda_adr,GL),-(a7)
  149.         move.l    (a7),-(a7)
  150.         move.l    a7,a1
  151.         bsr    _PrintArgs
  152.         add.w    #16,a7
  153.         
  154.         move.l    d6,d5        ;scan point
  155.         
  156. .loop        bsr    _CheckBreak
  157.         tst.l    d0
  158.         bne    .free
  159.         move.l    (gl_rdarray+rda_adr,GL),d0
  160.         move.l    d5,d1
  161.         sub.l    d6,d1
  162.         add.l    (gl_rdarray+rda_org,GL),d1    ;offset
  163.         move.l    d5,a0        ;buffer
  164.         move.l    d6,a1
  165.         add.l    d7,a1        ;end
  166.         sub.l    a2,a2        ;registers
  167.         bsr    _FindAccess
  168.         move.l    d1,d4            ;D4 = at address found
  169.         move.l    d1,d5
  170.         cmp.w    #FA_nothing,d0
  171.         beq    .free
  172.         cmp.w    #FA_AbsL,d0
  173.         beq    .AbsL
  174.         cmp.w    #FA_AbsW,d0
  175.         beq    .AbsW
  176.         cmp.w    #FA_RelL,d0
  177.         beq    .RelL
  178.         cmp.w    #FA_RelW,d0
  179.         beq    .RelW
  180.         cmp.w    #FA_RelB,d0
  181.         beq    .RelB
  182.         bra    .free
  183.  
  184. .AbsL        lea    (_Abs),a0
  185.         lea    (_foundL),a2
  186.         addq.l    #4,d5
  187.         bra    .all
  188. .AbsW        lea    (_Abs),a0
  189.         lea    (_foundW),a2
  190.         addq.l    #2,d5
  191.         bra    .all
  192. .RelL        lea    (_Rel),a0
  193.         lea    (_foundL),a2
  194.         addq.l    #4,d5
  195.         bra    .all
  196. .RelW        lea    (_Rel),a0
  197.         lea    (_foundW),a2
  198.         addq.l    #2,d5
  199.         bra    .all
  200. .RelB        lea    (_Rel),a0
  201.         lea    (_foundB),a2
  202.         addq.l    #2,d5
  203.  
  204. .all        bsr    _Print
  205.         move.l    a2,a0
  206.         move.l    d4,a1
  207.         add.w    #12,a1
  208.         move.l    -(a1),-(a7)
  209.         move.l    -(a1),-(a7)
  210.         move.w    -(a1),-(a7)
  211.         moveq    #0,d0
  212.         move.b    -(a1),d0
  213.         move.w    d0,-(a7)
  214.         move.b    -(a1),d0
  215.         move.w    d0,-(a7)
  216.         move.l    -(a1),-(a7)
  217.         move.l    -(a1),-(a7)
  218.         move.l    d4,-(a7)
  219.         sub.l    d6,(a7)
  220.         move.l    a7,a1
  221.         bsr    _PrintArgs
  222.         add.w    #6*4+2,a7
  223.         bra    .loop
  224. .free
  225.         move.l    d6,a1
  226.         move.l    (gl_execbase,GL),a6
  227.         jsr    (_LVOFreeVec,a6)
  228. .end
  229.         unlk    LOC
  230.         rts
  231.  
  232. ;----------------------------------------
  233. ; IN:    D0 = LONG address to search
  234. ;    D1 = LONG address on which the buffer was relocted original
  235. ;            (offset from buffer start to real address "zero")
  236. ;    A0 = APTR buffer start
  237. ;    A1 = APTR buffer end
  238. ;    A2 = STRUCT array of LONG's = registers D0-A7 (or NIL)
  239. ; OUT:    D0 = LONG result
  240. ;    D1 = LONG address of access
  241.  
  242. FA_nothing    = 0
  243. FA_AbsL        = 1
  244. FA_AbsW        = 2
  245. FA_RelB        = 3
  246. FA_RelW        = 4
  247. FA_RelL        = 5
  248.  
  249. _FindAccess    movem.l    d2-d7,-(a7)
  250.     ;make a0 even (up round)
  251.         move.l    a0,d2
  252.         addq.l    #1,d2
  253.         and.b    #$fe,d2
  254.         move.l    d2,a0
  255.     ;make a1 even (down round)
  256.         move.l    a1,d2
  257.         and.b    #$fe,d2
  258.         move.l    d2,a1
  259.     ;check for buffer >= 4 bytes
  260.         move.l    a1,d2
  261.         sub.l    a0,d2
  262.         bcs    .nothing
  263.         cmp.l    #4,d2
  264.         blo    .nothing
  265.  
  266.     ;check for "AbsW" possible
  267.         moveq    #%110,d7    ;D7 = status
  268.         cmp.l    #$7fff,d0
  269.         bgt    .abswno
  270.         cmp.l    #-$8000,d0
  271.         blt    .abswno
  272.         bset    #0,d7        ;D7.0 = AbsW possible
  273. .abswno
  274.         neg.l    d1
  275.         add.l    d0,d1        ;D1 = distance to searched address relative to contens d2
  276.         move.l    d1,d3
  277.         addq.l    #4,d1        ;D1 = distance + 4
  278.         addq.l    #2,d3        ;D3 = distance + 2
  279.  
  280.         move.w    (a0)+,d2
  281.         subq.l    #2,d1
  282.         subq.l    #2,d3
  283.     ;here all checks for WORD+BYTE for first word only
  284.     ;absolut word
  285. .1AbsW        btst    #0,d7
  286.         beq    .1relW
  287.         cmp.w    d0,d2
  288.         bne    .1relW
  289.         moveq    #FA_AbsW,d0
  290.         move.l    a0,d1
  291.         subq.l    #2,d1
  292.         bra    .end
  293.     ;relative word
  294. .1relW        cmp.l    #-$8000,d3
  295.         blt    .1relend
  296.         cmp.l    #$7fff,d3
  297.         bgt    .1relend
  298.         cmp.w    d3,d2
  299.         bne    .1relB
  300.         moveq    #FA_RelW,d0
  301.         move.l    a0,d1
  302.         subq.l    #2,d1
  303.         bra    .end
  304.     ;relative byte
  305. .1relB        cmp.w    #-$80,d3
  306.         blt    .1relend
  307.         cmp.w    #$7f,d3
  308.         bgt    .1relend
  309.         cmp.b    d3,d2
  310.         bne    .1relend
  311.         moveq    #FA_RelB,d0
  312.         move.l    a0,d1
  313.         subq.l    #2,d1
  314.         bra    .end
  315. .1relend
  316.         bra    .next        ;perhaps buffer = 2 byte !
  317.         
  318. .loop        swap    d2
  319.         move.w    (a0)+,d2
  320.         subq.l    #2,d1
  321.         subq.l    #2,d3
  322.     ;absolut long
  323. .AbsL        cmp.l    d0,d2
  324.         bne    .AbsW
  325.         moveq    #FA_AbsL,d0
  326.         move.l    a0,d1
  327.         subq.l    #4,d1
  328.         bra    .end
  329.     ;absolut word
  330. .AbsW        btst    #0,d7
  331.         beq    .relL
  332.         cmp.w    d0,d2
  333.         bne    .relL
  334.         moveq    #FA_AbsW,d0
  335.         move.l    a0,d1
  336.         subq.l    #2,d1
  337.         bra    .end
  338.     ;relative long
  339. .relL        cmp.l    d1,d2
  340.         bne    .relW
  341.         moveq    #FA_RelL,d0
  342.         move.l    a0,d1
  343.         subq.l    #4,d1
  344.         bra    .end
  345.     ;relative word
  346. .relW        btst    #1,d7        ;D7.1 = RelW possible
  347.         beq    .relend
  348.         cmp.l    #-$8000,d3
  349.         bge    .relW_1
  350.         bclr    #1,d7
  351.         bra    .relend
  352. .relW_1        cmp.l    #$7fff,d3
  353.         bgt    .relend
  354.         cmp.w    d3,d2
  355.         bne    .relB
  356.         moveq    #FA_RelW,d0
  357.         move.l    a0,d1
  358.         subq.l    #2,d1
  359.         bra    .end
  360.     ;relative byte
  361. .relB        btst    #2,d7        ;D7.2 = RelB possible
  362.         beq    .relend
  363.         cmp.w    #-$80,d3
  364.         bge    .relB_1
  365.         bclr    #2,d7
  366.         bra    .relend
  367. .relB_1        cmp.w    #$7f,d3
  368.         bgt    .relend
  369.         cmp.b    d3,d2
  370.         bne    .relend
  371.         moveq    #FA_RelB,d0
  372.         move.l    a0,d1
  373.         subq.l    #2,d1
  374.         bra    .end
  375. .relend
  376.  
  377. .next        cmp.l    a0,a1
  378.         bhi    .loop
  379.  
  380. .nothing    moveq    #FA_nothing,d0
  381.  
  382. .end        movem.l    (a7)+,d2-d7
  383.         rts
  384.  
  385. ;##########################################################################
  386.  
  387.     INCDIR    Sources:
  388.     INCLUDE    dosio.i
  389.         CheckBreak
  390.     INCLUDE    error.i
  391.         PrintErrorDOS
  392.     INCLUDE    files.i
  393.         LoadFileMsg
  394.     INCLUDE    strings.i
  395.         etoi
  396.  
  397. ;##########################################################################
  398.  
  399. _Abs        dc.b    "Absolut  ",0
  400. _Rel        dc.b    "Relative ",0
  401. _foundL        dc.b    " Long at $%6lx -> %08lx %08lx ",155,"1m%02x%02x%04x",155,"22m %08lx %08lx",10,0
  402. _foundW        dc.b    " Word at $%6lx -> %08lx %08lx ",155,"1m%02x%02x",155,"22m %08lx %08lx",10,0
  403. _foundB        dc.b    " Byte at $%6lx -> %08lx %08lx %02x",155,"1m%02x",155,"22m %08lx %08lx",10,0
  404.  
  405. _msg        dc.b    "scanning accesses to $%lx (%ld)  file: $%lx-$%lx",10,0
  406. _readargs    dc.b    "read arguments",0
  407. _dosname    dc.b    "dos.library",0
  408. _template    dc.b    "FILE/A"        ;name eines zu ladenden Files
  409.         dc.b    ",ADDRESS/A"        ;to search
  410.         dc.b    ",ORG"            ;orginal address of file (def = 0)
  411.         dc.b    0
  412.  
  413. _ver        VER
  414.         dc.b    10,0
  415.  
  416. ;##########################################################################
  417.  
  418.     END
  419.  
  420.