From 2532407a7e0c3b7041c755e847bb0d1b990dda00 Mon Sep 17 00:00:00 2001 From: nroskill Date: Wed, 8 Jun 2022 20:03:32 +0800 Subject: [PATCH] fix coredump in sw --- deps/oblib/src/lib/CMakeLists.txt | 4 +- .../context/asm/jump_sw_64_aapcs_elf_gas.S | 88 +++++++++ .../context/asm/jump_sw_64_sysv_elf_gas.S | 172 ------------------ .../context/asm/make_sw_64_aapcs_elf_gas.S | 39 ++++ .../context/asm/make_sw_64_sysv_elf_gas.S | 93 ---------- .../context/asm/ontop_sw_64_aapcs_elf_gas.S | 10 +- 6 files changed, 134 insertions(+), 272 deletions(-) create mode 100644 deps/oblib/src/lib/coro/context/asm/jump_sw_64_aapcs_elf_gas.S delete mode 100644 deps/oblib/src/lib/coro/context/asm/jump_sw_64_sysv_elf_gas.S create mode 100644 deps/oblib/src/lib/coro/context/asm/make_sw_64_aapcs_elf_gas.S delete mode 100644 deps/oblib/src/lib/coro/context/asm/make_sw_64_sysv_elf_gas.S diff --git a/deps/oblib/src/lib/CMakeLists.txt b/deps/oblib/src/lib/CMakeLists.txt index fb8abd0a65..82420dc7b3 100644 --- a/deps/oblib/src/lib/CMakeLists.txt +++ b/deps/oblib/src/lib/CMakeLists.txt @@ -23,8 +23,8 @@ ob_lib_add_target(oblib_lib_coro_context coro/context/asm/jump_x86_64_sysv_elf_gas.S coro/context/asm/make_x86_64_sysv_elf_gas.S coro/context/asm/ontop_x86_64_sysv_elf_gas.S - coro/context/asm/make_sw_64_sysv_elf_gas.S - coro/context/asm/jump_sw_64_sysv_elf_gas.S + coro/context/asm/make_sw_64_aapcs_elf_gas.S + coro/context/asm/jump_sw_64_aapcs_elf_gas.S coro/context/asm/ontop_sw_64_aapcs_elf_gas.S coro/context/asm/jump_loongarch64_sysv_elf_gas.S coro/context/asm/make_loongarch64_sysv_elf_gas.S diff --git a/deps/oblib/src/lib/coro/context/asm/jump_sw_64_aapcs_elf_gas.S b/deps/oblib/src/lib/coro/context/asm/jump_sw_64_aapcs_elf_gas.S new file mode 100644 index 0000000000..97b8e196c8 --- /dev/null +++ b/deps/oblib/src/lib/coro/context/asm/jump_sw_64_aapcs_elf_gas.S @@ -0,0 +1,88 @@ +#if defined(__sw_64__) +.text +.align 2 +.global jump_fcontext +.type jump_fcontext, %function +jump_fcontext: + # prepare stack for GP + FPU + #ldih $29,0($27) + #ldi $29,0($29) + subl $sp, 0x98, $sp + + # save $f2-$f9 + fstd $f2, 0x00($sp) + fstd $f3, 0x08($sp) + fstd $f4, 0x10($sp) + fstd $f5, 0x18($sp) + fstd $f6, 0x20($sp) + fstd $f7, 0x28($sp) + fstd $f8, 0x30($sp) + fstd $f9, 0x38($sp) + + # save $9-$15, fp,$26 + stl $9, 0x40($sp) + stl $10, 0x48($sp) + stl $11, 0x50($sp) + stl $12, 0x58($sp) + stl $13, 0x60($sp) + stl $14, 0x68($sp) + stl $15, 0x70($sp) + stl $fp, 0x78($sp) + stl $16, 0x80($sp) #save jump_fcontext return address + stl $26, 0x88($sp) + + # save LR as PC + stl $26, 0x90($sp) + + # store RSP (pointing to context-data) in $16 + mov $sp, $20 + + + # restore RSP (pointing to context-data) from $17 + mov $17, $sp + + # load $f2-$f9 + fldd $f2, 0x00($sp) + fldd $f3, 0x08($sp) + fldd $f4, 0x10($sp) + fldd $f5, 0x18($sp) + fldd $f6, 0x20($sp) + fldd $f7, 0x28($sp) + fldd $f8, 0x30($sp) + fldd $f9, 0x38($sp) + + # load $9-$15, fp,$26 + ldl $9, 0x40($sp) + ldl $10, 0x48($sp) + ldl $11, 0x50($sp) + ldl $12, 0x58($sp) + ldl $13, 0x60($sp) + ldl $14, 0x68($sp) + ldl $15, 0x70($sp) + ldl $fp, 0x78($sp) + ldl $26, 0x88($sp) + + # pass transfer_t as first arg in context function + # to store $1,$2 to $16 address + ldl $16, 0x80($sp) #load $16, store return struct do return address + stl $20,0($16) + stl $18,8($16) + + # pass transfer_t as first arg in context function,such as f1,f2,f3 + # $16 == FCTX, $17 == DATA + mov $20,$16 #$16 $17 as first and second arg + mov $18,$17 + + + # load pc + ldl $27, 0x90($sp) + + + # restore stack from GP + FPU + addl $sp, 0x98, $sp + + ret $31,($27),0x1 //jmp $31, ($27) //ret ($27) +.size jump_fcontext,.-jump_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits +#endif \ No newline at end of file diff --git a/deps/oblib/src/lib/coro/context/asm/jump_sw_64_sysv_elf_gas.S b/deps/oblib/src/lib/coro/context/asm/jump_sw_64_sysv_elf_gas.S deleted file mode 100644 index 9f6a61549b..0000000000 --- a/deps/oblib/src/lib/coro/context/asm/jump_sw_64_sysv_elf_gas.S +++ /dev/null @@ -1,172 +0,0 @@ -#if defined(__sw_64__) -/* - Copyright Edward Nevill 2015 - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE_1_0.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ -/******************************************************* - * * - * ------------------------------------------------- * - * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * - * ------------------------------------------------- * - * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * - * ------------------------------------------------- * - * | d8 | d9 | d10 | d11 | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * - * ------------------------------------------------- * - * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * - * ------------------------------------------------- * - * | d12 | d13 | d14 | d15 | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * - * ------------------------------------------------- * - * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * - * ------------------------------------------------- * - * | x19 | x20 | x21 | x22 | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * - * ------------------------------------------------- * - * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * - * ------------------------------------------------- * - * | x23 | x24 | x25 | x26 | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * - * ------------------------------------------------- * - * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * - * ------------------------------------------------- * - * | x27 | x28 | FP | LR | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 40 | 41 | 42 | 43 | | | * - * ------------------------------------------------- * - * | 0xa0| 0xa4| 0xa8| 0xac| | | * - * ------------------------------------------------- * - * | PC | align | | | * - * ------------------------------------------------- * - * * - *******************************************************/ - -#.cpu generic+fp+simd -.text -.align 2 -.global jump_fcontext -.type jump_fcontext, %function -jump_fcontext: - # prepare stack for GP + FPU -# sub sp, sp, #0xb0 - ldih $29,0($27) !gpdisp!1 - ldi $29,0($29) !gpdisp!1 - subl $30, 0x98, $30 -# Because gcc may save integer registers in fp registers across a -# function call we cannot skip saving the fp registers. -# -# Do not reinstate this test unless you fully understand what you -# are doing. -# -# # test if fpu env should be preserved -# cmp w3, #0 -# b.eq 1f - - # save d8 - d15 -# stp d8, d9, [sp, #0x00] -# stp d10, d11, [sp, #0x10] -# stp d12, d13, [sp, #0x20] -# stp d14, d15, [sp, #0x30] - fstd $f2,0x00($30) - fstd $f3,0x08($30) - fstd $f3,0x10($30) - fstd $f4,0x18($30) - fstd $f5,0x20($30) - fstd $f6,0x28($30) - fstd $f7,0x30($30) - fstd $f8,0x38($30) - fstd $f9,0x40($30) -1: - # save x19-x30 -# stp x19, x20, [sp, #0x40] -# stp x21, x22, [sp, #0x50] -# stp x23, x24, [sp, #0x60] -# stp x25, x26, [sp, #0x70] -# stp x27, x28, [sp, #0x80] -# stp x29, x30, [sp, #0x90] - stl $9, 0x48($30) - stl $10, 0x50($30) - stl $11, 0x58($30) - stl $12, 0x60($30) - stl $13, 0x68($30) - stl $14, 0x70($30) - stl $15, 0x90($30) - # save LR as PC -# str x30, [sp, #0xa0] - stl $26, 0x80($30) - stl $26, 0x88($30) - # store RSP (pointing to context-data) in first argument (x0). - # STR cannot have sp as a target register -# mov x4, sp - mov $30,$1 -# str x4, [x0] - stl $1,0x00($16) - # restore RSP (pointing to context-data) from A2 (x1) -# mov sp, x1 - mov $17,$30 -# # test if fpu env should be preserved -# cmp w3, #0 -# b.eq 2f - - # load d8 - d15 -# ldp d8, d9, [sp, #0x00] -# ldp d10, d11, [sp, #0x10] -# ldp d12, d13, [sp, #0x20] -# ldp d14, d15, [sp, #0x30] - fldd $f2,0x00($30) - fldd $f3,0x08($30) - fldd $f3,0x10($30) - fldd $f4,0x18($30) - fldd $f5,0x20($30) - fldd $f6,0x28($30) - fldd $f7,0x30($30) - fldd $f8,0x38($30) - fldd $f9,0x40($30) -2: - # load x19-x30 -# ldp x19, x20, [sp, #0x40] -# ldp x21, x22, [sp, #0x50] -# ldp x23, x24, [sp, #0x60] -# ldp x25, x26, [sp, #0x70] -# ldp x27, x28, [sp, #0x80] -# ldp x29, x30, [sp, #0x90] - ldl $9, 0x48($30) - ldl $10, 0x50($30) - ldl $11, 0x58($30) - ldl $12, 0x60($30) - ldl $13, 0x68($30) - ldl $14, 0x70($30) - ldl $26, 0x80($30) - ldl $15, 0x90($30) - # use third arg as return value after jump - # and as first arg in context function -# mov x0, x2 - mov $18,$16 - mov $18,$0 - # load pc -# ldr x4, [sp, #0xa0] - ldl $27,0x88($30) -# ldl $26,0x88($30) - # restore stack from GP + FPU -# add sp, sp, #0xb0 - #mov $1,$30 - addl $30, 0x98, $30 -# addl $30,32,$30 -# ret x4 -# mov $1,$26 - ret $31,($27),1 -.size jump_fcontext,.-jump_fcontext -# Mark that we don't need executable stack. -.section .note.GNU-stack,"",%progbits -#endif diff --git a/deps/oblib/src/lib/coro/context/asm/make_sw_64_aapcs_elf_gas.S b/deps/oblib/src/lib/coro/context/asm/make_sw_64_aapcs_elf_gas.S new file mode 100644 index 0000000000..1be7ed8c2a --- /dev/null +++ b/deps/oblib/src/lib/coro/context/asm/make_sw_64_aapcs_elf_gas.S @@ -0,0 +1,39 @@ +#if defined(__sw_64__) +.text +.align 2 +.global make_fcontext +.type make_fcontext, %function +make_fcontext: + #ldih $29,0($27) + #ldi $29,0($29) + # shift address in $16 (allocated stack) to lower 16 byte boundary + bic $16, 0xf,$16 + + # reserve space for context-data on context-stack + subl $16, 0x98,$16 + + # third arg of make_fcontext() == address of context-function + # store address as a PC to jump in + stl $18, 0x90($16) + + # save address of finish as return-address for context-function + # will be entered after context-function returns (LR register) + ldi $17, finish + stl $17, 0x88($16) + + stl $16, 0x80($16) + + mov $16, $0 + + ret $31,($26),1 //jump ($26) // return pointer to context-data ($16) + +finish: + # exit code is zero + mov 0, $0 + # exit application + call _exit #ldi $27,_exit #jmp ($27) + +.size make_fcontext,.-make_fcontext +# Mark that we don't need executable stack. +.section .note.GNU-stack,"",%progbits +#endif \ No newline at end of file diff --git a/deps/oblib/src/lib/coro/context/asm/make_sw_64_sysv_elf_gas.S b/deps/oblib/src/lib/coro/context/asm/make_sw_64_sysv_elf_gas.S deleted file mode 100644 index 4d571daffa..0000000000 --- a/deps/oblib/src/lib/coro/context/asm/make_sw_64_sysv_elf_gas.S +++ /dev/null @@ -1,93 +0,0 @@ -#if defined(__sw_64__) -/* - Copyright Edward Nevill 2015 - Distributed under the Boost Software License, Version 1.0. - (See accompanying file LICENSE_1_0.txt or copy at - http://www.boost.org/LICENSE_1_0.txt) -*/ -/******************************************************* - * * - * ------------------------------------------------- * - * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * - * ------------------------------------------------- * - * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| * - * ------------------------------------------------- * - * | d8 | d9 | d10 | d11 | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * - * ------------------------------------------------- * - * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| * - * ------------------------------------------------- * - * | d12 | d13 | d14 | d15 | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * - * ------------------------------------------------- * - * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| * - * ------------------------------------------------- * - * | x19 | x20 | x21 | x22 | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * - * ------------------------------------------------- * - * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| * - * ------------------------------------------------- * - * | x23 | x24 | x25 | x26 | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * - * ------------------------------------------------- * - * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| * - * ------------------------------------------------- * - * | x27 | x28 | FP | LR | * - * ------------------------------------------------- * - * ------------------------------------------------- * - * | 40 | 41 | 42 | 43 | | | * - * ------------------------------------------------- * - * | 0xa0| 0xa4| 0xa8| 0xac| | | * - * ------------------------------------------------- * - * | PC | align | | | * - * ------------------------------------------------- * - * * - *******************************************************/ - -#.cpu generic+fp+simd -.text -.align 2 -.global make_fcontext -.type make_fcontext, %function -make_fcontext: - ldih $29,0($27) !gpdisp!1 - ldi $29,0($29) !gpdisp!1 - # shift address in x0 (allocated stack) to lower 16 byte boundary -# and $16, ~0xf, $16 - srl $16,4,$16 - sll $16,4,$16 - # reserve space for context-data on context-stack - subl $16, 0x90,$16 - - # third arg of make_fcontext() == address of context-function - # store address as a PC to jump in -# stl x2, [x0, #0xa0] - stl $18, 0x88($16) - # save address of finish as return-address for context-function - # will be entered after context-function returns (LR register) -# adr x1, finish - ldi $17,finish -# str x1, [x0, #0x98] - stl $17,0x80($16) -# ret x30 // return pointer to context-data (x0) - mov $16,$0 - ret $31,($26),1 -finish: - # exit code is zero -# mov 0,$16 - mov 0,$0 - # exit application - call _exit - -.size make_fcontext,.-make_fcontext -# Mark that we don't need executable stack. -.section .note.GNU-stack,"",%progbits -#endif diff --git a/deps/oblib/src/lib/coro/context/asm/ontop_sw_64_aapcs_elf_gas.S b/deps/oblib/src/lib/coro/context/asm/ontop_sw_64_aapcs_elf_gas.S index 711f556f9b..282030b64e 100644 --- a/deps/oblib/src/lib/coro/context/asm/ontop_sw_64_aapcs_elf_gas.S +++ b/deps/oblib/src/lib/coro/context/asm/ontop_sw_64_aapcs_elf_gas.S @@ -70,13 +70,13 @@ ontop_fcontext: # pass transfer_t as first arg in context function,such as f1,f2,f3 # $16 == FCTX, $17 == DATA - mov $20,$16 #$16 $17 $18 as first and second arg + mov $20,$16 #$16 $17 $18 as first and second arg mov $18,$17 - - + + # skip pc mov $19, $27 - + # restore stack from GP + FPU addl $sp, 0x98, $sp @@ -85,4 +85,4 @@ ontop_fcontext: .size ontop_fcontext,.-ontop_fcontext # Mark that we don't need executable stack. .section .note.GNU-stack,"",%progbits -#endif +#endif \ No newline at end of file -- GitLab