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