Add save_registers() and save_signal_registers() to x86-64 as well.

Cc: Eduard - Gabriel Munteanu <eduard.munte...@linux360.ro>
Cc: Tomek Grabiec <tgrab...@gmail.com>
Cc: Vegard Nossum <vegard.nos...@gmail.com>
Signed-off-by: Pekka Enberg <penb...@cs.helsinki.fi>
---
 arch/x86/include/arch/registers_64.h |   75 +++++++++++++++++++++++++++++++---
 1 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/arch/registers_64.h 
b/arch/x86/include/arch/registers_64.h
index 057d97e..300bd80 100644
--- a/arch/x86/include/arch/registers_64.h
+++ b/arch/x86/include/arch/registers_64.h
@@ -1,11 +1,12 @@
-#ifndef __X86_REGISTERS_64_H
-#define __X86_REGISTERS_64_H
-
-#include <limits.h>
-#include <stdbool.h>
+#ifndef X86_REGISTERS_64_H
+#define X86_REGISTERS_64_H
 
 #include "vm/types.h"
 
+#include <ucontext.h>  /* for gregset_t */
+#include <stdbool.h>
+#include <limits.h>
+
 enum machine_reg {
        MACH_REG_RAX, /* R0 */
        MACH_REG_RCX, /* R1 */
@@ -62,4 +63,66 @@ const char *reg_name(enum machine_reg reg);
 enum machine_reg_type reg_type(enum machine_reg reg);
 bool reg_supports_type(enum machine_reg reg, enum vm_type type);
 
-#endif /* __X86_REGISTERS_64_H */
+struct register_state {
+       union {
+               unsigned long           regs[14];
+               struct {
+                       unsigned long   rax;
+                       unsigned long   rbx;
+                       unsigned long   rcx;
+                       unsigned long   rdx;
+                       unsigned long   rsi;
+                       unsigned long   rdi;
+                       unsigned long   r8;
+                       unsigned long   r9;
+                       unsigned long   r10;
+                       unsigned long   r11;
+                       unsigned long   r12;
+                       unsigned long   r13;
+                       unsigned long   r14;
+                       unsigned long   r15;
+               };
+       };
+};
+
+#define SAVE_REG(reg, dst)  \
+       __asm__ volatile ("movq %%" reg ", %0\n\t" : "=m"(dst))
+
+static inline void save_registers(struct register_state *regs)
+{
+       SAVE_REG("rax", regs->rax);
+       SAVE_REG("rbx", regs->rbx);
+       SAVE_REG("rcx", regs->rcx);
+       SAVE_REG("rdx", regs->rdx);
+       SAVE_REG("rsi", regs->rsi);
+       SAVE_REG("rdi", regs->rdi);
+       SAVE_REG("r8",  regs->r8);
+       SAVE_REG("r9",  regs->r9);
+       SAVE_REG("r10", regs->r10);
+       SAVE_REG("r11", regs->r11);
+       SAVE_REG("r12", regs->r12);
+       SAVE_REG("r13", regs->r13);
+       SAVE_REG("r14", regs->r14);
+       SAVE_REG("r15", regs->r15);
+}
+
+static inline void
+save_signal_registers(struct register_state *regs, gregset_t gregs)
+{
+        regs->rax      = gregs[REG_RAX];
+        regs->rbx      = gregs[REG_RBX];
+        regs->rcx      = gregs[REG_RCX];
+        regs->rdx      = gregs[REG_RDX];
+        regs->rsi      = gregs[REG_RSI];
+        regs->rdi      = gregs[REG_RDI];
+        regs->r8       = gregs[REG_R8];
+        regs->r9       = gregs[REG_R9];
+        regs->r10      = gregs[REG_R10];
+        regs->r11      = gregs[REG_R11];
+        regs->r12      = gregs[REG_R12];
+        regs->r13      = gregs[REG_R13];
+        regs->r14      = gregs[REG_R14];
+        regs->r15      = gregs[REG_R15];
+}
+
+#endif /* X86_REGISTERS_64_H */
-- 
1.5.6.3


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to