home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / ssl-4.1.lha / SSL / SSLExamp / AddModule.asm < prev    next >
Assembly Source File  |  1993-12-21  |  3KB  |  181 lines

  1. ; Add Resident Module
  2. ; (c) 1993 MJSoft System Software
  3. ; Martin Mares
  4.  
  5. ;DEBUG    set    1
  6.  
  7.     include    "ssmac.h"
  8.  
  9.     rsreset            ; KickMem & KickTag structure
  10. kb_kickmem    rs.b    ML_SIZE
  11. kb_kicktag    rs.l    2
  12. kb_sizeof    rs.b    0
  13.  
  14.     clistart
  15.  
  16.     get.l    module,a0
  17.     move.l    #1005,d0
  18.     call    TrackOpen
  19.     pea    freefunc(pc)
  20.     pea    allocfunc(pc)
  21.     get.l    dosbase,a6
  22.     pea    _LVORead(a6)
  23.     move.l    sp,a1
  24.     sub.l    a0,a0
  25.     clr.l    -(sp)
  26.     move.l    sp,a2
  27.     call    InternalLoadSeg
  28.     lea    16(sp),sp
  29.     put.l    d0,seglist
  30.     dv.l    seglist
  31.     bne.s    segok
  32.     lea    errmsg(pc),a0
  33. moderr    geta    module,a1
  34.     jump    ss,ExitError
  35.  
  36. segok    move.l    d0,d7        ; D7=copy of SegList
  37.     lea    moderrt(pc),a0
  38.     lsl.l    #2,d0
  39.     move.l    d0,a1
  40.     move.l    -(a1),d0
  41.     lsr.l    #1,d0
  42.     subq.l    #3,d0
  43.     bmi.s    moderr
  44.     move.l    d0,d1
  45.     swap    d1
  46. findtag1    cmp.w    #RTC_MATCHWORD,(a1)+
  47. findtag2    dbeq    d0,findtag1
  48.     dbeq    d1,findtag1
  49.     bne.s    moderr
  50.     move.l    a1,d2
  51.     subq.l    #2,d2
  52.     cmp.l    (a1),d2        ; A1=D2+2
  53.     bne.s    findtag2    ; D2 contains address of ResidentTag
  54.  
  55.     get.l    class,d0    ; Set options
  56.     beq.s    noclass
  57.     move.l    d0,a0
  58.     move.l    (a0),d0
  59.     move.l    d0,d1
  60.     tst.b    RT_FLAGS-RT_MATCHTAG(a1)
  61.     bpl.s    1$
  62.     bset    #7,d0
  63. 1$    move.b    d0,RT_FLAGS-RT_MATCHTAG(a1)
  64.     lsr.l    #7,d1
  65.     lea    badclass(pc),a0
  66.     bne.s    moderr
  67.  
  68. noclass    get.l    pri,d0
  69.     beq.s    modok
  70.     move.l    d0,a0
  71.     move.l    (a0),d0
  72.     move.b    d0,RT_PRI-RT_MATCHTAG(a1)
  73.     ext.w    d0
  74.     ext.l    d0
  75.     cmp.l    (a0),d0
  76.     lea    badpri(pc),a0
  77.     bne.s    moderr
  78.  
  79. modok    moveq    #kb_sizeof+8,d0    ; Calculate size of KickMem & KickTag
  80.     moveq    #1,d6
  81.     move.l    d7,d5        ; D5=SegList
  82. calcsize    lsl.l    #2,d7
  83.     addq.l    #8,d0
  84.     addq.l    #1,d6
  85.     move.l    d7,a0
  86.     move.l    (a0),d7
  87.     bne.s    calcsize
  88.     move.l    d0,d3        ; D3=KM+KT size
  89.     move.l    #MEMF_CLEAR+MEMF_PUBLIC,d1
  90.     move.l    4.w,a6
  91.     bsr.s    allocfunc
  92.     tst.l    d0
  93.     bne.s    tagok
  94.     moveq    #err_memory,d0
  95.     jump    ss,ReportError
  96.  
  97. tagok    move.l    d0,a0
  98.     lea    kb_kickmem+ML_NUMENTRIES(a0),a1
  99.     move.w    d6,(a1)+
  100.     move.l    a0,(a1)
  101.     subq.l    #8,(a1)+
  102.     move.l    d3,(a1)
  103.     addq.l    #8,(a1)+
  104. fillmem    lsl.l    #2,d5
  105.     move.l    d5,a2
  106.     move.l    -(a2),d0
  107.     move.l    a2,(a1)
  108.     subq.l    #8,(a1)+
  109.     addq.l    #8,d0
  110.     move.l    d0,(a1)+
  111.     move.l    4(a2),d5
  112.     bne.s    fillmem
  113.  
  114.     clrv.l    seglist
  115.     call    Forbid
  116.     lea    KickMemPtr(a6),a2
  117.     move.l    (a2),(a0)
  118.     move.l    a0,(a2)+
  119.     move.l    d2,(a1)+
  120.     move.l    (a2),(a1)
  121.     beq.s    1$
  122.     bset    #7,(a1)
  123. 1$    subq.l    #4,a1
  124.     move.l    a1,(a2)+
  125.     call    SumKickData
  126.     move.l    d0,(a2)
  127.     call    Permit
  128.  
  129.     tsv.l    callinit    ; Call module initialization if needed
  130.     beq.s    cl1
  131.     move.l    d2,a1
  132.     jump    InitResident
  133.  
  134. cleanup    get.l    seglist,d1
  135.     beq.s    cl1
  136.     lea    freefunc(pc),a1
  137.     call    dos,InternalUnLoadSeg
  138. cl1    rts
  139.  
  140. allocfunc    addq.l    #8,d0
  141.     mpush    d0/d1
  142.     or.l    #MEMF_REVERSE+MEMF_KICK,d1
  143.     call    AllocMem
  144.     tst.l    d0
  145.     bne.s    1$
  146.     movem.l    (sp),d0/d1
  147.     or.l    #MEMF_REVERSE+MEMF_LOCAL,d1
  148.     call    AllocMem
  149.     tst.l    d0
  150.     beq.s    2$
  151. 1$    addq.l    #8,d0
  152. 2$    addq.l    #8,sp
  153.     rts
  154.  
  155. freefunc    subq.l    #8,a1
  156.     addq.l    #8,d0
  157.     jump    FreeMem
  158.  
  159.     dc.b    '$VER: AddModule 1.1 (21.9.93)',0
  160. errmsg    dc.b    'Error loading %s',0
  161. moderrt    dc.b    '%s is not a resident module',0
  162. badclass    dc.b    'Class must be in range 0 to 127',0
  163. badpri    dc.b    'Priority must be in range -128 to 127',0
  164.     even
  165.  
  166.     tags
  167.     template    <MODULE/A,CLASS/K/N,PRI/K/N,INIT/S>
  168.     dv.l    module
  169.     dv.l    class
  170.     dv.l    pri
  171.     dv.l    callinit
  172.     extrahelp
  173.     dc.b    'Resident Module Adder 1.1 (c) 1993 Martin Mares, MJSoft System Software',10,10
  174.     dc.b    'Usage: AddModule <module> [CLASS <class>] [PRI <priority>] [INIT]',10
  175.     dc.b    'Switches: INIT - call initialization entry of the module after it''s added.',10
  176.     endhelp
  177.     exitrout cleanup
  178.     finish
  179.  
  180.     end
  181.