Subversion Repositories Kolibri OS

Rev

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

Rev 434 Rev 465
Line 1... Line 1...
1
$Revision: 434 $
1
$Revision: 465 $
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
5
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
6
;; Distributed under terms of the GNU General Public License    ;;
6
;; Distributed under terms of the GNU General Public License    ;;
Line 8... Line 8...
8
 
8
 
9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
10
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
Line -... Line 11...
-
 
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
 
12
 
13
 
-
 
14
align 32
13
align 32
15
irq0:
14
irq0:
16
   ;     pushfd
15
        save_ring3_context
17
        pushad
16
	mov   ax, os_data
18
        mov   ax, app_data  ;
Line 17... Line 19...
17
	mov   ds, ax
19
        mov   ds, ax
Line 26... Line 28...
26
        jb    .nocounter
28
        jb    .nocounter
27
        add   eax,100
29
        add   eax,100
28
        mov   [next_usage_update],eax
30
        mov   [next_usage_update],eax
29
        call  updatecputimes
31
        call  updatecputimes
30
     .nocounter:
32
.nocounter:
31
 
-
 
32
        cmp   [DONT_SWITCH], byte 1
33
        cmp   [DONT_SWITCH], byte 1
33
        jne   .change_task
34
        jne   .change_task
Line 34... Line 35...
34
 
35
 
35
        mov   al,0x20   ; send End Of Interrupt signal
36
        mov   al,0x20   ; send End Of Interrupt signal
36
        mov   dx,0x20
37
        mov   dx,0x20
Line 37... Line 38...
37
        out   dx,al
38
        out   dx,al
Line 38... Line 39...
38
 
39
 
-
 
40
        mov   [DONT_SWITCH], byte 0
39
        mov   [DONT_SWITCH], byte 0
41
 
Line 40... Line 42...
40
 
42
        popad
41
        restore_ring3_context
43
 ;       popfd
Line 42... Line 44...
42
        iret
44
        iretd
Line 55... Line 57...
55
        jnz   .return
57
        jnz   .return
Line 56... Line 58...
56
 
58
 
Line 57... Line 59...
57
        call  do_change_task
59
        call  do_change_task
58
 
60
 
-
 
61
.return:
59
     .return:
62
        popad
Line 60... Line 63...
60
        restore_ring3_context
63
 ;       popfd
61
        iret
64
        iretd
Line 62... Line 65...
62
 
65
 
63
 
66
 
64
align 4
67
align 4
Line 65... Line 68...
65
change_task:
68
change_task:
-
 
69
 
-
 
70
        pushfd
-
 
71
        cli
66
 
72
        pushad
67
        pushfd
73
 
68
        cli
74
        call  update_counters
69
        pushad
75
 
70
 
76
if 0
Line 80... Line 86...
80
        mov     [CURRENT_TASK], ebx
86
        mov     [CURRENT_TASK], ebx
81
        mov     [TASK_BASE], edi
87
        mov     [TASK_BASE], edi
82
        jmp     @f
88
        jmp     @f
83
.find_next_task:
89
.find_next_task:
84
; \end{Mario79}
90
; \end{Mario79}
-
 
91
 
-
 
92
end if
-
 
93
 
85
        call  find_next_task
94
        call  find_next_task
86
        test  eax, eax    ; the same task -> skip switch
95
        test  eax, eax    ; the same task -> skip switch
87
        jnz    .return
96
        jnz    .return
88
@@:
97
@@:
89
        mov   [DONT_SWITCH],byte 1
98
        mov   [DONT_SWITCH],byte 1
90
        call  do_change_task
99
        call  do_change_task
Line 91... Line 100...
91
 
100
 
92
     .return:
101
.return:
93
        popad
102
        popad
94
        popfd
-
 
95
 
103
        popfd
Line 96... Line 104...
96
        ret
104
        ret
97
 
105
 
Line 110... Line 118...
110
 
118
 
111
 
119
 
112
update_counters:
120
update_counters:
113
        mov   edi, [TASK_BASE]
121
        mov   edi, [TASK_BASE]
114
        mov   ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
122
        mov   ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
115
        call  _rdtsc
123
        rdtsc
116
        sub   eax, ebx
124
        sub   eax, ebx
117
        add   eax, [edi+TASKDATA.counter_sum] ; counter sum
125
        add   eax, [edi+TASKDATA.counter_sum] ; counter sum
Line 157... Line 165...
157
        cmp   al, 9
