changeset 379:a0d6f7124b9b

add ReadSyscall interface
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 13 Jul 2020 16:10:06 +0900
parents 297515214d9b
children 8f2bc03fcbb2
files src/impl/ReadSyscallImpl.cbc src/impl/ReadSyscallImpl.h src/interface/ReadSyscall.h
diffstat 3 files changed, 102 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/impl/ReadSyscallImpl.cbc	Mon Jul 13 16:10:06 2020 +0900
@@ -0,0 +1,84 @@
+#include "../context.h"
+#interface "ReadSyscall.h"
+
+// ----
+// typedef struct ReadSyscallImpl <Type, Isa> impl ReadSyscall {
+//   __code next(....);
+// } ReadSyscallImpl;
+// ----
+
+ReadSyscall* createReadSyscallImpl(struct Context* cbc_context) {
+    struct ReadSyscall* read_syscall  = new ReadSyscall();
+    struct ReadSyscallImpl* read_syscall_impl = new ReadSyscallImpl();
+    read_syscall->read_syscall = (union Data*)read_syscall_impl;
+    read_syscall->consoleread = C_consolereadReadSyscallImpl;
+    read_syscall->consoleread1 = C_consoleread1ReadSyscallImpl;
+    read_syscall->consoleread2 = C_consoleread2ReadSyscallImpl;
+    read_syscall->piperead = C_pipereadReadSyscallImpl;
+    read_syscall->piperead1 = C_piperead1ReadSyscallImpl;
+    read_syscall->piperead2 = C_piperead2ReadSyscallImpl;
+    read_syscall->piperead3 = C_piperead3ReadSyscallImpl;
+    read_syscall->fileread = C_filereadReadSyscallImpl;
+    read_syscall->fileread1 = C_fileread1ReadSyscallImpl;
+    return read_syscall;
+}
+__code consolereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct inode* ip, char* dst, int n, __code next(int ret, ...)) {
+
+    goto next(ret, ...);
+}
+
+__code consoleread1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall,int n, int target, char* dst, struct inode* ip,  __code next(...)) {
+
+    goto next(...);
+}
+
+__code consoleread2ReadSyscallImpl(struct ReadSyscallImpl* read_syscall,struct inode* ip, __code next(...)) {
+
+    goto next(...);
+}
+
+__code pipereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p,char* addr, int n,  __code next(int ret,...)) {
+
+    goto next(ret,...);
+}
+
+__code piperead1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p, __code next(int ret,...)) {
+
+    goto next(ret,...);
+}
+
+__code piperead2ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, int i, int n, struct pipe* p, char* addr, __code next(int ret,...)) {
+
+    goto next(ret,...);
+}
+
+__code piperead3ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct pipe* p, int i, __code next(int ret,...)) {
+
+    goto next(ret,...);
+}
+
+__code filereadReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct file* f, char* addr, int n, __code next(int ret, ...)) {
+    if (f->readable == 0) {
+        ret = -1;
+        goto next(ret);
+    }
+
+    if (f->type == FD_PIPE) {
+        goto read_syscall->piperead(f->pipe, addr, n, next);
+    }
+
+    if (f->type == FD_INODE) {
+        ilock(f->ip);
+        goto read_syscall->cbc_readi(f->ip, addr, f->off, n, readsys_call->fileread1);
+    }
+
+    goto cbc_panic("fileread");
+}
+
+__code fileread1ReadSyscallImpl(struct ReadSyscallImpl* read_syscall, struct file* f, int ret, __code next(ret, ...)) {
+    if (ret > 0)
+        f->off += ret;
+    iunlock(f->ip);
+    goto next(ret);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/impl/ReadSyscallImpl.h	Mon Jul 13 16:10:06 2020 +0900
@@ -0,0 +1,3 @@
+typedef struct ReadSyscallImpl <Type, Isa> impl ReadSyscall {
+  __code next(....);
+} ReadSyscallImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/interface/ReadSyscall.h	Mon Jul 13 16:10:06 2020 +0900
@@ -0,0 +1,15 @@
+typedef struct ReadSyscall <Type, Impl> {
+  __code consoleread(Impl* read_syscall, struct inode* ip, char* dst, int n, __code next(int ret, ...));
+  __code consoleread1(Impl* read_syscall,int n, int target, char* dst, struct inode* ip,  __code next(...));
+  __code consoleread2(Impl* read_syscall,struct inode* ip, __code next(...));
+
+  __code piperead(Impl* read_syscall, struct pipe* p,char* addr, int n,  __code next(int ret,...));
+  __code piperead1(Impl* read_syscall, struct pipe* p, __code next(int ret,...));
+  __code piperead2(Impl* read_syscall, int i, int n, struct pipe* p, char* addr, __code next(int ret,...));
+  __code piperead3(Impl* read_syscall, struct pipe* p, int i, __code next(int ret,...));
+
+  __code fileread(Impl* read_syscall, struct file* f, char* addr, int n, __code next(int ret, ...));
+  __code fileread1(Impl* read_syscall, struct file* f, int ret, __code next(ret, ...));
+
+  __code next(....);
+} ReadSyscall;