Rev 254 | Rev 363 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 254 | Rev 354 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | struc EVENT |
- | |
2 | { .code rd 1 |
- | |
3 | rd 5 |
- | |
4 | .next rd 1 ;+24 |
- | |
5 | .prev rd 1 ;+28 |
- | |
6 | } |
- | |
7 | EVENT_SIZE equ 32 |
- | |
8 | - | ||
9 | virtual at 0 |
- | |
10 | EVENT EVENT |
- | |
11 | end virtual |
- | |
Line 12... | Line 1... | ||
12 | 1 | align 4 |
|
13 | align 4 |
2 | init_events: |
14 | init_events: |
3 | stdcall kernel_alloc, 512*EVENT_SIZE |
15 | stdcall kernel_alloc, 1024*EVENT_SIZE |
4 | mov [events], eax |
16 | mov [events], eax |
5 | xor eax, eax |
- | 6 | mov [event_uid], eax |
|
17 | xor eax, eax |
7 | not eax |
18 | not eax |
8 | mov edi, event_map |
19 | mov edi, event_map |
9 | mov [event_start], edi |
20 | mov [event_start], edi |
10 | mov ecx, 64/4 |
21 | mov ecx, 128/4 |
11 | cld |
22 | cld |
12 | rep stosd |
23 | rep stosd |
13 | mov [event_end], edi |
24 | mov [event_end], edi |
14 | ret |
Line 41... | Line 31... | ||
41 | xor eax,eax |
31 | ret |
42 | ret |
32 | .found: |
43 | .found: |
33 | btr [ebx], eax |
44 | btr [ebx], eax |
34 | mov [event_start],ebx |
45 | mov [event_start],ebx |
35 | inc [event_uid] |
- | 36 | ||
- | 37 | sub ebx, event_map |
|
46 | sub ebx, event_map |
38 | lea eax,[eax+ebx*8] |
47 | lea eax,[eax+ebx*8] |
39 | |
- | 40 | lea ebx, [eax+eax*4] |
|
- | 41 | shl eax,5 |
|
48 | shl eax,5 |
42 | lea eax,[eax+ebx*4] ;eax*=52 (EVENT_SIZE) |
- | 43 | add eax, [events] |
|
49 | add eax, [events] |
44 | mov ebx, [event_uid] |
- | 45 | popfd |
|
50 | popfd |
46 | ret |
51 | xor ebx, ebx |
- | |
52 | mov [eax+EVENT.next], ebx |
- | |
53 | mov [eax+EVENT.prev], ebx |
- | |
54 | ret |
47 | endp |
55 | endp |
48 | |
Line 56... | Line 49... | ||
56 | 49 | align 4 |
|
57 | align 4 |
50 | free_event: |
58 | free_event: |
- | |
59 | pushfd |
- | |
60 | cli |
51 | sub eax, [events] |
61 | sub eax, [events] |
52 | mov ecx, EVENT_SIZE |
62 | shr eax, 5 |
53 | mov ebx, event_map |
- | 54 | cdq |
|
- | 55 | div ecx |
|
- | 56 | ||
- | 57 | pushfd |
|
- | 58 | cli |
|
63 | mov ebx, event_map |
59 | bts [ebx], eax |
64 | bts [ebx], eax |
60 | shr eax, 3 |
65 | shr eax, 3 |
61 | and eax, not 3 |
66 | and eax, not 3 |
62 | add eax, ebx |
67 | add eax, ebx |
63 | cmp [event_start], eax |
Line 72... | Line 68... | ||
72 | @@: |
68 | mov [event_start], eax |
73 | mov [event_start], eax |
69 | popfd |
74 | popfd |
70 | ret |
75 | ret |
71 | |
Line -... | Line 72... | ||
- | 72 | EVENT_WATCHED equ 0x10000000 |
|
- | 73 | EVENT_SIGNALED equ 0x20000000 |
|
- | 74 | MANUAL_RESET equ 0x40000000 |
|
- | 75 | MANUAL_DESTROY equ 0x80000000 |
|
- | 76 | ||
- | 77 | ||
- | 78 | ; param |
|
- | 79 | ; eax= event data |
|
- | 80 | ; ebx= flags |
|
- | 81 | ; |
|
- | 82 | ; retval |
|
- | 83 | ; eax= event |
|
- | 84 | ; edx= id |
|
- | 85 | ||
- | 86 | create_event: |
|
- | 87 | .flags equ esp+4 |
|
- | 88 | .data equ esp |
|
- | 89 | ||
- | 90 | push ebx |
|
- | 91 | push eax |
|
- | 92 | ||
- | 93 | call alloc_event |
|
- | 94 | test eax, eax |
|
- | 95 | jz .fail |
|
- | 96 | ||
- | 97 | mov [eax+APPOBJ.magic], 'EVNT' |
|
- | 98 | mov [eax+APPOBJ.destroy], destroy_event |
|
- | 99 | mov [eax+EVENT.id], ebx |
|
- | 100 | ||
- | 101 | mov ebx, [CURRENT_TASK] |
|
- | 102 | shl ebx, 5 |
|
- | 103 | mov ebx, [0x3000+ebx+4] |
|
- | 104 | mov [eax+APPOBJ.pid], ebx |
|
- | 105 | mov edx, [.flags] |
|
- | 106 | mov [eax+EVENT.state], edx |
|
- | 107 | ||
- | 108 | mov esi, [.data] |
|
- | 109 | test esi, esi |
|
- | 110 | jz @F |
|
- | 111 | lea edi, [eax+EVENT.code] |
|
- | 112 | mov ecx, 6 |
|
- | 113 | cld |
|
- | 114 | rep movsd |
|
- | 115 | @@: |
|
- | 116 | mov ecx, [CURRENT_TASK] |
|
- | 117 | shl ecx,8 |
|
- | 118 | add ecx, PROC_BASE+APP_OBJ_OFFSET |
|
- | 119 | ||
- | 120 | pushfd |
|
- | 121 | cli |
|
- | 122 | mov edx, [ecx+APPOBJ.fd] |
|
- | 123 | mov [eax+APPOBJ.fd], edx |
|
- | 124 | mov [eax+APPOBJ.bk], ecx |
|
- | 125 | mov [ecx+APPOBJ.fd], eax |
|
- | 126 | mov [edx+APPOBJ.bk], eax |
|
- | 127 | popfd |
|
- | 128 | mov edx, [eax+EVENT.id] |
|
- | 129 | .fail: |
|
- | 130 | add esp, 8 |
|
- | 131 | ret |
|
- | 132 | ||
- | 133 | restore .flags |
|
- | 134 | restore .data |
|
- | 135 | ||
- | 136 | ; param |
|
- | 137 | ; eax= event |
|
- | 138 | ; ebx= id |
|
- | 139 | ||
- | 140 | destroy_event: |
|
- | 141 | ||
- | 142 | cmp [eax+APPOBJ.magic], 'EVNT' |
|
- | 143 | jne .fail |
|
- | 144 | cmp [eax+EVENT.id], ebx |
|
- | 145 | jne .fail |
|
- | 146 | ||
- | 147 | mov ebx, [eax+APPOBJ.fd] |
|
- | 148 | mov ecx, [eax+APPOBJ.bk] |
|
- | 149 | mov [ebx+APPOBJ.bk], ecx |
|
- | 150 | mov [ecx+APPOBJ.fd], ebx |
|
- | 151 | .internal: |
|
- | 152 | xor edx, edx ;clear common header |
|
- | 153 | mov [eax], edx |
|
- | 154 | mov [eax+4], edx |
|
- | 155 | mov [eax+8], edx |
|
- | 156 | mov [eax+12], edx |
|
- | 157 | mov [eax+16], edx |
|
- | 158 | ||
- | 159 | call free_event ;release object memory |
|
- | 160 | .fail: |
|
- | 161 | ret |
|
- | 162 | ||
76 | 163 | align 4 |
|
77 | align 4 |
164 | proc send_event stdcall pid:dword, event:dword |
78 | proc send_event stdcall pid:dword, event:dword |
165 | locals |
79 | locals |
166 | slot dd ? |
80 | slot dd ? |
167 | endl |
Line 88... | Line 175... | ||
88 | shl eax, 8 |
175 | cmp [PROC_BASE+eax+APPDATA.ev_count], 32 |
89 | cmp [PROC_BASE+eax+APPDATA.ev_count], 32 |
176 | ja .fail |
90 | ja .fail |
177 | |
Line 91... | Line 178... | ||
91 | 178 | mov [slot], eax |
|
- | 179 | ||
92 | mov [slot], eax |
180 | call alloc_event |
93 | call alloc_event |
181 | test eax, eax |
94 | test eax, eax |
182 | jz .fail |
Line 95... | Line 183... | ||
95 | jz .fail |
183 | |
96 | 184 | lea edi, [eax+EVENT.code] |
|
97 | mov edi, eax |
185 | mov ecx, 6 |
98 | mov ecx, 6 |
186 | mov esi, [event] |
99 | mov esi, [event] |
187 | cld |
Line 100... | Line 188... | ||
100 | cld |
188 | rep movsd |
101 | rep movsd |
189 | |
- | 190 | mov ecx, [slot] |
|
102 | 191 | add ecx, PROC_BASE+APP_EV_OFFSET |
|
103 | mov esi, eax |
192 | |
104 | mov eax, [slot] |
193 | mov [eax+APPOBJ.magic], 'EVNT' |
105 | mov edi, [PROC_BASE+eax+APPDATA.ev_last] |
194 | mov [eax+APPOBJ.destroy], destroy_event |
106 | mov [esi+EVENT.prev], edi |
195 | mov ebx, [pid] |
- | 196 | mov [eax+APPOBJ.pid], ebx |
|
107 | test edi, edi |
197 | mov [eax+EVENT.state], EVENT_SIGNALED |
- | 198 | ||
108 | jz .set_last |
199 | pushfd |
109 | mov [edi+EVENT.next], esi |
200 | cli ;insert event into |
110 | .set_last: |
201 | mov edx, [ecx+APPOBJ.fd] ;events list |
111 | mov edx, [PROC_BASE+eax+APPDATA.ev_first] |
202 | mov [eax+APPOBJ.fd], edx ;and set events flag |
112 | test edx, edx |
- | |
113 | jnz @F |
203 | mov [eax+APPOBJ.bk], ecx |
114 | mov [PROC_BASE+eax+APPDATA.ev_first], esi |
204 | mov [ecx+APPOBJ.fd], eax |
115 | @@: |
205 | mov [edx+APPOBJ.bk], eax |
- | 206 | inc [ecx+APPDATA.ev_count-APP_EV_OFFSET] |
|
116 | mov [PROC_BASE+eax+APPDATA.ev_last], esi |
207 | or [ecx+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED |
117 | inc [PROC_BASE+eax+APPDATA.ev_count] |
208 | popfd |
118 | or [PROC_BASE+eax+APPDATA.event_mask], EVENT_EXTENDED |
209 | .fail: |
Line -... | Line 210... | ||
- | 210 | ret |
|
- | 211 | endp |
|
119 | .fail: |
212 | |
120 | ret |
213 | ; timeout ignored |
Line 121... | Line 214... | ||
121 | endp |
214 | |
122 | 215 | align 4 |
|
123 | align 4 |
216 | proc get_event_ex stdcall, p_ev:dword, timeout:dword |
124 | proc get_event_ex stdcall, p_ev:dword, timeout:dword |
217 | |
125 | 218 | .wait: |
|
Line 126... | Line 219... | ||
126 | .wait: |
219 | mov edx,[CURRENT_TASK] |
- | 220 | shl edx,8 |
|
127 | mov ebx,[CURRENT_TASK] |
221 | cmp [PROC_BASE+edx+APPDATA.ev_count], 0 |
128 | shl ebx,8 |
- | |
129 | cmp [PROC_BASE+ebx+APPDATA.ev_count], 0 |
222 | je .switch |
130 | je .switch |
223 | |
131 | - | ||
132 | mov esi, [PROC_BASE+ebx+APPDATA.ev_first] |
- | |
133 | mov edx, [esi+EVENT.next] |
- | |
134 | mov [PROC_BASE+ebx+APPDATA.ev_first], edx |
- | |
135 | test edx, edx |
- | |
136 | jz @F |
- | |
137 | mov [edx+EVENT.prev], 0 |
- | |
Line 138... | Line -... | ||
138 | @@: |
- | |
139 | jnz @F |
224 | add edx, PROC_BASE+APP_EV_OFFSET |
140 | mov [PROC_BASE+ebx+APPDATA.ev_last], edx |
225 | |
141 | and dword [PROC_BASE+ebx+APPDATA.event_mask], not EVENT_EXTENDED |
226 | mov eax, [edx+EVENT.fd] |
142 | @@: |
227 | cmp eax, edx |
143 | dec [PROC_BASE+ebx+APPDATA.ev_count] |
228 | je .switch |
- | 229 | ||
- | 230 | lea esi, [eax+EVENT.code] |
|
- | 231 | mov edi, [p_ev] ;copy event data |
|
- | 232 | mov ecx, 6 |
|
- | 233 | cld |
|
- | 234 | rep movsd |
|
- | 235 | ||
- | 236 | and dword [edi-24], 0xFF00FFFF ;clear priority field |
|
- | 237 | ; |
|
- | 238 | ||
- | 239 | test [eax+EVENT.state], MANUAL_RESET |
|
- | 240 | jnz .done |
|
- | 241 | ||
- | 242 | pushfd |
|
- | 243 | cli ;remove event from events |
|
- | 244 | mov ebx, [eax+APPOBJ.fd] ;list (reset event) |
|
- | 245 | mov ecx, [eax+APPOBJ.bk] ;and clear events flag |
|
- | 246 | mov [ebx+APPOBJ.bk], ecx ;if no active events |
|
- | 247 | mov [ecx+APPOBJ.fd], ebx |
|
- | 248 | dec [edx+APPDATA.ev_count-APP_EV_OFFSET] |
|
- | 249 | jnz @F |
|
- | 250 | and [edx+APPDATA.event_mask-APP_EV_OFFSET], not EVENT_EXTENDED |
|
- | 251 | popfd |
|
- | 252 | ||
- | 253 | test [eax+EVENT.state], MANUAL_DESTROY |
|
- | 254 | jz .destroy |
|
- | 255 | ||
- | 256 | add edx, (APP_OBJ_OFFSET-APP_EV_OFFSET) |
|
- | 257 | ||
- | 258 | pushfd |
|
- | 259 | cli |
|
- | 260 | mov edx, [ecx+APPOBJ.fd] ;insert event into |
|
- | 261 | mov [eax+APPOBJ.fd], edx ;objects list |
|
- | 262 | mov [eax+APPOBJ.bk], ecx |
|
- | 263 | mov [ecx+APPOBJ.fd], eax |
|
144 | 264 | mov [edx+APPOBJ.bk], eax |
|
145 | mov eax, esi |
265 | popfd |
146 | and dword [esi], 0xFF00FFFF |
266 | .done: |
147 | mov edi, [p_ev] |
267 | ret |
148 | mov ecx, 6 |
268 | |
149 | cld |
269 | .destroy: |
150 | rep movsd |
270 | call destroy_event.internal |
151 | call free_event |
271 | ret |
Line -... | Line 272... | ||
- | 272 | .switch: |
|
- | 273 | mov eax, [0x3010] |
|
- | 274 | mov [eax+TASKDATA.state], byte 5 |
|
- | 275 | call change_task |
|
- | 276 | jmp .wait |
|
- | 277 | endp |
|
- | 278 | ||
- | 279 | ; param |
|
- | 280 | ; eax= event |
|
- | 281 | ; ebx= id |
|
- | 282 | ||
- | 283 | align 4 |
|
- | 284 | wait_event: |
|
- | 285 | .event equ esp |
|
- | 286 | push eax |
|
- | 287 | .wait: |
|
- | 288 | cmp [eax+APPOBJ.magic], 'EVNT' |
|
- | 289 | jne .done |
|
- | 290 | cmp [eax+EVENT.id], ebx |
|
- | 291 | jne .done |
|
- | 292 | ||
- | 293 | test [eax+EVENT.state], EVENT_SIGNALED |
|
- | 294 | jz .switch |
|
- | 295 | ||
- | 296 | test [eax+EVENT.state], MANUAL_RESET |
|
- | 297 | jnz .done |
|
- | 298 | ||
- | 299 | mov edx,[CURRENT_TASK] |
|
- | 300 | shl edx,8 |
|
- | 301 | add edx, PROC_BASE |
|
- | 302 | ||
- | 303 | pushfd |
|
- | 304 | cli ;remove event from events |
|
- | 305 | mov ebx, [eax+APPOBJ.fd] ;list (reset event) |
|
- | 306 | mov ecx, [eax+APPOBJ.bk] ;and clear events flag |
|
- | 307 | mov [ebx+APPOBJ.bk], ecx ;if no active events |
|
- | 308 | mov [ecx+APPOBJ.fd], ebx |
|
- | 309 | dec [edx+APPDATA.ev_count] |
|
- | 310 | jnz @F |
|
- | 311 | and [edx+APPDATA.event_mask], not EVENT_EXTENDED |
|
- | 312 | @@: |
|
- | 313 | and [eax+EVENT.state], not (EVENT_SIGNALED+EVENT_WATCHED) |
|
- | 314 | popfd |
|
- | 315 | ||
- | 316 | test [eax+EVENT.state], MANUAL_DESTROY |
|
- | 317 | jz .destroy |
|
- | 318 | ||
- | 319 | add edx, APP_OBJ_OFFSET |
|
- | 320 | ||
- | 321 | pushfd |
|
- | 322 | cli |
|
- | 323 | mov ecx, [edx+APPOBJ.fd] ;insert event into |
|
- | 324 | mov [eax+APPOBJ.fd], ecx ;objects list |
|
- | 325 | mov [eax+APPOBJ.bk], edx |
|
- | 326 | mov [edx+APPOBJ.fd], eax |
|
- | 327 | mov [ecx+APPOBJ.bk], eax |
|
- | 328 | popfd |
|
- | 329 | .done: |
|
- | 330 | add esp, 4 |
|
- | 331 | ret |
|
- | 332 | .destroy: |
|
- | 333 | call destroy_event.internal |
|
- | 334 | add esp, 4 |
|
- | 335 | ret |
|
- | 336 | .switch: |
|
- | 337 | or [eax+EVENT.state], EVENT_WATCHED |
|
- | 338 | mov eax, [0x3010] |
|
- | 339 | mov [eax+TASKDATA.state], byte 5 |
|
- | 340 | call change_task |
|
- | 341 | mov eax, [.event] |
|
- | 342 | jmp .wait |
|
- | 343 | restore .event |
|
- | 344 | ||
- | 345 | ; param |
|
- | 346 | ; eax= event |
|
- | 347 | ; ebx= id |
|
- | 348 | ; ecx= flags |
|
- | 349 | ||
- | 350 | raise_event: |
|
- | 351 | .event equ esp |
|
- | 352 | push eax |
|
- | 353 | ||
- | 354 | cmp [eax+APPOBJ.magic], 'EVNT' |
|
- | 355 | jne .fail |
|
- | 356 | cmp [eax+EVENT.id], ebx |
|
- | 357 | jne .fail |
|
- | 358 | ||
- | 359 | mov eax, [eax+APPOBJ.pid] |
|
- | 360 | call pid_to_slot |
|
- | 361 | test eax, eax |
|
- | 362 | jz .fail |
|
- | 363 | ||
- | 364 | mov edx, [.event] |
|
- | 365 | test [edx+EVENT.state], EVENT_SIGNALED |
|
- | 366 | jnz .done |
|
- | 367 | ||
- | 368 | test ecx, EVENT_WATCHED |
|
- | 369 | jz @F |
|
- | 370 | test [edx+EVENT.state], EVENT_WATCHED |
|
- | 371 | jz .done |
|
- | 372 | @@: |
|
- | 373 | shl eax, 8 |
|
- | 374 | add eax, PROC_BASE+APP_EV_OFFSET |
|
- | 375 | ||
- | 376 | pushfd |
|
- | 377 | cli |
|
- | 378 | mov ebx, [edx+APPOBJ.fd] |
|
- | 379 | mov ecx, [edx+APPOBJ.bk] |
|
- | 380 | mov [ebx+APPOBJ.bk], ecx |
|
- | 381 | mov [ecx+APPOBJ.fd], ebx |
|
- | 382 | ||
- | 383 | mov ecx, [eax+APPOBJ.fd] |
|
- | 384 | mov [edx+APPOBJ.fd], ecx |
|
- | 385 | mov [edx+APPOBJ.bk], eax |
|
- | 386 | mov [eax+APPOBJ.fd], edx |
|
- | 387 | mov [ecx+APPOBJ.bk], edx |
|
- | 388 | or [edx+EVENT.state], EVENT_SIGNALED |
|
- | 389 | ||
- | 390 | inc [eax+APPDATA.ev_count-APP_EV_OFFSET] |
|
- | 391 | or [eax+APPDATA.event_mask-APP_EV_OFFSET], EVENT_EXTENDED |
|
152 | ret |
392 | popfd |
Line 153... | Line 393... | ||
153 | .switch: |
393 | .fail: |
154 | mov eax, [0x3010] |
394 | .done: |
155 | mov [eax+TASKDATA.state], byte 5 |
395 | add esp, 4 |
Line 319... | Line 559... | ||
319 | mov eax,8 |
559 | ret |
320 | ret |
560 | no_stack_event: |
321 | no_stack_event: |
561 | |
Line 322... | Line 562... | ||
322 | 562 | test byte [edi+TASKDATA.event_mask+1], 1 ; DEBUG |
|
323 | test byte [edi+TASKDATA.event_mask+1], 1 ; DEBUG |
563 | jz .test_IRQ |
324 | jz .test_ext |
564 | mov eax, [0x3000] |
325 | mov eax, [0x3000] |
565 | shl eax, 8 |
326 | shl eax, 8 |
566 | test byte [eax+0x80000+APPDATA.event_mask+1], byte 1 |
327 | test byte [eax+0x80000+APPDATA.event_mask+1], byte 1 |
567 | jz .test_IRQ |
328 | jz .test_ext |
568 | and byte [eax+0x80000+APPDATA.event_mask+1], not 1 |
329 | and byte [eax+0x80000+APPDATA.event_mask+1], not 1 |
569 | popad |
330 | popad |
570 | mov eax, 9 |
331 | mov eax, 9 |
571 | ret |
Line 332... | Line 572... | ||
332 | ret |
572 | |
333 | 573 | ;.test_ext: |
|
334 | .test_ext: |
574 | ; mov eax, [0x3000] |
335 | mov eax, [0x3000] |
575 | ; shl eax, 8 |
336 | shl eax, 8 |
576 | ; test dword [eax+0x80000+APPDATA.event_mask], EVENT_EXTENDED |
- | 577 | ; jz .test_IRQ |
|
337 | test dword [eax+0x80000+APPDATA.event_mask], EVENT_EXTENDED |
578 | ; popad |
338 | jz .test_IRQ |
579 | ; mov eax, 10 |
Line 339... | Line 580... | ||
339 | mov eax, 10 |
580 | ; ret |
340 | ret |
- | |
341 | - | ||
342 | .test_IRQ: |
581 | |
343 | 582 | .test_IRQ: |
|
Line 344... | Line 583... | ||
344 | 583 | cmp dword [edi+TASKDATA.event_mask], 0xFFFF |
|
345 | cmp dword [edi+TASKDATA.event_mask], 0xFFFF |
584 | jbe no_events |