Kernel 0.9.2

This commit is contained in:
Rémy GIBERT 2018-10-04 08:13:44 +02:00
parent e9e8508c2e
commit 44ca048591
8 changed files with 219 additions and 134 deletions

View File

@ -565,7 +565,7 @@ CS : error
A = EC
# MkNod
return a hFile for a given file descriptor.
Create a special or ordinary file.
(CDEV, BDEV, DSOCKS, SSOCK, PIPE)
## C
@ -736,8 +736,13 @@ CC = success
# GetChar
Get char from StdIn
## C
`int getchar ();`
## ASM
**In:**
none.
`>SYSCALL getchar`
**Out:**
CC = success
A = char
@ -746,11 +751,12 @@ Get char from StdIn
Get char from Node
## C
`int getc ( FILE * stream );`
`int getc ( hFILE stream );`
## ASM
**In:**
A = hNODE
`lda stream`
`>SYSCALL getc`
**Out:**
CC = success
A = char
@ -794,20 +800,21 @@ Open a file
`>PUSHWI auxtype`
`>PUSHBI ftype`
`>PUSHBI mode`
+ SYS.FOpen.R : if R and exists -> ERROR
+ SYS.FOpen.W : if W and exists -> CREATE
+ SYS.FOpen.A : Append
+ SYS.FOpen.T : Open/Append in Text mode
+ SYS.FOpen.X : Create if not exists
http://man7.org/linux/man-pages/man3/fopen.3.html
r = O_RDONLY
w = O_WRONLY | O_CREAT | O_TRUNC
a = O_WRONLY | O_CREAT | O_APPEND
r+ = O_RDWR
w+ = O_RDWR | O_CREAT | O_TRUNC
a+ = O_RDWR | O_CREAT | O_APPEND
*
TODO: mode="w+t=TYP,x=AUXTYPE"
+ O.RDONLY : if R and exists -> ERROR
+ O.WRONLY : if W and exists -> CREATE
+ O.TRUNC : Reset Size To 0
+ O.APPEND : Append
+ O.TEXT : Open/Append in Text mode
+ O.CREATE : Create if not exists
TODO: mode="w+,t=TYP,x=AUXTYPE"
+ r = O_RDONLY
+ r+ = O_RDWR
+ w = O_WRONLY | O_CREAT | O_TRUNC
+ w+ = O_RDWR | O_CREAT | O_TRUNC
+ a = O_WRONLY | O_CREAT | O_APPEND
+ a+ = O_RDWR | O_CREAT | O_APPEND
+ ,t=123 or t=$ff or t=TXT
+ ,x=12345 or x=$ffff
`>LDYAI filename`
**Out:**
CC : A = hFILE
@ -821,7 +828,8 @@ int fclose ( hFILE stream );
## ASM
**In:**
A = hFILE
`lda stream`
`>SYSCALL fclose`
**Out:**
# FRead
@ -830,7 +838,7 @@ Read bytes from file
**In:**
`>PUSHWI count`
`>PUSHW ptr`
`lda hFILE`
`lda stream`
`>SYSCALL fread`
**Out:**
Y,A = Bytes Read
@ -845,7 +853,7 @@ Write bytes to file
**In:**
`>PUSHWI count`
`>PUSHW ptr`
`lda hFILE`
`lda stream`
`>SYSCALL fwrite`
**Out:**
Y,A = Bytes Written
@ -857,7 +865,8 @@ int fflush(hFILE stream);
## ASM
**In:**
A = hFILE
`lda stream`
`>SYSCALL fflush`
# FSeek
Set the file-position indicator for hFILE
@ -874,12 +883,18 @@ Set the file-position indicator for hFILE
# FEOF
Test the end-of-file indicator for hFILE
## C
`int feof(hFILE stream);`
## ASM
**In:**
A = hFILE
`lda stream`
`>SYSCALL feof`
**Out:**
CC :
A=0 EOF
A =0 NOT EOF
A=0 EOF
A =0 NOT EOF
CS :
# FTell
@ -896,6 +911,16 @@ Return the current value of the file-position indicator
On stack (long)
# Remove
Remove a file or directory
## C
int remove(const char *pathname);
## ASM
**In:**
`>LDYA pathname`
`>SYSCALL remove`
**Out:**
# Rename
Rename a file

View File

@ -20,7 +20,7 @@
PUSHW PTR to MAC
PUSHW PTR to IP
# ARP.GetCAche
# ARP.GetCache
Return a Ptr to ARP Cache Table
**In:**
**Out:**
@ -52,59 +52,89 @@
**Out:**
Y,A = PTR to DNS.CACHE
# SKT.New
# SKT.Socket
Create a new socket
## C
`hSOCKET skt.new(void *template);`
`hFD socket(short int type, short int protocol);`
## ASM
**In:**
`>PUSHW template`
`>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.New`
`>PUSHB protocol`
`lda type`
`>LIBCALL hLIBTCPIP,LIBTCPIP.socket`
**Out:**
CC: A = hSOCKET
CS: A = EC
# SKT.Close
Close socket
**In:**
A = hSocket
**Out:**
# SKT.Get
Get Ptr to socket
**In:**
A = hSocket
**Out:**
Y,A = pS.SOCKET
# SKT.GetTable
Get socket table
**In:**
**Out:**
Y,A = pS.SOCKET
# SKT.Accept
Check for an incoming connection
**In:**
A = hListeningSocket
**Out:**
A = hSocket
# SKT.MkNod
# SKT.bind
bind a name to a socket
## C
`hFD skt.mknod(hSOCKET s);`
`int bind(hFD fd, const struct sockaddr *addr);`
## ASM
**In:**
`lda s`
`>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.MkNod`
`>PUSHW addr`
`lda fd`
`>LIBCALL hLIBTCPIP,LIBTCPIP.socket`
**Out:**
CC: A = hFD
CC: A = hSOCKET
CS: A = EC
# SKT.connect
Iinitiate a connection on a socket
## C
`int connect(hFD fd, const struct sockaddr *addr);`
## ASM
**In:**
`>PUSHW addr`
`lda fd`
`>LIBCALL hLIBTCPIP,LIBTCPIP.socket`
**Out:**
CC: A = hSOCKET
CS: A = EC
# SKT.listen
Listen for connections on a socket
## C
`int listen(hFD fd);`
## ASM
**In:**
`lda fd`
`>LIBCALL hLIBTCPIP,LIBTCPIP.listen`
**Out:**
CS: A = EC
# SKT.Accept
Accept a connection on a socket
## C
`hFD Accept(hFD fd);`
## ASM
**In:**
`lda fd`
`>LIBCALL hLIBTCPIP,LIBTCPIP.accept`
**Out:**
A = hSocket
# SKT.Close
Close socket
## C
`int close(int fd);`
## ASM
**In:**
`lda fd`
`>LIBCALL hLIBTCPIP,LIBTCPIP.close`
**Out:**
# SKT.Read (STREAM)
## C
@ -135,19 +165,32 @@ CS: A = EC
CC: Y,A = bytes written
CS: A = EC
# SKT.Rcvd (DGRAM,RAW)
**In:**
A = hSocket
**Out:**
A = hFrame
# SKT.Recv (RAW,DGRAM,SEQPACKET)
# SKT.Send (DGRAM,RAW)
## C
`int skt.send(hFD fd, const void *buf, int count);`
# SKT.RecvFrom (RAW,DGRAM,SEQPACKET)
hMem recv(hFD fd);
hMem recvfrom(hFD fd, struct sockaddr *addr);
## ASM
**In:**
`>PUSHW addr` (RecvFrom)
`lda fd`
`>LIBCALL hLIBTCPIP,LIBTCPIP.skt.Recv`
**Out:**
CC: A = hMem
CS: A = EC
# SKT.Send (RAW,DGRAM,SEQPACKET)
# SKT.SendTo (RAW,DGRAM,SEQPACKET)
## C
`int skt.send(hFD fd, const void *buf, int count);`
`int skt.sendto(hFD fd, const void *buf, int count, const struct sockaddr *addr);`
## ASM
**In:**
`>PUSHW addr` (SendTo)
`>PUSHWI count`
`>PUSHW buf`
`lda fd`
@ -155,3 +198,14 @@ CS: A = EC
**Out:**
CC: Y,A = bytes written
CS: A = EC
# SKT.GetTable
Get socket table
## C
`void * skt.gettable();`
## ASM
**In:**
`>LIBCALL hLIBTCPIP,LIBTCPIP.skt.GetTable`
**Out:**

Binary file not shown.

Binary file not shown.

View File

@ -74,6 +74,17 @@ A2osX.S.DISABLE .EQ $FF
*--------------------------------------
* A2osX.SYSCALL Constants
*--------------------------------------
C.EOF .EQ 4
C.ENQ .EQ 5
C.BS .EQ 8
C.LF .EQ 10
C.FF .EQ 12
C.CR .EQ 13
C.FS .EQ 21
C.ESC .EQ 27
C.SPACE .EQ 32
C.DEL .EQ 127
*--------------------------------------
AF.LOCAL .EQ 0
AF.INET .EQ 2
AF.APPLETALK .EQ 4
@ -300,17 +311,6 @@ S.MSTAT .EQ 24
*--------------------------------------
* IOCTL device API
*--------------------------------------
C.EOF .EQ 4
C.ENQ .EQ 5
C.BS .EQ 8
C.LF .EQ 10
C.FF .EQ 12
C.CR .EQ 13
C.FS .EQ 21
C.ESC .EQ 27
C.SPACE .EQ 32
C.DEL .EQ 127
*--------------------------------------
DEVID.NULL .EQ 0
DEVID.SYS .EQ 1
*--------------------------------------

View File

@ -293,7 +293,7 @@ PS0.Init >LDYAI CORE.S.PS0 Select Process 0 (Kernel)
>PUSHBI 0
>LDYAI DEV.SYS
>SYSCALL open
>SYSCALL fopen
bcs .9
ldy #S.PS.hStdIn

View File

@ -125,9 +125,6 @@ IO.CLOSE.PIPE clc
K.Read jsr K.GetMemPtr
>STYA pFD
>PULLW K.S.IOCTL+S.IOCTL.BUFPTR
>PULLW K.S.IOCTL+S.IOCTL.BYTECNT
IO.Read.I lda (pFD) #S.FD.T
tax
jmp (.1,x)
@ -169,14 +166,12 @@ IO.Write.I lda (pFD) #S.FD.T
.DA STDIO.IOERR DSOCK
.DA IO.WRITE.SSOCK
.DA IO.WRITE.PIPE
K.Write.9 lda #MLI.E.NODEV
>RET 4
*--------------------------------------
IO.READ.REG ldx #MLIREAD
.HS 2C BIT ABS
*--------------------------------------
IO.WRITE.REG ldx #MLIWRITE
ldy #S.FD.REG.REF
lda (pFD),y
sta K.MLI.PARAMS+1
@ -209,6 +204,7 @@ IO.WRITE.SSOCK ldy #S.FD.SOCK.WRITE
.HS 2C BIT ABS
*--------------------------------------
IO.READ.SSOCK ldy #S.FD.SOCK.READ
lda (pFD),y
tax Function Offset in LIB

View File

