; ; wimp_stat.s ; ; Special static parts of wimp ; ; © 1994-1998 Straylight ; ;----- Licensing note ------------------------------------------------------- ; ; This file is part of Straylight's Steel library. ; ; Steel is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2, or (at your option) ; any later version. ; ; Steel is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with Steel. If not, write to the Free Software Foundation, ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ;----- Standard header ------------------------------------------------------ GET libs:header GET libs:SWIs ;----- Private data --------------------------------------------------------- AREA |C$$data|,DATA wimp__savefp DCD 1 ;----- Some flags and things ----------------------------------------------- dpoll__savefp EQU 1<<24 ;Bit to set to save FP state ;----- Polling code --------------------------------------------------------- AREA |C$$Code|,CODE,READONLY ; --- wimp_poll --- ; ; On entry: a1 == Wimp_Poll event mask ; a2 == pointer to wimp_eventstr to be filled in ; On exit: a1 == pointer to an os_error, or nothing EXPORT wimp_poll wimp_poll ROUT STMFD sp!,{lr} ;Look after some registers ; --- Figure out about saving the FP status --- LDR a4,=wimp__savefp ;Find the magic flag LDR a4,[a4] ;Get the value of the flag CMP a4,#0 ;Do we have to save FP state? ORRNE a1,a1,#dpoll__savefp ;Yes -- set the flag BICNE a1,a1,#dpoll__savefp ;No -- clear the flag ; --- Call the SWI and get out again --- ADD a2,a2,#4 ;Point to the big poll block BL wimp__doPoll ;Get a Wimp event SUB a2,a2,#4 ;Point to the wimp_eventstr STRVC a1,[a2] ;Store the reason code away MOVVC a1,#0 ;If no error, return NULL LDMFD sp!,{pc}^ ;Return to caller nicely LTORG ; --- wimp_pollidle --- ; ; On entry: a1 == Wimp_Poll event mask ; a2 == pointer to wimp_eventstr to be filled in ; a3 == time before which thou shalt not return ; On exit: a1 == pointer to an os_error, or nothing EXPORT wimp_pollidle wimp_pollidle ROUT STMFD sp!,{v1-v3,lr} ;Look after some registers ; --- Figure out about saving the FP status --- LDR a4,=wimp__savefp ;Find the magic flag LDR a4,[a4] ;Get the value of the flag CMP a4,#0 ;Do we have to save FP state? ORRNE a1,a1,#dpoll__savefp ;Yes -- set the flag BICNE a1,a1,#dpoll__savefp ;No -- clear the flag ; --- Call the SWI and get out again --- ADD a2,a2,#4 ;Point to the big poll block BL wimp__doPollIdle ;Get a Wimp event SUB a2,a2,#4 ;Point to the wimp_eventstr STRVC a1,[a2] ;Store the reason code away MOVVC a1,#0 ;If no error, return NULL LDMFD sp!,{v1-v3,pc}^ ;Return to caller nicely LTORG ; --- wimp_save_fp_state_on_poll --- EXPORT wimp_save_fp_state_on_poll wimp_save_fp_state_on_poll ROUT LDR a1,=wimp__savefp ;Find the magic flag MOV a2,#1 ;Store a TRUE value away STR a2,[a1] ;Tuck it into my workspace MOVS pc,lr ;Return to the caller LTORG ; --- wimp_corrupt_fp_state_on_poll --- EXPORT wimp_corrupt_fp_state_on_poll wimp_corrupt_fp_state_on_poll ROUT LDR a1,=wimp__savefp ;Find the magic flag MOV a2,#0 ;Store a FALSE value away STR a2,[a1] ;Tuck it into my workspace MOVS pc,lr ;Return to the caller LTORG ; --- wimp__doPoll --- ; ; On entry: a1 == event mask ; a2 == pointer to wimp poll block ; a4 == pointer to poll word if bit 22 of a1 is set ; On exit: a1 == reason code returned by Wimp_Poll ; Other registers preserved ; ; Floating point status is preserved if a1 on entry has bit 24 set and the ; floating point emulator or hardware is present. The floating point ; registers preserved are f4-f7 and the FPSR. wimp__doPoll ROUT STMFD sp!,{v1-v3,lr} MOV v2,#0 ;Don't restore FP state TST a1,#1<<24 ;Does caller want FP saved? BIC v3,a1,#1<<24 ;We're doing it, not the WIMP BEQ %00 ;No -- skip this bit SWI XFPEmulator_Version ;Is the FPE/FPA there? MOVVC v2,#1 ;Yes -- set flag to restore BLVC save_fp ;Save the FP state 00 MOV a1,v3 ;Restore event mask SWI XWimp_Poll ;Do the SWI call ORRVS v2,v2,#2 ;Set bit 1 of v2 if error TST v2,#1 ;Is bit 0 set? BLNE restore_fp ;Yes -- restore FP state TST v2,#2 ;Was there an error? LDMFD sp!,{v1-v3,lr} ;Restore all registers anyhow BICEQS pc,lr,#V_flag ;No -- clear V flag ORRS pc,lr,#V_flag ;Yes -- set V flag LTORG ; --- wimp__doPollIdle --- ; ; On entry: a1 == event mask ; a2 == pointer to wimp poll block ; a3 == earliest time to return with an idle event ; a4 == pointer to poll word if bit 22 of a1 is set ; On exit: a1 == reason code returned by Wimp_Poll ; Other registers preserved ; ; Floating point status is preserved if a1 on entry has bit 24 set and the ; floating point emulator or hardware is present. The floating point ; registers preserved are f4-f7 and the FPSR. wimp__doPollIdle ROUT STMFD sp!,{v1-v3,lr} MOV v2,#0 ;Don't restore FP state TST a1,#1<<24 ;Does caller want FP saved? BIC v3,a1,#1<<24 ;We're doing it, not the WIMP BEQ %00 ;No -- skip this bit SWI XFPEmulator_Version ;Is the FPE/FPA there? MOVVC v2,#1 ;Yes -- set flag to restore BLVC save_fp ;Save the FP state 00 MOV a1,v3 ;Restore event mask SWI XWimp_PollIdle ;Do the SWI call ORRVS v2,v2,#2 ;Set bit 1 of v2 if error TST v2,#1 ;Is bit 0 set? BLNE restore_fp ;Yes -- restore FP state TST v2,#2 ;Was there an error? LDMFD sp!,{v1-v3,lr} ;Restore all registers anyhow BICEQS pc,lr,#V_flag ;No -- clear V flag ORRS pc,lr,#V_flag ;Yes -- set V flag LTORG ; --- save_fp --- ; ; On entry: -- ; On exit: v1 corrupted save_fp ROUT RFS v1 ;Read the FP status word STMFD sp!,{v1} ;Stack it MOV v1,#0 ;We will zero the FPSR WFS v1 ;Zero it SUB sp,sp,#4*12 ;Leave space for 4 FP regs STFE f4,[sp,#0*12] ;Stack F4 STFE f5,[sp,#1*12] ;Stack F5 STFE f6,[sp,#2*12] ;Stack F6 STFE f7,[sp,#3*12] ;Stack F7 MOVS pc,lr ;Return to caller ; --- restore_fp --- ; ; On entry: -- ; On exit: v1 corrupted restore_fp ROUT MOV v1,#0 ;We will zero the FPSR WFS v1 ;Zero it LDFE f4,[sp,#0*12] ;Unstack F4 LDFE f5,[sp,#1*12] ;Unstack F5 LDFE f6,[sp,#2*12] ;Unstack F6 LDFE f7,[sp,#3*12] ;Unstack F7 ADD sp,sp,#4*12 ;Move stack ptr up past FP LDMFD sp!,{v1} ;Restore FPSR WFS v1 ;Write it to the FPSR MOVS pc,lr ;Return to caller ;----- Include the main wimp veneers ---------------------------------------- LNK s.wimp_main