?? main.cpp
字號(hào):
/*************************************************************************
Copyright (C) 2002,2003,2004,2005 Wei Qin
See file COPYING for more information.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*************************************************************************/
#include <cstdio>
#include <csignal>
#include <cstring>
#include <cstdlib>
#include <armemul.h>
#include "config.h"
#if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#endif
using namespace emulator;
static void usage(char *fname)
{
char *cp;
if ((cp = strrchr(fname, '/'))!=NULL) cp++;
else cp = fname;
fprintf(stderr,
"**** " PACKAGE " Version " VERSION
" (C) 2002,2003,2004,2005 Wei Qin ****\n"
"usage : %s [-d] [-v] [-m num] [-f fpe-path] [-h]"
" <file name> <args...>\n"
" -d : debuging mode\n"
" -v : verbose\n"
" -m : maximum number of instructions to simulate\n"
" -f : FPE binary file path\n"
" -h : print this message and quit\n"
" file name : the ARM ELF32 program to simulate\n"
" args : arguments to the program\n", cp);
}
static arm_emulator *mltr = NULL;
static void sigint_handler(int signum)
{
if (mltr->is_running()) {
mltr->stop();
}
else if (mltr->is_debugging()) {
mltr->stop_debug();
}
else exit(0);
}
int main(int argc, char *argv[], char *envp[])
{
int i;
char *prog_name = NULL;
char *fpe_name = NULL;
bool verbose = false;
bool debuging = false;
UInt64 max_inum = (UInt64)-1;
void (*prev_sigint_handler)(int);
for(i = 1; i < argc; i++)
{
if(strcmp(argv[i], "-d") == 0) debuging = true; else
if(strcmp(argv[i], "-v") == 0) verbose = true; else
if(strcmp(argv[i], "-f") == 0) fpe_name = argv[++i]; else
if(strcmp(argv[i], "-m") == 0) max_inum = ato_uint64(argv[++i]); else
if(strcmp(argv[i], "-h") == 0) {usage(argv[0]); return 0;} else
if(!prog_name)
{
prog_name = argv[i];
break;
}
}
/* emulator instance */
if(prog_name)
{
arm_emulator ema(verbose, true);
mltr = &ema;
prev_sigint_handler = signal(SIGINT, sigint_handler);
ema.load_fpe(fpe_name);
ema.load_program(prog_name, argc - i, argv + i, envp);
if(debuging)
ema.debug();
else {
#if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
struct timeval begin_u, end_u, begin_s, end_s;
struct rusage usg;
float user_time, sys_time;
getrusage(RUSAGE_SELF, &usg);
begin_u = usg.ru_utime;
begin_s = usg.ru_stime;
#endif
UInt64 icount = ema.run_count(max_inum);
#if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
getrusage(RUSAGE_SELF, &usg);
end_u = usg.ru_utime;
end_s = usg.ru_stime;
user_time = (end_u.tv_sec+end_u.tv_usec/1000000.0)-
(begin_u.tv_sec+begin_u.tv_usec/1000000.0);
sys_time = (end_s.tv_sec+end_s.tv_usec/1000000.0)-
(begin_s.tv_sec+begin_s.tv_usec/1000000.0);
fprintf(stderr, "Total user time : %.3f sec.\n"
"Total system time: %.3f sec.\n"
"Simulation speed : %.3e inst/sec.\n",
user_time, sys_time, icount/(user_time+sys_time));
#endif
ema.dump_instruction_counters(stderr);
#ifdef EMUMEM_HASH
fprintf(stderr, "Total 4K memory pages allocated : %d\n",
ema.mem->get_page_count());
#endif
#ifdef EMUMEM_MMAP
fprintf(stderr, "Total 4M memory pages allocated : %d\n",
ema.mem->get_page_count());
#endif
}
if(prev_sigint_handler != SIG_ERR) signal(SIGINT, SIG_DFL);
}
else usage(argv[0]);
return 0;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -