Compare commits
138 Commits
libucontex
...
master
Author | SHA1 | Date |
---|---|---|
Ariadne Conill | d64402737b | |
Ariadne Conill | c3d26b7940 | |
Ariadne Conill | e07c8d0ac5 | |
Ariadne Conill | ed663cf0e5 | |
Ariadne Conill | f593205e95 | |
Ariadne Conill | a65049c8d4 | |
Ariadne Conill | 828fc9e950 | |
Ariadne Conill | 3e5059e8a1 | |
Ariadne Conill | 570c0c8b32 | |
Ariadne Conill | 998ae99d61 | |
Ariadne Conill | c2a8b0a9d5 | |
Ariadne Conill | e603fd7239 | |
Ariadne Conill | c468c50b7b | |
Ariadne Conill | c1ecb0ea59 | |
Ariadne Conill | 5445f70157 | |
Ariadne Conill | 1a2dff93e7 | |
L. Pereira | 7badd2d5b2 | |
Jim Hauxwell | 4975ba9051 | |
Jim Hauxwell | b3cbfd9c1a | |
Sören Tempel | d0b03541bf | |
Volker Christian | 124a962b39 | |
Volker Christian | 9e5de65076 | |
Volker Christian | 076e69c9c1 | |
matoro | be80075e95 | |
Ariadne Conill | 4c2cfc54ac | |
L. Pereira | 0f625a86ee | |
Ismael Luceno | 8e1397f5a2 | |
Ariadne Conill | 33ff253d52 | |
Richard Campbell | 3044c2b908 | |
Ariadne Conill | 128e4fdc4b | |
Richard Campbell | 5244775fb9 | |
Richard Campbell | 9abcd8afe0 | |
Richard Campbell | 7bc3e90984 | |
Ariadne Conill | 4dde3417b4 | |
Ariadne Conill | 6ec3e63877 | |
Ariadne Conill | 69ebc5e51b | |
Ariadne Conill | 0a72eff002 | |
Ariadne Conill | 973e61441a | |
Ariadne Conill | 00128f7575 | |
Ariadne Conill | 7fc08a6dc6 | |
Ariadne Conill | e26a93806e | |
Ariadne Conill | 5d2f30f96a | |
Ariadne Conill | a51dce6e2c | |
Ariadne Conill | a5ed584aa8 | |
Ariadne Conill | 9943d4f5fc | |
Ariadne Conill | 9403b481bc | |
Ariadne Conill | 2c0c0e5d29 | |
Ariadne Conill | c8fe721e69 | |
Ariadne Conill | c50182d98c | |
Ariadne Conill | 55c91428ba | |
Ariadne Conill | 18aa732212 | |
Ariadne Conill | 8215aedb56 | |
Ariadne Conill | 8efa9e8b85 | |
Torrekie Gen | 6ddefbbbb4 | |
Ariadne Conill | b1b4fe9665 | |
Richard Campbell | 1e37bf30f9 | |
Ariadne Conill | 14d9859c00 | |
Richard Campbell | 06303df1cd | |
Ariadne Conill | ae058b1f38 | |
Peng Fan | a182fee66a | |
Ariadne Conill | 0108623531 | |
Khem Raj | a530eed9e7 | |
Ariadne Conill | 335ee864ef | |
Ariadne Conill | 4d8abf9b3b | |
Ariadne Conill | 7b8f3f6d04 | |
Ariadne Conill | fb1d203677 | |
Ariadne Conill | 1ad20e03e5 | |
Ariadne Conill | 464f98a01b | |
osy | 9b1d8f01a6 | |
osy | 5d66c194a7 | |
osy | f3e1b876c7 | |
Ariadne Conill | f04d423e63 | |
Leandro Pereira | 7823593b6f | |
Ariadne Conill | 7df60a2504 | |
Ariadne Conill | b757e1268c | |
Ariadne Conill | c4b5fedc1d | |
Ariadne Conill | 63b15f130a | |
Ariadne Conill | 98d7493b2a | |
Ariadne Conill | 9affe94dee | |
Daniel Kolesa | f3e0033a06 | |
Daniel Kolesa | 4801f0bdd8 | |
Daniel Kolesa | 739894e9a7 | |
Daniel Kolesa | efa6464e41 | |
osy | d592961b1a | |
Ariadne Conill | b1902729f7 | |
Ariadne Conill | 5546fde1e5 | |
Ariadne Conill | 09f78ddc28 | |
osy | fffb55011b | |
osy | f7eed30132 | |
Ariadne Conill | 3064ad6dbc | |
osy | 9983d136af | |
osy | d31c95a11a | |
Ariadne Conill | e4233715f3 | |
osy | 163c11d989 | |
osy | b6e60b5d64 | |
osy | 73d5e101ad | |
Ariadne Conill | e45956896a | |
osy | e1e6508af2 | |
Ariadne Conill | 638770cfd0 | |
Ariadne Conill | 78e880a29f | |
Ariadne Conill | 39a2958561 | |
Ariadne Conill | 5e6e421c54 | |
Ariadne Conill | 91c8837c93 | |
Daniel Kolesa | cf05112306 | |
Daniel Kolesa | 6026980cac | |
Daniel Kolesa | 03927d4c4c | |
Ariadne Conill | d81154a61c | |
Ariadne Conill | 11a40293be | |
Ariadne Conill | 6763b5ba1e | |
Ariadne Conill | c986ba340e | |
Ariadne Conill | 22b91690bc | |
Ariadne Conill | afcca79d7b | |
Ariadne Conill | a6a64b0711 | |
Ariadne Conill | 388edbe121 | |
Ariadne Conill | 3123bfdd9b | |
Ariadne Conill | b6542e1a6a | |
Ariadne Conill | b62ecd476c | |
Ariadne Conill | 09d3f81dcf | |
Ariadne Conill | 2d51d7bfa4 | |
Ariadne Conill | 71cbb6a3d3 | |
Ariadne Conill | 5c3ca5a7e1 | |
Ariadne Conill | 8d58adb3ba | |
Ariadne Conill | dd7ef8a806 | |
Ariadne Conill | f9a3f65f5b | |
Ariadne Conill | 82f734ab47 | |
Ariadne Conill | da3c8d170f | |
Ariadne Conill | a42fb86da0 | |
Ariadne Conill | 00261d70e8 | |
Ariadne Conill | fd06f42bc3 | |
Ariadne Conill | 2692ecf74a | |
Ariadne Conill | 42a4fbe9d1 | |
Ariadne Conill | de399ebdbf | |
Ariadne Conill | 4ea37b1877 | |
Ariadne Conill | 634145cc40 | |
Ariadne Conill | 04b5520a61 | |
Ariadne Conill | 2688747f8a | |
Ariadne Conill | ed1e5752fc | |
Ariadne Conill | 27d8a515e1 |
|
@ -1,7 +1,15 @@
|
||||||
include/libucontext/bits.h
|
|
||||||
*.o
|
*.o
|
||||||
|
examples/cooperative_threading
|
||||||
test_libucontext
|
test_libucontext
|
||||||
|
test_libucontext_posix
|
||||||
|
test_libucontext_bare_posixabi
|
||||||
libucontext.a
|
libucontext.a
|
||||||
libucontext.so
|
libucontext.so
|
||||||
libucontext.so.*
|
libucontext.so.*
|
||||||
|
libucontext_posix.a
|
||||||
|
libucontext_posix.so
|
||||||
|
libucontext_posix.so.*
|
||||||
libucontext.pc
|
libucontext.pc
|
||||||
|
*.tar.xz
|
||||||
|
core
|
||||||
|
*.core
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
pipeline:
|
||||||
|
build-x86_64:
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache build-base
|
||||||
|
- make check ARCH=x86_64
|
||||||
|
when:
|
||||||
|
platform: linux/amd64
|
||||||
|
|
||||||
|
build-s390x:
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache build-base
|
||||||
|
- make check ARCH=s390x
|
||||||
|
when:
|
||||||
|
platform: linux/s390x
|
||||||
|
|
||||||
|
build-ppc64le:
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache build-base
|
||||||
|
- make check ARCH=ppc64le
|
||||||
|
when:
|
||||||
|
platform: linux/ppc64le
|
||||||
|
|
||||||
|
build-armv7:
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache build-base
|
||||||
|
- make check ARCH=arm
|
||||||
|
when:
|
||||||
|
platform: linux/arm
|
||||||
|
|
||||||
|
build-aarch64:
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- apk add --no-cache build-base
|
||||||
|
- make check ARCH=aarch64
|
||||||
|
when:
|
||||||
|
platform: linux/arm64
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2018-2020 Ariadne Conill <ariadne@dereferenced.org>
|
Copyright (c) 2018-2022 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
232
Makefile
232
Makefile
|
@ -4,58 +4,136 @@ ARCH := $(shell uname -m)
|
||||||
ifeq ($(ARCH),$(filter $(ARCH),i386 i686))
|
ifeq ($(ARCH),$(filter $(ARCH),i386 i686))
|
||||||
override ARCH = x86
|
override ARCH = x86
|
||||||
endif
|
endif
|
||||||
|
ifeq ($(ARCH),$(filter $(ARCH),sh2 sh4))
|
||||||
|
override ARCH = sh
|
||||||
|
endif
|
||||||
|
ifeq ($(ARCH),$(filter $(ARCH),ppc64le))
|
||||||
|
override ARCH = ppc64
|
||||||
|
endif
|
||||||
|
ifeq ($(ARCH),$(filter $(ARCH),armv7l))
|
||||||
|
override ARCH = arm
|
||||||
|
endif
|
||||||
|
ifeq ($(ARCH),$(filter $(ARCH),arm64))
|
||||||
|
override ARCH = aarch64
|
||||||
|
endif
|
||||||
|
|
||||||
LIBDIR := /lib
|
prefix = /usr
|
||||||
INCLUDEDIR := /usr/include
|
libdir = ${prefix}/lib
|
||||||
PKGCONFIGDIR := /usr/lib/pkgconfig
|
shared_libdir = ${libdir}
|
||||||
CFLAGS := -ggdb3 -O2 -Wall
|
static_libdir = ${libdir}
|
||||||
|
includedir = ${prefix}/include
|
||||||
|
pkgconfigdir = ${prefix}/lib/pkgconfig
|
||||||
|
|
||||||
|
CFLAGS ?= -ggdb3 -O2 -Wall
|
||||||
CPPFLAGS := -Iinclude -Iarch/${ARCH} -Iarch/common
|
CPPFLAGS := -Iinclude -Iarch/${ARCH} -Iarch/common
|
||||||
EXPORT_UNPREFIXED := yes
|
ifneq ($(shell uname),Darwin)
|
||||||
|
EXPORT_UNPREFIXED := yes
|
||||||
|
else
|
||||||
|
# Darwin does not support aliases
|
||||||
|
EXPORT_UNPREFIXED := no
|
||||||
|
CPPFLAGS += -D_XOPEN_SOURCE
|
||||||
|
endif
|
||||||
FREESTANDING := no
|
FREESTANDING := no
|
||||||
|
|
||||||
ifeq ($(FREESTANDING),yes)
|
ifeq ($(FREESTANDING),yes)
|
||||||
CFLAGS += -DFREESTANDING -isystem arch/${ARCH}/freestanding
|
CPPFLAGS += -DFREESTANDING
|
||||||
EXPORT_UNPREFIXED = no
|
EXPORT_UNPREFIXED = no -Iarch/${ARCH}/include
|
||||||
|
else
|
||||||
|
CPPFLAGS += -Iarch/common/include
|
||||||
|
endif
|
||||||
|
|
||||||
|
# ARM hard float support is presently broken.
|
||||||
|
FORCE_SOFT_FLOAT := yes
|
||||||
|
|
||||||
|
ifeq ($(FORCE_SOFT_FLOAT),yes)
|
||||||
|
CPPFLAGS += -DFORCE_SOFT_FLOAT
|
||||||
|
endif
|
||||||
|
|
||||||
|
FORCE_HARD_FLOAT := no
|
||||||
|
|
||||||
|
ifeq ($(FORCE_HARD_FLOAT),yes)
|
||||||
|
CPPFLAGS += -DFORCE_HARD_FLOAT
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(EXPORT_UNPREFIXED),yes)
|
ifeq ($(EXPORT_UNPREFIXED),yes)
|
||||||
CFLAGS += -DEXPORT_UNPREFIXED
|
CPPFLAGS += -DEXPORT_UNPREFIXED
|
||||||
endif
|
endif
|
||||||
|
|
||||||
LIBUCONTEXT_C_SRC = $(wildcard arch/${ARCH}/*.c)
|
LIBUCONTEXT_C_SRC = $(wildcard arch/${ARCH}/*.c)
|
||||||
LIBUCONTEXT_S_SRC = $(wildcard arch/${ARCH}/*.S)
|
LIBUCONTEXT_S_SRC = $(wildcard arch/${ARCH}/*.S)
|
||||||
|
|
||||||
LIBUCONTEXT_VERSION := 0.13.1
|
ifeq ($(shell test -d arch/${ARCH}/include; echo $?),0)
|
||||||
|
CPPFLAGS += -Iarch/${ARCH}/include
|
||||||
|
endif
|
||||||
|
|
||||||
|
LIBUCONTEXT_VERSION := $(shell head -n 1 VERSION)
|
||||||
LIBUCONTEXT_OBJ = ${LIBUCONTEXT_C_SRC:.c=.o} ${LIBUCONTEXT_S_SRC:.S=.o}
|
LIBUCONTEXT_OBJ = ${LIBUCONTEXT_C_SRC:.c=.o} ${LIBUCONTEXT_S_SRC:.S=.o}
|
||||||
LIBUCONTEXT_SOVERSION = 0
|
LIBUCONTEXT_SOVERSION = 1
|
||||||
LIBUCONTEXT_NAME = libucontext.so
|
ifeq ($(shell uname),Darwin)
|
||||||
|
LIBUCONTEXT_NAME = libucontext.dylib
|
||||||
|
LIBUCONTEXT_SONAME = libucontext.${LIBUCONTEXT_SOVERSION}.dylib
|
||||||
|
LIBUCONTEXT_POSIX_NAME = libucontext_posix.dylib
|
||||||
|
LIBUCONTEXT_POSIX_SONAME = libucontext_posix.${LIBUCONTEXT_SOVERSION}.dylib
|
||||||
|
LIBUCONTEXT_LINKER_FLAGS = -Wl,-dynamiclib,-install_name,${LIBUCONTEXT_SONAME},-current_version,${LIBUCONTEXT_SOVERSION},-compatibility_version,${LIBUCONTEXT_SOVERSION}
|
||||||
|
LIBUCONTEXT_POSIX_LINKER_FLAGS = -Wl,-dynamiclib,-install_name,${LIBUCONTEXT_POSIX_SONAME},-current_version,${LIBUCONTEXT_SOVERSION},-compatibility_version,${LIBUCONTEXT_SOVERSION}
|
||||||
|
else
|
||||||
|
LIBUCONTEXT_NAME = libucontext.so
|
||||||
|
LIBUCONTEXT_SONAME = libucontext.so.${LIBUCONTEXT_SOVERSION}
|
||||||
|
LIBUCONTEXT_POSIX_NAME = libucontext_posix.so
|
||||||
|
LIBUCONTEXT_POSIX_SONAME = libucontext_posix.so.${LIBUCONTEXT_SOVERSION}
|
||||||
|
LIBUCONTEXT_LINKER_FLAGS = -shared -Wl,-soname,${LIBUCONTEXT_SONAME} -Wl,-z,noexecstack
|
||||||
|
LIBUCONTEXT_POSIX_LINKER_FLAGS = -shared -Wl,-soname,${LIBUCONTEXT_POSIX_SONAME} -Wl,-z,noexecstack
|
||||||
|
ASFLAGS = -Wa,--noexecstack
|
||||||
|
endif
|
||||||
LIBUCONTEXT_STATIC_NAME = libucontext.a
|
LIBUCONTEXT_STATIC_NAME = libucontext.a
|
||||||
LIBUCONTEXT_PC = libucontext.pc
|
LIBUCONTEXT_PC = libucontext.pc
|
||||||
LIBUCONTEXT_SONAME = libucontext.so.${LIBUCONTEXT_SOVERSION}
|
LIBUCONTEXT_PATH = ${shared_libdir}/${LIBUCONTEXT_SONAME}
|
||||||
LIBUCONTEXT_PATH = ${LIBDIR}/${LIBUCONTEXT_SONAME}
|
LIBUCONTEXT_STATIC_PATH = ${static_libdir}/${LIBUCONTEXT_STATIC_NAME}
|
||||||
LIBUCONTEXT_STATIC_PATH = ${LIBDIR}/${LIBUCONTEXT_STATIC_NAME}
|
|
||||||
LIBUCONTEXT_HEADERS = \
|
LIBUCONTEXT_HEADERS = \
|
||||||
include/libucontext/libucontext.h \
|
include/libucontext/libucontext.h
|
||||||
include/libucontext/bits.h
|
ifeq ($(FREESTANDING),yes)
|
||||||
|
LIBUCONTEXT_HEADERS += arch/${ARCH}/include/libucontext/bits.h
|
||||||
|
else
|
||||||
|
LIBUCONTEXT_HEADERS += arch/common/include/libucontext/bits.h
|
||||||
|
endif
|
||||||
LIBUCONTEXT_EXAMPLES = \
|
LIBUCONTEXT_EXAMPLES = \
|
||||||
examples/cooperative_threading
|
examples/cooperative_threading
|
||||||
|
LIBUCONTEXT_POSIX_STATIC_NAME = libucontext_posix.a
|
||||||
|
LIBUCONTEXT_POSIX_C_SRC = libucontext_posix.c
|
||||||
|
LIBUCONTEXT_POSIX_OBJ = ${LIBUCONTEXT_POSIX_C_SRC:.c=.o}
|
||||||
|
LIBUCONTEXT_POSIX_PATH = ${shared_libdir}/${LIBUCONTEXT_POSIX_SONAME}
|
||||||
|
LIBUCONTEXT_POSIX_STATIC_PATH = ${static_libdir}/${LIBUCONTEXT_POSIX_STATIC_NAME}
|
||||||
|
|
||||||
all: ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_PC}
|
ifeq ($(FREESTANDING),yes)
|
||||||
|
LIBUCONTEXT_POSIX_NAME =
|
||||||
|
LIBUCONTEXT_POSIX_STATIC_NAME =
|
||||||
|
endif
|
||||||
|
|
||||||
|
all: ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_POSIX_NAME} ${LIBUCONTEXT_POSIX_STATIC_NAME} ${LIBUCONTEXT_PC}
|
||||||
|
|
||||||
|
${LIBUCONTEXT_POSIX_NAME}: ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_POSIX_OBJ}
|
||||||
|
$(CC) -fPIC -o ${LIBUCONTEXT_POSIX_NAME} ${LIBUCONTEXT_POSIX_LINKER_FLAGS} ${LIBUCONTEXT_POSIX_OBJ} -L. -lucontext ${LDFLAGS}
|
||||||
|
|
||||||
|
${LIBUCONTEXT_POSIX_STATIC_NAME}: ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_POSIX_OBJ}
|
||||||
|
$(AR) rcs ${LIBUCONTEXT_POSIX_STATIC_NAME} ${LIBUCONTEXT_POSIX_OBJ}
|
||||||
|
|
||||||
|
${LIBUCONTEXT_POSIX_SONAME}: ${LIBUCONTEXT_POSIX_NAME}
|
||||||
|
ln -sf ${LIBUCONTEXT_POSIX_NAME} ${LIBUCONTEXT_POSIX_SONAME}
|
||||||
|
|
||||||
${LIBUCONTEXT_STATIC_NAME}: ${LIBUCONTEXT_OBJ}
|
${LIBUCONTEXT_STATIC_NAME}: ${LIBUCONTEXT_OBJ}
|
||||||
$(AR) rcs ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_OBJ}
|
$(AR) rcs ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_OBJ}
|
||||||
|
|
||||||
${LIBUCONTEXT_NAME}: ${LIBUCONTEXT_HEADERS} ${LIBUCONTEXT_OBJ}
|
${LIBUCONTEXT_NAME}: ${LIBUCONTEXT_OBJ}
|
||||||
$(CC) -fPIC -o ${LIBUCONTEXT_NAME} -Wl,-soname,${LIBUCONTEXT_SONAME} \
|
$(CC) -fPIC -o ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_LINKER_FLAGS} ${LIBUCONTEXT_OBJ} ${LDFLAGS}
|
||||||
-shared ${LIBUCONTEXT_OBJ} ${LDFLAGS}
|
|
||||||
|
|
||||||
${LIBUCONTEXT_SONAME}: ${LIBUCONTEXT_NAME}
|
${LIBUCONTEXT_SONAME}: ${LIBUCONTEXT_NAME}
|
||||||
ln -sf ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_SONAME}
|
ln -sf ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_SONAME}
|
||||||
|
|
||||||
${LIBUCONTEXT_PC}: libucontext.pc.in
|
${LIBUCONTEXT_PC}: libucontext.pc.in
|
||||||
sed -e s:@LIBUCONTEXT_VERSION@:${LIBUCONTEXT_VERSION}:g \
|
sed -e s:@LIBUCONTEXT_VERSION@:${LIBUCONTEXT_VERSION}:g \
|
||||||
-e s:@LIBUCONTEXT_LIBDIR@:${LIBDIR}:g \
|
-e s:@LIBUCONTEXT_SHARED_LIBDIR@:${shared_libdir}:g \
|
||||||
-e s:@LIBUCONTEXT_INCLUDEDIR@:${INCLUDEDIR}:g $< > $@
|
-e s:@LIBUCONTEXT_STATIC_LIBDIR@:${static_libdir}:g \
|
||||||
|
-e s:@LIBUCONTEXT_INCLUDEDIR@:${includedir}:g $< > $@
|
||||||
|
|
||||||
MANPAGES_SYMLINKS_3 = \
|
MANPAGES_SYMLINKS_3 = \
|
||||||
libucontext_getcontext.3 \
|
libucontext_getcontext.3 \
|
||||||
|
@ -74,25 +152,77 @@ MANPAGES = ${MANPAGES_3}
|
||||||
docs: ${MANPAGES}
|
docs: ${MANPAGES}
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -std=c99 -D_BSD_SOURCE -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
|
$(CC) -std=gnu99 -D_DEFAULT_SOURCE -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
|
||||||
|
|
||||||
.S.o:
|
.S.o:
|
||||||
$(CC) -fPIC -DPIC -DLIBUCONTEXT_ASSEMBLY ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
|
$(CC) -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} ${ASFLAGS} -c -o $@ $<
|
||||||
|
|
||||||
clean:
|
${LIBUCONTEXT_NAME}_clean:
|
||||||
rm -f ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME} \
|
rm -f ${LIBUCONTEXT_NAME}
|
||||||
${LIBUCONTEXT_OBJ} ${LIBUCONTEXT_PC} \
|
|
||||||
include/libucontext/bits.h test_libucontext ${MANPAGES}
|
${LIBUCONTEXT_SONAME}_clean:
|
||||||
|
rm -f ${LIBUCONTEXT_SONAME}
|
||||||
|
|
||||||
|
${LIBUCONTEXT_STATIC_NAME}_clean:
|
||||||
|
rm -f ${LIBUCONTEXT_STATIC_NAME}
|
||||||
|
|
||||||
|
libucontext_obj_clean:
|
||||||
|
rm -f ${LIBUCONTEXT_OBJ}
|
||||||
|
|
||||||
|
${LIBUCONTEXT_PC}_clean:
|
||||||
|
rm -f ${LIBUCONTEXT_PC}
|
||||||
|
|
||||||
|
${LIBUCONTEXT_POSIX_NAME}_clean:
|
||||||
|
rm -f ${LIBUCONTEXT_POSIX_NAME}
|
||||||
|
|
||||||
|
${LIBUCONTEXT_POSIX_SONAME}_clean:
|
||||||
|
rm -f ${LIBUCONTEXT_POSIX_SONAME}
|
||||||
|
|
||||||
|
${LIBUCONTEXT_POSIX_STATIC_NAME}_clean:
|
||||||
|
rm -f ${LIBUCONTEXT_POSIX_STATIC_NAME}
|
||||||
|
|
||||||
|
libucontext_posix_obj_clean:
|
||||||
|
rm -f ${LIBUCONTEXT_POSIX_OBJ}
|
||||||
|
|
||||||
|
check_clean: check_bare_clean check_posix_clean check_bare_posixabi_clean
|
||||||
|
|
||||||
|
check_bare_clean:
|
||||||
|
rm -f test_libucontext
|
||||||
|
|
||||||
|
check_posix_clean:
|
||||||
|
rm -f test_libucontext_posix
|
||||||
|
|
||||||
|
check_bare_posixabi_clean:
|
||||||
|
rm -f test_libucontext_bare_posixabi
|
||||||
|
|
||||||
|
docs_clean:
|
||||||
|
rm -f ${MANPAGES}
|
||||||
|
|
||||||
|
clean: ${LIBUCONTEXT_NAME}_clean
|
||||||
|
clean: ${LIBUCONTEXT_SONAME}_clean
|
||||||
|
clean: ${LIBUCONTEXT_STATIC_NAME}_clean
|
||||||
|
clean: ${LIBUCONTEXT_PC}_clean
|
||||||
|
clean: ${LIBUCONTEXT_POSIX_NAME}_clean
|
||||||
|
clean: ${LIBUCONTEXT_POSIX_SONAME}_clean
|
||||||
|
clean: ${LIBUCONTEXT_POSIX_STATIC_NAME}_clean
|
||||||
|
clean: libucontext_posix_obj_clean
|
||||||
|
clean: libucontext_obj_clean
|
||||||
|
clean: check_clean
|
||||||
|
clean: docs_clean
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
install -D -m755 ${LIBUCONTEXT_NAME} ${DESTDIR}${LIBUCONTEXT_PATH}
|
install -D -m755 ${LIBUCONTEXT_NAME} ${DESTDIR}${LIBUCONTEXT_PATH}
|
||||||
install -D -m664 ${LIBUCONTEXT_STATIC_NAME} ${DESTDIR}${LIBUCONTEXT_STATIC_PATH}
|
install -D -m664 ${LIBUCONTEXT_STATIC_NAME} ${DESTDIR}${LIBUCONTEXT_STATIC_PATH}
|
||||||
ln -sf ${LIBUCONTEXT_SONAME} ${DESTDIR}${LIBDIR}/${LIBUCONTEXT_NAME}
|
ln -sf ${LIBUCONTEXT_SONAME} ${DESTDIR}${shared_libdir}/${LIBUCONTEXT_NAME}
|
||||||
for i in ${LIBUCONTEXT_HEADERS}; do \
|
for i in ${LIBUCONTEXT_HEADERS}; do \
|
||||||
destfn=$$(echo $$i | sed s:include/::g); \
|
destfn=$$(echo $$i | sed s:include/::g); \
|
||||||
install -D -m644 $$i ${DESTDIR}${INCLUDEDIR}/$$destfn; \
|
install -D -m644 $$i ${DESTDIR}${includedir}/$$destfn; \
|
||||||
done
|
done
|
||||||
install -D -m644 ${LIBUCONTEXT_PC} ${DESTDIR}${PKGCONFIGDIR}/${LIBUCONTEXT_PC}
|
install -D -m644 ${LIBUCONTEXT_PC} ${DESTDIR}${pkgconfigdir}/${LIBUCONTEXT_PC}
|
||||||
|
if [ -n "${LIBUCONTEXT_POSIX_NAME}" ]; then \
|
||||||
|
install -D -m755 ${LIBUCONTEXT_POSIX_NAME} ${DESTDIR}${LIBUCONTEXT_POSIX_PATH}; \
|
||||||
|
install -D -m644 ${LIBUCONTEXT_POSIX_STATIC_NAME} ${DESTDIR}${LIBUCONTEXT_POSIX_STATIC_PATH}; \
|
||||||
|
fi
|
||||||
|
|
||||||
install_docs: docs
|
install_docs: docs
|
||||||
install -D -m644 doc/libucontext.3 ${DESTDIR}/usr/share/man/man3/libucontext.3
|
install -D -m644 doc/libucontext.3 ${DESTDIR}/usr/share/man/man3/libucontext.3
|
||||||
|
@ -100,27 +230,37 @@ install_docs: docs
|
||||||
ln -s libucontext.3 ${DESTDIR}/usr/share/man/man3/$$i; \
|
ln -s libucontext.3 ${DESTDIR}/usr/share/man/man3/$$i; \
|
||||||
done
|
done
|
||||||
|
|
||||||
check: test_libucontext ${LIBUCONTEXT_SONAME}
|
ifneq (${FREESTANDING},yes)
|
||||||
|
check: check_libucontext_posix
|
||||||
|
|
||||||
|
check_libucontext_posix: test_libucontext_posix ${LIBUCONTEXT_POSIX_SONAME} ${LIBUCONTEXT_SONAME}
|
||||||
|
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext_posix
|
||||||
|
|
||||||
|
test_libucontext_posix: test_libucontext_posix.c ${LIBUCONTEXT_POSIX_NAME}
|
||||||
|
$(CC) -std=gnu99 -D_DEFAULT_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext -lucontext_posix
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(EXPORT_UNPREFIXED),yes)
|
||||||
|
check: check_libucontext_bare_posixabi
|
||||||
|
|
||||||
|
check_libucontext_bare_posixabi: test_libucontext_bare_posixabi ${LIBUCONTEXT_SONAME}
|
||||||
|
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext_bare_posixabi
|
||||||
|
|
||||||
|
test_libucontext_bare_posixabi: test_libucontext_posix.c ${LIBUCONTEXT_NAME}
|
||||||
|
$(CC) -std=gnu99 -D_DEFAULT_SOURCE ${CFLAGS} ${CPPFLAGS} test_libucontext_posix.c -o $@ -L. -lucontext
|
||||||
|
endif
|
||||||
|
|
||||||
|
check_libucontext: test_libucontext ${LIBUCONTEXT_SONAME}
|
||||||
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext
|
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext
|
||||||
|
|
||||||
|
check: check_libucontext
|
||||||
|
|
||||||
test_libucontext: test_libucontext.c ${LIBUCONTEXT_NAME}
|
test_libucontext: test_libucontext.c ${LIBUCONTEXT_NAME}
|
||||||
$(CC) -std=c99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
|
$(CC) -std=gnu99 -D_DEFAULT_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
|
||||||
|
|
||||||
examples: ${LIBUCONTEXT_EXAMPLES}
|
examples: ${LIBUCONTEXT_EXAMPLES}
|
||||||
examples/cooperative_threading: examples/cooperative_threading.c ${LIBUCONTEXT_NAME}
|
examples/cooperative_threading: examples/cooperative_threading.c ${LIBUCONTEXT_NAME}
|
||||||
$(CC) -std=c99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
|
$(CC) -std=gnu99 -D_DEFAULT_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
|
||||||
|
|
||||||
ifeq ($(FREESTANDING),no)
|
|
||||||
|
|
||||||
include/libucontext/bits.h: arch/common/bits.h
|
|
||||||
cp arch/common/bits.h $@
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
include/libucontext/bits.h: arch/${ARCH}/freestanding/bits.h
|
|
||||||
cp arch/${ARCH}/freestanding/bits.h $@
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
PACKAGE_NAME = libucontext
|
PACKAGE_NAME = libucontext
|
||||||
PACKAGE_VERSION = ${LIBUCONTEXT_VERSION}
|
PACKAGE_VERSION = ${LIBUCONTEXT_VERSION}
|
||||||
|
|
84
NEWS
84
NEWS
|
@ -1,3 +1,87 @@
|
||||||
|
Changes from 1.3 to 1.3.1
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
* Disable hard-float support on ARM by default.
|
||||||
|
|
||||||
|
* Fix up getcontext/swapcontext return values on LoongArch.
|
||||||
|
|
||||||
|
* Fix assembler warnings when building on LoongArch.
|
||||||
|
|
||||||
|
Changes from 1.2 to 1.3
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
* Fix up getcontext/swapcontext return values across a few ports.
|
||||||
|
Patches contributed for ARM and test suite by Volker Christian.
|
||||||
|
|
||||||
|
* Add support for hard-float on ARM.
|
||||||
|
Patches contributed by Richard Campbell.
|
||||||
|
|
||||||
|
* Align build system variables with those used by Automake.
|
||||||
|
Patch contributed by Ismael Luceno.
|
||||||
|
|
||||||
|
* Fix sporadic parallel build failures.
|
||||||
|
Patches contributed by Jim Hauxwell.
|
||||||
|
|
||||||
|
* Ensure frame pointers are omitted when using the C trampoline.
|
||||||
|
Patch contributed by Sören Tempel.
|
||||||
|
|
||||||
|
* Define _XOPEN_SOURCE when building on Darwin.
|
||||||
|
Patch contributed by L. Pereira.
|
||||||
|
|
||||||
|
* Add support for building the manpages with Meson.
|
||||||
|
Patch contributed by matoro.
|
||||||
|
|
||||||
|
* Migrate build from _BSD_SOURCE to _DEFAULT_SOURCE.
|
||||||
|
|
||||||
|
Changes from 1.1 to 1.2
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
* Added Loongarch64 port.
|
||||||
|
|
||||||
|
* Added OpenRISC (or1k) port.
|
||||||
|
|
||||||
|
* Fixed various build system issues:
|
||||||
|
- libucontext_posix.so is no longer underlinked
|
||||||
|
- Executable stacks are now disabled when using GNU-like toolchains
|
||||||
|
- CPPFLAGS is used consistently
|
||||||
|
- Users may now build on Darwin without using Meson
|
||||||
|
|
||||||
|
* aarch64 now implements the necessary SIMD register save/restore as
|
||||||
|
mandatory in AAPCS64.
|
||||||
|
Patches contributed by Richard Campbell.
|
||||||
|
|
||||||
|
Changes from 1.0 to 1.1
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
* Added RISC-V RV32 port.
|
||||||
|
|
||||||
|
* Cleaned up use of _GNU_SOURCE in C code.
|
||||||
|
Partially from patches contributed by osy.
|
||||||
|
|
||||||
|
* Added automatic detection of armv7l architecture.
|
||||||
|
Patch contributed by Leandro Pereira.
|
||||||
|
|
||||||
|
* Fixed installation path of libucontext_posix.a.
|
||||||
|
|
||||||
|
* Work around deficiency in clang built-in assembler on AArch64 targets.
|
||||||
|
Patch contributed by osy.
|
||||||
|
|
||||||
|
Changes from 0.13.1 to 1.0
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
* Implement common libucontext_trampoline, written in C with inline
|
||||||
|
assembly.
|
||||||
|
|
||||||
|
* Added Renesas / Hitachi SH-2/SH-4 port (sh).
|
||||||
|
|
||||||
|
* Added Meson build system, primarily for the convenience of using
|
||||||
|
libucontext with qemu as a subproject.
|
||||||
|
|
||||||
|
* Added support for Mach-O ABI.
|
||||||
|
|
||||||
|
* Fixed deficiencies in libucontext ABI, SONAME has been bumped due
|
||||||
|
to the ABI regressions in 0.13.
|
||||||
|
|
||||||
Changes from 0.13 to 0.13.1
|
Changes from 0.13 to 0.13.1
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
|
|
52
README.md
52
README.md
|
@ -16,19 +16,23 @@ target to do it.
|
||||||
|
|
||||||
## supported features
|
## supported features
|
||||||
|
|
||||||
| Architecture | Works on musl | Syscall | Supports FREESTANDING |
|
| Architecture | Works on musl | Syscall | Supports FREESTANDING | Common trampoline |
|
||||||
|--------------|---------------|---------|-----------------------|
|
|--------------|---------------|---------|-----------------------|-------------------|
|
||||||
| aarch64 | ✓ | | ✓ |
|
| aarch64 | ✓ | | ✓ | ✓ |
|
||||||
| arm | ✓ | | ✓ |
|
| arm | ✓ | | ✓ | ✓ |
|
||||||
| m68k | ✓ | | ✓ |
|
| loongarch64 | ✓ | | ✓ | |
|
||||||
| mips | ✓ | | ✓ |
|
| m68k | ✓ | | ✓ | ✓ |
|
||||||
| mips64 | ✓ | | ✓ |
|
| mips | ✓ | | ✓ | |
|
||||||
| ppc | ✓ | ✓ | |
|
| mips64 | ✓ | | ✓ | |
|
||||||
| ppc64 | ✓ | ✓ | |
|
| or1k | ✓ | | ✓ | ✓ |
|
||||||
| riscv64 | ✓ | | ✓ |
|
| ppc | ✓ | ✓ | | |
|
||||||
| s390x | ✓ | | ✓ |
|
| ppc64 | ✓ | ✓ | | |
|
||||||
| x86 | ✓ | | ✓ |
|
| riscv32 | ✓ | | ✓ | ✓ |
|
||||||
| x86_64 | ✓ | | ✓ |
|
| riscv64 | ✓ | | ✓ | ✓ |
|
||||||
|
| s390x | ✓ | | ✓ | |
|
||||||
|
| sh | ✓ | | ✓ | ✓ |
|
||||||
|
| x86 | ✓ | | ✓ | |
|
||||||
|
| x86_64 | ✓ | | ✓ | ✓ |
|
||||||
|
|
||||||
|
|
||||||
## building
|
## building
|
||||||
|
@ -69,15 +73,26 @@ $ make DESTDIR=out install_docs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## real-world use cases
|
||||||
|
|
||||||
|
`libucontext` is used on almost all musl distributions to provide the legacy `ucontext.h` API.
|
||||||
|
Additionally, it is used by:
|
||||||
|
|
||||||
|
* [UTM](https://getutm.app) -- friendly qemu distribution for macOS and iOS devices. UTM uses libucontext
|
||||||
|
as qemu's coroutine backend.
|
||||||
|
|
||||||
|
* [Lwan](https://lwan.ws) -- a high-performance embeddable asynchronous web server. Lwan uses libucontext
|
||||||
|
to provide green threads when building on non-x86 architectures.
|
||||||
|
|
||||||
|
|
||||||
## caveats
|
## caveats
|
||||||
|
|
||||||
`libucontext`, while largely functionally equivalent does have some differences over traditional POSIX
|
`libucontext`, while largely functionally equivalent does have some differences over traditional POSIX
|
||||||
ucontext functions:
|
ucontext functions:
|
||||||
|
|
||||||
* Saving and restoring the signal mask is not implemented. This is largely a non-issue because most
|
* Saving and restoring the signal mask is not implemented by default in order to avoid kernel syscall
|
||||||
uses of these functions did not modify the signal mask anyway, but saving/restoring the signal mask
|
overhead. Use `-lucontext_posix` if you actually need this functionality, which provides a POSIX
|
||||||
(even though it is unmodified in basically all cases in practice) induces a significant performance
|
compliant implementation at the cost of performance.
|
||||||
penalty due to having to make kernel syscalls.
|
|
||||||
|
|
||||||
* Only basic GPR registers are saved and restored when context swapping. The glibc implementation uses
|
* Only basic GPR registers are saved and restored when context swapping. The glibc implementation uses
|
||||||
hardware capability detection to save/restore other register groups, such as the FPU registers or
|
hardware capability detection to save/restore other register groups, such as the FPU registers or
|
||||||
|
@ -86,4 +101,5 @@ ucontext functions:
|
||||||
save/restore FPU registers or vector registers may be added in a later release as a build-time
|
save/restore FPU registers or vector registers may be added in a later release as a build-time
|
||||||
setting -- for now, we assume a soft-float ABI with no optional processor features. In practice, this
|
setting -- for now, we assume a soft-float ABI with no optional processor features. In practice, this
|
||||||
does not really matter, code using these functions are unlikely to be impacted by this design
|
does not really matter, code using these functions are unlikely to be impacted by this design
|
||||||
assumption.
|
assumption. This is a work in progress, as newer compilers will spill even non-floating-point state
|
||||||
|
through floating point registers when allowed to do so.
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#define SP_OFFSET 432
|
#define SP_OFFSET 432
|
||||||
#define PC_OFFSET 440
|
#define PC_OFFSET 440
|
||||||
#define PSTATE_OFFSET 448
|
#define PSTATE_OFFSET 448
|
||||||
|
#define FPSIMD_CONTEXT_OFFSET 464
|
||||||
|
|
||||||
#ifndef FPSIMD_MAGIC
|
#ifndef FPSIMD_MAGIC
|
||||||
# define FPSIMD_MAGIC 0x46508001
|
# define FPSIMD_MAGIC 0x46508001
|
||||||
|
@ -18,6 +19,9 @@
|
||||||
# define ESR_MAGIC 0x45535201
|
# define ESR_MAGIC 0x45535201
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define FETCH_LINKPTR(dest) \
|
||||||
|
asm("mov %0, x19" : "=r" ((dest)))
|
||||||
|
|
||||||
#include "common-defs.h"
|
#include "common-defs.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,27 +13,17 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(getcontext, libucontext_getcontext)
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
FUNC(libucontext_getcontext)
|
.global PROC_NAME(libucontext_getcontext);
|
||||||
|
.align 2;
|
||||||
|
TYPE(libucontext_getcontext)
|
||||||
|
ENT(libucontext_getcontext)
|
||||||
|
PROC_NAME(libucontext_getcontext):
|
||||||
str xzr, [x0, #REG_OFFSET(0)]
|
str xzr, [x0, #REG_OFFSET(0)]
|
||||||
|
|
||||||
/* save GPRs */
|
/* save x2 and x3 for reuse */
|
||||||
stp x0, x1, [x0, #REG_OFFSET(0)]
|
|
||||||
stp x2, x3, [x0, #REG_OFFSET(2)]
|
stp x2, x3, [x0, #REG_OFFSET(2)]
|
||||||
stp x4, x5, [x0, #REG_OFFSET(4)]
|
|
||||||
stp x6, x7, [x0, #REG_OFFSET(6)]
|
|
||||||
stp x8, x9, [x0, #REG_OFFSET(8)]
|
|
||||||
stp x10, x11, [x0, #REG_OFFSET(10)]
|
|
||||||
stp x12, x13, [x0, #REG_OFFSET(12)]
|
|
||||||
stp x14, x15, [x0, #REG_OFFSET(14)]
|
|
||||||
stp x16, x17, [x0, #REG_OFFSET(16)]
|
|
||||||
stp x18, x19, [x0, #REG_OFFSET(18)]
|
|
||||||
stp x20, x21, [x0, #REG_OFFSET(20)]
|
|
||||||
stp x22, x23, [x0, #REG_OFFSET(22)]
|
|
||||||
stp x24, x25, [x0, #REG_OFFSET(24)]
|
|
||||||
stp x26, x27, [x0, #REG_OFFSET(26)]
|
|
||||||
stp x28, x29, [x0, #REG_OFFSET(28)]
|
|
||||||
str x30, [x0, #REG_OFFSET(30)]
|
|
||||||
|
|
||||||
/* save current program counter in link register */
|
/* save current program counter in link register */
|
||||||
str x30, [x0, #PC_OFFSET]
|
str x30, [x0, #PC_OFFSET]
|
||||||
|
@ -45,8 +35,32 @@ FUNC(libucontext_getcontext)
|
||||||
/* save pstate */
|
/* save pstate */
|
||||||
str xzr, [x0, #PSTATE_OFFSET]
|
str xzr, [x0, #PSTATE_OFFSET]
|
||||||
|
|
||||||
/* TODO: SIMD / FPRs */
|
add x2, x0, #FPSIMD_CONTEXT_OFFSET
|
||||||
|
stp q8, q9, [x2, #144]
|
||||||
|
stp q10, q11, [x2, #176]
|
||||||
|
stp q12, q13, [x2, #208]
|
||||||
|
stp q14, q15, [x2, #240]
|
||||||
|
|
||||||
|
/* save GPRs and return value 0 */
|
||||||
|
mov x2, x0
|
||||||
mov x0, #0
|
mov x0, #0
|
||||||
|
|
||||||
|
stp x0, x1, [x2, #REG_OFFSET(0)]
|
||||||
|
/* x2 and x3 have already been saved */
|
||||||
|
stp x4, x5, [x2, #REG_OFFSET(4)]
|
||||||
|
stp x6, x7, [x2, #REG_OFFSET(6)]
|
||||||
|
stp x8, x9, [x2, #REG_OFFSET(8)]
|
||||||
|
stp x10, x11, [x2, #REG_OFFSET(10)]
|
||||||
|
stp x12, x13, [x2, #REG_OFFSET(12)]
|
||||||
|
stp x14, x15, [x2, #REG_OFFSET(14)]
|
||||||
|
stp x16, x17, [x2, #REG_OFFSET(16)]
|
||||||
|
stp x18, x19, [x2, #REG_OFFSET(18)]
|
||||||
|
stp x20, x21, [x2, #REG_OFFSET(20)]
|
||||||
|
stp x22, x23, [x2, #REG_OFFSET(22)]
|
||||||
|
stp x24, x25, [x2, #REG_OFFSET(24)]
|
||||||
|
stp x26, x27, [x2, #REG_OFFSET(26)]
|
||||||
|
stp x28, x29, [x2, #REG_OFFSET(28)]
|
||||||
|
str x30, [x2, #REG_OFFSET(30)]
|
||||||
|
|
||||||
ret
|
ret
|
||||||
END(libucontext_getcontext)
|
END(libucontext_getcontext)
|
||||||
|
|
|
@ -27,7 +27,7 @@ typedef struct libucontext_ucontext {
|
||||||
unsigned long uc_flags;
|
unsigned long uc_flags;
|
||||||
struct libucontext_ucontext *uc_link;
|
struct libucontext_ucontext *uc_link;
|
||||||
libucontext_stack_t uc_stack;
|
libucontext_stack_t uc_stack;
|
||||||
unsigned char __pad[128];
|
unsigned char __pad[136];
|
||||||
libucontext_mcontext_t uc_mcontext;
|
libucontext_mcontext_t uc_mcontext;
|
||||||
} libucontext_ucontext_t;
|
} libucontext_ucontext_t;
|
||||||
|
|
|
@ -10,17 +10,21 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
extern void libucontext_trampoline(void);
|
extern void libucontext_trampoline(void);
|
||||||
|
|
||||||
|
_Static_assert(offsetof(libucontext_ucontext_t, uc_mcontext.regs[0]) == R0_OFFSET, "R0_OFFSET is invalid");
|
||||||
|
_Static_assert(offsetof(libucontext_ucontext_t, uc_mcontext.sp) == SP_OFFSET, "SP_OFFSET is invalid");
|
||||||
|
_Static_assert(offsetof(libucontext_ucontext_t, uc_mcontext.pc) == PC_OFFSET, "PC_OFFSET is invalid");
|
||||||
|
_Static_assert(offsetof(libucontext_ucontext_t, uc_mcontext.pstate) == PSTATE_OFFSET, "PSTATE_OFFSET is invalid");
|
||||||
|
|
||||||
void
|
void
|
||||||
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
|
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||||
|
@ -52,5 +56,7 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
||||||
|
|
|
@ -13,8 +13,13 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(setcontext, libucontext_setcontext)
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
FUNC(libucontext_setcontext)
|
.global PROC_NAME(libucontext_setcontext);
|
||||||
|
.align 2;
|
||||||
|
TYPE(libucontext_setcontext)
|
||||||
|
ENT(libucontext_setcontext)
|
||||||
|
PROC_NAME(libucontext_setcontext):
|
||||||
/* restore GPRs */
|
/* restore GPRs */
|
||||||
ldp x18, x19, [x0, #REG_OFFSET(18)]
|
ldp x18, x19, [x0, #REG_OFFSET(18)]
|
||||||
ldp x20, x21, [x0, #REG_OFFSET(20)]
|
ldp x20, x21, [x0, #REG_OFFSET(20)]
|
||||||
|
@ -28,7 +33,11 @@ FUNC(libucontext_setcontext)
|
||||||
ldr x2, [x0, #SP_OFFSET]
|
ldr x2, [x0, #SP_OFFSET]
|
||||||
mov sp, x2
|
mov sp, x2
|
||||||
|
|
||||||
/* TODO: SIMD / FPRs */
|
add x2, x0, #FPSIMD_CONTEXT_OFFSET
|
||||||
|
ldp q8, q9, [x2, #144]
|
||||||
|
ldp q10, q11, [x2, #176]
|
||||||
|
ldp q12, q13, [x2, #208]
|
||||||
|
ldp q14, q15, [x2, #240]
|
||||||
|
|
||||||
/* save current program counter in link register */
|
/* save current program counter in link register */
|
||||||
ldr x16, [x0, #PC_OFFSET]
|
ldr x16, [x0, #PC_OFFSET]
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 Ariadne Conill <ariadne@dereferenced.org>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* This software is provided 'as is' and without any warranty, express or
|
|
||||||
* implied. In no event shall the authors be liable for any damages arising
|
|
||||||
* from the use of this software.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "defs.h"
|
|
||||||
|
|
||||||
FUNC(libucontext_trampoline)
|
|
||||||
/* get the proper context into position and test for NULL */
|
|
||||||
mov x0, x19
|
|
||||||
cbnz x0, libucontext_setcontext
|
|
||||||
|
|
||||||
/* something went wrong, exit */
|
|
||||||
b exit
|
|
||||||
END(libucontext_trampoline)
|
|
|
@ -13,8 +13,13 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(swapcontext, libucontext_swapcontext)
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
FUNC(libucontext_swapcontext)
|
.global PROC_NAME(libucontext_swapcontext);
|
||||||
|
.align 2;
|
||||||
|
TYPE(libucontext_swapcontext)
|
||||||
|
ENT(libucontext_swapcontext)
|
||||||
|
PROC_NAME(libucontext_swapcontext):
|
||||||
str xzr, [x0, #REG_OFFSET(0)]
|
str xzr, [x0, #REG_OFFSET(0)]
|
||||||
|
|
||||||
/* save GPRs */
|
/* save GPRs */
|
||||||
|
@ -44,13 +49,19 @@ FUNC(libucontext_swapcontext)
|
||||||
/* save pstate */
|
/* save pstate */
|
||||||
str xzr, [x0, #PSTATE_OFFSET]
|
str xzr, [x0, #PSTATE_OFFSET]
|
||||||
|
|
||||||
|
add x2, x0, #FPSIMD_CONTEXT_OFFSET
|
||||||
|
stp q8, q9, [x2, #144]
|
||||||
|
stp q10, q11, [x2, #176]
|
||||||
|
stp q12, q13, [x2, #208]
|
||||||
|
stp q14, q15, [x2, #240]
|
||||||
|
|
||||||
/* context to swap to is in x1 so... we move to x0 and call setcontext */
|
/* context to swap to is in x1 so... we move to x0 and call setcontext */
|
||||||
/* store our link register in x28 */
|
/* store our link register in x28 */
|
||||||
mov x28, x30
|
mov x28, x30
|
||||||
|
|
||||||
/* move x1 to x0 and call setcontext */
|
/* move x1 to x0 and call setcontext */
|
||||||
mov x0, x1
|
mov x0, x1
|
||||||
bl libucontext_setcontext
|
bl PROC_NAME(libucontext_setcontext)
|
||||||
|
|
||||||
/* hmm, we came back here try to return */
|
/* hmm, we came back here try to return */
|
||||||
mov x30, x28
|
mov x30, x28
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
#include "common-trampoline.c"
|
|
@ -2,8 +2,14 @@
|
||||||
|
|
||||||
#define REG_SZ (4)
|
#define REG_SZ (4)
|
||||||
#define MCONTEXT_GREGS (32)
|
#define MCONTEXT_GREGS (32)
|
||||||
|
#define VFP_MAGIC_OFFSET (232)
|
||||||
|
#define VFP_D8_OFFSET (304)
|
||||||
|
|
||||||
#define TYPE(__proc)
|
#define TYPE(__proc) .type __proc, %function;
|
||||||
|
#define END(__proc)
|
||||||
|
|
||||||
|
#define FETCH_LINKPTR(dest) \
|
||||||
|
asm("movs %0, r4" : "=r" ((dest)))
|
||||||
|
|
||||||
#include "common-defs.h"
|
#include "common-defs.h"
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(getcontext, libucontext_getcontext)
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
FUNC(libucontext_getcontext)
|
FUNC(libucontext_getcontext)
|
||||||
/* copy all of the current registers into the ucontext structure */
|
/* copy all of the current registers into the ucontext structure */
|
||||||
|
@ -21,6 +22,27 @@ FUNC(libucontext_getcontext)
|
||||||
str r13, [r0, #REG_OFFSET(13)]
|
str r13, [r0, #REG_OFFSET(13)]
|
||||||
str r14, [r0, #REG_OFFSET(15)]
|
str r14, [r0, #REG_OFFSET(15)]
|
||||||
|
|
||||||
|
#ifndef FORCE_SOFT_FLOAT
|
||||||
|
#ifndef FORCE_HARD_FLOAT
|
||||||
|
/* test for vfp, set kernel-defined magic number in uc_regspace */
|
||||||
|
push {r0-r1,fp,lr}
|
||||||
|
mov r0, #16
|
||||||
|
bl getauxval
|
||||||
|
tst r0, #64
|
||||||
|
pop {r0-r1,fp,lr}
|
||||||
|
moveq r2, #0
|
||||||
|
ldrne r2, =#0x56465001
|
||||||
|
str r2, [r0, #VFP_MAGIC_OFFSET]
|
||||||
|
beq 1f
|
||||||
|
#endif
|
||||||
|
/* if vfp detected, save d8-d15 */
|
||||||
|
.fpu vfp
|
||||||
|
add r1, r0, #VFP_D8_OFFSET
|
||||||
|
vstmia r1, {d8-d15}
|
||||||
|
.fpu softvfp
|
||||||
|
1:
|
||||||
|
#endif
|
||||||
|
|
||||||
/* return 0 */
|
/* return 0 */
|
||||||
mov r0, #0
|
mov r0, #0
|
||||||
mov pc, lr
|
mov pc, lr
|
||||||
|
|
|
@ -23,6 +23,8 @@ typedef struct libucontext_ucontext {
|
||||||
struct libucontext_ucontext *uc_link;
|
struct libucontext_ucontext *uc_link;
|
||||||
libucontext_stack_t uc_stack;
|
libucontext_stack_t uc_stack;
|
||||||
libucontext_mcontext_t uc_mcontext;
|
libucontext_mcontext_t uc_mcontext;
|
||||||
|
unsigned long uc_sigmask[128 / sizeof(long)];
|
||||||
|
unsigned long long uc_regspace[64];
|
||||||
} libucontext_ucontext_t;
|
} libucontext_ucontext_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -10,7 +10,6 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -19,6 +18,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
extern void libucontext_trampoline(void);
|
extern void libucontext_trampoline(void);
|
||||||
|
@ -56,5 +56,7 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
||||||
|
|
|
@ -13,8 +13,25 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(setcontext, libucontext_setcontext)
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
FUNC(libucontext_setcontext)
|
FUNC(libucontext_setcontext)
|
||||||
|
#ifndef FORCE_SOFT_FLOAT
|
||||||
|
#ifndef FORCE_HARD_FLOAT
|
||||||
|
/* test for vfp magic number set by getcontext */
|
||||||
|
ldr r2, [r0, #VFP_MAGIC_OFFSET]
|
||||||
|
ldr r3, =#0x56465001
|
||||||
|
cmp r2, r3
|
||||||
|
bne 1f
|
||||||
|
#endif
|
||||||
|
/* if vfp in use, restore d8-d15 from uc_regspace */
|
||||||
|
.fpu vfp
|
||||||
|
add r14, r0, #VFP_D8_OFFSET
|
||||||
|
vldmia r14, {d8-d15}
|
||||||
|
.fpu softvfp
|
||||||
|
1:
|
||||||
|
#endif
|
||||||
|
|
||||||
/* copy all of the current registers into the ucontext structure */
|
/* copy all of the current registers into the ucontext structure */
|
||||||
add r14, r0, #REG_OFFSET(0)
|
add r14, r0, #REG_OFFSET(0)
|
||||||
ldmia r14, {r0-r12}
|
ldmia r14, {r0-r12}
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 Ariadne Conill <ariadne@dereferenced.org>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* This software is provided 'as is' and without any warranty, express or
|
|
||||||
* implied. In no event shall the authors be liable for any damages arising
|
|
||||||
* from the use of this software.
|
|
||||||
*/
|
|
||||||
|
|
||||||
.globl libucontext_trampoline;
|
|
||||||
.fnstart
|
|
||||||
.cantunwind
|
|
||||||
nop
|
|
||||||
libucontext_trampoline:
|
|
||||||
/* get the proper context into position and test for NULL */
|
|
||||||
movs r0, r4
|
|
||||||
bne libucontext_setcontext@plt
|
|
||||||
|
|
||||||
/* we are returning into a null context, it seems, so maybe we should exit */
|
|
||||||
b exit@plt
|
|
|
@ -13,13 +13,36 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(swapcontext, libucontext_swapcontext)
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
FUNC(libucontext_swapcontext)
|
FUNC(libucontext_swapcontext)
|
||||||
|
#ifndef FORCE_SOFT_FLOAT
|
||||||
|
#ifndef FORCE_HARD_FLOAT
|
||||||
|
/* test for vfp magic number, copy to other ucontext */
|
||||||
|
ldr r3, [r1, #VFP_MAGIC_OFFSET]
|
||||||
|
ldr r4, =#0x56465001
|
||||||
|
str r3, [r0, #VFP_MAGIC_OFFSET]
|
||||||
|
cmp r3, r4
|
||||||
|
bne 1f
|
||||||
|
#endif
|
||||||
|
/* if vfp in use, save and restore d8-d15 */
|
||||||
|
.fpu vfp
|
||||||
|
add r2, r0, #VFP_D8_OFFSET
|
||||||
|
vstmia r2, {d8-d15}
|
||||||
|
|
||||||
|
add r14, r1, #VFP_D8_OFFSET
|
||||||
|
vldmia r14, {d8-d15}
|
||||||
|
.fpu softvfp
|
||||||
|
1:
|
||||||
|
#endif
|
||||||
|
|
||||||
/* copy all of the current registers into the ucontext structure */
|
/* copy all of the current registers into the ucontext structure */
|
||||||
add r2, r0, #REG_OFFSET(0)
|
|
||||||
stmia r2, {r0-r12}
|
|
||||||
str r13, [r0,#REG_OFFSET(13)]
|
str r13, [r0,#REG_OFFSET(13)]
|
||||||
str r14, [r0,#REG_OFFSET(15)]
|
str r14, [r0,#REG_OFFSET(15)]
|
||||||
|
add r2, r0, #REG_OFFSET(0)
|
||||||
|
/* copy r0 with value 0 to indicate success (return value 0) */
|
||||||
|
mov r0, #0
|
||||||
|
stmia r2, {r0-r12}
|
||||||
|
|
||||||
/* load new registers from the second ucontext structure */
|
/* load new registers from the second ucontext structure */
|
||||||
add r14, r1, #REG_OFFSET(0)
|
add r14, r1, #REG_OFFSET(0)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
#include "common-trampoline.c"
|
|
@ -18,16 +18,30 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TYPE
|
#ifndef TYPE
|
||||||
|
# ifdef __clang__
|
||||||
|
# define TYPE(__proc) // .type not supported
|
||||||
|
# else
|
||||||
# define TYPE(__proc) .type __proc, @function;
|
# define TYPE(__proc) .type __proc, @function;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PROC_NAME
|
||||||
|
# ifdef __MACH__
|
||||||
|
# define PROC_NAME(__proc) _ ## __proc
|
||||||
|
# else
|
||||||
|
# define PROC_NAME(__proc) __proc
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#define FUNC(__proc) \
|
#define FUNC(__proc) \
|
||||||
.global __proc; \
|
.global PROC_NAME(__proc); \
|
||||||
.align 2; \
|
.align 2; \
|
||||||
TYPE(__proc) \
|
TYPE(__proc) \
|
||||||
ENT(__proc) \
|
ENT(__proc) \
|
||||||
__proc: \
|
PROC_NAME(__proc): \
|
||||||
SETUP_FRAME(__proc)
|
SETUP_FRAME(__proc)
|
||||||
|
|
||||||
|
#ifndef END
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#define END(__proc)
|
#define END(__proc)
|
||||||
#else
|
#else
|
||||||
|
@ -35,6 +49,7 @@ __proc: \
|
||||||
.end __proc; \
|
.end __proc; \
|
||||||
.size __proc,.-__proc;
|
.size __proc,.-__proc;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef EXPORT_UNPREFIXED
|
#ifdef EXPORT_UNPREFIXED
|
||||||
#define ALIAS(__alias, __real) \
|
#define ALIAS(__alias, __real) \
|
||||||
|
@ -46,10 +61,4 @@ __proc: \
|
||||||
|
|
||||||
#define REG_OFFSET(__reg) (MCONTEXT_GREGS + ((__reg) * REG_SZ))
|
#define REG_OFFSET(__reg) (MCONTEXT_GREGS + ((__reg) * REG_SZ))
|
||||||
|
|
||||||
#ifndef LIBUCONTEXT_ASSEMBLY
|
|
||||||
|
|
||||||
#include <libucontext/libucontext.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* We need to make sure that the C compiler doesn't push any
|
||||||
|
* additional data to the stack frame. Otherwise, assumptions
|
||||||
|
* made by the architecture-specific implementation of the
|
||||||
|
* FETCH_LINKPTR() macro about the location of the linkptr,
|
||||||
|
* relative to the stack pointer, will not hold.
|
||||||
|
*
|
||||||
|
* Hence, we compile this function with -fomit-frame-pointer
|
||||||
|
* and use the register storage-class specifier for all local
|
||||||
|
* vars. Note that the latter is just a "suggestion" (see C99).
|
||||||
|
*/
|
||||||
|
|
||||||
|
__attribute__ ((visibility ("hidden")))
|
||||||
|
__attribute__ ((optimize ("omit-frame-pointer")))
|
||||||
|
void
|
||||||
|
libucontext_trampoline(void)
|
||||||
|
{
|
||||||
|
register libucontext_ucontext_t *uc_link = NULL;
|
||||||
|
|
||||||
|
FETCH_LINKPTR(uc_link);
|
||||||
|
|
||||||
|
if (uc_link == NULL)
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
libucontext_setcontext(uc_link);
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
#ifndef __ARCH_LOONGARCH64_DEFS_H
|
||||||
|
#define __ARCH_LOONGARCH64_DEFS_H
|
||||||
|
|
||||||
|
#define REG_SZ (8)
|
||||||
|
|
||||||
|
#define REG_R0 (0)
|
||||||
|
#define REG_R1 (1)
|
||||||
|
#define REG_R2 (2)
|
||||||
|
#define REG_R3 (3)
|
||||||
|
#define REG_R4 (4)
|
||||||
|
#define REG_R5 (5)
|
||||||
|
#define REG_R6 (6)
|
||||||
|
#define REG_R7 (7)
|
||||||
|
#define REG_R8 (8)
|
||||||
|
#define REG_R9 (9)
|
||||||
|
#define REG_R10 (10)
|
||||||
|
#define REG_R11 (11)
|
||||||
|
#define REG_R12 (12)
|
||||||
|
#define REG_R13 (13)
|
||||||
|
#define REG_R14 (14)
|
||||||
|
#define REG_R15 (15)
|
||||||
|
#define REG_R16 (16)
|
||||||
|
#define REG_R17 (17)
|
||||||
|
#define REG_R18 (18)
|
||||||
|
#define REG_R19 (19)
|
||||||
|
#define REG_R20 (20)
|
||||||
|
#define REG_R21 (21)
|
||||||
|
#define REG_R22 (22)
|
||||||
|
#define REG_R23 (23)
|
||||||
|
#define REG_R24 (24)
|
||||||
|
#define REG_R25 (25)
|
||||||
|
#define REG_R26 (26)
|
||||||
|
#define REG_R27 (27)
|
||||||
|
#define REG_R28 (28)
|
||||||
|
#define REG_R29 (29)
|
||||||
|
#define REG_R30 (30)
|
||||||
|
#define REG_R31 (31)
|
||||||
|
|
||||||
|
/* $a0 is $4 , also $v0, same as $5, $a1 and $v1*/
|
||||||
|
#define REG_A0 (4)
|
||||||
|
|
||||||
|
/* stack pointer is actually $3 */
|
||||||
|
#define REG_SP (3)
|
||||||
|
|
||||||
|
/* frame pointer is actually $22 */
|
||||||
|
#define REG_FP (22)
|
||||||
|
|
||||||
|
/* $s0 is $23 */
|
||||||
|
#define REG_S0 (23)
|
||||||
|
|
||||||
|
/* $ra is $1 */
|
||||||
|
#define REG_RA (1)
|
||||||
|
|
||||||
|
/* offset to mc_gregs in ucontext_t */
|
||||||
|
#define MCONTEXT_GREGS (184)
|
||||||
|
|
||||||
|
/* offset to PC in ucontext_t */
|
||||||
|
#define MCONTEXT_PC (176)
|
||||||
|
|
||||||
|
/* offset to uc_link in ucontext_t */
|
||||||
|
#define UCONTEXT_UC_LINK (8)
|
||||||
|
|
||||||
|
/* offset to uc_stack.ss_sp in ucontext_t */
|
||||||
|
#define UCONTEXT_STACK_PTR (16)
|
||||||
|
|
||||||
|
/* offset to uc_stack.ss_size in ucontext_t */
|
||||||
|
#define UCONTEXT_STACK_SIZE (32)
|
||||||
|
|
||||||
|
/* Stack alignment, from Kernel source */
|
||||||
|
#define ALSZ 15
|
||||||
|
#define ALMASK ~15
|
||||||
|
#define FRAMESZ (((LOCALSZ * REG_SZ) + ALSZ) & ALMASK)
|
||||||
|
|
||||||
|
#define PUSH_FRAME(__proc) \
|
||||||
|
addi.d $sp, $sp, -FRAMESZ;
|
||||||
|
|
||||||
|
#define POP_FRAME(__proc) \
|
||||||
|
addi.d $sp, $sp, FRAMESZ;
|
||||||
|
|
||||||
|
#include <common-defs.h>
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef LIBUCONTEXT_BITS_H
|
||||||
|
#define LIBUCONTEXT_BITS_H
|
||||||
|
|
||||||
|
typedef unsigned long long libucontext_greg_t, libucontext_gregset_t[32];
|
||||||
|
|
||||||
|
/* Container for all general registers. */
|
||||||
|
typedef __loongarch_mc_gp_state gregset_t;
|
||||||
|
|
||||||
|
/* Container for floating-point state. */
|
||||||
|
typedef union __loongarch_mc_fp_state fpregset_t;
|
||||||
|
|
||||||
|
union __loongarch_mc_fp_state {
|
||||||
|
unsigned int __val32[256 / 32];
|
||||||
|
unsigned long long __val64[256 / 64];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct mcontext_t {
|
||||||
|
unsigned long long __pc;
|
||||||
|
unsigned long long __gregs[32];
|
||||||
|
unsigned int __flags;
|
||||||
|
|
||||||
|
unsigned int __fcsr;
|
||||||
|
unsigned int __vcsr;
|
||||||
|
unsigned long long __fcc;
|
||||||
|
union __loongarch_mc_fp_state __fpregs[32] __attribute__((__aligned__ (32)));
|
||||||
|
|
||||||
|
unsigned int __reserved;
|
||||||
|
} mcontext_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *ss_sp;
|
||||||
|
int ss_flags;
|
||||||
|
size_t ss_size;
|
||||||
|
} libucontext_stack_t;
|
||||||
|
|
||||||
|
typedef struct libucontext_ucontext {
|
||||||
|
unsigned long uc_flags;
|
||||||
|
struct libucontext_ucontext *uc_link;
|
||||||
|
libucontext_stack_t uc_stack;
|
||||||
|
libucontext_mcontext_t uc_mcontext;
|
||||||
|
} libucontext_ucontext_t;
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Peng Fan <fanpeng@loongson.cn>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LOCALSZ (1)
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_getcontext)
|
||||||
|
/* copy $sp, $fp to temporary registers so we don't clobber them */
|
||||||
|
move $a2, $sp
|
||||||
|
move $a3, $fp
|
||||||
|
|
||||||
|
PUSH_FRAME(libucontext_getcontext)
|
||||||
|
|
||||||
|
/* set registers */
|
||||||
|
st.d $s0, $a0, REG_OFFSET(23)
|
||||||
|
st.d $s1, $a0, REG_OFFSET(24)
|
||||||
|
st.d $s2, $a0, REG_OFFSET(25)
|
||||||
|
st.d $s3, $a0, REG_OFFSET(26)
|
||||||
|
st.d $s4, $a0, REG_OFFSET(27)
|
||||||
|
st.d $s5, $a0, REG_OFFSET(28)
|
||||||
|
st.d $s6, $a0, REG_OFFSET(29)
|
||||||
|
st.d $s7, $a0, REG_OFFSET(30)
|
||||||
|
st.d $s8, $a0, REG_OFFSET(31)
|
||||||
|
|
||||||
|
st.d $a2, $a0, REG_OFFSET(3)
|
||||||
|
st.d $zero, $a0, REG_OFFSET(4)
|
||||||
|
st.d $a3, $a0, REG_OFFSET(22)
|
||||||
|
st.d $ra, $a0, REG_OFFSET(1)
|
||||||
|
|
||||||
|
st.d $ra, $a0, (MCONTEXT_PC)
|
||||||
|
|
||||||
|
move $a0, $zero
|
||||||
|
|
||||||
|
POP_FRAME(libucontext_getcontext)
|
||||||
|
|
||||||
|
jr $ra
|
||||||
|
END(libucontext_getcontext)
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
|
extern void libucontext_trampoline(void);
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||||
|
{
|
||||||
|
libucontext_greg_t *sp, *regp;
|
||||||
|
va_list va;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* set up and align the stack. */
|
||||||
|
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||||
|
sp -= argc < 8 ? 0 : argc - 8;
|
||||||
|
sp = (libucontext_greg_t *) (((uintptr_t) sp & -16L));
|
||||||
|
|
||||||
|
/* set up the ucontext structure */
|
||||||
|
ucp->uc_mcontext.__gregs[REG_RA] = (libucontext_greg_t) libucontext_trampoline;
|
||||||
|
ucp->uc_mcontext.__gregs[REG_S0] = (libucontext_greg_t) ucp->uc_link;
|
||||||
|
ucp->uc_mcontext.__gregs[REG_SP] = (libucontext_greg_t) sp;
|
||||||
|
ucp->uc_mcontext.__pc = (libucontext_greg_t) func;
|
||||||
|
|
||||||
|
va_start(va, argc);
|
||||||
|
|
||||||
|
/* first 8 args go in $a0 through $a7. */
|
||||||
|
regp = &(ucp->uc_mcontext.__gregs[REG_A0]);
|
||||||
|
|
||||||
|
for (i = 0; (i < argc && i < 8); i++)
|
||||||
|
*regp++ = va_arg (va, libucontext_greg_t);
|
||||||
|
|
||||||
|
/* remainder overflows into stack */
|
||||||
|
for (; i < argc; i++)
|
||||||
|
*sp++ = va_arg (va, libucontext_greg_t);
|
||||||
|
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Peng Fan <fanpeng@loongson.cn>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LOCALSZ (1)
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_setcontext)
|
||||||
|
PUSH_FRAME(libucontext_setcontext)
|
||||||
|
|
||||||
|
/* move the context to $v0, in LA, $v0 = $a0 = $4 */
|
||||||
|
move $t5, $a0
|
||||||
|
|
||||||
|
/* load the registers */
|
||||||
|
ld.d $a0, $t5, REG_OFFSET(4)
|
||||||
|
ld.d $a1, $t5, REG_OFFSET(5)
|
||||||
|
ld.d $a2, $t5, REG_OFFSET(6)
|
||||||
|
ld.d $a3, $t5, REG_OFFSET(7)
|
||||||
|
ld.d $a4, $t5, REG_OFFSET(8)
|
||||||
|
ld.d $a5, $t5, REG_OFFSET(9)
|
||||||
|
ld.d $a6, $t5, REG_OFFSET(10)
|
||||||
|
ld.d $a7, $t5, REG_OFFSET(11)
|
||||||
|
|
||||||
|
ld.d $s0, $t5, REG_OFFSET(23)
|
||||||
|
ld.d $s1, $t5, REG_OFFSET(24)
|
||||||
|
ld.d $s2, $t5, REG_OFFSET(25)
|
||||||
|
ld.d $s3, $t5, REG_OFFSET(26)
|
||||||
|
ld.d $s4, $t5, REG_OFFSET(27)
|
||||||
|
ld.d $s5, $t5, REG_OFFSET(28)
|
||||||
|
ld.d $s6, $t5, REG_OFFSET(29)
|
||||||
|
ld.d $s7, $t5, REG_OFFSET(30)
|
||||||
|
ld.d $s8, $t5, REG_OFFSET(31)
|
||||||
|
|
||||||
|
ld.d $sp, $t5, REG_OFFSET(3)
|
||||||
|
ld.d $fp, $t5, REG_OFFSET(22)
|
||||||
|
ld.d $ra, $t5, REG_OFFSET(1)
|
||||||
|
|
||||||
|
ld.d $t8, $t5, (MCONTEXT_PC)
|
||||||
|
|
||||||
|
jr $t8
|
||||||
|
move $a0, $zero
|
||||||
|
|
||||||
|
POP_FRAME(libucontext_setcontext)
|
||||||
|
END(libucontext_setcontext)
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
* Copyright (c) 2021 Peng Fan <fanpeng@loongson.cn>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -10,20 +10,24 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define LOCALSZ (4)
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
FUNC(libucontext_trampoline)
|
FUNC(libucontext_trampoline)
|
||||||
/* call the function passed to makecontext() */
|
|
||||||
jalr s1
|
|
||||||
|
|
||||||
/* check for linked context */
|
/* call setcontext */
|
||||||
beqz s2, no_linked_context
|
move $a0, $s0
|
||||||
|
/* we receive our initial ucontext in $s0, so if $s0 is nil, bail */
|
||||||
|
beqz $s0, no_linked_context
|
||||||
|
|
||||||
/* if one is set, invoke it */
|
la.got $t8, libucontext_setcontext
|
||||||
mv a0, s2
|
|
||||||
jal libucontext_setcontext
|
jr $t8
|
||||||
|
|
||||||
/* otherwise, exit. */
|
|
||||||
no_linked_context:
|
no_linked_context:
|
||||||
tail exit@plt
|
move $a0, $zero
|
||||||
|
la.global $t8, exit
|
||||||
|
jr $t8
|
||||||
|
|
||||||
END(libucontext_trampoline)
|
END(libucontext_trampoline)
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Peng Fan <fanpeng@loongson.cn>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LOCALSZ (4)
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
#define A1_OFFSET (FRAMESZ - (1 * REG_SZ))
|
||||||
|
|
||||||
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_swapcontext)
|
||||||
|
/* copy $sp, $fp to temporary registers so we don't clobber them */
|
||||||
|
move $a3, $sp
|
||||||
|
move $a4, $fp
|
||||||
|
|
||||||
|
move $t5, $a0
|
||||||
|
|
||||||
|
PUSH_FRAME(libucontext_swapcontext)
|
||||||
|
|
||||||
|
/* set registers */
|
||||||
|
st.d $s0, $t5, REG_OFFSET(23)
|
||||||
|
st.d $s1, $t5, REG_OFFSET(24)
|
||||||
|
st.d $s2, $t5, REG_OFFSET(25)
|
||||||
|
st.d $s3, $t5, REG_OFFSET(26)
|
||||||
|
st.d $s4, $t5, REG_OFFSET(27)
|
||||||
|
st.d $s5, $t5, REG_OFFSET(28)
|
||||||
|
st.d $s6, $t5, REG_OFFSET(29)
|
||||||
|
st.d $s7, $t5, REG_OFFSET(30)
|
||||||
|
st.d $s8, $t5, REG_OFFSET(31)
|
||||||
|
|
||||||
|
st.d $a3, $t5, REG_OFFSET(3)
|
||||||
|
st.d $zero, $t5, REG_OFFSET(4)
|
||||||
|
st.d $a4, $t5, REG_OFFSET(22)
|
||||||
|
st.d $ra, $t5, REG_OFFSET(1)
|
||||||
|
|
||||||
|
st.d $ra, $t5, (MCONTEXT_PC)
|
||||||
|
|
||||||
|
/* copy new context address in $a1 to stack */
|
||||||
|
st.d $a1, $sp, A1_OFFSET
|
||||||
|
|
||||||
|
/* load new context address into $v0 */
|
||||||
|
ld.d $t4, $sp, A1_OFFSET
|
||||||
|
|
||||||
|
/* load the registers */
|
||||||
|
ld.d $a0, $t4, REG_OFFSET(4)
|
||||||
|
ld.d $a1, $t4, REG_OFFSET(5)
|
||||||
|
ld.d $a2, $t4, REG_OFFSET(6)
|
||||||
|
ld.d $a3, $t4, REG_OFFSET(7)
|
||||||
|
ld.d $a4, $t4, REG_OFFSET(8)
|
||||||
|
ld.d $a5, $t4, REG_OFFSET(9)
|
||||||
|
ld.d $a6, $t4, REG_OFFSET(10)
|
||||||
|
ld.d $a7, $t4, REG_OFFSET(11)
|
||||||
|
|
||||||
|
ld.d $s0, $t4, REG_OFFSET(23)
|
||||||
|
ld.d $s1, $t4, REG_OFFSET(24)
|
||||||
|
ld.d $s2, $t4, REG_OFFSET(25)
|
||||||
|
ld.d $s3, $t4, REG_OFFSET(26)
|
||||||
|
ld.d $s4, $t4, REG_OFFSET(27)
|
||||||
|
ld.d $s5, $t4, REG_OFFSET(28)
|
||||||
|
ld.d $s6, $t4, REG_OFFSET(29)
|
||||||
|
ld.d $s7, $t4, REG_OFFSET(30)
|
||||||
|
ld.d $s8, $t4, REG_OFFSET(31)
|
||||||
|
|
||||||
|
ld.d $sp, $t4, REG_OFFSET(3)
|
||||||
|
ld.d $fp, $t4, REG_OFFSET(22)
|
||||||
|
ld.d $ra, $t4, REG_OFFSET(1)
|
||||||
|
|
||||||
|
ld.d $t8, $t4, (MCONTEXT_PC)
|
||||||
|
|
||||||
|
jr $t8
|
||||||
|
move $a0, $zero
|
||||||
|
|
||||||
|
fail:
|
||||||
|
la.global $t8, exit
|
||||||
|
|
||||||
|
POP_FRAME(libucontext_swapcontext)
|
||||||
|
|
||||||
|
jirl $ra, $t8, 0
|
||||||
|
move $a0, $zero
|
||||||
|
END(libucontext_swapcontext)
|
|
@ -26,6 +26,9 @@
|
||||||
|
|
||||||
#define PC_OFFSET REG_OFFSET(REG_PC)
|
#define PC_OFFSET REG_OFFSET(REG_PC)
|
||||||
|
|
||||||
|
#define FETCH_LINKPTR(dest) \
|
||||||
|
asm("mov.l (%%sp, %%d7.l * 4), %0" :: "r" ((dest)))
|
||||||
|
|
||||||
#include "common-defs.h"
|
#include "common-defs.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(getcontext, libucontext_getcontext)
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
FUNC(libucontext_getcontext)
|
FUNC(libucontext_getcontext)
|
||||||
move.l 4(%sp), %a0 /* load ucontext_t pointer from stack */
|
move.l 4(%sp), %a0 /* load ucontext_t pointer from stack */
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
extern void libucontext_trampoline(void);
|
extern void libucontext_trampoline(void);
|
||||||
|
@ -55,5 +55,7 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
||||||
*sp++ = (libucontext_greg_t) ucp->uc_link;
|
*sp++ = (libucontext_greg_t) ucp->uc_link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(setcontext, libucontext_setcontext)
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
FUNC(libucontext_setcontext)
|
FUNC(libucontext_setcontext)
|
||||||
move.l 4(%sp), %a0 /* load ucontext_t pointer from stack */
|
move.l 4(%sp), %a0 /* load ucontext_t pointer from stack */
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* This software is provided 'as is' and without any warranty, express or
|
|
||||||
* implied. In no event shall the authors be liable for any damages arising
|
|
||||||
* from the use of this software.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "defs.h"
|
|
||||||
|
|
||||||
FUNC(libucontext_trampoline)
|
|
||||||
lea (%sp, %d7.l * REG_SZ), %sp /* place uc_link in $sp */
|
|
||||||
|
|
||||||
tst.l (%sp) /* test next content for NULL */
|
|
||||||
jeq no_linked_context
|
|
||||||
|
|
||||||
jbsr libucontext_setcontext /* call setcontext */
|
|
||||||
move.l %d0, (%sp)
|
|
||||||
|
|
||||||
no_linked_context:
|
|
||||||
jbsr exit
|
|
||||||
END(libucontext_trampoline)
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(swapcontext, libucontext_swapcontext)
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
FUNC(libucontext_swapcontext)
|
FUNC(libucontext_swapcontext)
|
||||||
move.l 4(%sp), %a0 /* load save ucontext_t pointer from stack */
|
move.l 4(%sp), %a0 /* load save ucontext_t pointer from stack */
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
#include "common-trampoline.c"
|
|
@ -15,6 +15,7 @@ LOCALSZ = 1
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(getcontext, libucontext_getcontext)
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
FUNC(libucontext_getcontext)
|
FUNC(libucontext_getcontext)
|
||||||
/* copy $gp, $sp, $fp to temporary registers so we don't clobber them */
|
/* copy $gp, $sp, $fp to temporary registers so we don't clobber them */
|
||||||
|
|
|
@ -22,6 +22,7 @@ A3_OFF = FRAMESZ + (3 * REG_SZ)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ALIAS(makecontext, libucontext_makecontext)
|
ALIAS(makecontext, libucontext_makecontext)
|
||||||
|
ALIAS(__makecontext, libucontext_makecontext)
|
||||||
|
|
||||||
FUNC(libucontext_makecontext)
|
FUNC(libucontext_makecontext)
|
||||||
PUSH_FRAME(libucontext_makecontext)
|
PUSH_FRAME(libucontext_makecontext)
|
||||||
|
|
|
@ -15,6 +15,7 @@ LOCALSZ = 1
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(setcontext, libucontext_setcontext)
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
FUNC(libucontext_setcontext)
|
FUNC(libucontext_setcontext)
|
||||||
PUSH_FRAME(libucontext_setcontext)
|
PUSH_FRAME(libucontext_setcontext)
|
||||||
|
|
|
@ -14,6 +14,7 @@ LOCALSZ = 1
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
|
.hidden libucontext_trampoline
|
||||||
FUNC(libucontext_trampoline)
|
FUNC(libucontext_trampoline)
|
||||||
move $gp, $s1
|
move $gp, $s1
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ FUNC(libucontext_trampoline)
|
||||||
|
|
||||||
/* call setcontext */
|
/* call setcontext */
|
||||||
move $a0, $s0
|
move $a0, $s0
|
||||||
la $t9, libucontext_setcontext
|
la $t9, PROC_NAME(libucontext_setcontext)
|
||||||
|
|
||||||
jr $t9
|
jr $t9
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ LOCALSZ = 2
|
||||||
A1_OFFSET = FRAMESZ - (1 * REG_SZ)
|
A1_OFFSET = FRAMESZ - (1 * REG_SZ)
|
||||||
|
|
||||||
ALIAS(swapcontext, libucontext_swapcontext)
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
FUNC(libucontext_swapcontext)
|
FUNC(libucontext_swapcontext)
|
||||||
/* copy $gp, $sp, $fp to temporary registers so we don't clobber them */
|
/* copy $gp, $sp, $fp to temporary registers so we don't clobber them */
|
||||||
|
|
|
@ -15,6 +15,7 @@ LOCALSZ = 1
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(getcontext, libucontext_getcontext)
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
FUNC(libucontext_getcontext)
|
FUNC(libucontext_getcontext)
|
||||||
/* copy $gp, $sp, $fp to temporary registers so we don't clobber them */
|
/* copy $gp, $sp, $fp to temporary registers so we don't clobber them */
|
||||||
|
|
|
@ -27,6 +27,7 @@ A7_OFF = FRAMESZ - (1 * REG_SZ)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ALIAS(makecontext, libucontext_makecontext)
|
ALIAS(makecontext, libucontext_makecontext)
|
||||||
|
ALIAS(__makecontext, libucontext_makecontext)
|
||||||
|
|
||||||
FUNC(libucontext_makecontext)
|
FUNC(libucontext_makecontext)
|
||||||
PUSH_FRAME(libucontext_makecontext)
|
PUSH_FRAME(libucontext_makecontext)
|
||||||
|
|
|
@ -15,6 +15,7 @@ LOCALSZ = 1
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(setcontext, libucontext_setcontext)
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
FUNC(libucontext_setcontext)
|
FUNC(libucontext_setcontext)
|
||||||
PUSH_FRAME(libucontext_setcontext)
|
PUSH_FRAME(libucontext_setcontext)
|
||||||
|
|
|
@ -14,6 +14,7 @@ LOCALSZ = 1
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
|
.hidden libucontext_trampoline
|
||||||
FUNC(libucontext_trampoline)
|
FUNC(libucontext_trampoline)
|
||||||
move $gp, $s1
|
move $gp, $s1
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ FUNC(libucontext_trampoline)
|
||||||
|
|
||||||
/* call setcontext */
|
/* call setcontext */
|
||||||
move $a0, $s0
|
move $a0, $s0
|
||||||
dla $t9, libucontext_setcontext
|
dla $t9, PROC_NAME(libucontext_setcontext)
|
||||||
|
|
||||||
jr $t9
|
jr $t9
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ LOCALSZ = 2
|
||||||
A1_OFFSET = FRAMESZ - (1 * REG_SZ)
|
A1_OFFSET = FRAMESZ - (1 * REG_SZ)
|
||||||
|
|
||||||
ALIAS(swapcontext, libucontext_swapcontext)
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
FUNC(libucontext_swapcontext)
|
FUNC(libucontext_swapcontext)
|
||||||
/* copy $gp, $sp, $fp to temporary registers so we don't clobber them */
|
/* copy $gp, $sp, $fp to temporary registers so we don't clobber them */
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef __ARCH_OR1K_DEFS_H
|
||||||
|
#define __ARCH_OR1K_DEFS_H
|
||||||
|
|
||||||
|
#define REG_SZ (4)
|
||||||
|
#define MCONTEXT_GREGS (20)
|
||||||
|
|
||||||
|
#define REG_SP (1)
|
||||||
|
#define REG_FP (2)
|
||||||
|
#define REG_RA (9)
|
||||||
|
#define REG_SA (11)
|
||||||
|
#define REG_LR (14)
|
||||||
|
#define REG_PC (33)
|
||||||
|
#define REG_SR (34)
|
||||||
|
|
||||||
|
#define PC_OFFSET REG_OFFSET(REG_PC)
|
||||||
|
|
||||||
|
#define FETCH_LINKPTR(dest) \
|
||||||
|
asm("l.ori %0, r14, 0" :: "r" ((dest)))
|
||||||
|
|
||||||
|
#include "common-defs.h"
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_getcontext)
|
||||||
|
l.sw REG_OFFSET(1)(r3), r1 /* store r1 and r2 */
|
||||||
|
l.sw REG_OFFSET(2)(r3), r2
|
||||||
|
|
||||||
|
l.sw REG_OFFSET(9)(r3), r9 /* link register */
|
||||||
|
l.sw REG_OFFSET(11)(r3), r0 /* return value is 0 */
|
||||||
|
|
||||||
|
l.sw REG_OFFSET(10)(r3), r10 /* store r10 for TLS */
|
||||||
|
|
||||||
|
l.sw REG_OFFSET(14)(r3), r14 /* store r14 through r30 even */
|
||||||
|
l.sw REG_OFFSET(16)(r3), r16
|
||||||
|
l.sw REG_OFFSET(18)(r3), r18
|
||||||
|
l.sw REG_OFFSET(20)(r3), r20
|
||||||
|
l.sw REG_OFFSET(22)(r3), r22
|
||||||
|
l.sw REG_OFFSET(24)(r3), r24
|
||||||
|
l.sw REG_OFFSET(26)(r3), r26
|
||||||
|
l.sw REG_OFFSET(28)(r3), r28
|
||||||
|
l.sw REG_OFFSET(30)(r3), r30
|
||||||
|
|
||||||
|
l.ori r11, r0, 0
|
||||||
|
l.jr r9
|
||||||
|
END(libucontext_getcontext)
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef LIBUCONTEXT_BITS_H
|
||||||
|
#define LIBUCONTEXT_BITS_H
|
||||||
|
|
||||||
|
typedef struct sigaltstack {
|
||||||
|
void *ss_sp;
|
||||||
|
int ss_flags;
|
||||||
|
size_t ss_size;
|
||||||
|
} libucontext_stack_t;
|
||||||
|
|
||||||
|
typedef int libucontext_greg_t, libucontext_gregset_t[32];
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
struct {
|
||||||
|
libucontext_gregset_t gpr;
|
||||||
|
libucontext_greg_t pc;
|
||||||
|
libucontext_greg_t sr;
|
||||||
|
} regs;
|
||||||
|
unsigned long oldmask;
|
||||||
|
} libucontext_mcontext_t;
|
||||||
|
|
||||||
|
typedef struct libucontext_ucontext {
|
||||||
|
unsigned long uc_flags;
|
||||||
|
struct libucontext_ucontext *uc_link;
|
||||||
|
libucontext_stack_t uc_stack;
|
||||||
|
libucontext_mcontext_t uc_mcontext;
|
||||||
|
} libucontext_ucontext_t;
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
|
extern void libucontext_trampoline(void);
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||||
|
{
|
||||||
|
libucontext_greg_t *sp;
|
||||||
|
va_list va;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* set up and align the stack. */
|
||||||
|
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||||
|
sp -= argc < 6 ? 0 : (argc - 6);
|
||||||
|
sp = (libucontext_greg_t *) (((uintptr_t) sp & ~0x3));
|
||||||
|
|
||||||
|
/* set up the ucontext structure */
|
||||||
|
ucp->uc_mcontext.regs.gpr[REG_SP] = (libucontext_greg_t) sp;
|
||||||
|
ucp->uc_mcontext.regs.gpr[REG_RA] = (libucontext_greg_t) &libucontext_trampoline;
|
||||||
|
ucp->uc_mcontext.regs.gpr[REG_FP] = 0;
|
||||||
|
ucp->uc_mcontext.regs.gpr[REG_SA] = (libucontext_greg_t) func;
|
||||||
|
ucp->uc_mcontext.regs.gpr[REG_LR] = (libucontext_greg_t) ucp->uc_link;
|
||||||
|
|
||||||
|
va_start(va, argc);
|
||||||
|
|
||||||
|
/* args less than argv[6] have dedicated registers, else they overflow onto stack */
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
{
|
||||||
|
if (i < 6)
|
||||||
|
ucp->uc_mcontext.regs.gpr[i + 3] = va_arg (va, libucontext_greg_t);
|
||||||
|
else
|
||||||
|
sp[i - 6] = va_arg (va, libucontext_greg_t);
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_setcontext)
|
||||||
|
l.ori r30, r3, 0 /* avoid clobbering r3 by copying to r30 */
|
||||||
|
|
||||||
|
l.lwz r3, REG_OFFSET(3)(r30) /* restore r3-r8 (argument registers) */
|
||||||
|
l.lwz r4, REG_OFFSET(4)(r30)
|
||||||
|
l.lwz r5, REG_OFFSET(5)(r30)
|
||||||
|
l.lwz r6, REG_OFFSET(6)(r30)
|
||||||
|
l.lwz r7, REG_OFFSET(7)(r30)
|
||||||
|
l.lwz r8, REG_OFFSET(8)(r30)
|
||||||
|
|
||||||
|
l.lwz r1, REG_OFFSET(1)(r30) /* restore stack/frame pointers */
|
||||||
|
l.lwz r2, REG_OFFSET(2)(r30)
|
||||||
|
|
||||||
|
l.lwz r9, REG_OFFSET(9)(r30) /* restore link register and starting address register */
|
||||||
|
l.lwz r11, REG_OFFSET(11)(r30)
|
||||||
|
|
||||||
|
l.lwz r10, REG_OFFSET(10)(r30) /* restore TLS register */
|
||||||
|
|
||||||
|
l.lwz r14, REG_OFFSET(14)(r30) /* restore r14-r30, even only */
|
||||||
|
l.lwz r16, REG_OFFSET(16)(r30)
|
||||||
|
l.lwz r18, REG_OFFSET(18)(r30)
|
||||||
|
l.lwz r20, REG_OFFSET(20)(r30)
|
||||||
|
l.lwz r22, REG_OFFSET(22)(r30)
|
||||||
|
l.lwz r24, REG_OFFSET(24)(r30)
|
||||||
|
l.lwz r26, REG_OFFSET(26)(r30)
|
||||||
|
l.lwz r28, REG_OFFSET(28)(r30)
|
||||||
|
l.lwz r30, REG_OFFSET(30)(r30)
|
||||||
|
|
||||||
|
l.jr r11 /* jump to new starting address */
|
||||||
|
l.ori r11, r0, 0
|
||||||
|
END(libucontext_setcontext)
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_swapcontext)
|
||||||
|
/* copy context into r3 like getcontext */
|
||||||
|
l.sw REG_OFFSET(1)(r3), r1 /* store r1 and r2 */
|
||||||
|
l.sw REG_OFFSET(2)(r3), r2
|
||||||
|
|
||||||
|
l.sw REG_OFFSET(9)(r3), r9 /* link register */
|
||||||
|
l.sw REG_OFFSET(11)(r3), r0 /* return value is zero */
|
||||||
|
|
||||||
|
l.sw REG_OFFSET(10)(r3), r10 /* store r10 for TLS */
|
||||||
|
|
||||||
|
l.sw REG_OFFSET(14)(r3), r14 /* store r14 through r30 even */
|
||||||
|
l.sw REG_OFFSET(16)(r3), r16
|
||||||
|
l.sw REG_OFFSET(18)(r3), r18
|
||||||
|
l.sw REG_OFFSET(20)(r3), r20
|
||||||
|
l.sw REG_OFFSET(22)(r3), r22
|
||||||
|
l.sw REG_OFFSET(24)(r3), r24
|
||||||
|
l.sw REG_OFFSET(26)(r3), r26
|
||||||
|
l.sw REG_OFFSET(28)(r3), r28
|
||||||
|
l.sw REG_OFFSET(30)(r3), r30
|
||||||
|
|
||||||
|
/* set the new context from r4 */
|
||||||
|
l.ori r30, r4, 0 /* copy r4 to r30 to avoid clobbering */
|
||||||
|
|
||||||
|
l.lwz r3, REG_OFFSET(3)(r30) /* restore r3-r8 (argument registers) */
|
||||||
|
l.lwz r4, REG_OFFSET(4)(r30)
|
||||||
|
l.lwz r5, REG_OFFSET(5)(r30)
|
||||||
|
l.lwz r6, REG_OFFSET(6)(r30)
|
||||||
|
l.lwz r7, REG_OFFSET(7)(r30)
|
||||||
|
l.lwz r8, REG_OFFSET(8)(r30)
|
||||||
|
|
||||||
|
l.lwz r1, REG_OFFSET(1)(r30) /* restore stack/frame pointers */
|
||||||
|
l.lwz r2, REG_OFFSET(2)(r30)
|
||||||
|
|
||||||
|
l.lwz r9, REG_OFFSET(9)(r30) /* restore link register and starting address register */
|
||||||
|
l.lwz r11, REG_OFFSET(11)(r30)
|
||||||
|
|
||||||
|
l.lwz r10, REG_OFFSET(10)(r30) /* restore TLS register */
|
||||||
|
|
||||||
|
l.lwz r14, REG_OFFSET(14)(r30) /* restore r14-r30, even only */
|
||||||
|
l.lwz r16, REG_OFFSET(16)(r30)
|
||||||
|
l.lwz r18, REG_OFFSET(18)(r30)
|
||||||
|
l.lwz r20, REG_OFFSET(20)(r30)
|
||||||
|
l.lwz r22, REG_OFFSET(22)(r30)
|
||||||
|
l.lwz r24, REG_OFFSET(24)(r30)
|
||||||
|
l.lwz r26, REG_OFFSET(26)(r30)
|
||||||
|
l.lwz r28, REG_OFFSET(28)(r30)
|
||||||
|
l.lwz r30, REG_OFFSET(30)(r30)
|
||||||
|
|
||||||
|
l.ori r11, r0, 0
|
||||||
|
l.jr r9 /* jump to new starting address */
|
||||||
|
END(libucontext_swapcontext)
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
#include "common-trampoline.c"
|
|
@ -10,11 +10,13 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.global libucontext_getcontext
|
#include "common-defs.h"
|
||||||
|
|
||||||
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
.hidden __libucontext_swapcontext
|
.hidden __libucontext_swapcontext
|
||||||
libucontext_getcontext:
|
FUNC(libucontext_getcontext)
|
||||||
li 4, 0
|
li 4, 0
|
||||||
b __libucontext_swapcontext@local
|
b __libucontext_swapcontext@local
|
||||||
|
END(libucontext_getcontext)
|
||||||
.weak getcontext
|
|
||||||
getcontext = libucontext_getcontext
|
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
extern void libucontext_trampoline(void);
|
extern void libucontext_trampoline(void);
|
||||||
|
@ -55,5 +55,7 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(), int argc, .
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
||||||
|
|
|
@ -10,12 +10,14 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.global libucontext_setcontext
|
#include "common-defs.h"
|
||||||
|
|
||||||
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
.hidden __libucontext_swapcontext
|
.hidden __libucontext_swapcontext
|
||||||
libucontext_setcontext:
|
FUNC(libucontext_setcontext)
|
||||||
mr 4, 3
|
mr 4, 3
|
||||||
li 3, 0
|
li 3, 0
|
||||||
b __libucontext_swapcontext@local
|
b __libucontext_swapcontext@local
|
||||||
|
END(libucontext_setcontext)
|
||||||
.weak setcontext
|
|
||||||
setcontext = libucontext_setcontext
|
|
||||||
|
|
|
@ -10,8 +10,10 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.globl libucontext_trampoline;
|
#include "common-defs.h"
|
||||||
libucontext_trampoline:
|
|
||||||
|
.hidden libucontext_trampoline
|
||||||
|
FUNC(libucontext_trampoline)
|
||||||
/* get the proper context into position and test for NULL */
|
/* get the proper context into position and test for NULL */
|
||||||
mr. 3,31
|
mr. 3,31
|
||||||
|
|
||||||
|
@ -23,3 +25,4 @@ libucontext_trampoline:
|
||||||
|
|
||||||
no_linked_context:
|
no_linked_context:
|
||||||
b exit@GOT
|
b exit@GOT
|
||||||
|
END(libucontext_trampoline)
|
||||||
|
|
|
@ -10,17 +10,20 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.global __libucontext_swapcontext
|
#include "common-defs.h"
|
||||||
__libucontext_swapcontext:
|
|
||||||
|
ALIAS(swapcontext, __libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, __libucontext_swapcontext)
|
||||||
|
|
||||||
|
/* make sure this is visible regardless of EXPORT_UNPREFIXED */
|
||||||
|
.weak libucontext_swapcontext
|
||||||
|
libucontext_swapcontext = __libucontext_swapcontext
|
||||||
|
|
||||||
|
FUNC(__libucontext_swapcontext)
|
||||||
li 0, 249 # SYS_swapcontext
|
li 0, 249 # SYS_swapcontext
|
||||||
li 5, 1184 # sizeof(ucontext_t)
|
li 5, 1184 # sizeof(ucontext_t)
|
||||||
sc
|
sc
|
||||||
|
|
||||||
.hidden __retfromsyscall
|
.hidden __retfromsyscall
|
||||||
b __retfromsyscall@local
|
b __retfromsyscall@local
|
||||||
|
END(__libucontext_swapcontext)
|
||||||
.weak swapcontext
|
|
||||||
swapcontext = libucontext_swapcontext
|
|
||||||
|
|
||||||
.weak libucontext_swapcontext
|
|
||||||
libucontext_swapcontext = __libucontext_swapcontext
|
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.global libucontext_getcontext
|
#include "common-defs.h"
|
||||||
|
|
||||||
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
.hidden __libucontext_swapcontext
|
.hidden __libucontext_swapcontext
|
||||||
libucontext_getcontext:
|
FUNC(libucontext_getcontext)
|
||||||
addis 2, 12, .TOC.-libucontext_getcontext@ha
|
addis 2, 12, .TOC.-libucontext_getcontext@ha
|
||||||
addi 2, 12, .TOC.-libucontext_getcontext@l
|
addi 2, 12, .TOC.-libucontext_getcontext@l
|
||||||
|
|
||||||
|
@ -20,6 +24,4 @@ libucontext_getcontext:
|
||||||
|
|
||||||
li 4, 0
|
li 4, 0
|
||||||
b __libucontext_swapcontext
|
b __libucontext_swapcontext
|
||||||
|
END(libucontext_getcontext)
|
||||||
.weak getcontext
|
|
||||||
getcontext = libucontext_getcontext
|
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
extern void libucontext_trampoline(void);
|
extern void libucontext_trampoline(void);
|
||||||
|
@ -56,5 +56,7 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(), int argc, .
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.global libucontext_setcontext
|
#include "common-defs.h"
|
||||||
|
|
||||||
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
.hidden __libucontext_swapcontext
|
.hidden __libucontext_swapcontext
|
||||||
libucontext_setcontext:
|
FUNC(libucontext_setcontext)
|
||||||
addis 2, 12, .TOC.-libucontext_setcontext@ha
|
addis 2, 12, .TOC.-libucontext_setcontext@ha
|
||||||
addi 2, 12, .TOC.-libucontext_setcontext@l
|
addi 2, 12, .TOC.-libucontext_setcontext@l
|
||||||
|
|
||||||
|
@ -21,6 +25,4 @@ libucontext_setcontext:
|
||||||
mr 4, 3
|
mr 4, 3
|
||||||
li 3, 0
|
li 3, 0
|
||||||
b __libucontext_swapcontext
|
b __libucontext_swapcontext
|
||||||
|
END(libucontext_setcontext)
|
||||||
.weak setcontext
|
|
||||||
setcontext = libucontext_setcontext
|
|
||||||
|
|
|
@ -10,9 +10,10 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.globl libucontext_trampoline;
|
#include "common-defs.h"
|
||||||
.hidden libucontext_trampoline;
|
|
||||||
libucontext_trampoline:
|
.hidden libucontext_trampoline
|
||||||
|
FUNC(libucontext_trampoline)
|
||||||
cmpdi 31,0 /* test if ucontext link pointer is null */
|
cmpdi 31,0 /* test if ucontext link pointer is null */
|
||||||
beq no_linked_context /* if it is, exit */
|
beq no_linked_context /* if it is, exit */
|
||||||
|
|
||||||
|
@ -29,3 +30,4 @@ libucontext_trampoline:
|
||||||
no_linked_context:
|
no_linked_context:
|
||||||
b exit@GOT
|
b exit@GOT
|
||||||
nop
|
nop
|
||||||
|
END(libucontext_trampoline)
|
||||||
|
|
|
@ -10,8 +10,16 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.global __libucontext_swapcontext
|
#include "common-defs.h"
|
||||||
__libucontext_swapcontext:
|
|
||||||
|
ALIAS(swapcontext, __libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, __libucontext_swapcontext)
|
||||||
|
|
||||||
|
/* make sure this is visible regardless of EXPORT_UNPREFIXED */
|
||||||
|
.weak libucontext_swapcontext
|
||||||
|
libucontext_swapcontext = __libucontext_swapcontext
|
||||||
|
|
||||||
|
FUNC(__libucontext_swapcontext)
|
||||||
addis 2, 12, .TOC.-__libucontext_swapcontext@ha
|
addis 2, 12, .TOC.-__libucontext_swapcontext@ha
|
||||||
addi 2, 12, .TOC.-__libucontext_swapcontext@l
|
addi 2, 12, .TOC.-__libucontext_swapcontext@l
|
||||||
|
|
||||||
|
@ -23,9 +31,4 @@ __libucontext_swapcontext:
|
||||||
|
|
||||||
.hidden __retfromsyscall
|
.hidden __retfromsyscall
|
||||||
b __retfromsyscall
|
b __retfromsyscall
|
||||||
|
END(__libucontext_swapcontext)
|
||||||
.weak swapcontext
|
|
||||||
swapcontext = __libucontext_swapcontext
|
|
||||||
|
|
||||||
.weak libucontext_swapcontext
|
|
||||||
libucontext_swapcontext = __libucontext_swapcontext
|
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
#ifndef __ARCH_RISCV64_DEFS_H
|
||||||
|
#define __ARCH_RISCV64_DEFS_H
|
||||||
|
|
||||||
|
#define REG_SZ (4)
|
||||||
|
#define MCONTEXT_GREGS (160)
|
||||||
|
|
||||||
|
/* program counter is saved in x0 as well as x1, similar to mips */
|
||||||
|
#ifndef REG_PC
|
||||||
|
#define REG_PC (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef REG_RA
|
||||||
|
#define REG_RA (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef REG_SP
|
||||||
|
#define REG_SP (2)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef REG_S0
|
||||||
|
#define REG_S0 (8)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define REG_S1 (9)
|
||||||
|
|
||||||
|
#ifndef REG_A0
|
||||||
|
#define REG_A0 (10)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define REG_A1 (11)
|
||||||
|
#define REG_A2 (12)
|
||||||
|
#define REG_A3 (13)
|
||||||
|
#define REG_A4 (14)
|
||||||
|
#define REG_A5 (15)
|
||||||
|
#define REG_A6 (16)
|
||||||
|
#define REG_A7 (17)
|
||||||
|
#define REG_S2 (18)
|
||||||
|
#define REG_S3 (19)
|
||||||
|
#define REG_S4 (20)
|
||||||
|
#define REG_S5 (21)
|
||||||
|
#define REG_S6 (22)
|
||||||
|
#define REG_S7 (23)
|
||||||
|
#define REG_S8 (24)
|
||||||
|
#define REG_S9 (25)
|
||||||
|
#define REG_S10 (26)
|
||||||
|
#define REG_S11 (27)
|
||||||
|
|
||||||
|
#define PC_OFFSET REG_OFFSET(REG_PC)
|
||||||
|
|
||||||
|
#define FETCH_LINKPTR(dest) \
|
||||||
|
asm("mv %0, s1" : "=r" ((dest)))
|
||||||
|
|
||||||
|
#include "common-defs.h"
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_getcontext)
|
||||||
|
sw ra, REG_OFFSET(REG_PC)(a0)
|
||||||
|
sw ra, REG_OFFSET(REG_RA)(a0)
|
||||||
|
sw sp, REG_OFFSET(REG_SP)(a0)
|
||||||
|
|
||||||
|
/* first saved register block */
|
||||||
|
sw s0, REG_OFFSET(REG_S0)(a0)
|
||||||
|
sw s1, REG_OFFSET(REG_S1)(a0)
|
||||||
|
|
||||||
|
/* return register block */
|
||||||
|
sw x0, REG_OFFSET(REG_A0)(a0)
|
||||||
|
sw x0, REG_OFFSET(REG_A1)(a0)
|
||||||
|
|
||||||
|
/* second saved register block */
|
||||||
|
sw s2, REG_OFFSET(REG_S2)(a0)
|
||||||
|
sw s3, REG_OFFSET(REG_S3)(a0)
|
||||||
|
sw s4, REG_OFFSET(REG_S4)(a0)
|
||||||
|
sw s5, REG_OFFSET(REG_S5)(a0)
|
||||||
|
sw s6, REG_OFFSET(REG_S6)(a0)
|
||||||
|
sw s7, REG_OFFSET(REG_S7)(a0)
|
||||||
|
sw s8, REG_OFFSET(REG_S8)(a0)
|
||||||
|
sw s9, REG_OFFSET(REG_S9)(a0)
|
||||||
|
sw s10, REG_OFFSET(REG_S10)(a0)
|
||||||
|
sw s11, REG_OFFSET(REG_S11)(a0)
|
||||||
|
|
||||||
|
/* done saving, return */
|
||||||
|
mv a0, x0
|
||||||
|
ret
|
||||||
|
END(libucontext_getcontext)
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
|
extern void libucontext_trampoline(void);
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||||
|
{
|
||||||
|
libucontext_greg_t *sp, *regp;
|
||||||
|
va_list va;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* set up and align the stack. */
|
||||||
|
sp = (libucontext_greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
|
||||||
|
sp -= argc < 8 ? 0 : argc - 8;
|
||||||
|
sp = (libucontext_greg_t *) (((uintptr_t) sp & -16L));
|
||||||
|
|
||||||
|
/* set up the ucontext structure */
|
||||||
|
ucp->uc_mcontext.__gregs[REG_RA] = (libucontext_greg_t) libucontext_trampoline;
|
||||||
|
ucp->uc_mcontext.__gregs[REG_S0] = 0;
|
||||||
|
ucp->uc_mcontext.__gregs[REG_S1] = (libucontext_greg_t) ucp->uc_link;
|
||||||
|
ucp->uc_mcontext.__gregs[REG_SP] = (libucontext_greg_t) sp;
|
||||||
|
ucp->uc_mcontext.__gregs[REG_PC] = (libucontext_greg_t) func;
|
||||||
|
|
||||||
|
va_start(va, argc);
|
||||||
|
|
||||||
|
/* first 8 args go in $a0 through $a7. */
|
||||||
|
regp = &(ucp->uc_mcontext.__gregs[REG_A0]);
|
||||||
|
|
||||||
|
for (i = 0; (i < argc && i < 8); i++)
|
||||||
|
*regp++ = va_arg (va, libucontext_greg_t);
|
||||||
|
|
||||||
|
/* remainder overflows into stack */
|
||||||
|
for (; i < argc; i++)
|
||||||
|
*sp++ = va_arg (va, libucontext_greg_t);
|
||||||
|
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_setcontext)
|
||||||
|
/* move $a0 to $t0 to avoid clobbering. */
|
||||||
|
mv t0, a0
|
||||||
|
|
||||||
|
lw t1, PC_OFFSET(t0)
|
||||||
|
lw ra, REG_OFFSET(REG_RA)(t0)
|
||||||
|
lw sp, REG_OFFSET(REG_SP)(t0)
|
||||||
|
|
||||||
|
/* first saved register block */
|
||||||
|
lw s0, REG_OFFSET(REG_S0)(t0)
|
||||||
|
lw s1, REG_OFFSET(REG_S1)(t0)
|
||||||
|
|
||||||
|
/* return register block */
|
||||||
|
lw a0, REG_OFFSET(REG_A0)(t0)
|
||||||
|
lw a1, REG_OFFSET(REG_A1)(t0)
|
||||||
|
|
||||||
|
/* argument register block */
|
||||||
|
lw a2, REG_OFFSET(REG_A2)(t0)
|
||||||
|
lw a3, REG_OFFSET(REG_A3)(t0)
|
||||||
|
lw a4, REG_OFFSET(REG_A4)(t0)
|
||||||
|
lw a5, REG_OFFSET(REG_A5)(t0)
|
||||||
|
lw a6, REG_OFFSET(REG_A6)(t0)
|
||||||
|
lw a7, REG_OFFSET(REG_A7)(t0)
|
||||||
|
|
||||||
|
/* second saved register block */
|
||||||
|
lw s2, REG_OFFSET(REG_S2)(t0)
|
||||||
|
lw s3, REG_OFFSET(REG_S3)(t0)
|
||||||
|
lw s4, REG_OFFSET(REG_S4)(t0)
|
||||||
|
lw s5, REG_OFFSET(REG_S5)(t0)
|
||||||
|
lw s6, REG_OFFSET(REG_S6)(t0)
|
||||||
|
lw s7, REG_OFFSET(REG_S7)(t0)
|
||||||
|
lw s8, REG_OFFSET(REG_S8)(t0)
|
||||||
|
lw s9, REG_OFFSET(REG_S9)(t0)
|
||||||
|
lw s10, REG_OFFSET(REG_S10)(t0)
|
||||||
|
lw s11, REG_OFFSET(REG_S11)(t0)
|
||||||
|
|
||||||
|
/* done restoring, jump to new pc in S1 */
|
||||||
|
jr t1
|
||||||
|
END(libucontext_setcontext)
|
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_swapcontext)
|
||||||
|
/* move $a1 to $t0 to avoid clobbering. */
|
||||||
|
mv t0, a1
|
||||||
|
|
||||||
|
sw ra, REG_OFFSET(REG_PC)(a0)
|
||||||
|
sw ra, REG_OFFSET(REG_RA)(a0)
|
||||||
|
sw sp, REG_OFFSET(REG_SP)(a0)
|
||||||
|
|
||||||
|
/* first saved register block */
|
||||||
|
sw s0, REG_OFFSET(REG_S0)(a0)
|
||||||
|
sw s1, REG_OFFSET(REG_S1)(a0)
|
||||||
|
|
||||||
|
/* return register block */
|
||||||
|
sw x0, REG_OFFSET(REG_A0)(a0)
|
||||||
|
sw x0, REG_OFFSET(REG_A1)(a0)
|
||||||
|
|
||||||
|
/* second saved register block */
|
||||||
|
sw s2, REG_OFFSET(REG_S2)(a0)
|
||||||
|
sw s3, REG_OFFSET(REG_S3)(a0)
|
||||||
|
sw s4, REG_OFFSET(REG_S4)(a0)
|
||||||
|
sw s5, REG_OFFSET(REG_S5)(a0)
|
||||||
|
sw s6, REG_OFFSET(REG_S6)(a0)
|
||||||
|
sw s7, REG_OFFSET(REG_S7)(a0)
|
||||||
|
sw s8, REG_OFFSET(REG_S8)(a0)
|
||||||
|
sw s9, REG_OFFSET(REG_S9)(a0)
|
||||||
|
sw s10, REG_OFFSET(REG_S10)(a0)
|
||||||
|
sw s11, REG_OFFSET(REG_S11)(a0)
|
||||||
|
|
||||||
|
/* restore the other context from $t0. */
|
||||||
|
lw t1, REG_OFFSET(REG_PC)(t0)
|
||||||
|
lw ra, REG_OFFSET(REG_RA)(t0)
|
||||||
|
lw sp, REG_OFFSET(REG_SP)(t0)
|
||||||
|
|
||||||
|
/* first saved register block */
|
||||||
|
lw s0, REG_OFFSET(REG_S0)(t0)
|
||||||
|
lw s1, REG_OFFSET(REG_S1)(t0)
|
||||||
|
|
||||||
|
/* return register block */
|
||||||
|
lw a0, REG_OFFSET(REG_A0)(t0)
|
||||||
|
lw a1, REG_OFFSET(REG_A1)(t0)
|
||||||
|
|
||||||
|
/* argument register block */
|
||||||
|
lw a2, REG_OFFSET(REG_A2)(t0)
|
||||||
|
lw a3, REG_OFFSET(REG_A3)(t0)
|
||||||
|
lw a4, REG_OFFSET(REG_A4)(t0)
|
||||||
|
lw a5, REG_OFFSET(REG_A5)(t0)
|
||||||
|
lw a6, REG_OFFSET(REG_A6)(t0)
|
||||||
|
lw a7, REG_OFFSET(REG_A7)(t0)
|
||||||
|
|
||||||
|
/* second saved register block */
|
||||||
|
lw s2, REG_OFFSET(REG_S2)(t0)
|
||||||
|
lw s3, REG_OFFSET(REG_S3)(t0)
|
||||||
|
lw s4, REG_OFFSET(REG_S4)(t0)
|
||||||
|
lw s5, REG_OFFSET(REG_S5)(t0)
|
||||||
|
lw s6, REG_OFFSET(REG_S6)(t0)
|
||||||
|
lw s7, REG_OFFSET(REG_S7)(t0)
|
||||||
|
lw s8, REG_OFFSET(REG_S8)(t0)
|
||||||
|
lw s9, REG_OFFSET(REG_S9)(t0)
|
||||||
|
lw s10, REG_OFFSET(REG_S10)(t0)
|
||||||
|
lw s11, REG_OFFSET(REG_S11)(t0)
|
||||||
|
|
||||||
|
/* done swapping, jump to new PC in S1 */
|
||||||
|
jr t1
|
||||||
|
END(libucontext_swapcontext)
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
#include "common-trampoline.c"
|
|
@ -47,6 +47,9 @@
|
||||||
|
|
||||||
#define PC_OFFSET REG_OFFSET(REG_PC)
|
#define PC_OFFSET REG_OFFSET(REG_PC)
|
||||||
|
|
||||||
|
#define FETCH_LINKPTR(dest) \
|
||||||
|
asm("mv %0, s1" : "=r" ((dest)))
|
||||||
|
|
||||||
#include "common-defs.h"
|
#include "common-defs.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(getcontext, libucontext_getcontext)
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
FUNC(libucontext_getcontext)
|
FUNC(libucontext_getcontext)
|
||||||
sd ra, REG_OFFSET(REG_PC)(a0)
|
sd ra, REG_OFFSET(REG_PC)(a0)
|
||||||
|
@ -24,8 +25,8 @@ FUNC(libucontext_getcontext)
|
||||||
sd s1, REG_OFFSET(REG_S1)(a0)
|
sd s1, REG_OFFSET(REG_S1)(a0)
|
||||||
|
|
||||||
/* return register block */
|
/* return register block */
|
||||||
sd a0, REG_OFFSET(REG_A0)(a0)
|
sd x0, REG_OFFSET(REG_A0)(a0)
|
||||||
sd a1, REG_OFFSET(REG_A1)(a0)
|
sd x0, REG_OFFSET(REG_A1)(a0)
|
||||||
|
|
||||||
/* second saved register block */
|
/* second saved register block */
|
||||||
sd s2, REG_OFFSET(REG_S2)(a0)
|
sd s2, REG_OFFSET(REG_S2)(a0)
|
||||||
|
@ -40,5 +41,6 @@ FUNC(libucontext_getcontext)
|
||||||
sd s11, REG_OFFSET(REG_S11)(a0)
|
sd s11, REG_OFFSET(REG_S11)(a0)
|
||||||
|
|
||||||
/* done saving, return */
|
/* done saving, return */
|
||||||
|
mv a0, x0
|
||||||
ret
|
ret
|
||||||
END(libucontext_getcontext)
|
END(libucontext_getcontext)
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
#ifndef LIBUCONTEXT_BITS_H
|
||||||
|
#define LIBUCONTEXT_BITS_H
|
||||||
|
|
||||||
|
typedef unsigned long libucontext_greg_t;
|
||||||
|
typedef unsigned long libucontext__riscv_mc_gp_state[32];
|
||||||
|
|
||||||
|
struct libucontext__riscv_mc_f_ext_state {
|
||||||
|
unsigned int __f[32];
|
||||||
|
unsigned int __fcsr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct libucontext__riscv_mc_d_ext_state {
|
||||||
|
unsigned long long __f[32];
|
||||||
|
unsigned int __fcsr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct libucontext__riscv_mc_q_ext_state {
|
||||||
|
unsigned long long __f[64] __attribute__((aligned(16)));
|
||||||
|
unsigned int __fcsr;
|
||||||
|
unsigned int __reserved[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
union libucontext__riscv_mc_fp_state {
|
||||||
|
struct libucontext__riscv_mc_f_ext_state __f;
|
||||||
|
struct libucontext__riscv_mc_d_ext_state __d;
|
||||||
|
struct libucontext__riscv_mc_q_ext_state __q;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct libucontext_mcontext {
|
||||||
|
libucontext__riscv_mc_gp_state __gregs;
|
||||||
|
union libucontext__riscv_mc_fp_state __fpregs;
|
||||||
|
} libucontext_mcontext_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *ss_sp;
|
||||||
|
int ss_flags;
|
||||||
|
size_t ss_size;
|
||||||
|
} libucontext_stack_t;
|
||||||
|
|
||||||
|
typedef struct libucontext_ucontext {
|
||||||
|
unsigned long uc_flags;
|
||||||
|
struct libucontext_ucontext *uc_link;
|
||||||
|
libucontext_stack_t uc_stack;
|
||||||
|
unsigned char __pad[128];
|
||||||
|
libucontext_mcontext_t uc_mcontext;
|
||||||
|
} libucontext_ucontext_t;
|
||||||
|
|
||||||
|
#endif
|
|
@ -10,13 +10,13 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
extern void libucontext_trampoline(void);
|
extern void libucontext_trampoline(void);
|
||||||
|
@ -37,10 +37,9 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
||||||
/* set up the ucontext structure */
|
/* set up the ucontext structure */
|
||||||
ucp->uc_mcontext.__gregs[REG_RA] = (libucontext_greg_t) libucontext_trampoline;
|
ucp->uc_mcontext.__gregs[REG_RA] = (libucontext_greg_t) libucontext_trampoline;
|
||||||
ucp->uc_mcontext.__gregs[REG_S0] = 0;
|
ucp->uc_mcontext.__gregs[REG_S0] = 0;
|
||||||
ucp->uc_mcontext.__gregs[REG_S1] = (libucontext_greg_t) func;
|
ucp->uc_mcontext.__gregs[REG_S1] = (libucontext_greg_t) ucp->uc_link;
|
||||||
ucp->uc_mcontext.__gregs[REG_S2] = (libucontext_greg_t) ucp->uc_link;
|
|
||||||
ucp->uc_mcontext.__gregs[REG_SP] = (libucontext_greg_t) sp;
|
ucp->uc_mcontext.__gregs[REG_SP] = (libucontext_greg_t) sp;
|
||||||
ucp->uc_mcontext.__gregs[REG_PC] = 0;
|
ucp->uc_mcontext.__gregs[REG_PC] = (libucontext_greg_t) func;
|
||||||
|
|
||||||
va_start(va, argc);
|
va_start(va, argc);
|
||||||
|
|
||||||
|
@ -57,5 +56,7 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(setcontext, libucontext_setcontext)
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
FUNC(libucontext_setcontext)
|
FUNC(libucontext_setcontext)
|
||||||
/* move $a0 to $t0 to avoid clobbering. */
|
/* move $a0 to $t0 to avoid clobbering. */
|
||||||
|
@ -50,6 +51,6 @@ FUNC(libucontext_setcontext)
|
||||||
ld s10, REG_OFFSET(REG_S10)(t0)
|
ld s10, REG_OFFSET(REG_S10)(t0)
|
||||||
ld s11, REG_OFFSET(REG_S11)(t0)
|
ld s11, REG_OFFSET(REG_S11)(t0)
|
||||||
|
|
||||||
/* done saving, return */
|
/* done restoring, jump to new pc in S1 */
|
||||||
ret
|
jr t1
|
||||||
END(libucontext_setcontext)
|
END(libucontext_setcontext)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(swapcontext, libucontext_swapcontext)
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
FUNC(libucontext_swapcontext)
|
FUNC(libucontext_swapcontext)
|
||||||
/* move $a1 to $t0 to avoid clobbering. */
|
/* move $a1 to $t0 to avoid clobbering. */
|
||||||
|
@ -27,8 +28,8 @@ FUNC(libucontext_swapcontext)
|
||||||
sd s1, REG_OFFSET(REG_S1)(a0)
|
sd s1, REG_OFFSET(REG_S1)(a0)
|
||||||
|
|
||||||
/* return register block */
|
/* return register block */
|
||||||
sd a0, REG_OFFSET(REG_A0)(a0)
|
sd x0, REG_OFFSET(REG_A0)(a0)
|
||||||
sd a1, REG_OFFSET(REG_A1)(a0)
|
sd x0, REG_OFFSET(REG_A1)(a0)
|
||||||
|
|
||||||
/* second saved register block */
|
/* second saved register block */
|
||||||
sd s2, REG_OFFSET(REG_S2)(a0)
|
sd s2, REG_OFFSET(REG_S2)(a0)
|
||||||
|
@ -75,6 +76,6 @@ FUNC(libucontext_swapcontext)
|
||||||
ld s10, REG_OFFSET(REG_S10)(t0)
|
ld s10, REG_OFFSET(REG_S10)(t0)
|
||||||
ld s11, REG_OFFSET(REG_S11)(t0)
|
ld s11, REG_OFFSET(REG_S11)(t0)
|
||||||
|
|
||||||
/* done swapping, return */
|
/* done swapping, jump to new PC in S1 */
|
||||||
ret
|
jr t1
|
||||||
END(libucontext_swapcontext)
|
END(libucontext_swapcontext)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
#include "common-trampoline.c"
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(getcontext, libucontext_getcontext)
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
FUNC(libucontext_getcontext)
|
FUNC(libucontext_getcontext)
|
||||||
lgr %r1, %r2 /* use %r1 as our working register */
|
lgr %r1, %r2 /* use %r1 as our working register */
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
* from the use of this software.
|
* from the use of this software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -18,6 +17,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
extern void libucontext_trampoline(void);
|
extern void libucontext_trampoline(void);
|
||||||
|
@ -62,5 +62,7 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
|
||||||
ucp->uc_mcontext.gregs[15] = (uintptr_t) sp;
|
ucp->uc_mcontext.gregs[15] = (uintptr_t) sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(setcontext, libucontext_setcontext)
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
FUNC(libucontext_setcontext)
|
FUNC(libucontext_setcontext)
|
||||||
lgr %r1, %r2 /* use %r1 as our working register */
|
lgr %r1, %r2 /* use %r1 as our working register */
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
|
.hidden libucontext_trampoline
|
||||||
FUNC(libucontext_trampoline)
|
FUNC(libucontext_trampoline)
|
||||||
basr %r14, %r7 /* run function pointer (%r7) and return here */
|
basr %r14, %r7 /* run function pointer (%r7) and return here */
|
||||||
ltgr %r8, %r8 /* check to see if uc_link (%r8) is null */
|
ltgr %r8, %r8 /* check to see if uc_link (%r8) is null */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, 2020 Ariadne Conill <ariadne@dereferenced.org>
|
* Copyright (c) 2018, 2020, 2024 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -13,17 +13,20 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(swapcontext, libucontext_swapcontext)
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
FUNC(libucontext_swapcontext)
|
FUNC(libucontext_swapcontext)
|
||||||
lgr %r1, %r2 /* use %r1 to save current context to */
|
lgr %r1, %r2 /* use %r1 to save current context to */
|
||||||
lgr %r0, %r3 /* use %r0 for source context */
|
lgr %r0, %r3 /* use %r0 for source context */
|
||||||
|
|
||||||
|
la %r2, 0 /* zero out future return value */
|
||||||
|
|
||||||
stam %a0, %a15, AREG_OFFSET(0)(%r1) /* store access registers */
|
stam %a0, %a15, AREG_OFFSET(0)(%r1) /* store access registers */
|
||||||
stmg %r0, %r15, REG_OFFSET(0)(%r1) /* store general-purpose registers */
|
stmg %r0, %r15, REG_OFFSET(0)(%r1) /* store general-purpose registers */
|
||||||
|
|
||||||
lgr %r2, %r0 /* swap %r0 to %r2 (XXX: figure out why it hates loading from %r0) */
|
lgr %r5, %r0 /* copy %r0 to %r5 so that %r0 doesn't get clobbered */
|
||||||
lam %a2, %a15, AREG_OFFSET(2)(%r2) /* load access registers, but skip %a0 and %a1 which are for TLS */
|
lam %a2, %a15, AREG_OFFSET(2)(%r5) /* load access registers, but skip %a0 and %a1 which are for TLS */
|
||||||
lmg %r0, %r15, REG_OFFSET(0)(%r2) /* load general-purpose registers */
|
lmg %r0, %r15, REG_OFFSET(0)(%r5) /* load general-purpose registers */
|
||||||
|
|
||||||
br %r14 /* return to new link register address */
|
br %r14 /* return to new link register address */
|
||||||
END(libucontext_swapcontext)
|
END(libucontext_swapcontext)
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef __ARCH_SH4_DEFS_H
|
||||||
|
#define __ARCH_SH4_DEFS_H
|
||||||
|
|
||||||
|
#define REG_SZ (4)
|
||||||
|
#define MCONTEXT_GREGS (24)
|
||||||
|
|
||||||
|
#define REG_SP (15)
|
||||||
|
#define REG_PC (16)
|
||||||
|
#define REG_PR (17)
|
||||||
|
#define REG_SR (18)
|
||||||
|
#define REG_GBR (19)
|
||||||
|
#define REG_MACH (20)
|
||||||
|
#define REG_MACL (21)
|
||||||
|
|
||||||
|
#define FETCH_LINKPTR(dest) \
|
||||||
|
asm("mov r8, %0" : "=r" (dest));
|
||||||
|
|
||||||
|
#include "common-defs.h"
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_getcontext)
|
||||||
|
mov r4, r0 /* move r4 to r0, and increment by REG_OFFSET(REG_MACL) + REG_SZ. */
|
||||||
|
add #(REG_OFFSET(REG_MACL + 1)), r0
|
||||||
|
|
||||||
|
sts.l macl, @-r0 /* save macl/mach registers */
|
||||||
|
sts.l mach, @-r0
|
||||||
|
|
||||||
|
stc.l gbr, @-r0 /* save gbr register */
|
||||||
|
|
||||||
|
movt r1 /* load T-flag into r1 */
|
||||||
|
mov.l r1, @-r0 /* save T-flag as SR register */
|
||||||
|
|
||||||
|
sts.l pr, @-r0 /* save current PR */
|
||||||
|
sts.l pr, @-r0 /* save current PR as PC as well */
|
||||||
|
|
||||||
|
mov.l r15, @-r0 /* preserve registers backwards, from r15 to r1 */
|
||||||
|
mov.l r14, @-r0
|
||||||
|
mov.l r13, @-r0
|
||||||
|
mov.l r12, @-r0
|
||||||
|
mov.l r11, @-r0
|
||||||
|
mov.l r10, @-r0
|
||||||
|
mov.l r9, @-r0
|
||||||
|
mov.l r8, @-r0
|
||||||
|
mov.l r7, @-r0
|
||||||
|
mov.l r6, @-r0
|
||||||
|
mov.l r5, @-r0
|
||||||
|
mov.l r4, @-r0
|
||||||
|
mov.l r3, @-r0
|
||||||
|
mov.l r2, @-r0
|
||||||
|
mov.l r1, @-r0
|
||||||
|
|
||||||
|
mov r0, r1
|
||||||
|
mov #0, r0
|
||||||
|
|
||||||
|
mov.l r0, @-r1 /* preserve r0 as explicit zero */
|
||||||
|
|
||||||
|
mov #0, r0 /* set return value as zero */
|
||||||
|
rts
|
||||||
|
END(libucontext_getcontext)
|
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef LIBUCONTEXT_BITS_H
|
||||||
|
#define LIBUCONTEXT_BITS_H
|
||||||
|
|
||||||
|
typedef unsigned long libucontext_greg_t, libucontext_gregset_t[16];
|
||||||
|
typedef unsigned long libucontext_freg_t, libucontext_fpregset_t[16];
|
||||||
|
typedef struct sigcontext {
|
||||||
|
unsigned long oldmask;
|
||||||
|
unsigned long gregs[16];
|
||||||
|
unsigned long pc, pr, sr;
|
||||||
|
unsigned long gbr, mach, macl;
|
||||||
|
unsigned long fpregs[16];
|
||||||
|
unsigned long xfpregs[16];
|
||||||
|
unsigned int fpscr, fpul, ownedfp;
|
||||||
|
} libucontext_mcontext_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void *ss_sp;
|
||||||
|
int ss_flags;
|
||||||
|
size_t ss_size;
|
||||||
|
} libucontext_stack_t;
|
||||||
|
|
||||||
|
typedef struct libucontext_ucontext {
|
||||||
|
unsigned long uc_flags;
|
||||||
|
struct libucontext_ucontext *uc_link;
|
||||||
|
libucontext_stack_t uc_stack;
|
||||||
|
libucontext_mcontext_t uc_mcontext;
|
||||||
|
} libucontext_ucontext_t;
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
|
||||||
|
|
||||||
|
extern void libucontext_trampoline(void);
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...)
|
||||||
|
{
|
||||||
|
libucontext_greg_t *sp, *regp;
|
||||||
|
va_list va;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* set up and align the stack */
|
||||||
|
sp = (libucontext_greg_t *) (((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & -4L);
|
||||||
|
sp -= argc > 4 ? argc - 4 : 0;
|
||||||
|
|
||||||
|
/* set up the context */
|
||||||
|
ucp->uc_mcontext.gregs[REG_SP] = (libucontext_greg_t) sp;
|
||||||
|
ucp->uc_mcontext.pr = (libucontext_greg_t) libucontext_trampoline;
|
||||||
|
ucp->uc_mcontext.pc = (libucontext_greg_t) func;
|
||||||
|
ucp->uc_mcontext.gregs[8] = (libucontext_greg_t) ucp->uc_link;
|
||||||
|
|
||||||
|
/* pass up to four args in r4-r7, rest on stack */
|
||||||
|
va_start(va, argc);
|
||||||
|
|
||||||
|
regp = &ucp->uc_mcontext.gregs[4];
|
||||||
|
|
||||||
|
for (i = 0; i < argc && i < 4; i++)
|
||||||
|
*regp++ = va_arg(va, libucontext_greg_t);
|
||||||
|
|
||||||
|
for (; i < argc; i++)
|
||||||
|
*sp++ = va_arg(va, libucontext_greg_t);
|
||||||
|
|
||||||
|
va_end(va);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef EXPORT_UNPREFIXED
|
||||||
|
extern __typeof(libucontext_makecontext) makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
extern __typeof(libucontext_makecontext) __makecontext __attribute__((weak, __alias__("libucontext_makecontext")));
|
||||||
|
#endif
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(setcontext, libucontext_setcontext)
|
||||||
|
ALIAS(__setcontext, libucontext_setcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_setcontext)
|
||||||
|
mov r4, r0
|
||||||
|
|
||||||
|
add #(REG_OFFSET(5)), r0 /* restore GPRs r5-15 */
|
||||||
|
mov.l @r0+, r5
|
||||||
|
mov.l @r0+, r6
|
||||||
|
mov.l @r0+, r7
|
||||||
|
mov.l @r0+, r8
|
||||||
|
mov.l @r0+, r9
|
||||||
|
mov.l @r0+, r10
|
||||||
|
mov.l @r0+, r11
|
||||||
|
mov.l @r0+, r12
|
||||||
|
mov.l @r0+, r13
|
||||||
|
mov.l @r0+, r14
|
||||||
|
mov.l @r0+, r15
|
||||||
|
|
||||||
|
mov.l @r0+, r2 /* restore PR */
|
||||||
|
lds.l @r0+, pr
|
||||||
|
|
||||||
|
mov.l @r0+, r1 /* restore T-flag */
|
||||||
|
shlr r1
|
||||||
|
|
||||||
|
add #REG_SZ, r0 /* skip GBR (used for TLS) */
|
||||||
|
|
||||||
|
lds.l @r0+, mach /* load mach/macl registers */
|
||||||
|
lds.l @r0+, macl
|
||||||
|
|
||||||
|
mov r4, r0 /* bring r0 back to the top of the context */
|
||||||
|
add #(REG_OFFSET(0)), r1 /* restore r0 into r1 (temporarily) */
|
||||||
|
mov.l r1, @-r15 /* push to stack from r1 */
|
||||||
|
mov.l r2, @-r15 /* push PC to stack */
|
||||||
|
|
||||||
|
mov.l @(REG_OFFSET(1), r0), r1 /* restore real r1 */
|
||||||
|
mov.l @(REG_OFFSET(2), r0), r2 /* restore real r2 */
|
||||||
|
mov.l @(REG_OFFSET(3), r0), r3 /* restore real r2 */
|
||||||
|
mov.l @(REG_OFFSET(4), r0), r4 /* restore real r2 */
|
||||||
|
|
||||||
|
mov.l @r15+, r0 /* pop PC from stack */
|
||||||
|
|
||||||
|
jmp @r0 /* jump to new PC */
|
||||||
|
|
||||||
|
mov.l @r15+, r0 /* pop original r0 from stack */
|
||||||
|
END(libucontext_setcontext)
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Ariadne Conill <ariadne@dereferenced.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* This software is provided 'as is' and without any warranty, express or
|
||||||
|
* implied. In no event shall the authors be liable for any damages arising
|
||||||
|
* from the use of this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
|
ALIAS(swapcontext, libucontext_swapcontext)
|
||||||
|
ALIAS(__swapcontext, libucontext_swapcontext)
|
||||||
|
|
||||||
|
FUNC(libucontext_swapcontext)
|
||||||
|
mov r4, r0 /* move r4 to r0, and increment by REG_OFFSET(REG_MACL) + REG_SZ. */
|
||||||
|
add #(REG_OFFSET(REG_MACL + 1)), r0
|
||||||
|
|
||||||
|
sts.l macl, @-r0 /* save macl/mach registers */
|
||||||
|
sts.l mach, @-r0
|
||||||
|
|
||||||
|
stc.l gbr, @-r0 /* save gbr register */
|
||||||
|
|
||||||
|
movt r1 /* load T-flag into r1 */
|
||||||
|
mov.l r1, @-r0 /* save T-flag as SR register */
|
||||||
|
|
||||||
|
sts.l pr, @-r0 /* save current PR */
|
||||||
|
sts.l pr, @-r0 /* save current PR as PC as well */
|
||||||
|
|
||||||
|
mov.l r15, @-r0 /* preserve registers backwards, from r15 to r1 */
|
||||||
|
mov.l r14, @-r0
|
||||||
|
mov.l r13, @-r0
|
||||||
|
mov.l r12, @-r0
|
||||||
|
mov.l r11, @-r0
|
||||||
|
mov.l r10, @-r0
|
||||||
|
mov.l r9, @-r0
|
||||||
|
mov.l r8, @-r0
|
||||||
|
mov.l r7, @-r0
|
||||||
|
mov.l r6, @-r0
|
||||||
|
mov.l r5, @-r0
|
||||||
|
mov.l r4, @-r0
|
||||||
|
mov.l r3, @-r0
|
||||||
|
mov.l r2, @-r0
|
||||||
|
mov.l r1, @-r0
|
||||||
|
|
||||||
|
mov r0, r1
|
||||||
|
mov #0, r0
|
||||||
|
|
||||||
|
mov.l r0, @-r1 /* preserve r0 as explicit zero */
|
||||||
|
|
||||||
|
mov r5, r0 /* now restore the new context */
|
||||||
|
|
||||||
|
add #(REG_OFFSET(6)), r0 /* restore GPRs r6-15 */
|
||||||
|
mov.l @r0+, r6
|
||||||
|
mov.l @r0+, r7
|
||||||
|
mov.l @r0+, r8
|
||||||
|
mov.l @r0+, r9
|
||||||
|
mov.l @r0+, r10
|
||||||
|
mov.l @r0+, r11
|
||||||
|
mov.l @r0+, r12
|
||||||
|
mov.l @r0+, r13
|
||||||
|
mov.l @r0+, r14
|
||||||
|
mov.l @r0+, r15
|
||||||
|
|
||||||
|
mov.l @r0+, r2 /* restore PR */
|
||||||
|
lds.l @r0+, pr
|
||||||
|
|
||||||
|
mov.l @r0+, r1 /* restore T-flag */
|
||||||
|
shlr r1
|
||||||
|
|
||||||
|
add #REG_SZ, r0 /* skip GBR (used for TLS) */
|
||||||
|
|
||||||
|
lds.l @r0+, mach /* load mach/macl registers */
|
||||||
|
lds.l @r0+, macl
|
||||||
|
|
||||||
|
mov r5, r0 /* bring r0 back to the top of the context */
|
||||||
|
add #(REG_OFFSET(0)), r1 /* restore r0 into r1 (temporarily) */
|
||||||
|
mov.l r1, @-r15 /* push to stack from r1 */
|
||||||
|
mov.l r2, @-r15 /* push PC to stack */
|
||||||
|
|
||||||
|
mov.l @(REG_OFFSET(1), r0), r1 /* restore real r1 */
|
||||||
|
mov.l @(REG_OFFSET(2), r0), r2 /* restore real r2 */
|
||||||
|
mov.l @(REG_OFFSET(3), r0), r3 /* restore real r3 */
|
||||||
|
mov.l @(REG_OFFSET(4), r0), r4 /* restore real r4 */
|
||||||
|
mov.l @(REG_OFFSET(5), r0), r5 /* restore real r5 */
|
||||||
|
|
||||||
|
mov.l @r15+, r0 /* pop PC from stack */
|
||||||
|
|
||||||
|
jmp @r0 /* jump to new PC */
|
||||||
|
|
||||||
|
mov.l @r15+, r0 /* pop original r0 from stack */
|
||||||
|
END(libucontext_swapcontext)
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "defs.h"
|
||||||
|
#include <libucontext/libucontext.h>
|
||||||
|
#include "common-trampoline.c"
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef __ARCH_X86_DEFS_H
|
#ifndef __ARCH_X86_DEFS_H
|
||||||
#define __ARCH_X86_DEFS_H
|
#define __ARCH_X86_DEFS_H
|
||||||
|
|
||||||
#ifndef _GNU_SOURCE
|
|
||||||
#ifndef REG_GS
|
#ifndef REG_GS
|
||||||
# define REG_GS (0)
|
# define REG_GS (0)
|
||||||
#endif
|
#endif
|
||||||
|
@ -53,7 +52,6 @@
|
||||||
#ifndef REG_EIP
|
#ifndef REG_EIP
|
||||||
# define REG_EIP (14)
|
# define REG_EIP (14)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#define REG_SZ (4)
|
#define REG_SZ (4)
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
ALIAS(getcontext, libucontext_getcontext)
|
ALIAS(getcontext, libucontext_getcontext)
|
||||||
|
ALIAS(__getcontext, libucontext_getcontext)
|
||||||
|
|
||||||
FUNC(libucontext_getcontext)
|
FUNC(libucontext_getcontext)
|
||||||
/* load address of the ucontext structure */
|
/* load address of the ucontext structure */
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue