1 commit 70a04a287a2875c82e6822c36e071afba5b63a62
2 Author: Waldemar Brodkorb <wbx@openadk.org>
3 Date: Wed Jan 29 18:58:56 2014 +0100
5 libc: mips: Fix setjmp/longjmp for MIPS64 N64 ABI
7 When booting a Linux system with qemu-system-mips64 the execution
8 of $(pwd) in the ash shell triggers a segmentation fault. Ash uses
9 setjmp/longjmp for exception handling.
11 After looking at the glibc implementation,
12 I found some differences, with this patch tries to resolve.
13 Now the system boots up fine and no segmentation faults occur.
15 The global pointer should be restored and the types for the
16 register values should be wide enough.
19 http://www.cygwin.com/ml/libc-alpha/2003-03/msg00363.html
21 Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
22 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
24 --- a/libc/sysdeps/linux/mips/bits/setjmp.h
25 +++ b/libc/sysdeps/linux/mips/bits/setjmp.h
30 +#if _MIPS_SIM == _MIPS_SIM_ABI32
31 +#define ptrsize void *
33 +#define ptrsize long long
38 /* Program counter. */
46 /* Callee-saved registers s0 through s7. */
47 #if _MIPS_SIM == _MIPS_SIM_ABI32
48 @@ -42,10 +48,10 @@ typedef struct
51 /* The frame pointer. */
55 /* The global pointer. */
59 /* Floating point status register. */
61 --- a/libc/sysdeps/linux/mips/setjmp.S
62 +++ b/libc/sysdeps/linux/mips/setjmp.S
63 @@ -53,6 +53,7 @@ __sigsetjmp:
64 PTR_LA t9, __sigsetjmp_aux
65 #if _MIPS_SIM != _MIPS_SIM_ABI32
71 --- a/libc/sysdeps/linux/mips/setjmp_aux.c
72 +++ b/libc/sysdeps/linux/mips/setjmp_aux.c
73 @@ -31,7 +31,7 @@ extern int __sigjmp_save (sigjmp_buf, in
76 #if _MIPS_SIM == _MIPS_SIM_ABI64
77 -__sigsetjmp_aux (jmp_buf env, int savemask, long sp, long fp)
78 +__sigsetjmp_aux (jmp_buf env, int savemask, long long sp, long long fp, long long gp)
79 #else /* O32 || N32 */
80 __sigsetjmp_aux (jmp_buf env, int savemask, int sp, int fp)
81 #endif /* O32 || N32 */
82 @@ -65,14 +65,14 @@ __sigsetjmp_aux (jmp_buf env, int savema
85 /* .. and the stack pointer; */
86 - env[0].__jmpbuf[0].__sp = (void *) sp;
87 + env[0].__jmpbuf[0].__sp = (ptrsize) sp;
89 /* .. and the FP; it'll be in s8. */
90 - env[0].__jmpbuf[0].__fp = (void *) fp;
91 + env[0].__jmpbuf[0].__fp = (ptrsize) fp;
94 #if _MIPS_SIM == _MIPS_SIM_ABI64
95 - __asm__ __volatile__ ("sd $gp, %0" : : "m" (env[0].__jmpbuf[0].__gp));
96 + env[0].__jmpbuf[0].__gp = (ptrsize) gp;
98 __asm__ __volatile__ ("sw $gp, %0" : : "m" (env[0].__jmpbuf[0].__gp));