diff --git a/tools/src/librw11/Makefile b/tools/src/librw11/Makefile index ecee870c..2c6b6228 100644 --- a/tools/src/librw11/Makefile +++ b/tools/src/librw11/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile 859 2017-03-11 22:36:45Z mueller $ +# $Id: Makefile 1063 2018-10-29 18:37:42Z mueller $ # # Revision History: # Date Rev Version Comment @@ -21,29 +21,30 @@ LDLIBS = -L${RETROBASE}/tools/lib -lrtools -lrlink # # Object files to be included # -OBJ_all = Rw11.o Rw11Cpu.o Rw11CpuW11a.o +OBJ_all = Rw11.o Rw11Cpu.o Rw11CpuW11a.o OBJ_all += Rw11Probe.o OBJ_all += Rw11Cntl.o Rw11Unit.o -OBJ_all += Rw11UnitTerm.o -OBJ_all += Rw11UnitDisk.o -OBJ_all += Rw11UnitTape.o -OBJ_all += Rw11UnitStream.o -OBJ_all += Rw11CntlDL11.o Rw11UnitDL11.o -OBJ_all += Rw11CntlLP11.o Rw11UnitLP11.o -OBJ_all += Rw11CntlPC11.o Rw11UnitPC11.o +OBJ_all += Rw11UnitTerm.o +OBJ_all += Rw11UnitDisk.o +OBJ_all += Rw11UnitTape.o +OBJ_all += Rw11UnitStream.o +OBJ_all += Rw11CntlDL11.o Rw11UnitDL11.o +OBJ_all += Rw11CntlLP11.o Rw11UnitLP11.o +OBJ_all += Rw11CntlPC11.o Rw11UnitPC11.o OBJ_all += Rw11CntlRL11.o Rw11UnitRL11.o OBJ_all += Rw11CntlRK11.o Rw11UnitRK11.o OBJ_all += Rw11CntlRHRP.o Rw11UnitRHRP.o OBJ_all += Rw11CntlTM11.o Rw11UnitTM11.o OBJ_all += Rw11CntlDEUNA.o Rw11UnitDEUNA.o -OBJ_all += Rw11Virt.o -OBJ_all += Rw11VirtTerm.o Rw11VirtTermPty.o Rw11VirtTermTcp.o +OBJ_all += Rw11Virt.o +OBJ_all += Rw11VirtTerm.o Rw11VirtTermPty.o Rw11VirtTermTcp.o OBJ_all += Rw11VirtDiskBuffer.o -OBJ_all += Rw11VirtDisk.o Rw11VirtDiskFile.o Rw11VirtDiskOver.o -OBJ_all += Rw11VirtTape.o Rw11VirtTapeTap.o -OBJ_all += Rw11VirtEth.o Rw11VirtEthTap.o -OBJ_all += Rw11VirtStream.o -OBJ_all += Rw11Rdma.o Rw11RdmaDisk.o +OBJ_all += Rw11VirtDisk.o Rw11VirtDiskFile.o +OBJ_all += Rw11VirtDiskOver.o Rw11VirtDiskRam.o +OBJ_all += Rw11VirtTape.o Rw11VirtTapeTap.o +OBJ_all += Rw11VirtEth.o Rw11VirtEthTap.o +OBJ_all += Rw11VirtStream.o +OBJ_all += Rw11Rdma.o Rw11RdmaDisk.o OBJ_all += RethTools.o RethBuf.o # DEP_all = $(OBJ_all:.o=.dep) diff --git a/tools/src/librw11/Rw11VirtDisk.cpp b/tools/src/librw11/Rw11VirtDisk.cpp index d293fc23..f55b0dec 100644 --- a/tools/src/librw11/Rw11VirtDisk.cpp +++ b/tools/src/librw11/Rw11VirtDisk.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11VirtDisk.cpp 1061 2018-10-27 17:39:11Z mueller $ +// $Id: Rw11VirtDisk.cpp 1066 2018-11-10 11:21:53Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -57,7 +57,10 @@ std::string Rw11VirtDisk::sDefaultScheme("file"); Rw11VirtDisk::Rw11VirtDisk(Rw11Unit* punit) : Rw11Virt(punit), fBlkSize(0), - fNBlock(0) + fNBlock(0), + fNCyl(0), + fNHead(0), + fNSect(0) { fStats.Define(kStatNVDRead, "NVDRead", "Read() calls"); fStats.Define(kStatNVDReadBlk, "NVDReadBlk", "blocks read"); diff --git a/tools/src/librw11/Rw11VirtDiskRam.cpp b/tools/src/librw11/Rw11VirtDiskRam.cpp new file mode 100644 index 00000000..e6dd45d7 --- /dev/null +++ b/tools/src/librw11/Rw11VirtDiskRam.cpp @@ -0,0 +1,226 @@ +// $Id: Rw11VirtDiskRam.cpp 1063 2018-10-29 18:37:42Z mueller $ +// +// Copyright 2018- by Walter F.J. Mueller +// +// This program is free software; you may redistribute and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for complete details. +// +// Revision History: +// Date Rev Version Comment +// 2018-10-28 1063 1.0 Initial version +// 2018-10-27 1061 0.1 First draft +// --------------------------------------------------------------------------- + +/*! + \file + \brief Implemenation of Rw11VirtDiskRam. +*/ + +#include +#include +#include +#include + +#include "librtools/RosFill.hpp" +#include "librtools/RosPrintf.hpp" + +#include "Rw11VirtDiskRam.hpp" + +using namespace std; + +/*! + \class Retro::Rw11VirtDiskRam + \brief FIXME_docs +*/ + +// all method definitions in namespace Retro +namespace Retro { + +//------------------------------------------+----------------------------------- +//! Default constructor + +Rw11VirtDiskRam::Rw11VirtDiskRam(Rw11Unit* punit) + : Rw11VirtDisk(punit), + fPatTyp(kPatZero), + fBlkMap() +{ + fStats.Define(kStatNVDReadRam, "NVDReadRam", "ram: blocks read from ram"); + fStats.Define(kStatNVDWriteOver, "NVDWriteOver", "ram: blocks overwritten"); +} + +//------------------------------------------+----------------------------------- +//! Destructor + +Rw11VirtDiskRam::~Rw11VirtDiskRam() +{} + +//------------------------------------------+----------------------------------- +//! FIXME_docs + +bool Rw11VirtDiskRam::Open(const std::string& url, RerrMsg& emsg) +{ + return Open(url, "file", emsg); +} + +//------------------------------------------+----------------------------------- +//! FIXME_docs + +bool Rw11VirtDiskRam::Open(const std::string& url, const std::string& scheme, + RerrMsg& emsg) +{ + if (!fUrl.Set(url, "|wpro|pat=|", scheme, emsg)) return false; + fWProt = fUrl.FindOpt("wpro"); + + string pat; + fPatTyp = kPatZero; + if (fUrl.FindOpt("pat", pat)) { + if (pat == "zero") { + fPatTyp = kPatZero; + } else if (pat == "ones") { + fPatTyp = kPatOnes; + } else if (pat == "dead") { + fPatTyp = kPatDead; + } else if (pat == "test") { + fPatTyp = kPatTest; + } else { + emsg.Init("Rw11VirtDiskRam::Open()", + string("invalid pattern name '") + pat + "'"); + return false; + } + } + + return true; +} + +//------------------------------------------+----------------------------------- +//! FIXME_docs + +bool Rw11VirtDiskRam::Read(size_t lba, size_t nblk, uint8_t* data, + RerrMsg& /*emsg*/) +{ + fStats.Inc(kStatNVDRead); + fStats.Inc(kStatNVDReadBlk, double(nblk)); + + for (size_t i=0; isecond).Read(data+i*fBlkSize); + } + } + + return true; +} + +//------------------------------------------+----------------------------------- +//! FIXME_docs + +bool Rw11VirtDiskRam::Write(size_t lba, size_t nblk, const uint8_t* data, + RerrMsg& /*emsg*/) +{ + fStats.Inc(kStatNVDWrite); + fStats.Inc(kStatNVDWriteBlk, double(nblk)); + + for (size_t i=0; isecond).Write(data+i*fBlkSize); + } + + return true; +} + +//------------------------------------------+----------------------------------- +//! FIXME_docs + +void Rw11VirtDiskRam::List(std::ostream& os) const +{ + if (fBlkMap.empty()) return; + + uint32_t lbabeg = fBlkMap.begin()->first; // first lba + uint32_t nwrite = 0; + for (auto it=fBlkMap.begin(); it!=fBlkMap.end(); ) { + nwrite += (it->second).NWrite(); + auto itnext = next(it); + if (itnext == fBlkMap.end() || itnext->first != (it->first)+1) { + os << RosPrintf(lbabeg,"d",8) + << " .. " << RosPrintf(it->first,"d",8) + << " : nb=" << RosPrintf(it->first-lbabeg+1,"d",8) + << " nw=" << RosPrintf(nwrite,"d",8) << endl; + if (itnext != fBlkMap.end()) lbabeg = itnext->first; + nwrite = 0; + } + it = itnext; + } + return; +} + +//------------------------------------------+----------------------------------- +//! FIXME_docs + +void Rw11VirtDiskRam::Dump(std::ostream& os, int ind, const char* text, + int detail) const +{ + RosFill bl(ind); + os << bl << (text?text:"--") << "Rw11VirtDiskRam @ " << this << endl; + + os << bl << " fPatTyp: " << fPatTyp << endl; + os << bl << " fBlkMap.size: " << fBlkMap.size() << endl; + Rw11VirtDisk::Dump(os, ind, " ^", detail); + return; +} + +//------------------------------------------+----------------------------------- +//! FIXME_doc + +void Rw11VirtDiskRam::ReadPattern(size_t lba, uint8_t* data) +{ + uint16_t* p = reinterpret_cast(data); + uint16_t* pend = reinterpret_cast(data+fBlkSize); + size_t addr = lba*fBlkSize; + + switch (fPatTyp) { + case kPatZero: + while (p < pend) { *p++ = 0x0000; } + break; + case kPatOnes: + while (p < pend) { *p++ = 0xffff; } + break; + case kPatDead: + while (p < pend) { *p++ = 0xdead; *p++ = 0xbeaf; } + break; + case kPatTest: + while(p < pend) { + *p++ = addr & 0xffff; // byte address, LSB + *p++ = (addr>>16) & 0xffff; // byte address, MSB + *p++ = lba / (fNSect*fNHead); // current cylinder + *p++ = (lba/fNSect) % fNHead; // current head + *p++ = lba % fNSect; // current sector + *p++ = fNCyl; // total number of cylinders + *p++ = fNHead; // total number of heads + *p++ = fNSect; // total number of sectors + addr += 16; + } + break; + default: + break; + } + + return; +} + +} // end namespace Retro diff --git a/tools/src/librw11/Rw11VirtDiskRam.hpp b/tools/src/librw11/Rw11VirtDiskRam.hpp new file mode 100644 index 00000000..2934ab32 --- /dev/null +++ b/tools/src/librw11/Rw11VirtDiskRam.hpp @@ -0,0 +1,88 @@ +// $Id: Rw11VirtDiskRam.hpp 1063 2018-10-29 18:37:42Z mueller $ +// +// Copyright 2018- by Walter F.J. Mueller +// +// This program is free software; you may redistribute and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for complete details. +// +// Revision History: +// Date Rev Version Comment +// 2018-10-28 1063 1.0 Initial version +// 2018-10-27 1061 0.1 First draft +// --------------------------------------------------------------------------- + + +/*! + \file + \brief Declaration of class Rw11VirtDiskRam. +*/ + +#ifndef included_Retro_Rw11VirtDiskRam +#define included_Retro_Rw11VirtDiskRam 1 + +#include + +#include "Rw11VirtDiskBuffer.hpp" + +#include "Rw11VirtDisk.hpp" + +namespace Retro { + + class Rw11VirtDiskRam : public Rw11VirtDisk { + public: + + typedef std::map bmap_t; + typedef bmap_t::iterator bmap_it_t; + typedef bmap_t::const_iterator bmap_cit_t; + typedef bmap_t::value_type bmap_val_t; + + explicit Rw11VirtDiskRam(Rw11Unit* punit); + ~Rw11VirtDiskRam(); + + virtual bool Open(const std::string& url, RerrMsg& emsg); + bool Open(const std::string& url, const std::string& scheme, + RerrMsg& emsg); + + virtual bool Read(size_t lba, size_t nblk, uint8_t* data, + RerrMsg& emsg); + virtual bool Write(size_t lba, size_t nblk, const uint8_t* data, + RerrMsg& emsg); + + void List(std::ostream& os) const; + + virtual void Dump(std::ostream& os, int ind=0, const char* text=0, + int detail=0) const; + + // statistics counter indices (now new) + enum stats { + kStatNVDReadRam = Rw11VirtDisk::kDimStat, + kStatNVDWriteOver, + kDimStat + }; + + protected: + void ReadPattern(size_t lba, uint8_t* data); + + protected: + enum pattyp { + kPatZero = 0, + kPatOnes, + kPatDead, + kPatTest + }; + + pattyp fPatTyp; //!< pattern type + bmap_t fBlkMap; + }; + +} // end namespace Retro + +//#include "Rw11VirtDiskRam.ipp" + +#endif diff --git a/tools/src/librwxxtpp/Makefile b/tools/src/librwxxtpp/Makefile index 52ab0700..451b857a 100644 --- a/tools/src/librwxxtpp/Makefile +++ b/tools/src/librwxxtpp/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile 859 2017-03-11 22:36:45Z mueller $ +# $Id: Makefile 1063 2018-10-29 18:37:42Z mueller $ # # Revision History: # Date Rev Version Comment @@ -25,9 +25,9 @@ LDLIBS += -lrlinktpp # # Object files to be included # -OBJ_all = Rwxxtpp_Init.o RtclRw11.o +OBJ_all = Rwxxtpp_Init.o RtclRw11.o OBJ_all += RtclRw11Cpu.o RtclRw11CpuW11a.o -OBJ_all += RtclRw11Cntl.o RtclRw11CntlFactory.o +OBJ_all += RtclRw11Cntl.o RtclRw11CntlFactory.o OBJ_all += RtclRw11Unit.o OBJ_all += RtclRw11UnitTerm.o OBJ_all += RtclRw11UnitDisk.o @@ -42,8 +42,8 @@ OBJ_all += RtclRw11CntlRHRP.o RtclRw11UnitRHRP.o OBJ_all += RtclRw11CntlTM11.o RtclRw11UnitTM11.o OBJ_all += RtclRw11CntlDEUNA.o RtclRw11UnitDEUNA.o OBJ_all += RtclRw11Virt.o -OBJ_all += RtclRw11VirtFactory.o -OBJ_all += RtclRw11VirtDiskOver.o +OBJ_all += RtclRw11VirtFactory.o +OBJ_all += RtclRw11VirtDiskOver.o RtclRw11VirtDiskRam.o # DEP_all = $(OBJ_all:.o=.dep) # diff --git a/tools/src/librwxxtpp/RtclRw11VirtDiskRam.cpp b/tools/src/librwxxtpp/RtclRw11VirtDiskRam.cpp new file mode 100644 index 00000000..6a6d399a --- /dev/null +++ b/tools/src/librwxxtpp/RtclRw11VirtDiskRam.cpp @@ -0,0 +1,66 @@ +// $Id: RtclRw11VirtDiskRam.cpp 1063 2018-10-29 18:37:42Z mueller $ +// +// Copyright 2018- by Walter F.J. Mueller +// +// This program is free software; you may redistribute and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for complete details. +// +// Revision History: +// Date Rev Version Comment +// 2018-10-28 1063 1.0 Initial version +// --------------------------------------------------------------------------- + +/*! + \file + \brief Implemenation of RtclRw11VirtDiskRam. +*/ + +#include "RtclRw11VirtDiskRam.hpp" + +using namespace std; + +/*! + \class Retro::RtclRw11VirtDiskRam + \brief FIXME_docs +*/ + +// all method definitions in namespace Retro +namespace Retro { + +//------------------------------------------+----------------------------------- +//! Constructor + +RtclRw11VirtDiskRam::RtclRw11VirtDiskRam(Rw11VirtDiskRam* pobj) + : RtclRw11VirtBase(pobj) +{ + AddMeth("list", boost::bind(&RtclRw11VirtDiskRam::M_list, this, _1)); +} + +//------------------------------------------+----------------------------------- +//! Destructor + +RtclRw11VirtDiskRam::~RtclRw11VirtDiskRam() +{} + +//------------------------------------------+----------------------------------- +//! FIXME_docs + +int RtclRw11VirtDiskRam::M_list(RtclArgs& args) +{ + if (!args.AllDone()) return kERR; + ostringstream sos; + + // synchronize with server thread + boost::lock_guard lock(Obj().Cpu().Connect()); + Obj().List(sos); + args.SetResult(sos); + return kOK; +} + +} // end namespace Retro diff --git a/tools/src/librwxxtpp/RtclRw11VirtDiskRam.hpp b/tools/src/librwxxtpp/RtclRw11VirtDiskRam.hpp new file mode 100644 index 00000000..c0db6e1a --- /dev/null +++ b/tools/src/librwxxtpp/RtclRw11VirtDiskRam.hpp @@ -0,0 +1,47 @@ +// $Id: RtclRw11VirtDiskRam.hpp 1063 2018-10-29 18:37:42Z mueller $ +// +// Copyright 2018- by Walter F.J. Mueller +// +// This program is free software; you may redistribute and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for complete details. +// +// Revision History: +// Date Rev Version Comment +// 2018-10-28 1063 1.0 Initial version +// --------------------------------------------------------------------------- + + +/*! + \file + \brief Declaration of class RtclRw11VirtDiskRam. +*/ + +#ifndef included_Retro_RtclRw11VirtDiskRam +#define included_Retro_RtclRw11VirtDiskRam 1 + +#include "librw11/Rw11VirtDiskRam.hpp" + +#include "RtclRw11VirtBase.hpp" + +namespace Retro { + + class RtclRw11VirtDiskRam : public RtclRw11VirtBase { + public: + RtclRw11VirtDiskRam(Rw11VirtDiskRam* pobj); + ~RtclRw11VirtDiskRam(); + + protected: + int M_list(RtclArgs& args); + }; + +} // end namespace Retro + +//#include "RtclRw11VirtDiskRam.ipp" + +#endif diff --git a/tools/src/librwxxtpp/RtclRw11VirtFactory.cpp b/tools/src/librwxxtpp/RtclRw11VirtFactory.cpp index 794a7185..6b8a3afd 100644 --- a/tools/src/librwxxtpp/RtclRw11VirtFactory.cpp +++ b/tools/src/librwxxtpp/RtclRw11VirtFactory.cpp @@ -1,4 +1,4 @@ -// $Id: RtclRw11VirtFactory.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RtclRw11VirtFactory.cpp 1063 2018-10-29 18:37:42Z mueller $ // // Copyright 2017- by Walter F.J. Mueller // @@ -22,8 +22,10 @@ */ #include "librw11/Rw11VirtDiskOver.hpp" +#include "librw11/Rw11VirtDiskRam.hpp" #include "RtclRw11VirtDiskOver.hpp" +#include "RtclRw11VirtDiskRam.hpp" #include "RtclRw11VirtFactory.hpp" @@ -43,6 +45,10 @@ RtclRw11Virt* RtclRw11VirtFactory(Rw11Virt* pobj) if (pdiskover) { return new RtclRw11VirtDiskOver(pdiskover); } + Rw11VirtDiskRam* pdiskram = dynamic_cast(pobj); + if (pdiskram) { + return new RtclRw11VirtDiskRam(pdiskram); + } return nullptr; }