home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / startup / ncrt0.S < prev    next >
Encoding:
Text File  |  1995-03-04  |  2.2 KB  |  131 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,___commandline
  26.         movel    d0,___commandlen
  27.  
  28.         movel    sp,___SaveSP
  29.         movel    4:W,a6
  30.         movel    a6,_SysBase
  31.  
  32.         subal    a1,a1
  33.         jsr    a6@(_LVOFindTask:W)
  34.         movel    d0,a3
  35.         tstl    a3@(pr_CLI:W)
  36.         bne    fromCLI
  37.  
  38. | wb start - get wbmsg
  39.  
  40. fromWB:        lea    a3@(pr_MsgPort:W),a0
  41.         jsr    a6@(_LVOWaitPort:W)
  42.         lea    a3@(pr_MsgPort:W),a0
  43.         jsr    a6@(_LVOGetMsg:W)
  44.         movel    d0,__WBenchMsg
  45.  
  46. | execute all init functions then call main
  47.  
  48. fromCLI:    lea    ___INIT_LIST__+4,a2
  49.         moveql    #-1,d2
  50.         jbsr    callfuncs
  51.  
  52.         movel    ___env,sp@-
  53.         movel    ___argv,sp@-
  54.         movel    ___argc,sp@-
  55.         jbsr    _main
  56.         movel    d0,sp@(4:W)
  57.  
  58. | exit() entry - execute all exit functions, reply wbmsg
  59.  
  60. __exit:        lea    ___EXIT_LIST__+4,a2
  61.         moveql    #0,d2
  62.         jbsr    callfuncs
  63.  
  64.         movel    _SysBase,a6
  65.  
  66.         movel    __WBenchMsg,d2
  67.         beq    todos
  68.         jsr    a6@(_LVOForbid:W)
  69.         movel    d2,a1
  70.         jsr    a6@(_LVOReplyMsg:W)
  71.  
  72. | leave - get return val, restore stackptr
  73.  
  74. todos:        movel    sp@(4:W),d0
  75.         movel    ___SaveSP,sp
  76.         rts
  77.  
  78. | call all functions in the NULL terminated list pointed to by a2
  79. | d2 ascending or descending priority mode
  80.  
  81. callfuncs:    lea    cleanupflag,a5
  82.         movel    a2,a3
  83.         moveql    #0,d3
  84.         jra    oldpri
  85. stabloop:    movel    a3@+,d4
  86.         movel    a5@,d5
  87.         cmpl    d4,d5
  88.         jne    notnow
  89.         movel    d0,a0
  90.         jsr    a0@
  91. notnow:        eorl    d2,d4
  92.         eorl    d2,d5
  93.         cmpl    d5,d4
  94.         jcc    oldpri
  95.         cmpl    d3,d4
  96.         jls    oldpri
  97.         movel    d4,d3
  98. oldpri:        movel    a3@+,d0
  99.         jne    stabloop
  100.         eorl    d2,d3
  101.         movel    d3,a5@
  102.         cmpl    d2,d3
  103.         jne    callfuncs
  104.  
  105. | geta4() doesn´t do anything, but enables you to use
  106. | one source for both code models
  107.  
  108. _geta4:        rts
  109.  
  110. | redirection of _exit
  111.  
  112.         .stabs    "_exit",11,0,0,0
  113.         .stabs    "__exit",1,0,0,0
  114.  
  115. | data area
  116.  
  117.         .data
  118.  
  119.         .long ___nocommandline
  120.         .long ___initlibraries
  121.  
  122. .comm        _SysBase,4
  123. .comm        ___SaveSP,4
  124. .comm        __WBenchMsg,4
  125. .comm        ___commandline,4
  126. .comm        ___commandlen,4
  127. .comm        ___argc,4
  128. .comm        ___argv,4
  129. .comm        ___env,4
  130. .lcomm        cleanupflag,4
  131.