head.S 6.0 KB

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