Subversion Repositories Kolibri OS

Rev

Rev 9709 | Rev 9742 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9709 Rev 9715
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;;
4
;;  Distributed under terms of the GNU General Public License.  ;;
4
;;  Distributed under terms of the GNU General Public License.  ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 7... Line 7...
7
 
7
 
Line 8... Line 8...
8
$Revision: 9709 $
8
$Revision: 9715 $
9
 
9
 
10
align 4 ;3A08
10
align 4 ;3A08
11
build_interrupt_table:
11
build_interrupt_table:
Line 137... Line 137...
137
        cmp     bl, 14             ; #PF
137
        cmp     bl, 14             ; #PF
138
        jne     @f
138
        jne     @f
139
        call    page_fault_handler ; SEE: core/memory.inc
139
        call    page_fault_handler ; SEE: core/memory.inc
140
  @@:
140
  @@:
141
        mov     esi, [current_slot]
141
        mov     esi, [current_slot]
142
        btr     [esi+APPDATA.except_mask], ebx
142
        btr     [esi + APPDATA.except_mask], ebx
143
        jnc     @f
143
        jnc     @f
144
        mov     eax, [esi+APPDATA.exc_handler]
144
        mov     eax, [esi + APPDATA.exc_handler]
145
        test    eax, eax
145
        test    eax, eax
146
        jnz     IRetToUserHook
146
        jnz     IRetToUserHook
147
  @@:
147
  @@:
148
        cli
148
        cli
149
        mov     eax, [esi+APPDATA.debugger_slot]
149
        mov     eax, [esi + APPDATA.debugger_slot]
150
        test    eax, eax
150
        test    eax, eax
151
        jnz     .debug
151
        jnz     .debug
152
; not debuggee => say error and terminate
152
; not debuggee => say error and terminate
153
        call    show_error_parameters  ; this function output in edx = current_slot
153
        call    show_error_parameters  ; this function output in edx = current_slot
154
        sti
154
        sti
Line 286... Line 286...
286
        add     ebx, 4
286
        add     ebx, 4
287
        call    .check_ESP
287
        call    .check_ESP
288
        test    eax, eax
288
        test    eax, eax
289
        jnz     .error_ESP
289
        jnz     .error_ESP
290
        DEBUGF  1, " [ESP+32]: %x\n",[ebx]
290
        DEBUGF  1, " [ESP+32]: %x\n",[ebx]
291
;for input instruction
-
 
292
        mov     ebx, [reg_eip+4]
-
 
293
        call    .check_ESP
-
 
294
        test    eax, eax
-
 
295
        jnz     .error_ESP
-
 
296
        DEBUGF  1, "K : [EIP]: %x",[ebx]
-
 
297
        add     ebx, 4
-
 
298
        call    .check_ESP
-
 
299
        test    eax, eax
-
 
300
        jnz     .error_ESP
-
 
301
        DEBUGF  1, " [EIP+4]: %x",[ebx]
-
 
302
        add     ebx, 4
-
 
303
        call    .check_ESP
-
 
304
        test    eax, eax
-
 
305
        jnz     .error_ESP
-
 
306
        DEBUGF  1, " [EIP+8]: %x\n",[ebx]
-
 
307
        add     ebx, 4
-
 
308
        call    .check_ESP
-
 
309
        test    eax, eax
-
 
310
        jnz     .error_ESP
-
 
311
        DEBUGF  1, "K : [EIP+12]: %x\n",[ebx]
-
 
312
        pop     edx ecx ebx eax
291
        pop     edx ecx ebx eax
313
        ret
292
        ret
314
.error_ESP:
293
.error_ESP:
315
        pop     edx ecx ebx eax
294
        pop     edx ecx ebx eax
316
        DEBUGF  1, "\n"
295
        DEBUGF  1, "\n"
Line 320... Line 299...
320
.check_ESP:
299
.check_ESP:
321
        push    ebx
300
        push    ebx
322
        shr     ebx, 12
301
        shr     ebx, 12
323
        mov     ecx, ebx
302
        mov     ecx, ebx
324
        shr     ecx, 10
303
        shr     ecx, 10
325
        mov     edx, [master_tab+ecx*4]
304
        mov     edx, [master_tab + ecx*4]
326
        test    edx, PG_READ
