head.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Early kernel startup code for Hexagon
  3. *
  4. * Copyright (c) 2010-2011, 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. __INIT
  28. ENTRY(stext)
  29. /*
  30. * VMM will already have set up true vector page, MMU, etc.
  31. * To set up initial kernel identity map, we have to pass
  32. * the VMM a pointer to some canonical page tables. In
  33. * this implementation, we're assuming that we've got
  34. * them precompiled. Generate value in R24, as we'll need
  35. * it again shortly.
  36. */
  37. r24.L = #LO(swapper_pg_dir)
  38. r24.H = #HI(swapper_pg_dir)
  39. /*
  40. * Symbol is kernel segment address, but we need
  41. * the logical/physical address.
  42. */
  43. r25 = pc;
  44. r2.h = #0xffc0;
  45. r2.l = #0x0000;
  46. r25 = and(r2,r25); /* R25 holds PHYS_OFFSET now */
  47. r1.h = #HI(PAGE_OFFSET);
  48. r1.l = #LO(PAGE_OFFSET);
  49. r24 = sub(r24,r1); /* swapper_pg_dir - PAGE_OFFSET */
  50. r24 = add(r24,r25); /* + PHYS_OFFSET */
  51. r0 = r24; /* aka __pa(swapper_pg_dir) */
  52. /*
  53. * Initialize page dir to make the virtual and physical
  54. * addresses where the kernel was loaded be identical.
  55. * Done in 4MB chunks.
  56. */
  57. #define PTE_BITS ( __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X \
  58. | __HEXAGON_C_WB_L2 << 6 \
  59. | __HVM_PDE_S_4MB)
  60. r1 = pc
  61. r2.H = #0xffc0
  62. r2.L = #0x0000
  63. r1 = and(r1,r2) /* round PC to 4MB boundary */
  64. r2 = lsr(r1, #22) /* 4MB page number */
  65. r2 = asl(r2, #2) /* times sizeof(PTE) (4bytes) */
  66. r0 = add(r0,r2) /* r0 = address of correct PTE */
  67. r2 = #PTE_BITS
  68. r1 = add(r1,r2) /* r1 = 4MB PTE for the first entry */
  69. r2.h = #0x0040
  70. r2.l = #0x0000 /* 4MB */
  71. memw(r0 ++ #4) = r1
  72. r1 = add(r1, r2)
  73. memw(r0 ++ #4) = r1
  74. r0 = r24
  75. /*
  76. * The subroutine wrapper around the virtual instruction touches
  77. * no memory, so we should be able to use it even here.
  78. */
  79. call __vmnewmap;
  80. /* Jump into virtual address range. */
  81. r31.h = #hi(__head_s_vaddr_target)
  82. r31.l = #lo(__head_s_vaddr_target)
  83. jumpr r31
  84. /* Insert trippy space effects. */
  85. __head_s_vaddr_target:
  86. /*
  87. * Tear down VA=PA translation now that we are running
  88. * in the desgnated kernel segments.
  89. */
  90. r0 = #__HVM_PDE_S_INVALID
  91. r1 = r24
  92. loop0(1f,#0x100)
  93. 1:
  94. {
  95. memw(R1 ++ #4) = R0
  96. }:endloop0
  97. r0 = r24
  98. call __vmnewmap
  99. /* Go ahead and install the trap0 return so angel calls work */
  100. r0.h = #hi(_K_provisional_vec)
  101. r0.l = #lo(_K_provisional_vec)
  102. call __vmsetvec
  103. /*
  104. * OK, at this point we should start to be much more careful,
  105. * we're going to enter C code and start touching memory
  106. * in all sorts of places.
  107. * This means:
  108. * SGP needs to be OK
  109. * Need to lock shared resources
  110. * A bunch of other things that will cause
  111. * all kinds of painful bugs
  112. */
  113. /*
  114. * Stack pointer should be pointed at the init task's
  115. * thread stack, which should have been declared in arch/init_task.c.
  116. * So uhhhhh...
  117. * It's accessible via the init_thread_union, which is a union
  118. * of a thread_info struct and a stack; of course, the top
  119. * of the stack is not for you. The end of the stack
  120. * is simply init_thread_union + THREAD_SIZE.
  121. */
  122. {r29.H = #HI(init_thread_union); r0.H = #HI(_THREAD_SIZE); }
  123. {r29.L = #LO(init_thread_union); r0.L = #LO(_THREAD_SIZE); }
  124. /* initialize the register used to point to current_thread_info */
  125. /* Fixme: THREADINFO_REG can't be R2 because of that memset thing. */
  126. {r29 = add(r29,r0); THREADINFO_REG = r29; }
  127. /* Hack: zero bss; */
  128. { r0.L = #LO(__bss_start); r1 = #0; r2.l = #LO(__bss_stop); }
  129. { r0.H = #HI(__bss_start); r2.h = #HI(__bss_stop); }
  130. r2 = sub(r2,r0);
  131. call memset;
  132. /* Set PHYS_OFFSET; should still be in R25 */
  133. #ifdef CONFIG_HEXAGON_PHYS_OFFSET
  134. r0.l = #LO(__phys_offset);
  135. r0.h = #HI(__phys_offset);
  136. memw(r0) = r25;
  137. #endif
  138. /* Time to make the doughnuts. */
  139. call start_kernel
  140. /*
  141. * Should not reach here.
  142. */
  143. 1:
  144. jump 1b
  145. .p2align PAGE_SHIFT
  146. ENTRY(external_cmdline_buffer)
  147. .fill _PAGE_SIZE,1,0
  148. .data
  149. .p2align PAGE_SHIFT
  150. ENTRY(empty_zero_page)
  151. .fill _PAGE_SIZE,1,0