Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

View File

@ -0,0 +1,131 @@
/*
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
# 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]
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]
# save LR as PC
str x30, [sp, #0xa0]
# store RSP (pointing to context-data) in first argument (x0).
# STR cannot have sp as a target register
mov x4, sp
str x4, [x0]
# restore RSP (pointing to context-data) from A2 (x1)
mov sp, x1
# # 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]
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]
# use third arg as return value after jump
# and as first arg in context function
mov x0, x2
# load pc
ldr x4, [sp, #0xa0]
# restore stack from GP + FPU
add sp, sp, #0xb0
ret x4
.size jump_fcontext,.-jump_fcontext
# Mark that we don't need executable stack.
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,120 @@
/*******************************************************
* *
* ------------------------------------------------- *
* | 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 | | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _jump_fcontext
.balign 16
_jump_fcontext:
; prepare stack for GP + FPU
sub sp, sp, #0xb0
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
; 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]
1:
#endif
; 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 fp, lr, [sp, #0x90]
; save LR as PC
str lr, [sp, #0xa0]
; store RSP (pointing to context-data) in first argument (x0).
; STR cannot have sp as a target register
mov x4, sp
str x4, [x0]
; restore RSP (pointing to context-data) from A2 (x1)
mov sp, x1
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
; 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]
2:
#endif
; 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 fp, lr, [sp, #0x90]
; use third arg as return value after jump
; and as first arg in context function
mov x0, x2
; load pc
ldr x4, [sp, #0xa0]
; restore stack from GP + FPU
add sp, sp, #0xb0
ret x4

View File

@ -0,0 +1,93 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | | *
* ------------------------------------------------- *
* | 0x60| 0x64| | *
* ------------------------------------------------- *
* | lr | pc | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,%function
jump_fcontext:
@ save LR as PC
push {lr}
@ save V1-V8,LR
push {v1-v8,lr}
@ prepare stack for FPU
sub sp, sp, #64
#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, #64
@ 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}
.size jump_fcontext,.-jump_fcontext
@ Mark that we don't need executable stack.
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,103 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | sjlj| v1 | v2 | v3 | v4 | v5 | v6 | v7 |
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | | *
* ------------------------------------------------- *
* | 0x60| 0x64| 0x68| | *
* ------------------------------------------------- *
* | 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, #64
#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, #64
@ 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}

View File

@ -0,0 +1,112 @@
;/*
; 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 | 6 | 7 | *
; * ------------------------------------------------- *
; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
; * ------------------------------------------------- *
; * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
; * ------------------------------------------------- *
; * ------------------------------------------------- *
; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
; * ------------------------------------------------- *
; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
; * ------------------------------------------------- *
; * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
; * ------------------------------------------------- *
; * ------------------------------------------------- *
; * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
; * ------------------------------------------------- *
; * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
; * ------------------------------------------------- *
; * |deall|limit| base| v1 | v2 | v3 | v4 | v5 | *
; * ------------------------------------------------- *
; * ------------------------------------------------- *
; * | 24 | 25 | 26 | 27 | 28 | | *
; * ------------------------------------------------- *
; * | 0x60| 0x64| 0x68| 0x6c| 0x70| | *
; * ------------------------------------------------- *
; * | v6 | v7 | v8 | lr | pc | | *
; * ------------------------------------------------- *
; * *
; *******************************************************
AREA |.text|, CODE
ALIGN 4
EXPORT jump_fcontext
jump_fcontext PROC
@ save LR as PC
push {lr}
@ save V1-V8,LR
push {v1-v8,lr}
@ prepare stack for FPU
sub sp, sp, #0x4c
@ test if fpu env should be preserved
cmp a4, #0
beq 1f
@ save S16-S31
vstmia sp, {d8-d15}
1:
; load TIB to save/restore thread size and limit.
; we do not need preserve CPU flag and can use it's arg register
mrc p15, #0, v1, c13, c0, #2
; save current stack base
ldr a5, [v1,#0x04]
str a5, [sp,#0x48]
; save current stack limit
ldr a5, [v1,#0x08]
str a5, [sp,#0x44]
; save current deallocation stack
ldr a5, [v1,#0xe0c]
str a5, [sp,#0x40]
@ store RSP (pointing to context-data) in A1
str sp, [a1]
@ restore RSP (pointing to context-data) from A2
mov sp, a2
@ test if fpu env should be preserved
cmp a4, #0
beq 2f
@ restore S16-S31
vldmia sp, {d8-d15}
2:
; restore stack base
ldr a5, [sp,#0x48]
str a5, [v1,#0x04]
; restore stack limit
ldr a5, [sp,#0x44]
str a5, [v1,#0x08]
; restore deallocation stack
ldr a5, [sp,#0x40]
str a5, [v1,#0xe0c]
@ prepare stack for FPU
add sp, sp, #0x4c
; use third arg as return value after jump
; and as first arg in context function
mov a1, a3
@ restore v1-V8,LR
pop {v1-v8,lr}
pop {pc}
ENDP
END

View File

@ -0,0 +1,20 @@
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__i386__)
#include "jump_i386_sysv_macho_gas.S"
#elif defined(__x86_64__)
#include "jump_x86_64_sysv_macho_gas.S"
#elif defined(__ppc__)
#include "jump_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "jump_ppc64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -0,0 +1,140 @@
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
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 |
---------------------------------------------------------------------------------
| 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch |
---------------------------------------------------------------------------------
| fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI |
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
| 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
---------------------------------------------------------------------------------
| 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch |
---------------------------------------------------------------------------------
| ESI | EBX | EBP | EIP | EXIT | | SEH NXT |SEH HNDLR|
---------------------------------------------------------------------------------
* *****************************************************************/
.file "jump_i386_ms_pe_gas.asm"
.text
.p2align 4,,15
.globl _jump_fcontext
.def _jump_fcontext; .scl 2; .type 32; .endef
_jump_fcontext:
/* fourth arg of jump_fcontext() == flag indicating preserving FPU */
movl 0x10(%esp), %ecx
pushl %ebp /* save EBP */
pushl %ebx /* save EBX */
pushl %esi /* save ESI */
pushl %edi /* save EDI */
/* load NT_TIB */
movl %fs:(0x18), %edx
/* load current SEH exception list */
movl (%edx), %eax
push %eax
/* load current stack base */
movl 0x04(%edx), %eax
push %eax
/* load current stack limit */
movl 0x08(%edx), %eax
push %eax
/* load current dealloction stack */
movl 0xe0c(%edx), %eax
push %eax
/* load fiber local storage */
movl 0x10(%edx), %eax
push %eax
/* prepare stack for FPU */
leal -0x08(%esp), %esp
/* test for flag preserve_fpu */
testl %ecx, %ecx
je 1f
/* save MMX control word */
stmxcsr (%esp)
/* save x87 control word */
fnstcw 0x04(%esp)
1:
/* first arg of jump_fcontext() == context jumping from */
movl 0x30(%esp), %eax
/* store ESP (pointing to context-data) in EAX */
movl %esp, (%eax)
/* second arg of jump_fcontext() == context jumping to */
movl 0x34(%esp), %edx
/* third arg of jump_fcontext() == value to be returned after jump */
movl 0x38(%esp), %eax
/* restore ESP (pointing to context-data) from EDX */
movl %edx, %esp
/* test for flag preserve_fpu */
testl %ecx, %ecx
je 2f
/* restore MMX control- and status-word */
ldmxcsr (%esp)
/* restore x87 control-word */
fldcw 0x04(%esp)
2:
/* prepare stack for FPU */
leal 0x08(%esp), %esp
/* load NT_TIB into ECX */
movl %fs:(0x18), %edx
/* restore fiber local storage */
popl %ecx
movl %ecx, 0x10(%edx)
/* restore current deallocation stack */
popl %ecx
movl %ecx, 0xe0c(%edx)
/* restore current stack limit */
popl %ecx
movl %ecx, 0x08(%edx)
/* restore current stack base */
popl %ecx
movl %ecx, 0x04(%edx)
/* restore current SEH exception list */
popl %ecx
movl %ecx, (%edx)
popl %edi /* save EDI */
popl %esi /* save ESI */
popl %ebx /* save EBX */
popl %ebp /* save EBP */
/* restore return-address */
popl %edx
/* use value in EAX as return-value after jump */
/* use value in EAX as first arg in context function */
movl %eax, 0x04(%esp)
/* indirect jump to context */
jmp *%edx

View File

@ -0,0 +1,142 @@
; 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 | 6 | 7 |
; ---------------------------------------------------------------------------------
; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch |
; ---------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ---------------------------------------------------------------------------------
; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch |
; ---------------------------------------------------------------------------------
; | ESI | EBX | EBP | EIP | EXIT | | SEH NXT |SEH HNDLR|
; ---------------------------------------------------------------------------------
.386
.XMM
.model flat, c
.code
jump_fcontext PROC BOOST_CONTEXT_EXPORT
; fourth arg of jump_fcontext() == flag indicating preserving FPU
mov ecx, [esp+010h]
push ebp ; save EBP
push ebx ; save EBX
push esi ; save ESI
push edi ; save EDI
assume fs:nothing
; load NT_TIB into ECX
mov edx, fs:[018h]
assume fs:error
; load current SEH exception list
mov eax, [edx]
push eax
; load current stack base
mov eax, [edx+04h]
push eax
; load current stack limit
mov eax, [edx+08h]
push eax
; load current deallocation stack
mov eax, [edx+0e0ch]
push eax
; load fiber local storage
mov eax, [edx+010h]
push eax
; prepare stack for FPU
lea esp, [esp-08h]
; test for flag preserve_fpu
test ecx, ecx
je nxt1
; save MMX control- and status-word
stmxcsr [esp]
; save x87 control-word
fnstcw [esp+04h]
nxt1:
; first arg of jump_fcontext() == context jumping from
mov eax, [esp+030h]
; store ESP (pointing to context-data) in EAX
mov [eax], esp
; second arg of jump_fcontext() == context jumping to
mov edx, [esp+034h]
; third arg of jump_fcontext() == value to be returned after jump
mov eax, [esp+038h]
; restore ESP (pointing to context-data) from EDX
mov esp, edx
; test for flag preserve_fpu
test ecx, ecx
je nxt2
; restore MMX control- and status-word
ldmxcsr [esp]
; restore x87 control-word
fldcw [esp+04h]
nxt2:
; prepare stack for FPU
lea esp, [esp+08h]
assume fs:nothing
; load NT_TIB into ECX
mov edx, fs:[018h]
assume fs:error
; restore fiber local storage
pop ecx
mov [edx+010h], ecx
; restore current deallocation stack
pop ecx
mov [edx+0e0ch], ecx
; restore current stack limit
pop ecx
mov [edx+08h], ecx
; restore current stack base
pop ecx
mov [edx+04h], ecx
; restore current SEH exception list
pop ecx
mov [edx], ecx
pop edi ; save EDI
pop esi ; save ESI
pop ebx ; save EBX
pop ebp ; save EBP
; restore return-address
pop edx
; use value in EAX as return-value after jump
; use value in EAX as first arg in context function
mov [esp+04h], eax
; indirect jump to context
jmp edx
jump_fcontext ENDP
END

View File

@ -0,0 +1,90 @@
/*
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 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | EXIT | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
jump_fcontext:
/* fourth arg of jump_fcontext() == flag indicating preserving FPU */
movl 0x10(%esp), %ecx
pushl %ebp /* save EBP */
pushl %ebx /* save EBX */
pushl %esi /* save ESI */
pushl %edi /* save EDI */
/* prepare stack for FPU */
leal -0x8(%esp), %esp
/* test for flag preserve_fpu */
test %ecx, %ecx
je 1f
/* save MMX control- and status-word */
stmxcsr (%esp)
/* save x87 control-word */
fnstcw 0x4(%esp)
1:
/* first arg of jump_fcontext() == context jumping from */
movl 0x1c(%esp), %eax
/* store ESP (pointing to context-data) in EAX */
movl %esp, (%eax)
/* second arg of jump_fcontext() == context jumping to */
movl 0x20(%esp), %edx
/* third arg of jump_fcontext() == value to be returned after jump */
movl 0x24(%esp), %eax
/* restore ESP (pointing to context-data) from EDX */
movl %edx, %esp
/* test for flag preserve_fpu */
test %ecx, %ecx
je 2f
/* restore MMX control- and status-word */
ldmxcsr (%esp)
/* restore x87 control-word */
fldcw 0x4(%esp)
2:
/* prepare stack for FPU */
leal 0x8(%esp), %esp
popl %edi /* restore EDI */
popl %esi /* restore ESI */
popl %ebx /* restore EBX */
popl %ebp /* restore EBP */
/* restore return-address */
popl %edx
/* use value in EAX as return-value after jump */
/* use value in EAX as first arg in context function */
movl %eax, 0x4(%esp)
/* indirect jump to context */
jmp *%edx
.size jump_fcontext,.-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,85 @@
/*
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 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | EXIT | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl _jump_fcontext
.align 2
_jump_fcontext:
/* fourth arg of jump_fcontext() == flag indicating preserving FPU */
movl 0x10(%esp), %ecx
pushl %ebp /* save EBP */
pushl %ebx /* save EBX */
pushl %esi /* save ESI */
pushl %edi /* save EDI */
/* prepare stack for FPU */
leal -0x8(%esp), %esp
/* test for flag preserve_fpu */
test %ecx, %ecx
je 1f
/* save MMX control- and status-word */
stmxcsr (%esp)
/* save x87 control-word */
fnstcw 0x4(%esp)
1:
/* first arg of jump_fcontext() == context jumping from */
movl 0x1c(%esp), %eax
/* store ESP (pointing to context-data) in EAX */
movl %esp, (%eax)
/* second arg of jump_fcontext() == context jumping to */
movl 0x20(%esp), %edx
/* third arg of jump_fcontext() == value to be returned after jump */
movl 0x24(%esp), %eax
/* restore ESP (pointing to context-data) from EDX */
movl %edx, %esp
/* test for flag preserve_fpu */
test %ecx, %ecx
je 2f
/* restore MMX control- and status-word */
ldmxcsr (%esp)
/* restore x87 control-word */
fldcw 0x4(%esp)
2:
/* prepare stack for FPU */
leal 0x8(%esp), %esp
popl %edi /* restore EDI */
popl %esi /* restore ESI */
popl %ebx /* restore EBX */
popl %ebp /* restore EBP */
/* restore return-address */
popl %edx
/* use value in EAX as return-value after jump */
/* use value in EAX as first arg in context function */
movl %eax, 0x4(%esp)
/* indirect jump to context */
jmp *%edx

View File

@ -0,0 +1,16 @@
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__i386__)
#include "jump_i386_sysv_macho_gas.S"
#elif defined(__x86_64__)
#include "jump_x86_64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -0,0 +1,118 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F20 | F22 | F24 | F26 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F28 | F30 | S0 | S1 | S2 | S3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | | *
* ------------------------------------------------- *
* | S4 | S5 | S6 | S7 | FP | RA | PC | | *
* ------------------------------------------------- *
* *
* *****************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
.ent jump_fcontext
jump_fcontext:
# reserve space on stack
addiu $sp, $sp, -92
sw $s0, 48($sp) # save S0
sw $s1, 52($sp) # save S1
sw $s2, 56($sp) # save S2
sw $s3, 60($sp) # save S3
sw $s4, 64($sp) # save S4
sw $s5, 68($sp) # save S5
sw $s6, 72($sp) # save S6
sw $s7, 76($sp) # save S7
sw $fp, 80($sp) # save FP
sw $ra, 84($sp) # save RA
sw $ra, 88($sp) # save RA as PC
#if defined(__mips_hard_float)
# test if fpu env should be preserved
beqz $a3, 1f
s.d $f20, ($sp) # save F20
s.d $f22, 8($sp) # save F22
s.d $f24, 16($sp) # save F24
s.d $f26, 24($sp) # save F26
s.d $f28, 32($sp) # save F28
s.d $f30, 40($sp) # save F30
1:
#endif
# store SP (pointing to context-data) in A0
sw $sp, ($a0)
# restore SP (pointing to context-data) from A1
move $sp, $a1
#if defined(__mips_hard_float)
# test if fpu env should be preserved
beqz $a3, 2f
l.d $f20, ($sp) # restore F20
l.d $f22, 8($sp) # restore F22
l.d $f24, 16($sp) # restore F24
l.d $f26, 24($sp) # restore F26
l.d $f28, 32($sp) # restore F28
l.d $f30, 40($sp) # restore F30
2:
#endif
lw $s0, 48($sp) # restore S0
lw $s1, 52($sp) # restore S1
lw $s2, 56($sp) # restore S2
lw $s3, 60($sp) # restore S3
lw $s4, 64($sp) # restore S4
lw $s5, 68($sp) # restore S5
lw $s6, 72($sp) # restore S6
lw $s7, 76($sp) # restore S7
lw $fp, 80($sp) # restore FP
lw $ra, 84($sp) # restore RA
# load PC
lw $t9, 88($sp)
# adjust stack
addiu $sp, $sp, 92
# use third arg as return value after jump
move $v0, $a2
# use third arg as first arg in context function
move $a0, $a2
# jump to context
jr $t9
.end jump_fcontext
.size jump_fcontext, .-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,16 @@
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__ppc__)
#include "jump_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "jump_ppc64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -0,0 +1,208 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | 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 | | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | | *
* ------------------------------------------------- *
* | R31 | CR | LR | PC | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl jump_fcontext
.align 2
.type jump_fcontext,@function
jump_fcontext:
# reserve space on stack
subi %r1, %r1, 240
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
# save CR
mfcr %r0
stw %r0, 228(%r1)
# save LR
mflr %r0
stw %r0, 232(%r1)
# save LR as PC
stw %r0, 236(%r1)
# test if fpu env should be preserved
cmpwi cr7, %r6, 0
beq cr7, 1f
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
1:
# store RSP (pointing to context-data) in R3
stw %r1, 0(%r3)
# restore RSP (pointing to context-data) from R4
mr %r1, %r4
# test if fpu env should be preserved
cmpwi cr7, %r6, 0
beq cr7, 2f
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
2:
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
# restore CR
lwz %r0, 228(%r1)
mtcr %r0
# restore LR
lwz %r0, 232(%r1)
mtlr %r0
# load PC
lwz %r0, 236(%r1)
# restore CTR
mtctr %r0
# adjust stack
addi %r1, %r1, 240
# use third arg as return value after jump
# use third arg as first arg in context function
mr %r3, %r5
# jump to context
bctr
.size jump_fcontext, .-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,203 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | 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 | | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | | *
* ------------------------------------------------- *
* | R31 | CR | LR | PC | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _jump_fcontext
.align 2
_jump_fcontext:
; reserve space on stack
subi r1, r1, 240
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
; save CR
mfcr r0
stw r0, 228(r1)
; save LR
mflr r0
stw r0, 232(r1)
; save LR as PC
stw r0, 236(r1)
; test if fpu env should be preserved
cmpwi cr7, r6, 0
beq cr7, l1
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
l1:
; store RSP (pointing to context-data) in R3
stw r1, 0(r3)
; restore RSP (pointing to context-data) from R4
mr r1, r4
; test if fpu env should be preserved
cmpwi cr7, r6, 0
beq cr7, l2
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
l2:
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
; restore CR
lwz r0, 228(r1)
mtcr r0
; restore LR
lwz r0, 232(r1)
mtlr r0
; load PC
lwz r0, 236(r1)
; restore CTR
mtctr r0
; adjust stack
addi r1, r1, 240
; use third arg as return value after jump
; use third arg as first arg in context function
mr r3, r5
; jump to context
bctr

View File

@ -0,0 +1,138 @@
.globl .jump_fcontext
.globl jump_fcontext[DS]
.align 2
.csect jump_fcontext[DS]
jump_fcontext:
.long .jump_fcontext
.jump_fcontext:
# reserve space on stack
subi 1, 1, 240
stw 13, 152(1) # save R13
stw 14, 156(1) # save R14
stw 15, 160(1) # save R15
stw 16, 164(1) # save R16
stw 17, 168(1) # save R17
stw 18, 172(1) # save R18
stw 19, 176(1) # save R19
stw 20, 180(1) # save R20
stw 21, 184(1) # save R21
stw 22, 188(1) # save R22
stw 23, 192(1) # save R23
stw 24, 196(1) # save R24
stw 25, 200(1) # save R25
stw 26, 204(1) # save R26
stw 27, 208(1) # save R27
stw 28, 212(1) # save R28
stw 29, 216(1) # save R29
stw 30, 220(1) # save R30
stw 31, 224(1) # save R31
# save CR
mfcr 0
stw 0, 228(1)
# save LR
mflr 0
stw 0, 232(1)
# save LR as PC
stw 0, 236(1)
# test if fpu env should be preserved
cmpwi 7, 6, 0
beq 7, label1
stfd 14, 0(1) # save F14
stfd 15, 8(1) # save F15
stfd 16, 16(1) # save F16
stfd 17, 24(1) # save F17
stfd 18, 32(1) # save F18
stfd 19, 40(1) # save F19
stfd 20, 48(1) # save F20
stfd 21, 56(1) # save F21
stfd 22, 64(1) # save F22
stfd 23, 72(1) # save F23
stfd 24, 80(1) # save F24
stfd 25, 88(1) # save F25
stfd 26, 96(1) # save F26
stfd 27, 104(1) # save F27
stfd 28, 112(1) # save F28
stfd 29, 120(1) # save F29
stfd 30, 128(1) # save F30
stfd 31, 136(1) # save F31
mffs 0 # load FPSCR
stfd 0, 144(1) # save FPSCR
label1:
# store RSP (pointing to context-data) in R3
stw 1, 0(3)
# restore RSP (pointing to context-data) from R4
mr 1, 4
# test if fpu env should be preserved
cmpwi 7, 6, 0
beq 7, label2
lfd 14, 0(1) # restore F14
lfd 15, 8(1) # restore F15
lfd 16, 16(1) # restore F16
lfd 17, 24(1) # restore F17
lfd 18, 32(1) # restore F18
lfd 19, 40(1) # restore F19
lfd 20, 48(1) # restore F20
lfd 21, 56(1) # restore F21
lfd 22, 64(1) # restore F22
lfd 23, 72(1) # restore F23
lfd 24, 80(1) # restore F24
lfd 25, 88(1) # restore F25
lfd 26, 96(1) # restore F26
lfd 27, 104(1) # restore F27
lfd 28, 112(1) # restore F28
lfd 29, 120(1) # restore F29
lfd 30, 128(1) # restore F30
lfd 31, 136(1) # restore F31
lfd 0, 144(1) # load FPSCR
mtfsf 0xff, 0 # restore FPSCR
label2:
lwz 13, 152(1) # restore R13
lwz 14, 156(1) # restore R14
lwz 15, 160(1) # restore R15
lwz 16, 164(1) # restore R16
lwz 17, 168(1) # restore R17
lwz 18, 172(1) # restore R18
lwz 19, 176(1) # restore R19
lwz 20, 180(1) # restore R20
lwz 21, 184(1) # restore R21
lwz 22, 188(1) # restore R22
lwz 23, 192(1) # restore R23
lwz 24, 196(1) # restore R24
lwz 25, 200(1) # restore R25
lwz 26, 204(1) # restore R26
lwz 27, 208(1) # restore R27
lwz 28, 212(1) # restore R28
lwz 29, 216(1) # restore R29
lwz 30, 220(1) # restore R30
lwz 31, 224(1) # restore R31
# restore CR
lwz 0, 228(1)
mtcr 0
# restore LR
lwz 0, 232(1)
mtlr 0
# load PC
lwz 0, 236(1)
# restore CTR
mtctr 0
# adjust stack
addi 1, 1, 240
# use third arg as return value after jump
# use third arg as first arg in context function
mr 3, 5
# jump to context
bctr

View File

@ -0,0 +1,267 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | TOC | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R14 | R15 | R16 | R17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R18 | R19 | R20 | R21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R22 | R23 | R24 | R25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | *
* ------------------------------------------------- *
* | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | *
* ------------------------------------------------- *
* | R26 | R27 | R28 | R29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | *
* ------------------------------------------------- *
* | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | R30 | R31 | CR | LR | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 80 | 81 | | *
* ------------------------------------------------- *
* | 320 | 324 | | *
* ------------------------------------------------- *
* | PC | | *
* ------------------------------------------------- *
* *
*******************************************************/
.globl jump_fcontext
#if _CALL_ELF == 2
.text
.align 2
jump_fcontext:
addis %r2, %r12, .TOC.-jump_fcontext@ha
addi %r2, %r2, .TOC.-jump_fcontext@l
.localentry jump_fcontext, . - jump_fcontext
#else
.section ".opd","aw"
.align 3
jump_fcontext:
# ifdef _CALL_LINUX
.quad .L.jump_fcontext,.TOC.@tocbase,0
.type jump_fcontext,@function
.text
.align 2
.L.jump_fcontext:
# else
.hidden .jump_fcontext
.globl .jump_fcontext
.quad .jump_fcontext,.TOC.@tocbase,0
.size jump_fcontext,24
.type .jump_fcontext,@function
.text
.align 2
.jump_fcontext:
# endif
#endif
# reserve space on stack
subi %r1, %r1, 328
#if _CALL_ELF != 2
std %r2, 152(%r1) # save TOC
#endif
std %r14, 160(%r1) # save R14
std %r15, 168(%r1) # save R15
std %r16, 176(%r1) # save R16
std %r17, 184(%r1) # save R17
std %r18, 192(%r1) # save R18
std %r19, 200(%r1) # save R19
std %r20, 208(%r1) # save R20
std %r21, 216(%r1) # save R21
std %r22, 224(%r1) # save R22
std %r23, 232(%r1) # save R23
std %r24, 240(%r1) # save R24
std %r25, 248(%r1) # save R25
std %r26, 256(%r1) # save R26
std %r27, 264(%r1) # save R27
std %r28, 272(%r1) # save R28
std %r29, 280(%r1) # save R29
std %r30, 288(%r1) # save R30
std %r31, 296(%r1) # save R31
# save CR
mfcr %r0
std %r0, 304(%r1)
# save LR
mflr %r0
std %r0, 312(%r1)
# save LR as PC
std %r0, 320(%r1)
# test if fpu env should be preserved
cmpwi cr7, %r6, 0
beq cr7, 1f
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
1:
# store RSP (pointing to context-data) in R3
std %r1, 0(%r3)
# restore RSP (pointing to context-data) from R4
mr %r1, %r4
# test if fpu env should be preserved
cmpwi cr7, %r6, 0
beq cr7, 2f
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
2:
#if _CALL_ELF != 2
ld %r2, 152(%r1) # restore TOC
#endif
ld %r14, 160(%r1) # restore R14
ld %r15, 168(%r1) # restore R15
ld %r16, 176(%r1) # restore R16
ld %r17, 184(%r1) # restore R17
ld %r18, 192(%r1) # restore R18
ld %r19, 200(%r1) # restore R19
ld %r20, 208(%r1) # restore R20
ld %r21, 216(%r1) # restore R21
ld %r22, 224(%r1) # restore R22
ld %r23, 232(%r1) # restore R23
ld %r24, 240(%r1) # restore R24
ld %r25, 248(%r1) # restore R25
ld %r26, 256(%r1) # restore R26
ld %r27, 264(%r1) # restore R27
ld %r28, 272(%r1) # restore R28
ld %r29, 280(%r1) # restore R29
ld %r30, 288(%r1) # restore R30
ld %r31, 296(%r1) # restore R31
# restore CR
ld %r0, 304(%r1)
mtcr %r0
# restore LR
ld %r0, 312(%r1)
mtlr %r0
# load PC
ld %r12, 320(%r1)
# restore CTR
mtctr %r12
# adjust stack
addi %r1, %r1, 328
# use third arg as return value after jump
# use third arg as first arg in context function
mr %r3, %r5
# jump to context
bctr
#if _CALL_ELF == 2
.size jump_fcontext, .-jump_fcontext
#else
# ifdef _CALL_LINUX
.size .jump_fcontext, .-.L.jump_fcontext
# else
.size .jump_fcontext, .-.jump_fcontext
# endif
#endif
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,226 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | R13 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R14 | R15 | R16 | R17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R18 | R19 | R20 | R21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R22 | R23 | R24 | R25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | *
* ------------------------------------------------- *
* | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | *
* ------------------------------------------------- *
* | R26 | R27 | R28 | R29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | *
* ------------------------------------------------- *
* | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | R30 | R31 | CR | LR | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 80 | 81 | | *
* ------------------------------------------------- *
* | 320 | 324 | | *
* ------------------------------------------------- *
* | PC | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.align 2
.globl jump_fcontext
_jump_fcontext:
; reserve space on stack
subi r1, r1, 328
std r13, 152(r1) ; save R13
std r14, 160(r1) ; save R14
std r15, 168(r1) ; save R15
std r16, 176(r1) ; save R16
std r17, 184(r1) ; save R17
std r18, 192(r1) ; save R18
std r19, 200(r1) ; save R19
std r20, 208(r1) ; save R20
std r21, 216(r1) ; save R21
std r22, 224(r1) ; save R22
std r23, 232(r1) ; save R23
std r24, 240(r1) ; save R24
std r25, 248(r1) ; save R25
std r26, 256(r1) ; save R26
std r27, 264(r1) ; save R27
std r28, 272(r1) ; save R28
std r29, 280(r1) ; save R29
std r30, 288(r1) ; save R30
std r31, 296(r1) ; save R31
; save CR
mfcr r0
std r0, 304(r1)
; save LR
mflr r0
std r0, 312(r1)
; save LR as PC
std r0, 320(r1)
; test if fpu env should be preserved
cmpwi cr7, r6, 0
beq cr7, l1
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
l1:
; store RSP (pointing to context-data) in R3
stw r1, 0(r3)
; restore RSP (pointing to context-data) from R4
mr r1, r4
; test if fpu env should be preserved
cmpwi cr7, r6, 0
beq cr7, l2
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
2:
ld r13, 152(r1) ; restore R13
ld r14, 160(r1) ; restore R14
ld r15, 168(r1) ; restore R15
ld r16, 176(r1) ; restore R16
ld r17, 184(r1) ; restore R17
ld r18, 192(r1) ; restore R18
ld r19, 200(r1) ; restore R19
ld r20, 208(r1) ; restore R20
ld r21, 216(r1) ; restore R21
ld r22, 224(r1) ; restore R22
ld r23, 232(r1) ; restore R23
ld r24, 240(r1) ; restore R24
ld r25, 248(r1) ; restore R25
ld r26, 256(r1) ; restore R26
ld r27, 264(r1) ; restore R27
ld r28, 272(r1) ; restore R28
ld r29, 280(r1) ; restore R29
ld r30, 288(r1) ; restore R30
ld r31, 296(r1) ; restore R31
; restore CR
ld r0, 304(r1)
mtcr r0
; restore LR
ld r0, 312(r1)
mtlr r0
; load PC
ld r0, 320(r1)
; restore CTR
mtctr r0
; adjust stack
addi r1, r1, 328
; use third arg as return value after jump
; use third arg as first arg in context function
mr r3, r5
; jump to context
bctr

View File

@ -0,0 +1,134 @@
.align 2
.globl .jump_fcontext
.jump_fcontext:
# reserve space on stack
subi 1, 1, 328
std 13, 152(1) # save R13
std 14, 160(1) # save R14
std 15, 168(1) # save R15
std 16, 176(1) # save R16
std 17, 184(1) # save R17
std 18, 192(1) # save R18
std 19, 200(1) # save R19
std 20, 208(1) # save R20
std 21, 216(1) # save R21
std 22, 224(1) # save R22
std 23, 232(1) # save R23
std 24, 240(1) # save R24
std 25, 248(1) # save R25
std 26, 256(1) # save R26
std 27, 264(1) # save R27
std 28, 272(1) # save R28
std 29, 280(1) # save R29
std 30, 288(1) # save R30
std 31, 296(1) # save R31
# save CR
mfcr 0
std 0, 304(1)
# save LR
mflr 0
std 0, 312(1)
# save LR as PC
std 0, 320(1)
# test if fpu env should be preserved
cmpwi 7, 6, 0
beq 7, label1
stfd 14, 0(1) # save F14
stfd 15, 8(1) # save F15
stfd 16, 16(1) # save F16
stfd 17, 24(1) # save F17
stfd 18, 32(1) # save F18
stfd 19, 40(1) # save F19
stfd 20, 48(1) # save F20
stfd 21, 56(1) # save F21
stfd 22, 64(1) # save F22
stfd 23, 72(1) # save F23
stfd 24, 80(1) # save F24
stfd 25, 88(1) # save F25
stfd 26, 96(1) # save F26
stfd 27, 104(1) # save F27
stfd 28, 112(1) # save F28
stfd 29, 120(1) # save F29
stfd 30, 128(1) # save F30
stfd 31, 136(1) # save F31
mffs 0 # load FPSCR
stfd 0, 144(1) # save FPSCR
label1:
# store RSP (pointing to context-data) in R3
stw 1, 0(3)
# restore RSP (pointing to context-data) from R4
mr 1, 4
# test if fpu env should be preserved
cmpwi 7, 6, 0
beq 7, label2
lfd 14, 0(1) # restore F14
lfd 15, 8(1) # restore F15
lfd 16, 16(1) # restore F16
lfd 17, 24(1) # restore F17
lfd 18, 32(1) # restore F18
lfd 19, 40(1) # restore F19
lfd 20, 48(1) # restore F20
lfd 21, 56(1) # restore F21
lfd 22, 64(1) # restore F22
lfd 23, 72(1) # restore F23
lfd 24, 80(1) # restore F24
lfd 25, 88(1) # restore F25
lfd 26, 96(1) # restore F26
lfd 27, 104(1) # restore F27
lfd 28, 112(1) # restore F28
lfd 29, 120(1) # restore F29
lfd 30, 128(1) # restore F30
lfd 31, 136(1) # restore F31
lfd 0, 144(1) # load FPSCR
mtfsf 0xff, 0 # restore FPSCR
label2:
ld 13, 152(1) # restore R13
ld 14, 160(1) # restore R14
ld 15, 168(1) # restore R15
ld 16, 176(1) # restore R16
ld 17, 184(1) # restore R17
ld 18, 192(1) # restore R18
ld 19, 200(1) # restore R19
ld 20, 208(1) # restore R20
ld 21, 216(1) # restore R21
ld 22, 224(1) # restore R22
ld 23, 232(1) # restore R23
ld 24, 240(1) # restore R24
ld 25, 248(1) # restore R25
ld 26, 256(1) # restore R26
ld 27, 264(1) # restore R27
ld 28, 272(1) # restore R28
ld 29, 280(1) # restore R29
ld 30, 288(1) # restore R30
ld 31, 296(1) # restore R31
# restore CR
ld 0, 304(1)
mtcr 0
# restore LR
ld 0, 312(1)
mtlr 0
# load PC
ld 0, 320(1)
# restore CTR
mtctr 0
# adjust stack
addi 1, 1, 328
# use third arg as return value after jump
# use third arg as first arg in context function
mr 3, 5
# jump to context
bctr

View File

@ -0,0 +1,139 @@
/*
Copyright Martin Husemann 2013.
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)
*/
/*******************************************************************
* *
* ------------------------------------------------------------- *
* | Offset (in 4 or 8 byte units) | Content | *
* ------------------------------------------------------------- *
* | 0 | %sp | *
* ------------------------------------------------------------- *
* | 1 | %pc | *
* ------------------------------------------------------------- *
* | 2 | %i7 (return address) | *
* ------------------------------------------------------------- *
* | 3 | %g1 | *
* ------------------------------------------------------------- *
* | 4 | %g2 | *
* ------------------------------------------------------------- *
* | 5 | %g3 | *
* ------------------------------------------------------------- *
* | 6 | %g6 | *
* ------------------------------------------------------------- *
* | 7 | %g7 | *
* ------------------------------------------------------------- *
* The local and in registers are stored on the stack. *
*******************************************************************/
#define OFF(N) (8*(N))
#define CCFSZ 176 // C Compiler Frame Size
#define BIAS (2048-1) // Stack offset for 64 bit programs
#define FC_SZ 448 // sizeof(fcontext_t)
#define FC_STK 384 // offsetof(fcontext_t, fc_stack)
#define FC_FPU 0 // offsetof(fcontext_t, fc_fp)
#define FC_FSR 264 // offsetof(fcontext_t, fc_fp.fp_fsr)
#define FC_FPRS 256 // offsetof(fcontext_t, fc_fp.fp_fprs)
#define FC_GREG 320 // offsetof(fcontext_t, fc_greg)
#define BLOCK_SIZE 64
.register %g2,#ignore
.register %g3,#ignore
.register %g6,#ignore
.text
.globl jump_fcontext
.align 4
.type jump_fcontext,@function
// intptr_t
// jump_fcontext( fcontext_t * ofc, fcontext_t const* nfc, intptr_t vp,
// bool preserve_fpu = true);
jump_fcontext:
// %o0 = pointer to old fcontext, save current state here
// %o1 = new context to jump to
// %o2 = new return value in context %o0
// %o3 = preserve fpu registers
// Save current state in %o0 fcontext, then activate %o1.
// If %o3, include fpu registers.
flushw // make sure all shadow registers are up to date in the current stack
// save current state to fcontext_t at %o0
stx %sp, [%o0 + FC_GREG + OFF(0)] // current stack pointer
add %o7, 8, %o4 // calculate next instruction past call
stx %o4, [%o0 + FC_GREG + OFF(1)] // and store it as %pc in save context
stx %o7, [%o0 + FC_GREG + OFF(2)]
stx %g1, [%o0 + FC_GREG + OFF(3)]
stx %g2, [%o0 + FC_GREG + OFF(4)]
stx %g3, [%o0 + FC_GREG + OFF(5)]
stx %g6, [%o0 + FC_GREG + OFF(6)]
stx %g7, [%o0 + FC_GREG + OFF(7)]
// do we need to handle fpu?
brz %o3, Lno_fpu
nop
add %o0, FC_FPU, %o5
stda %f0, [%o5] 0xf0 /* ASI_BLOCK_PRIMARY */
add %o5, BLOCK_SIZE, %o5
stda %f16, [%o5] 0xf0
add %o5, BLOCK_SIZE, %o5
stda %f32, [%o5] 0xf0
add %o5, BLOCK_SIZE, %o5
stda %f48, [%o5] 0xf0
stx %fsr, [%o0+FC_FSR]
rd %fprs, %o4
stx %o4, [%o0+FC_FPRS]
add %o1, FC_FPU, %o5
ldda [%o5] 0xf0 /* ASI_BLOCK_PRIMARY */, %f0
add %o5, BLOCK_SIZE, %o5
ldda [%o5] 0xf0, %f16
add %o5, BLOCK_SIZE, %o5
ldda [%o5] 0xf0, %f32
add %o5, BLOCK_SIZE, %o5
ldda [%o5] 0xf0, %f48
ldx [%o1+FC_FSR], %fsr
ldx [%o1+FC_FPRS], %o4
wr %o4,0,%fprs
Lno_fpu:
// load new state from %o1
ldx [%o1 + FC_GREG + OFF(1)], %o4
ldx [%o1 + FC_GREG + OFF(2)], %o7
ldx [%o1 + FC_GREG + OFF(3)], %g1
ldx [%o1 + FC_GREG + OFF(4)], %g2
ldx [%o1 + FC_GREG + OFF(5)], %g3
ldx [%o1 + FC_GREG + OFF(6)], %g6
ldx [%o1 + FC_GREG + OFF(7)], %g7
// switch to new stack
ldx [%o1 + FC_GREG + OFF(0)], %sp
// and now reload from this stack the shadow regist bank contents
ldx [%sp + BIAS + OFF(0)], %l0
ldx [%sp + BIAS + OFF(1)], %l1
ldx [%sp + BIAS + OFF(2)], %l2
ldx [%sp + BIAS + OFF(3)], %l3
ldx [%sp + BIAS + OFF(4)], %l4
ldx [%sp + BIAS + OFF(5)], %l5
ldx [%sp + BIAS + OFF(6)], %l6
ldx [%sp + BIAS + OFF(7)], %l7
ldx [%sp + BIAS + OFF(8)], %i0
ldx [%sp + BIAS + OFF(9)], %i1
ldx [%sp + BIAS + OFF(10)], %i2
ldx [%sp + BIAS + OFF(11)], %i3
ldx [%sp + BIAS + OFF(12)], %i4
ldx [%sp + BIAS + OFF(13)], %i5
ldx [%sp + BIAS + OFF(14)], %i6
ldx [%sp + BIAS + OFF(15)], %i7
// finally continue execution in new context
jmp %o4
mov %o2, %o0 // return arg as result
.size jump_fcontext,.-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,135 @@
/*
Copyright Martin Husemann 2013.
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)
*/
/*******************************************************************
* *
* ------------------------------------------------------------- *
* | Offset (in 4 or 8 byte units) | Content | *
* ------------------------------------------------------------- *
* | 0 | %sp | *
* ------------------------------------------------------------- *
* | 1 | %pc | *
* ------------------------------------------------------------- *
* | 2 | %i7 (return address) | *
* ------------------------------------------------------------- *
* | 3 | %g1 | *
* ------------------------------------------------------------- *
* | 4 | %g2 | *
* ------------------------------------------------------------- *
* | 5 | %g3 | *
* ------------------------------------------------------------- *
* | 6 | %g6 | *
* ------------------------------------------------------------- *
* | 7 | %g7 | *
* ------------------------------------------------------------- *
* The local and in registers are stored on the stack. *
*******************************************************************/
#define OFF(N) (4*(N))
#define CCFSZ 96
#define FC_SZ 176
#define FC_stK 168 // offsetof(fcontext_t, fc_stack)
#define FC_FPU 0 // offsetof(fcontext_t, fc_fp)
#define FC_FSR 128 // offsetof(fcontext_t, fc_fp.fp_fsr)
#define FC_GREG 136 // offsetof(fcontext_t, fc_greg)
#define BLOCK_SIZE 8
#ifdef __NetBSD__
#define FLUSHW t 0x83; nop // T_FLUSHWIN
#endif
.text
.globl jump_fcontext
.align 4
.type jump_fcontext,@function
// intptr_t
// jump_fcontext( fcontext_t * ofc, fcontext_t const* nfc, intptr_t vp,
// bool preserve_fpu = true);
jump_fcontext:
// %o0 = pointer to old fcontext, save current state here
// %o1 = new context to jump to
// %o2 = new return value in context %o0
// %o3 = preserve fpu registers
// Save current state in %o0 fcontext, then activate %o1.
// If %o3, include fpu registers.
FLUSHW // make sure all shadow registers are up to date in the current stack
// save current state to fcontext_t at %o0
st %sp, [%o0 + FC_GREG + OFF(0)] // current stack pointer
add %o7, 8, %o4 // calculate next instruction past call
st %o4, [%o0 + FC_GREG + OFF(1)] // and store it as %pc in save context
st %o7, [%o0 + FC_GREG + OFF(2)]
st %g1, [%o0 + FC_GREG + OFF(3)]
st %g2, [%o0 + FC_GREG + OFF(4)]
st %g3, [%o0 + FC_GREG + OFF(5)]
st %g6, [%o0 + FC_GREG + OFF(6)]
st %g7, [%o0 + FC_GREG + OFF(7)]
// do we need to handle fpu?
cmp %o3, 0
bz Lno_fpu
nop
add %o0, FC_FPU, %o5
std %f0, [%o5]
std %f2, [%o5+0x08]
std %f4, [%o5+0x10]
std %f6, [%o5+0x18]
std %f8, [%o5+0x20]
std %f10, [%o5+0x28]
std %f12, [%o5+0x30]
std %f14, [%o5+0x38]
st %fsr, [%o0+FC_FSR]
add %o1, FC_FPU, %o5
ldd [%o5], %f0
ldd [%o5+0x08], %f2
ldd [%o5+0x10], %f4
ldd [%o5+0x18], %f6
ldd [%o5+0x20], %f8
ldd [%o5+0x28], %f10
ldd [%o5+0x30], %f12
ldd [%o5+0x38], %f14
ld [%o1+FC_FSR], %fsr
Lno_fpu:
// load new state from %o1
ld [%o1 + FC_GREG + OFF(1)], %o4
ld [%o1 + FC_GREG + OFF(2)], %o7
ld [%o1 + FC_GREG + OFF(3)], %g1
ld [%o1 + FC_GREG + OFF(4)], %g2
ld [%o1 + FC_GREG + OFF(5)], %g3
ld [%o1 + FC_GREG + OFF(6)], %g6
ld [%o1 + FC_GREG + OFF(7)], %g7
// switch to new stack
ld [%o1 + FC_GREG + OFF(0)], %sp
// and now reload from this stack the shadow regist bank contents
ld [%sp + OFF(0)], %l0
ld [%sp + OFF(1)], %l1
ld [%sp + OFF(2)], %l2
ld [%sp + OFF(3)], %l3
ld [%sp + OFF(4)], %l4
ld [%sp + OFF(5)], %l5
ld [%sp + OFF(6)], %l6
ld [%sp + OFF(7)], %l7
ld [%sp + OFF(8)], %i0
ld [%sp + OFF(9)], %i1
ld [%sp + OFF(10)], %i2
ld [%sp + OFF(11)], %i3
ld [%sp + OFF(12)], %i4
ld [%sp + OFF(13)], %i5
ld [%sp + OFF(14)], %i6
ld [%sp + OFF(15)], %i7
// finally continue execution in new context
jmp %o4
mov %o2, %o0 // return arg as result
.size jump_fcontext,.-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,225 @@
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
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 | |
* ----------------------------------------------------------------------------------
* | 0x0 | 0x4 | |
* ----------------------------------------------------------------------------------
* | <indicator> | |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
* ----------------------------------------------------------------------------------
* | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | 0x20 | 0x24 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
* ----------------------------------------------------------------------------------
* | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | 0x40 | 0x44 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
* ----------------------------------------------------------------------------------
* | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
* ----------------------------------------------------------------------------------
* | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
* ----------------------------------------------------------------------------------
* | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
* ----------------------------------------------------------------------------------
* | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 |
* ----------------------------------------------------------------------------------
* | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
* ----------------------------------------------------------------------------------
* | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 |
* ----------------------------------------------------------------------------------
* | limit | base | R12 | R13 |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
* ----------------------------------------------------------------------------------
* | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 |
* ----------------------------------------------------------------------------------
* | R14 | R15 | RDI | RSI |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
* ----------------------------------------------------------------------------------
* | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 |
* ----------------------------------------------------------------------------------
* | RBX | RBP | RIP | EXIT |
* ----------------------------------------------------------------------------------
* *
* *************************************************************************************/
.file "jump_x86_64_ms_pe_gas.asm"
.text
.p2align 4,,15
.globl jump_fcontext
.def jump_fcontext; .scl 2; .type 32; .endef
.seh_proc jump_fcontext
jump_fcontext:
.seh_endprologue
pushq %rbp /* save RBP */
pushq %rbx /* save RBX */
pushq %rsi /* save RSI */
pushq %rdi /* save RDI */
pushq %r15 /* save R15 */
pushq %r14 /* save R14 */
pushq %r13 /* save R13 */
pushq %r12 /* save R12 */
/* load NT_TIB */
movq %gs:(0x30), %r10
/* save current stack base */
movq 0x08(%r10), %rax
pushq %rax
/* save current stack limit */
movq 0x10(%r10), %rax
pushq %rax
/* save current deallocation stack */
movq 0x1478(%r10), %rax
pushq %rax
/* save fiber local storage */
movq 0x18(%r10), %rax
pushq %rax
/* prepare stack for FPU */
leaq -0xa8(%rsp), %rsp
/* test for flag preserve_fpu */
testq %r9, %r9
je 1f
/* save MMX control- and status-word */
stmxcsr 0xa0(%rsp)
/* save x87 control-word */
fnstcw 0xa4(%rsp)
/* save XMM storage */
movaps %xmm6, (%rsp)
movaps %xmm7, 0x10(%rsp)
movaps %xmm8, 0x20(%rsp)
movaps %xmm9, 0x30(%rsp)
movaps %xmm10, 0x40(%rsp)
movaps %xmm11, 0x50(%rsp)
movaps %xmm12, 0x60(%rsp)
movaps %xmm13, 0x70(%rsp)
movaps %xmm14, 0x80(%rsp)
movaps %xmm15, 0x90(%rsp)
1:
/* set R10 to zero */
xorq %r10, %r10
/* set indicator */
pushq %r10
/* store RSP (pointing to context-data) in RCX */
movq %rsp, (%rcx)
/* restore RSP (pointing to context-data) from RDX */
movq %rdx, %rsp
/* load indicator */
popq %r10
/* test for flag preserve_fpu */
testq %r9, %r9
je 2f
/* restore MMX control- and status-word */
ldmxcsr 0xa0(%rsp)
/* save x87 control-word */
fldcw 0xa4(%rsp)
/* restore XMM storage */
movaps (%rsp), %xmm6
movaps 0x10(%rsp), %xmm7
movaps 0x20(%rsp), %xmm8
movaps 0x30(%rsp), %xmm9
movaps 0x40(%rsp), %xmm10
movaps 0x50(%rsp), %xmm11
movaps 0x60(%rsp), %xmm12
movaps 0x70(%rsp), %xmm13
movaps 0x80(%rsp), %xmm14
movaps 0x90(%rsp), %xmm15
2:
/* set offset of stack */
movq 0xa8, %rcx
/* test for indicator */
testq %r10, %r10
je 3f
addq 0x8, %rcx
3:
/* prepare stack for FPU */
leaq (%rsp,%rcx), %rsp
/* load NT_TIB */
movq %gs:(0x30), %r10
/* restore fiber local storage */
popq %rax
movq %rax, 0x18(%r10)
/* restore deallocation stack */
popq %rax
movq %rax, 0x1478(%r10)
/* restore stack limit */
popq %rax
movq %rax, 0x10(%r10)
/* restore stack base */
popq %rax
movq %rax, 0x8(%r10)
popq %r12 /* restore R12 */
popq %r13 /* restore R13 */
popq %r14 /* restore R14 */
popq %r15 /* restore R15 */
popq %rdi /* restore RDI */
popq %rsi /* restore RSI */
popq %rbx /* restore RBX */
popq %rbp /* restore RBP */
/* restore return-address */
popq %r10
/* use third arg as return-value after jump */
movq %r8, %rax
/* use third arg as first arg in context function */
movq %r8, %rcx
/* indirect jump to context */
jmp *%r10
.seh_endproc

View File

@ -0,0 +1,216 @@
; 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 | |
; ----------------------------------------------------------------------------------
; | 0x0 | 0x4 | |
; ----------------------------------------------------------------------------------
; | <indicator> | |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
; ----------------------------------------------------------------------------------
; | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | 0x20 | 0x24 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
; ----------------------------------------------------------------------------------
; | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | 0x40 | 0x44 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
; ----------------------------------------------------------------------------------
; | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
; ----------------------------------------------------------------------------------
; | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
; ----------------------------------------------------------------------------------
; | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
; ----------------------------------------------------------------------------------
; | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 |
; ----------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
; ----------------------------------------------------------------------------------
; | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 |
; ----------------------------------------------------------------------------------
; | limit | base | R12 | R13 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
; ----------------------------------------------------------------------------------
; | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 |
; ----------------------------------------------------------------------------------
; | R14 | R15 | RDI | RSI |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
; ----------------------------------------------------------------------------------
; | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 |
; ----------------------------------------------------------------------------------
; | RBX | RBP | RIP | EXIT |
; ----------------------------------------------------------------------------------
.code
jump_fcontext PROC BOOST_CONTEXT_EXPORT FRAME
.endprolog
push rbp ; save RBP
push rbx ; save RBX
push rsi ; save RSI
push rdi ; save RDI
push r15 ; save R15
push r14 ; save R14
push r13 ; save R13
push r12 ; save R12
; load NT_TIB
mov r10, gs:[030h]
; save current stack base
mov rax, [r10+08h]
push rax
; save current stack limit
mov rax, [r10+010h]
push rax
; save current deallocation stack
mov rax, [r10+01478h]
push rax
; save fiber local storage
mov rax, [r10+018h]
push rax
; prepare stack for FPU
lea rsp, [rsp-0a8h]
; test for flag preserve_fpu
test r9, r9
je nxt1
; save MMX control- and status-word
stmxcsr [rsp+0a0h]
; save x87 control-word
fnstcw [rsp+0a4h]
; save XMM storage
movaps [rsp], xmm6
movaps [rsp+010h], xmm7
movaps [rsp+020h], xmm8
movaps [rsp+030h], xmm9
movaps [rsp+040h], xmm10
movaps [rsp+050h], xmm11
movaps [rsp+060h], xmm12
movaps [rsp+070h], xmm13
movaps [rsp+080h], xmm14
movaps [rsp+090h], xmm15
nxt1:
; set R10 to zero
xor r10, r10
; set indicator
push r10
; store RSP (pointing to context-data) in RCX
mov [rcx], rsp
; restore RSP (pointing to context-data) from RDX
mov rsp, rdx
; load indicator
pop r10
; test for flag preserve_fpu
test r9, r9
je nxt2
; restore MMX control- and status-word
ldmxcsr [rsp+0a0h]
; save x87 control-word
fldcw [rsp+0a4h]
; restore XMM storage
movaps xmm6, [rsp]
movaps xmm7, [rsp+010h]
movaps xmm8, [rsp+020h]
movaps xmm9, [rsp+030h]
movaps xmm10, [rsp+040h]
movaps xmm11, [rsp+050h]
movaps xmm12, [rsp+060h]
movaps xmm13, [rsp+070h]
movaps xmm14, [rsp+080h]
movaps xmm15, [rsp+090h]
nxt2:
; set offset of stack
mov rcx, 0a8h
; test for indicator
test r10, r10
je nxt3
add rcx, 08h
nxt3:
; prepare stack for FPU
lea rsp, [rsp+rcx]
; load NT_TIB
mov r10, gs:[030h]
; restore fiber local storage
pop rax
mov [r10+018h], rax
; restore deallocation stack
pop rax
mov [r10+01478h], rax
; restore stack limit
pop rax
mov [r10+010h], rax
; restore stack base
pop rax
mov [r10+08h], rax
pop r12 ; restore R12
pop r13 ; restore R13
pop r14 ; restore R14
pop r15 ; restore R15
pop rdi ; restore RDI
pop rsi ; restore RSI
pop rbx ; restore RBX
pop rbp ; restore RBP
; restore return-address
pop r10
; use third arg as return-value after jump
mov rax, r8
; use third arg as first arg in context function
mov rcx, r8
; indirect jump to context
jmp r10
jump_fcontext ENDP
END

View File

@ -0,0 +1,98 @@
/*
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 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBX | RBP | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | | *
* ---------------------------------------------------------------------------------- *
* | 0x40 | 0x44 | | *
* ---------------------------------------------------------------------------------- *
* | EXIT | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl jump_fcontext
.type jump_fcontext,@function
.align 16
jump_fcontext:
pushq %rbp /* save RBP */
pushq %rbx /* save RBX */
pushq %r15 /* save R15 */
pushq %r14 /* save R14 */
pushq %r13 /* save R13 */
pushq %r12 /* save R12 */
/* prepare stack for FPU */
leaq -0x8(%rsp), %rsp
/* test for flag preserve_fpu */
cmp $0, %rcx
je 1f
/* save MMX control- and status-word */
stmxcsr (%rsp)
/* save x87 control-word */
fnstcw 0x4(%rsp)
1:
/* store RSP (pointing to context-data) in RDI */
movq %rsp, (%rdi)
/* restore RSP (pointing to context-data) from RSI */
movq %rsi, %rsp
/* test for flag preserve_fpu */
cmp $0, %rcx
je 2f
/* restore MMX control- and status-word */
ldmxcsr (%rsp)
/* restore x87 control-word */
fldcw 0x4(%rsp)
2:
/* prepare stack for FPU */
leaq 0x8(%rsp), %rsp
popq %r12 /* restrore R12 */
popq %r13 /* restrore R13 */
popq %r14 /* restrore R14 */
popq %r15 /* restrore R15 */
popq %rbx /* restrore RBX */
popq %rbp /* restrore RBP */
/* restore return-address */
popq %r8
/* use third arg as return-value after jump */
movq %rdx, %rax
/* use third arg as first arg in context function */
movq %rdx, %rdi
/* indirect jump to context */
jmp *%r8
.size jump_fcontext,.-jump_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,93 @@
/*
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 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBX | RBP | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | | *
* ---------------------------------------------------------------------------------- *
* | 0x40 | 0x44 | | *
* ---------------------------------------------------------------------------------- *
* | EXIT | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl _jump_fcontext
.align 8
_jump_fcontext:
pushq %rbp /* save RBP */
pushq %rbx /* save RBX */
pushq %r15 /* save R15 */
pushq %r14 /* save R14 */
pushq %r13 /* save R13 */
pushq %r12 /* save R12 */
/* prepare stack for FPU */
leaq -0x8(%rsp), %rsp
/* test for flag preserve_fpu */
cmp $0, %rcx
je 1f
/* save MMX control- and status-word */
stmxcsr (%rsp)
/* save x87 control-word */
fnstcw 0x4(%rsp)
1:
/* store RSP (pointing to context-data) in RDI */
movq %rsp, (%rdi)
/* restore RSP (pointing to context-data) from RSI */
movq %rsi, %rsp
/* test for flag preserve_fpu */
cmp $0, %rcx
je 2f
/* restore MMX control- and status-word */
ldmxcsr (%rsp)
/* restore x87 control-word */
fldcw 0x4(%rsp)
2:
/* prepare stack for FPU */
leaq 0x8(%rsp), %rsp
popq %r12 /* restrore R12 */
popq %r13 /* restrore R13 */
popq %r14 /* restrore R14 */
popq %r15 /* restrore R15 */
popq %rbx /* restrore RBX */
popq %rbp /* restrore RBP */
/* restore return-address */
popq %r8
/* use third arg as return-value after jump */
movq %rdx, %rax
/* use third arg as first arg in context function */
movq %rdx, %rdi
/* indirect jump to context */
jmp *%r8

View File

@ -0,0 +1,85 @@
/*
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:
# shift address in x0 (allocated stack) to lower 16 byte boundary
and x0, x0, ~0xF
# reserve space for context-data on context-stack
sub x0, x0, #0xb0
# third arg of make_fcontext() == address of context-function
# store address as a PC to jump in
str x2, [x0, #0xa0]
# save address of finish as return-address for context-function
# will be entered after context-function returns (LR register)
adr x1, finish
str x1, [x0, #0x98]
ret x30 // return pointer to context-data (x0)
finish:
# exit code is zero
mov x0, #0
# exit application
bl _exit
.size make_fcontext,.-make_fcontext
# Mark that we don't need executable stack.
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,83 @@
/*******************************************************
* *
* ------------------------------------------------- *
* | 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 | | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _make_fcontext
.balign 16
_make_fcontext:
; shift address in x0 (allocated stack) to lower 16 byte boundary
and x0, x0, ~0xF
; reserve space for context-data on context-stack
sub x0, x0, #0xb0
; third arg of make_fcontext() == address of context-function
; 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
; save address of finish as return-address for context-function
; will be entered after context-function returns (LR register)
str x1, [x0, #0x98]
ret lr ; return pointer to context-data (x0)
finish:
; exit code is zero
mov x0, #0
; exit application
bl __exit

View File

@ -0,0 +1,71 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | v1 | v2 | v3 | v4 | v5 | v6 | v7 | v8 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | | *
* ------------------------------------------------- *
* | 0x60| 0x64| | *
* ------------------------------------------------- *
* | lr | pc | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl make_fcontext
.align 2
.type make_fcontext,%function
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, #104
@ third arg of make_fcontext() == address of context-function
str a3, [a1,#100]
@ 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,#96]
bx lr @ return pointer to context-data
finish:
@ exit code is zero
mov a1, #0
@ exit application
bl _exit@PLT
.size make_fcontext,.-make_fcontext
@ Mark that we don't need executable stack.
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,66 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
* ------------------------------------------------- *
* | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
* ------------------------------------------------- *
* | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
* ------------------------------------------------- *
* | sjlj| v1 | v2 | v3 | v4 | v5 | v6 | v7 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | | *
* ------------------------------------------------- *
* | 0x60| 0x64| 0x68| | *
* ------------------------------------------------- *
* | 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, #108
@ third arg of make_fcontext() == address of context-function
str a3, [a1,#104]
@ 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,#100]
bx lr @ return pointer to context-data
finish:
@ exit code is zero
mov a1, #0
@ exit application
bl __exit

View File

@ -0,0 +1,86 @@
;/*
; 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 | 6 | 7 | *
; * ------------------------------------------------- *
; * | 0x0 | 0x4 | 0x8 | 0xc | 0x10| 0x14| 0x18| 0x1c| *
; * ------------------------------------------------- *
; * | s16 | s17 | s18 | s19 | s20 | s21 | s22 | s23 | *
; * ------------------------------------------------- *
; * ------------------------------------------------- *
; * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
; * ------------------------------------------------- *
; * | 0x20| 0x24| 0x28| 0x2c| 0x30| 0x34| 0x38| 0x3c| *
; * ------------------------------------------------- *
; * | s24 | s25 | s26 | s27 | s28 | s29 | s30 | s31 | *
; * ------------------------------------------------- *
; * ------------------------------------------------- *
; * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
; * ------------------------------------------------- *
; * | 0x40| 0x44| 0x48| 0x4c| 0x50| 0x54| 0x58| 0x5c| *
; * ------------------------------------------------- *
; * |deall|limit| base| v1 | v2 | v3 | v4 | v5 | *
; * ------------------------------------------------- *
; * ------------------------------------------------- *
; * | 24 | 25 | 26 | 27 | 28 | | *
; * ------------------------------------------------- *
; * | 0x60| 0x64| 0x68| 0x6c| 0x70| | *
; * ------------------------------------------------- *
; * | v6 | v7 | v8 | lr | pc | | *
; * ------------------------------------------------- *
; * *
; *******************************************************
AREA |.text|, CODE
ALIGN 4
EXPORT make_fcontext
IMPORT _exit
make_fcontext PROC
; first arg of make_fcontext() == top of context-stack
; save top of context-stack (base) A4
mov a4, a1
; shift address in A1 to lower 16 byte boundary
bic a1, a1, #0x0f
; reserve space for context-data on context-stack
sub a1, a1, #0x74
; save top address of context_stack as 'base'
str a4, [a1,#0x48]
; second arg of make_fcontext() == size of context-stack
; compute bottom address of context-stack (limit)
sub a4, a4, a2
; save bottom address of context-stack as 'limit'
str a4, [a1,#0x44]
; save bottom address of context-stack as 'dealloction stack'
str a4, [a1,#0x40]
; third arg of make_fcontext() == address of context-function
str a3, [a1,#0x70]
; 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,#0x6c]
bx lr ; return pointer to context-data
finish
; exit code is zero
mov a1, #0
; exit application
bl _exit
ENDP
END

View File

@ -0,0 +1,20 @@
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__i386__)
#include "make_i386_sysv_macho_gas.S"
#elif defined(__x86_64__)
#include "make_x86_64_sysv_macho_gas.S"
#elif defined(__ppc__)
#include "make_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "make_ppc64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -0,0 +1,124 @@
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
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 |
---------------------------------------------------------------------------------
| 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch |
---------------------------------------------------------------------------------
| fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI |
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
| 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
---------------------------------------------------------------------------------
| 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch |
---------------------------------------------------------------------------------
| ESI | EBX | EBP | EIP | EXIT | | SEH NXT |SEH HNDLR|
---------------------------------------------------------------------------------
*******************************************************************/
.file "make_i386_ms_pe_gas.asm"
.text
.p2align 4,,15
.globl _make_fcontext
.def _make_fcontext; .scl 2; .type 32; .endef
_make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movl 0x04(%esp), %eax
/* reserve space for first argument of context-function */
/* EAX might already point to a 16byte border */
leal -0x08(%eax), %eax
/* shift address in EAX to lower 16 byte boundary */
andl $-16, %eax
/* reserve space for context-data on context-stack */
/* size for fc_mxcsr .. EIP + return-address for context-function */
/* on context-function entry: (ESP -0x4) % 8 == 0 */
/* additional space is required for SEH */
leal -0x3c(%eax), %eax
/* first arg of make_fcontext() == top of context-stack */
movl 0x04(%esp), %ecx
/* save top address of context stack as 'base' */
movl %ecx, 0x14(%eax)
/* second arg of make_fcontext() == size of context-stack */
movl 0x08(%esp), %edx
/* negate stack size for LEA instruction (== substraction) */
negl %edx
/* compute bottom address of context stack (limit) */
leal (%ecx,%edx), %ecx
/* save bottom address of context-stack as 'limit' */
movl %ecx, 0x10(%eax)
/* save bottom address of context-stack as 'dealloction stack' */
movl %ecx, 0xc(%eax)
/* third arg of make_fcontext() == address of context-function */
movl 0xc(%esp), %ecx
movl %ecx, 0x2c(%eax)
/* save MMX control- and status-word */
stmxcsr (%eax)
/* save x87 control-word */
fnstcw 0x04(%eax)
/* compute abs address of label finish */
movl $finish, %ecx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movl %ecx, 0x30(%eax)
/* traverse current seh chain to get the last exception handler installed by Windows */
/* note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default */
/* the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler */
/* at its end by RaiseException all seh andlers are disregarded if not present and the */
/* program is aborted */
/* load NT_TIB into ECX */
movl %fs:(0x0), %ecx
walk:
/* load 'next' member of current SEH into EDX */
movl (%ecx), %edx
/* test if 'next' of current SEH is last (== 0xffffffff) */
incl %edx
jz found
decl %edx
/* exchange content; ECX contains address of next SEH */
xchgl %ecx, %edx
/* inspect next SEH */
jmp walk
found:
/* load 'handler' member of SEH == address of last SEH handler installed by Windows */
movl 0x04(%ecx), %ecx
/* save address in ECX as SEH handler for context */
movl %ecx, 0x3c(%eax)
/* set ECX to -1 */
movl $0xffffffff, %ecx
/* save ECX as next SEH item */
movl %ecx, 0x38(%eax)
/* load address of next SEH item */
leal 0x38(%eax), %ecx
/* save next SEH */
movl %ecx, 0x18(%eax)
/* return pointer to context-data */
ret
finish:
/* ESP points to same address as ESP on entry of context function + 0x4 */
xorl %eax, %eax
/* exit code is zero */
movl %eax, (%esp)
/* exit application */
call __exit
hlt
.def __exit; .scl 2; .type 32; .endef /* standard C library function */

View File

@ -0,0 +1,122 @@
; 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 | 6 | 7 |
; ---------------------------------------------------------------------------------
; | 0h | 04h | 08h | 0ch | 010h | 014h | 018h | 01ch |
; ---------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| fc_strg |fc_deallo| limit | base | fc_seh | EDI |
; ---------------------------------------------------------------------------------
; ---------------------------------------------------------------------------------
; | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
; ---------------------------------------------------------------------------------
; | 020h | 024h | 028h | 02ch | 030h | 034h | 038h | 03ch |
; ---------------------------------------------------------------------------------
; | ESI | EBX | EBP | EIP | EXIT | | SEH NXT |SEH HNDLR|
; ---------------------------------------------------------------------------------
.386
.XMM
.model flat, c
; standard C library function
_exit PROTO, value:SDWORD
.code
make_fcontext PROC BOOST_CONTEXT_EXPORT
; first arg of make_fcontext() == top of context-stack
mov eax, [esp+04h]
; reserve space for first argument of context-function
; EAX might already point to a 16byte border
lea eax, [eax-08h]
; shift address in EAX to lower 16 byte boundary
and eax, -16
; reserve space for context-data on context-stack
; size for fc_mxcsr .. EIP + return-address for context-function
; on context-function entry: (ESP -0x4) % 8 == 0
; additional space is required for SEH
lea eax, [eax-03ch]
; first arg of make_fcontext() == top of context-stack
mov ecx, [esp+04h]
; save top address of context stack as 'base'
mov [eax+014h], ecx
; second arg of make_fcontext() == size of context-stack
mov edx, [esp+08h]
; negate stack size for LEA instruction (== substraction)
neg edx
; compute bottom address of context stack (limit)
lea ecx, [ecx+edx]
; save bottom address of context-stack as 'limit'
mov [eax+010h], ecx
; save bottom address of context-stack as 'dealloction stack'
mov [eax+0ch], ecx
; third arg of make_fcontext() == address of context-function
mov ecx, [esp+0ch]
mov [eax+02ch], ecx
; save MMX control- and status-word
stmxcsr [eax]
; save x87 control-word
fnstcw [eax+04h]
; compute abs address of label finish
mov ecx, finish
; save address of finish as return-address for context-function
; will be entered after context-function returns
mov [eax+030h], ecx
; traverse current seh chain to get the last exception handler installed by Windows
; note that on Windows Server 2008 and 2008 R2, SEHOP is activated by default
; the exception handler chain is tested for the presence of ntdll.dll!FinalExceptionHandler
; at its end by RaiseException all seh-handlers are disregarded if not present and the
; program is aborted
assume fs:nothing
; load NT_TIB into ECX
mov ecx, fs:[0h]
assume fs:error
walk:
; load 'next' member of current SEH into EDX
mov edx, [ecx]
; test if 'next' of current SEH is last (== 0xffffffff)
inc edx
jz found
dec edx
; exchange content; ECX contains address of next SEH
xchg edx, ecx
; inspect next SEH
jmp walk
found:
; load 'handler' member of SEH == address of last SEH handler installed by Windows
mov ecx, [ecx+04h]
; save address in ECX as SEH handler for context
mov [eax+03ch], ecx
; set ECX to -1
mov ecx, 0ffffffffh
; save ECX as next SEH item
mov [eax+038h], ecx
; load address of next SEH item
lea ecx, [eax+038h]
; save next SEH
mov [eax+018h], ecx
ret ; return pointer to context-data
finish:
; exit code is zero
xor eax, eax
mov [esp], eax
; exit application
call _exit
hlt
make_fcontext ENDP
END

View File

@ -0,0 +1,77 @@
/*
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 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | EXIT | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl make_fcontext
.align 2
.type make_fcontext,@function
make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movl 0x4(%esp), %eax
/* reserve space for first argument of context-function
rax might already point to a 16byte border */
leal -0x8(%eax), %eax
/* shift address in EAX to lower 16 byte boundary */
andl $-16, %eax
/* reserve space for context-data on context-stack */
/* size for fc_mxcsr .. EIP + return-address for context-function */
/* on context-function entry: (ESP -0x4) % 8 == 0 */
leal -0x20(%eax), %eax
/* third arg of make_fcontext() == address of context-function */
movl 0xc(%esp), %edx
movl %edx, 0x18(%eax)
/* save MMX control- and status-word */
stmxcsr (%eax)
/* save x87 control-word */
fnstcw 0x4(%eax)
/* compute abs address of label finish */
call 1f
/* address of label 1 */
1: popl %ecx
/* compute abs address of label finish */
addl $finish-1b, %ecx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movl %ecx, 0x1c(%eax)
ret /* return pointer to context-data */
finish:
call 2f
/* address of label 2 */
2: popl %ebx
/* compute address of GOT and store it in EBX */
addl $_GLOBAL_OFFSET_TABLE_+[.-2b], %ebx
/* exit code is zero */
xorl %eax, %eax
movl %eax, (%esp)
/* exit application */
call _exit@PLT
hlt
.size make_fcontext,.-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,66 @@
/*
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 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| EDI | ESI | EBX | EBP | EIP | EXIT | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl _make_fcontext
.align 2
_make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movl 0x4(%esp), %eax
/* reserve space for first argument of context-function
rax might already point to a 16byte border */
leal -0x8(%eax), %eax
/* shift address in EAX to lower 16 byte boundary */
andl $-16, %eax
/* reserve space for context-data on context-stack */
/* size for fc_mxcsr .. EIP + return-address for context-function */
/* on context-function entry: (ESP -0x4) % 8 == 0 */
leal -0x20(%eax), %eax
/* thrid arg of make_fcontext() == address of context-function */
movl 0xc(%esp), %edx
movl %edx, 0x18(%eax)
/* save MMX control- and status-word */
stmxcsr (%eax)
/* save x87 control-word */
fnstcw 0x4(%eax)
/* compute abs address of label finish */
call 1f
/* address of label 1 */
1: popl %ecx
/* compute abs address of label finish */
addl $finish-1b, %ecx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movl %ecx, 0x1c(%eax)
ret /* return pointer to context-data */
finish:
/* exit code is zero */
xorl %eax, %eax
movl %eax, (%esp)
/* exit application */
call __exit
hlt

View File

@ -0,0 +1,16 @@
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__i386__)
#include "make_i386_sysv_macho_gas.S"
#elif defined(__x86_64__)
#include "make_x86_64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -0,0 +1,89 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F20 | F22 | F24 | F26 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F28 | F30 | S0 | S1 | S2 | S3 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | | *
* ------------------------------------------------- *
* | S4 | S5 | S6 | S7 | FP | RA | PC | | *
* ------------------------------------------------- *
* *
* *****************************************************/
.text
.globl make_fcontext
.align 2
.type make_fcontext,@function
.ent make_fcontext
make_fcontext:
#ifdef __PIC__
.set noreorder
.cpload $t9
.set reorder
#endif
# first arg of make_fcontext() == top address of context-stack
move $v0, $a0
# shift address in A0 to lower 16 byte boundary
move $v1, $v0
li $v0, -16 # 0xfffffffffffffff0
and $v0, $v1, $v0
# reserve space for context-data on context-stack
# including 48 byte of shadow space (sp % 16 == 0)
addiu $v0, $v0, -140
# third arg of make_fcontext() == address of context-function
sw $a2, 88($v0)
# save global pointer in context-data
# S0 will contain address of global pointer
sw $gp, 48($v0)
# compute abs address of label finish
la $t9, finish
# save address of finish as return-address for context-function
# will be entered after context-function returns
sw $t9, 84($v0)
jr $ra # return pointer to context-data
finish:
# allocate stack space (contains shadow space for subroutines)
addiu $sp, $sp, -32
# save return address
sw $ra, 28($sp)
# restore GP (global pointer)
move $gp, $s0
# exit code is zero
move $a0, $zero
# address of exit
lw $t9, %call16(_exit)($gp)
# exit application
jalr $t9
.end make_fcontext
.size make_fcontext, .-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,16 @@
/*
Copyright Sergue E. Leontiev 2013.
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)
*/
// Stub file for universal binary
#if defined(__ppc__)
#include "make_ppc32_sysv_macho_gas.S"
#elif defined(__ppc64__)
#include "make_ppc64_sysv_macho_gas.S"
#else
#error "No arch's"
#endif

View File

@ -0,0 +1,123 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | 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 | | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | | *
* ------------------------------------------------- *
* | R31 | CR | LR | PC | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl make_fcontext
.align 2
.type make_fcontext,@function
make_fcontext:
# save return address into R6
mflr %r6
# first arg of make_fcontext() == top address of context-function
# 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, 304
# third arg of make_fcontext() == address of context-function
stw %r5, 236(%r3)
# load LR
mflr %r0
# jump to label 1
bl 1f
1:
# load LR into R4
mflr %r4
# 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, 232(%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)
# exit code is zero
li %r3, 0
# exit application
bl _exit@plt
.size make_fcontext, .-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,118 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | 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 | | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | | *
* ------------------------------------------------- *
* | R31 | CR | LR | PC | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _make_fcontext
.align 2
_make_fcontext:
; save return address into R6
mflr r6
; first arg of make_fcontext() == top address of context-function
; 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, 304
; third arg of make_fcontext() == address of context-function
stw r5, 236(r3)
; load LR
mflr r0
; jump to label 1
bl l1
l1:
; load LR into R4
mflr r4
; compute abs address of label finish
addi r4, r4, lo16((finish - .)+4)
# restore LR
mtlr r0
; save address of finish as return-address for context-function
; will be entered after context-function returns
stw r4, 232(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)
; exit code is zero
li r3, 0
; exit application
bl __exit

View File

@ -0,0 +1,55 @@
.globl make_fcontext[DS]
.globl .make_fcontext[PR]
.align 2
.csect make_fcontext[DS]
make_fcontext:
.long .make_fcontext[PR]
.csect .make_fcontext[PR], 3
#.make_fcontext:
# save return address into R6
mflr 6
# first arg of make_fcontext() == top address of context-function
# shift address in R3 to lower 16 byte boundary
clrrwi 3, 3, 4
# reserve space for context-data on context-stack
# including 64 byte of linkage + parameter area (R1 % 16 == 0)
subi 3, 3, 304
# third arg of make_fcontext() == address of context-function
stw 5, 236(3)
# load LR
mflr 0
# jump to label 1
bl .Label
.Label:
# load LR into R4
mflr 4
# compute abs address of label .L_finish
addi 4, 4, .L_finish - .Label
# restore LR
mtlr 0
# save address of finish as return-address for context-function
# will be entered after context-function returns
stw 4, 232(3)
# restore return address from R6
mtlr 6
blr # return pointer to context-data
.L_finish:
# save return address into R0
mflr 0
# save return address on stack, set up stack frame
stw 0, 4(1)
# allocate stack space, R1 % 16 == 0
stwu 1, -16(1)
# exit code is zero
li 3, 0
# exit application
bl ._exit
nop

View File

