18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * This file contains miscellaneous low-level functions.
48c2ecf20Sopenharmony_ci *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
78c2ecf20Sopenharmony_ci * and Paul Mackerras.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * PPC64 updates by Dave Engebretsen (engebret@us.ibm.com)
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * setjmp/longjmp code by Paul Mackerras.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci#include <asm/ppc_asm.h>
148c2ecf20Sopenharmony_ci#include <asm/unistd.h>
158c2ecf20Sopenharmony_ci#include <asm/asm-compat.h>
168c2ecf20Sopenharmony_ci#include <asm/asm-offsets.h>
178c2ecf20Sopenharmony_ci#include <asm/export.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	.text
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * Returns (address we are running at) - (address we were linked at)
238c2ecf20Sopenharmony_ci * for use before the text and data are mapped to KERNELBASE.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci * add_reloc_offset(x) returns x + reloc_offset().
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci_GLOBAL(reloc_offset)
298c2ecf20Sopenharmony_ci	li	r3, 0
308c2ecf20Sopenharmony_ci_GLOBAL(add_reloc_offset)
318c2ecf20Sopenharmony_ci	mflr	r0
328c2ecf20Sopenharmony_ci	bl	1f
338c2ecf20Sopenharmony_ci1:	mflr	r5
348c2ecf20Sopenharmony_ci	PPC_LL	r4,(2f-1b)(r5)
358c2ecf20Sopenharmony_ci	subf	r5,r4,r5
368c2ecf20Sopenharmony_ci	add	r3,r3,r5
378c2ecf20Sopenharmony_ci	mtlr	r0
388c2ecf20Sopenharmony_ci	blr
398c2ecf20Sopenharmony_ci_ASM_NOKPROBE_SYMBOL(reloc_offset)
408c2ecf20Sopenharmony_ci_ASM_NOKPROBE_SYMBOL(add_reloc_offset)
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	.align	3
438c2ecf20Sopenharmony_ci2:	PPC_LONG 1b
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci_GLOBAL(setjmp)
468c2ecf20Sopenharmony_ci	mflr	r0
478c2ecf20Sopenharmony_ci	PPC_STL	r0,0(r3)
488c2ecf20Sopenharmony_ci	PPC_STL	r1,SZL(r3)
498c2ecf20Sopenharmony_ci	PPC_STL	r2,2*SZL(r3)
508c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC32
518c2ecf20Sopenharmony_ci	mfcr	r12
528c2ecf20Sopenharmony_ci	stmw	r12, 3*SZL(r3)
538c2ecf20Sopenharmony_ci#else
548c2ecf20Sopenharmony_ci	mfcr	r0
558c2ecf20Sopenharmony_ci	PPC_STL	r0,3*SZL(r3)
568c2ecf20Sopenharmony_ci	PPC_STL	r13,4*SZL(r3)
578c2ecf20Sopenharmony_ci	PPC_STL	r14,5*SZL(r3)
588c2ecf20Sopenharmony_ci	PPC_STL	r15,6*SZL(r3)
598c2ecf20Sopenharmony_ci	PPC_STL	r16,7*SZL(r3)
608c2ecf20Sopenharmony_ci	PPC_STL	r17,8*SZL(r3)
618c2ecf20Sopenharmony_ci	PPC_STL	r18,9*SZL(r3)
628c2ecf20Sopenharmony_ci	PPC_STL	r19,10*SZL(r3)
638c2ecf20Sopenharmony_ci	PPC_STL	r20,11*SZL(r3)
648c2ecf20Sopenharmony_ci	PPC_STL	r21,12*SZL(r3)
658c2ecf20Sopenharmony_ci	PPC_STL	r22,13*SZL(r3)
668c2ecf20Sopenharmony_ci	PPC_STL	r23,14*SZL(r3)
678c2ecf20Sopenharmony_ci	PPC_STL	r24,15*SZL(r3)
688c2ecf20Sopenharmony_ci	PPC_STL	r25,16*SZL(r3)
698c2ecf20Sopenharmony_ci	PPC_STL	r26,17*SZL(r3)
708c2ecf20Sopenharmony_ci	PPC_STL	r27,18*SZL(r3)
718c2ecf20Sopenharmony_ci	PPC_STL	r28,19*SZL(r3)
728c2ecf20Sopenharmony_ci	PPC_STL	r29,20*SZL(r3)
738c2ecf20Sopenharmony_ci	PPC_STL	r30,21*SZL(r3)
748c2ecf20Sopenharmony_ci	PPC_STL	r31,22*SZL(r3)
758c2ecf20Sopenharmony_ci#endif
768c2ecf20Sopenharmony_ci	li	r3,0
778c2ecf20Sopenharmony_ci	blr
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci_GLOBAL(longjmp)
808c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC32
818c2ecf20Sopenharmony_ci	lmw	r12, 3*SZL(r3)
828c2ecf20Sopenharmony_ci	mtcrf	0x38, r12
838c2ecf20Sopenharmony_ci#else
848c2ecf20Sopenharmony_ci	PPC_LL	r13,4*SZL(r3)
858c2ecf20Sopenharmony_ci	PPC_LL	r14,5*SZL(r3)
868c2ecf20Sopenharmony_ci	PPC_LL	r15,6*SZL(r3)
878c2ecf20Sopenharmony_ci	PPC_LL	r16,7*SZL(r3)
888c2ecf20Sopenharmony_ci	PPC_LL	r17,8*SZL(r3)
898c2ecf20Sopenharmony_ci	PPC_LL	r18,9*SZL(r3)
908c2ecf20Sopenharmony_ci	PPC_LL	r19,10*SZL(r3)
918c2ecf20Sopenharmony_ci	PPC_LL	r20,11*SZL(r3)
928c2ecf20Sopenharmony_ci	PPC_LL	r21,12*SZL(r3)
938c2ecf20Sopenharmony_ci	PPC_LL	r22,13*SZL(r3)
948c2ecf20Sopenharmony_ci	PPC_LL	r23,14*SZL(r3)
958c2ecf20Sopenharmony_ci	PPC_LL	r24,15*SZL(r3)
968c2ecf20Sopenharmony_ci	PPC_LL	r25,16*SZL(r3)
978c2ecf20Sopenharmony_ci	PPC_LL	r26,17*SZL(r3)
988c2ecf20Sopenharmony_ci	PPC_LL	r27,18*SZL(r3)
998c2ecf20Sopenharmony_ci	PPC_LL	r28,19*SZL(r3)
1008c2ecf20Sopenharmony_ci	PPC_LL	r29,20*SZL(r3)
1018c2ecf20Sopenharmony_ci	PPC_LL	r30,21*SZL(r3)
1028c2ecf20Sopenharmony_ci	PPC_LL	r31,22*SZL(r3)
1038c2ecf20Sopenharmony_ci	PPC_LL	r0,3*SZL(r3)
1048c2ecf20Sopenharmony_ci	mtcrf	0x38,r0
1058c2ecf20Sopenharmony_ci#endif
1068c2ecf20Sopenharmony_ci	PPC_LL	r0,0(r3)
1078c2ecf20Sopenharmony_ci	PPC_LL	r1,SZL(r3)
1088c2ecf20Sopenharmony_ci	PPC_LL	r2,2*SZL(r3)
1098c2ecf20Sopenharmony_ci	mtlr	r0
1108c2ecf20Sopenharmony_ci	mr.	r3, r4
1118c2ecf20Sopenharmony_ci	bnelr
1128c2ecf20Sopenharmony_ci	li	r3, 1
1138c2ecf20Sopenharmony_ci	blr
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci_GLOBAL(current_stack_frame)
1168c2ecf20Sopenharmony_ci	PPC_LL	r3,0(r1)
1178c2ecf20Sopenharmony_ci	blr
1188c2ecf20Sopenharmony_ciEXPORT_SYMBOL(current_stack_frame)
119