Rev 115 | Rev 379 | 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: |
||
40 | halyavin | 8 | save_ring3_context |
8 | poddubny | 9 | mov ax, os_data |
10 | mov ds, ax |
||
11 | mov es, ax |
||
1 | ha | 12 | |
13 | inc dword [timer_ticks] |
||
14 | |||
15 | mov eax, [timer_ticks] |
||
22 | poddubny | 16 | call playNote ; <<<--- Speaker driver |
17 | |||
1 | ha | 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 | |||
101 | poddubny | 25 | cmp [0xffff], byte 1 |
26 | jne .change_task |
||
27 | |||
28 | mov al,0x20 ; send End Of Interrupt signal |
||
29 | mov dx,0x20 |
||
30 | out dx,al |
||
31 | |||
32 | mov [0xffff], byte 0 |
||
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 |
||
51 | |||
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 |
||
187 | diamond | 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 [0x3000], ebx |
||
71 | je .return |
||
72 | mov edi, [dma_slot_ptr] |
||
73 | mov [0x3000], ebx |
||
74 | mov [0x3010], edi |
||
75 | jmp @f |
||
76 | .find_next_task: |
||
77 | ; \end{Mario79} |
||
101 | poddubny | 78 | call find_next_task |
79 | test eax, eax ; the same task -> skip switch |
||
80 | jnz .return |
||
187 | diamond | 81 | @@: |
101 | poddubny | 82 | mov [0xffff],byte 1 |
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: |
||
1 | ha | 106 | mov edi, [0x3010] |
115 | poddubny | 107 | mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add |
1 | ha | 108 | call _rdtsc |
109 | sub eax, ebx |
||
115 | poddubny | 110 | add eax, [edi+TASKDATA.counter_sum] ; counter sum |
111 | mov [edi+TASKDATA.counter_sum], eax |
||
101 | poddubny | 112 | ret |
1 | ha | 113 | |
101 | poddubny | 114 | |
115 | ; Find next task to execute |
||
116 | ; result: ebx = number of the selected task |
||
102 | poddubny | 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 |
||
101 | poddubny | 121 | find_next_task: |
102 | poddubny | 122 | mov ebx, [0x3000] |
123 | mov edi, [0x3010] |
||
21 | poddubny | 124 | mov [prev_slot], ebx |
1 | ha | 125 | |
126 | .waiting_for_termination: |
||
127 | .waiting_for_reuse: |
||
21 | poddubny | 128 | .waiting_for_event: |
40 | halyavin | 129 | .suspended: |
21 | poddubny | 130 | cmp ebx, [0x3004] |
131 | jb @f |
||
132 | mov edi, 0x3000 |
||
133 | xor ebx, ebx |
||
134 | @@: |
||
135 | |||
1 | ha | 136 | add edi,0x20 |
137 | inc ebx |
||
138 | |||
115 | poddubny | 139 | mov al, byte [edi+TASKDATA.state] |
101 | poddubny | 140 | test al, al |
141 | jz .found |
||
40 | halyavin | 142 | cmp al, 1 |
143 | jz .suspended |
||
144 | cmp al, 2 |
||
145 | jz .suspended |
||
1 | ha | 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 | |||
153 | mov [0x3000],ebx |
||
154 | mov [0x3010],edi |
||
155 | |||
21 | poddubny | 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 |
||
115 | poddubny | 162 | mov [edi+TASKDATA.state], byte 0 |
26 | halyavin | 163 | .noevents: |
101 | poddubny | 164 | .found: |
165 | mov [0x3000],ebx |
||
166 | mov [0x3010],edi |
||
1 | ha | 167 | call _rdtsc |
115 | poddubny | 168 | mov [edi+TASKDATA.counter_add],eax |
1 | ha | 169 | |
101 | poddubny | 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: |
||
1 | ha | 177 | shl ebx, 3 |
178 | xor eax, eax |
||
179 | add ebx, tss0 |
||
101 | poddubny | 180 | mov [far_jump.sel], bx ; selector |
181 | mov [far_jump.offs], eax ; offset |
||
14 | poddubny | 182 | jmp pword [far_jump] |
9 | halyavin | 183 | inc [context_counter] ;noname & halyavin |
101 | poddubny | 184 | ret |
1 | ha | 185 | |
8 | poddubny | 186 | |
1 | ha | 187 | |
188 | align 4 |
||
189 | updatecputimes: |
||
190 | |||
191 | mov eax,[idleuse] |
||
192 | mov [idleusesec],eax |
||
193 | mov [idleuse],dword 0 |
||
194 | mov ecx, [0x3004] |
||
195 | mov edi, 0x3020 |
||
196 | .newupdate: |
||
115 | poddubny | 197 | mov ebx,[edi+TASKDATA.counter_sum] |
198 | mov [edi+TASKDATA.cpu_usage],ebx |
||
199 | mov [edi+TASKDATA.counter_sum],dword 0 |
||
1 | ha | 200 | add edi,0x20 |
201 | dec ecx |
||
202 | jnz .newupdate |
||
203 | |||
204 | ret---><---><<---> |