Skip to content
Permalink
309c13ab73
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
162 lines (147 sloc) 3.16 KB
/*
mipsivm - MIPS Interpreting Virtual Machine
Copyright 2018-2020, Yaotian "Zero" Tang. All rights reserved.
This file is the entry module of mipsivm program.
This program is distributed in the hope that it will be useful, but
without any warranty (no matter implied warranty or merchantability
or fitness for a particular purpose, etc.).
File Location: /entry.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "include/midef.h"
#include "include/devkit.h"
void cdecl sim_printf(const char* format,...)
{
va_list arg_list;
va_start(arg_list,format);
vprintf(format,arg_list);
va_end(arg_list);
}
i32 sim_readint()
{
int x=0;
scanf("%d",&x);
return x;
}
float sim_readfloat()
{
float x=0.0;
scanf("%f",&x);
return x;
}
double sim_readdouble()
{
double x=0.0;
scanf("%lf",&x);
return x;
}
void sim_readstring(char* string,u32 limit)
{
fgets(string,limit,stdin);
}
char sim_readchar()
{
return (char)getc(stdin);
}
void sim_setseed(u32 seed)
{
srand(seed);
}
u32 sim_getrand()
{
return rand();
}
void print_compiler()
{
#if defined(_msvc)
int major=_MSC_VER/100;
int minor=_MSC_VER%100;
int build=_MSC_FULL_VER%100000;
printf("Compiler Version: Microsoft Visual C++ %02d.%02d.%05d.%d\n",major,minor,build,_MSC_BUILD);
#endif
printf("Compilation Date: %s %s\n",__DATE__,__TIME__);
}
int main(int argc,char* argv[],char* envp[])
{
int i;
bool nologo=false;
char* runtime="mars";
char* data_path=null;
char* text_path=null;
int stack_size=0x10000;
for(i=1;i<argc;i++)
{
if(_stricmp(argv[i],"/nologo")==0)
nologo=true;
else if(_stricmp(argv[i],"/runtime")==0)
runtime=argv[++i];
else if(_stricmp(argv[i],"/ds")==0)
data_path=argv[++i];
else if(_stricmp(argv[i],"/ts")==0)
text_path=argv[++i];
else if(_stricmp(argv[i],"/ss")==0)
stack_size=atoi(argv[++i]);
else
printf("Warning: Unknown input Argument \"%s\"\n",argv[i]);
}
if(!nologo)
{
puts("Welcome to mipsivm!");
puts("Powered by Yaotian \"Zero\" Tang. All rights reserved.");
print_compiler();
}
if(_stricmp(runtime,"mars")==0)
{
void* ds_ptr=null;
void* ts_ptr=null;
u32 ds_size=0,ts_size=0;
puts("Simulation Preset: MARS");
if(data_path==null)
{
puts("Error P0010: No .data section file is specified!");
goto mars_final;
}
else
{
ds_ptr=load_section(data_path,&ds_size);
if(ds_ptr==null)
{
puts("Error P0011: Failed to load .data section!");
goto mars_final;
}
}
if(text_path==null)
{
puts("Error P0020: No .text section file is specified!");
goto mars_final;
}
else
{
ts_ptr=load_section(text_path,&ts_size);
if(ts_ptr==null)
{
puts("Error P0021: Failed to load .text section!");
goto mars_final;
}
}
puts("Program is loaded successfully!");
if(mips_init_mars_vm(ds_ptr,ts_ptr,ds_size,ts_size,stack_size)==false)
{
puts("Error R0000: Failed to initialize MARS Runtime VM!");
goto mars_final;
}
puts("MARS Environment is initialized successfully!");
mips_run_mars_vm();
mars_final:
unload_section(ds_ptr);
unload_section(ts_ptr);
}
else
{
printf("Error P0000: Unknown Runtime Preset \"%s\"\n",runtime);
}
system("pause");
}