305
        test    edx, PG_READ
327
        jz      .fail             ; page table is not created
306
        jz      .fail             ; page table is not created
328
                                  ; incorrect address in the program
307
                                  ; incorrect address in the program
Line 329... Line 308...
329
 
308
 
330
        mov     eax, [page_tabs+ebx*4]
309
        mov     eax, [page_tabs + ebx*4]
331
        test    eax, 2
310
        test    eax, 2
Line 332... Line 311...
332
        jz      .fail             ; address not reserved for use. error
311
        jz      .fail             ; address not reserved for use. error
333
 
312
 
Line 432... Line 411...
432
 
411
 
Line 433... Line 412...
433
 
412
 
434
        push    esi        ;save .slot
413
        push    esi        ;save .slot
435
 
414
 
436
        shl     esi, BSF sizeof.APPDATA
415
        shl     esi, BSF sizeof.APPDATA
437
        mov     edx, [SLOT_BASE+esi+APPDATA.process]
416
        mov     edx, [SLOT_BASE + esi + APPDATA.process]
438
        test    edx, edx
417
        test    edx, edx
439
        jnz     @F
418
        jnz     @F
440
        mov     [SLOT_BASE + esi + APPDATA.state], TSTATE_FREE
419
        mov     [SLOT_BASE + esi + APPDATA.state], TSTATE_FREE
441
        pop     esi
420
        pop     esi
442
        ret
421
        ret
443
@@:
422
@@:
444
        push    edx                     ;save .process
423
        push    edx                     ;save .process
Line 445... Line 424...
445
        lea     edx, [SLOT_BASE+esi]
424
        lea     edx, [SLOT_BASE + esi]
446
        call    scheduler_remove_thread
425
        call    scheduler_remove_thread
447
        call    lock_application_table
426
        call    lock_application_table
448
 
427
 
449
; if the process is in V86 mode...
428
; if the process is in V86 mode...
450
        mov     eax, [.slot]
429
        mov     eax, [.slot]
451
        shl     eax, BSF sizeof.APPDATA
430
        shl     eax, BSF sizeof.APPDATA
452
        mov     esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
431
        mov     esi, [SLOT_BASE + eax + APPDATA.pl0_stack]
453
        add     esi, RING0_STACK_SIZE
432
        add     esi, RING0_STACK_SIZE
454
        cmp     [eax+SLOT_BASE+APPDATA.saved_esp0], esi
433
        cmp     [SLOT_BASE + eax + APPDATA.saved_esp0], esi
455
        jz      .nov86
434
        jz      .nov86
456
; ...it has page directory for V86 mode
435
; ...it has page directory for V86 mode
457
        mov     esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
436
        mov     esi, [SLOT_BASE + eax + APPDATA.saved_esp0]
458
        mov     ecx, [esi+4]
437
        mov     ecx, [esi+4]
459
        mov     [eax+SLOT_BASE+APPDATA.process], ecx
438
        mov     [SLOT_BASE + eax + APPDATA.process], ecx
460
; ...and I/O permission map for V86 mode
439
; ...and I/O permission map for V86 mode
461
        mov     ecx, [esi+12]
440
        mov     ecx, [esi+12]
462
        mov     [eax+SLOT_BASE+APPDATA.io_map], ecx
441
        mov     [SLOT_BASE + eax + APPDATA.io_map], ecx
463
        mov     ecx, [esi+8]
442
        mov     ecx, [esi+8]
464
        mov     [eax+SLOT_BASE+APPDATA.io_map+4], ecx
443
        mov     [SLOT_BASE + eax + APPDATA.io_map+4], ecx
465
.nov86:
444
.nov86:
466
; destroy per-thread kernel objects
445
; destroy per-thread kernel objects
467
        mov     esi, [.slot]
446
        mov     esi, [.slot]
468
        shl     esi, BSF sizeof.APPDATA
447
        shl     esi, BSF sizeof.APPDATA
469
        add     esi, SLOT_BASE+APP_OBJ_OFFSET
448
        add     esi, SLOT_BASE + APP_OBJ_OFFSET
Line 470... Line 449...
470
@@:
449
@@:
471
        mov     eax, [esi+APPOBJ.fd]
450
        mov     eax, [esi + APPOBJ.fd]
Line 472... Line 451...
472
        test    eax, eax
451
        test    eax, eax
473
        jz      @F
452
        jz      @F
474
 
453
 
475
        cmp     eax, esi
454
        cmp     eax, esi
476
        je      @F
455
        je      @F
477
 
456
 
478
        push    esi
457
        push    esi
479
        call    [eax+APPOBJ.destroy]
458
        call    [eax + APPOBJ.destroy]
480
           DEBUGF 1,"%s",msg_obj_destroy
459
           DEBUGF 1,"%s",msg_obj_destroy
Line 481... Line 460...
481
        pop     esi
460
        pop     esi
482
        jmp     @B
461
        jmp     @B
483
@@:
462
@@:
484
        mov     esi, [.slot]
463
        mov     esi, [.slot]
485
        cmp     [fpu_owner], esi ; if user fpu last -> fpu user = 2
464
        cmp     [fpu_owner], esi ; if user fpu last -> fpu user = 2
486
        jne     @F
465
        jne     @F
487
 
466
 
Line 573... Line 552...
573
 
552
 
574
        pusha   ; save window coordinates for window restoring
553
        pusha   ; save window coordinates for window restoring
575
        cld
554
        cld
576
        shl     esi, BSF sizeof.WDATA
555
        shl     esi, BSF sizeof.WDATA
577
        add     esi, window_data
556
        add     esi, window_data
578
        mov     eax, [esi+WDATA.box.left]
557
        mov     eax, [esi + WDATA.box.left]
579
        mov     [draw_limits.left], eax
558
        mov     [draw_limits.left], eax
580
        add     eax, [esi+WDATA.box.width]
559
        add     eax, [esi + WDATA.box.width]
581
        mov     [draw_limits.right], eax
560
        mov     [draw_limits.right], eax
582
        mov     eax, [esi+WDATA.box.top]
561
        mov     eax, [esi + WDATA.box.top]
583
        mov     [draw_limits.top], eax
562
        mov     [draw_limits.top], eax
584
        add     eax, [esi+WDATA.box.height]
563
        add     eax, [esi + WDATA.box.height]
Line 585... Line 564...
585
        mov     [draw_limits.bottom], eax
564
        mov     [draw_limits.bottom], eax
586
 
565
 
587
        xor     eax, eax
566
        xor     eax, eax
588
        mov     edi, esi
567
        mov     edi, esi
Line 589... Line 568...
589
        mov     ecx, sizeof.WDATA/4
568
        mov     ecx, sizeof.WDATA/4
590
        rep stosd
569
        rep stosd
591
 
570
 
592
        lea     edi, [esi-window_data+draw_data]
571
        lea     edi, [esi - window_data + draw_data]
Line 593... Line 572...
593
        mov     ecx, sizeof.WDATA/4
572
        mov     ecx, sizeof.WDATA/4
Line 611... Line 590...
611
        popad
590
        popad
Line 612... Line 591...
612
 
591
 
613
        mov     ebx, [.slot]
592
        mov     ebx, [.slot]
614
        shl     ebx, BSF sizeof.APPDATA
593
        shl     ebx, BSF sizeof.APPDATA
615
        push    ebx
594
        push    ebx
Line 616... Line 595...
616
        mov     ebx, [SLOT_BASE+ebx+APPDATA.pl0_stack]
595
        mov     ebx, [SLOT_BASE + ebx + APPDATA.pl0_stack]
Line 617... Line 596...
617
 
596
 
618
        stdcall kernel_free, ebx
597
        stdcall kernel_free, ebx
619
 
598
 
Line 620... Line 599...
620
        pop     ebx
599
        pop     ebx
621
        mov     ebx, [SLOT_BASE+ebx+APPDATA.cur_dir]
600
        mov     ebx, [SLOT_BASE + ebx + APPDATA.cur_dir]
622
        stdcall kernel_free, ebx
601
        stdcall kernel_free, ebx
Line 623... Line 602...
623
 
602
 
624
        mov     edi, [.slot]
603
        mov     edi, [.slot]
625
        shl     edi, BSF sizeof.APPDATA
604
        shl     edi, BSF sizeof.APPDATA
626
        add     edi, SLOT_BASE
605
        add     edi, SLOT_BASE
627
 
606
 
628
        mov     eax, [edi+APPDATA.io_map]
607
        mov     eax, [edi + APPDATA.io_map]
629
        cmp     eax, [SLOT_BASE+sizeof.APPDATA+APPDATA.io_map]
608
        cmp     eax, [SLOT_BASE + sizeof.APPDATA+APPDATA.io_map]
630
        je      @F
609
        je      @F
631
        call    free_page
610
        call    free_page
632
@@:
611
@@:
633
        mov     eax, [edi+APPDATA.io_map+4]
612
        mov     eax, [edi+APPDATA.io_map+4]
634
        cmp     eax, [SLOT_BASE+sizeof.APPDATA+APPDATA.io_map+4]
613
        cmp     eax, [SLOT_BASE+sizeof.APPDATA+APPDATA.io_map+4]
Line 635... Line 614...
635
        je      @F
614
        je      @F
636
        call    free_page
615
        call    free_page
637
@@:
616
@@:
Line 653... Line 632...
653
        pushad
632
        pushad
654
 .check_next_window:
633
 .check_next_window:
655
        dec     eax
634
        dec     eax
656
        cmp     eax, 1
635
        cmp     eax, 1
657
        jbe     .nothing_to_activate
636
        jbe     .nothing_to_activate
658
        lea     esi, [WIN_POS+eax*2]
637
        lea     esi, [WIN_POS + eax*2]
659
        movzx   edi, word [esi]              ; edi = process
638
        movzx   edi, word [esi]              ; edi = process
660
        shl     edi, BSF sizeof.APPDATA
639
        shl     edi, BSF sizeof.APPDATA
661
        cmp     [SLOT_BASE + edi + APPDATA.state], TSTATE_FREE ; skip free slots
640
        cmp     [SLOT_BASE + edi + APPDATA.state], TSTATE_FREE ; skip free slots
662
        je      .check_next_window
641
        je      .check_next_window
663
        shr     edi, 3
642
        shr     edi, 3
Line 672... Line 651...
672
        popad
651
        popad
673
 .dont_activate:
652
 .dont_activate:
Line 674... Line 653...
674
 
653
 
675
        push    esi     ; remove hd1 & cd & flp reservation
654
        push    esi     ; remove hd1 & cd & flp reservation
676
        shl     esi, BSF sizeof.APPDATA
655
        shl     esi, BSF sizeof.APPDATA
677
        mov     esi, [esi + SLOT_BASE + APPDATA.tid]
656
        mov     esi, [SLOT_BASE + esi + APPDATA.tid]
678
        cmp     [cd_status], esi
657
        cmp     [cd_status], esi
679
        jnz     @f
658
        jnz     @f
680
        call    free_cd_channel
659
        call    free_cd_channel
681
        and     [cd_status], 0
660
        and     [cd_status], 0
Line 688... Line 667...
688
@@:
667
@@:
Line 689... Line 668...
689
 
668
 
690
        pusha                 ; remove all port reservations
669
        pusha                 ; remove all port reservations
691
        mov     edx, esi
670
        mov     edx, esi
692
        shl     edx, BSF sizeof.APPDATA
671
        shl     edx, BSF sizeof.APPDATA
Line 693... Line 672...
693
        mov     edx, [edx + SLOT_BASE + APPDATA.tid]
672
        mov     edx, [SLOT_BASE + edx + APPDATA.tid]
Line 694... Line 673...
694
 
673
 
Line 731... Line 710...
731
  rmpr9:
710
  rmpr9:
Line 732... Line 711...
732
 
711
 
733
        popa
712
        popa
734
        mov     edi, esi ; do not run this process slot
713
        mov     edi, esi ; do not run this process slot
735
        shl     edi, BSF sizeof.APPDATA
714
        shl     edi, BSF sizeof.APPDATA
736
        mov     [edi + SLOT_BASE + APPDATA.state], TSTATE_FREE
715
        mov     [SLOT_BASE + edi + APPDATA.state], TSTATE_FREE
737
; debugger test - terminate all debuggees
716
; debugger test - terminate all debuggees
738
        mov     eax, 2
717
        mov     eax, 2
739
        mov     ecx, SLOT_BASE+2*sizeof.APPDATA + APPDATA.debugger_slot
718
        mov     ecx, SLOT_BASE + 2*sizeof.APPDATA + APPDATA.debugger_slot
