From a6035e0c1b5785205c73dd6510e0b83631bda75b Mon Sep 17 00:00:00 2001 From: Joshua Wise Date: Mon, 26 May 2008 20:55:01 -0400 Subject: [PATCH 1/1] New ethernet code --- Ethernet.v | 10 ++++--- ethernet.asm | 75 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 75 insertions(+), 10 deletions(-) diff --git a/Ethernet.v b/Ethernet.v index d961585..bd3fdc7 100644 --- a/Ethernet.v +++ b/Ethernet.v @@ -259,16 +259,18 @@ module EnetRX( reg [2:0] transition_timeout; always @(posedge rxclk) if(in_data[2]^in_data[1]) transition_timeout<=0; else if(~&cnt) transition_timeout<=transition_timeout+1; always @(posedge rxclk) end_of_Ethernet_frame <= &transition_timeout; + reg [11:0] iaddr; ///////////////////////////////////////////////// always @(posedge rxclk) if (new_byte_available && !pktrdy) begin odata <= data; - oaddr <= oaddr + 1; + oaddr <= iaddr; + iaddr <= iaddr + 1; wr <= 1; - end else if (end_of_Ethernet_frame && (oaddr > 1)) begin - olength <= oaddr; - oaddr <= 0; + end else if (end_of_Ethernet_frame && (iaddr > 1)) begin + olength <= iaddr; + iaddr <= 0; wr <= 0; pktrdy <= 1; end else if (pktclear) begin diff --git a/ethernet.asm b/ethernet.asm index 4bcee82..85d66e1 100644 --- a/ethernet.asm +++ b/ethernet.asm @@ -58,22 +58,35 @@ myGW: db $0A, $00, $00, $01 start: ld sp, $D800 + call zerobss PUTSIL "Ethernet test ROM" -.lp: xor a ; Rest state machines +.lp: xor a ; Reset state machines ld [ETH_STATUS], a - ld a, [ETH_STATUS] ; New shit? + ld a, [ETH_STATUS] ; Load current status ld [$FF51], a and $02 ; New packet? call nz, getpacket jr .lp +zerobss: + ld hl, bssstart + ld bc, bssend - bssstart +.lp: ld a, b + or c + ret z + dec bc + xor a + ld [hli], a + ld a, h + jr .lp + getpacket: ld a, [ETH_DATA] ld b, a ld a, [ETH_DATA] ld c, a push bc - ld hl, $D000 + ld hl, packet .cplp: ld a, b or c jr z, .done @@ -133,15 +146,65 @@ ether_input: inc hl dec c jr nz, .maclp - PUTSIL "ether_input: It's to us!" + ; Done? Then it was to us! + jr .us +.notus: ; Was it to broadcast? pop hl + push hl + ld c, $06 +.bclp: ld a, [hli] + cp $FF + jr nz, .notbc + dec c + jr nz, .bclp + +.us: PUTSIL "ether_input: It's to us!" + ; Which protocol does it belong to? + pop hl + ld b, $00 + ld c, 12 + add hl, bc ; Skip source and dest MAC. + ld a, [hli] + cp $08 + jr nz, .unknownproto + ld a, [hli] + cp $06 + jr z, .arp + cp $00 + jp z, .ip + jr .unknownproto + +.notbc: pop hl + PUTSIL "ether_input: Not addressed to us and not broadcast." + ret +.unknownproto: + PUTSIL "ether_input: Unknown protocol; dropping" ret -.notus: PUTSIL "ether_input: Not to us..." - pop hl + +.arp: + PUTSIL "ether_input: ARP packet" + call arp_input + ret +.ip: + PUTSIL "ether_input: IP packet" + call ip_input ret +arp_input: + ret + +ip_input: + ret + + SECTION "ethdata", BSS +bssstart DS 0 +packet DS 1552 +bssend DS 0 + + ; SERIAL ROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + SECTION "serial", HOME putc: push af -- 2.43.0