From: Peter Johnson Date: Sun, 29 Jan 2006 21:06:31 +0000 (-0000) Subject: * arch.h (yasm_arch_min_insn_len): Get the minimum instruction length in X-Git-Tag: v0.5.0rc1~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f3e684dace107b50e09563e3e4b7bf06a70d23c4;p=yasm * arch.h (yasm_arch_min_insn_len): Get the minimum instruction length in bytes. (yasm_arch_get_address_size): Get the active address size in bits. * lc3barch.c, x86arch.c: Implement. These are needed for the DWARF2 dbgfmt, but may be useful for other things in the future. svn path=/trunk/yasm/; revision=1349 --- diff --git a/libyasm/arch.h b/libyasm/arch.h index d4dc6fb7..bb414355 100644 --- a/libyasm/arch.h +++ b/libyasm/arch.h @@ -105,6 +105,11 @@ typedef struct yasm_arch_module { */ const char * (*get_machine) (const yasm_arch *arch); + /** Module-level implementation of yasm_arch_get_address_size(). + * Call yasm_arch_get_address_size() instead of calling this function. + */ + unsigned int (*get_address_size) (const yasm_arch *arch); + /** Module-level implementation of yasm_arch_set_var(). * Call yasm_arch_set_var() instead of calling this function. */ @@ -247,6 +252,12 @@ typedef struct yasm_arch_module { * #yasm_arch. */ unsigned int wordsize; + + /** Worst case minimum instruction length in bytes. + * Call yasm_arch_min_insn_len() to get the minimum instruction length of + * a particular #yasm_arch. + */ + unsigned int min_insn_len; } yasm_arch_module; #ifdef YASM_LIB_INTERNAL @@ -306,6 +317,12 @@ const char *yasm_arch_keyword(const yasm_arch *arch); */ unsigned int yasm_arch_wordsize(const yasm_arch *arch); +/** Get the minimum instruction length of an architecture. + * \param arch architecture + * \return Minimum instruction length (in bytes). + */ +unsigned int yasm_arch_min_insn_len(const yasm_arch *arch); + /** Create architecture. * \param module architecture module * \param machine keyword of machine in use (must be one listed in @@ -330,6 +347,12 @@ void yasm_arch_destroy(/*@only@*/ yasm_arch *arch); */ const char *yasm_arch_get_machine(const yasm_arch *arch); +/** Get architecture's active address size, in bits. + * \param arch architecture + * \return Active address size (in bits). + */ +unsigned int yasm_arch_get_address_size(const yasm_arch *arch); + /** Set any arch-specific variables. For example, "mode_bits" in x86. * \param arch architecture * \param var variable name @@ -598,6 +621,8 @@ yasm_effaddr *yasm_arch_ea_create(yasm_arch *arch, /*@keep@*/ yasm_expr *e); (((yasm_arch_base *)arch)->module->keyword) #define yasm_arch_wordsize(arch) \ (((yasm_arch_base *)arch)->module->wordsize) +#define yasm_arch_min_insn_len(arch) \ + (((yasm_arch_base *)arch)->module->min_insn_len) #define yasm_arch_create(module, machine, parser, error) \ module->create(machine, parser, error) @@ -606,6 +631,8 @@ yasm_effaddr *yasm_arch_ea_create(yasm_arch *arch, /*@keep@*/ yasm_expr *e); ((yasm_arch_base *)arch)->module->destroy(arch) #define yasm_arch_get_machine(arch) \ ((yasm_arch_base *)arch)->module->get_machine(arch) +#define yasm_arch_get_address_size(arch) \ + ((yasm_arch_base *)arch)->module->get_address_size(arch) #define yasm_arch_set_var(arch, var, val) \ ((yasm_arch_base *)arch)->module->set_var(arch, var, val) #define yasm_arch_parse_cpu(arch, cpuid, line) \ diff --git a/modules/arch/lc3b/lc3barch.c b/modules/arch/lc3b/lc3barch.c index 6aca91e2..04e5a9d6 100644 --- a/modules/arch/lc3b/lc3barch.c +++ b/modules/arch/lc3b/lc3barch.c @@ -71,6 +71,12 @@ lc3b_get_machine(/*@unused@*/ const yasm_arch *arch) return "lc3b"; } +static unsigned int +lc3b_get_address_size(/*@unused@*/ const yasm_arch *arch) +{ + return 16; +} + static int lc3b_set_var(yasm_arch *arch, const char *var, unsigned long val) { @@ -167,6 +173,7 @@ yasm_arch_module yasm_lc3b_LTX_arch = { lc3b_create, lc3b_destroy, lc3b_get_machine, + lc3b_get_address_size, lc3b_set_var, yasm_lc3b__parse_cpu, yasm_lc3b__parse_check_reg, @@ -188,5 +195,6 @@ yasm_arch_module yasm_lc3b_LTX_arch = { lc3b_ea_create_expr, lc3b_machines, "lc3b", + 2, 2 }; diff --git a/modules/arch/x86/x86arch.c b/modules/arch/x86/x86arch.c index b6aaeab0..02be78e1 100644 --- a/modules/arch/x86/x86arch.c +++ b/modules/arch/x86/x86arch.c @@ -91,6 +91,18 @@ x86_get_machine(const yasm_arch *arch) return "x86"; } +static unsigned int +x86_get_address_size(const yasm_arch *arch) +{ + const yasm_arch_x86 *arch_x86 = (const yasm_arch_x86 *)arch; + if (arch_x86->mode_bits != 0) + return arch_x86->mode_bits; + if (arch_x86->amd64_machine) + return 64; + else + return 32; +} + static int x86_set_var(yasm_arch *arch, const char *var, unsigned long val) { @@ -362,6 +374,7 @@ yasm_arch_module yasm_x86_LTX_arch = { x86_create, x86_destroy, x86_get_machine, + x86_get_address_size, x86_set_var, yasm_x86__parse_cpu, yasm_x86__parse_check_reg, @@ -383,5 +396,6 @@ yasm_arch_module yasm_x86_LTX_arch = { yasm_x86__ea_create_expr, x86_machines, "x86", - 2 + 2, + 1 };