summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/powerpc/pmu/ebb/ebb_handler.S
blob: 14274ea206e563366cf8c80126175d2ed7cc3ed4 (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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*
 * Copyright 2014, Michael Ellerman, IBM Corp.
 * Licensed under GPLv2.
 */

#include <ppc-asm.h>
#include "reg.h"


/* ppc-asm.h defines most of the reg aliases, but not r1/r2. */
#define r1 1
#define r2 2

#define RFEBB   .long 0x4c000924

/* Stack layout:
 *
 *                   ^
 *  User stack       |
 *  Back chain ------+	<- r1		<-------+
 *  ...						|
 *  Red zone / ABI Gap				|
 *  ...						|
 *  vr63	<+				|
 *  vr0		 |				|
 *  VSCR	 |				|
 *  FSCR	 |				|
 *  r31		 | Save area			|
 *  r0		 |				|
 *  XER		 |				|
 *  CTR		 |				|
 *  LR		 |				|
 *  CCR		<+				|
 *  ...		<+				|
 *  LR		 | Caller frame			|
 *  CCR		 |				|
 *  Back chain	<+	<- updated r1	--------+
 *
 */

#if defined(_CALL_ELF) && _CALL_ELF == 2
#define ABIGAP		512
#else
#define ABIGAP		288
#endif

#define NR_GPR		32
#define NR_SPR		6
#define NR_VSR		64

#define SAVE_AREA	((NR_GPR + NR_SPR) * 8 + (NR_VSR * 16))
#define CALLER_FRAME	112

#define STACK_FRAME	(ABIGAP + SAVE_AREA + CALLER_FRAME)

#define CCR_SAVE	(CALLER_FRAME)
#define LR_SAVE		(CCR_SAVE + 8)
#define CTR_SAVE	(LR_SAVE  + 8)
#define XER_SAVE	(CTR_SAVE + 8)
#define GPR_SAVE(n)	(XER_SAVE + 8 + (8 * n))
#define FSCR_SAVE	(GPR_SAVE(31) + 8)
#define VSCR_SAVE	(FSCR_SAVE + 8)
#define VSR_SAVE(n)	(VSCR_SAVE + 8 + (16 * n))

#define SAVE_GPR(n)	std n,GPR_SAVE(n)(r1)
#define REST_GPR(n)	ld  n,GPR_SAVE(n)(r1)
#define TRASH_GPR(n)	lis n,0xaaaa

#define SAVE_VSR(n, b)	li b, VSR_SAVE(n); stxvd2x n,b,r1
#define LOAD_VSR(n, b)	li b, VSR_SAVE(n); lxvd2x  n,b,r1

#define LOAD_REG_IMMEDIATE(reg,expr)	\
	lis     reg,(expr)@highest;	\
	ori     reg,reg,(expr)@higher;	\
	rldicr  reg,reg,32,31;		\
	oris    reg,reg,(expr)@h;	\
	ori     reg,reg,(expr)@l;


#if defined(_CALL_ELF) && _CALL_ELF == 2
#define ENTRY_POINT(name) \
	.type FUNC_NAME(name),@function; \
	.globl FUNC_NAME(name); \
	FUNC_NAME(name):

#define RESTORE_TOC(name)	\
	/* Restore our TOC pointer using our entry point */	\
	LOAD_REG_IMMEDIATE(r12, name)				\
0:	addis	r2,r12,(.TOC.-0b)@ha;				\
	addi	r2,r2,(.TOC.-0b)@l;

#else
#define ENTRY_POINT(name) FUNC_START(name)
#define RESTORE_TOC(name)	\
	/* Restore our TOC pointer via our opd entry */	\
	LOAD_REG_IMMEDIATE(r2, name)			\
	ld      r2,8(r2);
#endif

    .text

ENTRY_POINT(ebb_handler)
    stdu    r1,-STACK_FRAME(r1)
    SAVE_GPR(0)
    mflr    r0
    std     r0,LR_SAVE(r1)
    mfcr    r0
    std     r0,CCR_SAVE(r1)
    mfctr   r0
    std     r0,CTR_SAVE(r1)
    mfxer   r0
    std     r0,XER_SAVE(r1)
    SAVE_GPR(2)
    SAVE_GPR(3)
    SAVE_GPR(4)
    SAVE_GPR(5)
    SAVE_GPR(6)
    SAVE_GPR(7)
    SAVE_GPR(8)
    SAVE_GPR(9)
    SAVE_GPR(10)
    SAVE_GPR(11)
    SAVE_GPR(12)
    SAVE_GPR(13)
    SAVE_GPR(14)
    SAVE_GPR(15)
    SAVE_GPR(16)
    SAVE_GPR(17)
    SAVE_GPR(18)
    SAVE_GPR(19)
    SAVE_GPR(20)
    SAVE_GPR(21)
    SAVE_GPR(22)
    SAVE_GPR(23)
    SAVE_GPR(24)
    SAVE_GPR(25)
    SAVE_GPR(26)
    SAVE_GPR(27)
    SAVE_GPR(28)
    SAVE_GPR(29)
    SAVE_GPR(30)
    SAVE_GPR(31)
    SAVE_VSR(0, r3)
    mffs     f0
    stfd     f0, FSCR_SAVE(r1)
    mfvscr   f0
    stfd     f0, VSCR_SAVE(r1)
    SAVE_VSR(1,  r3)
    SAVE_VSR(2,  r3)
    SAVE_VSR(3,  r3)
    SAVE_VSR(4,  r3)
    SAVE_VSR(5,  r3)
    SAVE_VSR(6,  r3)
    SAVE_VSR(7,  r3)
    SAVE_VSR(8,  r3)
    SAVE_VSR(9,  r3)
    SAVE_VSR(10, r3)
    SAVE_VSR(11, r3)
    SAVE_VSR(12, r3)
    SAVE_VSR(13, r3)
    SAVE_VSR(14, r3)
    SAVE_VSR(15, r3)
    SAVE_VSR(16, r3)
    SAVE_VSR(17, r3)
    SAVE_VSR(18, r3)
    SAVE_VSR(19, r3)
    SAVE_VSR(20, r3)
    SAVE_VSR(21, r3)
    SAVE_VSR(22, r3)
    SAVE_VSR(23, r3)
    SAVE_VSR(24, r3)
    SAVE_VSR(25, r3)
    SAVE_VSR(26, r3)
    SAVE_VSR(27, r3)
    SAVE_VSR(28, r3)
    SAVE_VSR(29, r3)
    SAVE_VSR(30, r3)
    SAVE_VSR(31, r3)
    SAVE_VSR(32, r3)
    SAVE_VSR(33, r3)
    SAVE_VSR(34, r3)
    SAVE_VSR(35, r3)
    SAVE_VSR(36, r3)
    SAVE_VSR(37, r3)
    SAVE_VSR(38, r3)
    SAVE_VSR(39, r3)
    SAVE_VSR(40, r3)
    SAVE_VSR(41, r3)
    SAVE_VSR(42, r3)
    SAVE_VSR(43, r3)
    SAVE_VSR(44, r3)
    SAVE_VSR(45, r3)
    SAVE_VSR(46, r3)
    SAVE_VSR(47, r3)
    SAVE_VSR(48, r3)
    SAVE_VSR(49, r3)
    SAVE_VSR(50, r3)
    SAVE_VSR(51, r3)
    SAVE_VSR(52, r3)
    SAVE_VSR(53, r3)
    SAVE_VSR(54, r3)
    SAVE_VSR(55, r3)
    SAVE_VSR(56, r3)
    SAVE_VSR(57, r3)
    SAVE_VSR(58, r3)
    SAVE_VSR(59, r3)
    SAVE_VSR(60, r3)
    SAVE_VSR(61, r3)
    SAVE_VSR(62, r3)
    SAVE_VSR(63, r3)

    TRASH_GPR(2)
    TRASH_GPR(3)
    TRASH_GPR(4)
    TRASH_GPR(5)
    TRASH_GPR(6)
    TRASH_GPR(7)
    TRASH_GPR(8)
    TRASH_GPR(9)
    TRASH_GPR(10)
    TRASH_GPR(11)
    TRASH_GPR(12)
    TRASH_GPR(14)
    TRASH_GPR(15)
    TRASH_GPR(16)
    TRASH_GPR(17)
    TRASH_GPR(18)
    TRASH_GPR(19)
    TRASH_GPR(20)
    TRASH_GPR(21)
    TRASH_GPR(22)
    TRASH_GPR(23)
    TRASH_GPR(24)
    TRASH_GPR(25)
    TRASH_GPR(26)
    TRASH_GPR(27)
    TRASH_GPR(28)
    TRASH_GPR(29)
    TRASH_GPR(30)
    TRASH_GPR(31)

    RESTORE_TOC(ebb_handler)

    /*
     * r13 is our TLS pointer. We leave whatever value was in there when the
     * EBB fired. That seems to be OK because once set the TLS pointer is not
     * changed - but presumably that could change in future.
     */

    bl      ebb_hook
    nop

    /* r2 may be changed here but we don't care */

    lfd      f0, FSCR_SAVE(r1)
    mtfsf    0xff,f0
    lfd      f0, VSCR_SAVE(r1)
    mtvscr   f0
    LOAD_VSR(0, r3)
    LOAD_VSR(1,  r3)
    LOAD_VSR(2,  r3)
    LOAD_VSR(3,  r3)
    LOAD_VSR(4,  r3)
    LOAD_VSR(5,  r3)
    LOAD_VSR(6,  r3)
    LOAD_VSR(7,  r3)
    LOAD_VSR(8,  r3)
    LOAD_VSR(9,  r3)
    LOAD_VSR(10, r3)
    LOAD_VSR(11, r3)
    LOAD_VSR(12, r3)
    LOAD_VSR(13, r3)
    LOAD_VSR(14, r3)
    LOAD_VSR(15, r3)
    LOAD_VSR(16, r3)
    LOAD_VSR(17, r3)
    LOAD_VSR(18, r3)
    LOAD_VSR(19, r3)
    LOAD_VSR(20, r3)
    LOAD_VSR(21, r3)
    LOAD_VSR(22, r3)
    LOAD_VSR(23, r3)
    LOAD_VSR(24, r3)
    LOAD_VSR(25, r3)
    LOAD_VSR(26, r3)
    LOAD_VSR(27, r3)
    LOAD_VSR(28, r3)
    LOAD_VSR(29, r3)
    LOAD_VSR(30, r3)
    LOAD_VSR(31, r3)
    LOAD_VSR(32, r3)
    LOAD_VSR(33, r3)
    LOAD_VSR(34, r3)
    LOAD_VSR(35, r3)
    LOAD_VSR(36, r3)
    LOAD_VSR(37, r3)
    LOAD_VSR(38, r3)
    LOAD_VSR(39, r3)
    LOAD_VSR(40, r3)
    LOAD_VSR(41, r3)
    LOAD_VSR(42, r3)
    LOAD_VSR(43, r3)
    LOAD_VSR(44, r3)
    LOAD_VSR(45, r3)
    LOAD_VSR(46, r3)
    LOAD_VSR(47, r3)
    LOAD_VSR(48, r3)
    LOAD_VSR(49, r3)
    LOAD_VSR(50, r3)
    LOAD_VSR(51, r3)
    LOAD_VSR(52, r3)
    LOAD_VSR(53, r3)
    LOAD_VSR(54, r3)
    LOAD_VSR(55, r3)
    LOAD_VSR(56, r3)
    LOAD_VSR(57, r3)
    LOAD_VSR(58, r3)
    LOAD_VSR(59, r3)
    LOAD_VSR(60, r3)
    LOAD_VSR(61, r3)
    LOAD_VSR(62, r3)
    LOAD_VSR(63, r3)

    ld      r0,XER_SAVE(r1)
    mtxer   r0
    ld      r0,CTR_SAVE(r1)
    mtctr   r0
    ld      r0,LR_SAVE(r1)
    mtlr    r0
    ld      r0,CCR_SAVE(r1)
    mtcr    r0
    REST_GPR(0)
    REST_GPR(2)
    REST_GPR(3)
    REST_GPR(4)
    REST_GPR(5)
    REST_GPR(6)
    REST_GPR(7)
    REST_GPR(8)
    REST_GPR(9)
    REST_GPR(10)
    REST_GPR(11)
    REST_GPR(12)
    REST_GPR(13)
    REST_GPR(14)
    REST_GPR(15)
    REST_GPR(16)
    REST_GPR(17)
    REST_GPR(18)
    REST_GPR(19)
    REST_GPR(20)
    REST_GPR(21)
    REST_GPR(22)
    REST_GPR(23)
    REST_GPR(24)
    REST_GPR(25)
    REST_GPR(26)
    REST_GPR(27)
    REST_GPR(28)
    REST_GPR(29)
    REST_GPR(30)
    REST_GPR(31)
    addi    r1,r1,STACK_FRAME
    RFEBB
FUNC_END(ebb_handler)