Subversion Repositories Kolibri OS

Rev

Rev 4423 | Rev 5565 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4423 Rev 5201
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2012. 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: 4423 $
8
$Revision: 5201 $
9
 
9
 
Line 121... Line 121...
121
        popfd
121
        popfd
122
        ret
122
        ret
123
endp
123
endp
Line 124... Line 124...
124
 
124
 
125
align 4
125
align 4
-
 
126
;proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
126
proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
127
map_page:
127
        push    ebx
128
        push    ebx
128
        mov     eax, [phis_addr]
129
        mov     eax, [esp+12]               ; phis_addr
129
        and     eax, not 0xFFF
130
        and     eax, not 0xFFF
130
        or      eax, [flags]
131
        or      eax, [esp+16]              ; flags
131
        mov     ebx, [lin_addr]
132
        mov     ebx, [esp+8]               ; lin_addr
132
        shr     ebx, 12
133
        shr     ebx, 12
133
        mov     [page_tabs+ebx*4], eax
134
        mov     [page_tabs+ebx*4], eax
134
        mov     eax, [lin_addr]
-
 
135
        invlpg  [eax]
135
        mov     eax, [esp+8]               ; lin_addr
136
        pop     ebx
136
        pop     ebx
137
        ret
137
        invlpg  [eax]
Line 138... Line 138...
138
endp
138
        ret     12
139
 
139
 
Line 348... Line 348...
348
        invlpg  [eax]
348
        invlpg  [eax]
349
        pop     ebx
349
        pop     ebx
350
        ret
350
        ret
351
endp
351
endp
Line -... Line 352...
-
 
352
 
-
 
353
uglobal
-
 
354
sb16_buffer_allocated db 0
-
 
355
endg
-
 
356
 
-
 
357
; Allocates [.size] bytes so that the target memory block
-
 
358
; is inside one 64K page for 24-bit DMA controller,
-
 
359
; that is, somewhere between 00xx0000h and 00xxFFFFh.
-
 
360
proc alloc_dma24
-
 
361
; Implementation note.
-
 
362
; The only user of that function is SB16 driver,
-
 
363
; so just return a statically allocated buffer.
-
 
364
virtual at esp
-
 
365
                dd      ? ; return address
-
 
366
.size           dd      ?
-
 
367
end virtual
-
 
368
        cmp     [sb16_buffer_allocated], 0
-
 
369
        jnz     .fail
-
 
370
        inc     [sb16_buffer_allocated]
-
 
371
        mov     eax, SB16Buffer
-
 
372
        ret     4
-
 
373
.fail:
-
 
374
        xor     eax, eax
-
 
375
        ret     4
-
 
376
endp
-
 
377
 
-
 
378
; Allocates a physical page for master page table
-
 
379
; that duplicates first Mb of OS_BASE at address 0;
-
 
380
; used for starting APs and for shutting down,
-
 
381
; where it is important to execute code in trivial-mapped pages.
-
 
382
; Returns eax = allocated physical page.
-
 
383
proc create_trampoline_pgmap
-
 
384
; The only non-trivial moment:
-
 
385
; we need a linear address to fill information,
-
 
386
; but we don't need it outside of this function,
-
 
387
; so we're returning physical address.
-
 
388
; Therefore, allocate memory with kernel_alloc,
-
 
389
; this will allocate physical page and a linear address somewhere,
-
 
390
; and deallocate only linear address with free_kernel_space.
-
 
391
        stdcall kernel_alloc, 0x1000
-
 
392
        mov     edi, eax
-
 
393
        mov     esi, master_tab
-
 
394
        mov     ecx, 1024
-
 
395
        rep movsd
-
 
396
        mov     ecx, [master_tab+(OS_BASE shr 20)]
-
 
397
        mov     [eax], ecx
-
 
398
        mov     edi, eax
-
 
399
        call    get_pg_addr
-
 
400
        push    eax
-
 
401
        stdcall free_kernel_space, edi
-
 
402
        pop     eax
-
 
403
        ret
-
 
404
endp
352
 
405
 
353
align 4
406
align 4
354
init_LFB:
407
proc init_LFB
-
 
408
           locals
-
 
409
             pg_count dd ?
Line 355... Line 410...
355
        xchg bx, bx
410
           endl
356
 
411
 
357
        cmp     dword [LFBAddress], -1
412
        cmp     dword [LFBAddress], -1
358
        jne     @f
413
        jne     @f
Line 379... Line 434...
379
        mov     [BOOT_VARS+BOOT_MTRR], byte 2
434
        mov     [BOOT_VARS+BOOT_MTRR], byte 2
380
        ret
435
        ret
381
@@:
436
@@:
382
        call    init_mtrr
437
        call    init_mtrr
Line 383... Line 438...
383
 
438
 
384
        xor     edx, edx
439
        mov     edx, LFB_BASE
-
 
440
        mov     esi, [LFBAddress]
-
 
441
        mov     edi, 0x00C00000
-
 
442
        mov     dword [exp_lfb+4], edx
-
 
443
 
-
 
444
        shr     edi, 12
-
 
445
        mov     [pg_count], edi
-
 
446
        shr     edi, 10
-
 
447
 
-
 
448
        bt      [cpu_caps], CAPS_PSE
-
 
449
        jnc     .map_page_tables
-
 
450
        or      esi, PG_LARGE+PG_UW
-
 
451
        mov     edx, sys_proc+PROC.pdt_0+(LFB_BASE shr 20)
-
 
452
@@:
-
 
453
        mov     [edx], esi
-
 
454
        add     edx, 4
-
 
455
        add     esi, 0x00400000
-
 
456
        dec     edi
-
 
457
        jnz     @B
385
        mov     eax, [LFBAddress]
458
 
-
 
459
        bt      [cpu_caps], CAPS_PGE
386
        bt      [cpu_caps], CAPS_PGE
460
        jnc     @F
-
 
461
        or      dword [sys_proc+PROC.pdt_0+(LFB_BASE shr 20)], PG_GLOBAL
387
        setc    dh                            ;eliminate branch and
462
@@:
388
        mov     ecx, LFB_SIZE/4096
463
        mov     dword [LFBAddress], LFB_BASE
389
        mov     edi, lfb_pd_0
464
        mov     eax, cr3      ;flush TLB
-
 
465
        mov     cr3, eax
Line 390... Line 466...
390
        lea     eax, [eax+edx+PG_UW]          ;set PG_GLOBAL if supported
466
        ret
391
 
-
 
392
.map_pte:
-
 
393
        stosd
-
 
Line -... Line 467...
-
 
467
 
394
        add     eax, 0x1000
468
.map_page_tables:
395
        loop    .map_pte
469
 
396
 
470
@@:
-
 
471
        call    alloc_page
-
 
472
        stdcall map_page_table, edx, eax
Line -... Line 473...
-
 
473
        add     edx, 0x00400000
-
 
474
        dec     edi
-
 
475
        jnz     @B
-
 
476
 
397
        mov     ecx, (LFB_SIZE/4096)/1024
477
        mov     eax, [LFBAddress]
-
 
478
        mov     edi, page_tabs + (LFB_BASE shr 10)
398
        mov     edi, sys_pgdir+(LFB_BASE shr 20)
479
        or      eax, PG_UW
399
        lea     eax, [(lfb_pd_0-OS_BASE)+PG_UW]
480
        mov     ecx, [pg_count]
400
 
481
        cld
-
 
482
@@:
Line 401... Line -...
401
.map_pde:
-
 
402
        stosd
483
        stosd
403
        add     eax, 0x1000
484
        add     eax, 0x1000
404
        loop    .map_pde
485
        dec     ecx
-
 
486
        jnz     @B
405
 
487
 
-
 
488
        mov     dword [LFBAddress], LFB_BASE
Line 406... Line 489...
406
        mov     dword [exp_lfb+4], LFB_BASE
489
        mov     eax, cr3                      ;flush TLB
407
        mov     dword [LFBAddress], LFB_BASE
490
        mov     cr3, eax
Line 408... Line 491...
408
        mov     eax, cr3                      ;flush TLB
491
 
409
        mov     cr3, eax
492
        ret
410
        ret
493
endp
Line 411... Line 494...
411
 
494
 
-
 
495
align 4
-
 
496
proc new_mem_resize stdcall, new_size:dword
412
align 4
497
 
413
proc new_mem_resize stdcall, new_size:dword
498
        push    ebx
Line 414... Line 499...
414
 
499
        push    esi
415
        push    ebx
500
        push    edi
416
        push    esi
501
 
417
        push    edi
502
        mov     edx, [current_slot]
Line 418... Line 503...
418
 
503
        mov     ebx, [edx+APPDATA.process]
419
        mov     edx, [current_slot]
504
 
420
        cmp     [edx+APPDATA.heap_base], 0
505
        cmp     [ebx+PROC.heap_base], 0
Line 421... Line 506...
421
        jne     .exit
506
        jne     .exit
422
 
507
 
Line 458... Line 543...
458
        call    mutex_unlock
543
        call    mutex_unlock
Line 459... Line 544...
459
 
544
 
460
.update_size:
545
.update_size:
461
        mov     edx, [current_slot]
546
        mov     edx, [current_slot]
-
 
547
        mov     ebx, [new_size]
462
        mov     ebx, [new_size]
548
        mov     edx, [edx+APPDATA.process]
463
        call    update_mem_size
549
        mov     [edx+PROC.mem_used], ebx
464
.exit:
550
.exit:
465
        pop     edi
551
        pop     edi
466
        pop     esi
552
        pop     esi
467
        pop     ebx
553
        pop     ebx
Line 534... Line 620...
534
        inc     eax
620
        inc     eax
535
        ret
621
        ret
536
endp
622
endp
Line 537... Line -...
537
 
-
 
538
 
-
 
539
align 4
-
 
540
update_mem_size:
-
 
541
; in: edx = slot base
-
 
542
;     ebx = new memory size
-
 
543
; destroys eax,ecx,edx
-
 
544
 
-
 
545
        mov     [APPDATA.mem_size+edx], ebx
-
 
546
;search threads and update
-
 
547
;application memory size infomation
-
 
548
        mov     ecx, [APPDATA.dir_table+edx]
-
 
549
        mov     eax, 2
-
 
550
 
-
 
551
.search_threads:
-
 
552
;eax = current slot
-
 
553
;ebx = new memory size
-
 
554
;ecx = page directory
-
 
555
        cmp     eax, [TASK_COUNT]
-
 
556
        jg      .search_threads_end
-
 
557
        mov     edx, eax
-
 
558
        shl     edx, 5
-
 
559
        cmp     word [CURRENT_TASK+edx+TASKDATA.state], 9  ;if slot empty?
-
 
560
        jz      .search_threads_next
-
 
561
        shl     edx, 3
-
 
562
        cmp     [SLOT_BASE+edx+APPDATA.dir_table], ecx      ;if it is our thread?
-
 
563
        jnz     .search_threads_next
-
 
564
        mov     [SLOT_BASE+edx+APPDATA.mem_size], ebx      ;update memory size
-
 
565
.search_threads_next:
-
 
566
        inc     eax
-
 
567
        jmp     .search_threads
-
 
568
.search_threads_end:
-
 
569
        ret
623
 
570
 
624
 
571
; param
625
; param
572
;  eax= linear address
626
;  eax= linear address
573
;
627
;
Line 622... Line 676...
622
.fail:  ;simply return to caller
676
.fail:  ;simply return to caller
623
        mov     esp, ebp
677
        mov     esp, ebp
