Subversion Repositories Kolibri OS

Rev

Rev 431 | Rev 465 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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