head.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 1995 Waldorf Electronics
  7. * Written by Ralf Baechle and Andreas Busse
  8. * Copyright (C) 1994 - 99, 2003, 06 Ralf Baechle
  9. * Copyright (C) 1996 Paul M. Antoine
  10. * Modified for DECStation and hence R3000 support by Paul M. Antoine
  11. * Further modifications by David S. Miller and Harald Koerfgen
  12. * Copyright (C) 1999 Silicon Graphics, Inc.
  13. * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  14. * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/threads.h>
  18. #include <asm/addrspace.h>
  19. #include <asm/asm.h>
  20. #include <asm/asmmacro.h>
  21. #include <asm/irqflags.h>
  22. #include <asm/regdef.h>
  23. #include <asm/mipsregs.h>
  24. #include <asm/stackframe.h>
  25. #include <kernel-entry-init.h>
  26. /*
  27. * For the moment disable interrupts, mark the kernel mode and
  28. * set ST0_KX so that the CPU does not spit fire when using
  29. * 64-bit addresses. A full initialization of the CPU's status
  30. * register is done later in per_cpu_trap_init().
  31. */
  32. .macro setup_c0_status set clr
  33. .set push
  34. mfc0 t0, CP0_STATUS
  35. or t0, ST0_CU0|\set|0x1f|\clr
  36. xor t0, 0x1f|\clr
  37. mtc0 t0, CP0_STATUS
  38. .set noreorder
  39. sll zero,3 # ehb
  40. .set pop
  41. .endm
  42. .macro setup_c0_status_pri
  43. #ifdef CONFIG_64BIT
  44. setup_c0_status ST0_KX 0
  45. #else
  46. setup_c0_status 0 0
  47. #endif
  48. .endm
  49. .macro setup_c0_status_sec
  50. #ifdef CONFIG_64BIT
  51. setup_c0_status ST0_KX ST0_BEV
  52. #else
  53. setup_c0_status 0 ST0_BEV
  54. #endif
  55. .endm
  56. #ifndef CONFIG_NO_EXCEPT_FILL
  57. /*
  58. * Reserved space for exception handlers.
  59. * Necessary for machines which link their kernels at KSEG0.
  60. */
  61. .fill 0x400
  62. #endif
  63. EXPORT(_stext)
  64. #ifdef CONFIG_BOOT_RAW
  65. /*
  66. * Give us a fighting chance of running if execution beings at the
  67. * kernel load address. This is needed because this platform does
  68. * not have a ELF loader yet.
  69. */
  70. FEXPORT(__kernel_entry)
  71. j kernel_entry
  72. #endif /* CONFIG_BOOT_RAW */
  73. __REF
  74. NESTED(kernel_entry, 16, sp) # kernel entry point
  75. kernel_entry_setup # cpu specific setup
  76. setup_c0_status_pri
  77. /* We might not get launched at the address the kernel is linked to,
  78. so we jump there. */
  79. PTR_LA t0, 0f
  80. jr t0
  81. 0:
  82. #ifdef CONFIG_USE_OF
  83. #if defined(CONFIG_MIPS_RAW_APPENDED_DTB) || \
  84. defined(CONFIG_MIPS_ELF_APPENDED_DTB)
  85. PTR_LA t2, __appended_dtb
  86. #ifdef CONFIG_CPU_BIG_ENDIAN
  87. li t1, 0xd00dfeed
  88. #else /* !CONFIG_CPU_BIG_ENDIAN */
  89. li t1, 0xedfe0dd0
  90. #endif /* !CONFIG_CPU_BIG_ENDIAN */
  91. lw t0, (t2)
  92. beq t0, t1, dtb_found
  93. #endif /* CONFIG_MIPS_RAW_APPENDED_DTB || CONFIG_MIPS_ELF_APPENDED_DTB */
  94. li t1, -2
  95. move t2, a1
  96. beq a0, t1, dtb_found
  97. li t2, 0
  98. dtb_found:
  99. #endif /* CONFIG_USE_OF */
  100. PTR_LA t0, __bss_start # clear .bss
  101. LONG_S zero, (t0)
  102. PTR_LA t1, __bss_stop - LONGSIZE
  103. 1:
  104. PTR_ADDIU t0, LONGSIZE
  105. LONG_S zero, (t0)
  106. bne t0, t1, 1b
  107. LONG_S a0, fw_arg0 # firmware arguments
  108. LONG_S a1, fw_arg1
  109. LONG_S a2, fw_arg2
  110. LONG_S a3, fw_arg3
  111. #ifdef CONFIG_USE_OF
  112. LONG_S t2, fw_passed_dtb
  113. #endif
  114. MTC0 zero, CP0_CONTEXT # clear context register
  115. PTR_LA $28, init_thread_union
  116. /* Set the SP after an empty pt_regs. */
  117. PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
  118. PTR_ADDU sp, $28
  119. back_to_back_c0_hazard
  120. set_saved_sp sp, t0, t1
  121. PTR_SUBU sp, 4 * SZREG # init stack pointer
  122. #ifdef CONFIG_RELOCATABLE
  123. /* Copy kernel and apply the relocations */
  124. jal relocate_kernel
  125. /* Repoint the sp into the new kernel image */
  126. PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
  127. PTR_ADDU sp, $28
  128. set_saved_sp sp, t0, t1
  129. PTR_SUBU sp, 4 * SZREG # init stack pointer
  130. /*
  131. * relocate_kernel returns the entry point either
  132. * in the relocated kernel or the original if for
  133. * some reason relocation failed - jump there now
  134. * with instruction hazard barrier because of the
  135. * newly sync'd icache.
  136. */
  137. jr.hb v0
  138. #else /* !CONFIG_RELOCATABLE */
  139. j start_kernel
  140. #endif /* !CONFIG_RELOCATABLE */
  141. END(kernel_entry)
  142. #ifdef CONFIG_SMP
  143. /*
  144. * SMP slave cpus entry point. Board specific code for bootstrap calls this
  145. * function after setting up the stack and gp registers.
  146. */
  147. NESTED(smp_bootstrap, 16, sp)
  148. smp_slave_setup
  149. setup_c0_status_sec
  150. j start_secondary
  151. END(smp_bootstrap)
  152. #endif /* CONFIG_SMP */