/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* OpenRISC Linux3*4* Linux architectural port borrowing liberally from similar works of5* others. All original copyrights apply as per the original source6* declaration.7*8* OpenRISC implementation:9* Copyright (C) 2003 Matjaz Breskvar <[email protected]>10* Copyright (C) 2010-2011 Jonas Bonn <[email protected]>11* et al.12*/13#ifndef __ASM_OPENRISC_PTRACE_H14#define __ASM_OPENRISC_PTRACE_H151617#include <asm/spr_defs.h>18#include <uapi/asm/ptrace.h>19#include <linux/compiler.h>2021/*22* Make kernel PTrace/register structures opaque to userspace... userspace can23* access thread state via the regset mechanism. This allows us a bit of24* flexibility in how we order the registers on the stack, permitting some25* optimizations like packing call-clobbered registers together so that26* they share a cacheline (not done yet, though... future optimization).27*/2829#ifndef __ASSEMBLER__30/*31* This struct describes how the registers are laid out on the kernel stack32* during a syscall or other kernel entry.33*34* This structure should always be cacheline aligned on the stack.35* FIXME: I don't think that's the case right now. The alignment is36* taken care of elsewhere... head.S, process.c, etc.37*/3839struct pt_regs {40union {41struct {42/* Named registers */43long sr; /* Stored in place of r0 */44long sp; /* r1 */45long gpr2;46long gpr3;47long gpr4;48long gpr5;49long gpr6;50long gpr7;51long gpr8;52long gpr9;53long gpr10;54long gpr11;55long gpr12;56long gpr13;57long gpr14;58long gpr15;59long gpr16;60long gpr17;61long gpr18;62long gpr19;63long gpr20;64long gpr21;65long gpr22;66long gpr23;67long gpr24;68long gpr25;69long gpr26;70long gpr27;71long gpr28;72long gpr29;73long gpr30;74long gpr31;75};76struct {77/* Old style */78long offset[2];79long gprs[30];80};81struct {82/* New style */83long gpr[32];84};85};86long pc;87/* For restarting system calls:88* Set to syscall number for syscall exceptions,89* -1 for all other exceptions.90*/91long orig_gpr11; /* For restarting system calls */92long dummy; /* Cheap alignment fix */93long dummy2; /* Cheap alignment fix */94};9596/* TODO: Rename this to REDZONE because that's what it is */97#define STACK_FRAME_OVERHEAD 128 /* size of minimum stack frame */9899#define MAX_REG_OFFSET offsetof(struct pt_regs, orig_gpr11)100101/* Helpers for working with the instruction pointer */102static inline unsigned long instruction_pointer(struct pt_regs *regs)103{104return (unsigned long)regs->pc;105}106static inline void instruction_pointer_set(struct pt_regs *regs,107unsigned long val)108{109regs->pc = val;110}111112#define user_mode(regs) (((regs)->sr & SPR_SR_SM) == 0)113#define user_stack_pointer(regs) ((unsigned long)(regs)->sp)114#define profile_pc(regs) instruction_pointer(regs)115116/* Valid only for Kernel mode traps. */117static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)118{119return (unsigned long)regs->sp;120}121122static inline long regs_return_value(struct pt_regs *regs)123{124return regs->gpr[11];125}126127extern int regs_query_register_offset(const char *name);128extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,129unsigned int n);130131/**132* regs_get_register() - get register value from its offset133* @regs: pt_regs from which register value is gotten134* @offset: offset of the register.135*136* regs_get_register returns the value of a register whose offset from @regs.137* The @offset is the offset of the register in struct pt_regs.138* If @offset is bigger than MAX_REG_OFFSET, this returns 0.139*/140static inline unsigned long regs_get_register(struct pt_regs *regs,141unsigned int offset)142{143if (unlikely(offset > MAX_REG_OFFSET))144return 0;145146return *(unsigned long *)((unsigned long)regs + offset);147}148149#endif /* __ASSEMBLER__ */150151/*152* Offsets used by 'ptrace' system call interface.153*/154#define PT_SR 0155#define PT_SP 4156#define PT_GPR2 8157#define PT_GPR3 12158#define PT_GPR4 16159#define PT_GPR5 20160#define PT_GPR6 24161#define PT_GPR7 28162#define PT_GPR8 32163#define PT_GPR9 36164#define PT_GPR10 40165#define PT_GPR11 44166#define PT_GPR12 48167#define PT_GPR13 52168#define PT_GPR14 56169#define PT_GPR15 60170#define PT_GPR16 64171#define PT_GPR17 68172#define PT_GPR18 72173#define PT_GPR19 76174#define PT_GPR20 80175#define PT_GPR21 84176#define PT_GPR22 88177#define PT_GPR23 92178#define PT_GPR24 96179#define PT_GPR25 100180#define PT_GPR26 104181#define PT_GPR27 108182#define PT_GPR28 112183#define PT_GPR29 116184#define PT_GPR30 120185#define PT_GPR31 124186#define PT_PC 128187#define PT_ORIG_GPR11 132188189#endif /* __ASM_OPENRISC_PTRACE_H */190191192