Commit graph

532 commits

Author SHA1 Message Date
Fabian ff3945bab4 Don't skip Linux 4 bzImage test 2020-08-30 19:37:15 -05:00
Fabian 7a31922078 Add test for bzimage_initrd_from_filesystem 2020-08-30 19:37:15 -05:00
Fabian 92346f51ed Add test for clean shutdown 2020-08-30 19:37:15 -05:00
Fabian d2f86799e9 Simplify load_from_json: Accept json object directly, don't run asynchronously 2020-08-30 19:37:14 -05:00
Fabian 99a7bdd6e3 Fix error message when libv86-debug.js hasn't been built 2020-08-30 19:37:14 -05:00
Fabian ae4733a25e Integration test: Boot from bzimage 2020-08-30 19:37:14 -05:00
Fabian 028e131ddb Rename OnJSONLoaded & small refactor 2020-08-30 19:37:14 -05:00
Fabian 23a2ac9c44 Default to synchronous execution for nasm tests 2020-08-30 19:37:14 -05:00
Fabian 148be53525 Try fixing nasmtests hang for gdb 8.2 2020-08-30 19:37:14 -05:00
Fabian b83ed1b7c1 Minor 2020-08-30 19:29:54 -05:00
Fabian 0798a0b40e Don't create unnecessary entry points
This commit prevents creation of entry points for jumps within the same
page. In interpreted mode, execution is continued on these kinds of
jumps.

Since this prevents the old hotness detection from working efficiently,
hotness detection has also been changed to work based on instruction
counters, and is such more precise (longer basic blocks are compiled
earlier).

This also breaks the old detection loop safety mechanism and causes
Linux to sometimes loop forever on "calibrating delay loop", so
JIT_ALWAYS_USE_LOOP_SAFETY has been set to 1.
2020-08-30 19:29:54 -05:00
Fabian fc35ea3ee2 Add emms after code that uses mmx registers before code that uses fpu registers 2020-08-30 19:29:54 -05:00
Fabian fd1f8e1108 Test more edge cases for sse shifts 2020-08-30 19:29:54 -05:00
Fabian 76cc19dee4 Tests for sse shifts with 64 bit shift operand 2020-08-30 19:29:54 -05:00
Ernest Wong a23b4f969e Filesystem tests: Also use non-blocking flock -n 2020-08-30 19:29:54 -05:00
Ernest Wong 401b814f93 Filesystem: Store infinite lock lengths
Having both lock.length and lock.get_length() giving different values is
confusing.
2020-08-30 19:29:54 -05:00
Ernest Wong f7ee28d8ca Filesystem tests: Replace nlinks script with function
Simplifies the code, as well as to experiment to see why there are
processes being killed during only the hard links test and only on CI.
2020-08-30 19:29:54 -05:00
Ernest Wong 400ed64d54 Filesystem: Add tests for byte-range file locks 2020-08-30 19:29:54 -05:00
Ernest Wong e14ef4b8a9 Filesystem: Add tests for whole-file locks. 2020-08-30 19:29:54 -05:00
Fabian b70a5c081a Allow fast path for memory reads from pages that contain code 2020-08-30 19:29:54 -05:00
Ernest Wong 3773f0bfdf Filesystem tests: Increase memory size to 64MiB
OOM Killer was killing the processes.
2020-08-30 19:29:54 -05:00
Ernest Wong e5a689ac2d Filesystem: Expand tests for hard links
Verify multiple hardlinks and verify nlinks counter.
2020-08-30 19:29:54 -05:00
Ernest Wong c7dda46de1 Filesystem: Disallow hardlinks across filesystems
Although hardlinks across filesystems worked quite well in the current
implementation, we will run into problems when we try to implement
different backends for each sub-filesystem.

Note: EPERM is used instead of EXDEV since the mv command will silently
try to use copy-and-unlink when rename(2) fails with EXDEV.

The rules for linking has been reverted back:
 - Before commit: Any inode, including forwarders, could be linked as
long as the parent is not a forwarder and is a directory.
 - After commit: Only non-forwarders and root-forwarders are allowed to
