1 /* SPDX-License-Identifier: GPL-2.0-or-later */
5 * Linux architectural port borrowing liberally from similar works of
6 * others. All original copyrights apply as per the original source
9 * OpenRISC implementation:
10 * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
11 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
14 #ifndef __ASM_OPENRISC_PTRACE_H
15 #define __ASM_OPENRISC_PTRACE_H
18 #include <asm/spr_defs.h>
19 #include <uapi/asm/ptrace.h>
20 #include <linux/compiler.h>
23 * Make kernel PTrace/register structures opaque to userspace... userspace can
24 * access thread state via the regset mechanism. This allows us a bit of
25 * flexibility in how we order the registers on the stack, permitting some
26 * optimizations like packing call-clobbered registers together so that
27 * they share a cacheline (not done yet, though... future optimization).
32 * This struct describes how the registers are laid out on the kernel stack
33 * during a syscall or other kernel entry.
35 * This structure should always be cacheline aligned on the stack.
36 * FIXME: I don't think that's the case right now. The alignment is
37 * taken care of elsewhere... head.S, process.c, etc.
44 long sr
; /* Stored in place of r0 */
88 /* For restarting system calls:
89 * Set to syscall number for syscall exceptions,
90 * -1 for all other exceptions.
92 long orig_gpr11
; /* For restarting system calls */
93 long dummy
; /* Cheap alignment fix */
94 long dummy2
; /* Cheap alignment fix */
97 /* TODO: Rename this to REDZONE because that's what it is */
98 #define STACK_FRAME_OVERHEAD 128 /* size of minimum stack frame */
100 #define MAX_REG_OFFSET offsetof(struct pt_regs, orig_gpr11)
102 /* Helpers for working with the instruction pointer */
103 static inline unsigned long instruction_pointer(struct pt_regs
*regs
)
105 return (unsigned long)regs
->pc
;
107 static inline void instruction_pointer_set(struct pt_regs
*regs
,
113 #define user_mode(regs) (((regs)->sr & SPR_SR_SM) == 0)
114 #define user_stack_pointer(regs) ((unsigned long)(regs)->sp)
115 #define profile_pc(regs) instruction_pointer(regs)
117 /* Valid only for Kernel mode traps. */
118 static inline unsigned long kernel_stack_pointer(struct pt_regs
*regs
)
120 return (unsigned long)regs
->sp
;
123 static inline long regs_return_value(struct pt_regs
*regs
)
125 return regs
->gpr
[11];
128 extern int regs_query_register_offset(const char *name
);
129 extern unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
,
133 * regs_get_register() - get register value from its offset
134 * @regs: pt_regs from which register value is gotten
135 * @offset: offset of the register.
137 * regs_get_register returns the value of a register whose offset from @regs.
138 * The @offset is the offset of the register in struct pt_regs.
139 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
141 static inline unsigned long regs_get_register(struct pt_regs
*regs
,
144 if (unlikely(offset
> MAX_REG_OFFSET
))
147 return *(unsigned long *)((unsigned long)regs
+ offset
);
150 #endif /* __ASSEMBLY__ */
153 * Offsets used by 'ptrace' system call interface.
188 #define PT_ORIG_GPR11 132
190 #endif /* __ASM_OPENRISC_PTRACE_H */