aboutsummaryrefslogtreecommitdiff
path: root/src/libthread
diff options
context:
space:
mode:
Diffstat (limited to 'src/libthread')
-rw-r--r--src/libthread/Linux-arm-asm.s53
-rw-r--r--src/libthread/Linux.c40
2 files changed, 93 insertions, 0 deletions
diff --git a/src/libthread/Linux-arm-asm.s b/src/libthread/Linux-arm-asm.s
new file mode 100644
index 00000000..95c8aaac
--- /dev/null
+++ b/src/libthread/Linux-arm-asm.s
@@ -0,0 +1,53 @@
+
+.globl _tas
+_tas:
+ mov r3, #0xCA000000
+ add r3, r3, #0xFE0000
+ add r3, r3, #0xBA00
+ add r3, r3, #0xBE
+ swp r3, r3, [r0]
+ mov r0, r3
+ mov pc, lr
+
+.globl getmcontext
+getmcontext:
+ /* r0 will be overwritten */
+ str r1, [r0,#4]!
+ str r2, [r0,#4]!
+ str r3, [r0,#4]!
+ str r4, [r0,#4]!
+ str r5, [r0,#4]!
+ str r6, [r0,#4]!
+ str r7, [r0,#4]!
+ str r8, [r0,#4]!
+ str r9, [r0,#4]!
+ str r10, [r0,#4]!
+ str r11, [r0,#4]!
+ str r12, [r0,#4]!
+ str r13, [r0,#4]!
+ str r14, [r0,#4]!
+ /* r15 is pc */
+ mov r0, #0
+ mov pc, lr
+
+.globl setmcontext
+setmcontext:
+ /* r0 will be overwritten */
+ ldr r1, [r0,#4]!
+ ldr r2, [r0,#4]!
+ ldr r3, [r0,#4]!
+ ldr r4, [r0,#4]!
+ ldr r5, [r0,#4]!
+ ldr r6, [r0,#4]!
+ ldr r7, [r0,#4]!
+ ldr r8, [r0,#4]!
+ ldr r9, [r0,#4]!
+ ldr r10, [r0,#4]!
+ ldr r11, [r0,#4]!
+ ldr r12, [r0,#4]!
+ ldr r13, [r0,#4]!
+ ldr r14, [r0,#4]!
+ /* r15 is pc */
+ mov r0, #1
+ mov pc, lr
+
diff --git a/src/libthread/Linux.c b/src/libthread/Linux.c
index dab12d3f..5d033248 100644
--- a/src/libthread/Linux.c
+++ b/src/libthread/Linux.c
@@ -436,3 +436,43 @@ _threadpexit(void)
_exit(0);
}
+#ifdef __arm__
+extern int getmcontext(mcontext_t*);
+extern int setmcontext(const mcontext_t*);
+
+void
+makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
+{
+ int i, *sp;
+ va_list arg;
+
+ sp = (int*)uc->uc_stack.ss_sp+uc->uc_stack.ss_size/4;
+ va_start(arg, argc);
+ for(i=0; i<4 && i<argc; i++)
+ uc->uc_mcontext.gregs[0] = va_arg(arg, uint);
+ uc->uc_mcontext.gregs[13] = (uint)sp;
+ uc->uc_mcontext.gregs[14] = (uint)fn;
+}
+
+int
+getcontext(ucontext_t *uc)
+{
+ return getmcontext(&uc->uc_mcontext);
+}
+
+int
+setcontext(const ucontext_t *uc)
+{
+ setmcontext(&uc->uc_mcontext);
+ return 0; /* not reached */
+}
+
+int
+swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
+{
+ if(getcontext(oucp) == 0)
+ setcontext(ucp);
+ return 0;
+}
+#endif
+