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_*
12 #define DISK_RET_SUCCESS 0x00
13 #define DISK_RET_EPARAM 0x01
14 #define DISK_RET_EADDRNOTFOUND 0x02
15 #define DISK_RET_EWRITEPROTECT 0x03
16 #define DISK_RET_ECHANGED 0x06
17 #define DISK_RET_EBOUNDARY 0x09
18 #define DISK_RET_EBADTRACK 0x0c
19 #define DISK_RET_ECONTROLLER 0x20
20 #define DISK_RET_ETIMEOUT 0x80
21 #define DISK_RET_ENOTLOCKED 0xb0
22 #define DISK_RET_ELOCKED 0xb1
23 #define DISK_RET_ENOTREMOVABLE 0xb2
24 #define DISK_RET_ETOOMANYLOCKS 0xb4
25 #define DISK_RET_EMEDIA 0xC0
26 #define DISK_RET_ENOTREADY 0xAA
29 /****************************************************************
31 ****************************************************************/
33 // 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
71 #define GET_INT13DPT(regs,var) \
72 GET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var)
73 #define SET_INT13DPT(regs,var,val) \
74 SET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var, (val))
76 // Floppy "Disk Base Table"
91 struct floppy_ext_dbt_s {
92 struct floppy_dbt_s dbt;
99 // Helper function for setting up a return code.
101 void __disk_ret(struct bregs *regs, u32 linecode, const char *fname);
102 #define disk_ret(regs, code) \
103 __disk_ret((regs), (code) | (__LINE__ << 8), __func__)
106 /****************************************************************
108 ****************************************************************/
110 struct packed_chs_s {
118 struct packed_chs_s first;
120 struct packed_chs_s last;
132 struct partition_s partitions[4];
137 #define MBR_SIGNATURE 0xaa55
140 /****************************************************************
141 * Disk command request
142 ****************************************************************/
159 /****************************************************************
161 ****************************************************************/
164 u16 heads; // # heads
165 u16 cylinders; // # cylinders
166 u16 spt; // # sectors / track
169 struct ata_channel_s {
170 u16 iobase1; // IO Base 1
171 u16 iobase2; // IO Base 2
176 struct ata_device_s {
177 u8 type; // Detected type of ata (ata/atapi/none/unknown)
178 u8 device; // Detected type of attached devices (hd/cd/none)
179 u8 removable; // Removable device flag
180 u16 blksize; // block size
181 u8 version; // ATA/ATAPI version
185 u8 translation; // type of translation
186 struct chs_s lchs; // Logical CHS
187 struct chs_s pchs; // Physical CHS
189 u64 sectors; // Total sectors count
194 struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
197 struct ata_device_s devices[CONFIG_MAX_ATA_DEVICES];
199 // map between bios hd/cd id and ata channels
201 u8 idmap[2][CONFIG_MAX_ATA_DEVICES];
205 /****************************************************************
207 ****************************************************************/
210 extern struct ata_s ATA;
211 int cdrom_read(struct disk_op_s *op);
212 int ata_cmd_packet(int driveid, u8 *cmdbuf, u8 cmdlen
213 , u32 length, void *buf_fl);
214 void hard_drive_setup();
215 int process_ata_op(struct disk_op_s *op);
216 int process_atapi_op(struct disk_op_s *op);
217 void map_drive(int driveid);
220 extern u8 FloppyCount;
221 extern struct floppy_ext_dbt_s diskette_param_table2;
222 void floppy_drive_setup();
223 void floppy_13(struct bregs *regs, u8 drive);
227 void disk_13(struct bregs *regs, u8 device);
228 void disk_13XX(struct bregs *regs, u8 device);
229 void cdemu_access(struct bregs *regs, u8 device, u16 command);
232 void cdrom_13(struct bregs *regs, u8 device);
233 void cdemu_13(struct bregs *regs);
234 void cdemu_134b(struct bregs *regs);
235 int cdrom_boot(int cdid);