162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * arch/arm/include/asm/ptrace.h 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 1996-2003 Russell King 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci#ifndef __ASM_ARM_PTRACE_H 862306a36Sopenharmony_ci#define __ASM_ARM_PTRACE_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <uapi/asm/ptrace.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 1362306a36Sopenharmony_ci#include <linux/types.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cistruct pt_regs { 1662306a36Sopenharmony_ci unsigned long uregs[18]; 1762306a36Sopenharmony_ci}; 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_cistruct svc_pt_regs { 2062306a36Sopenharmony_ci struct pt_regs regs; 2162306a36Sopenharmony_ci u32 dacr; 2262306a36Sopenharmony_ci}; 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#define to_svc_pt_regs(r) container_of(r, struct svc_pt_regs, regs) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#define user_mode(regs) \ 2762306a36Sopenharmony_ci (((regs)->ARM_cpsr & 0xf) == 0) 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#ifdef CONFIG_ARM_THUMB 3062306a36Sopenharmony_ci#define thumb_mode(regs) \ 3162306a36Sopenharmony_ci (((regs)->ARM_cpsr & PSR_T_BIT)) 3262306a36Sopenharmony_ci#else 3362306a36Sopenharmony_ci#define thumb_mode(regs) (0) 3462306a36Sopenharmony_ci#endif 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#ifndef CONFIG_CPU_V7M 3762306a36Sopenharmony_ci#define isa_mode(regs) \ 3862306a36Sopenharmony_ci ((((regs)->ARM_cpsr & PSR_J_BIT) >> (__ffs(PSR_J_BIT) - 1)) | \ 3962306a36Sopenharmony_ci (((regs)->ARM_cpsr & PSR_T_BIT) >> (__ffs(PSR_T_BIT)))) 4062306a36Sopenharmony_ci#else 4162306a36Sopenharmony_ci#define isa_mode(regs) 1 /* Thumb */ 4262306a36Sopenharmony_ci#endif 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#define processor_mode(regs) \ 4562306a36Sopenharmony_ci ((regs)->ARM_cpsr & MODE_MASK) 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci#define interrupts_enabled(regs) \ 4862306a36Sopenharmony_ci (!((regs)->ARM_cpsr & PSR_I_BIT)) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define fast_interrupts_enabled(regs) \ 5162306a36Sopenharmony_ci (!((regs)->ARM_cpsr & PSR_F_BIT)) 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci/* Are the current registers suitable for user mode? 5462306a36Sopenharmony_ci * (used to maintain security in signal handlers) 5562306a36Sopenharmony_ci */ 5662306a36Sopenharmony_cistatic inline int valid_user_regs(struct pt_regs *regs) 5762306a36Sopenharmony_ci{ 5862306a36Sopenharmony_ci#ifndef CONFIG_CPU_V7M 5962306a36Sopenharmony_ci unsigned long mode = regs->ARM_cpsr & MODE_MASK; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci /* 6262306a36Sopenharmony_ci * Always clear the F (FIQ) and A (delayed abort) bits 6362306a36Sopenharmony_ci */ 6462306a36Sopenharmony_ci regs->ARM_cpsr &= ~(PSR_F_BIT | PSR_A_BIT); 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci if ((regs->ARM_cpsr & PSR_I_BIT) == 0) { 6762306a36Sopenharmony_ci if (mode == USR_MODE) 6862306a36Sopenharmony_ci return 1; 6962306a36Sopenharmony_ci if (elf_hwcap & HWCAP_26BIT && mode == USR26_MODE) 7062306a36Sopenharmony_ci return 1; 7162306a36Sopenharmony_ci } 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci /* 7462306a36Sopenharmony_ci * Force CPSR to something logical... 7562306a36Sopenharmony_ci */ 7662306a36Sopenharmony_ci regs->ARM_cpsr &= PSR_f | PSR_s | PSR_x | PSR_T_BIT | MODE32_BIT; 7762306a36Sopenharmony_ci if (!(elf_hwcap & HWCAP_26BIT)) 7862306a36Sopenharmony_ci regs->ARM_cpsr |= USR_MODE; 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci return 0; 8162306a36Sopenharmony_ci#else /* ifndef CONFIG_CPU_V7M */ 8262306a36Sopenharmony_ci return 1; 8362306a36Sopenharmony_ci#endif 8462306a36Sopenharmony_ci} 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_cistatic inline long regs_return_value(struct pt_regs *regs) 8762306a36Sopenharmony_ci{ 8862306a36Sopenharmony_ci return regs->ARM_r0; 8962306a36Sopenharmony_ci} 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci#define instruction_pointer(regs) (regs)->ARM_pc 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci#ifdef CONFIG_THUMB2_KERNEL 9462306a36Sopenharmony_ci#define frame_pointer(regs) (regs)->ARM_r7 9562306a36Sopenharmony_ci#else 9662306a36Sopenharmony_ci#define frame_pointer(regs) (regs)->ARM_fp 9762306a36Sopenharmony_ci#endif 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_cistatic inline void instruction_pointer_set(struct pt_regs *regs, 10062306a36Sopenharmony_ci unsigned long val) 10162306a36Sopenharmony_ci{ 10262306a36Sopenharmony_ci instruction_pointer(regs) = val; 10362306a36Sopenharmony_ci} 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci#ifdef CONFIG_SMP 10662306a36Sopenharmony_ciextern unsigned long profile_pc(struct pt_regs *regs); 10762306a36Sopenharmony_ci#else 10862306a36Sopenharmony_ci#define profile_pc(regs) instruction_pointer(regs) 10962306a36Sopenharmony_ci#endif 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci#define predicate(x) ((x) & 0xf0000000) 11262306a36Sopenharmony_ci#define PREDICATE_ALWAYS 0xe0000000 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* 11562306a36Sopenharmony_ci * True if instr is a 32-bit thumb instruction. This works if instr 11662306a36Sopenharmony_ci * is the first or only half-word of a thumb instruction. It also works 11762306a36Sopenharmony_ci * when instr holds all 32-bits of a wide thumb instruction if stored 11862306a36Sopenharmony_ci * in the form (first_half<<16)|(second_half) 11962306a36Sopenharmony_ci */ 12062306a36Sopenharmony_ci#define is_wide_instruction(instr) ((unsigned)(instr) >= 0xe800) 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci/* 12362306a36Sopenharmony_ci * kprobe-based event tracer support 12462306a36Sopenharmony_ci */ 12562306a36Sopenharmony_ci#include <linux/compiler.h> 12662306a36Sopenharmony_ci#define MAX_REG_OFFSET (offsetof(struct pt_regs, ARM_ORIG_r0)) 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ciextern int regs_query_register_offset(const char *name); 12962306a36Sopenharmony_ciextern const char *regs_query_register_name(unsigned int offset); 13062306a36Sopenharmony_ciextern bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr); 13162306a36Sopenharmony_ciextern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, 13262306a36Sopenharmony_ci unsigned int n); 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci/** 13562306a36Sopenharmony_ci * regs_get_register() - get register value from its offset 13662306a36Sopenharmony_ci * @regs: pt_regs from which register value is gotten 13762306a36Sopenharmony_ci * @offset: offset number of the register. 13862306a36Sopenharmony_ci * 13962306a36Sopenharmony_ci * regs_get_register returns the value of a register whose offset from @regs. 14062306a36Sopenharmony_ci * The @offset is the offset of the register in struct pt_regs. 14162306a36Sopenharmony_ci * If @offset is bigger than MAX_REG_OFFSET, this returns 0. 14262306a36Sopenharmony_ci */ 14362306a36Sopenharmony_cistatic inline unsigned long regs_get_register(struct pt_regs *regs, 14462306a36Sopenharmony_ci unsigned int offset) 14562306a36Sopenharmony_ci{ 14662306a36Sopenharmony_ci if (unlikely(offset > MAX_REG_OFFSET)) 14762306a36Sopenharmony_ci return 0; 14862306a36Sopenharmony_ci return *(unsigned long *)((unsigned long)regs + offset); 14962306a36Sopenharmony_ci} 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci/* Valid only for Kernel mode traps. */ 15262306a36Sopenharmony_cistatic inline unsigned long kernel_stack_pointer(struct pt_regs *regs) 15362306a36Sopenharmony_ci{ 15462306a36Sopenharmony_ci return regs->ARM_sp; 15562306a36Sopenharmony_ci} 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_cistatic inline unsigned long user_stack_pointer(struct pt_regs *regs) 15862306a36Sopenharmony_ci{ 15962306a36Sopenharmony_ci return regs->ARM_sp; 16062306a36Sopenharmony_ci} 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#define current_pt_regs(void) ({ (struct pt_regs *) \ 16362306a36Sopenharmony_ci ((current_stack_pointer | (THREAD_SIZE - 1)) - 7) - 1; \ 16462306a36Sopenharmony_ci}) 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_cistatic inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) 16762306a36Sopenharmony_ci{ 16862306a36Sopenharmony_ci regs->ARM_r0 = rc; 16962306a36Sopenharmony_ci} 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci/* 17262306a36Sopenharmony_ci * Update ITSTATE after normal execution of an IT block instruction. 17362306a36Sopenharmony_ci * 17462306a36Sopenharmony_ci * The 8 IT state bits are split into two parts in CPSR: 17562306a36Sopenharmony_ci * ITSTATE<1:0> are in CPSR<26:25> 17662306a36Sopenharmony_ci * ITSTATE<7:2> are in CPSR<15:10> 17762306a36Sopenharmony_ci */ 17862306a36Sopenharmony_cistatic inline unsigned long it_advance(unsigned long cpsr) 17962306a36Sopenharmony_ci{ 18062306a36Sopenharmony_ci if ((cpsr & 0x06000400) == 0) { 18162306a36Sopenharmony_ci /* ITSTATE<2:0> == 0 means end of IT block, so clear IT state */ 18262306a36Sopenharmony_ci cpsr &= ~PSR_IT_MASK; 18362306a36Sopenharmony_ci } else { 18462306a36Sopenharmony_ci /* We need to shift left ITSTATE<4:0> */ 18562306a36Sopenharmony_ci const unsigned long mask = 0x06001c00; /* Mask ITSTATE<4:0> */ 18662306a36Sopenharmony_ci unsigned long it = cpsr & mask; 18762306a36Sopenharmony_ci it <<= 1; 18862306a36Sopenharmony_ci it |= it >> (27 - 10); /* Carry ITSTATE<2> to correct place */ 18962306a36Sopenharmony_ci it &= mask; 19062306a36Sopenharmony_ci cpsr &= ~mask; 19162306a36Sopenharmony_ci cpsr |= it; 19262306a36Sopenharmony_ci } 19362306a36Sopenharmony_ci return cpsr; 19462306a36Sopenharmony_ci} 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ciint syscall_trace_enter(struct pt_regs *regs); 19762306a36Sopenharmony_civoid syscall_trace_exit(struct pt_regs *regs); 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */ 20062306a36Sopenharmony_ci#endif 201