public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: "liqin.chen" <liqin.chen@sunplusct.com>
To: Roland McGrath <roland@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Christoph Hellwig <hch@infradead.org>,
	linux-arch@vger.kernel.org, linux-arch-owner@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH V2] score: add regset support
Date: Fri, 10 Jul 2009 17:13:52 +0800	[thread overview]
Message-ID: <4A570650.3060309@sunplusct.com> (raw)

ptrace.c add register sets support for score architecture.

- genregs_get(struct task_struct *target,
           const struct user_regset *regset,
           unsigned int pos, unsigned int count,
           void *kbuf, void __user *ubuf)
    Retrieve the contents of score userspace general registers.

- genregs_set(struct task_struct *target,
           const struct user_regset *regset,
           unsigned int pos, unsigned int count,
           const void *kbuf, const void __user *ubuf)
    Update the contents of the score userspace general registers.

Signed-off-by: Chen Liqin <liqin.chen@sunplusct.com>
---
 arch/score/include/asm/elf.h    |   18 +++--
 arch/score/include/asm/ptrace.h |    2 +
 arch/score/kernel/ptrace.c      |  140 
++++++++++++++++++++++++++++++--------
 3 files changed, 123 insertions(+), 37 deletions(-)

diff --git a/arch/score/include/asm/elf.h b/arch/score/include/asm/elf.h
index 8324363..43526d9 100644
--- a/arch/score/include/asm/elf.h
+++ b/arch/score/include/asm/elf.h
@@ -1,9 +1,8 @@
 #ifndef _ASM_SCORE_ELF_H
 #define _ASM_SCORE_ELF_H
 
-/* ELF register definitions */
-#define ELF_NGREG    45
-#define ELF_NFPREG    33
+#include <linux/ptrace.h>
+
 #define EM_SCORE7    135
 
 /* Relocation types. */
@@ -30,11 +29,15 @@
 #define R_SCORE_IMM30        20
 #define R_SCORE_IMM32        21
 
-typedef unsigned long elf_greg_t;
-typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+/* ELF register definitions */
+typedef unsigned long    elf_greg_t;
+
+#define ELF_NGREG    (sizeof(struct pt_regs) / sizeof(elf_greg_t))
+typedef elf_greg_t    elf_gregset_t[ELF_NGREG];
 
-typedef double elf_fpreg_t;
-typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
+/* Score does not have fp regs. */
+typedef double        elf_fpreg_t;
+typedef elf_fpreg_t    elf_fpregset_t;
 
 #define elf_check_arch(x)    ((x)->e_machine == EM_SCORE7)
 
