免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12345下一页
最近访问板块 发新帖
查看: 103760 | 回复: 46

我也来发一款自己写的x86虚拟机(NXVM),能在win 7,linux和surface rt(ARM)下跑MS [复制链接]

论坛徽章:
0
发表于 2013-10-11 11:09 |显示全部楼层
本帖最后由 ylide 于 2014-05-10 00:20 编辑

发一款自己花了5个月时间编写的386虚拟机 NXVM。

这个虚拟机是用C编写的,一共40,000行代码,
它完整的模拟了一台PC,包括一个80386 CPU,以及所有必要的设备,
因此它可以运行一个基于x86的操作系统,如MS-DOS6.22,并支持32位寻址。

这个虚拟机还额外附加了16位调试器(用法和DOS的debug.exe一样)和32位调试器,以及一个汇编器和反汇编器,可以调试操作系统。

NXVM虚拟机可以同时在Windows和Linux下通过编译。在Windows下,它可以运行在命令提示符窗口中(将Win32控制台作为虚拟机显示器和键盘),也可以创建自己的窗口(模拟DOS下的点阵字体)。在Linux下,它能在80x25尺寸的终端窗口中正常运行。

写这个虚拟机的过程中也参考过easyVM和LightMachine,发现和修正了它们的一些bug,并用Bochs的CPU来跟踪对比调试我的虚拟80386。

我还写了一份文档,详细描述了使用方法并做了源代码分析,感兴趣的人可以直接理解相关逻辑。

【下载】

源代码和简介在GITHUB: http://github.com/cshaxu/nxvm/

磁盘镜像和设计文档:http://sdrv.ms/17XmGWa

【编译】
1. 在Linux下编译:
./configure 生成Makefile
make 生成可执行文件./nxvm

2. 在Windows下编译:在VS2008、VS2010或VS2012中,创建空的Win32控制台项目,

把src文件夹下面的所有文件加入项目,然后排除掉src/platform/linux/下的代码。

编译x64 Release即可.

【截图】
在 Surface RT 8.0下跑MS-DOS:


在64位Windows的命令提示符窗口中运行DOS:


在Linux终端里跑MS-DOS:



DOS运行在HMA:



TT打字程序:


俄罗斯方块:



Windows窗口模式下的点阵字体模拟:

论坛徽章:
1
综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00
发表于 2013-10-13 12:13 |显示全部楼层
编程功力很强,不过程序实用性似乎不太大。  :wink:

论坛徽章:
1
综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00
发表于 2013-10-14 08:15 |显示全部楼层
回复 1# ylide

-bash-4.1$ make
gcc -c -g -O console.c
gcc -c -g -O main.c
gcc -c -g -O vmachine/vapi.c
gcc -c -g -O vmachine/vcmos.c
gcc -c -g -O vmachine/vcpu.c
gcc -c -g -O vmachine/vcpuins.c
gcc -c -g -O vmachine/vdma.c
gcc -c -g -O vmachine/vfdc.c
gcc -c -g -O vmachine/vfdd.c
gcc -c -g -O vmachine/vhdd.c
gcc -c -g -O vmachine/vkbc.c
gcc -c -g -O vmachine/vmachine.c
gcc -c -g -O vmachine/vpic.c
gcc -c -g -O vmachine/vpit.c
gcc -c -g -O vmachine/vport.c
gcc -c -g -O vmachine/vram.c
gcc -c -g -O vmachine/vvadp.c
gcc -c -g -O vmachine/system/linux.c -lpthread -lncurses
vmachine/system/linux.c:3:20: error: curses.h: No such file or directory
vmachine/system/linux.c: In function ‘linuxDisplayInit’:
vmachine/system/linux.c:32: error: ‘stdscr’ undeclared (first use in this function)
vmachine/system/linux.c:32: error: (Each undeclared identifier is reported only once
vmachine/system/linux.c:32: error: for each function it appears in.)
vmachine/system/linux.c:32: error: ‘TRUE’ undeclared (first use in this function)
vmachine/system/linux.c: In function ‘linuxDisplayFinal’:
vmachine/system/linux.c:45: error: ‘stdscr’ undeclared (first use in this function)
vmachine/system/linux.c:45: error: ‘FALSE’ undeclared (first use in this function)
vmachine/system/linux.c: In function ‘ReverseColor’:
vmachine/system/linux.c:58: error: ‘COLOR_BLACK’ undeclared (first use in this function)
vmachine/system/linux.c:58: error: ‘COLOR_WHITE’ undeclared (first use in this function)
vmachine/system/linux.c:59: error: ‘COLOR_BLUE’ undeclared (first use in this function)
vmachine/system/linux.c:59: error: ‘COLOR_YELLOW’ undeclared (first use in this function)
vmachine/system/linux.c:60: error: ‘COLOR_GREEN’ undeclared (first use in this function)
vmachine/system/linux.c:60: error: ‘COLOR_RED’ undeclared (first use in this function)
vmachine/system/linux.c:61: error: ‘COLOR_CYAN’ undeclared (first use in this function)
vmachine/system/linux.c:61: error: ‘COLOR_MAGENTA’ undeclared (first use in this function)
vmachine/system/linux.c: In function ‘CharProp2Color’:
vmachine/system/linux.c:80: error: ‘COLOR_BLACK’ undeclared (first use in this function)
vmachine/system/linux.c:81: error: ‘COLOR_BLUE’ undeclared (first use in this function)
vmachine/system/linux.c:82: error: ‘COLOR_GREEN’ undeclared (first use in this function)
vmachine/system/linux.c:83: error: ‘COLOR_CYAN’ undeclared (first use in this function)
vmachine/system/linux.c:84: error: ‘COLOR_RED’ undeclared (first use in this function)
vmachine/system/linux.c:85: error: ‘COLOR_MAGENTA’ undeclared (first use in this function)
vmachine/system/linux.c:86: error: ‘COLOR_YELLOW’ undeclared (first use in this function)
vmachine/system/linux.c:87: error: ‘COLOR_WHITE’ undeclared (first use in this function)
vmachine/system/linux.c: In function ‘linuxDisplayPaint’:
vmachine/system/linux.c:179: error: ‘COLS’ undeclared (first use in this function)
vmachine/system/linux.c:180: error: ‘LINES’ undeclared (first use in this function)
vmachine/system/linux.c: In function ‘linuxKeyboardMakeKey’:
vmachine/system/linux.c:311: error: ‘ERR’ undeclared (first use in this function)
vmachine/system/linux.c:327: error: ‘KEY_F0’ undeclared (first use in this function)
vmachine/system/linux.c:336: error: ‘KEY_DOWN’ undeclared (first use in this function)
vmachine/system/linux.c:338: error: ‘KEY_UP’ undeclared (first use in this function)
vmachine/system/linux.c:340: error: ‘KEY_LEFT’ undeclared (first use in this function)
vmachine/system/linux.c:342: error: ‘KEY_RIGHT’ undeclared (first use in this function)
vmachine/system/linux.c:344: error: ‘KEY_HOME’ undeclared (first use in this function)
vmachine/system/linux.c:346: error: ‘KEY_BACKSPACE’ undeclared (first use in this function)
vmachine/system/linux.c:348: error: ‘KEY_ENTER’ undeclared (first use in this function)
vmachine/system/linux.c:350: error: ‘KEY_NPAGE’ undeclared (first use in this function)
vmachine/system/linux.c:352: error: ‘KEY_PPAGE’ undeclared (first use in this function)
vmachine/system/linux.c:354: error: ‘KEY_END’ undeclared (first use in this function)
vmachine/system/linux.c: In function ‘linuxKeyboardProcess’:
vmachine/system/linux.c:368: error: ‘ERR’ undeclared (first use in this function)
make: *** [linux.o] Error 1

这个应该怎么弄呢?

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-12-20 06:20:00
发表于 2013-10-14 11:37 |显示全部楼层
能说一下大体的架构吗?

论坛徽章:
4
天秤座
日期:2013-10-18 13:58:33金牛座
日期:2013-11-28 16:17:01辰龙
日期:2014-01-14 09:54:32戌狗
日期:2014-01-24 09:23:27
发表于 2013-10-14 11:45 |显示全部楼层
专程来拜楼主的。

论坛徽章:
0
发表于 2013-10-18 09:36 |显示全部楼层
我毕业设计差点就是选择的做一个x86虚拟机,以后我也想做一个出来玩玩,楼主好厉害,赞一个.....

论坛徽章:
1
综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00
发表于 2013-10-18 15:47 |显示全部楼层
表瞎拜了!  

程序错误一大堆...  也不知道是怎么楼主怎么编译运行通过的 ,  估计还有部分没有 commit .

论坛徽章:
0
发表于 2013-10-20 12:14 |显示全部楼层
本帖最后由 ylide 于 2013-10-20 12:27 编辑

回复 7# fly3ds

所有代码都已经commit了的,至少在Windows下用VS编译肯定是可以的。
主贴更新了编译方法,谢谢~~

论坛徽章:
0
发表于 2013-10-20 12:19 |显示全部楼层
回复 4# goingstudy

可以参考设计文档,在http://sdrv.ms/17XmGWa下载

论坛徽章:
1
综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00
发表于 2013-10-20 12:20 |显示全部楼层
回复 9# ylide

这个我也想到了, 只是这台机器有ncurse库啊

    [linux@linuxlearn:include]$ find ./ | grep curses
./cursesf.h
./cursesm.h
./curses.h
./ncurses_dll.h
./python2.6/py_curses.h
./ncursesw
./ncursesw/unctrl.h
./ncursesw/cursesf.h
./ncursesw/cursesm.h
./ncursesw/curses.h
./ncursesw/ncurses_dll.h
./ncursesw/menu.h
./ncursesw/etip.h
./ncursesw/cursesp.h
./ncursesw/cursesw.h
./ncursesw/termcap.h
./ncursesw/form.h
./ncursesw/cursesapp.h
./ncursesw/term.h
./ncursesw/eti.h
./ncursesw/nc_tparm.h
./ncursesw/cursslk.h
./ncursesw/panel.h
./ncursesw/ncurses.h
./ncursesw/term_entry.h
./ncursesw/tic.h
./cursesp.h
./cursesw.h
./cursesapp.h
./ncurses.h
./ncurses
./ncurses/unctrl.h
./ncurses/cursesf.h
./ncurses/cursesm.h
./ncurses/curses.h
./ncurses/ncurses_dll.h
./ncurses/menu.h
./ncurses/etip.h
./ncurses/cursesp.h
./ncurses/cursesw.h
./ncurses/termcap.h
./ncurses/form.h
./ncurses/cursesapp.h
./ncurses/term.h
./ncurses/eti.h
./ncurses/nc_tparm.h
./ncurses/cursslk.h
./ncurses/panel.h
./ncurses/ncurses.h
./ncurses/term_entry.h
./ncurses/tic.h
[linux@linuxlearn:include]$ cd /lib/
[linux@linuxlearn:lib]$ ls | grep ncurse
libncurses.so.5
libncurses.so.5.7
libncursesw.so.5
libncursesw.so.5.7
[linux@linuxlearn:lib]$
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP