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

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