Skip to content

Commit d6d13cf

Browse files
authored
Memory arena (#21)
* Implement basic DTB parser * Change CD * Add SpanAt macro * WIP memory management boot init * Fix tests * Span and BitArray * WIP BitArray operations * Change SpanCast implementation * Implement bitmap memory allotor for kernel init * WIP Memory Arena * WIP MemoryArena * WIP memory * Fix build * Refactor Span types * Implement MemoryArena Pop and Clear. * WIP StackMemoryArena * Implement StackMemoryArena * Update StringSplit function * Update StringFormat * Fix test
1 parent 909031d commit d6d13cf

35 files changed

Lines changed: 2388 additions & 455 deletions

.github/workflows/kanso-cd.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Kanso-CD
22
on:
3-
push:
4-
branches:
5-
- main
63
workflow_dispatch:
74

85
jobs:

.github/workflows/kanso-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Kanso-CI
22
on:
3+
push:
4+
branches:
5+
- main
36
pull_request:
47
workflow_dispatch:
58

cmake/Toolchains/riscv-common.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ endif()
1919
set(CMAKE_C_FLAGS "${_COMMON} -march=${_MARCH} -mabi=${_MABI} ${_MODEL}")
2020
set(CMAKE_ASM_FLAGS "--target=${COMPILE_TARGET} -march=${_MARCH} -mabi=${_MABI} -Wno-unused-command-line-argument -x assembler-with-cpp")
2121

22+
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld")
23+
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld")
24+
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=lld")
25+
set(CMAKE_C_LINK_FLAGS_INIT "-fuse-ld=lld")

src/Common/Console.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "Console.h"
2+
3+
void FormatBoxedMessage(SpanChar destination, ReadOnlySpanChar message)
4+
{
5+
auto upLeftCorner = String("┌");
6+
auto upRightCorner = String("┐");
7+
auto downLeftCorner = String("└");
8+
auto downRightCorner = String("┘");
9+
auto horizontalLine = String("─");
10+
auto verticalLine = String("│");
11+
12+
MemoryCopy(destination, upLeftCorner);
13+
destination = SpanSliceFrom(destination, upLeftCorner.Length);
14+
15+
for (uint32_t i = 0; i < message.Length + 2; i++)
16+
{
17+
MemoryCopy(destination, horizontalLine);
18+
destination = SpanSliceFrom(destination, horizontalLine.Length);
19+
}
20+
21+
MemoryCopy(destination, upRightCorner);
22+
destination = SpanSliceFrom(destination, upRightCorner.Length);
23+
24+
MemoryCopy(destination, String("\n"));
25+
destination = SpanSliceFrom(destination, 1);
26+
27+
MemoryCopy(destination, verticalLine);
28+
destination = SpanSliceFrom(destination, verticalLine.Length);
29+
30+
MemoryCopy(destination, String(" "));
31+
destination = SpanSliceFrom(destination, 1);
32+
33+
MemoryCopy(destination, message);
34+
destination = SpanSliceFrom(destination, message.Length);
35+
36+
MemoryCopy(destination, String(" "));
37+
destination = SpanSliceFrom(destination, 1);
38+
39+
MemoryCopy(destination, verticalLine);
40+
destination = SpanSliceFrom(destination, verticalLine.Length);
41+
42+
MemoryCopy(destination, String("\n"));
43+
destination = SpanSliceFrom(destination, 1);
44+
45+
MemoryCopy(destination, downLeftCorner);
46+
destination = SpanSliceFrom(destination, downLeftCorner.Length);
47+
48+
for (uint32_t i = 0; i < message.Length + 2; i++)
49+
{
50+
MemoryCopy(destination, horizontalLine);
51+
destination = SpanSliceFrom(destination, horizontalLine.Length);
52+
}
53+
54+
MemoryCopy(destination, downRightCorner);
55+
destination = SpanSliceFrom(destination, downRightCorner.Length);
56+
57+
// TODO: There is a problem here with null terminator not present
58+
}
59+
60+
void ConsoleSetForegroundColor(Color color)
61+
{
62+
ConsolePrint(String("\x1b[38;2;%d;%d;%dm"), (int32_t)color.Red, (int32_t)color.Green, (int32_t)color.Blue);
63+
}
64+
65+
void ConsoleResetStyle()
66+
{
67+
ConsolePrint(String("\x1b[0m"));
68+
ConsoleSetForegroundColor(ConsoleColorNormal);
69+
}
70+
71+
void ConsolePrintBoxMessage(ReadOnlySpanChar message)
72+
{
73+
// TODO: Use the stack memory arena here
74+
auto boxedMessage = StackAlloc(char, 512);
75+
FormatBoxedMessage(boxedMessage, message);
76+
ConsolePrint(String("\n%s\n"), boxedMessage);
77+
}

src/Common/Console.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include "Memory.h"
4+
#include "String.h"
5+
#include "Types.h"
6+
7+
const Color ConsoleColorNormal = { 212, 212, 212, 255 };
8+
const Color ConsoleColorHighlight = { 250, 250, 250, 255 };
9+
const Color ConsoleColorAccent = { 79, 193, 255, 255 };
10+
const Color ConsoleColorSuccess = { 106, 153, 85, 255 };
11+
const Color ConsoleColorWarning = { 255, 135, 100, 255 };
12+
const Color ConsoleColorError = { 255, 105, 105, 255 };
13+
const Color ConsoleColorInfo = { 220, 220, 170, 255 };
14+
const Color ConsoleColorAction = { 197, 134, 192, 255 };
15+
const Color ConsoleColorKeyword = { 86, 156, 214, 255 };
16+
const Color ConsoleColorNumeric = { 181, 206, 168, 255 };
17+
18+
void ConsolePrint(ReadOnlySpanChar message, ...);
19+
20+
void ConsoleSetForegroundColor(Color color);
21+
void ConsoleResetStyle();
22+
23+
void ConsolePrintBoxMessage(ReadOnlySpanChar message);

0 commit comments

Comments
 (0)