start.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * U-boot - i386 Startup Code
  3. *
  4. * Copyright (c) 2002 Omicron Ceti AB, Daniel Engström <denaiel@omicron.se>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <config.h>
  25. #include <version.h>
  26. .section .text
  27. .code32
  28. .globl _start
  29. .type _start, @function
  30. .globl _i386boot_start
  31. _i386boot_start:
  32. _start:
  33. movl $0x18,%eax /* Load our segement registes, the
  34. * gdt have already been loaded by start16.S */
  35. movw %ax,%fs
  36. movw %ax,%ds
  37. movw %ax,%gs
  38. movw %ax,%es
  39. movw %ax,%ss
  40. /* We call a few functions in the board support package
  41. * since we have no stack yet we'll have to use %ebp
  42. * to store the return address */
  43. /* Early platform init (setup gpio, etc ) */
  44. mov $early_board_init_ret, %ebp
  45. jmp early_board_init
  46. early_board_init_ret:
  47. /* The __port80 entry-point should be usabe by now */
  48. /* so we try to indicate progress */
  49. movw $0x01, %ax
  50. movl $.progress0, %ebp
  51. jmp show_boot_progress_asm
  52. .progress0:
  53. /* size memory */
  54. mov $mem_init_ret, %ebp
  55. jmp mem_init
  56. mem_init_ret:
  57. /* check ammount of configured memory
  58. * (we need atleast bss start+bss size+stack size) */
  59. movl $_i386boot_bss_start, %ecx /* BSS start */
  60. addl $_i386boot_bss_size, %ecx /* BSS size */
  61. addl $CONFIG_SYS_STACK_SIZE, %ecx
  62. cmpl %ecx, %eax
  63. jae mem_ok
  64. /* indicate (lack of) progress */
  65. movw $0x81, %ax
  66. movl $.progress0a, %ebp
  67. jmp show_boot_progress_asm
  68. .progress0a:
  69. jmp die
  70. mem_ok:
  71. /* indicate progress */
  72. movw $0x02, %ax
  73. movl $.progress1, %ebp
  74. jmp show_boot_progress_asm
  75. .progress1:
  76. /* create a stack after the bss */
  77. movl $_i386boot_bss_start, %eax
  78. addl $_i386boot_bss_size, %eax
  79. addl $CONFIG_SYS_STACK_SIZE, %eax
  80. movl %eax, %esp
  81. pushl $0
  82. popl %eax
  83. cmpl $0, %eax
  84. jne no_stack
  85. push $0x55aa55aa
  86. popl %ebx
  87. cmpl $0x55aa55aa, %ebx
  88. je stack_ok
  89. no_stack:
  90. /* indicate (lack of) progress */
  91. movw $0x82, %ax
  92. movl $.progress1a, %ebp
  93. jmp show_boot_progress_asm
  94. .progress1a:
  95. jmp die
  96. stack_ok:
  97. /* indicate progress */
  98. movw $0x03, %ax
  99. movl $.progress2, %ebp
  100. jmp show_boot_progress_asm
  101. .progress2:
  102. /* copy data section to ram, size must be 4-byte aligned */
  103. movl $_i386boot_romdata_dest, %edi /* destination address */
  104. movl $_i386boot_romdata_start, %esi /* source address */
  105. movl $_i386boot_romdata_size, %ecx /* number of bytes to copy */
  106. movl %ecx, %eax
  107. andl $3, %eax
  108. jnz data_fail
  109. shrl $2, %ecx /* copy 4 byte each time */
  110. cld
  111. cmpl $0, %ecx
  112. je data_ok
  113. data_segment:
  114. movsl
  115. loop data_segment
  116. jmp data_ok
  117. data_fail:
  118. /* indicate (lack of) progress */
  119. movw $0x83, %ax
  120. movl $.progress2a, %ebp
  121. jmp show_boot_progress_asm
  122. .progress2a:
  123. jmp die
  124. data_ok:
  125. /* indicate progress */
  126. movw $0x04, %ax
  127. movl $.progress3, %ebp
  128. jmp show_boot_progress_asm
  129. .progress3:
  130. /* clear bss section in ram, size must be 4-byte aligned */
  131. movl $_i386boot_bss_start, %edi /* MK_CHG BSS start */
  132. movl $_i386boot_bss_size, %ecx /* BSS size */
  133. movl %ecx, %eax
  134. andl $3, %eax
  135. jnz bss_fail
  136. shrl $2, %ecx /* clear 4 byte each time */
  137. cld
  138. cmpl $0, %ecx
  139. je bss_ok
  140. bss:
  141. movl $0, (%edi)
  142. add $4, %edi
  143. loop bss
  144. jmp bss_ok
  145. bss_fail:
  146. /* indicate (lack of) progress */
  147. movw $0x84, %ax
  148. movl $.progress3a, %ebp
  149. jmp show_boot_progress_asm
  150. .progress3a:
  151. jmp die
  152. bss_ok:
  153. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  154. /* indicate progress */
  155. movw $0x06, %ax
  156. movl $.progress6, %ebp
  157. jmp show_boot_progress_asm
  158. .progress6:
  159. /* copy text section to ram, size must be 4-byte aligned */
  160. movl $CONFIG_SYS_BL_START_RAM, %edi /* destination address */
  161. movl $TEXT_BASE, %esi /* source address */
  162. movl $_i386boot_text_size, %ecx /* number of bytes to copy */
  163. movl %ecx, %eax
  164. andl $3, %eax
  165. jz text_copy /* Already 4-byte aligned */
  166. subl $4, %eax /* Add extra bytes to size */
  167. addl %eax, %ecx
  168. text_copy:
  169. shrl $2, %ecx /* copy 4 byte each time */
  170. cld
  171. cmpl $0, %ecx
  172. je text_ok
  173. text_segment:
  174. movsl
  175. loop text_segment
  176. jmp text_ok
  177. text_fail:
  178. /* indicate (lack of) progress */
  179. movw $0x86, %ax
  180. movl $.progress5a, %ebp
  181. jmp show_boot_progress_asm
  182. .progress5a:
  183. jmp die
  184. text_ok:
  185. #endif
  186. wbinvd
  187. /* indicate progress */
  188. movw $0x05, %ax
  189. movl $.progress4, %ebp
  190. jmp show_boot_progress_asm
  191. .progress4:
  192. #ifndef CONFIG_SKIP_RELOCATE_UBOOT
  193. /* Jump to the RAM copy of start_i386boot */
  194. movl $start_i386boot, %ebp
  195. addl $(CONFIG_SYS_BL_START_RAM - TEXT_BASE), %ebp
  196. call *%ebp /* Enter, U-boot! */
  197. #else
  198. call start_i386boot /* Enter, U-boot! */
  199. #endif
  200. /* indicate (lack of) progress */
  201. movw $0x85, %ax
  202. movl $.progress4a, %ebp
  203. jmp show_boot_progress_asm
  204. .progress4a:
  205. die: hlt
  206. jmp die
  207. hlt