Subversion Repositories Kolibri OS

Rev

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

Rev 7967 Rev 8052
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2020. 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: 7967 $
8
$Revision: 8052 $
9
 
9
 
Line 10... Line 10...
10
 
10
 
11
align 4
11
align 4
12
proc alloc_page
12
proc alloc_page
13
 
13
 
14
        pushfd
14
        pushfd
15
        cli
15
        cli
16
        push    ebx
16
        push    ebx
Line 17... Line 17...
17
;//-
17
 
18
        cmp     [pg_data.pages_free], 1
18
        cmp     [pg_data.pages_free], 1
19
        jle     .out_of_memory
19
        jle     .out_of_memory
20
;//-
20
 
Line 30... Line 30...
30
        pop     ebx
30
        pop     ebx
31
        popfd
31
        popfd
32
        xor     eax, eax
32
        xor     eax, eax
33
        ret
33
        ret
34
.found:
34
.found:
35
;//-
35
 
36
        dec     [pg_data.pages_free]
36
        dec     [pg_data.pages_free]
37
        jz      .out_of_memory
37
        jz      .out_of_memory
38
;//-
38
 
39
        btr     [ebx], eax
39
        btr     [ebx], eax
40
        mov     [page_start], ebx
40
        mov     [page_start], ebx
41
        sub     ebx, sys_pgmap
41
        sub     ebx, sys_pgmap
42
        lea     eax, [eax+ebx*8]
42
        lea     eax, [eax+ebx*8]
43
        shl     eax, 12
43
        shl     eax, 12
44
;//-       dec [pg_data.pages_free]
44
;       dec [pg_data.pages_free]
45
        pop     ebx
45
        pop     ebx
46
        popfd
46
        popfd
47
        ret
47
        ret
48
;//-
48
 
49
.out_of_memory:
49
.out_of_memory:
50
        mov     [pg_data.pages_free], 1
50
        mov     [pg_data.pages_free], 1
51
        xor     eax, eax
51
        xor     eax, eax
52
        pop     ebx
52
        pop     ebx
53
        popfd
53
        popfd
54
        ret
54
        ret
55
;//-
55
 
56
endp
56
endp
Line 57... Line 57...
57
 
57
 
58
align 4
58
align 4
59
proc alloc_pages stdcall, count:dword
59
proc alloc_pages stdcall, count:dword
Line 63... Line 63...
63
        cli
63
        cli
64
        mov     eax, [count]
64
        mov     eax, [count]
65
        add     eax, 7
65
        add     eax, 7
66
        shr     eax, 3
66
        shr     eax, 3
67
        mov     [count], eax
67
        mov     [count], eax
68
;//-
68
 
69
        mov     ebx, [pg_data.pages_free]
69
        mov     ebx, [pg_data.pages_free]
70
        sub     ebx, 9
70
        sub     ebx, 9
71
        js      .out_of_memory
71
        js      .out_of_memory
72
        shr     ebx, 3
72
        shr     ebx, 3
73
        cmp     eax, ebx
73
        cmp     eax, ebx
74
        jg      .out_of_memory
74
        jg      .out_of_memory
75
;//-
75
 
76
        mov     ecx, [page_start]
76
        mov     ecx, [page_start]
77
        mov     ebx, [page_end]
77
        mov     ebx, [page_end]
78
.find:
78
.find:
79
        mov     edx, [count]
79
        mov     edx, [count]
80
        mov     edi, ecx
80
        mov     edi, ecx
Line 536... Line 536...
536
 
536
 
537
; param
537
; param
538
;  eax= linear address
538
;  eax= linear address
539
;
539
;
540
; retval
540
; retval
Line 541... Line 541...
541
;  eax= phisical page address
541
;  eax= physical page address
542
 
542
 
543
align 4
543
align 4
544
get_pg_addr:
544
get_pg_addr:
Line 565... Line 565...
565
        inc     [pg_data.pages_faults]
565
        inc     [pg_data.pages_faults]
Line 566... Line 566...
566
 
566
 
Line 567... Line 567...
567
        mov     eax, [pf_err_code]
567
        mov     eax, [pf_err_code]
568
 
568
 
Line 569... Line 569...
569
        cmp     ebx, OS_BASE      ;ebx == .err_addr
569
        cmp     ebx, OS_BASE      ;ebx == .err_addr
570
        jb      .user_space       ;страница в памяти приложения ;
570
        jb      .user_space       ;page in application memory
Line 571... Line 571...
571
 
571
 
572
        cmp     ebx, page_tabs
572
        cmp     ebx, page_tabs
573
        jb      .kernel_space     ;страница в памяти ядра
573
        jb      .kernel_space     ;page in kernel memory
574
 
574
 
575
        cmp     ebx, kernel_tabs
575
        cmp     ebx, kernel_tabs
576
        jb      .alloc;.app_tabs  ;таблицы страниц приложения ;
576
        jb      .alloc;.app_tabs  ;page tables of application ;
577
                                  ;просто создадим одну
577
                                  ;simply create one
578
.core_tabs:
578
.core_tabs:
Line 579... Line 579...
579
.fail:  ;simply return to caller
579
.fail:  ;simply return to caller
580
        mov     esp, ebp
580
        mov     esp, ebp
581
        pop     ebx               ;restore exception number (#PF)
581
        pop     ebx               ;restore exception number (#PF)
582
        ret
582
        ret
Line 583... Line 583...
583
 
583
 
584
.user_space:
584
.user_space:
585
        test    eax, PG_READ
585
        test    eax, PG_READ
586
        jnz     .err_access       ;Страница присутствует
586
        jnz     .err_access       ;Page presents
587
                                  ;Ошибка доступа ?
587
                                  ;Access error ?
588
 
588
 
589
        shr     ebx, 12
589
        shr     ebx, 12
Line 590... Line 590...
590
        mov     ecx, ebx
590
        mov     ecx, ebx
591
        shr     ecx, 10
591
        shr     ecx, 10
592
        mov     edx, [master_tab+ecx*4]
-
 
593
        test    edx, PG_READ
592
        mov     edx, [master_tab+ecx*4]
-
 
593
        test    edx, PG_READ
594
        jz      .fail             ;таблица страниц не создана
594
        jz      .fail             ;page table is not created
595
                                  ;неверный адрес в программе
595
                                  ;incorrect address in program
596
 
596
 
597
        mov     eax, [page_tabs+ebx*4]
597
        mov     eax, [page_tabs+ebx*4]
Line 650... Line 650...
650
        rep movsd
650
        rep movsd
651
        jmp     .exit
651
        jmp     .exit
Line 652... Line 652...
652
 
652
 
653
.kernel_space:
653
.kernel_space:
654
        test    eax, PG_READ
654
        test    eax, PG_READ
Line 655... Line 655...
655
        jz      .fail   ;страница не присутствует
655
        jz      .fail   ;page does not present
656
 
656
 
657
        test    eax, 12 ;U/S (+below)
-
 
-
 
657
        test    eax, 12 ;U/S (+below)
658
        jnz     .fail   ;приложение обратилось к памяти
658
        jnz     .fail   ;application requested kernel memory
659
                        ;ядра
659
                        
660
       ;test    eax, 8
-
 
-
 
660
       ;test    eax, 8
Line 661... Line 661...
661
       ;jnz     .fail   ;установлен зарезервированный бит
661
       ;jnz     .fail   ;the reserved bit is set in page tables. Added in P4/Xeon
Line 662... Line 662...
662
                        ;в таблицах страниц. добавлено в P4/Xeon
662
                        
663
 
663
 
Line 664... Line 664...
664
;попытка записи в защищённую страницу ядра
664
;an attempt to write to a protected kernel page