home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / start.s < prev    next >
Text File  |  1996-09-28  |  11KB  |  348 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. #define SYSTEM_CALL(func, vec) \
  166. trace_/**/func: ;                        \
  167.     pea _/**/func;                        \
  168.     pea vec;                         \
  169.     jsr _trace_entry;                    \
  170.     lea sp@(8),sp;                        \
  171.     tstl d0;                        \
  172.     beq  1f;        /* jump directly there */    \
  173.     /* in that case, trace_entry already provided the result */    \
  174.     movel sp@(-4),d0;                    \
  175.     rts;                            \
  176. 1:    jmp _/**/func;
  177. #include <sys/syscall.def>
  178. #undef SYSTEM_CALL
  179. #endif
  180.  
  181.  
  182.  
  183.    | The data table initializes static data structures.
  184.    | The format is specified in exec/InitStruct routines
  185.    | manual pages.  The INITBYTE/INITWORD/INITLONG routines
  186.    | are in the file "exec/initializers.i".  The first argument
  187.    | is the offset from the library base for this byte/word/long.
  188.    | The second argument is the value to put in that cell.
  189.    | The table is null terminated
  190.    | NOTE - LN_TYPE below is a correction - old example had LH_TYPE
  191.  
  192. dataTable:
  193.     INITBYTE (LN_TYPE,         NT_LIBRARY)
  194.     INITLONG (LN_NAME,         ixName)
  195.     INITBYTE (IXBASE_FLAGS,     0x6) |LIBF_CHANGED_SUMUSED
  196.     INITWORD (IXBASE_VERSION,     IX_VERSION)
  197.     INITWORD (IXBASE_REVISION,     IX_REVISION)
  198.     INITLONG (IXBASE_IDSTRING,     idString)
  199.     .long   0
  200.  
  201.  
  202. #ifdef DEBUG
  203. twoint:
  204.     .asciz "$%lx, $%lx\n"
  205. #endif
  206.  
  207.    | This routine gets called after the library has been allocated.
  208.    | The library pointer is in D0.  The segment list is in A0.
  209.    | If it returns non-zero then the library will be linked into
  210.    | the library list.
  211. initRoutine:
  212.  
  213.    |------ get the library pointer into a convenient A register
  214.    movel   a5,sp@-
  215.    movel   d0,a5
  216.  
  217.    |------ save a pointer to our loaded code
  218.    movel   a0,a5@(IXBASE_SEGLIST)
  219.  
  220.    |------ do the higher-level initialization in C
  221.    |------ the ix_init_glue() function checks if the hardware is supported
  222.    |------ (using 68000 instructions only) and if so will call ix_init()
  223.    |------ for the main initialization.
  224.    pea       a5@
  225.    jsr       _ix_init_glue
  226.    addqw   #4,sp
  227.  
  228.    movel   sp@+,a5
  229.    rts
  230.  
  231. |----------------------------------------------------------------------
  232. |
  233. | here begins the system interface commands.  When the user calls
  234. | OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  235. | into a call to the following routines (Open/Close/Expunge).  Exec
  236. | has already put our library pointer in A6 for us.  Exec has turned
  237. | off task switching while in these routines (via Forbid/Permit), so
  238. | we should not take too long in them.
  239. |
  240. |----------------------------------------------------------------------
  241.  
  242.  
  243.    | Open returns the library pointer in d0 if the open
  244.    | was successful.  If the open failed then null is returned.
  245.    | It might fail if we allocated memory on each open, or
  246.    | if only open application could have the library open
  247.    | at a time...
  248.  
  249. Open:      | ( libptr:a6, version:d0 )
  250.  
  251.  
  252.    |------ mark us as having another opener
  253.    addqw   #1,a6@(IXBASE_OPENCNT)
  254.  
  255.    |------ prevent delayed expunges
  256.    | !!!!!!
  257.    | commo - example code uses private flags field (IXBASE_MYFLAGS), WHY????
  258.    | !!!!!!
  259.    bclr    #LIBB_DELEXP,a6@(IXBASE_FLAGS)
  260.  
  261.    |------ do other things in C
  262.    pea       a6@
  263.    jsr       _ix_open
  264.    addqw   #4,sp
  265.    |--- ix_open() should return the library base, if all ok
  266.  
  267.    rts
  268.  
  269.    | There are two different things that might be returned from
  270.    | the Close routine.  If the library is no longer open and
  271.    | there is a delayed expunge then Close should return the
  272.    | segment list (as given to Init).  Otherwise close should
  273.    | return NULL.
  274.  
  275. Close:      | ( libptr:a6 )
  276.  
  277.    |------ do any cleanups needed in C
  278.    pea       a6@
  279.    jsr       _ix_close
  280.    addqw   #4,sp
  281.  
  282.    |------ mark us as having one fewer openers
  283.    subqw   #1,a6@(IXBASE_OPENCNT)
  284.  
  285.    |------ see if there is anyone left with us open
  286.    bne     Null
  287.  
  288.    |------ see if we have a delayed expunge pending
  289.    btst    #LIBB_DELEXP,a6@(IXBASE_FLAGS)    | SEE ABOVE!
  290.    bne     Expunge
  291.  
  292.    | reserved entry
  293.  
  294. Null:
  295.    moveq   #0,d0
  296.    rts
  297.  
  298.    | There are two different things that might be returned from
  299.    | the Expunge routine.  If the library is no longer open
  300.    | then Expunge should return the segment list (as given to
  301.    | Init).  Otherwise Expunge should set the delayed expunge
  302.    | flag and return NULL.
  303.    |
  304.    | One other important note: because Expunge is called from
  305.    | the memory allocator, it may NEVER Wait() or otherwise
  306.    | take long time to complete.
  307.  
  308. Expunge:   | ( libptr: a6 )
  309.    moveml  a2/a5/a6,sp@-
  310.    movel   a6,a5
  311.  
  312.    |------ assume we can't expunge
  313.    subal   a2,a2
  314.    bset    #LIBB_DELEXP,a5@(IXBASE_FLAGS)    | SEE ABOVE !!
  315.  
  316.    |------ see if anyone has us open
  317.    tstw    a5@(IXBASE_OPENCNT)
  318.    bne     L21
  319.  
  320.    |------ go ahead and get rid of us.  Store our seglist in a2
  321.    movel   a5@(IXBASE_SEGLIST),a2
  322.    movel   4:w,a6
  323.  
  324.    |------ unlink from library list
  325.    movel   a5,a1
  326.    jsr       a6@(_LVORemove)
  327.  
  328.    |
  329.    | device specific closings here...
  330.    |
  331.    pea       a5@
  332.    jsr       _ix_expunge
  333.    addqw   #4,sp
  334.  
  335.    |------ free our memory
  336.    movel   a5,a1
  337.    moveq   #0,d0
  338.    movew   a5@(IXBASE_NEGSIZE),d0
  339.    subl    d0,a1
  340.    addw    a5@(IXBASE_POSSIZE),d0
  341.    jsr       a6@(_LVOFreeMem)
  342.  
  343. L21:       |------ set up our return value
  344.    movel   a2,d0
  345.  
  346.    moveml  sp@+,a2/a5/a6
  347.    rts
  348.