Commit Graph

284 Commits

Author SHA1 Message Date
Tristan Ravitch
c228cca75c Merge branch 'master' of github.com:GaloisInc/macaw-semmc into HEAD 2018-05-18 15:28:59 -07:00
Tristan Ravitch
1ed8d66dc7 Improve the BinaryLoader interface
It is now (optionally) pure via the MonadThrow class.  It also exposes a new
binary format repr, which currently only has constructors for ELF containers.
2018-05-18 15:26:19 -07:00
Kevin Quick
f81f2437ee
Update for crucible reorganization and new what4 module. 2018-05-18 08:33:58 -07:00
Tristan Ravitch
27810cdbf3 Add a draft of a generic binary loading interface, simplify TOC handling on PPC
The generic binary loading interface is instantiated once for each
architecture/binary container pair.  This isn't great, but there is enough
custom work in each setting to justify it.

The binary loading interface isn't finished yet, and needs to learn some
additional operations to support relocation.  It already supports additional
information that is architecture specific and binary container format
specific (that operations will have to use on a per-format basis).

On the PowerPC side, the Table of Contents (TOC) is now architecture-specific
information constructed by the loader (currently from ELF binaries).  The new
TOC data type is in place to support this more easily (the old format was just a
function).
2018-05-17 16:03:04 -07:00
Tristan Ravitch
7d306f052d Export more details from macaw-ppc 2018-05-03 16:40:58 -07:00
Tristan Ravitch
6747f0ed44 Generalize the HasRepr instance for PPCPrimFn 2018-05-03 10:00:53 -07:00
Tristan Ravitch
05061a2140 Add a PrettyF instance for PPCReg 2018-05-03 09:46:46 -07:00
Tristan Ravitch
4bed676ca2 Update to the latest macaw 2018-04-24 10:55:07 -07:00
Tristan Ravitch
8f4865e106 Haddock fixes 2018-04-10 10:27:29 -07:00
Tristan Ravitch
b7c3118070 Update the calls to asAtomicStateUpdate
The type of the instruction address changed
2018-03-30 10:52:58 -07:00
Tristan Ravitch
76eb501d45 ppc: Improve the register pretty printer 2018-03-29 18:07:25 -07:00
Tristan Ravitch
f959773cbd Emit the new 'ArchState' macaw statement
This change is in the core generator monad and applied in the PowerPC backend.
This change includes some macaw updates (which required a new elf-edit version).
2018-03-29 18:06:26 -07:00
Tristan Ravitch
ebd52aa11c Remove some unused imports 2018-03-29 11:18:56 -07:00
Tristan Ravitch
716092eef1 ppc: Improve the test suite
Now test to ensure that no blocks end in a classification failure (or a
disassembly failure).  Before, many blocks were not classified, which causes
problems downstream.  This required some changes in macaw core in two places:

1. The simplifier needed some additional rules to remove some redundant
   constructions that threw off the abstract interpretation of values.  This was
   particularly an issue while reading return values off of the stack in
   PowerPC.
2. Extending the abstract interpretation to be able to handle more operations (shiftl)
2018-03-28 16:59:12 -07:00
Tristan Ravitch
fdb00dec14 ppc: Initialize the stack pointer in the abstract state
PPC uses r1 for the stack pointer
2018-03-28 16:59:12 -07:00
Tristan Ravitch
d885de3a72 ppc: Implement identifyReturn
We need special treatment of the return, as the low two bits are cleared on
PowerPC, so we can't just rely on pattern matching against the ReturnAddr in the
IP register.
2018-03-28 16:59:12 -07:00
Tristan Ravitch
d3a97edb4b ppc: Implement identifyReturn 2018-03-27 18:19:36 -07:00
Kevin Quick
7d7656bbd7
[ppc] Replace deprecated asLiteralAddr with valueAsMemAddr. 2018-03-27 10:51:16 -07:00
Kevin Quick
5ec4b48e16
[ppc] Update identifyReturn to identify based on IP == LNK
The identifyReturn was previously unused because the Macaw Discovery
performed this test inline, but some architectures have different
semantics so the identifyReturn is now used by the Discovery process.
This implements the return discovery that should be sufficient for the
PPC.
2018-03-27 10:49:30 -07:00
Tristan Ravitch
2d54ca1362 ppc: Fix some expected test output
Recent changes in macaw(-base) mean that we split blocks more aggressively.  The
old expected outputs were conservative - these new values are much more in line
with intuitive expectation (with more aggressive splitting of blocks and less
code duplication between blocks).
2018-03-23 15:14:54 -07:00
Kevin Quick
a3fe4a0f6b
Modify genExecInstruction to use functions for opcode semantics bodies.
Pass operand and architecture types and instead of

   case opcode of
      ADD -> case operands of
               Just GPR gpr0 :< Nil of ->
                   SSA-semantics

