Subversion Repositories Kolibri OS

Rev

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

Rev 147 Rev 154
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                               ;;
2
;;                                                               ;;
3
;;  MenuetOS process management, protected ring3                 ;;
3
;;  MenuetOS process management, protected ring3                 ;;
4
;;                                                               ;;
4
;;                                                               ;;
5
;;  Distributed under GPL. See file COPYING for details.         ;;
5
;;  Distributed under GPL. See file COPYING for details.         ;;
6
;;  Copyright 2003 Ville Turjanmaa                               ;;
6
;;  Copyright 2003 Ville Turjanmaa                               ;;
7
;;                                                               ;;
7
;;                                                               ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
9
 
10
align 32
10
align 32
11
 
11
 
12
; GDT TABLE
12
; GDT TABLE
13
 
13
 
14
gdts:
14
gdts:
15
 
15
 
16
        dw     gdte-$-1
16
        dw     gdte-$-1
17
        dd     gdts
17
        dd     gdts
18
        dw     0
18
        dw     0
19
 
19
 
20
int_code_l:
20
int_code_l:
21
os_code_l:
21
os_code_l:
22
 
22
 
23
        dw     0xffff
23
        dw     0xffff
24
        dw     0x0000
24
        dw     0x0000
25
        db     0x00
25
        db     0x00
26
        dw     11011111b *256 +10011010b
26
        dw     11011111b *256 +10011010b
27
        db     0x00
27
        db     0x00
28
 
28
 
29
int_data_l:
29
int_data_l:
30
os_data_l:
30
os_data_l:
31
 
31
 
32
        dw     0xffff
32
        dw     0xffff
33
        dw     0x0000
33
        dw     0x0000
34
        db     0x00
34
        db     0x00
35
        dw     11011111b *256 +10010010b
35
        dw     11011111b *256 +10010010b
36
        db     0x00
36
        db     0x00
37
 
37
 
38
; --------------- APM ---------------------
38
; --------------- APM ---------------------
39
apm_code_32:
39
apm_code_32:
40
        dw     0x10        ; limit 64kb
40
        dw     0x10        ; limit 64kb
41
        db     0, 0, 0
41
        db     0, 0, 0
42
        dw     11011111b *256 +10011010b
42
        dw     11011111b *256 +10011010b
43
        db     0x00
43
        db     0x00
44
apm_code_16:
44
apm_code_16:
45
        dw     0x10
45
        dw     0x10
46
        db     0, 0, 0
46
        db     0, 0, 0
47
        dw     10011111b *256 +10011010b
47
        dw     10011111b *256 +10011010b
48
        db     0x00
48
        db     0x00
49
apm_data_16:
49
apm_data_16:
50
        dw     0x10
50
        dw     0x10
51
        db     0, 0, 0
51
        db     0, 0, 0
52
        dw     10011111b *256 +10010010b
52
        dw     10011111b *256 +10010010b
53
        db     0x00
53
        db     0x00
54
; -----------------------------------------
54
; -----------------------------------------
55
 
55
 
56
app_code_l:
56
app_code_l:
57
      dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
57
      dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
58
      dw 0
58
      dw 0
59
      db 0
59
      db 0
60
      dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
60
      dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
61
      db std_application_base_address shr 24
61
      db std_application_base_address shr 24
62
 
62
 
63
app_data_l:
63
app_data_l:
64
      dw (0x80000000-std_application_base_address) shr 12 and 0xffff
64
      dw (0x80000000-std_application_base_address) shr 12 and 0xffff
65
      dw 0
65
      dw 0
66
      db 0
66
      db 0
67
      dw 11010000b*256+11110010b+256*((0x80000000-std_application_base_address) shr 28)
67
      dw 11010000b*256+11110010b+256*((0x80000000-std_application_base_address) shr 28)
68
      db std_application_base_address shr 24
68
      db std_application_base_address shr 24
69
 
69
 
70
graph_data_l:
70
graph_data_l:
71
 
71
 
72
        dw     0x3ff
72
        dw     0x3ff
73
        dw     0x0000
73
        dw     0x0000
74
        db     0x00
74
        db     0x00
75
        dw     11010000b *256 +11110010b
75
        dw     11010000b *256 +11110010b
76
        db     0x00
76
        db     0x00
77
 
77
 
78
tss0_l:
78
tss0_l:
79
      times (max_processes+10) dd 0,0
79
      times (max_processes+10) dd 0,0
80
 
80
 
81
gdte:
81
gdte:
82
 
82
 
83
 
83
 
84
 
84
 
85
idtreg:
85
idtreg:
86
     dw   8*0x41-1
86
     dw   8*0x41-1
87
     dd   idts+8
87
     dd   idts+8
88
label idts at 0xB100-8
88
label idts at 0xB100-8
89
 
89
 
90
 
90
 
91
 
91
 
92
uglobal
92
uglobal
93
 tss_sceleton:
93
 tss_sceleton:
94
  l.back   dw 0,0
94
  l.back   dw 0,0
95
  l.esp0   dd 0
95
  l.esp0   dd 0
96
  l.ss0    dw 0,0
96
  l.ss0    dw 0,0
97
  l.esp1   dd 0
97
  l.esp1   dd 0
98
  l.ss1    dw 0,0
98
  l.ss1    dw 0,0
99
  l.esp2   dd 0
99
  l.esp2   dd 0
100
  l.ss2    dw 0,0
100
  l.ss2    dw 0,0
101
  l.cr3    dd 0
101
  l.cr3    dd 0
102
  l.eip    dd 0
102
  l.eip    dd 0
103
  l.eflags dd 0
103
  l.eflags dd 0
104
  l.eax    dd 0
104
  l.eax    dd 0
105
  l.ecx    dd 0
105
  l.ecx    dd 0
106
  l.edx    dd 0
106
  l.edx    dd 0
107
  l.ebx    dd 0
107
  l.ebx    dd 0
108
  l.esp    dd 0
108
  l.esp    dd 0
109
  l.ebp    dd 0
109
  l.ebp    dd 0
110
  l.esi    dd 0
110
  l.esi    dd 0
111
  l.edi    dd 0
111
  l.edi    dd 0
112
  l.es     dw 0,0
112
  l.es     dw 0,0
113
  l.cs     dw 0,0
113
  l.cs     dw 0,0
114
  l.ss     dw 0,0
114
  l.ss     dw 0,0
115
  l.ds     dw 0,0
115
  l.ds     dw 0,0
116
  l.fs     dw 0,0
116
  l.fs     dw 0,0
117
  l.gs     dw 0,0
117
  l.gs     dw 0,0
118
  l.ldt    dw 0,0
118
  l.ldt    dw 0,0
119
  l.trap   dw 0
119
  l.trap   dw 0
120
  l.io     dw 0
120
  l.io     dw 0
121
endg
121
endg
122
 
122
 
123
 
123
 
124
build_process_gdt_tss_pointer:
124
build_process_gdt_tss_pointer:
125
 
125
 
126
        mov    ecx,tss_data
126
        mov    ecx,tss_data
127
        mov    edi,0
127
        mov    edi,0
128
      setgdtl2:
128
      setgdtl2:
129
        mov    [edi+gdts+ tss0 +0], word tss_step
129
        mov    [edi+gdts+ tss0 +0], word tss_step
130
        mov    [edi+gdts+ tss0 +2], cx
130
        mov    [edi+gdts+ tss0 +2], cx
131
        mov    eax,ecx
131
        mov    eax,ecx
132
        shr    eax,16
132
        shr    eax,16
133
        mov    [edi+gdts+ tss0 +4], al
133
        mov    [edi+gdts+ tss0 +4], al
134
        mov    [edi+gdts+ tss0 +7], ah
134
        mov    [edi+gdts+ tss0 +7], ah
135
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
135
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
136
        add    ecx,tss_step
136
        add    ecx,tss_step
137
        add    edi,8
137
        add    edi,8
138
        cmp    edi,8*(max_processes+5)
138
        cmp    edi,8*(max_processes+5)
139
        jbe    setgdtl2
139
        jbe    setgdtl2
140
 
140
 
141
        ret
141
        ret
142
 
142
 
143
 
143
 
144
build_interrupt_table:
144
build_interrupt_table:
145
 
145
 
146
        mov    edi, idts+8
146
        mov    edi, idts+8
147
        mov    esi, sys_int
147
        mov    esi, sys_int
148
        mov    ecx, 0x40
148
        mov    ecx, 0x40
149
     @@:
149
     @@:
150
        mov    eax, [esi]
150
        mov    eax, [esi]
151
        mov    [edi],   ax           ; lower part of offset
151
        mov    [edi],   ax           ; lower part of offset
152
        mov    [edi+2], word os_code ; segment selector
152
        mov    [edi+2], word os_code ; segment selector
153
        shr    eax, 16
153
        shr    eax, 16
154
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
154
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
155
        mov    [edi+6], ax
155
        mov    [edi+6], ax
156
        add    esi, 4
156
        add    esi, 4
157
        add    edi, 8
157
        add    edi, 8
158
        dec    ecx
158
        dec    ecx
159
        jnz    @b
159
        jnz    @b
160
        
160
        
161
        ;mov    edi,8*0x40+idts+8
161
        ;mov    edi,8*0x40+idts+8
162
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
162
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
163
        mov    [edi + 2], word os_code
163
        mov    [edi + 2], word os_code
164
        mov    [edi + 4], word 11101110b*256
164
        mov    [edi + 4], word 11101110b*256
165
        mov    [edi + 6], word (i40 shr 16)
165
        mov    [edi + 6], word (i40 shr 16)
166
 
166
 
167
        ret
167
        ret
168
 
168
 
169
 
169
 
170
 
170
 
171
iglobal
171
iglobal
172
  sys_int:
172
  sys_int:
173
    dd   e0,debug_exc,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15
173
    dd   e0,debug_exc,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15
174
    dd   e16,e17
174
    dd   e16,e17
175
    times 14 dd unknown_interrupt
175
    times 14 dd unknown_interrupt
176
 
176
 
177
    dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
177
    dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
178
    dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
178
    dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
179
 
179
 
180
    times 16 dd unknown_interrupt
180
    times 16 dd unknown_interrupt
181
 
181
 
182
    dd   i40
182
    dd   i40
183
endg
183
endg
184
 
184
 
185
macro save_ring3_context
185
macro save_ring3_context
186
{
186
{
187
    push    ds es
187
    push    ds es
188
    pushad
188
    pushad
189
}
189
}
190
macro restore_ring3_context
190
macro restore_ring3_context
191
{
191
{
192
    popad
192
    popad
193
    pop    es ds
193
    pop    es ds
194
}
194
}
195
 
195
 
196
; simply return control to interrupted process
196
; simply return control to interrupted process
197
unknown_interrupt:
197
unknown_interrupt:
198
     iret
198
     iret
199
 
199
 
200
macro exc_wo_code [num]
200
macro exc_wo_code [num]
201
{
201
{
202
  forward
202
  forward
203
  e#num :
203
  e#num :
204
      save_ring3_context
204
      save_ring3_context
205
      mov bl, num
205
      mov bl, num
206
      jmp exc_c
206
      jmp exc_c
207
}
207
}
208
 
208
 
209
macro exc_w_code [num]
209
macro exc_w_code [num]
210
{
210
{
211
  forward
211
  forward
212
  e#num :
212
  e#num :
213
      add esp, 4
213
      add esp, 4
214
      save_ring3_context
214
      save_ring3_context
215
      mov bl, num
215
      mov bl, num
216
      jmp exc_c
216
      jmp exc_c
217
}
217
}
218
 
218
 
219
exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 16 ; 18, 19
219
exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 16 ; 18, 19
220
exc_w_code 8, 10, 11, 12, 13, 14, 17
220
exc_w_code 8, 10, 11, 12, 13, 14, 17
221
 
221
 
222
exc_c:
222
exc_c:
223
        mov   ax, os_data
223
        mov   ax, os_data
224
        mov   ds, ax
224
        mov   ds, ax
225
        mov   es, ax
225
        mov   es, ax
226
 
226
 
227
; test if debugging
227
; test if debugging
228
        cli
228
        cli
229
        mov   eax, [0x3000]
229
        mov   eax, [0x3000]
230
        shl   eax, 8
230
        shl   eax, 8
231
        mov   eax, [0x80000+eax+APPDATA.debugger_slot]
231
        mov   eax, [0x80000+eax+APPDATA.debugger_slot]
232
        test  eax, eax
232
        test  eax, eax
233
        jnz   .debug
233
        jnz   .debug
234
        sti
234
        sti
235
; not debuggee => say error and terminate
235
; not debuggee => say error and terminate
236
        add   esp, 28h
236
        add   esp, 28h
237
        movzx eax, bl        
237
        movzx eax, bl        
238
        mov   [error_interrupt], eax
238
        mov   [error_interrupt], eax
239
        call  show_error_parameters
239
        call  show_error_parameters
240
        
240
        
241
        mov   edx, [0x3010]
241
        mov   edx, [0x3010]
242
        mov   [edx + TASKDATA.state], byte 4
242
        mov   [edx + TASKDATA.state], byte 4
243
        
243
        
244
        jmp   change_task
244
        jmp   change_task
245
 
245
 
246
.debug:
246
.debug:
247
; we are debugged process, notify debugger and suspend ourself
247
; we are debugged process, notify debugger and suspend ourself
248
; eax=debugger PID
248
; eax=debugger PID
249
        cld
249
        cld
250
        movzx ecx, bl
250
        movzx ecx, bl
251
        push  ecx
251
        push  ecx
252
        mov   ecx, [0x3010]
252
        mov   ecx, [0x3010]
253
        push  dword [ecx+TASKDATA.pid]    ; PID of current process
253
        push  dword [ecx+TASKDATA.pid]    ; PID of current process
254
        push  12
254
        push  12
255
        pop   ecx
255
        pop   ecx
256
        push  1        ; 1=exception
256
        push  1        ; 1=exception
257
        call  debugger_notify
257
        call  debugger_notify
258
        pop   ecx
258
        pop   ecx
259
        pop   ecx
259
        pop   ecx
260
        pop   ecx
260
        pop   ecx
261
        mov   edx, [0x3010]
261
        mov   edx, [0x3010]
262
        mov   byte [edx+TASKDATA.state], 1        ; suspended
262
        mov   byte [edx+TASKDATA.state], 1        ; suspended
263
        call  change_task
263
        call  change_task
264
        restore_ring3_context
264
        restore_ring3_context
265
        iretd
265
        iretd
266
 
266
 
267
;;;;;;;;;;;;;;;;;;;;;;;
267
;;;;;;;;;;;;;;;;;;;;;;;
268
;; FPU ERROR HANDLER ;;
268
;; FPU ERROR HANDLER ;;
269
;;;;;;;;;;;;;;;;;;;;;;;
269
;;;;;;;;;;;;;;;;;;;;;;;
270
 
270
 
271
align 4
271
align 4
272
e7:
272
e7:
273
        save_ring3_context
273
        save_ring3_context
274
        clts
274
        clts
275
        mov   ax, os_data
275
        mov   ax, os_data
276
        mov   ds, ax
276
        mov   ds, ax
277
        mov   es, ax
277
        mov   es, ax
278
        
278
        
279
        mov   eax, [prev_user_of_fpu]
279
        mov   eax, [prev_user_of_fpu]
280
        shl   eax, 8
280
        shl   eax, 8
281
        add   eax, 0x80000 + APPDATA.fpu_save_area
281
        add   eax, 0x80000 + APPDATA.fpu_save_area
282
        fsave [eax]
282
        fsave [eax]
283
        
283
        
284
        mov   eax, [0x3000]
284
        mov   eax, [0x3000]
285
        mov   [prev_user_of_fpu], eax
285
        mov   [prev_user_of_fpu], eax
286
        shl   eax, 8
286
        shl   eax, 8
287
        add   eax, 0x80000
287
        add   eax, 0x80000
288
        cmp   [eax + APPDATA.is_fpu_saved], 0
288
        cmp   [eax + APPDATA.is_fpu_saved], 0
289
        je    @f
289
        je    @f
290
        frstor [eax+APPDATA.fpu_save_area]
290
        frstor [eax+APPDATA.fpu_save_area]
291
     @@:
291
     @@:
292
        mov   [eax + APPDATA.is_fpu_saved], 1
292
        mov   [eax + APPDATA.is_fpu_saved], 1
293
        restore_ring3_context
293
        restore_ring3_context
294
        iret
294
        iret
295
        
295
        
296
iglobal
296
iglobal
297
  prev_user_of_fpu dd 1
297
  prev_user_of_fpu dd 1
298
endg
298
endg
299
 
299
 
300
 
300
 
301
writehex:
301
writehex:
302
      pusha
302
      pusha
303
      
303
      
304
      mov  edi, [write_error_to]
304
      mov  edi, [write_error_to]
305
      mov  esi, 8
305
      mov  esi, 8
306
    @@:
306
    @@:
307
      mov  ecx, eax
307
      mov  ecx, eax
308
      and  ecx, 0xf
308
      and  ecx, 0xf
309
 
309
 
310
      mov  cl,[ecx+hexletters]
310
      mov  cl,[ecx+hexletters]
311
      mov  [edi],cl
311
      mov  [edi],cl
312
      dec  edi
312
      dec  edi
313
 
313
 
314
      shr  eax,4
314
      shr  eax,4
315
      dec  esi
315
      dec  esi
316
      jnz  @b
316
      jnz  @b
317
 
317
 
318
      popa
318
      popa
319
      ret
319
      ret
320
 
320
 
321
iglobal
321
iglobal
322
  hexletters  db '0123456789ABCDEF'
322
  hexletters  db '0123456789ABCDEF'
323
 
323
 
324
  error_interrupt         dd  -1
324
  error_interrupt         dd  -1
325
 
325
 
326
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
326
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
327
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
327
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
328
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
328
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
329
  system_error   db 'K : Kernel error',13,10,0
329
  system_error   db 'K : Kernel error',13,10,0
330
endg
330
endg
331
 
331
 
332
uglobal
332
uglobal
333
  write_error_to  dd  0x0
333
  write_error_to  dd  0x0
334
endg
334
endg
335
 
335
 
336
show_error_parameters:
336
show_error_parameters:
337
        
337
        
338
        mov    [write_error_to],process_pid+43
338
        mov    [write_error_to],process_pid+43
339
        mov    eax,[0x3000]
339
        mov    eax,[0x3000]
340
        shl    eax, 5
340
        shl    eax, 5
341
        mov    eax,[0x3000+TASKDATA.pid+eax]
341
        mov    eax,[0x3000+TASKDATA.pid+eax]
342
        call   writehex
342
        call   writehex
343
        
343
        
344
        mov    [write_error_to],process_error+43
344
        mov    [write_error_to],process_error+43
345
        mov    eax,[error_interrupt]
345
        mov    eax,[error_interrupt]
346
        call   writehex
346
        call   writehex
347
 
347
 
348
        cmp    dword [esp+4+4], os_code ; CS
348
        cmp    dword [esp+4+4], os_code ; CS
349
        jnz    @f
349
        jnz    @f
350
        mov    esi,system_error
350
        mov    esi,system_error
351
        call   sys_msg_board_str
351
        call   sys_msg_board_str
352
      @@:
352
      @@:
353
        mov    eax, [esp+4] ; EIP
353
        mov    eax, [esp+4] ; EIP
354
 
354
 
355
        mov    [write_error_to],process_eip+43
355
        mov    [write_error_to],process_eip+43
356
        call   writehex
356
        call   writehex
357
 
357
 
358
        mov    esi,process_error
358
        mov    esi,process_error
359
        call   sys_msg_board_str
359
        call   sys_msg_board_str
360
 
360
 
361
        mov    esi,process_pid
361
        mov    esi,process_pid
362
        call   sys_msg_board_str
362
        call   sys_msg_board_str
363
 
363
 
364
        mov    esi,process_eip
364
        mov    esi,process_eip
365
        call   sys_msg_board_str
365
        call   sys_msg_board_str
366
 
366
 
367
        ret
367
        ret
368
 
368
 
369
 
369
 
370
 
370
 
371
; irq1  ->  hid/keyboard.inc
371
; irq1  ->  hid/keyboard.inc
372
 
372
 
373
 
373
 
374
macro irqh [num]
374
macro irqh [num]
375
{
375
{
376
  forward
376
  forward
377
  p_irq#num :
377
  p_irq#num :
378
     save_ring3_context
378
     save_ring3_context
379
     mov   edi, num
379
     mov   edi, num
380
     jmp   irq_c
380
     jmp   irq_c
381
}
381
}
382
 
382
 
383
irqh 2,5,7,8,9,10,11,14,15
383
irqh 2,5,7,8,9,10,11,14,15
384
 
384
 
385
 irq_c:
385
 irq_c:
386
     mov   ax, os_data
386
     mov   ax, os_data
387
     mov   ds, ax
387
     mov   ds, ax
388
     mov   es, ax
388
     mov   es, ax
389
     call  irqhandler
389
     call  irqhandler
390
     restore_ring3_context
390
     restore_ring3_context
391
     iret
391
     iret
392
 
392
 
393
p_irq6:
393
p_irq6:
394
     save_ring3_context
394
     save_ring3_context
395
     mov   ax, os_data
395
     mov   ax, os_data
396
     mov   ds, ax
396
     mov   ds, ax
397
     mov   es, ax
397
     mov   es, ax
398
     call  fdc_irq
398
     call  fdc_irq
399
     call  ready_for_next_irq
399
     call  ready_for_next_irq
400
     restore_ring3_context
400
     restore_ring3_context
401
     iret
401
     iret
402
 
402
 
403
p_irq3:
403
p_irq3:
404
     save_ring3_context
404
     save_ring3_context
405
     mov   ax, os_data
405
     mov   ax, os_data
406
     mov   ds, ax
406
     mov   ds, ax
407
     mov   es, ax
407
     mov   es, ax
408
     cmp   [com2_mouse_detected],0
408
     cmp   [com2_mouse_detected],0
409
     je    old_irq3_handler
409
     je    old_irq3_handler
410
     call  check_mouse_data_com2
410
     call  check_mouse_data_com2
411
     jmp   p_irq3_1
411
     jmp   p_irq3_1
412
 old_irq3_handler:
412
 old_irq3_handler:
413
     mov   edi,3
413
     mov   edi,3
414
     call  irqhandler
414
     call  irqhandler
415
  p_irq3_1: 
415
  p_irq3_1: 
416
     restore_ring3_context
416
     restore_ring3_context
417
     iret
417
     iret
418
 
418
 
419
p_irq4:
419
p_irq4:
420
     save_ring3_context
420
     save_ring3_context
421
     mov   ax, os_data
421
     mov   ax, os_data
422
     mov   ds, ax
422
     mov   ds, ax
423
     mov   es, ax
423
     mov   es, ax
424
     cmp   [com1_mouse_detected],0
424
     cmp   [com1_mouse_detected],0
425
     je    old_irq4_handler
425
     je    old_irq4_handler
426
     call  check_mouse_data_com1
426
     call  check_mouse_data_com1
427
     jmp   p_irq4_1
427
     jmp   p_irq4_1
428
 old_irq4_handler:
428
 old_irq4_handler:
429
     mov   edi,4
429
     mov   edi,4
430
     call  irqhandler
430
     call  irqhandler
431
  p_irq4_1:   
431
  p_irq4_1:   
432
     restore_ring3_context
432
     restore_ring3_context
433
     iret
433
     iret
434
 
434
 
435
p_irq12:
435
p_irq12:
436
     save_ring3_context
436
     save_ring3_context
437
     mov   ax, os_data
437
     mov   ax, os_data
438
     mov   ds, ax
438
     mov   ds, ax
439
     mov   es, ax
439
     mov   es, ax
440
     call  check_mouse_data_ps2
440
     call  check_mouse_data_ps2
441
     restore_ring3_context
441
     restore_ring3_context
442
     iret
442
     iret
443
 
443
 
444
ready_for_next_irq:
444
ready_for_next_irq:
445
     mov    [check_idle_semaphore],5
445
     mov    [check_idle_semaphore],5
446
     mov   al, 0x20
446
     mov   al, 0x20
447
     out   0x20, al
447
     out   0x20, al
448
     ret
448
     ret
449
 
449
 
450
ready_for_next_irq_1:
450
ready_for_next_irq_1:
451
     mov    [check_idle_semaphore],5
451
     mov    [check_idle_semaphore],5
452
     mov   al, 0x20
452
     mov   al, 0x20
453
     out    0xa0,al
453
     out    0xa0,al
454
     out   0x20, al
454
     out   0x20, al
455
     ret
455
     ret
456
 
456
 
457
irqD:
457
irqD:
458
     save_ring3_context
458
     save_ring3_context
459
     mov   ax, os_data
459
     mov   ax, os_data
460
     mov   ds, ax
460
     mov   ds, ax
461
     mov   es, ax
461
     mov   es, ax
462
     
462
     
463
     mov   dx,0xf0
463
     mov   dx,0xf0
464
     mov   al,0
464
     mov   al,0
465
     out   dx,al
465
     out   dx,al
466
 
466
 
467
     mov   dx,0xa0
467
     mov   dx,0xa0
468
     mov   al,0x20
468
     mov   al,0x20
469
     out   dx,al
469
     out   dx,al
470
     mov   dx,0x20
470
     mov   dx,0x20
471
     out   dx,al
471
     out   dx,al
472
 
472
 
473
     restore_ring3_context
473
     restore_ring3_context
474
     
474
     
475
     iret
475
     iret
476
 
476
 
477
 
477
 
478
irqhandler:
478
irqhandler:
479
 
479
 
480
     push   edi
480
     push   edi
481
 
481
 
482
     mov    esi,edi          ; 1
482
     mov    esi,edi          ; 1
483
     shl    esi,6            ; 1
483
     shl    esi,6            ; 1
484
     add    esi,irq00read    ; 1
484
     add    esi,irq00read    ; 1
485
     shl    edi,12           ; 1
485
     shl    edi,12           ; 1
486
     add    edi,0x2E0000
486
     add    edi,0x2E0000
487
     mov    ecx,16
487
     mov    ecx,16
488
 
488
 
489
     mov    [check_idle_semaphore],5
489
     mov    [check_idle_semaphore],5
490
 
490
 
491
   irqnewread:
491
   irqnewread:
492
     dec    ecx
492
     dec    ecx
493
     js     irqover
493
     js     irqover
494
 
494
 
495
     mov    dx,[esi]         ; 2+
495
     mov    dx,[esi]         ; 2+
496
 
496
 
497
     cmp    dx,0             ; 1
497
     cmp    dx,0             ; 1
498
     jz     irqover
498
     jz     irqover
499
     cmp    [esi+3],byte 1   ; 2     ; byte read
499
     cmp    [esi+3],byte 1   ; 2     ; byte read
500
     jne    noirqbyte        ; 4-11
500
     jne    noirqbyte        ; 4-11
501
 
501
 
502
     in     al,dx
502
     in     al,dx
503
 
503
 
504
     mov    edx,[edi]
504
     mov    edx,[edi]
505
     cmp    edx,4000
505
     cmp    edx,4000
506
     je     irqfull
506
     je     irqfull
507
     mov    ebx,edi
507
     mov    ebx,edi
508
     add    ebx,0x10
508
     add    ebx,0x10
509
     add    ebx,edx
509
     add    ebx,edx
510
     mov    [ebx],al
510
     mov    [ebx],al
511
     inc    edx
511
     inc    edx
512
     mov    [edi],edx
512
     mov    [edi],edx
513
 
513
 
514
     add    esi,4
514
     add    esi,4
515
     jmp    irqnewread
515
     jmp    irqnewread
516
 
