Move userspace to a templated StrFormat.

This commit is contained in:
Drew Galbraith 2023-11-03 02:48:21 -07:00
parent d9df1212b7
commit 26b61db021
25 changed files with 263 additions and 217 deletions

View File

@ -1,6 +1,8 @@
add_library(glacier STATIC add_library(glacier STATIC
string/string.cpp string/string.cpp
string/string_builder.cpp
string/string_view.cpp string/string_view.cpp
string/str_format.cpp
string/str_split.cpp string/str_split.cpp
) )

View File

@ -57,6 +57,8 @@ class Vector {
uint64_t size() const { return size_; } uint64_t size() const { return size_; }
uint64_t capacity() const { return capacity_; } uint64_t capacity() const { return capacity_; }
const T* RawPtr() const { return data_; }
private: private:
T* data_; T* data_;
uint64_t size_; uint64_t size_;

View File

@ -0,0 +1,73 @@
#include "glacier/string/str_format.h"
namespace glcr {
namespace {
void StrFormatNumber(StringBuilder& builder, uint64_t value, uint64_t base) {
const char* kHexCharacters = "0123456789ABCDEF";
if (value < base) {
builder.PushBack(kHexCharacters[value]);
return;
}
StrFormatNumber(builder, value / base, base);
builder.PushBack(kHexCharacters[value % base]);
}
} // namespace
template <>
void StrFormatValue(StringBuilder& builder, uint8_t value, StringView opts) {
StrFormatValue(builder, static_cast<uint64_t>(value), opts);
}
template <>
void StrFormatValue(StringBuilder& builder, uint16_t value, StringView opts) {
StrFormatValue(builder, static_cast<uint64_t>(value), opts);
}
template <>
void StrFormatValue(StringBuilder& builder, int32_t value, StringView opts) {
StrFormatValue(builder, static_cast<uint64_t>(value), opts);
}
template <>
void StrFormatValue(StringBuilder& builder, uint32_t value, StringView opts) {
StrFormatValue(builder, static_cast<uint64_t>(value), opts);
}
template <>
void StrFormatValue(StringBuilder& builder, uint64_t value, StringView opts) {
if (opts.find('x') != opts.npos) {
builder.PushBack("0x");
StrFormatNumber(builder, value, 16);
} else {
StrFormatNumber(builder, value, 10);
}
}
template <>
void StrFormatValue(StringBuilder& builder, ErrorCode value, StringView opts) {
StrFormatValue(builder, static_cast<uint64_t>(value), opts);
}
template <>
void StrFormatValue(StringBuilder& builder, const char* value,
StringView opts) {
StrFormatValue(builder, StringView(value), opts);
}
template <>
void StrFormatValue(StringBuilder& builder, StringView value, StringView opts) {
StrFormatInternal(builder, value);
}
void StrFormatInternal(StringBuilder& builder, StringView format) {
// TODO: Consider throwing an error if there are unhandled format
builder.PushBack(format);
}
} // namespace glcr

View File

@ -0,0 +1,62 @@
#pragma once
#include "glacier/memory/move.h"
#include "glacier/status/error.h"
#include "glacier/string/string_builder.h"
#include "glacier/string/string_view.h"
namespace glcr {
template <typename T>
void StrFormatValue(StringBuilder& builder, T value, StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, uint8_t value, StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, uint16_t value, StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, int32_t value, StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, uint32_t value, StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, uint64_t value, StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, ErrorCode value, StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, const char* value, StringView opts);
template <>
void StrFormatValue(StringBuilder& builder, StringView value, StringView opts);
void StrFormatInternal(StringBuilder& builder, StringView format);
template <typename T, typename... Args>
void StrFormatInternal(StringBuilder& builder, StringView format, T value,
Args... args) {
uint64_t posl = format.find('{');
uint64_t posr = format.find('}', posl);
if (posl == format.npos || posr == format.npos) {
// TODO: Consider throwing an error since we still have values to consume.
return StrFormatInternal(builder, format);
}
builder.PushBack(format.substr(0, posl));
StrFormatValue(builder, value, format.substr(posl + 1, posr - posl - 1));
StrFormatInternal(builder, format.substr(posr + 1, format.size() - posr - 1),
args...);
}
template <typename... Args>
StringBuilder StrFormat(StringView format, Args... args) {
StringBuilder builder;
StrFormatInternal(builder, format, args...);
return glcr::Move(builder);
}
} // namespace glcr

View File

@ -0,0 +1,24 @@
#include "glacier/string/string_builder.h"
namespace glcr {
void StringBuilder::PushBack(const StringView& str) {
if (capacity() < size() + str.size()) {
uint64_t new_capacity = capacity() == 0 ? 1 : capacity() * 2;
while (new_capacity < size() + str.size()) {
new_capacity *= 2;
}
Resize(new_capacity);
}
for (uint64_t i = 0; i < str.size(); i++) {
Vector<char>::PushBack(str[i]);
}
}
String StringBuilder::ToString() const { return String(RawPtr(), size()); }
StringBuilder::operator StringView() const {
return StringView(RawPtr(), size());
}
} // namespace glcr

View File

@ -0,0 +1,26 @@
#pragma once
#include "glacier/container/vector.h"
#include "glacier/string/string.h"
#include "glacier/string/string_view.h"
namespace glcr {
class StringBuilder : public Vector<char> {
public:
StringBuilder() : Vector<char>() {}
StringBuilder(const StringBuilder&) = delete;
StringBuilder(StringBuilder&& str) : Vector<char>(Move(str)) {}
void PushBack(const StringView& str);
using Vector<char>::PushBack;
String ToString() const;
// Note that this could become invalidated
// at any time if more characters are pushed
// onto the builder.
operator StringView() const;
};
} // namespace glcr

View File

@ -25,6 +25,7 @@ uint64_t StringView::size() const { return size_; }
bool StringView::empty() const { return size_ == 0; } bool StringView::empty() const { return size_ == 0; }
char StringView::at(uint64_t pos) const { return value_[pos]; } char StringView::at(uint64_t pos) const { return value_[pos]; }
char StringView::operator[](uint64_t pos) const { return at(pos); };
uint64_t StringView::find(char c, uint64_t pos) const { uint64_t StringView::find(char c, uint64_t pos) const {
for (uint64_t i = pos; i < size_; i++) { for (uint64_t i = pos; i < size_; i++) {

View File

@ -19,6 +19,7 @@ class StringView {
bool empty() const; bool empty() const;
char at(uint64_t pos) const; char at(uint64_t pos) const;
char operator[](uint64_t pos) const;
uint64_t find(char c, uint64_t pos = 0) const; uint64_t find(char c, uint64_t pos = 0) const;

View File

@ -1,7 +1,6 @@
add_library(c STATIC add_library(c STATIC
src/malloc.cpp src/malloc.cpp
src/stdio.cpp
src/string.cpp src/string.cpp
) )

View File

@ -1,10 +0,0 @@
#pragma once
#include <stdarg.h>
// int fprintf(FILE *stream, const char *format, ...);
int printf(const char *format, ...);
int sprintf(char *str, const char *format, ...);
// int vfprintf(FILE *stream, const char *format, va_list arg);
int vprintf(const char *format, va_list arg);
int vsprintf(char *str, const char *format, va_list arg);

View File

@ -1,126 +0,0 @@
#include "stdio.h"
#include <stdint.h>
namespace {
uint32_t num_chars(uint64_t num, uint8_t base) {
uint32_t width = 0;
while (num > 0) {
num /= base;
width++;
}
return width;
}
int sprint_base(char *str, uint64_t num, uint32_t base) {
uint32_t width = num_chars(num, base);
if (width == 0) {
*str = '0';
return 1;
}
uint64_t place = 1;
while (num > 0) {
// FIXME: We seem to have an issue with loading globals.
const char *kHexChars = "0123456789abcdef";
str[width - place] = kHexChars[num % base];
place++;
num /= base;
}
return width;
}
} // namespace
int sprintf(char *str, const char *format, ...) {
va_list arg;
va_start(arg, format);
int ret = vsprintf(str, format, arg);
va_end(arg);
return ret;
}
int vsprintf(char *str, const char *format, va_list arg) {
uint32_t chars = 0;
while (*format != '\0') {
if (*format != '%') {
*str = *format;
chars++;
str++;
format++;
continue;
}
format++;
switch (*format) {
case '%':
*(str++) = *(format++);
chars++;
break;
case 'l': {
switch (*(++format)) {
case 'x': {
int width = sprint_base(str, va_arg(arg, uint64_t), 16);
if (width == -1) {
return -1;
}
chars += width;
str += width;
format++;
break;
}
case 'u': {
int width = sprint_base(str, va_arg(arg, uint64_t), 10);
if (width == -1) {
return -1;
}
chars += width;
str += width;
format++;
break;
}
}
break;
}
case 'x': {
int width = sprint_base(str, va_arg(arg, uint32_t), 16);
if (width == -1) {
return -1;
}
chars += width;
str += width;
format++;
break;
}
case 'u': {
int width = sprint_base(str, va_arg(arg, uint32_t), 10);
if (width == -1) {
return -1;
}
chars += width;
str += width;
format++;
break;
}
case 's': {
char *instr = va_arg(arg, char *);
int width = 0;
while (*instr != '\0') {
*(str++) = *(instr++);
width++;
}
format++;
break;
}
default:
*(str++) = *(format++);
chars++;
}
}
*str = '\0';
chars++;
return chars;
}

View File

@ -1,9 +1,17 @@
#pragma once #pragma once
#include <glacier/string/str_format.h>
#include <glacier/string/string_view.h>
#include <stdint.h> #include <stdint.h>
#include <ztypes.h> #include <ztypes.h>
void dbgln(const char* fmt, ...); // TODO: Take StringView here instead.
void dbgln(const glcr::StringBuilder& builder);
template <typename... Args>
void dbgln(const glcr::StringView& fmt, Args... args) {
dbgln(StrFormat(fmt, args...));
}
// Checks that the code is ok. // Checks that the code is ok.
// if not exits the process. // if not exits the process.

View File

@ -1,27 +1,11 @@
#include "include/mammoth/debug.h" #include "include/mammoth/debug.h"
#include <glacier/status/error.h> #include <glacier/status/error.h>
#include <stdarg.h>
#include <stdio.h>
#include <zcall.h> #include <zcall.h>
void dbgln_internal(const char* str) { // Safe to ignore the result since right void dbgln(const glcr::StringBuilder& builder) {
// now this doesn't throw. glcr::String str = builder.ToString();
uint64_t _ = ZDebug(str); (void)ZDebug(str.cstr());
}
void dbgln(const char* fmt, ...) {
char str[1024];
va_list arg;
va_start(arg, fmt);
int ret = vsprintf(str, fmt, arg);
va_end(arg);
if (ret == -1 || ret > 1024) {
crash("Bad vsprintf", 1);
}
dbgln_internal(str);
} }
void check(uint64_t code) { void check(uint64_t code) {
@ -44,10 +28,10 @@ void check(uint64_t code) {
dbgln("Unhandled code"); dbgln("Unhandled code");
break; break;
} }
ZProcessExit(code); (void)ZProcessExit(code);
} }
void crash(const char* str, uint64_t code) { void crash(const char* str, uint64_t code) {
dbgln(str); dbgln(str);
ZProcessExit(code); (void)ZProcessExit(code);
} }

View File

@ -26,7 +26,7 @@ void EndpointServer::ServerThread() {
ZEndpointRecv(endpoint_cap_, &message_size, recieve_buffer_, &num_caps, ZEndpointRecv(endpoint_cap_, &message_size, recieve_buffer_, &num_caps,
nullptr, &reply_port_cap)); nullptr, &reply_port_cap));
if (err != glcr::OK) { if (err != glcr::OK) {
dbgln("Error in receive: %x", err); dbgln("Error in receive: {x}", err);
continue; continue;
} }
@ -35,7 +35,7 @@ void EndpointServer::ServerThread() {
// FIXME: Consider pumping these errors into the response as well. // FIXME: Consider pumping these errors into the response as well.
check(HandleRequest(request, response)); check(HandleRequest(request, response));
if (!response.HasWritten()) { if (!response.HasWritten()) {
dbgln("Returning without having written a response. Req type %x", dbgln("Returning without having written a response. Req type {x}",
request.request_id()); request.request_id());
} }
} }

View File

@ -23,30 +23,25 @@ z_err_t ParseInitPort(uint64_t init_port_cap) {
RET_ERR(ret); RET_ERR(ret);
switch (init_sig) { switch (init_sig) {
case Z_INIT_SELF_PROC: case Z_INIT_SELF_PROC:
dbgln("received proc");
gSelfProcCap = init_cap; gSelfProcCap = init_cap;
break; break;
case Z_INIT_SELF_VMAS: case Z_INIT_SELF_VMAS:
dbgln("received vmas");
gSelfVmasCap = init_cap; gSelfVmasCap = init_cap;
break; break;
case Z_INIT_ENDPOINT: case Z_INIT_ENDPOINT:
gInitEndpointCap = init_cap; gInitEndpointCap = init_cap;
break; break;
case Z_BOOT_DENALI_VMMO: case Z_BOOT_DENALI_VMMO:
dbgln("received denali");
gBootDenaliVmmoCap = init_cap; gBootDenaliVmmoCap = init_cap;
break; break;
case Z_BOOT_VICTORIA_FALLS_VMMO: case Z_BOOT_VICTORIA_FALLS_VMMO:
dbgln("received victoria falls");
gBootVictoriaFallsVmmoCap = init_cap; gBootVictoriaFallsVmmoCap = init_cap;
break; break;
case Z_BOOT_PCI_VMMO: case Z_BOOT_PCI_VMMO:
dbgln("received pci");
gBootPciVmmoCap = init_cap; gBootPciVmmoCap = init_cap;
break; break;
default: default:
dbgln("Unexpected init type %x, continuing.", init_sig); dbgln("Unexpected init type {}, continuing.", init_sig);
} }
} }

View File

@ -56,20 +56,20 @@ glcr::ErrorCode AhciDevice::IssueCommand(Command* command) {
} }
void AhciDevice::DumpInfo() { void AhciDevice::DumpInfo() {
dbgln("Comlist: %lx", port_struct_->command_list_base); dbgln("Comlist: {x}", port_struct_->command_list_base);
dbgln("FIS: %lx", port_struct_->fis_base); dbgln("FIS: {x}", port_struct_->fis_base);
dbgln("Command: %x", port_struct_->command); dbgln("Command: {x}", port_struct_->command);
dbgln("Signature: %x", port_struct_->signature); dbgln("Signature: {x}", port_struct_->signature);
dbgln("SATA status: %x", port_struct_->sata_status); dbgln("SATA status: {x}", port_struct_->sata_status);
dbgln("Int status: %x", port_struct_->interrupt_status); dbgln("Int status: {x}", port_struct_->interrupt_status);
dbgln("Int enable: %x", port_struct_->interrupt_enable); dbgln("Int enable: {x}", port_struct_->interrupt_enable);
// Just dump one command info for now. // Just dump one command info for now.
for (uint64_t i = 0; i < 32; i++) { for (uint64_t i = 0; i < 32; i++) {
dbgln("Command Header: %u", i); dbgln("Command Header: {}", i);
dbgln("Command %x", command_list_->command_headers[i].command); dbgln("Command {x}", command_list_->command_headers[i].command);
dbgln("PRD Len: %x", command_list_->command_headers[i].prd_table_length); dbgln("PRD Len: {x}", command_list_->command_headers[i].prd_table_length);
dbgln("Command Table %lx", dbgln("Command Table {x}",
command_list_->command_headers[i].command_table_base_addr); command_list_->command_headers[i].command_table_base_addr);
} }
} }
@ -94,23 +94,27 @@ void AhciDevice::HandleIrq() {
// Device to host. // Device to host.
DeviceToHostRegisterFis& fis = received_fis_->device_to_host_register_fis; DeviceToHostRegisterFis& fis = received_fis_->device_to_host_register_fis;
if (fis.fis_type != FIS_TYPE_REG_D2H) { if (fis.fis_type != FIS_TYPE_REG_D2H) {
dbgln("BAD FIS TYPE (exp,act): %x, %x", FIS_TYPE_REG_D2H, fis.fis_type); dbgln("BAD FIS TYPE (exp,act): {x}, {x}",
static_cast<uint64_t>(FIS_TYPE_REG_D2H),
static_cast<uint64_t>(fis.fis_type));
return; return;
} }
if (fis.error) { if (fis.error) {
dbgln("D2H err: %x", fis.error); dbgln("D2H err: {x}", fis.error);
dbgln("status: %x", fis.status); dbgln("status: {x}", fis.status);
} }
} }
if (int_status & 0x2) { if (int_status & 0x2) {
// PIO. // PIO.
PioSetupFis& fis = received_fis_->pio_set_fis; PioSetupFis& fis = received_fis_->pio_set_fis;
if (fis.fis_type != FIS_TYPE_PIO_SETUP) { if (fis.fis_type != FIS_TYPE_PIO_SETUP) {
dbgln("BAD FIS TYPE (exp,act): %x, %x", FIS_TYPE_PIO_SETUP, fis.fis_type); dbgln("BAD FIS TYPE (exp,act): {x}, {x}",
static_cast<uint64_t>(FIS_TYPE_PIO_SETUP),
static_cast<uint64_t>(fis.fis_type));
return; return;
} }
if (fis.error) { if (fis.error) {
dbgln("PIO err: %x", fis.error); dbgln("PIO err: {x}", fis.error);
} }
} }
} }

