操作系统虚拟机小论文_第1页
操作系统虚拟机小论文_第2页
操作系统虚拟机小论文_第3页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、课程设计课程设计名称:计算机操作系统专业班级:计算机科学与技术学生姓名:学号:指导教师:课程设计时间:操作系统专业课程设计任务书课程设计题目虚拟页式存储管理系统的实现学院专业计算机科学与技术年级指导教师成绩所需环境Linux环境Bochs虚拟实验室设计要求1掌握Linux环境下常用编译工具如 gcc/g+/nasm及开源虚拟机bochs的下载、安装、使用2掌握x86架构下分页式存储管理系统的基本原理,设 计个请求分页式虚拟存储系统。3掌握Linux系统下程序的编写及运行。学生应完成的工作1. 按照实验二要求,构建 Bochs虚拟实验室2. 回顾虚拟页式存储系统:作业分页,内存分块,只有当 进程

2、要使用其虚拟内存时,其对应的数据才装入物理内存。3. 请认真阅读readme.txt文件,弄清楚各个文件的作用审查意见指导教师签字:教研室主任签字:年月日说明:本表由指导教师填写,由教研室主任审核后下达给选题学生,装订在设计(论文)首页目录一、设计目的为了掌握 Linux 环境下常用编译工具如 gcc/g+/nasm 及开源虚拟机 bochs 的下载、安装、使用,掌握 x86 架构下分页式存储管理系统的基本原理 , 设计一 个请求分页式虚拟存储系统。 掌握 Linux 系统下程序的编写及运行等方面展开实 验。二、设计要求2.1 要求熟练掌握 sudo apt-get install 的用法。2

3、.2 要求能够掌握分页存储管理系统的基本原理。2.3 要求学会在 Linux 系统下编写程序、执行程序。三、设计内容3.1 运行环境虚拟机系统下使用 Ubuntu 下提供的 apt-get 软件包安装工具 安装 vim、 g+ 、 nasm 、 bochs 等3.2 2. 详细设计1)回顾虚拟页式存储系统:作业分页,内存分块,只有当进程要使请认真 阅读 readme.txt 文件,弄清楚各个文件的作用2)用其虚拟内存时 , 其对应的数据才装入物理内存。3)完成 frame_pool.H 、frame_pool.C 、page_table.C 三个文件,其中 page_table.H 已经提供,

4、我们需要添加 page_table.C, 自己设计并实现这些函 数。4)在 frame_pool.H 定义所需要的数据结构,在 frame_pool.C 完成这些函数添加代码如下所示:class FramePool private: unsigned long base_frame_no; unsignedlong nframes;unsigned long info_frame_no; unsigned char* free_frames;public:static const unsigned char USED -1;static const unsignedchar UNUSED -0

5、;static const unsigned int FRAME_SIZE -4096;public:FramePool(unsigned long _base_frame_no,unsigned long _nframes,unsigned long _info_frame_no);5)建立 Frame_pool.C 文件系统中使用位示图 bitmap 标识页面是否使用, start_frame 表示第一个页 面的起始地址(如系统内存池从 2M开始),pool_size表示在用户池中页框的总 数(如系统内存池的页框从2M4M因此共有(4M-2M /4KB=512个页框)。初始 化用户池中位示

6、图的内容Frame_pool:frame_pool ()初始化 bitmap 记录系统中所有物理块是否可 用,如果可用设置为 0,否则为 1。Frame_pool:get_frame ()通过该方法去查询 bitmap ,查找可用物理块号。FramePool:mark_inaccessible( ) 方法将 bitmap 中对应位置置 1。FramePool:release_frame ()方法将 bitmap 中对应位置置 0。设计一个私有函数 set_frame_flag ,来设置某一个字节的某个 bit 为 0 或 则为 1。6) 打开 page_table.H页表如下图所示:其中,页面

