Ejemplo n.º 1
0
int main() {
  usr_sem_t *wait0, *wait1, *read_write_lock;
  uint32_t prog0, prog1;
  int ret0, ret1;

  puts("Create the semaphores.\n");
  wait0 = syscall_sem_open("wait0", 0);
  wait1 = syscall_sem_open("wait1", 0);
  read_write_lock = syscall_sem_open("rwlock", 1);
  read_write_lock = read_write_lock;

  puts("Run the children.\n");
  prog0 = syscall_exec(VOLUME "sem_barrier_p0");
  prog1 = syscall_exec(VOLUME "sem_barrier_p1");

  puts("Wait for them to finish.\n");
  ret0 = syscall_join(prog0);
  ret1 = syscall_join(prog1);
  printf("Children joined with return values %d and %d.\n", ret0, ret1);

  puts("Destroy the semaphores.\n");
  syscall_sem_destroy(wait0);
  syscall_sem_destroy(wait1);

  syscall_halt();
  return 0;
}
Ejemplo n.º 2
0
int main(void)
{
  uint32_t child;
  uint32_t child2;
  uint32_t child3;
  uint32_t child4;
  int ret;
  int ret2;
  int ret3;
  int ret4;
  int i;
for(i = 0; i < 10;i++) {
  printf("Starting program %s\n", prog);
  child = syscall_exec(prog);
  child2 = syscall_exec(prog);
  child3 = syscall_exec(prog);
  child4 = syscall_exec(prog);
  printf("Now joining child %d\n", child);
  
  ret = (char)syscall_join(child);
  ret2 = (char)syscall_join(child2);
  ret3 = (char)syscall_join(child3);
  ret4 = (char)syscall_join(child4);
  printf("Child joined with status: %d\n", ret);
  printf("Child joined with status: %d\n", ret2);
  printf("Child joined with status: %d\n", ret3);
  printf("Child joined with status: %d\n", ret4);
   }
  syscall_halt();
  return 0;
}
Ejemplo n.º 3
0
int main(void)
{
  int a,b,c,d,e;
  a = syscall_exec("[arkimedes]a", -1);
  b = syscall_exec("[arkimedes]b", 9000);
  c = syscall_exec("[arkimedes]c", 3000);
  d = syscall_exec("[arkimedes]d", 4000);
  e = syscall_exec("[arkimedes]e", 2000);
  syscall_join(a);
  syscall_join(b);
  syscall_join(c);
  syscall_join(d);
  syscall_join(e);
  return 0;
}
Ejemplo n.º 4
0
Archivo: shell.c Proyecto: Rathcke/uni
int cmd_run(char* prog) {
  if (does_file_exist(prog)) {
    return syscall_join(syscall_exec(prog));
  } else {
    printf("No such program: %s.\n", prog);
    return 1;
  }
}
Ejemplo n.º 5
0
int main(void) {
    uint32_t child;
    printf("Beginning proc_test \n");
    child = syscall_exec(prog);
    syscall_join(child);
    printf("Ending proc_test \n");
    syscall_halt();
    return 0;
}
Ejemplo n.º 6
0
Archivo: exec.c Proyecto: cfrost/buenos
int main(void)
{
  uint32_t child;
  int ret;
  printf("Starting program %s\n", prog);
  child = syscall_exec(prog);
  printf("Now joining child %d\n", child);
  ret = (char)syscall_join(child);
  printf("Child joined with status: %d\n", ret);
  
  printf("Starting program %s\n", prog2);
  child = syscall_exec(prog2);
  printf("Now joining child %d\n", child);
  ret = (char)syscall_join(child);
  printf("Child joined with status: %d\n", ret);
  syscall_halt();
  return 0;
}
Ejemplo n.º 7
0
Archivo: shell.c Proyecto: Rathcke/uni
int cmd_wait(int argc, char** argv) {
  argv=argv;
  if (argc != 1) {
    printf("Usage: wait\n");
  } else if (background_proc == -1) {
    printf("No background process to wait for.\n");
  } else {
    int retval = syscall_join(background_proc);
    background_proc = 1;
    return retval;
  }
  return 1;
}
Ejemplo n.º 8
0
Archivo: testexec.c Proyecto: ArvoX/osm
int main(void)
{
    int child_p, retval;

    write("dette er en test\n");

    child_p = syscall_exec("[test]testexit");
    retval = syscall_join(child_p);

    syscall_halt();

    return -1;
}
Ejemplo n.º 9
0
/**
 * Handle system calls. Interrupts are enabled when this function is
 * called.
 *
 * @param user_context The userland context (CPU registers as they
 * where when system call instruction was called in userland)
 */
void syscall_handle(context_t *user_context)
{
    /* When a syscall is executed in userland, register a0 contains
     * the number of the syscall. Registers a1, a2 and a3 contain the
     * arguments of the syscall. The userland code expects that after
     * returning from the syscall instruction the return value of the
     * syscall is found in register v0. Before entering this function
     * the userland context has been saved to user_context and after
     * returning from this function the userland context will be
     * restored from user_context.
     */
    switch(user_context->cpu_regs[MIPS_REGISTER_A0]) {
    case SYSCALL_HALT:
        halt_kernel();
        break;
    case SYSCALL_READ:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_read(user_context->cpu_regs[MIPS_REGISTER_A1],
                         (void *)user_context->cpu_regs[MIPS_REGISTER_A2],
                         user_context->cpu_regs[MIPS_REGISTER_A3]);
        break;
    case SYSCALL_WRITE:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_write(user_context->cpu_regs[MIPS_REGISTER_A1],
                          (const void *)user_context->cpu_regs[MIPS_REGISTER_A2],
                          user_context->cpu_regs[MIPS_REGISTER_A3]);
        break;
    case SYSCALL_EXEC:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_exec((const char *)user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_EXIT:
        syscall_exit(user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_JOIN:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_join(user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    default: 
        KERNEL_PANIC("Unhandled system call\n");
    }

    /* Move to next instruction after system call */
    user_context->pc += 4;
}
Ejemplo n.º 10
0
Archivo: syscall.c Proyecto: mrb852/osm
/**
 * Handle system calls. Interrupts are enabled when this function is
 * called.
 *
 * @param user_context The userland context (CPU registers as they
 * where when system call instruction was called in userland)
 */
void syscall_handle(context_t *user_context)
{
  /* When a syscall is executed in userland, register a0 contains
   * the number of the syscall. Registers a1, a2 and a3 contain the
   * arguments of the syscall. The userland code expects that after
   * returning from the syscall instruction the return value of the
   * syscall is found in register v0. Before entering this function
   * the userland context has been saved to user_context and after
   * returning from this function the userland context will be
   * restored from user_context.
   */
  switch (A0)
  {
  case SYSCALL_HALT:
    halt_kernel();
    break;
  case SYSCALL_READ:
    V0 = tty_read((int) A1, (void*) A2, (int) A3);
    break;
  case SYSCALL_WRITE:
    V0 = tty_write((int) A1, (void*) A2, (int) A3);
    break;
  case SYSCALL_EXEC:
    V0 = syscall_exec((char*) A1);
    break;
  case SYSCALL_EXIT:
    syscall_exit((int) A1);
    break;
  case SYSCALL_JOIN:
    V0 = syscall_join((process_id_t) A1);
    break;
  case SYSCALL_MEMLIMIT:
    V0 = (int)process_memlimit((void *) A1);
    break;
  default:
    KERNEL_PANIC("Unhandled system call\n");
  }

  /* Move to next instruction after system call */
  user_context->pc += 4;
}
Ejemplo n.º 11
0
Archivo: syscall.c Proyecto: kazyka/OSM
/**
 * Handle system calls. Interrupts are enabled when this function is
 * called.
 */
uintptr_t syscall_entry(uintptr_t syscall,
                        uintptr_t arg0, uintptr_t arg1, uintptr_t arg2)
{
  arg0 = arg0;
  arg1 = arg1;
  arg2 = arg2;
  /* When a syscall is executed in userland, register a0 contains
   * the number of the syscall. Registers a1, a2 and a3 contain the
   * arguments of the syscall. The userland code expects that after
   * returning from the syscall instruction the return value of the
   * syscall is found in register v0. Before entering this function
   * the userland context has been saved to user_context and after
   * returning from this function the userland context will be
   * restored from user_context.
   */
  switch(syscall) {
  case SYSCALL_HALT:
    halt_kernel();
    break;
  case SYSCALL_READ:
    return syscall_read((void*)arg0);
    break;
  case SYSCALL_WRITE:
    return syscall_write((const void*)arg0, (int)arg1);
    break;
  case SYSCALL_SPAWN:
    return syscall_spawn((char const*)arg0, (char const**)arg1);
    break;
  case SYSCALL_EXIT:
    syscall_exit((int)arg0);
    break;
  case SYSCALL_JOIN:
    return syscall_join((int)arg0);
    break;
  default:
    KERNEL_PANIC("Unhandled system call\n");
  }

  return 0;
}
Ejemplo n.º 12
0
/**
 * Handle system calls. Interrupts are enabled when this function is
 * called.
 *
 * @param user_context The userland context (CPU registers as they
 * where when system call instruction was called in userland)
 */
void syscall_handle(context_t *user_context)
{
    /* When a syscall is executed in userland, register a0 contains
     * the number of the syscall. Registers a1, a2 and a3 contain the
     * arguments of the syscall. The userland code expects that after
     * returning from the syscall instruction the return value of the
     * syscall is found in register v0. Before entering this function
     * the userland context has been saved to user_context and after
     * returning from this function the userland context will be
     * restored from user_context.
     */
    switch(user_context->cpu_regs[MIPS_REGISTER_A0]) {
    case SYSCALL_HALT:
        halt_kernel();
        break;
    case SYSCALL_EXIT:
        syscall_exit(user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_WRITE:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_write(user_context->cpu_regs[MIPS_REGISTER_A1],
                          (char*)user_context->cpu_regs[MIPS_REGISTER_A2],
                          (user_context->cpu_regs[MIPS_REGISTER_A3]));
        break;
    case SYSCALL_READ:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_read(user_context->cpu_regs[MIPS_REGISTER_A1],
                         (char*)user_context->cpu_regs[MIPS_REGISTER_A2],
                         (user_context->cpu_regs[MIPS_REGISTER_A3]));
        break;
    case SYSCALL_JOIN:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
          syscall_join(user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_EXEC:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_exec((char*)user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_FORK:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_fork((void (*)(int))user_context->cpu_regs[MIPS_REGISTER_A1],
                         user_context->cpu_regs[MIPS_REGISTER_A2]);
        break;
    case SYSCALL_LOCK_CREATE:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_lock_create((lock_t*) user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_LOCK_ACQUIRE:
        syscall_lock_acquire((lock_t*) user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_LOCK_RELEASE:
        syscall_lock_release((lock_t*) user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_CONDITION_CREATE:
        user_context->cpu_regs[MIPS_REGISTER_V0] =
            syscall_condition_create((cond_t*) user_context->cpu_regs[MIPS_REGISTER_A1]);
        break;
    case SYSCALL_CONDITION_WAIT:
        syscall_condition_wait((cond_t*) user_context->cpu_regs[MIPS_REGISTER_A1],
                (lock_t*) user_context->cpu_regs[MIPS_REGISTER_A2]);
        break;
    case SYSCALL_CONDITION_SIGNAL:
        syscall_condition_signal((cond_t*) user_context->cpu_regs[MIPS_REGISTER_A1],
                (lock_t*) user_context->cpu_regs[MIPS_REGISTER_A2]);
        break;
    case SYSCALL_CONDITION_BROADCAST:
        syscall_condition_broadcast((cond_t*) user_context->cpu_regs[MIPS_REGISTER_A1],
                (lock_t*) user_context->cpu_regs[MIPS_REGISTER_A2]);
        break;
    default:
        KERNEL_PANIC("Unhandled system call\n");
    }
    /* Move to next instruction after system call */
    user_context->pc += 4;
}
Ejemplo n.º 13
0
Archivo: syscall.c Proyecto: mrb852/osm
/**
 * Handle system calls. Interrupts are enabled when this function is
 * called.
 *
 * @param user_context The userland context (CPU registers as they
 * where when system call instruction was called in userland)
 */
void syscall_handle(context_t *user_context)
{
  /* When a syscall is executed in userland, register a0 contains
   * the number of the syscall. Registers a1, a2 and a3 contain the
   * arguments of the syscall. The userland code expects that after
   * returning from the syscall instruction the return value of the
   * syscall is found in register v0. Before entering this function
   * the userland context has been saved to user_context and after
   * returning from this function the userland context will be
   * restored from user_context.
   */
  switch (A0) {
  case SYSCALL_HALT:
    halt_kernel();
    break;
  case SYSCALL_READ: {
      int filehandle = (int)A1;
      if (filehandle == FILEHANDLE_STDIN || filehandle == FILEHANDLE_STDOUT
        || filehandle == FILEHANDLE_STDERR) {
        V0 = io_read((int) A1, (void*) A2, (int) A3);
      } else {
        V0 = syscall_read((openfile_t)A1, (void *)A2, (int)A3);
      }
    }
    break;
  case SYSCALL_WRITE: {
      int filehandle = (int)A1;
      if (filehandle == FILEHANDLE_STDIN || filehandle == FILEHANDLE_STDOUT
        || filehandle == FILEHANDLE_STDERR) {
        V0 = io_write((int) A1, (void*) A2, (int) A3);
      } else {
        V0 = syscall_write((openfile_t)A1, (void *)A2, (int)A3);
      }
    }
    break;
  case SYSCALL_EXEC:
    V0 = syscall_exec((char*) A1);
    break;
  case SYSCALL_EXIT:
    syscall_exit((int) A1);
    break;
  case SYSCALL_JOIN:
    V0 = syscall_join((process_id_t) A1);
    break;
  case SYSCALL_OPEN:
    V0 = syscall_open((char *) A1);
  break;
  case SYSCALL_CLOSE:
    V0 = syscall_close((openfile_t) A1);
  break;
  case SYSCALL_SEEK:
    V0 = syscall_seek((openfile_t)A1, (int)A2);
  break;
  case SYSCALL_CREATE:
    V0 = syscall_create((const char *)A1, (int)A2);
  break;
  case SYSCALL_REMOVE:
    V0 = syscall_remove((const char *)A1);
  break;
  case SYSCALL_TELL:
    V0 = syscall_tell((openfile_t)A1);
  break;
  case SYSCALL_SEM_OPEN:
    V0 = (uint32_t) usr_sem_open((char*) A1, A2);
    break;
  case SYSCALL_SEM_PROCURE:
    V0 = usr_sem_p((usr_sem_t*) A1);
    break;
  case SYSCALL_SEM_VACATE:
    V0 = usr_sem_v((usr_sem_t*) A1);
    break;
  case SYSCALL_SEM_DESTROY:
    V0 = usr_sem_destroy((usr_sem_t*) A1);
    break;
  default:
    KERNEL_PANIC("Unhandled system call\n");
  }

  /* Move to next instruction after system call */
  user_context->pc += 4;
}