start.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. /*
  42. * Zero the BIST (Built-In Self Test) value since we don't have it.
  43. * It must be 0 or the previous loader would have reported an error.
  44. */
  45. movl $0, %ebp
  46. jmp 1f
  47. /* Add a way for tools to discover the _start entry point */
  48. .align 4
  49. .long 0x12345678
  50. _start:
  51. /*
  52. * This is the 32-bit cold-reset entry point, coming from start16.
  53. * Set %ebx to GD_FLG_COLD_BOOT to indicate this.
  54. */
  55. movl $GD_FLG_COLD_BOOT, %ebx
  56. /* Save BIST */
  57. movl %eax, %ebp
  58. 1:
  59. /* Save table pointer */
  60. movl %ecx, %esi
  61. /* Load the segement registers to match the GDT loaded in start16.S */
  62. movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
  63. movw %ax, %fs
  64. movw %ax, %ds
  65. movw %ax, %gs
  66. movw %ax, %es
  67. movw %ax, %ss
  68. /* Clear the interrupt vectors */
  69. lidt blank_idt_ptr
  70. /*
  71. * Critical early platform init - generally not used, we prefer init
  72. * to happen later when we have a console, in case something goes
  73. * wrong.
  74. */
  75. jmp early_board_init
  76. .globl early_board_init_ret
  77. early_board_init_ret:
  78. post_code(POST_START)
  79. /* Initialise Cache-As-RAM */
  80. jmp car_init
  81. .globl car_init_ret
  82. car_init_ret:
  83. #ifndef CONFIG_HAVE_FSP
  84. /*
  85. * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
  86. * or fully initialised SDRAM - we really don't care which)
  87. * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
  88. * and early malloc() area. The MRC requires some space at the top.
  89. *
  90. * Stack grows down from top of CAR. We have:
  91. *
  92. * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE
  93. * MRC area
  94. * global_data with x86 global descriptor table
  95. * early malloc area
  96. * stack
  97. * bottom-> CONFIG_SYS_CAR_ADDR
  98. */
  99. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - 4), %esp
  100. #ifdef CONFIG_DCACHE_RAM_MRC_VAR_SIZE
  101. subl $CONFIG_DCACHE_RAM_MRC_VAR_SIZE, %esp
  102. #endif
  103. #else
  104. /*
  105. * U-Boot enters here twice. For the first time it comes from
  106. * car_init_done() with esp points to a temporary stack and esi
  107. * set to zero. For the second time it comes from fsp_init_done()
  108. * with esi holding the HOB list address returned by the FSP.
  109. */
  110. #endif
  111. /* Set up global data */
  112. mov %esp, %eax
  113. call board_init_f_alloc_reserve
  114. mov %eax, %esp
  115. call board_init_f_init_reserve
  116. #ifdef CONFIG_DEBUG_UART
  117. call debug_uart_init
  118. #endif
  119. /* Get address of global_data */
  120. mov %fs:0, %edx
  121. #ifdef CONFIG_HAVE_FSP
  122. /* Store the HOB list if we have one */
  123. test %esi, %esi
  124. jz skip_hob
  125. movl %esi, GD_HOB_LIST(%edx)
  126. /*
  127. * After fsp_init() returns, the stack has already been switched to a
  128. * place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR.
  129. * Enlarge the size of malloc() pool before relocation since we have
  130. * plenty of memory now.
  131. */
  132. subl $CONFIG_FSP_SYS_MALLOC_F_LEN, %esp
  133. movl %esp, GD_MALLOC_BASE(%edx)
  134. skip_hob:
  135. #else
  136. /* Store table pointer */
  137. movl %esi, GD_TABLE(%edx)
  138. #endif
  139. /* Store BIST */
  140. movl %ebp, GD_BIST(%edx)
  141. /* Set parameter to board_init_f() to boot flags */
  142. post_code(POST_START_DONE)
  143. xorl %eax, %eax
  144. /* Enter, U-Boot! */
  145. call board_init_f
  146. /* indicate (lack of) progress */
  147. movw $0x85, %ax
  148. jmp die
  149. .globl board_init_f_r_trampoline
  150. .type board_init_f_r_trampoline, @function
  151. board_init_f_r_trampoline:
  152. /*
  153. * SDRAM has been initialised, U-Boot code has been copied into
  154. * RAM, BSS has been cleared and relocation adjustments have been
  155. * made. It is now time to jump into the in-RAM copy of U-Boot
  156. *
  157. * %eax = Address of top of new stack
  158. */
  159. /* Stack grows down from top of SDRAM */
  160. movl %eax, %esp
  161. /* See if we need to disable CAR */
  162. .weak car_uninit
  163. movl $car_uninit, %eax
  164. cmpl $0, %eax
  165. jz 1f
  166. call car_uninit
  167. 1:
  168. /* Re-enter U-Boot by calling board_init_f_r() */
  169. call board_init_f_r
  170. die:
  171. hlt
  172. jmp die
  173. hlt
  174. blank_idt_ptr:
  175. .word 0 /* limit */
  176. .long 0 /* base */
  177. .p2align 2 /* force 4-byte alignment */
  178. /* Add a multiboot header so U-Boot can be loaded by GRUB2 */
  179. multiboot_header:
  180. /* magic */
  181. .long 0x1badb002
  182. /* flags */
  183. .long (1 << 16)
  184. /* checksum */
  185. .long -0x1BADB002 - (1 << 16)
  186. /* header addr */
  187. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  188. /* load addr */
  189. .long CONFIG_SYS_TEXT_BASE
  190. /* load end addr */
  191. .long 0
  192. /* bss end addr */
  193. .long 0
  194. /* entry addr */
  195. .long CONFIG_SYS_TEXT_BASE