Skip to content

Commit 9a17dec

Browse files
xzh3836598winlinvip
authored andcommitted
add ARM buildin setjmp/longjmp support (#3)
* add ARMv7 support * add ARM buildin setjmp/longjmp support
1 parent 9f7ed8f commit 9a17dec

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

md.S

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,40 @@
462462
#elif defined(__arm__)
463463

464464
/* TODO: FIXME: implement setjmp and longjmp for ARM */
465+
.globl _st_md_cxt_save
466+
.type _st_md_cxt_save, %function
467+
.align 2
468+
_st_md_cxt_save:
469+
mov ip, r0 // r0 is the param jmpbuf ptr address.
470+
// Save registers like
471+
// *ip++ = v1
472+
// *ip++ = ...
473+
// *ip++ = v6
474+
// *ip++ = sl
475+
// *ip++ = fp
476+
stmia ip!, {v1-v6, sl, fp} // TODO: compatible with other ARM version.
477+
movs r2, sp
478+
stmia ip!, {r2, lr}
479+
mov r0, #0 // r0 save the return value(0) of setjmp.
480+
bx lr // return
481+
.size _st_md_cxt_save, .-_st_md_cxt_save
482+
483+
.globl _st_md_cxt_restore
484+
.type _st_md_cxt_restore, %function
485+
.align 2
486+
_st_md_cxt_restore:
487+
mov ip, r0 // r0 -> jmp_buf
488+
movs r0, r1 // r1 -> return value
489+
// The bellow is a group, that is:
490+
// if (r0 == 0) r0 =1;
491+
ITT eq
492+
moveq r0, #1 // long_jmp should never return 0
493+
494+
ldmia ip!, {v1-v6, sl, fp} // restore registers.
495+
ldr sp, [ip], #4 // restore sp, like: sp=*ip; ip+=4;
496+
ldr lr, [ip], #4
497+
bx lr
498+
.size _st_md_cxt_restore, .-_st_md_cxt_restore
465499

466500
#endif
467501

md.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,12 @@
421421
#elif defined(__arm__)
422422
#define MD_STACK_GROWS_DOWN
423423

424-
#if defined(__GLIBC__) && __GLIBC__ >= 2
425-
/* Merge from https://github.com/michaeltalyansky/state-threads/commit/56554a5c425aee8e7a73782eae23d74d83c4120a */
426-
#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[8]
427-
#else
428-
#error "ARM/Linux pre-glibc2 not supported yet"
429-
#endif /* defined(__GLIBC__) && __GLIBC__ >= 2 */
424+
#define MD_USE_BUILTIN_SETJMP
425+
426+
#ifndef JB_RSP
427+
#define JB_RSP 8 // JB_RSP must be same as the index we save in jmpbuf
428+
#endif
429+
#define MD_GET_SP(_t) (_t)->context[0].__jmpbuf[JB_RSP]
430430

431431
#elif defined(__s390__)
432432
#define MD_STACK_GROWS_DOWN

0 commit comments

Comments
 (0)