blob: d435dbe25b710dd014b15a3989f8b60dfe870b66 [file] [log] [blame]
Patrick Georgi11f00792020-03-04 15:10:45 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin7f8afe02016-03-18 12:21:23 -05002
3#include <cpu/x86/mtrr.h>
4#include <cpu/x86/cr.h>
Arthur Heymansa6a2f932019-11-25 19:58:36 +01005#include <cpu/x86/cache.h>
Aaron Durbin7f8afe02016-03-18 12:21:23 -05006
Elyes Haouas3b3bb7c2023-02-08 12:49:33 +01007/* Place the stack in the bss section. It's not necessary to define it in
Arthur Heymans5315e962021-05-14 11:22:31 +02008 * the linker script. */
9 .section .bss, "aw", @nobits
10.global _stack
11.global _estack
12.global _stack_size
13
14_stack:
15.space CONFIG_STACK_SIZE
16_estack:
17.set _stack_size, _estack - _stack
18
Aaron Durbin7f8afe02016-03-18 12:21:23 -050019.text
20.global _start
21_start:
Aaron Durbin028e18f2017-06-23 11:14:58 -050022 /* Assume stack alignment doesn't matter here as chipset_teardown_car
23 is expected to be implemented in assembly. */
24
Hannah Williamsd3c0c0c2018-04-27 09:09:04 -070025 /* Migrate GDT to this text segment */
Patrick Rudolphadcf7822020-08-27 20:50:18 +020026#if ENV_X86_64
Patrick Rudolph8daa12f2018-12-26 15:12:32 +010027 call gdt_init64
28#else
Hannah Williamsd3c0c0c2018-04-27 09:09:04 -070029 call gdt_init
Patrick Rudolph8daa12f2018-12-26 15:12:32 +010030#endif
Hannah Williamsd3c0c0c2018-04-27 09:09:04 -070031
Patrick Rudolphadcf7822020-08-27 20:50:18 +020032#if ENV_X86_64
Patrick Rudolphd0239092021-06-11 21:24:10 +020033 mov %rdi, %rax
34 movabs %rax, _cbmem_top_ptr
Arthur Heymans7c9a0e82019-10-23 17:02:50 +020035#else
36 /* The return argument is at 0(%esp), the calling argument at 4(%esp) */
37 movl 4(%esp), %eax
38 movl %eax, _cbmem_top_ptr
39#endif
Arthur Heymansa6a2f932019-11-25 19:58:36 +010040 /* Make sure _cbmem_top_ptr hits dram before invd */
41 movl $1, %eax
42 cpuid
43 btl $CPUID_FEATURE_CLFLUSH_BIT, %edx
Arthur Heymans014c8892020-08-29 08:21:49 +020044 jnc skip_clflush
Patrick Rudolphadcf7822020-08-27 20:50:18 +020045#if ENV_X86_64
Patrick Rudolphfeab8bb2021-12-03 17:12:08 +010046 movabs $_cbmem_top_ptr, %rax
Patrick Rudolphd0239092021-06-11 21:24:10 +020047 clflush (%rax)
48#else
Arthur Heymansa6a2f932019-11-25 19:58:36 +010049 clflush _cbmem_top_ptr
Patrick Rudolphd0239092021-06-11 21:24:10 +020050#endif
Arthur Heymans7c9a0e82019-10-23 17:02:50 +020051
Arthur Heymansa6a2f932019-11-25 19:58:36 +010052skip_clflush:
Aaron Durbin7f8afe02016-03-18 12:21:23 -050053 /* chipset_teardown_car() is expected to disable cache-as-ram. */
54 call chipset_teardown_car
55
56 /* Enable caching if not already enabled. */
Patrick Rudolphadcf7822020-08-27 20:50:18 +020057#if ENV_X86_64
Patrick Rudolph8daa12f2018-12-26 15:12:32 +010058 mov %cr0, %rax
59 and $(~(CR0_CD | CR0_NW)), %eax
60 mov %rax, %cr0
61#else
Aaron Durbin7f8afe02016-03-18 12:21:23 -050062 mov %cr0, %eax
63 and $(~(CR0_CD | CR0_NW)), %eax
64 mov %eax, %cr0
Arthur Heymans46b409d2021-05-14 13:19:43 +020065#endif
Aaron Durbin7f8afe02016-03-18 12:21:23 -050066 /* Ensure cache is clean. */
67 invd
68
Arthur Heymans5315e962021-05-14 11:22:31 +020069 movl $_estack, %esp
Patrick Rudolph3d93cd72021-12-03 17:17:45 +010070#if ENV_X86_64
71 /* Align stack to 16 bytes at call instruction. */
72 movq $0xfffffffffffffff0, %rax
73 and %rax, %rsp
74#else
Aaron Durbin028e18f2017-06-23 11:14:58 -050075 /* Align stack to 16 bytes at call instruction. */
76 andl $0xfffffff0, %esp
Patrick Rudolph3d93cd72021-12-03 17:17:45 +010077#endif
Arthur Heymans5315e962021-05-14 11:22:31 +020078
Arthur Heymans46b409d2021-05-14 13:19:43 +020079 /* Call this in assembly as some platforms like to mess with the bootflow and
80 call into main directly from chipset_teardown_car. */
81 call postcar_mtrr_setup
82
Aaron Durbin6b0cebc2016-09-16 16:15:14 -050083 /* Call into main for postcar. */
84 call main
Aaron Durbin7f8afe02016-03-18 12:21:23 -050085 /* Should never return. */
861:
87 jmp 1b