| 1 | /* Workaround for CR JAGab60546 setjmp/longjmp and
|
|---|
| 2 | JAGad55982 sigsetjmp/siglongjmp from shared libraries. */
|
|---|
| 3 |
|
|---|
| 4 | /*
|
|---|
| 5 | * tabstop=4
|
|---|
| 6 | *
|
|---|
| 7 | * _setjmp/setjmp/sigsetjmp and
|
|---|
| 8 | *_longjmp/longjmp/siglongjmp.
|
|---|
| 9 | *
|
|---|
| 10 | * Written by Mark Klein, 10 October, 2000
|
|---|
| 11 | * Updated for gcc 3.x 6 October, 2005
|
|---|
| 12 | *
|
|---|
| 13 | * These routines are GCC specific and MUST BE COMPILED
|
|---|
| 14 | * WITH -O2
|
|---|
| 15 | *
|
|---|
| 16 | * The existing setjmp/longjmp code in both libc.a and XL.PUB.SYS
|
|---|
| 17 | * are not SR4 aware and cause problems when working with shared
|
|---|
| 18 | * libraries (XLs), especially when executing a longjmp between
|
|---|
| 19 | * XLs. This code preserves SR4 and will successfully handle
|
|---|
| 20 | * a cross space longjmp. However, the setjmp code must be
|
|---|
| 21 | * bound into each XL from which it will be called as well as
|
|---|
| 22 | * being bound into the main program.
|
|---|
| 23 | */
|
|---|
| 24 |
|
|---|
| 25 | /*
|
|---|
| 26 | * The following macro takes the contents of the jmpbuf and
|
|---|
| 27 | * restores the registers from them. There is other code
|
|---|
| 28 | * elsewhere that ensures that __jmpbuf is %r26 at this
|
|---|
| 29 | * point in time. If it becomes some other register, that
|
|---|
| 30 | * register must be the last restored. At the end will
|
|---|
| 31 | * be a branch external that will cause a cross space
|
|---|
| 32 | * return if needed.
|
|---|
| 33 | */
|
|---|
| 34 | #define RESTORE_REGS_AND_RETURN(__jmpbuf, __retval) \
|
|---|
| 35 | ({ \
|
|---|
| 36 | __asm__ __volatile__ ( \
|
|---|
| 37 | " ldw 0(%%sr0, %0), %%rp\n" \
|
|---|
| 38 | "\t ldw 4(%%sr0, %0), %%sp\n" \
|
|---|
| 39 | "\t ldw 16(%%sr0, %0), %%r3\n" \
|
|---|
| 40 | "\t ldw 20(%%sr0, %0), %%r4\n" \
|
|---|
| 41 | "\t ldw 24(%%sr0, %0), %%r5\n" \
|
|---|
| 42 | "\t ldw 28(%%sr0, %0), %%r6\n" \
|
|---|
| 43 | "\t ldw 32(%%sr0, %0), %%r7\n" \
|
|---|
| 44 | "\t ldw 36(%%sr0, %0), %%r8\n" \
|
|---|
| 45 | "\t ldw 40(%%sr0, %0), %%r9\n" \
|
|---|
| 46 | "\t ldw 44(%%sr0, %0), %%r10\n" \
|
|---|
| 47 | "\t ldw 48(%%sr0, %0), %%r11\n" \
|
|---|
| 48 | "\t ldw 52(%%sr0, %0), %%r12\n" \
|
|---|
| 49 | "\t ldw 56(%%sr0, %0), %%r13\n" \
|
|---|
| 50 | "\t ldw 60(%%sr0, %0), %%r14\n" \
|
|---|
| 51 | "\t ldw 64(%%sr0, %0), %%r15\n" \
|
|---|
| 52 | "\t ldw 68(%%sr0, %0), %%r16\n" \
|
|---|
| 53 | "\t ldw 72(%%sr0, %0), %%r17\n" \
|
|---|
| 54 | "\t ldw 76(%%sr0, %0), %%r18\n" \
|
|---|
| 55 | "\t ldw 80(%%sr0, %0), %%r19\n" \
|
|---|
| 56 | "\t ldw 84(%%sr0, %0), %%r20\n" \
|
|---|
| 57 | "\t ldw 88(%%sr0, %0), %%r21\n" \
|
|---|
| 58 | "\t ldw 92(%%sr0, %0), %%r22\n" \
|
|---|
| 59 | "\t ldw 96(%%sr0, %0), %%r23\n" \
|
|---|
| 60 | "\t ldw 100(%%sr0, %0), %%r24\n" \
|
|---|
| 61 | "\t ldw 104(%%sr0, %0), %%r25\n" \
|
|---|
| 62 | "\t ldw 112(%%sr0, %0), %%r27\n" \
|
|---|
| 63 | "\t ldw 116(%%sr0, %0), %%r1\n" \
|
|---|
| 64 | "\t mtsp %%r1, %%sr3\n" \
|
|---|
| 65 | "\t ldw 120(%%sr0, %0), %%r1\n" \
|
|---|
| 66 | "\t mtsp %%r1, %%sr1\n" \
|
|---|
| 67 | "\t or,<> %%r0, %1, %%r0\n" \
|
|---|
| 68 | "\t ldi 1, %%r28\n" \
|
|---|
| 69 | "\t ldw 108(%%sr0, %0), %%r26\n" \
|
|---|
| 70 | "\t be 0(%%sr1, %%rp)\n" \
|
|---|
| 71 | "\t mtsp %%r1, %%sr4\n" \
|
|---|
| 72 | : \
|
|---|
| 73 | : "r" (__jmpbuf), \
|
|---|
| 74 | "r" (__retval)); \
|
|---|
| 75 | })
|
|---|
| 76 |
|
|---|
| 77 | /*
|
|---|
| 78 | * The following macro extracts the signal mask
|
|---|
| 79 | * from __jmpbuf from the 3rd and 4th words and
|
|---|
| 80 | * if non-zero, calls sigprocmask with that value
|
|---|
| 81 | * to set the signal mask. This macro is usually
|
|---|
| 82 | * invoked before the registers are restored in
|
|---|
| 83 | * the longjmp routines and it can clobber things
|
|---|
| 84 | * without needing to spill them as a result.
|
|---|
| 85 | * A quick frame is built before making the
|
|---|
| 86 | * call and cut back just afterwards.
|
|---|
| 87 | * The ldi 2, %r26 is actually SIG_SETMASK from
|
|---|
| 88 | * /usr/include/signal.h.
|
|---|
| 89 | */
|
|---|
| 90 | #define RESTORE_SIGNAL_MASK(__jmpbuf) \
|
|---|
| 91 | ({ \
|
|---|
| 92 | __asm__ __volatile__ ( \
|
|---|
| 93 | " ldw 8(%0), %%r26\n" \
|
|---|
| 94 | "\t comibt,=,n 0,%%r26,.+36\n" \
|
|---|
| 95 | "\t ldo 64(%%sp), %%sp\n" \
|
|---|
| 96 | "\t stw %0, -28(%%sp)\n" \
|
|---|
| 97 | "\t ldi 0, %%r24\n" \
|
|---|
| 98 | "\t ldo 8(%0), %%r25\n" \
|
|---|
| 99 | "\t .import sigprocmask,code\n" \
|
|---|
| 100 | "\t bl sigprocmask,%%rp\n" \
|
|---|
| 101 | "\t ldi 2, %%r26\n" \
|
|---|
| 102 | "\t ldw -28(%%sr0, %%sp), %0\n" \
|
|---|
| 103 | "\t ldo -64(%%sp), %%sp\n" \
|
|---|
| 104 | : \
|
|---|
| 105 | : "r" (__jmpbuf)); \
|
|---|
| 106 | })
|
|---|
| 107 |
|
|---|
| 108 | /*
|
|---|
| 109 | * This macro saves the current contents of the
|
|---|
| 110 | * registers to __jmpbuf. Note that __jmpbuf is
|
|---|
| 111 | * guaranteed elsewhere to be in %r26. We do not
|
|---|
| 112 | * want it spilled, nor do we want a new frame
|
|---|
| 113 | * built.
|
|---|
| 114 | */
|
|---|
| 115 | #define SAVE_REGS(__jmpbuf) \
|
|---|
| 116 | ({ \
|
|---|
| 117 | __asm__ __volatile__ ( \
|
|---|
| 118 | " stw %%rp, 0(%%sr0, %0)\n" \
|
|---|
| 119 | "\t stw %%sp, 4(%%sr0, %0)\n" \
|
|---|
| 120 | "\t stw %%r0, 8(%%sr0, %0)\n" \
|
|---|
| 121 | "\t stw %%r3, 16(%%sr0, %0)\n" \
|
|---|
| 122 | "\t stw %%r4, 20(%%sr0, %0)\n" \
|
|---|
| 123 | "\t stw %%r5, 24(%%sr0, %0)\n" \
|
|---|
| 124 | "\t stw %%r6, 28(%%sr0, %0)\n" \
|
|---|
| 125 | "\t stw %%r7, 32(%%sr0, %0)\n" \
|
|---|
| 126 | "\t stw %%r8, 36(%%sr0, %0)\n" \
|
|---|
| 127 | "\t stw %%r9, 40(%%sr0, %0)\n" \
|
|---|
| 128 | "\t stw %%r10, 44(%%sr0, %0)\n" \
|
|---|
| 129 | "\t stw %%r11, 48(%%sr0, %0)\n" \
|
|---|
| 130 | "\t stw %%r12, 52(%%sr0, %0)\n" \
|
|---|
| 131 | "\t stw %%r13, 56(%%sr0, %0)\n" \
|
|---|
| 132 | "\t stw %%r14, 60(%%sr0, %0)\n" \
|
|---|
| 133 | "\t stw %%r15, 64(%%sr0, %0)\n" \
|
|---|
| 134 | "\t stw %%r16, 68(%%sr0, %0)\n" \
|
|---|
| 135 | "\t stw %%r17, 72(%%sr0, %0)\n" \
|
|---|
| 136 | "\t stw %%r18, 76(%%sr0, %0)\n" \
|
|---|
| 137 | "\t stw %%r19, 80(%%sr0, %0)\n" \
|
|---|
| 138 | "\t stw %%r20, 84(%%sr0, %0)\n" \
|
|---|
| 139 | "\t stw %%r21, 88(%%sr0, %0)\n" \
|
|---|
| 140 | "\t stw %%r22, 92(%%sr0, %0)\n" \
|
|---|
| 141 | "\t stw %%r23, 96(%%sr0, %0)\n" \
|
|---|
| 142 | "\t stw %%r24, 100(%%sr0, %0)\n" \
|
|---|
| 143 | "\t stw %%r25, 104(%%sr0, %0)\n" \
|
|---|
| 144 | "\t stw %%r26, 108(%%sr0, %0)\n" \
|
|---|
| 145 | "\t stw %%r27, 112(%%sr0, %0)\n" \
|
|---|
| 146 | "\t mfsp %%sr3, %%r1\n" \
|
|---|
| 147 | "\t stw %%r1, 116(%%sr0, %0)\n" \
|
|---|
| 148 | "\t mfsp %%sr4, %%r1\n" \
|
|---|
| 149 | "\t stw %%r1, 120(%%sr0, %0)\n" \
|
|---|
| 150 | : \
|
|---|
| 151 | : "r" (__jmpbuf)); \
|
|---|
| 152 | })
|
|---|
| 153 |
|
|---|
| 154 | /*
|
|---|
| 155 | * This macro will save the signal mask to the
|
|---|
| 156 | * __jmpbuf if __savemask is non-zero. By this
|
|---|
| 157 | * point in time, the other resisters have been
|
|---|
| 158 | * saved into the __jmpbuf.
|
|---|
| 159 | * The ldi 0, %r26 is actually SIG_BLOCK from
|
|---|
| 160 | * /usr/include/signal.h. Since the block is
|
|---|
| 161 | * an OR of the bits, this does not change the
|
|---|
| 162 | * mask, but returns it into the double word at
|
|---|
| 163 | * the address in %r24.
|
|---|
| 164 | */
|
|---|
| 165 | #define SAVE_SIGNAL_MASK(__jmpbuf,__savemask) \
|
|---|
| 166 | ({ \
|
|---|
| 167 | __asm__ __volatile__ ( \
|
|---|
| 168 | " comibt,=,n 0,%1,.+36\n" \
|
|---|
| 169 | "\t stw %%rp, -20(%%sr0, %%sp)\n" \
|
|---|
| 170 | "\t ldo 64(%%sp), %%sp\n" \
|
|---|
| 171 | "\t ldo 8(%0), %%r24\n" \
|
|---|
| 172 | "\t ldi 0, %%r25\n" \
|
|---|
| 173 | "\t .import sigprocmask,code\n" \
|
|---|
| 174 | "\t bl sigprocmask,%%rp\n" \
|
|---|
| 175 | "\t ldi 0, %%r26\n" \
|
|---|
| 176 | "\t ldo -64(%%sp), %%sp\n" \
|
|---|
| 177 | "\t ldw -20(%%sr0, %%sp), %%rp\n" \
|
|---|
| 178 | : \
|
|---|
| 179 | : "r" (__jmpbuf), \
|
|---|
| 180 | "r" (__savemask)); \
|
|---|
| 181 | })
|
|---|
| 182 |
|
|---|
| 183 | /*
|
|---|
| 184 | * Construct a jump buffer and unconditionally save
|
|---|
| 185 | * the signal mask. Return a 0 unconditinoally.
|
|---|
| 186 | * Care is taken here and in the macros to assume
|
|---|
| 187 | * the __jumpbuf is in %r26 and that the return
|
|---|
| 188 | * value will be in %r28. It is done this way to
|
|---|
| 189 | * prevent a frame from being built and any registers
|
|---|
| 190 | * from being spilled.
|
|---|
| 191 | */
|
|---|
| 192 | int setjmp(register void *jmpbuf)
|
|---|
| 193 | {
|
|---|
| 194 | register int __jmpbuf asm ("%r26");
|
|---|
| 195 |
|
|---|
| 196 | SAVE_REGS(__jmpbuf);
|
|---|
| 197 | SAVE_SIGNAL_MASK(__jmpbuf, 1);
|
|---|
|
|---|