Generate:

    let opc_ADD operands = case operands of
                             Just GPR gpr0 :< Nil of ->
                                SSA-semantics
    in case opcode of
         ADD -> opc_ADD operand

This provides better encapsulation for the individual operands and
more specific control over the types (at the cost of a pair of
additional type specifications in the call).  This also seems to
reduce memory consumption by about half.
2018-03-05 16:02:17 -08:00
Daniel Wagner
851168f9ad let tests compile again 2018-03-01 11:45:59 -05:00
Tristan Ravitch
82bbd93d2a ppc: Add arch statements for hardware transactional memory
These instructions are mostly outside of our model.  That said, they do have
effects on the CPU state that we really should model, but are not yet.
2018-02-28 22:33:10 -08:00
Kevin Quick
e8b9d8a6a4
[ppc] Update for changed Macaw.Memory LoadOptions. 2018-02-22 17:37:40 -08:00
Kevin Quick
22bbdf7ee7
Common ExtractValue instances for sharing amongst architectures. 2018-02-07 11:34:38 -08:00
Tristan Ravitch
aaf2f67ea4 ppc: Add arch-specific statements for some icache instructions 2018-01-22 11:22:24 -08:00
Tristan Ravitch
71e3d868b8 Fix a bug in handling arch-specific statements
The system call instructions TRAP and SC were updating the IP twice, which led
to skipping instructions.  The IP increment for these instructions was already
handled in the abstract interpretation of arch-specific terminators.
2018-01-22 10:34:52 -08:00
Tristan Ravitch
46333f1a09 Submodule updates 2018-01-22 10:26:20 -08:00
Tristan Ravitch
260ac399c6 Merge branch 'master' of gitlab-ext.galois.com:macaw/macaw-semmc 2018-01-19 18:12:47 -08:00
Tristan Ravitch
37d6ca6732 Fix a bug where arch-specific statements weren't incrementing the IP 2018-01-19 18:12:15 -08:00
Ben Selfridge
7e47db94a3 Updated macaw-ppc to handle floating-point UFs 2018-01-17 12:54:30 -08:00
Ben Selfridge
f6face9136 Added VSCR for vector semantics 2018-01-08 17:56:00 -08:00
Ben Selfridge
63c2fec79b Simplified code using addArchExpr. 2018-01-05 14:58:15 -08:00
Ben Selfridge
3c3ffbc375 Merge branch 'master' of gitlab-ext.galois.com:macaw/macaw-semmc 2018-01-05 13:38:36 -08:00
Ben Selfridge
d95b1f6b3f Updated macaw-ppc code to handle VecN PPCPrimFns. 2018-01-05 13:27:53 -08:00
Tristan Ravitch
2247747bef Update submodules to the latest macaw (and others)
Macaw has removed all floating point expression types, so we duplicate those as
arch-specific functions for PowerPC until the more general floating point
support is ready.
2018-01-02 18:17:32 -08:00
Tristan Ravitch
5a2999089a Remove some tracing 2017-12-18 17:15:05 -08:00
Tristan Ravitch
b7359957bf Remove the Witness type and related constraint magic
This change uses ShapeReprs, and requires changes from dismantle and semmc
2017-12-17 21:29:17 -08:00
Tristan Ravitch
f1b0775be8 Update to the new parameterized-utils List
This replaces the old ShapedList from dismantle-tablegen
2017-12-13 21:56:29 -08:00
Tristan Ravitch
269c329b93 Factor out the rest of the architecture-independent code
The PowerPC bits are now in macaw-ppc and the rest now lives in macaw-semmc.
2017-12-10 20:53:03 -08:00
Tristan Ravitch
a24ea27be5 ppc: Implement the abstract evaluator for the TRAP instruction
Basically treat it just like a system call for now.
2017-11-29 20:27:25 -08:00
Tristan Ravitch
52dc736c08 ppc: Add more support for CR and FPSCR instructions 2017-11-29 16:30:46 -08:00
Ben Selfridge
45a898cf5d added double precision load/store 2017-11-29 15:11:12 -08:00
Ben Selfridge
11affb8848 Tests for all single-precision floating point load and store ops 2017-11-29 15:02:07 -08:00
Ben Selfridge
a25a477944 added first actual floating point test instruction (stfs) 2017-11-29 13:08:11 -08:00
Tristan Ravitch
5cea5a8a42 ppc: Fix the expected results of the fp test case 2017-11-29 10:14:20 -08:00
Tristan Ravitch
b033f3788c ppc: Change how we translate instructions represented by arch-specific statements
The old method involved providing the TH code a list of match expressions.  This
made it very difficult to inspect arguments of instructions.  The new approach
has the architecture backend provide a function that gets the first opportunity
to process instructions, which is much more flexible.  This commit also includes
support for a number of cache hint instructions that use the new features.
2017-11-28 21:36:49 -08:00
Ben Selfridge
3d1eb18289 Added support for floating point LT uf 2017-11-28 14:47:28 -08:00
Tristan Ravitch
ef5150e2e1 ppc: Remove an unused module 2017-11-27 22:53:55 -08:00
Tristan Ravitch
df03ddf439 Use more qualified names in the TH-generated SimpleBuilder->Macaw translation
This gives us better name capture properties, allowing us to use more
restrictive imports in the PPC64 and PPC32 modules.
2017-11-27 22:40:18 -08:00
Tristan Ravitch
289e1f33be [ppc] Updates to support some vector instructions
The semantics for many of the vector instructions are incomplete and just set
the target register to undefined.  This is enough for code discovery (for now).
2017-11-27 18:16:19 -08:00
Tristan Ravitch
c7af261d66 Marginally improve compile times
Disable a few optimizations in the TH-generated modules and add a fallthrough
case to prevent the coverage checker from firing.
2017-11-27 08:33:48 -08:00
Tristan Ravitch
7256fd597f Generalize the generator monad, the TH helper monad, and the simplifier
This code was mostly architecture independent already, so this commit moves it
to the macaw-semmc module so that it can be shared with the ARM backend.  I
still plan to move the main TH module with the SimpleBuilder to macaw
translation, but that requires a few other changes first.
2017-11-26 23:31:04 -08:00
Ben Selfridge
221e5b3407 Merge branch 'master' of gitlab-ext.galois.com:macaw/macaw-semmc 2017-11-22 16:31:51 -08:00
Ben Selfridge
e1ffa245c2 added support for is_snan uninterpreted functions 2017-11-22 16:31:36 -08:00
Tristan Ravitch
18d5ac3fe4 Add a translation for the undefined value from semmc 2017-11-21 23:37:17 -08:00
Tristan Ravitch
3b763bf347 Export useful helpers from macaw-ppc
This includes another ELF helper to find function entry points and the
type-level tags to choose between the 32 and 64 bit architectures.
2017-11-21 14:21:37 -08:00
Tristan Ravitch
d49dbc679c [ppc] Make the PPC ELF helpers easier to use
The TOC parser now doesn't require a Memory object, making it easier to actually
instantiate this in derived tools (where the TOC parser needs to be used before
a memory is available).  To do this, we use MemAddr as the base type for the TOC
instead of MemSegmentOff
2017-11-21 14:10:47 -08:00
Tristan Ravitch
80145a0161 Fix a bad exponential behavior bug
The recursive simplifier could exhibit exponential behavior in cases where a
nested tree of irreducable terms were accumulated.  The recursive calls quickly
exploded execution times.

The fix was to remove the recursive calls from the simplifier, but to
incrementally simplify expressions to constants as they are added (via the
addExpr function).  This simplifies as much as the recursive case, but more
efficiently.  This change required exporting the simplifyApp function.
2017-11-16 21:42:30 -05:00
Ben Selfridge
9ce1ffa0c5 Added test case for floating point store. Not really functional yet. 2017-11-16 16:08:25 -08:00
Tristan Ravitch
dbbb0bd947 Add TOC entries to the macaw list of entry points in the test harness
This code now pulls all of the function addresses from the TOC as entry points
for the code discovery search.  This lets us trivially find code reachable via
indirect calls, as the function pointer discovery heuristic doesn't seem to be
well-suited to PowerPC.  I'd like to push on that, but it seems like a good
start for now.
2017-11-16 10:16:22 -05:00
Ben Selfridge
399cd4ab6c Merge branch 'master' of gitlab-ext.galois.com:macaw/macaw-semmc 2017-11-15 18:00:39 -08:00
Ben Selfridge
e1963bcbf2 Added single_to_double for floating point operations 2017-11-15 18:00:19 -08:00
Tristan Ravitch
2092a0fd01 Add a (currently failing) test for indirect call handling
The code pointer discovery in macaw can't handle this case because we never
write the code pointers into memory - we only read them.  We really need a way
to tell macaw about code pointers.

