Subversion Repositories Kolibri OS

Rev

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

Rev 1161 Rev 1198
Line 14... Line 14...
14
 
14
 
15
 
15
 
16
align 32
16
align 32
17
irq0:
17
irq0:
18
	pushad
-
 
19
	mov   ax, app_data  ;
18
        pushad
20
	mov   ds, ax
-
 
21
	mov   es, ax
-
 
22
 
-
 
23
;       cmp     dword[CURRENT_TASK], 1
-
 
24
;       jnz     @f
-
 
25
;       mov     eax, [esp + 32]
-
 
26
;       cmp     eax, idle_loop + 1
-
 
27
;       jz      @f
-
 
28
;       DEBUGF  1, "K : OOOPS! EAX = 0x%x\n", eax
-
 
29
;   @@:
19
        Mov     ds, ax, app_data
30
 
-
 
31
	inc   dword [timer_ticks]
20
        mov     es, ax
32
 
21
        inc     [timer_ticks]
33
	mov   eax, [timer_ticks]
-
 
34
	call  playNote		 ; <<<--- Speaker driver
22
        mov     eax, [timer_ticks]
-
 
23
        call    playNote       ; <<<--- Speaker driver
35
 
24
        sub     eax,[next_usage_update]
36
	cmp   eax,[next_usage_update]
-
 
37
	jb    .nocounter
25
        cmp     eax,100
38
	add   eax,100
26
        jb      .nocounter
39
	mov   [next_usage_update],eax
27
        add     [next_usage_update],100
40
	call  updatecputimes
-
 
41
.nocounter:
-
 
42
	cmp   [DONT_SWITCH], byte 1
-
 
43
	jne   .change_task
28
        call    updatecputimes
44
 
-
 
45
	mov   al,0x20	; send End Of Interrupt signal
29
  .nocounter:
46
	mov   dx,0x20
-
 
47
	out   dx,al
30
        mov     al,0x20  ; send End Of Interrupt signal
48
 
-
 
49
	mov   [DONT_SWITCH], byte 0
-
 
50
 
-
 
51
	popad
-
 
52
	iretd
-
 
53
 
31
        out     0x20,al
54
.change_task:
-
 
55
	call  update_counters
32
        btr     dword[DONT_SWITCH], 0
56
 
-
 
57
	call  find_next_task
-
 
58
	mov   ecx, eax
-
 
59
 
-
 
60
	mov   al,0x20	; send End Of Interrupt signal
-
 
61
	mov   dx,0x20
-
 
62
	out   dx,al
33
        jc      .return
63
 
-
 
64
	test  ecx, ecx	; if there is only one running process
-
 
65
	jnz   .return
34
        call    find_next_task
66
 
-
 
67
	call  do_change_task
35
        jz      .return  ; if there is only one running process
68
 
36
        call    do_change_task
69
.return:
-
 
70
	popad
37
  .return:
Line 71... Line -...
71
 ;       popfd
-
 
72
	iretd
38
        popad
73
 
39
        iretd
74
 
-
 
75
align 4
40
 
76
change_task:
41
align 4
77
 
42
change_task:
78
	pushfd
-
 
79
	cli
-
 
80
	pushad
-
 
81
 
43
        pushfd
82
	call  update_counters
-
 
83
 
44
        cli
84
if 0
45
        pushad
85
 
46
if 0
86
; \begin{Mario79}
47
; \begin{Mario79} ; <- must be refractoried, if used...
87
	cmp	[dma_task_switched], 1
48
        cmp     [dma_task_switched], 1
88
	jne	.find_next_task
49
        jne     .find_next_task
Line 94... Line 55...
94
	mov	[CURRENT_TASK], ebx
55
        mov     [CURRENT_TASK], ebx
95
	mov	[TASK_BASE], edi
56
        mov     [TASK_BASE], edi
96
	jmp	@f
57
        jmp     @f
97
.find_next_task:
58
.find_next_task:
98
; \end{Mario79}
59
; \end{Mario79}
99
 
-
 
100
end if
60
end if
101
 
-
 
102
	call  find_next_task
61
        call    find_next_task
103
	test  eax, eax	  ; the same task -> skip switch
62
        jz      .return  ; the same task -> skip switch
104
	jnz    .return
-
 
105
@@:
-
 
106
	mov   [DONT_SWITCH],byte 1
63
  @@:   mov     byte[DONT_SWITCH], 1
107
	call  do_change_task
64
        call    do_change_task
108
 
-
 
109
.return:
65
  .return:
110
	popad
66
        popad
111
	popfd
67
        popfd
112
	ret
68
        ret
Line 113... Line -...
113
 
-
 
114
 
69
 
115
uglobal
70
uglobal
116
   align 4
71
align 4
117
   far_jump:
72
;  far_jump:
118
    .offs dd ?
73
;   .offs dd ?
119
    .sel  dw ?
74
;   .sel  dw ?
120
   context_counter     dd ? ;noname & halyavin
75
   context_counter     dd 0 ;noname & halyavin
121
   next_usage_update   dd ?
76
   next_usage_update   dd 0
122
   timer_ticks	       dd ?
77
   timer_ticks         dd 0
123
   prev_slot	       dd ?
78
;  prev_slot           dd ?
124
   event_sched	       dd ?
79
;  event_sched         dd ?
Line 125... Line 80...
125
endg
80
endg
126
 
81
 
127
 
82
align 4
128
update_counters:
-
 
129
	mov   edi, [TASK_BASE]
83
update_counters:
-
 
84
        mov     edi, [TASK_BASE]
-
 
85
        rdtsc
-
 
86
        sub     eax, [edi+TASKDATA.counter_add] ; time stamp counter add
-
 
87
        add     [edi+TASKDATA.counter_sum], eax ; counter sum
-
 
88
        ret
130
	mov   ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
89
align 4
-
 
90
updatecputimes:
-
 
91
        xor     eax,eax
-
 
92
        xchg    eax,[idleuse]
-
 
93
        mov     [idleusesec],eax
-
 
94
        mov     ecx, [TASK_COUNT]
-
 
95
        mov     edi, TASK_DATA
131
	rdtsc
96
  .newupdate:
132
	sub   eax, ebx
97
        xor     eax,eax
-
 
98
        xchg    eax,[edi+TASKDATA.counter_sum]
-
 
99
        mov     [edi+TASKDATA.cpu_usage],eax
133
	add   eax, [edi+TASKDATA.counter_sum] ; counter sum
100
        add     edi,0x20
Line 134... Line -...
134
	mov   [edi+TASKDATA.counter_sum], eax
-
 
135
ret
101
        loop    .newupdate
136
 
-
 
137
 
-
 
138
; Find next task to execute
-
 
139
; result: ebx = number of the selected task
-
 
140
;         eax = 1  if the task is the same
-
 
141
;         edi = address of the data for the task in ebx
102
        ret
-
 
103
 
142
;         [0x3000] = ebx and [0x3010] = edi
104
align 4
143
;         corrupts other regs
105
find_next_task:
-
 
106
;info:
144
find_next_task:
107
;   Find next task to execute
145
	mov   ebx, [CURRENT_TASK]
-
 
-
 
108
;retval:
146
	mov   edi, [TASK_BASE]
109
;   ebx = address of the APPDATA for the selected task (slot-base)
147
	mov   [prev_slot], ebx
110
;   esi = previous slot-base ([current_slot] at the begin)
-
 
111
;   edi = address of the TASKDATA for the selected task
-
 
112
;   ZF  = 1  if the task is the same
148
 
113
;warning:
-
 
114
;   [CURRENT_TASK] = bh , [TASK_BASE] = edi -- as result
-
 
115
;   [current_slot] is not set to new value (ebx)!!!
149
.waiting_for_termination:
116
;scratched: eax,ecx
150
.waiting_for_reuse:
117
        call    update_counters ; edi := [TASK_BASE]
151
.waiting_for_event:
118
        Mov     esi, ebx, [current_slot]
-
 
119
  .loop:
152
.suspended:
120
        cmp     bh,[TASK_COUNT]
153
	cmp   ebx, [TASK_COUNT]
121
        jb      @f
154
	jb    @f
-
 
155
	mov   edi, CURRENT_TASK
-
 
156
	xor   ebx, ebx
122
        xor     bh, bh
157
@@:
-
 
158
 
-
 
159
	add   edi,0x20
123
        mov     edi,CURRENT_TASK
160
	inc   ebx
124
  @@:   inc     bh       ; ebx += APPDATA.size
161
 
-
 
162
	mov   al, byte [edi+TASKDATA.state]
-
 
163
	test  al, al
-
 
164
	jz    .found
-
 
165
	cmp   al, 1
-
 
166
	jz    .suspended
-
 
167
	cmp   al, 2
125
        add     edi,0x20 ; edi += TASKDATA.size
168
	jz    .suspended
-
 
169
	cmp   al, 3
-
 
170
	je    .waiting_for_termination
-
 
171
	cmp   al, 4
-
 
172
	je    .waiting_for_termination
-
 
173
	cmp   al, 9
-
 
174
	je    .waiting_for_reuse
-
 
175
 
-
 
176
	mov   [CURRENT_TASK],ebx
126
        mov     al, [edi+TASKDATA.state]
-
 
127
        test    al, al
177
	mov   [TASK_BASE],edi
128
        jz      .found   ; state == 0
-
 
129
        cmp     al, 5
-
 
130
        jne     .loop    ; state == 1,2,3,4,9
178
 
131
      ; state == 5
-
 
132
        pushad  ; more freedom for [APPDATA.wait_test]
179
	cmp   al, 5
133
        call    [ebx+APPDATA.wait_test]
180
	jne   .noevents
134
        mov     [esp+28],eax
181
	call  get_event_for_app
135
        popad
182
	test  eax, eax
136
        or      eax,eax
183
	jnz   @f
137
        jnz     @f
184
	mov   eax, ebx
138
      ; testing for timeout
185
	shl   eax, 8
-
 
186
	mov   eax, [SLOT_BASE + APPDATA.wait_timeout + eax]
139
        mov     ecx, [timer_ticks]
187
	cmp   eax, [timer_ticks]
-
 
188
	jae   .waiting_for_event
140
        sub     ecx, [ebx+APPDATA.wait_begin]
189
	xor   eax, eax
141
        cmp     ecx, [ebx+APPDATA.wait_timeout]
190
@@:
-
 
191
	mov   [event_sched], eax
142
        jb      .loop
192
	mov   [edi+TASKDATA.state], byte 0
143
  @@:   mov     [ebx+APPDATA.wait_param], eax  ; retval for wait
193
.noevents:
144
        mov     [edi+TASKDATA.state], 0
194
.found:
145
  .found:
195
	mov   [CURRENT_TASK],ebx
146
        mov     [CURRENT_TASK],bh
196
	mov   [TASK_BASE],edi
-
 
197
	rdtsc			  ;call  _rdtsc
147
        mov     [TASK_BASE],edi
198
	mov   [edi+TASKDATA.counter_add],eax
-
 
199
 
-
 
200
	mov esi, [prev_slot]
-
 
201
	xor   eax, eax
148
        rdtsc   ;call  _rdtsc
-
 
149
        mov     [edi+TASKDATA.counter_add],eax ; for next using update_counters
-
 
150
        cmp     ebx, esi ;esi - previous slot-base
Line 202... Line 151...
202
	cmp   ebx, esi
151
        ret
203
	sete  al
-
 
204
ret
-
 
205
 
-
 
206
; param
152
;TODO: Íàäî áû óáðàòü èñïîëüçîâàíèå do_change_task èç V86...
207
;  ebx = incoming task
153
; è ïîñëå ýòîãî ïåðåíåñòè îáðàáîòêó TASKDATA.counter_add/sum â do_change_task
-
 
154
 
208
;  esi = outcomig task
155
align 4
-
 
156
do_change_task:
-
 
157
;param:
209
 
158
;   ebx = address of the APPDATA for incoming task (new)
210
do_change_task:
159
;warning:
211
 
-
 
212
	shl ebx, 8
160
;   [CURRENT_TASK] and [TASK_BASE] must be changed before (e.g. in find_next_task)
213
	add ebx, SLOT_BASE
161
;   [current_slot] is the outcoming (old), and set here to a new value (ebx)
214
	mov [current_slot], ebx
-
 
215
 
162
;scratched: eax,ecx,esi
216
	shl esi, 8
163
        mov     esi,ebx
217
	add esi, SLOT_BASE
-
 
218
 
164
        xchg    esi,[current_slot]
219
	mov [esi+APPDATA.saved_esp], esp
-
 
220
	mov esp, [ebx+APPDATA.saved_esp]
-
 
221
 
-
 
222
; set thread io map
165
      ; set new stack after saving old
223
 
166
        mov     [esi+APPDATA.saved_esp], esp
224
	mov ecx, [ebx+APPDATA.io_map]
-
 
-
 
167
        mov     esp, [ebx+APPDATA.saved_esp]
225
	mov edx, [ebx+APPDATA.io_map+4]
168
      ; set new thread io-map
-
 
169
        Mov     dword [page_tabs+((tss._io_map_0 and -4096) shr 10)],eax,[ebx+APPDATA.io_map]
226
	mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], ecx
170
        Mov     dword [page_tabs+((tss._io_map_1 and -4096) shr 10)],eax,[ebx+APPDATA.io_map+4]
227
	mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], edx
171
      ; set new thread memory-map
228
 
172
        mov     ecx, APPDATA.dir_table
229
	mov eax, [ebx+APPDATA.dir_table]
173
        mov     eax, [ebx+ecx]      ;offset>0x7F
230
	cmp eax, [esi+APPDATA.dir_table]
174
        cmp     eax, [esi+ecx]      ;offset>0x7F
231
	je @F
175
        je      @f
232
	mov cr3, eax
176
        mov     cr3, eax
233
@@:
-
 
234
	mov	eax, [ebx+APPDATA.saved_esp0]
-
 
235
	mov	[tss._esp0], eax
177
  @@: ; set tss.esp0
236
	mov ax, graph_data
178
        Mov     [tss._esp0],eax,[ebx+APPDATA.saved_esp0]
237
	mov gs, ax
179
      ; set gs selector unconditionally
238
 
180
        Mov     gs,ax,graph_data
239
	mov eax, [CURRENT_TASK]
181
      ; set CR0.TS
240
	cmp eax, [fpu_owner]
182
        cmp     bh, byte[fpu_owner] ;bh == incoming task (new)
241
	clts				 ;clear a task switch flag
-
 
242
	je @F
183
        clts                        ;clear a task switch flag
243
					 ;and set it again if the owner
-
 
-
 
184
        je      @f
244
	mov ecx, cr0			 ;of a fpu has changed
185
        mov     eax, cr0            ;and set it again if the owner
245
	or ecx, CR0_TS
-
 
246
	mov cr0, ecx
-
 
247
@@:
-
 
248
	inc   [context_counter] ;noname & halyavin
-
 
249
	test [ebx+APPDATA.dbg_state], 1
-
 
250
	jnz @F
-
 
251
	ret
186
        or      eax, CR0_TS         ;of a fpu has changed
252
@@:
-
 
253
	mov eax, [ebx+APPDATA.dbg_regs.dr0]
-
 
254
	mov dr0, eax
-
 
255
	mov eax, [ebx+APPDATA.dbg_regs.dr1]
187
        mov     cr0, eax
256
	mov dr1, eax
188
  @@: ; set context_counter (only for user pleasure ???)
257
	mov eax, [ebx+APPDATA.dbg_regs.dr2]
189
        inc     [context_counter]   ;noname & halyavin
258
	mov dr2, eax
190
      ; set debug-registers, if it's necessary
259
	mov eax, [ebx+APPDATA.dbg_regs.dr3]
191
        test    byte[ebx+APPDATA.dbg_state], 1
260
	mov dr3, eax
192
        jz      @f
261
	xor eax, eax
-
 
262
	mov dr6, eax
-
 
263
	mov eax, [ebx+APPDATA.dbg_regs.dr7]
-
 
264
	mov dr7, eax
193
        xor     eax, eax
265
	ret
-
 
266
 
194
        mov     dr6, eax
267
align 4
195
        lea     esi,[ebx+ecx+APPDATA.dbg_regs-APPDATA.dir_table] ;offset>0x7F
268
updatecputimes:
196
        cld
269
 
-
 
270
	mov  eax,[idleuse]
-
 
271
	mov  [idleusesec],eax
197
  macro lodsReg [reg] {
272
	mov  [idleuse],dword 0
-
 
273
	mov  ecx, [TASK_COUNT]
-
 
274
	mov  edi, TASK_DATA
-
 
275
.newupdate:
-
 
276
	mov  ebx,[edi+TASKDATA.counter_sum]
198
        lodsd
277
	mov  [edi+TASKDATA.cpu_usage],ebx
-
 
278
	mov  [edi+TASKDATA.counter_sum],dword 0
-
 
279
	add  edi,0x20
199
        mov     reg,eax
Line 280... Line 200...
280
	dec  ecx
200
  }     lodsReg dr0, dr1, dr2, dr3, dr7
281
	jnz  .newupdate
-
 
282
 
-
 
283
	ret
201
  purge lodsReg
284
 
202
  @@:   ret
285
if 0
203
;end.
286
 
204
 
287
 
205
if 0
288
struc TIMER
206
struc TIMER
289
{
207
{
Line 290... Line -...
290
  .next      dd ?
-
 
291
  .exp_time  dd ?
-
 
292
  .func      dd ?
-
 
293
  .arg	     dd ?
-
 
294
}
-
 
295
 
-
 
296
 
-
 
297
 
-
 
298
 
208
  .next      dd ?
299
 
209
  .exp_time  dd ?
300
 
210
  .func      dd ?
301
 
211
  .arg       dd ?
302
 
212
}
303
 
213
 
Line 304... Line 214...
304
MAX_PROIRITY	     0	 ; highest, used for kernel tasks
214
MAX_PROIRITY         0   ; highest, used for kernel tasks
Line 305... Line -...
305
MAX_USER_PRIORITY    0	 ; highest priority for user processes
-
 
306
USER_PRIORITY	     7	 ; default (should correspond to nice 0)
215
MAX_USER_PRIORITY    0   ; highest priority for user processes
307
MIN_USER_PRIORITY   14	 ; minimum priority for user processes
216
USER_PRIORITY        7   ; default (should correspond to nice 0)
Line 308... Line 217...
308
IDLE_PRIORITY	    15	 ; lowest, only IDLE process goes here
217
MIN_USER_PRIORITY   14   ; minimum priority for user processes
309
NR_SCHED_QUEUES     16	 ; MUST equal IDLE_PRIORYTY + 1
218
IDLE_PRIORITY       15   ; lowest, only IDLE process goes here
Line 328... Line 237...
328
	   ret
237
       ret
329
.next:
238
  .next:
330
	   inc eax
239
       inc eax
331
	   jmp .pick
240
       jmp .pick
Line 332... Line -...
332
 
-
 
333
 
241
 
334
; param
242
; param
335
;  eax= task
243
;  eax= task
336
;
244
;
337
; retval
245
; retval
338
;  eax= task
246
;  eax= task
339
;  ebx= queue
247
;  ebx= queue
340
;  ecx= front if 1 or back if 0
-
 
341
 
248
;  ecx= front if 1 or back if 0
342
align 4
249
align 4
343
shed:
250
shed:
344
	   cmp [eax+.tics_left], 0 ;signed compare
251
       cmp [eax+.tics_left], 0 ;signed compare
345
	   mov ebx, [eax+.priority]
252
       mov ebx, [eax+.priority]
Line 354... Line 261...
354
@@:
261
  @@:
355
	   ret
262
       ret
Line 356... Line 263...
356
 
263
 
357
; param
264
; param
358
;  eax= task
-
 
359
 
265
;  eax= task
360
align 4
266
align 4
361
enqueue:
267
enqueue:
362
	  call shed  ;eax
268
      call shed  ;eax
363
	  cmp [rdy_head+ebx*4],0
269
      cmp [rdy_head+ebx*4],0
Line 383... Line 289...
383
.pick:
289
  .pick:
384
	  call pick_proc     ;select next task
290
      call pick_proc     ;select next task
385
	  ret
291
      ret
Line 386... Line 292...
386
 
292
 
387
end if
-