chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Steel / s / wimp_stat
1 ;
2 ; wimp_stat.s
3 ;
4 ; Special static parts of wimp
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's Steel library.
12 ;
13 ; Steel is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Steel is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Steel.  If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29                 GET     libs:header
30                 GET     libs:SWIs
31
32 ;----- Private data ---------------------------------------------------------
33
34                 AREA    |C$$data|,DATA
35
36 wimp__savefp    DCD     1
37
38 ;----- Some flags and things -----------------------------------------------
39
40 dpoll__savefp   EQU     1<<24                   ;Bit to set to save FP state
41
42 ;----- Polling code ---------------------------------------------------------
43
44                 AREA    |C$$Code|,CODE,READONLY
45
46 ; --- wimp_poll ---
47 ;
48 ; On entry:     a1 == Wimp_Poll event mask
49 ;               a2 == pointer to wimp_eventstr to be filled in
50 ; On exit:      a1 == pointer to an os_error, or nothing
51
52                 EXPORT  wimp_poll
53 wimp_poll       ROUT
54
55                 STMFD   sp!,{lr}                ;Look after some registers
56
57                 ; --- Figure out about saving the FP status ---
58
59                 LDR     a4,=wimp__savefp        ;Find the magic flag
60                 LDR     a4,[a4]                 ;Get the value of the flag
61                 CMP     a4,#0                   ;Do we have to save FP state?
62                 ORRNE   a1,a1,#dpoll__savefp    ;Yes -- set the flag
63                 BICNE   a1,a1,#dpoll__savefp    ;No -- clear the flag
64
65                 ; --- Call the SWI and get out again ---
66
67                 ADD     a2,a2,#4                ;Point to the big poll block
68                 BL      wimp__doPoll            ;Get a Wimp event
69                 SUB     a2,a2,#4                ;Point to the wimp_eventstr
70                 STRVC   a1,[a2]                 ;Store the reason code away
71                 MOVVC   a1,#0                   ;If no error, return NULL
72                 LDMFD   sp!,{pc}^               ;Return to caller nicely
73
74                 LTORG
75
76 ; --- wimp_pollidle ---
77 ;
78 ; On entry:     a1 == Wimp_Poll event mask
79 ;               a2 == pointer to wimp_eventstr to be filled in
80 ;               a3 == time before which thou shalt not return
81 ; On exit:      a1 == pointer to an os_error, or nothing
82
83                 EXPORT  wimp_pollidle
84 wimp_pollidle   ROUT
85
86                 STMFD   sp!,{v1-v3,lr}          ;Look after some registers
87
88                 ; --- Figure out about saving the FP status ---
89
90                 LDR     a4,=wimp__savefp        ;Find the magic flag
91                 LDR     a4,[a4]                 ;Get the value of the flag
92                 CMP     a4,#0                   ;Do we have to save FP state?
93                 ORRNE   a1,a1,#dpoll__savefp    ;Yes -- set the flag
94                 BICNE   a1,a1,#dpoll__savefp    ;No -- clear the flag
95
96                 ; --- Call the SWI and get out again ---
97
98                 ADD     a2,a2,#4                ;Point to the big poll block
99                 BL      wimp__doPollIdle        ;Get a Wimp event
100                 SUB     a2,a2,#4                ;Point to the wimp_eventstr
101                 STRVC   a1,[a2]                 ;Store the reason code away
102                 MOVVC   a1,#0                   ;If no error, return NULL
103                 LDMFD   sp!,{v1-v3,pc}^         ;Return to caller nicely
104
105                 LTORG
106
107 ; --- wimp_save_fp_state_on_poll ---
108
109                 EXPORT  wimp_save_fp_state_on_poll
110 wimp_save_fp_state_on_poll
111                 ROUT
112
113                 LDR     a1,=wimp__savefp        ;Find the magic flag
114                 MOV     a2,#1                   ;Store a TRUE value away
115                 STR     a2,[a1]                 ;Tuck it into my workspace
116                 MOVS    pc,lr                   ;Return to the caller
117
118                 LTORG
119
120 ; --- wimp_corrupt_fp_state_on_poll ---
121
122                 EXPORT  wimp_corrupt_fp_state_on_poll
123 wimp_corrupt_fp_state_on_poll
124                 ROUT
125
126                 LDR     a1,=wimp__savefp        ;Find the magic flag
127                 MOV     a2,#0                   ;Store a FALSE value away
128                 STR     a2,[a1]                 ;Tuck it into my workspace
129                 MOVS    pc,lr                   ;Return to the caller
130
131                 LTORG
132
133 ; --- wimp__doPoll ---
134 ;
135 ; On entry:     a1 == event mask
136 ;               a2 == pointer to wimp poll block
137 ;               a4 == pointer to poll word if bit 22 of a1 is set
138 ; On exit:      a1 == reason code returned by Wimp_Poll
139 ;               Other registers preserved
140 ;
141 ; Floating point status is preserved if a1 on entry has bit 24 set and the
142 ; floating point emulator or hardware is present.  The floating point
143 ; registers preserved are f4-f7 and the FPSR.
144
145 wimp__doPoll    ROUT
146
147                 STMFD   sp!,{v1-v3,lr}
148
149                 MOV     v2,#0                   ;Don't restore FP state
150                 TST     a1,#1<<24               ;Does caller want FP saved?
151                 BIC     v3,a1,#1<<24            ;We're doing it, not the WIMP
152                 BEQ     %00                     ;No -- skip this bit
153                 SWI     XFPEmulator_Version     ;Is the FPE/FPA there?
154                 MOVVC   v2,#1                   ;Yes -- set flag to restore
155                 BLVC    save_fp                 ;Save the FP state
156
157 00              MOV     a1,v3                   ;Restore event mask
158                 SWI     XWimp_Poll              ;Do the SWI call
159                 ORRVS   v2,v2,#2                ;Set bit 1 of v2 if error
160
161                 TST     v2,#1                   ;Is bit 0 set?
162                 BLNE    restore_fp              ;Yes -- restore FP state
163                 TST     v2,#2                   ;Was there an error?
164                 LDMFD   sp!,{v1-v3,lr}          ;Restore all registers anyhow
165                 BICEQS  pc,lr,#V_flag           ;No -- clear V flag
166                 ORRS    pc,lr,#V_flag           ;Yes -- set V flag
167
168                 LTORG
169
170 ; --- wimp__doPollIdle ---
171 ;
172 ; On entry:     a1 == event mask
173 ;               a2 == pointer to wimp poll block
174 ;               a3 == earliest time to return with an idle event
175 ;               a4 == pointer to poll word if bit 22 of a1 is set
176 ; On exit:      a1 == reason code returned by Wimp_Poll
177 ;               Other registers preserved
178 ;
179 ; Floating point status is preserved if a1 on entry has bit 24 set and the
180 ; floating point emulator or hardware is present.  The floating point
181 ; registers preserved are f4-f7 and the FPSR.
182
183 wimp__doPollIdle ROUT
184
185                 STMFD   sp!,{v1-v3,lr}
186
187                 MOV     v2,#0                   ;Don't restore FP state
188                 TST     a1,#1<<24               ;Does caller want FP saved?
189                 BIC     v3,a1,#1<<24            ;We're doing it, not the WIMP
190                 BEQ     %00                     ;No -- skip this bit
191                 SWI     XFPEmulator_Version     ;Is the FPE/FPA there?
192                 MOVVC   v2,#1                   ;Yes -- set flag to restore
193                 BLVC    save_fp                 ;Save the FP state
194
195 00              MOV     a1,v3                   ;Restore event mask
196                 SWI     XWimp_PollIdle          ;Do the SWI call
197                 ORRVS   v2,v2,#2                ;Set bit 1 of v2 if error
198
199                 TST     v2,#1                   ;Is bit 0 set?
200                 BLNE    restore_fp              ;Yes -- restore FP state
201                 TST     v2,#2                   ;Was there an error?
202                 LDMFD   sp!,{v1-v3,lr}          ;Restore all registers anyhow
203                 BICEQS  pc,lr,#V_flag           ;No -- clear V flag
204                 ORRS    pc,lr,#V_flag           ;Yes -- set V flag
205
206                 LTORG
207
208 ; --- save_fp ---
209 ;
210 ; On entry:     --
211 ; On exit:      v1 corrupted
212
213 save_fp         ROUT
214
215                 RFS     v1                      ;Read the FP status word
216                 STMFD   sp!,{v1}                ;Stack it
217                 MOV     v1,#0                   ;We will zero the FPSR
218                 WFS     v1                      ;Zero it
219                 SUB     sp,sp,#4*12             ;Leave space for 4 FP regs
220                 STFE    f4,[sp,#0*12]           ;Stack F4
221                 STFE    f5,[sp,#1*12]           ;Stack F5
222                 STFE    f6,[sp,#2*12]           ;Stack F6
223                 STFE    f7,[sp,#3*12]           ;Stack F7
224                 MOVS    pc,lr                   ;Return to caller
225
226 ; --- restore_fp ---
227 ;
228 ; On entry:     --
229 ; On exit:      v1 corrupted
230
231 restore_fp      ROUT
232
233                 MOV     v1,#0                   ;We will zero the FPSR
234                 WFS     v1                      ;Zero it
235                 LDFE    f4,[sp,#0*12]           ;Unstack F4
236                 LDFE    f5,[sp,#1*12]           ;Unstack F5
237                 LDFE    f6,[sp,#2*12]           ;Unstack F6
238                 LDFE    f7,[sp,#3*12]           ;Unstack F7
239                 ADD     sp,sp,#4*12             ;Move stack ptr up past FP
240                 LDMFD   sp!,{v1}                ;Restore FPSR
241                 WFS     v1                      ;Write it to the FPSR
242                 MOVS    pc,lr                   ;Return to caller
243
244 ;----- Include the main wimp veneers ----------------------------------------
245
246                 LNK     s.wimp_main