diff --git a/src/opensuperclone/common.c b/src/opensuperclone/common.c index 453078e..b2f7b40 100644 --- a/src/opensuperclone/common.c +++ b/src/opensuperclone/common.c @@ -144,7 +144,7 @@ int create_dma_table_ccc(void) table_entry_count_ccc = max_entries; break; } - int n = (i * 16) + superbyte_ccc[15]; // potential superbyte + int n = (i * 16) + 0x80; uint32_t dword = buffer_physical_address_ccc[i]; memcpy(table_buffer_ccc + n, &dword, 4); memset(table_buffer_ccc + n + 4, 0, 8); @@ -240,11 +240,11 @@ int create_dma_table_ccc(void) // if last page then mark it if (i == page_count - 1) { - c = superbyte_ccc[15]; // potential superbyte + c = 0x80; } else { - c = superbyte_ccc[11]; // potential superbyte + c = 0x00; } memcpy(table_buffer_ccc + 7 + (i * 8), &c, 1); #ifdef DEBUG diff --git a/src/opensuperclone/common.h b/src/opensuperclone/common.h index 9e7f22d..a506ad6 100644 --- a/src/opensuperclone/common.h +++ b/src/opensuperclone/common.h @@ -292,17 +292,6 @@ char current_time_ccc[40]; unsigned char random_data_ccc[2048]; // char *driver_buffer_ccc; -unsigned char sbyte_ccc[16]; -unsigned char superbyte_ccc[1024]; -int license_type_ccc; -int license_version_ccc; -int license_time_ccc; -int activation_type_ccc; -int activation_days_remaining_ccc; -int check_command_ccc; -int check_read_ccc; -int check_write_ccc; - int disk1_fd_ccc; int disk2_fd_ccc; int current_disk_ccc; diff --git a/src/opensuperclone/driver/opensuperclone_driver.c b/src/opensuperclone/driver/opensuperclone_driver.c index 6fd7c37..07f58fc 100644 --- a/src/opensuperclone/driver/opensuperclone_driver.c +++ b/src/opensuperclone/driver/opensuperclone_driver.c @@ -98,7 +98,7 @@ } \ } while (0) -#define DRIVER_VERSION "2.6_20211126" +#define DRIVER_VERSION "2.6.1" MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("Driver for OpenSuperClone"); diff --git a/src/opensuperclone/io.c b/src/opensuperclone/io.c index 08cc71b..4453126 100644 --- a/src/opensuperclone/io.c +++ b/src/opensuperclone/io.c @@ -674,15 +674,15 @@ int do_usb_cmd_ccc(void) usb_csw_valid_ccc = 0; usb_tag_ccc++; memset(usbcbwbuffer_ccc, 0, USBCBW_BUFFER_SIZE); - memcpy(usbcbwbuffer_ccc + superbyte_ccc[71], passthrough_ccc.scsi_cmd, command_length_ccc); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[72], &command_length_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73], &usb_transfer_direction_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73] + 1, &usb_lun_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[74], &usb_tag_ccc, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x0f, passthrough_ccc.scsi_cmd, command_length_ccc); + memcpy(usbcbwbuffer_ccc + 0x0e, &command_length_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c, &usb_transfer_direction_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c + 1, &usb_lun_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x04, &usb_tag_ccc, 4); usb_transfer_length_ccc = ccc_main_buffer_size_ccc; - memcpy(usbcbwbuffer_ccc + superbyte_ccc[75], &usb_transfer_length_ccc, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x08, &usb_transfer_length_ccc, 4); uint32_t cbwsig = 0x43425355; - memcpy(usbcbwbuffer_ccc + superbyte_ccc[76], &cbwsig, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x00, &cbwsig, 4); cbw_timeout_ccc = usb_timeout_ccc; cbw_ret = do_usb_send_cbw_ccc(cbw_timeout_ccc); if (cbw_ret != USBCBW_BUFFER_SIZE) @@ -821,14 +821,14 @@ int usb_get_sense_ccc(void) uint32_t csw_residue = 0; usb_tag_ccc++; memset(usbcbwbuffer_ccc, 0, USBCBW_BUFFER_SIZE); - memcpy(usbcbwbuffer_ccc + superbyte_ccc[71], passthrough_ccc.scsi_cmd, command_length_ccc); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[72], &command_length_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73], &usb_transfer_direction_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73] + 1, &usb_lun_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[74], &usb_tag_ccc, 4); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[75], &usb_transfer_length_ccc, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x0f, passthrough_ccc.scsi_cmd, command_length_ccc); + memcpy(usbcbwbuffer_ccc + 0x0e, &command_length_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c, &usb_transfer_direction_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c + 1, &usb_lun_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x04, &usb_tag_ccc, 4); + memcpy(usbcbwbuffer_ccc + 0x08, &usb_transfer_length_ccc, 4); uint32_t cbwsig = 0x43425355; - memcpy(usbcbwbuffer_ccc + superbyte_ccc[76], &cbwsig, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x00, &cbwsig, 4); cbw_timeout_ccc = usb_timeout_ccc; cbw_ret = do_usb_send_cbw_ccc(cbw_timeout_ccc); if (cbw_ret != USBCBW_BUFFER_SIZE) @@ -1057,14 +1057,14 @@ int usb_soft_hard_reset_ccc(unsigned char reset_type, int timeout) uint32_t csw_residue = 0; usb_tag_ccc++; memset(usbcbwbuffer_ccc, 0, USBCBW_BUFFER_SIZE); - memcpy(usbcbwbuffer_ccc + superbyte_ccc[71], passthrough_ccc.scsi_cmd, command_length_ccc); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[72], &command_length_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73], &usb_transfer_direction_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73] + 1, &usb_lun_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[74], &usb_tag_ccc, 4); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[75], &usb_transfer_length_ccc, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x0f, passthrough_ccc.scsi_cmd, command_length_ccc); + memcpy(usbcbwbuffer_ccc + 0x0e, &command_length_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c, &usb_transfer_direction_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c + 1, &usb_lun_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x04, &usb_tag_ccc, 4); + memcpy(usbcbwbuffer_ccc + 0x08, &usb_transfer_length_ccc, 4); uint32_t cbwsig = 0x43425355; - memcpy(usbcbwbuffer_ccc + superbyte_ccc[76], &cbwsig, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x00, &cbwsig, 4); cbw_timeout_ccc = usb_timeout_ccc; cbw_ret = do_usb_send_cbw_ccc(cbw_timeout_ccc); if (cbw_ret != USBCBW_BUFFER_SIZE) @@ -1147,14 +1147,14 @@ int usb_inquiry_ccc(int timeout) uint32_t csw_residue = 0; usb_tag_ccc++; memset(usbcbwbuffer_ccc, 0, USBCBW_BUFFER_SIZE); - memcpy(usbcbwbuffer_ccc + superbyte_ccc[71], passthrough_ccc.scsi_cmd, command_length_ccc); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[72], &command_length_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73], &usb_transfer_direction_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73] + 1, &usb_lun_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[74], &usb_tag_ccc, 4); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[75], &usb_transfer_length_ccc, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x0f, passthrough_ccc.scsi_cmd, command_length_ccc); + memcpy(usbcbwbuffer_ccc + 0x0e, &command_length_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c, &usb_transfer_direction_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c + 1, &usb_lun_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x04, &usb_tag_ccc, 4); + memcpy(usbcbwbuffer_ccc + 0x08, &usb_transfer_length_ccc, 4); uint32_t cbwsig = 0x43425355; - memcpy(usbcbwbuffer_ccc + superbyte_ccc[76], &cbwsig, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x00, &cbwsig, 4); cbw_timeout_ccc = usb_timeout_ccc; cbw_ret = do_usb_send_cbw_ccc(cbw_timeout_ccc); if (cbw_ret != USBCBW_BUFFER_SIZE) @@ -1262,14 +1262,14 @@ int usb_identify_ccc(int timeout) uint32_t csw_residue = 0; usb_tag_ccc++; memset(usbcbwbuffer_ccc, 0, USBCBW_BUFFER_SIZE); - memcpy(usbcbwbuffer_ccc + superbyte_ccc[71], passthrough_ccc.scsi_cmd, command_length_ccc); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[72], &command_length_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73], &usb_transfer_direction_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73] + 1, &usb_lun_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[74], &usb_tag_ccc, 4); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[75], &usb_transfer_length_ccc, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x0f, passthrough_ccc.scsi_cmd, command_length_ccc); + memcpy(usbcbwbuffer_ccc + 0x0e, &command_length_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c, &usb_transfer_direction_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c + 1, &usb_lun_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x04, &usb_tag_ccc, 4); + memcpy(usbcbwbuffer_ccc + 0x08, &usb_transfer_length_ccc, 4); uint32_t cbwsig = 0x43425355; - memcpy(usbcbwbuffer_ccc + superbyte_ccc[76], &cbwsig, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x00, &cbwsig, 4); cbw_timeout_ccc = usb_timeout_ccc; cbw_ret = do_usb_send_cbw_ccc(cbw_timeout_ccc); if (cbw_ret != USBCBW_BUFFER_SIZE) @@ -1387,14 +1387,14 @@ int usb_read_smart_ccc(int timeout, unsigned char reg[7]) uint32_t csw_residue = 0; usb_tag_ccc++; memset(usbcbwbuffer_ccc, 0, USBCBW_BUFFER_SIZE); - memcpy(usbcbwbuffer_ccc + superbyte_ccc[71], passthrough_ccc.scsi_cmd, command_length_ccc); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[72], &command_length_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73], &usb_transfer_direction_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73] + 1, &usb_lun_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[74], &usb_tag_ccc, 4); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[75], &usb_transfer_length_ccc, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x0f, passthrough_ccc.scsi_cmd, command_length_ccc); + memcpy(usbcbwbuffer_ccc + 0x0e, &command_length_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c, &usb_transfer_direction_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c + 1, &usb_lun_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x04, &usb_tag_ccc, 4); + memcpy(usbcbwbuffer_ccc + 0x08, &usb_transfer_length_ccc, 4); uint32_t cbwsig = 0x43425355; - memcpy(usbcbwbuffer_ccc + superbyte_ccc[76], &cbwsig, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x00, &cbwsig, 4); cbw_timeout_ccc = usb_timeout_ccc; cbw_ret = do_usb_send_cbw_ccc(cbw_timeout_ccc); if (cbw_ret != USBCBW_BUFFER_SIZE) @@ -1528,14 +1528,14 @@ int usb_check_capacity_ccc(int timeout) uint32_t csw_residue = 0; usb_tag_ccc++; memset(usbcbwbuffer_ccc, 0, USBCBW_BUFFER_SIZE); - memcpy(usbcbwbuffer_ccc + superbyte_ccc[71], passthrough_ccc.scsi_cmd, command_length_ccc); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[72], &command_length_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73], &usb_transfer_direction_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[73] + 1, &usb_lun_ccc, 1); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[74], &usb_tag_ccc, 4); // potential superbyte - memcpy(usbcbwbuffer_ccc + superbyte_ccc[75], &usb_transfer_length_ccc, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x0f, passthrough_ccc.scsi_cmd, command_length_ccc); + memcpy(usbcbwbuffer_ccc + 0x0e, &command_length_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c, &usb_transfer_direction_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x0c + 1, &usb_lun_ccc, 1); + memcpy(usbcbwbuffer_ccc + 0x04, &usb_tag_ccc, 4); + memcpy(usbcbwbuffer_ccc + 0x08, &usb_transfer_length_ccc, 4); uint32_t cbwsig = 0x43425355; - memcpy(usbcbwbuffer_ccc + superbyte_ccc[76], &cbwsig, 4); // potential superbyte + memcpy(usbcbwbuffer_ccc + 0x00, &cbwsig, 4); cbw_timeout_ccc = usb_timeout_ccc; cbw_ret = do_usb_send_cbw_ccc(cbw_timeout_ccc); if (cbw_ret != USBCBW_BUFFER_SIZE) @@ -2050,177 +2050,175 @@ int do_ata_pio_read_ccc(int command_type) int ahci_rw_ccc(int command_type, int write_bit) { - if (superbyte_ccc[30] == 0xd9) + set_number_variable_value_ccc("$data_transferred", 0); + int fail_level = 0x0; + int success = 1; + int what_changed = 0; + + // clear any interrupt bits + ahci_interrupt_changed_ccc = true; + memset(port_virt_addr_ccc + 0x10, 0xff, 4); + + // clear all error bits + memset(port_virt_addr_ccc + 0x30, 0xff, 4); + + // wait for drive to be ready + return_value_ccc = wait_not_busy_or_drq_ccc(initial_busy_wait_time_ccc, 0); + // fprintf (stdout, "return from initial wait = %d\n", return_value_ccc); //debug + if (stop_signal_ccc) { - set_number_variable_value_ccc("$data_transferred", 0); - int fail_level = 0x0; - int success = 1; - int what_changed = 0; + return STOP_SIGNAL_RETURN_CODE; + } + if (return_value_ccc != 0) + { + int status = do_soft_reset_ccc(0); + if (status) + { + success = 0; + fail_level = 0x20 + return_value_ccc; + } + } - // clear any interrupt bits - ahci_interrupt_changed_ccc = true; - memset(port_virt_addr_ccc + superbyte_ccc[7], 0xff, 4); // potential superbyte + if (success) + { +#ifdef DEBUG + int i; + for (i = 0; i < 0x80; i += 4) + { + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + // fprintf (stdout, "%x %08x\n", i, io_doubleword_ccc); //debug + } +#endif - // clear all error bits - memset(port_virt_addr_ccc + superbyte_ccc[18], 0xff, 4); // potential superbyte + // clear the command list + memset(command_list_buffer_ccc, 0, command_list_size_ccc); + // set the command FIS length, 5 dwords for h2d, also contains read/write bit + io_singlebyte_ccc = 5; + io_singlebyte_ccc = io_singlebyte_ccc | ((write_bit & 1) << 6); + memcpy(command_list_buffer_ccc, &io_singlebyte_ccc, 1); - // wait for drive to be ready - return_value_ccc = wait_not_busy_or_drq_ccc(initial_busy_wait_time_ccc, 0); - // fprintf (stdout, "return from initial wait = %d\n", return_value_ccc); //debug + set_and_send_regs_ccc(command_type); // this does not send for ahci + + // set the start bit + enable_start_ccc(START_BIT_TIME); + + if (wait_for_ds_bit_ccc) + { + // set the device status bit + io_doubleword_ccc = 1; + memcpy(port_virt_addr_ccc + 0x34, &io_doubleword_ccc, 4); + } + + // set the command issue bit + enable_command_issue_ccc(COMMAND_BIT_TIME); + + // wait while busy, if timeout do soft reset + return_value_ccc = wait_not_busy_or_drq_ccc(soft_reset_time_ccc + first_read_time_ccc, 1); + first_read_time_ccc = 0; + // fprintf (stdout, "return from wait = %d\n", return_value_ccc); //debug + wait_for_ds_bit_ccc = false; if (stop_signal_ccc) { return STOP_SIGNAL_RETURN_CODE; } if (return_value_ccc != 0) { - int status = do_soft_reset_ccc(0); - if (status) + success = 0; + // if err was set for fpdma command then read the ncq error log + if (return_value_ccc == 4) { - success = 0; - fail_level = 0x20 + return_value_ccc; + // fprintf (stdout, "port status before ncq read log = 0x%08x\n", get_ahci_status_ccc()); //debug + // read_ncq_error_log_ccc(); + // fprintf (stdout, "port status after ncq read log = 0x%08x\n", get_ahci_status_ccc()); //debug } - } - - if (success) - { -#ifdef DEBUG - int i; - for (i = 0; i < 0x80; i += 4) + // only do reset if soft reset time exceeded, but not if general timeout or fault + else if (return_value_ccc == 1) { - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - // fprintf (stdout, "%x %08x\n", i, io_doubleword_ccc); //debug - } -#endif - - // clear the command list - memset(command_list_buffer_ccc, 0, command_list_size_ccc); - // set the command FIS length, 5 dwords for h2d, also contains read/write bit - io_singlebyte_ccc = 5; - io_singlebyte_ccc = io_singlebyte_ccc | ((write_bit & 1) << 6); - memcpy(command_list_buffer_ccc, &io_singlebyte_ccc, 1); - - set_and_send_regs_ccc(command_type); // this does not send for ahci - - // set the start bit - enable_start_ccc(START_BIT_TIME); - - if (wait_for_ds_bit_ccc) - { - // set the device status bit - io_doubleword_ccc = 1; - memcpy(port_virt_addr_ccc + superbyte_ccc[69], &io_doubleword_ccc, 4); // potential superbyte - } - - // set the command issue bit - enable_command_issue_ccc(COMMAND_BIT_TIME); - - // wait while busy, if timeout do soft reset - return_value_ccc = wait_not_busy_or_drq_ccc(soft_reset_time_ccc + first_read_time_ccc, 1); - first_read_time_ccc = 0; - // fprintf (stdout, "return from wait = %d\n", return_value_ccc); //debug - wait_for_ds_bit_ccc = false; - if (stop_signal_ccc) - { - return STOP_SIGNAL_RETURN_CODE; - } - if (return_value_ccc != 0) - { - success = 0; - // if err was set for fpdma command then read the ncq error log - if (return_value_ccc == 4) + fail_level = 0x30 + return_value_ccc; + return_value_ccc = soft_reset_ccc(0); + if (return_value_ccc != 0) { - // fprintf (stdout, "port status before ncq read log = 0x%08x\n", get_ahci_status_ccc()); //debug - // read_ncq_error_log_ccc(); - // fprintf (stdout, "port status after ncq read log = 0x%08x\n", get_ahci_status_ccc()); //debug - } - // only do reset if soft reset time exceeded, but not if general timeout or fault - else if (return_value_ccc == 1) - { - fail_level = 0x30 + return_value_ccc; - return_value_ccc = soft_reset_ccc(0); - if (return_value_ccc != 0) - { - fail_level = 0x40 + return_value_ccc; - } - } - // if it failed the change check and drive is hung then do reset - else if (return_value_ccc == 8) - { - what_changed = check_for_unwanted_changes_ccc(); - return_value_ccc = wait_not_busy_or_drq_ccc(1000, 0); - if (return_value_ccc) - { - return_value_ccc = soft_reset_ccc(0); - } - fail_level = 0x80 + return_value_ccc; - } - else - { - fail_level = 0x50 + return_value_ccc; + fail_level = 0x40 + return_value_ccc; } } - - // check for unwanted changes - if (success) + // if it failed the change check and drive is hung then do reset + else if (return_value_ccc == 8) { what_changed = check_for_unwanted_changes_ccc(); - // get port status/error - unsigned int port_error = get_ahci_error_ccc(); - if (port_error) + return_value_ccc = wait_not_busy_or_drq_ccc(1000, 0); + if (return_value_ccc) { - // what_changed = what_changed | 0x2000; - // memcpy(&io_byte_ccc[1], port_virt_addr_ccc + superbyte_ccc[8], 1); // status //potential superbyte - // memcpy(&io_byte_ccc[2], port_virt_addr_ccc + superbyte_ccc[9], 1); // error //potential superbyte - // sprintf (tempmessage_ccc, "port ERR = 0x%08x s/e=0x%02x/0x%02x fail=0x%04x changed=0x%04x\n", port_error, io_byte_ccc[1], io_byte_ccc[2], fail_level, what_changed); - sprintf(tempmessage_ccc, "port ERR = 0x%08x\n", port_error); - message_console_log_ccc(tempmessage_ccc, 0); - // fprintf (stdout, "port ERR = 0x%08x\n", port_error); - } - unsigned int port_status = get_ahci_status_ccc(); - if (port_status && !use_fpdma_ccc) - { - // what_changed = what_changed | 0x2000; - // memcpy(&io_byte_ccc[1], port_virt_addr_ccc + superbyte_ccc[8], 1); // status //potential superbyte - // memcpy(&io_byte_ccc[2], port_virt_addr_ccc + superbyte_ccc[9], 1); // error //potential superbyte - // sprintf (tempmessage_ccc, "port DS = 0x%08x s/e=0x%02x/0x%02x fail=0x%04x changed=0x%04x\n", port_status, io_byte_ccc[1], io_byte_ccc[2], fail_level, what_changed); - sprintf(tempmessage_ccc, "port DS = 0x%08x\n", port_status); - message_console_log_ccc(tempmessage_ccc, 0); - // fprintf (stdout, "port DS = 0x%08x\n", port_status); + return_value_ccc = soft_reset_ccc(0); } + fail_level = 0x80 + return_value_ccc; + } + else + { + fail_level = 0x50 + return_value_ccc; } } - fail_level = fail_level + what_changed; - - disable_start_ccc(START_BIT_TIME); - - // clear any interrupt bits - ahci_interrupt_changed_ccc = true; - memset(port_virt_addr_ccc + superbyte_ccc[7], 0xff, 4); // potential superbyte - - // clear all error bits - memset(port_virt_addr_ccc + superbyte_ccc[18], 0xff, 4); // potential superbyte - - // get recent copy of status and error - memcpy(&io_byte_ccc[1], port_virt_addr_ccc + superbyte_ccc[8], 1); // status //potential superbyte - memcpy(&io_byte_ccc[2], port_virt_addr_ccc + superbyte_ccc[9], 1); // error //potential superbyte + // check for unwanted changes if (success) { - set_number_variable_value_ccc("$data_transferred", ccc_main_buffer_size_ccc); - } - - return_value_ccc = post_direct_ccc(command_type); - - set_number_variable_value_ccc("$command_status", fail_level); - if (superclone_ccc) - { - return (fail_level); - } - else - { - return 0; + what_changed = check_for_unwanted_changes_ccc(); + // get port status/error + unsigned int port_error = get_ahci_error_ccc(); + if (port_error) + { + // what_changed = what_changed | 0x2000; + // memcpy(&io_byte_ccc[1], port_virt_addr_ccc + 0x20, 1); // status + // memcpy(&io_byte_ccc[2], port_virt_addr_ccc + 0x21, 1); // error + // sprintf (tempmessage_ccc, "port ERR = 0x%08x s/e=0x%02x/0x%02x fail=0x%04x changed=0x%04x\n", port_error, io_byte_ccc[1], io_byte_ccc[2], fail_level, what_changed); + sprintf(tempmessage_ccc, "port ERR = 0x%08x\n", port_error); + message_console_log_ccc(tempmessage_ccc, 0); + // fprintf (stdout, "port ERR = 0x%08x\n", port_error); + } + unsigned int port_status = get_ahci_status_ccc(); + if (port_status && !use_fpdma_ccc) + { + // what_changed = what_changed | 0x2000; + // memcpy(&io_byte_ccc[1], port_virt_addr_ccc + 0x20, 1); // status + // memcpy(&io_byte_ccc[2], port_virt_addr_ccc + 0x21, 1); // error + // sprintf (tempmessage_ccc, "port DS = 0x%08x s/e=0x%02x/0x%02x fail=0x%04x changed=0x%04x\n", port_status, io_byte_ccc[1], io_byte_ccc[2], fail_level, what_changed); + sprintf(tempmessage_ccc, "port DS = 0x%08x\n", port_status); + message_console_log_ccc(tempmessage_ccc, 0); + // fprintf (stdout, "port DS = 0x%08x\n", port_status); + } } } + fail_level = fail_level + what_changed; + + disable_start_ccc(START_BIT_TIME); + + // clear any interrupt bits + ahci_interrupt_changed_ccc = true; + memset(port_virt_addr_ccc + 0x10, 0xff, 4); + + // clear all error bits + memset(port_virt_addr_ccc + 0x30, 0xff, 4); + + // get recent copy of status and error + memcpy(&io_byte_ccc[1], port_virt_addr_ccc + 0x20, 1); // status + memcpy(&io_byte_ccc[2], port_virt_addr_ccc + 0x21, 1); // error + + if (success) + { + set_number_variable_value_ccc("$data_transferred", ccc_main_buffer_size_ccc); + } + + return_value_ccc = post_direct_ccc(command_type); + + set_number_variable_value_ccc("$command_status", fail_level); + if (superclone_ccc) + { + return (fail_level); + } + else + { + return 0; + } + return 0; } @@ -2288,17 +2286,17 @@ int do_ata_dma_read_ccc(int command_type) set_table_address_ccc(); // Clear the Interrupt bit and Error bit in the Status register. - c = superbyte_ccc[1]; // potential superbyte + c = 0x06; outb(c, bus_base_address_ccc + 2); // set the read/write bit to 1 (read) - c = superbyte_ccc[2]; // potential superbyte + c = 0x08; outb(c, bus_base_address_ccc); set_and_send_regs_ccc(command_type); // set the start/stop bit - c = superbyte_ccc[3]; // potential superbyte + c = 0x09; outb(c, bus_base_address_ccc); // wait while busy or drq, if timeout do soft reset @@ -2328,14 +2326,14 @@ int do_ata_dma_read_ccc(int command_type) } // clear the start/stop bit - c = superbyte_ccc[2]; // potential superbyte + c = 0x08; outb(c, bus_base_address_ccc); // read the bus master status byte to flush cache and finalize transfer io_byte_ccc[8] = inb(bus_base_address_ccc + 2); // Clear the Interrupt bit and Error bit in the Status register. - c = superbyte_ccc[1]; // potential superbyte + c = 0x06; outb(c, bus_base_address_ccc + 2); // fprintf (stdout, "%02x\n", io_byte_ccc[8]); @@ -2542,151 +2540,9 @@ int do_ata_pio_write_ccc(int command_type) int do_ata_dma_write_ccc(int command_type) { - if (superbyte_ccc[32] == 0x83) + if (ccc_main_buffer_size_ccc > max_dma_size_ccc) { - if (ccc_main_buffer_size_ccc > max_dma_size_ccc) - { - sprintf(tempmessage_ccc, "ERROR: Maximum DMA buffer size (%llu) exceeded.\n", max_dma_size_ccc); - if (superclone_ccc) - { - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - } - else - { - message_now_ccc(tempmessage_ccc); - } - return (-1); - } - // ahci - if (ahci_mode_ccc) - { - return_value_ccc = ahci_rw_ccc(command_type, 1); - return (return_value_ccc); - } - - // ide - else - { - set_number_variable_value_ccc("$data_transferred", 0); - int fail_level = 0x0; - int success = 1; - unsigned char c; - - // set device, this is important to do first to make sure the proper drive is selected - set_device_ccc(reg_base_address_ccc, device_select_base_ccc); - // tell device not to send interrupts - outb(2, control_base_address_ccc); - - // wait for drive to be ready - return_value_ccc = wait_not_busy_or_drq_ccc(initial_busy_wait_time_ccc, 0); - if (stop_signal_ccc) - { - return STOP_SIGNAL_RETURN_CODE; - } - if (return_value_ccc != 0) - { - return_value_ccc = soft_reset_ccc(0); - } - if (return_value_ccc != 0) - { - success = 0; - fail_level = 0x10 + return_value_ccc; - } - // do this again in case there was a reset event - // set device, this is important to do first to make sure the proper drive is selected - set_device_ccc(reg_base_address_ccc, device_select_base_ccc); - // tell device not to send interrupts - outb(2, control_base_address_ccc); - - if (success) - { - // put table address into controler - set_table_address_ccc(); - - // Clear the Interrupt bit and Error bit in the Status register. - c = superbyte_ccc[1]; // potential superbyte - outb(c, bus_base_address_ccc + 2); - - // set the read/write bit to 0 (write) - c = superbyte_ccc[4]; // potential superbyte - outb(c, bus_base_address_ccc); - - set_and_send_regs_ccc(command_type); - - // set the start/stop bit - c = superbyte_ccc[5]; // potential superbyte - outb(c, bus_base_address_ccc); - - // wait while busy or drq, if timeout do soft reset - return_value_ccc = wait_not_busy_or_drq_ccc(soft_reset_time_ccc + first_read_time_ccc, 0); - first_read_time_ccc = 0; - if (stop_signal_ccc) - { - return STOP_SIGNAL_RETURN_CODE; - } - if (return_value_ccc != 0) - { - success = 0; - // only do reset if soft reset time exceeded, but not if general timeout or fault - if (return_value_ccc == 1) - { - fail_level = 0x30 + return_value_ccc; - return_value_ccc = soft_reset_ccc(0); - if (return_value_ccc != 0) - { - fail_level = 0x40 + return_value_ccc; - } - } - else - { - fail_level = 0x50 + return_value_ccc; - } - } - - // clear the start/stop bit - c = superbyte_ccc[4]; // potential superbyte - outb(c, bus_base_address_ccc); - - // read the bus master status byte to flush cache and finalize transfer - io_byte_ccc[8] = inb(bus_base_address_ccc + 2); - - // Clear the Interrupt bit and Error bit in the Status register. - c = superbyte_ccc[1]; // potential superbyte - outb(c, bus_base_address_ccc + 2); - - // fprintf (stdout, "%02x\n", io_byte_ccc[8]); - set_number_variable_value_ccc("$bus_master_status", io_byte_ccc[8]); - } - - if (success) - { - set_number_variable_value_ccc("$data_transferred", ccc_main_buffer_size_ccc); - } - - return_value_ccc = post_direct_ccc(command_type); - // if success then check if still correct device - if (return_value_ccc && success) - { - fail_level = 0x70 + return_value_ccc; - success = 0; - } - - set_number_variable_value_ccc("$command_status", fail_level); - if (superclone_ccc) - { - return (fail_level); - } - else - { - return 0; - } - } - } - else - { - sprintf(tempmessage_ccc, "ERROR: DMA not allowed in free version.\n"); + sprintf(tempmessage_ccc, "ERROR: Maximum DMA buffer size (%llu) exceeded.\n", max_dma_size_ccc); if (superclone_ccc) { message_error_ccc(tempmessage_ccc); @@ -2699,72 +2555,192 @@ int do_ata_dma_write_ccc(int command_type) } return (-1); } + // ahci + if (ahci_mode_ccc) + { + return_value_ccc = ahci_rw_ccc(command_type, 1); + return (return_value_ccc); + } + + // ide + else + { + set_number_variable_value_ccc("$data_transferred", 0); + int fail_level = 0x0; + int success = 1; + unsigned char c; + + // set device, this is important to do first to make sure the proper drive is selected + set_device_ccc(reg_base_address_ccc, device_select_base_ccc); + // tell device not to send interrupts + outb(2, control_base_address_ccc); + + // wait for drive to be ready + return_value_ccc = wait_not_busy_or_drq_ccc(initial_busy_wait_time_ccc, 0); + if (stop_signal_ccc) + { + return STOP_SIGNAL_RETURN_CODE; + } + if (return_value_ccc != 0) + { + return_value_ccc = soft_reset_ccc(0); + } + if (return_value_ccc != 0) + { + success = 0; + fail_level = 0x10 + return_value_ccc; + } + // do this again in case there was a reset event + // set device, this is important to do first to make sure the proper drive is selected + set_device_ccc(reg_base_address_ccc, device_select_base_ccc); + // tell device not to send interrupts + outb(2, control_base_address_ccc); + + if (success) + { + // put table address into controler + set_table_address_ccc(); + + // Clear the Interrupt bit and Error bit in the Status register. + c = 0x06; + outb(c, bus_base_address_ccc + 2); + + // set the read/write bit to 0 (write) + c = 0x00; + outb(c, bus_base_address_ccc); + + set_and_send_regs_ccc(command_type); + + // set the start/stop bit + c = 0x01; + outb(c, bus_base_address_ccc); + + // wait while busy or drq, if timeout do soft reset + return_value_ccc = wait_not_busy_or_drq_ccc(soft_reset_time_ccc + first_read_time_ccc, 0); + first_read_time_ccc = 0; + if (stop_signal_ccc) + { + return STOP_SIGNAL_RETURN_CODE; + } + if (return_value_ccc != 0) + { + success = 0; + // only do reset if soft reset time exceeded, but not if general timeout or fault + if (return_value_ccc == 1) + { + fail_level = 0x30 + return_value_ccc; + return_value_ccc = soft_reset_ccc(0); + if (return_value_ccc != 0) + { + fail_level = 0x40 + return_value_ccc; + } + } + else + { + fail_level = 0x50 + return_value_ccc; + } + } + + // clear the start/stop bit + c = 0x00; + outb(c, bus_base_address_ccc); + + // read the bus master status byte to flush cache and finalize transfer + io_byte_ccc[8] = inb(bus_base_address_ccc + 2); + + // Clear the Interrupt bit and Error bit in the Status register. + c = 0x06; + outb(c, bus_base_address_ccc + 2); + + // fprintf (stdout, "%02x\n", io_byte_ccc[8]); + set_number_variable_value_ccc("$bus_master_status", io_byte_ccc[8]); + } + + if (success) + { + set_number_variable_value_ccc("$data_transferred", ccc_main_buffer_size_ccc); + } + + return_value_ccc = post_direct_ccc(command_type); + // if success then check if still correct device + if (return_value_ccc && success) + { + fail_level = 0x70 + return_value_ccc; + success = 0; + } + + set_number_variable_value_ccc("$command_status", fail_level); + if (superclone_ccc) + { + return (fail_level); + } + else + { + return 0; + } + } + return (0); } int set_table_address_ccc(void) { - if (superbyte_ccc[33] == 0xb0) - { - // save current table address - table_address_backup_ccc[0] = inb(bus_base_address_ccc + 0 + superbyte_ccc[0]); // potential superbyte - table_address_backup_ccc[1] = inb(bus_base_address_ccc + 1 + superbyte_ccc[0]); // potential superbyte - table_address_backup_ccc[2] = inb(bus_base_address_ccc + 2 + superbyte_ccc[0]); // potential superbyte - table_address_backup_ccc[3] = inb(bus_base_address_ccc + 3 + superbyte_ccc[0]); // potential superbyte - table_address_changed_ccc = true; + // save current table address + table_address_backup_ccc[0] = inb(bus_base_address_ccc + 0 + 0x04); + table_address_backup_ccc[1] = inb(bus_base_address_ccc + 1 + 0x04); + table_address_backup_ccc[2] = inb(bus_base_address_ccc + 2 + 0x04); + table_address_backup_ccc[3] = inb(bus_base_address_ccc + 3 + 0x04); + table_address_changed_ccc = true; - // put table address into controler - unsigned char c; - c = table_physical_address_ccc; - outb(c, bus_base_address_ccc + 0 + superbyte_ccc[0]); // potential superbyte - c = table_physical_address_ccc >> 8; - outb(c, bus_base_address_ccc + 1 + superbyte_ccc[0]); // potential superbyte - c = table_physical_address_ccc >> 16; - outb(c, bus_base_address_ccc + 2 + superbyte_ccc[0]); // potential superbyte - c = table_physical_address_ccc >> 24; - outb(c, bus_base_address_ccc + 3 + superbyte_ccc[0]); // potential superbyte + // put table address into controler + unsigned char c; + c = table_physical_address_ccc; + outb(c, bus_base_address_ccc + 0 + 0x04); + c = table_physical_address_ccc >> 8; + outb(c, bus_base_address_ccc + 1 + 0x04); + c = table_physical_address_ccc >> 16; + outb(c, bus_base_address_ccc + 2 + 0x04); + c = table_physical_address_ccc >> 24; + outb(c, bus_base_address_ccc + 3 + 0x04); #ifdef DEBUG - if (debug_ccc & DEBUG34) + if (debug_ccc & DEBUG34) + { + fprintf(stdout, "table_physical_address=0x%llx\n", table_physical_address_ccc); + int size = 512; + int i; + for (i = 0; i < size; i += 16) { - fprintf(stdout, "table_physical_address=0x%llx\n", table_physical_address_ccc); - int size = 512; - int i; - for (i = 0; i < size; i += 16) + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < size; n++) { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < size; n++) - { - c = (unsigned char *)table_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < size; n++) - { - c = (unsigned char *)table_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); + c = (unsigned char *)table_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); } + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < size; n++) + { + c = (unsigned char *)table_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); + } + fprintf(stdout, "\n"); } -#endif } +#endif return (0); } int restore_table_address_ccc(void) { - if (superbyte_ccc[34] == 0x51) - { - outb(table_address_backup_ccc[0], bus_base_address_ccc + 0 + superbyte_ccc[0]); // potential superbyte - outb(table_address_backup_ccc[1], bus_base_address_ccc + 1 + superbyte_ccc[0]); // potential superbyte - outb(table_address_backup_ccc[2], bus_base_address_ccc + 2 + superbyte_ccc[0]); // potential superbyte - outb(table_address_backup_ccc[3], bus_base_address_ccc + 3 + superbyte_ccc[0]); // potential superbyte - table_address_changed_ccc = false; - } + outb(table_address_backup_ccc[0], bus_base_address_ccc + 0 + 0x04); + outb(table_address_backup_ccc[1], bus_base_address_ccc + 1 + 0x04); + outb(table_address_backup_ccc[2], bus_base_address_ccc + 2 + 0x04); + outb(table_address_backup_ccc[3], bus_base_address_ccc + 3 + 0x04); + table_address_changed_ccc = false; + return (0); } @@ -2864,268 +2840,265 @@ int soft_reset_ccc(int disk_fd) } if (ahci_mode_ccc) { - if (superbyte_ccc[35] == 0x26) - { // ahci #ifdef DEBUG - int i; - if (debug_ccc & DEBUG35) + int i; + if (debug_ccc & DEBUG35) + { + // fprintf (stdout, "soft reset\n"); //debug + for (i = 0; i < 0x80; i += 4) { - // fprintf (stdout, "soft reset\n"); //debug - for (i = 0; i < 0x80; i += 4) + break; // debug + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) { - break; // debug - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) + if (!(n % 8)) { - if (!(n % 8)) - { - fprintf(stdout, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(stdout, "1"); - else - fprintf(stdout, "0"); + fprintf(stdout, " "); } - fprintf(stdout, "\n"); + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(stdout, "1"); + else + fprintf(stdout, "0"); } + fprintf(stdout, "\n"); } + } #endif - // clear the start bit - uint8_t byte; - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + // clear the start bit + uint8_t byte; + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + byte = byte & 0xfe; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); - // set the buffer size to 0 for no data transfer - unsigned long long backup_buffer_size = ccc_main_buffer_size_ccc; - ccc_main_buffer_size_ccc = 0; - set_main_buffer_ccc(); + // set the buffer size to 0 for no data transfer + unsigned long long backup_buffer_size = ccc_main_buffer_size_ccc; + ccc_main_buffer_size_ccc = 0; + set_main_buffer_ccc(); - int status = 0; + int status = 0; - if (hard_reset_time_ccc == 0) + if (hard_reset_time_ccc == 0) + { + // if forced then do hard reset without soft reset + status = hard_reset_ccc(disk_fd); + did_hard_reset_ccc = 1; + } + else + { + // try soft reset first + // clear the command list + memset(command_list_buffer_ccc, 0, command_list_size_ccc); + // set the command FIS length, 5 dwords for h2d, also contains read/write bit + io_singlebyte_ccc = 5; + io_singlebyte_ccc = io_singlebyte_ccc | ((1) << 6); + memcpy(command_list_buffer_ccc, &io_singlebyte_ccc, 1); + // set the reset bit in the command fis + memset(command_list_buffer_ccc + 1, 1, 1); + + // clear the fis buffer + memset(fis_buffer_ccc, 0, fis_size_ccc); + // clear the command FIS + memset(table_buffer_ccc, 0, 0x80); + // set FIS type + memset(table_buffer_ccc, REG_H2D, 1); + // set type as control + memset(table_buffer_ccc + 1, 0x00, 1); + // set the table entry length + uint16_t word = table_entry_count_ccc; + memcpy(command_list_buffer_ccc + 2, &word, 2); + // set the command table address + uint64_t qword = table_physical_address_ccc; + memcpy(command_list_buffer_ccc + 8, &qword, 8); + + // set the soft reset control bit + memset(table_buffer_ccc + 15, 4, 1); + + // set the command list override bit + byte = byte | 8; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); + // wait for clo bit to be clear + int check_bit = 1; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (check_bit) { - // if forced then do hard reset without soft reset + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + COMMAND_LIST_OVERRIDE_TIME) + { + // if it exceeds general timeout then quit + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + check_bit = byte & 0x08; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); + } + + // make sure fis is running + enable_fis_ccc(FIS_BIT_TIME); + + // set the start bit + enable_start_ccc(START_BIT_TIME); + + // set the command issue bit + enable_command_issue_ccc(COMMAND_BIT_TIME); + + do_nanosleep_ccc(500); + + // clear the soft reset control bit + memset(table_buffer_ccc + 15, 0, 1); + + // clear the start bit + disable_start_ccc(START_BIT_TIME); + + // set the command list override bit + byte = byte | 8; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); + // wait for clo bit to be clear + check_bit = 1; + start_time = get_elapsed_usec_ccc(); + while (check_bit) + { + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + COMMAND_LIST_OVERRIDE_TIME) + { + // if it exceeds general timeout then quit + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + check_bit = byte & 0x08; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); + } + + // set the start bit + enable_start_ccc(START_BIT_TIME); + + // set the command issue bit + enable_command_issue_ccc(COMMAND_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // clear the start bit + disable_start_ccc(START_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // reset the fis to make sure it updates + disable_fis_ccc(FIS_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // set addresses + uint64_t command_list_address = command_list_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x00, &command_list_address, 8); + uint64_t fis_address = fis_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x08, &fis_address, 8); + // wait for 1ms + do_nanosleep_ccc(1000000); + + // make sure fis is running + enable_fis_ccc(FIS_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // if always wait for reset time then wait + if (always_wait_for_reset_timers_ccc) + { + unsigned long long rstart_time = get_elapsed_usec_ccc(); + unsigned long long relapsed_time = get_elapsed_usec_ccc(); + while ((relapsed_time - rstart_time) < hard_reset_time_ccc) + { + do_nanosleep_ccc(1000000); + relapsed_time = get_elapsed_usec_ccc(); + update_display_status_buttons_ccc(DISPLAY_STATUS_UPDATE_TIME); + } + } + + // wait for device to be ready + status = wait_not_busy_or_drq_ccc(hard_reset_time_ccc, 0); + if (stop_signal_ccc) + { + return STOP_SIGNAL_RETURN_CODE; + } + if (status == 1) + { + sprintf(tempmessage_ccc, "timeout after soft reset\n"); + message_console_log_ccc(tempmessage_ccc, 0); + // if it timed out then do hard reset + performing_reset_ccc = 1; status = hard_reset_ccc(disk_fd); + performing_reset_ccc = 0; did_hard_reset_ccc = 1; } + } + + // clear any interrupt bits + ahci_interrupt_changed_ccc = true; + memset(port_virt_addr_ccc + 0x10, 0xff, 4); + + // get recent copy of status and error + memcpy(&io_byte_ccc[1], port_virt_addr_ccc + 0x20, 1); // status + memcpy(&io_byte_ccc[2], port_virt_addr_ccc + 0x21, 1); // error + + post_direct_ccc(28); + + // put the buffer size back + ccc_main_buffer_size_ccc = backup_buffer_size; + set_main_buffer_ccc(); + + if (1) + { + // perform steps to help with recovery after reset + // turn interupts off + memset(port_virt_addr_ccc + 0x14, 0x0, 4); + // wait for 1ms + do_nanosleep_ccc(1000000); + // clear the start bit + disable_start_ccc(START_BIT_TIME); + // wait for 1ms + do_nanosleep_ccc(1000000); + // clear the fis enable bit + disable_fis_ccc(FIS_BIT_TIME); + // wait for 1ms + do_nanosleep_ccc(1000000); + // set new addresses + uint64_t command_list_address = command_list_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x00, &command_list_address, 8); + uint64_t fis_address = fis_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x08, &fis_address, 8); + // wait for 1ms + do_nanosleep_ccc(1000000); + // set the fis enable bit + enable_fis_ccc(FIS_BIT_TIME); + // wait for 1ms + do_nanosleep_ccc(1000000); + } + + // if it fails to identify after then bad status + performing_reset_ccc = 1; + if (!did_hard_reset_ccc && identify_device_ccc()) + { + sprintf(tempmessage_ccc, "identify failed after soft reset\n"); + message_console_log_ccc(tempmessage_ccc, 0); + if (did_hard_reset_ccc) + { + status = status | 4; + } else { - // try soft reset first - // clear the command list - memset(command_list_buffer_ccc, 0, command_list_size_ccc); - // set the command FIS length, 5 dwords for h2d, also contains read/write bit - io_singlebyte_ccc = 5; - io_singlebyte_ccc = io_singlebyte_ccc | ((1) << 6); - memcpy(command_list_buffer_ccc, &io_singlebyte_ccc, 1); - // set the reset bit in the command fis - memset(command_list_buffer_ccc + 1, 1, 1); - - // clear the fis buffer - memset(fis_buffer_ccc, 0, fis_size_ccc); - // clear the command FIS - memset(table_buffer_ccc, 0, 0x80); - // set FIS type - memset(table_buffer_ccc, REG_H2D, 1); - // set type as control - memset(table_buffer_ccc + 1, 0x00, 1); - // set the table entry length - uint16_t word = table_entry_count_ccc; - memcpy(command_list_buffer_ccc + 2, &word, 2); - // set the command table address - uint64_t qword = table_physical_address_ccc; - memcpy(command_list_buffer_ccc + 8, &qword, 8); - - // set the soft reset control bit - memset(table_buffer_ccc + 15, 4, 1); - - // set the command list override bit - byte = byte | 8; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte - // wait for clo bit to be clear - int check_bit = 1; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (check_bit) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + COMMAND_LIST_OVERRIDE_TIME) - { - // if it exceeds general timeout then quit - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - check_bit = byte & 0x08; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - - // make sure fis is running - enable_fis_ccc(FIS_BIT_TIME); - - // set the start bit - enable_start_ccc(START_BIT_TIME); - - // set the command issue bit - enable_command_issue_ccc(COMMAND_BIT_TIME); - - do_nanosleep_ccc(500); - - // clear the soft reset control bit - memset(table_buffer_ccc + 15, 0, 1); - - // clear the start bit - disable_start_ccc(START_BIT_TIME); - - // set the command list override bit - byte = byte | 8; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte - // wait for clo bit to be clear - check_bit = 1; - start_time = get_elapsed_usec_ccc(); - while (check_bit) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + COMMAND_LIST_OVERRIDE_TIME) - { - // if it exceeds general timeout then quit - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - check_bit = byte & 0x08; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - - // set the start bit - enable_start_ccc(START_BIT_TIME); - - // set the command issue bit - enable_command_issue_ccc(COMMAND_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - // clear the start bit - disable_start_ccc(START_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - // reset the fis to make sure it updates - disable_fis_ccc(FIS_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - // set addresses - uint64_t command_list_address = command_list_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address, 8); // potential superbyte - uint64_t fis_address = fis_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address, 8); // potential superbyte - // wait for 1ms - do_nanosleep_ccc(1000000); - - // make sure fis is running - enable_fis_ccc(FIS_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - // if always wait for reset time then wait - if (always_wait_for_reset_timers_ccc) - { - unsigned long long rstart_time = get_elapsed_usec_ccc(); - unsigned long long relapsed_time = get_elapsed_usec_ccc(); - while ((relapsed_time - rstart_time) < hard_reset_time_ccc) - { - do_nanosleep_ccc(1000000); - relapsed_time = get_elapsed_usec_ccc(); - update_display_status_buttons_ccc(DISPLAY_STATUS_UPDATE_TIME); - } - } - - // wait for device to be ready - status = wait_not_busy_or_drq_ccc(hard_reset_time_ccc, 0); - if (stop_signal_ccc) - { - return STOP_SIGNAL_RETURN_CODE; - } - if (status == 1) - { - sprintf(tempmessage_ccc, "timeout after soft reset\n"); - message_console_log_ccc(tempmessage_ccc, 0); - // if it timed out then do hard reset - performing_reset_ccc = 1; - status = hard_reset_ccc(disk_fd); - performing_reset_ccc = 0; - did_hard_reset_ccc = 1; - } + status = hard_reset_ccc(disk_fd); } - - // clear any interrupt bits - ahci_interrupt_changed_ccc = true; - memset(port_virt_addr_ccc + superbyte_ccc[7], 0xff, 4); // potential superbyte - - // get recent copy of status and error - memcpy(&io_byte_ccc[1], port_virt_addr_ccc + superbyte_ccc[8], 1); // status //potential superbyte - memcpy(&io_byte_ccc[2], port_virt_addr_ccc + superbyte_ccc[9], 1); // error //potential superbyte - - post_direct_ccc(28); - - // put the buffer size back - ccc_main_buffer_size_ccc = backup_buffer_size; - set_main_buffer_ccc(); - - if (1) - { - // perform steps to help with recovery after reset - // turn interupts off - memset(port_virt_addr_ccc + superbyte_ccc[13], 0x0, 4); // potential superbyte - // wait for 1ms - do_nanosleep_ccc(1000000); - // clear the start bit - disable_start_ccc(START_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); - // clear the fis enable bit - disable_fis_ccc(FIS_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); - // set new addresses - uint64_t command_list_address = command_list_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address, 8); // potential superbyte - uint64_t fis_address = fis_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address, 8); // potential superbyte - // wait for 1ms - do_nanosleep_ccc(1000000); - // set the fis enable bit - enable_fis_ccc(FIS_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); - } - - // if it fails to identify after then bad status - performing_reset_ccc = 1; - if (!did_hard_reset_ccc && identify_device_ccc()) - { - sprintf(tempmessage_ccc, "identify failed after soft reset\n"); - message_console_log_ccc(tempmessage_ccc, 0); - if (did_hard_reset_ccc) - { - status = status | 4; - } - else - { - status = hard_reset_ccc(disk_fd); - } - } - performing_reset_ccc = 0; - return (status); } + performing_reset_ccc = 0; + return (status); } else @@ -3259,147 +3232,206 @@ int hard_reset_ccc(int disk_fd) } else { - if (superbyte_ccc[36] == 0x6f) + if (ahci_mode_ccc) { - if (ahci_mode_ccc) + // ahci + if (superclone_ccc) { - // ahci - if (superclone_ccc) - { - sprintf(tempmessage_ccc, "hard reset\n"); - message_console_log_ccc(tempmessage_ccc, 0); - } + sprintf(tempmessage_ccc, "hard reset\n"); + message_console_log_ccc(tempmessage_ccc, 0); + } #ifdef DEBUG - int i; - if (debug_ccc & DEBUG35) + int i; + if (debug_ccc & DEBUG35) + { + fprintf(stdout, "hard reset\n"); + for (i = 0; i < 0x80; i += 4) { - fprintf(stdout, "hard reset\n"); - for (i = 0; i < 0x80; i += 4) + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) { - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) + if (!(n % 8)) { - if (!(n % 8)) - { - fprintf(stdout, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(stdout, "1"); - else - fprintf(stdout, "0"); + fprintf(stdout, " "); } - fprintf(stdout, "\n"); + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(stdout, "1"); + else + fprintf(stdout, "0"); } + fprintf(stdout, "\n"); } + } #endif - // clear the start bit - uint8_t byte; - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + // clear the start bit + uint8_t byte; + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + byte = byte & 0xfe; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); - // set the buffer size to 0 for no data transfer - unsigned long long backup_buffer_size = ccc_main_buffer_size_ccc; - ccc_main_buffer_size_ccc = 0; - set_main_buffer_ccc(); + // set the buffer size to 0 for no data transfer + unsigned long long backup_buffer_size = ccc_main_buffer_size_ccc; + ccc_main_buffer_size_ccc = 0; + set_main_buffer_ccc(); - // clear the command list - memset(command_list_buffer_ccc, 0, command_list_size_ccc); - // clear the fis buffer - memset(fis_buffer_ccc, 0, fis_size_ccc); - // clear the command FIS - memset(table_buffer_ccc, 0, 0x80); + // clear the command list + memset(command_list_buffer_ccc, 0, command_list_size_ccc); + // clear the fis buffer + memset(fis_buffer_ccc, 0, fis_size_ccc); + // clear the command FIS + memset(table_buffer_ccc, 0, 0x80); - // set the comreset bit in the Device Detection Initialization field - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[16], 1); - byte = byte & 0xf0; - byte = byte | 0x01; - memcpy(port_virt_addr_ccc + superbyte_ccc[16], &byte, 1); + // set the comreset bit in the Device Detection Initialization field + memcpy(&byte, port_virt_addr_ccc + 0x2c, 1); + byte = byte & 0xf0; + byte = byte | 0x01; + memcpy(port_virt_addr_ccc + 0x2c, &byte, 1); - // wait for 1ms - do_nanosleep_ccc(1000000); + // wait for 1ms + do_nanosleep_ccc(1000000); - // clear the comreset bit - byte = byte & 0xf0; - memcpy(port_virt_addr_ccc + superbyte_ccc[16], &byte, 1); + // clear the comreset bit + byte = byte & 0xf0; + memcpy(port_virt_addr_ccc + 0x2c, &byte, 1); - // wait for device to connect - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[17], 1); + // wait for device to connect + memcpy(&byte, port_virt_addr_ccc + 0x28, 1); + byte = byte & 0x0f; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (byte != 3) + { + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + reset_wait_time_ccc) + { + // if it exceeds the reset timeout then quit + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x28, 1); byte = byte & 0x0f; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (byte != 3) + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); + } + + // clear all error bits + memset(port_virt_addr_ccc + 0x30, 0xff, 4); + + // clear the start bit + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + byte = byte & 0xfe; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // reset the fis to make sure it updates + disable_fis_ccc(FIS_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // set addresses + uint64_t command_list_address = command_list_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x00, &command_list_address, 8); + uint64_t fis_address = fis_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x08, &fis_address, 8); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // make sure fis is running + enable_fis_ccc(FIS_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // if always wait for reset time then wait + if (always_wait_for_reset_timers_ccc) + { + unsigned long long rstart_time = get_elapsed_usec_ccc(); + unsigned long long relapsed_time = get_elapsed_usec_ccc(); + while ((relapsed_time - rstart_time) < reset_wait_time_ccc) { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + reset_wait_time_ccc) - { - // if it exceeds the reset timeout then quit - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[17], 1); - byte = byte & 0x0f; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); + do_nanosleep_ccc(1000000); + relapsed_time = get_elapsed_usec_ccc(); + update_display_status_buttons_ccc(DISPLAY_STATUS_UPDATE_TIME); } + } - // clear all error bits - memset(port_virt_addr_ccc + superbyte_ccc[18], 0xff, 4); + // wait for device to be ready + int status = wait_not_busy_or_drq_ccc(reset_wait_time_ccc, 0); + if (stop_signal_ccc) + { + return STOP_SIGNAL_RETURN_CODE; + } + if (superclone_ccc && status) + { + sprintf(tempmessage_ccc, "timeout after hard reset\n"); + message_console_log_ccc(tempmessage_ccc, 0); + status = call_command_on_power_cycle_ccc(); + did_power_cycle_ccc = 1; + if (status) + { + return status; + } + } + + // put the buffer size back + ccc_main_buffer_size_ccc = backup_buffer_size; + set_main_buffer_ccc(); + +#ifdef DEBUG + for (i = 0; i < 0x80; i += 4) + { + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + // fprintf (stdout, "%x %08x\n", i, io_doubleword_ccc); //debug + } +#endif + + if (1) + { + // perform steps to help with recovery after reset + // turn interupts off + memset(port_virt_addr_ccc + 0x14, 0x0, 4); + // wait for 1ms + do_nanosleep_ccc(1000000); // clear the start bit - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); - byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); - + disable_start_ccc(START_BIT_TIME); // wait for 1ms do_nanosleep_ccc(1000000); - - // reset the fis to make sure it updates + // clear the fis enable bit disable_fis_ccc(FIS_BIT_TIME); - // wait for 1ms do_nanosleep_ccc(1000000); - - // set addresses + // set new addresses uint64_t command_list_address = command_list_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address, 8); // potential superbyte + memcpy(port_virt_addr_ccc + 0x00, &command_list_address, 8); uint64_t fis_address = fis_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address, 8); // potential superbyte - + memcpy(port_virt_addr_ccc + 0x08, &fis_address, 8); // wait for 1ms do_nanosleep_ccc(1000000); - - // make sure fis is running + // set the fis enable bit enable_fis_ccc(FIS_BIT_TIME); - // wait for 1ms do_nanosleep_ccc(1000000); + } - // if always wait for reset time then wait - if (always_wait_for_reset_timers_ccc) + // if it fails to identify after then bad status + performing_reset_ccc = 1; + if (identify_device_ccc()) + { + sprintf(tempmessage_ccc, "identify failed after hard reset\n"); + message_console_log_ccc(tempmessage_ccc, 0); + performing_reset_ccc = 0; + if (did_power_cycle_ccc) { - unsigned long long rstart_time = get_elapsed_usec_ccc(); - unsigned long long relapsed_time = get_elapsed_usec_ccc(); - while ((relapsed_time - rstart_time) < reset_wait_time_ccc) - { - do_nanosleep_ccc(1000000); - relapsed_time = get_elapsed_usec_ccc(); - update_display_status_buttons_ccc(DISPLAY_STATUS_UPDATE_TIME); - } + status = status | 4; } - - // wait for device to be ready - int status = wait_not_busy_or_drq_ccc(reset_wait_time_ccc, 0); - if (stop_signal_ccc) + else { - return STOP_SIGNAL_RETURN_CODE; - } - - if (superclone_ccc && status) - { - sprintf(tempmessage_ccc, "timeout after hard reset\n"); - message_console_log_ccc(tempmessage_ccc, 0); status = call_command_on_power_cycle_ccc(); did_power_cycle_ccc = 1; if (status) @@ -3407,78 +3439,16 @@ int hard_reset_ccc(int disk_fd) return status; } } - - // put the buffer size back - ccc_main_buffer_size_ccc = backup_buffer_size; - set_main_buffer_ccc(); - -#ifdef DEBUG - for (i = 0; i < 0x80; i += 4) - { - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - // fprintf (stdout, "%x %08x\n", i, io_doubleword_ccc); //debug - } -#endif - - if (1) - { - // perform steps to help with recovery after reset - // turn interupts off - memset(port_virt_addr_ccc + superbyte_ccc[13], 0x0, 4); // potential superbyte - // wait for 1ms - do_nanosleep_ccc(1000000); - // clear the start bit - disable_start_ccc(START_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); - // clear the fis enable bit - disable_fis_ccc(FIS_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); - // set new addresses - uint64_t command_list_address = command_list_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address, 8); // potential superbyte - uint64_t fis_address = fis_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address, 8); // potential superbyte - // wait for 1ms - do_nanosleep_ccc(1000000); - // set the fis enable bit - enable_fis_ccc(FIS_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); - } - - // if it fails to identify after then bad status - performing_reset_ccc = 1; - if (identify_device_ccc()) - { - sprintf(tempmessage_ccc, "identify failed after hard reset\n"); - message_console_log_ccc(tempmessage_ccc, 0); - performing_reset_ccc = 0; - if (did_power_cycle_ccc) - { - status = status | 4; - } - else - { - status = call_command_on_power_cycle_ccc(); - did_power_cycle_ccc = 1; - if (status) - { - return status; - } - } - } - performing_reset_ccc = 0; - return (status); } + performing_reset_ccc = 0; + return (status); + } - else - { - // ide - // not available so return status of 1 - return (1); - } + else + { + // ide + // not available so return status of 1 + return (1); } } } @@ -3533,67 +3503,176 @@ int hba_reset_ccc(void) { if (ahci_mode_ccc) { - if (superbyte_ccc[42] == 0x20) + if (hba_reset_address_ccc == 0) { - if (hba_reset_address_ccc == 0) + fprintf(stderr, "hba address not valid, try choosing a source first\n"); + strcpy(tempmessage_ccc, "hba address not valid, try choosing a source first\n"); + message_error_ccc(tempmessage_ccc); + return (-1); + } + FILE *hba_debug_reset_file = fopen("hba_reset_debug.log", "w"); + fprintf(hba_debug_reset_file, "%s %s hba debug reset file created at ", title_ccc, version_number_ccc); + time_t mytime; + mytime = time(NULL); + fprintf(hba_debug_reset_file, "%s", ctime(&mytime)); + + sprintf(tempmessage_ccc, "HBA Reset\n"); + message_console_log_ccc(tempmessage_ccc, 0); + + unsigned char hba_backup[0x30]; + unsigned char hba_after[0x30]; + unsigned char port_backup[32][0x80]; + unsigned char port_after[32][0x80]; + unsigned char temp_hba_data[0x30]; + unsigned char temp_port_data[0x80]; + + uint32_t page_mask, page_size; + + hba_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); + if (hba_mem_dev_ccc == -1) + { + fprintf(stderr, "unable to open /dev/mem\n"); + fclose(hba_debug_reset_file); + return (-1); + } + const uint32_t hba_mem_address = hba_reset_address_ccc; + const uint32_t hba_mem_size = 128; + + page_size = pagesize_ccc; + hba_alloc_mem_size_ccc = (((hba_mem_size / page_size) + 1) * page_size); + page_mask = (page_size - 1); + + hba_mem_pointer_ccc = mmap(NULL, + hba_alloc_mem_size_ccc, + PROT_READ | PROT_WRITE, + MAP_SHARED, + hba_mem_dev_ccc, + (hba_mem_address & ~page_mask)); + + if (hba_mem_pointer_ccc == MAP_FAILED) + { + fprintf(stderr, "HBA mem map failed\n"); + fclose(hba_debug_reset_file); + return (-1); + } + hba_virt_addr_ccc = (hba_mem_pointer_ccc + (hba_mem_address & page_mask)); + memory_mapped_ccc = true; + memcpy(hba_backup, hba_virt_addr_ccc, 0x30); + uint32_t ports_implemented; + memcpy(&ports_implemented, hba_virt_addr_ccc + 0x0c, 4); + + // backup ports + int x; + for (x = 0; x < 32; x++) + { + int port_used = (ports_implemented >> x) & 1; + if (port_used) { - fprintf(stderr, "hba address not valid, try choosing a source first\n"); - strcpy(tempmessage_ccc, "hba address not valid, try choosing a source first\n"); - message_error_ccc(tempmessage_ccc); - return (-1); + port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); + if (port_mem_dev_ccc == -1) + { + fprintf(stderr, "unable to open /dev/mem\n"); + return (-1); + } + const uint32_t port_mem_address = (hba_reset_address_ccc + 0x100) + (0x80 * x); + const uint32_t port_mem_size = 128; + + page_size = pagesize_ccc; + port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); + page_mask = (page_size - 1); + + port_mem_pointer_ccc = mmap(NULL, + port_alloc_mem_size_ccc, + PROT_READ | PROT_WRITE, + MAP_SHARED, + port_mem_dev_ccc, + (port_mem_address & ~page_mask)); + + if (port_mem_pointer_ccc == MAP_FAILED) + { + fprintf(stderr, "Port mem map failed\n"); + return (-1); + } + port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); + + memcpy(port_backup[x], port_virt_addr_ccc, 0x80); + + munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); + close(port_mem_dev_ccc); } - FILE *hba_debug_reset_file = fopen("hba_reset_debug.log", "w"); - fprintf(hba_debug_reset_file, "%s %s hba debug reset file created at ", title_ccc, version_number_ccc); - time_t mytime; - mytime = time(NULL); - fprintf(hba_debug_reset_file, "%s", ctime(&mytime)); + } - sprintf(tempmessage_ccc, "HBA Reset\n"); - message_console_log_ccc(tempmessage_ccc, 0); - - unsigned char hba_backup[0x30]; - unsigned char hba_after[0x30]; - unsigned char port_backup[32][0x80]; - unsigned char port_after[32][0x80]; - unsigned char temp_hba_data[0x30]; - unsigned char temp_port_data[0x80]; - - uint32_t page_mask, page_size; - - hba_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); - if (hba_mem_dev_ccc == -1) + if (1) + { + memcpy(temp_hba_data, hba_backup, 0x30); + fprintf(stdout, "hba before hba reset\n"); + fprintf(hba_debug_reset_file, "hba before hba reset\n"); + dump_hba_data_to_file_ccc(stdout, temp_hba_data, 0x30); + dump_hba_data_to_file_ccc(hba_debug_reset_file, temp_hba_data, 0x30); + } + if (1) + { + int x; + for (x = 0; x < 32; x++) { - fprintf(stderr, "unable to open /dev/mem\n"); - fclose(hba_debug_reset_file); - return (-1); + int port_used = (ports_implemented >> x) & 1; + if (port_used) + { + fprintf(stdout, "port %d before hba reset\n", x); + fprintf(hba_debug_reset_file, "port %d before hba reset\n", x); + if (port_reset_address_ccc == (hba_reset_address_ccc + 0x100) + (0x80 * x)) + { + fprintf(stdout, "this is chosen port\n"); + fprintf(hba_debug_reset_file, "this is chosen port\n"); + } + memcpy(temp_port_data, port_backup[x], 0x80); + dump_hba_data_to_file_ccc(stdout, temp_port_data, 0x80); + dump_hba_data_to_file_ccc(hba_debug_reset_file, temp_port_data, 0x80); + } } - const uint32_t hba_mem_address = hba_reset_address_ccc; - const uint32_t hba_mem_size = 128; + } - page_size = pagesize_ccc; - hba_alloc_mem_size_ccc = (((hba_mem_size / page_size) + 1) * page_size); - page_mask = (page_size - 1); + if (1) // choose to do the actual reset or not + { + fprintf(stdout, "performing actual hba reset now\n"); + fprintf(hba_debug_reset_file, "performing actual hba reset now\n"); + // set the hba reset bit + uint8_t byte; + memcpy(&byte, hba_virt_addr_ccc + 0x04, 1); + byte = byte | 0x01; + memcpy(hba_virt_addr_ccc + 0x04, &byte, 1); - hba_mem_pointer_ccc = mmap(NULL, - hba_alloc_mem_size_ccc, - PROT_READ | PROT_WRITE, - MAP_SHARED, - hba_mem_dev_ccc, - (hba_mem_address & ~page_mask)); - - if (hba_mem_pointer_ccc == MAP_FAILED) + // wait for hba to reset + memcpy(&byte, hba_virt_addr_ccc + 0x04, 1); + byte = byte & 0x01; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (byte != 0) { - fprintf(stderr, "HBA mem map failed\n"); - fclose(hba_debug_reset_file); - return (-1); + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + HBA_RESET_TIME) + { + // if it exceeds the hba timeout then quit + fprintf(stderr, "HBA appears to be hung\n"); + ret = -1; + break; + } + memcpy(&byte, hba_virt_addr_ccc + 0x04, 1); + byte = byte & 0x01; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); } - hba_virt_addr_ccc = (hba_mem_pointer_ccc + (hba_mem_address & page_mask)); - memory_mapped_ccc = true; - memcpy(hba_backup, hba_virt_addr_ccc, 0x30); - uint32_t ports_implemented; - memcpy(&ports_implemented, hba_virt_addr_ccc + 0x0c, 4); - // backup ports + // now put some things back the way they were before the computer knows what happened + // first enable ahci + memcpy(&byte, hba_virt_addr_ccc + 0x07, 1); + byte = byte | 0x80; + memcpy(hba_virt_addr_ccc + 0x07, &byte, 1); + // enable hba interupts + memcpy(&byte, hba_virt_addr_ccc + 0x04, 1); + byte = byte | 0x02; + memcpy(hba_virt_addr_ccc + 0x04, &byte, 1); + + // now cycle through the ports int x; for (x = 0; x < 32; x++) { @@ -3608,18 +3687,15 @@ int hba_reset_ccc(void) } const uint32_t port_mem_address = (hba_reset_address_ccc + 0x100) + (0x80 * x); const uint32_t port_mem_size = 128; - page_size = pagesize_ccc; port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); page_mask = (page_size - 1); - port_mem_pointer_ccc = mmap(NULL, port_alloc_mem_size_ccc, PROT_READ | PROT_WRITE, MAP_SHARED, port_mem_dev_ccc, (port_mem_address & ~page_mask)); - if (port_mem_pointer_ccc == MAP_FAILED) { fprintf(stderr, "Port mem map failed\n"); @@ -3627,423 +3703,314 @@ int hba_reset_ccc(void) } port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); - memcpy(port_backup[x], port_virt_addr_ccc, 0x80); - - munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); - close(port_mem_dev_ccc); - } - } - - if (1) - { - memcpy(temp_hba_data, hba_backup, 0x30); - fprintf(stdout, "hba before hba reset\n"); - fprintf(hba_debug_reset_file, "hba before hba reset\n"); - dump_hba_data_to_file_ccc(stdout, temp_hba_data, 0x30); - dump_hba_data_to_file_ccc(hba_debug_reset_file, temp_hba_data, 0x30); - } - if (1) - { - int x; - for (x = 0; x < 32; x++) - { - int port_used = (ports_implemented >> x) & 1; - if (port_used) + // clear the start bit in case it is not clear + if (disable_start_ccc(START_BIT_TIME)) { - fprintf(stdout, "port %d before hba reset\n", x); - fprintf(hba_debug_reset_file, "port %d before hba reset\n", x); - if (port_reset_address_ccc == (hba_reset_address_ccc + 0x100) + (0x80 * x)) - { - fprintf(stdout, "this is chosen port\n"); - fprintf(hba_debug_reset_file, "this is chosen port\n"); - } - memcpy(temp_port_data, port_backup[x], 0x80); - dump_hba_data_to_file_ccc(stdout, temp_port_data, 0x80); - dump_hba_data_to_file_ccc(hba_debug_reset_file, temp_port_data, 0x80); + fprintf(stdout, "port %d command list did not stop in time\n", x); + fprintf(hba_debug_reset_file, "port %d command list did not stop in time\n", x); } - } - } - - if (1) // choose to do the actual reset or not - { - fprintf(stdout, "performing actual hba reset now\n"); - fprintf(hba_debug_reset_file, "performing actual hba reset now\n"); - // set the hba reset bit - uint8_t byte; - memcpy(&byte, hba_virt_addr_ccc + superbyte_ccc[68], 1); // superbyte - byte = byte | 0x01; - memcpy(hba_virt_addr_ccc + superbyte_ccc[68], &byte, 1); // superbyte - - // wait for hba to reset - memcpy(&byte, hba_virt_addr_ccc + superbyte_ccc[68], 1); // superbyte - byte = byte & 0x01; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (byte != 0) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + HBA_RESET_TIME) + // clear port interrupt status + uint32_t doubleword = 0; + memcpy(port_virt_addr_ccc + 0x10, &doubleword, 4); + // clear error status + memcpy(port_virt_addr_ccc + 0x30, &doubleword, 4); + // restore transitions and allowed speed (whole register is ok) + memcpy(&doubleword, port_backup[x] + 0x2c, 4); + memcpy(port_virt_addr_ccc + 0x2c, &doubleword, 4); + // restore fis enable bit + byte = port_backup[x][0x18] & 0x10; + if (byte) { - // if it exceeds the hba timeout then quit - fprintf(stderr, "HBA appears to be hung\n"); - ret = -1; - break; + if (enable_fis_ccc(FIS_BIT_TIME)) + { + fprintf(stdout, "port %d fis did not start in time\n", x); + fprintf(hba_debug_reset_file, "port %d fis did not start in time\n", x); + } + else + { + fprintf(stdout, "port %d fis running\n", x); + fprintf(hba_debug_reset_file, "port %d fis running\n", x); + } } - memcpy(&byte, hba_virt_addr_ccc + superbyte_ccc[68], 1); // superbyte - byte = byte & 0x01; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - - // now put some things back the way they were before the computer knows what happened - // first enable ahci - memcpy(&byte, hba_virt_addr_ccc + superbyte_ccc[70], 1); // superbyte - byte = byte | 0x80; - memcpy(hba_virt_addr_ccc + superbyte_ccc[70], &byte, 1); // superbyte - // enable hba interupts - memcpy(&byte, hba_virt_addr_ccc + superbyte_ccc[68], 1); // superbyte - byte = byte | 0x02; - memcpy(hba_virt_addr_ccc + superbyte_ccc[68], &byte, 1); // superbyte - - // now cycle through the ports - int x; - for (x = 0; x < 32; x++) - { - int port_used = (ports_implemented >> x) & 1; - if (port_used) + else { - port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); - if (port_mem_dev_ccc == -1) - { - fprintf(stderr, "unable to open /dev/mem\n"); - return (-1); - } - const uint32_t port_mem_address = (hba_reset_address_ccc + 0x100) + (0x80 * x); - const uint32_t port_mem_size = 128; - page_size = pagesize_ccc; - port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); - page_mask = (page_size - 1); - port_mem_pointer_ccc = mmap(NULL, - port_alloc_mem_size_ccc, - PROT_READ | PROT_WRITE, - MAP_SHARED, - port_mem_dev_ccc, - (port_mem_address & ~page_mask)); - if (port_mem_pointer_ccc == MAP_FAILED) - { - fprintf(stderr, "Port mem map failed\n"); - return (-1); - } - port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); + fprintf(stdout, "port %d fis was not enabled\n", x); + fprintf(hba_debug_reset_file, "port %d fis was not enabled\n", x); + } + // if there was a device connected before reset, perform a com reset + memcpy(&byte, port_backup[x] + 0x28, 1); + byte = byte & 0x0f; + if (byte == 3) + { + fprintf(stdout, "port %d com reset\n", x); + fprintf(hba_debug_reset_file, "port %d com reset\n", x); // clear the start bit in case it is not clear + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + byte = byte & 0xfe; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); + + // set the comreset bit in the Device Detection Initialization field + memcpy(&byte, port_virt_addr_ccc + 0x2c, 1); + byte = byte | 0x01; + memcpy(port_virt_addr_ccc + 0x2c, &byte, 1); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + // clear the comreset bit + byte = byte & 0xfe; + memcpy(port_virt_addr_ccc + 0x2c, &byte, 1); + + // wait for device to connect + memcpy(&byte, port_virt_addr_ccc + 0x28, 1); + byte = byte & 0x0f; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (byte != 3) + { + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + reset_wait_time_ccc) + { + // if it exceeds the reset timeout then quit + fprintf(stdout, "port %d took too long to connect\n", x); + fprintf(hba_debug_reset_file, "port %d took too long to connect\n", x); + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x28, 1); + byte = byte & 0x0f; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); + } + + // clear all error bits + memset(port_virt_addr_ccc + 0x30, 0xff, 4); + + // clear the start bit if (disable_start_ccc(START_BIT_TIME)) { fprintf(stdout, "port %d command list did not stop in time\n", x); fprintf(hba_debug_reset_file, "port %d command list did not stop in time\n", x); } - // clear port interrupt status - uint32_t doubleword = 0; - memcpy(port_virt_addr_ccc + superbyte_ccc[7], &doubleword, 4); // superbyte - // clear error status - memcpy(port_virt_addr_ccc + superbyte_ccc[18], &doubleword, 4); // superbyte - // restore transitions and allowed speed (whole register is ok) - memcpy(&doubleword, port_backup[x] + superbyte_ccc[16], 4); // superbyte - memcpy(port_virt_addr_ccc + superbyte_ccc[16], &doubleword, 4); // superbyte - // restore fis enable bit - byte = port_backup[x][superbyte_ccc[10]] & 0x10; // superbyte - if (byte) + } + + // clear port interrupt status + doubleword = 0; + memcpy(port_virt_addr_ccc + 0x10, &doubleword, 4); + // clear error status + memcpy(port_virt_addr_ccc + 0x30, &doubleword, 4); + // restore transitions and allowed speed (whole register is ok) + memcpy(&doubleword, port_backup[x] + 0x2c, 4); + memcpy(port_virt_addr_ccc + 0x2c, &doubleword, 4); + // restore fis enable bit + byte = port_backup[x][0x18] & 0x10; + if (byte) + { + if (enable_fis_ccc(FIS_BIT_TIME)) { - if (enable_fis_ccc(FIS_BIT_TIME)) - { - fprintf(stdout, "port %d fis did not start in time\n", x); - fprintf(hba_debug_reset_file, "port %d fis did not start in time\n", x); - } - else - { - fprintf(stdout, "port %d fis running\n", x); - fprintf(hba_debug_reset_file, "port %d fis running\n", x); - } + fprintf(stdout, "port %d fis did not start in time\n", x); + fprintf(hba_debug_reset_file, "port %d fis did not start in time\n", x); } else { - fprintf(stdout, "port %d fis was not enabled\n", x); - fprintf(hba_debug_reset_file, "port %d fis was not enabled\n", x); + fprintf(stdout, "port %d fis running\n", x); + fprintf(hba_debug_reset_file, "port %d fis running\n", x); } - - // if there was a device connected before reset, perform a com reset - memcpy(&byte, port_backup[x] + superbyte_ccc[17], 1); - byte = byte & 0x0f; - if (byte == 3) + } + else + { + fprintf(stdout, "port %d fis was not enabled\n", x); + fprintf(hba_debug_reset_file, "port %d fis was not enabled\n", x); + } + // restore start bit + byte = port_backup[x][0x18] & 0x01; + if (byte) + { + if (enable_start_ccc(START_BIT_TIME)) { - fprintf(stdout, "port %d com reset\n", x); - fprintf(hba_debug_reset_file, "port %d com reset\n", x); - // clear the start bit in case it is not clear - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte - - // set the comreset bit in the Device Detection Initialization field - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[16], 1); - byte = byte | 0x01; - memcpy(port_virt_addr_ccc + superbyte_ccc[16], &byte, 1); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - // clear the comreset bit - byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[16], &byte, 1); - - // wait for device to connect - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[17], 1); - byte = byte & 0x0f; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (byte != 3) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + reset_wait_time_ccc) - { - // if it exceeds the reset timeout then quit - fprintf(stdout, "port %d took too long to connect\n", x); - fprintf(hba_debug_reset_file, "port %d took too long to connect\n", x); - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[17], 1); - byte = byte & 0x0f; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - - // clear all error bits - memset(port_virt_addr_ccc + superbyte_ccc[18], 0xff, 4); - - // clear the start bit - if (disable_start_ccc(START_BIT_TIME)) - { - fprintf(stdout, "port %d command list did not stop in time\n", x); - fprintf(hba_debug_reset_file, "port %d command list did not stop in time\n", x); - } - } - - // clear port interrupt status - doubleword = 0; - memcpy(port_virt_addr_ccc + superbyte_ccc[7], &doubleword, 4); // superbyte - // clear error status - memcpy(port_virt_addr_ccc + superbyte_ccc[18], &doubleword, 4); // superbyte - // restore transitions and allowed speed (whole register is ok) - memcpy(&doubleword, port_backup[x] + superbyte_ccc[16], 4); // superbyte - memcpy(port_virt_addr_ccc + superbyte_ccc[16], &doubleword, 4); // superbyte - // restore fis enable bit - byte = port_backup[x][superbyte_ccc[10]] & 0x10; // superbyte - if (byte) - { - if (enable_fis_ccc(FIS_BIT_TIME)) - { - fprintf(stdout, "port %d fis did not start in time\n", x); - fprintf(hba_debug_reset_file, "port %d fis did not start in time\n", x); - } - else - { - fprintf(stdout, "port %d fis running\n", x); - fprintf(hba_debug_reset_file, "port %d fis running\n", x); - } + fprintf(stdout, "port %d command list did not start in time\n", x); + fprintf(hba_debug_reset_file, "port %d command list did not start in time\n", x); } else { - fprintf(stdout, "port %d fis was not enabled\n", x); - fprintf(hba_debug_reset_file, "port %d fis was not enabled\n", x); + fprintf(stdout, "port %d command list running\n", x); + fprintf(hba_debug_reset_file, "port %d command list running\n", x); } - // restore start bit - byte = port_backup[x][superbyte_ccc[10]] & 0x01; // superbyte - if (byte) + } + else + { + fprintf(stdout, "port %d start bit was not enabled\n", x); + fprintf(hba_debug_reset_file, "port %d start bit was not enabled\n", x); + } + // restore interrupt enable bits + memcpy(&doubleword, port_backup[x] + 0x14, 4); + memcpy(port_virt_addr_ccc + 0x14, &doubleword, 4); + + // if it is the chosen port, then wait for it to be not busy + if (0 && port_reset_address_ccc == (hba_reset_address_ccc + 0x100) + (0x80 * x)) + { + fprintf(stdout, "wating for chosen port not busy\n"); + fprintf(hba_debug_reset_file, "wating for chosen port not busy\n"); + // wait for drive to be ready + int busy = 1; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (busy) { - if (enable_start_ccc(START_BIT_TIME)) + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + reset_wait_time_ccc) { - fprintf(stdout, "port %d command list did not start in time\n", x); - fprintf(hba_debug_reset_file, "port %d command list did not start in time\n", x); - } - else - { - fprintf(stdout, "port %d command list running\n", x); - fprintf(hba_debug_reset_file, "port %d command list running\n", x); + // if it times out then fail + fprintf(stdout, "port stayed busy through reset wait time\n"); + fprintf(hba_debug_reset_file, "port stayed busy through reset wait time\n"); + break; } + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); + // fprintf (stdout, "%08x\n", io_doubleword_ccc); //debug + busy = io_doubleword_ccc & 0x80; + // give the cpu a chance to do something else so we are not using 100% + // do_nanosleep_ccc(1); } - else - { - fprintf(stdout, "port %d start bit was not enabled\n", x); - fprintf(hba_debug_reset_file, "port %d start bit was not enabled\n", x); - } - // restore interrupt enable bits - memcpy(&doubleword, port_backup[x] + superbyte_ccc[13], 4); // superbyte - memcpy(port_virt_addr_ccc + superbyte_ccc[13], &doubleword, 4); // superbyte - - // if it is the chosen port, then wait for it to be not busy - if (0 && port_reset_address_ccc == (hba_reset_address_ccc + 0x100) + (0x80 * x)) - { - fprintf(stdout, "wating for chosen port not busy\n"); - fprintf(hba_debug_reset_file, "wating for chosen port not busy\n"); - // wait for drive to be ready - int busy = 1; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (busy) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + reset_wait_time_ccc) - { - // if it times out then fail - fprintf(stdout, "port stayed busy through reset wait time\n"); - fprintf(hba_debug_reset_file, "port stayed busy through reset wait time\n"); - break; - } - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); - // fprintf (stdout, "%08x\n", io_doubleword_ccc); //debug - busy = io_doubleword_ccc & 0x80; - // give the cpu a chance to do something else so we are not using 100% - // do_nanosleep_ccc(1); - } - } - - munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); - close(port_mem_dev_ccc); } - } - fprintf(stdout, "hba reset complete, hope everything still works and doesn't hang\n"); - fprintf(hba_debug_reset_file, "hba reset complete, hope everything still works and doesn't hang\n"); - } - - // wait for all ports to not be busy - for (x = 0; x < 32; x++) - { - int port_used = (ports_implemented >> x) & 1; - if (port_used) - { - port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); - if (port_mem_dev_ccc == -1) - { - fprintf(stderr, "unable to open /dev/mem\n"); - return (-1); - } - const uint32_t port_mem_address = (hba_reset_address_ccc + 0x100) + (0x80 * x); - const uint32_t port_mem_size = 128; - page_size = pagesize_ccc; - port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); - page_mask = (page_size - 1); - port_mem_pointer_ccc = mmap(NULL, - port_alloc_mem_size_ccc, - PROT_READ | PROT_WRITE, - MAP_SHARED, - port_mem_dev_ccc, - (port_mem_address & ~page_mask)); - if (port_mem_pointer_ccc == MAP_FAILED) - { - fprintf(stderr, "Port mem map failed\n"); - return (-1); - } - port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); - fprintf(stdout, "wating for port %d not busy\n", x); - fprintf(hba_debug_reset_file, "wating for port %d not busy\n", x); - // wait for drive to be ready - int busy = 1; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (busy) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + reset_wait_time_ccc) - { - // if it times out then fail - fprintf(stdout, "port %d stayed busy through reset wait time\n", x); - fprintf(hba_debug_reset_file, "port %d stayed busy through reset wait time\n", x); - break; - } - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); - // fprintf (stdout, "%08x\n", io_doubleword_ccc); //debug - busy = io_doubleword_ccc & 0x80; - // give the cpu a chance to do something else so we are not using 100% - // do_nanosleep_ccc(1); - } - munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); - close(port_mem_dev_ccc); - } - } - - // backup hba and ports after reset for display - memcpy(hba_after, hba_virt_addr_ccc, 0x30); - for (x = 0; x < 32; x++) - { - int port_used = (ports_implemented >> x) & 1; - if (port_used) - { - port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); - if (port_mem_dev_ccc == -1) - { - fprintf(stderr, "unable to open /dev/mem\n"); - return (-1); - } - const uint32_t port_mem_address = (hba_reset_address_ccc + 0x100) + (0x80 * x); - const uint32_t port_mem_size = 128; - - page_size = pagesize_ccc; - port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); - page_mask = (page_size - 1); - - port_mem_pointer_ccc = mmap(NULL, - port_alloc_mem_size_ccc, - PROT_READ | PROT_WRITE, - MAP_SHARED, - port_mem_dev_ccc, - (port_mem_address & ~page_mask)); - - if (port_mem_pointer_ccc == MAP_FAILED) - { - fprintf(stderr, "Port mem map failed\n"); - return (-1); - } - port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); - - memcpy(port_after[x], port_virt_addr_ccc, 0x80); munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); close(port_mem_dev_ccc); } } - - if (1) - { - memcpy(temp_hba_data, hba_after, 0x30); - fprintf(stdout, "hba after hba reset\n"); - fprintf(hba_debug_reset_file, "hba after hba reset\n"); - dump_hba_data_to_file_ccc(stdout, temp_hba_data, 0x30); - dump_hba_data_to_file_ccc(hba_debug_reset_file, temp_hba_data, 0x30); - } - if (1) - { - int x; - for (x = 0; x < 32; x++) - { - int port_used = (ports_implemented >> x) & 1; - if (port_used) - { - fprintf(stdout, "port %d after hba reset\n", x); - fprintf(hba_debug_reset_file, "port %d after hba reset\n", x); - if (port_reset_address_ccc == (hba_reset_address_ccc + 0x100) + (0x80 * x)) - { - fprintf(stdout, "this is chosen port\n"); - fprintf(hba_debug_reset_file, "this is chosen port\n"); - } - memcpy(temp_port_data, port_after[x], 0x80); - dump_hba_data_to_file_ccc(stdout, temp_port_data, 0x80); - dump_hba_data_to_file_ccc(hba_debug_reset_file, temp_port_data, 0x80); - } - } - } - - // close mapped memory - munmap(hba_mem_pointer_ccc, hba_alloc_mem_size_ccc); - close(hba_mem_dev_ccc); - memory_mapped_ccc = false; - - fclose(hba_debug_reset_file); + fprintf(stdout, "hba reset complete, hope everything still works and doesn't hang\n"); + fprintf(hba_debug_reset_file, "hba reset complete, hope everything still works and doesn't hang\n"); } + + // wait for all ports to not be busy + for (x = 0; x < 32; x++) + { + int port_used = (ports_implemented >> x) & 1; + if (port_used) + { + port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); + if (port_mem_dev_ccc == -1) + { + fprintf(stderr, "unable to open /dev/mem\n"); + return (-1); + } + const uint32_t port_mem_address = (hba_reset_address_ccc + 0x100) + (0x80 * x); + const uint32_t port_mem_size = 128; + page_size = pagesize_ccc; + port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); + page_mask = (page_size - 1); + port_mem_pointer_ccc = mmap(NULL, + port_alloc_mem_size_ccc, + PROT_READ | PROT_WRITE, + MAP_SHARED, + port_mem_dev_ccc, + (port_mem_address & ~page_mask)); + if (port_mem_pointer_ccc == MAP_FAILED) + { + fprintf(stderr, "Port mem map failed\n"); + return (-1); + } + port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); + fprintf(stdout, "wating for port %d not busy\n", x); + fprintf(hba_debug_reset_file, "wating for port %d not busy\n", x); + // wait for drive to be ready + int busy = 1; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (busy) + { + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + reset_wait_time_ccc) + { + // if it times out then fail + fprintf(stdout, "port %d stayed busy through reset wait time\n", x); + fprintf(hba_debug_reset_file, "port %d stayed busy through reset wait time\n", x); + break; + } + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); + // fprintf (stdout, "%08x\n", io_doubleword_ccc); //debug + busy = io_doubleword_ccc & 0x80; + // give the cpu a chance to do something else so we are not using 100% + // do_nanosleep_ccc(1); + } + munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); + close(port_mem_dev_ccc); + } + } + + // backup hba and ports after reset for display + memcpy(hba_after, hba_virt_addr_ccc, 0x30); + for (x = 0; x < 32; x++) + { + int port_used = (ports_implemented >> x) & 1; + if (port_used) + { + port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); + if (port_mem_dev_ccc == -1) + { + fprintf(stderr, "unable to open /dev/mem\n"); + return (-1); + } + const uint32_t port_mem_address = (hba_reset_address_ccc + 0x100) + (0x80 * x); + const uint32_t port_mem_size = 128; + + page_size = pagesize_ccc; + port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); + page_mask = (page_size - 1); + + port_mem_pointer_ccc = mmap(NULL, + port_alloc_mem_size_ccc, + PROT_READ | PROT_WRITE, + MAP_SHARED, + port_mem_dev_ccc, + (port_mem_address & ~page_mask)); + + if (port_mem_pointer_ccc == MAP_FAILED) + { + fprintf(stderr, "Port mem map failed\n"); + return (-1); + } + port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); + + memcpy(port_after[x], port_virt_addr_ccc, 0x80); + + munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); + close(port_mem_dev_ccc); + } + } + + if (1) + { + memcpy(temp_hba_data, hba_after, 0x30); + fprintf(stdout, "hba after hba reset\n"); + fprintf(hba_debug_reset_file, "hba after hba reset\n"); + dump_hba_data_to_file_ccc(stdout, temp_hba_data, 0x30); + dump_hba_data_to_file_ccc(hba_debug_reset_file, temp_hba_data, 0x30); + } + if (1) + { + int x; + for (x = 0; x < 32; x++) + { + int port_used = (ports_implemented >> x) & 1; + if (port_used) + { + fprintf(stdout, "port %d after hba reset\n", x); + fprintf(hba_debug_reset_file, "port %d after hba reset\n", x); + if (port_reset_address_ccc == (hba_reset_address_ccc + 0x100) + (0x80 * x)) + { + fprintf(stdout, "this is chosen port\n"); + fprintf(hba_debug_reset_file, "this is chosen port\n"); + } + memcpy(temp_port_data, port_after[x], 0x80); + dump_hba_data_to_file_ccc(stdout, temp_port_data, 0x80); + dump_hba_data_to_file_ccc(hba_debug_reset_file, temp_port_data, 0x80); + } + } + } + + // close mapped memory + munmap(hba_mem_pointer_ccc, hba_alloc_mem_size_ccc); + close(hba_mem_dev_ccc); + memory_mapped_ccc = false; + + fclose(hba_debug_reset_file); } } @@ -4211,7 +4178,7 @@ int dump_hba_port_fis_command_data_ccc(unsigned long long hba_address, unsigned // fis data int data_size = 0x100; uint64_t address; - memcpy(&address, port_virt_addr + superbyte_ccc[12], 8); // potential superbyte + memcpy(&address, port_virt_addr + 0x08, 8); fprintf(stdout, "fis data, address=%08llx\n", (unsigned long long)address); sprintf(temp_string, "fis data, address=%08llx\n", (unsigned long long)address); dump_info_to_filename_ccc(dump_filename, temp_string); @@ -4267,7 +4234,7 @@ int dump_hba_port_fis_command_data_ccc(unsigned long long hba_address, unsigned // command data int data_size = 0x400; uint64_t address; - memcpy(&address, port_virt_addr + superbyte_ccc[11], 8); // potential superbyte + memcpy(&address, port_virt_addr + 0x00, 8); fprintf(stdout, "command list data, address=%08llx\n", (unsigned long long)address); sprintf(temp_string, "command list data, address=%08llx\n", (unsigned long long)address); dump_info_to_filename_ccc(dump_filename, temp_string); @@ -4509,7 +4476,7 @@ int hba_test_ccc(void) // fis data int data_size = 0x100; uint64_t address; - memcpy(&address, port_virt_addr_ccc + superbyte_ccc[12], 8); // potential superbyte + memcpy(&address, port_virt_addr_ccc + 0x08, 8); fprintf(stdout, "fis data at start, address=%08llx\n", (unsigned long long)address); fprintf(hba_debug_file, "fis data at start, address=%08llx\n", (unsigned long long)address); fflush(hba_debug_file); @@ -4576,7 +4543,7 @@ int hba_test_ccc(void) // command data int data_size = 0x400; uint64_t address; - memcpy(&address, port_virt_addr_ccc + superbyte_ccc[11], 8); // potential superbyte + memcpy(&address, port_virt_addr_ccc + 0x00, 8); fprintf(stdout, "command list data at start, address=%08llx\n", (unsigned long long)address); fprintf(hba_debug_file, "command list data at start, address=%08llx\n", (unsigned long long)address); fflush(hba_debug_file); @@ -4734,15 +4701,15 @@ int hba_test_ccc(void) } // backup current addresses - memcpy(&command_list_address_backup_ccc, port_virt_addr_ccc + superbyte_ccc[11], 8); // potential superbyte - memcpy(&fis_address_backup_ccc, port_virt_addr_ccc + superbyte_ccc[12], 8); // potential superbyte + memcpy(&command_list_address_backup_ccc, port_virt_addr_ccc + 0x00, 8); + memcpy(&fis_address_backup_ccc, port_virt_addr_ccc + 0x08, 8); // backup the interrupt settings - memcpy(&interrupt_backup_ccc, port_virt_addr_ccc + superbyte_ccc[13], 4); // potential superbyte + memcpy(&interrupt_backup_ccc, port_virt_addr_ccc + 0x14, 4); // turn interupts off ahci_interrupt_changed_ccc = true; - memset(port_virt_addr_ccc + superbyte_ccc[13], 0x0, 4); // potential superbyte + memset(port_virt_addr_ccc + 0x14, 0x0, 4); // wait for 1ms do_nanosleep_ccc(1000000); @@ -4762,9 +4729,9 @@ int hba_test_ccc(void) // set new addresses ahci_address_changed_ccc = true; uint64_t command_list_address = command_list_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address, 8); // potential superbyte + memcpy(port_virt_addr_ccc + 0x00, &command_list_address, 8); uint64_t fis_address = fis_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address, 8); // potential superbyte + memcpy(port_virt_addr_ccc + 0x08, &fis_address, 8); // wait for 1ms do_nanosleep_ccc(1000000); @@ -4797,9 +4764,9 @@ int hba_test_ccc(void) fsync(ptf); // clear the start bit uint8_t byte; - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); // set the buffer size to 0 for no data transfer unsigned long long backup_buffer_size = ccc_main_buffer_size_ccc; @@ -4837,7 +4804,7 @@ int hba_test_ccc(void) // set the command list override bit byte = byte | 8; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); // wait for clo bit to be clear int check_bit = 1; unsigned long long start_time = get_elapsed_usec_ccc(); @@ -4849,7 +4816,7 @@ int hba_test_ccc(void) // if it exceeds general timeout then quit break; } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); check_bit = byte & 0x08; // give the cpu a chance to do something else so we are not using 100% do_nanosleep_ccc(1); @@ -4874,7 +4841,7 @@ int hba_test_ccc(void) // set the command list override bit byte = byte | 8; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); // wait for clo bit to be clear check_bit = 1; start_time = get_elapsed_usec_ccc(); @@ -4886,7 +4853,7 @@ int hba_test_ccc(void) // if it exceeds general timeout then quit break; } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); check_bit = byte & 0x08; // give the cpu a chance to do something else so we are not using 100% do_nanosleep_ccc(1); @@ -4921,7 +4888,7 @@ int hba_test_ccc(void) // clear any interrupt bits ahci_interrupt_changed_ccc = true; - memset(port_virt_addr_ccc + superbyte_ccc[7], 0xff, 4); // potential superbyte + memset(port_virt_addr_ccc + 0x10, 0xff, 4); // put the buffer size back ccc_main_buffer_size_ccc = backup_buffer_size; @@ -4936,24 +4903,24 @@ int hba_test_ccc(void) ptf = fileno(hba_debug_file); fsync(ptf); // clear the start bit in case it is not clear - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); // set the comreset bit in the Device Detection Initialization field - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[16], 1); + memcpy(&byte, port_virt_addr_ccc + 0x2c, 1); byte = byte | 0x01; - memcpy(port_virt_addr_ccc + superbyte_ccc[16], &byte, 1); + memcpy(port_virt_addr_ccc + 0x2c, &byte, 1); // wait for 1ms do_nanosleep_ccc(1000000); // clear the comreset bit byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[16], &byte, 1); + memcpy(port_virt_addr_ccc + 0x2c, &byte, 1); // wait for device to connect - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[17], 1); + memcpy(&byte, port_virt_addr_ccc + 0x28, 1); byte = byte & 0x0f; unsigned long long start_time = get_elapsed_usec_ccc(); while (byte != 3) @@ -4969,14 +4936,14 @@ int hba_test_ccc(void) fsync(ptf); break; } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[17], 1); + memcpy(&byte, port_virt_addr_ccc + 0x28, 1); byte = byte & 0x0f; // give the cpu a chance to do something else so we are not using 100% do_nanosleep_ccc(1); } // clear all error bits - memset(port_virt_addr_ccc + superbyte_ccc[18], 0xff, 4); + memset(port_virt_addr_ccc + 0x30, 0xff, 4); // clear the start bit if (disable_start_ccc(START_BIT_TIME)) @@ -5004,7 +4971,7 @@ int hba_test_ccc(void) fsync(ptf); break; } - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); busy = io_doubleword_ccc & 0x80; // give the cpu a chance to do something else so we are not using 100% // do_nanosleep_ccc(1); @@ -5056,7 +5023,7 @@ int hba_test_ccc(void) fsync(ptf); break; } - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); // potential superbyte + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); busy = io_doubleword_ccc & 0x80; drq = io_doubleword_ccc & 0x08; do_nanosleep_ccc(1); @@ -5119,7 +5086,7 @@ int hba_test_ccc(void) fsync(ptf); break; } - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); // potential superbyte + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); busy = io_doubleword_ccc & 0x80; drq = io_doubleword_ccc & 0x08; do_nanosleep_ccc(1); @@ -5192,7 +5159,7 @@ int hba_test_ccc(void) // fis data int data_size = 0x100; uint64_t address; - memcpy(&address, port_virt_addr_ccc + superbyte_ccc[12], 8); // potential superbyte + memcpy(&address, port_virt_addr_ccc + 0x08, 8); fprintf(stdout, "fis data after identify device, address=%08llx\n", (unsigned long long)address); fprintf(hba_debug_file, "fis data after identify device, address=%08llx\n", (unsigned long long)address); fflush(hba_debug_file); @@ -5259,7 +5226,7 @@ int hba_test_ccc(void) // command data int data_size = 0x400; uint64_t address; - memcpy(&address, port_virt_addr_ccc + superbyte_ccc[11], 8); // potential superbyte + memcpy(&address, port_virt_addr_ccc + 0x00, 8); fprintf(stdout, "command list data after identify device, address=%08llx\n", (unsigned long long)address); fprintf(hba_debug_file, "command list data after identify device, address=%08llx\n", (unsigned long long)address); fflush(hba_debug_file); @@ -5424,14 +5391,14 @@ int hba_test_ccc(void) if (ahci_address_changed_ccc) { // restore addresses - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address_backup_ccc, 8); // potential superbyte - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address_backup_ccc, 8); // potential superbyte + memcpy(port_virt_addr_ccc + 0x00, &command_list_address_backup_ccc, 8); + memcpy(port_virt_addr_ccc + 0x08, &fis_address_backup_ccc, 8); ahci_address_changed_ccc = false; } if (ahci_interrupt_changed_ccc) { // restore the interrupt settings - memcpy(port_virt_addr_ccc + superbyte_ccc[13], &interrupt_backup_ccc, 4); // potential superbyte + memcpy(port_virt_addr_ccc + 0x14, &interrupt_backup_ccc, 4); ahci_interrupt_changed_ccc = false; } if (memory_mapped_ccc) @@ -5517,15 +5484,15 @@ int hba_test_ccc(void) } // backup current addresses - memcpy(&command_list_address_backup_ccc, port_virt_addr_ccc + superbyte_ccc[11], 8); // potential superbyte - memcpy(&fis_address_backup_ccc, port_virt_addr_ccc + superbyte_ccc[12], 8); // potential superbyte + memcpy(&command_list_address_backup_ccc, port_virt_addr_ccc + 0x00, 8); + memcpy(&fis_address_backup_ccc, port_virt_addr_ccc + 0x08, 8); // backup the interrupt settings - memcpy(&interrupt_backup_ccc, port_virt_addr_ccc + superbyte_ccc[13], 4); // potential superbyte + memcpy(&interrupt_backup_ccc, port_virt_addr_ccc + 0x14, 4); // turn interupts off ahci_interrupt_changed_ccc = true; - memset(port_virt_addr_ccc + superbyte_ccc[13], 0x0, 4); // potential superbyte + memset(port_virt_addr_ccc + 0x14, 0x0, 4); // wait for 1ms do_nanosleep_ccc(1000000); @@ -5545,9 +5512,9 @@ int hba_test_ccc(void) // set new addresses ahci_address_changed_ccc = true; uint64_t command_list_address = command_list_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address, 8); // potential superbyte + memcpy(port_virt_addr_ccc + 0x00, &command_list_address, 8); uint64_t fis_address = fis_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address, 8); // potential superbyte + memcpy(port_virt_addr_ccc + 0x08, &fis_address, 8); // wait for 1ms do_nanosleep_ccc(1000000); @@ -5591,7 +5558,7 @@ int hba_test_ccc(void) fsync(ptf); break; } - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); // potential superbyte + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); busy = io_doubleword_ccc & 0x80; drq = io_doubleword_ccc & 0x08; do_nanosleep_ccc(1); @@ -5654,7 +5621,7 @@ int hba_test_ccc(void) fsync(ptf); break; } - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); // potential superbyte + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); busy = io_doubleword_ccc & 0x80; drq = io_doubleword_ccc & 0x08; do_nanosleep_ccc(1); @@ -5728,15 +5695,15 @@ int hba_test_ccc(void) if (ahci_address_changed_ccc) { // restore addresses - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address_backup_ccc, 8); // potential superbyte - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address_backup_ccc, 8); // potential superbyte + memcpy(port_virt_addr_ccc + 0x00, &command_list_address_backup_ccc, 8); + memcpy(port_virt_addr_ccc + 0x08, &fis_address_backup_ccc, 8); ahci_address_changed_ccc = false; } if (ahci_interrupt_changed_ccc) { // restore the interrupt settings - memcpy(port_virt_addr_ccc + superbyte_ccc[13], &interrupt_backup_ccc, 4); // potential superbyte + memcpy(port_virt_addr_ccc + 0x14, &interrupt_backup_ccc, 4); ahci_interrupt_changed_ccc = false; } @@ -5767,147 +5734,144 @@ int post_direct_ccc(int command_type) if (ahci_mode_ccc) { - if (superbyte_ccc[37] == 0xf5) + // ahci + // clear return data + set_number_variable_value_ccc("$ata_return_error", 0); + set_number_variable_value_ccc("$ata_return_count", 0); + set_number_variable_value_ccc("$ata_return_lba", 0); + set_number_variable_value_ccc("$ata_return_device", 0); + set_number_variable_value_ccc("$ata_return_status", 0); + set_number_variable_value_ccc("$ata_alternate_status", 0); + + // set error and status to current values + set_number_variable_value_ccc("$ata_return_status", io_byte_ccc[1]); + set_number_variable_value_ccc("$ata_alternate_status", 0); + set_number_variable_value_ccc("$ata_return_error", io_byte_ccc[2]); + memcpy(&ata_error_ccc, &io_byte_ccc[2], 1); + memcpy(&ata_status_ccc, &io_byte_ccc[1], 1); + + // check if there is a d2h fis + // if there is then get that data but keep current error and status + memcpy(&io_singlebyte_ccc, fis_buffer_ccc + 0x40, 1); + if (io_singlebyte_ccc == REG_D2H) { - // ahci - // clear return data - set_number_variable_value_ccc("$ata_return_error", 0); - set_number_variable_value_ccc("$ata_return_count", 0); - set_number_variable_value_ccc("$ata_return_lba", 0); - set_number_variable_value_ccc("$ata_return_device", 0); - set_number_variable_value_ccc("$ata_return_status", 0); - set_number_variable_value_ccc("$ata_alternate_status", 0); - - // set error and status to current values - set_number_variable_value_ccc("$ata_return_status", io_byte_ccc[1]); - set_number_variable_value_ccc("$ata_alternate_status", 0); - set_number_variable_value_ccc("$ata_return_error", io_byte_ccc[2]); - memcpy(&ata_error_ccc, &io_byte_ccc[2], 1); - memcpy(&ata_status_ccc, &io_byte_ccc[1], 1); - - // check if there is a d2h fis - // if there is then get that data but keep current error and status - memcpy(&io_singlebyte_ccc, fis_buffer_ccc + 0x40, 1); - if (io_singlebyte_ccc == REG_D2H) + if (command_type == 28) { - if (command_type == 28) - { - memcpy(&io_byte_ccc[1], fis_buffer_ccc + 0x42, 1); // status - memcpy(&io_byte_ccc[2], fis_buffer_ccc + 0x43, 1); // error - memcpy(&io_byte_ccc[3], fis_buffer_ccc + 0x44, 1); // lba low - memcpy(&io_byte_ccc[4], fis_buffer_ccc + 0x45, 1); // lba mid - memcpy(&io_byte_ccc[5], fis_buffer_ccc + 0x46, 1); // lba high - memcpy(&io_byte_ccc[6], fis_buffer_ccc + 0x47, 1); // device - memcpy(&io_byte_ccc[7], fis_buffer_ccc + 0x4c, 1); // count + memcpy(&io_byte_ccc[1], fis_buffer_ccc + 0x42, 1); // status + memcpy(&io_byte_ccc[2], fis_buffer_ccc + 0x43, 1); // error + memcpy(&io_byte_ccc[3], fis_buffer_ccc + 0x44, 1); // lba low + memcpy(&io_byte_ccc[4], fis_buffer_ccc + 0x45, 1); // lba mid + memcpy(&io_byte_ccc[5], fis_buffer_ccc + 0x46, 1); // lba high + memcpy(&io_byte_ccc[6], fis_buffer_ccc + 0x47, 1); // device + memcpy(&io_byte_ccc[7], fis_buffer_ccc + 0x4c, 1); // count - unsigned long long lba = io_byte_ccc[3] + (io_byte_ccc[4] << 8) + (io_byte_ccc[5] << 16) + ((io_byte_ccc[5] & 0x0f) << 24); - // set_number_variable_value_ccc("$ata_return_error", io_byte_ccc[2]); - set_number_variable_value_ccc("$ata_return_count", io_byte_ccc[7]); - set_number_variable_value_ccc("$ata_return_lba", lba); - set_number_variable_value_ccc("$ata_return_device", io_byte_ccc[6]); - set_number_variable_value_ccc("$ata_alternate_status", io_byte_ccc[1]); - ata_lba_ccc = lba; - ata_count_ccc = io_byte_ccc[7]; - memcpy(&ata_device_ccc, &io_byte_ccc[6], 1); - } - else if (command_type == 48) - { - memcpy(&io_byte_ccc[1], fis_buffer_ccc + 0x42, 1); // status - memcpy(&io_byte_ccc[2], fis_buffer_ccc + 0x43, 1); // error - memcpy(&io_byte_ccc[3], fis_buffer_ccc + 0x44, 1); // lba1 7:0 - memcpy(&io_byte_ccc[4], fis_buffer_ccc + 0x45, 1); // lba2 15:8 - memcpy(&io_byte_ccc[5], fis_buffer_ccc + 0x46, 1); // lba3 23:16 - memcpy(&io_byte_ccc[6], fis_buffer_ccc + 0x47, 1); // device - memcpy(&io_byte_ccc[7], fis_buffer_ccc + 0x48, 1); // lba4 31:24 - memcpy(&io_byte_ccc[8], fis_buffer_ccc + 0x49, 1); // lba5 39:32 - memcpy(&io_byte_ccc[9], fis_buffer_ccc + 0x4a, 1); // lba6 47:40 - memcpy(&io_byte_ccc[10], fis_buffer_ccc + 0x4c, 1); // count low - memcpy(&io_byte_ccc[11], fis_buffer_ccc + 0x4d, 1); // count high - - unsigned long long lba = io_byte_ccc[3] + (io_byte_ccc[4] << 8) + (io_byte_ccc[5] << 16) + (io_byte_ccc[7] << 24) + ((unsigned long long)io_byte_ccc[8] << 32) + ((unsigned long long)io_byte_ccc[9] << 40); - unsigned int count = io_byte_ccc[10] + (io_byte_ccc[11] << 8); - // set_number_variable_value_ccc("$ata_return_error", io_byte_ccc[2]); - set_number_variable_value_ccc("$ata_return_count", count); - set_number_variable_value_ccc("$ata_return_lba", lba); - set_number_variable_value_ccc("$ata_return_device", io_byte_ccc[6]); - set_number_variable_value_ccc("$ata_alternate_status", io_byte_ccc[1]); - ata_lba_ccc = lba; - ata_count_ccc = count; - memcpy(&ata_device_ccc, &io_byte_ccc[6], 1); - } + unsigned long long lba = io_byte_ccc[3] + (io_byte_ccc[4] << 8) + (io_byte_ccc[5] << 16) + ((io_byte_ccc[5] & 0x0f) << 24); + // set_number_variable_value_ccc("$ata_return_error", io_byte_ccc[2]); + set_number_variable_value_ccc("$ata_return_count", io_byte_ccc[7]); + set_number_variable_value_ccc("$ata_return_lba", lba); + set_number_variable_value_ccc("$ata_return_device", io_byte_ccc[6]); + set_number_variable_value_ccc("$ata_alternate_status", io_byte_ccc[1]); + ata_lba_ccc = lba; + ata_count_ccc = io_byte_ccc[7]; + memcpy(&ata_device_ccc, &io_byte_ccc[6], 1); } + else if (command_type == 48) + { + memcpy(&io_byte_ccc[1], fis_buffer_ccc + 0x42, 1); // status + memcpy(&io_byte_ccc[2], fis_buffer_ccc + 0x43, 1); // error + memcpy(&io_byte_ccc[3], fis_buffer_ccc + 0x44, 1); // lba1 7:0 + memcpy(&io_byte_ccc[4], fis_buffer_ccc + 0x45, 1); // lba2 15:8 + memcpy(&io_byte_ccc[5], fis_buffer_ccc + 0x46, 1); // lba3 23:16 + memcpy(&io_byte_ccc[6], fis_buffer_ccc + 0x47, 1); // device + memcpy(&io_byte_ccc[7], fis_buffer_ccc + 0x48, 1); // lba4 31:24 + memcpy(&io_byte_ccc[8], fis_buffer_ccc + 0x49, 1); // lba5 39:32 + memcpy(&io_byte_ccc[9], fis_buffer_ccc + 0x4a, 1); // lba6 47:40 + memcpy(&io_byte_ccc[10], fis_buffer_ccc + 0x4c, 1); // count low + memcpy(&io_byte_ccc[11], fis_buffer_ccc + 0x4d, 1); // count high + + unsigned long long lba = io_byte_ccc[3] + (io_byte_ccc[4] << 8) + (io_byte_ccc[5] << 16) + (io_byte_ccc[7] << 24) + ((unsigned long long)io_byte_ccc[8] << 32) + ((unsigned long long)io_byte_ccc[9] << 40); + unsigned int count = io_byte_ccc[10] + (io_byte_ccc[11] << 8); + // set_number_variable_value_ccc("$ata_return_error", io_byte_ccc[2]); + set_number_variable_value_ccc("$ata_return_count", count); + set_number_variable_value_ccc("$ata_return_lba", lba); + set_number_variable_value_ccc("$ata_return_device", io_byte_ccc[6]); + set_number_variable_value_ccc("$ata_alternate_status", io_byte_ccc[1]); + ata_lba_ccc = lba; + ata_count_ccc = count; + memcpy(&ata_device_ccc, &io_byte_ccc[6], 1); + } + } #ifdef DEBUG - if (debug_ccc & DEBUG36) + if (debug_ccc & DEBUG36) + { + int i; + for (i = 0; i < 256; i += 16) { - int i; - for (i = 0; i < 256; i += 16) + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)table_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)table_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); + c = (unsigned char *)table_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); } - } - - if (debug_ccc & DEBUG36) - { - int i; - for (i = 0; i < 256; i += 16) + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)fis_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)fis_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); + c = (unsigned char *)table_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); } + fprintf(stdout, "\n"); } - - if (debug_ccc & DEBUG36) - { - int i; - for (i = 0; i < 128; i += 16) - { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)command_list_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)command_list_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); - } - } -#endif } + + if (debug_ccc & DEBUG36) + { + int i; + for (i = 0; i < 256; i += 16) + { + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)fis_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); + } + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)fis_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); + } + fprintf(stdout, "\n"); + } + } + + if (debug_ccc & DEBUG36) + { + int i; + for (i = 0; i < 128; i += 16) + { + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)command_list_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); + } + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)command_list_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); + } + fprintf(stdout, "\n"); + } + } +#endif } else @@ -6016,64 +5980,61 @@ int refresh_status_ccc(int disk_fd) { if (ahci_mode_ccc) { - if (superbyte_ccc[38] == 0x50) - { // ahci #ifdef DEBUG - if (debug_ccc & DEBUG37) + if (debug_ccc & DEBUG37) + { + int i; + fprintf(stdout, "HBA memory\n"); + for (i = 0; i < 0x80; i += 4) { - int i; - fprintf(stdout, "HBA memory\n"); - for (i = 0; i < 0x80; i += 4) + memcpy(&io_doubleword_ccc, hba_virt_addr_ccc + i, 4); + fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) { - memcpy(&io_doubleword_ccc, hba_virt_addr_ccc + i, 4); - fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) + if (!(n % 8)) { - if (!(n % 8)) - { - fprintf(stdout, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(stdout, "1"); - else - fprintf(stdout, "0"); + fprintf(stdout, " "); } - fprintf(stdout, "\n"); - } - - fprintf(stdout, "Port memory\n"); - for (i = 0; i < 0x80; i += 4) - { - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) - { - if (!(n % 8)) - { - fprintf(stdout, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(stdout, "1"); - else - fprintf(stdout, "0"); - } - fprintf(stdout, "\n"); + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(stdout, "1"); + else + fprintf(stdout, "0"); } + fprintf(stdout, "\n"); } + + fprintf(stdout, "Port memory\n"); + for (i = 0; i < 0x80; i += 4) + { + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) + { + if (!(n % 8)) + { + fprintf(stdout, " "); + } + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(stdout, "1"); + else + fprintf(stdout, "0"); + } + fprintf(stdout, "\n"); + } + } #endif - // get recent copy of status and error - memcpy(&io_byte_ccc[1], port_virt_addr_ccc + superbyte_ccc[8], 1); // status - memcpy(&io_byte_ccc[2], port_virt_addr_ccc + superbyte_ccc[9], 1); // error - set_number_variable_value_ccc("$ata_return_error", io_byte_ccc[2]); - set_number_variable_value_ccc("$ata_return_status", io_byte_ccc[1]); - set_number_variable_value_ccc("$ata_alternate_status", 0); - memcpy(&ata_error_ccc, &io_byte_ccc[2], 1); - memcpy(&ata_status_ccc, &io_byte_ccc[1], 1); - } + // get recent copy of status and error + memcpy(&io_byte_ccc[1], port_virt_addr_ccc + 0x20, 1); // status + memcpy(&io_byte_ccc[2], port_virt_addr_ccc + 0x21, 1); // error + set_number_variable_value_ccc("$ata_return_error", io_byte_ccc[2]); + set_number_variable_value_ccc("$ata_return_status", io_byte_ccc[1]); + set_number_variable_value_ccc("$ata_alternate_status", 0); + memcpy(&ata_error_ccc, &io_byte_ccc[2], 1); + memcpy(&ata_status_ccc, &io_byte_ccc[1], 1); } else @@ -6432,134 +6393,131 @@ int process_resources_ccc(unsigned long long *start, unsigned long long *end, un { if (ahci_mode_ccc) { - if (superbyte_ccc[39] == 0x0e) + int i; + if (verbose_ccc & DEBUG8) { - int i; - if (verbose_ccc & DEBUG8) + for (i = 0; i < count; i++) { - for (i = 0; i < count; i++) + fprintf(stdout, "0x%llx 0x%llx 0x%llx\n", start[i], end[i], flag[i]); + } + } + unsigned long long potential_hba_start; + unsigned long long potential_hba_end; + // new fixed method of memory mapping ports, the 6th in the list should be the hba + int fixed_method = 1; + if (fixed_method) + { + potential_hba_start = start[5]; + potential_hba_end = end[5]; + } + else + { + int potential_count = 0; + for (i = 0; i < count; i++) + { + if (end[i] - start[i] > 1024 && end[i] - start[i] < 16384) { - fprintf(stdout, "0x%llx 0x%llx 0x%llx\n", start[i], end[i], flag[i]); + potential_hba_start = start[i]; + potential_hba_end = end[i]; + potential_count++; } } - unsigned long long potential_hba_start; - unsigned long long potential_hba_end; - // new fixed method of memory mapping ports, the 6th in the list should be the hba - int fixed_method = 1; - if (fixed_method) + if (potential_count == 0) { - potential_hba_start = start[5]; - potential_hba_end = end[5]; + // fprintf (stdout, "fail1\n"); //debug + return (0); } - else + else if (potential_count > 1) { - int potential_count = 0; + potential_count = 0; for (i = 0; i < count; i++) { - if (end[i] - start[i] > 1024 && end[i] - start[i] < 16384) + if (end[i] - start[i] > 2047 && end[i] - start[i] < 8192 && flag[i] == 0x40200) { potential_hba_start = start[i]; potential_hba_end = end[i]; potential_count++; } } - if (potential_count == 0) + if (potential_count != 1) { - // fprintf (stdout, "fail1\n"); //debug + // fprintf (stdout, "fail2\n"); //debug return (0); } - else if (potential_count > 1) - { - potential_count = 0; - for (i = 0; i < count; i++) - { - if (end[i] - start[i] > 2047 && end[i] - start[i] < 8192 && flag[i] == 0x40200) - { - potential_hba_start = start[i]; - potential_hba_end = end[i]; - potential_count++; - } - } - if (potential_count != 1) - { - // fprintf (stdout, "fail2\n"); //debug - return (0); - } - } } - // fprintf (stdout, "0x%llx 0x%llx\n", potential_hba_start, potential_hba_end); //debug - - int port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); - - if (port_mem_dev_ccc == -1) - { - sprintf(tempmessage_ccc, "unable to open /dev/mem\n"); - message_now_ccc(tempmessage_ccc); - return (0); - } - const uint32_t mem_address = potential_hba_start; - const uint32_t mem_size = potential_hba_end - potential_hba_start + 1; - - uint32_t port_alloc_mem_size_ccc, page_mask, page_size; - void *port_mem_pointer_ccc, *port_virt_addr_ccc; - - page_size = pagesize_ccc; - port_alloc_mem_size_ccc = (((mem_size / page_size) + 1) * page_size); - page_mask = (page_size - 1); - - port_mem_pointer_ccc = mmap(NULL, - port_alloc_mem_size_ccc, - PROT_READ | PROT_WRITE, - MAP_SHARED, - port_mem_dev_ccc, - (mem_address & ~page_mask)); - - if (port_mem_pointer_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "mem map failed\n"); - message_now_ccc(tempmessage_ccc); - return (0); - } - port_virt_addr_ccc = (port_mem_pointer_ccc + (mem_address & page_mask)); - - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[19], 4); - unsigned int ports_implemented = io_doubleword_ccc; - // fprintf (stdout, "ports_implemented= 0x%x\n", ports_implemented); //debug - - for (i = 0; i < 32; i++) - { - int possible_device = ports_implemented & 1; - if (possible_device) - { - get_device_information_ccc(driver, bus, i, 0, device_count_ccc); - strcpy(device_driver_ccc[device_count_ccc], driver); - strcpy(device_bus_ccc[device_count_ccc], bus); - hba_address_ccc[device_count_ccc] = potential_hba_start; - port_number_ccc[device_count_ccc] = i; - port_address_ccc[device_count_ccc] = potential_hba_start + 0x100 + (i * 0x80); - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x128 + (i * 0x80), 4); - port_status_ccc[device_count_ccc] = io_doubleword_ccc; - if (port_status_ccc == 0) - { - device_present_ccc[device_count_ccc] = false; - } - else - { - device_present_ccc[device_count_ccc] = true; - } - // fprintf (stdout, "port_status_ccc= 0x%x\n", port_status_ccc); //debug - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x124 + (i * 0x80), 4); - port_signature_ccc[device_count_ccc] = io_doubleword_ccc; - // fprintf (stdout, "port_signature_ccc= 0x%x\n", port_signature_ccc); //debug - // fprintf (stdout, "%s %s %llx %d %llx %x %x\n", driver, bus, potential_hba_start, port_number_ccc[device_count_ccc], port_address_ccc[device_count_ccc], port_status_ccc[device_count_ccc], port_signature_ccc[device_count_ccc]); //debug - device_count_ccc++; - } - ports_implemented = ports_implemented >> 1; - } - - munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); - close(port_mem_dev_ccc); } + // fprintf (stdout, "0x%llx 0x%llx\n", potential_hba_start, potential_hba_end); //debug + + int port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); + + if (port_mem_dev_ccc == -1) + { + sprintf(tempmessage_ccc, "unable to open /dev/mem\n"); + message_now_ccc(tempmessage_ccc); + return (0); + } + const uint32_t mem_address = potential_hba_start; + const uint32_t mem_size = potential_hba_end - potential_hba_start + 1; + + uint32_t port_alloc_mem_size_ccc, page_mask, page_size; + void *port_mem_pointer_ccc, *port_virt_addr_ccc; + + page_size = pagesize_ccc; + port_alloc_mem_size_ccc = (((mem_size / page_size) + 1) * page_size); + page_mask = (page_size - 1); + + port_mem_pointer_ccc = mmap(NULL, + port_alloc_mem_size_ccc, + PROT_READ | PROT_WRITE, + MAP_SHARED, + port_mem_dev_ccc, + (mem_address & ~page_mask)); + + if (port_mem_pointer_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "mem map failed\n"); + message_now_ccc(tempmessage_ccc); + return (0); + } + port_virt_addr_ccc = (port_mem_pointer_ccc + (mem_address & page_mask)); + + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x0c, 4); + unsigned int ports_implemented = io_doubleword_ccc; + // fprintf (stdout, "ports_implemented= 0x%x\n", ports_implemented); //debug + + for (i = 0; i < 32; i++) + { + int possible_device = ports_implemented & 1; + if (possible_device) + { + get_device_information_ccc(driver, bus, i, 0, device_count_ccc); + strcpy(device_driver_ccc[device_count_ccc], driver); + strcpy(device_bus_ccc[device_count_ccc], bus); + hba_address_ccc[device_count_ccc] = potential_hba_start; + port_number_ccc[device_count_ccc] = i; + port_address_ccc[device_count_ccc] = potential_hba_start + 0x100 + (i * 0x80); + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x128 + (i * 0x80), 4); + port_status_ccc[device_count_ccc] = io_doubleword_ccc; + if (port_status_ccc == 0) + { + device_present_ccc[device_count_ccc] = false; + } + else + { + device_present_ccc[device_count_ccc] = true; + } + // fprintf (stdout, "port_status_ccc= 0x%x\n", port_status_ccc); //debug + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x124 + (i * 0x80), 4); + port_signature_ccc[device_count_ccc] = io_doubleword_ccc; + // fprintf (stdout, "port_signature_ccc= 0x%x\n", port_signature_ccc); //debug + // fprintf (stdout, "%s %s %llx %d %llx %x %x\n", driver, bus, potential_hba_start, port_number_ccc[device_count_ccc], port_address_ccc[device_count_ccc], port_status_ccc[device_count_ccc], port_signature_ccc[device_count_ccc]); //debug + device_count_ccc++; + } + ports_implemented = ports_implemented >> 1; + } + + munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); + close(port_mem_dev_ccc); } else @@ -7278,672 +7236,670 @@ int identify_device_direct_ccc(unsigned long long address, int select, int count int identify_device_ahci_ccc(int count) { - if (superbyte_ccc[40] == 0x05) - { - memset(ccc_buffer_ccc, 0, ccc_main_buffer_size_ccc); + memset(ccc_buffer_ccc, 0, ccc_main_buffer_size_ccc); - strcpy(model_ccc[count], ""); - strcpy(serial_ccc[count], ""); + strcpy(model_ccc[count], ""); + strcpy(serial_ccc[count], ""); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump before identify for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + int ret = dump_hba_port_fis_command_data_ccc(hba_address_ccc[count], port_address_ccc[count], 1, 1, 1, 1, 1); + if (ret) + { + strcpy(model_ccc[count], "error with data dump"); + return (1); + } + } + + if (port_signature_ccc[count] == 0xffffffff) + { + strcpy(model_ccc[count], "no device"); + return (1); + } + + else if (port_signature_ccc[count] == SATA_SIG_ATA) + { + int busy; + int drq; + int drdy; + strcpy(model_ccc[count], "sata device"); + int port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); + if (port_mem_dev_ccc == -1) + { + sprintf(tempmessage_ccc, "unable to open /dev/mem\n"); + message_now_ccc(tempmessage_ccc); + return (-1); + } + const uint32_t mem_address = port_address_ccc[count]; + const uint32_t mem_size = 128; + + uint32_t port_alloc_mem_size_ccc, page_mask, page_size; + void *port_mem_pointer_ccc; + + page_size = pagesize_ccc; + port_alloc_mem_size_ccc = (((mem_size / page_size) + 1) * page_size); + page_mask = (page_size - 1); + + port_mem_pointer_ccc = mmap(NULL, + port_alloc_mem_size_ccc, + PROT_READ | PROT_WRITE, + MAP_SHARED, + port_mem_dev_ccc, + (mem_address & ~page_mask)); + + if (port_mem_pointer_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "mem map failed\n"); + message_now_ccc(tempmessage_ccc); + return (0); + } + port_virt_addr_ccc = (port_mem_pointer_ccc + (mem_address & page_mask)); if (enable_data_dump_ccc) // TODO this is for hba debug testing { char temp_string[256]; - sprintf(temp_string, "dump before identify for port number %d\n", port_number_ccc[count]); + sprintf(temp_string, "dump 1 for port number %d\n", port_number_ccc[count]); dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - int ret = dump_hba_port_fis_command_data_ccc(hba_address_ccc[count], port_address_ccc[count], 1, 1, 1, 1, 1); - if (ret) - { - strcpy(model_ccc[count], "error with data dump"); - return (1); - } + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); } - if (port_signature_ccc[count] == 0xffffffff) + // check for busy or drq + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); + busy = io_doubleword_ccc & 0x80; + drdy = io_doubleword_ccc & 0x40; + drq = io_doubleword_ccc & 0x08; + if (busy || drq) { - strcpy(model_ccc[count], "no device"); - return (1); - } - - else if (port_signature_ccc[count] == SATA_SIG_ATA) - { - int busy; - int drq; - int drdy; - strcpy(model_ccc[count], "sata device"); - int port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); - if (port_mem_dev_ccc == -1) - { - sprintf(tempmessage_ccc, "unable to open /dev/mem\n"); - message_now_ccc(tempmessage_ccc); - return (-1); - } - const uint32_t mem_address = port_address_ccc[count]; - const uint32_t mem_size = 128; - - uint32_t port_alloc_mem_size_ccc, page_mask, page_size; - void *port_mem_pointer_ccc; - - page_size = pagesize_ccc; - port_alloc_mem_size_ccc = (((mem_size / page_size) + 1) * page_size); - page_mask = (page_size - 1); - - port_mem_pointer_ccc = mmap(NULL, - port_alloc_mem_size_ccc, - PROT_READ | PROT_WRITE, - MAP_SHARED, - port_mem_dev_ccc, - (mem_address & ~page_mask)); - - if (port_mem_pointer_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "mem map failed\n"); - message_now_ccc(tempmessage_ccc); - return (0); - } - port_virt_addr_ccc = (port_mem_pointer_ccc + (mem_address & page_mask)); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 1 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // check for busy or drq - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); - busy = io_doubleword_ccc & 0x80; - drdy = io_doubleword_ccc & 0x40; - drq = io_doubleword_ccc & 0x08; - if (busy || drq) - { - strcpy(model_ccc[count], "busy or drq"); - device_present_ccc[count] = false; - char str[32]; - sprintf(str, "e/s=%04x", io_doubleword_ccc); - strcpy(serial_ccc[count], str); - // close mapped memory - munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); - close(port_mem_dev_ccc); - return (1); - } - else if (enable_dont_identify_on_choose_source_ccc) - { - strcpy(model_ccc[count], "error/status"); - if (drdy) - { - strcpy(model_ccc[count], "ready"); - } - char str[32]; - sprintf(str, "e/s=%04x", io_doubleword_ccc); - strcpy(serial_ccc[count], str); - // close mapped memory - munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); - close(port_mem_dev_ccc); - return (1); - } - -#ifdef DEBUG - int i; - for (i = 0; i < 0x80; i += 4) - { - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - // fprintf (stdout, "%x %08x\n", i, io_doubleword_ccc); //debug - } -#endif - - // backup the interrupt settings - memcpy(&interrupt_backup_ccc, port_virt_addr_ccc + superbyte_ccc[13], 4); // potential superbyte - ahci_interrupt_changed_ccc = true; - - // backup current addresses - memcpy(&command_list_address_backup_ccc, port_virt_addr_ccc + superbyte_ccc[11], 8); // potential superbyte - memcpy(&fis_address_backup_ccc, port_virt_addr_ccc + superbyte_ccc[12], 8); // potential superbyte - ahci_address_changed_ccc = true; - // fprintf (stdout, "command_list_address_backup_ccc= %016llx\n", command_list_address_backup_ccc); //debug - // fprintf (stdout, "fis_address_backup_ccc= %016llx\n", fis_address_backup_ccc); //debug - - // clear the fis buffer - memset(fis_buffer_ccc, 0, fis_size_ccc); - // clear the command FIS - memset(table_buffer_ccc, 0, 0x80); - // set FIS type - memset(table_buffer_ccc, REG_H2D, 1); - // set type as command - memset(table_buffer_ccc + 1, 0x80, 1); - // set the command register for identify device - memset(table_buffer_ccc + 2, 0xec, 1); - if (enable_data_dump_ccc) - { - // set the count to 1 - memset(table_buffer_ccc + 12, 1, 1); - // set the control register value (something unknown) - memset(table_buffer_ccc + 15, 0x08, 1); - } - // clear the command list - memset(command_list_buffer_ccc, 0, command_list_size_ccc); - // set the command FIS length, 5 dwords for h2d - memset(command_list_buffer_ccc, 5, 1); - // set the table entry length - uint16_t word = table_entry_count_ccc; - memcpy(command_list_buffer_ccc + 2, &word, 2); - // set the command table address - uint64_t qword = table_physical_address_ccc; - memcpy(command_list_buffer_ccc + 8, &qword, 8); - - // turn interupts off - memset(port_virt_addr_ccc + superbyte_ccc[13], 0x0, 4); // potential superbyte - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 2 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // backup the start bit - uint8_t byte; - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - start_bit_ccc = byte & 1; - - // clear the start bit - disable_start_ccc(START_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 3 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // clear the fis enable bit - disable_fis_ccc(FIS_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 4 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // set new addresses - uint64_t command_list_address = command_list_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address, 8); // potential superbyte - uint64_t fis_address = fis_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address, 8); // potential superbyte - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 5 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // set the fis enable bit - enable_fis_ccc(FIS_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 6 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // set the start bit - enable_start_ccc(START_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 7 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // set the command issue bit - enable_command_issue_ccc(COMMAND_BIT_TIME); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 8 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // wait for it to complete - busy = 1; - drq = 1; - unsigned long long start_time = get_elapsed_usec_ccc(); - bool timeout = false; - while (busy || drq) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + initial_busy_wait_time_ccc) - { - timeout = true; - break; - } - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); // potential superbyte - busy = io_doubleword_ccc & 0x80; - drq = io_doubleword_ccc & 0x08; - // fprintf (stdout, "e/s=%x\n", io_doubleword_ccc); //debug - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - - if (enable_data_dump_ccc) - { - char temp_string[256]; - sprintf(temp_string, "dump during identify for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - dump_hba_port_fis_command_data_ccc(hba_address_ccc[count], port_address_ccc[count], 1, 1, 1, 1, 1); - } - - // clear the start bit - disable_start_ccc(START_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 9 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // clear the fis enable bit - disable_fis_ccc(FIS_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 10 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // restore addresses - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address_backup_ccc, 8); // potential superbyte - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address_backup_ccc, 8); // potential superbyte - ahci_address_changed_ccc = false; - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 11 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // set the fis enable bit - enable_fis_ccc(FIS_BIT_TIME); - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 12 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // restore the start bit - if (start_bit_ccc) - { - enable_start_ccc(START_BIT_TIME); - } - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 13 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - - // restore the interrupt settings - memcpy(port_virt_addr_ccc + superbyte_ccc[13], &interrupt_backup_ccc, 4); // potential superbyte - ahci_interrupt_changed_ccc = false; - - // wait for 1ms - do_nanosleep_ccc(1000000); - - if (enable_data_dump_ccc) // TODO this is for hba debug testing - { - char temp_string[256]; - sprintf(temp_string, "dump 14 for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - unsigned char temp_buffer[0x80]; - memcpy(temp_buffer, port_virt_addr_ccc, 0x80); - dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); - } - + strcpy(model_ccc[count], "busy or drq"); + device_present_ccc[count] = false; + char str[32]; + sprintf(str, "e/s=%04x", io_doubleword_ccc); + strcpy(serial_ccc[count], str); // close mapped memory munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); close(port_mem_dev_ccc); + return (1); + } + else if (enable_dont_identify_on_choose_source_ccc) + { + strcpy(model_ccc[count], "error/status"); + if (drdy) + { + strcpy(model_ccc[count], "ready"); + } + char str[32]; + sprintf(str, "e/s=%04x", io_doubleword_ccc); + strcpy(serial_ccc[count], str); + // close mapped memory + munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); + close(port_mem_dev_ccc); + return (1); + } #ifdef DEBUG - if (debug_ccc & DEBUG36) - { - for (i = 0; i < 256; i += 16) - { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)fis_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)fis_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); - } - } - - if (debug_ccc & DEBUG36) - { - for (i = 0; i < 256; i += 16) - { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)table_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)table_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); - } - } - - if (debug_ccc & DEBUG36) - { - for (i = 0; i < 128; i += 16) - { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)command_list_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)command_list_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); - } - } + int i; + for (i = 0; i < 0x80; i += 4) + { + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + // fprintf (stdout, "%x %08x\n", i, io_doubleword_ccc); //debug + } #endif - if (timeout) - { - strcpy(model_ccc[count], "timeout"); - char str[32]; - sprintf(str, "e/s=%04x", io_doubleword_ccc); - strcpy(serial_ccc[count], str); - return (1); - } - else - { - // check for error - if (io_doubleword_ccc & 0x0001) - { - strcpy(model_ccc[count], "error"); - char str[32]; - sprintf(str, "e/s=%04x", io_doubleword_ccc); - strcpy(serial_ccc[count], str); - return (1); - } - } + // backup the interrupt settings + memcpy(&interrupt_backup_ccc, port_virt_addr_ccc + 0x14, 4); + ahci_interrupt_changed_ccc = true; + + // backup current addresses + memcpy(&command_list_address_backup_ccc, port_virt_addr_ccc + 0x00, 8); + memcpy(&fis_address_backup_ccc, port_virt_addr_ccc + 0x08, 8); + ahci_address_changed_ccc = true; + // fprintf (stdout, "command_list_address_backup_ccc= %016llx\n", command_list_address_backup_ccc); //debug + // fprintf (stdout, "fis_address_backup_ccc= %016llx\n", fis_address_backup_ccc); //debug + + // clear the fis buffer + memset(fis_buffer_ccc, 0, fis_size_ccc); + // clear the command FIS + memset(table_buffer_ccc, 0, 0x80); + // set FIS type + memset(table_buffer_ccc, REG_H2D, 1); + // set type as command + memset(table_buffer_ccc + 1, 0x80, 1); + // set the command register for identify device + memset(table_buffer_ccc + 2, 0xec, 1); + if (enable_data_dump_ccc) + { + // set the count to 1 + memset(table_buffer_ccc + 12, 1, 1); + // set the control register value (something unknown) + memset(table_buffer_ccc + 15, 0x08, 1); + } + // clear the command list + memset(command_list_buffer_ccc, 0, command_list_size_ccc); + // set the command FIS length, 5 dwords for h2d + memset(command_list_buffer_ccc, 5, 1); + // set the table entry length + uint16_t word = table_entry_count_ccc; + memcpy(command_list_buffer_ccc + 2, &word, 2); + // set the command table address + uint64_t qword = table_physical_address_ccc; + memcpy(command_list_buffer_ccc + 8, &qword, 8); + + // turn interupts off + memset(port_virt_addr_ccc + 0x14, 0x0, 4); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 2 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); } - else if (port_signature_ccc[count] == SATA_SIG_ATAPI) + // backup the start bit + uint8_t byte; + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + start_bit_ccc = byte & 1; + + // clear the start bit + disable_start_ccc(START_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing { - strcpy(model_ccc[count], "satapi device"); - return (2); - } - else if (port_signature_ccc[count] == SATA_SIG_SEMB) - { - strcpy(model_ccc[count], "enclosure management bridge"); - return (2); - } - else if (port_signature_ccc[count] == SATA_SIG_PM) - { - strcpy(model_ccc[count], "port multiplier"); - return (2); - } - else - { - strcpy(model_ccc[count], "unknown device"); - return (2); + char temp_string[256]; + sprintf(temp_string, "dump 3 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); } - int i; - if (verbose_ccc & DEBUG9) + // clear the fis enable bit + disable_fis_ccc(FIS_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing { - for (i = 0; i < 512; i += 16) + char temp_string[256]; + sprintf(temp_string, "dump 4 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // set new addresses + uint64_t command_list_address = command_list_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x00, &command_list_address, 8); + uint64_t fis_address = fis_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x08, &fis_address, 8); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 5 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // set the fis enable bit + enable_fis_ccc(FIS_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 6 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // set the start bit + enable_start_ccc(START_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 7 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // set the command issue bit + enable_command_issue_ccc(COMMAND_BIT_TIME); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 8 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // wait for it to complete + busy = 1; + drq = 1; + unsigned long long start_time = get_elapsed_usec_ccc(); + bool timeout = false; + while (busy || drq) + { + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + initial_busy_wait_time_ccc) + { + timeout = true; + break; + } + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); + busy = io_doubleword_ccc & 0x80; + drq = io_doubleword_ccc & 0x08; + // fprintf (stdout, "e/s=%x\n", io_doubleword_ccc); //debug + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); + } + + if (enable_data_dump_ccc) + { + char temp_string[256]; + sprintf(temp_string, "dump during identify for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + dump_hba_port_fis_command_data_ccc(hba_address_ccc[count], port_address_ccc[count], 1, 1, 1, 1, 1); + } + + // clear the start bit + disable_start_ccc(START_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 9 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // clear the fis enable bit + disable_fis_ccc(FIS_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 10 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // restore addresses + memcpy(port_virt_addr_ccc + 0x00, &command_list_address_backup_ccc, 8); + memcpy(port_virt_addr_ccc + 0x08, &fis_address_backup_ccc, 8); + ahci_address_changed_ccc = false; + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 11 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // set the fis enable bit + enable_fis_ccc(FIS_BIT_TIME); + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 12 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // restore the start bit + if (start_bit_ccc) + { + enable_start_ccc(START_BIT_TIME); + } + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 13 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // restore the interrupt settings + memcpy(port_virt_addr_ccc + 0x14, &interrupt_backup_ccc, 4); + ahci_interrupt_changed_ccc = false; + + // wait for 1ms + do_nanosleep_ccc(1000000); + + if (enable_data_dump_ccc) // TODO this is for hba debug testing + { + char temp_string[256]; + sprintf(temp_string, "dump 14 for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + unsigned char temp_buffer[0x80]; + memcpy(temp_buffer, port_virt_addr_ccc, 0x80); + dump_data_to_filename_binary_ccc(data_dump_filename_ccc, temp_buffer, 0x80, "Port data"); + } + + // close mapped memory + munmap(port_mem_pointer_ccc, port_alloc_mem_size_ccc); + close(port_mem_dev_ccc); + +#ifdef DEBUG + if (debug_ccc & DEBUG36) + { + for (i = 0; i < 256; i += 16) { fprintf(stdout, "%x: ", i); unsigned char *c; int n; for (n = 0; n < 16 && i + n < 512; n++) { - c = (unsigned char *)ccc_buffer_ccc + i + n; + c = (unsigned char *)fis_buffer_ccc + i + n; fprintf(stdout, "%02x ", *c); } fprintf(stdout, " "); for (n = 0; n < 16 && i + n < 512; n++) { - c = (unsigned char *)ccc_buffer_ccc + i + n; + c = (unsigned char *)fis_buffer_ccc + i + n; fprintf(stdout, "%c", isprint(*c) ? *c : '.'); } fprintf(stdout, "\n"); } } - char temp_model[41] = ""; - char temp_serial[21] = ""; - for (i = 0; i < 40; i += 2) + if (debug_ccc & DEBUG36) { - unsigned char *c = (unsigned char *)ccc_buffer_ccc + 54 + i + 1; - unsigned char *d = (unsigned char *)ccc_buffer_ccc + 54 + i; - if (isprint(*c)) + for (i = 0; i < 256; i += 16) { - temp_model[i] = *c; - } - else - { - temp_model[i] = '\0'; - } - if (isprint(*d)) - { - temp_model[i + 1] = *d; - } - else - { - temp_model[i + 1] = '\0'; + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)table_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); + } + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)table_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); + } + fprintf(stdout, "\n"); } } - temp_model[40] = '\0'; - for (i = 0; i < 20; i += 2) + + if (debug_ccc & DEBUG36) { - unsigned char *c = (unsigned char *)ccc_buffer_ccc + 20 + i + 1; - unsigned char *d = (unsigned char *)ccc_buffer_ccc + 20 + i; - if (isprint(*c)) + for (i = 0; i < 128; i += 16) { - temp_serial[i] = *c; - } - else - { - temp_serial[i] = '\0'; - } - if (isprint(*d)) - { - temp_serial[i + 1] = *d; - } - else - { - temp_serial[i + 1] = '\0'; + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)command_list_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); + } + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)command_list_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); + } + fprintf(stdout, "\n"); } } - temp_serial[20] = '\0'; +#endif - char *found_model = trim_white_space_ccc(temp_model); - char *found_serial = trim_white_space_ccc(temp_serial); - - strcpy(model_ccc[count], found_model); - strcpy(serial_ccc[count], found_serial); - - uint16_t word; - uint32_t double_word; - uint64_t quad_word; - words_per_logical_sector_ccc = 256; - bytes_per_logical_sector_ccc = 512; - memcpy(&word, ccc_buffer_ccc + 212, 2); - // check if word data is valid - if ((word & 0xc000) == 0x4000) + if (timeout) { - // check if sector size greater than 256 words - if (word & 0x1000) - { - memcpy(&double_word, ccc_buffer_ccc + 234, 4); - words_per_logical_sector_ccc = double_word; - } - } - bytes_per_logical_sector_ccc = words_per_logical_sector_ccc * 2; - memcpy(&double_word, ccc_buffer_ccc + 120, 4); - memcpy(&quad_word, ccc_buffer_ccc + 200, 8); - unsigned char c; - // pick based on if extend 48 bit supported - memcpy(&c, ccc_buffer_ccc + 167, 1); - if (c & 4) - { - drive_size_ccc[count] = (quad_word * bytes_per_logical_sector_ccc); + strcpy(model_ccc[count], "timeout"); + char str[32]; + sprintf(str, "e/s=%04x", io_doubleword_ccc); + strcpy(serial_ccc[count], str); + return (1); } else { - drive_size_ccc[count] = (double_word * bytes_per_logical_sector_ccc); - } - - // check if lba is supported and if not get data from chs - memcpy(&c, ccc_buffer_ccc + 99, 1); - if (!(c & 2)) - { - bytes_per_logical_sector_ccc = 512; // CHS should always be 512 bytes per sector - uint16_t word; - memcpy(&word, ccc_buffer_ccc + 106, 2); - if (word & 1) + // check for error + if (io_doubleword_ccc & 0x0001) { - memcpy(&word, ccc_buffer_ccc + 114, 2); - drive_size_ccc[count] = word << 16; - memcpy(&word, ccc_buffer_ccc + 116, 2); - drive_size_ccc[count] = drive_size_ccc[count] + word; - drive_size_ccc[count] = drive_size_ccc[count] * bytes_per_logical_sector_ccc; - } - else - { - memcpy(&word, ccc_buffer_ccc + 2, 2); - drive_size_ccc[count] = word; - memcpy(&word, ccc_buffer_ccc + 6, 2); - drive_size_ccc[count] = drive_size_ccc[count] * word; - memcpy(&word, ccc_buffer_ccc + 12, 2); - drive_size_ccc[count] = drive_size_ccc[count] * word; - drive_size_ccc[count] = drive_size_ccc[count] * bytes_per_logical_sector_ccc; + strcpy(model_ccc[count], "error"); + char str[32]; + sprintf(str, "e/s=%04x", io_doubleword_ccc); + strcpy(serial_ccc[count], str); + return (1); } } - drive_bytes_per_sector_ccc[count] = bytes_per_logical_sector_ccc; - - device_type_ccc[count] = DEVICE_TYPE_AHCI; - - if (enable_data_dump_ccc) - { - char temp_string[256]; - sprintf(temp_string, "dump after identify for port number %d\n", port_number_ccc[count]); - dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); - dump_hba_port_fis_command_data_ccc(hba_address_ccc[count], port_address_ccc[count], 1, 1, 1, 1, 1); - dump_data_to_filename_ccc(data_dump_filename_ccc, ccc_buffer_ccc, ccc_main_buffer_size_ccc, "Main buffer data"); - } - - memset(ccc_buffer_ccc, 0, ccc_main_buffer_size_ccc); } + + else if (port_signature_ccc[count] == SATA_SIG_ATAPI) + { + strcpy(model_ccc[count], "satapi device"); + return (2); + } + else if (port_signature_ccc[count] == SATA_SIG_SEMB) + { + strcpy(model_ccc[count], "enclosure management bridge"); + return (2); + } + else if (port_signature_ccc[count] == SATA_SIG_PM) + { + strcpy(model_ccc[count], "port multiplier"); + return (2); + } + else + { + strcpy(model_ccc[count], "unknown device"); + return (2); + } + + int i; + if (verbose_ccc & DEBUG9) + { + for (i = 0; i < 512; i += 16) + { + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)ccc_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); + } + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)ccc_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); + } + fprintf(stdout, "\n"); + } + } + + char temp_model[41] = ""; + char temp_serial[21] = ""; + for (i = 0; i < 40; i += 2) + { + unsigned char *c = (unsigned char *)ccc_buffer_ccc + 54 + i + 1; + unsigned char *d = (unsigned char *)ccc_buffer_ccc + 54 + i; + if (isprint(*c)) + { + temp_model[i] = *c; + } + else + { + temp_model[i] = '\0'; + } + if (isprint(*d)) + { + temp_model[i + 1] = *d; + } + else + { + temp_model[i + 1] = '\0'; + } + } + temp_model[40] = '\0'; + for (i = 0; i < 20; i += 2) + { + unsigned char *c = (unsigned char *)ccc_buffer_ccc + 20 + i + 1; + unsigned char *d = (unsigned char *)ccc_buffer_ccc + 20 + i; + if (isprint(*c)) + { + temp_serial[i] = *c; + } + else + { + temp_serial[i] = '\0'; + } + if (isprint(*d)) + { + temp_serial[i + 1] = *d; + } + else + { + temp_serial[i + 1] = '\0'; + } + } + temp_serial[20] = '\0'; + + char *found_model = trim_white_space_ccc(temp_model); + char *found_serial = trim_white_space_ccc(temp_serial); + + strcpy(model_ccc[count], found_model); + strcpy(serial_ccc[count], found_serial); + + uint16_t word; + uint32_t double_word; + uint64_t quad_word; + words_per_logical_sector_ccc = 256; + bytes_per_logical_sector_ccc = 512; + memcpy(&word, ccc_buffer_ccc + 212, 2); + // check if word data is valid + if ((word & 0xc000) == 0x4000) + { + // check if sector size greater than 256 words + if (word & 0x1000) + { + memcpy(&double_word, ccc_buffer_ccc + 234, 4); + words_per_logical_sector_ccc = double_word; + } + } + bytes_per_logical_sector_ccc = words_per_logical_sector_ccc * 2; + memcpy(&double_word, ccc_buffer_ccc + 120, 4); + memcpy(&quad_word, ccc_buffer_ccc + 200, 8); + unsigned char c; + // pick based on if extend 48 bit supported + memcpy(&c, ccc_buffer_ccc + 167, 1); + if (c & 4) + { + drive_size_ccc[count] = (quad_word * bytes_per_logical_sector_ccc); + } + else + { + drive_size_ccc[count] = (double_word * bytes_per_logical_sector_ccc); + } + + // check if lba is supported and if not get data from chs + memcpy(&c, ccc_buffer_ccc + 99, 1); + if (!(c & 2)) + { + bytes_per_logical_sector_ccc = 512; // CHS should always be 512 bytes per sector + uint16_t word; + memcpy(&word, ccc_buffer_ccc + 106, 2); + if (word & 1) + { + memcpy(&word, ccc_buffer_ccc + 114, 2); + drive_size_ccc[count] = word << 16; + memcpy(&word, ccc_buffer_ccc + 116, 2); + drive_size_ccc[count] = drive_size_ccc[count] + word; + drive_size_ccc[count] = drive_size_ccc[count] * bytes_per_logical_sector_ccc; + } + else + { + memcpy(&word, ccc_buffer_ccc + 2, 2); + drive_size_ccc[count] = word; + memcpy(&word, ccc_buffer_ccc + 6, 2); + drive_size_ccc[count] = drive_size_ccc[count] * word; + memcpy(&word, ccc_buffer_ccc + 12, 2); + drive_size_ccc[count] = drive_size_ccc[count] * word; + drive_size_ccc[count] = drive_size_ccc[count] * bytes_per_logical_sector_ccc; + } + } + drive_bytes_per_sector_ccc[count] = bytes_per_logical_sector_ccc; + + device_type_ccc[count] = DEVICE_TYPE_AHCI; + + if (enable_data_dump_ccc) + { + char temp_string[256]; + sprintf(temp_string, "dump after identify for port number %d\n", port_number_ccc[count]); + dump_info_to_filename_ccc(data_dump_filename_ccc, temp_string); + dump_hba_port_fis_command_data_ccc(hba_address_ccc[count], port_address_ccc[count], 1, 1, 1, 1, 1); + dump_data_to_filename_ccc(data_dump_filename_ccc, ccc_buffer_ccc, ccc_main_buffer_size_ccc, "Main buffer data"); + } + + memset(ccc_buffer_ccc, 0, ccc_main_buffer_size_ccc); + return (0); } @@ -8393,112 +8349,109 @@ int choose_device_ccc(void) if (ahci_mode_ccc) { - if (superbyte_ccc[41] == 0xd4) + // ahci + char input_text[32]; + char raw_value[32]; + int choice = -1; + int keeptrying = 1; + if (drive_serial_ccc == NULL && !superclone_ccc) { - // ahci - char input_text[32]; - char raw_value[32]; - int choice = -1; - int keeptrying = 1; - if (drive_serial_ccc == NULL && !superclone_ccc) + while (keeptrying) { - while (keeptrying) + strcpy(raw_value, ""); + int i; + fprintf(stdout, "\nQ) Quit\n"); + fprintf(stdout, "R) Refresh drive list\n"); + for (i = 0; i < device_count_ccc; i++) { - strcpy(raw_value, ""); - int i; - fprintf(stdout, "\nQ) Quit\n"); - fprintf(stdout, "R) Refresh drive list\n"); - for (i = 0; i < device_count_ccc; i++) + if (verbose_ccc & DEBUG6) { - if (verbose_ccc & DEBUG6) - { - fprintf(stdout, "%d) %s %s %s %s %llx %d %llx (%lld) %s %s\n", i + 1, device_driver_ccc[i], device_bus_ccc[i], device_reference_ccc[i], device_name_ccc[i], hba_address_ccc[i], port_number_ccc[i], port_address_ccc[i], drive_size_ccc[i], model_ccc[i], serial_ccc[i]); - } - else if (verbose_ccc & DEBUG5) - { - fprintf(stdout, "%d) %s %s %llx %d %llx (%lld) %s %s\n", i + 1, device_reference_ccc[i], device_name_ccc[i], hba_address_ccc[i], port_number_ccc[i], port_address_ccc[i], drive_size_ccc[i], model_ccc[i], serial_ccc[i]); - } - else - { - fprintf(stdout, "%d) %s %s (%lld) %s %s\n", i + 1, device_reference_ccc[i], device_name_ccc[i], drive_size_ccc[i], model_ccc[i], serial_ccc[i]); - } + fprintf(stdout, "%d) %s %s %s %s %llx %d %llx (%lld) %s %s\n", i + 1, device_driver_ccc[i], device_bus_ccc[i], device_reference_ccc[i], device_name_ccc[i], hba_address_ccc[i], port_number_ccc[i], port_address_ccc[i], drive_size_ccc[i], model_ccc[i], serial_ccc[i]); } - - fprintf(stdout, "Choose which drive > "); - - fflush(stdout); - - if (fgets(input_text, sizeof input_text, stdin) != NULL) + else if (verbose_ccc & DEBUG5) { - sscanf(input_text, "%s", raw_value); - if (strcasecmp(raw_value, "Q") == 0) + fprintf(stdout, "%d) %s %s %llx %d %llx (%lld) %s %s\n", i + 1, device_reference_ccc[i], device_name_ccc[i], hba_address_ccc[i], port_number_ccc[i], port_address_ccc[i], drive_size_ccc[i], model_ccc[i], serial_ccc[i]); + } + else + { + fprintf(stdout, "%d) %s %s (%lld) %s %s\n", i + 1, device_reference_ccc[i], device_name_ccc[i], drive_size_ccc[i], model_ccc[i], serial_ccc[i]); + } + } + + fprintf(stdout, "Choose which drive > "); + + fflush(stdout); + + if (fgets(input_text, sizeof input_text, stdin) != NULL) + { + sscanf(input_text, "%s", raw_value); + if (strcasecmp(raw_value, "Q") == 0) + { + return (-1); + } + else if (strcasecmp(raw_value, "R") == 0) + { + find_all_devices_ccc(); + } + else + { + char *endptr; + choice = strtol(raw_value, &endptr, 0); + if (*endptr) { - return (-1); + fprintf(stderr, "Error! Choice \'%s\' was unable to processed.\n", raw_value); } - else if (strcasecmp(raw_value, "R") == 0) + else if (choice < 1 || choice > device_count_ccc) { - find_all_devices_ccc(); + fprintf(stderr, "Error! Choice %d is out of range.\n", choice); } else { - char *endptr; - choice = strtol(raw_value, &endptr, 0); - if (*endptr) - { - fprintf(stderr, "Error! Choice \'%s\' was unable to processed.\n", raw_value); - } - else if (choice < 1 || choice > device_count_ccc) - { - fprintf(stderr, "Error! Choice %d is out of range.\n", choice); - } - else - { - keeptrying = 0; - } + keeptrying = 0; } } } } + } - else - { - choice = new_source_ccc + 1; - } + else + { + choice = new_source_ccc + 1; + } - if (choice == -1) - { - fprintf(stdout, "Error: Drive serial not found\n"); - return (-2); - } + if (choice == -1) + { + fprintf(stdout, "Error: Drive serial not found\n"); + return (-2); + } - int i = choice - 1; - if (verbose_ccc & DEBUG6) - { - fprintf(stdout, "%d) %s %s %s %s %llx %d %llx (%lld) %s %s\n", i + 1, device_driver_ccc[i], device_bus_ccc[i], device_reference_ccc[i], device_name_ccc[i], hba_address_ccc[i], port_number_ccc[i], port_address_ccc[i], drive_size_ccc[i], model_ccc[i], serial_ccc[i]); - } + int i = choice - 1; + if (verbose_ccc & DEBUG6) + { + fprintf(stdout, "%d) %s %s %s %s %llx %d %llx (%lld) %s %s\n", i + 1, device_driver_ccc[i], device_bus_ccc[i], device_reference_ccc[i], device_name_ccc[i], hba_address_ccc[i], port_number_ccc[i], port_address_ccc[i], drive_size_ccc[i], model_ccc[i], serial_ccc[i]); + } - check_choice = i; - strcpy(check_serial, serial_ccc[i]); - hba_base_address_ccc = hba_address_ccc[i]; - port_base_address_ccc = port_address_ccc[i]; - port_number_base_ccc = port_number_ccc[i]; - strcpy(device_driver_base_ccc, device_driver_ccc[i]); - strcpy(device_bus_base_ccc, device_bus_ccc[i]); - strcpy(current_source_model_ccc, model_ccc[i]); - strcpy(current_source_serial_ccc, serial_ccc[i]); - current_device_type_ccc = device_type_ccc[i]; - disk_1_ccc = malloc(sizeof device_reference_ccc[i]); - memcpy(disk_1_ccc, device_reference_ccc[i], sizeof device_reference_ccc[i]); - if (drive_bytes_per_sector_ccc[i] > 0) - { - source_total_size_ccc = drive_size_ccc[i] / drive_bytes_per_sector_ccc[i]; - bytes_per_sector_ccc = drive_bytes_per_sector_ccc[i]; - } - else - { - source_total_size_ccc = 0; - bytes_per_sector_ccc = 0; - } + check_choice = i; + strcpy(check_serial, serial_ccc[i]); + hba_base_address_ccc = hba_address_ccc[i]; + port_base_address_ccc = port_address_ccc[i]; + port_number_base_ccc = port_number_ccc[i]; + strcpy(device_driver_base_ccc, device_driver_ccc[i]); + strcpy(device_bus_base_ccc, device_bus_ccc[i]); + strcpy(current_source_model_ccc, model_ccc[i]); + strcpy(current_source_serial_ccc, serial_ccc[i]); + current_device_type_ccc = device_type_ccc[i]; + disk_1_ccc = malloc(sizeof device_reference_ccc[i]); + memcpy(disk_1_ccc, device_reference_ccc[i], sizeof device_reference_ccc[i]); + if (drive_bytes_per_sector_ccc[i] > 0) + { + source_total_size_ccc = drive_size_ccc[i] / drive_bytes_per_sector_ccc[i]; + bytes_per_sector_ccc = drive_bytes_per_sector_ccc[i]; + } + else + { + source_total_size_ccc = 0; + bytes_per_sector_ccc = 0; } } @@ -8893,212 +8846,209 @@ int connect_source_disk_ccc(void) { if (ahci_mode_ccc) { - if (superbyte_ccc[42] == 0x20) + if (enable_hba_test_on_connect_source_ccc) // TODO this is debug for troubleshooting the hba and port { - if (enable_hba_test_on_connect_source_ccc) // TODO this is debug for troubleshooting the hba and port + hba_test_ccc(); + return -1; + } + else + { + // ahci + uint32_t page_mask, page_size; + + hba_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); + if (hba_mem_dev_ccc == -1) { - hba_test_ccc(); - return -1; + fprintf(stderr, "unable to open /dev/mem\n"); + return (-1); } - else + const uint32_t hba_mem_address = hba_base_address_ccc; + const uint32_t hba_mem_size = 128; + + page_size = pagesize_ccc; + hba_alloc_mem_size_ccc = (((hba_mem_size / page_size) + 1) * page_size); + page_mask = (page_size - 1); + + hba_mem_pointer_ccc = mmap(NULL, + hba_alloc_mem_size_ccc, + PROT_READ | PROT_WRITE, + MAP_SHARED, + hba_mem_dev_ccc, + (hba_mem_address & ~page_mask)); + + if (hba_mem_pointer_ccc == MAP_FAILED) { - // ahci - uint32_t page_mask, page_size; + fprintf(stderr, "HBA mem map failed\n"); + return (-1); + } + hba_virt_addr_ccc = (hba_mem_pointer_ccc + (hba_mem_address & page_mask)); + memory_mapped_ccc = true; - hba_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); - if (hba_mem_dev_ccc == -1) + port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); + if (port_mem_dev_ccc == -1) + { + fprintf(stderr, "unable to open /dev/mem\n"); + return (-1); + } + const uint32_t port_mem_address = port_base_address_ccc; + const uint32_t port_mem_size = 128; + + page_size = pagesize_ccc; + port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); + page_mask = (page_size - 1); + + port_mem_pointer_ccc = mmap(NULL, + port_alloc_mem_size_ccc, + PROT_READ | PROT_WRITE, + MAP_SHARED, + port_mem_dev_ccc, + (port_mem_address & ~page_mask)); + + if (port_mem_pointer_ccc == MAP_FAILED) + { + fprintf(stderr, "Port mem map failed\n"); + return (-1); + } + port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); + memory_mapped_ccc = true; + + int i; + if (verbose_ccc & DEBUG39) + { + fprintf(stdout, "hba data, address=%08llx\n", hba_base_address_ccc); + for (i = 0; i < 0x80; i += 4) { - fprintf(stderr, "unable to open /dev/mem\n"); - return (-1); - } - const uint32_t hba_mem_address = hba_base_address_ccc; - const uint32_t hba_mem_size = 128; - - page_size = pagesize_ccc; - hba_alloc_mem_size_ccc = (((hba_mem_size / page_size) + 1) * page_size); - page_mask = (page_size - 1); - - hba_mem_pointer_ccc = mmap(NULL, - hba_alloc_mem_size_ccc, - PROT_READ | PROT_WRITE, - MAP_SHARED, - hba_mem_dev_ccc, - (hba_mem_address & ~page_mask)); - - if (hba_mem_pointer_ccc == MAP_FAILED) - { - fprintf(stderr, "HBA mem map failed\n"); - return (-1); - } - hba_virt_addr_ccc = (hba_mem_pointer_ccc + (hba_mem_address & page_mask)); - memory_mapped_ccc = true; - - port_mem_dev_ccc = open("/dev/mem", O_RDWR | O_SYNC); - if (port_mem_dev_ccc == -1) - { - fprintf(stderr, "unable to open /dev/mem\n"); - return (-1); - } - const uint32_t port_mem_address = port_base_address_ccc; - const uint32_t port_mem_size = 128; - - page_size = pagesize_ccc; - port_alloc_mem_size_ccc = (((port_mem_size / page_size) + 1) * page_size); - page_mask = (page_size - 1); - - port_mem_pointer_ccc = mmap(NULL, - port_alloc_mem_size_ccc, - PROT_READ | PROT_WRITE, - MAP_SHARED, - port_mem_dev_ccc, - (port_mem_address & ~page_mask)); - - if (port_mem_pointer_ccc == MAP_FAILED) - { - fprintf(stderr, "Port mem map failed\n"); - return (-1); - } - port_virt_addr_ccc = (port_mem_pointer_ccc + (port_mem_address & page_mask)); - memory_mapped_ccc = true; - - int i; - if (verbose_ccc & DEBUG39) - { - fprintf(stdout, "hba data, address=%08llx\n", hba_base_address_ccc); - for (i = 0; i < 0x80; i += 4) + memcpy(&io_doubleword_ccc, hba_virt_addr_ccc + i, 4); + fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) { - memcpy(&io_doubleword_ccc, hba_virt_addr_ccc + i, 4); - fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) + if (!(n % 8)) { - if (!(n % 8)) - { - fprintf(stdout, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(stdout, "1"); - else - fprintf(stdout, "0"); + fprintf(stdout, " "); } - fprintf(stdout, "\n"); + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(stdout, "1"); + else + fprintf(stdout, "0"); } + fprintf(stdout, "\n"); } - if (verbose_ccc & DEBUG39) + } + if (verbose_ccc & DEBUG39) + { + fprintf(stdout, "port data, address=%08llx\n", port_base_address_ccc); + for (i = 0; i < 0x80; i += 4) { - fprintf(stdout, "port data, address=%08llx\n", port_base_address_ccc); - for (i = 0; i < 0x80; i += 4) + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) { - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) + if (!(n % 8)) { - if (!(n % 8)) - { - fprintf(stdout, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(stdout, "1"); - else - fprintf(stdout, "0"); + fprintf(stdout, " "); } - fprintf(stdout, "\n"); + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(stdout, "1"); + else + fprintf(stdout, "0"); } + fprintf(stdout, "\n"); } - if (debug_ccc & DEBUG39) + } + if (debug_ccc & DEBUG39) + { + fprintf(debug_file_ccc, "hba data, address=%08llx\n", hba_base_address_ccc); + for (i = 0; i < 0x80; i += 4) { - fprintf(debug_file_ccc, "hba data, address=%08llx\n", hba_base_address_ccc); - for (i = 0; i < 0x80; i += 4) + memcpy(&io_doubleword_ccc, hba_virt_addr_ccc + i, 4); + fprintf(debug_file_ccc, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) { - memcpy(&io_doubleword_ccc, hba_virt_addr_ccc + i, 4); - fprintf(debug_file_ccc, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) + if (!(n % 8)) { - if (!(n % 8)) - { - fprintf(debug_file_ccc, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(debug_file_ccc, "1"); - else - fprintf(debug_file_ccc, "0"); + fprintf(debug_file_ccc, " "); } - fprintf(debug_file_ccc, "\n"); + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(debug_file_ccc, "1"); + else + fprintf(debug_file_ccc, "0"); } + fprintf(debug_file_ccc, "\n"); } - if (debug_ccc & DEBUG39) + } + if (debug_ccc & DEBUG39) + { + fprintf(debug_file_ccc, "port data, address=%08llx\n", port_base_address_ccc); + for (i = 0; i < 0x80; i += 4) { - fprintf(debug_file_ccc, "port data, address=%08llx\n", port_base_address_ccc); - for (i = 0; i < 0x80; i += 4) + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + fprintf(debug_file_ccc, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) { - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - fprintf(debug_file_ccc, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) + if (!(n % 8)) { - if (!(n % 8)) - { - fprintf(debug_file_ccc, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(debug_file_ccc, "1"); - else - fprintf(debug_file_ccc, "0"); + fprintf(debug_file_ccc, " "); } - fprintf(debug_file_ccc, "\n"); + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(debug_file_ccc, "1"); + else + fprintf(debug_file_ccc, "0"); } + fprintf(debug_file_ccc, "\n"); } + } - // backup current addresses - memcpy(&command_list_address_backup_ccc, port_virt_addr_ccc + superbyte_ccc[11], 8); // potential superbyte - memcpy(&fis_address_backup_ccc, port_virt_addr_ccc + superbyte_ccc[12], 8); // potential superbyte + // backup current addresses + memcpy(&command_list_address_backup_ccc, port_virt_addr_ccc + 0x00, 8); + memcpy(&fis_address_backup_ccc, port_virt_addr_ccc + 0x08, 8); - // backup the interrupt settings - memcpy(&interrupt_backup_ccc, port_virt_addr_ccc + superbyte_ccc[13], 4); // potential superbyte + // backup the interrupt settings + memcpy(&interrupt_backup_ccc, port_virt_addr_ccc + 0x14, 4); - // turn interupts off - ahci_interrupt_changed_ccc = true; - memset(port_virt_addr_ccc + superbyte_ccc[13], 0x0, 4); // potential superbyte + // turn interupts off + ahci_interrupt_changed_ccc = true; + memset(port_virt_addr_ccc + 0x14, 0x0, 4); - // wait for 1ms - do_nanosleep_ccc(1000000); + // wait for 1ms + do_nanosleep_ccc(1000000); - // clear the start bit - disable_start_ccc(START_BIT_TIME); + // clear the start bit + disable_start_ccc(START_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); + // wait for 1ms + do_nanosleep_ccc(1000000); - // clear the fis enable bit - disable_fis_ccc(FIS_BIT_TIME); + // clear the fis enable bit + disable_fis_ccc(FIS_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); + // wait for 1ms + do_nanosleep_ccc(1000000); - // set new addresses - ahci_address_changed_ccc = true; - uint64_t command_list_address = command_list_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address, 8); // potential superbyte - uint64_t fis_address = fis_physical_address_ccc; - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address, 8); // potential superbyte + // set new addresses + ahci_address_changed_ccc = true; + uint64_t command_list_address = command_list_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x00, &command_list_address, 8); + uint64_t fis_address = fis_physical_address_ccc; + memcpy(port_virt_addr_ccc + 0x08, &fis_address, 8); - // wait for 1ms - do_nanosleep_ccc(1000000); + // wait for 1ms + do_nanosleep_ccc(1000000); - // set the fis enable bit - enable_fis_ccc(FIS_BIT_TIME); + // set the fis enable bit + enable_fis_ccc(FIS_BIT_TIME); - // wait for 1ms - do_nanosleep_ccc(1000000); + // wait for 1ms + do_nanosleep_ccc(1000000); - if (use_rebuild_assist_ccc) + if (use_rebuild_assist_ccc) + { + if (set_rebuild_assist_enabled_ccc()) { - if (set_rebuild_assist_enabled_ccc()) - { - fprintf(stderr, "Enable rebuild assist failed\n"); - } + fprintf(stderr, "Enable rebuild assist failed\n"); } } } @@ -9596,50 +9546,47 @@ int wait_not_busy_or_drq_ccc(unsigned long long time, int check) } if (ahci_mode_ccc) { - if (superbyte_ccc[43] == 0x3d) + // ahci + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); + // fprintf (stdout, "%08x\n", io_doubleword_ccc); //debug + busy = io_doubleword_ccc & 0x80; + drq = io_doubleword_ccc & 0x08; + err = io_doubleword_ccc & 0x01; + unsigned char current_status = io_doubleword_ccc; + unsigned char current_error = io_doubleword_ccc >> 8; + memcpy(&ata_error_ccc, ¤t_error, 1); + memcpy(&ata_status_ccc, ¤t_status, 1); + memcpy(&io_singlebyte_ccc, port_virt_addr_ccc + 0x34, 1); + if (io_singlebyte_ccc) { - // ahci - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); - // fprintf (stdout, "%08x\n", io_doubleword_ccc); //debug - busy = io_doubleword_ccc & 0x80; - drq = io_doubleword_ccc & 0x08; - err = io_doubleword_ccc & 0x01; - unsigned char current_status = io_doubleword_ccc; - unsigned char current_error = io_doubleword_ccc >> 8; - memcpy(&ata_error_ccc, ¤t_error, 1); - memcpy(&ata_status_ccc, ¤t_status, 1); - memcpy(&io_singlebyte_ccc, port_virt_addr_ccc + superbyte_ccc[69], 1); // potential superbyte - if (io_singlebyte_ccc) + dscount++; + } + if (busy) + { + busycount++; + } + if (drq) + { + drqcount++; + } + if (err) + { + errcount++; + } + if (use_fpdma_ccc && wait_for_ds_bit_ccc && !performing_reset_ccc) + { + ncq = io_singlebyte_ccc & 1; + if (ncq) { - dscount++; - } - if (busy) - { - busycount++; - } - if (drq) - { - drqcount++; + ncqcount++; } if (err) { - errcount++; + // timeout = 4; + break; } - if (use_fpdma_ccc && wait_for_ds_bit_ccc && !performing_reset_ccc) - { - ncq = io_singlebyte_ccc & 1; - if (ncq) - { - ncqcount++; - } - if (err) - { - // timeout = 4; - break; - } - } - // fprintf (stdout, "busy=%d drq=%d err=%d ncq=%d\n", busy, drq, err, ncq); } + // fprintf (stdout, "busy=%d drq=%d err=%d ncq=%d\n", busy, drq, err, ncq); } else { @@ -9716,55 +9663,52 @@ int wait_drdy_not_busy_or_drq_ccc(unsigned long long time, int check) } if (ahci_mode_ccc) { - if (superbyte_ccc[43] == 0x3d) + // ahci + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + 0x20, 4); + // fprintf (stdout, "%08x\n", io_doubleword_ccc); //debug + busy = io_doubleword_ccc & 0x80; + drdy = io_doubleword_ccc & 0x40; + drq = io_doubleword_ccc & 0x08; + err = io_doubleword_ccc & 0x01; + unsigned char current_status = io_doubleword_ccc; + unsigned char current_error = io_doubleword_ccc >> 8; + memcpy(&ata_error_ccc, ¤t_error, 1); + memcpy(&ata_status_ccc, ¤t_status, 1); + memcpy(&io_singlebyte_ccc, port_virt_addr_ccc + 0x34, 1); + if (io_singlebyte_ccc) { - // ahci - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + superbyte_ccc[8], 4); - // fprintf (stdout, "%08x\n", io_doubleword_ccc); //debug - busy = io_doubleword_ccc & 0x80; - drdy = io_doubleword_ccc & 0x40; - drq = io_doubleword_ccc & 0x08; - err = io_doubleword_ccc & 0x01; - unsigned char current_status = io_doubleword_ccc; - unsigned char current_error = io_doubleword_ccc >> 8; - memcpy(&ata_error_ccc, ¤t_error, 1); - memcpy(&ata_status_ccc, ¤t_status, 1); - memcpy(&io_singlebyte_ccc, port_virt_addr_ccc + superbyte_ccc[69], 1); // potential superbyte - if (io_singlebyte_ccc) + dscount++; + } + if (busy) + { + busycount++; + } + if (!drdy) + { + drdycount++; + } + if (drq) + { + drqcount++; + } + if (err) + { + errcount++; + } + if (use_fpdma_ccc && wait_for_ds_bit_ccc && !performing_reset_ccc) + { + ncq = io_singlebyte_ccc & 1; + if (ncq) { - dscount++; - } - if (busy) - { - busycount++; - } - if (!drdy) - { - drdycount++; - } - if (drq) - { - drqcount++; + ncqcount++; } if (err) { - errcount++; + // timeout = 4; + break; } - if (use_fpdma_ccc && wait_for_ds_bit_ccc && !performing_reset_ccc) - { - ncq = io_singlebyte_ccc & 1; - if (ncq) - { - ncqcount++; - } - if (err) - { - // timeout = 4; - break; - } - } - // fprintf (stdout, "busy=%d drdy=%d drq=%d err=%d ncq=%d\n", busy, drdy, drq, err, ncq); } + // fprintf (stdout, "busy=%d drdy=%d drq=%d err=%d ncq=%d\n", busy, drdy, drq, err, ncq); } else { @@ -9809,7 +9753,7 @@ int set_device_ccc(unsigned long long address, int device) int set_and_send_regs_ccc(int command_type) { // leave this here for reference even though it does not do anything - if (0 && superbyte_ccc[44] == 0x88 && passthrough_ccc.direction == 1) + if (0 && passthrough_ccc.direction == 1) { // check serial byte 9 at random } @@ -9817,152 +9761,149 @@ int set_and_send_regs_ccc(int command_type) // ahci if (ahci_mode_ccc) { - if (superbyte_ccc[45] == 0x33) + // ahci + // clear the fis buffer + memset(fis_buffer_ccc, 0, fis_size_ccc); + // clear the command FIS + memset(table_buffer_ccc, 0, 0x80); + // set FIS type + memset(table_buffer_ccc, REG_H2D, 1); + // set type as command + memset(table_buffer_ccc + 1, 0x80, 1); + // set the table entry length + uint16_t word = table_entry_count_ccc; + memcpy(command_list_buffer_ccc + 2, &word, 2); + // set the command table address + uint64_t qword = table_physical_address_ccc; + memcpy(command_list_buffer_ccc + 8, &qword, 8); + + if (enable_data_dump_ccc) { - // ahci - // clear the fis buffer - memset(fis_buffer_ccc, 0, fis_size_ccc); - // clear the command FIS - memset(table_buffer_ccc, 0, 0x80); - // set FIS type - memset(table_buffer_ccc, REG_H2D, 1); - // set type as command - memset(table_buffer_ccc + 1, 0x80, 1); - // set the table entry length - uint16_t word = table_entry_count_ccc; - memcpy(command_list_buffer_ccc + 2, &word, 2); - // set the command table address - uint64_t qword = table_physical_address_ccc; - memcpy(command_list_buffer_ccc + 8, &qword, 8); + // set the control register value (something unknown) + memset(table_buffer_ccc + 15, 0x08, 1); + } - if (enable_data_dump_ccc) + if (command_type == 28) + { + // set command + memset(table_buffer_ccc + 2, passthrough_ccc.ata_cmd[6], 1); // command + memset(table_buffer_ccc + 3, passthrough_ccc.ata_cmd[0], 1); // feature + memset(table_buffer_ccc + 4, passthrough_ccc.ata_cmd[2], 1); // lba low + memset(table_buffer_ccc + 5, passthrough_ccc.ata_cmd[3], 1); // lba mid + memset(table_buffer_ccc + 6, passthrough_ccc.ata_cmd[4], 1); // lba high + passthrough_ccc.ata_cmd[5] = passthrough_ccc.ata_cmd[5] & 0xef; // strip out the device select bit + passthrough_ccc.ata_cmd[5] = passthrough_ccc.ata_cmd[5] | (device_select_base_ccc << 4); // set proper select bit + memset(table_buffer_ccc + 7, passthrough_ccc.ata_cmd[5], 1); // device + memset(table_buffer_ccc + 12, passthrough_ccc.ata_cmd[1], 1); // count + } + + else if (command_type == 48) + { + // set command + memset(table_buffer_ccc + 2, passthrough_ccc.ata_cmd[11], 1); // command + memset(table_buffer_ccc + 3, passthrough_ccc.ata_cmd[1], 1); // feature low + memset(table_buffer_ccc + 4, passthrough_ccc.ata_cmd[5], 1); // LBA LL 7:0 + memset(table_buffer_ccc + 5, passthrough_ccc.ata_cmd[7], 1); // LBA LH 15:8 + memset(table_buffer_ccc + 6, passthrough_ccc.ata_cmd[9], 1); // LBA ML 23:16 + passthrough_ccc.ata_cmd[10] = passthrough_ccc.ata_cmd[10] & 0xef; // strip out the device select bit + passthrough_ccc.ata_cmd[10] = passthrough_ccc.ata_cmd[10] | (device_select_base_ccc << 4); // set proper select bit + memset(table_buffer_ccc + 7, passthrough_ccc.ata_cmd[10], 1); // device + memset(table_buffer_ccc + 8, passthrough_ccc.ata_cmd[4], 1); // LBA MH 31:24 + memset(table_buffer_ccc + 9, passthrough_ccc.ata_cmd[6], 1); // LBA HL 39:32 + memset(table_buffer_ccc + 10, passthrough_ccc.ata_cmd[8], 1); // LBA HH 47:40 + memset(table_buffer_ccc + 11, passthrough_ccc.ata_cmd[0], 1); // feature high + memset(table_buffer_ccc + 12, passthrough_ccc.ata_cmd[3], 1); // sector count low + memset(table_buffer_ccc + 13, passthrough_ccc.ata_cmd[2], 1); // sector count high + } + + else + { + sprintf(tempmessage_ccc, "\n\nInternal error, send regs command type not valid\n\n"); + if (superclone_ccc) { - // set the control register value (something unknown) - memset(table_buffer_ccc + 15, 0x08, 1); + message_error_ccc(tempmessage_ccc); + print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); + clear_error_message_ccc(); } - - if (command_type == 28) - { - // set command - memset(table_buffer_ccc + 2, passthrough_ccc.ata_cmd[6], 1); // command - memset(table_buffer_ccc + 3, passthrough_ccc.ata_cmd[0], 1); // feature - memset(table_buffer_ccc + 4, passthrough_ccc.ata_cmd[2], 1); // lba low - memset(table_buffer_ccc + 5, passthrough_ccc.ata_cmd[3], 1); // lba mid - memset(table_buffer_ccc + 6, passthrough_ccc.ata_cmd[4], 1); // lba high - passthrough_ccc.ata_cmd[5] = passthrough_ccc.ata_cmd[5] & 0xef; // strip out the device select bit - passthrough_ccc.ata_cmd[5] = passthrough_ccc.ata_cmd[5] | (device_select_base_ccc << 4); // set proper select bit - memset(table_buffer_ccc + 7, passthrough_ccc.ata_cmd[5], 1); // device - memset(table_buffer_ccc + 12, passthrough_ccc.ata_cmd[1], 1); // count - } - - else if (command_type == 48) - { - // set command - memset(table_buffer_ccc + 2, passthrough_ccc.ata_cmd[11], 1); // command - memset(table_buffer_ccc + 3, passthrough_ccc.ata_cmd[1], 1); // feature low - memset(table_buffer_ccc + 4, passthrough_ccc.ata_cmd[5], 1); // LBA LL 7:0 - memset(table_buffer_ccc + 5, passthrough_ccc.ata_cmd[7], 1); // LBA LH 15:8 - memset(table_buffer_ccc + 6, passthrough_ccc.ata_cmd[9], 1); // LBA ML 23:16 - passthrough_ccc.ata_cmd[10] = passthrough_ccc.ata_cmd[10] & 0xef; // strip out the device select bit - passthrough_ccc.ata_cmd[10] = passthrough_ccc.ata_cmd[10] | (device_select_base_ccc << 4); // set proper select bit - memset(table_buffer_ccc + 7, passthrough_ccc.ata_cmd[10], 1); // device - memset(table_buffer_ccc + 8, passthrough_ccc.ata_cmd[4], 1); // LBA MH 31:24 - memset(table_buffer_ccc + 9, passthrough_ccc.ata_cmd[6], 1); // LBA HL 39:32 - memset(table_buffer_ccc + 10, passthrough_ccc.ata_cmd[8], 1); // LBA HH 47:40 - memset(table_buffer_ccc + 11, passthrough_ccc.ata_cmd[0], 1); // feature high - memset(table_buffer_ccc + 12, passthrough_ccc.ata_cmd[3], 1); // sector count low - memset(table_buffer_ccc + 13, passthrough_ccc.ata_cmd[2], 1); // sector count high - } - else { - sprintf(tempmessage_ccc, "\n\nInternal error, send regs command type not valid\n\n"); - if (superclone_ccc) - { - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - } - else - { - message_now_ccc(tempmessage_ccc); - message_exit_ccc(tempmessage_ccc); - exitcode_ccc = INTERNAL_ERROR_EXIT_CODE; - } - return -1; + message_now_ccc(tempmessage_ccc); + message_exit_ccc(tempmessage_ccc); + exitcode_ccc = INTERNAL_ERROR_EXIT_CODE; } + return -1; + } #ifdef DEBUG - if (debug_ccc & DEBUG36) + if (debug_ccc & DEBUG36) + { + int i; + for (i = 0; i < 256; i += 16) { - int i; - for (i = 0; i < 256; i += 16) + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)table_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)table_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); + c = (unsigned char *)table_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); } - } - - if (debug_ccc & DEBUG36) - { - int i; - for (i = 0; i < 256; i += 16) + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)fis_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)fis_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); + c = (unsigned char *)table_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); } + fprintf(stdout, "\n"); } - - if (debug_ccc & DEBUG36) - { - int i; - for (i = 0; i < 128; i += 16) - { - fprintf(stdout, "%x: ", i); - unsigned char *c; - int n; - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)command_list_buffer_ccc + i + n; - fprintf(stdout, "%02x ", *c); - } - fprintf(stdout, " "); - for (n = 0; n < 16 && i + n < 512; n++) - { - c = (unsigned char *)command_list_buffer_ccc + i + n; - fprintf(stdout, "%c", isprint(*c) ? *c : '.'); - } - fprintf(stdout, "\n"); - } - } -#endif } + + if (debug_ccc & DEBUG36) + { + int i; + for (i = 0; i < 256; i += 16) + { + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)fis_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); + } + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)fis_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); + } + fprintf(stdout, "\n"); + } + } + + if (debug_ccc & DEBUG36) + { + int i; + for (i = 0; i < 128; i += 16) + { + fprintf(stdout, "%x: ", i); + unsigned char *c; + int n; + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)command_list_buffer_ccc + i + n; + fprintf(stdout, "%02x ", *c); + } + fprintf(stdout, " "); + for (n = 0; n < 16 && i + n < 512; n++) + { + c = (unsigned char *)command_list_buffer_ccc + i + n; + fprintf(stdout, "%c", isprint(*c) ? *c : '.'); + } + fprintf(stdout, "\n"); + } + } +#endif } else @@ -10053,77 +9994,74 @@ int check_for_unwanted_changes_ccc(void) if (ahci_mode_ccc) { - if (superbyte_ccc[46] == 0x9b) + uint32_t wtf; + // check that interrupts are still turned off + memcpy(&wtf, port_virt_addr_ccc + 0x14, 4); + if (wtf) { - uint32_t wtf; - // check that interrupts are still turned off - memcpy(&wtf, port_virt_addr_ccc + superbyte_ccc[13], 4); // potential superbyte - if (wtf) - { - changed_status = changed_status + 0x0100; - } + changed_status = changed_status + 0x0100; + } - // check that start bit and fis enable are still on - memcpy(&wtf, port_virt_addr_ccc + superbyte_ccc[10], 4); // potential superbyte - if (!(wtf & 0x01)) - { - changed_status = changed_status + 0x0200; - } - if (!(wtf & 0x10)) - { - changed_status = changed_status + 0x0400; - } + // check that start bit and fis enable are still on + memcpy(&wtf, port_virt_addr_ccc + 0x18, 4); + if (!(wtf & 0x01)) + { + changed_status = changed_status + 0x0200; + } + if (!(wtf & 0x10)) + { + changed_status = changed_status + 0x0400; + } - // check addresses - uint64_t wtf2; - uint64_t wtf3; - memcpy(&wtf2, port_virt_addr_ccc + superbyte_ccc[11], 8); // command list address - memcpy(&wtf3, port_virt_addr_ccc + superbyte_ccc[12], 8); // fis address - if (command_list_physical_address_ccc != wtf2) - { - changed_status = changed_status + 0x0800; - } - if (fis_physical_address_ccc != wtf3) - { - changed_status = changed_status + 0x1000; - } + // check addresses + uint64_t wtf2; + uint64_t wtf3; + memcpy(&wtf2, port_virt_addr_ccc + 0x00, 8); // command list address + memcpy(&wtf3, port_virt_addr_ccc + 0x08, 8); // fis address + if (command_list_physical_address_ccc != wtf2) + { + changed_status = changed_status + 0x0800; + } + if (fis_physical_address_ccc != wtf3) + { + changed_status = changed_status + 0x1000; + } #ifdef DEBUG - if (changed_status && (debug_ccc & DEBUG38)) + if (changed_status && (debug_ccc & DEBUG38)) + { + fprintf(stdout, "status changed\n"); // debug + int i; + for (i = 0; i < 0x80; i += 4) { - fprintf(stdout, "status changed\n"); // debug - int i; - for (i = 0; i < 0x80; i += 4) + break; // debug + memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); + fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug + int n; + for (n = 0; n < 32; n++) { - break; // debug - memcpy(&io_doubleword_ccc, port_virt_addr_ccc + i, 4); - fprintf(stdout, "%x %08x ", i, io_doubleword_ccc); // debug - int n; - for (n = 0; n < 32; n++) + if (!(n % 8)) { - if (!(n % 8)) - { - fprintf(stdout, " "); - } - if ((io_doubleword_ccc << n) & 0x80000000) - fprintf(stdout, "1"); - else - fprintf(stdout, "0"); + fprintf(stdout, " "); } - fprintf(stdout, "\n"); + if ((io_doubleword_ccc << n) & 0x80000000) + fprintf(stdout, "1"); + else + fprintf(stdout, "0"); } + fprintf(stdout, "\n"); } -#endif } +#endif } else { // ide - unsigned char ta1 = inb(bus_base_address_ccc + 0 + superbyte_ccc[0]); // potential superbyte - unsigned char ta2 = inb(bus_base_address_ccc + 1 + superbyte_ccc[0]); // potential superbyte - unsigned char ta3 = inb(bus_base_address_ccc + 2 + superbyte_ccc[0]); // potential superbyte - unsigned char ta4 = inb(bus_base_address_ccc + 3 + superbyte_ccc[0]); // potential superbyte + unsigned char ta1 = inb(bus_base_address_ccc + 0 + 0x04); + unsigned char ta2 = inb(bus_base_address_ccc + 1 + 0x04); + unsigned char ta3 = inb(bus_base_address_ccc + 2 + 0x04); + unsigned char ta4 = inb(bus_base_address_ccc + 3 + 0x04); unsigned char tpa1 = table_physical_address_ccc; unsigned char tpa2 = table_physical_address_ccc >> 8; unsigned char tpa3 = table_physical_address_ccc >> 16; @@ -10141,12 +10079,9 @@ unsigned int get_ahci_error_ccc(void) { if (ahci_mode_ccc) { - if (superbyte_ccc[47] == 0x41) - { - uint32_t port_error; - memcpy(&port_error, port_virt_addr_ccc + superbyte_ccc[18], 4); // port error - return port_error; - } + uint32_t port_error; + memcpy(&port_error, port_virt_addr_ccc + 0x30, 4); // port error + return port_error; } return 0; } @@ -10155,12 +10090,9 @@ unsigned int get_ahci_status_ccc(void) { if (ahci_mode_ccc) { - if (superbyte_ccc[47] == 0x41) - { - uint64_t port_status; - memcpy(&port_status, port_virt_addr_ccc + superbyte_ccc[18] + 4, 4); // port status - return port_status; - } + uint64_t port_status; + memcpy(&port_status, port_virt_addr_ccc + 0x30 + 4, 4); // port status + return port_status; } return 0; } @@ -10168,189 +10100,160 @@ unsigned int get_ahci_status_ccc(void) int disable_fis_ccc(unsigned long long time) { int timeout = 0; - if (superbyte_ccc[48] == 0x0a) - { - uint8_t byte; - timeout = 0; - // clear the fis enable bit - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - byte = byte & 0xef; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); + uint8_t byte; + timeout = 0; + // clear the fis enable bit + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + byte = byte & 0xef; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); - // wait for fis running bit to clear - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); - byte = byte & 0x40; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (byte) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + time) - { - // if it exceeds general timeout then quit - timeout = 1; - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); - byte = byte & 0x40; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - } - else + // wait for fis running bit to clear + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x40; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (byte) { - timeout = 0; + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + time) + { + // if it exceeds general timeout then quit + timeout = 1; + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x40; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); } + return (timeout); } int enable_fis_ccc(unsigned long long time) { int timeout = 0; - if (superbyte_ccc[49] == 0xd9) - { - uint8_t byte; - timeout = 0; - // set the fis enable bit - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - byte = byte | 0x10; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + uint8_t byte; + timeout = 0; + // set the fis enable bit + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + byte = byte | 0x10; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); - // wait for fis running bit to set - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); // potential superbyte - byte = byte & 0x40; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (!byte) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + time) - { - // if it exceeds general timeout then quit - timeout = 1; - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); // potential superbyte - byte = byte & 0x40; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - } - else + // wait for fis running bit to set + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x40; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (!byte) { - timeout = 0; + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + time) + { + // if it exceeds general timeout then quit + timeout = 1; + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x40; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); } + return (timeout); } int disable_start_ccc(unsigned long long time) { int timeout = 0; - if (superbyte_ccc[50] == 0x22) - { - uint8_t byte; - timeout = 0; - // clear the start bit - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - byte = byte & 0xfe; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + uint8_t byte; + timeout = 0; + // clear the start bit + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + byte = byte & 0xfe; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); - // wait for command list running bit to clear - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); // potential superbyte - byte = byte & 0x80; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (byte) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + time) - { - // if it exceeds general timeout then quit - timeout = 1; - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); // potential superbyte - byte = byte & 0x80; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - } - else + // wait for command list running bit to clear + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x80; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (byte) { - timeout = 0; + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + time) + { + // if it exceeds general timeout then quit + timeout = 1; + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x80; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); } + return (timeout); } int enable_start_ccc(unsigned long long time) { int timeout = 0; - if (superbyte_ccc[51] == 0x4b) - { - uint8_t byte; - timeout = 0; - // set the start bit - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[10], 1); // potential superbyte - byte = byte | 0x01; - memcpy(port_virt_addr_ccc + superbyte_ccc[10], &byte, 1); // potential superbyte + uint8_t byte; + timeout = 0; + // set the start bit + memcpy(&byte, port_virt_addr_ccc + 0x18, 1); + byte = byte | 0x01; + memcpy(port_virt_addr_ccc + 0x18, &byte, 1); - // wait for command list running bit to set - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); // potential superbyte - byte = byte & 0x80; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (!byte) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + time) - { - // if it exceeds general timeout then quit - timeout = 1; - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); // potential superbyte - byte = byte & 0x80; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - } - else + // wait for command list running bit to set + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x80; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (!byte) { - timeout = 0; + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + time) + { + // if it exceeds general timeout then quit + timeout = 1; + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x80; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); } + return (timeout); } int enable_command_issue_ccc(unsigned long long time) { int timeout = 0; - if (superbyte_ccc[51] == 0x4b) - { - uint8_t byte; - timeout = 0; - // set the command issue bit - io_doubleword_ccc = 1; - memcpy(port_virt_addr_ccc + superbyte_ccc[6], &io_doubleword_ccc, 4); // potential superbyte - // wait for busy bit to set - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[8], 1); // potential superbyte - byte = byte & 0x80; - unsigned long long start_time = get_elapsed_usec_ccc(); - while (!byte) - { - unsigned long long elapsed_time = get_elapsed_usec_ccc(); - if (elapsed_time > start_time + time) - { - // if it exceeds general timeout then quit - timeout = 1; - break; - } - memcpy(&byte, port_virt_addr_ccc + superbyte_ccc[14], 1); // potential superbyte - byte = byte & 0x80; - // give the cpu a chance to do something else so we are not using 100% - do_nanosleep_ccc(1); - } - } - else + uint8_t byte; + timeout = 0; + // set the command issue bit + io_doubleword_ccc = 1; + memcpy(port_virt_addr_ccc + 0x38, &io_doubleword_ccc, 4); + + // wait for busy bit to set + memcpy(&byte, port_virt_addr_ccc + 0x20, 1); + byte = byte & 0x80; + unsigned long long start_time = get_elapsed_usec_ccc(); + while (!byte) { - timeout = 0; + unsigned long long elapsed_time = get_elapsed_usec_ccc(); + if (elapsed_time > start_time + time) + { + // if it exceeds general timeout then quit + timeout = 1; + break; + } + memcpy(&byte, port_virt_addr_ccc + 0x19, 1); + byte = byte & 0x80; + // give the cpu a chance to do something else so we are not using 100% + do_nanosleep_ccc(1); } + return (timeout); } @@ -10596,143 +10499,137 @@ int write_rebuild_assist_log_ccc(unsigned char data[LOG_PAGE_SIZE]) int start_driver_ccc(void) { - if (superbyte_ccc[57] == 0xcc) + sprintf(driver_device_name_ccc, "/proc/%s%d", MAIN_DRIVER_IOCTL_NAME, process_id_ccc); + if (main_driver_fd_ccc > 0) { - sprintf(driver_device_name_ccc, "/proc/%s%d", MAIN_DRIVER_IOCTL_NAME, process_id_ccc); - if (main_driver_fd_ccc > 0) - { - close(main_driver_fd_ccc); - } - main_driver_fd_ccc = open(driver_device_name_ccc, O_RDWR); - if (main_driver_fd_ccc == -1) - { - check_message_ccc = true; - strcpy(tempmessage_ccc, curlang_ccc[LANGUERROROPENINGDRIVER]); - message_error_ccc(tempmessage_ccc); - sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - return -1; - } - - if (charater_device_driver_mode_ccc) - { - driver_control_data_ccc.command = START_FILE_COMMAND; - } - else - { - driver_control_data_ccc.command = START_DRIVE_COMMAND; - } - unsigned long request = IOCTL_CMD_HDDSC; - // strcpy(driver_control_data_ccc.buffer, virtual_driver_name_ccc); - strncpy(driver_control_data_ccc.name, virtual_driver_name_ccc, sizeof(driver_control_data_ccc.name)); - // fprintf (stdout, "sizeofstructdata = %d\n", sizeof(driver_control_data_ccc)); // debug - int ret = ioctl(main_driver_fd_ccc, request, &driver_control_data_ccc); - if (ret < 0) - { - strcpy(tempmessage_ccc, curlang_ccc[LANGERRORSTARTINGDRIVER]); - message_error_ccc(tempmessage_ccc); - sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - if (charater_device_driver_mode_ccc) - { - // install the node - char command[256]; - sprintf(command, "mknod /dev/%s c %d 0", virtual_driver_name_ccc, ret); - system(command); - } - - // sleep for a few seconds before activating the driver to give it time to settle in - do_nanosleep_ccc(DRIVER_WAIT_TO_ACTIVATE_TIME); - - driver_control_data_ccc.command = ACTIVATE_DRIVE_COMMAND; - request = IOCTL_CMD_HDDSC; - ret = ioctl(main_driver_fd_ccc, request, &driver_control_data_ccc); - if (ret < 0) - { - strcpy(tempmessage_ccc, curlang_ccc[LANGERRORSTARTINGDRIVER]); - message_error_ccc(tempmessage_ccc); - sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - close(main_driver_fd_ccc); - driver_running_ccc = 1; } + main_driver_fd_ccc = open(driver_device_name_ccc, O_RDWR); + if (main_driver_fd_ccc == -1) + { + check_message_ccc = true; + strcpy(tempmessage_ccc, curlang_ccc[LANGUERROROPENINGDRIVER]); + message_error_ccc(tempmessage_ccc); + sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); + message_error_ccc(tempmessage_ccc); + print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); + clear_error_message_ccc(); + return -1; + } + + if (charater_device_driver_mode_ccc) + { + driver_control_data_ccc.command = START_FILE_COMMAND; + } + else + { + driver_control_data_ccc.command = START_DRIVE_COMMAND; + } + unsigned long request = IOCTL_CMD_HDDSC; + // strcpy(driver_control_data_ccc.buffer, virtual_driver_name_ccc); + strncpy(driver_control_data_ccc.name, virtual_driver_name_ccc, sizeof(driver_control_data_ccc.name)); + // fprintf (stdout, "sizeofstructdata = %d\n", sizeof(driver_control_data_ccc)); // debug + int ret = ioctl(main_driver_fd_ccc, request, &driver_control_data_ccc); + if (ret < 0) + { + strcpy(tempmessage_ccc, curlang_ccc[LANGERRORSTARTINGDRIVER]); + message_error_ccc(tempmessage_ccc); + sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + if (charater_device_driver_mode_ccc) + { + // install the node + char command[256]; + sprintf(command, "mknod /dev/%s c %d 0", virtual_driver_name_ccc, ret); + system(command); + } + + // sleep for a few seconds before activating the driver to give it time to settle in + do_nanosleep_ccc(DRIVER_WAIT_TO_ACTIVATE_TIME); + + driver_control_data_ccc.command = ACTIVATE_DRIVE_COMMAND; + request = IOCTL_CMD_HDDSC; + ret = ioctl(main_driver_fd_ccc, request, &driver_control_data_ccc); + if (ret < 0) + { + strcpy(tempmessage_ccc, curlang_ccc[LANGERRORSTARTINGDRIVER]); + message_error_ccc(tempmessage_ccc); + sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + close(main_driver_fd_ccc); + driver_running_ccc = 1; return 0; } int stop_driver_ccc(void) { - if (superbyte_ccc[58] == 0x74) + sprintf(driver_device_name_ccc, "/proc/%s%d", MAIN_DRIVER_IOCTL_NAME, process_id_ccc); + if (main_driver_fd_ccc > 0) { - sprintf(driver_device_name_ccc, "/proc/%s%d", MAIN_DRIVER_IOCTL_NAME, process_id_ccc); - if (main_driver_fd_ccc > 0) - { - close(main_driver_fd_ccc); - } - main_driver_fd_ccc = open(driver_device_name_ccc, O_RDWR); - if (main_driver_fd_ccc == -1) - { - check_message_ccc = true; - strcpy(tempmessage_ccc, curlang_ccc[LANGUERROROPENINGDRIVER]); - message_error_ccc(tempmessage_ccc); - sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - return -1; - } - int error = 0; - if (charater_device_driver_mode_ccc) - { - driver_control_data_ccc.command = STOP_FILE_COMMAND; - } - else - { - driver_control_data_ccc.command = STOP_DRIVE_COMMAND; - } - unsigned long request = IOCTL_CMD_HDDSC; - int ret = ioctl(main_driver_fd_ccc, request, &driver_control_data_ccc); - if (ret < 0) - { - error = 1; - strcpy(tempmessage_ccc, curlang_ccc[LANGERRORSTOPINGDRIVER]); - message_error_ccc(tempmessage_ccc); - sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); - message_error_ccc(tempmessage_ccc); - } - - if (charater_device_driver_mode_ccc) - { - // remove the node - char command[256]; - sprintf(command, "rm -f /dev/%s", virtual_driver_name_ccc); - system(command); - } - - ret = close(main_driver_fd_ccc); - if (ret < 0) - { - error = 1; - strcpy(tempmessage_ccc, curlang_ccc[LANGERRORCLOSINGINGDRIVER]); - message_error_ccc(tempmessage_ccc); - sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); - message_error_ccc(tempmessage_ccc); - } - if (error) - { - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - return -1; - } - driver_running_ccc = 0; + close(main_driver_fd_ccc); } + main_driver_fd_ccc = open(driver_device_name_ccc, O_RDWR); + if (main_driver_fd_ccc == -1) + { + check_message_ccc = true; + strcpy(tempmessage_ccc, curlang_ccc[LANGUERROROPENINGDRIVER]); + message_error_ccc(tempmessage_ccc); + sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); + message_error_ccc(tempmessage_ccc); + print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); + clear_error_message_ccc(); + return -1; + } + int error = 0; + if (charater_device_driver_mode_ccc) + { + driver_control_data_ccc.command = STOP_FILE_COMMAND; + } + else + { + driver_control_data_ccc.command = STOP_DRIVE_COMMAND; + } + unsigned long request = IOCTL_CMD_HDDSC; + int ret = ioctl(main_driver_fd_ccc, request, &driver_control_data_ccc); + if (ret < 0) + { + error = 1; + strcpy(tempmessage_ccc, curlang_ccc[LANGERRORSTOPINGDRIVER]); + message_error_ccc(tempmessage_ccc); + sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); + message_error_ccc(tempmessage_ccc); + } + + if (charater_device_driver_mode_ccc) + { + // remove the node + char command[256]; + sprintf(command, "rm -f /dev/%s", virtual_driver_name_ccc); + system(command); + } + + ret = close(main_driver_fd_ccc); + if (ret < 0) + { + error = 1; + strcpy(tempmessage_ccc, curlang_ccc[LANGERRORCLOSINGINGDRIVER]); + message_error_ccc(tempmessage_ccc); + sprintf(tempmessage_ccc, " %s (%s)\n", driver_device_name_ccc, strerror(errno)); + message_error_ccc(tempmessage_ccc); + } + if (error) + { + print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); + clear_error_message_ccc(); + return -1; + } + driver_running_ccc = 0; return 0; } @@ -10761,112 +10658,107 @@ int check_driver_ccc(void) int map_driver_memory_ccc(void) { - if (superbyte_ccc[59] == 0x0c) + unmap_driver_memory_ccc(); + int configfd; + driver_control_address_ccc = NULL; + driver_error_bitmap_address_ccc = NULL; + driver_transfer_buffer_address_ccc = NULL; + driver_memory_mapped_ccc = 0; + + char name[256]; + sprintf(name, "/proc/%s%d", MAIN_DRIVER_MMAP_NAME, process_id_ccc); + configfd = open(name, O_RDWR); + if (configfd < 0) { - unmap_driver_memory_ccc(); - int configfd; - driver_control_address_ccc = NULL; - driver_error_bitmap_address_ccc = NULL; - driver_transfer_buffer_address_ccc = NULL; - driver_memory_mapped_ccc = 0; - - char name[256]; - sprintf(name, "/proc/%s%d", MAIN_DRIVER_MMAP_NAME, process_id_ccc); - configfd = open(name, O_RDWR); - if (configfd < 0) - { - sprintf(tempmessage_ccc, "Opening driver mapping file failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - driver_control_address_ccc = mmap(NULL, pagesize_ccc, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, 0); - if (driver_control_address_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - driver_error_bitmap_address_ccc = mmap(NULL, pagesize_ccc * 2, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, pagesize_ccc * 1); - if (driver_error_bitmap_address_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - driver_table_buffer_ccc = mmap(NULL, pagesize_ccc * 4, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, pagesize_ccc * 3); - if (driver_table_buffer_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - driver_command_list_buffer_ccc = mmap(NULL, pagesize_ccc, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, pagesize_ccc * 7); - if (driver_command_list_buffer_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - driver_fis_buffer_ccc = mmap(NULL, pagesize_ccc, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, pagesize_ccc * 8); - if (driver_fis_buffer_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - close(configfd); - - sprintf(name, "/proc/%s%d", MAIN_DRIVER_MMAPTB_NAME, process_id_ccc); - configfd = open(name, O_RDWR); - if (configfd < 0) - { - sprintf(tempmessage_ccc, "Opening driver mapping file failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - driver_transfer_buffer_address_ccc = mmap(NULL, DRIVER_TRANSFER_BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, 0); - if (driver_transfer_buffer_address_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - close(configfd); - - sprintf(name, "/proc/%s%d", MAIN_DRIVER_MMAPMDB_NAME, process_id_ccc); - configfd = open(name, O_RDWR); - if (configfd < 0) - { - sprintf(tempmessage_ccc, "Opening driver mapping file failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - - driver_main_data_buffer_address_ccc = mmap(NULL, DRIVER_MAIN_DATA_BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, 0); - if (driver_main_data_buffer_address_ccc == MAP_FAILED) - { - sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); - message_error_ccc(tempmessage_ccc); - return -1; - } - close(configfd); - - driver_memory_mapped_ccc = 1; + sprintf(tempmessage_ccc, "Opening driver mapping file failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; } + + driver_control_address_ccc = mmap(NULL, pagesize_ccc, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, 0); + if (driver_control_address_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + driver_error_bitmap_address_ccc = mmap(NULL, pagesize_ccc * 2, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, pagesize_ccc * 1); + if (driver_error_bitmap_address_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + driver_table_buffer_ccc = mmap(NULL, pagesize_ccc * 4, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, pagesize_ccc * 3); + if (driver_table_buffer_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + driver_command_list_buffer_ccc = mmap(NULL, pagesize_ccc, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, pagesize_ccc * 7); + if (driver_command_list_buffer_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + driver_fis_buffer_ccc = mmap(NULL, pagesize_ccc, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, pagesize_ccc * 8); + if (driver_fis_buffer_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + close(configfd); + + sprintf(name, "/proc/%s%d", MAIN_DRIVER_MMAPTB_NAME, process_id_ccc); + configfd = open(name, O_RDWR); + if (configfd < 0) + { + sprintf(tempmessage_ccc, "Opening driver mapping file failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + driver_transfer_buffer_address_ccc = mmap(NULL, DRIVER_TRANSFER_BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, 0); + if (driver_transfer_buffer_address_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + close(configfd); + + sprintf(name, "/proc/%s%d", MAIN_DRIVER_MMAPMDB_NAME, process_id_ccc); + configfd = open(name, O_RDWR); + if (configfd < 0) + { + sprintf(tempmessage_ccc, "Opening driver mapping file failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + + driver_main_data_buffer_address_ccc = mmap(NULL, DRIVER_MAIN_DATA_BUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, configfd, 0); + if (driver_main_data_buffer_address_ccc == MAP_FAILED) + { + sprintf(tempmessage_ccc, "Mapping driver memory failed (%s)\n", strerror(errno)); + message_error_ccc(tempmessage_ccc); + return -1; + } + close(configfd); + + driver_memory_mapped_ccc = 1; return 0; } int unmap_driver_memory_ccc(void) { - if (superbyte_ccc[60] == 0xaa) - { if (driver_control_address_ccc) { munmap(driver_control_address_ccc, pagesize_ccc); @@ -10907,20 +10799,19 @@ int unmap_driver_memory_ccc(void) ccc_buffer_ccc = NULL; } driver_memory_mapped_ccc = 0; - } return 0; } unsigned long long read_ctrl_data_ccc(int item) { unsigned long long value = 0; - memcpy(&value, driver_control_address_ccc + (item * superbyte_ccc[64]), superbyte_ccc[65]); // potential superbyte + memcpy(&value, driver_control_address_ccc + (item * 0x08), 0x08); return value; } void write_ctrl_data_ccc(int item, unsigned long long value) { - memcpy(driver_control_address_ccc + (item * superbyte_ccc[66]), &value, superbyte_ccc[67]); // potential superbyte + memcpy(driver_control_address_ccc + (item * 0x08), &value, 0x08); } unsigned char read_ctrl_error_bitmap_ccc(int offset) diff --git a/src/opensuperclone/opensuperclone.c b/src/opensuperclone/opensuperclone.c index fe555ec..79f02a5 100644 --- a/src/opensuperclone/opensuperclone.c +++ b/src/opensuperclone/opensuperclone.c @@ -51,9 +51,6 @@ int main(int argc, char **argv) start_time_ccc = time(NULL); // set some variables - check_command_ccc = 0; - check_read_ccc = 0; - check_write_ccc = 0; append_script_ccc = 0; ccc_indent_ccc = 0; spaces_ccc = 0; @@ -96,9 +93,6 @@ int main(int argc, char **argv) driver_return_marked_ccc = false; strcpy(command_to_call_ccc, ""); check_log_size_ccc = 1; - check_command_ccc = 0; - check_read_ccc = 0; - check_write_ccc = 0; append_script_ccc = 0; exitcode_ccc = 0; pagesize_ccc = sysconf(_SC_PAGESIZE); @@ -188,11 +182,6 @@ int main(int argc, char **argv) aggressive_driver_ccc = true; charater_device_driver_mode_ccc = false; // TODO make this an option normally false color_statusbar_ccc = false; - license_type_ccc = 0; - license_version_ccc = 0; - license_time_ccc = 0; - activation_type_ccc = 0; - activation_days_remaining_ccc = 0; running_analyze_ccc = 0; drive_locked_ccc = false; smart_supported_ccc = false; @@ -235,9 +224,6 @@ int main(int argc, char **argv) strcpy(virtual_driver_name_ccc, "sdv"); - // clear license data - memset(license_data_ccc, 0, sizeof(license_data_ccc)); - // get process id of this program process_id_ccc = getpid(); @@ -608,115 +594,6 @@ int main(int argc, char **argv) #endif } - memset(superbyte_ccc, 0, sizeof(superbyte_ccc)); - - // allow full pro mode for free - memcpy(license_data_ccc, master_data_ccc, 1024); - - superbyte_ccc[0] = license_data_ccc[0x00] ^ 0x43; // (0x47) 0x04 hard - superbyte_ccc[1] = license_data_ccc[0x01] ^ 0x85; // (0x83) 0x06 hard - superbyte_ccc[2] = license_data_ccc[0x02] ^ 0xc1; // (0xc9) 0x08 hard - superbyte_ccc[3] = license_data_ccc[0x03] ^ 0x04; // (0x0d) 0x09 hard - superbyte_ccc[4] = license_data_ccc[0x04] ^ 0xb2; // (0xb2) 0x00 hard - superbyte_ccc[5] = license_data_ccc[0x05] ^ 0xe7; // (0xe6) 0x01 hard - superbyte_ccc[6] = license_data_ccc[0x06] ^ 0xe3; // (0xdb) 0x38 hard - superbyte_ccc[7] = license_data_ccc[0x07] ^ 0x6f; // (0x7f) 0x10 hard - superbyte_ccc[8] = license_data_ccc[0x08] ^ 0x1a; // (0x3a) 0x20 hard - superbyte_ccc[9] = license_data_ccc[0x09] ^ 0xdc; // (0xfd) 0x21 hard - superbyte_ccc[10] = license_data_ccc[0x0a] ^ 0x03; // (0x1b) 0x18 hard - superbyte_ccc[11] = license_data_ccc[0x0b] ^ 0x55; // (0x55) 0x00 hard - superbyte_ccc[12] = license_data_ccc[0x0c] ^ 0x2e; // (0x26) 0x08 hard - superbyte_ccc[13] = license_data_ccc[0x0d] ^ 0x29; // (0x3d) 0x14 hard - superbyte_ccc[14] = license_data_ccc[0x0e] ^ 0x8a; // (0x93) 0x19 hard - superbyte_ccc[15] = license_data_ccc[0x0f] ^ 0xaa; // (0x2a) 0x80 hard - superbyte_ccc[16] = license_data_ccc[0x10] ^ 0xd7; // (0xfb) 0x2c hard - superbyte_ccc[17] = license_data_ccc[0x11] ^ 0x67; // (0x4f) 0x28 hard - superbyte_ccc[18] = license_data_ccc[0x12] ^ 0xbf; // (0x8f) 0x30 hard - superbyte_ccc[19] = license_data_ccc[0x13] ^ 0x1f; // (0x13) 0x0c hard - superbyte_ccc[20] = license_data_ccc[0x14] ^ 0x4e; // (0x67) 0x29 soft - superbyte_ccc[21] = license_data_ccc[0x15] ^ 0x73; // (0xd5) 0xa6 soft - superbyte_ccc[22] = license_data_ccc[0x16] ^ 0xde; // (0x0f) 0xd1 soft - superbyte_ccc[23] = license_data_ccc[0x17] ^ 0x20; // (0x7b) 0x5b soft - superbyte_ccc[24] = license_data_ccc[0x18] ^ 0xb7; // (0x03) 0xb4 soft - superbyte_ccc[25] = license_data_ccc[0x19] ^ 0x41; // (0x30) 0x71 soft - superbyte_ccc[26] = license_data_ccc[0x1a] ^ 0x54; // (0xae) 0xfa soft - superbyte_ccc[27] = license_data_ccc[0x1b] ^ 0x3d; // (0x23) 0x1e soft - superbyte_ccc[28] = license_data_ccc[0x1c] ^ 0xf5; // (0xba) 0x4f soft - superbyte_ccc[29] = license_data_ccc[0x1d] ^ 0x41; // (0x21) 0x60 soft - superbyte_ccc[30] = license_data_ccc[0x1e] ^ 0xb7; // (0x6e) 0xd9 soft - superbyte_ccc[31] = license_data_ccc[0x1f] ^ 0x97; // (0x0b) 0x9c soft - superbyte_ccc[32] = license_data_ccc[0x20] ^ 0xa3; // (0x20) 0x83 soft - superbyte_ccc[33] = license_data_ccc[0x21] ^ 0x33; // (0x83) 0xb0 soft - superbyte_ccc[34] = license_data_ccc[0x22] ^ 0xd8; // (0x89) 0x51 soft - superbyte_ccc[35] = license_data_ccc[0x23] ^ 0x14; // (0x32) 0x26 soft - superbyte_ccc[36] = license_data_ccc[0x24] ^ 0x1e; // (0x71) 0x6f soft - superbyte_ccc[37] = license_data_ccc[0x25] ^ 0x32; // (0xc7) 0xf5 soft - superbyte_ccc[38] = license_data_ccc[0x26] ^ 0x99; // (0xc9) 0x50 soft - superbyte_ccc[39] = license_data_ccc[0x27] ^ 0x4d; // (0x43) 0x0e soft - superbyte_ccc[40] = license_data_ccc[0x28] ^ 0x8a; // (0x8f) 0x05 soft - superbyte_ccc[41] = license_data_ccc[0x29] ^ 0x83; // (0x57) 0xd4 soft - superbyte_ccc[42] = license_data_ccc[0x2a] ^ 0x64; // (0x44) 0x20 soft - superbyte_ccc[43] = license_data_ccc[0x2b] ^ 0x16; // (0x2b) 0x3d soft - superbyte_ccc[44] = license_data_ccc[0x2c] ^ 0x8f; // (0x07) 0x88 soft - superbyte_ccc[45] = license_data_ccc[0x2d] ^ 0x1d; // (0x2e) 0x33 soft - superbyte_ccc[46] = license_data_ccc[0x2e] ^ 0xcd; // (0x56) 0x9b soft - superbyte_ccc[47] = license_data_ccc[0x2f] ^ 0x55; // (0x14) 0x41 soft - superbyte_ccc[48] = license_data_ccc[0x30] ^ 0x23; // (0x29) 0x0a soft - superbyte_ccc[49] = license_data_ccc[0x31] ^ 0x74; // (0xad) 0xd9 soft - superbyte_ccc[50] = license_data_ccc[0x32] ^ 0xda; // (0xf8) 0x22 soft - superbyte_ccc[51] = license_data_ccc[0x33] ^ 0x62; // (0x29) 0x4b soft - superbyte_ccc[52] = license_data_ccc[0x34] ^ 0xda; // (0x2a) 0xf0 soft - superbyte_ccc[53] = license_data_ccc[0x35] ^ 0xdd; // (0x52) 0x8f soft - superbyte_ccc[54] = license_data_ccc[0x36] ^ 0xc7; // (0x01) 0xc6 soft - superbyte_ccc[55] = license_data_ccc[0x37] ^ 0x6b; // (0x2d) 0x46 soft - superbyte_ccc[56] = license_data_ccc[0x38] ^ 0x3a; // (0x51) 0x6b soft - superbyte_ccc[57] = license_data_ccc[0x39] ^ 0x8d; // (0x41) 0xcc soft - superbyte_ccc[58] = license_data_ccc[0x3a] ^ 0xc8; // (0xbc) 0x74 soft - superbyte_ccc[59] = license_data_ccc[0x3b] ^ 0x59; // (0x55) 0x0c soft - superbyte_ccc[60] = license_data_ccc[0x3c] ^ 0x61; // (0xcb) 0xaa soft - superbyte_ccc[61] = license_data_ccc[0x3d] ^ 0x29; // (0x45) 0x6c soft - superbyte_ccc[62] = license_data_ccc[0x3e] ^ 0x67; // (0x72) 0x15 soft - superbyte_ccc[63] = license_data_ccc[0x3f] ^ 0x18; // (0x3d) 0x25 soft - superbyte_ccc[64] = license_data_ccc[0x40] ^ 0x64; // (0x6c) 0x08 hard - superbyte_ccc[65] = license_data_ccc[0x41] ^ 0x79; // (0x71) 0x08 hard - superbyte_ccc[66] = license_data_ccc[0x42] ^ 0xff; // (0xf7) 0x08 hard - superbyte_ccc[67] = license_data_ccc[0x43] ^ 0x6d; // (0x65) 0x08 hard - superbyte_ccc[68] = license_data_ccc[0x44] ^ 0x2c; // (0x28) 0x04 hard - superbyte_ccc[69] = license_data_ccc[0x45] ^ 0x92; // (0xa6) 0x34 hard - superbyte_ccc[70] = license_data_ccc[0x46] ^ 0xef; // (0xe8) 0x07 hard - superbyte_ccc[71] = license_data_ccc[0x47] ^ 0x75; // (0x7a) 0x0f hard - superbyte_ccc[72] = license_data_ccc[0x48] ^ 0xf1; // (0xff) 0x0e hard - superbyte_ccc[73] = license_data_ccc[0x49] ^ 0x28; // (0x24) 0x0c hard - superbyte_ccc[74] = license_data_ccc[0x4a] ^ 0x1d; // (0x19) 0x04 hard - superbyte_ccc[75] = license_data_ccc[0x4b] ^ 0x59; // (0x51) 0x08 hard - superbyte_ccc[76] = license_data_ccc[0x4c] ^ 0x33; // (0x33) 0x00 hard - superbyte_ccc[77] = license_data_ccc[0x4d] ^ 0x0; // (0x7d) - superbyte_ccc[78] = license_data_ccc[0x4e] ^ 0x0; // (0x61) - superbyte_ccc[79] = license_data_ccc[0x4f] ^ 0x0; // (0x79) - superbyte_ccc[80] = license_data_ccc[0x50] ^ 0x0; // (0x78) email pass - superbyte_ccc[81] = license_data_ccc[0x51] ^ 0x0; // (0x79) email pass - superbyte_ccc[82] = license_data_ccc[0x52] ^ 0x0; // (0x75) email pass - superbyte_ccc[83] = license_data_ccc[0x53] ^ 0x0; // (0x20) email pass - superbyte_ccc[84] = license_data_ccc[0x54] ^ 0x0; // (0x93) email pass - superbyte_ccc[85] = license_data_ccc[0x55] ^ 0x0; // (0xd3) email pass - superbyte_ccc[86] = license_data_ccc[0x56] ^ 0x0; // (0x5b) email pass - superbyte_ccc[87] = license_data_ccc[0x57] ^ 0x0; // (0x77) email pass - superbyte_ccc[88] = license_data_ccc[0x58] ^ 0x0; // (0x60) email pass - superbyte_ccc[89] = license_data_ccc[0x59] ^ 0x0; // (0x8e) email pass - superbyte_ccc[90] = license_data_ccc[0x5a] ^ 0x0; // (0x23) email pass - superbyte_ccc[91] = license_data_ccc[0x5b] ^ 0x0; // (0x73) email pass - superbyte_ccc[92] = license_data_ccc[0x5c] ^ 0x0; // (0x63) email pass - superbyte_ccc[93] = license_data_ccc[0x5d] ^ 0x0; // (0xb5) email pass - superbyte_ccc[94] = license_data_ccc[0x5e] ^ 0x0; // (0x78) email pass - superbyte_ccc[95] = license_data_ccc[0x5f] ^ 0x0; // (0x08) email pass - -#ifdef DEBUG - for (i = 0; i < 96; i++) - { - // fprintf (stdout, "superbyte%d(%02x) = %02x\n", i, i, superbyte_ccc[i]); - } -#endif - // Check if root privilages if (geteuid()) { @@ -1098,24 +975,24 @@ void release_devices_ccc(void) if (ahci_address_changed_ccc) { // restore addresses - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address_backup_ccc, 8); // potential superbyte - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address_backup_ccc, 8); // potential superbyte + memcpy(port_virt_addr_ccc + 0x00, &command_list_address_backup_ccc, 8); + memcpy(port_virt_addr_ccc + 0x08, &fis_address_backup_ccc, 8); ahci_address_changed_ccc = false; } if (ahci_interrupt_changed_ccc) { // restore the interrupt settings - memcpy(port_virt_addr_ccc + superbyte_ccc[13], &interrupt_backup_ccc, 4); // potential superbyte + memcpy(port_virt_addr_ccc + 0x14, &interrupt_backup_ccc, 4); ahci_interrupt_changed_ccc = false; } if (table_address_changed_ccc) { - outb(table_address_backup_ccc[0], bus_base_address_ccc + 0 + superbyte_ccc[0]); // potential superbyte - outb(table_address_backup_ccc[1], bus_base_address_ccc + 1 + superbyte_ccc[0]); // potential superbyte - outb(table_address_backup_ccc[2], bus_base_address_ccc + 2 + superbyte_ccc[0]); // potential superbyte - outb(table_address_backup_ccc[3], bus_base_address_ccc + 3 + superbyte_ccc[0]); // potential superbyte + outb(table_address_backup_ccc[0], bus_base_address_ccc + 0 + 0x04); + outb(table_address_backup_ccc[1], bus_base_address_ccc + 1 + 0x04); + outb(table_address_backup_ccc[2], bus_base_address_ccc + 2 + 0x04); + outb(table_address_backup_ccc[3], bus_base_address_ccc + 3 + 0x04); table_address_changed_ccc = false; } @@ -1468,132 +1345,132 @@ int initialize_memory_ccc(void) real_buffer_size_ccc = MAX_BUFFER_SIZE; memory_failed_ccc = true; int attempt = 0; - if (usb_mode_ccc && !driver_memory_mapped_ccc) + if (usb_mode_ccc && !driver_memory_mapped_ccc) + { + real_buffer_size_ccc = MAX_USB_BUFFER_SIZE; + } + while (attempt < 2) + { + attempt++; + if (!quiet_ccc) { - real_buffer_size_ccc = MAX_USB_BUFFER_SIZE; + sprintf(tempmessage_ccc, "Initializing memory\n"); + message_now_ccc(tempmessage_ccc); } - while (attempt < 2) + + if (attempt == 2 && !driver_installed_ccc) { - attempt++; - if (!quiet_ccc) - { - sprintf(tempmessage_ccc, "Initializing memory\n"); - message_now_ccc(tempmessage_ccc); - } + install_driver_ccc(); + } - if (attempt == 2 && !driver_installed_ccc) - { - install_driver_ccc(); - } + int multiplier = 1; + if (driver_installed_ccc && driver_memory_mapped_ccc) + { + multiplier = 4; + } + max_dma_size_ccc = ((pagesize_ccc * multiplier) / 16) * pagesize_ccc; + if (ahci_mode_ccc) + { + max_dma_size_ccc = (((pagesize_ccc * multiplier) - 128) / 16) * pagesize_ccc; + } - int multiplier = 1; - if (driver_installed_ccc && driver_memory_mapped_ccc) + padding_buffer_ccc = malloc(pagesize_ccc); + // initialize the table buffer + if (direct_mode_ccc) + { + return_value_ccc = set_table_buffer_ccc(); + if (return_value_ccc != 0) { - multiplier = 4; - } - max_dma_size_ccc = ((pagesize_ccc * multiplier) / 16) * pagesize_ccc; - if (ahci_mode_ccc) - { - max_dma_size_ccc = (((pagesize_ccc * multiplier) - 128) / 16) * pagesize_ccc; - } - - padding_buffer_ccc = malloc(pagesize_ccc); - // initialize the table buffer - if (direct_mode_ccc) - { - return_value_ccc = set_table_buffer_ccc(); - if (return_value_ccc != 0) + if (attempt < 2) { - if (attempt < 2) - { - continue; - } - strcpy(tempmessage_ccc, curlang_ccc[LANGBUFFERADDRESSRANGE]); + continue; + } + strcpy(tempmessage_ccc, curlang_ccc[LANGBUFFERADDRESSRANGE]); + message_error_ccc(tempmessage_ccc); + print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); + clear_error_message_ccc(); + return GENERAL_ERROR_RETURN_CODE; + } + } + + if (ahci_mode_ccc) + { + // initialize the command list buffer + return_value_ccc = set_command_list_buffer_ccc(); + if (return_value_ccc != 0) + { + if (attempt < 2) + { + continue; + } + strcpy(tempmessage_ccc, curlang_ccc[LANGBUFFERADDRESSRANGE]); + message_error_ccc(tempmessage_ccc); + print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); + clear_error_message_ccc(); + return GENERAL_ERROR_RETURN_CODE; + } + + // initialize the FIS buffer + return_value_ccc = set_fis_buffer_ccc(); + if (return_value_ccc != 0) + { + if (attempt < 2) + { + continue; + } + strcpy(tempmessage_ccc, curlang_ccc[LANGBUFFERADDRESSRANGE]); + message_error_ccc(tempmessage_ccc); + print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); + clear_error_message_ccc(); + return GENERAL_ERROR_RETURN_CODE; + } + } + + // initialize main buffer + // create a buffer that is memory aligned with the pagesize + if (direct_mode_ccc) + { + return_value_ccc = get_buffer_physical_memory_locations_ccc(); + if (return_value_ccc != 0) + { + if (attempt < 2) + { + continue; + } + exitcode_ccc = GENERAL_ERROR_EXIT_CODE; + return (return_value_ccc); + } + } + else + { + unsigned int align = pagesize_ccc; + if (!driver_memory_mapped_ccc) + { + free(ccc_buffer_ccc); + if (posix_memalign(&ccc_buffer_ccc, align, real_buffer_size_ccc)) + { + strcpy(tempmessage_ccc, curlang_ccc[LANGPOSIXMEMFAIL]); + message_error_ccc(tempmessage_ccc); + sprintf(tempmessage_ccc, " (%s)", strerror(errno)); message_error_ccc(tempmessage_ccc); print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); clear_error_message_ccc(); return GENERAL_ERROR_RETURN_CODE; } } - - if (ahci_mode_ccc) - { - // initialize the command list buffer - return_value_ccc = set_command_list_buffer_ccc(); - if (return_value_ccc != 0) - { - if (attempt < 2) - { - continue; - } - strcpy(tempmessage_ccc, curlang_ccc[LANGBUFFERADDRESSRANGE]); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - return GENERAL_ERROR_RETURN_CODE; - } - - // initialize the FIS buffer - return_value_ccc = set_fis_buffer_ccc(); - if (return_value_ccc != 0) - { - if (attempt < 2) - { - continue; - } - strcpy(tempmessage_ccc, curlang_ccc[LANGBUFFERADDRESSRANGE]); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - return GENERAL_ERROR_RETURN_CODE; - } - } - - // initialize main buffer - // create a buffer that is memory aligned with the pagesize - if (direct_mode_ccc && superbyte_ccc[21] == 0xa6) - { - return_value_ccc = get_buffer_physical_memory_locations_ccc(); - if (return_value_ccc != 0) - { - if (attempt < 2) - { - continue; - } - exitcode_ccc = GENERAL_ERROR_EXIT_CODE; - return (return_value_ccc); - } - } else { - unsigned int align = pagesize_ccc; - if (!driver_memory_mapped_ccc) - { - free(ccc_buffer_ccc); - if (posix_memalign(&ccc_buffer_ccc, align, real_buffer_size_ccc)) - { - strcpy(tempmessage_ccc, curlang_ccc[LANGPOSIXMEMFAIL]); - message_error_ccc(tempmessage_ccc); - sprintf(tempmessage_ccc, " (%s)", strerror(errno)); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - return GENERAL_ERROR_RETURN_CODE; - } - } - else - { - ccc_buffer_ccc = driver_main_data_buffer_address_ccc; - } - memset(ccc_buffer_ccc, 0, real_buffer_size_ccc); + ccc_buffer_ccc = driver_main_data_buffer_address_ccc; } - if (!quiet_ccc) - { - sprintf(tempmessage_ccc, "Memory initialized\n"); - message_now_ccc(tempmessage_ccc); - } - attempt++; + memset(ccc_buffer_ccc, 0, real_buffer_size_ccc); } + if (!quiet_ccc) + { + sprintf(tempmessage_ccc, "Memory initialized\n"); + message_now_ccc(tempmessage_ccc); + } + attempt++; + } // exit (0); @@ -6063,18 +5940,6 @@ int add_to_domain_ccc(long long position, long long size) int clone_forward_ccc(void) { - if (!generic_mode_ccc && superbyte_ccc[28] != 0x4f) - { - if (sector_size_ccc != DEFAULT_SECTOR_SIZE && sector_size_ccc != ADVANCED_SECTOR_SIZE) - { - sprintf(tempmessage_ccc, "%s: %d", curlang_ccc[LANGUNSUPPORTEDSECTORSIZE], sector_size_ccc); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - sector_size_ccc = DEFAULT_SECTOR_SIZE; - return INPUT_DEVICE_ERROR_RETURN_CODE; - } - } int ret = 0; int rollover = 0; // fprintf (stdout, "currentpos= %lld currentstat=%lld\n", current_position_ccc, current_status_ccc); //debug @@ -6483,18 +6348,6 @@ int clone_forward_ccc(void) int clone_reverse_ccc(void) { - if (!generic_mode_ccc && superbyte_ccc[28] != 0x4f) - { - if (sector_size_ccc != DEFAULT_SECTOR_SIZE && sector_size_ccc != ADVANCED_SECTOR_SIZE) - { - sprintf(tempmessage_ccc, "%s: %d", curlang_ccc[LANGUNSUPPORTEDSECTORSIZE], sector_size_ccc); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - sector_size_ccc = DEFAULT_SECTOR_SIZE; - return INPUT_DEVICE_ERROR_RETURN_CODE; - } - } int ret = 0; int rollover = 0; // fprintf (stdout, "currentpos= %lld currentstat=%lld\n", current_position_ccc, current_status_ccc); //debug @@ -6893,18 +6746,6 @@ int clone_reverse_ccc(void) int driver_clone_forward_ccc(long long start, long long small_end, long long big_end) { - if (!generic_mode_ccc && superbyte_ccc[28] != 0x4f) - { - if (sector_size_ccc != DEFAULT_SECTOR_SIZE && sector_size_ccc != ADVANCED_SECTOR_SIZE) - { - sprintf(tempmessage_ccc, "%s: %d", curlang_ccc[LANGUNSUPPORTEDSECTORSIZE], sector_size_ccc); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - sector_size_ccc = DEFAULT_SECTOR_SIZE; - return INPUT_DEVICE_ERROR_RETURN_CODE; - } - } // if the destination is null then reset the log to always read from the source int no_destination = 0; if (strcmp(disk_2_ccc, "/dev/null") == 0) @@ -9102,10 +8943,6 @@ int trim_reverse_ccc(int status_type, int status_mask, int new_status_type) int analyze_drive_ccc(int sections, int extended) { - if (extended && superbyte_ccc[61] != 0x6c) - { - return 0; - } if (drive_locked_ccc) { strcpy(tempmessage_ccc, curlang_ccc[LANGDRIVELOCKED]); @@ -10762,116 +10599,17 @@ int process_chunk_ccc(int new_status_type, int retstat, int rsize, int skip_info fprintf(debug_file_ccc, "process_chunk newstatus=0x%x retstat=0x%x rsize=0x%x skipinfo=0x%x\n", new_status_type, retstat, rsize, skip_info); } - if (superbyte_ccc[22] == 0xd1) + // if it is the first sector of the read then mark it as bad and mark the rest as needed + if (ata_lba_ccc == current_position_ccc) { - // if it is the first sector of the read then mark it as bad and mark the rest as needed - if (ata_lba_ccc == current_position_ccc) - { - int ret = change_chunk_status_ccc(current_position_ccc, block_size_ccc, BAD | additional_status | get_timing_byte_ccc(), FULL_MASK); - if (ret < 0) - { - return ret; - } - ret = change_chunk_status_ccc(current_position_ccc + block_size_ccc, rsize - block_size_ccc, new_status_type | additional_status | get_timing_byte_ccc(), FULL_MASK); - if (ret < 0) - { - return ret; - } - if (driver_mode_ccc) - { - long long kposition = current_position_ccc * (sector_size_ccc / KERNEL_SECTOR_SIZE); - long long koffset = kposition - read_ctrl_data_ccc(CTRL_KSECTOR_START); - long long ksize = rsize * (sector_size_ccc / KERNEL_SECTOR_SIZE); - if (koffset >= 0 && koffset + ksize <= DRIVER_TRANSFER_BUFFER_SIZE / KERNEL_SECTOR_SIZE) - { - memset(driver_transfer_buffer_address_ccc + (koffset * KERNEL_SECTOR_SIZE), 0, ksize * KERNEL_SECTOR_SIZE); - memset(driver_error_bitmap_address_ccc + koffset, 0x80, ksize); - } - } - } - else - { - // if not the first sector of the read then do a new read up to the reported error and recheck - int rsize2 = ata_lba_ccc - current_position_ccc; - int retstat2 = read_chunk_ccc(current_position_ccc, rsize2); - if (stop_signal_ccc) - { - return STOP_SIGNAL_RETURN_CODE; - } - // if read was successful then write the chunk, otherwise mark the whole chunk - if (!retstat2 && !(ata_status_ccc & 1) && sense_key_ccc < 2 && !usb_read_residue_ccc) - { - int ret = write_chunk_ccc(current_position_ccc, rsize2); - if (ret) - { - // write error - return ret; - } - ret = change_chunk_status_ccc(current_position_ccc, rsize2, FINISHED | get_timing_byte_ccc(), FULL_MASK); - if (ret < 0) - { - // error changing chunk - return ret; - } - // mark the reported bad sector as bad - ret = change_chunk_status_ccc(current_position_ccc + rsize2, block_size_ccc, BAD | additional_status | original_timing_byte, FULL_MASK); - if (ret < 0) - { - return ret; - } - // if there is leftover then mark it as new status type - int rsize3 = rsize - rsize2 - block_size_ccc; - if (rsize3 > 0) - { - ret = change_chunk_status_ccc(current_position_ccc + rsize2 + block_size_ccc, rsize3, new_status_type | additional_status | original_timing_byte, FULL_MASK); - if (ret < 0) - { - // error changing chunk - return ret; - } - } - if (driver_mode_ccc) - { - long long kposition = (current_position_ccc + rsize2) * (sector_size_ccc / KERNEL_SECTOR_SIZE); - long long koffset = kposition - read_ctrl_data_ccc(CTRL_KSECTOR_START); - long long ksize = (rsize3 + block_size_ccc) * (sector_size_ccc / KERNEL_SECTOR_SIZE); - if (koffset >= 0 && koffset + ksize <= DRIVER_TRANSFER_BUFFER_SIZE / KERNEL_SECTOR_SIZE) - { - memset(driver_transfer_buffer_address_ccc + (koffset * KERNEL_SECTOR_SIZE), 0, ksize * KERNEL_SECTOR_SIZE); - memset(driver_error_bitmap_address_ccc + koffset, 0x80, ksize); - } - } - } - else - { - // if it failed the second read attempt then process the whole chunk as normal read error - int ret = change_chunk_status_ccc(current_position_ccc, rsize, ((rsize > block_size_ccc || (retstat && dont_mark)) ? new_status_type : BAD) | additional_status | original_timing_byte, FULL_MASK); - if (ret < 0) - { - // error changing chunk - return ret; - } - if (driver_mode_ccc) - { - long long kposition = current_position_ccc * (sector_size_ccc / KERNEL_SECTOR_SIZE); - long long koffset = kposition - read_ctrl_data_ccc(CTRL_KSECTOR_START); - long long ksize = rsize * (sector_size_ccc / KERNEL_SECTOR_SIZE); - if (koffset >= 0 && koffset + ksize <= DRIVER_TRANSFER_BUFFER_SIZE / KERNEL_SECTOR_SIZE) - { - memset(driver_transfer_buffer_address_ccc + (koffset * KERNEL_SECTOR_SIZE), 0, ksize * KERNEL_SECTOR_SIZE); - memset(driver_error_bitmap_address_ccc + koffset, 0x80, ksize); - } - } - } - } - } - else - { - // process the whole chunk as normal read error for free version - int ret = change_chunk_status_ccc(current_position_ccc, rsize, ((rsize > block_size_ccc || (retstat && dont_mark)) ? new_status_type : BAD) | additional_status | original_timing_byte, FULL_MASK); + int ret = change_chunk_status_ccc(current_position_ccc, block_size_ccc, BAD | additional_status | get_timing_byte_ccc(), FULL_MASK); + if (ret < 0) + { + return ret; + } + ret = change_chunk_status_ccc(current_position_ccc + block_size_ccc, rsize - block_size_ccc, new_status_type | additional_status | get_timing_byte_ccc(), FULL_MASK); if (ret < 0) { - // error changing chunk return ret; } if (driver_mode_ccc) @@ -10886,6 +10624,82 @@ int process_chunk_ccc(int new_status_type, int retstat, int rsize, int skip_info } } } + else + { + // if not the first sector of the read then do a new read up to the reported error and recheck + int rsize2 = ata_lba_ccc - current_position_ccc; + int retstat2 = read_chunk_ccc(current_position_ccc, rsize2); + if (stop_signal_ccc) + { + return STOP_SIGNAL_RETURN_CODE; + } + // if read was successful then write the chunk, otherwise mark the whole chunk + if (!retstat2 && !(ata_status_ccc & 1) && sense_key_ccc < 2 && !usb_read_residue_ccc) + { + int ret = write_chunk_ccc(current_position_ccc, rsize2); + if (ret) + { + // write error + return ret; + } + ret = change_chunk_status_ccc(current_position_ccc, rsize2, FINISHED | get_timing_byte_ccc(), FULL_MASK); + if (ret < 0) + { + // error changing chunk + return ret; + } + // mark the reported bad sector as bad + ret = change_chunk_status_ccc(current_position_ccc + rsize2, block_size_ccc, BAD | additional_status | original_timing_byte, FULL_MASK); + if (ret < 0) + { + return ret; + } + // if there is leftover then mark it as new status type + int rsize3 = rsize - rsize2 - block_size_ccc; + if (rsize3 > 0) + { + ret = change_chunk_status_ccc(current_position_ccc + rsize2 + block_size_ccc, rsize3, new_status_type | additional_status | original_timing_byte, FULL_MASK); + if (ret < 0) + { + // error changing chunk + return ret; + } + } + if (driver_mode_ccc) + { + long long kposition = (current_position_ccc + rsize2) * (sector_size_ccc / KERNEL_SECTOR_SIZE); + long long koffset = kposition - read_ctrl_data_ccc(CTRL_KSECTOR_START); + long long ksize = (rsize3 + block_size_ccc) * (sector_size_ccc / KERNEL_SECTOR_SIZE); + if (koffset >= 0 && koffset + ksize <= DRIVER_TRANSFER_BUFFER_SIZE / KERNEL_SECTOR_SIZE) + { + memset(driver_transfer_buffer_address_ccc + (koffset * KERNEL_SECTOR_SIZE), 0, ksize * KERNEL_SECTOR_SIZE); + memset(driver_error_bitmap_address_ccc + koffset, 0x80, ksize); + } + } + } + else + { + // if it failed the second read attempt then process the whole chunk as normal read error + int ret = change_chunk_status_ccc(current_position_ccc, rsize, ((rsize > block_size_ccc || (retstat && dont_mark)) ? new_status_type : BAD) | additional_status | original_timing_byte, FULL_MASK); + if (ret < 0) + { + // error changing chunk + return ret; + } + if (driver_mode_ccc) + { + long long kposition = current_position_ccc * (sector_size_ccc / KERNEL_SECTOR_SIZE); + long long koffset = kposition - read_ctrl_data_ccc(CTRL_KSECTOR_START); + long long ksize = rsize * (sector_size_ccc / KERNEL_SECTOR_SIZE); + if (koffset >= 0 && koffset + ksize <= DRIVER_TRANSFER_BUFFER_SIZE / KERNEL_SECTOR_SIZE) + { + memset(driver_transfer_buffer_address_ccc + (koffset * KERNEL_SECTOR_SIZE), 0, ksize * KERNEL_SECTOR_SIZE); + memset(driver_error_bitmap_address_ccc + koffset, 0x80, ksize); + } + } + } + } + return 0; } @@ -11997,23 +11811,16 @@ int process_chs_ccc(long long position) int check_buffer_limit_ccc(void) { - if (superbyte_ccc[26] == 0xfa) + int multiplier = 1; + if (driver_installed_ccc && driver_memory_mapped_ccc) { - int multiplier = 1; - if (driver_installed_ccc && driver_memory_mapped_ccc) - { - multiplier = 4; - } - // max_dma_size_ccc = (pagesize_ccc / 8) * pagesize_ccc; - max_dma_size_ccc = ((pagesize_ccc * multiplier) / 16) * pagesize_ccc; // limited to this to more match the ahci limit - if (ahci_mode_ccc) - { - max_dma_size_ccc = (((pagesize_ccc * multiplier) - 128) / 16) * pagesize_ccc; - } + multiplier = 4; } - else + // max_dma_size_ccc = (pagesize_ccc / 8) * pagesize_ccc; + max_dma_size_ccc = ((pagesize_ccc * multiplier) / 16) * pagesize_ccc; // limited to this to more match the ahci limit + if (ahci_mode_ccc) { - max_dma_size_ccc = pagesize_ccc; + max_dma_size_ccc = (((pagesize_ccc * multiplier) - 128) / 16) * pagesize_ccc; } int max_size = 0; if (direct_mode_ccc) @@ -13283,23 +13090,8 @@ int process_source_ccc(void) if (!data_read_from_log_ccc) { sector_size_ccc = bytes_per_sector_ccc; - if (superbyte_ccc[23] == 0x5b) - { - block_size_ccc = logical_sectors_per_physical; - block_offset_ccc = sector_offset; - } - } - if (!generic_mode_ccc && superbyte_ccc[28] != 0x4f) - { - if (sector_size_ccc != DEFAULT_SECTOR_SIZE && sector_size_ccc != ADVANCED_SECTOR_SIZE) - { - sprintf(tempmessage_ccc, "%s: %d", curlang_ccc[LANGUNSUPPORTEDSECTORSIZE], sector_size_ccc); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - sector_size_ccc = DEFAULT_SECTOR_SIZE; - return INPUT_DEVICE_ERROR_RETURN_CODE; - } + block_size_ccc = logical_sectors_per_physical; + block_offset_ccc = sector_offset; } // fprintf(stdout, "LBA supported= %d\n", lba_supported_ccc); //debug memcpy(&c, identify_buffer_ccc + 256, 1); // word 128 @@ -13628,24 +13420,10 @@ int process_source_ccc(void) if (!data_read_from_log_ccc) { sector_size_ccc = blocksize; - if (superbyte_ccc[23] == 0x5b) - { - block_size_ccc = logical_sectors_per_physical; - block_offset_ccc = sector_offset; - } - } - if (!generic_mode_ccc && superbyte_ccc[28] != 0x4f) - { - if (sector_size_ccc != DEFAULT_SECTOR_SIZE && sector_size_ccc != ADVANCED_SECTOR_SIZE) - { - sprintf(tempmessage_ccc, "%s: %d", curlang_ccc[LANGUNSUPPORTEDSECTORSIZE], sector_size_ccc); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - sector_size_ccc = DEFAULT_SECTOR_SIZE; - return INPUT_DEVICE_ERROR_RETURN_CODE; - } + block_size_ccc = logical_sectors_per_physical; + block_offset_ccc = sector_offset; } + if (scsi_check_read_commands_ccc()) { return INPUT_DEVICE_ERROR_RETURN_CODE; @@ -13721,24 +13499,8 @@ int process_source_ccc(void) if (!data_read_from_log_ccc) { sector_size_ccc = bytes_per_log_sec; - if (superbyte_ccc[23] == 0x5b) - { - block_size_ccc = blocksize; - block_offset_ccc = sector_offset; - } - } - if (!generic_mode_ccc && superbyte_ccc[28] != 0x4f) - { - if (sector_size_ccc != DEFAULT_SECTOR_SIZE && sector_size_ccc != ADVANCED_SECTOR_SIZE) - { - sprintf(tempmessage_ccc, "%s: %d", curlang_ccc[LANGUNSUPPORTEDSECTORSIZE], sector_size_ccc); - message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGERROR], 1); - clear_error_message_ccc(); - sector_size_ccc = DEFAULT_SECTOR_SIZE; - return INPUT_DEVICE_ERROR_RETURN_CODE; - } - sector_size_ccc = DEFAULT_SECTOR_SIZE; + block_size_ccc = blocksize; + block_offset_ccc = sector_offset; } } else @@ -14798,34 +14560,14 @@ void set_mode_direct_ccc(void) { if (!direct_mode_ccc || ahci_mode_ccc) { - if (superbyte_ccc[24] == 0xb4) + clear_mode_ccc(); + direct_mode_ccc = true; + clear_source_ccc(); + update_mode_ccc(); + // re-initialize memory after mode change + if (initialize_memory_ccc()) { - clear_mode_ccc(); - direct_mode_ccc = true; - clear_source_ccc(); - update_mode_ccc(); - // re-initialize memory after mode change - if (initialize_memory_ccc()) - { - // set_mode_auto_passthrough_ccc(); - } - } - else - { - clear_mode_ccc(); - sprintf(tempmessage_ccc, "%s", curlang_ccc[LANGDIRECTPIO]); - message_error_ccc(tempmessage_ccc); - // sprintf (tempmessage_ccc, "%s", curlang_ccc[LANGDIRECTLIMITED]); - // message_error_ccc(tempmessage_ccc); - print_gui_error_message_ccc(error_message_ccc, curlang_ccc[LANGINFO], 0); - clear_error_message_ccc(); - limit_recovery_ccc = false; - direct_mode_ccc = true; - pio_mode_ccc = true; - clear_source_ccc(); - update_mode_ccc(); - // re-initialize memory after mode change - initialize_memory_ccc(); + // set_mode_auto_passthrough_ccc(); } } } diff --git a/src/opensuperclone/opensuperclone.h b/src/opensuperclone/opensuperclone.h index 45b121b..4d9aecc 100644 --- a/src/opensuperclone/opensuperclone.h +++ b/src/opensuperclone/opensuperclone.h @@ -497,78 +497,3 @@ char start_working_directory_ccc[PATH_MAX]; char called_name_ccc[PATH_MAX]; char full_exec_path_ccc[PATH_MAX * 2]; bool found_exec_ccc = false; - -#define LICENSEHEADERSIZE 48 -unsigned char license_data_ccc[1024]; - -// unlock free pro version -unsigned char master_data_ccc[1024] = { - // 0 1 2 3 4 5 6 7 8 9 a b c d e f - 0x47, 0x83, 0xc9, 0x0d, 0xb2, 0xe6, 0xdb, 0x7f, 0x3a, 0xfd, 0x1b, 0x55, 0x26, 0x3d, 0x93, 0x2a, // 0 - 0xfb, 0x4f, 0x8f, 0x13, 0x67, 0xd5, 0x0f, 0x7b, 0x03, 0x30, 0xae, 0x23, 0xba, 0x21, 0x6e, 0x0b, // 10 - 0x20, 0x83, 0x89, 0x32, 0x71, 0xc7, 0xc9, 0x43, 0x8f, 0x57, 0x44, 0x2b, 0x07, 0x2e, 0x56, 0x14, // 20 - 0x29, 0xad, 0xf8, 0x29, 0x2a, 0x52, 0x01, 0x2d, 0x51, 0x41, 0xbc, 0x55, 0xcb, 0x45, 0x72, 0x3d, // 30 - 0x6c, 0x71, 0xf7, 0x65, 0x28, 0xa6, 0xe8, 0x7a, 0xff, 0x24, 0x19, 0x51, 0x33, 0x7d, 0x61, 0x79, // 40 - 0x78, 0x79, 0x75, 0x20, 0x93, 0xd3, 0x5b, 0x77, 0x60, 0x8e, 0x23, 0x73, 0x63, 0xb5, 0x78, 0x08, // 50 - 0x61, 0x66, 0x2c, 0x5f, 0x0b, 0xde, 0x07, 0x63, 0x52, 0x94, 0x5a, 0x38, 0xdd, 0xd9, 0x44, 0x6a, // 60 - 0x96, 0x3d, 0x0f, 0x6a, 0x1d, 0x79, 0x82, 0x46, 0xc3, 0xb4, 0xd1, 0x38, 0x1d, 0x9d, 0xe6, 0x4d, // 70 - 0xc4, 0xd1, 0x65, 0x52, 0xd9, 0xd0, 0x3a, 0x28, 0xd4, 0x3e, 0xc3, 0x5e, 0xba, 0x8b, 0x74, 0x62, // 80 - 0xa5, 0x11, 0xd8, 0x27, 0x81, 0x50, 0x1b, 0x3d, 0x3e, 0x8e, 0x0a, 0x13, 0xdd, 0x3b, 0xac, 0x56, // 90 - 0x35, 0xd6, 0x8c, 0x3e, 0x75, 0x9a, 0x58, 0x26, 0xd8, 0x36, 0x0f, 0x7d, 0x43, 0x48, 0x97, 0x53, // a0 - 0x03, 0xbb, 0xac, 0x10, 0x4d, 0x65, 0x77, 0x26, 0x0e, 0x91, 0xe1, 0x7b, 0xa4, 0xe9, 0x4e, 0x24, // b0 - 0xc6, 0x4f, 0xd4, 0x0b, 0x38, 0x20, 0x9c, 0x09, 0xa3, 0xb2, 0x3c, 0x1f, 0xc1, 0x67, 0x21, 0x07, // c0 - 0xc2, 0x6f, 0x01, 0x02, 0xe3, 0x9d, 0xe0, 0x56, 0x58, 0x20, 0xef, 0x3f, 0xe8, 0x87, 0x67, 0x67, // d0 - 0xaf, 0x09, 0xd0, 0x3c, 0xdf, 0x29, 0xa1, 0x65, 0x28, 0x62, 0x30, 0x7b, 0xb5, 0x24, 0xb3, 0x35, // e0 - 0x6c, 0xb4, 0x17, 0x4b, 0x98, 0xe7, 0x14, 0x60, 0xb7, 0x76, 0x15, 0x14, 0x3d, 0xfb, 0x10, 0x29, // f0 - // 0 1 2 3 4 5 6 7 8 9 a b c d e f - 0x21, 0xfd, 0x56, 0x11, 0x62, 0x86, 0x80, 0x67, 0x72, 0xd4, 0xfd, 0x7c, 0xb3, 0xe2, 0x10, 0x65, // 100 - 0xe9, 0x1f, 0x0a, 0x7b, 0x08, 0x31, 0x92, 0x52, 0xd8, 0xd9, 0xa8, 0x39, 0xbb, 0x50, 0x97, 0x61, // 110 - 0x0a, 0x99, 0x9f, 0x09, 0xda, 0x78, 0x16, 0x72, 0xd1, 0x64, 0xf1, 0x06, 0x20, 0x85, 0xcf, 0x5d, // 120 - 0xf2, 0x42, 0xfa, 0x72, 0xa0, 0x05, 0xd6, 0x1b, 0xa2, 0x16, 0x51, 0x03, 0x80, 0xd8, 0x90, 0x58, // 130 - 0x97, 0x7f, 0x1e, 0x01, 0x0a, 0x67, 0xa1, 0x16, 0xdf, 0xdb, 0x97, 0x2d, 0xba, 0x0d, 0x1e, 0x55, // 140 - 0xf6, 0xff, 0x03, 0x6a, 0x07, 0x5c, 0x5a, 0x53, 0xbf, 0x01, 0xc6, 0x28, 0x29, 0x50, 0x91, 0x3e, // 150 - 0x11, 0x45, 0x9c, 0x66, 0x53, 0x88, 0xb0, 0x7b, 0xba, 0x9d, 0xa6, 0x1b, 0x8e, 0x97, 0xbf, 0x71, // 160 - 0xdd, 0x5a, 0x43, 0x2c, 0x4e, 0x1c, 0xf4, 0x40, 0x84, 0xec, 0x7f, 0x16, 0x18, 0xf9, 0xea, 0x7f, // 170 - 0xb8, 0xd4, 0x02, 0x27, 0xce, 0xaa, 0x7b, 0x7c, 0x8a, 0x72, 0x99, 0x25, 0xcf, 0xba, 0x72, 0x3a, // 180 - 0x2b, 0x64, 0x33, 0x63, 0xc1, 0x27, 0xc2, 0x38, 0x2f, 0x53, 0xe8, 0x0d, 0xfc, 0x8c, 0x8d, 0x36, // 190 - 0x36, 0x5a, 0x10, 0x4c, 0x2c, 0xfa, 0xf4, 0x34, 0x8a, 0x45, 0x7b, 0x0a, 0xd7, 0x03, 0xbc, 0x5f, // 1a0 - 0xcb, 0x58, 0x5a, 0x76, 0x5f, 0x38, 0xe4, 0x26, 0xa7, 0xba, 0x42, 0x77, 0xf3, 0x83, 0x15, 0x68, // 1b0 - 0xe0, 0xd4, 0x4c, 0x1a, 0xdb, 0x47, 0x6b, 0x0f, 0x80, 0xa5, 0x88, 0x5c, 0x7e, 0xee, 0x09, 0x74, // 1c0 - 0xe9, 0xe7, 0x20, 0x54, 0xc3, 0x52, 0xbd, 0x6a, 0xcf, 0x97, 0xe5, 0x3f, 0x02, 0xde, 0x8e, 0x49, // 1d0 - 0xc9, 0xed, 0xe3, 0x62, 0x6f, 0x5b, 0xa0, 0x03, 0xbc, 0xb2, 0x46, 0x16, 0x3f, 0x46, 0x3b, 0x55, // 1e0 - 0x98, 0x5e, 0xcd, 0x3a, 0x3f, 0x1e, 0xf0, 0x39, 0x61, 0x50, 0xf9, 0x56, 0x88, 0xb8, 0x2f, 0x31, // 1f0 - // 0 1 2 3 4 5 6 7 8 9 a b c d e f - 0xdf, 0xe5, 0xca, 0x0f, 0x58, 0xc2, 0xef, 0x32, 0x0a, 0x0d, 0xe9, 0x45, 0xef, 0xfc, 0x74, 0x5f, // 200 - 0x2c, 0x53, 0x5b, 0x74, 0xd2, 0xff, 0xe9, 0x14, 0x56, 0x60, 0xcd, 0x7c, 0xc8, 0xef, 0xcc, 0x41, // 210 - 0xbe, 0x97, 0x2f, 0x57, 0xd7, 0x92, 0x80, 0x2d, 0x5f, 0xb3, 0x72, 0x43, 0xad, 0x21, 0x74, 0x58, // 220 - 0x05, 0x62, 0x47, 0x01, 0x4b, 0xe6, 0x45, 0x57, 0x38, 0x41, 0x7d, 0x6c, 0x66, 0xc0, 0x90, 0x70, // 230 - 0x8b, 0xa3, 0x69, 0x06, 0x4c, 0xb9, 0x2c, 0x5c, 0xe4, 0xcb, 0x7c, 0x71, 0x87, 0xe1, 0xe9, 0x46, // 240 - 0x3a, 0x8a, 0x1a, 0x31, 0xfa, 0x4b, 0x45, 0x50, 0x42, 0x74, 0x48, 0x03, 0xe9, 0x2e, 0x92, 0x06, // 250 - 0xdc, 0x8c, 0x35, 0x5c, 0x30, 0x51, 0x88, 0x3c, 0xac, 0x51, 0x40, 0x51, 0x67, 0x42, 0x16, 0x16, // 260 - 0x14, 0x9f, 0x27, 0x6b, 0x6e, 0xa1, 0xf3, 0x46, 0x5a, 0xd2, 0x51, 0x45, 0x97, 0x9e, 0xde, 0x48, // 270 - 0xd9, 0x42, 0xa5, 0x16, 0xa8, 0x69, 0xe2, 0x7d, 0xf2, 0xeb, 0xdb, 0x25, 0xb9, 0xb3, 0x2b, 0x3c, // 280 - 0xc2, 0xa4, 0x7a, 0x7f, 0x63, 0x2b, 0x7b, 0x54, 0xf3, 0x1b, 0xc8, 0x3d, 0x0a, 0xb3, 0x52, 0x13, // 290 - 0x09, 0xeb, 0xc8, 0x05, 0x6c, 0x59, 0x9f, 0x5b, 0x18, 0x3b, 0x35, 0x31, 0x60, 0xf7, 0x1c, 0x48, // 2a0 - 0xc9, 0xef, 0xf5, 0x5c, 0xb8, 0x73, 0xd9, 0x45, 0x4f, 0x27, 0x17, 0x6d, 0xee, 0xe7, 0xe8, 0x54, // 2b0 - 0xec, 0x0a, 0xf3, 0x7c, 0x6a, 0x74, 0x74, 0x13, 0x9f, 0xa7, 0x37, 0x29, 0xfe, 0xad, 0x0e, 0x3f, // 2c0 - 0x39, 0xbf, 0x32, 0x14, 0x16, 0x67, 0xaf, 0x7c, 0x2f, 0x05, 0xdf, 0x52, 0xbf, 0x54, 0xf6, 0x7a, // 2d0 - 0x07, 0x06, 0x0d, 0x50, 0x5c, 0x1d, 0x17, 0x66, 0xaf, 0xc5, 0x1e, 0x7c, 0xe3, 0x76, 0x0a, 0x52, // 2e0 - 0xbd, 0xb4, 0x32, 0x27, 0x5c, 0x6d, 0x3a, 0x13, 0x85, 0x58, 0x75, 0x28, 0x70, 0xd1, 0xe2, 0x6c, // 2f0 - // 0 1 2 3 4 5 6 7 8 9 a b c d e f - 0x7e, 0x9b, 0x14, 0x55, 0xff, 0x02, 0x09, 0x6a, 0x3b, 0xc1, 0x88, 0x40, 0xaf, 0x09, 0x90, 0x55, // 300 - 0xc4, 0x95, 0x24, 0x5a, 0xf3, 0xa7, 0x5b, 0x30, 0x53, 0xaf, 0x52, 0x58, 0xc0, 0xb1, 0x50, 0x6f, // 310 - 0x47, 0x22, 0x83, 0x32, 0x4a, 0x59, 0x3c, 0x08, 0x12, 0xbb, 0xbd, 0x6f, 0x3d, 0xf6, 0x36, 0x17, // 320 - 0xea, 0x3c, 0x75, 0x40, 0xaf, 0xac, 0x33, 0x71, 0x9a, 0x96, 0x0f, 0x77, 0xe7, 0x1e, 0x18, 0x68, // 330 - 0x85, 0x3d, 0xa1, 0x34, 0xe3, 0x7a, 0x14, 0x48, 0x41, 0x24, 0xa2, 0x5c, 0x44, 0xf6, 0x72, 0x63, // 340 - 0xcc, 0xe8, 0xf9, 0x13, 0x9f, 0x3a, 0x4f, 0x46, 0xb3, 0x0d, 0x09, 0x67, 0xfc, 0xbe, 0xf8, 0x4f, // 350 - 0x92, 0x60, 0x3c, 0x62, 0x1c, 0xb8, 0x27, 0x13, 0xb7, 0x91, 0x3b, 0x76, 0x5c, 0x20, 0x83, 0x03, // 360 - 0x66, 0xd5, 0xbe, 0x36, 0x6b, 0xdf, 0x57, 0x0e, 0xf2, 0x6b, 0x3b, 0x35, 0xde, 0x30, 0x7f, 0x1d, // 370 - 0x9a, 0xc3, 0x2a, 0x05, 0x32, 0xe1, 0x87, 0x6c, 0x1b, 0x0f, 0xe9, 0x67, 0x0e, 0xba, 0x92, 0x4f, // 380 - 0xee, 0x9a, 0xc8, 0x27, 0xea, 0x2c, 0xa2, 0x7d, 0x31, 0xd7, 0x45, 0x12, 0x3d, 0x9d, 0xdf, 0x28, // 390 - 0xe0, 0x71, 0xeb, 0x7e, 0x48, 0x23, 0xd9, 0x15, 0x53, 0xcb, 0x4f, 0x7c, 0x1b, 0x6c, 0x90, 0x23, // 3a0 - 0x14, 0xa5, 0x3e, 0x5f, 0x70, 0xac, 0x33, 0x34, 0xde, 0x1f, 0x4d, 0x09, 0x19, 0x59, 0x7e, 0x72, // 3b0 - 0x46, 0x58, 0x55, 0x1a, 0xbb, 0x7b, 0x49, 0x70, 0xaf, 0x5c, 0x6b, 0x61, 0xd7, 0x12, 0x32, 0x77, // 3c0 - 0x4b, 0x41, 0x92, 0x3b, 0x8d, 0xf2, 0x10, 0x63, 0x6d, 0x9d, 0x83, 0x0b, 0x30, 0x01, 0x41, 0x20, // 3d0 - 0xf4, 0xf7, 0xa1, 0x36, 0x86, 0x6f, 0x08, 0x60, 0x08, 0x61, 0x60, 0x07, 0xd4, 0x4b, 0xac, 0x42, // 3e0 - 0xb5, 0xa5, 0x83, 0x57, 0x2f, 0x42, 0x78, 0x2d, 0x4b, 0x32, 0x5b, 0x56, 0x78, 0x84, 0x37, 0x7d, // 3f0 -}; diff --git a/src/opensuperclone/tool.c b/src/opensuperclone/tool.c index 19ba29d..67104b9 100644 --- a/src/opensuperclone/tool.c +++ b/src/opensuperclone/tool.c @@ -252,22 +252,22 @@ void supertool_cleanup_ccc(void) if (ahci_address_changed_ccc) { // restore addresses - memcpy(port_virt_addr_ccc + superbyte_ccc[11], &command_list_address_backup_ccc, 8); - memcpy(port_virt_addr_ccc + superbyte_ccc[12], &fis_address_backup_ccc, 8); + memcpy(port_virt_addr_ccc + 0x00, &command_list_address_backup_ccc, 8); + memcpy(port_virt_addr_ccc + 0x08, &fis_address_backup_ccc, 8); } if (ahci_interrupt_changed_ccc) { // restore the interrupt settings - memcpy(port_virt_addr_ccc + superbyte_ccc[13], &interrupt_backup_ccc, 4); + memcpy(port_virt_addr_ccc + 0x14, &interrupt_backup_ccc, 4); } if (table_address_changed_ccc) { - outb(table_address_backup_ccc[0], bus_base_address_ccc + 0 + superbyte_ccc[10]); - outb(table_address_backup_ccc[1], bus_base_address_ccc + 1 + superbyte_ccc[10]); - outb(table_address_backup_ccc[2], bus_base_address_ccc + 2 + superbyte_ccc[10]); - outb(table_address_backup_ccc[3], bus_base_address_ccc + 3 + superbyte_ccc[10]); + outb(table_address_backup_ccc[0], bus_base_address_ccc + 0 + 0x18); + outb(table_address_backup_ccc[1], bus_base_address_ccc + 1 + 0x18); + outb(table_address_backup_ccc[2], bus_base_address_ccc + 2 + 0x18); + outb(table_address_backup_ccc[3], bus_base_address_ccc + 3 + 0x18); } if (memory_mapped_ccc)