xref: /openbmc/linux/arch/riscv/kernel/asm-offsets.c (revision 4bb1eb3c)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2012 Regents of the University of California
4  * Copyright (C) 2017 SiFive
5  */
6 
7 #define GENERATING_ASM_OFFSETS
8 
9 #include <linux/kbuild.h>
10 #include <linux/sched.h>
11 #include <asm/thread_info.h>
12 #include <asm/ptrace.h>
13 
14 void asm_offsets(void)
15 {
16 	OFFSET(TASK_THREAD_RA, task_struct, thread.ra);
17 	OFFSET(TASK_THREAD_SP, task_struct, thread.sp);
18 	OFFSET(TASK_THREAD_S0, task_struct, thread.s[0]);
19 	OFFSET(TASK_THREAD_S1, task_struct, thread.s[1]);
20 	OFFSET(TASK_THREAD_S2, task_struct, thread.s[2]);
21 	OFFSET(TASK_THREAD_S3, task_struct, thread.s[3]);
22 	OFFSET(TASK_THREAD_S4, task_struct, thread.s[4]);
23 	OFFSET(TASK_THREAD_S5, task_struct, thread.s[5]);
24 	OFFSET(TASK_THREAD_S6, task_struct, thread.s[6]);
25 	OFFSET(TASK_THREAD_S7, task_struct, thread.s[7]);
26 	OFFSET(TASK_THREAD_S8, task_struct, thread.s[8]);
27 	OFFSET(TASK_THREAD_S9, task_struct, thread.s[9]);
28 	OFFSET(TASK_THREAD_S10, task_struct, thread.s[10]);
29 	OFFSET(TASK_THREAD_S11, task_struct, thread.s[11]);
30 	OFFSET(TASK_TI_FLAGS, task_struct, thread_info.flags);
31 	OFFSET(TASK_TI_PREEMPT_COUNT, task_struct, thread_info.preempt_count);
32 	OFFSET(TASK_TI_KERNEL_SP, task_struct, thread_info.kernel_sp);
33 	OFFSET(TASK_TI_USER_SP, task_struct, thread_info.user_sp);
34 	OFFSET(TASK_TI_CPU, task_struct, thread_info.cpu);
35 
36 	OFFSET(TASK_THREAD_F0,  task_struct, thread.fstate.f[0]);
37 	OFFSET(TASK_THREAD_F1,  task_struct, thread.fstate.f[1]);
38 	OFFSET(TASK_THREAD_F2,  task_struct, thread.fstate.f[2]);
39 	OFFSET(TASK_THREAD_F3,  task_struct, thread.fstate.f[3]);
40 	OFFSET(TASK_THREAD_F4,  task_struct, thread.fstate.f[4]);
41 	OFFSET(TASK_THREAD_F5,  task_struct, thread.fstate.f[5]);
42 	OFFSET(TASK_THREAD_F6,  task_struct, thread.fstate.f[6]);
43 	OFFSET(TASK_THREAD_F7,  task_struct, thread.fstate.f[7]);
44 	OFFSET(TASK_THREAD_F8,  task_struct, thread.fstate.f[8]);
45 	OFFSET(TASK_THREAD_F9,  task_struct, thread.fstate.f[9]);
46 	OFFSET(TASK_THREAD_F10, task_struct, thread.fstate.f[10]);
47 	OFFSET(TASK_THREAD_F11, task_struct, thread.fstate.f[11]);
48 	OFFSET(TASK_THREAD_F12, task_struct, thread.fstate.f[12]);
49 	OFFSET(TASK_THREAD_F13, task_struct, thread.fstate.f[13]);
50 	OFFSET(TASK_THREAD_F14, task_struct, thread.fstate.f[14]);
51 	OFFSET(TASK_THREAD_F15, task_struct, thread.fstate.f[15]);
52 	OFFSET(TASK_THREAD_F16, task_struct, thread.fstate.f[16]);
53 	OFFSET(TASK_THREAD_F17, task_struct, thread.fstate.f[17]);
54 	OFFSET(TASK_THREAD_F18, task_struct, thread.fstate.f[18]);
55 	OFFSET(TASK_THREAD_F19, task_struct, thread.fstate.f[19]);
56 	OFFSET(TASK_THREAD_F20, task_struct, thread.fstate.f[20]);
57 	OFFSET(TASK_THREAD_F21, task_struct, thread.fstate.f[21]);
58 	OFFSET(TASK_THREAD_F22, task_struct, thread.fstate.f[22]);
59 	OFFSET(TASK_THREAD_F23, task_struct, thread.fstate.f[23]);
60 	OFFSET(TASK_THREAD_F24, task_struct, thread.fstate.f[24]);
61 	OFFSET(TASK_THREAD_F25, task_struct, thread.fstate.f[25]);
62 	OFFSET(TASK_THREAD_F26, task_struct, thread.fstate.f[26]);
63 	OFFSET(TASK_THREAD_F27, task_struct, thread.fstate.f[27]);
64 	OFFSET(TASK_THREAD_F28, task_struct, thread.fstate.f[28]);
65 	OFFSET(TASK_THREAD_F29, task_struct, thread.fstate.f[29]);
66 	OFFSET(TASK_THREAD_F30, task_struct, thread.fstate.f[30]);
67 	OFFSET(TASK_THREAD_F31, task_struct, thread.fstate.f[31]);
68 	OFFSET(TASK_THREAD_FCSR, task_struct, thread.fstate.fcsr);
69 
70 	DEFINE(PT_SIZE, sizeof(struct pt_regs));
71 	OFFSET(PT_EPC, pt_regs, epc);
72 	OFFSET(PT_RA, pt_regs, ra);
73 	OFFSET(PT_FP, pt_regs, s0);
74 	OFFSET(PT_S0, pt_regs, s0);
75 	OFFSET(PT_S1, pt_regs, s1);
76 	OFFSET(PT_S2, pt_regs, s2);
77 	OFFSET(PT_S3, pt_regs, s3);
78 	OFFSET(PT_S4, pt_regs, s4);
79 	OFFSET(PT_S5, pt_regs, s5);
80 	OFFSET(PT_S6, pt_regs, s6);
81 	OFFSET(PT_S7, pt_regs, s7);
82 	OFFSET(PT_S8, pt_regs, s8);
83 	OFFSET(PT_S9, pt_regs, s9);
84 	OFFSET(PT_S10, pt_regs, s10);
85 	OFFSET(PT_S11, pt_regs, s11);
86 	OFFSET(PT_SP, pt_regs, sp);
87 	OFFSET(PT_TP, pt_regs, tp);
88 	OFFSET(PT_A0, pt_regs, a0);
89 	OFFSET(PT_A1, pt_regs, a1);
90 	OFFSET(PT_A2, pt_regs, a2);
91 	OFFSET(PT_A3, pt_regs, a3);
92 	OFFSET(PT_A4, pt_regs, a4);
93 	OFFSET(PT_A5, pt_regs, a5);
94 	OFFSET(PT_A6, pt_regs, a6);
95 	OFFSET(PT_A7, pt_regs, a7);
96 	OFFSET(PT_T0, pt_regs, t0);
97 	OFFSET(PT_T1, pt_regs, t1);
98 	OFFSET(PT_T2, pt_regs, t2);
99 	OFFSET(PT_T3, pt_regs, t3);
100 	OFFSET(PT_T4, pt_regs, t4);
101 	OFFSET(PT_T5, pt_regs, t5);
102 	OFFSET(PT_T6, pt_regs, t6);
103 	OFFSET(PT_GP, pt_regs, gp);
104 	OFFSET(PT_ORIG_A0, pt_regs, orig_a0);
105 	OFFSET(PT_STATUS, pt_regs, status);
106 	OFFSET(PT_BADADDR, pt_regs, badaddr);
107 	OFFSET(PT_CAUSE, pt_regs, cause);
108 
109 	/*
110 	 * THREAD_{F,X}* might be larger than a S-type offset can handle, but
111 	 * these are used in performance-sensitive assembly so we can't resort
112 	 * to loading the long immediate every time.
113 	 */
114 	DEFINE(TASK_THREAD_RA_RA,
115 		  offsetof(struct task_struct, thread.ra)
116 		- offsetof(struct task_struct, thread.ra)
117 	);
118 	DEFINE(TASK_THREAD_SP_RA,
119 		  offsetof(struct task_struct, thread.sp)
120 		- offsetof(struct task_struct, thread.ra)
121 	);
122 	DEFINE(TASK_THREAD_S0_RA,
123 		  offsetof(struct task_struct, thread.s[0])
124 		- offsetof(struct task_struct, thread.ra)
125 	);
126 	DEFINE(TASK_THREAD_S1_RA,
127 		  offsetof(struct task_struct, thread.s[1])
128 		- offsetof(struct task_struct, thread.ra)
129 	);
130 	DEFINE(TASK_THREAD_S2_RA,
131 		  offsetof(struct task_struct, thread.s[2])
132 		- offsetof(struct task_struct, thread.ra)
133 	);
134 	DEFINE(TASK_THREAD_S3_RA,
135 		  offsetof(struct task_struct, thread.s[3])
136 		- offsetof(struct task_struct, thread.ra)
137 	);
138 	DEFINE(TASK_THREAD_S4_RA,
139 		  offsetof(struct task_struct, thread.s[4])
140 		- offsetof(struct task_struct, thread.ra)
141 	);
142 	DEFINE(TASK_THREAD_S5_RA,
143 		  offsetof(struct task_struct, thread.s[5])
144 		- offsetof(struct task_struct, thread.ra)
145 	);
146 	DEFINE(TASK_THREAD_S6_RA,
147 		  offsetof(struct task_struct, thread.s[6])
148 		- offsetof(struct task_struct, thread.ra)
149 	);
150 	DEFINE(TASK_THREAD_S7_RA,
151 		  offsetof(struct task_struct, thread.s[7])
152 		- offsetof(struct task_struct, thread.ra)
153 	);
154 	DEFINE(TASK_THREAD_S8_RA,
155 		  offsetof(struct task_struct, thread.s[8])
156 		- offsetof(struct task_struct, thread.ra)
157 	);
158 	DEFINE(TASK_THREAD_S9_RA,
159 		  offsetof(struct task_struct, thread.s[9])
160 		- offsetof(struct task_struct, thread.ra)
161 	);
162 	DEFINE(TASK_THREAD_S10_RA,
163 		  offsetof(struct task_struct, thread.s[10])
164 		- offsetof(struct task_struct, thread.ra)
165 	);
166 	DEFINE(TASK_THREAD_S11_RA,
167 		  offsetof(struct task_struct, thread.s[11])
168 		- offsetof(struct task_struct, thread.ra)
169 	);
170 
171 	DEFINE(TASK_THREAD_F0_F0,
172 		  offsetof(struct task_struct, thread.fstate.f[0])
173 		- offsetof(struct task_struct, thread.fstate.f[0])
174 	);
175 	DEFINE(TASK_THREAD_F1_F0,
176 		  offsetof(struct task_struct, thread.fstate.f[1])
177 		- offsetof(struct task_struct, thread.fstate.f[0])
178 	);
179 	DEFINE(TASK_THREAD_F2_F0,
180 		  offsetof(struct task_struct, thread.fstate.f[2])
181 		- offsetof(struct task_struct, thread.fstate.f[0])
182 	);
183 	DEFINE(TASK_THREAD_F3_F0,
184 		  offsetof(struct task_struct, thread.fstate.f[3])
185 		- offsetof(struct task_struct, thread.fstate.f[0])
186 	);
187 	DEFINE(TASK_THREAD_F4_F0,
188 		  offsetof(struct task_struct, thread.fstate.f[4])
189 		- offsetof(struct task_struct, thread.fstate.f[0])
190 	);
191 	DEFINE(TASK_THREAD_F5_F0,
192 		  offsetof(struct task_struct, thread.fstate.f[5])
193 		- offsetof(struct task_struct, thread.fstate.f[0])
194 	);
195 	DEFINE(TASK_THREAD_F6_F0,
196 		  offsetof(struct task_struct, thread.fstate.f[6])
197 		- offsetof(struct task_struct, thread.fstate.f[0])
198 	);
199 	DEFINE(TASK_THREAD_F7_F0,
200 		  offsetof(struct task_struct, thread.fstate.f[7])
201 		- offsetof(struct task_struct, thread.fstate.f[0])
202 	);
203 	DEFINE(TASK_THREAD_F8_F0,
204 		  offsetof(struct task_struct, thread.fstate.f[8])
205 		- offsetof(struct task_struct, thread.fstate.f[0])
206 	);
207 	DEFINE(TASK_THREAD_F9_F0,
208 		  offsetof(struct task_struct, thread.fstate.f[9])
209 		- offsetof(struct task_struct, thread.fstate.f[0])
210 	);
211 	DEFINE(TASK_THREAD_F10_F0,
212 		  offsetof(struct task_struct, thread.fstate.f[10])
213 		- offsetof(struct task_struct, thread.fstate.f[0])
214 	);
215 	DEFINE(TASK_THREAD_F11_F0,
216 		  offsetof(struct task_struct, thread.fstate.f[11])
217 		- offsetof(struct task_struct, thread.fstate.f[0])
218 	);
219 	DEFINE(TASK_THREAD_F12_F0,
220 		  offsetof(struct task_struct, thread.fstate.f[12])
221 		- offsetof(struct task_struct, thread.fstate.f[0])
222 	);
223 	DEFINE(TASK_THREAD_F13_F0,
224 		  offsetof(struct task_struct, thread.fstate.f[13])
225 		- offsetof(struct task_struct, thread.fstate.f[0])
226 	);
227 	DEFINE(TASK_THREAD_F14_F0,
228 		  offsetof(struct task_struct, thread.fstate.f[14])
229 		- offsetof(struct task_struct, thread.fstate.f[0])
230 	);
231 	DEFINE(TASK_THREAD_F15_F0,
232 		  offsetof(struct task_struct, thread.fstate.f[15])
233 		- offsetof(struct task_struct, thread.fstate.f[0])
234 	);
235 	DEFINE(TASK_THREAD_F16_F0,
236 		  offsetof(struct task_struct, thread.fstate.f[16])
237 		- offsetof(struct task_struct, thread.fstate.f[0])
238 	);
239 	DEFINE(TASK_THREAD_F17_F0,
240 		  offsetof(struct task_struct, thread.fstate.f[17])
241 		- offsetof(struct task_struct, thread.fstate.f[0])
242 	);
243 	DEFINE(TASK_THREAD_F18_F0,
244 		  offsetof(struct task_struct, thread.fstate.f[18])
245 		- offsetof(struct task_struct, thread.fstate.f[0])
246 	);
247 	DEFINE(TASK_THREAD_F19_F0,
248 		  offsetof(struct task_struct, thread.fstate.f[19])
249 		- offsetof(struct task_struct, thread.fstate.f[0])
250 	);
251 	DEFINE(TASK_THREAD_F20_F0,
252 		  offsetof(struct task_struct, thread.fstate.f[20])
253 		- offsetof(struct task_struct, thread.fstate.f[0])
254 	);
255 	DEFINE(TASK_THREAD_F21_F0,
256 		  offsetof(struct task_struct, thread.fstate.f[21])
257 		- offsetof(struct task_struct, thread.fstate.f[0])
258 	);
259 	DEFINE(TASK_THREAD_F22_F0,
260 		  offsetof(struct task_struct, thread.fstate.f[22])
261 		- offsetof(struct task_struct, thread.fstate.f[0])
262 	);
263 	DEFINE(TASK_THREAD_F23_F0,
264 		  offsetof(struct task_struct, thread.fstate.f[23])
265 		- offsetof(struct task_struct, thread.fstate.f[0])
266 	);
267 	DEFINE(TASK_THREAD_F24_F0,
268 		  offsetof(struct task_struct, thread.fstate.f[24])
269 		- offsetof(struct task_struct, thread.fstate.f[0])
270 	);
271 	DEFINE(TASK_THREAD_F25_F0,
272 		  offsetof(struct task_struct, thread.fstate.f[25])
273 		- offsetof(struct task_struct, thread.fstate.f[0])
274 	);
275 	DEFINE(TASK_THREAD_F26_F0,
276 		  offsetof(struct task_struct, thread.fstate.f[26])
277 		- offsetof(struct task_struct, thread.fstate.f[0])
278 	);
279 	DEFINE(TASK_THREAD_F27_F0,
280 		  offsetof(struct task_struct, thread.fstate.f[27])
281 		- offsetof(struct task_struct, thread.fstate.f[0])
282 	);
283 	DEFINE(TASK_THREAD_F28_F0,
284 		  offsetof(struct task_struct, thread.fstate.f[28])
285 		- offsetof(struct task_struct, thread.fstate.f[0])
286 	);
287 	DEFINE(TASK_THREAD_F29_F0,
288 		  offsetof(struct task_struct, thread.fstate.f[29])
289 		- offsetof(struct task_struct, thread.fstate.f[0])
290 	);
291 	DEFINE(TASK_THREAD_F30_F0,
292 		  offsetof(struct task_struct, thread.fstate.f[30])
293 		- offsetof(struct task_struct, thread.fstate.f[0])
294 	);
295 	DEFINE(TASK_THREAD_F31_F0,
296 		  offsetof(struct task_struct, thread.fstate.f[31])
297 		- offsetof(struct task_struct, thread.fstate.f[0])
298 	);
299 	DEFINE(TASK_THREAD_FCSR_F0,
300 		  offsetof(struct task_struct, thread.fstate.fcsr)
301 		- offsetof(struct task_struct, thread.fstate.f[0])
302 	);
303 
304 	/*
305 	 * We allocate a pt_regs on the stack when entering the kernel.  This
306 	 * ensures the alignment is sane.
307 	 */
308 	DEFINE(PT_SIZE_ON_STACK, ALIGN(sizeof(struct pt_regs), STACK_ALIGN));
309 }
310