start.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * (C) Copyright 2007 Michal Simek
  3. * (C) Copyright 2004 Atmark Techno, Inc.
  4. *
  5. * Michal SIMEK <monstr@monstr.eu>
  6. * Yasushi SHOJI <yashi@atmark-techno.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <asm-offsets.h>
  27. #include <config.h>
  28. .text
  29. .global _start
  30. _start:
  31. /*
  32. * reserve registers:
  33. * r10: Stores little/big endian offset for vectors
  34. * r2: Stores imm opcode
  35. * r3: Stores brai opcode
  36. */
  37. mts rmsr, r0 /* disable cache */
  38. addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET
  39. addi r1, r1, -4 /* Decrement SP to top of memory */
  40. /* Find-out if u-boot is running on BIG/LITTLE endian platform
  41. * There are some steps which is necessary to keep in mind:
  42. * 1. Setup offset value to r6
  43. * 2. Store word offset value to address 0x0
  44. * 3. Load just byte from address 0x0
  45. * 4a) LITTLE endian - r10 contains 0x2 because it is the smallest
  46. * value that's why is on address 0x0
  47. * 4b) BIG endian - r10 contains 0x0 because 0x2 offset is on addr 0x3
  48. */
  49. addik r6, r0, 0x2 /* BIG/LITTLE endian offset */
  50. lwi r7, r0, 0x28
  51. swi r6, r0, 0x28 /* used first unused MB vector */
  52. lbui r10, r0, 0x28 /* used first unused MB vector */
  53. swi r7, r0, 0x28
  54. /* add opcode instruction for 32bit jump - 2 instruction imm & brai */
  55. addi r2, r0, 0xb0000000 /* hex b000 opcode imm */
  56. addi r3, r0, 0xb8080000 /* hew b808 opcode brai */
  57. #ifdef CONFIG_SYS_RESET_ADDRESS
  58. /* reset address */
  59. swi r2, r0, 0x0 /* reset address - imm opcode */
  60. swi r3, r0, 0x4 /* reset address - brai opcode */
  61. addik r6, r0, CONFIG_SYS_RESET_ADDRESS
  62. sw r6, r1, r0
  63. lhu r7, r1, r10
  64. rsubi r8, r10, 0x2
  65. sh r7, r0, r8
  66. rsubi r8, r10, 0x6
  67. sh r6, r0, r8
  68. #endif
  69. #ifdef CONFIG_SYS_USR_EXCEP
  70. /* user_vector_exception */
  71. swi r2, r0, 0x8 /* user vector exception - imm opcode */
  72. swi r3, r0, 0xC /* user vector exception - brai opcode */
  73. addik r6, r0, _exception_handler
  74. sw r6, r1, r0
  75. /*
  76. * BIG ENDIAN memory map for user exception
  77. * 0x8: 0xB000XXXX
  78. * 0xC: 0xB808XXXX
  79. *
  80. * then it is necessary to count address for storing the most significant
  81. * 16bits from _exception_handler address and copy it to
  82. * 0xa address. Big endian use offset in r10=0 that's why is it just
  83. * 0xa address. The same is done for the least significant 16 bits
  84. * for 0xe address.
  85. *
  86. * LITTLE ENDIAN memory map for user exception
  87. * 0x8: 0xXXXX00B0
  88. * 0xC: 0xXXXX08B8
  89. *
  90. * Offset is for little endian setup to 0x2. rsubi instruction decrease
  91. * address value to ensure that points to proper place which is
  92. * 0x8 for the most significant 16 bits and
  93. * 0xC for the least significant 16 bits
  94. */
  95. lhu r7, r1, r10
  96. rsubi r8, r10, 0xa
  97. sh r7, r0, r8
  98. rsubi r8, r10, 0xe
  99. sh r6, r0, r8
  100. #endif
  101. #ifdef CONFIG_SYS_INTC_0
  102. /* interrupt_handler */
  103. swi r2, r0, 0x10 /* interrupt - imm opcode */
  104. swi r3, r0, 0x14 /* interrupt - brai opcode */
  105. addik r6, r0, _interrupt_handler
  106. sw r6, r1, r0
  107. lhu r7, r1, r10
  108. rsubi r8, r10, 0x12
  109. sh r7, r0, r8
  110. rsubi r8, r10, 0x16
  111. sh r6, r0, r8
  112. #endif
  113. /* hardware exception */
  114. swi r2, r0, 0x20 /* hardware exception - imm opcode */
  115. swi r3, r0, 0x24 /* hardware exception - brai opcode */
  116. addik r6, r0, _hw_exception_handler
  117. sw r6, r1, r0
  118. lhu r7, r1, r10
  119. rsubi r8, r10, 0x22
  120. sh r7, r0, r8
  121. rsubi r8, r10, 0x26
  122. sh r6, r0, r8
  123. /* enable instruction and data cache */
  124. mfs r12, rmsr
  125. ori r12, r12, 0xa0
  126. mts rmsr, r12
  127. clear_bss:
  128. /* clear BSS segments */
  129. addi r5, r0, __bss_start
  130. addi r4, r0, __bss_end
  131. cmp r6, r5, r4
  132. beqi r6, 3f
  133. 2:
  134. swi r0, r5, 0 /* write zero to loc */
  135. addi r5, r5, 4 /* increment to next loc */
  136. cmp r6, r5, r4 /* check if we have reach the end */
  137. bnei r6, 2b
  138. 3: /* jumping to board_init */
  139. brai board_init
  140. 1: bri 1b
  141. /*
  142. * Read 16bit little endian
  143. */
  144. .text
  145. .global in16
  146. .ent in16
  147. .align 2
  148. in16: lhu r3, r0, r5
  149. bslli r4, r3, 8
  150. bsrli r3, r3, 8
  151. andi r4, r4, 0xffff
  152. or r3, r3, r4
  153. rtsd r15, 8
  154. sext16 r3, r3
  155. .end in16
  156. /*
  157. * Write 16bit little endian
  158. * first parameter(r5) - address, second(r6) - short value
  159. */
  160. .text
  161. .global out16
  162. .ent out16
  163. .align 2
  164. out16: bslli r3, r6, 8
  165. bsrli r6, r6, 8
  166. andi r3, r3, 0xffff
  167. or r3, r3, r6
  168. sh r3, r0, r5
  169. rtsd r15, 8
  170. or r0, r0, r0
  171. .end out16