@@ -57,6 +60,7 @@ do {                                \
 struct task_struct;
 struct pt_regs;
 
+#define CORE_DUMP_USE_REGSET
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE    PAGE_SIZE
 
diff --git a/arch/score/include/asm/ptrace.h 
b/arch/score/include/asm/ptrace.h
index 66b14c8..19ce850 100644
--- a/arch/score/include/asm/ptrace.h
+++ b/arch/score/include/asm/ptrace.h
@@ -74,6 +74,8 @@ struct pt_regs {
 
 #ifdef __KERNEL__
 
+struct task_struct;
+
 /*
  * Does the process account for user or for system time?
  */
diff --git a/arch/score/kernel/ptrace.c b/arch/score/kernel/ptrace.c
index 1db876b..43784d8 100644
--- a/arch/score/kernel/ptrace.c
+++ b/arch/score/kernel/ptrace.c
@@ -23,11 +23,113 @@
  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <linux/elf.h>
 #include <linux/kernel.h>
 #include <linux/ptrace.h>
+#include <linux/regset.h>
 
 #include <asm/uaccess.h>
 
+/*
+ * retrieve the contents of SCORE userspace general registers
+ */
+static int genregs_get(struct task_struct *target,
+               const struct user_regset *regset,
+               unsigned int pos, unsigned int count,
+               void *kbuf, void __user *ubuf)
+{
+    const struct pt_regs *regs = task_pt_regs(target);
+    int ret;
+
+    /* skip 8 * sizeof(unsigned long) not use for pt_regs */
+    ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
+                    0, offsetof(struct pt_regs, regs));
+
+    /* r0 - r31 */
+    ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                  regs->regs,
+                  offsetof(struct pt_regs, regs),
+                  offsetof(struct pt_regs, cel));
+
+    if (!ret)
+        /* cel, ceh, sr0, sr1, sr2, epc, ema, psr, ecr, condition */
+        ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                    &regs->cel,
+                    offsetof(struct pt_regs, cel),
+                    offsetof(struct pt_regs, is_syscall));
+
+    if (!ret)
+        ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
+                        sizeof(struct pt_regs), -1);
+
+    return ret;
+}
+
+/*
+ * update the contents of the SCORE userspace general registers
+ */
+static int genregs_set(struct task_struct *target,
+               const struct user_regset *regset,
+               unsigned int pos, unsigned int count,
+               const void *kbuf, const void __user *ubuf)
+{
+    struct pt_regs *regs = task_pt_regs(target);
+    int ret;
+
+    /* skip 8 * sizeof(unsigned long) */
+    ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
+                    0, offsetof(struct pt_regs, regs));
+
+    /* r0 - r31 */
+    ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                  regs->regs,
+                  offsetof(struct pt_regs, regs),
+                  offsetof(struct pt_regs, cel));
+
+    if (!ret)
+        /* cel, ceh, sr0, sr1, sr2, epc, ema, psr, ecr, condition */
+        ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                    &regs->cel,
+                    offsetof(struct pt_regs, cel),
+                    offsetof(struct pt_regs, is_syscall));
+
+    if (!ret)
+        ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
+                        sizeof(struct pt_regs), -1);
+
+    return ret;
+}
+
+/*
+ * Define the register sets available on the score7 under Linux
+ */
+enum score7_regset {
+    REGSET_GENERAL,
+};
+
+static const struct user_regset score7_regsets[] = {
+    [REGSET_GENERAL] = {
+        .core_note_type    = NT_PRSTATUS,
+        .n        = ELF_NGREG,
+        .size        = sizeof(long),
+        .align        = sizeof(long),
+        .get        = genregs_get,
+        .set        = genregs_set,
+    },
+};
+
+static const struct user_regset_view user_score_native_view = {
+    .name        = "score7",
+    .e_machine    = EM_SCORE7,
+    .regsets    = score7_regsets,
+    .n        = ARRAY_SIZE(score7_regsets),
+};
+
+const struct user_regset_view *task_user_regset_view(struct task_struct 
*task)
+{
+    return &user_score_native_view;
+}
+
 static int is_16bitinsn(unsigned long insn)
 {
     if ((insn & INSN32_MASK) == INSN32_MASK)
@@ -80,34 +182,6 @@ write_tsk_long(struct task_struct *child,
     return copied != sizeof(val) ? -EIO : 0;
 }
 
-/*
- * Get all user integer registers.
- */
-static int ptrace_getregs(struct task_struct *tsk, void __user *uregs)
-{
-    struct pt_regs *regs = task_pt_regs(tsk);
-
-    return copy_to_user(uregs, regs, sizeof(struct pt_regs)) ? -EFAULT : 0;
-}
-
-/*
- * Set all user integer registers.
- */
-static int ptrace_setregs(struct task_struct *tsk, void __user *uregs)
-{
-    struct pt_regs newregs;
-    int ret;
-
-    ret = -EFAULT;
-    if (copy_from_user(&newregs, uregs, sizeof(struct pt_regs)) == 0) {
-        struct pt_regs *regs = task_pt_regs(tsk);
-        *regs = newregs;
-        ret = 0;
-    }
-
-    return ret;
-}
-
 void user_enable_single_step(struct task_struct *child)
 {
     /* far_epc is the target of branch */
@@ -356,11 +430,17 @@ arch_ptrace(struct task_struct *child, long 
request, long addr, long data)
     }
 
     case PTRACE_GETREGS:
-        ret = ptrace_getregs(child, (void __user *)datap);
+        return copy_regset_to_user(child, &user_score_native_view,
+                        REGSET_GENERAL,
+                        0, sizeof(struct pt_regs),
+                        (void __user *)datap);
         break;
 
     case PTRACE_SETREGS:
-        ret = ptrace_setregs(child, (void __user *)datap);
+        return copy_regset_from_user(child, &user_score_native_view,
+                        REGSET_GENERAL,
+                        0, sizeof(struct pt_regs),
+                        (const void __user *)datap);
         break;
 
     default:
-- 
1.6.2

             reply	other threads:[~2009-07-10  9:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10  9:13 liqin.chen [this message]
2009-07-10 12:49 ` [PATCH V2] score: add regset support Arnd Bergmann
2009-07-13  5:56   ` liqin.chen
2009-07-13 14:24     ` Arnd Bergmann
2009-07-14  1:42       ` liqin.chen
2009-07-15 20:18       ` Roland McGrath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A570650.3060309@sunplusct.com \
    --to=liqin.chen@sunplusct.com \
    --cc=arnd@arndb.de \
    --cc=hch@infradead.org \
    --cc=linux-arch-owner@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@redhat.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox