📄 ide.h
字号:
/***************************************************************************** Copyright Storlink Corp 2005. All rights reserved. *--------------------------------------------------------------------------* Name : ide.h* Description : Collect IDE definition** History** Date Writer Description* ----------- ----------- -------------------------------------------------* 09/07/2005 Gary Chen Create*****************************************************************************/#ifndef _IDE_H_#define _IDE_H_#if defined(BOARD_SUPPORT_IDE0) && defined(BOARD_SUPPORT_IDE1) #define IDE_CONTROLLERS 2#else #define IDE_CONTROLLERS 1#endif//#define IDE_CONTROLLERS 2#define IDE_MAX_DISKS 2 //2 #define IDE_SECTOR_SIZE 512#define IDE_MAX_PARTS_PER_DISK 1//4#define IDE_MAX_PARTITIONS IDE_MAX_PARTS_PER_DISK*IDE_CONTROLLERS#define IDE_CMD_REG8(base,addr) REG8(base+addr)#define IDE_CMD_REG16(base,addr) REG16(base+addr)#define IDE_CMD_REG32(base,addr) REG32(base+addr)#define IDE_CTRL_REG8(base) REG8(base)// IDE Register Indices#define IDE_REG_DATA 0#define IDE_REG_ERROR 1#define IDE_REG_FEATURES 1#define IDE_REG_COUNT 2#define IDE_REG_REASON 2 // ATAPI#define IDE_REG_LBALOW 3#define IDE_REG_LBAMID 4#define IDE_REG_LBAHI 5#define IDE_REG_DEVICE 6#define IDE_REG_STATUS 7#define IDE_REG_COMMAND 7#define IDE_STAT_BSY 0x80#define IDE_STAT_DRDY 0x40#define IDE_STAT_SERVICE 0x10#define IDE_STAT_DRQ 0x08#define IDE_STAT_CORR 0x04#define IDE_STAT_ERR 0x01#define IDE_REASON_REL 0x04#define IDE_REASON_IO 0x02#define IDE_REASON_COD 0x01/* flag values */#define IDE_DEV_PRESENT 1 // Device is present#define IDE_DEV_PACKET 2 // Supports packet interface#define IDE_DEV_ADDR48 3 // Supports 48bit addressing//// Drive ID offsets of interest//#define IDE_DEVID_GENCONFIG 0#define IDE_DEVID_SERNO 20#define IDE_DEVID_MODEL 54#define IDE_DEVID_LBA_CAPACITY 120#define IDE_LBA_48 (100*2)#define IDE_CMD_SET (83*2)// Kinds of disks#define DISK_IDE_HD 1#define DISK_IDE_CDROM 2#define DISK_FLOPPY 3// DOS partition table as laid out in the MBR//typedef struct mbr_partition { UINT8 boot_ind; // 0x80 == active UINT8 start_head; UINT8 start_sector; UINT8 start_cyl; UINT8 sys_ind; // partition type UINT8 end_head; UINT8 end_sector; UINT8 end_cyl; UINT8 start_sect[4]; // starting sector counting from 0 UINT8 sector_num[4]; // number of sectors in partition} IDE_MBR_T;#define MBR_PTABLE_OFFSET 0x1be#define MBR_MAGIC_OFFSET 0x1fe#define MBR_MAGIC 0xaa55#define IDE_PART_FAT12 0x01#define IDE_PART_FAT16_32M 0x04#define IDE_PART_EXTENDED 0x05#define IDE_PART_FAT16 0x06#define IDE_PART_LINUX_MINIX 0x81#define IDE_PART_LINUX_SWAP 0x82#define IDE_PART_LINUX 0x83#define IDE_PART_LINUX_EXTENDED 0x85struct disk_t;struct ide_t;typedef int disk_read_f(struct disk_t *disk, UINT64 start, UINT8 num, UINT16 *buf);typedef int disk_write_f(struct disk_t *disk, UINT64 start, UINT8 count, UINT16 *buf);typedef struct part_t { unsigned int present; unsigned int part_id; // partition id in disk, 0,1, ... struct disk_t *disk; disk_read_f *read; disk_write_f *write; UINT32 start_sector; // first sector in partition UINT64 sector_num; // number of sectors in partition UINT8 os; // FAT12, FAT16, Linux, etc. UINT8 bootflag; // not really used...} IDE_PART_T;extern IDE_PART_T ide_partitions[IDE_MAX_PARTITIONS];extern int ide_part_num;typedef struct disk_t{ unsigned int present; struct ide_t *ide; disk_read_f *read; disk_write_f *write; unsigned int drive_id; UINT32 flags; int kind; UINT64 sector_num; int part_num; // partition number per disk int lba_48;} IDE_DISK_T;typedef struct ide_t{ unsigned int present; int ide_id; unsigned int cmd_base; unsigned int ctrl_base; int disk_num; IDE_DISK_T disk[IDE_MAX_DISKS];} IDE_INFO_T;extern IDE_INFO_T ide_info[IDE_CONTROLLERS];/*----------------------------------------------------------------------* ide_get_uint16*----------------------------------------------------------------------*/static inline UINT16 ide_get_uint16(char *datap){ return (((*(datap+1)) << 8) + (*(datap)));}/*----------------------------------------------------------------------* ide_get_uint32*----------------------------------------------------------------------*/static inline UINT32 ide_get_uint32(char *datap){ return (((*(datap+3)) << 24) + ((*(datap+2)) << 16) + ((*(datap+1)) << 8) + (*(datap+0)));}#define SWAB32(x) \ ((((x) & 0xff) << 24) | \ (((x) & 0xff00) << 8) | \ (((x) >> 8) & 0xff00) | \ (((x) >> 24) & 0xff))#define SWAB16(x) \ ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))#define SWAB_LE32(x) (x)#define SWAB_LE16(x) (x)#define DISK_READ(d,s,n,p) ((d)->read)((d),(s),(n),(UINT16 *)(p))#define PARTITION_READ(part,s,n,p) \ ((part)->read)((part->disk),(s) + (part)->start_sector,(n),(UINT16 *)(p))#endif // _IDE_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -