int main() { const char test[] = "test\0"; usr_sem_t* dummy = syscall_usr_sem_open(test, 0); printf("Thread 1 is waiting for thread 2 to vacate\n"); syscall_spawn("[disk]sem_w.mips32", NULL); syscall_usr_sem_procure(dummy); printf("Thread 1 is alive and going to destroy semaphore\n"); syscall_usr_sem_destroy(dummy); syscall_halt(); return 0; }
int main() { usr_sem_t* sem = syscall_usr_sem_open("S1", 0); syscall_spawn("[disk]prog2.mips32", NULL); printf("Test (1) %d\n", 101); syscall_usr_sem_procure(sem); printf("Bjon (3)%d\n", 101); syscall_halt(); return 0; }
/** * 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*)arg1); break; case SYSCALL_WRITE: return syscall_write((const void*)arg1, (int)arg2); break; case SYSCALL_SPAWN: return syscall_spawn((char const*)arg0, (void*) arg1); break; case SYSCALL_EXIT: syscall_exit((int)arg0); break; case SYSCALL_JOIN: return process_join((int)arg0); break; default: KERNEL_PANIC("Unhandled system call\n"); } return 0; }
int main(void) { struct task *next; /* Set the CPU speed */ uint32_t skuid = read32(DEVICEID_BASE + DEVICEID_SKUID_OFFSET); uint32_t cpuspeed_id = skuid & DEVICEID_SKUID_CPUSPEED_MASK; uint32_t clksel_val = (1<<19) | 12; if(cpuspeed_id == DEVICEID_SKUID_CPUSPEED_720) clksel_val |= (720 << 8); else if(cpuspeed_id == DEVICEID_SKUID_CPUSPEED_600) clksel_val |= (600 << 8); else panic("Unsupported CPU!"); write32(CM_MPU_BASE + PRM_CLKSEL1_PLL_MPU_OFFSET, clksel_val); /* Basic hardware initialization */ init_cpumodes(); // set up CPU modes for interrupt handling intc_init(); // initialize interrupt controller gpio_init(); // initialize gpio interrupt system /* Start up hardware */ timers_init(); // must come first, since it initializes the watchdog eth_init(); uart_init(); /* For some reason, turning on the caches causes the kernel to hang after finishing the third invocation. Maybe we have to clear the caches here, or enable the MMU. */ printk("mmu init\n"); prep_pagetable(); init_mmu(); printk("cache init\n"); init_cache(); /* Initialize other interrupts */ init_interrupts(); /* Initialize task queues */ init_tasks(); /* Initialize idle task */ syscall_spawn(NULL, 7, idle_task, NULL, 0, SPAWN_DAEMON); pmu_enable(); trace_init(); printk("userspace init\n"); /* Initialize first user program */ syscall_spawn(NULL, 6, init_task, NULL, 0, 0); while (nondaemon_count > 0) { next = schedule(); task_activate(next); check_stack(next); } pmu_disable(); intc_reset(); eth_deinit(); deinit_mmu(); return 0; }