7、大小为4K,即可用12位表示页内地址,各个位含义如上图页表 所示,其余 20位表示页号,即 1M。7) 创建一个文件: page_table.CPageTable:init_paging() 给私有变量传递参数。 PageTable:PageTable() 构造函数。当 bochs 启动时, start.asm 首先被读入到软盘镜像文件中, 并将 kernel.C 放入到内存1MB-2ME空间内,然后启动CPU运行,操作系统开始启动。#include "page_table.H"#include "exceptions.H"#include "

8、frame_pool.H"#include "paging_low.H"FramePool* PageTable:kernel_mem_pool =NULL;FramePool* PageTable:process_mem_pool =NULL;unsigned long PageTable:shares_size;PageTable*PageTable:current_page_table;void PageTable:init_paging(FramePool* _kernel_mem_pool,FramePool* _process_mem_pool,con

9、st unsigned long _shared_size)kernel_mem_pool =_kernel_mem_pool;process_mem_pool =_process_mem_pool;shared_size =_shared_size;PageTable:PageTable()unsigned long phys_address =0;page_directory =(unsigned long*) (kernel_mem_pool->get_frame()* PAGE_SIZE);unsigned long* page_table=(unsigned long*)(ke

10、rnel_mem_pool->get_frame() *PAGE_SIZE);for(unsigned int i=0;i<ENTRIES_PER_PAGE;i+) page_tablei=phys_address|3phys_address+=PAGE_SIZE;page_directory0=(unsigned long) page_table |3;for(unsigned int i=1;i<ENTRIES_PER_PAGE;i+) page_directoryi=0|2;void PageTable:enable_paging()writE_cr3(unsigned

11、 long )(current_page_table->page_directory);write_cr0(read_cr0()|0x80000000);void PageTable:handle_fault(REGS *_r)unsigned int page_fault_addr=read_cr2()unsigned long* page_table;Console:putui(page_fault_addr);Console:puts("n");unsigned int page_dir_entry+page_fault_addr >>22;unsi

12、gned long page_table_addr =current_page->directorypage_dir_entry;if (page_fault_addr & 0x01)=0)unsigned long new_page_table_addr=kernel_mem_pool ->get_frame() *PAGE_SIZE;page_table=(unsigned long*)(new_page_table_addr);long)current_page_table->page_directorypage_dir_entry=(unsigned new_

13、page_table_addr|3;for(unsigned int i=0;i<ENTRIES_PER_PAGE;i+)page_tablei=0x00; elsepage_table=(unsigned long*)(page_table_addr &0xFFFF000);unsigned long free_frame_no=process_mem_pool->frame();page_tablepage_tab_entry=(free_frame_no*PAGE_SIZE)|7;代码如下:#include "exceptions.H"#inclu

14、de "frame_pool.H"#include "paging_low.H"FranePool* PageTable:kernel_mem_pool = NULL;FramePool* PageTable:process_mem_pool = NULL;unsigned long PageTable:shared_size;PageTable* PageTable:curent_page_table;void PageTable:init_paging(FarmePool* _kernel_mem_pool,FramePool* _process_m

15、em_pool,const unsigned long _shared_size)kernel_mem_pool = _kernel_mem_pool;process_mem_pool = _process_mem_pool;shared_size = _shared_size;PageTable:PageTable()unsigned long phys_address = 0;page_directory = (unsigned long *)(kernel_mem_pool->get_frame() * PAGE_SIZE);unsigned long * page_table =

16、 (unsigned long *)(kernel_mem_pool->get_frame() * PAGE_SIZE); for(unsigned int i = 0; i<ENTRIES_PER_PAGE;i+)page_tablei = phys_adress | 3;phys_adress += PAGE_SIZE;page_directory0 = (unsigned long) page_table | 3;for(unsigned int i = 1;i < ENTRIES_PER_PAGE;i+)page_directoryi = 0 | 2;void Pag

