diff --git a/kernel/src/cppstubs.cpp b/kernel/src/cppstubs.cpp index 177390b..1570cb8 100644 --- a/kernel/src/cppstubs.cpp +++ b/kernel/src/cppstubs.cpp @@ -7,12 +7,6 @@ extern "C" void __cxa_pure_virtual() { // panic("Pure virtual function called."); } -void *operator new(size_t s) { return (void *)1; } -void *operator new[](size_t s) { return (void *)1; } -void operator delete(void *p) {} -void operator delete[](void *p) {} -void operator delete(void *p, size_t s) {} -void operator delete[](void *p, size_t s) {} void *operator new(size_t s, void *p) { return p; } void *operator new[](size_t s, void *p) { return p; } void operator delete(void *, void *p) {} diff --git a/kernel/src/heap.cpp b/kernel/src/heap.cpp new file mode 100644 index 0000000..e3977ac --- /dev/null +++ b/kernel/src/heap.cpp @@ -0,0 +1,21 @@ +#include +#include +//Shitty heap which wastes a ton of bytes and page-aligns everything +void *operator new(size_t s) { + return (void*)(*pmm, (s+4095)/4096); +} +void *operator new[](size_t s) { + return (void*)(*pmm, (s+4095)/4096); +} +void *operator delete(void *p) { + (*pmm)((phys_t)p,1); +} +void *operator delete[](void *p) { + (*pmm)((phys_t)p,1); +} +void *operator delete(void *p, size_t s) { + (*pmm)((phys_t)p,(s+4095)/4096); +} +void *operator delete[](void *p, size_t s) { + (*pmm)((phys_t)p,(s+4095)/4096); +} diff --git a/kernel/src/include/function.hpp b/kernel/src/include/function.hpp new file mode 100644 index 0000000..5ec7ada --- /dev/null +++ b/kernel/src/include/function.hpp @@ -0,0 +1,90 @@ +#pragma once +//copypasted from https://stackoverflow.com/a/14741161 +namespace bicycle +{ + template + struct abstract_function + { + virtual Result operator()(Args... args)=0; + virtual abstract_function *clone() const =0; + virtual ~abstract_function() = default; + }; + + template + class concrete_function: public abstract_function + { + Func f; + public: + concrete_function(const Func &x) + : f(x) + {} + Result operator()(Args... args) override + { + return f(args...); + } + concrete_function *clone() const override + { + return new concrete_function{f}; + } + }; + + template + struct func_filter + { + typedef Func type; + }; + template + struct func_filter + { + typedef Result (*type)(Args...); + }; + + template + class function; + + template + class function + { + abstract_function *f; + public: + function() + : f(nullptr) + {} + template function(const Func &x) + : f(new concrete_function::type,Result,Args...>(x)) + {} + function(const function &rhs) + : f(rhs.f ? rhs.f->clone() : nullptr) + {} + function &operator=(const function &rhs) + { + if( (&rhs != this ) && (rhs.f) ) + { + auto *temp = rhs.f->clone(); + delete f; + f = temp; + } + return *this; + } + template function &operator=(const Func &x) + { + auto *temp = new concrete_function::type,Result,Args...>(x); + delete f; + f = temp; + return *this; + } + Result operator()(Args... args) + { + if(f) + return (*f)(args...); + else + return Result{}; + } + ~function() + { + delete f; + } + }; +} + +using bicycle::function; diff --git a/kernel/src/include/pxi.hpp b/kernel/src/include/pxi.hpp new file mode 100644 index 0000000..cd864a4 --- /dev/null +++ b/kernel/src/include/pxi.hpp @@ -0,0 +1,35 @@ +#pragma once +#include +struct PXIcmd { + uint32_t conid; + uint32_t cmdid; + uint32_t args[14]; +}; + +enum class ErrorCode { + SUCCESS, + SEGV, + UNKNOWN +}; + +struct PXIreply { + uint32_t conid; + ErrorCode err; + uint32_t resp[14]; +}; + +struct PXI { + PXIcmd command; + function pxi_handlers[16]; + uint32_t connid; + PXI(); + ~PXI(); + + void set_cmd_handler(uint32_t cmd, function handler); + void send_cmd(PXIcmd command, function callback); + void main_loop(); + + void +}; + +extern PXI pxi; diff --git a/kernel/src/pxi.cpp b/kernel/src/pxi.cpp new file mode 100644 index 0000000..2e076f1 --- /dev/null +++ b/kernel/src/pxi.cpp @@ -0,0 +1,8 @@ +#include + +PXI pxi; + + +PXI::PXI() { + +}