[PATCH] Return probe redesign: ppc64 specific implementation
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / ia64 / kernel / kprobes.c
CommitLineData
fd7b231f
AK
1/*
2 * Kernel Probes (KProbes)
3 * arch/ia64/kernel/kprobes.c
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *
19 * Copyright (C) IBM Corporation, 2002, 2004
20 * Copyright (C) Intel Corporation, 2005
21 *
22 * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy
23 * <anil.s.keshavamurthy@intel.com> adapted from i386
24 */
25
26#include <linux/config.h>
27#include <linux/kprobes.h>
28#include <linux/ptrace.h>
29#include <linux/spinlock.h>
30#include <linux/string.h>
31#include <linux/slab.h>
32#include <linux/preempt.h>
33#include <linux/moduleloader.h>
34
35#include <asm/pgtable.h>
36#include <asm/kdebug.h>
37
b2761dc2
AK
38extern void jprobe_inst_return(void);
39
fd7b231f
AK
40/* kprobe_status settings */
41#define KPROBE_HIT_ACTIVE 0x00000001
42#define KPROBE_HIT_SS 0x00000002
43
852caccc
AK
44static struct kprobe *current_kprobe, *kprobe_prev;
45static unsigned long kprobe_status, kprobe_status_prev;
b2761dc2 46static struct pt_regs jprobe_saved_regs;
fd7b231f
AK
47
48enum instruction_type {A, I, M, F, B, L, X, u};
49static enum instruction_type bundle_encoding[32][3] = {
50 { M, I, I }, /* 00 */
51 { M, I, I }, /* 01 */
52 { M, I, I }, /* 02 */
53 { M, I, I }, /* 03 */
54 { M, L, X }, /* 04 */
55 { M, L, X }, /* 05 */
56 { u, u, u }, /* 06 */
57 { u, u, u }, /* 07 */
58 { M, M, I }, /* 08 */
59 { M, M, I }, /* 09 */
60 { M, M, I }, /* 0A */
61 { M, M, I }, /* 0B */
62 { M, F, I }, /* 0C */
63 { M, F, I }, /* 0D */
64 { M, M, F }, /* 0E */
65 { M, M, F }, /* 0F */
66 { M, I, B }, /* 10 */
67 { M, I, B }, /* 11 */
68 { M, B, B }, /* 12 */
69 { M, B, B }, /* 13 */
70 { u, u, u }, /* 14 */
71 { u, u, u }, /* 15 */
72 { B, B, B }, /* 16 */
73 { B, B, B }, /* 17 */
74 { M, M, B }, /* 18 */
75 { M, M, B }, /* 19 */
76 { u, u, u }, /* 1A */
77 { u, u, u }, /* 1B */
78 { M, F, B }, /* 1C */
79 { M, F, B }, /* 1D */
80 { u, u, u }, /* 1E */
81 { u, u, u }, /* 1F */
82};
83
a5403183
AK
84/*
85 * In this function we check to see if the instruction
86 * is IP relative instruction and update the kprobe
87 * inst flag accordingly
88 */
89static void update_kprobe_inst_flag(uint template, uint slot, uint major_opcode,
90 unsigned long kprobe_inst, struct kprobe *p)
fd7b231f 91{
8bc76772
RL
92 p->ainsn.inst_flag = 0;
93 p->ainsn.target_br_reg = 0;
fd7b231f 94
a5403183
AK
95 if (bundle_encoding[template][slot] == B) {
96 switch (major_opcode) {
97 case INDIRECT_CALL_OPCODE:
98 p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG;
99 p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
100 break;
101 case IP_RELATIVE_PREDICT_OPCODE:
102 case IP_RELATIVE_BRANCH_OPCODE:
103 p->ainsn.inst_flag |= INST_FLAG_FIX_RELATIVE_IP_ADDR;
104 break;
105 case IP_RELATIVE_CALL_OPCODE:
106 p->ainsn.inst_flag |= INST_FLAG_FIX_RELATIVE_IP_ADDR;
107 p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG;
108 p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
109 break;
110 }
111 } else if (bundle_encoding[template][slot] == X) {
112 switch (major_opcode) {
113 case LONG_CALL_OPCODE:
114 p->ainsn.inst_flag |= INST_FLAG_FIX_BRANCH_REG;
115 p->ainsn.target_br_reg = ((kprobe_inst >> 6) & 0x7);
116 break;
117 }
118 }
119 return;
120}
fd7b231f 121
708de8f1
AK
122/*
123 * In this function we check to see if the instruction
124 * on which we are inserting kprobe is supported.
125 * Returns 0 if supported
126 * Returns -EINVAL if unsupported
127 */
128static int unsupported_inst(uint template, uint slot, uint major_opcode,
129 unsigned long kprobe_inst, struct kprobe *p)
130{
131 unsigned long addr = (unsigned long)p->addr;
132
133 if (bundle_encoding[template][slot] == I) {
134 switch (major_opcode) {
135 case 0x0: //I_UNIT_MISC_OPCODE:
136 /*
137 * Check for Integer speculation instruction
138 * - Bit 33-35 to be equal to 0x1
139 */
140 if (((kprobe_inst >> 33) & 0x7) == 1) {
141 printk(KERN_WARNING
142 "Kprobes on speculation inst at <0x%lx> not supported\n",
143 addr);
144 return -EINVAL;
145 }
146
147 /*
148 * IP relative mov instruction
149 * - Bit 27-35 to be equal to 0x30
150 */
151 if (((kprobe_inst >> 27) & 0x1FF) == 0x30) {
152 printk(KERN_WARNING
153 "Kprobes on \"mov r1=ip\" at <0x%lx> not supported\n",
154 addr);
155 return -EINVAL;
156
157 }
158 }
159 }
160 return 0;
161}
162
163
1674eafc
AK
164/*
165 * In this function we check to see if the instruction
166 * (qp) cmpx.crel.ctype p1,p2=r2,r3
167 * on which we are inserting kprobe is cmp instruction
168 * with ctype as unc.
169 */
170static uint is_cmp_ctype_unc_inst(uint template, uint slot, uint major_opcode,
171unsigned long kprobe_inst)
172{
173 cmp_inst_t cmp_inst;
174 uint ctype_unc = 0;
175
176 if (!((bundle_encoding[template][slot] == I) ||
177 (bundle_encoding[template][slot] == M)))
178 goto out;
179
180 if (!((major_opcode == 0xC) || (major_opcode == 0xD) ||
181 (major_opcode == 0xE)))
182 goto out;
183
184 cmp_inst.l = kprobe_inst;
185 if ((cmp_inst.f.x2 == 0) || (cmp_inst.f.x2 == 1)) {
186 /* Integere compare - Register Register (A6 type)*/
187 if ((cmp_inst.f.tb == 0) && (cmp_inst.f.ta == 0)
188 &&(cmp_inst.f.c == 1))
189 ctype_unc = 1;
190 } else if ((cmp_inst.f.x2 == 2)||(cmp_inst.f.x2 == 3)) {
191 /* Integere compare - Immediate Register (A8 type)*/
192 if ((cmp_inst.f.ta == 0) &&(cmp_inst.f.c == 1))
193 ctype_unc = 1;
194 }
195out:
196 return ctype_unc;
197}
198
a5403183
AK
199/*
200 * In this function we override the bundle with
201 * the break instruction at the given slot.
202 */
203static void prepare_break_inst(uint template, uint slot, uint major_opcode,
204 unsigned long kprobe_inst, struct kprobe *p)
205{
206 unsigned long break_inst = BREAK_INST;
207 bundle_t *bundle = &p->ainsn.insn.bundle;
208
209 /*
210 * Copy the original kprobe_inst qualifying predicate(qp)
1674eafc
AK
211 * to the break instruction iff !is_cmp_ctype_unc_inst
212 * because for cmp instruction with ctype equal to unc,
213 * which is a special instruction always needs to be
214 * executed regradless of qp
a5403183 215 */
1674eafc
AK
216 if (!is_cmp_ctype_unc_inst(template, slot, major_opcode, kprobe_inst))
217 break_inst |= (0x3f & kprobe_inst);
a5403183
AK
218
219 switch (slot) {
220 case 0:
221 bundle->quad0.slot0 = break_inst;
222 break;
223 case 1:
224 bundle->quad0.slot1_p0 = break_inst;
225 bundle->quad1.slot1_p1 = break_inst >> (64-46);
226 break;
227 case 2:
228 bundle->quad1.slot2 = break_inst;
229 break;
8bc76772 230 }
cd2675bf 231
a5403183
AK
232 /*
233 * Update the instruction flag, so that we can
234 * emulate the instruction properly after we
235 * single step on original instruction
236 */
237 update_kprobe_inst_flag(template, slot, major_opcode, kprobe_inst, p);
238}
239
240static inline void get_kprobe_inst(bundle_t *bundle, uint slot,
241 unsigned long *kprobe_inst, uint *major_opcode)
242{
243 unsigned long kprobe_inst_p0, kprobe_inst_p1;
244 unsigned int template;
245
246 template = bundle->quad0.template;
fd7b231f 247
fd7b231f 248 switch (slot) {
a5403183
AK
249 case 0:
250 *major_opcode = (bundle->quad0.slot0 >> SLOT0_OPCODE_SHIFT);
251 *kprobe_inst = bundle->quad0.slot0;
fd7b231f 252 break;
a5403183
AK
253 case 1:
254 *major_opcode = (bundle->quad1.slot1_p1 >> SLOT1_p1_OPCODE_SHIFT);
255 kprobe_inst_p0 = bundle->quad0.slot1_p0;
256 kprobe_inst_p1 = bundle->quad1.slot1_p1;
257 *kprobe_inst = kprobe_inst_p0 | (kprobe_inst_p1 << (64-46));
fd7b231f 258 break;
a5403183
AK
259 case 2:
260 *major_opcode = (bundle->quad1.slot2 >> SLOT2_OPCODE_SHIFT);
261 *kprobe_inst = bundle->quad1.slot2;
fd7b231f
AK
262 break;
263 }
a5403183 264}
fd7b231f 265
a5403183
AK
266static int valid_kprobe_addr(int template, int slot, unsigned long addr)
267{
268 if ((slot > 2) || ((bundle_encoding[template][1] == L) && slot > 1)) {
269 printk(KERN_WARNING "Attempting to insert unaligned kprobe at 0x%lx\n",
270 addr);
271 return -EINVAL;
8bc76772 272 }
a5403183
AK
273 return 0;
274}
275
852caccc
AK
276static inline void save_previous_kprobe(void)
277{
278 kprobe_prev = current_kprobe;
279 kprobe_status_prev = kprobe_status;
280}
281
282static inline void restore_previous_kprobe(void)
283{
284 current_kprobe = kprobe_prev;
285 kprobe_status = kprobe_status_prev;
286}
287
288static inline void set_current_kprobe(struct kprobe *p)
289{
290 current_kprobe = p;
291}
292
9508dbfe
RL
293static void kretprobe_trampoline(void)
294{
295}
296
297/*
298 * At this point the target function has been tricked into
299 * returning into our trampoline. Lookup the associated instance
300 * and then:
301 * - call the handler function
302 * - cleanup by marking the instance as unused
303 * - long jump back to the original return address
304 */
305int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
306{
307 struct kretprobe_instance *ri = NULL;
308 struct hlist_head *head;
309 struct hlist_node *node, *tmp;
310 unsigned long orig_ret_address = 0;
311 unsigned long trampoline_address =
312 ((struct fnptr *)kretprobe_trampoline)->ip;
313
314 head = kretprobe_inst_table_head(current);
315
316 /*
317 * It is possible to have multiple instances associated with a given
318 * task either because an multiple functions in the call path
319 * have a return probe installed on them, and/or more then one return
320 * return probe was registered for a target function.
321 *
322 * We can handle this because:
323 * - instances are always inserted at the head of the list
324 * - when multiple return probes are registered for the same
325 * function, the first instance's ret_addr will point to the
326 * real return address, and all the rest will point to
327 * kretprobe_trampoline
328 */
329 hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
330 if (ri->task != current)
331 /* another task is sharing our hash bucket */
332 continue;
333
334 if (ri->rp && ri->rp->handler)
335 ri->rp->handler(ri, regs);
336
337 orig_ret_address = (unsigned long)ri->ret_addr;
338 recycle_rp_inst(ri);
339
340 if (orig_ret_address != trampoline_address)
341 /*
342 * This is the real return address. Any other
343 * instances associated with this task are for
344 * other calls deeper on the call stack
345 */
346 break;
347 }
348
349 BUG_ON(!orig_ret_address || (orig_ret_address == trampoline_address));
350 regs->cr_iip = orig_ret_address;
351
352 unlock_kprobes();
353 preempt_enable_no_resched();
354
355 /*
356 * By returning a non-zero value, we are telling
357 * kprobe_handler() that we have handled unlocking
358 * and re-enabling preemption.
359 */
360 return 1;
361}
362
363void arch_prepare_kretprobe(struct kretprobe *rp, struct pt_regs *regs)
364{
365 struct kretprobe_instance *ri;
366
367 if ((ri = get_free_rp_inst(rp)) != NULL) {
368 ri->rp = rp;
369 ri->task = current;
370 ri->ret_addr = (kprobe_opcode_t *)regs->b0;
371
372 /* Replace the return addr with trampoline addr */
373 regs->b0 = ((struct fnptr *)kretprobe_trampoline)->ip;
374
375 add_rp_inst(ri);
376 } else {
377 rp->nmissed++;
378 }
379}
380
a5403183
AK
381int arch_prepare_kprobe(struct kprobe *p)
382{
383 unsigned long addr = (unsigned long) p->addr;
384 unsigned long *kprobe_addr = (unsigned long *)(addr & ~0xFULL);
385 unsigned long kprobe_inst=0;
386 unsigned int slot = addr & 0xf, template, major_opcode = 0;
387 bundle_t *bundle = &p->ainsn.insn.bundle;
388
389 memcpy(&p->opcode.bundle, kprobe_addr, sizeof(bundle_t));
390 memcpy(&p->ainsn.insn.bundle, kprobe_addr, sizeof(bundle_t));
391
392 template = bundle->quad0.template;
393
394 if(valid_kprobe_addr(template, slot, addr))
395 return -EINVAL;
396
397 /* Move to slot 2, if bundle is MLX type and kprobe slot is 1 */
398 if (slot == 1 && bundle_encoding[template][1] == L)
399 slot++;
400
401 /* Get kprobe_inst and major_opcode from the bundle */
402 get_kprobe_inst(bundle, slot, &kprobe_inst, &major_opcode);
403
708de8f1
AK
404 if (unsupported_inst(template, slot, major_opcode, kprobe_inst, p))
405 return -EINVAL;
406
a5403183 407 prepare_break_inst(template, slot, major_opcode, kprobe_inst, p);
8bc76772
RL
408
409 return 0;
410}
411
412void arch_arm_kprobe(struct kprobe *p)
413{
414 unsigned long addr = (unsigned long)p->addr;
415 unsigned long arm_addr = addr & ~0xFULL;
416
417 memcpy((char *)arm_addr, &p->ainsn.insn.bundle, sizeof(bundle_t));
fd7b231f
AK
418 flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
419}
420
421void arch_disarm_kprobe(struct kprobe *p)
422{
423 unsigned long addr = (unsigned long)p->addr;
424 unsigned long arm_addr = addr & ~0xFULL;
425
426 /* p->opcode contains the original unaltered bundle */
427 memcpy((char *) arm_addr, (char *) &p->opcode.bundle, sizeof(bundle_t));
428 flush_icache_range(arm_addr, arm_addr + sizeof(bundle_t));
429}
430
431void arch_remove_kprobe(struct kprobe *p)
432{
433}
434
435/*
436 * We are resuming execution after a single step fault, so the pt_regs
437 * structure reflects the register state after we executed the instruction
438 * located in the kprobe (p->ainsn.insn.bundle). We still need to adjust
cd2675bf
AK
439 * the ip to point back to the original stack address. To set the IP address
440 * to original stack address, handle the case where we need to fixup the
441 * relative IP address and/or fixup branch register.
fd7b231f
AK
442 */
443static void resume_execution(struct kprobe *p, struct pt_regs *regs)
444{
8bc76772 445 unsigned long bundle_addr = ((unsigned long) (&p->opcode.bundle)) & ~0xFULL;
cd2675bf
AK
446 unsigned long resume_addr = (unsigned long)p->addr & ~0xFULL;
447 unsigned long template;
448 int slot = ((unsigned long)p->addr & 0xf);
fd7b231f 449
cd2675bf
AK
450 template = p->opcode.bundle.quad0.template;
451
452 if (slot == 1 && bundle_encoding[template][1] == L)
453 slot = 2;
454
455 if (p->ainsn.inst_flag) {
456
457 if (p->ainsn.inst_flag & INST_FLAG_FIX_RELATIVE_IP_ADDR) {
458 /* Fix relative IP address */
459 regs->cr_iip = (regs->cr_iip - bundle_addr) + resume_addr;
460 }
461
462 if (p->ainsn.inst_flag & INST_FLAG_FIX_BRANCH_REG) {
463 /*
464 * Fix target branch register, software convention is
465 * to use either b0 or b6 or b7, so just checking
466 * only those registers
467 */
468 switch (p->ainsn.target_br_reg) {
469 case 0:
470 if ((regs->b0 == bundle_addr) ||
471 (regs->b0 == bundle_addr + 0x10)) {
472 regs->b0 = (regs->b0 - bundle_addr) +
473 resume_addr;
474 }
475 break;
476 case 6:
477 if ((regs->b6 == bundle_addr) ||
478 (regs->b6 == bundle_addr + 0x10)) {
479 regs->b6 = (regs->b6 - bundle_addr) +
480 resume_addr;
481 }
482 break;
483 case 7:
484 if ((regs->b7 == bundle_addr) ||
485 (regs->b7 == bundle_addr + 0x10)) {
486 regs->b7 = (regs->b7 - bundle_addr) +
487 resume_addr;
488 }
489 break;
490 } /* end switch */
491 }
492 goto turn_ss_off;
493 }
fd7b231f 494
cd2675bf
AK
495 if (slot == 2) {
496 if (regs->cr_iip == bundle_addr + 0x10) {
497 regs->cr_iip = resume_addr + 0x10;
498 }
499 } else {
500 if (regs->cr_iip == bundle_addr) {
501 regs->cr_iip = resume_addr;
502 }
a5403183 503 }
fd7b231f 504
cd2675bf
AK
505turn_ss_off:
506 /* Turn off Single Step bit */
507 ia64_psr(regs)->ss = 0;
fd7b231f
AK
508}
509
510static void prepare_ss(struct kprobe *p, struct pt_regs *regs)
511{
8bc76772 512 unsigned long bundle_addr = (unsigned long) &p->opcode.bundle;
fd7b231f
AK
513 unsigned long slot = (unsigned long)p->addr & 0xf;
514
515 /* Update instruction pointer (IIP) and slot number (IPSR.ri) */
516 regs->cr_iip = bundle_addr & ~0xFULL;
517
518 if (slot > 2)
519 slot = 0;
520
521 ia64_psr(regs)->ri = slot;
522
523 /* turn on single stepping */
524 ia64_psr(regs)->ss = 1;
525}
526
89cb14c0 527static int pre_kprobes_handler(struct die_args *args)
fd7b231f
AK
528{
529 struct kprobe *p;
530 int ret = 0;
89cb14c0 531 struct pt_regs *regs = args->regs;
fd7b231f
AK
532 kprobe_opcode_t *addr = (kprobe_opcode_t *)instruction_pointer(regs);
533
534 preempt_disable();
535
536 /* Handle recursion cases */
537 if (kprobe_running()) {
538 p = get_kprobe(addr);
539 if (p) {
540 if (kprobe_status == KPROBE_HIT_SS) {
541 unlock_kprobes();
542 goto no_kprobe;
543 }
852caccc
AK
544 /* We have reentered the pre_kprobe_handler(), since
545 * another probe was hit while within the handler.
546 * We here save the original kprobes variables and
547 * just single step on the instruction of the new probe
548 * without calling any user handlers.
549 */
550 save_previous_kprobe();
551 set_current_kprobe(p);
552 p->nmissed++;
553 prepare_ss(p, regs);
554 kprobe_status = KPROBE_REENTER;
555 return 1;
89cb14c0 556 } else if (args->err == __IA64_BREAK_JPROBE) {
fd7b231f
AK
557 /*
558 * jprobe instrumented function just completed
559 */
560 p = current_kprobe;
561 if (p->break_handler && p->break_handler(p, regs)) {
562 goto ss_probe;
563 }
89cb14c0
KA
564 } else {
565 /* Not our break */
566 goto no_kprobe;
fd7b231f
AK
567 }
568 }
569
570 lock_kprobes();
571 p = get_kprobe(addr);
572 if (!p) {
573 unlock_kprobes();
574 goto no_kprobe;
575 }
576
577 kprobe_status = KPROBE_HIT_ACTIVE;
852caccc 578 set_current_kprobe(p);
fd7b231f
AK
579
580 if (p->pre_handler && p->pre_handler(p, regs))
581 /*
582 * Our pre-handler is specifically requesting that we just
9508dbfe
RL
583 * do a return. This is used for both the jprobe pre-handler
584 * and the kretprobe trampoline
fd7b231f
AK
585 */
586 return 1;
587
588ss_probe:
589 prepare_ss(p, regs);
590 kprobe_status = KPROBE_HIT_SS;
591 return 1;
592
593no_kprobe:
594 preempt_enable_no_resched();
595 return ret;
596}
597
598static int post_kprobes_handler(struct pt_regs *regs)
599{
600 if (!kprobe_running())
601 return 0;
602
852caccc
AK
603 if ((kprobe_status != KPROBE_REENTER) && current_kprobe->post_handler) {
604 kprobe_status = KPROBE_HIT_SSDONE;
fd7b231f 605 current_kprobe->post_handler(current_kprobe, regs, 0);
852caccc 606 }
fd7b231f
AK
607
608 resume_execution(current_kprobe, regs);
609
852caccc
AK
610 /*Restore back the original saved kprobes variables and continue. */
611 if (kprobe_status == KPROBE_REENTER) {
612 restore_previous_kprobe();
613 goto out;
614 }
615
fd7b231f 616 unlock_kprobes();
852caccc
AK
617
618out:
fd7b231f
AK
619 preempt_enable_no_resched();
620 return 1;
621}
622
623static int kprobes_fault_handler(struct pt_regs *regs, int trapnr)
624{
625 if (!kprobe_running())
626 return 0;
627
628 if (current_kprobe->fault_handler &&
629 current_kprobe->fault_handler(current_kprobe, regs, trapnr))
630 return 1;
631
632 if (kprobe_status & KPROBE_HIT_SS) {
633 resume_execution(current_kprobe, regs);
634 unlock_kprobes();
635 preempt_enable_no_resched();
636 }
637
638 return 0;
639}
640
641int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
642 void *data)
643{
644 struct die_args *args = (struct die_args *)data;
645 switch(val) {
646 case DIE_BREAK:
89cb14c0 647 if (pre_kprobes_handler(args))
fd7b231f
AK
648 return NOTIFY_STOP;
649 break;
650 case DIE_SS:
651 if (post_kprobes_handler(args->regs))
652 return NOTIFY_STOP;
653 break;
654 case DIE_PAGE_FAULT:
655 if (kprobes_fault_handler(args->regs, args->trapnr))
656 return NOTIFY_STOP;
657 default:
658 break;
659 }
660 return NOTIFY_DONE;
661}
662
663int setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
664{
b2761dc2
AK
665 struct jprobe *jp = container_of(p, struct jprobe, kp);
666 unsigned long addr = ((struct fnptr *)(jp->entry))->ip;
fd7b231f 667
b2761dc2
AK
668 /* save architectural state */
669 jprobe_saved_regs = *regs;
670
671 /* after rfi, execute the jprobe instrumented function */
672 regs->cr_iip = addr & ~0xFULL;
673 ia64_psr(regs)->ri = addr & 0xf;
674 regs->r1 = ((struct fnptr *)(jp->entry))->gp;
675
676 /*
677 * fix the return address to our jprobe_inst_return() function
678 * in the jprobes.S file
679 */
680 regs->b0 = ((struct fnptr *)(jprobe_inst_return))->ip;
681
682 return 1;
fd7b231f
AK
683}
684
685int longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
686{
b2761dc2
AK
687 *regs = jprobe_saved_regs;
688 return 1;
fd7b231f 689}
9508dbfe
RL
690
691static struct kprobe trampoline_p = {
692 .pre_handler = trampoline_probe_handler
693};
694
695int __init arch_init(void)
696{
697 trampoline_p.addr =
698 (kprobe_opcode_t *)((struct fnptr *)kretprobe_trampoline)->ip;
699 return register_kprobe(&trampoline_p);
700}