ata.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. *
  3. * Values for ATA / PATA devices
  4. */
  5. #pragma once
  6. #define ATA_SR_BSY 0x80
  7. #define ATA_SR_DRDY 0x40
  8. #define ATA_SR_DF 0x20
  9. #define ATA_SR_DSC 0x10
  10. #define ATA_SR_DRQ 0x08
  11. #define ATA_SR_CORR 0x04
  12. #define ATA_SR_IDX 0x02
  13. #define ATA_SR_ERR 0x01
  14. #define ATA_ER_BBK 0x80
  15. #define ATA_ER_UNC 0x40
  16. #define ATA_ER_MC 0x20
  17. #define ATA_ER_IDNF 0x10
  18. #define ATA_ER_MCR 0x08
  19. #define ATA_ER_ABRT 0x04
  20. #define ATA_ER_TK0NF 0x02
  21. #define ATA_ER_AMNF 0x01
  22. #define ATA_CMD_READ_PIO 0x20
  23. #define ATA_CMD_READ_PIO_EXT 0x24
  24. #define ATA_CMD_READ_DMA 0xC8
  25. #define ATA_CMD_READ_DMA_EXT 0x25
  26. #define ATA_CMD_WRITE_PIO 0x30
  27. #define ATA_CMD_WRITE_PIO_EXT 0x34
  28. #define ATA_CMD_WRITE_DMA 0xCA
  29. #define ATA_CMD_WRITE_DMA_EXT 0x35
  30. #define ATA_CMD_CACHE_FLUSH 0xE7
  31. #define ATA_CMD_CACHE_FLUSH_EXT 0xEA
  32. #define ATA_CMD_PACKET 0xA0
  33. #define ATA_CMD_IDENTIFY_PACKET 0xA1
  34. #define ATA_CMD_IDENTIFY 0xEC
  35. #define ATAPI_CMD_READ 0xA8
  36. #define ATAPI_CMD_EJECT 0x1B
  37. #define ATA_IDENT_DEVICETYPE 0
  38. #define ATA_IDENT_CYLINDERS 2
  39. #define ATA_IDENT_HEADS 6
  40. #define ATA_IDENT_SECTORS 12
  41. #define ATA_IDENT_SERIAL 20
  42. #define ATA_IDENT_MODEL 54
  43. #define ATA_IDENT_CAPABILITIES 98
  44. #define ATA_IDENT_FIELDVALID 106
  45. #define ATA_IDENT_MAX_LBA 120
  46. #define ATA_IDENT_COMMANDSETS 164
  47. #define ATA_IDENT_MAX_LBA_EXT 200
  48. #define IDE_ATA 0x00
  49. #define IDE_ATAPI 0x01
  50. #define ATA_MASTER 0x00
  51. #define ATA_SLAVE 0x01
  52. #define ATA_REG_DATA 0x00
  53. #define ATA_REG_ERROR 0x01
  54. #define ATA_REG_FEATURES 0x01
  55. #define ATA_REG_SECCOUNT0 0x02
  56. #define ATA_REG_LBA0 0x03
  57. #define ATA_REG_LBA1 0x04
  58. #define ATA_REG_LBA2 0x05
  59. #define ATA_REG_HDDEVSEL 0x06
  60. #define ATA_REG_COMMAND 0x07
  61. #define ATA_REG_STATUS 0x07
  62. #define ATA_REG_SECCOUNT1 0x08
  63. #define ATA_REG_LBA3 0x09
  64. #define ATA_REG_LBA4 0x0A
  65. #define ATA_REG_LBA5 0x0B
  66. #define ATA_REG_CONTROL 0x0C
  67. #define ATA_REG_ALTSTATUS 0x0C
  68. #define ATA_REG_DEVADDRESS 0x0D
  69. // Channels:
  70. #define ATA_PRIMARY 0x00
  71. #define ATA_SECONDARY 0x01
  72. // Directions:
  73. #define ATA_READ 0x00
  74. #define ATA_WRITE 0x01
  75. typedef struct {
  76. uint16_t base;
  77. uint16_t ctrl;
  78. uint16_t bmide;
  79. uint16_t nien;
  80. } ide_channel_regs_t;
  81. typedef struct {
  82. uint8_t reserved;
  83. uint8_t channel;
  84. uint8_t drive;
  85. uint16_t type;
  86. uint16_t signature;
  87. uint16_t capabilities;
  88. uint32_t command_sets;
  89. uint32_t size;
  90. uint8_t model[41];
  91. } ide_device_t;
  92. typedef struct {
  93. uint8_t status;
  94. uint8_t chs_first_sector[3];
  95. uint8_t type;
  96. uint8_t chs_last_sector[3];
  97. uint32_t lba_first_sector;
  98. uint32_t sector_count;
  99. } partition_t;
  100. typedef struct {
  101. uint16_t flags;
  102. uint16_t unused1[9];
  103. char serial[20];
  104. uint16_t unused2[3];
  105. char firmware[8];
  106. char model[40];
  107. uint16_t sectors_per_int;
  108. uint16_t unused3;
  109. uint16_t capabilities[2];
  110. uint16_t unused4[2];
  111. uint16_t valid_ext_data;
  112. uint16_t unused5[5];
  113. uint16_t size_of_rw_mult;
  114. uint32_t sectors_28;
  115. uint16_t unused6[38];
  116. uint64_t sectors_48;
  117. uint16_t unused7[152];
  118. } __attribute__((packed)) ata_identify_t;
  119. typedef struct {
  120. uint8_t boostrap[446];
  121. partition_t partitions[4];
  122. uint8_t signature[2];
  123. } __attribute__((packed)) mbr_t;