740
.xd0:
719
.xd0:
741
        cmp     eax, [thread_count]
720
        cmp     eax, [thread_count]
742
        ja      .xd1
721
        ja      .xd1
743
        cmp     dword [ecx], esi
722
        cmp     dword [ecx], esi
Line 756... Line 735...
756
;release slot
735
;release slot
Line 757... Line 736...
757
 
736
 
Line 758... Line 737...
758
        bts     [thr_slot_map], esi
737
        bts     [thr_slot_map], esi
759
 
738
 
760
        mov     ecx, [.process]
739
        mov     ecx, [.process]
761
        lea     eax, [ecx+PROC.thr_list]
740
        lea     eax, [ecx + PROC.thr_list]
Line 762... Line 741...
762
        cmp     eax, [eax+LHEAD.next]
741
        cmp     eax, [eax + LHEAD.next]
763
        jne     @F
742
        jne     @F
764
 
743
 
Line 810... Line 789...
810
; Enter critical area. Called by thread which wants to be protected.
789
; Enter critical area. Called by thread which wants to be protected.
811
proc protect_from_terminate
790
proc protect_from_terminate
812
        mov     edx, [current_slot]
791
        mov     edx, [current_slot]
813
; Atomically increment depth of critical areas and get the old value.
792
; Atomically increment depth of critical areas and get the old value.
814
        mov     eax, 1
793
        mov     eax, 1
815
        lock xadd [edx+APPDATA.terminate_protection], eax
794
        lock xadd [edx + APPDATA.terminate_protection], eax
816
; If the old value was zero, somebody has started to terminate us,
795
; If the old value was zero, somebody has started to terminate us,
817
; so we are destructing and cannot do anything protected.
796
; so we are destructing and cannot do anything protected.
818
; Otherwise, return to the caller.
797
; Otherwise, return to the caller.
819
        test    eax, eax
798
        test    eax, eax
820
        jz      @f
799
        jz      @f
Line 827... Line 806...
827
 
806
 
828
; Leave critical area. Called by thread which wants to be protected.
807
; Leave critical area. Called by thread which wants to be protected.
829
proc unprotect_from_terminate
808
proc unprotect_from_terminate
830
        mov     edx, [current_slot]
809
        mov     edx, [current_slot]
831
; Atomically decrement depth of critical areas.
810
; Atomically decrement depth of critical areas.
832
        lock dec [edx+APPDATA.terminate_protection]
811
        lock dec [edx + APPDATA.terminate_protection]
833
; If the result of decrement is zero, somebody has requested termination,
812
; If the result of decrement is zero, somebody has requested termination,
834
; but at that moment we were inside a critical area; terminate now.
813
; but at that moment we were inside a critical area; terminate now.
835
        jz      sys_end
814
        jz      sys_end
836
; Otherwise, return to the caller.
815
; Otherwise, return to the caller.
Line 841... Line 820...
841
; Called by anyone.
820
; Called by anyone.
842
proc request_terminate
821
proc request_terminate
843
        xor     eax, eax        ; set return value
822
        xor     eax, eax        ; set return value
844
; Atomically clear the upper bit. If it was already zero, then
823
; Atomically clear the upper bit. If it was already zero, then
845
; somebody has requested termination before us, so just exit.
824
; somebody has requested termination before us, so just exit.
846
        lock btr [edx+APPDATA.terminate_protection], 31
825
        lock btr [edx + APPDATA.terminate_protection], 31
847
        jnc     .unsafe
826
        jnc     .unsafe
848
; Atomically decrement depth of critical areas.
827
; Atomically decrement depth of critical areas.
849
        lock dec [edx+APPDATA.terminate_protection]
828
        lock dec [edx + APPDATA.terminate_protection]
850
; If the result of decrement is nonzero, the target thread is inside a
829
; If the result of decrement is nonzero, the target thread is inside a
851
; critical area; leave termination to leaving that area.
830
; critical area; leave termination to leaving that area.
852
        jnz     .unsafe
831
        jnz     .unsafe
853
; Otherwise, it is safe to kill the target now and the caller is responsible
832
; Otherwise, it is safe to kill the target now and the caller is responsible
854
; for this. Return eax=1.
833
; for this. Return eax=1.