Rev 1161 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1161 | Rev 1198 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | MEM_WC equ 1 ;write combined memory |
12 | MEM_WC equ 1 ;write combined memory |
13 | MEM_UC equ 0 ;uncached memory |
13 | MEM_UC equ 0 ;uncached memory |
Line 14... | Line 14... | ||
14 | 14 | ||
15 | align 4 |
15 | align 4 |
- | 16 | proc mem_test |
|
- | 17 | ; if we have BIOS with fn E820, skip the test |
|
- | 18 | cmp dword [BOOT_VAR-OS_BASE + 0x9100], 0 |
|
Line 16... | Line 19... | ||
16 | proc mem_test |
19 | jnz .ret |
17 | 20 | ||
18 | mov eax, cr0 |
21 | mov eax, cr0 |
19 | and eax, not (CR0_CD+CR0_NW) |
22 | and eax, not (CR0_CD+CR0_NW) |
Line 27... | Line 30... | ||
27 | add edi, 0x100000 |
30 | add edi, 0x100000 |
28 | xchg ebx, dword [edi] |
31 | xchg ebx, dword [edi] |
29 | cmp dword [edi], 'TEST' |
32 | cmp dword [edi], 'TEST' |
30 | xchg ebx, dword [edi] |
33 | xchg ebx, dword [edi] |
31 | je @b |
34 | je @b |
32 | mov [MEM_AMOUNT-OS_BASE], edi |
- | |
Line 33... | Line 35... | ||
33 | 35 | ||
34 | and eax, not (CR0_CD+CR0_NW) ;enable caching |
36 | and eax, not (CR0_CD+CR0_NW) ;enable caching |
- | 37 | mov cr0, eax |
|
35 | mov cr0, eax |
38 | inc dword [BOOT_VAR-OS_BASE + 0x9100] |
- | 39 | xor eax, eax |
|
- | 40 | mov [BOOT_VAR-OS_BASE + 0x9104], eax |
|
- | 41 | mov [BOOT_VAR-OS_BASE + 0x9108], eax |
|
- | 42 | mov [BOOT_VAR-OS_BASE + 0x910C], edi |
|
- | 43 | mov [BOOT_VAR-OS_BASE + 0x9110], eax |
|
36 | mov eax, edi |
44 | .ret: |
37 | ret |
45 | ret |
Line 38... | Line 46... | ||
38 | endp |
46 | endp |
39 | 47 | ||
- | 48 | align 4 |
|
40 | align 4 |
49 | proc init_mem |
- | 50 | ; calculate maximum allocatable address and number of allocatable pages |
|
- | 51 | mov edi, BOOT_VAR-OS_BASE + 0x9104 |
|
- | 52 | mov ecx, [edi-4] |
|
- | 53 | xor esi, esi ; esi will hold total amount of memory |
|
- | 54 | xor edx, edx ; edx will hold maximum allocatable address |
|
- | 55 | .calcmax: |
|
- | 56 | ; round all to pages |
|
- | 57 | mov eax, [edi] |
|
- | 58 | test eax, 0xFFF |
|
- | 59 | jz @f |
|
- | 60 | neg eax |
|
- | 61 | and eax, 0xFFF |
|
41 | proc init_mem |
62 | add [edi], eax |
- | 63 | adc dword [edi+4], 0 |
|
- | 64 | sub [edi+8], eax |
|
- | 65 | sbb dword [edi+12], 0 |
|
- | 66 | jc .unusable |
|
- | 67 | @@: |
|
- | 68 | and dword [edi+8], not 0xFFF |
|
- | 69 | jz .unusable |
|
- | 70 | ; ignore memory after 4 Gb |
|
- | 71 | cmp dword [edi+4], 0 |
|
- | 72 | jnz .unusable |
|
- | 73 | mov eax, [edi] |
|
- | 74 | cmp dword [edi+12], 0 |
|
- | 75 | jnz .overflow |
|
- | 76 | add eax, [edi+8] |
|
- | 77 | jnc @f |
|
42 | mov eax, [MEM_AMOUNT-OS_BASE] |
78 | .overflow: |
43 | mov [pg_data.mem_amount-OS_BASE], eax |
79 | mov eax, 0xFFFFF000 |
- | 80 | @@: |
|
44 | 81 | cmp edx, eax |
|
- | 82 | jae @f |
|
- | 83 | mov edx, eax |
|
- | 84 | @@: |
|
- | 85 | sub eax, [edi] |
|
- | 86 | mov [edi+8], eax |
|
- | 87 | add esi, eax |
|
- | 88 | jmp .usable |
|
- | 89 | .unusable: |
|
- | 90 | and dword [edi+8], 0 |
|
- | 91 | .usable: |
|
- | 92 | add edi, 20 |
|
- | 93 | loop .calcmax |
|
- | 94 | .calculated: |
|
- | 95 | mov [MEM_AMOUNT-OS_BASE], esi |
|
45 | shr eax, 12 |
96 | mov [pg_data.mem_amount-OS_BASE], esi |
- | 97 | shr esi, 12 |
|
- | 98 | mov [pg_data.pages_count-OS_BASE], esi |
|
- | 99 | ||
- | 100 | shr edx, 12 |
|
46 | mov edx, eax |
101 | add edx, 31 |
47 | mov [pg_data.pages_count-OS_BASE], eax |
102 | and edx, not 31 |
48 | shr eax, 3 |
103 | shr edx, 3 |
49 | mov [pg_data.pagemap_size-OS_BASE], eax |
104 | mov [pg_data.pagemap_size-OS_BASE], edx |
50 | 105 | ||
51 | add eax, (sys_pgmap-OS_BASE)+4095 |
106 | add edx, (sys_pgmap-OS_BASE)+4095 |
Line -... | Line 107... | ||
- | 107 | and edx, not 4095 |
|
- | 108 | mov [tmp_page_tabs], edx |
|
52 | and eax, not 4095 |
109 | |
53 | mov [tmp_page_tabs], eax |
110 | mov edx, esi |
54 | 111 | and edx, -1024 |
|
55 | cmp edx, (OS_BASE/4096) |
112 | cmp edx, (OS_BASE/4096) |
56 | jbe @F |
113 | jbe @F |
57 | mov edx, (OS_BASE/4096) |
114 | mov edx, (OS_BASE/4096) |
58 | jmp .set |
115 | jmp .set |
59 | @@: |
116 | @@: |
60 | cmp edx, (HEAP_MIN_SIZE/4096) |
117 | cmp edx, (HEAP_BASE+HEAP_MIN_SIZE)/4096 |
61 | jae .set |
118 | jae .set |
62 | mov edx, (HEAP_MIN_SIZE/4096) |
119 | mov edx, (HEAP_BASE+HEAP_MIN_SIZE)/4096 |
63 | .set: |
120 | .set: |
Line 128... | Line 185... | ||
128 | ret |
185 | ret |
129 | endp |
186 | endp |
Line 130... | Line 187... | ||
130 | 187 | ||
131 | align 4 |
188 | align 4 |
132 | proc init_page_map |
- | |
- | 189 | proc init_page_map |
|
133 | 190 | ; mark all memory as unavailable |
|
134 | mov edi, sys_pgmap-OS_BASE |
191 | mov edi, sys_pgmap-OS_BASE |
135 | mov ecx, [pg_data.pagemap_size-OS_BASE] |
192 | mov ecx, [pg_data.pagemap_size-OS_BASE] |
136 | shr ecx, 2 |
193 | shr ecx, 2 |
137 | or eax, -1 |
194 | xor eax, eax |
138 | cld |
195 | cld |
Line -... | Line 196... | ||
- | 196 | rep stosd |
|
- | 197 | ||
- | 198 | ; scan through memory map and mark free areas as available |
|
- | 199 | mov ebx, BOOT_VAR-OS_BASE + 0x9104 |
|
- | 200 | mov edx, [ebx-4] |
|
- | 201 | .scanmap: |
|
- | 202 | mov ecx, [ebx+8] |
|
- | 203 | shr ecx, 12 ; ecx = number of pages |
|
- | 204 | jz .next |
|
- | 205 | mov edi, [ebx] |
|
- | 206 | shr edi, 12 ; edi = first page |
|
- | 207 | mov eax, edi |
|
- | 208 | neg eax |
|
- | 209 | shr edi, 5 |
|
- | 210 | add edi, sys_pgmap-OS_BASE |
|
- | 211 | and eax, 31 |
|
- | 212 | jz .startok |
|
- | 213 | sub ecx, eax |
|
- | 214 | jbe .onedword |
|
- | 215 | push ecx |
|
- | 216 | mov ecx, eax |
|
- | 217 | xor eax, eax |
|
- | 218 | inc eax |
|
- | 219 | shl eax, cl |
|
- | 220 | dec eax |
|
- | 221 | or [edi], eax |
|
- | 222 | add edi, 4 |
|
- | 223 | pop ecx |
|
- | 224 | .startok: |
|
- | 225 | push ecx |
|
- | 226 | shr ecx, 5 |
|
- | 227 | or eax, -1 |
|
- | 228 | rep stosd |
|
- | 229 | pop ecx |
|
- | 230 | and ecx, 31 |
|
- | 231 | not eax |
|
- | 232 | shl eax, cl |
|
- | 233 | or [edi], eax |
|
- | 234 | jmp .next |
|
- | 235 | .onedword: |
|
- | 236 | add ecx, eax |
|
- | 237 | @@: |
|
- | 238 | dec eax |
|
- | 239 | bts [edi], eax |
|
- | 240 | loop @b |
|
- | 241 | .next: |
|
- | 242 | add ebx, 20 |
|
- | 243 | dec edx |
|
- | 244 | jnz .scanmap |
|
139 | rep stosd |
245 | |
140 | 246 | ; mark kernel memory as allocated (unavailable) |
|
141 | mov ecx, [tmp_page_tabs] |
247 | mov ecx, [tmp_page_tabs] |
142 | mov edx, [pg_data.pages_count-OS_BASE] |
248 | mov edx, [pg_data.pages_count-OS_BASE] |
143 | shr ecx, 12 |
249 | shr ecx, 12 |
Line 153... | Line 259... | ||
153 | 259 | ||
154 | not eax |
260 | not eax |
155 | mov ecx, ebx |
261 | mov ecx, ebx |
156 | and ecx, 31 |
262 | and ecx, 31 |
157 | shl eax, cl |
263 | shl eax, cl |
158 | mov [edi], eax |
264 | and [edi], eax |
159 | add edi, OS_BASE |
265 | add edi, OS_BASE |
Line 160... | Line 266... | ||
160 | mov [page_start-OS_BASE], edi; |
266 | mov [page_start-OS_BASE], edi; |
161 | 267 |