ptrace.c 46 KB

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