516
 
517
   noirqbyte:
517
   noirqbyte:
518
 
518
 
519
 
519
 
520
     cmp    [esi+3],byte 2     ; word read
520
     cmp    [esi+3],byte 2     ; word read
521
     jne    noirqword
521
     jne    noirqword
522
 
522
 
523
     in     ax,dx
523
     in     ax,dx
524
 
524
 
525
     mov    edx,[edi]
525
     mov    edx,[edi]
526
     cmp    edx,4000
526
     cmp    edx,4000
527
     je     irqfull
527
     je     irqfull
528
     mov    ebx,edi
528
     mov    ebx,edi
529
     add    ebx,0x10
529
     add    ebx,0x10
530
     add    ebx,edx
530
     add    ebx,edx
531
     mov    [ebx],ax
531
     mov    [ebx],ax
532
     add    edx,2
532
     add    edx,2
533
     mov    [edi],edx
533
     mov    [edi],edx
534
     add    esi,4
534
     add    esi,4
535
     jmp    irqnewread
535
     jmp    irqnewread
536
 
536
 
537
   noirqword:
537
   noirqword:
538
   irqfull:
538
   irqfull:
539
   irqover:
539
   irqover:
540
 
540
 
541
     mov    al,0x20            ; ready for next irq
541
     mov    al,0x20            ; ready for next irq
542
     out    0x20,al
542
     out    0x20,al
543
 
543
 
544
     pop    ebx
544
     pop    ebx
545
     cmp    ebx,7
545
     cmp    ebx,7
546
     jbe    noa0
546
     jbe    noa0
547
     out    0xa0,al
547
     out    0xa0,al
548
   noa0:
548
   noa0:
549
 
549
 
550
     ret
550
     ret
551
 
551
 
552
 
552
 
553
 
553
 
554
set_application_table_status:
554
set_application_table_status:
555
        push eax
555
        push eax
556
 
556
 
557
        mov  eax,[0x3000]
557
        mov  eax,[0x3000]
558
        shl  eax, 5
558
        shl  eax, 5
559
        add  eax,0x3000+TASKDATA.pid
559
        add  eax,0x3000+TASKDATA.pid
560
        mov  eax,[eax]
560
        mov  eax,[eax]
561
 
561
 
562
        mov  [application_table_status],eax
562
        mov  [application_table_status],eax
563
 
563
 
564
        pop  eax
564
        pop  eax
565
 
565
 
566
        ret
566
        ret
567
 
567
 
568
 
568
 
569
clear_application_table_status:
569
clear_application_table_status:
570
        push eax
570
        push eax
571
 
571
 
572
        mov  eax,[0x3000]
572
        mov  eax,[0x3000]
573
        shl  eax, 5
573
        shl  eax, 5
574
        add  eax,0x3000+TASKDATA.pid
574
        add  eax,0x3000+TASKDATA.pid
575
        mov  eax,[eax]
575
        mov  eax,[eax]
576
 
576
 
577
        cmp  eax,[application_table_status]
577
        cmp  eax,[application_table_status]
578
        jne  apptsl1
578
        jne  apptsl1
579
        mov  [application_table_status],0
579
        mov  [application_table_status],0
580
      apptsl1:
580
      apptsl1:
581
 
581
 
582
        pop  eax
582
        pop  eax
583
 
583
 
584
        ret
584
        ret
585
 
585
 
586
 
586
 
587
 
587
 
588
sys_resize_app_memory:
588
sys_resize_app_memory:
589
        ; eax = 1 - resize
589
        ; eax = 1 - resize
590
        ;     ebx = new amount of memory
590
        ;     ebx = new amount of memory
591
 
591
 
592
        cmp    eax,1
592
        cmp    eax,1
593
        jne    .no_application_mem_resize
593
        jne    .no_application_mem_resize
594
        
594
        
595
        jmp    new_mem_resize ;resize for new type of processes
595
        jmp    new_mem_resize ;resize for new type of processes
596
 
596
 
597
 
597
 
598
     .no_application_mem_resize:
598
     .no_application_mem_resize:
599
 
599
 
600
        ret
600
        ret
601
 
601
 
602
 
602
 
603
 
603
 
604
get_app_params:
604
get_app_params:
605
 
605
 
606
    push eax
606
    push eax
607
 
607
 
608
    cmp  [0x90000+6],word '00'
608
    cmp  [0x90000+6],word '00'
609
    jne  no_00_header
609
    jne  no_00_header
610
 
610
 
611
    mov  eax,[0x90000+12]
611
    mov  eax,[0x90000+12]
612
    mov  [app_start],eax
612
    mov  [app_start],eax
613
    mov  eax,[0x90000+16]
613
    mov  eax,[0x90000+16]
614
    mov  [app_i_end],eax
614
    mov  [app_i_end],eax
615
    mov  eax,[0x90000+20]
615
    mov  eax,[0x90000+20]
616
    mov  [app_mem],eax
616
    mov  [app_mem],eax
617
; \begin{diamond}[20.08.2006]
617
; \begin{diamond}[20.08.2006]
618
; sanity check (functions 19,58 load app_i_end bytes and that must
618
; sanity check (functions 19,58 load app_i_end bytes and that must
619
; fit in allocated memory to prevent kernel faults)
619
; fit in allocated memory to prevent kernel faults)
620
    cmp  eax,[app_i_end]
620
    cmp  eax,[app_i_end]
621
    jb   no_01_header
621
    jb   no_01_header
622
; \end{diamond}[20.08.2006]
622
; \end{diamond}[20.08.2006]
623
    shr  eax,1
623
    shr  eax,1
624
    sub  eax,0x10
624
    sub  eax,0x10
625
    mov  [app_esp],eax
625
    mov  [app_esp],eax
626
    mov  eax,[0x90000+24]
626
    mov  eax,[0x90000+24]
627
    mov  [app_i_param],eax
627
    mov  [app_i_param],eax
628
    mov  [app_i_icon],dword 0
628
    mov  [app_i_icon],dword 0
629
 
629
 
630
    pop  eax
630
    pop  eax
631
    clc
631
    clc
632
    ret
632
    ret
633
 
633
 
634
  no_00_header:
634
  no_00_header:
635
 
635
 
636
 
636
 
637
    cmp  [0x90000+6],word '01'
637
    cmp  [0x90000+6],word '01'
638
    jne  no_01_header
638
    jne  no_01_header
639
 
639
 
640
    mov  eax,[0x90000+12]
640
    mov  eax,[0x90000+12]
641
    mov  [app_start],eax
641
    mov  [app_start],eax
642
    mov  eax,[0x90000+16]
642
    mov  eax,[0x90000+16]
643
    mov  [app_i_end],eax
643
    mov  [app_i_end],eax
644
    mov  eax,[0x90000+20]
644
    mov  eax,[0x90000+20]
645
    mov  [app_mem],eax
645
    mov  [app_mem],eax
646
; \begin{diamond}[20.08.2006]
646
; \begin{diamond}[20.08.2006]
647
    cmp  eax,[app_i_end]
647
    cmp  eax,[app_i_end]
648
    jb   no_01_header
648
    jb   no_01_header
649
; \end{diamond}[20.08.2006]
649
; \end{diamond}[20.08.2006]
650
    mov  eax,[0x90000+24]
650
    mov  eax,[0x90000+24]
651
    mov  [app_esp],eax
651
    mov  [app_esp],eax
652
    mov  eax,[0x90000+28]
652
    mov  eax,[0x90000+28]
653
    mov  [app_i_param],eax
653
    mov  [app_i_param],eax
654
    mov  eax,[0x90000+32]
654
    mov  eax,[0x90000+32]
655
    mov  [app_i_icon],eax
655
    mov  [app_i_icon],eax
656
 
656
 
657
    pop  eax
657
    pop  eax
658
    clc
658
    clc
659
    ret
659
    ret
660
 
660
 
661
   no_01_header:
661
   no_01_header:
662
 
662
 
663
    pop  eax
663
    pop  eax
664
    stc
664
    stc
665
    ret
665
    ret
666
 
666
 
667
 
667
 
668
uglobal
668
uglobal
669
  new_process_place  dd  0x0
669
  new_process_place  dd  0x0
670
  app_start    dd  0x0
670
  app_start    dd  0x0
671
  app_i_end    dd  0x0
671
  app_i_end    dd  0x0
672
  app_mem      dd  0x0
672
  app_mem      dd  0x0
673
  app_esp      dd  0x0
673
  app_esp      dd  0x0
674
  app_i_param  dd  0x0
674
  app_i_param  dd  0x0
675
  app_i_icon   dd  0x0
675
  app_i_icon   dd  0x0
676
  ;app_mem_pos  dd  0x0
676
  ;app_mem_pos  dd  0x0
677
  appl_path        dd 0x0
677
  appl_path        dd 0x0
678
  appl_path_size   dd 0x0         
678
  appl_path_size   dd 0x0         
679
endg
679
endg
680
 
680
 
681
 
681
 
682
sys_threads:
682
sys_threads:
683
 
683
 
684
; eax=1 create thread
684
; eax=1 create thread
685
;
685
;
686
;   ebx=thread start
686
;   ebx=thread start
687
;   ecx=thread stack value
687
;   ecx=thread stack value
688
;
688
;
689
; on return : eax = pid
689
; on return : eax = pid
690
jmp new_sys_threads
690
jmp new_sys_threads
691
 
691
 
692
iglobal
692
iglobal
693
  process_terminating   db 'K : Process - terminating',13,10,0
693
  process_terminating   db 'K : Process - terminating',13,10,0
694
  process_terminated    db 'K : Process - done',13,10,0
694
  process_terminated    db 'K : Process - done',13,10,0
695
endg
695
endg
696
 
696
 
697
 
697
 
698
terminate: ; terminate application
698
terminate: ; terminate application
699
    push   esi
699
    push   esi
700
    mov    esi,process_terminating
700
    mov    esi,process_terminating
701
    call   sys_msg_board_str
701
    call   sys_msg_board_str
702
    pop    esi
702
    pop    esi
703
 
703
 
704
@@:
704
@@:
705
    cli
705
    cli
706
    cmp   [application_table_status],0
706
    cmp   [application_table_status],0
707
    je    term9
707
    je    term9
708
    sti
708
    sti
709
    call  change_task
709
    call  change_task
710
    jmp   @b
710
    jmp   @b
711
  term9:
711
  term9:
712
 
712
 
713
    call  set_application_table_status
713
    call  set_application_table_status
714
    
714
    
715
    mov    eax,esi
715
    mov    eax,esi
716
    call   dispose_app_cr3_table
716
    call   dispose_app_cr3_table
717
 
717
 
718
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
718
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
719
    jne   fpu_ok_1
719
    jne   fpu_ok_1
720
    mov   [prev_user_of_fpu],1
720
    mov   [prev_user_of_fpu],1
721
  fpu_ok_1:
721
  fpu_ok_1:
722
 
722
 
723
    mov   [0xf400],byte 0           ; empty keyboard buffer
723
    mov   [0xf400],byte 0           ; empty keyboard buffer
724
    mov   [0xf500],byte 0           ; empty button buffer
724
    mov   [0xf500],byte 0           ; empty button buffer
725
 
725
 
726
 
726
 
727
; remove defined hotkeys
727
; remove defined hotkeys
728
        mov     eax, hotkey_list
728
        mov     eax, hotkey_list
729
.loop:
729
.loop:
730
        cmp     [eax+8], esi
730
        cmp     [eax+8], esi
731
        jnz     .cont
731
        jnz     .cont
732
        mov     ecx, [eax]
732
        mov     ecx, [eax]
733
        jecxz   @f
733
        jecxz   @f
734
        push    dword [eax+12]
734
        push    dword [eax+12]
735
        pop     dword [ecx+12]
735
        pop     dword [ecx+12]
736
@@:
736
@@:
737
        mov     ecx, [eax+12]
737
        mov     ecx, [eax+12]
738
        push    dword [eax]
738
        push    dword [eax]
739
        pop     dword [ecx]
739
        pop     dword [ecx]
740
        xor     ecx, ecx
740
        xor     ecx, ecx
741
        mov     [eax], ecx
741
        mov     [eax], ecx
742
        mov     [eax+4], ecx
742
        mov     [eax+4], ecx
743
        mov     [eax+8], ecx
743
        mov     [eax+8], ecx
744
        mov     [eax+12], ecx
744
        mov     [eax+12], ecx
745
.cont:
745
.cont:
746
        add     eax, 16
746
        add     eax, 16
747
        cmp     eax, hotkey_list+256*16
747
        cmp     eax, hotkey_list+256*16
748
        jb      .loop
748
        jb      .loop
749
; remove hotkeys in buffer
749
; remove hotkeys in buffer
750
        mov     eax, hotkey_buffer
750
        mov     eax, hotkey_buffer
751
.loop2:
751
.loop2:
752
        cmp     [eax], esi
752
        cmp     [eax], esi
753
        jnz     .cont2
753
        jnz     .cont2
754
        and     dword [eax+4], 0
754
        and     dword [eax+4], 0
755
        and     dword [eax], 0
755
        and     dword [eax], 0
756
.cont2:
756
.cont2:
757
        add     eax, 8
757
        add     eax, 8
758
        cmp     eax, hotkey_buffer+120*8
758
        cmp     eax, hotkey_buffer+120*8
759
        jb      .loop2
759
        jb      .loop2
760
 
760
 
761
    mov   ecx,esi                 ; remove buttons
761
    mov   ecx,esi                 ; remove buttons
762
  bnewba2:
762
  bnewba2:
763
    mov   edi,[0xfe88]
763
    mov   edi,[0xfe88]
764
    mov   eax,edi
764
    mov   eax,edi
765
    cld
765
    cld
766
    movzx ebx,word [edi]
766
    movzx ebx,word [edi]
767
    inc   bx
767
    inc   bx
768
  bnewba:
768
  bnewba:
769
    dec   bx
769
    dec   bx
770
    jz    bnmba
