support mac arm & windows compiler

This commit is contained in:
jarodruan 2021-10-13 19:25:36 +08:00 committed by ruanshudong
parent 2cc9ecc0e4
commit e7a77deb45
22 changed files with 439 additions and 405 deletions

View File

@ -209,7 +209,7 @@ if (TARS_SSL)
set(LIB_CRYPTO "libcrypto")
ExternalProject_Add(ADD_${LIB_SSL}
URL http://cdn.tarsyun.com/src/openssl-1.1.1d.tar.gz
URL http://cdn.tarsyun.com/src/openssl-1.1.1l.tar.gz
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
@ -218,14 +218,14 @@ if (TARS_SSL)
BUILD_IN_SOURCE 1
BUILD_COMMAND nmake
INSTALL_COMMAND nmake install
URL_MD5 3be209000dbc7e1b95bcdf47980a3baa
URL_MD5 ac0d4387f3ba0ad741b0580dd45f6ff3
)
else ()
set(LIB_SSL "ssl")
set(LIB_CRYPTO "crypto")
ExternalProject_Add(ADD_${LIB_SSL}
URL http://cdn.tarsyun.com/src/openssl-1.1.1d.tar.gz
URL http://cdn.tarsyun.com/src/openssl-1.1.1l.tar.gz
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download
PREFIX ${CMAKE_BINARY_DIR}
INSTALL_DIR ${CMAKE_SOURCE_DIR}
@ -233,7 +233,7 @@ if (TARS_SSL)
SOURCE_DIR ${CMAKE_BINARY_DIR}/src/openssl-lib
BUILD_IN_SOURCE 1
BUILD_COMMAND make
URL_MD5 3be209000dbc7e1b95bcdf47980a3baa
URL_MD5 ac0d4387f3ba0ad741b0580dd45f6ff3
)
endif ()

@ -1 +1 @@
Subproject commit 0ba68259c4ab0e2cf712fce26cc78f317c02965a
Subproject commit 39c6f87733710a28eb5e57e42558c7e016d84eba

View File

@ -28,7 +28,8 @@
#include "servant/Current.h"
#include "servant/EndpointInfo.h"
#include <tuple>
#include <cmath>
#include <algorithm>
namespace tars
{
@ -320,7 +321,7 @@ public:
}
if (flags.size() >= 2)
{
maxLen = std::max(maxLen, TC_Common::strto<unsigned int>(flags[1]));
maxLen = max(maxLen, TC_Common::strto<unsigned int>(flags[1]));
}
// type = strtol(tid.substr(0, pos).c_str(), NULL, 16);

View File

@ -1,4 +1,4 @@
/**
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.

View File

@ -43,6 +43,7 @@
.globl jump_fcontext
.align 2
.type jump_fcontext,%function
.syntax unified
jump_fcontext:
@ save LR as PC
push {lr}

View File

@ -15,6 +15,10 @@
#include "jump_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "jump_ppc64_sysv_macho_gas.S"
#elif defined(__arm__)
#include "jump_arm_aapcs_macho_gas.S"
#elif defined(__arm64__)
#include "jump_arm64_aapcs_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -26,6 +26,12 @@
.file "jump_i386_ms_pe_gas.asm"
.text
.p2align 4,,15
/* mark as using no unregistered SEH handlers */
.globl @feat.00
.def @feat.00; .scl 3; .type 0; .endef
.set @feat.00, 1
.globl _jump_fcontext
.def _jump_fcontext; .scl 2; .type 32; .endef
_jump_fcontext:

View File

@ -54,9 +54,8 @@ _jump_fcontext:
/* return parent fcontext_t */
movl %ecx, %eax
/* returned data is stored in EDX */
movl %edx, 0x4(%eax)
/* returned data is stored in EDX */
movl 0x18(%esp), %ecx /* restore EIP */
#if !defined(BOOST_USE_TSX)

View File

