Page MenuHomePhabricator

Libextensionspauthpauth Helperssvsplatarmboardfvp Rfvp R Pauth Helperss
Updated 1,268 Days AgoPublic

/*                                                            /*
 * Copyright (c) 2019, Arm Limited. All rights reserved.   |   * Copyright (c) 2021, Arm Limited. All rights reserved.
 *                                                             *
 * SPDX-License-Identifier: BSD-3-Clause                       * SPDX-License-Identifier: BSD-3-Clause
 */                                                            */

#include <arch.h>                                             #include <arch.h>
#include <asm_macros.S>                                       #include <asm_macros.S>
#include <lib/el3_runtime/cpu_data.h>                         #include <lib/el3_runtime/cpu_data.h>

        .global pauth_init_enable_el1                      |          .global pauth_init_enable_el2
        .global pauth_disable_el1                          |          .global pauth_disable_el2
        .global pauth_init_enable_el3                      <
        .global pauth_disable_el3                          <
        .globl  pauth_load_bl31_apiakey                    <
        .globl  pauth_load_bl1_apiakey_enable              <

/* -------------------------------------------------------    /* -------------------------------------------------------
 * Program APIAKey_EL1 and enable pointer authentication i |   * File contains EL2 versions of EL3 funcs in:
                                                           >   *      .../lib/extensions/pauth/pauth_helpers.S
 * -------------------------------------------------------     * -------------------------------------------------------
 */                                                            */
func pauth_init_enable_el1                                 <
        stp     x29, x30, [sp, #-16]!                      <
                                                           <
        /* Initialize platform key */                      <
        bl      plat_init_apkey                            <
                                                           <
        /* Program instruction key A used by the Trusted F <
        msr     APIAKeyLo_EL1, x0                          <
        msr     APIAKeyHi_EL1, x1                          <
                                                           <
        /* Enable pointer authentication */                <
        mrs     x0, sctlr_el1                              <
        orr     x0, x0, #SCTLR_EnIA_BIT                    <
                                                           <
#if ENABLE_BTI                                             <
         /* Enable PAC branch type compatibility */        <
        bic     x0, x0, #(SCTLR_BT0_BIT | SCTLR_BT1_BIT)   <
#endif                                                     <
        msr     sctlr_el1, x0                              <
        isb                                                <
                                                           <
        ldp     x29, x30, [sp], #16                        <
        ret                                                <
endfunc pauth_init_enable_el1                              <

/* -------------------------------------------------------    /* -------------------------------------------------------
 * Disable pointer authentication in EL3                   |   * Program APIAKey_EL1 and enable pointer authentication i
 * -------------------------------------------------------     * -------------------------------------------------------
 */                                                            */
func pauth_disable_el1                                     |  func pauth_init_enable_el2
        mrs     x0, sctlr_el1                              <
        bic     x0, x0, #SCTLR_EnIA_BIT                    <
        msr     sctlr_el1, x0                              <
        isb                                                <
        ret                                                <
endfunc pauth_disable_el1                                  <
                                                           <
/* ------------------------------------------------------- <
 * Program APIAKey_EL1 and enable pointer authentication i <
 * ------------------------------------------------------- <
 */                                                        <
func pauth_init_enable_el3                                 <
        stp     x29, x30, [sp, #-16]!                                 stp     x29, x30, [sp, #-16]!

        /* Initialize platform key */                                 /* Initialize platform key */
        bl      plat_init_apkey                                       bl      plat_init_apkey

        /* Program instruction key A used by the Trusted F            /* Program instruction key A used by the Trusted F
        msr     APIAKeyLo_EL1, x0                                     msr     APIAKeyLo_EL1, x0
        msr     APIAKeyHi_EL1, x1                                     msr     APIAKeyHi_EL1, x1

        /* Enable pointer authentication */                           /* Enable pointer authentication */
        mrs     x0, sctlr_el3                              |          mrs     x0, sctlr_el2
        orr     x0, x0, #SCTLR_EnIA_BIT                               orr     x0, x0, #SCTLR_EnIA_BIT

#if ENABLE_BTI                                                #if ENABLE_BTI
         /* Enable PAC branch type compatibility */                    /* Enable PAC branch type compatibility */
        bic     x0, x0, #SCTLR_BT_BIT                                 bic     x0, x0, #SCTLR_BT_BIT
#endif                                                        #endif
        msr     sctlr_el3, x0                              |          msr     sctlr_el2, x0
        isb                                                           isb

        ldp     x29, x30, [sp], #16                                   ldp     x29, x30, [sp], #16
        ret                                                           ret
endfunc pauth_init_enable_el3                              |  endfunc pauth_init_enable_el2

/* -------------------------------------------------------    /* -------------------------------------------------------
 * Disable pointer authentication in EL3                   |   * Disable pointer authentication in EL2
 * -------------------------------------------------------     * -------------------------------------------------------
 */                                                            */
func pauth_disable_el3                                     |  func pauth_disable_el2
        mrs     x0, sctlr_el3                              |          mrs     x0, sctlr_el2
        bic     x0, x0, #SCTLR_EnIA_BIT                               bic     x0, x0, #SCTLR_EnIA_BIT
        msr     sctlr_el3, x0                              |          msr     sctlr_el2, x0
        isb                                                <
        ret                                                <
endfunc pauth_disable_el3                                  <
                                                           <
/* ------------------------------------------------------- <
 * The following functions strictly follow the AArch64 PCS <
 * to use x9-x17 (temporary caller-saved registers) to loa <
 * the APIAKey_EL1 and enable pointer authentication.      <
 * ------------------------------------------------------- <
 */                                                        <
func pauth_load_bl31_apiakey                               <
        /* tpidr_el3 contains the address of cpu_data stru <
        mrs     x9, tpidr_el3                              <
                                                           <
        /* Load apiakey from cpu_data */                   <
        ldp     x10, x11, [x9, #CPU_DATA_APIAKEY_OFFSET]   <
                                                           <
        /* Program instruction key A */                    <
        msr     APIAKeyLo_EL1, x10                         <
        msr     APIAKeyHi_EL1, x11                         <
        isb                                                <
        ret                                                <
endfunc pauth_load_bl31_apiakey                            <
                                                           <
func pauth_load_bl1_apiakey_enable                         <
        /* Load instruction key A used by the Trusted Firm <
        adrp    x9, bl1_apiakey                            <
        add     x9, x9, :lo12:bl1_apiakey                  <
        ldp     x10, x11, [x9]                             <
                                                           <
        /* Program instruction key A */                    <
        msr     APIAKeyLo_EL1, x10                         <
        msr     APIAKeyHi_EL1, x11                         <
                                                           <
        /* Enable pointer authentication */                <
        mrs     x9, sctlr_el3                              <
        orr     x9, x9, #SCTLR_EnIA_BIT                    <
                                                           <
#if ENABLE_BTI                                             <
         /* Enable PAC branch type compatibility */        <
        bic     x9, x9, #SCTLR_BT_BIT                      <
#endif                                                     <
        msr     sctlr_el3, x9                              <
        isb                                                           isb
        ret                                                           ret
endfunc pauth_load_bl1_apiakey_enable                      |  endfunc pauth_disable_el2
Last Author
garymorrison-arm
Last Edited
Jul 2 2021, 10:57 PM