start.S 7.7 KB

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