Commit Graph

1642 Commits

Author SHA1 Message Date
Alessandro Di Federico 38b79e944b Add support to load from CPU state 2015-11-23 20:14:16 +01:00
Alessandro Di Federico 3f25b17091 Handle explicitly the CPU state pointer 2015-11-23 20:14:16 +01:00
Alessandro Di Federico 15cc08304c Zero extend before storing into CPU state 2015-11-23 20:14:16 +01:00
Alessandro Di Federico a091b1b675 Don't remove nodes while iterating over them 2015-11-23 20:14:16 +01:00
Alessandro Di Federico 3e8bed2ce8 Decouple PTC::* from InstructionTranslator 2015-11-23 20:14:09 +01:00
Alessandro Di Federico 37615bb6e6 Fix UAF in DebugHelper (OutputPath) 2015-11-23 20:04:55 +01:00
Alessandro Di Federico 1d4e3169eb Add support for indirect jumps and function calls
The main aim of these changes is to support `ret` instructions (that are
indirect jumps), so that function calls can now work properly.

* Emit a dummy call to a `@newPC` function to record where a new
  instruction in the original assembly started, what is its PC and its
  size. The `Size` parameter for these function call is initially zero,
  and it's updated later when a new instruction is met or the current
  basic block is terminated. All these calls, before the final emission
  of the IR are removed `InstructionTranslator::removeNewPCMarkers`.
* Transform translateMoveToPC into an LLVM pass
  (`TranslateDirectBranchesPass`).
* Implement `getNextPC`, which returns the next program counter by
  looking for a call to `@newpc` in the current basic block, and,
  recursively, in all the basic blocks dominating the current one. This
  function is used to force exploration of the basic block coming after
  a direct jump, which is paritcularly useful in case of a function call.
* Introduce `translateIndirectJumps`, which translates all the leftover
  writes to the PC, i.e. all the indirect ones, by diverting execution
  to a large switch statement mapping addresses in the original program
  to the corresponding basic blocks in the translated program.
* Introduce `function_call`, a simple test for function calls.
* Other minor changes and whitespace fixes.
2015-11-15 12:06:17 +01:00
Alessandro Di Federico e2efe161e0 Add support for MIPS
First time all tests pass!
2015-11-10 09:22:58 +01:00
Alessandro Di Federico 94864e49b5 Introduce support for virtual addresses
* mmap on the PTC side before doing any translation
* Update usages of virtual addresses
* Refactor options to have --load-at and --entry
* Update tests according to the changes
2015-11-10 00:05:21 +01:00
Alessandro Di Federico 91a01937cf Let support.c know about the target architecture 2015-11-07 15:02:12 +01:00
Alessandro Di Federico 1d56c32667 Make writes to PC explicit
* Introduce PassManager running SROA
* Import the ScalarOpts LLVM module
2015-11-07 15:02:11 +01:00
Alessandro Di Federico c232c01238 Improve dump of PTC helper call instructions 2015-11-07 15:02:11 +01:00
Alessandro Di Federico ba950d26f2 Split CodeGenerator::translate and use CPUState from the QEMU helpers
* Implement an handler for PTC_INSTRUCTION_op_debug_insn_start
* Implement an handler for calls to helpers
* Implement an handler for all the remaining instructions
* Discover automatically path of the helpers module
* Import the IRReader module
* Remove support for predefined global variables
* Implement getByCPUStateOffset which returns or creates a global
  variable from an offset in the CPUState structure
* Remove the VariableManager::createGlobal function
* Implement getTypeAtOffset which searches for the data type at the
  specified offset, recursively exploring sub-structs
* Autodetect the CPUState structure by election on the struct parameters
  of the helper functions
