mirror of
https://github.com/thewesker/RASCSI.git
synced 2025-12-21 04:41:12 -05:00
Additional updates
This commit is contained in:
@@ -285,8 +285,10 @@ void *Command_Thread::MonThread(void *param)
|
||||
|
||||
// Scheduler Settings
|
||||
schedparam.sched_priority = 0;
|
||||
#if defined(__linux__)
|
||||
// sched_setscheduler is only available on Linux
|
||||
sched_setscheduler(0, SCHED_IDLE, &schedparam);
|
||||
|
||||
#endif
|
||||
// Set the affinity to a specific processor core
|
||||
FixCpu(2);
|
||||
|
||||
@@ -311,31 +313,27 @@ void *Command_Thread::MonThread(void *param)
|
||||
fp = fdopen(fd, "r+");
|
||||
p = fgets(buf, BUFSIZ, fp);
|
||||
|
||||
// Failed to get the command
|
||||
if (!p) {
|
||||
goto next;
|
||||
}
|
||||
// If we received a command....
|
||||
if (p) {
|
||||
|
||||
// Remove the newline character
|
||||
p[strlen(p) - 1] = 0;
|
||||
// // Remove the newline character
|
||||
// p[strlen(p) - 1] = 0;
|
||||
|
||||
// List all of the devices
|
||||
if (xstrncasecmp(p, "list", 4) == 0) {
|
||||
Rascsi_Manager::GetInstance()->ListDevice(fp);
|
||||
goto next;
|
||||
}
|
||||
// // List all of the devices
|
||||
// if (xstrncasecmp(p, "list", 4) == 0) {
|
||||
// Rascsi_Manager::GetInstance()->ListDevice(fp);
|
||||
// goto next;
|
||||
// }
|
||||
|
||||
new_command = Rasctl_Command::DeSerialize((BYTE*)p,BUFSIZ);
|
||||
new_command = Rasctl_Command::DeSerialize((BYTE*)p,BUFSIZ);
|
||||
|
||||
// // Wait until we becom idle
|
||||
// while (m_running) {
|
||||
// usleep(500 * 1000);
|
||||
// }
|
||||
if(new_command != nullptr){
|
||||
// Execute the command
|
||||
ExecuteCommand(fp, new_command);
|
||||
}
|
||||
|
||||
// Execute the command
|
||||
ExecuteCommand(fp, new_command);
|
||||
}
|
||||
|
||||
next:
|
||||
// Release the connection
|
||||
fclose(fp);
|
||||
close(fd);
|
||||
@@ -539,17 +537,16 @@ BOOL Command_Thread::ExecuteCommand(FILE *fp, Rasctl_Command *incoming_command)
|
||||
|
||||
|
||||
BOOL Command_Thread::DoShutdown(FILE *fp, Rasctl_Command *incoming_command){return FALSE;}
|
||||
BOOL Command_Thread::DoList(FILE *fp, Rasctl_Command *incoming_command){return FALSE;}
|
||||
BOOL Command_Thread::DoAttach(FILE *fp, Rasctl_Command *incoming_command){return FALSE;}
|
||||
BOOL Command_Thread::DoDetach(FILE *fp, Rasctl_Command *incoming_command){return FALSE;}
|
||||
BOOL Command_Thread::DoInsert(FILE *fp, Rasctl_Command *incoming_command){return FALSE;}
|
||||
BOOL Command_Thread::DoEject(FILE *fp, Rasctl_Command *incoming_command){return FALSE;}
|
||||
BOOL Command_Thread::DoProtect(FILE *fp, Rasctl_Command *incoming_command){return FALSE;}
|
||||
|
||||
BOOL Command_Thread::DoList(FILE *fp, Rasctl_Command *incoming_command){
|
||||
Rascsi_Manager::GetInstance()->ListDevice(fp);
|
||||
return TRUE;
|
||||
}
|
||||
BOOL Command_Thread::DoAttach(FILE *fp, Rasctl_Command *incoming_command){
|
||||
Filepath filepath;
|
||||
Disk *pUnit = nullptr;
|
||||
|
||||
// BOOL Command_Thread::DoAttach(File *fp, Rasctl_Command *incoming_command){
|
||||
|
||||
// // Connect Command
|
||||
// Connect Command
|
||||
// if (cmd == rasctl_cmd_attach) { // ATTACH
|
||||
// // Distinguish between SASI and SCSI
|
||||
// ext = NULL;
|
||||
@@ -557,67 +554,72 @@ BOOL Command_Thread::DoProtect(FILE *fp, Rasctl_Command *incoming_command){retur
|
||||
|
||||
// }
|
||||
|
||||
// // Create a new drive, based upon type
|
||||
// switch (type) {
|
||||
// case 0: // HDF
|
||||
// pUnit = new SASIHD();
|
||||
// break;
|
||||
// case 1: // HDS/HDN/HDI/NHD/HDA
|
||||
// if (ext == NULL) {
|
||||
// break;
|
||||
// }
|
||||
// if (xstrcasecmp(ext, "hdn") == 0 ||
|
||||
// xstrcasecmp(ext, "hdi") == 0 || xstrcasecmp(ext, "nhd") == 0) {
|
||||
// pUnit = new SCSIHD_NEC();
|
||||
// } else if (xstrcasecmp(ext, "hda") == 0) {
|
||||
// pUnit = new SCSIHD_APPLE();
|
||||
// } else {
|
||||
// pUnit = new SCSIHD();
|
||||
// }
|
||||
// break;
|
||||
// case 2: // MO
|
||||
// pUnit = new SCSIMO();
|
||||
// break;
|
||||
// case 3: // CD
|
||||
// pUnit = new SCSICD();
|
||||
// break;
|
||||
// case 4: // BRIDGE
|
||||
// pUnit = new SCSIBR();
|
||||
// break;
|
||||
// default:
|
||||
// FPRT(fp, "Error : Invalid device type\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
// Create a new drive, based upon type
|
||||
switch (incoming_command->type) {
|
||||
case rasctl_dev_sasi_hd: // HDF
|
||||
pUnit = new SASIHD();
|
||||
break;
|
||||
case rasctl_dev_scsi_hd: // HDS/HDN/HDI/NHD/HDA
|
||||
pUnit = new SCSIHD();
|
||||
break;
|
||||
case rasctl_dev_scsi_hd_appl:
|
||||
pUnit = new SCSIHD_APPLE();
|
||||
break;
|
||||
case rasctl_dev_scsi_hd_nec:
|
||||
pUnit = new SCSIHD_NEC();
|
||||
break;
|
||||
case rasctl_dev_mo:
|
||||
pUnit = new SCSIMO();
|
||||
break;
|
||||
case rasctl_dev_cd:
|
||||
pUnit = new SCSICD();
|
||||
break;
|
||||
case rasctl_dev_br:
|
||||
pUnit = new SCSIBR();
|
||||
break;
|
||||
default:
|
||||
FPRT(fp, "Error : Invalid device type\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// // drive checks files
|
||||
// if (type <= 1 || (type <= 3 && xstrcasecmp(file, "-") != 0)) {
|
||||
// // Set the Path
|
||||
// filepath.SetPath(file);
|
||||
// drive checks files
|
||||
switch(incoming_command->type){
|
||||
case rasctl_dev_mo:
|
||||
case rasctl_dev_scsi_hd_nec:
|
||||
case rasctl_dev_sasi_hd:
|
||||
case rasctl_dev_scsi_hd:
|
||||
case rasctl_dev_cd:
|
||||
case rasctl_dev_scsi_hd_appl:
|
||||
// Set the Path
|
||||
filepath.SetPath(incoming_command->file);
|
||||
|
||||
// // Open the file path
|
||||
// if (!pUnit->Open(filepath)) {
|
||||
// FPRT(fp, "Error : File open error [%s]\n", file);
|
||||
// delete pUnit;
|
||||
// return FALSE;
|
||||
// }
|
||||
// }
|
||||
// Open the file path
|
||||
if (!pUnit->Open(filepath)) {
|
||||
FPRT(fp, "Error : File open error [%s]\n", incoming_command->file);
|
||||
delete pUnit;
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
case rasctl_dev_br:
|
||||
case rasctl_dev_invalid:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
// // Set the cache to write-through
|
||||
// pUnit->SetCacheWB(FALSE);
|
||||
|
||||
// Set the cache to write-through
|
||||
pUnit->SetCacheWB(FALSE);
|
||||
|
||||
// // Replace with the newly created unit
|
||||
// map[id * Rascsi_Manager::GetInstance()->UnitNum + un] = pUnit;
|
||||
|
||||
// // Re-map the controller
|
||||
// Rascsi_Manager::GetInstance()->MapControler(fp, map);
|
||||
// return TRUE;
|
||||
// }
|
||||
|
||||
// // Is this a valid command?
|
||||
// if (cmd > 4) {
|
||||
// FPRT(fp, "Error : Invalid command\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
// Map the controller
|
||||
Rascsi_Manager::GetInstance()->MapControler(fp, map);
|
||||
return TRUE;
|
||||
|
||||
|
||||
return FALSE;}
|
||||
BOOL Command_Thread::DoDetach(FILE *fp, Rasctl_Command *incoming_command){
|
||||
|
||||
// // Does the controller exist?
|
||||
// if (Rascsi_Manager::GetInstance()->m_ctrl[id] == NULL) {
|
||||
@@ -632,7 +634,7 @@ BOOL Command_Thread::DoProtect(FILE *fp, Rasctl_Command *incoming_command){retur
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
// // Disconnect Command
|
||||
// // Disconnect Command
|
||||
// if (cmd == 1) { // DETACH
|
||||
// // Free the existing unit
|
||||
// map[id * Rascsi_Manager::GetInstance()->UnitNum + un] = NULL;
|
||||
@@ -641,44 +643,92 @@ BOOL Command_Thread::DoProtect(FILE *fp, Rasctl_Command *incoming_command){retur
|
||||
// Rascsi_Manager::GetInstance()->MapControler(fp, map);
|
||||
// return TRUE;
|
||||
// }
|
||||
|
||||
return FALSE;}
|
||||
BOOL Command_Thread::DoInsert(FILE *fp, Rasctl_Command *incoming_command){
|
||||
|
||||
// // Valid only for MO or CD
|
||||
|
||||
// // Does the controller exist?
|
||||
// if (Rascsi_Manager::GetInstance()->m_ctrl[id] == NULL) {
|
||||
// FPRT(fp, "Error : No such device\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
// // Does the unit exist?
|
||||
// pUnit = Rascsi_Manager::GetInstance()->m_disk[id * Rascsi_Manager::GetInstance()->UnitNum + un];
|
||||
// if (pUnit == NULL) {
|
||||
// FPRT(fp, "Error : No such device\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
// // Valid only for MO or CD
|
||||
// if (pUnit->GetID() != MAKEID('S', 'C', 'M', 'O') &&
|
||||
// pUnit->GetID() != MAKEID('S', 'C', 'C', 'D')) {
|
||||
// FPRT(fp, "Error : Operation denied(Deveice isn't removable)\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
// case 2: // INSERT
|
||||
// // Set the file path
|
||||
// filepath.SetPath(file);
|
||||
|
||||
// // Open the file
|
||||
// if (!pUnit->Open(filepath)) {
|
||||
// FPRT(fp, "Error : File open error [%s]\n", file);
|
||||
// return FALSE;
|
||||
// }
|
||||
// break;
|
||||
|
||||
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
BOOL Command_Thread::DoEject(FILE *fp, Rasctl_Command *incoming_command){
|
||||
|
||||
// // Does the controller exist?
|
||||
// if (Rascsi_Manager::GetInstance()->m_ctrl[id] == NULL) {
|
||||
// FPRT(fp, "Error : No such device\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
// // Does the unit exist?
|
||||
// pUnit = Rascsi_Manager::GetInstance()->m_disk[id * Rascsi_Manager::GetInstance()->UnitNum + un];
|
||||
// if (pUnit == NULL) {
|
||||
// FPRT(fp, "Error : No such device\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
// // Valid only for MO or CD
|
||||
// if (pUnit->GetID() != MAKEID('S', 'C', 'M', 'O') &&
|
||||
// pUnit->GetID() != MAKEID('S', 'C', 'C', 'D')) {
|
||||
// FPRT(fp, "Error : Operation denied(Deveice isn't removable)\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
// switch (cmd) {
|
||||
// case 2: // INSERT
|
||||
// // Set the file path
|
||||
// filepath.SetPath(file);
|
||||
|
||||
// // Open the file
|
||||
// if (!pUnit->Open(filepath)) {
|
||||
// FPRT(fp, "Error : File open error [%s]\n", file);
|
||||
// return FALSE;
|
||||
// }
|
||||
// break;
|
||||
|
||||
// case 3: // EJECT
|
||||
// pUnit->Eject(TRUE);
|
||||
// break;
|
||||
|
||||
// case 4: // PROTECT
|
||||
return FALSE;}
|
||||
BOOL Command_Thread::DoProtect(FILE *fp, Rasctl_Command *incoming_command){
|
||||
|
||||
// case 4: // PROTECT
|
||||
// if (pUnit->GetID() != MAKEID('S', 'C', 'M', 'O')) {
|
||||
// FPRT(fp, "Error : Operation denied(Deveice isn't MO)\n");
|
||||
// return FALSE;
|
||||
// }
|
||||
// pUnit->WriteP(!pUnit->IsWriteP());
|
||||
// break;
|
||||
// default:
|
||||
// ASSERT(FALSE);
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
return FALSE;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// return TRUE;
|
||||
// }
|
||||
|
||||
BOOL Command_Thread::HasSuffix(const char* string, const char* suffix) {
|
||||
int string_len = strlen(string);
|
||||
|
||||
@@ -121,8 +121,10 @@ BOOL FASTCALL Fileio::Open(LPCTSTR fname, OpenMode mode, BOOL directIO)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
// デフォルトモード
|
||||
omode = directIO ? O_DIRECT : 0;
|
||||
#endif // ifndef __APPLE__
|
||||
|
||||
// モード別
|
||||
switch (mode) {
|
||||
|
||||
@@ -1215,7 +1215,7 @@ int FASTCALL GPIOBUS::PollSelectEvent()
|
||||
{
|
||||
// clear errno
|
||||
errno = 0;
|
||||
|
||||
#if !defined(__x86_64__) && !defined(__X86__)
|
||||
#ifdef BAREMETAL
|
||||
// Enable interrupts
|
||||
EnableInterrupts();
|
||||
@@ -1235,6 +1235,7 @@ int FASTCALL GPIOBUS::PollSelectEvent()
|
||||
|
||||
read(selevreq.fd, &gpev, sizeof(gpev));
|
||||
#endif // BAREMETAL
|
||||
#endif // !__x86_64
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1506,6 +1507,9 @@ BOOL FASTCALL GPIOBUS::WaitSignal(int pin, BOOL ast)
|
||||
//---------------------------------------------------------------------------
|
||||
void FASTCALL GPIOBUS::DisableIRQ()
|
||||
{
|
||||
#if defined(__x86_64__) || defined(__X86__)
|
||||
return;
|
||||
#else
|
||||
#ifndef BAREMETAL
|
||||
if (rpitype == 4) {
|
||||
// RPI4 is disabled by GICC
|
||||
@@ -1522,6 +1526,7 @@ void FASTCALL GPIOBUS::DisableIRQ()
|
||||
irpctl[IRPT_DIS_IRQ_1] = irptenb & 0xf;
|
||||
}
|
||||
#endif // BAREMETAL
|
||||
#endif // ifdef __x86_64__ || __X86__
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//---------------------------------------------------------------------------
|
||||
void FixCpu(int cpu)
|
||||
{
|
||||
#ifndef BAREMETAL
|
||||
#if !defined BAREMETAL && defined(__linux__)
|
||||
cpu_set_t cpuset;
|
||||
int cpus;
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ int main(int argc, char* argv[])
|
||||
// Set the affinity to a specific processor core
|
||||
FixCpu(3);
|
||||
|
||||
#ifdef USE_SEL_EVENT_ENABLE
|
||||
#if defined(USE_SEL_EVENT_ENABLE) && defined(__linux__)
|
||||
// Scheduling policy setting (highest priority)
|
||||
schparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
|
||||
sched_setscheduler(0, SCHED_FIFO, &schparam);
|
||||
|
||||
@@ -25,6 +25,123 @@ Rascsi_Manager* Rascsi_Manager::GetInstance(){
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
|
||||
void Rascsi_Manager::AttachDevice(FILE *fp, Disk *disk, int id, int unit_num){
|
||||
int unitno = (id * UnitNum) + unit_num;
|
||||
|
||||
// Get the lock
|
||||
m_locked.lock();
|
||||
|
||||
// Check if something already exists at that SCSI ID / Unit Number
|
||||
if (m_disk[unitno]) {
|
||||
// Disconnect it from the controller
|
||||
if (m_ctrl[i]) {
|
||||
m_ctrl[i]->SetUnit(j, NULL);
|
||||
}else{
|
||||
printf("Warning: A controller was not connected to the drive at id %d un %d\n",id, unit_num);
|
||||
}
|
||||
|
||||
// Free the Unit
|
||||
delete m_disk[unitno];
|
||||
}
|
||||
|
||||
// Add the new unit
|
||||
m_disk[unitno] = disk;
|
||||
|
||||
// Reconfigure all of the controllers
|
||||
for (i = 0; i < CtrlMax; i++) {
|
||||
// Examine the unit configuration
|
||||
sasi_num = 0;
|
||||
scsi_num = 0;
|
||||
for (j = 0; j < UnitNum; j++) {
|
||||
unitno = i * UnitNum + j;
|
||||
// branch by unit type
|
||||
if (m_disk[unitno]) {
|
||||
if (m_disk[unitno]->IsSASI()) {
|
||||
// Drive is SASI, so increment SASI count
|
||||
sasi_num++;
|
||||
} else {
|
||||
// Drive is SCSI, so increment SCSI count
|
||||
scsi_num++;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the unit
|
||||
if (m_ctrl[i]) {
|
||||
m_ctrl[i]->SetUnit(j, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no units connected
|
||||
if (sasi_num == 0 && scsi_num == 0) {
|
||||
if (m_ctrl[i]) {
|
||||
delete m_ctrl[i];
|
||||
m_ctrl[i] = NULL;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Mixture of SCSI and SASI
|
||||
if (sasi_num > 0 && scsi_num > 0) {
|
||||
FPRT(fp, "Error : SASI and SCSI can't be mixed\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sasi_num > 0) {
|
||||
// Only SASI Unit(s)
|
||||
|
||||
// Release the controller if it is not SASI
|
||||
if (m_ctrl[i] && !m_ctrl[i]->IsSASI()) {
|
||||
delete m_ctrl[i];
|
||||
m_ctrl[i] = NULL;
|
||||
}
|
||||
|
||||
// Create a new SASI controller
|
||||
if (!m_ctrl[i]) {
|
||||
m_ctrl[i] = new SASIDEV();
|
||||
m_ctrl[i]->Connect(i, m_bus);
|
||||
}
|
||||
} else {
|
||||
// Only SCSI Unit(s)
|
||||
|
||||
// Release the controller if it is not SCSI
|
||||
if (m_ctrl[i] && !m_ctrl[i]->IsSCSI()) {
|
||||
delete m_ctrl[i];
|
||||
m_ctrl[i] = NULL;
|
||||
}
|
||||
|
||||
// Create a new SCSI controller
|
||||
if (!m_ctrl[i]) {
|
||||
m_ctrl[i] = new SCSIDEV();
|
||||
m_ctrl[i]->Connect(i, m_bus);
|
||||
}
|
||||
}
|
||||
|
||||
// connect all units
|
||||
for (j = 0; j < UnitNum; j++) {
|
||||
unitno = i * UnitNum + j;
|
||||
if (m_disk[unitno]) {
|
||||
// Add the unit connection
|
||||
m_ctrl[i]->SetUnit(j, m_disk[unitno]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
void Rascsi_Manager::DetachDevice(FILE *fp, Disk *map, int id, int ui)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Disk* Rascsi_Manager::GetDevice(FILE *fp, int id, int ui)
|
||||
{
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// Controller Mapping
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "rasctl_command.h"
|
||||
|
||||
//const char* Rasctl_Command::m_delimiter = "\x1E"; // Record separator charater
|
||||
const char* Rasctl_Command::m_delimiter = " "; // Record separator charater
|
||||
const char* Rasctl_Command::m_delimiter = "\x1E"; // Record separator charater
|
||||
//const char* Rasctl_Command::m_delimiter = " "; // Record separator charater
|
||||
|
||||
void Rasctl_Command::Serialize(BYTE *buff, int max_buff_size){
|
||||
snprintf((char*)buff, max_buff_size, "%d%s%d%s%d%s%d%s%s%s",
|
||||
snprintf((char*)buff, max_buff_size, "%d%s%d%s%d%s%d%s%s%s\n",
|
||||
this->id, this->m_delimiter,
|
||||
this->un, this->m_delimiter,
|
||||
this->cmd, this->m_delimiter,
|
||||
@@ -39,7 +39,7 @@ Rasctl_Command* Rasctl_Command::DeSerialize(BYTE* buff, int size){
|
||||
return_command->un = atoi(cur_token);
|
||||
break;
|
||||
default:
|
||||
for(int i=0; i<size; i++)
|
||||
for(int i=0; i<strlen((char*)buff); i++)
|
||||
{
|
||||
snprintf(&err_message[i*2], sizeof(err_message), "%02X", buff[i]);
|
||||
}
|
||||
@@ -49,16 +49,18 @@ Rasctl_Command* Rasctl_Command::DeSerialize(BYTE* buff, int size){
|
||||
break;
|
||||
}
|
||||
cur_token_idx = (serial_token_order)((int)cur_token_idx + 1);
|
||||
cur_token = strtok(NULL, m_delimiter);
|
||||
}
|
||||
|
||||
if(cur_token_idx != serial_token_last_token)
|
||||
{
|
||||
for(int i=0; i<size; i++)
|
||||
for(int i=0; i<strlen((char*)buff); i++)
|
||||
{
|
||||
snprintf(&err_message[i*2], sizeof(err_message), "%02X", buff[i]);
|
||||
}
|
||||
printf("Received too few tokens: %s", err_message);
|
||||
free(return_command);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return return_command;
|
||||
|
||||
Reference in New Issue
Block a user