arch/loongarch/include/asm/asmmacro.h
Source file repositories/reference/linux-study-clean/arch/loongarch/include/asm/asmmacro.h
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/include/asm/asmmacro.h- Extension
.h- Size
- 24914 bytes
- Lines
- 682
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
Dependency Surface
linux/sizes.hasm/asm-offsets.hasm/regdef.hasm/fpregdef.hasm/loongarch.h
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
#ifndef _ASM_ASMMACRO_H
#define _ASM_ASMMACRO_H
#include <linux/sizes.h>
#include <asm/asm-offsets.h>
#include <asm/regdef.h>
#include <asm/fpregdef.h>
#include <asm/loongarch.h>
#ifdef CONFIG_64BIT
#define TASK_STRUCT_OFFSET 0
#else
#define TASK_STRUCT_OFFSET 2000
#endif
.macro cpu_save_nonscratch thread
LONG_SPTR s0, \thread, (THREAD_REG23 - TASK_STRUCT_OFFSET)
LONG_SPTR s1, \thread, (THREAD_REG24 - TASK_STRUCT_OFFSET)
LONG_SPTR s2, \thread, (THREAD_REG25 - TASK_STRUCT_OFFSET)
LONG_SPTR s3, \thread, (THREAD_REG26 - TASK_STRUCT_OFFSET)
LONG_SPTR s4, \thread, (THREAD_REG27 - TASK_STRUCT_OFFSET)
LONG_SPTR s5, \thread, (THREAD_REG28 - TASK_STRUCT_OFFSET)
LONG_SPTR s6, \thread, (THREAD_REG29 - TASK_STRUCT_OFFSET)
LONG_SPTR s7, \thread, (THREAD_REG30 - TASK_STRUCT_OFFSET)
LONG_SPTR s8, \thread, (THREAD_REG31 - TASK_STRUCT_OFFSET)
LONG_SPTR ra, \thread, (THREAD_REG01 - TASK_STRUCT_OFFSET)
LONG_SPTR sp, \thread, (THREAD_REG03 - TASK_STRUCT_OFFSET)
LONG_SPTR fp, \thread, (THREAD_REG22 - TASK_STRUCT_OFFSET)
.endm
.macro cpu_restore_nonscratch thread
LONG_LPTR s0, \thread, (THREAD_REG23 - TASK_STRUCT_OFFSET)
LONG_LPTR s1, \thread, (THREAD_REG24 - TASK_STRUCT_OFFSET)
LONG_LPTR s2, \thread, (THREAD_REG25 - TASK_STRUCT_OFFSET)
LONG_LPTR s3, \thread, (THREAD_REG26 - TASK_STRUCT_OFFSET)
LONG_LPTR s4, \thread, (THREAD_REG27 - TASK_STRUCT_OFFSET)
LONG_LPTR s5, \thread, (THREAD_REG28 - TASK_STRUCT_OFFSET)
LONG_LPTR s6, \thread, (THREAD_REG29 - TASK_STRUCT_OFFSET)
LONG_LPTR s7, \thread, (THREAD_REG30 - TASK_STRUCT_OFFSET)
LONG_LPTR s8, \thread, (THREAD_REG31 - TASK_STRUCT_OFFSET)
LONG_LPTR ra, \thread, (THREAD_REG01 - TASK_STRUCT_OFFSET)
LONG_LPTR sp, \thread, (THREAD_REG03 - TASK_STRUCT_OFFSET)
LONG_LPTR fp, \thread, (THREAD_REG22 - TASK_STRUCT_OFFSET)
.endm
.macro fpu_save_csr thread tmp
movfcsr2gr \tmp, fcsr0
#ifdef CONFIG_32BIT
st.w \tmp, \thread, THREAD_FCSR
#else
stptr.w \tmp, \thread, THREAD_FCSR
#endif
#ifdef CONFIG_CPU_HAS_LBT
/* TM bit is always 0 if LBT not supported */
andi \tmp, \tmp, FPU_CSR_TM
beqz \tmp, 1f
/* Save FTOP */
x86mftop \tmp
stptr.w \tmp, \thread, THREAD_FTOP
/* Turn off TM to ensure the order of FPR in memory independent of TM */
x86clrtm
1:
#endif
.endm
.macro fpu_restore_csr thread tmp0 tmp1
#ifdef CONFIG_32BIT
ld.w \tmp0, \thread, THREAD_FCSR
#else
ldptr.w \tmp0, \thread, THREAD_FCSR
#endif
movgr2fcsr fcsr0, \tmp0
#ifdef CONFIG_CPU_HAS_LBT
/* TM bit is always 0 if LBT not supported */
andi \tmp0, \tmp0, FPU_CSR_TM
beqz \tmp0, 2f
/* Restore FTOP */
ldptr.w \tmp0, \thread, THREAD_FTOP
andi \tmp0, \tmp0, 0x7
la.pcrel \tmp1, 1f
alsl.d \tmp1, \tmp0, \tmp1, 3
jr \tmp1
1:
x86mttop 0
b 2f
x86mttop 1
b 2f
x86mttop 2
b 2f
x86mttop 3
Annotation
- Immediate include surface: `linux/sizes.h`, `asm/asm-offsets.h`, `asm/regdef.h`, `asm/fpregdef.h`, `asm/loongarch.h`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.