home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / src / amiga / libnix-0.7-src.lha / libnix-0.7 / sources / startup / ncrt0.S < prev    next >
Encoding:
Text File  |  1994-12-12  |  2.1 KB  |  130 lines

  1. | not baserelative startup code for gcc v2.3.3+
  2. | (c) by M.Fleischer and G.Nikl Wed Apr 13 17:44 1994
  3. | No bugs known
  4.  
  5. | some specific defines
  6.  
  7. _LVOForbid    =    -132
  8. _LVOFindTask    =    -294
  9. _LVOGetMsg    =    -372
  10. _LVOReplyMsg    =    -378
  11. _LVOWaitPort    =    -384
  12.  
  13. pr_MsgPort    =      92
  14. pr_CLI        =     172
  15.  
  16. | public symbols
  17.  
  18.         .globl    __exit
  19.         .globl    _geta4
  20.  
  21.         .text
  22.  
  23. | first entry - init some vars, check for cli or wb start
  24.  
  25. start:        movel    a0,d3
  26.  
  27.         movel    sp,___SaveSP
  28.         movel    4:W,a6
  29.         movel    a6,_SysBase
  30.  
  31.         subal    a1,a1
  32.         jsr    a6@(_LVOFindTask:W)
  33.         movel    d0,a3
  34.         tstl    a3@(pr_CLI:W)
  35.         bne    fromCLI
  36.  
  37. | wb start - get wbmsg
  38.  
  39. fromWB:        lea    a3@(pr_MsgPort:W),a0
  40.         jsr    a6@(_LVOWaitPort:W)
  41.         lea    a3@(pr_MsgPort:W),a0
  42.         jsr    a6@(_LVOGetMsg:W)
  43.         movel    d0,__WBenchMsg
  44.         moveq    #0,d3
  45.  
  46. fromCLI:    movel    d3,___commandline
  47.  
  48. | execute all init functions then call main
  49.  
  50.         lea    ___INIT_LIST__+4,a2
  51.         moveql    #-1,d2
  52.         jbsr    callfuncs
  53.  
  54.         movel    ___argv,sp@-
  55.         movel    ___argc,sp@-
  56.         jbsr    _main
  57.         movel    d0,sp@(4:W)
  58.  
  59. | exit() entry - execute all exit functions, reply wbmsg
  60.  
  61. __exit:        lea    ___EXIT_LIST__+4,a2
  62.         moveql    #0,d2
  63.         jbsr    callfuncs
  64.  
  65.         movel    _SysBase,a6
  66.  
  67.         movel    __WBenchMsg,d2
  68.         beq    todos
  69.         jsr    a6@(_LVOForbid:W)
  70.         movel    d2,a1
  71.         jsr    a6@(_LVOReplyMsg:W)
  72.  
  73. | leave - get return val, restore stackptr
  74.  
  75. todos:        movel    sp@(4:W),d0
  76.         movel    ___SaveSP,sp
  77.         rts
  78.  
  79. | call all functions in the NULL terminated list pointed to by a2
  80. | d2 ascending or descending priotity mode
  81.  
  82. callfuncs:    lea    cleanupflag,a5
  83.         movel    a2,a3
  84.         moveql    #0,d3
  85.         jra    oldpri
  86. stabloop:    movel    a3@+,d4
  87.         movel    a5@,d5
  88.         cmpl    d4,d5
  89.         jne    notnow
  90.         movel    d0,a0
  91.         jsr    a0@
  92. notnow:        eorl    d2,d4
  93.         eorl    d2,d5
  94.         cmpl    d5,d4
  95.         jcc    oldpri
  96.         cmpl    d3,d4
  97.         jls    oldpri
  98.         movel    d4,d3
  99. oldpri:        movel    a3@+,d0
  100.         jne    stabloop
  101.         eorl    d2,d3
  102.         movel    d3,a5@
  103.         cmpl    d2,d3
  104.         jne    callfuncs
  105.  
  106. | geta4() doesn´t do anything, but enables you to use
  107. | one source for both code models
  108.  
  109. _geta4:        rts
  110.  
  111. | redirection of _exit
  112.  
  113.         .stabs    "_exit",11,0,0,0
  114.         .stabs    "__exit",1,0,0,0
  115.  
  116. | data area
  117.  
  118.         .data
  119.  
  120.         .long ___nocommandline
  121.         .long ___initlibraries
  122.  
  123. .comm        _SysBase,4
  124. .comm        ___SaveSP,4
  125. .comm        __WBenchMsg,4
  126. .comm        ___commandline,4
  127. .comm        ___argc,4
  128. .comm        ___argv,4
  129. .lcomm        cleanupflag,4
  130.