/*----------------------------------------------------------------------------- * return start and end offset for given section and module ID *----------------------------------------------------------------------------*/ static int section_module_start( Section *section, int module_id ) { int addr, *item; int i; int cur_size; init_module(); cur_size = intArray_size( section->module_start ); if ( cur_size > module_id ) addr = *( intArray_item( section->module_start, module_id ) ); else { addr = 0; for ( i = cur_size < 1 ? 0 : cur_size - 1; i < module_id; i++ ) { item = intArray_item( section->module_start, i ); if ( *item < addr ) *item = addr; else addr = *item; } /* update address with current code index */ item = intArray_item( section->module_start, module_id ); assert( get_section_size( section ) >= addr ); addr = *item = get_section_size( section ); } return addr; }
static int section_module_size( Section *section, int module_id ) { int last_module_id = get_last_module_id(); int addr, size; addr = section_module_start( section, module_id ); if ( module_id < last_module_id ) size = section_module_start( section, module_id + 1 ) - addr; else size = get_section_size( section ) - addr; return size; }
/*----------------------------------------------------------------------------- * compute total size of all sections *----------------------------------------------------------------------------*/ int get_sections_size( void ) { Section *section; SectionHashElem *iter; int size; size = 0; for ( section = get_first_section( &iter ) ; section != NULL ; section = get_next_section( &iter ) ) { size += get_section_size( section ); } return size; }
/*----------------------------------------------------------------------------- * allocate the addr of each of the sections, concatenating the sections in * consecutive addresses, or starting from a new address if a section * has a defined origin. Start at the command line origin, or at 0 if negative *----------------------------------------------------------------------------*/ void sections_alloc_addr(void) { Section *section; SectionHashElem *iter; int addr; init_module(); /* allocate addr in sequence */ addr = 0; for ( section = get_first_section( &iter ) ; section != NULL ; section = get_next_section( &iter ) ) { if ( section->origin >= 0 ) /* break in address space */ addr = section->origin; section->addr = addr; addr += get_section_size( section ); } }
static void parse_bindings() { struct section *sect; struct property *prop; struct binding *bind; char buf[128]; char *p; char *q; int n; // Parse driver bindings sect = find_section(krnlcfg, "bindings"); if (!sect) return; num_bindings = get_section_size(sect); if (!num_bindings) return; bindtab = (struct binding *) kmalloc(num_bindings * sizeof(struct binding)); memset(bindtab, 0, num_bindings * sizeof(struct binding)); n = 0; prop = sect->properties; while (prop) { bind = &bindtab[n]; strcpy(buf, prop->name); p = q = buf; while (*q && *q != ' ') q++; if (!*q) continue; *q++ = 0; if (strcmp(p, "pci") == 0) { bind->bustype = BUSTYPE_PCI; } else if (strcmp(p, "isa") == 0) { bind->bustype = BUSTYPE_ISA; } while (*q == ' ') q++; p = q; while (*q && *q != ' ') q++; if (!*q) continue; *q++ = 0; if (strcmp(p, "class") == 0) { bind->bindtype = BIND_BY_CLASSCODE; } else if (strcmp(p, "unit") == 0) { bind->bindtype = BIND_BY_UNITCODE; } else if (strcmp(p, "subunit") == 0) { bind->bindtype = BIND_BY_SUBUNITCODE; } while (*q == ' ') q++; while (*q) { unsigned long digit; unsigned long mask; mask = 0xF; if (*q >= '0' && *q <= '9') { digit = *q - '0'; } else if (*q >= 'A' && *q <= 'F') { digit = *q - 'A' + 10; } else if (*q >= 'a' && *q <= 'f') { digit = *q - 'a' + 10; } else { digit = 0; mask = 0; } bind->code = (bind->code << 4) | digit; bind->mask = (bind->mask << 4) | mask; q++; } bind->module = prop->value; prop = prop->next; n++; } }
/*----------------------------------------------------------------------------- * read/write whole code area to an open file *----------------------------------------------------------------------------*/ void fwrite_codearea(char *filename, FILE **pbinfile, FILE **prelocfile) { STR_DEFINE(new_name, FILENAME_MAX); Section *section; SectionHashElem *iter; int section_size; int cur_section_block_size; int cur_addr; init_module(); cur_addr = -1; cur_section_block_size = 0; for (section = get_first_section(&iter); section != NULL; section = get_next_section(&iter)) { section_size = get_section_size(section); if (cur_addr < 0) cur_addr = section->addr; /* bytes from this section */ if (section_size > 0) { if (section->name && *section->name) /* only if section name not empty */ { /* change current file if address changed, or option --split-bin, or section_split */ if ((!opts.relocatable && opts.split_bin) || section->section_split || cur_addr != section->addr || (section != get_first_section(NULL) && section->origin >= 0)) { str_set(new_name, path_remove_ext(filename)); /* "test" */ str_append_char(new_name, '_'); str_append(new_name, section->name); myfclose(*pbinfile); *pbinfile = myfopen(get_bin_filename(str_data(new_name)), "wb"); if (!*pbinfile) break; if (*prelocfile) { myfclose(*prelocfile); *prelocfile = myfopen(get_reloc_filename(str_data(new_name)), "wb"); cur_section_block_size = 0; } cur_addr = section->addr; } } xfput_chars(*pbinfile, (char *)ByteArray_item(section->bytes, 0), section_size); if (*prelocfile) { unsigned i; for (i = 0; i < intArray_size(section->reloc); i++) { xfput_uint16(*prelocfile, *(intArray_item(section->reloc, i)) + cur_section_block_size); } } cur_section_block_size += section_size; } cur_addr += section_size; } STR_DELETE(new_name); }
void init_jvm_args() { JavaVMOption *options; struct section *optsect; struct section *propsect; struct section *cpsect; int nopts; int n; struct property *prop; char *buf; char *p; int len; int first; cpsect = find_section(cfg, get_property(cfg, cfgname, "classpaths", "java.classpaths")); optsect = find_section(cfg, get_property(cfg, cfgname, "options", "java.options")); propsect = find_section(cfg, get_property(cfg, cfgname, "properties", "java.properties")); nopts = get_section_size(optsect) + get_section_size(propsect) + (cpsect ? 1 : 0); options = (JavaVMOption *) malloc(nopts * sizeof(JavaVMOption)); memset(options, 0, nopts * sizeof(JavaVMOption)); n = 0; if (cpsect) { len = strlen("-Djava.class.path=") + 1; prop = cpsect->properties; while (prop) { if (prop->name) len += strlen(prop->name) + 1; if (prop->value) len += strlen(prop->value) + 1; prop = prop->next; } buf = (char *) malloc(len); strcpy(buf, "-Djava.class.path="); p = buf + strlen(buf); first = 1; prop = cpsect->properties; while (prop) { if (!first) *p++ = ';'; first = 0; if (prop->name) { len = strlen(prop->name); memcpy(p, prop->name, len + 1); p += len; } if (prop->value) { *p++ = ':'; len = strlen(prop->value); memcpy(p, prop->value, len + 1); p += len; } prop = prop->next; } options[n++].optionString = buf; } if (optsect) { prop = optsect->properties; while (prop) { if (prop->value) { len = strlen(prop->name) + 1 + strlen(prop->value); buf = (char *) malloc(len + 1); strcpy(buf, prop->name); strcpy(buf + strlen(buf), ":"); strcpy(buf + strlen(buf), prop->value); } else { len = strlen(prop->name); buf = (char *) malloc(len + 1); strcpy(buf, prop->name); } options[n++].optionString = buf; prop = prop->next; } } if (propsect) { prop = propsect->properties; while (prop) { if (prop->value) { len = 2 + strlen(prop->name) + 1 + strlen(prop->value); } else { len = 2 + strlen(prop->name); } buf = (char *) malloc(len + 1); strcpy(buf, "-D"); strcpy(buf + strlen(buf), prop->name); if (prop->value) { strcpy(buf + strlen(buf), "="); strcpy(buf + strlen(buf), prop->value); } options[n++].optionString = buf; prop = prop->next; } } memset(&args, 0, sizeof(args)); args.version = JNI_VERSION_1_2; args.nOptions = nopts; args.options = options; args.ignoreUnrecognized = JNI_FALSE; }