Getting Started with x86 » History » Revision 50
Revision 49 (Alexander Protsenko, 04/06/2017 05:43 PM) → Revision 50/87 (Alexander Protsenko, 04/06/2017 05:56 PM)
h1. Getting Started with x86 {{toc}} h2. Prerequisite MicroTESK should be [[Installation Guide|installed]]. h2. Demo Specifications Specifications of the x86 (8086) instruction set architecture (ISA) can be found in "$MICROTESK_HOME/arch/demo/x86/model/x86.nml":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/model/x86.nml. Instruction are described in [[nML Language Reference|nML]] by means of the following constructs (_mov r16/r16_ is taken as an example): ## the signature <pre><code class="c">op <pre>op mov_r1616 (dst: GPR16, src: GPR16)</code></pre> GPR16)</pre> ## the assembly format <pre><code class="c">syntax <pre>syntax = format("mov %s, %s", dst.syntax, src.syntax)</code></pre> src.syntax)</pre> ## the binary encoding <pre><code class="c">image <pre>image = format("1000101111%s%s", dst.image, src.image)</code></pre> src.image)</pre> ## the semantics <pre><code class="c"> <pre> action = { dst = src; ... } </code></pre> </pre> To compile the ISA model, run the following command: <pre>sh $MICROTESK_HOME/bin/compile.sh x86.nml</pre> h2. Demo Templates Test templates for the x86 ISA can be found in "$MICROTESK_HOME/arch/demo/x86/templates":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/templates. The directory contains a number of demo templates including the following ones: {background:#f6fcff}. | "block.rb":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/templates/block.rb | demonstrates how to use block constructs | | "block_random.rb":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/templates/block_random.rb | demonstrates how to create randomized instruction sequences using block constructs | {background:#f6fcff}. | "euclid.rb":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/templates/euclid.rb | demonstrates test program simulation to predict the resulting microprocessor state | | "random.rb":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/templates/random.rb | demonstrates how to randomize tests by using biases and distributions | {background:#f6fcff}. | "random_immediate.rb":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/templates/random_immediate.rb | demonstrates how to randomize immediate values | | "random_registers.rb":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/templates/random_registers.rb | demonstrates how to randomize registers (dependencies) | Test templates are written in "Ruby":http://www.ruby-lang.org extended with specific [[Template_Description_Language|constructs]]. Let''s review one of the templates ("block.rb":http://forge.ispras.ru/projects/microtesk/repository/entry/trunk/microtesk/src/main/arch/demo/x86/templates/block.rb) (@block.rb@) in detail. # includes the file where the base class is defined, containing definition of the x86 ISA registers, their preparators, etc. <pre><code class="ruby">require_relative ''x86_base''</code></pre> <pre>require_relative ''x86_base''</pre> # declares current template class declaration as a heir of X86BaseTemplate <pre><code class="ruby">class <pre>class BlockTemplate < X86BaseTemplate</code></pre> X86BaseTemplate</pre> # defines a "run" method (also, "initialize", "pre", and "post" methods are declared in the base class, and always inherited) <pre><code class="ruby"> <pre> def run</code></pre> run</pre> # produces a single test case that consists of three instructions <pre><code class="ruby"> <pre> sequence { mov_r16r16 ax, bx sub_r16r16 cx, dx add_r16r16 gpr16(_), gpr16(_) }.run </code></pre> </pre> # atomic sequence; works as sequence in this context <pre><code class="ruby"> <pre> atomic { mov_r16r16 ax, bx add_r16r16 cx, dx sub_r16r16 gpr16(_), gpr16(_) }.run </code></pre> </pre> # produces three test cases each consisting of one instruction <pre><code class="ruby"> <pre> iterate { mov_r16r16 ax, bx sub_r16r16 cx, dx add_r16r16 gpr16(_), gpr16(_) }.run </code></pre> </pre> # produces four test cases consisting of two instructions (Cartesian product composed in a random order) <pre><code class="ruby"> <pre> block(:combinator => ''product'', :compositor => ''random'') { iterate { sub_r16r16 cx, dx add_r16r16 ax, bx } iterate { mov_r16r16 ax, bx sub_r16r16 gpr16(_), gpr16(_) } }.run </code></pre> </pre> # merges two sequences in random fashion; atomic sequences are unmodifiable <pre><code class="ruby"> <pre> block(:combinator => ''diagonal'', :compositor => ''random'', :obfuscator => ''random'') { sequence { sub_r16r16 bx, ax or_r16r16 cx, dx } atomic { prologue { comment ''Atomic starts'' } epilogue { comment ''Atomic ends'' } and_r16r16 gpr16(_), gpr16(_) } }.run </code></pre> </pre> # finishes definition of the "run" method and class "BlockTemplate" <pre><code class="ruby"> <pre> end end </code></pre> </pre> To generate test program(s) from a test template (in our case, from @block.rb@), run the following command: <pre>sh $MICROTESK_HOME/bin/generate.sh x86 block.rb --code-file-prefix block --code-file-extension asm -v</pre> When generation is finished, the resulting assembly code can be found in @$MICROTESK_HOME@. Output file: block_0000.s To execute resulted test cases is possible by means of the "online simulator":https://www.tutorialspoint.com/compile_assembly_online.php !Example_block.png!