From Ghost: calls to PCIBIOS services

git-svn-id: svn://kolibrios.org@586 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2007-07-23 17:50:42 +00:00
parent 93e2c279ba
commit a4f10b7565
8 changed files with 281 additions and 61 deletions

View File

@ -9,9 +9,11 @@ $Revision$
;; ;; ;; ;;
;; 32 bit PCI driver code ;; ;; 32 bit PCI driver code ;;
;; ;; ;; ;;
;; Version 0.3 April 9, 2007 ;;
;; Version 0.2 December 21st, 2002 ;; ;; Version 0.2 December 21st, 2002 ;;
;; ;; ;; ;;
;; Author: Victor Prodan, victorprodan@yahoo.com ;; ;; Author: Victor Prodan, victorprodan@yahoo.com ;;
;; Mihailov Ilia, ghost.nsk@gmail.com ;;
;; Credits: ;; ;; Credits: ;;
;; Ralf Brown ;; ;; Ralf Brown ;;
;; Mike Hibbett, mikeh@oceanfree.net ;; ;; Mike Hibbett, mikeh@oceanfree.net ;;
@ -108,6 +110,7 @@ pci_make_config_cmd:
; read a register from the PCI config space into EAX/AX/AL ; read a register from the PCI config space into EAX/AX/AL
; IN: ah=bus,device+func=bh,register address=bl ; IN: ah=bus,device+func=bh,register address=bl
; number of bytes to read (1,2,4) coded into AL, bits 0-1 ; number of bytes to read (1,2,4) coded into AL, bits 0-1
; (0 - byte, 1 - word, 2 - dword)
;*************************************************************************** ;***************************************************************************
align 4 align 4
@ -238,6 +241,7 @@ pci_read_reg_err:
; IN: ah=bus,device+func=bh,register address (dword aligned)=bl, ; IN: ah=bus,device+func=bh,register address (dword aligned)=bl,
; value to write in ecx ; value to write in ecx
; number of bytes to write (1,2,4) coded into AL, bits 0-1 ; number of bytes to write (1,2,4) coded into AL, bits 0-1
; (0 - byte, 1 - word, 2 - dword)
;*************************************************************************** ;***************************************************************************
align 4 align 4
@ -361,3 +365,118 @@ pci_write_reg_err:
xor eax,eax xor eax,eax
dec eax dec eax
ret ret
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; VendID (2), DevID (2), Revision = 0 (1), Class Code (3), FNum (1), Bus (1)
pci_emu_dat: times 30*10 db 0
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
align 4
sys_pcibios:
cmp [pci_access_enabled], 1
jne .unsupported_func
mov edi, [pci_bios_entry]
test edi, edi
jz .emulate_bios
xchg ebx, eax
xchg ecx, eax
xchg edx, eax
xchg esi, eax
mov edi, eax
push ds
mov ax, pci_data_sel
mov ds, ax
mov eax, ebp
call pword [cs:pci_bios_entry]
pop ds
jmp .return
;-=-=-=-=-=-=-=-=
.emulate_bios:
cmp ebp, 1 ; PCI_FUNCTION_ID
jnz .not_PCI_BIOS_PRESENT
mov edx, 'PCI '
xor ah, ah
mov al, [OS_BASE+0x2F0000 + 0x9020]
mov bx, [OS_BASE+0x2F0000 + 0x9022]
mov cl, [OS_BASE+0x2F0000 + 0x9021]
jmp .return
.not_PCI_BIOS_PRESENT:
cmp ebp, 2 ; FIND_PCI_DEVICE
jne .not_FIND_PCI_DEVICE
mov esi, pci_emu_dat
..nxt: cmp [esi], cx
jne ..no
cmp [esi + 2], bx
jne ..no
dec dx
jns ..no
mov bx, [esi + 4]
xor ah, ah
jmp .return
..no: cmp word[esi], 0
je ..dev_not_found
add esi, 10
jmp ..nxt
..dev_not_found:
mov ah, 0x86 ; DEVICE_NOT_FOUND
jmp .return
.not_FIND_PCI_DEVICE:
cmp ebp, 3 ; FIND_PCI_CLASS_CODE
jne .not_FIND_PCI_CLASS_CODE
mov esi, pci_emu_dat
shl ebx, 8
..nxt2: cmp [esi], ebx
jne ..no2
mov bx, [esi]
xor ah, ah
jmp .return
..no2: cmp dword[esi], 0
je ..dev_not_found2
add esi, 10
jmp ..nxt2
..dev_not_found2:
mov ah, 0x86 ; DEVICE_NOT_FOUND
jmp .return
.not_FIND_PCI_CLASS_CODE:
cmp ebp, 8 ; READ_CONFIG_*
jb .not_READ_CONFIG
cmp ebp, 0x0A
ja .not_READ_CONFIG
mov ebx, esi
mov bh, al
mov edx, ebp
mov al, dl
call pci_read_reg
mov ecx, eax
xor ah, ah ; SUCCESSFUL
jmp .return
.not_READ_CONFIG:
cmp ebp, 0x0B ; WRITE_CONFIG_*
jb .not_WRITE_CONFIG
cmp ebp, 0x0D
ja .not_WRITE_CONFIG
mov ecx, ebx
mov ebx, esi
mov bh, al
mov edx, ebp
inc edx
mov al, dl
call pci_write_reg
xor ah, ah ; SUCCESSFUL
jmp .return
.not_WRITE_CONFIG:
.unsupported_func:
mov ah, 0x81 ; FUNC_NOT_SUPPORTED
.return:mov dword[esp + 8 ], edi
mov dword[esp + 12], esi
mov dword[esp + 24], ebx
mov dword[esp + 28], edx
mov dword[esp + 32], ecx
mov dword[esp + 36], eax
ret

View File

@ -6,6 +6,7 @@ $Revision$
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
dpl0 equ 10010000b ; data read dpl0
drw0 equ 10010010b ; data read/write dpl0 drw0 equ 10010010b ; data read/write dpl0
drw3 equ 11110010b ; data read/write dpl3 drw3 equ 11110010b ; data read/write dpl3
cpl0 equ 10011010b ; code read dpl0 cpl0 equ 10011010b ; code read dpl0

View File

@ -196,7 +196,7 @@ iglobal
dd user_events ; 54-User events dd user_events ; 54-User events
dd sound_interface ; 55-Sound interface dd sound_interface ; 55-Sound interface
dd undefined_syscall ; 56-reserved dd undefined_syscall ; 56-reserved
dd undefined_syscall ; 57-reserved dd sys_pcibios ; 57-reserved
dd file_system ; 58-Common file system interface dd file_system ; 58-Common file system interface
dd undefined_syscall ; 59-reserved dd undefined_syscall ; 59-reserved
dd sys_IPC ; 60-Inter Process Communication dd sys_IPC ; 60-Inter Process Communication

View File

@ -4,7 +4,7 @@ $Revision$
flm db 0 flm db 0
preboot_lfb db 0 preboot_lfb db 0
preboot_bootlog db 0 preboot_bootlog db 0
boot_drive db 0
bx_from_load: dw 'r1' ; структура для хранения параметров- откуда гашрузились, берется ниже из bx ; {SPraid}[13.03.2007] bx_from_load: dw 'r1' ; структура для хранения параметров- откуда гашрузились, берется ниже из bx ; {SPraid}[13.03.2007]
; a,b,c,d - винчестеры, r - рам диск ; a,b,c,d - винчестеры, r - рам диск
; # диска... символ, а не байт. '1', а не 1 ; # диска... символ, а не байт. '1', а не 1

View File

@ -117,6 +117,8 @@ syslang dd 1
boot_y dd 10 boot_y dd 10
pci_bios_entry dd 0
dw pci_code_sel
if __DEBUG__ eq 1 if __DEBUG__ eq 1
include_debug_strings include_debug_strings
@ -164,6 +166,24 @@ app_data_l:
db drw3 db drw3
dw G32+D32+(new_app_base shr 16)+0xF; dw G32+D32+(new_app_base shr 16)+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
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
; --------------- APM --------------------- ; --------------- APM ---------------------
apm_code_32: apm_code_32:
dw 0x0f ; limit 64kb dw 0x0f ; limit 64kb

View File

