init.inc optimized for AMD chipsets

git-svn-id: svn://kolibrios.org@1683 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Artem Jerdev (art_zh) 2010-11-01 11:30:29 +00:00
parent 3c2f9c9b90
commit 74c5e79c92
9 changed files with 3262 additions and 3446 deletions

View File

@ -180,24 +180,6 @@ no_hd_load:
mov ax, 3 mov ax, 3
int 0x10 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 ; draw frames
push 0xb800 push 0xb800
pop es pop es
@ -308,33 +290,6 @@ sayerr:
.nopci: .nopci:
; \end{Mario79} ; \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 --------------------- ; --------------- APM ---------------------
and word [es:0x9044], 0 ; ver = 0.0 (APM not found) and word [es:0x9044], 0 ; ver = 0.0 (APM not found)
mov ax, 0x5300 mov ax, 0x5300
@ -496,18 +451,12 @@ cfgmanager:
pop dword [.oldtimer] pop dword [.oldtimer]
push dword [.timer] push dword [.timer]
pop dword [es:8*4] pop dword [es:8*4]
; mov eax, [es:8*4]
; mov [.oldtimer], eax
; mov eax, [.timer]
; mov [es:8*4], eax
sti sti
; wait for keypressed ; wait for keypressed
xor ax,ax xor ax,ax
int 16h int 16h
push ax push ax
; restore timer interrupt ; restore timer interrupt
; push 0
; pop es
mov eax, [.oldtimer] mov eax, [.oldtimer]
mov [es:8*4], eax mov [es:8*4], eax
mov [.timer], eax mov [.timer], eax
@ -560,7 +509,6 @@ cfgmanager:
_setcursor 25,0 ; out of screen _setcursor 25,0 ; out of screen
xor ax,ax xor ax,ax
int 0x16 int 0x16
; call clear_table_cursor ;clear current position of cursor
mov si,word [cursor_pos] mov si,word [cursor_pos]
@ -631,11 +579,6 @@ cfgmanager:
.change_b: .change_b:
_setcursor 15,0 _setcursor 15,0
; mov si, ask_dma
; call print
; mov bx, '13'
; call getkey
; mov [preboot_dma], al
mov si, ask_bd mov si, ask_bd
call print call print
mov bx, '12' mov bx, '12'
@ -692,30 +635,13 @@ end virtual
mov bx, 18 mov bx, 18
xor dx, dx xor dx, dx
div bx 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 ; wait 5/4/3/2 seconds, 1 second
cmp al, 1 cmp al, 1
mov cl, 's' mov cl, 's'
ja @f ja @f
mov cl, ' ' mov cl, ' '
@@: mov [time_str+9], cl @@: mov [time_str+9], cl
end if
add al, '0' add al, '0'
mov [time_str+1], al mov [time_str+1], al
mov si, time_msg mov si, time_msg
@ -1144,12 +1070,12 @@ no_sys_on_floppy:
xor ax, ax xor ax, ax
mov es, ax mov es, ax
mov ax, [es:0x9008] ; vga & 320x200 mov bx, [es:0x9008] ; vga & 320x200
mov bx, ax ; mov bx, ax
cmp ax, 0x13 ; cmp ax, 0x13
je setgr ; je setgr
cmp ax, 0x12 ; cmp ax, 0x12
je setgr ; je setgr
mov ax, 0x4f02 ; Vesa mov ax, 0x4f02 ; Vesa
setgr: setgr:
int 0x10 int 0x10
@ -1157,27 +1083,24 @@ setgr:
mov si, fatalsel mov si, fatalsel
jnz v_mode_error jnz v_mode_error
; set mode 0x12 graphics registers: ; set mode 0x12 graphics registers:
cmp bx, 0x12 ; cmp bx, 0x12
jne gmok2 ; jne gmok2
; mov al, 0x05
mov al, 0x05 ; mov dx, 0x03ce
mov dx, 0x03ce ; push dx
push dx ; out dx, al ; select GDC mode register
out dx, al ; select GDC mode register ; mov al, 0x02
mov al, 0x02 ; inc dx
inc dx ; out dx, al ; set write mode 2
out dx, al ; set write mode 2 ; mov al, 0x02
; mov dx, 0x03c4
mov al, 0x02 ; out dx, al ; select VGA sequencer map mask register
mov dx, 0x03c4 ; mov al, 0x0f
out dx, al ; select VGA sequencer map mask register ; inc dx
mov al, 0x0f ; out dx, al ; set mask for all planes 0-3
inc dx ; mov al, 0x08
out dx, al ; set mask for all planes 0-3 ; pop dx
; out dx, al ; select GDC bit mask register
mov al, 0x08
pop dx
out dx, al ; select GDC bit mask register
; for writes to 0x03cf ; for writes to 0x03cf
gmok2: gmok2:
push ds push ds

