49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#include "arch/Serial.h"
|
|
#include "arch/CPU.h"
|
|
#include <Format.h>
|
|
|
|
namespace Serial
|
|
{
|
|
void write(const char* str, usize size)
|
|
{
|
|
while (size--) putchar(*str++);
|
|
}
|
|
|
|
void print(const char* str)
|
|
{
|
|
while (*str) putchar(*str++);
|
|
}
|
|
|
|
void println(const char* str)
|
|
{
|
|
print(str);
|
|
putchar('\n');
|
|
}
|
|
|
|
Result<usize> printf(const char* format, ...)
|
|
{
|
|
va_list ap;
|
|
va_start(ap, format);
|
|
auto rc = cstyle_format(
|
|
format,
|
|
[](char c, void*) -> Result<void> {
|
|
putchar(c);
|
|
return {};
|
|
},
|
|
nullptr, ap);
|
|
va_end(ap);
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
static bool g_check_already_failed = false;
|
|
|
|
_noreturn bool __check_failed(const char* file, const char* line, const char* func, const char* expr)
|
|
{
|
|
if (!g_check_already_failed)
|
|
{ // Avoid endlessly failing when trying to report a failed check.
|
|
g_check_already_failed = true;
|
|
Serial::printf("ERROR: Check failed at %s:%s, in %s: %s\n", file, line, func, expr);
|
|
}
|
|
CPU::efficient_halt();
|
|
} |