atabasedevice: add ATAPI signature at device reset.

This commit is contained in:
Maxim Poliakovski 2022-12-12 15:07:19 +01:00
parent 52bb87b72a
commit dee225ee8f
4 changed files with 24 additions and 10 deletions

View File

@ -38,7 +38,7 @@ AtaBaseDevice::AtaBaseDevice(const std::string name)
device_reset();
}
void AtaBaseDevice::device_reset()
void AtaBaseDevice::device_reset(const uint8_t dev_head_val)
{
this->r_error = 1; // Device 0 passed, Device 1 passed or not present
@ -46,11 +46,17 @@ void AtaBaseDevice::device_reset()
this->r_sect_num = 1;
this->r_dev_ctrl = 0;
// set ATA protocol signature
this->r_cylinder_lo = 0;
this->r_cylinder_hi = 0;
this->r_dev_head = 0; // TODO: ATAPI devices shouldn't change this reg!
this->r_status = DRDY | DSC;
// set protocol signature
if (this->device_type == DEVICE_TYPE_ATAPI) {
this->r_cylinder_lo = 0x14;
this->r_cylinder_hi = 0xEB;
this->r_dev_head = dev_head_val;
} else { // assume ATA by default
this->r_cylinder_lo = 0;
this->r_cylinder_hi = 0;
this->r_dev_head = 0;
this->r_status = DRDY | DSC;
}
}
uint16_t AtaBaseDevice::read(const uint8_t reg_addr) {

View File

@ -42,13 +42,14 @@ public:
int get_device_id() { return this->my_dev_id; };
void device_reset();
void device_reset(const uint8_t dev_head_val = 0);
private:
bool is_selected() { return ((this->r_dev_head >> 4) & 1) == this->my_dev_id; };
protected:
uint8_t my_dev_id = 0; // my IDE device ID configured by the host
uint8_t device_type = ata_interface::DEVICE_TYPE_UNKNOWN;
// IDE aka task file registers
uint8_t r_error;

View File

@ -35,6 +35,13 @@ enum {
DEVICE_ID_ONE = 1
};
/** Device types. */
enum {
DEVICE_TYPE_UNKNOWN = -1,
DEVICE_TYPE_ATA = 0,
DEVICE_TYPE_ATAPI = 1,
};
/** ATA register offsets. */
enum ATA_Reg : int {
DATA = 0x0,
@ -49,7 +56,7 @@ enum ATA_Reg : int {
COMMAND = 0x7, // command (write)
ALT_STATUS = 0x16, // alt status (read)
DEV_CTRL = 0x16, // device control (write)
TIME_CONFIG = 0x20
TIME_CONFIG = 0x20 // Apple ASIC specific timing configuration
};
/** Status register bits. */

View File

@ -41,7 +41,7 @@ void AtaHardDisk::insert_image(std::string filename) {
if (!rc) {
this->img_size = stat_buf.st_size;
} else {
ABORT_F("ScsiHardDisk: could not determine file size using stat()");
ABORT_F("AtaHardDisk: could not determine file size using stat()");
}
this->hdd_img.seekg(0, std::ios_base::beg);
}
@ -51,7 +51,7 @@ int AtaHardDisk::perform_command()
LOG_F(INFO, "%s: command 0x%x requested", this->name.c_str(), this->r_command);
this->r_status |= BSY;
this->r_status &= ~(DRDY);
switch (this->r_command) {
switch (this->r_command) {
case NOP:
break;
case RESET_ATAPI: {