Subversion Repositories Kolibri OS

Rev

Rev 100 | Rev 102 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 100 Rev 101
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
2
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line -... Line 4...
-
 
4
 
4
 
5
 
5
align 32
6
align 32
6
irq0:
7
irq0:
7
        save_ring3_context
8
        save_ring3_context
8
	mov   ax, os_data
9
	mov   ax, os_data
9
	mov   ds, ax
10
	mov   ds, ax
Line 10... Line -...
10
	mov   es, ax
-
 
11
 
-
 
12
        mov   edi,[0x3000]
-
 
13
        shl   edi, 3
-
 
14
                         ; fields of TSS descriptor:
-
 
15
;        mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
11
	mov   es, ax
Line 16... Line 12...
16
 
12
 
17
        inc   dword [timer_ticks]
13
        inc   dword [timer_ticks]
Line 24... Line 20...
24
        add   eax,100
20
        add   eax,100
25
        mov   [next_usage_update],eax
21
        mov   [next_usage_update],eax
26
        call  updatecputimes
22
        call  updatecputimes
27
     .nocounter:
23
     .nocounter:
Line -... Line 24...
-
 
24
 
-
 
25
        cmp   [0xffff], byte 1
-
 
26
        jne   .change_task
-
 
27
 
28
 
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:
Line -... Line 38...
-
 
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
 
29
        mov   edi, [0x3010]
92
update_counters:
30
 
93
        mov   edi, [0x3010]
31
        mov   ebx, [edi+0x18] ; time stamp counter add
94
        mov   ebx, [edi+0x18] ; time stamp counter add
32
        call  _rdtsc
95
        call  _rdtsc
33
        sub   eax, ebx
96
        sub   eax, ebx
-
 
97
        add   eax, [edi+0x14] ; counter sum
-
 
98
        mov   [edi+0x14], eax
Line -... Line 99...
-
 
99
ret
-
 
100
 
-
 
101
 
-
 
102
; Find next task to execute
34
        add   eax, [edi+0x14] ; counter sum
103
; result: ebx = number of the selected task
35
        mov   [edi+0x14], eax
104
;         [0xffff] = 1  if the task is the same
Line 36... Line -...
36
 
-
 
37
        mov   ebx,[0x3000]
-
 
38
        mov   [prev_slot], ebx
-
 
39
 
-
 
40
        cmp   [0xffff], byte 1
105
find_next_task:
41
        je    .do_not_change_task
106
        mov   ebx,[0x3000]
42
 
107
        mov   [prev_slot], ebx
43
 
108
 
44
      .waiting_for_termination:
109
      .waiting_for_termination:
Line 53... Line 118...
53
 
118
 
54
        add   edi,0x20
119
        add   edi,0x20
Line 55... Line 120...
55
        inc   ebx
120
        inc   ebx
-
 
121
 
-
 
122
        mov   al, byte [edi+0xA]
56
 
123
        test  al, al
57
        mov   al, byte [edi+0xA]
124
        jz    .found
58
	cmp   al, 1
125
	cmp   al, 1
59
	jz    .suspended
126
	jz    .suspended
60
	cmp   al, 2
127
	cmp   al, 2
Line 75... Line 142...
75
        test  eax, eax
142
        test  eax, eax
76
        jz    .waiting_for_event
143
        jz    .waiting_for_event
77
        mov   [event_sched], eax
144
        mov   [event_sched], eax
78
        mov   [edi+0xA], byte 0
145
        mov   [edi+0xA], byte 0
79
      .noevents:
146
      .noevents:
80
        cmp   ebx, [prev_slot]
147
      .found:
81
        sete  [0xffff]
148
        mov   [0x3000],ebx
82
 
-
 
83
 
-
 
84
     .do_not_change_task:
149
        mov   [0x3010],edi
85
 
-
 
86
        call  _rdtsc
150
        call  _rdtsc
87
        mov   [edi+0x18],eax
151
        mov   [edi+0x18],eax
Line -... Line 152...
-
 
152
 
-
 
153
	xor   eax, eax
-
 
154
        cmp   ebx, [prev_slot]
-
 
155
        sete  al
-
 
156
ret
-
 
157
 
-
 
158
; in: ebx = TSS selector index
88
 
159
do_change_task:
89
        shl   ebx, 3
160
        shl   ebx, 3
90
        xor   eax, eax
161
        xor   eax, eax
91
        add   ebx, tss0
162
        add   ebx, tss0
92
        mov   word  [far_jump.sel],  bx   ; selector
163
        mov   [far_jump.sel],  bx   ; selector
93
        mov   dword [far_jump.offs], eax  ; offset
-
 
94
        
-
 
95
        cmp   [irq0needeoi],byte 0
-
 
96
        mov   [irq0needeoi],byte 1          
-
 
97
        jz    .noeoi
-
 
98
 
-
 
99
        mov   al,0x20   ; send End Of Interrupt signal
-
 
100
        mov   dx,0x20
-
 
101
        out   dx,al
-
 
102
.noeoi:   
-
 
103
 
-
 
104
        cmp   [0xffff],byte 0
-
 
105
        je    .switch
-
 
106
        dec   byte [0xffff]
-
 
107
        jz    @f
-
 
108
     .switch:
164
        mov   [far_jump.offs], eax  ; offset
109
        jmp   pword [far_jump]
165
        jmp   pword [far_jump]
110
        inc   [context_counter] ;noname & halyavin
-
 
111
       @@:
-
 
112
        
-
 
113
        restore_ring3_context
-
 
114
        iret
-
 
115
 
-
 
116
 
-
 
117
uglobal
-
 
118
   align 4
-
 
119
   far_jump:
-
 
120
    .offs dd ?
-
 
121
    .sel  dw ?
-
 
122
   context_counter     dd ? ;noname & halyavin
-
 
123
   next_usage_update   dd ?
-
 
124
   timer_ticks         dd ?
-
 
125
   prev_slot dd ?
-
 
126
   event_sched dd ?
-
 
127
endg
-
 
128
iglobal
-
 
129
   irq0needeoi         db 1   
-
 
130
endg
-
 
131
 
-
 
132
 
-
 
133
align 4
-
 
134
change_task:
-
 
135
 
-
 
136
        pushfd
-
 
137
        cli
-
 
138
        mov   [0xffff],byte 2
-
 
139
 
-
 
140
        mov   [irq0needeoi],byte 0
-
 
141
        dec   dword [timer_ticks]  ; because irq0 will increase it
-
 
142
 
-
 
143
        int   0x20   ; irq0 handler
-
 
144
        popfd
-
 
145
 
166
        inc   [context_counter] ;noname & halyavin
Line 146... Line 167...
146
        ret
167
ret