Rev 102 | 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 |
||
65 | call find_next_task |
||
66 | test eax, eax ; the same task -> skip switch |
||
67 | jnz .return |
||
68 | |||
69 | mov [0xffff],byte 1 |
||
70 | call do_change_task |
||
71 | |||
72 | .return: |
||
73 | popad |
||
74 | popfd |
||
75 | |||
76 | ret |
||
77 | |||
78 | |||
79 | uglobal |
||
80 | align 4 |
||
81 | far_jump: |
||
82 | .offs dd ? |
||
83 | .sel dw ? |
||
84 | context_counter dd ? ;noname & halyavin |
||
85 | next_usage_update dd ? |
||
86 | timer_ticks dd ? |
||
87 | prev_slot dd ? |
||
88 | event_sched dd ? |
||
89 | endg |
||
90 | |||
91 | |||
92 | update_counters: |
||
1 | ha | 93 | mov edi, [0x3010] |
115 | poddubny | 94 | mov ebx, [edi+TASKDATA.counter_add] ; time stamp counter add |
1 | ha | 95 | call _rdtsc |
96 | sub eax, ebx |
||
115 | poddubny | 97 | add eax, [edi+TASKDATA.counter_sum] ; counter sum |
98 | mov [edi+TASKDATA.counter_sum], eax |
||
101 | poddubny | 99 | ret |
1 | ha | 100 | |
101 | poddubny | 101 | |
102 | ; Find next task to execute |
||
103 | ; result: ebx = number of the selected task |
||
102 | poddubny | 104 | ; eax = 1 if the task is the same |
105 | ; edi = address of the data for the task in ebx |
||
106 | ; [0x3000] = ebx and [0x3010] = edi |
||
107 | ; corrupts other regs |
||
101 | poddubny | 108 | find_next_task: |
102 | poddubny | 109 | mov ebx, [0x3000] |
110 | mov edi, [0x3010] |
||
21 | poddubny | 111 | mov [prev_slot], ebx |
1 | ha | 112 | |
113 | .waiting_for_termination: |
||
114 | .waiting_for_reuse: |
||
21 | poddubny | 115 | .waiting_for_event: |
40 | halyavin | 116 | .suspended: |
21 | poddubny | 117 | cmp ebx, [0x3004] |
118 | jb @f |
||
119 | mov edi, 0x3000 |
||
120 | xor ebx, ebx |
||
121 | @@: |
||
122 | |||
1 | ha | 123 | add edi,0x20 |
124 | inc ebx |
||
125 | |||
115 | poddubny | 126 | mov al, byte [edi+TASKDATA.state] |
101 | poddubny | 127 | test al, al |
128 | jz .found |
||
40 | halyavin | 129 | cmp al, 1 |
130 | jz .suspended |
||
131 | cmp al, 2 |
||
132 | jz .suspended |
||
1 | ha | 133 | cmp al, 3 |
134 | je .waiting_for_termination |
||
135 | cmp al, 4 |
||
136 | je .waiting_for_termination |
||
137 | cmp al, 9 |
||
138 | je .waiting_for_reuse |
||
139 | |||
140 | mov [0x3000],ebx |
||
141 | mov [0x3010],edi |
||
142 | |||
21 | poddubny | 143 | cmp al, 5 |
144 | jne .noevents |
||
145 | call get_event_for_app |
||
146 | test eax, eax |
||
147 | jz .waiting_for_event |
||
148 | mov [event_sched], eax |
||
115 | poddubny | 149 | mov [edi+TASKDATA.state], byte 0 |
26 | halyavin | 150 | .noevents: |
101 | poddubny | 151 | .found: |
152 | mov [0x3000],ebx |
||
153 | mov [0x3010],edi |
||
1 | ha | 154 | call _rdtsc |
115 | poddubny | 155 | mov [edi+TASKDATA.counter_add],eax |
1 | ha | 156 | |
101 | poddubny | 157 | xor eax, eax |
158 | cmp ebx, [prev_slot] |
||
159 | sete al |
||
160 | ret |
||
161 | |||
162 | ; in: ebx = TSS selector index |
||
163 | do_change_task: |
||
1 | ha | 164 | shl ebx, 3 |
165 | xor eax, eax |
||
166 | add ebx, tss0 |
||
101 | poddubny | 167 | mov [far_jump.sel], bx ; selector |
168 | mov [far_jump.offs], eax ; offset |
||
14 | poddubny | 169 | jmp pword [far_jump] |
9 | halyavin | 170 | inc [context_counter] ;noname & halyavin |
101 | poddubny | 171 | ret |
1 | ha | 172 | |
8 | poddubny | 173 | |
1 | ha | 174 | |
175 | align 4 |
||
176 | updatecputimes: |
||
177 | |||
178 | mov eax,[idleuse] |
||
179 | mov [idleusesec],eax |
||
180 | mov [idleuse],dword 0 |
||
181 | mov ecx, [0x3004] |
||
182 | mov edi, 0x3020 |
||
183 | .newupdate: |
||
115 | poddubny | 184 | mov ebx,[edi+TASKDATA.counter_sum] |
185 | mov [edi+TASKDATA.cpu_usage],ebx |
||
186 | mov [edi+TASKDATA.counter_sum],dword 0 |
||
1 | ha | 187 | add edi,0x20 |
188 | dec ecx |
||
189 | jnz .newupdate |
||
190 | |||
191 | ret---><---><<---> |