Changeset a35a3d8 in mainline
- Timestamp:
- 2018-03-12T17:13:46Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b127e4af
- Parents:
- f3d47c97
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-12 17:13:46)
- git-committer:
- GitHub <noreply@…> (2018-03-12 17:13:46)
- Location:
- uspace/lib/c
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/abs32le/src/fibril.c
rf3d47c97 ra35a3d8 30 30 */ 31 31 32 #include < fibril.h>32 #include <setjmp.h> 33 33 #include <stdbool.h> 34 34 35 int context_save(context_t *ctx)35 int __setjmp(context_t *ctx) 36 36 { 37 return 1;37 return 0; 38 38 } 39 39 40 void context_restore(context_t *ctx)40 void __longjmp(context_t *ctx, int val) 41 41 { 42 42 while (true); -
uspace/lib/c/arch/amd64/src/fibril.S
rf3d47c97 ra35a3d8 35 35 # 36 36 # Save CPU context to context_t variable 37 # pointed by the 1st argument. Returns 1 in EAX.37 # pointed by the 1st argument. Returns 0 in RAX. 38 38 # 39 FUNCTION_BEGIN( context_save)39 FUNCTION_BEGIN(__setjmp) 40 40 movq (%rsp), %rdx # the caller's return %eip 41 41 … … 54 54 movq %rax, CONTEXT_OFFSET_TLS(%rdi) 55 55 56 xorl %eax, %eax # context_save returns 1 57 incl %eax 56 xorq %rax, %rax # __setjmp returns 0 58 57 ret 59 FUNCTION_END( context_save)58 FUNCTION_END(__setjmp) 60 59 61 60 ## Restore current CPU context 62 61 # 63 62 # Restore CPU context from context_t variable 64 # pointed by the 1st argument. Returns 0 in EAX.63 # pointed by the 1st argument. Returns second argument in RAX. 65 64 # 66 FUNCTION_BEGIN( context_restore)65 FUNCTION_BEGIN(__longjmp) 67 66 movq CONTEXT_OFFSET_R15(%rdi), %r15 68 67 movq CONTEXT_OFFSET_R14(%rdi), %r14 … … 81 80 movq %rdi, %fs:0 82 81 83 xorl %eax, %eax # context_restore returns 082 movq %rsi, %rax # __longjmp returns second argument 84 83 ret 85 FUNCTION_END( context_restore)84 FUNCTION_END(__longjmp) 86 85 -
uspace/lib/c/arch/arm32/src/fibril.S
rf3d47c97 ra35a3d8 31 31 .text 32 32 33 FUNCTION_BEGIN( context_save)33 FUNCTION_BEGIN(__setjmp) 34 34 stmia r0!, {sp, lr} 35 35 stmia r0!, {r4-r11} 36 37 # return 138 mov r0, #139 mov pc, lr40 FUNCTION_END(context_save)41 42 FUNCTION_BEGIN(context_restore)43 ldmia r0!, {sp, lr}44 ldmia r0!, {r4-r11}45 36 46 37 # return 0 47 38 mov r0, #0 48 39 mov pc, lr 49 FUNCTION_END( context_restore)40 FUNCTION_END(__setjmp) 50 41 42 FUNCTION_BEGIN(__longjmp) 43 ldmia r0!, {sp, lr} 44 ldmia r0!, {r4-r11} 45 46 # return second argument 47 mov r0, r1 48 mov pc, lr 49 FUNCTION_END(__longjmp) 50 -
uspace/lib/c/arch/ia32/src/fibril.S
rf3d47c97 ra35a3d8 35 35 # 36 36 # Save CPU context to the context_t variable 37 # pointed by the 1st argument. Returns 1in EAX.37 # pointed by the 1st argument. Returns 0 in EAX. 38 38 # 39 FUNCTION_BEGIN( context_save)39 FUNCTION_BEGIN(__setjmp) 40 40 movl 0(%esp), %eax # the caller's return %eip 41 41 movl 4(%esp), %edx # address of the context variable to save context to … … 53 53 movl %eax, CONTEXT_OFFSET_TLS(%edx) # tls -> ctx->tls 54 54 55 xorl %eax, %eax # context_save returns 1 56 incl %eax 55 xorl %eax, %eax # __setjmp returns 0 57 56 ret 58 FUNCTION_END( context_save)57 FUNCTION_END(__setjmp) 59 58 60 59 ## Restore saved CPU context 61 60 # 62 61 # Restore CPU context from context_t variable 63 # pointed by the 1st argument. Returns 0in EAX.62 # pointed by the 1st argument. Returns second argument in EAX. 64 63 # 65 FUNCTION_BEGIN( context_restore)64 FUNCTION_BEGIN(__longjmp) 66 65 movl 4(%esp), %eax # address of the context variable to restore context from 66 movl 8(%esp), %ecx # return value 67 67 68 68 # restore registers from the context structure … … 80 80 movl %edx, %gs:0 81 81 82 xorl %eax, %eax # context_restore returns 082 movl %ecx, %eax 83 83 ret 84 FUNCTION_END( context_restore)84 FUNCTION_END(__longjmp) 85 85 -
uspace/lib/c/arch/ia64/include/libarch/fibril.h
rf3d47c97 ra35a3d8 43 43 44 44 /* 45 * context_save() and context_restore() are both leaf procedures.45 * __setjmp() and __longjmp() are both leaf procedures. 46 46 * No need to allocate scratch area. 47 47 */ -
uspace/lib/c/arch/ia64/src/fibril.S
rf3d47c97 ra35a3d8 32 32 .text 33 33 34 FUNCTION_BEGIN( context_save)34 FUNCTION_BEGIN(__setjmp) 35 35 alloc loc0 = ar.pfs, 1, 49, 0, 0 36 36 mov loc1 = ar.unat ;; … … 178 178 mov ar.unat = loc1 179 179 180 add r8 = r0, r0, 1 /* context_save returns 1*/180 mov r8 = 0 /* __setjmp returns 0 */ 181 181 br.ret.sptk.many b0 182 FUNCTION_END( context_save)183 184 FUNCTION_BEGIN( context_restore)185 alloc loc0 = ar.pfs, 1, 50, 0, 0 ;;182 FUNCTION_END(__setjmp) 183 184 FUNCTION_BEGIN(__longjmp) 185 alloc loc0 = ar.pfs, 2, 51, 0, 0 ;; 186 186 187 187 add loc9 = CONTEXT_OFFSET_AR_PFS, in0 … … 230 230 add loc47 = CONTEXT_OFFSET_F29, in0 231 231 add loc48 = CONTEXT_OFFSET_F30, in0 232 add loc49 = CONTEXT_OFFSET_F31, in0 ;; 232 add loc49 = CONTEXT_OFFSET_F31, in0 233 mov loc50 = in1 ;; 233 234 234 235 ld8 loc0 = [loc9] /* load ar.pfs */ … … 335 336 mov ar.unat = loc1 336 337 337 mov r8 = r0 /* context_restore returns 0*/338 mov r8 = loc50 /* __longjmp returns second argument */ 338 339 br.ret.sptk.many b0 339 FUNCTION_END( context_restore)340 FUNCTION_END(__longjmp) -
uspace/lib/c/arch/mips32/src/fibril.S
rf3d47c97 ra35a3d8 35 35 #include <libarch/fibril_context.h> 36 36 37 FUNCTION_BEGIN( context_save)37 FUNCTION_BEGIN(__setjmp) 38 38 sw $s0, CONTEXT_OFFSET_S0($a0) 39 39 sw $s1, CONTEXT_OFFSET_S1($a0) … … 87 87 sw $sp, CONTEXT_OFFSET_SP($a0) 88 88 89 # context_save returns 189 # __setjmp returns 0 90 90 j $ra 91 li $v0, 192 FUNCTION_END( context_save)91 li $v0, 0 92 FUNCTION_END(__setjmp) 93 93 94 FUNCTION_BEGIN( context_restore)94 FUNCTION_BEGIN(__longjmp) 95 95 lw $s0, CONTEXT_OFFSET_S0($a0) 96 96 lw $s1, CONTEXT_OFFSET_S1($a0) … … 147 147 move $t9, $ra 148 148 149 # context_restore returns 0149 # __longjmp returns second argument 150 150 j $ra 151 xor $v0, $v0152 FUNCTION_END( context_restore)151 move $v0, $a1 152 FUNCTION_END(__longjmp) -
uspace/lib/c/arch/ppc32/src/fibril.S
rf3d47c97 ra35a3d8 33 33 #include <libarch/fibril_context.h> 34 34 35 FUNCTION_BEGIN( context_save)35 FUNCTION_BEGIN(__setjmp) 36 36 stw sp, CONTEXT_OFFSET_SP(r3) 37 37 stw r2, CONTEXT_OFFSET_TLS(r3) … … 62 62 stw r4, CONTEXT_OFFSET_CR(r3) 63 63 64 # context_save returns 165 li r3, 164 # __setjmp returns 0 65 li r3, 0 66 66 blr 67 FUNCTION_END( context_save)67 FUNCTION_END(__setjmp) 68 68 69 FUNCTION_BEGIN( context_restore)69 FUNCTION_BEGIN(__longjmp) 70 70 lwz sp, CONTEXT_OFFSET_SP(r3) 71 71 lwz r2, CONTEXT_OFFSET_TLS(r3) … … 90 90 lwz r31, CONTEXT_OFFSET_R31(r3) 91 91 92 lwz r 4, CONTEXT_OFFSET_CR(r3)93 mtcr r 492 lwz r5, CONTEXT_OFFSET_CR(r3) 93 mtcr r5 94 94 95 lwz r 4, CONTEXT_OFFSET_PC(r3)96 mtlr r 495 lwz r5, CONTEXT_OFFSET_PC(r3) 96 mtlr r5 97 97 98 # context_restore returns 099 li r3, 098 # __longjmp returns second argument 99 mr r3, r4 100 100 blr 101 FUNCTION_END( context_restore)101 FUNCTION_END(__longjmp) -
uspace/lib/c/arch/riscv64/src/fibril.c
rf3d47c97 ra35a3d8 33 33 #include <stdbool.h> 34 34 35 int context_save(context_t *ctx)35 int __setjmp(context_t *ctx) 36 36 { 37 return 1;37 return 0; 38 38 } 39 39 40 void context_restore(context_t *ctx)40 void __longjmp(context_t *ctx, int ret) 41 41 { 42 42 while (true); -
uspace/lib/c/arch/sparc64/src/fibril.S
rf3d47c97 ra35a3d8 32 32 .text 33 33 34 FUNCTION_BEGIN( context_save)34 FUNCTION_BEGIN(__setjmp) 35 35 # 36 36 # We rely on the kernel to flush our active register windows to memory … … 57 57 stx %g7, [%o0 + CONTEXT_OFFSET_TP] 58 58 retl 59 mov 1, %o0 ! context_save_arch returns 160 FUNCTION_END( context_save)59 mov 0, %o0 ! __setjmp returns 0 60 FUNCTION_END(__setjmp) 61 61 62 FUNCTION_BEGIN( context_restore)62 FUNCTION_BEGIN(__longjmp) 63 63 # 64 64 # Flush all active windows. … … 89 89 ldx [%o0 + CONTEXT_OFFSET_TP], %g7 90 90 retl 91 xor %o0, %o0, %o0 ! context_restore_arch returns 092 FUNCTION_END( context_restore)91 mov %o1, %o0 ! __longjmp returns second argument 92 FUNCTION_END(__longjmp) -
uspace/lib/c/generic/context.c
rf3d47c97 ra35a3d8 28 28 29 29 #include <context.h> 30 #include <setjmp.h> 30 31 #include <libarch/tls.h> 31 32 #include <libarch/fibril.h> … … 42 43 void context_swap(context_t *self, context_t *other) 43 44 { 44 if ( context_save(self))45 context_restore(other);45 if (!__setjmp(self)) 46 __longjmp(other, 1); 46 47 } 47 48 48 49 void context_create(context_t *context, const context_create_t *arg) 49 50 { 50 context_save(context);51 __setjmp(context); 51 52 context_set(context, FADDR(arg->fn), arg->stack_base, 52 53 arg->stack_size, arg->tls); -
uspace/lib/c/generic/setjmp.c
rf3d47c97 ra35a3d8 1 1 /* 2 2 * Copyright (c) 2013 Vojtech Horky 3 * Copyright (c) 2018 CZ.NIC, z.s.p.o. 3 4 * All rights reserved. 4 5 * … … 30 31 * @{ 31 32 */ 32 /** @file Long jump implementation.33 *34 * Implementation inspired by Jiri Zarevucky's code from35 * http://bazaar.launchpad.net/~zarevucky-jiri/helenos/stdc/revision/1544/uspace/lib/posix/setjmp.h36 */37 33 38 34 #include <setjmp.h> 39 35 #include <context.h> 40 36 41 // TODO: setjmp/longjmp are basically a stronger version of 42 // context_save/context_restore. It would be preferable to turn 43 // those two into setjmp/longjmp (all it would need is preserving the 44 // return value). 45 46 /** 47 * Restore environment previously stored by setjmp. 48 * 49 * This function never returns. 50 * 51 * @param env Variable with the environment previously stored by call 52 * to setjmp. 53 * @param val Value to fake when returning from setjmp (0 is transformed to 1). 54 */ 55 void longjmp(jmp_buf env, int val) { 56 env[0].return_value = (val == 0) ? 1 : val; 57 context_restore(&env[0].context); 37 /** Standard function implementation. */ 38 void longjmp(jmp_buf env, int val) 39 { 40 /* __longjmp defined in assembly doesn't "correct" the value. */ 41 __longjmp(env, val == 0 ? 1 : val); 58 42 } 59 43 -
uspace/lib/c/include/context.h
rf3d47c97 ra35a3d8 46 46 extern uintptr_t context_get_pc(context_t *ctx); 47 47 48 // TODO: These should go away.49 50 extern int context_save(context_t *ctx) __attribute__((returns_twice));51 extern void context_restore(context_t *ctx) __attribute__((noreturn));52 53 48 #endif 54 49 -
uspace/lib/c/include/setjmp.h
rf3d47c97 ra35a3d8 1 1 /* 2 * Copyright (c) 2008 Josef Cejka 3 * Copyright (c) 2013 Vojtech Horky 2 * Copyright (c) 2018 CZ.NIC, z.s.p.o. 4 3 * All rights reserved. 5 4 * … … 31 30 * @{ 32 31 */ 33 /** @file Long jump implementation.34 *35 * Implementation inspired by Jiri Zarevucky's code from36 * http://bazaar.launchpad.net/~zarevucky-jiri/helenos/stdc/revision/1544/uspace/lib/posix/setjmp.h37 */38 32 39 33 #ifndef LIBC_SETJMP_H_ 40 34 #define LIBC_SETJMP_H_ 41 35 42 #include <libarch/fibril .h>36 #include <libarch/fibril_context.h> 43 37 44 struct jmp_buf_interal { 45 context_t context; 46 int return_value; 47 }; 48 typedef struct jmp_buf_interal jmp_buf[1]; 38 typedef context_t jmp_buf[1]; 49 39 50 /* 51 * Specified as extern to minimize number of included headers 52 * because this file is used as is in libposix too. 53 */ 54 extern int context_save(context_t *ctx) __attribute__((returns_twice)); 40 extern int __setjmp(jmp_buf) __attribute__((returns_twice)); 41 extern _Noreturn void __longjmp(jmp_buf, int); 55 42 56 /** 57 * Save current environment (registers). 58 * 59 * This function may return twice. 60 * 61 * @param env Variable where to save the environment (of type jmp_buf). 62 * @return Whether the call returned after longjmp. 63 * @retval 0 Environment was saved, normal execution. 64 * @retval other longjmp was executed and returned here. 65 */ 66 #define setjmp(env) \ 67 ((env)[0].return_value = 0, \ 68 context_save(&(env)[0].context), \ 69 (env)[0].return_value) 70 71 extern void longjmp(jmp_buf env, int val) __attribute__((noreturn)); 43 #define setjmp __setjmp 44 extern _Noreturn void longjmp(jmp_buf, int); 72 45 73 46 #endif
Note:
See TracChangeset
for help on using the changeset viewer.