Commit graph

444 commits

Author SHA1 Message Date
Andreas Kling
c4ec38ddb5 UserspaceEmulator: Print out the current EIP as we execute instructions 2020-07-11 16:48:27 +02:00
Andreas Kling
ae1d14bc7a UserspaceEmulator: Load the target executable ELF semi-properly :^)
This patch adds a basic ELF program loader to the UserspaceEmulator and
creates MMU regions for each PT_LOAD header. (Note that we don't yet
respect the R/W/X flags etc.)

We also turn the SoftCPU into an X86::InstructionStream and give it an
EIP register so we can actually execute code by fetching memory through
our MMU abstraction.
2020-07-11 16:45:48 +02:00
Andreas Kling
0eab5659f8 UserspaceEmulator: Set up a very basic program entry stack 2020-07-11 16:30:17 +02:00
Andreas Kling
76b9fb258d UserspaceEmulator: Convert the XOR instruction to inline assembly 2020-07-11 16:02:25 +02:00
Andreas Kling
9db588daf1 UserspaceEmulator: Convert the SUB instruction to inline assembly 2020-07-11 15:52:53 +02:00
Andreas Kling
7d41b95071 UserspaceEmulator: Tweak INC and SAR helpers to not be SoftCPU members
It's quite nice having these as compartmentalized free functions.
2020-07-11 15:47:53 +02:00
Andreas Kling
e852768ba6 UserspaceEmulator: Add the INC and ADD instructions
More inline assembly. I'm still figuring out how to combine templates
and inline assembly, but it's turning out pretty cool. :^)
2020-07-11 14:20:08 +02:00
Andreas Kling
12ab46def9 UserspaceEmulator: Give SoftCPU an API for evaluating jump conditions
There are 16 conditions and they're all based on a combination of the
CPU flags.
2020-07-11 13:45:39 +02:00
Andreas Kling
133803b8a7 UserspaceEmulator: Split SAR inline assembly into 8/16/32 bit variants 2020-07-11 13:43:27 +02:00
Andreas Kling
743d4ccb8f UserspaceEmulator: Support MOV_RM32_reg32 with memory destination 2020-07-11 13:29:05 +02:00
Andreas Kling
e5afe6a579 UserspaceEmulator: Implement the CMP family of instructions
These are identical to SUB, except they don't store the result (they
only upate the arithmetic flags.)
2020-07-11 13:27:40 +02:00
Andreas Kling
f4ddca0a73 UserspaceEmulator: Warn in SoftMMU if accessing unknown memory 2020-07-10 20:29:44 +02:00
Andreas Kling
58fd010caf UserspaceEmulator: Implement a bunch of the MOV instructions 2020-07-10 20:29:14 +02:00
Andreas Kling
04d58f54b3 UserspaceEmulator: Implement the SAR instruction
Let's try doing this with some inline assembly. We know we're running
on an x86 target anyway. :^)
2020-07-10 20:20:27 +02:00
Andreas Kling
3899effb19 UserspaceEmulator: Implement the SUB family of instructions 2020-07-10 20:20:27 +02:00
Andreas Kling
0cf7fd5268 UserspaceEmulator+LibX86: Implement all the forms of XOR
And they're all generic, which will make it easy to support more ops.
2020-07-10 20:20:27 +02:00
Andreas Kling
9955819d92 UserspaceEmulator: Better 8/16 bit GPR accessors 2020-07-10 20:20:27 +02:00
Andreas Kling
6f27770cea UserspaceEmulator: Add 8/16 bit memory read/write operations 2020-07-10 20:20:27 +02:00
Andreas Kling
f8b38eabeb UserspaceEmulator: First cut of generic instruction implementations
Let's use C++ templates to implement the generic parts of instructions.
There are tons of them with the same set of inputs, just different
behavior. Templates are perfect for this.
2020-07-10 20:20:27 +02:00
Andreas Kling
30ef30ca09 UserspaceEmulator: Add proper segment registers
Some things will flow better if we're able to index into a table of our
segment registers.
2020-07-10 20:20:27 +02:00
Andreas Kling
4f41fada39 UserspaceEmulator: Add accessors for the 16-bit GPRs 2020-07-10 20:20:27 +02:00
Andreas Kling
f1801cfb28 UserspaceEmulator: Fix a Clang warning
Clang didn't like default construction of PartAddressableRegister,
so let's just use memset() then.
2020-07-10 20:20:27 +02:00
Andreas Kling
4d8683b632 UserspaceEmulator: Tidy up SoftCPU's general purpose registers
This patch adds a PartAddressableRegister type, which divides a 32-bit
value into separate parts needed for the EAX/AX/AL/AH register splits.

Clean up the code around register access to make it a little less
cumbersome to use.
2020-07-09 23:27:50 +02:00
Andreas Kling
d10765bec3 UserspaceEmulator: Add an initial stack and implement PUSH/POP reg32
Programs now start out with a 64 KB stack at 0x10000000. :^)
2020-07-09 16:20:08 +02:00
Andreas Kling
d5c46cf528 UserspaceEmulator: Start sketching out a SoftMMU class :^)
This Emulator sub-object will keep track of all active memory regions
and handle memory read/write operations from the CPU.

A memory region is currently represented by a virtual Region object
that can implement arbitrary behavior by overriding read/write ops.
2020-07-09 16:18:47 +02:00
Andreas Kling
3a73fdd244 UserspaceEmulator: Start executing in _start() instead of main()
This is one step closer to the real thing. :^)
2020-07-09 15:47:10 +02:00
Andreas Kling
8ab601f9e1 UserspaceEmulator: Implement XOR_RM32_reg32
Note that this is a partial implementation since we don't have support
for memory r/m variants yet.
2020-07-07 22:44:58 +02:00
Andreas Kling
934f0b999e UserspaceEmulator: Add arithmetic CPU flags 2020-07-07 22:44:58 +02:00
Andreas Kling
d0dbf92c8d UserspaceEmulator: Break out of emulation when hitting a RET
Until we learn more instructions, we'll have to exit somewhere, so let
us exit when we hit a RET instruction for now.
2020-07-07 22:44:58 +02:00
Andreas Kling
8d8bb07476 UserspaceEmulator: Start building a userspace X86 emulator :^)
This introduces a new X86 CPU emulator for running SerenityOS userspace
programs in a virtualized interpreter environment.

The main goal is to be able to instrument memory accesses and catch
interesting bugs that are very hard to find otherwise. But before we
can do fancy things like that, we have to build a competent emulator
able to actually run programs.

This initial version is able to run a very small program that makes
some tiny syscalls, but nothing more.
2020-07-07 22:44:58 +02:00
Andreas Kling
bc1ec588f0 TextEditor: Tweak 16x16 icon
In keeping with the slightly-higher-contrast theme.
2020-07-04 19:44:27 +02:00
Andreas Kling
14edd67bcc Profiler: Use SortingProxyModel::set_sort_role()
Use the new API to avoid duplicating code in the RunningProcessesModel.
2020-07-04 19:22:30 +02:00
Andreas Kling
ca93c22ae2 LibGUI: Turn GUI::Application::the() into a pointer
During app teardown, the Application object may be destroyed before
something else, and so having Application::the() return a reference was
obscuring the truth about its lifetime.

This patch makes the API more honest by returning a pointer. While
this makes call sites look a bit more sketchy, do note that the global
Application pointer only becomes null during app teardown.
2020-07-04 16:54:55 +02:00
Andreas Kling
1dd1595043 LibGUI: Make GUI::Application a Core::Object
Having this on the stack makes whole-program teardown iffy. Turning it
into a Core::Object allows anyone who needs it to extends its lifetime.
2020-07-04 14:05:57 +02:00
Andreas Kling
e7393bfb7b Profiler: Turn the "choose a process" functionality into a GUI::Dialog
This feels a bit nicer and make it possible to reuse this in other
places as well. :^)
2020-07-02 20:46:59 +02:00
Andreas Kling
f5d920eb2e Profiler: Make the RunningProcessesModel actually sortable
GUI::TableView looks at data(Model::Role::Sort) to know which order
things should be in.
2020-07-02 07:35:11 +02:00
Andreas Kling
d4c92bd1b7 Profiler: Allow specifying a PID to profile with --pid 2020-07-01 21:07:53 +02:00
Andreas Kling
8d52e200ee Profiler: If run without arguments, let user select process from a list
We now show a list of running processes that the user can choose from.
After choosing one, we start profiling it and show a timer with a stop
button that the user has to press to stop profiling.
2020-07-01 20:49:51 +02:00
Andreas Kling
8661af9b72 Profiler: Rename from ProfileViewer :^) 2020-07-01 19:43:17 +02:00
AnotherTest
7b72001667 Inspector: Expand and show properties in a TreeView
This allows the inspector to show arbitrary json structures.
2020-07-01 11:18:19 +02:00
Nico Weber
12cbc4ad0d Everywhere: Replace some uses of fork/exec with posix_spawn
It's less code, and it's potentially more efficient once
posix_spawn is a real syscall.
2020-06-29 12:04:27 +02:00
Andreas Kling
2ba9e9b9c9 HackStudio: Use Web::PageView::load_html() for the documentation popup
Also simplify the way we change the background color a little bit.
2020-06-21 21:54:30 +02:00
Matthew Olsson
e8e728454c AK: JsonParser improvements
- Parsing invalid JSON no longer asserts
    Instead of asserting when coming across malformed JSON,
    JsonParser::parse now returns an Optional<JsonValue>.
- Disallow trailing commas in JSON objects and arrays
- No longer parse 'undefined', as that is a purely JS thing
- No longer allow non-whitespace after anything consumed by the initial
  parse() call. Examples of things that were valid and no longer are:
    - undefineddfz
    - {"foo": 1}abcd
    - [1,2,3]4
- JsonObject.for_each_member now iterates in original insertion order
2020-06-13 12:43:22 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Andreas Kling
116cf92156 LibGfx: Rename Rect,Point,Size => IntRect,IntPoint,IntSize
This fits nicer with FloatRect,FloatPoint,FloatSize and gives a much
better visual clue about what type of metric is being used.
2020-06-10 10:59:04 +02:00
Sergey Bugaev
bb19eb8f23 IPCCompiler: Properly handle stream read errors
If we exhaust the buffer stream, the reads appear to succeed, but the stream
itself panics when we later attempt to drop it. To prevent it, we check for
errors explicitly.
2020-06-08 13:58:32 +02:00
Sergey Bugaev
fc481552f5 LibIPC+LibGfx+IPCCompiler: Drop some unused includes 2020-06-08 13:58:32 +02:00
Andreas Kling
3654710c41 LibIPC+Services: Support URL as a native IPC type 2020-06-07 22:55:33 +02:00
FalseHonesty
f958c693ee HackStudio: Support debugging variables with Enum types
Variables with enum types can now be both viewed and modified in the
variables view!
2020-06-03 08:12:50 +02:00
FalseHonesty
75e42648e1 HackStudio: Allow changing variable values in debugger
This patch adds a context menu to variables in the debugger variable
tree view that has an option to set the value of a variable. An input
box will pop up asking for the new value of the variable, which
is then parsed and used to set the actual variable.
2020-05-31 10:52:25 +02:00