File tree Expand file tree Collapse file tree 2 files changed +40
-6
lines changed Expand file tree Collapse file tree 2 files changed +40
-6
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments