1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #include <adainit.h> 4 #include <arch/romstage.h> 5 #include <arch/symbols.h> 6 #include <commonlib/helpers.h> 7 #include <console/console.h> 8 #include <cpu/x86/smm.h> 9 #include <program_loading.h> 10 #include <romstage_common.h> 11 #include <security/vboot/vboot_common.h> 12 #include <types.h> 13 14 /* If we do not have a constrained _car_stack region size, use the 15 following as a guideline for acceptable stack usage. */ 16 #define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000 17 romstage_main(void)18void __noreturn romstage_main(void) 19 { 20 int i; 21 const int num_guards = 64; 22 const u32 stack_guard = 0xdeadbeef; 23 u32 *stack_base; 24 u32 size; 25 const size_t stack_size = MAX(CONFIG_DCACHE_BSP_STACK_SIZE, 26 DCACHE_RAM_ROMSTAGE_STACK_SIZE); 27 28 /* Size of unallocated CAR. */ 29 size = ALIGN_DOWN(_car_stack_size, 16); 30 31 size = MIN(size, stack_size); 32 if (size < stack_size) 33 printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n", 34 size); 35 36 stack_base = (u32 *)(_ecar_stack - size); 37 38 for (i = 0; i < num_guards; i++) 39 stack_base[i] = stack_guard; 40 41 if (CONFIG(VBOOT_EARLY_EC_SYNC)) 42 vboot_sync_ec(); 43 44 /* 45 * We can generally jump between C and Ada code back and forth 46 * without trouble. But since we don't have an Ada main() we 47 * have to do some Ada package initializations that GNAT would 48 * do there. This has to be done before calling any Ada code. 49 * 50 * The package initializations should not have any dependen- 51 * cies on C code. So we can call them here early, and don't 52 * have to worry at which point we can start to use Ada. 53 */ 54 romstage_adainit(); 55 56 mainboard_romstage_entry(); 57 58 /* Check the stack. */ 59 for (i = 0; i < num_guards; i++) { 60 if (stack_base[i] == stack_guard) 61 continue; 62 printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); 63 } 64 65 if (CONFIG(SMM_TSEG)) 66 smm_list_regions(); 67 68 prepare_and_run_postcar(); 69 /* We do not return here. */ 70 } 71