home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / library / start.s < prev    next >
Text File  |  1996-12-15  |  11KB  |  349 lines

  1. /*
  2.  *  This file is part of ixemul.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 <ixemul.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.    rts
  39.  
  40. |-----------------------------------------------------------------------
  41. | A romtag structure.  Both "exec" and "ramlib" look for
  42. | this structure to discover magic constants about you
  43. | (such as where to start running you from...).
  44. |-----------------------------------------------------------------------
  45.  
  46. initDDescrip:
  47.                |STRUCTURE RT,0
  48.      .word    RTC_MATCHWORD      | UWORD RT_MATCHWORD
  49.      .long    initDDescrip       | APTR  RT_MATCHTAG
  50.      .long    EndCode            | APTR  RT_ENDSKIP
  51.      .byte    RTF_AUTOINIT       | UBYTE RT_FLAGS
  52.      .byte    IX_VERSION         | UBYTE RT_VERSION
  53.      .byte    NT_LIBRARY         | UBYTE RT_TYPE
  54.      .byte    IX_PRIORITY        | BYTE  RT_PRI
  55.      .long    ixName             | APTR  RT_NAME
  56.      .long    idString           | APTR  RT_IDSTRING
  57.      .long    Init               | APTR  RT_INIT
  58. | this is just fool proof, and this library will never make it to ROM
  59. | anyway, so resident tags are not that important ;-)
  60. EndCode:
  61.  
  62.  
  63.    | this is the name that the library will have
  64. ixName:    .asciz IX_NAME
  65.  
  66.    | this is an identifier tag to help in supporting the library
  67.    | format is 'name version.revision (dd.mm.yy)',<cr>,<lf>,<null>'
  68.    | without any leading zeros in dd.mm.yy
  69. idString:
  70.     .ascii IX_IDSTRING
  71.     .byte 13
  72.     .byte 10
  73.     .byte 0
  74.  
  75.    | force word alignment
  76.    .even
  77.  
  78.  
  79.    | The romtag specified that we were "RTF_AUTOINIT".  This means
  80.    | that the RT_INIT structure member points to one of these
  81.    | tables below.  If the AUTOINIT bit was not set then RT_INIT
  82.    | would point to a routine to run.
  83.  
  84. Init:
  85.    .long   IXBASE_SIZEOF    | size of library base data space
  86.    .long   funcTable        | pointer to function initializers
  87.    .long   dataTable            | pointer to data initializers
  88.    .long   initRoutine            | routine to run
  89.  
  90.  
  91. funcTable:
  92.  
  93.    |------ standard system routines
  94.    .long   Open
  95.    .long   Close
  96.    .long   Expunge
  97.    .long   Null
  98.  
  99.    |------ my libraries definitions
  100.  
  101. #define ___must_recompile220 ___must_recompile
  102. #define ___must_recompile221 ___must_recompile
  103. #define ___must_recompile222 ___must_recompile
  104. #define ___must_recompile223 ___must_recompile
  105. #define ___must_recompile224 ___must_recompile
  106. #define ___must_recompile226 ___must_recompile
  107. #define ___must_recompile229 ___must_recompile
  108. #define ___must_recompile235 ___must_recompile
  109. #define ___must_recompile237 ___must_recompile
  110. #define ___must_recompile239 ___must_recompile
  111. #define ___must_recompile240 ___must_recompile
  112. #define ___must_recompile241 ___must_recompile
  113. #define ___must_recompile242 ___must_recompile
  114. #define ___must_recompile243 ___must_recompile
  115. #define ___must_recompile244 ___must_recompile
  116. #define ___must_recompile253 ___must_recompile
  117. #define ___must_recompile254 ___must_recompile
  118. #define ___must_recompile255 ___must_recompile
  119. #define ___must_recompile256 ___must_recompile
  120. #define ___must_recompile259 ___must_recompile
  121. #define ___must_recompile262 ___must_recompile
  122. #define ___must_recompile267 ___must_recompile
  123. #define ___must_recompile273 ___must_recompile
  124. #define ___must_recompile274 ___must_recompile
  125. #define ___must_recompile275 ___must_recompile
  126. #define ___must_recompile277 ___must_recompile
  127. #define ___must_recompile386 ___must_recompile
  128. #define ___must_recompile387 ___must_recompile
  129. #define ___must_recompile388 ___must_recompile
  130. #define ___must_recompile389 ___must_recompile
  131. #define ___must_recompile390 ___must_recompile
  132. #define ___must_recompile447 ___must_recompile
  133. #define ___must_recompile448 ___must_recompile
  134. #define ___must_recompile449 ___must_recompile
  135. #define ___must_recompile450 ___must_recompile
  136. #define ___must_recompile502 ___must_recompile
  137. #define ___must_recompile503 ___must_recompile
  138. #define ___must_recompile504 ___must_recompile
  139. #define ___must_recompile505 ___must_recompile
  140. #define ___must_recompile506 ___must_recompile
  141. #define ___must_recompile507 ___must_recompile
  142. #define ___must_recompile520 ___must_recompile
  143. #define ___must_recompile521 ___must_recompile
  144. #define ___must_recompile523 ___must_recompile
  145. #define ___must_recompile524 ___must_recompile
  146. #define ___must_recompile525 ___must_recompile
  147. #define ___must_recompile526 ___must_recompile
  148. #define ___must_recompile527 ___must_recompile
  149. #define ___must_recompile528 ___must_recompile
  150. #define ___must_recompile529 ___must_recompile
  151. #define ___must_recompile530 ___must_recompile
  152.  
  153. #ifdef TRACE_LIBRARY
  154. #define SYSTEM_CALL(func, vec) .long trace_/**/func
  155. #else
  156. #define SYSTEM_CALL(func, vec) .long _/**/func
  157. #endif
  158. #include <sys/syscall.def>
  159. #undef SYSTEM_CALL
  160.  
  161.    |------ function table end marker
  162.    .long   -1
  163.  
  164. #ifdef TRACE_LIBRARY
  165.  
  166. # Make sure tracing doesn't clobber A1, as that will be used to return a
  167. # pointer to a structure.
  168.  
  169. #define SYSTEM_CALL(func, vec) \
  170. trace_/**/func: ;                        \
  171.     moveml d0/d1/a0/a1,sp@-;                \
  172.     pea _/**/func;                        \
  173.     pea vec;                         \
  174.     jsr _trace_entry;                    \
  175.     lea sp@(8),sp;                        \
  176.     tstl d0;                        \
  177.     beq  1f;        /* jump directly there */    \
  178.     moveml sp@+,d0/d1/a0/a1;                \
  179.     /* in that case, trace_entry already provided the result */    \
  180.     movel sp@(-20),d0;                    \
  181.     rts;                            \
  182. 1:    moveml sp@+,d0/d1/a0/a1;                \
  183.     jmp _/**/func;
  184. #include <sys/syscall.def>
  185. #undef SYSTEM_CALL
  186. #endif
  187.  
  188.  
  189.  
  190.    | The data table initializes static data structures.
  191.    | The format is specified in exec/InitStruct routines
  192.    | manual pages.  The INITBYTE/INITWORD/INITLONG routines
  193.    | are in the file "exec/initializers.i".  The first argument
  194.    | is the offset from the library base for this byte/word/long.
  195.    | The second argument is the value to put in that cell.
  196.    | The table is null terminated
  197.    | NOTE - LN_TYPE below is a correction - old example had LH_TYPE
  198.  
  199. dataTable:
  200.     INITBYTE (LN_TYPE,         NT_LIBRARY)
  201.     INITLONG (LN_NAME,         ixName)
  202.     INITBYTE (IXBASE_FLAGS,     0x6) |LIBF_CHANGED_SUMUSED
  203.     INITWORD (IXBASE_VERSION,     IX_VERSION)
  204.     INITWORD (IXBASE_REVISION,     IX_REVISION)
  205.     INITLONG (IXBASE_IDSTRING,     idString)
  206.     .long   0
  207.  
  208.    | This routine gets called after the library has been allocated.
  209.    | The library pointer is in D0.  The segment list is in A0.
  210.    | If it returns non-zero then the library will be linked into
  211.    | the library list.
  212. initRoutine:
  213.  
  214.    |------ get the library pointer into a convenient A register
  215.    movel   a5,sp@-
  216.    movel   d0,a5
  217.  
  218.    |------ save a pointer to our loaded code
  219.    movel   a0,a5@(IXBASE_SEGLIST)
  220.  
  221.    |------ do the higher-level initialization in C
  222.    |------ the ix_init_glue() function checks if the hardware is supported
  223.    |------ (using 68000 instructions only) and if so will call ix_init()
  224.    |------ for the main initialization.
  225.    pea       a5@
  226.    jsr       _ix_init_glue
  227.    addqw   #4,sp
  228.  
  229.    movel   sp@+,a5
  230.    rts
  231.  
  232. |----------------------------------------------------------------------
  233. |
  234. | here begins the system interface commands.  When the user calls
  235. | OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  236. | into a call to the following routines (Open/Close/Expunge).  Exec
  237. | has already put our library pointer in A6 for us.  Exec has turned
  238. | off task switching while in these routines (via Forbid/Permit), so
  239. | we should not take too long in them.
  240. |
  241. |----------------------------------------------------------------------
  242.  
  243.  
  244.    | Open returns the library pointer in d0 if the open
  245.    | was successful.  If the open failed then null is returned.
  246.    | It might fail if we allocated memory on each open, or
  247.    | if only open application could have the library open
  248.    | at a time...
  249.  
  250. Open:      | ( libptr:a6, version:d0 )
  251.  
  252.  
  253.    |------ mark us as having another opener
  254.    addqw   #1,a6@(IXBASE_OPENCNT)
  255.  
  256.    |------ prevent delayed expunges
  257.    | !!!!!!
  258.    | commo - example code uses private flags field (IXBASE_MYFLAGS), WHY????
  259.    | !!!!!!
  260.    bclr    #LIBB_DELEXP,a6@(IXBASE_FLAGS)
  261.  
  262.    |------ do other things in C
  263.    pea       a6@
  264.    jsr       _ix_open
  265.    addqw   #4,sp
  266.    |--- ix_open() should return the library base, if all ok
  267.  
  268.    rts
  269.  
  270.    | There are two different things that might be returned from
  271.    | the Close routine.  If the library is no longer open and
  272.    | there is a delayed expunge then Close should return the
  273.    | segment list (as given to Init).  Otherwise close should
  274.    | return NULL.
  275.  
  276. Close:      | ( libptr:a6 )
  277.  
  278.    |------ do any cleanups needed in C
  279.    pea       a6@
  280.    jsr       _ix_close
  281.    addqw   #4,sp
  282.  
  283.    |------ mark us as having one fewer openers
  284.    subqw   #1,a6@(IXBASE_OPENCNT)
  285.  
  286.    |------ see if there is anyone left with us open
  287.    bne     Null
  288.  
  289.    |------ see if we have a delayed expunge pending
  290.    btst    #LIBB_DELEXP,a6@(IXBASE_FLAGS)    | SEE ABOVE!
  291.    bne     Expunge
  292.  
  293.    | reserved entry
  294.  
  295. Null:
  296.    moveq   #0,d0
  297.    rts
  298.  
  299.    | There are two different things that might be returned from
  300.    | the Expunge routine.  If the library is no longer open
  301.    | then Expunge should return the segment list (as given to
  302.    | Init).  Otherwise Expunge should set the delayed expunge
  303.    | flag and return NULL.
  304.    |
  305.    | One other important note: because Expunge is called from
  306.    | the memory allocator, it may NEVER Wait() or otherwise
  307.    | take long time to complete.
  308.  
  309. Expunge:   | ( libptr: a6 )
  310.    moveml  a2/a5/a6,sp@-
  311.    movel   a6,a5
  312.  
  313.    |------ assume we can't expunge
  314.    subal   a2,a2
  315.    bset    #LIBB_DELEXP,a5@(IXBASE_FLAGS)    | SEE ABOVE !!
  316.  
  317.    |------ see if anyone has us open
  318.    tstw    a5@(IXBASE_OPENCNT)
  319.    bne     L21
  320.  
  321.    |------ go ahead and get rid of us.  Store our seglist in a2
  322.    movel   a5@(IXBASE_SEGLIST),a2
  323.    movel   4:w,a6
  324.  
  325.    |------ unlink from library list
  326.    movel   a5,a1
  327.    jsr       a6@(_LVORemove)
  328.  
  329.    |
  330.    | device specific closings here...
  331.    |
  332.    pea       a5@
  333.    jsr       _ix_expunge
  334.    addqw   #4,sp
  335.  
  336.    |------ free our memory
  337.    movel   a5,a1
  338.    moveq   #0,d0
  339.    movew   a5@(IXBASE_NEGSIZE),d0
  340.    subl    d0,a1
  341.    addw    a5@(IXBASE_POSSIZE),d0
  342.    jsr       a6@(_LVOFreeMem)
  343.  
  344. L21:       |------ set up our return value
  345.    movel   a2,d0
  346.  
  347.    moveml  sp@+,a2/a5/a6
  348.    rts
  349.