Rev 2594 | Rev 2647 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2594 | Rev 2595 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 2594 $ |
8 | $Revision: 2595 $ |
9 | 9 | ||
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 |
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 | ;//- |
21 | 21 | ||
22 | mov ebx, [page_start] |
22 | mov ebx, [page_start] |
23 | mov ecx, [page_end] |
23 | mov ecx, [page_end] |
24 | .l1: |
24 | .l1: |
25 | bsf eax, [ebx]; |
25 | bsf eax, [ebx]; |
26 | jnz .found |
26 | jnz .found |
27 | add ebx, 4 |
27 | add ebx, 4 |
28 | cmp ebx, ecx |
28 | cmp ebx, ecx |
29 | jb .l1 |
29 | jb .l1 |
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 |
57 | 57 | ||
58 | align 4 |
58 | align 4 |
59 | proc alloc_pages stdcall, count:dword |
59 | proc alloc_pages stdcall, count:dword |
60 | pushfd |
60 | pushfd |
61 | push ebx |
61 | push ebx |
62 | push edi |
62 | push edi |
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 |
81 | .match: |
81 | .match: |
82 | cmp byte [ecx], 0xFF |
82 | cmp byte [ecx], 0xFF |
83 | jne .next |
83 | jne .next |
84 | dec edx |
84 | dec edx |
85 | jz .ok |
85 | jz .ok |
86 | inc ecx |
86 | inc ecx |
87 | cmp ecx, ebx |
87 | cmp ecx, ebx |
88 | jb .match |
88 | jb .match |
89 | .out_of_memory: |
89 | .out_of_memory: |
90 | .fail: |
90 | .fail: |
91 | xor eax, eax |
91 | xor eax, eax |
92 | pop edi |
92 | pop edi |
93 | pop ebx |
93 | pop ebx |
94 | popfd |
94 | popfd |
95 | ret |
95 | ret |
96 | .next: |
96 | .next: |
97 | inc ecx |
97 | inc ecx |
98 | cmp ecx, ebx |
98 | cmp ecx, ebx |
99 | jb .find |
99 | jb .find |
100 | pop edi |
100 | pop edi |
101 | pop ebx |
101 | pop ebx |
102 | popfd |
102 | popfd |
103 | xor eax, eax |
103 | xor eax, eax |
104 | ret |
104 | ret |
105 | .ok: |
105 | .ok: |
106 | sub ecx, edi |
106 | sub ecx, edi |
107 | inc ecx |
107 | inc ecx |
108 | push esi |
108 | push esi |
109 | mov esi, edi |
109 | mov esi, edi |
110 | xor eax, eax |
110 | xor eax, eax |
111 | rep stosb |
111 | rep stosb |
112 | sub esi, sys_pgmap |
112 | sub esi, sys_pgmap |
113 | shl esi, 3+12 |
113 | shl esi, 3+12 |
114 | mov eax, esi |
114 | mov eax, esi |
115 | mov ebx, [count] |
115 | mov ebx, [count] |
116 | shl ebx, 3 |
116 | shl ebx, 3 |
117 | sub [pg_data.pages_free], ebx |
117 | sub [pg_data.pages_free], ebx |
118 | pop esi |
118 | pop esi |
119 | pop edi |
119 | pop edi |
120 | pop ebx |
120 | pop ebx |
121 | popfd |
121 | popfd |
122 | ret |
122 | ret |
123 | endp |
123 | endp |
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 | push ebx |
127 | push ebx |
128 | mov eax, [phis_addr] |
128 | mov eax, [phis_addr] |
129 | and eax, not 0xFFF |
129 | and eax, not 0xFFF |
130 | or eax, [flags] |
130 | or eax, [flags] |
131 | mov ebx, [lin_addr] |
131 | mov ebx, [lin_addr] |
132 | shr ebx, 12 |
132 | shr ebx, 12 |
133 | mov [page_tabs+ebx*4], eax |
133 | mov [page_tabs+ebx*4], eax |
134 | mov eax, [lin_addr] |
134 | mov eax, [lin_addr] |
135 | invlpg [eax] |
135 | invlpg [eax] |
136 | pop ebx |
136 | pop ebx |
137 | ret |
137 | ret |
138 | endp |
138 | endp |
139 | 139 | ||
140 | align 4 |
140 | align 4 |
141 | map_space: ;not implemented |
141 | map_space: ;not implemented |
142 | 142 | ||
143 | 143 | ||
144 | ret |
144 | ret |
145 | 145 | ||
146 | 146 | ||
147 | align 4 |
147 | align 4 |
148 | proc free_page |
148 | proc free_page |
149 | ;arg: eax page address |
149 | ;arg: eax page address |
150 | pushfd |
150 | pushfd |
151 | cli |
151 | cli |
152 | shr eax, 12 ;page index |
152 | shr eax, 12 ;page index |
153 | bts dword [sys_pgmap], eax ;that's all! |
153 | bts dword [sys_pgmap], eax ;that's all! |
154 | cmc |
154 | cmc |
155 | adc [pg_data.pages_free], 0 |
155 | adc [pg_data.pages_free], 0 |
156 | shr eax, 3 |
156 | shr eax, 3 |
157 | and eax, not 3 ;dword offset from page_map |
157 | and eax, not 3 ;dword offset from page_map |
158 | add eax, sys_pgmap |
158 | add eax, sys_pgmap |
159 | cmp [page_start], eax |
159 | cmp [page_start], eax |
160 | ja @f |
160 | ja @f |
161 | popfd |
161 | popfd |
162 | ret |
162 | ret |
163 | @@: |
163 | @@: |
164 | mov [page_start], eax |
164 | mov [page_start], eax |
165 | popfd |
165 | popfd |
166 | ret |
166 | ret |
167 | endp |
167 | endp |
168 | 168 | ||
169 | align 4 |
169 | align 4 |
170 | proc map_io_mem stdcall, base:dword, size:dword, flags:dword |
170 | proc map_io_mem stdcall, base:dword, size:dword, flags:dword |
171 | 171 | ||
172 | push ebx |
172 | push ebx |
173 | push edi |
173 | push edi |
174 | mov eax, [size] |
174 | mov eax, [size] |
175 | add eax, [base] |
175 | add eax, [base] |
176 | add eax, 4095 |
176 | add eax, 4095 |
177 | and eax, -4096 |
177 | and eax, -4096 |
178 | mov ecx, [base] |
178 | mov ecx, [base] |
179 | and ecx, -4096 |
179 | and ecx, -4096 |
180 | sub eax, ecx |
180 | sub eax, ecx |
181 | mov [size], eax |
181 | mov [size], eax |
182 | 182 | ||
183 | stdcall alloc_kernel_space, eax |
183 | stdcall alloc_kernel_space, eax |
184 | test eax, eax |
184 | test eax, eax |
185 | jz .fail |
185 | jz .fail |
186 | push eax |
186 | push eax |
187 | 187 | ||
188 | mov edi, 0x1000 |
188 | mov edi, 0x1000 |
189 | mov ebx, eax |
189 | mov ebx, eax |
190 | mov ecx, [size] |
190 | mov ecx, [size] |
191 | mov edx, [base] |
191 | mov edx, [base] |
192 | shr eax, 12 |
192 | shr eax, 12 |
193 | shr ecx, 12 |
193 | shr ecx, 12 |
194 | and edx, -4096 |
194 | and edx, -4096 |
195 | or edx, [flags] |
195 | or edx, [flags] |
196 | @@: |
196 | @@: |
197 | mov [page_tabs+eax*4], edx |
197 | mov [page_tabs+eax*4], edx |
198 | invlpg [ebx] |
198 | invlpg [ebx] |
199 | inc eax |
199 | inc eax |
200 | add ebx, edi |
200 | add ebx, edi |
201 | add edx, edi |
201 | add edx, edi |
202 | loop @B |
202 | loop @B |
203 | 203 | ||
204 | pop eax |
204 | pop eax |
205 | mov edx, [base] |
205 | mov edx, [base] |
206 | and edx, 4095 |
206 | and edx, 4095 |
207 | add eax, edx |
207 | add eax, edx |
208 | .fail: |
208 | .fail: |
209 | pop edi |
209 | pop edi |
210 | pop ebx |
210 | pop ebx |
211 | ret |
211 | ret |
212 | endp |
212 | endp |
213 | 213 | ||
214 | ; param |
214 | ; param |
215 | ; eax= page base + page flags |
215 | ; eax= page base + page flags |
216 | ; ebx= linear address |
216 | ; ebx= linear address |
217 | ; ecx= count |
217 | ; ecx= count |
218 | 218 | ||
219 | align 4 |
219 | align 4 |