head.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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, 95, 96, 97, 98, 99, 2003 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/config.h>
  17. #include <linux/init.h>
  18. #include <linux/threads.h>
  19. #include <asm/asm.h>
  20. #include <asm/regdef.h>
  21. #include <asm/page.h>
  22. #include <asm/mipsregs.h>
  23. #include <asm/stackframe.h>
  24. #ifdef CONFIG_SGI_IP27
  25. #include <asm/sn/addrs.h>
  26. #include <asm/sn/sn0/hubni.h>
  27. #include <asm/sn/klkernvars.h>
  28. #endif
  29. .macro ARC64_TWIDDLE_PC
  30. #if defined(CONFIG_ARC64) || defined(CONFIG_MAPPED_KERNEL)
  31. /* We get launched at a XKPHYS address but the kernel is linked to
  32. run at a KSEG0 address, so jump there. */
  33. PTR_LA t0, \@f
  34. jr t0
  35. \@:
  36. #endif
  37. .endm
  38. #ifdef CONFIG_SGI_IP27
  39. /*
  40. * outputs the local nasid into res. IP27 stuff.
  41. */
  42. .macro GET_NASID_ASM res
  43. dli \res, LOCAL_HUB_ADDR(NI_STATUS_REV_ID)
  44. ld \res, (\res)
  45. and \res, NSRI_NODEID_MASK
  46. dsrl \res, NSRI_NODEID_SHFT
  47. .endm
  48. #endif /* CONFIG_SGI_IP27 */
  49. /*
  50. * inputs are the text nasid in t1, data nasid in t2.
  51. */
  52. .macro MAPPED_KERNEL_SETUP_TLB
  53. #ifdef CONFIG_MAPPED_KERNEL
  54. /*
  55. * This needs to read the nasid - assume 0 for now.
  56. * Drop in 0xffffffffc0000000 in tlbhi, 0+VG in tlblo_0,
  57. * 0+DVG in tlblo_1.
  58. */
  59. dli t0, 0xffffffffc0000000
  60. dmtc0 t0, CP0_ENTRYHI
  61. li t0, 0x1c000 # Offset of text into node memory
  62. dsll t1, NASID_SHFT # Shift text nasid into place
  63. dsll t2, NASID_SHFT # Same for data nasid
  64. or t1, t1, t0 # Physical load address of kernel text
  65. or t2, t2, t0 # Physical load address of kernel data
  66. dsrl t1, 12 # 4K pfn
  67. dsrl t2, 12 # 4K pfn
  68. dsll t1, 6 # Get pfn into place
  69. dsll t2, 6 # Get pfn into place
  70. li t0, ((_PAGE_GLOBAL|_PAGE_VALID| _CACHE_CACHABLE_COW) >> 6)
  71. or t0, t0, t1
  72. mtc0 t0, CP0_ENTRYLO0 # physaddr, VG, cach exlwr
  73. li t0, ((_PAGE_GLOBAL|_PAGE_VALID| _PAGE_DIRTY|_CACHE_CACHABLE_COW) >> 6)
  74. or t0, t0, t2
  75. mtc0 t0, CP0_ENTRYLO1 # physaddr, DVG, cach exlwr
  76. li t0, 0x1ffe000 # MAPPED_KERN_TLBMASK, TLBPGMASK_16M
  77. mtc0 t0, CP0_PAGEMASK
  78. li t0, 0 # KMAP_INX
  79. mtc0 t0, CP0_INDEX
  80. li t0, 1
  81. mtc0 t0, CP0_WIRED
  82. tlbwi
  83. #else
  84. mtc0 zero, CP0_WIRED
  85. #endif
  86. .endm
  87. /*
  88. * For the moment disable interrupts, mark the kernel mode and
  89. * set ST0_KX so that the CPU does not spit fire when using
  90. * 64-bit addresses. A full initialization of the CPU's status
  91. * register is done later in per_cpu_trap_init().
  92. */
  93. .macro setup_c0_status set clr
  94. .set push
  95. mfc0 t0, CP0_STATUS
  96. or t0, ST0_CU0|\set|0x1f|\clr
  97. xor t0, 0x1f|\clr
  98. mtc0 t0, CP0_STATUS
  99. .set noreorder
  100. sll zero,3 # ehb
  101. .set pop
  102. .endm
  103. .macro setup_c0_status_pri
  104. #ifdef CONFIG_64BIT
  105. setup_c0_status ST0_KX 0
  106. #else
  107. setup_c0_status 0 0
  108. #endif
  109. .endm
  110. .macro setup_c0_status_sec
  111. #ifdef CONFIG_64BIT
  112. setup_c0_status ST0_KX ST0_BEV
  113. #else
  114. setup_c0_status 0 ST0_BEV
  115. #endif
  116. .endm
  117. /*
  118. * Reserved space for exception handlers.
  119. * Necessary for machines which link their kernels at KSEG0.
  120. */
  121. .fill 0x400
  122. EXPORT(stext) # used for profiling
  123. EXPORT(_stext)
  124. __INIT
  125. NESTED(kernel_entry, 16, sp) # kernel entry point
  126. setup_c0_status_pri
  127. #ifdef CONFIG_SGI_IP27
  128. GET_NASID_ASM t1
  129. move t2, t1 # text and data are here
  130. MAPPED_KERNEL_SETUP_TLB
  131. #endif /* IP27 */
  132. ARC64_TWIDDLE_PC
  133. PTR_LA t0, __bss_start # clear .bss
  134. LONG_S zero, (t0)
  135. PTR_LA t1, __bss_stop - LONGSIZE
  136. 1:
  137. PTR_ADDIU t0, LONGSIZE
  138. LONG_S zero, (t0)
  139. bne t0, t1, 1b
  140. LONG_S a0, fw_arg0 # firmware arguments
  141. LONG_S a1, fw_arg1
  142. LONG_S a2, fw_arg2
  143. LONG_S a3, fw_arg3
  144. PTR_LA $28, init_thread_union
  145. PTR_ADDIU sp, $28, _THREAD_SIZE - 32
  146. set_saved_sp sp, t0, t1
  147. PTR_SUBU sp, 4 * SZREG # init stack pointer
  148. j start_kernel
  149. END(kernel_entry)
  150. #ifdef CONFIG_SMP
  151. /*
  152. * SMP slave cpus entry point. Board specific code for bootstrap calls this
  153. * function after setting up the stack and gp registers.
  154. */
  155. NESTED(smp_bootstrap, 16, sp)
  156. setup_c0_status_sec
  157. #ifdef CONFIG_SGI_IP27
  158. GET_NASID_ASM t1
  159. dli t0, KLDIR_OFFSET + (KLI_KERN_VARS * KLDIR_ENT_SIZE) + \
  160. KLDIR_OFF_POINTER + CAC_BASE
  161. dsll t1, NASID_SHFT
  162. or t0, t0, t1
  163. ld t0, 0(t0) # t0 points to kern_vars struct
  164. lh t1, KV_RO_NASID_OFFSET(t0)
  165. lh t2, KV_RW_NASID_OFFSET(t0)
  166. MAPPED_KERNEL_SETUP_TLB
  167. ARC64_TWIDDLE_PC
  168. #endif /* CONFIG_SGI_IP27 */
  169. j start_secondary
  170. END(smp_bootstrap)
  171. #endif /* CONFIG_SMP */
  172. __FINIT
  173. .comm kernelsp, NR_CPUS * 8, 8
  174. .comm pgd_current, NR_CPUS * 8, 8
  175. .comm fw_arg0, SZREG, SZREG # firmware arguments
  176. .comm fw_arg1, SZREG, SZREG
  177. .comm fw_arg2, SZREG, SZREG
  178. .comm fw_arg3, SZREG, SZREG
  179. .macro page name, order=0
  180. .globl \name
  181. \name: .size \name, (_PAGE_SIZE << \order)
  182. .org . + (_PAGE_SIZE << \order)
  183. .type \name, @object
  184. .endm
  185. .data
  186. .align PAGE_SHIFT
  187. /*
  188. * ... but on 64-bit we've got three-level pagetables with a
  189. * slightly different layout ...
  190. */
  191. page swapper_pg_dir, _PGD_ORDER
  192. #ifdef CONFIG_64BIT
  193. page invalid_pmd_table, _PMD_ORDER
  194. #endif
  195. page invalid_pte_table, _PTE_ORDER