@@ -938,6 +938,21 @@ static int handle_cmd(AHCIState *s, int port, int slot)
* do, I simply assume non-used fields as reserved and OR everything
* together, independent of the command.
*/
+ // enable lba and lba48 mode, otherwise the bit won't get set until the command is completed, cause read/write corruption
+ ide_state->lba48 = (cmd_fis[2] == WIN_READDMA_EXT
+ || cmd_fis[2] == WIN_READ_EXT
+ || cmd_fis[2] == WIN_READDMA_QUEUED_EXT
+ || cmd_fis[2] == WIN_READ_NATIVE_MAX_EXT
+ || cmd_fis[2] == WIN_MULTREAD_EXT
+ || cmd_fis[2] == WIN_WRITE_EXT
+ || cmd_fis[2] == WIN_WRITEDMA_EXT
+ || cmd_fis[2] == WIN_WRITEDMA_QUEUED_EXT
+ || cmd_fis[2] == WIN_SET_MAX_EXT
+ || cmd_fis[2] == WIN_MULTWRITE_EXT
+ || cmd_fis[2] == WIN_VERIFY_EXT
+ || cmd_fis[2] == WIN_FLUSH_CACHE_EXT
+ );
+ ide_state->select |= 0x40;
ide_set_sector(ide_state, ((uint64_t)cmd_fis[10] << 40)
| ((uint64_t)cmd_fis[9] << 32)
/* This is used for LBA48 commands */
@@ -445,9 +445,23 @@ void ide_transfer_stop(IDEState *s)
s->status &= ~DRQ_STAT;
}
+#define DEBUG_SECTOR 1
+
+#if DEBUG_SECTOR
+#define DPRINTF(fmt, ...) \
+ do { printf("debug_sector: " fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+/* Leave a chunk of memory at the top of RAM for the BIOS ACPI tables. */
+#define ACPI_DATA_SIZE 0x10000
+#define BIOS_CFG_IOPORT 0x510
+
int64_t ide_get_sector(IDEState *s)
{
int64_t sector_num;
+
if (s->select & 0x40) {
/* lba */
if (!s->lba48) {
@@ -464,12 +478,18 @@ int64_t ide_get_sector(IDEState *s)
sector_num = ((s->hcyl << 8) | s->lcyl) * s->heads * s->sectors +
(s->select & 0x0f) * s->sectors + (s->sector - 1);
}
+#if DEBUG_SECTOR
+ DPRINTF("get_sector: %lx\n", sector_num);
+#endif
return sector_num;
}
void ide_set_sector(IDEState *s, int64_t sector_num)
{
unsigned int cyl, r;
+#if DEBUG_SECTOR
+ DPRINTF("set_sector: %lx\n", sector_num);
+#endif
if (s->select & 0x40) {
if (!s->lba48) {
s->select = (s->select & 0xf0) | (sector_num >> 24);