Acquiring Source Code for PAs
Acquiring Source Code for PAs
Getting Source Code
Go back to the home directory by
cd ~Usually, all works unrelated to system should be performed under the home directory. Other directories under the root of file system (/) are related to system. Therefore, do NOT finish your PAs and Labs under these directories by sudo.
Now acquire source code for PA by the following command:
git clone -b 2017 https://github.com/NJU-ProjectN/ics-pa.git ics2017A directory called ics2017 will be created. This is the project directory for PAs. Details will be explained in PA1.
Issue the following commands to perform git configuration:
git config --global user.name "161220000-Zhang San" # your student ID and name
git config --global user.email "zhangsan@foo.com" # your email
git config --global core.editor vim # your favorite editor
git config --global color.ui trueYou should configure git with your student ID, name, and email. Before continuing, please read this git tutorial to learn some basics of git.
Enter the project directory ics2017, then run
git branch -m master
bash init.shto initialize all the subprojects. This script will pull 4 subprojects from github. We will explain them later. Besides, the script will also add some environment variables into the bash configuration file ~/.bashrc. These variables are defined by absolute path to support the compilation of the subprojects. Therefore, DO NOT move your project to another directory once the initialization finishes, else these variables will become invalid. Particularly, if you use shell other than bash, please set these variables in the corresponding configuration file manually.
Git usage
We will use the branch feature of git to manage the process of development. A branch is an ordered list of commits, where a commit refers to some modifications in the project.
You can list all branches by
You will see there is only one branch called "master" now.
To create a new branch, use git checkout command:
This command will create a branch called pa0, and check out to it. Now list all branches again, and you will see we are now at branch pa0:
From now on, all modifications of files in the project will be recorded in the branch pa0.
Now have a try! Modify the STU_ID variable in nemu/Makefile.git:
Run
to see those files modified from the last commit:
Run
to list modifications from the last commit:
You should see the STU_ID is modified. Now add the changes to commit by git add, and issue git commit:
The git commit command will call the text editor. Type modified my STU_ID in the first line, and keep the remaining contents unchanged. Save and exit the editor, and this finishes a commit. Now you should see a log labeled with your student ID and name by
Now switch back to the master branch by
Open nemu/Makefile.git, and you will find that STU_ID is still unchanged! By issuing git log, you will find that the commit log you just created has disappeared!
Don't worry! This is a feature of branches in git. Modifications in different branches are isolated, which means modifying files in one branch will not affect other branches. Switch back to pa0 branch by
You will find that everything comes back! At the beginning of PA1, you will merge all changes in branch pa0 into master.
The workflow above shows how you will use branch in PAs:
before starting a new PA, new a branch
pa?and check out to itcoding in the branch
pa?(this will introduce lot of modifications)after finish the PA, merge the branch
pa?intomaster, and check out back tomaster
Compiling and Running NEMU
Now enter nemu/ directory, and compile the project by make:
If nothing goes wrong, NEMU will be compiled successfully.
To perform a fresh compilation, type
to remove the old compilation result, then make again.
To run NEMU, type
However, you will see an error message:
This message tells you that the program has triggered an assertion fail at line 21 of the file nemu/src/cpu/reg.c. If you do not know what is assertion, blame the 程序设计基础 course. If you go to see the line 21 of nemu/src/cpu/reg.c, you will discover the failure is in a test function. This failure is expected, because you have not implemented the register structure correctly. Just ignore it now, and you will fix it in PA1.
To debug NEMU with gdb, type
Development Tracing
Once the compilation succeeds, the change of source code will be traced by git. Type
If you see something like
this means the change is traced successfully.
If you see the following message while executing make, this means the tracing fails.
Try to clean the compilation result and compile again:
If the error message above always appears, please contact us as soon as possible.
Local Commit
Although the development tracing system will trace the change of your code after every successful compilation, the trace record is not suitable for your development. This is because the code is still buggy at most of the time. Also, it is not easy for you to identify those bug-free traces. Therefore, you should trace your bug-free code manually.
When you want to commit the change, type
The --allow-empty option is necessary, because usually the change is already committed by development tracing system. Without this option, git will reject no-change commits. If the commit succeeds, you can see a log labeled with your student ID and name by
To filter out the commit logs corresponding to your manual commit, use --author option with git log. For details of how to use this option, RTFM.
Submission
Finally, you should submit your project to the submission website. To submit PA0, put your report file (ONLY .pdf file is accepted) under the project directory.
Then go back to the project directory, issue
This command does 3 things: 1. Cleanup unnecessary files for submission 1. Cleanup unnecessary files in git 1. Create an archive containing the source code and your report. The archive is located in the father directory of the project directory, and it is named by your student ID set in Makefile.
If nothing goes wrong, transfer the archive to your host. Open the archive to double check whether everything is fine. And you can manually submit this archive to the submission website.
RTFSC and Enjoy
If you are new to GNU/Linux and finish this tutorial by yourself, congratulations! You have learn a lot! The most important, you have learn searching the Internet and RTFM for using new tools and trouble-shooting. With these skills, you can solve lots of troubles by yourself during PAs, as well as in the future.
In PA1, the first thing you will do is to RTFSC. If you have troubles during reading the source code, go to RTFM:
If you can not find the definition of a function, it is probably a library function.
Read
manfor more information about that function.If you can not understand the code related to hardware details, refer to the i386 manual.
By the way, you will use C language for programming in all PAs. Here is an excellent tutorial about C language. It contains not only C language (such as how to use printf() and scanf()), but also other elements in a computer system (data structure, computer architecture, assembly language, linking, operating system, network...). It covers most parts of this course. You are strongly recommended to read this tutorial.
Finally, enjoy the journey of PAs, and you will find hardware is not mysterious, so does the computer system! But remember:
The machine is always right.
Every line of untested code is always wrong.
RTFM.
Last updated
Was this helpful?