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() {
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);
}
}
} 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);
}
});
}
}
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) {
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');
+ }
+}
#include <cstdint>
+#include "lib/phys_ptr.hpp"
+
namespace os {
template<typename... Ts>
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_;
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 {