s390: Add pt_regs register and stack access API
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Fri, 12 Feb 2010 12:38:40 +0000 (13:38 +0100)
committerFrederic Weisbecker <fweisbec@gmail.com>
Wed, 17 Feb 2010 12:19:26 +0000 (13:19 +0100)
This API is needed for the kprobe-based event tracer.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Reviewed-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
LKML-Reference: <20100212123840.GB27548@osiris.boeblingen.de.ibm.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
arch/s390/Kconfig
arch/s390/include/asm/ptrace.h
arch/s390/kernel/ptrace.c

index c80235206c017a89df2b365b5792845f3ecb850b..2590ce20157d889c49c52d56322bd4918aac00db 100644 (file)
@@ -87,6 +87,7 @@ config S390
        select HAVE_SYSCALL_TRACEPOINTS
        select HAVE_DYNAMIC_FTRACE
        select HAVE_FUNCTION_GRAPH_TRACER
+       select HAVE_REGS_AND_STACK_ACCESS_API
        select HAVE_DEFAULT_NO_SPIN_MUTEXES
        select HAVE_OPROFILE
        select HAVE_KPROBES
index 95dcf183a28df8565afe8892a8968c8c4bd2c23c..dd2d913afcaed7464dedab631b419a7a8ca719e6 100644 (file)
@@ -492,13 +492,24 @@ struct user_regs_struct
 struct task_struct;
 extern void user_enable_single_step(struct task_struct *);
 extern void user_disable_single_step(struct task_struct *);
+extern void show_regs(struct pt_regs * regs);
 
 #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0)
 #define instruction_pointer(regs) ((regs)->psw.addr & PSW_ADDR_INSN)
 #define user_stack_pointer(regs)((regs)->gprs[15])
 #define regs_return_value(regs)((regs)->gprs[2])
 #define profile_pc(regs) instruction_pointer(regs)
-extern void show_regs(struct pt_regs * regs);
+
+int regs_query_register_offset(const char *name);
+const char *regs_query_register_name(unsigned int offset);
+unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset);
+unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n);
+
+static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
+{
+       return regs->gprs[15] & PSW_ADDR_INSN;
+}
+
 #endif /* __KERNEL__ */
 #endif /* __ASSEMBLY__ */
 
index 13815d39f7dd2c757590c416298c71176f795f81..1720f380add54f11cc9e19737b7455942becc0af 100644 (file)
@@ -984,3 +984,61 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
 #endif
        return &user_s390_view;
 }
+
+static const char *gpr_names[NUM_GPRS] = {
+       "r0", "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",
+       "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
+};
+
+unsigned long regs_get_register(struct pt_regs *regs, unsigned int offset)
+{
+       if (offset >= NUM_GPRS)
+               return 0;
+       return regs->gprs[offset];
+}
+
+int regs_query_register_offset(const char *name)
+{
+       unsigned long offset;
+
+       if (!name || *name != 'r')
+               return -EINVAL;
+       if (strict_strtoul(name + 1, 10, &offset))
+               return -EINVAL;
+       if (offset >= NUM_GPRS)
+               return -EINVAL;
+       return offset;
+}
+
+const char *regs_query_register_name(unsigned int offset)
+{
+       if (offset >= NUM_GPRS)
+               return NULL;
+       return gpr_names[offset];
+}
+
+static int regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
+{
+       unsigned long ksp = kernel_stack_pointer(regs);
+
+       return (addr & ~(THREAD_SIZE - 1)) == (ksp & ~(THREAD_SIZE - 1));
+}
+
+/**
+ * regs_get_kernel_stack_nth() - get Nth entry of the stack
+ * @regs:pt_regs which contains kernel stack pointer.
+ * @n:stack entry number.
+ *
+ * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
+ * is specifined by @regs. If the @n th entry is NOT in the kernel stack,
+ * this returns 0.
+ */
+unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
+{
+       unsigned long addr;
+
+       addr = kernel_stack_pointer(regs) + n * sizeof(long);
+       if (!regs_within_kernel_stack(regs, addr))
+               return 0;
+       return *(unsigned long *)addr;
+}