Adding the LoongArch CPU support for libcontext
This commit is contained in:
parent
cf6acae791
commit
b7ab5330bf
|
@ -791,6 +791,111 @@ __asm (
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LIBCONTEXT_PLATFORM_linux_loong64) && defined(LIBCONTEXT_COMPILER_gcc)
|
||||||
|
__asm (
|
||||||
|
".text\n"
|
||||||
|
".align 2\n"
|
||||||
|
".global jump_fcontext\n"
|
||||||
|
".type jump_fcontext,@function\n"
|
||||||
|
"jump_fcontext:\n"
|
||||||
|
" # reserve space on stack\n"
|
||||||
|
" addi.d $sp, $sp, -176\n"
|
||||||
|
" # save fs0-fs7\n"
|
||||||
|
" fst.d $fs0, $sp, 0\n"
|
||||||
|
" fst.d $fs1, $sp, 8\n"
|
||||||
|
" fst.d $fs2, $sp, 16\n"
|
||||||
|
" fst.d $fs3, $sp, 24\n"
|
||||||
|
" fst.d $fs4, $sp, 32\n"
|
||||||
|
" fst.d $fs5, $sp, 40\n"
|
||||||
|
" fst.d $fs6, $sp, 48\n"
|
||||||
|
" fst.d $fs7, $sp, 56\n"
|
||||||
|
" # save s0-s8\n"
|
||||||
|
" st.d $s0, $sp, 64\n"
|
||||||
|
" st.d $s1, $sp, 72\n"
|
||||||
|
" st.d $s2, $sp, 80\n"
|
||||||
|
" st.d $s3, $sp, 88\n"
|
||||||
|
" st.d $s4, $sp, 96\n"
|
||||||
|
" st.d $s5, $sp, 104\n"
|
||||||
|
" st.d $s6, $sp, 112\n"
|
||||||
|
" st.d $s7, $sp, 120\n"
|
||||||
|
" st.d $s8, $sp, 128\n"
|
||||||
|
" # save fp and ra\n"
|
||||||
|
" st.d $fp, $sp, 136\n"
|
||||||
|
" st.d $ra, $sp, 144\n"
|
||||||
|
" # save ra as pc\n"
|
||||||
|
" st.d $ra, $sp, 152\n"
|
||||||
|
" # store SP (pointing to old context-data) in pointer a0(first arg)\n"
|
||||||
|
" st.d $sp, $a0, 0\n"
|
||||||
|
" # get SP (pointing to new context-data) from a1 param\n"
|
||||||
|
" move $sp, $a1\n"
|
||||||
|
" # restore fs0-fs7\n"
|
||||||
|
" fld.d $fs0, $sp, 0\n"
|
||||||
|
" fld.d $fs1, $sp, 8\n"
|
||||||
|
" fld.d $fs2, $sp, 16\n"
|
||||||
|
" fld.d $fs3, $sp, 24\n"
|
||||||
|
" fld.d $fs4, $sp, 32\n"
|
||||||
|
" fld.d $fs5, $sp, 40\n"
|
||||||
|
" fld.d $fs6, $sp, 48\n"
|
||||||
|
" fld.d $fs7, $sp, 56\n"
|
||||||
|
" # restore s0-s8\n"
|
||||||
|
" ld.d $s0, $sp, 64\n"
|
||||||
|
" ld.d $s1, $sp, 72\n"
|
||||||
|
" ld.d $s2, $sp, 80\n"
|
||||||
|
" ld.d $s3, $sp, 88\n"
|
||||||
|
" ld.d $s4, $sp, 96\n"
|
||||||
|
" ld.d $s5, $sp, 104\n"
|
||||||
|
" ld.d $s6, $sp, 112\n"
|
||||||
|
" ld.d $s7, $sp, 120\n"
|
||||||
|
" ld.d $s8, $sp, 128\n"
|
||||||
|
" # restore fp and ra\n"
|
||||||
|
" ld.d $fp, $sp, 136\n"
|
||||||
|
" ld.d $ra, $sp, 144\n"
|
||||||
|
" # load pc\n"
|
||||||
|
" ld.d $t0, $sp, 152\n"
|
||||||
|
" st.d $a2, $sp, 160\n"
|
||||||
|
" # adjust stack\n"
|
||||||
|
" addi.d $sp, $sp, 176\n"
|
||||||
|
" # move *data from a2 to a0 as param\n"
|
||||||
|
" move $a0, $a2\n"
|
||||||
|
" # move *data from a2 to v0 as return\n"
|
||||||
|
" move $v0, $a2\n"
|
||||||
|
" # jump to context\n"
|
||||||
|
" jr $t0\n"
|
||||||
|
".size jump_fcontext, .-jump_fcontext\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(LIBCONTEXT_PLATFORM_linux_loong64) && defined(LIBCONTEXT_COMPILER_gcc)
|
||||||
|
__asm (
|
||||||
|
".text\n"
|
||||||
|
".align 2\n"
|
||||||
|
".global make_fcontext\n"
|
||||||
|
".type make_fcontext,@function\n"
|
||||||
|
"make_fcontext:\n"
|
||||||
|
" # shift address in $a0 (allocated stack) to lower 16 byte boundary\n"
|
||||||
|
" addi.d $v1, $zero, -16\n"
|
||||||
|
" and $v0, $v1, $a0\n"
|
||||||
|
" # reserve space for context-data on context-stack\n"
|
||||||
|
" addi.d $v0, $v0, -176\n"
|
||||||
|
" # third arg of make_fontext() == address of context-function\n"
|
||||||
|
" st.d $a2, $v0, 152\n"
|
||||||
|
" # save address of finish as return-address for context-function\n"
|
||||||
|
" # will be entered after context-function returns (LR register)\n"
|
||||||
|
" la.local $t0, finish\n"
|
||||||
|
" st.d $t0, $v0, 0x0090\n"
|
||||||
|
" # return pointer to context-data\n"
|
||||||
|
" jr $ra\n"
|
||||||
|
"finish:\n"
|
||||||
|
" # exit code is zero\n"
|
||||||
|
" ext.w.h $a0, $zero\n"
|
||||||
|
" # exit application\n"
|
||||||
|
" bl _exit\n"
|
||||||
|
".size make_fcontext, .-make_fcontext\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(LIBCONTEXT_PLATFORM_linux_mips_n64) && defined(LIBCONTEXT_COMPILER_gcc)
|
#if defined(LIBCONTEXT_PLATFORM_linux_mips_n64) && defined(LIBCONTEXT_COMPILER_gcc)
|
||||||
__asm (
|
__asm (
|
||||||
".text\n"
|
".text\n"
|
||||||
|
|
|
@ -41,6 +41,9 @@
|
||||||
#elif __aarch64__
|
#elif __aarch64__
|
||||||
#define LIBCONTEXT_PLATFORM_linux_arm64
|
#define LIBCONTEXT_PLATFORM_linux_arm64
|
||||||
#define LIBCONTEXT_CALL_CONVENTION
|
#define LIBCONTEXT_CALL_CONVENTION
|
||||||
|
#elif (__loongarch__ && _LOONGARCH_SIM == _ABILP64)
|
||||||
|
#define LIBCONTEXT_PLATFORM_linux_loong64
|
||||||
|
#define LIBCONTEXT_CALL_CONVENTION
|
||||||
#elif (__mips__ && _MIPS_SIM == _ABI64)
|
#elif (__mips__ && _MIPS_SIM == _ABI64)
|
||||||
#define LIBCONTEXT_PLATFORM_linux_mips_n64
|
#define LIBCONTEXT_PLATFORM_linux_mips_n64
|
||||||
#define LIBCONTEXT_CALL_CONVENTION
|
#define LIBCONTEXT_CALL_CONVENTION
|
||||||
|
|
Loading…
Reference in New Issue