startup.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* startup.S - Startup code for the MIPS. */
  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/offsets.h>
  21. #include <grub/machine/memory.h>
  22. #include <grub/machine/kernel.h>
  23. #include <grub/offsets.h>
  24. #include <grub/mips/asm.h>
  25. #define BASE_ADDR 8
  26. .globl __start, _start, start
  27. .set noreorder
  28. .set nomacro
  29. __start:
  30. _start:
  31. start:
  32. .extern __bss_start
  33. .extern _end
  34. bal cont
  35. nop
  36. .org GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
  37. VARIABLE(grub_total_modules_size)
  38. .long 0
  39. VARIABLE (grub_arch_busclock)
  40. .long 0
  41. VARIABLE (grub_arch_cpuclock)
  42. .long 0
  43. VARIABLE (grub_arch_memsize)
  44. .long 0
  45. VARIABLE (grub_arch_highmemsize)
  46. .long 0
  47. #ifdef GRUB_MACHINE_MIPS_LOONGSON
  48. VARIABLE (grub_arch_machine)
  49. .long GRUB_ARCH_MACHINE_FULOONG2F
  50. #endif
  51. cont:
  52. /* Save our base. */
  53. move $s0, $ra
  54. #ifdef GRUB_MACHINE_MIPS_QEMU_MIPS
  55. lui $t1, %hi(grub_arch_busclock)
  56. addiu $t1, %lo(grub_arch_busclock)
  57. sw $s4, 8($t1)
  58. #endif
  59. #ifdef GRUB_MACHINE_MIPS_LOONGSON
  60. lui $t1, %hi(grub_arch_busclock)
  61. addiu $t1, %lo(grub_arch_busclock)
  62. sw $s2, 0($t1)
  63. sw $s3, 4($t1)
  64. sw $s4, 8($t1)
  65. sw $s5, 12($t1)
  66. sw $s7, 16($t1)
  67. #endif
  68. /* Move the modules out of BSS. */
  69. lui $t2, %hi(__bss_start)
  70. addiu $t2, %lo(__bss_start)
  71. lui $t1, %hi(_end)
  72. addiu $t1, %lo(_end)
  73. addiu $t1, (GRUB_KERNEL_MACHINE_MOD_ALIGN - 1)
  74. li $t3, (GRUB_KERNEL_MACHINE_MOD_ALIGN - 1)
  75. nor $t3, $t3, $0
  76. and $t1, $t1, $t3
  77. lw $t3, (GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE - BASE_ADDR)($s0)
  78. /* Backward copy. */
  79. add $t1, $t1, $t3
  80. add $t2, $t2, $t3
  81. addiu $t1, $t1, -1
  82. addiu $t2, $t2, -1
  83. /* $t2 is source. $t1 is destination. $t3 is size. */
  84. modulesmovcont:
  85. beq $t3, $0, modulesmovdone
  86. nop
  87. lb GRUB_ASM_T4, 0($t2)
  88. sb GRUB_ASM_T4, 0($t1)
  89. addiu $t2, $t2, -1
  90. addiu $t1, $t1, -1
  91. b modulesmovcont
  92. addiu $t3, $t3, -1
  93. modulesmovdone:
  94. /* Clean BSS. */
  95. lui $t1, %hi(__bss_start)
  96. addiu $t1, $t1, %lo(__bss_start)
  97. lui $t2, %hi(_end)
  98. addiu $t2, $t2, %lo(_end)
  99. bsscont:
  100. sb $0,0($t1)
  101. addiu $t1, $t1, 1
  102. sltu $t3, $t1, $t2
  103. bne $t3, $0, bsscont
  104. nop
  105. lui $t9, %hi(grub_main)
  106. addiu $t9, %lo(grub_main)
  107. lui $sp, %hi(GRUB_MACHINE_MEMORY_STACK_HIGH)
  108. jr $t9
  109. addiu $sp, $sp, %lo(GRUB_MACHINE_MEMORY_STACK_HIGH)