ptrace.c 39 KB

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