sh: add remaining port files

pull/23/head
Ariadne Conill 2020-12-11 23:18:04 +00:00
parent a42fb86da0
commit da3c8d170f
3 changed files with 36 additions and 5 deletions

View File

@ -99,7 +99,7 @@ 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_BSD_SOURCE -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
.S.o: .S.o:
$(CC) -fPIC -DPIC -DLIBUCONTEXT_ASSEMBLY ${CFLAGS} ${CPPFLAGS} -c -o $@ $< $(CC) -fPIC -DPIC -DLIBUCONTEXT_ASSEMBLY ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
@ -181,18 +181,18 @@ check_libucontext_posix: test_libucontext_posix ${LIBUCONTEXT_POSIX_SONAME}
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext_posix env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext_posix
test_libucontext_posix: test_libucontext_posix.c ${LIBUCONTEXT_POSIX_NAME} test_libucontext_posix: test_libucontext_posix.c ${LIBUCONTEXT_POSIX_NAME}
$(CC) -std=c99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext $(CC) -std=gnu99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
endif endif
check: test_libucontext ${LIBUCONTEXT_SONAME} check: test_libucontext ${LIBUCONTEXT_SONAME}
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext env LD_LIBRARY_PATH=$(shell pwd) ./test_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_BSD_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_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
ifeq ($(FREESTANDING),no) ifeq ($(FREESTANDING),no)

View File

@ -37,12 +37,15 @@ libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int arg
ucp->uc_mcontext.sr = (libucontext_greg_t) sp; ucp->uc_mcontext.sr = (libucontext_greg_t) sp;
ucp->uc_mcontext.pr = (libucontext_greg_t) libucontext_trampoline; ucp->uc_mcontext.pr = (libucontext_greg_t) libucontext_trampoline;
ucp->uc_mcontext.pc = (libucontext_greg_t) func; 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 */ /* pass up to four args in r4-r7, rest on stack */
va_start(va, argc); va_start(va, argc);
regp = &ucp->uc_mcontext.gregs[4];
for (i = 0; i < argc && i < 4; i++) for (i = 0; i < argc && i < 4; i++)
ucp->uc_mcontext.gregs[4 + i] = va_arg(va, libucontext_greg_t); *regp++ = va_arg(va, libucontext_greg_t);
for (; i < argc; i++) for (; i < argc; i++)
*sp++ = va_arg(va, libucontext_greg_t); *sp++ = va_arg(va, libucontext_greg_t);

28
arch/sh/trampoline.c Normal file
View File

@ -0,0 +1,28 @@
/*
* 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 "defs.h"
void
libucontext_trampoline(void)
{
libucontext_ucontext_t *uc_link;
asm("mov r8, %0" : "=r" (uc_link));
if (uc_link == NULL)
exit(0);
libucontext_setcontext(uc_link);
}