xref: /linux/arch/riscv/lib/uaccess_vector.S (revision e7d759f31ca295d589f7420719c311870bb3166f)
1/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <linux/linkage.h>
4#include <asm-generic/export.h>
5#include <asm/asm.h>
6#include <asm/asm-extable.h>
7#include <asm/csr.h>
8
9#define pDst a0
10#define pSrc a1
11#define iNum a2
12
13#define iVL a3
14
15#define ELEM_LMUL_SETTING m8
16#define vData v0
17
18	.macro fixup op reg addr lbl
19100:
20	\op \reg, \addr
21	_asm_extable	100b, \lbl
22	.endm
23
24SYM_FUNC_START(__asm_vector_usercopy)
25	/* Enable access to user memory */
26	li	t6, SR_SUM
27	csrs	CSR_STATUS, t6
28
29loop:
30	vsetvli iVL, iNum, e8, ELEM_LMUL_SETTING, ta, ma
31	fixup vle8.v vData, (pSrc), 10f
32	sub iNum, iNum, iVL
33	add pSrc, pSrc, iVL
34	fixup vse8.v vData, (pDst), 11f
35	add pDst, pDst, iVL
36	bnez iNum, loop
37
38	/* Exception fixup for vector load is shared with normal exit */
3910:
40	/* Disable access to user memory */
41	csrc	CSR_STATUS, t6
42	mv	a0, iNum
43	ret
44
45	/* Exception fixup code for vector store. */
4611:
47	/* Undo the subtraction after vle8.v */
48	add	iNum, iNum, iVL
49	/* Make sure the scalar fallback skip already processed bytes */
50	csrr	t2, CSR_VSTART
51	sub	iNum, iNum, t2
52	j	10b
53SYM_FUNC_END(__asm_vector_usercopy)
54