Subversion Repositories Kolibri OS

Rev

Rev 387 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
 
101 poddubny 5
 
1 ha 6
align 32
7
irq0:
420 serge 8
        pushfd
9
        pushad
10
        mov   ax, app_data  ;
11
        mov   ds, ax
12
        mov   es, ax
1 ha 13
 
14
        inc   dword [timer_ticks]
15
 
16
        mov   eax, [timer_ticks]
22 poddubny 17
        call  playNote           ; <<<--- Speaker driver
18
 
1 ha 19
        cmp   eax,[next_usage_update]
20
        jb    .nocounter
21
        add   eax,100
22
        mov   [next_usage_update],eax
23
        call  updatecputimes
420 serge 24
.nocounter:
381 serge 25
        cmp   [DONT_SWITCH], byte 1
101 poddubny 26
        jne   .change_task
27
 
28
        mov   al,0x20   ; send End Of Interrupt signal
29
        mov   dx,0x20
30
        out   dx,al
31
 
381 serge 32
        mov   [DONT_SWITCH], byte 0
101 poddubny 33
 
420 serge 34
        popad
35
        popfd
36
        iretd
101 poddubny 37
 
420 serge 38
.change_task:
101 poddubny 39
        call  update_counters
40
 
41
        call  find_next_task
42
        mov   ecx, eax
43
 
44
        mov   al,0x20   ; send End Of Interrupt signal
45
        mov   dx,0x20
46
        out   dx,al
47
 
48
	test  ecx, ecx  ; if there is only one running process
49
        jnz   .return
50
 
51
        call  do_change_task
379 serge 52
 
420 serge 53
.return:
54
        popad
55
        popfd
56
        iretd
101 poddubny 57
 
58
 
59
align 4
60
change_task:
61
 
62
        pushfd
63
        cli
64
        pushad
65
 
66
        call  update_counters
187 diamond 67
; \begin{Mario79}
68
        cmp     [dma_task_switched], 1
69
        jne     .find_next_task
70
        mov     [dma_task_switched], 0
71
        mov     ebx, [dma_process]
379 serge 72
        cmp     [CURRENT_TASK], ebx
187 diamond 73
        je      .return
74
        mov     edi, [dma_slot_ptr]
379 serge 75
        mov     [CURRENT_TASK], ebx
76
        mov     [TASK_BASE], edi
187 diamond 77
        jmp     @f
78
.find_next_task:
79
; \end{Mario79}
101 poddubny 80
        call  find_next_task
81
        test  eax, eax    ; the same task -> skip switch
82
        jnz    .return
187 diamond 83
@@:
381 serge 84
        mov   [DONT_SWITCH],byte 1
101 poddubny 85
        call  do_change_task
86
 
420 serge 87
.return:
101 poddubny 88
        popad
89
        popfd
90
        ret
91
 
92
 
93
uglobal
94
   align 4
95
   far_jump:
96
    .offs dd ?
97
    .sel  dw ?
98
   context_counter     dd ? ;noname & halyavin
99
   next_usage_update   dd ?
100
   timer_ticks         dd ?
101
   prev_slot           dd ?
102
   event_sched         dd ?
103
endg
104
 
105
 
106
update_counters:
379 serge 107
        mov   edi, [TASK_BASE]
115 poddubny 108
        mov   ebx, [edi+TASKDATA.counter_add] ; time stamp counter add
420 serge 109
        rdtsc
1 ha 110
        sub   eax, ebx
115 poddubny 111
        add   eax, [edi+TASKDATA.counter_sum] ; counter sum
112
        mov   [edi+TASKDATA.counter_sum], eax
101 poddubny 113
ret
1 ha 114
 
101 poddubny 115
 
116
; Find next task to execute
117
; result: ebx = number of the selected task
102 poddubny 118
;         eax = 1  if the task is the same
119
;         edi = address of the data for the task in ebx
120
;         [0x3000] = ebx and [0x3010] = edi
121
;         corrupts other regs
101 poddubny 122
find_next_task:
379 serge 123
        mov   ebx, [CURRENT_TASK]
124
        mov   edi, [TASK_BASE]
21 poddubny 125
        mov   [prev_slot], ebx
