Subversion Repositories Kolibri OS

Rev

Rev 9917 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
9715 Doczom 3
;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 10002 $
9
 
10
 
11
align 4
12
proc alloc_page
13
 
14
        pushfd
15
        cli
16
        push    ebx
8052 rgimad 17
 
2288 clevermous 18
        cmp     [pg_data.pages_free], 1
19
        jle     .out_of_memory
20
 
8052 rgimad 21
 
2288 clevermous 22
        mov     ebx, [page_start]
23
        mov     ecx, [page_end]
24
.l1:
25
        bsf     eax, [ebx];
26
        jnz     .found
27
        add     ebx, 4
28
        cmp     ebx, ecx
29
        jb      .l1
30
        pop     ebx
31
        popfd
32
        xor     eax, eax
33
        ret
34
.found:
8052 rgimad 35
 
2288 clevermous 36
        dec     [pg_data.pages_free]
37
        jz      .out_of_memory
8052 rgimad 38
 
2288 clevermous 39
        btr     [ebx], eax
40
        mov     [page_start], ebx
41
        sub     ebx, sys_pgmap
42
        lea     eax, [eax+ebx*8]
43
        shl     eax, 12
8052 rgimad 44
;       dec [pg_data.pages_free]
2288 clevermous 45
        pop     ebx
46
        popfd
47
        ret
8052 rgimad 48
 
2288 clevermous 49
.out_of_memory:
50
        mov     [pg_data.pages_free], 1
51
        xor     eax, eax
52
        pop     ebx
53
        popfd
54
        ret
8052 rgimad 55
 
2288 clevermous 56
endp
57
 
58
align 4
59
proc alloc_pages stdcall, count:dword
60
        pushfd
61
        push    ebx
62
        push    edi
63
        cli
64
        mov     eax, [count]
65
        add     eax, 7
66
        shr     eax, 3
67
        mov     [count], eax
8052 rgimad 68
 
2288 clevermous 69
        mov     ebx, [pg_data.pages_free]
70
        sub     ebx, 9
71
        js      .out_of_memory
72
        shr     ebx, 3
73
        cmp     eax, ebx
74
        jg      .out_of_memory
8052 rgimad 75
 
2288 clevermous 76
        mov     ecx, [page_start]
77
        mov     ebx, [page_end]
78
.find:
79
        mov     edx, [count]
80
        mov     edi, ecx
7967 hidnplayr 81
  .match:
2288 clevermous 82
        cmp     byte [ecx], 0xFF
83
        jne     .next
84
        dec     edx
85
        jz      .ok
86
        inc     ecx
87
        cmp     ecx, ebx
88
        jb      .match
7967 hidnplayr 89
  .out_of_memory:
90
  .fail:
2288 clevermous 91
        xor     eax, eax
92
        pop     edi
93
        pop     ebx
94
        popfd
95
        ret
7967 hidnplayr 96
  .next:
2288 clevermous 97
        inc     ecx
98
        cmp     ecx, ebx
99
        jb      .find
100
        pop     edi
101
        pop     ebx
102
        popfd
103
        xor     eax, eax
104
        ret
7967 hidnplayr 105
  .ok:
2288 clevermous 106
        sub     ecx, edi
107
        inc     ecx
108
        push    esi
109
        mov     esi, edi
110
        xor     eax, eax
111
        rep stosb
112
        sub     esi, sys_pgmap
113
        shl     esi, 3+12
114
        mov     eax, esi
115
        mov     ebx, [count]
116
        shl     ebx, 3
117
        sub     [pg_data.pages_free], ebx
118
        pop     esi
119
        pop     edi
120
        pop     ebx
121
        popfd
122
        ret
123
endp
124
 
125
align 4
4424 Serge 126
;proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword
127
map_page:
2288 clevermous 128
        push    ebx
5357 serge 129
        mov     eax, [esp+12]              ; phis_addr
4424 Serge 130
        or      eax, [esp+16]              ; flags
5357 serge 131
        and     eax, [pte_valid_mask]
4424 Serge 132
        mov     ebx, [esp+8]               ; lin_addr
2288 clevermous 133
        shr     ebx, 12
9715 Doczom 134
        mov     [page_tabs + ebx*4], eax
4424 Serge 135
        mov     eax, [esp+8]               ; lin_addr
136
        pop     ebx
2288 clevermous 137
        invlpg  [eax]
4424 Serge 138
        ret     12
2288 clevermous 139
 
140
align 4
141
map_space:    ;not implemented
142
 
143
 
144
        ret
145
 
146
 
147
align 4
148
proc free_page
149
;arg:  eax  page address
150
        pushfd
151
        cli
152
        shr     eax, 12                       ;page index
153
        bts     dword [sys_pgmap], eax        ;that's all!
154
        cmc
155
        adc     [pg_data.pages_free], 0
156
        shr     eax, 3
157
        and     eax, not 3                    ;dword offset from page_map
158
        add     eax, sys_pgmap
159
        cmp     [page_start], eax
160
        ja      @f
161
        popfd
162
        ret
163
@@:
164
        mov     [page_start], eax
165
        popfd
166
        ret
167
endp
168
 
2414 Serge 169
align 4
2288 clevermous 170
proc map_io_mem stdcall, base:dword, size:dword, flags:dword
171
 
172
        push    ebx
173
        push    edi
174
        mov     eax, [size]
175
        add     eax, [base]
9900 Doczom 176
        add     eax, PAGE_SIZE-1
177
        and     eax, -PAGE_SIZE
2288 clevermous 178
        mov     ecx, [base]
9900 Doczom 179
        and     ecx, -PAGE_SIZE
2288 clevermous 180
        sub     eax, ecx
181
        mov     [size], eax
182
 
183
        stdcall alloc_kernel_space, eax
184
        test    eax, eax
185
        jz      .fail
186
        push    eax
187
 
9900 Doczom 188
        mov     edi, PAGE_SIZE
2288 clevermous 189
        mov     ebx, eax
190
        mov     ecx, [size]
191
        mov     edx, [base]
192
        shr     eax, 12
193
        shr     ecx, 12
194
        or      edx, [flags]
5357 serge 195
        and     edx, [pte_valid_mask]
2288 clevermous 196
@@:
9715 Doczom 197
        mov     [page_tabs + eax*4], edx
2288 clevermous 198
        invlpg  [ebx]
199
        inc     eax
200
        add     ebx, edi
201
        add     edx, edi
202
        loop    @B
203
 
204
        pop     eax
205
        mov     edx, [base]
9900 Doczom 206
        and     edx, PAGE_SIZE-1
2288 clevermous 207
        add     eax, edx
208
.fail:
209
        pop     edi
210
        pop     ebx
211
        ret
212
endp
213
 
214
; param
215
;  eax= page base + page flags
216
;  ebx= linear address
217
;  ecx= count
218
 
219
align 4
220
commit_pages:
221
        test    ecx, ecx
222
        jz      .fail
223
 
224
        push    edi
225
        push    eax
226
        push    ecx
227
        mov     ecx, pg_data.mutex
228
        call    mutex_lock
229
        pop     ecx
230
        pop     eax
231
 
5357 serge 232
        and     eax, [pte_valid_mask ]
2288 clevermous 233