4 ****************************************************************************
5 * Copyright IBM Corporation 1988, 1989 - All Rights Reserved *
7 * Permission to use, copy, modify, and distribute this software and its *
8 * documentation for any purpose and without fee is hereby granted, *
9 * provided that the above copyright notice appear in all copies and *
10 * that both that copyright notice and this permission notice appear in *
11 * supporting documentation, and that the name of IBM not be used in *
12 * advertising or publicity pertaining to distribution of the software *
13 * without specific, written prior permission. *
15 * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL *
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM *
17 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY *
18 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER *
19 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING *
20 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
21 ****************************************************************************
28 /* lws 92.11.18 I don't know if we have to save the TOC (R2) or not...
29 * Note that stack-frame is supposed to be aligned on
30 * a double-word boundary.
31 * For details about RIOS calling conventions
32 * see the Assembler manual and /usr/include/sys/asdef.s
37 * savecontext(f, area1, newsp)
38 * int (*f)(); struct savearea *area1; char *newsp;
60 .set szdsa, 8*nfprs+4*ngprs+linkarea+argarea
62 .csect .savecontext[PR]
63 .globl .savecontext[PR]
65 mflr r0 # save link register
68 * save floating point registers. Interleave some other stuff for
69 * timing reasons. Set up conditions and registers for branches
70 * early, so that processor can prefetch instructions.
80 l 11, 0(a_f) # r11 <- *(a_f)
85 cmpi cr0, a_newsp, 0 # cr0 <- (a_newsp :: 0)
91 mtlr 11 # set up lr early so prefetch works
97 st r0, 8(r1) # save return addr
103 st 12, 4(r1) # save CR
110 * save general-purpose registers
112 stm 12, -8*nfprs-4*ngprs(r1)# save the general-purpose regs
113 stu r1, -szdsa(r1) # dec SP and save back chain
115 l r7, PRE_Block.S(toc) # r7 <- &PRE_Block
116 cal r6, 1(r0) # r6 <- #1
117 st r6, 0(r7) # r6 -> PRE_Block
119 st r1, topstack(a_area1) # save old SP
121 beq L1 # if (a_newsp == 0) goto L1
123 mr r1, r5 # r1 <- a_newsp -- load new SP
125 L1: brl # pc <- lr -- (*a_f)()
128 * returnto(area2) This is a little jumbled, I tried to interleave
129 * memory accesses with simple instructions for speed, and I tried to
130 * set up the link register and condition register reasonably early
131 * so that processor instruction prefetching might help us out a little.
138 l r1, topstack(a_area2) # r1 <- a_area2->topstack
139 cal r1, szdsa(r1) # pop off frame
140 l r7, PRE_Block.S(toc) # r7 <- &PRE_Block
142 l 8, 8(1) # restore lr
143 mtlr 8 # do it early so prefetch works
145 lm 12, -8*nfprs-4*ngprs(r1)
146 cal r6, 0(r0) # r6 <- #0
147 mtcrf 0x38, 12 # put back cr
148 st r6, 0(r7) # r6 -> PRE_Block
172 brl # pc <- lr -- return
177 .tc PRE_Block[tc], PRE_Block[ua]
178 .extern PRE_Block[ua]