Subversion Repositories Kolibri OS

Rev

Rev 170 | Rev 203 | 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
239
 
170 serge 240
.init:
241
        fninit                      ;нам не нужны немаскированные исключения
242
.ready:
243
        mov dword [ebx+PROC_BASE+APPDATA.fpu_init], 1
244
.exit:
245
        restore_ring3_context
246
        iret
247
 
6 poddubny 248
iglobal
164 serge 249
  fpu_owner dd 1
250
 endg
1 ha 251
 
252
 
253
writehex:
254
      pusha
164 serge 255
 
8 poddubny 256
      mov  edi, [write_error_to]
257
      mov  esi, 8
258
    @@:
259
      mov  ecx, eax
260
      and  ecx, 0xf
1 ha 261
 
8 poddubny 262
      mov  cl,[ecx+hexletters]
1 ha 263
      mov  [edi],cl
8 poddubny 264
      dec  edi
1 ha 265
 
8 poddubny 266
      shr  eax,4
1 ha 267
      dec  esi
8 poddubny 268
      jnz  @b
1 ha 269
 
270
      popa
271
      ret
272
 
273
iglobal
274
  hexletters  db '0123456789ABCDEF'
275
 
276
  error_interrupt         dd  -1
277
 
278
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
279
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
280
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
281
  system_error   db 'K : Kernel error',13,10,0
282
endg
283
 
284
uglobal
285
  write_error_to  dd  0x0
286
endg
287
 
288
show_error_parameters:
164 serge 289
 
1 ha 290
        mov    [write_error_to],process_pid+43
291
        mov    eax,[0x3000]
292
        shl    eax, 5
115 poddubny 293
        mov    eax,[0x3000+TASKDATA.pid+eax]
1 ha 294
        call   writehex
164 serge 295
 
1 ha 296
        mov    [write_error_to],process_error+43
297
        mov    eax,[error_interrupt]
298
        call   writehex
16 poddubny 299
 
300
        cmp    dword [esp+4+4], os_code ; CS
301
        jnz    @f
10 poddubny 302
        mov    esi,system_error
303
        call   sys_msg_board_str
304
      @@:
16 poddubny 305
        mov    eax, [esp+4] ; EIP
10 poddubny 306
 
1 ha 307
        mov    [write_error_to],process_eip+43
308
        call   writehex
309
 
310
        mov    esi,process_error
311
        call   sys_msg_board_str
312
 
313
        mov    esi,process_pid
314
        call   sys_msg_board_str
315
 
316
        mov    esi,process_eip
317
        call   sys_msg_board_str
318
 
319
        ret
320
 
321
 
322
 
6 poddubny 323
; irq1  ->  hid/keyboard.inc
1 ha 324
 
325
 
10 poddubny 326
macro irqh [num]
8 poddubny 327
{
328
  forward
329
  p_irq#num :
40 halyavin 330
     save_ring3_context
8 poddubny 331
     mov   edi, num
332
     jmp   irq_c
333
}
1 ha 334
 
160 diamond 335
irqh 2,5,7,8,9,10,11
1 ha 336
 
8 poddubny 337
 irq_c:
338
     mov   ax, os_data
339
     mov   ds, ax
340
     mov   es, ax
1 ha 341
     call  irqhandler
40 halyavin 342
     restore_ring3_context
8 poddubny 343
     iret
11 poddubny 344
 
345
p_irq6:
40 halyavin 346
     save_ring3_context
11 poddubny 347
     mov   ax, os_data
348
     mov   ds, ax
349
     mov   es, ax
350
     call  fdc_irq
33 mario79 351
     call  ready_for_next_irq
40 halyavin 352
     restore_ring3_context
33 mario79 353
     iret
15 poddubny 354
 
33 mario79 355
p_irq3:
40 halyavin 356
     save_ring3_context
33 mario79 357
     mov   ax, os_data
358
     mov   ds, ax
359
     mov   es, ax
58 mario79 360
     cmp   [com2_mouse_detected],0
361
     je    old_irq3_handler
33 mario79 362
     call  check_mouse_data_com2
58 mario79 363
     jmp   p_irq3_1
364
 old_irq3_handler:
365
     mov   edi,3
366
     call  irqhandler
164 serge 367
  p_irq3_1:
40 halyavin 368
     restore_ring3_context
33 mario79 369
     iret
15 poddubny 370
 
33 mario79 371
p_irq4:
40 halyavin 372
     save_ring3_context
33 mario79 373
     mov   ax, os_data
374
     mov   ds, ax
375
     mov   es, ax
58 mario79 376
     cmp   [com1_mouse_detected],0
377
     je    old_irq4_handler
33 mario79 378
     call  check_mouse_data_com1
58 mario79 379
     jmp   p_irq4_1
380
 old_irq4_handler:
381
     mov   edi,4
382
     call  irqhandler
164 serge 383
  p_irq4_1:
40 halyavin 384
     restore_ring3_context
11 poddubny 385
     iret
386
 
33 mario79 387
p_irq12:
40 halyavin 388
     save_ring3_context
33 mario79 389
     mov   ax, os_data
390
     mov   ds, ax
391
     mov   es, ax
392
     call  check_mouse_data_ps2
40 halyavin 393
     restore_ring3_context
33 mario79 394
     iret
395
 
160 diamond 396
p_irq14:
397
        save_ring3_context
398
        mov     ax, os_data
399
        mov     ds, ax
400
        mov     es, ax
401
        call    [irq14_func]
402
        call    ready_for_next_irq_1
403
        restore_ring3_context
404
        iret
405
p_irq15:
406
        save_ring3_context
407
        mov     ax, os_data
408
        mov     ds, ax
409
        mov     es, ax
410
        call    [irq15_func]
411
        call    ready_for_next_irq_1
412
        restore_ring3_context
413
        iret
414
 
33 mario79 415
ready_for_next_irq:
416
     mov    [check_idle_semaphore],5
417
     mov   al, 0x20
418
     out   0x20, al
419
     ret
420
 
421
ready_for_next_irq_1:
422
     mov    [check_idle_semaphore],5
423
     mov   al, 0x20
424
     out    0xa0,al
425
     out   0x20, al
426
     ret
427
 
6 poddubny 428
irqD:
40 halyavin 429
     save_ring3_context
8 poddubny 430
     mov   ax, os_data
431
     mov   ds, ax
432
     mov   es, ax
164 serge 433
 
6 poddubny 434
     mov   dx,0xf0
435
     mov   al,0
436
     out   dx,al
1 ha 437
 
6 poddubny 438
     mov   dx,0xa0
439
     mov   al,0x20
440
     out   dx,al
441
     mov   dx,0x20
40 halyavin 442
     out   dx,al
443
 
444
     restore_ring3_context
164 serge 445
 
8 poddubny 446
     iret
1 ha 447
 
448
 
449
irqhandler:
450
 
451
     push   edi
452
 
453
     mov    esi,edi          ; 1
454
     shl    esi,6            ; 1
455
     add    esi,irq00read    ; 1
456
     shl    edi,12           ; 1
457
     add    edi,0x2E0000
75 diamond 458
     mov    ecx,16
1 ha 459
 
460
     mov    [check_idle_semaphore],5
461
 
462
   irqnewread:
75 diamond 463
     dec    ecx
464
     js     irqover
1 ha 465
 
466
     mov    dx,[esi]         ; 2+
467
 
468
     cmp    dx,0             ; 1
469
     jz     irqover
470
     cmp    [esi+3],byte 1   ; 2     ; byte read
471
     jne    noirqbyte        ; 4-11
472
 
473
     in     al,dx
474
 
475
     mov    edx,[edi]
476
     cmp    edx,4000
477
     je     irqfull
478
     mov    ebx,edi
479
     add    ebx,0x10
480
     add    ebx,edx
481
     mov    [ebx],al
482
     inc    edx
483
     mov    [edi],edx
484
 
485
     add    esi,4
486
     jmp    irqnewread
487
 
488
   noirqbyte:
489
 
490
 
491
     cmp    [esi+3],byte 2     ; word read
492
     jne    noirqword
493
 
494
     in     ax,dx
495
 
496
     mov    edx,[edi]
497
     cmp    edx,4000
498
     je     irqfull
499
     mov    ebx,edi
500
     add    ebx,0x10
501
     add    ebx,edx
502
     mov    [ebx],ax
503
     add    edx,2
504
     mov    [edi],edx
505
     add    esi,4
506
     jmp    irqnewread
507
 
508
   noirqword:
509
   irqfull:
510
   irqover:
511
 
512
     mov    al,0x20            ; ready for next irq
513
     out    0x20,al
514
 
515
     pop    ebx
516
     cmp    ebx,7
517
     jbe    noa0
518
     out    0xa0,al
519
   noa0:
520
 
521
     ret
522
 
523
 
524
 
525
set_application_table_status:
526
        push eax
527
 
528
        mov  eax,[0x3000]
529
        shl  eax, 5
115 poddubny 530
        add  eax,0x3000+TASKDATA.pid
1 ha 531
        mov  eax,[eax]
532
 
533
        mov  [application_table_status],eax
534
 
535
        pop  eax
536
 
537
        ret
538
 
539
 
540
clear_application_table_status:
541
        push eax
542
 
543
        mov  eax,[0x3000]
544
        shl  eax, 5
115 poddubny 545
        add  eax,0x3000+TASKDATA.pid
1 ha 546
        mov  eax,[eax]
547
 
548
        cmp  eax,[application_table_status]
549
        jne  apptsl1
550
        mov  [application_table_status],0
551
      apptsl1:
552
 
553
        pop  eax
554
 
555
        ret
556
 
557
 
558
 
559
sys_resize_app_memory:
560
        ; eax = 1 - resize
561
        ;     ebx = new amount of memory
562
 
563
        cmp    eax,1
4 poddubny 564
        jne    .no_application_mem_resize
1 ha 565
 
164 serge 566
        stdcall new_mem_resize, ebx
567
        mov [esp+36], eax
568
        ret
1 ha 569
 
164 serge 570
.no_application_mem_resize:
1 ha 571
        ret
572
 
573
 
574
 
575
get_app_params:
576
 
577
    push eax
578
 
579
    cmp  [0x90000+6],word '00'
580
    jne  no_00_header
581
 
582
    mov  eax,[0x90000+12]
583
    mov  [app_start],eax
584
    mov  eax,[0x90000+16]
585
    mov  [app_i_end],eax
586
    mov  eax,[0x90000+20]
587
    mov  [app_mem],eax
133 diamond 588
; \begin{diamond}[20.08.2006]
589
; sanity check (functions 19,58 load app_i_end bytes and that must
590
; fit in allocated memory to prevent kernel faults)
591
    cmp  eax,[app_i_end]
592
    jb   no_01_header
593
; \end{diamond}[20.08.2006]
1 ha 594
    shr  eax,1
595
    sub  eax,0x10
596
    mov  [app_esp],eax
597
    mov  eax,[0x90000+24]
598
    mov  [app_i_param],eax
599
    mov  [app_i_icon],dword 0
600
 
601
    pop  eax
133 diamond 602
    clc
1 ha 603
    ret
604
 
605
  no_00_header:
606
 
607
 
608
    cmp  [0x90000+6],word '01'
609
    jne  no_01_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
133 diamond 617
; \begin{diamond}[20.08.2006]
618
    cmp  eax,[app_i_end]
619
    jb   no_01_header
620
; \end{diamond}[20.08.2006]
1 ha 621
    mov  eax,[0x90000+24]
622
    mov  [app_esp],eax
623
    mov  eax,[0x90000+28]
624
    mov  [app_i_param],eax
625
    mov  eax,[0x90000+32]
