From 6307b0168978f7df99a7ea747c00f8e9c7624a39 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 13 May 2023 16:34:18 +0200 Subject: [PATCH] kernel/ATA: Read ATA strings properly instead of backwards Now we can see the model string. What does it say... "QEMU DVD-ROM". Let's go! --- kernel/src/arch/x86_64/disk/ATA.cpp | 20 +++++++++++++++++--- libluna/include/luna/StaticString.h | 10 ++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/kernel/src/arch/x86_64/disk/ATA.cpp b/kernel/src/arch/x86_64/disk/ATA.cpp index 5f84bd68..4229322c 100644 --- a/kernel/src/arch/x86_64/disk/ATA.cpp +++ b/kernel/src/arch/x86_64/disk/ATA.cpp @@ -12,6 +12,20 @@ static void irq_handler(Registers* regs, void* ctx) ((ATA::Channel*)ctx)->irq_handler(regs); } +static usize copy_ata_string(char* out, u16* in, usize size) +{ + for (usize i = 0; i < size; i += 2) + { + u16 val = in[i / 2]; + out[i] = (u8)(val >> 8); + out[i + 1] = (u8)(val & 0xff); + } + + out[size + 1] = '\0'; + + return size; +} + namespace ATA { Result Controller::scan() @@ -275,9 +289,9 @@ namespace ATA if (!identify_ata()) return false; - m_serial = StringView::from_fixed_size_cstring((const char*)&m_identify_words[10], SERIAL_LEN); - m_revision = StringView::from_fixed_size_cstring((const char*)&m_identify_words[23], REVISION_LEN); - m_model = StringView::from_fixed_size_cstring((const char*)&m_identify_words[27], MODEL_LEN); + m_serial.set_length(copy_ata_string(m_serial.data(), &m_identify_words[10], SERIAL_LEN)); + m_revision.set_length(copy_ata_string(m_revision.data(), &m_identify_words[23], REVISION_LEN)); + m_model.set_length(copy_ata_string(m_model.data(), &m_identify_words[27], MODEL_LEN)); m_serial.trim(" "); m_revision.trim(" "); diff --git a/libluna/include/luna/StaticString.h b/libluna/include/luna/StaticString.h index cc1835fd..33e79b11 100644 --- a/libluna/include/luna/StaticString.h +++ b/libluna/include/luna/StaticString.h @@ -62,6 +62,16 @@ template class StaticString return m_buffer; } + char* data() + { + return m_buffer; + } + + void set_length(usize len) + { + m_length = len; + } + usize length() const { return m_length;