;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; RDOS operating system ; Copyright (C) 1988-2011, Leif Ekblad ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. The only exception to this rule ; is for commercial usage in embedded systems. For information on ; usage in commercial embedded systems, contact embedded@rdos.net ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ; ; The author of this program may be contacted at leif@rdos.net ; ; i2xx.ASM ; Intel i2xx driver ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; INCLUDE ..\os\system.def INCLUDE ..\driver.def INCLUDE ..\os.def INCLUDE ..\os.inc INCLUDE ..\user.def INCLUDE ..\user.inc INCLUDE ..\pcdev\pci.inc INCLUDE ..\os\core.inc INCLUDE ..\os\net.inc IFDEF __WASM__ .686p .xmm2 ELSE .386p ENDIF rx_descr STRUC rx_phys DD ?,? rx_len DW ? rx_checksum DW ? rx_status DB ? rx_errors DB ? rx_tag DW ? rx_descr ENDS tx_descr STRUC tx_phys DD ?,? tx_len DW ? tx_cso DB ? tx_cmd DB ? tx_sta DB ? tx_resv DB ? tx_tag DW ? tx_descr ENDS CTRL_SC = 1 SHL 26 RCTL_RXEN = 1 SHL 1 RXDCTL_EN = 1 SHL 25 TCTL_TXEN = 1 SHL 1 TXDCTL_EN = 1 SHL 25 REG_CTRL = 0 REG_STATUS = 8 REG_RCTL = 100h REG_TCTL = 400h REG_ICR = 1500h REG_ICS = 1504h REG_IMS = 1508h REG_IMC = 150Ch REG_GPIE = 1514h REG_RA = 5400h REG_RDBA = 0C000h REG_RDLEN = 0C008h REG_RDH = 0C010h REG_RDT = 0C018h REG_RXDCTL = 0C028h REG_TDBA = 0E000h REG_TDLEN = 0E008h REG_TDH = 0E010h REG_TDT = 0E018h REG_TXDCTL = 0E028h data STRUC FuncSel DW ? RxRingSel DW ? RxRingPhys DD ?,? TxRingPhys DD ?,? TxRingSel DW ? TxTail DW ? Handle DW ? SuperThread DW ? PendInt DD ? Mac DB 6 DUP(?) data ENDS code SEGMENT byte public 'CODE' assume cs:code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: NetInt ; ; DESCRIPTION: Network card interrupt ; ; PARAMETERS: DS Ether sel ; ; RETURNS: ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NetInt Proc far mov es,ds:FuncSel mov eax,es:REG_ICR lock or ds:PendInt,eax ; mov bx,ds:SuperThread Signal ret NetInt Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: CreateFuncSel ; ; DESCRIPTION: Create function selector ; ; PARAMETERS: EBX:EAX Physical address of BAR0 ; ; RETURNS: ES Function sel ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CreateFuncSel Proc near push eax push ebx push ecx ; push eax mov eax,10000h AllocateBigLinear pop eax ; push eax push edx ; and ax,0F000h or ax,813h mov ecx,10h cfsLoop: SetPageEntry ; add edx,1000h add eax,1000h loop cfsLoop ; pop edx pop eax ; and ax,0FFFh or dx,ax ; AllocateGdt mov ecx,10000h CreateDataSelector32 mov es,bx ; pop ecx pop ebx pop eax ret CreateFuncSel Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: SetupInts ; ; DESCRIPTION: Setup PCI or MSI IRQ ; ; PARAMETERS: BH Bus ; BL Device ; CH Function ; DS Ether sel ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SetupInts Proc near pushad ; GetPciMsi jc siIrq siMsi: push cx mov cx,1 mov al,14h AllocateInts pop cx jc siIrq ; mov dl,1 SetupPciMsi ; mov di,cs mov es,di mov edi,OFFSET NetInt RequestMsiHandler jmp siDone siIrq: GetPciIrqNr mov ah,14h mov bx,cs mov es,bx mov edi,OFFSET NetInt RequestIrqHandler siDone: popad ret SetupInts Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: CreateRxRing ; ; DESCRIPTION: Create RX ring ; ; PARAMETERS: DS Ether sel ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CreateRxRing Proc near push es pushad ; mov ax,flat_sel mov es,ax mov eax,1000h AllocateBigLinear AllocatePhysical64 mov ds:RxRingPhys,eax mov ds:RxRingPhys+4,ebx or al,13h SetPageEntry ; AllocateGdt mov ecx,1000h CreateDataSelector16 mov ds:RxRingSel,bx ; mov es,bx mov ecx,100h xor edi,edi crLoop: mov es:[edi].rx_len,1000h mov es:[edi].rx_checksum,0 mov es:[edi].rx_status,0 mov es:[edi].rx_errors,0 mov es:[edi].rx_tag,0 ; AllocatePhysical64 mov es:[edi].rx_phys,eax mov es:[edi].rx_phys+4,ebx ; add edi,16 loop crLoop ; popad pop es ret CreateRxRing Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: CreateTxRing ; ; DESCRIPTION: Create TX ring ; ; PARAMETERS: DS Ether sel ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CreateTxRing Proc near push es pushad ; mov ax,flat_sel mov es,ax mov eax,1000h AllocateBigLinear AllocatePhysical64 mov ds:TxRingPhys,eax mov ds:TxRingPhys+4,ebx or al,13h SetPageEntry ; AllocateGdt mov ecx,1000h CreateDataSelector16 mov ds:TxRingSel,bx mov ds:TxTail,0 ; mov es,bx mov ecx,100h xor edi,edi ctLoop: mov es:[edi].tx_phys,0 mov es:[edi].tx_phys+4,0 mov es:[edi].tx_len,0 mov es:[edi].tx_cso,0 mov es:[edi].tx_cmd,0Bh mov es:[edi].tx_sta,0 mov es:[edi].tx_resv,0 mov es:[edi].tx_tag,0 ; add edi,16 loop ctLoop ; popad pop es ret CreateTxRing Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: InitRx ; ; DESCRIPTION: Init RX ; ; PARAMETERS: DS Ether sel ; ES Function sel ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; InitRx Proc near call CreateRxRing ; mov eax,es:REG_RCTL and eax,NOT RCTL_RXEN mov es:REG_RCTL,eax ; mov eax,ds:RxRingPhys mov es:REG_RDBA,eax mov eax,ds:RxRingPhys+4 mov es:REG_RDBA+4,eax ; mov dword ptr es:REG_RDLEN,1000h ; mov eax,es:REG_RXDCTL or eax,RXDCTL_EN mov es:REG_RXDCTL,eax ; mov ecx,100000h irWaitEn: pause mov eax,es:REG_RXDCTL test eax,RXDCTL_EN jnz irDoneEn loop irWaitEn irDoneEn: mov eax,0FF0h mov es:REG_RDT,eax ; mov eax,es:REG_RCTL or eax,RCTL_RXEN mov es:REG_RCTL,eax ret InitRx Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: InitTx ; ; DESCRIPTION: Init TX ; ; PARAMETERS: DS Ether sel ; ES Function sel ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; InitTx Proc near call CreateTxRing ; mov eax,es:REG_TCTL and eax,NOT TCTL_TXEN mov es:REG_TCTL,eax ; mov eax,ds:TxRingPhys mov es:REG_TDBA,eax mov eax,ds:TxRingPhys+4 mov es:REG_TDBA+4,eax ; mov dword ptr es:REG_TDLEN,1000h ; mov eax,es:REG_TXDCTL or eax,TXDCTL_EN mov es:REG_TXDCTL,eax ; mov ecx,100000h itWaitEn: pause mov eax,es:REG_TXDCTL test eax,TXDCTL_EN jnz itDoneEn loop itWaitEn itDoneEn: mov eax,es:REG_TCTL or eax,TCTL_TXEN mov es:REG_TCTL,eax ret InitTx Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: InitFunc ; ; DESCRIPTION: Init function ; ; PARAMETERS: DS Ether sel ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; InitFunc Proc near push es pushad ; mov ds:PendInt,0 ; mov es,ds:FuncSel mov eax,es:REG_CTRL or eax,CTRL_SC mov es:REG_CTRL,eax ; mov ecx,100000h ifWaitReset: pause mov eax,es:REG_CTRL test eax,CTRL_SC jz ifDoneReset loop ifWaitReset ifDoneReset: call InitRx call InitTx ; mov eax,es:REG_RA mov dword ptr ds:Mac,eax mov ax,es:REG_RA+4 mov word ptr ds:Mac+4,ax ; mov eax,014004D5h mov es:REG_IMS,eax ; popad pop es ret InitFunc Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: mem_supervisor_thread ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mem_super_thread: mov ds,bx GetThread mov ds:SuperThread,ax mstLoop: WaitForSignal int 3 xor eax,eax xchg eax,ds:PendInt jmp mstLoop ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: MemPreview ; ; DESCRIPTION: Return size of block or no more data ; ; RETURNS: NC Data available ; ECX Size of data (0) ; DX Packet type ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MemPreview1 Proc far stc ret MemPreview1 Endp MemPreview2 Proc far stc ret MemPreview2 Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: Receive ; ; DESCRIPTION: Receive data ; ; PARAMETERS: ECX size of data ; ; RETURNS: ES:EDI data buffer ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Receive1 Proc far int 3 ret Receive1 Endp Receive2 Proc far int 3 ret Receive2 Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: Remove ; ; DESCRIPTION: Remove data from buffer ring ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Remove1 Proc far int 3 ret Remove1 Endp Remove2 Proc far int 3 ret Remove2 Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: GetBuffer ; ; DESCRIPTION: Get buffer ; ; PARAMETERS: ECX size ; ; RETURNS: ES:EDI data buffer ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GetBuffer Proc far push eax push ebx push edx ; push ecx mov eax,1000h AllocateBigLinear pop ecx ; add ecx,14 AllocateGdt CreateDataSelector32 ; mov es,ebx mov edi,14 sub ecx,14 ; pop edx pop ebx pop eax ret GetBuffer Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: MemSend ; ; DESCRIPTION: Send data ; ; PARAMETERS: ECX size ; DX packet type ; DS:ESI dest address ; ES:EDI data buffer ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MemSend1 Proc far int 3 push ds push fs pushad ; xor edi,edi mov ax,ds:[esi] stos word ptr es:[edi] mov ax,[esi+2] stos word ptr es:[edi] mov ax,[esi+4] stos word ptr es:[edi] ; mov eax,ether_data_sel mov ds,eax ; mov ax,word ptr ds:Mac stos word ptr es:[edi] mov ax,word ptr ds:Mac+2 stos word ptr es:[edi] mov ax,word ptr ds:Mac+4 stos word ptr es:[edi] ; mov ax,dx xchg al,ah mov es:[edi],ax ; add ecx,14 xor edi,edi NotifyEthernetPacket ; mov ebx,es GetSelectorBaseSize test dx,0FFFh jz ms1SelOk ; int 3 ms1SelOk: GetPageEntry and ax,0F000h ; push eax push ebx ; xor eax,eax xor ebx,ebx SetPageEntry ; pop ebx pop eax FreeMem ; cmp ecx,60 jae ms1PadOk ; mov ecx,60 ms1PadOk: mov es,ds:FuncSel mov fs,ds:TxRingSel movzx esi,ds:TxTail shl esi,4 mov fs:[esi].tx_phys,eax mov fs:[esi].tx_phys+4,ebx mov fs:[esi].tx_len,cx mov fs:[esi].tx_cso,0 mov fs:[esi].tx_cmd,0Bh mov fs:[esi].tx_sta,0 mov fs:[esi].tx_resv,0 mov fs:[esi].tx_tag,0 ; movzx esi,ds:TxTail inc esi mov ds:TxTail,si mov es:REG_TDT,esi ; xor eax,eax mov es,eax ; popad pop fs pop ds ret MemSend1 Endp MemSend2 Proc far push ds push fs pushad ; xor edi,edi mov ax,ds:[esi] stos word ptr es:[edi] mov ax,[esi+2] stos word ptr es:[edi] mov ax,[esi+4] stos word ptr es:[edi] ; mov eax,ether_data2_sel mov ds,eax ; mov ax,word ptr ds:Mac stos word ptr es:[edi] mov ax,word ptr ds:Mac+2 stos word ptr es:[edi] mov ax,word ptr ds:Mac+4 stos word ptr es:[edi] ; mov ax,dx xchg al,ah mov es:[edi],ax ; add ecx,14 xor edi,edi NotifyEthernetPacket ; mov ebx,es GetSelectorBaseSize test dx,0FFFh jz ms2SelOk ; int 3 ms2SelOk: GetPageEntry and ax,0F000h ; push eax push ebx ; xor eax,eax xor ebx,ebx SetPageEntry ; pop ebx pop eax FreeMem ; cmp ecx,60 jae ms2PadOk ; mov ecx,60 ms2PadOk: mov es,ds:FuncSel mov fs,ds:TxRingSel movzx esi,ds:TxTail shl esi,4 mov fs:[esi].tx_phys,eax mov fs:[esi].tx_phys+4,ebx mov fs:[esi].tx_len,cx mov fs:[esi].tx_cso,0 mov fs:[esi].tx_cmd,0Bh mov fs:[esi].tx_sta,0 mov fs:[esi].tx_resv,0 mov fs:[esi].tx_tag,0 ; movzx esi,ds:TxTail inc esi mov ds:TxTail,si mov es:REG_TDT,esi ; xor eax,eax mov es,eax ; popad pop fs pop ds ret MemSend2 Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: GetAddress ; ; DESCRIPTION: Get adapter address ; ; RETURNS: DS:ESI address ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GetAddress1 Proc far mov esi,ether_data_sel mov ds,esi mov esi,OFFSET Mac ret GetAddress1 Endp GetAddress2 Proc far mov esi,ether_data2_sel mov ds,esi mov esi,OFFSET Mac ret GetAddress2 Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: GetPktAddress ; ; DESCRIPTION: Get packet addresses ; ; PARAMETERS: ES Data buffer selector ; ; RETURNS: ES:ESI Source address ; ES:EDI Dest address ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GetPktAddress Proc far int 3 ret GetPktAddress Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: MemGetLinkState ; ; DESCRIPTION: Get link state ; ; RETURNS: NC Link up ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MemGetLinkState1 Proc far push ds push eax ; mov eax,ether_data_sel mov ds,eax mov ds,ds:FuncSel mov eax,ds:REG_STATUS test al,2 clc jnz mgls1Ok ; stc mgls1Ok: pop eax pop ds ret MemGetLinkState1 Endp MemGetLinkState2 Proc far push ds push eax ; mov eax,ether_data2_sel mov ds,eax mov ds,ds:FuncSel mov eax,ds:REG_STATUS test al,2 clc jnz mgls2Ok ; stc mgls2Ok: pop eax pop ds ret MemGetLinkState2 Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: GetMac ; ; DESCRIPTION: Get Mac address ; ; RETURNS: ES:EDI Mac ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GetMac1 Proc far mov edi,ether_data_sel mov es,edi mov edi,OFFSET Mac ret GetMac1 Endp GetMac2 Proc far mov edi,ether_data2_sel mov es,edi mov edi,OFFSET Mac ret GetMac2 Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: InitPciAdapter ; ; DESCRIPTION: Init PCI adapter if found ; ; PARAMETERS: AX Device number ; ; RETURNS: NC Adapter found ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DriverName1 DB 'Net i2xx-1',0 DriverName2 DB 'Net i2xx-2',0 SupervisorName1 DB 'Super i2xx-1',0 SupervisorName2 DB 'Super i2xx-2',0 MemDispTable1: DD OFFSET MemPreview1, SEG code DD OFFSET Receive1, SEG code DD OFFSET Remove1, SEG code DD OFFSET GetBuffer, SEG code DD OFFSET MemSend1, SEG code DD OFFSET GetAddress1, SEG code DD OFFSET GetPktAddress, SEG code DD OFFSET MemGetLinkState1, SEG code DD OFFSET GetMac1, SEG code MemDispTable2: DD OFFSET MemPreview2, SEG code DD OFFSET Receive2, SEG code DD OFFSET Remove2, SEG code DD OFFSET GetBuffer, SEG code DD OFFSET MemSend2, SEG code DD OFFSET GetAddress2, SEG code DD OFFSET GetPktAddress, SEG code DD OFFSET MemGetLinkState2, SEG code DD OFFSET GetMac2, SEG code PciVendorTab: pci00 DW 8086h, 1539h, 0 pci07 DW 0, 0 DevName1 DB 'i2xx-1', 0 DevName2 DB 'i2xx-2', 0 InitPrimaryPciAdapter Proc near mov ax,cs mov es,ax xor ax,ax mov bp,ax mov ax,ether_data_sel mov ds,ax mov si,OFFSET PciVendorTab init_pci1_loop: mov ax,bp mov dx,cs:[si] mov cx,cs:[si+2] or dx,dx stc jz init_pci1_done ; FindPciDevice jnc init_pci1_found ; add si,6 jmp init_pci1_loop init_pci1_found: mov edi,OFFSET DevName1 PciPowerOn ; mov bp,bx mov cl,PCI_command_reg ReadPciWord or al,PCI_command_busmstr OR PCI_command_IO OR PCI_command_mem WritePciWord ; mov cl,PCI_card_ExCa_base ReadPciDword test al,1 stc jnz init_pci1_done ; push eax call SetupInts ; mov cl,PCI_card_ExCa_base+4 ReadPciDword ; mov ebx,eax pop eax ; call CreateFuncSel mov ds:FuncSel,es ; call InitFunc ; push ds mov ax,cs mov ds,ax mov es,ax mov esi,OFFSET MemDispTable1 mov edi,OFFSET DriverName1 mov al,1 mov dx,0 mov ecx,1600 RegisterNetDriver pop ds mov ds:Handle,bx ; push ds mov bx,ds mov ax,cs mov ds,ax mov es,ax mov esi,OFFSET mem_super_thread mov edi,OFFSET SupervisorName1 mov ax,2 mov cx,1000h CreateThread pop ds ; mov ax,bp clc jmp init_pci1_done io_pci1: int 3 mov ax,bp clc jmp init_pci1_done init_pci1_done: ret InitPrimaryPciAdapter Endp InitSecondaryPciAdapter Proc near mov bp,ax mov ax,cs mov es,ax mov ax,ether_data2_sel mov ds,ax mov si,OFFSET PciVendorTab init_pci2_loop: mov ax,bp mov dx,cs:[si] mov cx,cs:[si+2] or dx,dx stc jz init_pci2_done ; FindPciDevice jnc init_pci2_found ; add si,6 jmp init_pci2_loop init_pci2_found: mov edi,OFFSET DevName2 PciPowerOn ; mov bp,bx mov cl,PCI_command_reg ReadPciWord or al,PCI_command_busmstr OR PCI_command_IO OR PCI_command_mem WritePciWord ; mov cl,PCI_card_ExCa_base ReadPciDword test al,1 stc jnz init_pci2_done ; push eax call SetupInts ; mov cl,PCI_card_ExCa_base+4 ReadPciDword ; mov ebx,eax pop eax ; call CreateFuncSel mov ds:FuncSel,es ; call InitFunc ; push ds mov ax,cs mov ds,ax mov es,ax mov esi,OFFSET MemDispTable1 mov edi,OFFSET DriverName2 mov al,1 mov dx,0 mov ecx,1600 RegisterNetDriver pop ds mov ds:Handle,bx ; push ds mov bx,ds mov ax,cs mov ds,ax mov es,ax mov esi,OFFSET mem_super_thread mov edi,OFFSET SupervisorName2 mov ax,2 mov cx,1000h CreateThread pop ds ; mov ax,bp clc jmp init_pci2_done io_pci2: int 3 mov ax,bp clc jmp init_pci2_done init_pci2_done: ret InitSecondaryPciAdapter Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: Init_net ; ; DESCRIPTION: inits adpater ; ; PARAMETERS: ; ; RETURNS: ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; init_net Proc far push ds push es pusha ; xor ax,ax call InitPrimaryPciAdapter ; inc ax call InitSecondaryPciAdapter ; popa pop es pop ds ret init_net Endp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; NAME: Init ; ; DESCRIPTION: init device ; ; PARAMETERS: ; ; RETURNS: ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Init Proc far mov ax,cs mov ds,ax mov es,ax ; mov eax,SIZE data mov bx,ether_data_sel AllocateFixedSystemMem mov ds,bx mov es,bx mov ecx,eax xor edi,edi xor al,al rep stos byte ptr es:[edi] ; mov eax,SIZE data mov bx,ether_data2_sel AllocateFixedSystemMem mov ds,bx mov es,bx mov ecx,eax xor edi,edi xor al,al rep stos byte ptr es:[edi] ; mov ax,cs mov es,ax mov edi,OFFSET init_net HookInitPci clc ret Init Endp code ENDS END init