@ -42,11 +42,9 @@ K.PutChar sta K.IOBuf
ldy #S.PS.hStdOut
lda (pPs),y
K.PutChar.1 jsr K.GetMemPtr
K.PutChar.1 jsr STDIO.GetHFile
bcs K.PutS.9
>STYA pFD
ldx #1
K.PutChar.X >LDYAI K.IOBuf
@ -105,11 +103,9 @@ K.FPutS pha
pla
K.FPutS.I jsr K.GetMemPtr
K.FPutS.I jsr STDIO.GetHFile
bcs K.PutS.9
>STYA pFD
ldy #0
ldx #0
@ -713,11 +709,9 @@ K.FGetS pha save hFILE
sta ZPPtr2+1 !n
pla
jsr K.GetMemPtr
jsr STDIO.GetHFile
bcs .99
>STYA pFD
jsr K.GetC.I
bcs .9
@ -748,8 +742,11 @@ K.FGetS pha save hFILE
*/--------------------------------------
* # GetChar
* Get char from StdIn
* ## C
* `int getchar ();`
* ## ASM
* **In:**
* none.
* `>SYSCALL getchar`
* **Out:**
* CC = success
* A = char
@ -760,19 +757,18 @@ K.GetChar ldy #S.PS.hStdIn
* # GetC
* Get char from Node
* ## C
* `int getc ( FILE * stream );`
* `int getc ( hFILE stream );`
* ## ASM
* **In:**
* A = hNODE
* `lda stream`
* `>SYSCALL getc`
* **Out:**
* CC = success
* A = char
*\-----------a---------------------------
K.GetC jsr K.GetMemPtr
K.GetC jsr STDIO.GetHFile
bcs K.GetC.9
>STYA pFD
K.GetC.I >LDYAI K.IOBuf
>STYA K.S.IOCTL+S.IOCTL.BUFPTR
lda #1
@ -1094,7 +1090,8 @@ K.FOpen.AUXTYPE .BS 2
* int fclose ( hFILE stream );
* ## ASM
* **In:**
* A = hFILE
* `lda stream`
* `>SYSCALL fclose`
* **Out:**
*\--------------------------------------
K.FClose jsr PFT.CheckNodeA
@ -1126,7 +1123,7 @@ K.FClose jsr PFT.CheckNodeA
* **In:**
* `>PUSHWI count`
* `>PUSHW ptr`
* `lda hFILE`
* `lda stream`
* `>SYSCALL fread`
* **Out:**
* Y,A = Bytes Read
@ -1137,7 +1134,7 @@ K.FRead jsr PFT.CheckNodeA
jmp K.Read
.9
.9 rts
*/--------------------------------------
* # FWrite
* Write bytes to file
@ -1147,23 +1144,17 @@ K.FRead jsr PFT.CheckNodeA
* **In:**
* `>PUSHWI count`
* `>PUSHW ptr`
* `lda hFILE`
* `lda stream`
* `>SYSCALL fwrite`
* **Out:**
* Y,A = Bytes Written
*\--------------------------------------
K.FWrite jsr PFT.CheckNodeA
ldx #MLIWRITE
K.FReadWrite.1 jsr STDIO.GetHFile
jsr STDIO.GetHFile
bcs .9
>PULLW K.MLI.PARAMS+2
>PULLW K.MLI.PARAMS+4
lda #4 Param Count = 4 for MLIREAD & MLIWRITE
jsr GP.MLICall
bcs .9
>LDYA K.MLI.PARAMS+6
jmp K.Write
.9 rts
*/--------------------------------------
* # FFlush
@ -1171,12 +1162,14 @@ K.FReadWrite.1 jsr STDIO.GetHFile
* int fflush(hFILE stream);
* ## ASM
* **In:**
* A = hFILE
* `lda stream`
* `>SYSCALL fflush`
*\--------------------------------------
K.FFlush jsr PFT.CheckNodeA
jsr STDIO.GetHFile
jsr STDIO.GetHFileREG
bcs .9
>MLICALL MLIFLUSH
rts
.9 rts
*/-------------------------------------
* # FSeek
* Set the file-position indicator for hFILE
@ -1191,7 +1184,9 @@ K.FFlush jsr PFT.CheckNodeA
*\-------------------------------------
K.FSeek jsr PFT.CheckNodeA
jsr STDIO.GetHFileREG
>PULLA FROM
bcs .9
>PULLA whence
tax
>PULLW ZPPtr1 offset LW
>PULLW ZPPtr2 offset HW
@ -1250,17 +1245,22 @@ K.FSeek jsr PFT.CheckNodeA
*/--------------------------------------
* # FEOF
* Test the end-of-file indicator for hFILE
* ## C
* `int feof(hFILE stream);`
* ## ASM
* **In:**
* A = hFILE
* `lda stream`
* `>SYSCALL feof`
* **Out:**
* CC :
* A=0 EOF
* A !=0 NOT EOF
* A=0 EOF
* A !=0 NOT EOF
* CS :
*\--------------------------------------
K.FEOF jsr PFT.CheckNodeA
jsr STDIO.GetHFileREG
bcs .9
>MLICALL MLIGETMARK
bcs .9
@ -1316,6 +1316,14 @@ K.FTell jsr PFT.CheckNodeA
.9 rts
*/--------------------------------------
* # Remove
* Remove a file or directory
* ## C
* int remove(const char *pathname);
* ## ASM
* **In:**
* `>LDYA pathname`
* `>SYSCALL remove`
* **Out:**
*\--------------------------------------
K.Remove jsr PFT.CheckPathYA
jsr STDIO.SetMLIPathYA
@ -1390,22 +1398,24 @@ STDIO.NewHFileYAX
clc
.9 rts
*--------------------------------------
STDIO.GetHFile tay
lda Dev.Table.hFD,y
beq .9
*--------------------------------------
STDIO.GetHFileREG
tay
lda Dev.Table.hFD,y
beq STDIO.GetHFile.9
jsr STDIO.GetHFile
bcs .9
jsr K.GetMemPtr
>STYA pFD
lda (pFD) #S.FD.T
bne STDIO.GetHFile.9
ldy #S.FD.REG.REF
lda (pFD),y
sta K.MLI.PARAMS+1
.9 rts
*--------------------------------------
STDIO.GetHFile tay
lda Dev.Table.hFD,y
beq STDIO.GetHFile.9
jsr K.GetMemPtr
>STYA pFD
rts
STDIO.GetHFile.9