kernel/CPU: Move some stuff to StringView

This commit is contained in:
apio 2023-05-03 17:35:46 +02:00
parent 1215c38d75
commit abaf24d0da
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 11 additions and 10 deletions

View File

@ -1,12 +1,13 @@
#pragma once
#include <luna/Result.h>
#include <luna/StringView.h>
struct Registers;
namespace CPU
{
Result<const char*> identify();
const char* platform_string();
Result<StringView> identify();
StringView platform_string();
void platform_init();
void platform_finish_init();

View File

@ -184,7 +184,7 @@ static bool test_nx()
namespace CPU
{
Result<const char*> identify()
Result<StringView> identify()
{
static char brand_string[49];
@ -198,12 +198,12 @@ namespace CPU
brand_string[48] = 0; // null-terminate it :)
return brand_string;
return StringView { brand_string, 48 };
}
const char* platform_string()
StringView platform_string()
{
return "x86_64";
return "x86_64"_sv;
}
void platform_init()

View File

@ -41,8 +41,8 @@ Result<void> init()
// Default hostname if nobody from userspace changes it
set_host_name("moon"_sv);
kinfoln("Current platform: %s", CPU::platform_string());
kinfoln("Current processor: %s", CPU::identify().value_or("(unknown)"));
kinfoln("Current platform: %s", CPU::platform_string().chars());
kinfoln("Current processor: %s", CPU::identify().value_or("(unknown)"_sv).chars());
kinfoln("Total memory: %s", to_dynamic_unit(MemoryManager::total()).release_value().chars());
kinfoln("Free memory: %s", to_dynamic_unit(MemoryManager::free()).release_value().chars());

View File

@ -27,7 +27,7 @@ Result<u64> sys_uname(Registers*, SyscallArgs args)
// FIXME: Hardcode this at build time instead of in code (should be the short commit hash).
strncpy(result.version, "alpha", _UTSNAME_LENGTH);
strncpy(result.machine, CPU::platform_string(), _UTSNAME_LENGTH);
strncpy(result.machine, CPU::platform_string().chars(), _UTSNAME_LENGTH);
if (!MemoryManager::copy_to_user_typed(buf, &result)) return err(EFAULT);

View File

@ -63,7 +63,7 @@ namespace ELFLoader
if (elf_header.e_machine != EM_MACH)
{
kerrorln("Error while loading ELF: ELF object's target architecture does not match the current one (%s)",
CPU::platform_string());
CPU::platform_string().chars());
return err(ENOEXEC);
}