Commit Graph

14 Commits

Author SHA1 Message Date
Alessandro Di Federico 475adf963c Update VariableManager's DataLayout after linking 2016-01-30 11:02:07 +01:00
Alessandro Di Federico f20c8e8839 Take initial values for CPU state from libtinycode 2016-01-30 10:59:00 +01:00
Alessandro Di Federico a0f89a4269 Delay Env + non-const failures to run-time 2016-01-30 10:57:57 +01:00
Alessandro Di Federico cc7851d040 Abort upon an unhandled usage of the CPU state
When an unexpected instruction is met in `CorrectCPUStateUsagePass`,
propagate the error until a load or a store is performed, then emit an
`abort`.
2016-01-12 18:08:14 +01:00
Alessandro Di Federico d510fea8c7 Simplify command line usage exploiting ELF info
* s/`importGlobalData`/`parseELF`/
* Save the entry point specified in the ELF header, which will be used
  if the user doesn't provide an address.
* Let parse `parseELF` take care of informing libtinycode about what
  has to be mmap'd and where.
* Remove some support scripts used during testing, now no longer
  necessary.
* Various cleanups
2016-01-09 13:37:03 +01:00
Alessandro Di Federico 3c0fce0ba0 Transform calls to cpu_loop_exit to cpu_loop
`cpu_loop_exit` is used by QEMU to get back control from the translated
code while running an helper. Here we complete the inversion of the
hierarchy by transforming calls to `cpu_loop_exit` into calls to our
customized `cpu_loop`, which will handle syscalls and the like.

Since originally `cpu_loop_exit` was a noreturn function, we also need to
ensure that the semantic of its usage is preserved. We do this by setting
a global variable (`cpu_loop_exiting`) right after the call to
`cpu_loop_exit` and forcing the whole call stack to return immediately
if it's true.

* Introduce `CpuLoopExitPass`: replace all the calls to
  `cpu_loop_exit` with a call to `cpu_loop`, a store true to
  `cpu_loop_exiting` and a return. Then take all the callers and make
  them return if `cpu_loop_exiting` is set. Once we get to the translated
  function just reset `cpu_loop_exiting` to false.
* Introduce `VariableManager::computeEnvAddress`: generate code to
  compute the offset of env . This computation is useful when
  reference to the CPU state must be arificially introduced. This code
  will be flattened by `CorrectCPUStateUsagePass` later.
2016-01-04 21:47:26 +01:00
Alessandro Di Federico 581be847ce Abort on unsupported accesses to the CPU state
Currently we do not support access to pointer data types in the CPU state
structure. Now, since their usage is marginal, instead of failing at
compile-time we put an abort instruction when the code reaches that
point.

The same is done in case an access to an array member using a
non-constant index is performed.
2016-01-04 21:26:43 +01:00
Alessandro Di Federico 046947da14 CorrectCPUStateUsagePass: add support to IntToPtr 2016-01-04 21:24:31 +01:00
Alessandro Di Federico 46cb955bfa Replace existing globals if a new name is given 2016-01-04 21:23:36 +01:00
Alessandro Di Federico 1ca2e57f00 Allow unsupported but dead usages of the CPU state 2016-01-04 21:22:40 +01:00
Alessandro Di Federico 6338f3b0b8 Link with helpers and adjust their CPU state usage
* Move initialization and management of the structure describing the CPU
  state (CPUStateType) into variablemanager.cpp.
* Support parts of CPU state outside "env" (e.g. the MIPSCPU
  structure). Now "env" has an offset into the possibly larger CPU state
  which we have to take into account where appropriate (see
  VariableManager::envOffset).
* Link the helpers module into the generated module, including only what
  is needed.
* Create some "no-op" or "abort" function corresponding to QEMU functions
  not included in the helper module (e.g. logging and abort functions).
* Implement the CorrectCPUStateUsagePass pass, which starts from the
  "env" global variable and looks for all its usages recursively, keeping
  track of where pointers are pointing into the CPU state data structure,
  and replaces all the load/stores with the global variable corresponding
  to that specific field of the CPU state.
* After the linking phase, run SROA, the pass to adjust the CPU usage and
  DCE.
* Let global variables have common linkage.
2015-12-04 23:44:46 +01:00
Alessandro Di Federico 4416ef84d1 getTypeAtOffset: handle arrays of structs 2015-12-03 18:00:30 +01:00
Alessandro Di Federico 4e326f5799 Factorize LLVM-related helper functions 2015-12-03 17:59:32 +01:00
Alessandro Di Federico 5d130b7072 Split ptctollvmir.cpp into multiple files 2015-11-24 15:21:17 +01:00