-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove interface header files, split executor
- Loading branch information
Showing
6 changed files
with
119 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//--------------------------------------------------------------------------- | ||
// | ||
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi | ||
// | ||
// Copyright (C) 2024 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
#include "disk_executor.h" | ||
#include <spdlog/spdlog.h> | ||
#include "shared/memory_util.h" | ||
|
||
using namespace spdlog; | ||
using namespace memory_util; | ||
|
||
pair<uint64_t, uint32_t> DiskExecutor::ReadCapacity() | ||
{ | ||
vector<uint8_t> buffer(14); | ||
vector<uint8_t> cdb(10); | ||
|
||
if (initiator_executor->Execute(scsi_command::read_capacity_10, cdb, buffer, 8)) { | ||
return {0, 0}; | ||
} | ||
|
||
uint64_t capacity = GetInt32(buffer, 0); | ||
|
||
int sector_size_offset = 4; | ||
|
||
if (static_cast<int32_t>(capacity) == -1) { | ||
cdb.resize(16); | ||
// READ CAPACITY(16), not READ LONG(16) | ||
cdb[1] = 0x10; | ||
|
||
if (initiator_executor->Execute(scsi_command::read_capacity_16_read_long_16, cdb, buffer, | ||
static_cast<int>(buffer.size()))) { | ||
return {0, 0}; | ||
} | ||
|
||
capacity = GetInt64(buffer, 0); | ||
|
||
sector_size_offset = 8; | ||
} | ||
|
||
const uint32_t sector_size = GetInt32(buffer, sector_size_offset); | ||
|
||
return {capacity + 1, sector_size}; | ||
} | ||
|
||
bool DiskExecutor::ReadWriteDisk(span<uint8_t> buffer, uint32_t bstart, uint32_t blength, int length, bool is_write) | ||
{ | ||
if (bstart < 16777216 && blength <= 256) { | ||
vector<uint8_t> cdb(6); | ||
cdb[1] = static_cast<uint8_t>(bstart >> 16); | ||
cdb[2] = static_cast<uint8_t>(bstart >> 8); | ||
cdb[3] = static_cast<uint8_t>(bstart); | ||
cdb[4] = static_cast<uint8_t>(blength); | ||
|
||
return !initiator_executor->Execute(is_write ? scsi_command::write_6 : scsi_command::read_6, cdb, buffer, | ||
length); | ||
} | ||
else { | ||
vector<uint8_t> cdb(10); | ||
cdb[2] = static_cast<uint8_t>(bstart >> 24); | ||
cdb[3] = static_cast<uint8_t>(bstart >> 16); | ||
cdb[4] = static_cast<uint8_t>(bstart >> 8); | ||
cdb[5] = static_cast<uint8_t>(bstart); | ||
cdb[7] = static_cast<uint8_t>(blength >> 8); | ||
cdb[8] = static_cast<uint8_t>(blength); | ||
|
||
return !initiator_executor->Execute(is_write ? scsi_command::write_10 : scsi_command::read_10, cdb, buffer, | ||
length); | ||
} | ||
} | ||
|
||
void DiskExecutor::SynchronizeCache() | ||
{ | ||
vector<uint8_t> cdb(10); | ||
|
||
initiator_executor->Execute(scsi_command::synchronize_cache_10, cdb, { }, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//--------------------------------------------------------------------------- | ||
// | ||
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi | ||
// | ||
// Copyright (C) 2024 Uwe Seimet | ||
// | ||
//--------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include "s2pdump_executor.h" | ||
|
||
using namespace std; | ||
|
||
class DiskExecutor : public S2pDumpExecutor | ||
{ | ||
|
||
public: | ||
|
||
DiskExecutor(Bus &b, int i, logger &l) : S2pDumpExecutor(b, i, l) | ||
{ | ||
} | ||
|
||
pair<uint64_t, uint32_t> ReadCapacity(); | ||
bool ReadWriteDisk(span<uint8_t>, uint32_t, uint32_t, int, bool); | ||
void SynchronizeCache(); | ||
|
||
private: | ||
|
||
unique_ptr<S2pDumpExecutor> s2pdump_executor; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters