ptrace.c 45 KB

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