Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
10 KiB

  1. //
  2. // This code is temporary. When Insignia supplies rom support, it should
  3. // be removed.
  4. //
  5. /* x86 v1.0
  6. *
  7. * XBIOSDSK.H
  8. * Guest ROM BIOS disk emulation
  9. *
  10. * History
  11. * Created 20-Oct-90 by Jeff Parsons
  12. * 17-Apr-91 Trimmed by Dave Hastings for use in temp. softpc
  13. *
  14. * COPYRIGHT NOTICE
  15. * This source file may not be distributed, modified or incorporated into
  16. * another product without prior approval from the author, Jeff Parsons.
  17. * This file may be copied to designated servers and machines authorized to
  18. * access those servers, but that does not imply any form of approval.
  19. */
  20. #define MAX_FD 2 // # supported floppy drives
  21. #define MAX_HD 2 // # supported hard disk drives
  22. #define MAX_DRIVES (MAX_FD+MAX_HD)
  23. #define DRIVE_FD0 0x00 // first floppy disk drive #
  24. #define DRIVE_FD1 0x01 //
  25. #define DRIVE_HD0 0x80 // first hard disk drive #
  26. #define DRIVE_HD1 0x81 //
  27. /* Drive types for QUERYDRVPARMS
  28. */
  29. #define DRVTYPE_360KB 1
  30. #define DRVTYPE_1200KB 2
  31. #define DRVTYPE_720KB 3
  32. #define DRVTYPE_1440KB 4
  33. /* BIOS disk functions
  34. */
  35. #define DSKFUNC_DISKRESET 0x00
  36. #define DSKFUNC_DISKSTATUS 0x01
  37. #define DSKFUNC_READSECTORS 0x02
  38. #define DSKFUNC_WRITESECTORS 0x03
  39. #define DSKFUNC_VERIFYSECTORS 0x04
  40. #define DSKFUNC_FORMATTRACK 0x05
  41. #define DSKFUNC_QUERYDRVPARMS 0x08
  42. #define DSKFUNC_QUERYDASDTYPE 0x15
  43. #define DSKFUNC_QUERYCHANGE 0x16
  44. #define DSKFUNC_SETDISKTYPE 0x17
  45. #define DSKFUNC_SETMEDIATYPE 0x18
  46. /* BIOS disk status codes
  47. */
  48. #define DSKSTAT_SUCCESS 0x00 // successful completion
  49. #define DSKSTAT_BADCMD 0x01 // bad command
  50. #define DSKSTAT_BADADDRMARK 0x02 // address mark not found
  51. #define DSKSTAT_WRITEPROTECT 0x03 // write on write-protected disk
  52. #define DSKSTAT_RECNOTFOUND 0x04 // sector not found
  53. #define DSKSTAT_BADRESET 0x05 // reset failed (HD)
  54. #define DSKSTAT_MEDIACHANGE 0x06 // media changed
  55. #define DSKSTAT_INITFAIL 0x07 // parm. act. failed (HD)
  56. #define DSKSTAT_BADDMA 0x08 // DMA overrun
  57. #define DSKSTAT_DMABOUNDARY 0x09 // DMA across 64K boundary
  58. #define DSKSTAT_BADSECTOR 0x0A // bad sector detected (HD)
  59. #define DSKSTAT_BADTRACK 0x0B // bad track detected (HD)
  60. #define DSKSTAT_BADMEDIATYPE 0x0C // unsupported track (HD)
  61. #define DSKSTAT_BADFMTSECNUM 0x0D // bad # of sectors on format (HD)
  62. #define DSKSTAT_ADDRMARKDET 0x0E // ctrl data addr mark detected (HD
  63. #define DSKSTAT_DMAARBERR 0x0F // DMA arbitration error (HD)
  64. #define DSKSTAT_BADCRCECC 0x10 // bad CRC/ECC
  65. #define DSKSTAT_DATACORRECT 0x11 // data ECC corrected
  66. #define DSKSTAT_BADCNTLR 0x20 // controller failure
  67. #define DSKSTAT_BADSEEK 0x40 // seek failed
  68. #define DSKSTAT_TIMEOUT 0x80 // time out
  69. #define DSKSTAT_DRVNOTREADY 0xAA // drive not ready (HD)
  70. #define DSKSTAT_UNDEFERR 0xBB // undefined error (HD)
  71. #define DSKSTAT_WRITEFAULT 0xCC // write fault (HD)
  72. #define DSKSTAT_STATUSERROR 0xE0 // status register error (HD)
  73. #define DSKSTAT_SENSEFAIL 0xFF // sense operation failed (HD)
  74. /* BIOS Data Area disk locations
  75. */
  76. #define DSKDATA_SEEKSTATUS 0x43E // drive recal. status (1 byte)
  77. #define DSKDATA_MOTORSTATUS 0x43F // motor status (1 byte)
  78. #define DSKDATA_MOTORCOUNT 0x440 // time-out count for motor (1 byte)
  79. #define DSKDATA_DISKETTESTATUS 0x441 // return code status (1 byte)
  80. #define DSKDATA_NECSTATUS 0x442 // controller status bytes (7 bytes)
  81. #define DSKDATA_DISKSTATUS1 0x474 // return code status (1 byte)
  82. /* Floppy Diskette Parameter Table
  83. * (pointed by vector BIOSINT_FDSKPARMS (1Eh))
  84. */
  85. typedef struct fdp_s {
  86. BYTE bSpecify1; // step-rate, head-unload
  87. BYTE bSpecify2; // head-load, DMA mode
  88. BYTE bMotorOff; // motor-off delay
  89. BYTE bSectorSize; // bytes/sec (0=128,1=256,2=512,3=1024)
  90. BYTE nLastSector; // (or think of it as # sectors/track)
  91. BYTE lenGapRW; //
  92. BYTE lenData; //
  93. BYTE lenGapFormat; //
  94. BYTE bFormatData; // format initialization byte
  95. BYTE bSettle; // head settle time
  96. BYTE bMotorOn; // motor start-up time
  97. } FDP;
  98. typedef FDP *PFDP; // pointer to diskette parameter table
  99. /* Hard Disk Parameter Table
  100. */
  101. typedef struct hdp_s {
  102. USHORT usMaxCylinders; // maximum number of cylinders
  103. BYTE bMaxHeads; // maximum number of heads
  104. USHORT usReserve1; // reserved (not used)
  105. USHORT usWritePrecompCyl; // starting write precompensation cyl.
  106. BYTE bMaxECCDataBurstLen; // maximum ECC data burst length
  107. BYTE bControl; // control byte
  108. BYTE abReserve2[3]; // reserved (not used)
  109. USHORT usLandingZone; // landing zone for head parking
  110. BYTE bSectorsPerTrack; // number of sectors per track
  111. BYTE bReserve3; // reserved for future use
  112. } HDP;
  113. typedef HDP *PHDP; // pointer to hard disk parameter table
  114. /* Hard Disk Parameter Table control byte bit definitions
  115. */
  116. #define HDPCTRL_DISABLERETRY 0xC0 // disable retries
  117. #define HDPCTRL_EXCEED8HEADS 0x08 // more than 8 heads
  118. /* Boot sector structures (more DOS-defined than BIOS-defined however -JTP)
  119. */
  120. #define PARTITION_ACTIVE 0x80 // status values
  121. #define PARTITION_12BITFAT 1 // type valus
  122. #define PARTITION_16BITFAT 4
  123. #define PARTITION_LARGEFAT 6
  124. typedef struct mbr_s { // Master Boot Record
  125. BYTE boot_code[0x1BE];
  126. BYTE partition_status;
  127. BYTE starting_head;
  128. USHORT starting_sec_cyl;
  129. BYTE partition_type;
  130. BYTE ending_head;
  131. USHORT ending_sec_cyl;
  132. ULONG starting_abs_sector;
  133. ULONG total_sectors;
  134. } MBR;
  135. typedef MBR *PMBR;
  136. typedef struct bpb_s { // BIOS Parameter Block (from sysbloks.h)
  137. BYTE boot_code[0x0B];
  138. USHORT bytes_per_sector; // sector size
  139. BYTE sectors_per_cluster; // sectors per allocation unit
  140. USHORT reserved_sectors; // number of reserved sectors
  141. BYTE nbr_fats; // number of fats
  142. USHORT root_entries; // number of directory entries
  143. USHORT total_sectors; // number of sectors
  144. BYTE media_type; // fatid byte
  145. USHORT sectors_per_fat; // sectors in a copy of the FAT
  146. USHORT sectors_per_track; // number of sectors per track
  147. USHORT number_of_heads; // number of heads
  148. ULONG hidden_sectors; // number of hidden sectors
  149. ULONG large_total_sectors; // large total sectors
  150. BYTE reserved[6]; // 6 reserved bytes
  151. } BPB;
  152. typedef BPB *PBPB;
  153. /* Virtual disk mapping info
  154. *
  155. * VIRTDISK is the header of a virtual disk file. Following the header
  156. * is an optional track table, and TRACKINFO is the format of each entry
  157. * in that table. The track table is only present if the last two
  158. * fields in the header (nsecTrack and nbSector) are zero, indicating a
  159. * non-homogeneous disk structure.
  160. *
  161. * Currently, a max of 4 DRIVEMAP structures are supported. The first two
  162. * entries are for physical drives 0 and 1 (specified in the command-line
  163. * options as drives A: and B:), and subsequent entries are for physical
  164. * hard drives 0x80 and up (specified as drives C: and up). Each DRIVEMAP
  165. * describes the remapping that should occur, if any, and for virtual disk
  166. * files, it also contains the virtual disk file header (which is read in
  167. * during initialization).
  168. *
  169. * When a request comes in for one of those drives, we check the flags in
  170. * corresponding DRIVEMAP structure. If no flags are set, no remapping
  171. * or virtualization occurs (drive behaves normally). This is the default.
  172. * If the drive is disabled (eg, "A:=*"), then all requests are returned
  173. * with an error. If the drive is remapped to another physical drive (eg,
  174. * "A:=B:") then the request is routed to the mapped drive. Finally, if
  175. * the drive is remapped to a virtual disk file, the appropriate file I/O
  176. * is performed.
  177. *
  178. * NOTE: Contrary to comments above, access to physical drives is not
  179. * currently supported, so mapping to a virtual drive is all you can do
  180. * right now.... (24-Nov-90 JTP)
  181. */
  182. #define VDFLAGS_WRITEPROTECT 0x01 // virtual disk is "write-protected"
  183. typedef struct virtdisk_s {
  184. BYTE fbVirt; // flags
  185. BYTE nHeads; // # heads
  186. USHORT nCyls; // # cylinders
  187. USHORT nsecTrack; // # sectors per track
  188. USHORT nbSector; // # bytes per sector
  189. } VIRTDISK;
  190. typedef VIRTDISK *PVIRTDISK;
  191. typedef struct trackinfo_s {
  192. USHORT nsecTrack; // # sectors per track
  193. USHORT nbSector; // # bytes per sector
  194. ULONG offVirtDisk; // offset within virtual disk file
  195. } TRACKINFO;
  196. typedef TRACKINFO *PTRACKINFO;
  197. #define DMFLAGS_VIRTUAL 0x01 // physical remapped to virtual
  198. #define DMFLAGS_DISABLED 0x02 // physical remapped to disabled
  199. #define DMFLAGS_PHYSICAL 0x04 // physical remapped to physical
  200. #define DMFLAGS_LOGICAL 0x08 // physical remapped to logical
  201. typedef struct drivemap_s {
  202. BYTE fbMap; // flags
  203. BYTE iPhysical; // # of remapped drive, if any
  204. FILE *hfVirtDisk; // handle to virtual disk, if any
  205. VIRTDISK vdInfo; // virtual disk info, if any
  206. #ifdef LOGICAL_DRIVE_SUPPORT
  207. ULONG nsecHidden; // from BPB, if any (logical disks only)
  208. BYTE type; // disk type, if any (logical disks only)
  209. #endif
  210. } DRIVEMAP;
  211. typedef DRIVEMAP *PDRIVEMAP;