diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-10-18 13:05:00 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-10-18 13:05:00 +0200 |
commit | f67d695254bf9e0d053e064ade4387665180f27d (patch) | |
tree | f6f74e40a76a89480780f1765e6851d16c234fe6 /Kernel/i386.h | |
parent | 89851a9ded3589551df0fe518acc302b5f907f79 (diff) | |
download | serenity-f67d695254bf9e0d053e064ade4387665180f27d.zip |
More paging stuff.
The test userspace process now runs at linear address 0x300000 which is
mapped to a dynamically allocated page from the MemoryManager. Cool!
Diffstat (limited to 'Kernel/i386.h')
-rw-r--r-- | Kernel/i386.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Kernel/i386.h b/Kernel/i386.h index c96001af22..b15b8b6069 100644 --- a/Kernel/i386.h +++ b/Kernel/i386.h @@ -2,6 +2,8 @@ #include "types.h" +#define PAGE_SIZE 4096u + union Descriptor { struct { WORD limit_lo; @@ -76,6 +78,42 @@ void writeGDTEntry(WORD selector, Descriptor&); /* Map IRQ0-15 @ ISR 0x50-0x5F */ #define IRQ_VECTOR_BASE 0x50 +struct PageFaultFlags { +enum Flags { + NotPresent = 0x00, + ProtectionViolation = 0x01, + Read = 0x00, + Write = 0x02, + UserMode = 0x04, + SupervisorMode = 0x00, + InstructionFetch = 0x08, +}; +}; + +class PageFault { +public: + PageFault(word code, LinearAddress address) + : m_code(code) + , m_address(address) + { + } + + LinearAddress address() const { return m_address; } + word code() const { return m_code; } + + bool isNotPresent() const { return (m_code & 1) == PageFaultFlags::NotPresent; } + bool isProtectionViolation() const { return (m_code & 1) == PageFaultFlags::ProtectionViolation; } + bool isRead() const { return (m_code & 2) == PageFaultFlags::Read; } + bool isWrite() const { return (m_code & 2) == PageFaultFlags::Write; } + bool isUser() const { return (m_code & 4) == PageFaultFlags::UserMode; } + bool isSupervisor() const { return (m_code & 4) == PageFaultFlags::SupervisorMode; } + bool isInstructionFetch() const { return (m_code & 8) == PageFaultFlags::InstructionFetch; } + +private: + word m_code; + LinearAddress m_address; +}; + struct RegisterDump { WORD gs; WORD fs; @@ -95,3 +133,8 @@ struct RegisterDump { DWORD eflags; } PACKED; +inline constexpr dword pageBaseOf(dword address) +{ + return address & 0xfffff000; +} + |