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 / nrcrt0.S < prev   
Encoding:
Text File  |  1994-12-12  |  3.1 KB  |  178 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.  
  36.         movel    4:W,a6
  37.  
  38.         subal    a1,a1
  39.         jsr    a6@(_LVOFindTask:W)
  40.         movel    d0,a3
  41.         tstl    a3@(pr_CLI:W)
  42.         subal    a2,a2
  43.         bne    fromCLI
  44.  
  45. | wb start - get our message
  46.  
  47. fromWB:        lea    a3@(pr_MsgPort:W),a0
  48.         jsr    a6@(_LVOWaitPort:W)
  49.         lea    a3@(pr_MsgPort:W),a0
  50.         jsr    a6@(_LVOGetMsg:W)
  51.         movel    d0,a2
  52.         moveq    #0,d3
  53.  
  54. | resident setup - allocate memory and relocate
  55.  
  56. fromCLI:    movql    #ERROR_NO_FREE_STORE,d7
  57.         movel    #___data_size,d4
  58.         movel    #___bss_size,d2
  59.         addl    d4,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    d4,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    d2,a4@(___MemLen:W)
  88.  
  89. | call main() - push args onto stack
  90.  
  91.         lea    a4@(___INIT_LIST__:W),a2
  92.         addqw    #4,a2
  93.         moveql    #-1,d2
  94.         jbsr    callfuncs
  95.  
  96.         movel    a4@(___argv:W),sp@-
  97.         movel    a4@(___argc:W),sp@-
  98.         jbsr    _main
  99.         movel    d0,sp@(4:W)
  100.  
  101. | exit() entry - get return val, restore stackptr
  102.  
  103. __exit:        lea    a4@(___EXIT_LIST__:W),a2
  104.         addqw    #4,a2
  105.         moveql    #0,d2
  106.         jbsr    callfuncs
  107.  
  108.         movel    sp@(4:W),d7
  109.         movel    a4@(___SaveSP:W),sp
  110.  
  111. | prepare cleanup - setup regs, free resident memory
  112.  
  113.         movel    a4@(_SysBase:W),a6
  114.  
  115.         movel    a4@(__WBenchMsg:W),a2
  116.         movel    a4@(___MemLen:W),d0
  117.         lea    a4@(-0x7ffe:W),a1
  118.         jsr    a6@(_LVOFreeMem:W)
  119.  
  120. | cleanup - reply wbmsg and exit
  121.  
  122. cleanup:    movel    a2,d0
  123.         beqs    todos
  124.         jsr    a6@(_LVOForbid:W)
  125.         movel    a2,a1
  126.         jsr    a6@(_LVOReplyMsg:W)
  127. todos:        movel    d7,d0
  128.         rts
  129.  
  130. | call all functions in the NULL terminated list pointed to by a2
  131. | d2 ascending or descending priotity mode
  132.  
  133. callfuncs:    lea    a4@(cleanupflag:W),a5
  134.         movel    a2,a3
  135.         moveql    #0,d3
  136.         jra    oldpri
  137. stabloop:    movel    a3@+,d4
  138.         movel    a5@,d5
  139.         cmpl    d4,d5
  140.         jne    notnow
  141.         movel    d0,a0
  142.         jsr    a0@
  143. notnow:        eorl    d2,d4
  144.         eorl    d2,d5
  145.         cmpl    d5,d4
  146.         jcc    oldpri
  147.         cmpl    d3,d4
  148.         jls    oldpri
  149.         movel    d4,d3
  150. oldpri:        movel    a3@+,d0
  151.         jne    stabloop
  152.         eorl    d2,d3
  153.         movel    d3,a5@
  154.         cmpl    d2,d3
  155.         jne    callfuncs
  156.         rts
  157.  
  158. | redirection of _exit
  159.  
  160.         .stabs    "_exit",11,0,0,0
  161.         .stabs    "__exit",1,0,0,0
  162.  
  163. | data area
  164.  
  165.         .data
  166.  
  167.         .long ___nocommandline
  168.         .long ___initlibraries
  169.  
  170. .comm        _SysBase,4
  171. .comm        ___SaveSP,4
  172. .comm        __WBenchMsg,4
  173. .comm        ___commandline,4
  174. .comm        ___MemLen,4
  175. .comm        ___argc,4
  176. .comm        ___argv,4
  177. .lcomm        cleanupflag,4
  178.