# HG changeset patch # User mir3636 # Date 1548139715 -32400 # Node ID 96af12a50fdb65479875144627c734c967cdf71e # Parent 96a5833d0d82dc38c5750138c94ff330447b0193 fix cbc_read diff -r 96a5833d0d82 -r 96af12a50fdb src/console.c --- a/src/console.c Fri Jan 18 18:20:02 2019 +0900 +++ b/src/console.c Tue Jan 22 15:48:35 2019 +0900 @@ -12,8 +12,8 @@ #include "mmu.h" #include "proc.h" -__code cbc_consoleread1 (__code(*)(int)); -__code cbc_consoleread2 (__code(*)(int)); +__code cbc_consoleread1 (); +__code cbc_consoleread2 (); static void consputc (int); @@ -233,19 +233,10 @@ release(&input.lock); } -__code cbc_consoleread2 (__code(*next)(int ret)) +__code cbc_consoleread2 () { - 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; + __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next; if (input.r == input.w) { if (proc->killed) { release(&input.lock); @@ -254,10 +245,10 @@ } goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); } - goto cbc_consoleread1(0); + goto cbc_consoleread1(); } -__code cbc_consoleread1 (__code(*next)(int ret)) +__code cbc_consoleread1 () { int cont = 1; int n = proc->cbc_arg.cbc_console_arg.n; @@ -265,6 +256,7 @@ 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; + __code(*next)(int ret) = proc->cbc_arg.cbc_console_arg.next; int c = input.buf[input.r++ % INPUT_BUF]; @@ -284,14 +276,16 @@ cont = 0; } - 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; - goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); + if (cont == 1) { + 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; + goto cbc_sleep(&input.r, &input.lock, cbc_consoleread2); + } } release(&input.lock); @@ -305,7 +299,7 @@ //goto next(target - n); - goto cbc_ret(r); + goto next(r); } __code cbc_consoleread (struct inode *ip, char *dst, int n, struct file *f, __code(*next)(int ret)) diff -r 96a5833d0d82 -r 96af12a50fdb src/file.c --- a/src/file.c Fri Jan 18 18:20:02 2019 +0900 +++ b/src/file.c Tue Jan 22 15:48:35 2019 +0900 @@ -8,6 +8,7 @@ #include "fs.h" #include "file.h" #include "spinlock.h" +#include "proc.h" struct devsw devsw[NDEV]; struct cbc_devsw cbc_devsw[NDEV]; @@ -100,7 +101,7 @@ return -1; } -__code cbc_fileread1 (int r, struct file *f, char *addr, int n, __code (*next)(int ret)) +__code cbc_fileread1 (int r, struct file *f, __code (*next)(int ret)) { if (r > 0) f->off += r; @@ -110,8 +111,6 @@ __code cbc_fileread (struct file *f, char *addr, int n, __code (*next)(int ret)) { - int r; - if (f->readable == 0) { goto next(-1); } @@ -123,7 +122,6 @@ if (f->type == FD_INODE) { ilock(f->ip); - goto cbc_readi(f->ip, addr, f->off, n, f, next); } diff -r 96a5833d0d82 -r 96af12a50fdb src/fs.c --- a/src/fs.c Fri Jan 18 18:20:02 2019 +0900 +++ b/src/fs.c Tue Jan 22 15:48:35 2019 +0900 @@ -481,6 +481,10 @@ brelse(bp); } + if (n > 0) + f->off += n; + iunlock(f->ip); + goto next(n); } diff -r 96a5833d0d82 -r 96af12a50fdb src/proc.c --- a/src/proc.c Fri Jan 18 18:20:02 2019 +0900 +++ b/src/proc.c Tue Jan 22 15:48:35 2019 +0900 @@ -471,6 +471,7 @@ } proc->chan = chan; proc->state = SLEEPING; + proc->lk = lk; proc->cbc_next = next1; goto cbc_sched(cbc_sleep1); diff -r 96a5833d0d82 -r 96af12a50fdb src/proc.h --- a/src/proc.h Fri Jan 18 18:20:02 2019 +0900 +++ b/src/proc.h Tue Jan 22 15:48:35 2019 +0900 @@ -71,11 +71,12 @@ union cbc_arg { struct cbc_console_arg { int n; - int target; - char* dst; - struct inode *ip; - struct file *f; - __code (*next)(int ret); + int target; + char* dst; + struct inode *ip; + struct file *f; + int num; + __code (*next)(int ret); } cbc_console_arg; } cbc_arg; __code (*cbc_next)(); diff -r 96a5833d0d82 -r 96af12a50fdb src/syscall.c --- a/src/syscall.c Fri Jan 18 18:20:02 2019 +0900 +++ b/src/syscall.c Tue Jan 22 15:48:35 2019 +0900 @@ -150,7 +150,10 @@ } __code cbc_ret(int ret){ - proc->tf->r0 = ret; + int num = proc->cbc_arg.cbc_console_arg.num; + if (num != SYS_exec) { + proc->tf->r0 = ret; + } goto cbc_trap_return(); } @@ -166,7 +169,7 @@ //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); }