Subversion Repositories Kolibri OS

Rev

Rev 1376 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1376 Rev 2382
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
4
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 1376 $
8
$Revision: 2382 $
9
 
9
 
10
 
10
 
Line 25... Line 25...
25
        cmp     eax,100
25
        cmp     eax, 100
26
        jb      .nocounter
26
        jb      .nocounter
27
        add     [next_usage_update],100
27
        add     [next_usage_update], 100
28
        call    updatecputimes
28
        call    updatecputimes
29
  .nocounter:
29
  .nocounter:
30
        mov     al,0x20  ; send End Of Interrupt signal
30
        xor     ecx, ecx        ; send End Of Interrupt signal
31
        out     0x20,al
31
        call    irq_eoi
32
        btr     dword[DONT_SWITCH], 0
32
        btr     dword[DONT_SWITCH], 0
33
        jc      .return
33
        jc      .return
34
        call    find_next_task
34
        call    find_next_task
35
        jz      .return  ; if there is only one running process
35
        jz      .return  ; if there is only one running process
36
        call    do_change_task
36
        call    do_change_task
Line 58... Line 58...
58
.find_next_task:
58
.find_next_task:
59
; \end{Mario79}
59
; \end{Mario79}
60
end if
60
end if
61
        call    find_next_task
61
        call    find_next_task
62
        jz      .return  ; the same task -> skip switch
62
        jz      .return  ; the same task -> skip switch
-
 
63
  @@:
63
  @@:   mov     byte[DONT_SWITCH], 1
64
        mov     byte[DONT_SWITCH], 1
64
        call    do_change_task
65
        call    do_change_task
65
  .return:
66
  .return:
66
        popad
67
        popad
67
        popfd
68
        popfd
68
        ret
69
        ret
Line 119... Line 120...
119
  .loop:
120
  .loop:
120
        cmp     bh,[TASK_COUNT]
121
        cmp     bh, [TASK_COUNT]
121
        jb      @f
122
        jb      @f
122
        xor     bh, bh
123
        xor     bh, bh
123
        mov     edi,CURRENT_TASK
124
        mov     edi, CURRENT_TASK
-
 
125
  @@:
124
  @@:   inc     bh       ; ebx += APPDATA.size
126
        inc     bh       ; ebx += APPDATA.size
125
        add     edi,0x20 ; edi += TASKDATA.size
127
        add     edi, 0x20; edi += TASKDATA.size
126
        mov     al, [edi+TASKDATA.state]
128
        mov     al, [edi+TASKDATA.state]
127
        test    al, al
129
        test    al, al
128
        jz      .found   ; state == 0
130
        jz      .found   ; state == 0
129
        cmp     al, 5
131
        cmp     al, 5
Line 138... Line 140...
138
      ; testing for timeout
140
      ; testing for timeout
139
        mov     ecx, [timer_ticks]
141
        mov     ecx, [timer_ticks]
140
        sub     ecx, [ebx+APPDATA.wait_begin]
142
        sub     ecx, [ebx+APPDATA.wait_begin]
141
        cmp     ecx, [ebx+APPDATA.wait_timeout]
143
        cmp     ecx, [ebx+APPDATA.wait_timeout]
142
        jb      .loop
144
        jb      .loop
-
 
145
  @@:
143
  @@:   mov     [ebx+APPDATA.wait_param], eax  ; retval for wait
146
        mov     [ebx+APPDATA.wait_param], eax  ; retval for wait
144
        mov     [edi+TASKDATA.state], 0
147
        mov     [edi+TASKDATA.state], 0
145
  .found:
148
  .found:
146
        mov     [CURRENT_TASK],bh
149
        mov     [CURRENT_TASK], bh
147
        mov     [TASK_BASE],edi
150
        mov     [TASK_BASE], edi
148
        rdtsc   ;call  _rdtsc
151
        rdtsc   ;call  _rdtsc
Line 212... Line 215...
212
  macro lodsReg [reg] {
215
  macro lodsReg [reg] {
213
        lodsd
216
        lodsd
214
        mov     reg,eax
217
        mov     reg, eax
215
  }     lodsReg dr0, dr1, dr2, dr3, dr7
218
  }     lodsReg dr0, dr1, dr2, dr3, dr7
216
  purge lodsReg
219
  purge lodsReg
-
 
220
  @@:
217
  @@:   ret
221
        ret
218
;end.
222
;end.
Line -... Line 223...
-
 
223
 
-
 
224
 
-
 
225
 
-
 
226
struct  MUTEX_WAITER
-
 
227
        list    LHEAD
-
 
228
        task    dd ?
-
 
229
ends
-
 
230
 
-
 
231
;void  __fastcall mutex_init(struct mutex *lock)
-
 
232
 
-
 
233
align 4
-
 
234
mutex_init:
-
 
235
        mov     [ecx+MUTEX.lhead.next], ecx
-
 
236
        mov     [ecx+MUTEX.lhead.prev], ecx
-
 
237
        mov     [ecx+MUTEX.count], 1
-
 
238
        ret
-
 
239
 
-
 
240
 
-
 
241
;void  __fastcall mutex_lock(struct mutex *lock)
-
 
242
 
-
 
243
align 4
-
 
244
mutex_lock:
-
 
245
 
-
 
246
        dec     [ecx+MUTEX.count]
-
 
247
        jns     .done
-
 
248
 
-
 
249
        pushfd
-
 
250
        cli
-
 
251
 
-
 
252
        sub     esp, sizeof.MUTEX_WAITER
-
 
253
 
-
 
254
        list_add_tail esp, ecx      ;esp= new waiter, ecx= list head
-
 
255
 
-
 
256
        mov     edx, [TASK_BASE]
-
 
257
        mov     [esp+MUTEX_WAITER.task], edx
-
 
258
 
-
 
259
.forever:
-
 
260
 
-
 
261
        mov     eax, -1
-
 
262
        xchg    eax, [ecx+MUTEX.count]
-
 
263
        dec     eax
-
 
264
        jz      @F
-
 
265
 
-
 
266
        mov     [edx+TASKDATA.state], 1
-
 
267
        call    change_task
-
 
268
        jmp     .forever
-
 
269
@@:
-
 
270
        mov     edx, [esp+MUTEX_WAITER.list.next]
-
 
271
        mov     eax, [esp+MUTEX_WAITER.list.prev]
-
 
272
 
-
 
273
        mov     [eax+MUTEX_WAITER.list.next], edx
-
 
274
        mov     [edx+MUTEX_WAITER.list.prev], eax
-
 
275
        cmp     [ecx+MUTEX.lhead.next], ecx
-
 
276
        jne     @F
-
 
277
 
-
 
278
        mov     [ecx+MUTEX.count], 0
-
 
279
@@:
-
 
280
        add     esp, sizeof.MUTEX_WAITER
-
 
281
 
-
 
282
        popfd
-
 
283
.done:
-
 
284
        ret
-
 
285
 
-
 
286
;void  __fastcall mutex_unlock(struct mutex *lock)
-
 
287
 
-
 
288
align 4
-
 
289
mutex_unlock:
-
 
290
 
-
 
291
        pushfd
-
 
292
        cli
-
 
293
 
-
 
294
        mov     eax, [ecx+MUTEX.lhead.next]
-
 
295
        cmp     eax, ecx
-
 
296
        mov     [ecx+MUTEX.count], 1
-
 
297
        je      @F
-
 
298
 
-
 
299
        mov     eax, [eax+MUTEX_WAITER.task]
-
 
300
        mov     [eax+TASKDATA.state], 0
-
 
301
@@:
-
 
302
        popfd
-
 
303
        ret
-
 
304
 
-
 
305
 
-
 
306
purge MUTEX_WAITER
219
 
307
 
-
 
308
if 0
220
if 0
309
 
221
struc TIMER
310
struc TIMER
222
{
311
{
223
  .next      dd ?
312
  .next      dd ?
224
  .exp_time  dd ?
313
  .exp_time  dd ?