amu_helpers.S 5.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch.h>
#include <assert_macros.S>
#include <asm_macros.S>

	.globl	amu_group0_cnt_read_internal
	.globl	amu_group0_cnt_write_internal
	.globl	amu_group1_cnt_read_internal
	.globl	amu_group1_cnt_write_internal
	.globl	amu_group1_set_evtype_internal

/*
 * uint64_t amu_group0_cnt_read_internal(int idx);
 *
 * Given `idx`, read the corresponding AMU counter
 * and return it in `r0`.
 */
func amu_group0_cnt_read_internal
#if ENABLE_ASSERTIONS
	/* `idx` should be between [0, 3] */
	mov	r1, r0
	lsr	r1, r1, #2
	cmp	r1, #0
	ASM_ASSERT(eq)
#endif

	/*
	 * Given `idx` calculate address of ldcopr16/bx lr instruction pair
	 * in the table below.
	 */
	adr	r1, 1f
	lsl	r0, r0, #3	/* each ldcopr16/bx lr sequence is 8 bytes */
	add	r1, r1, r0
	bx	r1
1:
	ldcopr16	r0, r1, AMEVCNTR00	/* index 0 */
	bx		lr
	ldcopr16	r0, r1, AMEVCNTR01	/* index 1 */
	bx 		lr
	ldcopr16	r0, r1, AMEVCNTR02	/* index 2 */
	bx 		lr
	ldcopr16	r0, r1, AMEVCNTR03	/* index 3 */
	bx 		lr
endfunc amu_group0_cnt_read_internal

/*
 * void amu_group0_cnt_write_internal(int idx, uint64_t val);
 *
 * Given `idx`, write `val` to the corresponding AMU counter.
 */
func amu_group0_cnt_write_internal
#if ENABLE_ASSERTIONS
	/* `idx` should be between [0, 3] */
	mov	r2, r0
	lsr	r2, r2, #2
	cmp	r2, #0
	ASM_ASSERT(eq)
#endif

	/*
	 * Given `idx` calculate address of stcopr16/bx lr instruction pair
	 * in the table below.
	 */
	adr	r2, 1f
	lsl	r0, r0, #3	/* each stcopr16/bx lr sequence is 8 bytes */
	add	r2, r2, r0
	bx	r2

1:
	stcopr16	r0,r1, AMEVCNTR00	/* index 0 */
	bx 		lr
	stcopr16	r0,r1, AMEVCNTR01	/* index 1 */
	bx 		lr
	stcopr16	r0,r1, AMEVCNTR02	/* index 2 */
	bx 		lr
	stcopr16	r0,r1, AMEVCNTR03	/* index 3 */
	bx 		lr
endfunc amu_group0_cnt_write_internal

/*
 * uint64_t amu_group1_cnt_read_internal(int idx);
 *
 * Given `idx`, read the corresponding AMU counter
 * and return it in `r0`.
 */
func amu_group1_cnt_read_internal
#if ENABLE_ASSERTIONS
	/* `idx` should be between [0, 15] */
	mov	r2, r0
	lsr	r2, r2, #4
	cmp	r2, #0
	ASM_ASSERT(eq)
#endif

	/*
	 * Given `idx` calculate address of ldcopr16/bx lr instruction pair
	 * in the table below.
	 */
	adr	r1, 1f
	lsl	r0, r0, #3	/* each ldcopr16/bx lr sequence is 8 bytes */
	add	r1, r1, r0
	bx	r1

1:
	ldcopr16	r0,r1, AMEVCNTR10	/* index 0 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR11	/* index 1 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR12	/* index 2 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR13	/* index 3 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR14	/* index 4 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR15	/* index 5 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR16	/* index 6 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR17	/* index 7 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR18	/* index 8 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR19	/* index 9 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR1A	/* index 10 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR1B	/* index 11 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR1C	/* index 12 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR1D	/* index 13 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR1E	/* index 14 */
	bx	lr
	ldcopr16	r0,r1, AMEVCNTR1F	/* index 15 */
	bx	lr
endfunc amu_group1_cnt_read_internal

/*
 * void amu_group1_cnt_write_internal(int idx, uint64_t val);
 *
 * Given `idx`, write `val` to the corresponding AMU counter.
 */
func amu_group1_cnt_write_internal
#if ENABLE_ASSERTIONS
	/* `idx` should be between [0, 15] */
	mov	r2, r0
	lsr	r2, r2, #4
	cmp	r2, #0
	ASM_ASSERT(eq)
#endif

	/*
	 * Given `idx` calculate address of ldcopr16/bx lr instruction pair
	 * in the table below.
	 */
	adr	r2, 1f
	lsl	r0, r0, #3	/* each stcopr16/bx lr sequence is 8 bytes */
	add	r2, r2, r0
	bx	r2

1:
	stcopr16	r0,r1,	AMEVCNTR10	/* index 0 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR11	/* index 1 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR12	/* index 2 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR13	/* index 3 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR14	/* index 4 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR15	/* index 5 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR16	/* index 6 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR17	/* index 7 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR18	/* index 8 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR19	/* index 9 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR1A	/* index 10 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR1B	/* index 11 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR1C	/* index 12 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR1D	/* index 13 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR1E	/* index 14 */
	bx		lr
	stcopr16	r0,r1,	AMEVCNTR1F	/* index 15 */
	bx		lr
endfunc amu_group1_cnt_write_internal

/*
 * void amu_group1_set_evtype_internal(int idx, unsigned int val);
 *
 * Program the AMU event type register indexed by `idx`
 * with the value `val`.
 */
func amu_group1_set_evtype_internal
#if ENABLE_ASSERTIONS
	/* `idx` should be between [0, 15] */
	mov	r2, r0
	lsr	r2, r2, #4
	cmp	r2, #0
	ASM_ASSERT(eq)

	/* val should be between [0, 65535] */
	mov	r2, r1
	lsr	r2, r2, #16
	cmp	r2, #0
	ASM_ASSERT(eq)
#endif

	/*
	 * Given `idx` calculate address of stcopr/bx lr instruction pair
	 * in the table below.
	 */
	adr	r2, 1f
	lsl	r0, r0, #3	/* each stcopr/bx lr sequence is 8 bytes */
	add	r2, r2, r0
	bx	r2

1:
	stcopr	r0,	AMEVTYPER10 /* index 0 */
	bx	lr
	stcopr	r0,	AMEVTYPER11 /* index 1 */
	bx	lr
	stcopr	r0,	AMEVTYPER12 /* index 2 */
	bx	lr
	stcopr	r0,	AMEVTYPER13 /* index 3 */
	bx	lr
	stcopr	r0,	AMEVTYPER14 /* index 4 */
	bx	lr
	stcopr	r0,	AMEVTYPER15 /* index 5 */
	bx	lr
	stcopr	r0,	AMEVTYPER16 /* index 6 */
	bx	lr
	stcopr	r0,	AMEVTYPER17 /* index 7 */
	bx	lr
	stcopr	r0,	AMEVTYPER18 /* index 8 */
	bx	lr
	stcopr	r0,	AMEVTYPER19 /* index 9 */
	bx	lr
	stcopr	r0,	AMEVTYPER1A /* index 10 */
	bx	lr
	stcopr	r0,	AMEVTYPER1B /* index 11 */
	bx	lr
	stcopr	r0,	AMEVTYPER1C /* index 12 */
	bx	lr
	stcopr	r0,	AMEVTYPER1D /* index 13 */
	bx	lr
	stcopr	r0,	AMEVTYPER1E /* index 14 */
	bx	lr
	stcopr	r0,	AMEVTYPER1F /* index 15 */
	bx	lr
endfunc amu_group1_set_evtype_internal