3 Copyright (c) 2005 Red Hat Incorporated.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
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.
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.
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.
33 #if defined(__r8c_cpu__) || defined(__m16c_cpu__)
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.
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.
49 Jump buffer sizes: 21 bytes for 16 bit, 34 bytes for 24 bit.
54 #ifdef A16 /* 16 bit versions */
59 pushm r1,r2,r3,a0,a1,sb,fb
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> */
64 mov.w r1,a1 ; a1 is the destination of smovf
66 stc sp,a0 ; r1h:a0 is the source of smovf
69 mov.w #19,r3 ; plus two for sp later
74 popm r1,r2,r3,a0,a1,sb,fb
80 mov.w r1,a0 ; pointer to jump buf
81 mov.w r2,r0 ; setjmp's "new" return value
83 mov.b #0,r1h ; r1h: a0 is the source, now jmpbuf
84 mov.w [a0],a1 ; dest is new stack
90 ;; now return to our caller with this newly restored frame
91 popm r1,r2,r3,a0,a1,sb,fb
94 #else /* 24 bit versions */
99 pushm r1,r2,r3,a0,a1,sb,fb
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> */
104 mov.l 8[fb],a1 ; a1 is the destination of smovf
105 stc sp,a0 ; r1h:a0 is the source of smovf
108 mov.w #30,r3 ; plus two for sp later
111 ; Return 0 to caller.
113 popm r1,r2,r3,a0,a1,sb,fb
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
123 mov.l [a0],a1 ; dest is new stack
129 ;; now return to our caller with this newly restored frame
130 popm r1,r2,r3,a0,a1,sb,fb