1 ha 126
 
420 serge 127
.waiting_for_termination:
128
.waiting_for_reuse:
129
.waiting_for_event:
130
.suspended:
379 serge 131
        cmp   ebx, [TASK_COUNT]
21 poddubny 132
        jb    @f
379 serge 133
        mov   edi, CURRENT_TASK
21 poddubny 134
        xor   ebx, ebx
135
      @@:
136
 
1 ha 137
        add   edi,0x20
138
        inc   ebx
139
 
115 poddubny 140
        mov   al, byte [edi+TASKDATA.state]
101 poddubny 141
        test  al, al
142
        jz    .found
40 halyavin 143
	cmp   al, 1
144
	jz    .suspended
145
	cmp   al, 2
146
	jz    .suspended
1 ha 147
        cmp   al, 3
148
        je    .waiting_for_termination
149
        cmp   al, 4
150
        je    .waiting_for_termination
151
        cmp   al, 9
152
        je    .waiting_for_reuse
153
 
379 serge 154
        mov   [CURRENT_TASK],ebx
155
        mov   [TASK_BASE],edi
1 ha 156
 
21 poddubny 157
        cmp   al, 5
158
        jne   .noevents
159
        call  get_event_for_app
160
        test  eax, eax
161
        jz    .waiting_for_event
162
        mov   [event_sched], eax
115 poddubny 163
        mov   [edi+TASKDATA.state], byte 0
420 serge 164
.noevents:
165
.found:
379 serge 166
        mov   [CURRENT_TASK],ebx
167
        mov   [TASK_BASE],edi
420 serge 168
        rdtsc                     ;call  _rdtsc
115 poddubny 169
        mov   [edi+TASKDATA.counter_add],eax
1 ha 170
 
420 serge 171
        mov esi, [prev_slot]
101 poddubny 172
	xor   eax, eax
420 serge 173
        cmp   ebx, esi
101 poddubny 174
        sete  al
175
ret
176
 
177
; in: ebx = TSS selector index
420 serge 178
;
179
; param
180
;  ebx = incoming task
181
;  esi = outcomig task
182
 
101 poddubny 183
do_change_task:
420 serge 184
 
185
        shl ebx, 8
186
        add ebx, SLOT_BASE
187
        mov [current_slot], ebx
188
        shl esi, 8
189
        add esi, SLOT_BASE
190
 
191
        mov [esi+APPDATA.saved_esp], esp
192
        mov esp, [ebx+APPDATA.saved_esp]
193
 
194
        mov eax, [ebx+APPDATA.dir_table]
195
        mov cr3, eax
196
 
197
        mov ebx, [ebx+APPDATA.pl0_stack]
198
        add ebx, RING0_STACK_SIZE
199
        mov [tss_data+TSS._esp0], ebx
200
        mov ecx, cr0
201
        or ecx, CR0_TS   ;set task switch flag
202
        mov cr0, ecx
9 halyavin 203
        inc   [context_counter] ;noname & halyavin
1 ha 204
 
420 serge 205
        ret
8 poddubny 206
 
420 serge 207
;
208
;        shl   ebx, 3
209
;        xor   eax, eax
210
;        add   ebx, tss0
211
;        mov   [far_jump.sel],  bx   ; selector
212
;        mov   [far_jump.offs], eax  ; offset
213
;        jmp   pword [far_jump]
214
;        inc   [context_counter] ;noname & halyavin
215
;ret
1 ha 216
 
420 serge 217
 
218
 
1 ha 219
align 4
220
updatecputimes:
221
 
222
        mov  eax,[idleuse]
223
        mov  [idleusesec],eax
224
        mov  [idleuse],dword 0
379 serge 225
        mov  ecx, [TASK_COUNT]
226
        mov  edi, TASK_DATA
420 serge 227
.newupdate:
115 poddubny 228
        mov  ebx,[edi+TASKDATA.counter_sum]
229
        mov  [edi+TASKDATA.cpu_usage],ebx
230
        mov  [edi+TASKDATA.counter_sum],dword 0
1 ha 231
        add  edi,0x20
232
        dec  ecx
233
        jnz  .newupdate
234
 
235
        ret