Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update by Jan.26th, 2021
Replace the compiler from WDK7.1 to EWDK10-2004.
The code will be compliant to C99 instead of Microsoft C98.
Add spectre-mitigation by compiler.
Add "Release/Free" compilation preset.
Add cleanup script.
  • Loading branch information
yat17006 committed Jan 26, 2021
1 parent 0ea1d6b commit 0935aed
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 45 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -51,4 +51,6 @@
modules.order
Module.symvers
Mkfile.old
dkms.conf
dkms.conf

bin/
11 changes: 7 additions & 4 deletions README.md
Expand Up @@ -18,7 +18,7 @@ To virtualize the processor, we implement the VMCB structure. VMCB is the acrony
- Register File, including GPR and FPU
- Execution Control, controlling the behavior of vCPU

Duly note that mipsivm simulates in LE byte order.
Duly note that mipsivm simulates in `Little-Endian` byte order.

### Glossary of Processor Virtualization
| Acronyms | Abbreviated for | Explanation |
Expand Down Expand Up @@ -70,6 +70,7 @@ Each PTE is an 8-byte entry. There are 512 PTEs. For each entry, there are 64 bi
| PTE | Page-Table Entry | The first level of address-translation |
| PDE | Page-Directory Entry | The second level of address-translation |
| PDPTE | Page-Directory Pointer Table Entry | The third level of address-translation |
| XTLB | Execution Translate Lookaside Buffer | TLB that accelerates instruction fetching |

## FAQ
Following lists the frequently asked questions, and corresponding answers.
Expand All @@ -82,6 +83,7 @@ Yes, there is. The famous PCSX2 is a free and open-source PlayStation 2 (PS2) em

### What big difference does this project make in comparison to CSE3666 assignment?
- There is access-controlled memory-virtualization feature.
- There is a simple implementation of TLB for instruction fetching.
- This project is written in C programming language.
- This software is implemented by inspirations from AMD64 architecture.
- This project aims to support more instructions.
Expand All @@ -92,8 +94,9 @@ If it is your first time to build mipsivm, you will have to execute `build_prep.
Currently, mipsivm supports 64-bit Windows.

### Windows
To build mipsivm for Windows, you will need to install [Windows Driver Kit 7.1.0](https://www.microsoft.com/en-us/download/details.aspx?id=11800) to default path on C drive. Compiler of WDK 7.1.0 can be considered as Visual C++ 2008 with a minor update. <br>
Execute `compchk_win7x64.bat` to compile mipsivm with `Debug/Checked` (unoptimized) compilation preset.
To build mipsivm for Windows, you will need to install [Enterprise Windows Driver Kit 10](https://docs.microsoft.com/en-us/legal/windows/hardware/enterprise-wdk-license-2019) and mount it to T disk. Make sure you downloaded EWDK 10 version 2004 with Visual Studio Tools 16.7. <br>
Execute `compchk_win10x64.bat` to compile mipsivm with `Debug/Checked` (unoptimized) compilation preset. <br>
Execute `compfre_win10x64.bat` to compile mipsivm with `Release/Free` (optimized) compilation preset.

## Command-Line Argument
Here list all command-line arguments.
Expand All @@ -104,7 +107,7 @@ Here list all command-line arguments.
Following runtime presets are available:

### MARS Runtime Preset
MARS, acronym that stands for MIPS Assembler and Runtime Simulator, is an MIPS Assembly Development IDE written by Dr. Pete Sanderson and Dr.Ken Vollmar at Missouri State University. This preset would let mipsivm to simulate the MARS environment. <br>
MARS, acronym that stands for MIPS Assembler and Runtime Simulator, is an MIPS Assembly Development IDE written by Dr. Pete Sanderson and Dr. Ken Vollmar at Missouri State University. This preset would let mipsivm to simulate the MARS environment. <br>
MARS runtime preset simulates the program in user-mode. It is a uniprocessor preset - no multi-processing is available. <br>
Here list command-line arguments specific to MARS Runtime Preset.

Expand Down
8 changes: 5 additions & 3 deletions build_prep.bat
@@ -1,14 +1,16 @@
@echo off

title Compiling mipsivm, Checked Build, 64-Bit Windows (AMD64 Architecture)
title Preparing Compilation of Project mipsivm
echo Project: mipsivm
echo Platform: Universal
echo Preset: Preparation
pause

mkdir .\bin
mkdir .\bin\compchk_win7x64
mkdir .\bin\compchk_win7x64\Intermediate
mkdir .\bin\compchk_win10x64
mkdir .\bin\compchk_win10x64\Intermediate
mkdir .\bin\compfre_win10x64
mkdir .\bin\compfre_win10x64\Intermediate

echo Completed!
pause.
15 changes: 15 additions & 0 deletions cleanup.bat
@@ -0,0 +1,15 @@
@echo off

title mipsivm Cleanup
echo Project: mipsivm
echo Platform: Universal (Non-Binary Build)
echo Preset: Cleanup
echo Powered by zero.tangptr@gmail.com
echo Warning: All compiled binaries, including intermediate files, will be deleted!
pause.

echo Performing cleanup...
del .\bin /q /s

echo Cleanup Completed!
pause.
33 changes: 33 additions & 0 deletions compchk_win10x64.bat
@@ -0,0 +1,33 @@
@echo off
set ddkpath=T:\Program Files\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110
set path=%ddkpath%\bin\Hostx64\x64;T:\Program Files\Windows Kits\10\bin\10.0.19041.0\x64;%path%
set incpath=T:\Program Files\Windows Kits\10\Include\10.0.19041.0
set libpath=T:\Program Files\Windows Kits\10\Lib\10.0.19041.0
set binpath=.\bin\compchk_win10x64
set objpath=.\bin\compchk_win10x64\Intermediate

title Compiling mipsivm, Checked Build, 64-Bit Windows (AMD64 Architecture)
echo Project: mipsivm
echo Platform: 64-Bit Windows
echo Preset: Debug/Checked Build
pause

echo ============Start Compiling============
cl .\src\xpf\windows\system.c /I"%incpath%\shared" /I"%incpath%\ucrt" /I"%incpath%\um" /I"%ddkpath%\include" /I".\src\include" /Zi /nologo /W3 /WX /Od /D"_MBCS" /D"_WIN64" /D"_M_AMD64" /D"_AMD64_" /D"_CRT_SECURE_NO_WARNINGS" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\system.cod" /Fo"%objpath%\system.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\entry.c /I"%incpath%\shared" /I"%incpath%\ucrt" /I"%incpath%\um" /I"%ddkpath%\include" /I".\src\include" /Zi /nologo /W3 /WX /Od /D"_msvc" /D"_amd64" /D"_CRT_SECURE_NO_WARNINGS" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\entry.cod" /Fo"%objpath%\entry.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\vcpu.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /Od /D"_msvc" /D"_amd64" /D"_mips_hvm" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\vcpu.cod" /Fo"%objpath%\vcpu.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\mars.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /Od /D"_msvc" /D"_amd64" /D"_mips_hvm_mars" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\mars.cod" /Fo"%objpath%\mars.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\sim-r.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /Od /D"_msvc" /D"_amd64" /D"_mips_simr" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\sim-r.cod" /Fo"%objpath%\sim-r.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\sim-i.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /Od /D"_msvc" /D"_amd64" /D"_mips_simi" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\sim-i.cod" /Fo"%objpath%\sim-i.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\sim-j.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /Od /D"_msvc" /D"_amd64" /D"_mips_simj" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\sim-j.cod" /Fo"%objpath%\sim-j.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

echo ============Start Linking============
link "%objpath%\*.obj" /LIBPATH:"%libpath%\um\x64" /LIBPATH:"%libpath%\ucrt\x64" /LIBPATH:"%ddkpath%\lib\x64" /NOLOGO /DEBUG /PDB:"%objpath%\mipsivm.pdb" /INCREMENTAL:NO /OUT:"%binpath%\mipsivm.exe" /SUBSYSTEM:CONSOLE /Machine:X64 /ERRORREPORT:QUEUE

pause
32 changes: 0 additions & 32 deletions compchk_win7x64.bat

This file was deleted.

33 changes: 33 additions & 0 deletions compfre_win10x64.bat
@@ -0,0 +1,33 @@
@echo off
set ddkpath=T:\Program Files\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110
set path=%ddkpath%\bin\Hostx64\x64;T:\Program Files\Windows Kits\10\bin\10.0.19041.0\x64;%path%
set incpath=T:\Program Files\Windows Kits\10\Include\10.0.19041.0
set libpath=T:\Program Files\Windows Kits\10\Lib\10.0.19041.0
set binpath=.\bin\compfre_win10x64
set objpath=.\bin\compfre_win10x64\Intermediate

title Compiling mipsivm, Free Build, 64-Bit Windows (AMD64 Architecture)
echo Project: mipsivm
echo Platform: 64-Bit Windows
echo Preset: Release/Free Build
pause

echo ============Start Compiling============
cl .\src\xpf\windows\system.c /I"%incpath%\shared" /I"%incpath%\ucrt" /I"%incpath%\um" /I"%ddkpath%\include" /I".\src\include" /Zi /nologo /W3 /WX /O2 /D"_MBCS" /D"_WIN64" /D"_M_AMD64" /D"_AMD64_" /D"_CRT_SECURE_NO_WARNINGS" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\system.cod" /Fo"%objpath%\system.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\entry.c /I"%incpath%\shared" /I"%incpath%\ucrt" /I"%incpath%\um" /I"%ddkpath%\include" /I".\src\include" /Zi /nologo /W3 /WX /O2 /D"_msvc" /D"_amd64" /D"_CRT_SECURE_NO_WARNINGS" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\entry.cod" /Fo"%objpath%\entry.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\vcpu.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /O2 /D"_msvc" /D"_amd64" /D"_mips_hvm" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\vcpu.cod" /Fo"%objpath%\vcpu.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\mars.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /O2 /D"_msvc" /D"_amd64" /D"_mips_hvm_mars" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\mars.cod" /Fo"%objpath%\mars.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\sim-r.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /O2 /D"_msvc" /D"_amd64" /D"_mips_simr" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\sim-r.cod" /Fo"%objpath%\sim-r.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\sim-i.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /O2 /D"_msvc" /D"_amd64" /D"_mips_simi" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\sim-i.cod" /Fo"%objpath%\sim-i.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

cl .\src\sim-j.c /I".\src\include" /Zi /nologo /W3 /WX /Oi /O2 /D"_msvc" /D"_amd64" /D"_mips_simj" /Zc:wchar_t /Zc:forScope /FAcs /Fa"%objpath%\sim-j.cod" /Fo"%objpath%\sim-j.obj" /Fd"%objpath%\vc140.pdb" /Qspectre /GS- /Gd /TC /c /errorReport:queue

echo ============Start Linking============
link "%objpath%\*.obj" /LIBPATH:"%libpath%\um\x64" /LIBPATH:"%libpath%\ucrt\x64" /LIBPATH:"%ddkpath%\lib\x64" /NOLOGO /DEBUG /PDB:"%objpath%\mipsivm.pdb" /INCREMENTAL:NO /OUT:"%binpath%\mipsivm.exe" /SUBSYSTEM:CONSOLE /Machine:X64 /ERRORREPORT:QUEUE

pause
1 change: 1 addition & 0 deletions src/mars.c
Expand Up @@ -188,6 +188,7 @@ void mips_run_mars_vm()
sim_printf("Guest Ticks Elapsed: %lld\n",vm.vcpu.tsc);
tsc_diff=t2-t1;
sim_printf("Host Ticks Elapsed: %lld\n",tsc_diff);
sim_printf("XTLB Hits: %lld\tMisses: %lld\n",vm.vcpu.xtlb.hits,vm.vcpu.xtlb.misses);
cpi=(double)vm.vcpu.tsc/(double)vm.vcpu.eic;
sim_printf("Guest Program CPI: %f (Higher CPI indicates less efficiency in program)\n",cpi);
ghr=(double)vm.vcpu.tsc/(double)tsc_diff;
Expand Down
7 changes: 2 additions & 5 deletions src/vcpu.c
Expand Up @@ -95,14 +95,12 @@ bool mips_npt_edit_entry(vmcb_p vcpu,u32 gpa,void* hva,bool r,bool w,bool x)
void mips_npt_cleanup(vmcb_p vcpu)
{
#if defined(_amd64)
u32 i=0;
for(;i<4;i++)
for(u32 i=0;i<4;i++)
{
l3p_pde_p pdeb=(l3p_pde_p)(vcpu->npt_base[i].pde_page<<12);
if(pdeb)
{
u32 j=0;
for(;j<512;j++)
for(u32 j=0;j<512;j++)
{
l3p_pte_p pteb=(l3p_pte_p)(pdeb[j].pte_page<<12);
if(pteb)free_page(pteb);
Expand Down Expand Up @@ -145,7 +143,6 @@ void mips_vcpu_dump_state(vmcb_p vcpu)
sim_printf("hi\t\t0x%08X\n",vcpu->gpr.v.hi);
sim_printf("lo\t\t0x%08X\n",vcpu->gpr.v.lo);
sim_printf("pc\t\t0x%08X\n",vcpu->gpr.pc);
sim_printf("XTLB Hits: %lld\tMisses: %lld\n",vcpu->xtlb.hits,vcpu->xtlb.misses);
sim_printf("======================Dump Complete======================\n");
}

Expand Down

0 comments on commit 0935aed

Please sign in to comment.