Subversion Repositories Kolibri OS

Rev

Rev 837 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
750 victor 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
593 mikedld 7
 
465 serge 8
$Revision: 838 $
9
 
593 mikedld 10
 
465 serge 11
MEM_WB     equ 6               ;write-back memory
12
MEM_WC     equ 1               ;write combined memory
13
MEM_UC     equ 0               ;uncached memory
14
 
15
 
16
align 4
17
proc init_mem
837 serge 18
 
19
           mov ecx, [0x2F0000 + 0x9100]
838 serge 20
           mov esi, 0x2F0000 + 0x9104
837 serge 21
           xor eax, eax
22
@@:
23
           cmp dword [esi+16], 1
24
           jne .next
25
           mov edx, [esi+8]
26
           cmp eax, [esi+8]
27
           ja .next
28
 
29
           mov eax, [esi+8]
30
.next:
31
           add esi, 20
32
           loop @B
33
 
838 serge 34
           and eax, -4096
35
 
837 serge 36
           mov [MEM_AMOUNT-OS_BASE], eax
465 serge 37
           mov [pg_data.mem_amount-OS_BASE], eax
38
 
39
           shr eax, 12
40
           mov edx, eax
41
           mov [pg_data.pages_count-OS_BASE], eax
42
           shr eax, 3
43
           mov [pg_data.pagemap_size-OS_BASE], eax
44
 
513 serge 45
           add eax, (sys_pgmap-OS_BASE)+4095
46
           and eax, not 4095
47
           mov [tmp_page_tabs], eax
48
 
465 serge 49
           cmp edx, (OS_BASE/4096)
50
           jbe @F
51
           mov edx, (OS_BASE/4096)
52
           jmp .set
53
@@:
54
           cmp edx, (HEAP_MIN_SIZE/4096)
55
           jae .set
56
           mov edx, (HEAP_MIN_SIZE/4096)
57
.set:
58
           mov [pg_data.kernel_pages-OS_BASE], edx
59
           shr edx, 10
60
           mov [pg_data.kernel_tables-OS_BASE], edx
61
 
62
           xor eax, eax
63
           mov edi, sys_pgdir-OS_BASE
64
           mov ecx, 4096/4
65
           cld
66
           rep stosd
67
 
837 serge 68
           mov edx, (sys_pgdir-OS_BASE)+ (OS_BASE shr 20)
465 serge 69
           bt [cpu_caps-OS_BASE], CAPS_PSE
70
           jnc .no_PSE
71
 
72
           mov ebx, cr4
73
           or ebx, CR4_PSE
74
           mov eax, PG_LARGE+PG_SW
75
           mov cr4, ebx
513 serge 76
           dec [pg_data.kernel_tables-OS_BASE]
465 serge 77
 
78
           mov [edx], eax
79
           add eax, 0x00400000
80
           add edx, 4
81
 
82
           mov eax, 0x400000+PG_SW
513 serge 83
           mov ecx, [tmp_page_tabs]
84
           sub ecx, 0x400000
85
           shr ecx, 12          ;ecx/=4096
465 serge 86
           jmp .map_low
87
.no_PSE:
88
           mov eax, PG_SW
513 serge 89
           mov ecx, [tmp_page_tabs]
90
           shr ecx, 12
465 serge 91
.map_low:
513 serge 92
           mov edi, [tmp_page_tabs]
465 serge 93
@@:                                   ;
94
           stosd
95
           add eax, 0x1000
96
           dec ecx
97
           jnz @B
98
 
99
           mov ecx, [pg_data.kernel_tables-OS_BASE]
100
           shl ecx, 10
101
           xor eax, eax
102
           rep stosd
103
 
104
           mov ecx, [pg_data.kernel_tables-OS_BASE]
513 serge 105
           mov eax, [tmp_page_tabs]
106
           or eax, PG_SW
465 serge 107
           mov edi, edx
108
 
