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