Acquiring Source Code for PAs
Getting Source Code
Go back to the home directory by
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
使用root账户进行实验, 会改变实验相关文件的权限属性, 可能会导致开发跟踪系统无法正常工作; 更严重的, 你的误操作可能会无意中损坏系统文件, 导致虚拟机/容器无法启动! 往届有若干学长因此而影响了实验进度, 甚至由于损坏了实验相关的文件而影响了分数. 请大家引以为鉴, 不要贪图方便, 否则后果自负!
如果你仍然不理解为什么要这样做, 你可以阅读这个页面: Why is it bad to login as root?
Now acquire source code for PA by the following command:
git clone -b 2018 https://github.com/NJU-ProjectN/ics-pa.git ics2018
A directory called
ics2018 will be created.
This is the project directory for PAs.
Details will be explained in PA1.
Issue the following commands to perform
git config --global user.name "171220000-Zhang San" # your student ID and name git config --global user.email "[email protected]" # your email git config --global core.editor vim # your favorite editor git config --global color.ui true
You should configure
git with your student ID, name, and email.
Before continuing, please read this
git tutorial to learn some basics of
Enter the project directory
ics2018, then run
git branch -m master bash init.sh
to 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
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
please set these variables in the corresponding configuration file manually.
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:
git checkout -b pa0
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
master * pa0
From now on, all modifications of files in the project will be recorded in the branch
Now have a try!
STUNAME variables in
STUID = 171220000 # your student ID STUNAME = 张三 # your Chinese name
to see those files modified from the last commit:
On branch pa0 Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: nemu/Makefile.git no changes added to commit (use "git add" and/or "git commit -a")
to list modifications from the last commit:
diff --git a/nemu/Makefile.git b/nemu/Makefile.git index c9b1708..b7b2e02 100644 --- a/nemu/Makefile.git +++ b/nemu/Makefile.git -STUID = 171220000 -STUNAME = 张三 +STUID = 171221234 +STUNAME = 李四 # DO NOT modify the following code!!!
You should see
STUNAME are modified.
Now add the changes to commit by
git add, and issue
git add . git commit
git commit command will call the text editor.
modified my info 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
git checkout master
nemu/Makefile.git, and you will find that
STUNAME are still unchanged!
git log, you will find that the commit log you just created has disappeared!
Don't worry! This is a feature of branches in
Modifications in different branches are isolated,
which means modifying files in one branch will not affect other branches.
Switch back to
pa0 branch by
git checkout pa0
You will find that everything comes back!
At the beginning of PA1, you will merge all changes in branch
The workflow above shows how you will use branch in PAs:
- before starting a new PA, new a branch
pa?and check out to it
- coding in the branch
pa?(this will introduce lot of modifications)
- after finish the PA, merge the branch
master, and check out back to
Compiling and Running NEMU
nemu/ directory, and compile the project by
If nothing goes wrong, NEMU will be compiled successfully.
你有可能会遇到这个错误信息, 好吧确实是讲义疏忽了. 那就正好当作一个练习吧: 你需要把缺少的工具装上.
You should know how a program is generated in the 程序设计基础 course.
But do you have any idea about what happened when a bunch of information is output to the screen during
make is executed?
To perform a fresh compilation, type
to remove the old compilation result, then
To run NEMU, type
However, you will see an error message:
nemu: nemu/src/cpu/reg.c:21: reg_test: Assertion `(cpu.gpr[check_reg_index(i)]._16) == (sample[i] & 0xffff)' failed.
This message tells you that the program has triggered an assertion fail
at line 21 of the file
If you do not know what is assertion, blame the 程序设计基础 course.
If you go to see the line 21 of
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
Once the compilation succeeds, the change of source code will be traced by
If you see something like
commit 4072d39e5b6c6b6837077f2d673cb0b5014e6ef9 Author: tracer-ics2018 <[email protected]> Date: Sun Jul 26 14:30:31 2018 +0800 compile 171220000 user Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.7-3 i686 GNU/Linux 14:30:31 up 3:44, 2 users, load average: 0.28, 0.09, 0.07 3860572d5cc66412bf85332837c381c5c8c1009f
this means the change is traced successfully.
If you see the following message while executing make, this means the tracing fails.
fatal: Unable to create '/home/user/ics2018/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier. Make sure no other git process is running and remove the file manually to continue.
Try to clean the compilation result and compile again:
make clean make
If the error message above always appears, please contact us as soon as possible.
往届有学长"完成"了某部分实验内容, 但我们找不到相应的git log, 最终该部分内容被视为没有完成.
git log是独立完成实验的最有力证据, 完成了实验内容却缺少合理的git log,
- 请你不定期查看自己的git log, 检查是否与自己的开发过程相符.
- 总是在工程目录下进行开发, 不要在其它地方进行开发, 然后一次性将代码复制到工程目录下, 这样
- 不要删除我们要求创建的分支, 否则会影响我们的脚本运行, 从而影响你的成绩
- 不要清除git log
偶然的跟踪失败不会影响你的成绩. 如果上文中的错误信息总是出现, 请尽快联系我们.
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
git add . git commit --allow-empty
--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
For details about how to use this option, RTFM.
Finally, you should submit your project to the submission website.
To submit PA0, put your report file (ONLY
ics2018 ├── 171220000.pdf # put your report file here ├── init.sh ├── Makefile ├── nanos-lite ├── navy-apps ├── nemu ├── nexus-am └── README.md
Double check whether everything is fine. Then go back to the project directory, issue
This command does 3 things:
- Cleanup unnecessary files for submission
- Cleanup unnecessary files in git
- Download a script from the server and run it to submit everything to the specific website
The script will ask you to enter the task name.
PA0 for this submission.
If everything is fine, the script will output a
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 STFW 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.
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
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:
This ends PA0. And there is no 必答题 in PA0.