Subversion Repositories Kolibri OS

Rev

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

Rev 8 Rev 9
1
label  next_usage_update   dword   at  0xB008
1
label  next_usage_update   dword   at  0xB008
2
label  timer_ticks         dword   at  0xFDF0
2
label  timer_ticks         dword   at  0xFDF0
3
 
3
 
4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
5
;; IRQ0 HANDLER (TIMER INTERRUPT) ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
7
 
8
align 32
8
align 32
9
irq0:
9
irq0:
10
	pushad
10
	pushad
11
	push  ds es
11
	push  ds es
12
	mov   ax, os_data
12
	mov   ax, os_data
13
	mov   ds, ax
13
	mov   ds, ax
14
	mov   es, ax
14
	mov   es, ax
15
 
15
 
16
        mov   edi,[0x3000]
16
        mov   edi,[0x3000]
17
        shl   edi, 3
17
        shl   edi, 3
18
                         ; fields of TSS descriptor:
18
                         ; fields of TSS descriptor:
19
        mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
19
        mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
20
 
20
 
21
        inc   dword [timer_ticks]
21
        inc   dword [timer_ticks]
22
 
22
 
23
        mov   eax, [timer_ticks]
23
        mov   eax, [timer_ticks]
24
        cmp   eax,[next_usage_update]
24
        cmp   eax,[next_usage_update]
25
        jb    .nocounter
25
        jb    .nocounter
26
        add   eax,100
26
        add   eax,100
27
        mov   [next_usage_update],eax
27
        mov   [next_usage_update],eax
28
        call  updatecputimes
28
        call  updatecputimes
29
     .nocounter:
29
     .nocounter:
30
 
30
 
31
        call  playNote           ; <<<--- Speaker driver
31
        call  playNote           ; <<<--- Speaker driver
32
 
32
 
33
        mov   edi, [0x3010]
33
        mov   edi, [0x3010]
34
 
34
 
35
        mov   ebx, [edi+0x18] ; time stamp counter add
35
        mov   ebx, [edi+0x18] ; time stamp counter add
36
        call  _rdtsc
36
        call  _rdtsc
37
        sub   eax, ebx
37
        sub   eax, ebx
38
        add   eax, [edi+0x14] ; counter sum
38
        add   eax, [edi+0x14] ; counter sum
39
        mov   [edi+0x14], eax
39
        mov   [edi+0x14], eax
40
 
40
 
41
        mov   ebx,[0x3000]
41
        mov   ebx,[0x3000]
-
 
42
 
42
 
43
        xor   esi,esi           ;esi - should we change task?
43
        cmp   [0xffff], byte 1
44
        cmp   [0xffff], byte 1
44
        je    .do_not_change_task
45
        je    .do_not_change_task
45
 
46
 
46
      .waiting_for_termination:
47
      .waiting_for_termination:
47
      .waiting_for_reuse:
48
      .waiting_for_reuse:
48
        add   edi,0x20
49
        add   edi,0x20
49
        inc   ebx
50
        inc   ebx
50
 
51
 
51
        mov   al, byte [edi+0xA]
52
        mov   al, byte [edi+0xA]
52
        cmp   al, 3
53
        cmp   al, 3
53
        je    .waiting_for_termination
54
        je    .waiting_for_termination
54
        cmp   al, 4
55
        cmp   al, 4
55
        je    .waiting_for_termination
56
        je    .waiting_for_termination
56
        cmp   al, 9
57
        cmp   al, 9
57
        je    .waiting_for_reuse
58
        je    .waiting_for_reuse
58
 
59
 
59
        cmp   ebx,[0x3004]
60
        cmp   ebx,[0x3004]
60
        jbe   @f
61
        jbe   @f
61
        mov   ebx,1
62
        mov   ebx,1
62
        mov   edi,0x3020
63
        mov   edi,0x3020
63
       @@:
64
       @@:
64
 
65
 
65
        mov   [0x3000],ebx
66
        mov   [0x3000],ebx
66
        mov   [0x3010],edi
