From 0c6077854aa223cfa40378393391f06621cfc814 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sun, 6 Dec 2020 13:08:31 +0000 Subject: [PATCH] riscv64: add freestanding port --- README.md | 2 +- arch/riscv64/freestanding/bits.h | 48 ++++++++++++++++++++++++++++++++ arch/riscv64/makecontext.c | 2 +- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 arch/riscv64/freestanding/bits.h diff --git a/README.md b/README.md index c91e0a3..3badba5 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Adding support for new architectures is easy, but you need to know assembly lang | mips64 | ✓ | | | | ppc | ✓ | ✓ | | | ppc64 | ✓ | ✓ | | -| riscv64 | ✓ | | | +| riscv64 | ✓ | | ✓ | | s390x | ✓ | | ✓ | | x86 | ✓ | | ✓ | | x86_64 | ✓ | | ✓ | diff --git a/arch/riscv64/freestanding/bits.h b/arch/riscv64/freestanding/bits.h new file mode 100644 index 0000000..8d78676 --- /dev/null +++ b/arch/riscv64/freestanding/bits.h @@ -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 diff --git a/arch/riscv64/makecontext.c b/arch/riscv64/makecontext.c index 19d09ed..23d054b 100644 --- a/arch/riscv64/makecontext.c +++ b/arch/riscv64/makecontext.c @@ -23,7 +23,7 @@ extern void libucontext_trampoline(void); void -libucontext_makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) +libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...) { libucontext_greg_t *sp, *regp; va_list va;