home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk399.lzh / CCLib / GCC / crt0_no_fp.asm < prev    next >
Assembly Source File  |  1990-11-02  |  7KB  |  320 lines

  1. *crt0_no_fp.asm
  2. *   Copyright (C) 1990 Paul Gittings.
  3. *
  4. * This file is part of aMIGA gARGANTUAN c cOMPILER (agcc).
  5. *
  6. * agcc is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 1, or (at your option)
  9. * any later version.
  10. *
  11. * agcc 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
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with agcc; see the file COPYING.  If not, write to
  18. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. *
  21. *    A startup/__main routine for use with agcc and CCLib.library
  22. *    ctr0_no_fp.o should be used when an application does not use
  23. *    floating point.
  24. *    ctr0.o should be used if floating point is required.
  25. *
  26. *    The following libraries are loaded:
  27. *        Dos.library
  28. *        CCLib.library
  29. *    
  30. *
  31. *    Paul Gittings    21/2/1990
  32. *    ACSnet          paulg@tplrd.tpl.oz
  33. *    snail        172 Union St.
  34. *            Erskineville 2043
  35. *            NSW
  36. *            Australia
  37. *
  38. ******* Included Files *************************************************
  39.  
  40.  
  41. ;    INCLUDE "exec/types.i"
  42.  
  43.  
  44. ;    IFND EXEC_ABLES_I
  45. ;    INCLUDE "exec/ables.i"
  46. ;    ENDC
  47.     
  48. FORBID    MACRO
  49.     IFC    '\1',''
  50.     ADDQ.B    #1,TDNestCnt(A6)
  51.     ENDC
  52.     IFNC    '\1',''
  53.     MOVE.L    4,\1
  54.     ADDQ.B    #1,TDNestCnt(\1)
  55.     ENDC
  56.     ENDM
  57.  
  58. ;    IFND EXEC_EXECBASE_I
  59. ;    INCLUDE "exec/execbase.i"
  60. ;    ENDC
  61.  
  62. ThisTask    EQU    $114
  63. TDNestCnt    EQU    $127
  64.  
  65. ;    IFND LIBRARIES_DOS_I
  66. ;    INCLUDE "libraries/dos.i"
  67. ;    ENDC
  68.  
  69. ;    IFND LIBRARIES_DOESEXTENS_I
  70. ;    INCLUDE "libraries/dosextens.i"
  71. ;    ENDC
  72.  
  73. pr_CLI        EQU    $0ac
  74. pr_MsgPort    EQU    $05c
  75.  
  76. ;
  77. ;       Offsets into CClib user data
  78. ;
  79. ud_argc        EQU     96
  80. ud_argv        EQU    100
  81.  
  82. ******* Imported *******************************************************
  83.  
  84.     xref    _main            ; C code entry point
  85.  
  86. ;    cclib routines.
  87.  
  88.     xref    _ClearSTDIO
  89.     xref    _SetupSTDIO
  90.     xref    _GetSTDIO
  91.  
  92. callsys macro
  93.     xref    _LVO\1
  94.     jsr    _LVO\1(a6)
  95.     endm
  96.  
  97. ******* Exported *******************************************************
  98.  
  99.     xdef    _SysBase
  100.     xdef    _DOSBase
  101.     xdef    _CCLibBase
  102.  
  103.     xdef    _errno
  104.     xdef    _stdin
  105.     xdef    _stdout
  106.     xdef    _stderr
  107.     xdef    __math
  108.     xdef    _blocksize
  109.     xdef    _exit_fcn
  110.     xdef    _type
  111.  
  112.     xdef    _exit            ; standard C exit function
  113.     xdef    __exit
  114.  
  115. ************************************************************************
  116. *
  117. *    Standard Program Entry Point
  118. *
  119. *    If called from CLI then a0 will point to a buffer containing the
  120. *    command line but not including the command name. Also, d0 will
  121. *    contain the length of this line.
  122. *
  123. *
  124. ;
  125. ;a3 - frame pointer
  126. ;a4 - ThisTask
  127. dosCmdLen    equr    d6
  128. dosCmdBuf    equr    d5
  129. ;
  130. startup:    move.l    d0,dosCmdLen
  131.         move.l    a0,dosCmdBuf
  132.         lea.l    ss,a3        ; set up "frame pointer"
  133.         clr.l    (a3)+        ; _errno
  134.         clr.l    (a3)+        ; _exit_fcn
  135.         move.l    sp,(a3)+    ; initialSP
  136.  
  137.     ;------ get Exec's library base pointer:
  138.         move.l    4,a6        ; get _AbsExecBase
  139.         move.l    a6,(a3)+    ; _SysBase
  140.  
  141.     ;------ Open the DOS library:
  142.  
  143.         clr.l    d0
  144.         lea.l    DOSName(pc),A1
  145.         callsys OpenLibrary
  146.         tst.l    d0
  147.         beq    bailout
  148.         move.l    d0,(a3)+    ; _DOSBase
  149.  
  150.         clr.l    (a3)+        ; _MathIeeeDoubBasBase
  151.  
  152.     ;------ Open CCLib library:
  153.  
  154.         clr.l    d0
  155.         lea.l    CCLibName(pc),a1
  156.         callsys    OpenLibrary
  157.         tst.l    d0
  158.         beq    bailout
  159.         move.l    d0,(a3)+    ; _CCLibBase
  160.  
  161.     ;------ get the address of our task
  162.         move.l    ThisTask(a6),a4
  163.  
  164.     ;------ were we started from the Workbench
  165.         tst.l    pr_CLI(A4)
  166.         beq.s    fromWorkbench
  167.  
  168.     ;------ No, then we were started by CLI.
  169.     ;------ so clear out workbench msg pointer
  170.         clr.l    (a3)+        ; returnMsg
  171.         bra.s    skipwbstartup
  172.  
  173. ;
  174. ;------- Do some Workbench specific startup work
  175. ;
  176.  
  177.     ;------ we are now set up.  wait for a message from our starter
  178. fromWorkbench:    ;[a4=ThisTask]
  179. nostartupmsg:
  180.         lea.l    pr_MsgPort(A4),a0    ; our process base
  181.         callsys WaitPort
  182.     ;------ Get the message and save in returnMsg
  183.         lea.l    pr_MsgPort(A4),a0    ; our process base
  184.         callsys GetMsg
  185.         tst.l    d0
  186.         beq.s    nostartupmsg    ; ROM kernal manual says we could
  187.                     ; get a signal but no msg...
  188.  
  189.         move.l    d0,(a3)+     ; returnMsg
  190.  
  191. skipwbstartup:
  192.         clr.l    (a3)+        ; _stdin
  193.         clr.l    (a3)+        ; _stdout
  194.         clr.l    (a3)+        ; _stderr
  195.         clr.l    (a3)+        ; _type
  196.         clr.l    (a3)        ; _blocksize
  197.         lea.l    ss,a3
  198. ;
  199. ;  SetupSTDIO(&stdin, &stdout, &stderr, &errno, &blocksize, &type,
  200. ;        MathIeeeDoubBasBase, dosCmdLen, dosCmdBuf, returnMsg,
  201. ;        _exit)
  202. ;
  203.  
  204.         pea    __exit
  205.         move.l    returnMsg-ss(a3),-(sp)
  206.         move.l    dosCmdBuf,-(SP)
  207.         move.l    dosCmdLen,-(SP)
  208.         move.l    UNUSED-ss(a3),-(sp)
  209.         pea    _type-ss(a3)
  210.         pea    _blocksize-ss(a3)
  211.         pea    _errno-ss(a3)
  212.         pea    _stderr-ss(a3)
  213.         pea    _stdout-ss(a3)
  214.         pea    _stdin-ss(a3)
  215.         jsr    _SetupSTDIO
  216.  
  217.         add.w    #44,sp
  218.         tst.l    d0
  219.         beq.s    bailout
  220.  
  221.     ;------ get pointer to the block of user data (ud) belonging to
  222.     ;------ this task.
  223.  
  224.         jsr    _GetSTDIO    ; put ud into d0
  225.         tst.l    d0
  226.         beq.s    bailout
  227.  
  228.     ;------ push argv and argc from the ud onto the stack
  229.     ;------ and call main()
  230.         move.l    d0,a1
  231.         move.l  ud_argv(a1),-(sp)    ; put ud->_argv onto stack
  232.         clr.l    d0
  233.         move.w    ud_argc(a1),d0    ; get ud->_argc and
  234.         move.l    d0,-(sp)    ; push to stack
  235.  
  236.         jsr _main        ; hand over to C main routine.
  237.  
  238.         clr.l    _errno        ; Successful return code
  239.         bra.s    exit2
  240.  
  241.     ;------ get here if something went wrong during startup.
  242. bailout:
  243.         move.l    #$DEADBEEF,_errno
  244.         bra.s    exit2
  245.  
  246. ************************************************************************
  247. *
  248. *    C Program exit(returncode) Function
  249. *
  250. *
  251. ; a1 - general
  252. ; a3 - Frame pointer
  253. ; a6 - Exec Base pointer
  254. _exit:
  255. __exit:
  256.         move.l    4(SP),_errno     ; save error code
  257. exit2:        lea.l    ss,a3         ; set "frame pointer" back up
  258.  
  259.     ;------ check for an exit function set up by call to atexit().
  260.     ;------ If there is one execute it.
  261.  
  262.         move.l    _exit_fcn-ss(a3),a1
  263.         cmp.l    #0,a1
  264.         beq.s    no_atexit_fcn
  265.         jsr    (a1)
  266.  
  267. no_atexit_fcn:
  268.         move.l    initialSP-ss(a3),SP    ; restore stack pointer
  269.  
  270.         move.l    4,a6
  271.  
  272.     ;------ If CCLib.library is open close it
  273.         move.l    _CCLibBase-ss(a3),a2
  274.         cmp.l    #0,a2
  275.         beq.s    no_CCLib
  276.     ;------ close all files free memory 
  277.         jsr _ClearSTDIO
  278.         move.l    a2,a1
  279.         callsys CloseLibrary
  280.  
  281. no_CCLib:
  282.     ;------ If DOS library is open close it
  283.         move.l    _DOSBase-ss(a3),a1
  284.         cmp.l    #0,a1
  285.         beq.s    exitToDOS
  286.         callsys CloseLibrary
  287.  
  288.     ;------ this rts sends us back to DOS:
  289. exitToDOS:
  290.         move.l    _errno-ss(a3),d0    ; save return code
  291.         rts
  292. ******* DATA ***********************************************************
  293.  
  294. DOSName:    dc.b 'dos.library',0
  295.         EVEN
  296. CCLibName:    dc.b 'CClib.library',0
  297.         EVEN
  298. __math        dc.w 0    ; Set to indicate MathIEEEDoubBas is not loaded.
  299.  
  300.         EVEN
  301.         BSS    b.crt0_no_fp
  302. ss            ; placemarker
  303. _errno        ds.l 1    ; error number from OS routines
  304. _exit_fcn    ds.l 1    ; exit function ptr. setup by call to atexit
  305. initialSP    ds.l 1    ; initial stack pointer
  306. _SysBase    ds.l 1    ; exec library base pointer
  307. _DOSBase    ds.l 1    ; dos library base pointer
  308. UNUSED        ds.l 1    ; 
  309. _CCLibBase    ds.l 1    ; CCLib library base pointer
  310. returnMsg    ds.l 1    ; Workbench message, or zero for CLI startup
  311. _stdin        ds.l 1    ;       STANDARD 
  312. _stdout     ds.l 1    ;            I/O FILE
  313. _stderr     ds.l 1    ;            POINTERS
  314. _type        ds.l 1
  315. _blocksize    ds.l 1    ; blocksize global variable
  316.  
  317.         END
  318.  
  319.  
  320.