]> granicus.if.org Git - yasm/commitdiff
* arch.h (yasm_arch_min_insn_len): Get the minimum instruction length in
authorPeter Johnson <peter@tortall.net>
Sun, 29 Jan 2006 21:06:31 +0000 (21:06 -0000)
committerPeter Johnson <peter@tortall.net>
Sun, 29 Jan 2006 21:06:31 +0000 (21:06 -0000)
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

libyasm/arch.h
modules/arch/lc3b/lc3barch.c
modules/arch/x86/x86arch.c

index d4dc6fb7c58f339d580728a21e9f8f04a7127630..bb414355678e7078528380db4e85beacbcf2c43b 100644 (file)
@@ -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) \
index 6aca91e215bc104f71dbdc266f0a8742c9859df6..04e5a9d6b0f650bd2a60ed3f6dd88d60f41c9ae8 100644 (file)
@@ -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
 };
index b6aaeab0b5c3a07f88d2c7c2a1080b590577f730..02be78e1a4f7c7e1cf65b58acca2b1a2fad88f0f 100644 (file)
@@ -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
 };