Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 1683 → Rev 1682

/kernel/branches/Kolibri-A/trunk/bus/HT.inc
3,7 → 3,6
;; Copyright (C) 2010 KolibriOS team. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;;
;; ;;
;; HT.inc ;; ;;
;; ;;
;; AMD HyperTransport bus control ;;
;; ;;
23,9 → 22,6
; This code is a part of Kolibri-A and will only work with AMD RS760+ chipsets
;
;=============================================================================
 
org $-OS_BASE ; physical addresses needed at initial stage
 
align 4
 
;------------------------------------------
75,7 → 71,7
align 4
rs7xx_unlock_bar3:
mov eax, NB_MISC_INDEX
mov ebx, 0x080 ; NBMISCIND:0x0; write-enable
mov ebx, 0x080 ; reg#0; write-enable
call rs7xx_nbconfig_write_pci ; set index
mov eax, NB_MISC_DATA
call rs7xx_nbconfig_read_pci ; read data
88,90 → 84,6
call rs7xx_nbconfig_write_pci ; set index
ret
 
 
 
;***************************************************************************
; Function
; rs7xx_pcie_init:
;
; Description
; PCIe extended (memory-mapped) config space detection
;
;***************************************************************************
 
align 4
 
rs7xx_pcie_init:
call rs7xx_unlock_bar3
mov al, 0x7C ; NB_IOC_CFG_CNTL
call rs7xx_nbconfig_read_pci
mov ebx, eax
; call rs7xx_nbconfig_flush_pci
test ebx, 0x20000000 ; BAR3 locked?
jz $
mov al, 0x84 ; NB_PCI_ARB
call rs7xx_nbconfig_read_pci
shr eax,16
and ax, 7 ; the Bus range lays here:
jnz @f
mov ax, 8 ; 1=2Mb, 2=4MB, 3=8MB, 4=16MB
@@:
mov word[PCIe_bus_range-OS_BASE], ax ; 5=32Mb, 6=64MB, 7=128Mb, 8=256Mb
mov cl, al
call rs7xx_nbconfig_flush_pci
dec cl ; <4M ?
jz @f
dec cl ; one PDE needed anyway
@@:
mov ebx, 1
shl ebx, cl
mov word[mmio_pcie_cfg_pdes-OS_BASE], bx ; 1..64 PDE(s) needed,
shl ebx, 22
mov dword[mmio_pcie_cfg_lim-OS_BASE], ebx ; or 4..256Mb space to map
dec dword[mmio_pcie_cfg_lim-OS_BASE]
 
mov al, 0x1C ; NB_BAR3_PCIEXP_MMCFG
call rs7xx_nbconfig_read_pci
mov ebx, eax
call rs7xx_nbconfig_flush_pci
mov eax, ebx
and eax, 0xFFE00000 ; valid bits [31..21]
jz $ ; NB BAR3 may be invisible!
.addr_found:
mov dword[mmio_pcie_cfg_addr-OS_BASE], eax ; physical address (lower 32 bits)
add dword[mmio_pcie_cfg_lim-OS_BASE], eax
 
or eax, (PG_NOCACHE + PG_SHARED + PG_LARGE + PG_UW) ; by the way, UW is unsafe!
mov ecx, PCIe_CONFIG_SPACE ; linear address
mov ebx, ecx
shr ebx, 20
add ebx, (sys_pgdir - OS_BASE) ; PgDir entry @
mov dl, byte[mmio_pcie_cfg_pdes-OS_BASE] ; 1 page = 4M in address space
cmp dl, 0x34 ; =(USER_DMA_BUFFER - PCIe_CONFIG_SPACE) / 4M
jb @f
mov dl, 0x33
mov byte[mmio_pcie_cfg_pdes-OS_BASE], dl
@@:
xor dx, dx ; PDEs counter
.write_pde:
mov dword[ebx], eax ; map 4 buses
add bx, 4 ; new PDE
add eax, 0x400000 ; +4M phys.
add ecx, 0x400000 ; +4M lin.
cmp dl, byte[mmio_pcie_cfg_pdes-OS_BASE]
jae .pcie_cfg_mapped
inc dl
jmp .write_pde
; mov eax, cr3
; mov cr3, eax ; flush TLB
.pcie_cfg_mapped:
ret ; <<< OK >>>
 
 
; ================================================================================
 
org OS_BASE+$ ; back to the linear address space
 
;--------------------------------------------------------------
align 4
rs780_read_misc:
280,4 → 192,96
 
 
 
;***************************************************************************
; Function
; rs7xx_pcie_init:
;
; Description
; PCIe extended (memory-mapped) config space detection
;
;***************************************************************************
 
align 4
 
rs7xx_pcie_init:
call rs7xx_unlock_bar3
mov al, 0x7C ; NB_IOC_CFG_CNTL
call rs7xx_nbconfig_read_pci
mov ebx, eax
call rs7xx_nbconfig_flush_pci
test ebx, 0x20000000 ; BAR3 locked?
jz .rs7xx_pcie_blocked
mov al, 0x84 ; NB_PCI_ARB
call rs7xx_nbconfig_read_pci
shr eax,16
and ax, 7 ; the Bus range lays here:
jnz @f
mov ax, 8 ; 1=2Mb, 2=4MB, 3=8MB, 4=16MB
@@:
mov [PCIe_bus_range], ax ; 5=32Mb, 6=64MB, 7=128Mb, 8=256Mb
mov cl, al
call rs7xx_nbconfig_flush_pci
dec cl ; <4M ?
jnz @f
inc cl ; one PDE needed anyway
@@:
dec cl
mov ebx, 1
shl ebx, cl
mov [mmio_pcie_cfg_pdes], bx ; 1..64 PDE(s) needed,
shl ebx, 22
mov [mmio_pcie_cfg_lim], ebx ; or 4..256Mb space to map
dec [mmio_pcie_cfg_lim]
 
mov al, 0x1C ; NB_BAR3_PCIEXP_MMCFG
call rs7xx_nbconfig_read_pci
mov ebx, eax
call rs7xx_nbconfig_flush_pci
mov eax, ebx
and eax, 0xFFE00000 ; valid bits [31..21]
jz .rs7xx_pcie_blocked ; NB BAR3 may be invisible!
; try to get pcie ecfg address indirectly
.addr_found:
mov [mmio_pcie_cfg_addr], eax ; physical address (lower 32 bits)
add [mmio_pcie_cfg_lim], eax
 
or eax, (PG_SHARED + PG_LARGE + PG_UW) ; by the way, UW is unsafe!
mov ecx, PCIe_CONFIG_SPACE ; linear address
mov ebx, ecx
shr ebx, 20
add ebx, sys_pgdir ; PgDir entry @
mov dl, byte[mmio_pcie_cfg_pdes] ; 1 page = 4M in address space
cmp dl, (USER_DMA_BUFFER - PCIe_CONFIG_SPACE) / 4194304
jb @f
mov dl, ((USER_DMA_BUFFER - PCIe_CONFIG_SPACE) / 4194304) - 1
mov byte[mmio_pcie_cfg_pdes], dl
@@:
xor dx, dx ; PDEs counter
@@:
mov dword[ebx], eax ; map 4 buses
add bx, 4 ; new PDE
add eax, 0x400000 ; +4M phys.
add ecx, 0x400000 ; +4M lin.
cmp dl, byte[mmio_pcie_cfg_pdes]
jnc .pcie_cfg_mapped
inc dl
jmp @b
mov eax, cr3
mov cr3, eax ; flush TLB
.pcie_cfg_mapped:
mov esi, boot_pcie_ok
call boot_log
ret ; <<< OK >>>
.rs7xx_pcie_fail:
mov esi, boot_rs7xx_fail
call boot_log
jmp $
.rs7xx_pcie_blocked:
mov esi, boot_rs7xx_blkd
call boot_log
jmp $
 
 
 
 
 
/kernel/branches/Kolibri-A/trunk/bus/pci/PCIe.inc
87,9 → 87,10
jb .check_HT_mmio
 
