blob: 31670c29b69c17cfbd0075d8610cae0523e68cf6 [file] [log] [blame]
Patrick Georgi11f00792020-03-04 15:10:45 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbine581b062015-09-03 11:29:28 -05002
Aaron Durbinaef58652016-04-29 12:34:01 -05003#include <rules.h>
Andrey Petrov73f70692016-02-28 22:37:15 -08004
Aaron Durbinaef58652016-04-29 12:34:01 -05005/*
Arthur Heymansc05b1a62019-11-22 21:01:30 +01006 * This path is for stages that are post bootblock. The gdt is reloaded
7 * to accommodate platforms that are executing out of CAR. In order to
8 * continue with C code execution one needs to set stack pointer and
9 * clear .bss variables that are stage specific.
Andrey Petrov73f70692016-02-28 22:37:15 -080010 */
Felix Heldca928c62020-04-04 01:47:37 +020011
12#if CONFIG(RESET_VECTOR_IN_RAM)
13 #define _STACK_TOP _eearlyram_stack
14#else
15 #define _STACK_TOP _ecar_stack
16#endif
17
Patrick Rudolph29ed4f52020-07-05 08:46:55 +020018#ifdef __x86_64__
19.code64
20#else
21.code32
22#endif
23
Andrey Petrov73f70692016-02-28 22:37:15 -080024.section ".text._start", "ax", @progbits
25.global _start
26_start:
27
Hannah Williamsd3c0c0c2018-04-27 09:09:04 -070028 /* Migrate GDT to this text segment */
Patrick Rudolph29ed4f52020-07-05 08:46:55 +020029#ifdef __x86_64__
30 call gdt_init64
31#else
Hannah Williamsd3c0c0c2018-04-27 09:09:04 -070032 call gdt_init
Patrick Rudolph29ed4f52020-07-05 08:46:55 +020033#endif
Hannah Williamsd3c0c0c2018-04-27 09:09:04 -070034
Felix Heldca928c62020-04-04 01:47:37 +020035 /* reset stack pointer to CAR/EARLYRAM stack */
36 mov $_STACK_TOP, %esp
Andrey Petrov73f70692016-02-28 22:37:15 -080037
Kyösti Mälkki910490f2019-08-22 12:56:22 +030038 /* clear .bss section as it is not shared */
Andrey Petrov73f70692016-02-28 22:37:15 -080039 cld
40 xor %eax, %eax
Kyösti Mälkki910490f2019-08-22 12:56:22 +030041 movl $(_ebss), %ecx
42 movl $(_bss), %edi
Andrey Petrov73f70692016-02-28 22:37:15 -080043 sub %edi, %ecx
Kyösti Mälkki5cbaba42019-08-28 20:52:37 +030044 shrl $2, %ecx
Andrey Petrov73f70692016-02-28 22:37:15 -080045 rep stosl
46
Julius Werner21a40532020-04-21 16:03:53 -070047#if ((ENV_SEPARATE_VERSTAGE && CONFIG(VERSTAGE_DEBUG_SPINLOOP)) \
Julius Wernercd49cce2019-03-05 16:53:33 -080048 || (ENV_ROMSTAGE && CONFIG(ROMSTAGE_DEBUG_SPINLOOP)))
Lee Leahyd131ea32016-06-08 13:40:08 -070049
50 /* Wait for a JTAG debugger to break in and set EBX non-zero */
51 xor %ebx, %ebx
52
53debug_spinloop:
54 cmp $0, %ebx
55 jz debug_spinloop
56#endif
57
Marshall Dawsonce9c8832017-07-07 16:09:56 -060058 andl $0xfffffff0, %esp
Julius Wernercd49cce2019-03-05 16:53:33 -080059#if CONFIG(IDT_IN_EVERY_STAGE)
Aaron Durbin4b032e42018-04-20 01:39:30 -060060 call exception_init
61#endif
Harshit Sharmaa6ebe082020-07-20 00:21:05 -070062
63#if CONFIG(ASAN_IN_ROMSTAGE)
64 call asan_init
65#endif
Marshall Dawsonce9c8832017-07-07 16:09:56 -060066 call car_stage_entry
Andrey Petrov73f70692016-02-28 22:37:15 -080067
Aaron Durbinafec0712019-08-28 07:34:51 -060068 /* Expect to never return. */
Andrey Petrov73f70692016-02-28 22:37:15 -0800691:
70 jmp 1b