| 1 |
/* -*- linux-c -*- |
| 2 |
* IA64 register access functions |
| 3 |
* Copyright (C) 2005 Intel Corporation. |
| 4 |
* |
| 5 |
* This file is part of systemtap, and is free software. You can |
| 6 |
* redistribute it and/or modify it under the terms of the GNU General |
| 7 |
* Public License (GPL); either version 2, or (at your option) any |
| 8 |
* later version. |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef _REGS_IA64_C_ |
| 12 |
#define _REGS_IA64_C_ |
| 13 |
|
| 14 |
#if defined __ia64__ |
| 15 |
|
| 16 |
struct ia64_stap_get_arbsp_param { |
| 17 |
unsigned long ip; |
| 18 |
unsigned long *address; |
| 19 |
}; |
| 20 |
|
| 21 |
static void ia64_stap_get_arbsp(struct unw_frame_info *info, void *arg) |
| 22 |
{ |
| 23 |
unsigned long ip; |
| 24 |
struct ia64_stap_get_arbsp_param *lp = arg; |
| 25 |
|
| 26 |
do { |
| 27 |
unw_get_ip(info, &ip); |
| 28 |
if (ip == 0) |
| 29 |
break; |
| 30 |
if (ip == lp->ip) { |
| 31 |
unw_get_bsp(info, (unsigned long*)&lp->address); |
| 32 |
return; |
| 33 |
} |
| 34 |
} while (unw_unwind(info) >= 0); |
| 35 |
lp->address = 0; |
| 36 |
} |
| 37 |
|
| 38 |
/* |
| 39 |
* bspcache: get cached unwound address from current BSP and |
| 40 |
* set a static local cache of the offset of unwound address |
| 41 |
* if the static local cache(variable) is not set. |
| 42 |
* The unwound address means the BSP value when the kprobe |
| 43 |
* was hit. This macro stores the difference of BSP between |
| 44 |
* when the kprobe was hit and when this macro was called. |
| 45 |
* Since the difference depends on how much stack is consumed |
| 46 |
* from when the kprobe was hit, this macro *MUST NOT* be put |
| 47 |
* on the path which several functions execute (in that case, |
| 48 |
* each time the difference is changed and this macro can't |
| 49 |
* return correct unwound address). |
| 50 |
*/ |
| 51 |
#define bspcache(cache, regs)\ |
| 52 |
if(regs) {\ |
| 53 |
static unsigned __offset = 0; /* probe local cache */\ |
| 54 |
static void * __ip = NULL; /* reference ip */\ |
| 55 |
unsigned long *bsp;\ |
| 56 |
asm volatile("{ flushrs }\n"); /* flushrs for fixing bsp */\ |
| 57 |
bsp = (void*)ia64_getreg(_IA64_REG_AR_BSP);\ |
| 58 |
if (__offset == 0) {\ |
| 59 |
struct ia64_stap_get_arbsp_param pa;\ |
| 60 |
pa.ip = regs->cr_iip;\ |
| 61 |
unw_init_running(ia64_stap_get_arbsp, &pa);\ |
| 62 |
if (pa.address != 0) {\ |
| 63 |
__offset = ia64_rse_num_regs(pa.address, bsp)\ |
| 64 |
-(regs->cr_ifs & 127);\ |
| 65 |
__ip = (void *)REG_IP(regs);\ |
| 66 |
cache = pa.address;\ |
| 67 |
}\ |
| 68 |
} else if ((void *)REG_IP(regs) == __ip)\ |
| 69 |
cache = ia64_rse_skip_regs(bsp,\ |
| 70 |
-(__offset + (regs->cr_ifs & 127)));\ |
| 71 |
} |
| 72 |
|
| 73 |
static long * |
| 74 |
__ia64_fetch_register(int regno, struct pt_regs *pt_regs, unsigned long **cache) |
| 75 |
{ |
| 76 |
struct ia64_stap_get_arbsp_param pa; |
| 77 |
|
| 78 |
if (regno == 12) |
| 79 |
return &pt_regs->r12; |
| 80 |
|
| 81 |
if (regno >= 8 && regno <= 11) |
| 82 |
return (long *)(&pt_regs->r8 + regno - 8); |
| 83 |
else if (regno < 32 || regno > 127) |
| 84 |
return NULL; |
| 85 |
|
| 86 |
if (!*cache) { |
| 87 |
pa.ip = pt_regs->cr_iip; |
| 88 |
unw_init_running(ia64_stap_get_arbsp, &pa); |
| 89 |
if (pa.address == 0) |
| 90 |
return NULL; |
| 91 |
*cache = pa.address; |
| 92 |
} |
| 93 |
|
| 94 |
return ia64_rse_skip_regs(*cache, regno-32); |
| 95 |
} |
| 96 |
|
| 97 |
static long |
| 98 |
ia64_fetch_register(int regno, struct pt_regs *pt_regs, unsigned long **cache) |
| 99 |
{ |
| 100 |
long *reg; |
| 101 |
reg = __ia64_fetch_register(regno, pt_regs, cache); |
| 102 |
return (reg != NULL)? *reg : 0; |
| 103 |
} |
| 104 |
|
| 105 |
static void ia64_store_register(int regno, |
| 106 |
struct pt_regs *pt_regs, |
| 107 |
unsigned long value) |
| 108 |
{ |
| 109 |
struct ia64_stap_get_arbsp_param pa; |
| 110 |
unsigned long rsc_save = 0; |
| 111 |
unsigned long *addr; |
| 112 |
|
| 113 |
if (regno >= 8 && regno <= 11) { |
| 114 |
addr =&pt_regs->r8; |
| 115 |
addr += regno - 8; |
| 116 |
*(addr) = value; |
| 117 |
return; |
| 118 |
} |
| 119 |
else if (regno < 32 || regno > 127) |
| 120 |
return; |
| 121 |
|
| 122 |
pa.ip = pt_regs->cr_iip; |
| 123 |
unw_init_running(ia64_stap_get_arbsp, &pa); |
| 124 |
if (pa.address == 0) |
| 125 |
return; |
| 126 |
*ia64_rse_skip_regs(pa.address, regno-32) = value; |
| 127 |
//Invalidate all stacked registers outside the current frame |
| 128 |
asm volatile( "mov %0=ar.rsc;;\n\t" |
| 129 |
"mov ar.rsc=0;;\n\t" |
| 130 |
"{\n\tloadrs;;\n\t\n\t\n\t}\n\t" |
| 131 |
"mov ar.rsc=%1\n\t" |
| 132 |
:"=r" (rsc_save):"r" (rsc_save):"memory"); |
| 133 |
|
| 134 |
return; |
| 135 |
} |
| 136 |
|
| 137 |
#endif /* if defined __ia64__ */ |
| 138 |
|
| 139 |
|
| 140 |
#endif /* _REGS_IA64_C_ */ |