void *atag_build() { struct memory_image image; struct tag *tag = (struct tag*)ATAG_BASE_ADDR; printf("building atags\n"); tag->hdr.tag = ATAG_CORE; tag->hdr.size = tag_size (tag_core); tag->u.core.flags = 0; tag->u.core.pagesize = 0x00001000; tag->u.core.rootdev = 0x0000; tag = tag_next(tag); if (image_find(IMG_CMDLINE, &image) != NULL) { char *atag_cmdline = tag->u.cmdline.cmdline; tag->hdr.tag = ATAG_CMDLINE; tag->hdr.size = (sizeof(struct tag_header) + image.size + 1 + 3) >> 2; memcpy(atag_cmdline, image.data, image.size); if (atag_cmdline[image.size-1] == '\xa') { atag_cmdline[image.size-1] = '\0'; } else { atag_cmdline[image.size] = '\0'; } printf("cmdline found[%s]\n", atag_cmdline); tag = tag_next(tag); }
/* If this function is NULL, polling is not needed */ static int display_update(void *handle, void *device, int x, int y, int w, int h) { UInt64 t1; UInt64 t2; int delta; IMAGE *img = image_find(handle, device); if (img == NULL) return -1; Microseconds((UnsignedWide*)&t1); delta = (t1 - img->update_time) / 1000000L; if (img->update_interval < 1) img->update_interval = 1; /* seconds */ if (delta < 0) img->update_time = t1; else if (delta > img->update_interval) { /* redraw window */ window_invalidate(img->windowRef); /* Make sure the update interval is at least 10 times * what it takes to paint the window */ Microseconds((UnsignedWide*)&t2); delta = (t2 - t1) / 1000; if (delta < 0) delta += 60000; /* delta = time to redraw */ if (delta > img->update_interval * 100) img->update_interval = delta/100; img->update_time = t2; } return gsdll_poll(handle); }
/* This is the last event from this device. */ static int display_close(void *handle, void *device) { IMAGE *img = image_find(handle, device); if (img == NULL) return -1; gsdll_poll(handle); /* remove from list */ if (img == first_image) first_image = img->next; else { IMAGE *tmp; for (tmp = first_image; tmp!=0; tmp=tmp->next) { if (img == tmp->next) tmp->next = img->next; } } DisposePixMap(img->pixmapHdl); // need to go in doCloseWindow() DisposeWindow(img->windowRef); free(img); return 0; }
int image_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) { _cleanup_free_ char *e = NULL; Manager *m = userdata; Image *image = NULL; const char *p; int r; assert(bus); assert(path); assert(interface); assert(found); p = startswith(path, "/org/freedesktop/machine1/image/"); if (!p) return 0; e = bus_label_unescape(p); if (!e) return -ENOMEM; image = hashmap_get(m->image_cache, e); if (image) { *found = image; return 1; } r = hashmap_ensure_allocated(&m->image_cache, &string_hash_ops); if (r < 0) return r; if (!m->image_cache_defer_event) { r = sd_event_add_defer(m->event, &m->image_cache_defer_event, image_flush_cache, m); if (r < 0) return r; r = sd_event_source_set_priority(m->image_cache_defer_event, SD_EVENT_PRIORITY_IDLE); if (r < 0) return r; } r = sd_event_source_set_enabled(m->image_cache_defer_event, SD_EVENT_ONESHOT); if (r < 0) return r; r = image_find(e, &image); if (r <= 0) return r; image->userdata = m; r = hashmap_put(m->image_cache, image->name, image); if (r < 0) { image_unref(image); return r; } *found = image; return 1; }
/* flushpage */ static int display_sync(void *handle, void *device) { IMAGE *img = image_find(handle, device); if (img == NULL) return -1; window_invalidate(img->windowRef); gsdll_poll(handle); return 0; }
/* New pointer to raster returned in pimage */ static int display_size(void *handle, void *device, int width, int height, int raster, unsigned int format, unsigned char *pimage) { PixMapPtr pixmap; IMAGE *img = image_find(handle, device); if (img == NULL) return -1; /* Check that image is within allowable bounds */ if (raster > 0x3fff) { printf("QuickDraw can't cope with an image this big.\n"); fflush(stdout); if (img->pixmapHdl) { DisposePixMap(img->pixmapHdl); img->pixmapHdl = NULL; } return e_rangecheck; } /* Create the PixMap */ if (!img->pixmapHdl) img->pixmapHdl = NewPixMap(); pixmap = *(img->pixmapHdl); pixmap->baseAddr = (char*)pimage; pixmap->rowBytes = (((SInt16)raster) & 0x3fff) | 0x8000; pixmap->bounds.right = width; pixmap->bounds.bottom = height; pixmap->packType = 0; pixmap->packSize = 0; pixmap->pixelType = RGBDirect; pixmap->pixelSize = 32; pixmap->cmpCount = 3; pixmap->cmpSize = 8; /* Update the display window */ window_adjust_scrollbars(img->windowRef); window_invalidate(img->windowRef); return gsdll_poll(handle); }
int main() { struct memory_image image; void *p; printf("milestone 2 loader\n"); image_complete(); image_dump_stats(); write32(2, 0x48200010); while(!(read32(0x48200014)&1)); if (image_find(IMG_LINUX, &image) != NULL) { printf("ARCH_NUBMBER[%d], KERNEL_DEST[%d]\n", ARCH_NUMBER, KERNEL_DEST); enter_kernel(0, ARCH_NUMBER, atag_build(), KERNEL_DEST); } else { critical_error(IMG_NOT_PROVIDED); } return 0; }
int main() { struct memory_image image; image_complete(); printf("Multiloader rev %s.\n", LDR_VERSION); image_dump_stats(); atlas_init(); if (atlas_test_io() != 0) { printf("btw, atlas i/o is not working\n"); } dsp_reboot(); hw_preboot(); if (image_find(IMG_LINUX, &image) != NULL) { jump_to_linux(image.data, 1024, atag_build()); } else { critical_error(IMG_NOT_PROVIDED); } return 0; }
static int import_tar(int argc, char *argv[], void *userdata) { _cleanup_(tar_import_unrefp) TarImport *import = NULL; _cleanup_event_unref_ sd_event *event = NULL; const char *path = NULL, *local = NULL; _cleanup_free_ char *ll = NULL; _cleanup_close_ int open_fd = -1; int r, fd; if (argc >= 2) path = argv[1]; if (isempty(path) || streq(path, "-")) path = NULL; if (argc >= 3) local = argv[2]; else if (path) local = basename(path); if (isempty(local) || streq(local, "-")) local = NULL; if (local) { r = tar_strip_suffixes(local, &ll); if (r < 0) return log_oom(); local = ll; if (!machine_name_is_valid(local)) { log_error("Local image name '%s' is not valid.", local); return -EINVAL; } if (!arg_force) { r = image_find(local, NULL); if (r < 0) return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local); else if (r > 0) { log_error_errno(EEXIST, "Image '%s' already exists.", local); return -EEXIST; } } } else local = "imported"; if (path) { open_fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY); if (open_fd < 0) return log_error_errno(errno, "Failed to open tar image to import: %m"); fd = open_fd; log_info("Importing '%s', saving as '%s'.", path, local); } else { _cleanup_free_ char *pretty = NULL; fd = STDIN_FILENO; (void) readlink_malloc("/proc/self/fd/0", &pretty); log_info("Importing '%s', saving as '%s'.", strna(pretty), local); } r = sd_event_default(&event); if (r < 0) return log_error_errno(r, "Failed to allocate event loop: %m"); assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); (void) sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL); (void) sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL); r = tar_import_new(&import, event, arg_image_root, on_tar_finished, event); if (r < 0) return log_error_errno(r, "Failed to allocate importer: %m"); r = tar_import_start(import, fd, local, arg_force, arg_read_only); if (r < 0) return log_error_errno(r, "Failed to import image: %m"); r = sd_event_loop(event); if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); log_info("Exiting."); return -r; }
static int pull_tar(int argc, char *argv[], void *userdata) { _cleanup_(tar_pull_unrefp) TarPull *pull = NULL; _cleanup_event_unref_ sd_event *event = NULL; const char *url, *local; _cleanup_free_ char *l = NULL, *ll = NULL; int r; url = argv[1]; if (!http_url_is_valid(url)) { log_error("URL '%s' is not valid.", url); return -EINVAL; } if (argc >= 3) local = argv[2]; else { r = import_url_last_component(url, &l); if (r < 0) return log_error_errno(r, "Failed get final component of URL: %m"); local = l; } if (isempty(local) || streq(local, "-")) local = NULL; if (local) { r = tar_strip_suffixes(local, &ll); if (r < 0) return log_oom(); local = ll; if (!machine_name_is_valid(local)) { log_error("Local image name '%s' is not valid.", local); return -EINVAL; } if (!arg_force) { r = image_find(local, NULL); if (r < 0) return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local); else if (r > 0) { log_error_errno(EEXIST, "Image '%s' already exists.", local); return -EEXIST; } } log_info("Pulling '%s', saving as '%s'.", url, local); } else log_info("Pulling '%s'.", url); r = sd_event_default(&event); if (r < 0) return log_error_errno(r, "Failed to allocate event loop: %m"); assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); (void) sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL); (void) sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL); r = tar_pull_new(&pull, event, arg_image_root, on_tar_finished, event); if (r < 0) return log_error_errno(r, "Failed to allocate puller: %m"); r = tar_pull_start(pull, url, local, arg_force, arg_verify, arg_settings); if (r < 0) return log_error_errno(r, "Failed to pull image: %m"); r = sd_event_loop(event); if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); log_info("Exiting."); return -r; }
static int pull_dkr(int argc, char *argv[], void *userdata) { _cleanup_(dkr_pull_unrefp) DkrPull *pull = NULL; _cleanup_event_unref_ sd_event *event = NULL; const char *name, *reference, *local, *digest; int r; if (!arg_dkr_index_url) { log_error("Please specify an index URL with --dkr-index-url="); return -EINVAL; } if (arg_verify != IMPORT_VERIFY_NO) { log_error("Pulls from dkr do not support image verification, please pass --verify=no."); return -EINVAL; } digest = strchr(argv[1], '@'); if (digest) { reference = digest + 1; name = strndupa(argv[1], digest - argv[1]); } else { reference = strchr(argv[1], ':'); if (reference) { name = strndupa(argv[1], reference - argv[1]); reference++; } else { name = argv[1]; reference = "latest"; } } if (!dkr_name_is_valid(name)) { log_error("Remote name '%s' is not valid.", name); return -EINVAL; } if (!dkr_ref_is_valid(reference)) { log_error("Tag name '%s' is not valid.", reference); return -EINVAL; } if (argc >= 3) local = argv[2]; else { local = strchr(name, '/'); if (local) local++; else local = name; } if (isempty(local) || streq(local, "-")) local = NULL; if (local) { if (!machine_name_is_valid(local)) { log_error("Local image name '%s' is not valid.", local); return -EINVAL; } if (!arg_force) { r = image_find(local, NULL); if (r < 0) return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local); else if (r > 0) { log_error_errno(EEXIST, "Image '%s' already exists.", local); return -EEXIST; } } log_info("Pulling '%s' with reference '%s', saving as '%s'.", name, reference, local); } else log_info("Pulling '%s' with reference '%s'.", name, reference); r = sd_event_default(&event); if (r < 0) return log_error_errno(r, "Failed to allocate event loop: %m"); assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0); (void) sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL); (void) sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL); r = dkr_pull_new(&pull, event, arg_dkr_index_url, arg_image_root, on_dkr_finished, event); if (r < 0) return log_error_errno(r, "Failed to allocate puller: %m"); r = dkr_pull_start(pull, name, reference, local, arg_force, DKR_PULL_V2); if (r < 0) return log_error_errno(r, "Failed to pull image: %m"); r = sd_event_loop(event); if (r < 0) return log_error_errno(r, "Failed to run event loop: %m"); log_info("Exiting."); return -r; }
int bus_image_acquire( Manager *m, sd_bus_message *message, const char *name_or_path, Image *image, ImageAcquireMode mode, const char *polkit_action, Image **ret, sd_bus_error *error) { _cleanup_(image_unrefp) Image *loaded = NULL; Image *cached; int r; assert(m); assert(message); assert(name_or_path || image); assert(mode >= 0); assert(mode < _BUS_IMAGE_ACQUIRE_MODE_MAX); assert(polkit_action || mode == BUS_IMAGE_REFUSE_BY_PATH); assert(ret); /* Acquires an 'Image' object if not acquired yet, and enforces necessary authentication while doing so. */ if (mode == BUS_IMAGE_AUTHENTICATE_ALL) { r = bus_verify_polkit_async( message, CAP_SYS_ADMIN, polkit_action, NULL, false, UID_INVALID, &m->polkit_registry, error); if (r < 0) return r; if (r == 0) { /* Will call us back */ *ret = NULL; return 0; } } /* Already passed in? */ if (image) { *ret = image; return 1; } /* Let's see if this image is already cached? */ cached = manager_image_cache_get(m, name_or_path); if (cached) { *ret = cached; return 1; } if (image_name_is_valid(name_or_path)) { /* If it's a short name, let's search for it */ r = image_find(IMAGE_PORTABLE, name_or_path, &loaded); if (r == -ENOENT) return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_PORTABLE_IMAGE, "No image '%s' found.", name_or_path); /* other errors are handled below… */ } else { /* Don't accept path if this is always forbidden */ if (mode == BUS_IMAGE_REFUSE_BY_PATH) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Expected image name, not path in place of '%s'.", name_or_path); if (!path_is_absolute(name_or_path)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is not valid or not a valid path.", name_or_path); if (!path_is_normalized(name_or_path)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image path '%s' is not normalized.", name_or_path); if (mode == BUS_IMAGE_AUTHENTICATE_BY_PATH) { r = bus_verify_polkit_async( message, CAP_SYS_ADMIN, polkit_action, NULL, false, UID_INVALID, &m->polkit_registry, error); if (r < 0) return r; if (r == 0) { /* Will call us back */ *ret = NULL; return 0; } } r = image_from_path(name_or_path, &loaded); } if (r == -EMEDIUMTYPE) { sd_bus_error_setf(error, BUS_ERROR_BAD_PORTABLE_IMAGE_TYPE, "Typ of image '%s' not recognized; supported image types are directories/btrfs subvolumes, block devices, and raw disk image files with suffix '.raw'.", name_or_path); return r; } if (r < 0) return r; /* Add what we just loaded to the cache. This has as side-effect that the object stays in memory until the * cache is purged again, i.e. at least for the current event loop iteration, which is all we need, and which * means we don't actually need to ref the return object. */ r = manager_image_cache_add(m, loaded); if (r < 0) return r; *ret = loaded; return 1; }
int turing_criteria (struct RootSet RS[SampleWorkN][MultiRootN], long unsigned int net, long unsigned int sam, long unsigned int samwork,int rn){ double partial[EdgeN]; double posi,nega,regu,dyn; int i,j; for(i=1;i<=EdgeN;i++) { if(Net[net].topology[i]!=0) { nega=1.0; for(j=((int)(i-1)/NodeN)*NodeN+1;j<=((int)(i-1)/NodeN)*NodeN+NodeN;j++){ if(i==j) continue; else if(Net[net].topology[j]==-1) nega/=(1.0+indeX(RS[samwork][rn].steady[(j-1)%NodeN]/Sample[sam].K[j],N[j])); } if(Net[net].topology[i]==1){ regu=indeX(Sample[sam].K[i]/RS[samwork][rn].steady[(i-1)%NodeN],N[i]); dyn=Sample[sam].h[(i-1)/NodeN]*N[i]*regu/(indeX(1.0+regu,2)*RS[samwork][rn].steady[(i-1)%NodeN])*nega; } else{ regu=indeX(RS[samwork][rn].steady[(i-1)%NodeN]/Sample[sam].K[i],N[i]); posi=0.0; for(j=((int)(i-1)/NodeN)*NodeN+1;j<=((int)(i-1)/NodeN)*NodeN+NodeN;j++){ if(Net[net].topology[j]==1) posi+=1.0/(1.0+indeX(Sample[sam].K[j]/RS[samwork][rn].steady[(j-1)%NodeN],N[j])); } dyn=-Sample[sam].h[(i-1)/NodeN]*N[i]*regu/(indeX(1.0+regu,2)*RS[samwork][rn].steady[(i-1)%NodeN])*posi*nega; } } else dyn=0.0; if((i-1)/NodeN==(i-1)%NodeN) dyn-=Sample[sam].g[(i-1)/NodeN]; partial[i-1]=dyn; RS[samwork][rn].partial[i-1]=dyn; } double point=0.5*EIGENSCAN_STEP; double max_eigen=0,tem_eigen,max_point=0,left_point=0.0,right_point=1.0; int on_off=0,n_interval=0,kappawork=0; do{ if(eigenscan_step(partial,sam,point,&tem_eigen)==GSL_SUCCESS) { if(max_eigen<tem_eigen) { max_eigen=tem_eigen; max_point=point; } if(on_off==0) { if(n_interval>=RealIntervalN){ n_interval++; break; } RS[samwork][rn].RE[n_interval].k_min=sqrt( EIGENVALUESCAN_MINKAPPA*pow(KAPPA_SCALE_RATIO, point) ); left_point=point; on_off=1; } else if(1.0-point<EIGENSCAN_STEP) { right_point=1.0; RS[samwork][rn].RE[n_interval].k_max=-1; if(max_point-left_point<EIGENSCAN_STEP) RS[samwork][rn].RE[n_interval].k_mid=-7.0; // -10~-5--> kc=0 else if(right_point-max_point<EIGENSCAN_STEP) RS[samwork][rn].RE[n_interval].k_mid=-3.0; // -5~0--> kc more than max_k else RS[samwork][rn].RE[n_interval].k_mid=sqrt(EIGENVALUESCAN_MINKAPPA*pow(KAPPA_SCALE_RATIO, max_point)); eigen_set(partial,RS,max_point,sam,samwork,rn,n_interval); image_find(RS, partial, net, sam, samwork, rn, n_interval, left_point, right_point); n_interval++; break; } } else if(on_off==1) { right_point=point; RS[samwork][rn].RE[n_interval].k_max=sqrt( EIGENVALUESCAN_MINKAPPA*pow(KAPPA_SCALE_RATIO, point) ); kappawork++; if(max_point-left_point<EIGENSCAN_STEP){ RS[samwork][rn].RE[n_interval].k_mid=-7.0; // -10~-5--> kc=0 } else if(right_point-max_point<EIGENSCAN_STEP){ RS[samwork][rn].RE[n_interval].k_mid=-3.0; // -5~0--> kc more than max_k } else{ RS[samwork][rn].RE[n_interval].k_mid=sqrt(EIGENVALUESCAN_MINKAPPA*pow(KAPPA_SCALE_RATIO, max_point)); } eigen_set(partial,RS,max_point,sam,samwork,rn,n_interval); image_find(RS, partial, net, sam, samwork, rn, n_interval, left_point, right_point); max_eigen=0; on_off=0; n_interval++; } point+=EIGENSCAN_STEP; }while(point<1.0); RS[samwork][rn].intervalReal=n_interval; if(n_interval==0 || kappawork==0) return GSL_CONTINUE; else return GSL_SUCCESS; }