A2osX/SBIN/NETWORKD.S.txt
2020-06-13 21:27:06 +02:00

364 lines
6.3 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF sbin/networkd
*--------------------------------------
LIB.MAX .EQ 4
DBG .EQ 1
*--------------------------------------
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/mli.i
.INB inc/mli.e.i
.INB inc/nic.i
.INB inc/eth.i
.INB inc/lib.net.i
*--------------------------------------
* Zero Page Segment, up to 32 bytes
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
pNETCFG .BS 2
pBuf .BS 2
hNetworkFile .BS 1
hLineBuf .BS 1
hFrameIn .BS 1
ZS.END .ED
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #S.PS.F.EVENT
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data SegmentSize
.DO DBG=1
.DA #128 Stack Size
.ELSE
.DA #64 Stack Size
.FIN
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.RUNNING .DA MSG.RUNNING
L.MSG.DEV.OK .DA MSG.DEV.OK
L.MSG.DEV.KO .DA MSG.DEV.KO
L.MSG.LIB .DA MSG.LIB
L.MSG.EXEC .DA MSG.EXEC
L.DEVNAME .DA DEVNAME
L.IOCTL .DA IOCTL
L.DCB.NIC .DA DCB.NIC
L.ETCNETWORK .DA ETCNETWORK
.DO DBG=1
L.MSG.DBG .DA MSG.DBG
.FIN
.DA 0
*--------------------------------------
CS.INIT lda DevID
bne .99
jsr CS.INIT.DEV
bcs .9
jsr CS.INIT.LIBS
bcs .9
jsr CS.INIT.CONF
.9 rts
.99 >LDYA L.MSG.RUNNING
>SYSCALL PutS
lda #0
sec
rts
*--------------------------------------
CS.INIT.DEV >PUSHBI 0
>LDYA L.DEVNAME
>SYSCALL open
bcc .8
inc DEVNAME+8
lda DEVNAME+8
cmp #'8'
bne CS.INIT.DEV
>LDYA L.MSG.DEV.KO
>SYSCALL PutS
lda #MLI.E.NODEV
sec
rts
.8 sta DevID
>PUSHW L.MSG.DEV.OK
>PUSHW L.DEVNAME
>PUSHBI 2
>SYSCALL PrintF
>LDYA L.DCB.NIC
>STYA IOCTL+S.IOCTL.BUFPTR
lda #S.IOCTL.STATCODE.GETDCB
sta IOCTL+S.IOCTL.STATCODE
>PUSHB DevID
>PUSHBI IOCTL.STATUS
>PUSHW L.IOCTL
>SYSCALL IOCTL
rts
*--------------------------------------
CS.INIT.LIBS lda LibCnt
.1 inc
>SYSCALL ArgV
bcs .8
phy
pha
>PUSHW L.MSG.LIB
pla
pha
>PUSHYA
>PUSHBI 2
>SYSCALL PrintF
pla
ply
>SYSCALL LoadLib
bcs CS.INIT.LIBS.9
ldy LibCnt
sta hLIBs,y
tay
ldx #LIBNET.GETCFG
jsr A2osX.LIBCALL
bcs CS.INIT.LIBS.9
>STYA pNETCFG
jsr CS.INIT.SETUP.NETCFG
>PUSHW pNETCFG
ldx LibCnt
ldy hLIBs,x
ldx #LIBNET.SETCFG
jsr A2osX.LIBCALL
bcs CS.INIT.LIBS.9
inc LibCnt
lda LibCnt
cmp #LIB.MAX
bne .1
.8 clc
CS.INIT.LIBS.9 rts
*--------------------------------------
CS.INIT.SETUP.NETCFG
lda DevID
ldy #S.NETCFG.DevID
sta (pNETCFG),y
iny S.NETCFG.DevFlags
lda DCB.NIC+S.DCB.NIC.FLAGS
sta (pNETCFG),y
ldx #5
ldy #S.NETCFG.MAC+5
.2 lda DCB.NIC+S.DCB.NIC.MAC,x
sta (pNETCFG),y
dey
dex
bpl .2
rts
*--------------------------------------
CS.INIT.CONF >LDYAI 64
>SYSCALL GetMem
bcs CS.INIT.LIBS.9
>STYA pBuf
stx hLineBuf
>PUSHW L.ETCNETWORK
>PUSHBI O.RDONLY+O.TEXT
>PUSHBI S.FI.T.TXT
>PUSHWZ
>SYSCALL FOpen
bcs .98
sta hNetworkFile
.1 >PUSHWI 64
>PUSHW pBuf
lda hNetworkFile
>SYSCALL fgets
bcs .80
>PUSHW L.MSG.EXEC
>PUSHW pBuf
>PUSHBI 2
>SYSCALL PrintF
>PUSHW pBuf
>PUSHBI 0 S.PS.F.HOLD+S.PS.F.NOHUP
>SYSCALL execL
bra .1
.98 pha
jsr .81
pla
sec
rts
.80 lda hNetworkFile
>SYSCALL FClose
.81 lda hLineBuf
>SYSCALL FreeMem
* clc
rts
*--------------------------------------
CS.RUN >PUSHB DevID
>PUSHBI IOCTL.READ
>PUSHW L.IOCTL
>SYSCALL IOCTL
bcs .8 No Frame
sta hFrameIn
.DO DBG=1
>SYSCALL GetMemPtr
>STYA pBuf
lda (pBuf)
cmp #$ff
beq .23
cmp #1
beq .23
>PUSHW L.MSG.DBG
ldy #0
.22 >PUSHB (pBuf),y
iny
cpy #50
bne .22
>PUSHBI 50
>SYSCALL printf
.23 .FIN
ldx #0
.1 ldy hLIBs,x
beq .2
>PUSHW L.IOCTL
lda hFrameIn
phx
ldx #LIBNET.INCOMING
jsr A2osX.LIBCALL
plx
bcc CS.RUN
inx
bra .1
.2 lda hFrameIn
>SYSCALL FreeMem
jmp CS.RUN
.8 clc
rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9
ldx #0
.1 ldy hLIBs,x
beq .9
phx
ldx #LIBNET.PULSE
lda (pEvent)
jsr A2osX.LIBCALL
plx
inx
bra .1
.9 sec never discard TIME event
rts
*--------------------------------------
CS.QUIT ldx #0
.1 lda hLIBs,x
beq .7
phx
>SYSCALL UnLoadLib
plx
inx
bra .1
.7 lda DevID
beq .8
>PUSHA
>PUSHBI IOCTL.CLOSE
>PUSHWZ
>SYSCALL IOCTL
.8 clc
rts
*--------------------------------------
CS.END
*--------------------------------------
MSG.RUNNING .AZ "NETWORKD:Already loaded, exiting."
MSG.DEV.KO .AZ "NETWORKD:No Device Found, exiting."
MSG.DEV.OK .AZ "NETWORKD:Bound To Device : %s\r\n"
MSG.LIB .AZ "NETWORKD:Loading %s ...\r\n"
MSG.EXEC .AZ "NETWORKD:Running %s ...\r\n"
ETCNETWORK .AZ "${BOOT}etc/network"
.DO DBG=1
MSG.DBG .AS "FRM %h%h%h%h%h%h.%h%h%h%h%h%h.%h%h\r\n"
.AS " %h%h.%h%h%h%h%h%h.%h%h%h%h %d.%d.%d.%d %d.%d.%d.%d\r\n"
.AZ " %h%h%h%h%h%h%h%h.%h%h%h%h%h%h%h%h\r\n"
.FIN
*--------------------------------------
DevID .BS 1
LibCnt .BS 1
hLIBs .BS LIB.MAX+1 for ending 0 if MAX libs
DEVNAME .AZ "/dev/eth1"
IOCTL .BS S.IOCTL
DCB.NIC .BS S.DCB.NIC
*--------------------------------------
.DUMMY
.OR 0
DS.START
DS.END .ED
*--------------------------------------
MAN
SAVE usr/src/sbin/networkd.s
ASM