From bfc703a5568498102f163466271321c5a5068b8c Mon Sep 17 00:00:00 2001 From: joevt Date: Sat, 9 Mar 2024 23:49:34 -0800 Subject: [PATCH] scsihd: Add sector_size. Replace HDD_SECTOR_SIZE with class field sector_size. --- devices/common/scsi/scsihd.cpp | 24 ++++++++---------------- devices/common/scsi/scsihd.h | 1 + 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/devices/common/scsi/scsihd.cpp b/devices/common/scsi/scsihd.cpp index 773c9fc..72c2429 100644 --- a/devices/common/scsi/scsihd.cpp +++ b/devices/common/scsi/scsihd.cpp @@ -29,11 +29,6 @@ along with this program. If not, see . #include #include -#include -#include - -#define HDD_SECTOR_SIZE 512 - using namespace std; ScsiHardDisk::ScsiHardDisk(std::string name, int my_id) : ScsiDevice(name, my_id) { @@ -46,7 +41,7 @@ void ScsiHardDisk::insert_image(std::string filename) { ABORT_F("%s: could not open image file %s", this->name.c_str(), filename.c_str()); this->img_size = this->disk_img.size(); - uint64_t tb = (this->img_size + HDD_SECTOR_SIZE - 1) / HDD_SECTOR_SIZE; + uint64_t tb = (this->img_size + this->sector_size - 1) / this->sector_size; this->total_blocks = static_cast(tb); if (this->total_blocks < 0 || tb != this->total_blocks) { ABORT_F("ScsiHardDisk: file size is too large"); @@ -255,7 +250,7 @@ void ScsiHardDisk::mode_select_6(uint8_t param_len) { this->incoming_size = param_len; - std::memset(&this->data_buf[0], 0xDD, HDD_SECTOR_SIZE); + std::memset(&this->data_buf[0], 0xDD, this->sector_size); this->post_xfer_action = [this]() { // TODO: parse the received mode parameter list here @@ -280,10 +275,7 @@ void ScsiHardDisk::mode_sense_6() { this->data_buf[ 5] = (this->total_blocks >> 16) & 0xFFU; this->data_buf[ 6] = (this->total_blocks >> 8) & 0xFFU; this->data_buf[ 7] = (this->total_blocks ) & 0xFFU; - this->data_buf[ 8] = 0; - this->data_buf[ 9] = 0; // sector size MSB - this->data_buf[10] = 2; // sector size - this->data_buf[11] = 0; // sector size LSB + WRITE_DWORD_BE_A(&this->data_buf[8], this->sector_size); this->data_buf[12] = page_code; @@ -337,7 +329,7 @@ void ScsiHardDisk::read_capacity_10() { } uint32_t last_lba = this->total_blocks - 1; - uint32_t blk_len = HDD_SECTOR_SIZE; + uint32_t blk_len = this->sector_size; WRITE_DWORD_BE_A(&data_buf[0], last_lba); WRITE_DWORD_BE_A(&data_buf[4], blk_len); @@ -368,8 +360,8 @@ void ScsiHardDisk::read(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) { transfer_size = 256; } - transfer_size *= HDD_SECTOR_SIZE; - uint64_t device_offset = lba * HDD_SECTOR_SIZE; + transfer_size *= this->sector_size; + uint64_t device_offset = lba * this->sector_size; this->disk_img.read(data_buf, device_offset, transfer_size); @@ -385,8 +377,8 @@ void ScsiHardDisk::write(uint32_t lba, uint16_t transfer_len, uint8_t cmd_len) { transfer_size = 256; } - transfer_size *= HDD_SECTOR_SIZE; - uint64_t device_offset = lba * HDD_SECTOR_SIZE; + transfer_size *= this->sector_size; + uint64_t device_offset = lba * this->sector_size; this->incoming_size = transfer_size; diff --git a/devices/common/scsi/scsihd.h b/devices/common/scsi/scsihd.h index 59eb980..c996d61 100644 --- a/devices/common/scsi/scsihd.h +++ b/devices/common/scsi/scsihd.h @@ -66,6 +66,7 @@ private: uint64_t img_size; int total_blocks; uint64_t file_offset = 0; + static const int sector_size = 512; int bytes_out = 0; uint8_t data_buf[1 << 21]; // TODO: add proper buffer management!