Commit graph

15 commits

Author SHA1 Message Date
Andreas Kling
079021a607 UserspaceEmulator: Put the executable name in argv[0] :^)
The emulated program can now find its own name in argv[0]. Very cool!
2020-07-12 21:37:54 +02:00
Andreas Kling
ddf7b817df UserspaceEmulator: Add Emulator::dump_backtrace()
This gives you a nice, symbolicated backtrace at the current EIP. :^)
2020-07-12 21:37:54 +02:00
Andreas Kling
584923445c UserspaceEmulator: "Add" a couple of syscalls
This patch adds gettid() and stubs out pledge() and unveil() for now.
2020-07-12 21:37:54 +02:00
Andreas Kling
734f63d522 UserspaceEmulator: Add basic TLS (thread-local storage) support
The SoftMMU now receives full X86::LogicalAddress values from SoftCPU.
This allows the MMU to reroute TLS accesses to a special memory region.

The ELF executable's PT_TLS header tells us how to allocate the TLS.

Basically, the GS register points to a magical 4-byte area which has
a pointer to the TCB (thread control block). The TCB lives in normal
flat memory space and is accessed through the DS register.
2020-07-12 01:36:45 +02:00
Andreas Kling
ce51cf90c6 UserspaceEmulator: Make sure ELF data segments are zero-initialized
(And all other memory, too.) This will mutate later when we add shadow
memory etc, but for now just zero-initialize it since that's expected
by the emulated program.
2020-07-12 01:36:45 +02:00
Andreas Kling
463afa69a7 UserspaceEmulator: Improve the initial program stack a tiny bit
Instead of starting with argv=nullptr, envp=nullptr, programs now
start with both pointing to a null terminated array (that immediately
terminates.) :^)
2020-07-11 23:57:14 +02:00
Andreas Kling
0f63d8c9b4 UserspaceEmulator: Symbolicate disassembly output :^)
Since we have the ELF executable handy, we can actually symbolicate the
disassembly trace output really easily. Very cool! :^)
2020-07-11 17:18:07 +02:00
Andreas Kling
dc66d70369 UserspaceEmulator: Don't exit the emulation loop on "RET" :^) 2020-07-11 17:13:15 +02:00
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
6f27770cea UserspaceEmulator: Add 8/16 bit memory read/write operations 2020-07-10 20:20:27 +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
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