Browse Source

Merge branch 'master' of github.com:chyyuu/ucore_lab

main
yuchen 9 years ago
parent
commit
3f271b3a65
9 changed files with 384 additions and 317 deletions
  1. +4
    -0
      .gitignore
  2. +0
    -163
      README-chinese.md
  3. +16
    -11
      README-english.md
  4. +219
    -0
      README.md
  5. +5
    -2
      labcodes_answer/lab1_result/Makefile
  6. +2
    -3
      labcodes_answer/lab1_result/boot/bootmain.c
  7. +3
    -3
      labcodes_answer/lab1_result/kern/init/init.c
  8. +3
    -3
      labcodes_answer/lab1_result/tools/gdbinit

+ 4
- 0
.gitignore View File

@ -7,3 +7,7 @@ cscope.*
ncscope.* ncscope.*
tags tags
*swp *swp
.cproject
.project
*.bak
*.org

+ 0
- 163
README-chinese.md View File

@ -1,163 +0,0 @@
# 介绍(2014)
ucore OS是用于清华大学计算机系本科操作系统课程的OS教学试验内容。
ucore OS起源于MIT CSAIL PDOS课题组开发的xv6&jos、哈佛大学开发的
OS161教学操作系统、以及Linux-2.4内核。
ucore OS中包含的xv6&jos代码版权属于Frans Kaashoek, Robert Morris,
and Russ Cox,使用MIT License。ucore OS中包含的OS/161代码版权属于
David A. Holland。其他代码版权属于陈渝、王乃铮、向勇,并采用GPL License.
ucore OS相关的文档版权属于陈渝、向勇,并采用 Creative Commons
Attribution/Share-Alike (CC-BY-SA) License.
# 开发维护人员
- [陈渝](http://soft.cs.tsinghua.edu.cn/~chen) yuchen AT tsinghua.edu.cn
- 茅俊杰 eternal.n08 AT gmail.com
助教
============
何嘉权
徐永健
王 欢
陈一璋
...
# 课程汇总信息
-[课程汇总](https://github.com/chyyuu/mooc_os)
# 实验内容
1. lab0 : 完成实验环境的搭建,熟悉基本的Linux命令和工具
1. lab1 :启动操作系统
1. lab2 :物理内存管理
1. lab3 :虚拟内存管理
1. lab4 :内核线程
1. lab5 :用户进程
1. lab6 :处理器调度
1. lab7 : 同步互斥
1. lab8 : 文件系统
# 实验环境
ucore OS实验主要在Linux环境下开发。如果你使用的是非Linux环境,则建议参考下面两种方法。
## Windows下基于MingW进行实验
- windows下如何配置ucore实验环境:这种方式不用安装Linux,感谢“下来障”同学提供的[配置教程](http://pan.baidu.com/s/1i3JxZZR)
## Windows下基于VirtualBox or VMWare进行实验
### 1. 安装VirtualBox or VMWare软件
VirtualBox虚拟机软件
https://www.virtualbox.org/
[NOTICE] 也可以安装vmware虚拟机软件
### 2.使用已经预先安装好相关实验环境所需软件的虚拟硬盘
并下载已经安装好ubuntu 14.04 x86-64的虚拟硬盘文件压缩包。
[VirtualBox和虚拟硬盘文件压缩包](http://pan.baidu.com/s/1pJ4XTGZ)
--------------
[NOTICE] 可下载直接使用[同时用于vmware和virtualbox的OVA格式的虚拟硬盘文件mooc-os.ova]( http://pan.baidu.com/s/1gdePM6J)
压缩包可以用[haozip for windows软件](http://www.haozip.com)解压。解压压缩包后,可得到如下内容(大约4GB多)。
```
\mooc-os\mooc-os.vbox
\mooc-os\mooc-os.vbox-prev
\mooc-os\mooc-os.vdi
```
如果此时你已经安装好了VirtualBox,在Windows资源管理器中双击文件“mooc-os.vbox”,
就可以在VirtualBox模拟的x86-64计算机中运行ubuntu 14.04 x86-64,并可以开始学习
ucore OS实验了。
```
用户名是 moocos
口令是 <空格键>
```
## 手动在VirtualBox虚拟机中安装ubuntu 14.04 和实验环境相关软件
(这里假定安装的要是ubuntu14.04 x86-64的系统)
-------------------------------------
1. 在VirtualBox上安装ubuntu
下载ubuntu 14.04 img镜像,并在VirtualBox中安装系统。
建议a: 设置虚拟硬盘的大小为8GB以上,虚拟内存在512MB以上。
建议b: 如果你的机器安装的是32位的windows,则下载32位的ubuntu 14.04 img镜像。
2. 在ubuntu系统中安装实验环境相关软件
在shell(比如gnome-terminal)下可执行如下命令来安装相关软件 (“$”是shell的提示符,不用输入)
```
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential git qemu-system-x86 vim-gnome gdb make diffutils exuberant-ctags tmux openssh-server cscope meld
```
[NOTICE] 最小需要的安装包: build-essential git qemu-system-x86 gdb make diffutils
# 练习步骤
进入VirtualBox中运行的ubuntu,点击左侧的gnome-terminal软件图标,可启动gnome-terminal
软件。在此软件中,执行如下命令:
1. 目前环境中已经有ucore lab源码,可进一步取得最新ucore lab源码
```
$cd moocos/ucore_lab #到ucore lab所在目录
$git pull #取得最新的ucore lab源代码
$cd
```
2. 学习源码
```
$cd labX #X为 1--8
```
3. 阅读,修改源码,可以用understand软件或vim软件
```
$understand
```
4. 修改完毕后,编译实验代码
```
$make
```
5. 如果编译无误,则可以运行测试一下
```
$make qemu
```
6. 可以运行如下命令,看看自己的得分
$make grade
# 相关资料
## 希望了解OS基本概念和原理的同学
. [OS课程资料]( http://pan.baidu.com/s/1bncWxyv)
. [OS MOOC公开课(原理部分)](http://www.topu.com/mooc/4100)
## 希望了解OS设计与实现细节的同学
. [OS实验资料](http://pan.baidu.com/s/1i3vbdXV)
. [OS实验代码](https://github.com/chyyuu/mooc_os_lab)
. [OS MOOC公开课(实验部分)](http://www.topu.com/mooc/4100)
## 希望自己动手实践OS的同学
. ["操作系统简单实现与基本原理 — 基于ucore" (持续更新,变动较大) ](http://chyyuu.gitbooks.io/ucorebook/)
. ["操作系统简单实现与基本原理 — 基于ucore" 配套代码](https://github.com/chyyuu/ucorebook_code)
. [ucore plus 跨硬件平台的ucore OS](https://github.com/chyyuu/ucore_plus)
# UCORERS (代码贡献者)
茅俊杰、陈宇恒、刘聪、杨扬、渠准、任胜伟、朱文雷、
曹正、沈彤、陈旭、蓝昶、方宇剑、韩文涛、张凯成、
S郭晓林、薛天凡、胡刚、刘超、粟裕、袁昕颢...
# NOTICE
如果你发现了问题,有好的建议或意见,请给 yuchen AT tsinghua.edu.cn 发电邮;
如果你完成这8个实验,且对进一步探索、研究、研发操作系统感兴趣,请给 yuchen AT tsinghua.edu.cn 发电邮,欢迎加入我们的OS兴趣小组,共同进步!

README → README-english.md View File

@ -23,7 +23,8 @@ CONTENTS
os course info os course info
---------------- ----------------
[os course summary materials](https://github.com/chyyuu/mooc_os)
* [newest os course summary materials](https://github.com/chyyuu/mooc_os)
* [newest chinese README for ucore_lab](https://github.com/chyyuu/ucore_lab/)
labs info labs info
---------------- ----------------
@ -45,17 +46,17 @@ VirtualBox soft (https://www.virtualbox.org/) and a virtual disk image with all
You can download this virtual disk image -- oslabs_for_student_2012.zip (576.2MB,) from http://pan.baidu.com/share/link?shareid=69868&uk=2585194235, which You can download this virtual disk image -- oslabs_for_student_2012.zip (576.2MB,) from http://pan.baidu.com/share/link?shareid=69868&uk=2585194235, which
is an VirtualBox disk image (contains ubuntu 12.04 and needed softs, and is zipped with zip and xz format), and can be unzipped is an VirtualBox disk image (contains ubuntu 12.04 and needed softs, and is zipped with zip and xz format), and can be unzipped
by haozip software (http://www.haozip.com). by haozip software (http://www.haozip.com).
After unzip oslabs_for_student_2012.zip, you will get
After unzip oslabs_for_student_XXX.zip, you will get
--- ---
C:\vms\ubuntu-12.04.vbox.xz
C:\vms\ubuntu-12.04.vmdk.vmdk.xz
C:\vms\ubuntu-12.04.vmdk-flat.vmdk.xz
C:\vms\ubuntu-14.04.vbox.xz
C:\vms\ubuntu-14.04.vmdk.vmdk.xz
C:\vms\ubuntu-14.04.vmdk-flat.vmdk.xz
--- ---
then you will continue unzip all these files, and get then you will continue unzip all these files, and get
--- ---
C:\vms\ubuntu-12.04.vbox
C:\vms\ubuntu-12.04.vmdk.vmdk
C:\vms\ubuntu-12.04.vmdk-flat.vmdk
C:\vms\ubuntu-14.04.vbox
C:\vms\ubuntu-14.04.vmdk.vmdk
C:\vms\ubuntu-14.04.vmdk-flat.vmdk
--- ---
If you installed VirtualBox soft, then the last step is: double clik file "ubuntu-12.04.vbox" and run ubuntu 12.04 in VirtualBox. If you installed VirtualBox soft, then the last step is: double clik file "ubuntu-12.04.vbox" and run ubuntu 12.04 in VirtualBox.
In ubuntu 12.04 login Interface: In ubuntu 12.04 login Interface:
@ -72,11 +73,11 @@ FEDORA 20: GCC-4.8.2
EXERCISE STEPS EXERCISE STEPS
============== ==============
0 Get the newest os lab src codes/docs.(Insure you can connect to github in ubuntu running on VrtualBox) 0 Get the newest os lab src codes/docs.(Insure you can connect to github in ubuntu running on VrtualBox)
0.1 If you try to get all codes/docs
0.1 If you try to get all codes
$rm -rf ucore_lab $rm -rf ucore_lab
$git clone git://github.com/chyyuu/ucore_lab.git $git clone git://github.com/chyyuu/ucore_lab.git
$cd ucore_lab $cd ucore_lab
0.2 If you gloned ucore_lab and only try to get the updated codes/docs
0.2 If you gloned ucore_lab and only try to get the updated codes
$cd ucore_lab $cd ucore_lab
$git pull $git pull
1 $cd labX 1 $cd labX
@ -88,7 +89,11 @@ EXERCISE STEPS
$make qemu $make qemu
OR OR
$make grade $make grade
6 handin your code
6 debug your code
$make debug
7 handin your code
$make handin $make handin
OPTION OPTION

+ 219
- 0
README.md View File

@ -0,0 +1,219 @@
# 介绍(2015)
ucore OS是用于清华大学计算机系本科操作系统课程的OS教学试验内容。
ucore OS起源于MIT CSAIL PDOS课题组开发的xv6&jos、哈佛大学开发的
OS161教学操作系统、以及Linux-2.4内核。
ucore OS中包含的xv6&jos代码版权属于Frans Kaashoek, Robert Morris,
and Russ Cox,使用MIT License。ucore OS中包含的OS/161代码版权属于
David A. Holland。其他代码版权属于陈渝、王乃铮、向勇,并采用GPL License.
ucore OS相关的文档版权属于陈渝、向勇,并采用 Creative Commons
Attribution/Share-Alike (CC-BY-SA) License.
# 实验总体流程
1. 在[学堂在线](https://www.xuetangx.com/courses/TsinghuaX/30240243X/2015_T1/about)查看OS相关原理和labX的视频;
2. 在[实验指导书 on gitbook](http://objectkuan.gitbooks.io/ucore-docs/)上阅读实验指导书;
3. 在实验环境中完成实验并提交实验到git server(清华学生需要在学校内部的git server上,其他同学可提交在其他git server上);
4. 如实验中碰到问题,在[在线OS课程问题集](http://xuyongjiande.gitbooks.io/os-qa/)查找是否已经有解答;
5. 如没有解答,可在[在线OS课程问答和交流区](https://piazza.com/tsinghua.edu.cn/spring2015/30240243x/home)提问。(QQ群 181873534主要用于OS课程一般性交流);
6. 可进一步在[学堂在线](https://www.xuetangx.com/courses/TsinghuaX/30240243X/2015_T1/about)或[在线的操作系统课程练习题](https://www.gitbook.io/book/xuyongjiande/os_exercises)完成实验相关的练习题;
# 实验内容
## 实验指导书
- [实验指导书 on gitbook](http://objectkuan.gitbooks.io/ucore-docs/)
## 实验题目
1. lab0 : 完成实验环境的搭建,熟悉基本的Linux命令和工具
1. lab1 :启动操作系统
1. lab2 :物理内存管理
1. lab3 :虚拟内存管理
1. lab4 :内核线程
1. lab5 :用户进程
1. lab6 :处理器调度
1. lab7 : 同步互斥
1. lab8 : 文件系统
## 实验环境
ucore OS实验主要在Linux环境下开发。如果你使用的是非Linux环境,则建议参考下面两种方法。
### Windows下基于MingW进行实验
- windows下如何配置ucore实验环境:这种方式不用安装Linux,感谢“下来障”同学提供的[配置教程](http://pan.baidu.com/s/1i3JxZZR)
[NOTICE] 没有足够的技术支持,希望有感兴趣的生成一个安装软件包和中文使用说明,方便大家使用!
### Windows下基于VirtualBox or VMWare进行实验
#### 1. 安装VirtualBox or VMWare软件
VirtualBox虚拟机软件
https://www.virtualbox.org/
[NOTICE] 也可以安装vmware虚拟机软件
#### 2.使用已经预先安装好相关实验环境所需软件的虚拟硬盘
并下载已经安装好ubuntu 14.04 x86-64的虚拟硬盘文件压缩包。
[VirtualBox的虚拟硬盘文件压缩包2015版](http://pan.baidu.com/s/11zjRK)
--------------
压缩包可以用[haozip for windows软件](http://www.haozip.com)解压。解压压缩包后,可得到如下内容(大约6GB多)。
```
mooc-os-2015-2.vdi
```
如果此时你已经安装好了VirtualBox,在Windows资源管理器中双击文件“mooc-os.vbox”,
就可以在VirtualBox模拟的x86-64计算机中运行ubuntu 14.04 x86-64,并可以开始学习
ucore OS实验了。
```
用户名是 moocos
口令是 <空格键>
```
### 手动在VirtualBox虚拟机中安装ubuntu 14.04 和实验环境相关软件
(这里假定安装的要是ubuntu14.04 x86-64的系统)
-------------------------------------
1) 在VirtualBox上安装ubuntu
下载ubuntu 14.04 img镜像,并在VirtualBox中安装系统。
建议a: 设置虚拟硬盘的大小为8GB以上,虚拟内存在512MB以上。
建议b: 如果你的机器安装的是32位的windows,则下载32位的ubuntu 14.04 img镜像。
2) 在ubuntu系统中安装实验环境相关软件
在shell(比如gnome-terminal)下可执行如下命令来安装相关软件 (“$”是shell的提示符,不用输入)
```
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install build-essential git qemu-system-x86 vim-gnome gdb cgdb eclipse-cdt make diffutils exuberant-ctags tmux openssh-server cscope meld
```
[NOTICE] 最小需要的安装包: build-essential git qemu-system-x86 gdb make diffutils
## 实验中的练习步骤
进入VirtualBox中运行的ubuntu,点击左侧的gnome-terminal软件图标,可启动gnome-terminal
软件。在此软件中,执行如下命令:
1) 目前环境中已经有ucore lab源码,可进一步取得最新ucore lab源码
```
$cd moocos/ucore_lab #到ucore lab所在目录
$git pull #取得最新的ucore lab源代码
$cd
```
2) 学习源码
```
$cd labX #X为 1--8
```
3) 阅读,修改源码,可以用eclipse-cdt, understand, gedit或vim软件
```
$eclipse
OR
$understand
```
4) 修改完毕后,编译实验代码
```
$make
```
5) 如果编译无误,则可以运行测试一下
```
$make qemu
```
6) 如果需要调试,
a. 可基于cgdb的字符方式(以lab1_ans为例)
```
$cd labcodes_answer/lab1_ans
$make debug
```
可以看到弹出两个窗口,一个是qemu,一个是cgdb
可以看到在bootloader的bootmain函数处停了下来。
然后我们就可以进一步在cgdb中用gdb的命令进行调试了
```
(gdb)file bin/kernel #加载ucore kernel的符号信息
(gdb)break kern_init #在函数kern_init处(即 0x100000地址处)设置断点
(gdb)continue #继续执行
```
这时就可以看到在kern_init处停了下来,可进一步调试。
b. 基于eclipse-CDT的debug view进行调试,如果安装了zylin debug插件,则完成初步配置后,
也可很方便地进行调试。
7) 可以运行如下命令,看看自己的得分
```
$make grade
```
# 与实验相关的资料
## 清华大学计算机系本科操作系统课程的主讲老师
向勇 陈渝
## 开发维护人员
- [陈渝](http://soft.cs.tsinghua.edu.cn/~chen) yuchen AT tsinghua.edu.cn
- 茅俊杰 eternal.n08 AT gmail.com
## 助教
茅俊杰、何嘉权、曹睿东、武祥晋、辛云星、刘聪、常铖
## 教学平台支持
张禹、郭旭
## WIKI
http://os.cs.tsinghua.edu.cn/oscourse/OS2015
## 学堂在线
https://www.xuetangx.com/courses/TsinghuaX/30240243X/2015_T1/about
## 在线交流
- [piazza,OS课程技术交流的主要在线QA平台](https://piazza.com/tsinghua.edu.cn/spring2015/30240243x/home)
- QQ群 181873534 主要用于事件通知,聊天等
## 课程汇总信息
- [课程汇总](https://github.com/chyyuu/mooc_os)
## 希望了解OS基本概念和原理的同学
- [OS课程资料]( http://pan.baidu.com/s/1bncWxyv)
- [OS MOOC公开课(原理部分)](http://www.topu.com/mooc/4100)
## 希望了解OS设计与实现细节的同学
- [OS实验资料](http://hejq.me/ucore_docs/)
- [OS实验代码](https://github.com/chyyuu/ucore_lab)
- [OS MOOC公开课(实验部分)](http://www.topu.com/mooc/4100)
## 希望自己动手实践OS的同学
- ["操作系统简单实现与基本原理 — 基于ucore" (持续更新,变动较大) ](http://chyyuu.gitbooks.io/ucorebook/)
- ["操作系统简单实现与基本原理 — 基于ucore" 配套代码](https://github.com/chyyuu/ucorebook_code)
- [ucore plus 跨硬件平台的ucore OS](https://github.com/chyyuu/ucore_plus)
# UCORERS (代码贡献者)
茅俊杰、陈宇恒、刘聪、杨扬、渠准、任胜伟、朱文雷、
曹正、沈彤、陈旭、蓝昶、方宇剑、韩文涛、张凯成、
S郭晓林、薛天凡、胡刚、刘超、粟裕、袁昕颢...
# NOTICE
如果你发现了问题,有好的建议或意见,请给 yuchen AT tsinghua.edu.cn 发电邮;
如果你完成这8个实验,且对进一步探索、研究、研发操作系统感兴趣,请给 yuchen AT tsinghua.edu.cn 发电邮,欢迎加入我们的OS兴趣小组,共同进步!

+ 5
- 2
labcodes_answer/lab1_result/Makefile View File

@ -152,6 +152,7 @@ $(bootblock): $(call toobj,$(bootfiles)) | $(call totarget,sign)
@echo + ld $@ @echo + ld $@
$(V)$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 $^ -o $(call toobj,bootblock) $(V)$(LD) $(LDFLAGS) -N -e start -Ttext 0x7C00 $^ -o $(call toobj,bootblock)
@$(OBJDUMP) -S $(call objfile,bootblock) > $(call asmfile,bootblock) @$(OBJDUMP) -S $(call objfile,bootblock) > $(call asmfile,bootblock)
@$(OBJDUMP) -t $(call objfile,bootblock) | $(SED) '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $(call symfile,bootblock)
@$(OBJCOPY) -S -O binary $(call objfile,bootblock) $(call outfile,bootblock) @$(OBJCOPY) -S -O binary $(call objfile,bootblock) $(call outfile,bootblock)
@$(call totarget,sign) $(call outfile,bootblock) $(bootblock) @$(call totarget,sign) $(call outfile,bootblock) $(bootblock)
@ -193,7 +194,7 @@ endif
# files for grade script # files for grade script
TARGETS: $(TARGETS) TARGETS: $(TARGETS)
all: $(TARGETS)
.DEFAULT_GOAL := TARGETS .DEFAULT_GOAL := TARGETS
.PHONY: qemu qemu-nox debug debug-nox .PHONY: qemu qemu-nox debug debug-nox
@ -214,10 +215,12 @@ qemu: $(UCOREIMG)
qemu-nox: $(UCOREIMG) qemu-nox: $(UCOREIMG)
$(V)$(QEMU) -serial mon:stdio -hda $< -nographic $(V)$(QEMU) -serial mon:stdio -hda $< -nographic
TERMINAL :=gnome-terminal TERMINAL :=gnome-terminal
gdb: $(UCOREIMG)
$(V)$(QEMU) -S -s -parallel stdio -hda $< -serial null
debug: $(UCOREIMG) debug: $(UCOREIMG)
$(V)$(QEMU) -S -s -parallel stdio -hda $< -serial null & $(V)$(QEMU) -S -s -parallel stdio -hda $< -serial null &
$(V)sleep 2 $(V)sleep 2
$(V)$(TERMINAL) -e "gdb -q -x tools/gdbinit"
$(V)$(TERMINAL) -e "cgdb -q -x tools/gdbinit"
debug-nox: $(UCOREIMG) debug-nox: $(UCOREIMG)
$(V)$(QEMU) -S -s -serial mon:stdio -hda $< -nographic & $(V)$(QEMU) -S -s -serial mon:stdio -hda $< -nographic &

+ 2
- 3
labcodes_answer/lab1_result/boot/bootmain.c View File

@ -29,9 +29,8 @@
* *
* * bootmain() in this file takes over, reads in the kernel and jumps to it. * * bootmain() in this file takes over, reads in the kernel and jumps to it.
* */ * */
#define SECTSIZE 512
#define ELFHDR ((struct elfhdr *)0x10000) // scratch space
unsigned int SECTSIZE = 512 ;
struct elfhdr * ELFHDR = ((struct elfhdr *)0x10000) ; // scratch space
/* waitdisk - wait for disk ready */ /* waitdisk - wait for disk ready */
static void static void

+ 3
- 3
labcodes_answer/lab1_result/kern/init/init.c View File

@ -9,12 +9,12 @@
#include <intr.h> #include <intr.h>
#include <pmm.h> #include <pmm.h>
#include <kmonitor.h> #include <kmonitor.h>
int kern_init(void) __attribute__((noreturn));
void kern_init(void) __attribute__((noreturn));
void grade_backtrace(void); void grade_backtrace(void);
static void lab1_switch_test(void); static void lab1_switch_test(void);
int
kern_init(void) {
void
kern_init(void){
extern char edata[], end[]; extern char edata[], end[];
memset(edata, 0, end - edata); memset(edata, 0, end - edata);

+ 3
- 3
labcodes_answer/lab1_result/tools/gdbinit View File

@ -1,4 +1,4 @@
file bin/kernel
file obj/bootblock.o
target remote :1234 target remote :1234
break kern_init
continue
break bootmain
continue

Loading…
Cancel
Save