// // Firefly cache coherency simulation // // Copyright © 1997 - 2008 jones@cs.tcd.ie // // This program is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software Foundation; // either version 2 of the License, 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 more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software Foundation Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // // 21/02/97 first version // 10/06/97 used SimpleButton + corrected a bug // 07/12/01 added locks and parallel operation // 10/12/01 memory read bug - now flush cache line if dirty (rather than ~SD) // 07/08/02 Vivio 2.0 // 08/08/02 bug fix - from reset if CPU0 write a3 is followed by CPU0 write a1 write NOW a shared write // 20/08/02 moved positioning of bus lock in write // 21/02/05 memory read bug - handle flush of shared cache line correctly (see bug 10/12/01) // 18/01/06 Vivio 4.0 // 20/02/06 real x,y event parameters // 07/11/06 added extra wait(1) after getting bus lock // 11/01/07 added Vivio logo // 14/01/07 used ImageButton for logo // 13/03/07 return EV_FORGET in event handlers which call getURL // 19/05/07 logo now uses a hand cursor // // Copyright © 2007 - 2007 alek.stevanovic@gmail.com // // 23/12/07 first version // 23/11/08 second version, Djordje Jevdjic // Last Revision: Marko Peric 17/02/10 // // include files // #include "standard.vin" #include "simpleButton.vin" // // set viewport // const int LOGICALW = 1024; const int LOGICALH = 768; setViewport(0, 0, LOGICALW, LOGICALH, 1); // // set background // bgbrush = SolidBrush(vellum); setBGBrush(bgbrush); // // fonts // hintFont = Font("Times New Roman", 16, 0); titleFont = Font("Times New Roman", 24, 0); f12B = Font("Times New Roman", 12, 1); fsmall = Font("Times New Roman", 14, 0); // // title // navybrush = SolidBrush(rgb(0, 0, 102)); title = Rectangle2(0, VCENTRE, 0, navybrush, 5, 5, LOGICALW/2, 30, whitebrush, titleFont, "Dragon Cache Coherency Protocol"); title.setTxtOff(2, 1); // // useage infomation // str = "Like real hardware, the CPUs can operate\n"; str += "in parallel - try pressing a button on each\n"; str += "CPU \"simultaneously\"."; hint = Txt(0, HLEFT | VTOP, 5, 80, blackbrush, hintFont, str); const int DIRTYBIT = 1; // const int SHAREDBIT = 2; // cache line states const int NOTHING = 0; const int RECV = 1; const int SEND = 2; const int SND_RCV = 3; const int MEMORY = 4; const int ST_E = 0; // Exclusive const int ST_M = 1; // Modified const int ST_Sc = 2; // Shared clean const int ST_Sm = 3; // Shared modified const int ST_No = 4; // Beginner empty state string statetxt[5] = { "E", "M", "Sc", "Sm", "No" }; int wValue = 0; // value written into cache int isdirty = 0; // indicates if there is a dirty cache int isshared = 0; // indicates if cache line shared int issharedstate = 0; // shared cache line state (all should be the same) int isshareddata = 0; // shared cache line data (all should be the same) int buglevel = 0; // buglevel (0 = bug free) int isbusy = 0; // counter used to signify when any of the processors is busy // (with it representing the number of busy processors) // // Number of CPUs // const int NCPU = 4; // Set the number of CPUs in the simulation for (int i=0; i