162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2019 Western Digital Corporation or its affiliates.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Authors:
662306a36Sopenharmony_ci *     Anup Patel <anup.patel@wdc.com>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/linkage.h>
1062306a36Sopenharmony_ci#include <asm/asm.h>
1162306a36Sopenharmony_ci#include <asm/asm-offsets.h>
1262306a36Sopenharmony_ci#include <asm/csr.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci	.text
1562306a36Sopenharmony_ci	.altmacro
1662306a36Sopenharmony_ci	.option norelax
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciENTRY(__kvm_riscv_switch_to)
1962306a36Sopenharmony_ci	/* Save Host GPRs (except A0 and T0-T6) */
2062306a36Sopenharmony_ci	REG_S	ra, (KVM_ARCH_HOST_RA)(a0)
2162306a36Sopenharmony_ci	REG_S	sp, (KVM_ARCH_HOST_SP)(a0)
2262306a36Sopenharmony_ci	REG_S	gp, (KVM_ARCH_HOST_GP)(a0)
2362306a36Sopenharmony_ci	REG_S	tp, (KVM_ARCH_HOST_TP)(a0)
2462306a36Sopenharmony_ci	REG_S	s0, (KVM_ARCH_HOST_S0)(a0)
2562306a36Sopenharmony_ci	REG_S	s1, (KVM_ARCH_HOST_S1)(a0)
2662306a36Sopenharmony_ci	REG_S	a1, (KVM_ARCH_HOST_A1)(a0)
2762306a36Sopenharmony_ci	REG_S	a2, (KVM_ARCH_HOST_A2)(a0)
2862306a36Sopenharmony_ci	REG_S	a3, (KVM_ARCH_HOST_A3)(a0)
2962306a36Sopenharmony_ci	REG_S	a4, (KVM_ARCH_HOST_A4)(a0)
3062306a36Sopenharmony_ci	REG_S	a5, (KVM_ARCH_HOST_A5)(a0)
3162306a36Sopenharmony_ci	REG_S	a6, (KVM_ARCH_HOST_A6)(a0)
3262306a36Sopenharmony_ci	REG_S	a7, (KVM_ARCH_HOST_A7)(a0)
3362306a36Sopenharmony_ci	REG_S	s2, (KVM_ARCH_HOST_S2)(a0)
3462306a36Sopenharmony_ci	REG_S	s3, (KVM_ARCH_HOST_S3)(a0)
3562306a36Sopenharmony_ci	REG_S	s4, (KVM_ARCH_HOST_S4)(a0)
3662306a36Sopenharmony_ci	REG_S	s5, (KVM_ARCH_HOST_S5)(a0)
3762306a36Sopenharmony_ci	REG_S	s6, (KVM_ARCH_HOST_S6)(a0)
3862306a36Sopenharmony_ci	REG_S	s7, (KVM_ARCH_HOST_S7)(a0)
3962306a36Sopenharmony_ci	REG_S	s8, (KVM_ARCH_HOST_S8)(a0)
4062306a36Sopenharmony_ci	REG_S	s9, (KVM_ARCH_HOST_S9)(a0)
4162306a36Sopenharmony_ci	REG_S	s10, (KVM_ARCH_HOST_S10)(a0)
4262306a36Sopenharmony_ci	REG_S	s11, (KVM_ARCH_HOST_S11)(a0)
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	/* Load Guest CSR values */
4562306a36Sopenharmony_ci	REG_L	t0, (KVM_ARCH_GUEST_SSTATUS)(a0)
4662306a36Sopenharmony_ci	REG_L	t1, (KVM_ARCH_GUEST_HSTATUS)(a0)
4762306a36Sopenharmony_ci	REG_L	t2, (KVM_ARCH_GUEST_SCOUNTEREN)(a0)
4862306a36Sopenharmony_ci	la	t4, __kvm_switch_return
4962306a36Sopenharmony_ci	REG_L	t5, (KVM_ARCH_GUEST_SEPC)(a0)
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	/* Save Host and Restore Guest SSTATUS */
5262306a36Sopenharmony_ci	csrrw	t0, CSR_SSTATUS, t0
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci	/* Save Host and Restore Guest HSTATUS */
5562306a36Sopenharmony_ci	csrrw	t1, CSR_HSTATUS, t1
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci	/* Save Host and Restore Guest SCOUNTEREN */
5862306a36Sopenharmony_ci	csrrw	t2, CSR_SCOUNTEREN, t2
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	/* Save Host STVEC and change it to return path */
6162306a36Sopenharmony_ci	csrrw	t4, CSR_STVEC, t4
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	/* Save Host SSCRATCH and change it to struct kvm_vcpu_arch pointer */
6462306a36Sopenharmony_ci	csrrw	t3, CSR_SSCRATCH, a0
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci	/* Restore Guest SEPC */
6762306a36Sopenharmony_ci	csrw	CSR_SEPC, t5
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci	/* Store Host CSR values */
7062306a36Sopenharmony_ci	REG_S	t0, (KVM_ARCH_HOST_SSTATUS)(a0)
7162306a36Sopenharmony_ci	REG_S	t1, (KVM_ARCH_HOST_HSTATUS)(a0)
7262306a36Sopenharmony_ci	REG_S	t2, (KVM_ARCH_HOST_SCOUNTEREN)(a0)
7362306a36Sopenharmony_ci	REG_S	t3, (KVM_ARCH_HOST_SSCRATCH)(a0)
7462306a36Sopenharmony_ci	REG_S	t4, (KVM_ARCH_HOST_STVEC)(a0)
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	/* Restore Guest GPRs (except A0) */
7762306a36Sopenharmony_ci	REG_L	ra, (KVM_ARCH_GUEST_RA)(a0)
7862306a36Sopenharmony_ci	REG_L	sp, (KVM_ARCH_GUEST_SP)(a0)
7962306a36Sopenharmony_ci	REG_L	gp, (KVM_ARCH_GUEST_GP)(a0)
8062306a36Sopenharmony_ci	REG_L	tp, (KVM_ARCH_GUEST_TP)(a0)
8162306a36Sopenharmony_ci	REG_L	t0, (KVM_ARCH_GUEST_T0)(a0)
8262306a36Sopenharmony_ci	REG_L	t1, (KVM_ARCH_GUEST_T1)(a0)
8362306a36Sopenharmony_ci	REG_L	t2, (KVM_ARCH_GUEST_T2)(a0)
8462306a36Sopenharmony_ci	REG_L	s0, (KVM_ARCH_GUEST_S0)(a0)
8562306a36Sopenharmony_ci	REG_L	s1, (KVM_ARCH_GUEST_S1)(a0)
8662306a36Sopenharmony_ci	REG_L	a1, (KVM_ARCH_GUEST_A1)(a0)
8762306a36Sopenharmony_ci	REG_L	a2, (KVM_ARCH_GUEST_A2)(a0)
8862306a36Sopenharmony_ci	REG_L	a3, (KVM_ARCH_GUEST_A3)(a0)
8962306a36Sopenharmony_ci	REG_L	a4, (KVM_ARCH_GUEST_A4)(a0)
9062306a36Sopenharmony_ci	REG_L	a5, (KVM_ARCH_GUEST_A5)(a0)
9162306a36Sopenharmony_ci	REG_L	a6, (KVM_ARCH_GUEST_A6)(a0)
9262306a36Sopenharmony_ci	REG_L	a7, (KVM_ARCH_GUEST_A7)(a0)
9362306a36Sopenharmony_ci	REG_L	s2, (KVM_ARCH_GUEST_S2)(a0)
9462306a36Sopenharmony_ci	REG_L	s3, (KVM_ARCH_GUEST_S3)(a0)
9562306a36Sopenharmony_ci	REG_L	s4, (KVM_ARCH_GUEST_S4)(a0)
9662306a36Sopenharmony_ci	REG_L	s5, (KVM_ARCH_GUEST_S5)(a0)
9762306a36Sopenharmony_ci	REG_L	s6, (KVM_ARCH_GUEST_S6)(a0)
9862306a36Sopenharmony_ci	REG_L	s7, (KVM_ARCH_GUEST_S7)(a0)
9962306a36Sopenharmony_ci	REG_L	s8, (KVM_ARCH_GUEST_S8)(a0)
10062306a36Sopenharmony_ci	REG_L	s9, (KVM_ARCH_GUEST_S9)(a0)
10162306a36Sopenharmony_ci	REG_L	s10, (KVM_ARCH_GUEST_S10)(a0)
10262306a36Sopenharmony_ci	REG_L	s11, (KVM_ARCH_GUEST_S11)(a0)
10362306a36Sopenharmony_ci	REG_L	t3, (KVM_ARCH_GUEST_T3)(a0)
10462306a36Sopenharmony_ci	REG_L	t4, (KVM_ARCH_GUEST_T4)(a0)
10562306a36Sopenharmony_ci	REG_L	t5, (KVM_ARCH_GUEST_T5)(a0)
10662306a36Sopenharmony_ci	REG_L	t6, (KVM_ARCH_GUEST_T6)(a0)
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	/* Restore Guest A0 */
10962306a36Sopenharmony_ci	REG_L	a0, (KVM_ARCH_GUEST_A0)(a0)
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci	/* Resume Guest */
11262306a36Sopenharmony_ci	sret
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci	/* Back to Host */
11562306a36Sopenharmony_ci	.align 2
11662306a36Sopenharmony_ci__kvm_switch_return:
11762306a36Sopenharmony_ci	/* Swap Guest A0 with SSCRATCH */
11862306a36Sopenharmony_ci	csrrw	a0, CSR_SSCRATCH, a0
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	/* Save Guest GPRs (except A0) */
12162306a36Sopenharmony_ci	REG_S	ra, (KVM_ARCH_GUEST_RA)(a0)
12262306a36Sopenharmony_ci	REG_S	sp, (KVM_ARCH_GUEST_SP)(a0)
12362306a36Sopenharmony_ci	REG_S	gp, (KVM_ARCH_GUEST_GP)(a0)
12462306a36Sopenharmony_ci	REG_S	tp, (KVM_ARCH_GUEST_TP)(a0)
12562306a36Sopenharmony_ci	REG_S	t0, (KVM_ARCH_GUEST_T0)(a0)
12662306a36Sopenharmony_ci	REG_S	t1, (KVM_ARCH_GUEST_T1)(a0)
12762306a36Sopenharmony_ci	REG_S	t2, (KVM_ARCH_GUEST_T2)(a0)
12862306a36Sopenharmony_ci	REG_S	s0, (KVM_ARCH_GUEST_S0)(a0)
12962306a36Sopenharmony_ci	REG_S	s1, (KVM_ARCH_GUEST_S1)(a0)
13062306a36Sopenharmony_ci	REG_S	a1, (KVM_ARCH_GUEST_A1)(a0)
13162306a36Sopenharmony_ci	REG_S	a2, (KVM_ARCH_GUEST_A2)(a0)
13262306a36Sopenharmony_ci	REG_S	a3, (KVM_ARCH_GUEST_A3)(a0)
13362306a36Sopenharmony_ci	REG_S	a4, (KVM_ARCH_GUEST_A4)(a0)
13462306a36Sopenharmony_ci	REG_S	a5, (KVM_ARCH_GUEST_A5)(a0)
13562306a36Sopenharmony_ci	REG_S	a6, (KVM_ARCH_GUEST_A6)(a0)
13662306a36Sopenharmony_ci	REG_S	a7, (KVM_ARCH_GUEST_A7)(a0)
13762306a36Sopenharmony_ci	REG_S	s2, (KVM_ARCH_GUEST_S2)(a0)
13862306a36Sopenharmony_ci	REG_S	s3, (KVM_ARCH_GUEST_S3)(a0)
13962306a36Sopenharmony_ci	REG_S	s4, (KVM_ARCH_GUEST_S4)(a0)
14062306a36Sopenharmony_ci	REG_S	s5, (KVM_ARCH_GUEST_S5)(a0)
14162306a36Sopenharmony_ci	REG_S	s6, (KVM_ARCH_GUEST_S6)(a0)
14262306a36Sopenharmony_ci	REG_S	s7, (KVM_ARCH_GUEST_S7)(a0)
14362306a36Sopenharmony_ci	REG_S	s8, (KVM_ARCH_GUEST_S8)(a0)
14462306a36Sopenharmony_ci	REG_S	s9, (KVM_ARCH_GUEST_S9)(a0)
14562306a36Sopenharmony_ci	REG_S	s10, (KVM_ARCH_GUEST_S10)(a0)
14662306a36Sopenharmony_ci	REG_S	s11, (KVM_ARCH_GUEST_S11)(a0)
14762306a36Sopenharmony_ci	REG_S	t3, (KVM_ARCH_GUEST_T3)(a0)
14862306a36Sopenharmony_ci	REG_S	t4, (KVM_ARCH_GUEST_T4)(a0)
14962306a36Sopenharmony_ci	REG_S	t5, (KVM_ARCH_GUEST_T5)(a0)
15062306a36Sopenharmony_ci	REG_S	t6, (KVM_ARCH_GUEST_T6)(a0)
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci	/* Load Host CSR values */
15362306a36Sopenharmony_ci	REG_L	t1, (KVM_ARCH_HOST_STVEC)(a0)
15462306a36Sopenharmony_ci	REG_L	t2, (KVM_ARCH_HOST_SSCRATCH)(a0)
15562306a36Sopenharmony_ci	REG_L	t3, (KVM_ARCH_HOST_SCOUNTEREN)(a0)
15662306a36Sopenharmony_ci	REG_L	t4, (KVM_ARCH_HOST_HSTATUS)(a0)
15762306a36Sopenharmony_ci	REG_L	t5, (KVM_ARCH_HOST_SSTATUS)(a0)
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	/* Save Guest SEPC */
16062306a36Sopenharmony_ci	csrr	t0, CSR_SEPC
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci	/* Save Guest A0 and Restore Host SSCRATCH */
16362306a36Sopenharmony_ci	csrrw	t2, CSR_SSCRATCH, t2
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci	/* Restore Host STVEC */
16662306a36Sopenharmony_ci	csrw	CSR_STVEC, t1
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci	/* Save Guest and Restore Host SCOUNTEREN */
16962306a36Sopenharmony_ci	csrrw	t3, CSR_SCOUNTEREN, t3
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ci	/* Save Guest and Restore Host HSTATUS */
17262306a36Sopenharmony_ci	csrrw	t4, CSR_HSTATUS, t4
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci	/* Save Guest and Restore Host SSTATUS */
17562306a36Sopenharmony_ci	csrrw	t5, CSR_SSTATUS, t5
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	/* Store Guest CSR values */
17862306a36Sopenharmony_ci	REG_S	t0, (KVM_ARCH_GUEST_SEPC)(a0)
17962306a36Sopenharmony_ci	REG_S	t2, (KVM_ARCH_GUEST_A0)(a0)
18062306a36Sopenharmony_ci	REG_S	t3, (KVM_ARCH_GUEST_SCOUNTEREN)(a0)
18162306a36Sopenharmony_ci	REG_S	t4, (KVM_ARCH_GUEST_HSTATUS)(a0)
18262306a36Sopenharmony_ci	REG_S	t5, (KVM_ARCH_GUEST_SSTATUS)(a0)
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci	/* Restore Host GPRs (except A0 and T0-T6) */
18562306a36Sopenharmony_ci	REG_L	ra, (KVM_ARCH_HOST_RA)(a0)
18662306a36Sopenharmony_ci	REG_L	sp, (KVM_ARCH_HOST_SP)(a0)
18762306a36Sopenharmony_ci	REG_L	gp, (KVM_ARCH_HOST_GP)(a0)
18862306a36Sopenharmony_ci	REG_L	tp, (KVM_ARCH_HOST_TP)(a0)
18962306a36Sopenharmony_ci	REG_L	s0, (KVM_ARCH_HOST_S0)(a0)
19062306a36Sopenharmony_ci	REG_L	s1, (KVM_ARCH_HOST_S1)(a0)
19162306a36Sopenharmony_ci	REG_L	a1, (KVM_ARCH_HOST_A1)(a0)
19262306a36Sopenharmony_ci	REG_L	a2, (KVM_ARCH_HOST_A2)(a0)
19362306a36Sopenharmony_ci	REG_L	a3, (KVM_ARCH_HOST_A3)(a0)
19462306a36Sopenharmony_ci	REG_L	a4, (KVM_ARCH_HOST_A4)(a0)
19562306a36Sopenharmony_ci	REG_L	a5, (KVM_ARCH_HOST_A5)(a0)
19662306a36Sopenharmony_ci	REG_L	a6, (KVM_ARCH_HOST_A6)(a0)
19762306a36Sopenharmony_ci	REG_L	a7, (KVM_ARCH_HOST_A7)(a0)
19862306a36Sopenharmony_ci	REG_L	s2, (KVM_ARCH_HOST_S2)(a0)
19962306a36Sopenharmony_ci	REG_L	s3, (KVM_ARCH_HOST_S3)(a0)
20062306a36Sopenharmony_ci	REG_L	s4, (KVM_ARCH_HOST_S4)(a0)
20162306a36Sopenharmony_ci	REG_L	s5, (KVM_ARCH_HOST_S5)(a0)
20262306a36Sopenharmony_ci	REG_L	s6, (KVM_ARCH_HOST_S6)(a0)
20362306a36Sopenharmony_ci	REG_L	s7, (KVM_ARCH_HOST_S7)(a0)
20462306a36Sopenharmony_ci	REG_L	s8, (KVM_ARCH_HOST_S8)(a0)
20562306a36Sopenharmony_ci	REG_L	s9, (KVM_ARCH_HOST_S9)(a0)
20662306a36Sopenharmony_ci	REG_L	s10, (KVM_ARCH_HOST_S10)(a0)
20762306a36Sopenharmony_ci	REG_L	s11, (KVM_ARCH_HOST_S11)(a0)
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci	/* Return to C code */
21062306a36Sopenharmony_ci	ret
21162306a36Sopenharmony_ciENDPROC(__kvm_riscv_switch_to)
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ciENTRY(__kvm_riscv_unpriv_trap)
21462306a36Sopenharmony_ci	/*
21562306a36Sopenharmony_ci	 * We assume that faulting unpriv load/store instruction is
21662306a36Sopenharmony_ci	 * 4-byte long and blindly increment SEPC by 4.
21762306a36Sopenharmony_ci	 *
21862306a36Sopenharmony_ci	 * The trap details will be saved at address pointed by 'A0'
21962306a36Sopenharmony_ci	 * register and we use 'A1' register as temporary.
22062306a36Sopenharmony_ci	 */
22162306a36Sopenharmony_ci	csrr	a1, CSR_SEPC
22262306a36Sopenharmony_ci	REG_S	a1, (KVM_ARCH_TRAP_SEPC)(a0)
22362306a36Sopenharmony_ci	addi	a1, a1, 4
22462306a36Sopenharmony_ci	csrw	CSR_SEPC, a1
22562306a36Sopenharmony_ci	csrr	a1, CSR_SCAUSE
22662306a36Sopenharmony_ci	REG_S	a1, (KVM_ARCH_TRAP_SCAUSE)(a0)
22762306a36Sopenharmony_ci	csrr	a1, CSR_STVAL
22862306a36Sopenharmony_ci	REG_S	a1, (KVM_ARCH_TRAP_STVAL)(a0)
22962306a36Sopenharmony_ci	csrr	a1, CSR_HTVAL
23062306a36Sopenharmony_ci	REG_S	a1, (KVM_ARCH_TRAP_HTVAL)(a0)
23162306a36Sopenharmony_ci	csrr	a1, CSR_HTINST
23262306a36Sopenharmony_ci	REG_S	a1, (KVM_ARCH_TRAP_HTINST)(a0)
23362306a36Sopenharmony_ci	sret
23462306a36Sopenharmony_ciENDPROC(__kvm_riscv_unpriv_trap)
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci#ifdef	CONFIG_FPU
23762306a36Sopenharmony_ci	.align 3
23862306a36Sopenharmony_ci	.global __kvm_riscv_fp_f_save
23962306a36Sopenharmony_ci__kvm_riscv_fp_f_save:
24062306a36Sopenharmony_ci	csrr t2, CSR_SSTATUS
24162306a36Sopenharmony_ci	li t1, SR_FS
24262306a36Sopenharmony_ci	csrs CSR_SSTATUS, t1
24362306a36Sopenharmony_ci	frcsr t0
24462306a36Sopenharmony_ci	fsw f0,  KVM_ARCH_FP_F_F0(a0)
24562306a36Sopenharmony_ci	fsw f1,  KVM_ARCH_FP_F_F1(a0)
24662306a36Sopenharmony_ci	fsw f2,  KVM_ARCH_FP_F_F2(a0)
24762306a36Sopenharmony_ci	fsw f3,  KVM_ARCH_FP_F_F3(a0)
24862306a36Sopenharmony_ci	fsw f4,  KVM_ARCH_FP_F_F4(a0)
24962306a36Sopenharmony_ci	fsw f5,  KVM_ARCH_FP_F_F5(a0)
25062306a36Sopenharmony_ci	fsw f6,  KVM_ARCH_FP_F_F6(a0)
25162306a36Sopenharmony_ci	fsw f7,  KVM_ARCH_FP_F_F7(a0)
25262306a36Sopenharmony_ci	fsw f8,  KVM_ARCH_FP_F_F8(a0)
25362306a36Sopenharmony_ci	fsw f9,  KVM_ARCH_FP_F_F9(a0)
25462306a36Sopenharmony_ci	fsw f10, KVM_ARCH_FP_F_F10(a0)
25562306a36Sopenharmony_ci	fsw f11, KVM_ARCH_FP_F_F11(a0)
25662306a36Sopenharmony_ci	fsw f12, KVM_ARCH_FP_F_F12(a0)
25762306a36Sopenharmony_ci	fsw f13, KVM_ARCH_FP_F_F13(a0)
25862306a36Sopenharmony_ci	fsw f14, KVM_ARCH_FP_F_F14(a0)
25962306a36Sopenharmony_ci	fsw f15, KVM_ARCH_FP_F_F15(a0)
26062306a36Sopenharmony_ci	fsw f16, KVM_ARCH_FP_F_F16(a0)
26162306a36Sopenharmony_ci	fsw f17, KVM_ARCH_FP_F_F17(a0)
26262306a36Sopenharmony_ci	fsw f18, KVM_ARCH_FP_F_F18(a0)
26362306a36Sopenharmony_ci	fsw f19, KVM_ARCH_FP_F_F19(a0)
26462306a36Sopenharmony_ci	fsw f20, KVM_ARCH_FP_F_F20(a0)
26562306a36Sopenharmony_ci	fsw f21, KVM_ARCH_FP_F_F21(a0)
26662306a36Sopenharmony_ci	fsw f22, KVM_ARCH_FP_F_F22(a0)
26762306a36Sopenharmony_ci	fsw f23, KVM_ARCH_FP_F_F23(a0)
26862306a36Sopenharmony_ci	fsw f24, KVM_ARCH_FP_F_F24(a0)
26962306a36Sopenharmony_ci	fsw f25, KVM_ARCH_FP_F_F25(a0)
27062306a36Sopenharmony_ci	fsw f26, KVM_ARCH_FP_F_F26(a0)
27162306a36Sopenharmony_ci	fsw f27, KVM_ARCH_FP_F_F27(a0)
27262306a36Sopenharmony_ci	fsw f28, KVM_ARCH_FP_F_F28(a0)
27362306a36Sopenharmony_ci	fsw f29, KVM_ARCH_FP_F_F29(a0)
27462306a36Sopenharmony_ci	fsw f30, KVM_ARCH_FP_F_F30(a0)
27562306a36Sopenharmony_ci	fsw f31, KVM_ARCH_FP_F_F31(a0)
27662306a36Sopenharmony_ci	sw t0, KVM_ARCH_FP_F_FCSR(a0)
27762306a36Sopenharmony_ci	csrw CSR_SSTATUS, t2
27862306a36Sopenharmony_ci	ret
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci	.align 3
28162306a36Sopenharmony_ci	.global __kvm_riscv_fp_d_save
28262306a36Sopenharmony_ci__kvm_riscv_fp_d_save:
28362306a36Sopenharmony_ci	csrr t2, CSR_SSTATUS
28462306a36Sopenharmony_ci	li t1, SR_FS
28562306a36Sopenharmony_ci	csrs CSR_SSTATUS, t1
28662306a36Sopenharmony_ci	frcsr t0
28762306a36Sopenharmony_ci	fsd f0,  KVM_ARCH_FP_D_F0(a0)
28862306a36Sopenharmony_ci	fsd f1,  KVM_ARCH_FP_D_F1(a0)
28962306a36Sopenharmony_ci	fsd f2,  KVM_ARCH_FP_D_F2(a0)
29062306a36Sopenharmony_ci	fsd f3,  KVM_ARCH_FP_D_F3(a0)
29162306a36Sopenharmony_ci	fsd f4,  KVM_ARCH_FP_D_F4(a0)
29262306a36Sopenharmony_ci	fsd f5,  KVM_ARCH_FP_D_F5(a0)
29362306a36Sopenharmony_ci	fsd f6,  KVM_ARCH_FP_D_F6(a0)
29462306a36Sopenharmony_ci	fsd f7,  KVM_ARCH_FP_D_F7(a0)
29562306a36Sopenharmony_ci	fsd f8,  KVM_ARCH_FP_D_F8(a0)
29662306a36Sopenharmony_ci	fsd f9,  KVM_ARCH_FP_D_F9(a0)
29762306a36Sopenharmony_ci	fsd f10, KVM_ARCH_FP_D_F10(a0)
29862306a36Sopenharmony_ci	fsd f11, KVM_ARCH_FP_D_F11(a0)
29962306a36Sopenharmony_ci	fsd f12, KVM_ARCH_FP_D_F12(a0)
30062306a36Sopenharmony_ci	fsd f13, KVM_ARCH_FP_D_F13(a0)
30162306a36Sopenharmony_ci	fsd f14, KVM_ARCH_FP_D_F14(a0)
30262306a36Sopenharmony_ci	fsd f15, KVM_ARCH_FP_D_F15(a0)
30362306a36Sopenharmony_ci	fsd f16, KVM_ARCH_FP_D_F16(a0)
30462306a36Sopenharmony_ci	fsd f17, KVM_ARCH_FP_D_F17(a0)
30562306a36Sopenharmony_ci	fsd f18, KVM_ARCH_FP_D_F18(a0)
30662306a36Sopenharmony_ci	fsd f19, KVM_ARCH_FP_D_F19(a0)
30762306a36Sopenharmony_ci	fsd f20, KVM_ARCH_FP_D_F20(a0)
30862306a36Sopenharmony_ci	fsd f21, KVM_ARCH_FP_D_F21(a0)
30962306a36Sopenharmony_ci	fsd f22, KVM_ARCH_FP_D_F22(a0)
31062306a36Sopenharmony_ci	fsd f23, KVM_ARCH_FP_D_F23(a0)
31162306a36Sopenharmony_ci	fsd f24, KVM_ARCH_FP_D_F24(a0)
31262306a36Sopenharmony_ci	fsd f25, KVM_ARCH_FP_D_F25(a0)
31362306a36Sopenharmony_ci	fsd f26, KVM_ARCH_FP_D_F26(a0)
31462306a36Sopenharmony_ci	fsd f27, KVM_ARCH_FP_D_F27(a0)
31562306a36Sopenharmony_ci	fsd f28, KVM_ARCH_FP_D_F28(a0)
31662306a36Sopenharmony_ci	fsd f29, KVM_ARCH_FP_D_F29(a0)
31762306a36Sopenharmony_ci	fsd f30, KVM_ARCH_FP_D_F30(a0)
31862306a36Sopenharmony_ci	fsd f31, KVM_ARCH_FP_D_F31(a0)
31962306a36Sopenharmony_ci	sw t0, KVM_ARCH_FP_D_FCSR(a0)
32062306a36Sopenharmony_ci	csrw CSR_SSTATUS, t2
32162306a36Sopenharmony_ci	ret
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_ci	.align 3
32462306a36Sopenharmony_ci	.global __kvm_riscv_fp_f_restore
32562306a36Sopenharmony_ci__kvm_riscv_fp_f_restore:
32662306a36Sopenharmony_ci	csrr t2, CSR_SSTATUS
32762306a36Sopenharmony_ci	li t1, SR_FS
32862306a36Sopenharmony_ci	lw t0, KVM_ARCH_FP_F_FCSR(a0)
32962306a36Sopenharmony_ci	csrs CSR_SSTATUS, t1
33062306a36Sopenharmony_ci	flw f0,  KVM_ARCH_FP_F_F0(a0)
33162306a36Sopenharmony_ci	flw f1,  KVM_ARCH_FP_F_F1(a0)
33262306a36Sopenharmony_ci	flw f2,  KVM_ARCH_FP_F_F2(a0)
33362306a36Sopenharmony_ci	flw f3,  KVM_ARCH_FP_F_F3(a0)
33462306a36Sopenharmony_ci	flw f4,  KVM_ARCH_FP_F_F4(a0)
33562306a36Sopenharmony_ci	flw f5,  KVM_ARCH_FP_F_F5(a0)
33662306a36Sopenharmony_ci	flw f6,  KVM_ARCH_FP_F_F6(a0)
33762306a36Sopenharmony_ci	flw f7,  KVM_ARCH_FP_F_F7(a0)
33862306a36Sopenharmony_ci	flw f8,  KVM_ARCH_FP_F_F8(a0)
33962306a36Sopenharmony_ci	flw f9,  KVM_ARCH_FP_F_F9(a0)
34062306a36Sopenharmony_ci	flw f10, KVM_ARCH_FP_F_F10(a0)
34162306a36Sopenharmony_ci	flw f11, KVM_ARCH_FP_F_F11(a0)
34262306a36Sopenharmony_ci	flw f12, KVM_ARCH_FP_F_F12(a0)
34362306a36Sopenharmony_ci	flw f13, KVM_ARCH_FP_F_F13(a0)
34462306a36Sopenharmony_ci	flw f14, KVM_ARCH_FP_F_F14(a0)
34562306a36Sopenharmony_ci	flw f15, KVM_ARCH_FP_F_F15(a0)
34662306a36Sopenharmony_ci	flw f16, KVM_ARCH_FP_F_F16(a0)
34762306a36Sopenharmony_ci	flw f17, KVM_ARCH_FP_F_F17(a0)
34862306a36Sopenharmony_ci	flw f18, KVM_ARCH_FP_F_F18(a0)
34962306a36Sopenharmony_ci	flw f19, KVM_ARCH_FP_F_F19(a0)
35062306a36Sopenharmony_ci	flw f20, KVM_ARCH_FP_F_F20(a0)
35162306a36Sopenharmony_ci	flw f21, KVM_ARCH_FP_F_F21(a0)
35262306a36Sopenharmony_ci	flw f22, KVM_ARCH_FP_F_F22(a0)
35362306a36Sopenharmony_ci	flw f23, KVM_ARCH_FP_F_F23(a0)
35462306a36Sopenharmony_ci	flw f24, KVM_ARCH_FP_F_F24(a0)
35562306a36Sopenharmony_ci	flw f25, KVM_ARCH_FP_F_F25(a0)
35662306a36Sopenharmony_ci	flw f26, KVM_ARCH_FP_F_F26(a0)
35762306a36Sopenharmony_ci	flw f27, KVM_ARCH_FP_F_F27(a0)
35862306a36Sopenharmony_ci	flw f28, KVM_ARCH_FP_F_F28(a0)
35962306a36Sopenharmony_ci	flw f29, KVM_ARCH_FP_F_F29(a0)
36062306a36Sopenharmony_ci	flw f30, KVM_ARCH_FP_F_F30(a0)
36162306a36Sopenharmony_ci	flw f31, KVM_ARCH_FP_F_F31(a0)
36262306a36Sopenharmony_ci	fscsr t0
36362306a36Sopenharmony_ci	csrw CSR_SSTATUS, t2
36462306a36Sopenharmony_ci	ret
36562306a36Sopenharmony_ci
36662306a36Sopenharmony_ci	.align 3
36762306a36Sopenharmony_ci	.global __kvm_riscv_fp_d_restore
36862306a36Sopenharmony_ci__kvm_riscv_fp_d_restore:
36962306a36Sopenharmony_ci	csrr t2, CSR_SSTATUS
37062306a36Sopenharmony_ci	li t1, SR_FS
37162306a36Sopenharmony_ci	lw t0, KVM_ARCH_FP_D_FCSR(a0)
37262306a36Sopenharmony_ci	csrs CSR_SSTATUS, t1
37362306a36Sopenharmony_ci	fld f0,  KVM_ARCH_FP_D_F0(a0)
37462306a36Sopenharmony_ci	fld f1,  KVM_ARCH_FP_D_F1(a0)
37562306a36Sopenharmony_ci	fld f2,  KVM_ARCH_FP_D_F2(a0)
37662306a36Sopenharmony_ci	fld f3,  KVM_ARCH_FP_D_F3(a0)
37762306a36Sopenharmony_ci	fld f4,  KVM_ARCH_FP_D_F4(a0)
37862306a36Sopenharmony_ci	fld f5,  KVM_ARCH_FP_D_F5(a0)
37962306a36Sopenharmony_ci	fld f6,  KVM_ARCH_FP_D_F6(a0)
38062306a36Sopenharmony_ci	fld f7,  KVM_ARCH_FP_D_F7(a0)
38162306a36Sopenharmony_ci	fld f8,  KVM_ARCH_FP_D_F8(a0)
38262306a36Sopenharmony_ci	fld f9,  KVM_ARCH_FP_D_F9(a0)
38362306a36Sopenharmony_ci	fld f10, KVM_ARCH_FP_D_F10(a0)
38462306a36Sopenharmony_ci	fld f11, KVM_ARCH_FP_D_F11(a0)
38562306a36Sopenharmony_ci	fld f12, KVM_ARCH_FP_D_F12(a0)
38662306a36Sopenharmony_ci	fld f13, KVM_ARCH_FP_D_F13(a0)
38762306a36Sopenharmony_ci	fld f14, KVM_ARCH_FP_D_F14(a0)
38862306a36Sopenharmony_ci	fld f15, KVM_ARCH_FP_D_F15(a0)
38962306a36Sopenharmony_ci	fld f16, KVM_ARCH_FP_D_F16(a0)
39062306a36Sopenharmony_ci	fld f17, KVM_ARCH_FP_D_F17(a0)
39162306a36Sopenharmony_ci	fld f18, KVM_ARCH_FP_D_F18(a0)
39262306a36Sopenharmony_ci	fld f19, KVM_ARCH_FP_D_F19(a0)
39362306a36Sopenharmony_ci	fld f20, KVM_ARCH_FP_D_F20(a0)
39462306a36Sopenharmony_ci	fld f21, KVM_ARCH_FP_D_F21(a0)
39562306a36Sopenharmony_ci	fld f22, KVM_ARCH_FP_D_F22(a0)
39662306a36Sopenharmony_ci	fld f23, KVM_ARCH_FP_D_F23(a0)
39762306a36Sopenharmony_ci	fld f24, KVM_ARCH_FP_D_F24(a0)
39862306a36Sopenharmony_ci	fld f25, KVM_ARCH_FP_D_F25(a0)
39962306a36Sopenharmony_ci	fld f26, KVM_ARCH_FP_D_F26(a0)
40062306a36Sopenharmony_ci	fld f27, KVM_ARCH_FP_D_F27(a0)
40162306a36Sopenharmony_ci	fld f28, KVM_ARCH_FP_D_F28(a0)
40262306a36Sopenharmony_ci	fld f29, KVM_ARCH_FP_D_F29(a0)
40362306a36Sopenharmony_ci	fld f30, KVM_ARCH_FP_D_F30(a0)
40462306a36Sopenharmony_ci	fld f31, KVM_ARCH_FP_D_F31(a0)
40562306a36Sopenharmony_ci	fscsr t0
40662306a36Sopenharmony_ci	csrw CSR_SSTATUS, t2
40762306a36Sopenharmony_ci	ret
40862306a36Sopenharmony_ci#endif
409