View File

@ -75,7 +75,7 @@ void AhciDriver::DumpCapabilities() {
if (caps & 0x4'0000) { if (caps & 0x4'0000) {
dbgln("AHCI mode only"); dbgln("AHCI mode only");
} }
dbgln("Speed support: %u", (caps & 0xF0'0000) >> 20); dbgln("Speed support: {}", (caps & 0xF0'0000) >> 20);
if (caps & 0x100'0000) { if (caps & 0x100'0000) {
dbgln("Command list override"); dbgln("Command list override");
} }
@ -130,7 +130,7 @@ void AhciDriver::DumpPorts() {
} }
dbgln(""); dbgln("");
dbgln("Port %u:", i); dbgln("Port {}:", i);
dev->DumpInfo(); dev->DumpInfo();
} }
} }
@ -143,7 +143,7 @@ void AhciDriver::InterruptLoop() {
for (uint64_t i = 0; i < 32; i++) { for (uint64_t i = 0; i < 32; i++) {
if (devices_[i] != nullptr && devices_[i]->IsInit() && if (devices_[i] != nullptr && devices_[i]->IsInit() &&
(ahci_hba_->interrupt_status & (1 << i))) { (ahci_hba_->interrupt_status & (1 << i))) {
dbgln("Interrupt for %u", i); dbgln("Interrupt for {}", i);
devices_[i]->HandleIrq(); devices_[i]->HandleIrq();
ahci_hba_->interrupt_status &= ~(1 << i); ahci_hba_->interrupt_status &= ~(1 << i);
} }

View File

@ -63,23 +63,23 @@ glcr::ErrorOr<glcr::Vector<DirEntry>> Ext2Driver::ReadDirectory(
glcr::Vector<DirEntry> directory; glcr::Vector<DirEntry> directory;
for (uint64_t i = 0; i < real_block_cnt; i++) { for (uint64_t i = 0; i < real_block_cnt; i++) {
dbgln("Getting block %lx", inode->block[i]); dbgln("Getting block {x}", inode->block[i]);
ASSIGN_OR_RETURN(MappedMemoryRegion block, ASSIGN_OR_RETURN(MappedMemoryRegion block,
ext2_reader_->ReadBlock(inode->block[i])); ext2_reader_->ReadBlock(inode->block[i]));
uint64_t addr = block.vaddr(); uint64_t addr = block.vaddr();
while (addr < block.vaddr() + ext2_reader_->BlockSize()) { while (addr < block.vaddr() + ext2_reader_->BlockSize()) {
DirEntry* entry = reinterpret_cast<DirEntry*>(addr); DirEntry* entry = reinterpret_cast<DirEntry*>(addr);
directory.PushBack(*entry); directory.PushBack(*entry);
glcr::String name(entry->name, entry->name_len); glcr::StringView name(entry->name, entry->name_len);
switch (entry->file_type) { switch (entry->file_type) {
case kExt2FtFile: case kExt2FtFile:
dbgln("FILE (0x%x): %s", entry->inode, name.cstr()); dbgln("FILE (0x{x}): {}", entry->inode, name);
break; break;
case kExt2FtDirectory: case kExt2FtDirectory:
dbgln("DIR (0x%x): %s", entry->inode, name.cstr()); dbgln("DIR (0x{x}): {}", entry->inode, name);
break; break;
default: default:
dbgln("UNK (0x%x): %s", entry->inode, name.cstr()); dbgln("UNK (0x{x}): {}", entry->inode, name);
} }
addr += entry->record_length; addr += entry->record_length;
} }

View File

@ -15,7 +15,7 @@ uint64_t main(uint64_t init_cap) {
Empty empty; Empty empty;
DenaliInfo denali_info; DenaliInfo denali_info;
RET_ERR(yellowstone.GetDenali(empty, denali_info)); RET_ERR(yellowstone.GetDenali(empty, denali_info));
dbgln("LBA (recv): %u", denali_info.lba_offset()); dbgln("LBA (recv): {x}", denali_info.lba_offset());
ScopedDenaliClient denali(denali_info.denali_endpoint(), ScopedDenaliClient denali(denali_info.denali_endpoint(),
denali_info.device_id(), denali_info.lba_offset()); denali_info.device_id(), denali_info.lba_offset());
ASSIGN_OR_RETURN(Ext2Driver ext2, Ext2Driver::Init(glcr::Move(denali))); ASSIGN_OR_RETURN(Ext2Driver ext2, Ext2Driver::Init(glcr::Move(denali)));

View File

@ -28,7 +28,7 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
ASSIGN_OR_RETURN(files, driver_.ReadDirectory(files.at(j).inode)); ASSIGN_OR_RETURN(files, driver_.ReadDirectory(files.at(j).inode));
} }
} }
dbgln("Directory '%s' not found.", glcr::String(path_tokens.at(i)).cstr()); dbgln("Directory '{}' not found.", glcr::String(path_tokens.at(i)).cstr());
return glcr::NOT_FOUND; return glcr::NOT_FOUND;
} }
@ -43,7 +43,7 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
} }
} }
if (!region) { if (!region) {
dbgln("File '%s' not found.", dbgln("File '{}' not found.",
glcr::String(path_tokens.at(path_tokens.size() - 1)).cstr()); glcr::String(path_tokens.at(path_tokens.size() - 1)).cstr());
} }

View File

@ -66,36 +66,36 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
MappedMemoryRegion::FromCapability(resp.memory()); MappedMemoryRegion::FromCapability(resp.memory());
uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE); uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE);
if (*mbr_sig != 0xAA55) { if (*mbr_sig != 0xAA55) {
dbgln("Invalid MBR Sig: %x", *mbr_sig); dbgln("Invalid MBR Sig: {x}", *mbr_sig);
return glcr::FAILED_PRECONDITION; return glcr::FAILED_PRECONDITION;
} }
MbrPartition* first_partition = MbrPartition* first_partition =
reinterpret_cast<MbrPartition*>(lba_1_and_2.vaddr() + 0x1BE); reinterpret_cast<MbrPartition*>(lba_1_and_2.vaddr() + 0x1BE);
if (first_partition->boot_indicator != 0) { if (first_partition->boot_indicator != 0) {
dbgln("Boot indicator set: %u", first_partition->boot_indicator); dbgln("Boot indicator set: {}", first_partition->boot_indicator);
return glcr::FAILED_PRECONDITION; return glcr::FAILED_PRECONDITION;
} }
if (first_partition->os_type != 0xEE) { if (first_partition->os_type != 0xEE) {
dbgln("Incorrect OS type: %x", first_partition->os_type); dbgln("Incorrect OS type: {x}", first_partition->os_type);
return glcr::FAILED_PRECONDITION; return glcr::FAILED_PRECONDITION;
} }
dbgln("LBAs: (%x, %x)", first_partition->starting_lba, dbgln("LBAs: ({x}, {x})", first_partition->starting_lba,
first_partition->ending_lba); first_partition->ending_lba);
// FIXME: Don't hardcode sector size. // FIXME: Don't hardcode sector size.
ParititionHeader* header = ParititionHeader* header =
reinterpret_cast<ParititionHeader*>(lba_1_and_2.vaddr() + 512); reinterpret_cast<ParititionHeader*>(lba_1_and_2.vaddr() + 512);
dbgln("signature %lx", header->signature); dbgln("signature {}", header->signature);
uint64_t num_partitions = header->num_partitions; uint64_t num_partitions = header->num_partitions;
uint64_t entry_size = header->parition_entry_size; uint64_t entry_size = header->parition_entry_size;
uint64_t num_blocks = (num_partitions * entry_size) / 512; uint64_t num_blocks = (num_partitions * entry_size) / 512;
dbgln("lba_partition_entries %lx", header->lba_partition_entries); dbgln("lba_partition_entries {x}", header->lba_partition_entries);
dbgln("num_partitions: %x", num_partitions); dbgln("num_partitions: {x}", num_partitions);
dbgln("partition_entry_size: %x", entry_size); dbgln("partition_entry_size: {x}", entry_size);
dbgln("Num blocks: %x", num_blocks); dbgln("Num blocks: {x}", num_blocks);
req.set_device_id(0); req.set_device_id(0);
req.set_lba(header->lba_partition_entries); req.set_lba(header->lba_partition_entries);
@ -108,11 +108,11 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
PartitionEntry* entry = reinterpret_cast<PartitionEntry*>( PartitionEntry* entry = reinterpret_cast<PartitionEntry*>(
part_table.vaddr() + (i * entry_size)); part_table.vaddr() + (i * entry_size));
if (entry->type_guid_low != 0 || entry->type_guid_high != 0) { if (entry->type_guid_low != 0 || entry->type_guid_high != 0) {
dbgln("Entry %u", i); dbgln("Entry {}", i);
dbgln("T Guid: %lx-%lx", entry->type_guid_high, entry->type_guid_low); dbgln("T Guid: {x}-{x}", entry->type_guid_high, entry->type_guid_low);
dbgln("P Guid: %lx-%lx", entry->part_guid_high, entry->part_guid_low); dbgln("P Guid: {x}-{x}", entry->part_guid_high, entry->part_guid_low);
dbgln("LBA: %lx, %lx", entry->lba_start, entry->lba_end); dbgln("LBA: {x}, {x}", entry->lba_start, entry->lba_end);
dbgln("Attrs: %lx", entry->attributes); dbgln("Attrs: {x}", entry->attributes);
// For now we hardcode these values to the type that is // For now we hardcode these values to the type that is
// created in our setup script. // created in our setup script.
// FIXME: Set up our own root partition type guid at some // FIXME: Set up our own root partition type guid at some

View File

@ -18,7 +18,7 @@ PciReader::PciReader() {
dbgln("Creating addr space"); dbgln("Creating addr space");
uint64_t vaddr; uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootPciVmmoCap, &vaddr)); check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootPciVmmoCap, &vaddr));
dbgln("Addr %lx", vaddr); dbgln("Addr {x}", vaddr);
dbgln("Dumping PCI"); dbgln("Dumping PCI");
PciDump(vaddr); PciDump(vaddr);
@ -41,8 +41,8 @@ void PciReader::FunctionDump(uint64_t base, uint64_t bus, uint64_t dev,
return; return;
} }
dbgln( dbgln(
"[%u.%u.%u] (Vendor, Device): (%x, %x), (Type, Class, Sub, PIF): (%u, " "[{}.{}.{}] (Vendor, Device): ({x}, {x}), (Type, Class, Sub, PIF): ({}, "
"%x, %x, %x)", "{x}, {x}, {x})",
bus, dev, fun, hdr->vendor_id, hdr->device_id, hdr->header_type, bus, dev, fun, hdr->vendor_id, hdr->device_id, hdr->header_type,
hdr->class_code, hdr->subclass, hdr->prog_interface); hdr->class_code, hdr->subclass, hdr->prog_interface);
@ -50,7 +50,7 @@ void PciReader::FunctionDump(uint64_t base, uint64_t bus, uint64_t dev,
dbgln("FIXME: Handle PCI to PCI bridge."); dbgln("FIXME: Handle PCI to PCI bridge.");
} }
if (hdr->class_code == 0x1) { if (hdr->class_code == 0x1) {
dbgln("SATA Device at: %lx", reinterpret_cast<uint64_t>(hdr) - base); dbgln("SATA Device at: {x}", reinterpret_cast<uint64_t>(hdr) - base);
achi_device_offset_ = reinterpret_cast<uint64_t>(hdr) - base; achi_device_offset_ = reinterpret_cast<uint64_t>(hdr) - base;
} }
} }

