home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Utilities / Extract / TinyStart.s < prev   
Encoding:
Text File  |  1995-06-01  |  5.0 KB  |  155 lines

  1. *************************************************************************
  2. *                                    *
  3. *              Tiny SAS/C Startup Code            *
  4. *              -----------------------            *
  5. *                                    *
  6. *                -------------------                *
  7. *                   Version 1.00                *
  8. *                -------------------                *
  9. *                 Copyright © 1995                *
  10. *                  Nick Christie.                *
  11. *                39 St Georges Drive                *
  12. *                Bransgore BH23 8EZ                *
  13. *                  Great Britain.                *
  14. *                All Rights Reserved                *
  15. *                -------------------                *
  16. *                                    *
  17. * Tab size = 8.                                *
  18. *                                    *
  19. * Version 1.0    (12/07/94)                        *
  20. * ========================                        *
  21. * Startup for C using a4 base-relative data and registerized parameters    *
  22. * callable from WB or shell. Adapted from SAS/C 5.10 startup "c.a".    *
  23. * Sets up _SysBase and _DOSBase, opens/closes dos.library, initializes    *
  24. * initializes _WBenchMsg. Does not allow stack checking, or set up    *
  25. * __ProgramName, oserr, ONBREAK, etc.                    *
  26. * Calls @main (@ == register args) as:                    *
  27. *    LONG rc [d0] = @main(char *cmdline [a0], ULONG cmdlen [d0])    *
  28. * Can't use exit(), as it needs other stuff.                *
  29. *                                    *
  30. * Assembles under GenAm3 with:                        *
  31. *    genam INCDIR <whatever> ALINK TinyStart.s            *
  32. * Should assemble easily under other assemblers, me thinks.        *
  33. *                                    *
  34. *************************************************************************
  35.  
  36. *************************************************************************
  37. ******************************  INCLUDES  *******************************
  38. *************************************************************************
  39.  
  40.         INCLUDE        "exec/exec.i"
  41.         INCLUDE        "exec/funcdef.i"
  42.         INCLUDE        "exec/exec_lib.i"
  43.         INCLUDE        "dos/dosextens.i"
  44.  
  45. *************************************************************************
  46. *****************************  REFERENCES  ******************************
  47. *************************************************************************
  48.  
  49.         XREF        _LinkerDB    ; linker defined base value
  50.         XREF        __BSSBAS    ; linker defined base of BSS
  51.         XREF        __BSSLEN    ; linker defined length of BSS
  52.  
  53.         XREF        @main        ; name of C routine to start
  54.  
  55.         XDEF        _SysBase    ; exec.library base
  56.         XDEF        _DOSBase    ; dos.library base
  57.         XDEF        __WBenchMsg    ; Workbench Startup Msg
  58.  
  59. *************************************************************************
  60. *****************************  DEFINITIONS  *****************************
  61. *************************************************************************
  62.  
  63. ABSEXECBASE    EQU        4
  64.  
  65. *************************************************************************
  66. ********************************  START  ********************************
  67. *************************************************************************
  68. * Called from shell with cmd line info, from WB with nothing.
  69. *
  70. * In:    a0 = ptr to cmd line (if shell)
  71. *    d0 = len of cmd line (if shell)
  72. * Out:    d0 = return code (if shell)
  73. *
  74. *************************************************************************
  75.  
  76.         SECTION        TEXT,CODE
  77.  
  78. Start:        movem.l        d1-d6/a0-a6,-(a7)
  79.  
  80.         move.l        a0,a2            ; save command pointer
  81.         move.l        d0,d2            ;  and command length
  82.         lea.l        _LinkerDB,a4        ; load data base reg
  83.         move.l        ABSEXECBASE.w,a6
  84.  
  85.         lea.l        __BSSBAS,a3        ; get base of BSS seg
  86.         moveq.l        #0,d1
  87.         move.l        #__BSSLEN,d0        ; len of BSS in longs
  88.         bra.s        S_ClrBSS2
  89. S_ClrBSS1:    move.l        d1,(a3)+        ; clear BSS segment
  90. S_ClrBSS2:    dbra        d0,S_ClrBSS1
  91.  
  92.         move.l        a6,_SysBase(a4)        ; save SysBase
  93.         clr.l        __WBenchMsg(a4)        ; clr WB msg ptr
  94.  
  95.         moveq.l        #0,d0            ; clear any pending
  96.         move.l        #$3000,d1        ;   signals
  97.         jsr        _LVOSetSignal(a6)
  98.  
  99.         lea.l        DOSName(pc),a1        ; attempt to open
  100.         moveq.l        #0,d0            ;  DOS library
  101.         jsr        _LVOOpenLibrary(a6)
  102.         move.l        d0,_DOSBase(a4)
  103.         bne.s        S_DOSOpen
  104.  
  105.         moveq.l        #100,d2            ; if fail, return
  106.         bra.s        S_Return        ;  error level 100
  107.  
  108. S_DOSOpen:    move.l        ThisTask(a6),a3        ; ptr to my process
  109.         tst.l        pr_CLI(a3)        ; called from WB ?
  110.         bne.s        S_GoMain        ; no...
  111.  
  112.         lea.l        pr_MsgPort(a3),a0    ; now wait for and
  113.         jsr        _LVOWaitPort(a6)    ;  get the WB startup
  114.         lea.l        pr_MsgPort(a3),a0    ;   message...
  115.         jsr        _LVOGetMsg(a6)
  116.         move.l        d0,__WBenchMsg(a4)    ; save ptr to WB msg,
  117.         movea.l        d0,a2            ;  also into a2
  118.         moveq.l        #0,d2            ; cmdlen = 0 for WB
  119.  
  120. S_GoMain:    movea.l        a2,a0            ; move cmdlen and
  121.         move.l        d2,d0            ;  cmdline into a0/d0
  122.         jsr        @main(pc)        ; call C program
  123.  
  124.         move.l        d0,d2            ; save return code
  125.         movea.l        _SysBase(a4),a6        ; load execbase
  126.  
  127.         tst.l        __WBenchMsg(a4)        ; came from WB ?
  128.         beq.s        S_CloseDOS        ; nope...
  129.                             ; yes...reply the WB msg
  130.         jsr        _LVOForbid(a6)        ; but Forbid() first so
  131.         movea.l        __WBenchMsg(a4),a1    ; WB doesn't UnLoadSeg()
  132.         jsr        _LVOReplyMsg(a6)    ;  us before we're done
  133.  
  134. S_CloseDOS:    movea.l        _DOSBase(a4),a1        ; close dos library
  135.         jsr        _LVOCloseLibrary(a6)
  136.  
  137. S_Return:    move.l        d2,d0            ; retrieve return code
  138.         movem.l        (a7)+,d1-d6/a0-a6
  139.         rts
  140.  
  141. DOSName:    dc.b        'dos.library',0
  142.  
  143. *************************************************************************
  144. ********************************  DATA  *********************************
  145. *************************************************************************
  146.  
  147.         SECTION        __MERGED,BSS
  148.  
  149. _SysBase:    ds.l        1
  150. _DOSBase:    ds.l        1
  151. __WBenchMsg:    ds.l        1
  152.  
  153.         END
  154.  
  155.