.pcie_failed:
jmp $
; xor eax, eax
; ret ; <<<<<<<<< FAILURE >>>>>>>>>
mov esi, boot_pcie_fail
call boot_log
xor eax, eax
ret ; <<<<<<<<< FAILURE >>>>>>>>>
 
 
;--------------------------------------------------------------------------
/kernel/branches/Kolibri-A/trunk/kernel.asm
130,8 → 130,6
include "bus/pci/pci16.inc"
include "detect/biosdisk.inc"
 
diff16 "end of code16 ",0,$
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SWITCH TO 32 BIT PROTECTED MODE ;;
194,18 → 192,13
dw 11011111b *256 +10010010b
db 0x00
 
diff16 "end of tmp_gdt ",0,$
 
include "data16.inc"
 
diff16 "end of data16 ",0,$
 
use32
org $+0x10000
 
align 4
B32:
diff16 "32-bit code start ",0,$
mov ax,os_stack ; Selector for os
mov ds,ax
mov es,ax
212,22 → 205,42
mov fs,ax
mov gs,ax
mov ss,ax
mov esp,0x4ec00 ; Set stack
mov esp,0x3ec00 ; Set stack
 
;-------------------------------------------------------------------------------
call preinit_mem ; (init.inc)
; CLEAR 0x280000 - HEAP_BASE
 
call test_cpu ; (init.inc - to be moved to bus/CPU.inc)
bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
xor eax,eax
mov edi,0x280000
mov ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
cld
rep stosd
 
call init_BIOS32 ; (init.inc - to be removed later)
mov edi,0x40000
mov ecx,(0x90000-0x40000)/4
rep stosd
 
; PCIe extended config space access
call rs7xx_pcie_init ; (bus/HT.inc)
; CLEAR KERNEL UNDEFINED GLOBALS
mov edi, endofcode-OS_BASE
mov ecx, (uglobals_size/4)+4
rep stosd
 
; SAVE & CLEAR 0-0xffff
 
xor esi, esi
mov edi,0x2F0000
mov ecx,0x10000 / 4
rep movsd
mov edi,0x1000
mov ecx,0xf000 / 4
rep stosd
 
call test_cpu
bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
 
call init_BIOS32
; MEMORY MODEL
call init_mem ; (init.inc)
call init_page_map ; (init.inc)
call init_mem
call init_page_map
 
; ENABLE PAGING
 
365,7 → 378,6
mov edi, BiosDisksData
rep movsd
 
 
; GRAPHICS ADDRESSES
 
and byte [BOOT_VAR+0x901e],0x0
372,6 → 384,7
mov eax,[BOOT_VAR+0x9018]
mov [LFBAddress],eax
 
;==
cmp [SCR_MODE],word 0100000000000000b
jge setvesa20
mov eax, 0xDEADBEEF
378,13 → 391,37
hlt
; === EGA, VGA & Vesa 1.2 modes not supported ===
setvesa20:
; mov [PUTPIXEL],dword Vesa20_putpixel24 ; Vesa 2.0 24bpp modes
; mov [GETPIXEL],dword Vesa20_getpixel24
; cmp [ScreenBPP],byte 24
; jz v20ga24
v20ga32:
mov [PUTPIXEL],dword Vesa20_putpixel32
mov [GETPIXEL],dword Vesa20_getpixel32
 
; -------- Fast System Call init ----------
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
; bt [cpu_caps], CAPS_SEP
; jnc .SEnP ; SysEnter not Present
; xor edx, edx
; mov ecx, MSR_SYSENTER_CS
; mov eax, os_code
; wrmsr
; mov ecx, MSR_SYSENTER_ESP
;; mov eax, sysenter_stack ; Check it
; xor eax, eax
; wrmsr
; mov ecx, MSR_SYSENTER_EIP
; mov eax, sysenter_entry
; wrmsr
.SEnP:
; AMD SYSCALL/SYSRET
; cmp byte[cpu_vendor], 'A'
; jne .noSYSCALL
; mov eax, 0x80000001
; cpuid
; test edx, 0x800 ; bit_11 - SYSCALL/SYSRET support
; jz .noSYSCALL
mov ecx, MSR_AMD_EFER
rdmsr
or eax, 1 ; bit_0 - System Call Extension (SCE)
391,9 → 428,9
wrmsr
 
