A2osX/SYS/KERNEL.S.IO.txt

305 lines
6.1 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...
2018-08-08 15:13:37 +00:00
ldx #5 $/DEV/
2018-07-11 15:13:29 +00:00
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-08-08 15:13:37 +00:00
K.Open.DEV >LDYAI K.MLI.PATH+6 skip $/DEV/
2018-07-11 15:13:29 +00:00
jsr K.GetDevByName
bcs .9
>STYA pFD
2018-08-08 15:13:37 +00:00
stx .1+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
2018-08-08 15:13:37 +00:00
sta .2+1
2018-07-12 15:20:39 +00:00
iny
lda (pFD),y
2018-08-08 15:13:37 +00:00
sta .2+2
2018-07-12 15:20:39 +00:00
>PULLA get flags
2018-08-08 15:13:37 +00:00
.1 lda #$ff SELF MODIFIED pass A=DEVID To Driver
2018-07-12 15:20:39 +00:00
ldx #IOCTL.OPEN
2018-08-08 15:13:37 +00:00
.2 jsr $ffff SELF MODIFIED pDRV
2018-07-12 15:20:39 +00:00
bcs .99
2018-08-08 15:13:37 +00:00
ldx .1+1
lda Dev.Table.hFD,x
2018-07-12 15:20:39 +00:00
.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-08-08 15:13:37 +00:00
bra *
2018-07-12 15:20:39 +00:00
lda (pStack)
* sta K.S.IOCTL
>RET 1
*--------------------------------------
2018-08-08 15:13:37 +00:00
* int close(short int hFD);
2018-07-09 15:25:38 +00:00
*--------------------------------------
2018-07-11 15:13:29 +00:00
K.Close jsr K.GetMemPtr
2018-08-08 15:13:37 +00:00
bcs .9
2018-07-11 15:13:29 +00:00
>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-08-08 15:13:37 +00:00
.9 lda #MLI.E.NODEV
sec
rts
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);`
*\--------------------------------------
2018-08-08 15:13:37 +00:00
K.Read jsr K.GetMemPtr
bcs K.Write.9
2018-07-18 15:30:42 +00:00
2018-08-08 15:13:37 +00:00
>STYA pFD
2018-07-18 15:30:42 +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.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
2018-07-10 15:33:13 +00:00
*--------------------------------------
* int write(int fd, const void *buf, size_t count);
*--------------------------------------
2018-08-08 15:13:37 +00:00
K.Write jsr K.GetMemPtr
2018-07-13 14:38:24 +00:00
bcs K.Write.9
2018-07-11 15:13:29 +00:00
2018-08-08 15:13:37 +00:00
>STYA pFD
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-08-08 15:13:37 +00:00
K.Write.9 lda #MLI.E.NODEV
>RET 4
2018-06-19 05:55:12 +00:00
*--------------------------------------
2018-08-08 15:13:37 +00:00
IO.READ.REG ldx #MLIREAD
.HS 2C BIT ABS
2018-07-24 16:00:24 +00:00
*--------------------------------------
2018-08-08 15:13:37 +00:00
IO.WRITE.REG ldx #MLIWRITE
2018-07-10 15:33:13 +00:00
ldy #S.FD.REG.REF
2018-07-24 16:00:24 +00:00
lda (pFD),y
2018-08-08 15:13:37 +00:00
sta K.MLI.PARAMS+1
>LDYA K.S.IOCTL+S.IOCTL.BUFPTR
>STYA K.MLI.PARAMS+2
>LDYA K.S.IOCTL+S.IOCTL.BYTECNT
>STYA K.MLI.PARAMS+4
lda #4 Param Count = 4 for MLIREAD & MLIWRITE
jsr GP.MLICall
rts
2018-06-19 05:55:12 +00:00
*--------------------------------------
2018-07-24 16:00:24 +00:00
IO.READ.CDEV ldx #IOCTL.READ
.HS 2C BIT ABS
*--------------------------------------
IO.WRITE.CDEV ldx #IOCTL.WRITE
ldy #S.FD.DEV.DRVPTR
2018-07-10 15:33:13 +00:00
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-07-24 16:00:24 +00:00
2018-06-19 05:55:12 +00:00
.1 jmp $ffff
*--------------------------------------
2018-07-24 16:00:24 +00:00
IO.WRITE.SSOCK ldy #S.FD.SSOCK.WRITE
.HS 2C BIT ABS
*--------------------------------------
IO.READ.SSOCK ldy #S.FD.SSOCK.READ
lda (pFD),y
tax Function Offset in LIB
ldy #S.FD.HANDLER
lda (pFD),y
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
.1 jmp $ffff
*--------------------------------------
2018-07-24 16:00:24 +00:00
IO.READ.FIFO
clc
rts
*--------------------------------------
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-08-08 15:13:37 +00:00
* `int ioctl(short int hFD, 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`
2018-08-08 15:13:37 +00:00
* `lda hFD`
2018-07-11 15:13:29 +00:00
* `>SYSCALL IOCTL`
* **Out:**
* Y,A = ...
*\--------------------------------------
2018-08-08 15:13:37 +00:00
K.IOCTL jsr K.GetMemPtr
2018-07-19 15:33:55 +00:00
bcs .9
2018-07-11 15:13:29 +00:00
2018-08-08 15:13:37 +00:00
>STYA pFD
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-08-08 15:13:37 +00:00
.9 lda #MLI.E.NODEV
>RET 3
2018-07-11 15:13:29 +00:00
*/--------------------------------------
* # pipe
* ## C
* `int pipe(int pipefd[2]);`
* ## ASM
* **In:**
2018-08-08 15:13:37 +00:00
*\--------------------------------------
K.Pipe
.9 sec
2018-07-12 15:20:39 +00:00
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