Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | e581b06 | 2015-09-03 11:29:28 -0500 | [diff] [blame] | 2 | |
Aaron Durbin | aef5865 | 2016-04-29 12:34:01 -0500 | [diff] [blame] | 3 | #include <rules.h> |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 4 | |
Aaron Durbin | aef5865 | 2016-04-29 12:34:01 -0500 | [diff] [blame] | 5 | /* |
Arthur Heymans | c05b1a6 | 2019-11-22 21:01:30 +0100 | [diff] [blame] | 6 | * 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 Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 10 | */ |
Felix Held | ca928c6 | 2020-04-04 01:47:37 +0200 | [diff] [blame] | 11 | |
| 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 Rudolph | 29ed4f5 | 2020-07-05 08:46:55 +0200 | [diff] [blame] | 18 | #ifdef __x86_64__ |
| 19 | .code64 |
| 20 | #else |
| 21 | .code32 |
| 22 | #endif |
| 23 | |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 24 | .section ".text._start", "ax", @progbits |
| 25 | .global _start |
| 26 | _start: |
| 27 | |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 28 | /* Migrate GDT to this text segment */ |
Patrick Rudolph | 29ed4f5 | 2020-07-05 08:46:55 +0200 | [diff] [blame] | 29 | #ifdef __x86_64__ |
| 30 | call gdt_init64 |
| 31 | #else |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 32 | call gdt_init |
Patrick Rudolph | 29ed4f5 | 2020-07-05 08:46:55 +0200 | [diff] [blame] | 33 | #endif |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 34 | |
Felix Held | ca928c6 | 2020-04-04 01:47:37 +0200 | [diff] [blame] | 35 | /* reset stack pointer to CAR/EARLYRAM stack */ |
| 36 | mov $_STACK_TOP, %esp |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 37 | |
Kyösti Mälkki | 910490f | 2019-08-22 12:56:22 +0300 | [diff] [blame] | 38 | /* clear .bss section as it is not shared */ |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 39 | cld |
| 40 | xor %eax, %eax |
Kyösti Mälkki | 910490f | 2019-08-22 12:56:22 +0300 | [diff] [blame] | 41 | movl $(_ebss), %ecx |
| 42 | movl $(_bss), %edi |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 43 | sub %edi, %ecx |
Kyösti Mälkki | 5cbaba4 | 2019-08-28 20:52:37 +0300 | [diff] [blame] | 44 | shrl $2, %ecx |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 45 | rep stosl |
| 46 | |
Julius Werner | 21a4053 | 2020-04-21 16:03:53 -0700 | [diff] [blame] | 47 | #if ((ENV_SEPARATE_VERSTAGE && CONFIG(VERSTAGE_DEBUG_SPINLOOP)) \ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 48 | || (ENV_ROMSTAGE && CONFIG(ROMSTAGE_DEBUG_SPINLOOP))) |
Lee Leahy | d131ea3 | 2016-06-08 13:40:08 -0700 | [diff] [blame] | 49 | |
| 50 | /* Wait for a JTAG debugger to break in and set EBX non-zero */ |
| 51 | xor %ebx, %ebx |
| 52 | |
| 53 | debug_spinloop: |
| 54 | cmp $0, %ebx |
| 55 | jz debug_spinloop |
| 56 | #endif |
| 57 | |
Marshall Dawson | ce9c883 | 2017-07-07 16:09:56 -0600 | [diff] [blame] | 58 | andl $0xfffffff0, %esp |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 59 | #if CONFIG(IDT_IN_EVERY_STAGE) |
Aaron Durbin | 4b032e4 | 2018-04-20 01:39:30 -0600 | [diff] [blame] | 60 | call exception_init |
| 61 | #endif |
Harshit Sharma | a6ebe08 | 2020-07-20 00:21:05 -0700 | [diff] [blame] | 62 | |
| 63 | #if CONFIG(ASAN_IN_ROMSTAGE) |
| 64 | call asan_init |
| 65 | #endif |
Marshall Dawson | ce9c883 | 2017-07-07 16:09:56 -0600 | [diff] [blame] | 66 | call car_stage_entry |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 67 | |
Aaron Durbin | afec071 | 2019-08-28 07:34:51 -0600 | [diff] [blame] | 68 | /* Expect to never return. */ |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 69 | 1: |
| 70 | jmp 1b |