ptrace.c 46 KB

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