^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2012 Regents of the University of California
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef _ASM_RISCV_PTRACE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define _ASM_RISCV_PTRACE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <uapi/asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/csr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct pt_regs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) unsigned long epc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) unsigned long ra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) unsigned long sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) unsigned long gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) unsigned long tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) unsigned long t0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) unsigned long t1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) unsigned long t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned long s0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) unsigned long s1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) unsigned long a0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) unsigned long a1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) unsigned long a2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) unsigned long a3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) unsigned long a4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) unsigned long a5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned long a6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned long a7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned long s2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned long s3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned long s4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned long s5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned long s6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned long s7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned long s8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned long s9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned long s10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned long s11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned long t3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned long t4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned long t5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned long t6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* Supervisor/Machine CSRs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) unsigned long status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned long badaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) unsigned long cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* a0 value before the syscall */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long orig_a0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define REG_FMT "%016lx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define REG_FMT "%08lx"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define user_mode(regs) (((regs)->status & SR_PP) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* Helpers for working with the instruction pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static inline unsigned long instruction_pointer(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return regs->epc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static inline void instruction_pointer_set(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) regs->epc = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define profile_pc(regs) instruction_pointer(regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Helpers for working with the user stack pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static inline unsigned long user_stack_pointer(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return regs->sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static inline void user_stack_pointer_set(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) regs->sp = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* Helpers for working with the frame pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static inline unsigned long frame_pointer(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return regs->s0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static inline void frame_pointer_set(struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) regs->s0 = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static inline unsigned long regs_return_value(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return regs->a0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #endif /* __ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #endif /* _ASM_RISCV_PTRACE_H */