head.S 3.8 KB

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