626
    mov  [app_i_icon],eax
627
 
628
    pop  eax
133 diamond 629
    clc
1 ha 630
    ret
631
 
632
   no_01_header:
633
 
634
    pop  eax
133 diamond 635
    stc
1 ha 636
    ret
637
 
638
 
639
uglobal
640
  new_process_place  dd  0x0
641
  app_start    dd  0x0
642
  app_i_end    dd  0x0
643
  app_mem      dd  0x0
644
  app_esp      dd  0x0
645
  app_i_param  dd  0x0
646
  app_i_icon   dd  0x0
164 serge 647
;  app_mem_pos  dd  0x0
5 halyavin 648
  appl_path        dd 0x0
164 serge 649
  appl_path_size   dd 0x0
1 ha 650
endg
651
 
652
 
653
sys_threads:
654
 
655
; eax=1 create thread
656
;
657
;   ebx=thread start
658
;   ecx=thread stack value
659
;
660
; on return : eax = pid
661
jmp new_sys_threads
662
 
663
iglobal
664
  process_terminating   db 'K : Process - terminating',13,10,0
665
  process_terminated    db 'K : Process - done',13,10,0
666
endg
667
 
668
 
669
terminate: ; terminate application
670
    push   esi
671
    mov    esi,process_terminating
672
    call   sys_msg_board_str
673
    pop    esi
674
 
40 halyavin 675
@@:
1 ha 676
    cli
677
    cmp   [application_table_status],0
678
    je    term9
679
    sti
680
    call  change_task
40 halyavin 681
    jmp   @b
1 ha 682
  term9:
683
 
684
    call  set_application_table_status
164 serge 685
 
1 ha 686
    mov    eax,esi
687
 
164 serge 688
    pushad
689
    shl   eax,8
690
    mov   eax,[PROC_BASE+eax+0xB8]
691
    stdcall destroy_app_space, eax
692
    popad
693
 
694
    cmp   [fpu_owner],esi   ; if user fpu last -> fpu user = 1
1 ha 695
    jne   fpu_ok_1
164 serge 696
    mov   [fpu_owner],1
1 ha 697
  fpu_ok_1:
698
 
699
    mov   [0xf400],byte 0           ; empty keyboard buffer
700
    mov   [0xf500],byte 0           ; empty button buffer
701
 
702
 
92 diamond 703
; remove defined hotkeys
704
        mov     eax, hotkey_list
705
.loop:
706
        cmp     [eax+8], esi
707
        jnz     .cont
708
        mov     ecx, [eax]
709
        jecxz   @f
710
        push    dword [eax+12]
711
        pop     dword [ecx+12]
712
@@:
713
        mov     ecx, [eax+12]
714
        push    dword [eax]
715
        pop     dword [ecx]
716
        xor     ecx, ecx
717
        mov     [eax], ecx
718
        mov     [eax+4], ecx
719
        mov     [eax+8], ecx
720
        mov     [eax+12], ecx
721
.cont:
722
        add     eax, 16
723
        cmp     eax, hotkey_list+256*16
724
        jb      .loop
725
; remove hotkeys in buffer
726
        mov     eax, hotkey_buffer
727
.loop2:
728
        cmp     [eax], esi
729
        jnz     .cont2
730
        and     dword [eax+4], 0
731
        and     dword [eax], 0
732
.cont2:
733
        add     eax, 8
734
        cmp     eax, hotkey_buffer+120*8
735
        jb      .loop2
736
 
1 ha 737
    mov   ecx,esi                 ; remove buttons
738
  bnewba2:
739
    mov   edi,[0xfe88]
740
    mov   eax,edi
741
    cld
742
    movzx ebx,word [edi]
743
    inc   bx
744
  bnewba:
745
    dec   bx
746
    jz    bnmba
747
    add   eax,0x10
748
    cmp   cx,[eax]
749
    jnz   bnewba
750
    pusha
751
    mov   ecx,ebx
752
    inc   ecx
753
    shl   ecx,4
754
    mov   ebx,eax
755
    add   eax,0x10
756
    call  memmove
757
    dec   dword [edi]
758
    popa
759
    jmp   bnewba2
760
  bnmba:
761
 
762
    pusha     ; save window coordinates for window restoring
763
    cld
764
    shl   esi,5
765
    add   esi,window_data
114 mikedld 766
    mov   eax,[esi+WDATA.box.left]
102 poddubny 767
    mov   [dlx],eax
114 mikedld 768
    add   eax,[esi+WDATA.box.width]
102 poddubny 769
    mov   [dlxe],eax
114 mikedld 770
    mov   eax,[esi+WDATA.box.top]
102 poddubny 771
    mov   [dly],eax
114 mikedld 772
    add   eax,[esi+WDATA.box.height]
102 poddubny 773
    mov   [dlye],eax
1 ha 774
 
142 diamond 775
    xor   eax, eax
776
    mov   [esi+WDATA.box.left],eax
777
    mov   [esi+WDATA.box.width],eax
114 mikedld 778
    mov   [esi+WDATA.box.top],eax
142 diamond 779
    mov   [esi+WDATA.box.height],eax
115 poddubny 780
    mov   [esi+WDATA.cl_workarea],eax
781
    mov   [esi+WDATA.cl_titlebar],eax
782
    mov   [esi+WDATA.cl_frames],eax
783
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
102 poddubny 784
    lea   edi, [esi-window_data+draw_data]
1 ha 785
    mov   ecx,32/4
786
    rep   stosd
787
    popa
788
 
40 halyavin 789
; debuggee test
790
    pushad
791
    mov  edi, esi
792
    shl  edi, 5
115 poddubny 793
    mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
40 halyavin 794
    test eax, eax
795
    jz   .nodebug
796
    push 8
797
    pop  ecx
115 poddubny 798
    push dword [0x3000+edi+TASKDATA.pid]   ; PID
40 halyavin 799
    push 2
800
    call debugger_notify
801
    pop  ecx
802
    pop  ecx
803
.nodebug:
804
    popad
805
 
1 ha 806
    pusha         ; at 0x80000+
807
    mov   edi,esi
808
    shl   edi,8
809
    add   edi,0x80000
810
    mov   ecx,256/4
811
    xor   eax, eax
812
    rep   stosd
813
    popa
814
 
815
    pusha          ; name to spaces
816
    mov   edi,esi
817
    shl   edi,8
115 poddubny 818
    add   edi,0x80000+APPDATA.app_name
1 ha 819
    mov   ecx,11
820
    mov   eax,' '
821
    rep   stosb
822
    popa
823
 
824
 
102 poddubny 825
  ; activate window
826
        movzx  eax, word [0xC000 + esi*2]
827
        cmp    eax, [0x3004]
828
        jne    .dont_activate
829
        pushad
830
 .check_next_window:
831
        dec    eax
832
        cmp    eax, 1
833
        jbe    .nothing_to_activate
834
        lea    esi, [0xc400+eax*2]
835
        movzx  edi, word [esi]               ; edi = process
836
        shl    edi, 5
115 poddubny 837
        cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
102 poddubny 838
        je     .check_next_window
839
        add    edi, window_data
154 diamond 840
; \begin{diamond}[19.09.2006]
841
; skip minimized windows
164 serge 842
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
843
        jnz    .check_next_window
154 diamond 844
; \end{diamond}
102 poddubny 845
        call   waredraw
846
 .nothing_to_activate:
847
        popad
848
 .dont_activate:
849
 
92 diamond 850
        push    esi     ; remove hd1 & cd & flp reservation
851
        shl     esi, 5
118 diamond 852
        mov     esi, [esi+0x3000+TASKDATA.pid]
92 diamond 853
        cmp     [hd1_status], esi
854
        jnz     @f
855
        mov     [hd1_status], 0
856
@@:
857
        cmp     [cd_status], esi
