From 6fd6fdcc05cf7584cb818584b8bc2064dc7f3192 Mon Sep 17 00:00:00 2001 From: akuker Date: Tue, 7 Jul 2020 14:16:02 -0500 Subject: [PATCH] Failed attempt at monitoring the SCSI traffic. --- src/raspberrypi/Makefile | 34 +++- src/raspberrypi/disk.cpp | 346 ++++++++++++++++++++++++++++++------ src/raspberrypi/disk.h | 177 ++++++++++++++++++ src/raspberrypi/gpiobus.cpp | 106 +++++++++-- src/raspberrypi/rascsi.cpp | 14 +- 5 files changed, 602 insertions(+), 75 deletions(-) diff --git a/src/raspberrypi/Makefile b/src/raspberrypi/Makefile index f2adee5..96ea2bc 100644 --- a/src/raspberrypi/Makefile +++ b/src/raspberrypi/Makefile @@ -1,8 +1,13 @@ +.DEFAULT_GOAL: all + CC = gcc -CFLAGS = -DDISK_LOG -O0 -g -Wall CXX = g++ + +CFLAGS = -DDISK_LOG -O0 -g -Wall CXXFLAGS = -DDISK_LOG -O0 -g -Wall + + # If its not specified, build for STANDARD configuration CONNECT_TYPE ?= STANDARD @@ -15,9 +20,13 @@ RASCSI = rascsi RASCTL = rasctl RASDUMP = rasdump SASIDUMP = sasidump +SCSIMON = scsimon +#BIN_ALL = $(RASCSI) $(RASCTL) $(RASDUMP) $(SASIDUMP) $(SCSIMON) +# Temporarily remove the RASDUMP and RASDUMP tools, since they're not needed +# for my specific use case. If you need them - add them back in! +BIN_ALL = $(RASCSI) $(RASCTL) $(SCSIMON) -BIN_ALL = $(RASCSI) $(RASCTL) $(RASDUMP) $(SASIDUMP) SRC_RASCSI = \ rascsi.cpp \ @@ -46,16 +55,29 @@ SRC_SASIDUMP = \ filepath.cpp \ fileio.cpp +SRC_SCSIMON = \ + scsimon.cpp \ + scsi.cpp \ + disk.cpp \ + gpiobus.cpp \ + ctapdriver.cpp \ + cfilesystem.cpp \ + filepath.cpp \ + fileio.cpp \ + scsimondev.cpp + OBJ_RASCSI := $(SRC_RASCSI:%.cpp=%.o) OBJ_RASCTL := $(SRC_RASCTL:%.cpp=%.o) OBJ_RASDUMP := $(SRC_RASDUMP:%.cpp=%.o) OBJ_SASIDUMP := $(SRC_SASIDUMP:%.cpp=%.o) -OBJ_ALL := $(OBJ_RASCSI) $(OBJ_RASCTL) $(OBJ_RASDUMP) $(OBJ_SASIDUMP) +OBJ_SCSIMON := $(SRC_SCSIMON:%.cpp=%.o) +OBJ_ALL := $(OBJ_RASCSI) $(OBJ_RASCTL) $(OBJ_RASDUMP) $(OBJ_SASIDUMP) $(OBJ_SCSIMON) %.o: %.cpp $(CXX) $(CXXFLAGS) -c $< -o $@ ALL: $(BIN_ALL) +all: $(BIN_ALL) $(RASCSI): $(OBJ_RASCSI) $(CXX) -o $@ $(OBJ_RASCSI) -lpthread @@ -69,8 +91,14 @@ $(RASDUMP): $(OBJ_RASDUMP) $(SASIDUMP): $(OBJ_SASIDUMP) $(CXX) -o $@ $(OBJ_SASIDUMP) +$(SCSIMON): $(OBJ_SCSIMON) + $(CXX) $(CXXFLAGS) -o $@ $(OBJ_SCSIMON) -lpthread + clean: rm -f $(OBJ_ALL) $(BIN_ALL) run: sudo ./$(RASCSI) -ID1 /home/pi/HARDDISK.HDA -ID6 /home/pi/marathon.iso + +.PHONY: Debug +Debug: scsimon diff --git a/src/raspberrypi/disk.cpp b/src/raspberrypi/disk.cpp index 217e6d1..23678f6 100644 --- a/src/raspberrypi/disk.cpp +++ b/src/raspberrypi/disk.cpp @@ -4534,6 +4534,248 @@ void FASTCALL SCSICD::GetBuf( ASSERT(this); } + + +//=========================================================================== +// +// SCSI Monitor Device +// This will monitor all of the traffic to this SCSI ID and dump it to +// STDOUT +// +//=========================================================================== + +//--------------------------------------------------------------------------- +// +// Constructor +// +//--------------------------------------------------------------------------- +MONITORHD::MONITORHD() : Disk() +{ + // SCSI Monitor + disk.id = MAKEID('S', 'M', 'O', 'N'); +} + +//--------------------------------------------------------------------------- +// +// Reset +// +//--------------------------------------------------------------------------- +void FASTCALL MONITORHD::Reset() +{ +// // Unlock and release attention +// disk.lock = FALSE; +// disk.attn = FALSE; +// +// // No reset, clear code +// disk.reset = FALSE; +// disk.code = 0x00; +} + +//--------------------------------------------------------------------------- +// +// Open +// +//--------------------------------------------------------------------------- +BOOL FASTCALL MONITORHD::Open(const Filepath& path, BOOL /*attn*/) +{ +// Fileio fio; +// off64_t size; +// +// ASSERT(this); +// ASSERT(!disk.ready); +// +// // read open required +// if (!fio.Open(path, Fileio::ReadOnly)) { +// return FALSE; +// } +// +// // Get file size +// size = fio.GetFileSize(); +// fio.Close(); +// +// // Must be 512 bytes +// if (size & 0x1ff) { +// return FALSE; +// } +// +// // 10MB or more +// if (size < 0x9f5400) { +// return FALSE; +// } +// // 2TB according to xm6i +// // There is a similar one in wxw/wxw_cfg.cpp +// if (size > 2LL * 1024 * 1024 * 1024 * 1024) { +// return FALSE; +// } +// +// // sector size and number of blocks +// disk.size = 9; +// disk.blocks = (DWORD)(size >> 9); +// +// // Call base class +// return Disk::Open(path); +} + +//--------------------------------------------------------------------------- +// +// INQUIRY +// +//--------------------------------------------------------------------------- +int FASTCALL MONITORHD::Inquiry( + const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor) +{ +//////// char vendor[32]; +//////// char product[32]; +//////// char rev[32]; + int size = 0; +//////// +//////// ASSERT(this); +//////// ASSERT(cdb); +//////// ASSERT(buf); +//////// ASSERT(cdb[0] == 0x12); +//////// +//////// // EVPD check +//////// if (cdb[1] & 0x01) { +//////// disk.code = DISK_INVALIDCDB; +//////// return 0; +//////// } +//////// +//////// // Ready check (Error if no image file) +//////// if (!disk.ready) { +//////// disk.code = DISK_NOTREADY; +//////// return 0; +//////// } +//////// +//////// // Basic data +//////// // buf[0] ... Direct Access Device +//////// // buf[2] ... SCSI-2 compliant command system +//////// // buf[3] ... SCSI-2 compliant Inquiry response +//////// // buf[4] ... Inquiry additional data +//////// memset(buf, 0, 8); +//////// +//////// // SCSI-2 p.104 4.4.3 Incorrect logical unit handling +//////// if (((cdb[1] >> 5) & 0x07) != disk.lun) { +//////// buf[0] = 0x7f; +//////// } +//////// +//////// buf[2] = 0x02; +//////// buf[3] = 0x02; +//////// buf[4] = 122 + 3; // Value close to real HDD +//////// +//////// // Fill with blanks +//////// memset(&buf[8], 0x20, buf[4] - 3); +//////// +//////// // Determine vendor name/product name +//////// sprintf(vendor, BENDER_SIGNATURE); +//////// size = disk.blocks >> 11; +//////// if (size < 300) +//////// sprintf(product, "PRODRIVE LPS%dS", size); +//////// else if (size < 600) +//////// sprintf(product, "MAVERICK%dS", size); +//////// else if (size < 800) +//////// sprintf(product, "LIGHTNING%dS", size); +//////// else if (size < 1000) +//////// sprintf(product, "TRAILBRAZER%dS", size); +//////// else if (size < 2000) +//////// sprintf(product, "FIREBALL%dS", size); +//////// else +//////// sprintf(product, "FBSE%d.%dS", size / 1000, (size % 1000) / 100); +//////// +//////// // Vendor name +//////// memcpy(&buf[8], vendor, strlen(vendor)); +//////// +//////// // Product name +//////// memcpy(&buf[16], product, strlen(product)); +//////// +//////// // Revision +//////// sprintf(rev, "0%01d%01d%01d", +//////// (int)major, (int)(minor >> 4), (int)(minor & 0x0f)); +//////// memcpy(&buf[32], rev, 4); +//////// +//////// // Size of data that can be returned +//////// size = (buf[4] + 5); +//////// +//////// // Limit if the other buffer is small +//////// if (size > (int)cdb[4]) { +//////// size = (int)cdb[4]; +//////// } +//////// +//////// // Success +//////// disk.code = DISK_NOERROR; + return size; +} + +//--------------------------------------------------------------------------- +// +// MODE SELECT +// *Not affected by disk.code +// +//--------------------------------------------------------------------------- +BOOL FASTCALL MONITORHD::ModeSelect(const DWORD *cdb, const BYTE *buf, int length) +{ +// int page; +// int size; +// +// ASSERT(this); +// ASSERT(buf); +// ASSERT(length >= 0); +// +// // PF +// if (cdb[1] & 0x10) { +// // Mode Parameter header +// if (length >= 12) { +// // Check the block length bytes +// size = 1 << disk.size; +// if (buf[9] != (BYTE)(size >> 16) || +// buf[10] != (BYTE)(size >> 8) || +// buf[11] != (BYTE)size) { +// // currently does not allow changing sector length +// disk.code = DISK_INVALIDPRM; +// return FALSE; +// } +// buf += 12; +// length -= 12; +// } +// +// // Parsing the page +// while (length > 0) { +// // Get page +// page = buf[0]; +// +// switch (page) { +// // format device +// case 0x03: +// // check the number of bytes in the physical sector +// size = 1 << disk.size; +// if (buf[0xc] != (BYTE)(size >> 8) || +// buf[0xd] != (BYTE)size) { +// // currently does not allow changing sector length +// disk.code = DISK_INVALIDPRM; +// return FALSE; +// } +// break; +// +// // Other page +// default: +// break; +// } +// +// // Advance to the next page +// size = buf[1] + 2; +// length -= size; +// buf += size; +// } +// } +// +// // Do not generate an error for the time being (MINIX) +// disk.code = DISK_NOERROR; + + return TRUE; +} + + + + //=========================================================================== // // SCSI Host Bridge @@ -6294,19 +6536,20 @@ BUS::phase_t FASTCALL SASIDEV::Process() // Get bus information ctrl.bus->Aquire(); - // Reset - if (ctrl.bus->GetRST()) { -#if defined(DISK_LOG) - Log(Log::Normal, "RESET signal received"); -#endif // DISK_LOG - - // Reset the controller - Reset(); - - // Reset the bus - ctrl.bus->Reset(); - return ctrl.phase; - } + // For the monitor tool, we shouldn't need to reset. We're just logging information +//////// // Reset +//////// if (ctrl.bus->GetRST()) { +////////#if defined(DISK_LOG) +//////// Log(Log::Normal, "RESET signal received"); +////////#endif // DISK_LOG +//////// +//////// // Reset the controller +//////// Reset(); +//////// +//////// // Reset the bus +//////// ctrl.bus->Reset(); +//////// return ctrl.phase; +//////// } // Phase processing switch (ctrl.phase) { @@ -6373,12 +6616,12 @@ void FASTCALL SASIDEV::BusFree() // Phase Setting ctrl.phase = BUS::busfree; - // 信号線 - ctrl.bus->SetREQ(FALSE); - ctrl.bus->SetMSG(FALSE); - ctrl.bus->SetCD(FALSE); - ctrl.bus->SetIO(FALSE); - ctrl.bus->SetBSY(FALSE); +// // Set Signal lines +// ctrl.bus->SetREQ(FALSE); +// ctrl.bus->SetMSG(FALSE); +// ctrl.bus->SetCD(FALSE); +// ctrl.bus->SetIO(FALSE); +// ctrl.bus->SetBSY(FALSE); // Initialize status and message ctrl.status = 0x00; @@ -6459,10 +6702,10 @@ void FASTCALL SASIDEV::Command() // Phase Setting ctrl.phase = BUS::command; - // Signal line operated by the target - ctrl.bus->SetMSG(FALSE); - ctrl.bus->SetCD(TRUE); - ctrl.bus->SetIO(FALSE); +// // Signal line operated by the target +// ctrl.bus->SetMSG(FALSE); +// ctrl.bus->SetCD(TRUE); +// ctrl.bus->SetIO(FALSE); // Data transfer is 6 bytes x 1 block ctrl.offset = 0; @@ -6653,10 +6896,10 @@ void FASTCALL SASIDEV::Status() // Phase Setting ctrl.phase = BUS::status; - // Signal line operated by the target - ctrl.bus->SetMSG(FALSE); - ctrl.bus->SetCD(TRUE); - ctrl.bus->SetIO(TRUE); +//////// // Signal line operated by the target +//////// ctrl.bus->SetMSG(FALSE); +//////// ctrl.bus->SetCD(TRUE); +//////// ctrl.bus->SetIO(TRUE); // Data transfer is 1 byte x 1 block ctrl.offset = 0; @@ -6666,8 +6909,8 @@ void FASTCALL SASIDEV::Status() #ifndef RASCSI // Request status - ctrl.bus->SetDAT(ctrl.buffer[0]); - ctrl.bus->SetREQ(TRUE); +// ctrl.bus->SetDAT(ctrl.buffer[0]); +// ctrl.bus->SetREQ(TRUE); #if defined(DISK_LOG) Log(Log::Normal, "Status Phase $%02X", ctrl.status); @@ -6714,10 +6957,10 @@ void FASTCALL SASIDEV::MsgIn() // Phase Setting ctrl.phase = BUS::msgin; - // Signal line operated by the target - ctrl.bus->SetMSG(TRUE); - ctrl.bus->SetCD(TRUE); - ctrl.bus->SetIO(TRUE); +////////// // Signal line operated by the target +////////// ctrl.bus->SetMSG(TRUE); +////////// ctrl.bus->SetCD(TRUE); +////////// ctrl.bus->SetIO(TRUE); // length, blocks are already set ASSERT(ctrl.length > 0); @@ -6798,10 +7041,10 @@ void FASTCALL SASIDEV::DataIn() // Phase Setting ctrl.phase = BUS::datain; - // Signal line operated by the target - ctrl.bus->SetMSG(FALSE); - ctrl.bus->SetCD(FALSE); - ctrl.bus->SetIO(TRUE); +//////// // Signal line operated by the target +//////// ctrl.bus->SetMSG(FALSE); +//////// ctrl.bus->SetCD(FALSE); +//////// ctrl.bus->SetIO(TRUE); // length, blocks are already set ASSERT(ctrl.length > 0); @@ -6880,10 +7123,10 @@ void FASTCALL SASIDEV::DataOut() // Phase Setting ctrl.phase = BUS::dataout; - // Signal line operated by the target - ctrl.bus->SetMSG(FALSE); - ctrl.bus->SetCD(FALSE); - ctrl.bus->SetIO(FALSE); +//////// // Signal line operated by the target +//////// ctrl.bus->SetMSG(FALSE); +//////// ctrl.bus->SetCD(FALSE); +//////// ctrl.bus->SetIO(FALSE); // length, blocks are already calculated ASSERT(ctrl.length > 0); @@ -8026,6 +8269,7 @@ void FASTCALL SCSIDEV::Reset() BUS::phase_t FASTCALL SCSIDEV::Process() { ASSERT(this); + printf("SCSIDEV::Process() %d\n", ctrl.id); // Do nothing if not connected if (ctrl.id < 0 || ctrl.bus == NULL) { @@ -8125,12 +8369,12 @@ void FASTCALL SCSIDEV::BusFree() // Phase setting ctrl.phase = BUS::busfree; - // Signal line - ctrl.bus->SetREQ(FALSE); - ctrl.bus->SetMSG(FALSE); - ctrl.bus->SetCD(FALSE); - ctrl.bus->SetIO(FALSE); - ctrl.bus->SetBSY(FALSE); +//////// // Signal line +//////// ctrl.bus->SetREQ(FALSE); +//////// ctrl.bus->SetMSG(FALSE); +//////// ctrl.bus->SetCD(FALSE); +//////// ctrl.bus->SetIO(FALSE); +//////// ctrl.bus->SetBSY(FALSE); // Initialize status and message ctrl.status = 0x00; @@ -8399,10 +8643,10 @@ void FASTCALL SCSIDEV::MsgOut() // Phase Setting ctrl.phase = BUS::msgout; - // Signal line operated by the target - ctrl.bus->SetMSG(TRUE); - ctrl.bus->SetCD(TRUE); - ctrl.bus->SetIO(FALSE); +//////// // Signal line operated by the target +//////// ctrl.bus->SetMSG(TRUE); +//////// ctrl.bus->SetCD(TRUE); +//////// ctrl.bus->SetIO(FALSE); // Data transfer is 1 byte x 1 block ctrl.offset = 0; diff --git a/src/raspberrypi/disk.h b/src/raspberrypi/disk.h index 69dc47a..d6dff79 100644 --- a/src/raspberrypi/disk.h +++ b/src/raspberrypi/disk.h @@ -229,6 +229,8 @@ public: // NULL check BOOL FASTCALL IsSASI() const; // SASI Check + virtual BOOL FASTCALL IsMonitor() const {return FALSE;} + // Check if this is a monitor device // Media Operations virtual BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); @@ -399,6 +401,26 @@ public: // MODE SELECT(6) command }; +class MONITORHD : public Disk +{ +public: + // Basic Functions + MONITORHD(); + // Constructor + void FASTCALL Reset(); + // Reset + BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); + // Open + + // commands + int FASTCALL Inquiry( + const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); + // INQUIRY command + BOOL FASTCALL ModeSelect(const DWORD *cdb, const BYTE *buf, int length); + // MODE SELECT(6) command + BOOL FASTCALL IsMonitor() const {return TRUE;} +}; + //=========================================================================== // // SCSI hard disk (PC-9801-55 NEC genuine /Anex86/T98Next) @@ -701,6 +723,31 @@ private: #endif }; + +//////////=========================================================================== +////////// +////////// SCSI Monitor Device (Interits SCSI device) +////////// +//////////=========================================================================== +////////class SCSIMONDEV : public Disk +////////{ +////////public: +//////// // Basic Functions +//////// SCSIMONDEV(); +//////// // Constructor +//////// void FASTCALL Reset(); +//////// // Reset +//////// BOOL FASTCALL Open(const Filepath& path, BOOL attn = TRUE); +//////// // Open +//////// +//////// // commands +//////// int FASTCALL Inquiry( +//////// const DWORD *cdb, BYTE *buf, DWORD major, DWORD minor); +//////// // INQUIRY command +//////// BOOL FASTCALL ModeSelect(const DWORD *cdb, const BYTE *buf, int length); +//////// // MODE SELECT(6) command +////////}; + //=========================================================================== // // SCSI Host Bridge @@ -933,6 +980,8 @@ public: // SASI Check virtual BOOL FASTCALL IsSCSI() const {return FALSE;} // SCSI check + virtual BOOL FASTCALL IsMonitor() const {return FALSE;} + // Check to see if this is a monitor device Disk* FASTCALL GetBusyUnit(); // Get the busy unit @@ -1141,4 +1190,132 @@ private: // Internal data }; +//=========================================================================== +// +// SCSI Device (Interits SASI device) +// +//=========================================================================== +class SCSIMONDEV : public SASIDEV +{ +public: + // Internal data definition + typedef struct { + // Synchronous transfer + BOOL syncenable; // Synchronous transfer possible + int syncperiod; // Synchronous transfer period + int syncoffset; // Synchronous transfer offset + int syncack; // Number of synchronous transfer ACKs + + // ATN message + BOOL atnmsg; + int msc; + BYTE msb[256]; + } scsi_t; + + BOOL FASTCALL IsMonitor() const {return TRUE;} + +public: + // Basic Functions +#ifdef RASCSI + SCSIMONDEV(); +#else + SCSIMONDEV(Device *dev); +#endif // RASCSI + // Constructor + + void FASTCALL Reset(); + // Device Reset + + // 外部API + BUS::phase_t FASTCALL Process(); + // Run + + void FASTCALL SyncTransfer(BOOL enable) { scsi.syncenable = enable; } + // Synchronouse transfer enable setting + + // Other + BOOL FASTCALL IsSASI() const {return FALSE;} + // SASI Check + BOOL FASTCALL IsSCSI() const {return TRUE;} + // SCSI check + +private: + // Phase + void FASTCALL BusFree(); + // Bus free phase + void FASTCALL Selection(); + // Selection phase + void FASTCALL Execute(); + // Execution phase + void FASTCALL MsgOut(); + // Message out phase + void FASTCALL Error(); + // Common erorr handling + + // commands + void FASTCALL CmdInquiry(); + // INQUIRY command + void FASTCALL CmdModeSelect(); + // MODE SELECT command + void FASTCALL CmdModeSense(); + // MODE SENSE command + void FASTCALL CmdStartStop(); + // START STOP UNIT command + void FASTCALL CmdSendDiag(); + // SEND DIAGNOSTIC command + void FASTCALL CmdRemoval(); + // PREVENT/ALLOW MEDIUM REMOVAL command + void FASTCALL CmdReadCapacity(); + // READ CAPACITY command + void FASTCALL CmdRead10(); + // READ(10) command + void FASTCALL CmdWrite10(); + // WRITE(10) command + void FASTCALL CmdSeek10(); + // SEEK(10) command + void FASTCALL CmdVerify(); + // VERIFY command + void FASTCALL CmdSynchronizeCache(); + // SYNCHRONIZE CACHE command + void FASTCALL CmdReadDefectData10(); + // READ DEFECT DATA(10) command + void FASTCALL CmdReadToc(); + // READ TOC command + void FASTCALL CmdPlayAudio10(); + // PLAY AUDIO(10) command + void FASTCALL CmdPlayAudioMSF(); + // PLAY AUDIO MSF command + void FASTCALL CmdPlayAudioTrack(); + // PLAY AUDIO TRACK INDEX command + void FASTCALL CmdModeSelect10(); + // MODE SELECT(10) command + void FASTCALL CmdModeSense10(); + // MODE SENSE(10) command + void FASTCALL CmdGetMessage10(); + // GET MESSAGE(10) command + void FASTCALL CmdSendMessage10(); + // SEND MESSAGE(10) command + + // データ転送 + void FASTCALL Send(); + // Send data +#ifndef RASCSI + void FASTCALL SendNext(); + // Continue sending data +#endif // RASCSI + void FASTCALL Receive(); + // Receive data +#ifndef RASCSI + void FASTCALL ReceiveNext(); + // Continue receiving data +#endif // RASCSI + BOOL FASTCALL XferMsg(DWORD msg); + // Data transfer message + + scsi_t scsi; + // Internal data +}; + + + #endif // disk_h diff --git a/src/raspberrypi/gpiobus.cpp b/src/raspberrypi/gpiobus.cpp index e0b8386..a8cd7a3 100644 --- a/src/raspberrypi/gpiobus.cpp +++ b/src/raspberrypi/gpiobus.cpp @@ -65,7 +65,7 @@ DWORD bcm_host_get_peripheral_address(void) char buf[1024]; size_t len = sizeof(buf); DWORD address; - + if (sysctlbyname("hw.model", buf, &len, NULL, 0) || strstr(buf, "ARM1176JZ-S") != buf) { // Failed to get CPU model || Not BCM2835 @@ -88,7 +88,7 @@ extern uint32_t RPi_IO_Base_Addr; // Core frequency extern uint32_t RPi_Core_Freq; -#ifdef USE_SEL_EVENT_ENABLE +#ifdef USE_SEL_EVENT_ENABLE //--------------------------------------------------------------------------- // // Interrupt control function @@ -169,6 +169,7 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode) // Open /dev/mem fd = open("/dev/mem", O_RDWR | O_SYNC); if (fd == -1) { + printf("Error: Unable to open /dev/mem. Are you running as root?\n"); return FALSE; } @@ -274,6 +275,7 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode) PinConfig(PIN_DTD, GPIO_OUTPUT); // Set the ENABLE signal + // This is used to show that the application is running PinSetSignal(PIN_ENB, ENB_OFF); PinConfig(PIN_ENB, GPIO_OUTPUT); @@ -373,6 +375,7 @@ BOOL FASTCALL GPIOBUS::Init(mode_e mode) MakeTable(); // Finally, enable ENABLE + // Show the user that this app is running SetControl(PIN_ENB, ENB_ON); return TRUE; @@ -518,7 +521,7 @@ DWORD FASTCALL GPIOBUS::Aquire() // Invert if negative logic (internal processing is unified to positive logic) signals = ~signals; #endif // SIGNAL_CONTROL_MODE - + return signals; } @@ -549,9 +552,15 @@ BOOL FASTCALL GPIOBUS::GetBSY() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetBSY(BOOL ast) { - // Set BSY signal - SetSignal(PIN_BSY, ast); - + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET BSY IN MONITOR MODE"); + } + else + { + // Set BSY signal + SetSignal(PIN_BSY, ast); + } if (actmode == TARGET) { if (ast) { // Turn on ACTIVE signal @@ -603,8 +612,14 @@ void FASTCALL GPIOBUS::SetSEL(BOOL ast) SetControl(PIN_ACT, ACT_ON); } - // Set SEL signal - SetSignal(PIN_SEL, ast); + if (actmode != MONITOR) + { + // Set SEL signal + SetSignal(PIN_SEL, ast); + } + else{ + printf("WARNING!!! SOMEONE TRIED TO SET SEL IN MONITOR MODE"); +} } //--------------------------------------------------------------------------- @@ -624,7 +639,14 @@ BOOL FASTCALL GPIOBUS::GetATN() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetATN(BOOL ast) { - SetSignal(PIN_ATN, ast); + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET ATN IN MONITOR MODE"); + } + else + { + SetSignal(PIN_ATN, ast); + } } //--------------------------------------------------------------------------- @@ -644,7 +666,14 @@ BOOL FASTCALL GPIOBUS::GetACK() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetACK(BOOL ast) { + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET ACK IN MONITOR MODE"); + } + else + { SetSignal(PIN_ACK, ast); + } } //--------------------------------------------------------------------------- @@ -664,7 +693,14 @@ BOOL FASTCALL GPIOBUS::GetRST() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetRST(BOOL ast) { + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET RST IN MONITOR MODE"); + } + else + { SetSignal(PIN_RST, ast); + } } //--------------------------------------------------------------------------- @@ -684,7 +720,13 @@ BOOL FASTCALL GPIOBUS::GetMSG() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetMSG(BOOL ast) { - SetSignal(PIN_MSG, ast); + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET MSG IN MONITOR MODE"); + } + else{ + SetSignal(PIN_MSG, ast); + } } //--------------------------------------------------------------------------- @@ -704,7 +746,14 @@ BOOL FASTCALL GPIOBUS::GetCD() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetCD(BOOL ast) { - SetSignal(PIN_CD, ast); + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET CD IN MONITOR MODE"); + } + else + { + SetSignal(PIN_CD, ast); + } } //--------------------------------------------------------------------------- @@ -754,6 +803,21 @@ BOOL FASTCALL GPIOBUS::GetIO() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetIO(BOOL ast) { + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET IO IN MONITOR MODE"); + SetControl(PIN_DTD, DTD_IN); + SetMode(PIN_DT0, IN); + SetMode(PIN_DT1, IN); + SetMode(PIN_DT2, IN); + SetMode(PIN_DT3, IN); + SetMode(PIN_DT4, IN); + SetMode(PIN_DT5, IN); + SetMode(PIN_DT6, IN); + SetMode(PIN_DT7, IN); + SetMode(PIN_DP, IN); + } + SetSignal(PIN_IO, ast); if (actmode == TARGET) { @@ -802,6 +866,12 @@ BOOL FASTCALL GPIOBUS::GetREQ() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetREQ(BOOL ast) { + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET REQ IN MONITOR MODE"); + return; + } + SetSignal(PIN_REQ, ast); } @@ -835,6 +905,14 @@ BYTE FASTCALL GPIOBUS::GetDAT() //--------------------------------------------------------------------------- void FASTCALL GPIOBUS::SetDAT(BYTE dat) { + + + if(actmode == MONITOR) + { + printf("WARNING!!! SOMEONE TRIED TO SET Data IN MONITOR MODE"); + return; + } + // Write to port #if SIGNAL_CONTROL_MODE == 0 DWORD fsel; @@ -1152,7 +1230,7 @@ int FASTCALL GPIOBUS::SendHandShake(BYTE *buf, int count) } // Already waiting for REQ assertion - + // Assert the ACK signal SetSignal(PIN_ACK, ON); @@ -1396,7 +1474,7 @@ void FASTCALL GPIOBUS::SetMode(int pin, int mode) gpio[index] = data; gpfsel[index] = data; } - + //--------------------------------------------------------------------------- // // Get input signal value @@ -1406,7 +1484,7 @@ BOOL FASTCALL GPIOBUS::GetSignal(int pin) { return (signals >> pin) & 1; } - + //--------------------------------------------------------------------------- // // Set output signal value diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index 4e55f00..c12ac06 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -153,9 +153,9 @@ BOOL Init() // GPIOBUS creation bus = new GPIOBUS(); - + // GPIO Initialization - if (!bus->Init()) { + if (!bus->Init(BUS::TARGET)) { return FALSE; } @@ -206,7 +206,7 @@ void Cleanup() // Cleanup the Bus bus->Cleanup(); - + // Discard the GPIOBUS object delete bus; @@ -306,7 +306,7 @@ void ListDevice(FILE *fp) FPRT(fp, "No device is installed.\n"); return; } - + FPRT(fp, "+----+----+------+-------------------------------------\n"); } @@ -862,7 +862,7 @@ static void *MonThread(void *param) { struct sched_param schedparam; struct sockaddr_in client; - socklen_t len; + socklen_t len; int fd; FILE *fp; char buf[BUFSIZ]; @@ -892,8 +892,8 @@ static void *MonThread(void *param) while (1) { // Wait for connection - memset(&client, 0, sizeof(client)); - len = sizeof(client); + memset(&client, 0, sizeof(client)); + len = sizeof(client); fd = accept(monsocket, (struct sockaddr*)&client, &len); if (fd < 0) { break;