1*344aa361SAndroid Build Coastguard Worker/* 2*344aa361SAndroid Build Coastguard Worker * Copyright (c) 2023, Google Inc. All rights reserved 3*344aa361SAndroid Build Coastguard Worker * 4*344aa361SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining 5*344aa361SAndroid Build Coastguard Worker * a copy of this software and associated documentation files 6*344aa361SAndroid Build Coastguard Worker * (the "Software"), to deal in the Software without restriction, 7*344aa361SAndroid Build Coastguard Worker * including without limitation the rights to use, copy, modify, merge, 8*344aa361SAndroid Build Coastguard Worker * publish, distribute, sublicense, and/or sell copies of the Software, 9*344aa361SAndroid Build Coastguard Worker * and to permit persons to whom the Software is furnished to do so, 10*344aa361SAndroid Build Coastguard Worker * subject to the following conditions: 11*344aa361SAndroid Build Coastguard Worker * 12*344aa361SAndroid Build Coastguard Worker * The above copyright notice and this permission notice shall be 13*344aa361SAndroid Build Coastguard Worker * included in all copies or substantial portions of the Software. 14*344aa361SAndroid Build Coastguard Worker * 15*344aa361SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16*344aa361SAndroid Build Coastguard Worker * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17*344aa361SAndroid Build Coastguard Worker * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18*344aa361SAndroid Build Coastguard Worker * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19*344aa361SAndroid Build Coastguard Worker * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20*344aa361SAndroid Build Coastguard Worker * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21*344aa361SAndroid Build Coastguard Worker * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22*344aa361SAndroid Build Coastguard Worker */ 23*344aa361SAndroid Build Coastguard Worker 24*344aa361SAndroid Build Coastguard Worker#include <asm.h> 25*344aa361SAndroid Build Coastguard Worker#include <arch/asm_macros.h> 26*344aa361SAndroid Build Coastguard Worker#include <err.h> 27*344aa361SAndroid Build Coastguard Worker 28*344aa361SAndroid Build Coastguard Worker.arch_extension pauth 29*344aa361SAndroid Build Coastguard Worker.section .text 30*344aa361SAndroid Build Coastguard Worker 31*344aa361SAndroid Build Coastguard Worker/** 32*344aa361SAndroid Build Coastguard Worker * int pactest_autia(uint64_t address, uint64_t modifier, uint64_t* result) 33*344aa361SAndroid Build Coastguard Worker * - Function to test autia instruction (instruction A-key). 34*344aa361SAndroid Build Coastguard Worker * 35*344aa361SAndroid Build Coastguard Worker * This checks the passed address is authenticated with the modifier and IA key, 36*344aa361SAndroid Build Coastguard Worker * and returns the pointer in *result if FEAT_FPAC is not implemented. 37*344aa361SAndroid Build Coastguard Worker * 38*344aa361SAndroid Build Coastguard Worker * Returns ERR_FAULT if the PAC instruction faults (FEAT_FPAC). 39*344aa361SAndroid Build Coastguard Worker * Return 0 if the PAC check does not fault, in which case *result is updated. 40*344aa361SAndroid Build Coastguard Worker */ 41*344aa361SAndroid Build Coastguard WorkerFUNCTION(pactest_autia) 42*344aa361SAndroid Build Coastguard Workerset_fault_handler .Lpactest_fault 43*344aa361SAndroid Build Coastguard Worker autia x0, x1 44*344aa361SAndroid Build Coastguard Worker str x0, [x2] 45*344aa361SAndroid Build Coastguard Worker mov x0, #0 46*344aa361SAndroid Build Coastguard Worker ret 47*344aa361SAndroid Build Coastguard Worker 48*344aa361SAndroid Build Coastguard Worker/** 49*344aa361SAndroid Build Coastguard Worker * int pactest_autib(uint64_t address, uint64_t modifier, uint64_t* result) 50*344aa361SAndroid Build Coastguard Worker * - Function to test autib instruction (instruction B-key). 51*344aa361SAndroid Build Coastguard Worker * 52*344aa361SAndroid Build Coastguard Worker * This checks the passed address is authenticated with the modifier and IB key, 53*344aa361SAndroid Build Coastguard Worker * and returns the pointer in *result if FEAT_FPAC is not implemented. 54*344aa361SAndroid Build Coastguard Worker * 55*344aa361SAndroid Build Coastguard Worker * Returns ERR_FAULT if the PAC instruction faults (FEAT_FPAC). 56*344aa361SAndroid Build Coastguard Worker * Return 0 if the PAC check does not fault, in which case *result is updated. 57*344aa361SAndroid Build Coastguard Worker */ 58*344aa361SAndroid Build Coastguard WorkerFUNCTION(pactest_autib) 59*344aa361SAndroid Build Coastguard Workerset_fault_handler .Lpactest_fault 60*344aa361SAndroid Build Coastguard Worker autib x0, x1 61*344aa361SAndroid Build Coastguard Worker str x0, [x2] 62*344aa361SAndroid Build Coastguard Worker mov x0, #0 63*344aa361SAndroid Build Coastguard Worker ret 64*344aa361SAndroid Build Coastguard Worker 65*344aa361SAndroid Build Coastguard Worker 66*344aa361SAndroid Build Coastguard Worker/** 67*344aa361SAndroid Build Coastguard Worker * int pactest_autda(uint64_t address, uint64_t modifier, uint64_t* result) 68*344aa361SAndroid Build Coastguard Worker * - Function to test autda instruction (data A-key). 69*344aa361SAndroid Build Coastguard Worker * 70*344aa361SAndroid Build Coastguard Worker * This checks the passed address is authenticated with the modifier and DA key, 71*344aa361SAndroid Build Coastguard Worker * and returns the pointer in *result if FEAT_FPAC is not implemented. 72*344aa361SAndroid Build Coastguard Worker * 73*344aa361SAndroid Build Coastguard Worker * Returns ERR_FAULT if the PAC instruction faults (FEAT_FPAC). 74*344aa361SAndroid Build Coastguard Worker * Return 0 if the PAC check does not fault, in which case *result is updated. 75*344aa361SAndroid Build Coastguard Worker */ 76*344aa361SAndroid Build Coastguard WorkerFUNCTION(pactest_autda) 77*344aa361SAndroid Build Coastguard Workerset_fault_handler .Lpactest_fault 78*344aa361SAndroid Build Coastguard Worker autda x0, x1 79*344aa361SAndroid Build Coastguard Worker str x0, [x2] 80*344aa361SAndroid Build Coastguard Worker mov x0, #0 81*344aa361SAndroid Build Coastguard Worker ret 82*344aa361SAndroid Build Coastguard Worker 83*344aa361SAndroid Build Coastguard Worker/** 84*344aa361SAndroid Build Coastguard Worker * int pactest_autdb(uint64_t address, uint64_t modifier, uint64_t* result) 85*344aa361SAndroid Build Coastguard Worker * - Function to test autdb instruction (data B-key). 86*344aa361SAndroid Build Coastguard Worker * 87*344aa361SAndroid Build Coastguard Worker * This checks the passed address is authenticated with the modifier and DB key, 88*344aa361SAndroid Build Coastguard Worker * and returns the pointer in *result if FEAT_FPAC is not implemented. 89*344aa361SAndroid Build Coastguard Worker * 90*344aa361SAndroid Build Coastguard Worker * Returns ERR_FAULT if the PAC instruction faults (FEAT_FPAC). 91*344aa361SAndroid Build Coastguard Worker * Return 0 if the PAC check does not fault, in which case *result is updated. 92*344aa361SAndroid Build Coastguard Worker */ 93*344aa361SAndroid Build Coastguard WorkerFUNCTION(pactest_autdb) 94*344aa361SAndroid Build Coastguard Workerset_fault_handler .Lpactest_fault 95*344aa361SAndroid Build Coastguard Worker autdb x0, x1 96*344aa361SAndroid Build Coastguard Worker str x0, [x2] 97*344aa361SAndroid Build Coastguard Worker mov x0, #0 98*344aa361SAndroid Build Coastguard Worker ret 99*344aa361SAndroid Build Coastguard Worker 100*344aa361SAndroid Build Coastguard Worker.Lpactest_fault: 101*344aa361SAndroid Build Coastguard Worker bti jc 102*344aa361SAndroid Build Coastguard Worker mov x0, #ERR_FAULT 103*344aa361SAndroid Build Coastguard Worker ret 104