boost/boost-context-0001-add-support-for-ARM64-MACH-O.patch
2015-04-15 11:57:23 +01:00

282 lines
10 KiB
Diff

From cbcd605a24352521d769cff7008d92f15f08bfe6 Mon Sep 17 00:00:00 2001
From: Oliver Kowalke <oliver.kowalke@gmx.de>
Date: Wed, 12 Nov 2014 19:46:42 +0100
Subject: [PATCH 01/54] add support fro ARM64/MACH-O
---
build/Jamfile.v2 | 31 +++++++++
src/asm/jump_arm64_aapcs_macho_gas.S | 124 +++++++++++++++++++++++++++++++++++
src/asm/make_arm64_aapcs_macho_gas.S | 87 ++++++++++++++++++++++++
3 files changed, 242 insertions(+)
create mode 100644 src/asm/jump_arm64_aapcs_macho_gas.S
create mode 100644 src/asm/make_arm64_aapcs_macho_gas.S
diff --git a/libs/context/build/Jamfile.v2 b/libs/context/build/Jamfile.v2
index 7cc8a07..32d5222 100644
--- a/libs/context/build/Jamfile.v2
+++ b/libs/context/build/Jamfile.v2
@@ -209,6 +209,37 @@ alias asm_context_sources
<toolset>msvc
;
+# ARM64
+# ARM64/AAPCS/MACH-O
+alias asm_context_sources
+ : [ make asm/make_arm64_aapcs_macho_gas.o : asm/make_arm64_aapcs_macho_gas.S : @gas64 ]
+ [ make asm/jump_arm64_aapcs_macho_gas.o : asm/jump_arm64_aapcs_macho_gas.S : @gas64 ]
+ : <abi>aapcs
+ <address-model>64
+ <architecture>arm
+ <binary-format>mach-o
+ ;
+
+alias asm_context_sources
+ : asm/make_arm64_aapcs_macho_gas.S
+ asm/jump_arm64_aapcs_macho_gas.S
+ : <abi>aapcs
+ <address-model>64
+ <architecture>arm
+ <binary-format>mach-o
+ <toolset>clang
+ ;
+
+alias asm_context_sources
+ : asm/make_arm64_aapcs_macho_gas.S
+ asm/jump_arm64_aapcs_macho_gas.S
+ : <abi>aapcs
+ <address-model>64
+ <architecture>arm
+ <binary-format>mach-o
+ <toolset>darwin
+ ;
+
# MIPS
# MIPS/O32/ELF
alias asm_context_sources
diff --git a/libs/context/src/asm/jump_arm64_aapcs_macho_gas.S b/libs/context/src/asm/jump_arm64_aapcs_macho_gas.S
new file mode 100644
index 0000000..6ad5b38
--- /dev/null
+++ b/libs/context/src/asm/jump_arm64_aapcs_macho_gas.S
@@ -0,0 +1,124 @@
+/*
+ Copyright Oliver Kowalke 2014.
+ 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| *
+ * ------------------------------------------------- *
+ * | s16 | s17 | s18 | s19 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
+ * ------------------------------------------------- *
+ * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
+ * ------------------------------------------------- *
+ * | s20 | s21 | s22 | s23 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
+ * ------------------------------------------------- *
+ * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
+ * ------------------------------------------------- *
+ * | s24 | s25 | s26 | s27 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
+ * ------------------------------------------------- *
+ * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
+ * ------------------------------------------------- *
+ * | s28 | s29 | s30 | s31 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
+ * ------------------------------------------------- *
+ * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
+ * ------------------------------------------------- *
+ * | sjlj | v1 | v2 | v3 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
+ * ------------------------------------------------- *
+ * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| *
+ * ------------------------------------------------- *
+ * | v4 | v5 | v6 | v7 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 48 | 49 | 50 | 51 | 52 | 53 | | *
+ * ------------------------------------------------- *
+ * | 0xc0| 0xc4| 0xc8| 0xcc| 0xd0| 0xd4| | *
+ * ------------------------------------------------- *
+ * | v8 | lr | pc | | *
+ * ------------------------------------------------- *
+ * *
+ *******************************************************/
+
+.text
+.globl _jump_fcontext
+.align 2
+_jump_fcontext:
+ @ save LR as PC
+ push {lr}
+ @ save V1-V8,LR
+ push {v1-v8,lr}
+
+ @ locate TLS to save/restore SjLj handler
+ mrc p15, 0, v2, c13, c0, #3
+ bic v2, v2, #3
+
+ @ load TLS[__PTK_LIBC_DYLD_Unwind_SjLj_Key]
+ ldr v1, [v2, #72]
+ @ save SjLj handler
+ push {v1}
+
+ @ prepare stack for FPU
+ sub sp, sp, #128
+
+#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
+ @ test if fpu env should be preserved
+ cmp a4, #0
+ beq 1f
+
+ @ save S16-S31
+ vstmia sp, {d8-d15}
+
+1:
+#endif
+
+ @ store RSP (pointing to context-data) in A1
+ str sp, [a1]
+
+ @ restore RSP (pointing to context-data) from A2
+ mov sp, a2
+
+#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
+ @ test if fpu env should be preserved
+ cmp a4, #0
+ beq 2f
+
+ @ restore S16-S31
+ vldmia sp, {d8-d15}
+
+2:
+#endif
+
+ @ prepare stack for FPU
+ add sp, sp, #128
+
+ @ restore SjLj handler
+ pop {v1}
+ @ store SjLj handler in TLS
+ str v1, [v2, #72]
+
+ @ use third arg as return value after jump
+ @ and as first arg in context function
+ mov a1, a3
+
+ @ restore v1-V8,LR,PC
+ pop {v1-v8,lr,pc}
diff --git a/libs/context/src/asm/make_arm64_aapcs_macho_gas.S b/libs/context/src/asm/make_arm64_aapcs_macho_gas.S
new file mode 100644
index 0000000..67d2f89
--- /dev/null
+++ b/libs/context/src/asm/make_arm64_aapcs_macho_gas.S
@@ -0,0 +1,87 @@
+/*
+ Copyright Oliver Kowalke 2014.
+ 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| *
+ * ------------------------------------------------- *
+ * | s16 | s17 | s18 | s19 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
+ * ------------------------------------------------- *
+ * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
+ * ------------------------------------------------- *
+ * | s20 | s21 | s22 | s23 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
+ * ------------------------------------------------- *
+ * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
+ * ------------------------------------------------- *
+ * | s24 | s25 | s26 | s27 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
+ * ------------------------------------------------- *
+ * | 0x60| 0x64| 0x68| 0x6c| 0x70| 0x74| 0x78| 0x7c| *
+ * ------------------------------------------------- *
+ * | s28 | s29 | s30 | s31 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
+ * ------------------------------------------------- *
+ * | 0x80| 0x84| 0x88| 0x8c| 0x90| 0x94| 0x98| 0x9c| *
+ * ------------------------------------------------- *
+ * | sjlj | v1 | v2 | v3 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
+ * ------------------------------------------------- *
+ * | 0xa0| 0xa4| 0xa8| 0xac| 0xb0| 0xb4| 0xb8| 0xbc| *
+ * ------------------------------------------------- *
+ * | v4 | v5 | v6 | v7 | *
+ * ------------------------------------------------- *
+ * ------------------------------------------------- *
+ * | 48 | 49 | 50 | 51 | 52 | 53 | | *
+ * ------------------------------------------------- *
+ * | 0xc0| 0xc4| 0xc8| 0xcc| 0xd0| 0xd4| | *
+ * ------------------------------------------------- *
+ * | v8 | lr | pc | | *
+ * ------------------------------------------------- *
+ * *
+ *******************************************************/
+
+.text
+.globl _make_fcontext
+.align 2
+_make_fcontext:
+ @ shift address in A1 to lower 16 byte boundary
+ bic a1, a1, #15
+
+ @ reserve space for context-data on context-stack
+ sub a1, a1, #216
+
+ @ third arg of make_fcontext() == address of context-function
+ str a3, [a1,#208]
+
+ @ compute abs address of label finish
+ adr a2, finish
+ @ save address of finish as return-address for context-function
+ @ will be entered after context-function returns
+ str a2, [a1,#200]
+
+ bx lr @ return pointer to context-data
+
+finish:
+ @ exit code is zero
+ mov a1, #0
+ @ exit application
+ bl __exit
--
2.3.5