head.S 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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
  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. #ifdef CONFIG_MIPS_RAW_APPENDED_DTB
  84. PTR_LA t2, __appended_dtb
  85. #ifdef CONFIG_CPU_BIG_ENDIAN
  86. li t1, 0xd00dfeed
  87. #else
  88. li t1, 0xedfe0dd0
  89. #endif
  90. lw t0, (t2)
  91. beq t0, t1, dtb_found
  92. #endif
  93. li t1, -2
  94. move t2, a1
  95. beq a0, t1, dtb_found
  96. li t2, 0
  97. dtb_found:
  98. #endif
  99. PTR_LA t0, __bss_start # clear .bss
  100. LONG_S zero, (t0)
  101. PTR_LA t1, __bss_stop - LONGSIZE
  102. 1:
  103. PTR_ADDIU t0, LONGSIZE
  104. LONG_S zero, (t0)
  105. bne t0, t1, 1b
  106. LONG_S a0, fw_arg0 # firmware arguments
  107. LONG_S a1, fw_arg1
  108. LONG_S a2, fw_arg2
  109. LONG_S a3, fw_arg3
  110. #ifdef CONFIG_USE_OF
  111. LONG_S t2, fw_passed_dtb
  112. #endif
  113. MTC0 zero, CP0_CONTEXT # clear context register
  114. PTR_LA $28, init_thread_union
  115. /* Set the SP after an empty pt_regs. */
  116. PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
  117. PTR_ADDU sp, $28
  118. back_to_back_c0_hazard
  119. set_saved_sp sp, t0, t1
  120. PTR_SUBU sp, 4 * SZREG # init stack pointer
  121. #ifdef CONFIG_RELOCATABLE
  122. /* Copy kernel and apply the relocations */
  123. jal relocate_kernel
  124. /* Repoint the sp into the new kernel image */
  125. PTR_LI sp, _THREAD_SIZE - 32 - PT_SIZE
  126. PTR_ADDU sp, $28
  127. set_saved_sp sp, t0, t1
  128. PTR_SUBU sp, 4 * SZREG # init stack pointer
  129. /*
  130. * relocate_kernel returns the entry point either
  131. * in the relocated kernel or the original if for
  132. * some reason relocation failed - jump there now
  133. * with instruction hazard barrier because of the
  134. * newly sync'd icache.
  135. */
  136. jr.hb v0
  137. #else
  138. j start_kernel
  139. #endif
  140. END(kernel_entry)
  141. #ifdef CONFIG_SMP
  142. /*
  143. * SMP slave cpus entry point. Board specific code for bootstrap calls this
  144. * function after setting up the stack and gp registers.
  145. */
  146. NESTED(smp_bootstrap, 16, sp)
  147. smp_slave_setup
  148. setup_c0_status_sec
  149. j start_secondary
  150. END(smp_bootstrap)
  151. #endif /* CONFIG_SMP */