4 ; Special static parts of wimp
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Steel library.
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)
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.
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.
27 ;----- Standard header ------------------------------------------------------
32 ;----- Private data ---------------------------------------------------------
38 ;----- Some flags and things -----------------------------------------------
40 dpoll__savefp EQU 1<<24 ;Bit to set to save FP state
42 ;----- Polling code ---------------------------------------------------------
44 AREA |C$$Code|,CODE,READONLY
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
55 STMFD sp!,{lr} ;Look after some registers
57 ; --- Figure out about saving the FP status ---
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
65 ; --- Call the SWI and get out again ---
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
76 ; --- wimp_pollidle ---
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
86 STMFD sp!,{v1-v3,lr} ;Look after some registers
88 ; --- Figure out about saving the FP status ---
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
96 ; --- Call the SWI and get out again ---
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
107 ; --- wimp_save_fp_state_on_poll ---
109 EXPORT wimp_save_fp_state_on_poll
110 wimp_save_fp_state_on_poll
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
120 ; --- wimp_corrupt_fp_state_on_poll ---
122 EXPORT wimp_corrupt_fp_state_on_poll
123 wimp_corrupt_fp_state_on_poll
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
133 ; --- wimp__doPoll ---
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
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.
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
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
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
170 ; --- wimp__doPollIdle ---
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
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.
183 wimp__doPollIdle ROUT
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
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
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
211 ; On exit: v1 corrupted
215 RFS v1 ;Read the FP status word
216 STMFD sp!,{v1} ;Stack it
217 MOV v1,#0 ;We will zero the FPSR
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
229 ; On exit: v1 corrupted
233 MOV v1,#0 ;We will zero the FPSR
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
244 ;----- Include the main wimp veneers ----------------------------------------