Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/kanso-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
with:
platform: ${{ matrix.Platform }}

release-pine64_star64:
release-riscv64_pine64_star64:
needs: kernel-build
uses: ./.github/workflows/release-pine64_star64.yml
uses: ./.github/workflows/release-riscv64_pine64_star64.yml
secrets: inherit

release:
needs: release-pine64_star64
needs: release-riscv64_pine64_star64
uses: ./.github/workflows/release.yml
secrets: inherit
13 changes: 13 additions & 0 deletions .github/workflows/kanso-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,16 @@ jobs:
with:
platform: ${{ matrix.Platform }}

results:
if: ${{ always() }}
runs-on: ubuntu-latest
name: Final Results
needs: [kernel-build]
steps:
- run: |
result="${{ needs.kernel-build.result }}"
if [[ $result == "success" || $result == "skipped" ]]; then
exit 0
else
exit 1
fi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Kernel-Build
name: Release-Riscv64_Pine64_Star64
on:
workflow_call:

Expand Down Expand Up @@ -64,6 +64,6 @@ jobs:
- name: Upload packaged Star64 image
uses: actions/upload-artifact@v4
with:
name: kanso_pine64_star64
name: kanso_riscv64_pine64_star64
path: |
images/kanso_pine64_star64.img
images/kanso_riscv64_pine64_star64.img
2 changes: 1 addition & 1 deletion .github/workflows/releases/pine64_star64/genimage.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image kanso_pine64_star64.img {
image kanso_riscv64_pine64_star64.img {
hdimage {
gpt = true
}
Expand Down
13 changes: 13 additions & 0 deletions cmake/Toolchains/clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ if(NOT CMAKE_C_COMPILER OR NOT CMAKE_ASM_COMPILER)
message(FATAL_ERROR "Could not find Clang.")
endif()

get_filename_component(_LLVM_BIN_DIR "${_CLANG}" DIRECTORY)

find_program(CMAKE_OBJCOPY # standard CMake cache variable
NAMES llvm-objcopy objcopy
HINTS "${_LLVM_BIN_DIR}"
"${_BREW_LLVM_PREFIX}/bin"
"C:\\Program Files\\LLVM\\bin"
NO_CMAKE_SYSTEM_PATH)

if(NOT CMAKE_OBJCOPY)
message(FATAL_ERROR "Could not find llvm-objcopy or objcopy in ${_LLVM_BIN_DIR}")
endif()

set(CMAKE_C_COMPILER "${_CLANG}" CACHE FILEPATH "C compiler" FORCE)
set(CMAKE_ASM_COMPILER "${_CLANG}" CACHE FILEPATH "ASM compiler" FORCE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Expand Down
35 changes: 33 additions & 2 deletions src/Common/String.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void StringFormat(SpanChar* destination, ReadOnlySpanChar message, ...)
va_end(vargs);
}

// TODO: Refactor this function
void StringFormatVargs(SpanChar* destination, ReadOnlySpanChar message, va_list vargs)
{
uint32_t length = 0;
Expand Down Expand Up @@ -97,13 +98,43 @@ void StringFormatVargs(SpanChar* destination, ReadOnlySpanChar message, va_list
break;
}

case 'l':
{
int64_t decimalArgument = va_arg(vargs, int64_t);

// HACK: We should do a code that compile 32 and 64-bit
int32_t magnitude = (int32_t)decimalArgument;

if (decimalArgument < 0)
{
destination->Pointer[length++] = '-';
magnitude = -magnitude;
}

int32_t divisor = 1;

while ((magnitude / divisor) > 9)
{
divisor *= 10;
}

while (divisor > 0)
{
destination->Pointer[length++] = '0' + magnitude / divisor;

magnitude %= divisor;
divisor /= 10;
}
break;
}

case 'x':
{
uint64_t hexaArgument = va_arg(vargs, uint64_t);
uintptr_t hexaArgument = va_arg(vargs, uintptr_t);
destination->Pointer[length++] = '0';
destination->Pointer[length++] = 'x';

for (int64_t i = 15; i >= 0; i--)
for (int32_t i = (sizeof(uintptr_t) * 2) - 1; i >= 0; i--)
{
unsigned nibble = (hexaArgument >> (i * 4)) & 0xf;
destination->Pointer[length++] = "0123456789abcdef"[nibble];
Expand Down
14 changes: 8 additions & 6 deletions src/Common/Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,35 @@ extern SpanChar globalTestLastErrorMessage;
do { \
if (!(expr)) { \
TestEntry* testEntry = &globalTests[globalCurrentTestIndex]; \
testEntry->HasError = true; \
StringFormat(&globalTestLastErrorMessage, String("%s\n Expected: %s\n Actual: %d %s %d"), __FILE__, #expr, expected, operator, actual); \
return; \
if (!testEntry->HasError) \
{ \
testEntry->HasError = true; \
StringFormat(&globalTestLastErrorMessage, String("%s\n Expected: %s\n Actual: %d %s %d"), __FILE__, #expr, expected, operator, actual); \
} \
} \
} while (false)

// BUG: There is a bug in the assert only in 32-bit version, when the assert fail
// BUG: There is a bug in the assert only in 32-bit version, when the assert fail maybe due to 64 bit values used in the comparison like with the time
#define TestAssertEquals(expected, actual) TestAssertCore((expected) == (actual), expected, actual, "==")
#define TestAssertNotEquals(expected, actual) TestAssertCore((expected) != (actual), expected, actual, "!=")
#define TestAssertGreaterThan(expected, actual) TestAssertCore((expected) > (actual), expected, actual, ">")
#define TestAssertIsTrue(actual) TestAssertCore(true == (actual), true, actual, "==")

// TODO: Adapt the macro like the core one
#define TestAssertStringEquals(expected, actual) \
do { \
if (finalString.Length != destination.Length) \
{ \
TestEntry* testEntry = &globalTests[globalCurrentTestIndex]; \
testEntry->HasError = true; \
StringFormat(&globalTestLastErrorMessage, String("%s\n Expected: (%s.Length) == (%s.Length)\n Actual: %d == %d"), __FILE__, #expected, #actual, expected.Length, actual.Length); \
return; \
} \
\
if (!StringEquals(expected, actual)) \
{ \
TestEntry* testEntry = &globalTests[globalCurrentTestIndex]; \
testEntry->HasError = true; \
StringFormat(&globalTestLastErrorMessage, String("%s\n Expected: (%s) == (%s)\n Actual: \"%s\" == \"%s\""), __FILE__, #expected, #actual, expected.Pointer, actual.Pointer); \
return; \
} \
} while (false)

Expand Down
8 changes: 8 additions & 0 deletions src/Common/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ static_assert(sizeof(uintptr_t) == sizeof(void *), "uintptr_t is not pointer-siz
#define va_start __builtin_va_start
#define va_end __builtin_va_end
#define va_arg __builtin_va_arg

typedef struct
{
uint8_t Red;
uint8_t Green;
uint8_t Blue;
uint8_t Alpha;
} Color;
11 changes: 6 additions & 5 deletions src/Kernel/Kernel.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "Kernel.h"
#include "KernelConsole.h"
#include "Memory.h"
#include "Platform.h"

void KernelFailureCore(ReadOnlySpanChar file, uint32_t line, ReadOnlySpanChar message, ...)
{
KernelConsolePrint(String("\x1b[31m\n ----------------\n"));
KernelConsolePrint(String("| KERNEL Failure |\n"));
KernelConsolePrint(String(" ----------------\n\n"));
KernelConsoleSetForegroundColor(KernelConsoleColorError);
KernelConsolePrintBoxMessage(String("Kernel Failure"));
KernelConsolePrint(String("%s:%d\n"), file, line);

va_list vargs;
Expand All @@ -15,11 +15,12 @@ void KernelFailureCore(ReadOnlySpanChar file, uint32_t line, ReadOnlySpanChar me
auto tmp = StackAllocChar(256);
StringFormatVargs(&tmp, message, vargs);

KernelConsolePrint(String("%s\n\n\x1b[0m"), tmp);
KernelConsolePrint(String("%s\n\n"), tmp);
KernelConsoleResetStyle();

va_end(vargs);

CpuDisableSupervisorInterrupts(CpuInterruptType_All);
CpuDisableInterrupts(CpuInterruptType_All);

while (true)
{
Expand Down
75 changes: 74 additions & 1 deletion src/Kernel/KernelConsole.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "KernelConsole.h"
#include "Memory.h"
#include "String.h"
#include "Platform.h"

// TODO: See https://github.com/riscv-software-src/opensbi/blob/master/lib/sbi/sbi_console.c#L440 for more implementation details
void KernelConsolePrint(ReadOnlySpanChar message, ...)
{
auto output = StackAllocChar(2048);
Expand All @@ -16,3 +16,76 @@ void KernelConsolePrint(ReadOnlySpanChar message, ...)

BiosDebugConsoleWrite(ToReadOnlySpanChar(output));
}

void KernelConsoleSetForegroundColor(Color color)
{
KernelConsolePrint(String("\x1b[38;2;%d;%d;%dm"), (int32_t)color.Red, (int32_t)color.Green, (int32_t)color.Blue);
}

void KernelConsoleResetStyle()
{
KernelConsolePrint(String("\x1b[0m"));
KernelConsoleSetForegroundColor(KernelConsoleColorNormal);
}

void FormatBoxedMessage(SpanChar destination, ReadOnlySpanChar message)
{
auto upLeftCorner = String("┌");
auto upRightCorner = String("┐");
auto downLeftCorner = String("└");
auto downRightCorner = String("┘");
auto horizontalLine = String("─");
auto verticalLine = String("│");

MemoryCopy(destination, upLeftCorner);
destination = SpanSliceFrom(destination, upLeftCorner.Length);

for (uint32_t i = 0; i < message.Length + 2; i++)
{
MemoryCopy(destination, horizontalLine);
destination = SpanSliceFrom(destination, horizontalLine.Length);
}

MemoryCopy(destination, upRightCorner);
destination = SpanSliceFrom(destination, upRightCorner.Length);

MemoryCopy(destination, String("\n"));
destination = SpanSliceFrom(destination, 1);

MemoryCopy(destination, verticalLine);
destination = SpanSliceFrom(destination, verticalLine.Length);

MemoryCopy(destination, String(" "));
destination = SpanSliceFrom(destination, 1);

MemoryCopy(destination, message);
destination = SpanSliceFrom(destination, message.Length);

MemoryCopy(destination, String(" "));
destination = SpanSliceFrom(destination, 1);

MemoryCopy(destination, verticalLine);
destination = SpanSliceFrom(destination, verticalLine.Length);

MemoryCopy(destination, String("\n"));
destination = SpanSliceFrom(destination, 1);

MemoryCopy(destination, downLeftCorner);
destination = SpanSliceFrom(destination, downLeftCorner.Length);

for (uint32_t i = 0; i < message.Length + 2; i++)
{
MemoryCopy(destination, horizontalLine);
destination = SpanSliceFrom(destination, horizontalLine.Length);
}

MemoryCopy(destination, downRightCorner);
destination = SpanSliceFrom(destination, downRightCorner.Length);
}

void KernelConsolePrintBoxMessage(ReadOnlySpanChar message)
{
auto boxedMessage = StackAllocChar(512);
FormatBoxedMessage(boxedMessage, message);
KernelConsolePrint(String("\n%s\n"), boxedMessage);
}
15 changes: 15 additions & 0 deletions src/Kernel/KernelConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,20 @@
#include "String.h"
#include "Types.h"

const Color KernelConsoleColorNormal = { 212, 212, 212, 255 };
const Color KernelConsoleColorHighlight = { 250, 250, 250, 255 };
const Color KernelConsoleColorAccent = { 79, 193, 255, 255 };
const Color KernelConsoleColorSuccess = { 106, 153, 85, 255 };
const Color KernelConsoleColorWarning = { 255, 135, 100, 255 };
const Color KernelConsoleColorError = { 255, 105, 105, 255 };
const Color KernelConsoleColorInfo = { 220, 220, 170, 255 };
const Color KernelConsoleColorAction = { 197, 134, 192, 255 };
const Color KernelConsoleColorKeyword = { 86, 156, 214, 255 };
const Color KernelConsoleColorNumeric = { 181, 206, 168, 255 };

void KernelConsolePrint(ReadOnlySpanChar message, ...);

void KernelConsoleSetForegroundColor(Color color);
void KernelConsoleResetStyle();

void KernelConsolePrintBoxMessage(ReadOnlySpanChar message);
Loading