; Bits of EDX :
; Bit 31..16 During the SYSRET instruction, this field is copied into the CS register
; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
; and the contents of this field, plus 8, are copied into the SS register.
; Bit 15..0 During the SYSCALL instruction, this field is copied into the CS register
; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
; and the contents of this field, plus 8, are copied into the SS register.
 
mov edx, 0x1B000B ; RING3 task stack will be used for fast syscalls!
450,7 → 487,7
call init_LFB
call init_fpu
call init_malloc
;-
 
stdcall alloc_kernel_space, 0x51000
mov [default_io_map], eax
 
706,7 → 743,9
mov [CPU_FREQ],eax ; save tsc / sec
; mov ebx, 1000000
; div ebx
; faster division possible:
; ¢®®¡é¥-â® ¯à®¨§¢®¤¨â¥«ì­®áâì ¢ ¤ ­­®¬ ª®­ªà¥â­®¬ ¬¥áâ¥
; ᮢ¥à襭­® ­¥ªà¨â¨ç­ , ­® çâ®¡ë § âª­ãâì «î¡¨â¥«¥©
; ®¯â¨¬¨§¨àãîé¨å ª®¬¯¨«ïâ®à®¢ Ÿ‚“...
mov edx, 2251799814
mul edx
shr edx, 19
744,7 → 783,22
call stack_init
call fdc_init
 
; PALETTE FOR 320x200 and 640x480 16 col
 
; cmp [SCR_MODE],word 0x12
; jne no_pal_vga
; mov esi,boot_pal_vga
; call boot_log
; call paletteVGA
; no_pal_vga:
 
; cmp [SCR_MODE],word 0x13
; jne no_pal_ega
; mov esi,boot_pal_ega
; call boot_log
; call palette320x200
; no_pal_ega:
 
; LOAD DEFAULT SKIN
 
call load_default_skin
770,6 → 824,9
call init_userDMA ; <<<<<<<<< ============== core/memory.inc =================
mov esi, boot_uDMA_ok
call boot_log
; call pci_ext_config ; <<<<<<<<< bus/pci/pcie.inc
;-------------------------------------------------------------------------------
call rs7xx_pcie_init ; <<<<<<<<< bus/ht.inc
 
; LOAD FIRST APPLICATION
cli
4844,12 → 4901,9
ret
end if
 
diff16 "End of 32-code ",0,$
 
include "data32.inc"
 
__REV__ = __REV
 
uglobals_size = $ - endofcode
diff16 "Zero-filled blk",0,endofcode
diff16 "End of kernel ",0,$
diff16 "end of kernel code",0,$
/kernel/branches/Kolibri-A/trunk/kernel32.inc
246,7 → 246,7
 
; Pci functions
include "bus/pci/pci32.inc"
;include "bus/pci/PCIe.inc"
include "bus/pci/PCIe.inc"
include "bus/HT.inc" ; AMD HyperTransport bus control
 
; Floppy drive controller
/kernel/branches/Kolibri-A/trunk/data32.inc
57,15 → 57,21
boot_setmouse db 'Setting mouse',0
boot_windefs db 'Setting window defaults',0
boot_bgr db 'Calculating background',0
; boot_resirqports db 'Reserving IRQs & ports',0
boot_resirqports db 'Reserving IRQs & ports',0
; boot_setrports db 'Setting addresses for IRQs',0
boot_setostask db 'Setting OS task',0
boot_allirqs db 'Unmasking all IRQs',0
boot_tsc db 'Reading TSC',0
boot_cpufreq db 'CPU frequency is ',' ',' MHz',0
; boot_pal_ega db 'Setting EGA/CGA 320x200 palette',0
; boot_pal_vga db 'Setting VGA 640x480 palette',0
boot_failed db 'Failed to start first app',0
boot_mtrr db 'Setting MTRR',0
boot_uDMA_ok db 'Set user DMA OK',0
boot_pcie_ok db 'PCIe config set OK',0
boot_pcie_fail db 'PCIe config XXX failed XXX',0
boot_rs7xx_fail db 'RS7xx config XXX failed XXX',0
boot_rs7xx_blkd db 'RS7xx config ---------- FAILED -----------',0
if preboot_blogesc
boot_tasking db 'All set - press ESC to start',0
end if
81,7 → 87,7
msg_CR db 13,10,0
aSis db 'SIS',0
 
