Rev 5984 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5984 | Rev 6339 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
4 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
4 | ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; Distributed under terms of the GNU General Public License ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 5984 $ |
8 | $Revision: 6339 $ |
9 | 9 | ||
10 | 10 | ||
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
12 | ;; IRQ0 HANDLER (TIMER INTERRUPT) ;; |
12 | ;; IRQ0 HANDLER (TIMER INTERRUPT) ;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
14 | 14 | ||
15 | 15 | ||
16 | align 32 |
16 | align 32 |
17 | irq0: |
17 | irq0: |
18 | pushad |
18 | pushad |
19 | mov ax, app_data |
19 | mov ax, app_data |
20 | mov ds, ax |
20 | mov ds, ax |
21 | mov es, ax |
21 | mov es, ax |
22 | inc [timer_ticks] |
22 | inc [timer_ticks] |
23 | mov eax, [timer_ticks] |
23 | mov eax, [timer_ticks] |
24 | call playNote ; <<<--- Speaker driver |
24 | call playNote ; <<<--- Speaker driver |
25 | sub eax, [next_usage_update] |
25 | sub eax, [next_usage_update] |
26 | cmp eax, 100 |
26 | cmp eax, 100 |
27 | jb .nocounter |
27 | jb .nocounter |
28 | add [next_usage_update], 100 |
28 | add [next_usage_update], 100 |
29 | call updatecputimes |
29 | call updatecputimes |
30 | .nocounter: |
30 | .nocounter: |
31 | xor ecx, ecx ; send End Of Interrupt signal |
31 | xor ecx, ecx ; send End Of Interrupt signal |
32 | call irq_eoi |
32 | call irq_eoi |
33 | 33 | ||
34 | mov bl, SCHEDULE_ANY_PRIORITY |
34 | mov bl, SCHEDULE_ANY_PRIORITY |
35 | call find_next_task |
35 | call find_next_task |
36 | jz .return ; if there is only one running process |
36 | jz .return ; if there is only one running process |
37 | call do_change_task |
37 | call do_change_task |
38 | .return: |
38 | .return: |
39 | popad |
39 | popad |
40 | iretd |
40 | iretd |
41 | 41 | ||
42 | align 4 |
42 | align 4 |
43 | change_task: |
43 | change_task: |
44 | pushfd |
44 | pushfd |
45 | cli |
45 | cli |
46 | pushad |
46 | pushad |
47 | mov bl, SCHEDULE_ANY_PRIORITY |
47 | mov bl, SCHEDULE_ANY_PRIORITY |
48 | call find_next_task |
48 | call find_next_task |
49 | jz .return ; the same task -> skip switch |
49 | jz .return ; the same task -> skip switch |
50 | 50 | ||
51 | call do_change_task |
51 | call do_change_task |
52 | .return: |
52 | .return: |
53 | popad |
53 | popad |
54 | popfd |
54 | popfd |
55 | ret |
55 | ret |
56 | 56 | ||
57 | uglobal |
57 | uglobal |
58 | align 4 |
58 | align 4 |
59 | ; far_jump: |
- | |
60 | ; .offs dd ? |
- | |
61 | ; .sel dw ? |
- | |
62 | context_counter dd 0 ;noname & halyavin |
59 | context_counter dd 0 ;noname & halyavin |
63 | next_usage_update dd 0 |
60 | next_usage_update dd 0 |
64 | timer_ticks dd 0 |
61 | timer_ticks dd 0 |
65 | ; prev_slot dd ? |
62 | ; prev_slot dd ? |
66 | ; event_sched dd ? |
63 | ; event_sched dd ? |
67 | endg |
64 | endg |
68 | 65 | ||
69 | align 4 |
66 | align 4 |
70 | update_counters: |
67 | update_counters: |
71 | mov edi, [TASK_BASE] |
68 | mov edi, [TASK_BASE] |
72 | rdtsc |
69 | rdtsc |
73 | sub eax, [edi+TASKDATA.counter_add] ; time stamp counter add |
70 | sub eax, [edi+TASKDATA.counter_add] ; time stamp counter add |
74 | add [edi+TASKDATA.counter_sum], eax ; counter sum |
71 | add [edi+TASKDATA.counter_sum], eax ; counter sum |
75 | ret |
72 | ret |
76 | align 4 |
73 | align 4 |
77 | updatecputimes: |
74 | updatecputimes: |
78 | mov ecx, [TASK_COUNT] |
75 | mov ecx, [TASK_COUNT] |
79 | mov edi, TASK_DATA |
76 | mov edi, TASK_DATA |
80 | .newupdate: |
77 | .newupdate: |
81 | xor eax, eax |
78 | xor eax, eax |
82 | xchg eax, [edi+TASKDATA.counter_sum] |
79 | xchg eax, [edi+TASKDATA.counter_sum] |
83 | mov [edi+TASKDATA.cpu_usage], eax |
80 | mov [edi+TASKDATA.cpu_usage], eax |
84 | add edi, 0x20 |
81 | add edi, 0x20 |
85 | loop .newupdate |
82 | loop .newupdate |
86 | ret |
83 | ret |
87 | 84 | ||
88 | ;TODO: Надо бы убрать использование do_change_task из V86... |
85 | ;TODO: Надо бы убрать использование do_change_task из V86... |
89 | ; и после этого перенести обработку TASKDATA.counter_add/sum в do_change_task |
86 | ; и после этого перенести обработку TASKDATA.counter_add/sum в do_change_task |
90 | 87 | ||
91 | align 4 |
88 | align 4 |
92 | do_change_task: |
89 | do_change_task: |
93 | ;param: |
90 | ;param: |
94 | ; ebx = address of the APPDATA for incoming task (new) |
91 | ; ebx = address of the APPDATA for incoming task (new) |
95 | ;warning: |
92 | ;warning: |
96 | ; [CURRENT_TASK] and [TASK_BASE] must be changed before (e.g. in find_next_task) |
93 | ; [CURRENT_TASK] and [TASK_BASE] must be changed before (e.g. in find_next_task) |
97 | ; [current_slot] is the outcoming (old), and set here to a new value (ebx) |
94 | ; [current_slot] is the outcoming (old), and set here to a new value (ebx) |
98 | ;scratched: eax,ecx,esi |
95 | ;scratched: eax,ecx,esi |
99 | mov esi, ebx |
96 | mov esi, ebx |
100 | xchg esi, [current_slot] |
97 | xchg esi, [current_slot] |
101 | ; set new stack after saving old |
98 | ; set new stack after saving old |
102 | mov [esi+APPDATA.saved_esp], esp |
99 | mov [esi+APPDATA.saved_esp], esp |
103 | mov esp, [ebx+APPDATA.saved_esp] |
100 | mov esp, [ebx+APPDATA.saved_esp] |
104 | ; set new thread io-map |
101 | ; set new thread io-map |
105 | mov eax, [ebx+APPDATA.io_map] |
102 | mov eax, [ebx+APPDATA.io_map] |
106 | mov dword [page_tabs+((tss._io_map_0 and -4096) shr 10)], eax |
103 | ; mov dword [page_tabs+((tss._io_map_0 and -4096) shr 9)], eax |
107 | mov eax, [ebx+APPDATA.io_map+4] |
104 | mov eax, [ebx+APPDATA.io_map+4] |
108 | mov dword [page_tabs+((tss._io_map_1 and -4096) shr 10)], eax |
105 | ; mov dword [page_tabs+((tss._io_map_1 and -4096) shr 9)], eax |
109 | ; set new thread memory-map |
106 | ; set new thread memory-map |
110 | mov eax, [ebx+APPDATA.process] |
107 | mov eax, [ebx+APPDATA.process] |
111 | cmp eax, [current_process] |
108 | cmp eax, [current_process] |
112 | je @f |
109 | je @f |
113 | mov [current_process], eax |
110 | mov [current_process], eax |
- | 111 | ||
- | 112 | mov ecx, [eax+PROC.pdt_0_phys] |
|
114 | mov eax, [eax+PROC.pdt_0_phys] |
113 | mov eax, [eax+PROC.pdt_1_phys] |
- | 114 | or ecx, PG_READ |
|
- | 115 | or eax, PG_READ |
|
- | 116 | mov [sys_pml3], ecx |
|
- | 117 | mov [sys_pml3+8], eax |
|
- | 118 | ||
- | 119 | or ecx, PG_SWR |
|
- | 120 | or eax, PG_SWR |
|
- | 121 | ||
- | 122 | mov [sys_pml2+OS_BASE+8192-20*8], ecx |
|
- | 123 | mov [sys_pml2+OS_BASE+8192-19*8], eax |
|
- | 124 | ||
- | 125 | mov eax, sys_pml3-OS_BASE |
|
115 | mov cr3, eax |
126 | mov cr3, eax |
116 | @@: |
127 | @@: |
117 | ; set tss.esp0 |
128 | ; set tss.esp0 |
118 | 129 | ||
119 | mov eax, [ebx+APPDATA.saved_esp0] |
130 | mov eax, [ebx+APPDATA.saved_esp0] |
120 | mov [tss._esp0], eax |
131 | mov [tss._esp0], eax |
121 | 132 | ||
122 | mov edx, [ebx+APPDATA.tls_base] |
133 | mov edx, [ebx+APPDATA.tls_base] |
123 | 134 | ||
124 | mov [tls_data_l+2], dx |
135 | mov [tls_data_l+2], dx |
125 | shr edx, 16 |
136 | shr edx, 16 |
126 | mov [tls_data_l+4], dl |
137 | mov [tls_data_l+4], dl |
127 | mov [tls_data_l+7], dh |
138 | mov [tls_data_l+7], dh |
128 | 139 | ||
129 | mov dx, app_tls |
140 | mov dx, app_tls |
130 | mov fs, dx |
141 | mov fs, dx |
131 | 142 | ||
132 | ; set gs selector unconditionally |
143 | ; set gs selector unconditionally |
133 | Mov ax, graph_data |
144 | Mov ax, graph_data |
134 | Mov gs, ax |
145 | Mov gs, ax |
135 | ; set CR0.TS |
146 | ; set CR0.TS |
136 | cmp bh, byte[fpu_owner] ;bh == incoming task (new) |
147 | cmp bh, byte[fpu_owner] ;bh == incoming task (new) |
137 | clts ;clear a task switch flag |
148 | clts ;clear a task switch flag |
138 | je @f |
149 | je @f |
139 | mov eax, cr0 ;and set it again if the owner |
150 | mov eax, cr0 ;and set it again if the owner |
140 | or eax, CR0_TS ;of a fpu has changed |
151 | or eax, CR0_TS ;of a fpu has changed |
141 | mov cr0, eax |
152 | mov cr0, eax |
142 | @@: ; set context_counter (only for user pleasure ???) |
153 | @@: ; set context_counter (only for user pleasure ???) |
143 | inc [context_counter] ;noname & halyavin |
154 | inc [context_counter] ;noname & halyavin |
144 | ; set debug-registers, if it's necessary |
155 | ; set debug-registers, if it's necessary |
145 | test byte[ebx+APPDATA.dbg_state], 1 |
156 | test byte[ebx+APPDATA.dbg_state], 1 |
146 | jz @f |
157 | jz @f |
147 | xor eax, eax |
158 | xor eax, eax |
148 | mov dr6, eax |
159 | mov dr6, eax |
149 | lea esi, [ebx+APPDATA.dbg_regs] |
160 | lea esi, [ebx+APPDATA.dbg_regs] |
150 | cld |
161 | cld |
151 | macro lodsReg [reg] { |
162 | macro lodsReg [reg] { |
152 | lodsd |
163 | lodsd |
153 | mov reg, eax |
164 | mov reg, eax |
154 | } lodsReg dr0, dr1, dr2, dr3, dr7 |
165 | } lodsReg dr0, dr1, dr2, dr3, dr7 |
155 | purge lodsReg |
166 | purge lodsReg |
156 | @@: |
167 | @@: |
157 | ret |
168 | ret |
158 | ;end. |
169 | ;end. |
159 | 170 | ||
160 | 171 | ||
161 | 172 | ||
162 | 173 | ||
163 | MAX_PRIORITY = 0 ; highest, used for kernel tasks |
174 | MAX_PRIORITY = 0 ; highest, used for kernel tasks |
164 | USER_PRIORITY = 1 ; default |
175 | USER_PRIORITY = 1 ; default |
165 | IDLE_PRIORITY = 2 ; lowest, only IDLE thread goes here |
176 | IDLE_PRIORITY = 2 ; lowest, only IDLE thread goes here |
166 | NR_SCHED_QUEUES = 3 ; MUST equal IDLE_PRIORYTY + 1 |
177 | NR_SCHED_QUEUES = 3 ; MUST equal IDLE_PRIORYTY + 1 |
167 | 178 | ||
168 | uglobal |
179 | uglobal |
169 | ; [scheduler_current + i*4] = zero if there are no threads with priority i, |
180 | ; [scheduler_current + i*4] = zero if there are no threads with priority i, |
170 | ; pointer to APPDATA of the current thread with priority i otherwise. |
181 | ; pointer to APPDATA of the current thread with priority i otherwise. |
171 | align 4 |
182 | align 4 |
172 | scheduler_current rd NR_SCHED_QUEUES |
183 | scheduler_current rd NR_SCHED_QUEUES |
173 | endg |
184 | endg |
174 | 185 | ||
175 | ; Add the given thread to the given priority list for the scheduler. |
186 | ; Add the given thread to the given priority list for the scheduler. |
176 | ; in: edx -> APPDATA, ecx = priority |
187 | ; in: edx -> APPDATA, ecx = priority |
177 | proc scheduler_add_thread |
188 | proc scheduler_add_thread |
178 | ; 1. Acquire the lock. |
189 | ; 1. Acquire the lock. |
179 | spin_lock_irqsave SchedulerLock |
190 | spin_lock_irqsave SchedulerLock |
180 | ; 2. Store the priority in APPDATA structure. |
191 | ; 2. Store the priority in APPDATA structure. |
181 | mov [edx+APPDATA.priority], ecx |
192 | mov [edx+APPDATA.priority], ecx |
182 | ; 3. There are two different cases: the given list is empty or not empty. |
193 | ; 3. There are two different cases: the given list is empty or not empty. |
183 | ; In first case, go to 6. Otherwise, advance to 4. |
194 | ; In first case, go to 6. Otherwise, advance to 4. |
184 | mov eax, [scheduler_current+ecx*4] |
195 | mov eax, [scheduler_current+ecx*4] |
185 | test eax, eax |
196 | test eax, eax |
186 | jz .new_list |
197 | jz .new_list |
187 | ; 4. Insert the new item immediately before the current item. |
198 | ; 4. Insert the new item immediately before the current item. |
188 | mov ecx, [eax+APPDATA.in_schedule.prev] |
199 | mov ecx, [eax+APPDATA.in_schedule.prev] |
189 | mov [edx+APPDATA.in_schedule.next], eax |
200 | mov [edx+APPDATA.in_schedule.next], eax |
190 | mov [edx+APPDATA.in_schedule.prev], ecx |
201 | mov [edx+APPDATA.in_schedule.prev], ecx |
191 | mov [eax+APPDATA.in_schedule.prev], edx |
202 | mov [eax+APPDATA.in_schedule.prev], edx |
192 | mov [ecx+APPDATA.in_schedule.next], edx |
203 | mov [ecx+APPDATA.in_schedule.next], edx |
193 | ; 5. Release the lock and return. |
204 | ; 5. Release the lock and return. |
194 | spin_unlock_irqrestore SchedulerLock |
205 | spin_unlock_irqrestore SchedulerLock |
195 | ret |
206 | ret |
196 | .new_list: |
207 | .new_list: |
197 | ; 6. Initialize the list with one item and make it the current item. |
208 | ; 6. Initialize the list with one item and make it the current item. |
198 | mov [edx+APPDATA.in_schedule.next], edx |
209 | mov [edx+APPDATA.in_schedule.next], edx |
199 | mov [edx+APPDATA.in_schedule.prev], edx |
210 | mov [edx+APPDATA.in_schedule.prev], edx |
200 | mov [scheduler_current+ecx*4], edx |
211 | mov [scheduler_current+ecx*4], edx |
201 | ; 7. Release the lock and return. |
212 | ; 7. Release the lock and return. |
202 | spin_unlock_irqrestore SchedulerLock |
213 | spin_unlock_irqrestore SchedulerLock |
203 | ret |
214 | ret |
204 | endp |
215 | endp |
205 | 216 | ||
206 | ; Remove the given thread from the corresponding priority list for the scheduler. |
217 | ; Remove the given thread from the corresponding priority list for the scheduler. |
207 | ; in: edx -> APPDATA |
218 | ; in: edx -> APPDATA |
208 | proc scheduler_remove_thread |
219 | proc scheduler_remove_thread |
209 | ; 1. Acquire the lock. |
220 | ; 1. Acquire the lock. |
210 | spin_lock_irqsave SchedulerLock |
221 | spin_lock_irqsave SchedulerLock |
211 | ; 2. Remove the item from the corresponding list. |
222 | ; 2. Remove the item from the corresponding list. |
212 | mov eax, [edx+APPDATA.in_schedule.next] |
223 | mov eax, [edx+APPDATA.in_schedule.next] |
213 | mov ecx, [edx+APPDATA.in_schedule.prev] |
224 | mov ecx, [edx+APPDATA.in_schedule.prev] |
214 | mov [eax+APPDATA.in_schedule.prev], ecx |
225 | mov [eax+APPDATA.in_schedule.prev], ecx |
215 | mov [ecx+APPDATA.in_schedule.next], eax |
226 | mov [ecx+APPDATA.in_schedule.next], eax |
216 | ; 3. If the given thread is the current item in the list, |
227 | ; 3. If the given thread is the current item in the list, |
217 | ; advance the current item. |
228 | ; advance the current item. |
218 | ; 3a. Check whether the given thread is the current item; |
229 | ; 3a. Check whether the given thread is the current item; |
219 | ; if no, skip the rest of this step. |
230 | ; if no, skip the rest of this step. |
220 | mov ecx, [edx+APPDATA.priority] |
231 | mov ecx, [edx+APPDATA.priority] |
221 | cmp [scheduler_current+ecx*4], edx |
232 | cmp [scheduler_current+ecx*4], edx |
222 | jnz .return |
233 | jnz .return |
223 | ; 3b. Set the current item to eax; step 2 has set eax = next item. |
234 | ; 3b. Set the current item to eax; step 2 has set eax = next item. |
224 | mov [scheduler_current+ecx*4], eax |
235 | mov [scheduler_current+ecx*4], eax |
225 | ; 3c. If there were only one item in the list, zero the current item. |
236 | ; 3c. If there were only one item in the list, zero the current item. |
226 | cmp eax, edx |
237 | cmp eax, edx |
227 | jnz .return |
238 | jnz .return |
228 | mov [scheduler_current+ecx*4], 0 |
239 | mov [scheduler_current+ecx*4], 0 |
229 | .return: |
240 | .return: |
230 | ; 4. Release the lock and return. |
241 | ; 4. Release the lock and return. |
231 | spin_unlock_irqrestore SchedulerLock |
242 | spin_unlock_irqrestore SchedulerLock |
232 | ret |
243 | ret |
233 | endp |
244 | endp |
234 | 245 | ||
235 | SCHEDULE_ANY_PRIORITY = 0 |
246 | SCHEDULE_ANY_PRIORITY = 0 |
236 | SCHEDULE_HIGHER_PRIORITY = 1 |
247 | SCHEDULE_HIGHER_PRIORITY = 1 |
237 | ;info: |
248 | ;info: |
238 | ; Find next task to execute |
249 | ; Find next task to execute |
239 | ;in: |
250 | ;in: |
240 | ; bl = SCHEDULE_ANY_PRIORITY: |
251 | ; bl = SCHEDULE_ANY_PRIORITY: |
241 | ; consider threads with any priority |
252 | ; consider threads with any priority |
242 | ; bl = SCHEDULE_HIGHER_PRIORITY: |
253 | ; bl = SCHEDULE_HIGHER_PRIORITY: |
243 | ; consider only threads with strictly higher priority than the current one, |
254 | ; consider only threads with strictly higher priority than the current one, |
244 | ; keep running the current thread if other ready threads have the same or lower priority |
255 | ; keep running the current thread if other ready threads have the same or lower priority |
245 | ;retval: |
256 | ;retval: |
246 | ; ebx = address of the APPDATA for the selected task (slot-base) |
257 | ; ebx = address of the APPDATA for the selected task (slot-base) |
247 | ; edi = address of the TASKDATA for the selected task |
258 | ; edi = address of the TASKDATA for the selected task |
248 | ; ZF = 1 if the task is the same |
259 | ; ZF = 1 if the task is the same |
249 | ;warning: |
260 | ;warning: |
250 | ; [CURRENT_TASK] = bh , [TASK_BASE] = edi -- as result |
261 | ; [CURRENT_TASK] = bh , [TASK_BASE] = edi -- as result |
251 | ; [current_slot] is not set to new value (ebx)!!! |
262 | ; [current_slot] is not set to new value (ebx)!!! |
252 | ;scratched: eax,ecx |
263 | ;scratched: eax,ecx |
253 | proc find_next_task |
264 | proc find_next_task |
254 | call update_counters |
265 | call update_counters |
255 | spin_lock_irqsave SchedulerLock |
266 | spin_lock_irqsave SchedulerLock |
256 | push NR_SCHED_QUEUES |
267 | push NR_SCHED_QUEUES |
257 | ; If bl == SCHEDULE_ANY_PRIORITY = 0, loop over all NR_SCHED lists. |
268 | ; If bl == SCHEDULE_ANY_PRIORITY = 0, loop over all NR_SCHED lists. |
258 | ; Otherwise, loop over first [APPDATA.priority] lists. |
269 | ; Otherwise, loop over first [APPDATA.priority] lists. |
259 | test bl, bl |
270 | test bl, bl |
260 | jz .start |
271 | jz .start |
261 | mov ebx, [current_slot] |
272 | mov ebx, [current_slot] |
262 | mov edi, [TASK_BASE] |
273 | mov edi, [TASK_BASE] |
263 | mov eax, [ebx+APPDATA.priority] |
274 | mov eax, [ebx+APPDATA.priority] |
264 | test eax, eax |
275 | test eax, eax |
265 | jz .unlock_found |
276 | jz .unlock_found |
266 | mov [esp], eax |
277 | mov [esp], eax |
267 | .start: |
278 | .start: |
268 | xor ecx, ecx |
279 | xor ecx, ecx |
269 | .priority_loop: |
280 | .priority_loop: |
270 | mov ebx, [scheduler_current+ecx*4] |
281 | mov ebx, [scheduler_current+ecx*4] |
271 | test ebx, ebx |
282 | test ebx, ebx |
272 | jz .priority_next |
283 | jz .priority_next |
273 | .task_loop: |
284 | .task_loop: |
274 | mov ebx, [ebx+APPDATA.in_schedule.next] |
285 | mov ebx, [ebx+APPDATA.in_schedule.next] |
275 | mov edi, ebx |
286 | mov edi, ebx |
276 | shr edi, 3 |
287 | shr edi, 3 |
277 | add edi, CURRENT_TASK - (SLOT_BASE shr 3) |
288 | add edi, CURRENT_TASK - (SLOT_BASE shr 3) |
278 | mov al, [edi+TASKDATA.state] |
289 | mov al, [edi+TASKDATA.state] |
279 | test al, al |
290 | test al, al |
280 | jz .task_found ; state == 0 |
291 | jz .task_found ; state == 0 |
281 | cmp al, 5 |
292 | cmp al, 5 |
282 | jne .task_next ; state == 1,2,3,4,9 |
293 | jne .task_next ; state == 1,2,3,4,9 |
283 | ; state == 5 |
294 | ; state == 5 |
284 | pushad ; more freedom for [APPDATA.wait_test] |
295 | pushad ; more freedom for [APPDATA.wait_test] |
285 | call [ebx+APPDATA.wait_test] |
296 | call [ebx+APPDATA.wait_test] |
286 | mov [esp+28], eax |
297 | mov [esp+28], eax |
287 | popad |
298 | popad |
288 | or eax, eax |
299 | or eax, eax |
289 | jnz @f |
300 | jnz @f |
290 | ; testing for timeout |
301 | ; testing for timeout |
291 | mov eax, [timer_ticks] |
302 | mov eax, [timer_ticks] |
292 | sub eax, [ebx+APPDATA.wait_begin] |
303 | sub eax, [ebx+APPDATA.wait_begin] |
293 | cmp eax, [ebx+APPDATA.wait_timeout] |
304 | cmp eax, [ebx+APPDATA.wait_timeout] |
294 | jb .task_next |
305 | jb .task_next |
295 | xor eax, eax |
306 | xor eax, eax |
296 | @@: |
307 | @@: |
297 | mov [ebx+APPDATA.wait_param], eax ; retval for wait |
308 | mov [ebx+APPDATA.wait_param], eax ; retval for wait |
298 | mov [edi+TASKDATA.state], 0 |
309 | mov [edi+TASKDATA.state], 0 |
299 | .task_found: |
310 | .task_found: |
300 | mov [scheduler_current+ecx*4], ebx |
311 | mov [scheduler_current+ecx*4], ebx |
301 | ; If we have selected a thread with higher priority |
312 | ; If we have selected a thread with higher priority |
302 | ; AND rescheduling is due to IRQ, |
313 | ; AND rescheduling is due to IRQ, |
303 | ; turn the current scheduler list one entry back, |
314 | ; turn the current scheduler list one entry back, |
304 | ; so the current thread will be next after high-priority thread is done. |
315 | ; so the current thread will be next after high-priority thread is done. |
305 | mov ecx, [esp] |
316 | mov ecx, [esp] |
306 | cmp ecx, NR_SCHED_QUEUES |
317 | cmp ecx, NR_SCHED_QUEUES |
307 | jz .unlock_found |
318 | jz .unlock_found |
308 | mov eax, [current_slot] |
319 | mov eax, [current_slot] |
309 | mov eax, [eax+APPDATA.in_schedule.prev] |
320 | mov eax, [eax+APPDATA.in_schedule.prev] |
310 | mov [scheduler_current+ecx*4], eax |
321 | mov [scheduler_current+ecx*4], eax |
311 | .unlock_found: |
322 | .unlock_found: |
312 | pop ecx |
323 | pop ecx |
313 | spin_unlock_irqrestore SchedulerLock |
324 | spin_unlock_irqrestore SchedulerLock |
314 | .found: |
325 | .found: |
315 | mov [CURRENT_TASK], bh |
326 | mov [CURRENT_TASK], bh |
316 | mov [TASK_BASE], edi |
327 | mov [TASK_BASE], edi |
317 | rdtsc ;call _rdtsc |
328 | rdtsc ;call _rdtsc |
318 | mov [edi+TASKDATA.counter_add], eax; for next using update_counters |
329 | mov [edi+TASKDATA.counter_add], eax; for next using update_counters |
319 | cmp ebx, [current_slot] |
330 | cmp ebx, [current_slot] |
320 | ret |
331 | ret |
321 | .task_next: |
332 | .task_next: |
322 | cmp ebx, [scheduler_current+ecx*4] |
333 | cmp ebx, [scheduler_current+ecx*4] |
323 | jnz .task_loop |
334 | jnz .task_loop |
324 | .priority_next: |
335 | .priority_next: |
325 | inc ecx |
336 | inc ecx |
326 | cmp ecx, [esp] |
337 | cmp ecx, [esp] |
327 | jb .priority_loop |
338 | jb .priority_loop |
328 | mov ebx, [current_slot] |
339 | mov ebx, [current_slot] |
329 | mov edi, [TASK_BASE] |
340 | mov edi, [TASK_BASE] |
330 | jmp .unlock_found |
341 | jmp .unlock_found |
331 | endp |
342 | endp |
332 | 343 | ||
333 | if 0 |
344 | if 0 |
334 | 345 | ||
335 | struc TIMER |
346 | struc TIMER |
336 | { |
347 | { |
337 | .next dd ? |
348 | .next dd ? |
338 | .exp_time dd ? |
349 | .exp_time dd ? |
339 | .func dd ? |
350 | .func dd ? |
340 | .arg dd ? |
351 | .arg dd ? |
341 | } |
352 | } |
342 | 353 | ||
343 | 354 | ||
344 | uglobal |
355 | uglobal |
345 | rdy_head rd 16 |
356 | rdy_head rd 16 |
346 | endg |
357 | endg |
347 | 358 | ||
348 | align 4 |
359 | align 4 |
349 | pick_task: |
360 | pick_task: |
350 | 361 | ||
351 | xor eax, eax |
362 | xor eax, eax |
352 | .pick: |
363 | .pick: |
353 | mov ebx, [rdy_head+eax*4] |
364 | mov ebx, [rdy_head+eax*4] |
354 | test ebx, ebx |
365 | test ebx, ebx |
355 | jz .next |
366 | jz .next |
356 | 367 | ||
357 | mov [next_task], ebx |
368 | mov [next_task], ebx |
358 | test [ebx+flags.billable] |
369 | test [ebx+flags.billable] |
359 | jz @F |
370 | jz @F |
360 | mov [bill_task], ebx |
371 | mov [bill_task], ebx |
361 | @@: |
372 | @@: |
362 | ret |
373 | ret |
363 | .next: |
374 | .next: |
364 | inc eax |
375 | inc eax |
365 | jmp .pick |
376 | jmp .pick |
366 | 377 | ||
367 | ; param |
378 | ; param |
368 | ; eax= task |
379 | ; eax= task |
369 | ; |
380 | ; |
370 | ; retval |
381 | ; retval |
371 | ; eax= task |
382 | ; eax= task |
372 | ; ebx= queue |
383 | ; ebx= queue |
373 | ; ecx= front if 1 or back if 0 |
384 | ; ecx= front if 1 or back if 0 |
374 | align 4 |
385 | align 4 |
375 | shed: |
386 | shed: |
376 | cmp [eax+.tics_left], 0;signed compare |
387 | cmp [eax+.tics_left], 0;signed compare |
377 | mov ebx, [eax+.priority] |
388 | mov ebx, [eax+.priority] |
378 | setg ecx |
389 | setg ecx |
379 | jg @F |
390 | jg @F |
380 | 391 | ||
381 | mov edx, [eax+.tics_quantum] |
392 | mov edx, [eax+.tics_quantum] |
382 | mov [eax+.ticks_left], edx |
393 | mov [eax+.ticks_left], edx |
383 | cmp ebx, (IDLE_PRIORITY-1) |
394 | cmp ebx, (IDLE_PRIORITY-1) |
384 | je @F |
395 | je @F |
385 | inc ebx |
396 | inc ebx |
386 | @@: |
397 | @@: |
387 | ret |
398 | ret |
388 | 399 | ||
389 | ; param |
400 | ; param |
390 | ; eax= task |
401 | ; eax= task |
391 | align 4 |
402 | align 4 |
392 | enqueue: |
403 | enqueue: |
393 | call shed;eax |
404 | call shed;eax |
394 | cmp [rdy_head+ebx*4], 0 |
405 | cmp [rdy_head+ebx*4], 0 |
395 | jnz @F |
406 | jnz @F |
396 | 407 | ||
397 | mov [rdy_head+ebx*4], eax |
408 | mov [rdy_head+ebx*4], eax |
398 | mov [rdy_tail+ebx*4], eax |
409 | mov [rdy_tail+ebx*4], eax |
399 | mov [eax+.next_ready], 0 |
410 | mov [eax+.next_ready], 0 |
400 | jmp .pick |
411 | jmp .pick |
401 | @@: |
412 | @@: |
402 | test ecx, ecx |
413 | test ecx, ecx |
403 | jz .back |
414 | jz .back |
404 | 415 | ||
405 | mov ecx, [rdy_head+ebx*4] |
416 | mov ecx, [rdy_head+ebx*4] |
406 | mov [eax+.next_ready], ecx |
417 | mov [eax+.next_ready], ecx |
407 | mov [rdy_head+ebx*4], eax |
418 | mov [rdy_head+ebx*4], eax |
408 | jmp .pick |
419 | jmp .pick |
409 | .back: |
420 | .back: |
410 | mov ecx, [rdy_tail+ebx*4] |
421 | mov ecx, [rdy_tail+ebx*4] |
411 | mov [ecx+.next_ready], eax |
422 | mov [ecx+.next_ready], eax |
412 | mov [rdy_tail+ebx*4], eax |
423 | mov [rdy_tail+ebx*4], eax |
413 | mov [eax+.next_ready], 0 |
424 | mov [eax+.next_ready], 0 |
414 | .pick: |
425 | .pick: |
415 | call pick_proc;select next task |
426 | call pick_proc;select next task |
416 | ret |
427 | ret |
417 | 428 | ||
418 | end if---><---><<---> |
429 | end if---><---><<---> |