mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
ST: Refine OSX asm.
This commit is contained in:
parent
e8bca303f9
commit
6ddef894d9
1 changed files with 13 additions and 12 deletions
25
trunk/3rdparty/st-srs/md_darwin.S
vendored
25
trunk/3rdparty/st-srs/md_darwin.S
vendored
|
@ -11,17 +11,17 @@
|
|||
*/
|
||||
#define JB_RBX 0
|
||||
#define JB_RBP 1
|
||||
#define JB_R12 2 /* Backup IP, https://www.cnblogs.com/Five100Miles/p/8458561.html */
|
||||
#define JB_R13 3 /* Backup SP, https://www.cnblogs.com/Five100Miles/p/8458561.html */
|
||||
#define JB_R14 4 /* Backup LR, https://www.cnblogs.com/Five100Miles/p/8458561.html */
|
||||
#define JB_R15 5 /* Backup PC, https://www.cnblogs.com/Five100Miles/p/8458561.html */
|
||||
#define JB_R12 2 /* The first six integer or pointer arguments are passed in registers RDI, RSI, RDX, RCX, R8, R9. */
|
||||
#define JB_R13 3 /* If the callee wishes to use registers RBX, RSP, RBP, and R12–R15, it must restore their original values before returning control to the caller. */
|
||||
#define JB_R14 4 /* @see https://en.wikipedia.org/wiki/X86_calling_conventions */
|
||||
#define JB_R15 5 /* @see https://www.cnblogs.com/Five100Miles/p/8458561.html */
|
||||
#define JB_RSP 6
|
||||
#define JB_PC 7
|
||||
|
||||
.file "md_darwin.S"
|
||||
.text
|
||||
|
||||
/* _st_md_cxt_save(__jmp_buf env) */ /* The env is rdi, http://blog.chinaunix.net/uid-20157960-id-1974354.html */
|
||||
/* _st_md_cxt_save(__jmp_buf env) */ /* The env is rdi, https://en.wikipedia.org/wiki/X86_calling_conventions */
|
||||
.globl __st_md_cxt_save
|
||||
.align 16
|
||||
__st_md_cxt_save:
|
||||
|
@ -35,18 +35,18 @@
|
|||
movq %r14, (JB_R14*8)(%rdi) /* Save r14 to env[4], *(int64_t*)(rdi+4)=r14 */
|
||||
movq %r15, (JB_R15*8)(%rdi) /* Save r15 to env[5], *(int64_t*)(rdi+5)=r15 */
|
||||
/* Save SP */
|
||||
leaq 8(%rsp), %rdx /* Save *(int64_t*)(rsp+8) to rdx, https://my.oschina.net/guonaihong/blog/508907 */
|
||||
movq %rdx, (JB_RSP*8)(%rdi) /* Save rdx(rsp) to env[6], *(int64_t*)(rdi+6)=rdx */
|
||||
leaq 8(%rsp), %r8 /* Save *(int64_t*)(rsp+8) to r8, https://github.com/ossrs/state-threads/issues/11#issuecomment-888709759 */
|
||||
movq %r8, (JB_RSP*8)(%rdi) /* Save r8(rsp) to env[6], *(int64_t*)(rdi+6)=r8 */
|
||||
/* Save PC we are returning to */
|
||||
movq (%rsp), %rax /* Save PC(parent function address) %(rsp) to rax */
|
||||
movq %rax, (JB_PC*8)(%rdi) /* Save rax(PC) to env[7], *(int64_t*)(rdi+7)=rax */
|
||||
movq (%rsp), %r9 /* Save PC(parent function address) %(rsp) to r9 */
|
||||
movq %r9, (JB_PC*8)(%rdi) /* Save r9(PC) to env[7], *(int64_t*)(rdi+7)=r9 */
|
||||
xorq %rax, %rax /* Reset rax to 0 */
|
||||
ret
|
||||
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
/* _st_md_cxt_restore(__jmp_buf env, int val) */ /* The env is rdi, val is esi/rsi, http://blog.chinaunix.net/uid-20157960-id-1974354.html */
|
||||
/* _st_md_cxt_restore(__jmp_buf env, int val) */ /* The env is rdi, val is esi/rsi, https://en.wikipedia.org/wiki/X86_calling_conventions */
|
||||
.globl __st_md_cxt_restore
|
||||
.align 16
|
||||
__st_md_cxt_restore:
|
||||
|
@ -64,10 +64,11 @@
|
|||
mov $01, %eax /* val=1; */
|
||||
cmove %eax, %esi /* } */
|
||||
mov %esi, %eax /* return val; */
|
||||
movq (JB_PC*8)(%rdi), %rdx /* Load rdx(PC) from env[7] */
|
||||
/* Restore PC and RSP */
|
||||
movq (JB_PC*8)(%rdi), %r8 /* Load r8(PC) from env[7] */
|
||||
movq (JB_RSP*8)(%rdi), %rsp /* Load rsp from env[6] */
|
||||
/* Jump to saved PC */
|
||||
jmpq *%rdx /* Jump to rdx(PC) */
|
||||
jmpq *%r8 /* Jump to r8(PC) */
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue