seL4_timer_t *sel4platsupport_get_default_timer(vka_t *vka, UNUSED vspace_t *vspace, simple_t *simple, seL4_CPtr aep) { UNUSED int error = sel4platsupport_get_io_port_ops(&ops, simple); assert(error == 0); seL4_timer_t *pit = sel4platsupport_get_pit(vka, simple, &ops, aep); assert(pit != NULL); return pit; }
//============================================================================= int main(int argc, char *argv[]) { seL4_BootInfo *info = seL4_GetBootInfo(); /* initialize libsel4simple, which abstracts away which kernel version * we are running on */ #ifdef CONFIG_KERNEL_STABLE //experimental kernel simple_stable_init_bootinfo(&env.simple, info); #else //master kernel (currently) simple_default_init_bootinfo(&env.simple, info); #endif /* initialize the test environment - allocator, cspace manager, vspace manager, timer */ init_env(&env); /* enable serial driver */ platsupport_serial_setup_simple(NULL, &env.simple, &env.vka); simple_print(&env.simple); printf("\n\n>>>>>>>>>> keyboard - keyboard test <<<<<<<<<< \n\n"); printf("%d %s\n", argc, argv[0]); //from libsel4platsupport /* Set up keyboard device. */ printf("ps_cdev_init keyboard...\n"); struct ps_io_ops opsIO; sel4platsupport_get_io_port_ops(&opsIO.io_port_ops, &env.simple); ps_chardevice_t *devKeyboardRet; devKeyboardRet = ps_cdev_init(PC99_KEYBOARD_PS2, &opsIO, &conServ.devKeyboard); if (!devKeyboardRet) { printf("ERROR: could not initialize keyboard device.\n"); assert(!"ps_cdev_init failed."); exit(1); } //read from keyboard for(;;) { int c = ps_cdev_getchar(&conServ.devKeyboard); if (c != EOF) { printf("You typed [%c]\n", c); } fflush(stdout); } }
/* * Initialize all main data structures. * * The code to initialize simple, allocman, vka, and vspace is modeled * after the "sel4test-driver" app: * https://github.com/seL4/sel4test/blob/master/apps/sel4test-driver/src/main.c */ static void setup_system() { /* initialize boot information */ bootinfo = seL4_GetBootInfo(); bootinfo2 = seL4_IA32_GetBootInfo(); assert(bootinfo2); // boot kernel in graphics mode /* initialize simple interface */ simple_stable_init_bootinfo(&simple, bootinfo); //simple_default_init_bootinfo(simple, bootinfo); /* create an allocator */ allocman_t *allocman; allocman = bootstrap_use_current_simple(&simple, POOL_SIZE, memPool); assert(allocman); /* create a VKA */ allocman_make_vka(&vka, allocman); /* create a vspace */ UNUSED int err; err = sel4utils_bootstrap_vspace_with_bootinfo_leaky(&vspace, &allocData, seL4_CapInitThreadPD, &vka, bootinfo); assert(err == 0); /* fill allocator with virtual memory */ void *vaddr; UNUSED reservation_t vres; vres = vspace_reserve_range(&vspace, VIRT_POOL_SIZE, seL4_AllRights, 1, &vaddr); assert(vres.res); bootstrap_configure_virtual_pool(allocman, vaddr, VIRT_POOL_SIZE, seL4_CapInitThreadPD); /* initialize platsupport IO: virt memory */ err = sel4platsupport_new_io_mapper(simple, vspace, vka, &io_ops.io_mapper); assert(err == 0); /* initialize platsupport IO: ports */ err = sel4platsupport_get_io_port_ops(&io_ops.io_port_ops, &simple); assert(err == 0); }
seL4_timer_t * sel4platsupport_get_pit(vka_t *vka, simple_t *simple, ps_io_port_ops_t *ops, seL4_CPtr notification) { seL4_timer_t *pit = calloc(1, sizeof(*pit)); if (pit == NULL) { ZF_LOGE("Failed to malloc object of size %zu\n", sizeof(*pit)); return NULL; } /* initialise an io port ops interface if none was provided */ if (ops == NULL) { ops = calloc(1, sizeof(*ops)); if (ops == NULL) { ZF_LOGE("Failed to malloc object of size %zu", sizeof(*ops)); goto error; } /* store ops pointer in pit so it can be freed later */ pit->data = ops; if (sel4platsupport_get_io_port_ops(ops, simple) != 0) { ZF_LOGE("Failed to initialise io port ops"); goto error; } } else { pit->data = NULL; } pit->destroy = pit_destroyer; pit->handle_irq = timer_common_handle_irq; /* set up irq */ cspacepath_t dest; if (sel4platsupport_copy_irq_cap(vka, simple, PIT_INTERRUPT, &dest) != seL4_NoError) { goto error; } pit->irq = dest.capPtr; /* bind to endpoint */ if (seL4_IRQHandler_SetNotification(pit->irq, notification) != seL4_NoError) { ZF_LOGE("seL4_IRQHandler_SetEndpoint failed\n"); goto error; } /* ack (api hack) */ seL4_IRQHandler_Ack(pit->irq); /* finally set up the actual timer */ pit->timer = pit_get_timer(ops); if (pit->timer == NULL) { goto error; } /* sucess */ return pit; error: if (pit->irq != 0) { timer_common_cleanup_irq(vka, pit->irq); free(pit->data); free(pit); } return NULL; }
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; }