head.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. r24 = asl(r24, #2)
  44. r24 = lsr(r24, #2)
  45. r0 = r24
  46. /*
  47. * Initialize a 16MB PTE to make the virtual and physical
  48. * addresses where the kernel was loaded be identical.
  49. */
  50. #define PTE_BITS ( __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X \
  51. | __HEXAGON_C_WB_L2 << 6 \
  52. | __HVM_PDE_S_4MB)
  53. r1 = pc
  54. r2.H = #0xffc0
  55. r2.L = #0x0000
  56. r1 = and(r1,r2) /* round PC to 4MB boundary */
  57. r2 = lsr(r1, #22) /* 4MB page number */
  58. r2 = asl(r2, #2) /* times sizeof(PTE) (4bytes) */
  59. r0 = add(r0,r2) /* r0 = address of correct PTE */
  60. r2 = #PTE_BITS
  61. r1 = add(r1,r2) /* r1 = 4MB PTE for the first entry */
  62. r2.h = #0x0040
  63. r2.l = #0x0000 /* 4MB */
  64. memw(r0 ++ #4) = r1
  65. r1 = add(r1, r2)
  66. memw(r0 ++ #4) = r1
  67. r0 = r24
  68. /*
  69. * The subroutine wrapper around the virtual instruction touches
  70. * no memory, so we should be able to use it even here.
  71. */
  72. call __vmnewmap;
  73. /* Jump into virtual address range. */
  74. r31.h = #hi(__head_s_vaddr_target)
  75. r31.l = #lo(__head_s_vaddr_target)
  76. jumpr r31
  77. /* Insert trippy space effects. */
  78. __head_s_vaddr_target:
  79. /*
  80. * Tear down VA=PA translation now that we are running
  81. * in the desgnated kernel segments.
  82. */
  83. r0 = #__HVM_PDE_S_INVALID
  84. r1 = r24
  85. loop0(1f,#0x100)
  86. 1:
  87. {
  88. memw(R1 ++ #4) = R0
  89. }:endloop0
  90. r0 = r24
  91. call __vmnewmap
  92. /* Go ahead and install the trap0 return so angel calls work */
  93. r0.h = #hi(_K_provisional_vec)
  94. r0.l = #lo(_K_provisional_vec)
  95. call __vmsetvec
  96. /*
  97. * OK, at this point we should start to be much more careful,
  98. * we're going to enter C code and start touching memory
  99. * in all sorts of places.
  100. * This means:
  101. * SGP needs to be OK
  102. * Need to lock shared resources
  103. * A bunch of other things that will cause
  104. * all kinds of painful bugs
  105. */
  106. /*
  107. * Stack pointer should be pointed at the init task's
  108. * thread stack, which should have been declared in arch/init_task.c.
  109. * So uhhhhh...
  110. * It's accessible via the init_thread_union, which is a union
  111. * of a thread_info struct and a stack; of course, the top
  112. * of the stack is not for you. The end of the stack
  113. * is simply init_thread_union + THREAD_SIZE.
  114. */
  115. {r29.H = #HI(init_thread_union); r0.H = #HI(_THREAD_SIZE); }
  116. {r29.L = #LO(init_thread_union); r0.L = #LO(_THREAD_SIZE); }
  117. /* initialize the register used to point to current_thread_info */
  118. /* Fixme: THREADINFO_REG can't be R2 because of that memset thing. */
  119. {r29 = add(r29,r0); THREADINFO_REG = r29; }
  120. /* Hack: zero bss; */
  121. { r0.L = #LO(__bss_start); r1 = #0; r2.l = #LO(__bss_stop); }
  122. { r0.H = #HI(__bss_start); r2.h = #HI(__bss_stop); }
  123. r2 = sub(r2,r0);
  124. call memset;
  125. /* Time to make the doughnuts. */
  126. call start_kernel
  127. /*
  128. * Should not reach here.
  129. */
  130. 1:
  131. jump 1b
  132. .p2align PAGE_SHIFT
  133. ENTRY(external_cmdline_buffer)
  134. .fill _PAGE_SIZE,1,0
  135. .data
  136. .p2align PAGE_SHIFT
  137. ENTRY(empty_zero_page)
  138. .fill _PAGE_SIZE,1,0