Index: boost/context/detail/fcontext_arm_mac.hpp =================================================================== --- boost/context/detail/fcontext_arm_mac.hpp (revision 0) +++ boost/context/detail/fcontext_arm_mac.hpp (working copy) @@ -0,0 +1,69 @@ + +// Copyright Oliver Kowalke 2009. +// 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) + +#ifndef BOOST_CONTEXT_DETAIL_FCONTEXT_ARM_MAC_H +#define BOOST_CONTEXT_DETAIL_FCONTEXT_ARM_MAC_H + +#include + +#include +#include + +#include + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +namespace boost { +namespace context { + +extern "C" { + +#define BOOST_CONTEXT_CALLDECL + +struct stack_t +{ + void * sp; + std::size_t size; + + stack_t() : + sp( 0), size( 0) + {} +}; + +struct fp_t +{ + boost::uint32_t fc_freg[16]; + + fp_t() : + fc_freg() + {} +}; + +struct fcontext_t +{ + boost::uint32_t fc_greg[11]; + stack_t fc_stack; + fp_t fc_fp; + void * fc_unwind_sjlj; + + fcontext_t() : + fc_greg(), + fc_stack(), + fc_fp() + {} +}; + +} + +}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif + +#endif // BOOST_CONTEXT_DETAIL_FCONTEXT_ARM_MAC_H Index: boost/context/fcontext.hpp =================================================================== --- boost/context/fcontext.hpp (revision 86787) +++ boost/context/fcontext.hpp (working copy) @@ -49,7 +49,11 @@ // arm #elif defined(__arm__) || defined(__thumb__) || defined(__TARGET_ARCH_ARM) \ || defined(__TARGET_ARCH_THUMB) || defined(_ARM) || defined(_M_ARM) -# include +# if defined(__MACH__) && defined(__APPLE__) +# include +# else +# include +# endif // mips #elif (defined(__mips) && __mips == 1) || defined(_MIPS_ISA_MIPS1) \ || defined(_R3000) Index: libs/context/src/asm/jump_arm_aapcs_macho_gas.S =================================================================== --- libs/context/src/asm/jump_arm_aapcs_macho_gas.S (revision 86787) +++ libs/context/src/asm/jump_arm_aapcs_macho_gas.S (working copy) @@ -42,6 +42,13 @@ * ------------------------------------------------------------- * * | s26 | s27 | s28 | s29 | s30 | s31 | | * * ------------------------------------------------------------- * + * ------------------------------------------------------------- * + * | 29 | | * + * ------------------------------------------------------------- * + * | 0x74| | * + * ------------------------------------------------------------- * + * | sjlj| | * + * ------------------------------------------------------------- * * * * *****************************************************************/ @@ -65,7 +72,15 @@ vldmia a4, {d8-d15} @ restore S16-S31 1: #endif + + mrc p15, 0, a4, c13, c0, #3 @ locate TLS to save/restore SjLj handler + bic a4, a4, #3 + ldr v1, [a4, #72] @ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key] + str v1, [a1, #116] @ save SjLj unwind top handler + ldr v1, [a2, #116] @ load new SjLj handler + str v1, [a4, #72] @ store it to TLS + mov a1, a3 @ use third arg as return value after jump @ and as first arg in context function ldmia a2, {v1-v8,sp-pc} @ restore v1-V8,SP-PC Index: libs/context/src/asm/jump_arm_aapcs_pe_armasm.asm =================================================================== --- libs/context/src/asm/jump_arm_aapcs_pe_armasm.asm (revision 86787) +++ libs/context/src/asm/jump_arm_aapcs_pe_armasm.asm (working copy) @@ -12,7 +12,7 @@ ; * ------------------------------------------------------------- * ; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| 0x20| 0x24| * ; * ------------------------------------------------------------- * -; * | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | sp | lr | * +; * | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | lr | sp | * ; * ------------------------------------------------------------- * ; * ------------------------------------------------------------- * ; * | 10 | | * @@ -50,12 +50,32 @@ EXPORT jump_fcontext jump_fcontext PROC - stmia a1, {r4-r11,sp-lr} ; save V1-V8,SP-LR - str lr, [a1,#40] ; save LR as PC + stmia a1, {r4-r11,lr} ; save V1-V8,LR + str sp, [a1,#0x24] ; save SP separately - Thumb cannot handle stmia {sp-pc} + str lr, [a1,#0x28] ; save LR as PC - mov a1, a3 ; use third arg as return value after jump - ; and as first arg in context function - ldmia a2, {r4-r11,sp-pc} ; restore v1-V8,SP-PC + ; load TIB to save/restore thread size and limit. + ; we do not need preserveCPU flag and can use it's arg register + mrc p15, #0, a4, c13, c0, #2 + ldr r4, [a4,#0x04] ; current stack base + ldr r5, [a4,#0x08] ; current stack limit + sub r5, r4, r5 ; size = base - limit + str r4, [a1,#0x2c] ; save stack base + str r5, [a1,#0x30] ; save stack size + + ldr r4, [a2,#0x2c] ; load stack base + ldr r5, [a2,#0x30] ; load stack limit + sub r5, r4, r5 ; limit = base - size + str r4, [a4,#0x04] ; restore stack base + str r5, [a4,#0x08] ; restore stack limit + + mov a1, a3 ; use third arg as return value after jump + ; and as first arg in context function + + ldmia a2, {r4-r11,lr} ; restore V1-V8,LR + ldr sp, [a2,#0x24] + ldr pc, [a2,#0x28] + ENDP END Index: libs/context/src/asm/make_arm_aapcs_macho_gas.S =================================================================== --- libs/context/src/asm/make_arm_aapcs_macho_gas.S (revision 86787) +++ libs/context/src/asm/make_arm_aapcs_macho_gas.S (working copy) @@ -42,6 +42,13 @@ * ------------------------------------------------------------- * * | s26 | s27 | s28 | s29 | s30 | s31 | | * * ------------------------------------------------------------- * + * ------------------------------------------------------------- * + * | 29 | | * + * ------------------------------------------------------------- * + * | 0x74| | * + * ------------------------------------------------------------- * + * | sjlj| | * + * ------------------------------------------------------------- * * * * *****************************************************************/ @@ -50,7 +57,7 @@ .align 2 _make_fcontext: mov a4, a1 @ save address of context stack (base) A4 - sub a1, a1, #116 @ reserve space for fcontext_t at top of context stack + sub a1, a1, #120 @ reserve space for fcontext_t at top of context stack @ shift address in A1 to lower 16 byte boundary @ == pointer to fcontext_t and address of context stack Index: libs/context/src/asm/make_arm_aapcs_pe_armasm.asm =================================================================== --- libs/context/src/asm/make_arm_aapcs_pe_armasm.asm (revision 86787) +++ libs/context/src/asm/make_arm_aapcs_pe_armasm.asm (working copy) @@ -12,7 +12,7 @@ ; * ------------------------------------------------------------- * ; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| 0x20| 0x24| * ; * ------------------------------------------------------------- * -; * | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | sp | lr | * +; * | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | lr | sp | * ; * ------------------------------------------------------------- * ; * ------------------------------------------------------------- * ; * | 10 | | * @@ -53,20 +53,20 @@ make_fcontext PROC mov a4, a1 ; save address of context stack (base) A4 - sub a1, a1, #116 ; reserve space for fcontext_t at top of context stack + sub a1, a1, #0x74 ; reserve space for fcontext_t at top of context stack ; shift address in A1 to lower 16 byte boundary ; == pointer to fcontext_t and address of context stack - bic a1, a1, #15 + bic a1, a1, #0x0f - str a4, [a1,#44] ; save address of context stack (base) in fcontext_t - str a2, [a1,#48] ; save context stack size in fcontext_t - str a3, [a1,#40] ; save address of context function in fcontext_t + str a4, [a1,#0x2c] ; save address of context stack (base) in fcontext_t + str a2, [a1,#0x30] ; save context stack size in fcontext_t + str a3, [a1,#0x28] ; save address of context function in fcontext_t - str a1, [a1,#32] ; save address in A4 as stack pointer for context function + str a1, [a1,#0x24] ; save address in A4 as stack pointer for context function adr a2, finish ; compute abs address of label finish - str a2, [a1,#36] ; save address of finish as return address for context function + str a2, [a1,#0x20] ; save address of finish as return address for context function ; entered after context function returns bx lr