The easy workaround is to pull all of the function entry points out of the TOC
and just seed the macaw search with them, but it would be nice to be able to
identify them from first principles.
2017-11-14 19:00:01 -08:00
Tristan Ravitch
94b72b2c73 Improvements for the generated semantics transformers
This change now memoizes translations of SimpleBuilder expression fragments,
which allows us to restore the sharing in semantics formulas.  The generator
re-uses shared sub-expressions automatically now.  This generates less Haskell
code, yielding better code density and fewer terms constructed at run time.  It
also reduces compile times.

It seems to cut the size of the generated TH code by about half.  It also
generates less deeply-nested Haskell code, making the resulting TH splices human
readable.
2017-11-13 10:46:33 -08:00
Tristan Ravitch
2002afa246 [ppc] Add preliminary support for popcount
It isn't supported in SimpleBuilder, so we use an uninterpreted function in the
formula language for now.
2017-11-10 16:52:38 -08:00
Tristan Ravitch
bbd00f7ef2 [ppc] Add division and a few arch-specific statements
The arch-specific statements are for memory synchronization
2017-11-10 14:48:35 -08:00
Tristan Ravitch
48dfa4d192 Remove an accidentally-committed binary file 2017-11-10 08:18:16 -08:00
Tristan Ravitch
9d750c944a Add a new type of test to PowerPC
It runs code discovery over a large-ish binary to test coverage.  We currently
fail due to unsupported instructions (expected).  This test will guide
priorities on implementing new semantics.
2017-11-09 17:18:20 -08:00
Tristan Ravitch
fc1bd8b077 Add support for more instructions
semmc has semantics for many new instructions.  We also added support for
translating the count leading zero functions.
2017-11-09 17:17:51 -08:00
Tristan Ravitch
d5d1d87fd5 Split some shared helpers out of a test module 2017-11-09 10:43:41 -08:00
Tristan Ravitch
e307c9a82a Add a comment in the test suite 2017-11-08 15:46:40 -08:00
Tristan Ravitch
e5d20c6acf Fix an expected test output
It looks like I counted the bytes wrong the first time
2017-11-08 10:56:13 -08:00
Tristan Ravitch
b9835b9767 Cleanup and documentation pass 2017-11-07 22:46:06 -08:00
Tristan Ravitch
599a357515 Don't export curPPCState 2017-11-07 21:45:04 -08:00
Tristan Ravitch
a03953ecdc Delete some obsolete comments 2017-11-07 21:36:25 -08:00
Tristan Ravitch
6308df3a8f Add a helper to set register values
This helper additionally simplifies constants.  This is very useful for dealing
with simplifying the instruction pointer.  That is required by the rest of
macaw, which expects IP values it wants to explore to be fully reduced.
2017-11-07 21:16:00 -08:00
Tristan Ravitch
71a432ed18 Improve the test suite
Don't just ensure that found blocks are expected: also ensure that all expected
blocks are found.
2017-11-07 20:50:33 -08:00
Tristan Ravitch
c3d0ede125 Import alignment 2017-11-07 20:29:41 -08:00
Tristan Ravitch
65bc1231fb Implement 'identifyCall' for PowerPC
The current heuristic isn't great, but is probably okay for now.  It just checks
to see if the LNK register is an address plus four.  Something more precise
would require knowing the address of the next instruction, but we can't get that
from the IP, which has already been changed due to the call.
2017-11-07 20:23:11 -08:00
Tristan Ravitch
a648a4c50b Improve the formatting for test failures
Now print addresses as hex values
2017-11-07 20:22:49 -08:00
Tristan Ravitch
fed8e00482 [ppc] Fix the offsets in the call test 2017-11-07 20:22:32 -08:00
Tristan Ravitch
f126dbf5fa Add a (currently failing) test for calls 2017-11-07 17:49:53 -08:00
Tristan Ravitch
48ba00870d Add some extra tracing to 'identifyFunction' 2017-11-07 17:49:36 -08:00
Tristan Ravitch
65c940e334 Remove an unused function 2017-11-07 17:49:28 -08:00
Tristan Ravitch
fdcbbeae39 Fix a bug in register value handling
The semantics of each instruction are atomic updates over the register state.
Prior to this commit, changes were not atomic and updates to register values
were visible to later register definitions, which causes a huge number of
problems.  Now, we take a snapshot of the register state at the beginning of the
instruction and read all values we need from that snapshot.  This way, updates
are isolated from one another.
2017-11-07 17:45:00 -08:00
Tristan Ravitch
fc48993507 Update an expected test result
My understanding of how macaw splits up blocks was incorrect when I wrote the
test initially.  Macaw doesn't split blocks just because a jump happens to land
in the middle of the block, so the middle block in this example is actually a
few instructions longer.
2017-11-07 14:32:51 -08:00
Tristan Ravitch
81fbec6bb9 Improve the layout of the frontier calculation 2017-11-07 13:45:40 -08:00
Tristan Ravitch
a4cbd3a9d0 Make the simplifier more powerful
It now recursively traverses its arguments.  This isn't great from an efficiency
perspective, but we need it to be able to simplify instruction pointers computed
from relative jumps (which involve some sign extensions and shifts).
2017-11-07 13:44:41 -08:00
Tristan Ravitch
0b43f5672e Have 'matchConditionalBranch' simplify the values it returns
These values are new values of the IP to explore, and the code consuming these
values expects them to be BV literals (i.e., simplified from expressions to
values).

