This patch introduces a save_registers() function that can be used to
take a snapshot of general purpose registers. This is needed in the
gc_alloc() function to save registers in case we need to enter a
safepoint and need to scan them for references.

We also need a save_signal_registers() function for converting gregset_t
to struct register_state so we can pass register contents to the
gc_safepoint() function.

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_32.h |   52 +++++++++++++++++++++++++++++----
 1 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/arch/registers_32.h 
b/arch/x86/include/arch/registers_32.h
index 30fa29d..9b4c858 100644
--- a/arch/x86/include/arch/registers_32.h
+++ b/arch/x86/include/arch/registers_32.h
@@ -1,11 +1,11 @@
-#ifndef __X86_REGISTERS_32_H
-#define __X86_REGISTERS_32_H
+#ifndef X86_REGISTERS_32_H
+#define X86_REGISTERS_32_H
 
-#include <limits.h>
+#include "vm/types.h"
+
+#include <ucontext.h>  /* for gregset_t */
 #include <stdbool.h>
-#include <stdint.h>
-#include <assert.h>
-#include <vm/types.h>
+#include <limits.h>
 
 enum machine_reg {
        MACH_REG_EAX,
@@ -55,4 +55,42 @@ const char *reg_name(enum machine_reg reg);
 
 bool reg_supports_type(enum machine_reg reg, enum vm_type type);
 
-#endif /* __X86_REGISTERS_32_H */
+struct register_state {
+       union {
+               unsigned long           regs[6];
+               struct {
+                       unsigned long   eax;
+                       unsigned long   ebx;
+                       unsigned long   ecx;
+                       unsigned long   edi;
+                       unsigned long   edx;
+                       unsigned long   esi;
+               };
+       };
+};
+
+#define SAVE_REG(reg, dst)  \
+       __asm__ volatile ("movl %%" reg ", %0\n\t" : "=m"(dst))
+
+static inline void save_registers(struct register_state *regs)
+{
+       SAVE_REG("eax", regs->eax);
+       SAVE_REG("ebx", regs->ebx);
+       SAVE_REG("ecx", regs->ecx);
+       SAVE_REG("edx", regs->edx);
+       SAVE_REG("edi", regs->edi);
+       SAVE_REG("esi", regs->esi);
+}
+
+static inline void
+save_signal_registers(struct register_state *regs, gregset_t gregs)
+{
+        regs->eax = gregs[REG_EAX];
+        regs->ebx = gregs[REG_EBX];
+        regs->ecx = gregs[REG_ECX];
+        regs->edx = gregs[REG_EDX];
+        regs->esi = gregs[REG_ESI];
+        regs->edi = gregs[REG_EDI];
+}
+
+#endif /* X86_REGISTERS_32_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