start.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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.
  27. *
  28. * This code is used when booting from another boot loader like
  29. * coreboot or EFI. So we repeat some of the same init found in
  30. * start16.
  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. movl $GD_FLG_WARM_BOOT, %ebx
  41. jmp 1f
  42. /* Add a way for tools to discover the _start entry point */
  43. .align 4
  44. .long 0x12345678
  45. _start:
  46. /*
  47. * This is the 32-bit cold-reset entry point, coming from start16.
  48. * Set %ebx to GD_FLG_COLD_BOOT to indicate this.
  49. */
  50. movl $GD_FLG_COLD_BOOT, %ebx
  51. 1:
  52. /* Save BIST */
  53. movl %eax, %ebp
  54. /* Load the segement registers to match the GDT loaded in start16.S */
  55. movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
  56. movw %ax, %fs
  57. movw %ax, %ds
  58. movw %ax, %gs
  59. movw %ax, %es
  60. movw %ax, %ss
  61. /* Clear the interrupt vectors */
  62. lidt blank_idt_ptr
  63. /*
  64. * Critical early platform init - generally not used, we prefer init
  65. * to happen later when we have a console, in case something goes
  66. * wrong.
  67. */
  68. jmp early_board_init
  69. .globl early_board_init_ret
  70. early_board_init_ret:
  71. post_code(POST_START)
  72. /* Initialise Cache-As-RAM */
  73. jmp car_init
  74. .globl car_init_ret
  75. car_init_ret:
  76. #ifndef CONFIG_HAVE_FSP
  77. /*
  78. * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
  79. * or fully initialised SDRAM - we really don't care which)
  80. * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
  81. * and early malloc() area. The MRC requires some space at the top.
  82. *
  83. * Stack grows down from top of CAR. We have:
  84. *
  85. * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE
  86. * MRC area
  87. * global_data
  88. * x86 global descriptor table
  89. * early malloc area
  90. * stack
  91. * bottom-> CONFIG_SYS_CAR_ADDR
  92. */
  93. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - 4), %esp
  94. #ifdef CONFIG_DCACHE_RAM_MRC_VAR_SIZE
  95. subl $CONFIG_DCACHE_RAM_MRC_VAR_SIZE, %esp
  96. #endif
  97. #else
  98. /*
  99. * When we get here after car_init(), esp points to a temporary stack
  100. * and esi holds the HOB list address returned by the FSP.
  101. */
  102. #endif
  103. /* Reserve space on stack for global data */
  104. subl $GENERATED_GBL_DATA_SIZE, %esp
  105. /* Align global data to 16-byte boundary */
  106. andl $0xfffffff0, %esp
  107. post_code(POST_START_STACK)
  108. /* Zero the global data since it won't happen later */
  109. xorl %eax, %eax
  110. movl $GENERATED_GBL_DATA_SIZE, %ecx
  111. movl %esp, %edi
  112. rep stosb
  113. #ifdef CONFIG_HAVE_FSP
  114. test %esi, %esi
  115. jz skip_hob
  116. /* Store HOB list */
  117. movl %esp, %edx
  118. addl $GD_HOB_LIST, %edx
  119. movl %esi, (%edx)
  120. skip_hob:
  121. #endif
  122. /* Setup first parameter to setup_gdt, pointer to global_data */
  123. movl %esp, %eax
  124. /* Reserve space for global descriptor table */
  125. subl $X86_GDT_SIZE, %esp
  126. /* Align temporary global descriptor table to 16-byte boundary */
  127. andl $0xfffffff0, %esp
  128. movl %esp, %ecx
  129. #if defined(CONFIG_SYS_MALLOC_F_LEN)
  130. /* Set up the pre-relocation malloc pool */
  131. subl $CONFIG_SYS_MALLOC_F_LEN, %esp
  132. movl %eax, %edx
  133. addl $GD_MALLOC_BASE, %edx
  134. movl %esp, (%edx)
  135. #endif
  136. /* Store BIST into global_data */
  137. movl %eax, %edx
  138. addl $GD_BIST, %edx
  139. movl %ebp, (%edx)
  140. /* Set second parameter to setup_gdt() */
  141. movl %ecx, %edx
  142. /* Setup global descriptor table so gd->xyz works */
  143. call setup_gdt
  144. /* Set parameter to board_init_f() to boot flags */
  145. post_code(POST_START_DONE)
  146. xorl %eax, %eax
  147. /* Enter, U-Boot! */
  148. call board_init_f
  149. /* indicate (lack of) progress */
  150. movw $0x85, %ax
  151. jmp die
  152. .globl board_init_f_r_trampoline
  153. .type board_init_f_r_trampoline, @function
  154. board_init_f_r_trampoline:
  155. /*
  156. * SDRAM has been initialised, U-Boot code has been copied into
  157. * RAM, BSS has been cleared and relocation adjustments have been
  158. * made. It is now time to jump into the in-RAM copy of U-Boot
  159. *
  160. * %eax = Address of top of new stack
  161. */
  162. /* Stack grows down from top of SDRAM */
  163. movl %eax, %esp
  164. /* Reserve space on stack for global data */
  165. subl $GENERATED_GBL_DATA_SIZE, %esp
  166. /* Align global data to 16-byte boundary */
  167. andl $0xfffffff0, %esp
  168. /* Setup first parameter to memcpy() and setup_gdt() */
  169. movl %esp, %eax
  170. /* Setup second parameter to memcpy() */
  171. fs movl 0, %edx
  172. /* Set third parameter to memcpy() */
  173. movl $GENERATED_GBL_DATA_SIZE, %ecx
  174. /* Copy global data from CAR to SDRAM stack */
  175. call memcpy
  176. /* Reserve space for global descriptor table */
  177. subl $X86_GDT_SIZE, %esp
  178. /* Align global descriptor table to 16-byte boundary */
  179. andl $0xfffffff0, %esp
  180. /* Set second parameter to setup_gdt() */
  181. movl %esp, %edx
  182. /* Setup global descriptor table so gd->xyz works */
  183. call setup_gdt
  184. /* Set if we need to disable CAR */
  185. .weak car_uninit
  186. movl $car_uninit, %eax
  187. cmpl $0, %eax
  188. jz 1f
  189. call car_uninit
  190. 1:
  191. /* Re-enter U-Boot by calling board_init_f_r() */
  192. call board_init_f_r
  193. die:
  194. hlt
  195. jmp die
  196. hlt
  197. blank_idt_ptr:
  198. .word 0 /* limit */
  199. .long 0 /* base */
  200. .p2align 2 /* force 4-byte alignment */
  201. /* Add a multiboot header so U-Boot can be loaded by GRUB2 */
  202. multiboot_header:
  203. /* magic */
  204. .long 0x1badb002
  205. /* flags */
  206. .long (1 << 16)
  207. /* checksum */
  208. .long -0x1BADB002 - (1 << 16)
  209. /* header addr */
  210. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  211. /* load addr */
  212. .long CONFIG_SYS_TEXT_BASE
  213. /* load end addr */
  214. .long 0
  215. /* bss end addr */
  216. .long 0
  217. /* entry addr */
  218. .long CONFIG_SYS_TEXT_BASE