View File

@ -3,6 +3,7 @@
;; Copyright (C) 2010 KolibriOS team. All rights reserved. ;; ;; Copyright (C) 2010 KolibriOS team. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; HT.inc ;; ;;
;; ;; ;; ;;
;; AMD HyperTransport bus control ;; ;; AMD HyperTransport bus control ;;
;; ;; ;; ;;
@ -22,6 +23,9 @@ HTIU_NB_INDEX equ 0xF0000094 ; HyperTransport indirect config space access
; This code is a part of Kolibri-A and will only work with AMD RS760+ chipsets ; 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 align 4
;------------------------------------------ ;------------------------------------------
@ -71,7 +75,7 @@ rs7xx_nbconfig_write_pci:
align 4 align 4
rs7xx_unlock_bar3: rs7xx_unlock_bar3:
mov eax, NB_MISC_INDEX mov eax, NB_MISC_INDEX
mov ebx, 0x080 ; reg#0; write-enable mov ebx, 0x080 ; NBMISCIND:0x0; write-enable
call rs7xx_nbconfig_write_pci ; set index call rs7xx_nbconfig_write_pci ; set index
mov eax, NB_MISC_DATA mov eax, NB_MISC_DATA
call rs7xx_nbconfig_read_pci ; read data call rs7xx_nbconfig_read_pci ; read data
@ -84,6 +88,90 @@ rs7xx_unlock_bar3:
call rs7xx_nbconfig_write_pci ; set index call rs7xx_nbconfig_write_pci ; set index
ret 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 align 4
rs780_read_misc: rs780_read_misc:
@ -192,96 +280,4 @@ rs780_write_htiu:
;***************************************************************************
; 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 $

View File

@ -87,10 +87,9 @@ pci_ext_config:
jb .check_HT_mmio jb .check_HT_mmio
.pcie_failed: .pcie_failed:
mov esi, boot_pcie_fail jmp $
call boot_log ; xor eax, eax
xor eax, eax ; ret ; <<<<<<<<< FAILURE >>>>>>>>>
ret ; <<<<<<<<< FAILURE >>>>>>>>>
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------

View File

@ -252,8 +252,13 @@ Screen_Max_Y equ (OS_BASE+0x000FE04)
BytesPerScanLine equ (OS_BASE+0x000FE08) BytesPerScanLine equ (OS_BASE+0x000FE08)
SCR_MODE equ (OS_BASE+0x000FE0C) SCR_MODE equ (OS_BASE+0x000FE0C)
LFBAddress equ (OS_BASE+0x000FE80) mmio_pcie_cfg_addr equ (OS_BASE+0x000FE74)
UserDMAaddr equ (OS_BASE+0x000FE84) 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)
BTN_ADDR equ (OS_BASE+0x000FE88) BTN_ADDR equ (OS_BASE+0x000FE88)
MEM_AMOUNT equ (OS_BASE+0x000FE8C) MEM_AMOUNT equ (OS_BASE+0x000FE8C)

View File