@ -5,71 +5,48 @@
http://www.boost.org/LICENSE_1_0.txt)
*/
/******************************************************
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* |bchai|hiddn| fpscr | PC | CR | R14 | R15 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | R13 | R14 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | | *
* ------------------------------------------------- *
* | 256 | | *
* ------------------------------------------------- *
* | DATA| | *
* ------------------------------------------------- *
* ------------------------|------------ *
* | 224 | 228 | 232 | 236 | 240 | 244 | *
* ------------------------|------------ *
* | F30 | F31 |bchai| LR | *
* ------------------------|------------ *
* *
*******************************************************/
@ -79,125 +56,142 @@
.align 2
.type jump_fcontext,@function
jump_fcontext:
# reserve space on stack
subi %r1, %r1, 244
# Linux: jump_fcontext( hidden transfer_t * R3, R4, R5)
# Other: transfer_t R3:R4 = jump_fcontext( R3, R4)
stfd %f14, 0(%r1) # save F14
stfd %f15, 8(%r1) # save F15
stfd %f16, 16(%r1) # save F16
stfd %f17, 24(%r1) # save F17
stfd %f18, 32(%r1) # save F18
stfd %f19, 40(%r1) # save F19
stfd %f20, 48(%r1) # save F20
stfd %f21, 56(%r1) # save F21
stfd %f22, 64(%r1) # save F22
stfd %f23, 72(%r1) # save F23
stfd %f24, 80(%r1) # save F24
stfd %f25, 88(%r1) # save F25
stfd %f26, 96(%r1) # save F26
stfd %f27, 104(%r1) # save F27
stfd %f28, 112(%r1) # save F28
stfd %f29, 120(%r1) # save F29
stfd %f30, 128(%r1) # save F30
stfd %f31, 136(%r1) # save F31
mffs %f0 # load FPSCR
stfd %f0, 144(%r1) # save FPSCR
mflr %r0 # return address from LR
mffs %f0 # FPSCR
mfcr %r8 # condition register
stw %r13, 152(%r1) # save R13
stw %r14, 156(%r1) # save R14
stw %r15, 160(%r1) # save R15
stw %r16, 164(%r1) # save R16
stw %r17, 168(%r1) # save R17
stw %r18, 172(%r1) # save R18
stw %r19, 176(%r1) # save R19
stw %r20, 180(%r1) # save R20
stw %r21, 184(%r1) # save R21
stw %r22, 188(%r1) # save R22
stw %r23, 192(%r1) # save R23
stw %r24, 196(%r1) # save R24
stw %r25, 200(%r1) # save R25
stw %r26, 204(%r1) # save R26
stw %r27, 208(%r1) # save R27
stw %r28, 212(%r1) # save R28
stw %r29, 216(%r1) # save R29
stw %r30, 220(%r1) # save R30
stw %r31, 224(%r1) # save R31
stw %r3, 228(%r1) # save hidden
stwu %r1, -240(%r1) # allocate stack space, R1 % 16 == 0
stw %r0, 244(%r1) # save LR in caller's frame
# save CR
mfcr %r0
stw %r0, 232(%r1)
# save LR
mflr %r0
stw %r0, 236(%r1)
# save LR as PC
stw %r0, 240(%r1)
#ifdef __linux__
stw %r3, 4(%r1) # hidden pointer
#endif
# store RSP (pointing to context-data) in R6
mr %r6, %r1
stfd %f0, 8(%r1) # FPSCR
stw %r0, 16(%r1) # LR as PC
stw %r8, 20(%r1) # CR
# restore RSP (pointing to context-data) from R4
mr %r1, %r4
# Save registers R14 to R31.
# Don't change R2, the thread-local storage pointer.
# Don't change R13, the small data pointer.
stw %r14, 24(%r1)
stw %r15, 28(%r1)
stw %r16, 32(%r1)
stw %r17, 36(%r1)
stw %r18, 40(%r1)
stw %r19, 44(%r1)
stw %r20, 48(%r1)
stw %r21, 52(%r1)
stw %r22, 56(%r1)
stw %r23, 60(%r1)
stw %r24, 64(%r1)
stw %r25, 68(%r1)
stw %r26, 72(%r1)
stw %r27, 76(%r1)
stw %r28, 80(%r1)
stw %r29, 84(%r1)
stw %r30, 88(%r1)
stw %r31, 92(%r1)
lfd %f14, 0(%r1) # restore F14
lfd %f15, 8(%r1) # restore F15
lfd %f16, 16(%r1) # restore F16
lfd %f17, 24(%r1) # restore F17
lfd %f18, 32(%r1) # restore F18
lfd %f19, 40(%r1) # restore F19
lfd %f20, 48(%r1) # restore F20
lfd %f21, 56(%r1) # restore F21
lfd %f22, 64(%r1) # restore F22
lfd %f23, 72(%r1) # restore F23
lfd %f24, 80(%r1) # restore F24
lfd %f25, 88(%r1) # restore F25
lfd %f26, 96(%r1) # restore F26
lfd %f27, 104(%r1) # restore F27
lfd %f28, 112(%r1) # restore F28
lfd %f29, 120(%r1) # restore F29
lfd %f30, 128(%r1) # restore F30
lfd %f31, 136(%r1) # restore F31
lfd %f0, 144(%r1) # load FPSCR
mtfsf 0xff, %f0 # restore FPSCR
# Save registers F14 to F31 in slots with 8-byte alignment.
# 4-byte alignment may stall the pipeline of some processors.
# Less than 4 may cause alignment traps.
stfd %f14, 96(%r1)
stfd %f15, 104(%r1)
stfd %f16, 112(%r1)
stfd %f17, 120(%r1)
stfd %f18, 128(%r1)
stfd %f19, 136(%r1)
stfd %f20, 144(%r1)
stfd %f21, 152(%r1)
stfd %f22, 160(%r1)
stfd %f23, 168(%r1)
stfd %f24, 176(%r1)
stfd %f25, 184(%r1)
stfd %f26, 192(%r1)
stfd %f27, 200(%r1)
stfd %f28, 208(%r1)
stfd %f29, 216(%r1)
stfd %f30, 224(%r1)
stfd %f31, 232(%r1)
lwz %r13, 152(%r1) # restore R13
lwz %r14, 156(%r1) # restore R14
lwz %r15, 160(%r1) # restore R15
lwz %r16, 164(%r1) # restore R16
lwz %r17, 168(%r1) # restore R17
lwz %r18, 172(%r1) # restore R18
lwz %r19, 176(%r1) # restore R19
lwz %r20, 180(%r1) # restore R20
lwz %r21, 184(%r1) # restore R21
lwz %r22, 188(%r1) # restore R22
lwz %r23, 192(%r1) # restore R23
lwz %r24, 196(%r1) # restore R24
lwz %r25, 200(%r1) # restore R25
lwz %r26, 204(%r1) # restore R26
lwz %r27, 208(%r1) # restore R27
lwz %r28, 212(%r1) # restore R28
lwz %r29, 216(%r1) # restore R29
lwz %r30, 220(%r1) # restore R30
lwz %r31, 224(%r1) # restore R31
lwz %r3, 228(%r1) # restore hidden
# store RSP (pointing to context-data) in R7/R6
# restore RSP (pointing to context-data) from R4/R3
#ifdef __linux__
mr %r7, %r1
mr %r1, %r4
lwz %r3, 4(%r1) # hidden pointer
#else
mr %r6, %r1
mr %r1, %r3
#endif
# restore CR
lwz %r0, 232(%r1)
mtcr %r0
# restore LR
lwz %r0, 236(%r1)
lfd %f0, 8(%r1) # FPSCR
lwz %r0, 16(%r1) # PC
lwz %r8, 20(%r1) # CR
mtfsf 0xff, %f0 # restore FPSCR
mtctr %r0 # load CTR with PC
mtcr %r8 # restore CR
# restore R14 to R31
lwz %r14, 24(%r1)
lwz %r15, 28(%r1)
lwz %r16, 32(%r1)
lwz %r17, 36(%r1)
lwz %r18, 40(%r1)
lwz %r19, 44(%r1)
lwz %r20, 48(%r1)
lwz %r21, 52(%r1)
lwz %r22, 56(%r1)
lwz %r23, 60(%r1)
lwz %r24, 64(%r1)
lwz %r25, 68(%r1)
lwz %r26, 72(%r1)
lwz %r27, 76(%r1)
lwz %r28, 80(%r1)
lwz %r29, 84(%r1)
lwz %r30, 88(%r1)
lwz %r31, 92(%r1)
# restore F14 to F31
lfd %f14, 96(%r1)
lfd %f15, 104(%r1)
lfd %f16, 112(%r1)
lfd %f17, 120(%r1)
lfd %f18, 128(%r1)
lfd %f19, 136(%r1)
lfd %f20, 144(%r1)
lfd %f21, 152(%r1)
lfd %f22, 160(%r1)
lfd %f23, 168(%r1)
lfd %f24, 176(%r1)
lfd %f25, 184(%r1)
lfd %f26, 192(%r1)
lfd %f27, 200(%r1)
lfd %f28, 208(%r1)
lfd %f29, 216(%r1)
lfd %f30, 224(%r1)
lfd %f31, 232(%r1)
# restore LR from caller's frame
lwz %r0, 244(%r1)
mtlr %r0
# load PC
lwz %r0, 240(%r1)
# restore CTR
mtctr %r0
# adjust stack
addi %r1, %r1, 244
addi %r1, %r1, 240
# return transfer_t
stw %r6, 0(%r3)
# return transfer_t
#ifdef __linux__
stw %r7, 0(%r3)
stw %r5, 4(%r3)
#else
mr %r3, %r6
# %r4, %r4
#endif
# jump to context
bctr

