home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / startup / rcrt0.s < prev   
Encoding:
Text File  |  1993-12-12  |  3.8 KB  |  216 lines

  1. | residentfähiger baserelativer Startup_code für Gcc V2.3.3
  2. | (c) by Gerhard Müller Fri Jun  4 23:39:41 1993
  3. | No real bugs known
  4. |
  5. | rearly bases on the original startup-Code provided by m.wild.
  6. |
  7. | Important: don't use any DOS-funktion here ! (First get WBStartup_Msg!)
  8. |
  9. | Problem: geta4()
  10. | I really don't know how to implement it with multiple starts
  11. |
  12. | You should use the non-resident startup-code if you need it !
  13. |
  14. | Sun Dec 12 16:35:56 1993 GM: Bug fix: don't use tstl ax, as these command
  15. |                                       doesn't exist on a 68000 !
  16.  
  17.     .text
  18.  
  19.     | retten der Register a0/d0
  20.  
  21.     movel    4:W,a6
  22.     movel    d0,d7
  23.     movel    a0,a5
  24.  
  25.  
  26.     | wieviel Data+BSS ? merken in D5
  27.  
  28.      movel    #___data_size,d0
  29.     addl    #___bss_size,d0
  30.     movel    d0,d5
  31.  
  32.     | dafür Speicher holen (Länge: d0)
  33.  
  34.     moveq    #0,d1
  35.           jsr a6@(-0xc6)    |AllocMem
  36.  
  37.     | Kein Speicher ? -> ENDE ! (20)
  38.  
  39.     movel    d0,d6
  40.     jeq    err_exit
  41.  
  42.     | Speicher umkopieren via CopyMem
  43.  
  44.     lea    ___a4_init,a0
  45.     subl    #0x7ffe,a0
  46.     movel    d6,a1
  47.     movel    d5,d0
  48.     jsr    a6@(-0x270)
  49.  
  50.         | Nun die Relocs korrigieren.... Source siehe Original-File
  51.  
  52.         | d2=a4=origmem, d3= databbs_size a2=new mem
  53.     lea    ___a4_init,a0
  54.     subl    #0x7ffe,a0
  55.     movel    a0,d2
  56.     movel    d5,d3
  57.     movel    d6,a2
  58.  
  59.     movel    #___datadata_relocs,a0
  60.     tstl    a0@                      | if relocs[0] > 0
  61.     jle    Relocs_Ende
  62.     movel    a0@+,d1                  | num_rel = relocs[0], relocs++
  63.     moveq    #0,d0                    | for(i=0;
  64.     cmpl    d0,d1                    | i < num_rel
  65.     jle    Relocs_Ende
  66.     subl    a2,d2                    | origmem - mem
  67. Reloc_Schleife:
  68.     movel    a0@+,a1                  |       ...   relocs++
  69.     subl    d2,a1@(a2:l)             | *(long *)(mem + *relocs) -= origmem - mem;
  70.     addql    #1,d0                    | i++
  71.     cmpl    d0,d1
  72.     jgt Reloc_Schleife
  73. Relocs_Ende:
  74.  
  75.     | und a4 endgültig setzen
  76.  
  77.     movel    d6,d0
  78.     addl    #0x7ffe,d0
  79.     movel    d0,a4
  80.  
  81.     | SysBase und StackPtr initialisieren
  82.  
  83.     movel    4,a4@(_SysBase:W)
  84.     movel    a7,a4@(StackPtr_for_exit:W)
  85.  
  86.     # Variablen retten
  87.  
  88.     movel    d5,a4@(MemLen:W)
  89.     movel   d6,a4@(MemAdr:W)
  90.  
  91.     # dos.library öffnen
  92.  
  93.     moveq    #0,d0
  94.     lea    DOSName,a1
  95.     jsr    a6@(-0x228)
  96.     movel    d0,a4@(_DOSBase:W)
  97.  
  98.     movel    d0,a6
  99.     jsr     a6@(-0x36)        | Input()
  100.     movel    d0,a4@(_stdin:W)
  101.     jsr    a6@(-0x3c)              | Output()
  102.     movel    d0,a4@(_stdout:W)
  103.  
  104.     # main aufrufen
  105.  
  106.     movel    d7,sp@-
  107.     movel    a5,sp@-
  108.     jsr __main
  109.     movel    d0,sp@-
  110.     jsr        _exit    | kehrt niemals zurück ! Nur wichtig für Stack.
  111.  
  112.     .globl __exit
  113. __exit:
  114.     | dos.library schließen
  115.  
  116.     movel    4,a6
  117.  
  118.     movel    a4@(_DOSBase:W),d0
  119.     beq    __exit4
  120.     movel    d0,a1
  121.     jsr    a6@(-0x19e)    | CloseLibrary(a1)
  122.  
  123. __exit4:
  124.     | Speicher-Handling: Alles in Register holen
  125.  
  126.     movel    a4@(MemLen:W),d6
  127.     movel    a4@(MemAdr:W),a3
  128.  
  129.     movel    a4@(StackPtr_for_exit:W),a2
  130.  
  131.     | WB-Message ?
  132.  
  133.     movel    a4@(_WBenchMsg:W),a5
  134.  
  135.     | nun aber erst Speicher freigeben
  136.  
  137.     movel    a3,a1
  138.     movel    d6,d0
  139.     jsr    a6@(-0xd2)    | FreeMem
  140.  
  141.     | Weiter mit WB-Msg. Gibt es sie ?
  142.  
  143.     movel    a5,d0
  144.     tstl    d0
  145.     jeq    __exit2
  146.  
  147. __exit5:
  148.     jsr    a6@(-0x84)    | Forbid
  149.     movel    a5,a1
  150.     jsr    a6@(-0x17a)    | ReplyMsg
  151. __exit2:
  152.     movel    sp@(4),d0
  153. __exit3:
  154.     movel    a2,a7
  155.     rts
  156.  
  157.  
  158. err_exit:
  159.     | handles WB-Startup if necessary
  160.  
  161.     movel 4:W,a3        | ExecBase
  162.     movel a3@(276),a2    | SysBase->ThisTask
  163.     tstl a2@(172)        | if (! me->pr_CLI)
  164.     jne err_exit_no_wb
  165.  
  166.  
  167.     | WaitPort (& me->pr_MsgPort);
  168.  
  169.     addw #92,a2
  170.     movel a3,a6
  171.     movel a2,a0
  172.     jsr a6@(-0x180)
  173.  
  174.  
  175.     | WBenchMsg = (struct WBStartup *) GetMsg (& me->pr_MsgPort);
  176.  
  177.     movel a2,a0
  178.     jsr a6@(-0x174)
  179.     movel    d0,a5
  180.  
  181.     jsr    a6@(-0x84)    | Forbid
  182.     movel    a5,a1
  183.     jsr    a6@(-0x17a)    | ReplyMsg
  184.     rts
  185.  
  186.  
  187. err_exit_no_wb:
  188.     moveq    #20,d0
  189.     rts
  190.  
  191. DOSName:    .ascii "dos.library\0"
  192.     .even
  193.  
  194.     .data
  195.     .even
  196. StackPtr_for_exit:    .long 0
  197. MemAdr:    .long 0
  198. MemLen:    .long 0
  199. .globl    _SysBase
  200. _SysBase:    .long 0
  201. .globl    _WBenchMsg
  202. _WBenchMsg:
  203.     .long 0
  204.  
  205.     | this here avoids linker errors
  206. .globl __exit_dummy_ref
  207. .data
  208.     .even
  209. __exit_dummy_ref:
  210.     .long __exit_dummy_decl
  211. .comm __exit_dummy_decl,4
  212.  
  213. .comm _DOSBase,4
  214. .comm _stdin,4
  215. .comm _stdout,4
  216.