crt0.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* crt0.S - Startup code for the Sparc64. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2009 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/machine/kernel.h>
  21. #include <grub/offsets.h>
  22. .text
  23. .align 4
  24. .globl _start
  25. _start:
  26. ba codestart
  27. mov %o4, %o0
  28. .org GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
  29. VARIABLE(grub_total_module_size)
  30. .word 0
  31. codestart:
  32. /* Copy the modules past the end of the kernel image.
  33. * They are currently sitting in the BSS.
  34. */
  35. sethi %hi(__bss_start + GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN - 1), %o2
  36. or %o2, %lo(__bss_start + GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN - 1), %o2
  37. srl %o2, GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN, %o2
  38. sll %o2, GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN, %o2
  39. sethi %hi(_end + GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN - 1), %o3
  40. or %o3, %lo(_end + GRUB_KERNEL_SPARC64_IEEE1275_MOD_ALIGN - 1), %o3
  41. srl %o3, GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN, %o3
  42. sll %o3, GRUB_KERNEL_SPARC64_IEEE1275_LOG_MOD_ALIGN, %o3
  43. sethi %hi(grub_total_module_size), %o4
  44. lduw [%o4 + %lo(grub_total_module_size)], %o4
  45. add %o2, %o4, %o2
  46. add %o3, %o4, %o3
  47. /* Save ieee1275 stack for future use by booter. */
  48. mov %o6, %o1
  49. /* Our future stack. */
  50. sethi %hi(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5
  51. or %o5, %lo(GRUB_KERNEL_MACHINE_STACK_SIZE), %o5
  52. add %o3, %o5, %o6
  53. and %o6, ~0xff, %o6
  54. sub %o6, 2047, %o6
  55. sub %o2, 4, %o2
  56. sub %o3, 4, %o3
  57. 1: lduw [%o2], %o5
  58. stw %o5, [%o3]
  59. subcc %o4, 4, %o4
  60. sub %o2, 4, %o2
  61. bne,pt %icc, 1b
  62. sub %o3, 4, %o3
  63. /* Now it's safe to clear out the BSS. */
  64. sethi %hi(__bss_start), %o2
  65. or %o2, %lo(__bss_start), %o2
  66. 1: stb %g0, [%o2]
  67. add %o2, 1, %o2
  68. and %o2, 7, %o3
  69. brnz %o3, 1b
  70. nop
  71. sethi %hi(_end - 1), %o3
  72. or %o3, %lo(_end - 1), %o3
  73. srl %o3, 3, %o3
  74. sll %o3, 3, %o3
  75. 1: stx %g0, [%o2]
  76. add %o2, 8, %o2
  77. cmp %o2, %o3
  78. blt,pt %xcc, 1b
  79. nop
  80. sethi %hi(_end), %o3
  81. or %o3, %lo(_end), %o3
  82. 1: stb %g0, [%o2]
  83. add %o2, 1, %o2
  84. cmp %o2, %o3
  85. blt,pt %xcc, 1b
  86. nop
  87. sethi %hi(grub_ieee1275_original_stack), %o2
  88. stx %o1, [%o2 + %lo(grub_ieee1275_original_stack)]
  89. sethi %hi(grub_ieee1275_entry_fn), %o2
  90. call grub_main
  91. stx %o0, [%o2 + %lo(grub_ieee1275_entry_fn)]
  92. 1: ba,a 1b
  93. nop