From 559a5c83600a8066f52b56e9f1ab10860955a8d6 Mon Sep 17 00:00:00 2001 From: peteraa Date: Mon, 9 Sep 2019 15:56:18 +0200 Subject: [PATCH 1/7] Fix up deliver script --- deliver.sh | 8 +++++--- exercise.org | 9 +++++++++ src/test/scala/RISCV/Parser.scala | 5 ++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/deliver.sh b/deliver.sh index f64f668..180e209 100755 --- a/deliver.sh +++ b/deliver.sh @@ -3,23 +3,25 @@ read -p "Enter your student username (the one you use on badboard): " username echo "Cleaning your project" -./sbt.sh clean +# ./sbt.sh clean echo "Creating archive" mkdir wrap +mkdir wrap/project cp -r src ./wrap/ cp build.sbt ./wrap cp project/Dependencies.scala ./wrap/project/Dependencies.scala cp project/build.properties ./wrap/project/build.properties cp sbt.sh ./wrap -tar czfv $username.gz wrap +(cd ./wrap/; tar czfv $username.gz .) +mv ./wrap/$username.gz . rm -rf ./wrap echo "Unwrapping and testing your wrapped package" mkdir wrapTest tar -C ./wrapTest -xvf $username.gz -./wrapTest/wrap/sbt.sh test +./wrapTest/sbt.sh test rm -rf ./wrapTest echo "If the test output looked good then you're good to go!" diff --git a/exercise.org b/exercise.org index a5459e3..cd9ebe5 100644 --- a/exercise.org +++ b/exercise.org @@ -22,6 +22,15 @@ Keep in mind that this is just a high level sketch, omitting many details as well entire features (for instance branch logic) + *Important* + When you are done, use the provided ./deliver.sh script to pack up the archive. + If you're unable to run bash scripts then please ensure that you deliver a *zip* archive. + Not .rar or anything else, just use zip because my grading script knows how to handle that + in addition to the one used by deliver.sh + named after your username. Nothing more, nothing less, just your username. + This archive should be runnable as is, thus you need to include all the necessary files. + (I may or may not diff the tests to check if you're screwing with them) + #+CAPTION: A very high level processor schematic. Registers, Instruction and data memory are already implemented. [[./Images/FiveStage.png]] diff --git a/src/test/scala/RISCV/Parser.scala b/src/test/scala/RISCV/Parser.scala index 50da76d..24ded7a 100644 --- a/src/test/scala/RISCV/Parser.scala +++ b/src/test/scala/RISCV/Parser.scala @@ -26,7 +26,7 @@ object Parser { def branchZ : (Parser[Int], Parser[String]) = (reg <~ sep, label) def arith : (Parser[Int], Parser[Int], Parser[Int]) = (reg <~ sep, reg <~ sep, reg) - def arithImm : (Parser[Int], Parser[Int], Parser[Int]) = (reg <~ sep, reg <~ sep, hex | int) + def arithImm : (Parser[Int], Parser[Int], Parser[Int]) = (reg <~ sep, reg <~ sep, (hex | int)) def stringWs(s: String) : Parser[String] = many(whitespace) ~> string(s) <~ many1(whitespace) @@ -144,7 +144,6 @@ object Parser { val multipleInstructions: Parser[List[Op]] = List( - // stringWs("li") ~> (reg <~ sep, (hex | int).map(_.splitLoHi(20))).mapN{ case(rd, (hi, lo)) => { stringWs("li") ~> (reg <~ sep, (hex | int).map(_.splitHiLo(20))).mapN{ case(rd, (hi, lo)) => { say("hello?") List( @@ -155,7 +154,7 @@ object Parser { // NOTE: THESE ARE NOT PSEUDO-OPS IN RISC-V32I! // NOTE: USES A SPECIAL REGISTER // NOTE: PROBABLY BROKEN, NOT EXHAUSTIVELY TESTED!!! - stringWs("lh") ~> (reg <~ sep, int <~ char('('), reg <~ char(')')).mapN{ + stringWs("lh") ~> (reg <~ sep, (hex | int) <~ char('('), reg <~ char(')')).mapN{ case (rd, offset, rs1) if (offset % 4 == 3) => { val placeHolder = if(rd == Reg("a0").value) Reg("a1").value else Reg("a0").value List( From d6a135b206cb33442d40736b248f937f05f3a000 Mon Sep 17 00:00:00 2001 From: peteraa Date: Mon, 9 Sep 2019 19:06:05 +0200 Subject: [PATCH 2/7] Fix li bias for certain integers --- src/test/scala/RISCV/Parser.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/scala/RISCV/Parser.scala b/src/test/scala/RISCV/Parser.scala index 24ded7a..37773d9 100644 --- a/src/test/scala/RISCV/Parser.scala +++ b/src/test/scala/RISCV/Parser.scala @@ -145,10 +145,9 @@ object Parser { val multipleInstructions: Parser[List[Op]] = List( stringWs("li") ~> (reg <~ sep, (hex | int).map(_.splitHiLo(20))).mapN{ case(rd, (hi, lo)) => { - say("hello?") List( ArithImm.add(rd, rd, lo), - LUI(rd, hi), + LUI(rd, if(lo>0) hi else hi+1), )}}.map(_.widen[Op]), // NOTE: THESE ARE NOT PSEUDO-OPS IN RISC-V32I! From 70556c496cdd88f0d0ea18613ec2a6bad1d4ea94 Mon Sep 17 00:00:00 2001 From: peteraa Date: Wed, 11 Sep 2019 17:19:41 +0200 Subject: [PATCH 3/7] Add theory exercises --- theory1.org | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 theory1.org diff --git a/theory1.org b/theory1.org new file mode 100644 index 0000000..7a06ab5 --- /dev/null +++ b/theory1.org @@ -0,0 +1,98 @@ +* Theory question EX1 + + Keep in mind that your design and your implementation are separate entities, + thus you should answer these questions based on your ideal design, not your + finished implementation. Consequently I will not consider your implementation + when grading these questions, thus even with no implementation at all you + should still be able to score 100% on the theory questions. + + All questions can be answered in a few sentences. Remember that brevity is the + soul of wit, and also the key to getting a good score. + +** Question 1 + 2 points. +*** Part 1 + When decoding the BNE branch instruction in the above assembly program + #+begin_src asm + bne x6, x2, "loop", + #+end_src + + In your design, what is the value of each of the control signals below? + + + memToReg + + regWrite + + memRead + + memWrite + + branch + + jump + + Keep in mind that your design and your implementation are separate entities, thus + you should answer this question based on your ideal design, not your finished + implementation. + +*** Part 2 + During execution, at some arbitrary cycle the control signals are: + + + memToReg = 0 + + regWrite = 1 + + memRead = 0 + + memWrite = 0 + + branch = 0 + + jump = 1 + + In your design, which intruction(s) could be executing? + + + Keep in mind that your design and your implementation are separate entities, thus + you should answer this question based on your ideal design, not your finished + implementation. + +** Question 2 + 4 points. + + Reading the binary of a RISC-V program you get the following: + + #+begin_src text + 0x0: 0x00a00293 -- 0000 0000 1010 0000 0000 0010 1001 0011 + 0x4: 0x01400313 -- 0000 0001 0100 0000 0000 0011 0001 0011 + 0x8: 0xfff30313 -- 1111 1111 1111 0011 0000 0011 0001 0011 + 0xc: 0x00628463 -- 0000 0000 0110 0010 1000 0100 0110 0011 + 0x10: 0xff9ff06f -- 1111 1111 1001 1111 1111 0000 0110 1111 + #+end_src + + For each instruction describe the format and name and corresponding RISC-V source + To give you an idea on how decoding would work, here is the decoding of 0x40635293: + + #+begin_src text + 0x40635293 -- 0100 0000 0110 0011 0101 0010 1001 0011 + + Opcode: 0010011 => Format is IType, thus the funct3 field is used to decode further + funct3: 101 => Instruction is of type SRAI, the instruction looks like ~srai rd, rx, imm~ + + rs1: 00110 => x6 + rd: 00101 => x5 + shamt: 000110 => 6 + + Resulting in ~srai x5, x6, 6~ + #+end_src + + *Your answer should be in the form of a simple asm program.* + (hint 1: the original asm program had a label, you need to infer where that label was) + (hint 2: verify your conclusion by assembling your answer) + +** Question 3 + 4 points. + + In order to load a large number LUI and ADDI are used. + consider the following program + #+begin_src asm + li x0, 0xFF + li x1, 0x600 + li x2, 0x8EE + li x3, 0xBABEFACE + li x4, 0xBABE07CE + #+end_src + + a) Which of these instructions will be split into ADDI LUI pairs? + b) Why do the two last instructions need to be handled differently from each other? + (hint: The parser and assembler in the test suite can help you answer this question) From d9a52384338d239a06b3e72af39bebbf4a40f4e9 Mon Sep 17 00:00:00 2001 From: Peter Aaser Date: Thu, 12 Sep 2019 11:31:25 +0200 Subject: [PATCH 4/7] Update deliver.sh --- deliver.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deliver.sh b/deliver.sh index 180e209..83fd85a 100755 --- a/deliver.sh +++ b/deliver.sh @@ -13,14 +13,14 @@ cp build.sbt ./wrap cp project/Dependencies.scala ./wrap/project/Dependencies.scala cp project/build.properties ./wrap/project/build.properties cp sbt.sh ./wrap -(cd ./wrap/; tar czfv $username.gz .) +(cd ./wrap/; tar czfv $username.tar.gz .) mv ./wrap/$username.gz . rm -rf ./wrap echo "Unwrapping and testing your wrapped package" mkdir wrapTest -tar -C ./wrapTest -xvf $username.gz +tar -C ./wrapTest -xvf $username.tar.gz ./wrapTest/sbt.sh test rm -rf ./wrapTest From 3c668fa963eceebb1d74ae239874aebcc1e04163 Mon Sep 17 00:00:00 2001 From: Peter Aaser Date: Tue, 1 Oct 2019 15:06:45 +0200 Subject: [PATCH 5/7] Update testRunner.scala Add enough steps --- src/test/scala/RISCV/testRunner.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/scala/RISCV/testRunner.scala b/src/test/scala/RISCV/testRunner.scala index 0e25da6..8ef1f1f 100644 --- a/src/test/scala/RISCV/testRunner.scala +++ b/src/test/scala/RISCV/testRunner.scala @@ -49,7 +49,7 @@ object TestRunner { binary.toList.sortBy(_._1.value).map(_._2), program.settings, finalVM.pc, - 1500) + 15000) } yield { val traces = mergeTraces(trace, chiselTrace).map(x => printMergedTraces((x), program)) From 626868db89d9959451cb4e1ceab9de46767f75c9 Mon Sep 17 00:00:00 2001 From: Peter Aaser Date: Thu, 3 Oct 2019 11:02:28 +0200 Subject: [PATCH 6/7] Delete arithmetic.s --- src/test/resources/tests/basic/immediate/arithmetic.s | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/test/resources/tests/basic/immediate/arithmetic.s diff --git a/src/test/resources/tests/basic/immediate/arithmetic.s b/src/test/resources/tests/basic/immediate/arithmetic.s deleted file mode 100644 index e69de29..0000000 From da05c8924c484dcaed62b434e25b987a7dadd638 Mon Sep 17 00:00:00 2001 From: Peter Aaser Date: Mon, 7 Oct 2019 17:44:16 +0200 Subject: [PATCH 7/7] Update deliver.sh Fixed oopsie --- deliver.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deliver.sh b/deliver.sh index 83fd85a..5d6deae 100755 --- a/deliver.sh +++ b/deliver.sh @@ -14,7 +14,7 @@ cp project/Dependencies.scala ./wrap/project/Dependencies.scala cp project/build.properties ./wrap/project/build.properties cp sbt.sh ./wrap (cd ./wrap/; tar czfv $username.tar.gz .) -mv ./wrap/$username.gz . +mv ./wrap/$username.tar.gz . rm -rf ./wrap