summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/thread/powerpc64
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
commit8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch)
treedf55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/thread/powerpc64
parentInitial commit. (diff)
downloadwasi-libc-upstream/0.0_git20221206.8b7148f.tar.xz
wasi-libc-upstream/0.0_git20221206.8b7148f.zip
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/thread/powerpc64')
-rw-r--r--libc-top-half/musl/src/thread/powerpc64/__set_thread_area.s9
-rw-r--r--libc-top-half/musl/src/thread/powerpc64/__unmapself.s9
-rw-r--r--libc-top-half/musl/src/thread/powerpc64/clone.s48
-rw-r--r--libc-top-half/musl/src/thread/powerpc64/syscall_cp.s44
4 files changed, 110 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/thread/powerpc64/__set_thread_area.s b/libc-top-half/musl/src/thread/powerpc64/__set_thread_area.s
new file mode 100644
index 0000000..bb9c55d
--- /dev/null
+++ b/libc-top-half/musl/src/thread/powerpc64/__set_thread_area.s
@@ -0,0 +1,9 @@
+.text
+.global __set_thread_area
+.hidden __set_thread_area
+.type __set_thread_area, %function
+__set_thread_area:
+ mr 13, 3
+ li 3, 0
+ blr
+
diff --git a/libc-top-half/musl/src/thread/powerpc64/__unmapself.s b/libc-top-half/musl/src/thread/powerpc64/__unmapself.s
new file mode 100644
index 0000000..c9360b4
--- /dev/null
+++ b/libc-top-half/musl/src/thread/powerpc64/__unmapself.s
@@ -0,0 +1,9 @@
+ .text
+ .global __unmapself
+ .type __unmapself,%function
+__unmapself:
+ li 0, 91 # __NR_munmap
+ sc
+ li 0, 1 #__NR_exit
+ sc
+ blr
diff --git a/libc-top-half/musl/src/thread/powerpc64/clone.s b/libc-top-half/musl/src/thread/powerpc64/clone.s
new file mode 100644
index 0000000..41cb678
--- /dev/null
+++ b/libc-top-half/musl/src/thread/powerpc64/clone.s
@@ -0,0 +1,48 @@
+.text
+.global __clone
+.hidden __clone
+.type __clone, %function
+__clone:
+ # int clone(fn, stack, flags, arg, ptid, tls, ctid)
+ # a b c d e f g
+ # 3 4 5 6 7 8 9
+ # pseudo C code:
+ # tid = syscall(SYS_clone,c,b,e,f,g);
+ # if (!tid) syscall(SYS_exit, a(d));
+ # return tid;
+
+ # create initial stack frame for new thread
+ clrrdi 4, 4, 4
+ li 0, 0
+ stdu 0,-32(4)
+
+ # save fn and arg to child stack
+ std 3, 8(4)
+ std 6, 16(4)
+
+ # shuffle args into correct registers and call SYS_clone
+ mr 3, 5
+ #mr 4, 4
+ mr 5, 7
+ mr 6, 8
+ mr 7, 9
+ li 0, 120 # SYS_clone = 120
+ sc
+
+ # if error, negate return (errno)
+ bns+ 1f
+ neg 3, 3
+
+1: # if we're the parent, return
+ cmpwi cr7, 3, 0
+ bnelr cr7
+
+ # we're the child. call fn(arg)
+ ld 3, 16(1)
+ ld 12, 8(1)
+ mtctr 12
+ bctrl
+
+ # call SYS_exit. exit code is already in r3 from fn return value
+ li 0, 1 # SYS_exit = 1
+ sc
diff --git a/libc-top-half/musl/src/thread/powerpc64/syscall_cp.s b/libc-top-half/musl/src/thread/powerpc64/syscall_cp.s
new file mode 100644
index 0000000..ef50ed0
--- /dev/null
+++ b/libc-top-half/musl/src/thread/powerpc64/syscall_cp.s
@@ -0,0 +1,44 @@
+ .global __cp_begin
+ .hidden __cp_begin
+ .global __cp_end
+ .hidden __cp_end
+ .global __cp_cancel
+ .hidden __cp_cancel
+ .hidden __cancel
+ .global __syscall_cp_asm
+ .hidden __syscall_cp_asm
+ .text
+ .type __syscall_cp_asm,%function
+__syscall_cp_asm:
+ # at enter: r3 = pointer to self->cancel, r4: syscall no, r5: first arg, r6: 2nd, r7: 3rd, r8: 4th, r9: 5th, r10: 6th
+__cp_begin:
+ # if (self->cancel) goto __cp_cancel
+ lwz 0, 0(3)
+ cmpwi cr7, 0, 0
+ bne- cr7, __cp_cancel
+
+ # make syscall
+ mr 0, 4
+ mr 3, 5
+ mr 4, 6
+ mr 5, 7
+ mr 6, 8
+ mr 7, 9
+ mr 8, 10
+ sc
+
+__cp_end:
+ # return error ? -r3 : r3
+ bnslr+
+ neg 3, 3
+ blr
+
+__cp_cancel:
+ mflr 0
+ bl 1f
+ .long .TOC.-.
+1: mflr 3
+ lwa 2, 0(3)
+ add 2, 2, 3
+ mtlr 0
+ b __cancel