12using namespace MaxOS::common;
13using namespace MaxOS::hardwarecommunication;
14using namespace MaxOS::drivers;
15using namespace MaxOS::drivers::disk;
24 : m_data_port(port_base),
25 m_error_port(port_base + 1),
26 m_sector_count_port(port_base + 2),
27 m_LBA_low_port(port_base + 3),
28 m_LBA_mid_port(port_base + 4),
29 m_LBA_high_Port(port_base + 5),
30 m_device_port(port_base + 6),
31 m_command_port(port_base + 7),
32 m_control_port(port_base + 0x206),
37AdvancedTechnologyAttachment::~AdvancedTechnologyAttachment() =
default;
47 m_device_port.
write(m_is_master ? 0xA0 : 0xB0);
50 m_control_port.
write(0);
53 m_device_port.
write(0xA0);
61 m_device_port.
write(m_is_master ? 0xA0 : 0xB0);
64 m_sector_count_port.
write(0);
65 m_LBA_low_port.
write(0);
66 m_LBA_mid_port.
write(0);
67 m_LBA_high_Port.
write(0);
70 m_command_port.
write(0x0EC);
71 status = m_command_port.
read();
76 while (((status & 0x80) == 0x80) && ((status & 0x01) != 0x01))
77 status = m_command_port.
read();
110 m_device_port.
write((m_is_master ? 0xE0 : 0xF0) | ((
sector & 0x0F000000) >> 24));
113 while ((m_command_port.
read() & 0x80) != 0);
116 m_error_port.
write(0);
117 m_sector_count_port.
write(1);
122 m_LBA_high_Port.
write((
sector & 0x00FF0000) >> 16);
125 m_command_port.
write(0x20);
133 while (((status & 0x80) == 0x80) && ((status & 0x01) != 0x01))
134 status = m_command_port.
read();
140 for (
size_t i = 0; i <
amount; i += 2) {
166 if (
sector > 0x0FFFFFFF ||
count > m_bytes_per_sector)
170 m_device_port.
write(m_is_master ? 0xE0 : 0xF0 | ((
sector & 0x0F000000) >> 24));
173 while ((m_command_port.
read() & 0x80) != 0);
176 m_error_port.
write(0);
177 m_sector_count_port.
write(1);
182 m_LBA_high_Port.
write((
sector & 0x00FF0000) >> 16);
185 m_command_port.
write(0x30);
189 while ((status & 0x80) != 0 || (status & 0x08) == 0)
190 status = m_command_port.
read();
193 for (
size_t i = 0; i < m_bytes_per_sector; i += 2) {
205 for (
size_t i =
count + (
count % 2); i < m_bytes_per_sector; i += 2)
206 m_data_port.
write(0x0000);
209 status = m_command_port.
read();
210 while ((status & 0x80) != 0 || (status & 0x08) != 0)
211 status = m_command_port.
read();
222 m_device_port.
write(m_is_master ? 0xE0 : 0xF0);
225 m_command_port.
write(0xE7);
233 while (((status & 0x80) == 0x80) && ((status & 0x01) != 0x01))
234 status = m_command_port.
read();
249 return "Advanced Technology Attachment";
Driver for the ATA controller, handles the reading and writing of data to the hard drive.
static Logger WARNING()
Gets active logger set to WARNING level.
Wrapper class for a region of bytes in memor in an attempt to add some memory safety....
uint8_t read()
Safely reads a byte from the buffer at the current offset.
Stores the left, top, width and height of a rectangle.
AdvancedTechnologyAttachment(uint16_t port_base, bool master)
Constructor for the AdvancedTechnologyAttachment class.
bool identify()
Identify the ATA device.
string device_name() final
Get the device name.
void flush() final
Flush the cache of the ATA device.
void read(uint32_t sector, common::buffer_t *data_buffer, size_t amount) final
read a sector from the ATA device
string vendor_name() final
Get the vendor name.
void write(uint32_t sector, common::buffer_t *data, size_t count) final
write to a sector on the ATA device
virtual void write(uint16_t data)
write a word to the port
virtual uint16_t read()
read a word from the port
virtual uint8_t read()
read a byte from the port
virtual void write(uint8_t data)
write a byte to the port