17、eTable:enable_paging()write_cr3 (unsigned long ) (current_page_table_>page_directory); write_cr0(read_cr0() | 0x80000000);void PageTable:handle_fault(REGS * _r)(unsigned int page_fault_addr = read_cr2();unsigned long* page_table;Console:putui(page_fault_addr);Console:puts("n");unsigned

18、int page_dir-entry = page_fault_addr >>22;unsigned int page_dir-entry = (page_fault_addr & (0x03FF << 12) >>12;unsigned long page_table_addr = current_page_table->page_directorypage_dir_entry; if (page_fault_addr & 0x01 = 0)unsigned long new_page_table_addr = kernel_men_

19、pool -> get_frame() * PAGE_SIZE;page_table = (unsigned long*) (new_page_table_addr);longcurrent_page_table->page_directorypage_dir_entry = (unsigned new_page_table_addr | 3;for(unsiqned int i =0;i<ENTRIKS_PER_PAGE:i+)page_tablei=0x00;else/Page table has been present, but the entry in page t

20、able is not present/get page table address from page_table_addrpage_table=(unsigned long*) page_table_addr&0xFFFFF000);/find a free framo from process memory pool and give it to page table entryunsigned long free_framo_no=process_mem_pool->get_framo();/attributo set to; user level,read/write,

21、 present(111 in binary)page_table(page_tab_entry)=(free_framo_no*PAGE_SIZE)1 7;#include "frame_pool.H"#define MB * (0x1 << 20)#define kB * (0x1 << 20)Framepool:Framepool( unsigned long _base_frame_no,unsigned long _nframe, unsigned long _info_frame_no)base_frame_no =_base_frame

22、_no;nframes =_nframes;info_frame_no =_info_frame_no;if (info_frame_no = 0)info_frame_no - (2MB)/FRAME_SIZE;free_frames =(unsigned char*)(info_frame_no * FRAME_SIZE);unsigned long total_bitmap_bytes = (nframes + 7) /8;for( unsigned long i = 0;i<total_bitmap_bytes; i+)free_frames i =0x00;set_frame_

23、flag(info_frame_no,USED);/unsigned long Framepool:get_frame() unsigned long which_byte_free;unsigned char val;for(which_byte_free = 0;which_byte_free<total_bitmap_bytes;which_byte_free+) val = *(free_frame + which_byte_free);if(val !=0xFF)break;if(val = 0xFF)return 0;char bit = 0;while(1)if (va;&

24、amp;(USED<<BIT) =0)break;bit+;unsigned long abs_free_frame_add =base_frame_no + which_byte_free *8 + bit;set_frame_flag( abs_free_frame_add ,USED);return abs_free_frame_add;void Framepool:mark_inaccessible(unsigned long _base_frame_no,unsigned long _nframe,)for(unsigned long i = 0;i < _nfra

25、mes; i+) set_frame_flag(_base_frame_no + i,USED);void Framepool:release_frame( unsigned long _frame_no) set_frame_flag(_frame_no,UNUSED);inline void Framepool:set_frame_flag(unsigned long _frame_no,unsigned char ifused)_frame_on -= base_frame_on;int bit_counter = _frame_on%8;unsigned char mask = 0;i

26、f(ifused =USED)mask=(0x01 << bit_counter);*(free_frames + _frame_no /8) |=mask;else mask=(0x01 << bit_counter);*(free_frames + _frame_no /8) &=mask;#include "page_table.H"#include "exceptions.H"#include "frame_pool.H"#include "paging_low.H"Fran

27、ePool* PageTable:kernel_mem_pool = NULL;FramePool* PageTable:process_mem_pool = NULL; unsigned long PageTable:shared_size;PageTable* PageTable:curent_page_table;void PageTable:init_paging(FarmePool* _kernel_mem_pool,FramePool* _process_mem_pool, const unsigned long _shared_size) kernel_mem_pool = _k

28、ernel_mem_pool;process_mem_pool = _process_mem_pool; shared_size = _shared_size;PageTable:PageTable() unsigned long phys_address = 0;page_directory = (unsigned long *)(kernel_mem_pool->get_frame() * PAGE_SIZE);unsigned long * page_table = (unsigned long *)(kernel_mem_pool->get_frame() * PAGE_S

29、IZE); for(unsigned int i = 0; i<ENTRIES_PER_PAGE;i+)page_tablei = phys_adress | 3;phys_adress += PAGE_SIZE;page_directory0 = (unsigned long) page_table | 3;for(unsigned int i = 1;i < ENTRIES_PER_PAGE;i+)page_directoryi = 0 | 2;void PageTable:enable_paging()write_cr3 (unsigned long ) (current_p

30、age_table_>page_directory);write_cr0(read_cr0() | 0x80000000);void PageTable:handle_fault(REGS * _r)unsigned int page_fault_addr = read_cr2();unsigned long* page_table;Console:putui(page_fault_addr);Console:puts("n");unsigned int page_dir_entry = page_fault_addr >> 22;unsigned int

31、 page_tab_entry = (page_fault_addr & (0x03FF << 12) >> 12;unsigned long page_table_addr = current_page_table->page_directorypage_dir_entry;if(page_fault_addr & 0x01) = 0)unsigned long new_page_table_addr = kernel_mem_pool ->get_frame() *PAGE_SIZE; page_table =(unsigned long

32、*)(ew_page_table_addr);current_page_table->page_directorypage_dir_entry = ( unsigned long)new_page_table_addr | 3; for( unsigned int i = 0;i< ENTRIES_PAR_PAGE; i+)page_tablei = 0x00;else page_table =(un sig ned Ion g*)(page_table_addr &0xfff000);un sig ned long free_frame_ no = process_mem

33、_pool ->get_frame();page_tablepage_tab_e ntry = (free_frame_no *PAGE_SIZE) | 7;8)编写Makefile 文件即 make f makefile.linux3.3调试分析O Ab1 studentubuntu: /MPZstudentubuntu studentgubuntu wtudentgubuntu studentubuntu studentubuntu student(Jiubuntu studentubuntu studentubuntu studentubuntu student(Jubuntu-$

34、 cd HP2-/MP2$ /MlP2$ 川P2$*/MP2$-/MP2$/MlP2$vtn frame paol*Hvtn frane_poolTHvin framepool.cvtn frame_pool.cvtn frame pool, cvtn frdme_pool.匚 vtn pagetable.匚 vtn Makefile make -f makefile*linux No wuch file or dire匚to¥make: makefile *linux: make: * No rule to nake target makefile.linuxT, 丁+料P2$ |

35、UbreOfTiceCalcStop.Preparing to unpack .,/bochs-sdl_2,4.6-3-138®*dmb *Setting up Iib5dli4,2debian:i386 (1*2 + 15'Subuntul.l) * * Pracessing triggers for Ltbc-bin (219-9ubuntu&) -* studentubuntu; - $ MP2$ vin frarie_poQl »HMP2$: command not found studentubuntu:MP2 vim franepool»

36、;H MP2: command not foundstudentubuntv studentubuntu studentubuntu studentgubuntu studentubuntu studentubuntu 5tudrituburit:u studentubuntu studentubuntu nake:帕cd WP2-/MP2S/MP25-/MP25-/HP2$/MP2$/MP2S/MP25/MP2$vim vim vtn vtn vim vim vimfrane_pool,H frane_pool” C frane_pool. *C frame_pool,H Framepool

37、*C page_table *C page_t己bli” Crake -f nakeftle,Linux No such file or directorykeftie,Itnux:No rule to make target ' makeftle3nux'-nake: * studentubuntw:-/MP2$ make -f makefile*Linuxmake: makefile.linux: No such file or directory nake: * No rule to nake target makefile.linux*-5 top.Stop.修改 bochsrc.bxrc 文件,增加

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论