blob: ab00989a18aa044d88a1f50a0cc3018898a08b3b [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001/*
2 * Copyright (c) 2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <realm_def.h>
10
11 .globl realm_entrypoint
12
13.section .bss.stacks
Shruti Gupta550e3e82023-08-16 13:20:11 +010014.align 16
15 .fill REALM_STACK_SIZE * MAX_REC_COUNT
nabkah01002e5692022-10-10 12:36:46 +010016stacks_end:
17
18func realm_entrypoint
Shruti Gupta699cd4f2023-09-27 16:46:54 +010019 /* Save x0 - context_id */
20 mov x20, x0
Shruti Gupta550e3e82023-08-16 13:20:11 +010021 mrs x0, mpidr_el1
22 mov_imm x1, MPID_MASK
23 and x0, x0, x1
24
nabkah01002e5692022-10-10 12:36:46 +010025 /* Setup the stack pointer. */
Shruti Gupta550e3e82023-08-16 13:20:11 +010026 bl realm_setup_my_stack
27
28 /* mpidr 0 is assumed to be primary CPU, jump to warmboot otherwise */
29 cbnz x0, realm_warmboot_endpoint
nabkah01002e5692022-10-10 12:36:46 +010030
Shruti Gupta699cd4f2023-09-27 16:46:54 +010031 /* Primary CPU Only */
nabkah01002e5692022-10-10 12:36:46 +010032 /* Clear BSS */
33 ldr x0, =__REALM_BSS_START__
34 adr x1, realm_entrypoint
35 add x0, x1, x0
36 ldr x1, =__REALM_BSS_SIZE__
37 bl zeromem16
38
39 /*
40 * Invalidate the data cache for the whole Realm.
41 * This prevents re-use of stale data cache entries from
42 * prior bootloader stages.
43 */
44 adrp x0, __REALM_TEXT_START__
45 add x0, x0, realm_entrypoint
46 adrp x1, __REALM_BSS_END__
47 add x1, x1, realm_entrypoint
48 sub x1, x1, x0
49 bl inv_dcache_range
50
nabkah01002e5692022-10-10 12:36:46 +010051 /* Relocate symbols */
52pie_fixup:
53 ldr x0, =pie_fixup
54 and x0, x0, #~(PAGE_ALIGNMENT - 1)
55 mov x1, REALM_MAX_LOAD_IMG_SIZE
56 add x1, x1, x0
57 bl fixup_gdt_reloc
Shruti Gupta550e3e82023-08-16 13:20:11 +010058
Shruti Gupta550e3e82023-08-16 13:20:11 +010059 /* Initialize architectural state. */
60 bl arch_init
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010061#if ENABLE_PAUTH
62 bl pauth_init_enable
63#endif
nabkah01002e5692022-10-10 12:36:46 +010064
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010065loop:
nabkah01002e5692022-10-10 12:36:46 +010066 /* And jump to the C entrypoint. */
Shruti Gupta9d0cfe82023-04-17 10:57:26 +010067 bl realm_payload_main
68 b loop
Shruti Gupta699cd4f2023-09-27 16:46:54 +010069
70realm_warmboot_endpoint:
71 /* Initialize architectural state. */
72 bl arch_init
73#if ENABLE_PAUTH
74 bl pauth_init_enable
75#endif
76 mov x0, x20
77 b realm_secondary_entrypoint
nabkah01002e5692022-10-10 12:36:46 +010078endfunc realm_entrypoint
79
Shruti Gupta550e3e82023-08-16 13:20:11 +010080/*
81 * Setup the stack pointer.
82 * x0 = mpidr
83 * clobbers x1,x2
84 */
85func realm_setup_my_stack
86 adr x1, stacks_end
87 mov x2, REALM_STACK_SIZE
88 mul x2, x0, x2
89 sub sp, x1, x2
90 ret
91endfunc realm_setup_my_stack
92
nabkah01002e5692022-10-10 12:36:46 +010093/* Initialize architectural state. */
94func arch_init
95 /* Set the exception vectors. */
96 adr x0, realm_vector
97 add x1, x1, :lo12:realm_vector
98 msr vbar_el1, x0
99 isb
100
101 /* Enable the instruction cache and stack pointer alignment checks. */
102 mov_imm x0, (SCTLR_EL1_RES1 | SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
103 msr sctlr_el1, x0
104
105 /*
106 * Set CPACR_EL1.FPEN=11 no EL1/0 trapping of
107 * SVE/Adv. SIMD/FP instructions.
108 */
109 mov x1, CPACR_EL1_FPEN(CPACR_EL1_FP_TRAP_NONE)
110 mrs x0, cpacr_el1
111 orr x0, x0, x1
Arunachalam Ganapathy0bbdc2d2023-04-05 15:30:18 +0100112 mov x1, CPACR_EL1_ZEN(CPACR_EL1_ZEN_TRAP_NONE)
113 orr x0, x0, x1
nabkah01002e5692022-10-10 12:36:46 +0100114 msr cpacr_el1, x0
115 isb
116
117 ret
118endfunc arch_init