#ifndef _HD_H
#define _HD_H

// header file for harddisk driver.

// ports for Primary/Secondary ATA bus
#define PRIMARY_BASE		0x1F0	// base port of the Primary ATA bus
#define SECONDARY_BASE		0x170	// base port of the Secondary ATA bus

// use these with PRIMARY/SECONDARY_BASE.
// NOTE: even if PRIMARY/SECONDARY_BASE is actually the data port, still use
// ATA_DATA macro for readability.
#define ATA_DATA(x)		(x+0)	// Read or write PIO data bytes here
#define ATA_FEATURES(x)		(x+1)	// Features or error information, usually used for ATAPI devices
#define ATA_SECTOR_COUNT(x)	(x+2)	// Number of sectors to read or write
#define ATA_SECTOR_NUM(x)	(x+3)	// CHS/LBA28/LBA48 specific, or LBAlo
#define ATA_CYLINDER_LOW(x)	(x+4)	// Partial disk sector address, or LBAmid
#define ATA_CYLINDER_HI(x)	(x+5)	// Partial disk sector address, or LBAhi
#define ATA_DRIVE(x)		(x+6)	// Select a drive and/or head here
#define ATA_COMMAND(x)		(x+7)	// Send commands or read Regular Status here

// these are for use with the Status Byte.
// Use like so:
// if (status_byte & (1 << ATA_DRQ))
// These can also be or'd together to check more than one at once.  Example:
// if (!(status_byte & ((1 << ATA_ERR) | (1 << ATA_DF))))
#define ATA_ERR			0	// Indicates an error occurred
#define ATA_DRQ			3	// Drive has PIO data to transfer, or it can accept PIO data.
#define ATA_SRV			4	// Overlapped Mode service request.
#define ATA_DF			5	// Drive Fault Error
#define ATA_RDY			6	// Clear when drive is spun down or after error
#define ATA_BSY			7	// Drive is preparing to send or receive data (wait for this to clear)

#define FLOATING_BUS		0xFF	// if reading Regular Status returns this, that means that no drives are connected.

// these are numbers for drive commands
#define ATA_IDENTIFY		1

// these are flag bits for send_command()
// use like above
#define ATA_CONTROLLER		0	// set for Primary, clear for Secondary
#define ATA_SLAVE		1	// set to select Slave, clear to select Master

extern void hd_install(void);

#endif
