From 650e1b4fc554799016284963922991968c650d9f Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 13 Jul 2023 15:53:09 +0300 Subject: [PATCH] Kernel: Fix bug which made bochs unbootable We could not boot if ATABus did not have valid primary device. --- kernel/kernel/Storage/ATABus.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/kernel/Storage/ATABus.cpp b/kernel/kernel/Storage/ATABus.cpp index bacd47eb4..fbb20c391 100644 --- a/kernel/kernel/Storage/ATABus.cpp +++ b/kernel/kernel/Storage/ATABus.cpp @@ -247,8 +247,11 @@ namespace Kernel uint8_t ATABus::device_index(const ATADevice& device) const { - ASSERT(&device == m_devices[0].ptr() || &device == m_devices[1].ptr()); - return (&device == m_devices[0].ptr()) ? 0 : 1; + if (m_devices[0] && m_devices[0].ptr() == &device) + return 0; + if (m_devices[1] && m_devices[1].ptr() == &device) + return 1; + ASSERT_NOT_REACHED(); } BAN::ErrorOr ATABus::read(ATADevice& device, uint64_t lba, uint8_t sector_count, uint8_t* buffer)