^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* ptrace.c: Sparc process tracing support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 1996, 2008 David S. Miller (davem@davemloft.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Based upon code written by Ross Biro, Linus Torvalds, Bob Manson,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * and David Mosberger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Added Linux support -miguel (weird, eh?, the original code was meant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * to emulate SunOS).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/regset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* #define ALLOW_INIT_TRACING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Called by kernel/ptrace.c when detaching..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Make sure single step bits etc are not set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void ptrace_disable(struct task_struct *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* nothing to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) enum sparc_regset {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) REGSET_GENERAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) REGSET_FP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int regwindow32_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) const struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u32 *uregs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned long reg_window = regs->u_regs[UREG_I6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int size = 16 * sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (target == current) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (copy_from_user(uregs, (void __user *)reg_window, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (access_process_vm(target, reg_window, uregs, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) FOLL_FORCE) != size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return 0;
^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) static int regwindow32_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) const struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u32 *uregs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned long reg_window = regs->u_regs[UREG_I6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int size = 16 * sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (target == current) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (copy_to_user((void __user *)reg_window, uregs, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (access_process_vm(target, reg_window, uregs, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) FOLL_FORCE | FOLL_WRITE) != size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int genregs32_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) const struct pt_regs *regs = target->thread.kregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u32 uregs[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) flush_user_windows();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) membuf_write(&to, regs->u_regs, 16 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!to.left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (regwindow32_get(target, regs, uregs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) membuf_write(&to, uregs, 16 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) membuf_store(&to, regs->psr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) membuf_store(&to, regs->pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) membuf_store(&to, regs->npc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) membuf_store(&to, regs->y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return membuf_zero(&to, 2 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int genregs32_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct pt_regs *regs = target->thread.kregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u32 uregs[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u32 psr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) flush_user_windows();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) regs->u_regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 0, 16 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (ret || !count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (regwindow32_get(target, regs, uregs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) uregs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 16 * sizeof(u32), 32 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (regwindow32_set(target, regs, uregs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) &psr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 32 * sizeof(u32), 33 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) regs->psr = (regs->psr & ~(PSR_ICC | PSR_SYSCALL)) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) (psr & (PSR_ICC | PSR_SYSCALL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (!count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ®s->pc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 33 * sizeof(u32), 34 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (ret || !count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ®s->npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 34 * sizeof(u32), 35 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (ret || !count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ®s->y,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 35 * sizeof(u32), 36 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (ret || !count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 36 * sizeof(u32), 38 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int fpregs32_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) save_and_clear_fpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) membuf_write(&to, target->thread.float_regs, 32 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) membuf_zero(&to, sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) membuf_write(&to, &target->thread.fsr, sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) membuf_store(&to, (u32)((1 << 8) | (8 << 16)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return membuf_zero(&to, 64 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static int fpregs32_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) unsigned long *fpregs = target->thread.float_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) save_and_clear_fpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) fpregs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 0, 32 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 32 * sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 33 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) &target->thread.fsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 33 * sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 34 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 34 * sizeof(u32), -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static const struct user_regset sparc32_regsets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* Format is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * G0 --> G7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * O0 --> O7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * L0 --> L7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * I0 --> I7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * PSR, PC, nPC, Y, WIM, TBR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) [REGSET_GENERAL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .core_note_type = NT_PRSTATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .n = 38,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .size = sizeof(u32), .align = sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .regset_get = genregs32_get, .set = genregs32_set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* Format is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * F0 --> F31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * empty 32-bit word
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * FSR (32--bit word)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * FPU QUEUE COUNT (8-bit char)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * FPU QUEUE ENTRYSIZE (8-bit char)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * FPU ENABLED (8-bit char)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * empty 8-bit char
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * FPU QUEUE (64 32-bit ints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) [REGSET_FP] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .core_note_type = NT_PRFPREG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .n = 99,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .size = sizeof(u32), .align = sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .regset_get = fpregs32_get, .set = fpregs32_set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int getregs_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) const struct pt_regs *regs = target->thread.kregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) flush_user_windows();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) membuf_store(&to, regs->psr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) membuf_store(&to, regs->pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) membuf_store(&to, regs->npc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) membuf_store(&to, regs->y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return membuf_write(&to, regs->u_regs + 1, 15 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static int setregs_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct pt_regs *regs = target->thread.kregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) u32 v[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) flush_user_windows();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) v,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 0, 4 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) regs->psr = (regs->psr & ~(PSR_ICC | PSR_SYSCALL)) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) (v[0] & (PSR_ICC | PSR_SYSCALL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) regs->pc = v[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) regs->npc = v[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) regs->y = v[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) regs->u_regs + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 4 * sizeof(u32) , 19 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static int getfpregs_get(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct membuf to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) save_and_clear_fpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) membuf_write(&to, &target->thread.float_regs, 32 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) membuf_write(&to, &target->thread.fsr, sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return membuf_zero(&to, 35 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int setfpregs_set(struct task_struct *target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) const struct user_regset *regset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) unsigned int pos, unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) const void *kbuf, const void __user *ubuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) unsigned long *fpregs = target->thread.float_regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (target == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) save_and_clear_fpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) fpregs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 0, 32 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) &target->thread.fsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 32 * sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 33 * sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static const struct user_regset ptrace32_regsets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) [REGSET_GENERAL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .n = 19, .size = sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .regset_get = getregs_get, .set = setregs_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) [REGSET_FP] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .n = 68, .size = sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .regset_get = getfpregs_get, .set = setfpregs_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static const struct user_regset_view ptrace32_view = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) .regsets = ptrace32_regsets, .n = ARRAY_SIZE(ptrace32_regsets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static const struct user_regset_view user_sparc32_view = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .name = "sparc", .e_machine = EM_SPARC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) const struct user_regset_view *task_user_regset_view(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return &user_sparc32_view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct fps {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) unsigned long regs[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) unsigned long fsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) unsigned long extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) unsigned long fpqd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct fq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) unsigned long *insnaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) unsigned long insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) } fpq[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) long arch_ptrace(struct task_struct *child, long request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) unsigned long addr, unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) void __user *addr2p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct pt_regs __user *pregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct fps __user *fps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) addr2p = (void __user *) addr2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) pregs = (struct pt_regs __user *) addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) fps = (struct fps __user *) addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) switch(request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) case PTRACE_GETREGS: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ret = copy_regset_to_user(child, &ptrace32_view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) REGSET_GENERAL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 19 * sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) pregs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) case PTRACE_SETREGS: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ret = copy_regset_from_user(child, &ptrace32_view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) REGSET_GENERAL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 19 * sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) pregs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) case PTRACE_GETFPREGS: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ret = copy_regset_to_user(child, &ptrace32_view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) REGSET_FP, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 68 * sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) fps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) case PTRACE_SETFPREGS: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) ret = copy_regset_from_user(child, &ptrace32_view,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) REGSET_FP, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 33 * sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) fps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) case PTRACE_READTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) case PTRACE_READDATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) ret = ptrace_readdata(child, addr, addr2p, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (ret == data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) else if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) case PTRACE_WRITETEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) case PTRACE_WRITEDATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ret = ptrace_writedata(child, addr2p, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (ret == data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) else if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (request == PTRACE_SPARC_DETACH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) request = PTRACE_DETACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) ret = ptrace_request(child, request, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) asmlinkage int syscall_trace(struct pt_regs *regs, int syscall_exit_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (test_thread_flag(TIF_SYSCALL_TRACE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (syscall_exit_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) tracehook_report_syscall_exit(regs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ret = tracehook_report_syscall_entry(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }