[444] | 1 | /* |
---|
| 2 | |
---|
| 3 | Copyright (c) 2005 Red Hat Incorporated. |
---|
| 4 | All rights reserved. |
---|
| 5 | |
---|
| 6 | Redistribution and use in source and binary forms, with or without |
---|
| 7 | modification, are permitted provided that the following conditions are met: |
---|
| 8 | |
---|
| 9 | Redistributions of source code must retain the above copyright |
---|
| 10 | notice, this list of conditions and the following disclaimer. |
---|
| 11 | |
---|
| 12 | Redistributions in binary form must reproduce the above copyright |
---|
| 13 | notice, this list of conditions and the following disclaimer in the |
---|
| 14 | documentation and/or other materials provided with the distribution. |
---|
| 15 | |
---|
| 16 | The name of Red Hat Incorporated may not be used to endorse |
---|
| 17 | or promote products derived from this software without specific |
---|
| 18 | prior written permission. |
---|
| 19 | |
---|
| 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
| 23 | DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY |
---|
| 24 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
| 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
| 26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
| 27 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
| 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 30 | |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | #if defined(__r8c_cpu__) || defined(__m16c_cpu__) |
---|
| 34 | #define A16 1 |
---|
| 35 | #endif |
---|
| 36 | |
---|
| 37 | /* We implement setjmp/longjmp much like the way gcc implements |
---|
| 38 | exceptions - we create new stack frames, then switch to them and |
---|
| 39 | return. Thus, the two setjmp's below each push all the relevent |
---|
| 40 | registers, then copy the whole frame into the buffer (first $sp is |
---|
| 41 | moved, then smovf copies the frame itself), and the two longjmps |
---|
| 42 | restore $sp, copy the frame back into place, and issue the same |
---|
| 43 | return as the setjmp would have used. |
---|
| 44 | |
---|
| 45 | Since the sizes of registers differs between the 16 and 24 bit |
---|
| 46 | models, we provide separate implementations for each rather than |
---|
| 47 | trying to parameterize them. |
---|
| 48 | |
---|
| 49 | Jump buffer sizes: 21 bytes for 16 bit, 34 bytes for 24 bit. |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | .text |
---|
| 53 | |
---|
| 54 | #ifdef A16 /* 16 bit versions */ |
---|
| 55 | |
---|
| 56 | .global _setjmp |
---|
| 57 | _setjmp: |
---|
| 58 | enter #0 |
---|
| 59 | pushm r1,r2,r3,a0,a1,sb,fb |
---|
| 60 | |
---|
| 61 | ; At this point, the stack looks like this: |
---|
| 62 | ; ... [pc:3] [oldfb:2] <fb> [r1:2] [r2:2] [r3:2] [a0:2] [a1:2] [sb:2] [fb:2] <sp> */ |
---|
| 63 | |
---|
| 64 | mov.w r1,a1 ; a1 is the destination of smovf |
---|
| 65 | mov.b #0,r1h |
---|
| 66 | stc sp,a0 ; r1h:a0 is the source of smovf |
---|
| 67 | mov.w a0,[a1] |
---|
| 68 | add.w #2,a1 |
---|
| 69 | mov.w #19,r3 ; plus two for sp later |
---|
| 70 | smovf.b |
---|
| 71 | |
---|
| 72 | ; Return 0 to caller. |
---|
| 73 | mov.w #0,r0 |
---|
| 74 | popm r1,r2,r3,a0,a1,sb,fb |
---|
| 75 | exitd |
---|
| 76 | |
---|
| 77 | .global _longjmp |
---|
| 78 | _longjmp: |
---|
| 79 | enter #0 |
---|
| 80 | mov.w r1,a0 ; pointer to jump buf |
---|
| 81 | mov.w r2,r0 ; setjmp's "new" return value |
---|
| 82 | |
---|
| 83 | mov.b #0,r1h ; r1h: a0 is the source, now jmpbuf |
---|
| 84 | mov.w [a0],a1 ; dest is new stack |
---|
| 85 | ldc a1,sp |
---|
| 86 | add.w #2,a0 |
---|
| 87 | mov.w #19,r3 |
---|
| 88 | smovf.b |
---|
| 89 | |
---|
| 90 | ;; now return to our caller with this newly restored frame |
---|
| 91 | popm r1,r2,r3,a0,a1,sb,fb |
---|
| 92 | exitd |
---|
| 93 | |
---|
| 94 | #else /* 24 bit versions */ |
---|
| 95 | |
---|
| 96 | .global _setjmp |
---|
| 97 | _setjmp: |
---|
| 98 | enter #0 |
---|
| 99 | pushm r1,r2,r3,a0,a1,sb,fb |
---|
| 100 | |
---|
| 101 | ; At this point, the stack looks like this: |
---|
| 102 | ; ... [jbuf:4] [pc:4] [oldfb:4] <fb> [r1:2] [r2:2] [r3:2] [a0:4] [a1:4] [sb:4] [fb:4] <sp> */ |
---|
| 103 | |
---|
| 104 | mov.l 8[fb],a1 ; a1 is the destination of smovf |
---|
| 105 | stc sp,a0 ; r1h:a0 is the source of smovf |
---|
| 106 | mov.l a0,[a1] |
---|
| 107 | add.l #4,a1 |
---|
| 108 | mov.w #30,r3 ; plus two for sp later |
---|
| 109 | smovf.b |
---|
| 110 | |
---|
| 111 | ; Return 0 to caller. |
---|
| 112 | mov.w #0,r0 |
---|
| 113 | popm r1,r2,r3,a0,a1,sb,fb |
---|
| 114 | exitd |
---|
| 115 | |
---|
| 116 | .global _longjmp |
---|
| 117 | _longjmp: |
---|
| 118 | enter #0 |
---|
| 119 | ; ... [rv:2] [jbuf:4] [pc:4] [oldfb:4] <fb> |
---|
| 120 | mov.l 8[fb],a0 ; pointer to jump buf |
---|
| 121 | mov.w 12[fb],r0 ; setjmp's "new" return value |
---|
| 122 | |
---|
| 123 | mov.l [a0],a1 ; dest is new stack |
---|
| 124 | ldc a1,sp |
---|
| 125 | add.l #4,a0 |
---|
| 126 | mov.w #30,r3 |
---|
| 127 | smovf.b |
---|
| 128 | |
---|
| 129 | ;; now return to our caller with this newly restored frame |
---|
| 130 | popm r1,r2,r3,a0,a1,sb,fb |
---|
| 131 | exitd |
---|
| 132 | #endif |
---|
| 133 | |
---|