@ -2916,6 +2916,18 @@ dword-
* „ ­­ë¥ ¤®«¦­ë á®åà ­ïâìáï ¢ ¯ ¬ï⨠¯® ªà ©­¥© ¬¥à¥ * „ ­­ë¥ ¤®«¦­ë á®åà ­ïâìáï ¢ ¯ ¬ï⨠¯® ªà ©­¥© ¬¥à¥
¤® ª®­æ  ¯à®¨£à뢠­¨ï. ¤® ª®­æ  ¯à®¨£à뢠­¨ï.
======================================================================
============================ ”ã­ªæ¨ï 57 ==============================
====================== ‚맮¢ á¥à¢¨á®¢ PCIBIOS ========================
======================================================================
<EFBFBD> à ¬¥âàë:
* eax = 57
* ebp = ᮮ⢥âáâ¢ã¥â ॣ¨áâàã al ¯® ᯥæ¨ä¨ª æ¨¨ PCIBIOS
* ®áâ «ì­ë¥ ॣ¨áâàë ¯® ᯥæ¨ä¨ª æ¨¨ PCIBIOS
‚®§¢à é ¥¬ë¥ §­ ç¥­¨ï:
* CF ­¥ ®¯à¥¤¥«ñ­
* ®áâ «ì­ë¥ ॣ¨áâàë ¯® ᯥæ¨ä¨ª æ¨¨ PCIBIOS
====================================================================== ======================================================================
============== ”ã­ªæ¨ï 58 - à ¡®â  á ä ©«®¢®© á¨á⥬®©. ============== ============== ”ã­ªæ¨ï 58 - à ¡®â  á ä ©«®¢®© á¨á⥬®©. ==============
====================================================================== ======================================================================

View File

@ -159,6 +159,69 @@ proc init_page_map
ret ret
endp endp
align 4
init_BIOS32:
mov edi, 0xE0000
.pcibios_nxt:
cmp dword[edi], '_32_' ; "magic" word
je .BIOS32_found
.pcibios_nxt2:
add edi, 0x10
cmp edi, 0xFFFF0
je .BIOS32_not_found
jmp .pcibios_nxt
.BIOS32_found: ; magic word found, check control summ
movzx ecx, byte[edi + 9]
shl ecx, 4
mov esi, edi
xor eax, eax
cld ; paranoia
@@: lodsb
add ah, al
loop @b
jnz .pcibios_nxt2 ; control summ must be zero
; BIOS32 service found !
mov ebp, [edi + 4]
mov [bios32_entry], ebp
; check PCI BIOS present
mov eax, '$PCI'
xor ebx, ebx
push cs ; special for 'ret far' from BIOS
call ebp
test al, al
jnz .PCI_BIOS32_not_found
; çäåñü ñîçäàþòñÿ äèñêðèïòîðû äëÿ PCI BIOS
add ebx, OS_BASE
dec ecx
mov [(pci_code_32-OS_BASE)], cx ;limit 0-15
mov [(pci_data_32-OS_BASE)], cx ;limit 0-15
mov [(pci_code_32-OS_BASE)+2], bx ;base 0-15
mov [(pci_data_32-OS_BASE)+2], bx ;base 0-15
shr ebx, 16
mov [(pci_code_32-OS_BASE)+4], bl ;base 16-23
mov [(pci_data_32-OS_BASE)+4], bl ;base 16-23
shr ecx, 16
and cl, 0x0F
mov ch, bh
add cx, D32
mov [(pci_code_32-OS_BASE)+6], cx ;lim 16-19 &
mov [(pci_data_32-OS_BASE)+6], cx ;base 24-31
mov [(pci_bios_entry-OS_BASE)], edx
; jmp .end
.PCI_BIOS32_not_found:
; çäåñü äîëæíà çàïîëíÿòñÿ pci_emu_dat
.BIOS32_not_found:
.end:
align 4 align 4
proc test_cpu proc test_cpu
locals locals

View File

@ -74,6 +74,8 @@ graph_data equ (3+graph_data_l-gdts)
tss0 equ (tss0_l-gdts) tss0 equ (tss0_l-gdts)
app_code equ (3+app_code_l-gdts) app_code equ (3+app_code_l-gdts)
app_data equ (3+app_data_l-gdts) app_data equ (3+app_data_l-gdts)
pci_code_sel equ (pci_code_32-gdts)
pci_data_sel equ (pci_data_32-gdts)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -237,6 +239,7 @@ B32:
call test_cpu call test_cpu
bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc bts [cpu_caps-OS_BASE], CAPS_TSC ;force use rdtsc
call init_BIOS32
; MEMORY MODEL ; MEMORY MODEL
call mem_test call mem_test
call init_mem call init_mem
@ -255,7 +258,9 @@ B32:
jmp pword os_code:high_code jmp pword os_code:high_code
align 4 align 4
bios32_entry dd ?
tmp_page_tabs dd ? tmp_page_tabs dd ?
use16 use16
org $-0x10000 org $-0x10000
include "boot/shutdown.inc" ; shutdown or restart include "boot/shutdown.inc" ; shutdown or restart