⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skyeye.c

📁 skyeye-1.2-RC7-3的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, 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 ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public License alongwith this program; if not, write to the Free Software Foundation, Inc.,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  *//** * \author chenyu <yuchen@tsinghua.edu.cn> *  teawater <c7code-uc@yahoo.com.cn> add elf load function in 2005.08.30 *///#include "armdefs.h"//#include "armemu.h"#include <signal.h>#include <stdio.h>#include <stdarg.h>#include <stdlib.h>#include <string.h>#include "skyeye_types.h"#include "skyeye_defs.h"#include "skyeye_config.h"generic_arch_t *arch_instance;char *skyeye_config_filename = NULL;extern int skyeye_net_on;static int verbosity;int big_endian;static int mem_size = (1 << 21);static FILE *pf;int global_argc;char **global_argv;int stop_simulator = 0;int debugmode = 0;ARMwordARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr){}voidARMul_ConsolePrint (ARMul_State * state, const char *format, ...){}voidARMul_CallCheck (ARMul_State * state, ARMword cur_pc, ARMword to_pc,		 ARMword instr){}//chy 2005-08-01, borrow from wlm's 2005-07-26's changestatic voidbase_termios_exit (void){	//tcsetattr (STDIN_FILENO, TCSANOW, &(state->base_termios));}//chy 2005-08-01 ---------------------------------------------    static intinit (){	static int done;	int ret;	if (!done) {		done = 1;		/*some option should init before read config. e.g. uart option. *///chy 2005-08-01, borrow from wlm's 2005-07-26's change		initialize_all_devices ();		initialize_all_arch ();//chy 2005-08-01 ---------------------------------------------    		skyeye_option_init (&skyeye_config);		if((ret = skyeye_read_config()) < 0)			return ret;		arch_instance =			(generic_arch_t *) malloc (sizeof (generic_arch_t));		if (!arch_instance) {			printf ("malloc error!\n");			return -1;		}		arch_instance->init = skyeye_config.arch->init;		arch_instance->reset = skyeye_config.arch->reset;		arch_instance->step_once = skyeye_config.arch->step_once;		arch_instance->set_pc = skyeye_config.arch->set_pc;		arch_instance->get_pc = skyeye_config.arch->get_pc;		arch_instance->ICE_write_byte = skyeye_config.arch->ICE_write_byte;		arch_instance->ICE_read_byte = skyeye_config.arch->ICE_read_byte;		arch_instance->init ();		//chy:2003-08-19, after mach_init, because ARMul_Reset should after ARMul_SelectProcess		arch_instance->reset ();		}	return 1;}#include "armemu.h"extern ARMul_State * state;voidsim_resume (int step){	/*workaround here: we have different run mode on arm*/	if(!strcmp(skyeye_config.arch->arch_name, "arm")){		state->EndCondition = 0;		stop_simulator = 0;		if (step) {			state->Reg[15] = ARMul_DoInstr (state);			if (state->EndCondition == 0) {				//chy 20050729 ????				printf ("error in sim_resume for state->EndCondition");				skyeye_exit (-1);			}		}		else {			state->NextInstr = RESUME;	/* treat as PC change */			state->Reg[15] = ARMul_DoProg (state);		}		FLUSHPIPE;	}	/* other target simualtor step run*/	else {		do {			arch_instance->step_once ();		}while(!step);	}}//teawater add for load elf 2005.07.31------------------------------------------static inline voidtea_write (uint32_t addr, uint8_t * buffer, int size){	int i,fault;	for (i = 0; i < size; i++) {		fault=arch_instance->ICE_write_byte (addr + i, buffer[i]);		if(fault) {printf("SKYEYE: tea_write error!!!\n");skyeye_exit(-1);}	}}#ifdef NO_BFD#include <elf32.h>static inline voidtea_set(uint32_t addr, uint8_t value, int size){   int i,fault;   for (i = 0; i < size; i++) {	   	fault=arch_instance->ICE_write_byte (addr + i, value);		if(fault) {printf("SKYEYE: tea_set error!!!\n");skyeye_exit(-1);}   }}/* These function convert little-endian ELF datatypes   into host endianess values. */#ifdef HOST_IS_BIG_ENDIANuint16_te2h16(uint16_t x){    return ((x & 0xff) << 8) | (x >> 8);}uint32_te2h32(uint32_t x){    return ((x & 0xff)         << 24) | 	(((x >> 8) & 0xff) << 16)  |	(((x >> 16) & 0xff) << 8)  |	(((x >> 24) & 0xff));}#elseuint16_te2h16(uint16_t x) {	return x;}uint32_te2h32(uint32_t x) {	return x;}#endifstatic intelf32_checkFile(struct Elf32_Header *file){   if (file->e_ident[EI_MAG0] != ELFMAG0       || file->e_ident[EI_MAG1] != ELFMAG1       || file->e_ident[EI_MAG2] != ELFMAG2       || file->e_ident[EI_MAG3] != ELFMAG3)      return -1;  /* not an elf file */   if (file->e_ident[EI_CLASS] != ELFCLASS32)      return -2;  /* not 32-bit file */   if (e2h16(file->e_machine) != EM_ARM)      return -3;   return 0;      /* elf file looks OK */}static inttea_load_exec(const char *file){   int ret = -1;   int i;   int tmp_fd;   int r;   struct Elf32_Header *elfFile;   struct stat stat;   struct Elf32_Phdr *segments;   tmp_fd = open(file, O_RDONLY);   if (tmp_fd == -1) {      fprintf (stderr, "open %s error: %s\n", file, strerror(errno));      goto out;   }   fstat(tmp_fd, &stat);   /* malloc */   elfFile = mmap(NULL, stat.st_size, PROT_READ, MAP_PRIVATE, tmp_fd, 0);   if (elfFile == NULL) {      fprintf (stderr, "mmap error: %s\n", strerror(errno));      goto out;   }   r = elf32_checkFile(elfFile);   if (r != 0) {       fprintf (stderr, "elf_checkFile failed: %d\n", r);       goto out;   }   segments = (struct Elf32_Phdr*) (uintptr_t) (((uintptr_t) elfFile) + e2h32(elfFile->e_phoff));   for(i=0; i < e2h16(elfFile->e_phnum); i++) {      /* Load that section */      uint32_t dest;      char *src;      size_t len = e2h32(segments[i].p_filesz);      dest = e2h32(segments[i].p_paddr);      src = ((char*) elfFile) + e2h32(segments[i].p_offset);      tea_write(dest, src, len);      dest += len;      tea_set(dest, 0, len);   }   if (skyeye_config.start_address == 0) {       skyeye_config.start_address = e2h32(elfFile->e_entry);   }   ret = 0;out:   if (tmp_fd != -1)      close(tmp_fd);   if (elfFile)      munmap(elfFile, stat.st_size);   return(ret);}#else//teawater add for load elf 2005.07.31------------------------------------------#include <bfd.h>static inttea_load_exec (const char *file){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -