summaryrefslogtreecommitdiff
path: root/lib/extensions/amu/aarch64/amu_helpers.S
blob: aa12f3fc81427066247766cf49e72b573958ccf1 (plain)
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
/*
 * Copyright (c) 2017, 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_group1_cnt_read_internal

/*
 * uint64_t amu_group0_cnt_read_internal(int idx);
 *
 * Given `idx`, read the corresponding AMU counter
 * and return it in `x0`.
 */
func amu_group0_cnt_read_internal
#if ENABLE_ASSERTIONS
	/*
	 * It can be dangerous to call this function with an
	 * out of bounds index.  Ensure `idx` is valid.
	 */
	mov	x1, x0
	lsr	x1, x1, #2
	cmp	x1, #0
	ASM_ASSERT(eq)
#endif

	/*
	 * Given `idx` calculate address of mrs/ret instruction pair
	 * in the table below.
	 */
	adr	x1, 1f
	lsl	x0, x0, #3		/* each mrs/ret sequence is 8 bytes */
	add	x1, x1, x0
	br	x1

1:
	mrs	x0, AMEVCNTR00_EL0	/* index 0 */
	ret
	mrs	x0, AMEVCNTR01_EL0	/* index 1 */
	ret
	mrs	x0, AMEVCNTR02_EL0	/* index 2 */
	ret
	mrs	x0, AMEVCNTR03_EL0	/* index 3 */
	ret
endfunc amu_group0_cnt_read_internal

/*
 * uint64_t amu_group1_cnt_read_internal(int idx);
 *
 * Given `idx`, read the corresponding AMU counter
 * and return it in `x0`.
 */
func amu_group1_cnt_read_internal
#if ENABLE_ASSERTIONS
	/*
	 * It can be dangerous to call this function with an
	 * out of bounds index.  Ensure `idx` is valid.
	 */
	mov	x1, x0
	lsr	x1, x1, #4
	cmp	x1, #0
	ASM_ASSERT(eq)
#endif

	/*
	 * Given `idx` calculate address of mrs/ret instruction pair
	 * in the table below.
	 */
	adr	x1, 1f
	lsl	x0, x0, #3		/* each mrs/ret sequence is 8 bytes */
	add	x1, x1, x0
	br	x1

1:
	mrs	x0, AMEVCNTR10_EL0	/* index 0 */
	ret
	mrs	x0, AMEVCNTR11_EL0	/* index 1 */
	ret
	mrs	x0, AMEVCNTR12_EL0	/* index 2 */
	ret
	mrs	x0, AMEVCNTR13_EL0	/* index 3 */
	ret
	mrs	x0, AMEVCNTR14_EL0	/* index 4 */
	ret
	mrs	x0, AMEVCNTR15_EL0	/* index 5 */
	ret
	mrs	x0, AMEVCNTR16_EL0	/* index 6 */
	ret
	mrs	x0, AMEVCNTR17_EL0	/* index 7 */
	ret
	mrs	x0, AMEVCNTR18_EL0	/* index 8 */
	ret
	mrs	x0, AMEVCNTR19_EL0	/* index 9 */
	ret
	mrs	x0, AMEVCNTR1A_EL0	/* index 10 */
	ret
	mrs	x0, AMEVCNTR1B_EL0	/* index 11 */
	ret
	mrs	x0, AMEVCNTR1C_EL0	/* index 12 */
	ret
	mrs	x0, AMEVCNTR1D_EL0	/* index 13 */
	ret
	mrs	x0, AMEVCNTR1E_EL0	/* index 14 */
	ret
	mrs	x0, AMEVCNTR1F_EL0	/* index 15 */
	ret
endfunc amu_group1_cnt_read_internal