mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-29 17:50:18 +00:00
367 lines
7.9 KiB
Plaintext
367 lines
7.9 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
.OP 65C02
|
||
.OR $2000
|
||
.TF /A2OSX.BOOT/LIB/LIBTCPIP.O
|
||
*--------------------------------------
|
||
.INB INC/MACROS.I
|
||
.INB INC/A2OSX.I
|
||
.INB INC/LIBTCPIP.I
|
||
*--------------------------------------
|
||
ZPFrameBase1 .EQ ZPLIB
|
||
ZPFrameLen1 .EQ ZPLIB+2
|
||
*ZPFramePtr1 .EQ ZPLIB+4
|
||
ZPPtrIP .EQ ZPLIB+12
|
||
ZPPtrMAC .EQ ZPLIB+14
|
||
ZPPtrDNS .EQ ZPLIB+16
|
||
ZPPtrSKT .EQ ZPLIB+18
|
||
ZPTmpPtr1 .EQ ZPLIB+20
|
||
ZPTmpPtr2 .EQ ZPLIB+22
|
||
ZPTmpPtr3 .EQ ZPLIB+24
|
||
ZPDataPtr .EQ ZPLIB+26
|
||
ZPDataLen .EQ ZPLIB+28
|
||
ZPCachePtr .EQ ZPLIB+30
|
||
*--------------------------------------
|
||
* File Header (16 Bytes)
|
||
*--------------------------------------
|
||
CS.START cld
|
||
jmp (.1,x)
|
||
.DA #$61 6502,Level 1 (65c02)
|
||
.DA #1 BIN Layout Version 1
|
||
.DA 0
|
||
.DA CS.END-CS.START
|
||
.DA 0
|
||
.DA 0
|
||
.DA 0
|
||
*--------------------------------------
|
||
* Relocation Table
|
||
*--------------------------------------
|
||
.1 .DA LIB.LOAD
|
||
.DA LIB.UNLOAD
|
||
|
||
.DA SET.IPCFG
|
||
.DA GET.IPCFG
|
||
|
||
.DA NEW.ICMP.FRAME
|
||
.DA NEW.TCP.FRAME
|
||
.DA NEW.UDP.FRAME
|
||
.DA NEW.IP.FRAME
|
||
.DA $ffff NEW.ARP.FRAME
|
||
.DA $ffff NEW.ETH.FRAME
|
||
|
||
.DA SEND.ICMP.FRAME
|
||
.DA SEND.TCP.FRAME
|
||
.DA SEND.UDP.FRAME
|
||
.DA SEND.IP.FRAME
|
||
.DA $ffff SEND.ARP.FRAME
|
||
.DA $ffff SEND.ETH.FRAME
|
||
|
||
.DA ARP.CLEAR
|
||
.DA ARP.QUERY
|
||
.DA ARP.ADD
|
||
.DA ARP.GETCACHE
|
||
|
||
.DA DNS.CLEAR
|
||
.DA DNS.QUERY
|
||
.DA DNS.ADD
|
||
.DA DNS.GETCACHE
|
||
|
||
.DA RCVD.FRAMEA
|
||
.DA PULSEA
|
||
|
||
.DA SKT.NEW
|
||
.DA $FFFF
|
||
.DA SKT.ACCEPTA
|
||
.DA SKT.SENDA
|
||
.DA SKT.SEND
|
||
.DA SKT.RCVDA
|
||
.DA $FFFF
|
||
.DA SKT.CLOSEA
|
||
.DA SKT.GETTABLE
|
||
.DA SKT.GETA
|
||
|
||
.DA HST.GETBYNAME
|
||
.DA HST.GETBYADDR
|
||
*--------------------------------------
|
||
L.IPCFG .DA IPCFG
|
||
L.ARP.REQ .DA ARP.REQ
|
||
L.ARP.REP .DA ARP.REP
|
||
L.DNS.SOCKET .DA DNS.SOCKET
|
||
L.DNS.MSG .DA DNS.MSG
|
||
L.ARP.CACHE .DA ARP.CACHE
|
||
L.DNS.CACHE .DA DNS.CACHE
|
||
L.SKT.TABLE .DA SKT.TABLE
|
||
L.TmpSocket .DA TmpSocket
|
||
L.TCP.MSG .DA TCP.MSG
|
||
.DA 0
|
||
*--------------------------------------
|
||
LIB.LOAD lda bFirstLoad
|
||
bne .8
|
||
jsr ARP.CLEAR
|
||
jsr DNS.CLEAR
|
||
|
||
>LDYAI K.DYNPORT.START
|
||
>STYA DYNPORT.LAST
|
||
|
||
inc bFirstLoad
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
LIB.UNLOAD clc
|
||
rts
|
||
*--------------------------------------
|
||
* PULLW = PTR to S.IPCFG
|
||
*--------------------------------------
|
||
SET.IPCFG >PULLW ZPTmpPtr1
|
||
ldy #0
|
||
.1 lda (ZPTmpPtr1),y
|
||
sta IPCFG,y
|
||
iny
|
||
cpy #S.IPCFG
|
||
bne .1
|
||
|
||
ldx #5
|
||
.2 lda IPCFG+S.IPCFG.MAC,x
|
||
sta ARP.REQ.SRCMAC,x
|
||
sta ARP.REQ.SHA,x
|
||
sta ARP.REP.SRCMAC,x
|
||
sta ARP.REP.SHA,x
|
||
dex
|
||
bpl .2
|
||
|
||
ldx #3
|
||
.3 lda IPCFG+S.IPCFG.IP,x
|
||
sta ARP.REQ.SPA,x
|
||
sta ARP.REP.SPA,x
|
||
sta DNS.SOCKET.SA,x
|
||
dex
|
||
bpl .3
|
||
|
||
lda IPCFG+S.IPCFG.HDEV
|
||
|
||
>SYSCALL SYS.GetDevByIDA
|
||
>STYA NetDevJmp+1
|
||
|
||
ldx #DEVMGR.GETINFO
|
||
jsr NetDevJmp
|
||
|
||
>STYA ZPTmpPtr2
|
||
ldy #S.DEVINFO.FLAGS
|
||
lda (ZPTmpPtr2),y
|
||
sta DevFlags
|
||
and #S.DEVINFO.NET.FLAGS.ARPOFFLOAD
|
||
beq .4
|
||
|
||
>LDYA ZPTmpPtr1
|
||
ldx #DEVMGR.SETIPCFG
|
||
jsr NetDevJmp
|
||
|
||
.4 lda hDNSSocket1
|
||
beq .41
|
||
jsr SKT.CLOSEA
|
||
|
||
.41 lda hDNSSocket2
|
||
beq .42
|
||
jsr SKT.CLOSEA
|
||
|
||
.42 lda IPCFG+S.IPCFG.DNS1
|
||
beq .6
|
||
|
||
ldx #3
|
||
.5 lda IPCFG+S.IPCFG.DNS1,x
|
||
sta DNS.SOCKET.DA,x
|
||
dex
|
||
bpl .5
|
||
|
||
>PUSHW L.DNS.SOCKET
|
||
jsr SKT.NEW
|
||
bcs .9
|
||
|
||
stx hDNSSocket1
|
||
|
||
.6 lda IPCFG+S.IPCFG.DNS2
|
||
beq .8
|
||
|
||
ldx #3
|
||
.7 lda IPCFG+S.IPCFG.DNS2,x
|
||
sta DNS.SOCKET.DA,x
|
||
dex
|
||
bpl .7
|
||
|
||
>PUSHW L.DNS.SOCKET
|
||
jsr SKT.NEW
|
||
bcs .9
|
||
|
||
stx hDNSSocket2
|
||
|
||
.8 >LDYA ZPTmpPtr1
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
* grab a copy on the fly for lib function
|
||
* OUT :
|
||
* Y,A = PTR to S.IPCFG
|
||
*--------------------------------------
|
||
GET.IPCFG >LDYA L.IPCFG
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* Expire = every sec
|
||
* Retry = every 100 msec
|
||
*--------------------------------------
|
||
PULSEA asl
|
||
bpl .1
|
||
jsr ARP.EXPIRE
|
||
jsr DNS.EXPIRE
|
||
.1 jmp FRM.RETRY
|
||
*--------------------------------------
|
||
ToLowerCaseA cmp #'A'
|
||
bcc .1
|
||
cmp #'Z'+1
|
||
bcs .1
|
||
adc #$20
|
||
.1 rts
|
||
*--------------------------------------
|
||
GetDynPort inc DYNPORT.LAST
|
||
bne .1
|
||
inc DYNPORT.LAST+1
|
||
lda DYNPORT.LAST
|
||
sec
|
||
sbc #K.DYNPORT.END
|
||
lda DYNPORT.LAST+1
|
||
sbc /K.DYNPORT.END
|
||
bcs .1
|
||
>LDAXI K.DYNPORT.START
|
||
>STAX DYNPORT.LAST
|
||
rts CC
|
||
|
||
.1 >LDAX DYNPORT.LAST
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
DecDataLen lda ZPDataLen
|
||
bne .1
|
||
lda ZPDataLen+1
|
||
beq .9
|
||
dec ZPDataLen+1
|
||
.1 dec ZPDataLen
|
||
lda #$FF Make NZ
|
||
.9 rts
|
||
*--------------------------------------
|
||
NetDevJmp jmp *
|
||
*--------------------------------------
|
||
.INB LIB/LIBTCPIP.S.FRM
|
||
.INB LIB/LIBTCPIP.S.ARP
|
||
.INB LIB/LIBTCPIP.S.IP
|
||
.INB LIB/LIBTCPIP.S.ICMP
|
||
.INB LIB/LIBTCPIP.S.UDP
|
||
.INB LIB/LIBTCPIP.S.TCP
|
||
.INB LIB/LIBTCPIP.S.DNS
|
||
.INB LIB/LIBTCPIP.S.SKT
|
||
.INB LIB/LIBTCPIP.S.HST
|
||
*--------------------------------------
|
||
CS.END
|
||
*--------------------------------------
|
||
ARP.REQ .DA S.ARP-2 Frame size
|
||
ARP.REQ.DSTMAC .HS FFFFFFFFFFFF
|
||
ARP.REQ.SRCMAC .BS 6
|
||
ARP.REQ.ETYPE .DA /S.ETH.ETHERTYPE.ARP
|
||
.DA #S.ETH.ETHERTYPE.ARP
|
||
.HS 0001.0800.06.04
|
||
ARP.REQ.OP .DA /S.ARP.OPERATION.REQ
|
||
.DA #S.ARP.OPERATION.REQ
|
||
ARP.REQ.SHA .BS 6
|
||
ARP.REQ.SPA .BS 4
|
||
ARP.REQ.THA .BS 6
|
||
ARP.REQ.TPA .BS 4
|
||
*--------------------------------------
|
||
ARP.REP .DA S.ARP-2 Frame size
|
||
ARP.REP.DSTMAC .BS 6
|
||
ARP.REP.SRCMAC .BS 6
|
||
ARP.REP.ETYPE .DA /S.ETH.ETHERTYPE.ARP
|
||
.DA #S.ETH.ETHERTYPE.ARP
|
||
.HS 0001.0800.06.04
|
||
ARP.REP.OP .DA /S.ARP.OPERATION.REP
|
||
.DA #S.ARP.OPERATION.REP
|
||
ARP.REP.SHA .BS 6
|
||
ARP.REP.SPA .BS 4
|
||
ARP.REP.THA .BS 6
|
||
ARP.REP.TPA .BS 4
|
||
*--------------------------------------
|
||
TCP.MSG .DA S.TCP-2+4 +4 bytes for MSS option
|
||
.BS 12 ETH:MAC+MAC
|
||
.DA /S.ETH.ETHERTYPE.IP
|
||
.DA #S.ETH.ETHERTYPE.IP
|
||
|
||
.DA $0045 IP:
|
||
.BS 6 LEN+ID+Frag
|
||
.DA #K.IP.TTL
|
||
.DA #S.IP.PROTOCOL.TCP
|
||
.BS 2 Checksum
|
||
.BS 8 IP:DST,SRC
|
||
|
||
.BS 4 TCP:Ports
|
||
.BS 8 SEQ,ACK
|
||
.DA #$60 6 DWORD
|
||
.BS 1 Options
|
||
.DA /K.TCP.WSIZE
|
||
.DA #K.TCP.WSIZE
|
||
.BS 4 CHK,URG
|
||
.HS 0204 MSS option
|
||
.DA /K.TCP.MSS
|
||
.DA #K.TCP.MSS
|
||
*--------------------------------------
|
||
DNS.SOCKET .DA #S.SOCKET.SOCK.DGRAM
|
||
.BS 3
|
||
DNS.SOCKET.SA .BS 4
|
||
DNS.SOCKET.SP .DA 0 Dynamic
|
||
DNS.SOCKET.DA .BS 4
|
||
DNS.SOCKET.DP .DA UDP.PORT.DNS
|
||
.BS 16
|
||
*--------------------------------------
|
||
DNS.MSG.LEN .BS 2
|
||
DNS.MSG
|
||
DNS.MSG.ID .BS 2
|
||
.DA /S.DNS.F.RD Flags=query
|
||
.DA #S.DNS.F.RD
|
||
.DA $100 QDCOUNT
|
||
.BS 6 ANCOUNT,NSCOUNT,ARCOUNT
|
||
DNS.MSG.NAME .BS K.DNS.MAXLEN+6
|
||
*--------------------------------------
|
||
IPCFG .BS S.IPCFG
|
||
ARP.CACHE .BS K.ARPCACHE.SIZE*S.ARPCACHE
|
||
DNS.CACHE .BS K.DNSCACHE.SIZE*S.DNSCACHE
|
||
SKT.TABLE .BS K.SKTTABLE.SIZE*S.SOCKET
|
||
FRM.QUEUE.Tail .BS 1
|
||
FRM.QUEUE.Head .BS 1
|
||
FRM.QUEUE.hMem .BS K.FRMQUEUE.SIZE
|
||
FRM.QUEUE.State .BS K.FRMQUEUE.SIZE
|
||
FRM.QUEUE.Retry .BS K.FRMQUEUE.SIZE
|
||
*--------------------------------------
|
||
bFirstLoad .DA #0
|
||
DevFlags .BS 1
|
||
DYNPORT.LAST .BS 2
|
||
hDNSSocket1 .BS 1
|
||
hDNSSocket2 .BS 1
|
||
DNS.HostNameLen .BS 1
|
||
DNS.HostName .BS K.DNS.MAXLEN+1
|
||
DNS.TmpCache .BS S.DNSCACHE
|
||
ARP.TmpCache .BS S.ARP
|
||
TmpDWord .BS 4
|
||
TmpSocket .BS S.SOCKET
|
||
hFrame1 .BS 1
|
||
hSocket .BS 1
|
||
TmpOffset .BS 2
|
||
HST.DecStr .BS 4
|
||
HST.IP .BS 5
|
||
IP.CHECKSUM .BS 4
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE LIB/LIBTCPIP.S
|
||
ASM
|