head.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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/page.h>
  24. #include <asm/mipsregs.h>
  25. #include <asm/stackframe.h>
  26. #include <kernel-entry-init.h>
  27. .macro ARC64_TWIDDLE_PC
  28. #if defined(CONFIG_ARC64) || defined(CONFIG_MAPPED_KERNEL)
  29. /* We get launched at a XKPHYS address but the kernel is linked to
  30. run at a KSEG0 address, so jump there. */
  31. PTR_LA t0, \@f
  32. jr t0
  33. \@:
  34. #endif
  35. .endm
  36. /*
  37. * inputs are the text nasid in t1, data nasid in t2.
  38. */
  39. .macro MAPPED_KERNEL_SETUP_TLB
  40. #ifdef CONFIG_MAPPED_KERNEL
  41. /*
  42. * This needs to read the nasid - assume 0 for now.
  43. * Drop in 0xffffffffc0000000 in tlbhi, 0+VG in tlblo_0,
  44. * 0+DVG in tlblo_1.
  45. */
  46. dli t0, 0xffffffffc0000000
  47. dmtc0 t0, CP0_ENTRYHI
  48. li t0, 0x1c000 # Offset of text into node memory
  49. dsll t1, NASID_SHFT # Shift text nasid into place
  50. dsll t2, NASID_SHFT # Same for data nasid
  51. or t1, t1, t0 # Physical load address of kernel text
  52. or t2, t2, t0 # Physical load address of kernel data
  53. dsrl t1, 12 # 4K pfn
  54. dsrl t2, 12 # 4K pfn
  55. dsll t1, 6 # Get pfn into place
  56. dsll t2, 6 # Get pfn into place
  57. li t0, ((_PAGE_GLOBAL|_PAGE_VALID| _CACHE_CACHABLE_COW) >> 6)
  58. or t0, t0, t1
  59. mtc0 t0, CP0_ENTRYLO0 # physaddr, VG, cach exlwr
  60. li t0, ((_PAGE_GLOBAL|_PAGE_VALID| _PAGE_DIRTY|_CACHE_CACHABLE_COW) >> 6)
  61. or t0, t0, t2
  62. mtc0 t0, CP0_ENTRYLO1 # physaddr, DVG, cach exlwr
  63. li t0, 0x1ffe000 # MAPPED_KERN_TLBMASK, TLBPGMASK_16M
  64. mtc0 t0, CP0_PAGEMASK
  65. li t0, 0 # KMAP_INX
  66. mtc0 t0, CP0_INDEX
  67. li t0, 1
  68. mtc0 t0, CP0_WIRED
  69. tlbwi
  70. #else
  71. mtc0 zero, CP0_WIRED
  72. #endif
  73. .endm
  74. /*
  75. * For the moment disable interrupts, mark the kernel mode and
  76. * set ST0_KX so that the CPU does not spit fire when using
  77. * 64-bit addresses. A full initialization of the CPU's status
  78. * register is done later in per_cpu_trap_init().
  79. */
  80. .macro setup_c0_status set clr
  81. .set push
  82. #ifdef CONFIG_MIPS_MT_SMTC
  83. /*
  84. * For SMTC, we need to set privilege and disable interrupts only for
  85. * the current TC, using the TCStatus register.
  86. */
  87. mfc0 t0, CP0_TCSTATUS
  88. /* Fortunately CU 0 is in the same place in both registers */
  89. /* Set TCU0, TMX, TKSU (for later inversion) and IXMT */
  90. li t1, ST0_CU0 | 0x08001c00
  91. or t0, t1
  92. /* Clear TKSU, leave IXMT */
  93. xori t0, 0x00001800
  94. mtc0 t0, CP0_TCSTATUS
  95. _ehb
  96. /* We need to leave the global IE bit set, but clear EXL...*/
  97. mfc0 t0, CP0_STATUS
  98. or t0, ST0_CU0 | ST0_EXL | ST0_ERL | \set | \clr
  99. xor t0, ST0_EXL | ST0_ERL | \clr
  100. mtc0 t0, CP0_STATUS
  101. #else
  102. mfc0 t0, CP0_STATUS
  103. or t0, ST0_CU0|\set|0x1f|\clr
  104. xor t0, 0x1f|\clr
  105. mtc0 t0, CP0_STATUS
  106. .set noreorder
  107. sll zero,3 # ehb
  108. #endif
  109. .set pop
  110. .endm
  111. .macro setup_c0_status_pri
  112. #ifdef CONFIG_64BIT
  113. setup_c0_status ST0_KX 0
  114. #else
  115. setup_c0_status 0 0
  116. #endif
  117. .endm
  118. .macro setup_c0_status_sec
  119. #ifdef CONFIG_64BIT
  120. setup_c0_status ST0_KX ST0_BEV
  121. #else
  122. setup_c0_status 0 ST0_BEV
  123. #endif
  124. .endm
  125. #ifndef CONFIG_NO_EXCEPT_FILL
  126. /*
  127. * Reserved space for exception handlers.
  128. * Necessary for machines which link their kernels at KSEG0.
  129. */
  130. .fill 0x400
  131. #endif
  132. EXPORT(_stext)
  133. #ifndef CONFIG_BOOT_RAW
  134. /*
  135. * Give us a fighting chance of running if execution beings at the
  136. * kernel load address. This is needed because this platform does
  137. * not have a ELF loader yet.
  138. */
  139. __INIT
  140. #endif
  141. NESTED(kernel_entry, 16, sp) # kernel entry point
  142. kernel_entry_setup # cpu specific setup
  143. setup_c0_status_pri
  144. ARC64_TWIDDLE_PC
  145. #ifdef CONFIG_MIPS_MT_SMTC
  146. /*
  147. * In SMTC kernel, "CLI" is thread-specific, in TCStatus.
  148. * We still need to enable interrupts globally in Status,
  149. * and clear EXL/ERL.
  150. *
  151. * TCContext is used to track interrupt levels under
  152. * service in SMTC kernel. Clear for boot TC before
  153. * allowing any interrupts.
  154. */
  155. mtc0 zero, CP0_TCCONTEXT
  156. mfc0 t0, CP0_STATUS
  157. ori t0, t0, 0xff1f
  158. xori t0, t0, 0x001e
  159. mtc0 t0, CP0_STATUS
  160. #endif /* CONFIG_MIPS_MT_SMTC */
  161. PTR_LA t0, __bss_start # clear .bss
  162. LONG_S zero, (t0)
  163. PTR_LA t1, __bss_stop - LONGSIZE
  164. 1:
  165. PTR_ADDIU t0, LONGSIZE
  166. LONG_S zero, (t0)
  167. bne t0, t1, 1b
  168. LONG_S a0, fw_arg0 # firmware arguments
  169. LONG_S a1, fw_arg1
  170. LONG_S a2, fw_arg2
  171. LONG_S a3, fw_arg3
  172. MTC0 zero, CP0_CONTEXT # clear context register
  173. PTR_LA $28, init_thread_union
  174. PTR_LI sp, _THREAD_SIZE - 32
  175. PTR_ADDU sp, $28
  176. set_saved_sp sp, t0, t1
  177. PTR_SUBU sp, 4 * SZREG # init stack pointer
  178. j start_kernel
  179. END(kernel_entry)
  180. __INIT
  181. #ifdef CONFIG_SMP
  182. /*
  183. * SMP slave cpus entry point. Board specific code for bootstrap calls this
  184. * function after setting up the stack and gp registers.
  185. */
  186. NESTED(smp_bootstrap, 16, sp)
  187. #ifdef CONFIG_MIPS_MT_SMTC
  188. /*
  189. * Read-modify-writes of Status must be atomic, and this
  190. * is one case where CLI is invoked without EXL being
  191. * necessarily set. The CLI and setup_c0_status will
  192. * in fact be redundant for all but the first TC of
  193. * each VPE being booted.
  194. */
  195. DMT 10 # dmt t2 /* t0, t1 are used by CLI and setup_c0_status() */
  196. jal mips_ihb
  197. #endif /* CONFIG_MIPS_MT_SMTC */
  198. setup_c0_status_sec
  199. smp_slave_setup
  200. #ifdef CONFIG_MIPS_MT_SMTC
  201. andi t2, t2, VPECONTROL_TE
  202. beqz t2, 2f
  203. EMT # emt
  204. 2:
  205. #endif /* CONFIG_MIPS_MT_SMTC */
  206. j start_secondary
  207. END(smp_bootstrap)
  208. #endif /* CONFIG_SMP */
  209. __FINIT