Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 1 | // 16bit code to access hard drives. |
| 2 | // |
| 3 | // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // Copyright (C) 2002 MandrakeSoft S.A. |
| 5 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 7 | |
| 8 | #include "disk.h" // floppy_13 |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 9 | #include "biosvar.h" // SET_BDA |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 10 | #include "config.h" // CONFIG_* |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 11 | #include "util.h" // debug_enter |
Kevin O'Connor | f54c150 | 2008-06-14 15:56:16 -0400 | [diff] [blame] | 12 | #include "pic.h" // eoi_pic2 |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 13 | #include "bregs.h" // struct bregs |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 14 | #include "pci.h" // pci_bdf_to_bus |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 15 | #include "atabits.h" // ATA_CB_STAT |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 16 | |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 17 | |
| 18 | /**************************************************************** |
| 19 | * Helper functions |
| 20 | ****************************************************************/ |
| 21 | |
Kevin O'Connor | 567e4e3 | 2008-04-05 11:37:51 -0400 | [diff] [blame] | 22 | void |
Kevin O'Connor | 0560034 | 2009-01-02 13:10:58 -0500 | [diff] [blame] | 23 | __disk_ret(struct bregs *regs, u32 linecode, const char *fname) |
Kevin O'Connor | 567e4e3 | 2008-04-05 11:37:51 -0400 | [diff] [blame] | 24 | { |
Kevin O'Connor | 0560034 | 2009-01-02 13:10:58 -0500 | [diff] [blame] | 25 | u8 code = linecode; |
Kevin O'Connor | 567e4e3 | 2008-04-05 11:37:51 -0400 | [diff] [blame] | 26 | SET_BDA(disk_last_status, code); |
| 27 | if (code) |
Kevin O'Connor | 0560034 | 2009-01-02 13:10:58 -0500 | [diff] [blame] | 28 | __set_code_fail(regs, linecode, fname); |
Kevin O'Connor | 567e4e3 | 2008-04-05 11:37:51 -0400 | [diff] [blame] | 29 | else |
| 30 | set_code_success(regs); |
| 31 | } |
| 32 | |
| 33 | static void |
Kevin O'Connor | 0560034 | 2009-01-02 13:10:58 -0500 | [diff] [blame] | 34 | __disk_stub(struct bregs *regs, int lineno, const char *fname) |
Kevin O'Connor | 567e4e3 | 2008-04-05 11:37:51 -0400 | [diff] [blame] | 35 | { |
Kevin O'Connor | 0560034 | 2009-01-02 13:10:58 -0500 | [diff] [blame] | 36 | __debug_stub(regs, lineno, fname); |
| 37 | __disk_ret(regs, DISK_RET_SUCCESS | (lineno << 8), fname); |
Kevin O'Connor | 567e4e3 | 2008-04-05 11:37:51 -0400 | [diff] [blame] | 38 | } |
| 39 | |
Kevin O'Connor | 0560034 | 2009-01-02 13:10:58 -0500 | [diff] [blame] | 40 | #define DISK_STUB(regs) \ |
| 41 | __disk_stub((regs), __LINE__, __func__) |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 42 | |
Kevin O'Connor | 7f34309 | 2009-01-01 18:31:11 -0500 | [diff] [blame] | 43 | static int |
Kevin O'Connor | 8b267cb | 2009-01-19 19:25:21 -0500 | [diff] [blame] | 44 | __send_disk_op(struct disk_op_s *op_far, u16 op_seg) |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 45 | { |
Kevin O'Connor | 7f34309 | 2009-01-01 18:31:11 -0500 | [diff] [blame] | 46 | struct disk_op_s dop; |
Kevin O'Connor | 8b267cb | 2009-01-19 19:25:21 -0500 | [diff] [blame] | 47 | memcpy_far(GET_SEG(SS), &dop |
| 48 | , op_seg, op_far |
| 49 | , sizeof(dop)); |
Kevin O'Connor | 7f34309 | 2009-01-01 18:31:11 -0500 | [diff] [blame] | 50 | |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 51 | dprintf(DEBUG_HDL_13, "disk_op d=%d lba=%d buf=%p count=%d cmd=%d\n" |
Kevin O'Connor | 35ae726 | 2009-01-19 15:44:44 -0500 | [diff] [blame] | 52 | , dop.driveid, (u32)dop.lba, dop.buf_fl |
Kevin O'Connor | 7f34309 | 2009-01-01 18:31:11 -0500 | [diff] [blame] | 53 | , dop.count, dop.command); |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 54 | |
| 55 | irq_enable(); |
| 56 | |
| 57 | int status; |
Kevin O'Connor | 7f34309 | 2009-01-01 18:31:11 -0500 | [diff] [blame] | 58 | if (dop.command == CMD_CDEMU_READ) |
| 59 | status = cdrom_read_512(&dop); |
| 60 | else if (dop.command == CMD_CDROM_READ) |
| 61 | status = cdrom_read(&dop); |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 62 | else |
Kevin O'Connor | 7f34309 | 2009-01-01 18:31:11 -0500 | [diff] [blame] | 63 | status = ata_cmd_data(&dop); |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 64 | |
| 65 | irq_disable(); |
| 66 | |
| 67 | return status; |
| 68 | } |
| 69 | |
Kevin O'Connor | 7f34309 | 2009-01-01 18:31:11 -0500 | [diff] [blame] | 70 | static int |
| 71 | send_disk_op(struct disk_op_s *op) |
| 72 | { |
Kevin O'Connor | 0d9e673 | 2009-01-17 21:54:16 -0500 | [diff] [blame] | 73 | if (! CONFIG_ATA) |
| 74 | return -1; |
| 75 | |
Kevin O'Connor | 7f34309 | 2009-01-01 18:31:11 -0500 | [diff] [blame] | 76 | return stack_hop((u32)op, GET_SEG(SS), 0, __send_disk_op); |
| 77 | } |
| 78 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 79 | static void |
| 80 | basic_access(struct bregs *regs, u8 device, u16 command) |
| 81 | { |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 82 | struct disk_op_s dop; |
| 83 | dop.lba = 0; |
| 84 | dop.driveid = device; |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 85 | u8 type = GET_GLOBAL(ATA.devices[device].type); |
Kevin O'Connor | aa2590c | 2008-03-22 23:13:24 -0400 | [diff] [blame] | 86 | u16 nlc, nlh, nlspt; |
| 87 | if (type == ATA_TYPE_ATA) { |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 88 | nlc = GET_GLOBAL(ATA.devices[device].lchs.cylinders); |
| 89 | nlh = GET_GLOBAL(ATA.devices[device].lchs.heads); |
| 90 | nlspt = GET_GLOBAL(ATA.devices[device].lchs.spt); |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 91 | dop.command = command; |
Kevin O'Connor | aa2590c | 2008-03-22 23:13:24 -0400 | [diff] [blame] | 92 | } else { |
| 93 | // Must be cd emulation. |
Kevin O'Connor | 4a16ef6 | 2008-12-31 00:09:28 -0500 | [diff] [blame] | 94 | u16 ebda_seg = get_ebda_seg(); |
| 95 | nlc = GET_EBDA2(ebda_seg, cdemu.cylinders); |
| 96 | nlh = GET_EBDA2(ebda_seg, cdemu.heads); |
| 97 | nlspt = GET_EBDA2(ebda_seg, cdemu.spt); |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 98 | dop.lba = GET_EBDA2(ebda_seg, cdemu.ilba) * 4; |
| 99 | dop.command = CMD_CDEMU_READ; |
Kevin O'Connor | aa2590c | 2008-03-22 23:13:24 -0400 | [diff] [blame] | 100 | } |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 101 | |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 102 | dop.count = regs->al; |
Kevin O'Connor | 0cdac0e | 2008-03-29 12:45:53 -0400 | [diff] [blame] | 103 | u16 cylinder = regs->ch | ((((u16) regs->cl) << 2) & 0x300); |
| 104 | u16 sector = regs->cl & 0x3f; |
| 105 | u16 head = regs->dh; |
| 106 | |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 107 | if (dop.count > 128 || dop.count == 0 || sector == 0) { |
Kevin O'Connor | ac8df8c | 2008-05-24 23:46:33 -0400 | [diff] [blame] | 108 | dprintf(1, "int13_harddisk: function %02x, parameter out of range!\n" |
Kevin O'Connor | 0cdac0e | 2008-03-29 12:45:53 -0400 | [diff] [blame] | 109 | , regs->ah); |
| 110 | disk_ret(regs, DISK_RET_EPARAM); |
| 111 | return; |
| 112 | } |
| 113 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 114 | // sanity check on cyl heads, sec |
Kevin O'Connor | 1fcf144 | 2008-03-11 19:42:41 -0400 | [diff] [blame] | 115 | if (cylinder >= nlc || head >= nlh || sector > nlspt) { |
Kevin O'Connor | ac8df8c | 2008-05-24 23:46:33 -0400 | [diff] [blame] | 116 | dprintf(1, "int13_harddisk: function %02x, parameters out of" |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 117 | " range %04x/%04x/%04x!\n" |
| 118 | , regs->ah, cylinder, head, sector); |
| 119 | disk_ret(regs, DISK_RET_EPARAM); |
| 120 | return; |
| 121 | } |
| 122 | |
Kevin O'Connor | 3a04963 | 2008-03-11 11:48:04 -0400 | [diff] [blame] | 123 | if (!command) { |
| 124 | // If verify or seek |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 125 | disk_ret(regs, DISK_RET_SUCCESS); |
| 126 | return; |
| 127 | } |
| 128 | |
Kevin O'Connor | 049d5a2 | 2008-03-13 19:09:49 -0400 | [diff] [blame] | 129 | // translate lchs to lba |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 130 | dop.lba += (((((u32)cylinder * (u32)nlh) + (u32)head) * (u32)nlspt) |
| 131 | + (u32)sector - 1); |
Kevin O'Connor | aa2590c | 2008-03-22 23:13:24 -0400 | [diff] [blame] | 132 | |
| 133 | u16 segment = regs->es; |
| 134 | u16 offset = regs->bx; |
Kevin O'Connor | 35ae726 | 2009-01-19 15:44:44 -0500 | [diff] [blame] | 135 | dop.buf_fl = MAKE_FLATPTR(segment, offset); |
Kevin O'Connor | aa2590c | 2008-03-22 23:13:24 -0400 | [diff] [blame] | 136 | |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 137 | int status = send_disk_op(&dop); |
Kevin O'Connor | 74799df | 2008-03-12 20:49:07 -0400 | [diff] [blame] | 138 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 139 | // Set nb of sector transferred |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 140 | regs->al = GET_EBDA(sector_count); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 141 | |
| 142 | if (status != 0) { |
Kevin O'Connor | fe42eb2 | 2008-06-21 11:38:21 -0400 | [diff] [blame] | 143 | dprintf(1, "int13_harddisk: function %02x, error %d!\n" |
Kevin O'Connor | fad2da8 | 2008-03-22 20:37:44 -0400 | [diff] [blame] | 144 | , regs->ah, status); |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 145 | disk_ret(regs, DISK_RET_EBADTRACK); |
Kevin O'Connor | 6aa673d | 2009-01-02 12:36:46 -0500 | [diff] [blame] | 146 | return; |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 147 | } |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 148 | disk_ret(regs, DISK_RET_SUCCESS); |
| 149 | } |
| 150 | |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 151 | static void |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 152 | extended_access(struct bregs *regs, u8 device, u16 command) |
| 153 | { |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 154 | struct disk_op_s dop; |
Kevin O'Connor | 1bb3b5c | 2008-05-14 00:43:13 -0400 | [diff] [blame] | 155 | // Get lba and check. |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 156 | dop.lba = GET_INT13EXT(regs, lba); |
| 157 | dop.command = command; |
| 158 | dop.driveid = device; |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 159 | u8 type = GET_GLOBAL(ATA.devices[device].type); |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 160 | if (type == ATA_TYPE_ATA) { |
| 161 | if (dop.lba >= GET_GLOBAL(ATA.devices[device].sectors)) { |
| 162 | dprintf(1, "int13_harddisk: function %02x. LBA out of range\n" |
| 163 | , regs->ah); |
| 164 | disk_ret(regs, DISK_RET_EPARAM); |
| 165 | return; |
| 166 | } |
| 167 | } else { |
| 168 | dop.command = CMD_CDROM_READ; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Kevin O'Connor | 3a04963 | 2008-03-11 11:48:04 -0400 | [diff] [blame] | 171 | if (!command) { |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 172 | // If verify or seek |
| 173 | disk_ret(regs, DISK_RET_SUCCESS); |
| 174 | return; |
| 175 | } |
| 176 | |
Kevin O'Connor | aa2590c | 2008-03-22 23:13:24 -0400 | [diff] [blame] | 177 | u16 segment = GET_INT13EXT(regs, segment); |
| 178 | u16 offset = GET_INT13EXT(regs, offset); |
Kevin O'Connor | 35ae726 | 2009-01-19 15:44:44 -0500 | [diff] [blame] | 179 | dop.buf_fl = MAKE_FLATPTR(segment, offset); |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 180 | dop.count = GET_INT13EXT(regs, count); |
Kevin O'Connor | aa2590c | 2008-03-22 23:13:24 -0400 | [diff] [blame] | 181 | |
Kevin O'Connor | 4524bf7 | 2008-12-31 00:31:03 -0500 | [diff] [blame] | 182 | int status = send_disk_op(&dop); |
Kevin O'Connor | 74799df | 2008-03-12 20:49:07 -0400 | [diff] [blame] | 183 | |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 184 | SET_INT13EXT(regs, count, GET_EBDA(sector_count)); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 185 | |
| 186 | if (status != 0) { |
Kevin O'Connor | fe42eb2 | 2008-06-21 11:38:21 -0400 | [diff] [blame] | 187 | dprintf(1, "int13_harddisk: function %02x, error %d!\n" |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 188 | , regs->ah, status); |
| 189 | disk_ret(regs, DISK_RET_EBADTRACK); |
| 190 | return; |
| 191 | } |
| 192 | disk_ret(regs, DISK_RET_SUCCESS); |
| 193 | } |
| 194 | |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 195 | |
| 196 | /**************************************************************** |
| 197 | * Hard Drive functions |
| 198 | ****************************************************************/ |
| 199 | |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 200 | // disk controller reset |
| 201 | static void |
| 202 | disk_1300(struct bregs *regs, u8 device) |
| 203 | { |
| 204 | ata_reset(device); |
| 205 | } |
| 206 | |
| 207 | // read disk status |
| 208 | static void |
| 209 | disk_1301(struct bregs *regs, u8 device) |
| 210 | { |
Kevin O'Connor | fad2da8 | 2008-03-22 20:37:44 -0400 | [diff] [blame] | 211 | u8 v = GET_BDA(disk_last_status); |
| 212 | regs->ah = v; |
| 213 | set_cf(regs, v); |
| 214 | // XXX - clear disk_last_status? |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 217 | // read disk sectors |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 218 | static void |
| 219 | disk_1302(struct bregs *regs, u8 device) |
| 220 | { |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 221 | basic_access(regs, device, ATA_CMD_READ_SECTORS); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 222 | } |
| 223 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 224 | // write disk sectors |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 225 | static void |
| 226 | disk_1303(struct bregs *regs, u8 device) |
| 227 | { |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 228 | basic_access(regs, device, ATA_CMD_WRITE_SECTORS); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 229 | } |
| 230 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 231 | // verify disk sectors |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 232 | static void |
| 233 | disk_1304(struct bregs *regs, u8 device) |
| 234 | { |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 235 | basic_access(regs, device, 0); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 236 | // FIXME verify |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 237 | } |
| 238 | |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 239 | // format disk track |
| 240 | static void |
| 241 | disk_1305(struct bregs *regs, u8 device) |
| 242 | { |
| 243 | DISK_STUB(regs); |
| 244 | } |
| 245 | |
| 246 | // read disk drive parameters |
| 247 | static void |
| 248 | disk_1308(struct bregs *regs, u8 device) |
| 249 | { |
| 250 | // Get logical geometry from table |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 251 | u16 nlc = GET_GLOBAL(ATA.devices[device].lchs.cylinders); |
| 252 | u16 nlh = GET_GLOBAL(ATA.devices[device].lchs.heads); |
| 253 | u16 nlspt = GET_GLOBAL(ATA.devices[device].lchs.spt); |
Kevin O'Connor | 4a16ef6 | 2008-12-31 00:09:28 -0500 | [diff] [blame] | 254 | u16 count = GET_BDA(hdcount); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 255 | |
| 256 | nlc = nlc - 2; /* 0 based , last sector not used */ |
| 257 | regs->al = 0; |
| 258 | regs->ch = nlc & 0xff; |
| 259 | regs->cl = ((nlc >> 2) & 0xc0) | (nlspt & 0x3f); |
| 260 | regs->dh = nlh - 1; |
| 261 | regs->dl = count; /* FIXME returns 0, 1, or n hard drives */ |
| 262 | |
| 263 | // FIXME should set ES & DI |
| 264 | disk_ret(regs, DISK_RET_SUCCESS); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 265 | } |
| 266 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 267 | // initialize drive parameters |
| 268 | static void |
| 269 | disk_1309(struct bregs *regs, u8 device) |
| 270 | { |
| 271 | DISK_STUB(regs); |
| 272 | } |
| 273 | |
| 274 | // seek to specified cylinder |
| 275 | static void |
| 276 | disk_130c(struct bregs *regs, u8 device) |
| 277 | { |
| 278 | DISK_STUB(regs); |
| 279 | } |
| 280 | |
| 281 | // alternate disk reset |
| 282 | static void |
| 283 | disk_130d(struct bregs *regs, u8 device) |
| 284 | { |
| 285 | DISK_STUB(regs); |
| 286 | } |
| 287 | |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 288 | // check drive ready |
| 289 | static void |
| 290 | disk_1310(struct bregs *regs, u8 device) |
| 291 | { |
| 292 | // should look at 40:8E also??? |
| 293 | |
| 294 | // Read the status from controller |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 295 | u8 status = inb(GET_GLOBAL(ATA.channels[device/2].iobase1) + ATA_CB_STAT); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 296 | if ( (status & ( ATA_CB_STAT_BSY | ATA_CB_STAT_RDY )) == ATA_CB_STAT_RDY ) |
| 297 | disk_ret(regs, DISK_RET_SUCCESS); |
| 298 | else |
| 299 | disk_ret(regs, DISK_RET_ENOTREADY); |
| 300 | } |
| 301 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 302 | // recalibrate |
| 303 | static void |
| 304 | disk_1311(struct bregs *regs, u8 device) |
| 305 | { |
| 306 | DISK_STUB(regs); |
| 307 | } |
| 308 | |
| 309 | // controller internal diagnostic |
| 310 | static void |
| 311 | disk_1314(struct bregs *regs, u8 device) |
| 312 | { |
| 313 | DISK_STUB(regs); |
| 314 | } |
| 315 | |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 316 | // read disk drive size |
| 317 | static void |
| 318 | disk_1315(struct bregs *regs, u8 device) |
| 319 | { |
| 320 | // Get logical geometry from table |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 321 | u16 nlc = GET_GLOBAL(ATA.devices[device].lchs.cylinders); |
| 322 | u16 nlh = GET_GLOBAL(ATA.devices[device].lchs.heads); |
| 323 | u16 nlspt = GET_GLOBAL(ATA.devices[device].lchs.spt); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 324 | |
| 325 | // Compute sector count seen by int13 |
| 326 | u32 lba = (u32)(nlc - 1) * (u32)nlh * (u32)nlspt; |
| 327 | regs->cx = lba >> 16; |
| 328 | regs->dx = lba & 0xffff; |
| 329 | |
Kevin O'Connor | dcc7a4f | 2008-03-08 23:25:16 -0500 | [diff] [blame] | 330 | disk_ret(regs, DISK_RET_SUCCESS); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 331 | regs->ah = 3; // hard disk accessible |
| 332 | } |
| 333 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 334 | // IBM/MS installation check |
| 335 | static void |
| 336 | disk_1341(struct bregs *regs, u8 device) |
| 337 | { |
| 338 | regs->bx = 0xaa55; // install check |
| 339 | regs->cx = 0x0007; // ext disk access and edd, removable supported |
| 340 | disk_ret(regs, DISK_RET_SUCCESS); |
| 341 | regs->ah = 0x30; // EDD 3.0 |
| 342 | } |
| 343 | |
| 344 | // IBM/MS extended read |
| 345 | static void |
| 346 | disk_1342(struct bregs *regs, u8 device) |
| 347 | { |
| 348 | extended_access(regs, device, ATA_CMD_READ_SECTORS); |
| 349 | } |
| 350 | |
| 351 | // IBM/MS extended write |
| 352 | static void |
| 353 | disk_1343(struct bregs *regs, u8 device) |
| 354 | { |
| 355 | extended_access(regs, device, ATA_CMD_WRITE_SECTORS); |
| 356 | } |
| 357 | |
| 358 | // IBM/MS verify |
| 359 | static void |
| 360 | disk_1344(struct bregs *regs, u8 device) |
| 361 | { |
| 362 | extended_access(regs, device, 0); |
| 363 | } |
| 364 | |
| 365 | // IBM/MS lock/unlock drive |
| 366 | static void |
| 367 | disk_1345(struct bregs *regs, u8 device) |
| 368 | { |
| 369 | // Always success for HD |
| 370 | disk_ret(regs, DISK_RET_SUCCESS); |
| 371 | } |
| 372 | |
| 373 | // IBM/MS eject media |
| 374 | static void |
| 375 | disk_1346(struct bregs *regs, u8 device) |
| 376 | { |
| 377 | // Volume Not Removable |
| 378 | disk_ret(regs, DISK_RET_ENOTREMOVABLE); |
| 379 | } |
| 380 | |
| 381 | // IBM/MS extended seek |
| 382 | static void |
| 383 | disk_1347(struct bregs *regs, u8 device) |
| 384 | { |
| 385 | extended_access(regs, device, 0); |
| 386 | } |
| 387 | |
| 388 | // IBM/MS get drive parameters |
| 389 | static void |
| 390 | disk_1348(struct bregs *regs, u8 device) |
| 391 | { |
| 392 | u16 size = GET_INT13DPT(regs, size); |
| 393 | |
| 394 | // Buffer is too small |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 395 | if (size < 26) { |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 396 | disk_ret(regs, DISK_RET_EPARAM); |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | // EDD 1.x |
| 401 | |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 402 | u8 type = GET_GLOBAL(ATA.devices[device].type); |
| 403 | u16 npc = GET_GLOBAL(ATA.devices[device].pchs.cylinders); |
| 404 | u16 nph = GET_GLOBAL(ATA.devices[device].pchs.heads); |
| 405 | u16 npspt = GET_GLOBAL(ATA.devices[device].pchs.spt); |
| 406 | u64 lba = GET_GLOBAL(ATA.devices[device].sectors); |
| 407 | u16 blksize = GET_GLOBAL(ATA.devices[device].blksize); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 408 | |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 409 | dprintf(DEBUG_HDL_13, "disk_1348 size=%d t=%d chs=%d,%d,%d lba=%d bs=%d\n" |
| 410 | , size, type, npc, nph, npspt, (u32)lba, blksize); |
| 411 | |
| 412 | SET_INT13DPT(regs, size, 26); |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 413 | if (type == ATA_TYPE_ATA) { |
Kevin O'Connor | 1bb3b5c | 2008-05-14 00:43:13 -0400 | [diff] [blame] | 414 | if (lba > (u64)npspt*nph*0x3fff) { |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 415 | SET_INT13DPT(regs, infos, 0x00); // geometry is invalid |
| 416 | SET_INT13DPT(regs, cylinders, 0x3fff); |
| 417 | } else { |
| 418 | SET_INT13DPT(regs, infos, 0x02); // geometry is valid |
| 419 | SET_INT13DPT(regs, cylinders, (u32)npc); |
| 420 | } |
| 421 | SET_INT13DPT(regs, heads, (u32)nph); |
| 422 | SET_INT13DPT(regs, spt, (u32)npspt); |
Kevin O'Connor | 1bb3b5c | 2008-05-14 00:43:13 -0400 | [diff] [blame] | 423 | SET_INT13DPT(regs, sector_count, lba); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 424 | } else { |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 425 | // ATAPI |
| 426 | // 0x74 = removable, media change, lockable, max values |
| 427 | SET_INT13DPT(regs, infos, 0x74); |
| 428 | SET_INT13DPT(regs, cylinders, 0xffffffff); |
| 429 | SET_INT13DPT(regs, heads, 0xffffffff); |
| 430 | SET_INT13DPT(regs, spt, 0xffffffff); |
Kevin O'Connor | 1bb3b5c | 2008-05-14 00:43:13 -0400 | [diff] [blame] | 431 | SET_INT13DPT(regs, sector_count, (u64)-1); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 432 | } |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 433 | SET_INT13DPT(regs, blksize, blksize); |
| 434 | |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 435 | if (size < 30) { |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 436 | disk_ret(regs, DISK_RET_SUCCESS); |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | // EDD 2.x |
| 441 | |
Kevin O'Connor | 0881537 | 2008-12-29 21:16:31 -0500 | [diff] [blame] | 442 | u16 ebda_seg = get_ebda_seg(); |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 443 | SET_INT13DPT(regs, size, 30); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 444 | |
Kevin O'Connor | 0881537 | 2008-12-29 21:16:31 -0500 | [diff] [blame] | 445 | SET_INT13DPT(regs, dpte_segment, ebda_seg); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 446 | SET_INT13DPT(regs, dpte_offset |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 447 | , offsetof(struct extended_bios_data_area_s, dpte)); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 448 | |
| 449 | // Fill in dpte |
| 450 | u8 channel = device / 2; |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 451 | u8 slave = device % 2; |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 452 | u16 iobase1 = GET_GLOBAL(ATA.channels[channel].iobase1); |
| 453 | u16 iobase2 = GET_GLOBAL(ATA.channels[channel].iobase2); |
| 454 | u8 irq = GET_GLOBAL(ATA.channels[channel].irq); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 455 | |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 456 | u16 options = 0; |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 457 | if (type == ATA_TYPE_ATA) { |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 458 | u8 translation = GET_GLOBAL(ATA.devices[device].translation); |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 459 | if (translation != ATA_TRANSLATION_NONE) { |
| 460 | options |= 1<<3; // CHS translation |
| 461 | if (translation == ATA_TRANSLATION_LBA) |
| 462 | options |= 1<<9; |
| 463 | if (translation == ATA_TRANSLATION_RECHS) |
| 464 | options |= 3<<9; |
| 465 | } |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 466 | } else { |
| 467 | // ATAPI |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 468 | options |= 1<<5; // removable device |
| 469 | options |= 1<<6; // atapi device |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 470 | } |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 471 | options |= 1<<4; // lba translation |
Kevin O'Connor | 32945af | 2009-02-27 21:23:01 -0500 | [diff] [blame] | 472 | if (CONFIG_ATA_PIO32) |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 473 | options |= 1<<7; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 474 | |
Kevin O'Connor | 0881537 | 2008-12-29 21:16:31 -0500 | [diff] [blame] | 475 | SET_EBDA2(ebda_seg, dpte.iobase1, iobase1); |
| 476 | SET_EBDA2(ebda_seg, dpte.iobase2, iobase2 + ATA_CB_DC); |
| 477 | SET_EBDA2(ebda_seg, dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0) |
| 478 | | ATA_CB_DH_LBA)); |
| 479 | SET_EBDA2(ebda_seg, dpte.unused, 0xcb); |
| 480 | SET_EBDA2(ebda_seg, dpte.irq, irq); |
| 481 | SET_EBDA2(ebda_seg, dpte.blkcount, 1); |
| 482 | SET_EBDA2(ebda_seg, dpte.dma, 0); |
| 483 | SET_EBDA2(ebda_seg, dpte.pio, 0); |
| 484 | SET_EBDA2(ebda_seg, dpte.options, options); |
| 485 | SET_EBDA2(ebda_seg, dpte.reserved, 0); |
| 486 | SET_EBDA2(ebda_seg, dpte.revision, 0x11); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 487 | |
Kevin O'Connor | 8b267cb | 2009-01-19 19:25:21 -0500 | [diff] [blame] | 488 | u8 sum = checksum_far( |
| 489 | ebda_seg, (void*)offsetof(struct extended_bios_data_area_s, dpte), 15); |
| 490 | SET_EBDA2(ebda_seg, dpte.checksum, -sum); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 491 | |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 492 | if (size < 66) { |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 493 | disk_ret(regs, DISK_RET_SUCCESS); |
| 494 | return; |
| 495 | } |
| 496 | |
| 497 | // EDD 3.x |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 498 | SET_INT13DPT(regs, key, 0xbedd); |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 499 | SET_INT13DPT(regs, dpi_length, 36); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 500 | SET_INT13DPT(regs, reserved1, 0); |
| 501 | SET_INT13DPT(regs, reserved2, 0); |
| 502 | |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 503 | SET_INT13DPT(regs, host_bus[0], 'P'); |
| 504 | SET_INT13DPT(regs, host_bus[1], 'C'); |
| 505 | SET_INT13DPT(regs, host_bus[2], 'I'); |
| 506 | SET_INT13DPT(regs, host_bus[3], 0); |
| 507 | |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 508 | u32 bdf = GET_GLOBAL(ATA.channels[channel].pci_bdf); |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 509 | u32 path = (pci_bdf_to_bus(bdf) | (pci_bdf_to_dev(bdf) << 8) |
| 510 | | (pci_bdf_to_fn(bdf) << 16)); |
| 511 | SET_INT13DPT(regs, iface_path, path); |
| 512 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 513 | SET_INT13DPT(regs, iface_type[0], 'A'); |
| 514 | SET_INT13DPT(regs, iface_type[1], 'T'); |
| 515 | SET_INT13DPT(regs, iface_type[2], 'A'); |
| 516 | SET_INT13DPT(regs, iface_type[3], 0); |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 517 | SET_INT13DPT(regs, iface_type[4], 0); |
| 518 | SET_INT13DPT(regs, iface_type[5], 0); |
| 519 | SET_INT13DPT(regs, iface_type[6], 0); |
| 520 | SET_INT13DPT(regs, iface_type[7], 0); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 521 | |
Kevin O'Connor | 970a032 | 2008-10-26 12:01:21 -0400 | [diff] [blame] | 522 | SET_INT13DPT(regs, device_path, slave); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 523 | |
Kevin O'Connor | 7d10821 | 2009-01-21 19:13:21 -0500 | [diff] [blame] | 524 | SET_INT13DPT(regs, checksum |
| 525 | , -checksum_far(regs->ds, (void*)(regs->si+30), 35)); |
Kevin O'Connor | 53236cc | 2008-08-31 11:16:33 -0400 | [diff] [blame] | 526 | |
| 527 | disk_ret(regs, DISK_RET_SUCCESS); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | // IBM/MS extended media change |
| 531 | static void |
| 532 | disk_1349(struct bregs *regs, u8 device) |
| 533 | { |
| 534 | // Always success for HD |
| 535 | disk_ret(regs, DISK_RET_SUCCESS); |
| 536 | } |
| 537 | |
| 538 | static void |
| 539 | disk_134e01(struct bregs *regs, u8 device) |
| 540 | { |
| 541 | disk_ret(regs, DISK_RET_SUCCESS); |
| 542 | } |
| 543 | |
| 544 | static void |
| 545 | disk_134e03(struct bregs *regs, u8 device) |
| 546 | { |
| 547 | disk_ret(regs, DISK_RET_SUCCESS); |
| 548 | } |
| 549 | |
| 550 | static void |
| 551 | disk_134e04(struct bregs *regs, u8 device) |
| 552 | { |
| 553 | disk_ret(regs, DISK_RET_SUCCESS); |
| 554 | } |
| 555 | |
| 556 | static void |
| 557 | disk_134e06(struct bregs *regs, u8 device) |
| 558 | { |
| 559 | disk_ret(regs, DISK_RET_SUCCESS); |
| 560 | } |
| 561 | |
| 562 | static void |
| 563 | disk_134eXX(struct bregs *regs, u8 device) |
| 564 | { |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 565 | disk_ret(regs, DISK_RET_EPARAM); |
| 566 | } |
| 567 | |
| 568 | // IBM/MS set hardware configuration |
| 569 | static void |
| 570 | disk_134e(struct bregs *regs, u8 device) |
| 571 | { |
| 572 | switch (regs->al) { |
| 573 | case 0x01: disk_134e01(regs, device); break; |
| 574 | case 0x03: disk_134e03(regs, device); break; |
| 575 | case 0x04: disk_134e04(regs, device); break; |
| 576 | case 0x06: disk_134e06(regs, device); break; |
| 577 | default: disk_134eXX(regs, device); break; |
| 578 | } |
| 579 | } |
| 580 | |
Kevin O'Connor | 31d8c8a | 2008-03-04 19:56:41 -0500 | [diff] [blame] | 581 | void |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 582 | disk_13XX(struct bregs *regs, u8 device) |
| 583 | { |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 584 | disk_ret(regs, DISK_RET_EPARAM); |
| 585 | } |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 586 | |
Kevin O'Connor | 31d8c8a | 2008-03-04 19:56:41 -0500 | [diff] [blame] | 587 | void |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 588 | disk_13(struct bregs *regs, u8 device) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 589 | { |
Kevin O'Connor | 15aee2e | 2008-03-01 13:34:04 -0500 | [diff] [blame] | 590 | //debug_stub(regs); |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 591 | |
| 592 | // clear completion flag |
| 593 | SET_BDA(disk_interrupt_flag, 0); |
| 594 | |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 595 | switch (regs->ah) { |
| 596 | case 0x00: disk_1300(regs, device); break; |
| 597 | case 0x01: disk_1301(regs, device); break; |
| 598 | case 0x02: disk_1302(regs, device); break; |
| 599 | case 0x03: disk_1303(regs, device); break; |
| 600 | case 0x04: disk_1304(regs, device); break; |
| 601 | case 0x05: disk_1305(regs, device); break; |
| 602 | case 0x08: disk_1308(regs, device); break; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 603 | case 0x09: disk_1309(regs, device); break; |
| 604 | case 0x0c: disk_130c(regs, device); break; |
| 605 | case 0x0d: disk_130d(regs, device); break; |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 606 | case 0x10: disk_1310(regs, device); break; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 607 | case 0x11: disk_1311(regs, device); break; |
| 608 | case 0x14: disk_1314(regs, device); break; |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 609 | case 0x15: disk_1315(regs, device); break; |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 610 | case 0x41: disk_1341(regs, device); break; |
| 611 | case 0x42: disk_1342(regs, device); break; |
| 612 | case 0x43: disk_1343(regs, device); break; |
| 613 | case 0x44: disk_1344(regs, device); break; |
| 614 | case 0x45: disk_1345(regs, device); break; |
| 615 | case 0x46: disk_1346(regs, device); break; |
| 616 | case 0x47: disk_1347(regs, device); break; |
| 617 | case 0x48: disk_1348(regs, device); break; |
| 618 | case 0x49: disk_1349(regs, device); break; |
| 619 | case 0x4e: disk_134e(regs, device); break; |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 620 | default: disk_13XX(regs, device); break; |
| 621 | } |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 622 | } |
| 623 | |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 624 | |
| 625 | /**************************************************************** |
Kevin O'Connor | b74102d | 2008-03-03 21:57:30 -0500 | [diff] [blame] | 626 | * Entry points |
| 627 | ****************************************************************/ |
| 628 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 629 | static u8 |
Kevin O'Connor | 180a959 | 2008-03-04 22:50:53 -0500 | [diff] [blame] | 630 | get_device(struct bregs *regs, u8 iscd, u8 drive) |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 631 | { |
| 632 | // basic check : device has to be defined |
| 633 | if (drive >= CONFIG_MAX_ATA_DEVICES) { |
| 634 | disk_ret(regs, DISK_RET_EPARAM); |
| 635 | return CONFIG_MAX_ATA_DEVICES; |
| 636 | } |
| 637 | |
| 638 | // Get the ata channel |
Kevin O'Connor | 609da23 | 2008-12-28 23:18:57 -0500 | [diff] [blame] | 639 | u8 device = GET_GLOBAL(ATA.idmap[iscd][drive]); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 640 | |
| 641 | // basic check : device has to be valid |
| 642 | if (device >= CONFIG_MAX_ATA_DEVICES) { |
| 643 | disk_ret(regs, DISK_RET_EPARAM); |
| 644 | return CONFIG_MAX_ATA_DEVICES; |
| 645 | } |
| 646 | |
| 647 | return device; |
| 648 | } |
| 649 | |
| 650 | static void |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 651 | handle_legacy_disk(struct bregs *regs, u8 drive) |
| 652 | { |
| 653 | if (drive < 0x80) { |
| 654 | floppy_13(regs, drive); |
| 655 | return; |
| 656 | } |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 657 | |
| 658 | if (! CONFIG_ATA) { |
| 659 | // XXX - old code had other disk access method. |
| 660 | disk_ret(regs, DISK_RET_EPARAM); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 661 | return; |
| 662 | } |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 663 | |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 664 | if (drive >= 0xe0) { |
Kevin O'Connor | 180a959 | 2008-03-04 22:50:53 -0500 | [diff] [blame] | 665 | u8 device = get_device(regs, 1, drive - 0xe0); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 666 | if (device >= CONFIG_MAX_ATA_DEVICES) |
| 667 | return; |
| 668 | cdrom_13(regs, device); |
| 669 | return; |
| 670 | } |
| 671 | |
Kevin O'Connor | 180a959 | 2008-03-04 22:50:53 -0500 | [diff] [blame] | 672 | u8 device = get_device(regs, 0, drive - 0x80); |
Kevin O'Connor | e43df9e | 2008-03-01 22:16:32 -0500 | [diff] [blame] | 673 | if (device >= CONFIG_MAX_ATA_DEVICES) |
| 674 | return; |
| 675 | disk_13(regs, device); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 676 | } |
| 677 | |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 678 | void VISIBLE16 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 679 | handle_40(struct bregs *regs) |
| 680 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 681 | debug_enter(regs, DEBUG_HDL_40); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 682 | handle_legacy_disk(regs, regs->dl); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | // INT 13h Fixed Disk Services Entry Point |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 686 | void VISIBLE16 |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 687 | handle_13(struct bregs *regs) |
| 688 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 689 | debug_enter(regs, DEBUG_HDL_13); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 690 | u8 drive = regs->dl; |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 691 | |
Kevin O'Connor | dfa1650 | 2008-03-22 20:13:08 -0400 | [diff] [blame] | 692 | if (CONFIG_CDROM_EMU) { |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 693 | if (regs->ah == 0x4b) { |
| 694 | cdemu_134b(regs); |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 695 | return; |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 696 | } |
Kevin O'Connor | 4a16ef6 | 2008-12-31 00:09:28 -0500 | [diff] [blame] | 697 | u16 ebda_seg = get_ebda_seg(); |
| 698 | if (GET_EBDA2(ebda_seg, cdemu.active)) { |
Kevin O'Connor | 5c0c4b7 | 2009-02-17 20:40:59 -0500 | [diff] [blame] | 699 | u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_drive); |
| 700 | if (drive == emudrive) { |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 701 | cdemu_13(regs); |
Kevin O'Connor | 6c78122 | 2008-03-09 12:19:23 -0400 | [diff] [blame] | 702 | return; |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 703 | } |
Kevin O'Connor | 5c0c4b7 | 2009-02-17 20:40:59 -0500 | [diff] [blame] | 704 | if (drive < 0xe0 && ((emudrive ^ drive) & 0x80) == 0) |
Kevin O'Connor | 180a959 | 2008-03-04 22:50:53 -0500 | [diff] [blame] | 705 | drive--; |
Kevin O'Connor | 941d3e4 | 2008-03-04 19:45:04 -0500 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | handle_legacy_disk(regs, drive); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | // record completion in BIOS task complete flag |
Kevin O'Connor | 1978676 | 2008-03-05 21:09:59 -0500 | [diff] [blame] | 712 | void VISIBLE16 |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 713 | handle_76() |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 714 | { |
Kevin O'Connor | 15c1f22 | 2008-06-12 22:59:43 -0400 | [diff] [blame] | 715 | debug_isr(DEBUG_ISR_76); |
Kevin O'Connor | ed12849 | 2008-03-11 11:14:59 -0400 | [diff] [blame] | 716 | SET_BDA(disk_interrupt_flag, 0xff); |
Kevin O'Connor | f54c150 | 2008-06-14 15:56:16 -0400 | [diff] [blame] | 717 | eoi_pic2(); |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 718 | } |
Kevin O'Connor | 3085376 | 2009-01-17 18:49:20 -0500 | [diff] [blame] | 719 | |
| 720 | // Old Fixed Disk Parameter Table (newer tables are in the ebda). |
| 721 | struct fdpt_s OldFDPT VAR16FIXED(0xe401); |