riscv64: simplify the context swapping
parent
6763b5ba1e
commit
11a40293be
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,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,14 +13,11 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
FUNC(libucontext_trampoline)
|
FUNC(libucontext_trampoline)
|
||||||
/* call the function passed to makecontext() */
|
|
||||||
jalr s1
|
|
||||||
|
|
||||||
/* check for linked context */
|
/* check for linked context */
|
||||||
beqz s2, no_linked_context
|
beqz s1, no_linked_context
|
||||||
|
|
||||||
/* if one is set, invoke it */
|
/* if one is set, invoke it */
|
||||||
mv a0, s2
|
mv a0, s1
|
||||||
jal libucontext_setcontext
|
jal libucontext_setcontext
|
||||||
|
|
||||||
/* otherwise, exit. */
|
/* otherwise, exit. */
|
||||||
|
|
|
@ -75,6 +75,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)
|
||||||
|
|
Loading…
Reference in New Issue