]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Added printing of phys_ptrs and pointers
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Sun, 26 Mar 2023 02:08:35 +0000 (04:08 +0200)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Sun, 26 Mar 2023 02:08:35 +0000 (04:08 +0200)
kernel/src/interrupts.cpp
kernel/src/paging.cpp
kernel/src/ring3.cpp
kernel/src/serial.cpp
kernel/src/serial.hpp

index 5cea3c89550d1c5649e8967ef509608a096a4259..837734576851be6ca9ef3a76728d41d96cb3aceb 100644 (file)
@@ -111,19 +111,19 @@ extern "C" void int_page_fault(std::uint32_t err_code, std::uint64_t vaddr) {
        if (
                (0xFFFF'C000'0000'0000 <= vaddr && vaddr < 0xFFFF'C000'0801'0000) // process/port info
        ) { // Kernel memory
-               os::print("Allocating (Ring 0): {}\n", vaddr);
+               os::print("Allocating (Ring 0): {}\n", (void*)vaddr);
                os::paging::setup_page(PML4T, (void*)vaddr, true, false);
                return;
        } else if (
                (0x0000'7FFF'FFFF'0000 <= vaddr && vaddr < 0x0000'8000'0000'0000) // stack
        ) { // Userspace memory
-               os::print("Allocating (Ring 3): {}\n", vaddr);
+               os::print("Allocating (Ring 3): {}\n", (void*)vaddr);
                os::paging::setup_page(*os::get_process(os::current_pid).PML4T, (void*)vaddr, true, true);
                return;
        }
        os::print("Interrupt: Page Fault.\n");
        os::print("Err code: {}.\n", err_code);
-       os::print("Vaddr: {}.\n", vaddr);
+       os::print("Vaddr: {}.\n", (void*)vaddr);
        while (true) { os::hlt(); }
 }
 extern "C" void int_x87_floating_point_exception() {
index c3af8d5865514c2a46e59aa54ba33f24af89035a..13ea990b9348ad90e94242b0ff88a192e46a2bb9 100644 (file)
@@ -112,7 +112,7 @@ os::paging::page_allocator_t::page_allocator_t(): begin(nullptr) {}
 
 void os::paging::page_allocator_t::print_all() const {
        for (auto it = begin; it != nullptr; it = it->next) {
-               os::print("{} -> {} ({})\n", it.get_phys_addr(), (it + it->size).get_phys_addr(), it->size);
+               os::print("{} -> {} ({})\n", it, it + it->size, it->size);
        }
 }
 
index c0f58bd27176428ebbd3219aa98c3d92d0dbdc17..7aee109204668a88a4176cb62de9f2ce29b7b7d4 100644 (file)
@@ -61,7 +61,7 @@ extern "C" void os::syscall_print_low_mmap() {
                        } else {
                                os::print("stack:   ");
                        }
-                       os::print(" {} -> {} (0x{}B)\n", std::size_t(vaddr), paddr.get_phys_addr(), page_size_in_bytes);
+                       os::print(" {} -> {} ({}B)\n", vaddr, paddr, page_size_in_bytes);
                }
        });
 }
index d02bc12c34eb9d471a33c4f7b747f382a2a5b5bc..bd702466fed9435e38d15033071d4c2b7df2e34d 100644 (file)
@@ -60,9 +60,17 @@ void os::print_formatted(const char* format, const char* val) {
 }
 void os::print_formatted(const char* format, std::uint64_t val) {
        os::assert(format[0] == '}', "Format string unsupported. TODO.");
+       bool printed = false;
+       os::print("0x");
        for (int i = 60; i >= 0; i -= 4) {
                const int v = (val >> i) & 0xF;
-               os::printc(v < 10 ? v + '0' : v - 10 + 'a');
+               if (printed || v != 0) {
+                       os::printc(v < 10 ? v + '0' : v - 10 + 'a');
+                       printed = true;
+               }
+       }
+       if (!printed) {
+               os::printc('0');
        }
 }
 void os::print_formatted(const char* format, std::int64_t val) {
@@ -75,3 +83,19 @@ void os::print_formatted(const char* format, std::int64_t val) {
                os::print_formatted(format, std::uint64_t(val));
        }
 }
+void os::print_formatted(const char* format, phys_ptr<void> val) {
+       os::assert(format[0] == '}', "Format string unsupported. TODO.");
+       os::print("0x");
+       for (int i = 60; i >= 0; i -= 4) {
+               const int v = (val.get_phys_addr() >> i) & 0xF;
+               os::printc(v < 10 ? v + '0' : v - 10 + 'a');
+       }
+}
+void os::print_formatted(const char* format, const void* val) {
+       os::assert(format[0] == '}', "Format string unsupported. TODO.");
+       os::print("0x");
+       for (int i = 60; i >= 0; i -= 4) {
+               const int v = (reinterpret_cast<std::uintptr_t>(val) >> i) & 0xF;
+               os::printc(v < 10 ? v + '0' : v - 10 + 'a');
+       }
+}
index c64de07e533de6c4d5e4ac6e9d4c75a2b8adb08d..56c4ef9f22d0bd570b8d3395c1be621dd4a06252 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <cstdint>
 
+#include "lib/phys_ptr.hpp"
+
 namespace os {
 
 template<typename... Ts>
@@ -33,6 +35,8 @@ void printc(char c);
 void print_formatted(const char* format, const char* val);
 void print_formatted(const char* format, std::uint64_t val);
 void print_formatted(const char* format, std::int64_t val);
+void print_formatted(const char* format, phys_ptr<void> val);
+void print_formatted(const char* format, const void* val);
 
 template <typename T_> struct get_more_general_type_helper {
        using T = T_;
@@ -44,6 +48,10 @@ template <> struct get_more_general_type_helper<std::uint32_t> { using T = std::
 template <> struct get_more_general_type_helper<std::int8_t> { using T = std::int64_t; };
 template <> struct get_more_general_type_helper<std::int16_t> { using T = std::int64_t; };
 template <> struct get_more_general_type_helper<std::int32_t> { using T = std::int64_t; };
+template <> struct get_more_general_type_helper<char*> { using T = const char*; };
+template <> struct get_more_general_type_helper<const char*> { using T = const char*; };
+template <typename T_> struct get_more_general_type_helper<phys_ptr<T_>> { using T = phys_ptr<void>; };
+template <typename T_> struct get_more_general_type_helper<T_*> { using T = const void*; };
 template <std::size_t n> struct get_more_general_type_helper<char[n]> { using T = const char*; };
 
 struct print_nth_helper {