Add ATA drive support #27

Merged
apio merged 28 commits from please-read-my-ata-drive into main 2023-06-16 19:40:11 +00:00
2 changed files with 27 additions and 3 deletions
Showing only changes of commit 6307b01689 - Show all commits

View File

@ -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<void> 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(" ");

View File

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