ylide 发表于 2013-10-11 11:09

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

本帖最后由 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:
https://raw.github.com/cshaxu/nxvm/master/doc/image/nxvm_on_surface_rt_arm.jpg

在64位Windows的命令提示符窗口中运行DOS:
http://img.blog.csdn.net/20131010040422484?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3NoYXh1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast

在Linux终端里跑MS-DOS:
http://img.blog.csdn.net/20131010041443015?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3NoYXh1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast
http://img.blog.csdn.net/20131010041457156?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3NoYXh1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast

DOS运行在HMA:
http://img.blog.csdn.net/20131010040454203?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3NoYXh1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast


TT打字程序:
http://img.blog.csdn.net/20131010040505734?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3NoYXh1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast

俄罗斯方块:
http://img.blog.csdn.net/20131010040535187?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3NoYXh1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast


Windows窗口模式下的点阵字体模拟:
http://img.blog.csdn.net/20131010041400593?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3NoYXh1/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast

fly3ds 发表于 2013-10-13 12:13

编程功力很强,不过程序实用性似乎不太大。:wink:

fly3ds 发表于 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: *** Error 1

这个应该怎么弄呢?

goingstudy 发表于 2013-10-14 11:37

能说一下大体的架构吗?

liuiang 发表于 2013-10-14 11:45

专程来拜楼主的。

true_casey 发表于 2013-10-18 09:36

我毕业设计差点就是选择的做一个x86虚拟机,以后我也想做一个出来玩玩,楼主好厉害,赞一个.....:mrgreen:

fly3ds 发表于 2013-10-18 15:47

表瞎拜了!

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

ylide 发表于 2013-10-20 12:14

本帖最后由 ylide 于 2013-10-20 12:27 编辑

回复 7# fly3ds

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

ylide 发表于 2013-10-20 12:19

回复 4# goingstudy

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

fly3ds 发表于 2013-10-20 12:20

回复 9# ylide

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

    $ 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
$ cd /lib/
$ ls | grep ncurse
libncurses.so.5
libncurses.so.5.7
libncursesw.so.5
libncursesw.so.5.7
$
页: [1] 2 3 4 5
查看完整版本: 我也来发一款自己写的x86虚拟机(NXVM),能在win 7,linux和surface rt(ARM)下跑MS