arch/loongarch/lib/memmove.S

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

File Facts

System
Linux kernel
Corpus path
arch/loongarch/lib/memmove.S
Extension
.S
Size
2610 bytes
Lines
148
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/cpu.h>
#include <asm/regdef.h>

.section .noinstr.text, "ax"

SYM_FUNC_START(memmove)
	blt	a0, a1, __memcpy	/* dst < src, memcpy */
	blt	a1, a0, __rmemcpy	/* src < dst, rmemcpy */
	jr	ra			/* dst == src, return */
SYM_FUNC_END(memmove)
SYM_FUNC_ALIAS(__memmove, memmove)

EXPORT_SYMBOL(memmove)
EXPORT_SYMBOL(__memmove)

_ASM_NOKPROBE(memmove)
_ASM_NOKPROBE(__memmove)

SYM_FUNC_START(__rmemcpy)
	/*
	 * Some CPUs support hardware unaligned access
	 */
	ALTERNATIVE	"b __rmemcpy_generic", \
			"b __rmemcpy_fast", CPU_FEATURE_UAL
SYM_FUNC_END(__rmemcpy)
_ASM_NOKPROBE(__rmemcpy)

/*
 * void *__rmemcpy_generic(void *dst, const void *src, size_t n)
 *
 * a0: dst
 * a1: src
 * a2: n
 */
SYM_FUNC_START(__rmemcpy_generic)
	move	a3, a0
	beqz	a2, 2f

	add.d	a0, a0, a2
	add.d	a1, a1, a2

1:	ld.b	t0, a1, -1
	st.b	t0, a0, -1
	addi.d	a0, a0, -1
	addi.d	a1, a1, -1
	addi.d	a2, a2, -1
	bgt	a2, zero, 1b

2:	move	a0, a3
	jr	ra
SYM_FUNC_END(__rmemcpy_generic)
_ASM_NOKPROBE(__rmemcpy_generic)

/*
 * void *__rmemcpy_fast(void *dst, const void *src, size_t n)
 *
 * a0: dst
 * a1: src
 * a2: n
 */
SYM_FUNC_START(__rmemcpy_fast)
	sltui	t0, a2, 9
	bnez	t0, __memcpy_small

	add.d	a3, a1, a2
	add.d	a2, a0, a2

Annotation

Implementation Notes