started writing part of the 3ds9 stuff

This commit is contained in:
Morten Delenk 2017-12-09 19:35:36 +00:00
parent 2d7c0a36fe
commit 31862a292c
5 changed files with 154 additions and 6 deletions

View file

@ -7,12 +7,6 @@
extern "C" void __cxa_pure_virtual() { extern "C" void __cxa_pure_virtual() {
// panic("Pure virtual function called."); // 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 new[](size_t s, void *p) { return p; } void *operator new[](size_t s, void *p) { return p; }
void operator delete(void *, void *p) {} void operator delete(void *, void *p) {}

21
kernel/src/heap.cpp Normal file
View file

@ -0,0 +1,21 @@
#include <base.hpp>
#include <stddef.h>
//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);
}

View file

@ -0,0 +1,90 @@
#pragma once
//copypasted from https://stackoverflow.com/a/14741161
namespace bicycle
{
template<typename Result,typename ...Args>
struct abstract_function
{
virtual Result operator()(Args... args)=0;
virtual abstract_function *clone() const =0;
virtual ~abstract_function() = default;
};
template<typename Func,typename Result,typename ...Args>
class concrete_function: public abstract_function<Result,Args...>
{
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<typename Func>
struct func_filter
{
typedef Func type;
};
template<typename Result,typename ...Args>
struct func_filter<Result(Args...)>
{
typedef Result (*type)(Args...);
};
template<typename signature>
class function;
template<typename Result,typename ...Args>
class function<Result(Args...)>
{
abstract_function<Result,Args...> *f;
public:
function()
: f(nullptr)
{}
template<typename Func> function(const Func &x)
: f(new concrete_function<typename func_filter<Func>::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<typename Func> function &operator=(const Func &x)
{
auto *temp = new concrete_function<typename func_filter<Func>::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;

View file

@ -0,0 +1,35 @@
#pragma once
#include <function.hpp>
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<PXIreply(PXIcmd)> pxi_handlers[16];
uint32_t connid;
PXI();
~PXI();
void set_cmd_handler(uint32_t cmd, function<PXIreply(PXIcmd)> handler);
void send_cmd(PXIcmd command, function<void(PXIreplay)> callback);
void main_loop();
void
};
extern PXI pxi;

8
kernel/src/pxi.cpp Normal file
View file

@ -0,0 +1,8 @@
#include <pxi.hpp>
PXI pxi;
PXI::PXI() {
}