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