^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * OpenRISC Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Linux architectural port borrowing liberally from similar works of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * others. All original copyrights apply as per the original source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * declaration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * OpenRISC implementation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * et al.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #ifndef __ASM_OPENRISC_PTRACE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define __ASM_OPENRISC_PTRACE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/spr_defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <uapi/asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Make kernel PTrace/register structures opaque to userspace... userspace can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * access thread state via the regset mechanism. This allows us a bit of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * flexibility in how we order the registers on the stack, permitting some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * optimizations like packing call-clobbered registers together so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * they share a cacheline (not done yet, though... future optimization).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * This struct describes how the registers are laid out on the kernel stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * during a syscall or other kernel entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * This structure should always be cacheline aligned on the stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * FIXME: I don't think that's the case right now. The alignment is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * taken care of elsewhere... head.S, process.c, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct pt_regs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Named registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) long sr; /* Stored in place of r0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) long sp; /* r1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* Old style */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) long offset[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) long gprs[30];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* New style */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) long gpr[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) long pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* For restarting system calls:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * Set to syscall number for syscall exceptions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * -1 for all other exceptions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) long orig_gpr11; /* For restarting system calls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) long dummy; /* Cheap alignment fix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) long dummy2; /* Cheap alignment fix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* TODO: Rename this to REDZONE because that's what it is */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define STACK_FRAME_OVERHEAD 128 /* size of minimum stack frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define instruction_pointer(regs) ((regs)->pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define user_mode(regs) (((regs)->sr & SPR_SR_SM) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define user_stack_pointer(regs) ((unsigned long)(regs)->sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define profile_pc(regs) instruction_pointer(regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static inline long regs_return_value(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return regs->gpr[11];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #endif /* __ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Offsets used by 'ptrace' system call interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define PT_SR 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define PT_SP 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define PT_GPR2 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define PT_GPR3 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define PT_GPR4 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define PT_GPR5 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define PT_GPR6 24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define PT_GPR7 28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define PT_GPR8 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define PT_GPR9 36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #define PT_GPR10 40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define PT_GPR11 44
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define PT_GPR12 48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define PT_GPR13 52
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define PT_GPR14 56
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define PT_GPR15 60
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define PT_GPR16 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define PT_GPR17 68
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define PT_GPR18 72
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define PT_GPR19 76
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define PT_GPR20 80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define PT_GPR21 84
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define PT_GPR22 88
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define PT_GPR23 92
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define PT_GPR24 96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define PT_GPR25 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define PT_GPR26 104
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define PT_GPR27 108
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define PT_GPR28 112
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define PT_GPR29 116
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define PT_GPR30 120
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define PT_GPR31 124
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define PT_PC 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define PT_ORIG_GPR11 132
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define PT_SYSCALLNO 136
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #endif /* __ASM_OPENRISC_PTRACE_H */