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 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/types.h>
12#include <linux/sched.h>
13#include <linux/mm.h>
14
15#include <asm/ptrace.h>
16#include <asm/processor.h>
17
18#define text(t) __asm__("\n@@@" t)
19#define _offset(type, member) (&(((type *)NULL)->member))
20
21#define offset(string, ptr, member) \
22	__asm__("\n@@@" string "%0" : : "i" (_offset(ptr, member)))
23#define constant(string, member) \
24	__asm__("\n@@@" string "%x0" : : "i" (member))
25#define size(string, size) \
26	__asm__("\n@@@" string "%0" : : "i" (sizeof(size)))
27#define linefeed text("")
28
29text("/* DO NOT TOUCH, AUTOGENERATED BY OFFSET.C */");
30linefeed;
31text("#ifndef _MIPS_OFFSET_H");
32text("#define _MIPS_OFFSET_H");
33linefeed;
34
35void output_ptreg_defines(void)
36{
37	text("/* MIPS pt_regs offsets. */");
38	offset("#define PT_R0     ", struct pt_regs, regs[0]);
39	offset("#define PT_R1     ", struct pt_regs, regs[1]);
40	offset("#define PT_R2     ", struct pt_regs, regs[2]);
41	offset("#define PT_R3     ", struct pt_regs, regs[3]);
42	offset("#define PT_R4     ", struct pt_regs, regs[4]);
43	offset("#define PT_R5     ", struct pt_regs, regs[5]);
44	offset("#define PT_R6     ", struct pt_regs, regs[6]);
45	offset("#define PT_R7     ", struct pt_regs, regs[7]);
46	offset("#define PT_R8     ", struct pt_regs, regs[8]);
47	offset("#define PT_R9     ", struct pt_regs, regs[9]);
48	offset("#define PT_R10    ", struct pt_regs, regs[10]);
49	offset("#define PT_R11    ", struct pt_regs, regs[11]);
50	offset("#define PT_R12    ", struct pt_regs, regs[12]);
51	offset("#define PT_R13    ", struct pt_regs, regs[13]);
52	offset("#define PT_R14    ", struct pt_regs, regs[14]);
53	offset("#define PT_R15    ", struct pt_regs, regs[15]);
54	offset("#define PT_R16    ", struct pt_regs, regs[16]);
55	offset("#define PT_R17    ", struct pt_regs, regs[17]);
56	offset("#define PT_R18    ", struct pt_regs, regs[18]);
57	offset("#define PT_R19    ", struct pt_regs, regs[19]);
58	offset("#define PT_R20    ", struct pt_regs, regs[20]);
59	offset("#define PT_R21    ", struct pt_regs, regs[21]);
60	offset("#define PT_R22    ", struct pt_regs, regs[22]);
61	offset("#define PT_R23    ", struct pt_regs, regs[23]);
62	offset("#define PT_R24    ", struct pt_regs, regs[24]);
63	offset("#define PT_R25    ", struct pt_regs, regs[25]);
64	offset("#define PT_R26    ", struct pt_regs, regs[26]);
65	offset("#define PT_R27    ", struct pt_regs, regs[27]);
66	offset("#define PT_R28    ", struct pt_regs, regs[28]);
67	offset("#define PT_R29    ", struct pt_regs, regs[29]);
68	offset("#define PT_R30    ", struct pt_regs, regs[30]);
69	offset("#define PT_R31    ", struct pt_regs, regs[31]);
70	offset("#define PT_LO     ", struct pt_regs, lo);
71	offset("#define PT_HI     ", struct pt_regs, hi);
72	offset("#define PT_EPC    ", struct pt_regs, cp0_epc);
73	offset("#define PT_BVADDR ", struct pt_regs, cp0_badvaddr);
74	offset("#define PT_STATUS ", struct pt_regs, cp0_status);
75	offset("#define PT_CAUSE  ", struct pt_regs, cp0_cause);
76	size("#define PT_SIZE   ", struct pt_regs);
77	linefeed;
78}
79
80void output_task_defines(void)
81{
82	text("/* MIPS task_struct offsets. */");
83	offset("#define TASK_STATE         ", struct task_struct, state);
84	offset("#define TASK_FLAGS         ", struct task_struct, flags);
85	constant("  #define _PT_TRACESYS        ", PT_TRACESYS);
86	offset("#define TASK_SIGPENDING    ", struct task_struct, sigpending);
87	offset("#define TASK_NEED_RESCHED  ", struct task_struct, need_resched);
88	offset("#define TASK_PTRACE        ", struct task_struct, ptrace);
89	offset("#define TASK_COUNTER       ", struct task_struct, counter);
90	offset("#define TASK_NICE          ", struct task_struct, nice);
91	offset("#define TASK_MM            ", struct task_struct, mm);
92	offset("#define TASK_PROCESSOR     ", struct task_struct, processor);
93	offset("#define TASK_PID           ", struct task_struct, pid);
94	size(  "#define TASK_STRUCT_SIZE   ", struct task_struct);
95	linefeed;
96}
97
98void output_thread_defines(void)
99{
100	text("/* MIPS specific thread_struct offsets. */");
101	offset("#define THREAD_REG16   ", struct task_struct, thread.reg16);
102	offset("#define THREAD_REG17   ", struct task_struct, thread.reg17);
103	offset("#define THREAD_REG18   ", struct task_struct, thread.reg18);
104	offset("#define THREAD_REG19   ", struct task_struct, thread.reg19);
105	offset("#define THREAD_REG20   ", struct task_struct, thread.reg20);
106	offset("#define THREAD_REG21   ", struct task_struct, thread.reg21);
107	offset("#define THREAD_REG22   ", struct task_struct, thread.reg22);
108	offset("#define THREAD_REG23   ", struct task_struct, thread.reg23);
109	offset("#define THREAD_REG29   ", struct task_struct, thread.reg29);
110	offset("#define THREAD_REG30   ", struct task_struct, thread.reg30);
111	offset("#define THREAD_REG31   ", struct task_struct, thread.reg31);
112	offset("#define THREAD_STATUS  ", struct task_struct, \
113	       thread.cp0_status);
114	offset("#define THREAD_FPU     ", struct task_struct, thread.fpu);
115	offset("#define THREAD_BVADDR  ", struct task_struct, \
116	       thread.cp0_badvaddr);
117	offset("#define THREAD_BUADDR  ", struct task_struct, \
118	       thread.cp0_baduaddr);
119	offset("#define THREAD_ECODE   ", struct task_struct, \
120	       thread.error_code);
121	offset("#define THREAD_TRAPNO  ", struct task_struct, thread.trap_no);
122	offset("#define THREAD_MFLAGS  ", struct task_struct, thread.mflags);
123	offset("#define THREAD_CURDS   ", struct task_struct, \
124	       thread.current_ds);
125	offset("#define THREAD_TRAMP   ", struct task_struct, \
126	       thread.irix_trampoline);
127	offset("#define THREAD_OLDCTX  ", struct task_struct, \
128	       thread.irix_oldctx);
129	linefeed;
130}
131
132void output_mm_defines(void)
133{
134	text("/* Linux mm_struct offsets. */");
135	offset("#define MM_USERS      ", struct mm_struct, mm_users);
136	offset("#define MM_PGD        ", struct mm_struct, pgd);
137	offset("#define MM_CONTEXT    ", struct mm_struct, context);
138	linefeed;
139	constant("#define _PAGE_SIZE     ", PAGE_SIZE);
140	constant("#define _PGD_ORDER     ", PGD_ORDER);
141	constant("#define _PGDIR_SHIFT   ", PGDIR_SHIFT);
142	linefeed;
143}
144
145void output_sc_defines(void)
146{
147	text("/* Linux sigcontext offsets. */");
148	offset("#define SC_REGS       ", struct sigcontext, sc_regs);
149	offset("#define SC_FPREGS     ", struct sigcontext, sc_fpregs);
150	offset("#define SC_MDHI       ", struct sigcontext, sc_mdhi);
151	offset("#define SC_MDLO       ", struct sigcontext, sc_mdlo);
152	offset("#define SC_PC         ", struct sigcontext, sc_pc);
153	offset("#define SC_STATUS     ", struct sigcontext, sc_status);
154	offset("#define SC_FPC_CSR    ", struct sigcontext, sc_fpc_csr);
155	offset("#define SC_FPC_EIR    ", struct sigcontext, sc_fpc_eir);
156	offset("#define SC_CAUSE      ", struct sigcontext, sc_cause);
157	offset("#define SC_BADVADDR   ", struct sigcontext, sc_badvaddr);
158	linefeed;
159}
160
161void output_signal_defined(void)
162{
163	text("/* Linux signal numbers. */");
164	constant("#define _SIGHUP     ", SIGHUP);
165	constant("#define _SIGINT     ", SIGINT);
166	constant("#define _SIGQUIT    ", SIGQUIT);
167	constant("#define _SIGILL     ", SIGILL);
168	constant("#define _SIGTRAP    ", SIGTRAP);
169	constant("#define _SIGIOT     ", SIGIOT);
170	constant("#define _SIGABRT    ", SIGABRT);
171	constant("#define _SIGEMT     ", SIGEMT);
172	constant("#define _SIGFPE     ", SIGFPE);
173	constant("#define _SIGKILL    ", SIGKILL);
174	constant("#define _SIGBUS     ", SIGBUS);
175	constant("#define _SIGSEGV    ", SIGSEGV);
176	constant("#define _SIGSYS     ", SIGSYS);
177	constant("#define _SIGPIPE    ", SIGPIPE);
178	constant("#define _SIGALRM    ", SIGALRM);
179	constant("#define _SIGTERM    ", SIGTERM);
180	constant("#define _SIGUSR1    ", SIGUSR1);
181	constant("#define _SIGUSR2    ", SIGUSR2);
182	constant("#define _SIGCHLD    ", SIGCHLD);
183	constant("#define _SIGPWR     ", SIGPWR);
184	constant("#define _SIGWINCH   ", SIGWINCH);
185	constant("#define _SIGURG     ", SIGURG);
186	constant("#define _SIGIO      ", SIGIO);
187	constant("#define _SIGSTOP    ", SIGSTOP);
188	constant("#define _SIGTSTP    ", SIGTSTP);
189	constant("#define _SIGCONT    ", SIGCONT);
190	constant("#define _SIGTTIN    ", SIGTTIN);
191	constant("#define _SIGTTOU    ", SIGTTOU);
192	constant("#define _SIGVTALRM  ", SIGVTALRM);
193	constant("#define _SIGPROF    ", SIGPROF);
194	constant("#define _SIGXCPU    ", SIGXCPU);
195	constant("#define _SIGXFSZ    ", SIGXFSZ);
196}
197
198text("#endif /* !(_MIPS_OFFSET_H) */");
199