@ -57,21 +57,15 @@ keymap_alt:
boot_setmouse db 'Setting mouse',0 boot_setmouse db 'Setting mouse',0
boot_windefs db 'Setting window defaults',0 boot_windefs db 'Setting window defaults',0
boot_bgr db 'Calculating background',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_setrports db 'Setting addresses for IRQs',0
boot_setostask db 'Setting OS task',0 boot_setostask db 'Setting OS task',0
boot_allirqs db 'Unmasking all IRQs',0 boot_allirqs db 'Unmasking all IRQs',0
boot_tsc db 'Reading TSC',0 boot_tsc db 'Reading TSC',0
boot_cpufreq db 'CPU frequency is ',' ',' MHz',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_failed db 'Failed to start first app',0
boot_mtrr db 'Setting MTRR',0 boot_mtrr db 'Setting MTRR',0
boot_uDMA_ok db 'Set user DMA OK',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 if preboot_blogesc
boot_tasking db 'All set - press ESC to start',0 boot_tasking db 'All set - press ESC to start',0
end if end if
@ -87,7 +81,7 @@ msg_www db 'please visit www.kolibrios.org',13,10,0
msg_CR db 13,10,0 msg_CR db 13,10,0
aSis db 'SIS',0 aSis db 'SIS',0
intel_str db "GenuineIntel",0 ;intel_str db "GenuineIntel",0
AMD_str db "AuthenticAMD",0 AMD_str db "AuthenticAMD",0
;szSound db 'SOUND',0 ;szSound db 'SOUND',0
@ -469,4 +463,6 @@ BiosDisksData rb 200h
BiosDiskCaches rb 80h*(cache_ide1-cache_ide0) BiosDiskCaches rb 80h*(cache_ide1-cache_ide0)
BiosDiskPartitions rd 80h BiosDiskPartitions rd 80h
diff16 "UGlobals start ",0,$
IncludeUGlobals IncludeUGlobals

View File

