home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_oth / amigalib.lzh / AMIGALIB / AMIGALIB.LZH / asm_source / wbinit.asm < prev    next >
Encoding:
Assembly Source File  |  1990-01-17  |  14.6 KB  |  404 lines

  1. *************************************************************************
  2. *              WBInit.asm---FORTRAN Compiler Startup Code               *
  3. *                    Substantially based upon                           *
  4. *                                the                                    *
  5. *               ABSOFT CORPORATION FORTRAN 77 COMPILER                  *
  6. *                                                                       *
  7. *                       MAIN PROGRAM START UP CODE                      *
  8. *                               FOR                                     *
  9. *                       AMIGADOS BASED SYSTEMS                          *
  10. *                                                                       *
  11. *                       Copyright (C) 1986,1987                         *
  12. *               Absoft Corporation, Royal Oak, MI  48072                *
  13. *                                                                       *
  14. *                                                                       *
  15. *       This code segment is the main program start up procedure, with  *
  16. *       workbench support.   It must be linked using Alink or Blink to  *
  17. *       amiga.lib.                                                      *
  18. *                                                                       *
  19. *       The resulting linker output file must be named "init.sc".       *
  20. *                                                                       *
  21. *       The file is also used in source form as an INCLUDE file when    *
  22. *       assembly language source is being generated by the compiler     *
  23. *       for a main program.                                             *
  24. *                                                                       *
  25. *       The routine performs the following functions:                   *
  26. *                                                                       *
  27. *               1. Test for workbench vs CLI startup                    *
  28. *               2. If workbench, handle all necessary environment issues*
  29. *               3. allocate a memory segment for the heap               *
  30. *               4. open "dos.library"                                   *
  31. *               5. locate the STDIN and STDOUT file handles             *
  32. *               6. load f77.rl into the heap                            *
  33. *                                                                       *
  34. *       The routine passes the following registers to f77.rl:           *
  35. *                                                                       *
  36. *               D2 - run-time library specification:                    *
  37. *                    0 = f77.rl                                         *
  38. *                    1 = hdw.rl (not available for Amiga)               *
  39. *                    2 = m81.rl                                         *
  40. *               D5 - command line length                                *
  41. *               A0 - pointer to heap                                    *
  42. *               A2 - pointer to main program                            *
  43. *               A3 - command line pointer                               *
  44. *               A4 - debug or profil command line pointer               *
  45. *               A5 - pointer to f77.rl                                  *
  46. *                                                                       *
  47. *                                                                       *
  48. *************************************************************************
  49. *
  50. * Edit history:
  51. *
  52. *  19 Feb 86    file created                                            PAJ
  53. *  02 Jun 87    converted to V2.3                                       CAG
  54. *  06 Mar 89    WorkBench support provided         Jim Locker
  55. *
  56.  
  57. *
  58. * - Selected AmigaDOS equates:
  59. *
  60.    INCLUDE "exec/types.i"
  61.    INCLUDE "exec/alerts.i"
  62.    INCLUDE "exec/nodes.i"
  63.    INCLUDE "exec/lists.i"
  64.    INCLUDE "exec/ports.i"
  65.    INCLUDE "exec/libraries.i"
  66.    INCLUDE "exec/tasks.i"
  67.    INCLUDE "libraries/dos.i"
  68.    INCLUDE "libraries/dosextens.i"
  69.    INCLUDE "workbench/startup.i"
  70.  
  71. * - from "depsys"
  72.  
  73. AEXEC   EQU     -16                     * "exec_lib" pointer
  74. DOS     EQU     AEXEC-4                 * "dos.library" pointer
  75. STDIN   EQU     DOS-4                   * file handle for STDIN
  76. STDOUT  EQU     STDIN-4                 * file handle for STDOUT
  77. H.BASE  EQU     STDOUT-4                * base of heap
  78. H.SIZE  EQU     H.BASE-4                * size of heap
  79. WBSTAT  EQU     H.SIZE-2                * running from workbench?
  80. WBMSG   EQU     WBSTAT-4                * loc of WB message
  81. OURTSK  EQU     WBMSG-4                 * loc of our TCB
  82. AMIGA   EQU     -OURTSK                 * size of Amiga global storage
  83.  
  84. F77.RL  EQU     17408                   * size of "f77.rl"
  85. PCB     EQU     3348
  86. NO_OP   EQU     $4E71                   * hex of NOP instruction
  87.  
  88. * - from "exec_lib"
  89.  
  90. _LVOAlert         EQU     -108
  91. _LVOForbid        EQU     -132
  92. _LVOAllocMem      EQU     -198
  93. _LVOFreeMem       EQU     -210
  94. _LVOFindTask      EQU     -294
  95. _LVOWait          EQU     -318
  96. _LVOGetMsg        EQU     -372
  97. _LVOReplyMsg      EQU     -378
  98. _LVOWaitPort      EQU     -384
  99. _LVOOpenLibrary   EQU     -552
  100. _LVODebug         EQU     -114
  101.  
  102. EXEC.LIB          EQU     4               * pointer to "exec_lib"
  103.  
  104. * - from "dos.library"
  105.  
  106. _LVOOpen          EQU     -30
  107. _LVOClose         EQU     -36
  108. _LVORead          EQU     -42
  109. _LVOWrite         EQU     -48
  110. _LVOInput         EQU     -54
  111. _LVOOutput        EQU     -60
  112. _LVOCurrentDir    EQU     -126
  113. _LVOExit          EQU     -144
  114. _LVODelay         EQU     -198
  115.  
  116. *
  117. * - the following code is already in the source file:
  118. *
  119. *START: LEA     START(PC),A1            * load address of entry point
  120. *       MOVEA.L A1,A2
  121. *       ADDA.L  #OFFSET,A1              * pointer to main program
  122. *       ADDA.L  #OFFSET,A2              * pointer to end of data section
  123. *       MOVE.L  #HEAP,D1                * heap size
  124. *       MOVE.L  #RUN,D2                 * run-time library specification
  125. *
  126.         CLR.W   _WBStat
  127.         CLR.L   _WBenchMsg
  128.         JMP     S1(PC)
  129.         NOP
  130.         NOP
  131. S1:
  132.         MOVE.L  D2,-(A7)
  133.         MOVE.L  A0,_DosCmdBuf           * copy command line pointer
  134.         MOVE.L  A4,-(A7)                * stow original A4 safely away
  135.         MOVE.L  D0,_DosCmdLen           * copy command line length
  136.         MOVEA.L A1,A2                   * copy for global use
  137.         SUBA.L  A1,A1                   * find our own task
  138.         JMP     S2(PC)
  139.         NOP
  140.         NOP
  141. S2:
  142.         MOVE.W  #_LVOFindTask,D6
  143.         BSR     ECALL
  144.         MOVE.L  D0,A4
  145.         tst.l   pr_CLI(A4)
  146.         bne     from_Cli
  147. *
  148. * - open the "dos.library" and locate STDIN and STDOUT
  149. *
  150. fromWB:
  151.         move.w  #111,_WBStat
  152.         MOVEM.L D2/A2,-(A7)
  153.         MOVE.L  #1,_DosCmdLen           * make the run time library happy
  154.         BSR     DOSOPEN
  155.         lea     pr_MsgPort(A4),A0       * our process base
  156.         move.w  #_LVOWaitPort,D6
  157.         BSR     ECALL                   * wait for wbench message
  158.         JMP     S3(PC)
  159. LINKED:
  160.         NOP
  161.         NOP
  162.         NOP
  163.         NOP
  164.         NOP
  165.         NOP
  166.         NOP
  167. S3:
  168.         lea     pr_MsgPort(A4),A0
  169.         move.w  #_LVOGetMsg,D6          * get the message
  170.         BSR     ECALL
  171.         move.l  d0,_WBenchMsg           * save it so we can return it
  172.         move.l  D0,A2                   * get the first argument
  173.         Move.l  sm_ArgList(A2),D0
  174.         beq.s   docons
  175.  
  176. * - set the current directory to the same directory
  177.         move.l  D0,A0
  178.         move.l  wa_Lock(A0),d1
  179.         move.w  #_LVOCurrentDir,D6
  180.         BSR     DCALL
  181.  
  182. docons:
  183. *
  184. * - get the toolwindow argument
  185. *
  186.         move.l  sm_ToolWindow(A2),d1       * is there a default window?
  187.         bne.s   opnwndo                    * yes
  188.         lea     NIL(PC),A3                 * no default, so open NIL:
  189.         move.l  A3,D1
  190.         BSR     FILOPEN
  191.         bra.s   filhandl
  192. *
  193. * - open up the file
  194. *
  195. opnwndo:
  196.         BSR     FILOPEN
  197. *
  198. * - set the i/o descriptors
  199. *
  200. filhandl:
  201.         move.l  d0,_stdin
  202.         move.l  d0,_stdout
  203.         beq.s   domain
  204. *
  205. * - set the console task (so Open("*",mode) will work)
  206. *   waitmsg has left the task pointer in A4 for us
  207. *
  208.         lsl.l   #2,d0
  209.         move.l  d0,a0
  210.         move.l  fh_Type(a0),pr_ConsoleTask(A4)
  211. domain:
  212.         MOVEM.L (A7)+,D2/A2
  213. *        MOVE.L  _startkeep,A2
  214. *
  215. * - allocate the heap segment and establish global addresses
  216. *
  217. from_Cli:
  218.         MOVEA.L _DosCmdBuf,A3
  219.         MOVE.L  _DosCmdLen,D5
  220.         MOVE.L  #AMIGA+PCB,D0           * module size
  221.         MOVE.L  #NO_OP,D7               * find out if run time lib is linked  
  222.         CMP.W   LINKED+4,D7
  223.         BNE     S4
  224.         ADD.L   #F77.RL,D0              * if not, need space for it.
  225. S4:
  226.         MOVEQ   #0,D1                   * MEMF_FAST first, then MEMF_CHIP
  227.         MOVE.W  #_LVOAllocMem,D6
  228.         MOVE.L  D0,D4                   * save allocated size
  229.         BSR     ECALL
  230.         TST.L   D0                      * did the allocation succeed?
  231.         BEQ     ERROR                   *   no
  232.         MOVEA.L D0,A0                   * set pointer to base of heap
  233.         MOVE.L  A0,D3                   * save pointer for "f77.rl" load
  234.         MOVE.L  #NO_OP,D7               * find out if run time lib is linked  
  235.         CMP.W   LINKED+4,D7
  236.         BNE     S5
  237.         ADDA.L  #F77.RL,A0              * if not, allocate "f77.rl" area
  238. S5:
  239.         ADDA.L  #AMIGA,A0               * allocate global area
  240.         MOVE.L  D0,H.BASE(A0)           * save base of heap for .FREEMEM.
  241.         MOVE.L  D4,H.SIZE(A0)           * save size of heap for .FREEMEM.
  242.         MOVE.L  EXEC.LIB,AEXEC(A0)      * set pointer to "exec_lib"
  243.         MOVE.L  _stdin,STDIN(A0)        * pick up stdin and stdout from WB
  244.         MOVE.L  _stdout,STDOUT(A0)
  245.         MOVE.L  _DOSBase,DOS(A0)
  246.         MOVE.L  _WBenchMsg,WBMSG(A0)
  247.         MOVE.W  _WBStat,WBSTAT(A0)
  248.         MOVE.L  A4,OURTSK(A0)
  249.         MOVEA.L (A7)+,A4                *restore original A4
  250. *
  251. * - open the "dos.library" and locate STDIN and STDOUT
  252. *
  253.         TST.W   _WBStat                 * running from workbench?
  254.         BNE.S   BYPASS                  * yes..DOS already open
  255.         BSR     DOSOPEN                 * open DOS
  256.         MOVE.L  D0,DOS(A0)              * save pointer, error?
  257.         BNE.S   L1                      *   did open succeed?
  258. ERROR:  RTS                             *   no, fail silently (UNIX style)
  259.  
  260. L1:     MOVEQ   #_LVOInput,D6
  261.         BSR     DCALL
  262.         MOVE.L  D0,STDIN(A0)
  263.         MOVEQ   #_LVOOutput,D6
  264.         BSR     DCALL
  265.         MOVE.L  D0,STDOUT(A0)
  266. BYPASS:
  267. *
  268. * Now find out if the run time library is linked in.  We do this by testing
  269. * the location that is 4 bytes past the LINKED label.  If it contains the 
  270. * instruction NOP, which is what we put there, then the linker has not linked
  271. * in the run time library.  If the value is different, then the linker has
  272. * stepped on us, with the following code:
  273. *
  274. *       LEA     START(PC),A5
  275. *       ADDA.L  #OFFSET,A5
  276. *       JMP     (A5)
  277. *
  278. * In this case we branch to LINKED and execute the code we find there.  
  279. * Otherwise, we just fall through and find the run time library.
  280. *
  281.         MOVE.L  #NO_OP,D7        
  282.         CMP.W   LINKED+4,D7
  283.         BEQ     FNDLIB
  284.         MOVE.L  (A7)+,D2
  285.         BRA     LINKED
  286. *
  287. * - locate and load "f77.rl"
  288. *
  289. FNDLIB: 
  290.         LEA     F77LIB+6(PC),A6
  291.         MOVE.L  D2,D0                   * load run-time library specifier
  292.         LSL.L   #4,D0                   * calculate table offset
  293.         ADDA.W  D0,A6                   * index specified library
  294.         MOVE.L  A6,D1                   * "name"
  295.         move.l  #MODE_OLDFILE,D2
  296.         move.w  #_LVOOpen,D6
  297.         BSR     DCALL
  298.         MOVE.L  D0,D7                   * found in local library?
  299.         BNE.S   L2                      *   yes
  300.         SUBQ.L  #3,D1
  301.         BSR     DCALL
  302.         MOVE.L  D0,D7                   * found in current volume library?
  303.         BNE.S   L2                      *   yes
  304.         SUBQ.L  #3,D1
  305.         BSR     DCALL
  306.         MOVE.L  D0,D7                   * found in system volume library?
  307.         BEQ.S   L3                      *   no
  308. L2:     MOVEA.L D3,A5                   * set pointer to "f77.rl"
  309.         MOVE.L  D7,D1                   * "file"
  310.         MOVE.L  A5,D2                   * "buffer"
  311.         MOVE.L  #F77.RL,D3              * "length"
  312.         MOVEQ   #_LVORead,D6
  313.         BSR     DCALL                    * load the library
  314.         TST.L   D0                      * error?
  315.         BMI.S   L3                      *   yes
  316.         MOVE.L  D7,D1                   * "file"
  317.         MOVEQ   #_LVOClose,D6
  318.         BSR     DCALL                   * close the file
  319.         MOVE.L  (A7)+,D2                * run-time library specification
  320.         JMP     (A5)                    * transfer control to "f77.rl"
  321.  
  322. *
  323. * - "f77.rl" load failed: report error and quit
  324. *
  325.  
  326. L3:     MOVE.L  STDOUT(A0),D1           * "file"
  327.         LEA     ERRMSG(PC),A6
  328.         MOVE.L  A6,D2                   * "buffer"
  329.         MOVEQ   #30,D3                  * "length"
  330.         MOVEQ   #_LVOWrite,D6
  331.         BSR.S   DCALL
  332.         MOVE.L  DOS(A0),-(A7)           * save pointer to "dos.library"
  333.         BSR.S   DCALL
  334.         MOVEA.L H.BASE(A0),A1           * pointer to module to delete
  335.         MOVE.L  H.SIZE(A0),D0           * size of module to delete
  336.         MOVE.W  #_LVOFreeMem,D6
  337.         BSR.S   ECALL
  338.         MOVEA.L (A7)+,A6                * pointer to "dos.library"
  339.         MOVEQ   #10,D1                  * "something wrong"
  340.         JSR     _LVOExit(A6)
  341.  
  342.  
  343. *
  344. * - execute "exec_lib" call (offset passed in D6)
  345. *
  346.  
  347. ECALL:  MOVEM.L D1-D7/A0/A2/A3/A5,-(A7)
  348.         MOVEA.L EXEC.LIB,A6
  349.         JSR     0(A6,D6.W)
  350.         MOVEM.L (A7)+,D1-D7/A0/A2/A3/A5
  351.         RTS
  352.  
  353. *
  354. * - execute "dos.library" call (offset passed in D6)
  355. *
  356.  
  357. DCALL:  MOVEM.L D1-D7/A0/A2/A3/A5,-(A7)
  358.         MOVEA.L  _DOSBase,A6
  359.         JSR     0(A6,D6.W)
  360.         MOVEM.L (A7)+,D1-D7/A0/A2/A3/A5
  361.         RTS
  362.  
  363. DOSOPEN:
  364.         LEA     DOSLIB(PC),A1           * "dos.library"
  365.         MOVEQ   #0,D0                   * any version will do
  366.         MOVE.W  #_LVOOpenLibrary,D6
  367.         BSR     ECALL        
  368.         MOVE.L  D0,_DOSBase             * save pointer
  369.         RTS
  370.  
  371. FILOPEN:
  372.         MOVE.L  D2,-(A7)
  373.         move.l  #MODE_OLDFILE,D2
  374.         move.w  #_LVOOpen,D6
  375.         BSR     DCALL
  376.         MOVE.L  (A7)+,D2
  377.         rts
  378.  
  379. DOSLIB: DC.B    'dos.library'
  380.         DC.B    0
  381.  
  382. F77LIB: DC.B    'sys:l/f77.rl'
  383.         DC.L    0
  384.  
  385. HDWLIB: DC.B    'sys:l/hdw.rl'
  386.         DC.L    0
  387.  
  388. M81LIB: DC.B    'sys:l/m81.rl'
  389.         DC.B    0
  390.  
  391. ERRMSG: DC.B    '?cannot load run-time library'
  392.         DC.B    10,0
  393.  
  394. NIL:    DC.B    'NIL:'
  395.         DC.B    0
  396. _WBStat:     DC.W  0
  397. _stdin:      DC.L  0
  398. _stdout:     DC.L  0
  399. _errno:      DC.L  0
  400. _WBenchMsg:  DC.L  0
  401. _DosCmdBuf:  DC.L  0
  402. _DosCmdLen:  DC.L  0
  403. _DOSBase:    DC.L  0
  404.