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