11ae75529SAndre Przywara /* 2*45218c64SBoyan Karatotev * Copyright (c) 2022-2025, Arm Limited. All rights reserved. 31ae75529SAndre Przywara * 41ae75529SAndre Przywara * SPDX-License-Identifier: BSD-3-Clause 51ae75529SAndre Przywara * 61ae75529SAndre Przywara * This file just contains demonstration code, to "handle" RNG traps. 71ae75529SAndre Przywara */ 81ae75529SAndre Przywara 91ae75529SAndre Przywara #include <stdbool.h> 101ae75529SAndre Przywara 111ae75529SAndre Przywara #include <arch.h> 121ae75529SAndre Przywara #include <arch_helpers.h> 131ae75529SAndre Przywara #include <bl31/sync_handle.h> 141ae75529SAndre Przywara #include <context.h> 151ae75529SAndre Przywara 161ae75529SAndre Przywara /* 171ae75529SAndre Przywara * This emulation code here is not very meaningful: enabling the RNG 181ae75529SAndre Przywara * trap typically happens for a reason, so just calling the actual 191ae75529SAndre Przywara * hardware instructions might not be useful or even possible. 201ae75529SAndre Przywara */ plat_handle_rng_trap(uint64_t esr_el3,cpu_context_t * ctx)211ae75529SAndre Przywaraint plat_handle_rng_trap(uint64_t esr_el3, cpu_context_t *ctx) 221ae75529SAndre Przywara { 231ae75529SAndre Przywara /* extract the target register number from the exception syndrome */ 241ae75529SAndre Przywara unsigned int rt = get_sysreg_iss_rt(esr_el3); 251ae75529SAndre Przywara 261ae75529SAndre Przywara /* ignore XZR accesses and writes to the register */ 271ae75529SAndre Przywara if (rt == 31 || is_sysreg_iss_write(esr_el3)) { 281ae75529SAndre Przywara return TRAP_RET_CONTINUE; 291ae75529SAndre Przywara } 301ae75529SAndre Przywara 311ae75529SAndre Przywara if ((esr_el3 & ISS_SYSREG_OPCODE_MASK) == ISS_SYSREG_OPCODE_RNDR) { 321ae75529SAndre Przywara ctx->gpregs_ctx.ctx_regs[rt] = read_rndr(); 331ae75529SAndre Przywara } else { 341ae75529SAndre Przywara ctx->gpregs_ctx.ctx_regs[rt] = read_rndrrs(); 351ae75529SAndre Przywara } 361ae75529SAndre Przywara 371ae75529SAndre Przywara /* 381ae75529SAndre Przywara * We successfully handled the trap, continue with the next 391ae75529SAndre Przywara * instruction. 401ae75529SAndre Przywara */ 411ae75529SAndre Przywara return TRAP_RET_CONTINUE; 421ae75529SAndre Przywara } 43