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 GPLv3 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(const char *fname, int lineno, struct bregs *regs, u8 code);
102 #define disk_ret(regs, code) \
103 __disk_ret(__func__, __LINE__, (regs), (code))
106 /****************************************************************
107 * Disk command request
108 ****************************************************************/
118 #define CMD_CDROM_READ 1
119 #define CMD_CDEMU_READ 2
122 /****************************************************************
124 ****************************************************************/
127 u16 heads; // # heads
128 u16 cylinders; // # cylinders
129 u16 spt; // # sectors / track
132 struct ata_channel_s {
133 u16 iobase1; // IO Base 1
134 u16 iobase2; // IO Base 2
139 struct ata_device_s {
140 u8 type; // Detected type of ata (ata/atapi/none/unknown)
141 u8 device; // Detected type of attached devices (hd/cd/none)
142 u8 removable; // Removable device flag
143 u8 mode; // transfer mode : PIO 16/32 bits - IRQ - ISADMA - PCIDMA
144 u16 blksize; // block size
146 u8 translation; // type of translation
147 struct chs_s lchs; // Logical CHS
148 struct chs_s pchs; // Physical CHS
150 u64 sectors; // Total sectors count
155 struct ata_channel_s channels[CONFIG_MAX_ATA_INTERFACES];
158 struct ata_device_s devices[CONFIG_MAX_ATA_DEVICES];
160 // map between bios hd/cd id and ata channels
162 u8 idmap[2][CONFIG_MAX_ATA_DEVICES];
166 /****************************************************************
168 ****************************************************************/
171 extern struct ata_s ATA;
172 int ata_cmd_data(struct disk_op_s *op);
173 int cdrom_read(struct disk_op_s *op);
174 int cdrom_read_512(struct disk_op_s *op);
175 int ata_cmd_packet(int driveid, u8 *cmdbuf, u8 cmdlen
176 , u32 length, void *far_buffer);
177 void ata_reset(int driveid);
178 void hard_drive_setup();
181 extern struct floppy_ext_dbt_s diskette_param_table2;
182 void floppy_drive_setup();
183 void floppy_13(struct bregs *regs, u8 drive);
187 void disk_13(struct bregs *regs, u8 device);
188 void disk_13XX(struct bregs *regs, u8 device);
191 void cdrom_13(struct bregs *regs, u8 device);
192 void cdemu_13(struct bregs *regs);
193 void cdemu_134b(struct bregs *regs);