start.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_mem
  114. mov %eax, %esp
  115. #ifdef CONFIG_DEBUG_UART
  116. call debug_uart_init
  117. #endif
  118. /* Get address of global_data */
  119. mov %fs:0, %edx
  120. #ifdef CONFIG_HAVE_FSP
  121. /* Store the HOB list if we have one */
  122. test %esi, %esi
  123. jz skip_hob
  124. movl %esi, GD_HOB_LIST(%edx)
  125. /*
  126. * After fsp_init() returns, the stack has already been switched to a
  127. * place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR.
  128. * Enlarge the size of malloc() pool before relocation since we have
  129. * plenty of memory now.
  130. */
  131. subl $CONFIG_FSP_SYS_MALLOC_F_LEN, %esp
  132. movl %esp, GD_MALLOC_BASE(%edx)
  133. skip_hob:
  134. #else
  135. /* Store table pointer */
  136. movl %esi, GD_TABLE(%edx)
  137. #endif
  138. /* Store BIST */
  139. movl %ebp, GD_BIST(%edx)
  140. /* Set parameter to board_init_f() to boot flags */
  141. post_code(POST_START_DONE)
  142. xorl %eax, %eax
  143. /* Enter, U-Boot! */
  144. call board_init_f
  145. /* indicate (lack of) progress */
  146. movw $0x85, %ax
  147. jmp die
  148. .globl board_init_f_r_trampoline
  149. .type board_init_f_r_trampoline, @function
  150. board_init_f_r_trampoline:
  151. /*
  152. * SDRAM has been initialised, U-Boot code has been copied into
  153. * RAM, BSS has been cleared and relocation adjustments have been
  154. * made. It is now time to jump into the in-RAM copy of U-Boot
  155. *
  156. * %eax = Address of top of new stack
  157. */
  158. /* Stack grows down from top of SDRAM */
  159. movl %eax, %esp
  160. /* See if we need to disable CAR */
  161. .weak car_uninit
  162. movl $car_uninit, %eax
  163. cmpl $0, %eax
  164. jz 1f
  165. call car_uninit
  166. 1:
  167. /* Re-enter U-Boot by calling board_init_f_r() */
  168. call board_init_f_r
  169. die:
  170. hlt
  171. jmp die
  172. hlt
  173. blank_idt_ptr:
  174. .word 0 /* limit */
  175. .long 0 /* base */
  176. .p2align 2 /* force 4-byte alignment */
  177. /* Add a multiboot header so U-Boot can be loaded by GRUB2 */
  178. multiboot_header:
  179. /* magic */
  180. .long 0x1badb002
  181. /* flags */
  182. .long (1 << 16)
  183. /* checksum */
  184. .long -0x1BADB002 - (1 << 16)
  185. /* header addr */
  186. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  187. /* load addr */
  188. .long CONFIG_SYS_TEXT_BASE
  189. /* load end addr */
  190. .long 0
  191. /* bss end addr */
  192. .long 0
  193. /* entry addr */
  194. .long CONFIG_SYS_TEXT_BASE