arch/sparc/kernel/unaligned_64.c
Source file repositories/reference/linux-study-clean/arch/sparc/kernel/unaligned_64.c
File Facts
- System
- Linux kernel
- Corpus path
arch/sparc/kernel/unaligned_64.c- Extension
.c- Size
- 18042 bytes
- Lines
- 710
- Domain
- Architecture Layer
- Bucket
- arch/sparc
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/jiffies.hlinux/kernel.hlinux/sched.hlinux/mm.hlinux/extable.hasm/asi.hasm/ptrace.hasm/pstate.hasm/processor.hlinux/uaccess.hlinux/smp.hlinux/bitops.hlinux/perf_event.hlinux/ratelimit.hlinux/context_tracking.hasm/fpumacro.hasm/cacheflush.hasm/setup.hentry.hkernel.h
Detected Declarations
enum directionfunction decode_directionfunction decode_access_sizefunction decode_asifunction decode_signednessfunction maybe_flush_windowsfunction sign_extend_imm13function fetch_regfunction compute_effective_addressfunction unaligned_panicfunction do_int_storefunction advancefunction floating_point_load_or_store_pfunction ok_for_kernelfunction kernel_mna_trap_faultfunction log_unalignedfunction kernel_unaligned_trapfunction handle_popcfunction handle_ldf_stqfunction handle_ld_nffunction handle_lddfmnafunction handle_stdfmna
Annotated Snippet
switch ((insn>>19)&0xf) {
case 15: /* swap* */
return both;
default:
return store;
}
}
}
/* 16 = double-word, 8 = extra-word, 4 = word, 2 = half-word */
static inline int decode_access_size(struct pt_regs *regs, unsigned int insn)
{
unsigned int tmp;
tmp = ((insn >> 19) & 0xf);
if (tmp == 11 || tmp == 14) /* ldx/stx */
return 8;
tmp &= 3;
if (!tmp)
return 4;
else if (tmp == 3)
return 16; /* ldd/std - Although it is actually 8 */
else if (tmp == 2)
return 2;
else {
printk("Impossible unaligned trap. insn=%08x\n", insn);
die_if_kernel("Byte sized unaligned access?!?!", regs);
/* GCC should never warn that control reaches the end
* of this function without returning a value because
* die_if_kernel() is marked with attribute 'noreturn'.
* Alas, some versions do...
*/
return 0;
}
}
static inline int decode_asi(unsigned int insn, struct pt_regs *regs)
{
if (insn & 0x800000) {
if (insn & 0x2000)
return (unsigned char)(regs->tstate >> 24); /* %asi */
else
return (unsigned char)(insn >> 5); /* imm_asi */
} else
return ASI_P;
}
/* 0x400000 = signed, 0 = unsigned */
static inline int decode_signedness(unsigned int insn)
{
return (insn & 0x400000);
}
static inline void maybe_flush_windows(unsigned int rs1, unsigned int rs2,
unsigned int rd, int from_kernel)
{
if (rs2 >= 16 || rs1 >= 16 || rd >= 16) {
if (from_kernel != 0)
__asm__ __volatile__("flushw");
else
flushw_user();
}
}
static inline long sign_extend_imm13(long imm)
{
return imm << 51 >> 51;
}
static unsigned long fetch_reg(unsigned int reg, struct pt_regs *regs)
{
unsigned long value, fp;
if (reg < 16)
return (!reg ? 0 : regs->u_regs[reg]);
fp = regs->u_regs[UREG_FP];
if (regs->tstate & TSTATE_PRIV) {
struct reg_window *win;
win = (struct reg_window *)(fp + STACK_BIAS);
value = win->locals[reg - 16];
} else if (!test_thread_64bit_stack(fp)) {
struct reg_window32 __user *win32;
win32 = (struct reg_window32 __user *)((unsigned long)((u32)fp));
get_user(value, &win32->locals[reg - 16]);
} else {
struct reg_window __user *win;
Annotation
- Immediate include surface: `linux/jiffies.h`, `linux/kernel.h`, `linux/sched.h`, `linux/mm.h`, `linux/extable.h`, `asm/asi.h`, `asm/ptrace.h`, `asm/pstate.h`.
- Detected declarations: `enum direction`, `function decode_direction`, `function decode_access_size`, `function decode_asi`, `function decode_signedness`, `function maybe_flush_windows`, `function sign_extend_imm13`, `function fetch_reg`, `function compute_effective_address`, `function unaligned_panic`.
- Atlas domain: Architecture Layer / arch/sparc.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.