xref: /openbmc/linux/arch/powerpc/xmon/spr_access.S (revision ba61bb17)
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <asm/ppc_asm.h>
3
4/* unsigned long xmon_mfspr(sprn, default_value) */
5_GLOBAL(xmon_mfspr)
6	PPC_LL	r5, .Lmfspr_table@got(r2)
7	b	xmon_mxspr
8
9/* void xmon_mtspr(sprn, new_value) */
10_GLOBAL(xmon_mtspr)
11	PPC_LL	r5, .Lmtspr_table@got(r2)
12	b	xmon_mxspr
13
14/*
15 * r3 = sprn
16 * r4 = default or new value
17 * r5 = table base
18 */
19xmon_mxspr:
20	/*
21	 * To index into the table of mxsprs we need:
22	 *  i = (sprn & 0x3ff) * 8
23	 * or using rwlinm:
24	 *  i = (sprn << 3) & (0x3ff << 3)
25	 */
26	rlwinm	r3, r3, 3, 0x3ff << 3
27	add	r5, r5, r3
28	mtctr	r5
29	mr	r3, r4 /* put default_value in r3 for mfspr */
30	bctr
31
32.Lmfspr_table:
33	spr = 0
34	.rept	1024
35	mfspr	r3, spr
36	blr
37	spr = spr + 1
38	.endr
39
40.Lmtspr_table:
41	spr = 0
42	.rept	1024
43	mtspr	spr, r4
44	blr
45	spr = spr + 1
46	.endr
47