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

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