arch/loongarch/kernel/traps.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kernel/traps.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kernel/traps.c- Extension
.c- Size
- 29321 bytes
- Lines
- 1212
- 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.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/bitops.hlinux/bug.hlinux/compiler.hlinux/context_tracking.hlinux/entry-common.hlinux/init.hlinux/kernel.hlinux/kexec.hlinux/module.hlinux/export.hlinux/extable.hlinux/mm.hlinux/sched/mm.hlinux/sched/debug.hlinux/smp.hlinux/spinlock.hlinux/kallsyms.hlinux/memblock.hlinux/interrupt.hlinux/ptrace.hlinux/kgdb.hlinux/kdebug.hlinux/notifier.hlinux/irq.hlinux/perf_event.hasm/addrspace.hasm/bootinfo.hasm/branch.hasm/break.hasm/cpu.hasm/exception.h
Detected Declarations
function show_backtracefunction show_stacktracefunction show_stackfunction show_codefunction print_bool_fragmentfunction print_plv_fragmentfunction print_memory_type_fragmentfunction print_intr_fragmentfunction print_crmdfunction print_prmdfunction print_euenfunction print_ecfgfunction print_estatfunction __show_regsfunction show_regsfunction show_registersfunction diefunction setup_vint_sizefunction force_fcsr_sigfunction process_fpemu_returnfunction do_fpefunction do_adefunction do_alefunction is_valid_bugaddrfunction bug_handlerfunction do_bcefunction do_bpfunction do_watchfunction do_rifunction init_restore_fpfunction init_restore_lsxfunction init_restore_lasxfunction do_fpufunction do_lsxfunction do_lasxfunction init_restore_lbtfunction do_lbtfunction do_reservedfunction cache_parity_errorfunction handle_loongarch_irqfunction do_vintfunction configure_exception_vectorfunction per_cpu_trap_initfunction set_handlerfunction set_merr_handlerfunction trap_initexport exception_table
Annotated Snippet
if (i && ((i % (64 / field)) == 0)) {
pr_cont("\n");
printk("%s ", loglvl);
}
if (i > 39) {
pr_cont(" ...");
break;
}
if (__get_addr(&stackdata, sp++, user)) {
pr_cont(" (Bad stack address)");
break;
}
pr_cont(" %0*lx", field, stackdata);
i++;
}
pr_cont("\n");
show_backtrace(task, regs, loglvl, user);
}
void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
{
struct pt_regs regs;
regs.csr_crmd = 0;
if (sp) {
regs.csr_era = 0;
regs.regs[1] = 0;
regs.regs[3] = (unsigned long)sp;
} else {
if (!task || task == current)
prepare_frametrace(®s);
else {
regs.csr_era = task->thread.reg01;
regs.regs[1] = 0;
regs.regs[3] = task->thread.reg03;
regs.regs[22] = task->thread.reg22;
}
}
show_stacktrace(task, ®s, loglvl, false);
}
static void show_code(unsigned int *pc, bool user)
{
long i;
unsigned int insn;
printk("Code:");
for(i = -3 ; i < 6 ; i++) {
if (__get_inst(&insn, pc + i, user)) {
pr_cont(" (Bad address in era)\n");
break;
}
pr_cont("%c%08x%c", (i?' ':'<'), insn, (i?' ':'>'));
}
pr_cont("\n");
}
static void print_bool_fragment(const char *key, unsigned long val, bool first)
{
/* e.g. "+PG", "-DA" */
pr_cont("%s%c%s", first ? "" : " ", val ? '+' : '-', key);
}
static void print_plv_fragment(const char *key, int val)
{
/* e.g. "PLV0", "PPLV3" */
pr_cont("%s%d", key, val);
}
static void print_memory_type_fragment(const char *key, unsigned long val)
{
const char *humanized_type;
switch (val) {
case 0:
humanized_type = "SUC";
break;
case 1:
humanized_type = "CC";
break;
case 2:
humanized_type = "WUC";
break;
default:
pr_cont(" %s=Reserved(%lu)", key, val);
return;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitops.h`, `linux/bug.h`, `linux/compiler.h`, `linux/context_tracking.h`, `linux/entry-common.h`, `linux/init.h`, `linux/kernel.h`.
- Detected declarations: `function show_backtrace`, `function show_stacktrace`, `function show_stack`, `function show_code`, `function print_bool_fragment`, `function print_plv_fragment`, `function print_memory_type_fragment`, `function print_intr_fragment`, `function print_crmd`, `function print_prmd`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.