From bf3903612d998ca8d95a48fb7cc0e5bfbe68f4c4 Mon Sep 17 00:00:00 2001 From: rtm Date: Mon, 26 Jun 2006 15:11:19 +0000 Subject: system call arguments --- syscall.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'syscall.c') diff --git a/syscall.c b/syscall.c index 48adba8..beadcbb 100644 --- a/syscall.c +++ b/syscall.c @@ -10,11 +10,38 @@ /* * User code makes a system call with INT T_SYSCALL. * System call number in %eax. - * Arguments on the stack. + * Arguments on the stack, from the user call to the C + * library system call function. The saved user %esp points + * to a saved frame pointer, a program counter, and then + * the first argument. * * Return value? Error indication? Errno? */ +/* + * fetch 32 bits from a user-supplied pointer. + * returns 1 if addr was OK, 0 if illegal. + */ +int +fetchint(struct proc *p, unsigned addr, int *ip) +{ + *ip = 0; + + if(addr > p->sz - 4) + return 0; + memcpy(ip, p->mem + addr, 4); + return 1; +} + +int +fetcharg(int argno, int *ip) +{ + unsigned esp; + + esp = (unsigned) curproc[cpu()]->tf->tf_esp; + return fetchint(curproc[cpu()], esp + 8 + 4*argno, ip); +} + void sys_fork() { @@ -72,6 +99,15 @@ sys_wait() } } +void +sys_cons_putc() +{ + int c; + + fetcharg(0, &c); + cons_putc(c & 0xff); +} + void syscall() { @@ -89,6 +125,9 @@ syscall() case SYS_wait: sys_wait(); break; + case SYS_cons_putc: + sys_cons_putc(); + break; default: cprintf("unknown sys call %d\n", num); // XXX fault -- cgit v1.2.3