Commit graph

129 commits

Author SHA1 Message Date
Awal Garg 853bf477cc minor fixes 2020-08-30 19:27:07 -05:00
Awal Garg e33cc8f072 rust restructuring, some refactoring 2020-08-30 19:27:07 -05:00
Awal Garg 5d0d683bbc fix deps and remove trailing space 2020-08-30 19:27:07 -05:00
Awal Garg 75ed04e959 copy wasmgen bins instead of moving 2020-08-30 19:27:07 -05:00
Awal Garg fc7f4b468c add wasmgen tests to makefile 2020-08-30 19:27:07 -05:00
Awal Garg 95a65153f4 fix commit_instruction_body_to_cs 2020-08-30 19:27:07 -05:00
Awal Garg 03f0da9525 use wg_ prefix for wasmgen, add tests to makefile 2020-08-30 19:27:07 -05:00
Ernest Wong 129269fc14 Add devices test to CI + update tests to linux4 2020-08-30 19:27:07 -05:00
Fabian 4129335287 Stats printing 2020-08-30 19:27:02 -05:00
Fabian 9afb7eb39c Instruction stats: Instrument code to count how often certain opcodes are used 2020-08-30 19:27:02 -05:00
Fabian f2274e0a60 Fix nasm test with forced jit
This is a (partial) fix for #8. It manually forces compilation of the
first set of basic blocks in the nasm tests, waits for the blocks to be
compiled and then runs the test. It doesn't make use of the fragile
compile-time machinery to force compilation.

Analysis currently doesn't follow execution after the popf instructions,
which is included in most tests. It has been manually verified that
tests pass when the popf instruction is compiled, and this limitation
will be lifted soon.

Analysis also doesn't follow through call and return instructions, so
nasm tests can't currently test these in their compiled form.
2020-07-21 20:10:14 -05:00
Fabian 91480947da Expect test: Add missing dependency on build/v86-debug.wasm 2020-07-21 20:10:14 -05:00
Fabian e6af9f3d7f Expect tests 2020-07-21 20:10:14 -05:00
Fabian f093e23f9e Explicity use -std=c11 2020-07-21 20:10:14 -05:00
Fabian a30556b155 Don't rebuild other instruction tables when generate_analyzer.js changes 2020-07-21 20:10:14 -05:00
Fabian f8349af093 New block analysis, generation of state machine with multiple basic blocks
This commit consists of three components:

1. A new generated x86-parser that analyses instructions. For now, it
   only detects the control flow of an instruction: Whether it is a
   (conditional) jump, a normal instruction or a basic block boundary
2. A new function, jit_find_basic_blocks, that finds and connects basic
   blocks using 1. It loosely finds all basic blocks making up a function,
   i.e. it doesn't follow call or return instructions (but it does follow
   all near jumps). Different from our previous analysis, it also finds
   basic blocks in the strict sense that no basic block contains a jump
   into the middle of another basic block
3. A new code-generating function, jit_generate, that takes the output
   of 2 as input. It generates a state machine:
   - Each basic block becomes a case block in a switch-table
   - Each basic block ends with setting a state variable for the following basic block
   - The switch-table is inside a while(true) loop, which is terminated
     by return statements in basic blocks which are leaves

Additionally:
- Block linking has been removed as it is (mostly) obsoleted by these
  changes. It may later be reactived for call instructions
- The code generator API has been extended to generate the code for the state machine
- The iterations of the state machine are limited in order to avoid
  infinite loops that can't be interrupted
2020-07-21 20:10:14 -05:00
Fabian ed763e09a7 Fix clang-tidy invocation 2020-07-21 20:10:14 -05:00
Fabian 5c4c48e6dc Add JIT_ALWAYS handling to makefile and add nasm test with JIT_ALWAYS 2020-07-21 20:10:14 -05:00
Fabian 4379e5ef3e Use qemu as a test oracle instead of the local machine
Recently distributions started disabling the CONFIG_MODIFY_LDT_SYSCALL
kernel config, breaking parts of the qemu test. qemu is very suitable to
run these tests in the same configuration as v86 (booting from
linux3.iso, exchanging files using 9p fs and controlling via serial
console).
2020-07-21 20:10:14 -05:00
Amaan Cheval ce1ca76aea Backup and generate diff in generate_{jit,interpreter}, not Makefile 2020-07-21 20:10:14 -05:00
Amaan Cheval 7cf28d3d76 Have Makefile generate diff's for instruction tables as well 2020-07-21 20:10:14 -05:00
Amaan Cheval 96e64acdb8 Address feedback to clean Makefile up for including generated tables 2020-07-21 20:10:14 -05:00
Amaan Cheval 01e868a481 Add command-line switches to generate_{jit,interpreter}.js
In order of precedence:
--all generates all tables
--table jit{,0f_16,0f_32} / interpreter{,0f_16,0f_32}

And optionally:
--output-dir /path/to/output (defaults to v86 build directory)

This is in prep to let the make system generate individual tables as required
using this script instead of the script generating all 3.

Have output of generate table files use .c suffix

Remove write_sync_if_changed

The function existed to stop make from recompiling v86*.wasm everytime from
having the tables regenerated. With the upcoming change, this becomes unnecessary.

