Files
RockOS/kernel/drivers/atapi/ata.h

93 lines
2.5 KiB
C
Raw Normal View History

2026-06-19 00:27:08 -05:00
#ifndef KATA_H
#define KATA_H
2026-06-20 21:02:59 -05:00
#ifndef __ASSEMBLER__
2026-06-19 00:27:08 -05:00
#include <stdint.h>
2026-06-20 21:02:59 -05:00
#endif
2026-06-19 00:27:08 -05:00
2026-06-20 21:02:59 -05:00
#define IDE_PRIMARY_IO_BASE 0x01F0
#define IDE_PRIMARY_CRTL_BASE 0x03F6
#define IDE_SECONDARY_IO_BASE 0x0170
#define IDE_SECONDARY_CRTL_BASE 0x0376
#define IDE_DRIVE_MASTER 0xA0
#define IDE_DRIVE_SLAVE 0xB0
#define IO_DATA_REG 0x0000
#define IO_ERROR_REG 0x0001
#define IO_FEATURE_REG 0x0001
#define IO_SECTOR_COUNT_REG 0x0002
#define IO_SECTOR_NUM_REG 0x0003
#define IO_LBA_LO_REG 0x0003
#define IO_CYL_LO_REG 0x0004
#define IO_LBA_MID_REG 0x0004
#define IO_LBA_HI_REG 0x0005
#define IO_CYL_HI_REG 0x0005
#define IO_DRIVE_SELECT_REG 0x0006
#define IO_STATUS_REG 0x0007
#define IO_CMD_REG 0x0007
2026-06-19 00:27:08 -05:00
#define CTRL_ALT_STATUS_REG 0x00
#define CTRL_DEV_CTRL_REG 0x00
#define CTRL_DRIVE_ADDR_REG 0x01
#define ERROR_REG_AMNF 0b00000001 // Address mark not found
#define ERROR_REG_TKZNF 0b00000010 // Track zero not found
#define ERROR_REG_ABRT 0b00000100 // Aborted command
#define ERROR_REG_MCR 0b00001000 // Media change request
#define ERROR_REG_IDNF 0b00010000 // ID not found
#define ERROR_REG_MC 0b00100000 // Media changed
#define ERROR_REG_UNC 0b01000000 // Uncorrectable data error
#define ERROR_REG_BBK 0b10000000 // Bad Block detected
#define DRIVE_SELECT_REG_BN 0b00000111
#define DRIVE_SELECT_REG_DRV 0b00010000
#define DRIVE_SELECT_REG_LBAA 0b01000000
#define STATUS_REG_ERR 0b00000001
#define STATUS_REG_IDX 0b00000010
#define STATUS_REG_CORR 0b00000100
#define STATUS_REG_DRQ 0b00001000
#define STATUS_REG_SRV 0b00010000
#define STATUS_REG_DF 0b00100000
#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_HOB 0b10000000
2026-06-20 21:02:59 -05:00
#define DRIVE_ADDR_REG_DS0 0b00000001
#define DRIVE_ADDR_REG_DS1 0b00000010
#define DRIVE_ADDR_REG_HEAD 0b00111100
#define DRIVE_ADDR_REG_WTG 0b01000000
#define ATAPI_CMD_IDENTIFY_PACKET 0xA1
#ifndef __ASSEMBLER__
uint8_t ident_device(uint16_t bus, uint8_t drive_select, uint8_t* buffer);
typedef struct __attribute__((packed)) {
uint16_t bus;
uint8_t device;
uint8_t type;
void* ident_info_struct;
} ide_device_t;
typedef struct __attribute__((packed)) {
uint16_t gen_config;
uint16_t reserved_1[9];
char serial_number[20];
uint16_t vendor_1[3];
char firmware_v[8];
char model_num[40];
uint16_t vendor_2[2];
uint16_t capabilities;
uint16_t reserved_2;
uint16_t pio_dma_timing;
} atapi_identify_data_t;
#endif
2026-06-19 00:27:08 -05:00
#endif