arch/loongarch/lib/copy_user.S

Source file repositories/reference/linux-study-clean/arch/loongarch/lib/copy_user.S

File Facts

System
Linux kernel
Corpus path
arch/loongarch/lib/copy_user.S
Extension
.S
Size
5565 bytes
Lines
290
Domain
Architecture Layer
Bucket
arch/loongarch
Inferred role
Architecture Layer: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

#include <linux/export.h>
#include <asm/alternative-asm.h>
#include <asm/asm.h>
#include <asm/asmmacro.h>
#include <asm/asm-extable.h>
#include <asm/cpu.h>
#include <asm/regdef.h>
#include <asm/unwind_hints.h>

SYM_FUNC_START(__copy_user)
#ifdef CONFIG_32BIT
	b		__copy_user_generic
#else
	/*
	 * Some CPUs support hardware unaligned access
	 */
	ALTERNATIVE	"b __copy_user_generic",	\
			"b __copy_user_fast", CPU_FEATURE_UAL
#endif
SYM_FUNC_END(__copy_user)

EXPORT_SYMBOL(__copy_user)

/*
 * unsigned long __copy_user_generic(void *to, const void *from, size_t n)
 *
 * a0: to
 * a1: from
 * a2: n
 */
SYM_FUNC_START(__copy_user_generic)
	beqz		a2, 3f

1:	ld.b		t0, a1, 0
2:	st.b		t0, a0, 0
	PTR_ADDI	a0, a0, 1
	PTR_ADDI	a1, a1, 1
	PTR_ADDI	a2, a2, -1
	bgtz		a2, 1b

3:	move		a0, a2
	jr		ra

	_asm_extable	1b, 3b
	_asm_extable	2b, 3b
SYM_FUNC_END(__copy_user_generic)

#ifdef CONFIG_64BIT
/*
 * unsigned long __copy_user_fast(void *to, const void *from, unsigned long n)
 *
 * a0: to
 * a1: from
 * a2: n
 */
SYM_FUNC_START(__copy_user_fast)
	sltui	t0, a2, 9
	bnez	t0, .Lsmall

0:	ld.d	t0, a1, 0
1:	st.d	t0, a0, 0
	add.d	a3, a1, a2
	add.d	a2, a0, a2

	/* align up destination address */
	andi	t1, a0, 7
	sub.d	t0, zero, t1
	addi.d	t0, t0, 8
	add.d	a1, a1, t0
	add.d	a0, a0, t0

Annotation

Implementation Notes