home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / start.s,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  9.0 KB  |  349 lines

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