⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcnet32.inc

📁 MenuetOS是一个用汇编开发的32/64位PC操作系统
💻 INC
📖 第 1 页 / 共 2 页
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;                                                                    ;;;;  PCNET32.INC                                                       ;;;;                                                                    ;;;;  Ethernet driver for Menuet OS                                     ;;;;                                                                    ;;;;  Version 1.0  31 July 2004                                         ;;;;                                                                    ;;;;  This driver is based on the PCNet32 driver from                   ;;;;  the etherboot 5.0.6 project. The copyright statement is           ;;;;                                                                    ;;;;          GNU GENERAL PUBLIC LICENSE                                ;;;;             Version 2, June 1991                                   ;;;;                                                                    ;;;;  remaining parts Copyright 2004 Jarek Pelczar,                     ;;;;   jpelczar@interia.pl                                              ;;;;                                                                    ;;;;  See file COPYING for details                                      ;;;;                                                                    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;macro PutStr X;{; local .__xyz1; local .__xyz2; push esi; mov esi,.__xyz1; call sys_msg_board_str; push eax; mov eax,1; call delay_hs; pop eax; jmp .__xyz2;.__xyz1:; db X; db 13,10,0;.__xyz2:; pop esi;}PCNET32_PORT_AUI      equ 0x00PCNET32_PORT_10BT     equ 0x01PCNET32_PORT_GPSI     equ 0x02PCNET32_PORT_MII      equ 0x03PCNET32_PORT_PORTSEL  equ 0x03PCNET32_PORT_ASEL     equ 0x04PCNET32_PORT_100      equ 0x40PCNET32_PORT_FD	      equ 0x80PCNET32_DMA_MASK      equ 0xffffffffPCNET32_LOG_TX_BUFFERS	equ 1PCNET32_LOG_RX_BUFFERS	equ 2PCNET32_TX_RING_SIZE		equ (1 shl PCNET32_LOG_TX_BUFFERS)PCNET32_TX_RING_MOD_MASK	equ (PCNET32_TX_RING_SIZE-1)PCNET32_TX_RING_LEN_BITS	equ 0PCNET32_RX_RING_SIZE		equ (1 shl PCNET32_LOG_RX_BUFFERS)PCNET32_RX_RING_MOD_MASK	equ (PCNET32_RX_RING_SIZE-1)PCNET32_RX_RING_LEN_BITS	equ (PCNET32_LOG_RX_BUFFERS shl 4)PCNET32_PKT_BUF_SZ		equ 1544PCNET32_PKT_BUF_SZ_NEG		equ 0xf9f8pcnet32_txb equ (eth_data_start)pcnet32_rxb equ ((pcnet32_txb+(PCNET32_PKT_BUF_SZ*PCNET32_TX_RING_SIZE)+0xf) and 0xfffffff0)pcnet32_tx_ring equ ((pcnet32_rxb+(PCNET32_PKT_BUF_SZ*PCNET32_RX_RING_SIZE)+0xf) and 0xfffffff0)pcnet32_rx_ring equ ((pcnet32_tx_ring+(16*PCNET32_TX_RING_SIZE)+0xf) and 0xfffffff0)virtual at ((pcnet32_rx_ring+(16*PCNET32_RX_RING_SIZE)+0xf) and 0xfffffff0)pcnet32_private:.mode			dw ?.tlen_rlen		dw ?.phys_addr		db ?,?,?,?,?,?.reserved		dw ?.filter			dd ?,?.rx_ring		dd ?.tx_ring		dd ?.cur_rx			dd ?.cur_tx			dd ?.dirty_rx		dd ?.dirty_tx		dd ?.tx_full		db ?.options		dd ?.full_duplex		db ?.chip_version		dd ?.mii			db ?.ltint			db ?.dxsuflo		db ?.fset			db ?.fdx			db ?end virtualvirtual at 0pcnet32_rx_head:.base		dd ?.buf_length	dw ?.status		dw ?.msg_length	dd ?.reserved	dd ?end virtualvirtual at 0pcnet32_tx_head:.base		dd ?.length		dw ?.status		dw ?.misc		dd ?.reserved	dd ?end virtualpcnet32_access:.read_csr		dd ?.write_csr		dd ?.read_bcr		dd ?.write_bcr		dd ?.read_rap		dd ?.write_rap		dd ?.reset			dd ?pcnet32_options_mapping:dd PCNET32_PORT_ASEL	;  0 Auto-selectdd PCNET32_PORT_AUI	;  1 BNC/AUIdd PCNET32_PORT_AUI	;  2 AUI/BNC    dd PCNET32_PORT_ASEL	;  3 not supporteddd PCNET32_PORT_10BT or PCNET32_PORT_FD	;  4 10baseT-FDdd PCNET32_PORT_ASEL	;  5 not supporteddd PCNET32_PORT_ASEL	;  6 not supporteddd PCNET32_PORT_ASEL	;  7 not supporteddd PCNET32_PORT_ASEL	;  8 not supporteddd PCNET32_PORT_MII	;  9 MII 10baseTdd PCNET32_PORT_MII or PCNET32_PORT_FD	; 10 MII 10baseT-FDdd PCNET32_PORT_MII	; 11 MII (autosel)dd PCNET32_PORT_10BT	; 12 10BaseTdd PCNET32_PORT_MII or PCNET32_PORT_100	; 13 MII 100BaseTxdd PCNET32_PORT_MII or PCNET32_PORT_100 or PCNET32_PORT_FD	; 14 MII 100BaseTx-FDdd PCNET32_PORT_ASEL	; 15 not supportedPCNET32_WIO_RDP		equ 0x10PCNET32_WIO_RAP		equ 0x12PCNET32_WIO_RESET	equ 0x14PCNET32_WIO_BDP		equ 0x16PCNET32_DWIO_RDP	equ 0x10PCNET32_DWIO_RAP	equ 0x14PCNET32_DWIO_RESET	equ 0x18PCNET32_DWIO_BDP	equ 0x1CPCNET32_TOTAL_SIZE	equ 0x20; ebx - index; return:; eax - datapcnet32_wio_read_csr:    push edx    lea edx,[ebp+PCNET32_WIO_RAP]    mov ax,bx    out dx,ax    lea edx,[ebp+PCNET32_WIO_RDP]    in ax,dx    and eax,0xffff    pop edx    ret; eax - data; ebx - indexpcnet32_wio_write_csr:    push edx    lea edx,[ebp+PCNET32_WIO_RAP]    xchg eax,ebx    out dx,ax    xchg eax,ebx    lea edx,[ebp+PCNET32_WIO_RDP]    out dx,ax    pop edx    ret; ebx - index; return:; eax - datapcnet32_wio_read_bcr:    push edx    lea edx,[ebp+PCNET32_WIO_RAP]    mov ax,bx    out dx,ax    lea edx,[ebp+PCNET32_WIO_BDP]    in ax,dx    and eax,0xffff    pop edx    ret; eax - data; ebx - indexpcnet32_wio_write_bcr:    push edx    lea edx,[ebp+PCNET32_WIO_RAP]    xchg eax,ebx    out dx,ax    xchg eax,ebx    lea edx,[ebp+PCNET32_WIO_BDP]    out dx,ax    pop edx    retpcnet32_wio_read_rap:    push edx    lea edx,[ebp+PCNET32_WIO_RAP]    in ax,dx    and eax,0xffff    pop edx    ret; eax - valpcnet32_wio_write_rap:    push edx    lea edx,[ebp+PCNET32_WIO_RAP]    out dx,ax    pop edx    retpcnet32_wio_reset:    push edx    push eax    lea edx,[ebp+PCNET32_WIO_RESET]    in ax,dx    pop eax    pop edx    retpcnet32_wio_check:    push edx    mov ax,88    lea edx,[ebp+PCNET32_WIO_RAP]    out dx,ax    nop    nop    in ax,dx    cmp ax,88    sete al    pop edx    retpcnet32_wio:    dd pcnet32_wio_read_csr    dd pcnet32_wio_write_csr    dd pcnet32_wio_read_bcr    dd pcnet32_wio_write_bcr    dd pcnet32_wio_read_rap    dd pcnet32_wio_write_rap    dd pcnet32_wio_reset; ebx - index; return:; eax - datapcnet32_dwio_read_csr:    push edx    lea edx,[ebp+PCNET32_DWIO_RAP]    mov ebx,eax    out dx,eax    lea edx,[ebp+PCNET32_DWIO_RDP]    in eax,dx    and eax,0xffff    pop edx    ret; ebx - index; eax - datapcnet32_dwio_write_csr:    push edx    lea edx,[ebp+PCNET32_DWIO_RAP]    xchg eax,ebx    out dx,eax    lea edx,[ebp+PCNET32_DWIO_RDP]    xchg eax,ebx    out dx,eax    pop edx    ret; ebx - index; return:; eax - datapcnet32_dwio_read_bcr:    push edx    lea edx,[ebp+PCNET32_DWIO_RAP]    mov ebx,eax    out dx,eax    lea edx,[ebp+PCNET32_DWIO_BDP]    in eax,dx    and eax,0xffff    pop edx    ret; ebx - index; eax - datapcnet32_dwio_write_bcr:    push edx    lea edx,[ebp+PCNET32_DWIO_RAP]    xchg eax,ebx    out dx,eax    lea edx,[ebp+PCNET32_DWIO_BDP]    xchg eax,ebx    out dx,eax    pop edx    retpcnet32_dwio_read_rap:    push edx    lea edx,[ebp+PCNET32_DWIO_RAP]    in eax,dx    and eax,0xffff    pop edx    ret; eax - valpcnet32_dwio_write_rap:    push edx    lea edx,[ebp+PCNET32_DWIO_RAP]    out dx,eax    pop edx    retpcnet32_dwio_reset:    push edx    push eax    lea edx,[ebp+PCNET32_DWIO_RESET]    in eax,dx    pop eax    pop edx    retpcnet32_dwio_check:    push edx    lea edx,[PCNET32_DWIO_RAP]    mov eax,88    out dx,eax    nop    nop    in eax,dx    and eax,0xffff    cmp eax,88    sete al    pop edx    retpcnet32_dwio:    dd pcnet32_dwio_read_csr    dd pcnet32_dwio_write_csr    dd pcnet32_dwio_read_bcr    dd pcnet32_dwio_write_bcr    dd pcnet32_dwio_read_rap    dd pcnet32_dwio_write_rap    dd pcnet32_dwio_resetpcnet32_init_ring:    mov [pcnet32_private.tx_full],0    mov [pcnet32_private.cur_rx],0    mov [pcnet32_private.cur_tx],0    mov [pcnet32_private.dirty_rx],0    mov [pcnet32_private.dirty_tx],0    mov edi,pcnet32_rx_ring    mov ecx,PCNET32_RX_RING_SIZE    mov ebx,pcnet32_rxb.rx_init:    mov [edi+pcnet32_rx_head.base],ebx    mov [edi+pcnet32_rx_head.buf_length],word PCNET32_PKT_BUF_SZ_NEG    mov [edi+pcnet32_rx_head.status],word 0x8000    add ebx,PCNET32_PKT_BUF_SZ;    inc ebx    add edi,16    loop .rx_init    mov edi,pcnet32_tx_ring    mov ecx,PCNET32_TX_RING_SIZE.tx_init:    mov [edi+pcnet32_tx_head.base],dword 0    mov [edi+pcnet32_tx_head.status],word 0    add edi,16    loop .tx_init    mov [pcnet32_private.tlen_rlen],(PCNET32_TX_RING_LEN_BITS or PCNET32_RX_RING_LEN_BITS)    mov esi,node_addr    mov edi,pcnet32_private.phys_addr    cld    movsd    movsw    mov dword [pcnet32_private.rx_ring],pcnet32_rx_ring    mov dword [pcnet32_private.tx_ring],pcnet32_tx_ring    retpcnet32_reset:    ; Reset PCNET32    mov ebp,[io_addr]    call dword [pcnet32_access.reset]    ; set 32bit mode    mov ebx,20    mov eax,2    call dword [pcnet32_access.write_bcr]    ; set/reset autoselect bit    mov ebx,2    call dword [pcnet32_access.read_bcr]    and eax,not 2    test [pcnet32_private.options],PCNET32_PORT_ASEL    jz .L1    or eax,2.L1:    call dword [pcnet32_access.write_bcr]    ; Handle full duplex setting    cmp byte [pcnet32_private.full_duplex],0    je .L2    mov ebx,9    call dword [pcnet32_access.read_bcr]    and eax,not 3    test [pcnet32_private.options],PCNET32_PORT_FD    jz .L3    or eax,1    cmp [pcnet32_private.options],PCNET32_PORT_FD or PCNET32_PORT_AUI    jne .L4    or eax,2    jmp .L4.L3:    test [pcnet32_private.options],PCNET32_PORT_ASEL    jz .L4    cmp [pcnet32_private.chip_version],0x2627    jne .L4    or eax,3.L4:    mov ebx,9    call dword [pcnet32_access.write_bcr].L2:    ; set/reset GPSI bit    mov ebx,124    call dword [pcnet32_access.read_csr]    mov ecx,[pcnet32_private.options]    and ecx,PCNET32_PORT_PORTSEL    cmp ecx,PCNET32_PORT_GPSI    jne .L5    or eax,0x10

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -