prt0.as 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. $Id$
  3. */
  4. /*
  5. This file is part of the Free Pascal run time library.
  6. Copyright (c) 2004 by Karoly Balogh for Genesi Sarl
  7. Thanks for Martin 'MarK' Kuchinka <[email protected]>
  8. for his help.
  9. See the file COPYING.FPC, included in this distribution,
  10. for details about the copyright.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY;without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. */
  15. .section ".text"
  16. .globl _start
  17. .align 4
  18. _start:
  19. mflr 0
  20. stw 0,4(1)
  21. stwu 1,-16(1)
  22. /* Get ExecBase */
  23. lwz 3,4(0)
  24. lis 4,_ExecBase@ha
  25. stw 3,_ExecBase@l(4)
  26. /* Allocating new stack */
  27. lis 4,__stklen@ha
  28. lwz 3,__stklen@l(4)
  29. stw 3,0(2)
  30. lwz 3,4(0)
  31. stw 3,56(2)
  32. lwz 3,100(2)
  33. mtlr 3
  34. li 3,-858 /* AllocTaskPooled */
  35. blrl
  36. cmplwi cr0,3,0
  37. beq cr0,_exit
  38. lis 4,stackArea@ha
  39. stw 3,stackArea@l(4)
  40. /* Setting up stackSwap struct */
  41. lis 4,stackSwap@ha
  42. addi 4,4,stackSwap@l
  43. stw 3,0(4)
  44. lis 5,__stklen@ha
  45. lwz 6,__stklen@l(5)
  46. add 3,3,6
  47. stw 3,4(4)
  48. stw 3,8(4)
  49. /* Calling main function with the new stack */
  50. stw 4,32(2)
  51. lis 4,_initproc@ha
  52. addi 4,4,_initproc@l
  53. stw 4,36(2)
  54. li 3,0
  55. stw 3,40(2)
  56. lwz 4,100(2)
  57. mtlr 4
  58. li 3,-804 /* NewPPCStackSwap */
  59. blrl
  60. /* Setting return value */
  61. lis 4,returnValue@ha
  62. lwz 3,returnValue@l(4)
  63. _exit:
  64. addi 1,1,16
  65. lwz 0,4(1)
  66. mtlr 0
  67. blr
  68. _initproc:
  69. mflr 0
  70. stw 0,4(1)
  71. stwu 1,-128(1)
  72. stw 13,52(1)
  73. stw 14,56(1)
  74. stw 15,60(1)
  75. stw 16,64(1)
  76. stw 17,68(1)
  77. stw 18,72(1)
  78. stw 19,76(1)
  79. stw 20,80(1)
  80. stw 21,84(1)
  81. stw 22,88(1)
  82. stw 23,92(1)
  83. stw 24,96(1)
  84. stw 25,100(1)
  85. stw 26,104(1)
  86. stw 27,108(1)
  87. stw 28,112(1)
  88. stw 29,116(1)
  89. stw 30,120(1)
  90. stw 31,124(1)
  91. /* Save Stackpointer */
  92. lis 4,OriginalStkPtr@ha
  93. stw 1,OriginalStkPtr@l(4)
  94. bl PASCALMAIN
  95. .globl _haltproc
  96. _haltproc:
  97. /* Restore Stackpointer */
  98. lis 4,OriginalStkPtr@ha
  99. lwz 1,OriginalStkPtr@l(4)
  100. /* Store return value */
  101. lis 4,returnValue@ha
  102. stw 3,returnValue@l(4)
  103. lwz 13,52(1)
  104. lwz 14,56(1)
  105. lwz 15,60(1)
  106. lwz 16,64(1)
  107. lwz 17,68(1)
  108. lwz 18,72(1)
  109. lwz 19,76(1)
  110. lwz 20,80(1)
  111. lwz 21,84(1)
  112. lwz 22,88(1)
  113. lwz 23,92(1)
  114. lwz 24,96(1)
  115. lwz 25,100(1)
  116. lwz 26,104(1)
  117. lwz 27,108(1)
  118. lwz 28,112(1)
  119. lwz 29,116(1)
  120. lwz 30,120(1)
  121. lwz 31,124(1)
  122. addi 1,1,128
  123. lwz 0,4(1)
  124. mtlr 0
  125. blr
  126. .globl _ExecBase
  127. .globl SysBase
  128. .align 4
  129. SysBase:
  130. _ExecBase:
  131. .long 0
  132. .globl OriginalStkPtr
  133. .align 4
  134. OriginalStkPtr:
  135. .long 0
  136. .globl OriginalLinkRegister
  137. .align 4
  138. OriginalLinkRegister:
  139. .long 0
  140. .globl returnValue
  141. .align 4
  142. returnValue:
  143. .long 0
  144. .globl stackArea
  145. .align 4
  146. stackArea:
  147. .long 0
  148. .globl stackSwap
  149. .align 4
  150. stackSwap:
  151. .long 0
  152. .long 0
  153. .long 0
  154. /* This is needed to be a proper MOS ABox executable */
  155. /* This symbol _MUST NOT_ be stripped out from the executable */
  156. /* or else... */
  157. .globl __abox__
  158. .type __abox__,@object
  159. .size __abox__,4
  160. __abox__:
  161. .long 1
  162. /*
  163. $Log$
  164. Revision 1.12 2005-02-03 19:09:11 karoly
  165. * reworked startup code:
  166. - now uses AllocTaskPooled
  167. - check for unsuccessful stack allocation
  168. Revision 1.11 2004/06/06 22:02:22 karoly
  169. * hopefully fixed stack problems causing hits
  170. Revision 1.10 2004/06/06 12:51:06 karoly
  171. * changelog fixed
  172. Revision 1.9 2004/06/06 12:47:57 karoly
  173. * some cleanup, comments added
  174. Revision 1.8 2004/06/05 19:25:12 karoly
  175. + reworked to support resizing of stack
  176. Revision 1.7 2004/05/13 01:15:42 karoly
  177. - removed comment about argc/argv, made it work another way
  178. Revision 1.6 2004/05/01 15:08:57 karoly
  179. + haltproc added, saving/restoring stackpointer added
  180. Revision 1.5 2004/04/21 03:24:55 karoly
  181. * rewritten to be similar to GCC startup code
  182. Revision 1.4 2004/04/09 04:02:43 karoly
  183. * abox id symbol fixed
  184. Revision 1.3 2004/04/09 02:58:15 karoly
  185. * typo fixed.
  186. Revision 1.2 2004/04/09 02:54:25 karoly
  187. * execbase loading oops fixed.
  188. Revision 1.1 2004/03/16 10:29:22 karoly
  189. * first implementation of some startup code for MOS
  190. */