A2osX/SYS/KERNEL.S.UNISTD.txt
2020-07-18 16:18:10 +02:00

335 lines
6.8 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
*/--------------------------------------
* # open
* ## C
* `hFD open(const char *pathname, short int flags);`
* ## ASM
* **In:**
* `>PUSHB flags`
* `>LDYA pathname`
* `>SYSCALL open`
* ## RETURN VALUE
* A = hFD
* REG File created on ProDOS : T=TXT,X=$0000
*\--------------------------------------
.DUMMY
.OR ZPTMP+20 7 Bytes
IO.Open.FLAGS .BS 1
IO.Open.TYPE .BS 1
IO.Open.AUXTYPE .BS 2
IO.hFD .BS 1
.ED
*--------------------------------------
K.Open jsr PFT.YAToMLIPATH
>PULLB IO.Open.FLAGS
lda #S.FI.T.TXT
sta IO.Open.TYPE
stz IO.Open.AUXTYPE
stz IO.Open.AUXTYPE+1
*--------------------------------------
UNISTD.Open ldx #5 /DEV/
cpx K.MLI.PATH
bcs .99
.1 lda K.MLI.PATH,x
cmp DEV.FIFO-1,x
bne .99
dex
bne .1
*--------------------------------------
* /DEV/xxxxxx (CDEV,BDEV,DSOCK,SSOCK,PIPE)
*--------------------------------------
>LDYAI K.MLI.PATH+6 skip $/DEV/
jsr K.GetDevByName
bcc .7
ldx #2
.10 lda Nod.Table.hPath-2,x
beq .3
jsr K.GetMemPtr
>STYA ZPPtr1
ldy #0
.2 lda (ZPPtr1),y
iny
cmp K.MLI.PATH,y
bne .3
cmp #0 end of string ?
bne .2
lda Nod.Table.hFD-2,x return hFD
jsr UNISTD.GetPFD
bra .71
.3 inx
cpx #K.NOD.MAX+2
bne .10
lda #MLI.E.NODEV
* sec
rts no OF found
*--------------------------------------
.7 stx IO.hFD
>STYA pFD
.71 lda (pFD) #S.FD.T
tax
jmp (.8-2,x)
.8
* .DA STDIO.IOERR REG
.DA STDIO.IOERR DIR
.DA IO.OPEN.CDEV
.DA IO.OPEN.BDEV
.DA STDIO.IOERR LNK
.DA IO.OPEN.DSOCK
.DA IO.OPEN.SSOCK
.DA IO.OPEN.PIPE
.99 jmp IO.OPEN.REG
*/--------------------------------------
* # close
* ## C
* `int close(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>SYSCALL close`
*\--------------------------------------
K.Close jsr UNISTD.GetPFD
UNISTD.Close lda (pFD) #S.FD.T
tax
jmp (.1,x)
.1 .DA IO.CLOSE.REG
.DA IO.CLOSE.DIR
.DA IO.CLOSE.CDEV
.DA IO.CLOSE.BDEV
.DA STDIO.IOERR LNK
.DA IO.CLOSE.DSOCK
.DA IO.CLOSE.SSOCK
.DA IO.CLOSE.PIPE
*/--------------------------------------
* # read
* ## C
* `int read(hFD fd, void *buf, int count);`
* ## ASM
* **In:**
* `>PUSHWI count`
* `>PUSHW buf`
* `lda fd`
* `>SYSCALL read`
* ## RETURN VALUE
* CC: Y,A = bytes read
* CS: A = EC
*\--------------------------------------
K.Read jsr UNISTD.GetPFD
UNISTD.Read lda (pFD) #S.FD.T
tax
jmp (.1,x)
.1 .DA IO.READ.REG
.DA STDIO.IOERR DIR
.DA IO.READ.CDEV
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
.DA IO.READ.SSOCK
.DA IO.READ.PIPE
*/--------------------------------------
* # write
* ## C
* `int write(hFD fd, const void *buf, int count);`
* ## ASM
* **In:**
* `>PUSHWI count`
* `>PUSHW buf`
* `lda fd`
* `>SYSCALL write`
* ## RETURN VALUE
* CC: Y,A = bytes written
* CS: A = EC
*\--------------------------------------
K.Write jsr UNISTD.GetPFD
UNISTD.Write lda (pFD) #S.FD.T
tax
jmp (.1,x)
.1 .DA IO.WRITE.REG
.DA STDIO.IOERR DIR
.DA IO.WRITE.CDEV
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
.DA IO.WRITE.SSOCK
.DA IO.WRITE.PIPE
*--------------------------------------
UNISTD.GetPFD sta IO.hFD
jsr K.GetMemPtr
>STYA pFD
rts
*--------------------------------------
IO.OPEN.CDEV
IO.OPEN.BDEV jsr SHARED.GetPDrv
ldx #IOCTL.OPEN
lda IO.hFD
jsr SHARED.pDrvJmp
bcs IO.WRITE.CDEV.RTS
*--------------------------------------
IO.OPEN.DSOCK
*--------------------------------------
IO.OPEN.SSOCK
lda IO.hFD
*--------------------------------------
IO.CLOSE.CDEV
IO.CLOSE.BDEV
clc
rts
*--------------------------------------
IO.READ.CDEV ldx #IOCTL.READ
.HS 2C BIT ABS
*--------------------------------------
IO.WRITE.CDEV ldx #IOCTL.WRITE
>PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
jsr SHARED.GetPDrv
>LDYAI K.S.IOCTL
jsr SHARED.pDrvJmp
bcs .9
>LDYA K.S.IOCTL+S.IOCTL.BYTECNT
.9
IO.WRITE.CDEV.RTS
rts
*--------------------------------------
IO.CLOSE.DSOCK
IO.CLOSE.SSOCK
ldy #S.FD.SSOCK.CLOSE
.HS 2C BIT ABS
*--------------------------------------
IO.EOF.SSOCK ldy #S.FD.SSOCK.EOF
.HS 2C BIT ABS
*--------------------------------------
IO.READ.SSOCK ldy #S.FD.SSOCK.READ
.HS 2C BIT ABS
*--------------------------------------
IO.WRITE.SSOCK ldy #S.FD.SSOCK.WRITE
lda (pFD),y
tax Function Offset in LIB
ldy #S.FD.SSOCK.IOHANDLER
lda (pFD),y
jsr K.GetMemPtr
>STYA .1+1
lda IO.hFD
.1 jmp $FFFF SELF MODIFIED
*--------------------------------------
IO.EOF.CDEV lda #S.IOCTL.STATCODE.EOF
jmp SHARED.GetDevStatus
*--------------------------------------
* X = 0 > REG
* X = 1 > DIR
* X = 2 > PIPE
*--------------------------------------
IO.MkFD stx .8+1
ldy IO.MkFD.Y,x
lda #0
ldx #S.MEM.F.INIT0+S.MEM.F.FD
jsr MEM.GetMem.YAX
bcs .9
>STYA pFD
stx IO.hFD
.8 ldx #$ff SELF MODIFIED
lda IO.MkFD.T,x
sta (pFD) X = hFD, A = T
* clc
.9 rts
IO.MkFD.Y .DA #S.FD.REG,#S.FD.DIR,#S.FD.PIPE
IO.MkFD.T .DA #S.FD.T.REG,#S.FD.T.DIR,#S.FD.T.PIPE
*--------------------------------------
IO.CLOSE.NOD ldx #2
lda IO.hFD
.1 cmp Nod.Table.hFD-2,x
bne .2
stz Nod.Table.hFD-2,x
lda Nod.Table.hPath-2,x
stz Nod.Table.hPath-2,x
jmp K.FreeMem
.2 inx
cpx #K.Nod.MAX+2
bne .1
lda #E.INVH
* sec
rts
*/--------------------------------------
* # ChOwn
* ## C
* `short int chown(const char *pathname, short int owner, short int group);`
* ## ASM
* **In:**
* `>PUSHW pathname`
* `>PUSHB owner`
* `>PUSHB group`
* `>SYSCALL chown`
* ## RETURN VALUE
*\--------------------------------------
K.ChOwn jsr PFT.CheckPath2
bcs K.ChOwn.RET4
stz K.MLI.PARAMS+3+S.FIEX.ACL read mode
>MLICALL MLIACL
bcs K.ChOwn.RET4
lda (pStack)
bmi .1
sta K.MLI.PARAMS+3+S.FIEX.ACL.GID
.1
ldy #1
lda (pStack),y
bmi .2
sta K.MLI.PARAMS+3+S.FIEX.ACL.UID
.2 lda #$57 write mode
sta K.MLI.PARAMS+3+S.FIEX.ACL
>MLICALL MLIACL
K.ChOwn.RET4 >RET 4
*--------------------------------------
SHARED.GetPDrv ldy #S.FD.DEV.DRVPTR
lda (pFD),y
sta pDRV
iny
lda (pFD),y
sta pDRV+1
rts
*--------------------------------------
DEV.FIFO .AS "/dev/fifo" STAT,UNISTD
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.UNISTD
LOAD USR/SRC/SYS/KERNEL.S
ASM