Skip to content
Snippets Groups Projects
Commit 0ee4d185 authored by s2-fidan's avatar s2-fidan
Browse files

changes

parent c340daea
No related branches found
No related tags found
No related merge requests found
...@@ -40,21 +40,23 @@ syscall_handler (struct intr_frame *f UNUSED) ...@@ -40,21 +40,23 @@ syscall_handler (struct intr_frame *f UNUSED)
get_argument(esp,argument,1); get_argument(esp,argument,1);
syscall_exit(argument[0]); syscall_exit(argument[0]);
break; break;
case SYS_WAIT: // 2 case SYS_EXEC: // 2 (TODO: Change to execute)
printf("System Executing...");
get_argument(esp,argument,1); get_argument(esp,argument,1);
f->eax = syscall_wait(argument[0]); check_address((void *)argument[0]);
f->eax = syscall_exec((const char *)argument[0]);
break; break;
case SYS_CREATE: // 3 case SYS_CREATE: // 4
get_argument(esp,argument,2); get_argument(esp,argument,2);
check_address((void *)argument[0]); check_address((void *)argument[0]);
f->eax = syscall_create((const char *)argument[0],(unsigned)argument[1]); f->eax = syscall_create((const char *)argument[0],(unsigned)argument[1]);
break; break;
case SYS_REMOVE: // 4 case SYS_REMOVE: // 5
get_argument(esp,argument,1); get_argument(esp,argument,1);
check_address((void *)argument[0]); check_address((void *)argument[0]);
f->eax=syscall_remove((const char *)argument[0]); f->eax=syscall_remove((const char *)argument[0]);
break; break;
case SYS_WRITE: //5 case SYS_WRITE: //9
get_argument(esp,argument,3); get_argument(esp,argument,3);
check_address((void *)argument[1]); check_address((void *)argument[1]);
f->eax = syscall_write(argument[0],(void *)argument[1],(unsigned)argument[2]); f->eax = syscall_write(argument[0],(void *)argument[1],(unsigned)argument[2]);
...@@ -86,10 +88,31 @@ void syscall_exit(int status) { ...@@ -86,10 +88,31 @@ void syscall_exit(int status) {
thread_exit(); thread_exit();
} }
/* Wait */ /* Execute */
int syscall_wait(tid_t tid) /* create child process and wait until childprocess is loaded */
/* runs the executable whose name is given */
tid_t
syscall_exec(const char *argument)
{
printf("Exec : %s\n", argument);
/*dynamically create struct child*/
struct thread *child_process;
/*new process'c program id*/
tid_t pid;
pid = process_execute(argument);
/* the child calls sema_up after the done in load()*/
child_process = get_child_process(pid);
/*Call sema_down before we return, so parent process cannot return from the exec call
until it knows that the child process has loaded or not.
Only the parent process proceed past the sema_down line and return.*/
sema_down(&(child_process->load_semaphore));
if(child_process->load_success==true)
return pid;
else
{ {
return process_wait(tid); return -1;
}
} }
/* Create File */ /* Create File */
......
...@@ -11,7 +11,8 @@ void get_argument(void *esp, int *argument, int count); ...@@ -11,7 +11,8 @@ void get_argument(void *esp, int *argument, int count);
void syscall_halt(void); void syscall_halt(void);
void syscall_exit(int status); void syscall_exit(int status);
int syscall_wait(tid_t tid); tid_t
syscall_exec(const char *command);
bool syscall_create(const char* file_name, unsigned initial_size); bool syscall_create(const char* file_name, unsigned initial_size);
bool syscall_remove(const char* file_name); bool syscall_remove(const char* file_name);
int syscall_write(int fd, void *buffer, unsigned size); int syscall_write(int fd, void *buffer, unsigned size);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment