home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / ixnet / start.s < prev    next >
Text File  |  1996-09-28  |  9KB  |  300 lines

  1. /*
  2.  *  This file is part of ixnet.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #define START
  22. #include "ixnet.h"
  23. #include "version.h"
  24.  
  25. /* size of C_PRIVATE was generated by create_header.c */
  26. /* include the generated header */
  27. #include "ix_internals.h"
  28.  
  29.  
  30.     .text
  31.  
  32.    | The first executable location.  This should return an error
  33.    | in case someone tried to run you as a program (instead of
  34.    | loading you as a library).
  35.     .globl    Start        | we use this to force inclusion of start.s
  36. Start:
  37.    movel   #-1,d0
  38. obsolete:            | use this for obsolete syscalls
  39.    rts
  40.  
  41. |-----------------------------------------------------------------------
  42. | A romtag structure.  Both "exec" and "ramlib" look for
  43. | this structure to discover magic constants about you
  44. | (such as where to start running you from...).
  45. |-----------------------------------------------------------------------
  46.  
  47. initDDescrip:
  48.            |STRUCTURE RT,0
  49.      .word    RTC_MATCHWORD     | UWORD RT_MATCHWORD
  50.      .long    initDDescrip     | APTR  RT_MATCHTAG
  51.      .long    EndCode         | APTR  RT_ENDSKIP
  52.      .byte    RTF_AUTOINIT     | UBYTE RT_FLAGS
  53.      .byte    IXNET_VERSION     | UBYTE RT_VERSION
  54.      .byte    NT_LIBRARY     | UBYTE RT_TYPE
  55.      .byte    IXNET_PRIORITY     | BYTE  RT_PRI
  56.      .long    ixName         | APTR  RT_NAME
  57.      .long    idString         | APTR  RT_IDSTRING
  58.      .long    Init         | APTR  RT_INIT
  59. | this is just fool proof, and this library will never make it to ROM
  60. | anyway, so resident tags are not that important ;-)
  61. EndCode:
  62.  
  63.  
  64.    | this is the name that the library will have
  65. ixName:    .asciz IXNET_NAME
  66.  
  67.    | this is an identifier tag to help in supporting the library
  68.    | format is 'name version.revision (dd.mm.yy)',<cr>,<lf>,<null>'
  69.    | without any leading zeros in dd.mm.yy
  70. idString:
  71.     .ascii IXNET_IDSTRING
  72.     .byte 13
  73.     .byte 10
  74.     .byte 0
  75.  
  76.    | force word alignment
  77.    .even
  78.  
  79.  
  80.    | The romtag specified that we were "RTF_AUTOINIT".  This means
  81.    | that the RT_INIT structure member points to one of these
  82.    | tables below.  If the AUTOINIT bit was not set then RT_INIT
  83.    | would point to a routine to run.
  84.  
  85. Init:
  86.    .long   IXNETBASE_SIZEOF       | size of library base data space
  87.    .long   funcTable        | pointer to function initializers
  88.    .long   dataTable        | pointer to data initializers
  89.    .long   initRoutine        | routine to run
  90.  
  91.  
  92. funcTable:
  93.  
  94.    |------ standard system routines
  95.    .long   Open
  96.    .long   Close
  97.    .long   Expunge
  98.    .long   Null
  99.  
  100. #define _obsolete56 obsolete
  101. #define _obsolete57 obsolete
  102. #define _obsolete58 obsolete
  103. #define _obsolete59 obsolete
  104. #define _obsolete74 obsolete
  105. #define _obsolete75 obsolete
  106. #define _obsolete77 obsolete
  107. #define _obsolete78 obsolete
  108. #define _obsolete79 obsolete
  109. #define _obsolete80 obsolete
  110. #define _obsolete81 obsolete
  111. #define _obsolete82 obsolete
  112. #define _obsolete83 obsolete
  113. #define _obsolete84 obsolete
  114. #define _obsolete95 obsolete
  115. #define _obsolete96 obsolete
  116.  
  117.    |------ my libraries definitions
  118.  
  119. #define SYSTEM_CALL(func, vec) .long _/**/func
  120. #include <sys/ixnet_syscall.def>
  121. #undef SYSTEM_CALL
  122.  
  123.    |------ function table end marker
  124.    .long   -1
  125.  
  126.  
  127.    | The data table initializes static data structures.
  128.    | The format is specified in exec/InitStruct routines
  129.    | manual pages.  The INITBYTE/INITWORD/INITLONG routines
  130.    | are in the file "exec/initializers.i".  The first argument
  131.    | is the offset from the library base for this byte/word/long.
  132.    | The second argument is the value to put in that cell.
  133.    | The table is null terminated
  134.    | NOTE - LN_TYPE below is a correction - old example had LH_TYPE
  135.  
  136. dataTable:
  137.     INITBYTE (LN_TYPE,              NT_LIBRARY)
  138.     INITLONG (LN_NAME,              ixName)
  139.     INITBYTE (IXNETBASE_FLAGS,      0x6) |LIBF_CHANGED_SUMUSED
  140.     INITWORD (IXNETBASE_VERSION,    IXNET_VERSION)
  141.     INITWORD (IXNETBASE_REVISION,   IXNET_REVISION)
  142.     INITLONG (IXNETBASE_IDSTRING,   idString)
  143.     .long    0
  144.  
  145.  
  146. #ifdef DEBUG
  147. twoint:
  148.     .asciz "$%lx, $%lx\n"
  149. #endif
  150.  
  151.    | This routine gets called after the library has been allocated.
  152.    | The library pointer is in D0.  The segment list is in A0.
  153.    | If it returns non-zero then the library will be linked into
  154.    | the library list.
  155. initRoutine:
  156.  
  157.    |------ get the library pointer into a convenient A register
  158.    movel   a5,sp@-
  159.    movel   d0,a5
  160.  
  161.    |------ save a pointer to our loaded code
  162.    movel   a0,a5@(IXNETBASE_SEGLIST)
  163.  
  164.    |------ do the higher-level initialization in C
  165.    pea       a5@
  166.    jbsr    _ixnet_init
  167.    lea       sp@(4),sp
  168.    movel   sp@+,a5
  169.    rts
  170.  
  171. |----------------------------------------------------------------------
  172. |
  173. | here begins the system interface commands.  When the user calls
  174. | OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  175. | into a call to the following routines (Open/Close/Expunge).  Exec
  176. | has already put our library pointer in A6 for us.  Exec has turned
  177. | off task switching while in these routines (via Forbid/Permit), so
  178. | we should not take too long in them.
  179. |
  180. |----------------------------------------------------------------------
  181.  
  182.  
  183.    | Open returns the library pointer in d0 if the open
  184.    | was successful.  If the open failed then null is returned.
  185.    | It might fail if we allocated memory on each open, or
  186.    | if only open application could have the library open
  187.    | at a time...
  188.  
  189. Open:       | ( libptr:a6, version:d0 )
  190.  
  191.  
  192.    |------ mark us as having another opener
  193.    addw   #1,a6@(IXNETBASE_OPENCNT)
  194.  
  195.    |------ prevent delayed expunges
  196.    | !!!!!!
  197.    | commo - example code uses private flags field (IXNETBASE_MYFLAGS), WHY????
  198.    | !!!!!!
  199.    bclr   #LIBB_DELEXP,a6@(IXNETBASE_FLAGS)
  200.  
  201.    |------ do other things in C
  202.    pea       a6@
  203.    jbsr    _ixnet_open
  204.    lea       sp@(4),sp
  205.    |--- ix_open() should return the library base, if all ok
  206.  
  207.    rts
  208.  
  209.    | There are two different things that might be returned from
  210.    | the Close routine.  If the library is no longer open and
  211.    | there is a delayed expunge then Close should return the
  212.    | segment list (as given to Init).  Otherwise close should
  213.    | return NULL.
  214.  
  215. Close:        | ( libptr:a6 )
  216.  
  217.    |------ do any cleanups needed in C
  218.    pea      a6@
  219.    jsr      _ixnet_close
  220.    lea      sp@(4),sp
  221.  
  222.    |------ set the return value
  223.    clrl   d0
  224.  
  225.    |------ mark us as having one fewer openers
  226.    subw   #1,a6@(IXNETBASE_OPENCNT)
  227.  
  228.    |------ see if there is anyone left with us open
  229.    bne      L11
  230.  
  231.    |------ see if we have a delayed expunge pending
  232.    btst   #LIBB_DELEXP,a6@(IXNETBASE_FLAGS)        | SEE ABOVE!
  233.    beq      L11
  234.  
  235.    |------ do the expunge
  236.    bsr      Expunge
  237. L11:
  238.    rts
  239.  
  240.  
  241.    | There are two different things that might be returned from
  242.    | the Expunge routine.  If the library is no longer open
  243.    | then Expunge should return the segment list (as given to
  244.    | Init).  Otherwise Expunge should set the delayed expunge
  245.    | flag and return NULL.
  246.    |
  247.    | One other important note: because Expunge is called from
  248.    | the memory allocator, it may NEVER Wait() or otherwise
  249.    | take long time to complete.
  250.  
  251. Expunge:   | ( libptr: a6 )
  252.    moveml  d2/a5/a6,sp@-
  253.    movel   a6,a5
  254.    movel   4:w,a6
  255.  
  256.    |------ see if anyone has us open
  257.    tstw    a5@(IXNETBASE_OPENCNT)
  258.    beq       L21
  259.  
  260.    |------ it is still open.  set the delayed expunge flag
  261.    bset    #LIBB_DELEXP,a5@(IXNETBASE_FLAGS)       | SEE ABOVE !!
  262.    clrl    d0
  263.    bra       Expunge_End
  264.  
  265. L21:
  266.    |------ go ahead and get rid of us.    Store our seglist in d2
  267.    movel   a5@(IXNETBASE_SEGLIST),d2
  268.  
  269.    |------ unlink from library list
  270.    movel   a5,a1
  271.    jsr       a6@(_LVORemove)
  272.  
  273.    |
  274.    | device specific closings here...
  275.    |
  276.    pea       a5@
  277.    jsr       _ixnet_expunge
  278.    lea       sp@(4),sp
  279.  
  280.    |------ free our memory
  281.    clrl    d0
  282.    movel   a5,a1
  283.    movew   a5@(IXNETBASE_NEGSIZE),d0
  284.  
  285.    subl    d0,a1
  286.    addw    a5@(IXNETBASE_POSSIZE),d0
  287.  
  288.    jsr       a6@(_LVOFreeMem)
  289.  
  290.    |------ set up our return value
  291.    movel   d2,d0
  292.  
  293. Expunge_End:
  294.    moveml  sp@+,d2/a5/a6
  295.    rts
  296.  
  297. Null:
  298.    clrl    d0
  299.    rts
  300.