Initial revision
[ssr] / StraySrc / Libraries / DLLLib / s / dpoll
1 ;
2 ; dpoll
3 ;
4 ; Wimp_Poll support for DLLs and applications that use them
5 ;
6 ; © 1994 Straylight
7 ;
8
9 ;----- Standard stuff -------------------------------------------------------
10
11 GET libs:header
12 GET libs:swis
13
14 ;----- Main code ------------------------------------------------------------
15
16 AREA |DLL$$Code|,CODE,READONLY
17
18 ; --- _dll_wimpPoll ---
19 ;
20 ; On entry: a1 == event mask
21 ; a2 == pointer to wimp poll block
22 ; a4 == pointer to poll word if bit 22 of a1 is set
23 ; On exit: a1 == reason code returned by Wimp_Poll
24 ; Other registers preserved
25 ;
26 ; Floating point status is preserved if a1 on entry has bit 24 set and the
27 ; floating point emulator or hardware is present. The floating point
28 ; registers preserved are f4-f7 and the FPSR.
29
30 EXPORT |_dll_wimpPoll|
31 |_dll_wimpPoll| ROUT
32
33 STMFD sp!,{v1-v3,lr}
34
35 MOV v2,#0 ;Don't restore FP state
36 TST a1,#1<<24 ;Does caller want FP saved?
37 BIC v3,a1,#1<<24 ;We're doing it, not the WIMP
38 BEQ %00 ;No -- skip this bit
39 SWI XFPEmulator_Version ;Is the FPE/FPA there?
40 MOVVC v2,#1 ;Yes -- set flag to restore
41 BLVC save_fp ;Save the FP state
42
43 00 SWI XDLL_SaveHandle ;Get my application handle
44 MOV v1,a1 ;Look after it
45 MOV a1,v3 ;Restore event mask
46 SWI XWimp_Poll ;Do the SWI call
47 ORRVS v2,v2,#2 ;Set bit 1 of v2 if error
48 MOV v3,a1 ;Save the reason code/error
49 MOV a1,v1 ;Restore application handle
50 SWI XDLL_RestoreHandle ;Put the handle back again
51 MOV a1,v3 ;Restore event code/error
52
53 TST v2,#1 ;Is bit 0 set?
54 BLNE restore_fp ;Yes -- restore FP state
55 TST v2,#2 ;Was there an error?
56 LDMFD sp!,{v1-v3,lr} ;Restore all registers anyhow
57 BICEQS pc,lr,#V_flag ;No -- clear V flag
58 ORRS pc,lr,#V_flag ;Yes -- set V flag
59
60 LTORG
61
62 ; --- _dll_wimpPollIdle ---
63 ;
64 ; On entry: a1 == event mask
65 ; a2 == pointer to wimp poll block
66 ; a3 == earliest time to return with an idle event
67 ; a4 == pointer to poll word if bit 22 of a1 is set
68 ; On exit: a1 == reason code returned by Wimp_Poll
69 ; Other registers preserved
70 ;
71 ; Floating point status is preserved if a1 on entry has bit 24 set and the
72 ; floating point emulator or hardware is present. The floating point
73 ; registers preserved are f4-f7 and the FPSR.
74
75 EXPORT |_dll_wimpPollIdle|
76 |_dll_wimpPollIdle| ROUT
77
78 STMFD sp!,{v1-v3,lr}
79
80 MOV v2,#0 ;Don't restore FP state
81 TST a1,#1<<24 ;Does caller want FP saved?
82 BIC v3,a1,#1<<24 ;We're doing it, not the WIMP
83 BEQ %00 ;No -- skip this bit
84 SWI XFPEmulator_Version ;Is the FPE/FPA there?
85 MOVVC v2,#1 ;Yes -- set flag to restore
86 BLVC save_fp ;Save the FP state
87
88 00 SWI XDLL_SaveHandle ;Get my application handle
89 MOV v1,a1 ;Look after it
90 MOV a1,v3 ;Restore event mask
91 SWI XWimp_PollIdle ;Do the SWI call
92 ORRVS v2,v2,#2 ;Set bit 1 of v2 if error
93 MOV v3,a1 ;Save the reason code/error
94 MOV a1,v1 ;Restore application handle
95 SWI XDLL_RestoreHandle ;Put the handle back again
96 MOV a1,v3 ;Restore event code/error
97
98 TST v2,#1 ;Is bit 0 set?
99 BLNE restore_fp ;Yes -- restore FP state
100 TST v2,#2 ;Was there an error?
101 LDMFD sp!,{v1-v3,lr} ;Restore all registers anyhow
102 BICEQS pc,lr,#V_flag ;No -- clear V flag
103 ORRS pc,lr,#V_flag ;Yes -- set V flag
104
105 LTORG
106
107 ; --- save_fp ---
108 ;
109 ; On entry: --
110 ; On exit: v1 corrupted
111
112 save_fp ROUT
113
114 RFS v1 ;Read the FP status word
115 STMFD sp!,{v1} ;Stack it
116 MOV v1,#0 ;We will zero the FPSR
117 WFS v1 ;Zero it
118 SUB sp,sp,#4*12 ;Leave space for 4 FP regs
119 STFE f4,[sp,#0*12] ;Stack F4
120 STFE f5,[sp,#1*12] ;Stack F5
121 STFE f6,[sp,#2*12] ;Stack F6
122 STFE f7,[sp,#3*12] ;Stack F7
123 MOVS pc,lr ;Return to caller
124
125 ; --- restore_fp ---
126 ;
127 ; On entry: --
128 ; On exit: v1 corrupted
129
130 restore_fp ROUT
131
132 MOV v1,#0 ;We will zero the FPSR
133 WFS v1 ;Zero it
134 LDFE f4,[sp,#0*12] ;Unstack F4
135 LDFE f5,[sp,#1*12] ;Unstack F5
136 LDFE f6,[sp,#2*12] ;Unstack F6
137 LDFE f7,[sp,#3*12] ;Unstack F7
138 ADD sp,sp,#4*12 ;Move stack ptr up past FP
139 LDMFD sp!,{v1} ;Restore FPSR
140 WFS v1 ;Write it to the FPSR
141 MOVS pc,lr ;Return to caller
142
143 ;----- That's all, folks ----------------------------------------------------
144
145 END