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