;intel_str db "GenuineIntel",0
intel_str db "GenuineIntel",0
AMD_str db "AuthenticAMD",0
 
;szSound db 'SOUND',0
463,6 → 469,4
BiosDiskCaches rb 80h*(cache_ide1-cache_ide0)
BiosDiskPartitions rd 80h
 
diff16 "UGlobals start ",0,$
 
IncludeUGlobals
/kernel/branches/Kolibri-A/trunk/boot/bootcode.inc
180,6 → 180,24
mov ax, 3
int 0x10
 
if lang eq ru
; Load & set russian VGA font (RU.INC)
mov bp, RU_FNT1 ; RU_FNT1 - First part
mov bx, 1000h ; 768 bytes
mov cx, 30h ; 48 symbols
mov dx, 80h ; 128 - position of first symbol
mov ax, 1100h
int 10h
 
mov bp, RU_FNT2 ; RU_FNT2 -Second part
mov bx, 1000h ; 512 bytes
mov cx, 20h ; 32 symbols
mov dx, 0E0h ; 224 - position of first symbol
mov ax, 1100h
int 10h
; End set VGA russian font
end if
 
; draw frames
push 0xb800
pop es
290,6 → 308,33
.nopci:
; \end{Mario79}
 
; mov al, 0xf6 ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
; out 0x60, al
; xor cx, cx
;wait_loop: ; variant 2
; reading state of port of 8042 controller
; in al, 64h
; and al, 00000010b ; ready flag
; wait until 8042 controller is ready
; loopnz wait_loop
 
;;;/diamond 5.02.2008
; set keyboard typematic rate & delay
; mov al, 0xf3
; out 0x60, al
; xor cx, cx
;@@:
; in al, 64h
; test al, 2
; loopnz @b
; mov al, 0
; out 0x60, al
; xor cx, cx
;@@:
; in al, 64h
; test al, 2
; loopnz @b
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; --------------- APM ---------------------
and word [es:0x9044], 0 ; ver = 0.0 (APM not found)
mov ax, 0x5300
451,6 → 496,10
pop dword [.oldtimer]
push dword [.timer]
pop dword [es:8*4]
; mov eax, [es:8*4]
; mov [.oldtimer], eax
; mov eax, [.timer]
; mov [es:8*4], eax
sti
; wait for keypressed
xor ax,ax
457,6 → 506,8
int 16h
push ax
; restore timer interrupt
; push 0
; pop es
mov eax, [.oldtimer]
mov [es:8*4], eax
mov [.timer], eax
509,6 → 560,7
_setcursor 25,0 ; out of screen
xor ax,ax
int 0x16
; call clear_table_cursor ;clear current position of cursor
 
mov si,word [cursor_pos]
 
579,6 → 631,11
 
.change_b:
_setcursor 15,0
; mov si, ask_dma
; call print
; mov bx, '13'
; call getkey
; mov [preboot_dma], al
mov si, ask_bd
call print
mov bx, '12'
635,7 → 692,23
mov bx, 18
xor dx, dx
div bx
 
if lang eq ru
; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
cmp al, 5
mov cl, ' '
jae @f
cmp al, 1
mov cl, 'ã'
jz @f
mov cl, 'ë'
@@: mov [time_str+9], cl
else if lang eq et
cmp al, 1
ja @f
mov [time_str+9], ' '
mov [time_str+10],' '
@@:
else
; wait 5/4/3/2 seconds, 1 second
cmp al, 1
mov cl, 's'
642,6 → 715,7
ja @f
mov cl, ' '
@@: mov [time_str+9], cl
end if
add al, '0'
mov [time_str+1], al
mov si, time_msg
1070,12 → 1144,12
xor ax, ax
mov es, ax
 
