Subversion Repositories Kolibri OS

Rev

Rev 154 | Rev 164 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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