start.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. * SPDX-License-Identifier: GPL-2.0+
  11. */
  12. #include <config.h>
  13. #include <asm/global_data.h>
  14. #include <asm/post.h>
  15. #include <asm/processor.h>
  16. #include <asm/processor-flags.h>
  17. #include <generated/generic-asm-offsets.h>
  18. #include <generated/asm-offsets.h>
  19. .section .text
  20. .code32
  21. .globl _start
  22. .type _start, @function
  23. .globl _x86boot_start
  24. _x86boot_start:
  25. /*
  26. * This is the fail safe 32-bit bootstrap entry point. The
  27. * following code is not executed from a cold-reset (actually, a
  28. * lot of it is, but from real-mode after cold reset. It is
  29. * repeated here to put the board into a state as close to cold
  30. * reset as necessary)
  31. */
  32. cli
  33. cld
  34. /* Turn off cache (this might require a 486-class CPU) */
  35. movl %cr0, %eax
  36. orl $(X86_CR0_NW | X86_CR0_CD), %eax
  37. movl %eax, %cr0
  38. wbinvd
  39. /* Tell 32-bit code it is being entered from an in-RAM copy */
  40. movw $GD_FLG_WARM_BOOT, %bx
  41. jmp 1f
  42. _start:
  43. /*
  44. * This is the 32-bit cold-reset entry point. Initialize %bx to 0
  45. * in case we're preceeded by some sort of boot stub.
  46. */
  47. movw $GD_FLG_COLD_BOOT, %bx
  48. 1:
  49. /* Save BIST */
  50. movl %eax, %ebp
  51. /* Load the segement registes to match the gdt loaded in start16.S */
  52. movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
  53. movw %ax, %fs
  54. movw %ax, %ds
  55. movw %ax, %gs
  56. movw %ax, %es
  57. movw %ax, %ss
  58. /* Clear the interrupt vectors */
  59. lidt blank_idt_ptr
  60. /* Early platform init (setup gpio, etc ) */
  61. jmp early_board_init
  62. .globl early_board_init_ret
  63. early_board_init_ret:
  64. post_code(POST_START)
  65. /* Initialise Cache-As-RAM */
  66. jmp car_init
  67. .globl car_init_ret
  68. car_init_ret:
  69. #ifndef CONFIG_HAVE_FSP
  70. /*
  71. * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
  72. * or fully initialised SDRAM - we really don't care which)
  73. * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
  74. * and early malloc area. The MRC requires some space at the top.
  75. *
  76. * Stack grows down from top of CAR. We have:
  77. *
  78. * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE
  79. * MRC area
  80. * global_data
  81. * x86 global descriptor table
  82. * early malloc area
  83. * stack
  84. * bottom-> CONFIG_SYS_CAR_ADDR
  85. */
  86. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - 4), %esp
  87. #ifdef CONFIG_DCACHE_RAM_MRC_VAR_SIZE
  88. subl $CONFIG_DCACHE_RAM_MRC_VAR_SIZE, %esp
  89. #endif
  90. #else
  91. /*
  92. * When we get here after car_init, esp points to a temporary stack
  93. * and esi holds the HOB list address returned by the FSP.
  94. */
  95. #endif
  96. /* Reserve space on stack for global data */
  97. subl $GENERATED_GBL_DATA_SIZE, %esp
  98. /* Align global data to 16-byte boundary */
  99. andl $0xfffffff0, %esp
  100. post_code(POST_START_STACK)
  101. /* Zero the global data since it won't happen later */
  102. xorl %eax, %eax
  103. movl $GENERATED_GBL_DATA_SIZE, %ecx
  104. movl %esp, %edi
  105. rep stosb
  106. #ifdef CONFIG_HAVE_FSP
  107. test %esi, %esi
  108. jz skip_hob
  109. /* Store HOB list */
  110. movl %esp, %edx
  111. addl $GD_HOB_LIST, %edx
  112. movl %esi, (%edx)
  113. skip_hob:
  114. #endif
  115. /* Setup first parameter to setup_gdt, pointer to global_data */
  116. movl %esp, %eax
  117. /* Reserve space for global descriptor table */
  118. subl $X86_GDT_SIZE, %esp
  119. /* Align temporary global descriptor table to 16-byte boundary */
  120. andl $0xfffffff0, %esp
  121. movl %esp, %ecx
  122. #if defined(CONFIG_SYS_MALLOC_F_LEN)
  123. subl $CONFIG_SYS_MALLOC_F_LEN, %esp
  124. movl %eax, %edx
  125. addl $GD_MALLOC_BASE, %edx
  126. movl %esp, (%edx)
  127. #endif
  128. /* Store BIST */
  129. movl %eax, %edx
  130. addl $GD_BIST, %edx
  131. movl %ebp, (%edx)
  132. /* Set second parameter to setup_gdt */
  133. movl %ecx, %edx
  134. /* Setup global descriptor table so gd->xyz works */
  135. call setup_gdt
  136. /* Set parameter to board_init_f() to boot flags */
  137. post_code(POST_START_DONE)
  138. xorl %eax, %eax
  139. /* Enter, U-boot! */
  140. call board_init_f
  141. /* indicate (lack of) progress */
  142. movw $0x85, %ax
  143. jmp die
  144. .globl board_init_f_r_trampoline
  145. .type board_init_f_r_trampoline, @function
  146. board_init_f_r_trampoline:
  147. /*
  148. * SDRAM has been initialised, U-Boot code has been copied into
  149. * RAM, BSS has been cleared and relocation adjustments have been
  150. * made. It is now time to jump into the in-RAM copy of U-Boot
  151. *
  152. * %eax = Address of top of new stack
  153. */
  154. /* Stack grows down from top of SDRAM */
  155. movl %eax, %esp
  156. /* Reserve space on stack for global data */
  157. subl $GENERATED_GBL_DATA_SIZE, %esp
  158. /* Align global data to 16-byte boundary */
  159. andl $0xfffffff0, %esp
  160. /* Setup first parameter to memcpy (and setup_gdt) */
  161. movl %esp, %eax
  162. /* Setup second parameter to memcpy */
  163. fs movl 0, %edx
  164. /* Set third parameter to memcpy */
  165. movl $GENERATED_GBL_DATA_SIZE, %ecx
  166. /* Copy global data from CAR to SDRAM stack */
  167. call memcpy
  168. /* Reserve space for global descriptor table */
  169. subl $X86_GDT_SIZE, %esp
  170. /* Align global descriptor table to 16-byte boundary */
  171. andl $0xfffffff0, %esp
  172. /* Set second parameter to setup_gdt */
  173. movl %esp, %edx
  174. /* Setup global descriptor table so gd->xyz works */
  175. call setup_gdt
  176. /* Set if we need to disable CAR */
  177. .weak car_uninit
  178. movl $car_uninit, %eax
  179. cmpl $0, %eax
  180. jz 1f
  181. call car_uninit
  182. 1:
  183. /* Re-enter U-Boot by calling board_init_f_r */
  184. call board_init_f_r
  185. die:
  186. hlt
  187. jmp die
  188. hlt
  189. blank_idt_ptr:
  190. .word 0 /* limit */
  191. .long 0 /* base */
  192. .p2align 2 /* force 4-byte alignment */
  193. multiboot_header:
  194. /* magic */
  195. .long 0x1BADB002
  196. /* flags */
  197. .long (1 << 16)
  198. /* checksum */
  199. .long -0x1BADB002 - (1 << 16)
  200. /* header addr */
  201. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  202. /* load addr */
  203. .long CONFIG_SYS_TEXT_BASE
  204. /* load end addr */
  205. .long 0
  206. /* bss end addr */
  207. .long 0
  208. /* entry addr */
  209. .long CONFIG_SYS_TEXT_BASE