Allocator improvements, kernel C++ platform, streaming

This commit is contained in:
Daniel Hammer
2025-03-01 03:31:14 +04:00
parent 6f1c6f1316
commit 17d0bbf1bb
16 changed files with 367 additions and 166 deletions
+41
View File
@@ -0,0 +1,41 @@
#include "terminal.hpp"
#include "../Libraries/flanterm/backends/fb.h"
#include "../Libraries/flanterm/flanterm.h"
#include "../Libraries/string.hpp"
namespace Kt {
flanterm_context *ctx;
void Initialize(std::uint32_t *framebuffer, std::size_t width, std::size_t height, std::size_t pitch,
std::uint8_t red_mask_size, std::uint8_t red_mask_shift,
std::uint8_t green_mask_size, std::uint8_t green_mask_shift,
std::uint8_t blue_mask_size, std::uint8_t blue_mask_shift
)
{
ctx = flanterm_fb_init(
NULL,
NULL,
framebuffer,
width, height, pitch,
red_mask_size, red_mask_shift,
green_mask_size, green_mask_shift,
blue_mask_size, blue_mask_shift,
NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, 0, 0, 1,
0, 0,
0
);
}
void Putchar(char c) {
flanterm_write(ctx, &c, 1);
}
void Print(const char *text) {
flanterm_write(ctx, text, Lib::strlen(text));
}
};
+100
View File
@@ -0,0 +1,100 @@
#pragma once
#include <cstdint>
#include <cstddef>
#include <Libraries/string.hpp>
#include <CppLib/Stream.hpp>
using namespace kcp;
namespace Kt
{
constexpr char newline = '\n';
namespace screen
{
constexpr const char *clear = "\033[2J";
constexpr const char *cursor_reset = "\033[H";
};
void Initialize(std::uint32_t *framebuffer, std::size_t width, std::size_t height, std::size_t pitch,
std::uint8_t red_mask_size, std::uint8_t red_mask_shift,
std::uint8_t green_mask_size, std::uint8_t green_mask_shift,
std::uint8_t blue_mask_size, std::uint8_t blue_mask_shift);
void Putchar(char c);
void Print(const char *text);
inline base base_custom(int custom)
{
return (base)custom;
}
class KernelOutStream
{
public:
base streamBaseType = base::dec;
// C++ streaming operator like cout
friend KernelOutStream &operator<<(KernelOutStream &t, const char *string)
{
Print(string);
return t;
}
// C++ streaming operator like cout
friend KernelOutStream &operator<<(KernelOutStream &t, const char chr)
{
Putchar(chr);
return t;
}
friend KernelOutStream &operator<<(KernelOutStream &t, int number)
{
Print(Lib::int2basestr(number, t.streamBaseType));
return t;
}
friend KernelOutStream &operator<<(KernelOutStream &t, std::uint32_t number)
{
Print(Lib::uint2basestr(number, t.streamBaseType));
return t;
}
friend KernelOutStream &operator<<(KernelOutStream &t, std::uint64_t number)
{
Print(Lib::u64_2_basestr(number, t.streamBaseType));
return t;
}
friend KernelOutStream &operator<<(KernelOutStream &t, base newBase)
{
t.streamBaseType = newBase;
return t;
}
};
// This will be on the kernel entry point's stack. Which is totally fine since we don't ever exit from that function
};
extern Kt::KernelOutStream kout;
namespace Kt
{
class KernelErrorStream
{
public:
template <typename T>
friend KernelErrorStream &operator<<(KernelErrorStream &t, T value)
{
kout << "\e[0;31m" << value << "\e[0m";
return t;
}
};
};
extern Kt::KernelErrorStream kerr;