be linked, and must be linked under a directory and not a forwarder.
2020-08-30 19:29:54 -05:00
Ernest Wong 00b9ad683a Filesystem tests: don't rely on inode.name 2020-08-30 19:29:54 -05:00
Ernest Wong d368ccf617 Add more tests for filesystem hardlinks 2020-08-30 19:29:54 -05:00
Fabian 295985e8e0 Remove code section: Only a single buffer is used for generating code 2020-08-30 19:29:54 -05:00
Fabian 1a3c491647 More tests for rep {movs,stos}{b,d} 2020-08-30 19:29:54 -05:00
Fabian 920d150c8b qemu: Enable all sse2 tests, add tests for approximate operations 2020-08-30 19:29:54 -05:00
Fabian 0a9c2bf6e2 qemu tests: init fpu before fxsave as fpu state contains undefined values from previous operations 2020-08-30 19:29:54 -05:00
Fabian 12eb838939 Expect tests: Catch libwabt errors and try to help 2020-08-30 19:29:54 -05:00
Fabian 3b1063d58a Expect tests: Accept TEST_NAME env variable 2020-08-30 19:29:54 -05:00
Fabian 3706bcac12 Use jit for read-modify-write arithmetic instructions 2020-08-30 19:29:54 -05:00
Fabian ca36680d52 PAGE_FAULT is u8 2020-08-30 19:29:54 -05:00
Fabian d4d7d236d5 Make all instructions non-faulting; handle faulting case in gen_safe_{read,write} (#44) 2020-08-30 19:29:54 -05:00
Fabian d67b91b895 Update expect tests 2020-08-30 19:29:53 -05:00
Fabian 1faf8ccc86 Allocate memory via Rust instead of ahead-of-time 2020-08-30 19:29:53 -05:00
Awal Garg 26fc44a61f simplify push16,32 2020-08-30 19:29:53 -05:00
Awal Garg bfc04b80fb jit E8 2020-08-30 19:29:53 -05:00
Awal Garg 73cbea7d0f call gen_pop{16,32} instead of using interpreted variants, update expect
tests
2020-08-30 19:29:53 -05:00
Fabian 28ac891dc3 Filesystem: Load files via their sha256 2020-08-30 19:29:53 -05:00
Ernest Wong 4a76c66ff3 Improve tests for fs.Rename across mounts
- Test both file and directory.
- Test combinations of forwarder/non-forwarder source/destinations
- Test different destination filenames
- Test empty file

Can't test early failure behaviour when destination can't be unlinked,
since right now only non-empty directories and root directories can't be
unlinked and busybox's mv program does not support mv
--no-target-directory.
2020-08-30 19:29:53 -05:00
Ernest Wong 0a4b6c8388 Add fs test for using .. across filesystems 2020-08-30 19:29:53 -05:00
Ernest Wong e683e812fd Mount only onto non-existent paths, existent parent
If mountpoint already exists, then we're silently making its children
inaccessible which may not be what we expected/intended.

Create a new forwarder inode upon mounting.
2020-08-30 19:29:53 -05:00
Ernest Wong 89592e8283 Use fs.RecursiveDelete before each fs test
Don't need to involve the guest os to delete everything.
2020-08-30 19:29:53 -05:00
Ernest Wong 1c6e5f2a51 Add failing tests for fs.SearchPath
Bugs in fs.SearchPath is causing problems with fs.Mount.
2020-08-30 19:29:53 -05:00
Ernest Wong 070c38c6a1 Add tests for host-side fs mounting
The testing "framework" code is slowly turning into spaghetti due to the
asynchronous nature of the triggers. Using async functions will help
clarify the program flow if we think we should address this issue.
2020-08-30 19:29:53 -05:00
Ernest Wong fa7ffd6ccc FS tests: include preparation steps in timeout
Stop hangs caused by faults during mounting and file loading
2020-08-30 19:29:53 -05:00
Ernest Wong d96a3373a6 FS tests: add enable-logs switch, simplify basefs option 2020-08-30 19:29:53 -05:00
Fabian 21018b880e Enable a few more sse tests 2020-08-30 19:29:53 -05:00
Fabian 6fa702c8aa Implement {min,max,div}{p,s}{s,d} sse instructions (#57) 2020-08-30 19:29:53 -05:00
Fabian 70ae4b720a Remove use of raising cpu exceptions for trigger_ud 2020-08-30 19:29:53 -05:00
Fabian 7e574dde52 Implement some floating point sse1/sse2 instructions (#57) 2020-08-30 19:29:53 -05:00
Fabian 384b7f3f73 Add more full tests and skip slow tests by default 2020-08-30 19:29:53 -05:00
Awal Garg 9b0fdc5019 Improve locals handling
Issuing of locals should only happen with set_new_local and
tee_new_local now
2020-08-30 19:29:53 -05:00
Awal Garg 7a14a010a8 Improve handling of locals and add tests
- adds alloc_local and free_local
- slightly better wasmgen tests
- caller of gen_safe_write32 is responsible for allocating
  and freeing locals for address and value
- updates expect-tests
2020-08-30 19:29:53 -05:00
Fabian 848b07a628 Skip tests that fail due to qemu bugs 2020-08-30 19:29:53 -05:00
Fabian 7d627ac13a Make tests a bit more robust 2020-08-30 19:29:53 -05:00
Fabian c108aaaadd Extend qemu paging tests with cross-page page faults 2020-08-30 19:29:53 -05:00
Fabian 510c6c186b qemu tests: More sse shift tests 2020-08-30 19:29:53 -05:00
Fabian 9bd1e30439 qemu tests: Re-enable some sse tests and reduce diff between upstream version 2020-08-30 19:29:53 -05:00
Fabian a7c25c423e nasmtests: Add timeout and clarify 2020-08-30 19:29:53 -05:00
Fabian 1ee5895c44 api test: Print error 2020-08-30 19:29:53 -05:00
Fabian f43ab3387a Remove use of cpu exceptions for trigger_gp for instructions 2020-08-30 19:29:53 -05:00
Fabian 4ee7da8f83 Remove use of cpu exceptions for divisions 2020-08-30 19:29:53 -05:00
Ernest Wong a538ba9960 Fix 9p caps test and add tests for xattr 2020-08-30 19:29:53 -05:00
Awal Garg b3e415cf9f jit inline 0xC3 2020-08-30 19:29:53 -05:00
Awal Garg 9224fc3878 jit inline 0xEB 2020-08-30 19:29:53 -05:00
Ernest Wong 5ec59fa019 Increase 9p tests' timeouts 2020-08-30 19:29:51 -05:00
Fabian 766c50b6fb Enable api tests 2020-08-30 19:29:13 -05:00
Fabian e0d3ebd6bc Test for atime of new files 2020-08-30 19:29:13 -05:00
Fabian 5df3b702ab Nasmtests: Fix gdb execution on docker 2020-08-30 19:29:13 -05:00
Fabian b74869dc67 Don't initialise loop counter when it's not used 2020-08-30 19:29:13 -05:00
Fabian 1253b72906 Generate prefix handling for string instructions 2020-08-30 19:29:13 -05:00
Fabian 3a8d644d75 Port jit to Rust
The following files and functions were ported:
- jit.c
- codegen.c
- _jit functions in instructions*.c and misc_instr.c
- generate_{analyzer,jit}.js (produces Rust code)
- jit_* from cpu.c

And the following data structures:
- hot_code_addresses
- wasm_table_index_free_list
- entry_points
- jit_cache_array
- page_first_jit_cache_entry

Other miscellaneous changes:
- Page is an abstract type
- Addresses, locals and bitflags are unsigned
- Make the number of entry points a growable type
- Avoid use of global state wherever possible
- Delete string packing
- Make CachedStateFlags abstract
- Make AnalysisType product type
- Make BasicBlockType product type
- Restore opcode assertion
- Set opt-level=2 in debug mode (for test performance)
- Delete JIT_ALWAYS instrumentation (now possible via api)
- Refactor generate_analyzer.js
- Refactor generate_jit.js
2020-08-30 19:29:13 -05:00
Ernest Wong 30a72e5874 Filesystem tests: include newlines in capture
- keep empty lines
- handle word wraps
- remove extra space in assert failure logging
2020-08-30 19:29:13 -05:00
Ernest Wong 72a4dc6448 Filesystem tests tidyup and ls --color=never 2020-08-30 19:29:13 -05:00
Ernest Wong 496e63f76e Add walk to filesystem stress test 2020-08-30 19:29:13 -05:00
Ernest Wong 8c6bfdb6da Minor improvements to filesystem tests 2020-08-30 19:29:13 -05:00
Ernest Wong 42d21bde56 Extend 9p tests to cover most file system calls 2020-08-30 19:29:02 -05:00
Fabian 3812cb5489 Update expect tests due to following of call instructions 2020-08-30 19:27:07 -05:00
Fabian 793c68a501 Update expect tests due to optimisation of memory writes 2020-08-30 19:27:07 -05:00
Fabian 8ac1e2a995 Update expect tests due to optimisation of loop iterations 2020-08-30 19:27:07 -05:00
Fabian f8dd22cf04 Expect test: Accept tests interactively (#15) 2020-08-30 19:27:07 -05:00
Fabian c06d141ea6 Run full tests in debug mode 2020-08-30 19:27:07 -05:00
Awal Garg f346fb2c7d increase freedos tests time limit to 20 seconds 2020-08-30 19:27:07 -05:00
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 863c020785 delete codegen test 2020-08-30 19:27:07 -05:00
Awal Garg fc7f4b468c add wasmgen tests to makefile 2020-08-30 19:27:07 -05:00
Fabian 94b0376186 Remove timing profiler 2020-08-30 19:27:07 -05:00
Fabian 0cc47d72d1 nasmtests: Catch general protection error / sigsegv 2020-08-30 19:27:07 -05:00
Fabian c898611196 Regression tests for 8-bit jumps 2020-08-30 19:27:07 -05:00
Fabian c40a5ccf25 nasmtests: Put multiboot section early into binary 2020-08-30 19:27:07 -05:00
Fabian 67af8f55e1 nasmtests: Allow running specific test by name 2020-08-30 19:27:07 -05:00
Fabian f10dd50be6 Full test: Verbose mode 2020-08-30 19:27:07 -05:00
Fabian 2fcbfdaf19 Full test: Add extra time for more stability 2020-08-30 19:27:07 -05:00
Fabian e9eeba2248 Remove deprecated use of new Buffer 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
Ernest Wong a75eb60e45 Use linux4 for virtio9p test + tidy up test logic 2020-08-30 19:27:07 -05:00
Ernest Wong 2bb5b194dc Fix virtio 9p tests
I wrongly assumed that libv86 would perform faster than libv86-debug.
Using libv86 caused ttyS0 to timeout before initialising, so there was
not serial terminal to use by the time debian booted.
2020-08-30 19:27:07 -05:00
Ernest Wong fe40ebc0f8 Add tests for virtio 9p (tests are currently incorrect)
These tests do not work yet: it fails to capture the serial output
after root login.

In addition, these tests are currently too slow to run
since it takes a while to boot the debian image (> 16 minutes on my
machine while running the test in the terminal.)

Would need to switch to a newer minimal linux image when available.
2020-08-30 19:27:07 -05:00
Fabian 4764d5b41e Set log level to zero (in case of running in debug mode) 2020-08-30 19:27:07 -05:00
Fabian 4423cf3010 Also test synchronous cdrom state saving/restoring (currently failing) 2020-08-30 19:27:07 -05:00
Fabian 617d962eba qemutests: More rounding tests 2020-08-30 19:27:07 -05:00
Fabian 7ba14bb47e Add debian-bytemark benchmark script 2020-08-30 19:27:07 -05:00
Amaan Cheval 3641bc3b87 codegen: Make SCALE_INDEX_FOR_ARRAY32 more specific and revert
This reverts commit b830fe8d7acb0f83c3c8a0febd7e172927ae2f46 and makes
the macro more specific
2020-08-30 19:27:07 -05:00
Amaan Cheval 96c095d381 codegen: Get rid of scale_by parameter and use log2(sizeof(arr[0])) 2020-08-30 19:27:07 -05:00
Amaan Cheval 80c9cdb9c1 codegen/gen_safe_write32: Use local-variable based arg passing
Stack based passing was needless given that we wanted the values in
local variables anyway and could simply have the caller do it.

We could have a minor optimization and have the caller gen_tee_local for
the address, but I chose not to do that because it seems like a minor
difference that complicates the calling convention
significantly (i.e. both set local variable and push to stack).
2020-08-30 19:27:07 -05:00
Amaan Cheval 7b259df48f cpu: Move tlb_data and page_first_jit_cache_entry to global_pointers
When they're stack-allocated, their addresses may change very easily,
even simply through updates in a header file that cpu.c includes.

This will make the expect-tests fail unnecessarily, simply because these
offsets changed.

In the future, we may change how memory handling works, so this may be a
non-issue then, but for now, it's easier to use a fixed offset for these
arrays.
2020-08-30 19:27:07 -05:00
Amaan Cheval 83e585c123 jit/instructions: Inline 0x89 "mov [mem], reg" for generated WASM 2020-08-30 19:27:07 -05:00
Amaan Cheval e3aab618af codegen: Update to 3 local scratch variables instead of 2 2020-08-30 19:27:07 -05:00
Amaan Cheval 1b8a856d7a codegen: Add missing mask for gen_safe_read32 2020-08-30 19:27:07 -05:00
Amaan Cheval c64c418b6f expect-tests: Split mov32 test into mov32-{reg,mem} files for readability 2020-08-30 19:27:07 -05:00
Amaan Cheval 5abcffd916 codegen: gen_store instead of gen_set_reg32_from_stack
The latter had more code to do the swap on the stack than to actually
store the value. Generating the store inline seems better.
2020-08-30 19:27:07 -05:00
Amaan Cheval c941a5e936 Minor: Fold expression at compile-time instead of generating code 2020-08-30 19:27:07 -05:00
Amaan Cheval 6b6dbcbad3 codegen: Fix assumption of aligned load from mem8
There is no guarantee that the load will actually be aligned, so we
ought to not assume it is.
2020-08-30 19:27:07 -05:00
Amaan Cheval 105b12ff98 codegen: Add memory offset parameters to aligned, unaligned loads
This way we don't need to generate the i32.add operations we had before
to access "arr[index_from_stack]" for eg.
2020-08-30 19:27:02 -05:00
Amaan Cheval db166cd703 jit/instructions: Inline 0x8b "mov reg, [mem]" for generated WASM 2020-08-30 19:27:02 -05:00
Amaan Cheval 8d55b34c5a codegen: Add 2 local scratch variables for easier inlining
WebAssembly has no "dup" operator (to duplicate the value on the top of
the stack), which means that if a value needs to be used twice, we need
to use a variable. We add 2 general-purpose local scratch variables to
this end.

Note: Users of the variable should be careful about interference with
other users - they may contain junk values, and between functions, the
state of a variable may well change.
2020-08-30 19:27:02 -05:00
Fabian 89a8b13b00 Add simple state test 2020-08-30 19:27:02 -05:00
Fabian 7201f9616d Delete unused stats 2020-08-30 19:27:02 -05:00
Fabian cba5491fc4 Multiple jit block entry points
- introduce multiple entry points per compiled wasm module, by passing
  the initial state to the generated function.
- continue analysing and compiling after instructions that change eip, but
  will eventually return to the next instruction, in particular CALLs
  (and generate an entry point for the following instruction)

This commit is incomplete in the sense that the container will crash
after some time of execution, as wasm table indices are never freed
2020-08-30 19:27:02 -05:00
Fabian ae2407a4dc Minor: Simplify and delete dead code 2020-08-30 19:27:02 -05:00
Fabian b2c46a9a67 Minor: Remove use of V86Starter 2020-08-30 19:27:02 -05:00
Amaan Cheval ccb9b6cbbf nasmtests: Re-enable 0x89 mem tests in mov16
The old method understandably triggered the 0x67 address-size override
prefix, which caused the segfault.

(Changed "mov [mem], ax" because that might use op 0xA3.)
2020-08-30 19:27:02 -05:00
Amaan Cheval 795ba8ad42 expect-tests: Improve error message and var name 2020-08-30 19:27:02 -05:00
Amaan Cheval 56e74baed0 nasmtests/jit: Regression test for mov16 (confirm 16-bit, not 32-bit)
This regression test will _NOT_ currently catch regressions in "make
nasmtests-force-jit" due to a pending issue where JIT execution doesn't
follow through the popf instruction, which this and most tests use
through header.inc.

To see the test actually fail, you need:
- To remove the popf instruction
- s/load_u16/load_i32/ in gen_set_reg16_r
2020-08-30 19:26:51 -05:00
Amaan Cheval 26dced841e expect-tests: Reduce is_32 sensitivity and warn about remaining tests 2020-07-21 20:10:14 -05:00
Amaan Cheval 81c09ef811 expect-tests: Write out raw wasm file too
This makes it easier to test the generated output with different
tools too, such as wasm-objdump, for eg.
2020-07-21 20:10:14 -05:00
Amaan Cheval 3b1d3ae91e expect-tests: Add mov16/mov32 fixtures for JIT
These tests confirm that the generated WAST:

1. Optimizes "mov reg, reg" with direct memory access stores, requiring
no function calls

2. Memory loads/stores use the correct data-width (i32.load16_u for
reg16, etc.)
2020-07-21 20:10:14 -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 5886077633 Minor cleanup 2020-07-21 20:10:14 -05:00
Fabian 73614108b7 Clarify that expect test uses flat binaries 2020-07-21 20:10:14 -05:00
Fabian 03a1351163 expect tests: Force creation of build dir before build 2020-07-21 20:10:14 -05:00
Fabian e6af9f3d7f Expect tests 2020-07-21 20:10:14 -05:00
Fabian 37f4a7da51 Make unhandled rejected promises fatal in tests 2020-07-21 20:10:14 -05:00
Fabian 30bb5e6968 Fix codegen tests 2020-07-21 20:10:14 -05:00
Fabian f7d7327753 qemu tests: Dump version 2020-07-21 20:10:14 -05:00
Amaan Cheval f6cceafac1 qemutests: Fix bug where test would hang forever sometimes
The stdout stream is not line-buffered, which means that occasionally the
chunk/Buffer of data that comes in immediately after we run the commands may be:

~% chmod +x /mnt/test-i386
~% /mnt/test-i386 > /mnt/result
~% echo test fini''shed
test finished
~%

Note how the data ends with the prompt, not in "test finished\n" - this will
cause the test to run indefinitely.
2020-07-21 20:10:14 -05:00
Amaan Cheval eb21d0203e style: Remove single quotes from ./tests/nasm/ 2020-07-21 20:10:14 -05:00
Amaan Cheval 52474abe58 test: Have integration test read from urandom to trigger JIT 2020-07-21 20:10:14 -05:00
Awal Garg 54a43ab437 improve segment prefix handling and custom code generation for lea 2020-07-21 20:10:14 -05:00
Fabian acfc4372c5 Use Westmere instead of max cpu for qemu (max is not available on older qemu versions) 2020-07-21 20:10:14 -05:00
Fabian 3cfce44363 Nasm: Jump tests 2020-07-21 20:10:14 -05:00
Fabian 0c2113d28c nasm: pop esp test 2020-07-21 20:10:14 -05:00
Fabian e0dc847ded Re-enable TEST_VM86 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
Fabian f03b34ecd5 Handle missing modify_ldt syscall in qemu tests properly 2020-07-21 20:10:14 -05:00
Amaan Cheval b1787e5a0f Clean up push nasm test 2020-07-21 20:10:14 -05:00
Amaan Cheval b2e44e2340 NASM test for push [reg, r/m, imm] and pop reg are all tested
With ENABLE_JIT_ALWAYS set, it effectively tests all variants (is_32 +
imm/reg/rm) of the instruction.

Stack size variation should also be tested in the future.

See WASM dump for optimized versions here:

https://gist.github.com/AmaanC/c5c5f9d76bef589a7fbb0f4af3b15e64
2020-07-21 20:10:14 -05:00
Awal Garg cfad35612f add SYNC_GDB_EXECUTION flag 2020-07-21 20:10:14 -05:00
Amaan Cheval c3fa48e3fc Track stats for how many times the nonfaulting optimization is applied 2020-07-21 20:10:14 -05:00
Amaan Cheval 5c690d9de9 Update comment and fix line length 2020-07-21 20:10:14 -05:00
Amaan Cheval 158a697d67 s/scratch/instruction_body/ 2020-07-21 20:10:13 -05:00
Amaan Cheval 99098cc4df Remove _scratch from codegen function names.
This reverts parts of commit d779df89714ef784a1f0ebb264ed5b9fe8727fb1.
2020-07-21 20:10:13 -05:00
Amaan Cheval dbf0b7fa20 Add scratch buffer to codegen and refactor functions to indicate it
Since we can only know an instruction's length (and other characteristics) after
its been decoded, this change allows us to first decode the instruction and
generate the instruction function calls to a scratch buffer, which can then be
copied over to the main (cs) buffer as appropriate.

Tests for the scratch buffer were added too.
2020-07-21 20:10:13 -05:00
Fabian 86b8ac7b72 Add linux booting benchmark 2020-07-21 20:10:13 -05:00
Fabian 3e99913474 Catch signals in gdb instead of relying on the default printing 2020-07-21 20:10:13 -05:00
Fabian 26bb7c2caa Allocate more space for codegen buffers 2020-07-21 20:10:13 -05:00
Fabian a007fb690e Log fixture test when test was killed during execution 2020-07-21 20:10:13 -05:00
Fabian 87e1150acd Trailing comma 2020-07-21 20:10:13 -05:00
Amaan Cheval d505d7b936 Make JIT paging tests' mmap calls more robust (no SEGFAULT and better physical map)
1. SEGFAULTs may be caused by using MAP_FIXED - it may override an existing
mapping, which may exist for internal implementation helpers.

2. The Linux3 profile seems to allocate physical frames in the order in which
writes to memory mapped virtual addresses happen.

For this commit, for eg:

page0;     virtual=0xB7766000 physical=0x12C9000
throwaway; virtual=0xB7765000 physical=0x12C8000
page1;     virtual=0xB7767000 physical=0x12CC000

This way we can write from page0 -> page1's virtual addresses and make sure our
paging support works as it should, and that the tests aren't simply passing
because even the underlying physical frames are contiguous.
2020-07-21 20:10:13 -05:00
Amaan Cheval 89d80a5e3e Allocate enough space in page0 so that page1 can also fit
Without this, the MAP_FIXED call for page1 may cause a segfault by overwriting
an internally mapped structure.
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 413468f0bb Make sure total_blocks is parsed as a number 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 6362afa4c1 Minor cleanup for cov-report 2020-07-21 20:10:13 -05:00
Amaan Cheval bb5c84973e Add coverage-reporter
It looks for files in ./build/cov_data_fn_name_XX where XX=number of conditional
blocks in fn_name, and parses the binary data contained within to find which
blocks are missing.

Reports are generated in ./tests/coverage/build/report_XX where XX is
incremented to allow us to see how the coverage changes over time.

Note:

- The cov_data_* generated needs to be manually deleted if we want to compare 2
  individual coverage runs.
- We currently ignore the 0th block (LLVM marks it as visited when a function is
  entered).
2020-07-21 20:10:13 -05:00
Amaan Cheval 9c301f45e7 Improve NASM test error message marginally 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 a0f5074f18 Temporarily disable segment test in qemu 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 f92ab52b38 fix view in codegen test 2020-07-21 20:10:13 -05:00
Awal Garg 318f595aa2 fix codegen test addresses 2020-07-21 20:10:13 -05:00
Amaan Cheval c780862cf5 Remove outdated docs and gdbauto script 2020-07-21 20:10:13 -05:00
Amaan Cheval c7a9a49050 NASM: Move shared breakpoint out gdb definition script
This lets the gdb script be more standalone and have fewer side-effects.
2020-07-21 20:10:13 -05:00
Amaan Cheval 56bc2e3dd9 Have gen_fixtures.js use mtime to generate fixtures only when needed 2020-07-21 20:10:13 -05:00
Amaan Cheval f7a39f901d Use path.join instead of manually concatenating paths 2020-07-21 20:10:13 -05:00
Amaan Cheval 13ce0f8ecb Variable refactor: snake-case and scope updates 2020-07-21 20:10:13 -05:00
Amaan Cheval 0d46574719 Remove chunk's default parameter and replace comment with test 2020-07-21 20:10:13 -05:00
Amaan Cheval ac83adc872 Remove DEBUG_FILE_LIMIT parameter
It was used to limit the number of files that the script processes manually, but
it doesn't really need to be checked in.
2020-07-21 20:10:13 -05:00
Amaan Cheval 8a413b621d Fix indentation of end of user-defined gdb command extract-state 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
Amaan Cheval a3420c5f32 Fix manual pcmpeqb nasm test
It mistakenly tested the pand instruction earlier.
2020-07-21 20:10:13 -05:00
Fabian a1358bd082 Fix codegen test 2020-07-21 20:10:13 -05:00
Fabian 0c34310c99 Codegen changes for jit 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 16bbb73bef fix codegen test 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 7997defdfb add codegen-test to CI 2020-07-21 20:10:13 -05:00
Amaan Cheval 6802f6ab5f Update maskmovq test to use "test memory" the same way as maskmovdqu 2020-07-21 20:10:12 -05:00
Amaan Cheval fef1b05f35 Add XMM based manual tests for SSE shift instructions 2020-07-21 20:10:12 -05:00
Amaan Cheval 2ad796c85a Add NASM test for maskmovdqu xmm, xmm 2020-07-21 20:10:12 -05:00
Amaan Cheval f8b22d1b79 Add NASM test for maskmovq mm, mm 2020-07-21 20:10:12 -05:00
Fabian 58e4c6df72 Add some more operating systems to the full test suite 2020-07-21 20:10:12 -05:00
Awal Garg 705f59773a add modrm tests 2020-07-21 20:10:12 -05:00
Awal Garg c244eace01 use load_wasm from browser/lib.js 2020-07-21 20:10:12 -05:00
Awal Garg db5e31600b fix nits 2020-07-21 20:10:12 -05:00
Fabian 975a06269e Squash
2e469796 Minor
fab422ef Improve generation of 0f instructions
08ad7fe9 Improved if-else generation
3f81014d Minor: Align test output
4a3a84ef Generate modrm tests
61aa1875 Simplify
a6e47954 Generate decoding of immediate operands
435b2c10 Fix warnings
e4933042 Add missing immediate operand
3f3810c7 Generate immediate operands for instructions with modrm byte
a0aa7b1f Make memory layout in nasm tests clearer
6b8ef212 Remove 'g' property from instruction table (implied by 'e')
bf15c58c Remove unused declarations
1e543035 Remove useless `| 0` and `>>> 0` javascriptisms
1ccc5d53 Fix headers
8b40c532 Update qemu tests with changes from qemu
ec9b0fb5 Port xchg instructions to C
c73613e7 Port virt_boundary_* to C
d61d1241 Add headers
fd19f22c Make written value in write8 and write16 int32_t
497dcaec Generate read_imm for instructions with a modrm byte
8b7003d6 Generate read_imm8s
0cc75498 Remove read_op
9d716086 Trigger unimplemented_sse for partial sse instructions with prefix
8d5edd03 Remove unimplmented sse c-to-js hack
585d3565 Remove | 0
308124b2 Use int32_t as return value
f193f8e1 Use JS version of cvttsd2si for now
12747b97 Generate trigger_ud for missing modrm branches
770f674e Split 0f00 and 0f01 into multiple instructions depending on modrm bits
1cb372a3 Generate decoder for some 0f-prefix instructions
cec7bc63 Disable unused parameter warnings in instruction functions
807665b1 Generate read_imm for 0f/jmpcc
cdf6eccc Generate modrm decoding for shld
04528429 Create temporary files in /tmp/, not cwd
d8f3fbd8 Generate modrm/imm decoding for shld
00ef0942 Generate modrm decoding for bts
f531984b Generate modrm decoding for shrd and imul
07569c53 Generate modrm decoding cmpxchg
535ff190 Generate modrm decoding for lfs/lgs/lss
2f8ced8d Generate modrm decoding for btr and btc
95de6c66 Generate modrm decoding for movzx
c4d07e7e Generate modrm decoding for bsf and bsr
f0985d26 Generate modrm decoding for movsx
4b30937a Generate modrm decoding for xadd
a422eb27 Generate modrm decoding for movnti
e5501d3c Generate modrm decoding for mov to/from control/debug registers
bce11ec5 Generate modrm decoding for lar/lsl
5729a23c Fix access to DR4 and DR5 when cr4.DE is clear
44269a81 Specify immediate size explicitly instead of inferring it
82b2867a Fix STR instruction
98a9cc89 Log failing assertion
6d2f9964 Fix rdtsc
00260694 Log GP exceptions
7916883d Port trigger_ud and trigger_nm to C
36fedae9 Remove unused code
e08fabd0 Generate modrm decoding for 0f00 and 0f01
8ae8174d Generate modrm decoding for 0fae and 0fc7 (fxsave, cmpxchg8, etc.)
26168164 Generate modrm+immediate decoding for 0fba (bit test with immediate operand)
6adf7fa7 Simplify create_tests.js (unused prefix call)
c77cbdd8 Add comments about the implementation of pop [addr]
4640b4fe Simplify prefix call
a81a5497 Don't use var
3ca5d13d Separate call name and arguments in code generator
3191a543 Simplify other prefix call (8D/lea)
5185080e Update generated code (stylistic changes and #ud generation)
93b51d41 Remove unused wasm externals
e4af0a7f Avoid hardcoding special cases in code generator (lea, pop r/m)
654a2b49 Avoid hardcoding special cases in code generator (enter/jumpf/callf)
fd1a1e86 Commit generated code (only stylistic changes)
7310fd1a Simplify code generator by merging code for with and without 0f prefix
e7eae4af Simplify code generator by merging code for immediate operands
00fafd8a Improve assertions
db084e49 Simplify code generator (modrm if-else)
0a0e4c9e Improve code generation of switch-case
ce292795 Clarify some comments
37cf33fa Generate code in if/else blocks
cbcc33fc Document naming scheme
e30b97eb Generate modrm decoding for 0f12 (sse) instruction
24b72c2f movlpd cannot be used for register-to-register moves
72d72995 Generate modrm decoding for 0f13 (sse) instruction and disable register-to-register moving
75d76fbb Generate modrm decoding for 0f14 (sse) instruction
ac8965a7 Generate modrm decoding for 0f28-0f2b (movap, movntp)
e919d33e Generate modrm decoding for cvttsd2si
5f2ca2b4 Generate modrm decoding for andp and xorp
c8d1c6de Generate modrm decoding for 0f60-0f70 (sse instructions)
ae4ed46d Add multi-byte nop and prefetch to nasm test, generate modrm decoding
718a1acf Print qemu test error message more useful
d1ecc37e Generate modrm decoding for 0f70-0f80 (sse instructions)
6a7219a5 Generate modrm decoding for popcnt
25278217 Generate modrm decoding for 0f71-0f73 (sse shift with immediate byte)
ed1ec81b Generate modrm decoding for the remaining sse instructions (0fc0-0fff)
42bc5a6f Use 64-bit multiplication for native code
dda3fb39 Remove old modrm-decoding functions
717975ef Move register access functions to cpu.c
aee8138f Remove read_op, read_sib, read_op0F, read_disp
f31317f2 Rename xmm/mmx register access functions
a525e70b Remove 32-bit access to reg_xmm and reg_mmx
c803eabc Rename s8/s16/s32 to i8/i16/i32
9fbd2ddf Don't use uninitialised structs
942eb4f7 Use 64-bit load for mmx registers and assert reg64 and reg128 size
f94ec612 Use 64-bit writes for write_xmm64
08022de9 Use more efficient method for some 128-bit stores
9d5b084c Make timestamp counter unsigned
2ef388b3 Pass 64-bit value to safe_write64
4cb2b1be Optimise safe_write64 and safe_write128
b0ab09fb Implement psllq (660ff3)
9935e5d4 Optimise safe_read64s and safe_read128s
af9ea1cc Log cl in cpuid only if relevant
be5fe23e Add multi-op cache (disabled by default through ENABLE_JIT macro) and JIT paging test (similar to QEMU test).
aa2f286e Don't initialise group_dirtiness with 1 as it increases the binary size significantly
b8e14ed9 Remove unused reg_xmm32s
bc726e03 Implement dbg_log for native code with format characters 'd' and 'x'
454039d6 Fix store task register
63a4b349 Remove unnecessary parens and clean up some log statements
4cc96814 Add logop and dbg_trace imports
7940655d Only inhibit interrupts if the interrupt flag was 0 in STI
876c68a7 Split create_tests into create_tests and generate_interpreter
aa82499f Move detection of string instructions to x86_table
f3840ec2 Move C ast to separate file
90400703 Skip tests for lfence/mfence/sfence, clarify their encoding
4a9d8204 elf: Hide log messages when log level is zero
a601c526 Allow setting log level via settings
8a624453 Add cpu_exception_hook to debug builds
f9e335bf Nasm: Test exceptions
599ad088 logop: Format instruction pointer as unsigned
f95cf22b Don't skip zero dividing tests
2a655a0e Remove get_seg_prefix_ds from read_moffs (preparation for calling read_moffs from the code generator)
bc580b71 Remove obsolete comment
e556cee0 Fix nasmtest dependencies in makefile and clean
dcb1e72b Use all cores on travis
86efa737 Replace all instances of u32 & 0xFFFF with the respective u16 accesses
98b9f439 Use u8 instead of bit-shifts and masks from u32
b43f6569 Replace all instances of u32 >> 16 with the respective u16 accesses
9bfa72c7 Remove unnecessary parens
9cf93734 Clean up remaining instance of u32 with a mask instead of u16
22d4117f Correct order of writes in virt_boundary_write32
6734c7c1 Fix keyboard on ios, fixes #105
858a4506 Add missing file, c_ast.js
1d62e39e Move instruction naming scheme into function
f4816852 Reorder some code
69d49788 Minor improvements
0493e05f Add util.js
af9000c1 Improve full test
e5feba31 Add missing export
c7c42065 Replace prefix_call with custom_resolve_modrm
3186e6ad Add support for "%%" format string to dbg_log_wasm for printf import
efe54fad Add barebones instrumentation profiler (disabled by default).
c9f0d462 Implement movlps m64, xmm and enable its test
42869a12 Add tests for cross-page reads/writes confirmed with byte reads/writes
d68976ea Mask word values in port byte reads
9758d51e Add PS2_LOG_VERBOSE
5f52f037 Update NASM Makefile to include all dependencies to prevent unnecessary recompilation
2c71f927 Have NASM test generator use a seedable PRNG to allow for faster incremental tests
e4aa45bb Add chunk{16,32}_rw paging tests; instructions that read and write to memory
bdf538a2 add codegen to cpu constructor
aa76ce8e add resolve_modrm16
14d7ecf1 refactor codegen
b710319f [rebased] Merge branch codegen
0565ea42 minor refactoring
071dff3f temporary fix for automatic cast warnings
57c504f2 fix modrm16 issue
c2db5d9e jit modrm32
85c04245 reinstate modrm_fn0 and modrm_fn1
be65dafd add ip and previous ip manipulating functions
ae00ef89 update codegen js interface
530a74fa squashed commit for refactor
2c692199 add codegen-test to build
c15afe68 prefix gen to codegen api
c9611533 codegen tests fixes
2020-07-21 20:10:12 -05:00
Amaan Cheval 966f61616c Minor refactor based on feedback 2020-07-21 20:10:12 -05:00