diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-05-05 11:27:29 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-05-05 11:27:29 +0000 |
| commit | 7d2e8bc16e6c1bacb3c676d21ea2245d8132218f (patch) | |
| tree | e43e0c3e43f0288cf721de56f0ac33aac9dddbc0 /arch/x86_64/include | |
| parent | 27d4fb90ebbc754e98ff68ce5bc7839a44ed99c1 (diff) | |
| download | teachos-7d2e8bc16e6c1bacb3c676d21ea2245d8132218f.tar.xz teachos-7d2e8bc16e6c1bacb3c676d21ea2245d8132218f.zip | |
Remove the addition of USER_ACCESSIBLE flag to every entry created
Diffstat (limited to 'arch/x86_64/include')
5 files changed, 26 insertions, 6 deletions
diff --git a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp index 9e91a8c..a4a5b64 100644 --- a/arch/x86_64/include/arch/memory/paging/active_page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/active_page_table.hpp @@ -89,7 +89,7 @@ namespace teachos::arch::memory::paging arch::exception_handling::assert(!level1_entry.contains_flags(entry::HUGE_PAGE), "[Page Mapper] Unable to map huge pages"); arch::exception_handling::assert(level1_entry.is_unused(), "[Page Mapper] Page table entry is already used"); - level1_entry.set_entry(frame, flags.to_ulong() | entry::PRESENT); + level1_entry.set_entry(frame, flags.to_ulong() | entry::PRESENT | entry::USER_ACCESSIBLE); } /** diff --git a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp index 8d36fde..09e9bf4 100644 --- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp +++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp @@ -81,11 +81,12 @@ namespace teachos::arch::memory::paging kernel::cpu::read_control_register(kernel::cpu::control_register::CR3)); auto page_table_level4 = temporary_page.map_table_frame(backup, active_table); - active_table[511].set_entry(inactive_table.page_table_level_4_frame, entry::PRESENT | entry::WRITABLE); + active_table[511].set_entry(inactive_table.page_table_level_4_frame, + entry::PRESENT | entry::WRITABLE | entry::USER_ACCESSIBLE); kernel::cpu::tlb_flush_all(); map_elf_kernel_sections(active_table); - page_table_level4[511].set_entry(backup, entry::PRESENT | entry::WRITABLE); + page_table_level4[511].set_entry(backup, entry::PRESENT | entry::WRITABLE | entry::USER_ACCESSIBLE); kernel::cpu::tlb_flush_all(); temporary_page.unmap_page(active_table); } @@ -136,7 +137,14 @@ namespace teachos::arch::memory::paging allocator::frame_container::iterator const begin{start_frame}; allocator::frame_container::iterator const end{end_frame}; allocator::frame_container const frames{begin, end}; - entry const entry{section.flags}; + entry entry{section.flags}; + + // TODO: Only set this if we are in the .user_text section. + // address: 0000000000216000, offset: 013000, size: varies depending on code not a a good idea + // Alternatively index Nr. 8 could be used to detect section, can also change if we add more section + entry.set_user_accesible(); + + // TODO: Entering User Mode still works, but then attempting to execute an instruction immedatiately fails. for (auto const & frame : frames) { @@ -146,7 +154,7 @@ namespace teachos::arch::memory::paging auto const vga_buffer_frame = allocator::physical_frame::containing_address(video::vga::text::DEFAULT_VGA_TEXT_BUFFER_ADDRESS); - active_table.identity_map(allocator, vga_buffer_frame, entry::WRITABLE); + active_table.identity_map(allocator, vga_buffer_frame, entry::WRITABLE | entry::USER_ACCESSIBLE); } T & allocator; diff --git a/arch/x86_64/include/arch/memory/paging/page_entry.hpp b/arch/x86_64/include/arch/memory/paging/page_entry.hpp index ef4fe61..5cba1bc 100644 --- a/arch/x86_64/include/arch/memory/paging/page_entry.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_entry.hpp @@ -72,6 +72,12 @@ namespace teachos::arch::memory::paging auto set_unused() -> void; /** + * @brief Marks the page as accessible in User mode, meaning the underlying std::bitset has the 2nd bit aditonally + * set. + */ + auto set_user_accesible() -> void; + + /** * @brief Calculates the physical frame this entry is pointing too, can be null if the page is not present in * memory. * diff --git a/arch/x86_64/include/arch/memory/paging/page_table.hpp b/arch/x86_64/include/arch/memory/paging/page_table.hpp index 60a0a2f..db7ba6c 100644 --- a/arch/x86_64/include/arch/memory/paging/page_table.hpp +++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp @@ -94,7 +94,8 @@ namespace teachos::arch::memory::paging { auto const allocated_frame = allocator.allocate_frame(); exception_handling::assert(allocated_frame.has_value(), "[Page mapper] Unable to allocate frame"); - this->operator[](table_index).set_entry(allocated_frame.value(), entry::PRESENT | entry::WRITABLE); + this->operator[](table_index) + .set_entry(allocated_frame.value(), entry::PRESENT | entry::WRITABLE | entry::USER_ACCESSIBLE); // There should now be an entry at the previously not existent index, therefore we can simply access it again. next_handle = next_table(table_index); exception_handling::assert(next_handle.has_value(), "[Page mapper] Unable to create new entry into page table"); diff --git a/arch/x86_64/include/arch/user/main.hpp b/arch/x86_64/include/arch/user/main.hpp index 4f1d005..ba30864 100644 --- a/arch/x86_64/include/arch/user/main.hpp +++ b/arch/x86_64/include/arch/user/main.hpp @@ -3,6 +3,11 @@ namespace teachos::arch::user { + /** + * @brief User Main method. If this method finishes there is no code left to run and the whole OS will shut down. + * Additionally this main method is executed at Ring 3 and accessing CPU Registers or Kernel level functionality can + * only be done over syscalls and not directly anymore. + */ auto main() -> void; } // namespace teachos::arch::user |
