18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * OpenRISC Linux 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Linux architectural port borrowing liberally from similar works of 68c2ecf20Sopenharmony_ci * others. All original copyrights apply as per the original source 78c2ecf20Sopenharmony_ci * declaration. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * OpenRISC implementation: 108c2ecf20Sopenharmony_ci * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> 118c2ecf20Sopenharmony_ci * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> 128c2ecf20Sopenharmony_ci * et al. 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci#ifndef __ASM_OPENRISC_PTRACE_H 158c2ecf20Sopenharmony_ci#define __ASM_OPENRISC_PTRACE_H 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <asm/spr_defs.h> 198c2ecf20Sopenharmony_ci#include <uapi/asm/ptrace.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* 228c2ecf20Sopenharmony_ci * Make kernel PTrace/register structures opaque to userspace... userspace can 238c2ecf20Sopenharmony_ci * access thread state via the regset mechanism. This allows us a bit of 248c2ecf20Sopenharmony_ci * flexibility in how we order the registers on the stack, permitting some 258c2ecf20Sopenharmony_ci * optimizations like packing call-clobbered registers together so that 268c2ecf20Sopenharmony_ci * they share a cacheline (not done yet, though... future optimization). 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * This struct describes how the registers are laid out on the kernel stack 328c2ecf20Sopenharmony_ci * during a syscall or other kernel entry. 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * This structure should always be cacheline aligned on the stack. 358c2ecf20Sopenharmony_ci * FIXME: I don't think that's the case right now. The alignment is 368c2ecf20Sopenharmony_ci * taken care of elsewhere... head.S, process.c, etc. 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistruct pt_regs { 408c2ecf20Sopenharmony_ci union { 418c2ecf20Sopenharmony_ci struct { 428c2ecf20Sopenharmony_ci /* Named registers */ 438c2ecf20Sopenharmony_ci long sr; /* Stored in place of r0 */ 448c2ecf20Sopenharmony_ci long sp; /* r1 */ 458c2ecf20Sopenharmony_ci }; 468c2ecf20Sopenharmony_ci struct { 478c2ecf20Sopenharmony_ci /* Old style */ 488c2ecf20Sopenharmony_ci long offset[2]; 498c2ecf20Sopenharmony_ci long gprs[30]; 508c2ecf20Sopenharmony_ci }; 518c2ecf20Sopenharmony_ci struct { 528c2ecf20Sopenharmony_ci /* New style */ 538c2ecf20Sopenharmony_ci long gpr[32]; 548c2ecf20Sopenharmony_ci }; 558c2ecf20Sopenharmony_ci }; 568c2ecf20Sopenharmony_ci long pc; 578c2ecf20Sopenharmony_ci /* For restarting system calls: 588c2ecf20Sopenharmony_ci * Set to syscall number for syscall exceptions, 598c2ecf20Sopenharmony_ci * -1 for all other exceptions. 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_ci long orig_gpr11; /* For restarting system calls */ 628c2ecf20Sopenharmony_ci long dummy; /* Cheap alignment fix */ 638c2ecf20Sopenharmony_ci long dummy2; /* Cheap alignment fix */ 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* TODO: Rename this to REDZONE because that's what it is */ 678c2ecf20Sopenharmony_ci#define STACK_FRAME_OVERHEAD 128 /* size of minimum stack frame */ 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define instruction_pointer(regs) ((regs)->pc) 708c2ecf20Sopenharmony_ci#define user_mode(regs) (((regs)->sr & SPR_SR_SM) == 0) 718c2ecf20Sopenharmony_ci#define user_stack_pointer(regs) ((unsigned long)(regs)->sp) 728c2ecf20Sopenharmony_ci#define profile_pc(regs) instruction_pointer(regs) 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic inline long regs_return_value(struct pt_regs *regs) 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci return regs->gpr[11]; 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/* 828c2ecf20Sopenharmony_ci * Offsets used by 'ptrace' system call interface. 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_ci#define PT_SR 0 858c2ecf20Sopenharmony_ci#define PT_SP 4 868c2ecf20Sopenharmony_ci#define PT_GPR2 8 878c2ecf20Sopenharmony_ci#define PT_GPR3 12 888c2ecf20Sopenharmony_ci#define PT_GPR4 16 898c2ecf20Sopenharmony_ci#define PT_GPR5 20 908c2ecf20Sopenharmony_ci#define PT_GPR6 24 918c2ecf20Sopenharmony_ci#define PT_GPR7 28 928c2ecf20Sopenharmony_ci#define PT_GPR8 32 938c2ecf20Sopenharmony_ci#define PT_GPR9 36 948c2ecf20Sopenharmony_ci#define PT_GPR10 40 958c2ecf20Sopenharmony_ci#define PT_GPR11 44 968c2ecf20Sopenharmony_ci#define PT_GPR12 48 978c2ecf20Sopenharmony_ci#define PT_GPR13 52 988c2ecf20Sopenharmony_ci#define PT_GPR14 56 998c2ecf20Sopenharmony_ci#define PT_GPR15 60 1008c2ecf20Sopenharmony_ci#define PT_GPR16 64 1018c2ecf20Sopenharmony_ci#define PT_GPR17 68 1028c2ecf20Sopenharmony_ci#define PT_GPR18 72 1038c2ecf20Sopenharmony_ci#define PT_GPR19 76 1048c2ecf20Sopenharmony_ci#define PT_GPR20 80 1058c2ecf20Sopenharmony_ci#define PT_GPR21 84 1068c2ecf20Sopenharmony_ci#define PT_GPR22 88 1078c2ecf20Sopenharmony_ci#define PT_GPR23 92 1088c2ecf20Sopenharmony_ci#define PT_GPR24 96 1098c2ecf20Sopenharmony_ci#define PT_GPR25 100 1108c2ecf20Sopenharmony_ci#define PT_GPR26 104 1118c2ecf20Sopenharmony_ci#define PT_GPR27 108 1128c2ecf20Sopenharmony_ci#define PT_GPR28 112 1138c2ecf20Sopenharmony_ci#define PT_GPR29 116 1148c2ecf20Sopenharmony_ci#define PT_GPR30 120 1158c2ecf20Sopenharmony_ci#define PT_GPR31 124 1168c2ecf20Sopenharmony_ci#define PT_PC 128 1178c2ecf20Sopenharmony_ci#define PT_ORIG_GPR11 132 1188c2ecf20Sopenharmony_ci#define PT_SYSCALLNO 136 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#endif /* __ASM_OPENRISC_PTRACE_H */ 121