/* initialize our runtime environment */ static void init_env(env_t env) { allocman_t *allocman; UNUSED reservation_t virtual_reservation; UNUSED int error; /* create an allocator */ allocman = bootstrap_use_current_simple(&env->simple, ALLOCATOR_STATIC_POOL_SIZE, allocator_mem_pool); assert(allocman); /* create a vka (interface for interacting with the underlying allocator) */ allocman_make_vka(&env->vka, allocman); /* create a vspace (virtual memory management interface). We pass * boot info not because it will use capabilities from it, but so * it knows the address and will add it as a reserved region */ error = sel4utils_bootstrap_vspace_with_bootinfo_leaky(&env->vspace, &data, simple_get_pd(&env->simple), &env->vka, seL4_GetBootInfo()); assert(error == 0); /* fill the allocator with virtual memory */ void *vaddr; virtual_reservation = vspace_reserve_range(&env->vspace, ALLOCATOR_VIRTUAL_POOL_SIZE, seL4_AllRights, 1, &vaddr); assert(virtual_reservation.res); bootstrap_configure_virtual_pool(allocman, vaddr, ALLOCATOR_VIRTUAL_POOL_SIZE, simple_get_pd(&env->simple)); // create endpoint error = vka_alloc_async_endpoint(&env->vka, &env->aep); assert(error == 0); }
static void init_timers() { // get an endpoint for the timer IRQ (interrupt handler) UNUSED int err = vka_alloc_async_endpoint(&vka, &timer_aep); assert(err == 0); // get the timer timer = sel4platsupport_get_default_timer(&vka, &vspace, &simple, timer_aep.cptr); assert(timer != NULL); // get a TSC timer (forward marching time); use // timer_get_time(tsc_timer) to get current time (in ns) tsc_timer = sel4platsupport_get_tsc_timer(timer); assert(tsc_timer != NULL); }
/*! @brief Creates a kernel endpoint object for the given process. Creates a kernel endpoint object for the given process. Also does the book-keeping underneath so that the created objects can be destroyed when the process exits. @param pcb Handle to the process to create the object for. (no ownership) @param type The kernel endpoint object type to create for the process; sync or async. @return Handle to the created object if successful (no ownership), NULL if there was an error. (eg. ran out of heap or untyped memory). */ static seL4_CPtr proc_syscall_allocate_endpoint(struct proc_pcb *pcb, kobject_t type) { assert(pcb && pcb->magic == REFOS_PCB_MAGIC); /* Allocate the kernel object. */ vka_object_t endpoint; int error = -1; if (type == KOBJECT_ENDPOINT_SYNC) { error = vka_alloc_endpoint(&procServ.vka, &endpoint); } else if (type == KOBJECT_ENDPOINT_ASYNC) { error = vka_alloc_async_endpoint(&procServ.vka, &endpoint); } else { assert(!"Invalid endpoint type."); } if (error || endpoint.cptr == 0) { ROS_ERROR("failed to allocate endpoint for process. Procserv out of memory.\n"); return 0; } /* Track this allocation, so it may be freed along with the process vspace. */ vs_track_obj(&pcb->vspace, endpoint); return endpoint.cptr; }
int main() { UNUSED int err; setup_system(); /* enable serial driver */ platsupport_serial_setup_simple(NULL, &simple, &vka); printf("\n\n>>>>>>>>>> multi-irqs <<<<<<<<<< \n\n"); simple_print(&simple); /* TODO: lots of duplicate code here ... */ chardev_t serial1; chardev_t serial2; chardev_t keyboard; struct ps_io_ops opsIO; sel4platsupport_get_io_port_ops(&opsIO.io_port_ops, &simple); ps_chardevice_t *ret; ret = ps_cdev_init(PS_SERIAL0, &opsIO, &serial1.dev); assert(ret != NULL); ret = ps_cdev_init(PS_SERIAL1, &opsIO, &serial2.dev); assert(ret != NULL); ret = ps_cdev_init(PC99_KEYBOARD_PS2, &opsIO, &keyboard.dev); assert(ret != NULL); /////////////////// /* async endpoint*/ vka_object_t aep; // create endpoint err = vka_alloc_async_endpoint(&vka, &aep); assert(err == 0); seL4_CapData_t badge1 = seL4_CapData_Badge_new (1); //mint a badged endpoint with badge value 1 err = vka_mint_object(&vka, &aep, &serial1.ep, seL4_AllRights, badge1); assert(err == 0); seL4_CapData_t badge2 = seL4_CapData_Badge_new (2); //mint a badged endpoint with badge value 2 err = vka_mint_object(&vka, &aep, &serial2.ep, seL4_AllRights, badge2); assert(err == 0); seL4_CapData_t badge3 = seL4_CapData_Badge_new (4); //mint a badged endpoint with badge value 4 err = vka_mint_object(&vka, &aep, &keyboard.ep, seL4_AllRights, badge3); assert(err == 0); /////////////////// set_devEp(&serial1); set_devEp(&serial2); set_devEp(&keyboard); for (;;) { seL4_Word sender_badge; printf("waiting:\n"); UNUSED seL4_MessageInfo_t msg = seL4_Wait(aep.cptr, &sender_badge); printf("seL4_Wait returned with badge: %d\n", sender_badge); if (sender_badge & 1) { handle_cdev_event("serial1", &serial1); } if (sender_badge & 2) { handle_cdev_event("serial2", &serial2); } if (sender_badge & 4) { handle_cdev_event("keyboard", &keyboard); } } return 0; }