source: rtems/c/src/lib/libcpu/sparc/reg_win/window.S @ 8639685

5
Last change on this file since 8639685 was 8639685, checked in by Jacob Hansen <jacob.hansen@…>, on 10/28/16 at 14:05:56

sparc: Adjust assembly to improve compability with LLVM

  • All references of %0 changed to %g0
  • 'call label,0' changed to 'call label'. According to the sparc specification call does not take any registers
  • '.seg "text"' changed to '.section ".text"'
  • the synonym stub is replaced with stb
  • the synonym stuh is replaced with sth
  • Property mode set to 100644
File size: 8.0 KB
Line 
1/*
2 *  window.s
3 *
4 *  This file contains the register window management routines for the
5 *  SPARC architecture.  Trap handlers for the following capabilities
6 *  are included in this file:
7 *
8 *    + Window Overflow
9 *    + Window Underflow
10 *    + Flushing All Windows
11 *
12 *  COPYRIGHT:
13 *
14 *  This file includes the window overflow and underflow handlers from
15 *  the file srt0.s provided with the binary distribution of the SPARC
16 *  Instruction Simulator (SIS) found at
17 *  ftp://ftp.estec.esa.nl/pub/ws/wsd/erc32.
18 *
19 *  COPYRIGHT (c) 1995. European Space Agency.
20 *
21 *  This terms of the RTEMS license apply to this file.
22 */
23
24#include <rtems/asm.h>
25
26        .section    ".text"
27        /*
28         *  Window overflow trap handler.
29         *
30         *  On entry:
31         *
32         *    prev regwin l1 = pc
33         *    prev regwin l2 = npc
34         */
35
36        PUBLIC(window_overflow_trap_handler)
37
38SYM(window_overflow_trap_handler):
39
40        /*
41         *  Calculate new WIM by "rotating" the valid bits in the WIM right
42         *  by one position.  The following shows how the bits move for a SPARC
43         *  cpu implementation where SPARC_NUMBER_OF_REGISTER_WINDOWS is 8.
44         *
45         *    OLD WIM = 76543210
46         *    NEW WIM = 07654321
47         *
48         *  NOTE: New WIM must be stored in a global register since the
49         *        "save" instruction just prior to the load of the wim
50         *        register will result in the local register set changing.
51         */
52
53        std  %l0, [%sp + 0x00]           ! save local register set
54        std  %l2, [%sp + 0x08]
55        mov  %wim, %l3
56        sll  %l3, SPARC_NUMBER_OF_REGISTER_WINDOWS-1 , %l2
57                                         ! l2  = WIM << (Number Windows - 1)
58        std  %l4, [%sp + 0x10]
59        std  %l6, [%sp + 0x18]
60        srl  %l3, 1, %l3                 ! l3  = WIM >> 1
61        wr   %l3, %l2, %wim              ! WIM = (WIM >> 1) ^
62                                         !       (WIM << (Number Windows - 1))
63                                         ! 3 instruction delay not needed here
64        std  %i0, [%sp + 0x20]           ! save input register set
65        std  %i2, [%sp + 0x28]
66        std  %i4, [%sp + 0x30]
67        std  %i6, [%sp + 0x38]
68        restore                          ! Go back to trap window.
69        jmp  %l1                         ! Re-execute save.
70         rett %l2
71
72        /*
73         *  Window underflow trap handler.
74         *
75         *  On entry:
76         *
77         *    l1 = pc
78         *    l2 = npc
79         *    l3 = wim (from trap vector)
80         *    l4 = wim << 1 (from trap vector)
81         */
82
83        PUBLIC(window_underflow_trap_handler)
84
85SYM(window_underflow_trap_handler):
86
87        /*
88         *  Calculate new WIM by "rotating" the valid bits in the WIM left
89         *  by one position.  The following shows how the bits move for a SPARC
90         *  cpu implementation where SPARC_NUMBER_OF_REGISTER_WINDOWS is 8.
91         *
92         *    OLD WIM = 76543210
93         *    NEW WIM = 07654321
94         *
95         *  NOTE: New WIM must be stored in a global register since the
96         *        "save" instruction just prior to the load of the wim
97         *        register will result in the local register set changing.
98         */
99
100        srl  %l3, SPARC_NUMBER_OF_REGISTER_WINDOWS-1, %l5
101        or   %l5, %l4, %l5              ! l5 = (WIM << 1) |
102                                        !      (WIM >> (Number Windows-1))
103        mov  %l5, %wim                  ! load the new WIM
104        nop; nop; nop                   ! 3 slot delay
105        restore                         ! Two restores to get into the
106        restore                         ! window to restore
107        ldd  [%sp + 0x00], %l0          ! First the local register set
108        ldd  [%sp + 0x08], %l2
109        ldd  [%sp + 0x10], %l4
110        ldd  [%sp + 0x18], %l6
111        ldd  [%sp + 0x20], %i0          ! Then the input registers
112        ldd  [%sp + 0x28], %i2
113        ldd  [%sp + 0x30], %i4
114        ldd  [%sp + 0x38], %i6
115        save                            ! Get back to the trap window.
116        save
117        jmp  %l1                        ! Re-execute restore.
118         rett  %l2
119
120        /*
121         *  Flush All Windows trap handler.
122         *
123         *  Flush all windows with valid contents except the current one
124         *  and the one we will be returning to.
125         *
126         *  In examining the set register windows, one may logically divide
127         *  the windows into sets (some of which may be empty) based on their
128         *  current status:
129         *
130         *    + current (i.e. in use),
131         *    + used (i.e. a restore would not trap)
132         *    + invalid (i.e. 1 in corresponding bit in WIM)
133         *    + unused
134         *
135         *  Either the used or unused set of windows may be empty.
136         *
137         *  NOTE: We assume only one bit is set in the WIM at a time.
138         *
139         *  Given a CWP of 5 and a WIM of 0x1, the registers are divided
140         *  into sets as follows:
141         *
142         *    + 0   - invalid
143         *    + 1-4 - unused
144         *    + 5   - current
145         *    + 6-7 - used
146         *
147         *  In this case, we only would save the used windows which we
148         *  will not be returning to -- 6.
149         *
150         *    Register Usage while saving the windows:
151         *      g1 = current PSR
152         *      g2 = current wim
153         *      g3 = CWP
154         *      g4 = wim scratch
155         *      g5 = scratch
156         *
157         *  On entry:
158         *
159         *    l0 = psr (from trap table)
160         *    l1 = pc
161         *    l2 = npc
162         */
163
164        PUBLIC(window_flush_trap_handler)
165
166SYM(window_flush_trap_handler):
167        /*
168         *  Save the global registers we will be using
169         */
170
171        mov     %g1, %l3
172        mov     %g2, %l4
173        mov     %g3, %l5
174        mov     %g4, %l6
175        mov     %g5, %l7
176
177        mov     %l0, %g1                      ! g1 = psr
178        mov     %wim, %g2                     ! g2 = wim
179        and     %l0, SPARC_PSR_CWP_MASK, %g3  ! g3 = CWP
180
181        add     %g3, 1, %g5                   ! g5 = CWP + 1
182        and     %g5, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g5
183
184        mov     1, %g4
185        sll     %g4, %g5, %g4                 ! g4 = WIM mask for CWP+1 invalid
186
187        restore                               ! go back one register window
188
189save_frame_loop:
190        sll     %g4, 1, %g5                   ! rotate the "wim" left 1
191        srl     %g4, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g4
192        or      %g4, %g5, %g4                 ! g4 = wim if we do one restore
193
194        /*
195         *  If a restore would not underflow, then continue.
196         */
197
198        andcc   %g4, %g2, %g0                 ! Any windows to flush?
199        bnz     done_flushing                 ! No, then continue
200        nop
201
202        restore                               ! back one window
203
204        /*
205         *  Now save the window just as if we overflowed to it.
206         */
207
208        std     %l0, [%sp + CPU_STACK_FRAME_L0_OFFSET]
209        std     %l2, [%sp + CPU_STACK_FRAME_L2_OFFSET]
210        std     %l4, [%sp + CPU_STACK_FRAME_L4_OFFSET]
211        std     %l6, [%sp + CPU_STACK_FRAME_L6_OFFSET]
212
213        std     %i0, [%sp + CPU_STACK_FRAME_I0_OFFSET]
214        std     %i2, [%sp + CPU_STACK_FRAME_I2_OFFSET]
215        std     %i4, [%sp + CPU_STACK_FRAME_I4_OFFSET]
216        std     %i6, [%sp + CPU_STACK_FRAME_I6_FP_OFFSET]
217
218        ba      save_frame_loop
219        nop
220
221done_flushing:
222
223        add     %g3, 2, %g3                   ! calculate desired WIM
224        and     %g3, SPARC_NUMBER_OF_REGISTER_WINDOWS - 1, %g3
225        mov     1, %g4
226        sll     %g4, %g3, %g4                 ! g4 = new WIM
227        mov     %g4, %wim
228
229        mov     %g1, %psr                     ! restore PSR
230        nop
231        nop
232        nop
233
234        /*
235         *  Restore the global registers we used
236         */
237
238        mov     %l3, %g1
239        mov     %l4, %g2
240        mov     %l5, %g3
241        mov     %l6, %g4
242        mov     %l7, %g5
243
244        jmpl    %l2, %g0
245        rett    %l2 + 4
246
247/* end of file */
Note: See TracBrowser for help on using the repository browser.