165
        cmp   al, 9
158
        je    .waiting_for_reuse
166
        je    .waiting_for_reuse
Line 159... Line 167...
159
 
167
 
160
        mov   [CURRENT_TASK],ebx
168
        mov   [CURRENT_TASK],ebx
161
        mov   [TASK_BASE],edi
-
 
162
        push    ebx
-
 
163
        shl     ebx, 8
-
 
164
        mov     ebx, [SLOT_BASE + ebx + APPDATA.pl0_stack]
-
 
165
        add     ebx, RING0_STACK_SIZE
-
 
166
        mov     [CURRENT_RING0_ESP], ebx
-
 
Line 167... Line 169...
167
        pop     ebx
169
        mov   [TASK_BASE],edi
168
 
170
 
169
        cmp   al, 5
171
        cmp   al, 5
170
        jne   .noevents
172
        jne   .noevents
Line 175... Line 177...
175
        mov   [edi+TASKDATA.state], byte 0
177
        mov   [edi+TASKDATA.state], byte 0
176
      .noevents:
178
.noevents:
177
      .found:
179
.found:
178
        mov   [CURRENT_TASK],ebx
180
        mov   [CURRENT_TASK],ebx
179
        mov   [TASK_BASE],edi
181
        mov   [TASK_BASE],edi
180
        call  _rdtsc
182
        rdtsc                     ;call  _rdtsc
181
        mov   [edi+TASKDATA.counter_add],eax
183
        mov   [edi+TASKDATA.counter_add],eax
Line -... Line 184...
-
 
184
 
182
 
185
        mov esi, [prev_slot]
183
	xor   eax, eax
186
	xor   eax, eax
184
        cmp   ebx, [prev_slot]
187
        cmp   ebx, esi
185
        sete  al
188
        sete  al
Line -... Line 189...
-
 
189
ret
186
ret
190
 
-
 
191
; param
-
 
192
;  ebx = incoming task
187
 
193
;  esi = outcomig task
188
; in: ebx = TSS selector index
-
 
189
do_change_task:
-
 
190
        shl   ebx, 3
-
 
191
        xor   eax, eax
-
 
192
        add   ebx, tss0
-
 
193
        mov   [far_jump.sel],  bx   ; selector
-
 
194
        mov   [far_jump.offs], eax  ; offset
-
 
195
        jmp   pword [far_jump]
-
 
Line -... Line 194...
-
 
194
 
-
 
195
do_change_task:
-
 
196
 
-
 
197
        shl ebx, 8
-
 
198
        add ebx, SLOT_BASE
-
 
199
        mov [current_slot], ebx
-
 
200
 
-
 
201
        shl esi, 8
-
 
202
        add esi, SLOT_BASE
-
 
203
 
-
 
204
        mov [esi+APPDATA.saved_esp], esp
-
 
205
        mov esp, [ebx+APPDATA.saved_esp]
-
 
206
 
-
 
207
; set thread io map
-
 
208
 
-
 
209
        mov ecx, [ebx+APPDATA.io_map]
-
 
210
        mov edx, [ebx+APPDATA.io_map+4]
-
 
211
        mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], ecx
-
 
212
        mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx
-
 
213
 
-
 
214
        mov eax, [ebx+APPDATA.dir_table]
-
 
215
        mov cr3, eax
-
 
216
        mov ebx, [ebx+APPDATA.pl0_stack]
-
 
217
        add ebx, RING0_STACK_SIZE
-
 
218
        mov [tss._esp0], ebx
-
 
219
        mov ecx, cr0
Line -... Line 220...
-
 
220
        or ecx, CR0_TS   ;set task switch flag
-
 
221
        mov cr0, ecx
-
 
222
        inc   [context_counter] ;noname & halyavin
-
 
223
 
-
 
224
        test [ebx+APPDATA.dbg_state], 1
-
 
225
        jnz @F
-
 
226
        ret
-
 
227
@@:
-
 
228
        mov eax, [ebx+APPDATA.dbg_regs.dr0]
-
 
229
        mov dr0, eax
-
 
230
        mov eax, [ebx+APPDATA.dbg_regs.dr1]
-
 
231
        mov dr1, eax
-
 
232
        mov eax, [ebx+APPDATA.dbg_regs.dr2]
-
 
233
        mov dr2, eax
-
 
234
        mov eax, [ebx+APPDATA.dbg_regs.dr3]
-
 
235
        mov dr3, eax
-
 
236
        xor eax, eax
