1 // Definitions for X86 bios disks.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
9 #include "types.h" // u8
10 #include "config.h" // CONFIG_*
11 #include "farptr.h" // struct segoff_s
13 #define DISK_RET_SUCCESS 0x00
14 #define DISK_RET_EPARAM 0x01
15 #define DISK_RET_EADDRNOTFOUND 0x02
16 #define DISK_RET_EWRITEPROTECT 0x03
17 #define DISK_RET_ECHANGED 0x06
18 #define DISK_RET_EBOUNDARY 0x09
19 #define DISK_RET_EBADTRACK 0x0c
20 #define DISK_RET_ECONTROLLER 0x20
21 #define DISK_RET_ETIMEOUT 0x80
22 #define DISK_RET_ENOTLOCKED 0xb0
23 #define DISK_RET_ELOCKED 0xb1
24 #define DISK_RET_ENOTREMOVABLE 0xb2
25 #define DISK_RET_ETOOMANYLOCKS 0xb4
26 #define DISK_RET_EMEDIA 0xC0
27 #define DISK_RET_ENOTREADY 0xAA
30 /****************************************************************
32 ****************************************************************/
34 // Bios disk structures.
43 #define GET_INT13EXT(regs,var) \
44 GET_FARVAR((regs)->ds, ((struct int13ext_s*)((regs)->si+0))->var)
45 #define SET_INT13EXT(regs,var,val) \
46 SET_FARVAR((regs)->ds, ((struct int13ext_s*)((regs)->si+0))->var, (val))
48 // Disk Physical Table definition
80 #define GET_INT13DPT(regs,var) \
81 GET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var)
82 #define SET_INT13DPT(regs,var,val) \
83 SET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var, (val))
85 // Floppy "Disk Base Table"
100 struct floppy_ext_dbt_s {
101 struct floppy_dbt_s dbt;
108 // Helper function for setting up a return code.
110 void __disk_ret(struct bregs *regs, u32 linecode, const char *fname);
111 #define disk_ret(regs, code) \
112 __disk_ret((regs), (code) | (__LINE__ << 8), __func__)
113 void __disk_ret_unimplemented(struct bregs *regs, u32 linecode
114 , const char *fname);
115 #define disk_ret_unimplemented(regs, code) \
116 __disk_ret_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
119 /****************************************************************
121 ****************************************************************/
123 struct packed_chs_s {
131 struct packed_chs_s first;
133 struct packed_chs_s last;
145 struct partition_s partitions[4];
150 #define MBR_SIGNATURE 0xaa55
153 /****************************************************************
154 * Disk command request
155 ****************************************************************/
160 struct drive_s *drive_g;
165 #define CMD_RESET 0x00
166 #define CMD_READ 0x02
167 #define CMD_WRITE 0x03
168 #define CMD_VERIFY 0x04
169 #define CMD_FORMAT 0x05
170 #define CMD_SEEK 0x07
171 #define CMD_ISREADY 0x10
174 /****************************************************************
176 ****************************************************************/
179 u16 heads; // # heads
180 u16 cylinders; // # cylinders
181 u16 spt; // # sectors / track
185 u8 type; // Driver type (DTYPE_*)
186 u8 floppy_type; // Type of floppy (only for floppy drives).
187 struct chs_s lchs; // Logical CHS
188 u64 sectors; // Total sectors count
189 u32 cntl_id; // Unique id for a given driver type.
190 u8 removable; // Is media removable (currently unused)
192 // Info for EDD calls
193 u8 translation; // type of translation
194 u16 blksize; // block size
195 struct chs_s pchs; // Physical CHS
198 #define DISK_SECTOR_SIZE 512
199 #define CDROM_SECTOR_SIZE 2048
201 #define DTYPE_NONE 0x00
202 #define DTYPE_FLOPPY 0x01
203 #define DTYPE_ATA 0x02
204 #define DTYPE_ATAPI 0x03
205 #define DTYPE_RAMDISK 0x04
206 #define DTYPE_CDEMU 0x05
207 #define DTYPE_USB 0x06
208 #define DTYPE_VIRTIO 0x07
209 #define DTYPE_AHCI 0x08
211 #define MAXDESCSIZE 80
213 #define TRANSLATION_NONE 0
214 #define TRANSLATION_LBA 1
215 #define TRANSLATION_LARGE 2
216 #define TRANSLATION_RECHS 3
218 #define EXTTYPE_FLOPPY 0
222 #define EXTSTART_HD 0x80
223 #define EXTSTART_CD 0xE0
226 /****************************************************************
228 ****************************************************************/
231 extern u8 FloppyCount, CDCount;
232 extern u8 *bounce_buf_fl;
233 struct drive_s *getDrive(u8 exttype, u8 extdriveoffset);
234 int getDriveId(u8 exttype, struct drive_s *drive_g);
235 void map_floppy_drive(struct drive_s *drive_g);
236 void map_hd_drive(struct drive_s *drive_g);
237 void map_cd_drive(struct drive_s *drive_g);
238 int process_op(struct disk_op_s *op);
239 int send_disk_op(struct disk_op_s *op);
240 int bounce_buf_init(void);
243 extern struct floppy_ext_dbt_s diskette_param_table2;
244 void floppy_setup(void);
245 struct drive_s *init_floppy(int floppyid, int ftype);
246 int find_floppy_type(u32 size);
247 int process_floppy_op(struct disk_op_s *op);
248 void floppy_tick(void);
251 extern struct drive_s *cdemu_drive_gf;
252 int process_cdemu_op(struct disk_op_s *op);
253 void cdemu_setup(void);
254 void cdemu_134b(struct bregs *regs);
255 int cdrom_boot(struct drive_s *drive_g);
258 void ramdisk_setup(void);
259 int process_ramdisk_op(struct disk_op_s *op);