offset.c 13 KB

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