1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * 32-bit x86 Startup Code when running from SPL. This is the startup code in
4 * U-Boot proper, when SPL is used.
5
6 * Copyright 2018 Google, Inc
7 * Written by Simon Glass <sjg@chromium.org>
8 */
9
10#include <config.h>
11
12.section .text.start
13.code32
14.globl _start
15.type _start, @function
16_start:
17	/*
18	 * If running from coreboot, CAR is no-longer available. Use the
19	 * existing stack, which is large enough.
20	 */
21	call	locate_coreboot_table
22	cmp	$0, %eax
23	jge	use_existing_stack
24
25	movl	$(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - 4), %eax
26#ifdef CONFIG_DCACHE_RAM_MRC_VAR_SIZE
27	subl	$CONFIG_DCACHE_RAM_MRC_VAR_SIZE, %eax
28#endif
29	jmp	2f
30	/*
31	 * We don't subtract CONFIG_DCACHE_RAM_MRC_VAR_SIZE since memory is
32	 * already set up. This has the happy side-effect of putting gd in a
33	 * new place separate from SPL, so the memset() in
34	 * board_init_f_init_reserve() does not cause any problems (otherwise
35	 * it would zero out the gd and crash)
36	 */
37	/* Set up memory using the existing stack */
38use_existing_stack:
39	mov	%esp, %eax
402:
41	call	board_init_f_alloc_reserve
42	mov	%eax, %esp
43
44	call	board_init_f_init_reserve
45
46	call	x86_cpu_reinit_f
47	xorl	%eax, %eax
48	call	board_init_f
49	call	board_init_f_r
50
51	/* Should not return here */
52	jmp	.
53
54.globl board_init_f_r_trampoline
55.type board_init_f_r_trampoline, @function
56board_init_f_r_trampoline:
57	/*
58	 * SPL has been executed and SDRAM has been initialised, U-Boot code
59	 * has been copied into RAM, BSS has been cleared and relocation
60	 * adjustments have been made. It is now time to jump into the in-RAM
61	 * copy of U-Boot
62	 *
63	 * %eax = Address of top of new stack
64	 */
65
66	/* Stack grows down from top of SDRAM */
67	movl	%eax, %esp
68
69	/* Re-enter U-Boot by calling board_init_f_r() */
70	call	board_init_f_r
71
72die:
73	hlt
74	jmp	die
75	hlt
76
77	.align 4
78_dt_ucode_base_size:
79	/* These next two fields are filled in by binman */
80.globl ucode_base
81ucode_base:	/* Declared in microcode.h */
82	.long	0			/* microcode base */
83.globl ucode_size
84ucode_size:	/* Declared in microcode.h */
85	.long	0			/* microcode size */
86