| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <assert.h> |
| 8 |
|
| 9 |
#include <arch_helpers.h> |
| 10 |
#include <context.h> |
| 11 |
#include <common/debug.h> |
| 12 |
#include <lib/el3_runtime/context_mgmt.h> |
| 13 |
#include <plat/common/platform.h> |
| 14 |
|
| 15 |
#include "../bl1_private.h" |
| 16 |
|
| 17 |
|
| 18 |
static void *bl1_cpu_context_ptr[2]; |
| 19 |
entry_point_info_t *bl2_ep_info; |
| 20 |
|
| 21 |
|
| 22 |
void *cm_get_context(uint32_t security_state) |
| 23 |
{ |
| 24 |
assert(sec_state_is_valid(security_state)); |
| 25 |
return bl1_cpu_context_ptr[security_state]; |
| 26 |
} |
| 27 |
|
| 28 |
void cm_set_context(void *context, uint32_t security_state) |
| 29 |
{ |
| 30 |
assert(sec_state_is_valid(security_state)); |
| 31 |
bl1_cpu_context_ptr[security_state] = context; |
| 32 |
} |
| 33 |
|
| 34 |
#if ENABLE_RME |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
void bl1_prepare_next_image(unsigned int image_id) |
| 40 |
{ |
| 41 |
image_desc_t *bl2_desc; |
| 42 |
|
| 43 |
assert(image_id == BL2_IMAGE_ID); |
| 44 |
|
| 45 |
|
| 46 |
bl2_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); |
| 47 |
assert(bl2_desc != NULL); |
| 48 |
|
| 49 |
|
| 50 |
bl2_ep_info = &bl2_desc->ep_info; |
| 51 |
|
| 52 |
bl2_ep_info->spsr = (uint32_t)SPSR_64(MODE_EL3, MODE_SP_ELX, |
| 53 |
DISABLE_ALL_EXCEPTIONS); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
flush_dcache_range((uintptr_t)bl2_ep_info, sizeof(entry_point_info_t)); |
| 60 |
|
| 61 |
|
| 62 |
bl2_desc->state = IMAGE_STATE_EXECUTED; |
| 63 |
|
| 64 |
|
| 65 |
print_entry_point_info(bl2_ep_info); |
| 66 |
} |
| 67 |
#else |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
void bl1_prepare_next_image(unsigned int image_id) |
| 73 |
{ |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
static cpu_context_t bl1_cpu_context[2]; |
| 80 |
|
| 81 |
unsigned int security_state, mode = MODE_EL1; |
| 82 |
image_desc_t *desc; |
| 83 |
entry_point_info_t *next_bl_ep; |
| 84 |
|
| 85 |
#if CTX_INCLUDE_AARCH32_REGS |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
if (el_implemented(1) == EL_IMPL_A64ONLY) { |
| 91 |
ERROR("EL1 supports AArch64-only. Please set build flag " |
| 92 |
"CTX_INCLUDE_AARCH32_REGS = 0\n"); |
| 93 |
panic(); |
| 94 |
} |
| 95 |
#endif |
| 96 |
|
| 97 |
|
| 98 |
desc = bl1_plat_get_image_desc(image_id); |
| 99 |
assert(desc != NULL); |
| 100 |
|
| 101 |
|
| 102 |
next_bl_ep = &desc->ep_info; |
| 103 |
|
| 104 |
|
| 105 |
security_state = GET_SECURITY_STATE(next_bl_ep->h.attr); |
| 106 |
|
| 107 |
|
| 108 |
if (cm_get_context(security_state) == NULL) |
| 109 |
cm_set_context(&bl1_cpu_context[security_state], security_state); |
| 110 |
|
| 111 |
|
| 112 |
if ((security_state != SECURE) && (el_implemented(2) != EL_IMPL_NONE)) { |
| 113 |
mode = MODE_EL2; |
| 114 |
} |
| 115 |
|
| 116 |
next_bl_ep->spsr = (uint32_t)SPSR_64((uint64_t) mode, |
| 117 |
(uint64_t)MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS); |
| 118 |
|
| 119 |
|
| 120 |
bl1_plat_set_ep_info(image_id, next_bl_ep); |
| 121 |
|
| 122 |
|
| 123 |
cm_init_my_context(next_bl_ep); |
| 124 |
cm_prepare_el3_exit(security_state); |
| 125 |
|
| 126 |
|
| 127 |
desc->state = IMAGE_STATE_EXECUTED; |
| 128 |
|
| 129 |
print_entry_point_info(next_bl_ep); |
| 130 |
} |
| 131 |
#endif |