ptrace.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Derived from "arch/m68k/kernel/ptrace.c"
  6. * Copyright (C) 1994 by Hamish Macdonald
  7. * Taken from linux/kernel/ptrace.c and modified for M680x0.
  8. * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
  9. *
  10. * Modified by Cort Dougan (cort@hq.fsmlabs.com)
  11. * and Paul Mackerras (paulus@samba.org).
  12. *
  13. * This file is subject to the terms and conditions of the GNU General
  14. * Public License. See the file README.legal in the main directory of
  15. * this archive for more details.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/sched.h>
  19. #include <linux/mm.h>
  20. #include <linux/smp.h>
  21. #include <linux/errno.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/regset.h>
  24. #include <linux/tracehook.h>
  25. #include <linux/elf.h>
  26. #include <linux/user.h>
  27. #include <linux/security.h>
  28. #include <linux/signal.h>
  29. #include <linux/seccomp.h>
  30. #include <linux/audit.h>
  31. #include <trace/syscall.h>
  32. #include <linux/hw_breakpoint.h>
  33. #include <linux/perf_event.h>
  34. #include <linux/context_tracking.h>
  35. #include <asm/uaccess.h>
  36. #include <asm/page.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/switch_to.h>
  39. #define CREATE_TRACE_POINTS
  40. #include <trace/events/syscalls.h>
  41. /*
  42. * The parameter save area on the stack is used to store arguments being passed
  43. * to callee function and is located at fixed offset from stack pointer.
  44. */
  45. #ifdef CONFIG_PPC32
  46. #define PARAMETER_SAVE_AREA_OFFSET 24 /* bytes */
  47. #else /* CONFIG_PPC32 */
  48. #define PARAMETER_SAVE_AREA_OFFSET 48 /* bytes */
  49. #endif
  50. struct pt_regs_offset {
  51. const char *name;
  52. int offset;
  53. };
  54. #define STR(s) #s /* convert to string */
  55. #define REG_OFFSET_NAME(r) {.name = #r, .offset = offsetof(struct pt_regs, r)}
  56. #define GPR_OFFSET_NAME(num) \
  57. {.name = STR(gpr##num), .offset = offsetof(struct pt_regs, gpr[num])}
  58. #define REG_OFFSET_END {.name = NULL, .offset = 0}
  59. static const struct pt_regs_offset regoffset_table[] = {
  60. GPR_OFFSET_NAME(0),
  61. GPR_OFFSET_NAME(1),
  62. GPR_OFFSET_NAME(2),
  63. GPR_OFFSET_NAME(3),
  64. GPR_OFFSET_NAME(4),
  65. GPR_OFFSET_NAME(5),
  66. GPR_OFFSET_NAME(6),
  67. GPR_OFFSET_NAME(7),
  68. GPR_OFFSET_NAME(8),
  69. GPR_OFFSET_NAME(9),
  70. GPR_OFFSET_NAME(10),
  71. GPR_OFFSET_NAME(11),
  72. GPR_OFFSET_NAME(12),
  73. GPR_OFFSET_NAME(13),
  74. GPR_OFFSET_NAME(14),
  75. GPR_OFFSET_NAME(15),
  76. GPR_OFFSET_NAME(16),
  77. GPR_OFFSET_NAME(17),
  78. GPR_OFFSET_NAME(18),
  79. GPR_OFFSET_NAME(19),
  80. GPR_OFFSET_NAME(20),
  81. GPR_OFFSET_NAME(21),
  82. GPR_OFFSET_NAME(22),
  83. GPR_OFFSET_NAME(23),
  84. GPR_OFFSET_NAME(24),
  85. GPR_OFFSET_NAME(25),
  86. GPR_OFFSET_NAME(26),
  87. GPR_OFFSET_NAME(27),
  88. GPR_OFFSET_NAME(28),
  89. GPR_OFFSET_NAME(29),
  90. GPR_OFFSET_NAME(30),
  91. GPR_OFFSET_NAME(31),
  92. REG_OFFSET_NAME(nip),
  93. REG_OFFSET_NAME(msr),
  94. REG_OFFSET_NAME(ctr),
  95. REG_OFFSET_NAME(link),
  96. REG_OFFSET_NAME(xer),
  97. REG_OFFSET_NAME(ccr),
  98. #ifdef CONFIG_PPC64
  99. REG_OFFSET_NAME(softe),
  100. #else
  101. REG_OFFSET_NAME(mq),
  102. #endif
  103. REG_OFFSET_NAME(trap),
  104. REG_OFFSET_NAME(dar),
  105. REG_OFFSET_NAME(dsisr),
  106. REG_OFFSET_END,
  107. };
  108. /**
  109. * regs_query_register_offset() - query register offset from its name
  110. * @name: the name of a register
  111. *
  112. * regs_query_register_offset() returns the offset of a register in struct
  113. * pt_regs from its name. If the name is invalid, this returns -EINVAL;
  114. */
  115. int regs_query_register_offset(const char *name)
  116. {
  117. const struct pt_regs_offset *roff;
  118. for (roff = regoffset_table; roff->name != NULL; roff++)
  119. if (!strcmp(roff->name, name))
  120. return roff->offset;
  121. return -EINVAL;
  122. }
  123. /**
  124. * regs_query_register_name() - query register name from its offset
  125. * @offset: the offset of a register in struct pt_regs.
  126. *
  127. * regs_query_register_name() returns the name of a register from its
  128. * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
  129. */
  130. const char *regs_query_register_name(unsigned int offset)
  131. {
  132. const struct pt_regs_offset *roff;
  133. for (roff = regoffset_table; roff->name != NULL; roff++)
  134. if (roff->offset == offset)
  135. return roff->name;
  136. return NULL;
  137. }
  138. /*
  139. * does not yet catch signals sent when the child dies.
  140. * in exit.c or in signal.c.
  141. */
  142. /*
  143. * Set of msr bits that gdb can change on behalf of a process.
  144. */
  145. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  146. #define MSR_DEBUGCHANGE 0
  147. #else
  148. #define MSR_DEBUGCHANGE (MSR_SE | MSR_BE)
  149. #endif
  150. /*
  151. * Max register writeable via put_reg
  152. */
  153. #ifdef CONFIG_PPC32
  154. #define PT_MAX_PUT_REG PT_MQ
  155. #else
  156. #define PT_MAX_PUT_REG PT_CCR
  157. #endif
  158. static unsigned long get_user_msr(struct task_struct *task)
  159. {
  160. return task->thread.regs->msr | task->thread.fpexc_mode;
  161. }
  162. static int set_user_msr(struct task_struct *task, unsigned long msr)
  163. {
  164. task->thread.regs->msr &= ~MSR_DEBUGCHANGE;
  165. task->thread.regs->msr |= msr & MSR_DEBUGCHANGE;
  166. return 0;
  167. }
  168. #ifdef CONFIG_PPC64
  169. static int get_user_dscr(struct task_struct *task, unsigned long *data)
  170. {
  171. *data = task->thread.dscr;
  172. return 0;
  173. }
  174. static int set_user_dscr(struct task_struct *task, unsigned long dscr)
  175. {
  176. task->thread.dscr = dscr;
  177. task->thread.dscr_inherit = 1;
  178. return 0;
  179. }
  180. #else
  181. static int get_user_dscr(struct task_struct *task, unsigned long *data)
  182. {
  183. return -EIO;
  184. }
  185. static int set_user_dscr(struct task_struct *task, unsigned long dscr)
  186. {
  187. return -EIO;
  188. }
  189. #endif
  190. /*
  191. * We prevent mucking around with the reserved area of trap
  192. * which are used internally by the kernel.
  193. */
  194. static int set_user_trap(struct task_struct *task, unsigned long trap)
  195. {
  196. task->thread.regs->trap = trap & 0xfff0;
  197. return 0;
  198. }
  199. /*
  200. * Get contents of register REGNO in task TASK.
  201. */
  202. int ptrace_get_reg(struct task_struct *task, int regno, unsigned long *data)
  203. {
  204. if ((task->thread.regs == NULL) || !data)
  205. return -EIO;
  206. if (regno == PT_MSR) {
  207. *data = get_user_msr(task);
  208. return 0;
  209. }
  210. if (regno == PT_DSCR)
  211. return get_user_dscr(task, data);
  212. if (regno < (sizeof(struct pt_regs) / sizeof(unsigned long))) {
  213. *data = ((unsigned long *)task->thread.regs)[regno];
  214. return 0;
  215. }
  216. return -EIO;
  217. }
  218. /*
  219. * Write contents of register REGNO in task TASK.
  220. */
  221. int ptrace_put_reg(struct task_struct *task, int regno, unsigned long data)
  222. {
  223. if (task->thread.regs == NULL)
  224. return -EIO;
  225. if (regno == PT_MSR)
  226. return set_user_msr(task, data);
  227. if (regno == PT_TRAP)
  228. return set_user_trap(task, data);
  229. if (regno == PT_DSCR)
  230. return set_user_dscr(task, data);
  231. if (regno <= PT_MAX_PUT_REG) {
  232. ((unsigned long *)task->thread.regs)[regno] = data;
  233. return 0;
  234. }
  235. return -EIO;
  236. }
  237. static int gpr_get(struct task_struct *target, const struct user_regset *regset,
  238. unsigned int pos, unsigned int count,
  239. void *kbuf, void __user *ubuf)
  240. {
  241. int i, ret;
  242. if (target->thread.regs == NULL)
  243. return -EIO;
  244. if (!FULL_REGS(target->thread.regs)) {
  245. /* We have a partial register set. Fill 14-31 with bogus values */
  246. for (i = 14; i < 32; i++)
  247. target->thread.regs->gpr[i] = NV_REG_POISON;
  248. }
  249. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  250. target->thread.regs,
  251. 0, offsetof(struct pt_regs, msr));
  252. if (!ret) {
  253. unsigned long msr = get_user_msr(target);
  254. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &msr,
  255. offsetof(struct pt_regs, msr),
  256. offsetof(struct pt_regs, msr) +
  257. sizeof(msr));
  258. }
  259. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  260. offsetof(struct pt_regs, msr) + sizeof(long));
  261. if (!ret)
  262. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  263. &target->thread.regs->orig_gpr3,
  264. offsetof(struct pt_regs, orig_gpr3),
  265. sizeof(struct pt_regs));
  266. if (!ret)
  267. ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  268. sizeof(struct pt_regs), -1);
  269. return ret;
  270. }
  271. static int gpr_set(struct task_struct *target, const struct user_regset *regset,
  272. unsigned int pos, unsigned int count,
  273. const void *kbuf, const void __user *ubuf)
  274. {
  275. unsigned long reg;
  276. int ret;
  277. if (target->thread.regs == NULL)
  278. return -EIO;
  279. CHECK_FULL_REGS(target->thread.regs);
  280. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  281. target->thread.regs,
  282. 0, PT_MSR * sizeof(reg));
  283. if (!ret && count > 0) {
  284. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  285. PT_MSR * sizeof(reg),
  286. (PT_MSR + 1) * sizeof(reg));
  287. if (!ret)
  288. ret = set_user_msr(target, reg);
  289. }
  290. BUILD_BUG_ON(offsetof(struct pt_regs, orig_gpr3) !=
  291. offsetof(struct pt_regs, msr) + sizeof(long));
  292. if (!ret)
  293. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  294. &target->thread.regs->orig_gpr3,
  295. PT_ORIG_R3 * sizeof(reg),
  296. (PT_MAX_PUT_REG + 1) * sizeof(reg));
  297. if (PT_MAX_PUT_REG + 1 < PT_TRAP && !ret)
  298. ret = user_regset_copyin_ignore(
  299. &pos, &count, &kbuf, &ubuf,
  300. (PT_MAX_PUT_REG + 1) * sizeof(reg),
  301. PT_TRAP * sizeof(reg));
  302. if (!ret && count > 0) {
  303. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &reg,
  304. PT_TRAP * sizeof(reg),
  305. (PT_TRAP + 1) * sizeof(reg));
  306. if (!ret)
  307. ret = set_user_trap(target, reg);
  308. }
  309. if (!ret)
  310. ret = user_regset_copyin_ignore(
  311. &pos, &count, &kbuf, &ubuf,
  312. (PT_TRAP + 1) * sizeof(reg), -1);
  313. return ret;
  314. }
  315. static int fpr_get(struct task_struct *target, const struct user_regset *regset,
  316. unsigned int pos, unsigned int count,
  317. void *kbuf, void __user *ubuf)
  318. {
  319. #ifdef CONFIG_VSX
  320. double buf[33];
  321. int i;
  322. #endif
  323. flush_fp_to_thread(target);
  324. #ifdef CONFIG_VSX
  325. /* copy to local buffer then write that out */
  326. for (i = 0; i < 32 ; i++)
  327. buf[i] = target->thread.TS_FPR(i);
  328. memcpy(&buf[32], &target->thread.fpscr, sizeof(double));
  329. return user_regset_copyout(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  330. #else
  331. BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
  332. offsetof(struct thread_struct, TS_FPR(32)));
  333. return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  334. &target->thread.fpr, 0, -1);
  335. #endif
  336. }
  337. static int fpr_set(struct task_struct *target, const struct user_regset *regset,
  338. unsigned int pos, unsigned int count,
  339. const void *kbuf, const void __user *ubuf)
  340. {
  341. #ifdef CONFIG_VSX
  342. double buf[33];
  343. int i;
  344. #endif
  345. flush_fp_to_thread(target);
  346. #ifdef CONFIG_VSX
  347. /* copy to local buffer then write that out */
  348. i = user_regset_copyin(&pos, &count, &kbuf, &ubuf, buf, 0, -1);
  349. if (i)
  350. return i;
  351. for (i = 0; i < 32 ; i++)
  352. target->thread.TS_FPR(i) = buf[i];
  353. memcpy(&target->thread.fpscr, &buf[32], sizeof(double));
  354. return 0;
  355. #else
  356. BUILD_BUG_ON(offsetof(struct thread_struct, fpscr) !=
  357. offsetof(struct thread_struct, TS_FPR(32)));
  358. return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  359. &target->thread.fpr, 0, -1);
  360. #endif
  361. }
  362. #ifdef CONFIG_ALTIVEC
  363. /*
  364. * Get/set all the altivec registers vr0..vr31, vscr, vrsave, in one go.
  365. * The transfer totals 34 quadword. Quadwords 0-31 contain the
  366. * corresponding vector registers. Quadword 32 contains the vscr as the
  367. * last word (offset 12) within that quadword. Quadword 33 contains the
  368. * vrsave as the first word (offset 0) within the quadword.
  369. *
  370. * This definition of the VMX state is compatible with the current PPC32
  371. * ptrace interface. This allows signal handling and ptrace to use the
  372. * same structures. This also simplifies the implementation of a bi-arch
  373. * (combined (32- and 64-bit) gdb.
  374. */
  375. static int vr_active(struct task_struct *target,
  376. const struct user_regset *regset)
  377. {
  378. flush_altivec_to_thread(target);
  379. return target->thread.used_vr ? regset->n : 0;
  380. }
  381. static int vr_get(struct task_struct *target, const struct user_regset *regset,
  382. unsigned int pos, unsigned int count,
  383. void *kbuf, void __user *ubuf)
  384. {
  385. int ret;
  386. flush_altivec_to_thread(target);
  387. BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
  388. offsetof(struct thread_struct, vr[32]));
  389. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  390. &target->thread.vr, 0,
  391. 33 * sizeof(vector128));
  392. if (!ret) {
  393. /*
  394. * Copy out only the low-order word of vrsave.
  395. */
  396. union {
  397. elf_vrreg_t reg;
  398. u32 word;
  399. } vrsave;
  400. memset(&vrsave, 0, sizeof(vrsave));
  401. vrsave.word = target->thread.vrsave;
  402. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &vrsave,
  403. 33 * sizeof(vector128), -1);
  404. }
  405. return ret;
  406. }
  407. static int vr_set(struct task_struct *target, const struct user_regset *regset,
  408. unsigned int pos, unsigned int count,
  409. const void *kbuf, const void __user *ubuf)
  410. {
  411. int ret;
  412. flush_altivec_to_thread(target);
  413. BUILD_BUG_ON(offsetof(struct thread_struct, vscr) !=
  414. offsetof(struct thread_struct, vr[32]));
  415. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  416. &target->thread.vr, 0, 33 * sizeof(vector128));
  417. if (!ret && count > 0) {
  418. /*
  419. * We use only the first word of vrsave.
  420. */
  421. union {
  422. elf_vrreg_t reg;
  423. u32 word;
  424. } vrsave;
  425. memset(&vrsave, 0, sizeof(vrsave));
  426. vrsave.word = target->thread.vrsave;
  427. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &vrsave,
  428. 33 * sizeof(vector128), -1);
  429. if (!ret)
  430. target->thread.vrsave = vrsave.word;
  431. }
  432. return ret;
  433. }
  434. #endif /* CONFIG_ALTIVEC */
  435. #ifdef CONFIG_VSX
  436. /*
  437. * Currently to set and and get all the vsx state, you need to call
  438. * the fp and VMX calls as well. This only get/sets the lower 32
  439. * 128bit VSX registers.
  440. */
  441. static int vsr_active(struct task_struct *target,
  442. const struct user_regset *regset)
  443. {
  444. flush_vsx_to_thread(target);
  445. return target->thread.used_vsr ? regset->n : 0;
  446. }
  447. static int vsr_get(struct task_struct *target, const struct user_regset *regset,
  448. unsigned int pos, unsigned int count,
  449. void *kbuf, void __user *ubuf)
  450. {
  451. double buf[32];
  452. int ret, i;
  453. flush_vsx_to_thread(target);
  454. for (i = 0; i < 32 ; i++)
  455. buf[i] = target->thread.fpr[i][TS_VSRLOWOFFSET];
  456. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  457. buf, 0, 32 * sizeof(double));
  458. return ret;
  459. }
  460. static int vsr_set(struct task_struct *target, const struct user_regset *regset,
  461. unsigned int pos, unsigned int count,
  462. const void *kbuf, const void __user *ubuf)
  463. {
  464. double buf[32];
  465. int ret,i;
  466. flush_vsx_to_thread(target);
  467. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  468. buf, 0, 32 * sizeof(double));
  469. for (i = 0; i < 32 ; i++)
  470. target->thread.fpr[i][TS_VSRLOWOFFSET] = buf[i];
  471. return ret;
  472. }
  473. #endif /* CONFIG_VSX */
  474. #ifdef CONFIG_SPE
  475. /*
  476. * For get_evrregs/set_evrregs functions 'data' has the following layout:
  477. *
  478. * struct {
  479. * u32 evr[32];
  480. * u64 acc;
  481. * u32 spefscr;
  482. * }
  483. */
  484. static int evr_active(struct task_struct *target,
  485. const struct user_regset *regset)
  486. {
  487. flush_spe_to_thread(target);
  488. return target->thread.used_spe ? regset->n : 0;
  489. }
  490. static int evr_get(struct task_struct *target, const struct user_regset *regset,
  491. unsigned int pos, unsigned int count,
  492. void *kbuf, void __user *ubuf)
  493. {
  494. int ret;
  495. flush_spe_to_thread(target);
  496. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  497. &target->thread.evr,
  498. 0, sizeof(target->thread.evr));
  499. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  500. offsetof(struct thread_struct, spefscr));
  501. if (!ret)
  502. ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
  503. &target->thread.acc,
  504. sizeof(target->thread.evr), -1);
  505. return ret;
  506. }
  507. static int evr_set(struct task_struct *target, const struct user_regset *regset,
  508. unsigned int pos, unsigned int count,
  509. const void *kbuf, const void __user *ubuf)
  510. {
  511. int ret;
  512. flush_spe_to_thread(target);
  513. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  514. &target->thread.evr,
  515. 0, sizeof(target->thread.evr));
  516. BUILD_BUG_ON(offsetof(struct thread_struct, acc) + sizeof(u64) !=
  517. offsetof(struct thread_struct, spefscr));
  518. if (!ret)
  519. ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
  520. &target->thread.acc,
  521. sizeof(target->thread.evr), -1);
  522. return ret;
  523. }
  524. #endif /* CONFIG_SPE */
  525. /*
  526. * These are our native regset flavors.
  527. */
  528. enum powerpc_regset {
  529. REGSET_GPR,
  530. REGSET_FPR,
  531. #ifdef CONFIG_ALTIVEC
  532. REGSET_VMX,
  533. #endif
  534. #ifdef CONFIG_VSX
  535. REGSET_VSX,
  536. #endif
  537. #ifdef CONFIG_SPE
  538. REGSET_SPE,
  539. #endif
  540. };
  541. static const struct user_regset native_regsets[] = {
  542. [REGSET_GPR] = {
  543. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  544. .size = sizeof(long), .align = sizeof(long),
  545. .get = gpr_get, .set = gpr_set
  546. },
  547. [REGSET_FPR] = {
  548. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  549. .size = sizeof(double), .align = sizeof(double),
  550. .get = fpr_get, .set = fpr_set
  551. },
  552. #ifdef CONFIG_ALTIVEC
  553. [REGSET_VMX] = {
  554. .core_note_type = NT_PPC_VMX, .n = 34,
  555. .size = sizeof(vector128), .align = sizeof(vector128),
  556. .active = vr_active, .get = vr_get, .set = vr_set
  557. },
  558. #endif
  559. #ifdef CONFIG_VSX
  560. [REGSET_VSX] = {
  561. .core_note_type = NT_PPC_VSX, .n = 32,
  562. .size = sizeof(double), .align = sizeof(double),
  563. .active = vsr_active, .get = vsr_get, .set = vsr_set
  564. },
  565. #endif
  566. #ifdef CONFIG_SPE
  567. [REGSET_SPE] = {
  568. .n = 35,
  569. .size = sizeof(u32), .align = sizeof(u32),
  570. .active = evr_active, .get = evr_get, .set = evr_set
  571. },
  572. #endif
  573. };
  574. static const struct user_regset_view user_ppc_native_view = {
  575. .name = UTS_MACHINE, .e_machine = ELF_ARCH, .ei_osabi = ELF_OSABI,
  576. .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
  577. };
  578. #ifdef CONFIG_PPC64
  579. #include <linux/compat.h>
  580. static int gpr32_get(struct task_struct *target,
  581. const struct user_regset *regset,
  582. unsigned int pos, unsigned int count,
  583. void *kbuf, void __user *ubuf)
  584. {
  585. const unsigned long *regs = &target->thread.regs->gpr[0];
  586. compat_ulong_t *k = kbuf;
  587. compat_ulong_t __user *u = ubuf;
  588. compat_ulong_t reg;
  589. int i;
  590. if (target->thread.regs == NULL)
  591. return -EIO;
  592. if (!FULL_REGS(target->thread.regs)) {
  593. /* We have a partial register set. Fill 14-31 with bogus values */
  594. for (i = 14; i < 32; i++)
  595. target->thread.regs->gpr[i] = NV_REG_POISON;
  596. }
  597. pos /= sizeof(reg);
  598. count /= sizeof(reg);
  599. if (kbuf)
  600. for (; count > 0 && pos < PT_MSR; --count)
  601. *k++ = regs[pos++];
  602. else
  603. for (; count > 0 && pos < PT_MSR; --count)
  604. if (__put_user((compat_ulong_t) regs[pos++], u++))
  605. return -EFAULT;
  606. if (count > 0 && pos == PT_MSR) {
  607. reg = get_user_msr(target);
  608. if (kbuf)
  609. *k++ = reg;
  610. else if (__put_user(reg, u++))
  611. return -EFAULT;
  612. ++pos;
  613. --count;
  614. }
  615. if (kbuf)
  616. for (; count > 0 && pos < PT_REGS_COUNT; --count)
  617. *k++ = regs[pos++];
  618. else
  619. for (; count > 0 && pos < PT_REGS_COUNT; --count)
  620. if (__put_user((compat_ulong_t) regs[pos++], u++))
  621. return -EFAULT;
  622. kbuf = k;
  623. ubuf = u;
  624. pos *= sizeof(reg);
  625. count *= sizeof(reg);
  626. return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
  627. PT_REGS_COUNT * sizeof(reg), -1);
  628. }
  629. static int gpr32_set(struct task_struct *target,
  630. const struct user_regset *regset,
  631. unsigned int pos, unsigned int count,
  632. const void *kbuf, const void __user *ubuf)
  633. {
  634. unsigned long *regs = &target->thread.regs->gpr[0];
  635. const compat_ulong_t *k = kbuf;
  636. const compat_ulong_t __user *u = ubuf;
  637. compat_ulong_t reg;
  638. if (target->thread.regs == NULL)
  639. return -EIO;
  640. CHECK_FULL_REGS(target->thread.regs);
  641. pos /= sizeof(reg);
  642. count /= sizeof(reg);
  643. if (kbuf)
  644. for (; count > 0 && pos < PT_MSR; --count)
  645. regs[pos++] = *k++;
  646. else
  647. for (; count > 0 && pos < PT_MSR; --count) {
  648. if (__get_user(reg, u++))
  649. return -EFAULT;
  650. regs[pos++] = reg;
  651. }
  652. if (count > 0 && pos == PT_MSR) {
  653. if (kbuf)
  654. reg = *k++;
  655. else if (__get_user(reg, u++))
  656. return -EFAULT;
  657. set_user_msr(target, reg);
  658. ++pos;
  659. --count;
  660. }
  661. if (kbuf) {
  662. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count)
  663. regs[pos++] = *k++;
  664. for (; count > 0 && pos < PT_TRAP; --count, ++pos)
  665. ++k;
  666. } else {
  667. for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
  668. if (__get_user(reg, u++))
  669. return -EFAULT;
  670. regs[pos++] = reg;
  671. }
  672. for (; count > 0 && pos < PT_TRAP; --count, ++pos)
  673. if (__get_user(reg, u++))
  674. return -EFAULT;
  675. }
  676. if (count > 0 && pos == PT_TRAP) {
  677. if (kbuf)
  678. reg = *k++;
  679. else if (__get_user(reg, u++))
  680. return -EFAULT;
  681. set_user_trap(target, reg);
  682. ++pos;
  683. --count;
  684. }
  685. kbuf = k;
  686. ubuf = u;
  687. pos *= sizeof(reg);
  688. count *= sizeof(reg);
  689. return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
  690. (PT_TRAP + 1) * sizeof(reg), -1);
  691. }
  692. /*
  693. * These are the regset flavors matching the CONFIG_PPC32 native set.
  694. */
  695. static const struct user_regset compat_regsets[] = {
  696. [REGSET_GPR] = {
  697. .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
  698. .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
  699. .get = gpr32_get, .set = gpr32_set
  700. },
  701. [REGSET_FPR] = {
  702. .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
  703. .size = sizeof(double), .align = sizeof(double),
  704. .get = fpr_get, .set = fpr_set
  705. },
  706. #ifdef CONFIG_ALTIVEC
  707. [REGSET_VMX] = {
  708. .core_note_type = NT_PPC_VMX, .n = 34,
  709. .size = sizeof(vector128), .align = sizeof(vector128),
  710. .active = vr_active, .get = vr_get, .set = vr_set
  711. },
  712. #endif
  713. #ifdef CONFIG_SPE
  714. [REGSET_SPE] = {
  715. .core_note_type = NT_PPC_SPE, .n = 35,
  716. .size = sizeof(u32), .align = sizeof(u32),
  717. .active = evr_active, .get = evr_get, .set = evr_set
  718. },
  719. #endif
  720. };
  721. static const struct user_regset_view user_ppc_compat_view = {
  722. .name = "ppc", .e_machine = EM_PPC, .ei_osabi = ELF_OSABI,
  723. .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
  724. };
  725. #endif /* CONFIG_PPC64 */
  726. const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  727. {
  728. #ifdef CONFIG_PPC64
  729. if (test_tsk_thread_flag(task, TIF_32BIT))
  730. return &user_ppc_compat_view;
  731. #endif
  732. return &user_ppc_native_view;
  733. }
  734. void user_enable_single_step(struct task_struct *task)
  735. {
  736. struct pt_regs *regs = task->thread.regs;
  737. if (regs != NULL) {
  738. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  739. task->thread.dbcr0 &= ~DBCR0_BT;
  740. task->thread.dbcr0 |= DBCR0_IDM | DBCR0_IC;
  741. regs->msr |= MSR_DE;
  742. #else
  743. regs->msr &= ~MSR_BE;
  744. regs->msr |= MSR_SE;
  745. #endif
  746. }
  747. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  748. }
  749. void user_enable_block_step(struct task_struct *task)
  750. {
  751. struct pt_regs *regs = task->thread.regs;
  752. if (regs != NULL) {
  753. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  754. task->thread.dbcr0 &= ~DBCR0_IC;
  755. task->thread.dbcr0 = DBCR0_IDM | DBCR0_BT;
  756. regs->msr |= MSR_DE;
  757. #else
  758. regs->msr &= ~MSR_SE;
  759. regs->msr |= MSR_BE;
  760. #endif
  761. }
  762. set_tsk_thread_flag(task, TIF_SINGLESTEP);
  763. }
  764. void user_disable_single_step(struct task_struct *task)
  765. {
  766. struct pt_regs *regs = task->thread.regs;
  767. if (regs != NULL) {
  768. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  769. /*
  770. * The logic to disable single stepping should be as
  771. * simple as turning off the Instruction Complete flag.
  772. * And, after doing so, if all debug flags are off, turn
  773. * off DBCR0(IDM) and MSR(DE) .... Torez
  774. */
  775. task->thread.dbcr0 &= ~DBCR0_IC;
  776. /*
  777. * Test to see if any of the DBCR_ACTIVE_EVENTS bits are set.
  778. */
  779. if (!DBCR_ACTIVE_EVENTS(task->thread.dbcr0,
  780. task->thread.dbcr1)) {
  781. /*
  782. * All debug events were off.....
  783. */
  784. task->thread.dbcr0 &= ~DBCR0_IDM;
  785. regs->msr &= ~MSR_DE;
  786. }
  787. #else
  788. regs->msr &= ~(MSR_SE | MSR_BE);
  789. #endif
  790. }
  791. clear_tsk_thread_flag(task, TIF_SINGLESTEP);
  792. }
  793. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  794. void ptrace_triggered(struct perf_event *bp,
  795. struct perf_sample_data *data, struct pt_regs *regs)
  796. {
  797. struct perf_event_attr attr;
  798. /*
  799. * Disable the breakpoint request here since ptrace has defined a
  800. * one-shot behaviour for breakpoint exceptions in PPC64.
  801. * The SIGTRAP signal is generated automatically for us in do_dabr().
  802. * We don't have to do anything about that here
  803. */
  804. attr = bp->attr;
  805. attr.disabled = true;
  806. modify_user_hw_breakpoint(bp, &attr);
  807. }
  808. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  809. int ptrace_set_debugreg(struct task_struct *task, unsigned long addr,
  810. unsigned long data)
  811. {
  812. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  813. int ret;
  814. struct thread_struct *thread = &(task->thread);
  815. struct perf_event *bp;
  816. struct perf_event_attr attr;
  817. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  818. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  819. struct arch_hw_breakpoint hw_brk;
  820. #endif
  821. /* For ppc64 we support one DABR and no IABR's at the moment (ppc64).
  822. * For embedded processors we support one DAC and no IAC's at the
  823. * moment.
  824. */
  825. if (addr > 0)
  826. return -EINVAL;
  827. /* The bottom 3 bits in dabr are flags */
  828. if ((data & ~0x7UL) >= TASK_SIZE)
  829. return -EIO;
  830. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  831. /* For processors using DABR (i.e. 970), the bottom 3 bits are flags.
  832. * It was assumed, on previous implementations, that 3 bits were
  833. * passed together with the data address, fitting the design of the
  834. * DABR register, as follows:
  835. *
  836. * bit 0: Read flag
  837. * bit 1: Write flag
  838. * bit 2: Breakpoint translation
  839. *
  840. * Thus, we use them here as so.
  841. */
  842. /* Ensure breakpoint translation bit is set */
  843. if (data && !(data & HW_BRK_TYPE_TRANSLATE))
  844. return -EIO;
  845. hw_brk.address = data & (~HW_BRK_TYPE_DABR);
  846. hw_brk.type = (data & HW_BRK_TYPE_DABR) | HW_BRK_TYPE_PRIV_ALL;
  847. hw_brk.len = 8;
  848. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  849. if (ptrace_get_breakpoints(task) < 0)
  850. return -ESRCH;
  851. bp = thread->ptrace_bps[0];
  852. if ((!data) || !(hw_brk.type & HW_BRK_TYPE_RDWR)) {
  853. if (bp) {
  854. unregister_hw_breakpoint(bp);
  855. thread->ptrace_bps[0] = NULL;
  856. }
  857. ptrace_put_breakpoints(task);
  858. return 0;
  859. }
  860. if (bp) {
  861. attr = bp->attr;
  862. attr.bp_addr = hw_brk.address;
  863. arch_bp_generic_fields(hw_brk.type, &attr.bp_type);
  864. /* Enable breakpoint */
  865. attr.disabled = false;
  866. ret = modify_user_hw_breakpoint(bp, &attr);
  867. if (ret) {
  868. ptrace_put_breakpoints(task);
  869. return ret;
  870. }
  871. thread->ptrace_bps[0] = bp;
  872. ptrace_put_breakpoints(task);
  873. thread->hw_brk = hw_brk;
  874. return 0;
  875. }
  876. /* Create a new breakpoint request if one doesn't exist already */
  877. hw_breakpoint_init(&attr);
  878. attr.bp_addr = hw_brk.address;
  879. arch_bp_generic_fields(hw_brk.type,
  880. &attr.bp_type);
  881. thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
  882. ptrace_triggered, NULL, task);
  883. if (IS_ERR(bp)) {
  884. thread->ptrace_bps[0] = NULL;
  885. ptrace_put_breakpoints(task);
  886. return PTR_ERR(bp);
  887. }
  888. ptrace_put_breakpoints(task);
  889. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  890. task->thread.hw_brk = hw_brk;
  891. #else /* CONFIG_PPC_ADV_DEBUG_REGS */
  892. /* As described above, it was assumed 3 bits were passed with the data
  893. * address, but we will assume only the mode bits will be passed
  894. * as to not cause alignment restrictions for DAC-based processors.
  895. */
  896. /* DAC's hold the whole address without any mode flags */
  897. task->thread.dac1 = data & ~0x3UL;
  898. if (task->thread.dac1 == 0) {
  899. dbcr_dac(task) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  900. if (!DBCR_ACTIVE_EVENTS(task->thread.dbcr0,
  901. task->thread.dbcr1)) {
  902. task->thread.regs->msr &= ~MSR_DE;
  903. task->thread.dbcr0 &= ~DBCR0_IDM;
  904. }
  905. return 0;
  906. }
  907. /* Read or Write bits must be set */
  908. if (!(data & 0x3UL))
  909. return -EINVAL;
  910. /* Set the Internal Debugging flag (IDM bit 1) for the DBCR0
  911. register */
  912. task->thread.dbcr0 |= DBCR0_IDM;
  913. /* Check for write and read flags and set DBCR0
  914. accordingly */
  915. dbcr_dac(task) &= ~(DBCR_DAC1R|DBCR_DAC1W);
  916. if (data & 0x1UL)
  917. dbcr_dac(task) |= DBCR_DAC1R;
  918. if (data & 0x2UL)
  919. dbcr_dac(task) |= DBCR_DAC1W;
  920. task->thread.regs->msr |= MSR_DE;
  921. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  922. return 0;
  923. }
  924. /*
  925. * Called by kernel/ptrace.c when detaching..
  926. *
  927. * Make sure single step bits etc are not set.
  928. */
  929. void ptrace_disable(struct task_struct *child)
  930. {
  931. /* make sure the single step bit is not set. */
  932. user_disable_single_step(child);
  933. }
  934. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  935. static long set_instruction_bp(struct task_struct *child,
  936. struct ppc_hw_breakpoint *bp_info)
  937. {
  938. int slot;
  939. int slot1_in_use = ((child->thread.dbcr0 & DBCR0_IAC1) != 0);
  940. int slot2_in_use = ((child->thread.dbcr0 & DBCR0_IAC2) != 0);
  941. int slot3_in_use = ((child->thread.dbcr0 & DBCR0_IAC3) != 0);
  942. int slot4_in_use = ((child->thread.dbcr0 & DBCR0_IAC4) != 0);
  943. if (dbcr_iac_range(child) & DBCR_IAC12MODE)
  944. slot2_in_use = 1;
  945. if (dbcr_iac_range(child) & DBCR_IAC34MODE)
  946. slot4_in_use = 1;
  947. if (bp_info->addr >= TASK_SIZE)
  948. return -EIO;
  949. if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT) {
  950. /* Make sure range is valid. */
  951. if (bp_info->addr2 >= TASK_SIZE)
  952. return -EIO;
  953. /* We need a pair of IAC regsisters */
  954. if ((!slot1_in_use) && (!slot2_in_use)) {
  955. slot = 1;
  956. child->thread.iac1 = bp_info->addr;
  957. child->thread.iac2 = bp_info->addr2;
  958. child->thread.dbcr0 |= DBCR0_IAC1;
  959. if (bp_info->addr_mode ==
  960. PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  961. dbcr_iac_range(child) |= DBCR_IAC12X;
  962. else
  963. dbcr_iac_range(child) |= DBCR_IAC12I;
  964. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  965. } else if ((!slot3_in_use) && (!slot4_in_use)) {
  966. slot = 3;
  967. child->thread.iac3 = bp_info->addr;
  968. child->thread.iac4 = bp_info->addr2;
  969. child->thread.dbcr0 |= DBCR0_IAC3;
  970. if (bp_info->addr_mode ==
  971. PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  972. dbcr_iac_range(child) |= DBCR_IAC34X;
  973. else
  974. dbcr_iac_range(child) |= DBCR_IAC34I;
  975. #endif
  976. } else
  977. return -ENOSPC;
  978. } else {
  979. /* We only need one. If possible leave a pair free in
  980. * case a range is needed later
  981. */
  982. if (!slot1_in_use) {
  983. /*
  984. * Don't use iac1 if iac1-iac2 are free and either
  985. * iac3 or iac4 (but not both) are free
  986. */
  987. if (slot2_in_use || (slot3_in_use == slot4_in_use)) {
  988. slot = 1;
  989. child->thread.iac1 = bp_info->addr;
  990. child->thread.dbcr0 |= DBCR0_IAC1;
  991. goto out;
  992. }
  993. }
  994. if (!slot2_in_use) {
  995. slot = 2;
  996. child->thread.iac2 = bp_info->addr;
  997. child->thread.dbcr0 |= DBCR0_IAC2;
  998. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  999. } else if (!slot3_in_use) {
  1000. slot = 3;
  1001. child->thread.iac3 = bp_info->addr;
  1002. child->thread.dbcr0 |= DBCR0_IAC3;
  1003. } else if (!slot4_in_use) {
  1004. slot = 4;
  1005. child->thread.iac4 = bp_info->addr;
  1006. child->thread.dbcr0 |= DBCR0_IAC4;
  1007. #endif
  1008. } else
  1009. return -ENOSPC;
  1010. }
  1011. out:
  1012. child->thread.dbcr0 |= DBCR0_IDM;
  1013. child->thread.regs->msr |= MSR_DE;
  1014. return slot;
  1015. }
  1016. static int del_instruction_bp(struct task_struct *child, int slot)
  1017. {
  1018. switch (slot) {
  1019. case 1:
  1020. if ((child->thread.dbcr0 & DBCR0_IAC1) == 0)
  1021. return -ENOENT;
  1022. if (dbcr_iac_range(child) & DBCR_IAC12MODE) {
  1023. /* address range - clear slots 1 & 2 */
  1024. child->thread.iac2 = 0;
  1025. dbcr_iac_range(child) &= ~DBCR_IAC12MODE;
  1026. }
  1027. child->thread.iac1 = 0;
  1028. child->thread.dbcr0 &= ~DBCR0_IAC1;
  1029. break;
  1030. case 2:
  1031. if ((child->thread.dbcr0 & DBCR0_IAC2) == 0)
  1032. return -ENOENT;
  1033. if (dbcr_iac_range(child) & DBCR_IAC12MODE)
  1034. /* used in a range */
  1035. return -EINVAL;
  1036. child->thread.iac2 = 0;
  1037. child->thread.dbcr0 &= ~DBCR0_IAC2;
  1038. break;
  1039. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  1040. case 3:
  1041. if ((child->thread.dbcr0 & DBCR0_IAC3) == 0)
  1042. return -ENOENT;
  1043. if (dbcr_iac_range(child) & DBCR_IAC34MODE) {
  1044. /* address range - clear slots 3 & 4 */
  1045. child->thread.iac4 = 0;
  1046. dbcr_iac_range(child) &= ~DBCR_IAC34MODE;
  1047. }
  1048. child->thread.iac3 = 0;
  1049. child->thread.dbcr0 &= ~DBCR0_IAC3;
  1050. break;
  1051. case 4:
  1052. if ((child->thread.dbcr0 & DBCR0_IAC4) == 0)
  1053. return -ENOENT;
  1054. if (dbcr_iac_range(child) & DBCR_IAC34MODE)
  1055. /* Used in a range */
  1056. return -EINVAL;
  1057. child->thread.iac4 = 0;
  1058. child->thread.dbcr0 &= ~DBCR0_IAC4;
  1059. break;
  1060. #endif
  1061. default:
  1062. return -EINVAL;
  1063. }
  1064. return 0;
  1065. }
  1066. static int set_dac(struct task_struct *child, struct ppc_hw_breakpoint *bp_info)
  1067. {
  1068. int byte_enable =
  1069. (bp_info->condition_mode >> PPC_BREAKPOINT_CONDITION_BE_SHIFT)
  1070. & 0xf;
  1071. int condition_mode =
  1072. bp_info->condition_mode & PPC_BREAKPOINT_CONDITION_MODE;
  1073. int slot;
  1074. if (byte_enable && (condition_mode == 0))
  1075. return -EINVAL;
  1076. if (bp_info->addr >= TASK_SIZE)
  1077. return -EIO;
  1078. if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0) {
  1079. slot = 1;
  1080. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  1081. dbcr_dac(child) |= DBCR_DAC1R;
  1082. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  1083. dbcr_dac(child) |= DBCR_DAC1W;
  1084. child->thread.dac1 = (unsigned long)bp_info->addr;
  1085. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  1086. if (byte_enable) {
  1087. child->thread.dvc1 =
  1088. (unsigned long)bp_info->condition_value;
  1089. child->thread.dbcr2 |=
  1090. ((byte_enable << DBCR2_DVC1BE_SHIFT) |
  1091. (condition_mode << DBCR2_DVC1M_SHIFT));
  1092. }
  1093. #endif
  1094. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1095. } else if (child->thread.dbcr2 & DBCR2_DAC12MODE) {
  1096. /* Both dac1 and dac2 are part of a range */
  1097. return -ENOSPC;
  1098. #endif
  1099. } else if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0) {
  1100. slot = 2;
  1101. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  1102. dbcr_dac(child) |= DBCR_DAC2R;
  1103. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  1104. dbcr_dac(child) |= DBCR_DAC2W;
  1105. child->thread.dac2 = (unsigned long)bp_info->addr;
  1106. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  1107. if (byte_enable) {
  1108. child->thread.dvc2 =
  1109. (unsigned long)bp_info->condition_value;
  1110. child->thread.dbcr2 |=
  1111. ((byte_enable << DBCR2_DVC2BE_SHIFT) |
  1112. (condition_mode << DBCR2_DVC2M_SHIFT));
  1113. }
  1114. #endif
  1115. } else
  1116. return -ENOSPC;
  1117. child->thread.dbcr0 |= DBCR0_IDM;
  1118. child->thread.regs->msr |= MSR_DE;
  1119. return slot + 4;
  1120. }
  1121. static int del_dac(struct task_struct *child, int slot)
  1122. {
  1123. if (slot == 1) {
  1124. if ((dbcr_dac(child) & (DBCR_DAC1R | DBCR_DAC1W)) == 0)
  1125. return -ENOENT;
  1126. child->thread.dac1 = 0;
  1127. dbcr_dac(child) &= ~(DBCR_DAC1R | DBCR_DAC1W);
  1128. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1129. if (child->thread.dbcr2 & DBCR2_DAC12MODE) {
  1130. child->thread.dac2 = 0;
  1131. child->thread.dbcr2 &= ~DBCR2_DAC12MODE;
  1132. }
  1133. child->thread.dbcr2 &= ~(DBCR2_DVC1M | DBCR2_DVC1BE);
  1134. #endif
  1135. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  1136. child->thread.dvc1 = 0;
  1137. #endif
  1138. } else if (slot == 2) {
  1139. if ((dbcr_dac(child) & (DBCR_DAC2R | DBCR_DAC2W)) == 0)
  1140. return -ENOENT;
  1141. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1142. if (child->thread.dbcr2 & DBCR2_DAC12MODE)
  1143. /* Part of a range */
  1144. return -EINVAL;
  1145. child->thread.dbcr2 &= ~(DBCR2_DVC2M | DBCR2_DVC2BE);
  1146. #endif
  1147. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  1148. child->thread.dvc2 = 0;
  1149. #endif
  1150. child->thread.dac2 = 0;
  1151. dbcr_dac(child) &= ~(DBCR_DAC2R | DBCR_DAC2W);
  1152. } else
  1153. return -EINVAL;
  1154. return 0;
  1155. }
  1156. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  1157. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1158. static int set_dac_range(struct task_struct *child,
  1159. struct ppc_hw_breakpoint *bp_info)
  1160. {
  1161. int mode = bp_info->addr_mode & PPC_BREAKPOINT_MODE_MASK;
  1162. /* We don't allow range watchpoints to be used with DVC */
  1163. if (bp_info->condition_mode)
  1164. return -EINVAL;
  1165. /*
  1166. * Best effort to verify the address range. The user/supervisor bits
  1167. * prevent trapping in kernel space, but let's fail on an obvious bad
  1168. * range. The simple test on the mask is not fool-proof, and any
  1169. * exclusive range will spill over into kernel space.
  1170. */
  1171. if (bp_info->addr >= TASK_SIZE)
  1172. return -EIO;
  1173. if (mode == PPC_BREAKPOINT_MODE_MASK) {
  1174. /*
  1175. * dac2 is a bitmask. Don't allow a mask that makes a
  1176. * kernel space address from a valid dac1 value
  1177. */
  1178. if (~((unsigned long)bp_info->addr2) >= TASK_SIZE)
  1179. return -EIO;
  1180. } else {
  1181. /*
  1182. * For range breakpoints, addr2 must also be a valid address
  1183. */
  1184. if (bp_info->addr2 >= TASK_SIZE)
  1185. return -EIO;
  1186. }
  1187. if (child->thread.dbcr0 &
  1188. (DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W))
  1189. return -ENOSPC;
  1190. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  1191. child->thread.dbcr0 |= (DBCR0_DAC1R | DBCR0_IDM);
  1192. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  1193. child->thread.dbcr0 |= (DBCR0_DAC1W | DBCR0_IDM);
  1194. child->thread.dac1 = bp_info->addr;
  1195. child->thread.dac2 = bp_info->addr2;
  1196. if (mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE)
  1197. child->thread.dbcr2 |= DBCR2_DAC12M;
  1198. else if (mode == PPC_BREAKPOINT_MODE_RANGE_EXCLUSIVE)
  1199. child->thread.dbcr2 |= DBCR2_DAC12MX;
  1200. else /* PPC_BREAKPOINT_MODE_MASK */
  1201. child->thread.dbcr2 |= DBCR2_DAC12MM;
  1202. child->thread.regs->msr |= MSR_DE;
  1203. return 5;
  1204. }
  1205. #endif /* CONFIG_PPC_ADV_DEBUG_DAC_RANGE */
  1206. static long ppc_set_hwdebug(struct task_struct *child,
  1207. struct ppc_hw_breakpoint *bp_info)
  1208. {
  1209. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  1210. int len = 0;
  1211. struct thread_struct *thread = &(child->thread);
  1212. struct perf_event *bp;
  1213. struct perf_event_attr attr;
  1214. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  1215. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  1216. struct arch_hw_breakpoint brk;
  1217. #endif
  1218. if (bp_info->version != 1)
  1219. return -ENOTSUPP;
  1220. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1221. /*
  1222. * Check for invalid flags and combinations
  1223. */
  1224. if ((bp_info->trigger_type == 0) ||
  1225. (bp_info->trigger_type & ~(PPC_BREAKPOINT_TRIGGER_EXECUTE |
  1226. PPC_BREAKPOINT_TRIGGER_RW)) ||
  1227. (bp_info->addr_mode & ~PPC_BREAKPOINT_MODE_MASK) ||
  1228. (bp_info->condition_mode &
  1229. ~(PPC_BREAKPOINT_CONDITION_MODE |
  1230. PPC_BREAKPOINT_CONDITION_BE_ALL)))
  1231. return -EINVAL;
  1232. #if CONFIG_PPC_ADV_DEBUG_DVCS == 0
  1233. if (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
  1234. return -EINVAL;
  1235. #endif
  1236. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_EXECUTE) {
  1237. if ((bp_info->trigger_type != PPC_BREAKPOINT_TRIGGER_EXECUTE) ||
  1238. (bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE))
  1239. return -EINVAL;
  1240. return set_instruction_bp(child, bp_info);
  1241. }
  1242. if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
  1243. return set_dac(child, bp_info);
  1244. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1245. return set_dac_range(child, bp_info);
  1246. #else
  1247. return -EINVAL;
  1248. #endif
  1249. #else /* !CONFIG_PPC_ADV_DEBUG_DVCS */
  1250. /*
  1251. * We only support one data breakpoint
  1252. */
  1253. if ((bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_RW) == 0 ||
  1254. (bp_info->trigger_type & ~PPC_BREAKPOINT_TRIGGER_RW) != 0 ||
  1255. bp_info->condition_mode != PPC_BREAKPOINT_CONDITION_NONE)
  1256. return -EINVAL;
  1257. if ((unsigned long)bp_info->addr >= TASK_SIZE)
  1258. return -EIO;
  1259. brk.address = bp_info->addr & ~7UL;
  1260. brk.type = HW_BRK_TYPE_TRANSLATE;
  1261. brk.len = 8;
  1262. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_READ)
  1263. brk.type |= HW_BRK_TYPE_READ;
  1264. if (bp_info->trigger_type & PPC_BREAKPOINT_TRIGGER_WRITE)
  1265. brk.type |= HW_BRK_TYPE_WRITE;
  1266. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  1267. if (ptrace_get_breakpoints(child) < 0)
  1268. return -ESRCH;
  1269. /*
  1270. * Check if the request is for 'range' breakpoints. We can
  1271. * support it if range < 8 bytes.
  1272. */
  1273. if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_RANGE_INCLUSIVE) {
  1274. len = bp_info->addr2 - bp_info->addr;
  1275. } else if (bp_info->addr_mode == PPC_BREAKPOINT_MODE_EXACT)
  1276. len = 1;
  1277. else {
  1278. ptrace_put_breakpoints(child);
  1279. return -EINVAL;
  1280. }
  1281. bp = thread->ptrace_bps[0];
  1282. if (bp) {
  1283. ptrace_put_breakpoints(child);
  1284. return -ENOSPC;
  1285. }
  1286. /* Create a new breakpoint request if one doesn't exist already */
  1287. hw_breakpoint_init(&attr);
  1288. attr.bp_addr = (unsigned long)bp_info->addr & ~HW_BREAKPOINT_ALIGN;
  1289. attr.bp_len = len;
  1290. arch_bp_generic_fields(brk.type, &attr.bp_type);
  1291. thread->ptrace_bps[0] = bp = register_user_hw_breakpoint(&attr,
  1292. ptrace_triggered, NULL, child);
  1293. if (IS_ERR(bp)) {
  1294. thread->ptrace_bps[0] = NULL;
  1295. ptrace_put_breakpoints(child);
  1296. return PTR_ERR(bp);
  1297. }
  1298. ptrace_put_breakpoints(child);
  1299. return 1;
  1300. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  1301. if (bp_info->addr_mode != PPC_BREAKPOINT_MODE_EXACT)
  1302. return -EINVAL;
  1303. if (child->thread.hw_brk.address)
  1304. return -ENOSPC;
  1305. child->thread.hw_brk = brk;
  1306. return 1;
  1307. #endif /* !CONFIG_PPC_ADV_DEBUG_DVCS */
  1308. }
  1309. static long ppc_del_hwdebug(struct task_struct *child, long data)
  1310. {
  1311. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  1312. int ret = 0;
  1313. struct thread_struct *thread = &(child->thread);
  1314. struct perf_event *bp;
  1315. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  1316. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1317. int rc;
  1318. if (data <= 4)
  1319. rc = del_instruction_bp(child, (int)data);
  1320. else
  1321. rc = del_dac(child, (int)data - 4);
  1322. if (!rc) {
  1323. if (!DBCR_ACTIVE_EVENTS(child->thread.dbcr0,
  1324. child->thread.dbcr1)) {
  1325. child->thread.dbcr0 &= ~DBCR0_IDM;
  1326. child->thread.regs->msr &= ~MSR_DE;
  1327. }
  1328. }
  1329. return rc;
  1330. #else
  1331. if (data != 1)
  1332. return -EINVAL;
  1333. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  1334. if (ptrace_get_breakpoints(child) < 0)
  1335. return -ESRCH;
  1336. bp = thread->ptrace_bps[0];
  1337. if (bp) {
  1338. unregister_hw_breakpoint(bp);
  1339. thread->ptrace_bps[0] = NULL;
  1340. } else
  1341. ret = -ENOENT;
  1342. ptrace_put_breakpoints(child);
  1343. return ret;
  1344. #else /* CONFIG_HAVE_HW_BREAKPOINT */
  1345. if (child->thread.hw_brk.address == 0)
  1346. return -ENOENT;
  1347. child->thread.hw_brk.address = 0;
  1348. child->thread.hw_brk.type = 0;
  1349. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  1350. return 0;
  1351. #endif
  1352. }
  1353. long arch_ptrace(struct task_struct *child, long request,
  1354. unsigned long addr, unsigned long data)
  1355. {
  1356. int ret = -EPERM;
  1357. void __user *datavp = (void __user *) data;
  1358. unsigned long __user *datalp = datavp;
  1359. switch (request) {
  1360. /* read the word at location addr in the USER area. */
  1361. case PTRACE_PEEKUSR: {
  1362. unsigned long index, tmp;
  1363. ret = -EIO;
  1364. /* convert to index and check */
  1365. #ifdef CONFIG_PPC32
  1366. index = addr >> 2;
  1367. if ((addr & 3) || (index > PT_FPSCR)
  1368. || (child->thread.regs == NULL))
  1369. #else
  1370. index = addr >> 3;
  1371. if ((addr & 7) || (index > PT_FPSCR))
  1372. #endif
  1373. break;
  1374. CHECK_FULL_REGS(child->thread.regs);
  1375. if (index < PT_FPR0) {
  1376. ret = ptrace_get_reg(child, (int) index, &tmp);
  1377. if (ret)
  1378. break;
  1379. } else {
  1380. unsigned int fpidx = index - PT_FPR0;
  1381. flush_fp_to_thread(child);
  1382. if (fpidx < (PT_FPSCR - PT_FPR0))
  1383. tmp = ((unsigned long *)child->thread.fpr)
  1384. [fpidx * TS_FPRWIDTH];
  1385. else
  1386. tmp = child->thread.fpscr.val;
  1387. }
  1388. ret = put_user(tmp, datalp);
  1389. break;
  1390. }
  1391. /* write the word at location addr in the USER area */
  1392. case PTRACE_POKEUSR: {
  1393. unsigned long index;
  1394. ret = -EIO;
  1395. /* convert to index and check */
  1396. #ifdef CONFIG_PPC32
  1397. index = addr >> 2;
  1398. if ((addr & 3) || (index > PT_FPSCR)
  1399. || (child->thread.regs == NULL))
  1400. #else
  1401. index = addr >> 3;
  1402. if ((addr & 7) || (index > PT_FPSCR))
  1403. #endif
  1404. break;
  1405. CHECK_FULL_REGS(child->thread.regs);
  1406. if (index < PT_FPR0) {
  1407. ret = ptrace_put_reg(child, index, data);
  1408. } else {
  1409. unsigned int fpidx = index - PT_FPR0;
  1410. flush_fp_to_thread(child);
  1411. if (fpidx < (PT_FPSCR - PT_FPR0))
  1412. ((unsigned long *)child->thread.fpr)
  1413. [fpidx * TS_FPRWIDTH] = data;
  1414. else
  1415. child->thread.fpscr.val = data;
  1416. ret = 0;
  1417. }
  1418. break;
  1419. }
  1420. case PPC_PTRACE_GETHWDBGINFO: {
  1421. struct ppc_debug_info dbginfo;
  1422. dbginfo.version = 1;
  1423. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1424. dbginfo.num_instruction_bps = CONFIG_PPC_ADV_DEBUG_IACS;
  1425. dbginfo.num_data_bps = CONFIG_PPC_ADV_DEBUG_DACS;
  1426. dbginfo.num_condition_regs = CONFIG_PPC_ADV_DEBUG_DVCS;
  1427. dbginfo.data_bp_alignment = 4;
  1428. dbginfo.sizeof_condition = 4;
  1429. dbginfo.features = PPC_DEBUG_FEATURE_INSN_BP_RANGE |
  1430. PPC_DEBUG_FEATURE_INSN_BP_MASK;
  1431. #ifdef CONFIG_PPC_ADV_DEBUG_DAC_RANGE
  1432. dbginfo.features |=
  1433. PPC_DEBUG_FEATURE_DATA_BP_RANGE |
  1434. PPC_DEBUG_FEATURE_DATA_BP_MASK;
  1435. #endif
  1436. #else /* !CONFIG_PPC_ADV_DEBUG_REGS */
  1437. dbginfo.num_instruction_bps = 0;
  1438. dbginfo.num_data_bps = 1;
  1439. dbginfo.num_condition_regs = 0;
  1440. #ifdef CONFIG_PPC64
  1441. dbginfo.data_bp_alignment = 8;
  1442. #else
  1443. dbginfo.data_bp_alignment = 4;
  1444. #endif
  1445. dbginfo.sizeof_condition = 0;
  1446. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  1447. dbginfo.features = PPC_DEBUG_FEATURE_DATA_BP_RANGE;
  1448. if (cpu_has_feature(CPU_FTR_DAWR))
  1449. dbginfo.features |= PPC_DEBUG_FEATURE_DATA_BP_DAWR;
  1450. #else
  1451. dbginfo.features = 0;
  1452. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  1453. #endif /* CONFIG_PPC_ADV_DEBUG_REGS */
  1454. if (!access_ok(VERIFY_WRITE, datavp,
  1455. sizeof(struct ppc_debug_info)))
  1456. return -EFAULT;
  1457. ret = __copy_to_user(datavp, &dbginfo,
  1458. sizeof(struct ppc_debug_info)) ?
  1459. -EFAULT : 0;
  1460. break;
  1461. }
  1462. case PPC_PTRACE_SETHWDEBUG: {
  1463. struct ppc_hw_breakpoint bp_info;
  1464. if (!access_ok(VERIFY_READ, datavp,
  1465. sizeof(struct ppc_hw_breakpoint)))
  1466. return -EFAULT;
  1467. ret = __copy_from_user(&bp_info, datavp,
  1468. sizeof(struct ppc_hw_breakpoint)) ?
  1469. -EFAULT : 0;
  1470. if (!ret)
  1471. ret = ppc_set_hwdebug(child, &bp_info);
  1472. break;
  1473. }
  1474. case PPC_PTRACE_DELHWDEBUG: {
  1475. ret = ppc_del_hwdebug(child, data);
  1476. break;
  1477. }
  1478. case PTRACE_GET_DEBUGREG: {
  1479. #ifndef CONFIG_PPC_ADV_DEBUG_REGS
  1480. unsigned long dabr_fake;
  1481. #endif
  1482. ret = -EINVAL;
  1483. /* We only support one DABR and no IABRS at the moment */
  1484. if (addr > 0)
  1485. break;
  1486. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  1487. ret = put_user(child->thread.dac1, datalp);
  1488. #else
  1489. dabr_fake = ((child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) |
  1490. (child->thread.hw_brk.type & HW_BRK_TYPE_DABR));
  1491. ret = put_user(dabr_fake, datalp);
  1492. #endif
  1493. break;
  1494. }
  1495. case PTRACE_SET_DEBUGREG:
  1496. ret = ptrace_set_debugreg(child, addr, data);
  1497. break;
  1498. #ifdef CONFIG_PPC64
  1499. case PTRACE_GETREGS64:
  1500. #endif
  1501. case PTRACE_GETREGS: /* Get all pt_regs from the child. */
  1502. return copy_regset_to_user(child, &user_ppc_native_view,
  1503. REGSET_GPR,
  1504. 0, sizeof(struct pt_regs),
  1505. datavp);
  1506. #ifdef CONFIG_PPC64
  1507. case PTRACE_SETREGS64:
  1508. #endif
  1509. case PTRACE_SETREGS: /* Set all gp regs in the child. */
  1510. return copy_regset_from_user(child, &user_ppc_native_view,
  1511. REGSET_GPR,
  1512. 0, sizeof(struct pt_regs),
  1513. datavp);
  1514. case PTRACE_GETFPREGS: /* Get the child FPU state (FPR0...31 + FPSCR) */
  1515. return copy_regset_to_user(child, &user_ppc_native_view,
  1516. REGSET_FPR,
  1517. 0, sizeof(elf_fpregset_t),
  1518. datavp);
  1519. case PTRACE_SETFPREGS: /* Set the child FPU state (FPR0...31 + FPSCR) */
  1520. return copy_regset_from_user(child, &user_ppc_native_view,
  1521. REGSET_FPR,
  1522. 0, sizeof(elf_fpregset_t),
  1523. datavp);
  1524. #ifdef CONFIG_ALTIVEC
  1525. case PTRACE_GETVRREGS:
  1526. return copy_regset_to_user(child, &user_ppc_native_view,
  1527. REGSET_VMX,
  1528. 0, (33 * sizeof(vector128) +
  1529. sizeof(u32)),
  1530. datavp);
  1531. case PTRACE_SETVRREGS:
  1532. return copy_regset_from_user(child, &user_ppc_native_view,
  1533. REGSET_VMX,
  1534. 0, (33 * sizeof(vector128) +
  1535. sizeof(u32)),
  1536. datavp);
  1537. #endif
  1538. #ifdef CONFIG_VSX
  1539. case PTRACE_GETVSRREGS:
  1540. return copy_regset_to_user(child, &user_ppc_native_view,
  1541. REGSET_VSX,
  1542. 0, 32 * sizeof(double),
  1543. datavp);
  1544. case PTRACE_SETVSRREGS:
  1545. return copy_regset_from_user(child, &user_ppc_native_view,
  1546. REGSET_VSX,
  1547. 0, 32 * sizeof(double),
  1548. datavp);
  1549. #endif
  1550. #ifdef CONFIG_SPE
  1551. case PTRACE_GETEVRREGS:
  1552. /* Get the child spe register state. */
  1553. return copy_regset_to_user(child, &user_ppc_native_view,
  1554. REGSET_SPE, 0, 35 * sizeof(u32),
  1555. datavp);
  1556. case PTRACE_SETEVRREGS:
  1557. /* Set the child spe register state. */
  1558. return copy_regset_from_user(child, &user_ppc_native_view,
  1559. REGSET_SPE, 0, 35 * sizeof(u32),
  1560. datavp);
  1561. #endif
  1562. default:
  1563. ret = ptrace_request(child, request, addr, data);
  1564. break;
  1565. }
  1566. return ret;
  1567. }
  1568. /*
  1569. * We must return the syscall number to actually look up in the table.
  1570. * This can be -1L to skip running any syscall at all.
  1571. */
  1572. long do_syscall_trace_enter(struct pt_regs *regs)
  1573. {
  1574. long ret = 0;
  1575. user_exit();
  1576. secure_computing_strict(regs->gpr[0]);
  1577. if (test_thread_flag(TIF_SYSCALL_TRACE) &&
  1578. tracehook_report_syscall_entry(regs))
  1579. /*
  1580. * Tracing decided this syscall should not happen.
  1581. * We'll return a bogus call number to get an ENOSYS
  1582. * error, but leave the original number in regs->gpr[0].
  1583. */
  1584. ret = -1L;
  1585. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  1586. trace_sys_enter(regs, regs->gpr[0]);
  1587. #ifdef CONFIG_PPC64
  1588. if (!is_32bit_task())
  1589. audit_syscall_entry(AUDIT_ARCH_PPC64,
  1590. regs->gpr[0],
  1591. regs->gpr[3], regs->gpr[4],
  1592. regs->gpr[5], regs->gpr[6]);
  1593. else
  1594. #endif
  1595. audit_syscall_entry(AUDIT_ARCH_PPC,
  1596. regs->gpr[0],
  1597. regs->gpr[3] & 0xffffffff,
  1598. regs->gpr[4] & 0xffffffff,
  1599. regs->gpr[5] & 0xffffffff,
  1600. regs->gpr[6] & 0xffffffff);
  1601. return ret ?: regs->gpr[0];
  1602. }
  1603. void do_syscall_trace_leave(struct pt_regs *regs)
  1604. {
  1605. int step;
  1606. audit_syscall_exit(regs);
  1607. if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
  1608. trace_sys_exit(regs, regs->result);
  1609. step = test_thread_flag(TIF_SINGLESTEP);
  1610. if (step || test_thread_flag(TIF_SYSCALL_TRACE))
  1611. tracehook_report_syscall_exit(regs, step);
  1612. user_enter();
  1613. }