770
    jz    bnmba
771
    add   eax,0x10
771
    add   eax,0x10
772
    cmp   cx,[eax]
772
    cmp   cx,[eax]
773
    jnz   bnewba
773
    jnz   bnewba
774
    pusha
774
    pusha
775
    mov   ecx,ebx
775
    mov   ecx,ebx
776
    inc   ecx
776
    inc   ecx
777
    shl   ecx,4
777
    shl   ecx,4
778
    mov   ebx,eax
778
    mov   ebx,eax
779
    add   eax,0x10
779
    add   eax,0x10
780
    call  memmove
780
    call  memmove
781
    dec   dword [edi]
781
    dec   dword [edi]
782
    popa
782
    popa
783
    jmp   bnewba2
783
    jmp   bnewba2
784
  bnmba:
784
  bnmba:
785
 
785
 
786
    pusha     ; save window coordinates for window restoring
786
    pusha     ; save window coordinates for window restoring
787
    cld
787
    cld
788
    shl   esi,5
788
    shl   esi,5
789
    add   esi,window_data
789
    add   esi,window_data
790
    mov   eax,[esi+WDATA.box.left]
790
    mov   eax,[esi+WDATA.box.left]
791
    mov   [dlx],eax
791
    mov   [dlx],eax
792
    add   eax,[esi+WDATA.box.width]
792
    add   eax,[esi+WDATA.box.width]
793
    mov   [dlxe],eax
793
    mov   [dlxe],eax
794
    mov   eax,[esi+WDATA.box.top]
794
    mov   eax,[esi+WDATA.box.top]
795
    mov   [dly],eax
795
    mov   [dly],eax
796
    add   eax,[esi+WDATA.box.height]
796
    add   eax,[esi+WDATA.box.height]
797
    mov   [dlye],eax
797
    mov   [dlye],eax
798
 
798
 
799
    xor   eax, eax
799
    xor   eax, eax
800
    mov   [esi+WDATA.box.left],eax
800
    mov   [esi+WDATA.box.left],eax
801
    mov   [esi+WDATA.box.width],eax
801
    mov   [esi+WDATA.box.width],eax
802
    mov   [esi+WDATA.box.top],eax
802
    mov   [esi+WDATA.box.top],eax
803
    mov   [esi+WDATA.box.height],eax
803
    mov   [esi+WDATA.box.height],eax
804
    mov   [esi+WDATA.cl_workarea],eax
804
    mov   [esi+WDATA.cl_workarea],eax
805
    mov   [esi+WDATA.cl_titlebar],eax
805
    mov   [esi+WDATA.cl_titlebar],eax
806
    mov   [esi+WDATA.cl_frames],eax
806
    mov   [esi+WDATA.cl_frames],eax
807
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
807
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
808
    lea   edi, [esi-window_data+draw_data]
808
    lea   edi, [esi-window_data+draw_data]
809
    mov   ecx,32/4
809
    mov   ecx,32/4
810
    rep   stosd
810
    rep   stosd
811
    popa
811
    popa
812
 
812
 
813
; debuggee test
813
; debuggee test
814
    pushad
814
    pushad
815
    mov  edi, esi
815
    mov  edi, esi
816
    shl  edi, 5
816
    shl  edi, 5
817
    mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
817
    mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
818
    test eax, eax
818
    test eax, eax
819
    jz   .nodebug
819
    jz   .nodebug
820
    push 8
820
    push 8
821
    pop  ecx
821
    pop  ecx
822
    push dword [0x3000+edi+TASKDATA.pid]   ; PID
822
    push dword [0x3000+edi+TASKDATA.pid]   ; PID
823
    push 2
823
    push 2
824
    call debugger_notify
824
    call debugger_notify
825
    pop  ecx
825
    pop  ecx
826
    pop  ecx
826
    pop  ecx
827
.nodebug:
827
.nodebug:
828
    popad
828
    popad
829
 
829
 
830
    pusha         ; at 0x80000+
830
    pusha         ; at 0x80000+
831
    mov   edi,esi
831
    mov   edi,esi
832
    shl   edi,8
832
    shl   edi,8
833
    add   edi,0x80000
833
    add   edi,0x80000
834
    mov   ecx,256/4
834
    mov   ecx,256/4
835
    xor   eax, eax
835
    xor   eax, eax
836
    rep   stosd
836
    rep   stosd
837
    popa
837
    popa
838
 
838
 
839
    pusha          ; name to spaces
839
    pusha          ; name to spaces
840
    mov   edi,esi
840
    mov   edi,esi
841
    shl   edi,8
841
    shl   edi,8
842
    add   edi,0x80000+APPDATA.app_name
842
    add   edi,0x80000+APPDATA.app_name
843
    mov   ecx,11
843
    mov   ecx,11
844
    mov   eax,' '
844
    mov   eax,' '
845
    rep   stosb
845
    rep   stosb
846
    popa
846
    popa
847
 
847
 
848
 
848
 
849
  ; activate window
849
  ; activate window
850
        movzx  eax, word [0xC000 + esi*2]
850
        movzx  eax, word [0xC000 + esi*2]
851
        cmp    eax, [0x3004]
851
        cmp    eax, [0x3004]
852
        jne    .dont_activate
852
        jne    .dont_activate
853
        pushad
853
        pushad
854
 .check_next_window:
854
 .check_next_window:
855
        dec    eax
855
        dec    eax
856
        cmp    eax, 1
856
        cmp    eax, 1
857
        jbe    .nothing_to_activate
857
        jbe    .nothing_to_activate
858
        lea    esi, [0xc400+eax*2]
858
        lea    esi, [0xc400+eax*2]
859
        movzx  edi, word [esi]               ; edi = process
859
        movzx  edi, word [esi]               ; edi = process
860
        shl    edi, 5
860
        shl    edi, 5
861
        cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
861
        cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
862
        je     .check_next_window
862
        je     .check_next_window
863
        add    edi, window_data
863
        add    edi, window_data
-
 
864
; \begin{diamond}[19.09.2006]
-
 
865
; skip minimized windows
-
 
866
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
-
 
867
        jnz    .check_next_window
-
 
868
; \end{diamond}
864
        call   waredraw
869
        call   waredraw
865
 .nothing_to_activate:
870
 .nothing_to_activate:
866
        popad
871
        popad
867
 .dont_activate:
872
 .dont_activate:
868
 
873
 
869
        push    esi     ; remove hd1 & cd & flp reservation
874
        push    esi     ; remove hd1 & cd & flp reservation
870
        shl     esi, 5
875
        shl     esi, 5
871
        mov     esi, [esi+0x3000+TASKDATA.pid]
876
        mov     esi, [esi+0x3000+TASKDATA.pid]
872
        cmp     [hd1_status], esi
877
        cmp     [hd1_status], esi
873
        jnz     @f
878
        jnz     @f
874
        mov     [hd1_status], 0
879
        mov     [hd1_status], 0
875
@@:
880
@@:
876
        cmp     [cd_status], esi
881
        cmp     [cd_status], esi
877
        jnz     @f
882
        jnz     @f
