xref: /openbmc/linux/arch/mips/kernel/asm-offsets.c (revision 3c37026d43c47bec4710cbda286f4a17f416f5e6)
1 /*
2  * offset.c: Calculate pt_regs and task_struct offsets.
3  *
4  * Copyright (C) 1996 David S. Miller
5  * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Ralf Baechle
6  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
7  *
8  * Kevin Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
9  * Copyright (C) 2000 MIPS Technologies, Inc.
10  */
11 #include <linux/config.h>
12 #include <linux/compat.h>
13 #include <linux/types.h>
14 #include <linux/sched.h>
15 #include <linux/mm.h>
16 #include <linux/interrupt.h>
17 
18 #include <asm/ptrace.h>
19 #include <asm/processor.h>
20 
21 #define text(t) __asm__("\n@@@" t)
22 #define _offset(type, member) (&(((type *)NULL)->member))
23 #define offset(string, ptr, member) \
24 	__asm__("\n@@@" string "%0" : : "i" (_offset(ptr, member)))
25 #define constant(string, member) \
26 	__asm__("\n@@@" string "%x0" : : "ri" (member))
27 #define size(string, size) \
28 	__asm__("\n@@@" string "%0" : : "i" (sizeof(size)))
29 #define linefeed text("")
30 
31 void output_ptreg_defines(void)
32 {
33 	text("/* MIPS pt_regs offsets. */");
34 	offset("#define PT_R0     ", struct pt_regs, regs[0]);
35 	offset("#define PT_R1     ", struct pt_regs, regs[1]);
36 	offset("#define PT_R2     ", struct pt_regs, regs[2]);
37 	offset("#define PT_R3     ", struct pt_regs, regs[3]);
38 	offset("#define PT_R4     ", struct pt_regs, regs[4]);
39 	offset("#define PT_R5     ", struct pt_regs, regs[5]);
40 	offset("#define PT_R6     ", struct pt_regs, regs[6]);
41 	offset("#define PT_R7     ", struct pt_regs, regs[7]);
42 	offset("#define PT_R8     ", struct pt_regs, regs[8]);
43 	offset("#define PT_R9     ", struct pt_regs, regs[9]);
44 	offset("#define PT_R10    ", struct pt_regs, regs[10]);
45 	offset("#define PT_R11    ", struct pt_regs, regs[11]);
46 	offset("#define PT_R12    ", struct pt_regs, regs[12]);
47 	offset("#define PT_R13    ", struct pt_regs, regs[13]);
48 	offset("#define PT_R14    ", struct pt_regs, regs[14]);
49 	offset("#define PT_R15    ", struct pt_regs, regs[15]);
50 	offset("#define PT_R16    ", struct pt_regs, regs[16]);
51 	offset("#define PT_R17    ", struct pt_regs, regs[17]);
52 	offset("#define PT_R18    ", struct pt_regs, regs[18]);
53 	offset("#define PT_R19    ", struct pt_regs, regs[19]);
54 	offset("#define PT_R20    ", struct pt_regs, regs[20]);
55 	offset("#define PT_R21    ", struct pt_regs, regs[21]);
56 	offset("#define PT_R22    ", struct pt_regs, regs[22]);
57 	offset("#define PT_R23    ", struct pt_regs, regs[23]);
58 	offset("#define PT_R24    ", struct pt_regs, regs[24]);
59 	offset("#define PT_R25    ", struct pt_regs, regs[25]);
60 	offset("#define PT_R26    ", struct pt_regs, regs[26]);
61 	offset("#define PT_R27    ", struct pt_regs, regs[27]);
62 	offset("#define PT_R28    ", struct pt_regs, regs[28]);
63 	offset("#define PT_R29    ", struct pt_regs, regs[29]);
64 	offset("#define PT_R30    ", struct pt_regs, regs[30]);
65 	offset("#define PT_R31    ", struct pt_regs, regs[31]);
66 	offset("#define PT_LO     ", struct pt_regs, lo);
67 	offset("#define PT_HI     ", struct pt_regs, hi);
68 	offset("#define PT_EPC    ", struct pt_regs, cp0_epc);
69 	offset("#define PT_BVADDR ", struct pt_regs, cp0_badvaddr);
70 	offset("#define PT_STATUS ", struct pt_regs, cp0_status);
71 	offset("#define PT_CAUSE  ", struct pt_regs, cp0_cause);
72 	size("#define PT_SIZE   ", struct pt_regs);
73 	linefeed;
74 }
75 
76 void output_task_defines(void)
77 {
78 	text("/* MIPS task_struct offsets. */");
79 	offset("#define TASK_STATE         ", struct task_struct, state);
80 	offset("#define TASK_THREAD_INFO   ", struct task_struct, thread_info);
81 	offset("#define TASK_FLAGS         ", struct task_struct, flags);
82 	offset("#define TASK_MM            ", struct task_struct, mm);
83 	offset("#define TASK_PID           ", struct task_struct, pid);
84 	size(  "#define TASK_STRUCT_SIZE   ", struct task_struct);
85 	linefeed;
86 }
87 
88 void output_thread_info_defines(void)
89 {
90 	text("/* MIPS thread_info offsets. */");
91 	offset("#define TI_TASK            ", struct thread_info, task);
92 	offset("#define TI_EXEC_DOMAIN     ", struct thread_info, exec_domain);
93 	offset("#define TI_FLAGS           ", struct thread_info, flags);
94 	offset("#define TI_CPU             ", struct thread_info, cpu);
95 	offset("#define TI_PRE_COUNT       ", struct thread_info, preempt_count);
96 	offset("#define TI_ADDR_LIMIT      ", struct thread_info, addr_limit);
97 	offset("#define TI_RESTART_BLOCK   ", struct thread_info, restart_block);
98 	offset("#define TI_TP_VALUE        ", struct thread_info, tp_value);
99 	constant("#define _THREAD_SIZE_ORDER ", THREAD_SIZE_ORDER);
100 	constant("#define _THREAD_SIZE       ", THREAD_SIZE);
101 	constant("#define _THREAD_MASK       ", THREAD_MASK);
102 	linefeed;
103 }
104 
105 void output_thread_defines(void)
106 {
107 	text("/* MIPS specific thread_struct offsets. */");
108 	offset("#define THREAD_REG16   ", struct task_struct, thread.reg16);
109 	offset("#define THREAD_REG17   ", struct task_struct, thread.reg17);
110 	offset("#define THREAD_REG18   ", struct task_struct, thread.reg18);
111 	offset("#define THREAD_REG19   ", struct task_struct, thread.reg19);
112 	offset("#define THREAD_REG20   ", struct task_struct, thread.reg20);
113 	offset("#define THREAD_REG21   ", struct task_struct, thread.reg21);
114 	offset("#define THREAD_REG22   ", struct task_struct, thread.reg22);
115 	offset("#define THREAD_REG23   ", struct task_struct, thread.reg23);
116 	offset("#define THREAD_REG29   ", struct task_struct, thread.reg29);
117 	offset("#define THREAD_REG30   ", struct task_struct, thread.reg30);
118 	offset("#define THREAD_REG31   ", struct task_struct, thread.reg31);
119 	offset("#define THREAD_STATUS  ", struct task_struct,
120 	       thread.cp0_status);
121 	offset("#define THREAD_FPU     ", struct task_struct, thread.fpu);
122 
123 	offset("#define THREAD_BVADDR  ", struct task_struct, \
124 	       thread.cp0_badvaddr);
125 	offset("#define THREAD_BUADDR  ", struct task_struct, \
126 	       thread.cp0_baduaddr);
127 	offset("#define THREAD_ECODE   ", struct task_struct, \
128 	       thread.error_code);
129 	offset("#define THREAD_TRAPNO  ", struct task_struct, thread.trap_no);
130 	offset("#define THREAD_MFLAGS  ", struct task_struct, thread.mflags);
131 	offset("#define THREAD_TRAMP   ", struct task_struct, \
132 	       thread.irix_trampoline);
133 	offset("#define THREAD_OLDCTX  ", struct task_struct, \
134 	       thread.irix_oldctx);
135 	linefeed;
136 }
137 
138 void output_thread_fpu_defines(void)
139 {
140 	offset("#define THREAD_FPR0    ",
141 	       struct task_struct, thread.fpu.hard.fpr[0]);
142 	offset("#define THREAD_FPR1    ",
143 	       struct task_struct, thread.fpu.hard.fpr[1]);
144 	offset("#define THREAD_FPR2    ",
145 	       struct task_struct, thread.fpu.hard.fpr[2]);
146 	offset("#define THREAD_FPR3    ",
147 	       struct task_struct, thread.fpu.hard.fpr[3]);
148 	offset("#define THREAD_FPR4    ",
149 	       struct task_struct, thread.fpu.hard.fpr[4]);
150 	offset("#define THREAD_FPR5    ",
151 	       struct task_struct, thread.fpu.hard.fpr[5]);
152 	offset("#define THREAD_FPR6    ",
153 	       struct task_struct, thread.fpu.hard.fpr[6]);
154 	offset("#define THREAD_FPR7    ",
155 	       struct task_struct, thread.fpu.hard.fpr[7]);
156 	offset("#define THREAD_FPR8    ",
157 	       struct task_struct, thread.fpu.hard.fpr[8]);
158 	offset("#define THREAD_FPR9    ",
159 	       struct task_struct, thread.fpu.hard.fpr[9]);
160 	offset("#define THREAD_FPR10   ",
161 	       struct task_struct, thread.fpu.hard.fpr[10]);
162 	offset("#define THREAD_FPR11   ",
163 	       struct task_struct, thread.fpu.hard.fpr[11]);
164 	offset("#define THREAD_FPR12   ",
165 	       struct task_struct, thread.fpu.hard.fpr[12]);
166 	offset("#define THREAD_FPR13   ",
167 	       struct task_struct, thread.fpu.hard.fpr[13]);
168 	offset("#define THREAD_FPR14   ",
169 	       struct task_struct, thread.fpu.hard.fpr[14]);
170 	offset("#define THREAD_FPR15   ",
171 	       struct task_struct, thread.fpu.hard.fpr[15]);
172 	offset("#define THREAD_FPR16   ",
173 	       struct task_struct, thread.fpu.hard.fpr[16]);
174 	offset("#define THREAD_FPR17   ",
175 	       struct task_struct, thread.fpu.hard.fpr[17]);
176 	offset("#define THREAD_FPR18   ",
177 	       struct task_struct, thread.fpu.hard.fpr[18]);
178 	offset("#define THREAD_FPR19   ",
179 	       struct task_struct, thread.fpu.hard.fpr[19]);
180 	offset("#define THREAD_FPR20   ",
181 	       struct task_struct, thread.fpu.hard.fpr[20]);
182 	offset("#define THREAD_FPR21   ",
183 	       struct task_struct, thread.fpu.hard.fpr[21]);
184 	offset("#define THREAD_FPR22   ",
185 	       struct task_struct, thread.fpu.hard.fpr[22]);
186 	offset("#define THREAD_FPR23   ",
187 	       struct task_struct, thread.fpu.hard.fpr[23]);
188 	offset("#define THREAD_FPR24   ",
189 	       struct task_struct, thread.fpu.hard.fpr[24]);
190 	offset("#define THREAD_FPR25   ",
191 	       struct task_struct, thread.fpu.hard.fpr[25]);
192 	offset("#define THREAD_FPR26   ",
193 	       struct task_struct, thread.fpu.hard.fpr[26]);
194 	offset("#define THREAD_FPR27   ",
195 	       struct task_struct, thread.fpu.hard.fpr[27]);
196 	offset("#define THREAD_FPR28   ",
197 	       struct task_struct, thread.fpu.hard.fpr[28]);
198 	offset("#define THREAD_FPR29   ",
199 	       struct task_struct, thread.fpu.hard.fpr[29]);
200 	offset("#define THREAD_FPR30   ",
201 	       struct task_struct, thread.fpu.hard.fpr[30]);
202 	offset("#define THREAD_FPR31   ",
203 	       struct task_struct, thread.fpu.hard.fpr[31]);
204 
205 	offset("#define THREAD_FCR31   ",
206 	       struct task_struct, thread.fpu.hard.fcr31);
207 	linefeed;
208 }
209 
210 void output_mm_defines(void)
211 {
212 	text("/* Size of struct page  */");
213 	size("#define STRUCT_PAGE_SIZE   ", struct page);
214 	linefeed;
215 	text("/* Linux mm_struct offsets. */");
216 	offset("#define MM_USERS      ", struct mm_struct, mm_users);
217 	offset("#define MM_PGD        ", struct mm_struct, pgd);
218 	offset("#define MM_CONTEXT    ", struct mm_struct, context);
219 	linefeed;
220 	constant("#define _PAGE_SIZE     ", PAGE_SIZE);
221 	constant("#define _PAGE_SHIFT    ", PAGE_SHIFT);
222 	linefeed;
223 	constant("#define _PGD_T_SIZE    ", sizeof(pgd_t));
224 	constant("#define _PMD_T_SIZE    ", sizeof(pmd_t));
225 	constant("#define _PTE_T_SIZE    ", sizeof(pte_t));
226 	linefeed;
227 	constant("#define _PGD_T_LOG2    ", PGD_T_LOG2);
228 	constant("#define _PMD_T_LOG2    ", PMD_T_LOG2);
229 	constant("#define _PTE_T_LOG2    ", PTE_T_LOG2);
230 	linefeed;
231 	constant("#define _PMD_SHIFT     ", PMD_SHIFT);
232 	constant("#define _PGDIR_SHIFT   ", PGDIR_SHIFT);
233 	linefeed;
234 	constant("#define _PGD_ORDER     ", PGD_ORDER);
235 	constant("#define _PMD_ORDER     ", PMD_ORDER);
236 	constant("#define _PTE_ORDER     ", PTE_ORDER);
237 	linefeed;
238 	constant("#define _PTRS_PER_PGD  ", PTRS_PER_PGD);
239 	constant("#define _PTRS_PER_PMD  ", PTRS_PER_PMD);
240 	constant("#define _PTRS_PER_PTE  ", PTRS_PER_PTE);
241 	linefeed;
242 }
243 
244 void output_sc_defines(void)
245 {
246 	text("/* Linux sigcontext offsets. */");
247 	offset("#define SC_REGS       ", struct sigcontext, sc_regs);
248 	offset("#define SC_FPREGS     ", struct sigcontext, sc_fpregs);
249 	offset("#define SC_MDHI       ", struct sigcontext, sc_mdhi);
250 	offset("#define SC_MDLO       ", struct sigcontext, sc_mdlo);
251 	offset("#define SC_PC         ", struct sigcontext, sc_pc);
252 	offset("#define SC_STATUS     ", struct sigcontext, sc_status);
253 	offset("#define SC_FPC_CSR    ", struct sigcontext, sc_fpc_csr);
254 	offset("#define SC_FPC_EIR    ", struct sigcontext, sc_fpc_eir);
255 	offset("#define SC_CAUSE      ", struct sigcontext, sc_cause);
256 	offset("#define SC_BADVADDR   ", struct sigcontext, sc_badvaddr);
257 	linefeed;
258 }
259 
260 #ifdef CONFIG_MIPS32_COMPAT
261 void output_sc32_defines(void)
262 {
263 	text("/* Linux 32-bit sigcontext offsets. */");
264 	offset("#define SC32_FPREGS     ", struct sigcontext32, sc_fpregs);
265 	offset("#define SC32_FPC_CSR    ", struct sigcontext32, sc_fpc_csr);
266 	offset("#define SC32_FPC_EIR    ", struct sigcontext32, sc_fpc_eir);
267 	linefeed;
268 }
269 #endif
270 
271 void output_signal_defined(void)
272 {
273 	text("/* Linux signal numbers. */");
274 	constant("#define _SIGHUP     ", SIGHUP);
275 	constant("#define _SIGINT     ", SIGINT);
276 	constant("#define _SIGQUIT    ", SIGQUIT);
277 	constant("#define _SIGILL     ", SIGILL);
278 	constant("#define _SIGTRAP    ", SIGTRAP);
279 	constant("#define _SIGIOT     ", SIGIOT);
280 	constant("#define _SIGABRT    ", SIGABRT);
281 	constant("#define _SIGEMT     ", SIGEMT);
282 	constant("#define _SIGFPE     ", SIGFPE);
283 	constant("#define _SIGKILL    ", SIGKILL);
284 	constant("#define _SIGBUS     ", SIGBUS);
285 	constant("#define _SIGSEGV    ", SIGSEGV);
286 	constant("#define _SIGSYS     ", SIGSYS);
287 	constant("#define _SIGPIPE    ", SIGPIPE);
288 	constant("#define _SIGALRM    ", SIGALRM);
289 	constant("#define _SIGTERM    ", SIGTERM);
290 	constant("#define _SIGUSR1    ", SIGUSR1);
291 	constant("#define _SIGUSR2    ", SIGUSR2);
292 	constant("#define _SIGCHLD    ", SIGCHLD);
293 	constant("#define _SIGPWR     ", SIGPWR);
294 	constant("#define _SIGWINCH   ", SIGWINCH);
295 	constant("#define _SIGURG     ", SIGURG);
296 	constant("#define _SIGIO      ", SIGIO);
297 	constant("#define _SIGSTOP    ", SIGSTOP);
298 	constant("#define _SIGTSTP    ", SIGTSTP);
299 	constant("#define _SIGCONT    ", SIGCONT);
300 	constant("#define _SIGTTIN    ", SIGTTIN);
301 	constant("#define _SIGTTOU    ", SIGTTOU);
302 	constant("#define _SIGVTALRM  ", SIGVTALRM);
303 	constant("#define _SIGPROF    ", SIGPROF);
304 	constant("#define _SIGXCPU    ", SIGXCPU);
305 	constant("#define _SIGXFSZ    ", SIGXFSZ);
306 	linefeed;
307 }
308 
309 void output_irq_cpustat_t_defines(void)
310 {
311 	text("/* Linux irq_cpustat_t offsets. */");
312 	offset("#define IC_SOFTIRQ_PENDING ", irq_cpustat_t, __softirq_pending);
313 	size("#define IC_IRQ_CPUSTAT_T   ", irq_cpustat_t);
314 	linefeed;
315 }
316