1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef _CPU_H
6#define _CPU_H
7
8#if defined(__i386__) || defined(__x86_64__)
9#include <sys/user.h>
10#include <sys/reg.h>
11typedef struct user_regs_struct USER_REGS;
12typedef struct user_fpregs_struct USER_FPREGS;
13
14#if defined(__i386__)
15#define SYSCALL_NUMBER_INDEX ORIG_EAX
16#define SYSCALL_RESULT_INDEX EAX
17#define STACK_POINTER(regs) regs.esp
18
19#elif defined(__x86_64__)
20#define SYSCALL_NUMBER_INDEX ORIG_RAX
21#define SYSCALL_RESULT_INDEX RAX
22#define STACK_POINTER(regs) regs.rsp
23#endif
24
25#elif defined(__arm__) || defined(__aarch64__)
26typedef struct tagUSER_REGS {
27 unsigned long x0;
28 unsigned long x1;
29 unsigned long x2;
30 unsigned long x3;
31 unsigned long x4;
32 unsigned long x5;
33 unsigned long x6;
34 unsigned long x7;
35 unsigned long x8;
36 unsigned long x9;
37 unsigned long x10;
38 unsigned long x11;
39 unsigned long x12;
40 unsigned long x13;
41 unsigned long x14;
42 unsigned long x15;
43 unsigned long x16;
44 unsigned long x17;
45 unsigned long x18;
46 unsigned long x19;
47 unsigned long x20;
48 unsigned long x21;
49 unsigned long x22;
50 unsigned long x23;
51 unsigned long x24;
52 unsigned long x25;
53 unsigned long x26;
54 unsigned long x27;
55 unsigned long x28;
56 unsigned long x29;
57 unsigned long ra; //x30;
58 unsigned long sp;
59 unsigned long pc;
60 unsigned long pstate;
61 /*unsigned long orig_x0;
62 unsigned long syscallno;
63 unsigned long orig_addr_limit;
64 unsigned long unused; // maintain 16 byte alignment
65 */
66}USER_REGS;
67
68typedef struct tagUSER_FPREGS {
69 long fpregs[66];
70}USER_FPREGS;
71
72#define SYSCALL_NUMBER_INDEX 8 /*$x8 register*/
73#define SYSCALL_RESULT_INDEX 0 /*$x0 register*/
74#define STACK_POINTER(regs) regs.sp
75
76#elif defined(__mips__) || defined(__mips64)
77
78#define DT_MIPS_RLD_MAP_REL 0x70000035
79
80typedef struct tagUSER_REGS {
81 long zero;//$0 /* wired zero */
82 long at;//$1 /* assembler temp - uppercase because of ".set at" */
83 long v0;//$2 /* return value */
84 long v1;//$3
85 long a0;//$4 /* argument registers */
86 long a1;//$5
87 long a2;//$6
88 long a3;//$7
89
90#if _MIPS_SIM != _ABIO32
91 long a4;//$8
92 long a5;//$9
93 long a6;//$10
94 long a7;//$11
95 long t0;//$12
96 long t1;//$13
97 long t2;//$14
98 long t3;//$15
99#else /* if _MIPS_SIM == _ABIO32 */
100 long t0;//$8 /* caller saved */
101 long t1;//$9
102 long t2;//$10
103 long t3;//$11
104 long t4;//$12
105 long t5;//$13
106 long t6;//$14
107 long t7;//$15
108#endif /* _MIPS_SIM == _ABIO32 */
109 long s0;//$16 /* callee saved */
110 long s1;//$17
111 long s2;//$18
112 long s3;//$19
113 long s4;//$20
114 long s5;//$21
115 long s6;//$22
116 long s7;//$23
117 long t8;//$24 /* caller saved */
118 long t9;//$25
119 long k0;//$26 /* kernel scratch */
120 long k1;//$27
121 long gp;//$28 /* global pointer */
122 long sp;//$29 /* stack pointer */
123 long fp;//$30 /* frame pointer */
124 long ra;//$31 /* return address */
125
126 /* Saved special registers. */
127 long lo;
128 long hi;
129 long pc; //cp0_epc;
130 long cp0_badvaddr;
131 long cp0_status;
132 long cp0_cause;
133}USER_REGS;
134
135typedef struct tagUSER_FPREGS {
136 long fpregs[33];
137}USER_FPREGS;
138
139#define SYSCALL_NUMBER_INDEX 2 /*$v0 register*/
140#define SYSCALL_RESULT_INDEX 2 /*$v0 register*/
141#define STACK_POINTER(regs) regs.sp
142
143#elif defined(__sw_64)
144// refer to /usr/include/asm/reg.h
145// arch/sw_64/kernel/ptrace.c
146
147typedef struct tagUSER_REGS {
148 unsigned long v0; //r0;
149 unsigned long t0; //r1;
150 unsigned long t1; //r2;
151 unsigned long t2; //r3;
152 unsigned long t3; //r4;
153 unsigned long t4; //r5;
154 unsigned long t5; //r6;
155 unsigned long t6; //r7;
156 unsigned long t7; //r8;
157 unsigned long s0; //r9;
158 unsigned long s1;//r10;
159 unsigned long s2;//r11;
160 unsigned long s3;//r12;
161 unsigned long s4;//r13;
162 unsigned long s5;//r14;
163 unsigned long s6;//r15;
164
165 unsigned long a3; //r19;
166 unsigned long a4; //r20;
167 unsigned long a5; //r21;
168 unsigned long t8; //r22;
169 unsigned long t9; //r23;
170 unsigned long t10;//r24;
171 unsigned long t11;//r25;
172 unsigned long ra; //r26;
173 unsigned long t12;//r27;
174 unsigned long r28;
175
176 unsigned long sp; //r30
177 unsigned long ps; //r27
178 unsigned long pc; //
179 unsigned long gp; //r29
180 unsigned long a0; //r16;
181 unsigned long a1; //r17;
182 unsigned long a2; //r18;
183}USER_REGS;
184
185typedef struct tagUSER_FPREGS {
186 long fpregs[32];
187}USER_FPREGS;
188
189#define SYSCALL_NUMBER_INDEX 0 /*$v0 register*/
190#define SYSCALL_RESULT_INDEX 0 /*$v0 register*/
191#define STACK_POINTER(regs) regs.sp
192
193#else
194#error need to define new SYSCALL_RESULT_INDEX
195#endif
196
197#endif // end #ifndef _CPU_H
198