109
.map_kernel_tabs:
110
 
111
           stosd
112
           add eax, 0x1000
113
           dec ecx
114
           jnz .map_kernel_tabs
115
 
116
           mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
117
 
118
           mov edi, (sys_pgdir-OS_BASE)
119
           lea esi, [edi+(OS_BASE shr 20)]
519 serge 120
           movsd
121
           movsd
465 serge 122
           ret
123
endp
124
 
125
align 4
126
proc init_page_map
127
 
128
           mov edi, sys_pgmap-OS_BASE
129
           mov ecx, [pg_data.pagemap_size-OS_BASE]
130
           shr ecx, 2
513 serge 131
           or eax, -1
132
           cld
465 serge 133
           rep stosd
134
 
513 serge 135
           mov ecx, [tmp_page_tabs]
465 serge 136
           mov edx, [pg_data.pages_count-OS_BASE]
513 serge 137
           shr ecx, 12
138
           add ecx, [pg_data.kernel_tables-OS_BASE]
465 serge 139
           sub edx, ecx
140
           mov [pg_data.pages_free-OS_BASE], edx
141
 
513 serge 142
           mov edi, sys_pgmap-OS_BASE
465 serge 143
           mov ebx, ecx
144
           shr ecx, 5
513 serge 145
           xor eax, eax
465 serge 146
           rep stosd
147
 
148
           not eax
149
           mov ecx, ebx
150
           and ecx, 31
151
           shl eax, cl
152
           mov [edi], eax
153
           add edi, OS_BASE
154
           mov [page_start-OS_BASE], edi;
155
 
156
           mov ebx, sys_pgmap
157
           add ebx, [pg_data.pagemap_size-OS_BASE]
158
           mov [page_end-OS_BASE], ebx
159
 
160
           mov [pg_data.pg_mutex-OS_BASE], 0
161
           ret
162
endp
163
 
164
align 4
586 serge 165
 
166
init_BIOS32:
167
           mov edi, 0xE0000
168
.pcibios_nxt:
169
           cmp dword[edi], '_32_' ; "magic" word
170
           je .BIOS32_found
171
.pcibios_nxt2:
172
           add edi, 0x10
173
           cmp edi, 0xFFFF0
174
           je .BIOS32_not_found
175
           jmp .pcibios_nxt
176
.BIOS32_found:			; magic word found, check control summ
177
 
178
           movzx ecx, byte[edi + 9]
179
           shl ecx, 4
180
           mov esi, edi
181
           xor eax, eax
182
           cld   ; paranoia
183
@@:	lodsb
184
           add ah, al
185
           loop @b
186
           jnz .pcibios_nxt2 ; control summ must be zero
187
    ; BIOS32 service found !
188
           mov ebp, [edi + 4]
189
           mov [bios32_entry], ebp
190
    ; check PCI BIOS present
191
           mov eax, '$PCI'
192
           xor ebx, ebx
193
           push cs  ; special for 'ret far' from  BIOS
194
           call ebp
195
           test al, al
196
           jnz .PCI_BIOS32_not_found
197
 
198
 ; здесь создаются дискрипторы для PCI BIOS
199
 
200
           add ebx, OS_BASE
201
           dec ecx
202
           mov [(pci_code_32-OS_BASE)], cx    ;limit 0-15
203
           mov [(pci_data_32-OS_BASE)], cx    ;limit 0-15
204
 
205
           mov [(pci_code_32-OS_BASE)+2], bx  ;base  0-15
206
           mov [(pci_data_32-OS_BASE)+2], bx  ;base  0-15
207
 
208
           shr ebx, 16
209
           mov [(pci_code_32-OS_BASE)+4], bl  ;base  16-23
210
           mov [(pci_data_32-OS_BASE)+4], bl  ;base  16-23
211
 
212
           shr ecx, 16
213
           and cl, 0x0F
214
           mov ch, bh
215
           add cx, D32
216
           mov [(pci_code_32-OS_BASE)+6], cx  ;lim   16-19 &
217
           mov [(pci_data_32-OS_BASE)+6], cx  ;base  24-31
218
 
219
           mov [(pci_bios_entry-OS_BASE)], edx
220
         ; jmp .end
221
.PCI_BIOS32_not_found:
222
	; здесь должна заполнятся pci_emu_dat
223
.BIOS32_not_found:
224
.end:
837 serge 225
           ret
586 serge 226
 
227
align 4
465 serge 228
proc test_cpu
229
           locals
230
              cpu_type   dd ?
231
              cpu_id     dd ?
232
              cpu_Intel  dd ?
233
              cpu_AMD    dd ?
234
           endl
235
 
236
           mov [cpu_type], 0
237
           xor eax, eax
238
           mov [cpu_caps-OS_BASE], eax
239
           mov [cpu_caps+4-OS_BASE], eax
240
 
241
           pushfd
242
           pop eax
243
           mov ecx, eax
244
           xor eax, 0x40000
245
           push eax
246
           popfd
247
           pushfd
248
           pop eax
249
           xor eax, ecx
250
           mov [cpu_type], CPU_386
251
           jz .end_cpuid
252
           push ecx
253
           popfd
254
 
255
           mov [cpu_type], CPU_486
256
           mov eax, ecx
257
           xor eax, 0x200000
258
           push eax
259
           popfd
260
           pushfd
261
           pop eax
262
           xor eax, ecx
263
           je .end_cpuid
264
           mov [cpu_id], 1
265
 
266
           xor eax, eax
267
           cpuid
268
 
269
           mov [cpu_vendor-OS_BASE], ebx
270
           mov [cpu_vendor+4-OS_BASE], edx
271
           mov [cpu_vendor+8-OS_BASE], ecx
272
           cmp ebx, dword [intel_str-OS_BASE]
273
           jne .check_AMD
274
           cmp edx, dword [intel_str+4-OS_BASE]
275
           jne .check_AMD
276
           cmp ecx, dword [intel_str+8-OS_BASE]
277
           jne .check_AMD
278
           mov [cpu_Intel], 1
279
           cmp eax, 1
280
           jl .end_cpuid
281
           mov eax, 1
282
           cpuid
283
           mov [cpu_sign-OS_BASE], eax
284
           mov [cpu_info-OS_BASE],  ebx
285
           mov [cpu_caps-OS_BASE],  edx
286
           mov [cpu_caps+4-OS_BASE],ecx
287
 
288
           shr eax, 8
289
           and eax, 0x0f
290
           ret
291
.end_cpuid:
292
           mov eax, [cpu_type]
293
           ret
294
 
295
.check_AMD:
296
           cmp ebx, dword [AMD_str-OS_BASE]
297
           jne .unknown
298
           cmp edx, dword [AMD_str+4-OS_BASE]
299
           jne .unknown
300
           cmp ecx, dword [AMD_str+8-OS_BASE]
301
           jne .unknown
302
           mov [cpu_AMD], 1
303
           cmp eax, 1
304
           jl .unknown
305
           mov eax, 1
306
           cpuid
307
           mov [cpu_sign-OS_BASE], eax
308
           mov [cpu_info-OS_BASE],  ebx
309
           mov [cpu_caps-OS_BASE],  edx
310
           mov [cpu_caps+4-OS_BASE],ecx
311
           shr eax, 8
312
           and eax, 0x0f
313
           ret
314
.unknown:
315
           mov eax, 1
316
           cpuid
317
           mov [cpu_sign-OS_BASE], eax
318
           mov [cpu_info-OS_BASE],  ebx
319
           mov [cpu_caps-OS_BASE],  edx
320
           mov [cpu_caps+4-OS_BASE],ecx
321
           shr eax, 8
322
           and eax, 0x0f
323
           ret
324
endp
325