desparate to get ata reads to work
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
|
||||
#define DRIVE_SELECT_REG_BN 0b00000111
|
||||
#define DRIVE_SELECT_REG_DRV 0b00010000
|
||||
#define DRIVE_SELECT_REG_LBAA 0b01000000
|
||||
#define DRIVE_SELECT_REG_LBA 0b01000000
|
||||
|
||||
#define STATUS_REG_ERR 0b00000001
|
||||
#define STATUS_REG_IDX 0b00000010
|
||||
@@ -55,8 +55,8 @@
|
||||
#define STATUS_REG_RDY 0b01000000
|
||||
#define STATUS_REG_BSY 0b10000000
|
||||
|
||||
#define DEV_CTRL_REG_nIEN 0b00000001
|
||||
#define DEV_CTRL_REG_SRST 0b00000010
|
||||
#define DEV_CTRL_REG_nIEN 0b00000010
|
||||
#define DEV_CTRL_REG_SRST 0b00000100
|
||||
#define DEV_CTRL_REG_HOB 0b10000000
|
||||
|
||||
#define DRIVE_ADDR_REG_DS0 0b00000001
|
||||
@@ -64,148 +64,61 @@
|
||||
#define DRIVE_ADDR_REG_HEAD 0b00111100
|
||||
#define DRIVE_ADDR_REG_WTG 0b01000000
|
||||
|
||||
#define ATAPI_CMD_IDENTIFY_PACKET 0xA1
|
||||
#define ATA_CMD_READ_PIO 0x20
|
||||
#define ATA_CMD_READ_PIO_EXT 0x24
|
||||
#define ATA_CMD_READ_DMA 0xC8
|
||||
#define ATA_CMD_READ_DMA_EXT 0x25
|
||||
#define ATA_CMD_WRITE_PIO 0x30
|
||||
#define ATA_CMD_WRITE_PIO_EXT 0x34
|
||||
#define ATA_CMD_WRITE_DMA 0xCA
|
||||
#define ATA_CMD_WRITE_DMA_EXT 0x35
|
||||
#define ATA_CMD_CACHE_FLUSH 0xE7
|
||||
#define ATA_CMD_CACHE_FLUSH_EXT 0xEA
|
||||
#define ATA_CMD_PACKET 0xA0
|
||||
#define ATA_CMD_IDENTIFY_PACKET 0xA1
|
||||
#define ATA_CMD_IDENTIFY 0xEC
|
||||
|
||||
#define ATAPI_CMD_READ 0xA8
|
||||
#define ATAPI_CMD_EJECT 0x1B
|
||||
|
||||
#define ATA_IDENT_DEVICETYPE 0
|
||||
#define ATA_IDENT_CYLINDERS 2
|
||||
#define ATA_IDENT_HEADS 6
|
||||
#define ATA_IDENT_SECTORS 12
|
||||
#define ATA_IDENT_SERIAL 20
|
||||
#define ATA_IDENT_MODEL 54
|
||||
#define ATA_IDENT_MODEL_SZ 40
|
||||
#define ATA_IDENT_CAPABILITIES 98
|
||||
#define ATA_IDENT_FIELDVALID 106
|
||||
#define ATA_IDENT_MAX_LBA 120
|
||||
#define ATA_IDENT_COMMANDSETS 164
|
||||
#define ATA_IDENT_MAX_LBA_EXT 200
|
||||
|
||||
#ifndef __ASSEMBLER__
|
||||
uint8_t ident_device(uint16_t bus, uint8_t drive_select, uint8_t* buffer);
|
||||
int read_atapi(uint16_t bus, uint8_t drive, uint32_t lba, uint32_t sectors, uint16_t* buf);
|
||||
void send_scsi_packet(uint16_t bus, void* cmd, size_t sz);
|
||||
void read_data_words(uint16_t bus, void* buf, size_t sz);
|
||||
typedef enum {
|
||||
NO_DEVICE = 0,
|
||||
ATA,
|
||||
ATAPI,
|
||||
} ide_dev_type;
|
||||
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t bus;
|
||||
uint8_t device;
|
||||
uint8_t type;
|
||||
void* ident_info_struct;
|
||||
ide_dev_type type;
|
||||
uint16_t sig;
|
||||
uint16_t capabilities;
|
||||
uint32_t command_set;
|
||||
char* serial;
|
||||
char* model;
|
||||
uint32_t size;
|
||||
} ide_device_t;
|
||||
|
||||
typedef struct {
|
||||
// Word 0: General configuration bit-map
|
||||
struct {
|
||||
uint16_t packet_size : 2; // 00=12 bytes, 01=16 bytes
|
||||
uint16_t reserved1 : 3;
|
||||
uint16_t drq_response : 2; // DRQ response microsecond timing
|
||||
uint16_t device_type : 5; // Device type (e.g., 0x05 for CD/DVD-ROM)
|
||||
uint16_t reserved2 : 1;
|
||||
uint16_t removable_media : 1; // 1 = Removable media
|
||||
uint16_t command_packet_type : 2; // 10 = ATAPI device
|
||||
} general_config;
|
||||
int select_drive(uint16_t bus, uint8_t drive);
|
||||
void ident_device(uint16_t bus, uint8_t drive, uint32_t slot);
|
||||
void scan_drives();
|
||||
|
||||
uint16_t logical_cylinders;
|
||||
uint16_t specific_configuration; // Word 2: Specific configuration
|
||||
uint16_t logical_heads; // Word 3: Obsolete / Reserved
|
||||
uint16_t retired1[2]; // Words 4-5: Retired
|
||||
|
||||
uint16_t logical_sectors_per_track; // Word 6: Obsolete / Reserved
|
||||
uint16_t reserved_vendor[3]; // Words 7-9: Vendor specific
|
||||
|
||||
char serial_number[20]; // Words 10-19: Serial number (ASCII, byte-swapped)
|
||||
uint16_t retired2[2]; // Words 20-21: Retired
|
||||
uint16_t obsolete1; // Word 22: Obsolete
|
||||
|
||||
char firmware_revision[8]; // Words 23-26: Firmware revision (ASCII, byte-swapped)
|
||||
char model_number[40]; // Words 27-46: Model number (ASCII, byte-swapped)
|
||||
|
||||
uint16_t sectors_per_interrupt; // Word 47: Bits 7:0 = Max sectors per interrupt
|
||||
uint16_t reserved3; // Word 48: Reserved
|
||||
|
||||
// Word 49: Capabilities
|
||||
struct {
|
||||
uint16_t reserved1 : 8;
|
||||
uint16_t dma_supported : 1; // 1 = DMA supported
|
||||
uint16_t lba_supported : 1; // 1 = LBA supported
|
||||
uint16_t iordy_disable : 1; // 1 = IORDY can be disabled
|
||||
uint16_t iordy_supported : 1; // 1 = IORDY supported
|
||||
uint16_t reserved2 : 1;
|
||||
uint16_t overlap_supported : 1; // 1 = Overlap operation supported
|
||||
uint16_t reserved3 : 2;
|
||||
} capabilities1;
|
||||
|
||||
uint16_t capabilities2; // Word 50: Capabilities bit 0 = Min MDMA cycle time info
|
||||
uint16_t pio_data_transfer_timing;// Word 51: Obsolete
|
||||
uint16_t dma_data_transfer_timing;// Word 52: Obsolete
|
||||
|
||||
// Word 53: Field validity
|
||||
struct {
|
||||
uint16_t fields_54_58_valid : 1; // 1 = Words 54-58 are valid
|
||||
uint16_t fields_64_70_valid : 1; // 1 = Words 64-70 are valid
|
||||
uint16_t field_88_valid : 1; // 1 = Word 88 is valid (Ultra DMA)
|
||||
uint16_t reserved : 13;
|
||||
} field_validity;
|
||||
|
||||
uint16_t obsolete2[5]; // Words 54-58: Obsolete
|
||||
uint16_t multi_sector_setting; // Word 59: Multi-sector setting
|
||||
uint32_t total_addressable_sectors; // Words 60-61: Total number of user addressable sectors (LBA28)
|
||||
uint16_t single_word_dma_modes;
|
||||
uint16_t multi_word_dma_modes;
|
||||
|
||||
struct {
|
||||
uint16_t pio_mode_3 : 1;
|
||||
uint16_t pio_mode_4 : 1;
|
||||
uint16_t reserved : 14;
|
||||
} advanced_pio_modes;
|
||||
|
||||
uint16_t min_mwdma_cycle_time;
|
||||
uint16_t rec_mwdma_cycle_time;
|
||||
uint16_t min_pio_cycle_time_no_flow;
|
||||
uint16_t min_pio_cycle_time_iordy;
|
||||
uint16_t reserved4[2];
|
||||
|
||||
uint16_t packet_release_time;
|
||||
uint16_t service_clear_time;
|
||||
uint16_t major_revision_number;
|
||||
uint16_t minor_revision_number;
|
||||
|
||||
uint16_t queue_depth;
|
||||
uint16_t reserved5[4];
|
||||
|
||||
uint16_t major_version;
|
||||
uint16_t minor_version;
|
||||
|
||||
uint16_t command_sets_supported1;
|
||||
uint16_t command_sets_supported2;
|
||||
uint16_t command_sets_supported3;
|
||||
|
||||
uint16_t command_sets_enabled1;
|
||||
uint16_t command_sets_enabled2;
|
||||
uint16_t command_sets_enabled3;
|
||||
|
||||
uint16_t ultra_dma_modes;
|
||||
uint16_t reserved_erase_time[2];
|
||||
uint16_t current_apm_level;
|
||||
uint16_t master_password_revision;
|
||||
uint16_t hardware_reset_result;
|
||||
uint16_t obsolete3;
|
||||
uint16_t stream_minimum_request;
|
||||
uint16_t streaming_transfer_delay;
|
||||
uint16_t streaming_access_latency;
|
||||
uint32_t streaming_perf_granularity;
|
||||
|
||||
uint64_t total_user_sectors_lba48;
|
||||
uint16_t streaming_transfer_delay_block;
|
||||
uint16_t reserved6;
|
||||
|
||||
struct {
|
||||
uint16_t logical_sectors_per_physical : 4;
|
||||
uint16_t reserved1 : 8;
|
||||
uint16_t logical_sector_longer_than_256: 1;
|
||||
uint16_t physical_sector_longer_than_logical: 1;
|
||||
uint16_t validation_bits : 2;
|
||||
} physical_sector_size;
|
||||
|
||||
uint16_t inter_seek_delay;
|
||||
uint16_t world_wide_name[4];
|
||||
uint16_t reserved7[8];
|
||||
uint16_t command_submission_delay;
|
||||
uint16_t reserved8[7];
|
||||
uint16_t security_status;
|
||||
uint16_t vendor_specific[31];
|
||||
uint16_t cfa_power_mode;
|
||||
uint16_t reserved9[15];
|
||||
char media_serial_number[60];
|
||||
uint16_t sct_command_transport;
|
||||
uint16_t reserved10[49];
|
||||
} __attribute__((packed)) atapi_identify_t;
|
||||
void ide_invoke_irq();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user