mov bx, [es:0x9008] ; vga & 320x200
; mov bx, ax
; cmp ax, 0x13
; je setgr
; cmp ax, 0x12
; je setgr
mov ax, [es:0x9008] ; vga & 320x200
mov bx, ax
cmp ax, 0x13
je setgr
cmp ax, 0x12
je setgr
mov ax, 0x4f02 ; Vesa
setgr:
int 0x10
1083,24 → 1157,27
mov si, fatalsel
jnz v_mode_error
; set mode 0x12 graphics registers:
; cmp bx, 0x12
; jne gmok2
; mov al, 0x05
; mov dx, 0x03ce
; push dx
; out dx, al ; select GDC mode register
; mov al, 0x02
; inc dx
; out dx, al ; set write mode 2
; mov al, 0x02
; mov dx, 0x03c4
; out dx, al ; select VGA sequencer map mask register
; mov al, 0x0f
; inc dx
; out dx, al ; set mask for all planes 0-3
; mov al, 0x08
; pop dx
; out dx, al ; select GDC bit mask register
cmp bx, 0x12
jne gmok2
 
mov al, 0x05
mov dx, 0x03ce
push dx
out dx, al ; select GDC mode register
mov al, 0x02
inc dx
out dx, al ; set write mode 2
 
mov al, 0x02
mov dx, 0x03c4
out dx, al ; select VGA sequencer map mask register
mov al, 0x0f
inc dx
out dx, al ; set mask for all planes 0-3
 
mov al, 0x08
pop dx
out dx, al ; select GDC bit mask register
; for writes to 0x03cf
gmok2:
push ds
/kernel/branches/Kolibri-A/trunk/memmap.inc
122,13 → 122,9
; FE04 dword screen y size
; FE08 dword screen y multiplier
; FE0C dword screen mode
; FE10 -> FE73 free (100)
; FE74 dword PCIe extended (memory-mappable) config space - physical address
; FE78 dword PCIe extended config space limit
; FE7C word number of 4M-pages needed to map PCIe config space
; FE7E word PCIe bus range (power-ow-two Mbytes)
; FE80 dword physical address of user-accessible static system buffer
; FE84 dword physical address of LFB
; FE10 -> FE7F free (112)
; FE80 dword physical address of LFB
; FE84 dword physical address of user-accessible static system buffer
; FE88 dword address of button list
; FE8C dword memory to use
; FE90 -> FEFF free (112)
142,16 → 138,7
; FFFF byte do not change task for 1/100 sec.
;
; 0x80010000 -> 6CBFF kernel, 32-bit run-time code (up to 371 Kb)
; in the current version:
; -> 01726 16-bit code end
; -> 01828 16-bit data end
; -> 11828 32-bit code start
; -> 2E19E 32-bit code end
; -> 314F8..end_of_kernel zero-filled zone after preinit_mem
; -> 34DFB uninitialized globals start
; -> 3CFEA end_of_kernel
; -> 3D000 not used (190k)
; 0x80050000 -> 090000 zero-filled zone after preinit_mem
 
; 0x8006CC00 -> 6DBFF stack at boot time (4Kb)
;
; 0x8006DC00 -> 6E5FF basic text font II
205,8 → 192,6
; 0x800A0000 -> AFFFF screen access area
; 0x800B0000 -> FFFFF bios rest in peace -area (320k) ?
; 0x80100000 -> 27FFFF diskette image (1m5)
 
; 0x80280000 -> HEAP_BASE zero-filled zone after preinit_mem
; 0x80280000 -> 281FFF ramdisk fat (8k)
; 0x80282000 -> 283FFF floppy fat (8k)
;
/kernel/branches/Kolibri-A/trunk/const.inc
252,13 → 252,8
BytesPerScanLine equ (OS_BASE+0x000FE08)
SCR_MODE equ (OS_BASE+0x000FE0C)
 
mmio_pcie_cfg_addr equ (OS_BASE+0x000FE74)
mmio_pcie_cfg_lim equ (OS_BASE+0x000FE78)
mmio_pcie_cfg_pdes equ (OS_BASE+0x000FE7C)
PCIe_bus_range equ (OS_BASE+0x000FE7E)
 
