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 / nbcrt0.S < prev    next >
Encoding:
Text File  |  1994-12-12  |  2.3 KB  |  142 lines

  1. | baserelative startup code for gcc v2.3.3+
  2. | (c) by M.Fleischer and G.Nikl Wed Apr 13 17:45 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.         jbsr    _geta4
  28.  
  29.         movel    #___bss_size,d1
  30.         beqs    nobss
  31.         lea    a4@(__edata:W),a1
  32. clrbss:        clrl    a1@+
  33.         subql    #4,d1
  34.         bnes    clrbss
  35.  
  36. nobss:        movel    sp,a4@(___SaveSP:W)
  37.         movel    4:W,a6
  38.         movel    a6,a4@(_SysBase:W)
  39.  
  40.         subal    a1,a1
  41.         jsr    a6@(_LVOFindTask:W)
  42.         movel    d0,a3
  43.         tstl    a3@(pr_CLI:W)
  44.         bne    fromCLI
  45.  
  46. | wb start - get wbmsg
  47.  
  48. fromWB:        lea    a3@(pr_MsgPort:W),a0
  49.         jsr    a6@(_LVOWaitPort:W)
  50.         lea    a3@(pr_MsgPort:W),a0
  51.         jsr    a6@(_LVOGetMsg:W)
  52.         movel    d0,a4@(__WBenchMsg:W)
  53.         moveq    #0,d3
  54.  
  55. fromCLI:    movel    d3,a4@(___commandline:W)
  56.  
  57. | execute all init functions then call main
  58.  
  59.         lea    a4@(___INIT_LIST__:W),a2
  60.         addqw    #4,a2
  61.         moveql    #-1,d2
  62.         jbsr    callfuncs
  63.  
  64.         movel    a4@(___argv:W),sp@-
  65.         movel    a4@(___argc:W),sp@-
  66.         jbsr    _main
  67.         movel    d0,sp@(4:W)
  68.  
  69. | exit() entry - execute all exit functions, reply wbmsg
  70.  
  71. __exit:        lea    a4@(___EXIT_LIST__:W),a2
  72.         addqw    #4,a2
  73.         moveql    #0,d2
  74.         jbsr    callfuncs
  75.  
  76.         movel    a4@(_SysBase:W),a6
  77.  
  78.         movel    a4@(__WBenchMsg:W),d2
  79.         beq    todos
  80.         jsr    a6@(_LVOForbid:W)
  81.         movel    d2,a1
  82.         jsr    a6@(_LVOReplyMsg:W)
  83.  
  84. | leave - get return val, restore stackptr
  85.  
  86. todos:        movel    sp@(4:W),d0
  87.         movel    a4@(___SaveSP:W),sp
  88.         rts
  89.  
  90. | call all functions in the NULL terminated list pointed to by a2
  91. | d2 ascending or descending priotity mode
  92.  
  93. callfuncs:    lea    a4@(cleanupflag:W),a5
  94.         movel    a2,a3
  95.         moveql    #0,d3
  96.         jra    oldpri
  97. stabloop:    movel    a3@+,d4
  98.         movel    a5@,d5
  99.         cmpl    d4,d5
  100.         jne    notnow
  101.         movel    d0,a0
  102.         jsr    a0@
  103. notnow:        eorl    d2,d4
  104.         eorl    d2,d5
  105.         cmpl    d5,d4
  106.         jcc    oldpri
  107.         cmpl    d3,d4
  108.         jls    oldpri
  109.         movel    d4,d3
  110. oldpri:        movel    a3@+,d0
  111.         jne    stabloop
  112.         eorl    d2,d3
  113.         movel    d3,a5@
  114.         cmpl    d2,d3
  115.         jne    callfuncs
  116.         rts
  117.  
  118. | get baseptr
  119.  
  120. _geta4:        lea    ___a4_init,a4
  121.         rts
  122.  
  123. | redirection of _exit
  124.  
  125.         .stabs    "_exit",11,0,0,0
  126.         .stabs    "__exit",1,0,0,0
  127.  
  128. | data area
  129.  
  130.         .data
  131.  
  132.         .long ___nocommandline
  133.         .long ___initlibraries
  134.  
  135. .comm        _SysBase,4
  136. .comm        ___SaveSP,4
  137. .comm        __WBenchMsg,4
  138. .comm        ___commandline,4
  139. .comm        ___argc,4
  140. .comm        ___argv,4
  141. .lcomm        cleanupflag,4
  142.