xref: /openbmc/linux/arch/arc/include/asm/ptrace.h (revision 16f9afe6)
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 	/*to distinguish bet excp, syscall, irq */
48 	union {
49 #ifdef CONFIG_CPU_BIG_ENDIAN
50 		/* so that assembly code is same for LE/BE */
51 		unsigned long orig_r8:16, event:16;
52 #else
53 		unsigned long event:16, orig_r8:16;
54 #endif
55 		long orig_r8_word;
56 	};
57 };
58 
59 /* Callee saved registers - need to be saved only when you are scheduled out */
60 
61 struct callee_regs {
62 	long r25;
63 	long r24;
64 	long r23;
65 	long r22;
66 	long r21;
67 	long r20;
68 	long r19;
69 	long r18;
70 	long r17;
71 	long r16;
72 	long r15;
73 	long r14;
74 	long r13;
75 };
76 
77 #define instruction_pointer(regs)	((regs)->ret)
78 #define profile_pc(regs)		instruction_pointer(regs)
79 
80 /* return 1 if user mode or 0 if kernel mode */
81 #define user_mode(regs) (regs->status32 & STATUS_U_MASK)
82 
83 #define user_stack_pointer(regs)\
84 ({  unsigned int sp;		\
85 	if (user_mode(regs))	\
86 		sp = (regs)->sp;\
87 	else			\
88 		sp = -1;	\
89 	sp;			\
90 })
91 
92 /* return 1 if PC in delay slot */
93 #define delay_mode(regs) ((regs->status32 & STATUS_DE_MASK) == STATUS_DE_MASK)
94 
95 #define in_syscall(regs)    (regs->event & orig_r8_IS_SCALL)
96 #define in_brkpt_trap(regs) (regs->event & orig_r8_IS_BRKPT)
97 
98 #define syscall_wont_restart(regs) (regs->event |= orig_r8_IS_SCALL_RESTARTED)
99 #define syscall_restartable(regs) !(regs->event &  orig_r8_IS_SCALL_RESTARTED)
100 
101 #define current_pt_regs()					\
102 ({								\
103 	/* open-coded current_thread_info() */			\
104 	register unsigned long sp asm ("sp");			\
105 	unsigned long pg_start = (sp & ~(THREAD_SIZE - 1));	\
106 	(struct pt_regs *)(pg_start + THREAD_SIZE) - 1;	\
107 })
108 
109 static inline long regs_return_value(struct pt_regs *regs)
110 {
111 	return regs->r0;
112 }
113 
114 #endif /* !__ASSEMBLY__ */
115 
116 #define orig_r8_IS_SCALL		0x0001
117 #define orig_r8_IS_SCALL_RESTARTED	0x0002
118 #define orig_r8_IS_BRKPT		0x0004
119 #define orig_r8_IS_EXCPN		0x0008
120 #define orig_r8_IS_IRQ1			0x0010
121 #define orig_r8_IS_IRQ2			0x0020
122 
123 #endif /* __ASM_PTRACE_H */
124