Subversion Repositories Kolibri OS

Rev

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

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