__override_return_address() and __cleanup_args() will be needed
to implement exception throwing from jato functions with return
address substitution method.

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 arch/x86/include/arch/stack-frame.h |   61 +++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/arch/stack-frame.h 
b/arch/x86/include/arch/stack-frame.h
index 79fb318..743acc4 100644
--- a/arch/x86/include/arch/stack-frame.h
+++ b/arch/x86/include/arch/stack-frame.h
@@ -22,4 +22,65 @@ unsigned long slot_offset(struct stack_slot *slot);
 unsigned long frame_locals_size(struct stack_frame *frame);
 unsigned long cu_frame_locals_offset(struct compilation_unit *cu);
 
+/* Replaces C function's return address. */
+#define __override_return_address(ret)                 \
+       ({                                              \
+               volatile unsigned long *frame;          \
+                                                       \
+               frame = __builtin_frame_address(0);     \
+               frame[1] = (unsigned long)(ret);        \
+       })
+
+/*
+ * Removes current C function's arguments from frame.
+ *
+ *                          STACK
+ *
+ *                before              after
+ *              +---------+        +---------+
+ *              | arg0    |        | RET     |
+ *              +---------+        +---------+
+ *              | RET     |        | OLD EBP |
+ *              +---------+        +---------+ <- new EBP
+ *              | OLD EBP |        | local0  |
+ * EBP -------> +---------+        +---------+
+ *              + local0  +        + local1  +
+ *              +---------+        +---------+ <- new ESP
+ *              + local1  +        +         +
+ * ESP -------> +---------+        +---------+
+ *
+ */
+#ifdef CONFIG_X86_32
+#define __cleanup_args(args_size)              \
+       ({                                                              \
+       __asm__ volatile (                                              \
+            "movl %%ebp, %%esi \n"                                     \
+            "addl %1, %%esi \n"                                        \
+            "decl %%esi \n"                                            \
+                                                                       \
+            "movl %%esi, %%edi \n"                                     \
+            "addl %%ebx, %%edi \n"                                     \
+                                                                       \
+            "movl %%ebp, %%ecx \n"                                     \
+            "subl %%esp, %%ecx \n"                                     \
+            "addl %1, %%ecx \n"                                        \
+                                                                       \
+            "1: movb (%%esi), %%al \n"                                 \
+            "movb %%al, (%%edi) \n"                                    \
+            "decl %%esi \n"                                            \
+            "decl %%edi \n"                                            \
+            "decl %%ecx \n"                                            \
+            "jnz 1b \n"                                                \
+                                                                       \
+            "addl %%ebx, %%esp \n"                                     \
+            "addl %%ebx, %%ebp \n"                                     \
+            :                                                          \
+            : "b" (args_size), "n"(2*sizeof(unsigned long))            \
+            : "%eax", "%edi", "%esi", "%ecx"                           \
+                                                                       ); \
+       })
+#else
+ #error NOT IMPLEMENTED
+#endif
+
 #endif
-- 
1.6.0.6


------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to