878
        mov     [cd_status], 0
883
        mov     [cd_status], 0
879
@@:
884
@@:
880
        cmp     [flp_status], esi
885
        cmp     [flp_status], esi
881
        jnz     @f
886
        jnz     @f
882
        mov     [flp_status], 0
887
        mov     [flp_status], 0
883
@@:
888
@@:
884
        pop     esi
889
        pop     esi
885
 
890
 
886
    pusha ; remove all irq reservations
891
    pusha ; remove all irq reservations
887
    mov   eax,esi
892
    mov   eax,esi
888
    shl   eax, 5
893
    shl   eax, 5
889
    mov   eax,[eax+0x3000+TASKDATA.pid]
894
    mov   eax,[eax+0x3000+TASKDATA.pid]
890
    mov   edi,irq_owner
895
    mov   edi,irq_owner
891
    mov   ecx,16
896
    mov   ecx,16
892
  newirqfree:
897
  newirqfree:
893
    scasd
898
    scasd
894
    jne   nofreeirq
899
    jne   nofreeirq
895
    mov   [edi-4],dword 0
900
    mov   [edi-4],dword 0
896
  nofreeirq:
901
  nofreeirq:
897
    loop   newirqfree
902
    loop   newirqfree
898
    popa
903
    popa
899
 
904
 
900
 
905
 
901
    pusha                     ; remove all port reservations
906
    pusha                     ; remove all port reservations
902
    mov   edx,esi
907
    mov   edx,esi
903
    shl   edx, 5
908
    shl   edx, 5
904
    add   edx,0x3000
909
    add   edx,0x3000
905
    mov   edx,[edx+TASKDATA.pid]
910
    mov   edx,[edx+TASKDATA.pid]
906
 
911
 
907
  rmpr0:
912
  rmpr0:
908
 
913
 
909
    mov   esi,[0x2d0000]
914
    mov   esi,[0x2d0000]
910
 
915
 
911
    cmp   esi,0
916
    cmp   esi,0
912
    je    rmpr9
917
    je    rmpr9
913
 
918
 
914
  rmpr3:
919
  rmpr3:
915
 
920
 
916
    mov   edi,esi
921
    mov   edi,esi
917
    shl   edi,4
922
    shl   edi,4
918
    add   edi,0x2d0000
923
    add   edi,0x2d0000
919
 
924
 
920
    cmp   edx,[edi]
925
    cmp   edx,[edi]
921
    je    rmpr4
926
    je    rmpr4
922
 
927
 
923
    dec   esi
928
    dec   esi
924
    jnz   rmpr3
929
    jnz   rmpr3
925
 
930
 
926
    jmp   rmpr9
931
    jmp   rmpr9
927
 
932
 
928
  rmpr4:
933
  rmpr4:
929
 
934
 
930
    mov   ecx,256
935
    mov   ecx,256
931
    sub   ecx,esi
936
    sub   ecx,esi
932
    shl   ecx,4
937
    shl   ecx,4
933
 
938
 
934
    mov   esi,edi
939
    mov   esi,edi
935
    add   esi,16
940
    add   esi,16
936
    cld
941
    cld
937
    rep   movsb
942
    rep   movsb
938
 
943
 
939
    dec   dword [0x2d0000]
944
    dec   dword [0x2d0000]
940
 
945
 
941
    jmp   rmpr0
946
    jmp   rmpr0
942
 
947
 
943
  rmpr9:
948
  rmpr9:
944
 
949
 
945
    popa
950
    popa
946
    mov  edi,esi         ; do not run this process slot
951
    mov  edi,esi         ; do not run this process slot
947
    shl  edi, 5
952
    shl  edi, 5
948
    mov  [edi+0x3000 + TASKDATA.state],byte 9
953
    mov  [edi+0x3000 + TASKDATA.state],byte 9
949
; debugger test - terminate all debuggees
954
; debugger test - terminate all debuggees
950
    mov  eax, 2
955
    mov  eax, 2
951
    mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
956
    mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
952
.xd0:
957
.xd0:
953
    cmp  eax, [0x3004]
958
    cmp  eax, [0x3004]
954
    ja   .xd1
959
    ja   .xd1
955
    cmp  dword [ecx], esi
960
    cmp  dword [ecx], esi
956
    jnz  @f
961
    jnz  @f
957
    and  dword [ecx], 0
962
    and  dword [ecx], 0
958
    pushad
963
    pushad
959
    xchg eax, ebx
964
    xchg eax, ebx
960
    mov  eax, 2
965
    mov  eax, 2
961
    call sys_system
966
    call sys_system
962
    popad
967
    popad
963
@@:
968
@@:
964
    inc  eax
969
    inc  eax
965
    add  ecx, 0x100
970
    add  ecx, 0x100
966
    jmp  .xd0
971
    jmp  .xd0
967
.xd1:
972
.xd1:
968
;    call  systest
973
;    call  systest
969
    sti  ; .. and life goes on
974
    sti  ; .. and life goes on
970
 
975
 
971
    mov   eax, [dlx]
976
    mov   eax, [dlx]
972
    mov   ebx, [dly]
977
    mov   ebx, [dly]
973
    mov   ecx, [dlxe]
978
    mov   ecx, [dlxe]
974
    mov   edx, [dlye]
979
    mov   edx, [dlye]
975
    call  calculatescreen
980
    call  calculatescreen
976
    xor   eax, eax
981
    xor   eax, eax
977
    xor   esi, esi
982
    xor   esi, esi
978
    call  redrawscreen
983
    call  redrawscreen
979
 
984
 
980
    mov   [0xfff4],byte 0  ; no mouse background
985
    mov   [0xfff4],byte 0  ; no mouse background
981
    mov   [0xfff5],byte 0  ; draw mouse
986
    mov   [0xfff5],byte 0  ; draw mouse
982
 
987
 
983
    mov   [application_table_status],0
988
    mov   [application_table_status],0
984
    mov   esi,process_terminated
989
    mov   esi,process_terminated
985
    call  sys_msg_board_str
990
    call  sys_msg_board_str
986
 
991
 
987
    ret
992
    ret
988
 
993
 
989
iglobal
994
iglobal
990
  boot_sched_1    db   'Building gdt tss pointer',0
995
  boot_sched_1    db   'Building gdt tss pointer',0
991
  boot_sched_2    db   'Building IDT table',0
996
  boot_sched_2    db   'Building IDT table',0
992
endg
997
endg
993
 
998
 
994
 
999
 
995
build_scheduler:
1000
build_scheduler:
996
 
1001
 
997
        mov    esi,boot_sched_1
1002
        mov    esi,boot_sched_1
998
        call   boot_log
1003
        call   boot_log
999
        call   build_process_gdt_tss_pointer
1004
        call   build_process_gdt_tss_pointer
1000
 
1005
 
1001
        mov    esi,boot_sched_2
1006
        mov    esi,boot_sched_2
1002
        call   boot_log
1007
        call   boot_log
1003
        call   build_interrupt_table
1008
        call   build_interrupt_table
1004
 
1009
 
1005
        ret
1010
        ret