Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
750 victor 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
983 diamond 3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
750 victor 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
593 mikedld 7
 
465 serge 8
$Revision: 2425 $
9
 
593 mikedld 10
 
1683 art_zh 11
MEM_WB	   equ 6	       ;write-back memory
12
MEM_WC	   equ 1	       ;write combined memory
13
MEM_UC	   equ 0	       ;uncached memory
465 serge 14
 
1683 art_zh 15
; ======================================================================
16
align 4
17
preinit_mem:
465 serge 18
 
1952 art_zh 19
; clear [CLEAN_ZONE..HEAP_BASE]
1683 art_zh 20
	   xor	 eax,eax
2047 art_zh 21
	   mov	 edi,CLEAN_ZONE 		; 0x280000 = ramdisk FAT ?
1941 art_zh 22
	   mov	 ecx,(HEAP_BASE-OS_BASE-CLEAN_ZONE) / 4
1683 art_zh 23
	   cld
24
	   rep	 stosd
25
 
26
; clear [0x40000..0x90000]
27
	   mov	 edi,0x50000			; 0x50000 is somewhere inside kernel code?
28
	   mov	 ecx,(0x90000-0x50000)/4
29
	   rep	 stosd
30
 
31
; clear undefined kernel globals
32
	   mov	 edi, endofcode-OS_BASE
33
	   mov	 ecx, (uglobals_size/4)+4
34
	   rep	 stosd
35
 
36
; save [0..0xffff]
37
	   xor	 esi, esi
2047 art_zh 38
	   mov	 edi, (BOOT_VAR - OS_BASE)		; low mem storage area
1683 art_zh 39
	   mov	 ecx, 0x10000 / 4
40
	   rep	 movsd
41
; clear [0x1000..0x0ffff]
42
	   mov	 edi,0x1000
43
	   mov	 ecx,0xf000 / 4
44
	   rep	 stosd
45
 
46
; clear  table
47
	   mov edi, sys_pgdir-OS_BASE
48
	   mov ecx, 4096/4
49
	   rep stosd
50
	ret
51
 
52
; ======================================================================
465 serge 53
align 4
54
 
2425 art_zh 55
init_mem:
2047 art_zh 56
	   mov	ecx, 0xC001001A 			; Top of Memory MSR
57
	   xor	edi, edi
58
	   rdmsr
59
	   mov	esi, eax				; esi = total amount of memory
60
	   mov	ecx, 0x0200
61
.read_mtrr:
62
	   rdmsr
63
	   and	eax, 0xFFF00000 			; not just bitcleaning
64
	   jz	.next_mtrr				; ignore the main memory and free MTRRs
65
	   cmp	esi, eax
66
	   jb	.next_mtrr				; ignore MMIO blocks
67
	   mov	esi, eax
68
.next_mtrr:
69
	   add	cl, 2
70
	   cmp	cl, 0x10
71
	   jb	.read_mtrr
72
 
73
	   mov	eax, USER_DMA_SIZE
74
	   sub	esi, eax				; exclude the Global DMA block...
75
	   and	esi, 0xFF800000 			; ...and the hole above it
76
	   mov	eax, esi
77
	   mov	[MEM_AMOUNT-OS_BASE], eax
78
	   mov	[pg_data.mem_amount-OS_BASE], eax	; the true MEMTOP
79
	   mov	[UserDMAaddr-OS_BASE], eax
80
 
1683 art_zh 81
	   shr esi, 12
82
	   mov [pg_data.pages_count-OS_BASE], esi	; max number of PTEs   ?
513 serge 83
 
2350 art_zh 84
	   mov edx, esi 				; edx will hold maximum allocatable address
1683 art_zh 85
	   shr edx, 3
86
	   mov [pg_data.pagemap_size-OS_BASE], edx	; size of sys_pgmap structure
465 serge 87
 
1683 art_zh 88
	   add edx, (sys_pgmap-OS_BASE)+4095
89
	   and edx, not 4095
2350 art_zh 90
	   mov [tmp_page_tabs], edx			; free zone to build PTEs for all available memory
465 serge 91
 
1683 art_zh 92
	   mov edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096
93
	   mov [pg_data.kernel_pages -OS_BASE], edx
94
	   shr edx, 10
2350 art_zh 95
	   mov [pg_data.kernel_tables-OS_BASE], edx	; number of Kernel PDEs needed
