start.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <config.h>
  27. .text
  28. .global _start
  29. _start:
  30. mts rmsr, r0 /* disable cache */
  31. addi r1, r0, CONFIG_SYS_INIT_SP_OFFSET
  32. addi r1, r1, -4 /* Decrement SP to top of memory */
  33. /* add opcode instruction for 32bit jump - 2 instruction imm & brai*/
  34. addi r6, r0, 0xb0000000 /* hex b000 opcode imm */
  35. swi r6, r0, 0x0 /* reset address */
  36. swi r6, r0, 0x8 /* user vector exception */
  37. swi r6, r0, 0x10 /* interrupt */
  38. swi r6, r0, 0x20 /* hardware exception */
  39. addi r6, r0, 0xb8080000 /* hew b808 opcode brai*/
  40. swi r6, r0, 0x4 /* reset address */
  41. swi r6, r0, 0xC /* user vector exception */
  42. swi r6, r0, 0x14 /* interrupt */
  43. swi r6, r0, 0x24 /* hardware exception */
  44. #ifdef CONFIG_SYS_RESET_ADDRESS
  45. /* reset address */
  46. addik r6, r0, CONFIG_SYS_RESET_ADDRESS
  47. sw r6, r1, r0
  48. lhu r7, r1, r0
  49. shi r7, r0, 0x2
  50. shi r6, r0, 0x6
  51. /*
  52. * Copy U-Boot code to TEXT_BASE
  53. * solve problem with sbrk_base
  54. */
  55. #if (CONFIG_SYS_RESET_ADDRESS != TEXT_BASE)
  56. addi r4, r0, __end
  57. addi r5, r0, __text_start
  58. rsub r4, r5, r4 /* size = __end - __text_start */
  59. addi r6, r0, CONFIG_SYS_RESET_ADDRESS /* source address */
  60. addi r7, r0, 0 /* counter */
  61. 4:
  62. lw r8, r6, r7
  63. sw r8, r5, r7
  64. addi r7, r7, 0x4
  65. cmp r8, r4, r7
  66. blti r8, 4b
  67. #endif
  68. #endif
  69. #ifdef CONFIG_SYS_USR_EXCEP
  70. /* user_vector_exception */
  71. addik r6, r0, _exception_handler
  72. sw r6, r1, r0
  73. lhu r7, r1, r0
  74. shi r7, r0, 0xa
  75. shi r6, r0, 0xe
  76. #endif
  77. #ifdef CONFIG_SYS_INTC_0
  78. /* interrupt_handler */
  79. addik r6, r0, _interrupt_handler
  80. sw r6, r1, r0
  81. lhu r7, r1, r0
  82. shi r7, r0, 0x12
  83. shi r6, r0, 0x16
  84. #endif
  85. /* hardware exception */
  86. addik r6, r0, _hw_exception_handler
  87. sw r6, r1, r0
  88. lhu r7, r1, r0
  89. shi r7, r0, 0x22
  90. shi r6, r0, 0x26
  91. /* enable instruction and data cache */
  92. mfs r12, rmsr
  93. ori r12, r12, 0xa0
  94. mts rmsr, r12
  95. clear_bss:
  96. /* clear BSS segments */
  97. addi r5, r0, __bss_start
  98. addi r4, r0, __bss_end
  99. cmp r6, r5, r4
  100. beqi r6, 3f
  101. 2:
  102. swi r0, r5, 0 /* write zero to loc */
  103. addi r5, r5, 4 /* increment to next loc */
  104. cmp r6, r5, r4 /* check if we have reach the end */
  105. bnei r6, 2b
  106. 3: /* jumping to board_init */
  107. brai board_init
  108. 1: bri 1b
  109. /*
  110. * Read 16bit little endian
  111. */
  112. .text
  113. .global in16
  114. .ent in16
  115. .align 2
  116. in16: lhu r3, r0, r5
  117. bslli r4, r3, 8
  118. bsrli r3, r3, 8
  119. andi r4, r4, 0xffff
  120. or r3, r3, r4
  121. rtsd r15, 8
  122. sext16 r3, r3
  123. .end in16
  124. /*
  125. * Write 16bit little endian
  126. * first parameter(r5) - address, second(r6) - short value
  127. */
  128. .text
  129. .global out16
  130. .ent out16
  131. .align 2
  132. out16: bslli r3, r6, 8
  133. bsrli r6, r6, 8
  134. andi r3, r3, 0xffff
  135. or r3, r3, r6
  136. sh r3, r0, r5
  137. rtsd r15, 8
  138. or r0, r0, r0
  139. .end out16