@ -12,91 +12,71 @@ MEM_WB equ 6 ;write-back memory
MEM_WC equ 1 ;write combined memory MEM_WC equ 1 ;write combined memory
MEM_UC equ 0 ;uncached 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 align 4
proc init_mem proc init_mem
; calculate maximum allocatable address and number of allocatable pages
mov edi, BOOT_VAR-OS_BASE + 0x9104 mov esi, (PCIe_CONFIG_SPACE-OS_BASE) ; esi will hold total amount of memory
mov ecx, [edi-4] mov edx, esi ; edx will hold maximum allocatable address
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 [MEM_AMOUNT-OS_BASE], esi
mov [pg_data.mem_amount-OS_BASE], esi mov [pg_data.mem_amount-OS_BASE], esi
shr esi, 12 shr esi, 12
mov [pg_data.pages_count-OS_BASE], esi mov [pg_data.pages_count-OS_BASE], esi ; max number of PTEs ?
shr edx, 12 shr edx, 12
add edx, 31 add edx, 31
and edx, not 31 and edx, not 31
shr edx, 3 shr edx, 3
mov [pg_data.pagemap_size-OS_BASE], edx mov [pg_data.pagemap_size-OS_BASE], edx ; size of sys_pgmap structure
add edx, (sys_pgmap-OS_BASE)+4095 add edx, (sys_pgmap-OS_BASE)+4095
and edx, not 4095 and edx, not 4095
mov [tmp_page_tabs], edx mov [tmp_page_tabs], edx ; free zone to build PTEs
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 mov edx, (HEAP_BASE-OS_BASE+HEAP_MIN_SIZE)/4096
.set:
mov [pg_data.kernel_pages -OS_BASE], edx mov [pg_data.kernel_pages -OS_BASE], edx
shr edx, 10 shr edx, 10
mov [pg_data.kernel_tables-OS_BASE], edx mov [pg_data.kernel_tables-OS_BASE], edx
xor eax, eax mov edx, (sys_pgdir-OS_BASE)+ 0x800 ; (0x800 = OS_BASE shr 20)
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 mov ebx, cr4
or ebx, CR4_PSE or ebx, CR4_PSE
@ -104,19 +84,18 @@ proc init_mem
mov cr4, ebx mov cr4, ebx
dec [pg_data.kernel_tables-OS_BASE] dec [pg_data.kernel_tables-OS_BASE]
mov [edx], eax mov [edx], eax ; map first (physical) 4M bytes
add edx, 4 add edx, 4
mov edi, [tmp_page_tabs] mov edi, [tmp_page_tabs]
mov ecx, [pg_data.kernel_tables-OS_BASE] mov ecx, [pg_data.kernel_pages -OS_BASE] ; safety cleaning of already-zeroed space
shl ecx, 10
xor eax, eax xor eax, eax
rep stosd rep stosd
mov ecx, [pg_data.kernel_tables-OS_BASE] mov ecx, [pg_data.kernel_tables-OS_BASE] ; build some PDEs to hold empty PTEs
mov eax, [tmp_page_tabs] mov eax, [tmp_page_tabs]
or eax, PG_SW or eax, PG_SW
mov edi, edx mov edi, edx ; edi = sys_pgdir+0x804
.map_kernel_tabs: .map_kernel_tabs:
stosd stosd
@ -124,6 +103,7 @@ proc init_mem
dec ecx dec ecx
jnz .map_kernel_tabs 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 dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
mov edi, (sys_pgdir-OS_BASE) mov edi, (sys_pgdir-OS_BASE)
@ -286,16 +266,9 @@ init_BIOS32:
ret ret
align 4 align 4
proc test_cpu test_cpu: ; only AMD machines supported
locals
cpu_type dd ?
cpu_id dd ?
cpu_Intel dd ?
cpu_AMD dd ?
endl
xor eax, eax xor eax, eax
mov [cpu_type], eax
mov [cpu_caps-OS_BASE], eax mov [cpu_caps-OS_BASE], eax
mov [cpu_caps+4-OS_BASE], eax mov [cpu_caps+4-OS_BASE], eax
@ -308,12 +281,10 @@ proc test_cpu
pushfd pushfd
pop eax pop eax
xor eax, ecx xor eax, ecx
mov [cpu_type], CPU_386 jz $ ; 386
jz .end_cpuid
push ecx push ecx
popfd popfd
mov [cpu_type], CPU_486
mov eax, ecx mov eax, ecx
xor eax, 0x200000 xor eax, 0x200000
push eax push eax
@ -321,8 +292,7 @@ proc test_cpu
pushfd pushfd
pop eax pop eax
xor eax, ecx xor eax, ecx
je .end_cpuid je $ ; 486
mov [cpu_id], 1
xor eax, eax xor eax, eax
cpuid cpuid
@ -330,39 +300,15 @@ proc test_cpu
mov [cpu_vendor-OS_BASE], ebx mov [cpu_vendor-OS_BASE], ebx
mov [cpu_vendor+4-OS_BASE], edx mov [cpu_vendor+4-OS_BASE], edx
mov [cpu_vendor+8-OS_BASE], ecx 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] cmp ebx, dword [AMD_str-OS_BASE]
jne .unknown jne $
cmp edx, dword [AMD_str+4-OS_BASE] cmp edx, dword [AMD_str+4-OS_BASE]
jne .unknown jne $
cmp ecx, dword [AMD_str+8-OS_BASE] cmp ecx, dword [AMD_str+8-OS_BASE]
jne .unknown jne $
mov [cpu_AMD], 1
cmp eax, 1 cmp eax, 1
jl .unknown jl $
mov eax, 1 mov eax, 1
cpuid cpuid
mov [cpu_sign-OS_BASE], eax mov [cpu_sign-OS_BASE], eax
@ -372,16 +318,6 @@ proc test_cpu
shr eax, 8 shr eax, 8
and eax, 0x0f and eax, 0x0f
ret 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

View File

@ -130,6 +130,8 @@ include "boot/bootcode.inc" ; 16 bit system boot code
include "bus/pci/pci16.inc" include "bus/pci/pci16.inc"
include "detect/biosdisk.inc" include "detect/biosdisk.inc"
diff16 "end of code16 ",0,$
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; SWITCH TO 32 BIT PROTECTED MODE ;; ;; SWITCH TO 32 BIT PROTECTED MODE ;;
@ -192,55 +194,40 @@ tmp_gdt:
dw 11011111b *256 +10010010b dw 11011111b *256 +10010010b
db 0x00 db 0x00
diff16 "end of tmp_gdt ",0,$
include "data16.inc" include "data16.inc"
diff16 "end of data16 ",0,$
use32 use32
org $+0x10000 org $+0x10000
align 4 align 4
B32: B32:
diff16 "32-bit code start ",0,$
mov ax,os_stack ; Selector for os mov ax,os_stack ; Selector for os
mov ds,ax mov ds,ax
mov es,ax mov es,ax
mov fs,ax mov fs,ax
mov gs,ax mov gs,ax
mov ss,ax mov ss,ax
mov esp,0x3ec00 ; Set stack mov esp,0x4ec00 ; Set stack
; CLEAR 0x280000 - HEAP_BASE ;-------------------------------------------------------------------------------
call preinit_mem ; (init.inc)
xor eax,eax call test_cpu ; (init.inc - to be moved to bus/CPU.inc)
mov edi,0x280000
mov ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
cld
rep stosd
mov edi,0x40000
mov ecx,(0x90000-0x40000)/4
rep stosd
; 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 bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
call init_BIOS32 call init_BIOS32 ; (init.inc - to be removed later)
; PCIe extended config space access
call rs7xx_pcie_init ; (bus/HT.inc)
; MEMORY MODEL ; MEMORY MODEL
call init_mem call init_mem ; (init.inc)
call init_page_map call init_page_map ; (init.inc)
; ENABLE PAGING ; ENABLE PAGING
@ -378,59 +365,35 @@ high_code:
mov edi, BiosDisksData mov edi, BiosDisksData
rep movsd rep movsd
; GRAPHICS ADDRESSES ; GRAPHICS ADDRESSES
and byte [BOOT_VAR+0x901e],0x0 and byte [BOOT_VAR+0x901e],0x0
mov eax,[BOOT_VAR+0x9018] mov eax,[BOOT_VAR+0x9018]
mov [LFBAddress],eax mov [LFBAddress],eax
;==
cmp [SCR_MODE],word 0100000000000000b cmp [SCR_MODE],word 0100000000000000b
jge setvesa20 jge setvesa20
mov eax, 0xDEADBEEF mov eax, 0xDEADBEEF
hlt hlt
; === EGA, VGA & Vesa 1.2 modes not supported === ; === EGA, VGA & Vesa 1.2 modes not supported ===
setvesa20: setvesa20:
; mov [PUTPIXEL],dword Vesa20_putpixel24 ; Vesa 2.0 24bpp modes
; mov [GETPIXEL],dword Vesa20_getpixel24
; cmp [ScreenBPP],byte 24
; jz v20ga24
v20ga32: v20ga32:
mov [PUTPIXEL],dword Vesa20_putpixel32 mov [PUTPIXEL],dword Vesa20_putpixel32
mov [GETPIXEL],dword Vesa20_getpixel32 mov [GETPIXEL],dword Vesa20_getpixel32
; -------- Fast System Call init ---------- ; -------- 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: .SEnP:
; AMD SYSCALL/SYSRET ; 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 mov ecx, MSR_AMD_EFER
rdmsr rdmsr
or eax, 1 ; bit_0 - System Call Extension (SCE) or eax, 1 ; bit_0 - System Call Extension (SCE)
wrmsr wrmsr
; Bits of EDX : ; Bits of EDX :
; Bit 3116 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. ; and the contents of this field, plus 8, are copied into the SS register.
; Bit 150 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. ; 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! mov edx, 0x1B000B ; RING3 task stack will be used for fast syscalls!
@ -487,7 +450,7 @@ high_code:
call init_LFB call init_LFB
call init_fpu call init_fpu
call init_malloc call init_malloc
;-
stdcall alloc_kernel_space, 0x51000 stdcall alloc_kernel_space, 0x51000
mov [default_io_map], eax mov [default_io_map], eax
@ -743,9 +706,7 @@ end if
mov [CPU_FREQ],eax ; save tsc / sec mov [CPU_FREQ],eax ; save tsc / sec
; mov ebx, 1000000 ; mov ebx, 1000000
; div ebx ; div ebx
; ¢®®¡é¥-â® ¯à®¨§¢®¤¨â¥«ì­®áâì ¢ ¤ ­­®¬ ª®­ªà¥â­®¬ ¬¥á⥠; faster division possible:
; ᮢ¥à襭­® ­¥ªà¨â¨ç­ , ­® çâ®¡ë § âª­ãâì «î¡¨â¥«¥©
; ®¯â¨¬¨§¨àãîé¨å ª®¬¯¨«ïâ®à®¢ Ÿ‚“...
mov edx, 2251799814 mov edx, 2251799814
mul edx mul edx
shr edx, 19 shr edx, 19
@ -783,21 +744,6 @@ end if
call stack_init call stack_init
call fdc_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 ; LOAD DEFAULT SKIN
@ -824,9 +770,6 @@ end if
call init_userDMA ; <<<<<<<<< ============== core/memory.inc ================= call init_userDMA ; <<<<<<<<< ============== core/memory.inc =================
mov esi, boot_uDMA_ok mov esi, boot_uDMA_ok
call boot_log call boot_log
; call pci_ext_config ; <<<<<<<<< bus/pci/pcie.inc
;-------------------------------------------------------------------------------
call rs7xx_pcie_init ; <<<<<<<<< bus/ht.inc
; LOAD FIRST APPLICATION ; LOAD FIRST APPLICATION
cli cli
@ -4901,9 +4844,12 @@ scan_rsdp:
ret ret
end if end if
diff16 "End of 32-code ",0,$
include "data32.inc" include "data32.inc"
__REV__ = __REV __REV__ = __REV
uglobals_size = $ - endofcode uglobals_size = $ - endofcode
diff16 "end of kernel code",0,$ diff16 "Zero-filled blk",0,endofcode
diff16 "End of kernel ",0,$