67
        mov   [0x3010],edi
67
 
68
 
68
        jmp   @f
69
        jmp   @f
69
     .do_not_change_task:
70
     .do_not_change_task:
70
        mov   [noct], 1
71
        inc   esi          ;set don't change task flag
71
       @@:
72
       @@:
72
 
73
 
73
        call  _rdtsc
74
        call  _rdtsc
74
        mov   [edi+0x18],eax
75
        mov   [edi+0x18],eax
75
 
76
 
76
        cmp   [0xffff],byte 0
77
        cmp   [0xffff],byte 0
77
        je    @f
78
        je    @f
78
        dec   byte [0xffff]
79
        dec   byte [0xffff]
79
       @@:
80
       @@:
80
 
81
 
81
 
82
 
82
        shl   ebx, 3
83
        shl   ebx, 3
83
        xor   eax, eax
84
        xor   eax, eax
84
        add   ebx, tss0
85
        add   ebx, tss0
85
        mov   word  [0xB004], bx   ; selector
86
        mov   word  [0xB004], bx   ; selector
86
        mov   dword [0xB000], eax  ; offset
87
        mov   dword [0xB000], eax  ; offset
87
 
88
 
88
        mov   al,0x20   ; send End Of Interrupt signal
89
        mov   al,0x20   ; send End Of Interrupt signal
89
        mov   dx,0x20
90
        mov   dx,0x20
90
        out   dx,al
91
        out   dx,al
91
 
92
 
92
        cmp   [noct], 1
93
        test  esi,esi   ; skip jmp to TSS if we aren't going to switch tasks
-
 
94
        jnz    @f
93
        je    @f
95
        
94
.switch:
-
 
95
        jmp   pword [0xB000]
96
.switch:
96
        inc [context_counter] ;noname & halyavin
-
 
97
       @@:
97
        inc   [context_counter] ;noname & halyavin
-
 
98
        jmp   pword [0xB000]
98
        mov   [noct], 0
99
 
99
        
100
       @@:
100
        pop   es ds
101
        pop   es ds
101
        popad
102
        popad
102
        iret
103
        iret
103
 
104
 
104
 
105
 
105
 
106
 
106
uglobal
107
uglobal
107
context_counter dd 0 ;noname & halyavin
108
context_counter dd 0 ;noname & halyavin
108
noct db 0
-
 
109
endg
109
endg
110
 
110
 
111
 
111
 
112
align 4
112
align 4
113
change_task:
113
change_task:
114
 
114
 
115
        mov   [0xffff],byte 2
115
        mov   [0xffff],byte 2
116
 
116
 
117
        dec   dword [timer_ticks]  ; because irq0 will increase it
117
        dec   dword [timer_ticks]  ; because irq0 will increase it
118
 
118
 
119
        int   0x20   ; irq0 handler
119
        int   0x20   ; irq0 handler
120
 
120
 
121
        ret
121
        ret
122
 
122
 
123
 
123
 
124
 
124
 
125
align 4
125
align 4
126
updatecputimes:
126
updatecputimes:
127
 
127
 
128
        mov  eax,[idleuse]
128
        mov  eax,[idleuse]
129
        mov  [idleusesec],eax
129
        mov  [idleusesec],eax
130
        mov  [idleuse],dword 0
130
        mov  [idleuse],dword 0
131
        mov  ecx, [0x3004]
131
        mov  ecx, [0x3004]
132
        mov  edi, 0x3020
132
        mov  edi, 0x3020
133
      .newupdate:
133
      .newupdate:
134
        mov  ebx,[edi+0x14]
134
        mov  ebx,[edi+0x14]
135
        mov  [edi+0x1c],ebx
135
        mov  [edi+0x1c],ebx
136
        mov  [edi+0x14],dword 0
136
        mov  [edi+0x14],dword 0
137
        add  edi,0x20
137
        add  edi,0x20
138
        dec  ecx
138
        dec  ecx
139
        jnz  .newupdate
139
        jnz  .newupdate
140
 
140
 
141
        ret
141
        ret