head.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #include <kernel-entry-init.h>
  25. .macro ARC64_TWIDDLE_PC
  26. #if defined(CONFIG_ARC64) || defined(CONFIG_MAPPED_KERNEL)
  27. /* We get launched at a XKPHYS address but the kernel is linked to
  28. run at a KSEG0 address, so jump there. */
  29. PTR_LA t0, \@f
  30. jr t0
  31. \@:
  32. #endif
  33. .endm
  34. /*
  35. * inputs are the text nasid in t1, data nasid in t2.
  36. */
  37. .macro MAPPED_KERNEL_SETUP_TLB
  38. #ifdef CONFIG_MAPPED_KERNEL
  39. /*
  40. * This needs to read the nasid - assume 0 for now.
  41. * Drop in 0xffffffffc0000000 in tlbhi, 0+VG in tlblo_0,
  42. * 0+DVG in tlblo_1.
  43. */
  44. dli t0, 0xffffffffc0000000
  45. dmtc0 t0, CP0_ENTRYHI
  46. li t0, 0x1c000 # Offset of text into node memory
  47. dsll t1, NASID_SHFT # Shift text nasid into place
  48. dsll t2, NASID_SHFT # Same for data nasid
  49. or t1, t1, t0 # Physical load address of kernel text
  50. or t2, t2, t0 # Physical load address of kernel data
  51. dsrl t1, 12 # 4K pfn
  52. dsrl t2, 12 # 4K pfn
  53. dsll t1, 6 # Get pfn into place
  54. dsll t2, 6 # Get pfn into place
  55. li t0, ((_PAGE_GLOBAL|_PAGE_VALID| _CACHE_CACHABLE_COW) >> 6)
  56. or t0, t0, t1
  57. mtc0 t0, CP0_ENTRYLO0 # physaddr, VG, cach exlwr
  58. li t0, ((_PAGE_GLOBAL|_PAGE_VALID| _PAGE_DIRTY|_CACHE_CACHABLE_COW) >> 6)
  59. or t0, t0, t2
  60. mtc0 t0, CP0_ENTRYLO1 # physaddr, DVG, cach exlwr
  61. li t0, 0x1ffe000 # MAPPED_KERN_TLBMASK, TLBPGMASK_16M
  62. mtc0 t0, CP0_PAGEMASK
  63. li t0, 0 # KMAP_INX
  64. mtc0 t0, CP0_INDEX
  65. li t0, 1
  66. mtc0 t0, CP0_WIRED
  67. tlbwi
  68. #else
  69. mtc0 zero, CP0_WIRED
  70. #endif
  71. .endm
  72. /*
  73. * For the moment disable interrupts, mark the kernel mode and
  74. * set ST0_KX so that the CPU does not spit fire when using
  75. * 64-bit addresses. A full initialization of the CPU's status
  76. * register is done later in per_cpu_trap_init().
  77. */
  78. .macro setup_c0_status set clr
  79. .set push
  80. mfc0 t0, CP0_STATUS
  81. or t0, ST0_CU0|\set|0x1f|\clr
  82. xor t0, 0x1f|\clr
  83. mtc0 t0, CP0_STATUS
  84. .set noreorder
  85. sll zero,3 # ehb
  86. .set pop
  87. .endm
  88. .macro setup_c0_status_pri
  89. #ifdef CONFIG_64BIT
  90. setup_c0_status ST0_KX 0
  91. #else
  92. setup_c0_status 0 0
  93. #endif
  94. .endm
  95. .macro setup_c0_status_sec
  96. #ifdef CONFIG_64BIT
  97. setup_c0_status ST0_KX ST0_BEV
  98. #else
  99. setup_c0_status 0 ST0_BEV
  100. #endif
  101. .endm
  102. /*
  103. * Reserved space for exception handlers.
  104. * Necessary for machines which link their kernels at KSEG0.
  105. */
  106. .fill 0x400
  107. EXPORT(stext) # used for profiling
  108. EXPORT(_stext)
  109. #if defined(CONFIG_QEMU) || defined(CONFIG_MIPS_SIM)
  110. /*
  111. * Give us a fighting chance of running if execution beings at the
  112. * kernel load address. This is needed because this platform does
  113. * not have a ELF loader yet.
  114. */
  115. j kernel_entry
  116. #endif
  117. __INIT
  118. NESTED(kernel_entry, 16, sp) # kernel entry point
  119. kernel_entry_setup # cpu specific setup
  120. setup_c0_status_pri
  121. ARC64_TWIDDLE_PC
  122. PTR_LA t0, __bss_start # clear .bss
  123. LONG_S zero, (t0)
  124. PTR_LA t1, __bss_stop - LONGSIZE
  125. 1:
  126. PTR_ADDIU t0, LONGSIZE
  127. LONG_S zero, (t0)
  128. bne t0, t1, 1b
  129. LONG_S a0, fw_arg0 # firmware arguments
  130. LONG_S a1, fw_arg1
  131. LONG_S a2, fw_arg2
  132. LONG_S a3, fw_arg3
  133. MTC0 zero, CP0_CONTEXT # clear context register
  134. PTR_LA $28, init_thread_union
  135. PTR_ADDIU sp, $28, _THREAD_SIZE - 32
  136. set_saved_sp sp, t0, t1
  137. PTR_SUBU sp, 4 * SZREG # init stack pointer
  138. j start_kernel
  139. END(kernel_entry)
  140. #ifdef CONFIG_QEMU
  141. __INIT
  142. #endif
  143. #ifdef CONFIG_SMP
  144. /*
  145. * SMP slave cpus entry point. Board specific code for bootstrap calls this
  146. * function after setting up the stack and gp registers.
  147. */
  148. NESTED(smp_bootstrap, 16, sp)
  149. setup_c0_status_sec
  150. smp_slave_setup
  151. j start_secondary
  152. END(smp_bootstrap)
  153. #endif /* CONFIG_SMP */
  154. __FINIT
  155. .comm kernelsp, NR_CPUS * 8, 8
  156. .comm pgd_current, NR_CPUS * 8, 8
  157. .comm fw_arg0, SZREG, SZREG # firmware arguments
  158. .comm fw_arg1, SZREG, SZREG
  159. .comm fw_arg2, SZREG, SZREG
  160. .comm fw_arg3, SZREG, SZREG
  161. .macro page name, order
  162. .comm \name, (_PAGE_SIZE << \order), (_PAGE_SIZE << \order)
  163. .endm
  164. /*
  165. * On 64-bit we've got three-level pagetables with a slightly
  166. * different layout ...
  167. */
  168. page swapper_pg_dir, _PGD_ORDER
  169. #ifdef CONFIG_64BIT
  170. page invalid_pmd_table, _PMD_ORDER
  171. #endif
  172. page invalid_pte_table, _PTE_ORDER