View File

@ -67,10 +67,20 @@ jump_fcontext:
leaq 0x40(%rsp), %rsp /* prepare stack */
/* return transfer_t from jump */
#if !defined(_ILP32)
/* RAX == fctx, RDX == data */
movq %rsi, %rdx
#else
/* RAX == data:fctx */
salq $32, %rsi
orq %rsi, %rax
#endif
/* pass transfer_t as first arg in context function */
#if !defined(_ILP32)
/* RDI == fctx, RSI == data */
#else
/* RDI == data:fctx */
#endif
movq %rax, %rdi
/* indirect jump to context */

View File

@ -66,12 +66,7 @@ _make_fcontext:
; store address as a PC to jump in
str x2, [x0, #0xa0]
; compute abs address of label finish
; 0x0c = 3 instructions * size (4) before label 'finish'
; TODO: Numeric offset since llvm still does not support labels in ADR. Fix:
; http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140407/212336.html
adr x1, 0x0c
adr x1, finish
; save address of finish as return-address for context-function
; will be entered after context-function returns (LR register)

View File

@ -43,6 +43,7 @@
.globl make_fcontext
.align 2
.type make_fcontext,%function
.syntax unified
make_fcontext:
@ shift address in A1 to lower 16 byte boundary
bic a1, a1, #15

View File

@ -15,6 +15,10 @@
#include "make_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "make_ppc64_sysv_macho_gas.S"
#elif defined(__arm__)
#include "make_arm_aapcs_macho_gas.S"
#elif defined(__arm64__)
#include "make_arm64_aapcs_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -26,6 +26,12 @@
.file "make_i386_ms_pe_gas.asm"
.text
.p2align 4,,15
/* mark as using no unregistered SEH handlers */
.globl @feat.00
.def @feat.00; .scl 3; .type 0; .endef
.set @feat.00, 1
.globl _make_fcontext
.def _make_fcontext; .scl 2; .type 32; .endef
_make_fcontext:

View File

@ -5,71 +5,48 @@
http://www.boost.org/LICENSE_1_0.txt)
*/
/******************************************************
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* |bchai|hiddn| fpscr | PC | CR | R14 | R15 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | R13 | R14 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | | *
* ------------------------------------------------- *
* | 256 | | *
* ------------------------------------------------- *
* | DATA| | *
* ------------------------------------------------- *
* ------------------------|------------ *
* | 224 | 228 | 232 | 236 | 240 | 244 | *
* ------------------------|------------ *
* | F30 | F31 |bchai| LR | *
* ------------------------|------------ *
* *
*******************************************************/
@ -86,58 +63,84 @@ make_fcontext:
# shift address in R3 to lower 16 byte boundary
clrrwi %r3, %r3, 4
# reserve space for context-data on context-stack
# including 64 byte of linkage + parameter area (R1 % 16 == 0)
subi %r3, %r3, 336
# reserve space on context-stack, including 16 bytes of linkage
# and parameter area + 240 bytes of context-data (R1 % 16 == 0)
subi %r3, %r3, 16 + 240
# third arg of make_fcontext() == address of context-function
stw %r5, 240(%r3)
#ifdef __linux__
# save context-function as PC
stw %r5, 16(%r3)
#else
# save context-function for trampoline
stw %r5, 248(%r3)
#endif
# set back-chain to zero
li %r0, 0
stw %r0, 244(%r3)
stw %r0, 240(%r3)
mffs %f0 # load FPSCR
stfd %f0, 144(%r3) # save FPSCR
# copy FPSCR to new context
mffs %f0
stfd %f0, 8(%r3)
# compute address of returned transfer_t
addi %r0, %r3, 252
mr %r4, %r0
stw %r4, 228(%r3)
#ifdef __linux__
# set hidden pointer for returning transfer_t
la %r0, 248(%r3)
stw %r0, 4(%r3)
#endif
# load LR
mflr %r0
# jump to label 1
# load address of label 1 into R4
bl 1f
1:
# load LR into R4
mflr %r4
1: mflr %r4
#ifndef __linux__
# compute abs address of trampoline, use as PC
addi %r7, %r4, trampoline - 1b
stw %r7, 16(%r3)
#endif
# compute abs address of label finish
addi %r4, %r4, finish - 1b
# restore LR
mtlr %r0
# save address of finish as return-address for context-function
# will be entered after context-function returns
stw %r4, 236(%r3)
stw %r4, 244(%r3)
# restore return address from R6
mtlr %r6
blr # return pointer to context-data
finish:
# save return address into R0
mflr %r0
# save return address on stack, set up stack frame
stw %r0, 4(%r1)
# allocate stack space, R1 % 16 == 0
stwu %r1, -16(%r1)
#ifndef __linux__
trampoline:
# On systems other than Linux, jump_fcontext is returning the
# transfer_t in R3:R4, but we need to pass transfer_t * R3 to
# our context-function.
lwz %r0, 8(%r1) # address of context-function
mtctr %r0
stw %r3, 8(%r1)
stw %r4, 12(%r1)
la %r3, 8(%r1) # address of transfer_t
bctr
#endif
# exit code is zero
finish:
# Use the secure PLT for _exit(0). If we use the insecure BSS PLT
# here, then the linker may use the insecure BSS PLT even if the
# C++ compiler wanted the secure PLT.
# set R30 for secure PLT, large model
bl 2f
2: mflr %r30
addis %r30, %r30, .Ltoc - 2b@ha
addi %r30, %r30, .Ltoc - 2b@l
# call _exit(0) with special addend 0x8000 for large model
li %r3, 0
# exit application
bl _exit@plt
bl _exit + 0x8000@plt
.size make_fcontext, .-make_fcontext
/* Provide the GOT pointer for secure PLT, large model. */
.section .got2,"aw"
.Ltoc = . + 0x8000
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -43,6 +43,7 @@
.globl ontop_fcontext
.align 2
.type ontop_fcontext,%function
.syntax unified
ontop_fcontext:
@ save LR as PC
push {lr}

View File

@ -15,6 +15,10 @@
#include "ontop_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "ontop_ppc64_sysv_macho_gas.S"
#elif defined(__arm__)
#include "ontop_arm_aapcs_macho_gas.S"
#elif defined(__arm64__)
#include "ontop_arm64_aapcs_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -26,6 +26,12 @@
.file "ontop_i386_ms_pe_gas.asm"
.text
.p2align 4,,15
/* mark as using no unregistered SEH handlers */
.globl @feat.00
.def @feat.00; .scl 3; .type 0; .endef
.set @feat.00, 1
.globl _ontop_fcontext
.def _ontop_fcontext; .scl 2; .type 32; .endef
_ontop_fcontext:

View File

@ -5,71 +5,48 @@
http://www.boost.org/LICENSE_1_0.txt)
*/
/******************************************************
/*******************************************************
* *
* ------------------------------------------------- *
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* |bchai|hiddn| fpscr | PC | CR | R14 | R15 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | R16 | R17 | R18 | R19 | R20 | R21 | R22 | R23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | R24 | R25 | R26 | R27 | R28 | R29 | R30 | R31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | R13 | R14 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R31 |hiddn| CR | LR | PC |bchai|linkr| FCTX| *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | | *
* ------------------------------------------------- *
* | 256 | | *
* ------------------------------------------------- *
* | DATA| | *
* ------------------------------------------------- *
* ------------------------|------------ *
* | 224 | 228 | 232 | 236 | 240 | 244 | *
* ------------------------|------------ *
* | F30 | F31 |bchai| LR | *
* ------------------------|------------ *
* *
*******************************************************/
@ -79,128 +56,137 @@
.align 2
.type ontop_fcontext,@function
ontop_fcontext:
# reserve space on stack
subi %r1, %r1, 244
# Linux: ontop_fcontext( hidden transfer_t * R3, R4, R5, R6)
# Other: transfer_t R3:R4 = jump_fcontext( R3, R4, R5)
stfd %f14, 0(%r1) # save F14
stfd %f15, 8(%r1) # save F15
stfd %f16, 16(%r1) # save F16
stfd %f17, 24(%r1) # save F17
stfd %f18, 32(%r1) # save F18
stfd %f19, 40(%r1) # save F19
stfd %f20, 48(%r1) # save F20
stfd %f21, 56(%r1) # save F21
stfd %f22, 64(%r1) # save F22
stfd %f23, 72(%r1) # save F23
stfd %f24, 80(%r1) # save F24
stfd %f25, 88(%r1) # save F25
stfd %f26, 96(%r1) # save F26
stfd %f27, 104(%r1) # save F27
stfd %f28, 112(%r1) # save F28
stfd %f29, 120(%r1) # save F29
stfd %f30, 128(%r1) # save F30
stfd %f31, 136(%r1) # save F31
mffs %f0 # load FPSCR
stfd %f0, 144(%r1) # save FPSCR
mflr %r0 # return address from LR
mffs %f0 # FPSCR
mfcr %r8 # condition register
stw %r13, 152(%r1) # save R13
stw %r14, 156(%r1) # save R14
stw %r15, 160(%r1) # save R15
stw %r16, 164(%r1) # save R16
stw %r17, 168(%r1) # save R17
stw %r18, 172(%r1) # save R18
stw %r19, 176(%r1) # save R19
stw %r20, 180(%r1) # save R20
stw %r21, 184(%r1) # save R21
stw %r22, 188(%r1) # save R22
stw %r23, 192(%r1) # save R23
stw %r24, 196(%r1) # save R24
stw %r25, 200(%r1) # save R25
stw %r26, 204(%r1) # save R26
stw %r27, 208(%r1) # save R27
stw %r28, 212(%r1) # save R28
stw %r29, 216(%r1) # save R29
stw %r30, 220(%r1) # save R30
stw %r31, 224(%r1) # save R31
stw %r3, 228(%r1) # save hidden
stwu %r1, -240(%r1) # allocate stack space, R1 % 16 == 0
stw %r0, 244(%r1) # save LR in caller's frame
# save CR
mfcr %r0
stw %r0, 232(%r1)
# save LR
mflr %r0
stw %r0, 236(%r1)
# save LR as PC
stw %r0, 240(%r1)
#ifdef __linux__
stw %r3, 4(%r1) # hidden pointer
#endif
# store RSP (pointing to context-data) in R7
mr %r7, %r1
stfd %f0, 8(%r1) # FPSCR
stw %r0, 16(%r1) # LR as PC
stw %r8, 20(%r1) # CR
# restore RSP (pointing to context-data) from R4
mr %r1, %r4
# Save registers R14 to R31.
# Don't change R2, the thread-local storage pointer.
# Don't change R13, the small data pointer.
stw %r14, 24(%r1)
stw %r15, 28(%r1)
stw %r16, 32(%r1)
stw %r17, 36(%r1)
stw %r18, 40(%r1)
stw %r19, 44(%r1)
stw %r20, 48(%r1)
stw %r21, 52(%r1)
stw %r22, 56(%r1)
stw %r23, 60(%r1)
stw %r24, 64(%r1)
stw %r25, 68(%r1)
stw %r26, 72(%r1)
stw %r27, 76(%r1)
stw %r28, 80(%r1)
stw %r29, 84(%r1)
stw %r30, 88(%r1)
stw %r31, 92(%r1)
lfd %f14, 0(%r1) # restore F14
lfd %f15, 8(%r1) # restore F15
lfd %f16, 16(%r1) # restore F16
lfd %f17, 24(%r1) # restore F17
lfd %f18, 32(%r1) # restore F18
lfd %f19, 40(%r1) # restore F19
lfd %f20, 48(%r1) # restore F20
lfd %f21, 56(%r1) # restore F21
lfd %f22, 64(%r1) # restore F22
lfd %f23, 72(%r1) # restore F23
lfd %f24, 80(%r1) # restore F24
lfd %f25, 88(%r1) # restore F25
lfd %f26, 96(%r1) # restore F26
lfd %f27, 104(%r1) # restore F27
lfd %f28, 112(%r1) # restore F28
lfd %f29, 120(%r1) # restore F29
lfd %f30, 128(%r1) # restore F30
lfd %f31, 136(%r1) # restore F31
lfd %f0, 144(%r1) # load FPSCR
mtfsf 0xff, %f0 # restore FPSCR
# Save registers F14 to F31 in slots with 8-byte alignment.
# 4-byte alignment may stall the pipeline of some processors.
# Less than 4 may cause alignment traps.
stfd %f14, 96(%r1)
stfd %f15, 104(%r1)
stfd %f16, 112(%r1)
stfd %f17, 120(%r1)
stfd %f18, 128(%r1)
stfd %f19, 136(%r1)
stfd %f20, 144(%r1)
stfd %f21, 152(%r1)
stfd %f22, 160(%r1)
stfd %f23, 168(%r1)
stfd %f24, 176(%r1)
stfd %f25, 184(%r1)
stfd %f26, 192(%r1)
stfd %f27, 200(%r1)
stfd %f28, 208(%r1)
stfd %f29, 216(%r1)
stfd %f30, 224(%r1)
stfd %f31, 232(%r1)
lwz %r13, 152(%r1) # restore R13
lwz %r14, 156(%r1) # restore R14
lwz %r15, 160(%r1) # restore R15
lwz %r16, 164(%r1) # restore R16
lwz %r17, 168(%r1) # restore R17
lwz %r18, 172(%r1) # restore R18
lwz %r19, 176(%r1) # restore R19
lwz %r20, 180(%r1) # restore R20
lwz %r21, 184(%r1) # restore R21
lwz %r22, 188(%r1) # restore R22
lwz %r23, 192(%r1) # restore R23
lwz %r24, 196(%r1) # restore R24
lwz %r25, 200(%r1) # restore R25
lwz %r26, 204(%r1) # restore R26
lwz %r27, 208(%r1) # restore R27
lwz %r28, 212(%r1) # restore R28
lwz %r29, 216(%r1) # restore R29
lwz %r30, 220(%r1) # restore R30
lwz %r31, 224(%r1) # restore R31
lwz %r4, 228(%r1) # restore hidden
# store RSP (pointing to context-data) in R7/R6
# restore RSP (pointing to context-data) from R4/R3
#ifdef __linux__
mr %r7, %r1
mr %r1, %r4
lwz %r3, 4(%r1) # hidden pointer
#else
mr %r6, %r1
mr %r1, %r3
#endif
# restore CR
lwz %r0, 232(%r1)
mtcr %r0
# restore LR
lwz %r0, 236(%r1)
# ignore PC at 16(%r1)
lfd %f0, 8(%r1) # FPSCR
lwz %r8, 20(%r1) # CR
mtfsf 0xff, %f0 # restore FPSCR
mtcr %r8 # restore CR
# restore R14 to R31
lwz %r14, 24(%r1)
lwz %r15, 28(%r1)
lwz %r16, 32(%r1)
lwz %r17, 36(%r1)
lwz %r18, 40(%r1)
lwz %r19, 44(%r1)
lwz %r20, 48(%r1)
lwz %r21, 52(%r1)
lwz %r22, 56(%r1)
lwz %r23, 60(%r1)
lwz %r24, 64(%r1)
lwz %r25, 68(%r1)
lwz %r26, 72(%r1)
lwz %r27, 76(%r1)
lwz %r28, 80(%r1)
lwz %r29, 84(%r1)
lwz %r30, 88(%r1)
lwz %r31, 92(%r1)
# restore F14 to F31
lfd %f14, 96(%r1)
lfd %f15, 104(%r1)
lfd %f16, 112(%r1)
lfd %f17, 120(%r1)
lfd %f18, 128(%r1)
lfd %f19, 136(%r1)
lfd %f20, 144(%r1)
lfd %f21, 152(%r1)
lfd %f22, 160(%r1)
lfd %f23, 168(%r1)
lfd %f24, 176(%r1)
lfd %f25, 184(%r1)
lfd %f26, 192(%r1)
lfd %f27, 200(%r1)
lfd %f28, 208(%r1)
lfd %f29, 216(%r1)
lfd %f30, 224(%r1)
lfd %f31, 232(%r1)
# restore LR from caller's frame
lwz %r0, 244(%r1)
mtlr %r0
# ignore PC
# adjust stack
addi %r1, %r1, 244
addi %r1, %r1, 240
# return transfer_t
stw %r7, 0(%r4)
stw %r5, 4(%r4)
# restore CTR
mtctr %r6
# jump to ontop-function
bctr
# see tail_ppc32_sysv_elf_gas.cpp
# Linux: fcontext_ontop_tail( hidden transfer_t * R3, R4, R5, R6, R7)
# Other: transfer_t R3:R4 = fcontext_ontop_tail( R3, R4, R5, R6)
b ontop_fcontext_tail
.size ontop_fcontext, .-ontop_fcontext
/* Mark that we don't need executable stack. */

View File

@ -174,6 +174,9 @@ ontop_fcontext:
# restore CTR
mtctr %r5
# store cb entrypoint in %r12, used for TOC calculation
mr %r12, %r5
# copy transfer_t into ontop_fn arg registers
mr %r3, %r7
# arg pointer already in %r4

View File

@ -68,10 +68,20 @@ ontop_fcontext:
leaq 0x38(%rsp), %rsp /* prepare stack */
/* return transfer_t from jump */
#if !defined(_ILP32)
/* RAX == fctx, RDX == data */
movq %rsi, %rdx
#else
/* RAX == data:fctx */
salq $32, %rsi
orq %rsi, %rax
#endif
/* pass transfer_t as first arg in context function */
#if !defined(_ILP32)
/* RDI == fctx, RSI == data */
#else
/* RDI == data:fctx */
#endif
movq %rax, %rdi
/* keep return-address on stack */

View File

@ -1,4 +1,4 @@
/**
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.