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!
This commit is contained in:
apio 2023-05-13 16:34:18 +02:00
parent e118c9ea0d
commit 6307b01689
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 27 additions and 3 deletions

View File

@ -12,6 +12,20 @@ static void irq_handler(Registers* regs, void* ctx)
((ATA::Channel*)ctx)->irq_handler(regs); ((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 namespace ATA
{ {
Result<void> Controller::scan() Result<void> Controller::scan()
@ -275,9 +289,9 @@ namespace ATA
if (!identify_ata()) return false; if (!identify_ata()) return false;
m_serial = StringView::from_fixed_size_cstring((const char*)&m_identify_words[10], SERIAL_LEN); m_serial.set_length(copy_ata_string(m_serial.data(), &m_identify_words[10], SERIAL_LEN));
m_revision = StringView::from_fixed_size_cstring((const char*)&m_identify_words[23], REVISION_LEN); m_revision.set_length(copy_ata_string(m_revision.data(), &m_identify_words[23], REVISION_LEN));
m_model = StringView::from_fixed_size_cstring((const char*)&m_identify_words[27], MODEL_LEN); m_model.set_length(copy_ata_string(m_model.data(), &m_identify_words[27], MODEL_LEN));
m_serial.trim(" "); m_serial.trim(" ");
m_revision.trim(" "); m_revision.trim(" ");

View File

@ -62,6 +62,16 @@ template <usize Size> class StaticString
return m_buffer; return m_buffer;
} }
char* data()
{
return m_buffer;
}
void set_length(usize len)
{
m_length = len;
}
usize length() const usize length() const
{ {
return m_length; return m_length;