head.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Early kernel startup code for Hexagon
  4. *
  5. * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  6. */
  7. #include <linux/linkage.h>
  8. #include <linux/init.h>
  9. #include <asm/asm-offsets.h>
  10. #include <asm/mem-layout.h>
  11. #include <asm/vm_mmu.h>
  12. #include <asm/page.h>
  13. #include <asm/hexagon_vm.h>
  14. #define SEGTABLE_ENTRIES #0x0e0
  15. __INIT
  16. ENTRY(stext)
  17. /*
  18. * VMM will already have set up true vector page, MMU, etc.
  19. * To set up initial kernel identity map, we have to pass
  20. * the VMM a pointer to some canonical page tables. In
  21. * this implementation, we're assuming that we've got
  22. * them precompiled. Generate value in R24, as we'll need
  23. * it again shortly.
  24. */
  25. r24.L = #LO(swapper_pg_dir)
  26. r24.H = #HI(swapper_pg_dir)
  27. /*
  28. * Symbol is kernel segment address, but we need
  29. * the logical/physical address.
  30. */
  31. r25 = pc;
  32. r2.h = #0xffc0;
  33. r2.l = #0x0000;
  34. r25 = and(r2,r25); /* R25 holds PHYS_OFFSET now */
  35. r1.h = #HI(PAGE_OFFSET);
  36. r1.l = #LO(PAGE_OFFSET);
  37. r24 = sub(r24,r1); /* swapper_pg_dir - PAGE_OFFSET */
  38. r24 = add(r24,r25); /* + PHYS_OFFSET */
  39. r0 = r24; /* aka __pa(swapper_pg_dir) */
  40. /*
  41. * Initialize page dir to make the virtual and physical
  42. * addresses where the kernel was loaded be identical.
  43. * Done in 4MB chunks.
  44. */
  45. #define PTE_BITS ( __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X \
  46. | __HEXAGON_C_WB_L2 << 6 \
  47. | __HVM_PDE_S_4MB)
  48. /*
  49. * Get number of VA=PA entries; only really needed for jump
  50. * to hyperspace; gets blown away immediately after
  51. */
  52. {
  53. r1.l = #LO(_end);
  54. r2.l = #LO(stext);
  55. r3 = #1;
  56. }
  57. {
  58. r1.h = #HI(_end);
  59. r2.h = #HI(stext);
  60. r3 = asl(r3, #22);
  61. }
  62. {
  63. r1 = sub(r1, r2);
  64. r3 = add(r3, #-1);
  65. } /* r1 = _end - stext */
  66. r1 = add(r1, r3); /* + (4M-1) */
  67. r26 = lsr(r1, #22); /* / 4M = # of entries */
  68. r1 = r25;
  69. r2.h = #0xffc0;
  70. r2.l = #0x0000; /* round back down to 4MB boundary */
  71. r1 = and(r1,r2);
  72. r2 = lsr(r1, #22) /* 4MB page number */
  73. r2 = asl(r2, #2) /* times sizeof(PTE) (4bytes) */
  74. r0 = add(r0,r2) /* r0 = address of correct PTE */
  75. r2 = #PTE_BITS
  76. r1 = add(r1,r2) /* r1 = 4MB PTE for the first entry */
  77. r2.h = #0x0040
  78. r2.l = #0x0000 /* 4MB increments */
  79. loop0(1f,r26);
  80. 1:
  81. memw(r0 ++ #4) = r1
  82. { r1 = add(r1, r2); } :endloop0
  83. /* Also need to overwrite the initial 0xc0000000 entries */
  84. /* PAGE_OFFSET >> (4MB shift - 4 bytes per entry shift) */
  85. R1.H = #HI(PAGE_OFFSET >> (22 - 2))
  86. R1.L = #LO(PAGE_OFFSET >> (22 - 2))
  87. r0 = add(r1, r24); /* advance to 0xc0000000 entry */
  88. r1 = r25;
  89. r2.h = #0xffc0;
  90. r2.l = #0x0000; /* round back down to 4MB boundary */
  91. r1 = and(r1,r2); /* for huge page */
  92. r2 = #PTE_BITS
  93. r1 = add(r1,r2);
  94. r2.h = #0x0040
  95. r2.l = #0x0000 /* 4MB increments */
  96. loop0(1f,SEGTABLE_ENTRIES);
  97. 1:
  98. memw(r0 ++ #4) = r1;
  99. { r1 = add(r1,r2); } :endloop0
  100. r0 = r24;
  101. /*
  102. * The subroutine wrapper around the virtual instruction touches
  103. * no memory, so we should be able to use it even here.
  104. * Note that in this version, R1 and R2 get "clobbered"; see
  105. * vm_ops.S
  106. */
  107. r1 = #VM_TRANS_TYPE_TABLE
  108. call __vmnewmap;
  109. /* Jump into virtual address range. */
  110. r31.h = #hi(__head_s_vaddr_target)
  111. r31.l = #lo(__head_s_vaddr_target)
  112. jumpr r31
  113. /* Insert trippy space effects. */
  114. __head_s_vaddr_target:
  115. /*
  116. * Tear down VA=PA translation now that we are running
  117. * in kernel virtual space.
  118. */
  119. r0 = #__HVM_PDE_S_INVALID
  120. r1.h = #0xffc0;
  121. r1.l = #0x0000;
  122. r2 = r25; /* phys_offset */
  123. r2 = and(r1,r2);
  124. r1.l = #lo(swapper_pg_dir)
  125. r1.h = #hi(swapper_pg_dir)
  126. r2 = lsr(r2, #22) /* 4MB page number */
  127. r2 = asl(r2, #2) /* times sizeof(PTE) (4bytes) */
  128. r1 = add(r1,r2);
  129. loop0(1f,r26)
  130. 1:
  131. {
  132. memw(R1 ++ #4) = R0
  133. }:endloop0
  134. r0 = r24
  135. r1 = #VM_TRANS_TYPE_TABLE
  136. call __vmnewmap
  137. /* Go ahead and install the trap0 return so angel calls work */
  138. r0.h = #hi(_K_provisional_vec)
  139. r0.l = #lo(_K_provisional_vec)
  140. call __vmsetvec
  141. /*
  142. * OK, at this point we should start to be much more careful,
  143. * we're going to enter C code and start touching memory
  144. * in all sorts of places.
  145. * This means:
  146. * SGP needs to be OK
  147. * Need to lock shared resources
  148. * A bunch of other things that will cause
  149. * all kinds of painful bugs
  150. */
  151. /*
  152. * Stack pointer should be pointed at the init task's
  153. * thread stack, which should have been declared in arch/init_task.c.
  154. * So uhhhhh...
  155. * It's accessible via the init_thread_union, which is a union
  156. * of a thread_info struct and a stack; of course, the top
  157. * of the stack is not for you. The end of the stack
  158. * is simply init_thread_union + THREAD_SIZE.
  159. */
  160. {r29.H = #HI(init_thread_union); r0.H = #HI(_THREAD_SIZE); }
  161. {r29.L = #LO(init_thread_union); r0.L = #LO(_THREAD_SIZE); }
  162. /* initialize the register used to point to current_thread_info */
  163. /* Fixme: THREADINFO_REG can't be R2 because of that memset thing. */
  164. {r29 = add(r29,r0); THREADINFO_REG = r29; }
  165. /* Hack: zero bss; */
  166. { r0.L = #LO(__bss_start); r1 = #0; r2.l = #LO(__bss_stop); }
  167. { r0.H = #HI(__bss_start); r2.h = #HI(__bss_stop); }
  168. r2 = sub(r2,r0);
  169. call memset;
  170. /* Set PHYS_OFFSET; should be in R25 */
  171. #ifdef CONFIG_HEXAGON_PHYS_OFFSET
  172. r0.l = #LO(__phys_offset);
  173. r0.h = #HI(__phys_offset);
  174. memw(r0) = r25;
  175. #endif
  176. /* Time to make the doughnuts. */
  177. call start_kernel
  178. /*
  179. * Should not reach here.
  180. */
  181. 1:
  182. jump 1b
  183. .p2align PAGE_SHIFT
  184. ENTRY(external_cmdline_buffer)
  185. .fill _PAGE_SIZE,1,0
  186. .data
  187. .p2align PAGE_SHIFT
  188. ENTRY(empty_zero_page)
  189. .fill _PAGE_SIZE,1,0