startup.S 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /* startup.S - Startup code for the PowerPC. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2003,2004,2005,2007,2008 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB 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. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/symbol.h>
  20. #include <grub/cpu/kernel.h>
  21. .text
  22. .align 2
  23. .globl _start, grub_code_start
  24. _start:
  25. grub_code_start:
  26. b LOCAL(codestart)
  27. . = _start + GRUB_KERNEL_CPU_PREFIX
  28. VARIABLE(grub_prefix)
  29. /* to be filled by grub-mkelfimage */
  30. /*
  31. * Leave some breathing room for the prefix.
  32. */
  33. . = _start + GRUB_KERNEL_CPU_DATA_END
  34. LOCAL(codestart):
  35. #ifdef APPLE_CC
  36. li r2, 0
  37. li r13, 0
  38. /* Stage1 won't zero BSS for us. In other cases, why not do it again? */
  39. lis r6, hi16(grub_bss_start - 4)
  40. ori r6, r6, lo16(grub_bss_start - 4)
  41. lis r7, hi16(grub_bss_end - 4)
  42. ori r7, r7, lo16(grub_bss_end - 4)
  43. subf r7, r6, r7
  44. srwi r7, r7, 2 /* We store 4 bytes at a time. */
  45. mtctr r7
  46. 2: stwu r2, 4(r6) /* We know r2 is already 0 from above. */
  47. bdnz 2b
  48. /* Store r5 in grub_ieee1275_entry_fn. */
  49. lis r9, ha16(grub_ieee1275_entry_fn)
  50. stw r5, lo16(grub_ieee1275_entry_fn)(r9)
  51. bl grub_main
  52. 1: b 1b
  53. #else
  54. li 2, 0
  55. li 13, 0
  56. /* Stage1 won't zero BSS for us. In other cases, why not do it again? */
  57. lis 6, (grub_bss_start - 4)@h
  58. ori 6, 6, (grub_bss_start - 4)@l
  59. lis 7, (grub_bss_end - 4)@h
  60. ori 7, 7, (grub_bss_end - 4)@l
  61. subf 7, 6, 7
  62. srwi 7, 7, 2 /* We store 4 bytes at a time. */
  63. mtctr 7
  64. 2: stwu 2, 4(6) /* We know r2 is already 0 from above. */
  65. bdnz 2b
  66. /* Store r5 in grub_ieee1275_entry_fn. */
  67. lis 9, grub_ieee1275_entry_fn@ha
  68. stw 5, grub_ieee1275_entry_fn@l(9)
  69. bl grub_main
  70. 1: b 1b
  71. #endif
  72. #if defined(__GNUC__) && (__GNUC__ > 3) && (__GNUC__ > 4 || __GNUC_MINOR__ >= 4)
  73. /* Routines for saving integer registers, called by the compiler. */
  74. /* Called with r11 pointing to the stack header word of the caller of the */
  75. /* function, just beyond the end of the integer save area. */
  76. GRUB_EXPORT_START
  77. GRUB_EXPORT(_savegpr_14)
  78. GRUB_EXPORT(_savegpr_15)
  79. GRUB_EXPORT(_savegpr_16)
  80. GRUB_EXPORT(_savegpr_17)
  81. GRUB_EXPORT(_savegpr_18)
  82. GRUB_EXPORT(_savegpr_19)
  83. GRUB_EXPORT(_savegpr_20)
  84. GRUB_EXPORT(_savegpr_21)
  85. GRUB_EXPORT(_savegpr_22)
  86. GRUB_EXPORT(_savegpr_23)
  87. GRUB_EXPORT(_savegpr_24)
  88. GRUB_EXPORT(_savegpr_25)
  89. GRUB_EXPORT(_savegpr_26)
  90. GRUB_EXPORT(_savegpr_27)
  91. GRUB_EXPORT(_savegpr_28)
  92. GRUB_EXPORT(_savegpr_29)
  93. GRUB_EXPORT(_savegpr_30)
  94. GRUB_EXPORT(_savegpr_31)
  95. GRUB_EXPORT(_restgpr_14)
  96. GRUB_EXPORT(_restgpr_15)
  97. GRUB_EXPORT(_restgpr_16)
  98. GRUB_EXPORT(_restgpr_17)
  99. GRUB_EXPORT(_restgpr_18)
  100. GRUB_EXPORT(_restgpr_19)
  101. GRUB_EXPORT(_restgpr_20)
  102. GRUB_EXPORT(_restgpr_21)
  103. GRUB_EXPORT(_restgpr_22)
  104. GRUB_EXPORT(_restgpr_23)
  105. GRUB_EXPORT(_restgpr_24)
  106. GRUB_EXPORT(_restgpr_25)
  107. GRUB_EXPORT(_restgpr_26)
  108. GRUB_EXPORT(_restgpr_27)
  109. GRUB_EXPORT(_restgpr_28)
  110. GRUB_EXPORT(_restgpr_29)
  111. GRUB_EXPORT(_restgpr_30)
  112. GRUB_EXPORT(_restgpr_31)
  113. GRUB_EXPORT(_restgpr_14_x)
  114. GRUB_EXPORT(_restgpr_15_x)
  115. GRUB_EXPORT(_restgpr_16_x)
  116. GRUB_EXPORT(_restgpr_17_x)
  117. GRUB_EXPORT(_restgpr_18_x)
  118. GRUB_EXPORT(_restgpr_19_x)
  119. GRUB_EXPORT(_restgpr_20_x)
  120. GRUB_EXPORT(_restgpr_21_x)
  121. GRUB_EXPORT(_restgpr_22_x)
  122. GRUB_EXPORT(_restgpr_23_x)
  123. GRUB_EXPORT(_restgpr_24_x)
  124. GRUB_EXPORT(_restgpr_25_x)
  125. GRUB_EXPORT(_restgpr_26_x)
  126. GRUB_EXPORT(_restgpr_27_x)
  127. GRUB_EXPORT(_restgpr_28_x)
  128. GRUB_EXPORT(_restgpr_29_x)
  129. GRUB_EXPORT(_restgpr_30_x)
  130. GRUB_EXPORT(_restgpr_31_x)
  131. GRUB_EXPORT_END
  132. FUNCTION(_savegpr_14)
  133. stw 14,-72(11) /* save gp registers */
  134. FUNCTION(_savegpr_15)
  135. stw 15,-68(11)
  136. FUNCTION(_savegpr_16)
  137. stw 16,-64(11)
  138. FUNCTION(_savegpr_17)
  139. stw 17,-60(11)
  140. FUNCTION(_savegpr_18)
  141. stw 18,-56(11)
  142. FUNCTION(_savegpr_19)
  143. stw 19,-52(11)
  144. FUNCTION(_savegpr_20)
  145. stw 20,-48(11)
  146. FUNCTION(_savegpr_21)
  147. stw 21,-44(11)
  148. FUNCTION(_savegpr_22)
  149. stw 22,-40(11)
  150. FUNCTION(_savegpr_23)
  151. stw 23,-36(11)
  152. FUNCTION(_savegpr_24)
  153. stw 24,-32(11)
  154. FUNCTION(_savegpr_25)
  155. stw 25,-28(11)
  156. FUNCTION(_savegpr_26)
  157. stw 26,-24(11)
  158. FUNCTION(_savegpr_27)
  159. stw 27,-20(11)
  160. FUNCTION(_savegpr_28)
  161. stw 28,-16(11)
  162. FUNCTION(_savegpr_29)
  163. stw 29,-12(11)
  164. FUNCTION(_savegpr_30)
  165. stw 30,-8(11)
  166. FUNCTION(_savegpr_31)
  167. stw 31,-4(11)
  168. blr
  169. /* Routines for restoring integer registers, called by the compiler. */
  170. /* Called with r11 pointing to the stack header word of the caller of the */
  171. /* function, just beyond the end of the integer restore area. */
  172. FUNCTION(_restgpr_14)
  173. lwz 14,-72(11) /* restore gp registers */
  174. FUNCTION(_restgpr_15)
  175. lwz 15,-68(11)
  176. FUNCTION(_restgpr_16)
  177. lwz 16,-64(11)
  178. FUNCTION(_restgpr_17)
  179. lwz 17,-60(11)
  180. FUNCTION(_restgpr_18)
  181. lwz 18,-56(11)
  182. FUNCTION(_restgpr_19)
  183. lwz 19,-52(11)
  184. FUNCTION(_restgpr_20)
  185. lwz 20,-48(11)
  186. FUNCTION(_restgpr_21)
  187. lwz 21,-44(11)
  188. FUNCTION(_restgpr_22)
  189. lwz 22,-40(11)
  190. FUNCTION(_restgpr_23)
  191. lwz 23,-36(11)
  192. FUNCTION(_restgpr_24)
  193. lwz 24,-32(11)
  194. FUNCTION(_restgpr_25)
  195. lwz 25,-28(11)
  196. FUNCTION(_restgpr_26)
  197. lwz 26,-24(11)
  198. FUNCTION(_restgpr_27)
  199. lwz 27,-20(11)
  200. FUNCTION(_restgpr_28)
  201. lwz 28,-16(11)
  202. FUNCTION(_restgpr_29)
  203. lwz 29,-12(11)
  204. FUNCTION(_restgpr_30)
  205. lwz 30,-8(11)
  206. FUNCTION(_restgpr_31)
  207. lwz 31,-4(11)
  208. blr
  209. /* Routines for restoring integer registers, called by the compiler. */
  210. /* Called with r11 pointing to the stack header word of the caller of the */
  211. /* function, just beyond the end of the integer restore area. */
  212. FUNCTION(_restgpr_14_x)
  213. lwz 14,-72(11) /* restore gp registers */
  214. FUNCTION(_restgpr_15_x)
  215. lwz 15,-68(11)
  216. FUNCTION(_restgpr_16_x)
  217. lwz 16,-64(11)
  218. FUNCTION(_restgpr_17_x)
  219. lwz 17,-60(11)
  220. FUNCTION(_restgpr_18_x)
  221. lwz 18,-56(11)
  222. FUNCTION(_restgpr_19_x)
  223. lwz 19,-52(11)
  224. FUNCTION(_restgpr_20_x)
  225. lwz 20,-48(11)
  226. FUNCTION(_restgpr_21_x)
  227. lwz 21,-44(11)
  228. FUNCTION(_restgpr_22_x)
  229. lwz 22,-40(11)
  230. FUNCTION(_restgpr_23_x)
  231. lwz 23,-36(11)
  232. FUNCTION(_restgpr_24_x)
  233. lwz 24,-32(11)
  234. FUNCTION(_restgpr_25_x)
  235. lwz 25,-28(11)
  236. FUNCTION(_restgpr_26_x)
  237. lwz 26,-24(11)
  238. FUNCTION(_restgpr_27_x)
  239. lwz 27,-20(11)
  240. FUNCTION(_restgpr_28_x)
  241. lwz 28,-16(11)
  242. FUNCTION(_restgpr_29_x)
  243. lwz 29,-12(11)
  244. FUNCTION(_restgpr_30_x)
  245. lwz 30,-8(11)
  246. FUNCTION(_restgpr_31_x)
  247. lwz 0,4(11)
  248. lwz 31,-4(11)
  249. mtlr 0
  250. mr 1,11
  251. blr
  252. #endif