File: /usr/src/linux/arch/mips/tools/offset.c
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 Ralf Baechle
6 * Copyright (C) 1999 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
14 #include <asm/ptrace.h>
15 #include <asm/processor.h>
16
17 #define text(t) __asm__("\n@@@" t)
18 #define _offset(type, member) (&(((type *)NULL)->member))
19
20 #define offset(string, ptr, member) \
21 __asm__("\n@@@" string "%0" : : "i" (_offset(ptr, member)))
22 #define size(string, size) \
23 __asm__("\n@@@" string "%0" : : "i" (sizeof(size)))
24 #define linefeed text("")
25
26 text("/* DO NOT TOUCH, AUTOGENERATED BY OFFSET.C */");
27 linefeed;
28 text("#ifndef _MIPS_OFFSET_H");
29 text("#define _MIPS_OFFSET_H");
30 linefeed;
31
32 void output_ptreg_defines(void)
33 {
34 text("/* MIPS pt_regs offsets. */");
35 offset("#define PT_R0 ", struct pt_regs, regs[0]);
36 offset("#define PT_R1 ", struct pt_regs, regs[1]);
37 offset("#define PT_R2 ", struct pt_regs, regs[2]);
38 offset("#define PT_R3 ", struct pt_regs, regs[3]);
39 offset("#define PT_R4 ", struct pt_regs, regs[4]);
40 offset("#define PT_R5 ", struct pt_regs, regs[5]);
41 offset("#define PT_R6 ", struct pt_regs, regs[6]);
42 offset("#define PT_R7 ", struct pt_regs, regs[7]);
43 offset("#define PT_R8 ", struct pt_regs, regs[8]);
44 offset("#define PT_R9 ", struct pt_regs, regs[9]);
45 offset("#define PT_R10 ", struct pt_regs, regs[10]);
46 offset("#define PT_R11 ", struct pt_regs, regs[11]);
47 offset("#define PT_R12 ", struct pt_regs, regs[12]);
48 offset("#define PT_R13 ", struct pt_regs, regs[13]);
49 offset("#define PT_R14 ", struct pt_regs, regs[14]);
50 offset("#define PT_R15 ", struct pt_regs, regs[15]);
51 offset("#define PT_R16 ", struct pt_regs, regs[16]);
52 offset("#define PT_R17 ", struct pt_regs, regs[17]);
53 offset("#define PT_R18 ", struct pt_regs, regs[18]);
54 offset("#define PT_R19 ", struct pt_regs, regs[19]);
55 offset("#define PT_R20 ", struct pt_regs, regs[20]);
56 offset("#define PT_R21 ", struct pt_regs, regs[21]);
57 offset("#define PT_R22 ", struct pt_regs, regs[22]);
58 offset("#define PT_R23 ", struct pt_regs, regs[23]);
59 offset("#define PT_R24 ", struct pt_regs, regs[24]);
60 offset("#define PT_R25 ", struct pt_regs, regs[25]);
61 offset("#define PT_R26 ", struct pt_regs, regs[26]);
62 offset("#define PT_R27 ", struct pt_regs, regs[27]);
63 offset("#define PT_R28 ", struct pt_regs, regs[28]);
64 offset("#define PT_R29 ", struct pt_regs, regs[29]);
65 offset("#define PT_R30 ", struct pt_regs, regs[30]);
66 offset("#define PT_R31 ", struct pt_regs, regs[31]);
67 offset("#define PT_LO ", struct pt_regs, lo);
68 offset("#define PT_HI ", struct pt_regs, hi);
69 offset("#define PT_EPC ", struct pt_regs, cp0_epc);
70 offset("#define PT_BVADDR ", struct pt_regs, cp0_badvaddr);
71 offset("#define PT_STATUS ", struct pt_regs, cp0_status);
72 offset("#define PT_CAUSE ", struct pt_regs, cp0_cause);
73 size("#define PT_SIZE ", struct pt_regs);
74 linefeed;
75 }
76
77 void output_task_defines(void)
78 {
79 text("/* MIPS task_struct offsets. */");
80 offset("#define TASK_STATE ", struct task_struct, state);
81 offset("#define TASK_FLAGS ", struct task_struct, flags);
82 offset("#define TASK_SIGPENDING ", struct task_struct, sigpending);
83 offset("#define TASK_NEED_RESCHED ", struct task_struct, need_resched);
84 offset("#define TASK_PTRACE ", struct task_struct, ptrace);
85 offset("#define TASK_COUNTER ", struct task_struct, counter);
86 offset("#define TASK_NICE ", struct task_struct, nice);
87 offset("#define TASK_MM ", struct task_struct, mm);
88 offset("#define TASK_PID ", struct task_struct, pid);
89 size("#define TASK_STRUCT_SIZE ", struct task_struct);
90 linefeed;
91 }
92
93 void output_thread_defines(void)
94 {
95 text("/* MIPS specific thread_struct offsets. */");
96 offset("#define THREAD_REG16 ", struct task_struct, thread.reg16);
97 offset("#define THREAD_REG17 ", struct task_struct, thread.reg17);
98 offset("#define THREAD_REG18 ", struct task_struct, thread.reg18);
99 offset("#define THREAD_REG19 ", struct task_struct, thread.reg19);
100 offset("#define THREAD_REG20 ", struct task_struct, thread.reg20);
101 offset("#define THREAD_REG21 ", struct task_struct, thread.reg21);
102 offset("#define THREAD_REG22 ", struct task_struct, thread.reg22);
103 offset("#define THREAD_REG23 ", struct task_struct, thread.reg23);
104 offset("#define THREAD_REG29 ", struct task_struct, thread.reg29);
105 offset("#define THREAD_REG30 ", struct task_struct, thread.reg30);
106 offset("#define THREAD_REG31 ", struct task_struct, thread.reg31);
107 offset("#define THREAD_STATUS ", struct task_struct,
108 thread.cp0_status);
109 offset("#define THREAD_FPU ", struct task_struct, thread.fpu);
110 offset("#define THREAD_BVADDR ", struct task_struct,
111 thread.cp0_badvaddr);
112 offset("#define THREAD_BUADDR ", struct task_struct,
113 thread.cp0_baduaddr);
114 offset("#define THREAD_ECODE ", struct task_struct,
115 thread.error_code);
116 offset("#define THREAD_TRAPNO ", struct task_struct, thread.trap_no);
117 offset("#define THREAD_MFLAGS ", struct task_struct, thread.mflags);
118 offset("#define THREAD_CURDS ", struct task_struct,
119 thread.current_ds);
120 offset("#define THREAD_TRAMP ", struct task_struct,
121 thread.irix_trampoline);
122 offset("#define THREAD_OLDCTX ", struct task_struct,
123 thread.irix_oldctx);
124 offset("#define THREAD_DSEEPC ", struct task_struct,
125 thread.dsemul_epc);
126 offset("#define THREAD_DSEAERPC ", struct task_struct,
127 thread.dsemul_aerpc);
128 linefeed;
129 }
130
131 void output_mm_defines(void)
132 {
133 text("/* Linux mm_struct offsets. */");
134 offset("#define MM_USERS ", struct mm_struct, mm_users);
135 offset("#define MM_PGD ", struct mm_struct, pgd);
136 offset("#define MM_CONTEXT ", struct mm_struct, context);
137 linefeed;
138 }
139
140 void output_sc_defines(void)
141 {
142 text("/* Linux sigcontext offsets. */");
143 offset("#define SC_REGS ", struct sigcontext, sc_regs);
144 offset("#define SC_FPREGS ", struct sigcontext, sc_fpregs);
145 offset("#define SC_MDHI ", struct sigcontext, sc_mdhi);
146 offset("#define SC_MDLO ", struct sigcontext, sc_mdlo);
147 offset("#define SC_PC ", struct sigcontext, sc_pc);
148 offset("#define SC_STATUS ", struct sigcontext, sc_status);
149 offset("#define SC_OWNEDFP ", struct sigcontext, sc_ownedfp);
150 offset("#define SC_FPC_CSR ", struct sigcontext, sc_fpc_csr);
151 offset("#define SC_FPC_EIR ", struct sigcontext, sc_fpc_eir);
152 offset("#define SC_CAUSE ", struct sigcontext, sc_cause);
153 offset("#define SC_BADVADDR ", struct sigcontext, sc_badvaddr);
154 linefeed;
155 }
156
157 text("#endif /* !(_MIPS_OFFSET_H) */");
158