summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-06-04 06:45:09 -0400
committerRobert Morris <[email protected]>2019-06-04 06:45:09 -0400
commit0f684b9150b56c3fce1db099e93327ebaaca363a (patch)
tree5644e1b2e27d2ff3b2d57ab07238e06fe215bb40
parent8baac760500980d4b83e8de2e90265bfaa19df13 (diff)
downloadxv6-labs-0f684b9150b56c3fce1db099e93327ebaaca363a.tar.gz
xv6-labs-0f684b9150b56c3fce1db099e93327ebaaca363a.tar.bz2
xv6-labs-0f684b9150b56c3fce1db099e93327ebaaca363a.zip
fix exec argc
-rw-r--r--README2
-rw-r--r--console.c2
-rw-r--r--exec.c28
3 files changed, 16 insertions, 16 deletions
diff --git a/README b/README
index 9e3cf19..73e134e 100644
--- a/README
+++ b/README
@@ -1,6 +1,6 @@
xv6 is a re-implementation of Dennis Ritchie's and Ken Thompson's Unix
Version 6 (v6). xv6 loosely follows the structure and style of v6,
-but is implemented for a modern x86-based multiprocessor using ANSI C.
+but is implemented for a modern RISC-V multiprocessor using ANSI C.
ACKNOWLEDGMENTS
diff --git a/console.c b/console.c
index c7e1852..122ccb3 100644
--- a/console.c
+++ b/console.c
@@ -205,7 +205,7 @@ consolewrite(struct inode *ip, int user_src, uint64 src, int n)
acquire(&cons.lock);
for(i = 0; i < n; i++){
char c;
- if(either_copyin(&c, user_src, src, 1) == -1)
+ if(either_copyin(&c, user_src, src+i, 1) == -1)
break;
consputc(c);
}
diff --git a/exec.c b/exec.c
index 4c34a51..c854aae 100644
--- a/exec.c
+++ b/exec.c
@@ -13,7 +13,7 @@ exec(char *path, char **argv)
{
char *s, *last;
int i, off;
- uint64 argc, sz, sp, ustack[3+MAXARG+1];
+ uint64 argc, sz, sp, ustack[MAXARG+1];
struct elfhdr elf;
struct inode *ip;
struct proghdr ph;
@@ -71,24 +71,24 @@ exec(char *path, char **argv)
for(argc = 0; argv[argc]; argc++) {
if(argc >= MAXARG)
goto bad;
- sp = (sp - (strlen(argv[argc]) + 1)) & ~(sizeof(uint64)-1);
+ sp -= strlen(argv[argc]) + 1;
+ sp -= sp % 16; // riscv sp must be 16-byte aligned
if(copyout(pagetable, sp, argv[argc], strlen(argv[argc]) + 1) < 0)
goto bad;
- ustack[3+argc] = sp;
+ ustack[argc] = sp;
}
- ustack[3+argc] = 0;
+ ustack[argc] = 0;
- ustack[0] = 0xffffffff; // fake return PC
- ustack[1] = argc;
- ustack[2] = sp - (argc+1)*sizeof(uint64); // argv pointer
+ // push the array of argv[] pointers.
+ sp -= (argc+1) * sizeof(uint64);
+ sp -= sp % 16;
+ if(copyout(pagetable, sp, (char *)ustack, (argc+1)*sizeof(uint64)) < 0)
+ goto bad;
// arguments to user main(argc, argv)
- p->tf->a0 = argc;
- p->tf->a1 = sp - (argc+1)*sizeof(uint64);
-
- sp -= (3+argc+1) * sizeof(uint64);
- if(copyout(pagetable, sp, (char *)ustack, (3+argc+1)*sizeof(uint64)) < 0)
- goto bad;
+ // argc is returned via the system call return
+ // value, which goes in a0.
+ p->tf->a1 = sp;
// Save program name for debugging.
for(last=s=path; *s; s++)
@@ -103,7 +103,7 @@ exec(char *path, char **argv)
p->tf->epc = elf.entry; // initial program counter = main
p->tf->sp = sp; // initial stack pointer
proc_freepagetable(oldpagetable, oldsz);
- return 0;
+ return argc; // this ends up in a0, the first argument to main(argc, argv)
bad:
if(pagetable)