head.S 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /* This file is subject to the terms and conditions of the GNU General Public
  2. * License. See the file "COPYING" in the main directory of this archive
  3. * for more details.
  4. *
  5. * Copyright (C) 1999 by Helge Deller
  6. * Copyright 1999 SuSE GmbH (Philipp Rumpf)
  7. * Copyright 1999 Philipp Rumpf (prumpf@tux.org)
  8. * Copyright 2000 Hewlett Packard (Paul Bame, bame@puffin.external.hp.com)
  9. * Copyright (C) 2001 Grant Grundler (Hewlett Packard)
  10. * Copyright (C) 2004 Kyle McMartin <kyle@debian.org>
  11. *
  12. * Initial Version 04-23-1999 by Helge Deller <deller@gmx.de>
  13. */
  14. #include <linux/autoconf.h> /* for CONFIG_SMP */
  15. #include <asm/offsets.h>
  16. #include <asm/psw.h>
  17. #include <asm/pdc.h>
  18. #include <asm/assembly.h>
  19. #include <asm/pgtable.h>
  20. .level LEVEL
  21. .data
  22. .export boot_args
  23. boot_args:
  24. .word 0 /* arg0 */
  25. .word 0 /* arg1 */
  26. .word 0 /* arg2 */
  27. .word 0 /* arg3 */
  28. .text
  29. .align 4
  30. .import init_thread_union,data
  31. .import fault_vector_20,code /* IVA parisc 2.0 32 bit */
  32. #ifndef __LP64__
  33. .import fault_vector_11,code /* IVA parisc 1.1 32 bit */
  34. .import $global$ /* forward declaration */
  35. #endif /*!LP64*/
  36. .export stext
  37. .export _stext,data /* Kernel want it this way! */
  38. _stext:
  39. stext:
  40. .proc
  41. .callinfo
  42. /* Make sure sr4-sr7 are set to zero for the kernel address space */
  43. mtsp %r0,%sr4
  44. mtsp %r0,%sr5
  45. mtsp %r0,%sr6
  46. mtsp %r0,%sr7
  47. /* Clear BSS (shouldn't the boot loader do this?) */
  48. .import __bss_start,data
  49. .import __bss_stop,data
  50. load32 PA(__bss_start),%r3
  51. load32 PA(__bss_stop),%r4
  52. $bss_loop:
  53. cmpb,<<,n %r3,%r4,$bss_loop
  54. stw,ma %r0,4(%r3)
  55. /* Save away the arguments the boot loader passed in (32 bit args) */
  56. load32 PA(boot_args),%r1
  57. stw,ma %arg0,4(%r1)
  58. stw,ma %arg1,4(%r1)
  59. stw,ma %arg2,4(%r1)
  60. stw,ma %arg3,4(%r1)
  61. /* Initialize startup VM. Just map first 8/16 MB of memory */
  62. load32 PA(swapper_pg_dir),%r4
  63. mtctl %r4,%cr24 /* Initialize kernel root pointer */
  64. mtctl %r4,%cr25 /* Initialize user root pointer */
  65. #ifdef __LP64__
  66. /* Set pmd in pgd */
  67. load32 PA(pmd0),%r5
  68. shrd %r5,PxD_VALUE_SHIFT,%r3
  69. ldo (PxD_FLAG_PRESENT+PxD_FLAG_VALID)(%r3),%r3
  70. stw %r3,ASM_PGD_ENTRY*ASM_PGD_ENTRY_SIZE(%r4)
  71. ldo ASM_PMD_ENTRY*ASM_PMD_ENTRY_SIZE(%r5),%r4
  72. #else
  73. /* 2-level page table, so pmd == pgd */
  74. ldo ASM_PGD_ENTRY*ASM_PGD_ENTRY_SIZE(%r4),%r4
  75. #endif
  76. /* Fill in pmd with enough pte directories */
  77. load32 PA(pg0),%r1
  78. SHRREG %r1,PxD_VALUE_SHIFT,%r3
  79. ldo (PxD_FLAG_PRESENT+PxD_FLAG_VALID)(%r3),%r3
  80. ldi ASM_PT_INITIAL,%r1
  81. 1:
  82. stw %r3,0(%r4)
  83. ldo (ASM_PAGE_SIZE >> PxD_VALUE_SHIFT)(%r3),%r3
  84. addib,> -1,%r1,1b
  85. #ifdef __LP64__
  86. ldo ASM_PMD_ENTRY_SIZE(%r4),%r4
  87. #else
  88. ldo ASM_PGD_ENTRY_SIZE(%r4),%r4
  89. #endif
  90. /* Now initialize the PTEs themselves */
  91. ldo _PAGE_KERNEL(%r0),%r3 /* Hardwired 0 phys addr start */
  92. load32 PA(pg0),%r1
  93. $pgt_fill_loop:
  94. STREGM %r3,ASM_PTE_ENTRY_SIZE(%r1)
  95. ldo ASM_PAGE_SIZE(%r3),%r3
  96. bb,>= %r3,31-KERNEL_INITIAL_ORDER,$pgt_fill_loop
  97. nop
  98. /* Load the return address...er...crash 'n burn */
  99. copy %r0,%r2
  100. /* And the RFI Target address too */
  101. load32 start_kernel,%r11
  102. /* And the initial task pointer */
  103. load32 init_thread_union,%r6
  104. mtctl %r6,%cr30
  105. /* And the stack pointer too */
  106. ldo THREAD_SZ_ALGN(%r6),%sp
  107. /* And the interrupt stack */
  108. load32 interrupt_stack,%r6
  109. mtctl %r6,%cr31
  110. #ifdef CONFIG_SMP
  111. /* Set the smp rendevous address into page zero.
  112. ** It would be safer to do this in init_smp_config() but
  113. ** it's just way easier to deal with here because
  114. ** of 64-bit function ptrs and the address is local to this file.
  115. */
  116. load32 PA(smp_slave_stext),%r10
  117. stw %r10,0x10(%r0) /* MEM_RENDEZ */
  118. stw %r0,0x28(%r0) /* MEM_RENDEZ_HI - assume addr < 4GB */
  119. /* FALLTHROUGH */
  120. .procend
  121. /*
  122. ** Code Common to both Monarch and Slave processors.
  123. ** Entry:
  124. **
  125. ** 1.1:
  126. ** %r11 must contain RFI target address.
  127. ** %r25/%r26 args to pass to target function
  128. ** %r2 in case rfi target decides it didn't like something
  129. **
  130. ** 2.0w:
  131. ** %r3 PDCE_PROC address
  132. ** %r11 RFI target address
  133. **
  134. ** Caller must init: SR4-7, %sp, %r10, %cr24/25,
  135. */
  136. common_stext:
  137. .proc
  138. .callinfo
  139. #else
  140. /* Clear PDC entry point - we won't use it */
  141. stw %r0,0x10(%r0) /* MEM_RENDEZ */
  142. stw %r0,0x28(%r0) /* MEM_RENDEZ_HI */
  143. #endif /*CONFIG_SMP*/
  144. #ifdef __LP64__
  145. tophys_r1 %sp
  146. /* Save the rfi target address */
  147. ldd TI_TASK-THREAD_SZ_ALGN(%sp), %r10
  148. tophys_r1 %r10
  149. std %r11, TASK_PT_GR11(%r10)
  150. /* Switch to wide mode Superdome doesn't support narrow PDC
  151. ** calls.
  152. */
  153. 1: mfia %rp /* clear upper part of pcoq */
  154. ldo 2f-1b(%rp),%rp
  155. depdi 0,31,32,%rp
  156. bv (%rp)
  157. ssm PSW_SM_W,%r0
  158. /* Set Wide mode as the "Default" (eg for traps)
  159. ** First trap occurs *right* after (or part of) rfi for slave CPUs.
  160. ** Someday, palo might not do this for the Monarch either.
  161. */
  162. 2:
  163. #define MEM_PDC_LO 0x388
  164. #define MEM_PDC_HI 0x35C
  165. ldw MEM_PDC_LO(%r0),%r3
  166. ldw MEM_PDC_HI(%r0),%r6
  167. depd %r6, 31, 32, %r3 /* move to upper word */
  168. ldo PDC_PSW(%r0),%arg0 /* 21 */
  169. ldo PDC_PSW_SET_DEFAULTS(%r0),%arg1 /* 2 */
  170. ldo PDC_PSW_WIDE_BIT(%r0),%arg2 /* 2 */
  171. load32 PA(stext_pdc_ret), %rp
  172. bv (%r3)
  173. copy %r0,%arg3
  174. stext_pdc_ret:
  175. /* restore rfi target address*/
  176. ldd TI_TASK-THREAD_SZ_ALGN(%sp), %r10
  177. tophys_r1 %r10
  178. ldd TASK_PT_GR11(%r10), %r11
  179. tovirt_r1 %sp
  180. #endif
  181. /* PARANOID: clear user scratch/user space SR's */
  182. mtsp %r0,%sr0
  183. mtsp %r0,%sr1
  184. mtsp %r0,%sr2
  185. mtsp %r0,%sr3
  186. /* Initialize Protection Registers */
  187. mtctl %r0,%cr8
  188. mtctl %r0,%cr9
  189. mtctl %r0,%cr12
  190. mtctl %r0,%cr13
  191. /* Prepare to RFI! Man all the cannons! */
  192. /* Initialize the global data pointer */
  193. loadgp
  194. /* Set up our interrupt table. HPMCs might not work after this!
  195. *
  196. * We need to install the correct iva for PA1.1 or PA2.0. The
  197. * following short sequence of instructions can determine this
  198. * (without being illegal on a PA1.1 machine).
  199. */
  200. #ifndef __LP64__
  201. ldi 32,%r10
  202. mtctl %r10,%cr11
  203. .level 2.0
  204. mfctl,w %cr11,%r10
  205. .level 1.1
  206. comib,<>,n 0,%r10,$is_pa20
  207. ldil L%PA(fault_vector_11),%r10
  208. b $install_iva
  209. ldo R%PA(fault_vector_11)(%r10),%r10
  210. $is_pa20:
  211. .level LEVEL /* restore 1.1 || 2.0w */
  212. #endif /*!LP64*/
  213. load32 PA(fault_vector_20),%r10
  214. $install_iva:
  215. mtctl %r10,%cr14
  216. #ifdef __LP64__
  217. b aligned_rfi
  218. nop
  219. .align 256
  220. aligned_rfi:
  221. ssm 0,0
  222. nop /* 1 */
  223. nop /* 2 */
  224. nop /* 3 */
  225. nop /* 4 */
  226. nop /* 5 */
  227. nop /* 6 */
  228. nop /* 7 */
  229. nop /* 8 */
  230. #endif
  231. #ifdef __LP64__ /* move to psw.h? */
  232. #define PSW_BITS PSW_Q+PSW_I+PSW_D+PSW_P+PSW_R
  233. #else
  234. #define PSW_BITS PSW_SM_Q
  235. #endif
  236. $rfi:
  237. /* turn off troublesome PSW bits */
  238. rsm PSW_BITS,%r0
  239. /* kernel PSW:
  240. * - no interruptions except HPMC and TOC (which are handled by PDC)
  241. * - Q bit set (IODC / PDC interruptions)
  242. * - big-endian
  243. * - virtually mapped
  244. */
  245. load32 KERNEL_PSW,%r10
  246. mtctl %r10,%ipsw
  247. /* Set the space pointers for the post-RFI world
  248. ** Clear the two-level IIA Space Queue, effectively setting
  249. ** Kernel space.
  250. */
  251. mtctl %r0,%cr17 /* Clear IIASQ tail */
  252. mtctl %r0,%cr17 /* Clear IIASQ head */
  253. /* Load RFI target into PC queue */
  254. mtctl %r11,%cr18 /* IIAOQ head */
  255. ldo 4(%r11),%r11
  256. mtctl %r11,%cr18 /* IIAOQ tail */
  257. /* Jump to hyperspace */
  258. rfi
  259. nop
  260. .procend
  261. #ifdef CONFIG_SMP
  262. .import smp_init_current_idle_task,data
  263. .import smp_callin,code
  264. #ifndef __LP64__
  265. smp_callin_rtn:
  266. .proc
  267. .callinfo
  268. break 1,1 /* Break if returned from start_secondary */
  269. nop
  270. nop
  271. .procend
  272. #endif /*!LP64*/
  273. /***************************************************************************
  274. * smp_slave_stext is executed by all non-monarch Processors when the Monarch
  275. * pokes the slave CPUs in smp.c:smp_boot_cpus().
  276. *
  277. * Once here, registers values are initialized in order to branch to virtual
  278. * mode. Once all available/eligible CPUs are in virtual mode, all are
  279. * released and start out by executing their own idle task.
  280. *****************************************************************************/
  281. smp_slave_stext:
  282. .proc
  283. .callinfo
  284. /*
  285. ** Initialize Space registers
  286. */
  287. mtsp %r0,%sr4
  288. mtsp %r0,%sr5
  289. mtsp %r0,%sr6
  290. mtsp %r0,%sr7
  291. /* Initialize the SP - monarch sets up smp_init_current_idle_task */
  292. load32 PA(smp_init_current_idle_task),%sp
  293. LDREG 0(%sp),%sp /* load task address */
  294. tophys_r1 %sp
  295. LDREG TASK_THREAD_INFO(%sp),%sp
  296. mtctl %sp,%cr30 /* store in cr30 */
  297. ldo THREAD_SZ_ALGN(%sp),%sp
  298. /* point CPU to kernel page tables */
  299. load32 PA(swapper_pg_dir),%r4
  300. mtctl %r4,%cr24 /* Initialize kernel root pointer */
  301. mtctl %r4,%cr25 /* Initialize user root pointer */
  302. #ifdef __LP64__
  303. /* Setup PDCE_PROC entry */
  304. copy %arg0,%r3
  305. #else
  306. /* Load RFI *return* address in case smp_callin bails */
  307. load32 smp_callin_rtn,%r2
  308. #endif
  309. /* Load RFI target address. */
  310. load32 smp_callin,%r11
  311. /* ok...common code can handle the rest */
  312. b common_stext
  313. nop
  314. .procend
  315. #endif /* CONFIG_SMP */
  316. #ifndef __LP64__
  317. .data
  318. .align 4
  319. .export $global$,data
  320. .type $global$,@object
  321. .size $global$,4
  322. $global$:
  323. .word 0
  324. #endif /*!LP64*/