start.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * U-boot - x86 Startup Code
  3. *
  4. * (C) Copyright 2008-2011
  5. * Graeme Russ, <graeme.russ@gmail.com>
  6. *
  7. * (C) Copyright 2002
  8. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  9. *
  10. * See file CREDITS for list of people who contributed to this
  11. * project.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <config.h>
  29. #include <version.h>
  30. #include <asm/global_data.h>
  31. #include <asm/processor.h>
  32. #include <asm/processor-flags.h>
  33. #include <generated/generic-asm-offsets.h>
  34. .section .text
  35. .code32
  36. .globl _start
  37. .type _start, @function
  38. .globl _x86boot_start
  39. _x86boot_start:
  40. /*
  41. * This is the fail safe 32-bit bootstrap entry point. The
  42. * following code is not executed from a cold-reset (actually, a
  43. * lot of it is, but from real-mode after cold reset. It is
  44. * repeated here to put the board into a state as close to cold
  45. * reset as necessary)
  46. */
  47. cli
  48. cld
  49. /* Turn off cache (this might require a 486-class CPU) */
  50. movl %cr0, %eax
  51. orl $(X86_CR0_NW | X86_CR0_CD), %eax
  52. movl %eax, %cr0
  53. wbinvd
  54. /* Tell 32-bit code it is being entered from an in-RAM copy */
  55. movw $GD_FLG_WARM_BOOT, %bx
  56. jmp 1f
  57. _start:
  58. /*
  59. * This is the 32-bit cold-reset entry point. Initialize %bx to 0
  60. * in case we're preceeded by some sort of boot stub.
  61. */
  62. movw $GD_FLG_COLD_BOOT, %bx
  63. 1:
  64. /* Load the segement registes to match the gdt loaded in start16.S */
  65. movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
  66. movw %ax, %fs
  67. movw %ax, %ds
  68. movw %ax, %gs
  69. movw %ax, %es
  70. movw %ax, %ss
  71. /* Clear the interrupt vectors */
  72. lidt blank_idt_ptr
  73. /* Early platform init (setup gpio, etc ) */
  74. jmp early_board_init
  75. .globl early_board_init_ret
  76. early_board_init_ret:
  77. /* Initialise Cache-As-RAM */
  78. jmp car_init
  79. .globl car_init_ret
  80. car_init_ret:
  81. /*
  82. * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
  83. * or fully initialised SDRAM - we really don't care which)
  84. * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
  85. */
  86. /* Stack grows down from top of CAR */
  87. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE), %esp
  88. /* Reserve space on stack for global data */
  89. subl $GENERATED_GBL_DATA_SIZE, %esp
  90. /* Align global data to 16-byte boundary */
  91. andl $0xfffffff0, %esp
  92. /* Setup first parameter to setup_gdt */
  93. movl %esp, %eax
  94. /* Reserve space for global descriptor table */
  95. subl $X86_GDT_SIZE, %esp
  96. /* Align temporary global descriptor table to 16-byte boundary */
  97. andl $0xfffffff0, %esp
  98. /* Set second parameter to setup_gdt */
  99. movl %esp, %edx
  100. /* gd->gd_addr = gd (Required to allow gd->xyz to work) */
  101. movl %eax, (%eax)
  102. /* Setup global descriptor table so gd->xyz works */
  103. call setup_gdt
  104. /* Set parameter to board_init_f() to boot flags */
  105. xorl %eax, %eax
  106. movw %bx, %ax
  107. /* Enter, U-boot! */
  108. call board_init_f
  109. /* indicate (lack of) progress */
  110. movw $0x85, %ax
  111. jmp die
  112. .globl board_init_f_r_trampoline
  113. .type board_init_f_r_trampoline, @function
  114. board_init_f_r_trampoline:
  115. /*
  116. * SDRAM has been initialised, U-Boot code has been copied into
  117. * RAM, BSS has been cleared and relocation adjustments have been
  118. * made. It is now time to jump into the in-RAM copy of U-Boot
  119. *
  120. * %eax = Address of top of new stack
  121. */
  122. /* Stack grows down from top of SDRAM */
  123. movl %eax, %esp
  124. /* Reserve space on stack for global data */
  125. subl $GENERATED_GBL_DATA_SIZE, %esp
  126. /* Align global data to 16-byte boundary */
  127. andl $0xfffffff0, %esp
  128. /* Setup first parameter to memcpy (and setup_gdt) */
  129. movl %esp, %eax
  130. /* Setup second parameter to memcpy */
  131. fs movl 0, %edx
  132. /* Set third parameter to memcpy */
  133. movl $GENERATED_GBL_DATA_SIZE, %ecx
  134. /* Copy global data from CAR to SDRAM stack */
  135. call memcpy
  136. /* Reserve space for global descriptor table */
  137. subl $X86_GDT_SIZE, %esp
  138. /* Align global descriptor table to 16-byte boundary */
  139. andl $0xfffffff0, %esp
  140. /* Set second parameter to setup_gdt */
  141. movl %esp, %edx
  142. /* gd->gd_addr = gd (Required to allow gd->xyz to work) */
  143. movl %eax, (%eax)
  144. /* Setup global descriptor table so gd->xyz works */
  145. call setup_gdt
  146. /* Re-enter U-Boot by calling board_init_f_r */
  147. call board_init_f_r
  148. die:
  149. hlt
  150. jmp die
  151. hlt
  152. blank_idt_ptr:
  153. .word 0 /* limit */
  154. .long 0 /* base */
  155. .p2align 2 /* force 4-byte alignment */
  156. multiboot_header:
  157. /* magic */
  158. .long 0x1BADB002
  159. /* flags */
  160. .long (1 << 16)
  161. /* checksum */
  162. .long -0x1BADB002 - (1 << 16)
  163. /* header addr */
  164. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  165. /* load addr */
  166. .long CONFIG_SYS_TEXT_BASE
  167. /* load end addr */
  168. .long 0
  169. /* bss end addr */
  170. .long 0
  171. /* entry addr */
  172. .long CONFIG_SYS_TEXT_BASE