Debian Codegraph @

src/arch/x86/exit_car.S

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <cpu/x86/mtrr.h>
4 #include <cpu/x86/cr.h>
5 #include <cpu/x86/cache.h>
6
7 /* Place the stack in the bss section. It's not necessary to define it in
8 * 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
19 .text
20 .global _start
21 _start:
22 /* Assume stack alignment doesn't matter here as chipset_teardown_car
23 is expected to be implemented in assembly. */
24
25 /* Migrate GDT to this text segment */
26 #if ENV_X86_64
27 call gdt_init64
28 #else
29 call gdt_init
30 #endif
31
32 #if ENV_X86_64
33 mov %rdi, %rax
34 movabs %rax, _cbmem_top_ptr
35 #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
40 /* Make sure _cbmem_top_ptr hits dram before invd */
41 movl $1, %eax
42 cpuid
43 btl $CPUID_FEATURE_CLFLUSH_BIT, %edx
44 jnc skip_clflush
45 #if ENV_X86_64
46 movabs $_cbmem_top_ptr, %rax
47 clflush (%rax)
48 #else
49 clflush _cbmem_top_ptr
50 #endif
51
52 skip_clflush:
53 /* chipset_teardown_car() is expected to disable cache-as-ram. */
54 call chipset_teardown_car
55
56 /* Enable caching if not already enabled. */
57 #if ENV_X86_64
58 mov %cr0, %rax
59 and $(~(CR0_CD | CR0_NW)), %eax
60 mov %rax, %cr0
61 #else
62 mov %cr0, %eax
63 and $(~(CR0_CD | CR0_NW)), %eax
64 mov %eax, %cr0
65 #endif
66 /* Ensure cache is clean. */
67 invd
68
69 movl $_estack, %esp
70 #if ENV_X86_64
71 /* Align stack to 16 bytes at call instruction. */
72 movq $0xfffffffffffffff0, %rax
73 and %rax, %rsp
74 #else
75 /* Align stack to 16 bytes at call instruction. */
76 andl $0xfffffff0, %esp
77 #endif
78
79 /* 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
83 /* Call into main for postcar. */
84 call main
85 /* Should never return. */
86 1:
87 jmp 1b