Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77449 - in trunk/libs/context: build example src/asm
From: oliver.kowalke_at_[hidden]
Date: 2012-03-21 03:52:01


Author: olli
Date: 2012-03-21 03:52:00 EDT (Wed, 21 Mar 2012)
New Revision: 77449
URL: http://svn.boost.org/trac/boost/changeset/77449

Log:
context: add support for 32bit MacOS X

Added:
   trunk/libs/context/src/asm/fcontext_i386_sysv_macho_gas.S (contents, props changed)
Text files modified:
   trunk/libs/context/build/Jamfile.v2 | 19 ++++++++++---------
   trunk/libs/context/example/pic.sh | 4 ++--
   2 files changed, 12 insertions(+), 11 deletions(-)

Modified: trunk/libs/context/build/Jamfile.v2
==============================================================================
--- trunk/libs/context/build/Jamfile.v2 (original)
+++ trunk/libs/context/build/Jamfile.v2 2012-03-21 03:52:00 EDT (Wed, 21 Mar 2012)
@@ -83,13 +83,6 @@
                 ECHO "toolset not supported" ;
         }
 
- if ( <target-os>darwin in $(properties)
- && <address-model>32 in $(properties) )
- {
- result = <build>no ;
- ECHO "32bit Darwin not supported" ;
- }
-
         return $(result) ;
 }
 
@@ -165,6 +158,16 @@
    ;
 
 alias asm_context_sources
+ : asm/fcontext_i386_sysv_macho_gas.S
+ : <abi>sysv
+ <address-model>32
+ <architecture>x86
+ <binary-format>mach-o
+ <target-os>darwin
+ <toolset>gcc
+ ;
+
+alias asm_context_sources
    : asm/fcontext_x86_64_sysv_macho_gas.S
    : <abi>sysv
      <address-model>64
@@ -251,7 +254,6 @@
   : asm_context_sources
   : [ architecture.architecture ]
     [ architecture.address-model ]
- <conditional>@configure
   ;
 
 
@@ -276,7 +278,6 @@
    : select_asm_context_sources
      context_sources
    : <link>shared:<define>BOOST_CONTEXT_DYN_LINK=1
- <conditional>@configure
    ;
 
 

Modified: trunk/libs/context/example/pic.sh
==============================================================================
--- trunk/libs/context/example/pic.sh (original)
+++ trunk/libs/context/example/pic.sh 2012-03-21 03:52:00 EDT (Wed, 21 Mar 2012)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-g++ -x assembler-with-cpp -fPIC -O3 -finline-functions -Wno-inline -Wall -march=native -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_DYN_LINK=1 -DNDEBUG -I../../.. -c -o fcontext_x86_64_sysv_elf_gas.o ../src/asm/fcontext_x86_64_sysv_elf_gas.S
+g++ -x assembler-with-cpp -fPIC -O3 -finline-functions -Wno-inline -Wall -march=native -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_DYN_LINK=1 -DNDEBUG -I../../.. -c -o fcontext_i386_sysv_elf_gas.o ../src/asm/fcontext_i386_sysv_elf_gas.S
 
 g++ -ftemplate-depth-128 -fPIC -O3 -finline-functions -Wno-inline -Wall -march=native -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_DYN_LINK=1 -DNDEBUG -I../../.. -c -o fcontext.o ../src/fcontext.cpp
 
@@ -8,6 +8,6 @@
 
 g++ -ftemplate-depth-128 -fPIC -O3 -finline-functions -Wno-inline -Wall -march=native -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_DYN_LINK=1 -DNDEBUG -I../../.. -c -o stack_utils_posix.o ../src/stack_utils_posix.cpp
 
-gcc -shared -Wl,-soname,libboost_my_lib.so -o libboost_my_lib.so fcontext.o stack_allocator_posix.o stack_utils_posix.o fcontext_x86_64_sysv_elf_gas.o -lc -lstdc++
+gcc -shared -Wl,-soname,libboost_my_lib.so -o libboost_my_lib.so fcontext.o stack_allocator_posix.o stack_utils_posix.o fcontext_i386_sysv_elf_gas.o -lc -lstdc++
 
 gcc -g ./transfer.cpp -I../../../ -L./ -Wl,-rpath=./ -lboost_my_lib -lrt

Added: trunk/libs/context/src/asm/fcontext_i386_sysv_macho_gas.S
==============================================================================
--- (empty file)
+++ trunk/libs/context/src/asm/fcontext_i386_sysv_macho_gas.S 2012-03-21 03:52:00 EDT (Wed, 21 Mar 2012)
@@ -0,0 +1,132 @@
+/*
+ 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)
+*/
+
+/********************************************************************
+ * *
+ * -------------------------------------------------------------- *
+ * | 0 | 1 | 2 | 3 | 4 | 5 | *
+ * -------------------------------------------------------------- *
+ * | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | *
+ * -------------------------------------------------------------- *
+ * | EDI | ESI | EBX | EBP | ESP | EIP | *
+ * -------------------------------------------------------------- *
+ * -------------------------------------------------------------- *
+ * | 6 | 7 | | *
+ * -------------------i------------------------------------------ *
+ * | 0x18 | 0x1c | | *
+ * -------------------------------------------------------------- *
+ * | fc_mxcsr|fc_x87_cw| | *
+ * -------------------------------------------------------------- *
+ * -------------------------------------------------------------- *
+ * | 8 | 9 | | *
+ * -------------------------------------------------------------- *
+ * | 0x20 | 0x24 | | *
+ * -------------------------------------------------------------- *
+ * | sbase | slimit | | *
+ * -------------------------------------------------------------- *
+ * -------------------------------------------------------------- *
+ * | 10 | | *
+ * -------------------------------------------------------------- *
+ * | 0x28 | | *
+ * -------------------------------------------------------------- *
+ * | fc_link | | *
+ * -------------------------------------------------------------- *
+ * *
+ * *****************************************************************/
+
+.text
+.globl _boost_fcontext_jump
+.align 2
+_boost_fcontext_jump:
+ movl 0x4(%esp), %ecx /* load address of the first fcontext_t arg */
+ movl %edi, (%ecx) /* save EDI */
+ movl %esi, 0x4(%ecx) /* save ESI */
+ movl %ebx, 0x8(%ecx) /* save EBX */
+ movl %ebp, 0xc(%ecx) /* save EBP */
+
+ stmxcsr 0x18(%ecx) /* save SSE2 control and status word */
+ fnstcw 0x1c(%ecx) /* save x87 control word */
+
+ leal 0x4(%esp), %eax /* exclude the return address */
+ movl %eax, 0x10(%ecx) /* save as stack pointer */
+ movl (%esp), %eax /* load return address */
+ movl %eax, 0x14(%ecx) /* save return address */
+
+
+ movl 0x8(%esp), %ecx /* load address of the second fcontext_t arg */
+ movl (%ecx), %edi /* restore EDI */
+ movl 0x4(%ecx), %esi /* restore ESI */
+ movl 0x8(%ecx), %ebx /* restore EBX */
+ movl 0xc(%ecx), %ebp /* restore EBP */
+
+ ldmxcsr 0x18(%ecx) /* restore SSE2 control and status word */
+ fldcw 0x1c(%ecx) /* restore x87 control word */
+
+ movl 0xc(%esp), %eax /* use third arg as return value after jump */
+
+ movl 0x10(%ecx), %esp /* restore ESP */
+ movl 0x14(%ecx), %ecx /* fetch the address to return to */
+
+ jmp *%ecx /* indirect jump to context */
+
+.text
+.globl _boost_fcontext_make
+.align 2
+_boost_fcontext_make:
+ movl 0x4(%esp), %eax /* load address of the fcontext_t */
+ movl %eax, (%eax) /* save the address of current context */
+ movl 0x8(%esp), %ecx /* load the address of the function supposed to run */
+ movl %ecx, 0x14(%eax) /* save the address of the function supposed to run */
+ movl 0x20(%eax), %edx /* load the stack base */
+
+ pushl %eax /* save pointer to fcontext_t */
+ pushl %ebx /* save EBX */
+ pushl %edx /* stack pointer as arg for boost_fcontext_align */
+ call 1f
+1: popl %ebx /* address of label 1 */
+ addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx /* compute address of GOT and store it in EBX */
+ call boost_fcontext_align_at_PLT /* align stack */
+ movl %eax, %edx /* begin of aligned stack */
+ popl %eax /* remove arg for boost_fcontext_align */
+ popl %ebx /* restore EBX */
+ popl %eax /* restore pointer to fcontext_t */
+
+ leal -0x14(%edx), %edx /* reserve space for the last frame on stack, (ESP + 4) % 16 == 0 */
+ movl %edx, 0x10(%eax) /* save the address as stack pointer */
+ movl 0x28(%eax), %ecx /* load the address of the next context */
+ movl %ecx, 0x4(%eax) /* save the address of the next context */
+ movl 0xc(%esp), %ecx /* load the address of the void pointer */
+ movl %ecx, 0x4(%edx) /* save the address of the void pointer */
+ stmxcsr 0x18(%eax) /* save SSE2 control and status word */
+ fnstcw 0x1c(%eax) /* save x87 control word */
+ call 2f
+2: popl %ecx /* address of label 1 */
+ addl $link_fcontext-2b, %ecx /* compute address of label link_fcontext */
+ movl %ecx, (%edx) /* store address of link_fcontext as return address on stack */
+
+ xorl %eax, %eax /* set EAX to zero */
+ ret
+
+link_fcontext:
+ leal -0xc(%esp), %esp
+
+ call 3f
+3: popl %ebx /* address of label 3 */
+ addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %ebx /* compute address of GOT and store it in EBX */
+
+ testl %esi, %esi /* test if a next context was given */
+ je 4f /* jump to finish */
+
+ pushl %esi /* push the address of the next context on the stack */
+ pushl %edi /* push the address of the current context to stack */
+ call boost_fcontext_start_at_PLT /* jump to next context */
+
+4:
+ movl %eax, %eax
+ pushl %eax /* exit code is zero */
+ call _exit_at_PLT /* exit application */
+ hlt


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk