Commit graph

370 commits

Author SHA1 Message Date
Fabian
ec846b34d9 Codegen for fpu instructions (misc instructions) (D9_[14], DB_5, DD_5, DF_4) 2020-08-30 19:37:15 -05:00
Fabian
1eab44746b Codegen for fpu instructions (fldcw/fstcw) (D9_5, D9_7) 2020-08-30 19:37:15 -05:00
Fabian
fdce557820 Codegen for fpu instructions (memory stores: fst/fstp/fist/fistp) (D9_[23], DB_[23], DD_[23], DF_[237]) 2020-08-30 19:37:15 -05:00
Fabian
7c99bdae74 Codegen for fpu instructions (memory loads: fld, fild) (D9_0, DB_0, DD_0, DF_5) 2020-08-30 19:37:15 -05:00
Fabian
c452c357dd Codegen for fpu instructions (DE group) 2020-08-30 19:37:15 -05:00
Fabian
21caefbffd Codegen for fpu instructions (DC group) 2020-08-30 19:37:15 -05:00
Fabian
ec059a9f27 Codegen for fpu instructions (D8 group) 2020-08-30 19:37:15 -05:00
Fabian
05296b0586 Enable fpu instructions in nasm tests 2020-08-30 19:37:15 -05:00
Fabian
38b8435c88 Print eip on bad instruction encodings 2020-08-30 19:37:15 -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
7e3f1ad401 gen_fn: Accept wasm builder, not jit context 2020-08-30 19:29:54 -05:00
Fabian
5eaece7743 jit memory moves with immediate address (A0/A1/A2/A3) 2020-08-30 19:29:54 -05:00
Fabian
8de547455e jit memory access for imul 2020-08-30 19:29:54 -05:00
Fabian
6a2cd6419d jit memory access for 8-bit read-modify-write operations with immediate 2020-08-30 19:29:54 -05:00
Fabian
2635ed71b4 jit memory access for 8-bit read-modify-write operations 2020-08-30 19:29:54 -05:00
Awal Garg
54151e2306 jit 0x0FBF 2020-08-30 19:29:54 -05:00
Awal Garg
0377e95c42 jit 0x0FB7 2020-08-30 19:29:54 -05:00
Fabian
98d69c0bef Mark unimplemented instructions as block boundaries 2020-08-30 19:29:54 -05:00
Fabian
46f9bc9d00 Remove non-faulting property of instructions (all instructions are non-faulting) 2020-08-30 19:29:54 -05:00
Fabian
d63c956a89 sse: Implement 0F5A/0F5B/CVTT?[SPD][SDQ]2[SPD][SDQ] (#57) 2020-08-30 19:29:54 -05:00
Fabian
8ab707dbc2 sse: Implement 0FE6/CVTPD2DQ/CVTTPD2DQ/CVTDQ2PD (#57) 2020-08-30 19:29:54 -05:00
Fabian
3ea0089878 sse: Implement 0F2C/0F2D/CVTT[PS][SD]2[SP]I (#57) 2020-08-30 19:29:54 -05:00
Fabian
9665dbf994 sse: Implement 0F2E/0F2F/u?comis[sd] (#57) 2020-08-30 19:29:54 -05:00
Fabian
8dc066f73d sse: Expand sse3 instruction 2020-08-30 19:29:54 -05:00
Fabian
cc507db69b sse: Implement 0FC6/shufp[sd] (#57) 2020-08-30 19:29:54 -05:00
Fabian
9e902eb1dc sse: Implement 0F52/rcpps (#57) 2020-08-30 19:29:54 -05:00
Fabian
5dd26ead30 Generate code for memory instructions (0F4*, 0F9*, 0FAF: cmovcc, setcc, imul) 2020-08-30 19:29:54 -05:00
Fabian
de01a4b265 Generate code for memory instructions (F6/F7/FF_{0,1}: test/inc/dec) 2020-08-30 19:29:54 -05:00
Fabian
fa50294b47 Generate code for read-modify-write instructions (C1/D1/D3: Shifts and rotates) 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
cfb9cd8abe Partial custom implementation for arithmethic instructions with read-memory 2020-08-30 19:29:54 -05:00
Fabian
9de2b926a7 Custom implementations for test instruction (only wrapper) 2020-08-30 19:29:54 -05:00
Fabian
9164e0a48f Custom implementation for 'mov r/m, imm' 2020-08-30 19:29:54 -05:00
Fabian
415e345e54 C6/C7 don't need to marked as block boundary 2020-08-30 19:29:54 -05:00
Fabian
b0eff6b951 Implement 8-bit memory accesses 2020-08-30 19:29:54 -05:00
Fabian
60d4a28e2c jit: Custom instructions can be block boundaries 2020-08-30 19:29:54 -05:00
Fabian
5727ed2ecb Interpreter detect same block boundaries as jit/analyzer 2020-08-30 19:29:53 -05:00
Fabian
c36a179a5e Remove block_boundary from push 2020-08-30 19:29:53 -05:00
Fabian
a5cbf53da5 Fix jit in presence of new page fault handling
Makes the following a block boundary:

- push
- Any non-custom instruction that uses modrm encoding
- Any sse/fpu instruction

This commit affects performance negatively. In order to fix this, the
above instructions need to be implemented using custom code generators
for the memory access.
2020-08-30 19:29:53 -05:00
Fabian
a88420910d Handle pagefaults without JS exceptions
This commit makes the return type of most basic memory access primitives
Result, where the Err(()) case means a page fault happened, the
instruction should be aborted and execution should continue at the page
fault handler.

The following primites have a Result return type: safe_{read,write}*,
translate_address_*, read_imm*, writable_or_pagefault, get_phys_eip,
modrm_resolve, push*, pop*.

Any instruction needs to handle the page fault cases and abort
execution appropriately. The return_on_pagefault! macro has been
provided to get the same behaviour as the previously used JS exceptions
(local to the function).

Calls from JavaScript abort on a pagefault, except for
writable_or_pagefault, which returns a boolean. JS needs to check
before calling any function that may pagefault.

This commit does not yet pervasively apply return_on_pagefault!, this
will be added in the next commit.

Jitted code does not yet properly handle the new form of page faults,
this will be added in a later commit.
2020-08-30 19:29:53 -05:00
Fabian
4255d6634a generate_interpreter: Remove useless imports 2020-08-30 19:29:53 -05:00
Fabian
01061dc4b6 The final Rust porting
This commit contains the final changes requires for porting all C code
to Rust and from emscripten to llvm:

- tools/wasm-patch-indirect-function-table.js: A script that rewrites
  the wasm generated by llvm to remove the table limit
- tools/rust-lld-wrapper: A wrapper around rust-lld that removes
  arguments forced by rustc that break compilation for us
- src/rust/cpu2/Makefile: A monstrosity to postprocess c2rust's output
- gen/generate_interpreter.js: Ported to produce Rust instead of C
- src/rust/*: A few functions and macros to connect the old Rust code
  and the new Rust code
- src/*.js: Removes the loading of the old emscripten wasm module and
  adapts imports and exports from emscripten to llvm
2020-08-30 19:29:53 -05:00
Fabian
33acb48fb9 Implement cvtsd2si (#57) 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
c10bbca85e Add sqrt{p,s}{d,s} 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
9eab018e1f Check unhandled sse prefixes at runtime 2020-08-30 19:29:53 -05:00
Fabian
9f2c78efb4 Add missing sse3 instruction and add note on others 2020-08-30 19:29:53 -05:00
Fabian
49961ade7c Remove hintable nops that were refitted for mpx instructions 2020-08-30 19:29:53 -05:00