The simplifier isn't currently powerful enough to simplify everything we throw
at it, but this is at least the right place to apply it.  If we don't simplify
here, the core of macaw won't know how to follow the IP changes and will miss
blocks.
2017-11-07 11:36:50 -08:00
Tristan Ravitch
32d37e1a31 Delete an obsolete comment 2017-11-07 11:36:36 -08:00
Tristan Ravitch
ec9695d29b Fix the initial PreBlock state w.r.t. block ids
We were initializing the next PreBlock ID as 0, which caused that block id to be
reused later (the initial block is given ID 0)
2017-11-07 11:28:01 -08:00
Tristan Ravitch
e405e23b93 Fix a bug where we were generating macaw bitvector literals with negative integer components
Apparently this is not allowed, and caused an assertion failure in a pretty printer.
2017-11-07 11:24:57 -08:00
Tristan Ravitch
48bfd87165 Add a missing register (XER) to the macaw register state 2017-11-06 19:44:19 -08:00
Tristan Ravitch
fcb694ccb9 Add a test for conditional branches
It doesn't pass yet.  It is hung up on an unsupported register type (Crrc, used
in a compare).
2017-11-06 17:19:16 -08:00
Tristan Ravitch
11a754b3ed Add support for conditional branches 2017-11-06 17:18:59 -08:00
Tristan Ravitch
8db18882fa Factor out the implementations of some of the TH translations
These operations generate a lot of code, so it is helpful to factor them out and
reduce the burden on the type checker.  Factoring these two definitions out cuts
the generated code nearly in half.
2017-11-06 15:43:32 -08:00
Tristan Ravitch
6a45dc0893 [ppc] Fix an issue with floating point translation
The change is actually in the semantics (semmc), where we were extracting the
wrong part of the 128 bit vector registers to operate on.  Many operations were
being simplified to zero, which manifest as unused fprc registers.
2017-11-06 14:25:54 -08:00
Tristan Ravitch
15078b2bde Remove more unused imports 2017-11-06 10:22:16 -08:00
Tristan Ravitch
4e1db21b08 Remove another piece of commented-out code 2017-11-06 10:15:18 -08:00