View File

@ -246,7 +246,7 @@ include "gui/skincode.inc"
; Pci functions ; Pci functions
include "bus/pci/pci32.inc" include "bus/pci/pci32.inc"
include "bus/pci/PCIe.inc" ;include "bus/pci/PCIe.inc"
include "bus/HT.inc" ; AMD HyperTransport bus control include "bus/HT.inc" ; AMD HyperTransport bus control
; Floppy drive controller ; Floppy drive controller

View File

@ -122,9 +122,13 @@
; FE04 dword screen y size ; FE04 dword screen y size
; FE08 dword screen y multiplier ; FE08 dword screen y multiplier
; FE0C dword screen mode ; FE0C dword screen mode
; FE10 -> FE7F free (112) ; FE10 -> FE73 free (100)
; FE80 dword physical address of LFB ; FE74 dword PCIe extended (memory-mappable) config space - physical address
; FE84 dword physical address of user-accessible static system buffer ; 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
; FE88 dword address of button list ; FE88 dword address of button list
; FE8C dword memory to use ; FE8C dword memory to use
; FE90 -> FEFF free (112) ; FE90 -> FEFF free (112)
@ -138,7 +142,16 @@
; FFFF byte do not change task for 1/100 sec. ; FFFF byte do not change task for 1/100 sec.
; ;
; 0x80010000 -> 6CBFF kernel, 32-bit run-time code (up to 371 Kb) ; 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) ; 0x8006CC00 -> 6DBFF stack at boot time (4Kb)
; ;
; 0x8006DC00 -> 6E5FF basic text font II ; 0x8006DC00 -> 6E5FF basic text font II
@ -192,6 +205,8 @@
; 0x800A0000 -> AFFFF screen access area ; 0x800A0000 -> AFFFF screen access area
; 0x800B0000 -> FFFFF bios rest in peace -area (320k) ? ; 0x800B0000 -> FFFFF bios rest in peace -area (320k) ?
; 0x80100000 -> 27FFFF diskette image (1m5) ; 0x80100000 -> 27FFFF diskette image (1m5)
; 0x80280000 -> HEAP_BASE zero-filled zone after preinit_mem
; 0x80280000 -> 281FFF ramdisk fat (8k) ; 0x80280000 -> 281FFF ramdisk fat (8k)
; 0x80282000 -> 283FFF floppy fat (8k) ; 0x80282000 -> 283FFF floppy fat (8k)
; ;