Subversion Repositories Kolibri OS

Rev

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