xref: /openbmc/linux/arch/powerpc/kernel/misc.S (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
12874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
2127efeb2SStephen Rothwell/*
3127efeb2SStephen Rothwell * This file contains miscellaneous low-level functions.
4127efeb2SStephen Rothwell *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5127efeb2SStephen Rothwell *
6127efeb2SStephen Rothwell * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
7127efeb2SStephen Rothwell * and Paul Mackerras.
8127efeb2SStephen Rothwell *
9127efeb2SStephen Rothwell * PPC64 updates by Dave Engebretsen (engebret@us.ibm.com)
10127efeb2SStephen Rothwell *
11c3b75bd7SMichael Neuling * setjmp/longjmp code by Paul Mackerras.
12127efeb2SStephen Rothwell */
13*39326182SMasahiro Yamada#include <linux/export.h>
14127efeb2SStephen Rothwell#include <asm/ppc_asm.h>
1594b146ceSStephen Rothwell#include <asm/unistd.h>
16c3b75bd7SMichael Neuling#include <asm/asm-compat.h>
17c3b75bd7SMichael Neuling#include <asm/asm-offsets.h>
18127efeb2SStephen Rothwell
19127efeb2SStephen Rothwell	.text
20127efeb2SStephen Rothwell
21127efeb2SStephen Rothwell/*
22127efeb2SStephen Rothwell * Returns (address we are running at) - (address we were linked at)
23127efeb2SStephen Rothwell * for use before the text and data are mapped to KERNELBASE.
240cc377d1SChristophe Leroy
250cc377d1SChristophe Leroy * add_reloc_offset(x) returns x + reloc_offset().
26127efeb2SStephen Rothwell */
27127efeb2SStephen Rothwell
28127efeb2SStephen Rothwell_GLOBAL(reloc_offset)
290cc377d1SChristophe Leroy	li	r3, 0
30127efeb2SStephen Rothwell_GLOBAL(add_reloc_offset)
31127efeb2SStephen Rothwell	mflr	r0
3233e14024SChristophe Leroy	bcl	20,31,$+4
33127efeb2SStephen Rothwell1:	mflr	r5
34e31aa453SPaul Mackerras	PPC_LL	r4,(2f-1b)(r5)
35127efeb2SStephen Rothwell	subf	r5,r4,r5
36127efeb2SStephen Rothwell	add	r3,r3,r5
37127efeb2SStephen Rothwell	mtlr	r0
38127efeb2SStephen Rothwell	blr
395f32e836SChristophe Leroy_ASM_NOKPROBE_SYMBOL(reloc_offset)
405f32e836SChristophe Leroy_ASM_NOKPROBE_SYMBOL(add_reloc_offset)
4194b146ceSStephen Rothwell
42e31aa453SPaul Mackerras	.align	3
43e31aa453SPaul Mackerras2:	PPC_LONG 1b
44e31aa453SPaul Mackerras
45c3b75bd7SMichael Neuling_GLOBAL(setjmp)
46c3b75bd7SMichael Neuling	mflr	r0
47c3b75bd7SMichael Neuling	PPC_STL	r0,0(r3)
48c3b75bd7SMichael Neuling	PPC_STL	r1,SZL(r3)
49c3b75bd7SMichael Neuling	PPC_STL	r2,2*SZL(r3)
50a1f3ae3fSChristophe Leroy#ifdef CONFIG_PPC32
51a1f3ae3fSChristophe Leroy	mfcr	r12
52a1f3ae3fSChristophe Leroy	stmw	r12, 3*SZL(r3)
53a1f3ae3fSChristophe Leroy#else
54c3b75bd7SMichael Neuling	mfcr	r0
55c3b75bd7SMichael Neuling	PPC_STL	r0,3*SZL(r3)
56c3b75bd7SMichael Neuling	PPC_STL	r13,4*SZL(r3)
57c3b75bd7SMichael Neuling	PPC_STL	r14,5*SZL(r3)
58c3b75bd7SMichael Neuling	PPC_STL	r15,6*SZL(r3)
59c3b75bd7SMichael Neuling	PPC_STL	r16,7*SZL(r3)
60c3b75bd7SMichael Neuling	PPC_STL	r17,8*SZL(r3)
61c3b75bd7SMichael Neuling	PPC_STL	r18,9*SZL(r3)
62c3b75bd7SMichael Neuling	PPC_STL	r19,10*SZL(r3)
63c3b75bd7SMichael Neuling	PPC_STL	r20,11*SZL(r3)
64c3b75bd7SMichael Neuling	PPC_STL	r21,12*SZL(r3)
65c3b75bd7SMichael Neuling	PPC_STL	r22,13*SZL(r3)
66c3b75bd7SMichael Neuling	PPC_STL	r23,14*SZL(r3)
67c3b75bd7SMichael Neuling	PPC_STL	r24,15*SZL(r3)
68c3b75bd7SMichael Neuling	PPC_STL	r25,16*SZL(r3)
69c3b75bd7SMichael Neuling	PPC_STL	r26,17*SZL(r3)
70c3b75bd7SMichael Neuling	PPC_STL	r27,18*SZL(r3)
71c3b75bd7SMichael Neuling	PPC_STL	r28,19*SZL(r3)
72c3b75bd7SMichael Neuling	PPC_STL	r29,20*SZL(r3)
73c3b75bd7SMichael Neuling	PPC_STL	r30,21*SZL(r3)
74c3b75bd7SMichael Neuling	PPC_STL	r31,22*SZL(r3)
75a1f3ae3fSChristophe Leroy#endif
76c3b75bd7SMichael Neuling	li	r3,0
77c3b75bd7SMichael Neuling	blr
78c3b75bd7SMichael Neuling
79c3b75bd7SMichael Neuling_GLOBAL(longjmp)
80a1f3ae3fSChristophe Leroy#ifdef CONFIG_PPC32
81a1f3ae3fSChristophe Leroy	lmw	r12, 3*SZL(r3)
82a1f3ae3fSChristophe Leroy	mtcrf	0x38, r12
83a1f3ae3fSChristophe Leroy#else
8424c78586SChristophe Leroy	PPC_LL	r13,4*SZL(r3)
85c3b75bd7SMichael Neuling	PPC_LL	r14,5*SZL(r3)
86c3b75bd7SMichael Neuling	PPC_LL	r15,6*SZL(r3)
87c3b75bd7SMichael Neuling	PPC_LL	r16,7*SZL(r3)
88c3b75bd7SMichael Neuling	PPC_LL	r17,8*SZL(r3)
89c3b75bd7SMichael Neuling	PPC_LL	r18,9*SZL(r3)
90c3b75bd7SMichael Neuling	PPC_LL	r19,10*SZL(r3)
91c3b75bd7SMichael Neuling	PPC_LL	r20,11*SZL(r3)
92c3b75bd7SMichael Neuling	PPC_LL	r21,12*SZL(r3)
93c3b75bd7SMichael Neuling	PPC_LL	r22,13*SZL(r3)
94c3b75bd7SMichael Neuling	PPC_LL	r23,14*SZL(r3)
95c3b75bd7SMichael Neuling	PPC_LL	r24,15*SZL(r3)
96c3b75bd7SMichael Neuling	PPC_LL	r25,16*SZL(r3)
97c3b75bd7SMichael Neuling	PPC_LL	r26,17*SZL(r3)
98c3b75bd7SMichael Neuling	PPC_LL	r27,18*SZL(r3)
99c3b75bd7SMichael Neuling	PPC_LL	r28,19*SZL(r3)
100c3b75bd7SMichael Neuling	PPC_LL	r29,20*SZL(r3)
101c3b75bd7SMichael Neuling	PPC_LL	r30,21*SZL(r3)
102c3b75bd7SMichael Neuling	PPC_LL	r31,22*SZL(r3)
103c3b75bd7SMichael Neuling	PPC_LL	r0,3*SZL(r3)
104c3b75bd7SMichael Neuling	mtcrf	0x38,r0
105a1f3ae3fSChristophe Leroy#endif
106c3b75bd7SMichael Neuling	PPC_LL	r0,0(r3)
107c3b75bd7SMichael Neuling	PPC_LL	r1,SZL(r3)
108c3b75bd7SMichael Neuling	PPC_LL	r2,2*SZL(r3)
109c3b75bd7SMichael Neuling	mtlr	r0
11024c78586SChristophe Leroy	mr.	r3, r4
11124c78586SChristophe Leroy	bnelr
11224c78586SChristophe Leroy	li	r3, 1
113c3b75bd7SMichael Neuling	blr
114bfe9a2cfSAnton Blanchard
1153d13e839SMichael Ellerman_GLOBAL(current_stack_frame)
116bfe9a2cfSAnton Blanchard	PPC_LL	r3,0(r1)
117bfe9a2cfSAnton Blanchard	blr
1183d13e839SMichael EllermanEXPORT_SYMBOL(current_stack_frame)
119