start.S 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * U-Boot - x86 Startup Code
  4. *
  5. * This is always the first code to run from the U-Boot source. To spell it out:
  6. *
  7. * 1. When TPL (Tertiary Program Loader) is enabled, the boot flow is
  8. * TPL->SPL->U-Boot and this file is used for TPL. Then start_from_tpl.S is used
  9. * for SPL and start_from_spl.S is used for U-Boot proper.
  10. *
  11. * 2. When SPL (Secondary Program Loader) is enabled, but not TPL, the boot
  12. * flow is SPL->U-Boot and this file is used for SPL. Then start_from_spl.S is
  13. * used for U-Boot proper.
  14. *
  15. * 3. When neither TPL nor SPL is used, this file is used for U-Boot proper.
  16. *
  17. * (C) Copyright 2008-2011
  18. * Graeme Russ, <graeme.russ@gmail.com>
  19. *
  20. * (C) Copyright 2002
  21. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  22. */
  23. #include <config.h>
  24. #include <asm/post.h>
  25. #include <asm/processor.h>
  26. #include <asm/processor-flags.h>
  27. #include <generated/generic-asm-offsets.h>
  28. #include <generated/asm-offsets.h>
  29. #include <linux/linkage.h>
  30. .section .text.start
  31. .code32
  32. .globl _start
  33. .type _start, @function
  34. .globl _x86boot_start
  35. _x86boot_start:
  36. /*
  37. * This is the fail-safe 32-bit bootstrap entry point.
  38. *
  39. * This code is used when booting from another boot loader like
  40. * coreboot or EFI. So we repeat some of the same init found in
  41. * start16.
  42. */
  43. cli
  44. cld
  45. /* Turn off cache (this might require a 486-class CPU) */
  46. movl %cr0, %eax
  47. orl $(X86_CR0_NW | X86_CR0_CD), %eax
  48. movl %eax, %cr0
  49. wbinvd
  50. /*
  51. * Zero the BIST (Built-In Self Test) value since we don't have it.
  52. * It must be 0 or the previous loader would have reported an error.
  53. */
  54. movl $0, %ebp
  55. jmp 1f
  56. /* Add a way for tools to discover the _start entry point */
  57. .align 4
  58. .long 0x12345678
  59. _start:
  60. /* This is the 32-bit cold-reset entry point, coming from start16 */
  61. /* Save BIST */
  62. movl %eax, %ebp
  63. 1:
  64. /* Save table pointer */
  65. movl %ecx, %esi
  66. #ifdef CONFIG_X86_LOAD_FROM_32_BIT
  67. lgdt gdt_ptr2
  68. #endif
  69. /* Load the segment registers to match the GDT loaded in start16.S */
  70. movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
  71. movw %ax, %fs
  72. movw %ax, %ds
  73. movw %ax, %gs
  74. movw %ax, %es
  75. movw %ax, %ss
  76. /* Clear the interrupt vectors */
  77. lidt blank_idt_ptr
  78. #ifdef CONFIG_USE_EARLY_BOARD_INIT
  79. /*
  80. * Critical early platform init - generally not used, we prefer init
  81. * to happen later when we have a console, in case something goes
  82. * wrong.
  83. */
  84. jmp early_board_init
  85. .globl early_board_init_ret
  86. early_board_init_ret:
  87. #endif
  88. post_code(POST_START)
  89. /* Initialise Cache-As-RAM */
  90. jmp car_init
  91. .globl car_init_ret
  92. car_init_ret:
  93. #ifdef CONFIG_USE_CAR
  94. /*
  95. * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
  96. * or fully initialised SDRAM - we really don't care which)
  97. * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
  98. * and early malloc() area. The MRC requires some space at the top.
  99. *
  100. * Stack grows down from top of CAR. We have:
  101. *
  102. * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE
  103. * MRC area
  104. * global_data with x86 global descriptor table
  105. * early malloc area
  106. * stack
  107. * bottom-> CONFIG_SYS_CAR_ADDR
  108. */
  109. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - 4), %esp
  110. #ifdef CONFIG_DCACHE_RAM_MRC_VAR_SIZE
  111. subl $CONFIG_DCACHE_RAM_MRC_VAR_SIZE, %esp
  112. #endif
  113. #else
  114. /*
  115. * Instructions for FSP1, but not FSP2:
  116. * U-Boot enters here twice. For the first time it comes from
  117. * car_init_done() with esp points to a temporary stack and esi
  118. * set to zero. For the second time it comes from fsp_init_done()
  119. * with esi holding the HOB list address returned by the FSP.
  120. */
  121. #endif
  122. /* Set up global data */
  123. mov %esp, %eax
  124. call board_init_f_alloc_reserve
  125. mov %eax, %esp
  126. call board_init_f_init_reserve
  127. #ifdef CONFIG_DEBUG_UART
  128. call debug_uart_init
  129. #endif
  130. /* Get address of global_data */
  131. mov %fs:0, %edx
  132. #if defined(CONFIG_USE_HOB) && !defined(CONFIG_USE_CAR)
  133. /* Store the HOB list if we have one */
  134. test %esi, %esi
  135. jz skip_hob
  136. movl %esi, GD_HOB_LIST(%edx)
  137. #ifdef CONFIG_HAVE_FSP
  138. /*
  139. * After fsp_init() returns, the stack has already been switched to a
  140. * place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR.
  141. * Enlarge the size of malloc() pool before relocation since we have
  142. * plenty of memory now.
  143. */
  144. subl $CONFIG_FSP_SYS_MALLOC_F_LEN, %esp
  145. movl %esp, GD_MALLOC_BASE(%edx)
  146. #endif
  147. skip_hob:
  148. #else
  149. /* Store table pointer */
  150. movl %esi, GD_TABLE(%edx)
  151. #endif
  152. /* Store BIST */
  153. movl %ebp, GD_BIST(%edx)
  154. /* Set parameter to board_init_f() to boot flags */
  155. post_code(POST_START_DONE)
  156. xorl %eax, %eax
  157. /* Enter, U-Boot! */
  158. call board_init_f
  159. /* indicate (lack of) progress */
  160. movw $0x85, %ax
  161. jmp die
  162. .globl board_init_f_r_trampoline
  163. .type board_init_f_r_trampoline, @function
  164. board_init_f_r_trampoline:
  165. /*
  166. * SDRAM has been initialised, U-Boot code has been copied into
  167. * RAM, BSS has been cleared and relocation adjustments have been
  168. * made. It is now time to jump into the in-RAM copy of U-Boot
  169. *
  170. * %eax = Address of top of new stack
  171. */
  172. /* Stack grows down from top of SDRAM */
  173. movl %eax, %esp
  174. /* See if we need to disable CAR */
  175. call car_uninit
  176. /* Re-enter U-Boot by calling board_init_f_r() */
  177. call board_init_f_r
  178. #ifdef CONFIG_TPL
  179. .globl jump_to_spl
  180. .type jump_to_spl, @function
  181. jump_to_spl:
  182. /* Reset stack to the top of CAR space */
  183. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - 4), %esp
  184. #ifdef CONFIG_DCACHE_RAM_MRC_VAR_SIZE
  185. subl $CONFIG_DCACHE_RAM_MRC_VAR_SIZE, %esp
  186. #endif
  187. jmp *%eax
  188. #endif
  189. die:
  190. hlt
  191. jmp die
  192. hlt
  193. WEAK(car_uninit)
  194. ret
  195. ENDPROC(car_uninit)
  196. blank_idt_ptr:
  197. .word 0 /* limit */
  198. .long 0 /* base */
  199. .p2align 2 /* force 4-byte alignment */
  200. /* Add a multiboot header so U-Boot can be loaded by GRUB2 */
  201. multiboot_header:
  202. /* magic */
  203. .long 0x1badb002
  204. /* flags */
  205. .long (1 << 16)
  206. /* checksum */
  207. .long -0x1BADB002 - (1 << 16)
  208. /* header addr */
  209. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  210. /* load addr */
  211. .long CONFIG_SYS_TEXT_BASE
  212. /* load end addr */
  213. .long 0
  214. /* bss end addr */
  215. .long 0
  216. /* entry addr */
  217. .long CONFIG_SYS_TEXT_BASE
  218. #ifdef CONFIG_X86_LOAD_FROM_32_BIT
  219. /*
  220. * The following Global Descriptor Table is just enough to get us into
  221. * 'Flat Protected Mode' - It will be discarded as soon as the final
  222. * GDT is setup in a safe location in RAM
  223. */
  224. gdt_ptr2:
  225. .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */
  226. .long gdt_rom2 /* base */
  227. /* Some CPUs are picky about GDT alignment... */
  228. .align 16
  229. .globl gdt_rom2
  230. gdt_rom2:
  231. /*
  232. * The GDT table ...
  233. *
  234. * Selector Type
  235. * 0x00 NULL
  236. * 0x08 Unused
  237. * 0x10 32bit code
  238. * 0x18 32bit data/stack
  239. */
  240. /* The NULL Desciptor - Mandatory */
  241. .word 0x0000 /* limit_low */
  242. .word 0x0000 /* base_low */
  243. .byte 0x00 /* base_middle */
  244. .byte 0x00 /* access */
  245. .byte 0x00 /* flags + limit_high */
  246. .byte 0x00 /* base_high */
  247. /* Unused Desciptor - (matches Linux) */
  248. .word 0x0000 /* limit_low */
  249. .word 0x0000 /* base_low */
  250. .byte 0x00 /* base_middle */
  251. .byte 0x00 /* access */
  252. .byte 0x00 /* flags + limit_high */
  253. .byte 0x00 /* base_high */
  254. /*
  255. * The Code Segment Descriptor:
  256. * - Base = 0x00000000
  257. * - Size = 4GB
  258. * - Access = Present, Ring 0, Exec (Code), Readable
  259. * - Flags = 4kB Granularity, 32-bit
  260. */
  261. .word 0xffff /* limit_low */
  262. .word 0x0000 /* base_low */
  263. .byte 0x00 /* base_middle */
  264. .byte 0x9b /* access */
  265. .byte 0xcf /* flags + limit_high */
  266. .byte 0x00 /* base_high */
  267. /*
  268. * The Data Segment Descriptor:
  269. * - Base = 0x00000000
  270. * - Size = 4GB
  271. * - Access = Present, Ring 0, Non-Exec (Data), Writable
  272. * - Flags = 4kB Granularity, 32-bit
  273. */
  274. .word 0xffff /* limit_low */
  275. .word 0x0000 /* base_low */
  276. .byte 0x00 /* base_middle */
  277. .byte 0x93 /* access */
  278. .byte 0xcf /* flags + limit_high */
  279. .byte 0x00 /* base_high */
  280. #endif