summaryrefslogtreecommitdiffstats
path: root/src/uctx.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/uctx.h')
-rw-r--r--src/uctx.h39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/uctx.h b/src/uctx.h
index 03750e9..541fcf9 100644
--- a/src/uctx.h
+++ b/src/uctx.h
@@ -32,10 +32,32 @@ struct tf_uctx {
#if defined(__i386__)
+#define switch_fiber(prev, next) \
+ do { \
+ unsigned eax, ebx, ecx, edx, esi, edi; \
+ __asm__ __volatile__ ( \
+ "push %%ebp \n" \
+ "call 1f \n" \
+ "1: \n" \
+ "addl $2f-1b, (%%esp) \n" \
+ "movl %%esp, %[prev_sp] \n" \
+ "movl %[next_sp], %%esp \n" \
+ "ret \n" \
+ "2: \n" \
+ "pop %%ebp \n" \
+ : [prev_sp] "=m"(prev->current_sp), \
+ "=a"(eax), "=b"(ebx), "=c"(ecx), \
+ "=d"(edx), "=S"(esi), "=D"(edi) \
+ : [next_sp] "m"(next->current_sp) \
+ : "memory", "cc"); \
+ } while (0)
+
#define STACK_GROWS_UP
#else
-#error Your architecture is not supported. Send email to timo.teras@iki.fi.
+
+#error Your architecture is not supported. Contact timo.teras@iki.fi.
+
#endif
#if defined(STACK_GROWS_UP)
@@ -108,19 +130,6 @@ void tf_uctx_destroy(struct tf_fiber *fiber)
free(uctx->alloc);
}
-#define switch_fiber(oldspptr, newsp) \
- __asm__ __volatile__ ( \
- "push %%ebp ;" \
- "call .+5 ;" \
- "add $0x9,(%%esp) ;" \
- "mov %%esp, (%0) ;" \
- "mov %1, %%esp ;" \
- "ret ;" \
- "pop %%ebp" \
- : \
- : "a"(oldspptr), "d"(newsp) \
- : "%ebx", "%ecx", "%esi", "%edi", "memory", "cc");
-
static inline
void tf_uctx_transfer(struct tf_fiber *from, struct tf_fiber *to)
{
@@ -130,5 +139,5 @@ void tf_uctx_transfer(struct tf_fiber *from, struct tf_fiber *to)
/* Switch stack pointers */
TF_BUG_ON(*ufrom->stack_guard != STACK_GUARD);
- switch_fiber(&ufrom->current_sp, uto->current_sp);
+ switch_fiber(ufrom, uto);
}