xref: /linux/arch/riscv/include/asm/assembler.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1fcb89863SSia Jee Heng /* SPDX-License-Identifier: GPL-2.0-only */
2fcb89863SSia Jee Heng /*
3fcb89863SSia Jee Heng  * Copyright (C) 2023 StarFive Technology Co., Ltd.
4fcb89863SSia Jee Heng  *
5fcb89863SSia Jee Heng  * Author: Jee Heng Sia <jeeheng.sia@starfivetech.com>
6fcb89863SSia Jee Heng  */
7fcb89863SSia Jee Heng 
8fcb89863SSia Jee Heng #ifndef __ASSEMBLY__
9fcb89863SSia Jee Heng #error "Only include this from assembly code"
10fcb89863SSia Jee Heng #endif
11fcb89863SSia Jee Heng 
12fcb89863SSia Jee Heng #ifndef __ASM_ASSEMBLER_H
13fcb89863SSia Jee Heng #define __ASM_ASSEMBLER_H
14fcb89863SSia Jee Heng 
15fcb89863SSia Jee Heng #include <asm/asm.h>
16fcb89863SSia Jee Heng #include <asm/asm-offsets.h>
17fcb89863SSia Jee Heng #include <asm/csr.h>
18fcb89863SSia Jee Heng 
19fcb89863SSia Jee Heng /*
20fcb89863SSia Jee Heng  * suspend_restore_csrs - restore CSRs
21fcb89863SSia Jee Heng  */
22fcb89863SSia Jee Heng 	.macro suspend_restore_csrs
23fcb89863SSia Jee Heng 		REG_L	t0, (SUSPEND_CONTEXT_REGS + PT_EPC)(a0)
24fcb89863SSia Jee Heng 		csrw	CSR_EPC, t0
25fcb89863SSia Jee Heng 		REG_L	t0, (SUSPEND_CONTEXT_REGS + PT_STATUS)(a0)
26fcb89863SSia Jee Heng 		csrw	CSR_STATUS, t0
27fcb89863SSia Jee Heng 		REG_L	t0, (SUSPEND_CONTEXT_REGS + PT_BADADDR)(a0)
28fcb89863SSia Jee Heng 		csrw	CSR_TVAL, t0
29fcb89863SSia Jee Heng 		REG_L	t0, (SUSPEND_CONTEXT_REGS + PT_CAUSE)(a0)
30fcb89863SSia Jee Heng 		csrw	CSR_CAUSE, t0
31fcb89863SSia Jee Heng 	.endm
32fcb89863SSia Jee Heng 
33fcb89863SSia Jee Heng /*
34fcb89863SSia Jee Heng  * suspend_restore_regs - Restore registers (except A0 and T0-T6)
35fcb89863SSia Jee Heng  */
36fcb89863SSia Jee Heng 	.macro suspend_restore_regs
37fcb89863SSia Jee Heng 		REG_L	ra, (SUSPEND_CONTEXT_REGS + PT_RA)(a0)
38fcb89863SSia Jee Heng 		REG_L	sp, (SUSPEND_CONTEXT_REGS + PT_SP)(a0)
39fcb89863SSia Jee Heng 		REG_L	gp, (SUSPEND_CONTEXT_REGS + PT_GP)(a0)
40fcb89863SSia Jee Heng 		REG_L	tp, (SUSPEND_CONTEXT_REGS + PT_TP)(a0)
41fcb89863SSia Jee Heng 		REG_L	s0, (SUSPEND_CONTEXT_REGS + PT_S0)(a0)
42fcb89863SSia Jee Heng 		REG_L	s1, (SUSPEND_CONTEXT_REGS + PT_S1)(a0)
43fcb89863SSia Jee Heng 		REG_L	a1, (SUSPEND_CONTEXT_REGS + PT_A1)(a0)
44fcb89863SSia Jee Heng 		REG_L	a2, (SUSPEND_CONTEXT_REGS + PT_A2)(a0)
45fcb89863SSia Jee Heng 		REG_L	a3, (SUSPEND_CONTEXT_REGS + PT_A3)(a0)
46fcb89863SSia Jee Heng 		REG_L	a4, (SUSPEND_CONTEXT_REGS + PT_A4)(a0)
47fcb89863SSia Jee Heng 		REG_L	a5, (SUSPEND_CONTEXT_REGS + PT_A5)(a0)
48fcb89863SSia Jee Heng 		REG_L	a6, (SUSPEND_CONTEXT_REGS + PT_A6)(a0)
49fcb89863SSia Jee Heng 		REG_L	a7, (SUSPEND_CONTEXT_REGS + PT_A7)(a0)
50fcb89863SSia Jee Heng 		REG_L	s2, (SUSPEND_CONTEXT_REGS + PT_S2)(a0)
51fcb89863SSia Jee Heng 		REG_L	s3, (SUSPEND_CONTEXT_REGS + PT_S3)(a0)
52fcb89863SSia Jee Heng 		REG_L	s4, (SUSPEND_CONTEXT_REGS + PT_S4)(a0)
53fcb89863SSia Jee Heng 		REG_L	s5, (SUSPEND_CONTEXT_REGS + PT_S5)(a0)
54fcb89863SSia Jee Heng 		REG_L	s6, (SUSPEND_CONTEXT_REGS + PT_S6)(a0)
55fcb89863SSia Jee Heng 		REG_L	s7, (SUSPEND_CONTEXT_REGS + PT_S7)(a0)
56fcb89863SSia Jee Heng 		REG_L	s8, (SUSPEND_CONTEXT_REGS + PT_S8)(a0)
57fcb89863SSia Jee Heng 		REG_L	s9, (SUSPEND_CONTEXT_REGS + PT_S9)(a0)
58fcb89863SSia Jee Heng 		REG_L	s10, (SUSPEND_CONTEXT_REGS + PT_S10)(a0)
59fcb89863SSia Jee Heng 		REG_L	s11, (SUSPEND_CONTEXT_REGS + PT_S11)(a0)
60fcb89863SSia Jee Heng 	.endm
61fcb89863SSia Jee Heng 
62*c0317210SSia Jee Heng /*
63*c0317210SSia Jee Heng  * copy_page - copy 1 page (4KB) of data from source to destination
64*c0317210SSia Jee Heng  * @a0 - destination
65*c0317210SSia Jee Heng  * @a1 - source
66*c0317210SSia Jee Heng  */
67*c0317210SSia Jee Heng 	.macro	copy_page a0, a1
68*c0317210SSia Jee Heng 		lui	a2, 0x1
69*c0317210SSia Jee Heng 		add	a2, a2, a0
70*c0317210SSia Jee Heng 1 :
71*c0317210SSia Jee Heng 		REG_L	t0, 0(a1)
72*c0317210SSia Jee Heng 		REG_L	t1, SZREG(a1)
73*c0317210SSia Jee Heng 
74*c0317210SSia Jee Heng 		REG_S	t0, 0(a0)
75*c0317210SSia Jee Heng 		REG_S	t1, SZREG(a0)
76*c0317210SSia Jee Heng 
77*c0317210SSia Jee Heng 		addi	a0, a0, 2 * SZREG
78*c0317210SSia Jee Heng 		addi	a1, a1, 2 * SZREG
79*c0317210SSia Jee Heng 		bne	a2, a0, 1b
80*c0317210SSia Jee Heng 	.endm
81*c0317210SSia Jee Heng 
82fcb89863SSia Jee Heng #endif	/* __ASM_ASSEMBLER_H */
83