start.S 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. #ifdef CONFIG_X86_LOAD_FROM_32_BIT
  62. lgdt gdt_ptr2
  63. #endif
  64. /* Load the segement registers to match the GDT loaded in start16.S */
  65. movl $(X86_GDT_ENTRY_32BIT_DS * X86_GDT_ENTRY_SIZE), %eax
  66. movw %ax, %fs
  67. movw %ax, %ds
  68. movw %ax, %gs
  69. movw %ax, %es
  70. movw %ax, %ss
  71. /* Clear the interrupt vectors */
  72. lidt blank_idt_ptr
  73. /*
  74. * Critical early platform init - generally not used, we prefer init
  75. * to happen later when we have a console, in case something goes
  76. * wrong.
  77. */
  78. jmp early_board_init
  79. .globl early_board_init_ret
  80. early_board_init_ret:
  81. post_code(POST_START)
  82. /* Initialise Cache-As-RAM */
  83. jmp car_init
  84. .globl car_init_ret
  85. car_init_ret:
  86. #ifndef CONFIG_HAVE_FSP
  87. /*
  88. * We now have CONFIG_SYS_CAR_SIZE bytes of Cache-As-RAM (or SRAM,
  89. * or fully initialised SDRAM - we really don't care which)
  90. * starting at CONFIG_SYS_CAR_ADDR to be used as a temporary stack
  91. * and early malloc() area. The MRC requires some space at the top.
  92. *
  93. * Stack grows down from top of CAR. We have:
  94. *
  95. * top-> CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE
  96. * MRC area
  97. * global_data with x86 global descriptor table
  98. * early malloc area
  99. * stack
  100. * bottom-> CONFIG_SYS_CAR_ADDR
  101. */
  102. movl $(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - 4), %esp
  103. #ifdef CONFIG_DCACHE_RAM_MRC_VAR_SIZE
  104. subl $CONFIG_DCACHE_RAM_MRC_VAR_SIZE, %esp
  105. #endif
  106. #else
  107. /*
  108. * U-Boot enters here twice. For the first time it comes from
  109. * car_init_done() with esp points to a temporary stack and esi
  110. * set to zero. For the second time it comes from fsp_init_done()
  111. * with esi holding the HOB list address returned by the FSP.
  112. */
  113. #endif
  114. /* Set up global data */
  115. mov %esp, %eax
  116. call board_init_f_alloc_reserve
  117. mov %eax, %esp
  118. call board_init_f_init_reserve
  119. #ifdef CONFIG_DEBUG_UART
  120. call debug_uart_init
  121. #endif
  122. /* Get address of global_data */
  123. mov %fs:0, %edx
  124. #ifdef CONFIG_HAVE_FSP
  125. /* Store the HOB list if we have one */
  126. test %esi, %esi
  127. jz skip_hob
  128. movl %esi, GD_HOB_LIST(%edx)
  129. /*
  130. * After fsp_init() returns, the stack has already been switched to a
  131. * place within system memory as defined by CONFIG_FSP_TEMP_RAM_ADDR.
  132. * Enlarge the size of malloc() pool before relocation since we have
  133. * plenty of memory now.
  134. */
  135. subl $CONFIG_FSP_SYS_MALLOC_F_LEN, %esp
  136. movl %esp, GD_MALLOC_BASE(%edx)
  137. skip_hob:
  138. #else
  139. /* Store table pointer */
  140. movl %esi, GD_TABLE(%edx)
  141. #endif
  142. /* Store BIST */
  143. movl %ebp, GD_BIST(%edx)
  144. /* Set parameter to board_init_f() to boot flags */
  145. post_code(POST_START_DONE)
  146. xorl %eax, %eax
  147. /* Enter, U-Boot! */
  148. call board_init_f
  149. /* indicate (lack of) progress */
  150. movw $0x85, %ax
  151. jmp die
  152. .globl board_init_f_r_trampoline
  153. .type board_init_f_r_trampoline, @function
  154. board_init_f_r_trampoline:
  155. /*
  156. * SDRAM has been initialised, U-Boot code has been copied into
  157. * RAM, BSS has been cleared and relocation adjustments have been
  158. * made. It is now time to jump into the in-RAM copy of U-Boot
  159. *
  160. * %eax = Address of top of new stack
  161. */
  162. /* Stack grows down from top of SDRAM */
  163. movl %eax, %esp
  164. /* See if we need to disable CAR */
  165. .weak car_uninit
  166. movl $car_uninit, %eax
  167. cmpl $0, %eax
  168. jz 1f
  169. call car_uninit
  170. 1:
  171. /* Re-enter U-Boot by calling board_init_f_r() */
  172. call board_init_f_r
  173. die:
  174. hlt
  175. jmp die
  176. hlt
  177. blank_idt_ptr:
  178. .word 0 /* limit */
  179. .long 0 /* base */
  180. .p2align 2 /* force 4-byte alignment */
  181. /* Add a multiboot header so U-Boot can be loaded by GRUB2 */
  182. multiboot_header:
  183. /* magic */
  184. .long 0x1badb002
  185. /* flags */
  186. .long (1 << 16)
  187. /* checksum */
  188. .long -0x1BADB002 - (1 << 16)
  189. /* header addr */
  190. .long multiboot_header - _x86boot_start + CONFIG_SYS_TEXT_BASE
  191. /* load addr */
  192. .long CONFIG_SYS_TEXT_BASE
  193. /* load end addr */
  194. .long 0
  195. /* bss end addr */
  196. .long 0
  197. /* entry addr */
  198. .long CONFIG_SYS_TEXT_BASE
  199. #ifdef CONFIG_X86_LOAD_FROM_32_BIT
  200. /*
  201. * The following Global Descriptor Table is just enough to get us into
  202. * 'Flat Protected Mode' - It will be discarded as soon as the final
  203. * GDT is setup in a safe location in RAM
  204. */
  205. gdt_ptr2:
  206. .word 0x1f /* limit (31 bytes = 4 GDT entries - 1) */
  207. .long gdt_rom2 /* base */
  208. /* Some CPUs are picky about GDT alignment... */
  209. .align 16
  210. .globl gdt_rom2
  211. gdt_rom2:
  212. /*
  213. * The GDT table ...
  214. *
  215. * Selector Type
  216. * 0x00 NULL
  217. * 0x08 Unused
  218. * 0x10 32bit code
  219. * 0x18 32bit data/stack
  220. */
  221. /* The NULL Desciptor - Mandatory */
  222. .word 0x0000 /* limit_low */
  223. .word 0x0000 /* base_low */
  224. .byte 0x00 /* base_middle */
  225. .byte 0x00 /* access */
  226. .byte 0x00 /* flags + limit_high */
  227. .byte 0x00 /* base_high */
  228. /* Unused Desciptor - (matches Linux) */
  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. /*
  236. * The Code Segment Descriptor:
  237. * - Base = 0x00000000
  238. * - Size = 4GB
  239. * - Access = Present, Ring 0, Exec (Code), Readable
  240. * - Flags = 4kB Granularity, 32-bit
  241. */
  242. .word 0xffff /* limit_low */
  243. .word 0x0000 /* base_low */
  244. .byte 0x00 /* base_middle */
  245. .byte 0x9b /* access */
  246. .byte 0xcf /* flags + limit_high */
  247. .byte 0x00 /* base_high */
  248. /*
  249. * The Data Segment Descriptor:
  250. * - Base = 0x00000000
  251. * - Size = 4GB
  252. * - Access = Present, Ring 0, Non-Exec (Data), Writable
  253. * - Flags = 4kB Granularity, 32-bit
  254. */
  255. .word 0xffff /* limit_low */
  256. .word 0x0000 /* base_low */
  257. .byte 0x00 /* base_middle */
  258. .byte 0x93 /* access */
  259. .byte 0xcf /* flags + limit_high */
  260. .byte 0x00 /* base_high */
  261. #endif