Mercurial > hg > Members > tobaru > CbC_xv6
changeset 91:b5ddf6fb0a6d
use CbCFile instead of File struct Interface
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Oct 2019 20:39:36 +0900 |
parents | dd1d9ea1b7b5 |
children | bc5bcfd2f6d6 |
files | src/context.h src/file.cbc src/interface/CbCFile.h src/interface/File.h src/syscall.cbc src/sysfile.cbc |
diffstat | 6 files changed, 37 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/context.h Thu Oct 17 10:42:54 2019 +0900 +++ b/src/context.h Fri Oct 18 20:39:36 2019 +0900 @@ -226,6 +226,13 @@ struct CUDAWorker { } CUDAWorker; #endif + struct CbCFile { + struct file *f; + int n; + char *p; + enum Code next; + enum Code read; + } CbCFile; struct Main { enum Code code; enum Code next;
--- a/src/file.cbc Thu Oct 17 10:42:54 2019 +0900 +++ b/src/file.cbc Fri Oct 18 20:39:36 2019 +0900 @@ -113,7 +113,8 @@ goto next(r); } -__ncode cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret)) + +__code cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret)) { if (f->readable == 0) { goto next(-1); @@ -133,6 +134,12 @@ goto cbc_panic("fileread"); } +__code cbc_fileread_stub(struct Context* cbc_context) { + struct CbCFile* cbc_file = &cbc_context->data[D_CbCFile]->CbCFile; + enum Code next = cbc_context->next; + goto cbc_fileread(cbc_file->f, cbc_file->p, cbc_file->n, cbc_context->code[next]); +} + // Read from file f. int fileread (struct file *f, char *addr, int n) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/interface/CbCFile.h Fri Oct 18 20:39:36 2019 +0900 @@ -0,0 +1,5 @@ +typedef struct CbCFile<Type, Impl>{ + struct CbCFile* cbc_file; + __code file_read(__code next(...)); + __code next(...); +} CbCFile;
--- a/src/interface/File.h Thu Oct 17 10:42:54 2019 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -typedef struct File<Type, Impl>{ - union Data* file; - struct file *f; - int n; - char *p; - __code file_read(__code, next(...)); - __code next(...); -} File;
--- a/src/syscall.cbc Thu Oct 17 10:42:54 2019 +0900 +++ b/src/syscall.cbc Fri Oct 18 20:39:36 2019 +0900 @@ -143,8 +143,8 @@ [SYS_close] =sys_close, }; -static __code (*cbccodes[])(__code (*)(int)) = { - [SYS_cbc_read] = cbc_read, +static enum Code cbccodes[] = { + [SYS_cbc_read] = C_start_code, }; __ncode cbc_trap_return(){ @@ -163,16 +163,17 @@ { int num; int ret; + struct Context* cbc_context; num = proc->tf->r0; if (num == 5) - num = 22; + num = 22; //cprintf ("syscall(%d) from %s(%d)\n", num, proc->name, proc->pid); if((num >= NELEM(syscalls)) && (num <= NELEM(cbccodes)) && cbccodes[num]) { proc->cbc_arg.cbc_console_arg.num = num; - goto (cbccodes[num])(cbc_ret); + goto meta(cbc_context, cbccodes[num]); }
--- a/src/sysfile.cbc Thu Oct 17 10:42:54 2019 +0900 +++ b/src/sysfile.cbc Fri Oct 18 20:39:36 2019 +0900 @@ -14,6 +14,8 @@ #include "file.h" #include "fcntl.h" +#interface "CbCFile.h" + #define __ncode __code // Fetch the nth word-sized system call argument as a file descriptor @@ -87,18 +89,25 @@ goto cbc_fileread(f, p, n, next); } -__code file_read(struct file *f, int n, char *p, __code next(...)){ +struct CbCFile* initial_cbc_file(struct Context* cbc_context) { + struct CbCFile* cbc_file = new CbCFile(); + cbc_file->read = C_cbc_fileread; + return cbc_file; +} + +__code file_read(struct file *f, char *p, int n, __code next(...)){ goto cbc_fileread(f, p, n, next); } -__code file_read_stub(struct Context* cbc_context){ +__code file_read_stub(struct Context* cbc_context, __code next(...)){ + struct CbCFile* cbc_file = initial_cbc_file(cbc_context); struct file *f; int n; char *p; if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0) { goto next(-1); } - goto cbc_fileread(f, p, n, next); + goto file_read(cbc_context,f, p, n, next); } int sys_read(void) @@ -330,8 +339,6 @@ iupdate(ip); if(type == T_DIR){ // Create . and .. entries. - dp->nlink++; // for ".." - iupdate(dp); // No ip->nlink++ for ".": avoid cyclic ref count. if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0) {