@ -0,0 +1,189 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | TOC | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R14 | R15 | R16 | R17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R18 | R19 | R20 | R21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R22 | R23 | R24 | R25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | *
* ------------------------------------------------- *
* | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | *
* ------------------------------------------------- *
* | R26 | R27 | R28 | R29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | *
* ------------------------------------------------- *
* | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | R30 | R31 | CR | LR | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 80 | 81 | | *
* ------------------------------------------------- *
* | 320 | 324 | | *
* ------------------------------------------------- *
* | PC | | *
* ------------------------------------------------- *
* *
*******************************************************/
.globl make_fcontext
#if _CALL_ELF == 2
.text
.align 2
make_fcontext:
addis %r2, %r12, .TOC.-make_fcontext@ha
addi %r2, %r2, .TOC.-make_fcontext@l
.localentry make_fcontext, . - make_fcontext
#else
.section ".opd","aw"
.align 3
make_fcontext:
# ifdef _CALL_LINUX
.quad .L.make_fcontext,.TOC.@tocbase,0
.type make_fcontext,@function
.text
.align 2
.L.make_fcontext:
# else
.hidden .make_fcontext
.globl .make_fcontext
.quad .make_fcontext,.TOC.@tocbase,0
.size make_fcontext,24
.type .make_fcontext,@function
.text
.align 2
.make_fcontext:
# endif
#endif
# save return address into R6
mflr %r6
# first arg of make_fcontext() == top address of context-stack
# shift address in R3 to lower 16 byte boundary
clrrdi %r3, %r3, 4
# reserve space for context-data on context-stack
# including 64 byte of linkage + parameter area (R1 % 16 == 0)
subi %r3, %r3, 392
# third arg of make_fcontext() == address of context-function
# entry point (ELFv2) or descriptor (ELFv1)
#if _CALL_ELF == 2
# save address of context-function entry point
std %r5, 320(%r3)
#else
# save address of context-function entry point
ld %r4, 0(%r5)
std %r4, 320(%r3)
# save TOC of context-function
ld %r4, 8(%r5)
std %r4, 152(%r3)
#endif
# load LR
mflr %r0
# jump to label 1
bl 1f
1:
# load LR into R4
mflr %r4
# 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
std %r4, 312(%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
std %r0, 8(%r1)
# allocate stack space, R1 % 16 == 0
stdu %r1, -32(%r1)
# exit code is zero
li %r3, 0
# exit application
bl _exit
nop
#if _CALL_ELF == 2
.size make_fcontext, .-make_fcontext
#else
# ifdef _CALL_LINUX
.size .make_fcontext, .-.L.make_fcontext
# else
.size .make_fcontext, .-.make_fcontext
# endif
#endif
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,140 @@
/*
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 | 6 | 7 | *
* ------------------------------------------------- *
* | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | *
* ------------------------------------------------- *
* | F14 | F15 | F16 | F17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ------------------------------------------------- *
* | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
* ------------------------------------------------- *
* | F18 | F19 | F20 | F21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
* ------------------------------------------------- *
* | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
* ------------------------------------------------- *
* | F22 | F23 | F24 | F25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
* ------------------------------------------------- *
* | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
* ------------------------------------------------- *
* | F26 | F27 | F28 | F29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
* ------------------------------------------------- *
* | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
* ------------------------------------------------- *
* | F30 | F31 | fpscr | R13 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
* ------------------------------------------------- *
* | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
* ------------------------------------------------- *
* | R14 | R15 | R16 | R17 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
* ------------------------------------------------- *
* | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
* ------------------------------------------------- *
* | R18 | R19 | R20 | R21 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
* ------------------------------------------------- *
* | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
* ------------------------------------------------- *
* | R22 | R23 | R24 | R25 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | *
* ------------------------------------------------- *
* | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | *
* ------------------------------------------------- *
* | R26 | R27 | R28 | R29 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | *
* ------------------------------------------------- *
* | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | R30 | R31 | CR | LR | *
* ------------------------------------------------- *
* ------------------------------------------------- *
* | 80 | 81 | | *
* ------------------------------------------------- *
* | 320 | 324 | | *
* ------------------------------------------------- *
* | PC | | *
* ------------------------------------------------- *
* *
*******************************************************/
.text
.globl _make_fcontext
_make_fcontext:
; save return address into R6
mflr r6
; first arg of make_fcontext() == top address of context-function
; 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, 392
; third arg of make_fcontext() == address of context-function
stw r5, 320(r3)
; load LR
mflr r0
; jump to label 1
bl l1
l1:
; load LR into R4
mflr r4
; compute abs address of label finish
addi r4, r4, lo16((finish - .) + 4)
; restore LR
mtlr r0
; save address of finish as return-address for context-function
; will be entered after context-function returns
std r4, 312(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, 8(r1)
; allocate stack space, R1 16 == 0
stwu r1, -32(r1)
; set return value to zero
li r3, 0
; exit application
bl __exit
nop

View File

@ -0,0 +1,53 @@
.globl make_fcontext[DS]
.globl .make_fcontext[PR]
.align 2
.csect .make_fcontext[PR], 3
.globl _make_fcontext
#._make_fcontext:
# save return address into R6
mflr 6
# first arg of make_fcontext() == top address of context-function
# shift address in R3 to lower 16 byte boundary
clrrwi 3, 3, 4
# reserve space for context-data on context-stack
# including 64 byte of linkage + parameter area (R1 % 16 == 0)
subi 3, 3, 392
# third arg of make_fcontext() == address of context-function
stw 5, 320(3)
# load LR
mflr 0
# jump to label 1
bl .Label
.Label:
# load LR into R4
mflr 4
# compute abs address of label .L_finish
addi 4, 4, .L_finish - .Label
# restore LR
mtlr 0
# save address of finish as return-address for context-function
# will be entered after context-function returns
stw 4, 312(3)
# restore return address from R6
mtlr 6
blr # return pointer to context-data
.L_finish:
# save return address into R0
mflr 0
# save return address on stack, set up stack frame
stw 0, 8(1)
# allocate stack space, R1 % 16 == 0
stwu 1, -32(1)
# exit code is zero
li 3, 0
# exit application
bl ._exit
nop

View File

@ -0,0 +1,89 @@
/*
Copyright Martin Husemann 2013.
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)
*/
/*******************************************************************
* *
* ------------------------------------------------------------- *
* | Offset (in 4 or 8 byte units) | Content | *
* ------------------------------------------------------------- *
* | 0 | %sp | *
* ------------------------------------------------------------- *
* | 1 | %pc | *
* ------------------------------------------------------------- *
* | 2 | %i7 (return address) | *
* ------------------------------------------------------------- *
* | 3 | %g1 | *
* ------------------------------------------------------------- *
* | 4 | %g2 | *
* ------------------------------------------------------------- *
* | 5 | %g3 | *
* ------------------------------------------------------------- *
* | 6 | %g6 | *
* ------------------------------------------------------------- *
* | 7 | %g7 | *
* ------------------------------------------------------------- *
* The local and in registers are stored on the stack. *
*******************************************************************/
#define OFF(N) (8*(N))
#define CCFSZ 176 // C Compiler Frame Size
#define BIAS (2048-1) // Stack offset for 64 bit programs
#define FC_SZ 448 // sizeof(fcontext_t)
#define FC_STK 384 // offsetof(fcontext_t, fc_stack)
#define FC_FPU 0 // offsetof(fcontext_t, fc_fp)
#define FC_FSR 264 // offsetof(fcontext_t, fc_fp.fp_fsr)
#define FC_FPRS 256 // offsetof(fcontext_t, fc_fp.fp_fprs)
#define FC_GREG 320 // offsetof(fcontext_t, fc_greg)
#define BLOCK_SIZE 64
.register %g2,#ignore
.register %g3,#ignore
.register %g6,#ignore
.text
.globl make_fcontext
.align 4
.type make_fcontext,@function
// fcontext_t *
// make_fcontext( void * sp, std::size_t size, void (* fn)( intptr_t) )
make_fcontext:
save %sp, -CCFSZ, %sp
// %i0 initial stack pointer
// %i1 stack size limit
// %i2 function pointer for context start function
sub %i0, FC_SZ, %i4 // allocate fcontext_t at on the new stack and keep pointer as return value
andn %i4, BLOCK_SIZE-1, %i5 // force block ops usable alignement and keep pointer to fcontext in %i5
stx %i0, [%i5+FC_STK+OFF(0)] // save fs_stack.sp
stx %i1, [%i5+FC_STK+OFF(1)] // save fs_stack.size
sub %i5, CCFSZ+BIAS, %o1 // leave space for one register window (and offset stack for 64bit)
stx %o1, [%i5+FC_GREG+OFF(0)] // save new stack pointer
stx %i2, [%i5+FC_GREG+OFF(1)] // save new %pc (function pointer)
stx %g1, [%i5+FC_GREG+OFF(3)]
stx %g2, [%i5+FC_GREG+OFF(4)]
stx %g3, [%i5+FC_GREG+OFF(5)]
stx %g6, [%i5+FC_GREG+OFF(6)]
stx %g7, [%i5+FC_GREG+OFF(7)]
// synthesize "return address": jump to finish
1: rd %pc, %i4
add %i4, finish-1b-8, %i4
stx %i4, [%i5+FC_GREG+OFF(2)]
ret
restore %g0, %i5, %o0 // return fcontext_t
finish:
mov %g0, %o0
call _exit
nop
.size make_fcontext,.-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,85 @@
/*
Copyright Martin Husemann 2013.
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)
*/
/*******************************************************************
* *
* ------------------------------------------------------------- *
* | Offset (in 4 or 8 byte units) | Content | *
* ------------------------------------------------------------- *
* | 0 | %sp | *
* ------------------------------------------------------------- *
* | 1 | %pc | *
* ------------------------------------------------------------- *
* | 2 | %i7 (return address) | *
* ------------------------------------------------------------- *
* | 3 | %g1 | *
* ------------------------------------------------------------- *
* | 4 | %g2 | *
* ------------------------------------------------------------- *
* | 5 | %g3 | *
* ------------------------------------------------------------- *
* | 6 | %g6 | *
* ------------------------------------------------------------- *
* | 7 | %g7 | *
* ------------------------------------------------------------- *
* The local and in registers are stored on the stack. *
*******************************************************************/
#define OFF(N) (4*(N))
#define CCFSZ 96
#define FC_SZ 176
#define FC_stK 168 // offsetof(fcontext_t, fc_stack)
#define FC_FPU 0 // offsetof(fcontext_t, fc_fp)
#define FC_FSR 128 // offsetof(fcontext_t, fc_fp.fp_fsr)
#define FC_GREG 136 // offsetof(fcontext_t, fc_greg)
#define BLOCK_SIZE 8
.text
.globl make_fcontext
.align 4
.type make_fcontext,@function
// fcontext_t *
// make_fcontext( void * sp, std::size_t size, void (* fn)( intptr_t) )
make_fcontext:
save %sp, -CCFSZ, %sp
// %i0 initial stack pointer
// %i1 stack size limit
// %i2 function pointer for context start function
sub %i0, FC_SZ, %i4 // allocate fcontext_t at on the new stack and keep pointer as return value
andn %i4, BLOCK_SIZE-1, %i5 // force block ops usable alignement and keep pointer to fcontext in %i5
st %i0, [%i5+FC_stK+OFF(0)] // save fs_stack.sp
st %i1, [%i5+FC_stK+OFF(1)] // save fs_stack.size
sub %i5, CCFSZ, %o1 // leave space for one register window
st %o1, [%i5+FC_GREG+OFF(0)] // save new stack pointer
st %i2, [%i5+FC_GREG+OFF(1)] // save new %pc (function pointer)
st %g1, [%i5+FC_GREG+OFF(3)]
st %g2, [%i5+FC_GREG+OFF(4)]
st %g3, [%i5+FC_GREG+OFF(5)]
st %g6, [%i5+FC_GREG+OFF(6)]
st %g7, [%i5+FC_GREG+OFF(7)]
// synthesize "return address": jump to finish
mov %i7, %l0
2: call 3f
nop
3: add finish-2b-8, %o7, %i4
st %i4, [%i5+FC_GREG+OFF(2)]
ret
restore %g0, %i5, %o0 // return fcontext_t
finish:
mov %g0, %o0
call _exit
nop
.size make_fcontext,.-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,151 @@
/*
Copyright Oliver Kowalke 2009.
Copyright Thomas Sailer 2013.
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 | |
* ----------------------------------------------------------------------------------
* | 0x0 | 0x4 | |
* ----------------------------------------------------------------------------------
* | <indicator> | |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
* ----------------------------------------------------------------------------------
* | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | 0x20 | 0x24 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
* ----------------------------------------------------------------------------------
* | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | 0x40 | 0x44 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
* ----------------------------------------------------------------------------------
* | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
* ----------------------------------------------------------------------------------
* | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
* ----------------------------------------------------------------------------------
* | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 |
* ----------------------------------------------------------------------------------
* | SEE registers (XMM6-XMM15) |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
* ----------------------------------------------------------------------------------
* | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 |
* ----------------------------------------------------------------------------------
* | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
* ----------------------------------------------------------------------------------
* | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 |
* ----------------------------------------------------------------------------------
* | limit | base | R12 | R13 |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
* ----------------------------------------------------------------------------------
* | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 |
* ----------------------------------------------------------------------------------
* | R14 | R15 | RDI | RSI |
* ----------------------------------------------------------------------------------
* ----------------------------------------------------------------------------------
* | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
* ----------------------------------------------------------------------------------
* | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 |
* ----------------------------------------------------------------------------------
* | RBX | RBP | RIP | EXIT |
* ----------------------------------------------------------------------------------
* *
* *************************************************************************************/
.file "make_x86_64_ms_pe_gas.asm"
.text
.p2align 4,,15
.globl make_fcontext
.def make_fcontext; .scl 2; .type 32; .endef
.seh_proc make_fcontext
make_fcontext:
.seh_endprologue
/* first arg of make_fcontext() == top of context-stack */
movq %rcx, %rax
/* reserve 32byte shadow-space for context-function */
leaq -0x28(%rax), %rax
/* shift address in RAX to lower 16 byte boundary */
/* == pointer to fcontext_t and address of context stack */
andq $-16, %rax
/* reserve space for context-data on context-stack */
/* size for fc_mxcsr .. RIP + return-address for context-function */
/* on context-function entry: (RSP -0x8) % 16 == 0 */
leaq -0x128(%rax), %rax
/* third arg of make_fcontext() == address of context-function */
movq %r8, 0x118(%rax)
/* first arg of make_fcontext() == top of context-stack */
/* save top address of context stack as 'base' */
movq %rcx, 0xd0(%rax)
/* second arg of make_fcontext() == size of context-stack */
/* negate stack size for LEA instruction (== substraction) */
negq %rdx
/* compute bottom address of context stack (limit) */
leaq (%rcx,%rdx), %rcx
/* save bottom address of context stack as 'limit' */
movq %rcx, 0xc8(%rax)
/* save address of context stack limit as 'dealloction stack' */
movq %rcx, 0xc0(%rax)
/* save MMX control- and status-word */
stmxcsr 0xa8(%rax)
/* save x87 control-word */
fnstcw 0xac(%rax)
/* compute abs address of label finish */
leaq finish(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movq %rcx, 0x120(%rax)
/* set indicator */
movq 1, %rcx
movq %rcx, (%rax)
ret /* return pointer to context-data */
finish:
/* 32byte shadow-space for _exit() are */
/* already reserved by make_fcontext() */
/* exit code is zero */
xorq %rcx, %rcx
/* exit application */
call _exit
hlt
.seh_endproc
.def _exit; .scl 2; .type 32; .endef /* standard C library function */

View File

@ -0,0 +1,144 @@
; 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 | |
; ----------------------------------------------------------------------------------
; | 0x0 | 0x4 | |
; ----------------------------------------------------------------------------------
; | <indicator> | |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
; ----------------------------------------------------------------------------------
; | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | 0x20 | 0x24 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
; ----------------------------------------------------------------------------------
; | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | 0x40 | 0x44 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
; ----------------------------------------------------------------------------------
; | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
; ----------------------------------------------------------------------------------
; | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
; ----------------------------------------------------------------------------------
; | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 |
; ----------------------------------------------------------------------------------
; | SEE registers (XMM6-XMM15) |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
; ----------------------------------------------------------------------------------
; | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 |
; ----------------------------------------------------------------------------------
; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
; ----------------------------------------------------------------------------------
; | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 |
; ----------------------------------------------------------------------------------
; | limit | base | R12 | R13 |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
; ----------------------------------------------------------------------------------
; | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 |
; ----------------------------------------------------------------------------------
; | R14 | R15 | RDI | RSI |
; ----------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------
; | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
; ----------------------------------------------------------------------------------
; | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 |
; ----------------------------------------------------------------------------------
; | RBX | RBP | RIP | EXIT |
; ----------------------------------------------------------------------------------
; standard C library function
EXTERN _exit:PROC
.code
; generate function table entry in .pdata and unwind information in
make_fcontext PROC BOOST_CONTEXT_EXPORT FRAME
; .xdata for a function's structured exception handling unwind behavior
.endprolog
; first arg of make_fcontext() == top of context-stack
mov rax, rcx
; reserve 32byte shadow-space for context-function
sub rax, 028h
; shift address in RAX to lower 16 byte boundary
; == pointer to fcontext_t and address of context stack
and rax, -16
; reserve space for context-data on context-stack
; size for fc_mxcsr .. RIP + return-address for context-function
; on context-function entry: (RSP -0x8) % 16 == 0
sub rax, 0128h
; third arg of make_fcontext() == address of context-function
mov [rax+0118h], r8
; first arg of make_fcontext() == top of context-stack
; save top address of context stack as 'base'
mov [rax+0d0h], rcx
; second arg of make_fcontext() == size of context-stack
; negate stack size for LEA instruction (== substraction)
neg rdx
; compute bottom address of context stack (limit)
lea rcx, [rcx+rdx]
; save bottom address of context stack as 'limit'
mov [rax+0c8h], rcx
; save address of context stack limit as 'dealloction stack'
mov [rax+0c0h], rcx
; save MMX control- and status-word
stmxcsr [rax+0a8h]
; save x87 control-word
fnstcw [rax+0ach]
; compute abs address of label finish
lea rcx, finish
; save address of finish as return-address for context-function
; will be entered after context-function returns
mov [rax+0120h], rcx
; set indicator
mov rcx, 1
mov [rax], rcx
ret ; return pointer to context-data
finish:
; 32byte shadow-space for _exit() are
; already reserved by make_fcontext()
; exit code is zero
xor rcx, rcx
; exit application
call _exit
hlt
make_fcontext ENDP
END

View File

@ -0,0 +1,75 @@
/*
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 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBX | RBP | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | | *
* ---------------------------------------------------------------------------------- *
* | 0x40 | 0x44 | | *
* ---------------------------------------------------------------------------------- *
* | EXIT | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl make_fcontext
.type make_fcontext,@function
.align 16
make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movq %rdi, %rax
/* shift address in RAX to lower 16 byte boundary */
andq $-16, %rax
/* reserve space for context-data on context-stack */
/* size for fc_mxcsr .. RIP + return-address for context-function */
/* on context-function entry: (RSP -0x8) % 16 == 0 */
leaq -0x48(%rax), %rax
/* third arg of make_fcontext() == address of context-function */
movq %rdx, 0x38(%rax)
/* save MMX control- and status-word */
stmxcsr (%rax)
/* save x87 control-word */
fnstcw 0x4(%rax)
/* compute abs address of label finish */
leaq finish(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movq %rcx, 0x40(%rax)
ret /* return pointer to context-data */
finish:
/* exit code is zero */
xorq %rdi, %rdi
/* exit application */
call _exit@PLT
hlt
.size make_fcontext,.-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits

View File

@ -0,0 +1,71 @@
/*
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 | 6 | 7 | *
* ---------------------------------------------------------------------------------- *
* | 0x0 | 0x4 | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | *
* ---------------------------------------------------------------------------------- *
* | fc_mxcsr|fc_x87_cw| R12 | R13 | R14 | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
* ---------------------------------------------------------------------------------- *
* | 0x20 | 0x24 | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | *
* ---------------------------------------------------------------------------------- *
* | R15 | RBX | RBP | RIP | *
* ---------------------------------------------------------------------------------- *
* ---------------------------------------------------------------------------------- *
* | 16 | 17 | | *
* ---------------------------------------------------------------------------------- *
* | 0x40 | 0x44 | | *
* ---------------------------------------------------------------------------------- *
* | EXIT | | *
* ---------------------------------------------------------------------------------- *
* *
****************************************************************************************/
.text
.globl _make_fcontext
.align 8
_make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movq %rdi, %rax
/* shift address in RAX to lower 16 byte boundary */
movabs $-16, %r8
andq %r8, %rax
/* reserve space for context-data on context-stack */
/* size for fc_mxcsr .. RIP + return-address for context-function */
/* on context-function entry: (RSP -0x8) % 16 == 0 */
leaq -0x48(%rax), %rax
/* third arg of make_fcontext() == address of context-function */
movq %rdx, 0x38(%rax)
/* save MMX control- and status-word */
stmxcsr (%rax)
/* save x87 control-word */
fnstcw 0x4(%rax)
/* compute abs address of label finish */
leaq finish(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movq %rcx, 0x40(%rax)
ret /* return pointer to context-data */
finish:
/* exit code is zero */
xorq %rdi, %rdi
/* exit application */
call __exit
hlt