From d96aa80e59606fdf91e1562068b0b6f7a0373ee7 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 14 May 2021 01:58:46 -0600 Subject: [PATCH 01/84] ignore build files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 093805de..9b0d08dc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,7 @@ out .classpath .project examples/riscv + +# RARS build +build/ +rars.jar From e846a9d21bfd0b9d725329db0860a12010477c87 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 14 May 2021 01:59:40 -0600 Subject: [PATCH 02/84] lr.w and sc.w syntax support --- src/PseudoOps.txt | 4 ++ src/rars/riscv/BasicInstructionFormat.java | 3 +- src/rars/riscv/instructions/Atomic.java | 44 ++++++++++++++++++++++ src/rars/riscv/instructions/LR_W.java | 29 ++++++++++++++ src/rars/riscv/instructions/SC_W.java | 33 ++++++++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/rars/riscv/instructions/Atomic.java create mode 100644 src/rars/riscv/instructions/LR_W.java create mode 100644 src/rars/riscv/instructions/SC_W.java diff --git a/src/PseudoOps.txt b/src/PseudoOps.txt index d9870286..8c5568bf 100644 --- a/src/PseudoOps.txt +++ b/src/PseudoOps.txt @@ -265,3 +265,7 @@ fgt.s t1, f2, f3 ;fle.s RG1, RG2, RG3 ;#Floating Greater Than: if f1 > f2, fge.s t1, f2, f3 ;flt.s RG1, RG2, RG3 ;#Floating Greater Than or Equal: if f1 >= f2, set t1 to 1, else set t1 to 0 fgt.d t1, f2, f3 ;fle.d RG1, RG2, RG3 ;#Floating Greater Than (64 bit): if f1 > f2, set t1 to 1, else set t1 to 0 fge.d t1, f2, f3 ;flt.d RG1, RG2, RG3 ;#Floating Greater Than or Equal (64 bit): if f1 >= f2, set t1 to 1, else set t1 to 0 + +######################### atomic pseudo-ops ########################## +lr.w t1,(t2) ;lw RG1,0(RG3) ;#Load Reserved Word : Set t1 to contents of effective memory word address and reserves memory word address +sc.w t1,t2,(t3) ;sw RG1,0(RG3) ;#Store Conditional Word : Tries to store t2 contents into effective memory word address and returns store result in t1 diff --git a/src/rars/riscv/BasicInstructionFormat.java b/src/rars/riscv/BasicInstructionFormat.java index c607e051..a037566a 100644 --- a/src/rars/riscv/BasicInstructionFormat.java +++ b/src/rars/riscv/BasicInstructionFormat.java @@ -41,5 +41,6 @@ public enum BasicInstructionFormat { S_FORMAT, // 2 src registers + small immediate B_FORMAT, // 2 src registers + small immediate shifted left U_FORMAT, // 1 dst register + large immediate - J_FORMAT // 1 dst register + large immediate for jumping + J_FORMAT, // 1 dst register + large immediate for jumping + A_FORMAT, // 1 dst and 1 or 2 src register } diff --git a/src/rars/riscv/instructions/Atomic.java b/src/rars/riscv/instructions/Atomic.java new file mode 100644 index 00000000..335a9af9 --- /dev/null +++ b/src/rars/riscv/instructions/Atomic.java @@ -0,0 +1,44 @@ +package rars.riscv.instructions; + +import rars.riscv.BasicInstruction; +import rars.riscv.BasicInstructionFormat; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +/** + * Base class for all Atomic instructions + * + * @author Giancarlo Pernudi Segura + * @version May 2017 + */ +public abstract class Atomic extends BasicInstruction { + public Atomic(String usage, String description, String funct3, String funct5) { + super(usage, description, BasicInstructionFormat.A_FORMAT, + funct5 + " 00sssss ttttt " + funct3 + " fffff 0101111"); + } +} diff --git a/src/rars/riscv/instructions/LR_W.java b/src/rars/riscv/instructions/LR_W.java new file mode 100644 index 00000000..be9e6196 --- /dev/null +++ b/src/rars/riscv/instructions/LR_W.java @@ -0,0 +1,29 @@ +package rars.riscv.instructions; + +import rars.Globals; +import rars.riscv.hardware.AddressErrorException; +import rars.ProgramStatement; +import rars.SimulationException; +import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.RegisterFile; +import rars.riscv.BasicInstruction; +import rars.riscv.BasicInstructionFormat; + +public class LR_W extends Atomic { + public LR_W() { + super("lr.w t1, (t2)", "Set t1 to contents of effective memory word address and reserve", "010", "00010"); + } + + public void simulate(ProgramStatement statement) throws SimulationException { + int[] operands = statement.getOperands(); + try { + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1]))); + } catch (AddressErrorException e) { + throw new SimulationException(statement, e); + } + } + + private long load(int address) throws AddressErrorException { + return Globals.memory.getWord(address); + } +} diff --git a/src/rars/riscv/instructions/SC_W.java b/src/rars/riscv/instructions/SC_W.java new file mode 100644 index 00000000..13d2ab77 --- /dev/null +++ b/src/rars/riscv/instructions/SC_W.java @@ -0,0 +1,33 @@ +package rars.riscv.instructions; + +import rars.Globals; +import rars.riscv.hardware.AddressErrorException; +import rars.ProgramStatement; +import rars.SimulationException; +import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.RegisterFile; +import rars.riscv.BasicInstruction; +import rars.riscv.BasicInstructionFormat; + +public class SC_W extends Atomic { + public SC_W() { + super("sc.w t1, (t2)", "Try to store t1 to contents of effective memory word address, sets t0 to store attempt result", "010", "00011"); + } + + public void simulate(ProgramStatement statement) throws SimulationException { + int[] operands = statement.getOperands(); + System.out.println(operands[0]); + System.out.println(operands[1]); + System.out.println(operands[2]); + operands[1] = (operands[1] << 20) >> 20; + try { + store(RegisterFile.getValue(0), RegisterFile.getValue(operands[0])); + } catch (AddressErrorException e) { + throw new SimulationException(statement, e); + } + } + + private void store(int address, long value) throws AddressErrorException { + Globals.memory.setWord(address, data); + } +} From 73633781e93a4dda0527c4a06a5ba9f32a8fc4b5 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 14 May 2021 23:41:10 -0600 Subject: [PATCH 03/84] fix sc.w instructions --- src/PseudoOps.txt | 4 ++-- src/rars/riscv/instructions/LR_W.java | 3 --- src/rars/riscv/instructions/SC_W.java | 17 ++++++----------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/PseudoOps.txt b/src/PseudoOps.txt index 8c5568bf..dcb8a6de 100644 --- a/src/PseudoOps.txt +++ b/src/PseudoOps.txt @@ -267,5 +267,5 @@ fgt.d t1, f2, f3 ;fle.d RG1, RG2, RG3 ;#Floating Greater Than (64 bit): if fge.d t1, f2, f3 ;flt.d RG1, RG2, RG3 ;#Floating Greater Than or Equal (64 bit): if f1 >= f2, set t1 to 1, else set t1 to 0 ######################### atomic pseudo-ops ########################## -lr.w t1,(t2) ;lw RG1,0(RG3) ;#Load Reserved Word : Set t1 to contents of effective memory word address and reserves memory word address -sc.w t1,t2,(t3) ;sw RG1,0(RG3) ;#Store Conditional Word : Tries to store t2 contents into effective memory word address and returns store result in t1 +lr.w t1,(t2) ;lr.w RG1,(RG3) ;#Load Reserved Word : Set t1 to contents of effective memory word address and reserves memory word address +sc.w t1,t2,(t3) ;sc.w RG1,RG2,(RG3) ;#Store Conditional Word : Tries to store t2 contents into effective memory word address and returns store result in t1 diff --git a/src/rars/riscv/instructions/LR_W.java b/src/rars/riscv/instructions/LR_W.java index be9e6196..57f91b30 100644 --- a/src/rars/riscv/instructions/LR_W.java +++ b/src/rars/riscv/instructions/LR_W.java @@ -4,10 +4,7 @@ import rars.riscv.hardware.AddressErrorException; import rars.ProgramStatement; import rars.SimulationException; -import rars.riscv.hardware.AddressErrorException; import rars.riscv.hardware.RegisterFile; -import rars.riscv.BasicInstruction; -import rars.riscv.BasicInstructionFormat; public class LR_W extends Atomic { public LR_W() { diff --git a/src/rars/riscv/instructions/SC_W.java b/src/rars/riscv/instructions/SC_W.java index 13d2ab77..143d8219 100644 --- a/src/rars/riscv/instructions/SC_W.java +++ b/src/rars/riscv/instructions/SC_W.java @@ -4,30 +4,25 @@ import rars.riscv.hardware.AddressErrorException; import rars.ProgramStatement; import rars.SimulationException; -import rars.riscv.hardware.AddressErrorException; import rars.riscv.hardware.RegisterFile; -import rars.riscv.BasicInstruction; -import rars.riscv.BasicInstructionFormat; public class SC_W extends Atomic { public SC_W() { - super("sc.w t1, (t2)", "Try to store t1 to contents of effective memory word address, sets t0 to store attempt result", "010", "00011"); + super("sc.w t0, t1, (t2)", "Try to store t1 to contents of effective memory word address, sets t0 to store attempt result", "010", "00011"); } public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); - System.out.println(operands[0]); - System.out.println(operands[1]); - System.out.println(operands[2]); - operands[1] = (operands[1] << 20) >> 20; try { - store(RegisterFile.getValue(0), RegisterFile.getValue(operands[0])); + int result = store(RegisterFile.getValue(operands[2]), RegisterFile.getValue(operands[1])); + RegisterFile.updateRegister(operands[0], result); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } - private void store(int address, long value) throws AddressErrorException { - Globals.memory.setWord(address, data); + private int store(int address, int value) throws AddressErrorException { + Globals.memory.setWord(address, value); + return 0; } } From fd13240c0d6cbcfeb2e9f60043c0c7d6f700e01a Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 25 May 2021 22:53:41 +0530 Subject: [PATCH 04/84] ReserveTable for 2 processors with shared memory --- src/rars/api/Program.java | 2 ++ src/rars/riscv/instructions/LR_W.java | 5 +++++ src/rars/riscv/instructions/SC_W.java | 9 +++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rars/api/Program.java b/src/rars/api/Program.java index f0b0f0db..a5c8b589 100644 --- a/src/rars/api/Program.java +++ b/src/rars/api/Program.java @@ -54,6 +54,7 @@ public Program() { public Program(Options set){ Globals.initialize(false); + ReserveTable.ResetReserve(); this.set = set; code = new RISCVprogram(); assembled = new Memory(); @@ -130,6 +131,7 @@ private ErrorList assemble(ArrayList programs) throws AssemblyExce */ public void setup(ArrayList args, String STDIN){ RegisterFile.resetRegisters(); + ReserveTable.ResetReserve(); FloatingPointRegisterFile.resetRegisters(); ControlAndStatusRegisterFile.resetRegisters(); InterruptController.reset(); diff --git a/src/rars/riscv/instructions/LR_W.java b/src/rars/riscv/instructions/LR_W.java index 57f91b30..849e2326 100644 --- a/src/rars/riscv/instructions/LR_W.java +++ b/src/rars/riscv/instructions/LR_W.java @@ -5,6 +5,8 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReserveTable; + public class LR_W extends Atomic { public LR_W() { @@ -21,6 +23,9 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private long load(int address) throws AddressErrorException { + // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt + + ReserveTable.lr_w1(address); return Globals.memory.getWord(address); } } diff --git a/src/rars/riscv/instructions/SC_W.java b/src/rars/riscv/instructions/SC_W.java index 143d8219..1157de44 100644 --- a/src/rars/riscv/instructions/SC_W.java +++ b/src/rars/riscv/instructions/SC_W.java @@ -5,6 +5,7 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReserveTable; public class SC_W extends Atomic { public SC_W() { @@ -22,7 +23,11 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private int store(int address, int value) throws AddressErrorException { - Globals.memory.setWord(address, value); - return 0; + // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt + if(ReserveTable.sc_w1(address)){ + Globals.memory.setWord(address, value); + return 0; + } + return -1; } } From 2514a831aca721995cd5f507311053fe4ef4e546 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 25 May 2021 23:16:58 +0530 Subject: [PATCH 05/84] macOS .DS_Store --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9b0d08dc..4df50ddf 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ examples/riscv # RARS build build/ rars.jar + +# macOS +.DS_Store From fcac4779c8e6976e9f80ccbd8e80a6f63946da2f Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 25 May 2021 22:53:41 +0530 Subject: [PATCH 06/84] ReserveTable for 2 processors with shared memory --- src/rars/api/Program.java | 2 ++ src/rars/riscv/instructions/LR_W.java | 5 +++++ src/rars/riscv/instructions/SC_W.java | 9 +++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rars/api/Program.java b/src/rars/api/Program.java index f0b0f0db..a5c8b589 100644 --- a/src/rars/api/Program.java +++ b/src/rars/api/Program.java @@ -54,6 +54,7 @@ public Program() { public Program(Options set){ Globals.initialize(false); + ReserveTable.ResetReserve(); this.set = set; code = new RISCVprogram(); assembled = new Memory(); @@ -130,6 +131,7 @@ private ErrorList assemble(ArrayList programs) throws AssemblyExce */ public void setup(ArrayList args, String STDIN){ RegisterFile.resetRegisters(); + ReserveTable.ResetReserve(); FloatingPointRegisterFile.resetRegisters(); ControlAndStatusRegisterFile.resetRegisters(); InterruptController.reset(); diff --git a/src/rars/riscv/instructions/LR_W.java b/src/rars/riscv/instructions/LR_W.java index 57f91b30..849e2326 100644 --- a/src/rars/riscv/instructions/LR_W.java +++ b/src/rars/riscv/instructions/LR_W.java @@ -5,6 +5,8 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReserveTable; + public class LR_W extends Atomic { public LR_W() { @@ -21,6 +23,9 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private long load(int address) throws AddressErrorException { + // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt + + ReserveTable.lr_w1(address); return Globals.memory.getWord(address); } } diff --git a/src/rars/riscv/instructions/SC_W.java b/src/rars/riscv/instructions/SC_W.java index 143d8219..1157de44 100644 --- a/src/rars/riscv/instructions/SC_W.java +++ b/src/rars/riscv/instructions/SC_W.java @@ -5,6 +5,7 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReserveTable; public class SC_W extends Atomic { public SC_W() { @@ -22,7 +23,11 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private int store(int address, int value) throws AddressErrorException { - Globals.memory.setWord(address, value); - return 0; + // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt + if(ReserveTable.sc_w1(address)){ + Globals.memory.setWord(address, value); + return 0; + } + return -1; } } From e9022e0f0e13ceb1184aa3ded65e7d58c5edef8f Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 25 May 2021 23:26:34 +0530 Subject: [PATCH 07/84] Reserve Table --- src/rars/riscv/hardware/ReserveTable.java | 93 +++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/rars/riscv/hardware/ReserveTable.java diff --git a/src/rars/riscv/hardware/ReserveTable.java b/src/rars/riscv/hardware/ReserveTable.java new file mode 100644 index 00000000..6ef829dd --- /dev/null +++ b/src/rars/riscv/hardware/ReserveTable.java @@ -0,0 +1,93 @@ +package rars.riscv.hardware; + +import java.util.ArrayList; + +/* +Copyright (c) 2021, Siva Chowdeswar Nandipati. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class ReserveTable{ + public static ArrayList proc1 = new ArrayList(); + public static ArrayList proc2 = new ArrayList(); + public static ArrayList bool = new ArrayList(); + + public static void ResetReserve(){ + proc1.clear(); + proc2.clear(); + bool.clear(); + } + public static void addproc1(int address){ + proc1.add(Integer.valueOf(address)); + } + public static void addproc2(int address){ + proc1.add(Integer.valueOf(address)); + } + public static void addbool(int address){ + bool.add(Integer.valueOf(address)); + } + public static void lr_w1(int address){ + if(proc1.contains(Integer.valueOf(address))) + return; + addproc1(address); + } + public static void lr_w2(int address){ + if(proc2.contains(Integer.valueOf(address))) + return; + addproc2(address); + } + public static boolean sc_w1(int address){ + if(!proc1.contains(Integer.valueOf(address))){ + return false; // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt + } + if(bool.contains(Integer.valueOf(address))){ + proc1.remove(Integer.valueOf(address)); + bool.remove(Integer.valueOf(address)); + return false; + } + if(!proc2.contains(Integer.valueOf(address))){ + proc1.remove(Integer.valueOf(address)); + return true; + } + proc1.remove(Integer.valueOf(address)); + addbool(address); + return true; + } + public static boolean sc_w2(int address){ + if(!proc2.contains(Integer.valueOf(address))){ + return false; // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt + } + if(bool.contains(Integer.valueOf(address))){ + proc2.remove(Integer.valueOf(address)); + bool.remove(Integer.valueOf(address)); + return false; + } + if(!proc1.contains(Integer.valueOf(address))){ + proc2.remove(Integer.valueOf(address)); + return true; + } + proc2.remove(Integer.valueOf(address)); + addbool(address); + return true; + } +} \ No newline at end of file From e81c2532ea0849ce778a9346652eba2c4091404f Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Thu, 27 May 2021 21:51:43 +0530 Subject: [PATCH 08/84] General Reserve Table --- src/rars/riscv/hardware/ReserveTable.java | 78 ++++++++++------------- 1 file changed, 32 insertions(+), 46 deletions(-) diff --git a/src/rars/riscv/hardware/ReserveTable.java b/src/rars/riscv/hardware/ReserveTable.java index 6ef829dd..be0386e4 100644 --- a/src/rars/riscv/hardware/ReserveTable.java +++ b/src/rars/riscv/hardware/ReserveTable.java @@ -28,66 +28,52 @@ a copy of this software and associated documentation files (the */ public class ReserveTable{ - public static ArrayList proc1 = new ArrayList(); - public static ArrayList proc2 = new ArrayList(); - public static ArrayList bool = new ArrayList(); - + //0 represents Stored value;; + public static ArrayList arrrayProc = new ArrayList(); + public static int procs = 0; public static void ResetReserve(){ - proc1.clear(); - proc2.clear(); - bool.clear(); - } - public static void addproc1(int address){ - proc1.add(Integer.valueOf(address)); + arrayProc = new ArrayList(); } - public static void addproc2(int address){ - proc1.add(Integer.valueOf(address)); + + public static void addproc(int address, int processor){ + arrrayProc.get(processor).get(1).add(Integer.valueOf(address)); } + public static void addbool(int address){ - bool.add(Integer.valueOf(address)); + arrrayProc.get(processor).get(0).add(Integer.valueOf(address)); } - public static void lr_w1(int address){ - if(proc1.contains(Integer.valueOf(address))) + + public static void lr_w(int address, int processor){ + if(arrrayProc.get(processor).get(1).contains(Integer.valueOf(address))) return; - addproc1(address); + addproc(address, processor); } - public static void lr_w2(int address){ - if(proc2.contains(Integer.valueOf(address))) + + private static void addToRest(int address, int processor){ + if(procs = 0) return; - addproc2(address); - } - public static boolean sc_w1(int address){ - if(!proc1.contains(Integer.valueOf(address))){ - return false; // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt + for(int i = 0; i <= processor; i++){ + if(i == processor) + continue; + if(arrrayProc.get(i).get(1).contains(address)){ + arrrayProc.get(i).get(0).add(address) + } } - if(bool.contains(Integer.valueOf(address))){ - proc1.remove(Integer.valueOf(address)); - bool.remove(Integer.valueOf(address)); - return false; - } - if(!proc2.contains(Integer.valueOf(address))){ - proc1.remove(Integer.valueOf(address)); - return true; - } - proc1.remove(Integer.valueOf(address)); - addbool(address); - return true; } - public static boolean sc_w2(int address){ - if(!proc2.contains(Integer.valueOf(address))){ + + public static boolean sc_w(int address, int processor){ + if(!arrrayProc.get(processor).get(1).contains(Integer.valueOf(address))){ return false; // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt } - if(bool.contains(Integer.valueOf(address))){ - proc2.remove(Integer.valueOf(address)); - bool.remove(Integer.valueOf(address)); + if(arrrayProc.get(processor).get(0).contains(Integer.valueOf(address))){ + arrrayProc.get(processor).get(1).remove(Integer.valueOf(address)); + arrrayProc.get(processor).get(0).remove(Integer.valueOf(address)); return false; } - if(!proc1.contains(Integer.valueOf(address))){ - proc2.remove(Integer.valueOf(address)); - return true; - } - proc2.remove(Integer.valueOf(address)); - addbool(address); + addToRest(address, processor); return true; } + public static setProcs(int procces){ + procs = procces; + } } \ No newline at end of file From d37dcf555e8564077b8f6f840cbc147f254550cc Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Thu, 27 May 2021 23:20:51 +0530 Subject: [PATCH 09/84] General Reserve Table 27 May --- src/rars/riscv/hardware/ReserveTable.java | 35 +++++++---------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/rars/riscv/hardware/ReserveTable.java b/src/rars/riscv/hardware/ReserveTable.java index be0386e4..8c012d99 100644 --- a/src/rars/riscv/hardware/ReserveTable.java +++ b/src/rars/riscv/hardware/ReserveTable.java @@ -29,48 +29,33 @@ a copy of this software and associated documentation files (the public class ReserveTable{ //0 represents Stored value;; - public static ArrayList arrrayProc = new ArrayList(); + public static ArrayList arrrayProc = new ArrayList();//Reserve Table for public static int procs = 0; + public static ArrayList oldestReserve = new ArrayList() public static void ResetReserve(){ arrayProc = new ArrayList(); } public static void addproc(int address, int processor){ - arrrayProc.get(processor).get(1).add(Integer.valueOf(address)); - } - public static void addbool(int address){ - arrrayProc.get(processor).get(0).add(Integer.valueOf(address)); + arrrayProc.get(processor).add(Integer.valueOf(address)); } public static void lr_w(int address, int processor){ - if(arrrayProc.get(processor).get(1).contains(Integer.valueOf(address))) + if(arrrayProc.get(processor).contains(Integer.valueOf(address))) return; addproc(address, processor); } - private static void addToRest(int address, int processor){ - if(procs = 0) - return; - for(int i = 0; i <= processor; i++){ - if(i == processor) - continue; - if(arrrayProc.get(i).get(1).contains(address)){ - arrrayProc.get(i).get(0).add(address) - } - } - } - public static boolean sc_w(int address, int processor){ - if(!arrrayProc.get(processor).get(1).contains(Integer.valueOf(address))){ - return false; // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt - } - if(arrrayProc.get(processor).get(0).contains(Integer.valueOf(address))){ - arrrayProc.get(processor).get(1).remove(Integer.valueOf(address)); - arrrayProc.get(processor).get(0).remove(Integer.valueOf(address)); + if(!arrrayProc.get(processor).contains(Integer.valueOf(address))){ return false; } - addToRest(address, processor); + for(int i = 0; i < procs; i++){ + if(arrrayProc.get(i).contains(address)){ + arrrayProc.remove(Integer.valueOf(address)); + } + } return true; } public static setProcs(int procces){ From 7ea28ab132a15df7a4c9dbdaea32d69cf6ae5461 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 27 May 2021 19:06:19 -0600 Subject: [PATCH 10/84] reservation table and tables --- src/rars/riscv/hardware/ReservationTable.java | 59 ++++++++++++++ .../riscv/hardware/ReservationTables.java | 58 ++++++++++++++ src/rars/riscv/hardware/ReserveTable.java | 79 ------------------- 3 files changed, 117 insertions(+), 79 deletions(-) create mode 100644 src/rars/riscv/hardware/ReservationTable.java create mode 100644 src/rars/riscv/hardware/ReservationTables.java delete mode 100644 src/rars/riscv/hardware/ReserveTable.java diff --git a/src/rars/riscv/hardware/ReservationTable.java b/src/rars/riscv/hardware/ReservationTable.java new file mode 100644 index 00000000..cf90b082 --- /dev/null +++ b/src/rars/riscv/hardware/ReservationTable.java @@ -0,0 +1,59 @@ +package rars.riscv.hardware; + +import java.util.ArrayList; + +/* +Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class ReservationTable { + private ArrayList table; + public final static int capacity = 8; + + public ReservationTable() { + table = new ArrayList(); + } + + public void reserveAddress(int address) { + if (table.size() == capacity) + table.remove(0); + table.add(Integer.valueOf(address)); + } + + public void unreserveAddress(int address) { + table.removeIf(val -> val == address); + } + + public boolean contains(int address) { + return table.contains(Integer.valueOf(address)); + } + + public Integer[] getAddresses() { + Integer[] addresses = new Integer[table.size()]; + for (int i = 0; i < addresses.length; i++) { + addresses[i] = table.get(i); + } + return addresses; + } +} diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java new file mode 100644 index 00000000..a1cfff28 --- /dev/null +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -0,0 +1,58 @@ +package rars.riscv.hardware; + +/* +Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class ReservationTables { + private ReservationTable[] reservationTables; + + public ReservationTables(int processors) { + reservationTables = new ReservationTable[processors]; + } + + public void reserveAddress(int processor, int address) { + reservationTables[processor].reserveAddress(address); + } + + public boolean unreserveAddress(int processor, int address) { + if (reservationTables[processor].contains(address)) { + for (ReservationTable reservationTable : reservationTables) { + reservationTable.unreserveAddress(address); + } + return true; + } + return false; + } + + public Integer[][] allAddresses() { + Integer[][] all = new Integer[reservationTables.length][ReservationTable.capacity]; + for (int i = 0; i < reservationTables.length; i++) { + for (int j = 0; j < ReservationTable.capacity; j++) { + all[i] = reservationTables[i].getAddresses(); + } + } + return all; + } +} diff --git a/src/rars/riscv/hardware/ReserveTable.java b/src/rars/riscv/hardware/ReserveTable.java deleted file mode 100644 index be0386e4..00000000 --- a/src/rars/riscv/hardware/ReserveTable.java +++ /dev/null @@ -1,79 +0,0 @@ -package rars.riscv.hardware; - -import java.util.ArrayList; - -/* -Copyright (c) 2021, Siva Chowdeswar Nandipati. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject -to the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF -CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -(MIT license, http://www.opensource.org/licenses/mit-license.html) - */ - -public class ReserveTable{ - //0 represents Stored value;; - public static ArrayList arrrayProc = new ArrayList(); - public static int procs = 0; - public static void ResetReserve(){ - arrayProc = new ArrayList(); - } - - public static void addproc(int address, int processor){ - arrrayProc.get(processor).get(1).add(Integer.valueOf(address)); - } - - public static void addbool(int address){ - arrrayProc.get(processor).get(0).add(Integer.valueOf(address)); - } - - public static void lr_w(int address, int processor){ - if(arrrayProc.get(processor).get(1).contains(Integer.valueOf(address))) - return; - addproc(address, processor); - } - - private static void addToRest(int address, int processor){ - if(procs = 0) - return; - for(int i = 0; i <= processor; i++){ - if(i == processor) - continue; - if(arrrayProc.get(i).get(1).contains(address)){ - arrrayProc.get(i).get(0).add(address) - } - } - } - - public static boolean sc_w(int address, int processor){ - if(!arrrayProc.get(processor).get(1).contains(Integer.valueOf(address))){ - return false; // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt - } - if(arrrayProc.get(processor).get(0).contains(Integer.valueOf(address))){ - arrrayProc.get(processor).get(1).remove(Integer.valueOf(address)); - arrrayProc.get(processor).get(0).remove(Integer.valueOf(address)); - return false; - } - addToRest(address, processor); - return true; - } - public static setProcs(int procces){ - procs = procces; - } -} \ No newline at end of file From 37680f5cd85bef7ea077699d68d75534938dd67a Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Fri, 28 May 2021 10:25:02 +0530 Subject: [PATCH 11/84] Small change --- src/rars/riscv/hardware/ReservationTable.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rars/riscv/hardware/ReservationTable.java b/src/rars/riscv/hardware/ReservationTable.java index cf90b082..ed771da8 100644 --- a/src/rars/riscv/hardware/ReservationTable.java +++ b/src/rars/riscv/hardware/ReservationTable.java @@ -36,6 +36,8 @@ public ReservationTable() { } public void reserveAddress(int address) { + if(table.contains(Integer.valueOf(address))) + return; if (table.size() == capacity) table.remove(0); table.add(Integer.valueOf(address)); From 815f798a0903d5b37f7f0bcd18a76869369dd0e4 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 28 May 2021 02:41:34 -0600 Subject: [PATCH 12/84] basic tool --- src/rars/tools/ReservationTablesTool.java | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/rars/tools/ReservationTablesTool.java diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java new file mode 100644 index 00000000..dd079344 --- /dev/null +++ b/src/rars/tools/ReservationTablesTool.java @@ -0,0 +1,51 @@ +package rars.tools; + +import javax.swing.JComponent; +import javax.swing.JPanel; +import java.awt.GridLayout; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura. + +Developed by Giancarlo Pernudi Segura (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class ReservationTablesTool extends AbstractToolAndApplication { + private static String heading = "Reservation Table Tool"; + private static String version = "Version 1.0"; + + public ReservationTablesTool() { + super(heading + ", " + version, heading); + } + + protected JComponent buildMainDisplayArea() { + JPanel panelTools = new JPanel(new GridLayout(1, 2)); + return panelTools; + } + + @Override + public String getName() { + return heading; + } +} From f555edb5f4de364fec27e03a522d42568ff124b0 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Fri, 28 May 2021 22:07:47 +0530 Subject: [PATCH 13/84] 28 May --- src/images/Shared.png | Bin 0 -> 3124 bytes src/rars/api/Program.java | 2 -- src/rars/riscv/instructions/LR_W.java | 4 +--- src/rars/riscv/instructions/SC_W.java | 6 +----- 4 files changed, 2 insertions(+), 10 deletions(-) create mode 100644 src/images/Shared.png diff --git a/src/images/Shared.png b/src/images/Shared.png new file mode 100644 index 0000000000000000000000000000000000000000..320a5b1bef0ad16a7b438b6b5a21a823b532e942 GIT binary patch literal 3124 zcmZ`+2|Sc*7k}-HU1Uiag9tN&WEo5`*2+wH49&Fn9=v@MFH;M;rY+EaEFkhhC=Ok zXj!yf*LFo&|BBbC(2{za683nd55wDLH~tdmS$S}{t|hA}ptXPMNIag zld5aZv;wQDR26jb$y{B}ODYvXZjTz~j~a%mq-QHosuq^!R4u)-HCX z%EpW(`990u4C>#B8+WjFlP%QNo%frqMx&j-(mbT$Bv5`}_qYKL;KXe4`@ zs4A7G?NBF^xt8QMUD&xuZzj|AkKFnF5TxIvPpcx&O72N({HK`vCNBc0lkwJ<>(rt| zXV{uHuPGCAW-ka8*)L3ylkdTBbzMTcmi8&gF>Qh^Z8y19sp=_%FycYEx7~LmN@0){!5O2T0L)* zKQz7E>&qIo3dQ0OhM4G^`u-#yB=8-V*Y>PmZ}fH`Qx7ne~{Z=uwf>qD_`e)@wH; zRqXnuzGLkPVXws0&g?PH01M(GUC-Ps14+^SZqRT0-S{v@do|N>=;IF1Xy?DvyFwpP zGb-Jcdox_#vF2wl_mD3-%&#J3n8!C*ZdBa@Zjl-PK^l^^pe8AM6P&5ocN(3B9zh%z zIMR~?A)((r7#R&?k+Ut*PJNh44>j!G!J@Cz>W8|H7ikMk3{4CLJkA~`cp#z(j;SrC z4n-|bNy}t;tdu{L-1~gAfH<_<;kh(k?YX4w!neZ}%@(sV>Ckv&MRULb6xAH$N;P|D zV1-8BhT7x3>TZ@eA92`bmFWkf9#C4iv7D}-7qL7GQRAsFAUD7K;W!=-+qjsh_oQjd9^J|CMtO)Z7au!D=A&G%4 z;R&xdO3y`~FnE6Nd^c$wug~Ef=^3es6g}Dz94|SO`p2nP>!ZZw+J1q#G+aS_L*Cyh zoqY@Q-k^IL%6s`1+lrM|n&~alBc%cj*ZdZN>Ie;;jv$MjFXEG7w=tw5PMyz+dRs2{ zbp>gaY{Q@Y`n6)Q^Q~(@C9;&VX-iS0de5-xjKz1hJ6cN(RmiMtxKaoT)4)VztHqHIyb<@|G6$M58SL+pwV3q>Lb90cr_O}RyXKiN1W&NJGYJ3$ zy_l2b&e1X)0I=%d?3~C>mM0NDL4hzYbdWa&MhOgNvH*Pwf}sXt$X;MdAf7-%Pz)en z5eSCPG{Yg_uMl#80mRAD28;?KV!&E3HJBO%2?B$``b4xZ!q(XIJDu@l0P!P}gAs6e zXlN)b^e`-lh=r@`>gvMPG~gNnNOc|kuUY=(_*v&KM5mub4Xs~^zc_v&GV4HC6LA(rkf(-L;$>A>=l_%3^#TJ--=r_&}K+O`|Hn`*_w?&ppXwXP)Kq z5lN(sC*okScN5FYNl0DcxCCC8So5Bd!Du}z_1MPN_&LEDpLa{1)w^Tj6OTf8H^RTX zDkV+V4=kWrN>o#|$UGm{d6V}co^xK1Re?6jv^TgdhOx+7yl3wfPnno>GsV{KyELg? z(?0IQugJIX2`Qgb;p}-JF1cj4N8#7A#$E6zr~*^94WTYb+ig6dRLm77xN zuWY9G@^v)OBffj2mJ=vpave_veY9&j?ta+Qa?9RP; z(YTLqp>6m&Nb*ohLgcjR0KRRQ*UmA%b-3EIceZt_sEvx=jua~Tvm!9i5aN0zxbtlB z#%)@&`ao1&>P*gxgp5s1{bFLJ8C2|J$_0oU`JH9SP{#`{70PRV-r(};@jB5|8r7+a z_u`Vp`f&w(%%(2n4=#KAQ&Z34-w*yqZ`}r&CSh`nOm;I;3JtS!mEJh-3SZ>lCL4|3 z=&_6I9iHUQ?3az0e`3RiQ0x%s3y_K7?%HyjcmxMK!a6T6C&Q{bb6ex+6dsY5DpQ3V zWA7yA(R~U^#5m2Umz7|tBdG2}(Qtdbw9b*M;^G+wN^;XTJ0EY$T59q0zY}vi_)hEy>l6Xb$La zSUzRzg_jbX*Enp*`w8Xyg>x*u--EBp%#YaJ=Fc4HloZBx^6DiAXVVN1$}g-hoAT55 zy9MP|&s*FXeKhyi?$Rpk;c<@e2))`0UWw(;+*v-jUY9~FHIdLekYsWyyf6PG&mPWn z&Egg1)y|&9vhLyE?bc6waVa@^ogMN2h%EGx6wT%eSlCvy%j%ES5E)Z8Et0%28C=us z&~Y#HZ;2PSHTM-qIc|mR%`d-T`PNE};wTf5qK^kDZN67B4RXWc+U_6U&!-(OOPO{x7WtcWS65_>FBK z{8Mv>P{9%vgmp}gWHphNS3l`LCWRGWRPIAB%09+xsHm_%QOmdLJhvm(hJut#mBC$v zRoHc33sK5?HfLpc?+gyzw6dA7Z@MW*4?nxNRP1O;s7L;=h1qG+er;L;e`NZ6glF{r zsRiAlnB_5=)>T^1-DhV=Q3g{h2!YG-Gn!WYD~@vp?ReCaN{NQi^J7ijlj|C3SE75p z%|{>)C#xYN6-$StceS@dL{3OHea1qBdI}Ea%{`TONgmL_eW($~^Efjzr}M=}%lUEY`yDGy~>; O0bpTbWn5)+Chk9du~w7- literal 0 HcmV?d00001 diff --git a/src/rars/api/Program.java b/src/rars/api/Program.java index a5c8b589..f0b0f0db 100644 --- a/src/rars/api/Program.java +++ b/src/rars/api/Program.java @@ -54,7 +54,6 @@ public Program() { public Program(Options set){ Globals.initialize(false); - ReserveTable.ResetReserve(); this.set = set; code = new RISCVprogram(); assembled = new Memory(); @@ -131,7 +130,6 @@ private ErrorList assemble(ArrayList programs) throws AssemblyExce */ public void setup(ArrayList args, String STDIN){ RegisterFile.resetRegisters(); - ReserveTable.ResetReserve(); FloatingPointRegisterFile.resetRegisters(); ControlAndStatusRegisterFile.resetRegisters(); InterruptController.reset(); diff --git a/src/rars/riscv/instructions/LR_W.java b/src/rars/riscv/instructions/LR_W.java index 849e2326..95717e9a 100644 --- a/src/rars/riscv/instructions/LR_W.java +++ b/src/rars/riscv/instructions/LR_W.java @@ -5,7 +5,7 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; -import rars.riscv.hardware.ReserveTable; +import rars.riscv.hardware.ReservationTable; public class LR_W extends Atomic { @@ -23,9 +23,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private long load(int address) throws AddressErrorException { - // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt - ReserveTable.lr_w1(address); return Globals.memory.getWord(address); } } diff --git a/src/rars/riscv/instructions/SC_W.java b/src/rars/riscv/instructions/SC_W.java index 1157de44..5248fd41 100644 --- a/src/rars/riscv/instructions/SC_W.java +++ b/src/rars/riscv/instructions/SC_W.java @@ -5,7 +5,7 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; -import rars.riscv.hardware.ReserveTable; +import rars.riscv.hardware.ReservationTable; public class SC_W extends Atomic { public SC_W() { @@ -23,11 +23,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private int store(int address, int value) throws AddressErrorException { - // -------------------------------------------------> Doubt Doubt Doubt Doubt Doubt Doubt Doubt Doubt - if(ReserveTable.sc_w1(address)){ Globals.memory.setWord(address, value); return 0; - } - return -1; } } From c8bdb742ad8873c344ae0519d2a98aae7688e045 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Fri, 28 May 2021 22:32:57 +0530 Subject: [PATCH 14/84] 28 May --- src/rars/riscv/hardware/ReservationTables.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index a1cfff28..b860c72d 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -27,8 +27,13 @@ a copy of this software and associated documentation files (the public class ReservationTables { private ReservationTable[] reservationTables; - + private int processors; public ReservationTables(int processors) { + this.processors = processors; + reset(); + } + + public void reset(){ reservationTables = new ReservationTable[processors]; } From a6000a0093db6e765b3b9dd9eb409e8fc909f55e Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 28 May 2021 17:54:55 -0600 Subject: [PATCH 15/84] integrate reservation table with lr.w and sc.w --- src/rars/Globals.java | 8 +++++++- src/rars/api/Program.java | 1 + src/rars/riscv/hardware/ReservationTables.java | 3 +++ src/rars/riscv/instructions/LR_W.java | 3 +-- src/rars/riscv/instructions/SC_W.java | 4 +++- src/rars/tools/ReservationTablesTool.java | 5 ++++- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index 1696930d..4dbaf00d 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -2,6 +2,7 @@ import rars.assembler.SymbolTable; import rars.riscv.hardware.Memory; +import rars.riscv.hardware.ReservationTables; import rars.riscv.InstructionSet; import rars.riscv.SyscallNumberOverride; import rars.util.PropertiesFile; @@ -68,6 +69,10 @@ public class Globals { * Simulated memory component. **/ public static Memory memory; + /** + * Simulated reservation tables component. + **/ + public static ReservationTables reservationTables; /** * Lock variable used at head of synchronized block to guard memory and registers **/ @@ -166,7 +171,8 @@ public static Settings getSettings() { public static void initialize(boolean gui) { if (!initialized) { - memory = Memory.getInstance(); //clients can use Memory.getInstance instead of Globals.memory + memory = Memory.getInstance(); //clients can use Memory.getInstance instead of Globals.memory + reservationTables = new ReservationTables(1); symbolTable = new SymbolTable("global"); settings = new Settings(gui); instructionSet = new InstructionSet(); diff --git a/src/rars/api/Program.java b/src/rars/api/Program.java index f0b0f0db..26897876 100644 --- a/src/rars/api/Program.java +++ b/src/rars/api/Program.java @@ -130,6 +130,7 @@ private ErrorList assemble(ArrayList programs) throws AssemblyExce */ public void setup(ArrayList args, String STDIN){ RegisterFile.resetRegisters(); + Globals.reservationTables.reset(); FloatingPointRegisterFile.resetRegisters(); ControlAndStatusRegisterFile.resetRegisters(); InterruptController.reset(); diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index b860c72d..6b7a3cd2 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -35,6 +35,9 @@ public ReservationTables(int processors) { public void reset(){ reservationTables = new ReservationTable[processors]; + for (int i = 0; i < reservationTables.length; i++) { + reservationTables[i] = new ReservationTable(); + } } public void reserveAddress(int processor, int address) { diff --git a/src/rars/riscv/instructions/LR_W.java b/src/rars/riscv/instructions/LR_W.java index 95717e9a..98aafd4d 100644 --- a/src/rars/riscv/instructions/LR_W.java +++ b/src/rars/riscv/instructions/LR_W.java @@ -5,7 +5,6 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; -import rars.riscv.hardware.ReservationTable; public class LR_W extends Atomic { @@ -23,7 +22,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private long load(int address) throws AddressErrorException { - + Globals.reservationTables.reserveAddress(0, address); return Globals.memory.getWord(address); } } diff --git a/src/rars/riscv/instructions/SC_W.java b/src/rars/riscv/instructions/SC_W.java index 5248fd41..8e6d8952 100644 --- a/src/rars/riscv/instructions/SC_W.java +++ b/src/rars/riscv/instructions/SC_W.java @@ -5,7 +5,6 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; -import rars.riscv.hardware.ReservationTable; public class SC_W extends Atomic { public SC_W() { @@ -23,7 +22,10 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private int store(int address, int value) throws AddressErrorException { + if (Globals.reservationTables.unreserveAddress(0, address)) { Globals.memory.setWord(address, value); return 0; + } + return -1; } } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index dd079344..a5358116 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -3,6 +3,7 @@ import javax.swing.JComponent; import javax.swing.JPanel; import java.awt.GridLayout; +import javax.swing.JTable; /* Copyright (c) 2021, Giancarlo Pernudi Segura. @@ -40,7 +41,9 @@ public ReservationTablesTool() { } protected JComponent buildMainDisplayArea() { - JPanel panelTools = new JPanel(new GridLayout(1, 2)); + JPanel panelTools = new JPanel(new GridLayout(2, 1)); + JTable reservations = new JTable(); + panelTools.add(reservations); return panelTools; } From f2911f927981d95351eb6049bf9850cdbc7b8a90 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 28 May 2021 22:15:28 -0600 Subject: [PATCH 16/84] show reservation table and help --- src/rars/riscv/hardware/ReservationTable.java | 10 ++-- .../riscv/hardware/ReservationTables.java | 37 ++++++++++++--- src/rars/tools/ReservationTablesTool.java | 47 ++++++++++++++++++- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/src/rars/riscv/hardware/ReservationTable.java b/src/rars/riscv/hardware/ReservationTable.java index ed771da8..f7524c9c 100644 --- a/src/rars/riscv/hardware/ReservationTable.java +++ b/src/rars/riscv/hardware/ReservationTable.java @@ -52,9 +52,13 @@ public boolean contains(int address) { } public Integer[] getAddresses() { - Integer[] addresses = new Integer[table.size()]; - for (int i = 0; i < addresses.length; i++) { - addresses[i] = table.get(i); + Integer[] addresses = new Integer[capacity]; + for (int i = 0; i < capacity; i++) { + try { + addresses[i] = table.get(i); + } catch (IndexOutOfBoundsException e) { + addresses[i] = 0; + } } return addresses; } diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index 6b7a3cd2..f8b430b7 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -1,5 +1,10 @@ package rars.riscv.hardware; +import java.util.Collection; +import java.util.Observable; +import java.util.Observer; +import java.util.Vector; + /* Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura. @@ -27,13 +32,15 @@ a copy of this software and associated documentation files (the public class ReservationTables { private ReservationTable[] reservationTables; - private int processors; + public int processors; + private Collection observables = new Vector<>(); + public ReservationTables(int processors) { this.processors = processors; reset(); } - public void reset(){ + public void reset() { reservationTables = new ReservationTable[processors]; for (int i = 0; i < reservationTables.length; i++) { reservationTables[i] = new ReservationTable(); @@ -54,13 +61,29 @@ public boolean unreserveAddress(int processor, int address) { return false; } - public Integer[][] allAddresses() { - Integer[][] all = new Integer[reservationTables.length][ReservationTable.capacity]; - for (int i = 0; i < reservationTables.length; i++) { - for (int j = 0; j < ReservationTable.capacity; j++) { - all[i] = reservationTables[i].getAddresses(); + public Integer[][] getAllAddresses() { + Integer[][] all = new Integer[ReservationTable.capacity][processors]; + for (int i = 0; i < ReservationTable.capacity; i++) { + for (int j = 0; j < processors; j++) { + Integer[] addresses = reservationTables[j].getAddresses(); + all[i][j] = addresses[j]; } } return all; } + + public void addObserver(Observer obs) { + observables.add(new ReservationTablesObservable(obs)); + } + + private class ReservationTablesObservable extends Observable { + public ReservationTablesObservable(Observer obs) { + this.addObserver(obs); + } + + public void notifyObserver(MemoryAccessNotice notice) { + this.setChanged(); + this.notifyObservers(notice); + } + } } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index a5358116..5aec0f02 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -1,9 +1,13 @@ package rars.tools; +import java.awt.GridLayout; +import javax.swing.JButton; import javax.swing.JComponent; +import javax.swing.JOptionPane; import javax.swing.JPanel; -import java.awt.GridLayout; import javax.swing.JTable; +import rars.venus.NumberDisplayBaseChooser; +import rars.Globals; /* Copyright (c) 2021, Giancarlo Pernudi Segura. @@ -36,13 +40,20 @@ public class ReservationTablesTool extends AbstractToolAndApplication { private static String heading = "Reservation Table Tool"; private static String version = "Version 1.0"; + private String[][] addressStrings; + public ReservationTablesTool() { super(heading + ", " + version, heading); } protected JComponent buildMainDisplayArea() { JPanel panelTools = new JPanel(new GridLayout(2, 1)); - JTable reservations = new JTable(); + String[] columns = new String[Globals.reservationTables.processors]; + for (int i = 0; i < columns.length; i++) { + columns[i] = String.format("Processor %d", i); + } + updateDisplay(); + JTable reservations = new JTable(addressStrings, columns); panelTools.add(reservations); return panelTools; } @@ -51,4 +62,36 @@ protected JComponent buildMainDisplayArea() { public String getName() { return heading; } + + protected JComponent getHelpComponent() { + final String helpContent = "Use this tool to simulate atomic operations such as store conditional.\n" + + "While this tool is connected to the program, the table below shows the\n" + + "reservation table for each processor. Addresses reserved by a processor\n" + + "will appear under that processor's column. You can release an address, \n" + + "which will release that address across all the processor's tables in\n" + + "order to simulate some other processor performing a store conditional.\n" + + "(contributed by Giancarlo Pernudi Segura, pernudi@ualberta.ca)"; + JButton help = new JButton("Help"); + help.addActionListener(l -> { + JOptionPane.showMessageDialog(theWindow, helpContent); + }); + return help; + } + + @Override + protected void updateDisplay() { + Integer[][] addresses = Globals.reservationTables.getAllAddresses(); + addressStrings = new String[addresses.length][addresses[0].length]; + for (int i = 0; i < addressStrings.length; i++) { + for (int j = 0; j < addressStrings[i].length; j++) { + addressStrings[i][j] = NumberDisplayBaseChooser.formatNumber(addresses[i][j], 16); + } + } + } + + @Override + protected void reset() { + Globals.reservationTables.reset(); + updateDisplay(); + } } From af791d77133fef05c8f2b09e53c913515428c50c Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 28 May 2021 23:01:31 -0600 Subject: [PATCH 17/84] fix duplication of first cell --- .../riscv/hardware/ReservationTables.java | 2 +- src/rars/tools/ReservationTablesTool.java | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index f8b430b7..78a4f2a9 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -66,7 +66,7 @@ public Integer[][] getAllAddresses() { for (int i = 0; i < ReservationTable.capacity; i++) { for (int j = 0; j < processors; j++) { Integer[] addresses = reservationTables[j].getAddresses(); - all[i][j] = addresses[j]; + all[i][j] = addresses[i]; } } return all; diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 5aec0f02..0d2a3fcb 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -8,6 +8,7 @@ import javax.swing.JTable; import rars.venus.NumberDisplayBaseChooser; import rars.Globals; +import rars.riscv.hardware.ReservationTable; /* Copyright (c) 2021, Giancarlo Pernudi Segura. @@ -40,7 +41,7 @@ public class ReservationTablesTool extends AbstractToolAndApplication { private static String heading = "Reservation Table Tool"; private static String version = "Version 1.0"; - private String[][] addressStrings; + JTable reservations; public ReservationTablesTool() { super(heading + ", " + version, heading); @@ -48,12 +49,12 @@ public ReservationTablesTool() { protected JComponent buildMainDisplayArea() { JPanel panelTools = new JPanel(new GridLayout(2, 1)); - String[] columns = new String[Globals.reservationTables.processors]; - for (int i = 0; i < columns.length; i++) { - columns[i] = String.format("Processor %d", i); - } + reservations = new JTable(ReservationTable.capacity, Globals.reservationTables.processors); + // String[] columns = new String[Globals.reservationTables.processors]; + // for (int i = 0; i < columns.length; i++) { + // columns[i] = String.format("Processor %d", i); + // } updateDisplay(); - JTable reservations = new JTable(addressStrings, columns); panelTools.add(reservations); return panelTools; } @@ -81,10 +82,10 @@ protected JComponent getHelpComponent() { @Override protected void updateDisplay() { Integer[][] addresses = Globals.reservationTables.getAllAddresses(); - addressStrings = new String[addresses.length][addresses[0].length]; - for (int i = 0; i < addressStrings.length; i++) { - for (int j = 0; j < addressStrings[i].length; j++) { - addressStrings[i][j] = NumberDisplayBaseChooser.formatNumber(addresses[i][j], 16); + for (int i = 0; i < addresses.length; i++) { + for (int j = 0; j < addresses[i].length; j++) { + System.out.println(addresses[i][j]); + reservations.setValueAt(NumberDisplayBaseChooser.formatNumber(addresses[i][j], 16), i, j); } } } From 2d3e687728d29c5b0e449bcf06c17fd926a39812 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Sat, 29 May 2021 00:14:53 -0600 Subject: [PATCH 18/84] add table headers --- .../riscv/hardware/ReservationTables.java | 11 +++++++ src/rars/tools/ReservationTablesTool.java | 32 ++++++++++--------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index 78a4f2a9..16c041eb 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -72,6 +72,17 @@ public Integer[][] getAllAddresses() { return all; } + public String[][] getAllAddressesAsStrings() { + String[][] all = new String[ReservationTable.capacity][processors]; + for (int i = 0; i < ReservationTable.capacity; i++) { + for (int j = 0; j < processors; j++) { + Integer[] addresses = reservationTables[j].getAddresses(); + all[i][j] = String.format("0x%08x", addresses[i]); + } + } + return all; + } + public void addObserver(Observer obs) { observables.add(new ReservationTablesObservable(obs)); } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 0d2a3fcb..f6a7f97a 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -1,14 +1,13 @@ package rars.tools; -import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JTable; -import rars.venus.NumberDisplayBaseChooser; + import rars.Globals; -import rars.riscv.hardware.ReservationTable; /* Copyright (c) 2021, Giancarlo Pernudi Segura. @@ -48,14 +47,18 @@ public ReservationTablesTool() { } protected JComponent buildMainDisplayArea() { - JPanel panelTools = new JPanel(new GridLayout(2, 1)); - reservations = new JTable(ReservationTable.capacity, Globals.reservationTables.processors); - // String[] columns = new String[Globals.reservationTables.processors]; - // for (int i = 0; i < columns.length; i++) { - // columns[i] = String.format("Processor %d", i); - // } - updateDisplay(); - panelTools.add(reservations); + JPanel panelTools = new JPanel(); + String[] columns = new String[Globals.reservationTables.processors]; + for (int i = 0; i < columns.length; i++) { + columns[i] = String.format("Processor %d", i); + } + reservations = new JTable(Globals.reservationTables.getAllAddressesAsStrings(), columns) { + @Override + public boolean isCellEditable(int row, int column) { + return false; + } + }; + panelTools.add(new JScrollPane(reservations)); return panelTools; } @@ -68,7 +71,7 @@ protected JComponent getHelpComponent() { final String helpContent = "Use this tool to simulate atomic operations such as store conditional.\n" + "While this tool is connected to the program, the table below shows the\n" + "reservation table for each processor. Addresses reserved by a processor\n" - + "will appear under that processor's column. You can release an address, \n" + + "will appear under that processor's column. You can release an address,\n" + "which will release that address across all the processor's tables in\n" + "order to simulate some other processor performing a store conditional.\n" + "(contributed by Giancarlo Pernudi Segura, pernudi@ualberta.ca)"; @@ -81,11 +84,10 @@ protected JComponent getHelpComponent() { @Override protected void updateDisplay() { - Integer[][] addresses = Globals.reservationTables.getAllAddresses(); + String[][] addresses = Globals.reservationTables.getAllAddressesAsStrings(); for (int i = 0; i < addresses.length; i++) { for (int j = 0; j < addresses[i].length; j++) { - System.out.println(addresses[i][j]); - reservations.setValueAt(NumberDisplayBaseChooser.formatNumber(addresses[i][j], 16), i, j); + reservations.setValueAt(addresses[i][j], i, j); } } } From 9de9f2eb90a20056ac40752b2126172930e02352 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Sat, 29 May 2021 04:03:40 -0600 Subject: [PATCH 19/84] unreserve selection --- src/rars/tools/ReservationTablesTool.java | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index f6a7f97a..35a564ab 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -6,6 +6,7 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; +import javax.swing.ListSelectionModel; import rars.Globals; @@ -58,7 +59,21 @@ public boolean isCellEditable(int row, int column) { return false; } }; + reservations.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); panelTools.add(new JScrollPane(reservations)); + JButton clearButton = new JButton("Clear Selected"); + clearButton.addActionListener(l -> { + if (connectButton.isConnected()) { + int row = reservations.getSelectedRow(); + int col = reservations.getSelectedColumn(); + int address = Integer.parseInt(reservations.getValueAt(row, col) + .toString().substring(2), 16); + Globals.reservationTables.unreserveAddress(col, address); + } + reservations.clearSelection(); + updateDisplay(); + }); + panelTools.add(clearButton); return panelTools; } @@ -94,7 +109,9 @@ protected void updateDisplay() { @Override protected void reset() { - Globals.reservationTables.reset(); - updateDisplay(); + if (connectButton.isConnected()) { + Globals.reservationTables.reset(); + updateDisplay(); + } } } From 735c061a2e0cde659408f2824a808c7a22a2a26c Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Sat, 29 May 2021 17:34:16 +0530 Subject: [PATCH 20/84] Moved Clear to button area --- .../tools/AbstractToolAndApplication.java | 4 +-- src/rars/tools/ReservationTablesTool.java | 30 ++++++++++--------- src/rars/venus/run/RunAssembleAction.java | 1 + 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/rars/tools/AbstractToolAndApplication.java b/src/rars/tools/AbstractToolAndApplication.java index 2ef1518c..43784c12 100644 --- a/src/rars/tools/AbstractToolAndApplication.java +++ b/src/rars/tools/AbstractToolAndApplication.java @@ -68,7 +68,7 @@ public abstract class AbstractToolAndApplication extends JFrame implements Tool, protected boolean isBeingUsedAsATool = false; // can use to determine whether invoked as Tool or stand-alone. private JDialog dialog; // used only for Tool use. This is the pop-up dialog that appears when menu item selected. protected Window theWindow; // highest level GUI component (a JFrame for app, a JDialog for Tool) - + protected Box buttonArea; // Major GUI components private JLabel headingLabel; private String title; // descriptive title for title bar provided to constructor. @@ -262,7 +262,7 @@ protected JComponent buildHeadingArea() { * attach or detach simulator to memory, a button to reset the cache, and one to close the tool. */ protected JComponent buildButtonAreaForTool() { - Box buttonArea = Box.createHorizontalBox(); + buttonArea = Box.createHorizontalBox(); TitledBorder tc = new TitledBorder("Tool Control"); tc.setTitleJustification(TitledBorder.CENTER); buttonArea.setBorder(tc); diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 35a564ab..e0f0ad88 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -1,14 +1,8 @@ package rars.tools; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; - +import java.awt.GridLayout; import rars.Globals; +import javax.swing.*; /* Copyright (c) 2021, Giancarlo Pernudi Segura. @@ -48,7 +42,7 @@ public ReservationTablesTool() { } protected JComponent buildMainDisplayArea() { - JPanel panelTools = new JPanel(); + JPanel panelTools = new JPanel(new GridLayout()); String[] columns = new String[Globals.reservationTables.processors]; for (int i = 0; i < columns.length; i++) { columns[i] = String.format("Processor %d", i); @@ -60,8 +54,15 @@ public boolean isCellEditable(int row, int column) { } }; reservations.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - panelTools.add(new JScrollPane(reservations)); + panelTools.add(reservations); + return panelTools; + } + + @Override + protected JComponent buildButtonAreaForTool(){ + super.buildButtonAreaForTool(); JButton clearButton = new JButton("Clear Selected"); + clearButton.setToolTipText("Clear the Selected from the Reserve Table"); clearButton.addActionListener(l -> { if (connectButton.isConnected()) { int row = reservations.getSelectedRow(); @@ -73,8 +74,11 @@ public boolean isCellEditable(int row, int column) { reservations.clearSelection(); updateDisplay(); }); - panelTools.add(clearButton); - return panelTools; + clearButton.addKeyListener(new EnterKeyListener(clearButton)); + buttonArea.add(clearButton); + buttonArea.add(Box.createHorizontalGlue()); + return buttonArea; + } @Override @@ -109,9 +113,7 @@ protected void updateDisplay() { @Override protected void reset() { - if (connectButton.isConnected()) { Globals.reservationTables.reset(); updateDisplay(); - } } } diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index 5e5bec6c..7f6b2395 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -124,6 +124,7 @@ public void actionPerformed(ActionEvent e) { FloatingPointRegisterFile.resetRegisters(); ControlAndStatusRegisterFile.resetRegisters(); InterruptController.reset(); + Globals.reservationTables.reset(); executePane.getTextSegmentWindow().setupTable(); executePane.getDataSegmentWindow().setupTable(); From a4183fefc8c0fcf93a5a83065e82da3d07921750 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Sat, 29 May 2021 17:45:02 +0530 Subject: [PATCH 21/84] Modified Clear Selected --- src/rars/tools/ReservationTablesTool.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index e0f0ad88..8728e32c 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -67,6 +67,8 @@ protected JComponent buildButtonAreaForTool(){ if (connectButton.isConnected()) { int row = reservations.getSelectedRow(); int col = reservations.getSelectedColumn(); + if(row < 0 || col < 0) + return; int address = Integer.parseInt(reservations.getValueAt(row, col) .toString().substring(2), 16); Globals.reservationTables.unreserveAddress(col, address); From 92cefca0f054eee9154d3918ff938c3f8b1d261a Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Sat, 29 May 2021 17:46:46 +0530 Subject: [PATCH 22/84] May 29 --- src/rars/tools/ReservationTablesTool.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 8728e32c..7d912650 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -5,9 +5,9 @@ import javax.swing.*; /* -Copyright (c) 2021, Giancarlo Pernudi Segura. +Copyright (c) 2021, Giancarlo Pernudi Segura & Siva Chowdeswar Nandipati. -Developed by Giancarlo Pernudi Segura (pernudi@ualberta.ca) +Developed by Giancarlo Pernudi Segura (pernudi@ualberta.ca) & Siva Chowdeswar Nandipati (sivachow@ualberta.ca). Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From d60dfb56f0a45792fc47e9812981127316384231 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Sat, 29 May 2021 18:42:40 +0530 Subject: [PATCH 23/84] Reserve Table Layout --- src/rars/tools/ReservationTablesTool.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 7d912650..5f4f66cc 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -3,6 +3,7 @@ import java.awt.GridLayout; import rars.Globals; import javax.swing.*; +import java.awt.*; /* Copyright (c) 2021, Giancarlo Pernudi Segura & Siva Chowdeswar Nandipati. @@ -42,10 +43,10 @@ public ReservationTablesTool() { } protected JComponent buildMainDisplayArea() { - JPanel panelTools = new JPanel(new GridLayout()); + JPanel panelTools = new JPanel(new BorderLayout()); String[] columns = new String[Globals.reservationTables.processors]; for (int i = 0; i < columns.length; i++) { - columns[i] = String.format("Processor %d", i); + columns[i] = String.format("Processor %d", i + 1); } reservations = new JTable(Globals.reservationTables.getAllAddressesAsStrings(), columns) { @Override @@ -53,6 +54,7 @@ public boolean isCellEditable(int row, int column) { return false; } }; + panelTools.add(reservations.getTableHeader(), BorderLayout.NORTH); reservations.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); panelTools.add(reservations); return panelTools; From 56deb618daff18eb2215f27bb505c777c40e8535 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Sat, 29 May 2021 19:19:38 +0530 Subject: [PATCH 24/84] Reserve Table Tool --- src/rars/tools/ReservationTablesTool.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 5f4f66cc..10b9252d 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -55,7 +55,8 @@ public boolean isCellEditable(int row, int column) { } }; panelTools.add(reservations.getTableHeader(), BorderLayout.NORTH); - reservations.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + reservations.setCellSelectionEnabled(true); + reservations.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); panelTools.add(reservations); return panelTools; } @@ -97,7 +98,8 @@ protected JComponent getHelpComponent() { + "will appear under that processor's column. You can release an address,\n" + "which will release that address across all the processor's tables in\n" + "order to simulate some other processor performing a store conditional.\n" - + "(contributed by Giancarlo Pernudi Segura, pernudi@ualberta.ca)"; + + "(contributed by Giancarlo Pernudi Segura, pernudi@ualberta.ca) &" + + "\n Siva Chowdeswar Nandipati (sivachow@ualberta.ca)"; JButton help = new JButton("Help"); help.addActionListener(l -> { JOptionPane.showMessageDialog(theWindow, helpContent); From 87d0808b70bedb200b219a1b7cfb4fc7fd2a1091 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Mon, 31 May 2021 23:30:52 +0530 Subject: [PATCH 25/84] Changed 'Processor' to Hart' --- .../riscv/hardware/ReservationTables.java | 24 +++++++++---------- src/rars/tools/ReservationTablesTool.java | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index 16c041eb..a1e3bea4 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -32,27 +32,27 @@ a copy of this software and associated documentation files (the public class ReservationTables { private ReservationTable[] reservationTables; - public int processors; + public int harts; private Collection observables = new Vector<>(); - public ReservationTables(int processors) { - this.processors = processors; + public ReservationTables(int harts) { + this.harts = harts; reset(); } public void reset() { - reservationTables = new ReservationTable[processors]; + reservationTables = new ReservationTable[harts]; for (int i = 0; i < reservationTables.length; i++) { reservationTables[i] = new ReservationTable(); } } - public void reserveAddress(int processor, int address) { - reservationTables[processor].reserveAddress(address); + public void reserveAddress(int hart, int address) { + reservationTables[hart].reserveAddress(address); } - public boolean unreserveAddress(int processor, int address) { - if (reservationTables[processor].contains(address)) { + public boolean unreserveAddress(int hart, int address) { + if (reservationTables[hart].contains(address)) { for (ReservationTable reservationTable : reservationTables) { reservationTable.unreserveAddress(address); } @@ -62,9 +62,9 @@ public boolean unreserveAddress(int processor, int address) { } public Integer[][] getAllAddresses() { - Integer[][] all = new Integer[ReservationTable.capacity][processors]; + Integer[][] all = new Integer[ReservationTable.capacity][harts]; for (int i = 0; i < ReservationTable.capacity; i++) { - for (int j = 0; j < processors; j++) { + for (int j = 0; j < harts; j++) { Integer[] addresses = reservationTables[j].getAddresses(); all[i][j] = addresses[i]; } @@ -73,9 +73,9 @@ public Integer[][] getAllAddresses() { } public String[][] getAllAddressesAsStrings() { - String[][] all = new String[ReservationTable.capacity][processors]; + String[][] all = new String[ReservationTable.capacity][harts]; for (int i = 0; i < ReservationTable.capacity; i++) { - for (int j = 0; j < processors; j++) { + for (int j = 0; j < harts; j++) { Integer[] addresses = reservationTables[j].getAddresses(); all[i][j] = String.format("0x%08x", addresses[i]); } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 10b9252d..798c8281 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -44,9 +44,9 @@ public ReservationTablesTool() { protected JComponent buildMainDisplayArea() { JPanel panelTools = new JPanel(new BorderLayout()); - String[] columns = new String[Globals.reservationTables.processors]; + String[] columns = new String[Globals.reservationTables.harts]; for (int i = 0; i < columns.length; i++) { - columns[i] = String.format("Processor %d", i + 1); + columns[i] = String.format("Hart %d", i); } reservations = new JTable(Globals.reservationTables.getAllAddressesAsStrings(), columns) { @Override @@ -94,10 +94,10 @@ public String getName() { protected JComponent getHelpComponent() { final String helpContent = "Use this tool to simulate atomic operations such as store conditional.\n" + "While this tool is connected to the program, the table below shows the\n" - + "reservation table for each processor. Addresses reserved by a processor\n" - + "will appear under that processor's column. You can release an address,\n" - + "which will release that address across all the processor's tables in\n" - + "order to simulate some other processor performing a store conditional.\n" + + "reservation table for each Hart. Addresses reserved by a Hart\n" + + "will appear under that Hart's column. You can release an address,\n" + + "which will release that address across all the Hart's tables in\n" + + "order to simulate some other Hart performing a store conditional.\n" + "(contributed by Giancarlo Pernudi Segura, pernudi@ualberta.ca) &" + "\n Siva Chowdeswar Nandipati (sivachow@ualberta.ca)"; JButton help = new JButton("Help"); From 60d1341ce03faed2619d1dc6208d0a86a4d415c6 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Tue, 1 Jun 2021 10:20:53 -0600 Subject: [PATCH 26/84] change hart in help window to lowercase --- src/rars/tools/ReservationTablesTool.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 798c8281..bbb07475 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -94,10 +94,10 @@ public String getName() { protected JComponent getHelpComponent() { final String helpContent = "Use this tool to simulate atomic operations such as store conditional.\n" + "While this tool is connected to the program, the table below shows the\n" - + "reservation table for each Hart. Addresses reserved by a Hart\n" - + "will appear under that Hart's column. You can release an address,\n" - + "which will release that address across all the Hart's tables in\n" - + "order to simulate some other Hart performing a store conditional.\n" + + "reservation table for each hart. Addresses reserved by a hart\n" + + "will appear under that hart's column. You can release an address,\n" + + "which will release that address across all the hart's tables in\n" + + "order to simulate some other hart performing a store conditional.\n" + "(contributed by Giancarlo Pernudi Segura, pernudi@ualberta.ca) &" + "\n Siva Chowdeswar Nandipati (sivachow@ualberta.ca)"; JButton help = new JButton("Help"); From 22c1477439cdc066590d259c2e240fad5f9a7ead Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Wed, 2 Jun 2021 12:49:24 -0600 Subject: [PATCH 27/84] add atomic instructions example --- examples/atomic.s | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 examples/atomic.s diff --git a/examples/atomic.s b/examples/atomic.s new file mode 100644 index 00000000..01757c14 --- /dev/null +++ b/examples/atomic.s @@ -0,0 +1,15 @@ +.globl main +.data +num: + .word 0x12345678 + +.text +main: + la t0, num +retry: + lr.w t1, (t0) + # increment by 1 + addi t1, t1, 1 + sc.w t2, t1, (t0) + # if save fails; retry operations again + bne zero, t2, retry From 21ef508647bd6cb571c023f53b1b2fc567608bb6 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Wed, 2 Jun 2021 16:33:42 -0600 Subject: [PATCH 28/84] redefine all atomic instructions to be R type --- src/rars/riscv/BasicInstructionFormat.java | 1 - src/rars/riscv/instructions/Atomic.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rars/riscv/BasicInstructionFormat.java b/src/rars/riscv/BasicInstructionFormat.java index a037566a..fce2261f 100644 --- a/src/rars/riscv/BasicInstructionFormat.java +++ b/src/rars/riscv/BasicInstructionFormat.java @@ -42,5 +42,4 @@ public enum BasicInstructionFormat { B_FORMAT, // 2 src registers + small immediate shifted left U_FORMAT, // 1 dst register + large immediate J_FORMAT, // 1 dst register + large immediate for jumping - A_FORMAT, // 1 dst and 1 or 2 src register } diff --git a/src/rars/riscv/instructions/Atomic.java b/src/rars/riscv/instructions/Atomic.java index 335a9af9..5a8b8ffb 100644 --- a/src/rars/riscv/instructions/Atomic.java +++ b/src/rars/riscv/instructions/Atomic.java @@ -38,7 +38,7 @@ a copy of this software and associated documentation files (the */ public abstract class Atomic extends BasicInstruction { public Atomic(String usage, String description, String funct3, String funct5) { - super(usage, description, BasicInstructionFormat.A_FORMAT, + super(usage, description, BasicInstructionFormat.R_FORMAT, funct5 + " 00sssss ttttt " + funct3 + " fffff 0101111"); } } From ba9fd8ed7fd7e826ad56359af403689377b93d2d Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Wed, 2 Jun 2021 17:44:09 -0600 Subject: [PATCH 29/84] parent AMO class --- .../instructions/AtomicMemoryOperation.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/rars/riscv/instructions/AtomicMemoryOperation.java diff --git a/src/rars/riscv/instructions/AtomicMemoryOperation.java b/src/rars/riscv/instructions/AtomicMemoryOperation.java new file mode 100644 index 00000000..358543c5 --- /dev/null +++ b/src/rars/riscv/instructions/AtomicMemoryOperation.java @@ -0,0 +1,61 @@ +package rars.riscv.instructions; + +import rars.Globals; +import rars.ProgramStatement; +import rars.SimulationException; +import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.RegisterFile; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +/** + * Base class for all Atomic instructions + * + * @author Giancarlo Pernudi Segura + * @version May 2017 + */ +public abstract class AtomicMemoryOperation extends Atomic { + public AtomicMemoryOperation(String usage, String description, String funct3, String funct5) { + super(usage, description, funct5, funct3); + } + + public void simulate(ProgramStatement statement) throws SimulationException { + int[] operands = statement.getOperands(); + try { + int rs1Data = Globals.memory.getWord(RegisterFile.getValue(operands[1])); + int rs2Value = RegisterFile.getValue(operands[2]); + RegisterFile.updateRegister(operands[0], rs1Data); + rs1Data = binaryOperation(rs1Data, rs2Value); + Globals.memory.setWord(RegisterFile.getValue(operands[1]), rs1Data); + } catch (AddressErrorException e) { + throw new SimulationException(statement, e); + } + } + + protected abstract int binaryOperation(int value1, int value2); +} From 7a66fa1f4aacdb8808b1a10eb04cc7955276949d Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Thu, 3 Jun 2021 21:54:34 +0530 Subject: [PATCH 30/84] Fixing the glue before clearselect --- src/rars/Globals.java | 2 +- src/rars/tools/ReservationTablesTool.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index 4dbaf00d..c0d8ad81 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -172,7 +172,7 @@ public static Settings getSettings() { public static void initialize(boolean gui) { if (!initialized) { memory = Memory.getInstance(); //clients can use Memory.getInstance instead of Globals.memory - reservationTables = new ReservationTables(1); + reservationTables = new ReservationTables(2); symbolTable = new SymbolTable("global"); settings = new Settings(gui); instructionSet = new InstructionSet(); diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 798c8281..5f06f76a 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -80,6 +80,7 @@ protected JComponent buildButtonAreaForTool(){ updateDisplay(); }); clearButton.addKeyListener(new EnterKeyListener(clearButton)); + buttonArea.add(Box.createHorizontalGlue()); buttonArea.add(clearButton); buttonArea.add(Box.createHorizontalGlue()); return buttonArea; From 888a5614d0eeda1e7fe585eba6d903d3b1fa714f Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Sat, 5 Jun 2021 18:21:30 -0600 Subject: [PATCH 31/84] unreserve address on regular store --- src/PseudoOps.txt | 4 --- src/rars/Globals.java | 2 +- .../riscv/hardware/ReservationTables.java | 28 +++++++++++++++++-- .../instructions/{LR_W.java => LRW.java} | 4 +-- src/rars/riscv/instructions/SB.java | 4 +-- .../instructions/{SC_W.java => SCW.java} | 4 +-- src/rars/riscv/instructions/SH.java | 4 +-- src/rars/riscv/instructions/SW.java | 4 +-- src/rars/tools/ReservationTablesTool.java | 11 ++++++-- 9 files changed, 42 insertions(+), 23 deletions(-) rename src/rars/riscv/instructions/{LR_W.java => LRW.java} (94%) rename src/rars/riscv/instructions/{SC_W.java => SCW.java} (95%) diff --git a/src/PseudoOps.txt b/src/PseudoOps.txt index dcb8a6de..d9870286 100644 --- a/src/PseudoOps.txt +++ b/src/PseudoOps.txt @@ -265,7 +265,3 @@ fgt.s t1, f2, f3 ;fle.s RG1, RG2, RG3 ;#Floating Greater Than: if f1 > f2, fge.s t1, f2, f3 ;flt.s RG1, RG2, RG3 ;#Floating Greater Than or Equal: if f1 >= f2, set t1 to 1, else set t1 to 0 fgt.d t1, f2, f3 ;fle.d RG1, RG2, RG3 ;#Floating Greater Than (64 bit): if f1 > f2, set t1 to 1, else set t1 to 0 fge.d t1, f2, f3 ;flt.d RG1, RG2, RG3 ;#Floating Greater Than or Equal (64 bit): if f1 >= f2, set t1 to 1, else set t1 to 0 - -######################### atomic pseudo-ops ########################## -lr.w t1,(t2) ;lr.w RG1,(RG3) ;#Load Reserved Word : Set t1 to contents of effective memory word address and reserves memory word address -sc.w t1,t2,(t3) ;sc.w RG1,RG2,(RG3) ;#Store Conditional Word : Tries to store t2 contents into effective memory word address and returns store result in t1 diff --git a/src/rars/Globals.java b/src/rars/Globals.java index c0d8ad81..4dbaf00d 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -172,7 +172,7 @@ public static Settings getSettings() { public static void initialize(boolean gui) { if (!initialized) { memory = Memory.getInstance(); //clients can use Memory.getInstance instead of Globals.memory - reservationTables = new ReservationTables(2); + reservationTables = new ReservationTables(1); symbolTable = new SymbolTable("global"); settings = new Settings(gui); instructionSet = new InstructionSet(); diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index a1e3bea4..724410e2 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -5,6 +5,8 @@ import java.util.Observer; import java.util.Vector; +import rars.SimulationException; + /* Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura. @@ -30,7 +32,7 @@ a copy of this software and associated documentation files (the (MIT license, http://www.opensource.org/licenses/mit-license.html) */ -public class ReservationTables { +public class ReservationTables extends Observable { private ReservationTable[] reservationTables; public int harts; private Collection observables = new Vector<>(); @@ -51,7 +53,10 @@ public void reserveAddress(int hart, int address) { reservationTables[hart].reserveAddress(address); } - public boolean unreserveAddress(int hart, int address) { + public boolean unreserveAddress(int hart, int address) throws AddressErrorException { + if (address % 4 != 0) { + throw new AddressErrorException("Reservation address not aligned to word boundary ", SimulationException.STORE_ADDRESS_MISALIGNED, address); + } if (reservationTables[hart].contains(address)) { for (ReservationTable reservationTable : reservationTables) { reservationTable.unreserveAddress(address); @@ -87,6 +92,25 @@ public void addObserver(Observer obs) { observables.add(new ReservationTablesObservable(obs)); } + /** + * Remove specified reservation tables observer + * + * @param obs Observer to be removed + */ + public void deleteObserver(Observer obs) { + for (ReservationTablesObservable o : observables) { + o.deleteObserver(obs); + } + } + + /** + * Remove all reservation tables observers + */ + public void deleteObservers() { + // just drop the collection + observables = new Vector<>(); + } + private class ReservationTablesObservable extends Observable { public ReservationTablesObservable(Observer obs) { this.addObserver(obs); diff --git a/src/rars/riscv/instructions/LR_W.java b/src/rars/riscv/instructions/LRW.java similarity index 94% rename from src/rars/riscv/instructions/LR_W.java rename to src/rars/riscv/instructions/LRW.java index 98aafd4d..17bb7c95 100644 --- a/src/rars/riscv/instructions/LR_W.java +++ b/src/rars/riscv/instructions/LRW.java @@ -7,8 +7,8 @@ import rars.riscv.hardware.RegisterFile; -public class LR_W extends Atomic { - public LR_W() { +public class LRW extends Atomic { + public LRW() { super("lr.w t1, (t2)", "Set t1 to contents of effective memory word address and reserve", "010", "00010"); } diff --git a/src/rars/riscv/instructions/SB.java b/src/rars/riscv/instructions/SB.java index bc8f3446..125f4bc0 100644 --- a/src/rars/riscv/instructions/SB.java +++ b/src/rars/riscv/instructions/SB.java @@ -36,9 +36,7 @@ public SB() { } public void store(int address, long data) throws AddressErrorException { + Globals.reservationTables.unreserveAddress(0, address & ~0b11); Globals.memory.setByte(address, (int)data & 0x000000FF); } } - - - diff --git a/src/rars/riscv/instructions/SC_W.java b/src/rars/riscv/instructions/SCW.java similarity index 95% rename from src/rars/riscv/instructions/SC_W.java rename to src/rars/riscv/instructions/SCW.java index 8e6d8952..8628db84 100644 --- a/src/rars/riscv/instructions/SC_W.java +++ b/src/rars/riscv/instructions/SCW.java @@ -6,8 +6,8 @@ import rars.SimulationException; import rars.riscv.hardware.RegisterFile; -public class SC_W extends Atomic { - public SC_W() { +public class SCW extends Atomic { + public SCW() { super("sc.w t0, t1, (t2)", "Try to store t1 to contents of effective memory word address, sets t0 to store attempt result", "010", "00011"); } diff --git a/src/rars/riscv/instructions/SH.java b/src/rars/riscv/instructions/SH.java index 829b6cba..99e00741 100644 --- a/src/rars/riscv/instructions/SH.java +++ b/src/rars/riscv/instructions/SH.java @@ -36,9 +36,7 @@ public SH() { } public void store(int address, long data) throws AddressErrorException { + Globals.reservationTables.unreserveAddress(0, address & ~0b11); Globals.memory.setHalf(address, (int)data & 0x0000FFFF); } } - - - diff --git a/src/rars/riscv/instructions/SW.java b/src/rars/riscv/instructions/SW.java index 73b3ca65..4ab55821 100644 --- a/src/rars/riscv/instructions/SW.java +++ b/src/rars/riscv/instructions/SW.java @@ -36,9 +36,7 @@ public SW() { } public void store(int address, long data) throws AddressErrorException { + Globals.reservationTables.unreserveAddress(0, address); Globals.memory.setWord(address, (int) data); } } - - - diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index da863ef2..369281dc 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -1,7 +1,8 @@ package rars.tools; -import java.awt.GridLayout; import rars.Globals; +import rars.riscv.hardware.AddressErrorException; + import javax.swing.*; import java.awt.*; @@ -40,6 +41,7 @@ public class ReservationTablesTool extends AbstractToolAndApplication { public ReservationTablesTool() { super(heading + ", " + version, heading); + Globals.reservationTables.addObserver(this); } protected JComponent buildMainDisplayArea() { @@ -74,7 +76,11 @@ protected JComponent buildButtonAreaForTool(){ return; int address = Integer.parseInt(reservations.getValueAt(row, col) .toString().substring(2), 16); - Globals.reservationTables.unreserveAddress(col, address); + try { + Globals.reservationTables.unreserveAddress(col, address); + } catch (AddressErrorException e) { + e.printStackTrace(); + } } reservations.clearSelection(); updateDisplay(); @@ -82,7 +88,6 @@ protected JComponent buildButtonAreaForTool(){ clearButton.addKeyListener(new EnterKeyListener(clearButton)); buttonArea.add(Box.createHorizontalGlue()); buttonArea.add(clearButton); - buttonArea.add(Box.createHorizontalGlue()); return buttonArea; } From 1cf1ea4d91280dc4c08193385f98de74e0e77d28 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Sat, 5 Jun 2021 18:22:16 -0600 Subject: [PATCH 32/84] implement rest of 32-bit atomic instructions --- src/rars/riscv/instructions/AMOADDW.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOANDW.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOMAXUW.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOMAXW.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOMINUW.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOMINW.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOORW.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOSWAPW.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOXORW.java | 39 +++++++++++++++++++ .../instructions/AtomicMemoryOperation.java | 10 +++-- 10 files changed, 357 insertions(+), 4 deletions(-) create mode 100644 src/rars/riscv/instructions/AMOADDW.java create mode 100644 src/rars/riscv/instructions/AMOANDW.java create mode 100644 src/rars/riscv/instructions/AMOMAXUW.java create mode 100644 src/rars/riscv/instructions/AMOMAXW.java create mode 100644 src/rars/riscv/instructions/AMOMINUW.java create mode 100644 src/rars/riscv/instructions/AMOMINW.java create mode 100644 src/rars/riscv/instructions/AMOORW.java create mode 100644 src/rars/riscv/instructions/AMOSWAPW.java create mode 100644 src/rars/riscv/instructions/AMOXORW.java diff --git a/src/rars/riscv/instructions/AMOADDW.java b/src/rars/riscv/instructions/AMOADDW.java new file mode 100644 index 00000000..ab966d64 --- /dev/null +++ b/src/rars/riscv/instructions/AMOADDW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOADDW extends AtomicMemoryOperation { + public AMOADDW() { + super("amoadd.w t0, t1, (t2)", "Loads value at t2 and places it into t0, adds value t1 and t0 (new), and saves at memory location t2.", "010", "00000"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return value1 + value2; + } +} diff --git a/src/rars/riscv/instructions/AMOANDW.java b/src/rars/riscv/instructions/AMOANDW.java new file mode 100644 index 00000000..a781e417 --- /dev/null +++ b/src/rars/riscv/instructions/AMOANDW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOANDW extends AtomicMemoryOperation { + public AMOANDW() { + super("amoand.w t0, t1, (t2)", "Loads value at t2 and places it into t0, ANDS value t1 and t0 (new), and saves at memory location t2.", "010", "01100"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return value1 & value2; + } +} diff --git a/src/rars/riscv/instructions/AMOMAXUW.java b/src/rars/riscv/instructions/AMOMAXUW.java new file mode 100644 index 00000000..33087e06 --- /dev/null +++ b/src/rars/riscv/instructions/AMOMAXUW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOMAXUW extends AtomicMemoryOperation { + public AMOMAXUW() { + super("amomaxu.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the greatest unsigned value between value t1 and t0 (new).", "010", "11100"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return Integer.compareUnsigned(value1, value2) > 0 ? value1 : value2; + } +} diff --git a/src/rars/riscv/instructions/AMOMAXW.java b/src/rars/riscv/instructions/AMOMAXW.java new file mode 100644 index 00000000..4dcb3e17 --- /dev/null +++ b/src/rars/riscv/instructions/AMOMAXW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOMAXW extends AtomicMemoryOperation { + public AMOMAXW() { + super("amomax.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the greatest value between value t1 and t0 (new).", "010", "10100"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return Integer.max(value1, value2); + } +} diff --git a/src/rars/riscv/instructions/AMOMINUW.java b/src/rars/riscv/instructions/AMOMINUW.java new file mode 100644 index 00000000..cd4f6689 --- /dev/null +++ b/src/rars/riscv/instructions/AMOMINUW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOMINUW extends AtomicMemoryOperation { + public AMOMINUW() { + super("amominu.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the lowest unsigned value between value t1 and t0 (new).", "010", "11000"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return Integer.compareUnsigned(value1, value2) < 0 ? value1 : value2; + } +} diff --git a/src/rars/riscv/instructions/AMOMINW.java b/src/rars/riscv/instructions/AMOMINW.java new file mode 100644 index 00000000..635ac8fd --- /dev/null +++ b/src/rars/riscv/instructions/AMOMINW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOMINW extends AtomicMemoryOperation { + public AMOMINW() { + super("amomin.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the lowest value between value t1 and t0 (new).", "010", "10000"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return Integer.min(value1, value2); + } +} diff --git a/src/rars/riscv/instructions/AMOORW.java b/src/rars/riscv/instructions/AMOORW.java new file mode 100644 index 00000000..b574a0f4 --- /dev/null +++ b/src/rars/riscv/instructions/AMOORW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOORW extends AtomicMemoryOperation { + public AMOORW() { + super("amoor.w t0, t1, (t2)", "Loads value at t2 and places it into t0, ORS value t1 and t0 (new), and saves at memory location t2.", "010", "01000"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return value1 | value2; + } +} diff --git a/src/rars/riscv/instructions/AMOSWAPW.java b/src/rars/riscv/instructions/AMOSWAPW.java new file mode 100644 index 00000000..f836f30c --- /dev/null +++ b/src/rars/riscv/instructions/AMOSWAPW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOSWAPW extends AtomicMemoryOperation { + public AMOSWAPW() { + super("amoswap.w t0, t1, (t2)", "Loads value at t2 and places it into t0, saves value t1 at memory location t2.", "010", "00001"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return value2; + } +} diff --git a/src/rars/riscv/instructions/AMOXORW.java b/src/rars/riscv/instructions/AMOXORW.java new file mode 100644 index 00000000..6a43df30 --- /dev/null +++ b/src/rars/riscv/instructions/AMOXORW.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOXORW extends AtomicMemoryOperation { + public AMOXORW() { + super("amoxor.w t0, t1, (t2)", "Loads value at t2 and places it into t0, XORS value t1 and t0 (new), and saves at memory location t2.", "010", "00100"); + } + + @Override + protected int binaryOperation(int value1, int value2) { + return value1 ^ value2; + } +} diff --git a/src/rars/riscv/instructions/AtomicMemoryOperation.java b/src/rars/riscv/instructions/AtomicMemoryOperation.java index 358543c5..03cf2f20 100644 --- a/src/rars/riscv/instructions/AtomicMemoryOperation.java +++ b/src/rars/riscv/instructions/AtomicMemoryOperation.java @@ -41,17 +41,19 @@ a copy of this software and associated documentation files (the */ public abstract class AtomicMemoryOperation extends Atomic { public AtomicMemoryOperation(String usage, String description, String funct3, String funct5) { - super(usage, description, funct5, funct3); + super(usage, description, funct3, funct5); } public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); try { - int rs1Data = Globals.memory.getWord(RegisterFile.getValue(operands[1])); - int rs2Value = RegisterFile.getValue(operands[2]); + int rs1Loc = RegisterFile.getValue(operands[2]); + Globals.reservationTables.unreserveAddress(0, rs1Loc); + int rs1Data = Globals.memory.getWord(rs1Loc); + int rs2Value = RegisterFile.getValue(operands[1]); RegisterFile.updateRegister(operands[0], rs1Data); rs1Data = binaryOperation(rs1Data, rs2Value); - Globals.memory.setWord(RegisterFile.getValue(operands[1]), rs1Data); + Globals.memory.setWord(rs1Loc, rs1Data); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } From 8b0ce6ed3b1a5e0637b1aa602368c154e6827bb1 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Mon, 7 Jun 2021 15:21:30 +0530 Subject: [PATCH 33/84] Added To GUI --- src/rars/Globals.java | 7 ++- .../tools/AbstractToolAndApplication.java | 3 +- src/rars/tools/ReservationTablesTool.java | 60 +++++++++++++++---- 3 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index 4dbaf00d..efcb36f6 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -145,6 +145,11 @@ public class Globals { public static boolean runSpeedPanelExists = false; + private static int harts = 1; + + public static int getHarts() { + return harts; + } private static String getCopyrightYears() { return "2003-2019"; } @@ -172,7 +177,7 @@ public static Settings getSettings() { public static void initialize(boolean gui) { if (!initialized) { memory = Memory.getInstance(); //clients can use Memory.getInstance instead of Globals.memory - reservationTables = new ReservationTables(1); + reservationTables = new ReservationTables(harts); symbolTable = new SymbolTable("global"); settings = new Settings(gui); instructionSet = new InstructionSet(); diff --git a/src/rars/tools/AbstractToolAndApplication.java b/src/rars/tools/AbstractToolAndApplication.java index 43784c12..f5fca64a 100644 --- a/src/rars/tools/AbstractToolAndApplication.java +++ b/src/rars/tools/AbstractToolAndApplication.java @@ -68,7 +68,6 @@ public abstract class AbstractToolAndApplication extends JFrame implements Tool, protected boolean isBeingUsedAsATool = false; // can use to determine whether invoked as Tool or stand-alone. private JDialog dialog; // used only for Tool use. This is the pop-up dialog that appears when menu item selected. protected Window theWindow; // highest level GUI component (a JFrame for app, a JDialog for Tool) - protected Box buttonArea; // Major GUI components private JLabel headingLabel; private String title; // descriptive title for title bar provided to constructor. @@ -262,7 +261,7 @@ protected JComponent buildHeadingArea() { * attach or detach simulator to memory, a button to reset the cache, and one to close the tool. */ protected JComponent buildButtonAreaForTool() { - buttonArea = Box.createHorizontalBox(); + Box buttonArea = Box.createHorizontalBox(); TitledBorder tc = new TitledBorder("Tool Control"); tc.setTitleJustification(TitledBorder.CENTER); buttonArea.setBorder(tc); diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 369281dc..102cfae4 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -2,9 +2,15 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.*; +import rars.util.Binary; +import rars.venus.*; import javax.swing.*; import java.awt.*; +import java.util.*; +import java.awt.event.*; +import javax.swing.border.TitledBorder; /* Copyright (c) 2021, Giancarlo Pernudi Segura & Siva Chowdeswar Nandipati. @@ -36,8 +42,19 @@ a copy of this software and associated documentation files (the public class ReservationTablesTool extends AbstractToolAndApplication { private static String heading = "Reservation Table Tool"; private static String version = "Version 1.0"; - - JTable reservations; + private static String displayPanelTitle; + private JPanel displayOptions, hartPanel; + private JComboBox hartWindow; + + private Integer[] SelectHartWindow(){ + Integer hartChoser[]; + hartChoser = new Integer[(Integer) Globals.getHarts()]; + for(int i = 0; i < Globals.getHarts(); i ++){ + hartChoser[i] = i; + } + return hartChoser; + } + private JTable reservations; public ReservationTablesTool() { super(heading + ", " + version, heading); @@ -46,6 +63,7 @@ public ReservationTablesTool() { protected JComponent buildMainDisplayArea() { JPanel panelTools = new JPanel(new BorderLayout()); + hartPanel = new JPanel(new BorderLayout()); String[] columns = new String[Globals.reservationTables.harts]; for (int i = 0; i < columns.length; i++) { columns[i] = String.format("Hart %d", i); @@ -56,16 +74,26 @@ public boolean isCellEditable(int row, int column) { return false; } }; - panelTools.add(reservations.getTableHeader(), BorderLayout.NORTH); + + hartPanel.add(reservations.getTableHeader(), BorderLayout.NORTH); reservations.setCellSelectionEnabled(true); reservations.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); - panelTools.add(reservations); - return panelTools; - } + hartPanel.add(reservations); + + TitledBorder tb = new TitledBorder(displayPanelTitle); + tb.setTitleJustification(TitledBorder.CENTER); + panelTools.setBorder(tb); + + Box displayOptions = Box.createHorizontalBox(); + hartWindow = new JComboBox<>(SelectHartWindow()); + hartWindow.setToolTipText("Technique for determining simulated transmitter device processing delay"); + //ToDo----------- + hartWindow.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + } + }); - @Override - protected JComponent buildButtonAreaForTool(){ - super.buildButtonAreaForTool(); JButton clearButton = new JButton("Clear Selected"); clearButton.setToolTipText("Clear the Selected from the Reserve Table"); clearButton.addActionListener(l -> { @@ -85,13 +113,21 @@ protected JComponent buildButtonAreaForTool(){ reservations.clearSelection(); updateDisplay(); }); + + displayOptions.add(Box.createHorizontalGlue()); + displayOptions.add(hartWindow); clearButton.addKeyListener(new EnterKeyListener(clearButton)); - buttonArea.add(Box.createHorizontalGlue()); - buttonArea.add(clearButton); - return buttonArea; + displayOptions.add(Box.createHorizontalGlue()); + displayOptions.add(clearButton); + displayOptions.add(Box.createHorizontalGlue()); + JSplitPane both = new JSplitPane(JSplitPane.VERTICAL_SPLIT, hartPanel, displayOptions); + both.setResizeWeight(0.5); + panelTools.add(both); + return panelTools; } + @Override public String getName() { return heading; From 3a5ab653a77c4a2a44dd3ab8e7db4031747bdd06 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Mon, 7 Jun 2021 17:06:21 -0600 Subject: [PATCH 34/84] atomic 64-bit support --- .../riscv/hardware/ReservationTables.java | 10 ++++- src/rars/riscv/instructions/AMOADDD.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOADDW.java | 4 +- src/rars/riscv/instructions/AMOANDD.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOANDW.java | 4 +- src/rars/riscv/instructions/AMOMAXD.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOMAXUD.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOMAXUW.java | 6 +-- src/rars/riscv/instructions/AMOMAXW.java | 6 +-- src/rars/riscv/instructions/AMOMIND.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOMINUD.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOMINUW.java | 6 +-- src/rars/riscv/instructions/AMOMINW.java | 6 +-- src/rars/riscv/instructions/AMOORD.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOORW.java | 4 +- src/rars/riscv/instructions/AMOSWAPD.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOSWAPW.java | 4 +- src/rars/riscv/instructions/AMOXORD.java | 39 +++++++++++++++++++ src/rars/riscv/instructions/AMOXORW.java | 4 +- src/rars/riscv/instructions/Atomic.java | 5 +++ .../instructions/AtomicMemoryOperation.java | 21 +++++++--- src/rars/riscv/instructions/LRD.java | 27 +++++++++++++ src/rars/riscv/instructions/LRW.java | 1 - src/rars/riscv/instructions/SCD.java | 31 +++++++++++++++ 24 files changed, 459 insertions(+), 31 deletions(-) create mode 100644 src/rars/riscv/instructions/AMOADDD.java create mode 100644 src/rars/riscv/instructions/AMOANDD.java create mode 100644 src/rars/riscv/instructions/AMOMAXD.java create mode 100644 src/rars/riscv/instructions/AMOMAXUD.java create mode 100644 src/rars/riscv/instructions/AMOMIND.java create mode 100644 src/rars/riscv/instructions/AMOMINUD.java create mode 100644 src/rars/riscv/instructions/AMOORD.java create mode 100644 src/rars/riscv/instructions/AMOSWAPD.java create mode 100644 src/rars/riscv/instructions/AMOXORD.java create mode 100644 src/rars/riscv/instructions/LRD.java create mode 100644 src/rars/riscv/instructions/SCD.java diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index 724410e2..b7646e51 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -6,6 +6,7 @@ import java.util.Vector; import rars.SimulationException; +import rars.riscv.InstructionSet; /* Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura. @@ -49,12 +50,17 @@ public void reset() { } } - public void reserveAddress(int hart, int address) { + public void reserveAddress(int hart, int address) throws AddressErrorException { + int modulo = InstructionSet.rv64 ? 8 : 4; + if (address % modulo != 0) { + throw new AddressErrorException("Reservation address not aligned to word boundary ", SimulationException.LOAD_ADDRESS_MISALIGNED, address); + } reservationTables[hart].reserveAddress(address); } public boolean unreserveAddress(int hart, int address) throws AddressErrorException { - if (address % 4 != 0) { + int modulo = InstructionSet.rv64 ? 8 : 4; + if (address % modulo != 0) { throw new AddressErrorException("Reservation address not aligned to word boundary ", SimulationException.STORE_ADDRESS_MISALIGNED, address); } if (reservationTables[hart].contains(address)) { diff --git a/src/rars/riscv/instructions/AMOADDD.java b/src/rars/riscv/instructions/AMOADDD.java new file mode 100644 index 00000000..cef47d85 --- /dev/null +++ b/src/rars/riscv/instructions/AMOADDD.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOADDD extends AtomicMemoryOperation { + public AMOADDD() { + super("amoadd.d t0, t1, (t2)", "Loads value at t2 and places it into t0, adds value t1 and t0 (new), and saves at memory location t2.", "00000", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return value1 + value2; + } +} diff --git a/src/rars/riscv/instructions/AMOADDW.java b/src/rars/riscv/instructions/AMOADDW.java index ab966d64..8cad4e46 100644 --- a/src/rars/riscv/instructions/AMOADDW.java +++ b/src/rars/riscv/instructions/AMOADDW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOADDW extends AtomicMemoryOperation { public AMOADDW() { - super("amoadd.w t0, t1, (t2)", "Loads value at t2 and places it into t0, adds value t1 and t0 (new), and saves at memory location t2.", "010", "00000"); + super("amoadd.w t0, t1, (t2)", "Loads value at t2 and places it into t0, adds value t1 and t0 (new), and saves at memory location t2.", "00000"); } @Override - protected int binaryOperation(int value1, int value2) { + protected long binaryOperation(long value1, long value2) { return value1 + value2; } } diff --git a/src/rars/riscv/instructions/AMOANDD.java b/src/rars/riscv/instructions/AMOANDD.java new file mode 100644 index 00000000..ca9b07af --- /dev/null +++ b/src/rars/riscv/instructions/AMOANDD.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOANDD extends AtomicMemoryOperation { + public AMOANDD() { + super("amoand.d t0, t1, (t2)", "Loads value at t2 and places it into t0, ANDS value t1 and t0 (new), and saves at memory location t2.", "01100", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return value1 & value2; + } +} diff --git a/src/rars/riscv/instructions/AMOANDW.java b/src/rars/riscv/instructions/AMOANDW.java index a781e417..ade22070 100644 --- a/src/rars/riscv/instructions/AMOANDW.java +++ b/src/rars/riscv/instructions/AMOANDW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOANDW extends AtomicMemoryOperation { public AMOANDW() { - super("amoand.w t0, t1, (t2)", "Loads value at t2 and places it into t0, ANDS value t1 and t0 (new), and saves at memory location t2.", "010", "01100"); + super("amoand.w t0, t1, (t2)", "Loads value at t2 and places it into t0, ANDS value t1 and t0 (new), and saves at memory location t2.", "01100"); } @Override - protected int binaryOperation(int value1, int value2) { + protected long binaryOperation(long value1, long value2) { return value1 & value2; } } diff --git a/src/rars/riscv/instructions/AMOMAXD.java b/src/rars/riscv/instructions/AMOMAXD.java new file mode 100644 index 00000000..7f6de467 --- /dev/null +++ b/src/rars/riscv/instructions/AMOMAXD.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOMAXD extends AtomicMemoryOperation { + public AMOMAXD() { + super("amomax.d t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the greatest value between value t1 and t0 (new).", "10100", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return Long.max(value1, value2); + } +} diff --git a/src/rars/riscv/instructions/AMOMAXUD.java b/src/rars/riscv/instructions/AMOMAXUD.java new file mode 100644 index 00000000..eee095e9 --- /dev/null +++ b/src/rars/riscv/instructions/AMOMAXUD.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOMAXUD extends AtomicMemoryOperation { + public AMOMAXUD() { + super("amomaxu.d t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the greatest unsigned value between value t1 and t0 (new).", "11100", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return Long.compareUnsigned(value1, value2) > 0 ? value1 : value2; + } +} diff --git a/src/rars/riscv/instructions/AMOMAXUW.java b/src/rars/riscv/instructions/AMOMAXUW.java index 33087e06..e9a13139 100644 --- a/src/rars/riscv/instructions/AMOMAXUW.java +++ b/src/rars/riscv/instructions/AMOMAXUW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOMAXUW extends AtomicMemoryOperation { public AMOMAXUW() { - super("amomaxu.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the greatest unsigned value between value t1 and t0 (new).", "010", "11100"); + super("amomaxu.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the greatest unsigned value between value t1 and t0 (new).", "11100"); } @Override - protected int binaryOperation(int value1, int value2) { - return Integer.compareUnsigned(value1, value2) > 0 ? value1 : value2; + protected long binaryOperation(long value1, long value2) { + return Long.compareUnsigned(value1, value2) > 0 ? value1 : value2; } } diff --git a/src/rars/riscv/instructions/AMOMAXW.java b/src/rars/riscv/instructions/AMOMAXW.java index 4dcb3e17..fe20615f 100644 --- a/src/rars/riscv/instructions/AMOMAXW.java +++ b/src/rars/riscv/instructions/AMOMAXW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOMAXW extends AtomicMemoryOperation { public AMOMAXW() { - super("amomax.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the greatest value between value t1 and t0 (new).", "010", "10100"); + super("amomax.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the greatest value between value t1 and t0 (new).", "10100"); } @Override - protected int binaryOperation(int value1, int value2) { - return Integer.max(value1, value2); + protected long binaryOperation(long value1, long value2) { + return Long.max(value1, value2); } } diff --git a/src/rars/riscv/instructions/AMOMIND.java b/src/rars/riscv/instructions/AMOMIND.java new file mode 100644 index 00000000..a339e477 --- /dev/null +++ b/src/rars/riscv/instructions/AMOMIND.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOMIND extends AtomicMemoryOperation { + public AMOMIND() { + super("amomin.d t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the lowest value between value t1 and t0 (new).", "10000", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return Long.min(value1, value2); + } +} diff --git a/src/rars/riscv/instructions/AMOMINUD.java b/src/rars/riscv/instructions/AMOMINUD.java new file mode 100644 index 00000000..3f4e5348 --- /dev/null +++ b/src/rars/riscv/instructions/AMOMINUD.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOMINUD extends AtomicMemoryOperation { + public AMOMINUD() { + super("amominu.d t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the lowest unsigned value between value t1 and t0 (new).", "11000", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return Long.compareUnsigned(value1, value2) < 0 ? value1 : value2; + } +} diff --git a/src/rars/riscv/instructions/AMOMINUW.java b/src/rars/riscv/instructions/AMOMINUW.java index cd4f6689..c9ed5836 100644 --- a/src/rars/riscv/instructions/AMOMINUW.java +++ b/src/rars/riscv/instructions/AMOMINUW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOMINUW extends AtomicMemoryOperation { public AMOMINUW() { - super("amominu.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the lowest unsigned value between value t1 and t0 (new).", "010", "11000"); + super("amominu.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the lowest unsigned value between value t1 and t0 (new).", "11000"); } @Override - protected int binaryOperation(int value1, int value2) { - return Integer.compareUnsigned(value1, value2) < 0 ? value1 : value2; + protected long binaryOperation(long value1, long value2) { + return Long.compareUnsigned(value1, value2) < 0 ? value1 : value2; } } diff --git a/src/rars/riscv/instructions/AMOMINW.java b/src/rars/riscv/instructions/AMOMINW.java index 635ac8fd..f2f6d153 100644 --- a/src/rars/riscv/instructions/AMOMINW.java +++ b/src/rars/riscv/instructions/AMOMINW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOMINW extends AtomicMemoryOperation { public AMOMINW() { - super("amomin.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the lowest value between value t1 and t0 (new).", "010", "10000"); + super("amomin.w t0, t1, (t2)", "Loads value at t2 and places it into t0, and saves at memory location t2, the lowest value between value t1 and t0 (new).", "10000"); } @Override - protected int binaryOperation(int value1, int value2) { - return Integer.min(value1, value2); + protected long binaryOperation(long value1, long value2) { + return Long.min(value1, value2); } } diff --git a/src/rars/riscv/instructions/AMOORD.java b/src/rars/riscv/instructions/AMOORD.java new file mode 100644 index 00000000..31a820ab --- /dev/null +++ b/src/rars/riscv/instructions/AMOORD.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOORD extends AtomicMemoryOperation { + public AMOORD() { + super("amoor.d t0, t1, (t2)", "Loads value at t2 and places it into t0, ORS value t1 and t0 (new), and saves at memory location t2.", "01000", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return value1 | value2; + } +} diff --git a/src/rars/riscv/instructions/AMOORW.java b/src/rars/riscv/instructions/AMOORW.java index b574a0f4..8b97511a 100644 --- a/src/rars/riscv/instructions/AMOORW.java +++ b/src/rars/riscv/instructions/AMOORW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOORW extends AtomicMemoryOperation { public AMOORW() { - super("amoor.w t0, t1, (t2)", "Loads value at t2 and places it into t0, ORS value t1 and t0 (new), and saves at memory location t2.", "010", "01000"); + super("amoor.w t0, t1, (t2)", "Loads value at t2 and places it into t0, ORS value t1 and t0 (new), and saves at memory location t2.", "01000"); } @Override - protected int binaryOperation(int value1, int value2) { + protected long binaryOperation(long value1, long value2) { return value1 | value2; } } diff --git a/src/rars/riscv/instructions/AMOSWAPD.java b/src/rars/riscv/instructions/AMOSWAPD.java new file mode 100644 index 00000000..0cdccb0b --- /dev/null +++ b/src/rars/riscv/instructions/AMOSWAPD.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOSWAPD extends AtomicMemoryOperation { + public AMOSWAPD() { + super("amoswap.d t0, t1, (t2)", "Loads value at t2 and places it into t0, saves value t1 at memory location t2.", "00001", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return value2; + } +} diff --git a/src/rars/riscv/instructions/AMOSWAPW.java b/src/rars/riscv/instructions/AMOSWAPW.java index f836f30c..f2522a29 100644 --- a/src/rars/riscv/instructions/AMOSWAPW.java +++ b/src/rars/riscv/instructions/AMOSWAPW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOSWAPW extends AtomicMemoryOperation { public AMOSWAPW() { - super("amoswap.w t0, t1, (t2)", "Loads value at t2 and places it into t0, saves value t1 at memory location t2.", "010", "00001"); + super("amoswap.w t0, t1, (t2)", "Loads value at t2 and places it into t0, saves value t1 at memory location t2.", "00001"); } @Override - protected int binaryOperation(int value1, int value2) { + protected long binaryOperation(long value1, long value2) { return value2; } } diff --git a/src/rars/riscv/instructions/AMOXORD.java b/src/rars/riscv/instructions/AMOXORD.java new file mode 100644 index 00000000..5e558c75 --- /dev/null +++ b/src/rars/riscv/instructions/AMOXORD.java @@ -0,0 +1,39 @@ +package rars.riscv.instructions; + +/* +Copyright (c) 2021, Giancarlo Pernudi Segura + +Developed by Giancarlo Pernudi Segura at the University of Alberta (pernudi@ualberta.ca) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +public class AMOXORD extends AtomicMemoryOperation { + public AMOXORD() { + super("amoxor.d t0, t1, (t2)", "Loads value at t2 and places it into t0, XORS value t1 and t0 (new), and saves at memory location t2.", "00100", true); + } + + @Override + protected long binaryOperation(long value1, long value2) { + return value1 ^ value2; + } +} diff --git a/src/rars/riscv/instructions/AMOXORW.java b/src/rars/riscv/instructions/AMOXORW.java index 6a43df30..10dc0759 100644 --- a/src/rars/riscv/instructions/AMOXORW.java +++ b/src/rars/riscv/instructions/AMOXORW.java @@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the public class AMOXORW extends AtomicMemoryOperation { public AMOXORW() { - super("amoxor.w t0, t1, (t2)", "Loads value at t2 and places it into t0, XORS value t1 and t0 (new), and saves at memory location t2.", "010", "00100"); + super("amoxor.w t0, t1, (t2)", "Loads value at t2 and places it into t0, XORS value t1 and t0 (new), and saves at memory location t2.", "00100"); } @Override - protected int binaryOperation(int value1, int value2) { + protected long binaryOperation(long value1, long value2) { return value1 ^ value2; } } diff --git a/src/rars/riscv/instructions/Atomic.java b/src/rars/riscv/instructions/Atomic.java index 5a8b8ffb..8cd2cf2b 100644 --- a/src/rars/riscv/instructions/Atomic.java +++ b/src/rars/riscv/instructions/Atomic.java @@ -41,4 +41,9 @@ public Atomic(String usage, String description, String funct3, String funct5) { super(usage, description, BasicInstructionFormat.R_FORMAT, funct5 + " 00sssss ttttt " + funct3 + " fffff 0101111"); } + + public Atomic(String usage, String description, String funct3, String funct5, boolean rv64) { + super(usage, description, BasicInstructionFormat.R_FORMAT, + funct5 + " 00sssss ttttt " + funct3 + " fffff 0101111", rv64); + } } diff --git a/src/rars/riscv/instructions/AtomicMemoryOperation.java b/src/rars/riscv/instructions/AtomicMemoryOperation.java index 03cf2f20..88ab194a 100644 --- a/src/rars/riscv/instructions/AtomicMemoryOperation.java +++ b/src/rars/riscv/instructions/AtomicMemoryOperation.java @@ -3,6 +3,7 @@ import rars.Globals; import rars.ProgramStatement; import rars.SimulationException; +import rars.riscv.InstructionSet; import rars.riscv.hardware.AddressErrorException; import rars.riscv.hardware.RegisterFile; @@ -40,8 +41,12 @@ a copy of this software and associated documentation files (the * @version May 2017 */ public abstract class AtomicMemoryOperation extends Atomic { - public AtomicMemoryOperation(String usage, String description, String funct3, String funct5) { - super(usage, description, funct3, funct5); + public AtomicMemoryOperation(String usage, String description, String funct5) { + super(usage, description, "010", funct5); + } + + public AtomicMemoryOperation(String usage, String description, String funct5, boolean rv64) { + super(usage, description, rv64 ? "011" : "010", funct5, rv64); } public void simulate(ProgramStatement statement) throws SimulationException { @@ -49,15 +54,19 @@ public void simulate(ProgramStatement statement) throws SimulationException { try { int rs1Loc = RegisterFile.getValue(operands[2]); Globals.reservationTables.unreserveAddress(0, rs1Loc); - int rs1Data = Globals.memory.getWord(rs1Loc); - int rs2Value = RegisterFile.getValue(operands[1]); + long rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); + long rs2Value = RegisterFile.getValueLong(operands[1]); RegisterFile.updateRegister(operands[0], rs1Data); rs1Data = binaryOperation(rs1Data, rs2Value); - Globals.memory.setWord(rs1Loc, rs1Data); + if (InstructionSet.rv64) { + Globals.memory.setDoubleWord(rs1Loc, rs1Data); + } else { + Globals.memory.setWord(rs1Loc, (int) rs1Data); + } } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } - protected abstract int binaryOperation(int value1, int value2); + protected abstract long binaryOperation(long value1, long value2); } diff --git a/src/rars/riscv/instructions/LRD.java b/src/rars/riscv/instructions/LRD.java new file mode 100644 index 00000000..89ded3c5 --- /dev/null +++ b/src/rars/riscv/instructions/LRD.java @@ -0,0 +1,27 @@ +package rars.riscv.instructions; + +import rars.Globals; +import rars.riscv.hardware.AddressErrorException; +import rars.ProgramStatement; +import rars.SimulationException; +import rars.riscv.hardware.RegisterFile; + +public class LRD extends Atomic { + public LRD() { + super("lr.d t1, (t2)", "Set t1 to contents of effective memory word address and reserve", "011", "00010", true); + } + + public void simulate(ProgramStatement statement) throws SimulationException { + int[] operands = statement.getOperands(); + try { + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1]))); + } catch (AddressErrorException e) { + throw new SimulationException(statement, e); + } + } + + private long load(int address) throws AddressErrorException { + Globals.reservationTables.reserveAddress(0, address); + return Globals.memory.getDoubleWord(address); + } +} diff --git a/src/rars/riscv/instructions/LRW.java b/src/rars/riscv/instructions/LRW.java index 17bb7c95..27731971 100644 --- a/src/rars/riscv/instructions/LRW.java +++ b/src/rars/riscv/instructions/LRW.java @@ -6,7 +6,6 @@ import rars.SimulationException; import rars.riscv.hardware.RegisterFile; - public class LRW extends Atomic { public LRW() { super("lr.w t1, (t2)", "Set t1 to contents of effective memory word address and reserve", "010", "00010"); diff --git a/src/rars/riscv/instructions/SCD.java b/src/rars/riscv/instructions/SCD.java new file mode 100644 index 00000000..2ebef073 --- /dev/null +++ b/src/rars/riscv/instructions/SCD.java @@ -0,0 +1,31 @@ +package rars.riscv.instructions; + +import rars.Globals; +import rars.riscv.hardware.AddressErrorException; +import rars.ProgramStatement; +import rars.SimulationException; +import rars.riscv.hardware.RegisterFile; + +public class SCD extends Atomic { + public SCD() { + super("sc.d t0, t1, (t2)", "Try to store t1 to contents of effective memory word address, sets t0 to store attempt result", "011", "00011", true); + } + + public void simulate(ProgramStatement statement) throws SimulationException { + int[] operands = statement.getOperands(); + try { + long result = store(RegisterFile.getValue(operands[2]), RegisterFile.getValue(operands[1])); + RegisterFile.updateRegister(operands[0], result); + } catch (AddressErrorException e) { + throw new SimulationException(statement, e); + } + } + + private long store(int address, int value) throws AddressErrorException { + if (Globals.reservationTables.unreserveAddress(0, address)) { + Globals.memory.setDoubleWord(address, value); + return 0; + } + return -1; + } +} From 665ec73218f98ff8af036380e1dbd7a2cd2bc303 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 8 Jun 2021 18:22:02 +0530 Subject: [PATCH 35/84] GUI for Harts --- src/rars/Globals.java | 10 + src/rars/tools/ReservationTablesTool.java | 19 +- src/rars/venus/GeneralExecutePane.java | 252 ++++++++++++++++++ src/rars/venus/GeneralMainPane.java | 113 ++++++++ src/rars/venus/GeneralVenusUI.java | 221 +++++++++++++++ .../venus/registers/GeneralRegistersPane.java | 97 +++++++ src/rars/venus/run/RunAssembleAction.java | 19 ++ 7 files changed, 726 insertions(+), 5 deletions(-) create mode 100644 src/rars/venus/GeneralExecutePane.java create mode 100644 src/rars/venus/GeneralMainPane.java create mode 100644 src/rars/venus/GeneralVenusUI.java create mode 100644 src/rars/venus/registers/GeneralRegistersPane.java diff --git a/src/rars/Globals.java b/src/rars/Globals.java index efcb36f6..332d70da 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -7,6 +7,7 @@ import rars.riscv.SyscallNumberOverride; import rars.util.PropertiesFile; import rars.venus.VenusUI; +import rars.venus.GeneralVenusUI; import java.util.ArrayList; import java.util.Enumeration; @@ -147,6 +148,15 @@ public class Globals { private static int harts = 1; + private static ArrayList hartWindows = new ArrayList(); + + + public static ArrayList getHartWindows(){ + GeneralVenusUI temp= new GeneralVenusUI("Window "+0); + hartWindows.add(temp); + return hartWindows; + } + public static int getHarts() { return harts; } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 102cfae4..234ce10a 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -44,7 +44,8 @@ public class ReservationTablesTool extends AbstractToolAndApplication { private static String version = "Version 1.0"; private static String displayPanelTitle; private JPanel displayOptions, hartPanel; - private JComboBox hartWindow; + private JComboBox hartWindowSelector; + protected ArrayList hartWindows = Globals.getHartWindows(); private Integer[] SelectHartWindow(){ Integer hartChoser[]; @@ -59,6 +60,11 @@ private Integer[] SelectHartWindow(){ public ReservationTablesTool() { super(heading + ", " + version, heading); Globals.reservationTables.addObserver(this); + + for(int i = 1; i < Globals.getHarts(); i++){ + GeneralVenusUI temp= new GeneralVenusUI("Window "+i); + hartWindows.add(temp); + } } protected JComponent buildMainDisplayArea() { @@ -85,12 +91,13 @@ public boolean isCellEditable(int row, int column) { panelTools.setBorder(tb); Box displayOptions = Box.createHorizontalBox(); - hartWindow = new JComboBox<>(SelectHartWindow()); - hartWindow.setToolTipText("Technique for determining simulated transmitter device processing delay"); + hartWindowSelector = new JComboBox<>(SelectHartWindow()); + hartWindowSelector.setToolTipText("Technique for determining simulated transmitter device processing delay"); //ToDo----------- - hartWindow.addActionListener( + hartWindowSelector.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { + hartWindows.get(0).setVisible(true); } }); @@ -115,7 +122,7 @@ public void actionPerformed(ActionEvent e) { }); displayOptions.add(Box.createHorizontalGlue()); - displayOptions.add(hartWindow); + displayOptions.add(hartWindowSelector); clearButton.addKeyListener(new EnterKeyListener(clearButton)); displayOptions.add(Box.createHorizontalGlue()); displayOptions.add(clearButton); @@ -165,3 +172,5 @@ protected void reset() { updateDisplay(); } } + + diff --git a/src/rars/venus/GeneralExecutePane.java b/src/rars/venus/GeneralExecutePane.java new file mode 100644 index 00000000..0a53e6d4 --- /dev/null +++ b/src/rars/venus/GeneralExecutePane.java @@ -0,0 +1,252 @@ +package rars.venus; + +import rars.Globals; +import rars.Settings; +import rars.venus.registers.ControlAndStatusWindow; +import rars.venus.registers.FloatingPointWindow; +import rars.venus.registers.RegistersWindow; + +import javax.swing.*; +import java.awt.*; + +/* +Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar + +Developed by Pete Sanderson (psanderson@otterbein.edu) +and Kenneth Vollmar (kenvollmar@missouristate.edu) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +/** + * Container for the execution-related windows. Currently displayed as a tabbed pane. + * + * @author Sanderson and Team JSpim + **/ + +public class GeneralExecutePane extends JDesktopPane { + private RegistersWindow registerValues; + private FloatingPointWindow fpRegValues; + private ControlAndStatusWindow csrValues; + private DataSegmentWindow dataSegment; + private TextSegmentWindow textSegment; + private LabelsWindow labelValues; + private GeneralVenusUI mainUI; + private NumberDisplayBaseChooser valueDisplayBase; + private NumberDisplayBaseChooser addressDisplayBase; + private boolean labelWindowVisible; + + /** + * initialize the Execute pane with major components + * + * @param mainUI the parent GUI + * @param regs window containing integer register set + * @param fpRegs window containing floating point register set + * @param csrRegs window containing the CSR set + */ + + public GeneralExecutePane(GeneralVenusUI mainUI, RegistersWindow regs, FloatingPointWindow fpRegs, ControlAndStatusWindow csrRegs) { + this.mainUI = mainUI; + // Although these are displayed in Data Segment, they apply to all three internal + // windows within the Execute pane. So they will be housed here. + addressDisplayBase = new NumberDisplayBaseChooser("Hexadecimal Addresses", + Globals.getSettings().getBooleanSetting(Settings.Bool.DISPLAY_ADDRESSES_IN_HEX)); + valueDisplayBase = new NumberDisplayBaseChooser("Hexadecimal Values", + Globals.getSettings().getBooleanSetting(Settings.Bool.DISPLAY_VALUES_IN_HEX));//VenusUI.DEFAULT_NUMBER_BASE); + addressDisplayBase.setToolTipText("If checked, displays all memory addresses in hexadecimal. Otherwise, decimal."); + valueDisplayBase.setToolTipText("If checked, displays all memory and register contents in hexadecimal. Otherwise, decimal."); + registerValues = regs; + fpRegValues = fpRegs; + csrValues = csrRegs; + textSegment = new TextSegmentWindow(); + labelValues = new LabelsWindow(); + labelWindowVisible = Globals.getSettings().getBooleanSetting(Settings.Bool.LABEL_WINDOW_VISIBILITY); + this.add(textSegment); // these 3 LOC moved up. DPS 3-Sept-2014 + this.add(labelValues); + textSegment.pack(); // these 3 LOC added. DPS 3-Sept-2014 + labelValues.pack(); + textSegment.setVisible(true); + labelValues.setVisible(labelWindowVisible); + + } + + /** + * This method will set the bounds of this JDesktopPane's internal windows + * relative to the current size of this JDesktopPane. Such an operation + * cannot be adequately done at constructor time because the actual + * size of the desktop pane window is not yet established. Layout manager + * is not a good option here because JDesktopPane does not work well with + * them (the whole idea of using JDesktopPane with internal frames is to + * have mini-frames that you can resize, move around, minimize, etc). This + * method should be invoked only once: the first time the Execute tab is + * selected (a change listener invokes it). We do not want it invoked + * on subsequent tab selections; otherwise, user manipulations of the + * internal frames would be lost the next time execute tab is selected. + */ + public void setWindowBounds() { + + int fullWidth = this.getSize().width - this.getInsets().left - this.getInsets().right; + int fullHeight = this.getSize().height - this.getInsets().top - this.getInsets().bottom; + int halfHeight = fullHeight / 2; + Dimension textDim = new Dimension((int) (fullWidth * .75), halfHeight); + Dimension lablDim = new Dimension((int) (fullWidth * .25), halfHeight); + Dimension textFullDim = new Dimension((int) (fullWidth), halfHeight); + if (labelWindowVisible) { + textSegment.setBounds(0, 0, textDim.width, textDim.height); + labelValues.setBounds(textDim.width + 1, 0, lablDim.width, lablDim.height); + } else { + textSegment.setBounds(0, 0, textFullDim.width, textFullDim.height); + labelValues.setBounds(0, 0, 0, 0); + } + } + + /** + * Show or hide the label window (symbol table). If visible, it is displayed + * to the right of the text segment and the latter is shrunk accordingly. + * + * @param visibility set to true or false + */ + + public void setLabelWindowVisibility(boolean visibility) { + if (!visibility && labelWindowVisible) { + labelWindowVisible = false; + textSegment.setVisible(false); + labelValues.setVisible(false); + setWindowBounds(); + textSegment.setVisible(true); + } else if (visibility && !labelWindowVisible) { + labelWindowVisible = true; + textSegment.setVisible(false); + setWindowBounds(); + textSegment.setVisible(true); + labelValues.setVisible(true); + } + } + + /** + * Clears out all components of the Execute tab: text segment + * display, data segment display, label display and register display. + * This will typically be done upon File->Close, Open, New. + */ + + public void clearPane() { + this.getTextSegmentWindow().clearWindow(); + this.getRegistersWindow().clearWindow(); + this.getFloatingPointWindow().clearWindow(); + this.getControlAndStatusWindow().clearWindow(); + this.getLabelsWindow().clearWindow(); + // seems to be required, to display cleared Execute tab contents... + if (mainUI.getMainPane().getSelectedComponent() == this) { + mainUI.getMainPane().setSelectedComponent(mainUI.getMainPane().getEditTabbedPane()); + mainUI.getMainPane().setSelectedComponent(this); + } + } + + /** + * Access the text segment window. + */ + public TextSegmentWindow getTextSegmentWindow() { + return textSegment; + } + + /** + * Access the register values window. + */ + public RegistersWindow getRegistersWindow() { + return registerValues; + } + + /** + * Access the floating point values window. + */ + public FloatingPointWindow getFloatingPointWindow() { + return fpRegValues; + } + + /** + * Access the Control and Status values window. + */ + public ControlAndStatusWindow getControlAndStatusWindow() { + return csrValues; + } + + /** + * Access the label values window. + */ + public LabelsWindow getLabelsWindow() { + return labelValues; + } + + /** + * Retrieve the number system base for displaying values (mem/register contents) + */ + public int getValueDisplayBase() { + return valueDisplayBase.getBase(); + } + + /** + * Retrieve the number system base for displaying memory addresses + */ + public int getAddressDisplayBase() { + return addressDisplayBase.getBase(); + } + + /** + * Retrieve component used to set numerical base (10 or 16) of data value display. + * + * @return the chooser + */ + public NumberDisplayBaseChooser getValueDisplayBaseChooser() { + return valueDisplayBase; + } + + /** + * Retrieve component used to set numerical base (10 or 16) of address display. + * + * @return the chooser + */ + public NumberDisplayBaseChooser getAddressDisplayBaseChooser() { + return addressDisplayBase; + } + + /** + * Update display of columns based on state of given chooser. Normally + * called only by the chooser's ItemListener. + * + * @param chooser the GUI object manipulated by the user to change number base + */ + public void numberDisplayBaseChanged(NumberDisplayBaseChooser chooser) { + if (chooser == valueDisplayBase) { + // Have all internal windows update their value columns + registerValues.updateRegisters(); + fpRegValues.updateRegisters(); + csrValues.updateRegisters(); + textSegment.updateBasicStatements(); + } else { // addressDisplayBase + // Have all internal windows update their address columns + labelValues.updateLabelAddresses(); + textSegment.updateCodeAddresses(); + textSegment.updateBasicStatements(); + } + } + +} \ No newline at end of file diff --git a/src/rars/venus/GeneralMainPane.java b/src/rars/venus/GeneralMainPane.java new file mode 100644 index 00000000..bab0ddae --- /dev/null +++ b/src/rars/venus/GeneralMainPane.java @@ -0,0 +1,113 @@ +package rars.venus; + +import rars.Globals; +import rars.venus.registers.ControlAndStatusWindow; +import rars.venus.registers.FloatingPointWindow; +import rars.venus.registers.RegistersWindow; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.plaf.basic.BasicTabbedPaneUI; +import java.awt.*; + + + /* +Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar + +Developed by Pete Sanderson (psanderson@otterbein.edu) +and Kenneth Vollmar (kenvollmar@missouristate.edu) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +/** + * Creates the tabbed areas in the UI and also created the internal windows that + * exist in them. + * + * @author Sanderson and Bumgarner + **/ + +public class GeneralMainPane extends JTabbedPane { + GeneralExecutePane executeTab; + EditTabbedPane editTabbedPane; + + private GeneralVenusUI mainUI; + + /** + * Constructor for the MainPane class. + **/ + + public GeneralMainPane(GeneralVenusUI appFrame, RegistersWindow regs, + FloatingPointWindow cop1Regs, ControlAndStatusWindow cop0Regs) { + super(); + this.mainUI = appFrame; + this.setTabPlacement(JTabbedPane.TOP); //LEFT); + if (this.getUI() instanceof BasicTabbedPaneUI) { + BasicTabbedPaneUI ui = (BasicTabbedPaneUI) this.getUI(); + } + + executeTab = new GeneralExecutePane(appFrame, regs, cop1Regs, cop0Regs); + String executeTabTitle = "Execute"; //"
 
E
x
e
c
u
t
e
 
"; + Icon executeTabIcon = null;//new ImageIcon(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource(Globals.imagesPath+"Execute_tab.jpg"))); + + // this.addTab("
 
P
r
o
j
 
1", null, new JTabbedPane()); + // this.addTab("
 
P
r
o
j
 
2", null, new JTabbedPane()); + // this.addTab("
 
P
r
o
j
 
3", null, new JTabbedPane()); + // this.addTab("
 
P
r
o
j
 
4", null, new JTabbedPane()); + + this.addTab(executeTabTitle, executeTabIcon, executeTab); + + this.setToolTipTextAt(0, "View and control assembly language program execution. Enabled upon successful assemble."); + + } + + + /** + * Returns component containing editor display + * + * @return the editor tabbed pane + */ + public JComponent getEditTabbedPane() { + return editTabbedPane; + } + + /** + * returns component containing execution-time display + * + * @return the execute pane + */ + public GeneralExecutePane getExecutePane() { + return executeTab; + } + + /** + * returns component containing execution-time display. + * Same as getExecutePane(). + * + * @return the execute pane + */ + public GeneralExecutePane getExecuteTab() { + return executeTab; + } + +} \ No newline at end of file diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java new file mode 100644 index 00000000..876c916f --- /dev/null +++ b/src/rars/venus/GeneralVenusUI.java @@ -0,0 +1,221 @@ +package rars.venus; + +import rars.Globals; +import rars.Settings; +import rars.riscv.InstructionSet; +import rars.riscv.dump.DumpFormatLoader; +import rars.simulator.Simulator; +import rars.venus.registers.*; +import rars.venus.run.*; +import rars.venus.settings.*; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.net.URL; + +/* +Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar + +Developed by Pete Sanderson (psanderson@otterbein.edu) +and Kenneth Vollmar (kenvollmar@missouristate.edu) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +/** + * Top level container for Venus GUI. + * + * @author Sanderson and Team JSpim + **/ + + /* Heavily modified by Pete Sanderson, July 2004, to incorporate JSPIMMenu and JSPIMToolbar + * not as subclasses of JMenuBar and JToolBar, but as instances of them. They are both + * here primarily so both can share the Action objects. + */ + +public class GeneralVenusUI extends JFrame { + GeneralVenusUI mainUI; + + private GeneralMainPane mainPane; + private GeneralRegistersPane registersPane; + private RegistersWindow registersTab; + private FloatingPointWindow fpTab; + private ControlAndStatusWindow csrTab; + private JSplitPane splitter, horizonSplitter; + JPanel north; + + private int frameState; // see windowActivated() and windowDeactivated() + + // PLEASE PUT THESE TWO (& THEIR METHODS) SOMEWHERE THEY BELONG, NOT HERE + private boolean reset = true; // registers/memory reset for execution + private boolean started = false; // started execution + + /** + * Constructor for the Class. Sets up a window object for the UI + * + * @param s Name of the window to be created. + **/ + + public GeneralVenusUI(String s) { + super(s); + mainUI = this; + + double screenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); + double screenHeight = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); + double mainWidthPct = (screenWidth < 1000.0) ? 0.67 : 0.73; + double mainHeightPct = (screenWidth < 1000.0) ? 0.60 : 0.65; + double registersWidthPct = (screenWidth < 1000.0) ? 0.18 : 0.22; + double registersHeightPct = (screenWidth < 1000.0) ? 0.72 : 0.80; + Dimension mainPanePreferredSize = new Dimension((int) (screenWidth * mainWidthPct), (int) (screenHeight * mainHeightPct)); + Dimension registersPanePreferredSize = new Dimension((int) (screenWidth * registersWidthPct), (int) (screenHeight * registersHeightPct)); + + + Globals.initialize(true); + + // image courtesy of NASA/JPL. + URL im = this.getClass().getResource(Globals.imagesPath + "RISC-V.png"); + if (im == null) { + System.out.println("Internal Error: images folder or file not found"); + System.exit(0); + } + Image mars = Toolkit.getDefaultToolkit().getImage(im); + this.setIconImage(mars); + // Everything in frame will be arranged on JPanel "center", which is only frame component. + // "center" has BorderLayout and 2 major components: + // -- panel (jp) on North with 2 components + // 1. toolbar + // 2. run speed slider. + // -- split pane (horizonSplitter) in center with 2 components side-by-side + // 1. split pane (splitter) with 2 components stacked + // a. main pane, with 2 tabs (edit, execute) + // b. messages pane with 2 tabs (rars, run I/O) + // 2. registers pane with 3 tabs (register file, coproc 0, coproc 1) + // I should probably run this breakdown out to full detail. The components are created + // roughly in bottom-up order; some are created in component constructors and thus are + // not visible here. + + registersTab = new RegistersWindow(); + fpTab = new FloatingPointWindow(); + csrTab = new ControlAndStatusWindow(); + registersPane = new GeneralRegistersPane(mainUI, registersTab, fpTab, csrTab); + registersPane.setPreferredSize(registersPanePreferredSize); + + //Insets defaultTabInsets = (Insets)UIManager.get("TabbedPane.tabInsets"); + //UIManager.put("TabbedPane.tabInsets", new Insets(1, 1, 1, 1)); + mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab); + mainPane.remove(0); + //UIManager.put("TabbedPane.tabInsets", defaultTabInsets); + + mainPane.setPreferredSize(mainPanePreferredSize); + + horizonSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitter, registersPane); + horizonSplitter.setOneTouchExpandable(true); + horizonSplitter.resetToPreferredSizes(); + + JPanel jp = new JPanel(new FlowLayout(FlowLayout.LEFT)); + JPanel center = new JPanel(new BorderLayout()); + center.add(jp, BorderLayout.NORTH); + center.add(horizonSplitter); + + + // This is invoked when opening the app. It will set the app to + // appear at full screen size. + this.addWindowListener( + new WindowAdapter() { + public void windowOpened(WindowEvent e) { + mainUI.setExtendedState(JFrame.MAXIMIZED_BOTH); + } + }); + + this.pack(); + } + + + /** + * To set whether the register values are reset. + * + * @param b Boolean true if the register values have been reset. + **/ + + public void setReset(boolean b) { + reset = b; + } + + /** + * To set whether MIPS program execution has started. + * + * @param b true if the MIPS program execution has started. + **/ + + public void setStarted(boolean b) { + started = b; + } + + /** + * To find out whether the register values are reset. + * + * @return Boolean true if the register values have been reset. + **/ + + public boolean getReset() { + return reset; + } + + /** + * To find out whether MIPS program is currently executing. + * + * @return true if MIPS program is currently executing. + **/ + public boolean getStarted() { + return started; + } + + /** + * Get reference to messages pane associated with this GUI. + * + * @return MessagesPane object associated with the GUI. + **/ + + public GeneralMainPane getMainPane() { + return mainPane; + } + + /** + * Get reference to registers pane associated with this GUI. + * + * @return RegistersPane object associated with the GUI. + **/ + + public GeneralRegistersPane getRegistersPane() { + return registersPane; + } + + + private ImageIcon loadIcon(String name) { + return new ImageIcon(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource(Globals.imagesPath + name))); + } + + private KeyStroke makeShortcut(int key) { + return KeyStroke.getKeyStroke(key, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); + } +} \ No newline at end of file diff --git a/src/rars/venus/registers/GeneralRegistersPane.java b/src/rars/venus/registers/GeneralRegistersPane.java new file mode 100644 index 00000000..c2f96dc9 --- /dev/null +++ b/src/rars/venus/registers/GeneralRegistersPane.java @@ -0,0 +1,97 @@ +package rars.venus.registers; + +import rars.venus.GeneralVenusUI; + +import javax.swing.*; + +/* +Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar + +Developed by Pete Sanderson (psanderson@otterbein.edu) +and Kenneth Vollmar (kenvollmar@missouristate.edu) + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +(MIT license, http://www.opensource.org/licenses/mit-license.html) + */ + +/** + * Contains tabbed areas in the UI to display register contents + * + * @author Sanderson + * @version August 2005 + **/ + +public class GeneralRegistersPane extends JTabbedPane { + private RegistersWindow regsTab; + private FloatingPointWindow fpTab; + private ControlAndStatusWindow csrTab; + + private GeneralVenusUI mainUI; + + /** + * Constructor for the RegistersPane class. + **/ + + public GeneralRegistersPane(GeneralVenusUI appFrame, RegistersWindow regs, FloatingPointWindow cop1, + ControlAndStatusWindow cop0) { + super(); + this.mainUI = appFrame; + regsTab = regs; + fpTab = cop1; + csrTab = cop0; + regsTab.setVisible(true); + fpTab.setVisible(true); + csrTab.setVisible(true); + this.addTab("Registers", regsTab); + this.addTab("Floating Point", fpTab); + this.addTab("Control and Status", csrTab); + this.setToolTipTextAt(0, "CPU registers"); + this.setToolTipTextAt(1, "Floating point unit registers"); + this.setToolTipTextAt(2, "Control and Status registers"); + } + + /** + * Return component containing integer register set. + * + * @return integer register window + */ + public RegistersWindow getRegistersWindow() { + return regsTab; + } + + /** + * Return component containing floating point register set. + * + * @return floating point register window + */ + public FloatingPointWindow getFloatingPointWindow() { + return fpTab; + } + + /** + * Return component containing Control and Status register set. + * + * @return exceptions register window + */ + public ControlAndStatusWindow getControlAndStatusWindow() { + return csrTab; + } +} \ No newline at end of file diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index 7f6b2395..bf3a910f 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -1,11 +1,13 @@ package rars.venus.run; import rars.*; +import rars.Globals; import rars.riscv.hardware.*; import rars.util.FilenameFinder; import rars.util.SystemIO; import rars.venus.*; import rars.venus.registers.RegistersPane; +import rars.venus.registers.GeneralRegistersPane; import javax.swing.*; import java.awt.event.ActionEvent; @@ -51,10 +53,12 @@ public class RunAssembleAction extends GuiAction { // Threshold for adding filename to printed message of files being assembled. private static final int LINE_LENGTH_LIMIT = 60; private VenusUI mainUI; + private GeneralVenusUI gmainUI; public RunAssembleAction(String name, Icon icon, String descrip, Integer mnemonic, KeyStroke accel, VenusUI gui) { super(name, icon, descrip, mnemonic, accel); + gmainUI = Globals.getHartWindows().get(0); mainUI = gui; } @@ -76,6 +80,10 @@ public void actionPerformed(ActionEvent e) { MessagesPane messagesPane = mainUI.getMessagesPane(); ExecutePane executePane = mainUI.getMainPane().getExecutePane(); RegistersPane registersPane = mainUI.getRegistersPane(); + + GeneralExecutePane gexecutePane = gmainUI.getMainPane().getExecutePane(); + GeneralRegistersPane gregistersPane = gmainUI.getRegistersPane(); + extendedAssemblerEnabled = Globals.getSettings().getBooleanSetting(Settings.Bool.EXTENDED_ASSEMBLER_ENABLED); warningsAreErrors = Globals.getSettings().getBooleanSetting(Settings.Bool.WARNINGS_ARE_ERRORS); if (FileStatus.getFile() != null) { @@ -126,6 +134,9 @@ public void actionPerformed(ActionEvent e) { InterruptController.reset(); Globals.reservationTables.reset(); + gexecutePane.getTextSegmentWindow().setupTable(); + gexecutePane.getLabelsWindow().setupTable(); + executePane.getTextSegmentWindow().setupTable(); executePane.getDataSegmentWindow().setupTable(); executePane.getDataSegmentWindow().highlightCellForAddress(Memory.dataBaseAddress); @@ -136,10 +147,18 @@ public void actionPerformed(ActionEvent e) { registersPane.getRegistersWindow().clearWindow(); registersPane.getFloatingPointWindow().clearWindow(); registersPane.getControlAndStatusWindow().clearWindow(); + + gregistersPane.getRegistersWindow().clearWindow(); + gregistersPane.getFloatingPointWindow().clearWindow(); + gregistersPane.getControlAndStatusWindow().clearWindow(); + mainUI.setReset(true); mainUI.setStarted(false); mainUI.getMainPane().setSelectedComponent(executePane); + gmainUI.setReset(true); + gmainUI.setStarted(false); + // Aug. 24, 2005 Ken Vollmar SystemIO.resetFiles(); // Ensure that I/O "file descriptors" are initialized for a new program run From 4fd92f599d16bd9bbfadfb61fc4f62eab1854458 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 8 Jun 2021 19:50:51 +0530 Subject: [PATCH 36/84] Added the GUI for Harts --- src/rars/venus/GeneralExecutePane.java | 15 +++------------ src/rars/venus/GeneralMainPane.java | 11 ----------- src/rars/venus/GeneralVenusUI.java | 12 ++++-------- src/rars/venus/run/RunAssembleAction.java | 3 +++ 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/rars/venus/GeneralExecutePane.java b/src/rars/venus/GeneralExecutePane.java index 0a53e6d4..d46da445 100644 --- a/src/rars/venus/GeneralExecutePane.java +++ b/src/rars/venus/GeneralExecutePane.java @@ -47,7 +47,6 @@ public class GeneralExecutePane extends JDesktopPane { private RegistersWindow registerValues; private FloatingPointWindow fpRegValues; private ControlAndStatusWindow csrValues; - private DataSegmentWindow dataSegment; private TextSegmentWindow textSegment; private LabelsWindow labelValues; private GeneralVenusUI mainUI; @@ -68,12 +67,6 @@ public GeneralExecutePane(GeneralVenusUI mainUI, RegistersWindow regs, FloatingP this.mainUI = mainUI; // Although these are displayed in Data Segment, they apply to all three internal // windows within the Execute pane. So they will be housed here. - addressDisplayBase = new NumberDisplayBaseChooser("Hexadecimal Addresses", - Globals.getSettings().getBooleanSetting(Settings.Bool.DISPLAY_ADDRESSES_IN_HEX)); - valueDisplayBase = new NumberDisplayBaseChooser("Hexadecimal Values", - Globals.getSettings().getBooleanSetting(Settings.Bool.DISPLAY_VALUES_IN_HEX));//VenusUI.DEFAULT_NUMBER_BASE); - addressDisplayBase.setToolTipText("If checked, displays all memory addresses in hexadecimal. Otherwise, decimal."); - valueDisplayBase.setToolTipText("If checked, displays all memory and register contents in hexadecimal. Otherwise, decimal."); registerValues = regs; fpRegValues = fpRegs; csrValues = csrRegs; @@ -81,9 +74,7 @@ public GeneralExecutePane(GeneralVenusUI mainUI, RegistersWindow regs, FloatingP labelValues = new LabelsWindow(); labelWindowVisible = Globals.getSettings().getBooleanSetting(Settings.Bool.LABEL_WINDOW_VISIBILITY); this.add(textSegment); // these 3 LOC moved up. DPS 3-Sept-2014 - this.add(labelValues); textSegment.pack(); // these 3 LOC added. DPS 3-Sept-2014 - labelValues.pack(); textSegment.setVisible(true); labelValues.setVisible(labelWindowVisible); @@ -105,11 +96,12 @@ public GeneralExecutePane(GeneralVenusUI mainUI, RegistersWindow regs, FloatingP public void setWindowBounds() { int fullWidth = this.getSize().width - this.getInsets().left - this.getInsets().right; - int fullHeight = this.getSize().height - this.getInsets().top - this.getInsets().bottom; + int fullHeight = this.getSize().height; int halfHeight = fullHeight / 2; Dimension textDim = new Dimension((int) (fullWidth * .75), halfHeight); Dimension lablDim = new Dimension((int) (fullWidth * .25), halfHeight); Dimension textFullDim = new Dimension((int) (fullWidth), halfHeight); + if (labelWindowVisible) { textSegment.setBounds(0, 0, textDim.width, textDim.height); labelValues.setBounds(textDim.width + 1, 0, lablDim.width, lablDim.height); @@ -138,7 +130,7 @@ public void setLabelWindowVisibility(boolean visibility) { textSegment.setVisible(false); setWindowBounds(); textSegment.setVisible(true); - labelValues.setVisible(true); + labelValues.setVisible(false); } } @@ -156,7 +148,6 @@ public void clearPane() { this.getLabelsWindow().clearWindow(); // seems to be required, to display cleared Execute tab contents... if (mainUI.getMainPane().getSelectedComponent() == this) { - mainUI.getMainPane().setSelectedComponent(mainUI.getMainPane().getEditTabbedPane()); mainUI.getMainPane().setSelectedComponent(this); } } diff --git a/src/rars/venus/GeneralMainPane.java b/src/rars/venus/GeneralMainPane.java index bab0ddae..37915826 100644 --- a/src/rars/venus/GeneralMainPane.java +++ b/src/rars/venus/GeneralMainPane.java @@ -49,7 +49,6 @@ a copy of this software and associated documentation files (the public class GeneralMainPane extends JTabbedPane { GeneralExecutePane executeTab; - EditTabbedPane editTabbedPane; private GeneralVenusUI mainUI; @@ -81,16 +80,6 @@ public GeneralMainPane(GeneralVenusUI appFrame, RegistersWindow regs, } - - /** - * Returns component containing editor display - * - * @return the editor tabbed pane - */ - public JComponent getEditTabbedPane() { - return editTabbedPane; - } - /** * returns component containing execution-time display * diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index 876c916f..8fa90537 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -79,7 +79,6 @@ public class GeneralVenusUI extends JFrame { public GeneralVenusUI(String s) { super(s); mainUI = this; - double screenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); double screenHeight = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); double mainWidthPct = (screenWidth < 1000.0) ? 0.67 : 0.73; @@ -120,15 +119,12 @@ public GeneralVenusUI(String s) { registersPane = new GeneralRegistersPane(mainUI, registersTab, fpTab, csrTab); registersPane.setPreferredSize(registersPanePreferredSize); - //Insets defaultTabInsets = (Insets)UIManager.get("TabbedPane.tabInsets"); - //UIManager.put("TabbedPane.tabInsets", new Insets(1, 1, 1, 1)); mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab); - mainPane.remove(0); - //UIManager.put("TabbedPane.tabInsets", defaultTabInsets); + mainPane.setPreferredSize(mainPanePreferredSize); - horizonSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitter, registersPane); + horizonSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mainPane, registersPane); horizonSplitter.setOneTouchExpandable(true); horizonSplitter.resetToPreferredSizes(); @@ -136,14 +132,14 @@ public GeneralVenusUI(String s) { JPanel center = new JPanel(new BorderLayout()); center.add(jp, BorderLayout.NORTH); center.add(horizonSplitter); - + this.add(center); // This is invoked when opening the app. It will set the app to // appear at full screen size. this.addWindowListener( new WindowAdapter() { public void windowOpened(WindowEvent e) { - mainUI.setExtendedState(JFrame.MAXIMIZED_BOTH); + mainUI.pack(); } }); diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index bf3a910f..c45e5b90 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -137,6 +137,9 @@ public void actionPerformed(ActionEvent e) { gexecutePane.getTextSegmentWindow().setupTable(); gexecutePane.getLabelsWindow().setupTable(); + gexecutePane.getTextSegmentWindow().setCodeHighlighting(true); + gexecutePane.getTextSegmentWindow().highlightStepAtPC(); + executePane.getTextSegmentWindow().setupTable(); executePane.getDataSegmentWindow().setupTable(); executePane.getDataSegmentWindow().highlightCellForAddress(Memory.dataBaseAddress); From 58c3f0520a981753b0758cfdce5c55c0b8f17d93 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Wed, 9 Jun 2021 08:38:41 +0530 Subject: [PATCH 37/84] Bug fix for Window GUI --- src/rars/Globals.java | 2 -- src/rars/tools/ReservationTablesTool.java | 9 +++++++-- src/rars/venus/run/RunAssembleAction.java | 24 +++++++++++++---------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index 332d70da..c5dd8f3e 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -152,8 +152,6 @@ public class Globals { public static ArrayList getHartWindows(){ - GeneralVenusUI temp= new GeneralVenusUI("Window "+0); - hartWindows.add(temp); return hartWindows; } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 234ce10a..843871bf 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -93,11 +93,16 @@ public boolean isCellEditable(int row, int column) { Box displayOptions = Box.createHorizontalBox(); hartWindowSelector = new JComboBox<>(SelectHartWindow()); hartWindowSelector.setToolTipText("Technique for determining simulated transmitter device processing delay"); - //ToDo----------- hartWindowSelector.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { - hartWindows.get(0).setVisible(true); + int i = hartWindowSelector.getSelectedIndex(); + if(i == 0) + return; + else{ + hartWindows.get(i-1).setVisible(true); + } + } }); diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index c45e5b90..858907d4 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -58,7 +58,8 @@ public class RunAssembleAction extends GuiAction { public RunAssembleAction(String name, Icon icon, String descrip, Integer mnemonic, KeyStroke accel, VenusUI gui) { super(name, icon, descrip, mnemonic, accel); - gmainUI = Globals.getHartWindows().get(0); + if(Globals.getHarts() > 1) + gmainUI = Globals.getHartWindows().get(0); mainUI = gui; } @@ -80,9 +81,12 @@ public void actionPerformed(ActionEvent e) { MessagesPane messagesPane = mainUI.getMessagesPane(); ExecutePane executePane = mainUI.getMainPane().getExecutePane(); RegistersPane registersPane = mainUI.getRegistersPane(); - - GeneralExecutePane gexecutePane = gmainUI.getMainPane().getExecutePane(); - GeneralRegistersPane gregistersPane = gmainUI.getRegistersPane(); + GeneralExecutePane gexecutePane = null; + GeneralRegistersPane gregistersPane = null; + if(Globals.getHarts() > 1){ + gexecutePane = gmainUI.getMainPane().getExecutePane(); + gregistersPane = gmainUI.getRegistersPane(); + } extendedAssemblerEnabled = Globals.getSettings().getBooleanSetting(Settings.Bool.EXTENDED_ASSEMBLER_ENABLED); warningsAreErrors = Globals.getSettings().getBooleanSetting(Settings.Bool.WARNINGS_ARE_ERRORS); @@ -133,13 +137,13 @@ public void actionPerformed(ActionEvent e) { ControlAndStatusRegisterFile.resetRegisters(); InterruptController.reset(); Globals.reservationTables.reset(); - + if(Globals.getHarts() > 1){ gexecutePane.getTextSegmentWindow().setupTable(); gexecutePane.getLabelsWindow().setupTable(); gexecutePane.getTextSegmentWindow().setCodeHighlighting(true); gexecutePane.getTextSegmentWindow().highlightStepAtPC(); - + } executePane.getTextSegmentWindow().setupTable(); executePane.getDataSegmentWindow().setupTable(); executePane.getDataSegmentWindow().highlightCellForAddress(Memory.dataBaseAddress); @@ -150,17 +154,17 @@ public void actionPerformed(ActionEvent e) { registersPane.getRegistersWindow().clearWindow(); registersPane.getFloatingPointWindow().clearWindow(); registersPane.getControlAndStatusWindow().clearWindow(); - + if(Globals.getHarts() > 1){ gregistersPane.getRegistersWindow().clearWindow(); gregistersPane.getFloatingPointWindow().clearWindow(); gregistersPane.getControlAndStatusWindow().clearWindow(); - + gmainUI.setReset(true); + gmainUI.setStarted(false); + } mainUI.setReset(true); mainUI.setStarted(false); mainUI.getMainPane().setSelectedComponent(executePane); - gmainUI.setReset(true); - gmainUI.setStarted(false); // Aug. 24, 2005 Ken Vollmar SystemIO.resetFiles(); // Ensure that I/O "file descriptors" are initialized for a new program run From 4875de96774c54c0ae85c0c6060d54779958d973 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Wed, 9 Jun 2021 09:00:30 -0600 Subject: [PATCH 38/84] categorize atomic instructions in statistics tool --- src/rars/tools/InstructionStatistics.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rars/tools/InstructionStatistics.java b/src/rars/tools/InstructionStatistics.java index ef96d88d..1f63d9c9 100644 --- a/src/rars/tools/InstructionStatistics.java +++ b/src/rars/tools/InstructionStatistics.java @@ -259,6 +259,8 @@ protected int getInstructionCategory(Instruction instruction) { return InstructionStatistics.CATEGORY_MEM; // lb, lh, lwl, lw, lbu, lhu, lwr if (instruction instanceof Store) return InstructionStatistics.CATEGORY_MEM; // sb, sh, swl, sw, swr + if (instruction instanceof Atomic) + return InstructionStatistics.CATEGORY_MEM; // a extension return InstructionStatistics.CATEGORY_OTHER; } From 095b7158517a2fabc70eac0466a374a9281692f4 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Wed, 9 Jun 2021 13:08:54 -0600 Subject: [PATCH 39/84] update getInstructionCategory description for instruction support --- src/rars/tools/InstructionStatistics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rars/tools/InstructionStatistics.java b/src/rars/tools/InstructionStatistics.java index 1f63d9c9..dde83937 100644 --- a/src/rars/tools/InstructionStatistics.java +++ b/src/rars/tools/InstructionStatistics.java @@ -226,7 +226,7 @@ protected void addAsObserver() { * decodes the instruction and determines the category of the instruction. *

* The instruction is decoded by checking the java instance of the instruction. - * Only the most relevant instructions are decoded and categorized. + * Supported instructions are RV32I, RV64I, M, and A extensions. * * @param instruction the instruction to decode * @return the category of the instruction From 9cf6d0a623246d535dd099a5851a3423b85dac7c Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Wed, 9 Jun 2021 15:33:41 -0600 Subject: [PATCH 40/84] add mhartid csr --- src/rars/riscv/hardware/ControlAndStatusRegisterFile.java | 4 +++- src/rars/venus/registers/ControlAndStatusWindow.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java index bf1d88dc..0b4bfc66 100644 --- a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java +++ b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java @@ -70,13 +70,15 @@ public class ControlAndStatusRegisterFile { null, // cycleh null, // timeh null, // instreth + null, // mhartid }; tmp[1] = new LinkedRegister("fflags", 0x001, tmp[3], 0x1F); tmp[2] = new LinkedRegister("frm", 0x002, tmp[3], 0xE0); tmp[14] = new LinkedRegister("cycleh", 0xC80,tmp[11], 0xFFFFFFFF_00000000L); tmp[15] = new LinkedRegister("timeh", 0xC81, tmp[12],0xFFFFFFFF_00000000L); - tmp[16] = new LinkedRegister("instreth",0xC82, tmp[13],0xFFFFFFFF_00000000L); + tmp[16] = new LinkedRegister("instreth", 0xC82, tmp[13], 0xFFFFFFFF_00000000L); + tmp[17] = new ReadOnlyRegister("mhartid", 0xF10, 0); instance = new RegisterBlock('_', tmp); // prefix not used } diff --git a/src/rars/venus/registers/ControlAndStatusWindow.java b/src/rars/venus/registers/ControlAndStatusWindow.java index 3fb21358..743ad022 100644 --- a/src/rars/venus/registers/ControlAndStatusWindow.java +++ b/src/rars/venus/registers/ControlAndStatusWindow.java @@ -28,7 +28,8 @@ public class ControlAndStatusWindow extends RegisterBlockWindow { /*instret*/"Instructions retired (same as cycle in RARS)", /*cycleh*/ "High 32 bits of cycle", /*timeh*/ "High 32 bits of time", - /*instreth*/ "High 32 bits of instret" + /*instreth*/ "High 32 bits of instret", + /*mhartid*/"ID of the hardware thread running the code" }; public ControlAndStatusWindow() { @@ -54,4 +55,4 @@ protected void endObserving() { public void resetRegisters() { ControlAndStatusRegisterFile.resetRegisters(); } -} \ No newline at end of file +} From a72d74e92a1f46d83b53b76e7ff5c8704cd655bd Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Wed, 9 Jun 2021 16:28:38 -0600 Subject: [PATCH 41/84] sc.w/d returns unspecified failiure --- src/rars/riscv/instructions/SCD.java | 2 +- src/rars/riscv/instructions/SCW.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rars/riscv/instructions/SCD.java b/src/rars/riscv/instructions/SCD.java index 2ebef073..a70b30b7 100644 --- a/src/rars/riscv/instructions/SCD.java +++ b/src/rars/riscv/instructions/SCD.java @@ -26,6 +26,6 @@ private long store(int address, int value) throws AddressErrorException { Globals.memory.setDoubleWord(address, value); return 0; } - return -1; + return 1; } } diff --git a/src/rars/riscv/instructions/SCW.java b/src/rars/riscv/instructions/SCW.java index 8628db84..d87760c0 100644 --- a/src/rars/riscv/instructions/SCW.java +++ b/src/rars/riscv/instructions/SCW.java @@ -26,6 +26,6 @@ private int store(int address, int value) throws AddressErrorException { Globals.memory.setWord(address, value); return 0; } - return -1; + return 1; } } From d3c92b3de039285ad6e80b98eaeb1773327dab28 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Thu, 10 Jun 2021 07:19:11 +0530 Subject: [PATCH 42/84] Moving the Harts to Globals --- src/rars/tools/ReservationTablesTool.java | 5 +---- src/rars/venus/run/RunAssembleAction.java | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 843871bf..0ec04ffc 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -61,10 +61,7 @@ public ReservationTablesTool() { super(heading + ", " + version, heading); Globals.reservationTables.addObserver(this); - for(int i = 1; i < Globals.getHarts(); i++){ - GeneralVenusUI temp= new GeneralVenusUI("Window "+i); - hartWindows.add(temp); - } + } protected JComponent buildMainDisplayArea() { diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index 858907d4..f483a0af 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -54,10 +54,15 @@ public class RunAssembleAction extends GuiAction { private static final int LINE_LENGTH_LIMIT = 60; private VenusUI mainUI; private GeneralVenusUI gmainUI; + protected ArrayList hartWindows = Globals.getHartWindows(); public RunAssembleAction(String name, Icon icon, String descrip, Integer mnemonic, KeyStroke accel, VenusUI gui) { super(name, icon, descrip, mnemonic, accel); + for(int i = 1; i < Globals.getHarts(); i++){ + GeneralVenusUI temp= new GeneralVenusUI("Window "+i); + hartWindows.add(temp); + } if(Globals.getHarts() > 1) gmainUI = Globals.getHartWindows().get(0); mainUI = gui; From 0e171706ba60476960410fd22659047ac9ff1476 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Thu, 10 Jun 2021 18:37:15 +0530 Subject: [PATCH 43/84] Documentation --- src/rars/venus/GeneralExecutePane.java | 5 ++--- src/rars/venus/GeneralMainPane.java | 7 +++---- src/rars/venus/GeneralVenusUI.java | 5 ++--- src/rars/venus/registers/GeneralRegistersPane.java | 5 ++--- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/rars/venus/GeneralExecutePane.java b/src/rars/venus/GeneralExecutePane.java index d46da445..a2d167c1 100644 --- a/src/rars/venus/GeneralExecutePane.java +++ b/src/rars/venus/GeneralExecutePane.java @@ -10,10 +10,9 @@ import java.awt.*; /* -Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar +Copyright (c) 2003-2006, Siva Chowdeswar Nandipati -Developed by Pete Sanderson (psanderson@otterbein.edu) -and Kenneth Vollmar (kenvollmar@missouristate.edu) +Developed by Siva Chowdeswar Nandipati (sivachow@ualberta.ca) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/rars/venus/GeneralMainPane.java b/src/rars/venus/GeneralMainPane.java index 37915826..d8a08056 100644 --- a/src/rars/venus/GeneralMainPane.java +++ b/src/rars/venus/GeneralMainPane.java @@ -12,11 +12,10 @@ import java.awt.*; - /* -Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar +/* +Copyright (c) 2003-2006, Siva Chowdeswar Nandipati -Developed by Pete Sanderson (psanderson@otterbein.edu) -and Kenneth Vollmar (kenvollmar@missouristate.edu) +Developed by Siva Chowdeswar Nandipati (sivachow@ualberta.ca) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index 8fa90537..ebc0293a 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -15,10 +15,9 @@ import java.net.URL; /* -Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar +Copyright (c) 2003-2006, Siva Chowdeswar Nandipati -Developed by Pete Sanderson (psanderson@otterbein.edu) -and Kenneth Vollmar (kenvollmar@missouristate.edu) +Developed by Siva Chowdeswar Nandipati (sivachow@ualberta.ca) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/rars/venus/registers/GeneralRegistersPane.java b/src/rars/venus/registers/GeneralRegistersPane.java index c2f96dc9..fe10dccb 100644 --- a/src/rars/venus/registers/GeneralRegistersPane.java +++ b/src/rars/venus/registers/GeneralRegistersPane.java @@ -5,10 +5,9 @@ import javax.swing.*; /* -Copyright (c) 2003-2006, Pete Sanderson and Kenneth Vollmar +Copyright (c) 2003-2006, Siva Chowdeswar Nandipati -Developed by Pete Sanderson (psanderson@otterbein.edu) -and Kenneth Vollmar (kenvollmar@missouristate.edu) +Developed by Siva Chowdeswar Nandipati (sivachow@ualberta.ca) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From 0cc38158f6e05ba97db99c86f07a79fa1fb096c3 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 10 Jun 2021 18:46:48 -0600 Subject: [PATCH 44/84] add rv32a unit tests --- test/riscv-tests/amoaddw.s | 55 ++++++++++++++++++++++ test/riscv-tests/amoandw.s | 54 +++++++++++++++++++++ test/riscv-tests/amomaxuw.s | 55 ++++++++++++++++++++++ test/riscv-tests/amomaxw.s | 55 ++++++++++++++++++++++ test/riscv-tests/amominuw.s | 55 ++++++++++++++++++++++ test/riscv-tests/amominw.s | 55 ++++++++++++++++++++++ test/riscv-tests/amoorw.s | 54 +++++++++++++++++++++ test/riscv-tests/amoswapw.s | 54 +++++++++++++++++++++ test/riscv-tests/amoxorw.s | 54 +++++++++++++++++++++ test/riscv-tests/lrsc.s | 93 +++++++++++++++++++++++++++++++++++++ 10 files changed, 584 insertions(+) create mode 100644 test/riscv-tests/amoaddw.s create mode 100644 test/riscv-tests/amoandw.s create mode 100644 test/riscv-tests/amomaxuw.s create mode 100644 test/riscv-tests/amomaxw.s create mode 100644 test/riscv-tests/amominuw.s create mode 100644 test/riscv-tests/amominw.s create mode 100644 test/riscv-tests/amoorw.s create mode 100644 test/riscv-tests/amoswapw.s create mode 100644 test/riscv-tests/amoxorw.s create mode 100644 test/riscv-tests/lrsc.s diff --git a/test/riscv-tests/amoaddw.s b/test/riscv-tests/amoaddw.s new file mode 100644 index 00000000..4bafdd15 --- /dev/null +++ b/test/riscv-tests/amoaddw.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amoadd.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0x000000007ffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + lui a1, 0x80000 + amoadd.w a4, a1, (a3) + lui t2, 0x80000 + addi t2, t2, -2048 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, -2048 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/amoandw.s b/test/riscv-tests/amoandw.s new file mode 100644 index 00000000..3ec5def6 --- /dev/null +++ b/test/riscv-tests/amoandw.s @@ -0,0 +1,54 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amoand.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0xffffffff80000000 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0x80000000 + amoand.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, 0xffffffff80000000 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/amomaxuw.s b/test/riscv-tests/amomaxuw.s new file mode 100644 index 00000000..d0df56e2 --- /dev/null +++ b/test/riscv-tests/amomaxuw.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amomaxu.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0xfffffffffffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0xffffffffffffffff + sw zero, 0(a3) + amomaxu.w a4, a1, (a3) + li t2, 0 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, 0xffffffffffffffff + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/amomaxw.s b/test/riscv-tests/amomaxw.s new file mode 100644 index 00000000..5761a67d --- /dev/null +++ b/test/riscv-tests/amomaxw.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amomax.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0xfffffffffffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 1 + sw zero, 0(a3) + amomax.w a4, a1, (a3) + li t2, 0 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, 1 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/amominuw.s b/test/riscv-tests/amominuw.s new file mode 100644 index 00000000..fdadf1a6 --- /dev/null +++ b/test/riscv-tests/amominuw.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amominu.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0xffffffff80000000 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0xffffffffffffffff + sw zero, 0(a3) + amominu.w a4, a1, (a3) + li t2, 0 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, 0 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/amominw.s b/test/riscv-tests/amominw.s new file mode 100644 index 00000000..82f786a1 --- /dev/null +++ b/test/riscv-tests/amominw.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amomin.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0xffffffff80000000 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0xffffffffffffffff + sw zero, 0(a3) + amomin.w a4, a1, (a3) + li t2, 0 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, 0xffffffffffffffff + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/amoorw.s b/test/riscv-tests/amoorw.s new file mode 100644 index 00000000..8d8e0951 --- /dev/null +++ b/test/riscv-tests/amoorw.s @@ -0,0 +1,54 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amoor.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0xfffffffffffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 1 + amoor.w a4, a1, (a3) + li t2, 0xfffffffffffff800 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, 0xfffffffffffff801 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/amoswapw.s b/test/riscv-tests/amoswapw.s new file mode 100644 index 00000000..8afbd968 --- /dev/null +++ b/test/riscv-tests/amoswapw.s @@ -0,0 +1,54 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amoswap.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0xfffffffffffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0x80000000 + amoswap.w a4, a1, (a3) + li t2, 0xfffffffffffff800 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, 0xffffffff80000000 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/amoxorw.s b/test/riscv-tests/amoxorw.s new file mode 100644 index 00000000..8078f06b --- /dev/null +++ b/test/riscv-tests/amoxorw.s @@ -0,0 +1,54 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sw a0, 0(a3) + amoxor.w a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a5, 0(a3) + li t2, 0x7ffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0xc0000001 + amoxor.w a4, a1, (a3) + li t2, 0x7ffff800 + li gp, 4 + bne a4, t2, fail + +test_5: + lw a5, 0(a3) + li t2, 0xffffffffbffff801 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests/lrsc.s b/test/riscv-tests/lrsc.s new file mode 100644 index 00000000..029af77b --- /dev/null +++ b/test/riscv-tests/lrsc.s @@ -0,0 +1,93 @@ +.data +coreid: .word 0 +barrier: .word 0 +foo: .word 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +# get a unique core id +la a0, coreid +li a1, 1 +amoadd.w a2, a1, (a0) + +# for now, only run this on core 0 +lbl_1: +li a3, 1 +bgeu a2, a3, lbl_1 + +lbl_2: +lw a1, (a0) +bltu a1, a3, lbl_2 + +test_2: + la a0, foo + li a5, 0xdeadbeef + sc.w a4, a5, (a0) + li t2, 1 + li gp, 2 + bne a4, t2, fail + +test_3: + lw a4, foo + li t2, 0 + li gp, 3 + bne a4, t2, fail + +# have each core add its coreid+1 to foo 128 times +la a0, foo +li a1, 0x80 +addi a2, a2, 1 +lbl_3: lr.w a4, (a0) +add a4, a4, a2 +sc.w a4, a4, (a0) +bnez a4, lbl_3 +addi a1, a1, -1 +bnez a1, lbl_3 + +# wait for all cores to finish +la a0, barrier +li a1, 1 +amoadd.w x0, a1, (a0) +lbl_4: lw a1, (a0) +blt a1, a3, lbl_4 +fence 1, 1 + +test_5: + lw a0, foo + slli a1, a3, 6 + lbl_5: sub a0, a0, a1 + addi a3, a3, -1 + bgez a3, lbl_5 + li t2, 0 + li gp, 5 + bne a0, t2, fail + +test_6: + la a0, foo + lbl_6: lr.w a1, (a0) + sc.w a1, x0, (a0) + bnez a1, lbl_6 + sc.w a1, x0 (a0) + li t2, 1 + li gp, 6 + bne a1, t2, fail + +bne zero, gp, pass +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall From 895bfb7ee5d472a682ddb5d2dcc66f55c6e00815 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Fri, 11 Jun 2021 23:44:54 +0530 Subject: [PATCH 45/84] Fixed bugs for more than One Hart --- src/rars/Globals.java | 8 +- src/rars/venus/GeneralVenusUI.java | 4 +- .../venus/registers/RegisterBlockWindow.java | 9 +- src/rars/venus/registers/RegistersWindow.java | 4 + src/rars/venus/run/RunAssembleAction.java | 96 +++++++++---------- src/rars/venus/run/RunGoAction.java | 42 +++++++- 6 files changed, 109 insertions(+), 54 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index c5dd8f3e..e64a0f52 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -146,10 +146,16 @@ public class Globals { public static boolean runSpeedPanelExists = false; - private static int harts = 1; + private static int harts = 2; private static ArrayList hartWindows = new ArrayList(); + public static void setHartWindows(){ + for(int i = 1; i < Globals.getHarts(); i++){ + GeneralVenusUI temp= new GeneralVenusUI("Window "+i); + hartWindows.add(temp); + } + } public static ArrayList getHartWindows(){ return hartWindows; diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index ebc0293a..048ee64e 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -86,8 +86,6 @@ public GeneralVenusUI(String s) { double registersHeightPct = (screenWidth < 1000.0) ? 0.72 : 0.80; Dimension mainPanePreferredSize = new Dimension((int) (screenWidth * mainWidthPct), (int) (screenHeight * mainHeightPct)); Dimension registersPanePreferredSize = new Dimension((int) (screenWidth * registersWidthPct), (int) (screenHeight * registersHeightPct)); - - Globals.initialize(true); // image courtesy of NASA/JPL. @@ -112,7 +110,7 @@ public GeneralVenusUI(String s) { // roughly in bottom-up order; some are created in component constructors and thus are // not visible here. - registersTab = new RegistersWindow(); + registersTab = new RegistersWindow("Not GUI"); fpTab = new FloatingPointWindow(); csrTab = new ControlAndStatusWindow(); registersPane = new GeneralRegistersPane(mainUI, registersTab, fpTab, csrTab); diff --git a/src/rars/venus/registers/RegisterBlockWindow.java b/src/rars/venus/registers/RegisterBlockWindow.java index 7c94713e..0550261f 100644 --- a/src/rars/venus/registers/RegisterBlockWindow.java +++ b/src/rars/venus/registers/RegisterBlockWindow.java @@ -61,6 +61,7 @@ public abstract class RegisterBlockWindow extends JPanel implements Observer { private boolean highlighting; private int highlightRow; private Register[] registers; + private boolean notMainUI = true; private static final int NAME_COLUMN = 0; private static final int NUMBER_COLUMN = 1; @@ -93,6 +94,11 @@ public RegisterBlockWindow(Register[] registers, String[] registerDescriptions, this.add(new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); } + public RegisterBlockWindow(Register[] registers2, String[] regtooltips, String string, String string2) { + this(registers2, regtooltips, string); + notMainUI = false; + } + protected abstract String formatRegister(Register value, int base); protected abstract void beginObserving(); @@ -203,7 +209,8 @@ public void update(Observable observable, Object obj) { // AddressCellRenderer class in DataSegmentWindow.java. this.highlighting = true; this.highlightCellForRegister((Register) observable); - Globals.getGui().getRegistersPane().setSelectedComponent(this); + if(notMainUI) + Globals.getGui().getRegistersPane().setSelectedComponent(this); } } } diff --git a/src/rars/venus/registers/RegistersWindow.java b/src/rars/venus/registers/RegistersWindow.java index 694cb4b4..eb5b5282 100644 --- a/src/rars/venus/registers/RegistersWindow.java +++ b/src/rars/venus/registers/RegistersWindow.java @@ -52,6 +52,10 @@ public RegistersWindow() { super(getRegisters(), regToolTips, "Current 32 bit value"); } + public RegistersWindow(String s){ + super(getRegisters(), regToolTips, "Current 32 bit value", "GeneralGUI"); + } + /* * A simple wrapper to add pc into the Registers array */ diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index f483a0af..9ba147be 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -13,8 +13,8 @@ import java.awt.event.ActionEvent; import java.io.File; import java.util.ArrayList; - - /* + +/* Copyright (c) 2003-2010, Pete Sanderson and Kenneth Vollmar Developed by Pete Sanderson (psanderson@otterbein.edu) @@ -40,7 +40,7 @@ a copy of this software and associated documentation files (the WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (MIT license, http://www.opensource.org/licenses/mit-license.html) - */ +*/ /** * Action class for the Run -> Assemble menu item (and toolbar icon) @@ -53,22 +53,16 @@ public class RunAssembleAction extends GuiAction { // Threshold for adding filename to printed message of files being assembled. private static final int LINE_LENGTH_LIMIT = 60; private VenusUI mainUI; - private GeneralVenusUI gmainUI; protected ArrayList hartWindows = Globals.getHartWindows(); - public RunAssembleAction(String name, Icon icon, String descrip, - Integer mnemonic, KeyStroke accel, VenusUI gui) { + public RunAssembleAction(String name, Icon icon, String descrip, Integer mnemonic, KeyStroke accel, VenusUI gui) { super(name, icon, descrip, mnemonic, accel); - for(int i = 1; i < Globals.getHarts(); i++){ - GeneralVenusUI temp= new GeneralVenusUI("Window "+i); - hartWindows.add(temp); - } - if(Globals.getHarts() > 1) - gmainUI = Globals.getHartWindows().get(0); + Globals.setHartWindows(); mainUI = gui; } - // These are both used by RunResetAction to re-assemble under identical conditions. + // These are both used by RunResetAction to re-assemble under identical + // conditions. public static ArrayList getProgramsToAssemble() { return programsToAssemble; } @@ -86,11 +80,12 @@ public void actionPerformed(ActionEvent e) { MessagesPane messagesPane = mainUI.getMessagesPane(); ExecutePane executePane = mainUI.getMainPane().getExecutePane(); RegistersPane registersPane = mainUI.getRegistersPane(); - GeneralExecutePane gexecutePane = null; - GeneralRegistersPane gregistersPane = null; - if(Globals.getHarts() > 1){ - gexecutePane = gmainUI.getMainPane().getExecutePane(); - gregistersPane = gmainUI.getRegistersPane(); + ArrayList gexecutePanes = new ArrayList<>(); + ArrayList gregistersPanes = new ArrayList<>(); + + for (int i = 0; i < hartWindows.size(); i++) { + gexecutePanes.add(hartWindows.get(i).getMainPane().getExecutePane()); + gregistersPanes.add(hartWindows.get(i).getRegistersPane()); } extendedAssemblerEnabled = Globals.getSettings().getBooleanSetting(Settings.Bool.EXTENDED_ASSEMBLER_ENABLED); @@ -102,9 +97,10 @@ public void actionPerformed(ActionEvent e) { try { Globals.program = new RISCVprogram(); ArrayList filesToAssemble; - if (Globals.getSettings().getBooleanSetting(Settings.Bool.ASSEMBLE_ALL)) {// setting calls for multiple file assembly - filesToAssemble = FilenameFinder.getFilenameList( - new File(FileStatus.getName()).getParent(), Globals.fileExtensions); + if (Globals.getSettings().getBooleanSetting(Settings.Bool.ASSEMBLE_ALL)) {// setting calls for multiple + // file assembly + filesToAssemble = FilenameFinder.getFilenameList(new File(FileStatus.getName()).getParent(), + Globals.fileExtensions); } else { filesToAssemble = new ArrayList<>(); filesToAssemble.add(FileStatus.getName()); @@ -119,12 +115,13 @@ public void actionPerformed(ActionEvent e) { } } String exceptionHandler = null; - if (Globals.getSettings().getBooleanSetting(Settings.Bool.EXCEPTION_HANDLER_ENABLED) && - Globals.getSettings().getExceptionHandler() != null && - Globals.getSettings().getExceptionHandler().length() > 0) { + if (Globals.getSettings().getBooleanSetting(Settings.Bool.EXCEPTION_HANDLER_ENABLED) + && Globals.getSettings().getExceptionHandler() != null + && Globals.getSettings().getExceptionHandler().length() > 0) { exceptionHandler = Globals.getSettings().getExceptionHandler(); } - programsToAssemble = Globals.program.prepareFilesForAssembly(filesToAssemble, FileStatus.getFile().getPath(), exceptionHandler); + programsToAssemble = Globals.program.prepareFilesForAssembly(filesToAssemble, + FileStatus.getFile().getPath(), exceptionHandler); messagesPane.postMessage(buildFileNameList(name + ": assembling ", programsToAssemble)); // added logic to receive any warnings and output them.... DPS 11/28/06 ErrorList warnings = Globals.program.assemble(programsToAssemble, extendedAssemblerEnabled, @@ -132,8 +129,7 @@ public void actionPerformed(ActionEvent e) { if (warnings.warningsOccurred()) { messagesPane.postMessage(warnings.generateWarningReport()); } - messagesPane.postMessage( - name + ": operation completed successfully.\n\n"); + messagesPane.postMessage(name + ": operation completed successfully.\n\n"); FileStatus.setAssembled(true); FileStatus.set(FileStatus.RUNNABLE); @@ -142,12 +138,12 @@ public void actionPerformed(ActionEvent e) { ControlAndStatusRegisterFile.resetRegisters(); InterruptController.reset(); Globals.reservationTables.reset(); - if(Globals.getHarts() > 1){ - gexecutePane.getTextSegmentWindow().setupTable(); - gexecutePane.getLabelsWindow().setupTable(); + for (int i = 0; i < hartWindows.size(); i++) { + gexecutePanes.get(i).getTextSegmentWindow().setupTable(); + gexecutePanes.get(i).getLabelsWindow().setupTable(); - gexecutePane.getTextSegmentWindow().setCodeHighlighting(true); - gexecutePane.getTextSegmentWindow().highlightStepAtPC(); + gexecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); + gexecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(); } executePane.getTextSegmentWindow().setupTable(); executePane.getDataSegmentWindow().setupTable(); @@ -159,42 +155,46 @@ public void actionPerformed(ActionEvent e) { registersPane.getRegistersWindow().clearWindow(); registersPane.getFloatingPointWindow().clearWindow(); registersPane.getControlAndStatusWindow().clearWindow(); - if(Globals.getHarts() > 1){ - gregistersPane.getRegistersWindow().clearWindow(); - gregistersPane.getFloatingPointWindow().clearWindow(); - gregistersPane.getControlAndStatusWindow().clearWindow(); - gmainUI.setReset(true); - gmainUI.setStarted(false); + for(int i = 0; i < hartWindows.size(); i++){ + gregistersPanes.get(i).getRegistersWindow().clearWindow(); + gregistersPanes.get(i).getFloatingPointWindow().clearWindow(); + gregistersPanes.get(i).getControlAndStatusWindow().clearWindow(); + hartWindows.get(i).setReset(true); + hartWindows.get(i).setStarted(false); } mainUI.setReset(true); mainUI.setStarted(false); mainUI.getMainPane().setSelectedComponent(executePane); - // Aug. 24, 2005 Ken Vollmar - SystemIO.resetFiles(); // Ensure that I/O "file descriptors" are initialized for a new program run + SystemIO.resetFiles(); // Ensure that I/O "file descriptors" are initialized for a new program run } catch (AssemblyException pe) { String errorReport = pe.errors().generateErrorAndWarningReport(); messagesPane.postMessage(errorReport); - messagesPane.postMessage( - name + ": operation completed with errors.\n\n"); + messagesPane.postMessage(name + ": operation completed with errors.\n\n"); // Select editor line containing first error, and corresponding error message. ArrayList errorMessages = pe.errors().getErrorMessages(); for (ErrorMessage em : errorMessages) { - // No line or position may mean File Not Found (e.g. exception file). Don't try to open. DPS 3-Oct-2010 + // No line or position may mean File Not Found (e.g. exception file). Don't try + // to open. DPS 3-Oct-2010 if (em.getLine() == 0 && em.getPosition() == 0) { continue; } if (!em.isWarning() || warningsAreErrors) { - Globals.getGui().getMessagesPane().selectErrorMessage(em.getFilename(), em.getLine(), em.getPosition()); - // Bug workaround: Line selection does not work correctly for the JEditTextArea editor - // when the file is opened then automatically assembled (assemble-on-open setting). + Globals.getGui().getMessagesPane().selectErrorMessage(em.getFilename(), em.getLine(), + em.getPosition()); + // Bug workaround: Line selection does not work correctly for the JEditTextArea + // editor + // when the file is opened then automatically assembled (assemble-on-open + // setting). // Automatic assemble happens in EditTabbedPane's openFile() method, by invoking - // this method (actionPerformed) explicitly with null argument. Thus e!=null test. + // this method (actionPerformed) explicitly with null argument. Thus e!=null + // test. // DPS 9-Aug-2010 if (e != null) { - Globals.getGui().getMessagesPane().selectEditorTextLine(em.getFilename(), em.getLine(), em.getPosition()); + Globals.getGui().getMessagesPane().selectEditorTextLine(em.getFilename(), em.getLine(), + em.getPosition()); } break; } diff --git a/src/rars/venus/run/RunGoAction.java b/src/rars/venus/run/RunGoAction.java index d4c152dc..3d5bd5b1 100644 --- a/src/rars/venus/run/RunGoAction.java +++ b/src/rars/venus/run/RunGoAction.java @@ -10,12 +10,15 @@ import rars.util.SystemIO; import rars.venus.ExecutePane; import rars.venus.FileStatus; +import rars.venus.GeneralExecutePane; +import rars.venus.GeneralVenusUI; import rars.venus.GuiAction; import rars.venus.VenusUI; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.util.ArrayList; import java.util.Observable; import java.util.Observer; @@ -56,7 +59,9 @@ public class RunGoAction extends GuiAction { public static int maxSteps = defaultMaxSteps; private String name; private ExecutePane executePane; + private ArrayList gexecutePanes = new ArrayList<>(); private VenusUI mainUI; + protected ArrayList hartWindows = Globals.getHartWindows(); public RunGoAction(String name, Icon icon, String descrip, Integer mnemonic, KeyStroke accel, VenusUI gui) { @@ -70,6 +75,9 @@ public RunGoAction(String name, Icon icon, String descrip, public void actionPerformed(ActionEvent e) { name = this.getValue(Action.NAME).toString(); executePane = mainUI.getMainPane().getExecutePane(); + for(int i = 0; i < hartWindows.size(); i++){ + gexecutePanes.add(hartWindows.get(i).getMainPane().getExecutePane()); + } if (FileStatus.isAssembled()) { if (!mainUI.getStarted()) { processProgramArgumentsIfAny(); // DPS 17-July-2008 @@ -77,12 +85,18 @@ public void actionPerformed(ActionEvent e) { if (mainUI.getReset() || mainUI.getStarted()) { mainUI.setStarted(true); // added 8/27/05 - + for(int i = 0; i < hartWindows.size(); i++){ + hartWindows.get(i).setStarted(true); + } mainUI.getMessagesPane().postMessage( name + ": running " + FileStatus.getFile().getName() + "\n\n"); mainUI.getMessagesPane().selectRunMessageTab(); executePane.getTextSegmentWindow().setCodeHighlighting(false); executePane.getTextSegmentWindow().unhighlightAllSteps(); + for(int i = 0; i < hartWindows.size(); i++){ + gexecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(false); + gexecutePanes.get(i).getTextSegmentWindow().unhighlightAllSteps(); + } //FileStatus.set(FileStatus.RUNNING); mainUI.setMenuState(FileStatus.RUNNING); @@ -142,6 +156,15 @@ public void paused(boolean done, Simulator.Reason pauseReason, SimulationExcepti executePane.getFloatingPointWindow().updateRegisters(); executePane.getControlAndStatusWindow().updateRegisters(); executePane.getDataSegmentWindow().updateValues(); + for(int i = 0; i < hartWindows.size(); i++){ + gexecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); + gexecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(); + gexecutePanes.get(i).getRegistersWindow().updateRegisters(); + gexecutePanes.get(i).getFloatingPointWindow().updateRegisters(); + gexecutePanes.get(i).getControlAndStatusWindow().updateRegisters(); + hartWindows.get(i).setReset(false); + + } FileStatus.set(FileStatus.RUNNABLE); mainUI.setReset(false); } @@ -159,14 +182,26 @@ public void stopped(SimulationException pe, Simulator.Reason reason) { executePane.getFloatingPointWindow().updateRegisters(); executePane.getControlAndStatusWindow().updateRegisters(); executePane.getDataSegmentWindow().updateValues(); + for(int i = 0; i < hartWindows.size(); i++){ + gexecutePanes.get(i).getRegistersWindow().updateRegisters(); + gexecutePanes.get(i).getFloatingPointWindow().updateRegisters(); + gexecutePanes.get(i).getControlAndStatusWindow().updateRegisters(); + } FileStatus.set(FileStatus.TERMINATED); SystemIO.resetFiles(); // close any files opened in MIPS program // Bring CSRs to the front if terminated due to exception. if (pe != null) { + mainUI.getRegistersPane().setSelectedComponent(executePane.getControlAndStatusWindow()); executePane.getTextSegmentWindow().setCodeHighlighting(true); executePane.getTextSegmentWindow().unhighlightAllSteps(); executePane.getTextSegmentWindow().highlightStepAtAddress(RegisterFile.getProgramCounter() - 4); + for(int i = 0; i < hartWindows.size(); i++){ + hartWindows.get(i).getRegistersPane().setSelectedComponent(executePane.getControlAndStatusWindow()); + gexecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); + gexecutePanes.get(i).getTextSegmentWindow().unhighlightAllSteps(); + gexecutePanes.get(i).getTextSegmentWindow().highlightStepAtAddress(RegisterFile.getProgramCounter() - 4); + } } switch (reason) { case NORMAL_TERMINATION: @@ -204,6 +239,11 @@ public void stopped(SimulationException pe, Simulator.Reason reason) { } RunGoAction.resetMaxSteps(); mainUI.setReset(false); + for(int i = 0; i < hartWindows.size(); i++){ + hartWindows.get(i).setReset(false); + } + + } /** From 988346a2bb7a9eb364f6e238a9646fa84b0e183e Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 11 Jun 2021 14:02:38 -0600 Subject: [PATCH 46/84] add rv64a unit tests --- test/riscv-tests-64/amoaddd.s | 53 ++++++++++++++++++++++++++++++++ test/riscv-tests-64/amoandd.s | 54 +++++++++++++++++++++++++++++++++ test/riscv-tests-64/amomaxd.s | 55 ++++++++++++++++++++++++++++++++++ test/riscv-tests-64/amomaxud.s | 55 ++++++++++++++++++++++++++++++++++ test/riscv-tests-64/amomind.s | 55 ++++++++++++++++++++++++++++++++++ test/riscv-tests-64/amominud.s | 55 ++++++++++++++++++++++++++++++++++ test/riscv-tests-64/amoord.s | 54 +++++++++++++++++++++++++++++++++ test/riscv-tests-64/amoswapd.s | 54 +++++++++++++++++++++++++++++++++ test/riscv-tests-64/amoxord.s | 54 +++++++++++++++++++++++++++++++++ 9 files changed, 489 insertions(+) create mode 100644 test/riscv-tests-64/amoaddd.s create mode 100644 test/riscv-tests-64/amoandd.s create mode 100644 test/riscv-tests-64/amomaxd.s create mode 100644 test/riscv-tests-64/amomaxud.s create mode 100644 test/riscv-tests-64/amomind.s create mode 100644 test/riscv-tests-64/amominud.s create mode 100644 test/riscv-tests-64/amoord.s create mode 100644 test/riscv-tests-64/amoswapd.s create mode 100644 test/riscv-tests-64/amoxord.s diff --git a/test/riscv-tests-64/amoaddd.s b/test/riscv-tests-64/amoaddd.s new file mode 100644 index 00000000..bb6f25ab --- /dev/null +++ b/test/riscv-tests-64/amoaddd.s @@ -0,0 +1,53 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amoadd.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0xffffffff7ffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + amoadd.d a4, a1, (a3) + li t2, 0xffffffff7ffff800 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 0xffffffff7ffff000 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests-64/amoandd.s b/test/riscv-tests-64/amoandd.s new file mode 100644 index 00000000..b5182ce7 --- /dev/null +++ b/test/riscv-tests-64/amoandd.s @@ -0,0 +1,54 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amoand.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0xffffffff80000000 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0x0000000080000000 + amoand.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 0x0000000080000000 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests-64/amomaxd.s b/test/riscv-tests-64/amomaxd.s new file mode 100644 index 00000000..8ff48a4f --- /dev/null +++ b/test/riscv-tests-64/amomaxd.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amomax.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0xfffffffffffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 1 + sd x0, 0(a3) + amomax.d a4, a1, (a3) + li t2, 0 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 1 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests-64/amomaxud.s b/test/riscv-tests-64/amomaxud.s new file mode 100644 index 00000000..a8a3281c --- /dev/null +++ b/test/riscv-tests-64/amomaxud.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amomaxu.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0xfffffffffffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0xffffffffffffffff + sd x0, 0(a3) + amomaxu.d a4, a1, (a3) + li t2, 0 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 0xffffffffffffffff + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests-64/amomind.s b/test/riscv-tests-64/amomind.s new file mode 100644 index 00000000..142aa1ff --- /dev/null +++ b/test/riscv-tests-64/amomind.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amomin.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0xffffffff80000000 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0xffffffffffffffff + sd x0, 0(a3) + amomin.d a4, a1, (a3) + li t2, 0 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 0xffffffffffffffff + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests-64/amominud.s b/test/riscv-tests-64/amominud.s new file mode 100644 index 00000000..59e674b8 --- /dev/null +++ b/test/riscv-tests-64/amominud.s @@ -0,0 +1,55 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amominu.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0xffffffff80000000 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0xffffffffffffffff + sd x0, 0(a3) + amominu.d a4, a1, (a3) + li t2, 0 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 0 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests-64/amoord.s b/test/riscv-tests-64/amoord.s new file mode 100644 index 00000000..cc376e46 --- /dev/null +++ b/test/riscv-tests-64/amoord.s @@ -0,0 +1,54 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amoor.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0xfffffffffffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 1 + amoor.d a4, a1, (a3) + li t2, 0xfffffffffffff800 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 0xfffffffffffff801 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests-64/amoswapd.s b/test/riscv-tests-64/amoswapd.s new file mode 100644 index 00000000..d6060d99 --- /dev/null +++ b/test/riscv-tests-64/amoswapd.s @@ -0,0 +1,54 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amoswap.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0xfffffffffffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 0x0000000080000000 + amoswap.d a4, a1, (a3) + li t2, 0xfffffffffffff800 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 0x0000000080000000 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall diff --git a/test/riscv-tests-64/amoxord.s b/test/riscv-tests-64/amoxord.s new file mode 100644 index 00000000..6dfc27d2 --- /dev/null +++ b/test/riscv-tests-64/amoxord.s @@ -0,0 +1,54 @@ +.data +.align 3 +amo_operand: .dword 0 + +.text +main: + #------------------------------------------------------------- + # Atomic tests + #------------------------------------------------------------- + +test_2: + li a0, 0xffffffff80000000 + li a1, 0xfffffffffffff800 + la a3, amo_operand + sd a0, 0(a3) + amoxor.d a4, a1, (a3) + li t2, 0xffffffff80000000 + li gp, 2 + bne a4, t2, fail + +test_3: + ld a5, 0(a3) + li t2, 0x000000007ffff800 + li gp, 3 + bne a5, t2, fail + +test_4: + li a1, 1 + amoxor.d a4, a1, (a3) + li t2, 0x000000007ffff800 + li gp, 4 + bne a4, t2, fail + +test_5: + ld a5, 0(a3) + li t2, 0x000000007ffff801 + li gp, 5 + bne a5, t2, fail + bne zero, gp, pass + +fail: + fence 1, 1 + slli gp, gp, 0x1 + ori gp, gp, 1 + li a7, 93 + mv a0, gp + ecall + +pass: + fence 1, 1 + li gp, 1 + li a7, 93 + li a0, 42 + ecall From fc77595b423c391889ea6d4d29e0c96e4a68e178 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Wed, 16 Jun 2021 16:53:43 +0530 Subject: [PATCH 47/84] All Harts work alike --- src/rars/Globals.java | 2 ++ src/rars/venus/run/RunAssembleAction.java | 8 +++-- src/rars/venus/run/RunStepAction.java | 44 ++++++++++++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index e64a0f52..862ebb6e 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -62,6 +62,8 @@ public class Globals { * the program currently being worked with. Used by GUI only, not command line. **/ public static RISCVprogram program; + + public static ArrayList gPrograms; /** * Symbol table for file currently being assembled. **/ diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index 9ba147be..74ef9aa4 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -48,6 +48,7 @@ a copy of this software and associated documentation files (the public class RunAssembleAction extends GuiAction { private static ArrayList programsToAssemble; + private static ArrayList> gProgramsToAssemble; private static boolean extendedAssemblerEnabled; private static boolean warningsAreErrors; // Threshold for adding filename to printed message of files being assembled. @@ -96,6 +97,10 @@ public void actionPerformed(ActionEvent e) { } try { Globals.program = new RISCVprogram(); + Globals.gPrograms = new ArrayList<>(); + for (int i = 0; i < hartWindows.size(); i++){ + Globals.gPrograms.add(new RISCVprogram()); + } ArrayList filesToAssemble; if (Globals.getSettings().getBooleanSetting(Settings.Bool.ASSEMBLE_ALL)) {// setting calls for multiple // file assembly @@ -132,7 +137,7 @@ public void actionPerformed(ActionEvent e) { messagesPane.postMessage(name + ": operation completed successfully.\n\n"); FileStatus.setAssembled(true); FileStatus.set(FileStatus.RUNNABLE); - + //TODO RegisterFile.resetRegisters(); FloatingPointRegisterFile.resetRegisters(); ControlAndStatusRegisterFile.resetRegisters(); @@ -141,7 +146,6 @@ public void actionPerformed(ActionEvent e) { for (int i = 0; i < hartWindows.size(); i++) { gexecutePanes.get(i).getTextSegmentWindow().setupTable(); gexecutePanes.get(i).getLabelsWindow().setupTable(); - gexecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); gexecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(); } diff --git a/src/rars/venus/run/RunStepAction.java b/src/rars/venus/run/RunStepAction.java index 96b86bae..1a0ad7fc 100644 --- a/src/rars/venus/run/RunStepAction.java +++ b/src/rars/venus/run/RunStepAction.java @@ -11,10 +11,13 @@ import rars.venus.FileStatus; import rars.venus.GuiAction; import rars.venus.VenusUI; +import rars.venus.GeneralVenusUI; +import rars.venus.GeneralExecutePane; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; +import java.util.ArrayList; import java.util.Observable; import java.util.Observer; @@ -53,12 +56,14 @@ public class RunStepAction extends GuiAction { private String name; private ExecutePane executePane; + private ArrayList gExecutePanes; private VenusUI mainUI; - + private ArrayList hartWindows; public RunStepAction(String name, Icon icon, String descrip, Integer mnemonic, KeyStroke accel, VenusUI gui) { super(name, icon, descrip, mnemonic, accel); mainUI = gui; + hartWindows = Globals.getHartWindows(); } /** @@ -67,6 +72,10 @@ public RunStepAction(String name, Icon icon, String descrip, public void actionPerformed(ActionEvent e) { name = this.getValue(Action.NAME).toString(); executePane = mainUI.getMainPane().getExecutePane(); + gExecutePanes = new ArrayList<>(); + for(int i = 0; i < hartWindows.size(); i++){ + gExecutePanes.add(hartWindows.get(i).getMainPane().getExecutePane()); + } if (FileStatus.isAssembled()) { if (!mainUI.getStarted()) { // DPS 17-July-2008 processProgramArgumentsIfAny(); @@ -74,6 +83,10 @@ public void actionPerformed(ActionEvent e) { mainUI.setStarted(true); mainUI.getMessagesPane().selectRunMessageTab(); executePane.getTextSegmentWindow().setCodeHighlighting(true); + for(int i = 0; i < hartWindows.size(); i++){ + hartWindows.get(i).setStarted(true); + gExecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); + } // Setup callback for after step finishes final Observer stopListener = @@ -88,6 +101,9 @@ public void update(Observable o, Object simulator) { Simulator.getInstance().addObserver(stopListener); Globals.program.startSimulation(1, null); + for(int i = 0; i < hartWindows.size(); i++){ + Globals.gPrograms.get(i).startSimulation(1, null); + } } else { // note: this should never occur since "Step" is only enabled after successful assembly. JOptionPane.showMessageDialog(mainUI, "The program must be assembled before it can be run."); @@ -101,13 +117,25 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p executePane.getFloatingPointWindow().updateRegisters(); executePane.getControlAndStatusWindow().updateRegisters(); executePane.getDataSegmentWindow().updateValues(); + + for(int i = 0; i < hartWindows.size(); i++){ + gExecutePanes.get(i).getRegistersWindow().updateRegisters(); + gExecutePanes.get(i).getFloatingPointWindow().updateRegisters(); + gExecutePanes.get(i).getControlAndStatusWindow().updateRegisters(); + } if (!done) { + for(int i = 0; i < hartWindows.size(); i++){ + gExecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(); + } executePane.getTextSegmentWindow().highlightStepAtPC(); FileStatus.set(FileStatus.RUNNABLE); } if (done) { RunGoAction.resetMaxSteps(); executePane.getTextSegmentWindow().unhighlightAllSteps(); + for(int i = 0; i < hartWindows.size(); i++){ + gExecutePanes.get(i).getTextSegmentWindow().unhighlightAllSteps(); + } FileStatus.set(FileStatus.TERMINATED); } if (done && pe == null) { @@ -131,8 +159,17 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p executePane.getTextSegmentWindow().setCodeHighlighting(true); executePane.getTextSegmentWindow().unhighlightAllSteps(); executePane.getTextSegmentWindow().highlightStepAtAddress(RegisterFile.getProgramCounter() - 4); + for(int i = 0; i < hartWindows.size(); i++){ + hartWindows.get(i).getRegistersPane().setSelectedComponent(executePane.getControlAndStatusWindow()); + gExecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); + gExecutePanes.get(i).getTextSegmentWindow().unhighlightAllSteps(); + gExecutePanes.get(i).getTextSegmentWindow().highlightStepAtAddress(RegisterFile.getProgramCounter() - 4); + } } mainUI.setReset(false); + for(int i = 0; i < hartWindows.size(); i++){ + hartWindows.get(i).setReset(false); + } } //////////////////////////////////////////////////////////////////////////////////// @@ -142,6 +179,11 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p // $a0 gets argument count (argc), $a1 gets stack address of first arg pointer (argv). private void processProgramArgumentsIfAny() { String programArguments = executePane.getTextSegmentWindow().getProgramArguments(); + ArrayList gProgramArgumentsArrayList = new ArrayList<>(); + for(int i = 0; i < hartWindows.size(); i++){ + gProgramArgumentsArrayList.add(gExecutePanes.get(i).getTextSegmentWindow().getProgramArguments()); + } + //TODO if (programArguments == null || programArguments.length() == 0 || !Globals.getSettings().getBooleanSetting(Settings.Bool.PROGRAM_ARGUMENTS)) { return; From 35cda7621dab5030686810219daf3ac1db6261b2 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 17 Jun 2021 19:30:36 -0600 Subject: [PATCH 48/84] fix sc on 64-bit mode --- src/rars/riscv/hardware/ReservationTable.java | 63 ++++++++++++++++--- .../riscv/hardware/ReservationTables.java | 41 ++++++------ .../instructions/AtomicMemoryOperation.java | 7 ++- src/rars/riscv/instructions/LRD.java | 3 +- src/rars/riscv/instructions/LRW.java | 3 +- src/rars/riscv/instructions/SB.java | 3 +- src/rars/riscv/instructions/SCD.java | 3 +- src/rars/riscv/instructions/SCW.java | 3 +- src/rars/riscv/instructions/SD.java | 5 +- src/rars/riscv/instructions/SH.java | 3 +- src/rars/riscv/instructions/SW.java | 3 +- src/rars/tools/ReservationTablesTool.java | 29 ++++----- 12 files changed, 108 insertions(+), 58 deletions(-) diff --git a/src/rars/riscv/hardware/ReservationTable.java b/src/rars/riscv/hardware/ReservationTable.java index f7524c9c..1bee1ae8 100644 --- a/src/rars/riscv/hardware/ReservationTable.java +++ b/src/rars/riscv/hardware/ReservationTable.java @@ -1,6 +1,7 @@ package rars.riscv.hardware; import java.util.ArrayList; +import java.util.function.Predicate; /* Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura. @@ -28,38 +29,80 @@ a copy of this software and associated documentation files (the */ public class ReservationTable { - private ArrayList table; + private ArrayList table; public final static int capacity = 8; + private final static int doubleAlignMask = ~0x7; + + public enum bitWidth { + word, + doubleWord + } + + protected class ReservationTableEntry { + protected Integer address; + protected bitWidth width; + + public ReservationTableEntry(Integer address, bitWidth width) { + this.address = address; + this.width = width; + } + + public boolean equals(Object o) { + ReservationTableEntry other = (ReservationTableEntry) o; + return address.equals(other.address) && width.equals(other.width); + } + } public ReservationTable() { - table = new ArrayList(); + table = new ArrayList(); } - public void reserveAddress(int address) { - if(table.contains(Integer.valueOf(address))) + public void reserveAddress(int address, bitWidth width) { + ReservationTableEntry newEntry = new ReservationTableEntry(address, width); + if(table.contains(newEntry)) return; if (table.size() == capacity) table.remove(0); - table.add(Integer.valueOf(address)); + table.add(newEntry); } - public void unreserveAddress(int address) { - table.removeIf(val -> val == address); + public void unreserveAddress(int address, bitWidth width) { + Predicate filter = entry -> + (entry.address == address && entry.width == width) + || ((address & doubleAlignMask) == entry.address && entry.width == bitWidth.doubleWord); + table.removeIf(filter); } - public boolean contains(int address) { - return table.contains(Integer.valueOf(address)); + public boolean contains(int address, bitWidth width) { + for (ReservationTableEntry entry : table) { + if ((entry.address == address && entry.width == width) + || ((address & doubleAlignMask) == entry.address && entry.width == bitWidth.doubleWord)) + return true; + } + return false; } public Integer[] getAddresses() { Integer[] addresses = new Integer[capacity]; for (int i = 0; i < capacity; i++) { try { - addresses[i] = table.get(i); + addresses[i] = this.table.get(i).address; } catch (IndexOutOfBoundsException e) { addresses[i] = 0; } } return addresses; } + + public bitWidth[] getWidths() { + bitWidth[] addresses = new bitWidth[capacity]; + for (int i = 0; i < capacity; i++) { + try { + addresses[i] = this.table.get(i).width; + } catch (IndexOutOfBoundsException e) { + addresses[i] = null; + } + } + return addresses; + } } diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index b7646e51..398b0494 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -6,7 +6,7 @@ import java.util.Vector; import rars.SimulationException; -import rars.riscv.InstructionSet; +import rars.riscv.hardware.ReservationTable.bitWidth; /* Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura. @@ -50,45 +50,44 @@ public void reset() { } } - public void reserveAddress(int hart, int address) throws AddressErrorException { - int modulo = InstructionSet.rv64 ? 8 : 4; + public void reserveAddress(int hart, int address, bitWidth width) throws AddressErrorException { + int modulo = width == bitWidth.doubleWord ? 8 : 4; if (address % modulo != 0) { throw new AddressErrorException("Reservation address not aligned to word boundary ", SimulationException.LOAD_ADDRESS_MISALIGNED, address); } - reservationTables[hart].reserveAddress(address); + reservationTables[hart].reserveAddress(address, width); } - public boolean unreserveAddress(int hart, int address) throws AddressErrorException { - int modulo = InstructionSet.rv64 ? 8 : 4; + public boolean unreserveAddress(int hart, int address, bitWidth width) throws AddressErrorException { + int modulo = width == bitWidth.doubleWord ? 8 : 4; if (address % modulo != 0) { throw new AddressErrorException("Reservation address not aligned to word boundary ", SimulationException.STORE_ADDRESS_MISALIGNED, address); } - if (reservationTables[hart].contains(address)) { + if (reservationTables[hart].contains(address, width)) { for (ReservationTable reservationTable : reservationTables) { - reservationTable.unreserveAddress(address); + reservationTable.unreserveAddress(address, width); } return true; } return false; } - public Integer[][] getAllAddresses() { - Integer[][] all = new Integer[ReservationTable.capacity][harts]; - for (int i = 0; i < ReservationTable.capacity; i++) { - for (int j = 0; j < harts; j++) { - Integer[] addresses = reservationTables[j].getAddresses(); - all[i][j] = addresses[i]; - } - } - return all; - } - public String[][] getAllAddressesAsStrings() { - String[][] all = new String[ReservationTable.capacity][harts]; + String[][] all = new String[ReservationTable.capacity][harts * 2]; + char width = '0'; for (int i = 0; i < ReservationTable.capacity; i++) { for (int j = 0; j < harts; j++) { Integer[] addresses = reservationTables[j].getAddresses(); - all[i][j] = String.format("0x%08x", addresses[i]); + ReservationTable.bitWidth[] widths = reservationTables[j].getWidths(); + if (widths[i] == ReservationTable.bitWidth.word) { + width = 'w'; + } else if (widths[i] == ReservationTable.bitWidth.doubleWord) { + width = 'd'; + } else { + width = ' '; + } + all[i][j * 2] = String.format("0x%08x", addresses[i]); + all[i][j * 2 + 1] = String.format("%c", width); } } return all; diff --git a/src/rars/riscv/instructions/AtomicMemoryOperation.java b/src/rars/riscv/instructions/AtomicMemoryOperation.java index 88ab194a..655cfac8 100644 --- a/src/rars/riscv/instructions/AtomicMemoryOperation.java +++ b/src/rars/riscv/instructions/AtomicMemoryOperation.java @@ -6,6 +6,7 @@ import rars.riscv.InstructionSet; import rars.riscv.hardware.AddressErrorException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReservationTable.bitWidth; /* Copyright (c) 2021, Giancarlo Pernudi Segura @@ -41,19 +42,23 @@ a copy of this software and associated documentation files (the * @version May 2017 */ public abstract class AtomicMemoryOperation extends Atomic { + private bitWidth width; + public AtomicMemoryOperation(String usage, String description, String funct5) { super(usage, description, "010", funct5); + width = bitWidth.word; } public AtomicMemoryOperation(String usage, String description, String funct5, boolean rv64) { super(usage, description, rv64 ? "011" : "010", funct5, rv64); + width = rv64 ? bitWidth.doubleWord : bitWidth.word; } public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); try { int rs1Loc = RegisterFile.getValue(operands[2]); - Globals.reservationTables.unreserveAddress(0, rs1Loc); + Globals.reservationTables.unreserveAddress(0, rs1Loc, width); long rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); long rs2Value = RegisterFile.getValueLong(operands[1]); RegisterFile.updateRegister(operands[0], rs1Data); diff --git a/src/rars/riscv/instructions/LRD.java b/src/rars/riscv/instructions/LRD.java index 89ded3c5..16d702e0 100644 --- a/src/rars/riscv/instructions/LRD.java +++ b/src/rars/riscv/instructions/LRD.java @@ -5,6 +5,7 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReservationTable.bitWidth; public class LRD extends Atomic { public LRD() { @@ -21,7 +22,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private long load(int address) throws AddressErrorException { - Globals.reservationTables.reserveAddress(0, address); + Globals.reservationTables.reserveAddress(0, address, bitWidth.doubleWord); return Globals.memory.getDoubleWord(address); } } diff --git a/src/rars/riscv/instructions/LRW.java b/src/rars/riscv/instructions/LRW.java index 27731971..0d433abc 100644 --- a/src/rars/riscv/instructions/LRW.java +++ b/src/rars/riscv/instructions/LRW.java @@ -5,6 +5,7 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReservationTable.bitWidth; public class LRW extends Atomic { public LRW() { @@ -21,7 +22,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private long load(int address) throws AddressErrorException { - Globals.reservationTables.reserveAddress(0, address); + Globals.reservationTables.reserveAddress(0, address, bitWidth.word); return Globals.memory.getWord(address); } } diff --git a/src/rars/riscv/instructions/SB.java b/src/rars/riscv/instructions/SB.java index 125f4bc0..9768ff64 100644 --- a/src/rars/riscv/instructions/SB.java +++ b/src/rars/riscv/instructions/SB.java @@ -2,6 +2,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.ReservationTable.bitWidth; /* Copyright (c) 2017, Benjamin Landers @@ -36,7 +37,7 @@ public SB() { } public void store(int address, long data) throws AddressErrorException { - Globals.reservationTables.unreserveAddress(0, address & ~0b11); + Globals.reservationTables.unreserveAddress(0, address & ~0b11, bitWidth.word); Globals.memory.setByte(address, (int)data & 0x000000FF); } } diff --git a/src/rars/riscv/instructions/SCD.java b/src/rars/riscv/instructions/SCD.java index a70b30b7..dba28da1 100644 --- a/src/rars/riscv/instructions/SCD.java +++ b/src/rars/riscv/instructions/SCD.java @@ -5,6 +5,7 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReservationTable.bitWidth; public class SCD extends Atomic { public SCD() { @@ -22,7 +23,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private long store(int address, int value) throws AddressErrorException { - if (Globals.reservationTables.unreserveAddress(0, address)) { + if (Globals.reservationTables.unreserveAddress(0, address, bitWidth.doubleWord)) { Globals.memory.setDoubleWord(address, value); return 0; } diff --git a/src/rars/riscv/instructions/SCW.java b/src/rars/riscv/instructions/SCW.java index d87760c0..80ad716c 100644 --- a/src/rars/riscv/instructions/SCW.java +++ b/src/rars/riscv/instructions/SCW.java @@ -5,6 +5,7 @@ import rars.ProgramStatement; import rars.SimulationException; import rars.riscv.hardware.RegisterFile; +import rars.riscv.hardware.ReservationTable.bitWidth; public class SCW extends Atomic { public SCW() { @@ -22,7 +23,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { } private int store(int address, int value) throws AddressErrorException { - if (Globals.reservationTables.unreserveAddress(0, address)) { + if (Globals.reservationTables.unreserveAddress(0, address, bitWidth.word)) { Globals.memory.setWord(address, value); return 0; } diff --git a/src/rars/riscv/instructions/SD.java b/src/rars/riscv/instructions/SD.java index 20228068..4b901d8d 100644 --- a/src/rars/riscv/instructions/SD.java +++ b/src/rars/riscv/instructions/SD.java @@ -2,6 +2,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.ReservationTable.bitWidth; public class SD extends Store { public SD() { @@ -9,9 +10,7 @@ public SD() { } public void store(int address, long data) throws AddressErrorException { + Globals.reservationTables.unreserveAddress(0, address, bitWidth.doubleWord); Globals.memory.setDoubleWord(address, data); } } - - - diff --git a/src/rars/riscv/instructions/SH.java b/src/rars/riscv/instructions/SH.java index 99e00741..a640e1f5 100644 --- a/src/rars/riscv/instructions/SH.java +++ b/src/rars/riscv/instructions/SH.java @@ -2,6 +2,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.ReservationTable.bitWidth; /* Copyright (c) 2017, Benjamin Landers @@ -36,7 +37,7 @@ public SH() { } public void store(int address, long data) throws AddressErrorException { - Globals.reservationTables.unreserveAddress(0, address & ~0b11); + Globals.reservationTables.unreserveAddress(0, address & ~0b11, bitWidth.word); Globals.memory.setHalf(address, (int)data & 0x0000FFFF); } } diff --git a/src/rars/riscv/instructions/SW.java b/src/rars/riscv/instructions/SW.java index 4ab55821..9c1720cf 100644 --- a/src/rars/riscv/instructions/SW.java +++ b/src/rars/riscv/instructions/SW.java @@ -2,6 +2,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.ReservationTable.bitWidth; /* Copyright (c) 2017, Benjamin Landers @@ -36,7 +37,7 @@ public SW() { } public void store(int address, long data) throws AddressErrorException { - Globals.reservationTables.unreserveAddress(0, address); + Globals.reservationTables.unreserveAddress(0, address, bitWidth.word); Globals.memory.setWord(address, (int) data); } } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 0ec04ffc..1d885d0e 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -2,8 +2,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; -import rars.riscv.hardware.*; -import rars.util.Binary; +import rars.riscv.hardware.ReservationTable.bitWidth; import rars.venus.*; import javax.swing.*; @@ -60,16 +59,15 @@ private Integer[] SelectHartWindow(){ public ReservationTablesTool() { super(heading + ", " + version, heading); Globals.reservationTables.addObserver(this); - - } protected JComponent buildMainDisplayArea() { JPanel panelTools = new JPanel(new BorderLayout()); hartPanel = new JPanel(new BorderLayout()); - String[] columns = new String[Globals.reservationTables.harts]; - for (int i = 0; i < columns.length; i++) { - columns[i] = String.format("Hart %d", i); + String[] columns = new String[Globals.reservationTables.harts * 2]; + for (int i = 0; i < Globals.reservationTables.harts; i++) { + columns[i * 2] = String.format("Hart %d", i); + columns[i * 2 + 1] = "Length"; } reservations = new JTable(Globals.reservationTables.getAllAddressesAsStrings(), columns) { @Override @@ -80,7 +78,8 @@ public boolean isCellEditable(int row, int column) { hartPanel.add(reservations.getTableHeader(), BorderLayout.NORTH); reservations.setCellSelectionEnabled(true); - reservations.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + reservations.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + reservations.getTableHeader().setReorderingAllowed(false); hartPanel.add(reservations); TitledBorder tb = new TitledBorder(displayPanelTitle); @@ -94,12 +93,10 @@ public boolean isCellEditable(int row, int column) { new ActionListener() { public void actionPerformed(ActionEvent e) { int i = hartWindowSelector.getSelectedIndex(); - if(i == 0) + if (i == 0) return; - else{ - hartWindows.get(i-1).setVisible(true); - } - + else + hartWindows.get(i-1).setVisible(true); } }); @@ -111,10 +108,12 @@ public void actionPerformed(ActionEvent e) { int col = reservations.getSelectedColumn(); if(row < 0 || col < 0) return; + if (col % 2 == 1) + col--; int address = Integer.parseInt(reservations.getValueAt(row, col) .toString().substring(2), 16); try { - Globals.reservationTables.unreserveAddress(col, address); + Globals.reservationTables.unreserveAddress(col, address, bitWidth.word); } catch (AddressErrorException e) { e.printStackTrace(); } @@ -174,5 +173,3 @@ protected void reset() { updateDisplay(); } } - - From f703297f1de73d1b84e8a19af0d149896ca13c2b Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 17 Jun 2021 22:58:07 -0600 Subject: [PATCH 49/84] rename atomic example --- examples/{atomic.s => atomic_increment.s} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{atomic.s => atomic_increment.s} (100%) diff --git a/examples/atomic.s b/examples/atomic_increment.s similarity index 100% rename from examples/atomic.s rename to examples/atomic_increment.s From 85c7e75cacae3167b5d28c20758a49b2a1484b95 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Wed, 23 Jun 2021 12:05:21 +0530 Subject: [PATCH 50/84] Mannual Harts selection --- src/rars/Globals.java | 16 +++++++++++++- .../tools/AbstractToolAndApplication.java | 2 +- src/rars/tools/ReservationTablesTool.java | 22 ++++++++++++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index 862ebb6e..bee5d0a2 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -148,7 +148,7 @@ public class Globals { public static boolean runSpeedPanelExists = false; - private static int harts = 2; + private static int harts = 1; private static ArrayList hartWindows = new ArrayList(); @@ -166,6 +166,20 @@ public static ArrayList getHartWindows(){ public static int getHarts() { return harts; } + + public static void setHarts(int i){ + if(harts == 0 && i < 0 || harts ==7 && i > 0){ + return; + } + if(i >0){ + harts++; + reservationTables = new ReservationTables(harts); + } + else{ + harts--; + reservationTables = new ReservationTables(harts); + } + } private static String getCopyrightYears() { return "2003-2019"; } diff --git a/src/rars/tools/AbstractToolAndApplication.java b/src/rars/tools/AbstractToolAndApplication.java index f5fca64a..11ea7566 100644 --- a/src/rars/tools/AbstractToolAndApplication.java +++ b/src/rars/tools/AbstractToolAndApplication.java @@ -66,7 +66,7 @@ a copy of this software and associated documentation files (the */ public abstract class AbstractToolAndApplication extends JFrame implements Tool, Observer { protected boolean isBeingUsedAsATool = false; // can use to determine whether invoked as Tool or stand-alone. - private JDialog dialog; // used only for Tool use. This is the pop-up dialog that appears when menu item selected. + protected JDialog dialog; // used only for Tool use. This is the pop-up dialog that appears when menu item selected. protected Window theWindow; // highest level GUI component (a JFrame for app, a JDialog for Tool) // Major GUI components private JLabel headingLabel; diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 1d885d0e..ab50f571 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -42,9 +42,9 @@ public class ReservationTablesTool extends AbstractToolAndApplication { private static String heading = "Reservation Table Tool"; private static String version = "Version 1.0"; private static String displayPanelTitle; - private JPanel displayOptions, hartPanel; + private JPanel hartPanel; private JComboBox hartWindowSelector; - protected ArrayList hartWindows = Globals.getHartWindows(); + protected ArrayList hartWindows; private Integer[] SelectHartWindow(){ Integer hartChoser[]; @@ -58,6 +58,7 @@ private Integer[] SelectHartWindow(){ public ReservationTablesTool() { super(heading + ", " + version, heading); + hartWindows = Globals.getHartWindows(); Globals.reservationTables.addObserver(this); } @@ -93,6 +94,8 @@ public boolean isCellEditable(int row, int column) { new ActionListener() { public void actionPerformed(ActionEvent e) { int i = hartWindowSelector.getSelectedIndex(); + hartWindows = Globals.getHartWindows(); + Globals.setHartWindows(); if (i == 0) return; else @@ -121,9 +124,22 @@ public void actionPerformed(ActionEvent e) { reservations.clearSelection(); updateDisplay(); }); - + JButton btnPlus = new JButton("+"); + JButton btnMinus = new JButton("-"); + btnPlus.addActionListener(l -> { + Globals.setHarts(1); + buildMainDisplayArea(); + super.dialog.dispose(); + }); + btnMinus.addActionListener(l -> { + Globals.setHarts(-1); + buildMainDisplayArea(); + super.dialog.dispose(); + }); displayOptions.add(Box.createHorizontalGlue()); + displayOptions.add(btnMinus); displayOptions.add(hartWindowSelector); + displayOptions.add(btnPlus); clearButton.addKeyListener(new EnterKeyListener(clearButton)); displayOptions.add(Box.createHorizontalGlue()); displayOptions.add(clearButton); From 75d834b04df3e4809fbb85df2f79af020bf42b3a Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Thu, 24 Jun 2021 01:47:18 +0530 Subject: [PATCH 51/84] MultiThreading Works except LR.W and SC.W --- src/rars/RISCVprogram.java | 4 + src/rars/riscv/hardware/RegisterFile.java | 51 +++++++++++- src/rars/simulator/Simulator.java | 99 +++++++++++++++++++---- src/rars/venus/run/RunAssembleAction.java | 5 +- src/rars/venus/run/RunStepAction.java | 3 +- 5 files changed, 141 insertions(+), 21 deletions(-) diff --git a/src/rars/RISCVprogram.java b/src/rars/RISCVprogram.java index d9a9e6a8..7578b6a5 100644 --- a/src/rars/RISCVprogram.java +++ b/src/rars/RISCVprogram.java @@ -366,6 +366,10 @@ public void startSimulation(int maxSteps, int[] breakPoints) { sim.startSimulation(RegisterFile.getProgramCounter(), maxSteps, breakPoints); } + public void startSimulation(int maxSteps, int[] breakPoints, int hart) { + Simulator sim = Simulator.getInstance(hart); + sim.startSimulation(RegisterFile.getProgramCounter(hart), maxSteps, breakPoints, hart); + } /** * Instantiates a new {@link MacroPool} and sends reference of this * {@link RISCVprogram} to it diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index ac5ece2c..e5bd5c0c 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -5,6 +5,7 @@ import rars.assembler.SymbolTable; import rars.riscv.Instruction; +import java.util.ArrayList; import java.util.Observer; /* @@ -65,9 +66,45 @@ public class RegisterFile { new Register("t3", 28, 0), new Register("t4", 29, 0), new Register("t5", 30, 0), new Register("t6", 31, 0) }); - + private static ArrayList gInstance; private static Register programCounter = new Register("pc", -1, Memory.textBaseAddress); + private static ArrayList gProgramCounter; + + public static void initProgramCounter(){ + gProgramCounter = new ArrayList<>(); + for(int i = 1; i < Globals.getHarts(); i++){ + Register temp = new Register("pc", -1, Memory.textBaseAddress); + gProgramCounter.add(temp); + } + } + public static void initGRegisterBlock(){ + gInstance = new ArrayList<>(); + for(int i = 0; i < Globals.getHarts(); i++){ + RegisterBlock temp = new RegisterBlock('x', new Register[]{ + new Register("zero", 0, 0), new Register("ra", 1, 0), + new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer), + new Register("gp", GLOBAL_POINTER_REGISTER, Memory.globalPointer), + new Register("tp", 4, 0), new Register("t0", 5, 0), + new Register("t1", 6, 0), new Register("t2", 7, 0), + new Register("s0", 8, 0), new Register("s1", 9, 0), + new Register("a0", 10, 0), new Register("a1", 11, 0), + new Register("a2", 12, 0), new Register("a3", 13, 0), + new Register("a4", 14, 0), new Register("a5", 15, 0), + new Register("a6", 16, 0), new Register("a7", 17, 0), + new Register("s2", 18, 0), new Register("s3", 19, 0), + new Register("s4", 20, 0), new Register("s5", 21, 0), + new Register("s6", 22, 0), new Register("s7", 23, 0), + new Register("s8", 24, 0), new Register("s9", 25, 0), + new Register("s10", 26, 0), new Register("s11", 27, 0), + new Register("t3", 28, 0), new Register("t4", 29, 0), + new Register("t5", 30, 0), new Register("t6", 31, 0) + }); + gInstance.add(temp); + } + + } + /** * This method updates the register value who's number is num. Also handles the lo and hi registers * @@ -168,7 +205,9 @@ public static Register getRegister(String name) { public static void initializeProgramCounter(int value) { programCounter.setValue((long)value); } - + public static void initializeProgramCounter(int value, int hart){ + gProgramCounter.get(hart).setValue(value); + } /** * Will initialize the Program Counter to either the default reset value, or the address * associated with source program global label "main", if it exists as a text segment label @@ -214,7 +253,9 @@ public static int setProgramCounter(int value) { public static int getProgramCounter() { return (int)programCounter.getValue(); } - + public static int getProgramCounter(int hart){ + return (int) gProgramCounter.get(hart).getValue(); + } /** * Returns Register object for program counter. Use with caution. * @@ -255,7 +296,9 @@ public static void resetRegisters() { public static void incrementPC() { programCounter.setValue(programCounter.getValue() + Instruction.INSTRUCTION_LENGTH); } - + public static void incrementPC(int hart){ + gProgramCounter.get(hart).setValue(gProgramCounter.get(hart).getValue() + Instruction.INSTRUCTION_LENGTH); + } /** * Each individual register is a separate object and Observable. This handy method * will add the given Observer to each one. Currently does not apply to Program diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index 27a99323..78dda06e 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -49,10 +49,12 @@ a copy of this software and associated documentation files (the **/ public class Simulator extends Observable { - private SimThread simulatorThread; + private SimThread simulatorThread = null; + private static ArrayList gSimulatorThread; private static Simulator simulator = null; // Singleton object + private static ArrayList gSimulator; private static Runnable interactiveGUIUpdater = null; - + private int hart = 0; /** * various reasons for simulate to end... */ @@ -81,6 +83,21 @@ public static Simulator getInstance() { } return simulator; } + public static Simulator getInstance(int tempHart) { + // Do NOT change this to create the Simulator at load time (in declaration above)! + // Its constructor looks for the GUI, which at load time is not created yet, + // and incorrectly leaves interactiveGUIUpdater null! This causes runtime + // exceptions while running in timed mode. + if (gSimulator == null) { + gSimulator = new ArrayList<>(); + gSimulatorThread = new ArrayList<>(); + for(int i = 0; i < Globals.getHarts() - 1 ; i++){ + gSimulatorThread.add(null); + gSimulator.add(new Simulator(i)); + } + } + return gSimulator.get(tempHart); + } private Simulator() { simulatorThread = null; @@ -89,6 +106,12 @@ private Simulator() { } } + private Simulator(int tempHart) { + if (Globals.getGui() != null) { + interactiveGUIUpdater = new UpdateGUI(); + } + } + /** * Simulate execution of given source program (in this thread). It must have already been assembled. * @@ -125,7 +148,11 @@ public void startSimulation(int pc, int maxSteps, int[] breakPoints) { simulatorThread = new SimThread(pc, maxSteps, breakPoints); new Thread(simulatorThread, "RISCV").start(); } - + public void startSimulation(int pc, int maxSteps, int[] breakPoints, int hart) { + gSimulatorThread.add(hart, new SimThread(pc, maxSteps, breakPoints, hart)); + String s = "Hart " + hart; + new Thread(gSimulatorThread.get(hart), s).start(); + } /** * Set the volatile stop boolean variable checked by the execution @@ -202,6 +229,7 @@ class SimThread implements Runnable { private SimulationException pe; private volatile boolean stop = false; private Reason constructReturnReason; + private int hart = -1; /** * SimThread constructor. Receives all the information it needs to simulate execution. @@ -216,8 +244,16 @@ class SimThread implements Runnable { this.breakPoints = breakPoints; this.done = false; this.pe = null; + this.hart = -1; + } + SimThread(int pc, int maxSteps, int[] breakPoints, int hart) { + this.pc = pc; + this.maxSteps = maxSteps; + this.breakPoints = breakPoints; + this.done = false; + this.pe = null; + this.hart = hart; } - /** * Sets to "true" the volatile boolean variable that is tested after each * instruction is executed. After calling this method, the next test @@ -242,9 +278,10 @@ private void stopExecution(boolean done, Reason reason) { this.constructReturnReason = reason; SystemIO.flush(true); if (done) SystemIO.resetFiles(); // close any files opened in the process of simulating - Simulator.getInstance().notifyObserversOfExecution(new SimulatorNotice(SimulatorNotice.SIMULATOR_STOP, - maxSteps, (Globals.getGui() != null || Globals.runSpeedPanelExists)?RunSpeedPanel.getInstance().getRunSpeed():RunSpeedPanel.UNLIMITED_SPEED, - pc, reason, pe, done)); + if(hart == -1) + Simulator.getInstance().notifyObserversOfExecution(new SimulatorNotice(SimulatorNotice.SIMULATOR_STOP, + maxSteps, (Globals.getGui() != null || Globals.runSpeedPanelExists)?RunSpeedPanel.getInstance().getRunSpeed():RunSpeedPanel.UNLIMITED_SPEED, + pc, reason, pe, done)); } private synchronized void interrupt() { @@ -346,8 +383,8 @@ public void run() { } else { Arrays.sort(breakPoints); // must be pre-sorted for binary search } - - startExecution(); + if(hart == -1) + startExecution(); // ******************* PS addition 26 July 2006 ********************** // A couple statements below were added for the purpose of assuring that when @@ -378,8 +415,12 @@ public void run() { // the backstep button is not enabled until a "real" instruction is executed. // This is noticeable in stepped mode. // ********************************************************************* - - RegisterFile.initializeProgramCounter(pc); + if(hart == -1){ + RegisterFile.initializeProgramCounter(pc); + } + else{ + RegisterFile.initializeProgramCounter(pc, hart); + } ProgramStatement statement = null; int steps = 0; boolean ebreak = false, waiting = false; @@ -398,7 +439,12 @@ public void run() { long uip = ControlAndStatusRegisterFile.getValueNoNotify("uip"), uie = ControlAndStatusRegisterFile.getValueNoNotify("uie"); boolean IE = (ControlAndStatusRegisterFile.getValueNoNotify("ustatus") & ControlAndStatusRegisterFile.INTERRUPT_ENABLE) != 0; // make sure no interrupts sneak in while we are processing them - pc = RegisterFile.getProgramCounter(); + if(hart == -1){ + pc = RegisterFile.getProgramCounter(); + } + else{ + pc = RegisterFile.getProgramCounter(hart); + } synchronized (InterruptController.lock) { boolean pendingExternal = InterruptController.externalPending(), pendingTimer = InterruptController.timerPending(), @@ -446,11 +492,20 @@ public void run() { } } - pc = RegisterFile.getProgramCounter(); - RegisterFile.incrementPC(); + if(hart == -1){ + pc = RegisterFile.getProgramCounter(); + RegisterFile.incrementPC(); + } + else{ + pc = RegisterFile.getProgramCounter(hart); + } + // Get instuction try { - statement = Globals.memory.getStatement(pc); + if(hart == -1) + statement = Globals.memory.getStatement(pc); + else + statement = Globals.memory.getStatementNoNotify(pc); } catch (AddressErrorException e) { SimulationException tmp; if (e.getType() == SimulationException.LOAD_ACCESS_FAULT) { @@ -585,4 +640,18 @@ public void run() { Globals.getGui().getMainPane().getExecutePane().getTextSegmentWindow().highlightStepAtPC(); } } + + private class GeneralUpdateGUI implements Runnable { + public void run() { + if (Globals.getGui().getRegistersPane().getSelectedComponent() == + Globals.getGui().getMainPane().getExecutePane().getRegistersWindow()) { + Globals.getGui().getMainPane().getExecutePane().getRegistersWindow().updateRegisters(); + } else { + Globals.getGui().getMainPane().getExecutePane().getFloatingPointWindow().updateRegisters(); + } + Globals.getGui().getMainPane().getExecutePane().getDataSegmentWindow().updateValues(); + Globals.getGui().getMainPane().getExecutePane().getTextSegmentWindow().setCodeHighlighting(true); + Globals.getGui().getMainPane().getExecutePane().getTextSegmentWindow().highlightStepAtPC(); + } + } } diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index 74ef9aa4..1f2d4208 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -54,7 +54,7 @@ public class RunAssembleAction extends GuiAction { // Threshold for adding filename to printed message of files being assembled. private static final int LINE_LENGTH_LIMIT = 60; private VenusUI mainUI; - protected ArrayList hartWindows = Globals.getHartWindows(); + protected ArrayList hartWindows; public RunAssembleAction(String name, Icon icon, String descrip, Integer mnemonic, KeyStroke accel, VenusUI gui) { super(name, icon, descrip, mnemonic, accel); @@ -77,6 +77,9 @@ static boolean getWarningsAreErrors() { } public void actionPerformed(ActionEvent e) { + hartWindows = Globals.getHartWindows(); + RegisterFile.initGRegisterBlock(); + RegisterFile.initProgramCounter(); String name = this.getValue(Action.NAME).toString(); MessagesPane messagesPane = mainUI.getMessagesPane(); ExecutePane executePane = mainUI.getMainPane().getExecutePane(); diff --git a/src/rars/venus/run/RunStepAction.java b/src/rars/venus/run/RunStepAction.java index 1a0ad7fc..5ad4406c 100644 --- a/src/rars/venus/run/RunStepAction.java +++ b/src/rars/venus/run/RunStepAction.java @@ -70,6 +70,7 @@ public RunStepAction(String name, Icon icon, String descrip, * perform next simulated instruction step. */ public void actionPerformed(ActionEvent e) { + hartWindows = Globals.getHartWindows(); name = this.getValue(Action.NAME).toString(); executePane = mainUI.getMainPane().getExecutePane(); gExecutePanes = new ArrayList<>(); @@ -102,7 +103,7 @@ public void update(Observable o, Object simulator) { Globals.program.startSimulation(1, null); for(int i = 0; i < hartWindows.size(); i++){ - Globals.gPrograms.get(i).startSimulation(1, null); + Globals.gPrograms.get(i).startSimulation(1, null, i); } } else { // note: this should never occur since "Step" is only enabled after successful assembly. From 2020e7a9b6e15b78630003b6225011476fc88190 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Wed, 23 Jun 2021 17:14:35 -0600 Subject: [PATCH 52/84] reopen reservation table tool on hart update --- src/rars/Globals.java | 21 +++++++++------------ src/rars/tools/ReservationTablesTool.java | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index bee5d0a2..b83d0dae 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -150,10 +150,10 @@ public class Globals { private static int harts = 1; - private static ArrayList hartWindows = new ArrayList(); + private static ArrayList hartWindows = new ArrayList<>(); public static void setHartWindows(){ - for(int i = 1; i < Globals.getHarts(); i++){ + for (int i = 1; i < Globals.getHarts(); i++) { GeneralVenusUI temp= new GeneralVenusUI("Window "+i); hartWindows.add(temp); } @@ -167,19 +167,16 @@ public static int getHarts() { return harts; } - public static void setHarts(int i){ - if(harts == 0 && i < 0 || harts ==7 && i > 0){ + public static void setHarts(int i) { + if ((harts == 1 && i < 0) || (harts == 7 && i > 0)) { return; - } - if(i >0){ - harts++; - reservationTables = new ReservationTables(harts); - } - else{ - harts--; - reservationTables = new ReservationTables(harts); + } if (i > 0) { + reservationTables = new ReservationTables(++harts); + } else { + reservationTables = new ReservationTables(--harts); } } + private static String getCopyrightYears() { return "2003-2019"; } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index ab50f571..225aa587 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -45,15 +45,6 @@ public class ReservationTablesTool extends AbstractToolAndApplication { private JPanel hartPanel; private JComboBox hartWindowSelector; protected ArrayList hartWindows; - - private Integer[] SelectHartWindow(){ - Integer hartChoser[]; - hartChoser = new Integer[(Integer) Globals.getHarts()]; - for(int i = 0; i < Globals.getHarts(); i ++){ - hartChoser[i] = i; - } - return hartChoser; - } private JTable reservations; public ReservationTablesTool() { @@ -128,13 +119,13 @@ public void actionPerformed(ActionEvent e) { JButton btnMinus = new JButton("-"); btnPlus.addActionListener(l -> { Globals.setHarts(1); - buildMainDisplayArea(); super.dialog.dispose(); + action(); }); btnMinus.addActionListener(l -> { Globals.setHarts(-1); - buildMainDisplayArea(); super.dialog.dispose(); + action(); }); displayOptions.add(Box.createHorizontalGlue()); displayOptions.add(btnMinus); @@ -188,4 +179,13 @@ protected void reset() { Globals.reservationTables.reset(); updateDisplay(); } + + private Integer[] SelectHartWindow() { + Integer hartChoser[]; + hartChoser = new Integer[(Integer) Globals.getHarts()]; + for (int i = 0; i < Globals.getHarts(); i++) { + hartChoser[i] = i; + } + return hartChoser; + } } From cb52a903d1f1343918c00ab7b42879470cb14302 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 24 Jun 2021 09:23:25 -0600 Subject: [PATCH 53/84] add hart variable to ProgramStatement --- src/rars/ProgramStatement.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/rars/ProgramStatement.java b/src/rars/ProgramStatement.java index cce4d6f2..c3470d56 100644 --- a/src/rars/ProgramStatement.java +++ b/src/rars/ProgramStatement.java @@ -65,6 +65,7 @@ public class ProgramStatement implements Comparable { private int textAddress; private int sourceLine; private int binaryStatement; + private int currrentHart; private boolean altered; private static final String invalidOperator = ""; @@ -517,6 +518,15 @@ public void setSource(String src) { source = src; } + /** + * Set the current hart for this program statement. + * + * @param hart the new current hart + */ + public void setCurrentHart(int hart) { + currrentHart = hart; + } + /** * Produces RISCVprogram object representing the source file containing this statement. @@ -645,6 +655,15 @@ public int[] getOperands() { return operands; } + /** + * Produces current hart that will simulate this statement. + * + * @return curent hart. + */ + public int getCurrentHart() { + return currrentHart; + } + /** * Produces operand value from given array position (first operand is position 0). * @@ -873,5 +892,4 @@ private class ListElement { } } } - } From 85a96317b7d666cbd84f25bfa0ee06b0240509ed Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 24 Jun 2021 11:13:26 -0600 Subject: [PATCH 54/84] maximise text segment on extra hart windows --- src/rars/Globals.java | 2 +- src/rars/venus/GeneralVenusUI.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index b83d0dae..cbaf40d4 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -154,7 +154,7 @@ public class Globals { public static void setHartWindows(){ for (int i = 1; i < Globals.getHarts(); i++) { - GeneralVenusUI temp= new GeneralVenusUI("Window "+i); + GeneralVenusUI temp= new GeneralVenusUI(String.format("Hart %d", i)); hartWindows.add(temp); } } diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index 048ee64e..db7f349a 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -12,6 +12,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; +import java.beans.PropertyVetoException; import java.net.URL; /* @@ -117,9 +118,13 @@ public GeneralVenusUI(String s) { registersPane.setPreferredSize(registersPanePreferredSize); mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab); - - mainPane.setPreferredSize(mainPanePreferredSize); + try { + mainPane.getExecutePane().getTextSegmentWindow().setMaximum(true); + } catch (PropertyVetoException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } horizonSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mainPane, registersPane); horizonSplitter.setOneTouchExpandable(true); @@ -211,4 +216,4 @@ private ImageIcon loadIcon(String name) { private KeyStroke makeShortcut(int key) { return KeyStroke.getKeyStroke(key, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); } -} \ No newline at end of file +} From a795b312f93abe9efa6de0e24fa17c92df98004c Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Thu, 8 Jul 2021 14:49:02 -0600 Subject: [PATCH 55/84] add harts cli argument --- src/rars/Launch.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/rars/Launch.java b/src/rars/Launch.java index d0e43311..70f71d10 100644 --- a/src/rars/Launch.java +++ b/src/rars/Launch.java @@ -78,6 +78,7 @@ public class Launch { * segments are .text and .data. Current supported dump formats
* are Binary, HexText, BinaryText.
* h -- display help. Use by itself and with no filename
+ * harts -- the amount of harts to use for running RARS with
* hex -- display memory or register contents in hexadecimal (default)
* ic -- display count of basic instructions 'executed'"); * mc -- set memory configuration. Option has 1 argument, e.g.
@@ -384,6 +385,10 @@ private boolean parseCommandArgs(String[] args) { countInstructions = true; continue; } + if (args[i].toLowerCase().equals("harts")) { + Globals.setHarts(Integer.valueOf(args[++i])); + continue; + } if (new File(args[i]).exists()) { // is it a file name? filenameList.add(args[i]); @@ -713,6 +718,7 @@ private void displayHelp() { out.println(" = " + segments+", or a range like 0x400000-0x10000000"); out.println(" = " + formats); out.println(" h -- display this help. Use by itself with no filename."); + out.println(" harts -- the amount of harts to use for running RARS with"); out.println(" hex -- display memory or register contents in hexadecimal (default)"); out.println(" ic -- display count of basic instructions 'executed'"); out.println(" mc -- set memory configuration. Argument is"); @@ -749,5 +755,3 @@ private void displayHelp() { } } - - From c4feba904f53a230cedc5498a4cba91e8855be84 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Fri, 9 Jul 2021 20:55:58 +0530 Subject: [PATCH 56/84] Hart -1 independent, needs bug fixes --- src/rars/riscv/hardware/Register.java | 15 +++- .../riscv/hardware/RegisterAccessNotice.java | 13 +++- src/rars/riscv/hardware/RegisterFile.java | 68 ++++++++++++------- src/rars/riscv/instructions/AUIPC.java | 5 +- src/rars/riscv/instructions/Arithmetic.java | 16 ++++- .../instructions/AtomicMemoryOperation.java | 20 ++++-- src/rars/riscv/instructions/BEQ.java | 5 +- src/rars/riscv/instructions/BGE.java | 5 +- .../instructions/ImmediateInstruction.java | 16 ++++- src/rars/simulator/Simulator.java | 30 ++++++-- src/rars/tools/ReservationTablesTool.java | 6 ++ src/rars/venus/GeneralExecutePane.java | 10 ++- src/rars/venus/GeneralMainPane.java | 7 +- src/rars/venus/GeneralVenusUI.java | 4 +- src/rars/venus/TextSegmentWindow.java | 4 +- .../venus/registers/RegisterBlockWindow.java | 38 ++++++++--- src/rars/venus/registers/RegistersWindow.java | 17 ++++- src/rars/venus/run/RunStepAction.java | 5 +- 18 files changed, 216 insertions(+), 68 deletions(-) diff --git a/src/rars/riscv/hardware/Register.java b/src/rars/riscv/hardware/Register.java index d50667b1..4252226b 100644 --- a/src/rars/riscv/hardware/Register.java +++ b/src/rars/riscv/hardware/Register.java @@ -41,6 +41,7 @@ public class Register extends Observable { private String name; private int number; private long resetValue; + private int hart; // volatile should be enough to allow safe multi-threaded access // w/o the use of synchronized methods. getValue and setValue // are the only methods here used by the register collection @@ -60,8 +61,15 @@ public Register(String n, int num, long val) { number = num; value = val; resetValue = val; + hart = -1; + } + public Register(String n, int num, long val, int hart) { + name = n; + number = num; + value = val; + resetValue = val; + this.hart = hart; } - /** * Returns the name of the Register. * @@ -171,7 +179,10 @@ public synchronized void changeResetValue(long reset) { private void notifyAnyObservers(int type) { if (this.countObservers() > 0) {// && Globals.program != null) && Globals.program.inSteppedExecution()) { this.setChanged(); - this.notifyObservers(new RegisterAccessNotice(type, this.name)); + if(this.hart == -1) + this.notifyObservers(new RegisterAccessNotice(type, this.name)); + else + this.notifyObservers(new RegisterAccessNotice(type, this.name, hart)); } } diff --git a/src/rars/riscv/hardware/RegisterAccessNotice.java b/src/rars/riscv/hardware/RegisterAccessNotice.java index ced06218..d20aea9e 100644 --- a/src/rars/riscv/hardware/RegisterAccessNotice.java +++ b/src/rars/riscv/hardware/RegisterAccessNotice.java @@ -38,23 +38,30 @@ a copy of this software and associated documentation files (the public class RegisterAccessNotice extends AccessNotice { private String registerName; - + private int hart; /** * Constructor will be called only within this package, so assume * register number is in valid range. */ + RegisterAccessNotice(int type, String registerName, int hart) { + super(type); + this.registerName = registerName; + this.hart = hart; + } RegisterAccessNotice(int type, String registerName) { super(type); this.registerName = registerName; + hart = -1; } - /** * Fetch the register number of register accessed. */ public String getRegisterName() { return registerName; } - + public int getHart(){ + return hart; + } /** * String representation indicates access type and which register */ diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index e5bd5c0c..2aea17e9 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -47,7 +47,7 @@ public class RegisterFile { public static final int GLOBAL_POINTER_REGISTER = 3; public static final int STACK_POINTER_REGISTER = 2; - private static final RegisterBlock instance = new RegisterBlock('x', new Register[]{ + public static final RegisterBlock instance = new RegisterBlock('x', new Register[]{ new Register("zero", 0, 0), new Register("ra", 1, 0), new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer), new Register("gp", GLOBAL_POINTER_REGISTER, Memory.globalPointer), @@ -66,7 +66,7 @@ public class RegisterFile { new Register("t3", 28, 0), new Register("t4", 29, 0), new Register("t5", 30, 0), new Register("t6", 31, 0) }); - private static ArrayList gInstance; + public static ArrayList gInstance; private static Register programCounter = new Register("pc", -1, Memory.textBaseAddress); private static ArrayList gProgramCounter; @@ -82,23 +82,23 @@ public static void initGRegisterBlock(){ gInstance = new ArrayList<>(); for(int i = 0; i < Globals.getHarts(); i++){ RegisterBlock temp = new RegisterBlock('x', new Register[]{ - new Register("zero", 0, 0), new Register("ra", 1, 0), - new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer), - new Register("gp", GLOBAL_POINTER_REGISTER, Memory.globalPointer), - new Register("tp", 4, 0), new Register("t0", 5, 0), - new Register("t1", 6, 0), new Register("t2", 7, 0), - new Register("s0", 8, 0), new Register("s1", 9, 0), - new Register("a0", 10, 0), new Register("a1", 11, 0), - new Register("a2", 12, 0), new Register("a3", 13, 0), - new Register("a4", 14, 0), new Register("a5", 15, 0), - new Register("a6", 16, 0), new Register("a7", 17, 0), - new Register("s2", 18, 0), new Register("s3", 19, 0), - new Register("s4", 20, 0), new Register("s5", 21, 0), - new Register("s6", 22, 0), new Register("s7", 23, 0), - new Register("s8", 24, 0), new Register("s9", 25, 0), - new Register("s10", 26, 0), new Register("s11", 27, 0), - new Register("t3", 28, 0), new Register("t4", 29, 0), - new Register("t5", 30, 0), new Register("t6", 31, 0) + new Register("zero", 0, 0, i), new Register("ra", 1, 0, i), + new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer, i), + new Register("gp", GLOBAL_POINTER_REGISTER, Memory.globalPointer, i), + new Register("tp", 4, 0, i), new Register("t0", 5, 0, i), + new Register("t1", 6, 0, i), new Register("t2", 7, 0, i), + new Register("s0", 8, 0, i), new Register("s1", 9, 0, i), + new Register("a0", 10, 0, i), new Register("a1", 11, 0, i), + new Register("a2", 12, 0, i), new Register("a3", 13, 0, i), + new Register("a4", 14, 0, i), new Register("a5", 15, 0, i), + new Register("a6", 16, 0, i), new Register("a7", 17, 0, i), + new Register("s2", 18, 0, i), new Register("s3", 19, 0, i), + new Register("s4", 20, 0, i), new Register("s5", 21, 0, i), + new Register("s6", 22, 0, i), new Register("s7", 23, 0, i), + new Register("s8", 24, 0, i), new Register("s9", 25, 0, i), + new Register("s10", 26, 0,i), new Register("s11", 27, 0, i), + new Register("t3", 28, 0, i), new Register("t4", 29, 0, i), + new Register("t5", 30, 0, i), new Register("t6", 31, 0, i) }); gInstance.add(temp); } @@ -123,7 +123,13 @@ public static void updateRegister(int num, long val) { } } } - + public static void updateRegister(int num, long val, int hart) { + if (num == 0) { + ; + } else { + gInstance.get(hart).updateRegister(num, val); + } + } /** * Sets the value of the register given to the value given. * @@ -146,7 +152,10 @@ public static int getValue(int num) { return (int) instance.getValue(num); } + public static int getValue(int num, int hart) { + return (int) gInstance.get(hart).getValue(num); + } /** * Returns the value of the register. * @@ -158,7 +167,10 @@ public static long getValueLong(int num) { return instance.getValue(num); } + public static long getValueLong(int num, int hart) { + return gInstance.get(hart).getValue(num); + } /** * Returns the value of the register. * @@ -179,7 +191,11 @@ public static int getValue(String name) { public static Register[] getRegisters() { return instance.getRegisters(); } - + public static Register[] getRegisters(int hart) { + if(gInstance == null) + initGRegisterBlock(); + return gInstance.get(hart).getRegisters(); + } /** * Get register object corresponding to given name. If no match, return null. * @@ -264,7 +280,11 @@ public static int getProgramCounter(int hart){ public static Register getProgramCounterRegister() { return programCounter; } - + public static Register getProgramCounterRegister(int hart) { + if(gProgramCounter == null) + initProgramCounter(); + return gProgramCounter.get(hart); + } /** * For returning the program counter's initial (reset) value. * @@ -307,7 +327,9 @@ public static void incrementPC(int hart){ public static void addRegistersObserver(Observer observer) { instance.addRegistersObserver(observer); } - + public static void addRegistersObserver(Observer observer, int hart) { + gInstance.get(hart).addRegistersObserver(observer); + } /** * Each individual register is a separate object and Observable. This handy method * will delete the given Observer from each one. Currently does not apply to Program diff --git a/src/rars/riscv/instructions/AUIPC.java b/src/rars/riscv/instructions/AUIPC.java index cd5d6559..2f9746bc 100644 --- a/src/rars/riscv/instructions/AUIPC.java +++ b/src/rars/riscv/instructions/AUIPC.java @@ -40,6 +40,9 @@ public AUIPC() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter() - INSTRUCTION_LENGTH + (operands[1] << 12)); + if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter() - INSTRUCTION_LENGTH + (operands[1] << 12)); + else + RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter() - INSTRUCTION_LENGTH + (operands[1] << 12), statement.getCurrentHart()); } } diff --git a/src/rars/riscv/instructions/Arithmetic.java b/src/rars/riscv/instructions/Arithmetic.java index 194d1570..9cec24ee 100644 --- a/src/rars/riscv/instructions/Arithmetic.java +++ b/src/rars/riscv/instructions/Arithmetic.java @@ -53,9 +53,19 @@ public Arithmetic(String usage, String description, String funct7, String funct3 public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); if (InstructionSet.rv64){ - RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]),RegisterFile.getValueLong(operands[2]))); - }else { - RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]),RegisterFile.getValue(operands[2]))); + if(statement.getCurrentHart() == 0) + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]),RegisterFile.getValueLong(operands[2]))); + else{ + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]),RegisterFile.getValueLong(operands[2])), statement.getCurrentHart()); + } + } + else { + + if(statement.getCurrentHart() == 0) + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]),RegisterFile.getValue(operands[2]))); + else{ + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]),RegisterFile.getValue(operands[2])), statement.getCurrentHart()); + } } } diff --git a/src/rars/riscv/instructions/AtomicMemoryOperation.java b/src/rars/riscv/instructions/AtomicMemoryOperation.java index 655cfac8..b245b67d 100644 --- a/src/rars/riscv/instructions/AtomicMemoryOperation.java +++ b/src/rars/riscv/instructions/AtomicMemoryOperation.java @@ -57,11 +57,23 @@ public AtomicMemoryOperation(String usage, String description, String funct5, bo public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); try { - int rs1Loc = RegisterFile.getValue(operands[2]); + int rs1Loc; + long rs2Value; + long rs1Data; + if(statement.getCurrentHart() == -1){ + rs1Loc = RegisterFile.getValue(operands[2]); + rs2Value = RegisterFile.getValueLong(operands[1]); + rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); + RegisterFile.updateRegister(operands[0], rs1Data); + } + else{ + rs1Loc = RegisterFile.getValue(operands[2], statement.getCurrentHart()); + rs2Value = RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); + rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); + RegisterFile.updateRegister(operands[0], rs1Data, statement.getCurrentHart()); + } Globals.reservationTables.unreserveAddress(0, rs1Loc, width); - long rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); - long rs2Value = RegisterFile.getValueLong(operands[1]); - RegisterFile.updateRegister(operands[0], rs1Data); + rs1Data = binaryOperation(rs1Data, rs2Value); if (InstructionSet.rv64) { Globals.memory.setDoubleWord(rs1Loc, rs1Data); diff --git a/src/rars/riscv/instructions/BEQ.java b/src/rars/riscv/instructions/BEQ.java index 250ce4b2..936104ce 100644 --- a/src/rars/riscv/instructions/BEQ.java +++ b/src/rars/riscv/instructions/BEQ.java @@ -37,6 +37,9 @@ public BEQ() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - return RegisterFile.getValueLong(operands[0]) == RegisterFile.getValueLong(operands[1]); + if(statement.getCurrentHart() == -1) + return RegisterFile.getValueLong(operands[0]) == RegisterFile.getValueLong(operands[1]); + else + return RegisterFile.getValueLong(operands[0], statement.getCurrentHart()) == RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); } } \ No newline at end of file diff --git a/src/rars/riscv/instructions/BGE.java b/src/rars/riscv/instructions/BGE.java index bb293912..b4ec30fb 100644 --- a/src/rars/riscv/instructions/BGE.java +++ b/src/rars/riscv/instructions/BGE.java @@ -37,6 +37,9 @@ public BGE() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - return RegisterFile.getValueLong(operands[0]) >= RegisterFile.getValueLong(operands[1]); + if(statement.getCurrentHart() == -1) + return RegisterFile.getValueLong(operands[0]) >= RegisterFile.getValueLong(operands[1]); + else + return RegisterFile.getValueLong(operands[0], statement.getCurrentHart()) >= RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); } } \ No newline at end of file diff --git a/src/rars/riscv/instructions/ImmediateInstruction.java b/src/rars/riscv/instructions/ImmediateInstruction.java index bb9a081a..ae8d7edb 100644 --- a/src/rars/riscv/instructions/ImmediateInstruction.java +++ b/src/rars/riscv/instructions/ImmediateInstruction.java @@ -52,11 +52,21 @@ public ImmediateInstruction(String usage, String description, String funct, bool public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); if (InstructionSet.rv64){ - RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]), + if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]), (operands[2] << 20) >> 20)); // make sure the immediate is sign-extended + else + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1], statement.getCurrentHart()), + (operands[2] << 20) >> 20), statement.getCurrentHart()); // make sure the immediate is sign-extended }else { - RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]), + + if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]), (operands[2] << 20) >> 20)); // make sure the immediate is sign-extended + else{ + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1], statement.getCurrentHart()), + (operands[2] << 20) >> 20), statement.getCurrentHart()); // make sure the immediate is sign-extended + } } } @@ -72,6 +82,6 @@ public void simulate(ProgramStatement statement) { * @return the result to be stored from the instruction */ protected int computeW(int value, int immediate){ - return (int) compute(value,immediate); + return (int) compute(value, immediate); } } \ No newline at end of file diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index 78dda06e..897a74e7 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -88,6 +88,9 @@ public static Simulator getInstance(int tempHart) { // Its constructor looks for the GUI, which at load time is not created yet, // and incorrectly leaves interactiveGUIUpdater null! This causes runtime // exceptions while running in timed mode. + if(tempHart < 0){ + return null; + } if (gSimulator == null) { gSimulator = new ArrayList<>(); gSimulatorThread = new ArrayList<>(); @@ -229,7 +232,7 @@ class SimThread implements Runnable { private SimulationException pe; private volatile boolean stop = false; private Reason constructReturnReason; - private int hart = -1; + private int hart; /** * SimThread constructor. Receives all the information it needs to simulate execution. @@ -272,7 +275,11 @@ private void startExecution() { maxSteps,(Globals.getGui() != null || Globals.runSpeedPanelExists)?RunSpeedPanel.getInstance().getRunSpeed():RunSpeedPanel.UNLIMITED_SPEED, pc, null, pe, done)); } - + private void startExecution(int hart) { + Simulator.getInstance(hart).notifyObserversOfExecution(new SimulatorNotice(SimulatorNotice.SIMULATOR_START, + maxSteps,(Globals.getGui() != null || Globals.runSpeedPanelExists)?RunSpeedPanel.getInstance().getRunSpeed():RunSpeedPanel.UNLIMITED_SPEED, + pc, null, pe, done)); + } private void stopExecution(boolean done, Reason reason) { this.done = done; this.constructReturnReason = reason; @@ -385,6 +392,8 @@ public void run() { } if(hart == -1) startExecution(); + else + startExecution(hart); // ******************* PS addition 26 July 2006 ********************** // A couple statements below were added for the purpose of assuring that when @@ -498,14 +507,21 @@ public void run() { } else{ pc = RegisterFile.getProgramCounter(hart); + RegisterFile.incrementPC(hart); } // Get instuction try { - if(hart == -1) + if(hart == -1){ statement = Globals.memory.getStatement(pc); - else + if(statement != null) + statement.setCurrentHart(-1); + } + else{ statement = Globals.memory.getStatementNoNotify(pc); + if(statement != null) + statement.setCurrentHart(hart); + } } catch (AddressErrorException e) { SimulationException tmp; if (e.getType() == SimulationException.LOAD_ACCESS_FAULT) { @@ -536,8 +552,8 @@ public void run() { SimulationException.ILLEGAL_INSTRUCTION); } // THIS IS WHERE THE INSTRUCTION EXECUTION IS ACTUALLY SIMULATED! - instruction.simulate(statement); + instruction.simulate(statement); // IF statement added 7/26/06 (explanation above) if (Globals.getSettings().getBackSteppingEnabled()) { Globals.program.getBackStepper().addDoNothing(pc); @@ -641,7 +657,7 @@ public void run() { } } - private class GeneralUpdateGUI implements Runnable { + /* private class GeneralUpdateGUI implements Runnable { public void run() { if (Globals.getGui().getRegistersPane().getSelectedComponent() == Globals.getGui().getMainPane().getExecutePane().getRegistersWindow()) { @@ -653,5 +669,5 @@ public void run() { Globals.getGui().getMainPane().getExecutePane().getTextSegmentWindow().setCodeHighlighting(true); Globals.getGui().getMainPane().getExecutePane().getTextSegmentWindow().highlightStepAtPC(); } - } + }*/ } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 225aa587..dd7ac0e9 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -2,6 +2,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.RegisterFile; import rars.riscv.hardware.ReservationTable.bitWidth; import rars.venus.*; @@ -120,11 +121,16 @@ public void actionPerformed(ActionEvent e) { btnPlus.addActionListener(l -> { Globals.setHarts(1); super.dialog.dispose(); + RegisterFile.initGRegisterBlock(); + RegisterFile.initProgramCounter(); action(); + }); btnMinus.addActionListener(l -> { Globals.setHarts(-1); super.dialog.dispose(); + RegisterFile.initGRegisterBlock(); + RegisterFile.initProgramCounter(); action(); }); displayOptions.add(Box.createHorizontalGlue()); diff --git a/src/rars/venus/GeneralExecutePane.java b/src/rars/venus/GeneralExecutePane.java index a2d167c1..35376eb7 100644 --- a/src/rars/venus/GeneralExecutePane.java +++ b/src/rars/venus/GeneralExecutePane.java @@ -52,6 +52,7 @@ public class GeneralExecutePane extends JDesktopPane { private NumberDisplayBaseChooser valueDisplayBase; private NumberDisplayBaseChooser addressDisplayBase; private boolean labelWindowVisible; + private int hart; /** * initialize the Execute pane with major components @@ -62,10 +63,15 @@ public class GeneralExecutePane extends JDesktopPane { * @param csrRegs window containing the CSR set */ - public GeneralExecutePane(GeneralVenusUI mainUI, RegistersWindow regs, FloatingPointWindow fpRegs, ControlAndStatusWindow csrRegs) { + public GeneralExecutePane(GeneralVenusUI mainUI, RegistersWindow regs, FloatingPointWindow fpRegs, ControlAndStatusWindow csrRegs, int hart) { this.mainUI = mainUI; // Although these are displayed in Data Segment, they apply to all three internal // windows within the Execute pane. So they will be housed here. + addressDisplayBase = new NumberDisplayBaseChooser("Hexadecimal Addresses", + Globals.getSettings().getBooleanSetting(Settings.Bool.DISPLAY_ADDRESSES_IN_HEX)); + valueDisplayBase = new NumberDisplayBaseChooser("Hexadecimal Values", + Globals.getSettings().getBooleanSetting(Settings.Bool.DISPLAY_VALUES_IN_HEX));//VenusUI.DEFAULT_NUMBER_BASE); + this.hart = hart; registerValues = regs; fpRegValues = fpRegs; csrValues = csrRegs; @@ -227,7 +233,7 @@ public NumberDisplayBaseChooser getAddressDisplayBaseChooser() { public void numberDisplayBaseChanged(NumberDisplayBaseChooser chooser) { if (chooser == valueDisplayBase) { // Have all internal windows update their value columns - registerValues.updateRegisters(); + registerValues.updateRegisters(hart); fpRegValues.updateRegisters(); csrValues.updateRegisters(); textSegment.updateBasicStatements(); diff --git a/src/rars/venus/GeneralMainPane.java b/src/rars/venus/GeneralMainPane.java index d8a08056..aa8b8461 100644 --- a/src/rars/venus/GeneralMainPane.java +++ b/src/rars/venus/GeneralMainPane.java @@ -48,7 +48,7 @@ a copy of this software and associated documentation files (the public class GeneralMainPane extends JTabbedPane { GeneralExecutePane executeTab; - + private int hart; private GeneralVenusUI mainUI; /** @@ -56,15 +56,16 @@ public class GeneralMainPane extends JTabbedPane { **/ public GeneralMainPane(GeneralVenusUI appFrame, RegistersWindow regs, - FloatingPointWindow cop1Regs, ControlAndStatusWindow cop0Regs) { + FloatingPointWindow cop1Regs, ControlAndStatusWindow cop0Regs, int hart) { super(); + this.hart = hart; this.mainUI = appFrame; this.setTabPlacement(JTabbedPane.TOP); //LEFT); if (this.getUI() instanceof BasicTabbedPaneUI) { BasicTabbedPaneUI ui = (BasicTabbedPaneUI) this.getUI(); } - executeTab = new GeneralExecutePane(appFrame, regs, cop1Regs, cop0Regs); + executeTab = new GeneralExecutePane(appFrame, regs, cop1Regs, cop0Regs, hart); String executeTabTitle = "Execute"; //"

 
E
x
e
c
u
t
e
 
"; Icon executeTabIcon = null;//new ImageIcon(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource(Globals.imagesPath+"Execute_tab.jpg"))); diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index db7f349a..c0a69446 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -111,13 +111,13 @@ public GeneralVenusUI(String s) { // roughly in bottom-up order; some are created in component constructors and thus are // not visible here. - registersTab = new RegistersWindow("Not GUI"); + registersTab = new RegistersWindow(s.charAt(s.length()-1) - '1'); fpTab = new FloatingPointWindow(); csrTab = new ControlAndStatusWindow(); registersPane = new GeneralRegistersPane(mainUI, registersTab, fpTab, csrTab); registersPane.setPreferredSize(registersPanePreferredSize); - mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab); + mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab, s.charAt(s.length()-1) - '1'); mainPane.setPreferredSize(mainPanePreferredSize); try { mainPane.getExecutePane().getTextSegmentWindow().setMaximum(true); diff --git a/src/rars/venus/TextSegmentWindow.java b/src/rars/venus/TextSegmentWindow.java index 59ef000e..b323cee2 100644 --- a/src/rars/venus/TextSegmentWindow.java +++ b/src/rars/venus/TextSegmentWindow.java @@ -488,7 +488,9 @@ public void highlightStepAtPC() { highlightStepAtAddress(RegisterFile.getProgramCounter()); } - + public void highlightStepAtPC(int hart) { + highlightStepAtAddress(RegisterFile.getProgramCounter(hart)); + } /** * Highlights the source code line whose address matches the given * text segment address. diff --git a/src/rars/venus/registers/RegisterBlockWindow.java b/src/rars/venus/registers/RegisterBlockWindow.java index 0550261f..a7068001 100644 --- a/src/rars/venus/registers/RegisterBlockWindow.java +++ b/src/rars/venus/registers/RegisterBlockWindow.java @@ -62,7 +62,7 @@ public abstract class RegisterBlockWindow extends JPanel implements Observer { private int highlightRow; private Register[] registers; private boolean notMainUI = true; - + private int hart; private static final int NAME_COLUMN = 0; private static final int NUMBER_COLUMN = 1; private static final int VALUE_COLUMN = 2; @@ -77,6 +77,7 @@ public RegisterBlockWindow(Register[] registers, String[] registerDescriptions, Simulator.getInstance().addObserver(this); settings = Globals.getSettings(); this.registers = registers; + this.hart = -1; clearHighlighting(); table = new MyTippedJTable(new RegTableModel(setupWindow()), registerDescriptions, new String[]{"Each register has a tool tip describing its usage convention", "Corresponding register number", valueTip}) { @@ -93,12 +94,28 @@ public RegisterBlockWindow(Register[] registers, String[] registerDescriptions, this.setLayout(new BorderLayout()); // table display will occupy entire width if widened this.add(new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); } + + public RegisterBlockWindow(Register[] registers, String[] registerDescriptions, String valueTip, int hart) { + Simulator.getInstance(hart).addObserver(this); + settings = Globals.getSettings(); + this.registers = registers; + this.hart = hart; + clearHighlighting(); + table = new MyTippedJTable(new RegTableModel(setupWindow()), registerDescriptions, + new String[]{"Each register has a tool tip describing its usage convention", "Corresponding register number", valueTip}) { + }; + table.getColumnModel().getColumn(NAME_COLUMN).setPreferredWidth(50); + table.getColumnModel().getColumn(NUMBER_COLUMN).setPreferredWidth(25); + table.getColumnModel().getColumn(VALUE_COLUMN).setPreferredWidth(60); - public RegisterBlockWindow(Register[] registers2, String[] regtooltips, String string, String string2) { - this(registers2, regtooltips, string); - notMainUI = false; + // Display register values (String-ified) right-justified in mono font + table.getColumnModel().getColumn(NAME_COLUMN).setCellRenderer(new RegisterCellRenderer(MonoRightCellRenderer.MONOSPACED_PLAIN_12POINT, SwingConstants.LEFT)); + table.getColumnModel().getColumn(NUMBER_COLUMN).setCellRenderer(new RegisterCellRenderer(MonoRightCellRenderer.MONOSPACED_PLAIN_12POINT, SwingConstants.RIGHT)); + table.getColumnModel().getColumn(VALUE_COLUMN).setCellRenderer(new RegisterCellRenderer(MonoRightCellRenderer.MONOSPACED_PLAIN_12POINT, SwingConstants.RIGHT)); + table.setPreferredScrollableViewportSize(new Dimension(200, 700)); + this.setLayout(new BorderLayout()); // table display will occupy entire width if widened + this.add(new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); } - protected abstract String formatRegister(Register value, int base); protected abstract void beginObserving(); @@ -159,7 +176,12 @@ public void updateRegisters() { Globals.getGui().getMainPane().getExecutePane().getValueDisplayBase()), i, 2); } } - + public void updateRegisters(int hart) { + for (int i = 0; i < registers.length; i++) { + ((RegTableModel) table.getModel()).setDisplayAndModelValueAt(formatRegister(registers[i], + Globals.getHartWindows().get(hart).getMainPane().getExecutePane().getValueDisplayBase()), i, 2); + } + } /** * Highlight the row corresponding to the given register. * @@ -188,7 +210,7 @@ private void highlightCellForRegister(Register register) { * @param obj Auxiliary object with additional information. */ public void update(Observable observable, Object obj) { - if (observable == rars.simulator.Simulator.getInstance()) { + if (observable == rars.simulator.Simulator.getInstance() || observable == rars.simulator.Simulator.getInstance(hart)) { SimulatorNotice notice = (SimulatorNotice) obj; if (notice.getAction() == SimulatorNotice.SIMULATOR_START) { // Simulated MIPS execution starts. Respond to memory changes if running in timed @@ -209,7 +231,7 @@ public void update(Observable observable, Object obj) { // AddressCellRenderer class in DataSegmentWindow.java. this.highlighting = true; this.highlightCellForRegister((Register) observable); - if(notMainUI) + if(notMainUI && hart == -1) Globals.getGui().getRegistersPane().setSelectedComponent(this); } } diff --git a/src/rars/venus/registers/RegistersWindow.java b/src/rars/venus/registers/RegistersWindow.java index eb5b5282..f51671fd 100644 --- a/src/rars/venus/registers/RegistersWindow.java +++ b/src/rars/venus/registers/RegistersWindow.java @@ -12,6 +12,7 @@ public class RegistersWindow extends RegisterBlockWindow { /* * The tips to show when hovering over the names of the registers */ + private int hart; private static final String[] regToolTips = { /* zero */ "constant 0", /* ra */ "return address (used by function call)", @@ -50,10 +51,12 @@ public class RegistersWindow extends RegisterBlockWindow { public RegistersWindow() { super(getRegisters(), regToolTips, "Current 32 bit value"); + hart = -1; } - public RegistersWindow(String s){ - super(getRegisters(), regToolTips, "Current 32 bit value", "GeneralGUI"); + public RegistersWindow(int hart){ + super(getRegisters(hart), regToolTips, "Current 32 bit value", hart); + this.hart = hart; } /* @@ -65,6 +68,12 @@ private static Register[] getRegisters() { out[base.length] = RegisterFile.getProgramCounterRegister(); return out; } + private static Register[] getRegisters(int hart) { + Register[] base = RegisterFile.getRegisters(hart); + Register[] out = Arrays.copyOf(base, base.length + 1); + out[base.length] = RegisterFile.getProgramCounterRegister(hart); + return out; + } protected String formatRegister(Register value, int base) { if (Globals.getSettings().getBooleanSetting(Settings.Bool.RV64_ENABLED)){ @@ -77,7 +86,9 @@ protected String formatRegister(Register value, int base) { protected void beginObserving() { RegisterFile.addRegistersObserver(this); } - + protected void beginObserving(int hart){ + RegisterFile.addRegistersObserver(this, hart); + } protected void endObserving() { RegisterFile.deleteRegistersObserver(this); } diff --git a/src/rars/venus/run/RunStepAction.java b/src/rars/venus/run/RunStepAction.java index 5ad4406c..6b5d00e1 100644 --- a/src/rars/venus/run/RunStepAction.java +++ b/src/rars/venus/run/RunStepAction.java @@ -103,7 +103,10 @@ public void update(Observable o, Object simulator) { Globals.program.startSimulation(1, null); for(int i = 0; i < hartWindows.size(); i++){ + Simulator.getInstance(i).addObserver(stopListener); Globals.gPrograms.get(i).startSimulation(1, null, i); + gExecutePanes.get(i).getRegistersWindow().updateRegisters(i); + //System.out.println("Hart " + i + " " + RegisterFile.gInstance.get(i).getRegister(6).getValue()); } } else { // note: this should never occur since "Step" is only enabled after successful assembly. @@ -120,7 +123,7 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p executePane.getDataSegmentWindow().updateValues(); for(int i = 0; i < hartWindows.size(); i++){ - gExecutePanes.get(i).getRegistersWindow().updateRegisters(); + gExecutePanes.get(i).getRegistersWindow().updateRegisters(i); gExecutePanes.get(i).getFloatingPointWindow().updateRegisters(); gExecutePanes.get(i).getControlAndStatusWindow().updateRegisters(); } From 54661e8aa7091b8e71236626defda2c1e20c72bd Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 13 Jul 2021 14:22:41 +0530 Subject: [PATCH 57/84] Immediate and Arithmatic support --- src/rars/riscv/instructions/Arithmetic.java | 4 ++-- src/rars/riscv/instructions/ImmediateInstruction.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rars/riscv/instructions/Arithmetic.java b/src/rars/riscv/instructions/Arithmetic.java index 9cec24ee..91d2d37f 100644 --- a/src/rars/riscv/instructions/Arithmetic.java +++ b/src/rars/riscv/instructions/Arithmetic.java @@ -53,7 +53,7 @@ public Arithmetic(String usage, String description, String funct7, String funct3 public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); if (InstructionSet.rv64){ - if(statement.getCurrentHart() == 0) + if(statement.getCurrentHart() == -1) RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]),RegisterFile.getValueLong(operands[2]))); else{ RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]),RegisterFile.getValueLong(operands[2])), statement.getCurrentHart()); @@ -61,7 +61,7 @@ public void simulate(ProgramStatement statement) { } else { - if(statement.getCurrentHart() == 0) + if(statement.getCurrentHart() == -1) RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]),RegisterFile.getValue(operands[2]))); else{ RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]),RegisterFile.getValue(operands[2])), statement.getCurrentHart()); diff --git a/src/rars/riscv/instructions/ImmediateInstruction.java b/src/rars/riscv/instructions/ImmediateInstruction.java index ae8d7edb..2e0b9b50 100644 --- a/src/rars/riscv/instructions/ImmediateInstruction.java +++ b/src/rars/riscv/instructions/ImmediateInstruction.java @@ -66,6 +66,7 @@ public void simulate(ProgramStatement statement) { else{ RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1], statement.getCurrentHart()), (operands[2] << 20) >> 20), statement.getCurrentHart()); // make sure the immediate is sign-extended + System.out.println("Hart " + (statement.getCurrentHart() + 1) +" :" + "Register " + operands[0] + " : " + RegisterFile.getValue(operands[1], statement.getCurrentHart())); } } } From 2f6992dc20cf6d3c4654eeedb507eefc44492423 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Tue, 13 Jul 2021 13:21:27 -0600 Subject: [PATCH 58/84] add run buttons to secondary hart windows still have to sync enable/disable status with main gui --- src/rars/venus/GeneralVenusUI.java | 84 +++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 6 deletions(-) diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index c0a69446..b47c0347 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -1,13 +1,9 @@ package rars.venus; import rars.Globals; -import rars.Settings; -import rars.riscv.InstructionSet; -import rars.riscv.dump.DumpFormatLoader; import rars.simulator.Simulator; import rars.venus.registers.*; import rars.venus.run.*; -import rars.venus.settings.*; import javax.swing.*; import java.awt.*; @@ -56,15 +52,18 @@ a copy of this software and associated documentation files (the public class GeneralVenusUI extends JFrame { GeneralVenusUI mainUI; + private JToolBar toolbar; private GeneralMainPane mainPane; private GeneralRegistersPane registersPane; private RegistersWindow registersTab; private FloatingPointWindow fpTab; private ControlAndStatusWindow csrTab; - private JSplitPane splitter, horizonSplitter; + private JSplitPane horizonSplitter; JPanel north; - private int frameState; // see windowActivated() and windowDeactivated() + private JButton Run, Reset, Step, Backstep, Stop, Pause; + private Action runGoAction, runStepAction, runBackstepAction, + runResetAction, runStopAction, runPauseAction; // PLEASE PUT THESE TWO (& THEIR METHODS) SOMEWHERE THEY BELONG, NOT HERE private boolean reset = true; // registers/memory reset for execution @@ -76,6 +75,7 @@ public class GeneralVenusUI extends JFrame { * @param s Name of the window to be created. **/ + // TODO check for mem observer public GeneralVenusUI(String s) { super(s); mainUI = this; @@ -130,7 +130,11 @@ public GeneralVenusUI(String s) { horizonSplitter.setOneTouchExpandable(true); horizonSplitter.resetToPreferredSizes(); + this.createActionObjects(); + toolbar = this.setUpToolBar(); + JPanel jp = new JPanel(new FlowLayout(FlowLayout.LEFT)); + jp.add(toolbar); JPanel center = new JPanel(new BorderLayout()); center.add(jp, BorderLayout.NORTH); center.add(horizonSplitter); @@ -216,4 +220,72 @@ private ImageIcon loadIcon(String name) { private KeyStroke makeShortcut(int key) { return KeyStroke.getKeyStroke(key, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); } + + /* + * Action objects are used instead of action listeners because one can be easily + * shared between a menu item and a toolbar button. Does nice things like + * disable both if the action is disabled, etc. + */ + private void createActionObjects() { + try { + runGoAction = new RunGoAction("Go", loadIcon("Play22.png"), "Run the current program", KeyEvent.VK_G, + KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), Globals.getGui()); + runStepAction = new RunStepAction("Step", loadIcon("StepForward22.png"), "Run one step at a time", + KeyEvent.VK_T, KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0), Globals.getGui()); + runBackstepAction = new RunBackstepAction("Backstep", loadIcon("StepBack22.png"), "Undo the last step", + KeyEvent.VK_B, KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0), Globals.getGui()); + runPauseAction = new GuiAction("Pause", loadIcon("Pause22.png"), "Pause the currently running program", + KeyEvent.VK_P, KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0)) { + public void actionPerformed(ActionEvent e) { + Simulator.getInstance().pauseExecution(); + // RunGoAction's "paused" method will do the cleanup. + } + }; + runStopAction = new GuiAction("Stop", loadIcon("Stop22.png"), "Stop the currently running program", + KeyEvent.VK_S, KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0)) { + public void actionPerformed(ActionEvent e) { + Simulator.getInstance().stopExecution(); + // RunGoAction's "stopped" method will take care of the cleanup. + } + }; + runResetAction = new RunResetAction("Reset", loadIcon("Reset22.png"), "Reset memory and registers", + KeyEvent.VK_R, KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), Globals.getGui()); + } catch (NullPointerException e) { + System.out.println( + "Internal Error: images folder not found, or other null pointer exception while creating Action objects"); + e.printStackTrace(); + System.exit(0); + } + } + + /* + * build the toolbar and connect items to action objects (which serve as action + * listeners shared between toolbar icon and corresponding menu item). + */ + + JToolBar setUpToolBar() { + JToolBar toolBar = new JToolBar(); + + Run = new JButton(runGoAction); + Run.setText(""); + Step = new JButton(runStepAction); + Step.setText(""); + Backstep = new JButton(runBackstepAction); + Backstep.setText(""); + Reset = new JButton(runResetAction); + Reset.setText(""); + Stop = new JButton(runStopAction); + Stop.setText(""); + Pause = new JButton(runPauseAction); + Pause.setText(""); + + toolBar.add(Run); + toolBar.add(Step); + toolBar.add(Backstep); + toolBar.add(Pause); + toolBar.add(Stop); + toolBar.add(Reset); + + return toolBar; + } } From 1b330105738dbf9f9bdf35c5ca62e34ba3c6d86b Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 20 Jul 2021 23:20:29 +0530 Subject: [PATCH 59/84] Harts works dependent with main Hart --- src/rars/riscv/hardware/Register.java | 15 +++- .../riscv/hardware/RegisterAccessNotice.java | 13 +++- src/rars/riscv/hardware/RegisterFile.java | 68 ++++++++++++------- src/rars/riscv/instructions/AUIPC.java | 5 +- src/rars/riscv/instructions/Arithmetic.java | 16 ++++- .../instructions/AtomicMemoryOperation.java | 20 ++++-- src/rars/riscv/instructions/BEQ.java | 5 +- src/rars/riscv/instructions/BGE.java | 5 +- .../instructions/ImmediateInstruction.java | 16 ++++- src/rars/simulator/Simulator.java | 16 +++-- src/rars/tools/ReservationTablesTool.java | 6 ++ src/rars/venus/GeneralExecutePane.java | 10 ++- src/rars/venus/GeneralMainPane.java | 7 +- src/rars/venus/GeneralVenusUI.java | 4 +- src/rars/venus/TextSegmentWindow.java | 4 +- .../venus/registers/RegisterBlockWindow.java | 24 ++++--- src/rars/venus/registers/RegistersWindow.java | 13 +++- src/rars/venus/run/RunStepAction.java | 5 +- 18 files changed, 187 insertions(+), 65 deletions(-) diff --git a/src/rars/riscv/hardware/Register.java b/src/rars/riscv/hardware/Register.java index d50667b1..4252226b 100644 --- a/src/rars/riscv/hardware/Register.java +++ b/src/rars/riscv/hardware/Register.java @@ -41,6 +41,7 @@ public class Register extends Observable { private String name; private int number; private long resetValue; + private int hart; // volatile should be enough to allow safe multi-threaded access // w/o the use of synchronized methods. getValue and setValue // are the only methods here used by the register collection @@ -60,8 +61,15 @@ public Register(String n, int num, long val) { number = num; value = val; resetValue = val; + hart = -1; + } + public Register(String n, int num, long val, int hart) { + name = n; + number = num; + value = val; + resetValue = val; + this.hart = hart; } - /** * Returns the name of the Register. * @@ -171,7 +179,10 @@ public synchronized void changeResetValue(long reset) { private void notifyAnyObservers(int type) { if (this.countObservers() > 0) {// && Globals.program != null) && Globals.program.inSteppedExecution()) { this.setChanged(); - this.notifyObservers(new RegisterAccessNotice(type, this.name)); + if(this.hart == -1) + this.notifyObservers(new RegisterAccessNotice(type, this.name)); + else + this.notifyObservers(new RegisterAccessNotice(type, this.name, hart)); } } diff --git a/src/rars/riscv/hardware/RegisterAccessNotice.java b/src/rars/riscv/hardware/RegisterAccessNotice.java index ced06218..d20aea9e 100644 --- a/src/rars/riscv/hardware/RegisterAccessNotice.java +++ b/src/rars/riscv/hardware/RegisterAccessNotice.java @@ -38,23 +38,30 @@ a copy of this software and associated documentation files (the public class RegisterAccessNotice extends AccessNotice { private String registerName; - + private int hart; /** * Constructor will be called only within this package, so assume * register number is in valid range. */ + RegisterAccessNotice(int type, String registerName, int hart) { + super(type); + this.registerName = registerName; + this.hart = hart; + } RegisterAccessNotice(int type, String registerName) { super(type); this.registerName = registerName; + hart = -1; } - /** * Fetch the register number of register accessed. */ public String getRegisterName() { return registerName; } - + public int getHart(){ + return hart; + } /** * String representation indicates access type and which register */ diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index e5bd5c0c..2aea17e9 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -47,7 +47,7 @@ public class RegisterFile { public static final int GLOBAL_POINTER_REGISTER = 3; public static final int STACK_POINTER_REGISTER = 2; - private static final RegisterBlock instance = new RegisterBlock('x', new Register[]{ + public static final RegisterBlock instance = new RegisterBlock('x', new Register[]{ new Register("zero", 0, 0), new Register("ra", 1, 0), new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer), new Register("gp", GLOBAL_POINTER_REGISTER, Memory.globalPointer), @@ -66,7 +66,7 @@ public class RegisterFile { new Register("t3", 28, 0), new Register("t4", 29, 0), new Register("t5", 30, 0), new Register("t6", 31, 0) }); - private static ArrayList gInstance; + public static ArrayList gInstance; private static Register programCounter = new Register("pc", -1, Memory.textBaseAddress); private static ArrayList gProgramCounter; @@ -82,23 +82,23 @@ public static void initGRegisterBlock(){ gInstance = new ArrayList<>(); for(int i = 0; i < Globals.getHarts(); i++){ RegisterBlock temp = new RegisterBlock('x', new Register[]{ - new Register("zero", 0, 0), new Register("ra", 1, 0), - new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer), - new Register("gp", GLOBAL_POINTER_REGISTER, Memory.globalPointer), - new Register("tp", 4, 0), new Register("t0", 5, 0), - new Register("t1", 6, 0), new Register("t2", 7, 0), - new Register("s0", 8, 0), new Register("s1", 9, 0), - new Register("a0", 10, 0), new Register("a1", 11, 0), - new Register("a2", 12, 0), new Register("a3", 13, 0), - new Register("a4", 14, 0), new Register("a5", 15, 0), - new Register("a6", 16, 0), new Register("a7", 17, 0), - new Register("s2", 18, 0), new Register("s3", 19, 0), - new Register("s4", 20, 0), new Register("s5", 21, 0), - new Register("s6", 22, 0), new Register("s7", 23, 0), - new Register("s8", 24, 0), new Register("s9", 25, 0), - new Register("s10", 26, 0), new Register("s11", 27, 0), - new Register("t3", 28, 0), new Register("t4", 29, 0), - new Register("t5", 30, 0), new Register("t6", 31, 0) + new Register("zero", 0, 0, i), new Register("ra", 1, 0, i), + new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer, i), + new Register("gp", GLOBAL_POINTER_REGISTER, Memory.globalPointer, i), + new Register("tp", 4, 0, i), new Register("t0", 5, 0, i), + new Register("t1", 6, 0, i), new Register("t2", 7, 0, i), + new Register("s0", 8, 0, i), new Register("s1", 9, 0, i), + new Register("a0", 10, 0, i), new Register("a1", 11, 0, i), + new Register("a2", 12, 0, i), new Register("a3", 13, 0, i), + new Register("a4", 14, 0, i), new Register("a5", 15, 0, i), + new Register("a6", 16, 0, i), new Register("a7", 17, 0, i), + new Register("s2", 18, 0, i), new Register("s3", 19, 0, i), + new Register("s4", 20, 0, i), new Register("s5", 21, 0, i), + new Register("s6", 22, 0, i), new Register("s7", 23, 0, i), + new Register("s8", 24, 0, i), new Register("s9", 25, 0, i), + new Register("s10", 26, 0,i), new Register("s11", 27, 0, i), + new Register("t3", 28, 0, i), new Register("t4", 29, 0, i), + new Register("t5", 30, 0, i), new Register("t6", 31, 0, i) }); gInstance.add(temp); } @@ -123,7 +123,13 @@ public static void updateRegister(int num, long val) { } } } - + public static void updateRegister(int num, long val, int hart) { + if (num == 0) { + ; + } else { + gInstance.get(hart).updateRegister(num, val); + } + } /** * Sets the value of the register given to the value given. * @@ -146,7 +152,10 @@ public static int getValue(int num) { return (int) instance.getValue(num); } + public static int getValue(int num, int hart) { + return (int) gInstance.get(hart).getValue(num); + } /** * Returns the value of the register. * @@ -158,7 +167,10 @@ public static long getValueLong(int num) { return instance.getValue(num); } + public static long getValueLong(int num, int hart) { + return gInstance.get(hart).getValue(num); + } /** * Returns the value of the register. * @@ -179,7 +191,11 @@ public static int getValue(String name) { public static Register[] getRegisters() { return instance.getRegisters(); } - + public static Register[] getRegisters(int hart) { + if(gInstance == null) + initGRegisterBlock(); + return gInstance.get(hart).getRegisters(); + } /** * Get register object corresponding to given name. If no match, return null. * @@ -264,7 +280,11 @@ public static int getProgramCounter(int hart){ public static Register getProgramCounterRegister() { return programCounter; } - + public static Register getProgramCounterRegister(int hart) { + if(gProgramCounter == null) + initProgramCounter(); + return gProgramCounter.get(hart); + } /** * For returning the program counter's initial (reset) value. * @@ -307,7 +327,9 @@ public static void incrementPC(int hart){ public static void addRegistersObserver(Observer observer) { instance.addRegistersObserver(observer); } - + public static void addRegistersObserver(Observer observer, int hart) { + gInstance.get(hart).addRegistersObserver(observer); + } /** * Each individual register is a separate object and Observable. This handy method * will delete the given Observer from each one. Currently does not apply to Program diff --git a/src/rars/riscv/instructions/AUIPC.java b/src/rars/riscv/instructions/AUIPC.java index cd5d6559..2f9746bc 100644 --- a/src/rars/riscv/instructions/AUIPC.java +++ b/src/rars/riscv/instructions/AUIPC.java @@ -40,6 +40,9 @@ public AUIPC() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter() - INSTRUCTION_LENGTH + (operands[1] << 12)); + if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter() - INSTRUCTION_LENGTH + (operands[1] << 12)); + else + RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter() - INSTRUCTION_LENGTH + (operands[1] << 12), statement.getCurrentHart()); } } diff --git a/src/rars/riscv/instructions/Arithmetic.java b/src/rars/riscv/instructions/Arithmetic.java index 194d1570..9cec24ee 100644 --- a/src/rars/riscv/instructions/Arithmetic.java +++ b/src/rars/riscv/instructions/Arithmetic.java @@ -53,9 +53,19 @@ public Arithmetic(String usage, String description, String funct7, String funct3 public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); if (InstructionSet.rv64){ - RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]),RegisterFile.getValueLong(operands[2]))); - }else { - RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]),RegisterFile.getValue(operands[2]))); + if(statement.getCurrentHart() == 0) + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]),RegisterFile.getValueLong(operands[2]))); + else{ + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]),RegisterFile.getValueLong(operands[2])), statement.getCurrentHart()); + } + } + else { + + if(statement.getCurrentHart() == 0) + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]),RegisterFile.getValue(operands[2]))); + else{ + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]),RegisterFile.getValue(operands[2])), statement.getCurrentHart()); + } } } diff --git a/src/rars/riscv/instructions/AtomicMemoryOperation.java b/src/rars/riscv/instructions/AtomicMemoryOperation.java index 655cfac8..b245b67d 100644 --- a/src/rars/riscv/instructions/AtomicMemoryOperation.java +++ b/src/rars/riscv/instructions/AtomicMemoryOperation.java @@ -57,11 +57,23 @@ public AtomicMemoryOperation(String usage, String description, String funct5, bo public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); try { - int rs1Loc = RegisterFile.getValue(operands[2]); + int rs1Loc; + long rs2Value; + long rs1Data; + if(statement.getCurrentHart() == -1){ + rs1Loc = RegisterFile.getValue(operands[2]); + rs2Value = RegisterFile.getValueLong(operands[1]); + rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); + RegisterFile.updateRegister(operands[0], rs1Data); + } + else{ + rs1Loc = RegisterFile.getValue(operands[2], statement.getCurrentHart()); + rs2Value = RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); + rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); + RegisterFile.updateRegister(operands[0], rs1Data, statement.getCurrentHart()); + } Globals.reservationTables.unreserveAddress(0, rs1Loc, width); - long rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); - long rs2Value = RegisterFile.getValueLong(operands[1]); - RegisterFile.updateRegister(operands[0], rs1Data); + rs1Data = binaryOperation(rs1Data, rs2Value); if (InstructionSet.rv64) { Globals.memory.setDoubleWord(rs1Loc, rs1Data); diff --git a/src/rars/riscv/instructions/BEQ.java b/src/rars/riscv/instructions/BEQ.java index 250ce4b2..936104ce 100644 --- a/src/rars/riscv/instructions/BEQ.java +++ b/src/rars/riscv/instructions/BEQ.java @@ -37,6 +37,9 @@ public BEQ() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - return RegisterFile.getValueLong(operands[0]) == RegisterFile.getValueLong(operands[1]); + if(statement.getCurrentHart() == -1) + return RegisterFile.getValueLong(operands[0]) == RegisterFile.getValueLong(operands[1]); + else + return RegisterFile.getValueLong(operands[0], statement.getCurrentHart()) == RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); } } \ No newline at end of file diff --git a/src/rars/riscv/instructions/BGE.java b/src/rars/riscv/instructions/BGE.java index bb293912..b4ec30fb 100644 --- a/src/rars/riscv/instructions/BGE.java +++ b/src/rars/riscv/instructions/BGE.java @@ -37,6 +37,9 @@ public BGE() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - return RegisterFile.getValueLong(operands[0]) >= RegisterFile.getValueLong(operands[1]); + if(statement.getCurrentHart() == -1) + return RegisterFile.getValueLong(operands[0]) >= RegisterFile.getValueLong(operands[1]); + else + return RegisterFile.getValueLong(operands[0], statement.getCurrentHart()) >= RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); } } \ No newline at end of file diff --git a/src/rars/riscv/instructions/ImmediateInstruction.java b/src/rars/riscv/instructions/ImmediateInstruction.java index bb9a081a..ae8d7edb 100644 --- a/src/rars/riscv/instructions/ImmediateInstruction.java +++ b/src/rars/riscv/instructions/ImmediateInstruction.java @@ -52,11 +52,21 @@ public ImmediateInstruction(String usage, String description, String funct, bool public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); if (InstructionSet.rv64){ - RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]), + if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]), (operands[2] << 20) >> 20)); // make sure the immediate is sign-extended + else + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1], statement.getCurrentHart()), + (operands[2] << 20) >> 20), statement.getCurrentHart()); // make sure the immediate is sign-extended }else { - RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]), + + if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]), (operands[2] << 20) >> 20)); // make sure the immediate is sign-extended + else{ + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1], statement.getCurrentHart()), + (operands[2] << 20) >> 20), statement.getCurrentHart()); // make sure the immediate is sign-extended + } } } @@ -72,6 +82,6 @@ public void simulate(ProgramStatement statement) { * @return the result to be stored from the instruction */ protected int computeW(int value, int immediate){ - return (int) compute(value,immediate); + return (int) compute(value, immediate); } } \ No newline at end of file diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index 78dda06e..7da5ad0d 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -54,7 +54,6 @@ public class Simulator extends Observable { private static Simulator simulator = null; // Singleton object private static ArrayList gSimulator; private static Runnable interactiveGUIUpdater = null; - private int hart = 0; /** * various reasons for simulate to end... */ @@ -229,7 +228,7 @@ class SimThread implements Runnable { private SimulationException pe; private volatile boolean stop = false; private Reason constructReturnReason; - private int hart = -1; + private int hart; /** * SimThread constructor. Receives all the information it needs to simulate execution. @@ -498,14 +497,21 @@ public void run() { } else{ pc = RegisterFile.getProgramCounter(hart); + RegisterFile.incrementPC(hart); } // Get instuction try { - if(hart == -1) + if(hart == -1){ statement = Globals.memory.getStatement(pc); - else + if(statement != null) + statement.setCurrentHart(-1); + } + else{ statement = Globals.memory.getStatementNoNotify(pc); + if(statement != null) + statement.setCurrentHart(hart); + } } catch (AddressErrorException e) { SimulationException tmp; if (e.getType() == SimulationException.LOAD_ACCESS_FAULT) { @@ -536,8 +542,8 @@ public void run() { SimulationException.ILLEGAL_INSTRUCTION); } // THIS IS WHERE THE INSTRUCTION EXECUTION IS ACTUALLY SIMULATED! - instruction.simulate(statement); + instruction.simulate(statement); // IF statement added 7/26/06 (explanation above) if (Globals.getSettings().getBackSteppingEnabled()) { Globals.program.getBackStepper().addDoNothing(pc); diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 225aa587..dd7ac0e9 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -2,6 +2,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.RegisterFile; import rars.riscv.hardware.ReservationTable.bitWidth; import rars.venus.*; @@ -120,11 +121,16 @@ public void actionPerformed(ActionEvent e) { btnPlus.addActionListener(l -> { Globals.setHarts(1); super.dialog.dispose(); + RegisterFile.initGRegisterBlock(); + RegisterFile.initProgramCounter(); action(); + }); btnMinus.addActionListener(l -> { Globals.setHarts(-1); super.dialog.dispose(); + RegisterFile.initGRegisterBlock(); + RegisterFile.initProgramCounter(); action(); }); displayOptions.add(Box.createHorizontalGlue()); diff --git a/src/rars/venus/GeneralExecutePane.java b/src/rars/venus/GeneralExecutePane.java index a2d167c1..35376eb7 100644 --- a/src/rars/venus/GeneralExecutePane.java +++ b/src/rars/venus/GeneralExecutePane.java @@ -52,6 +52,7 @@ public class GeneralExecutePane extends JDesktopPane { private NumberDisplayBaseChooser valueDisplayBase; private NumberDisplayBaseChooser addressDisplayBase; private boolean labelWindowVisible; + private int hart; /** * initialize the Execute pane with major components @@ -62,10 +63,15 @@ public class GeneralExecutePane extends JDesktopPane { * @param csrRegs window containing the CSR set */ - public GeneralExecutePane(GeneralVenusUI mainUI, RegistersWindow regs, FloatingPointWindow fpRegs, ControlAndStatusWindow csrRegs) { + public GeneralExecutePane(GeneralVenusUI mainUI, RegistersWindow regs, FloatingPointWindow fpRegs, ControlAndStatusWindow csrRegs, int hart) { this.mainUI = mainUI; // Although these are displayed in Data Segment, they apply to all three internal // windows within the Execute pane. So they will be housed here. + addressDisplayBase = new NumberDisplayBaseChooser("Hexadecimal Addresses", + Globals.getSettings().getBooleanSetting(Settings.Bool.DISPLAY_ADDRESSES_IN_HEX)); + valueDisplayBase = new NumberDisplayBaseChooser("Hexadecimal Values", + Globals.getSettings().getBooleanSetting(Settings.Bool.DISPLAY_VALUES_IN_HEX));//VenusUI.DEFAULT_NUMBER_BASE); + this.hart = hart; registerValues = regs; fpRegValues = fpRegs; csrValues = csrRegs; @@ -227,7 +233,7 @@ public NumberDisplayBaseChooser getAddressDisplayBaseChooser() { public void numberDisplayBaseChanged(NumberDisplayBaseChooser chooser) { if (chooser == valueDisplayBase) { // Have all internal windows update their value columns - registerValues.updateRegisters(); + registerValues.updateRegisters(hart); fpRegValues.updateRegisters(); csrValues.updateRegisters(); textSegment.updateBasicStatements(); diff --git a/src/rars/venus/GeneralMainPane.java b/src/rars/venus/GeneralMainPane.java index d8a08056..aa8b8461 100644 --- a/src/rars/venus/GeneralMainPane.java +++ b/src/rars/venus/GeneralMainPane.java @@ -48,7 +48,7 @@ a copy of this software and associated documentation files (the public class GeneralMainPane extends JTabbedPane { GeneralExecutePane executeTab; - + private int hart; private GeneralVenusUI mainUI; /** @@ -56,15 +56,16 @@ public class GeneralMainPane extends JTabbedPane { **/ public GeneralMainPane(GeneralVenusUI appFrame, RegistersWindow regs, - FloatingPointWindow cop1Regs, ControlAndStatusWindow cop0Regs) { + FloatingPointWindow cop1Regs, ControlAndStatusWindow cop0Regs, int hart) { super(); + this.hart = hart; this.mainUI = appFrame; this.setTabPlacement(JTabbedPane.TOP); //LEFT); if (this.getUI() instanceof BasicTabbedPaneUI) { BasicTabbedPaneUI ui = (BasicTabbedPaneUI) this.getUI(); } - executeTab = new GeneralExecutePane(appFrame, regs, cop1Regs, cop0Regs); + executeTab = new GeneralExecutePane(appFrame, regs, cop1Regs, cop0Regs, hart); String executeTabTitle = "Execute"; //"
 
E
x
e
c
u
t
e
 
"; Icon executeTabIcon = null;//new ImageIcon(Toolkit.getDefaultToolkit().getImage(this.getClass().getResource(Globals.imagesPath+"Execute_tab.jpg"))); diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index db7f349a..c0a69446 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -111,13 +111,13 @@ public GeneralVenusUI(String s) { // roughly in bottom-up order; some are created in component constructors and thus are // not visible here. - registersTab = new RegistersWindow("Not GUI"); + registersTab = new RegistersWindow(s.charAt(s.length()-1) - '1'); fpTab = new FloatingPointWindow(); csrTab = new ControlAndStatusWindow(); registersPane = new GeneralRegistersPane(mainUI, registersTab, fpTab, csrTab); registersPane.setPreferredSize(registersPanePreferredSize); - mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab); + mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab, s.charAt(s.length()-1) - '1'); mainPane.setPreferredSize(mainPanePreferredSize); try { mainPane.getExecutePane().getTextSegmentWindow().setMaximum(true); diff --git a/src/rars/venus/TextSegmentWindow.java b/src/rars/venus/TextSegmentWindow.java index 59ef000e..b323cee2 100644 --- a/src/rars/venus/TextSegmentWindow.java +++ b/src/rars/venus/TextSegmentWindow.java @@ -488,7 +488,9 @@ public void highlightStepAtPC() { highlightStepAtAddress(RegisterFile.getProgramCounter()); } - + public void highlightStepAtPC(int hart) { + highlightStepAtAddress(RegisterFile.getProgramCounter(hart)); + } /** * Highlights the source code line whose address matches the given * text segment address. diff --git a/src/rars/venus/registers/RegisterBlockWindow.java b/src/rars/venus/registers/RegisterBlockWindow.java index 0550261f..f3624e93 100644 --- a/src/rars/venus/registers/RegisterBlockWindow.java +++ b/src/rars/venus/registers/RegisterBlockWindow.java @@ -62,7 +62,7 @@ public abstract class RegisterBlockWindow extends JPanel implements Observer { private int highlightRow; private Register[] registers; private boolean notMainUI = true; - + private int hart; private static final int NAME_COLUMN = 0; private static final int NUMBER_COLUMN = 1; private static final int VALUE_COLUMN = 2; @@ -77,6 +77,7 @@ public RegisterBlockWindow(Register[] registers, String[] registerDescriptions, Simulator.getInstance().addObserver(this); settings = Globals.getSettings(); this.registers = registers; + this.hart = -1; clearHighlighting(); table = new MyTippedJTable(new RegTableModel(setupWindow()), registerDescriptions, new String[]{"Each register has a tool tip describing its usage convention", "Corresponding register number", valueTip}) { @@ -93,12 +94,11 @@ public RegisterBlockWindow(Register[] registers, String[] registerDescriptions, this.setLayout(new BorderLayout()); // table display will occupy entire width if widened this.add(new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); } - - public RegisterBlockWindow(Register[] registers2, String[] regtooltips, String string, String string2) { - this(registers2, regtooltips, string); - notMainUI = false; + + public RegisterBlockWindow(Register[] registers, String[] registerDescriptions, String valueTip, int hart) { + this(registers, registerDescriptions, valueTip); + this.hart = hart; } - protected abstract String formatRegister(Register value, int base); protected abstract void beginObserving(); @@ -159,7 +159,13 @@ public void updateRegisters() { Globals.getGui().getMainPane().getExecutePane().getValueDisplayBase()), i, 2); } } - + public void updateRegisters(int hart) { + System.out.println("\nWorks"); + for (int i = 0; i < registers.length; i++) { + ((RegTableModel) table.getModel()).setDisplayAndModelValueAt(formatRegister(registers[i], + Globals.getHartWindows().get(hart).getMainPane().getExecutePane().getValueDisplayBase()), i, 2); + } + } /** * Highlight the row corresponding to the given register. * @@ -188,7 +194,8 @@ private void highlightCellForRegister(Register register) { * @param obj Auxiliary object with additional information. */ public void update(Observable observable, Object obj) { - if (observable == rars.simulator.Simulator.getInstance()) { + System.out.println("fff " + hart); + if (observable == rars.simulator.Simulator.getInstance() && hart == -1) { SimulatorNotice notice = (SimulatorNotice) obj; if (notice.getAction() == SimulatorNotice.SIMULATOR_START) { // Simulated MIPS execution starts. Respond to memory changes if running in timed @@ -207,6 +214,7 @@ public void update(Observable observable, Object obj) { if (access.getAccessType() == AccessNotice.WRITE) { // Uses the same highlighting technique as for Text Segment -- see // AddressCellRenderer class in DataSegmentWindow.java. + System.out.println("\nHHHHHHHH " + hart + "\n"); this.highlighting = true; this.highlightCellForRegister((Register) observable); if(notMainUI) diff --git a/src/rars/venus/registers/RegistersWindow.java b/src/rars/venus/registers/RegistersWindow.java index eb5b5282..1968ffbb 100644 --- a/src/rars/venus/registers/RegistersWindow.java +++ b/src/rars/venus/registers/RegistersWindow.java @@ -12,6 +12,7 @@ public class RegistersWindow extends RegisterBlockWindow { /* * The tips to show when hovering over the names of the registers */ + private int hart; private static final String[] regToolTips = { /* zero */ "constant 0", /* ra */ "return address (used by function call)", @@ -50,10 +51,12 @@ public class RegistersWindow extends RegisterBlockWindow { public RegistersWindow() { super(getRegisters(), regToolTips, "Current 32 bit value"); + hart = -1; } - public RegistersWindow(String s){ - super(getRegisters(), regToolTips, "Current 32 bit value", "GeneralGUI"); + public RegistersWindow(int hart){ + super(getRegisters(hart), regToolTips, "Current 32 bit value", hart); + this.hart = hart; } /* @@ -65,6 +68,12 @@ private static Register[] getRegisters() { out[base.length] = RegisterFile.getProgramCounterRegister(); return out; } + private static Register[] getRegisters(int hart) { + Register[] base = RegisterFile.getRegisters(hart); + Register[] out = Arrays.copyOf(base, base.length + 1); + out[base.length] = RegisterFile.getProgramCounterRegister(hart); + return out; + } protected String formatRegister(Register value, int base) { if (Globals.getSettings().getBooleanSetting(Settings.Bool.RV64_ENABLED)){ diff --git a/src/rars/venus/run/RunStepAction.java b/src/rars/venus/run/RunStepAction.java index 5ad4406c..780e87dd 100644 --- a/src/rars/venus/run/RunStepAction.java +++ b/src/rars/venus/run/RunStepAction.java @@ -103,7 +103,10 @@ public void update(Observable o, Object simulator) { Globals.program.startSimulation(1, null); for(int i = 0; i < hartWindows.size(); i++){ + Simulator.getInstance(i).addObserver(stopListener); Globals.gPrograms.get(i).startSimulation(1, null, i); + gExecutePanes.get(i).getRegistersWindow().updateRegisters(i); + System.out.println("Hart " + i + " " + RegisterFile.gInstance.get(i).getRegister(6).getValue()); } } else { // note: this should never occur since "Step" is only enabled after successful assembly. @@ -120,7 +123,7 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p executePane.getDataSegmentWindow().updateValues(); for(int i = 0; i < hartWindows.size(); i++){ - gExecutePanes.get(i).getRegistersWindow().updateRegisters(); + gExecutePanes.get(i).getRegistersWindow().updateRegisters(i); gExecutePanes.get(i).getFloatingPointWindow().updateRegisters(); gExecutePanes.get(i).getControlAndStatusWindow().updateRegisters(); } From 566200f5f90c408f0574a1063c2927714624e2e2 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Thu, 22 Jul 2021 13:09:24 +0530 Subject: [PATCH 60/84] Highlightung works with few bugs --- src/rars/riscv/InstructionSet.java | 8 ++- src/rars/riscv/hardware/Register.java | 4 ++ src/rars/riscv/hardware/RegisterFile.java | 55 ++++++++++++++++++- src/rars/riscv/instructions/JAL.java | 7 ++- src/rars/riscv/instructions/LRW.java | 9 ++- .../registers/ControlAndStatusWindow.java | 5 +- .../venus/registers/FloatingPointWindow.java | 4 +- .../venus/registers/RegisterBlockWindow.java | 11 ++-- src/rars/venus/run/RunAssembleAction.java | 2 - 9 files changed, 89 insertions(+), 16 deletions(-) diff --git a/src/rars/riscv/InstructionSet.java b/src/rars/riscv/InstructionSet.java index b186eb2f..33cf37f6 100644 --- a/src/rars/riscv/InstructionSet.java +++ b/src/rars/riscv/InstructionSet.java @@ -322,7 +322,9 @@ public static void processBranch(int displacement) { public static void processJump(int targetAddress) { RegisterFile.setProgramCounter(targetAddress); } - + public static void processJump(int targetAddress, int hart) { + RegisterFile.setProgramCounter(targetAddress, hart); + } /* * Method to process storing of a return address in the given * register. This is used only by the "and link" @@ -333,7 +335,9 @@ public static void processJump(int targetAddress) { public static void processReturnAddress(int register) { RegisterFile.updateRegister(register, RegisterFile.getProgramCounter()); } - + public static void processReturnAddress(int register, int hart){ + RegisterFile.updateRegister(register, RegisterFile.getProgramCounter(hart), hart); + } private static class MatchMap implements Comparable { private int mask; private int maskLength; // number of 1 bits in mask diff --git a/src/rars/riscv/hardware/Register.java b/src/rars/riscv/hardware/Register.java index 4252226b..03eede5b 100644 --- a/src/rars/riscv/hardware/Register.java +++ b/src/rars/riscv/hardware/Register.java @@ -140,6 +140,10 @@ public synchronized long setValue(long val) { return old; } + public int getHart(){ + return hart; + } + /** * Sets the value of the register to the val passed to it. This should only * be used to update registers not related to the current instruction. diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index 2aea17e9..572ffa67 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -72,6 +72,9 @@ public class RegisterFile { private static ArrayList gProgramCounter; public static void initProgramCounter(){ + if(gProgramCounter != null){ + return; + } gProgramCounter = new ArrayList<>(); for(int i = 1; i < Globals.getHarts(); i++){ Register temp = new Register("pc", -1, Memory.textBaseAddress); @@ -79,6 +82,8 @@ public static void initProgramCounter(){ } } public static void initGRegisterBlock(){ + if(gInstance != null) + return; gInstance = new ArrayList<>(); for(int i = 0; i < Globals.getHarts(); i++){ RegisterBlock temp = new RegisterBlock('x', new Register[]{ @@ -104,7 +109,40 @@ public static void initGRegisterBlock(){ } } - + public static void changeHarts(int sign){ + if(gInstance == null){ + initProgramCounter(); + initGRegisterBlock(); + } + if(sign > 0){ + int i = gInstance.size(); + RegisterBlock temp = new RegisterBlock('x', new Register[]{ + new Register("zero", 0, 0, i), new Register("ra", 1, 0, i), + new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer, i), + new Register("gp", GLOBAL_POINTER_REGISTER, Memory.globalPointer, i), + new Register("tp", 4, 0, i), new Register("t0", 5, 0, i), + new Register("t1", 6, 0, i), new Register("t2", 7, 0, i), + new Register("s0", 8, 0, i), new Register("s1", 9, 0, i), + new Register("a0", 10, 0, i), new Register("a1", 11, 0, i), + new Register("a2", 12, 0, i), new Register("a3", 13, 0, i), + new Register("a4", 14, 0, i), new Register("a5", 15, 0, i), + new Register("a6", 16, 0, i), new Register("a7", 17, 0, i), + new Register("s2", 18, 0, i), new Register("s3", 19, 0, i), + new Register("s4", 20, 0, i), new Register("s5", 21, 0, i), + new Register("s6", 22, 0, i), new Register("s7", 23, 0, i), + new Register("s8", 24, 0, i), new Register("s9", 25, 0, i), + new Register("s10", 26, 0,i), new Register("s11", 27, 0, i), + new Register("t3", 28, 0, i), new Register("t4", 29, 0, i), + new Register("t5", 30, 0, i), new Register("t6", 31, 0, i) + }); + gInstance.add(temp); + } + if(sign < 0){ + gInstance.remove(gInstance.size() -1); + gProgramCounter.remove(gProgramCounter.size()-1); + } + + } /** * This method updates the register value who's number is num. Also handles the lo and hi registers * @@ -259,7 +297,14 @@ public static int setProgramCounter(int value) { } return old; } - + public static int setProgramCounter(int value, int hart) { + int old = (int)gProgramCounter.get(hart).getValue(); + gProgramCounter.get(hart).setValue(value); + if (Globals.getSettings().getBackSteppingEnabled()) { + Globals.program.getBackStepper().addPCRestore(old); + } + return old; + } /** * For returning the program counters value. * @@ -307,6 +352,12 @@ public static int getInitialProgramCounter() { public static void resetRegisters() { instance.resetRegisters(); initializeProgramCounter(Globals.getSettings().getBooleanSetting(Settings.Bool.START_AT_MAIN));// replaces "programCounter.resetValue()", DPS 3/3/09 + if(gInstance == null) + return; + for(int i = 0; i < gInstance.size(); i++){ + gInstance.get(i).resetRegisters(); + } + } /** diff --git a/src/rars/riscv/instructions/JAL.java b/src/rars/riscv/instructions/JAL.java index 685bed0a..680b32d5 100644 --- a/src/rars/riscv/instructions/JAL.java +++ b/src/rars/riscv/instructions/JAL.java @@ -42,7 +42,12 @@ public JAL() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); + if(statement.getCurrentHart() != -1){ + InstructionSet.processReturnAddress(operands[0], statement.getCurrentHart()); + InstructionSet.processJump(RegisterFile.getProgramCounter(statement.getCurrentHart()) - Instruction.INSTRUCTION_LENGTH + operands[1]); + return; + } InstructionSet.processReturnAddress(operands[0]); - InstructionSet.processJump(RegisterFile.getProgramCounter() - Instruction.INSTRUCTION_LENGTH + operands[1]); + InstructionSet.processJump(RegisterFile.getProgramCounter() - Instruction.INSTRUCTION_LENGTH + operands[1], statement.getCurrentHart()); } } \ No newline at end of file diff --git a/src/rars/riscv/instructions/LRW.java b/src/rars/riscv/instructions/LRW.java index 0d433abc..7e83df66 100644 --- a/src/rars/riscv/instructions/LRW.java +++ b/src/rars/riscv/instructions/LRW.java @@ -15,14 +15,17 @@ public LRW() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); try { - RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1]))); + if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1]), statement.getCurrentHart())); + else + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1], statement.getCurrentHart()), statement.getCurrentHart()), statement.getCurrentHart()); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } - private long load(int address) throws AddressErrorException { - Globals.reservationTables.reserveAddress(0, address, bitWidth.word); + private long load(int address, int hart) throws AddressErrorException { + Globals.reservationTables.reserveAddress(hart + 1, address, bitWidth.word); return Globals.memory.getWord(address); } } diff --git a/src/rars/venus/registers/ControlAndStatusWindow.java b/src/rars/venus/registers/ControlAndStatusWindow.java index 743ad022..da453413 100644 --- a/src/rars/venus/registers/ControlAndStatusWindow.java +++ b/src/rars/venus/registers/ControlAndStatusWindow.java @@ -47,7 +47,10 @@ protected String formatRegister(Register value, int base) { protected void beginObserving() { ControlAndStatusRegisterFile.addRegistersObserver(this); } - + protected void beginObserving(int hart) { + ControlAndStatusRegisterFile.addRegistersObserver(this); + } + protected void endObserving() { ControlAndStatusRegisterFile.deleteRegistersObserver(this); } diff --git a/src/rars/venus/registers/FloatingPointWindow.java b/src/rars/venus/registers/FloatingPointWindow.java index 713f8720..01af2972 100644 --- a/src/rars/venus/registers/FloatingPointWindow.java +++ b/src/rars/venus/registers/FloatingPointWindow.java @@ -59,7 +59,9 @@ protected String formatRegister(Register value, int base) { protected void beginObserving() { FloatingPointRegisterFile.addRegistersObserver(this); } - + protected void beginObserving(int hart) { + FloatingPointRegisterFile.addRegistersObserver(this); + } protected void endObserving() { FloatingPointRegisterFile.deleteRegistersObserver(this); } diff --git a/src/rars/venus/registers/RegisterBlockWindow.java b/src/rars/venus/registers/RegisterBlockWindow.java index dcaff304..bcbfcffd 100644 --- a/src/rars/venus/registers/RegisterBlockWindow.java +++ b/src/rars/venus/registers/RegisterBlockWindow.java @@ -119,6 +119,7 @@ public RegisterBlockWindow(Register[] registers, String[] registerDescriptions, protected abstract String formatRegister(Register value, int base); protected abstract void beginObserving(); + protected abstract void beginObserving(int hart); protected abstract void endObserving(); @@ -188,6 +189,7 @@ public void updateRegisters(int hart) { * @param register Register object corresponding to row to be selected. */ private void highlightCellForRegister(Register register) { + System.out.println(register.getHart() + " ggg"); for (int i = 0; i < registers.length; i++) { if (registers[i] == register) { this.highlightRow = i; @@ -216,7 +218,10 @@ public void update(Observable observable, Object obj) { // Simulated MIPS execution starts. Respond to memory changes if running in timed // or stepped mode. if (notice.getRunSpeed() != RunSpeedPanel.UNLIMITED_SPEED || notice.getMaxSteps() == 1) { - beginObserving(); + if(this.hart == -1) + beginObserving(); + else + beginObserving(hart); this.highlighting = true; } } else { @@ -229,11 +234,9 @@ public void update(Observable observable, Object obj) { if (access.getAccessType() == AccessNotice.WRITE) { // Uses the same highlighting technique as for Text Segment -- see // AddressCellRenderer class in DataSegmentWindow.java. - System.out.println("\nHHHHHHHH " + hart + "\n"); + System.out.println("\nHHHHHHHH " + hart + " " + ((Register) observable).getHart()); this.highlighting = true; this.highlightCellForRegister((Register) observable); - if(notMainUI && hart == -1) - Globals.getGui().getRegistersPane().setSelectedComponent(this); } } } diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index 1f2d4208..03b6865e 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -78,8 +78,6 @@ static boolean getWarningsAreErrors() { public void actionPerformed(ActionEvent e) { hartWindows = Globals.getHartWindows(); - RegisterFile.initGRegisterBlock(); - RegisterFile.initProgramCounter(); String name = this.getValue(Action.NAME).toString(); MessagesPane messagesPane = mainUI.getMessagesPane(); ExecutePane executePane = mainUI.getMainPane().getExecutePane(); From 7534aed7c10daf183e1e915f1a68953991d9311e Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Thu, 22 Jul 2021 14:42:15 -0600 Subject: [PATCH 61/84] sync action buttons with main window --- src/rars/venus/GeneralVenusUI.java | 168 ++++++++++++++++++++++++++--- src/rars/venus/VenusUI.java | 12 ++- 2 files changed, 163 insertions(+), 17 deletions(-) diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index b47c0347..a25b56fe 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -1,6 +1,7 @@ package rars.venus; import rars.Globals; +import rars.Settings; import rars.simulator.Simulator; import rars.venus.registers.*; import rars.venus.run.*; @@ -12,9 +13,9 @@ import java.net.URL; /* -Copyright (c) 2003-2006, Siva Chowdeswar Nandipati +Copyright (c) 2003-2006, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura -Developed by Siva Chowdeswar Nandipati (sivachow@ualberta.ca) +Developed by Siva Chowdeswar Nandipati (sivachow@ualberta.ca) and Giancarlo (pernudi@ualberta.ca) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -39,16 +40,10 @@ a copy of this software and associated documentation files (the */ /** - * Top level container for Venus GUI. + * Top level container for General Venus GUI. * - * @author Sanderson and Team JSpim + * @author Siva, Giancarlo, Sanderson, and Team JSpim **/ - - /* Heavily modified by Pete Sanderson, July 2004, to incorporate JSPIMMenu and JSPIMToolbar - * not as subclasses of JMenuBar and JToolBar, but as instances of them. They are both - * here primarily so both can share the Action objects. - */ - public class GeneralVenusUI extends JFrame { GeneralVenusUI mainUI; @@ -79,6 +74,7 @@ public class GeneralVenusUI extends JFrame { public GeneralVenusUI(String s) { super(s); mainUI = this; + VenusUI.observers.add(this); double screenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); double screenHeight = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); double mainWidthPct = (screenWidth < 1000.0) ? 0.67 : 0.73; @@ -140,19 +136,22 @@ public GeneralVenusUI(String s) { center.add(horizonSplitter); this.add(center); - // This is invoked when opening the app. It will set the app to - // appear at full screen size. this.addWindowListener( - new WindowAdapter() { + new WindowAdapter() { + // This is invoked when opening the app. It will set the app to + // appear at full screen size. public void windowOpened(WindowEvent e) { mainUI.pack(); + mainUI.setMenuState(); } - }); - this.pack(); + // This is invoked when closing the app. + public void windowClosed(WindowEvent e) { + VenusUI.observers.remove(mainUI); + } + }); } - /** * To set whether the register values are reset. * @@ -288,4 +287,141 @@ JToolBar setUpToolBar() { return toolBar; } + + /* + * Determine from FileStatus what the menu state (enabled/disabled)should be + * then call the appropriate method to set it. Current states are: + * + * setMenuStateInitial: set upon startup and after File->Close + * setMenuStateEditingNew: set upon File->New setMenuStateEditing: set upon + * File->Open or File->Save or erroneous Run->Assemble setMenuStateRunnable: set + * upon successful Run->Assemble setMenuStateRunning: set upon Run->Go + * setMenuStateTerminated: set upon completion of simulated execution + */ + protected void setMenuState() { + int status = VenusUI.getMenuState(); + switch (status) { + case FileStatus.NO_FILE: + setMenuStateInitial(); + break; + case FileStatus.NEW_NOT_EDITED: + setMenuStateEditingNew(); + break; + case FileStatus.NEW_EDITED: + setMenuStateEditingNew(); + break; + case FileStatus.NOT_EDITED: + setMenuStateNotEdited(); // was MenuStateEditing. DPS 9-Aug-2011 + break; + case FileStatus.EDITED: + setMenuStateEditing(); + break; + case FileStatus.RUNNABLE: + setMenuStateRunnable(); + break; + case FileStatus.RUNNING: + setMenuStateRunning(); + break; + case FileStatus.TERMINATED: + setMenuStateTerminated(); + break; + case FileStatus.OPENING:// This is a temporary state. DPS 9-Aug-2011 + break; + default: + System.out.println("Invalid File Status: " + status); + break; + } + } + + private void setMenuStateInitial() { + runGoAction.setEnabled(false); + runStepAction.setEnabled(false); + runBackstepAction.setEnabled(false); + runResetAction.setEnabled(false); + runStopAction.setEnabled(false); + runPauseAction.setEnabled(false); + } + + /* + * Added DPS 9-Aug-2011, for newly-opened files. Retain existing Run menu state + * (except Assemble, which is always true). Thus if there was a valid assembly + * it is retained. + */ + private void setMenuStateNotEdited() { + /* Note: undo and redo are handled separately by the undo manager */ + // If assemble-all, allow previous Run menu settings to remain. + // Otherwise, clear them out. DPS 9-Aug-2011 + if (!Globals.getSettings().getBooleanSetting(Settings.Bool.ASSEMBLE_ALL)) { + runGoAction.setEnabled(false); + runStepAction.setEnabled(false); + runBackstepAction.setEnabled(false); + runResetAction.setEnabled(false); + runStopAction.setEnabled(false); + runPauseAction.setEnabled(false); + } + } + + private void setMenuStateEditing() { + /* Note: undo and redo are handled separately by the undo manager */ + runGoAction.setEnabled(false); + runStepAction.setEnabled(false); + runBackstepAction.setEnabled(false); + runResetAction.setEnabled(false); + runStopAction.setEnabled(false); + runPauseAction.setEnabled(false); + } + + /* + * Use this when "File -> New" is used + */ + private void setMenuStateEditingNew() { + /* Note: undo and redo are handled separately by the undo manager */ + runGoAction.setEnabled(false); + runStepAction.setEnabled(false); + runBackstepAction.setEnabled(false); + runResetAction.setEnabled(false); + runStopAction.setEnabled(false); + runPauseAction.setEnabled(false); + } + + /* + * Use this upon successful assemble or reset + */ + private void setMenuStateRunnable() { + /* Note: undo and redo are handled separately by the undo manager */ + runGoAction.setEnabled(true); + runStepAction.setEnabled(true); + runBackstepAction.setEnabled( + Globals.getSettings().getBackSteppingEnabled() && !Globals.program.getBackStepper().empty()); + runResetAction.setEnabled(true); + runStopAction.setEnabled(false); + runPauseAction.setEnabled(false); + } + + /* + * Use this while program is running + */ + private void setMenuStateRunning() { + /* Note: undo and redo are handled separately by the undo manager */ + runGoAction.setEnabled(false); + runStepAction.setEnabled(false); + runBackstepAction.setEnabled(false); + runResetAction.setEnabled(false); + runStopAction.setEnabled(true); + runPauseAction.setEnabled(true); + } + + /* + * Use this upon completion of execution + */ + private void setMenuStateTerminated() { + /* Note: undo and redo are handled separately by the undo manager */ + runGoAction.setEnabled(false); + runStepAction.setEnabled(false); + runBackstepAction.setEnabled( + Globals.getSettings().getBackSteppingEnabled() && !Globals.program.getBackStepper().empty()); + runResetAction.setEnabled(true); + runStopAction.setEnabled(false); + runPauseAction.setEnabled(false); + } } diff --git a/src/rars/venus/VenusUI.java b/src/rars/venus/VenusUI.java index 9225d28f..9791d63d 100644 --- a/src/rars/venus/VenusUI.java +++ b/src/rars/venus/VenusUI.java @@ -16,6 +16,7 @@ import java.awt.*; import java.awt.event.*; import java.net.URL; +import java.util.ArrayList; /* Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar @@ -112,6 +113,7 @@ public class VenusUI extends JFrame { settingsHighlightingAction, settingsMemoryConfigurationAction, settingsSelfModifyingCodeAction,settingsRV64Action; private Action helpHelpAction, helpAboutAction; + protected static ArrayList observers; /** * Constructor for the Class. Sets up a window object for the UI @@ -124,6 +126,7 @@ public VenusUI(String s) { mainUI = this; Globals.setGui(this); this.editor = new Editor(this); + observers = new ArrayList(); double screenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); double screenHeight = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); @@ -799,6 +802,7 @@ public void setMenuState(int status) { System.out.println("Invalid File Status: " + status); break; } + notifyObservers(); } @@ -1185,4 +1189,10 @@ private ImageIcon loadIcon(String name) { private KeyStroke makeShortcut(int key) { return KeyStroke.getKeyStroke(key, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); } -} \ No newline at end of file + + public void notifyObservers() { + for (GeneralVenusUI ui : observers) { + ui.setMenuState(); + } + } +} From ff2c506432160e91eda3fc296f0881139878a91e Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Fri, 23 Jul 2021 11:07:38 -0600 Subject: [PATCH 62/84] set terminal state independent --- src/rars/venus/GeneralVenusUI.java | 5 +---- src/rars/venus/run/RunGoAction.java | 5 ++++- src/rars/venus/run/RunStepAction.java | 8 +++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index a25b56fe..f5eaa121 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -322,9 +322,6 @@ protected void setMenuState() { case FileStatus.RUNNING: setMenuStateRunning(); break; - case FileStatus.TERMINATED: - setMenuStateTerminated(); - break; case FileStatus.OPENING:// This is a temporary state. DPS 9-Aug-2011 break; default: @@ -414,7 +411,7 @@ private void setMenuStateRunning() { /* * Use this upon completion of execution */ - private void setMenuStateTerminated() { + public void setMenuStateTerminated() { /* Note: undo and redo are handled separately by the undo manager */ runGoAction.setEnabled(false); runStepAction.setEnabled(false); diff --git a/src/rars/venus/run/RunGoAction.java b/src/rars/venus/run/RunGoAction.java index 3d5bd5b1..17b99402 100644 --- a/src/rars/venus/run/RunGoAction.java +++ b/src/rars/venus/run/RunGoAction.java @@ -188,6 +188,9 @@ public void stopped(SimulationException pe, Simulator.Reason reason) { gexecutePanes.get(i).getControlAndStatusWindow().updateRegisters(); } FileStatus.set(FileStatus.TERMINATED); + for (GeneralVenusUI hw : hartWindows) { + hw.setMenuStateTerminated(); + } SystemIO.resetFiles(); // close any files opened in MIPS program // Bring CSRs to the front if terminated due to exception. if (pe != null) { @@ -269,4 +272,4 @@ private void processProgramArgumentsIfAny() { } -} \ No newline at end of file +} diff --git a/src/rars/venus/run/RunStepAction.java b/src/rars/venus/run/RunStepAction.java index 6b5d00e1..f1c94d09 100644 --- a/src/rars/venus/run/RunStepAction.java +++ b/src/rars/venus/run/RunStepAction.java @@ -141,6 +141,9 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p gExecutePanes.get(i).getTextSegmentWindow().unhighlightAllSteps(); } FileStatus.set(FileStatus.TERMINATED); + for (GeneralVenusUI hw : hartWindows) { + hw.setMenuStateTerminated(); + } } if (done && pe == null) { mainUI.getMessagesPane().postMessage( @@ -160,6 +163,9 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p "\n" + name + ": execution terminated with errors.\n\n"); mainUI.getRegistersPane().setSelectedComponent(executePane.getControlAndStatusWindow()); FileStatus.set(FileStatus.TERMINATED); // should be redundant. + for (GeneralVenusUI hw : hartWindows) { + hw.setMenuStateTerminated(); + } executePane.getTextSegmentWindow().setCodeHighlighting(true); executePane.getTextSegmentWindow().unhighlightAllSteps(); executePane.getTextSegmentWindow().highlightStepAtAddress(RegisterFile.getProgramCounter() - 4); @@ -194,4 +200,4 @@ private void processProgramArgumentsIfAny() { } new ProgramArgumentList(programArguments).storeProgramArguments(); } -} \ No newline at end of file +} From 5509ea0d823910becc368bb701f36ee6437e021b Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Mon, 26 Jul 2021 16:14:19 -0600 Subject: [PATCH 63/84] extend Zicsr for multithread support --- .../ControlAndStatusRegisterFile.java | 75 ++++++++++++++++++- src/rars/riscv/hardware/RegisterFile.java | 8 +- src/rars/riscv/instructions/CSRRC.java | 25 +++++-- src/rars/riscv/instructions/CSRRCI.java | 23 ++++-- src/rars/riscv/instructions/CSRRS.java | 23 ++++-- src/rars/riscv/instructions/CSRRSI.java | 22 ++++-- src/rars/riscv/instructions/CSRRW.java | 19 ++++- src/rars/riscv/instructions/CSRRWI.java | 19 ++++- src/rars/tools/ReservationTablesTool.java | 3 + src/rars/venus/GeneralVenusUI.java | 2 +- .../registers/ControlAndStatusWindow.java | 7 ++ 11 files changed, 192 insertions(+), 34 deletions(-) diff --git a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java index 0b4bfc66..8fa5b878 100644 --- a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java +++ b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java @@ -2,6 +2,7 @@ import rars.Globals; +import java.util.ArrayList; import java.util.Observer; /* @@ -82,6 +83,41 @@ public class ControlAndStatusRegisterFile { instance = new RegisterBlock('_', tmp); // prefix not used } + public static ArrayList gInstance; + + public static void changeHarts(int sign) { + if (gInstance == null) { + gInstance = new ArrayList<>(); + } + if (sign > 0) { + for (int i = 1; i <= Globals.getHarts(); i++) { + Register[] tmp = new Register[] { new MaskedRegister("ustatus", 0x000, 0, ~0x11), null, // fflags + null, // frm + new MaskedRegister("fcsr", 0x003, 0, ~0xFF), new Register("uie", 0x004, 0), + new Register("utvec", 0x005, 0), new Register("uscratch", 0x040, 0), + new Register("uepc", 0x041, 0), new Register("ucause", 0x042, 0), + new Register("utval", 0x043, 0), new Register("uip", 0x044, 0), + new ReadOnlyRegister("cycle", 0xC00, 0), new ReadOnlyRegister("time", 0xC01, 0), + new ReadOnlyRegister("instret", 0xC02, 0), null, // cycleh + null, // timeh + null, // instreth + null, // mhartid + }; + tmp[1] = new LinkedRegister("fflags", 0x001, tmp[3], 0x1F); + tmp[2] = new LinkedRegister("frm", 0x002, tmp[3], 0xE0); + tmp[14] = new LinkedRegister("cycleh", 0xC80, tmp[11], 0xFFFFFFFF_00000000L); + tmp[15] = new LinkedRegister("timeh", 0xC81, tmp[12], 0xFFFFFFFF_00000000L); + tmp[16] = new LinkedRegister("instreth", 0xC82, tmp[13], 0xFFFFFFFF_00000000L); + tmp[17] = new ReadOnlyRegister("mhartid", 0xF10, i); + RegisterBlock temp = new RegisterBlock('_', tmp); + gInstance.add(temp); + } + } + if (sign < 0) { + gInstance.remove(gInstance.size() - 1); + } + } + /** * This method updates the register value * @@ -105,6 +141,22 @@ public static boolean updateRegister(int num, long val) { return false; } + public static boolean updateRegister(int num, long val, int hart) { + if (gInstance.get(hart).getRegister(num) instanceof ReadOnlyRegister) { + return true; + } + if (num >= 0xC80 && num <= 0xC82) { + return true; + } + if ((Globals.getSettings().getBackSteppingEnabled())) { + Globals.program.getBackStepper().addControlAndStatusRestore(num, + gInstance.get(hart).updateRegister(num, val)); + } else { + gInstance.get(hart).updateRegister(num, val); + } + return false; + } + /** * This method updates the register value * @@ -152,6 +204,10 @@ public static boolean orRegister(int num, long val) { return updateRegister(num, instance.getValue(num) | val); } + public static boolean orRegister(int num, long val, int hart) { + return updateRegister(num, gInstance.get(hart).getValue(num) | val, hart); + } + /** * ORs a register with a value * @@ -172,6 +228,10 @@ public static boolean clearRegister(int num, long val) { return updateRegister(num, instance.getValue(num) & ~val); } + public static boolean clearRegister(int num, long val, int hart) { + return updateRegister(num, instance.getValue(num) & ~val, hart); + } + /** * Clears bits from a register according to a value * @@ -190,7 +250,11 @@ public static void clearRegister(String name, long val) { **/ public static int getValue(int num) { - return (int)instance.getValue(num); + return (int) instance.getValue(num); + } + + public static int getValue(int num, int hart) { + return (int) gInstance.get(hart).getValue(num); } /** @@ -203,6 +267,11 @@ public static int getValue(int num) { public static long getValueLong(int num) { return instance.getValue(num); } + + public static long getValueLong(int num, int hart) { + return gInstance.get(hart).getValue(num); + } + /** * Returns the value of the register * @@ -235,6 +304,10 @@ public static Register[] getRegisters() { return instance.getRegisters(); } + public static Register[] getRegisters(int hart) { + return gInstance.get(hart).getRegisters(); + } + /** * ControlAndStatusRegisterFile implements a wide range of register numbers that don't math the position in the underlying array diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index 572ffa67..d9a2535e 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -81,8 +81,8 @@ public static void initProgramCounter(){ gProgramCounter.add(temp); } } - public static void initGRegisterBlock(){ - if(gInstance != null) + public static void initGRegisterBlock() { + if (gInstance != null) return; gInstance = new ArrayList<>(); for(int i = 0; i < Globals.getHarts(); i++){ @@ -105,7 +105,7 @@ public static void initGRegisterBlock(){ new Register("t3", 28, 0, i), new Register("t4", 29, 0, i), new Register("t5", 30, 0, i), new Register("t6", 31, 0, i) }); - gInstance.add(temp); + gInstance.add(temp); } } @@ -192,8 +192,8 @@ public static int getValue(int num) { } public static int getValue(int num, int hart) { return (int) gInstance.get(hart).getValue(num); - } + /** * Returns the value of the register. * diff --git a/src/rars/riscv/instructions/CSRRC.java b/src/rars/riscv/instructions/CSRRC.java index ceea2863..b45e250f 100644 --- a/src/rars/riscv/instructions/CSRRC.java +++ b/src/rars/riscv/instructions/CSRRC.java @@ -41,14 +41,29 @@ public CSRRC() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); try { - long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); - if (operands[2] != 0) { - if(ControlAndStatusRegisterFile.clearRegister(operands[1], RegisterFile.getValueLong(operands[2]))){ - throw new SimulationException(statement, "Attempt to write to read-only CSR", SimulationException.ILLEGAL_INSTRUCTION); + if (hart == -1) { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); + if (operands[2] != 0) { + if (ControlAndStatusRegisterFile.clearRegister(operands[1], + RegisterFile.getValueLong(operands[2]))) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } } + RegisterFile.updateRegister(operands[0], csr); + } else { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1], hart); + if (operands[2] != 0) { + if (ControlAndStatusRegisterFile.clearRegister(operands[1], + RegisterFile.getValueLong(operands[2], hart), hart)) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } + } + RegisterFile.updateRegister(operands[0], csr, hart); } - RegisterFile.updateRegister(operands[0], csr); } catch (NullPointerException e) { throw new SimulationException(statement, "Attempt to access unavailable CSR", SimulationException.ILLEGAL_INSTRUCTION); } diff --git a/src/rars/riscv/instructions/CSRRCI.java b/src/rars/riscv/instructions/CSRRCI.java index 13a97d38..b48d7fdf 100644 --- a/src/rars/riscv/instructions/CSRRCI.java +++ b/src/rars/riscv/instructions/CSRRCI.java @@ -41,14 +41,27 @@ public CSRRCI() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); try { - long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); - if (operands[2] != 0) { - if(ControlAndStatusRegisterFile.clearRegister(operands[1], operands[2])){ - throw new SimulationException(statement, "Attempt to write to read-only CSR", SimulationException.ILLEGAL_INSTRUCTION); + if (hart == -1) { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); + if (operands[2] != 0) { + if (ControlAndStatusRegisterFile.clearRegister(operands[1], operands[2])) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } } + RegisterFile.updateRegister(operands[0], csr); + } else { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1], hart); + if (operands[2] != 0) { + if (ControlAndStatusRegisterFile.clearRegister(operands[1], operands[2], hart)) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } + } + RegisterFile.updateRegister(operands[0], csr, hart); } - RegisterFile.updateRegister(operands[0], csr); } catch (NullPointerException e) { throw new SimulationException(statement, "Attempt to access unavailable CSR", SimulationException.ILLEGAL_INSTRUCTION); } diff --git a/src/rars/riscv/instructions/CSRRS.java b/src/rars/riscv/instructions/CSRRS.java index 80a4c8ff..fb689ff4 100644 --- a/src/rars/riscv/instructions/CSRRS.java +++ b/src/rars/riscv/instructions/CSRRS.java @@ -41,14 +41,27 @@ public CSRRS() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); try { - long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); - if (operands[2] != 0) { - if(ControlAndStatusRegisterFile.orRegister(operands[1], RegisterFile.getValueLong(operands[2]))) { - throw new SimulationException(statement, "Attempt to write to read-only CSR", SimulationException.ILLEGAL_INSTRUCTION); + if (hart == -1) { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); + if (operands[2] != 0) { + if (ControlAndStatusRegisterFile.orRegister(operands[1], RegisterFile.getValueLong(operands[2]))) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } } + RegisterFile.updateRegister(operands[0], csr); + } else { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1], hart); + if (operands[2] != 0) { + if (ControlAndStatusRegisterFile.orRegister(operands[1], RegisterFile.getValueLong(operands[2], hart), hart)) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } + } + RegisterFile.updateRegister(operands[0], csr, hart); } - RegisterFile.updateRegister(operands[0], csr); } catch (NullPointerException e) { throw new SimulationException(statement, "Attempt to access unavailable CSR", SimulationException.ILLEGAL_INSTRUCTION); } diff --git a/src/rars/riscv/instructions/CSRRSI.java b/src/rars/riscv/instructions/CSRRSI.java index b0e5e9f9..2e4d48a8 100644 --- a/src/rars/riscv/instructions/CSRRSI.java +++ b/src/rars/riscv/instructions/CSRRSI.java @@ -41,14 +41,26 @@ public CSRRSI() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); try { - long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); - if (operands[2] != 0){ - if(ControlAndStatusRegisterFile.orRegister(operands[1], operands[2])){ - throw new SimulationException(statement, "Attempt to write to read-only CSR", SimulationException.ILLEGAL_INSTRUCTION); + if (hart == -1) { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); + if (operands[2] != 0){ + if(ControlAndStatusRegisterFile.orRegister(operands[1], operands[2])){ + throw new SimulationException(statement, "Attempt to write to read-only CSR", SimulationException.ILLEGAL_INSTRUCTION); + } } + RegisterFile.updateRegister(operands[0], csr); + } else { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1], hart); + if (operands[2] != 0) { + if (ControlAndStatusRegisterFile.orRegister(operands[1], operands[2], hart)) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } + } + RegisterFile.updateRegister(operands[0], csr, hart); } - RegisterFile.updateRegister(operands[0], csr); } catch (NullPointerException e) { throw new SimulationException(statement, "Attempt to access unavailable CSR", SimulationException.ILLEGAL_INSTRUCTION); } diff --git a/src/rars/riscv/instructions/CSRRW.java b/src/rars/riscv/instructions/CSRRW.java index 7cb44d46..5293d616 100644 --- a/src/rars/riscv/instructions/CSRRW.java +++ b/src/rars/riscv/instructions/CSRRW.java @@ -41,12 +41,23 @@ public CSRRW() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); try { - long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); - if(ControlAndStatusRegisterFile.updateRegister(operands[1], RegisterFile.getValueLong(operands[2]))){ - throw new SimulationException(statement, "Attempt to write to read-only CSR", SimulationException.ILLEGAL_INSTRUCTION); + if (hart == -1) { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); + if (ControlAndStatusRegisterFile.updateRegister(operands[1], RegisterFile.getValueLong(operands[2]))) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } + RegisterFile.updateRegister(operands[0], csr); + } else { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1], hart); + if (ControlAndStatusRegisterFile.updateRegister(operands[1], RegisterFile.getValueLong(operands[2], hart), hart)) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } + RegisterFile.updateRegister(operands[0], csr, hart); } - RegisterFile.updateRegister(operands[0], csr); } catch (NullPointerException e) { throw new SimulationException(statement, "Attempt to access unavailable CSR", SimulationException.ILLEGAL_INSTRUCTION); } diff --git a/src/rars/riscv/instructions/CSRRWI.java b/src/rars/riscv/instructions/CSRRWI.java index 40efe473..cab428e7 100644 --- a/src/rars/riscv/instructions/CSRRWI.java +++ b/src/rars/riscv/instructions/CSRRWI.java @@ -41,12 +41,23 @@ public CSRRWI() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); try { - long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); - if(ControlAndStatusRegisterFile.updateRegister(operands[1], operands[2])){ - throw new SimulationException(statement, "Attempt to write to read-only CSR", SimulationException.ILLEGAL_INSTRUCTION); + if (hart == -1) { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1]); + if (ControlAndStatusRegisterFile.updateRegister(operands[1], operands[2])) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } + RegisterFile.updateRegister(operands[0], csr); + } else { + long csr = ControlAndStatusRegisterFile.getValueLong(operands[1], hart); + if (ControlAndStatusRegisterFile.updateRegister(operands[1], operands[2], hart)) { + throw new SimulationException(statement, "Attempt to write to read-only CSR", + SimulationException.ILLEGAL_INSTRUCTION); + } + RegisterFile.updateRegister(operands[0], csr, hart); } - RegisterFile.updateRegister(operands[0], csr); } catch (NullPointerException e) { throw new SimulationException(statement, "Attempt to access unavailable CSR", SimulationException.ILLEGAL_INSTRUCTION); } diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index dd7ac0e9..120f3a54 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -2,6 +2,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; +import rars.riscv.hardware.ControlAndStatusRegisterFile; import rars.riscv.hardware.RegisterFile; import rars.riscv.hardware.ReservationTable.bitWidth; import rars.venus.*; @@ -123,6 +124,7 @@ public void actionPerformed(ActionEvent e) { super.dialog.dispose(); RegisterFile.initGRegisterBlock(); RegisterFile.initProgramCounter(); + ControlAndStatusRegisterFile.changeHarts(1); action(); }); @@ -131,6 +133,7 @@ public void actionPerformed(ActionEvent e) { super.dialog.dispose(); RegisterFile.initGRegisterBlock(); RegisterFile.initProgramCounter(); + ControlAndStatusRegisterFile.changeHarts(-1); action(); }); displayOptions.add(Box.createHorizontalGlue()); diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index f5eaa121..bf2e5881 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -109,7 +109,7 @@ public GeneralVenusUI(String s) { registersTab = new RegistersWindow(s.charAt(s.length()-1) - '1'); fpTab = new FloatingPointWindow(); - csrTab = new ControlAndStatusWindow(); + csrTab = new ControlAndStatusWindow(s.charAt(s.length() - 1) - '1'); registersPane = new GeneralRegistersPane(mainUI, registersTab, fpTab, csrTab); registersPane.setPreferredSize(registersPanePreferredSize); diff --git a/src/rars/venus/registers/ControlAndStatusWindow.java b/src/rars/venus/registers/ControlAndStatusWindow.java index da453413..5f849c1d 100644 --- a/src/rars/venus/registers/ControlAndStatusWindow.java +++ b/src/rars/venus/registers/ControlAndStatusWindow.java @@ -7,6 +7,7 @@ import rars.venus.NumberDisplayBaseChooser; public class ControlAndStatusWindow extends RegisterBlockWindow { + private int hart; /* * The tips to show when hovering over the names of the registers * TODO: Maintain order if any new CSRs are added @@ -34,6 +35,12 @@ public class ControlAndStatusWindow extends RegisterBlockWindow { public ControlAndStatusWindow() { super(ControlAndStatusRegisterFile.getRegisters(), regToolTips, "Current 32 bit value"); + hart = -1; + } + + public ControlAndStatusWindow(int hart) { + super(ControlAndStatusRegisterFile.getRegisters(hart), regToolTips, "Current 32 bit value", hart); + this.hart = hart; } protected String formatRegister(Register value, int base) { From 01262f37bd3cc295b7da66d89da4fd95dc2da1e2 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Thu, 29 Jul 2021 14:26:26 -0600 Subject: [PATCH 64/84] update cycle, instret, time csr on secondary harts --- .../ControlAndStatusRegisterFile.java | 66 +++++++++++-------- src/rars/simulator/Simulator.java | 19 ++++-- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java index 8fa5b878..f69a9f85 100644 --- a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java +++ b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java @@ -83,39 +83,35 @@ public class ControlAndStatusRegisterFile { instance = new RegisterBlock('_', tmp); // prefix not used } - public static ArrayList gInstance; + public static ArrayList gInstance = new ArrayList<>(); public static void changeHarts(int sign) { - if (gInstance == null) { - gInstance = new ArrayList<>(); - } if (sign > 0) { - for (int i = 1; i <= Globals.getHarts(); i++) { - Register[] tmp = new Register[] { new MaskedRegister("ustatus", 0x000, 0, ~0x11), null, // fflags - null, // frm - new MaskedRegister("fcsr", 0x003, 0, ~0xFF), new Register("uie", 0x004, 0), - new Register("utvec", 0x005, 0), new Register("uscratch", 0x040, 0), - new Register("uepc", 0x041, 0), new Register("ucause", 0x042, 0), - new Register("utval", 0x043, 0), new Register("uip", 0x044, 0), - new ReadOnlyRegister("cycle", 0xC00, 0), new ReadOnlyRegister("time", 0xC01, 0), - new ReadOnlyRegister("instret", 0xC02, 0), null, // cycleh - null, // timeh - null, // instreth - null, // mhartid - }; - tmp[1] = new LinkedRegister("fflags", 0x001, tmp[3], 0x1F); - tmp[2] = new LinkedRegister("frm", 0x002, tmp[3], 0xE0); - tmp[14] = new LinkedRegister("cycleh", 0xC80, tmp[11], 0xFFFFFFFF_00000000L); - tmp[15] = new LinkedRegister("timeh", 0xC81, tmp[12], 0xFFFFFFFF_00000000L); - tmp[16] = new LinkedRegister("instreth", 0xC82, tmp[13], 0xFFFFFFFF_00000000L); - tmp[17] = new ReadOnlyRegister("mhartid", 0xF10, i); - RegisterBlock temp = new RegisterBlock('_', tmp); - gInstance.add(temp); - } + Register[] tmp = new Register[] { new MaskedRegister("ustatus", 0x000, 0, ~0x11), null, // fflags + null, // frm + new MaskedRegister("fcsr", 0x003, 0, ~0xFF), new Register("uie", 0x004, 0), + new Register("utvec", 0x005, 0), new Register("uscratch", 0x040, 0), + new Register("uepc", 0x041, 0), new Register("ucause", 0x042, 0), + new Register("utval", 0x043, 0), new Register("uip", 0x044, 0), + new ReadOnlyRegister("cycle", 0xC00, 0), new ReadOnlyRegister("time", 0xC01, 0), + new ReadOnlyRegister("instret", 0xC02, 0), null, // cycleh + null, // timeh + null, // instreth + null, // mhartid + }; + tmp[1] = new LinkedRegister("fflags", 0x001, tmp[3], 0x1F); + tmp[2] = new LinkedRegister("frm", 0x002, tmp[3], 0xE0); + tmp[14] = new LinkedRegister("cycleh", 0xC80, tmp[11], 0xFFFFFFFF_00000000L); + tmp[15] = new LinkedRegister("timeh", 0xC81, tmp[12], 0xFFFFFFFF_00000000L); + tmp[16] = new LinkedRegister("instreth", 0xC82, tmp[13], 0xFFFFFFFF_00000000L); + tmp[17] = new ReadOnlyRegister("mhartid", 0xF10, Globals.getHarts() - 1); + RegisterBlock temp = new RegisterBlock('_', tmp); + gInstance.add(temp); } if (sign < 0) { gInstance.remove(gInstance.size() - 1); } + System.out.println(gInstance.size()); } /** @@ -183,6 +179,15 @@ public static void updateRegisterBackdoor(int num, long val) { } } + public static void updateRegisterBackdoor(int num, long val, int hart) { + if ((Globals.getSettings().getBackSteppingEnabled())) { + Globals.program.getBackStepper().addControlAndStatusBackdoor(num, + gInstance.get(hart).getRegister(num).setValueBackdoor(val)); + } else { + gInstance.get(hart).getRegister(num).setValueBackdoor(val); + } + } + /** * This method updates the register value silently and bypasses read only * @@ -194,6 +199,11 @@ public static void updateRegisterBackdoor(String name, long val) { updateRegisterBackdoor(instance.getRegister(name).getNumber(), val); } + public static void updateRegisterBackdoor(String name, long val, int hart) { + System.out.printf("Getting secondary hart %d out of %d total secondary harts\n", hart, gInstance.size()); + updateRegisterBackdoor(gInstance.get(hart).getRegister(name).getNumber(), val, hart); + } + /** * ORs a register with a value * @@ -294,6 +304,10 @@ public static long getValueNoNotify(String name) { return instance.getRegister(name).getValueNoNotify(); } + public static long getValueNoNotify(String name, int hart) { + return gInstance.get(hart).getRegister(name).getValueNoNotify(); + } + /** * For returning the set of registers. * diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index 8b9b4e6e..fc075d7c 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -299,6 +299,7 @@ private boolean handleTrap(SimulationException se, int pc) { assert se.cause() >= 0 : "Interrupts cannot be handled by the trap handler"; // set the relevant CSRs + // TODO ControlAndStatusRegisterFile.updateRegister("ucause", se.cause()); ControlAndStatusRegisterFile.updateRegister("uepc", pc); ControlAndStatusRegisterFile.updateRegister("utval", se.value()); @@ -340,6 +341,7 @@ private boolean handleInterrupt(int value, int cause, int pc) { assert ((ControlAndStatusRegisterFile.getValue("ustatus") & 0x1) != 0 && (ControlAndStatusRegisterFile.getValue("uie") & (1 << code)) != 0) : "The interrupt handler must be enabled"; // set the relevant CSRs + // TODO ControlAndStatusRegisterFile.updateRegister("ucause", cause); ControlAndStatusRegisterFile.updateRegister("uepc", pc); ControlAndStatusRegisterFile.updateRegister("utval", value); @@ -487,6 +489,7 @@ public void run() { uip |= (pendingExternal ? ControlAndStatusRegisterFile.EXTERNAL_INTERRUPT : 0) | (pendingTimer ? ControlAndStatusRegisterFile.TIMER_INTERRUPT : 0); } if (uip != ControlAndStatusRegisterFile.getValueNoNotify("uip")) { + // TODO ControlAndStatusRegisterFile.updateRegister("uip", uip); } @@ -530,6 +533,7 @@ public void run() { } if (!InterruptController.registerSynchronousTrap(tmp, pc)) { this.pe = tmp; + // TODO ControlAndStatusRegisterFile.updateRegister("uepc", pc); stopExecution(true, Reason.EXCEPTION); return; @@ -594,10 +598,17 @@ public void run() { // Update cycle(h) and instret(h) long cycle = ControlAndStatusRegisterFile.getValueNoNotify("cycle"), instret = ControlAndStatusRegisterFile.getValueNoNotify("instret"), - time = System.currentTimeMillis();; - ControlAndStatusRegisterFile.updateRegisterBackdoor("cycle",cycle+1); - ControlAndStatusRegisterFile.updateRegisterBackdoor("instret",instret+1); - ControlAndStatusRegisterFile.updateRegisterBackdoor("time",time); + time = System.currentTimeMillis(); + ControlAndStatusRegisterFile.updateRegisterBackdoor("cycle", cycle + 1); + ControlAndStatusRegisterFile.updateRegisterBackdoor("instret", instret + 1); + ControlAndStatusRegisterFile.updateRegisterBackdoor("time", time); + for (int i = 0; i < Globals.getHarts() - 1; i++) { + cycle = ControlAndStatusRegisterFile.getValueNoNotify("cycle", i); + instret = ControlAndStatusRegisterFile.getValueNoNotify("instret", i); + ControlAndStatusRegisterFile.updateRegisterBackdoor("cycle", cycle + 1, i); + ControlAndStatusRegisterFile.updateRegisterBackdoor("instret", instret + 1, i); + ControlAndStatusRegisterFile.updateRegisterBackdoor("time", time, i); + } // Return if we've reached a breakpoint. if (ebreak || (breakPoints != null) && From 91a945a87fd42d59cfd1525a06700c35ce7d3cf1 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Tue, 3 Aug 2021 06:15:25 -0600 Subject: [PATCH 65/84] fix component not found error --- src/rars/venus/run/RunStepAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rars/venus/run/RunStepAction.java b/src/rars/venus/run/RunStepAction.java index f1c94d09..7e67dd0b 100644 --- a/src/rars/venus/run/RunStepAction.java +++ b/src/rars/venus/run/RunStepAction.java @@ -170,7 +170,7 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p executePane.getTextSegmentWindow().unhighlightAllSteps(); executePane.getTextSegmentWindow().highlightStepAtAddress(RegisterFile.getProgramCounter() - 4); for(int i = 0; i < hartWindows.size(); i++){ - hartWindows.get(i).getRegistersPane().setSelectedComponent(executePane.getControlAndStatusWindow()); + hartWindows.get(i).getRegistersPane().setSelectedComponent(gExecutePanes.get(i).getControlAndStatusWindow()); gExecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); gExecutePanes.get(i).getTextSegmentWindow().unhighlightAllSteps(); gExecutePanes.get(i).getTextSegmentWindow().highlightStepAtAddress(RegisterFile.getProgramCounter() - 4); From cc5db18d95f9208544592914a23de0a0f74b8933 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 5 Aug 2021 11:30:18 -0600 Subject: [PATCH 66/84] enable multithreaded branching --- src/rars/riscv/InstructionSet.java | 5 ++++- src/rars/riscv/instructions/AUIPC.java | 5 +++-- src/rars/riscv/instructions/BEQ.java | 7 ++++--- src/rars/riscv/instructions/BGE.java | 7 ++++--- src/rars/riscv/instructions/BGEU.java | 8 ++++++-- src/rars/riscv/instructions/BLT.java | 8 ++++++-- src/rars/riscv/instructions/BLTU.java | 8 ++++++-- src/rars/riscv/instructions/BNE.java | 8 ++++++-- src/rars/riscv/instructions/Branch.java | 8 ++++++-- 9 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/rars/riscv/InstructionSet.java b/src/rars/riscv/InstructionSet.java index 33cf37f6..a2fcf31f 100644 --- a/src/rars/riscv/InstructionSet.java +++ b/src/rars/riscv/InstructionSet.java @@ -310,6 +310,10 @@ public static void processBranch(int displacement) { // Decrement needed because PC has already been incremented RegisterFile.setProgramCounter(RegisterFile.getProgramCounter() + displacement - Instruction.INSTRUCTION_LENGTH); } + public static void processBranch(int displacement, int hart) { + // Decrement needed because PC has already been incremented + RegisterFile.setProgramCounter(RegisterFile.getProgramCounter(hart) + displacement - Instruction.INSTRUCTION_LENGTH, hart); + } /* * Method to process a jump. DO NOT USE WITH BRANCH INSTRUCTIONS! @@ -372,4 +376,3 @@ public BasicInstruction find(int instr) { } } } - diff --git a/src/rars/riscv/instructions/AUIPC.java b/src/rars/riscv/instructions/AUIPC.java index 2f9746bc..b8dd9a18 100644 --- a/src/rars/riscv/instructions/AUIPC.java +++ b/src/rars/riscv/instructions/AUIPC.java @@ -40,9 +40,10 @@ public AUIPC() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - if(statement.getCurrentHart() == -1) + int hart = statement.getCurrentHart(); + if (hart == -1) RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter() - INSTRUCTION_LENGTH + (operands[1] << 12)); else - RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter() - INSTRUCTION_LENGTH + (operands[1] << 12), statement.getCurrentHart()); + RegisterFile.updateRegister(operands[0], RegisterFile.getProgramCounter(hart) - INSTRUCTION_LENGTH + (operands[1] << 12), hart); } } diff --git a/src/rars/riscv/instructions/BEQ.java b/src/rars/riscv/instructions/BEQ.java index 936104ce..95a49d65 100644 --- a/src/rars/riscv/instructions/BEQ.java +++ b/src/rars/riscv/instructions/BEQ.java @@ -37,9 +37,10 @@ public BEQ() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - if(statement.getCurrentHart() == -1) + int hart = statement.getCurrentHart(); + if (hart == -1) return RegisterFile.getValueLong(operands[0]) == RegisterFile.getValueLong(operands[1]); else - return RegisterFile.getValueLong(operands[0], statement.getCurrentHart()) == RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); + return RegisterFile.getValueLong(operands[0], hart) == RegisterFile.getValueLong(operands[1], hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/BGE.java b/src/rars/riscv/instructions/BGE.java index b4ec30fb..d70aca75 100644 --- a/src/rars/riscv/instructions/BGE.java +++ b/src/rars/riscv/instructions/BGE.java @@ -37,9 +37,10 @@ public BGE() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - if(statement.getCurrentHart() == -1) + int hart = statement.getCurrentHart(); + if (hart == -1) return RegisterFile.getValueLong(operands[0]) >= RegisterFile.getValueLong(operands[1]); else - return RegisterFile.getValueLong(operands[0], statement.getCurrentHart()) >= RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); + return RegisterFile.getValueLong(operands[0], hart) >= RegisterFile.getValueLong(operands[1], hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/BGEU.java b/src/rars/riscv/instructions/BGEU.java index 4afca9a2..e97205ed 100644 --- a/src/rars/riscv/instructions/BGEU.java +++ b/src/rars/riscv/instructions/BGEU.java @@ -37,6 +37,10 @@ public BGEU() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - return Long.compareUnsigned(RegisterFile.getValueLong(operands[0]), RegisterFile.getValueLong(operands[1])) >= 0; + int hart = statement.getCurrentHart(); + if (hart == -1) + return Long.compareUnsigned(RegisterFile.getValueLong(operands[0]), RegisterFile.getValueLong(operands[1])) >= 0; + else + return Long.compareUnsigned(RegisterFile.getValueLong(operands[0], hart), RegisterFile.getValueLong(operands[1], hart)) >= 0; } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/BLT.java b/src/rars/riscv/instructions/BLT.java index df552406..f1e772d7 100644 --- a/src/rars/riscv/instructions/BLT.java +++ b/src/rars/riscv/instructions/BLT.java @@ -37,6 +37,10 @@ public BLT() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - return RegisterFile.getValueLong(operands[0]) < RegisterFile.getValueLong(operands[1]); + int hart = statement.getCurrentHart(); + if (hart == -1) + return RegisterFile.getValueLong(operands[0]) < RegisterFile.getValueLong(operands[1]); + else + return RegisterFile.getValueLong(operands[0], hart) < RegisterFile.getValueLong(operands[1], hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/BLTU.java b/src/rars/riscv/instructions/BLTU.java index f7545533..3e5952d7 100644 --- a/src/rars/riscv/instructions/BLTU.java +++ b/src/rars/riscv/instructions/BLTU.java @@ -37,6 +37,10 @@ public BLTU() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - return Long.compareUnsigned(RegisterFile.getValueLong(operands[0]), RegisterFile.getValueLong(operands[1])) < 0; + int hart = statement.getCurrentHart(); + if (hart == -1) + return Long.compareUnsigned(RegisterFile.getValueLong(operands[0]), RegisterFile.getValueLong(operands[1])) < 0; + else + return Long.compareUnsigned(RegisterFile.getValueLong(operands[0], hart), RegisterFile.getValueLong(operands[1], hart)) < 0; } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/BNE.java b/src/rars/riscv/instructions/BNE.java index 44c56ba8..1b2d8bc4 100644 --- a/src/rars/riscv/instructions/BNE.java +++ b/src/rars/riscv/instructions/BNE.java @@ -37,6 +37,10 @@ public BNE() { public boolean willBranch(ProgramStatement statement) { int[] operands = statement.getOperands(); - return RegisterFile.getValueLong(operands[0]) != RegisterFile.getValueLong(operands[1]); + int hart = statement.getCurrentHart(); + if (hart == -1) + return RegisterFile.getValueLong(operands[0]) != RegisterFile.getValueLong(operands[1]); + else + return RegisterFile.getValueLong(operands[0], hart) != RegisterFile.getValueLong(operands[1], hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/Branch.java b/src/rars/riscv/instructions/Branch.java index 2700e8e5..092684a8 100644 --- a/src/rars/riscv/instructions/Branch.java +++ b/src/rars/riscv/instructions/Branch.java @@ -48,7 +48,11 @@ public Branch(String usage, String description, String funct) { public void simulate(ProgramStatement statement) { if (willBranch(statement)) { - InstructionSet.processBranch(statement.getOperands()[2]); + if (statement.getCurrentHart() == -1) { + InstructionSet.processBranch(statement.getOperands()[2]); + } else { + InstructionSet.processBranch(statement.getOperands()[2], statement.getCurrentHart()); + } } } @@ -57,4 +61,4 @@ public void simulate(ProgramStatement statement) { * @return true if the Branch instruction will branch */ public abstract boolean willBranch(ProgramStatement statement); -} \ No newline at end of file +} From 44ed41cb3c269485632077fafca26b19a2f8a122 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 5 Aug 2021 11:31:28 -0600 Subject: [PATCH 67/84] reset pc on reassemble for secondary harts --- src/rars/riscv/hardware/RegisterFile.java | 24 +++++++++++------------ src/rars/simulator/Simulator.java | 7 +------ src/rars/tools/ReservationTablesTool.java | 1 - 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index d9a2535e..8d7198a0 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -69,18 +69,16 @@ public class RegisterFile { public static ArrayList gInstance; private static Register programCounter = new Register("pc", -1, Memory.textBaseAddress); - private static ArrayList gProgramCounter; - - public static void initProgramCounter(){ - if(gProgramCounter != null){ - return; - } - gProgramCounter = new ArrayList<>(); - for(int i = 1; i < Globals.getHarts(); i++){ + private static ArrayList gProgramCounter = new ArrayList<>(); + + public static void initProgramCounter() { + gProgramCounter.clear(); + for (int i = 1; i < Globals.getHarts(); i++) { Register temp = new Register("pc", -1, Memory.textBaseAddress); gProgramCounter.add(temp); } } + public static void initGRegisterBlock() { if (gInstance != null) return; @@ -111,7 +109,6 @@ public static void initGRegisterBlock() { } public static void changeHarts(int sign){ if(gInstance == null){ - initProgramCounter(); initGRegisterBlock(); } if(sign > 0){ @@ -257,10 +254,13 @@ public static Register getRegister(String name) { **/ public static void initializeProgramCounter(int value) { - programCounter.setValue((long)value); + programCounter.setValue((long) value); + for (int i = 0; i < gProgramCounter.size(); i++) { + initializeProgramCounter(value, i); + } } public static void initializeProgramCounter(int value, int hart){ - gProgramCounter.get(hart).setValue(value); + gProgramCounter.get(hart).setValue((long) value); } /** * Will initialize the Program Counter to either the default reset value, or the address @@ -326,8 +326,6 @@ public static Register getProgramCounterRegister() { return programCounter; } public static Register getProgramCounterRegister(int hart) { - if(gProgramCounter == null) - initProgramCounter(); return gProgramCounter.get(hart); } /** diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index fc075d7c..35b3b9d6 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -425,12 +425,7 @@ public void run() { // the backstep button is not enabled until a "real" instruction is executed. // This is noticeable in stepped mode. // ********************************************************************* - if(hart == -1){ - RegisterFile.initializeProgramCounter(pc); - } - else{ - RegisterFile.initializeProgramCounter(pc, hart); - } + RegisterFile.initializeProgramCounter(pc); ProgramStatement statement = null; int steps = 0; boolean ebreak = false, waiting = false; diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 120f3a54..9b7c6e04 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -126,7 +126,6 @@ public void actionPerformed(ActionEvent e) { RegisterFile.initProgramCounter(); ControlAndStatusRegisterFile.changeHarts(1); action(); - }); btnMinus.addActionListener(l -> { Globals.setHarts(-1); From 4da050685c8621a499df9784c4e63bd03ecd1e33 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 6 Aug 2021 09:27:09 -0600 Subject: [PATCH 68/84] add per hart execution setting --- src/Settings.properties | 2 +- src/rars/Settings.java | 8 ++++++-- src/rars/venus/VenusUI.java | 12 +++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Settings.properties b/src/Settings.properties index 8c02d809..78d1e9e5 100644 --- a/src/Settings.properties +++ b/src/Settings.properties @@ -30,4 +30,4 @@ DataSegmentHighlightBackground = 0x0099ccff DataSegmentHighlightForeground = 0 RegisterHighlightBackground = 0x0099cc55 RegisterHighlightForeground = 0 - +PerHartExecution = false diff --git a/src/rars/Settings.java b/src/rars/Settings.java index 70f86ef6..42aadc0d 100644 --- a/src/rars/Settings.java +++ b/src/rars/Settings.java @@ -153,7 +153,11 @@ public enum Bool { /** * Flag to determine whether a program uses rv64i instead of rv32i */ - RV64_ENABLED("rv64Enabled", false);; + RV64_ENABLED("rv64Enabled", false), + /** + * Flag to determine if the step buttons should run for all harts or just indivdual hart + */ + PER_HART_EXECUTION("PerHartExecution", false);; // TODO: add option for turning off user trap handling and interrupts private String name; @@ -1320,4 +1324,4 @@ private int[] getTextSegmentColumnOrder(String stringOfColumnIndexes) { return list; } -} \ No newline at end of file +} diff --git a/src/rars/venus/VenusUI.java b/src/rars/venus/VenusUI.java index 9791d63d..0649d2ae 100644 --- a/src/rars/venus/VenusUI.java +++ b/src/rars/venus/VenusUI.java @@ -85,7 +85,7 @@ public class VenusUI extends JFrame { private JMenuItem runGo, runStep, runBackstep, runReset, runAssemble, runStop, runPause, runClearBreakpoints, runToggleBreakpoints; private JCheckBoxMenuItem settingsLabel, settingsPopupInput, settingsValueDisplayBase, settingsAddressDisplayBase, settingsExtended, settingsAssembleOnOpen, settingsAssembleAll, settingsAssembleOpen, settingsWarningsAreErrors, - settingsStartAtMain, settingsProgramArguments, settingsSelfModifyingCode,settingsRV64; + settingsStartAtMain, settingsProgramArguments, settingsSelfModifyingCode, settingsRV64, settingsPerHartExecution; private JMenuItem settingsExceptionHandler, settingsEditor, settingsHighlighting, settingsMemoryConfiguration; private JMenuItem helpHelp, helpAbout; @@ -109,8 +109,8 @@ public class VenusUI extends JFrame { private Action settingsLabelAction, settingsPopupInputAction, settingsValueDisplayBaseAction, settingsAddressDisplayBaseAction, settingsExtendedAction, settingsAssembleOnOpenAction, settingsAssembleOpenAction, settingsAssembleAllAction, settingsWarningsAreErrorsAction, settingsStartAtMainAction, settingsProgramArgumentsAction, - settingsExceptionHandlerAction, settingsEditorAction, - settingsHighlightingAction, settingsMemoryConfigurationAction, settingsSelfModifyingCodeAction,settingsRV64Action; + settingsExceptionHandlerAction, settingsEditorAction, settingsHighlightingAction,settingsMemoryConfigurationAction, + settingsSelfModifyingCodeAction, settingsRV64Action, settingsPerHartExecutionAction; private Action helpHelpAction, helpAboutAction; protected static ArrayList observers; @@ -452,6 +452,9 @@ public void handler(boolean selected) { settingsSelfModifyingCodeAction = new SettingsAction("Self-modifying code", "If set, the program can write and branch to both text and data segments.", Settings.Bool.SELF_MODIFYING_CODE_ENABLED); + settingsPerHartExecutionAction = new SettingsAction("Each run steps button runs only assigned hart", + "If set, the run step, single step, and backward buttons will only affect the hart corelated to the window", + Settings.Bool.PER_HART_EXECUTION); // TODO: review this settingsRV64Action = new SettingsAction("64 bit", @@ -618,6 +621,8 @@ private JMenuBar setUpMenuBar() { settingsSelfModifyingCode.setSelected(Globals.getSettings().getBooleanSetting(Settings.Bool.SELF_MODIFYING_CODE_ENABLED)); settingsRV64 = new JCheckBoxMenuItem(settingsRV64Action); settingsRV64.setSelected(Globals.getSettings().getBooleanSetting(Settings.Bool.RV64_ENABLED)); + settingsPerHartExecution = new JCheckBoxMenuItem(settingsPerHartExecutionAction); + settingsPerHartExecution.setSelected(Globals.getSettings().getBooleanSetting(Settings.Bool.PER_HART_EXECUTION)); settingsAssembleOnOpen = new JCheckBoxMenuItem(settingsAssembleOnOpenAction); settingsAssembleOnOpen.setSelected(Globals.getSettings().getBooleanSetting(Settings.Bool.ASSEMBLE_ON_OPEN)); settingsAssembleAll = new JCheckBoxMenuItem(settingsAssembleAllAction); @@ -650,6 +655,7 @@ private JMenuBar setUpMenuBar() { settings.add(settingsExtended); settings.add(settingsSelfModifyingCode); settings.add(settingsRV64); + settings.add(settingsPerHartExecution); settings.addSeparator(); settings.add(settingsEditor); settings.add(settingsHighlighting); From aeb5dc8ddb1dd978644e244c03e8ea078475557b Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Thu, 12 Aug 2021 15:15:22 -0400 Subject: [PATCH 69/84] extend traps and interuptions to multithread --- src/rars/simulator/Simulator.java | 168 +++++++++++++++++++----------- 1 file changed, 109 insertions(+), 59 deletions(-) diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index 35b3b9d6..56b58363 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -150,9 +150,10 @@ public void startSimulation(int pc, int maxSteps, int[] breakPoints) { simulatorThread = new SimThread(pc, maxSteps, breakPoints); new Thread(simulatorThread, "RISCV").start(); } + public void startSimulation(int pc, int maxSteps, int[] breakPoints, int hart) { gSimulatorThread.add(hart, new SimThread(pc, maxSteps, breakPoints, hart)); - String s = "Hart " + hart; + String s = String.format("Hart %d", hart); new Thread(gSimulatorThread.get(hart), s).start(); } @@ -284,10 +285,15 @@ private void stopExecution(boolean done, Reason reason) { this.constructReturnReason = reason; SystemIO.flush(true); if (done) SystemIO.resetFiles(); // close any files opened in the process of simulating - if(hart == -1) + double runSpeed = (Globals.getGui() != null || Globals.runSpeedPanelExists) + ? RunSpeedPanel.getInstance().getRunSpeed() + : RunSpeedPanel.UNLIMITED_SPEED; + if (hart == -1) Simulator.getInstance().notifyObserversOfExecution(new SimulatorNotice(SimulatorNotice.SIMULATOR_STOP, - maxSteps, (Globals.getGui() != null || Globals.runSpeedPanelExists)?RunSpeedPanel.getInstance().getRunSpeed():RunSpeedPanel.UNLIMITED_SPEED, - pc, reason, pe, done)); + maxSteps, runSpeed, pc, reason, pe, done)); + else + Simulator.getInstance(hart).notifyObserversOfExecution(new SimulatorNotice(SimulatorNotice.SIMULATOR_STOP, + maxSteps, runSpeed, pc, reason, pe, done)); } private synchronized void interrupt() { @@ -299,31 +305,51 @@ private boolean handleTrap(SimulationException se, int pc) { assert se.cause() >= 0 : "Interrupts cannot be handled by the trap handler"; // set the relevant CSRs - // TODO - ControlAndStatusRegisterFile.updateRegister("ucause", se.cause()); - ControlAndStatusRegisterFile.updateRegister("uepc", pc); - ControlAndStatusRegisterFile.updateRegister("utval", se.value()); + if (hart == -1) { + ControlAndStatusRegisterFile.updateRegister("ucause", se.cause()); + ControlAndStatusRegisterFile.updateRegister("uepc", pc); + ControlAndStatusRegisterFile.updateRegister("utval", se.value()); + } else { + ControlAndStatusRegisterFile.updateRegister("ucause", se.cause(), hart); + ControlAndStatusRegisterFile.updateRegister("uepc", pc, hart); + ControlAndStatusRegisterFile.updateRegister("utval", se.value(), hart); + } // Get the interrupt handler if it exists - int utvec = ControlAndStatusRegisterFile.getValue("utvec"); + int utvec = (hart == -1) + ? ControlAndStatusRegisterFile.getValue("utvec") + : ControlAndStatusRegisterFile.getValue("utvec", hart); // Mode can be ignored because we are only handling traps int base = utvec & 0xFFFFFFFC; ProgramStatement exceptionHandler = null; - if ((ControlAndStatusRegisterFile.getValue("ustatus") & 0x1) != 0) { // test user-interrupt enable (UIE) - try { - exceptionHandler = Globals.memory.getStatement(base); - } catch (AddressErrorException aee) { - // Handled below + try { + if (hart == -1) { + if ((ControlAndStatusRegisterFile.getValue("ustatus") & 0x1) != 0) { // test user-interrupt enable (UIE) + exceptionHandler = Globals.memory.getStatement(base); + } + } else { + if ((ControlAndStatusRegisterFile.getValue("ustatus", hart) & 0x1) != 0) { // test user-interrupt enable (UIE) + exceptionHandler = Globals.memory.getStatement(base); + } } + } catch (AddressErrorException aee) { + // Handled below } if (exceptionHandler != null) { - ControlAndStatusRegisterFile.orRegister("ustatus", 0x10); // Set UPIE - ControlAndStatusRegisterFile.clearRegister("ustatus", 0x1); // Clear UIE - RegisterFile.setProgramCounter(base); - return true; + if (hart == -1) { + ControlAndStatusRegisterFile.orRegister("ustatus", 0x10); // Set UPIE + ControlAndStatusRegisterFile.clearRegister("ustatus", 0x1); // Clear UIE + RegisterFile.setProgramCounter(base); + return true; + } else { + ControlAndStatusRegisterFile.orRegister("ustatus", 0x10, hart); // Set UPIE + ControlAndStatusRegisterFile.clearRegister("ustatus", 0x1, hart); // Clear UIE + RegisterFile.setProgramCounter(base, hart); + return true; + } } else { // If we don't have an error handler or exceptions are disabled terminate the process this.pe = se; @@ -338,16 +364,30 @@ private boolean handleInterrupt(int value, int cause, int pc) { int code = cause & 0x7FFFFFFF; // Don't handle cases where that interrupt isn't enabled - assert ((ControlAndStatusRegisterFile.getValue("ustatus") & 0x1) != 0 && (ControlAndStatusRegisterFile.getValue("uie") & (1 << code)) != 0) : "The interrupt handler must be enabled"; + if (hart == -1) + assert ((ControlAndStatusRegisterFile.getValue("ustatus") & 0x1) != 0 + && (ControlAndStatusRegisterFile.getValue("uie") & (1 << code)) != 0) + : "The interrupt handler must be enabled"; + else + assert ((ControlAndStatusRegisterFile.getValue("ustatus", hart) & 0x1) != 0 + && (ControlAndStatusRegisterFile.getValue("uie", hart) & (1 << code)) != 0) + : "The interrupt handler must be enabled"; // set the relevant CSRs - // TODO - ControlAndStatusRegisterFile.updateRegister("ucause", cause); - ControlAndStatusRegisterFile.updateRegister("uepc", pc); - ControlAndStatusRegisterFile.updateRegister("utval", value); + if (hart == -1) { + ControlAndStatusRegisterFile.updateRegister("ucause", cause); + ControlAndStatusRegisterFile.updateRegister("uepc", pc); + ControlAndStatusRegisterFile.updateRegister("utval", value); + } else { + ControlAndStatusRegisterFile.updateRegister("ucause", cause, hart); + ControlAndStatusRegisterFile.updateRegister("uepc", pc, hart); + ControlAndStatusRegisterFile.updateRegister("utval", value, hart); + } // Get the interrupt handler if it exists - int utvec = ControlAndStatusRegisterFile.getValue("utvec"); + int utvec = (hart == -1) + ? ControlAndStatusRegisterFile.getValue("utvec") + : ControlAndStatusRegisterFile.getValue("utvec", hart); // Handle vectored mode int base = utvec & 0xFFFFFFFC, mode = utvec & 0x3; @@ -362,10 +402,19 @@ private boolean handleInterrupt(int value, int cause, int pc) { // handled below } if (exceptionHandler != null) { - ControlAndStatusRegisterFile.orRegister("ustatus", 0x10); // Set UPIE - ControlAndStatusRegisterFile.clearRegister("ustatus", ControlAndStatusRegisterFile.INTERRUPT_ENABLE); - RegisterFile.setProgramCounter(base); - return true; + if (hart == -1) { + ControlAndStatusRegisterFile.orRegister("ustatus", 0x10); // Set UPIE + ControlAndStatusRegisterFile.clearRegister("ustatus", + ControlAndStatusRegisterFile.INTERRUPT_ENABLE); + RegisterFile.setProgramCounter(base); + return true; + } else { + ControlAndStatusRegisterFile.orRegister("ustatus", 0x10, hart); // Set UPIE + ControlAndStatusRegisterFile.clearRegister("ustatus", ControlAndStatusRegisterFile.INTERRUPT_ENABLE, + hart); + RegisterFile.setProgramCounter(base, hart); + return true; + } } else { // If we don't have an error handler or exceptions are disabled terminate the process this.pe = new SimulationException("Interrupt handler was not supplied, but interrupt enable was high"); @@ -441,15 +490,21 @@ public void run() { Globals.memoryAndRegistersLock.lock(); try { // Handle pending interupts and traps first - long uip = ControlAndStatusRegisterFile.getValueNoNotify("uip"), uie = ControlAndStatusRegisterFile.getValueNoNotify("uie"); - boolean IE = (ControlAndStatusRegisterFile.getValueNoNotify("ustatus") & ControlAndStatusRegisterFile.INTERRUPT_ENABLE) != 0; + long uip = (hart == -1) + ? ControlAndStatusRegisterFile.getValueNoNotify("uip") + : ControlAndStatusRegisterFile.getValueNoNotify("uip", hart); + long uie = (hart == -1) + ? ControlAndStatusRegisterFile.getValueNoNotify("uie") + : ControlAndStatusRegisterFile.getValueNoNotify("uie", hart); + boolean IE = (hart == -1) + ? (ControlAndStatusRegisterFile.getValueNoNotify("ustatus") + & ControlAndStatusRegisterFile.INTERRUPT_ENABLE) != 0 + : (ControlAndStatusRegisterFile.getValueNoNotify("ustatus", hart) + & ControlAndStatusRegisterFile.INTERRUPT_ENABLE) != 0; // make sure no interrupts sneak in while we are processing them - if(hart == -1){ - pc = RegisterFile.getProgramCounter(); - } - else{ - pc = RegisterFile.getProgramCounter(hart); - } + pc = (hart == -1) + ? RegisterFile.getProgramCounter() + : RegisterFile.getProgramCounter(hart); synchronized (InterruptController.lock) { boolean pendingExternal = InterruptController.externalPending(), pendingTimer = InterruptController.timerPending(), @@ -483,9 +538,10 @@ public void run() { } uip |= (pendingExternal ? ControlAndStatusRegisterFile.EXTERNAL_INTERRUPT : 0) | (pendingTimer ? ControlAndStatusRegisterFile.TIMER_INTERRUPT : 0); } - if (uip != ControlAndStatusRegisterFile.getValueNoNotify("uip")) { - // TODO + if (hart == -1 && uip != ControlAndStatusRegisterFile.getValueNoNotify("uip")) { ControlAndStatusRegisterFile.updateRegister("uip", uip); + } else if (hart >= 0 && uip != ControlAndStatusRegisterFile.getValueNoNotify("uip", hart)) { + ControlAndStatusRegisterFile.updateRegister("uip", uip, hart); } // always handle interrupts and traps before quiting @@ -498,38 +554,32 @@ public void run() { } } - if(hart == -1){ + if (hart == -1) { pc = RegisterFile.getProgramCounter(); RegisterFile.incrementPC(); - } - else{ + } else { pc = RegisterFile.getProgramCounter(hart); RegisterFile.incrementPC(hart); } // Get instuction try { - if(hart == -1){ - statement = Globals.memory.getStatement(pc); - if(statement != null) - statement.setCurrentHart(-1); - } - else{ - statement = Globals.memory.getStatementNoNotify(pc); - if(statement != null) - statement.setCurrentHart(hart); - } + statement = (hart == -1) + ? Globals.memory.getStatement(pc) + : Globals.memory.getStatementNoNotify(pc); + if (statement != null) + statement.setCurrentHart(hart); } catch (AddressErrorException e) { - SimulationException tmp; - if (e.getType() == SimulationException.LOAD_ACCESS_FAULT) { - tmp = new SimulationException("Instruction load access error", SimulationException.INSTRUCTION_ACCESS_FAULT); - } else { - tmp = new SimulationException("Instruction load alignment error", SimulationException.INSTRUCTION_ADDR_MISALIGNED); - } + SimulationException tmp = (e.getType() == SimulationException.LOAD_ACCESS_FAULT) + ? new SimulationException("Instruction load access error", SimulationException.INSTRUCTION_ACCESS_FAULT) + : new SimulationException("Instruction load alignment error", SimulationException.INSTRUCTION_ADDR_MISALIGNED); if (!InterruptController.registerSynchronousTrap(tmp, pc)) { this.pe = tmp; - // TODO - ControlAndStatusRegisterFile.updateRegister("uepc", pc); + if (hart == -1) { + ControlAndStatusRegisterFile.updateRegister("uepc", pc); + } else { + ControlAndStatusRegisterFile.updateRegister("uepc", pc, hart); + } stopExecution(true, Reason.EXCEPTION); return; } else { From 3b535d6f38c8ee9f3e896af4ebe7e4ffafc24c12 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 13 Aug 2021 11:22:55 -0400 Subject: [PATCH 70/84] extend all but float instructions to multithread --- .../ControlAndStatusRegisterFile.java | 20 ++++++++++++++-- src/rars/riscv/hardware/RegisterFile.java | 5 +++- .../instructions/AtomicMemoryOperation.java | 12 +++++----- src/rars/riscv/instructions/DIV.java | 2 -- src/rars/riscv/instructions/DIVU.java | 4 +--- src/rars/riscv/instructions/DIVUW.java | 3 +-- src/rars/riscv/instructions/ECALL.java | 8 +++++-- .../instructions/ImmediateInstruction.java | 24 +++++++++---------- src/rars/riscv/instructions/JAL.java | 11 +++++---- src/rars/riscv/instructions/JALR.java | 18 ++++++++++---- src/rars/riscv/instructions/LRD.java | 10 +++++--- src/rars/riscv/instructions/LRW.java | 7 +++--- src/rars/riscv/instructions/LUI.java | 6 ++++- src/rars/riscv/instructions/Load.java | 13 ++++++---- src/rars/riscv/instructions/REM.java | 2 -- src/rars/riscv/instructions/REMU.java | 2 -- src/rars/riscv/instructions/REMUW.java | 4 ++-- src/rars/riscv/instructions/REMW.java | 4 ++-- src/rars/riscv/instructions/SW.java | 4 ++-- src/rars/riscv/instructions/Store.java | 16 +++++++++---- src/rars/riscv/instructions/URET.java | 24 ++++++++++++++----- 21 files changed, 126 insertions(+), 73 deletions(-) diff --git a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java index f69a9f85..bd1c150c 100644 --- a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java +++ b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java @@ -164,6 +164,10 @@ public static void updateRegister(String name, long val) { updateRegister(instance.getRegister(name).getNumber(), val); } + public static void updateRegister(String name, long val, int hart) { + updateRegister(gInstance.get(hart).getRegister(name).getNumber(), val, hart); + } + /** * This method updates the register value silently and bypasses read only * @@ -228,6 +232,10 @@ public static void orRegister(String name, long val) { updateRegister(name, instance.getValue(name) | val); } + public static void orRegister(String name, long val, int hart) { + updateRegister(name, gInstance.get(hart).getValue(name) | val, hart); + } + /** * Clears bits from a register according to a value * @@ -239,7 +247,7 @@ public static boolean clearRegister(int num, long val) { } public static boolean clearRegister(int num, long val, int hart) { - return updateRegister(num, instance.getValue(num) & ~val, hart); + return updateRegister(num, gInstance.get(hart).getValue(num) & ~val, hart); } /** @@ -252,6 +260,10 @@ public static void clearRegister(String name, long val) { updateRegister(name, instance.getValue(name) & ~val); } + public static void clearRegister(String name, long val, int hart) { + updateRegister(name, gInstance.get(hart).getValue(name) & ~val, hart); + } + /** * Returns the value of the register * @@ -290,7 +302,11 @@ public static long getValueLong(int num, int hart) { **/ public static int getValue(String name) { - return (int)instance.getValue(name); + return (int) instance.getValue(name); + } + + public static int getValue(String name, int hart) { + return (int) gInstance.get(hart).getValue(name); } /** diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index 8d7198a0..5cc0949a 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -212,11 +212,14 @@ public static long getValueLong(int num, int hart) { * @param name The register's name. * @return The value of the given register. **/ - public static int getValue(String name) { return (int) instance.getValue(name); } + public static int getValue(String name, int hart) { + return (int) gInstance.get(hart).getValue(name); + } + /** * For returning the set of registers. * diff --git a/src/rars/riscv/instructions/AtomicMemoryOperation.java b/src/rars/riscv/instructions/AtomicMemoryOperation.java index b245b67d..c988183f 100644 --- a/src/rars/riscv/instructions/AtomicMemoryOperation.java +++ b/src/rars/riscv/instructions/AtomicMemoryOperation.java @@ -60,17 +60,17 @@ public void simulate(ProgramStatement statement) throws SimulationException { int rs1Loc; long rs2Value; long rs1Data; - if(statement.getCurrentHart() == -1){ + int hart = statement.getCurrentHart(); + if (hart == -1) { rs1Loc = RegisterFile.getValue(operands[2]); rs2Value = RegisterFile.getValueLong(operands[1]); rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); RegisterFile.updateRegister(operands[0], rs1Data); - } - else{ - rs1Loc = RegisterFile.getValue(operands[2], statement.getCurrentHart()); - rs2Value = RegisterFile.getValueLong(operands[1], statement.getCurrentHart()); + } else { + rs1Loc = RegisterFile.getValue(operands[2], hart); + rs2Value = RegisterFile.getValueLong(operands[1], hart); rs1Data = InstructionSet.rv64 ? Globals.memory.getDoubleWord(rs1Loc) : Globals.memory.getWord(rs1Loc); - RegisterFile.updateRegister(operands[0], rs1Data, statement.getCurrentHart()); + RegisterFile.updateRegister(operands[0], rs1Data, hart); } Globals.reservationTables.unreserveAddress(0, rs1Loc, width); diff --git a/src/rars/riscv/instructions/DIV.java b/src/rars/riscv/instructions/DIV.java index 5553d929..dab9ec1f 100644 --- a/src/rars/riscv/instructions/DIV.java +++ b/src/rars/riscv/instructions/DIV.java @@ -1,7 +1,5 @@ package rars.riscv.instructions; -import rars.riscv.hardware.ControlAndStatusRegisterFile; - /* Copyright (c) 2017, Benjamin Landers diff --git a/src/rars/riscv/instructions/DIVU.java b/src/rars/riscv/instructions/DIVU.java index 27001a04..57400fae 100644 --- a/src/rars/riscv/instructions/DIVU.java +++ b/src/rars/riscv/instructions/DIVU.java @@ -1,7 +1,5 @@ package rars.riscv.instructions; -import rars.riscv.hardware.ControlAndStatusRegisterFile; - /* Copyright (c) 2017, Benjamin Landers @@ -45,4 +43,4 @@ public long compute(long value, long value2) { public int computeW(int value, int value2) { return (int)compute(value & 0xFFFFFFFFL, value2 & 0xFFFFFFFFL); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/DIVUW.java b/src/rars/riscv/instructions/DIVUW.java index 1c355c5a..0a1579a6 100644 --- a/src/rars/riscv/instructions/DIVUW.java +++ b/src/rars/riscv/instructions/DIVUW.java @@ -5,5 +5,4 @@ public DIVUW() { super("divuw t1,t2,t3", "Division: set t1 to the result of t2/t3 using unsigned division limited to 32 bits", "0000001", "101",new DIVU()); } - -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/ECALL.java b/src/rars/riscv/instructions/ECALL.java index 48e66c7d..c339d254 100644 --- a/src/rars/riscv/instructions/ECALL.java +++ b/src/rars/riscv/instructions/ECALL.java @@ -41,6 +41,10 @@ public ECALL() { } public void simulate(ProgramStatement statement) throws SimulationException { - InstructionSet.findAndSimulateSyscall(RegisterFile.getValue("a7"), statement); + int hart = statement.getCurrentHart(); + if (hart == -1) + InstructionSet.findAndSimulateSyscall(RegisterFile.getValue("a7"), statement); + else + InstructionSet.findAndSimulateSyscall(RegisterFile.getValue("a7", hart), statement); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/ImmediateInstruction.java b/src/rars/riscv/instructions/ImmediateInstruction.java index 2e0b9b50..0fda4448 100644 --- a/src/rars/riscv/instructions/ImmediateInstruction.java +++ b/src/rars/riscv/instructions/ImmediateInstruction.java @@ -51,23 +51,21 @@ public ImmediateInstruction(String usage, String description, String funct, bool public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - if (InstructionSet.rv64){ - if(statement.getCurrentHart() == -1) + int hart = statement.getCurrentHart(); + if (InstructionSet.rv64) { + if (hart == -1) RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1]), (operands[2] << 20) >> 20)); // make sure the immediate is sign-extended else - RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1], statement.getCurrentHart()), - (operands[2] << 20) >> 20), statement.getCurrentHart()); // make sure the immediate is sign-extended - }else { - - if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister(operands[0], compute(RegisterFile.getValueLong(operands[1], hart), + (operands[2] << 20) >> 20), hart); // make sure the immediate is sign-extended + } else { + if (hart == -1) RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1]), (operands[2] << 20) >> 20)); // make sure the immediate is sign-extended - else{ - RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1], statement.getCurrentHart()), - (operands[2] << 20) >> 20), statement.getCurrentHart()); // make sure the immediate is sign-extended - System.out.println("Hart " + (statement.getCurrentHart() + 1) +" :" + "Register " + operands[0] + " : " + RegisterFile.getValue(operands[1], statement.getCurrentHart())); - } + else + RegisterFile.updateRegister(operands[0], computeW(RegisterFile.getValue(operands[1], hart), + (operands[2] << 20) >> 20), hart); // make sure the immediate is sign-extended } } @@ -85,4 +83,4 @@ public void simulate(ProgramStatement statement) { protected int computeW(int value, int immediate){ return (int) compute(value, immediate); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/JAL.java b/src/rars/riscv/instructions/JAL.java index 680b32d5..d633726e 100644 --- a/src/rars/riscv/instructions/JAL.java +++ b/src/rars/riscv/instructions/JAL.java @@ -42,12 +42,13 @@ public JAL() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - if(statement.getCurrentHart() != -1){ - InstructionSet.processReturnAddress(operands[0], statement.getCurrentHart()); - InstructionSet.processJump(RegisterFile.getProgramCounter(statement.getCurrentHart()) - Instruction.INSTRUCTION_LENGTH + operands[1]); + int hart = statement.getCurrentHart(); + if (hart >= 0) { + InstructionSet.processReturnAddress(operands[0], hart); + InstructionSet.processJump(RegisterFile.getProgramCounter(hart) - Instruction.INSTRUCTION_LENGTH + operands[1]); return; } InstructionSet.processReturnAddress(operands[0]); - InstructionSet.processJump(RegisterFile.getProgramCounter() - Instruction.INSTRUCTION_LENGTH + operands[1], statement.getCurrentHart()); + InstructionSet.processJump(RegisterFile.getProgramCounter() - Instruction.INSTRUCTION_LENGTH + operands[1], hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/JALR.java b/src/rars/riscv/instructions/JALR.java index 2f209ac5..548a820f 100644 --- a/src/rars/riscv/instructions/JALR.java +++ b/src/rars/riscv/instructions/JALR.java @@ -41,9 +41,17 @@ public JALR() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - int target = RegisterFile.getValue(operands[1]); - InstructionSet.processReturnAddress(operands[0]); - // Set PC = $t2 + immediate with the last bit set to 0 - InstructionSet.processJump((target + ((operands[2]<<20)>>20)) & 0xFFFFFFFE); + int hart = statement.getCurrentHart(); + if (hart == -1) { + int target = RegisterFile.getValue(operands[1]); + InstructionSet.processReturnAddress(operands[0]); + // Set PC = $t2 + immediate with the last bit set to 0 + InstructionSet.processJump((target + ((operands[2] << 20) >> 20)) & 0xFFFFFFFE); + } else { + int target = RegisterFile.getValue(operands[1], hart); + InstructionSet.processReturnAddress(operands[0], hart); + // Set PC = $t2 + immediate with the last bit set to 0 + InstructionSet.processJump((target + ((operands[2] << 20) >> 20)) & 0xFFFFFFFE, hart); + } } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/LRD.java b/src/rars/riscv/instructions/LRD.java index 16d702e0..8417bd02 100644 --- a/src/rars/riscv/instructions/LRD.java +++ b/src/rars/riscv/instructions/LRD.java @@ -15,14 +15,18 @@ public LRD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); try { - RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1]))); + int hart = statement.getCurrentHart(); + if (hart == -1) + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1]), hart)); + else + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1], hart), hart), hart); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } - private long load(int address) throws AddressErrorException { - Globals.reservationTables.reserveAddress(0, address, bitWidth.doubleWord); + private long load(int address, int hart) throws AddressErrorException { + Globals.reservationTables.reserveAddress(hart + 1, address, bitWidth.doubleWord); return Globals.memory.getDoubleWord(address); } } diff --git a/src/rars/riscv/instructions/LRW.java b/src/rars/riscv/instructions/LRW.java index 7e83df66..4a37cb89 100644 --- a/src/rars/riscv/instructions/LRW.java +++ b/src/rars/riscv/instructions/LRW.java @@ -15,10 +15,11 @@ public LRW() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); try { - if(statement.getCurrentHart() == -1) - RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1]), statement.getCurrentHart())); + int hart = statement.getCurrentHart(); + if (hart == -1) + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1]), hart)); else - RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1], statement.getCurrentHart()), statement.getCurrentHart()), statement.getCurrentHart()); + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[1], hart), hart), hart); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } diff --git a/src/rars/riscv/instructions/LUI.java b/src/rars/riscv/instructions/LUI.java index 0a162a71..a3a3468e 100644 --- a/src/rars/riscv/instructions/LUI.java +++ b/src/rars/riscv/instructions/LUI.java @@ -40,6 +40,10 @@ public LUI() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - RegisterFile.updateRegister(operands[0], operands[1] << 12); + int hart = statement.getCurrentHart(); + if (hart == -1) + RegisterFile.updateRegister(operands[0], operands[1] << 12); + else + RegisterFile.updateRegister(operands[0], operands[1] << 12, hart); } } diff --git a/src/rars/riscv/instructions/Load.java b/src/rars/riscv/instructions/Load.java index e2c89eb7..9f5df928 100644 --- a/src/rars/riscv/instructions/Load.java +++ b/src/rars/riscv/instructions/Load.java @@ -42,21 +42,24 @@ a copy of this software and associated documentation files (the */ public abstract class Load extends BasicInstruction { public Load(String usage, String description, String funct) { - super(usage, description, BasicInstructionFormat.I_FORMAT, - "ssssssssssss ttttt " + funct + " fffff 0000011"); + super(usage, description, BasicInstructionFormat.I_FORMAT, "ssssssssssss ttttt " + funct + " fffff 0000011"); } + public Load(String usage, String description, String funct, boolean rv64) { super(usage, description, BasicInstructionFormat.I_FORMAT, "ssssssssssss ttttt " + funct + " fffff 0000011",rv64); - } public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); operands[1] = (operands[1] << 20) >> 20; + int hart = statement.getCurrentHart(); try { - RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[2]) + operands[1])); + if (hart == -1) + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[2]) + operands[1])); + else + RegisterFile.updateRegister(operands[0], load(RegisterFile.getValue(operands[2], hart) + operands[1]), hart); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } @@ -67,4 +70,4 @@ public void simulate(ProgramStatement statement) throws SimulationException { * @return The value to store to the register */ protected abstract long load(int address) throws AddressErrorException; -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/REM.java b/src/rars/riscv/instructions/REM.java index 1fa9644e..c0ad5930 100644 --- a/src/rars/riscv/instructions/REM.java +++ b/src/rars/riscv/instructions/REM.java @@ -1,7 +1,5 @@ package rars.riscv.instructions; -import rars.riscv.hardware.ControlAndStatusRegisterFile; - /* Copyright (c) 2017, Benjamin Landers diff --git a/src/rars/riscv/instructions/REMU.java b/src/rars/riscv/instructions/REMU.java index b7f517e1..2c22e437 100644 --- a/src/rars/riscv/instructions/REMU.java +++ b/src/rars/riscv/instructions/REMU.java @@ -1,7 +1,5 @@ package rars.riscv.instructions; -import rars.riscv.hardware.ControlAndStatusRegisterFile; - /* Copyright (c) 2017, Benjamin Landers diff --git a/src/rars/riscv/instructions/REMUW.java b/src/rars/riscv/instructions/REMUW.java index 5e9d4da4..c7dda11d 100644 --- a/src/rars/riscv/instructions/REMUW.java +++ b/src/rars/riscv/instructions/REMUW.java @@ -3,6 +3,6 @@ public class REMUW extends ArithmeticW { public REMUW() { super("remuw t1,t2,t3", "Remainder: set t1 to the remainder of t2/t3 using unsigned division limited to 32 bits", - "0000001", "111",new REMU()); + "0000001", "111", new REMU()); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/REMW.java b/src/rars/riscv/instructions/REMW.java index a6f31f61..43d37ad6 100644 --- a/src/rars/riscv/instructions/REMW.java +++ b/src/rars/riscv/instructions/REMW.java @@ -3,6 +3,6 @@ public class REMW extends ArithmeticW { public REMW() { super("remw t1,t2,t3", "Remainder: set t1 to the remainder of t2/t3 using only the lower 32 bits", - "0000001", "110",new REM()); + "0000001", "110", new REM()); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/SW.java b/src/rars/riscv/instructions/SW.java index 9c1720cf..6fbd4aa8 100644 --- a/src/rars/riscv/instructions/SW.java +++ b/src/rars/riscv/instructions/SW.java @@ -36,8 +36,8 @@ public SW() { super("sw t1, -100(t2)", "Store word : Store contents of t1 into effective memory word address", "010"); } - public void store(int address, long data) throws AddressErrorException { - Globals.reservationTables.unreserveAddress(0, address, bitWidth.word); + public void store(int address, long data, int hart) throws AddressErrorException { + Globals.reservationTables.unreserveAddress(hart + 1, address, bitWidth.word); Globals.memory.setWord(address, (int) data); } } diff --git a/src/rars/riscv/instructions/Store.java b/src/rars/riscv/instructions/Store.java index 7f309041..ddab202e 100644 --- a/src/rars/riscv/instructions/Store.java +++ b/src/rars/riscv/instructions/Store.java @@ -47,14 +47,21 @@ public Store(String usage, String description, String funct) { } public Store(String usage, String description, String funct, boolean rv64) { super(usage, description, BasicInstructionFormat.S_FORMAT, - "sssssss fffff ttttt " + funct + " sssss 0100011",rv64); + "sssssss fffff ttttt " + funct + " sssss 0100011", rv64); } public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); operands[1] = (operands[1] << 20) >> 20; try { - store(RegisterFile.getValue(operands[2]) + operands[1], RegisterFile.getValueLong(operands[0])); + int base = (hart == -1) + ? RegisterFile.getValue(operands[2]) + : RegisterFile.getValue(operands[2], hart); + long value = (hart == -1) + ? RegisterFile.getValueLong(operands[0]) + : RegisterFile.getValueLong(operands[0], hart); + store(base + operands[1], value, hart); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } @@ -63,6 +70,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { /** * @param address the address to store to * @param value the value to store + * @param hart the hart to store from */ - protected abstract void store(int address, long value) throws AddressErrorException; -} \ No newline at end of file + protected abstract void store(int address, long value, int hart) throws AddressErrorException; +} diff --git a/src/rars/riscv/instructions/URET.java b/src/rars/riscv/instructions/URET.java index 2c142e3d..a2e96f33 100644 --- a/src/rars/riscv/instructions/URET.java +++ b/src/rars/riscv/instructions/URET.java @@ -39,13 +39,25 @@ public URET() { } public void simulate(ProgramStatement statement) { - boolean upie = (ControlAndStatusRegisterFile.getValue("ustatus") & 0x10) == 0x10; - ControlAndStatusRegisterFile.clearRegister("ustatus", 0x10); // Clear UPIE - if (upie) { // Set UIE to UPIE - ControlAndStatusRegisterFile.orRegister("ustatus", 0x1); + int hart = statement.getCurrentHart(); + if (hart == -1) { + boolean upie = (ControlAndStatusRegisterFile.getValue("ustatus") & 0x10) == 0x10; + ControlAndStatusRegisterFile.clearRegister("ustatus", 0x10); // Clear UPIE + if (upie) { // Set UIE to UPIE + ControlAndStatusRegisterFile.orRegister("ustatus", 0x1); + } else { + ControlAndStatusRegisterFile.clearRegister("ustatus", 0x1); + } + RegisterFile.setProgramCounter(ControlAndStatusRegisterFile.getValue("uepc")); } else { - ControlAndStatusRegisterFile.clearRegister("ustatus", 0x1); + boolean upie = (ControlAndStatusRegisterFile.getValue("ustatus", hart) & 0x10) == 0x10; + ControlAndStatusRegisterFile.clearRegister("ustatus", 0x10, hart); // Clear UPIE + if (upie) { // Set UIE to UPIE + ControlAndStatusRegisterFile.orRegister("ustatus", 0x1, hart); + } else { + ControlAndStatusRegisterFile.clearRegister("ustatus", 0x1, hart); + } + RegisterFile.setProgramCounter(ControlAndStatusRegisterFile.getValue("uepc", hart), hart); } - RegisterFile.setProgramCounter(ControlAndStatusRegisterFile.getValue("uepc")); } } From 3249da44f3135460ee3a6b27c87cc377e47c7d29 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Fri, 13 Aug 2021 11:27:12 -0400 Subject: [PATCH 71/84] extend store instructions to multithread --- src/rars/riscv/instructions/SB.java | 4 ++-- src/rars/riscv/instructions/SCD.java | 14 ++++++++++---- src/rars/riscv/instructions/SCW.java | 14 ++++++++++---- src/rars/riscv/instructions/SD.java | 4 ++-- src/rars/riscv/instructions/SH.java | 6 +++--- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/rars/riscv/instructions/SB.java b/src/rars/riscv/instructions/SB.java index 9768ff64..ea31292a 100644 --- a/src/rars/riscv/instructions/SB.java +++ b/src/rars/riscv/instructions/SB.java @@ -36,8 +36,8 @@ public SB() { super("sb t1, -100(t2)", "Store byte : Store the low-order 8 bits of t1 into the effective memory byte address", "000"); } - public void store(int address, long data) throws AddressErrorException { - Globals.reservationTables.unreserveAddress(0, address & ~0b11, bitWidth.word); + public void store(int address, long data, int hart) throws AddressErrorException { + Globals.reservationTables.unreserveAddress(hart + 1, address & ~0b11, bitWidth.word); Globals.memory.setByte(address, (int)data & 0x000000FF); } } diff --git a/src/rars/riscv/instructions/SCD.java b/src/rars/riscv/instructions/SCD.java index dba28da1..474da212 100644 --- a/src/rars/riscv/instructions/SCD.java +++ b/src/rars/riscv/instructions/SCD.java @@ -14,16 +14,22 @@ public SCD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); try { - long result = store(RegisterFile.getValue(operands[2]), RegisterFile.getValue(operands[1])); - RegisterFile.updateRegister(operands[0], result); + if (hart == -1) { + long result = store(RegisterFile.getValue(operands[2]), RegisterFile.getValue(operands[1]), hart); + RegisterFile.updateRegister(operands[0], result); + } else { + long result = store(RegisterFile.getValue(operands[2], hart), RegisterFile.getValue(operands[1], hart), hart); + RegisterFile.updateRegister(operands[0], result, hart); + } } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } - private long store(int address, int value) throws AddressErrorException { - if (Globals.reservationTables.unreserveAddress(0, address, bitWidth.doubleWord)) { + private long store(int address, int value, int hart) throws AddressErrorException { + if (Globals.reservationTables.unreserveAddress(hart + 1, address, bitWidth.doubleWord)) { Globals.memory.setDoubleWord(address, value); return 0; } diff --git a/src/rars/riscv/instructions/SCW.java b/src/rars/riscv/instructions/SCW.java index 80ad716c..84a7d80c 100644 --- a/src/rars/riscv/instructions/SCW.java +++ b/src/rars/riscv/instructions/SCW.java @@ -14,16 +14,22 @@ public SCW() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); try { - int result = store(RegisterFile.getValue(operands[2]), RegisterFile.getValue(operands[1])); - RegisterFile.updateRegister(operands[0], result); + if (hart == - 1) { + int result = store(RegisterFile.getValue(operands[2], hart), RegisterFile.getValue(operands[1], hart), hart); + RegisterFile.updateRegister(operands[0], result); + } else { + int result = store(RegisterFile.getValue(operands[2]), RegisterFile.getValue(operands[1]), hart); + RegisterFile.updateRegister(operands[0], result, hart); + } } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } - private int store(int address, int value) throws AddressErrorException { - if (Globals.reservationTables.unreserveAddress(0, address, bitWidth.word)) { + private int store(int address, int value, int hart) throws AddressErrorException { + if (Globals.reservationTables.unreserveAddress(hart + 1, address, bitWidth.word)) { Globals.memory.setWord(address, value); return 0; } diff --git a/src/rars/riscv/instructions/SD.java b/src/rars/riscv/instructions/SD.java index 4b901d8d..bddaa0de 100644 --- a/src/rars/riscv/instructions/SD.java +++ b/src/rars/riscv/instructions/SD.java @@ -9,8 +9,8 @@ public SD() { super("sd t1, -100(t2)", "Store double word : Store contents of t1 into effective memory double word address", "011",true); } - public void store(int address, long data) throws AddressErrorException { - Globals.reservationTables.unreserveAddress(0, address, bitWidth.doubleWord); + public void store(int address, long data, int hart) throws AddressErrorException { + Globals.reservationTables.unreserveAddress(hart + 1, address, bitWidth.doubleWord); Globals.memory.setDoubleWord(address, data); } } diff --git a/src/rars/riscv/instructions/SH.java b/src/rars/riscv/instructions/SH.java index a640e1f5..de249dd5 100644 --- a/src/rars/riscv/instructions/SH.java +++ b/src/rars/riscv/instructions/SH.java @@ -36,8 +36,8 @@ public SH() { super("sh t1, -100(t2)", "Store halfword : Store the low-order 16 bits of t1 into the effective memory halfword address", "001"); } - public void store(int address, long data) throws AddressErrorException { - Globals.reservationTables.unreserveAddress(0, address & ~0b11, bitWidth.word); - Globals.memory.setHalf(address, (int)data & 0x0000FFFF); + public void store(int address, long data, int hart) throws AddressErrorException { + Globals.reservationTables.unreserveAddress(hart + 1, address & ~0b11, bitWidth.word); + Globals.memory.setHalf(address, (int) data & 0x0000FFFF); } } From 1895866990aa0a2df0e3f4b5adfd15786395b173 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Tue, 17 Aug 2021 10:09:53 -0400 Subject: [PATCH 72/84] multithread f+d extensions --- src/rars/Globals.java | 2 +- .../ControlAndStatusRegisterFile.java | 1 - .../hardware/FloatingPointRegisterFile.java | 99 ++++++++++++++++--- src/rars/riscv/instructions/Double.java | 28 ++++-- src/rars/riscv/instructions/FCLASSD.java | 12 ++- src/rars/riscv/instructions/FCLASSS.java | 29 +++++- src/rars/riscv/instructions/FCVTDL.java | 17 +++- src/rars/riscv/instructions/FCVTDLU.java | 16 ++- src/rars/riscv/instructions/FCVTDS.java | 14 ++- src/rars/riscv/instructions/FCVTDW.java | 12 ++- src/rars/riscv/instructions/FCVTDWU.java | 16 ++- src/rars/riscv/instructions/FCVTLD.java | 17 +++- src/rars/riscv/instructions/FCVTLS.java | 14 ++- src/rars/riscv/instructions/FCVTLUD.java | 17 +++- src/rars/riscv/instructions/FCVTLUS.java | 14 ++- src/rars/riscv/instructions/FCVTSD.java | 14 ++- src/rars/riscv/instructions/FCVTSL.java | 15 ++- src/rars/riscv/instructions/FCVTSLU.java | 16 ++- src/rars/riscv/instructions/FCVTSW.java | 15 ++- src/rars/riscv/instructions/FCVTSWU.java | 15 ++- src/rars/riscv/instructions/FCVTWD.java | 16 ++- src/rars/riscv/instructions/FCVTWS.java | 20 ++-- src/rars/riscv/instructions/FCVTWUD.java | 17 +++- src/rars/riscv/instructions/FCVTWUS.java | 19 ++-- src/rars/riscv/instructions/FENCE.java | 3 +- src/rars/riscv/instructions/FEQD.java | 13 ++- src/rars/riscv/instructions/FEQS.java | 15 +-- src/rars/riscv/instructions/FLD.java | 16 ++- src/rars/riscv/instructions/FLED.java | 13 ++- src/rars/riscv/instructions/FLES.java | 15 +-- src/rars/riscv/instructions/FLTD.java | 13 ++- src/rars/riscv/instructions/FLTS.java | 15 +-- src/rars/riscv/instructions/FLW.java | 11 ++- src/rars/riscv/instructions/FMVDX.java | 10 +- src/rars/riscv/instructions/FMVSX.java | 10 +- src/rars/riscv/instructions/FMVXD.java | 10 +- src/rars/riscv/instructions/FMVXS.java | 10 +- src/rars/riscv/instructions/FSD.java | 10 +- src/rars/riscv/instructions/FSGNJD.java | 18 +++- src/rars/riscv/instructions/FSGNJND.java | 18 +++- src/rars/riscv/instructions/FSGNJNS.java | 17 +++- src/rars/riscv/instructions/FSGNJS.java | 16 ++- src/rars/riscv/instructions/FSGNJXD.java | 15 ++- src/rars/riscv/instructions/FSGNJXS.java | 15 ++- src/rars/riscv/instructions/FSQRTD.java | 16 ++- src/rars/riscv/instructions/FSQRTS.java | 17 +++- src/rars/riscv/instructions/FSW.java | 10 +- src/rars/riscv/instructions/Floating.java | 45 +++++++-- src/rars/riscv/instructions/FusedDouble.java | 21 +++- src/rars/riscv/instructions/FusedFloat.java | 22 +++-- src/rars/tools/ReservationTablesTool.java | 11 ++- src/rars/venus/GeneralVenusUI.java | 16 +-- .../registers/ControlAndStatusWindow.java | 3 +- .../venus/registers/FloatingPointWindow.java | 9 ++ 54 files changed, 667 insertions(+), 221 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index cbaf40d4..c3743e5a 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -154,7 +154,7 @@ public class Globals { public static void setHartWindows(){ for (int i = 1; i < Globals.getHarts(); i++) { - GeneralVenusUI temp= new GeneralVenusUI(String.format("Hart %d", i)); + GeneralVenusUI temp = new GeneralVenusUI(i - 1); hartWindows.add(temp); } } diff --git a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java index bd1c150c..c7d6378f 100644 --- a/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java +++ b/src/rars/riscv/hardware/ControlAndStatusRegisterFile.java @@ -111,7 +111,6 @@ public static void changeHarts(int sign) { if (sign < 0) { gInstance.remove(gInstance.size() - 1); } - System.out.println(gInstance.size()); } /** diff --git a/src/rars/riscv/hardware/FloatingPointRegisterFile.java b/src/rars/riscv/hardware/FloatingPointRegisterFile.java index 949bcc0c..f3972b28 100644 --- a/src/rars/riscv/hardware/FloatingPointRegisterFile.java +++ b/src/rars/riscv/hardware/FloatingPointRegisterFile.java @@ -2,6 +2,7 @@ import rars.Globals; +import java.util.ArrayList; import java.util.Observer; /* @@ -64,6 +65,26 @@ public class FloatingPointRegisterFile { new Register("ft8", 28, 0), new Register("ft9", 29, 0), new Register("ft10", 30, 0), new Register("ft11", 31, 0) }); + private static final ArrayList gInstance = new ArrayList<>(); + + public static void increaseHarts() { + gInstance.add(new RegisterBlock('f', + new Register[] { new Register("ft0", 0, 0), new Register("ft1", 1, 0), new Register("ft2", 2, 0), + new Register("ft3", 3, 0), new Register("ft4", 4, 0), new Register("ft5", 5, 0), + new Register("ft6", 6, 0), new Register("ft7", 7, 0), new Register("fs0", 8, 0), + new Register("fs1", 9, 0), new Register("fa0", 10, 0), new Register("fa1", 11, 0), + new Register("fa2", 12, 0), new Register("fa3", 13, 0), new Register("fa4", 14, 0), + new Register("fa5", 15, 0), new Register("fa6", 16, 0), new Register("fa7", 17, 0), + new Register("fs2", 18, 0), new Register("fs3", 19, 0), new Register("fs4", 20, 0), + new Register("fs5", 21, 0), new Register("fs6", 22, 0), new Register("fs7", 23, 0), + new Register("fs8", 24, 0), new Register("fs9", 25, 0), new Register("fs10", 26, 0), + new Register("fs11", 27, 0), new Register("ft8", 28, 0), new Register("ft9", 29, 0), + new Register("ft10", 30, 0), new Register("ft11", 31, 0) })); + } + + public static void decreaseHarts() { + gInstance.remove(gInstance.size() - 1); + } /** * Sets the value of the FPU register given to the value given. @@ -71,22 +92,28 @@ public class FloatingPointRegisterFile { * @param reg Register to set the value of. * @param val The desired float value for the register. **/ - public static void setRegisterToFloat(int reg, float val) { updateRegister(reg, Float.floatToRawIntBits(val)); } + public static void setRegisterToFloat(int reg, float val, int hart) { + updateRegister(reg, Float.floatToRawIntBits(val), hart); + } + /** * Gets the float value stored in the given FPU register. * * @param name Register to get the value of. * @return The float value stored by that register. **/ - public static float getFloatFromRegister(String name) { return Float.intBitsToFloat(getValue(name)); } + public static float getFloatFromRegister(String name, int hart) { + return Float.intBitsToFloat(getValue(name)); + } + /** * This method updates the FPU register value who's number is num. Note the * registers themselves hold an int value. There are helper methods available @@ -95,7 +122,6 @@ public static float getFloatFromRegister(String name) { * @param num FPU register to set the value of. * @param val The desired int value for the register. **/ - public static void updateRegister(int num, int val) { long lval = val | 0xFFFFFFFF_00000000L; // NAN box if used as float if ((Globals.getSettings().getBackSteppingEnabled())) { @@ -105,6 +131,16 @@ public static void updateRegister(int num, int val) { } } + public static void updateRegister(int num, int val, int hart) { + long lval = val | 0xFFFFFFFF_00000000L; // NAN box if used as float + if ((Globals.getSettings().getBackSteppingEnabled())) { + // TODO: enable multithreaded backstepping + Globals.program.getBackStepper().addFloatingPointRestore(num, instance.updateRegister(num, lval)); + } else { + gInstance.get(hart).updateRegister(num, lval); + } + } + public static void updateRegisterLong(int num, long val) { if ((Globals.getSettings().getBackSteppingEnabled())) { Globals.program.getBackStepper().addFloatingPointRestore(num, instance.updateRegister(num, val)); @@ -112,6 +148,16 @@ public static void updateRegisterLong(int num, long val) { instance.updateRegister(num, val); } } + + public static void updateRegisterLong(int num, long val, int hart) { + if ((Globals.getSettings().getBackSteppingEnabled())) { + // TODO: enable multithreaded backstepping + Globals.program.getBackStepper().addFloatingPointRestore(num, instance.updateRegister(num, val)); + } else { + gInstance.get(hart).updateRegister(num, val); + } + } + /** * Gets the raw int value actually stored in a Register. If you need a * float, use Float.intBitsToFloat() to get the equivent float. @@ -119,20 +165,32 @@ public static void updateRegisterLong(int num, long val) { * @param num The FPU register number. * @return The int value of the given register. **/ - public static int getValue(int num) { long lval = instance.getValue(num); - if((lval & 0xFFFFFFFF_00000000L) == 0xFFFFFFFF_00000000L){ - return (int)lval; // If NaN-Boxed return value + if ((lval & 0xFFFFFFFF_00000000L) == 0xFFFFFFFF_00000000L) { + return (int) lval; // If NaN-Boxed return value }else{ return 0x7FC00000; // Otherwise NaN } } + public static int getValue(int num, int hart) { + long lval = gInstance.get(hart).getValue(num); + if ((lval & 0xFFFFFFFF_00000000L) == 0xFFFFFFFF_00000000L) { + return (int) lval; // If NaN-Boxed return value + } else { + return 0x7FC00000; // Otherwise NaN + } + } + public static long getValueLong(int num) { return instance.getValue(num); } + public static long getValueLong(int num, int hart) { + return gInstance.get(hart).getValue(num); + } + /** * Gets the raw int value actually stored in a Register. If you need a * float, use Float.intBitsToFloat() to get the equivent float. @@ -140,12 +198,20 @@ public static long getValueLong(int num) { * @param name The FPU register name. * @return The int value of the given register. **/ - public static int getValue(String name) { long lval = instance.getValue(name); - if((lval & 0xFFFFFFFF_00000000L) == 0xFFFFFFFF_00000000L){ - return (int)lval; - }else{ + if ((lval & 0xFFFFFFFF_00000000L) == 0xFFFFFFFF_00000000L) { + return (int) lval; + } else { + return 0x7FC00000; + } + } + + public static int getValue(String name, int hart) { + long lval = gInstance.get(hart).getValue(name); + if ((lval & 0xFFFFFFFF_00000000L) == 0xFFFFFFFF_00000000L) { + return (int) lval; + } else { return 0x7FC00000; } } @@ -155,29 +221,36 @@ public static int getValue(String name) { * * @return The set of registers. **/ - public static Register[] getRegisters() { return instance.getRegisters(); } + public static Register[] getRegisters(int hart) { + return gInstance.get(hart).getRegisters(); + } + /** * Get register object corresponding to given name. If no match, return null. * * @param name The FPU register name, must be "f0" through "f31". * @return The register object,or null if not found. **/ - public static Register getRegister(String name) { return instance.getRegister(name); } + public static Register getRegister(String name, int hart) { + return gInstance.get(hart).getRegister(name); + } + /** * Method to reinitialize the values of the registers. **/ - public static void resetRegisters() { instance.resetRegisters(); + for (RegisterBlock i : gInstance) + i.resetRegisters(); } diff --git a/src/rars/riscv/instructions/Double.java b/src/rars/riscv/instructions/Double.java index 0edc8011..7d214f3d 100644 --- a/src/rars/riscv/instructions/Double.java +++ b/src/rars/riscv/instructions/Double.java @@ -16,18 +16,34 @@ protected Double(String name, String description, String funct) { protected Double(String name, String description, String funct, String rm) { super(name + " f1, f2, f3", description, BasicInstructionFormat.R_FORMAT, funct + "ttttt sssss " + rm + " fffff 1010011"); } - public void simulate(ProgramStatement statement) throws SimulationException{ + public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[3],statement); - Float64 result = compute(new Float64(FloatingPointRegisterFile.getValueLong(operands[1])),new Float64(FloatingPointRegisterFile.getValueLong(operands[2])),e); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits); + Float64 result = compute( + new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart) + ), + new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[2]) + : FloatingPointRegisterFile.getValueLong(operands[2], hart)), + e); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits, hart); } public abstract Float64 compute(Float64 f1, Float64 f2, Environment e); - public static Float64 getDouble(int num){ + public static Float64 getDouble(int num) { return new Float64(FloatingPointRegisterFile.getValueLong(num)); } -} \ No newline at end of file + + public static Float64 getDouble(int num, int hart) { + return new Float64(FloatingPointRegisterFile.getValueLong(num, hart)); + } +} diff --git a/src/rars/riscv/instructions/FCLASSD.java b/src/rars/riscv/instructions/FCLASSD.java index ef1ea9c0..ac9f46bf 100644 --- a/src/rars/riscv/instructions/FCLASSD.java +++ b/src/rars/riscv/instructions/FCLASSD.java @@ -14,7 +14,13 @@ public FCLASSD() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - Float64 in = new Float64(FloatingPointRegisterFile.getValueLong(operands[1])); - FCLASSS.fclass(in,operands[0]); + int hart = statement.getCurrentHart(); + Float64 in = (hart == -1) + ? new Float64(FloatingPointRegisterFile.getValueLong(operands[1])) + : new Float64(FloatingPointRegisterFile.getValueLong(operands[1], hart)); + if (hart == -1) + FCLASSS.fclass(in, operands[0]); + else + FCLASSS.fclass(in, operands[0], hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FCLASSS.java b/src/rars/riscv/instructions/FCLASSS.java index ad613829..242adf57 100644 --- a/src/rars/riscv/instructions/FCLASSS.java +++ b/src/rars/riscv/instructions/FCLASSS.java @@ -54,8 +54,14 @@ public FCLASSS() { */ public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - Float32 in = new Float32(FloatingPointRegisterFile.getValue(operands[1])); - fclass(in,operands[0]); + int hart = statement.getCurrentHart(); + Float32 in = (hart == -1) + ? new Float32(FloatingPointRegisterFile.getValue(operands[1])) + : new Float32(FloatingPointRegisterFile.getValue(operands[1], hart)); + if (hart == -1) + fclass(in, operands[0]); + else + fclass(in, operands[0], hart); } public static > void fclass(T in, int out){ @@ -74,4 +80,21 @@ public static > void fclass(T in, int out } } } -} \ No newline at end of file + + public static > void fclass(T in, int out, int hart) { + if (in.isNaN()) { + RegisterFile.updateRegister(out, in.isSignalling() ? 0x100 : 0x200, hart); + } else { + boolean negative = in.isSignMinus(); + if (in.isInfinite()) { + RegisterFile.updateRegister(out, negative ? 0x001 : 0x080, hart); + } else if (in.isZero()) { + RegisterFile.updateRegister(out, negative ? 0x008 : 0x010, hart); + } else if (in.isSubnormal()) { + RegisterFile.updateRegister(out, negative ? 0x004 : 0x020, hart); + } else { + RegisterFile.updateRegister(out, negative ? 0x002 : 0x040, hart); + } + } + } +} diff --git a/src/rars/riscv/instructions/FCVTDL.java b/src/rars/riscv/instructions/FCVTDL.java index e004b451..06fbc47a 100644 --- a/src/rars/riscv/instructions/FCVTDL.java +++ b/src/rars/riscv/instructions/FCVTDL.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -19,12 +20,20 @@ public FCVTDL() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); Float64 tmp = new Float64(0); - Float64 converted = jsoftfloat.operations.Conversions.convertFromInt(BigInteger.valueOf(RegisterFile.getValueLong(operands[1])),e,tmp); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegisterLong(operands[0],converted.bits); + Float64 converted = Conversions + .convertFromInt(BigInteger.valueOf( + (hart == -1) + ? RegisterFile.getValueLong(operands[1]) + : RegisterFile.getValueLong(operands[1], hart)), + e, tmp); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], converted.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], converted.bits, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTDLU.java b/src/rars/riscv/instructions/FCVTDLU.java index c73e52fa..25c81f01 100644 --- a/src/rars/riscv/instructions/FCVTDLU.java +++ b/src/rars/riscv/instructions/FCVTDLU.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -19,17 +20,22 @@ public FCVTDLU() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); Float64 tmp = new Float64(0); - long value = RegisterFile.getValueLong(operands[1]); + long value = (hart == -1) + ? RegisterFile.getValueLong(operands[1]) + : RegisterFile.getValueLong(operands[1], hart); BigInteger unsigned = BigInteger.valueOf(value); if (value < 0) { unsigned = unsigned.add(BigInteger.ONE.shiftLeft(64)); } - Float64 converted = jsoftfloat.operations.Conversions.convertFromInt(unsigned,e,tmp); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegisterLong(operands[0],converted.bits); + Float64 converted = Conversions.convertFromInt(unsigned,e,tmp); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], converted.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], converted.bits, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTDS.java b/src/rars/riscv/instructions/FCVTDS.java index 25c6189d..6b0c73d0 100644 --- a/src/rars/riscv/instructions/FCVTDS.java +++ b/src/rars/riscv/instructions/FCVTDS.java @@ -17,12 +17,18 @@ public FCVTDS() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float32 in = new Float32(FloatingPointRegisterFile.getValue(operands[1])); + Float32 in = new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1])); Float64 out = new Float64(0); out = FCVTSD.convert(in,out,e); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegisterLong(operands[0],out.bits); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], out.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], out.bits, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FCVTDW.java b/src/rars/riscv/instructions/FCVTDW.java index 57e4f779..c239f9a7 100644 --- a/src/rars/riscv/instructions/FCVTDW.java +++ b/src/rars/riscv/instructions/FCVTDW.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -19,12 +20,15 @@ public FCVTDW() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); Float64 tmp = new Float64(0); - Float64 converted = jsoftfloat.operations.Conversions.convertFromInt(BigInteger.valueOf(RegisterFile.getValue(operands[1])),e,tmp); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegisterLong(operands[0],converted.bits); + Float64 converted = Conversions.convertFromInt(BigInteger.valueOf(RegisterFile.getValue(operands[1])),e,tmp); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], converted.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], converted.bits, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTDWU.java b/src/rars/riscv/instructions/FCVTDWU.java index 0644c2fc..d308d97b 100644 --- a/src/rars/riscv/instructions/FCVTDWU.java +++ b/src/rars/riscv/instructions/FCVTDWU.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -19,12 +20,19 @@ public FCVTDWU() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); Float64 tmp = new Float64(0); - Float64 converted = jsoftfloat.operations.Conversions.convertFromInt(BigInteger.valueOf(RegisterFile.getValue(operands[1]) & 0xFFFFFFFFL),e,tmp); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegisterLong(operands[0],converted.bits); + Float64 converted = Conversions + .convertFromInt(BigInteger.valueOf(((hart == -1) + ? RegisterFile.getValue(operands[1]) + : RegisterFile.getValue(operands[1])) + & 0xFFFFFFFFL), e, tmp); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], converted.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], converted.bits, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTLD.java b/src/rars/riscv/instructions/FCVTLD.java index 9648376a..af43608b 100644 --- a/src/rars/riscv/instructions/FCVTLD.java +++ b/src/rars/riscv/instructions/FCVTLD.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -17,11 +18,17 @@ public FCVTLD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float64 in = new Float64(FloatingPointRegisterFile.getValueLong(operands[1])); - long out = jsoftfloat.operations.Conversions.convertToLong(in,e,false); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0],out); + Float64 in = new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart)); + long out = Conversions.convertToLong(in,e,false); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], out); + else + RegisterFile.updateRegister(operands[0], out, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FCVTLS.java b/src/rars/riscv/instructions/FCVTLS.java index 4e8869fc..cc4d7e64 100644 --- a/src/rars/riscv/instructions/FCVTLS.java +++ b/src/rars/riscv/instructions/FCVTLS.java @@ -17,11 +17,17 @@ public FCVTLS() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float32 in = new Float32(FloatingPointRegisterFile.getValue(operands[1])); + Float32 in = new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart)); long out = jsoftfloat.operations.Conversions.convertToLong(in,e,false); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0],out); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], out); + else + RegisterFile.updateRegister(operands[1], out, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FCVTLUD.java b/src/rars/riscv/instructions/FCVTLUD.java index f8834248..96a7bb90 100644 --- a/src/rars/riscv/instructions/FCVTLUD.java +++ b/src/rars/riscv/instructions/FCVTLUD.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -17,11 +18,17 @@ public FCVTLUD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float64 in = new Float64(FloatingPointRegisterFile.getValueLong(operands[1])); - long out = jsoftfloat.operations.Conversions.convertToUnsignedLong(in,e,false); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0],out); + Float64 in = new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart)); + long out = Conversions.convertToUnsignedLong(in,e,false); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], out); + else + RegisterFile.updateRegister(operands[0], out, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FCVTLUS.java b/src/rars/riscv/instructions/FCVTLUS.java index 1f38cb05..9ad96d09 100644 --- a/src/rars/riscv/instructions/FCVTLUS.java +++ b/src/rars/riscv/instructions/FCVTLUS.java @@ -17,11 +17,17 @@ public FCVTLUS() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float32 in = new Float32(FloatingPointRegisterFile.getValue(operands[1])); + Float32 in = new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart)); long out = jsoftfloat.operations.Conversions.convertToUnsignedLong(in,e,false); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0],out); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], out); + else + RegisterFile.updateRegister(operands[0], out, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FCVTSD.java b/src/rars/riscv/instructions/FCVTSD.java index 1c073569..266fa131 100644 --- a/src/rars/riscv/instructions/FCVTSD.java +++ b/src/rars/riscv/instructions/FCVTSD.java @@ -17,13 +17,19 @@ public FCVTSD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float64 in = new Float64(FloatingPointRegisterFile.getValueLong(operands[1])); + Float64 in = (hart == -1) + ? new Float64(FloatingPointRegisterFile.getValueLong(operands[1])) + : new Float64(FloatingPointRegisterFile.getValueLong(operands[1], hart)); Float32 out = new Float32(0); out = convert(in,out,e); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegister(operands[0],out.bits); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], out.bits); + else + FloatingPointRegisterFile.updateRegister(operands[0], out.bits, hart); } // Kindof a long type, but removes duplicate code and would make it easy for quads to be implemented. public static ,D extends jsoftfloat.types.Floating> @@ -39,4 +45,4 @@ S convert(D toconvert, S constructor, Environment e){ } return constructor.fromExactFloat(toconvert.toExactFloat(),e); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FCVTSL.java b/src/rars/riscv/instructions/FCVTSL.java index eeca22a9..fb97f019 100644 --- a/src/rars/riscv/instructions/FCVTSL.java +++ b/src/rars/riscv/instructions/FCVTSL.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float32; import rars.ProgramStatement; import rars.SimulationException; @@ -19,12 +20,18 @@ public FCVTSL() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); Float32 tmp = new Float32(0); - Float32 converted = jsoftfloat.operations.Conversions.convertFromInt(BigInteger.valueOf(RegisterFile.getValueLong(operands[1])),e,tmp); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegister(operands[0],converted.bits); + Float32 converted = Conversions.convertFromInt(BigInteger.valueOf((hart == -1) + ? RegisterFile.getValueLong(operands[1]) + : RegisterFile.getValueLong(operands[1], hart) + ), e, tmp); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], converted.bits); + else + FloatingPointRegisterFile.updateRegister(operands[0], converted.bits, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTSLU.java b/src/rars/riscv/instructions/FCVTSLU.java index 37360d4c..42b0d732 100644 --- a/src/rars/riscv/instructions/FCVTSLU.java +++ b/src/rars/riscv/instructions/FCVTSLU.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float32; import rars.ProgramStatement; import rars.SimulationException; @@ -19,17 +20,22 @@ public FCVTSLU() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); Float32 tmp = new Float32(0); - long value = RegisterFile.getValueLong(operands[1]); + long value = (hart == -1) + ? RegisterFile.getValueLong(operands[1]) + : RegisterFile.getValueLong(operands[1], hart); BigInteger unsigned = BigInteger.valueOf(value); if (value < 0) { unsigned = unsigned.add(BigInteger.ONE.shiftLeft(64)); } - Float32 converted = jsoftfloat.operations.Conversions.convertFromInt(unsigned,e,tmp); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegister(operands[0],converted.bits); + Float32 converted = Conversions.convertFromInt(unsigned,e,tmp); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], converted.bits); + else + FloatingPointRegisterFile.updateRegister(operands[0], converted.bits, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTSW.java b/src/rars/riscv/instructions/FCVTSW.java index 3902630c..ec05f340 100644 --- a/src/rars/riscv/instructions/FCVTSW.java +++ b/src/rars/riscv/instructions/FCVTSW.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float32; import rars.ProgramStatement; import rars.SimulationException; @@ -46,12 +47,18 @@ public FCVTSW() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); Float32 tmp = new Float32(0); - Float32 converted = jsoftfloat.operations.Conversions.convertFromInt(BigInteger.valueOf(RegisterFile.getValue(operands[1])),e,tmp); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegister(operands[0],converted.bits); + Float32 converted = Conversions.convertFromInt(BigInteger.valueOf((hart == -1) + ? RegisterFile.getValue(operands[1]) + : RegisterFile.getValueLong(operands[1], hart) + ), e, tmp); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], converted.bits); + else + FloatingPointRegisterFile.updateRegister(operands[0], converted.bits, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTSWU.java b/src/rars/riscv/instructions/FCVTSWU.java index 4a452ae8..34f92488 100644 --- a/src/rars/riscv/instructions/FCVTSWU.java +++ b/src/rars/riscv/instructions/FCVTSWU.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float32; import rars.ProgramStatement; import rars.SimulationException; @@ -46,12 +47,18 @@ public FCVTSWU() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); Float32 tmp = new Float32(0); - Float32 converted = jsoftfloat.operations.Conversions.convertFromInt(BigInteger.valueOf(RegisterFile.getValue(operands[1]) &0xFFFFFFFFL),e,tmp); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegister(operands[0],converted.bits); + Float32 converted = Conversions.convertFromInt(BigInteger.valueOf(((hart == -1) + ? RegisterFile.getValue(operands[1]) + : RegisterFile.getValue(operands[1], hart)) & 0xFFFFFFFFL), + e, tmp); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], converted.bits); + else + FloatingPointRegisterFile.updateRegister(operands[0], converted.bits, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTWD.java b/src/rars/riscv/instructions/FCVTWD.java index c6ff4f10..48fc1fa2 100644 --- a/src/rars/riscv/instructions/FCVTWD.java +++ b/src/rars/riscv/instructions/FCVTWD.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -17,12 +18,17 @@ public FCVTWD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float64 in = new Float64(FloatingPointRegisterFile.getValueLong(operands[1])); - int out = jsoftfloat.operations.Conversions.convertToInt(in,e,false); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0],out); + Float64 in = new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart)); + int out = Conversions.convertToInt(in,e,false); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], out); + else + RegisterFile.updateRegister(operands[0], out, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTWS.java b/src/rars/riscv/instructions/FCVTWS.java index 84792325..d904a6dd 100644 --- a/src/rars/riscv/instructions/FCVTWS.java +++ b/src/rars/riscv/instructions/FCVTWS.java @@ -1,18 +1,15 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float32; import rars.ProgramStatement; import rars.SimulationException; -import rars.assembler.DataTypes; -import rars.riscv.hardware.ControlAndStatusRegisterFile; import rars.riscv.hardware.FloatingPointRegisterFile; import rars.riscv.hardware.RegisterFile; import rars.riscv.BasicInstruction; import rars.riscv.BasicInstructionFormat; -import java.math.BigInteger; - /* Copyright (c) 2017, Benjamin Landers @@ -48,12 +45,17 @@ public FCVTWS() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float32 in = new Float32(FloatingPointRegisterFile.getValue(operands[1])); - int out = jsoftfloat.operations.Conversions.convertToInt(in,e,false); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0],out); + Float32 in = new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart)); + int out = Conversions.convertToInt(in,e,false); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], out); + else + RegisterFile.updateRegister(operands[0], out, hart); } } - diff --git a/src/rars/riscv/instructions/FCVTWUD.java b/src/rars/riscv/instructions/FCVTWUD.java index 1b889fdd..14736092 100644 --- a/src/rars/riscv/instructions/FCVTWUD.java +++ b/src/rars/riscv/instructions/FCVTWUD.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -17,11 +18,17 @@ public FCVTWUD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float64 in = new Float64(FloatingPointRegisterFile.getValueLong(operands[1])); - int out = jsoftfloat.operations.Conversions.convertToUnsignedInt(in,e,false); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0],out); + Float64 in = new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart)); + int out = Conversions.convertToUnsignedInt(in,e,false); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], out); + else + RegisterFile.updateRegister(operands[0], out, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FCVTWUS.java b/src/rars/riscv/instructions/FCVTWUS.java index 3babac10..657a706c 100644 --- a/src/rars/riscv/instructions/FCVTWUS.java +++ b/src/rars/riscv/instructions/FCVTWUS.java @@ -1,11 +1,10 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Conversions; import jsoftfloat.types.Float32; import rars.ProgramStatement; import rars.SimulationException; -import rars.assembler.DataTypes; -import rars.riscv.hardware.ControlAndStatusRegisterFile; import rars.riscv.hardware.FloatingPointRegisterFile; import rars.riscv.hardware.RegisterFile; import rars.riscv.BasicInstruction; @@ -46,11 +45,17 @@ public FCVTWUS() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float32 in = new Float32(FloatingPointRegisterFile.getValue(operands[1])); - int out = jsoftfloat.operations.Conversions.convertToUnsignedInt(in,e,false); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0],out); + Float32 in = new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1])); + int out = Conversions.convertToUnsignedInt(in,e,false); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0],out); + else + RegisterFile.updateRegister(operands[0], out); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FENCE.java b/src/rars/riscv/instructions/FENCE.java index e5324a6c..a15cf3b2 100644 --- a/src/rars/riscv/instructions/FENCE.java +++ b/src/rars/riscv/instructions/FENCE.java @@ -39,5 +39,6 @@ public FENCE() { public void simulate(ProgramStatement statement) { // Do nothing, currently there are no other threads so local consitency is enough + // TODO idk what to do for now but something will need to be implemented, maybe with a global variable? } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FEQD.java b/src/rars/riscv/instructions/FEQD.java index ead483a2..d54b7c5c 100644 --- a/src/rars/riscv/instructions/FEQD.java +++ b/src/rars/riscv/instructions/FEQD.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Comparisons; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.riscv.BasicInstruction; @@ -15,10 +16,14 @@ public FEQD() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Float64 f1 = Double.getDouble(operands[1]), f2 = Double.getDouble(operands[2]); Environment e = new Environment(); - boolean result = jsoftfloat.operations.Comparisons.compareQuietEqual(f1,f2,e); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0], result ? 1 : 0); + boolean result = Comparisons.compareQuietEqual(f1,f2,e); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], result ? 1 : 0); + else + RegisterFile.updateRegister(operands[0], result ? 1 : 0, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FEQS.java b/src/rars/riscv/instructions/FEQS.java index 5c7f71d3..473d0a2f 100644 --- a/src/rars/riscv/instructions/FEQS.java +++ b/src/rars/riscv/instructions/FEQS.java @@ -1,10 +1,9 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Comparisons; import jsoftfloat.types.Float32; import rars.ProgramStatement; -import rars.riscv.hardware.ControlAndStatusRegisterFile; -import rars.riscv.hardware.FloatingPointRegisterFile; import rars.riscv.hardware.RegisterFile; import rars.riscv.BasicInstruction; import rars.riscv.BasicInstructionFormat; @@ -44,10 +43,14 @@ public FEQS() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Float32 f1 = Floating.getFloat(operands[1]), f2 = Floating.getFloat(operands[2]); Environment e = new Environment(); - boolean result = jsoftfloat.operations.Comparisons.compareQuietEqual(f1,f2,e); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0], result ? 1 : 0); + boolean result = Comparisons.compareQuietEqual(f1,f2,e); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], result ? 1 : 0); + else + RegisterFile.updateRegister(operands[0], result ? 1 : 0, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FLD.java b/src/rars/riscv/instructions/FLD.java index cbe27744..84aec4ba 100644 --- a/src/rars/riscv/instructions/FLD.java +++ b/src/rars/riscv/instructions/FLD.java @@ -17,13 +17,21 @@ public FLD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); operands[1] = (operands[1] << 20) >> 20; try { - long low = Globals.memory.getWord(RegisterFile.getValue(operands[2]) + operands[1]); - long high = Globals.memory.getWord(RegisterFile.getValue(operands[2]) + operands[1]+4); - FloatingPointRegisterFile.updateRegisterLong(operands[0], (high << 32) | (low & 0xFFFFFFFFL)); + long low = Globals.memory.getWord(((hart == -1) + ? RegisterFile.getValue(operands[2]) + : RegisterFile.getValue(operands[2])) + operands[1]); + long high = Globals.memory.getWord(((hart == -1) + ? RegisterFile.getValue(operands[2]) + : RegisterFile.getValue(operands[2])) + operands[1] + 4); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], (high << 32) | (low & 0xFFFFFFFFL)); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], (high << 32) | (low & 0xFFFFFFFFL), hart); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FLED.java b/src/rars/riscv/instructions/FLED.java index 25af82ab..b0d9039c 100644 --- a/src/rars/riscv/instructions/FLED.java +++ b/src/rars/riscv/instructions/FLED.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Comparisons; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.riscv.BasicInstruction; @@ -15,10 +16,14 @@ public FLED() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Float64 f1 = Double.getDouble(operands[1]), f2 = Double.getDouble(operands[2]); Environment e = new Environment(); - boolean result = jsoftfloat.operations.Comparisons.compareSignalingLessThanEqual(f1,f2,e); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0], result ? 1 : 0); + boolean result = Comparisons.compareSignalingLessThanEqual(f1,f2,e); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], result ? 1 : 0); + else + RegisterFile.updateRegister(operands[0], result ? 1 : 0, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FLES.java b/src/rars/riscv/instructions/FLES.java index f0404acf..e8c775b4 100644 --- a/src/rars/riscv/instructions/FLES.java +++ b/src/rars/riscv/instructions/FLES.java @@ -1,10 +1,9 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Comparisons; import jsoftfloat.types.Float32; import rars.ProgramStatement; -import rars.riscv.hardware.ControlAndStatusRegisterFile; -import rars.riscv.hardware.FloatingPointRegisterFile; import rars.riscv.hardware.RegisterFile; import rars.riscv.BasicInstruction; import rars.riscv.BasicInstructionFormat; @@ -44,10 +43,14 @@ public FLES() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Float32 f1 = Floating.getFloat(operands[1]), f2 = Floating.getFloat(operands[2]); Environment e = new Environment(); - boolean result = jsoftfloat.operations.Comparisons.compareSignalingLessThanEqual(f1,f2,e); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0], result ? 1 : 0); + boolean result = Comparisons.compareSignalingLessThanEqual(f1,f2,e); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], result ? 1 : 0); + else + RegisterFile.updateRegister(operands[0], result ? 1 : 0, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FLTD.java b/src/rars/riscv/instructions/FLTD.java index 0d4709f4..e9f406bf 100644 --- a/src/rars/riscv/instructions/FLTD.java +++ b/src/rars/riscv/instructions/FLTD.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Comparisons; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.riscv.BasicInstruction; @@ -15,10 +16,14 @@ public FLTD() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Float64 f1 = Double.getDouble(operands[1]), f2 = Double.getDouble(operands[2]); Environment e = new Environment(); - boolean result = jsoftfloat.operations.Comparisons.compareSignalingLessThan(f1,f2,e); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0], result ? 1 : 0); + boolean result = Comparisons.compareSignalingLessThan(f1,f2,e); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], result ? 1 : 0); + else + RegisterFile.updateRegister(operands[0], result ? 1 : 0, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FLTS.java b/src/rars/riscv/instructions/FLTS.java index b979eb53..b2f8a970 100644 --- a/src/rars/riscv/instructions/FLTS.java +++ b/src/rars/riscv/instructions/FLTS.java @@ -1,10 +1,9 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Comparisons; import jsoftfloat.types.Float32; import rars.ProgramStatement; -import rars.riscv.hardware.ControlAndStatusRegisterFile; -import rars.riscv.hardware.FloatingPointRegisterFile; import rars.riscv.hardware.RegisterFile; import rars.riscv.BasicInstruction; import rars.riscv.BasicInstructionFormat; @@ -44,10 +43,14 @@ public FLTS() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Float32 f1 = Floating.getFloat(operands[1]), f2 = Floating.getFloat(operands[2]); Environment e = new Environment(); - boolean result = jsoftfloat.operations.Comparisons.compareSignalingLessThan(f1,f2,e); - Floating.setfflags(e); - RegisterFile.updateRegister(operands[0], result ? 1 : 0); + boolean result = Comparisons.compareSignalingLessThan(f1,f2,e); + Floating.setfflags(e, hart); + if (hart == -1) + RegisterFile.updateRegister(operands[0], result ? 1 : 0); + else + RegisterFile.updateRegister(operands[0], result ? 1 : 0, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FLW.java b/src/rars/riscv/instructions/FLW.java index 76565885..4d41f462 100644 --- a/src/rars/riscv/instructions/FLW.java +++ b/src/rars/riscv/instructions/FLW.java @@ -44,11 +44,18 @@ public FLW() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); operands[1] = (operands[1] << 20) >> 20; try { - FloatingPointRegisterFile.updateRegister(operands[0], Globals.memory.getWord(RegisterFile.getValue(operands[2]) + operands[1])); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], + Globals.memory.getWord(RegisterFile.getValue(operands[2]) + operands[1])); + else + FloatingPointRegisterFile.updateRegister(operands[0], + Globals.memory.getWord(RegisterFile.getValue(operands[2], hart) + operands[1]), + hart); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FMVDX.java b/src/rars/riscv/instructions/FMVDX.java index 8f45800c..f4957922 100644 --- a/src/rars/riscv/instructions/FMVDX.java +++ b/src/rars/riscv/instructions/FMVDX.java @@ -14,6 +14,12 @@ public FMVDX() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - FloatingPointRegisterFile.updateRegisterLong(operands[0], RegisterFile.getValueLong(operands[1])); + int hart = statement.getCurrentHart(); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], + RegisterFile.getValueLong(operands[1])); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], + RegisterFile.getValueLong(operands[1], hart), hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FMVSX.java b/src/rars/riscv/instructions/FMVSX.java index 7670a204..18bcb123 100644 --- a/src/rars/riscv/instructions/FMVSX.java +++ b/src/rars/riscv/instructions/FMVSX.java @@ -41,6 +41,12 @@ public FMVSX() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - FloatingPointRegisterFile.updateRegister(operands[0], RegisterFile.getValue(operands[1])); + int hart = statement.getCurrentHart(); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], + RegisterFile.getValue(operands[1])); + else + FloatingPointRegisterFile.updateRegister(operands[0], + RegisterFile.getValue(operands[1], hart), hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FMVXD.java b/src/rars/riscv/instructions/FMVXD.java index 7d0b1c3f..ebccb65e 100644 --- a/src/rars/riscv/instructions/FMVXD.java +++ b/src/rars/riscv/instructions/FMVXD.java @@ -14,6 +14,12 @@ public FMVXD() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - RegisterFile.updateRegister(operands[0], FloatingPointRegisterFile.getValueLong(operands[1])); + int hart = statement.getCurrentHart(); + if (hart == -1) + RegisterFile.updateRegister(operands[0], + FloatingPointRegisterFile.getValueLong(operands[1])); + else + RegisterFile.updateRegister(operands[0], + FloatingPointRegisterFile.getValueLong(operands[1], hart), hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FMVXS.java b/src/rars/riscv/instructions/FMVXS.java index 095f34e5..056d66fd 100644 --- a/src/rars/riscv/instructions/FMVXS.java +++ b/src/rars/riscv/instructions/FMVXS.java @@ -41,6 +41,12 @@ public FMVXS() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - RegisterFile.updateRegister(operands[0], (int)FloatingPointRegisterFile.getValueLong(operands[1])); + int hart = statement.getCurrentHart(); + if (hart == -1) + RegisterFile.updateRegister(operands[0], + (int) FloatingPointRegisterFile.getValueLong(operands[1])); + else + RegisterFile.updateRegister(operands[0], + (int) FloatingPointRegisterFile.getValueLong(operands[1], hart), hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSD.java b/src/rars/riscv/instructions/FSD.java index 686f6712..c72042f5 100644 --- a/src/rars/riscv/instructions/FSD.java +++ b/src/rars/riscv/instructions/FSD.java @@ -17,11 +17,17 @@ public FSD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); operands[1] = (operands[1] << 20) >> 20; try { - Globals.memory.setDoubleWord(RegisterFile.getValue(operands[2]) + operands[1], FloatingPointRegisterFile.getValueLong(operands[0])); + Globals.memory.setDoubleWord(((hart == -1) + ? RegisterFile.getValue(operands[2]) + : RegisterFile.getValue(operands[2], hart)) + operands[1], + (hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[0]) + : FloatingPointRegisterFile.getValueLong(operands[0], hart)); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSGNJD.java b/src/rars/riscv/instructions/FSGNJD.java index 966d372a..35d3b3a3 100644 --- a/src/rars/riscv/instructions/FSGNJD.java +++ b/src/rars/riscv/instructions/FSGNJD.java @@ -13,8 +13,18 @@ public FSGNJD() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - long result = (FloatingPointRegisterFile.getValueLong(operands[1]) & 0x7FFFFFFF_FFFFFFFFL) | - (FloatingPointRegisterFile.getValueLong(operands[2]) & 0x80000000_00000000L); - FloatingPointRegisterFile.updateRegisterLong(operands[0], result); + int hart = statement.getCurrentHart(); + long op1 = (hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart); + long op2 = (hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[2]) + : FloatingPointRegisterFile.getValueLong(operands[2], hart); + long result = (op1 & 0x7FFFFFFF_FFFFFFFFL) | + (op2 & 0x80000000_00000000L); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], result); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], result, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSGNJND.java b/src/rars/riscv/instructions/FSGNJND.java index 7767f246..c6cebbf0 100644 --- a/src/rars/riscv/instructions/FSGNJND.java +++ b/src/rars/riscv/instructions/FSGNJND.java @@ -13,8 +13,18 @@ public FSGNJND() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - long result = (FloatingPointRegisterFile.getValueLong(operands[1]) & 0x7FFFFFFF_FFFFFFFFL) | - ((~FloatingPointRegisterFile.getValueLong(operands[2])) & 0x80000000_00000000L); - FloatingPointRegisterFile.updateRegisterLong(operands[0], result); + int hart = statement.getCurrentHart(); + long op1 = (hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart); + long op2= (hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[2]) + : FloatingPointRegisterFile.getValueLong(operands[2], hart); + long result = (op1 & 0x7FFFFFFF_FFFFFFFFL) | + ((~op2) & 0x80000000_00000000L); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], result); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], result, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSGNJNS.java b/src/rars/riscv/instructions/FSGNJNS.java index e8d3b3c0..0e2ba086 100644 --- a/src/rars/riscv/instructions/FSGNJNS.java +++ b/src/rars/riscv/instructions/FSGNJNS.java @@ -40,7 +40,18 @@ public FSGNJNS() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - int result = (FloatingPointRegisterFile.getValue(operands[1]) & 0x7FFFFFFF) | ((~FloatingPointRegisterFile.getValue(operands[2])) & 0x80000000); - FloatingPointRegisterFile.updateRegister(operands[0], result); + int hart = statement.getCurrentHart(); + int op1 = (hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart); + int op2 = (hart == -1) + ? FloatingPointRegisterFile.getValue(operands[2]) + : FloatingPointRegisterFile.getValue(operands[2], hart); + int result = (op1 & 0x7FFFFFFF) | + ((~op2) & 0x80000000); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], result); + else + FloatingPointRegisterFile.updateRegister(operands[0], result, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSGNJS.java b/src/rars/riscv/instructions/FSGNJS.java index 19cec7c8..f972789f 100644 --- a/src/rars/riscv/instructions/FSGNJS.java +++ b/src/rars/riscv/instructions/FSGNJS.java @@ -40,7 +40,17 @@ public FSGNJS() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - int result = (FloatingPointRegisterFile.getValue(operands[1]) & 0x7FFFFFFF) | (FloatingPointRegisterFile.getValue(operands[2]) & 0x80000000); - FloatingPointRegisterFile.updateRegister(operands[0], result); + int hart = statement.getCurrentHart(); + int op1 = (hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart); + int op2 = (hart == -1) + ? FloatingPointRegisterFile.getValue(operands[2]) + : FloatingPointRegisterFile.getValue(operands[2], hart); + int result = (op1 & 0x7FFFFFFF) | (op2 & 0x80000000); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], result); + else + FloatingPointRegisterFile.updateRegister(operands[0], result, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSGNJXD.java b/src/rars/riscv/instructions/FSGNJXD.java index 01f9b34d..3cc4cf1b 100644 --- a/src/rars/riscv/instructions/FSGNJXD.java +++ b/src/rars/riscv/instructions/FSGNJXD.java @@ -13,8 +13,17 @@ public FSGNJXD() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - long f2 = FloatingPointRegisterFile.getValueLong(operands[1]), f3 = FloatingPointRegisterFile.getValueLong(operands[2]); + int hart = statement.getCurrentHart(); + long f2 = (hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart); + long f3 = (hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[2]) + : FloatingPointRegisterFile.getValueLong(operands[2], hart); long result = (f2 & 0x7FFFFFFF_FFFFFFFFL) | ((f2 ^ f3) & 0x80000000_00000000L); - FloatingPointRegisterFile.updateRegisterLong(operands[0], result); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], result); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], result, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSGNJXS.java b/src/rars/riscv/instructions/FSGNJXS.java index 8f9aae61..86fb3a03 100644 --- a/src/rars/riscv/instructions/FSGNJXS.java +++ b/src/rars/riscv/instructions/FSGNJXS.java @@ -40,8 +40,17 @@ public FSGNJXS() { public void simulate(ProgramStatement statement) { int[] operands = statement.getOperands(); - int f2 = FloatingPointRegisterFile.getValue(operands[1]), f3 = FloatingPointRegisterFile.getValue(operands[2]); + int hart = statement.getCurrentHart(); + int f2 = (hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart); + int f3 = (hart == -1) + ? FloatingPointRegisterFile.getValue(operands[2]) + : FloatingPointRegisterFile.getValue(operands[2], hart); int result = (f2 & 0x7FFFFFFF) | ((f2 ^ f3) & 0x80000000); - FloatingPointRegisterFile.updateRegister(operands[0], result); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], result); + else + FloatingPointRegisterFile.updateRegister(operands[0], result, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSQRTD.java b/src/rars/riscv/instructions/FSQRTD.java index 17b49be0..f497493d 100644 --- a/src/rars/riscv/instructions/FSQRTD.java +++ b/src/rars/riscv/instructions/FSQRTD.java @@ -1,6 +1,7 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Arithmetic; import jsoftfloat.types.Float64; import rars.ProgramStatement; import rars.SimulationException; @@ -16,10 +17,17 @@ public FSQRTD() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float64 result = jsoftfloat.operations.Arithmetic.squareRoot(new Float64(FloatingPointRegisterFile.getValueLong(operands[1])),e); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegisterLong(operands[0],result.bits); + Float64 result = Arithmetic.squareRoot(new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart)), + e); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSQRTS.java b/src/rars/riscv/instructions/FSQRTS.java index 0c889d79..e3311c45 100644 --- a/src/rars/riscv/instructions/FSQRTS.java +++ b/src/rars/riscv/instructions/FSQRTS.java @@ -1,10 +1,10 @@ package rars.riscv.instructions; import jsoftfloat.Environment; +import jsoftfloat.operations.Arithmetic; import jsoftfloat.types.Float32; import rars.ProgramStatement; import rars.SimulationException; -import rars.riscv.hardware.ControlAndStatusRegisterFile; import rars.riscv.hardware.FloatingPointRegisterFile; import rars.riscv.BasicInstruction; import rars.riscv.BasicInstructionFormat; @@ -44,10 +44,17 @@ public FSQRTS() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[2],statement); - Float32 result = jsoftfloat.operations.Arithmetic.squareRoot(new Float32(FloatingPointRegisterFile.getValue(operands[1])),e); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegister(operands[0],result.bits); + Float32 result = Arithmetic.squareRoot(new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart)), + e); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], result.bits); + else + FloatingPointRegisterFile.updateRegister(operands[0], result.bits, hart); } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/FSW.java b/src/rars/riscv/instructions/FSW.java index 3c5cbee3..b5621dfe 100644 --- a/src/rars/riscv/instructions/FSW.java +++ b/src/rars/riscv/instructions/FSW.java @@ -44,11 +44,17 @@ public FSW() { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); operands[1] = (operands[1] << 20) >> 20; try { - Globals.memory.setWord(RegisterFile.getValue(operands[2]) + operands[1], (int)FloatingPointRegisterFile.getValueLong(operands[0])); + Globals.memory.setWord(((hart == -1) + ? RegisterFile.getValue(operands[2]) + : RegisterFile.getValue(operands[2], hart)) + operands[1], + (hart == -1) + ? (int) FloatingPointRegisterFile.getValueLong(operands[0]) + : (int) FloatingPointRegisterFile.getValue(operands[0], hart)); } catch (AddressErrorException e) { throw new SimulationException(statement, e); } } -} \ No newline at end of file +} diff --git a/src/rars/riscv/instructions/Floating.java b/src/rars/riscv/instructions/Floating.java index 5955db2f..3b1c00c5 100644 --- a/src/rars/riscv/instructions/Floating.java +++ b/src/rars/riscv/instructions/Floating.java @@ -52,27 +52,48 @@ protected Floating(String name, String description, String funct) { protected Floating(String name, String description, String funct, String rm) { super(name + " f1, f2, f3", description, BasicInstructionFormat.R_FORMAT, funct + "ttttt sssss " + rm + " fffff 1010011"); } - public void simulate(ProgramStatement statement) throws SimulationException{ + + public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); - e.mode = getRoundingMode(operands[3],statement); - Float32 result = compute(new Float32(FloatingPointRegisterFile.getValue(operands[1])),new Float32(FloatingPointRegisterFile.getValue(operands[2])),e); - setfflags(e); - FloatingPointRegisterFile.updateRegister(operands[0], result.bits); + e.mode = getRoundingMode(operands[3], statement); + Float32 result = compute( + new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart) + ), + new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[2]) + : FloatingPointRegisterFile.getValue(operands[2], hart) + ), + e); + setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegister(operands[0], result.bits); + else + FloatingPointRegisterFile.updateRegister(operands[0], result.bits, hart); } - public static void setfflags(Environment e){ + public static void setfflags(Environment e, int hart){ int fflags =(e.flags.contains(Flags.inexact)?1:0)+ (e.flags.contains(Flags.underflow)?2:0)+ (e.flags.contains(Flags.overflow)?4:0)+ (e.flags.contains(Flags.divByZero)?8:0)+ (e.flags.contains(Flags.invalid)?16:0); - if(fflags != 0) ControlAndStatusRegisterFile.orRegister("fflags",fflags); + if (fflags != 0) + if (hart == -1) + ControlAndStatusRegisterFile.orRegister("fflags", fflags); + else + ControlAndStatusRegisterFile.orRegister("fflags", fflags, hart); } public static RoundingMode getRoundingMode(int RM, ProgramStatement statement) throws SimulationException { int rm = RM; - int frm = ControlAndStatusRegisterFile.getValue("frm"); + int hart = statement.getCurrentHart(); + int frm = (hart == -1) + ? ControlAndStatusRegisterFile.getValue("frm") + : ControlAndStatusRegisterFile.getValue("frm", hart); if (rm == 7) rm = frm; switch (rm){ case 0: // RNE @@ -92,7 +113,11 @@ public static RoundingMode getRoundingMode(int RM, ProgramStatement statement) t public abstract Float32 compute(Float32 f1, Float32 f2, Environment e); - public static Float32 getFloat(int num){ + public static Float32 getFloat(int num) { return new Float32(FloatingPointRegisterFile.getValue(num)); } -} \ No newline at end of file + + public static Float32 getFloat(int num, int hart) { + return new Float32(FloatingPointRegisterFile.getValue(num, hart)); + } +} diff --git a/src/rars/riscv/instructions/FusedDouble.java b/src/rars/riscv/instructions/FusedDouble.java index 78e7f2ff..95aaa3a8 100644 --- a/src/rars/riscv/instructions/FusedDouble.java +++ b/src/rars/riscv/instructions/FusedDouble.java @@ -19,13 +19,24 @@ public FusedDouble(String usage, String description, String op) { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[4],statement); - Float64 result = compute(new Float64(FloatingPointRegisterFile.getValueLong(operands[1])), - new Float64(FloatingPointRegisterFile.getValueLong(operands[2])), - new Float64(FloatingPointRegisterFile.getValueLong(operands[3])),e); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegisterLong(operands[0],result.bits); + Float64 result = compute(new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[1]) + : FloatingPointRegisterFile.getValueLong(operands[1], hart)), + new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[2]) + : FloatingPointRegisterFile.getValueLong(operands[2], hart)), + new Float64((hart == -1) + ? FloatingPointRegisterFile.getValueLong(operands[3]) + : FloatingPointRegisterFile.getValueLong(operands[3], hart)), + e); + Floating.setfflags(e, hart); + if (hart == -1) + FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits, hart); } /** diff --git a/src/rars/riscv/instructions/FusedFloat.java b/src/rars/riscv/instructions/FusedFloat.java index 893ac6d1..0e091d78 100644 --- a/src/rars/riscv/instructions/FusedFloat.java +++ b/src/rars/riscv/instructions/FusedFloat.java @@ -5,7 +5,6 @@ import jsoftfloat.types.Float32; import rars.ProgramStatement; import rars.SimulationException; -import rars.riscv.hardware.ControlAndStatusRegisterFile; import rars.riscv.hardware.FloatingPointRegisterFile; import rars.riscv.BasicInstruction; import rars.riscv.BasicInstructionFormat; @@ -48,13 +47,24 @@ public FusedFloat(String usage, String description, String op) { public void simulate(ProgramStatement statement) throws SimulationException { int[] operands = statement.getOperands(); + int hart = statement.getCurrentHart(); Environment e = new Environment(); e.mode = Floating.getRoundingMode(operands[4],statement); - Float32 result = compute(new Float32(FloatingPointRegisterFile.getValue(operands[1])), - new Float32(FloatingPointRegisterFile.getValue(operands[2])), - new Float32(FloatingPointRegisterFile.getValue(operands[3])),e); - Floating.setfflags(e); - FloatingPointRegisterFile.updateRegister(operands[0],result.bits); + Float32 result = compute(new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[1]) + : FloatingPointRegisterFile.getValue(operands[1], hart)), + new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[2]) + : FloatingPointRegisterFile.getValue(operands[2])), + new Float32((hart == -1) + ? FloatingPointRegisterFile.getValue(operands[3]) + : FloatingPointRegisterFile.getValue(operands[2])), + e); + Floating.setfflags(e, hart); + if (hart == 1) + FloatingPointRegisterFile.updateRegister(operands[0],result.bits); + else + FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits, hart); } public static void flipRounding(Environment e){ diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 9b7c6e04..0b8530c6 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -3,6 +3,7 @@ import rars.Globals; import rars.riscv.hardware.AddressErrorException; import rars.riscv.hardware.ControlAndStatusRegisterFile; +import rars.riscv.hardware.FloatingPointRegisterFile; import rars.riscv.hardware.RegisterFile; import rars.riscv.hardware.ReservationTable.bitWidth; import rars.venus.*; @@ -87,8 +88,8 @@ public boolean isCellEditable(int row, int column) { new ActionListener() { public void actionPerformed(ActionEvent e) { int i = hartWindowSelector.getSelectedIndex(); - hartWindows = Globals.getHartWindows(); Globals.setHartWindows(); + hartWindows = Globals.getHartWindows(); if (i == 0) return; else @@ -125,6 +126,7 @@ public void actionPerformed(ActionEvent e) { RegisterFile.initGRegisterBlock(); RegisterFile.initProgramCounter(); ControlAndStatusRegisterFile.changeHarts(1); + FloatingPointRegisterFile.increaseHarts(); action(); }); btnMinus.addActionListener(l -> { @@ -133,6 +135,13 @@ public void actionPerformed(ActionEvent e) { RegisterFile.initGRegisterBlock(); RegisterFile.initProgramCounter(); ControlAndStatusRegisterFile.changeHarts(-1); + FloatingPointRegisterFile.decreaseHarts(); + try { + Globals + .getHartWindows() + .remove(Globals.getHarts() - 1) + .dispose(); + } catch (IndexOutOfBoundsException e) {} action(); }); displayOptions.add(Box.createHorizontalGlue()); diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index bf2e5881..68610cde 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -59,6 +59,7 @@ public class GeneralVenusUI extends JFrame { private JButton Run, Reset, Step, Backstep, Stop, Pause; private Action runGoAction, runStepAction, runBackstepAction, runResetAction, runStopAction, runPauseAction; + private final int hart; // PLEASE PUT THESE TWO (& THEIR METHODS) SOMEWHERE THEY BELONG, NOT HERE private boolean reset = true; // registers/memory reset for execution @@ -71,9 +72,11 @@ public class GeneralVenusUI extends JFrame { **/ // TODO check for mem observer - public GeneralVenusUI(String s) { - super(s); + public GeneralVenusUI(int hart) { + super(String.format("Hart %d", hart)); mainUI = this; + this.hart = hart; + this.createActionObjects(); VenusUI.observers.add(this); double screenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); double screenHeight = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); @@ -107,13 +110,13 @@ public GeneralVenusUI(String s) { // roughly in bottom-up order; some are created in component constructors and thus are // not visible here. - registersTab = new RegistersWindow(s.charAt(s.length()-1) - '1'); - fpTab = new FloatingPointWindow(); - csrTab = new ControlAndStatusWindow(s.charAt(s.length() - 1) - '1'); + registersTab = new RegistersWindow(hart); + fpTab = new FloatingPointWindow(hart); + csrTab = new ControlAndStatusWindow(hart); registersPane = new GeneralRegistersPane(mainUI, registersTab, fpTab, csrTab); registersPane.setPreferredSize(registersPanePreferredSize); - mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab, s.charAt(s.length()-1) - '1'); + mainPane = new GeneralMainPane(mainUI, registersTab, fpTab, csrTab, hart); mainPane.setPreferredSize(mainPanePreferredSize); try { mainPane.getExecutePane().getTextSegmentWindow().setMaximum(true); @@ -126,7 +129,6 @@ public GeneralVenusUI(String s) { horizonSplitter.setOneTouchExpandable(true); horizonSplitter.resetToPreferredSizes(); - this.createActionObjects(); toolbar = this.setUpToolBar(); JPanel jp = new JPanel(new FlowLayout(FlowLayout.LEFT)); diff --git a/src/rars/venus/registers/ControlAndStatusWindow.java b/src/rars/venus/registers/ControlAndStatusWindow.java index 5f849c1d..da1aeae0 100644 --- a/src/rars/venus/registers/ControlAndStatusWindow.java +++ b/src/rars/venus/registers/ControlAndStatusWindow.java @@ -54,10 +54,11 @@ protected String formatRegister(Register value, int base) { protected void beginObserving() { ControlAndStatusRegisterFile.addRegistersObserver(this); } + protected void beginObserving(int hart) { ControlAndStatusRegisterFile.addRegistersObserver(this); } - + protected void endObserving() { ControlAndStatusRegisterFile.deleteRegistersObserver(this); } diff --git a/src/rars/venus/registers/FloatingPointWindow.java b/src/rars/venus/registers/FloatingPointWindow.java index 01af2972..81282136 100644 --- a/src/rars/venus/registers/FloatingPointWindow.java +++ b/src/rars/venus/registers/FloatingPointWindow.java @@ -42,9 +42,16 @@ public class FloatingPointWindow extends RegisterBlockWindow { /* ft10 */ "floating point temporary", /* ft11 */ "floating point temporary" }; + private final int hart; public FloatingPointWindow() { super(FloatingPointRegisterFile.getRegisters(), regToolTips, "32-bit single precision IEEE 754 floating point"); + this.hart = -1; + } + + public FloatingPointWindow(int hart) { + super(FloatingPointRegisterFile.getRegisters(hart), regToolTips, "32-bit single precision IEEE 754 floating point", hart); + this.hart = hart; } protected String formatRegister(Register value, int base) { @@ -59,9 +66,11 @@ protected String formatRegister(Register value, int base) { protected void beginObserving() { FloatingPointRegisterFile.addRegistersObserver(this); } + protected void beginObserving(int hart) { FloatingPointRegisterFile.addRegistersObserver(this); } + protected void endObserving() { FloatingPointRegisterFile.deleteRegistersObserver(this); } From 0b3453d7025456ec4c3ee39794b00d7b9f1d69dc Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Tue, 17 Aug 2021 13:00:58 -0600 Subject: [PATCH 73/84] fix negative references on secondary harts --- src/rars/riscv/hardware/RegisterFile.java | 1 + src/rars/riscv/instructions/FusedFloat.java | 2 +- src/rars/riscv/instructions/JAL.java | 4 ++-- src/rars/riscv/instructions/SCW.java | 4 ++-- src/rars/simulator/Simulator.java | 4 +--- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index 5cc0949a..b636e879 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -187,6 +187,7 @@ public static int getValue(int num) { return (int) instance.getValue(num); } + public static int getValue(int num, int hart) { return (int) gInstance.get(hart).getValue(num); } diff --git a/src/rars/riscv/instructions/FusedFloat.java b/src/rars/riscv/instructions/FusedFloat.java index 0e091d78..a026aa31 100644 --- a/src/rars/riscv/instructions/FusedFloat.java +++ b/src/rars/riscv/instructions/FusedFloat.java @@ -61,7 +61,7 @@ public void simulate(ProgramStatement statement) throws SimulationException { : FloatingPointRegisterFile.getValue(operands[2])), e); Floating.setfflags(e, hart); - if (hart == 1) + if (hart == -1) FloatingPointRegisterFile.updateRegister(operands[0],result.bits); else FloatingPointRegisterFile.updateRegisterLong(operands[0], result.bits, hart); diff --git a/src/rars/riscv/instructions/JAL.java b/src/rars/riscv/instructions/JAL.java index d633726e..969e2f0e 100644 --- a/src/rars/riscv/instructions/JAL.java +++ b/src/rars/riscv/instructions/JAL.java @@ -45,10 +45,10 @@ public void simulate(ProgramStatement statement) { int hart = statement.getCurrentHart(); if (hart >= 0) { InstructionSet.processReturnAddress(operands[0], hart); - InstructionSet.processJump(RegisterFile.getProgramCounter(hart) - Instruction.INSTRUCTION_LENGTH + operands[1]); + InstructionSet.processJump(RegisterFile.getProgramCounter(hart) - Instruction.INSTRUCTION_LENGTH + operands[1], hart); return; } InstructionSet.processReturnAddress(operands[0]); - InstructionSet.processJump(RegisterFile.getProgramCounter() - Instruction.INSTRUCTION_LENGTH + operands[1], hart); + InstructionSet.processJump(RegisterFile.getProgramCounter() - Instruction.INSTRUCTION_LENGTH + operands[1]); } } diff --git a/src/rars/riscv/instructions/SCW.java b/src/rars/riscv/instructions/SCW.java index 84a7d80c..0d058d7c 100644 --- a/src/rars/riscv/instructions/SCW.java +++ b/src/rars/riscv/instructions/SCW.java @@ -17,10 +17,10 @@ public void simulate(ProgramStatement statement) throws SimulationException { int hart = statement.getCurrentHart(); try { if (hart == - 1) { - int result = store(RegisterFile.getValue(operands[2], hart), RegisterFile.getValue(operands[1], hart), hart); + int result = store(RegisterFile.getValue(operands[2]), RegisterFile.getValue(operands[1]), hart); RegisterFile.updateRegister(operands[0], result); } else { - int result = store(RegisterFile.getValue(operands[2]), RegisterFile.getValue(operands[1]), hart); + int result = store(RegisterFile.getValue(operands[2], hart), RegisterFile.getValue(operands[1], hart), hart); RegisterFile.updateRegister(operands[0], result, hart); } } catch (AddressErrorException e) { diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index 56b58363..5697e4a6 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -564,9 +564,7 @@ public void run() { // Get instuction try { - statement = (hart == -1) - ? Globals.memory.getStatement(pc) - : Globals.memory.getStatementNoNotify(pc); + statement = Globals.memory.getStatement(pc); if (statement != null) statement.setCurrentHart(hart); } catch (AddressErrorException e) { From 6682000fb936fed301225a9ba738c8429eea79d1 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Fri, 20 Aug 2021 05:16:14 -0600 Subject: [PATCH 74/84] PC register Fix --- src/rars/simulator/Simulator.java | 5 ++++- src/rars/venus/registers/RegisterBlockWindow.java | 2 -- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index 5697e4a6..c8fbb62d 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -474,7 +474,10 @@ public void run() { // the backstep button is not enabled until a "real" instruction is executed. // This is noticeable in stepped mode. // ********************************************************************* - RegisterFile.initializeProgramCounter(pc); + if(hart == -1) + RegisterFile.initializeProgramCounter(pc); + else + RegisterFile.initializeProgramCounter(pc, hart); ProgramStatement statement = null; int steps = 0; boolean ebreak = false, waiting = false; diff --git a/src/rars/venus/registers/RegisterBlockWindow.java b/src/rars/venus/registers/RegisterBlockWindow.java index bcbfcffd..8dfa405a 100644 --- a/src/rars/venus/registers/RegisterBlockWindow.java +++ b/src/rars/venus/registers/RegisterBlockWindow.java @@ -189,7 +189,6 @@ public void updateRegisters(int hart) { * @param register Register object corresponding to row to be selected. */ private void highlightCellForRegister(Register register) { - System.out.println(register.getHart() + " ggg"); for (int i = 0; i < registers.length; i++) { if (registers[i] == register) { this.highlightRow = i; @@ -234,7 +233,6 @@ public void update(Observable observable, Object obj) { if (access.getAccessType() == AccessNotice.WRITE) { // Uses the same highlighting technique as for Text Segment -- see // AddressCellRenderer class in DataSegmentWindow.java. - System.out.println("\nHHHHHHHH " + hart + " " + ((Register) observable).getHart()); this.highlighting = true; this.highlightCellForRegister((Register) observable); } From 5c4f453a95e9c0bc7dc485b30b1a68b61b6d8025 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Tue, 24 Aug 2021 10:53:04 -0600 Subject: [PATCH 75/84] fix (but not completely) highlighting on secondary harts --- src/rars/riscv/instructions/Branch.java | 5 +++-- src/rars/venus/run/RunAssembleAction.java | 2 +- src/rars/venus/run/RunGoAction.java | 2 +- src/rars/venus/run/RunStepAction.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/rars/riscv/instructions/Branch.java b/src/rars/riscv/instructions/Branch.java index 092684a8..f8fb38ee 100644 --- a/src/rars/riscv/instructions/Branch.java +++ b/src/rars/riscv/instructions/Branch.java @@ -48,10 +48,11 @@ public Branch(String usage, String description, String funct) { public void simulate(ProgramStatement statement) { if (willBranch(statement)) { - if (statement.getCurrentHart() == -1) { + int hart = statement.getCurrentHart(); + if (hart == -1) { InstructionSet.processBranch(statement.getOperands()[2]); } else { - InstructionSet.processBranch(statement.getOperands()[2], statement.getCurrentHart()); + InstructionSet.processBranch(statement.getOperands()[2], hart); } } } diff --git a/src/rars/venus/run/RunAssembleAction.java b/src/rars/venus/run/RunAssembleAction.java index 03b6865e..406653a8 100644 --- a/src/rars/venus/run/RunAssembleAction.java +++ b/src/rars/venus/run/RunAssembleAction.java @@ -148,7 +148,7 @@ public void actionPerformed(ActionEvent e) { gexecutePanes.get(i).getTextSegmentWindow().setupTable(); gexecutePanes.get(i).getLabelsWindow().setupTable(); gexecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); - gexecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(); + gexecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(i); } executePane.getTextSegmentWindow().setupTable(); executePane.getDataSegmentWindow().setupTable(); diff --git a/src/rars/venus/run/RunGoAction.java b/src/rars/venus/run/RunGoAction.java index 17b99402..164caabc 100644 --- a/src/rars/venus/run/RunGoAction.java +++ b/src/rars/venus/run/RunGoAction.java @@ -158,7 +158,7 @@ public void paused(boolean done, Simulator.Reason pauseReason, SimulationExcepti executePane.getDataSegmentWindow().updateValues(); for(int i = 0; i < hartWindows.size(); i++){ gexecutePanes.get(i).getTextSegmentWindow().setCodeHighlighting(true); - gexecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(); + gexecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(i); gexecutePanes.get(i).getRegistersWindow().updateRegisters(); gexecutePanes.get(i).getFloatingPointWindow().updateRegisters(); gexecutePanes.get(i).getControlAndStatusWindow().updateRegisters(); diff --git a/src/rars/venus/run/RunStepAction.java b/src/rars/venus/run/RunStepAction.java index 7e67dd0b..161bfbc8 100644 --- a/src/rars/venus/run/RunStepAction.java +++ b/src/rars/venus/run/RunStepAction.java @@ -129,7 +129,7 @@ public void stepped(boolean done, Simulator.Reason reason, SimulationException p } if (!done) { for(int i = 0; i < hartWindows.size(); i++){ - gExecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(); + gExecutePanes.get(i).getTextSegmentWindow().highlightStepAtPC(i); } executePane.getTextSegmentWindow().highlightStepAtPC(); FileStatus.set(FileStatus.RUNNABLE); From b3d1cfd4177cd4e6562f3685c7b349bb21f9799c Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Tue, 24 Aug 2021 12:54:44 -0600 Subject: [PATCH 76/84] set menu state terminated general venus ui --- src/rars/venus/GeneralVenusUI.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index 68610cde..ef68ae21 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -324,6 +324,8 @@ protected void setMenuState() { case FileStatus.RUNNING: setMenuStateRunning(); break; + case FileStatus.TERMINATED: + break; case FileStatus.OPENING:// This is a temporary state. DPS 9-Aug-2011 break; default: From f4c4a7c46f3a79e418950b24cf968c2fd3c1d85b Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Tue, 24 Aug 2021 12:55:36 -0600 Subject: [PATCH 77/84] =?UTF-8?q?Ecall=20Fixed=20=F0=9F=92=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rars/riscv/hardware/RegisterFile.java | 4 +++- src/rars/riscv/hardware/ReservationTables.java | 16 ++++++++++++++++ src/rars/riscv/syscalls/SyscallOpen.java | 14 +++++++++++--- src/rars/riscv/syscalls/SyscallRead.java | 8 ++++---- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index b636e879..8dc0452a 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -175,7 +175,9 @@ public static void updateRegister(int num, long val, int hart) { public static void updateRegister(String name, long val) { updateRegister(instance.getRegister(name).getNumber(), val); } - + public static void updateRegister(String name, long val, int hart) { + updateRegister(gInstance.get(hart).getRegister(name).getNumber(), val, hart); + } /** * Returns the value of the register. * diff --git a/src/rars/riscv/hardware/ReservationTables.java b/src/rars/riscv/hardware/ReservationTables.java index 398b0494..fe6c393b 100644 --- a/src/rars/riscv/hardware/ReservationTables.java +++ b/src/rars/riscv/hardware/ReservationTables.java @@ -1,5 +1,6 @@ package rars.riscv.hardware; +import java.util.ArrayList; import java.util.Collection; import java.util.Observable; import java.util.Observer; @@ -7,6 +8,7 @@ import rars.SimulationException; import rars.riscv.hardware.ReservationTable.bitWidth; +import rars.tools.ReservationTablesTool; /* Copyright (c) 2021, Siva Chowdeswar Nandipati & Giancarlo Pernudi Segura. @@ -37,6 +39,7 @@ public class ReservationTables extends Observable { private ReservationTable[] reservationTables; public int harts; private Collection observables = new Vector<>(); + private static final ArrayList toolObserver = new ArrayList<>(); public ReservationTables(int harts) { this.harts = harts; @@ -56,6 +59,17 @@ public void reserveAddress(int hart, int address, bitWidth width) throws Address throw new AddressErrorException("Reservation address not aligned to word boundary ", SimulationException.LOAD_ADDRESS_MISALIGNED, address); } reservationTables[hart].reserveAddress(address, width); + this.notifyTools(); + } + + public void subscribeTool(ReservationTablesTool tool) { + toolObserver.add(tool); + System.out.println(toolObserver.hashCode()); + } + + public void notifyTools() { + System.out.printf("NOTIFYING %d tools\n", toolObserver.hashCode()); + toolObserver.forEach(t -> t.update()); } public boolean unreserveAddress(int hart, int address, bitWidth width) throws AddressErrorException { @@ -67,8 +81,10 @@ public boolean unreserveAddress(int hart, int address, bitWidth width) throws Ad for (ReservationTable reservationTable : reservationTables) { reservationTable.unreserveAddress(address, width); } + this.notifyTools(); return true; } + this.notifyTools(); return false; } diff --git a/src/rars/riscv/syscalls/SyscallOpen.java b/src/rars/riscv/syscalls/SyscallOpen.java index 8eb50b1a..1bd41b14 100644 --- a/src/rars/riscv/syscalls/SyscallOpen.java +++ b/src/rars/riscv/syscalls/SyscallOpen.java @@ -43,8 +43,16 @@ public SyscallOpen() { } public void simulate(ProgramStatement statement) throws ExitingException { - int retValue = SystemIO.openFile(NullString.get(statement), - RegisterFile.getValue("a1")); - RegisterFile.updateRegister("a0", retValue); // set returned fd value in register + int retValue; + if(statement.getCurrentHart() == -1){ + retValue = SystemIO.openFile(NullString.get(statement), + RegisterFile.getValue("a1")); + RegisterFile.updateRegister("a0", retValue); // set returned fd value in register + return; + } + retValue = SystemIO.openFile(NullString.get(statement), + RegisterFile.getValue("a1", statement.getCurrentHart())); + RegisterFile.updateRegister("a0", (long) retValue, statement.getCurrentHart()); // set returned fd value in register + return; } } \ No newline at end of file diff --git a/src/rars/riscv/syscalls/SyscallRead.java b/src/rars/riscv/syscalls/SyscallRead.java index f2c97642..8fe97087 100644 --- a/src/rars/riscv/syscalls/SyscallRead.java +++ b/src/rars/riscv/syscalls/SyscallRead.java @@ -44,16 +44,16 @@ public SyscallRead() { } public void simulate(ProgramStatement statement) throws ExitingException { - int byteAddress = RegisterFile.getValue("a1"); // destination of characters read from file + int byteAddress = RegisterFile.getValue("a1", statement.getCurrentHart()); // destination of characters read from file int index = 0; - int length = RegisterFile.getValue("a2"); + int length = RegisterFile.getValue("a2", statement.getCurrentHart()); byte myBuffer[] = new byte[length]; // specified length // Call to SystemIO.xxxx.read(xxx,xxx,xxx) returns actual length int retLength = SystemIO.readFromFile( - RegisterFile.getValue("a0"), // fd + RegisterFile.getValue("a0", statement.getCurrentHart()), // fd myBuffer, // buffer length); // length - RegisterFile.updateRegister("a0", retLength); // set returned value in register + RegisterFile.updateRegister("a0", retLength, statement.getCurrentHart()); // set returned value in register // copy bytes from returned buffer into memory try { From e97482d2318f96472a41a2479743aaf24abdeaa9 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Thu, 26 Aug 2021 00:39:44 -0600 Subject: [PATCH 78/84] multithread getting null strings --- src/rars/riscv/syscalls/NullString.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rars/riscv/syscalls/NullString.java b/src/rars/riscv/syscalls/NullString.java index bfd26418..d993ec41 100644 --- a/src/rars/riscv/syscalls/NullString.java +++ b/src/rars/riscv/syscalls/NullString.java @@ -58,7 +58,10 @@ public static String get(ProgramStatement statement) throws ExitingException { * @throws ExitingException if it hits a #AddressErrorException */ public static String get(ProgramStatement statement, String reg) throws ExitingException { - int byteAddress = RegisterFile.getValue(reg); + int hart = statement.getCurrentHart(); + int byteAddress = hart == -1 + ? RegisterFile.getValue(reg) + : RegisterFile.getValue(reg, hart); ArrayList utf8BytesList = new ArrayList<>(); // Need an array to hold bytes try { utf8BytesList.add((byte) Globals.memory.getByte(byteAddress)); From 6818d53ddf2ecc2032e29aba2b55a929b1f438be Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Thu, 26 Aug 2021 00:40:32 -0600 Subject: [PATCH 79/84] fix GeneralVenusUI constructor --- src/rars/venus/GeneralVenusUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rars/venus/GeneralVenusUI.java b/src/rars/venus/GeneralVenusUI.java index ef68ae21..572a838c 100644 --- a/src/rars/venus/GeneralVenusUI.java +++ b/src/rars/venus/GeneralVenusUI.java @@ -73,7 +73,7 @@ public class GeneralVenusUI extends JFrame { // TODO check for mem observer public GeneralVenusUI(int hart) { - super(String.format("Hart %d", hart)); + super(String.format("Hart %d", hart + 1)); mainUI = this; this.hart = hart; this.createActionObjects(); From 7451ae97f66def9385ff04a92f6d0bc1ad8e8ac1 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Thu, 26 Aug 2021 00:41:08 -0600 Subject: [PATCH 80/84] fix reservation table update call --- src/rars/tools/ReservationTablesTool.java | 4 ++++ src/rars/venus/TextSegmentWindow.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rars/tools/ReservationTablesTool.java b/src/rars/tools/ReservationTablesTool.java index 0b8530c6..5f492d39 100644 --- a/src/rars/tools/ReservationTablesTool.java +++ b/src/rars/tools/ReservationTablesTool.java @@ -191,6 +191,10 @@ protected void updateDisplay() { } } + public void update() { + this.updateDisplay(); + } + @Override protected void reset() { Globals.reservationTables.reset(); diff --git a/src/rars/venus/TextSegmentWindow.java b/src/rars/venus/TextSegmentWindow.java index b323cee2..04c940db 100644 --- a/src/rars/venus/TextSegmentWindow.java +++ b/src/rars/venus/TextSegmentWindow.java @@ -806,7 +806,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, Settings settings = Globals.getSettings(); boolean highlighting = textSegment.getCodeHighlighting(); - if (highlighting && textSegment.getIntCodeAddressAtRow(row) == highlightAddress) { + if (highlighting && intAddresses != null && textSegment.getIntCodeAddressAtRow(row) == highlightAddress) { cell.setBackground(settings.getColorSettingByPosition(Settings.TEXTSEGMENT_HIGHLIGHT_BACKGROUND)); cell.setForeground(settings.getColorSettingByPosition(Settings.TEXTSEGMENT_HIGHLIGHT_FOREGROUND)); cell.setFont(settings.getFontByPosition(Settings.TEXTSEGMENT_HIGHLIGHT_FONT)); From 39e59a625f2e98f3ec6665b8ed5acc26749e0f9c Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Thu, 26 Aug 2021 00:41:22 -0600 Subject: [PATCH 81/84] fix syscall open and read multithreading --- src/rars/riscv/syscalls/SyscallOpen.java | 12 ++++++------ src/rars/riscv/syscalls/SyscallRead.java | 22 +++++++++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/rars/riscv/syscalls/SyscallOpen.java b/src/rars/riscv/syscalls/SyscallOpen.java index 1bd41b14..0c444dca 100644 --- a/src/rars/riscv/syscalls/SyscallOpen.java +++ b/src/rars/riscv/syscalls/SyscallOpen.java @@ -43,16 +43,16 @@ public SyscallOpen() { } public void simulate(ProgramStatement statement) throws ExitingException { - int retValue; - if(statement.getCurrentHart() == -1){ - retValue = SystemIO.openFile(NullString.get(statement), + int retValue, hart = statement.getCurrentHart(); + if (hart == -1) { + retValue = SystemIO.openFile(NullString.get(statement), RegisterFile.getValue("a1")); RegisterFile.updateRegister("a0", retValue); // set returned fd value in register return; } retValue = SystemIO.openFile(NullString.get(statement), - RegisterFile.getValue("a1", statement.getCurrentHart())); - RegisterFile.updateRegister("a0", (long) retValue, statement.getCurrentHart()); // set returned fd value in register + RegisterFile.getValue("a1", hart)); + RegisterFile.updateRegister("a0", (long) retValue, hart); // set returned fd value in register return; } -} \ No newline at end of file +} diff --git a/src/rars/riscv/syscalls/SyscallRead.java b/src/rars/riscv/syscalls/SyscallRead.java index 8fe97087..b438641f 100644 --- a/src/rars/riscv/syscalls/SyscallRead.java +++ b/src/rars/riscv/syscalls/SyscallRead.java @@ -44,16 +44,28 @@ public SyscallRead() { } public void simulate(ProgramStatement statement) throws ExitingException { - int byteAddress = RegisterFile.getValue("a1", statement.getCurrentHart()); // destination of characters read from file + int hart = statement.getCurrentHart(); + int byteAddress = hart == -1 + ? RegisterFile.getValue("a1") + : RegisterFile.getValue("a1", hart); // destination of characters read from file int index = 0; - int length = RegisterFile.getValue("a2", statement.getCurrentHart()); + int length = hart == -1 + ? RegisterFile.getValue("a2") + : RegisterFile.getValue("a2", hart); byte myBuffer[] = new byte[length]; // specified length // Call to SystemIO.xxxx.read(xxx,xxx,xxx) returns actual length int retLength = SystemIO.readFromFile( - RegisterFile.getValue("a0", statement.getCurrentHart()), // fd + hart == -1 // fd + ? RegisterFile.getValue("a0") + : RegisterFile.getValue("a0", hart), myBuffer, // buffer length); // length - RegisterFile.updateRegister("a0", retLength, statement.getCurrentHart()); // set returned value in register + // set returned value in register + if (hart == -1) { + RegisterFile.updateRegister("a0", retLength); + } else { + RegisterFile.updateRegister("a0", retLength, hart); + } // copy bytes from returned buffer into memory try { @@ -65,4 +77,4 @@ public void simulate(ProgramStatement statement) throws ExitingException { throw new ExitingException(statement, e); } } -} \ No newline at end of file +} From 2e3a5dbece79f4c426064afc94fde1cd34b968f6 Mon Sep 17 00:00:00 2001 From: Siva Chowdeswar Nandipati Date: Thu, 26 Aug 2021 11:52:28 -0600 Subject: [PATCH 82/84] Sys call Fixes :) --- src/rars/riscv/syscalls/SyscallRead.java | 23 +++++++++++ .../riscv/syscalls/SyscallReadDouble.java | 6 ++- src/rars/riscv/syscalls/SyscallReadFloat.java | 5 ++- .../riscv/syscalls/SyscallReadString.java | 34 +++++++++++++++- src/rars/riscv/syscalls/SyscallSbrk.java | 5 ++- src/rars/riscv/syscalls/SyscallSleep.java | 4 +- src/rars/riscv/syscalls/SyscallTime.java | 10 ++++- src/rars/riscv/syscalls/SyscallWrite.java | 39 ++++++++++++++++--- 8 files changed, 111 insertions(+), 15 deletions(-) diff --git a/src/rars/riscv/syscalls/SyscallRead.java b/src/rars/riscv/syscalls/SyscallRead.java index 8fe97087..279c3886 100644 --- a/src/rars/riscv/syscalls/SyscallRead.java +++ b/src/rars/riscv/syscalls/SyscallRead.java @@ -44,6 +44,29 @@ public SyscallRead() { } public void simulate(ProgramStatement statement) throws ExitingException { + if(statement.getCurrentHart() == -1){ + int byteAddress = RegisterFile.getValue("a1"); // destination of characters read from file + int index = 0; + int length = RegisterFile.getValue("a2"); + byte myBuffer[] = new byte[length]; // specified length + // Call to SystemIO.xxxx.read(xxx,xxx,xxx) returns actual length + int retLength = SystemIO.readFromFile( + RegisterFile.getValue("a0"), // fd + myBuffer, // buffer + length); // length + RegisterFile.updateRegister("a0", retLength); // set returned value in register + + // copy bytes from returned buffer into memory + try { + while (index < retLength) { + Globals.memory.setByte(byteAddress++, + myBuffer[index++]); + } + } catch (AddressErrorException e) { + throw new ExitingException(statement, e); + } + return; + } int byteAddress = RegisterFile.getValue("a1", statement.getCurrentHart()); // destination of characters read from file int index = 0; int length = RegisterFile.getValue("a2", statement.getCurrentHart()); diff --git a/src/rars/riscv/syscalls/SyscallReadDouble.java b/src/rars/riscv/syscalls/SyscallReadDouble.java index d89603f3..8f3495cd 100644 --- a/src/rars/riscv/syscalls/SyscallReadDouble.java +++ b/src/rars/riscv/syscalls/SyscallReadDouble.java @@ -60,7 +60,9 @@ public void simulate(ProgramStatement statement) throws ExitingException { throw new ExitingException(statement, "invalid double input (syscall " + this.getNumber() + ")"); } - - FloatingPointRegisterFile.updateRegisterLong(10, Double.doubleToRawLongBits(doubleValue)); + if(statement.getCurrentHart() == -1) + FloatingPointRegisterFile.updateRegisterLong(10, Double.doubleToRawLongBits(doubleValue)); + else + FloatingPointRegisterFile.updateRegisterLong(10, Double.doubleToRawLongBits(doubleValue), statement.getCurrentHart()); } } \ No newline at end of file diff --git a/src/rars/riscv/syscalls/SyscallReadFloat.java b/src/rars/riscv/syscalls/SyscallReadFloat.java index b73f022b..64a9e040 100644 --- a/src/rars/riscv/syscalls/SyscallReadFloat.java +++ b/src/rars/riscv/syscalls/SyscallReadFloat.java @@ -47,6 +47,9 @@ public void simulate(ProgramStatement statement) throws ExitingException { throw new ExitingException(statement, "invalid float input (syscall " + this.getNumber() + ")"); } - FloatingPointRegisterFile.updateRegister(10, Float.floatToRawIntBits(floatValue)); // TODO: update to string fa0 + if(statement.getCurrentHart() == -1) + FloatingPointRegisterFile.updateRegister(10, Float.floatToRawIntBits(floatValue)); // TODO: update to string fa0 + else + FloatingPointRegisterFile.updateRegister(10, Float.floatToRawIntBits(floatValue), statement.getCurrentHart()); } } \ No newline at end of file diff --git a/src/rars/riscv/syscalls/SyscallReadString.java b/src/rars/riscv/syscalls/SyscallReadString.java index 39acfd3a..9ed44b1f 100644 --- a/src/rars/riscv/syscalls/SyscallReadString.java +++ b/src/rars/riscv/syscalls/SyscallReadString.java @@ -54,9 +54,39 @@ public SyscallReadString() { } public void simulate(ProgramStatement statement) throws ExitingException { + if(statement.getCurrentHart() == -1){ + String inputString = ""; + int buf = RegisterFile.getValue("a0"); // buf addr + int maxLength = RegisterFile.getValue("a1") - 1; + boolean addNullByte = true; + // Guard against negative maxLength. DPS 13-July-2011 + if (maxLength < 0) { + maxLength = 0; + addNullByte = false; + } + inputString = SystemIO.readString(this.getNumber(), maxLength); + + byte[] utf8BytesList = inputString.getBytes(StandardCharsets.UTF_8); + // TODO: allow for utf-8 encoded strings + int stringLength = Math.min(maxLength, utf8BytesList.length); + try { + for (int index = 0; index < stringLength; index++) { + Globals.memory.setByte(buf + index, + utf8BytesList[index]); + } + if (stringLength < maxLength) { + Globals.memory.setByte(buf + stringLength, '\n'); + stringLength++; + } + if (addNullByte) Globals.memory.setByte(buf + stringLength, 0); + } catch (AddressErrorException e) { + throw new ExitingException(statement, e); + } + return; + } String inputString = ""; - int buf = RegisterFile.getValue("a0"); // buf addr - int maxLength = RegisterFile.getValue("a1") - 1; + int buf = RegisterFile.getValue("a0", statement.getCurrentHart());// buf addr + int maxLength = RegisterFile.getValue("a1", statement.getCurrentHart()) - 1; boolean addNullByte = true; // Guard against negative maxLength. DPS 13-July-2011 if (maxLength < 0) { diff --git a/src/rars/riscv/syscalls/SyscallSbrk.java b/src/rars/riscv/syscalls/SyscallSbrk.java index 117274f0..98c81281 100644 --- a/src/rars/riscv/syscalls/SyscallSbrk.java +++ b/src/rars/riscv/syscalls/SyscallSbrk.java @@ -42,7 +42,10 @@ public SyscallSbrk() { public void simulate(ProgramStatement statement) throws ExitingException { try { - RegisterFile.updateRegister("a0", Globals.memory.allocateBytesFromHeap(RegisterFile.getValue("a0"))); + if(statement.getCurrentHart() == -1) + RegisterFile.updateRegister("a0", Globals.memory.allocateBytesFromHeap(RegisterFile.getValue("a0"))); + else + RegisterFile.updateRegister("a0", Globals.memory.allocateBytesFromHeap(RegisterFile.getValue("a0", statement.getCurrentHart())), statement.getCurrentHart()); } catch (IllegalArgumentException iae) { throw new ExitingException(statement, iae.getMessage() + " (syscall " + this.getNumber() + ")"); diff --git a/src/rars/riscv/syscalls/SyscallSleep.java b/src/rars/riscv/syscalls/SyscallSleep.java index 05254aa3..871c2f8f 100644 --- a/src/rars/riscv/syscalls/SyscallSleep.java +++ b/src/rars/riscv/syscalls/SyscallSleep.java @@ -39,7 +39,9 @@ public SyscallSleep() { public void simulate(ProgramStatement statement) { try { - Thread.sleep(RegisterFile.getValue("a0")); // units of milliseconds 1000 millisec = 1 sec. + if(statement.getCurrentHart() == -1) + Thread.sleep(RegisterFile.getValue("a0")); // units of milliseconds 1000 millisec = 1 sec. + Thread.sleep(RegisterFile.getValue("a0", statement.getCurrentHart())); } catch (InterruptedException e) { } } diff --git a/src/rars/riscv/syscalls/SyscallTime.java b/src/rars/riscv/syscalls/SyscallTime.java index 02ed400e..c73e4b1f 100644 --- a/src/rars/riscv/syscalls/SyscallTime.java +++ b/src/rars/riscv/syscalls/SyscallTime.java @@ -39,9 +39,15 @@ public SyscallTime() { } public void simulate(ProgramStatement statement) { + if(statement.getCurrentHart() == -1){ + long value = new java.util.Date().getTime(); + RegisterFile.updateRegister("a0", Binary.lowOrderLongToInt(value)); + RegisterFile.updateRegister("a1", Binary.highOrderLongToInt(value)); + return; + } long value = new java.util.Date().getTime(); - RegisterFile.updateRegister("a0", Binary.lowOrderLongToInt(value)); - RegisterFile.updateRegister("a1", Binary.highOrderLongToInt(value)); + RegisterFile.updateRegister("a0", Binary.lowOrderLongToInt(value), statement.getCurrentHart()); + RegisterFile.updateRegister("a1", Binary.highOrderLongToInt(value), statement.getCurrentHart()); } } \ No newline at end of file diff --git a/src/rars/riscv/syscalls/SyscallWrite.java b/src/rars/riscv/syscalls/SyscallWrite.java index 29fc528f..230cac29 100644 --- a/src/rars/riscv/syscalls/SyscallWrite.java +++ b/src/rars/riscv/syscalls/SyscallWrite.java @@ -50,10 +50,37 @@ public SyscallWrite() { } public void simulate(ProgramStatement statement) throws ExitingException { - int byteAddress = RegisterFile.getValue("a1"); // source of characters to write to file - int reqLength = RegisterFile.getValue("a2"); // user-requested length + if(statement.getCurrentHart() == -1){ + int byteAddress = RegisterFile.getValue("a1"); // source of characters to write to file + int reqLength = RegisterFile.getValue("a2"); // user-requested length + if (reqLength < 0) { + RegisterFile.updateRegister("a0", -1); + return; + } + int index = 0; + byte myBuffer[] = new byte[reqLength]; + try { + byte b = (byte) Globals.memory.getByte(byteAddress); + while (index < reqLength) // Stop at requested length. Null bytes are included. + { + myBuffer[index++] = b; + byteAddress++; + b = (byte) Globals.memory.getByte(byteAddress); + } + } catch (AddressErrorException e) { + throw new ExitingException(statement, e); + } + int retValue = SystemIO.writeToFile( + RegisterFile.getValue("a0"), // fd + myBuffer, // buffer + RegisterFile.getValue("a2")); // length + RegisterFile.updateRegister("a0", retValue); // set returned value in register + return; + } + int byteAddress = RegisterFile.getValue("a1", statement.getCurrentHart()); // source of characters to write to file + int reqLength = RegisterFile.getValue("a2", statement.getCurrentHart()); // user-requested length if (reqLength < 0) { - RegisterFile.updateRegister("a0", -1); + RegisterFile.updateRegister("a0", -1, statement.getCurrentHart()); return; } int index = 0; @@ -70,9 +97,9 @@ public void simulate(ProgramStatement statement) throws ExitingException { throw new ExitingException(statement, e); } int retValue = SystemIO.writeToFile( - RegisterFile.getValue("a0"), // fd + RegisterFile.getValue("a0", statement.getCurrentHart()), // fd myBuffer, // buffer - RegisterFile.getValue("a2")); // length - RegisterFile.updateRegister("a0", retValue); // set returned value in register + RegisterFile.getValue("a2", statement.getCurrentHart())); // length + RegisterFile.updateRegister("a0", retValue, statement.getCurrentHart()); // set returned value in register } } \ No newline at end of file From c8a6dced0c43c2820c20894c6e4ccba721ca4423 Mon Sep 17 00:00:00 2001 From: Giancarlo Pernudi Segura Date: Tue, 31 Aug 2021 00:19:12 -0600 Subject: [PATCH 83/84] fix opening hart 2+ --- src/rars/Globals.java | 5 ++--- src/rars/riscv/hardware/RegisterFile.java | 18 ++++++++---------- src/rars/simulator/Simulator.java | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/rars/Globals.java b/src/rars/Globals.java index c3743e5a..ef8f1bbe 100644 --- a/src/rars/Globals.java +++ b/src/rars/Globals.java @@ -152,10 +152,9 @@ public class Globals { private static ArrayList hartWindows = new ArrayList<>(); - public static void setHartWindows(){ + public static void setHartWindows() { for (int i = 1; i < Globals.getHarts(); i++) { - GeneralVenusUI temp = new GeneralVenusUI(i - 1); - hartWindows.add(temp); + hartWindows.add(new GeneralVenusUI(i - 1)); } } diff --git a/src/rars/riscv/hardware/RegisterFile.java b/src/rars/riscv/hardware/RegisterFile.java index 8dc0452a..ca5aad81 100644 --- a/src/rars/riscv/hardware/RegisterFile.java +++ b/src/rars/riscv/hardware/RegisterFile.java @@ -72,18 +72,16 @@ public class RegisterFile { private static ArrayList gProgramCounter = new ArrayList<>(); public static void initProgramCounter() { - gProgramCounter.clear(); - for (int i = 1; i < Globals.getHarts(); i++) { + for (int i = gProgramCounter.size(); i < Globals.getHarts(); i++) { Register temp = new Register("pc", -1, Memory.textBaseAddress); gProgramCounter.add(temp); } } public static void initGRegisterBlock() { - if (gInstance != null) - return; - gInstance = new ArrayList<>(); - for(int i = 0; i < Globals.getHarts(); i++){ + if (gInstance == null) + gInstance = new ArrayList<>(); + for(int i = gInstance.size(); i < Globals.getHarts(); i++) { RegisterBlock temp = new RegisterBlock('x', new Register[]{ new Register("zero", 0, 0, i), new Register("ra", 1, 0, i), new Register("sp", STACK_POINTER_REGISTER, Memory.stackPointer, i), @@ -102,7 +100,7 @@ public static void initGRegisterBlock() { new Register("s10", 26, 0,i), new Register("s11", 27, 0, i), new Register("t3", 28, 0, i), new Register("t4", 29, 0, i), new Register("t5", 30, 0, i), new Register("t6", 31, 0, i) - }); + }); gInstance.add(temp); } @@ -306,9 +304,9 @@ public static int setProgramCounter(int value) { public static int setProgramCounter(int value, int hart) { int old = (int)gProgramCounter.get(hart).getValue(); gProgramCounter.get(hart).setValue(value); - if (Globals.getSettings().getBackSteppingEnabled()) { - Globals.program.getBackStepper().addPCRestore(old); - } + // if (Globals.getSettings().getBackSteppingEnabled()) { + // Globals.program.getBackStepper().addPCRestore(old); + // } return old; } /** diff --git a/src/rars/simulator/Simulator.java b/src/rars/simulator/Simulator.java index c8fbb62d..8529e5c2 100644 --- a/src/rars/simulator/Simulator.java +++ b/src/rars/simulator/Simulator.java @@ -93,7 +93,7 @@ public static Simulator getInstance(int tempHart) { if (gSimulator == null) { gSimulator = new ArrayList<>(); gSimulatorThread = new ArrayList<>(); - for(int i = 0; i < Globals.getHarts() - 1 ; i++){ + for(int i = 0; i < Globals.getHarts(); i++){ gSimulatorThread.add(null); gSimulator.add(new Simulator(i)); } From 6371a8f32d2f13c778b2cf3cb3d1b75472117d09 Mon Sep 17 00:00:00 2001 From: giancarlopernudisegura Date: Tue, 31 Aug 2021 22:39:04 -0600 Subject: [PATCH 84/84] remove unnecessary syscall import --- src/rars/riscv/syscalls/SyscallInputDialogDouble.java | 1 - src/rars/riscv/syscalls/SyscallMessageDialog.java | 1 - src/rars/riscv/syscalls/SyscallMidiOut.java | 3 --- src/rars/riscv/syscalls/SyscallPrintChar.java | 4 +--- 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/rars/riscv/syscalls/SyscallInputDialogDouble.java b/src/rars/riscv/syscalls/SyscallInputDialogDouble.java index c6c22572..1e393460 100644 --- a/src/rars/riscv/syscalls/SyscallInputDialogDouble.java +++ b/src/rars/riscv/syscalls/SyscallInputDialogDouble.java @@ -8,7 +8,6 @@ import rars.riscv.hardware.RegisterFile; import rars.riscv.AbstractSyscall; -import javax.lang.model.util.ElementScanner14; import javax.swing.*; /* diff --git a/src/rars/riscv/syscalls/SyscallMessageDialog.java b/src/rars/riscv/syscalls/SyscallMessageDialog.java index d5fe1da7..1baacad3 100644 --- a/src/rars/riscv/syscalls/SyscallMessageDialog.java +++ b/src/rars/riscv/syscalls/SyscallMessageDialog.java @@ -5,7 +5,6 @@ import rars.riscv.AbstractSyscall; import rars.riscv.hardware.RegisterFile; -import javax.lang.model.util.ElementScanner14; import javax.swing.*; /* diff --git a/src/rars/riscv/syscalls/SyscallMidiOut.java b/src/rars/riscv/syscalls/SyscallMidiOut.java index 07c920d0..dfd32d3e 100644 --- a/src/rars/riscv/syscalls/SyscallMidiOut.java +++ b/src/rars/riscv/syscalls/SyscallMidiOut.java @@ -1,7 +1,5 @@ package rars.riscv.syscalls; -import javax.lang.model.util.ElementScanner14; - import rars.ProgramStatement; import rars.riscv.AbstractSyscall; import rars.riscv.hardware.RegisterFile; @@ -79,4 +77,3 @@ public void simulate(ProgramStatement statement) { } } - diff --git a/src/rars/riscv/syscalls/SyscallPrintChar.java b/src/rars/riscv/syscalls/SyscallPrintChar.java index 5eb4ca67..03877722 100644 --- a/src/rars/riscv/syscalls/SyscallPrintChar.java +++ b/src/rars/riscv/syscalls/SyscallPrintChar.java @@ -1,7 +1,5 @@ package rars.riscv.syscalls; -import javax.lang.model.util.ElementScanner14; - import rars.ProgramStatement; import rars.riscv.AbstractSyscall; import rars.riscv.hardware.RegisterFile; @@ -50,4 +48,4 @@ public void simulate(ProgramStatement statement) { SystemIO.printString(Character.toString(t)); } -} \ No newline at end of file +}