Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pdf manual added

  • Loading branch information...
commit 498413fd59720c5db6b062aab85c03be0e29f908 1 parent 785c707
@nishiuramakoto authored
Showing with 6,158 additions and 8,255 deletions.
  1. +33 −20 INSTALL
  2. +6 −0 Makefile.am
  3. +70 −16 Makefile.in
  4. +3 −352 README
  5. +93 −11 configure
  6. +34 −2 configure.ac
  7. +216 −82 src/Makefile.am
  8. +850 −290 src/Makefile.in
  9. +1 −1  src/check_illegal_code.sh
  10. +6 −0 src/config.h.in
  11. +1 −1  src/erasm/demo86.cpp
  12. +12 −1 src/erasm/dsm_x64.hpp
  13. +1 −1  src/erasm/dsm_x64_performance_test.cpp
  14. +127 −247 src/erasm/dsm_x64_test_main.cpp
  15. +15 −1 src/erasm/dsm_x86.hpp
  16. +62 −25 src/erasm/dsm_x86_performance_test.cpp
  17. +107 −223 src/erasm/dsm_x86_test_main.cpp
  18. +2,438 −2,438 src/erasm/x64_assembler_auto_test.cpp
  19. +0 −2,635 src/erasm/x64_assembler_auto_test_snapshot.cpp
  20. +11 −11 src/erasm/x64_assembler_manual_test.cpp
  21. +4 −4 src/erasm/x64_implementation_defined.hpp
  22. +101 −22 src/erasm/x64_io.cpp
  23. +97 −0 src/erasm/x64_io.hpp
  24. +1 −0  src/erasm/x86.cpp
  25. +1,828 −1,828 src/erasm/x86_assembler_auto_test.cpp
  26. +1 −0  src/erasm/x86_assembler_impl.cpp
  27. +19 −19 src/erasm/x86_assembler_manual_test.cpp
  28. +16 −15 src/erasm/x86_instruction_definition_common.hpp
  29. +0 −7 src/erasm/x86_io.cpp
  30. +4 −2 src/erasm/x86_io.hpp
  31. +1 −1  src/haskell/Makefile.am
View
53 INSTALL
@@ -1,9 +1,36 @@
---------------------------------
ERASM++ Installation Instructions
---------------------------------
+ * Installation
* Supported Platforms
* Requirements
- * Installation
+
+INSTALLATION
+------------
+
+I assume you have downloaded erasm-plusplus-0.11.tar.gz from **,
+unpacked it,and cd'ed into the base directory.
+
+./configure --prefix=your-private-directory
+make
+make install
+
+This will install the necessary headers under PREFIX/include/erasm,
+and libraries under PREFIX/lib.
+
+We don't recommend installing on the system directories,as ERASM++ is still
+in its alpha stage.
+
+Note that due to the lack of standard C++ ABI, it is necessary to build the library
+for *every* major version of every compiler toolset you use. So we recommend
+something like (say) ./configure --prefix=$HOME/gcc-4.6 in the above example.
+
+We have several options to ease the installation.
+* Make Erasm++ a header-only library.
+* Make Erasm++ a thin-wrapper around an equivalent, but more portable C library where possible.
+* Adopt Boost-like library naming scheme and automate above process.
+
+Each solution has its pros and cons. If you have an idea,please let me know!
SUPPORTED PLATFORMS
------------------
@@ -14,23 +41,23 @@ Debian Testing(squeeze) running on Intel Celeron M 1.3GHz,
g++ version 4.5.3.
Windows 7 32-bit running on Intel Pentium Dual Core 2.4GHz,
-mingw g++ version 4.5.4.
+mingw g++ version 4.5.4 and 4.6.1.
Unfortunately,g++ 4.6.1 won't pass 'make check'. (it will eat up all the
user space. See README for the details.) However, there should be no problem
just to compile and install the library.
-cl.exe bundled with Visual C++ 2011 Express looks fine,but not tested
+cl.exe bundled with Visual C++ 2011 Express looks fine, but not tested
thoroughly yet.
-Please report if you have succeeded or failed to build and use ERASM++ on
+Please report at nishiuramakoto@gmail.com if you have succeeded or failed to build and use Erasm++ on
other systems.
REQUIREMENTS
------------
-ERASM++ requires:
+Erasm++ requires:
* GNU make
* Boost static assert
@@ -51,21 +78,7 @@ pass 'make check':
* libopcodes (bundled with GNU binutils)
* GHC (Glasgow Haskell Compiler) >= 7.0.3
* cabal
-* parsec,uulib,HUnit,QuickCheck >=2.4,HaskellForMaths >=0.4.0,fgl
+* parsec,uulib,HUnit,QuickCheck >=2.4,HaskellForMaths >=0.4.0,fgl,pointless-haskell
all of which are available through 'cabal install'.
-INSTALLATION
-------------
-git clone git://github.com/nishiuramakoto/erasm-plusplus.git
-cd erasm-plusplus
-./configure --prefix=your-private-directory
-make
-make install
-
-This will install the necessary headers under PREFIX/include/erasm,
-and libraries under PREFIX/lib.
-
-We don't recommend installing on the system directories,as ERASM++ is still
-in its alpha stage.
-
View
6 Makefile.am
@@ -19,3 +19,9 @@
SUBDIRS= . src
ACLOCAL_AMFLAGS= -I m4
+
+dist_data_DATA = doc/manual.pdf \
+ demo/demo86.cpp \
+ demo/demo64.cpp \
+ demo/dsm86_counter.cpp
+
View
86 Makefile.in
@@ -32,6 +32,7 @@
# You should have received a copy of the GNU General Public License
# along with ERASM++; see the file COPYING. If not see
# <http://www.gnu.org/licenses/>.
+
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
@@ -52,11 +53,11 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = .
-DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
- $(srcdir)/Makefile.in $(top_srcdir)/configure AUTHORS COPYING \
- ChangeLog INSTALL NEWS TODO config/config.guess \
- config/config.sub config/depcomp config/install-sh \
- config/ltmain.sh config/missing
+DIST_COMMON = README $(am__configure_deps) $(dist_data_DATA) \
+ $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
+ $(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
+ TODO config/config.guess config/config.sub config/depcomp \
+ config/install-sh config/ltmain.sh config/missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
@@ -79,6 +80,29 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
install-pdf-recursive install-ps-recursive install-recursive \
installcheck-recursive installdirs-recursive pdf-recursive \
ps-recursive uninstall-recursive
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(datadir)"
+DATA = $(dist_data_DATA)
RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
distclean-recursive maintainer-clean-recursive
AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
@@ -125,6 +149,7 @@ distuninstallcheck_listfiles = find . -type f -print
distcleancheck_listfiles = find . -type f -print
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
+AM_CXXFLAGS = @AM_CXXFLAGS@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
@@ -243,6 +268,11 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = . src
ACLOCAL_AMFLAGS = -I m4
+dist_data_DATA = doc/manual.pdf \
+ demo/demo86.cpp \
+ demo/demo64.cpp \
+ demo/dsm86_counter.cpp
+
all: all-recursive
.SUFFIXES:
@@ -289,6 +319,26 @@ clean-libtool:
distclean-libtool:
-rm -f libtool config.lt
+install-dist_dataDATA: $(dist_data_DATA)
+ @$(NORMAL_INSTALL)
+ test -z "$(datadir)" || $(MKDIR_P) "$(DESTDIR)$(datadir)"
+ @list='$(dist_data_DATA)'; test -n "$(datadir)" || list=; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(datadir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(datadir)" || exit $$?; \
+ done
+
+uninstall-dist_dataDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(dist_data_DATA)'; test -n "$(datadir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$files" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(datadir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(datadir)" && rm -f $$files
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
@@ -602,9 +652,12 @@ distcleancheck: distclean
exit 1; } >&2
check-am: all-am
check: check-recursive
-all-am: Makefile
+all-am: Makefile $(DATA)
installdirs: installdirs-recursive
installdirs-am:
+ for dir in "$(DESTDIR)$(datadir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
install: install-recursive
install-exec: install-exec-recursive
install-data: install-data-recursive
@@ -652,7 +705,7 @@ info: info-recursive
info-am:
-install-data-am:
+install-data-am: install-dist_dataDATA
install-dvi: install-dvi-recursive
@@ -698,7 +751,7 @@ ps: ps-recursive
ps-am:
-uninstall-am:
+uninstall-am: uninstall-dist_dataDATA
.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \
install-am install-strip tags-recursive
@@ -710,14 +763,15 @@ uninstall-am:
distcheck distclean distclean-generic distclean-libtool \
distclean-tags distcleancheck distdir distuninstallcheck dvi \
dvi-am html html-am info info-am install install-am \
- install-data install-data-am install-dvi install-dvi-am \
- install-exec install-exec-am install-html install-html-am \
- install-info install-info-am install-man install-pdf \
- install-pdf-am install-ps install-ps-am install-strip \
- installcheck installcheck-am installdirs installdirs-am \
- maintainer-clean maintainer-clean-generic mostlyclean \
- mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
- tags tags-recursive uninstall uninstall-am
+ install-data install-data-am install-dist_dataDATA install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip installcheck installcheck-am installdirs \
+ installdirs-am maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \
+ ps ps-am tags tags-recursive uninstall uninstall-am \
+ uninstall-dist_dataDATA
# Tell versions [3.59,3.63) of GNU make to not export all variables.
View
355 README
@@ -1,357 +1,8 @@
Copyright 2010,2011,2012 Makoto Nishiura.
-This is version 0.1 of ERASM++, Embedded Run-time ASseMbler in C++,
-a library for runtime code generation.
+This is version 0.11 of Erasm++, a library for runtime code generation,
+instruction decoding, and metaprogramming.
See INSTALL for system requirements and installation instructions.
-For the moment,this README is intended to serve as the only documentation
-of the library.
-Contents
-1. ERASM++
- 1.1 Overview
- 1.2 Basic Example
- 1.3 Syntax
- 1.4 Performance
- 1.5 Limitations
-2. License
-
-1. ERASM++
-
-1.1 Overview
-
-ERASM++ is an Embedded Domain Specific Language(EDSL) in C++ for run-time
-code generation.Its main strengths are very close syntactical similarity
-with the real assembly language, complete compile-time syntax checking ,the
-ability to produce very high quality code, and near full standard conformance
-(see below for exceptions). Current support includes Intel x86/x86-64
-architecture only.
-
-1.2 Basic Usage
-
-32-bit case
-
-First,create a file called demo86.cpp with the following contents:
-
-<CODE>
-#include <erasm/x86_addr32_data32.hpp>
-#include <iostream>
-
-typedef int (*func_type) (int);
-
-int main(int argc,char**argv)
-{
- using namespace std;
- using namespace erasm::x86;
- using namespace erasm::x86::addr32;
- using namespace erasm::x86::addr32::data32;
-
- byte_t buf[100];
- byte_t *p = buf;
- int32_t x = 2;
-
- p += mov(p,eax,dword_ptr[esp+4]);
- p += add(p,eax,x);
- p += ret(p);
-
- func_type f = (func_type)buf;
- int len = p - buf;
-
- cout << "code length=" << len << endl
- << "result=" << f(argc) << endl;
- return 0;
-}
-</CODE>
-
-Then,run the following commands:
-# g++ -DNDEBUG demo86.cpp -lerasm86 -o demo86
-# ./demo86
-# ./demo86 a b
-
-Provided the stack is executable in your operating system by default,it
-will print the numbers 3 and 5.
-
-64-bit case
-
-First,create a file called demo64.cpp with the following contents:
-
-<CODE>
-#include <erasm/x64_addr64_data32.hpp>
-#include <iostream>
-
-typedef int (*pf_t) (int);
-
-int main(int argc,char**argv)
-{
- using namespace std;
- using namespace erasm::x64;
- using namespace erasm::x64::addr64;
- using namespace erasm::x64::addr64::data32;
-
- byte_t buf[100];
- byte_t *p = buf;
- int32_t x = 2;
-
- p += mov(p,rax,dword_ptr[rsp+8]);
- p += add(p,rax,x);
- p += ret(p);
-
- pf_t f = (pf_t)buf;
- int len = p - buf;
- cout << "code length=" << len << endl
- << "result=" << f(argc) << endl;
- return 0;
-}
-</CODE>
-
-Then,run the following commands:
-# g++ -DNDEBUG demo64.cpp -lerasm64 -o demo64
-# ./demo64
-# ./demo64 a b
-
-Provided the stack is executable in your operating system by default,it
-will print the numbers 3 and 5.
-
-The namespace erasm::x86::addr32::data32 contains the actual instruction
-definitions whose default address and operand sizes are both 32-bit.
-Similarly, the namespace erasm::x64::addr64::data32 should be used for x64
-instructions whose default address and operand sizes are respectively 64-bit
-and 32-bit. Currently we don't support other default address or operand size
- modes.
-
-TODO:Add instructions for other compilers
-
-1.3 Syntax
-
-In general, the prototype of an instruction is in one of the following forms:
-
-int MNEMONIC(uint8_t* p);
-int MNEMONIC(uint8_t* p,OPERAND_TYPE op1);
-int MNEMONIC(uint8_t* p,OPERAND_TYPE op1,OPERAND_TYPE op2);
-int MNEMONIC(uint8_t* p,OPERAND_TYPE op1,OPERAND_TYPE op2,OPERAND_TYPE op3);
-
-where uint8_t is most likely an alias of unsigned char.(see the documentation
-of Boost stdint for the detail.) It is declared in erasm::x64 and
-erasm::x86 namespaces.
-
-Examples:
- p += adc (p,word_ptr [edx + esi * _2],ax);
- p += and_ (p,dword_ptr [rip + 0x1000],r12d);
- p += jmp (p, 0x10);
- p += rep_movs (p,dword_ptr.es [di],dword_ptr.gs [si]);
-
-
-The operational meaning of each instruction is always the same.That is,
-it encodes the instruction at the location specified by the first argument(p),
-and returns the number of bytes encoded.If the target address is writable,it
-is guaranteed that either it succeeds to encode the instruction, or the
-instruction is syntactically ill-formed and the compilation fails.It is
-undefined what would happen if the destination address is not writable.In
-particular,it never throws a (C++) exception.
-
-MNEMONIC is generally one of the instruction mnemonics as defined in the
-Intel's Instruction Set Reference[2], converted to all lower-case letters.
-
-There are some exceptions to this rule:
- * If the lower-case mnemonic is reserved as a keyword in C++ ,we append an
- underscore to the mnemonic, as in 'int_','xor_',etc.
-
- * If the instruction requires a mandatory prefix such as 'REP','REPZ' etc.,
- then the prefix and the mnemonic are joined by an underscore,as in
- 'repe_scas'.
-
- * Some instructions are ambiguous and cannot be fully specified solely by
- the combination of mnemonic and operand types. In such a case, we resort
- to some ad-hoc case-by-case disambiguation schemes such as:
-
- p += rep_movs(p,byte_ptr[rdi],byte_ptr[rsi]);
- p += rexw_rep_movs(p,byte_ptr[rdi],byte_ptr[rsi]);
-
- Here,rep_movs uses ecx as the count register,while rexw_rep_movs uses rcx.
- We are searching for less ad-hoc disambiguation methods,but we would also
- like the form of those instructions to be directly guessable from the
- Intel's manual.
-
-OPERAND_TYPE is the type of an operand, which is generally what your common
-sense as an assembly programmer tells you.More specifically,an operand is one
-of the following objects:
-
- * Registers. dh,ax,edx,xmm0,st3,gs,rax,r8,r9b,sil,etc.
-
- * Memory references.
- byte_ptr [esp + ebp * _2 + 4],
- dword_ptr [ebx * _8 + _4],
- xmmword_ptr . gs[bx+di].
-
- * Immediates. (int32_t)0,(int8_t)1,_1,_2,etc. The static constants _0 - _9
- can be used as a shorthand for specifying small 8-bit integers. By nature,
- assembly instructions are quite picky about the exact operand types, and
- it is very often the case that explicit casting is necessary to avoid
- ambiguity.
-
-A caveat is that the scale coefficient of the index register
-(e.g. _2 of [edx + _2 * ecx]) must be specified with the static constants
-_1-_9. This inconvenience results from the need to compute the necessary
-data statically,and will not change.
-
-Please see intel's Instruction Set Reference[2] for instruction definitions.
-
-For the examples of valid instructions,see
-
- src/erasm/x64_assembler_manual_test.cpp
- src/erasm/x64_assembler_auto_test.cpp
- src/erasm/x86_assembler_manual_test.cpp
- src/erasm/x86_assembler_auto_test.cpp
-
-For the examples of ill-formed instructions,see
-
- src/erasm/x64_assembler_illegal_code.cpp
- src/erasm/x86_assembler_illegal_code.cpp.
-
-
-1.4 Performance
-
-If all the required functions are inlined(see below),ERASM++ instructions
-will be compiled to a very fast and very localized code.
-
-Let us give an example.
-
-g++ 4.6.1 compiles (with the option -O3) the following code
-
-<CODE>
-inline int adc (code_ptr p, const ByteReg86 & op1,const BytePtr86 & op2)
-{
- // if the required instruction definition is declared inline like this..
-}
-
-extern "C" int code_test(code_ptr p)
-{ return adc(p ,cl,byte_ptr [eax+ebp*_4+12345678]); }
-</CODE>
-
-to
-
-<CODE>
-_code_test:
- sub esp, 32
- mov eax, DWORD PTR [esp+36]
- mov BYTE PTR [esp+5], -88
- mov DWORD PTR [esp+6], 12345678
- mov BYTE PTR [esp+4], -116
- mov BYTE PTR [eax], 103
- mov BYTE PTR [eax+1], 18
- mov edx, DWORD PTR [esp+4]
- mov DWORD PTR [eax+2], edx
- mov edx, DWORD PTR [esp+8]
- mov WORD PTR [eax+6], dx
- mov eax, 8
- add esp, 32
- ret
-</CODE>
-
-
-Although the above code may not be the fastest possible, we observe the
-following very nice properties:
-
-* No branches.
-
-Conditional or not,branches always consume precious processor resources[4],
-so their absence is quite beneficial for performance reasons. Furthermore,in
-kernel spaces,there is a greater risk that the target address is not
-accessible at all (e.g. the corresponding section may have been swapped out
-and the code runs in a high priority mode.)
-
-* No external references.
-
-This is also a very good property for the similar reasons. See [4] for the
-details.
-
-Although there are strong arguments against introducing C++ code into the
-operating system kernel spaces[5][6], it should be clear that ERASM++ per se
-does not possess any such weakness that makes it hard to adopt C++ code into
-the kernel space.
-
-Currently the main ERASM++ encoder functions are all compiled in a seperate
-module for the sake of compile-time performance.See
-src/test_asm_performance.cpp for how to inline the required functions.
-
-1.5 Limitations
-
-By far the biggest limitation of ERASM++ is its compile-time resource usage.
-For reasons explained later,the exact compile-time behaviour greatly varies
-from one compiler version to another.
-
-For example,while g++-4.5.4 compiles a source file which consists of about
-2500 instructions just fine with memory usage ~500MB ,g++-4.6.1 consumes all
-its user-space (~2GB) and eventually gives up.
-
-Another disadvantage of using ERASM++ is its often cryptic error messages.
-This is inherently an implementation-dependant problem,and is impossible to
-solve generally.
-
-Current implementation only makes some effort to increase readability for g++.
-
-Here's an example (manually formatted) error message from g++:
-
-<CODE>
-cvtpd2pi(p,mm1,xmmword_ptr[rax+ rsp*_2]);
-</CODE>
-results to
-
-./erasm/meta_prelude_core.hpp:829:128: error: no type named 'result' in
-'struct erasm::prelude::eval<
- erasm::prelude::if_<
- erasm::prelude::error<
- erasm::x64::Error_ESP_and_RSP_cannot_be_used_as_the_index_register,
- erasm::prelude::Term<erasm::prelude::Int<4>,
- erasm::prelude::times<erasm::prelude::Int<2>,
- erasm::prelude::Int<1> > >,
- erasm::prelude::Term<erasm::prelude::Int<0>, erasm::prelude::Int<1> >,
- void, void>,
- erasm::x64::PtrRex<erasm::x64::XmmWord>,
- erasm::x64::PtrNoRex<erasm::x64::XmmWord> > >'
-
-Note the 'Error_ESP_and_RSP_cannot_be_used_as_the_index_register' part above,
-which correctly spots the problem.
-
-Unfortunately,Microsoft's cl.exe tries to outsmart our effort and emits
-more obscure error messages.
-
-ERASM++ declares and uses static constants _1,_2,etc. in one of its
-namespaces. This is potentially problematic as the standard specifies that
-any identifier that begins with an underscore is reserved for the
-implementation in the global namespace.
-
-Finally,ERASM++ cannot be fully standard conformant because it must be
-dependent on the platform-specific data representations.Howerver,if the
-implementation does support the platform, there should be no problem
-compiling ERASM++ as long as the compiler is reasonably standard-conformant.
-
-
-2. License
-
-ERASM++ is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 3, or (at your option) any later
-version.
-
-ERASM++ is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-for more details.
-
-You should have received a copy of the GNU General Public License
-along with ERASM++; see the file COPYING. If not see
-<http://www.gnu.org/licenses/>.
-
-
-Reference
-
-[1] Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 1:
- Basic Architecture.
-[2] Intel® 64 and IA-32 Architectures Software Developer's Manual Combined
- Volumes 2A, 2B, and 2C: Instruction Set Reference, A-Z.
-[3] Intel® 64 and IA-32 Architectures Software Developer's Manual Combined
- Volumes 3A, 3B, and 3C: System Programming Guide, Parts 1 and 2.
-[4] Intel® 64 and IA-32 Architectures Optimization Reference Manual.
-[5] http://kerneltrap.org/node/2067
-[6] http://msdn.microsoft.com/en-us/windows/hardware/gg487420
+See doc/manual.pdf for the documentation.
View
104 configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for ERASM 0.1.
+# Generated by GNU Autoconf 2.68 for ERASM 0.1.1.
#
# Report bugs to <nishiuramakoto@gmail.com>.
#
@@ -570,8 +570,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='ERASM'
PACKAGE_TARNAME='erasm'
-PACKAGE_VERSION='0.1'
-PACKAGE_STRING='ERASM 0.1'
+PACKAGE_VERSION='0.1.1'
+PACKAGE_STRING='ERASM 0.1.1'
PACKAGE_BUGREPORT='nishiuramakoto@gmail.com'
PACKAGE_URL=''
@@ -615,6 +615,13 @@ ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
+AM_CXXFLAGS
+WINDOWS_FALSE
+WINDOWS_TRUE
+LINUX_FALSE
+LINUX_TRUE
+HOST_IS_64BIT_FALSE
+HOST_IS_64BIT_TRUE
HAVE_LIBINTL_FALSE
HAVE_LIBINTL_TRUE
CXXCPP
@@ -742,6 +749,7 @@ enable_fast_install
with_gnu_ld
with_sysroot
enable_libtool_lock
+enable_debug
'
ac_precious_vars='build_alias
host_alias
@@ -1298,7 +1306,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures ERASM 0.1 to adapt to many kinds of systems.
+\`configure' configures ERASM 0.1.1 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1368,7 +1376,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of ERASM 0.1:";;
+ short | recursive ) echo "Configuration of ERASM 0.1.1:";;
esac
cat <<\_ACEOF
@@ -1383,6 +1391,7 @@ Optional Features:
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
+ --enable-debug enable debug data generation (def=no)
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@@ -1472,7 +1481,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-ERASM configure 0.1
+ERASM configure 0.1.1
generated by GNU Autoconf 2.68
Copyright (C) 2010 Free Software Foundation, Inc.
@@ -1962,7 +1971,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by ERASM $as_me 0.1, which was
+It was created by ERASM $as_me 0.1.1, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ $0 $@
@@ -2786,7 +2795,7 @@ fi
# Define the identity of the package.
PACKAGE='erasm'
- VERSION='0.1'
+ VERSION='0.1.1'
cat >>confdefs.h <<_ACEOF
@@ -14957,7 +14966,6 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
ac_fn_cxx_check_header_mongrel "$LINENO" "sys/mman.h" "ac_cv_header_sys_mman_h" "$ac_includes_default"
if test "x$ac_cv_header_sys_mman_h" = xyes; then :
@@ -15021,6 +15029,68 @@ else
fi
+ if case "$host_os" in *64*) true ;; *) false ;; esac ; then
+ HOST_IS_64BIT_TRUE=
+ HOST_IS_64BIT_FALSE='#'
+else
+ HOST_IS_64BIT_TRUE='#'
+ HOST_IS_64BIT_FALSE=
+fi
+
+
+ if case "$host_os" in *linux*) true ;; *) false ;; esac; then
+ LINUX_TRUE=
+ LINUX_FALSE='#'
+else
+ LINUX_TRUE='#'
+ LINUX_FALSE=
+fi
+
+
+ if case "$host_os" in *mingw*) true ;; *cygwin*) true ;; *) false ;; esac; then
+ WINDOWS_TRUE=
+ WINDOWS_FALSE='#'
+else
+ WINDOWS_TRUE='#'
+ WINDOWS_FALSE=
+fi
+
+
+##########################################################################
+# debug compilation support
+##########################################################################
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build with debug information" >&5
+$as_echo_n "checking whether to build with debug information... " >&6; }
+# Check whether --enable-debug was given.
+if test "${enable_debug+set}" = set; then :
+ enableval=$enable_debug; debugit="$enableval"
+else
+ debugit=no
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $debugit" >&5
+$as_echo "$debugit" >&6; }
+
+if test x"$debugit" = x"yes"; then
+
+$as_echo "#define DEBUG /**/" >>confdefs.h
+
+# AM_CXXFLAGS="$AM_CXXFLAGS -g -Wall -Werror -Wno-uninitialized -O0"
+ AM_CXXFLAGS="$AM_CXXFLAGS -g -Wall -Wno-uninitialized -O0"
+else
+
+$as_echo "#define NDEBUG /**/" >>confdefs.h
+
+ AM_CPPFLAGS="$AM_CPPFLAGS -DNDEBUG"
+ AM_CXXFLAGS="$AM_CXXFLAGS -O3 -Wall"
+fi
+
+##########################################################################
+
+
+
+
ac_config_files="$ac_config_files Makefile src/Makefile"
cat >confcache <<\_ACEOF
@@ -15156,6 +15226,18 @@ if test -z "${HAVE_LIBINTL_TRUE}" && test -z "${HAVE_LIBINTL_FALSE}"; then
as_fn_error $? "conditional \"HAVE_LIBINTL\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
+if test -z "${HOST_IS_64BIT_TRUE}" && test -z "${HOST_IS_64BIT_FALSE}"; then
+ as_fn_error $? "conditional \"HOST_IS_64BIT\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${LINUX_TRUE}" && test -z "${LINUX_FALSE}"; then
+ as_fn_error $? "conditional \"LINUX\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${WINDOWS_TRUE}" && test -z "${WINDOWS_FALSE}"; then
+ as_fn_error $? "conditional \"WINDOWS\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
: "${CONFIG_STATUS=./config.status}"
ac_write_fail=0
@@ -15565,7 +15647,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by ERASM $as_me 0.1, which was
+This file was extended by ERASM $as_me 0.1.1, which was
generated by GNU Autoconf 2.68. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -15631,7 +15713,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-ERASM config.status 0.1
+ERASM config.status 0.1.1
configured by $0, generated by GNU Autoconf 2.68,
with options \\"\$ac_cs_config\\"
View
36 configure.ac
@@ -16,7 +16,7 @@
# along with ERASM++; see the file COPYING. If not see
# <http://www.gnu.org/licenses/>.
-AC_INIT([ERASM],[0.1],[nishiuramakoto@gmail.com])
+AC_INIT([ERASM],[0.1.1],[nishiuramakoto@gmail.com])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_AUX_DIR([config])
AC_CONFIG_MACRO_DIR([m4])
@@ -30,7 +30,6 @@ AC_PROG_INSTALL
LT_INIT
-
AC_CHECK_HEADER([sys/mman.h],
[AC_DEFINE([HAVE_SYS_MMAN_H],1,[Define to 1 if you have <sys/mman.h>])],
[AC_MSG_WARN([no sys/mman.h])])
@@ -38,6 +37,39 @@ AC_CHECK_HEADER([sys/mman.h],
AC_CHECK_LIB([intl],[libintl_dngettext],[my_have_libintl=yes],[my_have_libintl=no])
AM_CONDITIONAL([HAVE_LIBINTL],[test "$my_have_libintl" = yes])
+AM_CONDITIONAL([HOST_IS_64BIT],[case "$host_os" in *64*) true ;; *) false ;; esac ])
+
+AM_CONDITIONAL([LINUX],[ case "$host_os" in *linux*) true ;; *) false ;; esac])
+
+AM_CONDITIONAL([WINDOWS],[ case "$host_os" in *mingw*) true ;; *cygwin*) true ;; *) false ;; esac])
+
+##########################################################################
+# debug compilation support
+##########################################################################
+
+AC_MSG_CHECKING([whether to build with debug information])
+AC_ARG_ENABLE([debug],
+ [AS_HELP_STRING([--enable-debug],
+ [enable debug data generation (def=no)])],
+ [debugit="$enableval"],
+ [debugit=no])
+AC_MSG_RESULT([$debugit])
+
+if test x"$debugit" = x"yes"; then
+ AC_DEFINE([DEBUG],[],[Debug Mode])
+# AM_CXXFLAGS="$AM_CXXFLAGS -g -Wall -Werror -Wno-uninitialized -O0"
+ AM_CXXFLAGS="$AM_CXXFLAGS -g -Wall -Wno-uninitialized -O0"
+else
+ AC_DEFINE([NDEBUG],[],[No-debug Mode])
+ AM_CPPFLAGS="$AM_CPPFLAGS -DNDEBUG"
+ AM_CXXFLAGS="$AM_CXXFLAGS -O3 -Wall"
+fi
+
+##########################################################################
+
+AC_SUBST([AM_CXXFLAGS])
+
+
AC_OUTPUT([Makefile src/Makefile])
View
298 src/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright (C) 2011,2012 Makoto Nishiura.
+# Copyright (C) 2011,2012 Makoto Nishiura
# This file is part of ERASM++.
@@ -20,6 +20,37 @@ include $(srcdir)/haskell/Makefile.am
export CPP
export CXX
+if HAVE_LIBINTL
+# Some strange (e.g. cygwin) systems will need this
+GNU_DSM_LIB = libgnu_dsm.la -lopcodes -lbfd -lintl -liberty
+GTEST_LIB = -lgtest
+else
+GNU_DSM_LIB = libgnu_dsm.la -lopcodes -lbfd
+GTEST_LIB = -lgtest -lpthread
+endif
+
+CPPFLAGS_DR =
+LDFLAGS_DR =
+
+if HOST_IS_64BIT
+CPPFLAGS_DR += -DX86_64
+else
+CPPFLAGS_DR += -DX86_32
+endif
+
+if WINDOWS
+CPPFLAGS_DR += -DWINDOWS
+LDFLAGS_DR += dynamorio.dll
+endif
+
+if LINUX
+CPPFLAGS_DR += -DLINUX
+LDFLAGS_DR += -ldynamorio
+endif
+
+CXXFLAGS_DR = $(CPPFLAGS_DR)
+
+
bin_PROGRAMS =
TESTS64_ADDR = x64_addr64_test x64_addr32_test
@@ -69,28 +100,49 @@ check_PROGRAMS = \
erasm_checker \
preprocess
-lib_LTLIBRARIES = liberasm64.la liberasm86.la
+lib_LTLIBRARIES = liberasm.la
check_LTLIBRARIES = liberasm64_test.la liberasm86_test.la libgnu_dsm.la
-ERASM64_TEST_LDADD = liberasm64_test.la liberasm64.la
-ERASM86_TEST_LDADD = liberasm86_test.la liberasm86.la
+ERASM64_TEST_LDADD = liberasm64_test.la liberasm.la
+ERASM86_TEST_LDADD = liberasm86_test.la liberasm.la
EXTRA_PROGRAMS = \
- erasm_dsm_x86_prof \
+ iotest \
+ erasm_dsm_x86_profile \
+ erasm_dsm_x86_demo \
+ erasm_dsm_x86_formatA \
+ erasm_dsm_x86_formatB \
+ erasm_dsm_x86_formatC \
erasm_dsm_x86_performance_test \
- erasm_gdsm_x86_prof \
+ erasm_dsm_x86_performance_test_noio \
+ erasm_dsm_x86_count_ret \
+ erasm_dsm_x86_count_cti \
+ erasm_dsm_x64_performance_test \
+ erasm_gdsm_x86_formatC \
erasm_gdsm_x86_performance_test \
erasm_gdsm_x64_performance_test \
- erasm_dsm_x64_performance_test \
+ erasm_udis_x86_formatA \
+ erasm_udis_x86_formatB \
+ erasm_udis_x86_formatC \
+ erasm_udis_x86_test \
+ erasm_udis_x86_performance_test \
+ erasm_dr_x86_formatB \
+ erasm_dr_x86_performance_test \
+ erasm_dr_x86_test \
+ erasm_dr_x86_count_ret \
+ erasm_dr_x86_count_cti \
test_meta_binomial_heap \
instruction_manual_parser \
myghcpp meta_haskell \
- test_gnudsm hook_test
+ test_gnudsm hook_test \
+ test_faststream
nobase_include_HEADERS = \
erasm/dsm_x64.hpp \
+ erasm/dsm_x64_util.hpp \
erasm/dsm_x64_auto_stm.hpp \
erasm/dsm_x86.hpp \
+ erasm/dsm_x86_util.hpp \
erasm/dsm_x86_auto_stm.hpp \
erasm/intel_common.hpp \
erasm/intel_prefix_bitset.hpp \
@@ -128,13 +180,13 @@ nobase_include_HEADERS = \
erasm/meta_prelude_functions.hpp \
erasm/meta_leftist_heap.hpp \
erasm/meta_polynomial.hpp \
- erasm/common_macros.hpp
+ erasm/common_macros.hpp \
+ erasm/faststream.hpp
dist_noinst_HEADERS = \
erasm/x64_assembler_test_code_64_32.hpp \
erasm/x86_assembler_test_code_32_32.hpp \
gnu_disassembler.hpp \
- mystream.hpp \
dprintf.h \
memory_protection.hpp
@@ -161,20 +213,20 @@ EXTRA_DIST = erasm/x64_assembler_illegal_code.cpp \
#nodist_data_DATA = $(REFERENCES) $(TEST_REFERENCE)
-AM_CPPFLAGS = -include config.h -I $(srcdir) -DERASM_NO_META_ASSERT
+AM_CPPFLAGS = -include config.h -I $(srcdir)
BUILT_SOURCES = $(ERASM_GENERATED_FILES)
-liberasm64_la_SOURCES = erasm/x64.cpp erasm/x64_assembler_impl.cpp \
+liberasm_la_SOURCES = erasm/x64.cpp \
+ erasm/x64_assembler_impl.cpp \
erasm/x64_addr64_data32.cpp \
- erasm/x64_instruction_definition.cpp
-
-
-liberasm86_la_SOURCES = erasm/x64.cpp erasm/x64_assembler_impl.cpp \
- erasm/x86.cpp erasm/x86_assembler_impl.cpp \
+ erasm/x64_instruction_definition.cpp \
+ erasm/x86.cpp \
+ erasm/x86_assembler_impl.cpp \
erasm/x86_addr32_data32.cpp \
- erasm/x86_instruction_definition.cpp
-
-
+ erasm/x86_instruction_definition.cpp \
+ erasm/x86_io.cpp \
+ erasm/x64_io.cpp \
+ erasm/faststream.cpp
liberasm64_test_la_SOURCES= erasm/x64_assembler_test_code_64_32.cpp
@@ -188,18 +240,15 @@ liberasm86_test_la_DEPENDENCIES = erasm/x86_assembler_test_code_32_32.hpp \
erasm_demo86_SOURCES= erasm/demo86.cpp
-erasm_demo86_LDADD = liberasm86.la
+erasm_demo86_LDADD = liberasm.la
-x64_assembler_test_64_32_SOURCES = \
- erasm/x64_assembler_test_main_64_32.cpp
+x64_assembler_test_64_32_SOURCES = erasm/x64_assembler_test_main_64_32.cpp
x64_assembler_test_64_32_LDADD = $(GNU_DSM_LIB) $(ERASM64_TEST_LDADD)
x64_assembler_test_64_32_CPPFLAGS = # -DUSE_SAMPLE_HEADER
x86_assembler_test_32_32_LDADD = $(GNU_DSM_LIB) $(ERASM86_TEST_LDADD)
-x86_assembler_test_32_32_SOURCES = \
- erasm/x86_assembler_test_main_32_32.cpp
-
+x86_assembler_test_32_32_SOURCES = erasm/x86_assembler_test_main_32_32.cpp
test_dsm : erasm_dsm_x64_unit_test$(EXEEXT) \
erasm_dsm_x64_test$(EXEEXT) \
@@ -235,10 +284,9 @@ erasm_gdsm_x64_performance_test_LDADD = $(GNU_DSM_LIB) $(ERASM64_TEST_LDADD)
erasm_dsm_x64_test_SOURCES = erasm/dsm_x64_test_main.cpp \
- erasm/dsm_x64_auto_stm.hpp \
- erasm/x64_io.cpp
+ erasm/dsm_x64_auto_stm.hpp
-erasm_dsm_x64_test_LDADD = $(GNU_DSM_LIB) $(ERASM64_TEST_LDADD)
+erasm_dsm_x64_test_LDADD = $(GNU_DSM_LIB) $(ERASM64_TEST_LDADD) liberasm.la
erasm_dsm_x64_test_CXXFLAGS = $(AM_CXXFLAGS)
erasm_dsm_x64_unit_test_LDADD = $(GTEST_LIB)
@@ -246,6 +294,8 @@ erasm_dsm_x64_unit_test_SOURCES = erasm/dsm_x64_unit_test.cpp
erasm_dsm_x64_unit_test_CXXFLAGS = $(AM_CXXFLAGS)
+
+
test_dsm86 : erasm_dsm_x86_test$(EXEEXT) \
erasm_checker$(EXEEXT) \
test_x86_disassembler_32_32.sh
@@ -256,20 +306,34 @@ dump_dsm86 : erasm_dsm_x86_test$(EXEEXT)
./erasm_dsm_x86_test
time_dsm86 : erasm_dsm_x86_performance_test$(EXEEXT) \
- erasm_dsm_x86_prof$(EXEEXT) \
+ erasm_dsm_x86_performance_test_noio$(EXEEXT) \
+ erasm_dsm_x86_formatA$(EXEEXT) \
+ erasm_dsm_x86_formatB$(EXEEXT) \
+ erasm_dsm_x86_formatC$(EXEEXT) \
+ erasm_dsm_x86_count_ret$(EXEEXT) \
+ erasm_dsm_x86_count_cti$(EXEEXT) \
erasm_gdsm_x86_performance_test$(EXEEXT) \
- erasm_gdsm_x86_prof$(EXEEXT)
- for x in $^ ;do time (./$$x | wc) ;done
-
-
-dsm86.prof : erasm_dsm_x86_prof$(EXEEXT)
+ erasm_gdsm_x86_formatC$(EXEEXT) \
+ erasm_udis_x86_performance_test$(EXEEXT) \
+ erasm_udis_x86_formatA$(EXEEXT) \
+ erasm_udis_x86_formatB$(EXEEXT) \
+ erasm_udis_x86_formatC$(EXEEXT) \
+ erasm_dr_x86_formatB$(EXEEXT) \
+ erasm_dr_x86_performance_test$(EXEEXT) \
+ erasm_dr_x86_test$(EXEEXT) \
+ erasm_dr_x86_count_ret$(EXEEXT) \
+ erasm_dr_x86_count_cti$(EXEEXT)
+ for x in $^ ;do echo $$x;time (./$$x | wc) ;done
+
+
+dsm86.prof : erasm_dsm_x86_profile$(EXEEXT)
./$^ | wc; \
gprof .libs/$^ > $@
-reprof : clean_erasm_dsm_x86_prof dsm86.prof
+reprof : clean_erasm_dsm_x86_profile dsm86.prof
clean_erasm_dsm_x86_prof : FORCE
- rm erasm_dsm_x86_prof*.o erasm_dsm_x86_prof$(EXEEXT) ; true
+ rm erasm_dsm_x86_profile.o erasm_dsm_x86_profile$(EXEEXT) ; true
# CXXFLAGS_O3= -DNDEBUG -O3 -finline-limit=1000000 \
# --param max-inline-insns-single=1000000 \
@@ -282,45 +346,125 @@ clean_erasm_dsm_x86_prof : FORCE
CXXFLAGS_O3 = -DNDEBUG -O3 # -finline-limit=100000
CXXFLAGS_PROF = $(CXXFLAGS_O3) # -pg
-erasm_dsm_x86_performance_test_SOURCES = \
- erasm/dsm_x86_performance_test.cpp
+iotest_SOURCES = iotest.cpp
+iotest_LDADD = liberasm.la
-erasm_dsm_x86_performance_test_CXXFLAGS = \
- -DTEST_MYDSM $(CXXFLAGS_PROF)
-erasm_dsm_x86_performance_test_LDFLAGS = $(CXXFLAGS_PROF)
-erasm_dsm_x86_performance_test_LDADD = $(ERASM86_TEST_LDADD)
+erasm_dsm_x86_profile_SOURCES = erasm/dsm_x86_test_main.cpp \
+ erasm/x86_io.cpp \
+ erasm/x64_io.cpp \
+ erasm/faststream.cpp
+erasm_dsm_x86_profile_LDADD = $(ERASM86_TEST_LDADD)
+erasm_dsm_x86_profile_CXXFLAGS = -DFORMAT=A -DPROFILING $(CXXFLAGS_PROF) -pg
+erasm_dsm_x86_profile_LDFLAGS = $(CXXFLAGS_PROF)
-erasm_gdsm_x86_performance_test_SOURCES = \
- erasm/dsm_x86_performance_test.cpp
-erasm_gdsm_x86_performance_test_CXXFLAGS = \
- -DTEST_GDSM $(CXXFLAGS_PROF)
-erasm_gdsm_x86_performance_test_LDFLAGS = $(CXXFLAGS_PROF)
-erasm_gdsm_x86_performance_test_LDADD = $(GNU_DSM_LIB) $(ERASM86_TEST_LDADD)
+erasm_dsm_x86_performance_test_SOURCES = erasm/dsm_x86_performance_test.cpp
+erasm_dsm_x86_performance_test_CXXFLAGS = -DTEST_MYDSM $(CXXFLAGS_PROF)
+erasm_dsm_x86_performance_test_LDFLAGS = $(CXXFLAGS_PROF)
+erasm_dsm_x86_performance_test_LDADD = $(ERASM86_TEST_LDADD)
-erasm_dsm_x86_test_SOURCES = \
- erasm/dsm_x86_test_main.cpp \
- erasm/x86_io.cpp \
- erasm/x64_io.cpp
-erasm_dsm_x86_test_LDADD = $(ERASM86_TEST_LDADD)
-erasm_dsm_x86_test_CXXFLAGS = $(AM_CXXFLAGS)
+erasm_dsm_x86_performance_test_noio_SOURCES = erasm/dsm_x86_test_noio.cpp
+erasm_dsm_x86_performance_test_noio_CXXFLAGS = -DPROFILING -DTEST_MYDSM $(CXXFLAGS_PROF)
+erasm_dsm_x86_performance_test_noio_LDFLAGS = $(CXXFLAGS_PROF)
+erasm_dsm_x86_performance_test_noio_LDADD = $(ERASM86_TEST_LDADD)
+
+erasm_dsm_x86_count_ret_SOURCES = erasm/dsm_x86_count_ret.cpp
+erasm_dsm_x86_count_ret_CXXFLAGS = -DTEST_MYDSM $(CXXFLAGS_PROF)
+erasm_dsm_x86_count_ret_LDFLAGS = $(CXXFLAGS_PROF)
+erasm_dsm_x86_count_ret_LDADD = $(ERASM86_TEST_LDADD)
+
+erasm_dsm_x86_count_cti_SOURCES = erasm/dsm_x86_count_cti.cpp
+erasm_dsm_x86_count_cti_CXXFLAGS = -DTEST_MYDSM $(CXXFLAGS_PROF)
+erasm_dsm_x86_count_cti_LDFLAGS = $(CXXFLAGS_PROF)
+erasm_dsm_x86_count_cti_LDADD = $(ERASM86_TEST_LDADD)
-erasm_dsm_x86_prof_SOURCES = \
- erasm/dsm_x86_test_main.cpp \
- erasm/x86_io.cpp \
- erasm/x64_io.cpp
-erasm_dsm_x86_prof_LDADD = $(ERASM86_TEST_LDADD)
-erasm_dsm_x86_prof_CXXFLAGS = -DPROFILING $(CXXFLAGS_PROF)
-erasm_dsm_x86_prof_LDFLAGS = $(CXXFLAGS_PROF)
-erasm_gdsm_x86_prof_SOURCES = \
- erasm/dsm_x86_test_main.cpp \
- erasm/x86_io.cpp \
- erasm/x64_io.cpp
-erasm_gdsm_x86_prof_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
-erasm_gdsm_x86_prof_CXXFLAGS = -DPROFILING -DTEST_GDSM $(CXXFLAGS_PROF)
-erasm_gdsm_x86_prof_LDFLAGS = $(CXXFLAGS_PROF)
+test_faststream_SOURCES = test_faststream.cpp
+test_faststream_LDADD = liberasm.la
+erasm_dsm_x86_test_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_dsm_x86_test_LDADD = $(ERASM86_TEST_LDADD)
+erasm_dsm_x86_test_CXXFLAGS = $(AM_CXXFLAGS)
+
+erasm_dsm_x86_formatA_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_dsm_x86_formatA_LDADD = $(ERASM86_TEST_LDADD)
+erasm_dsm_x86_formatA_CXXFLAGS = -DFORMAT=A -DPROFILING $(CXXFLAGS_PROF)
+erasm_dsm_x86_formatA_LDFLAGS = $(CXXFLAGS_PROF)
+
+erasm_dsm_x86_formatB_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_dsm_x86_formatB_LDADD = $(ERASM86_TEST_LDADD)
+erasm_dsm_x86_formatB_CXXFLAGS = -DFORMAT=B -DPROFILING $(CXXFLAGS_PROF)
+erasm_dsm_x86_formatB_LDFLAGS = $(CXXFLAGS_PROF)
+
+erasm_dsm_x86_formatC_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_dsm_x86_formatC_LDADD = $(ERASM86_TEST_LDADD)
+erasm_dsm_x86_formatC_CXXFLAGS = -DFORMAT=C -DPROFILING $(CXXFLAGS_PROF)
+erasm_dsm_x86_formatC_LDFLAGS = $(CXXFLAGS_PROF)
+
+erasm_dsm_x86_demo_SOURCES = erasm/dsm_x86_demo.cpp
+erasm_dsm_x86_demo_LDADD = $(ERASM86_TEST_LDADD)
+erasm_dsm_x86_demo_LDFLAGS = $(CXXFLAGS_PROF)
+
+erasm_gdsm_x86_performance_test_SOURCES = erasm/dsm_x86_performance_test.cpp
+erasm_gdsm_x86_performance_test_CXXFLAGS = -DTEST_GDSM $(CXXFLAGS_PROF)
+erasm_gdsm_x86_performance_test_LDFLAGS = $(CXXFLAGS_PROF)
+erasm_gdsm_x86_performance_test_LDADD = $(GNU_DSM_LIB) $(ERASM86_TEST_LDADD)
+
+erasm_gdsm_x86_formatC_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_gdsm_x86_formatC_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_gdsm_x86_formatC_CXXFLAGS = -DFORMAT=C -DPROFILING -DTEST_GDSM $(CXXFLAGS_PROF)
+erasm_gdsm_x86_formatC_LDFLAGS = $(CXXFLAGS_PROF)
+
+
+erasm_udis_x86_performance_test_SOURCES = erasm/dsm_x86_performance_test.cpp
+erasm_udis_x86_performance_test_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_udis_x86_performance_test_CXXFLAGS= -DPROFILING -DTEST_UDIS $(CXXFLAGS_PROF)
+erasm_udis_x86_performance_test_LDFLAGS = $(CXXFLAGS_PROF) -ludis86
+
+erasm_udis_x86_formatA_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_udis_x86_formatA_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_udis_x86_formatA_CXXFLAGS = -DFORMAT=A -DPROFILING -DTEST_UDIS $(CXXFLAGS_PROF)
+erasm_udis_x86_formatA_LDFLAGS = $(CXXFLAGS_PROF) -ludis86
+
+erasm_udis_x86_formatB_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_udis_x86_formatB_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_udis_x86_formatB_CXXFLAGS = -DFORMAT=B -DPROFILING -DTEST_UDIS $(CXXFLAGS_PROF)
+erasm_udis_x86_formatB_LDFLAGS = $(CXXFLAGS_PROF) -ludis86
+
+erasm_udis_x86_formatC_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_udis_x86_formatC_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_udis_x86_formatC_CXXFLAGS = -DFORMAT=C -DPROFILING -DTEST_UDIS $(CXXFLAGS_PROF)
+erasm_udis_x86_formatC_LDFLAGS = $(CXXFLAGS_PROF) -ludis86
+
+erasm_udis_x86_test_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_udis_x86_test_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_udis_x86_test_CXXFLAGS = -DTEST_UDIS $(CXXFLAGS_PROF)
+erasm_udis_x86_test_LDFLAGS = $(CXXFLAGS_PROF) -ludis86
+
+erasm_dr_x86_formatB_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_dr_x86_formatB_LDADD = $(ERASM86_TEST_LDADD)
+erasm_dr_x86_formatB_CXXFLAGS = -DPROFILING -DTEST_DR $(CXXFLAGS_PROF) $(CXXFLAGS_DR)
+erasm_dr_x86_formatB_LDFLAGS = $(CXXFLAGS_PROF) $(LDFLAGS_DR)
+
+erasm_dr_x86_test_SOURCES = erasm/dsm_x86_test_main.cpp
+erasm_dr_x86_test_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_dr_x86_test_CXXFLAGS = -DTEST_DR $(CXXFLAGS_PROF) $(CXXFLAGS_DR)
+erasm_dr_x86_test_LDFLAGS = $(CXXFLAGS_PROF) $(LDFLAGS_DR)
+
+erasm_dr_x86_performance_test_SOURCES = erasm/dsm_x86_performance_test.cpp
+erasm_dr_x86_performance_test_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_dr_x86_performance_test_CXXFLAGS = -DPROFILING -DTEST_DR $(CXXFLAGS_PROF) $(CXXFLAGS_DR)
+erasm_dr_x86_performance_test_LDFLAGS = $(CXXFLAGS_PROF) $(LDFLAGS_DR)
+
+erasm_dr_x86_count_ret_SOURCES = erasm/dsm_x86_count_ret.cpp
+erasm_dr_x86_count_ret_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_dr_x86_count_ret_CXXFLAGS = -DTEST_DR $(CXXFLAGS_PROF) $(CXXFLAGS_DR)
+erasm_dr_x86_count_ret_LDFLAGS = $(CXXFLAGS_PROF) $(LDFLAGS_DR)
+
+erasm_dr_x86_count_cti_SOURCES = erasm/dsm_x86_count_cti.cpp
+erasm_dr_x86_count_cti_LDADD = $(ERASM86_TEST_LDADD) $(GNU_DSM_LIB)
+erasm_dr_x86_count_cti_CXXFLAGS = -DTEST_DR $(CXXFLAGS_PROF) $(CXXFLAGS_DR)
+erasm_dr_x86_count_cti_LDFLAGS = $(CXXFLAGS_PROF) $(LDFLAGS_DR)
x64_addr64_test_LDADD = $(GTEST_LIB) -lpthread
@@ -360,16 +504,6 @@ hook_test_SOURCES = hook_test.cpp
hook_test_LDADD = $(DSM_LIB) $(GNU_DSM_LIB)
-if HAVE_LIBINTL
-# Some strange (e.g. cygwin) systems will need this
-GNU_DSM_LIB = libgnu_dsm.la -lopcodes -lbfd -lintl -liberty
-GTEST_LIB = -lgtest
-else
-GNU_DSM_LIB = libgnu_dsm.la -lopcodes -lbfd
-GTEST_LIB = -lgtest -lpthread
-endif
-
-
TEST_LIB = libunit_test.la
libgnu_dsm_la_SOURCES = gnu_disassembler.cpp dprintf.cpp
@@ -430,7 +564,6 @@ ERASM_GENERATED_FILES= \
erasm/x64_addr64_data32.cpp \
erasm/x64_addr64_data32.hpp \
erasm/x64_assembler_auto_test.cpp \
- erasm/x64_assembler_auto_test_snapshot.cpp \
erasm/x64_instruction_definition.cpp \
erasm/x64_instruction_definition.hpp \
erasm/x86_addr16_data16.cpp \
@@ -480,10 +613,8 @@ CLEANFILES = opcode_app.txt opcode.txt p2inst.txt seed.txt \
out1.txt \
out2.txt \
out3.txt \
- parse_all.stamp \
parse_all.tmp \
parse_test \
- $(ERASM_GENERATED_FILES) \
disassembler_impl.cpp \
instruction_code.hpp \
assembler_converter.hpp \
@@ -491,3 +622,6 @@ CLEANFILES = opcode_app.txt opcode.txt p2inst.txt seed.txt \
assembler.hpp \
x.cpp
+
+MAINTAINERCLEANFILES = parse_all.stamp $(ERASM_GENERATED_FILES)
+
View
1,140 src/Makefile.in
850 additions, 290 deletions not shown
View
2  src/check_illegal_code.sh
@@ -43,7 +43,7 @@ function check_file()
CODE_FILE=$1
echo Checking illegal code in $CODE_FILE
- FIRST_TEST="add(p,eax,0);"
+ FIRST_TEST="add(p,eax,0u);"
if compile_test_fail "$FIRST_TEST" ;then
echo "FAIL (compilation failed)"
exit 1
View
6 src/config.h.in
@@ -1,5 +1,8 @@
/* src/config.h.in. Generated from configure.ac by autoheader. */
+/* Debug Mode */
+#undef DEBUG
+
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
@@ -37,6 +40,9 @@
*/
#undef LT_OBJDIR
+/* No-debug Mode */
+#undef NDEBUG
+
/* Name of package */
#undef PACKAGE
View
2  src/erasm/demo86.cpp
@@ -12,7 +12,7 @@ int main(int argc,char**argv)
byte_t buf[100];
byte_t *p = buf;
- int32_t x = 2;
+ uint32_t x = 2;
p += mov(p,eax,dword_ptr[esp+4]);
p += add(p,eax,x);
View
13 src/erasm/dsm_x64.hpp
@@ -2092,7 +2092,7 @@ template<class Action,
>
inline
const_code_pointer_type
-decode_instruction(const_code_pointer_type decode_start,Action & action)
+decode(const_code_pointer_type decode_start,Action & action)
{
using namespace impl;
InstructionData params;
@@ -2138,6 +2138,17 @@ decode_instruction(const_code_pointer_type decode_start,Action & action)
return action.error(params);
}
+namespace addr64 { namespace data32 {
+template<class Action>
+inline
+const_code_pointer_type
+decode(const_code_pointer_type decode_start,Action & action)
+{
+ return ::erasm::x64::decode<Action,true,true>
+ (decode_start,action) ;
+}
+}}
+
}}
#endif // MY_ERASM_DSM_X64_HPP
View
2  src/erasm/dsm_x64_performance_test.cpp
@@ -135,7 +135,7 @@ int main()
printf("testing mydsm\n");
Counter mydsm(buff,buff+len);
- decode_instruction<Counter,true,true>(buff,mydsm);
+ decode<Counter,true,true>(buff,mydsm);
int counter = mydsm.counter;
#else
printf("testing gdsm\n");
View
374 src/erasm/dsm_x64_test_main.cpp
@@ -16,289 +16,169 @@
You should have received a copy of the GNU General Public License
along with ERASM++; see the file COPYING. If not see
<http://www.gnu.org/licenses/>. */
+
+#ifndef FORMAT
+#define FORMAT C
+#endif
+
+#define CONCAT(X,Y) X ## Y
+#define PRINT_CODE_FUNC(X) CONCAT(print_code_,X)
+#define PRINT_CODE PRINT_CODE_FUNC(FORMAT)
+
#define ERASM_NO_META_ASSERT 1
-#include "meta_prelude.hpp"
-#include "erasm/dsm_x64.hpp"
-#include "erasm/x64_io.hpp"
-#include "erasm/x64_assembler_test_code_64_32.hpp"
+#include <erasm/meta_prelude.hpp>
+#include <erasm/dsm_x64.hpp>
+#include <erasm/dsm_x64_util.hpp>
+#include <erasm/faststream.hpp>
+#include <erasm/x64_addr64_data32.hpp>
+#include <erasm/x64_assembler_test_code_64_32.hpp>
+
+#include <boost/timer.hpp>
-#include <cstring>
-#include <stdlib.h>
#include <iostream>
#include <iomanip>
-#include <stdio.h>
-
using namespace std;
using namespace erasm::x64;
+inline ostream& print_code_A(ostream& os,const_code_ptr start,const_code_ptr end)
+{ return os ; }
-template<class X>
-struct Id
-{
- Id(const X& x) : x(x) {}
- const X& x;
-};
-
-template<class X>
-struct FormattedInt
-{
- FormattedInt(const X& x) : x(x) {}
- const X& x;
-};
-
-
-namespace erasm { namespace prelude {
-
-DEFINE_FOREIGN_DATA1(Id,class);
-DEFINE_FOREIGN_DATA1(FormattedInt,class);
-
-template<class X>
-struct isBuiltinIntegerType_;
-
-template<class X>
-struct eval<isBuiltinIntegerType_<X> >
-{
- typedef False result;
-};
-
-template<>
-struct eval<isBuiltinIntegerType_<int8_t> >
-{
- typedef True result;
-};
-
-template<>
-struct eval<isBuiltinIntegerType_<uint8_t> >
-{
- typedef True result;
-};
-
-template<>
-struct eval<isBuiltinIntegerType_<int16_t> >
-{
- typedef True result;
-};
-
-template<>
-struct eval<isBuiltinIntegerType_<uint16_t> >
-{
- typedef True result;
-};
+inline ostream& print_code_B(ostream& os,const_code_ptr start,const_code_ptr end)
+{ return os << std::hex << (uint32_t) start << " " ; }
-template<>
-struct eval<isBuiltinIntegerType_<int32_t> >
-{
- typedef True result;
-};
+inline ostream& print_code_C(ostream& os,const_code_ptr start,const_code_ptr end)
+{ return print_code(os,start,end) ; }
-template<>
-struct eval<isBuiltinIntegerType_<uint32_t> >
-{
- typedef True result;
-};
-template<>
-struct eval<isBuiltinIntegerType_<int64_t> >
+struct MyDsm : SimpleDsm<PRINT_CODE>
{
- typedef True result;
-};
-
-template<>
-struct eval<isBuiltinIntegerType_<uint64_t> >
-{
- typedef True result;
-};
-
-template<class X>
-struct isBuiltinIntegerType;
-template<class X>
-struct eval<isBuiltinIntegerType<X> >
-{
- // typedef typename eval<X>::result X_;
- typedef typename eval<isBuiltinIntegerType_<X> > ::result result;
-};
-
-ERASM_META_ASSERT_EQUAL((isBuiltinIntegerType<int>),(True));
-ERASM_META_ASSERT_EQUAL((isBuiltinIntegerType<Zero>),(False));
-
-}}
-
-
-template<class X> inline ostream& operator<< (ostream& os,Id<X> x)
-{ return os << x.x; }
-
-template<class X> inline ostream& operator<< (ostream& os,FormattedInt<X> x)
-{ return os << showbase << hex << (int)x.x; }
-
-
-using namespace erasm::prelude;
-template<class X>
-struct FormattedOp
- : eval<if_<isBuiltinIntegerType<X> ,
- FormattedInt<X> ,
- Id<X> > > :: result
-{
- typedef typename eval<if_<isBuiltinIntegerType<X> ,
- FormattedInt<X> ,
- Id<X> > > :: result base;
- FormattedOp(const X& x)
- : base(x)
+ typedef SimpleDsm<PRINT_CODE> base;
+ const_code_ptr end;
+ MyDsm(const_code_ptr start,const_code_ptr end,ostream& os = erasm::cout)
+ : base(start,os) ,end(end)
{}
- const base & get_base() const
- { return *this ; }
-};
-
-template<class X> inline ostream& operator<< (ostream& os,FormattedOp<X> x)
-{ return os << x.get_base(); }
-
-template<class X> inline FormattedOp<X> format(const X& x)
-{ return FormattedOp<X>(x); }
+ using base::action;
+ action_result_type
+ action(const Ret& insn)
+ {
+ if (insn.end >= end) {
+ return finish(insn);
+ }
+ print_code(os(),insn);
+ print_instruction(os(),insn) << endl;
+ return next(insn);
+ }
+};
+byte_t buff[1024 * 1024 * 10 ];
-template<class Insn>
-inline
-ostream&
-print_instruction(ostream& os,
- const Insn& insn)
+int gen_code(int n)
{
- print_code(os,insn.start,insn.end);
- os << Insn::mnemonic << endl;
- return os;
+ using namespace erasm::x64::addr64::data32;
+ code_ptr p = buff;
+ for (int i=0; i<n;i++) {
+ p += gen_manual_test(p);
+ p += gen_auto_test(p);
+ }
+ int len = p - buff;
+
+ p += ret(p);
+ return len;
}
-template<class Insn,class Op>
-inline
-ostream&
-print_instruction(ostream& os,
- const Insn& insn,
- const Op & op1)
+#ifdef TEST_GDSM
+int dsm(code_ptr beg,code_ptr end )
{
- print_code(os,insn.start,insn.end);
- os << Insn::mnemonic
- << " " << format(op1) << endl;
- return os;
+ cerr << "testing gdsm" << endl;
+ using namespace gnu_dsm;
+ Disassembler dsm(true,false,"intel,i386,addr64,data32");
+ int count = dsm.print(beg,end);
+ return count;
}
-
-template<class Insn,class Op1,class Op2>
-inline
-ostream&
-print_instruction(ostream& os,
- const Insn& insn,
- const Op1 & op1,
- const Op2 & op2)
-{
- print_code(os,insn.start,insn.end);
- os << Insn::mnemonic
- << " " << format(op1)
- << "," << format(op2) << endl;
- return os;
+#elif defined TEST_UDIS
+int dsm(code_ptr beg,code_ptr end )
+{
+ cerr << "testing udis86" << endl;
+ ud_t ud_obj;
+ unsigned char* p = (unsigned char*) beg;
+ size_t size = end - beg;
+ int count = 0;
+
+ ud_init(&ud_obj);
+ ud_set_input_buffer(&ud_obj, p , size);
+
+ ud_set_mode(&ud_obj, 64);
+
+ ud_set_syntax(&ud_obj, UD_SYN_INTEL);
+ ud_set_vendor(&ud_obj, UD_VENDOR_INTEL);
+
+ int len;
+ while (len = ud_disassemble(&ud_obj)) {
+ unsigned char* pc = beg + ud_obj.pc;
+ //printf("%08x",ud_obj.pc);
+ PRINT_CODE(::erasm::cout,pc, pc + len);
+ printf("\t%s\n", ud_insn_asm(&ud_obj));
+ count ++;
+ }
+ return count;
}
-
-template<class Insn,class Op1,class Op2,class Op3>
-inline
-ostream&
-print_instruction(ostream& os,
- const Insn& insn,
- const Op1 & op1,
- const Op2 & op2,
- const Op3 & op3)
+#elif defined TEST_DR
+int dsm(code_ptr beg,code_ptr end )
{
- print_code(os,insn.start,insn.end);
- os << Insn::mnemonic
- << " " << format(op1)
- << "," << format(op2)
- << "," << format(op3) << endl;
- return os;
-}
+ cerr << "testing dr" << endl;
+ int count = 0;
+ disassemble_set_syntax(DR_DISASM_INTEL);
+ byte* p = (byte*) beg;
-
-
-template<class Stream>
-struct Disasm
-{
- const_code_ptr start;
- const_code_ptr end;
- Stream& os;
-
- Disasm(const_code_ptr start,const_code_ptr end,Stream& os)
- : start(start),end(end),os(os)
- {}
-
- action_result_type cont(const InstructionData& params)
- {
- return make_pair(params.end,
- params.end < end ?
- ACTION_CONTINUE : ACTION_FINISH );
- }
-
- template<class Insn>
- action_result_type
- action(const Insn& insn)
- {
- print_instruction(os,insn);
- return cont(insn.data());
- }
-
- template<class Insn,class Op1>
- action_result_type
- action(const Insn& insn,
- const Op1& op1)
- {
- print_instruction(os,insn,op1);
- return cont(insn.data());
- }
-
- template<class Insn,class Op1,class Op2>
- action_result_type
- action(const Insn& insn,
- const Op1& op1,
- const Op2& op2)
- {
- print_instruction(os,insn,op1,op2);
- return cont(insn.data());
+ while (p < end) {
+ byte* next = disassemble(GLOBAL_DCONTEXT,p,1);
+ if (next) {
+ p = next ;
+ } else {
+ p ++;
}
+ count ++;
+ }
+ return count;
+}
+#else
+int dsm(code_ptr beg,code_ptr end )
+{
+ cerr << "testing mydsm" << endl;
+ typedef MyDsm dsm_type;
+ dsm_type mydsm(beg,end);
+ erasm::x64::addr64::data32::decode<dsm_type>(buff,mydsm);
+ return mydsm.get_counter();
+}
+#endif
- template<class Insn,class Op1,class Op2,class Op3>
- action_result_type
- action(const Insn& insn,
- const Op1& op1,
- const Op2& op2,
- const Op3& op3)
- {
- print_instruction(os,insn,op1,op2,op3);
- return cont(insn.data());
- }
-
- const_code_ptr
- error(const InstructionData& data)
- {
- print_code(os,data.start,data.start+5);
- os << "decode error:" << data.action_code << endl;
- os << "decoded length:" << data.start - start << endl;
- return data.start;
- }
-};
+int main(int argc,char**argv)
+{
+#ifdef PROFILING
+ int n = 1000;
+#else
+ int n = 1;
+#endif
-byte_t buff[1024 * 1024 ];
+ {
+ int len = gen_code(n);
-int main()
-{
- code_ptr p = buff;
- p += erasm::x64::addr64::data32::gen_manual_test(p);
- p += erasm::x64::addr64::data32::gen_auto_test(p);
+ boost::timer t0;
- int len = p-buff;
+ int count = dsm(buff,buff+len);
- typedef Disasm<ostream> dsm_type;
+ float elapsed = t0.elapsed();
+ cerr << "elapsed time = " << elapsed << " sec" << endl;
+ cerr << "number of bytes:" << len << endl;
+ cerr << "number of instructions:" << count << endl;
+ }
- dsm_type dsm(buff,buff+len ,cout);
- decode_instruction<dsm_type,true,true>(buff,dsm);
return 0;
}
View
16 src/erasm/dsm_x86.hpp
@@ -2017,7 +2017,7 @@ template<class Action,
>
inline
const_code_pointer_type
-decode_instruction(const_code_pointer_type decode_start,Action & action)
+decode(const_code_pointer_type decode_start,Action & action)
{
using namespace impl;
InstructionData params;
@@ -2060,8 +2060,22 @@ decode_instruction(const_code_pointer_type decode_start,Action & action)
return action.error(params);
}
+namespace addr32 { namespace data32 {
+template<class Action>
+inline
+const_code_pointer_type
+decode(const_code_pointer_type decode_start,Action & action)
+{
+ return ::erasm::x86::decode<Action,true,true>
+ (decode_start,action) ;
+}
}}
+}}
+
+
+
+
#endif // MY_ERASM_DSM_X86_HPP
View
87 src/erasm/dsm_x86_performance_test.cpp
@@ -25,25 +25,17 @@
#include "gnu_disassembler.hpp"
#include <boost/timer.hpp>
-#include <sstream>
-#include <string>
-#include <cstring>
-#include <stdlib.h>
-#include <iostream>
-#include <iomanip>
-#include <stdio.h>
+#ifdef TEST_UDIS
+#include <udis86.h>
+#endif
+#ifdef TEST_DR
+#include <dr_api.h>
+#endif
-using std::ostream;
-using std::hex;
-using std::showbase;
-using std::cout;
-using std::endl;
-using std::cerr;
-using std::make_pair;
-using std::string;
-using std::ostringstream;
+#include <iostream>
+using namespace std;
using namespace erasm::x86;
struct Counter
@@ -75,14 +67,6 @@ struct Counter
return check(insn);
}
- action_result_type
- action(const Jmp& insn)
- {
- counter ++;
- return check(insn);
- }
-
-
template<class Insn>
action_result_type
action(const Insn& insn)
@@ -153,7 +137,7 @@ int counter(code_ptr start,code_ptr end)
{
cerr << "testing mydsm" << endl;
Counter mydsm(start,end);
- decode_instruction<Counter,true,true>(buff,mydsm);
+ decode<Counter,true,true>(buff,mydsm);
int counter = mydsm.counter;
return counter;
}
@@ -172,6 +156,59 @@ int counter(code_ptr start,code_ptr end)
}
return counter;
}
+#elif defined TEST_UDIS
+int counter(code_ptr beg,code_ptr end )
+{
+ cerr << "testing udis86" << endl;
+ ud_t ud_obj;
+ unsigned char* p = (unsigned char*) beg;
+ size_t size = end - beg;
+ int count = 0;
+
+ ud_init(&ud_obj);
+ //ud_set_input_file(&ud_obj, stdin);
+ ud_set_input_buffer(&ud_obj, p , size);
+
+ //ud_set_mode(&ud_obj, 64);
+ ud_set_mode(&ud_obj, 32);
+
+ ud_set_syntax(&ud_obj, UD_SYN_INTEL);
+
+ while (ud_disassemble(&ud_obj)) {
+ //printf("\t%s\n", ud_insn_asm(&ud_obj));
+ count ++;
+ }
+ return count;
+}
+
+#elif defined TEST_DR
+int counter(code_ptr beg,code_ptr end )
+{
+ cerr << "testing dr" << endl;
+ void * context = dr_standalone_init();
+ instr_t instr;
+ instr_init(context,&instr);
+ byte* pc = beg;
+ int count = 0;
+
+ while (pc < end) {
+ //byte* next = decode(context, pc, &instr);
+ //instr_reuse(context, &instr);
+ byte* next = decode_next_pc(context,pc);
+
+ /* check for invalid instr */
+ if (next == NULL) {
+ pc ++;
+ } else {
+ pc = next;
+ }
+ count ++;
+ }
+
+ instr_free(context, &instr);
+ return count;
+}
+
#endif
View
330 src/erasm/dsm_x86_test_main.cpp
@@ -16,235 +16,48 @@
You should have received a copy of the GNU General Public License
along with ERASM++; see the file COPYING. If not see
<http://www.gnu.org/licenses/>. */
-#define ERASM_NO_META_ASSERT 1
-#include "meta_prelude.hpp"
-#include "erasm/dsm_x86.hpp"
-#include "erasm/x86_io.hpp"
-#include "erasm/x86_assembler_test_code_32_32.hpp"
-#include "erasm/x86_addr32_data32.hpp"
-#include "gnu_disassembler.hpp"
-#include <boost/timer.hpp>
-
-#include <sstream>
-#include <string>
-#include <cstring>
-#include <stdlib.h>
-#include <iostream>
-#include <iomanip>
-#include <stdio.h>
-
-#include "mystream.hpp"
-
-using std::ostream;
-using std::hex;
-using std::showbase;
-using std::cout;
-using std::cerr;
-using std::make_pair;
-using std::string;
-using std::ostringstream;
-
-
-using namespace erasm::x86;
-const char endl = '\n';
-
-inline ostream& operator<< (ostream& os,const FarPtr16& ptr)
-{
- os << showbase << hex << ptr.selector <<':'
- << showbase << hex << ptr.offset ;
- return os;
-}
-
-inline ostream& operator<< (ostream& os,const FarPtr32& ptr)
-{
- os << showbase << hex << ptr.selector <<':'
- << showbase << hex << ptr.offset ;
- return os;
-}
-
-
-
-template<class X>
-struct Formatted
-{
- Formatted(const X& x) : x(x) { }
- const X& x;
-};
-
-template<class X>
-inline ostream & operator<< (ostream& os,const Formatted<X>& x)
-{ return os << x.x; }
-
-template<>
-inline ostream & operator<< (ostream& os,const Formatted<uint8_t>& x)
-{ return os << showbase << hex << (int) x.x;}
-
-template<>
-inline ostream & operator<< (ostream& os,const Formatted<uint16_t>& x)
-{ return os << showbase << hex << (int) x.x; }
-
-template<>
-inline ostream & operator<< (ostream& os,const Formatted<uint32_t>& x)
-{ return os << showbase << hex << (int) x.x; }
-
-template<>
-inline ostream & operator<< (ostream& os,const Formatted<int8_t>& x)
-{ return os << showbase << hex << (int) x.x;}
-
-template<>
-inline ostream & operator<< (ostream& os,const Formatted<int16_t>& x)
-{ return os << showbase << hex << (int) x.x; }
-
-template<>
-inline ostream & operator<< (ostream& os,const Formatted<int32_t>& x)
-{ return os << showbase << hex << (int) x.x; }
-template<class X> inline Formatted<X> format(const X& x)
-{ return Formatted<X>(x) ; }
-
-
-template<class Insn>
-ostream&
-print_instruction(ostream& os,
- const Insn& insn)
-{
- print_code(os,insn.start,insn.end);
- os << Insn::mnemonic << endl;
- return os;
-}
-
-template<class Insn,class Op>
-ostream&
-print_instruction(ostream& os,
- const Insn& insn,
- const Op & op1)
-{
- print_code(os,insn.start,insn.end);
- os << Insn::mnemonic;
- os << " " << format(op1) << endl;
- return os;
-}
-
-template<class Insn,class Op1,class Op2>
-ostream&
-print_instruction(ostream& os,
- const Insn& insn,
- const Op1 & op1,
- const Op2 & op2)
-{
- print_code(os,insn.start,insn.end);
- os << Insn::mnemonic;
- os << " " << format(op1);
- os << "," << format(op2) << endl;
- return os;
-}
+#ifndef FORMAT
+#define FORMAT C
+#endif
-template<class Insn,class Op1,class Op2,class Op3>
-ostream&
-print_instruction(ostream& os,
- const Insn& insn,
- const Op1 & op1,
- const Op2 & op2,
- const Op3 & op3)
-{
- print_code(os,insn.start,insn.end);
- os << Insn::mnemonic ;
- os << " " << format(op1) ;
- os << "," << format(op2) ;
- os << "," << format(op3) << endl;
- return os;
-}
+#define CONCAT(X,Y) X ## Y
+#define PRINT_CODE_FUNC(X) CONCAT(print_code_,X)
+#define PRINT_CODE PRINT_CODE_FUNC(FORMAT)
+#define ERASM_NO_META_ASSERT 1
-struct Disasm
-{
- const_code_ptr start;
- const_code_ptr end;
- ostream& os;
- int count;
+#include "gnu_disassembler.hpp"
+#include <erasm/dsm_x86.hpp>
+#include <erasm/dsm_x86_util.hpp>
+#include <erasm/x86_assembler_test_code_32_32.hpp>
+#include <erasm/x86_addr32_data32.hpp>
+#include <erasm/faststream.hpp>
+#include <boost/timer.hpp>
- Disasm(const_code_ptr start,const_code_ptr end,ostream& os)
- : start(start),end(end),os(os) ,count(0)
- {
- }
-
- action_result_type finish(const InstructionData& params)
- {
- return make_pair(params.end, ACTION_FINISH);
- }
+#ifdef TEST_UDIS
+#include <udis86.h>
+#endif
- action_result_type cont(const InstructionData& params)
- {
- count++;
- return make_pair(params.end, ACTION_CONTINUE);
- }
+#ifdef TEST_DR
+#include <dr_api.h>
+#endif
- action_result_type check(const InstructionData& params)
- {
- if (params.end >= end) {
- return finish(params);
- }
- return cont(params);
- }
+using erasm::x86::const_code_ptr;
- action_result_type
- action(const Ret& insn)
- {
- if (insn.end >= end) {
- return finish(insn);
- }
- print_instruction(os,insn);
- return cont(insn);
- }
+inline std::ostream& print_code_A(std::ostream& os,const_code_ptr start,const_code_ptr end)
+{ return os ; }
- template<class Insn>
- action_result_type
- action(const Insn& insn)
- {
- print_instruction(os,insn);
- return cont(insn.data());
- }
+inline std::ostream& print_code_B(std::ostream& os,const_code_ptr start,const_code_ptr end)
+{ return os << std::hex << (uint32_t) start << " " ; }
- template<class Insn,class Op1>
- action_result_type
- action(const Insn& insn,
- const Op1& op1)
- {
- print_instruction(os,insn,op1);
- return cont(insn.data());
- }
+inline std::ostream& print_code_C(std::ostream& os,const_code_ptr start,const_code_ptr end)
+{ return erasm::x86::print_code(os,start,end) ; }
- template<class Insn,class Op1,class Op2>
- action_result_type
- action(const Insn& insn,
- const Op1& op1,
- const Op2& op2)
- {
- print_instruction(os,insn,op1,op2);
- return cont(insn.data());
- }
- template<class Insn,class Op1,class Op2,class Op3>
- action_result_type
- action(const Insn& insn,
- const Op1& op1,
- const Op2& op2,
- const Op3& op3)
- {
- print_instruction(os,insn,op1,op2,op3);
- return cont(insn.data());
- }
-
- const_code_ptr
- error(const InstructionData& data)
- {
- print_code(os,data.start,data.start+5);
- os << "decode error:" << data.action_code << endl;
- os << "decoded length:" << data.start - start << endl;
- return data.start;
- }
+using namespace std;
+using namespace erasm::x86;
-};
byte_t buff[1024 * 1024 * 10 ];
@@ -272,16 +85,88 @@ int dsm(code_ptr beg,code_ptr end )
int count = dsm.print(beg,end);
return count;
}
+#elif defined TEST_UDIS
+int dsm(code_ptr beg,code_ptr end )
+{
+ cerr << "testing udis86" << endl;
+ ud_t ud_obj;
+ unsigned char* p = (unsigned char*) beg;
+ size_t size = end - beg;
+ int count = 0;
+
+ ud_init(&ud_obj);
+ //ud_set_input_file(&ud_obj, stdin);
+ ud_set_input_buffer(&ud_obj, p , size);
+
+ //ud_set_mode(&ud_obj, 64);
+ ud_set_mode(&ud_obj, 32);
+
+ ud_set_syntax(&ud_obj, UD_SYN_INTEL);
+ ud_set_vendor(&ud_obj, UD_VENDOR_INTEL);
+
+ int len;
+ while (len = ud_disassemble(&ud_obj)) {
+ unsigned char* pc = beg + ud_obj.pc;
+ //printf("%08x",ud_obj.pc);
+ PRINT_CODE(::erasm::cout,pc, pc + len);
+ printf("\t%s\n", ud_insn_asm(&ud_obj));
+ count ++;
+ }
+ return count;
+}
+#elif defined TEST_DR
+int dsm(code_ptr beg,code_ptr end )
+{
+ cerr << "testing dr" << endl;
+ void * context = dr_standalone_init();
+ int count = 0;
+ disassemble_set_syntax(DR_DISASM_INTEL);
+
+ byte* p = (byte*) beg;
+
+ while (p < end) {
+ byte* next = disassemble(context,p,STDOUT);
+ if (next) {
+ p = next ;
+ } else {
+ p ++;
+ }
+ count ++;
+ }
+ return count;
+}
#else
-my::omystream<526 -1> myout(stdout);
-//my::nullstream myout;
+
+struct MyDsm : SimpleDsm<PRINT_CODE>
+{
+ typedef SimpleDsm<PRINT_CODE> base;
+ const_code_ptr end;
+ MyDsm(const_code_ptr start,const_code_ptr end,ostream& os = erasm::cout)
+ : base(start,os) ,end(end)
+ {}
+
+ using base::action;
+
+ action_result_type
+ action(const Ret& insn)
+ {
+ if (insn.end >= end) {
+ return finish(insn);
+ }
+ print_code(os(),insn);
+ print_instruction(os(),insn) << endl;
+ return next(insn);
+ }
+};
+
+
int dsm(code_ptr beg,code_ptr end )
{
cerr << "testing mydsm" << endl;
- typedef Disasm dsm_type;
- dsm_type mydsm(beg,end , myout);
- decode_instruction<dsm_type,true,true>(buff,mydsm);
- return mydsm.count;
+ typedef MyDsm dsm_type;
+ dsm_type mydsm(beg,end);
+ erasm::x86::addr32::data32::decode<dsm_type>(buff,mydsm);
+ return mydsm.get_counter();
}
#endif
@@ -297,7 +182,6 @@ int main(int argc,char**argv)
{
int len = gen_code(n);
-
boost::timer t0;
int count = dsm(buff,buff+len);
View
4,876 src/erasm/x64_assembler_auto_test.cpp
2,438 additions, 2,438 deletions not shown
View
2,635 src/erasm/x64_assembler_auto_test_snapshot.cpp
0 additions, 2,635 deletions not shown
View
22 src/erasm/x64_assembler_manual_test.cpp
@@ -12,7 +12,7 @@ p += adc(p,byte_ptr[rax + r13*_4+0x1],(imm8_t)0x1);
p += adc(p,byte_ptr[rbp + r13*_4+0x1],(imm8_t)0x1);
p += adc(p,byte_ptr[rax+0x1],(imm8_t)0x1);
p += adc(p,byte_ptr[rax+0xcccc],(imm8_t)0x1);
-p += adc(p,byte_ptr[rax+(imm32_t)0x2],(imm8_t)0x1);
+p += adc(p,byte_ptr[rax+(rel32_t)0x2],(imm8_t)0x1);
p += adc(p,al,(imm8_t)0x1);
p += adc(p,ax,(imm16_t)0x1);
p += adc(p,eax,(imm32_t)0x2);
@@ -137,16 +137,16 @@ p += mov(p,ax,word_offset.gs[0x12345678U]);
p += mov(p,eax,dword_offset.ds[0x12345678U]);
p += mov(p,rax,qword_offset.es[0x12345678U]);
-p += mov(p,al,0x1);
-p += mov(p,ah,0x1);
-p += mov(p,dil,0x1);
-p += mov(p,r8b,0x1);
-p += mov(p,ax,0x1);
-p += mov(p,r8w,0x1);
-p += mov(p,eax,0x1);
-p += mov(p,r8d,0x1);
-p += mov(p,rax,0x1);
-p += mov(p,r8 ,0x1);