Commit graph

240 commits

Author SHA1 Message Date
Fabian ea50e29e5f Remove dead & improve 2020-12-31 19:14:29 -06:00
Fabian d0fb1a78d9 Experimental xterm.js support (#172, #227) 2020-12-31 19:14:29 -06:00
Fabian d5c9b29942 Upgrade jshint 2020-12-31 19:14:29 -06:00
Fabian 48a9847d16 s/oxide// 2020-12-31 19:14:29 -06:00
Fabian 1665e9b358 Fix instruction counter wrap-around 2020-12-31 19:14:29 -06:00
github-jane-doe 15ff296628
Typos (#371)
Fix typos
2020-10-04 19:46:41 +02:00
Fabian 47e91de601 Remove has_rand_int, always require get_rand_int to be available 2020-08-30 19:37:15 -05:00
Fabian 0e16983dd3 Handle case when wasm table is full (fixes #35)
Also fix jit_empty_cache when callbacks are pending (fixes #53)

This is also a preparation for setting WASM_TABLE_SIZE to a low value to
work around memory limitations in browsers.
2020-08-30 19:37:15 -05:00
Ernest Wong c928964562 Minor: Tidy quotes and spacing 2020-08-30 19:37:15 -05:00
Ernest Wong d6bfa143ed Filestorage: Don't rely on errors to select type of storage 2020-08-30 19:37:15 -05:00
Ernest Wong 83b283ebbe Filestorage: Replace the two server classes with a wrapper class
Simplifies both the filestorage.js code as well as the starter.js code
that uses these FileStorage classes.

Now, the ServerFileStorageWrapper decorates the other FileStorage
classes by loading from the server when the file is not available.

Moreover, the previous starter.js was incorrectly passing the `baseurl`
parameter (it was passing it when baseurl was not defined nor needed).
2020-08-30 19:37:15 -05:00
Ernest Wong c2dcb440dd Filestorage: Refactor fallback and load-from-server
Fallback logic is moved to the caller's responsibility.

Empty FileStorages and FileStorages that load from the server are
separated into different classes. This is to avoid faults where the
caller of the constructor forgets to pass in a `baseurl` parameter and
leads to some confusing bug.
2020-08-30 19:37:15 -05:00
Ernest Wong 6a06a7108a Tidy: file_storage snake case and interface naming convention 2020-08-30 19:37:15 -05:00
Amaan Cheval 1d5e0052b4 cpu: Port iret, iret16, iret32 to Rust 2020-08-30 19:37:15 -05:00
Amaan Cheval 8aa06b54e0 cpu: Port switch_cs_real_mode to Rust 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 f7c22266c9 initrd/bzimage detection: Ignore case 2020-08-30 19:37:14 -05:00
Fabian 028e131ddb Rename OnJSONLoaded & small refactor 2020-08-30 19:37:14 -05:00
Fabian aea2409b1d Ignore filesystem base when state image is provided 2020-08-30 19:37:14 -05:00
Fabian af0f153640 Refactor using new filesystem function 2020-08-30 19:37:14 -05:00
Fabian 3f79814e05 Detect initrd/bzimage in 9p filesystem and load before boot 2020-08-30 19:37:14 -05:00
Fabian e94c30ef6f Don't wrap text in SyncBuffer 2020-08-30 19:37:14 -05:00
Fabian e1c6116a0f Implement Linux kernel boot protocol, accept bzimage/initrd as boot configuration 2020-08-30 19:37:14 -05:00
Fabian 753fcb25c7 Simplify multiboot buffer during init 2020-08-30 19:37:14 -05:00
Fabian 7796d9dcb4 Clean up wasm loading, remove unused code for emscripten 2020-08-30 19:29:54 -05:00
Ernest Wong a0c984dc8d Filesystem: Introduce IndexedDBFileStorage
Uses MemoryFileStorage as a fallback when:
- v86 is used in a browserless environment, e.g. NodeJS
- browser doesn't support indexedDB
- opening indexedDB fails
- existing database is a newer version
- existing database is an old version and is under use - blocking
current v86 instance to connect to it.
2020-08-30 19:29:54 -05:00
Ernest Wong 0a67e3532f Filesystem: Introduce FileStorage class for server-loaded files 2020-08-30 19:29:54 -05:00
Ernest Wong 595d6dca55 Filesystem: Refactor inodedata accesses to async methods
The "// jshint ignore:line" comments are pretty messy, so squint your eyes.
They're systematically placed, so we can regex it out when jshint's
new version finally arrives.

Using async/await instead of callbacks due to callback hell, and it also
helps minimising the diff)
2020-08-30 19:29:54 -05:00
Amaan Cheval 0bf4e4faf6 cpu: Port get_tss_stack_addr to Rust 2020-08-30 19:29:54 -05:00
Amaan Cheval 3b94c5f9d3 cpu: Refactor to use error_code: Option<i32> for call_interrupt_vector 2020-08-30 19:29:54 -05:00
Amaan Cheval ae70cb7e4f cpu: Minor refactor in call_interrupt_vector 2020-08-30 19:29:54 -05:00
Amaan Cheval 4ef09445e1 cpu: Port call_interrupt_vector to Rust 2020-08-30 19:29:54 -05:00
Fabian 32699a3a7e Clear unused wasm modules earlier 2020-08-30 19:29:54 -05:00
Fabian 35cd746940 Delete dead code 2020-08-30 19:29:54 -05:00
Amaan Cheval 96ef38e901 cpu: Port popa{16,32} to Rust 2020-08-30 19:29:54 -05:00
Amaan Cheval 56ec3be5a4 cpu: Port update_cs_size to Rust
The JS version needs to stay too since it can be called by other JS-only functions.
2020-08-30 19:29:54 -05:00
Amaan Cheval 1712d25725 cpu: Port set_cr0 to Rust 2020-08-30 19:29:54 -05:00
Amaan Cheval b4922dc3b1 cpu: Port cpl_changed to Rust
We leave the JS version too, since it's used by several other JS functions
that we aren't porting yet.
2020-08-30 19:29:54 -05:00
Amaan Cheval 8e7061eff5 cpu: Port test_privileges_for_io to Rust 2020-08-30 19:29:54 -05:00
Amaan Cheval 880aa5e2d1 cpu: Port lookup_segment_selector and switch_seg to Rust
We'll keep the JS versions too, since the Rust and JS versions are incompatible, but both are needed
in their own respect.
2020-08-30 19:29:54 -05:00
Fabian fcdda9487e handle_irqs: Do interrupt flag check from Rust 2020-08-30 19:29:54 -05:00
Fabian 38a84342a2 Give Rust more indirect function slots and clean up the code 2020-08-30 19:29:54 -05:00
Fabian d9282afec5 Force logging of panic messages 2020-08-30 19:29:53 -05:00
Fabian 4b34beeb79 c2rust cleanup: Use Rust imports instead of linking 2020-08-30 19:29:53 -05:00
Fabian 67247ec907 (partially) fix variadic dbg_log 2020-08-30 19:29:53 -05:00
Fabian 952b8cf723 Quote for Closure Compiler and add missing functions for non-optimised builds 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
Ernest Wong e29e1ef9f4 Handle unexpected errors from fs.Mount and fix V86Starter error handling. 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 23080e2731 Isolate filesystem qid counting to each v86 instance 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 9e592dbd84 Decouple 9p and starter from fs's internal structure
Part of changes to support fs mounting on the host side.
Inode attributes are generally left untouched as field accesses.
2020-08-30 19:29:53 -05:00
Fabian ae241fac7b Replace todo() by undefined_instruction() 2020-08-30 19:29:53 -05:00
Fabian 5e82bc0e00 Remove use of cpu exceptions for trigger_ss (partially including switch_seg) 2020-08-30 19:29:53 -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
Awal Garg e33cc8f072 rust restructuring, some refactoring 2020-08-30 19:27:07 -05:00
Awal Garg ca2486391a remove unused bindings 2020-08-30 19:27:07 -05:00
Awal Garg eb322bcddf rename get_cs 2020-08-30 19:27:07 -05:00
Awal Garg 43832da920 remove unused binding 2020-08-30 19:27:07 -05:00
Awal Garg 7be3803590 add wg_ prefix to rust exports 2020-08-30 19:27:07 -05:00
Awal Garg 345f979287 use a sane number of pages in wasmgen memory 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
Awal Garg 6251730fee added wasmgen init changes 2020-08-30 19:27:07 -05:00
Fabian 9964040583 Register memory before calling constructor
As the constructor might call wasm code, which in turn uses memory to
pass strings
2020-08-30 19:27:07 -05:00
Fabian d374afb72e Add memcpy 2020-08-30 19:27:07 -05:00
Fabian 2e7e6d206a Delete old block linking infrastructure 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
Fabian c59da991b8 First load 9p filesystem, then restore 2020-08-30 19:27:02 -05:00
Fabian 0ac3829778 Add missing wasm imports: llvm_round_f64 and llvm_trunc_f64 2020-08-30 19:27:02 -05:00
Fabian 2fd4e50c93 Keep track of cached code entries per page
- Use this data structure to delete cached code immediately when page is
  written, not later when wasm index is reused
- Remove "dirty page" data structure
- Simplify cycle_internal, as no entries can be found dirty, they are
  removed immediately after being overwritten
2020-08-30 19:27:02 -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
Amaan Cheval 371ed40c82 log: Remove obsoleted dbg_log and dbg_assert imports 2020-07-21 20:10:14 -05:00
Amaan Cheval d79f084f1d memory/cpu: Have safe_write128 use write128 and mmap_write128
According to Fabian: safe_write128 is called suprisingly often as it is used by
Linux to fill the frame buffer. We can do two optimisations here: Add write128
to avoid one in_mapped_range check. Add mmap_write128 (taking 4 32-bit integers)
to avoid several switches from wasm to js and lookups of
memory_map_write32[aligned_addr]
(we can assume that writes don't cross a 16-byte boundary)
2020-07-21 20:10:14 -05:00
Fabian caf3a9e1f3 Implement asynchronous compilation of wasm modules
Add a callback after codegen_finalize to create entry. Mark entries as
pending while they compile
2020-07-21 20:10:14 -05:00
Fabian 7939cfb8a8 Simplify jit_generate and codegen_finalize
- Don't pass the old entry to jit_generate, instead look it up in
  create_cache_entry (negligible performance overhead)
- Don't call the generated code immediate, this is a pre-requisite for
  asynchronous compilation. This also required disabling the
  self-modifying code assertion
- Don't pass codegen_finalize the start address to codegen_finalize,
  instead set it in jit_generate
2020-07-21 20:10:14 -05:00
Fabian bdc6f53099 Port full_clear_tlb and invlpg to C, fix clear_tlb 2020-07-21 20:10:14 -05:00
Fabian f5938caa5a Link blocks for conditional jumps 2020-07-21 20:10:14 -05:00
Fabian 3cee397d0e Port jcxz, loop* to C 2020-07-21 20:10:13 -05:00
Fabian f53aba84b5 Linking compiled blocks 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 6c107abc28 Log uncompiled assembly 2020-07-21 20:10:13 -05:00
Fabian 69c27f1a44 Warn when initial_state is passed as state 2020-07-21 20:10:13 -05:00
Fabian 27b0ab71b1 Pass Date.now directly 2020-07-21 20:10:13 -05:00
Fabian fcfcc76034 Delete more JavaScript 2020-07-21 20:10:13 -05:00
Fabian f7bac07b10 Improve performance of microtick 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 1a7172feab Helper functions for logging coverage
Notes:

- The coverage_dump_loop doesn't really help much, but it helps keep the memory
usage a bit down for longer running tests (eg. booting Linux) - Linux still
slows down too much and can't callibrate its time to boot
- Dumping the incoming data without structuring by file results in very large
files (~150-300 mb for the nasm tests). Structuring by fn_id/fn_name slows
execution down, but allows for more manageable coverage data
- Buffering data in memory and writing to disk synchronously is faster / about
the same speed as async or buffering + async IO.
2020-07-21 20:10:13 -05:00
Fabian 1faec0e669 Remove math_pow, move declarations from shared.h to cpu.h 2020-07-21 20:10:13 -05:00
Fabian 5c2eb24832 Port writable_or_pagefault, do_page_translation and trigger_pagefault to C 2020-07-21 20:10:13 -05:00
Fabian 9ad9693cdd Port fpu to C 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
Fabian 5e21d68d83 Clean up 2020-07-21 20:10:13 -05:00
Fabian d410f567a7 Temp: Amaan's improvements 2020-07-21 20:10:13 -05:00
Fabian 2a2f898a2a Generate jit, integrated it with the code generator and main loop, and enable it 2020-07-21 20:10:13 -05:00
Fabian f3f6c7801b Improve failing assertion message from C 2020-07-21 20:10:13 -05:00
Amaan Cheval 7ed2fcaf4f Clear cached function from wasm Table when we know for sure an index is dirty 2020-07-21 20:10:13 -05:00
Amaan Cheval 6dfda6f4a8 Add helper jit_store_func
The function fetches a buffer from the code-gen, compiles it, and stores it into
the WASM Table at a specific index
2020-07-21 20:10:13 -05:00
Amaan Cheval b4f5e59d17 Remove Closure Compiler hack for wm.exports functions 2020-07-21 20:10:13 -05:00