home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / ixnet / start.s < prev    next >
Text File  |  1996-12-11  |  9KB  |  312 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 _obsolete29 obsolete
  101. #define _obsolete30 obsolete
  102. #define _obsolete31 obsolete
  103. #define _obsolete32 obsolete
  104. #define _obsolete33 obsolete
  105. #define _obsolete34 obsolete
  106. #define _obsolete35 obsolete
  107. #define _obsolete36 obsolete
  108. #define _obsolete37 obsolete
  109. #define _obsolete40 obsolete
  110. #define _obsolete41 obsolete
  111. #define _obsolete47 obsolete
  112. #define _obsolete56 obsolete
  113. #define _obsolete57 obsolete
  114. #define _obsolete58 obsolete
  115. #define _obsolete59 obsolete
  116. #define _obsolete74 obsolete
  117. #define _obsolete75 obsolete
  118. #define _obsolete76 obsolete
  119. #define _obsolete77 obsolete
  120. #define _obsolete78 obsolete
  121. #define _obsolete79 obsolete
  122. #define _obsolete80 obsolete
  123. #define _obsolete81 obsolete
  124. #define _obsolete82 obsolete
  125. #define _obsolete83 obsolete
  126. #define _obsolete84 obsolete
  127. #define _obsolete95 obsolete
  128. #define _obsolete96 obsolete
  129. #define _obsolete97 obsolete
  130. #define _obsolete98 obsolete
  131. #define _obsolete99 obsolete
  132. #define _obsolete100 obsolete
  133. #define _obsolete102 obsolete
  134.  
  135.    |------ my libraries definitions
  136.  
  137. #define SYSTEM_CALL(func, vec) .long _/**/func
  138. #include <sys/ixnet_syscall.def>
  139. #undef SYSTEM_CALL
  140.  
  141.    |------ function table end marker
  142.    .long   -1
  143.  
  144.  
  145.    | The data table initializes static data structures.
  146.    | The format is specified in exec/InitStruct routines
  147.    | manual pages.  The INITBYTE/INITWORD/INITLONG routines
  148.    | are in the file "exec/initializers.i".  The first argument
  149.    | is the offset from the library base for this byte/word/long.
  150.    | The second argument is the value to put in that cell.
  151.    | The table is null terminated
  152.    | NOTE - LN_TYPE below is a correction - old example had LH_TYPE
  153.  
  154. dataTable:
  155.     INITBYTE (LN_TYPE,              NT_LIBRARY)
  156.     INITLONG (LN_NAME,              ixName)
  157.     INITBYTE (IXNETBASE_FLAGS,      0x6) |LIBF_CHANGED_SUMUSED
  158.     INITWORD (IXNETBASE_VERSION,    IXNET_VERSION)
  159.     INITWORD (IXNETBASE_REVISION,   IXNET_REVISION)
  160.     INITLONG (IXNETBASE_IDSTRING,   idString)
  161.     .long    0
  162.  
  163.    | This routine gets called after the library has been allocated.
  164.    | The library pointer is in D0.  The segment list is in A0.
  165.    | If it returns non-zero then the library will be linked into
  166.    | the library list.
  167. initRoutine:
  168.  
  169.    |------ get the library pointer into a convenient A register
  170.    movel   a5,sp@-
  171.    movel   d0,a5
  172.  
  173.    |------ save a pointer to our loaded code
  174.    movel   a0,a5@(IXNETBASE_SEGLIST)
  175.  
  176.    |------ do the higher-level initialization in C
  177.    pea       a5@
  178.    jbsr    _ixnet_init
  179.    lea       sp@(4),sp
  180.    movel   sp@+,a5
  181.    rts
  182.  
  183. |----------------------------------------------------------------------
  184. |
  185. | here begins the system interface commands.  When the user calls
  186. | OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  187. | into a call to the following routines (Open/Close/Expunge).  Exec
  188. | has already put our library pointer in A6 for us.  Exec has turned
  189. | off task switching while in these routines (via Forbid/Permit), so
  190. | we should not take too long in them.
  191. |
  192. |----------------------------------------------------------------------
  193.  
  194.  
  195.    | Open returns the library pointer in d0 if the open
  196.    | was successful.  If the open failed then null is returned.
  197.    | It might fail if we allocated memory on each open, or
  198.    | if only open application could have the library open
  199.    | at a time...
  200.  
  201. Open:       | ( libptr:a6, version:d0 )
  202.  
  203.  
  204.    |------ mark us as having another opener
  205.    addw   #1,a6@(IXNETBASE_OPENCNT)
  206.  
  207.    |------ prevent delayed expunges
  208.    | !!!!!!
  209.    | commo - example code uses private flags field (IXNETBASE_MYFLAGS), WHY????
  210.    | !!!!!!
  211.    bclr   #LIBB_DELEXP,a6@(IXNETBASE_FLAGS)
  212.  
  213.    |------ do other things in C
  214.    pea       a6@
  215.    jbsr    _ixnet_open
  216.    lea       sp@(4),sp
  217.    |--- ix_open() should return the library base, if all ok
  218.  
  219.    rts
  220.  
  221.    | There are two different things that might be returned from
  222.    | the Close routine.  If the library is no longer open and
  223.    | there is a delayed expunge then Close should return the
  224.    | segment list (as given to Init).  Otherwise close should
  225.    | return NULL.
  226.  
  227. Close:        | ( libptr:a6 )
  228.  
  229.    |------ do any cleanups needed in C
  230.    pea      a6@
  231.    jsr      _ixnet_close
  232.    lea      sp@(4),sp
  233.  
  234.    |------ set the return value
  235.    clrl   d0
  236.  
  237.    |------ mark us as having one fewer openers
  238.    subw   #1,a6@(IXNETBASE_OPENCNT)
  239.  
  240.    |------ see if there is anyone left with us open
  241.    bne      L11
  242.  
  243.    |------ see if we have a delayed expunge pending
  244.    btst   #LIBB_DELEXP,a6@(IXNETBASE_FLAGS)        | SEE ABOVE!
  245.    beq      L11
  246.  
  247.    |------ do the expunge
  248.    bsr      Expunge
  249. L11:
  250.    rts
  251.  
  252.  
  253.    | There are two different things that might be returned from
  254.    | the Expunge routine.  If the library is no longer open
  255.    | then Expunge should return the segment list (as given to
  256.    | Init).  Otherwise Expunge should set the delayed expunge
  257.    | flag and return NULL.
  258.    |
  259.    | One other important note: because Expunge is called from
  260.    | the memory allocator, it may NEVER Wait() or otherwise
  261.    | take long time to complete.
  262.  
  263. Expunge:   | ( libptr: a6 )
  264.    moveml  d2/a5/a6,sp@-
  265.    movel   a6,a5
  266.    movel   4:w,a6
  267.  
  268.    |------ see if anyone has us open
  269.    tstw    a5@(IXNETBASE_OPENCNT)
  270.    beq       L21
  271.  
  272.    |------ it is still open.  set the delayed expunge flag
  273.    bset    #LIBB_DELEXP,a5@(IXNETBASE_FLAGS)       | SEE ABOVE !!
  274.    clrl    d0
  275.    bra       Expunge_End
  276.  
  277. L21:
  278.    |------ go ahead and get rid of us.    Store our seglist in d2
  279.    movel   a5@(IXNETBASE_SEGLIST),d2
  280.  
  281.    |------ unlink from library list
  282.    movel   a5,a1
  283.    jsr       a6@(_LVORemove)
  284.  
  285.    |
  286.    | device specific closings here...
  287.    |
  288.    pea       a5@
  289.    jsr       _ixnet_expunge
  290.    lea       sp@(4),sp
  291.  
  292.    |------ free our memory
  293.    clrl    d0
  294.    movel   a5,a1
  295.    movew   a5@(IXNETBASE_NEGSIZE),d0
  296.  
  297.    subl    d0,a1
  298.    addw    a5@(IXNETBASE_POSSIZE),d0
  299.  
  300.    jsr       a6@(_LVOFreeMem)
  301.  
  302.    |------ set up our return value
  303.    movel   d2,d0
  304.  
  305. Expunge_End:
  306.    moveml  sp@+,d2/a5/a6
  307.    rts
  308.  
  309. Null:
  310.    clrl    d0
  311.    rts
  312.