Clean up ATA interface.

This commit is contained in:
Maxim Poliakovski 2022-12-08 08:04:09 +01:00
parent df1a56305a
commit 2537751fa7
3 changed files with 16 additions and 10 deletions

View File

@ -28,9 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes> #include <cinttypes>
#define sector_size 512 using namespace ata_interface;
using namespace std;
AtaBaseDevice::AtaBaseDevice(const std::string name) AtaBaseDevice::AtaBaseDevice(const std::string name)
{ {
@ -46,16 +44,18 @@ void AtaBaseDevice::device_reset()
this->r_sect_count = 1; this->r_sect_count = 1;
this->r_sect_num = 1; this->r_sect_num = 1;
this->r_dev_ctrl = 0;
// set ATA protocol signature // set ATA protocol signature
this->r_cylinder_lo = 0; this->r_cylinder_lo = 0;
this->r_cylinder_hi = 0; this->r_cylinder_hi = 0;
this->r_dev_head = 0; // TODO: ATAPI devices shouldn't change this reg!
this->r_status = IDE_Status::DRDY | IDE_Status::DSC; this->r_status = IDE_Status::DRDY | IDE_Status::DSC;
} }
uint16_t AtaBaseDevice::read(const uint8_t reg_addr) { uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
switch (reg_addr) { switch (reg_addr) {
case IDE_Reg::IDE_DATA: case IDE_Reg::DATA:
LOG_F(WARNING, "Retrieving data from %s", this->name.c_str()); LOG_F(WARNING, "Retrieving data from %s", this->name.c_str());
return 0xFFFFU; return 0xFFFFU;
case IDE_Reg::ERROR: case IDE_Reg::ERROR:
@ -83,7 +83,7 @@ uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {
void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) { void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
switch (reg_addr) { switch (reg_addr) {
case IDE_Reg::IDE_DATA: case IDE_Reg::DATA:
LOG_F(WARNING, "Pushing data to %s", this->name.c_str()); LOG_F(WARNING, "Pushing data to %s", this->name.c_str());
break; break;
case IDE_Reg::FEATURES: case IDE_Reg::FEATURES:
@ -106,7 +106,7 @@ void AtaBaseDevice::write(const uint8_t reg_addr, const uint16_t value) {
break; break;
case IDE_Reg::COMMAND: case IDE_Reg::COMMAND:
this->r_command = value; this->r_command = value;
if (is_selected()) { if (is_selected() || this->r_command == IDE_Cmd::DIAGNOSTICS) {
perform_command(); perform_command();
} }
break; break;

View File

@ -26,9 +26,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <cinttypes> #include <cinttypes>
/** IDE register offsets. */ namespace ata_interface {
/** ATA register offsets. */
enum IDE_Reg : int { enum IDE_Reg : int {
IDE_DATA = 0x0, DATA = 0x0,
ERROR = 0x1, // error (read) ERROR = 0x1, // error (read)
FEATURES = 0x1, // features (write) FEATURES = 0x1, // features (write)
SEC_COUNT = 0x2, // sector count SEC_COUNT = 0x2, // sector count
@ -67,9 +69,9 @@ enum IDE_Error : int {
BBK = 0x80 BBK = 0x80
}; };
/** Heath IDE commands. */ /** ATA commands. */
enum IDE_Cmd : int { enum IDE_Cmd : int {
IDE_NOP = 0x00, NOP = 0x00,
RESET_ATAPI = 0x08, RESET_ATAPI = 0x08,
RECALIBRATE = 0x10, RECALIBRATE = 0x10,
READ_SECTOR = 0x20, READ_SECTOR = 0x20,
@ -83,6 +85,8 @@ enum IDE_Cmd : int {
WRITE_DMA = 0xCA, WRITE_DMA = 0xCA,
}; };
}; // namespace ata_interface
/** Interface for ATA devices. */ /** Interface for ATA devices. */
class AtaInterface { class AtaInterface {
public: public:

View File

@ -35,6 +35,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <memory> #include <memory>
#include <string> #include <string>
using namespace ata_interface;
IdeChannel::IdeChannel(const std::string name) IdeChannel::IdeChannel(const std::string name)
{ {
this->set_name(name); this->set_name(name);