aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86_64/include/arch/context_switching/syscall/main.hpp1
-rw-r--r--arch/x86_64/include/arch/memory/paging/active_page_table.hpp7
-rw-r--r--arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp22
-rw-r--r--arch/x86_64/include/arch/memory/paging/page_table.hpp5
-rw-r--r--arch/x86_64/include/arch/user/main.hpp1
-rw-r--r--arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp1
-rw-r--r--arch/x86_64/src/memory/main.cpp3
-rw-r--r--arch/x86_64/src/memory/paging/inactive_page_table.cpp2
-rw-r--r--arch/x86_64/src/memory/paging/temporary_page.cpp2
-rw-r--r--arch/x86_64/src/user/main.cpp12
10 files changed, 37 insertions, 19 deletions
diff --git a/arch/x86_64/include/arch/context_switching/syscall/main.hpp b/arch/x86_64/include/arch/context_switching/syscall/main.hpp
index 48fa195..3af5a5a 100644
--- a/arch/x86_64/include/arch/context_switching/syscall/main.hpp
+++ b/arch/x86_64/include/arch/context_switching/syscall/main.hpp
@@ -60,6 +60,7 @@ namespace teachos::arch::context_switching::syscall
* not function correctly.
* @return Bool-convertable error code converting to true if the syscall failed or false if it didn't.
*/
+ [[gnu::section(".user_text")]]
auto syscall(type syscall_number, arguments args = {}) -> error;
} // namespace teachos::arch::context_switching::syscall
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 a4a5b64..d77b76c 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
@@ -82,14 +82,17 @@ namespace teachos::arch::memory::paging
for (auto level = page_table_handle::LEVEL4; level != page_table_handle::LEVEL1; --level)
{
- current_handle = current_handle.next_table_or_create(allocator, page.get_level_index(level));
+ // Ignore all bits passed besides the entry::USER_ACCESSIBLE bit, because for the entry into the Level 4 up to
+ // Level 2 page, we always have to set the entry::PRESENT and entry::WRITABLE bit anyway.
+ current_handle = current_handle.next_table_or_create(allocator, page.get_level_index(level),
+ flags.to_ulong() & entry::USER_ACCESSIBLE);
}
auto & level1_entry = current_handle[page.get_level_index(page_table_handle::LEVEL1)];
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 | entry::USER_ACCESSIBLE);
+ level1_entry.set_entry(frame, flags.to_ulong() | entry::PRESENT);
}
/**
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 09e9bf4..ce74b98 100644
--- a/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
+++ b/arch/x86_64/include/arch/memory/paging/kernel_mapper.hpp
@@ -81,12 +81,11 @@ 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 | entry::USER_ACCESSIBLE);
+ active_table[511].set_entry(inactive_table.page_table_level_4_frame, entry::PRESENT | entry::WRITABLE);
kernel::cpu::tlb_flush_all();
map_elf_kernel_sections(active_table);
- page_table_level4[511].set_entry(backup, entry::PRESENT | entry::WRITABLE | entry::USER_ACCESSIBLE);
+ page_table_level4[511].set_entry(backup, entry::PRESENT | entry::WRITABLE);
kernel::cpu::tlb_flush_all();
temporary_page.unmap_page(active_table);
}
@@ -139,12 +138,15 @@ namespace teachos::arch::memory::paging
allocator::frame_container const frames{begin, end};
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.
+ // TODO: Why exactly are this section required or not required?
+ // Required to be accesible in User Mode: .user_text (Contains the actuall code executed), .boot_bss (Contains
+ // statically allocated variables), .boot_rodata (Contains constant data stored in ROM)
+ // Not required: .text, .rodata, .ctors, .dtors, .bss, .data, .boot_data, .boot_text, .init
+ if (section.physical_address == 0x100000 || section.physical_address == 0x102000 ||
+ section.physical_address == 0x216000)
+ {
+ entry.set_user_accesible();
+ }
for (auto const & frame : frames)
{
@@ -154,7 +156,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 | entry::USER_ACCESSIBLE);
+ active_table.identity_map(allocator, vga_buffer_frame, entry::WRITABLE);
}
T & allocator;
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 db7ba6c..7b7e29e 100644
--- a/arch/x86_64/include/arch/memory/paging/page_table.hpp
+++ b/arch/x86_64/include/arch/memory/paging/page_table.hpp
@@ -81,9 +81,10 @@ namespace teachos::arch::memory::paging
* @param allocator Reference to an allocator following the FrameAllocator concept, which is used to allocate
* entries when a new page table is required.
* @param table_index Index of this page table in the page table one level lower.
+ * @param flags A bitset of flags that configure the page table entry for this mapping.
*/
template<allocator::FrameAllocator T>
- auto next_table_or_create(T & allocator, std::size_t table_index) -> page_table_handle
+ auto next_table_or_create(T & allocator, std::size_t table_index, std::bitset<64U> flags) -> page_table_handle
{
auto next_handle = next_table(table_index);
// If the next table method failed then it means that the page level of the frame we want allocate has not yet
@@ -95,7 +96,7 @@ 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 | entry::USER_ACCESSIBLE);
+ .set_entry(allocated_frame.value(), flags.to_ulong() | entry::PRESENT | entry::WRITABLE);
// 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 ba30864..c168a1f 100644
--- a/arch/x86_64/include/arch/user/main.hpp
+++ b/arch/x86_64/include/arch/user/main.hpp
@@ -8,6 +8,7 @@ namespace teachos::arch::user
* 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.
*/
+ [[gnu::section(".user_text")]]
auto main() -> void;
} // namespace teachos::arch::user
diff --git a/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp b/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp
index 8e2c62d..9d061a8 100644
--- a/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp
+++ b/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp
@@ -8,5 +8,6 @@ namespace teachos::arch::interrupt_handling
{
(void)frame;
video::vga::text::write("An Interrupt occurred.", video::vga::text::common_attributes::green_on_black);
+ video::vga::text::newline();
}
} // namespace teachos::arch::interrupt_handling
diff --git a/arch/x86_64/src/memory/main.cpp b/arch/x86_64/src/memory/main.cpp
index 4cccabb..bd094e0 100644
--- a/arch/x86_64/src/memory/main.cpp
+++ b/arch/x86_64/src/memory/main.cpp
@@ -31,8 +31,7 @@ namespace teachos::arch::memory
for (auto const & page : pages)
{
- active_table.map_page_to_next_free_frame(allocator, page,
- paging::entry::WRITABLE | paging::entry::USER_ACCESSIBLE);
+ active_table.map_page_to_next_free_frame(allocator, page, paging::entry::WRITABLE);
}
}
} // namespace
diff --git a/arch/x86_64/src/memory/paging/inactive_page_table.cpp b/arch/x86_64/src/memory/paging/inactive_page_table.cpp
index 780f12c..4e0610e 100644
--- a/arch/x86_64/src/memory/paging/inactive_page_table.cpp
+++ b/arch/x86_64/src/memory/paging/inactive_page_table.cpp
@@ -14,7 +14,7 @@ namespace teachos::arch::memory::paging
{
auto table = temporary_page.map_table_frame(page_table_level_4_frame, active_page_table);
table.zero_entries();
- table[511].set_entry(page_table_level_4_frame, entry::PRESENT | entry::WRITABLE | entry::USER_ACCESSIBLE);
+ table[511].set_entry(page_table_level_4_frame, entry::PRESENT | entry::WRITABLE);
temporary_page.unmap_page(active_page_table);
}
} // namespace teachos::arch::memory::paging
diff --git a/arch/x86_64/src/memory/paging/temporary_page.cpp b/arch/x86_64/src/memory/paging/temporary_page.cpp
index 9946f36..8e73523 100644
--- a/arch/x86_64/src/memory/paging/temporary_page.cpp
+++ b/arch/x86_64/src/memory/paging/temporary_page.cpp
@@ -18,7 +18,7 @@ namespace teachos::arch::memory::paging
exception_handling::assert(!active_table.translate_page(page).has_value(),
"[Temporary page] Page is already mapped");
- active_table.map_page_to_frame(allocator, page, frame, entry::WRITABLE | entry::USER_ACCESSIBLE);
+ active_table.map_page_to_frame(allocator, page, frame, entry::WRITABLE);
return page.start_address();
}
diff --git a/arch/x86_64/src/user/main.cpp b/arch/x86_64/src/user/main.cpp
index 3ddcb32..3e7b0ec 100644
--- a/arch/x86_64/src/user/main.cpp
+++ b/arch/x86_64/src/user/main.cpp
@@ -3,21 +3,31 @@
#include "arch/context_switching/syscall/main.hpp"
// TODO: Disallow this import
+#include "arch/kernel/cpu/if.hpp"
#include "arch/video/vga/text.hpp"
namespace teachos::arch::user
{
- [[gnu::section(".user_text")]]
auto main() -> void
{
char constexpr syscall_message[] = "Successfully entered user mode and wrote to VGA buffer via syscall!";
auto const error = context_switching::syscall::syscall(context_switching::syscall::type::WRITE,
{reinterpret_cast<uint64_t>(&syscall_message)});
+ kernel::cpu::clear_interrupt_flag(); // Causes crash Kernel Code (.text) is not mapped in User mMde
+
+ auto test = new int{20}; // Causes crash Heap is not mapped in User Mode
+ (void)test;
+
if (!error)
{
+ // Causes crash vga is not mapped in User Mode
video::vga::text::write("Successfully made a SYSCALL and returned with SYSRETQ!",
video::vga::text::common_attributes::green_on_black);
}
+
+ for (;;)
+ {
+ }
}
} // namespace teachos::arch::user