View File

@ -1,3 +1,4 @@
#include <glacier/string/str_format.h>
#include <mammoth/debug.h> #include <mammoth/debug.h>
#include <mammoth/endpoint_client.h> #include <mammoth/endpoint_client.h>
#include <mammoth/init.h> #include <mammoth/init.h>
@ -16,8 +17,8 @@ glcr::ErrorCode SpawnProcess(z_cap_t vmmo_cap, z_cap_t yellowstone_cap) {
} }
uint64_t main(uint64_t port_cap) { uint64_t main(uint64_t port_cap) {
dbgln("Yellowstone Initializing.");
check(ParseInitPort(port_cap)); check(ParseInitPort(port_cap));
dbgln("Yellowstone Initializing.");
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create()); ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
Thread server_thread = server->RunServer(); Thread server_thread = server->RunServer();
@ -45,7 +46,7 @@ uint64_t main(uint64_t port_cap) {
glcr::String file(reinterpret_cast<const char*>(filemem.vaddr()), glcr::String file(reinterpret_cast<const char*>(filemem.vaddr()),
response.size()); response.size());
dbgln("Test: '%s'", file.cstr()); dbgln("Test: '{}'", file.cstr());
check(server_thread.Join()); check(server_thread.Join());
dbgln("Yellowstone Finished Successfully."); dbgln("Yellowstone Finished Successfully.");

View File

@ -90,7 +90,7 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
vfs_client_ = glcr::MakeShared<VFSClient>(victoria_falls_cap_); vfs_client_ = glcr::MakeShared<VFSClient>(victoria_falls_cap_);
check(has_victoriafalls_mutex_.Release()); check(has_victoriafalls_mutex_.Release());
} else { } else {
dbgln("[WARN] Got endpoint cap type: %s", req.endpoint_name().cstr()); dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
} }
return glcr::OK; return glcr::OK;
} }

View File

@ -52,7 +52,7 @@ void {{interface.name}}ServerBase::ServerThread() {
recv_cap.Reset(); recv_cap.Reset();
glcr::ErrorCode recv_err = static_cast<glcr::ErrorCode>(ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap)); glcr::ErrorCode recv_err = static_cast<glcr::ErrorCode>(ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap));
if (recv_err != glcr::OK) { if (recv_err != glcr::OK) {
dbgln("Error in receive: %x", recv_err); dbgln("Error in receive: {x}", recv_err);
continue; continue;
} }
@ -69,7 +69,7 @@ void {{interface.name}}ServerBase::ServerThread() {
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr())); reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr()));
} }
if (reply_err != glcr::OK) { if (reply_err != glcr::OK) {
dbgln("Error in reply: %x", reply_err); dbgln("Error in reply: {x}", reply_err);
} }
} }