Correct Makefile to show dependency structure for generate scripts
2020-07-21 20:10:14 -05:00
Amaan Cheval e7cfc98922 "#include" generated instruction tables and update build process 2020-07-21 20:10:14 -05:00
Fabian fcfcc76034 Delete more JavaScript 2020-07-21 20:10:13 -05:00
Amaan Cheval 01f2d8f70f Simplify Makefile's mkdir 2020-07-21 20:10:13 -05:00
Amaan Cheval 12e6239d29 cov_data -> coverage_data in Makefile 2020-07-21 20:10:13 -05:00
Amaan Cheval 8b62c8c44d Improve name of coverage variable in Makefile 2020-07-21 20:10:13 -05:00
Amaan Cheval 91cc94e556 Coverage Reporter: Log raw JSON data for additional analyses as well 2020-07-21 20:10:13 -05:00
Amaan Cheval 538a2cb64c Major refactor for coverage logger
- Moved all helper functions to coverage.js
- Refactor individual cov_*[func_id] objects to coverage[func_id].*
- Write coverage data to its own directory (./build/coverage/coverage_data*)
- Enable/disable coverage logging in do_many_cycles to account for exceptions
- Better naming
- Minor stylistic refactoring
2020-07-21 20:10:13 -05:00
Amaan Cheval de01e6880d Allow compiling coverage-enabled v86-debug.wasm and covreport generation
Usage:
- make build/v86-debug.wasm ENABLE_COV=1 (assuming the file doesn't already
exist)
- make covreport
2020-07-21 20:10:13 -05:00
Fabian e6c8d8eabb Add clang-tidy 2020-07-21 20:10:13 -05:00
Fabian a7328f369c Make wget less verbose 2020-07-21 20:10:13 -05:00
Fabian fb1cb5e800 Run qemu tests in debug mode 2020-07-21 20:10:13 -05:00
Fabian d771b7bc7f Remove more unused JS 2020-07-21 20:10:13 -05:00
Awal Garg 8222d2e6e0 Squash
restore memcpy comment
delete all the things!
fix jshint issues
restore memcpy comment
remove duplicate fxsave assignment
Count cache drops
Use already available physical address instead of calling read_imm8
Remove useless assertion
Just move around to reduce later diff
Run jit paging test with assertions enabled
Run jit-paging test on CI
Extend jit-paging test
Fix deleting invalidated code across memory pages
Add jit-paging test to gitlab ci
Remove jit_in_progress
Clean up old comments, use bool for jit_jump
Fix state image not begin garbage collected
Add ENABLE_PROFILER_TIMES to configure slow profiling times
Move to jit_generate and jit_run_interpreted to separate function
Add missing struct field
Fix: Don't write jit cache entry until no more faults can happen
Download image for jit paging test
Add missing initialiser
Mark jit_{generate,run_interpreted} as static
Specify full path to profiler.h
Clean up duplicate/missing declaration after rebase
mmap error handling, line length and fix some warnings
remove further unused code
move js imports to single header file
2020-07-21 20:10:13 -05:00
Awal Garg c9a1db0666 cleanup makefile 2020-07-21 20:10:13 -05:00
Awal Garg 93926f0c31 enable separate compilation 2020-07-21 20:10:13 -05:00
Amaan Cheval 8354a1dafb Speed up NASM tests' fixture generation phase
The gen_fixtures.js currently generates fixtures for all
host_executables (*.bin) files, regardless of whether they need to be
regenerated or not.

The script speeds the process up by:

- Listing all files that need fixtures
- Finding nr_of_cpus (to parallelize execution)
- Dividing them up to roughly even "chunks" based on nr_of_cpus
- Spawning N gdb processes, which iteratively call a user-defined command named
  "extract-state" (see gdb-extract-def); the command automatically loads the new
  file and extracts its state into a fixture file

Rough benchmarks for 3725 tests:

Old method (after `rm build/*.fixture`):
make -j4  325.23s user 40.28s system 206% cpu 2:57.38 total
make -j4  342.65s user 43.73s system 289% cpu 2:13.23 total
make -j4  435.69s user 55.61s system 289% cpu 2:49.63 total

New method:
node gen_fixtures.js  11.85s user 4.86s system 140% cpu 11.890 total
node gen_fixtures.js  12.48s user 5.48s system 114% cpu 15.736 total
node gen_fixtures.js  14.54s user 6.33s system 141% cpu 14.769 total
2020-07-21 20:10:13 -05:00
Fabian cbb056726a Add profiling annotations 2020-07-21 20:10:13 -05:00
Fabian 171de68b98 Makefile: Create build directory if necessary 2020-07-21 20:10:13 -05:00
Fabian b8a7ca3a43 Temporarily disable separate compilation of codegen 2020-07-21 20:10:13 -05:00
Fabian 136fad7e01 Include capstone.js and libwabt.js for debugging 2020-07-21 20:10:13 -05:00
Fabian 02f75f476c Run kvm-unit-test in debug mode 2020-07-21 20:10:13 -05:00
Awal Garg 5f104e83da fix Makefile conflict 2020-07-21 20:10:13 -05:00
Awal Garg 85a67caaa7 nit fixes 2020-07-21 20:10:13 -05:00
Awal Garg ef1a6f0508 move jshint to .jshint.json 2020-07-21 20:10:13 -05:00
Awal Garg 51b6bc4e63 reenable separate compilation for codegen 2020-07-21 20:10:13 -05:00
Awal Garg 04f91d8935 codegen refactor 2020-07-21 20:10:13 -05:00
Awal Garg 243ffce941 add jshint to build 2020-07-21 20:10:13 -05:00