* CodeGenerator::translate returns void
* Multiplication should sign-extend, not zero-extend
* Fix wrong update of alloca insertion point
* Implement PTC_INSTRUCTION_op_mul{u,s}2_i{32,64} instructions
2015-11-07 15:02:11 +01:00
Alessandro Di Federico 711b798be6 Refactoring
* Fix whitespaces
* Fix case of method names
2015-11-07 15:02:11 +01:00
Alessandro Di Federico ee850e39bc Introduce C++ wrapper of the PTC library
* s/PTC/PTCInterface/
* Implement InstructionArgumentsIterator
* Implement Instrcution and CallInstruction
2015-11-07 15:02:11 +01:00
Alessandro Di Federico 4a151eaa82 Fix handling of debug information
* Don't output a source line if it's identical to the last printed one
* Invoke DIBuilder::finalize as appropriate
* Fix off-by-one in line number computation
2015-11-07 15:02:05 +01:00
Alessandro Di Federico f6ae68516d Use llc from the given LLVM installation 2015-11-07 15:01:34 +01:00
Alessandro Di Federico bd898de98f Fix propagation of OutputPath and DebugPath 2015-11-07 15:01:34 +01:00
Alessandro Di Federico 282fa2b40b Import functional-style iterators 2015-11-07 15:01:34 +01:00
Alessandro Di Federico 9795191f11 Add support for 64-bit local variables 2015-11-07 15:01:16 +01:00
Alessandro Di Federico fd1070b708 Disable RTTI 2015-11-07 14:24:20 +01:00
Alessandro Di Federico c5d510f4d6 Introduce using namespace std in ptctollvmir.cpp 2015-10-27 17:44:25 +01:00
Alessandro Di Federico 9007943839 Refactor the Translate function
* Create the CodeGenerator class from most of the logic that was in the
  Translate function.
* Extract debug information handling logic from the Translate function and move
  it into the DebugManager class.
* Add include guards.
* Remove some dead code and add and fix documentation.
2015-10-27 17:19:52 +01:00
Alessandro Di Federico 15cfbee422 Make reference to QEMU install path and dlopen an absolute path 2015-10-27 11:56:08 +01:00
Alessandro Di Federico 9cf82f36d8 Introduce testing framework
* Import single-function calculator
* Create a puppet CMake project for cross-compiling
* Create a CMake manager for the tests
2015-10-27 09:13:14 +01:00
Alessandro Di Federico 2b5823c6bc Dump useful information in case an unsupported helper is called 2015-10-27 08:54:05 +01:00
Alessandro Di Federico a4fdf0f1b5 Improve debug info handling
* Add support to specify a path for debug source
* Annotate generated LLVM with original assembly and PTC
* As debug source, use the same .ll as the compiled one
2015-10-27 08:54:05 +01:00
Alessandro Di Federico cb3ef7b263 Make global names case-insensitive 2015-10-27 08:54:05 +01:00
Alessandro Di Federico 7f9b86787c Minor refactoring of CMakeLists.txt 2015-10-27 08:54:05 +01:00
Alessandro Di Federico 089bfd2461 Introduce support for LLVM IR debugging information 2015-10-27 08:54:05 +01:00
Alessandro Di Federico 3b0588b75d Add support for PTC debug info 2015-10-27 08:54:04 +01:00
Alessandro Di Federico 256718cac4 Draft support for debug information (original assembly only) 2015-10-27 08:54:04 +01:00
Alessandro Di Federico 4b3a333493 Add support for add2 and sub2 PTC instructions 2015-10-27 08:53:58 +01:00
Alessandro Di Federico 15a2aba050 Introduce JumpTargetManager 2015-10-17 22:47:34 +02:00
Alessandro Di Federico fe6b6f8df9 Introduce explicit program counter handling
* Add support for predefined variables in VariableManager.
* Add the program counter to the architecture descriptor.
2015-10-17 22:44:53 +02:00
Alessandro Di Federico e22268a5ca Introduce handling of branches local to a PTC basic block 2015-10-17 22:44:53 +02:00
Alessandro Di Federico bba0fb78f6 Fix typos, coding style issues and add some documentation 2015-10-17 22:44:53 +02:00
Alessandro Di Federico a97f955a15 Fix bug in handling operands of load and store instructions 2015-10-17 22:44:53 +02:00
Alessandro Di Federico 6579e83bcd Introduce a wrapper to create comparison instructions (CreateICmp) 2015-10-17 22:44:53 +02:00
Alessandro Di Federico 0669fd625c Rename main function to root and change its return type to void 2015-10-17 22:44:52 +02:00
Alessandro Di Federico 8f88625e94 Add metadata with original and PTC instructions to each new instruction
* Convert ptcdump.cpp to use streams and export more fine-grained functions
* Add documentation to ptcdump.h
* Create metadata for the original instruction when a
  PTC_INSTRUCTION_op_debug_insn_start instruction is met.
2015-10-17 22:44:42 +02:00
Alessandro Di Federico 5ee7b1dd8a Initial import 2015-09-26 15:17:32 +02:00