]> Joshua Wise's Git repositories - fpgaboy.git/commitdiff
New ethernet code
authorJoshua Wise <joshua@rebirth.joshuawise.com>
Tue, 27 May 2008 00:55:01 +0000 (20:55 -0400)
committerJoshua Wise <joshua@rebirth.joshuawise.com>
Tue, 27 May 2008 00:55:01 +0000 (20:55 -0400)
Ethernet.v
ethernet.asm

index d96158534dc52154ceda219ce7d2c66db4934d0d..bd3fdc734dcc87faacefedec32e1936babc96827 100644 (file)
@@ -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
index 4bcee8263505e3741c7987b02117263358d3434c..85d66e1b38e1a1fe8d2528e50719eaf5e29dd379 100644 (file)
@@ -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
This page took 0.033859 seconds and 4 git commands to generate.