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