From e5b88861350e0d85d01f6a33abe4275a1083a04f Mon Sep 17 00:00:00 2001 From: "Artem Jerdev (art_zh)" Date: Thu, 2 Sep 2010 20:24:07 +0000 Subject: [PATCH] 1) SouthBridge utilities; 2) reverted for the old (but stable) 62syscall for a while... git-svn-id: svn://kolibrios.org@1599 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/Kolibri-A/trunk/bus/HT.INC | 153 +- .../branches/Kolibri-A/trunk/bus/SB/SB710.ASM | 131 ++ .../branches/Kolibri-A/trunk/bus/pci/PCIe.inc | 11 + .../Kolibri-A/trunk/bus/pci/pci32.inc | 432 ++-- .../branches/Kolibri-A/trunk/core/memory.inc | 1915 ++++++++--------- .../branches/Kolibri-A/trunk/core/syscall.inc | 4 +- kernel/branches/Kolibri-A/trunk/data32.inc | 422 ++-- kernel/branches/Kolibri-A/trunk/kernel.asm | 10 +- .../Kolibri-A/utilities/SB700/LPC_REG.ASM | 345 +++ .../Kolibri-A/utilities/SB700/PCI_REG.ASM | 344 +++ .../Kolibri-A/utilities/SB700/SB_CM_RG.ASM | 314 +++ .../Kolibri-A/utilities/SB700/SB_IO_RG.ASM | 331 +++ .../Kolibri-A/utilities/SB700/SB_PM2RG.ASM | 314 +++ .../Kolibri-A/utilities/SB700/SB_PM_RG.ASM | 314 +++ 14 files changed, 3544 insertions(+), 1496 deletions(-) create mode 100644 kernel/branches/Kolibri-A/trunk/bus/SB/SB710.ASM create mode 100644 kernel/branches/Kolibri-A/utilities/SB700/LPC_REG.ASM create mode 100644 kernel/branches/Kolibri-A/utilities/SB700/PCI_REG.ASM create mode 100644 kernel/branches/Kolibri-A/utilities/SB700/SB_CM_RG.ASM create mode 100644 kernel/branches/Kolibri-A/utilities/SB700/SB_IO_RG.ASM create mode 100644 kernel/branches/Kolibri-A/utilities/SB700/SB_PM2RG.ASM create mode 100644 kernel/branches/Kolibri-A/utilities/SB700/SB_PM_RG.ASM diff --git a/kernel/branches/Kolibri-A/trunk/bus/HT.INC b/kernel/branches/Kolibri-A/trunk/bus/HT.INC index 6490d3bfc1..25e2ccbcc9 100644 --- a/kernel/branches/Kolibri-A/trunk/bus/HT.INC +++ b/kernel/branches/Kolibri-A/trunk/bus/HT.INC @@ -7,13 +7,16 @@ ;; ;; ;; AMD HyperTransport bus control ;; ;; ;; -;; art_zh ;; +;; art_zh ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $Revision: 1554 $ - +NB_MISC_INDEX equ 0xF0000060 ; NB Misc indirect access +NB_MISC_DATA equ 0xF0000064 +PCIEIND_INDEX equ 0xF00000E0 ; PCIe Core indirect config space access +HTIU_NB_INDEX equ 0xF0000094 ; HyperTransport indirect config space access ;============================================================================= ; @@ -44,6 +47,10 @@ rs7xx_nbconfig_flush_pci: align 4 +;------------------------------------------ +; params: al = nbconfig register# +; ebx = register content +; rs7xx_nbconfig_write_pci: and eax, 0x0FC ; leave register# only or eax, 0x80000000 ; bdf = 0:0.0 @@ -54,6 +61,138 @@ rs7xx_nbconfig_write_pci: out dx, eax ret +;*************************************************************************** +; Function +; rs7xx_unlock_bar3: unlocks the BAR3 register of nbconfig that +; makes pcie config address space visible +; ----------------------- +; in: nothing out: nothing destroys: eax ebx edx +; +;*************************************************************************** +align 4 +rs7xx_unlock_bar3: + mov eax, NB_MISC_INDEX + 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 + mov ebx, eax + and ebx, 0xFFFFFFF7 ; clear bit3 + mov eax, NB_MISC_DATA + call rs7xx_nbconfig_write_pci ; write it back + mov eax, NB_MISC_INDEX + xor ebx, ebx ; reg#0; write-locked + call rs7xx_nbconfig_write_pci ; set index + ret + +;-------------------------------------------------------------- +align 4 +rs780_read_misc: +; in: eax(al) - reg# out: eax = NBMISCIND data + push edx + mov edx, NB_MISC_INDEX + and eax, 0x07F + mov [edx], eax + add dl, 4 + mov eax, [edx] + pop edx + ret + +;------------------------------------------- +align 4 +rs780_write_misc: +; in: eax(al) - reg# ebx = NBMISCIND data + push edx + mov edx, NB_MISC_INDEX + and eax, 0x07F + or eax, 0x080 ; set WE + mov [edx], eax + add dl, 4 + mov [edx], ebx + sub dl, 4 + xor eax, eax + mov [edx], eax ; safety last + pop edx + ret + +;------------------------------------------------------------- +align 4 +rs780_read_pcieind: +; in: ah = bridge#, al = reg# out: eax = PCIEIND data + push edx + xor edx, edx + mov ah, dl ; bridge# : 0 = Core+GFX; 0x10 = Core+SB + and dl, 15 ; 0x20 = Core+GPP; 2..12 = a PortBridge + shl edx, 15 ; device# + add edx, PCIEIND_INDEX ; full bdf-address + and eax, 0x30FF + or al, al + jnz @f + shl eax, 4 ; set bits 17..16 for a Core bridge +@@: + mov [edx], eax + add dl, 4 + mov eax, [edx] + pop edx + ret + +;------------------------------------------- +align 4 +rs780_write_pcieind: +; in: ah = bridge#, al = reg#, ebx = PCIEIND data + push edx + xor edx, edx + mov ah, dl ; bridge# : 0 = Core+GFX; 0x10 = Core+SB + and dl, 15 ; 0x20 = Core+GPP; 2..12 = a PortBridge + shl edx, 15 ; device# + add edx, PCIEIND_INDEX ; full bdf-address + and eax, 0x30FF + or al, al + jnz @f + shl eax, 4 ; set bits 17..16 for a Core bridge +@@: + mov [edx], eax + add dl, 4 + mov [edx], ebx + sub dl, 4 + xor eax, eax + mov [edx], eax ; safety last + pop edx + ret + +;------------------------------------------------ +align 4 +rs780_read_htiu: +; in: al = reg# | out: eax = HTIU data +;------------------------------------------------ + push edx + mov edx, HTIU_NB_INDEX + and eax, 0x07F + mov [edx], eax + add dl, 4 + mov eax, [edx] + pop edx + ret +;------------------------------------------------ +align 4 +rs780_write_htiu: +; in: al = reg#; ebx = data +;------------------------------------------------ + push edx + mov edx, HTIU_NB_INDEX + and eax, 0x07F + or eax, 0x100 + mov [edx], eax + add dl, 4 + mov [edx], ebx + sub dl, 4 + xor eax, eax + mov [edx], eax + pop edx + ret + + + ;*************************************************************************** ; Function ; rs7xx_pcie_init: @@ -66,6 +205,7 @@ rs7xx_nbconfig_write_pci: align 4 rs7xx_pcie_init: + call rs7xx_unlock_bar3 mov al, 0x7C ; NB_IOC_CFG_CNTL call rs7xx_nbconfig_read_pci mov ebx, eax @@ -120,7 +260,6 @@ rs7xx_pcie_init: xor dx, dx ; PDEs counter @@: mov dword[ebx], eax ; map 4 buses - invlpg [ecx] ; next PgDir entry add bx, 4 ; new PDE add eax, 0x400000 ; +4M phys. add ecx, 0x400000 ; +4M lin. @@ -128,6 +267,8 @@ rs7xx_pcie_init: 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 @@ -135,13 +276,11 @@ rs7xx_pcie_init: .rs7xx_pcie_fail: mov esi, boot_rs7xx_fail call boot_log - ret + jmp $ .rs7xx_pcie_blocked: mov esi, boot_rs7xx_blkd call boot_log - call pci_ext_config - jmp .addr_found - ret + jmp $ diff --git a/kernel/branches/Kolibri-A/trunk/bus/SB/SB710.ASM b/kernel/branches/Kolibri-A/trunk/bus/SB/SB710.ASM new file mode 100644 index 0000000000..9588568b7f --- /dev/null +++ b/kernel/branches/Kolibri-A/trunk/bus/SB/SB710.ASM @@ -0,0 +1,131 @@ +$Revision: 1598 $ + +SMBUS_PCIE_ADDR equ 0xF00A0000 ; bdf0:20.0 = SB7xx SMBus PCI Config Registers +LPC_PCIE_ADDR equ 0xF00A3000 ; bdf0:20.3 = SB7xx LPC ISA bridge Config Registers + +SB_SIO_INDEX equ 0x2e + +;--------------------------------------------------------------------- +align 4 +smbus_read_pciconfig: +; in: dl = reg# | out: eax = data + mov ebx, SMBUS_PCIE_ADDR + and edx, 0x0FC + mov eax, dword [ebx+edx] + ret +;------------------------------------------------ +align 4 +smbus_write_pciconfig: +; in: dl = reg#; eax = data + mov ebx, SMBUS_PCIE_ADDR + and edx, 0x0FC + mov dword [ebx+edx], eax + ret + +;-------------------------------------------------------------------- +align 4 +lpc_read_pciconfig: +; in: dl = reg# | out: eax = data + mov ebx, LPC_PCIE_ADDR + and edx, 0x0FC + mov eax, dword [ebx+edx] + ret +;------------------------------------------------ +align 4 +lpc_write_pciconfig: +; in: dl = reg#; eax = data + mov ebx, LPC_PCIE_ADDR + and edx, 0x0FC + mov dword [ebx+edx], eax + ret + +;-------------------------------------------------------------------- +align 4 +read_sio_cfg: +; in: al = reg# | out: al = data + mov dx, SB_SIO_INDEX + out dx, al + inc dl + in al, dx + ret + +;------------------------------------------------ +align 4 +write_sio_cfg: +; in: al = reg#; ah = data +;------------------------------------------------ + mov dx, SB_SIO_INDEX + out dx, al + inc dl + xchg al, ah + out dx, al + xchg al, ah + ret +;------------------------------------------------ +align 4 +enter_sio_cfg_mode: +; the magic sequence to unlock the port +;------------------------------------------------ + mov dx, SB_SIO_INDEX + mov eax, 0x55550187 ; low byte first + out dx, al + shr eax, 8 + out dx, al + shr eax, 8 + out dx, al + shr eax, 8 + out dx, al + ret + +;----------------------------------------------------------------------- +; ATTENTION: the functions assume that RESET# signals use pins 84 and 34 +; of IT8712F SuperIO chip. These signals may be (and will be!) different +; for every particular motherboard and SIO. Please refer to your m/board +; documentation to define the correct pins and GPIO lines! +; +; Note this example DOES NOT PRETEND to be 100% correct implementation +; of PCIe hotplug techniques !! +;----------------------------------------------------------------------- +align 4 +init_pcie_slot_control: +;------------------------------------------------ + call enter_sio_cfg_mode + mov ax, 0x0707 ; LDN = 07 + call write_sio_cfg + mov al, 0x25 + call read_sio_cfg ; ah = reg25h (Multy-function pin selector) + or ah, 3 ; set bits 0, 1 (GPIO) + call write_sio_cfg + mov al, 0x2A + call read_sio_cfg ; ah = reg2Ah (Extended fn pin selector) + or ah, 3 ; set bits 0, 1 (GPIO) + call write_sio_cfg + mov al, 0xB8 + call read_sio_cfg ; ah = regB8h (internal pull-up enable) + or ah, 3 ; set bits 0, 1 + call write_sio_cfg + mov al, 0xC0 + call read_sio_cfg ; ah = regC0h (simple IO enable) + or ah, 3 ; set bits 0, 1 + call write_sio_cfg + mov ax, 0x0202 ; Lock SIO config ports + call write_sio_cfg + ret + +align 4 +reset_pcie_slot: +;------------------------------------------------ + call enter_sio_cfg_mode + mov ax, 0x0707 ; LDN = 07 + call write_sio_cfg + mov al, 0xB0 + call read_sio_cfg ; ah = regB0h (Pin polarity) + and ah, 0xFC ; invert bits 0, 1 + call write_sio_cfg + or ah, 3 ; restore bits 0, 1 + call write_sio_cfg + mov ax, 0x0202 ; Lock SIO config ports + call write_sio_cfg + ret + + diff --git a/kernel/branches/Kolibri-A/trunk/bus/pci/PCIe.inc b/kernel/branches/Kolibri-A/trunk/bus/pci/PCIe.inc index 6c96de6385..323934ced8 100644 --- a/kernel/branches/Kolibri-A/trunk/bus/pci/PCIe.inc +++ b/kernel/branches/Kolibri-A/trunk/bus/pci/PCIe.inc @@ -94,3 +94,14 @@ pci_ext_config: call boot_log ret ; <<<<<<<<< FAILURE >>>>>>>>> + +;-------------------------------------------------------------------------- +; this routine is platform-specific and used to change some BIOS settengs +; pcie_init_gfx +; sets the GPP mode of GFX bus + + +; this option disables external graphics +pcie_init_gfx: + + ret diff --git a/kernel/branches/Kolibri-A/trunk/bus/pci/pci32.inc b/kernel/branches/Kolibri-A/trunk/bus/pci/pci32.inc index 11595e3876..14e9c83edf 100644 --- a/kernel/branches/Kolibri-A/trunk/bus/pci/pci32.inc +++ b/kernel/branches/Kolibri-A/trunk/bus/pci/pci32.inc @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;; ;; @@ -8,11 +8,13 @@ ;; ;; ;; 32 bit PCI driver code ;; ;; ;; +;; Version 0.4 February 2nd, 2010 ;; ;; Version 0.3 April 9, 2007 ;; ;; Version 0.2 December 21st, 2002 ;; ;; ;; ;; Author: Victor Prodan, victorprodan@yahoo.com ;; ;; Mihailov Ilia, ghost.nsk@gmail.com ;; +;; Artem Jerdev, kolibri@jerdev.co.uk ;; ;; Credits: ;; ;; Ralf Brown ;; ;; Mike Hibbett, mikeh@oceanfree.net ;; @@ -30,116 +32,64 @@ $Revision$ ; Description ; entry point for system PCI calls ;*************************************************************************** -mmio_pci_addr equ 0x400 ; set actual PCI address here to activate user-MMIO - -iglobal -align 4 -f62call: - dd pci_api.0 - dd pci_api.1 - dd pci_api.2 - dd pci_api.not_support ;3 - dd pci_read_reg ;4 byte - dd pci_read_reg ;5 word - dd pci_read_reg ;6 dword - dd pci_api.not_support ;7 - dd pci_write_reg ;8 byte - dd pci_write_reg ;9 word - dd pci_write_reg ;10 dword -if defined mmio_pci_addr - dd pci_mmio_init ;11 - dd pci_mmio_map ;12 - dd pci_mmio_unmap ;13 -end if -f62_rcall: - dd pci_read_reg.0 ;4 byte - dd pci_read_reg.1 ;5 word - dd pci_read_reg.2 ;6 dword -f62_rcall2: - dd pci_read_reg_2.0 ;4 byte - dd pci_read_reg_2.1 ;5 word - dd pci_read_reg_2.2 ;6 dword -f62_wcall: - dd pci_write_reg.0 ;4 byte - dd pci_write_reg.1 ;5 word - dd pci_write_reg.2 ;6 dword -f62_wcall2: - dd pci_write_reg_2.0 ;4 byte - dd pci_write_reg_2.1 ;5 word - dd pci_write_reg_2.2 ;6 dword -endg +mmio_pci_addr dw 0x400 ; default PCI device bdf-address align 4 + pci_api: - movzx eax,bl + cmp [pci_access_enabled],1 - jne .no_pci_access_for_applications + jne no_pci_access_for_applications -if defined mmio_pci_addr - cmp eax, 13 - jb .not_support -else - cmp eax, 10 - jb .not_support -end if - call dword [f62call+eax*4] - mov dword [esp+32],eax - ret - - - -; or al,al -; jnz pci_fn_1 + or al,al + jnz pci_fn_1 ; PCI function 0: get pci version (AH.AL) -.0: - movzx eax, word [BOOT_VAR+0x9022] + movzx eax,word [BOOT_VAR+0x9022] ret -;pci_fn_1: -; cmp al,1 -; jnz pci_fn_2 +pci_fn_1: + cmp al,1 + jnz pci_fn_2 ; PCI function 1: get last bus in AL -.1: - movzx eax, byte [BOOT_VAR+0x9021] + mov al,[BOOT_VAR+0x9021] ret -;pci_fn_2: -; cmp al,2 -; jne pci_fn_3 +pci_fn_2: + cmp al,2 + jne pci_fn_3 ; PCI function 2: get pci access mechanism -.2: - movzx eax, byte [BOOT_VAR+0x9020] + mov al,[BOOT_VAR+0x9020] ret -;pci_fn_3: +pci_fn_3: -; cmp al,4 -; jz pci_read_reg ;byte -; cmp al,5 -; jz pci_read_reg ;word -; cmp al,6 -; jz pci_read_reg ;dword + cmp al,4 + jz pci_read_reg ;byte + cmp al,5 + jz pci_read_reg ;word + cmp al,6 + jz pci_read_reg ;dword -; cmp al,8 -; jz pci_write_reg ;byte -; cmp al,9 -; jz pci_write_reg ;word -; cmp al,10 -; jz pci_write_reg ;dword + cmp al,8 + jz pci_write_reg ;byte + cmp al,9 + jz pci_write_reg ;word + cmp al,10 + jz pci_write_reg ;dword -;if defined mmio_pci_addr -; cmp al,11 ; user-level MMIO functions -; jz pci_mmio_init -; cmp al,12 -; jz pci_mmio_map -; cmp al,13 -; jz pci_mmio_unmap -;end if + cmp al,11 ; user-level MMIO functions + jz pci_mmio_init + cmp al,12 + jz pci_mmio_map + cmp al,13 + jz pci_mmio_unmap + + + no_pci_access_for_applications: + + or eax,-1 -.not_support: -.no_pci_access_for_applications: - or eax,-1 ret ;*************************************************************************** @@ -148,20 +98,20 @@ end if ; ; Description ; creates a command dword for use with the PCI bus -; bus # in bh;ah -; device+func in ch;bh (dddddfff) -; register in cl;bl +; bus # in ah +; device+func in bh (dddddfff) +; register in bl ; -; command dword returned in ebx;eax ( 10000000 bbbbbbbb dddddfff rrrrrr00 ) +; command dword returned in eax ( 10000000 bbbbbbbb dddddfff rrrrrr00 ) ;*************************************************************************** align 4 pci_make_config_cmd: - shl ebx,8;eax,8 ; move bus to bits 16-23 - mov bx,cx;ax,bx ; combine all - and ebx,0xffffff;eax,0xffffff - or ebx,0x80000000;eax,0x80000000 + shl eax,8 ; move bus to bits 16-23 + mov ax,bx ; combine all + and eax,0xffffff + or eax,0x80000000 ret ;*************************************************************************** @@ -178,16 +128,12 @@ pci_make_config_cmd: align 4 pci_read_reg: - cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? - je pci_read_reg_2 - - ; mechanism 1 -; push esi ; save register size into ESI - mov esi,ebx;eax + push esi ; save register size into ESI + mov esi,eax and esi,3 call pci_make_config_cmd - mov eax,ebx;ebx,eax + mov ebx,eax ; get current state mov dx,0xcf8 in eax, dx @@ -201,100 +147,37 @@ pci_read_reg: and bl,3 or dl,bl ; add to port address first 2 bits of register address -; or esi,esi -; jz pci_read_byte1 -; cmp esi,1 -; jz pci_read_word1 -; cmp esi,2 -; jz pci_read_dword1 -; jmp pci_fin_read1 - jmp dword [f62_rcall+esi*4] + or esi,esi + jz pci_read_byte1 + cmp esi,1 + jz pci_read_word1 + cmp esi,2 + jz pci_read_dword1 + jmp pci_fin_read1 -.0: +pci_read_byte1: in al,dx - jmp .pci_fin_read1 -.1: + jmp pci_fin_read1 +pci_read_word1: in ax,dx - jmp .pci_fin_read1 -.2: + jmp pci_fin_read1 +pci_read_dword1: in eax,dx -; jmp pci_fin_read1 -.pci_fin_read1: + jmp pci_fin_read1 +pci_fin_read1: ; restore configuration control xchg eax,[esp] mov dx,0xcf8 out dx,eax pop eax - ;pop esi - ret -pci_read_reg_2: - - test ch,128;bh,128 ;mech#2 only supports 16 devices per bus - jnz pci_api.not_support - -; push esi ; save register size into ESI - mov esi,ebx;eax - and esi,3 - - push ebx;eax - mov eax,ebx - ;store current state of config space - mov dx,0xcf8 - in al,dx - mov ah,al - mov dl,0xfa - in al,dx - - xchg eax,[esp] - ; out 0xcfa,bus - mov al,ah - out dx,al - ; out 0xcf8,0x80 - mov dl,0xf8 - mov al,0x80 - out dx,al - ; compute addr - shr ch,3;bh,3 ; func is ignored in mechanism 2 - or ch,0xc0;bh,0xc0 - mov dx,cx;bx - -; or esi,esi -; jz pci_read_byte2 -; cmp esi,1 -; jz pci_read_word2 -; cmp esi,2 -; jz pci_read_dword2 -; jmp pci_fin_read2 - jmp dword [f62_rcall2+esi*4] - -.0: - in al,dx - jmp .pci_fin_read2 -.1: - in ax,dx - jmp .pci_fin_read2 -.2: - in eax,dx -; jmp pci_fin_read2 - -.pci_fin_read2: - - ; restore configuration space - xchg eax,[esp] - mov dx,0xcfa - out dx,al - mov dl,0xf8 - mov al,ah - out dx,al - - pop eax -; pop esi + pop esi ret -;pci_read_reg_err: -; or dword [esp+32],-1 -; ret +pci_read_reg_err: + xor eax,eax + dec eax + ret ;*************************************************************************** @@ -312,17 +195,12 @@ pci_read_reg_2: align 4 pci_write_reg: - cmp byte [BOOT_VAR+0x9020],2 ;what mechanism will we use? - je pci_write_reg_2 - - ; mechanism 1 -; push esi ; save register size into ESI - mov esi,ebx;eax - and esi,3 ;not need + push esi ; save register size into ESI + mov esi,eax + and esi,3 call pci_make_config_cmd - mov eax,ebx;ebx,eax - mov ecx,edx ;cross registers + mov ebx,eax ; get current state into ecx mov dx,0xcf8 in eax, dx @@ -337,121 +215,56 @@ pci_write_reg: or dl,bl mov eax,ecx -; or esi,esi -; jz pci_write_byte1 -; cmp esi,1 -; jz pci_write_word1 -; cmp esi,2 -; jz pci_write_dword1 -; jmp pci_fin_write1 - jmp dword [f62_wcall+esi*4] -.0: - out dx,al - jmp .pci_fin_write1 -.1: - out dx,ax - jmp .pci_fin_write1 -.2: - out dx,eax -.pci_fin_write1: + or esi,esi + jz pci_write_byte1 + cmp esi,1 + jz pci_write_word1 + cmp esi,2 + jz pci_write_dword1 + jmp pci_fin_write1 +pci_write_byte1: + out dx,al + jmp pci_fin_write1 +pci_write_word1: + out dx,ax + jmp pci_fin_write1 +pci_write_dword1: + out dx,eax + jmp pci_fin_write1 +pci_fin_write1: ; restore configuration control pop eax mov dl,0xf8 out dx,eax xor eax,eax - ;pop esi + pop esi ret -pci_write_reg_2: - - test ch,128;bh,128 ;mech#2 only supports 16 devices per bus - jnz pci_api.not_support - - -; push esi ; save register size into ESI - mov esi,eax - and esi,3 ;not need - - push eax - mov ecx,edx ;cross registers - ;store current state of config space - mov dx,0xcf8 - in al,dx - mov ah,al - mov dl,0xfa - in al,dx - xchg eax,[esp] - ; out 0xcfa,bus - mov al,ah - out dx,al - ; out 0xcf8,0x80 - mov dl,0xf8 - mov al,0x80 - out dx,al - ; compute addr - shr bh,3 ; func is ignored in mechanism 2 - or bh,0xc0 - mov dx,bx - ; write register - mov eax,ecx - -; or esi,esi -; jz pci_write_byte2 -; cmp esi,1 -; jz pci_write_word2 -; cmp esi,2 -; jz pci_write_dword2 -; jmp pci_fin_write2 - jmp dword [f62_wcall2+esi*4] -.0: - out dx,al - jmp .pci_fin_write2 -.1: - out dx,ax - jmp .pci_fin_write2 -.2: - out dx,eax -.pci_fin_write2: - ; restore configuration space - pop eax - mov dx,0xcfa - out dx,al - mov dl,0xf8 - mov al,ah - out dx,al +pci_write_reg_err: xor eax,eax - ;pop esi + dec eax ret -;pci_write_reg_err: -; xor eax,eax -; dec eax -; ret - -if defined mmio_pci_addr ; must be set above ;*************************************************************************** ; Function -; pci_mmio_init +; pci_mmio_init ; ; Description -; IN: cx = device's PCI bus address (bbbbbbbbdddddfff) -; Returns eax = user heap space available (bytes) +; IN: bx = device's PCI bus address (bbbbbbbbdddddfff) +; Returns eax = phys. address of user-accessible DMA block ; Error codes ; eax = -1 : PCI user access blocked, -; eax = -2 : device not registered for uMMIO service ; eax = -3 : user heap initialization failure ;*************************************************************************** pci_mmio_init: - cmp cx, mmio_pci_addr - jz @f - mov eax,-2 - ret -@@: + mov [mmio_pci_addr],bx + call init_heap ; (if not initialized yet) or eax,eax jz @f + mov eax, [UserDMAaddr] ret @@: mov eax,-3 @@ -460,15 +273,14 @@ pci_mmio_init: ;*************************************************************************** ; Function -; pci_mmio_map +; pci_mmio_map ; ; Description ; maps a block of PCI memory to user-accessible linear address ; -; WARNING! This VERY EXPERIMENTAL service is for one chosen PCI device only! -; The target device address should be set in kernel var mmio_pci_addr ; -; IN: ah = BAR#; +; IN: ah = BAR#; or +; IN: ah = 0xDA for DMA-mapping requests; ; IN: ebx = block size (bytes); ; IN: ecx = offset in MMIO block (in 4K-pages, to avoid misaligned pages); ; @@ -484,17 +296,21 @@ pci_mmio_init: ;*************************************************************************** pci_mmio_map: -;cross - mov eax,ebx - mov ebx,ecx - mov ecx,edx -;;;;;;;;;;;;;;;;;;; and edx,0x0ffff + cmp ah, 0xDA + jz .dma_map cmp ah,6 - jc .bar_0_5 - jz .bar_rom + jb .bar_0_5 + jz .bar_rom mov eax,-2 ret + +.dma_map: + push ecx + mov ecx,ebx + mov eax,[UserDMAaddr] + jmp .allocate_block + .bar_rom: mov ah, 8 ; bar6 = Expansion ROM base address .bar_0_5: @@ -506,7 +322,7 @@ pci_mmio_map: shl bl, 1 shl bl, 1 add bl, 0x10 ; now bl = BAR offset in PCI config. space - mov ax, mmio_pci_addr + mov ax, [mmio_pci_addr] mov bh, al ; bh = dddddfff mov al, 2 ; al : DW to read call pci_read_reg @@ -523,7 +339,9 @@ pci_mmio_map: pop ecx ; ecx = block size, bytes (expanded to whole page) mov ebx, ecx ; user_alloc destroys eax, ecx, edx, but saves ebx and eax, 0xFFFFFFF0 - push eax ; store MMIO physical address + keep 2DWords in the stack + +.allocate_block: + push eax ; store MMIO physical address + keep the stack 2x4b deep stdcall user_alloc, ecx or eax, eax jnz mmio_map_over @@ -542,9 +360,7 @@ mmio_map_over: pop edx ; edx = MMIO shift (pages) shl edx, 12 ; edx = MMIO shift (bytes) add eax, edx ; eax = uMMIO physical address - or eax, PG_SHARED - or eax, PG_UW - or eax, PG_NOCACHE + or eax, (PG_SHARED+PG_UW+PG_NOCACHE) mov edi, ebx call commit_pages mov eax, edi @@ -552,7 +368,7 @@ mmio_map_over: ;*************************************************************************** ; Function -; pci_mmio_unmap_page +; pci_mmio_unmap_page ; ; Description ; unmaps the linear space previously tied to a PCI memory block @@ -566,11 +382,9 @@ mmio_map_over: ;*************************************************************************** pci_mmio_unmap: - stdcall user_free, ecx;ebx + stdcall user_free, ebx ret -end if - ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= uglobal align 4 diff --git a/kernel/branches/Kolibri-A/trunk/core/memory.inc b/kernel/branches/Kolibri-A/trunk/core/memory.inc index bc0d688e83..98fe8be2ad 100644 --- a/kernel/branches/Kolibri-A/trunk/core/memory.inc +++ b/kernel/branches/Kolibri-A/trunk/core/memory.inc @@ -11,43 +11,43 @@ $Revision$ align 4 proc alloc_page - pushfd - cli - push ebx + pushfd + cli + push ebx ;//- cmp [pg_data.pages_free], 1 jle .out_of_memory ;//- - mov ebx, [page_start] - mov ecx, [page_end] + mov ebx, [page_start] + mov ecx, [page_end] .l1: - bsf eax,[ebx]; - jnz .found - add ebx,4 - cmp ebx, ecx - jb .l1 - pop ebx - popfd - xor eax,eax - ret + bsf eax,[ebx]; + jnz .found + add ebx,4 + cmp ebx, ecx + jb .l1 + pop ebx + popfd + xor eax,eax + ret .found: -;//- +;//- dec [pg_data.pages_free] jz .out_of_memory ;//- - btr [ebx], eax - mov [page_start],ebx - sub ebx, sys_pgmap - lea eax, [eax+ebx*8] - shl eax, 12 + btr [ebx], eax + mov [page_start],ebx + sub ebx, sys_pgmap + lea eax, [eax+ebx*8] + shl eax, 12 ;//- dec [pg_data.pages_free] - pop ebx - popfd - ret + pop ebx + popfd + ret ;//- .out_of_memory: - mov [pg_data.pages_free], 1 + mov [pg_data.pages_free], 1 xor eax, eax pop ebx popfd @@ -57,154 +57,154 @@ endp align 4 proc alloc_pages stdcall, count:dword - pushfd - push ebx - push edi - cli - mov eax, [count] - add eax, 7 - shr eax, 3 - mov [count], eax + pushfd + push ebx + push edi + cli + mov eax, [count] + add eax, 7 + shr eax, 3 + mov [count], eax ;//- - mov ebx, [pg_data.pages_free] - sub ebx, 9 - js .out_of_memory - shr ebx, 3 - cmp eax, ebx - jg .out_of_memory + mov ebx, [pg_data.pages_free] + sub ebx, 9 + js .out_of_memory + shr ebx, 3 + cmp eax, ebx + jg .out_of_memory ;//- - mov ecx, [page_start] - mov ebx, [page_end] + mov ecx, [page_start] + mov ebx, [page_end] .find: - mov edx, [count] - mov edi, ecx + mov edx, [count] + mov edi, ecx .match: - cmp byte [ecx], 0xFF - jne .next - dec edx - jz .ok - inc ecx - cmp ecx,ebx - jb .match + cmp byte [ecx], 0xFF + jne .next + dec edx + jz .ok + inc ecx + cmp ecx,ebx + jb .match .out_of_memory: .fail: - xor eax, eax - pop edi - pop ebx - popfd - ret + xor eax, eax + pop edi + pop ebx + popfd + ret .next: - inc ecx - cmp ecx, ebx - jb .find - pop edi - pop ebx - popfd - xor eax, eax - ret + inc ecx + cmp ecx, ebx + jb .find + pop edi + pop ebx + popfd + xor eax, eax + ret .ok: - sub ecx, edi - inc ecx - push esi - mov esi, edi - xor eax, eax - rep stosb - sub esi, sys_pgmap - shl esi, 3+12 - mov eax, esi - mov ebx, [count] - shl ebx, 3 - sub [pg_data.pages_free], ebx - pop esi - pop edi - pop ebx - popfd - ret + sub ecx, edi + inc ecx + push esi + mov esi, edi + xor eax, eax + rep stosb + sub esi, sys_pgmap + shl esi, 3+12 + mov eax, esi + mov ebx, [count] + shl ebx, 3 + sub [pg_data.pages_free], ebx + pop esi + pop edi + pop ebx + popfd + ret endp align 4 proc map_page stdcall,lin_addr:dword,phis_addr:dword,flags:dword - push ebx - mov eax, [phis_addr] - and eax, not 0xFFF - or eax, [flags] - mov ebx, [lin_addr] - shr ebx, 12 - mov [page_tabs+ebx*4], eax - mov eax, [lin_addr] - invlpg [eax] - pop ebx - ret + push ebx + mov eax, [phis_addr] + and eax, not 0xFFF + or eax, [flags] + mov ebx, [lin_addr] + shr ebx, 12 + mov [page_tabs+ebx*4], eax + mov eax, [lin_addr] + invlpg [eax] + pop ebx + ret endp align 4 map_space: ;not implemented - ret + ret align 4 proc free_page ;arg: eax page address - pushfd - cli - shr eax, 12 ;page index - bts dword [sys_pgmap], eax ;that's all! - cmc - adc [pg_data.pages_free], 0 - shr eax, 3 - and eax, not 3 ;dword offset from page_map - add eax, sys_pgmap - cmp [page_start], eax - ja @f - popfd - ret + pushfd + cli + shr eax, 12 ;page index + bts dword [sys_pgmap], eax ;that's all! + cmc + adc [pg_data.pages_free], 0 + shr eax, 3 + and eax, not 3 ;dword offset from page_map + add eax, sys_pgmap + cmp [page_start], eax + ja @f + popfd + ret @@: - mov [page_start], eax - popfd - ret + mov [page_start], eax + popfd + ret endp proc map_io_mem stdcall, base:dword, size:dword, flags:dword - push ebx - push edi - mov eax, [size] - add eax, 4095 - and eax, -4096 - mov [size], eax - stdcall alloc_kernel_space, eax - test eax, eax - jz .fail - push eax + push ebx + push edi + mov eax, [size] + add eax, 4095 + and eax, -4096 + mov [size], eax + stdcall alloc_kernel_space, eax + test eax, eax + jz .fail + push eax - mov edi, 0x1000 - mov ebx, eax - mov ecx,[size] - mov edx, [base] - shr eax, 12 - shr ecx, 12 - and edx, -4096 - or edx, [flags] + mov edi, 0x1000 + mov ebx, eax + mov ecx,[size] + mov edx, [base] + shr eax, 12 + shr ecx, 12 + and edx, -4096 + or edx, [flags] @@: - mov [page_tabs+eax*4], edx - ; push eax - invlpg [ebx] - ; pop eax - inc eax - add ebx, edi - add edx, edi - loop @B + mov [page_tabs+eax*4], edx + ; push eax + invlpg [ebx] + ; pop eax + inc eax + add ebx, edi + add edx, edi + loop @B - pop eax - mov edx, [base] - and edx, 4095 - add eax, edx + pop eax + mov edx, [base] + and edx, 4095 + add eax, edx .fail: - pop edi - pop ebx - ret + pop edi + pop ebx + ret endp ; param @@ -214,31 +214,31 @@ endp align 4 commit_pages: - push edi - test ecx, ecx - jz .fail + push edi + test ecx, ecx + jz .fail - mov edi, ebx - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx + mov edi, ebx + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx - mov edx, 0x1000 - mov ebx, edi - shr ebx, 12 + mov edx, 0x1000 + mov ebx, edi + shr ebx, 12 @@: - mov [page_tabs+ebx*4], eax - ; push eax - invlpg [edi] - ; pop eax - add edi, edx - add eax, edx - inc ebx - dec ecx - jnz @B - mov [pg_data.pg_mutex],ecx + mov [page_tabs+ebx*4], eax + ; push eax + invlpg [edi] + ; pop eax + add edi, edx + add eax, edx + inc ebx + dec ecx + jnz @B + mov [pg_data.pg_mutex],ecx .fail: - pop edi - ret + pop edi + ret ; param @@ -248,49 +248,49 @@ commit_pages: align 4 release_pages: - pushad - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx + pushad + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx - mov esi, eax - mov edi, eax + mov esi, eax + mov edi, eax - shr esi, 10 - add esi, page_tabs + shr esi, 10 + add esi, page_tabs - mov ebp, [pg_data.pages_free] - mov ebx, [page_start] - mov edx, sys_pgmap + mov ebp, [pg_data.pages_free] + mov ebx, [page_start] + mov edx, sys_pgmap @@: - xor eax, eax - xchg eax, [esi] - push eax - invlpg [edi] - pop eax + xor eax, eax + xchg eax, [esi] + push eax + invlpg [edi] + pop eax - test eax, 1 - jz .next + test eax, 1 + jz .next - shr eax, 12 - bts [edx], eax - cmc - adc ebp, 0 - shr eax, 3 - and eax, -4 - add eax, edx - cmp eax, ebx - jae .next + shr eax, 12 + bts [edx], eax + cmc + adc ebp, 0 + shr eax, 3 + and eax, -4 + add eax, edx + cmp eax, ebx + jae .next - mov ebx, eax + mov ebx, eax .next: - add edi, 0x1000 - add esi, 4 - dec ecx - jnz @B - mov [pg_data.pages_free], ebp - and [pg_data.pg_mutex],0 - popad - ret + add edi, 0x1000 + add esi, 4 + dec ecx + jnz @B + mov [pg_data.pages_free], ebp + and [pg_data.pg_mutex],0 + popad + ret ; param ; eax= base @@ -299,196 +299,187 @@ release_pages: align 4 unmap_pages: - push edi + push edi - mov edi, eax - mov edx, eax + mov edi, eax + mov edx, eax - shr edi, 10 - add edi, page_tabs + shr edi, 10 + add edi, page_tabs - xor eax, eax + xor eax, eax @@: - stosd - invlpg [edx] - add edx, 0x1000 - loop @b + stosd + invlpg [edx] + add edx, 0x1000 + loop @b - pop edi - ret + pop edi + ret align 4 proc map_page_table stdcall, lin_addr:dword, phis_addr:dword - push ebx - mov ebx, [lin_addr] - shr ebx, 22 - mov eax, [phis_addr] - and eax, not 0xFFF - or eax, PG_UW ;+PG_NOCACHE - mov dword [master_tab+ebx*4], eax - mov eax, [lin_addr] - shr eax, 10 - add eax, page_tabs - invlpg [eax] - pop ebx - ret + push ebx + mov ebx, [lin_addr] + shr ebx, 22 + mov eax, [phis_addr] + and eax, not 0xFFF + or eax, PG_UW ;+PG_NOCACHE + mov dword [master_tab+ebx*4], eax + mov eax, [lin_addr] + shr eax, 10 + add eax, page_tabs + invlpg [eax] + pop ebx + ret endp align 4 proc init_LFB - locals - pg_count dd ? - endl +; cmp dword [LFBAddress], -1 +; jne @f +; +; mov esi, boot_framebuf +; call boot_log +; +; mov [BOOT_VAR+0x901c],byte 2 +; stdcall alloc_pages, (0x280000 / 4096) +; +; push eax +; call alloc_page +; stdcall map_page_table, LFB_BASE, eax +; pop eax +; or eax, PG_UW +; mov ebx, LFB_BASE +; mov ecx, 0x280000 / 4096 +; call commit_pages +; mov [LFBAddress], dword LFB_BASE +; ret +;@@: + call init_mtrr - cmp dword [LFBAddress], -1 - jne @f - mov [BOOT_VAR+0x901c],byte 2 - stdcall alloc_pages, (0x280000 / 4096) + mov edx, LFB_BASE + mov esi, [LFBAddress] + mov edi, 0x00C00000 ; 12Mb + mov dword [exp_lfb+4], edx - push eax - call alloc_page - stdcall map_page_table, LFB_BASE, eax - pop eax - or eax, PG_UW - mov ebx, LFB_BASE - mov ecx, 0x280000 / 4096 - call commit_pages - mov [LFBAddress], dword LFB_BASE - ret + shr edi, 12 ; C00 +; mov [pg_count], edi + shr edi, 10 ; 3 + + or esi, PG_GLOBAL+PG_LARGE+PG_UW + mov edx, sys_pgdir+(LFB_BASE shr 20) @@: - test [SCR_MODE],word 0100000000000000b - jnz @f - mov [BOOT_VAR+0x901c],byte 2 - ret -@@: - call init_mtrr + mov [edx], esi + add edx, 4 + add esi, 0x00400000 + dec edi + jnz @B - mov edx, LFB_BASE - mov esi, [LFBAddress] - mov edi, 0x00C00000 - mov dword [exp_lfb+4], edx - - shr edi, 12 - mov [pg_count], edi - shr edi, 10 - - or esi, PG_GLOBAL+PG_LARGE+PG_UW - mov edx, sys_pgdir+(LFB_BASE shr 20) -@@: - mov [edx], esi - add edx, 4 - add esi, 0x00400000 - dec edi - jnz @B - - mov dword [LFBAddress], LFB_BASE - mov eax, cr3 ;flush TLB - mov cr3, eax - ret + mov dword [LFBAddress], LFB_BASE + mov eax, cr3 ;flush TLB + mov cr3, eax + ret endp align 4 -proc init_userDMA - stdcall alloc_pages, 4096 ; 16M <<<<<<<<<<+++++++++++++++++++++++++++++++++ - add eax, 0x007FFFF0 +init_userDMA: + stdcall alloc_pages, 4096 ; 16M <<<<<<<<<<+++++++++++++++++++++++++++++++++ + add eax, 0x007FFFF0 ; terrible mess, sorry ... and eax, 0xFF800000 ; align at 8M boundary mov [UserDMAaddr], eax -; or eax, PG_UW + PG_NOCACHE -; mov ebx, USER_DMA_BUFFER -; mov ecx, 2048 ; 8M, to be sure -; call commit_pages -; mov eax, [UserDMAaddr] - or eax, PG_LARGE + PG_UW + PG_NOCACHE - mov ebx, sys_pgdir + (USER_DMA_BUFFER shr 20) - mov [ebx], eax + or eax, PG_LARGE + PG_UW + PG_NOCACHE + mov ebx, sys_pgdir + (USER_DMA_BUFFER shr 20) + mov [ebx], eax add ebx, 4 - add eax, 0x00400000 - mov [ebx], eax - ret -endp + add eax, 0x00400000 + mov [ebx], eax + mov eax, cr3 ;flush TLB + mov cr3, eax + ret align 4 proc new_mem_resize stdcall, new_size:dword - mov ebx, pg_data.pg_mutex - call wait_mutex ;ebx + mov ebx, pg_data.pg_mutex + call wait_mutex ;ebx - mov edi, [new_size] - add edi,4095 - and edi,not 4095 - mov [new_size], edi + mov edi, [new_size] + add edi,4095 + and edi,not 4095 + mov [new_size], edi - mov edx,[current_slot] - cmp [edx+APPDATA.heap_base],0 - jne .exit + mov edx,[current_slot] + cmp [edx+APPDATA.heap_base],0 + jne .exit - mov esi, [edx+APPDATA.mem_size] - add esi, 4095 - and esi, not 4095 + mov esi, [edx+APPDATA.mem_size] + add esi, 4095 + and esi, not 4095 - cmp edi, esi - jae .expand + cmp edi, esi + jae .expand - shr edi, 12 - shr esi, 12 + shr edi, 12 + shr esi, 12 @@: - mov eax, [app_page_tabs+edi*4] - test eax, 1 - jz .next - mov dword [app_page_tabs+edi*4], 2 - mov ebx, edi - shl ebx, 12 - push eax - invlpg [ebx] - pop eax - call free_page + mov eax, [app_page_tabs+edi*4] + test eax, 1 + jz .next + mov dword [app_page_tabs+edi*4], 2 + mov ebx, edi + shl ebx, 12 + push eax + invlpg [ebx] + pop eax + call free_page -.next: add edi, 1 - cmp edi, esi - jb @B +.next: add edi, 1 + cmp edi, esi + jb @B .update_size: - mov ebx, [new_size] - call update_mem_size + mov ebx, [new_size] + call update_mem_size - xor eax, eax - dec [pg_data.pg_mutex] - ret + xor eax, eax + dec [pg_data.pg_mutex] + ret .expand: - push esi - push edi + push esi + push edi - add edi, 0x3FFFFF - and edi, not(0x3FFFFF) - add esi, 0x3FFFFF - and esi, not(0x3FFFFF) + add edi, 0x3FFFFF + and edi, not(0x3FFFFF) + add esi, 0x3FFFFF + and esi, not(0x3FFFFF) - cmp esi, edi - jae .grow + cmp esi, edi + jae .grow - xchg esi, edi + xchg esi, edi @@: - call alloc_page - test eax, eax - jz .exit_pop + call alloc_page + test eax, eax + jz .exit_pop - stdcall map_page_table, edi, eax + stdcall map_page_table, edi, eax - push edi - shr edi, 10 - add edi, page_tabs - mov ecx, 1024 - xor eax, eax - cld - rep stosd - pop edi + push edi + shr edi, 10 + add edi, page_tabs + mov ecx, 1024 + xor eax, eax + cld + rep stosd + pop edi - add edi, 0x00400000 - cmp edi, esi - jb @B + add edi, 0x00400000 + cmp edi, esi + jb @B .grow: ;//- pop edi @@ -499,38 +490,38 @@ proc new_mem_resize stdcall, new_size:dword cmp esi, edi jle .out_of_memory ;//- - pop edi - pop esi + pop edi + pop esi @@: - call alloc_page - test eax, eax - jz .exit - stdcall map_page,esi,eax,dword PG_UW + call alloc_page + test eax, eax + jz .exit + stdcall map_page,esi,eax,dword PG_UW - push edi - mov edi, esi - xor eax, eax - mov ecx, 1024 - cld - rep stosd - pop edi + push edi + mov edi, esi + xor eax, eax + mov ecx, 1024 + cld + rep stosd + pop edi - add esi, 0x1000 - cmp esi, edi - jb @B + add esi, 0x1000 + cmp esi, edi + jb @B - jmp .update_size + jmp .update_size ;//- .exit_pop: .out_of_memory: ;//- - pop edi - pop esi + pop edi + pop esi .exit: - xor eax, eax - inc eax - dec [pg_data.pg_mutex] - ret + xor eax, eax + inc eax + dec [pg_data.pg_mutex] + ret endp update_mem_size: @@ -538,31 +529,31 @@ update_mem_size: ; ebx = new memory size ; destroys eax,ecx,edx - mov [APPDATA.mem_size+edx],ebx + mov [APPDATA.mem_size+edx],ebx ;search threads and update ;application memory size infomation - mov ecx,[APPDATA.dir_table+edx] - mov eax,2 + mov ecx,[APPDATA.dir_table+edx] + mov eax,2 .search_threads: ;eax = current slot ;ebx = new memory size ;ecx = page directory - cmp eax,[TASK_COUNT] - jg .search_threads_end - mov edx,eax - shl edx,5 - cmp word [CURRENT_TASK+edx+TASKDATA.state],9 ;if slot empty? - jz .search_threads_next - shl edx,3 - cmp [SLOT_BASE+edx+APPDATA.dir_table],ecx ;if it is our thread? - jnz .search_threads_next - mov [SLOT_BASE+edx+APPDATA.mem_size],ebx ;update memory size + cmp eax,[TASK_COUNT] + jg .search_threads_end + mov edx,eax + shl edx,5 + cmp word [CURRENT_TASK+edx+TASKDATA.state],9 ;if slot empty? + jz .search_threads_next + shl edx,3 + cmp [SLOT_BASE+edx+APPDATA.dir_table],ecx ;if it is our thread? + jnz .search_threads_next + mov [SLOT_BASE+edx+APPDATA.mem_size],ebx ;update memory size .search_threads_next: - inc eax - jmp .search_threads + inc eax + jmp .search_threads .search_threads_end: - ret + ret ; param ; eax= linear address @@ -572,49 +563,49 @@ update_mem_size: align 4 get_pg_addr: - shr eax, 12 - mov eax, [page_tabs+eax*4] - and eax, 0xFFFFF000 - ret + shr eax, 12 + mov eax, [page_tabs+eax*4] + and eax, 0xFFFFF000 + ret align 4 ; Now it is called from core/sys32::exc_c (see stack frame there) proc page_fault_handler - .err_addr equ ebp-4 + .err_addr equ ebp-4 - push ebx ;save exception number (#PF) - mov ebp, esp - mov ebx, cr2 - push ebx ;that is locals: .err_addr = cr2 - inc [pg_data.pages_faults] + push ebx ;save exception number (#PF) + mov ebp, esp + mov ebx, cr2 + push ebx ;that is locals: .err_addr = cr2 + inc [pg_data.pages_faults] - mov eax, [pf_err_code] + mov eax, [pf_err_code] - cmp ebx, OS_BASE ;ebx == .err_addr - jb .user_space ;страница в памяти приложения ; + cmp ebx, OS_BASE ;ebx == .err_addr + jb .user_space ;страница в памяти приложения ; - cmp ebx, page_tabs - jb .kernel_space ;страница в памяти ядра + cmp ebx, page_tabs + jb .kernel_space ;страница в памяти ядра - cmp ebx, kernel_tabs - jb .alloc;.app_tabs ;таблицы страниц приложения ; - ;просто создадим одну + cmp ebx, kernel_tabs + jb .alloc;.app_tabs ;таблицы страниц приложения ; + ;просто создадим одну if 0 ;пока это просто лишнее - cmp ebx, LFB_BASE - jb .core_tabs ;таблицы страниц ядра - ;Ошибка + cmp ebx, LFB_BASE + jb .core_tabs ;таблицы страниц ядра + ;Ошибка .lfb: - ;область LFB - ;Ошибка - jmp .fail + ;область LFB + ;Ошибка + jmp .fail end if .core_tabs: -.fail: ;simply return to caller - mov esp, ebp - pop ebx ;restore exception number (#PF) - ret +.fail: ;simply return to caller + mov esp, ebp + pop ebx ;restore exception number (#PF) + ret ; xchg bx, bx ; add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller @@ -622,143 +613,143 @@ end if ; iretd .user_space: - test eax, PG_MAP - jnz .err_access ;Страница присутствует - ;Ошибка доступа ? + test eax, PG_MAP + jnz .err_access ;Страница присутствует + ;Ошибка доступа ? - shr ebx, 12 - mov ecx, ebx - shr ecx, 10 - mov edx, [master_tab+ecx*4] - test edx, PG_MAP - jz .fail ;таблица страниц не создана - ;неверный адрес в программе + shr ebx, 12 + mov ecx, ebx + shr ecx, 10 + mov edx, [master_tab+ecx*4] + test edx, PG_MAP + jz .fail ;таблица страниц не создана + ;неверный адрес в программе - mov eax, [page_tabs+ebx*4] - test eax, 2 - jz .fail ;адрес не зарезервирован для ; - ;использования. Ошибка + mov eax, [page_tabs+ebx*4] + test eax, 2 + jz .fail ;адрес не зарезервирован для ; + ;использования. Ошибка .alloc: - call alloc_page - test eax, eax - jz .fail + call alloc_page + test eax, eax + jz .fail - stdcall map_page,[.err_addr],eax,PG_UW + stdcall map_page,[.err_addr],eax,PG_UW - mov edi, [.err_addr] - and edi, 0xFFFFF000 - mov ecx, 1024 - xor eax, eax + mov edi, [.err_addr] + and edi, 0xFFFFF000 + mov ecx, 1024 + xor eax, eax ;cld ;caller is duty for this - rep stosd -.exit: ;iret with repeat fault instruction - add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller - restore_ring3_context - iretd + rep stosd +.exit: ;iret with repeat fault instruction + add esp,12 ;clear in stack: locals(.err_addr) + #PF + ret_to_caller + restore_ring3_context + iretd .err_access: ; access denied? this may be a result of copy-on-write protection for DLL ; check list of HDLLs - and ebx, not 0xFFF - mov eax, [CURRENT_TASK] - shl eax, 8 - mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr] - test eax, eax - jz .fail - mov esi, [eax+HDLL.fd] + and ebx, not 0xFFF + mov eax, [CURRENT_TASK] + shl eax, 8 + mov eax, [SLOT_BASE+eax+APPDATA.dlls_list_ptr] + test eax, eax + jz .fail + mov esi, [eax+HDLL.fd] .scan_hdll: - cmp esi, eax - jz .fail - mov edx, ebx - sub edx, [esi+HDLL.base] - cmp edx, [esi+HDLL.size] - jb .fault_in_hdll + cmp esi, eax + jz .fail + mov edx, ebx + sub edx, [esi+HDLL.base] + cmp edx, [esi+HDLL.size] + jb .fault_in_hdll .scan_hdll.next: - mov esi, [esi+HDLL.fd] - jmp .scan_hdll + mov esi, [esi+HDLL.fd] + jmp .scan_hdll .fault_in_hdll: ; allocate new page, map it as rw and copy data - call alloc_page - test eax, eax - jz .fail - stdcall map_page,ebx,eax,PG_UW - mov edi, ebx - mov ecx, 1024 - sub ebx, [esi+HDLL.base] - mov esi, [esi+HDLL.parent] - mov esi, [esi+DLLDESCR.data] - add esi, ebx - rep movsd - jmp .exit + call alloc_page + test eax, eax + jz .fail + stdcall map_page,ebx,eax,PG_UW + mov edi, ebx + mov ecx, 1024 + sub ebx, [esi+HDLL.base] + mov esi, [esi+HDLL.parent] + mov esi, [esi+DLLDESCR.data] + add esi, ebx + rep movsd + jmp .exit .kernel_space: - test eax, PG_MAP - jz .fail ;страница не присутствует + test eax, PG_MAP + jz .fail ;страница не присутствует - test eax,12 ;U/S (+below) - jnz .fail ;приложение обратилось к памяти - ;ядра + test eax,12 ;U/S (+below) + jnz .fail ;приложение обратилось к памяти + ;ядра ;test eax, 8 ;jnz .fail ;установлен зарезервированный бит - ;в таблицах страниц. добавлено в P4/Xeon + ;в таблицах страниц. добавлено в P4/Xeon ;попытка записи в защищённую страницу ядра - cmp ebx, tss._io_map_0 - jb .fail + cmp ebx, tss._io_map_0 + jb .fail - cmp ebx, tss._io_map_0+8192 - jae .fail + cmp ebx, tss._io_map_0+8192 + jae .fail ; io permission map ; copy-on-write protection - call alloc_page - test eax, eax - jz .fail + call alloc_page + test eax, eax + jz .fail - push eax - stdcall map_page,[.err_addr],eax,dword PG_SW - pop eax - mov edi, [.err_addr] - and edi, -4096 - lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 + push eax + stdcall map_page,[.err_addr],eax,dword PG_SW + pop eax + mov edi, [.err_addr] + and edi, -4096 + lea esi, [edi+(not tss._io_map_0)+1]; -tss._io_map_0 - mov ebx, esi - shr ebx, 12 - mov edx, [current_slot] - or eax, PG_SW - mov [edx+APPDATA.io_map+ebx*4], eax + mov ebx, esi + shr ebx, 12 + mov edx, [current_slot] + or eax, PG_SW + mov [edx+APPDATA.io_map+ebx*4], eax - add esi, [default_io_map] - mov ecx, 4096/4 + add esi, [default_io_map] + mov ecx, 4096/4 ;cld ;caller is duty for this - rep movsd - jmp .exit + rep movsd + jmp .exit endp ; returns number of mapped bytes proc map_mem stdcall, lin_addr:dword,slot:dword,\ - ofs:dword,buf_size:dword,req_access:dword - push 0 ; initialize number of mapped bytes + ofs:dword,buf_size:dword,req_access:dword + push 0 ; initialize number of mapped bytes - cmp [buf_size], 0 - jz .exit + cmp [buf_size], 0 + jz .exit - mov eax, [slot] - shl eax, 8 - mov eax, [SLOT_BASE+eax+APPDATA.dir_table] - and eax, 0xFFFFF000 + mov eax, [slot] + shl eax, 8 + mov eax, [SLOT_BASE+eax+APPDATA.dir_table] + and eax, 0xFFFFF000 - stdcall map_page,[ipc_pdir],eax,PG_UW - mov ebx, [ofs] - shr ebx, 22 - mov esi, [ipc_pdir] - mov edi, [ipc_ptab] - mov eax, [esi+ebx*4] - and eax, 0xFFFFF000 - jz .exit - stdcall map_page,edi,eax,PG_UW + stdcall map_page,[ipc_pdir],eax,PG_UW + mov ebx, [ofs] + shr ebx, 22 + mov esi, [ipc_pdir] + mov edi, [ipc_ptab] + mov eax, [esi+ebx*4] + and eax, 0xFFFFF000 + jz .exit + stdcall map_page,edi,eax,PG_UW ; inc ebx ; add edi, 0x1000 ; mov eax, [esi+ebx*4] @@ -767,90 +758,90 @@ proc map_mem stdcall, lin_addr:dword,slot:dword,\ ; and eax, 0xFFFFF000 ; stdcall map_page, edi, eax -@@: mov edi, [lin_addr] - and edi, 0xFFFFF000 - mov ecx, [buf_size] - add ecx, 4095 - shr ecx, 12 - inc ecx +@@: mov edi, [lin_addr] + and edi, 0xFFFFF000 + mov ecx, [buf_size] + add ecx, 4095 + shr ecx, 12 + inc ecx - mov edx, [ofs] - shr edx, 12 - and edx, 0x3FF - mov esi, [ipc_ptab] + mov edx, [ofs] + shr edx, 12 + and edx, 0x3FF + mov esi, [ipc_ptab] .map: - stdcall safe_map_page,[slot],[req_access],[ofs] - jnc .exit - add dword [ebp-4], 4096 - add [ofs], 4096 - dec ecx - jz .exit - add edi, 0x1000 - inc edx - cmp edx, 0x400 - jnz .map - inc ebx - mov eax, [ipc_pdir] - mov eax, [eax+ebx*4] - and eax, 0xFFFFF000 - jz .exit - stdcall map_page,esi,eax,PG_UW - xor edx, edx - jmp .map + stdcall safe_map_page,[slot],[req_access],[ofs] + jnc .exit + add dword [ebp-4], 4096 + add [ofs], 4096 + dec ecx + jz .exit + add edi, 0x1000 + inc edx + cmp edx, 0x400 + jnz .map + inc ebx + mov eax, [ipc_pdir] + mov eax, [eax+ebx*4] + and eax, 0xFFFFF000 + jz .exit + stdcall map_page,esi,eax,PG_UW + xor edx, edx + jmp .map .exit: - pop eax - ret + pop eax + ret endp proc map_memEx stdcall, lin_addr:dword,slot:dword,\ - ofs:dword,buf_size:dword,req_access:dword - push 0 ; initialize number of mapped bytes + ofs:dword,buf_size:dword,req_access:dword + push 0 ; initialize number of mapped bytes - cmp [buf_size], 0 - jz .exit + cmp [buf_size], 0 + jz .exit - mov eax, [slot] - shl eax, 8 - mov eax, [SLOT_BASE+eax+APPDATA.dir_table] - and eax, 0xFFFFF000 + mov eax, [slot] + shl eax, 8 + mov eax, [SLOT_BASE+eax+APPDATA.dir_table] + and eax, 0xFFFFF000 - stdcall map_page,[proc_mem_pdir],eax,PG_UW - mov ebx, [ofs] - shr ebx, 22 - mov esi, [proc_mem_pdir] - mov edi, [proc_mem_tab] - mov eax, [esi+ebx*4] - and eax, 0xFFFFF000 - test eax, eax - jz .exit - stdcall map_page,edi,eax,PG_UW + stdcall map_page,[proc_mem_pdir],eax,PG_UW + mov ebx, [ofs] + shr ebx, 22 + mov esi, [proc_mem_pdir] + mov edi, [proc_mem_tab] + mov eax, [esi+ebx*4] + and eax, 0xFFFFF000 + test eax, eax + jz .exit + stdcall map_page,edi,eax,PG_UW -@@: mov edi, [lin_addr] - and edi, 0xFFFFF000 - mov ecx, [buf_size] - add ecx, 4095 - shr ecx, 12 - inc ecx +@@: mov edi, [lin_addr] + and edi, 0xFFFFF000 + mov ecx, [buf_size] + add ecx, 4095 + shr ecx, 12 + inc ecx - mov edx, [ofs] - shr edx, 12 - and edx, 0x3FF - mov esi, [proc_mem_tab] + mov edx, [ofs] + shr edx, 12 + and edx, 0x3FF + mov esi, [proc_mem_tab] .map: - stdcall safe_map_page,[slot],[req_access],[ofs] - jnc .exit - add dword [ebp-4], 0x1000 - add edi, 0x1000 - add [ofs], 0x1000 - inc edx - dec ecx - jnz .map + stdcall safe_map_page,[slot],[req_access],[ofs] + jnc .exit + add dword [ebp-4], 0x1000 + add edi, 0x1000 + add [ofs], 0x1000 + inc edx + dec ecx + jnz .map .exit: - pop eax - ret + pop eax + ret endp ; in: esi+edx*4 = pointer to page table entry @@ -866,7 +857,7 @@ proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword jz .resolve_readonly ; normal case: writable page, just map with requested access .map: - stdcall map_page, edi, eax, [req_access] + stdcall map_page, edi, eax, [req_access] stc .fail: ret @@ -923,7 +914,7 @@ proc safe_map_page stdcall, slot:dword, req_access:dword, ofs:dword jz .no_hdll or al, PG_UW mov [esi+edx*4], eax - stdcall map_page, edi, eax, [req_access] + stdcall map_page, edi, eax, [req_access] push esi edi mov esi, ebx mov ecx, 4096/4 @@ -948,24 +939,24 @@ sys_IPC: dec ebx jnz @f - mov eax,[current_slot] - pushf - cli - mov [eax+APPDATA.ipc_start],ecx ;set fields in extended information area - mov [eax+APPDATA.ipc_size],edx + mov eax,[current_slot] + pushf + cli + mov [eax+APPDATA.ipc_start],ecx ;set fields in extended information area + mov [eax+APPDATA.ipc_size],edx - add edx, ecx - add edx, 4095 - and edx, not 4095 + add edx, ecx + add edx, 4095 + and edx, not 4095 .touch: mov eax, [ecx] - add ecx, 0x1000 - cmp ecx, edx - jb .touch + add ecx, 0x1000 + cmp ecx, edx + jb .touch - popf - mov [esp+32], ebx ;ebx=0 - ret + popf + mov [esp+32], ebx ;ebx=0 + ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;2 @@ -973,13 +964,13 @@ sys_IPC: dec ebx jnz @f - stdcall sys_ipc_send, ecx, edx, esi - mov [esp+32], eax - ret + stdcall sys_ipc_send, ecx, edx, esi + mov [esp+32], eax + ret @@: or eax,-1 - mov [esp+32], eax - ret + mov [esp+32], eax + ret ;align 4 ;proc set_ipc_buff @@ -1005,504 +996,504 @@ sys_IPC: ;endp proc sys_ipc_send stdcall, PID:dword, msg_addr:dword, msg_size:dword - locals - dst_slot dd ? - dst_offset dd ? - buf_size dd ? - used_buf dd ? - endl + locals + dst_slot dd ? + dst_offset dd ? + buf_size dd ? + used_buf dd ? + endl - pushf - cli + pushf + cli - mov eax, [PID] - call pid_to_slot - test eax,eax - jz .no_pid + mov eax, [PID] + call pid_to_slot + test eax,eax + jz .no_pid - mov [dst_slot], eax - shl eax,8 - mov edi,[eax+SLOT_BASE+0xa0] ;is ipc area defined? - test edi,edi - jz .no_ipc_area + mov [dst_slot], eax + shl eax,8 + mov edi,[eax+SLOT_BASE+0xa0] ;is ipc area defined? + test edi,edi + jz .no_ipc_area - mov ebx, edi - and ebx, 0xFFF - mov [dst_offset], ebx + mov ebx, edi + and ebx, 0xFFF + mov [dst_offset], ebx - mov esi, [eax+SLOT_BASE+0xa4] - mov [buf_size], esi + mov esi, [eax+SLOT_BASE+0xa4] + mov [buf_size], esi - mov ecx, [ipc_tmp] - cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page - jbe @f - push esi edi - add esi,0x1000 - stdcall alloc_kernel_space,esi - mov ecx, eax - pop edi esi + mov ecx, [ipc_tmp] + cmp esi, 0x40000-0x1000 ; size of [ipc_tmp] minus one page + jbe @f + push esi edi + add esi,0x1000 + stdcall alloc_kernel_space,esi + mov ecx, eax + pop edi esi @@: - mov [used_buf], ecx - stdcall map_mem, ecx, [dst_slot],\ - edi, esi, PG_SW + mov [used_buf], ecx + stdcall map_mem, ecx, [dst_slot],\ + edi, esi, PG_SW - mov edi, [dst_offset] - add edi, [used_buf] - cmp dword [edi], 0 - jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now + mov edi, [dst_offset] + add edi, [used_buf] + cmp dword [edi], 0 + jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now - mov edx, dword [edi+4] - lea ebx, [edx+8] - add ebx, [msg_size] - cmp ebx, [buf_size] - ja .buffer_overflow ;esi<0 - not enough memory in buffer + mov edx, dword [edi+4] + lea ebx, [edx+8] + add ebx, [msg_size] + cmp ebx, [buf_size] + ja .buffer_overflow ;esi<0 - not enough memory in buffer - mov dword [edi+4], ebx - mov eax,[TASK_BASE] - mov eax, [eax+0x04] ;eax - our PID - add edi, edx - mov [edi], eax - mov ecx, [msg_size] + mov dword [edi+4], ebx + mov eax,[TASK_BASE] + mov eax, [eax+0x04] ;eax - our PID + add edi, edx + mov [edi], eax + mov ecx, [msg_size] - mov [edi+4], ecx - add edi, 8 - mov esi, [msg_addr] + mov [edi+4], ecx + add edi, 8 + mov esi, [msg_addr] ; add esi, new_app_base - cld - rep movsb + cld + rep movsb - mov ebx, [ipc_tmp] - mov edx, ebx - shr ebx, 12 - xor eax, eax - mov [page_tabs+ebx*4], eax - invlpg [edx] + mov ebx, [ipc_tmp] + mov edx, ebx + shr ebx, 12 + xor eax, eax + mov [page_tabs+ebx*4], eax + invlpg [edx] - mov ebx, [ipc_pdir] - mov edx, ebx - shr ebx, 12 - xor eax, eax - mov [page_tabs+ebx*4], eax - invlpg [edx] + mov ebx, [ipc_pdir] + mov edx, ebx + shr ebx, 12 + xor eax, eax + mov [page_tabs+ebx*4], eax + invlpg [edx] - mov ebx, [ipc_ptab] - mov edx, ebx - shr ebx, 12 - xor eax, eax - mov [page_tabs+ebx*4], eax - invlpg [edx] + mov ebx, [ipc_ptab] + mov edx, ebx + shr ebx, 12 + xor eax, eax + mov [page_tabs+ebx*4], eax + invlpg [edx] - mov eax, [dst_slot] - shl eax, 8 - or [eax+SLOT_BASE+0xA8],dword 0x40 - cmp dword [check_idle_semaphore],20 - jge .ipc_no_cis + mov eax, [dst_slot] + shl eax, 8 + or [eax+SLOT_BASE+0xA8],dword 0x40 + cmp dword [check_idle_semaphore],20 + jge .ipc_no_cis - mov dword [check_idle_semaphore],5 + mov dword [check_idle_semaphore],5 .ipc_no_cis: - push 0 - jmp .ret + push 0 + jmp .ret .no_pid: - popf - mov eax, 4 - ret + popf + mov eax, 4 + ret .no_ipc_area: - popf - xor eax, eax - inc eax - ret + popf + xor eax, eax + inc eax + ret .ipc_blocked: - push 2 - jmp .ret + push 2 + jmp .ret .buffer_overflow: - push 3 + push 3 .ret: - mov eax, [used_buf] - cmp eax, [ipc_tmp] - jz @f - stdcall free_kernel_space,eax + mov eax, [used_buf] + cmp eax, [ipc_tmp] + jz @f + stdcall free_kernel_space,eax @@: - pop eax - popf - ret + pop eax + popf + ret endp align 4 sysfn_meminfo: - ; add ecx, new_app_base - cmp ecx, OS_BASE - jae .fail + ; add ecx, new_app_base + cmp ecx, OS_BASE + jae .fail - mov eax, [pg_data.pages_count] - mov [ecx], eax - shl eax, 12 - mov [esp+32], eax - mov eax, [pg_data.pages_free] - mov [ecx+4], eax - mov eax, [pg_data.pages_faults] - mov [ecx+8], eax - mov eax, [heap_size] - mov [ecx+12], eax - mov eax, [heap_free] - mov [ecx+16], eax - mov eax, [heap_blocks] - mov [ecx+20], eax - mov eax, [free_blocks] - mov [ecx+24], eax - ret + mov eax, [pg_data.pages_count] + mov [ecx], eax + shl eax, 12 + mov [esp+32], eax + mov eax, [pg_data.pages_free] + mov [ecx+4], eax + mov eax, [pg_data.pages_faults] + mov [ecx+8], eax + mov eax, [heap_size] + mov [ecx+12], eax + mov eax, [heap_free] + mov [ecx+16], eax + mov eax, [heap_blocks] + mov [ecx+20], eax + mov eax, [free_blocks] + mov [ecx+24], eax + ret .fail: - or dword [esp+32], -1 - ret + or dword [esp+32], -1 + ret iglobal align 4 f68call: - dd f68.11 ; init_heap - dd f68.12 ; user_alloc - dd f68.13 ; user_free - dd f68.14 ; get_event_ex - dd f68.fail ;moved to f68.24 - dd f68.16 ; get_service - dd f68.17 ; call_service - dd f68.fail ;moved to f68.25 - dd f68.19 ; load_dll - dd f68.20 ; user_realloc - dd f68.21 ; load_driver - dd f68.22 ; shmem_open - dd f68.23 ; shmem_close - dd f68.24 - dd f68.25 + dd f68.11 ; init_heap + dd f68.12 ; user_alloc + dd f68.13 ; user_free + dd f68.14 ; get_event_ex + dd f68.fail ;moved to f68.24 + dd f68.16 ; get_service + dd f68.17 ; call_service + dd f68.fail ;moved to f68.25 + dd f68.19 ; load_dll + dd f68.20 ; user_realloc + dd f68.21 ; load_driver + dd f68.22 ; shmem_open + dd f68.23 ; shmem_close + dd f68.24 + dd f68.25 endg align 4 f68: - cmp ebx,4 - jbe sys_sheduler + cmp ebx,4 + jbe sys_sheduler - cmp ebx, 11 - jb .fail + cmp ebx, 11 + jb .fail - cmp ebx, 25 - ja .fail + cmp ebx, 25 + ja .fail - jmp dword [f68call+ebx*4-11*4] + jmp dword [f68call+ebx*4-11*4] .11: - call init_heap - mov [esp+32], eax - ret + call init_heap + mov [esp+32], eax + ret .12: - stdcall user_alloc, ecx - mov [esp+32], eax - ret + stdcall user_alloc, ecx + mov [esp+32], eax + ret .13: - stdcall user_free, ecx - mov [esp+32], eax - ret + stdcall user_free, ecx + mov [esp+32], eax + ret .14: - cmp ecx, OS_BASE - jae .fail - mov edi,ecx - call get_event_ex - mov [esp+32], eax - ret + cmp ecx, OS_BASE + jae .fail + mov edi,ecx + call get_event_ex + mov [esp+32], eax + ret .16: - test ecx, ecx - jz .fail - cmp ecx, OS_BASE - jae .fail - stdcall get_service, ecx - mov [esp+32], eax - ret + test ecx, ecx + jz .fail + cmp ecx, OS_BASE + jae .fail + stdcall get_service, ecx + mov [esp+32], eax + ret .17: - call srv_handlerEx ;ecx - mov [esp+32], eax - ret + call srv_handlerEx ;ecx + mov [esp+32], eax + ret .19: - cmp ecx, OS_BASE - jae .fail - stdcall load_library, ecx - mov [esp+32], eax - ret + cmp ecx, OS_BASE + jae .fail + stdcall load_library, ecx + mov [esp+32], eax + ret .20: - mov eax, edx + mov eax, edx mov ebx, ecx - call user_realloc ;in: eax = pointer, ebx = new size - mov [esp+32], eax - ret + call user_realloc ;in: eax = pointer, ebx = new size + mov [esp+32], eax + ret .21: - cmp ecx, OS_BASE - jae .fail + cmp ecx, OS_BASE + jae .fail - cmp ebx, OS_BASE - jae .fail + cmp ebx, OS_BASE + jae .fail - mov edi, edx - stdcall load_PE, ecx - mov esi, eax - test eax, eax - jz @F + mov edi, edx + stdcall load_PE, ecx + mov esi, eax + test eax, eax + jz @F - push edi - push DRV_ENTRY - call eax - add esp, 8 - test eax, eax - jz @F + push edi + push DRV_ENTRY + call eax + add esp, 8 + test eax, eax + jz @F - mov [eax+SRV.entry], esi + mov [eax+SRV.entry], esi @@: - mov [esp+32], eax - ret + mov [esp+32], eax + ret .22: - cmp ecx, OS_BASE - jae .fail + cmp ecx, OS_BASE + jae .fail - stdcall shmem_open, ecx, edx, esi - mov [esp+24], edx - mov [esp+32], eax - ret + stdcall shmem_open, ecx, edx, esi + mov [esp+24], edx + mov [esp+32], eax + ret .23: - cmp ecx, OS_BASE - jae .fail + cmp ecx, OS_BASE + jae .fail - stdcall shmem_close, ecx - mov [esp+32], eax - ret + stdcall shmem_close, ecx + mov [esp+32], eax + ret .24: - mov eax, [current_slot] - xchg ecx, [eax+APPDATA.exc_handler] - xchg edx, [eax+APPDATA.except_mask] - mov [esp+32], ecx ; reg_eax+8 - mov [esp+20], edx ; reg_ebx+8 - ret + mov eax, [current_slot] + xchg ecx, [eax+APPDATA.exc_handler] + xchg edx, [eax+APPDATA.except_mask] + mov [esp+32], ecx ; reg_eax+8 + mov [esp+20], edx ; reg_ebx+8 + ret .25: - cmp ecx,32 - jae .fail - mov eax, [current_slot] - btr [eax+APPDATA.except_mask],ecx - setc byte[esp+32] - jecxz @f - bts [eax+APPDATA.except_mask],ecx + cmp ecx,32 + jae .fail + mov eax, [current_slot] + btr [eax+APPDATA.except_mask],ecx + setc byte[esp+32] + jecxz @f + bts [eax+APPDATA.except_mask],ecx @@: - ret + ret .fail: - xor eax, eax - mov [esp+32], eax - ret + xor eax, eax + mov [esp+32], eax + ret align 4 proc load_pe_driver stdcall, file:dword - stdcall load_PE, [file] - test eax, eax - jz .fail + stdcall load_PE, [file] + test eax, eax + jz .fail - mov esi, eax - stdcall eax, DRV_ENTRY - test eax, eax - jz .fail + mov esi, eax + stdcall eax, DRV_ENTRY + test eax, eax + jz .fail - mov [eax+SRV.entry], esi - ret + mov [eax+SRV.entry], esi + ret .fail: - xor eax, eax - ret + xor eax, eax + ret endp align 4 proc init_mtrr - cmp [BOOT_VAR+0x901c],byte 2 - je .exit + cmp [BOOT_VAR+0x901c],byte 2 + je .exit - bt [cpu_caps], CAPS_MTRR - jnc .exit + bt [cpu_caps], CAPS_MTRR + jnc .exit - mov eax, cr0 - or eax, 0x60000000 ;disable caching - mov cr0, eax - wbinvd ;invalidate cache + mov eax, cr0 + or eax, 0x60000000 ;disable caching + mov cr0, eax + wbinvd ;invalidate cache - mov ecx, 0x2FF - rdmsr ; + mov ecx, 0x2FF + rdmsr ; ; has BIOS already initialized MTRRs? - test ah, 8 - jnz .skip_init + test ah, 8 + jnz .skip_init ; rarely needed, so mainly placeholder ; main memory - cached - push eax + push eax - mov eax, [MEM_AMOUNT] + mov eax, [MEM_AMOUNT] ; round eax up to next power of 2 - dec eax - bsr ecx, eax - mov ebx, 2 - shl ebx, cl - dec ebx + dec eax + bsr ecx, eax + mov ebx, 2 + shl ebx, cl + dec ebx ; base of memory range = 0, type of memory range = MEM_WB - xor edx, edx - mov eax, MEM_WB - mov ecx, 0x200 - wrmsr + xor edx, edx + mov eax, MEM_WB + mov ecx, 0x200 + wrmsr ; mask of memory range = 0xFFFFFFFFF - (size - 1), ebx = size - 1 - mov eax, 0xFFFFFFFF - mov edx, 0x0000000F - sub eax, ebx - sbb edx, 0 - or eax, 0x800 - inc ecx - wrmsr + mov eax, 0xFFFFFFFF + mov edx, 0x0000000F + sub eax, ebx + sbb edx, 0 + or eax, 0x800 + inc ecx + wrmsr ; clear unused MTRRs - xor eax, eax - xor edx, edx + xor eax, eax + xor edx, edx @@: - wrmsr - inc ecx - cmp ecx, 0x210 - jb @b + wrmsr + inc ecx + cmp ecx, 0x210 + jb @b ; enable MTRRs - pop eax - or ah, 8 - and al, 0xF0 ; default memtype = UC - mov ecx, 0x2FF - wrmsr + pop eax + or ah, 8 + and al, 0xF0 ; default memtype = UC + mov ecx, 0x2FF + wrmsr .skip_init: - stdcall set_mtrr, [LFBAddress],[LFBSize],MEM_WC + stdcall set_mtrr, [LFBAddress],[LFBSize],MEM_WC - wbinvd ;again invalidate + wbinvd ;again invalidate - mov eax, cr0 - and eax, not 0x60000000 - mov cr0, eax ; enable caching + mov eax, cr0 + and eax, not 0x60000000 + mov cr0, eax ; enable caching .exit: - ret + ret endp align 4 proc set_mtrr stdcall, base:dword,size:dword,mem_type:dword ; find unused register - mov ecx, 0x201 + mov ecx, 0x201 @@: - rdmsr - dec ecx - test ah, 8 - jz .found - rdmsr - mov al, 0 ; clear memory type field - cmp eax, [base] - jz .ret - add ecx, 3 - cmp ecx, 0x210 - jb @b + rdmsr + dec ecx + test ah, 8 + jz .found + rdmsr + mov al, 0 ; clear memory type field + cmp eax, [base] + jz .ret + add ecx, 3 + cmp ecx, 0x210 + jb @b ; no free registers, ignore the call .ret: - ret + ret .found: ; found, write values - xor edx, edx - mov eax, [base] - or eax, [mem_type] - wrmsr + xor edx, edx + mov eax, [base] + or eax, [mem_type] + wrmsr - mov ebx, [size] - dec ebx - mov eax, 0xFFFFFFFF - mov edx, 0x0000000F - sub eax, ebx - sbb edx, 0 - or eax, 0x800 - inc ecx - wrmsr - ret + mov ebx, [size] + dec ebx + mov eax, 0xFFFFFFFF + mov edx, 0x0000000F + sub eax, ebx + sbb edx, 0 + or eax, 0x800 + inc ecx + wrmsr + ret endp align 4 proc stall stdcall, delay:dword - push ecx - push edx - push ebx - push eax + push ecx + push edx + push ebx + push eax - mov eax, [delay] - mul [stall_mcs] - mov ebx, eax ;low - mov ecx, edx ;high - rdtsc - add ebx, eax - adc ecx,edx + mov eax, [delay] + mul [stall_mcs] + mov ebx, eax ;low + mov ecx, edx ;high + rdtsc + add ebx, eax + adc ecx,edx @@: - rdtsc - sub eax, ebx - sbb edx, ecx - jb @B + rdtsc + sub eax, ebx + sbb edx, ecx + jb @B - pop eax - pop ebx - pop edx - pop ecx - ret + pop eax + pop ebx + pop edx + pop ecx + ret endp align 4 proc create_ring_buffer stdcall, size:dword, flags:dword - locals - buf_ptr dd ? - endl + locals + buf_ptr dd ? + endl - mov eax, [size] - test eax, eax - jz .fail + mov eax, [size] + test eax, eax + jz .fail - add eax, eax - stdcall alloc_kernel_space, eax - test eax, eax - jz .fail + add eax, eax + stdcall alloc_kernel_space, eax + test eax, eax + jz .fail - push ebx + push ebx - mov [buf_ptr], eax + mov [buf_ptr], eax - mov ebx, [size] - shr ebx, 12 - push ebx + mov ebx, [size] + shr ebx, 12 + push ebx - stdcall alloc_pages, ebx - pop ecx + stdcall alloc_pages, ebx + pop ecx - test eax, eax - jz .mm_fail + test eax, eax + jz .mm_fail - push edi + push edi - or eax, [flags] - mov edi, [buf_ptr] - mov ebx, [buf_ptr] - mov edx, ecx - shl edx, 2 - shr edi, 10 + or eax, [flags] + mov edi, [buf_ptr] + mov ebx, [buf_ptr] + mov edx, ecx + shl edx, 2 + shr edi, 10 @@: - mov [page_tabs+edi], eax - mov [page_tabs+edi+edx], eax - invlpg [ebx] - invlpg [ebx+0x10000] - add eax, 0x1000 - add ebx, 0x1000 - add edi, 4 - dec ecx - jnz @B + mov [page_tabs+edi], eax + mov [page_tabs+edi+edx], eax + invlpg [ebx] + invlpg [ebx+0x10000] + add eax, 0x1000 + add ebx, 0x1000 + add edi, 4 + dec ecx + jnz @B - mov eax, [buf_ptr] - pop edi - pop ebx - ret + mov eax, [buf_ptr] + pop edi + pop ebx + ret .mm_fail: - stdcall free_kernel_space, [buf_ptr] - xor eax, eax - pop ebx + stdcall free_kernel_space, [buf_ptr] + xor eax, eax + pop ebx .fail: - ret + ret endp diff --git a/kernel/branches/Kolibri-A/trunk/core/syscall.inc b/kernel/branches/Kolibri-A/trunk/core/syscall.inc index 4db5508424..4bafe7ebee 100644 --- a/kernel/branches/Kolibri-A/trunk/core/syscall.inc +++ b/kernel/branches/Kolibri-A/trunk/core/syscall.inc @@ -99,7 +99,7 @@ iglobal dd 0 dd 0 dd 0 - dd 0;sys_pci ; 62-PCI functions + dd sys_pci ; 62-PCI functions dd sys_msg_board ; 63-System message board ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -170,7 +170,7 @@ iglobal dd undefined_syscall ; 59-reserved dd sys_IPC ; 60-Inter Process Communication dd sys_gs ; 61-Direct graphics access - dd pci_api;cross_order ; 62-PCI functions + dd cross_order ; 62-PCI functions dd cross_order ; 63-System message board dd sys_resize_app_memory ; 64-Resize application memory usage dd sys_putimage_palette ; 65-PutImagePalette diff --git a/kernel/branches/Kolibri-A/trunk/data32.inc b/kernel/branches/Kolibri-A/trunk/data32.inc index cdb2136cc1..971e1e8609 100644 --- a/kernel/branches/Kolibri-A/trunk/data32.inc +++ b/kernel/branches/Kolibri-A/trunk/data32.inc @@ -47,33 +47,33 @@ keymap_alt: db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' - boot_memdetect db 'Determining amount of memory',0 - boot_fonts db 'Fonts loaded',0 - boot_tss db 'Setting TSSs',0 - boot_cpuid db 'Reading CPUIDs',0 - boot_devices db 'Detecting devices',0 - boot_timer db 'Setting timer',0 - boot_irqs db 'Reprogramming IRQs',0 - 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_memdetect db 'Determining amount of memory',0 + boot_fonts db 'Fonts loaded',0 + boot_tss db 'Setting TSSs',0 + boot_cpuid db 'Reading CPUIDs',0 + boot_devices db 'Detecting devices',0 + boot_timer db 'Setting timer',0 + boot_irqs db 'Reprogramming IRQs',0 + 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_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_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_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 + boot_tasking db 'All set - press ESC to start',0 end if ;new_process_loading db 'K : New Process - loading',13,10,0 @@ -84,19 +84,19 @@ msg_unresolved db 'unresolved ',0 msg_module db 'in module ',0 msg_version db 'incompatible driver version',13,10,0 msg_www db 'please visit www.kolibrios.org',13,10,0 -msg_CR db 13,10,0 -aSis db 'SIS',0 +msg_CR db 13,10,0 +aSis db 'SIS',0 intel_str db "GenuineIntel",0 AMD_str db "AuthenticAMD",0 ;szSound db 'SOUND',0 ;szInfinity db 'INFINITY',0 -szHwMouse db 'ATI2D',0 -szPS2MDriver db 'PS2MOUSE',0 +szHwMouse db 'ATI2D',0 +szPS2MDriver db 'PS2MOUSE',0 ;szCOM_MDriver db 'COM_MOUSE',0 -szUSB db 'USB',0 -szAtiHW db '/rd/1/drivers/ati2d.drv',0 +szUSB db 'USB',0 +szAtiHW db '/rd/1/drivers/ati2d.drv',0 szSTART db 'START',0 szEXPORTS db 'EXPORTS',0 @@ -107,25 +107,25 @@ szIMPORTS db 'IMPORTS',0 read_firstapp db '/sys/' firstapp db 'LAUNCHER',0 -char db '/sys/FONTS/CHAR.MT',0 -char2 db '/sys/FONTS/CHAR2.MT',0 +char db '/sys/FONTS/CHAR.MT',0 +char2 db '/sys/FONTS/CHAR2.MT',0 bootpath db '/KOLIBRI ' bootpath2 db 0 -vmode db '/sys/drivers/VMODE.MDR',0 -vrr_m db 'VRR_M',0 +vmode db '/sys/drivers/VMODE.MDR',0 +vrr_m db 'VRR_M',0 kernel_file db 'KERNEL MNT' align 4 shmem_list: - .bk dd shmem_list - .fd dd shmem_list + .bk dd shmem_list + .fd dd shmem_list dll_list: - .bk dd dll_list - .fd dd dll_list + .bk dd dll_list + .fd dd dll_list MAX_DEFAULT_DLL_ADDR = 0x20000000 MIN_DEFAULT_DLL_ADDR = 0x10000000 @@ -137,13 +137,13 @@ dll_cur_addr dd MIN_DEFAULT_DLL_ADDR ; mike.dld { db 0 dd servetable-0x10000 -draw_line dd __sys_draw_line -draw_pointer dd __sys_draw_pointer +draw_line dd __sys_draw_line +draw_pointer dd __sys_draw_pointer ;//mike.dld, 2006-08-02 [ ;drawbar dd __sys_drawbar -drawbar dd __sys_drawbar.forced +drawbar dd __sys_drawbar.forced ;//mike.dld, 2006-08-02 ] -putpixel dd __sys_putpixel +putpixel dd __sys_putpixel ; } mike.dld @@ -151,10 +151,10 @@ align 4 keyboard dd 1 syslang dd 1 -boot_y dd 10 +boot_y dd 10 -pci_bios_entry dd 0 - dw pci_code_sel +pci_bios_entry dd 0 + dw pci_code_sel if __DEBUG__ eq 1 include_debug_strings @@ -165,292 +165,292 @@ IncludeIGlobals align 16 gdts: - dw gdte-$-1 - dd gdts - dw 0 + dw gdte-$-1 + dd gdts + dw 0 ; Attention! Do not change the order of the first four selectors. They are used in Fast System Call ; must be : os_code, os_data, app_code, app_data, .... int_code_l: os_code_l: - dw 0xffff - dw 0x0000 - db 0x00 - dw 11011111b *256 +10011010b - db 0x00 + dw 0xffff + dw 0x0000 + db 0x00 + dw 11011111b *256 +10011010b + db 0x00 int_data_l: os_data_l: - dw 0xffff - dw 0x0000 - db 0x00 - dw 11011111b *256 +10010010b - db 0x00 + dw 0xffff + dw 0x0000 + db 0x00 + dw 11011111b *256 +10010010b + db 0x00 app_code_l: - dw 0xFFFF - dw 0 - db 0 - db cpl3 - dw G32+D32+0xF; + dw 0xFFFF + dw 0 + db 0 + db cpl3 + dw G32+D32+0xF; app_data_l: - dw 0xFFFF - dw 0 - db 0 - db drw3 - dw G32+D32+0xF; + dw 0xFFFF + dw 0 + db 0 + db drw3 + dw G32+D32+0xF; ; ------------- PCI BIOS ------------------ pci_code_32: - dw 0 ;lim 0-15 - dw 0 ;base 0-15 - db 0 ;base 16-23 - db cpl0 ;type - db D32 ;lim 16-19+props - db 0 ;base 24-31 + dw 0 ;lim 0-15 + dw 0 ;base 0-15 + db 0 ;base 16-23 + db cpl0 ;type + db D32 ;lim 16-19+props + db 0 ;base 24-31 pci_data_32: - dw 0 ;lim 0-15 - dw 0 ;base 0-15 - db 0 ;base 16-23 - db dpl0 ;type - db D32 ;lim 16-19+props - db 0 ;base 24-31 + dw 0 ;lim 0-15 + dw 0 ;base 0-15 + db 0 ;base 16-23 + db dpl0 ;type + db D32 ;lim 16-19+props + db 0 ;base 24-31 ; --------------- APM --------------------- apm_code_32: - dw 0x0f ; limit 64kb - db 0, 0, 0 - dw 11010000b *256 +10011010b - db 0x00 + dw 0x0f ; limit 64kb + db 0, 0, 0 + dw 11010000b *256 +10011010b + db 0x00 apm_code_16: - dw 0x0f - db 0, 0, 0 - dw 10010000b *256 +10011010b - db 0x00 + dw 0x0f + db 0, 0, 0 + dw 10010000b *256 +10011010b + db 0x00 apm_data_16: - dw 0x0f - db 0, 0, 0 - dw 10010000b *256 +10010010b - db 0x00 + dw 0x0f + db 0, 0, 0 + dw 10010000b *256 +10010010b + db 0x00 ; ----------------------------------------- graph_data_l: - dw 0x7ff - dw 0x0000 - db 0x00 - dw 11010000b *256 +11110010b - db 0x00 + dw 0x7ff + dw 0x0000 + db 0x00 + dw 11010000b *256 +11110010b + db 0x00 tss0_l: - dw TSS_SIZE-1 - dw tss and 0xFFFF - db (tss shr 16) and 0xFF - db 10001001b - dw (tss shr 16) and 0xFF00 + dw TSS_SIZE-1 + dw tss and 0xFFFF + db (tss shr 16) and 0xFF + db 10001001b + dw (tss shr 16) and 0xFF00 tls_data_l: - dw 0x0FFF - dw 0 - db 0 - db drw3 - dw D32 + dw 0x0FFF + dw 0 + db 0 + db drw3 + dw D32 endofcode: gdte: align 16 -cur_saved_data rb 4096 -fpu_data: rb 512 +cur_saved_data rb 4096 +fpu_data: rb 512 ; device irq owners -irq_owner rd 16 ; process id +irq_owner rd 16 ; process id ; on irq read ports -irq00read rd 16 -irq01read rd 16 -irq02read rd 16 -irq03read rd 16 -irq04read rd 16 -irq05read rd 16 -irq06read rd 16 -irq07read rd 16 -irq08read rd 16 -irq09read rd 16 -irq10read rd 16 -irq11read rd 16 -irq12read rd 16 -irq13read rd 16 -irq14read rd 16 -irq15read rd 16 +irq00read rd 16 +irq01read rd 16 +irq02read rd 16 +irq03read rd 16 +irq04read rd 16 +irq05read rd 16 +irq06read rd 16 +irq07read rd 16 +irq08read rd 16 +irq09read rd 16 +irq10read rd 16 +irq11read rd 16 +irq12read rd 16 +irq13read rd 16 +irq14read rd 16 +irq15read rd 16 -irq_tab rd 16 +irq_tab rd 16 -mem_block_map rb 512 -mem_block_list rd 64 +mem_block_map rb 512 +mem_block_list rd 64 large_block_list rd 31 -mem_block_mask rd 2 +mem_block_mask rd 2 large_block_mask rd 1 -mem_used.fd rd 1 -mem_used.bk rd 1 +mem_used.fd rd 1 +mem_used.bk rd 1 -mem_block_arr rd 1 +mem_block_arr rd 1 mem_block_start rd 1 -mem_block_end rd 1 +mem_block_end rd 1 -heap_mutex rd 1 -heap_size rd 1 -heap_free rd 1 -heap_blocks rd 1 -free_blocks rd 1 +heap_mutex rd 1 +heap_size rd 1 +heap_free rd 1 +heap_blocks rd 1 +free_blocks rd 1 mst MEM_STATE -page_start rd 1 -page_end rd 1 -sys_page_map rd 1 -os_stack_seg rd 1 +page_start rd 1 +page_end rd 1 +sys_page_map rd 1 +os_stack_seg rd 1 -srv.fd rd 1 -srv.bk rd 1 +srv.fd rd 1 +srv.bk rd 1 align 16 -_display display_t +_display display_t -_WinMapAddress rd 1 -_WinMapSize rd 1 +_WinMapAddress rd 1 +_WinMapSize rd 1 -def_cursor rd 1 -current_cursor rd 1 -hw_cursor rd 1 -cur_saved_base rd 1 +def_cursor rd 1 +current_cursor rd 1 +hw_cursor rd 1 +cur_saved_base rd 1 -cur.lock rd 1 ;1 - lock update, 2- hide -cur.left rd 1 ;cursor clip box -cur.top rd 1 -cur.right rd 1 -cur.bottom rd 1 -cur.w rd 1 -cur.h rd 1 +cur.lock rd 1 ;1 - lock update, 2- hide +cur.left rd 1 ;cursor clip box +cur.top rd 1 +cur.right rd 1 +cur.bottom rd 1 +cur.w rd 1 +cur.h rd 1 -ipc_tmp rd 1 -ipc_pdir rd 1 -ipc_ptab rd 1 +ipc_tmp rd 1 +ipc_pdir rd 1 +ipc_ptab rd 1 -proc_mem_map rd 1 -proc_mem_pdir rd 1 -proc_mem_tab rd 1 +proc_mem_map rd 1 +proc_mem_pdir rd 1 +proc_mem_tab rd 1 -tmp_task_pdir rd 1 -tmp_task_ptab rd 1 +tmp_task_pdir rd 1 +tmp_task_ptab rd 1 -default_io_map rd 1 +default_io_map rd 1 -LFBSize rd 1 +LFBSize rd 1 -stall_mcs rd 1 -current_slot rd 1 +stall_mcs rd 1 +current_slot rd 1 ; status -hd1_status rd 1 ; 0 - free : other - pid +hd1_status rd 1 ; 0 - free : other - pid application_table_status rd 1 ; 0 - free : other - pid ; device addresses -mididp rd 1 -midisp rd 1 +mididp rd 1 +midisp rd 1 -cdbase rd 1 -cdid rd 1 +cdbase rd 1 +cdid rd 1 -hdbase rd 1 ; for boot 0x1f0 -hdid rd 1 -hdpos rd 1 ; for boot 0x1 -label known_part dword -fat32part rd 1 ; for boot 0x1 -cdpos rd 1 +hdbase rd 1 ; for boot 0x1f0 +hdid rd 1 +hdpos rd 1 ; for boot 0x1 +label known_part dword +fat32part rd 1 ; for boot 0x1 +cdpos rd 1 ;CPUID information -cpu_vendor rd 3 -cpu_sign rd 1 -cpu_info rd 1 -cpu_caps rd 4 +cpu_vendor rd 3 +cpu_sign rd 1 +cpu_info rd 1 +cpu_caps rd 4 -pg_data PG_DATA -heap_test rd 1 +pg_data PG_DATA +heap_test rd 1 -buttontype rd 1 +buttontype rd 1 windowtypechanged rd 1 -hd_entries rd 1 ;unused ? 0xfe10 +hd_entries rd 1 ;unused ? 0xfe10 ;* start code - Mario79 -mouse_active rd 1 -mouse_pause rd 1 +mouse_active rd 1 +mouse_pause rd 1 MouseTickCounter rd 1 ;* end code - Mario79 -img_background rd 1 -mem_BACKGROUND rd 1 +img_background rd 1 +mem_BACKGROUND rd 1 static_background_data rd 1 cache_ide0: -cache_ide0_pointer rd 1 -cache_ide0_size rd 1 ; not use +cache_ide0_pointer rd 1 +cache_ide0_size rd 1 ; not use cache_ide0_data_pointer rd 1 cache_ide0_system_data_size rd 1 ; not use cache_ide0_appl_data_size rd 1 ; not use -cache_ide0_system_data rd 1 -cache_ide0_appl_data rd 1 +cache_ide0_system_data rd 1 +cache_ide0_appl_data rd 1 cache_ide0_system_sad_size rd 1 cache_ide0_appl_sad_size rd 1 cache_ide0_search_start rd 1 cache_ide0_appl_search_start rd 1 cache_ide1: -cache_ide1_pointer rd 1 -cache_ide1_size rd 1 ; not use +cache_ide1_pointer rd 1 +cache_ide1_size rd 1 ; not use cache_ide1_data_pointer rd 1 cache_ide1_system_data_size rd 1 ; not use cache_ide1_appl_data_size rd 1 ; not use -cache_ide1_system_data rd 1 -cache_ide1_appl_data rd 1 +cache_ide1_system_data rd 1 +cache_ide1_appl_data rd 1 cache_ide1_system_sad_size rd 1 cache_ide1_appl_sad_size rd 1 cache_ide1_search_start rd 1 cache_ide1_appl_search_start rd 1 cache_ide2: -cache_ide2_pointer rd 1 -cache_ide2_size rd 1 ; not use +cache_ide2_pointer rd 1 +cache_ide2_size rd 1 ; not use cache_ide2_data_pointer rd 1 cache_ide2_system_data_size rd 1 ; not use cache_ide2_appl_data_size rd 1 ; not use -cache_ide2_system_data rd 1 -cache_ide2_appl_data rd 1 +cache_ide2_system_data rd 1 +cache_ide2_appl_data rd 1 cache_ide2_system_sad_size rd 1 cache_ide2_appl_sad_size rd 1 cache_ide2_search_start rd 1 cache_ide2_appl_search_start rd 1 cache_ide3: -cache_ide3_pointer rd 1 -cache_ide3_size rd 1 ; not use +cache_ide3_pointer rd 1 +cache_ide3_size rd 1 ; not use cache_ide3_data_pointer rd 1 cache_ide3_system_data_size rd 1 ; not use cache_ide3_appl_data_size rd 1 ; not use -cache_ide3_system_data rd 1 -cache_ide3_appl_data rd 1 +cache_ide3_system_data rd 1 +cache_ide3_appl_data rd 1 cache_ide3_system_sad_size rd 1 cache_ide3_appl_sad_size rd 1 cache_ide3_search_start rd 1 @@ -462,11 +462,11 @@ cd_appl_data rb 1 ; 0 = system cache, 1 - application cache lba_read_enabled rd 1 ; 0 = disabled , 1 = enabled pci_access_enabled rd 1 ; 0 = disabled , 1 = enabled -timer_ticks_enable rb 1 ; for cd driver +timer_ticks_enable rb 1 ; for cd driver -NumBiosDisks rd 1 -BiosDisksData rb 200h -BiosDiskCaches rb 80h*(cache_ide1-cache_ide0) +NumBiosDisks rd 1 +BiosDisksData rb 200h +BiosDiskCaches rb 80h*(cache_ide1-cache_ide0) BiosDiskPartitions rd 80h IncludeUGlobals diff --git a/kernel/branches/Kolibri-A/trunk/kernel.asm b/kernel/branches/Kolibri-A/trunk/kernel.asm index 25ede986b3..c972f42d81 100644 --- a/kernel/branches/Kolibri-A/trunk/kernel.asm +++ b/kernel/branches/Kolibri-A/trunk/kernel.asm @@ -4253,11 +4253,11 @@ sys_gs: ; direct screen access ;align 4 ; PCI functions ; -;sys_pci: -; -; call pci_api -; mov [esp+36],eax -; ret +sys_pci: + + call pci_api + mov [esp+36],eax + ret align 4 ; system functions diff --git a/kernel/branches/Kolibri-A/utilities/SB700/LPC_REG.ASM b/kernel/branches/Kolibri-A/utilities/SB700/LPC_REG.ASM new file mode 100644 index 0000000000..dac645d53e --- /dev/null +++ b/kernel/branches/Kolibri-A/utilities/SB700/LPC_REG.ASM @@ -0,0 +1,345 @@ + ;; ZiS test -- Art J ;; + + + use32 ; + org 0x0 ; + + db 'MENUET01' ; + dd 0x01 ; + dd START ; + dd I_END ; + dd 0x1000 ; + dd 0x1000 ; + dd 0x0 ; + dd 0x0 ; + +include 'MACROS.INC' ; + +PCIE_SPACE equ 0xF0000000 +PCIE_ADDR equ 0xF00A3000 ; bdf0:20.3 = SB7xx LPC Config Registers +BOX_COLOR equ 0xE0D8D0 + +START: + + mov edx, 0x88 + add edx, PCIE_ADDR + mov eax, 0x00010101 + mov [edx], eax + + +red: + + call draw_window + +still: + mcall 10 ; event waiting + + cmp eax,1 ; redraw window + je red ; + cmp eax,2 ; key pressed? + je key ; + cmp eax,3 ; button hit? + je button ; + + jmp still ; none of that + +;--------------------------------------------------------------------- + + key: ; key pressed + jmp red + +;--------------------------------------------------------------------- + + button: + mcall 17 ; get the button ID + cmp ah, 1 + jne .bt2 + mcall -1 +.bt2: + cmp ah, 2 + jne .bt3 + sub [Reg],4 ; Rg# decrement + jmp red +.bt3: + cmp ah, 3 + jne .bt4 + add [Reg],4 ; Rg# increment + jmp red +.bt4: + cmp ah, 4 + jne .bt5 + add [Reg],4*16 ; PgDn + jmp red +.bt5: + cmp ah, 5 + jne .bt6 + mov edx, [Reg] + cmp edx, 4*16 + jb @f + sub edx, 4*16 + mov [Reg],edx ; PgUp + jmp red +@@: + xor edx, edx + mov [Reg], edx + jmp red + +.bt6: + cmp ah, 6 + jne still + mcall 37, 1 ; get the mouse pointer + shr eax, 16 ; only X needed + sub eax, 124 ; check the left border + jb red + xor edx, edx + mov ebx, 12 + div ebx + cmp eax, 32 ; check the right border + jnb red + mov ecx, 31 + sub ecx, eax ; reverse the bit order + mov ebx, [Rct] + btc ebx, ecx ; invert the bit + mov eax, [Reg] + add eax, PCIE_ADDR + mov [Rct], ebx + mov [eax], ebx + + jmp red + + +;------------------------------------------------ +print_config_reg: +;------------------------------------------------ + mov eax, [reg] + and eax, 0x0FFC + mov ebx, 4*65536+256 ; 4 hex digits + mov ecx, eax + mov dx,[stX] + shl edx,16 ; = X*65536 + mov dx,[stY] ; = edx + Y + mov esi,0 + mcall 47 ; print reg# + mov eax, [reg] + add eax, PCIE_ADDR + mov ecx, [eax] + add edx, 36*65536 ; right column + mov ebx, 8*65536+256 ; 8 hex digits + mcall 47 ; print config data + ret +;------------------------------------------------ +read_nbconfig: +; in: dl = reg# | out: eax = data +;------------------------------------------------ + mov ebx, 0xF0000000 + and edx, 0x0FC + mov eax, dword [ebx+edx] + ret +;------------------------------------------------ +write_nbconfig: +; in: dl = reg#; eax = data +;------------------------------------------------ + mov ebx, 0xF0000000 + and edx, 0x0FC + mov dword [ebx+edx], eax + ret + +;------------------------------------------------ +;read_htiunbind: +; in: [HTr] = reg# | out: eax = data +;------------------------------------------------ +; mov dl, 0x94 +; mov al, byte[HTr] +; and eax, 0x07C +; call write_nbconfig +; add dl, 4 +; call read_nbconfig +; ret +;------------------------------------------------ +;write_htiunbind: +; in: [HTr] = reg#; ecx = data +;------------------------------------------------ +; mov dl, 0x94 +; mov al, byte[Reg] +; and eax, 0x017C +; call write_nbconfig +; add dl, 4 +; mov ecx, eax +; call write_nbconfig +; sub dl, 4 +; mov eax, 0x0 +; call write_nbconfig +; ret + + + + + + + +;------------------------------------------------ + draw_window: +;------------------------------------------------ + + + mcall 12, 1 + mcall 0, 600*65536+530, 120*65536+290, 0x1499AAA0,,title +; ----------------------------------------------------------------- +; BUTTONS: Xleft Xwid, Ytop Yheig + mcall 8, 370*65536+ 40, 26*65536+ 18, 2, 0x99AABB ; << + mcall , , 51*65536+ 18, 3, ; >> + mcall , 425*65536+ 90, 26*65536+ 18, 4, ; PCIe Cfg + mcall , , 51*65536+ 18, 5, ; NB config + mcall , 117*65536+400, 97*65536+ 40, 6, ; Bits + + mov edx, [Reg] + add edx, PCIE_ADDR ; reading the current reg content + mov ecx, [edx] + mov [Rct], ecx + + mov ebx, bitstr2 + inc ebx + mov edx, [Rct] + mov ecx, 0x80000000 + xor eax, eax +.stringtest: + test edx, ecx + jz @f + mov byte [ebx+eax*2],'I' ; bit dump + jmp .nextbit +@@: + mov byte [ebx+eax*2],'0' +.nextbit: + inc eax + shr ecx, 1 + jnz .stringtest + +; button txt: X *65536+ Y + mcall 4, 378*65536+32 ,0x10000000, butstr2,3 + mcall , 378*65536+57 , , butstr3, + mcall , 436*65536+32 , , butstr4,9 + mcall , 436*65536+57 , , butstr5, + + mcall 4, 122*65536+101,0 , bitstr0,65 + mcall , 122*65536+110,0 , bitstr1,65 + mcall , 122*65536+117,0 , bitstr2,65 + mcall , 122*65536+126,0 , bitstr3,65 +; ----------------------------------------------------------------- +; draw the reg-value box + mov ebx, 10*65536+100 ; Xleft | Xwidth + mov ecx, 26*65536+250 ; Ytop | Yheight + mov edx, BOX_COLOR + mcall 13 +; draw the reg-address box + mov ebx, 206*65536+146 ; Xleft | Xwidth + mov cx, 44 ; Yheight only + mcall 13 +; draw ZiS status box +; mov ebx, 206*65536+274 ; Xleft | Xwidth +; mov ecx, 84*65536+ 64 ; Ytop | Yheight +; mcall 13 +; draw the dump box +; mov ebx, 206*65536+274 ; Xleft | Xwidth +; mov ecx, 190*65536+232 ; Ytop | Yheight +; mcall 13 + +; fill the data box + mov ebx, [Reg] + mov [reg],ebx + mov bx, 40 ; upper position + mov [stY],bx +.print_reg_names: + call print_config_reg + add [stY],14 + add [reg], 4 + mov edx,[Reg] + add edx,16*4 + cmp edx,[reg] + ja .print_reg_names + +; fill the status box + mcall 4, 210*65536+30,0,str1,12 + mcall , 210*65536+44, ,str2, + mcall , 210*65536+56, ,str3, + mov ecx, PCIE_ADDR + mov edx, 300*65536+30 + mov ebx, 8*65536+256 + mcall 47 + add dx, 14 + mov ecx,[Reg] + mov esi, 0 + mcall 47 + add dx,14 + mov ecx, [Rct] + mcall 47 + +; print extra info + mov ebx, 120*65536+180 + xor ecx, ecx + mov edx, info1 +@@: + mcall 4,,,,66 + add edx, 66 + add ebx, 14 + cmp edx, info_end + jb @b + + + mcall 12, 2 ; дг­ЄжЁп 12: б®®ЎйЁвм Ћ‘ ®Ў ®ваЁб®ўЄҐ ®Є­  + +ret + + +align 4 +;------------------------------------------------- + + pix dd 0x55AACC33 + pxX dd 200 + pxY dd 160 + stX dw 18 + stY dw 0 + reg dd 0 + + Rct dd 0 ; reg content + Reg dd 0x00 ; reg number + + + title db ' SB710 LPC Config Registers - LPC_Reg ',0 +;------------------------------------------------------------------------------------ + reg_str db 'Reg#| hex.Value ' +;------------------------------------------------------------------------------------ +str1 db 'bdf address:' +str2 db 'Reg. number:' +str3 db 'Reg.content:' + + butstr2 db ' << ' + butstr3 db ' >> ' + butstr4 db 'Next Page' + butstr5 db 'Prev Page' + +bitstr0 db '31',209,205,209,205,209,205,209,205,209,205,209,205,'24',\ + 209,205,209,205,209,205,209,205,209,205,209,205,209,205,'16',\ + 209,'15',205,209,205,209,205,209,205,209,205,209,205,209,'8',\ + 205,'7',209,205,209,205,209,205,209,205,209,205,209,205,209,'0',184 +bitstr1 db 179,' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ',179 +bitstr2 db 179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179,'9 8 7 6',\ + 179,'5 4 3 2',179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179 +bitstr3 db 212,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,190 + +info1 db '--------------------------- extra info ---------------------------' +info2 db '| reg 00[31:16] (DeviceID): 439D = SB7100/710/750 LPC bus |' + db '| reg |' + db '| reg |' + db '| reg |' + db '------------------------------------------------------------------' +info_end: + +I_END: ; end of program + + rd 256 + +align 256 +st_0: diff --git a/kernel/branches/Kolibri-A/utilities/SB700/PCI_REG.ASM b/kernel/branches/Kolibri-A/utilities/SB700/PCI_REG.ASM new file mode 100644 index 0000000000..22a9714960 --- /dev/null +++ b/kernel/branches/Kolibri-A/utilities/SB700/PCI_REG.ASM @@ -0,0 +1,344 @@ +$Revision: 1598 $ + + use32 ; + org 0x0 ; + + db 'MENUET01' ; + dd 0x01 ; + dd START ; + dd I_END ; + dd 0x1000 ; + dd 0x1000 ; + dd 0x0 ; + dd 0x0 ; + +include 'MACROS.INC' ; + +PCIE_SPACE equ 0xF0000000 +PCIE_ADDR equ 0xF00A0000 ; bdf0:20.0 = SB7xx PCI Config Registers +BOX_COLOR equ 0xE0D8D0 + +START: + + mov edx, 0x88 + add edx, PCIE_ADDR + mov eax, 0x00010101 + mov [edx], eax + + +red: + + call draw_window + +still: + mcall 10 ; event waiting + + cmp eax,1 ; redraw window + je red ; + cmp eax,2 ; key pressed? + je key ; + cmp eax,3 ; button hit? + je button ; + + jmp still ; none of that + +;--------------------------------------------------------------------- + + key: ; key pressed + jmp red + +;--------------------------------------------------------------------- + + button: + mcall 17 ; get the button ID + cmp ah, 1 + jne .bt2 + mcall -1 +.bt2: + cmp ah, 2 + jne .bt3 + sub [Reg],4 ; Rg# decrement + jmp red +.bt3: + cmp ah, 3 + jne .bt4 + add [Reg],4 ; Rg# increment + jmp red +.bt4: + cmp ah, 4 + jne .bt5 + add [Reg],4*16 ; PgDn + jmp red +.bt5: + cmp ah, 5 + jne .bt6 + mov edx, [Reg] + cmp edx, 4*16 + jb @f + sub edx, 4*16 + mov [Reg],edx ; PgUp + jmp red +@@: + xor edx, edx + mov [Reg], edx + jmp red + +.bt6: + cmp ah, 6 + jne still + mcall 37, 1 ; get the mouse pointer + shr eax, 16 ; only X needed + sub eax, 124 ; check the left border + jb red + xor edx, edx + mov ebx, 12 + div ebx + cmp eax, 32 ; check the right border + jnb red + mov ecx, 31 + sub ecx, eax ; reverse the bit order + mov ebx, [Rct] + btc ebx, ecx ; invert the bit + mov eax, [Reg] + add eax, PCIE_ADDR + mov [Rct], ebx + mov [eax], ebx + + jmp red + + +;------------------------------------------------ +print_config_reg: +;------------------------------------------------ + mov eax, [reg] + and eax, 0x0FFC + mov ebx, 4*65536+256 ; 4 hex digits + mov ecx, eax + mov dx,[stX] + shl edx,16 ; = X*65536 + mov dx,[stY] ; = edx + Y + mov esi,0 + mcall 47 ; print reg# + mov eax, [reg] + add eax, PCIE_ADDR + mov ecx, [eax] + add edx, 36*65536 ; right column + mov ebx, 8*65536+256 ; 8 hex digits + mcall 47 ; print config data + ret +;------------------------------------------------ +read_nbconfig: +; in: dl = reg# | out: eax = data +;------------------------------------------------ + mov ebx, 0xF0000000 + and edx, 0x0FC + mov eax, dword [ebx+edx] + ret +;------------------------------------------------ +write_nbconfig: +; in: dl = reg#; eax = data +;------------------------------------------------ + mov ebx, 0xF0000000 + and edx, 0x0FC + mov dword [ebx+edx], eax + ret + +;------------------------------------------------ +;read_htiunbind: +; in: [HTr] = reg# | out: eax = data +;------------------------------------------------ +; mov dl, 0x94 +; mov al, byte[HTr] +; and eax, 0x07C +; call write_nbconfig +; add dl, 4 +; call read_nbconfig +; ret +;------------------------------------------------ +;write_htiunbind: +; in: [HTr] = reg#; ecx = data +;------------------------------------------------ +; mov dl, 0x94 +; mov al, byte[Reg] +; and eax, 0x017C +; call write_nbconfig +; add dl, 4 +; mov ecx, eax +; call write_nbconfig +; sub dl, 4 +; mov eax, 0x0 +; call write_nbconfig +; ret + + + + + + + +;------------------------------------------------ + draw_window: +;------------------------------------------------ + + + mcall 12, 1 + mcall 0, 600*65536+530, 120*65536+290, 0x1499AABB,,title +; ----------------------------------------------------------------- +; BUTTONS: Xleft Xwid, Ytop Yheig + mcall 8, 370*65536+ 40, 26*65536+ 18, 2, 0x99AABB ; << + mcall , , 51*65536+ 18, 3, ; >> + mcall , 425*65536+ 90, 26*65536+ 18, 4, ; PCIe Cfg + mcall , , 51*65536+ 18, 5, ; NB config + mcall , 117*65536+400, 97*65536+ 40, 6, ; Bits + + mov edx, [Reg] + add edx, PCIE_ADDR ; reading the current reg content + mov ecx, [edx] + mov [Rct], ecx + + mov ebx, bitstr2 + inc ebx + mov edx, [Rct] + mov ecx, 0x80000000 + xor eax, eax +.stringtest: + test edx, ecx + jz @f + mov byte [ebx+eax*2],'I' ; bit dump + jmp .nextbit +@@: + mov byte [ebx+eax*2],'0' +.nextbit: + inc eax + shr ecx, 1 + jnz .stringtest + +; button txt: X *65536+ Y + mcall 4, 378*65536+32 ,0x10000000, butstr2,3 + mcall , 378*65536+57 , , butstr3, + mcall , 436*65536+32 , , butstr4,9 + mcall , 436*65536+57 , , butstr5, + + mcall 4, 122*65536+101,0 , bitstr0,65 + mcall , 122*65536+110,0 , bitstr1,65 + mcall , 122*65536+117,0 , bitstr2,65 + mcall , 122*65536+126,0 , bitstr3,65 +; ----------------------------------------------------------------- +; draw the reg-value box + mov ebx, 10*65536+100 ; Xleft | Xwidth + mov ecx, 26*65536+250 ; Ytop | Yheight + mov edx, BOX_COLOR + mcall 13 +; draw the reg-address box + mov ebx, 206*65536+146 ; Xleft | Xwidth + mov cx, 44 ; Yheight only + mcall 13 +; draw ZiS status box +; mov ebx, 206*65536+274 ; Xleft | Xwidth +; mov ecx, 84*65536+ 64 ; Ytop | Yheight +; mcall 13 +; draw the dump box +; mov ebx, 206*65536+274 ; Xleft | Xwidth +; mov ecx, 190*65536+232 ; Ytop | Yheight +; mcall 13 + +; fill the data box + mov ebx, [Reg] + mov [reg],ebx + mov bx, 40 ; upper position + mov [stY],bx +.print_reg_names: + call print_config_reg + add [stY],14 + add [reg], 4 + mov edx,[Reg] + add edx,16*4 + cmp edx,[reg] + ja .print_reg_names + +; fill the status box + mcall 4, 210*65536+30,0,str1,12 + mcall , 210*65536+44, ,str2, + mcall , 210*65536+56, ,str3, + mov ecx, PCIE_ADDR + mov edx, 300*65536+30 + mov ebx, 8*65536+256 + mcall 47 + add dx, 14 + mov ecx,[Reg] + mov esi, 0 + mcall 47 + add dx,14 + mov ecx, [Rct] + mcall 47 + +; print extra info + mov ebx, 120*65536+180 + xor ecx, ecx + mov edx, info1 +@@: + mcall 4,,,,66 + add edx, 66 + add ebx, 14 + cmp edx, info_end + jb @b + + + mcall 12, 2 ; дг­ЄжЁп 12: б®®ЎйЁвм Ћ‘ ®Ў ®ваЁб®ўЄҐ ®Є­  + +ret + + +align 4 +;------------------------------------------------- + + pix dd 0x55AACC33 + pxX dd 200 + pxY dd 160 + stX dw 18 + stY dw 0 + reg dd 0 + + Rct dd 0 ; reg content + Reg dd 0x00 ; reg number + + + title db ' SB710 PCI Config Registers - PCI_Reg ',0 +;------------------------------------------------------------------------------------ + reg_str db 'Reg#| hex.Value ' +;------------------------------------------------------------------------------------ +str1 db 'bdf address:' +str2 db 'Reg. number:' +str3 db 'Reg.content:' + + butstr2 db ' << ' + butstr3 db ' >> ' + butstr4 db 'Next Page' + butstr5 db 'Prev Page' + +bitstr0 db '31',209,205,209,205,209,205,209,205,209,205,209,205,'24',\ + 209,205,209,205,209,205,209,205,209,205,209,205,209,205,'16',\ + 209,'15',205,209,205,209,205,209,205,209,205,209,205,209,'8',\ + 205,'7',209,205,209,205,209,205,209,205,209,205,209,205,209,'0',184 +bitstr1 db 179,' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ',179 +bitstr2 db 179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179,'9 8 7 6',\ + 179,'5 4 3 2',179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179 +bitstr3 db 212,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,190 + +info1 db '--------------------------- extra info ---------------------------' +info2 db '| reg 00[31:16] (DeviceID): 4385=SB7100/710/750 SMBus module |' + db '| reg |' + db '| reg |' + db '| reg |' + db '------------------------------------------------------------------' +info_end: + +I_END: ; end of program + + rd 256 + +align 256 +st_0: diff --git a/kernel/branches/Kolibri-A/utilities/SB700/SB_CM_RG.ASM b/kernel/branches/Kolibri-A/utilities/SB700/SB_CM_RG.ASM new file mode 100644 index 0000000000..55121bb164 --- /dev/null +++ b/kernel/branches/Kolibri-A/utilities/SB700/SB_CM_RG.ASM @@ -0,0 +1,314 @@ +$Revision: 1598 $ + + use32 ; + org 0x0 ; + + db 'MENUET01' ; + dd 0x01 ; + dd START ; + dd I_END ; + dd 0x1000 ; + dd 0x1000 ; + dd 0x0 ; + dd 0x0 ; + +include 'MACROS.INC' ; + +SB_PM_INDEX equ 0xC50 +SB_PM_DATA equ 0xC51 +BOX_COLOR equ 0xD0C8C0 + +START: + + + + + +red: + + call draw_window + +still: + mcall 10 ; event waiting + + cmp eax,1 ; redraw window + je red ; + cmp eax,2 ; key pressed? + je key ; + cmp eax,3 ; button hit? + je button ; + + jmp still ; none of that + +;--------------------------------------------------------------------- + + key: ; key pressed + jmp red + +;--------------------------------------------------------------------- + + button: + mcall 17 ; get the button ID + cmp ah, 1 + jne .bt2 + mcall -1 +.bt2: + cmp ah, 2 + jne .bt3 + dec [Reg] ; Rg# decrement + jmp red +.bt3: + cmp ah, 3 + jne .bt4 + inc [Reg] ; Rg# increment + jmp red +.bt4: + cmp ah, 4 + jne .bt5 + add [Reg],16 ; PgDn + jmp red +.bt5: + cmp ah, 5 + jne .bt6 + mov edx, [Reg] + cmp edx, 16 + jb @f + sub edx, 16 + mov [Reg],edx ; PgUp + jmp red +@@: + xor edx, edx + mov [Reg], edx + jmp red + +.bt6: + cmp ah, 6 + jne still + mcall 37, 1 ; get the mouse pointer + shr eax, 16 ; only X needed + sub eax, 124 ; check the left border + jb red + xor edx, edx + mov ebx, 12 + div ebx + cmp eax, 32 ; check the right border + jnb red + mov ecx, 31 + sub ecx, eax ; reverse the bit order + mov ebx, [Rct] + btc ebx, ecx ; invert the bit + mov eax, [Reg] + mov [Rct], ebx + call write_sb_pm_reg + + jmp red + + +;------------------------------------------------ +print_config_reg: +;------------------------------------------------ + mov eax, [Reg] +; and eax, 0x0FF + mov ebx, 3*65536+256 ; 3 hex digits + mov ecx, eax + mov dx,[stX] + shl edx,16 ; = X*65536 + mov dx,[stY] ; = edx + Y + mov esi,0 + mcall 47 ; print reg# + mov ecx, edx + call read_sb_pm_reg + mov edx, ecx + mov ecx, eax + add edx, 36*65536 ; right column + mov ebx, 8*65536+256 ; 8 hex digits + mcall 47 ; print config data + ret + +;------------------------------------------------ +read_sb_pm_reg: +; in: [Reg] = reg# | out: eax = [Rct] = data +;------------------------------------------------ + mov dx, SB_PM_INDEX + xor eax, eax + mov al, byte [Reg] + out dx, al + inc dl + in al, dx + mov [Rct], eax + ret + +;------------------------------------------------ +write_sb_pm_reg: +; in: [Reg] = reg#; [Rct] = data +;------------------------------------------------ + mov dx, SB_PM_INDEX + xor eax, eax + mov al, byte [Reg] + out dx, al + inc dl + mov eax, [Rct] + out dx, al + ret + + +;------------------------------------------------ + draw_window: +;------------------------------------------------ + + + mcall 12, 1 + mcall 0, 600*65536+530, 410*65536+290, 0x14748090,,title +; ----------------------------------------------------------------- +; BUTTONS: Xleft Xwid, Ytop Yheig + mcall 8, 370*65536+ 40, 26*65536+ 18, 2, 0x94A0B0 ; << + mcall , , 51*65536+ 18, 3, ; >> + mcall , 425*65536+ 90, 26*65536+ 18, 4, ; Next Page + mcall , , 51*65536+ 18, 5, ; Prev Page + mcall , 117*65536+400, 97*65536+ 40, 6, ; Bits + + call read_sb_pm_reg + + mov ebx, bitstr2 + inc ebx + mov edx, [Rct] + mov ecx, 0x80000000 + xor eax, eax +.stringtest: + test edx, ecx + jz @f + mov byte [ebx+eax*2],'I' ; bit dump + jmp .nextbit +@@: + mov byte [ebx+eax*2],'0' +.nextbit: + inc eax + shr ecx, 1 + jnz .stringtest + +; button txt: X *65536+ Y + mcall 4, 378*65536+32 ,0x10000000, butstr2,3 + mcall , 378*65536+57 , , butstr3, + mcall , 436*65536+32 , , butstr4,9 + mcall , 436*65536+57 , , butstr5, + + mcall 4, 122*65536+101,0 , bitstr0,65 + mcall , 122*65536+110,0 , bitstr1,65 + mcall , 122*65536+117,0 , bitstr2,65 + mcall , 122*65536+126,0 , bitstr3,65 +; ----------------------------------------------------------------- +; draw the reg-value box + mov ebx, 10*65536+100 ; Xleft | Xwidth + mov ecx, 26*65536+250 ; Ytop | Yheight + mov edx, BOX_COLOR + mcall 13 +; draw the reg-address box + mov ebx, 206*65536+146 ; Xleft | Xwidth + mov cx, 44 ; Yheight only + mcall 13 + +; fill the data box + mov bx, 40 ; upper position + mov [stY],bx + mov eax, [Reg] + mov [reg], eax ; store original# +.print_reg_names: + call print_config_reg + add [stY],14 + inc [Reg] + mov edx,[reg] + mov eax, 16 + add eax, edx + cmp eax,[Reg] + ja .print_reg_names + mov [Reg], edx ; restore original# + +; fill the status box + mcall 4, 210*65536+30,0,str1,12 + mcall , 210*65536+44, ,str2, + mcall , 210*65536+56, ,str3, + call read_sb_pm_reg + mov ecx, SB_PM_DATA + mov edx, 300*65536+30 + mov ebx, 8*65536+256 + mcall 47 + add dx, 14 + mov ecx,[Reg] + mov esi, 0 + mcall 47 + add dx,14 + mov ecx, [Rct] + mcall 47 + +; print extra info + mov ebx, 120*65536+170 + xor ecx, ecx + mov edx, info1 +@@: + mcall 4,,,,66 + add edx, 66 + add ebx, 14 + cmp edx, info_end + jb @b + + + mcall 12, 2 ; дг­ЄжЁп 12: б®®ЎйЁвм Ћ‘ ®Ў ®ваЁб®ўЄҐ ®Є­  + +ret + + +align 4 +;------------------------------------------------- + + pix dd 0x55AACC33 + pxX dd 200 + pxY dd 160 + stX dw 18 + stY dw 0 + reg dd 0 + + Rct dd 0 ; reg content + Reg dd 0x00 ; reg number + + + title db ' SB710 Client Management Registers - IO_CM_Reg',0 +;------------------------------------------------------------------------------------ + reg_str db 'Reg#| hex.Value ' +;------------------------------------------------------------------------------------ +str1 db 'bdf address:' +str2 db 'Reg. number:' +str3 db 'Reg.content:' + + butstr2 db ' << ' + butstr3 db ' >> ' + butstr4 db 'Next Page' + butstr5 db 'Prev Page' + +bitstr0 db '31',209,205,209,205,209,205,209,205,209,205,209,205,'24',\ + 209,205,209,205,209,205,209,205,209,205,209,205,209,205,'16',\ + 209,'15',205,209,205,209,205,209,205,209,205,209,205,209,'8',\ + 205,'7',209,205,209,205,209,205,209,205,209,205,209,205,209,'0',184 +bitstr1 db 179,' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ',179 +bitstr2 db 179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179,'9 8 7 6',\ + 179,'5 4 3 2',179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179 +bitstr3 db 212,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,190 + +info1 db '------------- PM REG -------------' + db '| see AMD SB700/710/750 Register Reference Guide, pp.172-173 |' +info2 db '| reg 00 - IdRegister |' + db '| reg 02 [0]: logical status of TALERT/GPIO64 input (read-clears)|' + db '| reg 03 [1]: generate SMI# ipon TALERT |' + db '| reg 12 - I2C Control |' + db '| reg 13 [7:6]: GpmPortStatus (00=read; 01=OE; 10=output) |' + db '------------------------------------------------------------------' +info_end: + +I_END: ; end of program + + rd 256 + +align 256 +st_0: diff --git a/kernel/branches/Kolibri-A/utilities/SB700/SB_IO_RG.ASM b/kernel/branches/Kolibri-A/utilities/SB700/SB_IO_RG.ASM new file mode 100644 index 0000000000..2dae28b7d5 --- /dev/null +++ b/kernel/branches/Kolibri-A/utilities/SB700/SB_IO_RG.ASM @@ -0,0 +1,331 @@ +$Revision: 1598 $ + + use32 ; + org 0x0 ; + + db 'MENUET01' ; + dd 0x01 ; + dd START ; + dd I_END ; + dd 0x1000 ; + dd 0x1000 ; + dd 0x0 ; + dd 0x0 ; + +include 'MACROS.INC' ; + +SB_SIO_INDEX equ 0x2e +SB_SIO_DATA equ 0x2f +BOX_COLOR equ 0xD0C8C0 + +START: + + call enter_cfg_mode ; call this once + + + +red: + + call draw_window + +still: + mcall 10 ; event waiting + + cmp eax,1 ; redraw window + je red ; + cmp eax,2 ; key pressed? + je key ; + cmp eax,3 ; button hit? + je button ; + + jmp still ; none of that + +;--------------------------------------------------------------------- + + key: ; key pressed + jmp red + +;--------------------------------------------------------------------- + + button: + mcall 17 ; get the button ID + cmp ah, 1 + jne .bt2 + + mov byte[Reg], 2 + mov byte[Rct], 2 + call write_sio_cfg ; exit config-mode on exit + mcall -1 +; -------------- +.bt2: + cmp ah, 2 + jne .bt3 + dec [Reg] ; Rg# decrement + jmp red +.bt3: + cmp ah, 3 + jne .bt4 + inc [Reg] ; Rg# increment + jmp red +.bt4: + cmp ah, 4 + jne .bt5 + add [Reg],16 ; PgDn + jmp red +.bt5: + cmp ah, 5 + jne .bt6 + mov edx, [Reg] + cmp edx, 16 + jb @f + sub edx, 16 + mov [Reg],edx ; PgUp + jmp red +@@: + xor edx, edx + mov [Reg], edx + jmp red + +.bt6: + cmp ah, 6 + jne still + mcall 37, 1 ; get the mouse pointer + shr eax, 16 ; only X needed + sub eax, 124 ; check the left border + jb red + xor edx, edx + mov ebx, 12 + div ebx + cmp eax, 32 ; check the right border + jnb red + mov ecx, 31 + sub ecx, eax ; reverse the bit order + mov ebx, [Rct] + btc ebx, ecx ; invert the bit + mov eax, [Reg] + mov [Rct], ebx + call write_sio_cfg + + jmp red + + +;------------------------------------------------ +print_config_reg: +;------------------------------------------------ + mov eax, [Reg] +; and eax, 0x0FF + mov ebx, 3*65536+256 ; 3 hex digits + mov ecx, eax + mov dx,[stX] + shl edx,16 ; = X*65536 + mov dx,[stY] ; = edx + Y + mov esi,0 + mcall 47 ; print reg# + mov ecx, edx + call read_sio_cfg + mov edx, ecx + mov ecx, eax + add edx, 36*65536 ; right column + mov ebx, 8*65536+256 ; 8 hex digits + mcall 47 ; print config data + ret + +;------------------------------------------------ +read_sio_cfg: +; in: [Reg] = reg# | out: eax = [Rct] = data +;------------------------------------------------ + mov dx, SB_SIO_INDEX + xor eax, eax + mov al, byte [Reg] + out dx, al + inc dl + in al, dx + mov [Rct], eax + ret + +;------------------------------------------------ +write_sio_cfg: +; in: [Reg] = reg#; [Rct] = data +;------------------------------------------------ + mov dx, SB_SIO_INDEX + mov eax, [Reg] + out dx, al + inc dl + mov eax, [Rct] + out dx, al + ret +;------------------------------------------------ +enter_cfg_mode: +; the magic sequence to unlock the port +;------------------------------------------------ + mov dx, SB_SIO_INDEX + mov eax, 0x55550187 ; low byte first + out dx, al + shr eax, 8 + out dx, al + shr eax, 8 + out dx, al + shr eax, 8 + out dx, al + ret + +;------------------------------------------------ + draw_window: +;------------------------------------------------ + + + mcall 12, 1 + mcall 0, 600*65536+530, 410*65536+290, 0x14748090,,title +; ----------------------------------------------------------------- +; BUTTONS: Xleft Xwid, Ytop Yheig + mcall 8, 370*65536+ 40, 26*65536+ 18, 2, 0x94A0B0 ; << + mcall , , 51*65536+ 18, 3, ; >> + mcall , 425*65536+ 90, 26*65536+ 18, 4, ; Next Page + mcall , , 51*65536+ 18, 5, ; Prev Page + mcall , 117*65536+400, 97*65536+ 40, 6, ; Bits + + call read_sio_cfg + + mov ebx, bitstr2 + inc ebx + mov edx, [Rct] + mov ecx, 0x80000000 + xor eax, eax +.stringtest: + test edx, ecx + jz @f + mov byte [ebx+eax*2],'I' ; bit dump + jmp .nextbit +@@: + mov byte [ebx+eax*2],'0' +.nextbit: + inc eax + shr ecx, 1 + jnz .stringtest + +; button txt: X *65536+ Y + mcall 4, 378*65536+32 ,0x10000000, butstr2,3 + mcall , 378*65536+57 , , butstr3, + mcall , 436*65536+32 , , butstr4,9 + mcall , 436*65536+57 , , butstr5, + + mcall 4, 122*65536+101,0 , bitstr0,65 + mcall , 122*65536+110,0 , bitstr1,65 + mcall , 122*65536+117,0 , bitstr2,65 + mcall , 122*65536+126,0 , bitstr3,65 +; ----------------------------------------------------------------- +; draw the reg-value box + mov ebx, 10*65536+100 ; Xleft | Xwidth + mov ecx, 26*65536+250 ; Ytop | Yheight + mov edx, BOX_COLOR + mcall 13 +; draw the reg-address box + mov ebx, 206*65536+146 ; Xleft | Xwidth + mov cx, 44 ; Yheight only + mcall 13 + +; fill the data box + mov bx, 40 ; upper position + mov [stY],bx + mov eax, [Reg] + mov [reg], eax ; store original# +.print_reg_names: + call print_config_reg + add [stY],14 + inc [Reg] + mov edx,[reg] + mov eax, 16 + add eax, edx + cmp eax,[Reg] + ja .print_reg_names + mov [Reg], edx ; restore original# + +; fill the status box + mcall 4, 210*65536+30,0,str1,12 + mcall , 210*65536+44, ,str2, + mcall , 210*65536+56, ,str3, + call read_sio_cfg + mov ecx, SB_SIO_DATA + mov edx, 300*65536+30 + mov ebx, 8*65536+256 + mcall 47 + add dx, 14 + mov ecx,[Reg] + mov esi, 0 + mcall 47 + add dx,14 + mov ecx, [Rct] + mcall 47 + +; print extra info + mov ebx, 120*65536+170 + xor ecx, ecx + mov edx, info1 +@@: + mcall 4,,,,66 + add edx, 66 + add ebx, 14 + cmp edx, info_end + jb @b + + + mcall 12, 2 ; дг­ЄжЁп 12: б®®ЎйЁвм Ћ‘ ®Ў ®ваЁб®ўЄҐ ®Є­  + +ret + + +align 4 +;------------------------------------------------- + + pix dd 0x55AACC33 + pxX dd 200 + pxY dd 160 + stX dw 18 + stY dw 0 + reg dd 0 + + Rct dd 0 ; reg content + Reg dd 0x00 ; reg number + + + title db ' IT8712F -- Super IO control - SIO_Reg',0 +;------------------------------------------------------------------------------------ + reg_str db 'Reg#| hex.Value ' +;------------------------------------------------------------------------------------ +str1 db 'bdf address:' +str2 db 'Reg. number:' +str3 db 'Reg.content:' + + butstr2 db ' << ' + butstr3 db ' >> ' + butstr4 db 'Next Page' + butstr5 db 'Prev Page' + +bitstr0 db '31',209,205,209,205,209,205,209,205,209,205,209,205,'24',\ + 209,205,209,205,209,205,209,205,209,205,209,205,209,205,'16',\ + 209,'15',205,209,205,209,205,209,205,209,205,209,205,209,'8',\ + 205,'7',209,205,209,205,209,205,209,205,209,205,209,205,209,'0',184 +bitstr1 db 179,' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ',179 +bitstr2 db 179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179,'9 8 7 6',\ + 179,'5 4 3 2',179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179 +bitstr3 db 212,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,190 + +info1 db '------------- SIO REG -------------' + db '| see AMD SB700/710/750 Register Reference Guide, pp. |' +info2 db '| |' + db '| reg |' + db '| reg |' + db '| reg |' + db '| reg |' + db '------------------------------------------------------------------' +info_end: + +I_END: ; end of program + + rd 256 + +align 256 +st_0: diff --git a/kernel/branches/Kolibri-A/utilities/SB700/SB_PM2RG.ASM b/kernel/branches/Kolibri-A/utilities/SB700/SB_PM2RG.ASM new file mode 100644 index 0000000000..3980882710 --- /dev/null +++ b/kernel/branches/Kolibri-A/utilities/SB700/SB_PM2RG.ASM @@ -0,0 +1,314 @@ +$Revision: 1598 $ + + use32 ; + org 0x0 ; + + db 'MENUET01' ; + dd 0x01 ; + dd START ; + dd I_END ; + dd 0x1000 ; + dd 0x1000 ; + dd 0x0 ; + dd 0x0 ; + +include 'MACROS.INC' ; + +SB_PM2_INDEX equ 0xCD0 +SB_PM2_DATA equ 0xCD1 +BOX_COLOR equ 0xD0C8C0 + +START: + + + + + +red: + + call draw_window + +still: + mcall 10 ; event waiting + + cmp eax,1 ; redraw window + je red ; + cmp eax,2 ; key pressed? + je key ; + cmp eax,3 ; button hit? + je button ; + + jmp still ; none of that + +;--------------------------------------------------------------------- + + key: ; key pressed + jmp red + +;--------------------------------------------------------------------- + + button: + mcall 17 ; get the button ID + cmp ah, 1 + jne .bt2 + mcall -1 +.bt2: + cmp ah, 2 + jne .bt3 + dec [Reg] ; Rg# decrement + jmp red +.bt3: + cmp ah, 3 + jne .bt4 + inc [Reg] ; Rg# increment + jmp red +.bt4: + cmp ah, 4 + jne .bt5 + add [Reg],16 ; PgDn + jmp red +.bt5: + cmp ah, 5 + jne .bt6 + mov edx, [Reg] + cmp edx, 16 + jb @f + sub edx, 16 + mov [Reg],edx ; PgUp + jmp red +@@: + xor edx, edx + mov [Reg], edx + jmp red + +.bt6: + cmp ah, 6 + jne still + mcall 37, 1 ; get the mouse pointer + shr eax, 16 ; only X needed + sub eax, 124 ; check the left border + jb red + xor edx, edx + mov ebx, 12 + div ebx + cmp eax, 32 ; check the right border + jnb red + mov ecx, 31 + sub ecx, eax ; reverse the bit order + mov ebx, [Rct] + btc ebx, ecx ; invert the bit + mov eax, [Reg] + mov [Rct], ebx + call write_sb_pm2_reg + + jmp red + + +;------------------------------------------------ +print_config_reg: +;------------------------------------------------ + mov eax, [Reg] +; and eax, 0x0FF + mov ebx, 3*65536+256 ; 3 hex digits + mov ecx, eax + mov dx,[stX] + shl edx,16 ; = X*65536 + mov dx,[stY] ; = edx + Y + mov esi,0 + mcall 47 ; print reg# + mov ecx, edx + call read_sb_pm2_reg + mov edx, ecx + mov ecx, eax + add edx, 36*65536 ; right column + mov ebx, 8*65536+256 ; 8 hex digits + mcall 47 ; print config data + ret + +;------------------------------------------------ +read_sb_pm2_reg: +; in: [Reg] = reg# | out: eax = [Rct] = data +;------------------------------------------------ + mov dx, SB_PM2_INDEX + xor eax, eax + mov al, byte [Reg] + out dx, al + inc dl + in al, dx + mov [Rct], eax + ret + +;------------------------------------------------ +write_sb_pm2_reg: +; in: [Reg] = reg#; [Rct] = data +;------------------------------------------------ + mov dx, SB_PM2_INDEX + xor eax, eax + mov al, byte [Reg] + out dx, al + inc dl + mov eax, [Rct] + out dx, al + ret + + +;------------------------------------------------ + draw_window: +;------------------------------------------------ + + + mcall 12, 1 + mcall 0, 600*65536+530, 410*65536+290, 0x14848090,,title +; ----------------------------------------------------------------- +; BUTTONS: Xleft Xwid, Ytop Yheig + mcall 8, 370*65536+ 40, 26*65536+ 18, 2, 0x94A0B0 ; << + mcall , , 51*65536+ 18, 3, ; >> + mcall , 425*65536+ 90, 26*65536+ 18, 4, ; Next Page + mcall , , 51*65536+ 18, 5, ; Prev Page + mcall , 117*65536+400, 97*65536+ 40, 6, ; Bits + + call read_sb_pm2_reg + + mov ebx, bitstr2 + inc ebx + mov edx, [Rct] + mov ecx, 0x80000000 + xor eax, eax +.stringtest: + test edx, ecx + jz @f + mov byte [ebx+eax*2],'I' ; bit dump + jmp .nextbit +@@: + mov byte [ebx+eax*2],'0' +.nextbit: + inc eax + shr ecx, 1 + jnz .stringtest + +; button txt: X *65536+ Y + mcall 4, 378*65536+32 ,0x10000000, butstr2,3 + mcall , 378*65536+57 , , butstr3, + mcall , 436*65536+32 , , butstr4,9 + mcall , 436*65536+57 , , butstr5, + + mcall 4, 122*65536+101,0 , bitstr0,65 + mcall , 122*65536+110,0 , bitstr1,65 + mcall , 122*65536+117,0 , bitstr2,65 + mcall , 122*65536+126,0 , bitstr3,65 +; ----------------------------------------------------------------- +; draw the reg-value box + mov ebx, 10*65536+100 ; Xleft | Xwidth + mov ecx, 26*65536+250 ; Ytop | Yheight + mov edx, BOX_COLOR + mcall 13 +; draw the reg-address box + mov ebx, 206*65536+146 ; Xleft | Xwidth + mov cx, 44 ; Yheight only + mcall 13 + +; fill the data box + mov bx, 40 ; upper position + mov [stY],bx + mov eax, [Reg] + mov [reg], eax ; store original# +.print_reg_names: + call print_config_reg + add [stY],14 + inc [Reg] + mov edx,[reg] + mov eax, 16 + add eax, edx + cmp eax,[Reg] + ja .print_reg_names + mov [Reg], edx ; restore original# + +; fill the status box + mcall 4, 210*65536+30,0,str1,12 + mcall , 210*65536+44, ,str2, + mcall , 210*65536+56, ,str3, + call read_sb_pm2_reg + mov ecx, SB_PM2_DATA + mov edx, 300*65536+30 + mov ebx, 8*65536+256 + mcall 47 + add dx, 14 + mov ecx,[Reg] + mov esi, 0 + mcall 47 + add dx,14 + mov ecx, [Rct] + mcall 47 + +; print extra info + mov ebx, 120*65536+170 + xor ecx, ecx + mov edx, info1 +@@: + mcall 4,,,,66 + add edx, 66 + add ebx, 14 + cmp edx, info_end + jb @b + + + mcall 12, 2 ; дг­ЄжЁп 12: б®®ЎйЁвм Ћ‘ ®Ў ®ваЁб®ўЄҐ ®Є­  + +ret + + +align 4 +;------------------------------------------------- + + pix dd 0x55AACC33 + pxX dd 200 + pxY dd 160 + stX dw 18 + stY dw 0 + reg dd 0 + + Rct dd 0 ; reg content + Reg dd 0x00 ; reg number + + + title db ' SB710 PowerManagement (Block2) registers - PM2_Reg',0 +;------------------------------------------------------------------------------------ + reg_str db 'Reg#| hex.Value ' +;------------------------------------------------------------------------------------ +str1 db 'bdf address:' +str2 db 'Reg. number:' +str3 db 'Reg.content:' + + butstr2 db ' << ' + butstr3 db ' >> ' + butstr4 db 'Next Page' + butstr5 db 'Prev Page' + +bitstr0 db '31',209,205,209,205,209,205,209,205,209,205,209,205,'24',\ + 209,205,209,205,209,205,209,205,209,205,209,205,209,205,'16',\ + 209,'15',205,209,205,209,205,209,205,209,205,209,205,209,'8',\ + 205,'7',209,205,209,205,209,205,209,205,209,205,209,205,209,'0',184 +bitstr1 db 179,' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ',179 +bitstr2 db 179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179,'9 8 7 6',\ + 179,'5 4 3 2',179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179 +bitstr3 db 212,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,190 + +info1 db '------------- PM2 REG ------------' + db '| see AMD SB700/710/750 Register Reference Guide, pp.228-258 |' +info2 db '| reg |' + db '| reg |' + db '| reg |' + db '| reg |' + db '| reg F6: Gpm3-0pull; F7: Gpm7-4pull; F8: Gpm9-8pull |' + db '------------------------------------------------------------------' +info_end: + +I_END: ; end of program + + rd 256 + +align 256 +st_0: diff --git a/kernel/branches/Kolibri-A/utilities/SB700/SB_PM_RG.ASM b/kernel/branches/Kolibri-A/utilities/SB700/SB_PM_RG.ASM new file mode 100644 index 0000000000..0d6ee6a560 --- /dev/null +++ b/kernel/branches/Kolibri-A/utilities/SB700/SB_PM_RG.ASM @@ -0,0 +1,314 @@ +$Revision: 1598 $ + + use32 ; + org 0x0 ; + + db 'MENUET01' ; + dd 0x01 ; + dd START ; + dd I_END ; + dd 0x1000 ; + dd 0x1000 ; + dd 0x0 ; + dd 0x0 ; + +include 'MACROS.INC' ; + +SB_PM_INDEX equ 0xCD6 +SB_PM_DATA equ 0xCD7 +BOX_COLOR equ 0xD0C8C0 + +START: + + + + + +red: + + call draw_window + +still: + mcall 10 ; event waiting + + cmp eax,1 ; redraw window + je red ; + cmp eax,2 ; key pressed? + je key ; + cmp eax,3 ; button hit? + je button ; + + jmp still ; none of that + +;--------------------------------------------------------------------- + + key: ; key pressed + jmp red + +;--------------------------------------------------------------------- + + button: + mcall 17 ; get the button ID + cmp ah, 1 + jne .bt2 + mcall -1 +.bt2: + cmp ah, 2 + jne .bt3 + dec [Reg] ; Rg# decrement + jmp red +.bt3: + cmp ah, 3 + jne .bt4 + inc [Reg] ; Rg# increment + jmp red +.bt4: + cmp ah, 4 + jne .bt5 + add [Reg],16 ; PgDn + jmp red +.bt5: + cmp ah, 5 + jne .bt6 + mov edx, [Reg] + cmp edx, 16 + jb @f + sub edx, 16 + mov [Reg],edx ; PgUp + jmp red +@@: + xor edx, edx + mov [Reg], edx + jmp red + +.bt6: + cmp ah, 6 + jne still + mcall 37, 1 ; get the mouse pointer + shr eax, 16 ; only X needed + sub eax, 124 ; check the left border + jb red + xor edx, edx + mov ebx, 12 + div ebx + cmp eax, 32 ; check the right border + jnb red + mov ecx, 31 + sub ecx, eax ; reverse the bit order + mov ebx, [Rct] + btc ebx, ecx ; invert the bit + mov eax, [Reg] + mov [Rct], ebx + call write_sb_pm_reg + + jmp red + + +;------------------------------------------------ +print_config_reg: +;------------------------------------------------ + mov eax, [Reg] +; and eax, 0x0FF + mov ebx, 3*65536+256 ; 3 hex digits + mov ecx, eax + mov dx,[stX] + shl edx,16 ; = X*65536 + mov dx,[stY] ; = edx + Y + mov esi,0 + mcall 47 ; print reg# + mov ecx, edx + call read_sb_pm_reg + mov edx, ecx + mov ecx, eax + add edx, 36*65536 ; right column + mov ebx, 8*65536+256 ; 8 hex digits + mcall 47 ; print config data + ret + +;------------------------------------------------ +read_sb_pm_reg: +; in: [Reg] = reg# | out: eax = [Rct] = data +;------------------------------------------------ + mov dx, SB_PM_INDEX + xor eax, eax + mov al, byte [Reg] + out dx, al + inc dl + in al, dx + mov [Rct], eax + ret + +;------------------------------------------------ +write_sb_pm_reg: +; in: [Reg] = reg#; [Rct] = data +;------------------------------------------------ + mov dx, SB_PM_INDEX + xor eax, eax + mov al, byte [Reg] + out dx, al + inc dl + mov eax, [Rct] + out dx, al + ret + + +;------------------------------------------------ + draw_window: +;------------------------------------------------ + + + mcall 12, 1 + mcall 0, 600*65536+530, 410*65536+290, 0x14748090,,title +; ----------------------------------------------------------------- +; BUTTONS: Xleft Xwid, Ytop Yheig + mcall 8, 370*65536+ 40, 26*65536+ 18, 2, 0x94A0B0 ; << + mcall , , 51*65536+ 18, 3, ; >> + mcall , 425*65536+ 90, 26*65536+ 18, 4, ; Next Page + mcall , , 51*65536+ 18, 5, ; Prev Page + mcall , 117*65536+400, 97*65536+ 40, 6, ; Bits + + call read_sb_pm_reg + + mov ebx, bitstr2 + inc ebx + mov edx, [Rct] + mov ecx, 0x80000000 + xor eax, eax +.stringtest: + test edx, ecx + jz @f + mov byte [ebx+eax*2],'I' ; bit dump + jmp .nextbit +@@: + mov byte [ebx+eax*2],'0' +.nextbit: + inc eax + shr ecx, 1 + jnz .stringtest + +; button txt: X *65536+ Y + mcall 4, 378*65536+32 ,0x10000000, butstr2,3 + mcall , 378*65536+57 , , butstr3, + mcall , 436*65536+32 , , butstr4,9 + mcall , 436*65536+57 , , butstr5, + + mcall 4, 122*65536+101,0 , bitstr0,65 + mcall , 122*65536+110,0 , bitstr1,65 + mcall , 122*65536+117,0 , bitstr2,65 + mcall , 122*65536+126,0 , bitstr3,65 +; ----------------------------------------------------------------- +; draw the reg-value box + mov ebx, 10*65536+100 ; Xleft | Xwidth + mov ecx, 26*65536+250 ; Ytop | Yheight + mov edx, BOX_COLOR + mcall 13 +; draw the reg-address box + mov ebx, 206*65536+146 ; Xleft | Xwidth + mov cx, 44 ; Yheight only + mcall 13 + +; fill the data box + mov bx, 40 ; upper position + mov [stY],bx + mov eax, [Reg] + mov [reg], eax ; store original# +.print_reg_names: + call print_config_reg + add [stY],14 + inc [Reg] + mov edx,[reg] + mov eax, 16 + add eax, edx + cmp eax,[Reg] + ja .print_reg_names + mov [Reg], edx ; restore original# + +; fill the status box + mcall 4, 210*65536+30,0,str1,12 + mcall , 210*65536+44, ,str2, + mcall , 210*65536+56, ,str3, + call read_sb_pm_reg + mov ecx, SB_PM_DATA + mov edx, 300*65536+30 + mov ebx, 8*65536+256 + mcall 47 + add dx, 14 + mov ecx,[Reg] + mov esi, 0 + mcall 47 + add dx,14 + mov ecx, [Rct] + mcall 47 + +; print extra info + mov ebx, 120*65536+170 + xor ecx, ecx + mov edx, info1 +@@: + mcall 4,,,,66 + add edx, 66 + add ebx, 14 + cmp edx, info_end + jb @b + + + mcall 12, 2 ; дг­ЄжЁп 12: б®®ЎйЁвм Ћ‘ ®Ў ®ваЁб®ўЄҐ ®Є­  + +ret + + +align 4 +;------------------------------------------------- + + pix dd 0x55AACC33 + pxX dd 200 + pxY dd 160 + stX dw 18 + stY dw 0 + reg dd 0 + + Rct dd 0 ; reg content + Reg dd 0x00 ; reg number + + + title db ' SB710 PowerManagement registers - PM_Reg',0 +;------------------------------------------------------------------------------------ + reg_str db 'Reg#| hex.Value ' +;------------------------------------------------------------------------------------ +str1 db 'bdf address:' +str2 db 'Reg. number:' +str3 db 'Reg.content:' + + butstr2 db ' << ' + butstr3 db ' >> ' + butstr4 db 'Next Page' + butstr5 db 'Prev Page' + +bitstr0 db '31',209,205,209,205,209,205,209,205,209,205,209,205,'24',\ + 209,205,209,205,209,205,209,205,209,205,209,205,209,205,'16',\ + 209,'15',205,209,205,209,205,209,205,209,205,209,205,209,'8',\ + 205,'7',209,205,209,205,209,205,209,205,209,205,209,205,209,'0',184 +bitstr1 db 179,' | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ',179 +bitstr2 db 179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179,'9 8 7 6',\ + 179,'5 4 3 2',179,'1 0 9 8',179,'7 6 5 4',179,'3 2 1 0',179 +bitstr3 db 212,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,205,207,\ + 205,207,205,207,205,207,205,207,205,207,205,190 + +info1 db '------------- PM REG -------------' + db '| see AMD SB700/710/750 Register Reference Guide, pp.174-223 |' +info2 db '| |' + db '| reg |' + db '| reg |' + db '| reg |' + db '| reg |' + db '------------------------------------------------------------------' +info_end: + +I_END: ; end of program + + rd 256 + +align 256 +st_0: