Subversion Repositories Kolibri OS

Rev

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

Rev 1090 Rev 1103
Line 3... Line 3...
3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2008. 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: 1090 $
8
$Revision: 1103 $
9
 
9
 
10
 
10
 
Line 11... Line 11...
11
MEM_WB     equ 6               ;write-back memory
11
MEM_WB     equ 6               ;write-back memory
12
MEM_WC     equ 1               ;write combined memory
12
MEM_WC     equ 1               ;write combined memory
-
 
13
MEM_UC     equ 0               ;uncached memory
-
 
14
 
-
 
15
align 4
Line 13... Line 16...
13
MEM_UC     equ 0               ;uncached memory
16
proc mem_test
14
 
17
; if we have BIOS with fn E820, skip the test
15
align 4
18
           cmp dword [BOOT_VAR-OS_BASE + 0x9100], 0
16
proc mem_test
19
           jnz .ret
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
-
 
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
-
 
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
-
 
78
.overflow:
-
 
79
           mov eax, 0xFFFFF000
-
 
80
@@:
-
 
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
40
align 4
93
           loop .calcmax
41
proc init_mem
94
.calculated:
-
 
95
           mov [MEM_AMOUNT-OS_BASE], esi
-
 
96
           mov [pg_data.mem_amount-OS_BASE], esi
42
           mov eax, [MEM_AMOUNT-OS_BASE]
97
           shr esi, 12
43
           mov [pg_data.mem_amount-OS_BASE], eax
98
           mov [pg_data.pages_count-OS_BASE], esi
-
 
99
 
44
 
100
           shr edx, 12
45
           shr eax, 12
101
           add edx, 31
46
           mov [pg_data.pages_count-OS_BASE], eax
102
           and edx, not 31
47
           shr eax, 3
103
           shr edx, 3
48
           mov [pg_data.pagemap_size-OS_BASE], eax
104
           mov [pg_data.pagemap_size-OS_BASE], edx
49
 
105
 
50
           add eax, (sys_pgmap-OS_BASE)+4095
106
           add edx, (sys_pgmap-OS_BASE)+4095
Line 51... Line 107...
51
           and eax, not 4095
107
           and edx, not 4095
52
           mov [tmp_page_tabs], eax
108
           mov [tmp_page_tabs], edx
53
 
109
 
54
           mov edx, (((sys_pgmap-OS_BASE) + 0xFFFFFF) and not 0xFFFFFF) shr 12
110
           mov edx, (((sys_pgmap-OS_BASE) + 0xFFFFFF) and not 0xFFFFFF) shr 12
Line 119... Line 175...
119
           ret
175
           ret
120
endp
176
endp
Line 121... Line 177...
121
 
177
 
122
align 4
178
align 4
123
proc init_page_map
-
 
-
 
179
proc init_page_map
124
 
180
; mark all memory as unavailable
125
           mov edi, sys_pgmap-OS_BASE
181
           mov edi, sys_pgmap-OS_BASE
126
           mov ecx, [pg_data.pagemap_size-OS_BASE]
182
           mov ecx, [pg_data.pagemap_size-OS_BASE]
127
           shr ecx, 2
183
           shr ecx, 2
128
           or eax, -1
184
           xor eax, eax
129
           cld
185
           cld
Line -... Line 186...
-
 
186
           rep stosd
-
 
187
 
-
 
188
; scan through memory map and mark free areas as available
-
 
189
           mov ebx, BOOT_VAR-OS_BASE + 0x9104
-
 
190
           mov edx, [ebx-4]
-
 
191
.scanmap:
-
 
192
           mov ecx, [ebx+8]
-
 
193
           shr ecx, 12 ; ecx = number of pages
-
 
194
           jz .next
-
 
195
           mov edi, [ebx]
-
 
196
           shr edi, 12 ; edi = first page
-
 
197
           mov eax, edi
-
 
198
           neg eax
-
 
199
           shr edi, 5
-
 
200
           add edi, sys_pgmap-OS_BASE
-
 
201
           and eax, 31
-
 
202
           jz .startok
-
 
203
           sub ecx, eax
-
 
204
           jbe .onedword
-
 
205
           push ecx
-
 
206
           mov ecx, eax
-
 
207
           xor eax, eax
-
 
208
           inc eax
-
 
209
           shl eax, cl
-
 
210
           dec eax
-
 
211
           or [edi], eax
-
 
212
           add edi, 4
-
 
213
           pop ecx
-
 
214
.startok:
-
 
215
           push ecx
-
 
216
           shr ecx, 5
-
 
217
           or eax, -1
-
 
218
           rep stosd
-
 
219
           pop ecx
-
 
220
           and ecx, 31
-
 
221
           not eax
-
 
222
           shl eax, cl
-
 
223
           or [edi], eax
-
 
224
           jmp .next
-
 
225
.onedword:
-
 
226
           add ecx, eax
-
 
227
@@:
-
 
228
           dec eax
-
 
229
           bts [edi], eax
-
 
230
           loop @b
-
 
231
.next:
-
 
232
           add ebx, 20
-
 
233
           dec edx
-
 
234
           jnz .scanmap
130
           rep stosd
235
 
131
 
236
; mark kernel memory as allocated (unavailable)
132
           mov ecx, [tmp_page_tabs]
237
           mov ecx, [tmp_page_tabs]
133
           mov edx, [pg_data.pages_count-OS_BASE]
238
           mov edx, [pg_data.pages_count-OS_BASE]
134
           shr ecx, 12
239
           shr ecx, 12
Line 144... Line 249...
144
 
249
 
145
           not eax
250
           not eax
146
           mov ecx, ebx
251
           mov ecx, ebx
147
           and ecx, 31
252
           and ecx, 31
148
           shl eax, cl
253
           shl eax, cl
149
           mov [edi], eax
254
           and [edi], eax
150
           add edi, OS_BASE
255
           add edi, OS_BASE
Line 151... Line 256...
151
           mov [page_start-OS_BASE], edi;
256
           mov [page_start-OS_BASE], edi;
152
 
257