162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef __SPARC_PTRACE_H 362306a36Sopenharmony_ci#define __SPARC_PTRACE_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <uapi/asm/ptrace.h> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#if defined(__sparc__) && defined(__arch64__) 862306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/compiler.h> 1162306a36Sopenharmony_ci#include <linux/threads.h> 1262306a36Sopenharmony_ci#include <asm/switch_to.h> 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_cistatic inline int pt_regs_trap_type(struct pt_regs *regs) 1562306a36Sopenharmony_ci{ 1662306a36Sopenharmony_ci return regs->magic & 0x1ff; 1762306a36Sopenharmony_ci} 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_cistatic inline bool pt_regs_is_syscall(struct pt_regs *regs) 2062306a36Sopenharmony_ci{ 2162306a36Sopenharmony_ci return (regs->tstate & TSTATE_SYSCALL); 2262306a36Sopenharmony_ci} 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_cistatic inline bool pt_regs_clear_syscall(struct pt_regs *regs) 2562306a36Sopenharmony_ci{ 2662306a36Sopenharmony_ci return (regs->tstate &= ~TSTATE_SYSCALL); 2762306a36Sopenharmony_ci} 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#define arch_ptrace_stop_needed() \ 3062306a36Sopenharmony_ci({ flush_user_windows(); \ 3162306a36Sopenharmony_ci get_thread_wsaved() != 0; \ 3262306a36Sopenharmony_ci}) 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define arch_ptrace_stop() \ 3562306a36Sopenharmony_ci synchronize_user_stack() 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define current_pt_regs() \ 3862306a36Sopenharmony_ci ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1) 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cistruct global_reg_snapshot { 4162306a36Sopenharmony_ci unsigned long tstate; 4262306a36Sopenharmony_ci unsigned long tpc; 4362306a36Sopenharmony_ci unsigned long tnpc; 4462306a36Sopenharmony_ci unsigned long o7; 4562306a36Sopenharmony_ci unsigned long i7; 4662306a36Sopenharmony_ci unsigned long rpc; 4762306a36Sopenharmony_ci struct thread_info *thread; 4862306a36Sopenharmony_ci unsigned long pad1; 4962306a36Sopenharmony_ci}; 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_cistruct global_pmu_snapshot { 5262306a36Sopenharmony_ci unsigned long pcr[4]; 5362306a36Sopenharmony_ci unsigned long pic[4]; 5462306a36Sopenharmony_ci}; 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ciunion global_cpu_snapshot { 5762306a36Sopenharmony_ci struct global_reg_snapshot reg; 5862306a36Sopenharmony_ci struct global_pmu_snapshot pmu; 5962306a36Sopenharmony_ci}; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ciextern union global_cpu_snapshot global_cpu_snapshot[NR_CPUS]; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define force_successful_syscall_return() set_thread_noerror(1) 6462306a36Sopenharmony_ci#define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV)) 6562306a36Sopenharmony_ci#define instruction_pointer(regs) ((regs)->tpc) 6662306a36Sopenharmony_ci#define instruction_pointer_set(regs, val) do { \ 6762306a36Sopenharmony_ci (regs)->tpc = (val); \ 6862306a36Sopenharmony_ci (regs)->tnpc = (val)+4; \ 6962306a36Sopenharmony_ci } while (0) 7062306a36Sopenharmony_ci#define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP]) 7162306a36Sopenharmony_cistatic inline int is_syscall_success(struct pt_regs *regs) 7262306a36Sopenharmony_ci{ 7362306a36Sopenharmony_ci return !(regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)); 7462306a36Sopenharmony_ci} 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_cistatic inline long regs_return_value(struct pt_regs *regs) 7762306a36Sopenharmony_ci{ 7862306a36Sopenharmony_ci return regs->u_regs[UREG_I0]; 7962306a36Sopenharmony_ci} 8062306a36Sopenharmony_ci#ifdef CONFIG_SMP 8162306a36Sopenharmony_ciunsigned long profile_pc(struct pt_regs *); 8262306a36Sopenharmony_ci#else 8362306a36Sopenharmony_ci#define profile_pc(regs) instruction_pointer(regs) 8462306a36Sopenharmony_ci#endif 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci#define MAX_REG_OFFSET (offsetof(struct pt_regs, magic)) 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ciint regs_query_register_offset(const char *name); 8962306a36Sopenharmony_ciunsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n); 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci/** 9262306a36Sopenharmony_ci * regs_get_register() - get register value from its offset 9362306a36Sopenharmony_ci * @regs: pt_regs from which register value is gotten 9462306a36Sopenharmony_ci * @offset: offset number of the register. 9562306a36Sopenharmony_ci * 9662306a36Sopenharmony_ci * regs_get_register returns the value of a register whose 9762306a36Sopenharmony_ci * offset from @regs. The @offset is the offset of the register 9862306a36Sopenharmony_ci * in struct pt_regs. If @offset is bigger than MAX_REG_OFFSET, 9962306a36Sopenharmony_ci * this returns 0. 10062306a36Sopenharmony_ci */ 10162306a36Sopenharmony_cistatic inline unsigned long regs_get_register(struct pt_regs *regs, 10262306a36Sopenharmony_ci unsigned long offset) 10362306a36Sopenharmony_ci{ 10462306a36Sopenharmony_ci if (unlikely(offset >= MAX_REG_OFFSET)) 10562306a36Sopenharmony_ci return 0; 10662306a36Sopenharmony_ci if (offset == PT_V9_Y) 10762306a36Sopenharmony_ci return *(unsigned int *)((unsigned long)regs + offset); 10862306a36Sopenharmony_ci return *(unsigned long *)((unsigned long)regs + offset); 10962306a36Sopenharmony_ci} 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci/* Valid only for Kernel mode traps. */ 11262306a36Sopenharmony_cistatic inline unsigned long kernel_stack_pointer(struct pt_regs *regs) 11362306a36Sopenharmony_ci{ 11462306a36Sopenharmony_ci return regs->u_regs[UREG_I6]; 11562306a36Sopenharmony_ci} 11662306a36Sopenharmony_ci#else /* __ASSEMBLY__ */ 11762306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */ 11862306a36Sopenharmony_ci#else /* (defined(__sparc__) && defined(__arch64__)) */ 11962306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 12062306a36Sopenharmony_ci#include <asm/switch_to.h> 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_cistatic inline bool pt_regs_is_syscall(struct pt_regs *regs) 12362306a36Sopenharmony_ci{ 12462306a36Sopenharmony_ci return (regs->psr & PSR_SYSCALL); 12562306a36Sopenharmony_ci} 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_cistatic inline bool pt_regs_clear_syscall(struct pt_regs *regs) 12862306a36Sopenharmony_ci{ 12962306a36Sopenharmony_ci return (regs->psr &= ~PSR_SYSCALL); 13062306a36Sopenharmony_ci} 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#define arch_ptrace_stop_needed() \ 13362306a36Sopenharmony_ci({ flush_user_windows(); \ 13462306a36Sopenharmony_ci current_thread_info()->w_saved != 0; \ 13562306a36Sopenharmony_ci}) 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci#define arch_ptrace_stop() \ 13862306a36Sopenharmony_ci synchronize_user_stack() 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci#define current_pt_regs() \ 14162306a36Sopenharmony_ci ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1) 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci#define user_mode(regs) (!((regs)->psr & PSR_PS)) 14462306a36Sopenharmony_ci#define instruction_pointer(regs) ((regs)->pc) 14562306a36Sopenharmony_ci#define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP]) 14662306a36Sopenharmony_ciunsigned long profile_pc(struct pt_regs *); 14762306a36Sopenharmony_ci#else /* (!__ASSEMBLY__) */ 14862306a36Sopenharmony_ci#endif /* (!__ASSEMBLY__) */ 14962306a36Sopenharmony_ci#endif /* (defined(__sparc__) && defined(__arch64__)) */ 15062306a36Sopenharmony_ci#define STACK_BIAS 2047 15162306a36Sopenharmony_ci 15262306a36Sopenharmony_ci/* global_reg_snapshot offsets */ 15362306a36Sopenharmony_ci#define GR_SNAP_TSTATE 0x00 15462306a36Sopenharmony_ci#define GR_SNAP_TPC 0x08 15562306a36Sopenharmony_ci#define GR_SNAP_TNPC 0x10 15662306a36Sopenharmony_ci#define GR_SNAP_O7 0x18 15762306a36Sopenharmony_ci#define GR_SNAP_I7 0x20 15862306a36Sopenharmony_ci#define GR_SNAP_RPC 0x28 15962306a36Sopenharmony_ci#define GR_SNAP_THREAD 0x30 16062306a36Sopenharmony_ci#define GR_SNAP_PAD1 0x38 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#endif /* !(__SPARC_PTRACE_H) */ 163