From 2af20a7baa3415b20ac102e609054ccabf71dd6a Mon Sep 17 00:00:00 2001 From: Ubuntu user Date: Sat, 3 Sep 2016 11:10:46 +0000 Subject: [PATCH 1/2] add ARMv7 support --- md.S | 33 +++++++++++++++++++++++++++++++++ md.h | 12 ++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/md.S b/md.S index 1dccb95..2e1d97e 100644 --- a/md.S +++ b/md.S @@ -462,6 +462,39 @@ #elif defined(__arm__) /* TODO: FIXME: implement setjmp and longjmp for ARM */ + .globl _st_md_cxt_save + .type _st_md_cxt_save, %function + .align 2 + _st_md_cxt_save: + mov ip, r0 // r0为参数jmpbuf地址 + // 以下指令等同于 + // *ip++ = v1 + // *ip++ = ... + // *ip++ = v6 + // *ip++ = sl + // *ip++ = fp + stmia ip!, {v1-v6, sl, fp} // TODO:根据不同的ARM版本,这里要做不同的寄存器保存 + movs r2, sp + stmia ip!, {r2, lr} + mov r0, #0 // setjmp first return 0(r0存放返回值) + bx lr // return + .size _st_md_cxt_save, .-_st_md_cxt_save + + .globl _st_md_cxt_restore + .type _st_md_cxt_restore, %function + .align 2 + _st_md_cxt_restore: + mov ip, r0 // r0 -> jmp_buf + movs r0, r1 // r1 -> return value + // 下面两条指令是一组,也就是if(r0 == 0) r0 = 1 + ITT eq + moveq r0, #1 // 从long_jmp返回一定不能是0 + + ldmia ip!, {v1-v6, sl, fp} // 恢复寄存器 + ldr sp, [ip], #4 // ip会+4, 这条指令相当于sp = *ip; ip+=4; + ldr lr, [ip], #4 + bx lr + .size _st_md_cxt_restore, .-_st_md_cxt_restore #endif diff --git a/md.h b/md.h index 6d3b6c0..6e3baf6 100644 --- a/md.h +++ b/md.h @@ -421,12 +421,12 @@ #elif defined(__arm__) #define MD_STACK_GROWS_DOWN - #if defined(__GLIBC__) && __GLIBC__ >= 2 - /* Merge from https://github.com/michaeltalyansky/state-threads/commit/56554a5c425aee8e7a73782eae23d74d83c4120a */ - #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[8] - #else - #error "ARM/Linux pre-glibc2 not supported yet" - #endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */ + #define MD_USE_BUILTIN_SETJMP + + #ifndef JB_RSP + #define JB_RSP 8 // 这里的JB_RSP的具体数值要跟md.S里面的保存位置对应 + #endif + #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP] #elif defined(__s390__) #define MD_STACK_GROWS_DOWN From f6278030d722f0bef88aeb4290f8bf5b7ca80ff0 Mon Sep 17 00:00:00 2001 From: Ubuntu user Date: Sat, 3 Sep 2016 11:46:33 +0000 Subject: [PATCH 2/2] add ARM buildin setjmp/longjmp support --- md.S | 17 +++++++++-------- md.h | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/md.S b/md.S index 2e1d97e..855a63a 100644 --- a/md.S +++ b/md.S @@ -466,17 +466,17 @@ .type _st_md_cxt_save, %function .align 2 _st_md_cxt_save: - mov ip, r0 // r0为参数jmpbuf地址 - // 以下指令等同于 + mov ip, r0 // r0 is the param jmpbuf ptr address. + // Save registers like // *ip++ = v1 // *ip++ = ... // *ip++ = v6 // *ip++ = sl // *ip++ = fp - stmia ip!, {v1-v6, sl, fp} // TODO:根据不同的ARM版本,这里要做不同的寄存器保存 + stmia ip!, {v1-v6, sl, fp} // TODO: compatible with other ARM version. movs r2, sp stmia ip!, {r2, lr} - mov r0, #0 // setjmp first return 0(r0存放返回值) + mov r0, #0 // r0 save the return value(0) of setjmp. bx lr // return .size _st_md_cxt_save, .-_st_md_cxt_save @@ -486,12 +486,13 @@ _st_md_cxt_restore: mov ip, r0 // r0 -> jmp_buf movs r0, r1 // r1 -> return value - // 下面两条指令是一组,也就是if(r0 == 0) r0 = 1 + // The bellow is a group, that is: + // if (r0 == 0) r0 =1; ITT eq - moveq r0, #1 // 从long_jmp返回一定不能是0 + moveq r0, #1 // long_jmp should never return 0 - ldmia ip!, {v1-v6, sl, fp} // 恢复寄存器 - ldr sp, [ip], #4 // ip会+4, 这条指令相当于sp = *ip; ip+=4; + ldmia ip!, {v1-v6, sl, fp} // restore registers. + ldr sp, [ip], #4 // restore sp, like: sp=*ip; ip+=4; ldr lr, [ip], #4 bx lr .size _st_md_cxt_restore, .-_st_md_cxt_restore diff --git a/md.h b/md.h index 6e3baf6..dd56e13 100644 --- a/md.h +++ b/md.h @@ -424,7 +424,7 @@ #define MD_USE_BUILTIN_SETJMP #ifndef JB_RSP - #define JB_RSP 8 // 这里的JB_RSP的具体数值要跟md.S里面的保存位置对应 + #define JB_RSP 8 // JB_RSP must be same as the index we save in jmpbuf #endif #define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP]