1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

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.
This commit is contained in:
Andreas Kling 2020-07-11 16:45:48 +02:00
parent 0eab5659f8
commit ae1d14bc7a
5 changed files with 68 additions and 22 deletions

View file

@ -48,11 +48,16 @@ union PartAddressableRegister {
};
};
class SoftCPU final : public X86::Interpreter {
class SoftCPU final
: public X86::Interpreter
, public X86::InstructionStream {
public:
explicit SoftCPU(Emulator&);
void dump() const;
u32 eip() const { return m_eip; }
void set_eip(u32 eip) { m_eip = eip; }
struct Flags {
enum Flag {
CF = 0x0001,
@ -274,6 +279,13 @@ public:
}
private:
// ^X86::InstructionStream
virtual bool can_read() override { return false; }
virtual u8 read8() override;
virtual u16 read16() override;
virtual u32 read32() override;
// ^X86::Interpreter
virtual void AAA(const X86::Instruction&) override;
virtual void AAD(const X86::Instruction&) override;
virtual void AAM(const X86::Instruction&) override;
@ -779,6 +791,8 @@ private:
PartAddressableRegister m_gpr[8];
u16 m_segment[8] { 0 };
u32 m_eflags { 0 };
u32 m_eip { 0 };
};
}