📄 skyeye.c
字号:
int ret = -1; bfd *tmp_bfd = NULL; asection *s; char *tmp_str = NULL; //open tmp_bfd = bfd_openr (file, NULL); if (tmp_bfd == NULL) { fprintf (stderr, "open %s error: %s\n", file, bfd_errmsg (bfd_get_error ())); goto out; } if (!bfd_check_format (tmp_bfd, bfd_object)) { /*FIXME:In freebsd, if bfd_errno is bfd_error_file_ambiguously_recognized, * though bfd can't recognize this format, we should try to load file.*/ if (bfd_get_error () != bfd_error_file_ambiguously_recognized) { fprintf (stderr, "check format of %s error: %s\n", file, bfd_errmsg (bfd_get_error ())); goto out; } } printf ("exec file \"%s\"'s format is %s.\n", file, tmp_bfd->xvec->name); //load for (s = tmp_bfd->sections; s; s = s->next) { if (bfd_get_section_flags (tmp_bfd, s) & (SEC_LOAD)) { if (bfd_section_lma (tmp_bfd, s) != bfd_section_vma (tmp_bfd, s)) { printf ("load section %s: lma = 0x%08x (vma = 0x%08x) size = 0x%08x.\n", bfd_section_name (tmp_bfd, s), (unsigned int) bfd_section_lma (tmp_bfd, s), (unsigned int) bfd_section_vma (tmp_bfd, s), (unsigned int) bfd_section_size (tmp_bfd, s)); } else { printf ("load section %s: addr = 0x%08x size = 0x%08x.\n", bfd_section_name (tmp_bfd, s), (unsigned int) bfd_section_lma (tmp_bfd, s), (unsigned int) bfd_section_size (tmp_bfd, s)); } if (bfd_section_size (tmp_bfd, s) > 0) { tmp_str = (char *) malloc (bfd_section_size (tmp_bfd, s)); if (!tmp_str) { fprintf (stderr, "alloc memory to load session %s error.\n", bfd_section_name (tmp_bfd, s)); goto out; } if (!bfd_get_section_contents (tmp_bfd, s, tmp_str, 0, bfd_section_size (tmp_bfd, s))) { fprintf (stderr, "get session %s content error: %s\n", bfd_section_name (tmp_bfd, s), bfd_errmsg (bfd_get_error ())); goto out; } tea_write (bfd_section_vma (tmp_bfd, s), tmp_str, bfd_section_size (tmp_bfd, s)); free (tmp_str); tmp_str = NULL; } } else { printf ("not load section %s: addr = 0x%08x size = 0x%08x .\n", bfd_section_name (tmp_bfd, s), (unsigned int) bfd_section_vma (tmp_bfd, s), (unsigned int) bfd_section_size (tmp_bfd, s)); } } //set strat address if (skyeye_config.start_address == 0) { skyeye_config.start_address = bfd_get_start_address (tmp_bfd); printf ("start addr is set to 0x%08x by exec file.\n", (unsigned int) skyeye_config.start_address); } ret = 0; out: if (tmp_str) free (tmp_str); if (tmp_bfd) bfd_close (tmp_bfd); return (ret);}#endif//AJ2D--------------------------------------------------------------------------voidusage (){ fprintf (stderr, "------------------------- SkyEye -V1.2 ---------------------------\n"); fprintf (stderr, "Usage: SkyEye [options] -e program [program args]\n"); fprintf (stderr, "Default mode is STANDALONE mode\n"); fprintf (stderr, "------------------------------------------------------------------\n"); fprintf (stderr, "Options:\n");//teawater add for load elf 2005.07.31------------------------------------------ fprintf (stderr, "-e exec-file the (ELF executable format)kernel file name.\n");//AJ2D-------------------------------------------------------------------------- fprintf (stderr, "-d in GDB Server mode (can be connected by GDB).\n"); fprintf (stderr, "-c config-file the skyeye configure file name.\n"); fprintf (stderr, "-h The SkyEye command options, and ARCHs and CPUs simulated\n"); fprintf (stderr, "------------------------------------------------------------------\n");}extern cpu_config_t bfin_cpu[];extern machine_config_t arm_machines[];void display_all_support(){ int i; fprintf (stderr, "----------- Architectures and CPUs simulated by SkyEye-------------\n"); fprintf (stderr, "-------- ARM architectures ---------\n"); for(i = 0; arm_machines[i].machine_name!=NULL ; i++) fprintf(stderr, "%s \n",arm_machines[i].machine_name); fprintf (stderr, "-------- BlackFin architectures ----\n"); for(i = 0; bfin_cpu[i].cpu_name!=NULL ; i++) fprintf(stderr, "%s \n",bfin_cpu[i].cpu_name);}//chy 2006-04-11 terminal old valuestruct termios skyeye_termios_old;void skyeye_exit(int ret){ /* Restore the original terminal settings */ tcsetattr (0, TCSANOW, &skyeye_termios_old); exit( ret);}intmain (int argc, char **argv){ int c; int index; int ret; opterr = 0;//teawater add for load elf 2005.07.31------------------------------------------ char *exec_file = NULL; /* Set the terminal for non-blocking per-character (not per-line) input, no echo */ struct termios old, tmp; tcgetattr (0, &old); tcgetattr (0, &skyeye_termios_old); tcgetattr (0, &tmp); tmp.c_lflag &= ~ICANON; tmp.c_lflag |= ISIG; tmp.c_lflag &= ~ECHO; tmp.c_cc[VMIN] = 0; tmp.c_cc[VTIME] = 0; tcsetattr (0, TCSANOW, &tmp); while ((c = getopt (argc, argv, "e:dc:h")) != -1)//AJ2D-------------------------------------------------------------------------- switch (c) {//teawater add for load elf 2005.07.31------------------------------------------ case 'e': exec_file = optarg; break;//AJ2D-------------------------------------------------------------------------- case 'd': debugmode = 1; break; case 'h': usage (); display_all_support(); goto exit_skyeye; case 'c': skyeye_config_filename = optarg; break; case '?': if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); ret=1; goto exit_skyeye; /* case 'v': display_all_support(); goto exit_skyeye; */ default: fprintf(stderr, "Default option .....\n"); ret=1; goto exit_skyeye; } //usage (); if(debugmode) printf ("debugmode= %d, filename = %s, server TCP port is 12345\n", debugmode, skyeye_config_filename); if(exec_file == NULL){ printf ("SKYEYE: If you have ELF kernel file, please use -e option to indicate your ELF format kernel filename \n"); printf ("SKYEYE: If you only have kernel binary image, you should put the filename of kernel binary image in skyeye.conf file\n"); } if (skyeye_config_filename == NULL) skyeye_config_filename = DEFAULT_CONFIG_FILE; for (index = optind; index < argc; index++) printf ("Non-option argument %s\n", argv[index]); //teawater add DBCT_TEST_SPEED 2005.10.04---------------------------------------#ifdef DBCT_TEST_SPEED { if (!dbct_test_speed_state) { //init timer struct itimerval value; struct sigaction act; dbct_test_speed_state = state; state->instr_count = 0; act.sa_handler = dbct_test_speed_sig; act.sa_flags = SA_RESTART; //cygwin don't support ITIMER_VIRTUAL or ITIMER_PROF#ifndef __CYGWIN__ if (sigaction(SIGVTALRM, &act, NULL) == -1) {#else if (sigaction(SIGALRM, &act, NULL) == -1) {#endif //__CYGWIN__ fprintf(stderr, "init timer error.\n"); goto exit_skyeye; } if (skyeye_config.dbct_test_speed_sec) { value.it_value.tv_sec = skyeye_config.dbct_test_speed_sec; } else { value.it_value.tv_sec = DBCT_TEST_SPEED_SEC; } printf("dbct_test_speed_sec = %ld\n", value.it_value.tv_sec); value.it_value.tv_usec = 0; value.it_interval.tv_sec = 0; value.it_interval.tv_usec = 0;#ifndef __CYGWIN__ if (setitimer(ITIMER_VIRTUAL, &value, NULL) == -1) {#else if (setitimer(ITIMER_REAL, &value, NULL) == -1) {#endif //__CYGWIN__ fprintf(stderr, "init timer error.\n"); goto exit_skyeye; } } }#endif //DBCT_TEST_SPEED//AJ2D-------------------------------------------------------------------------- /*do some initialization*/ if((ret = init ()) < 0) goto exit_skyeye;//teawater add for load elf 2005.07.31------------------------------------------ if (exec_file) { if (tea_load_exec (exec_file)) { fprintf (stderr, "load \"%s\" error\n", exec_file); goto exit_skyeye; } }//AJ2D-------------------------------------------------------------------------- if (skyeye_config.start_address != 0) arch_instance->set_pc (skyeye_config.start_address); fflush(stdout); if (debugmode == 0) sim_resume (0); else sim_debug ();exit_skyeye: /* Restore the original terminal settings */ tcsetattr (0, TCSANOW, &old); return ret;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -