浙江工业大学计算机学院计算机实验班1101章鹏201126100329实验报告名称:创新实践(30天自制操作系统)实验目标:根据教材从零开始使用C与汇编语言编写一个简单的操作系统,实现操作系统的基本功能。实验背景:为了让学生对操作系统的底层有更清晰的了解,选取了一本名为《30天自制操作系统》的书作为两学期创新实践课程的教材,并根据该教材一步步从零开始完成每个人自己特色的简易版操作系统,锻炼学生动手能力,提高学生对操作系统的知识理解。实验进度:第28天成果界面截图:截图1:操作系统初始化界面截图2:运行命令获取操作系统基本信息截图2.1Mem:读取系统内存与存储空间截图2.2Dir:读取当前系统允许使用的应用程序截图2.3Exit:关闭当前console命令窗截图2.4应用程序名:在当前窗口下运行应用程序截图2.5Start+应用程序名:新建一个console命令窗并运行程序截图2.6Ncst(noconsolestart):无新建窗口运行程序截图2.7Shift+f2:新建一个空的console窗口截图2.8F11:将下一层的console窗口切至最顶层截图2.9Tab:将当前工作区间(键盘)在窗口间循环截图3应用程序截图:截图3.1a(显示字符A):截图3.2Winhelo/winhelo2/winhelo3:截图3.3Color:截图3.4Color2:截图3.5Hello3:截图3.6Hello4与hello5:截图3.7Lines:画线程序截图3.8Noddle:计时程序(三分钟)截图3.9Sosu:显示1-1000内的素数截图3.10Sosu3:显示1-10000内的素数截图3.11Star1:显示一个点截图3.12Stars:显示多个点截图3.13Walk:使用方向键控制点的移动源代码截取:操作系统代码:haribote文件夹(以graphic界面颜色与图形控制为例)//graphic.c#includebootpack.hvoidinit_palette(void){staticunsignedchartable_rgb[16*3]={0x00,0x00,0x00,/*0:黑*/0xff,0x00,0x00,/*1:亮红*/0x00,0xff,0x00,/*2:亮绿*/0xff,0xff,0x00,/*3:亮黄*/0x00,0x00,0xff,/*4:亮蓝*/0xff,0x00,0xff,/*5:亮紫*/0x00,0xff,0xff,/*6:浅亮蓝*/0xff,0xff,0xff,/*7:白*/0xc6,0xc6,0xc6,/*8:亮灰*/0x84,0x00,0x00,/*9:暗红*/0x00,0x84,0x00,/*10:暗绿*/0x84,0x84,0x00,/*11:暗黄*/0x00,0x00,0x84,/*12:暗青*/0x84,0x00,0x84,/*13:暗紫*/0x00,0x84,0x84,/*14:浅暗蓝*/0x84,0x84,0x84/*15:暗灰*/};unsignedchartable2[216*3];intr,g,b;set_palette(0,15,table_rgb);for(b=0;b6;b++){for(g=0;g6;g++){for(r=0;r6;r++){table2[(r+g*6+b*36)*3+0]=r*51;table2[(r+g*6+b*36)*3+1]=g*51;table2[(r+g*6+b*36)*3+2]=b*51;}}}set_palette(16,231,table2);return;}voidset_palette(intstart,intend,unsignedchar*rgb){inti,eflags;eflags=io_load_eflags();io_cli();io_out8(0x03c8,start);for(i=start;i=end;i++){io_out8(0x03c9,rgb[0]/4);io_out8(0x03c9,rgb[1]/4);io_out8(0x03c9,rgb[2]/4);rgb+=3;}io_store_eflags(eflags);return;}voidboxfill8(unsignedchar*vram,intxsize,unsignedcharc,intx0,inty0,intx1,inty1){intx,y;for(y=y0;y=y1;y++){for(x=x0;x=x1;x++)vram[y*xsize+x]=c;}return;}voidinit_screen8(char*vram,intx,inty){boxfill8(vram,x,COL8_008484,0,0,x-1,y-29);boxfill8(vram,x,COL8_C6C6C6,0,y-28,x-1,y-28);boxfill8(vram,x,COL8_FFFFFF,0,y-27,x-1,y-27);boxfill8(vram,x,COL8_C6C6C6,0,y-26,x-1,y-1);boxfill8(vram,x,COL8_FFFFFF,3,y-24,59,y-24);boxfill8(vram,x,COL8_FFFFFF,2,y-24,2,y-4);boxfill8(vram,x,COL8_848484,3,y-4,59,y-4);boxfill8(vram,x,COL8_848484,59,y-23,59,y-5);boxfill8(vram,x,COL8_000000,2,y-3,59,y-3);boxfill8(vram,x,COL8_000000,60,y-24,60,y-3);boxfill8(vram,x,COL8_848484,x-47,y-24,x-4,y-24);boxfill8(vram,x,COL8_848484,x-47,y-23,x-47,y-4);boxfill8(vram,x,COL8_FFFFFF,x-47,y-3,x-4,y-3);boxfill8(vram,x,COL8_FFFFFF,x-3,y-24,x-3,y-3);return;}voidputfont8(char*vram,intxsize,intx,inty,charc,char*font){inti;char*p,d/*data*/;for(i=0;i16;i++){p=vram+(y+i)*xsize+x;d=font[i];if((d&0x80)!=0){p[0]=c;}if((d&0x40)!=0){p[1]=c;}if((d&0x20)!=0){p[2]=c;}if((d&0x10)!=0){p[3]=c;}if((d&0x08)!=0){p[4]=c;}if((d&0x04)!=0){p[5]=c;}if((d&0x02)!=0){p[6]=c;}if((d&0x01)!=0){p[7]=c;}}return;}voidputfonts8_asc(char*vram,intxsize,intx,inty,charc,unsignedchar*s){externcharhankaku[4096];for(;*s!=0x00;s++){putfont8(vram,xsize,x,y,c,hankaku+*s*16);x+=8;}return;}voidinit_mouse_cursor8(char*mouse,charbc){intx,y;for(y=0;y16;y++){for(x=0;x16;x++){if(cursor[y][x]=='*'){mouse[y*16+x]=COL8_000000;}if(cursor[y][x]=='0'){mouse[y*16+x]=COL8_FFFFFF;}if(cursor[y][x]=='.'){mouse[y*16+x]=bc;}}}return;}voidputblock8_8(char*vram,intvxsize,intpxsize,intpysize,intpx0,intpy0,char*buf,intbxsize){intx,y;for(y=0;ypysize;y++){for(x=0;xpxsize;x++){vram[(py0+y)*vxsize+(px0+x)]=buf[y*bxsize+x];}}return;}操作系统api(以api002’输出单个字符’为例)://api002.nas[FORMATWCOFF][INSTRSETi486p][BITS32][FILEapi002.nas]GLOBAL_api_putstr0[SECTION.text]_api_putstr0:;voidapi_putstr0(char*s);PUSHEBXMOVEDX,2MOVEBX,[ESP+8];sINT0x40POPEBXRET应用程序(以stars为例)://stars.c#includeapilib.hintrand(void);voidHariMain(void){char*buf;intwin,i,x,y;api_initmalloc();buf=api_malloc(150*100);win=api_openwin(buf,150,100,-1,stars);api_boxfilwin(win,6,26,143,93,0);for(i=0;i50;i++){x=(rand()%137)+6;y=(rand()%67)+26;api_point(win,x,y,3);}for(;;){if(api_getkey(1)==0x0a){break;}}api_end();}操作系统Makefile文件:TOOLPATH=../z_tools/INCPATH=../z_tools/haribote/MAKE=$(TOOLPATH)make.exe-rEDIMG=$(TOOLPATH)edimg.exeIMGTOL=$(TOOLPATH)imgtol.comCOPY=copyDEL=deldefault:$(MAKE)haribote.imgharibote.img:haribote/ipl10.binharibote/haribote.sysMakefile\a/a.hrbhello3/hello3.hrbhello4/hello4.hrbhello5/hello5.hrb\winhelo/winhelo.hrbwinhelo2/winhelo2.hrbwinhelo3/winhelo3.hrb\star1/star1.hrbstars/stars.hrbstars2/stars2.hrb\lines/lines.hrbwalk/walk.hrbnoodle/noodle.hrb\beepdown/beepdown.hrbcolor/color.hrbcolor2/color2.hrb$(EDIMG)imgin:../z_tools/fdimg0at.tek\wbinimgsrc:haribote/ipl10.binlen:512from:0to:0\copyfrom:haribote/haribote.systo:@:\copyfrom:haribote/ipl10.nasto:@:\copyfrom:make.batto:@:\copyfrom:a/a.hrbto:@:\copyfrom:hello3/hello3.hrbto:@:\copyfrom:hello4/hello4.hrbto:@:\copyfrom:hello5/hello5.hrbto:@:\copyfrom:winhelo/winhelo.hrbto:@:\copyfrom:winhelo2/winhelo2.hrbto:@:\copyfrom:winhelo3/winhelo3.hrbto:@:\copyfrom:star1/star1.hrbto:@:\copy