diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index 27eb8a21..55e18ff5 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -432,8 +432,18 @@ main(int argc, char *argv[]) /* Set up architecture using the selected (or default) machine and * selected (or default nasm) parser. */ - if (!machine_name) - machine_name = yasm__xstrdup(cur_arch_module->default_machine_keyword); + if (!machine_name) { + /* If we're using x86 and the default objfmt bits is 64, default the + * machine to amd64. When we get more arches with multiple machines, + * we should do this in a more modular fashion. + */ + if (strcmp(cur_arch_module->keyword, "x86") == 0 && + cur_objfmt_module->default_x86_mode_bits == 64) + machine_name = yasm__xstrdup("amd64"); + else + machine_name = + yasm__xstrdup(cur_arch_module->default_machine_keyword); + } cur_arch = cur_arch_module->create(machine_name, cur_parser_module->keyword, @@ -538,6 +548,9 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } + /* Get a fresh copy of objfmt_module as it may have changed. */ + cur_objfmt_module = ((yasm_objfmt_base *)cur_objfmt)->module; + /* Add an initial "default" section to object */ def_sect = yasm_objfmt_add_default_section(cur_objfmt, object); @@ -593,13 +606,10 @@ main(int argc, char *argv[]) apply_preproc_builtins(); apply_preproc_saved_options(); - /* Get initial x86 BITS setting from object format except for amd64 mode */ + /* Get initial x86 BITS setting from object format */ if (strcmp(cur_arch_module->keyword, "x86") == 0) { - if (strcmp(machine_name, "amd64") == 0) - yasm_arch_set_var(cur_arch, "mode_bits", 64); - else - yasm_arch_set_var(cur_arch, "mode_bits", - cur_objfmt_module->default_x86_mode_bits); + yasm_arch_set_var(cur_arch, "mode_bits", + cur_objfmt_module->default_x86_mode_bits); } /* Parse! */ diff --git a/modules/objfmts/Makefile.inc b/modules/objfmts/Makefile.inc index 01c963b3..b5b89945 100644 --- a/modules/objfmts/Makefile.inc +++ b/modules/objfmts/Makefile.inc @@ -6,6 +6,7 @@ EXTRA_DIST += modules/objfmts/elf/Makefile.inc #!EXTRA_DIST += modules/objfmts/omf/Makefile.inc EXTRA_DIST += modules/objfmts/coff/Makefile.inc EXTRA_DIST += modules/objfmts/win32/Makefile.inc +EXTRA_DIST += modules/objfmts/win64/Makefile.inc EXTRA_DIST += modules/objfmts/xdf/Makefile.inc include modules/objfmts/dbg/Makefile.inc @@ -14,4 +15,5 @@ include modules/objfmts/elf/Makefile.inc #!include modules/objfmts/omf/Makefile.inc include modules/objfmts/coff/Makefile.inc include modules/objfmts/win32/Makefile.inc +include modules/objfmts/win64/Makefile.inc include modules/objfmts/xdf/Makefile.inc diff --git a/modules/objfmts/coff/coff-objfmt.c b/modules/objfmts/coff/coff-objfmt.c index 48504739..2911115f 100644 --- a/modules/objfmts/coff/coff-objfmt.c +++ b/modules/objfmts/coff/coff-objfmt.c @@ -213,6 +213,7 @@ static const yasm_assoc_data_callback coff_symrec_data_cb = { yasm_objfmt_module yasm_coff_LTX_objfmt; yasm_objfmt_module yasm_win32_LTX_objfmt; +yasm_objfmt_module yasm_win64_LTX_objfmt; static /*@dependent@*/ coff_symrec_data * @@ -252,16 +253,6 @@ coff_common_create(const char *in_filename, yasm_object *object, yasm_arch *a) return NULL; } - /* Support x86 and amd64 machines of x86 arch */ - if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0) { - objfmt_coff->machine = COFF_MACHINE_I386; - } else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) { - objfmt_coff->machine = COFF_MACHINE_AMD64; - } else { - yasm_xfree(objfmt_coff); - return NULL; - } - objfmt_coff->parse_scnum = 1; /* section numbering starts at 1 */ /* FIXME: misuse of NULL bytecode here; it works, but only barely. */ @@ -279,7 +270,18 @@ coff_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) { yasm_objfmt_coff *objfmt_coff = coff_common_create(in_filename, object, a); + if (objfmt_coff) { + /* Support x86 and amd64 machines of x86 arch */ + if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0) { + objfmt_coff->machine = COFF_MACHINE_I386; + } else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) { + objfmt_coff->machine = COFF_MACHINE_AMD64; + } else { + yasm_xfree(objfmt_coff); + return NULL; + } + objfmt_coff->objfmt.module = &yasm_coff_LTX_objfmt; objfmt_coff->win32 = 0; } @@ -291,8 +293,43 @@ win32_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) { yasm_objfmt_coff *objfmt_coff = coff_common_create(in_filename, object, a); + + if (objfmt_coff) { + /* Support x86 and amd64 machines of x86 arch. + * (amd64 machine supported for backwards compatibility) + */ + if (yasm__strcasecmp(yasm_arch_get_machine(a), "x86") == 0) { + objfmt_coff->machine = COFF_MACHINE_I386; + objfmt_coff->objfmt.module = &yasm_win32_LTX_objfmt; + } else if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) { + objfmt_coff->machine = COFF_MACHINE_AMD64; + objfmt_coff->objfmt.module = &yasm_win64_LTX_objfmt; + } else { + yasm_xfree(objfmt_coff); + return NULL; + } + + objfmt_coff->win32 = 1; + } + return (yasm_objfmt *)objfmt_coff; +} + +static yasm_objfmt * +win64_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +{ + yasm_objfmt_coff *objfmt_coff = + coff_common_create(in_filename, object, a); + if (objfmt_coff) { - objfmt_coff->objfmt.module = &yasm_win32_LTX_objfmt; + /* Support amd64 machine of x86 arch */ + if (yasm__strcasecmp(yasm_arch_get_machine(a), "amd64") == 0) { + objfmt_coff->machine = COFF_MACHINE_AMD64; + } else { + yasm_xfree(objfmt_coff); + return NULL; + } + + objfmt_coff->objfmt.module = &yasm_win64_LTX_objfmt; objfmt_coff->win32 = 1; } return (yasm_objfmt *)objfmt_coff; @@ -1407,3 +1444,22 @@ yasm_objfmt_module yasm_win32_LTX_objfmt = { coff_objfmt_common_declare, win32_objfmt_directive }; + +/* Define objfmt structure -- see objfmt.h for details */ +yasm_objfmt_module yasm_win64_LTX_objfmt = { + "Win64", + "win64", + "obj", + ".text", + 64, + coff_objfmt_dbgfmt_keywords, + "null", + win64_objfmt_create, + coff_objfmt_output, + coff_objfmt_destroy, + coff_objfmt_section_switch, + coff_objfmt_extern_declare, + coff_objfmt_global_declare, + coff_objfmt_common_declare, + win32_objfmt_directive +}; diff --git a/modules/objfmts/elf/Makefile.inc b/modules/objfmts/elf/Makefile.inc index 07027326..7e37b5ba 100644 --- a/modules/objfmts/elf/Makefile.inc +++ b/modules/objfmts/elf/Makefile.inc @@ -7,7 +7,7 @@ libyasm_a_SOURCES += modules/objfmts/elf/elf-machine.h libyasm_a_SOURCES += modules/objfmts/elf/elf-x86-x86.c libyasm_a_SOURCES += modules/objfmts/elf/elf-x86-amd64.c -YASM_MODULES += objfmt_elf +YASM_MODULES += objfmt_elf objfmt_elf32 objfmt_elf64 EXTRA_DIST += modules/objfmts/elf/tests/Makefile.inc diff --git a/modules/objfmts/elf/elf-machine.h b/modules/objfmts/elf/elf-machine.h index 2a375971..9eb896fc 100644 --- a/modules/objfmts/elf/elf-machine.h +++ b/modules/objfmts/elf/elf-machine.h @@ -74,7 +74,7 @@ typedef struct { const int sym_rel; /* symbol or section-relative? */ } elf_machine_ssym; -typedef struct { +struct elf_machine_handler { const char *arch; const char *machine; const char *reloc_section_prefix; @@ -94,6 +94,8 @@ typedef struct { const elf_machine_ssym *ssyms; /* array of "special" syms */ const size_t num_ssyms; /* size of array */ -} elf_machine_handler; + + const int bits; /* usually 32 or 64 */ +}; #endif /* ELF_MACHINE_H_INCLUDED */ diff --git a/modules/objfmts/elf/elf-objfmt.c b/modules/objfmts/elf/elf-objfmt.c index af0622a2..613f58ef 100644 --- a/modules/objfmts/elf/elf-objfmt.c +++ b/modules/objfmts/elf/elf-objfmt.c @@ -50,6 +50,7 @@ #include #include "elf.h" +#include "elf-machine.h" typedef struct yasm_objfmt_elf { yasm_objfmt_base objfmt; /* base structure */ @@ -80,6 +81,8 @@ typedef struct { } append_local_sym_info; yasm_objfmt_module yasm_elf_LTX_objfmt; +yasm_objfmt_module yasm_elf32_LTX_objfmt; +yasm_objfmt_module yasm_elf64_LTX_objfmt; static elf_symtab_entry * @@ -146,20 +149,27 @@ elf_objfmt_append_local_sym(yasm_symrec *sym, /*@null@*/ void *d) } static yasm_objfmt * -elf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +elf_objfmt_create_common(const char *in_filename, yasm_object *object, + yasm_arch *a, yasm_objfmt_module *module, + int bits_pref, + const elf_machine_handler **elf_march_out) { yasm_objfmt_elf *objfmt_elf = yasm_xmalloc(sizeof(yasm_objfmt_elf)); yasm_symrec *filesym; elf_symtab_entry *entry; + const elf_machine_handler *elf_march; - objfmt_elf->objfmt.module = &yasm_elf_LTX_objfmt; + objfmt_elf->objfmt.module = module; objfmt_elf->object = object; objfmt_elf->symtab = yasm_object_get_symtab(object); objfmt_elf->arch = a; - if (!elf_set_arch(a, objfmt_elf->symtab)) { + elf_march = elf_set_arch(a, objfmt_elf->symtab, bits_pref); + if (!elf_march) { yasm_xfree(objfmt_elf); return NULL; } + if (elf_march_out) + *elf_march_out = elf_march; objfmt_elf->shstrtab = elf_strtab_create(); objfmt_elf->strtab = elf_strtab_create(); @@ -181,6 +191,40 @@ elf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) return (yasm_objfmt *)objfmt_elf; } +static yasm_objfmt * +elf_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +{ + const elf_machine_handler *elf_march; + yasm_objfmt *objfmt; + yasm_objfmt_elf *objfmt_elf; + + objfmt = elf_objfmt_create_common(in_filename, object, a, + &yasm_elf_LTX_objfmt, 0, &elf_march); + if (objfmt) { + objfmt_elf = (yasm_objfmt_elf *)objfmt; + /* Figure out which bitness of object format to use */ + if (elf_march->bits == 32) + objfmt_elf->objfmt.module = &yasm_elf32_LTX_objfmt; + else if (elf_march->bits == 64) + objfmt_elf->objfmt.module = &yasm_elf64_LTX_objfmt; + } + return objfmt; +} + +static yasm_objfmt * +elf32_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +{ + return elf_objfmt_create_common(in_filename, object, a, + &yasm_elf32_LTX_objfmt, 32, NULL); +} + +static yasm_objfmt * +elf64_objfmt_create(const char *in_filename, yasm_object *object, yasm_arch *a) +{ + return elf_objfmt_create_common(in_filename, object, a, + &yasm_elf64_LTX_objfmt, 64, NULL); +} + static long elf_objfmt_output_align(FILE *f, unsigned int align) { @@ -980,3 +1024,39 @@ yasm_objfmt_module yasm_elf_LTX_objfmt = { elf_objfmt_common_declare, elf_objfmt_directive }; + +yasm_objfmt_module yasm_elf32_LTX_objfmt = { + "ELF (32-bit)", + "elf32", + "o", + ".text", + 32, + elf_objfmt_dbgfmt_keywords, + "null", + elf32_objfmt_create, + elf_objfmt_output, + elf_objfmt_destroy, + elf_objfmt_section_switch, + elf_objfmt_extern_declare, + elf_objfmt_global_declare, + elf_objfmt_common_declare, + elf_objfmt_directive +}; + +yasm_objfmt_module yasm_elf64_LTX_objfmt = { + "ELF (64-bit)", + "elf64", + "o", + ".text", + 64, + elf_objfmt_dbgfmt_keywords, + "null", + elf64_objfmt_create, + elf_objfmt_output, + elf_objfmt_destroy, + elf_objfmt_section_switch, + elf_objfmt_extern_declare, + elf_objfmt_global_declare, + elf_objfmt_common_declare, + elf_objfmt_directive +}; diff --git a/modules/objfmts/elf/elf-x86-amd64.c b/modules/objfmts/elf/elf-x86-amd64.c index 27bfb1c3..a8c62031 100644 --- a/modules/objfmts/elf/elf-x86-amd64.c +++ b/modules/objfmts/elf/elf-x86-amd64.c @@ -233,5 +233,6 @@ elf_machine_handler_x86_amd64 = { elf_x86_amd64_write_reloc, elf_x86_amd64_write_proghead, elf_x86_amd64_ssyms, - sizeof(elf_x86_amd64_ssyms)/sizeof(elf_x86_amd64_ssyms[0]) + sizeof(elf_x86_amd64_ssyms)/sizeof(elf_x86_amd64_ssyms[0]), + 64 }; diff --git a/modules/objfmts/elf/elf-x86-x86.c b/modules/objfmts/elf/elf-x86-x86.c index d585a398..5da22aa1 100644 --- a/modules/objfmts/elf/elf-x86-x86.c +++ b/modules/objfmts/elf/elf-x86-x86.c @@ -223,5 +223,6 @@ elf_machine_handler_x86_x86 = { elf_x86_x86_write_reloc, elf_x86_x86_write_proghead, elf_x86_x86_ssyms, - sizeof(elf_x86_x86_ssyms)/sizeof(elf_x86_x86_ssyms[0]) + sizeof(elf_x86_x86_ssyms)/sizeof(elf_x86_x86_ssyms[0]), + 32 }; diff --git a/modules/objfmts/elf/elf.c b/modules/objfmts/elf/elf.c index 4659a811..4081f70a 100644 --- a/modules/objfmts/elf/elf.c +++ b/modules/objfmts/elf/elf.c @@ -63,12 +63,12 @@ static const elf_machine_handler *elf_machine_handlers[] = }; static const elf_machine_handler elf_null_machine = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0}; + 0, 0, 0}; static elf_machine_handler const *elf_march = &elf_null_machine; static yasm_symrec **elf_ssyms; -int -elf_set_arch(yasm_arch *arch, yasm_symtab *symtab) +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; @@ -79,7 +79,8 @@ elf_set_arch(yasm_arch *arch, yasm_symtab *symtab) { if (yasm__strcasecmp(yasm_arch_keyword(arch), elf_march->arch)==0) if (yasm__strcasecmp(machine, elf_march->machine)==0) - break; + if (bits_pref == 0 || bits_pref == elf_march->bits) + break; } if (elf_march && elf_march->num_ssyms > 0) @@ -96,7 +97,7 @@ elf_set_arch(yasm_arch *arch, yasm_symtab *symtab) } } - return elf_march != NULL; + return elf_march; } /* reloc functions */ diff --git a/modules/objfmts/elf/elf.h b/modules/objfmts/elf/elf.h index 909e7a13..c32ff808 100644 --- a/modules/objfmts/elf/elf.h +++ b/modules/objfmts/elf/elf.h @@ -36,6 +36,8 @@ typedef struct elf_strtab_head elf_strtab_head; typedef struct elf_symtab_entry elf_symtab_entry; typedef struct elf_symtab_head elf_symtab_head; +typedef struct elf_machine_handler elf_machine_handler; + typedef unsigned long elf_address; typedef unsigned long elf_offset; typedef unsigned long elf_size; @@ -399,7 +401,9 @@ extern const yasm_assoc_data_callback elf_section_data; extern const yasm_assoc_data_callback elf_symrec_data; -int elf_set_arch(struct yasm_arch *arch, yasm_symtab *symtab); +const elf_machine_handler *elf_set_arch(struct yasm_arch *arch, + yasm_symtab *symtab, + int bits_pref); /* reloc functions */ int elf_is_wrt_sym_relative(yasm_symrec *wrt); diff --git a/modules/objfmts/win64/Makefile.inc b/modules/objfmts/win64/Makefile.inc new file mode 100644 index 00000000..003ca6a5 --- /dev/null +++ b/modules/objfmts/win64/Makefile.inc @@ -0,0 +1,9 @@ +# $Id$ + +# Assume objfmt_coff is included + +YASM_MODULES += objfmt_win64 + +EXTRA_DIST += modules/objfmts/win64/tests/Makefile.inc + +include modules/objfmts/win64/tests/Makefile.inc diff --git a/modules/objfmts/win64/tests/Makefile.inc b/modules/objfmts/win64/tests/Makefile.inc new file mode 100644 index 00000000..d6aa6a47 --- /dev/null +++ b/modules/objfmts/win64/tests/Makefile.inc @@ -0,0 +1,5 @@ +# $Id$ + +TESTS += modules/objfmts/win64/tests/win64_test.sh + +EXTRA_DIST += modules/objfmts/win32/tests/win64_test.sh diff --git a/modules/objfmts/win64/tests/win64-dataref.asm b/modules/objfmts/win64/tests/win64-dataref.asm new file mode 100644 index 00000000..e98c7417 --- /dev/null +++ b/modules/objfmts/win64/tests/win64-dataref.asm @@ -0,0 +1,109 @@ +BITS 64 + +global x86ident +global __savident +extern foobar ; :proc +extern foobar2 ; :abs +extern foobar3 ; :qword +extern foobar4 ; :byte + +[SECTION .data] +__savident dd 0 +savidentptr dd __savident +savidentptr2 dq __savident +x86identptr dd x86ident +x86identptr2 dq x86ident +foobarptr dd foobar +foobarptr2 dq foobar +foobar2ptr dd foobar2 +foobar2ptr2 dq foobar2 +foobar3ptr dd foobar3 +foobar3ptr2 dq foobar3 +xptr dd x +xptr2 dq x + +[SECTION .bss] +x resq 1 + +[SECTION .text] +x86ident: + ; with :proc + mov ebx, foobar ; WTF ML64.. this had [] + mov rcx, foobar + lea rdx, [foobar wrt rip] + mov rax, [foobar+rcx] + mov rax, foobar + mov rbx, foobar + movzx rax, byte [foobar wrt rip] + movzx rax, byte [foobar+rax] + + ; with :abs + ;mov ebx,[foobar2] + ;mov rcx,offset foobar2 + ;lea rdx, foobar2 + ;mov rax, qword ptr foobar2[rcx] + ;mov rax, foobar2 + ;mov rbx, foobar2 + ;movzx rax, byte ptr foobar2 + ;movzx rax, byte ptr foobar2[rax] + + ; with :qword + mov ebx, [foobar3 wrt rip] + mov rcx, foobar3 + lea rdx, [foobar3 wrt rip] + mov rax, [foobar3+rcx] + mov rax, [foobar3 wrt rip] + mov rbx, [foobar3 wrt rip] + movzx rax, byte [foobar3 wrt rip] + movzx rax, byte [foobar3+rax] + + ; local var (dword) + mov ebx,[__savident wrt rip] + mov rcx, __savident + lea rdx, [__savident wrt rip] + mov rax, [__savident+rcx] + mov rax, [__savident wrt rip] + mov rbx, [__savident wrt rip] + movzx rax, byte [__savident wrt rip] + movzx rax, byte [__savident+rax] + + ; local var (qword) + mov ebx, [savidentptr2 wrt rip] + mov rcx, savidentptr2 + lea rdx, [savidentptr2 wrt rip] + mov rax, [savidentptr2+rcx] + mov rax, [savidentptr2 wrt rip] + mov rbx, [savidentptr2 wrt rip] + movzx rax, byte [savidentptr2 wrt rip] + movzx rax, byte [savidentptr2+rax] + + call foobar + + ret + +trap: sub rsp, 256 + int3 + add rsp, 256 +.end + +[SECTION .pdata] +dd trap +dd trap.end +dd $xdatasym + +[SECTION .xdata] +$xdatasym: +db 1, 7, 2, 0, 7, 1, 0x20, 0 + +[SECTION _FOO] +foo_foobar3ptr dd foobar3 +foo_foobar3ptr2 dq foobar3 + mov ebx, [foobar3 wrt rip] + mov rcx, foobar3 + lea rdx, [foobar3 wrt rip] + mov rax, [foobar3+rcx] + mov rax, [foobar3 wrt rip] + mov rbx, [foobar3 wrt rip] + movzx rax, byte [foobar3 wrt rip] + movzx rax, byte [foobar3+rax] + diff --git a/modules/objfmts/win64/tests/win64-dataref.errwarn b/modules/objfmts/win64/tests/win64-dataref.errwarn new file mode 100644 index 00000000..e69de29b diff --git a/modules/objfmts/win64/tests/win64-dataref.hex b/modules/objfmts/win64/tests/win64-dataref.hex new file mode 100644 index 00000000..615fb1f6 --- /dev/null +++ b/modules/objfmts/win64/tests/win64-dataref.hex @@ -0,0 +1,1649 @@ +64 +86 +06 +00 +00 +00 +00 +00 +fa +04 +00 +00 +14 +00 +00 +00 +00 +00 +0c +00 +2e +74 +65 +78 +74 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +0a +01 +00 +00 +04 +01 +00 +00 +0e +02 +00 +00 +00 +00 +00 +00 +21 +00 +00 +00 +20 +00 +50 +60 +2e +64 +61 +74 +61 +00 +00 +00 +0a +01 +00 +00 +00 +00 +00 +00 +4c +00 +00 +00 +58 +03 +00 +00 +a4 +03 +00 +00 +00 +00 +00 +00 +0c +00 +00 +00 +40 +00 +50 +c0 +2e +62 +73 +73 +00 +00 +00 +00 +56 +01 +00 +00 +00 +00 +00 +00 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +80 +00 +50 +c0 +2e +70 +64 +61 +74 +61 +00 +00 +5e +01 +00 +00 +00 +00 +00 +00 +0c +00 +00 +00 +1c +04 +00 +00 +28 +04 +00 +00 +00 +00 +00 +00 +03 +00 +00 +00 +40 +00 +30 +40 +2e +78 +64 +61 +74 +61 +00 +00 +6a +01 +00 +00 +00 +00 +00 +00 +08 +00 +00 +00 +46 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +40 +00 +40 +40 +5f +46 +4f +4f +00 +00 +00 +00 +72 +01 +00 +00 +00 +00 +00 +00 +48 +00 +00 +00 +4e +04 +00 +00 +96 +04 +00 +00 +00 +00 +00 +00 +0a +00 +00 +00 +20 +00 +00 +60 +bb +00 +00 +00 +00 +48 +b9 +00 +00 +00 +00 +00 +00 +00 +00 +48 +8d +15 +00 +00 +00 +00 +48 +8b +81 +00 +00 +00 +00 +48 +b8 +00 +00 +00 +00 +00 +00 +00 +00 +48 +bb +00 +00 +00 +00 +00 +00 +00 +00 +48 +0f +b6 +05 +00 +00 +00 +00 +48 +0f +b6 +80 +00 +00 +00 +00 +8b +1d +00 +00 +00 +00 +48 +b9 +00 +00 +00 +00 +00 +00 +00 +00 +48 +8d +15 +00 +00 +00 +00 +48 +8b +81 +00 +00 +00 +00 +48 +8b +05 +00 +00 +00 +00 +48 +8b +1d +00 +00 +00 +00 +48 +0f +b6 +05 +00 +00 +00 +00 +48 +0f +b6 +80 +00 +00 +00 +00 +8b +1d +00 +00 +00 +00 +48 +b9 +00 +00 +00 +00 +00 +00 +00 +00 +48 +8d +15 +00 +00 +00 +00 +48 +8b +81 +00 +00 +00 +00 +48 +8b +05 +00 +00 +00 +00 +48 +8b +1d +00 +00 +00 +00 +48 +0f +b6 +05 +00 +00 +00 +00 +48 +0f +b6 +80 +00 +00 +00 +00 +8b +1d +08 +00 +00 +00 +48 +b9 +08 +00 +00 +00 +00 +00 +00 +00 +48 +8d +15 +08 +00 +00 +00 +48 +8b +81 +08 +00 +00 +00 +48 +8b +05 +08 +00 +00 +00 +48 +8b +1d +08 +00 +00 +00 +48 +0f +b6 +05 +08 +00 +00 +00 +48 +0f +b6 +80 +08 +00 +00 +00 +e8 +00 +00 +00 +00 +c3 +48 +81 +ec +00 +01 +00 +00 +cc +48 +81 +c4 +00 +01 +00 +00 +01 +00 +00 +00 +06 +00 +00 +00 +04 +00 +07 +00 +00 +00 +06 +00 +00 +00 +01 +00 +12 +00 +00 +00 +06 +00 +00 +00 +04 +00 +19 +00 +00 +00 +06 +00 +00 +00 +04 +00 +1f +00 +00 +00 +06 +00 +00 +00 +01 +00 +29 +00 +00 +00 +06 +00 +00 +00 +01 +00 +35 +00 +00 +00 +06 +00 +00 +00 +04 +00 +3d +00 +00 +00 +06 +00 +00 +00 +04 +00 +43 +00 +00 +00 +08 +00 +00 +00 +04 +00 +49 +00 +00 +00 +08 +00 +00 +00 +01 +00 +54 +00 +00 +00 +08 +00 +00 +00 +04 +00 +5b +00 +00 +00 +08 +00 +00 +00 +04 +00 +62 +00 +00 +00 +08 +00 +00 +00 +04 +00 +69 +00 +00 +00 +08 +00 +00 +00 +04 +00 +71 +00 +00 +00 +08 +00 +00 +00 +04 +00 +79 +00 +00 +00 +08 +00 +00 +00 +04 +00 +7f +00 +00 +00 +0a +00 +00 +00 +04 +00 +85 +00 +00 +00 +0a +00 +00 +00 +01 +00 +90 +00 +00 +00 +0a +00 +00 +00 +04 +00 +97 +00 +00 +00 +0a +00 +00 +00 +04 +00 +9e +00 +00 +00 +0a +00 +00 +00 +04 +00 +a5 +00 +00 +00 +0a +00 +00 +00 +04 +00 +ad +00 +00 +00 +0a +00 +00 +00 +04 +00 +b5 +00 +00 +00 +0a +00 +00 +00 +04 +00 +bb +00 +00 +00 +0a +00 +00 +00 +04 +00 +c1 +00 +00 +00 +0a +00 +00 +00 +01 +00 +cc +00 +00 +00 +0a +00 +00 +00 +04 +00 +d3 +00 +00 +00 +0a +00 +00 +00 +04 +00 +da +00 +00 +00 +0a +00 +00 +00 +04 +00 +e1 +00 +00 +00 +0a +00 +00 +00 +04 +00 +e9 +00 +00 +00 +0a +00 +00 +00 +04 +00 +f1 +00 +00 +00 +0a +00 +00 +00 +04 +00 +f6 +00 +00 +00 +06 +00 +00 +00 +04 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +04 +00 +00 +00 +0a +00 +00 +00 +02 +00 +08 +00 +00 +00 +0a +00 +00 +00 +01 +00 +10 +00 +00 +00 +02 +00 +00 +00 +02 +00 +14 +00 +00 +00 +02 +00 +00 +00 +01 +00 +1c +00 +00 +00 +06 +00 +00 +00 +02 +00 +20 +00 +00 +00 +06 +00 +00 +00 +01 +00 +28 +00 +00 +00 +07 +00 +00 +00 +02 +00 +2c +00 +00 +00 +07 +00 +00 +00 +01 +00 +34 +00 +00 +00 +08 +00 +00 +00 +02 +00 +38 +00 +00 +00 +08 +00 +00 +00 +01 +00 +40 +00 +00 +00 +0c +00 +00 +00 +02 +00 +44 +00 +00 +00 +0c +00 +00 +00 +01 +00 +fb +00 +00 +00 +0a +01 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +00 +00 +03 +00 +04 +00 +00 +00 +02 +00 +00 +00 +03 +00 +08 +00 +00 +00 +10 +00 +00 +00 +03 +00 +01 +07 +02 +00 +07 +01 +20 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +8b +1d +00 +00 +00 +00 +48 +b9 +00 +00 +00 +00 +00 +00 +00 +00 +48 +8d +15 +00 +00 +00 +00 +48 +8b +81 +00 +00 +00 +00 +48 +8b +05 +00 +00 +00 +00 +48 +8b +1d +00 +00 +00 +00 +48 +0f +b6 +05 +00 +00 +00 +00 +48 +0f +b6 +80 +00 +00 +00 +00 +00 +00 +00 +00 +08 +00 +00 +00 +02 +00 +04 +00 +00 +00 +08 +00 +00 +00 +01 +00 +0e +00 +00 +00 +08 +00 +00 +00 +04 +00 +14 +00 +00 +00 +08 +00 +00 +00 +01 +00 +1f +00 +00 +00 +08 +00 +00 +00 +04 +00 +26 +00 +00 +00 +08 +00 +00 +00 +04 +00 +2d +00 +00 +00 +08 +00 +00 +00 +04 +00 +34 +00 +00 +00 +08 +00 +00 +00 +04 +00 +3c +00 +00 +00 +08 +00 +00 +00 +04 +00 +44 +00 +00 +00 +08 +00 +00 +00 +04 +00 +2e +66 +69 +6c +65 +00 +00 +00 +00 +00 +00 +00 +fe +ff +00 +00 +67 +01 +2d +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +2e +74 +65 +78 +74 +00 +00 +00 +00 +00 +00 +00 +01 +00 +00 +00 +03 +01 +0a +01 +00 +00 +21 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +78 +38 +36 +69 +64 +65 +6e +74 +00 +00 +00 +00 +01 +00 +00 +00 +02 +00 +00 +00 +00 +00 +04 +00 +00 +00 +00 +00 +00 +00 +02 +00 +00 +00 +02 +00 +66 +6f +6f +62 +61 +72 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +66 +6f +6f +62 +61 +72 +32 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +66 +6f +6f +62 +61 +72 +33 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +66 +6f +6f +62 +61 +72 +34 +00 +00 +00 +00 +00 +00 +00 +00 +00 +02 +00 +2e +64 +61 +74 +61 +00 +00 +00 +00 +00 +00 +00 +02 +00 +00 +00 +03 +01 +4c +00 +00 +00 +0c +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +2e +62 +73 +73 +00 +00 +00 +00 +00 +00 +00 +00 +03 +00 +00 +00 +03 +01 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +2e +70 +64 +61 +74 +61 +00 +00 +00 +00 +00 +00 +04 +00 +00 +00 +03 +01 +0c +00 +00 +00 +03 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +2e +78 +64 +61 +74 +61 +00 +00 +00 +00 +00 +00 +05 +00 +00 +00 +03 +01 +08 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +5f +46 +4f +4f +00 +00 +00 +00 +00 +00 +00 +00 +06 +00 +00 +00 +03 +01 +48 +00 +00 +00 +0a +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +00 +0f +00 +00 +00 +5f +5f +73 +61 +76 +69 +64 +65 +6e +74 +00 diff --git a/modules/objfmts/win64/tests/win64-dataref.masm b/modules/objfmts/win64/tests/win64-dataref.masm new file mode 100644 index 00000000..cfd43ad9 --- /dev/null +++ b/modules/objfmts/win64/tests/win64-dataref.masm @@ -0,0 +1,110 @@ +public x86ident +public __savident +extrn foobar : proc +extrn foobar2 : abs +extrn foobar3 : qword +extrn foobar4 : byte + +_DATA SEGMENT +__savident dd 0 +savidentptr dd __savident +savidentptr2 dq __savident +x86identptr dd x86ident +x86identptr2 dq x86ident +foobarptr dd foobar +foobarptr2 dq foobar +foobar2ptr dd foobar2 +foobar2ptr2 dq foobar2 +foobar3ptr dd foobar3 +foobar3ptr2 dq foobar3 +xptr dd x +xptr2 dq x +;dataptr dd offset _DATA +;dataptr2 dq offset _DATA +;codeptr dd offset _TEXT +;codeptr2 dq offset _TEXT + +_DATA ENDS +_BSS SEGMENT +x dq ? + +_BSS ENDS +_TEXT SEGMENT +x86ident: + ; with :proc + mov ebx,[foobar] + mov rcx,offset foobar + lea rdx, foobar + mov rax, qword ptr foobar[rcx] + mov rax, foobar + mov rbx, foobar + movzx rax, byte ptr foobar + movzx rax, byte ptr foobar[rax] + + ; with :abs + ;mov ebx,[foobar2] + ;mov rcx,offset foobar2 + ;lea rdx, foobar2 + ;mov rax, qword ptr foobar2[rcx] + ;mov rax, foobar2 + ;mov rbx, foobar2 + ;movzx rax, byte ptr foobar2 + ;movzx rax, byte ptr foobar2[rax] + + ; with :qword + mov ebx, dword ptr [foobar3] + mov rcx,offset foobar3 + lea rdx, foobar3 + mov rax, qword ptr foobar3[rcx] + mov rax, foobar3 + mov rbx, foobar3 + movzx rax, byte ptr foobar3 + movzx rax, byte ptr foobar3[rax] + + ; local var (dword) + mov ebx,[__savident] + mov rcx,offset __savident + lea rdx, __savident + mov rax, qword ptr __savident[rcx] + mov rax, qword ptr __savident + mov rbx, qword ptr __savident + movzx rax, byte ptr __savident + movzx rax, byte ptr __savident[rax] + + ; local var (qword) + mov ebx, dword ptr [savidentptr2] + mov rcx,offset savidentptr2 + lea rdx, savidentptr2 + mov rax, savidentptr2[rcx] + mov rax, savidentptr2 + mov rbx, savidentptr2 + movzx rax, byte ptr savidentptr2 + movzx rax, byte ptr savidentptr2[rax] + + call foobar + + ret + +trap proc public frame + sub rsp, 256 + .allocstack 256 + .endprolog + int 3 + add rsp, 256 +trap endp + +_TEXT ENDS + +_FOO SEGMENT +foo_foobar3ptr dd foobar3 +foo_foobar3ptr2 dq foobar3 + mov ebx, dword ptr [foobar3] + mov rcx,offset foobar3 + lea rdx, foobar3 + mov rax, qword ptr foobar3[rcx] + mov rax, foobar3 + mov rbx, foobar3 + movzx rax, byte ptr foobar3 + movzx rax, byte ptr foobar3[rax] +_FOO ENDS +END diff --git a/modules/objfmts/win64/tests/win64_test.sh b/modules/objfmts/win64/tests/win64_test.sh new file mode 100755 index 00000000..bf7f2d3c --- /dev/null +++ b/modules/objfmts/win64/tests/win64_test.sh @@ -0,0 +1,4 @@ +#! /bin/sh +# $Id$ +${srcdir}/out_test.sh win64_test modules/objfmts/win64/tests "win64 objfmt" "-f win64" ".obj" +exit $?