858
        jnz     @f
859
        mov     [cd_status], 0
860
@@:
861
        cmp     [flp_status], esi
862
        jnz     @f
863
        mov     [flp_status], 0
864
@@:
865
        pop     esi
1 ha 866
 
867
    pusha ; remove all irq reservations
92 diamond 868
    mov   eax,esi
115 poddubny 869
    shl   eax, 5
118 diamond 870
    mov   eax,[eax+0x3000+TASKDATA.pid]
1 ha 871
    mov   edi,irq_owner
872
    mov   ecx,16
873
  newirqfree:
92 diamond 874
    scasd
1 ha 875
    jne   nofreeirq
92 diamond 876
    mov   [edi-4],dword 0
1 ha 877
  nofreeirq:
878
    loop   newirqfree
879
    popa
880
 
881
 
882
    pusha                     ; remove all port reservations
883
    mov   edx,esi
115 poddubny 884
    shl   edx, 5
1 ha 885
    add   edx,0x3000
115 poddubny 886
    mov   edx,[edx+TASKDATA.pid]
1 ha 887
 
888
  rmpr0:
889
 
890
    mov   esi,[0x2d0000]
891
 
892
    cmp   esi,0
893
    je    rmpr9
894
 
895
  rmpr3:
896
 
897
    mov   edi,esi
898
    shl   edi,4
899
    add   edi,0x2d0000
900
 
901
    cmp   edx,[edi]
902
    je    rmpr4
903
 
904
    dec   esi
905
    jnz   rmpr3
906
 
907
    jmp   rmpr9
908
 
909
  rmpr4:
910
 
911
    mov   ecx,256
912
    sub   ecx,esi
913
    shl   ecx,4
914
 
915
    mov   esi,edi
916
    add   esi,16
917
    cld
918
    rep   movsb
919
 
920
    dec   dword [0x2d0000]
921
 
922
    jmp   rmpr0
923
 
924
  rmpr9:
925
 
926
    popa
927
    mov  edi,esi         ; do not run this process slot
6 poddubny 928
    shl  edi, 5
115 poddubny 929
    mov  [edi+0x3000 + TASKDATA.state],byte 9
40 halyavin 930
; debugger test - terminate all debuggees
931
    mov  eax, 2
115 poddubny 932
    mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
40 halyavin 933
.xd0:
934
    cmp  eax, [0x3004]
935
    ja   .xd1
936
    cmp  dword [ecx], esi
937
    jnz  @f
938
    and  dword [ecx], 0
939
    pushad
940
    xchg eax, ebx
941
    mov  eax, 2
942
    call sys_system
943
    popad
944
@@:
945
    inc  eax
946
    add  ecx, 0x100
947
    jmp  .xd0
948
.xd1:
1 ha 949
;    call  systest
950
    sti  ; .. and life goes on
951
 
112 poddubny 952
    mov   eax, [dlx]
953
    mov   ebx, [dly]
954
    mov   ecx, [dlxe]
955
    mov   edx, [dlye]
1 ha 956
    call  calculatescreen
957
    xor   eax, eax
958
    xor   esi, esi
959
    call  redrawscreen
960
 
961
    mov   [0xfff4],byte 0  ; no mouse background
962
    mov   [0xfff5],byte 0  ; draw mouse
963
 
964
    mov   [application_table_status],0
965
    mov   esi,process_terminated
966
    call  sys_msg_board_str
967
 
968
    ret
969
 
970
iglobal
971
  boot_sched_1    db   'Building gdt tss pointer',0
8 poddubny 972
  boot_sched_2    db   'Building IDT table',0
1 ha 973
endg
974
 
975
 
976
build_scheduler:
977
 
978
        mov    esi,boot_sched_1
979
        call   boot_log
980
        call   build_process_gdt_tss_pointer
981
 
8 poddubny 982
        mov    esi,boot_sched_2
1 ha 983
        call   boot_log
984
        call   build_interrupt_table
985
 
986
        ret
987