1*4882a593Smuzhiyun/* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun/* Copyright (C) 2020 ARM Limited */ 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun#include "mte_def.h" 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun#define ENTRY(name) \ 7*4882a593Smuzhiyun .globl name ;\ 8*4882a593Smuzhiyun .p2align 2;\ 9*4882a593Smuzhiyun .type name, @function ;\ 10*4882a593Smuzhiyunname: 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun#define ENDPROC(name) \ 13*4882a593Smuzhiyun .size name, .-name ; 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun .text 16*4882a593Smuzhiyun/* 17*4882a593Smuzhiyun * mte_insert_random_tag: Insert random tag and might be same as the source tag if 18*4882a593Smuzhiyun * the source pointer has it. 19*4882a593Smuzhiyun * Input: 20*4882a593Smuzhiyun * x0 - source pointer with a tag/no-tag 21*4882a593Smuzhiyun * Return: 22*4882a593Smuzhiyun * x0 - pointer with random tag 23*4882a593Smuzhiyun */ 24*4882a593SmuzhiyunENTRY(mte_insert_random_tag) 25*4882a593Smuzhiyun irg x0, x0, xzr 26*4882a593Smuzhiyun ret 27*4882a593SmuzhiyunENDPROC(mte_insert_random_tag) 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun/* 30*4882a593Smuzhiyun * mte_insert_new_tag: Insert new tag and different from the source tag if 31*4882a593Smuzhiyun * source pointer has it. 32*4882a593Smuzhiyun * Input: 33*4882a593Smuzhiyun * x0 - source pointer with a tag/no-tag 34*4882a593Smuzhiyun * Return: 35*4882a593Smuzhiyun * x0 - pointer with random tag 36*4882a593Smuzhiyun */ 37*4882a593SmuzhiyunENTRY(mte_insert_new_tag) 38*4882a593Smuzhiyun gmi x1, x0, xzr 39*4882a593Smuzhiyun irg x0, x0, x1 40*4882a593Smuzhiyun ret 41*4882a593SmuzhiyunENDPROC(mte_insert_new_tag) 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun/* 44*4882a593Smuzhiyun * mte_get_tag_address: Get the tag from given address. 45*4882a593Smuzhiyun * Input: 46*4882a593Smuzhiyun * x0 - source pointer 47*4882a593Smuzhiyun * Return: 48*4882a593Smuzhiyun * x0 - pointer with appended tag 49*4882a593Smuzhiyun */ 50*4882a593SmuzhiyunENTRY(mte_get_tag_address) 51*4882a593Smuzhiyun ldg x0, [x0] 52*4882a593Smuzhiyun ret 53*4882a593SmuzhiyunENDPROC(mte_get_tag_address) 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun/* 56*4882a593Smuzhiyun * mte_set_tag_address_range: Set the tag range from the given address 57*4882a593Smuzhiyun * Input: 58*4882a593Smuzhiyun * x0 - source pointer with tag data 59*4882a593Smuzhiyun * x1 - range 60*4882a593Smuzhiyun * Return: 61*4882a593Smuzhiyun * none 62*4882a593Smuzhiyun */ 63*4882a593SmuzhiyunENTRY(mte_set_tag_address_range) 64*4882a593Smuzhiyun cbz x1, 2f 65*4882a593Smuzhiyun1: 66*4882a593Smuzhiyun stg x0, [x0, #0x0] 67*4882a593Smuzhiyun add x0, x0, #MT_GRANULE_SIZE 68*4882a593Smuzhiyun sub x1, x1, #MT_GRANULE_SIZE 69*4882a593Smuzhiyun cbnz x1, 1b 70*4882a593Smuzhiyun2: 71*4882a593Smuzhiyun ret 72*4882a593SmuzhiyunENDPROC(mte_set_tag_address_range) 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun/* 75*4882a593Smuzhiyun * mt_clear_tag_address_range: Clear the tag range from the given address 76*4882a593Smuzhiyun * Input: 77*4882a593Smuzhiyun * x0 - source pointer with tag data 78*4882a593Smuzhiyun * x1 - range 79*4882a593Smuzhiyun * Return: 80*4882a593Smuzhiyun * none 81*4882a593Smuzhiyun */ 82*4882a593SmuzhiyunENTRY(mte_clear_tag_address_range) 83*4882a593Smuzhiyun cbz x1, 2f 84*4882a593Smuzhiyun1: 85*4882a593Smuzhiyun stzg x0, [x0, #0x0] 86*4882a593Smuzhiyun add x0, x0, #MT_GRANULE_SIZE 87*4882a593Smuzhiyun sub x1, x1, #MT_GRANULE_SIZE 88*4882a593Smuzhiyun cbnz x1, 1b 89*4882a593Smuzhiyun2: 90*4882a593Smuzhiyun ret 91*4882a593SmuzhiyunENDPROC(mte_clear_tag_address_range) 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun/* 94*4882a593Smuzhiyun * mte_enable_pstate_tco: Enable PSTATE.TCO (tag check override) field 95*4882a593Smuzhiyun * Input: 96*4882a593Smuzhiyun * none 97*4882a593Smuzhiyun * Return: 98*4882a593Smuzhiyun * none 99*4882a593Smuzhiyun */ 100*4882a593SmuzhiyunENTRY(mte_enable_pstate_tco) 101*4882a593Smuzhiyun msr tco, #MT_PSTATE_TCO_EN 102*4882a593Smuzhiyun ret 103*4882a593SmuzhiyunENDPROC(mte_enable_pstate_tco) 104*4882a593Smuzhiyun 105*4882a593Smuzhiyun/* 106*4882a593Smuzhiyun * mte_disable_pstate_tco: Disable PSTATE.TCO (tag check override) field 107*4882a593Smuzhiyun * Input: 108*4882a593Smuzhiyun * none 109*4882a593Smuzhiyun * Return: 110*4882a593Smuzhiyun * none 111*4882a593Smuzhiyun */ 112*4882a593SmuzhiyunENTRY(mte_disable_pstate_tco) 113*4882a593Smuzhiyun msr tco, #MT_PSTATE_TCO_DIS 114*4882a593Smuzhiyun ret 115*4882a593SmuzhiyunENDPROC(mte_disable_pstate_tco) 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun/* 118*4882a593Smuzhiyun * mte_get_pstate_tco: Get PSTATE.TCO (tag check override) field 119*4882a593Smuzhiyun * Input: 120*4882a593Smuzhiyun * none 121*4882a593Smuzhiyun * Return: 122*4882a593Smuzhiyun * x0 123*4882a593Smuzhiyun */ 124*4882a593SmuzhiyunENTRY(mte_get_pstate_tco) 125*4882a593Smuzhiyun mrs x0, tco 126*4882a593Smuzhiyun ubfx x0, x0, #MT_PSTATE_TCO_SHIFT, #1 127*4882a593Smuzhiyun ret 128*4882a593SmuzhiyunENDPROC(mte_get_pstate_tco) 129