#include #include #include #include #include #include int main(int argc, char **argv) { int xc_handle; uint32_t ssidref; xen_domain_handle_t handle; uint32_t flags; uint32_t domid; unsigned int mem_mb = 32; unsigned int mem_kb = mem_mb * 1024; int rc; char *kernel_img = "./mini-os.gz"; char uuid_str[37]; unsigned int store_evtchn, console_evtchn; unsigned long store_mfn, console_mfn; xc_handle = xc_interface_open(); if (xc_handle < 0) { printf("Error getting xc handle\n"); exit(0); } uuid_generate(handle); uuid_unparse(handle, uuid_str); printf("domain uuid:%s\n", uuid_str); ssidref = 0; flags = 0; rc = xc_domain_create(xc_handle, ssidref, handle, flags, &domid); if (rc) { printf("Error creating domain:%d\n", rc); exit(0); } printf("Created domain with ID:%u\n", domid); /*set max # of vcpus*/ rc = xc_domain_max_vcpus(xc_handle, domid, 1); if (rc) { printf("Unable to set max # of vcpus\n"); exit(0); } /*set max mem*/ rc = xc_domain_setmaxmem(xc_handle, domid, mem_kb); if (rc) { printf("Error setting max mem\n"); exit(0); } /*set memmap size*/ rc = xc_domain_set_memmap_limit(xc_handle, domid, mem_kb); if (rc) { printf("Error setting memmap size\n"); exit(0); } printf("Loading guest kernel\n"); /*allocate ports*/ store_evtchn = xc_evtchn_alloc_unbound(xc_handle, domid, 0); console_evtchn = xc_evtchn_alloc_unbound(xc_handle, domid, 0); printf("store evtchn:%u console evtchn:%u\n", store_evtchn, console_evtchn); /*load image using the linux builder*/ rc = xc_linux_build(xc_handle, domid, mem_mb, kernel_img, NULL, "", "", flags, store_evtchn, &store_mfn, console_evtchn, &console_mfn); if (rc) { printf("Unable to load guest kernel\n"); exit(0); } printf("store mfn:%lx console mfn:%lx\n", store_mfn, console_mfn); /*TODO store domain information in xenstore*/ /*TODO devices*/ /*unpause domain*/ rc = xc_domain_unpause(xc_handle, domid); if (rc) { printf("Unable to unpause domain\n"); exit(0); } xc_interface_close(xc_handle); return 0; }