start.S 6.9 KB

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