xref: /openbmc/linux/arch/arc/include/asm/ptrace.h (revision 502a0c77)
1 /*
2  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * Amit Bhor, Sameer Dhavale: Codito Technologies 2004
9  */
10 #ifndef __ASM_ARC_PTRACE_H
11 #define __ASM_ARC_PTRACE_H
12 
13 #include <uapi/asm/ptrace.h>
14 
15 #ifndef __ASSEMBLY__
16 
17 /* THE pt_regs: Defines how regs are saved during entry into kernel */
18 
19 struct pt_regs {
20 
21 	/* Real registers */
22 	long bta;	/* bta_l1, bta_l2, erbta */
23 	long lp_start;
24 	long lp_end;
25 	long lp_count;
26 	long status32;	/* status32_l1, status32_l2, erstatus */
27 	long ret;	/* ilink1, ilink2 or eret */
28 	long blink;
29 	long fp;
30 	long r26;	/* gp */
31 	long r12;
32 	long r11;
33 	long r10;
34 	long r9;
35 	long r8;
36 	long r7;
37 	long r6;
38 	long r5;
39 	long r4;
40 	long r3;
41 	long r2;
42 	long r1;
43 	long r0;
44 	long sp;	/* user/kernel sp depending on where we came from  */
45 	long orig_r0;
46 
47 	/*
48 	 * To distinguish bet excp, syscall, irq
49 	 * For traps and exceptions, Exception Cause Register.
50 	 * 	ECR: <00> <VV> <CC> <PP>
51 	 * 	Last word used by Linux for extra state mgmt (syscall-restart)
52 	 * For interrupts, use artificial ECR values to note current prio-level
53 	 */
54 	union {
55 		struct {
56 #ifdef CONFIG_CPU_BIG_ENDIAN
57 			unsigned long state:8, ecr_vec:8,
58 				      ecr_cause:8, ecr_param:8;
59 #else
60 			unsigned long ecr_param:8, ecr_cause:8,
61 				      ecr_vec:8, state:8;
62 #endif
63 		};
64 		unsigned long event;
65 	};
66 
67 	long user_r25;
68 };
69 
70 /* Callee saved registers - need to be saved only when you are scheduled out */
71 
72 struct callee_regs {
73 	long r25;
74 	long r24;
75 	long r23;
76 	long r22;
77 	long r21;
78 	long r20;
79 	long r19;
80 	long r18;
81 	long r17;
82 	long r16;
83 	long r15;
84 	long r14;
85 	long r13;
86 };
87 
88 #define instruction_pointer(regs)	((regs)->ret)
89 #define profile_pc(regs)		instruction_pointer(regs)
90 
91 /* return 1 if user mode or 0 if kernel mode */
92 #define user_mode(regs) (regs->status32 & STATUS_U_MASK)
93 
94 #define user_stack_pointer(regs)\
95 ({  unsigned int sp;		\
96 	if (user_mode(regs))	\
97 		sp = (regs)->sp;\
98 	else			\
99 		sp = -1;	\
100 	sp;			\
101 })
102 
103 /* return 1 if PC in delay slot */
104 #define delay_mode(regs) ((regs->status32 & STATUS_DE_MASK) == STATUS_DE_MASK)
105 
106 #define in_syscall(regs)    ((regs->ecr_vec == ECR_V_TRAP) && !regs->ecr_param)
107 #define in_brkpt_trap(regs) ((regs->ecr_vec == ECR_V_TRAP) && regs->ecr_param)
108 
109 #define STATE_SCALL_RESTARTED	0x01
110 
111 #define syscall_wont_restart(reg) (reg->state |= STATE_SCALL_RESTARTED)
112 #define syscall_restartable(reg) !(reg->state &  STATE_SCALL_RESTARTED)
113 
114 #define current_pt_regs()					\
115 ({								\
116 	/* open-coded current_thread_info() */			\
117 	register unsigned long sp asm ("sp");			\
118 	unsigned long pg_start = (sp & ~(THREAD_SIZE - 1));	\
119 	(struct pt_regs *)(pg_start + THREAD_SIZE) - 1;	\
120 })
121 
122 static inline long regs_return_value(struct pt_regs *regs)
123 {
124 	return regs->r0;
125 }
126 
127 #endif /* !__ASSEMBLY__ */
128 
129 #endif /* __ASM_PTRACE_H */
130