# HG changeset patch # User mir3636 # Date 1547803202 -32400 # Node ID 96a5833d0d82dc38c5750138c94ff330447b0193 # Parent 6a7ab1d7001cad1eecac2ac1ae047629f3ffe9cd fix diff -r 6a7ab1d7001c -r 96a5833d0d82 src/console.c --- a/src/console.c Fri Jan 18 11:50:48 2019 +0900 +++ b/src/console.c Fri Jan 18 18:20:02 2019 +0900 @@ -12,6 +12,9 @@ #include "mmu.h" #include "proc.h" +__code cbc_consoleread1 (__code(*)(int)); +__code cbc_consoleread2 (__code(*)(int)); + static void consputc (int); static int panicked = 0; @@ -230,6 +233,30 @@ release(&input.lock); } +__code cbc_consoleread2 (__code(*next)(int ret)) +{ + int n = proc->cbc_arg.cbc_console_arg.n; + int target = proc->cbc_arg.cbc_console_arg.target; + char* dst = proc->cbc_arg.cbc_console_arg.dst; + struct inode *ip = proc->cbc_arg.cbc_console_arg.ip; + struct file *f = proc->cbc_arg.cbc_console_arg.f; + proc->cbc_arg.cbc_console_arg.n = n; + proc->cbc_arg.cbc_console_arg.target = target; + proc->cbc_arg.cbc_console_arg.dst = dst; + proc->cbc_arg.cbc_console_arg.ip = ip; + proc->cbc_arg.cbc_console_arg.f = f; + proc->cbc_arg.cbc_console_arg.next = next; + if (input.r == input.w) { + if (proc->killed) { + release(&input.lock); + ilock(ip); + goto next(-1); + } + goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); + } + goto cbc_consoleread1(0); +} + __code cbc_consoleread1 (__code(*next)(int ret)) { int cont = 1; @@ -237,41 +264,51 @@ int target = proc->cbc_arg.cbc_console_arg.target; char* dst = proc->cbc_arg.cbc_console_arg.dst; struct inode *ip = proc->cbc_arg.cbc_console_arg.ip; + struct file *f = proc->cbc_arg.cbc_console_arg.f; int c = input.buf[input.r++ % INPUT_BUF]; - if (c == C('D')) { // EOF - if (n < target) { - // Save ^D for next time, to make sure - // caller gets a 0-byte result. - input.r--; - } - cont = 0; - } + if (c == C('D')) { // EOF + if (n < target) { + // Save ^D for next time, to make sure + // caller gets a 0-byte result. + input.r--; + } + cont = 0; + } - *dst++ = c; - --n; + *dst++ = c; + --n; - if (c == '\n') { - cont = 0; - } - + if (c == '\n') { + cont = 0; + } - if (cont){ + if (n > 0) { proc->cbc_arg.cbc_console_arg.n = n; + proc->cbc_arg.cbc_console_arg.target = target; proc->cbc_arg.cbc_console_arg.dst = dst; proc->cbc_arg.cbc_console_arg.ip = ip; - proc->cbc_arg.cbc_console_arg.next = next; - goto cbc_sleep(&input.r, &input.lock, cbc_consoleread1); + proc->cbc_arg.cbc_console_arg.f = f; + proc->cbc_arg.cbc_console_arg.next = next; + goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); } release(&input.lock); ilock(ip); - goto next(target - n); + int r = target - n; + + if (r > 0) + f->off += r; + iunlock(f->ip); + + //goto next(target - n); + + goto cbc_ret(r); } -__code cbc_consoleread (struct inode *ip, char *dst, int n, __code(*next)(int ret)) +__code cbc_consoleread (struct inode *ip, char *dst, int n, struct file *f, __code(*next)(int ret)) { uint target; @@ -280,21 +317,23 @@ target = n; acquire(&input.lock); - while (n > 0) { - while (input.r == input.w) { + if (n > 0) { + proc->cbc_arg.cbc_console_arg.n = n; + proc->cbc_arg.cbc_console_arg.target = target; + proc->cbc_arg.cbc_console_arg.dst = dst; + proc->cbc_arg.cbc_console_arg.ip = ip; + proc->cbc_arg.cbc_console_arg.f = f; + proc->cbc_arg.cbc_console_arg.next = next; + if (input.r == input.w) { if (proc->killed) { release(&input.lock); ilock(ip); goto next(-1); } - proc->cbc_arg.cbc_console_arg.n = n; - proc->cbc_arg.cbc_console_arg.target = target; - proc->cbc_arg.cbc_console_arg.dst = dst; - proc->cbc_arg.cbc_console_arg.ip = ip; - proc->cbc_arg.cbc_console_arg.next = next; - goto cbc_sleep(&input.r, &input.lock, cbc_consoleread1); + goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); } + goto cbc_consoleread1(0); } } diff -r 6a7ab1d7001c -r 96a5833d0d82 src/defs.h --- a/src/defs.h Fri Jan 18 11:50:48 2019 +0900 +++ b/src/defs.h Fri Jan 18 18:20:02 2019 +0900 @@ -90,7 +90,7 @@ int namecmp(const char*, const char*); struct inode* namei(char*); struct inode* nameiparent(char*, char*); -__code cbc_readi (struct inode*, char*, uint, uint, __code (*)(int)); +__code cbc_readi (struct inode*, char*, uint, uint, struct file*, __code (*)(int)); int readi(struct inode*, char*, uint, uint); void stati(struct inode*, struct stat*); int writei(struct inode*, char*, uint, uint); @@ -165,6 +165,7 @@ int argstr(int, char**); int fetchint(uint, int*); int fetchstr(uint, char**); +__code cbc_ret(int); void syscall(void); // timer.c diff -r 6a7ab1d7001c -r 96a5833d0d82 src/file.c --- a/src/file.c Fri Jan 18 11:50:48 2019 +0900 +++ b/src/file.c Fri Jan 18 18:20:02 2019 +0900 @@ -124,7 +124,7 @@ if (f->type == FD_INODE) { ilock(f->ip); - goto cbc_readi(f->ip, addr, f->off, n, next); + goto cbc_readi(f->ip, addr, f->off, n, f, next); } goto cbc_panic("fileread"); diff -r 6a7ab1d7001c -r 96a5833d0d82 src/file.h --- a/src/file.h Fri Jan 18 11:50:48 2019 +0900 +++ b/src/file.h Fri Jan 18 18:20:02 2019 +0900 @@ -34,7 +34,7 @@ }; struct cbc_devsw { - __code (*read) (struct inode*, char*, int, __code (*)(int)); + __code (*read) (struct inode*, char*, int, struct file*, __code (*)(int)); //__code (*write)(struct inode*, char*, int, __code (*)(int)); }; diff -r 6a7ab1d7001c -r 96a5833d0d82 src/fs.c --- a/src/fs.c Fri Jan 18 11:50:48 2019 +0900 +++ b/src/fs.c Fri Jan 18 18:20:02 2019 +0900 @@ -453,7 +453,7 @@ st->size = ip->size; } -__code cbc_readi (struct inode *ip, char *dst, uint off, uint n, __code (*next)(int ret)) +__code cbc_readi (struct inode *ip, char *dst, uint off, uint n, struct file *f, __code (*next)(int ret)) { uint tot, m; struct buf *bp; @@ -463,7 +463,7 @@ goto next(-1); } - goto cbc_devsw[ip->major].read(ip, dst, n, next); + goto cbc_devsw[ip->major].read(ip, dst, n, f, next); } if (off > ip->size || off + n < off) { diff -r 6a7ab1d7001c -r 96a5833d0d82 src/proc.h --- a/src/proc.h Fri Jan 18 11:50:48 2019 +0900 +++ b/src/proc.h Fri Jan 18 18:20:02 2019 +0900 @@ -74,6 +74,7 @@ int target; char* dst; struct inode *ip; + struct file *f; __code (*next)(int ret); } cbc_console_arg; } cbc_arg; diff -r 6a7ab1d7001c -r 96a5833d0d82 src/syscall.c --- a/src/syscall.c Fri Jan 18 11:50:48 2019 +0900 +++ b/src/syscall.c Fri Jan 18 18:20:02 2019 +0900 @@ -146,7 +146,7 @@ }; __code cbc_trap_return(){ - goto trap_swi(); + return; } __code cbc_ret(int ret){ @@ -161,9 +161,11 @@ num = proc->tf->r0; + if (num == 5) + num = 22; //cprintf ("syscall(%d) from %s(%d)\n", num, proc->name, proc->pid); - if((num > 0) && (num > NELEM(syscalls)) && cbccodes[num]) { + if((num >= NELEM(syscalls)) && (num <= NELEM(cbccodes)) && cbccodes[num]) { goto (cbccodes[num])(cbc_ret); }