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