Path: blob/main/sys/arm64/vmm/vmm_nvhe_exception.S
39478 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2024 Arm Ltd4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#define VMM_HYP_FUNC(func) vmm_nvhe_ ## func2829#include "vmm_hyp_exception.S"3031.section ".vmm_vectors","ax"32.align 1133hyp_init_vectors:34vempty /* Synchronous EL2t */35vempty /* IRQ EL2t */36vempty /* FIQ EL2t */37vempty /* Error EL2t */3839vempty /* Synchronous EL2h */40vempty /* IRQ EL2h */41vempty /* FIQ EL2h */42vempty /* Error EL2h */4344vector hyp_init /* Synchronous 64-bit EL1 */45vempty /* IRQ 64-bit EL1 */46vempty /* FIQ 64-bit EL1 */47vempty /* Error 64-bit EL1 */4849vempty /* Synchronous 32-bit EL1 */50vempty /* IRQ 32-bit EL1 */51vempty /* FIQ 32-bit EL1 */52vempty /* Error 32-bit EL1 */5354.text5556/*57* Initialize the hypervisor mode with a new exception vector table, translation58* table and stack.59*60* Expecting:61* x0 - translation tables physical address62* x1 - stack top virtual address63* x2 - TCR_EL2 value64* x3 - SCTLR_EL2 value65* x4 - VTCR_EL2 value66*/67LENTRY(handle_hyp_init)68/* Install the new exception vectors */69adrp x6, hyp_vectors70add x6, x6, :lo12:hyp_vectors71msr vbar_el2, x672/* Set the stack top address */73mov sp, x174/* Use the host VTTBR_EL2 to tell the host and the guests apart */75mov x9, #VTTBR_HOST76msr vttbr_el2, x977/* Load the base address for the translation tables */78msr ttbr0_el2, x079/* Invalidate the TLB */80dsb ish81tlbi alle282dsb ishst83isb84/* Use the same memory attributes as EL1 */85mrs x9, mair_el186msr mair_el2, x987/* Configure address translation */88msr tcr_el2, x289isb90/* Set the system control register for EL2 */91msr sctlr_el2, x392/* Set the Stage 2 translation control register */93msr vtcr_el2, x494/* Return success */95mov x0, #096/* MMU is up and running */97ERET98LEND(handle_hyp_init)99100/*101* Usage:102* void vmm_cleanup(uint64_t handle, void *hyp_stub_vectors)103*104* Expecting:105* x1 - physical address of hyp_stub_vectors106*/107LENTRY(vmm_cleanup)108/* Restore the stub vectors */109msr vbar_el2, x1110111/* Disable the MMU */112dsb sy113mrs x2, sctlr_el2114bic x2, x2, #SCTLR_EL2_M115msr sctlr_el2, x2116isb117118ERET119LEND(vmm_cleanup)120121122