ptrace.c 46 KB

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