| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 1 | /* |
| 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 Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 14 | .align 16 |
| 15 | .fill REALM_STACK_SIZE * MAX_REC_COUNT |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 16 | stacks_end: |
| 17 | |
| 18 | func realm_entrypoint |
| Shruti Gupta | 699cd4f | 2023-09-27 16:46:54 +0100 | [diff] [blame^] | 19 | /* Save x0 - context_id */ |
| 20 | mov x20, x0 |
| Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 21 | mrs x0, mpidr_el1 |
| 22 | mov_imm x1, MPID_MASK |
| 23 | and x0, x0, x1 |
| 24 | |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 25 | /* Setup the stack pointer. */ |
| Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 26 | 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 |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 30 | |
| Shruti Gupta | 699cd4f | 2023-09-27 16:46:54 +0100 | [diff] [blame^] | 31 | /* Primary CPU Only */ |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 32 | /* 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 | |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 51 | /* Relocate symbols */ |
| 52 | pie_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 Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 58 | |
| Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 59 | /* Initialize architectural state. */ |
| 60 | bl arch_init |
| Shruti Gupta | 9d0cfe8 | 2023-04-17 10:57:26 +0100 | [diff] [blame] | 61 | #if ENABLE_PAUTH |
| 62 | bl pauth_init_enable |
| 63 | #endif |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 64 | |
| Shruti Gupta | 9d0cfe8 | 2023-04-17 10:57:26 +0100 | [diff] [blame] | 65 | loop: |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 66 | /* And jump to the C entrypoint. */ |
| Shruti Gupta | 9d0cfe8 | 2023-04-17 10:57:26 +0100 | [diff] [blame] | 67 | bl realm_payload_main |
| 68 | b loop |
| Shruti Gupta | 699cd4f | 2023-09-27 16:46:54 +0100 | [diff] [blame^] | 69 | |
| 70 | realm_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 |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 78 | endfunc realm_entrypoint |
| 79 | |
| Shruti Gupta | 550e3e8 | 2023-08-16 13:20:11 +0100 | [diff] [blame] | 80 | /* |
| 81 | * Setup the stack pointer. |
| 82 | * x0 = mpidr |
| 83 | * clobbers x1,x2 |
| 84 | */ |
| 85 | func 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 |
| 91 | endfunc realm_setup_my_stack |
| 92 | |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 93 | /* Initialize architectural state. */ |
| 94 | func 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 Ganapathy | 0bbdc2d | 2023-04-05 15:30:18 +0100 | [diff] [blame] | 112 | mov x1, CPACR_EL1_ZEN(CPACR_EL1_ZEN_TRAP_NONE) |
| 113 | orr x0, x0, x1 |
| nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 114 | msr cpacr_el1, x0 |
| 115 | isb |
| 116 | |
| 117 | ret |
| 118 | endfunc arch_init |