コード例 #1
0
ファイル: svcHandler.c プロジェクト: hellertime/manos
static int execSyscall(int* args) {
    return sysexecv((const char*)args[0], (char * const *)args[1]);
}
コード例 #2
0
ファイル: syscall.c プロジェクト: gmumar/os161
void
mips_syscall(struct trapframe *tf)
{
	int callno;
	int32_t retval;
	int err;
	int s,act;
	char *d;

	//convert user level pointers to user level pointers
	assert(curspl==0);

	callno = tf->tf_v0;

	/*
	 * Initialize retval to 0. Many of the system calls don't
	 * really return a value, just 0 for success and -1 on
	 * error. Since retval is the value returned on success,
	 * initialize it to 0 by default; thus it's not necessary to
	 * deal with it except for calls that return other values, 
	 * like write.
	 */

	retval = 0;

	switch (callno) {
		case SYS_reboot:
			err = sys_reboot(tf->tf_a0);
			break;
			// syscall.h has all the callno numbers for differnt syscalls
		case SYS_fork:
			err = sysfork(&retval,tf);
			break;

		case SYS_getpid :
			err = sysgetpid(&retval);
			break;

		case SYS_write :
			s=splhigh();
			char *c = (char *)tf->tf_a1;
			kprintf("%c",*c);
			retval = 1;
			splx(s);
			err=0;
			break;

		case SYS_read :
			d = (char *)kmalloc(sizeof(char)*((tf->tf_a2)+1));
			//char *b;
			//b = (char *)kmalloc(sizeof(char)*((tf->tf_a2)+1));

			d[0] = getch();
			d[1] ='\0';
			putch(d[0]);
			putch('\n');

			s=splhigh();
			copyoutstr(d,(userptr_t)(tf->tf_a1),(tf->tf_a2)+1,&act);
			//DEBUG(1,"actual: %d tf size: %d\n",act,(tf->tf_a2)+1);

			//copyinstr((tf->tf_a1),b,(tf->tf_a2)+1,&act);
			//DEBUG(1,"copied bacl:%s\n",b);
			err=0;
			kfree(d);
			retval = strlen(d)+1;
			splx(s);
			break;

		case SYS_waitpid :
			err = syswaitpid(tf->tf_a0,(int *)tf->tf_a1,tf->tf_a2,&retval);
			//syswaitpid(&retval);
			break;

		case SYS__exit :
			err = sysexit(&retval,tf);
			break;

		case SYS_execv:
			err=sysexecv((char*)tf->tf_a0, (char**)tf->tf_a1);
			break;

		case SYS_sbrk:
			err = sys_sbrk((int)tf->tf_a0, &retval);
			break;

		default:
			kprintf("Unknown syscall %d\n", callno);
			err = ENOSYS;
			break;
	}


	if (err) {
		/*
		 * Return the error code. This gets converted at
		 * userlevel to a return value of -1 and the error
		 * code in errno.
		 */
		tf->tf_v0 = err;
		tf->tf_a3 = 1;      /* signal an error */
	}
	else {
		/* Success. */
		tf->tf_v0 = retval;
		tf->tf_a3 = 0;      /* signal no error */
	}

	/*
	 * Now, advance the program counter, to avoid restarting
	 * the syscall over and over again.
	 */

	tf->tf_epc += 4;

	/* Make sure the syscall code didn't forget to lower spl */
	assert(curspl==0);
}