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 / nrcrt0.S < prev   
Encoding:
Text File  |  1995-03-04  |  3.2 KB  |  182 lines

  1. | residentable baserelative startup code for gcc v2.3.3+
  2. | (c) by M.Fleischer and G.Nikl Wed Apr 13 17:46 1994
  3. | No bugs known
  4. |
  5. | Problem: geta4()
  6. | I really donĀ“t know how to implement it with multiple starts
  7. |
  8. | You should use the non-resident startup-code if you need it !
  9.  
  10. | some specific defines
  11.  
  12. _LVOForbid    =    -132
  13. _LVOAllocMem    =    -198
  14. _LVOFindTask    =    -294
  15. _LVOFreeMem    =    -210
  16. _LVOGetMsg    =    -372
  17. _LVOReplyMsg    =    -378
  18. _LVOWaitPort    =    -384
  19. _LVOCopyMemQuick =    -630
  20.  
  21. pr_MsgPort    =      92
  22. pr_CLI        =     172
  23.  
  24. ERROR_NO_FREE_STORE =     103
  25.  
  26. | public symbols
  27.  
  28.         .globl    __exit
  29.  
  30.         .text
  31.  
  32. | first entry - check for cli or wb start
  33.  
  34. start:        movel    a0,d3
  35.         movel    d0,d4
  36.  
  37.         movel    4:W,a6
  38.  
  39.         subal    a1,a1
  40.         jsr    a6@(_LVOFindTask:W)
  41.         movel    d0,a3
  42.         tstl    a3@(pr_CLI:W)
  43.         subal    a2,a2
  44.         bne    fromCLI
  45.  
  46. | wb start - get our message
  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,a2
  53.  
  54. | resident setup - allocate memory and relocate
  55.  
  56. fromCLI:    movql    #ERROR_NO_FREE_STORE,d7
  57.         movel    #___data_size,d5
  58.         movel    #___bss_size,d2
  59.         addl    d5,d2
  60.         movel    d2,d0
  61.         movql    #1,d1
  62.         swap    d1
  63.         jsr    a6@(_LVOAllocMem:W)
  64.         movel    d0,a4
  65.         movel    a4,d0
  66.         beq    cleanup
  67.         lea    ___a4_init-0x7ffe,a5
  68.         movel    d5,d0
  69.         movel    a5,a0
  70.         movel    a4,a1
  71.         jsr    a6@(_LVOCopyMemQuick:W)
  72.         lea    ___datadata_relocs,a0
  73.         movel    a0@+,d0
  74.         beq    no_reloc
  75.         movel    a5,d1
  76.         subl    a4,d1
  77. do_reloc:    movel    a0@+,a1
  78.         subl    d1,a4@(a1:l)
  79.         subql    #1,d0
  80.         bne    do_reloc
  81. no_reloc:    lea    a4@(0x7ffe:W),a4
  82.  
  83.         movel    sp,a4@(___SaveSP:W)
  84.         movel    a6,a4@(_SysBase:W)
  85.         movel    a2,a4@(__WBenchMsg:W)
  86.         movel    d3,a4@(___commandline:W)
  87.         movel    d4,a4@(___commandlen:W)
  88.         movel    d2,a4@(___MemLen:W)
  89.  
  90. | call main() - push args onto stack
  91.  
  92.         lea    a4@(___INIT_LIST__:W),a2
  93.         addqw    #4,a2
  94.         moveql    #-1,d2
  95.         jbsr    callfuncs
  96.  
  97.         movel    a4@(___env:W),sp@-
  98.         movel    a4@(___argv:W),sp@-
  99.         movel    a4@(___argc:W),sp@-
  100.         jbsr    _main
  101.         movel    d0,sp@(4:W)
  102.  
  103. | exit() entry - get return val, restore stackptr
  104.  
  105. __exit:        lea    a4@(___EXIT_LIST__:W),a2
  106.         addqw    #4,a2
  107.         moveql    #0,d2
  108.         jbsr    callfuncs
  109.  
  110.         movel    sp@(4:W),d7
  111.         movel    a4@(___SaveSP:W),sp
  112.  
  113. | prepare cleanup - setup regs, free resident memory
  114.  
  115.         movel    a4@(_SysBase:W),a6
  116.  
  117.         movel    a4@(__WBenchMsg:W),a2
  118.         movel    a4@(___MemLen:W),d0
  119.         lea    a4@(-0x7ffe:W),a1
  120.         jsr    a6@(_LVOFreeMem:W)
  121.  
  122. | cleanup - reply wbmsg and exit
  123.  
  124. cleanup:    movel    a2,d0
  125.         beqs    todos
  126.         jsr    a6@(_LVOForbid:W)
  127.         movel    a2,a1
  128.         jsr    a6@(_LVOReplyMsg:W)
  129. todos:        movel    d7,d0
  130.         rts
  131.  
  132. | call all functions in the NULL terminated list pointed to by a2
  133. | d2 ascending or descending priority mode
  134.  
  135. callfuncs:    lea    a4@(cleanupflag:W),a5
  136.         movel    a2,a3
  137.         moveql    #0,d3
  138.         jra    oldpri
  139. stabloop:    movel    a3@+,d4
  140.         movel    a5@,d5
  141.         cmpl    d4,d5
  142.         jne    notnow
  143.         movel    d0,a0
  144.         jsr    a0@
  145. notnow:        eorl    d2,d4
  146.         eorl    d2,d5
  147.         cmpl    d5,d4
  148.         jcc    oldpri
  149.         cmpl    d3,d4
  150.         jls    oldpri
  151.         movel    d4,d3
  152. oldpri:        movel    a3@+,d0
  153.         jne    stabloop
  154.         eorl    d2,d3
  155.         movel    d3,a5@
  156.         cmpl    d2,d3
  157.         jne    callfuncs
  158.         rts
  159.  
  160. | redirection of _exit
  161.  
  162.         .stabs    "_exit",11,0,0,0
  163.         .stabs    "__exit",1,0,0,0
  164.  
  165. | data area
  166.  
  167.         .data
  168.  
  169.         .long ___nocommandline
  170.         .long ___initlibraries
  171.  
  172. .comm        _SysBase,4
  173. .comm        ___SaveSP,4
  174. .comm        __WBenchMsg,4
  175. .comm        ___commandline,4
  176. .comm        ___commandlen,4
  177. .comm        ___MemLen,4
  178. .comm        ___argc,4
  179. .comm        ___argv,4
  180. .comm        ___env,4
  181. .lcomm        cleanupflag,4
  182.