const elf_machine_handler * elf_set_arch(yasm_arch *arch, yasm_symtab *symtab, int bits_pref) { const char *machine = yasm_arch_get_machine(arch); int i; for (i=0, elf_march = elf_machine_handlers[0]; elf_march != NULL; elf_march = elf_machine_handlers[++i]) { if (yasm__strcasecmp(yasm_arch_keyword(arch), elf_march->arch)==0) if (yasm__strcasecmp(machine, elf_march->machine)==0) if (bits_pref == 0 || bits_pref == elf_march->bits) break; } if (elf_march && elf_march->num_ssyms > 0) { /* Allocate "special" syms */ elf_ssyms = yasm_xmalloc(elf_march->num_ssyms * sizeof(yasm_symrec *)); for (i=0; (unsigned int)i<elf_march->num_ssyms; i++) { /* FIXME: misuse of NULL bytecode */ elf_ssyms[i] = yasm_symtab_define_label(symtab, elf_march->ssyms[i].name, NULL, 0, 0); } } return elf_march; }
void * yasm_load_module(yasm_module_type type, const char *keyword) { size_t i; module *modules; size_t n; /* Look for the module/symbol, first in loaded modules */ if (loaded_modules) { for (i=0; i<num_loaded_modules; i++) { if (loaded_modules[i].type == type && yasm__strcasecmp(loaded_modules[i].keyword, keyword) == 0) return loaded_modules[i].data; } } modules = module_types[type].m; n = module_types[type].n; for (i=0; i<n; i++) { if (yasm__strcasecmp(modules[i].keyword, keyword) == 0) return modules[i].data; } return NULL; }
int yasm_dir_helper(void *obj, yasm_valparam *vp_first, unsigned long line, const yasm_dir_help *help, size_t nhelp, void *data, int (*helper_valparam) (void *obj, yasm_valparam *vp, unsigned long line, void *data)) { yasm_valparam *vp = vp_first; int anymatched = 0; int matched; if (!vp) return 0; do { const char *s; size_t i; matched = 0; if (!vp->val && (s = yasm_vp_id(vp))) { for (i=0; i<nhelp; i++) { if (help[i].needsparam == 0 && yasm__strcasecmp(s, help[i].name) == 0) { if (help[i].helper(obj, vp, line, ((char *)data)+help[i].off, help[i].arg) != 0) return -1; matched = 1; anymatched = 1; break; } } } else if (vp->val) { for (i=0; i<nhelp; i++) { if (help[i].needsparam == 1 && yasm__strcasecmp(vp->val, help[i].name) == 0) { if (help[i].helper(obj, vp, line, ((char *)data)+help[i].off, help[i].arg) != 0) return -1; matched = 1; anymatched = 1; break; } } } if (!matched) { int final = helper_valparam(obj, vp, line, data); if (final < 0) return -1; if (final > 0) anymatched = 1; } } while((vp = yasm_vps_next(vp))); return anymatched; }
yasm_symrec * elf_get_special_sym(const char *name, const char *parser) { int i; for (i=0; (unsigned int)i<elf_march->num_ssyms; i++) { if (yasm__strcasecmp(name, elf_march->ssyms[i].name) == 0) return elf_ssyms[i]; } return NULL; }
static /*@only@*/ yasm_arch * x86_create(const char *machine, const char *parser, /*@out@*/ yasm_arch_create_error *error) { yasm_arch_x86 *arch_x86; unsigned int amd64_machine, address_size; *error = YASM_ARCH_CREATE_OK; if (yasm__strcasecmp(machine, "x86") == 0) { amd64_machine = 0; address_size = 32; } else if (yasm__strcasecmp(machine, "amd64") == 0) { amd64_machine = 1; address_size = 64; } else if (yasm__strcasecmp(machine, "x32") == 0) { amd64_machine = 1; address_size = 32; } else { *error = YASM_ARCH_CREATE_BAD_MACHINE; return NULL; } arch_x86 = yasm_xmalloc(sizeof(yasm_arch_x86)); arch_x86->arch.module = &yasm_x86_LTX_arch; /* default to all instructions/features enabled */ arch_x86->active_cpu = 0; arch_x86->cpu_enables_size = 1; arch_x86->cpu_enables = yasm_xmalloc(sizeof(wordptr)); arch_x86->cpu_enables[0] = BitVector_Create(64, FALSE); BitVector_Fill(arch_x86->cpu_enables[0]); arch_x86->amd64_machine = amd64_machine; arch_x86->mode_bits = 0; arch_x86->address_size = address_size; arch_x86->force_strict = 0; arch_x86->default_rel = 0; arch_x86->gas_intel_mode = 0; arch_x86->nop = X86_NOP_BASIC; if (yasm__strcasecmp(parser, "nasm") == 0) arch_x86->parser = X86_PARSER_NASM; else if (yasm__strcasecmp(parser, "tasm") == 0) arch_x86->parser = X86_PARSER_TASM; else if (yasm__strcasecmp(parser, "gas") == 0 || yasm__strcasecmp(parser, "gnu") == 0) arch_x86->parser = X86_PARSER_GAS; else { yasm_xfree(arch_x86); *error = YASM_ARCH_CREATE_BAD_PARSER; return NULL; } return (yasm_arch *)arch_x86; }
static int x86_set_var(yasm_arch *arch, const char *var, unsigned long val) { yasm_arch_x86 *arch_x86 = (yasm_arch_x86 *)arch; if (yasm__strcasecmp(var, "mode_bits") == 0) arch_x86->mode_bits = (unsigned int)val; else if (yasm__strcasecmp(var, "force_strict") == 0) arch_x86->force_strict = (unsigned int)val; else if (yasm__strcasecmp(var, "default_rel") == 0) { if (arch_x86->mode_bits != 64) yasm_warn_set(YASM_WARN_GENERAL, N_("ignoring default rel in non-64-bit mode")); else arch_x86->default_rel = (unsigned int)val; } else if (yasm__strcasecmp(var, "gas_intel_mode") == 0) { arch_x86->gas_intel_mode = (unsigned int)val; } else return 1; return 0; }
static /*@only@*/ yasm_arch * lc3b_create(const char *machine, const char *parser, /*@out@*/ yasm_arch_create_error *error) { yasm_arch_base *arch; *error = YASM_ARCH_CREATE_OK; if (yasm__strcasecmp(machine, "lc3b") != 0) { *error = YASM_ARCH_CREATE_BAD_MACHINE; return NULL; } if (yasm__strcasecmp(parser, "nasm") != 0) { *error = YASM_ARCH_CREATE_BAD_PARSER; return NULL; } arch = yasm_xmalloc(sizeof(yasm_arch_base)); arch->module = &yasm_lc3b_LTX_arch; return (yasm_arch *)arch; }
static yasm_objfmt * xdf_objfmt_create(yasm_object *object) { yasm_objfmt_xdf *objfmt_xdf = yasm_xmalloc(sizeof(yasm_objfmt_xdf)); /* Only support x86 arch */ if (yasm__strcasecmp(yasm_arch_keyword(object->arch), "x86") != 0) { yasm_xfree(objfmt_xdf); return NULL; } /* Support x86 and amd64 machines of x86 arch */ if (yasm__strcasecmp(yasm_arch_get_machine(object->arch), "x86") && yasm__strcasecmp(yasm_arch_get_machine(object->arch), "amd64")) { yasm_xfree(objfmt_xdf); return NULL; } objfmt_xdf->parse_scnum = 0; /* section numbering starts at 0 */ objfmt_xdf->objfmt.module = &yasm_xdf_LTX_objfmt; return (yasm_objfmt *)objfmt_xdf; }