” 辅导ECS 50编程、 写作ProgrammingECS 50: Programming Assignment #6Spring 2021Contents1 Changelog 12 General Submission Details 13 Grading Breakdown 14 Submitting on Gradescope 25 RV32EM 26 RISC-V Simulator 26.1 Accessing My CSIF Installation of the Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.2 Installing the Simulator Yourself . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Simulator Example Program 38 Relevant I/O Concepts in the Example Code 39 Your Assignment 49.1 Other Notes Regarding Use of the Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 ChangelogYou should always Refer to the latest version of this document. v.1: Initial version. v.2: Removed mention of Windows Subsystem for Linux. To Windows users, Id recommend MobaXTerm.2 General Submission DetailsPartnering on this assignment is prohibited. If you have not already, you should read the section onacademic misconduct in the syllabus.This assignment is due the night of Tuesday, 06/08. Gradescope will say 12:30 AM on Wednesday, 06/09, due to thegrace period (as described in the Syllabus). Be careful about relying on the grace period for extra time; this could be risky.3 Grading BreakdownAs stated in the updated syllabus, this assignment is worth 8% of your final grade.This content is protected and may not be shared, uploaded, or distributed.14 Submitting on GradescopeFiles to submit: main.cYou may be penalized for submitting unnecessary files.There is no autograder for this assignment. You must simply submit your code to Gradescope, and after thedeadline I will grade the submissions. (Make sure your files name is correct!) I will do this on the CSIF, so the CSIF isstill the reference environment.Your output must match mine exactly.5 RV32EMSince you will write C code in this assignment, the exact details on RV32EM are not too important, but I include themhere for your own edification.While introducing RISC-V during lecture, I very briefly talked about different extensions to RISC-V. Such extensionsinclude, for instance, the M extension for multiplication/division instructions and the FD extension for single/double floatingpointinstructions.In this assignment, you will write C code that can be run on a RV32EM processor. The 32 means that the processoris a 32-bit processor instead of a 64-bit processor, so addresses are 32 bits. The M refers to the M extension mentionedearlier. The E refers to the E extension, which helps to support low-end cores / embedded systems. Low-end cores arecheap; consequently, an RV32EM processor only has 16 registers, x0 through x15. (Where applicable, registers still maintaintheir special meaning. For instance, x0 is still hard-wired to always be zero, and x2 is the stack pointer.)6 RISC-V SimulatorIn this assignment, you will use Professor Chris Nittas RISC-V simulator that can be found here. You should skim thereadme to get a glance at what youll be dealing with.There are two ways that you can use the simulator, and I talk about both ways below. The first way should be mucheasier than the second way. Accessing my CSIF installation of the simulator. Installing the simulator yourself.6.1 Accessing My CSIF Installation of the SimulatorNote on ssh Command: Since the simulator is a graphical application, you will need to enable something called X11forwarding. I have personally confirmed that on a Linux machine and on a Windows machine (with a Linux command linelike MobaXTerm), this can be done by using the -X flag1in the ssh command that you use for logging on to the CSIF. Iimagine it would be similar on a Mac. I dont know how to enable X11 forwarding on Putty on Windows; to Windows users,I would recommend MobaXTerm.Running the Simulator: I have already installed the simulator in my CSIF files. You can run the simulator with thefollowing command2.1 / home / aaron123 / riscv – console / runsim . shThis will open the simulator. You can run the simulator as a background task (with ) if you want to continue using thesame terminal that you used to open the simulator.At this point, you can follow along with Professor Nittas example here. Note the following: Ignore launching the simulator with /code/runsim.sh. Presumably, the example files will not be in the same place on your end that they are in his walkthrough. You can findthe example files here or on Canvas in the riscv-example folder. (I included a zipped version too, in case its convenient.)1Someone once mentioned to me the -Y flag as an alternative; Ive never tried this flag.2Note that if you copy-and-paste the below line from this PDF, there may be unexpected spaces or strange characters in the result, as thistends to occur when one copies-and-pastes from a PDF.2As stated in Professor Nittas documentation for the simulator, you can use the -d flag to enable debug mode; just passit as a command-line argument to the script.Regarding compilation (of your code): As mentioned below, you will use a provided makefile in order to compileyour code. You will need to add the path to the RV32EM C compiler (that Ive installed) to your PATH environment variable.You can do that with a line like the below3.1 export PATH = $PATH :/ home / aaron123 / opt / riscv32 / binI believe that you would have to type the above line on the command line each type you log in to the CSIF. If you wantto avoid having to do this, then I would recommend adding the above line to a .bash_aliases file (in your home directory onthe CSIF) and putting the following line in the .bashrc file (that should already be in your home directory on the CSIF):source ~/.bash_aliases. Each time that you open a new session on the CSIF, the .bashrc file will be checked, which in turnmeans that the .bash_aliases file will be checked.6.2 Installing the Simulator YourselfI would not recommend this way. I would recommend using the simulator on the CSIF in order to save yourself time.Follow the directions that Professor Nitta provides here. Expect this process to take a few hours.7 Simulator Example ProgramAs mentioned above, the example code can be found here, and it is also provided on Canvas. These files are describedbelow. You need all of these files for what you are going to be doing in this assignment, because as mentionedbelow you will be modifying main.c. Note, however, that you do not need to understand much of what is inthe files, except for main.c and (maybe4) a bit of whats in src/startup.c. Makefile: for compilation. riscv32-console.ld: linker file that is also for compilation. src/crt0.s: The code in this file helps set up an interrupt handler (and other things). This code contains the _startlabel, which is the true starting point of the program. (Notice that main() is called at the bottom.) src/interrupt.s: This file contains the interrupt handler, which preserves registers, calls another function called c_interrupt_handler() to do most of the work, and returns with mret. (This mret instruction is similar to iret in x86 in that it is an instructionspecifically used for returning from an interrupt handler.) src/main.c: main() is defined here. This is where much of the action occurs; see below for more details. src/startup.c: This file has code for helping with certain things related to I/O and interrupts, including the definitionof the c_interrupt_handler() function that is called by the interrupt handler.You should make sure that you can run the simulator and that you use the example on the simulator as Professor Nittashows in the documentation. The rest of what I say here wont make much sense if you have not even tried the example yetor at least seen what the example is supposed to do.8 Relevant I/O Concepts in the Example CodeAs you know, there are two categories of approaches for interacting with I/O ports:1. The I/O address space approach, which is what x86 does.2. The memory-mapped I/O approach, which is what RISC-V does.In the memory-mapped I/O approach, certain memory addresses correspond to I/O ports. You can find what thoseaddresses are (for Professor Nittas RV32EM simulator) if you look at the documentation here. As an example, accordingto here, the text data of the video controller (controlling what text shows up on the screen) starts at address 500F E80016.This is why you see in the example codes main.c that VIDEO_MEMORY has a starting address of 500F E80016. This address ismapped to the top-left corner of the screen, meaning that if we do VIDEO_MEMORY[0] = a, then a lowercase a will appear atthe top-left of the screen. The following address, 500F E80116, is mapped to the spot immediately to the right of the top-leftcorner, and so on for 500F E80216. You should be able to understand how the example code gets Hello, World! to showup on the screen.As stated here, the screen is 64 x 36 characters.3See my earlier footnote about what can go wrong if you copy-and-paste from a PDF.4i.e. insofar as it is relevant to the final exam concepts3The example code uses an infinite loop, since theres no reason for the program to end. Within that infinite loop, somestuff is done with the global and last_global variables in order to prevent the example from being overly responsive to inputs.Once we check the value of controller_status, things become interesting again. Here, we are checking if any button hasbeen pressed. This is done by checking the multi-button controller status register5, which as stated here can be accessedby reading the value that is at address 4000001816. The code in startup.c set things up so that reading the controller_statusvariable will get whats at address 4000001816. When you read from the multi-button controller status register, you get a4-byte value in which certain bits have special meaning. You can read more here. As examples of how to interpret the bits,you can check if the left direction button is pressed by checking if bit #0 is set, and you can check if the up direction buttonis pressed by checking if bit #1 is set. You should be able to understand how the buttons are checked in main.c.For More Information: There are many other concepts related to RISC-Vs handling of I/O and interrupts that we willnot go into here. If you want more information, you may find Chapter 10 of The RISC-V Reader: An Open ArchitectureAtlas by David Patterson and Andrew Waterman to be useful.9 Your AssignmentFor this assignment, you must make the following modifications to main.c: No longer print Hello, World!. The top row and bottom row of the screen should be equal signs. The left and right columns of the screen should be vertical bars. The user (the X) should no longer be allowed to move to the top row, bottom row, left column, or right column. The users icon (the X) should start at the top-left most point that it is allowed to be at. Any other spot on the screen should contain a . at the start. When the user moves, the user should consume/remove any . that are touched. Instead of moving with the WASD keys/buttons, the user should now move with the UIJK keys/buttons. Specifically: U button: leftward movement. J button: downward movement. K button: rightward movement. I button: upward movement.Below is an example of what compilation looks like. You do not need to do the export line each time, just once per CSIFsession. (If you dont do it, then you should get a compiler error message complaining that riscv32-unknown-elf-gcc does notexist.)1 $ ls2 Makefile riscv32 – console . ld src3 $ ls src4 crt0 .s interrupt . s main .c startup .c5 $ export PATH = $PATH :/ Home / aaron123 / opt / riscv32 / bin6 $ make7 mkdir -p ./ obj8 mkdir -p ./ bin9 riscv32 – unknown – elf – gcc -O0 -g – ggdb – ffreestanding – nostartfiles – nostdlib – nodefaultlibs – DDEBUG -I ./include -c src / main .c -o obj / main . o10 riscv32 – unknown – elf – gcc -O0 -g – ggdb – ffreestanding – nostartfiles – nostdlib – nodefaultlibs – DDEBUG -I ./include -c src / crt0 .s -o obj / crt0 . o11 riscv32 – unknown – elf – gcc -O0 -g – ggdb – ffreestanding – nostartfiles – nostdlib – nodefaultlibs – DDEBUG -I ./include -c src / interrupt .s -o obj / interrupt .o12 riscv32 – unknown – elf – gcc -O0 -g – ggdb – ffreestanding – nostartfiles – nostdlib – nodefaultlibs – DDEBUG -I ./include -c src / startup .c -o obj / startup .o13 riscv32 – unknown – elf – gcc ./ obj / main .o ./ obj / crt0 .o ./ obj / interrupt . o ./ obj / startup .o -o ./ bin / riscv – console- example -O0 -g – ggdb – ffreestanding – nostartfiles – nostdlib – nodefaultlibs – DDEBUG -Wl , –gc -sections -Wl ,-T , riscv32 – console . ld14 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 – unknown – elf /10.2.0/../../../../ riscv32 – unknown – elf / bin / ld :cannot find default versions of the ISA extension i 15 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 – unknown – elf /10.2.0/../../../../ riscv32 – unknown – elf / bin / ld :cannot find default versions of the ISA extension i 16 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 – unknown – elf /10.2.0/../../../../ riscv32 – unknown – elf / bin / ld :cannot find default versions of the ISA extension i 17 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 – unknown – elf /10.2.0/../../../../ riscv32 – unknown – elf / bin / ld :cannot find default versions of the ISA extension i 18 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 – unknown – elf /10.2.0/../../../../ riscv32 – unknown – elf / bin / ld :cannot find default versions of the ISA extension i 5Do not confuse this kind of register with the kinds of general-purpose registers like a0 and s1 that you can (for the most part) freely accessand use in RISC-V assembly code. Register is a bit of an overloaded term.419 / home / aaron123 / opt / riscv32 / lib / gcc / riscv32 – unknown – elf /10.2.0/../../../../ riscv32 – unknown – elf / bin / ld :cannot find default versions of the ISA extension i 20 riscv32 – unknown – elf – strip ./ bin / riscv – console – example -o ./ bin / riscv – console – example . strip21 $ ls22 bin Makefile obj riscv32 – console . ld src23 $ ls bin24 riscv – console – example riscv – Console – example . stripBelow, I show some screenshots of my running my own solution in the simulator. This image shows what the screen should look like at the start. If I press the K button (or as I prefer k on the keyboard), then the X moves right, consuming any . marksthat are on the way. At this point, pressing i (the I button) does nothing, since I cannot move any further up. Pressing j (the J button) causes the X to move down.5 In the below image, I am as far Down as I can go; pressing j will do nothing. In the below image, I am as far to the right as I can go; pressing k will do nothing.6You should not have to modify the while loop or either of the outermost if statements in main(). As stated previously,you are only submitting main.c, so you should not bother modifying any other file in the setup.9.1 Other Notes Regarding Use of the SimulatorWhen I SSH onto the CSIF from a Ubuntu computer and use the file explorer that pops up when I try to choose firmware,I cannot seem to double-click folders to open them and instead have to click Open at the top right. This is not an issue whenI SSH onto the CSIF from a Windows computer or when I run the simulator directly on my Ubuntu computer. I only pointthis issue out because I think that it could trick students into thinking that their connection to the CSIF suddenly failed orthat theyre having internet issues.In general, I prefer to use the keyboard for pressing the buttons, e.g. pressing u instead of clicking the u button. Ifind that sometimes, when I click the buttons, they get stuck in a pushed position, as if theyre always clicked.Im not quite sure how helpful the debug mode of the simulator will be in this assignment, since you are not writingassembly code. However, I am acquainted With the debug mode, so if you have questions about it, feel free to ask me.请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。