ptrace.c 46 KB

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