624
        pop     ebx               ;restore exception number (#PF)
678
        pop     ebx               ;restore exception number (#PF)
625
        ret
679
        ret
Line 626... Line -...
626
 
-
 
627
;        xchg bx, bx
-
 
628
;        add     esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller
-
 
629
;        restore_ring3_context
-
 
630
;        iretd
-
 
631
 
680
 
632
.user_space:
681
.user_space:
633
        test    eax, PG_MAP
682
        test    eax, PG_MAP
634
        jnz     .err_access       ;Страница присутствует
683
        jnz     .err_access       ;Страница присутствует
Line 666... Line 715...
666
 
715
 
667
.err_access:
716
.err_access:
668
; access denied? this may be a result of copy-on-write protection for DLL
717
; access denied? this may be a result of copy-on-write protection for DLL
669
; check list of HDLLs
718
; check list of HDLLs
670
        and     ebx, not 0xFFF
719
        and     ebx, not 0xFFF
671
        mov     eax, [CURRENT_TASK]
-
 
672
        shl     eax, 8
720
        mov     eax, [current_process]
673
        mov     eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
721
        mov     eax, [eax+PROC.dlls_list_ptr]
674
        test    eax, eax
722
        test    eax, eax
675
        jz      .fail
723
        jz      .fail
676
        mov     esi, [eax+HDLL.fd]
724
        mov     esi, [eax+HDLL.fd]
677
.scan_hdll:
725
.scan_hdll:
Line 744... Line 792...
744
        rep movsd
792
        rep movsd
745
        jmp     .exit
793
        jmp     .exit
746
endp
794
endp
Line 747... Line 795...
747
 
795
 
748
; returns number of mapped bytes
796
; returns number of mapped bytes
749
proc map_mem stdcall, lin_addr:dword,slot:dword,\
797
proc map_mem_ipc stdcall, lin_addr:dword,slot:dword,\
-
 
798
                      ofs:dword,buf_size:dword,req_access:dword
750
                      ofs:dword,buf_size:dword,req_access:dword
799
        locals
-
 
800
             count   dd ?
-
 
801
             process dd ?
Line -... Line 802...
-
 
802
        endl
751
        push    0 ; initialize number of mapped bytes
803
 
752
 
804
        mov     [count], 0
Line 753... Line 805...
753
        cmp     [buf_size], 0
805
        cmp     [buf_size], 0
754
        jz      .exit
806
        jz      .exit
755
 
807
 
756
        mov     eax, [slot]
808
        mov     eax, [slot]
-
 
809
        shl     eax, 8
Line 757... Line 810...
757
        shl     eax, 8
810
        mov     eax, [SLOT_BASE+eax+APPDATA.process]
758
        mov     eax, [SLOT_BASE+eax+APPDATA.dir_table]
811
        test    eax, eax
759
        and     eax, 0xFFFFF000
812
        jz      .exit
760
 
813
 
761
        stdcall map_page, [ipc_pdir], eax, PG_UW
814
        mov     [process], eax
762
        mov     ebx, [ofs]
-
 
763
        shr     ebx, 22
815
        mov     ebx, [ofs]
764
        mov     esi, [ipc_pdir]
816
        shr     ebx, 22
765
        mov     edi, [ipc_ptab]
817
        mov     eax, [eax+PROC.pdt_0+ebx*4]                 ;get page table
766
        mov     eax, [esi+ebx*4]
-
 
767
        and     eax, 0xFFFFF000
-
 
768
        jz      .exit
-
 
769
        stdcall map_page, edi, eax, PG_UW
-
 
770
;           inc ebx
-
 
771
;           add edi, 0x1000
-
 
772
;           mov eax, [esi+ebx*4]
-
 
773
;           test eax, eax
-
 
774
;           jz @f
818
        mov     esi, [ipc_ptab]
775
;          and eax, 0xFFFFF000
819
        and     eax, 0xFFFFF000
776
;           stdcall map_page, edi, eax
820
        jz      .exit
777
 
821
        stdcall map_page, esi, eax, PG_SW
778
@@:
822
@@:
779
        mov     edi, [lin_addr]
823
        mov     edi, [lin_addr]
780
        and     edi, 0xFFFFF000
824
        and     edi, 0xFFFFF000
Line 781... Line 825...
781
        mov     ecx, [buf_size]
825
        mov     ecx, [buf_size]
782
        add     ecx, 4095
826
        add     ecx, 4095
783
        shr     ecx, 12
827
        shr     ecx, 12
784
        inc     ecx
-
 
785
 
-
 
786
        mov     edx, [ofs]
828
        inc     ecx                  ; ???????????
787
        shr     edx, 12
829
 
788
        and     edx, 0x3FF
830
        mov     edx, [ofs]
789
        mov     esi, [ipc_ptab]
831
        shr     edx, 12
790
 
832
        and     edx, 0x3FF
791
.map:
833
.map:
792
        stdcall safe_map_page, [slot], [req_access], [ofs]
834
        stdcall safe_map_page, [slot], [req_access], [ofs]
-
 
835
        jnc     .exit
793
        jnc     .exit
836
        add     [count], PAGE_SIZE
794
        add     dword [ebp-4], 4096
837
        add     [ofs], PAGE_SIZE
795
        add     [ofs], 4096
838
        dec     ecx
796
        dec     ecx
839
        jz      .exit
-
 
840
 
797
        jz      .exit
841
        add     edi, PAGE_SIZE
798
        add     edi, 0x1000
842
        inc     edx
799
        inc     edx
843
        cmp     edx, 1024
800
        cmp     edx, 0x400
844
        jnz     .map
801
        jnz     .map
845
 
-
 
846
        inc     ebx
802
        inc     ebx
847
        mov     eax, [process]
803
        mov     eax, [ipc_pdir]
848
        mov     eax, [eax+PROC.pdt_0+ebx*4]
804
        mov     eax, [eax+ebx*4]
849
        and     eax, 0xFFFFF000
805
        and     eax, 0xFFFFF000
-
 
806
        jz      .exit
850
        jz      .exit
807
        stdcall map_page, esi, eax, PG_UW
851
 
808
        xor     edx, edx
852
        stdcall map_page, esi, eax, PG_SW
809
        jmp     .map
853
        xor     edx, edx
Line 810... Line 854...
810
 
854
        jmp     .map
811
.exit:
855
.exit:
-
 
856
        mov     eax, [count]
812
        pop     eax
857
        ret
-
 
858
endp
-
 
859
 
Line -... Line 860...
-
 
860
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
813
        ret
861
                        ofs:dword,buf_size:dword,req_access:dword
814
endp
862
        locals
Line 815... Line 863...
815
 
863
             count   dd ?
816
proc map_memEx stdcall, lin_addr:dword,slot:dword,\
864
             process dd ?
817
                        ofs:dword,buf_size:dword,req_access:dword
865
        endl
818
        push    0 ; initialize number of mapped bytes
866
 
-
 
867
        mov     [count], 0
Line 819... Line 868...
819
 
868
        cmp     [buf_size], 0
820
        cmp     [buf_size], 0
869
        jz      .exit
821
        jz      .exit
870
 
822
 
871
        mov     eax, [slot]
823
        mov     eax, [slot]
872
        shl     eax, 8
824
        shl     eax, 8
-
 
825
        mov     eax, [SLOT_BASE+eax+APPDATA.dir_table]
873
        mov     eax, [SLOT_BASE+eax+APPDATA.process]
826
        and     eax, 0xFFFFF000
-
 
827
 
874
        test    eax, eax
828
        stdcall map_page, [proc_mem_pdir], eax, PG_UW
875
        jz      .exit
829
        mov     ebx, [ofs]
-
 
830
        shr     ebx, 22
876
 
831
        mov     esi, [proc_mem_pdir]
877
        mov     [process], eax
832
        mov     edi, [proc_mem_tab]
878
        mov     ebx, [ofs]
833
        mov     eax, [esi+ebx*4]
879
        shr     ebx, 22
834
        and     eax, 0xFFFFF000
880
        mov     eax, [eax+PROC.pdt_0+ebx*4]                 ;get page table
835
        test    eax, eax
881
        mov     esi, [proc_mem_tab]
836
        jz      .exit
882
        and     eax, 0xFFFFF000
Line 837... Line 883...
837
        stdcall map_page, edi, eax, PG_UW
883
        jz      .exit
838
 
884
        stdcall map_page, esi, eax, PG_SW
839
@@:
885
@@:
840
        mov     edi, [lin_addr]
-
 
841
        and     edi, 0xFFFFF000
-
 
842
        mov     ecx, [buf_size]
886
        mov     edi, [lin_addr]
843
        add     ecx, 4095
887
        and     edi, 0xFFFFF000
844
        shr     ecx, 12
888
        mov     ecx, [buf_size]
845
        inc     ecx
-
 
846
 
889
        add     ecx, 4095
847
        mov     edx, [ofs]
890
        shr     ecx, 12
848
        shr     edx, 12
-
 
849
        and     edx, 0x3FF
891
        inc     ecx                  ; ???????????
-
 
892
 
-
 
893
        mov     edx, [ofs]
-
 
894
        shr     edx, 12
-
 
895
        and     edx, 0x3FF
-
 
896
.map:
850
        mov     esi, [proc_mem_tab]
897
        stdcall safe_map_page, [slot], [req_access], [ofs]
-
 
898
        jnc     .exit
-
 
899
        add     [count], PAGE_SIZE
-
 
900
        add     [ofs], PAGE_SIZE
-
 
901
        dec     ecx
-
 
902
        jz      .exit
-
 
903
 
-
 
904
        add     edi, PAGE_SIZE
-
 
905
        inc     edx
-
 
906
        cmp     edx, 1024
-
 
907
        jnz     .map
851
 
908
 
852
.map:
909
        inc     ebx
853
        stdcall safe_map_page, [slot], [req_access], [ofs]
910
        mov     eax, [process]
854
        jnc     .exit
911
        mov     eax, [eax+PROC.pdt_0+ebx*4]
Line 855... Line 912...
855
        add     dword [ebp-4], 0x1000
912
        and     eax, 0xFFFFF000
856
        add     edi, 0x1000
913
        jz      .exit
Line 903... Line 960...
903
        cli
960
        cli
904
        cld
961
        cld
905
        push    ebx ecx
962
        push    ebx ecx
906
        mov     eax, [slot]
963
        mov     eax, [slot]
907
        shl     eax, 8
964
        shl     eax, 8
908
        mov     eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
965
        mov     eax, [SLOT_BASE+eax+APPDATA.process]
-
 
966
        mov     eax, [eax+PROC.dlls_list_ptr]
909
        test    eax, eax
967
        test    eax, eax
910
        jz      .no_hdll
968
        jz      .no_hdll
911
        mov     ecx, [eax+HDLL.fd]
969
        mov     ecx, [eax+HDLL.fd]
912
.scan_hdll:
970
.scan_hdll:
913
        cmp     ecx, eax
971
        cmp     ecx, eax
Line 990... Line 1048...
990
@@:
1048
@@:
991
        or      eax, -1
1049
        or      eax, -1
992
        mov     [esp+32], eax
1050
        mov     [esp+32], eax
993
        ret
1051
        ret
Line 994... Line -...
994
 
-
 
995
;align 4
-
 
996
;proc set_ipc_buff
-
 
997
 
-
 
998
;           mov  eax,[current_slot]
-
 
999
;           pushf
-
 
1000
;           cli
-
 
1001
;           mov  [eax+APPDATA.ipc_start],ebx     ;set fields in extended information area
-
 
1002
;           mov  [eax+APPDATA.ipc_size],ecx
-
 
1003
;
-
 
1004
;           add ecx, ebx
-
 
1005
;           add ecx, 4095
-
 
1006
;           and ecx, not 4095
-
 
1007
;
-
 
1008
;.touch:    mov eax, [ebx]
-
 
1009
;           add ebx, 0x1000
-
 
1010
;           cmp ebx, ecx
-
 
1011
;           jb  .touch
-
 
1012
;
-
 
1013
;           popf
-
 
1014
;           xor eax, eax
-
 
1015
;           ret
-
 
1016
;endp
-
 
1017
 
1052
 
1018
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
1053
proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword
1019
           locals
1054
           locals
1020
             dst_slot   dd ?
1055
             dst_slot   dd ?
1021
             dst_offset dd ?
1056
             dst_offset dd ?
Line 1031... Line 1066...
1031
        test    eax, eax
1066
        test    eax, eax
1032
        jz      .no_pid
1067
        jz      .no_pid
Line 1033... Line 1068...
1033
 
1068
 
1034
        mov     [dst_slot], eax
1069
        mov     [dst_slot], eax
1035
        shl     eax, 8
1070
        shl     eax, 8
1036
        mov     edi, [eax+SLOT_BASE+0xa0] ;is ipc area defined?
1071
        mov     edi, [eax+SLOT_BASE+APPDATA.ipc_start] ;is ipc area defined?
1037
        test    edi, edi
1072
        test    edi, edi
Line 1038... Line 1073...
1038
        jz      .no_ipc_area
1073
        jz      .no_ipc_area
1039
 
1074
 
1040
        mov     ebx, edi
1075
        mov     ebx, edi
Line 1041... Line 1076...
1041
        and     ebx, 0xFFF
1076
        and     ebx, 0xFFF
1042
        mov     [dst_offset], ebx
1077
        mov     [dst_offset], ebx
Line 1043... Line 1078...
1043
 
1078
 
1044
        mov     esi, [eax+SLOT_BASE+0xa4]
1079
        mov     esi, [eax+SLOT_BASE+APPDATA.ipc_size]
1045
        mov     [buf_size], esi
1080
        mov     [buf_size], esi
Line 1052... Line 1087...
1052
        stdcall alloc_kernel_space, esi
1087
        stdcall alloc_kernel_space, esi
1053
        mov     ecx, eax
1088
        mov     ecx, eax
1054
        pop     edi esi
1089
        pop     edi esi
1055
@@:
1090
@@:
1056
        mov     [used_buf], ecx
1091
        mov     [used_buf], ecx
1057
        stdcall map_mem, ecx, [dst_slot], \
1092
        stdcall map_mem_ipc, ecx, [dst_slot], \
1058
                edi, esi, PG_SW
1093
                edi, esi, PG_SW
Line 1059... Line 1094...
1059
 
1094
 
1060
        mov     edi, [dst_offset]
1095
        mov     edi, [dst_offset]
1061
        add     edi, [used_buf]
1096
        add     edi, [used_buf]
Line 1123... Line 1158...
1123
.buffer_overflow:
1158
.buffer_overflow:
1124
        push    3
1159
        push    3
1125
.ret:
1160
.ret:
1126
        mov     eax, [used_buf]
1161
        mov     eax, [used_buf]
1127
        cmp     eax, [ipc_tmp]
1162
        cmp     eax, [ipc_tmp]
1128
        jz      @f
1163
        je      @f
1129
        stdcall free_kernel_space, eax
1164
        stdcall free_kernel_space, eax
1130
@@:
1165
@@:
1131
        pop     eax
1166
        pop     eax
1132
        popf
1167
        popf
1133
        ret
1168
        ret
Line 1328... Line 1363...
1328
        pop     esi
1363
        pop     esi
1329
        ret
1364
        ret
1330
endp
1365
endp
Line 1331... Line 1366...
1331
 
1366
 
1332
align 4
-
 
1333
proc init_mtrr
-
 
1334
 
-
 
1335
        cmp     [BOOT_VARS+BOOT_MTRR], byte 2
-
 
1336
        je      .exit
-
 
1337
 
-
 
1338
        bt      [cpu_caps], CAPS_MTRR
-
 
1339
        jnc     .exit
-
 
1340
 
-
 
1341
        mov     eax, cr0
-
 
1342
        or      eax, 0x60000000 ;disable caching
-
 
1343
        mov     cr0, eax
-
 
1344
        wbinvd                  ;invalidate cache
-
 
1345
 
-
 
1346
        mov     ecx, 0x2FF
-
 
1347
        rdmsr                   ;
-
 
1348
; has BIOS already initialized MTRRs?
-
 
1349
        test    ah, 8
-
 
1350
        jnz     .skip_init
-
 
1351
; rarely needed, so mainly placeholder
-
 
1352
; main memory - cached
-
 
1353
        push    eax
-
 
1354
 
-
 
1355
        mov     eax, [MEM_AMOUNT]
-
 
1356
; round eax up to next power of 2
-
 
1357
        dec     eax
-
 
1358
        bsr     ecx, eax
-
 
1359
        mov     ebx, 2
-
 
1360
        shl     ebx, cl
-
 
1361
        dec     ebx
-
 
1362
; base of memory range = 0, type of memory range = MEM_WB
-
 
1363
        xor     edx, edx
-
 
1364
        mov     eax, MEM_WB
-
 
1365
        mov     ecx, 0x200
-
 
1366
        wrmsr
-
 
1367
; mask of memory range = 0xFFFFFFFFF - (size - 1), ebx = size - 1
-
 
1368
        mov     eax, 0xFFFFFFFF
-
 
1369
        mov     edx, 0x0000000F
-
 
1370
        sub     eax, ebx
-
 
1371
        sbb     edx, 0
-
 
1372
        or      eax, 0x800
-
 
1373
        inc     ecx
-
 
1374
        wrmsr
-
 
1375
; clear unused MTRRs
-
 
1376
        xor     eax, eax
-
 
1377
        xor     edx, edx
-
 
1378
@@:
-
 
1379
        inc     ecx
-
 
1380
        wrmsr
-
 
1381
        cmp     ecx, 0x20F
-
 
1382
        jb      @b
-
 
1383
; enable MTRRs
-
 
1384
        pop     eax
-
 
1385
        or      ah, 8
-
 
1386
        and     al, 0xF0; default memtype = UC
-
 
1387
        mov     ecx, 0x2FF
-
 
1388
        wrmsr
-
 
1389
.skip_init:
-
 
1390
        stdcall set_mtrr, [LFBAddress], [LFBSize], MEM_WC
-
 
1391
 
-
 
1392
        wbinvd                  ;again invalidate
-
 
1393
 
-
 
1394
        mov     eax, cr0
-
 
1395
        and     eax, not 0x60000000
-
 
1396
        mov     cr0, eax        ; enable caching
-
 
1397
.exit:
-
 
1398
        ret
-
 
1399
endp
-
 
1400
 
-
 
1401
align 4
-
 
1402
proc set_mtrr stdcall, base:dword,size:dword,mem_type:dword
-
 
1403
; find unused register
-
 
1404
        mov     ecx, 0x201
-
 
1405
@@:
-
 
1406
        rdmsr
-
 
1407
        dec     ecx
-
 
1408
        test    ah, 8
-
 
1409
        jz      .found
-
 
1410
        rdmsr
-
 
1411
        mov     al, 0; clear memory type field
-
 
1412
        cmp     eax, [base]
-
 
1413
        jz      .ret
-
 
1414
        add     ecx, 3
-
 
1415
        cmp     ecx, 0x210
-
 
1416
        jb      @b
-
 
1417
; no free registers, ignore the call
-
 
1418
.ret:
-
 
1419
        ret
-
 
1420
.found:
-
 
1421
; found, write values
-
 
1422
        xor     edx, edx
-
 
1423
        mov     eax, [base]
-
 
1424
        or      eax, [mem_type]
-
 
1425
        wrmsr
-
 
1426
 
-
 
1427
        mov     ebx, [size]
-
 
1428
        dec     ebx
-
 
1429
        mov     eax, 0xFFFFFFFF
-
 
1430
        mov     edx, 0x00000000
-
 
1431
        sub     eax, ebx
-
 
1432
        sbb     edx, 0
-
 
1433
        or      eax, 0x800
-
 
1434
        inc     ecx
-
 
1435
        wrmsr
-
 
1436
        ret
-
 
1437
endp
-
 
1438
 
-
 
1439
align 4
1367
align 4
1440
proc create_ring_buffer stdcall, size:dword, flags:dword
1368
proc create_ring_buffer stdcall, size:dword, flags:dword
1441
           locals
1369
           locals
1442
             buf_ptr  dd ?
1370
             buf_ptr  dd ?