Line 196... Line 237...
196
        inc   [context_counter] ;noname & halyavin
237
        mov dr6, eax
197
ret
238
        mov eax, [ebx+APPDATA.dbg_regs.dr7]
Line 198... Line 239...
198
 
239
        mov dr7, eax
Line 213... Line 254...
213
        add  edi,0x20
254
        add  edi,0x20
214
        dec  ecx
255
        dec  ecx
215
        jnz  .newupdate
256
        jnz  .newupdate
Line 216... Line 257...
216
 
257
 
-
 
258
        ret
-
 
259
 
-
 
260
if 0
-
 
261
 
-
 
262
 
-
 
263
struc TIMER
-
 
264
{
-
 
265
  .next      dd ?
-
 
266
  .exp_time  dd ?
-
 
267
  .func      dd ?
-
 
268
  .arg       dd ?
-
 
269
}
-
 
270
 
-
 
271
 
-
 
272
 
-
 
273
 
-
 
274
 
-
 
275
 
-
 
276
 
-
 
277
 
-
 
278
 
-
 
279
MAX_PROIRITY         0   ; highest, used for kernel tasks
-
 
280
MAX_USER_PRIORITY    0   ; highest priority for user processes
-
 
281
USER_PRIORITY        7   ; default (should correspond to nice 0)
-
 
282
MIN_USER_PRIORITY   14   ; minimum priority for user processes
-
 
283
IDLE_PRIORITY       15   ; lowest, only IDLE process goes here
-
 
284
NR_SCHED_QUEUES     16   ; MUST equal IDLE_PRIORYTY + 1
-
 
285
 
-
 
286
rdy_head   rd 16
-
 
287
 
-
 
288
 
-
 
289
align 4
-
 
290
pick_task:
-
 
291
 
-
 
292
           xor eax, eax
-
 
293
.pick:
-
 
294
           mov ebx, [rdy_head+eax*4]
-
 
295
           test ebx, ebx
-
 
296
           jz .next
-
 
297
 
-
 
298
           mov [next_task], ebx
-
 
299
           test [ebx+flags.billable]
-
 
300
           jz @F
-
 
301
           mov [bill_task], ebx
-
 
302
@@:
-
 
303
           ret
-
 
304
.next:
-
 
305
           inc eax
-
 
306
           jmp .pick
-
 
307
 
-
 
308
 
-
 
309
; param
-
 
310
;  eax= task
-
 
311
;
-
 
312
; retval
-
 
313
;  eax= task
-
 
314
;  ebx= queue
-
 
315
;  ecx= front if 1 or back if 0
-
 
316
 
-
 
317
align 4
-
 
318
shed:
-
 
319
           cmp [eax+.tics_left], 0 ;signed compare
-
 
320
           mov ebx, [eax+.priority]
-
 
321
           setg ecx
-
 
322
           jg @F
-
 
323
 
-
 
324
           mov edx, [eax+.tics_quantum]
-
 
325
           mov [eax+.ticks_left], edx
-
 
326
           cmp ebx, (IDLE_PRIORITY-1)
-
 
327
           je @F
-
 
328
           inc ebx
-
 
329
@@:
-
 
330
           ret
-
 
331
 
-
 
332
; param
-
 
333
;  eax= task
-
 
334
 
-
 
335
align 4
-
 
336
enqueue:
-
 
337
          call shed  ;eax
-
 
338
          cmp [rdy_head+ebx*4],0
-
 
339
          jnz @F
-
 
340
 
-
 
341
          mov [rdy_head+ebx*4], eax
-
 
342
          mov [rdy_tail+ebx*4], eax
-
 
343
          mov [eax+.next_ready], 0
-
 
344
          jmp .pick
-
 
345
@@:
-
 
346
          test ecx, ecx
-
 
347
          jz .back
-
 
348
 
-
 
349
          mov ecx, [rdy_head+ebx*4]
-
 
350
          mov [eax+.next_ready], ecx
-
 
351
          mov [rdy_head+ebx*4], eax
-
 
352
          jmp .pick
-
 
353
.back:
-
 
354
          mov ecx, [rdy_tail+ebx*4]
-
 
355
          mov [ecx+.next_ready], eax
-
 
356
          mov [rdy_tail+ebx*4], eax
-
 
357
          mov [eax+.next_ready], 0
-
 
358
.pick:
-
 
359
          call pick_proc     ;select next task
-
 
360
          ret
-
 
361
 
-
 
362
end if