start.S 7.1 KB

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