Rev 381 | Rev 431 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
425 | victor | 1 | $Revision: 425 $ |
1 | ha | 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3 | ;; IRQ0 HANDLER (TIMER INTERRUPT) ;; |
||
4 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
5 | |||
101 | poddubny | 6 | |
1 | ha | 7 | align 32 |
8 | irq0: |
||
40 | halyavin | 9 | save_ring3_context |
8 | poddubny | 10 | mov ax, os_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 |
||
24 | .nocounter: |
||
25 | |||
381 | serge | 26 | cmp [DONT_SWITCH], byte 1 |
101 | poddubny | 27 | jne .change_task |
28 | |||
29 | mov al,0x20 ; send End Of Interrupt signal |
||
30 | mov dx,0x20 |
||
31 | out dx,al |
||
32 | |||
381 | serge | 33 | mov [DONT_SWITCH], byte 0 |
101 | poddubny | 34 | |
35 | restore_ring3_context |
||
36 | iret |
||
37 | |||
38 | .change_task: |
||
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 | |
101 | poddubny | 53 | .return: |
54 | restore_ring3_context |
||
55 | iret |
||
56 | |||
57 | |||
58 | align 4 |
||
59 | change_task: |
||
60 | |||
61 | pushfd |
||
62 | cli |
||
63 | pushad |
||
64 | |||
65 | call update_counters |
||
187 | diamond | 66 | ; \begin{Mario79} |
67 | cmp [dma_task_switched], 1 |
||
68 | jne .find_next_task |
||
69 | mov [dma_task_switched], 0 |
||
70 | mov ebx, [dma_process] |
||
379 | serge | 71 | cmp [CURRENT_TASK], ebx |
187 | diamond | 72 | je .return |
73 | mov edi, [dma_slot_ptr] |
||
379 | serge | 74 | mov [CURRENT_TASK], ebx |
75 | mov [TASK_BASE], edi |
||
187 | diamond | 76 | jmp @f |
77 | .find_next_task: |
||
78 | ; \end{Mario79} |
||
101 | poddubny | 79 | call find_next_task |
80 | test eax, eax ; the same task -> skip switch |
||
81 | jnz .return |
||
187 | diamond | 82 | @@: |
381 | serge | 83 | mov [DONT_SWITCH],byte 1 |
101 | poddubny | 84 | call do_change_task |
85 | |||
86 | .return: |
||
87 | popad |
||
88 | popfd |
||
89 | |||
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 |
1 | ha | 109 | call _rdtsc |
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 | |
127 | .waiting_for_termination: |
||
128 | .waiting_for_reuse: |
||
21 | poddubny | 129 | .waiting_for_event: |
40 | halyavin | 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 |
26 | halyavin | 164 | .noevents: |
101 | poddubny | 165 | .found: |
379 | serge | 166 | mov [CURRENT_TASK],ebx |
167 | mov [TASK_BASE],edi |
||
1 | ha | 168 | call _rdtsc |
115 | poddubny | 169 | mov [edi+TASKDATA.counter_add],eax |
1 | ha | 170 | |
101 | poddubny | 171 | xor eax, eax |
172 | cmp ebx, [prev_slot] |
||
173 | sete al |
||
174 | ret |
||
175 | |||
176 | ; in: ebx = TSS selector index |
||
177 | do_change_task: |
||
1 | ha | 178 | shl ebx, 3 |
179 | xor eax, eax |
||
180 | add ebx, tss0 |
||
101 | poddubny | 181 | mov [far_jump.sel], bx ; selector |
182 | mov [far_jump.offs], eax ; offset |
||
14 | poddubny | 183 | jmp pword [far_jump] |
9 | halyavin | 184 | inc [context_counter] ;noname & halyavin |
101 | poddubny | 185 | ret |
1 | ha | 186 | |
8 | poddubny | 187 | |
1 | ha | 188 | |
189 | align 4 |
||
190 | updatecputimes: |
||
191 | |||
192 | mov eax,[idleuse] |
||
193 | mov [idleusesec],eax |
||
194 | mov [idleuse],dword 0 |
||
379 | serge | 195 | mov ecx, [TASK_COUNT] |
196 | mov edi, TASK_DATA |
||
1 | ha | 197 | .newupdate: |
115 | poddubny | 198 | mov ebx,[edi+TASKDATA.counter_sum] |
199 | mov [edi+TASKDATA.cpu_usage],ebx |
||
200 | mov [edi+TASKDATA.counter_sum],dword 0 |
||
1 | ha | 201 | add edi,0x20 |
202 | dec ecx |
||
203 | jnz .newupdate |
||
204 | |||
205 | ret---><---><<---> |