A2osX/SYS/KERNEL.S.IO.txt

301 lines
6.0 KiB
Plaintext
Raw Normal View History

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
2018-07-11 15:13:29 +00:00
*/--------------------------------------
* # open
* ## C
* `int open(const char *pathname, int flags);`
* ## ASM
* **In:**
* `>PUSHB flags`
* `>LDYA pathname`
* `>SYSCALL open`
* **Out:**
* A = hFD
* note : if file is created on ProDOS : T=TXT,X=$0000
*\--------------------------------------
K.Open jsr PFT.CheckPathYA check if not /mnt
K.Open.I jsr IO.SetMLIPathYA local pathname...
ldx #5 /DEV/
cpx K.MLI.PATH
2018-07-12 15:20:39 +00:00
bcs K.Open.REG
2018-07-11 15:13:29 +00:00
.1 lda K.MLI.PATH,x
cmp IO.DEVDIR,x
bne K.Open.REG
dex
bne .1
2018-07-12 15:20:39 +00:00
K.Open.DEV ldy #K.MLI.PATH+6 skip L/DEV/
lda /K.MLI.PATH+6
2018-07-11 15:13:29 +00:00
jsr K.GetDevByName
bcs .9
>STYA pFD
2018-07-12 15:20:39 +00:00
stx .8+1 DEVID
2018-07-11 15:13:29 +00:00
2018-07-12 15:20:39 +00:00
ldy #S.FD.DEV.DRVPTR
lda (pFD),y
sta .1+1
iny
lda (pFD),y
sta .1+2
>PULLA get flags
2018-07-17 15:45:59 +00:00
lda .8+1 pass A=DEVID To Driver
2018-07-12 15:20:39 +00:00
ldx #IOCTL.OPEN
.1 jsr $ffff SELF MODIFIED
bcs .99
.8 lda #$ff SELF MODIFIED
.99 rts
2018-07-11 15:13:29 +00:00
2018-07-12 15:20:39 +00:00
.9 >RET 1 discard flags
2018-07-11 15:13:29 +00:00
K.Open.REG >LDYAI K.MLI.PATH
>STYA K.MLI.PARAMS+1
2018-07-12 15:20:39 +00:00
lda (pStack)
* sta K.S.IOCTL
>RET 1
*--------------------------------------
2018-07-11 15:13:29 +00:00
* int close(int fd);
2018-07-09 15:25:38 +00:00
*--------------------------------------
2018-07-11 15:13:29 +00:00
K.Close jsr K.GetMemPtr
>STYA pFD
lda (pFD) #S.FD.T
tax
jmp (.1,x)
.1 .DA IO.CLOSE.REG
.DA STDIO.IOERR DIR
.DA IO.CLOSE.CDEV
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
.DA IO.CLOSE.SSOCK
.DA IO.CLOSE.FIFO
2018-07-10 15:33:13 +00:00
*--------------------------------------
2018-07-11 15:13:29 +00:00
IO.CLOSE.REG
2018-07-10 15:33:13 +00:00
*--------------------------------------
2018-07-11 15:13:29 +00:00
IO.CLOSE.CDEV
*--------------------------------------
IO.CLOSE.SSOCK
*--------------------------------------
2018-07-18 15:30:42 +00:00
IO.CLOSE.FIFO clc
rts
*/--------------------------------------
* # read
* ## C
* `int read(int fd, void *buf, size_t count);`
*\--------------------------------------
K.Read jsr IO.SELECT
bcs K.Read.9
>PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
2018-07-19 15:33:55 +00:00
IO.Read.I lda (pFD) #S.FD.T
2018-07-18 15:30:42 +00:00
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.FIFO
K.Read.9 >RET 4
2018-07-10 15:33:13 +00:00
*--------------------------------------
2018-07-18 15:30:42 +00:00
IO.READ.REG
clc
rts
2018-06-19 15:08:22 +00:00
*--------------------------------------
2018-07-18 15:30:42 +00:00
IO.READ.CDEV ldy #S.FD.DEV.DRVPTR
lda (pFD),y
sta .1+1
iny
lda (pFD),y
sta .1+2
>LDYAI K.S.IOCTL
ldx #IOCTL.READ
.1 jmp $ffff
*--------------------------------------
IO.READ.SSOCK
*--------------------------------------
IO.READ.FIFO
clc
rts
2018-07-10 15:33:13 +00:00
*--------------------------------------
* int write(int fd, const void *buf, size_t count);
*--------------------------------------
2018-07-13 14:38:24 +00:00
K.Write jsr IO.SELECT
bcs K.Write.9
2018-07-11 15:13:29 +00:00
2018-07-13 14:38:24 +00:00
>PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
2018-07-19 15:33:55 +00:00
IO.Write.I lda (pFD) #S.FD.T
2018-06-19 05:55:12 +00:00
tax
jmp (.1,x)
2018-07-11 15:13:29 +00:00
2018-06-19 15:08:22 +00:00
.1 .DA IO.WRITE.REG
2018-06-19 05:55:12 +00:00
.DA STDIO.IOERR DIR
2018-06-19 15:08:22 +00:00
.DA IO.WRITE.CDEV
2018-06-19 05:55:12 +00:00
.DA STDIO.IOERR BDEV
.DA STDIO.IOERR LNK
.DA STDIO.IOERR DSOCK
2018-06-19 15:08:22 +00:00
.DA IO.WRITE.SSOCK
.DA IO.WRITE.FIFO
2018-07-18 15:30:42 +00:00
2018-07-13 14:38:24 +00:00
K.Write.9 >RET 4
2018-06-19 05:55:12 +00:00
*--------------------------------------
2018-06-19 15:08:22 +00:00
IO.WRITE.REG >PUSHW K.S.IOCTL+S.IOCTL.BUFPTR
>PUSHW K.S.IOCTL+S.IOCTL.BYTECNT
2018-07-10 15:33:13 +00:00
ldy #S.FD.REG.REF
>PUSHB (pFD),y
2018-06-19 05:55:12 +00:00
jmp K.FWrite
*--------------------------------------
2018-07-10 15:33:13 +00:00
IO.WRITE.CDEV ldy #S.FD.DEV.DRVPTR
lda (pFD),y
2018-06-19 05:55:12 +00:00
sta .1+1
iny
2018-07-10 15:33:13 +00:00
lda (pFD),y
2018-06-19 05:55:12 +00:00
sta .1+2
2018-07-13 14:38:24 +00:00
>LDYAI K.S.IOCTL
2018-06-19 05:55:12 +00:00
ldx #IOCTL.WRITE
.1 jmp $ffff
*--------------------------------------
2018-07-10 15:33:13 +00:00
IO.WRITE.SSOCK lda (pFD) #S.FD.HANDLER
2018-06-21 15:12:10 +00:00
jsr K.GetMemPtr
2018-06-19 05:55:12 +00:00
>STYA .1
2018-07-10 15:33:13 +00:00
ldy #S.FD.SSOCK.HSKT
>PUSHB (pFD),y
2018-06-19 05:55:12 +00:00
>PUSHB K.IOBuf
2018-07-10 15:33:13 +00:00
ldy #S.FD.SSOCK.WRITE
lda (pFD),y
2018-06-19 05:55:12 +00:00
tax Function Offset for write
.1 jmp $ffff
*--------------------------------------
2018-07-10 15:33:13 +00:00
IO.WRITE.FIFO ldy #S.FD.FIFO.S
lda (pFD),y
2018-06-19 05:55:12 +00:00
beq .9 Remote PS did not opened yet the pipe
2018-07-10 15:33:13 +00:00
cmp #S.FD.FIFO.S.Closed
2018-06-19 05:55:12 +00:00
beq .99 Remote PS closed the Pipe
2018-07-10 15:33:13 +00:00
ldy #S.FD.FIFO.hMem
lda (pFD),y
2018-06-21 15:12:10 +00:00
jsr K.GetMemPtr
2018-06-19 05:55:12 +00:00
>STYA .1+2
2018-07-10 15:33:13 +00:00
ldy #S.FD.FIFO.Head
lda (pFD),y
2018-06-19 05:55:12 +00:00
inc
2018-07-10 15:33:13 +00:00
dey #S.FD.FIFO.Tail
cmp (pFD),y
2018-06-19 05:55:12 +00:00
beq .9 FIFO is full
iny
2018-07-10 15:33:13 +00:00
sta (pFD),y
2018-06-19 05:55:12 +00:00
tay
lda K.IOBuf
.1 sta $ffff,y
clc
rts
.9 lda #MLI.E.VOLFULL
.HS 2C bit abs
.99 lda #MLI.E.EOF
sec
rts
2018-07-11 15:13:29 +00:00
*/--------------------------------------
* # IOCTL
* ## C
2018-07-19 15:33:55 +00:00
* `int ioctl(int devid, int request, void * param );`
2018-07-11 15:13:29 +00:00
* ## ASM
* **In:**
* `PUSHWI param`
2018-07-19 15:33:55 +00:00
* `PUSHBI request`
* `lda devid`
2018-07-11 15:13:29 +00:00
* `>SYSCALL IOCTL`
* **Out:**
* Y,A = ...
*\--------------------------------------
2018-07-19 15:33:55 +00:00
K.IOCTL jsr IO.SELECT
bcs .9
2018-07-11 15:13:29 +00:00
2018-07-18 06:02:43 +00:00
ldy #S.FD.DEV.DRVPTR
lda (pFD),y
sta .8+1
iny
lda (pFD),y
sta .8+2
2018-07-19 15:33:55 +00:00
>PULLA
tax request
>PULLYA param
2018-07-18 06:02:43 +00:00
.8 jmp $ffff SELF MODIFIED x = op
2018-07-11 15:13:29 +00:00
2018-07-19 15:33:55 +00:00
.9 >RET 3
2018-07-11 15:13:29 +00:00
*/--------------------------------------
* # pipe
* ## C
* `int pipe(int pipefd[2]);`
* ## ASM
* **In:**
*\--------------------------------------
2018-07-12 15:20:39 +00:00
IO.SELECT cmp DevMgr.DevCnt
bcs .9
tax
ldy FD.Table.PTRLO,x
lda FD.Table.PTRHI,x
2018-07-10 15:33:13 +00:00
>STYA pFD
rts
2018-07-12 15:20:39 +00:00
.9 lda #MLI.E.NODEV
rts
2018-07-10 15:33:13 +00:00
*--------------------------------------
2018-07-11 15:13:29 +00:00
IO.PullMLIPath >PULLYA
IO.SetMLIPathYA >STYA .1+1
ldx #0
.1 lda $ffff,x Self Modified
beq .8
inx
sta K.MLI.PATH,x
cpx #MLI.MAXPATH
bne .1
.8 stx K.MLI.PATH
inx
stz K.MLI.PATH,x
rts
*--------------------------------------
IO.DEVDIR >PSTR "/DEV/"
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.IO
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM