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