| 1 |
|
| 2 |
|
| 3 |
#include <arch/cache.h> |
| 4 |
#include <arch/lib_helpers.h> |
| 5 |
#include <arch/mmu.h> |
| 6 |
#include <arch/transition.h> |
| 7 |
#include <assert.h> |
| 8 |
|
| 9 |
void __weak exc_dispatch(struct exc_state *exc_state, uint64_t id) |
| 10 |
{ |
| 11 |
|
| 12 |
} |
| 13 |
|
| 14 |
void exc_entry(struct exc_state *exc_state, uint64_t id) |
| 15 |
{ |
| 16 |
struct elx_state *elx = &exc_state->elx; |
| 17 |
struct regs *regs = &exc_state->regs; |
| 18 |
uint8_t elx_mode; |
| 19 |
|
| 20 |
elx->spsr = raw_read_spsr(); |
| 21 |
elx->elr = raw_read_elr(); |
| 22 |
|
| 23 |
elx_mode = get_mode_from_spsr(elx->spsr); |
| 24 |
|
| 25 |
if (elx_mode == SPSR_USE_H) |
| 26 |
regs->sp = (uint64_t)&exc_state[1]; |
| 27 |
else |
| 28 |
regs->sp = raw_read_sp_el0(); |
| 29 |
|
| 30 |
exc_dispatch(exc_state, id); |
| 31 |
} |
| 32 |
|
| 33 |
void transition_to_el2(void *entry, void *arg, uint64_t spsr) |
| 34 |
{ |
| 35 |
struct exc_state exc_state; |
| 36 |
struct elx_state *elx = &exc_state.elx; |
| 37 |
struct regs *regs = &exc_state.regs; |
| 38 |
|
| 39 |
regs->x[X0_INDEX] = (uint64_t)arg; |
| 40 |
elx->elr = (uint64_t)entry; |
| 41 |
elx->spsr = spsr; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
assert(get_el_from_spsr(spsr) == EL2 && !(spsr & SPSR_ERET_32)); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
raw_write_scr_el3(SCR_FIEN | SCR_API | SCR_APK | SCR_ST | SCR_RW | |
| 56 |
SCR_HCE | SCR_SMD | SCR_RES1 | SCR_NS); |
| 57 |
|
| 58 |
|
| 59 |
raw_write_cptr_el3(CPTR_EL3_TCPAC_DISABLE | CPTR_EL3_TTA_DISABLE | |
| 60 |
CPTR_EL3_TFP_DISABLE); |
| 61 |
|
| 62 |
|
| 63 |
raw_write_elr_el3(elx->elr); |
| 64 |
raw_write_spsr_el3(elx->spsr); |
| 65 |
|
| 66 |
|
| 67 |
raw_write_sctlr_el2(SCTLR_RES1); |
| 68 |
|
| 69 |
|
| 70 |
raw_write_sp_el2(elx->sp_elx); |
| 71 |
|
| 72 |
|
| 73 |
mmu_disable(); |
| 74 |
|
| 75 |
|
| 76 |
trans_switch(regs); |
| 77 |
} |