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