UserDMAaddr equ (OS_BASE+0x000FE80)
LFBAddress equ (OS_BASE+0x000FE84)
LFBAddress equ (OS_BASE+0x000FE80)
UserDMAaddr equ (OS_BASE+0x000FE84)
BTN_ADDR equ (OS_BASE+0x000FE88)
MEM_AMOUNT equ (OS_BASE+0x000FE8C)
 
/kernel/branches/Kolibri-A/trunk/init.inc
12,72 → 12,92
MEM_WC equ 1 ;write combined memory
MEM_UC equ 0 ;uncached memory
 
; ======================================================================
align 4
preinit_mem:
 
; clear [0x280000..HEAP_BASE]
xor eax,eax
mov edi,0x280000 ; 0x280000 = ramdisk FAT ?
mov ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
cld
rep stosd
 
; clear [0x40000..0x90000]
mov edi,0x50000 ; 0x50000 is somewhere inside kernel code?
mov ecx,(0x90000-0x50000)/4
rep stosd
 
; clear undefined kernel globals
mov edi, endofcode-OS_BASE
mov ecx, (uglobals_size/4)+4
rep stosd
 
; save [0..0xffff]
xor esi, esi
mov edi,0x2F0000 ; low mem storage area
mov ecx, 0x10000 / 4
rep movsd
; clear [0x1000..0x0ffff]
mov edi,0x1000
mov ecx,0xf000 / 4
rep stosd
 
; clear <sys_pgdir> table
mov edi, sys_pgdir-OS_BASE
mov ecx, 4096/4
rep stosd
ret
 
; ======================================================================
align 4
proc init_mem
 
mov esi, (PCIe_CONFIG_SPACE-OS_BASE) ; esi will hold total amount of memory
mov edx, esi ; edx will hold maximum allocatable address
 
; calculate maximum allocatable address and number of allocatable pages
mov edi, BOOT_VAR-OS_BASE + 0x9104
mov ecx, [edi-4]
xor esi, esi ; esi will hold total amount of memory
xor edx, edx ; edx will hold maximum allocatable address
.calcmax:
; round all to pages
mov eax, [edi]
test eax, 0xFFF
jz @f
neg eax
and eax, 0xFFF
add [edi], eax
adc dword [edi+4], 0
sub [edi+8], eax
sbb dword [edi+12], 0
jc .unusable
@@:
and dword [edi+8], not 0xFFF
jz .unusable
; ignore memory after 4 Gb
cmp dword [edi+4], 0
jnz .unusable
mov eax, [edi]
cmp dword [edi+12], 0
jnz .overflow
add eax, [edi+8]
jnc @f
.overflow:
mov eax, 0xFFFFF000
@@:
cmp edx, eax
jae @f
mov edx, eax
@@:
sub eax, [edi]
mov [edi+8], eax
add esi, eax
jmp .usable
.unusable:
and dword [edi+8], 0
.usable:
add edi, 20
loop .calcmax
.calculated:
mov [MEM_AMOUNT-OS_BASE], esi
mov [pg_data.mem_amount-OS_BASE], esi
shr esi, 12
mov [pg_data.pages_count-OS_BASE], esi ; max number of PTEs ?
mov [pg_data.pages_count-OS_BASE], esi
 
shr edx, 12
add edx, 31
and edx, not 31
shr edx, 3
mov [pg_data.pagemap_size-OS_BASE], edx ; size of sys_pgmap structure
mov [pg_data.pagemap_size-OS_BASE], edx
 
add edx, (sys_pgmap-OS_BASE)+4095
and edx, not 4095
mov [tmp_page_tabs], edx ; free zone to build PTEs
mov [tmp_page_tabs], edx
 
mov edx, esi
and edx, -1024
cmp edx, (OS_BASE/4096)
jbe @F
mov edx, (OS_BASE/4096)
jmp .set
@@:
cmp edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096
jae .set
mov edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096
.set:
mov [pg_data.kernel_pages -OS_BASE], edx
shr edx, 10
mov [pg_data.kernel_tables-OS_BASE], edx
 
