int l4x_kvm_create_vm(struct kvm *kvm) { l4_msgtag_t t; l4_utcb_t *u = l4_utcb(); int r; L4XV_V(f); kvm->arch.l4vmcap = L4_INVALID_CAP; if (l4lx_task_get_new_task(L4_INVALID_CAP, &kvm->arch.l4vmcap)) { printk("%s: could not allocate task cap\n", __func__); return -ENOENT; } L4XV_L(f); t = l4_factory_create_vm_u(l4re_env()->factory, kvm->arch.l4vmcap, u); if (unlikely((r = l4_error_u(t, u)))) { printk("%s: kvm task creation failed cap=%08lx: %d\n", __func__, kvm->arch.l4vmcap, r); l4lx_task_number_free(kvm->arch.l4vmcap); L4XV_U(f); return -ENOENT; } L4XV_U(f); printk("%s: cap = %08lx\n", __func__, kvm->arch.l4vmcap); #ifdef CONFIG_L4_DEBUG_REGISTER_NAMES L4XV_L(f); l4_debugger_set_object_name(kvm->arch.l4vmcap, "kvmVM"); L4XV_U(f); #endif return 0; }
int main(void) { l4re_env_t *env = l4re_env(); // get environment l4_msg_regs_t *mr = l4_utcb_mr(); // get msg regs char *str = "Hello, world!\n"; const int str_length = 15; mr->mr[0] = L4_VCON_WRITE_OP; mr->mr[1] = str_length; memcpy(&mr->mr[2], str, str_length); l4_msgtag_t tag, ret; tag = l4_msgtag(L4_PROTO_LOG, // long label (protocol) 6, // unsigned words 0, // unsigned items 0); // unsigned flags ret = l4_ipc_send(env->log, // l4_cap_idx_t dest l4_utcb(), // l4_utcb_t *utcb tag, // l4_msgtag_t tag L4_IPC_SEND_TIMEOUT_0); // l4_timeout_t timeout if (l4_msgtag_has_error(ret)) fprintf(stderr, "Error in message tag.\n"); }
int main(void) { l4_msgtag_t tag; #ifdef MEASURE l4_cpu_time_t s, e; #endif l4_utcb_t *u = l4_utcb(); l4_exc_regs_t exc; l4_umword_t mr0, mr1; printf("Alien feature testing\n"); l4_debugger_set_object_name(l4re_env()->main_thread, "alientest"); /* Start alien thread */ if (l4_is_invalid_cap(alien = l4re_util_cap_alloc())) return 1; l4_touch_rw(alien_thread_stack, sizeof(alien_thread_stack)); tag = l4_factory_create_thread(l4re_env()->factory, alien); if (l4_error(tag)) return 1; l4_debugger_set_object_name(alien, "alienth"); l4_thread_control_start(); l4_thread_control_pager(l4re_env()->main_thread); l4_thread_control_exc_handler(l4re_env()->main_thread); l4_thread_control_bind((l4_utcb_t *)l4re_env()->first_free_utcb, L4RE_THIS_TASK_CAP); l4_thread_control_alien(1); tag = l4_thread_control_commit(alien); if (l4_error(tag)) return 2; tag = l4_thread_ex_regs(alien, (l4_umword_t)alien_thread, (l4_umword_t)alien_thread_stack + sizeof(alien_thread_stack), 0); if (l4_error(tag)) return 3; l4_sched_param_t sp = l4_sched_param(1, 0); tag = l4_scheduler_run_thread(l4re_env()->scheduler, alien, &sp); if (l4_error(tag)) return 4; #ifdef MEASURE l4_calibrate_tsc(l4re_kip()); #endif /* Pager/Exception loop */ if (l4_msgtag_has_error(tag = l4_ipc_receive(alien, u, L4_IPC_NEVER))) { printf("l4_ipc_receive failed"); return 1; } memcpy(&exc, l4_utcb_exc(), sizeof(exc)); mr0 = l4_utcb_mr()->mr[0]; mr1 = l4_utcb_mr()->mr[1]; for (;;) { #ifdef MEASURE s = l4_rdtsc(); #endif if (l4_msgtag_is_exception(tag)) { #ifndef MEASURE printf("PC=%08lx SP=%08lx Err=%08lx Trap=%lx, %s syscall, SC-Nr: %lx\n", l4_utcb_exc_pc(&exc), exc.sp, exc.err, exc.trapno, (exc.err & 4) ? " after" : "before", exc.err >> 3); #endif tag = l4_msgtag((exc.err & 4) ? 0 : L4_PROTO_ALLOW_SYSCALL, L4_UTCB_EXCEPTION_REGS_SIZE, 0, 0); } else printf("Umm, non-handled request (like PF): %lx %lx\n", mr0, mr1); memcpy(l4_utcb_exc(), &exc, sizeof(exc)); /* Reply and wait */ if (l4_msgtag_has_error(tag = l4_ipc_call(alien, u, tag, L4_IPC_NEVER))) { printf("l4_ipc_call failed\n"); return 1; } memcpy(&exc, l4_utcb_exc(), sizeof(exc)); mr0 = l4_utcb_mr()->mr[0]; mr1 = l4_utcb_mr()->mr[1]; #ifdef MEASURE e = l4_rdtsc(); printf("time %lld\n", l4_tsc_to_ns(e - s)); #endif }
static int l4x_rtc_platform_probe(struct platform_device *pdev) { int r; if (l4x_re_resolve_name("rtc", &rtc_server)) { pr_err("l4x-rtc: Could not find 'rtc' cap.\n"); return -ENOENT; } irq_cap = l4x_cap_alloc(); if (l4_is_invalid_cap(irq_cap)) { pr_err("l4x-rtc: Could not allocate irq cap.\n"); return -ENOMEM; } if (L4XV_FN_e(l4_factory_create_irq(l4re_env()->factory, irq_cap))) { pr_err("l4x-rtc: Could not create user irq.\n"); r = -ENOMEM; goto free_cap; } if (L4XV_FN_e(l4_icu_bind(rtc_server, 0, irq_cap))) { pr_err("l4x-rtc: Error registering for time updates.\n"); r = -ENOSYS; goto free_irq_cap; } irq = l4x_register_irq(irq_cap); if (irq < 0) { pr_err("l4x-rtc: Error registering IRQ with L4Linux.\n"); r = irq; goto free_irq_cap; } r = request_irq(irq, l4x_rtc_int, IRQF_TRIGGER_RISING, "l4x_rtc", NULL); if (r) { pr_err("l4x-rtc: Could not register IRQ.\n"); goto unregister_irq; } if (l4x_rtc_update_offset()) { pr_err("l4x-rtc: Could not get the time offset to real time.\n"); r = -ENOSYS; goto free_irq; } rtc_dev = rtc_device_register(driver_name, &(pdev->dev), &l4x_rtc_ops, THIS_MODULE); if (IS_ERR(rtc_dev)) { pr_err("l4x-rtc: Could not register as rtc device.\n"); r = PTR_ERR(rtc_dev); goto free_irq; } INIT_WORK(&w_update_time, l4x_rtc_update_time); return 0; free_irq: free_irq(irq, NULL); unregister_irq: l4x_unregister_irq(irq); free_irq_cap: L4XV_FN_v(l4_task_release_cap(L4RE_THIS_TASK_CAP, irq_cap)); free_cap: l4x_cap_free(irq_cap); return r; }
int ux_probe(con_accel_t *accel) { struct l4_vhw_descriptor *vhw; struct l4_vhw_entry *vhwe; if (!l4util_kip_kernel_is_ux(l4re_kip())) return -L4_ENODEV; if (l4io_lookup_device("L4UXfb", NULL, 0, 0)) { printf("WARNING: Running under Fiasco-UX and no 'L4UXfb' device found, can only use polling mode!\n"); return -L4_ENODEV; } printf("Found Fiasco-UX Framebuffer\n"); if (!(vhw = l4_vhw_get(l4re_kip()))) return -L4_ENODEV; if (!(vhwe = l4_vhw_get_entry_type(vhw, L4_TYPE_VHW_FRAMEBUFFER))) return -L4_ENODEV; ux_con_pid = vhwe->provider_pid; accel->drty = uxScreenUpdate; accel->caps = ACCEL_POST_DIRTY; printf("Found VHW descriptor, provider is %d\n", ux_con_pid); l4_thread_control_start(); l4_thread_control_ux_host_syscall(1); l4_thread_control_commit(l4re_env()->main_thread); /* The update thread needs to run with the same priority than as the vc * threads (otherwise the screen won't be updated) */ { pthread_t update_tid; pthread_attr_t a; struct sched_param sp; pthread_attr_init(&a); sp.sched_priority = 0x70; pthread_attr_setschedpolicy(&a, SCHED_L4); pthread_attr_setschedparam(&a, &sp); pthread_attr_setinheritsched(&a, PTHREAD_EXPLICIT_SCHED); if (pthread_create(&update_tid, &a, updater_thread, NULL)) return -L4_ENOMEM; updater_id = pthread_getl4cap(update_tid); #if 0 update_tid = l4thread_create_long(L4THREAD_INVALID_ID, updater_thread, ".scr-upd", L4THREAD_INVALID_SP, L4THREAD_DEFAULT_SIZE, 0xff, NULL, L4THREAD_CREATE_ASYNC); if (update_tid < 0) { printf("Could not create updater thread.\n"); return -L4_ENOTHREAD; } updater_id = l4thread_l4_id(update_tid); #endif } #if 0 if (hw_vid_mem_addr != vhwe->mem_start || hw_vid_mem_size != vhwe->mem_size) printf("!!! Memory area mismatch "l4_addr_fmt"(%lx) vs. "l4_addr_fmt "(%lx) ... continuing\n", hw_vid_mem_addr, hw_vid_mem_size, vhwe->mem_start, vhwe->mem_size); #endif //map_io_mem(hw_vid_mem_addr, hw_vid_mem_size, 0, "UX video", // (l4_addr_t *)&hw_map_vid_mem_addr); // already mapped by vesa-ds + rm-attach hw_map_vid_mem_addr = hw_vid_mem_addr; return 0; }
/* Our main function */ int main(void) { /* Get a capability slot for our new thread. */ l4_cap_idx_t t1 = l4re_util_cap_alloc(); l4_utcb_t *u = l4_utcb(); l4_exc_regs_t *e = l4_utcb_exc_u(u); l4_msgtag_t tag; int err; extern char _start[], _end[], _etext[]; if (l4_is_invalid_cap(t1)) return 1; /* Prevent pagefaults of our new thread because we do not want to * implement a pager as well. */ l4_touch_ro(_start, _end - _start + 1); l4_touch_rw(_etext, _end - _etext); /* Create the thread using our default factory */ tag = l4_factory_create_thread(l4re_env()->factory, t1); if (l4_msgtag_has_error(tag)) return 1; /* Setup the thread by setting the pager and task. */ l4_thread_control_start(); l4_thread_control_pager(l4re_env()->main_thread); l4_thread_control_exc_handler(l4re_env()->main_thread); l4_thread_control_bind((l4_utcb_t *)l4re_env()->first_free_utcb, L4RE_THIS_TASK_CAP); tag = l4_thread_control_commit(t1); if (l4_msgtag_has_error(tag)) return 2; /* Start the thread by finally setting instruction and stack pointer */ tag = l4_thread_ex_regs(t1, (l4_umword_t)thread, (l4_umword_t)thread_stack + sizeof(thread_stack), L4_THREAD_EX_REGS_TRIGGER_EXCEPTION); if (l4_msgtag_has_error(tag)) return 3; /* Receive initial exception from just started thread */ tag = l4_ipc_receive(t1, u, L4_IPC_NEVER); if ((err = l4_ipc_error(tag, u))) { printf("Umm, ipc error: %x\n", err); return 1; } /* We expect an exception IPC */ if (!l4_msgtag_is_exception(tag)) { printf("PF?: %lx %lx (not prepared to handle this) %ld\n", l4_utcb_mr_u(u)->mr[0], l4_utcb_mr_u(u)->mr[1], l4_msgtag_label(tag)); return 1; } /* Fill out the complete register set of the new thread */ e->ip = (l4_umword_t)thread; e->sp = (l4_umword_t)(thread_stack + sizeof(thread_stack)); e->eax = 1; e->ebx = 4; e->ecx = 2; e->edx = 3; e->esi = 6; e->edi = 7; e->ebp = 5; /* Send a complete exception */ tag = l4_msgtag(0, L4_UTCB_EXCEPTION_REGS_SIZE, 0, 0); /* Send reply and start the thread with the defined CPU register set */ tag = l4_ipc_send(t1, u, tag, L4_IPC_NEVER); if ((err = l4_ipc_error(tag, u))) printf("Error sending IPC: %x\n", err); /* Idle around */ while (1) l4_sleep(10000); return 0; }
static int __init l4x_timer_init_ret(void) { int r; l4lx_thread_t thread; int irq; L4XV_V(f); timer_irq_cap = l4x_cap_alloc(); if (l4_is_invalid_cap(timer_irq_cap)) { printk(KERN_ERR "l4timer: Failed to alloc\n"); return -ENOMEM; } r = L4XV_FN_i(l4_error(l4_factory_create_irq(l4re_env()->factory, timer_irq_cap))); if (r) { printk(KERN_ERR "l4timer: Failed to create irq: %d\n", r); goto out1; } if ((irq = l4x_register_irq(timer_irq_cap)) < 0) { r = -ENOMEM; goto out2; } printk("l4timer: Using IRQ%d\n", irq); setup_irq(irq, &l4timer_irq); L4XV_L(f); thread = l4lx_thread_create (timer_thread, /* thread function */ smp_processor_id(), /* cpu */ NULL, /* stack */ &timer_irq_cap, sizeof(timer_irq_cap), /* data */ l4x_cap_alloc(), /* cap */ PRIO_TIMER, /* prio */ 0, /* vcpup */ "timer", /* name */ NULL); L4XV_U(f); timer_srv = l4lx_thread_get_cap(thread); if (!l4lx_thread_is_valid(thread)) { printk(KERN_ERR "l4timer: Failed to create thread\n"); r = -ENOMEM; goto out3; } l4timer_clockevent.irq = irq; l4timer_clockevent.mult = div_sc(1000000, NSEC_PER_SEC, l4timer_clockevent.shift); l4timer_clockevent.max_delta_ns = clockevent_delta2ns(0xffffffff, &l4timer_clockevent); l4timer_clockevent.min_delta_ns = clockevent_delta2ns(0xf, &l4timer_clockevent); l4timer_clockevent.cpumask = cpumask_of(0); clockevents_register_device(&l4timer_clockevent); return 0; out3: l4x_unregister_irq(irq); out2: L4XV_FN_v(l4_task_delete_obj(L4RE_THIS_TASK_CAP, timer_irq_cap)); out1: l4x_cap_free(timer_irq_cap); return r; }
/* Our main function */ int main(void) { /* Get a capability slot for our new thread. */ l4_cap_idx_t t1 = l4re_util_cap_alloc(); l4_utcb_t *u = l4_utcb(); l4_exc_regs_t *e = l4_utcb_exc_u(u); l4_msgtag_t tag; int err; printf("Example showing how to start a thread with an exception.\n"); /* We do not want to implement a pager here, take the shortcut. */ printf("Make sure to start this program with ldr-flags=eager_map\n"); if (l4_is_invalid_cap(t1)) return 1; /* Create the thread using our default factory */ tag = l4_factory_create_thread(l4re_env()->factory, t1); if (l4_error(tag)) return 1; /* Setup the thread by setting the pager and task. */ l4_thread_control_start(); l4_thread_control_pager(l4re_env()->main_thread); l4_thread_control_exc_handler(l4re_env()->main_thread); l4_thread_control_bind((l4_utcb_t *)l4re_env()->first_free_utcb, L4RE_THIS_TASK_CAP); tag = l4_thread_control_commit(t1); if (l4_error(tag)) return 2; /* Start the thread by finally setting instruction and stack pointer */ tag = l4_thread_ex_regs(t1, (l4_umword_t)thread, (l4_umword_t)thread_stack + sizeof(thread_stack), L4_THREAD_EX_REGS_TRIGGER_EXCEPTION); if (l4_error(tag)) return 3; l4_sched_param_t sp = l4_sched_param(1, 0); tag = l4_scheduler_run_thread(l4re_env()->scheduler, t1, &sp); if (l4_error(tag)) return 4; /* Receive initial exception from just started thread */ tag = l4_ipc_receive(t1, u, L4_IPC_NEVER); if ((err = l4_ipc_error(tag, u))) { printf("Umm, ipc error: %x\n", err); return 1; } /* We expect an exception IPC */ if (!l4_msgtag_is_exception(tag)) { printf("PF?: %lx %lx (not prepared to handle this) %ld\n", l4_utcb_mr_u(u)->mr[0], l4_utcb_mr_u(u)->mr[1], l4_msgtag_label(tag)); return 1; } /* Fill out the complete register set of the new thread */ e->sp = (l4_umword_t)(thread_stack + sizeof(thread_stack)); #ifdef ARCH_x86 e->ip = (l4_umword_t)thread; e->eax = 1; e->ebx = 4; e->ecx = 2; e->edx = 3; e->esi = 6; e->edi = 7; e->ebp = 5; #endif #ifdef ARCH_arm e->pc = (l4_umword_t)thread; e->r[0] = 0; e->r[1] = 1; e->r[2] = 2; e->r[3] = 3; e->r[4] = 4; e->r[5] = 5; e->r[6] = 6; e->r[7] = 7; #endif /* Send a complete exception */ tag = l4_msgtag(0, L4_UTCB_EXCEPTION_REGS_SIZE, 0, 0); /* Send reply and start the thread with the defined CPU register set */ tag = l4_ipc_send(t1, u, tag, L4_IPC_NEVER); if ((err = l4_ipc_error(tag, u))) printf("Error sending IPC: %x\n", err); /* Idle around */ while (1) l4_sleep(10000); return 0; }