mirror of
https://github.com/A2osX/A2osX.git
synced 2024-12-29 01:33:40 +00:00
373 lines
6.6 KiB
Plaintext
373 lines
6.6 KiB
Plaintext
NEW
|
||
PREFIX /A2OSX.BUILD
|
||
AUTO 4,1
|
||
.LIST OFF
|
||
*/--------------------------------------
|
||
* # ARP.Clear
|
||
* Clear ARP Cache
|
||
* **In:**
|
||
* **Out:**
|
||
*\--------------------------------------
|
||
ARP.Clear ldx #K.ARPCACHE.SIZE*S.ARPCACHE
|
||
.1 stz ARP.CACHE-1,x
|
||
dex
|
||
bne .1
|
||
clc
|
||
rts
|
||
*/--------------------------------------
|
||
* # ARP.Query
|
||
* Query ARP Cache and returns HW address
|
||
* **In:**
|
||
* PUSHW PTR to MAC (to fill)
|
||
* PUSHW PTR to IP
|
||
* **Out:**
|
||
* CC: hit: MAC filled
|
||
* CS: missed
|
||
*\--------------------------------------
|
||
ARP.Query >PULLW ZPPtrIP IP
|
||
>PULLW ZPPtrMAC MAC
|
||
|
||
ldy #3
|
||
.1 lda (ZPPtrIP),y
|
||
sta ARP.TmpCache+S.ARPCACHE.IP,y
|
||
dey
|
||
bpl .1
|
||
jsr ARP.QUERY.I
|
||
bcs .9
|
||
|
||
ldy #5
|
||
.2 lda ARP.TmpCache+S.ARPCACHE.MAC,y
|
||
sta (ZPPtrMAC),y
|
||
dey
|
||
bpl .2
|
||
clc
|
||
.9 rts
|
||
*/--------------------------------------
|
||
* # ARP.Add
|
||
* Add a static ARP cache record
|
||
* **In:**
|
||
* PUSHW PTR to MAC
|
||
* PUSHW PTR to IP
|
||
*\--------------------------------------
|
||
ARP.Add >PULLW ZPPtrIP IP
|
||
>PULLW ZPPtrMAC MAC
|
||
|
||
stz ARP.TmpCache+S.ARPCACHE.TTL
|
||
stz ARP.TmpCache+S.ARPCACHE.TTL+1
|
||
|
||
ldy #3
|
||
.1 lda (ZPPtrIP),y
|
||
sta ARP.TmpCache+S.ARPCACHE.IP,y
|
||
dey
|
||
bpl .1
|
||
|
||
ldy #5
|
||
.2 lda (ZPPtrMAC),y
|
||
sta ARP.TmpCache+S.ARPCACHE.MAC,y
|
||
dey
|
||
bpl .2
|
||
|
||
lda #S.ARPCACHE.STATUS.RESOLVED+S.ARPCACHE.STATUS.STATIC
|
||
|
||
ARP.ADD.I sta ARP.TmpCache
|
||
|
||
jsr ARP.FIND.BY.IP
|
||
bcc .1
|
||
jsr ARP.FIND.FREE
|
||
|
||
.1 ldy #S.ARPCACHE-1
|
||
.2 lda ARP.TmpCache,y
|
||
sta (ZPCachePtr),y
|
||
dey
|
||
bpl .2
|
||
|
||
clc
|
||
rts
|
||
*/--------------------------------------
|
||
* # ARP.GetCAche
|
||
* Return a Ptr to ARP Cache Table
|
||
* **In:**
|
||
* **Out:**
|
||
* Y,A = PTR to ARP.CACHE
|
||
*\--------------------------------------
|
||
ARP.GetCAche >LDYA L.ARP.CACHE
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* PRIVATE
|
||
*--------------------------------------
|
||
ARP.AddFromFrameInPtr
|
||
ldy #S.IP.SRC+3
|
||
ldx #3
|
||
|
||
.1 lda (ZPFrameInPtr),y
|
||
sta ARP.TmpCache+S.ARPCACHE.IP,x
|
||
dey
|
||
dex
|
||
bpl .1
|
||
|
||
ldy #S.ETH.SRCMAC+5
|
||
ldx #5
|
||
|
||
.2 lda (ZPFrameInPtr),y
|
||
sta ARP.TmpCache+S.ARPCACHE.MAC,x
|
||
dey
|
||
dex
|
||
bpl .2
|
||
|
||
lda #K.ARP.TTL
|
||
sta ARP.TmpCache+S.ARPCACHE.TTL
|
||
lda /K.ARP.TTL
|
||
sta ARP.TmpCache+S.ARPCACHE.TTL+1
|
||
|
||
lda #S.ARPCACHE.STATUS.RESOLVED
|
||
jmp ARP.ADD.I
|
||
*--------------------------------------
|
||
ARP.IN ldy #S.ARP.TPA+3
|
||
ldx #3
|
||
|
||
.1 lda (ZPFrameInPtr),y
|
||
cmp IPCFG+S.IPCFG.IP,x
|
||
bne ARP.IN.EXIT
|
||
dey
|
||
dex
|
||
bpl .1
|
||
|
||
ldy #S.ARP.OPERATION+1 HI byte
|
||
lda (ZPFrameInPtr),y
|
||
cmp #S.ARP.OPERATION.REQ
|
||
beq ARP.IN.REQ
|
||
|
||
cmp #S.ARP.OPERATION.REP
|
||
beq ARP.IN.REP
|
||
|
||
ARP.IN.EXIT lda hFrameIn
|
||
beq .8
|
||
stz hFrameIn
|
||
>SYSCALL FreeMem
|
||
.8 clc
|
||
rts
|
||
|
||
ARP.IN.REQ ldy #S.ARP.SPA+3
|
||
ldx #3
|
||
|
||
.1 lda (ZPFrameInPtr),y
|
||
sta ARP.REP.TPA,x
|
||
dey
|
||
dex
|
||
bpl .1
|
||
|
||
ldy #S.ARP.SHA+5
|
||
ldx #5
|
||
|
||
.2 lda (ZPFrameInPtr),y
|
||
sta ARP.REP.DSTMAC,x
|
||
sta ARP.REP.THA,x
|
||
dey
|
||
dex
|
||
bpl .2
|
||
|
||
>PUSHWI S.ARP
|
||
>PUSHW L.ARP.REP
|
||
lda IPCFG+S.IPCFG.hFD
|
||
>SYSCALL write
|
||
|
||
bra ARP.IN.EXIT
|
||
|
||
ARP.IN.REP lda #K.ARP.TTL
|
||
sta ARP.TmpCache+S.ARPCACHE.TTL
|
||
lda /K.ARP.TTL
|
||
sta ARP.TmpCache+S.ARPCACHE.TTL+1
|
||
|
||
ldy #S.ARP.SPA+3
|
||
ldx #3
|
||
|
||
.1 lda (ZPFrameInPtr),y
|
||
sta ARP.TmpCache+S.ARPCACHE.IP,x
|
||
dey
|
||
dex
|
||
bpl .1
|
||
|
||
ldy #S.ARP.SHA+5
|
||
ldx #5
|
||
|
||
.2 lda (ZPFrameInPtr),y
|
||
sta ARP.TmpCache+S.ARPCACHE.MAC,x
|
||
dey
|
||
dex
|
||
bpl .2
|
||
|
||
lda #S.ARPCACHE.STATUS.RESOLVED
|
||
|
||
jsr ARP.ADD.I
|
||
jmp ARP.IN.EXIT
|
||
*--------------------------------------
|
||
ARP.QUERY.I jsr ARP.FIND.BY.IP
|
||
bcs .3 send an ARP request
|
||
|
||
lda (ZPCachePtr) get status...
|
||
bpl .9 Pending...
|
||
|
||
ldy #S.ARPCACHE.MAC
|
||
|
||
.2 lda (ZPCachePtr),y
|
||
sta ARP.TmpCache,y
|
||
iny
|
||
cpy #S.ARPCACHE.MAC+6
|
||
bne .2
|
||
|
||
ldy #S.ARPCACHE.TTL
|
||
lda #K.ARP.TTL
|
||
sta (ZPCachePtr),y
|
||
iny
|
||
lda /K.ARP.TTL
|
||
sta (ZPCachePtr),y
|
||
|
||
clc
|
||
rts
|
||
|
||
.3 ldx #3
|
||
|
||
.4 lda ARP.TmpCache+S.ARPCACHE.IP,x
|
||
sta ARP.REQ.TPA,x
|
||
dex
|
||
bpl .4
|
||
|
||
>PUSHWI S.ARP
|
||
>PUSHW L.ARP.REQ
|
||
lda IPCFG+S.IPCFG.hFD
|
||
>SYSCALL write
|
||
bcs .99
|
||
|
||
lda #K.ARP.PENDING.TTL
|
||
sta ARP.TmpCache+S.ARPCACHE.TTL
|
||
stz ARP.TmpCache+S.ARPCACHE.TTL+1
|
||
|
||
lda #S.ARPCACHE.STATUS.PENDING
|
||
jsr ARP.ADD.I
|
||
|
||
.9 lda #ERR.ARP.PENDING
|
||
sec
|
||
.99 rts
|
||
*--------------------------------------
|
||
ARP.FIND.BY.IP >LDYA L.ARP.CACHE
|
||
>STYA ZPCachePtr
|
||
|
||
lda #K.ARPCACHE.SIZE
|
||
sta TmpOffset
|
||
|
||
.1 lda (ZPCachePtr)
|
||
beq .3
|
||
|
||
ldx #3
|
||
ldy #S.ARPCACHE.IP+3
|
||
|
||
.2 lda ARP.TmpCache+S.ARPCACHE.IP,x
|
||
cmp (ZPCachePtr),y
|
||
bne .3
|
||
dey
|
||
dex
|
||
bpl .2
|
||
|
||
clc
|
||
rts
|
||
|
||
.3 lda ZPCachePtr
|
||
clc
|
||
adc #S.ARPCACHE
|
||
sta ZPCachePtr
|
||
bcc .8
|
||
inc ZPCachePtr+1
|
||
|
||
.8 dec TmpOffset
|
||
bne .1
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
ARP.FIND.FREE >LDYA L.ARP.CACHE
|
||
>STYA ZPCachePtr
|
||
|
||
lda #$ff
|
||
sta TmpDWord
|
||
sta TmpDWord+1
|
||
|
||
ldx #K.ARPCACHE.SIZE
|
||
|
||
.1 lda (ZPCachePtr)
|
||
beq .8
|
||
bpl .6
|
||
|
||
ldy #S.ARPCACHE.TTL
|
||
lda (ZPCachePtr),y
|
||
sec
|
||
sbc TmpDWord
|
||
iny
|
||
lda (ZPCachePtr),y
|
||
sbc TmpDWord+1
|
||
bcc .6
|
||
|
||
lda (ZPCachePtr),y
|
||
sta TmpDWord+1
|
||
dey
|
||
lda (ZPCachePtr),y
|
||
sta TmpDWord
|
||
|
||
>LDYA ZPCachePtr
|
||
>STYA ZPTmpPtr1 save lowest TTL slot ...
|
||
|
||
.6 lda ZPCachePtr
|
||
clc
|
||
adc #S.ARPCACHE
|
||
sta ZPCachePtr
|
||
bcc .7
|
||
inc ZPCachePtr+1
|
||
|
||
.7 dex
|
||
bne .1
|
||
|
||
>LDYA ZPTmpPtr1
|
||
>STYA ZPCachePtr
|
||
lda #0
|
||
sta (ZPCachePtr)
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
ARP.EXPIRE >LDYA L.ARP.CACHE
|
||
>STYA ZPCachePtr
|
||
|
||
ldx #K.ARPCACHE.SIZE
|
||
|
||
.1 lda (ZPCachePtr)
|
||
beq .2
|
||
|
||
ldy #S.ARPCACHE.TTL
|
||
sec
|
||
lda (ZPCachePtr),y
|
||
sbc #1
|
||
sta (ZPCachePtr),y
|
||
iny
|
||
lda (ZPCachePtr),y
|
||
sbc #0
|
||
sta (ZPCachePtr),y
|
||
bcs .2
|
||
|
||
lda #0
|
||
sta (ZPCachePtr)
|
||
|
||
.2 lda ZPCachePtr
|
||
clc
|
||
adc #S.ARPCACHE
|
||
sta ZPCachePtr
|
||
bcc .3
|
||
inc ZPCachePtr+1
|
||
|
||
.3 dex
|
||
bne .1
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/LIB/LIBTCPIP.S.ARP
|
||
LOAD /A2OSX.SRC/LIB/LIBTCPIP.S
|
||
ASM
|