465 serge 96
 
1683 art_zh 97
	   mov edx, (sys_pgdir-OS_BASE)+ 0x800		; (0x800 = OS_BASE shr 20)
465 serge 98
 
1683 art_zh 99
	   mov ebx, cr4
100
	   or  ebx, CR4_PSE
101
	   mov eax, PG_LARGE+PG_SW
102
	   mov cr4, ebx
103
	   dec [pg_data.kernel_tables-OS_BASE]
465 serge 104
 
1683 art_zh 105
	   mov [edx], eax				; map first (physical) 4M bytes
106
	   add edx, 4
465 serge 107
 
1683 art_zh 108
	   mov edi, [tmp_page_tabs]
1952 art_zh 109
	   mov ecx, [pg_data.kernel_pages -OS_BASE]	; safety cleaning of already-zeroed space
110
	   xor eax, eax
111
	   rep stosd
1683 art_zh 112
 
113
	   mov ecx, [pg_data.kernel_tables-OS_BASE]	; build some PDEs to hold empty PTEs
114
	   mov eax, [tmp_page_tabs]
115
	   or  eax, PG_SW
116
	   mov edi, edx 		; edi = sys_pgdir+0x804
1952 art_zh 117
 
465 serge 118
.map_kernel_tabs:
1683 art_zh 119
	   stosd
120
	   add eax, 0x1000
121
	   dec ecx
122
	   jnz .map_kernel_tabs
465 serge 123
 
1683 art_zh 124
; map pagetables to linear space
125
	   mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
465 serge 126
 
1683 art_zh 127
	   mov edi, (sys_pgdir-OS_BASE)
128
	   lea esi, [edi+(OS_BASE shr 20)]
129
	   movsd
130
	   movsd
465 serge 131
 
2425 art_zh 132
init_page_map:
2350 art_zh 133
; mark all memory as available
1683 art_zh 134
	   mov edi, sys_pgmap-OS_BASE
135
	   mov ecx, [pg_data.pagemap_size-OS_BASE]
136
	   shr ecx, 2
2350 art_zh 137
	   mov eax, -1
1683 art_zh 138
	   cld
139
	   rep stosd
465 serge 140
 
1103 diamond 141
 
142
; mark kernel memory as allocated (unavailable)
1683 art_zh 143
	   mov ecx, [tmp_page_tabs]
144
	   mov edx, [pg_data.pages_count-OS_BASE]
145
	   shr ecx, 12
146
	   add ecx, [pg_data.kernel_tables-OS_BASE]
147
	   sub edx, ecx
148
	   mov [pg_data.pages_free-OS_BASE], edx
465 serge 149
 
1683 art_zh 150
	   mov edi, sys_pgmap-OS_BASE
151
	   mov ebx, ecx
152
	   shr ecx, 5
153
	   xor eax, eax
154
	   rep stosd
465 serge 155
 
1683 art_zh 156
	   not eax
157
	   mov ecx, ebx
158
	   and ecx, 31
159
	   shl eax, cl
160
	   and [edi], eax
161
	   add edi, OS_BASE
162
	   mov [page_start-OS_BASE], edi;
465 serge 163
 
1683 art_zh 164
	   mov ebx, sys_pgmap
165
	   add ebx, [pg_data.pagemap_size-OS_BASE]
166
	   mov [page_end-OS_BASE], ebx
465 serge 167
 
1683 art_zh 168
	   mov [pg_data.pg_mutex-OS_BASE], 0
169
	   ret
465 serge 170
 
2425 art_zh 171
 
465 serge 172
align 4
586 serge 173
 
174
init_BIOS32:
1683 art_zh 175
	   mov edi, 0xE0000
586 serge 176
.pcibios_nxt:
1683 art_zh 177
	   cmp dword[edi], '_32_' ; "magic" word
178
	   je .BIOS32_found
586 serge 179
.pcibios_nxt2:
1683 art_zh 180
	   add edi, 0x10
181
	   cmp edi, 0xFFFF0
182
	   je .BIOS32_not_found
183
	   jmp .pcibios_nxt
586 serge 184
.BIOS32_found:			; magic word found, check control summ
185
 
1683 art_zh 186
	   movzx ecx, byte[edi + 9]
187
	   shl ecx, 4
188
	   mov esi, edi
189
	   xor eax, eax
190
	   cld	 ; paranoia
586 serge 191
@@:	lodsb
1683 art_zh 192
	   add ah, al
193
	   loop @b
194
	   jnz .pcibios_nxt2 ; control summ must be zero
586 serge 195
    ; BIOS32 service found !
1683 art_zh 196
	   mov ebp, [edi + 4]
197
	   mov [bios32_entry], ebp
586 serge 198
    ; check PCI BIOS present
1683 art_zh 199
	   mov eax, '$PCI'
200
	   xor ebx, ebx
201
	   push cs  ; special for 'ret far' from  BIOS
202
	   call ebp
203
	   test al, al
204
	   jnz .PCI_BIOS32_not_found
586 serge 205
 
206
 ; здесь создаются дискрипторы для PCI BIOS
207
 
1683 art_zh 208
	   add ebx, OS_BASE
209
	   dec ecx
210
	   mov [(pci_code_32-OS_BASE)], cx    ;limit 0-15
211
	   mov [(pci_data_32-OS_BASE)], cx    ;limit 0-15
586 serge 212
 
1683 art_zh 213
	   mov [(pci_code_32-OS_BASE)+2], bx  ;base  0-15
214
	   mov [(pci_data_32-OS_BASE)+2], bx  ;base  0-15
586 serge 215
 
1683 art_zh 216
	   shr ebx, 16
217
	   mov [(pci_code_32-OS_BASE)+4], bl  ;base  16-23
218
	   mov [(pci_data_32-OS_BASE)+4], bl  ;base  16-23
586 serge 219
 
1683 art_zh 220
	   shr ecx, 16
221
	   and cl, 0x0F
222
	   mov ch, bh
223
	   add cx, D32
224
	   mov [(pci_code_32-OS_BASE)+6], cx  ;lim   16-19 &
225
	   mov [(pci_data_32-OS_BASE)+6], cx  ;base  24-31
586 serge 226
 
1683 art_zh 227
	   mov [(pci_bios_entry-OS_BASE)], edx
228
	 ; jmp .end
586 serge 229
.PCI_BIOS32_not_found:
230
	; здесь должна заполнятся pci_emu_dat
231
.BIOS32_not_found:
232
.end:
1683 art_zh 233
	   ret
586 serge 234
 
235
align 4
1683 art_zh 236
test_cpu:	; only AMD machines supported
465 serge 237
 
1683 art_zh 238
	   xor eax, eax
239
	   mov [cpu_caps-OS_BASE], eax
240
	   mov [cpu_caps+4-OS_BASE], eax
465 serge 241
 
1683 art_zh 242
	   pushfd
243
	   pop eax
244
	   mov ecx, eax
245
	   xor eax, 0x40000
246
	   push eax
247
	   popfd
248
	   pushfd
249
	   pop eax
250
	   xor eax, ecx
251
	   jz $ 		; 386
252
	   push ecx
253
	   popfd
465 serge 254
 
1683 art_zh 255
	   mov eax, ecx
256
	   xor eax, 0x200000
257
	   push eax
258
	   popfd
259
	   pushfd
260
	   pop eax
261
	   xor eax, ecx
262
	   je $ 		; 486
465 serge 263
 
1683 art_zh 264
	   xor eax, eax
265
	   cpuid
465 serge 266
 
1683 art_zh 267
	   mov [cpu_vendor-OS_BASE],   ebx
268
	   mov [cpu_vendor+4-OS_BASE], edx
269
	   mov [cpu_vendor+8-OS_BASE], ecx
465 serge 270
 
1683 art_zh 271
	   cmp ebx, dword [AMD_str-OS_BASE]
272
	   jne $
273
	   cmp edx, dword [AMD_str+4-OS_BASE]
274
	   jne $
275
	   cmp ecx, dword [AMD_str+8-OS_BASE]
276
	   jne $
277
	   cmp eax, 1
278
	   jl $
279
	   mov eax, 1
280
	   cpuid
281
	   mov [cpu_sign-OS_BASE],  eax
282
	   mov [cpu_info-OS_BASE],  ebx
283
	   mov [cpu_caps-OS_BASE],  edx
284
	   mov [cpu_caps+4-OS_BASE],ecx
285
	   shr eax, 8
286
	   and eax, 0x0f
287
	   ret
465 serge 288