mov edx, (sys_pgdir-OS_BASE)+ 0x800 ; (0x800 = OS_BASE shr 20)
xor eax, eax
mov edi, sys_pgdir-OS_BASE
mov ecx, 4096/4
cld
rep stosd
 
mov edx, (sys_pgdir-OS_BASE)+ 0x800; (OS_BASE shr 20)
 
mov ebx, cr4
or ebx, CR4_PSE
mov eax, PG_LARGE+PG_SW
84,18 → 104,19
mov cr4, ebx
dec [pg_data.kernel_tables-OS_BASE]
 
mov [edx], eax ; map first (physical) 4M bytes
mov [edx], eax
add edx, 4
 
mov edi, [tmp_page_tabs]
mov ecx, [pg_data.kernel_pages -OS_BASE] ; safety cleaning of already-zeroed space
mov ecx, [pg_data.kernel_tables-OS_BASE]
shl ecx, 10
xor eax, eax
rep stosd
 
mov ecx, [pg_data.kernel_tables-OS_BASE] ; build some PDEs to hold empty PTEs
mov ecx, [pg_data.kernel_tables-OS_BASE]
mov eax, [tmp_page_tabs]
or eax, PG_SW
mov edi, edx ; edi = sys_pgdir+0x804
mov edi, edx
 
.map_kernel_tabs:
stosd
103,7 → 124,6
dec ecx
jnz .map_kernel_tabs
 
; map pagetables to linear space
mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
 
mov edi, (sys_pgdir-OS_BASE)
266,9 → 286,16
ret
 
align 4
test_cpu: ; only AMD machines supported
proc test_cpu
locals
cpu_type dd ?
cpu_id dd ?
cpu_Intel dd ?
cpu_AMD dd ?
endl
 
xor eax, eax
mov [cpu_type], eax
mov [cpu_caps-OS_BASE], eax
mov [cpu_caps+4-OS_BASE], eax
 
281,10 → 308,12
pushfd
pop eax
xor eax, ecx
jz $ ; 386
mov [cpu_type], CPU_386
jz .end_cpuid
push ecx
popfd
 
mov [cpu_type], CPU_486
mov eax, ecx
xor eax, 0x200000
push eax
292,7 → 321,8
pushfd
pop eax
xor eax, ecx
je $ ; 486
je .end_cpuid
mov [cpu_id], 1
 
xor eax, eax
cpuid
300,15 → 330,39
mov [cpu_vendor-OS_BASE], ebx
mov [cpu_vendor+4-OS_BASE], edx
mov [cpu_vendor+8-OS_BASE], ecx
cmp ebx, dword [intel_str-OS_BASE]
jne .check_AMD
cmp edx, dword [intel_str+4-OS_BASE]
jne .check_AMD
cmp ecx, dword [intel_str+8-OS_BASE]
jne .check_AMD
mov [cpu_Intel], 1
cmp eax, 1
jl .end_cpuid
mov eax, 1
cpuid
mov [cpu_sign-OS_BASE], eax
mov [cpu_info-OS_BASE], ebx
mov [cpu_caps-OS_BASE], edx
mov [cpu_caps+4-OS_BASE],ecx
 
shr eax, 8
and eax, 0x0f
ret
.end_cpuid:
mov eax, [cpu_type]
ret
 
.check_AMD:
cmp ebx, dword [AMD_str-OS_BASE]
jne $
jne .unknown
cmp edx, dword [AMD_str+4-OS_BASE]
jne $
jne .unknown
cmp ecx, dword [AMD_str+8-OS_BASE]
jne $
jne .unknown
mov [cpu_AMD], 1
cmp eax, 1
jl $
jl .unknown
mov eax, 1
cpuid
mov [cpu_sign-OS_BASE], eax
318,6 → 372,16
shr eax, 8
and eax, 0x0f
ret
.unknown:
mov eax, 1
cpuid
mov [cpu_sign-OS_BASE], eax
mov [cpu_info-OS_BASE], ebx
mov [cpu_caps-OS_BASE], edx
mov [cpu_caps+4-OS_BASE],ecx
shr eax, 8
and eax, 0x0f
ret
endp