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

📄 ethernet.inc

📁 MenuetOS是一个用汇编开发的32/64位PC操作系统
💻 INC
📖 第 1 页 / 共 4 页
字号:
    mov     [hdrtype], al
    jmp     sb_002

sb_001:
    mov     al, [hdrtype]
    and     al, 0x80
    cmp     al, 0x80
    jne     sb_inc_devf

sb_002:
    mov     edx, PCI_VENDOR_ID
    call    pcibios_read_config_dword
    mov     [vendor_device], eax
    cmp     eax, 0xffffffff
    je      sb_empty
    cmp     eax, 0
    jne     sb_check_vendor

sb_empty:
    mov     [hdrtype], byte 0
    jmp     sb_inc_devf

sb_check_vendor:
    ; iterate though PCICards until end or match found
    mov     esi, PCICards

sb_check:
    cmp     [esi], dword 0
    je      sb_inc_devf                ; Quit if at last entry
    cmp     eax, [esi]
    je      sb_got_card
    add     esi, PCICARDS_ENTRY_SIZE
    jmp     sb_check

sb_got_card:
    ; indicate that we have found the card
    mov     [pci_data], eax
    mov     [pci_dev], ecx
    mov     [pci_bus], ebx

    ; Define the driver functions
    push    eax
    mov     eax, [esi+4]
    mov     [drvr_probe], eax
    mov     eax, [esi+8]
    mov     [drvr_reset], eax
    mov     eax, [esi+12]
    mov     [drvr_poll], eax
    mov     eax, [esi+16]
    mov     [drvr_transmit], eax
    pop     eax

    mov     edx, PCI_BASE_ADDRESS_0

sb_reg_check:
    call    pcibios_read_config_dword
    mov     [io_addr], eax
    and     eax, PCI_BASE_ADDRESS_IO_MASK
    cmp     eax, 0
    je      sb_inc_reg
    mov     eax, [io_addr]
    and     eax, PCI_BASE_ADDRESS_SPACE_IO
    cmp     eax, 0
    je      sb_inc_reg

    mov     eax, [io_addr]
    and     eax, PCI_BASE_ADDRESS_IO_MASK
    mov     [io_addr], eax

sb_exit1:
    ret

sb_inc_reg:
    add     edx, 4
    cmp     edx, PCI_BASE_ADDRESS_5
    jbe     sb_reg_check

sb_inc_devf:
    inc     ecx
    cmp     ecx, 255
    jb      sb_devf_loop
    inc     ebx
    cmp     ebx, 256
    jb      sb_bus_loop

    ; We get here if we didn't find our card
    ; set io_addr to 0 as an indication
    xor     eax, eax
    mov     [io_addr], eax

sb_exit2:
    ret

;***************************************************************************
;
;  DEBUGGING CODE FOLLOWS
;
;  If debugging data output is not required, ALL code & data below may
;  be removed.
;
;***************************************************************************

if DEBUGGING_STATE = DEBUGGING_ENABLED

;***************************************************************************
;   Function
;      eth_dump
;
;   Description
;       Dumps a tx or rx ethernet packet over the rs232 link
;       This is a debugging routine that seriously slows down the stack.
;       Use with caution.
;
;       Baud rate is 57600, 8n1  com1
;         eax : type (0 == rx, 1 == tx )
;          cx : # of bytes in buffer
;         esi : address of buffer start
;         edi : pointer to MACAddress ( tx only )
;
;***************************************************************************
eth_dump:
    pusha

    ; Set the port to the desired speed
    mov     ebx, 0x3f8                     ; combase

    mov     edx, ebx
    add     edx, 3                        ; data format register
    mov     al, 0x80                    ; enable access to divisor latch
    out     dx, al

    mov     edx, ebx
    add     edx, 1                        ; interrupt enable register
    mov     al, 0x00                    ; No interruts enabled
    out     dx, al

    mov     edx, ebx
    mov     al, 0x20 / 16                ; set baud rate to 57600 0x10 =115200
    out     dx, al

    mov     edx, ebx
    add     edx, 3                        ; data format register
    mov     al, 0x03                    ; 8 data bits
    out     dx, al

    mov     edx, ebx
    add     edx, 4                        ; Modem control register
    mov     al, 0x08                    ; out2 enabled. No handshaking.
    out     dx, al

    mov     edx, ebx
    add     edx, 1                        ; interrupt enable register
    mov     al, 0x01                    ; Receive data interrupt enabled,
    out     dx, al

    popa

    ; First, display the type of the buffer.
    ; If it is a tx buffer, display the macaddress

    pusha

    cmp     eax, 0
    jne     dd001

    mov     bl, 0x0a
    call    tx_byted
    mov     bl, 0x0d
    call    tx_byted

    ; Output "RX:"
    mov     bl, 'R'
    call    tx_byted
    mov     bl, 'X'
    call    tx_byted
    mov     bl, ':'
    call    tx_byted
    jmp     dump_data

dd001:
    mov     bl, 0x0a
    call    tx_byted
    mov     bl, 0x0d
    call    tx_byted

    ; Output TX: xxxxxxxxxxxx
    mov     bl, 'T'
    call    tx_byted
    mov     bl, 'X'
    call    tx_byted
    mov     bl, ':'
    call    tx_byted
    mov     bl, ' '
    call    tx_byted

    ; Display MAC address
    xor     eax, eax
    mov     al, [edi]
    shr     al, 4
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    xor     eax, eax
    mov     al, [edi]
    and     al, 0x0f
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    inc     edi
    xor     eax, eax
    mov     al, [edi]
    shr     al, 4
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    xor     eax, eax
    mov     al, [edi]
    and     al, 0x0f
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    inc     edi
    xor     eax, eax
    mov     al, [edi]
    shr     al, 4
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    xor     eax, eax
    mov     al, [edi]
    and     al, 0x0f
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    inc     edi
    xor     eax, eax
    mov     al, [edi]
    shr     al, 4
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    xor     eax, eax
    mov     al, [edi]
    and     al, 0x0f
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    inc     edi
    xor     eax, eax
    mov     al, [edi]
    shr     al, 4
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    xor     eax, eax
    mov     al, [edi]
    and     al, 0x0f
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    inc     edi
    xor     eax, eax
    mov     al, [edi]
    shr     al, 4
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    xor     eax, eax
    mov     al, [edi]
    and     al, 0x0f
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

dump_data:
    popa

    ; OK, we come in here with
    ; cx == number of byte to send
    ; esi == buffer start
    ;
dd_000:
    mov     bl, 0x0a
    call    tx_byted
    mov     bl, 0x0d
    call    tx_byted

    mov     eax, 16        ; Number of characters on the line
    mov     edi, esi    ; Save first byte position for later

    push    ecx

dd_001:
    push    eax

    ; Print a byte, and a space
    xor     eax, eax
    mov     al, [esi]
    shr     al, 4
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    xor     eax, eax
    mov     al, [esi]
    and     al, 0x0f
    mov     bl, [eax + hexchars]
    call    tx_byted ; byte in bl eax ebx edx destroyed

    mov     bl, ' '
    call    tx_byted

    pop     eax

    inc     esi
    dec     ecx
    cmp     ecx, 0
    je      dd_0011            ; Print the ASCII format

    dec     eax

    cmp     eax, 0
    je      dd_002            ; Print the ASCII format
    jmp     dd_001            ; Print rest of line

dd_0011:
    ; First, complete the 16 bytes of data, by printing spaces
    dec     eax
    cmp     eax, 0
    je      dd_002

    push    eax
    mov     bl, ' '
    call    tx_byted
    mov     bl, ' '
    call    tx_byted
    mov     bl, ' '
    call    tx_byted
    pop     eax
    jmp     dd_0011

dd_002:
    pop     ecx
    mov     esi, edi        ; Go back to the start of the line data

    mov     eax, 16

outLineAscii:
    push    eax

    xor     eax, eax
    mov     al, [esi]
    mov     bl, '.'

    cmp     al, 0x1F
    jle     outAscii
    cmp     al, 0x7e
    jge     outAscii

    mov     bl, al

outAscii:
    call    tx_byted ; byte in bl eax ebx edx destroyed

    pop     eax
    dec     ecx
    inc     esi
    cmp     ecx, 0
    je      dd_003

    dec     eax
    cmp     eax, 0
    je      dd_003
    jmp     outLineAscii

dd_003:
    cmp     ecx, 0
    je      dd_004
    jmp     dd_000

dd_004:
    ret

;***************************************************************************
;   Function
;      tx_byte
;
;   Description
;       Send a byte in bl out of the com port 1
;       destroys eax, edx
;
;***************************************************************************
tx_byted:
    push    ebx                     ; Save the byte

    mov     ebx, 0x3f8            ; get the com port address

    ; Wait for transmit buffer to empty. This could take 1ms @ 9600baud

    mov     edx, ebx
    add     edx, 5

wait_txd:
    in      al, dx                   ; read uart serialisation status
    and     al, 0x40
    cmp     al, 0
    jz      wait_txd                  ; loop until free

    mov     edx, ebx
    pop     eax                     ; restore the byte to send
    out     dx, al
    ret

; This is used for translating hex to ASCII for display or output
hexchars    db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'

end if

⌨️ 快捷键说明

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