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 | /* |
Arthur Heymans | c05b1a6 | 2019-11-22 21:01:30 +0100 | [diff] [blame] | 4 | * This path is for stages that are post bootblock. The gdt is reloaded |
| 5 | * to accommodate platforms that are executing out of CAR. In order to |
| 6 | * continue with C code execution one needs to set stack pointer and |
| 7 | * clear .bss variables that are stage specific. |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 8 | */ |
Felix Held | ca928c6 | 2020-04-04 01:47:37 +0200 | [diff] [blame] | 9 | |
| 10 | #if CONFIG(RESET_VECTOR_IN_RAM) |
| 11 | #define _STACK_TOP _eearlyram_stack |
| 12 | #else |
| 13 | #define _STACK_TOP _ecar_stack |
| 14 | #endif |
| 15 | |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 16 | #if ENV_X86_64 |
Patrick Rudolph | 29ed4f5 | 2020-07-05 08:46:55 +0200 | [diff] [blame] | 17 | .code64 |
| 18 | #else |
| 19 | .code32 |
| 20 | #endif |
| 21 | |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 22 | .section ".text._start", "ax", @progbits |
| 23 | .global _start |
| 24 | _start: |
| 25 | |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 26 | /* Migrate GDT to this text segment */ |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 27 | #if ENV_X86_64 |
Patrick Rudolph | 29ed4f5 | 2020-07-05 08:46:55 +0200 | [diff] [blame] | 28 | call gdt_init64 |
| 29 | #else |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 30 | call gdt_init |
Patrick Rudolph | 29ed4f5 | 2020-07-05 08:46:55 +0200 | [diff] [blame] | 31 | #endif |
Hannah Williams | d3c0c0c | 2018-04-27 09:09:04 -0700 | [diff] [blame] | 32 | |
Felix Held | ca928c6 | 2020-04-04 01:47:37 +0200 | [diff] [blame] | 33 | /* reset stack pointer to CAR/EARLYRAM stack */ |
| 34 | mov $_STACK_TOP, %esp |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 35 | |
Jeremy Compostella | b7832de | 2023-08-30 15:42:09 -0700 | [diff] [blame] | 36 | #if ENV_SEPARATE_DATA_AND_BSS |
Kyösti Mälkki | 910490f | 2019-08-22 12:56:22 +0300 | [diff] [blame] | 37 | /* clear .bss section as it is not shared */ |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 38 | cld |
| 39 | xor %eax, %eax |
Kyösti Mälkki | 910490f | 2019-08-22 12:56:22 +0300 | [diff] [blame] | 40 | movl $(_ebss), %ecx |
| 41 | movl $(_bss), %edi |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 42 | sub %edi, %ecx |
Kyösti Mälkki | 5cbaba4 | 2019-08-28 20:52:37 +0300 | [diff] [blame] | 43 | shrl $2, %ecx |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 44 | rep stosl |
Jeremy Compostella | b7832de | 2023-08-30 15:42:09 -0700 | [diff] [blame] | 45 | |
| 46 | /* Copy .data section content to Cache-As-Ram */ |
| 47 | movl $(_edata), %ecx |
| 48 | movl $(_data), %edi |
| 49 | sub %edi, %ecx |
| 50 | shrl $2, %ecx |
| 51 | movl $(_data_load),%esi |
| 52 | rep movsl |
Arthur Heymans | 9efb0c0 | 2020-11-30 14:03:51 +0100 | [diff] [blame] | 53 | #endif |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 54 | |
Julius Werner | 21a4053 | 2020-04-21 16:03:53 -0700 | [diff] [blame] | 55 | #if ((ENV_SEPARATE_VERSTAGE && CONFIG(VERSTAGE_DEBUG_SPINLOOP)) \ |
Arthur Heymans | a2bc254 | 2021-05-29 08:10:49 +0200 | [diff] [blame^] | 56 | || (ENV_SEPARATE_ROMSTAGE && CONFIG(ROMSTAGE_DEBUG_SPINLOOP))) |
Lee Leahy | d131ea3 | 2016-06-08 13:40:08 -0700 | [diff] [blame] | 57 | |
| 58 | /* Wait for a JTAG debugger to break in and set EBX non-zero */ |
| 59 | xor %ebx, %ebx |
| 60 | |
| 61 | debug_spinloop: |
| 62 | cmp $0, %ebx |
| 63 | jz debug_spinloop |
| 64 | #endif |
| 65 | |
Marshall Dawson | ce9c883 | 2017-07-07 16:09:56 -0600 | [diff] [blame] | 66 | andl $0xfffffff0, %esp |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 67 | #if CONFIG(IDT_IN_EVERY_STAGE) |
Aaron Durbin | 4b032e4 | 2018-04-20 01:39:30 -0600 | [diff] [blame] | 68 | call exception_init |
| 69 | #endif |
Harshit Sharma | a6ebe08 | 2020-07-20 00:21:05 -0700 | [diff] [blame] | 70 | |
| 71 | #if CONFIG(ASAN_IN_ROMSTAGE) |
| 72 | call asan_init |
| 73 | #endif |
Marshall Dawson | ce9c883 | 2017-07-07 16:09:56 -0600 | [diff] [blame] | 74 | call car_stage_entry |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 75 | |
Aaron Durbin | afec071 | 2019-08-28 07:34:51 -0600 | [diff] [blame] | 76 | /* Expect to never return. */ |
Andrey Petrov | 73f7069 | 2016-02-28 22:37:15 -0800 | [diff] [blame] | 77 | 1: |
| 78 | jmp 1b |