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

@ -56,20 +56,20 @@ glcr::ErrorCode AhciDevice::IssueCommand(Command* command) {
}
void AhciDevice::DumpInfo() {
dbgln("Comlist: %lx", port_struct_->command_list_base);
dbgln("FIS: %lx", port_struct_->fis_base);
dbgln("Command: %x", port_struct_->command);
dbgln("Signature: %x", port_struct_->signature);
dbgln("SATA status: %x", port_struct_->sata_status);
dbgln("Int status: %x", port_struct_->interrupt_status);
dbgln("Int enable: %x", port_struct_->interrupt_enable);
dbgln("Comlist: {x}", port_struct_->command_list_base);
dbgln("FIS: {x}", port_struct_->fis_base);
dbgln("Command: {x}", port_struct_->command);
dbgln("Signature: {x}", port_struct_->signature);
dbgln("SATA status: {x}", port_struct_->sata_status);
dbgln("Int status: {x}", port_struct_->interrupt_status);
dbgln("Int enable: {x}", port_struct_->interrupt_enable);
// Just dump one command info for now.
for (uint64_t i = 0; i < 32; i++) {
dbgln("Command Header: %u", i);
dbgln("Command %x", command_list_->command_headers[i].command);
dbgln("PRD Len: %x", command_list_->command_headers[i].prd_table_length);
dbgln("Command Table %lx",
dbgln("Command Header: {}", i);
dbgln("Command {x}", command_list_->command_headers[i].command);
dbgln("PRD Len: {x}", command_list_->command_headers[i].prd_table_length);
dbgln("Command Table {x}",
command_list_->command_headers[i].command_table_base_addr);
}
}
@ -94,23 +94,27 @@ void AhciDevice::HandleIrq() {
// Device to host.
DeviceToHostRegisterFis& fis = received_fis_->device_to_host_register_fis;
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;
}
if (fis.error) {
dbgln("D2H err: %x", fis.error);
dbgln("status: %x", fis.status);
dbgln("D2H err: {x}", fis.error);
dbgln("status: {x}", fis.status);
}
}
if (int_status & 0x2) {
// PIO.
PioSetupFis& fis = received_fis_->pio_set_fis;
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;
}
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) {
dbgln("AHCI mode only");
}
dbgln("Speed support: %u", (caps & 0xF0'0000) >> 20);
dbgln("Speed support: {}", (caps & 0xF0'0000) >> 20);
if (caps & 0x100'0000) {
dbgln("Command list override");
}
@ -130,7 +130,7 @@ void AhciDriver::DumpPorts() {
}
dbgln("");
dbgln("Port %u:", i);
dbgln("Port {}:", i);
dev->DumpInfo();
}
}
@ -143,7 +143,7 @@ void AhciDriver::InterruptLoop() {
for (uint64_t i = 0; i < 32; i++) {
if (devices_[i] != nullptr && devices_[i]->IsInit() &&
(ahci_hba_->interrupt_status & (1 << i))) {
dbgln("Interrupt for %u", i);
dbgln("Interrupt for {}", i);
devices_[i]->HandleIrq();
ahci_hba_->interrupt_status &= ~(1 << i);
}

View file

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

View file

@ -15,7 +15,7 @@ uint64_t main(uint64_t init_cap) {
Empty empty;
DenaliInfo 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(),
denali_info.device_id(), denali_info.lba_offset());
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));
}
}
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;
}
@ -43,7 +43,7 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
}
}
if (!region) {
dbgln("File '%s' not found.",
dbgln("File '{}' not found.",
glcr::String(path_tokens.at(path_tokens.size() - 1)).cstr());
}

View file

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

View file

@ -18,7 +18,7 @@ PciReader::PciReader() {
dbgln("Creating addr space");
uint64_t vaddr;
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootPciVmmoCap, &vaddr));
dbgln("Addr %lx", vaddr);
dbgln("Addr {x}", vaddr);
dbgln("Dumping PCI");
PciDump(vaddr);
@ -41,8 +41,8 @@ void PciReader::FunctionDump(uint64_t base, uint64_t bus, uint64_t dev,
return;
}
dbgln(
"[%u.%u.%u] (Vendor, Device): (%x, %x), (Type, Class, Sub, PIF): (%u, "
"%x, %x, %x)",
"[{}.{}.{}] (Vendor, Device): ({x}, {x}), (Type, Class, Sub, PIF): ({}, "
"{x}, {x}, {x})",
bus, dev, fun, hdr->vendor_id, hdr->device_id, hdr->header_type,
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.");
}
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;
}
}

View file

@ -1,3 +1,4 @@
#include <glacier/string/str_format.h>
#include <mammoth/debug.h>
#include <mammoth/endpoint_client.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) {
dbgln("Yellowstone Initializing.");
check(ParseInitPort(port_cap));
dbgln("Yellowstone Initializing.");
ASSIGN_OR_RETURN(auto server, YellowstoneServer::Create());
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()),
response.size());
dbgln("Test: '%s'", file.cstr());
dbgln("Test: '{}'", file.cstr());
check(server_thread.Join());
dbgln("Yellowstone Finished Successfully.");

View file

@ -90,7 +90,7 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
vfs_client_ = glcr::MakeShared<VFSClient>(victoria_falls_cap_);
check(has_victoriafalls_mutex_.Release());
} 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;
}