Subversion Repositories Kolibri OS

Rev

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

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