ptrace.c 46 KB

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