Getting Started with x86 » History » Revision 50
« Previous |
Revision 50/87
(diff)
| Next »
Alexander Protsenko, 04/06/2017 05:56 PM
Getting Started with x86¶
Prerequisite¶
MicroTESK should be installed.
Demo Specifications¶
Specifications of the x86 (8086) instruction set architecture (ISA) can be found in $MICROTESK_HOME/arch/demo/x86/model/x86.nml.
Instruction are described in nML by means of the following constructs (mov r16/r16 is taken as an example):
- the signature
op mov_r1616 (dst: GPR16, src: GPR16)
- the assembly format
syntax = format("mov %s, %s", dst.syntax, src.syntax)
- the binary encoding
image = format("1000101111%s%s", dst.image, src.image)
- the semantics
action = { dst = src; ... }
To compile the ISA model, run the following command:
sh $MICROTESK_HOME/bin/compile.sh x86.nml
Demo Templates¶
Test templates for the x86 ISA can be found in $MICROTESK_HOME/arch/demo/x86/templates.
The directory contains a number of demo templates including the following ones:
block.rb | demonstrates how to use block constructs |
block_random.rb | demonstrates how to create randomized instruction sequences using block constructs |
euclid.rb | demonstrates test program simulation to predict the resulting microprocessor state |
random.rb | demonstrates how to randomize tests by using biases and distributions |
random_immediate.rb | demonstrates how to randomize immediate values |
random_registers.rb | demonstrates how to randomize registers (dependencies) |
Test templates are written in Ruby extended with specific constructs.
Let''s review one of the templates (block.rb) in detail.- includes the file where the base class is defined, containing definition of the x86 ISA registers, their preparators, etc.
require_relative ''x86_base''
- declares current template class declaration as a heir of X86BaseTemplate
class BlockTemplate < X86BaseTemplate
- defines a "run" method (also, "initialize", "pre", and "post" methods are declared in the base class, and always inherited)
def run
- produces a single test case that consists of three instructions
sequence { mov_r16r16 ax, bx sub_r16r16 cx, dx add_r16r16 gpr16(_), gpr16(_) }.run
- atomic sequence; works as sequence in this context
atomic { mov_r16r16 ax, bx add_r16r16 cx, dx sub_r16r16 gpr16(_), gpr16(_) }.run
- produces three test cases each consisting of one instruction
iterate { mov_r16r16 ax, bx sub_r16r16 cx, dx add_r16r16 gpr16(_), gpr16(_) }.run
- produces four test cases consisting of two instructions (Cartesian product composed in a random order)
block(:combinator => ''product'', :compositor => ''random'') { iterate { sub_r16r16 cx, dx add_r16r16 ax, bx } iterate { mov_r16r16 ax, bx sub_r16r16 gpr16(_), gpr16(_) } }.run
- merges two sequences in random fashion; atomic sequences are unmodifiable
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
- finishes definition of the "run" method and class "BlockTemplate"
end end
To generate test program(s) from a test template (in our case, from block.rb
), run the following command:
sh $MICROTESK_HOME/bin/generate.sh x86 block.rb --code-file-prefix block --code-file-extension asm -v
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
Updated by Alexander Protsenko over 7 years ago · 87 revisions