Beispiel #1
0
static exception_t register_skyeye_module(char* module_name, char* filename, void* handler){
	exception_t ret;
	skyeye_module_t* node;
	skyeye_module_t* list;
	list = get_module_list();
	//skyeye_log(Debug_log, __FUNCTION__, "module_name = %s\n", module_name);
	if(module_name == NULL|| filename == NULL)
		return Invarg_exp;

	node = malloc(sizeof(skyeye_module_t));
	if(node == NULL){
		skyeye_log(Error_log, __FUNCTION__, get_exp_str(Malloc_exp));
		return Malloc_exp;
	}
		
	node->module_name = strdup(module_name);
	if(node->module_name == NULL){
		free(node);
		return Malloc_exp;
	}

	node->filename = strdup(filename);
	if(node->filename == NULL){
		free(node->module_name);
		free(node);
		return Malloc_exp;
	}
	
	node->handler = handler;

	node->next = list;
	set_module_list(node);
	return No_exp;
}
static bool arm_cpu_init()
{
	skyeye_config_t* config = get_current_config();
	machine_config_t *mach = config->mach;
	ARM_CPU_State* cpu = (ARM_CPU_State*)skyeye_mm_zero(sizeof(ARM_CPU_State));
	if(!cpu){
		skyeye_log(Critical_log, __FUNCTION__, "Can not allocate the enough memory for cpu.\n");
		skyeye_exit(-1);
	}
	mach->cpu_data = get_conf_obj_by_cast(cpu, "ARM_CPU_State");

	cpu->core_num = 1;

	if(!cpu->core_num){
		skyeye_log(Critical_log, __FUNCTION__, "Can not get the core number or set wrong mach name?\n");
		skyeye_exit(-1);
	}
	else
		cpu->core = (arm_core_t*)skyeye_mm(sizeof(arm_core_t) * cpu->core_num);
	/* TODO: zero the memory by malloc */

	if(!cpu->core){
		skyeye_log(Critical_log, __FUNCTION__, "Can not allocate memory for ppc core.\n");
		skyeye_exit(-1);
	}
	else
		skyeye_log(Info_log, __FUNCTION__, "Initilization for %d core\n", cpu->core_num);

	int i;
	for(i = 0; i < cpu->core_num; i++){
		arm_core_t* core = &cpu->core[i];
		arm_core_init(core, i);
		arm_dyncom_init(core);

		skyeye_exec_t* exec = create_exec();
		//exec->priv_data = get_conf_obj_by_cast(core, "arm_core_t");
		exec->priv_data = (conf_object_t*)core;
		exec->run =  (void (*)(conf_object_t*))per_cpu_step;
		exec->stop = (void (*)(conf_object_t*))per_cpu_stop;
		add_to_default_cell(exec);
	}

	cpu->boot_core_id = 0;

	return true;
}
Beispiel #3
0
//#define Check_Failed_Module 0
exception_t SKY_load_module(const char* module_filename){
	exception_t ret;
	char **module_name;
 	lt_dlhandle * handler;
	const char* err_str = NULL;
	//skyeye_log(Debug_log, __FUNCTION__, "module_filename = %s\n", module_filename);
#ifndef Check_Failed_Module
        handler = lt_dlopenext(module_filename);
#else
        //handler = dlopen(module_filename, RTLD_LAZY);
	handler = dlopen(module_filename, RTLD_NOW);
	if(handler == NULL){
		err_str = dlerror();
		skyeye_log(Error_log, __FUNCTION__, "dll error: %s\n", err_str);
	}
	return Dll_open_exp;
#endif
        if (handler == NULL)
        {
        	err_str = dlerrordup(err_str);
                skyeye_log(Warnning_log, __FUNCTION__, "%s\n", err_str);
		return Dll_open_exp;
        }
	
	module_name = lt_dlsym(handler, "skyeye_module");
	if((err_str = dlerrordup(err_str)) != NULL){
		skyeye_log(Warnning_log, __FUNCTION__, "dll error %s\n", err_str);
		skyeye_log(Warnning_log, __FUNCTION__, "Invalid module in file %s\n", module_filename);
		lt_dlclose(handler);
		return Invmod_exp;
	}
	//skyeye_log(Debug_log, __FUNCTION__, "Load module %s\n", *module_name);
		
	ret = register_skyeye_module(*module_name, module_filename, handler);
	if(ret != No_exp){
		lt_dlclose(handler);
		return ret;
	}
	return No_exp;	
}
Beispiel #4
0
/**
* @brief get the default architecture supported by skyeye
*
* @return 
*/
generic_arch_t* get_default_arch(){
	int i;
	for (i = 0; i < MAX_SUPP_ARCH; i++) {
        	if (skyeye_archs[i] == NULL)
                	continue;
		if (!strncmp
                    (default_arch_name, skyeye_archs[i]->arch_name, MAX_PARAM_NAME)) {
                        return skyeye_archs[i];
                }
        }
	skyeye_log(Warning_log, __FUNCTION__, "No default arch is found.\n");
	return NULL;
}
Beispiel #5
0
void skyeye_stepi(int steps){
	/* FIXME, that is not true for variable length of ISA, so get_next_pc should implemented for every core  */
	generic_arch_t* arch_instance = get_arch_instance("");
	/* we do not have valid arch_instance now */
	if(arch_instance == NULL){
		return;
	}
	if(arch_instance->get_step == NULL){
		printf(Warnning_log, __FUNCTION__, "The arch have not implemented get_step.\n");
		return;
	}
	stopped_step  = arch_instance->get_step() + steps;
	skyeye_log(Debug_log, __FUNCTION__, "stopped_step=%d\n", stopped_step);
	SIM_continue(arch_instance);
}
Beispiel #6
0
void SKY_load_all_modules(char* lib_dir, char* suffix){
	/* we assume the length of dirname + filename does not over 1024 */
	char full_filename[1024];
	char* lib_suffix;
	/* Find all the module under lib_dir */
	DIR *module_dir = opendir(lib_dir);
	exception_t exp;
	/*FIXME we should throw some exception. */
	if(module_dir == NULL)
		return;
	if(suffix == NULL)
		lib_suffix = Default_libsuffix;
	else
		lib_suffix = suffix;	
	struct dirent* dir_ent;
	while((dir_ent = readdir(module_dir)) != NULL){
		char* mod_name = dir_ent->d_name;
		/* exclude the library not end with lib_suffix */
		char* suffix = strrchr(mod_name, '.');
		if(suffix == NULL)
				continue;
		else{
			//skyeye_log(Debug_log, __FUNCTION__, "file suffix=%s\n", suffix);
			if(strcmp(suffix, lib_suffix))
				continue;
		}
			/* exclude the reserved library */
		if(!strncmp(mod_name, Reserved_libprefix, strlen(Reserved_libprefix)))
			continue;

		/* contruct the full filename for module */
		int lib_dir_len = strlen(lib_dir);
		memset(&full_filename[0], '\0', 1024);
		strncpy(&full_filename[0], lib_dir, lib_dir_len);	
		full_filename[lib_dir_len] = Dir_splitter;
		full_filename[lib_dir_len + 1] = '\0';
		//skyeye_log(Debug_log, __FUNCTION__, "1 full_filename=%s\n", full_filename);
		strncat(full_filename, mod_name, strlen(mod_name) + 1);
		//skyeye_log(Debug_log, __FUNCTION__, "full_filename=%s\n", full_filename);
		/* Try to load a module */
		exp = SKY_load_module(full_filename);
		if(exp != No_exp)
			skyeye_log(Info_log, __FUNCTION__, "Can not load module from file %s.\n", dir_ent->d_name);
		//}
	}
	closedir(module_dir);
}
Beispiel #7
0
int
do_mach_option (skyeye_option_t * this_option, int num_params,
                const char *params[])
{
        int ret;
        machine_config_t *mach = get_mach(params[0]);
	skyeye_config_t* config = get_current_config();
	if(mach != NULL){
		config->mach = mach;
		skyeye_log(Info_log,__FUNCTION__,"mach info: name %s, mach_init addr %p\n", config->mach->machine_name, config->mach->mach_init);
		ret = 0;
	}
        else{
                SKYEYE_ERR ("Error: Unkonw mach name \"%s\"\n", params[0]);
		ret = -1;
        }
        return ret;
}
Beispiel #8
0
/**
* @brief  initialization of a symbol table
*
* @param filename
* @param arch_name
*/
void init_symbol_table(char* filename, char* arch_name)
{
  long i,j, digit;
  ENTRY newentry, *oldentry;
  SYM_FUNC *symp;
  asymbol *symptr;
  int key;
  bfd *abfd;

	if(!filename){
		skyeye_info("Can not get correct kernel filename!Maybe your skyeye.conf have something wrong!\n");
		return;
	}
	abfd = bfd_openr (filename, get_bfd_target(arch_name));

	if (!bfd_check_format(abfd, bfd_object)) {
		bfd_close(abfd);
		skyeye_log(Debug_log, __FUNCTION__, "wrong bfd format\n");
		return;
		//exit(0);
	}

	storage_needed = bfd_get_symtab_upper_bound(abfd);
	if (storage_needed < 0){
		printf("FAIL\n");
		exit(0);
	}

	symbol_table = (asymbol **) skyeye_mm_zero (storage_needed);
	if(symbol_table == NULL){
		fprintf(stderr, "Can not alloc memory for symbol table.\n");
		exit(0);
	}

	number_of_symbols =
		bfd_canonicalize_symtab (abfd, symbol_table);
	kernel_number = number_of_symbols; /* <tktan> BUG200106022219 */

	if (number_of_symbols < 0){
		printf("FAIL\n");
		exit(0);
	}

	if (!hcreate(number_of_symbols << 1)) {
		printf("Not enough memory for hash table\n");
		exit(0);
	}
	for (i = 0; i < number_of_symbols; i++) {
		symptr = symbol_table[i] ;
		key = symptr->value + symptr->section->vma; // adjust for section address

    if (((i<kernel_number) && (symbol_table[i]->flags == 0x01)) || // <tktan> BUG200105172154, BUG200106022219 
	((i<kernel_number) && (symbol_table[i]->flags == 0x02)) || // <tktan> BUG200204051654
	(symbol_table[i]->flags & 0x10)) { // Is a function symbol
      // printf("%x %8x %s\n", symbol_table[i]->flags, key, symbol_table[i]->name);

      // ***********************************************************
      // This is converting the function symbol value to char string
      // and use it as a key in the GNU hash table
      // ********************************************************
      newentry.key = (char *) skyeye_mm_zero(9);
      for (j=0;j<8;j++) {
        newentry.key[j] = itoa_tab[((key) >> (j << 2)) & 0xf] ;
      }
      newentry.key[8] = 0 ;

      // *************************************************
      // This is allocating memory for a struct funcsym
      // *************************************************
      symp = (SYM_FUNC *) skyeye_mm_zero(sizeof(SYM_FUNC));
      newentry.data = (char *) symp; 
      symp->name = (char *) symbol_table[i]->name ;
      symp->total_cycle = 0;
      symp->total_energy = 0;
      symp->instances = 0;

      // ***********************************************
      // Insert into hash table
      // *******************************************
      /* <tktan> BUG200106022219 */
      oldentry = hsearch(newentry, FIND) ;
      if (oldentry) { // was entered
        // printf("Duplicate Symbol: %x %s\n", key, symp->name);
        oldentry->data = (char *) symp ;	
      } else if (!hsearch(newentry, ENTER)) { 
        printf("Insufficient memory\n");
        exit(0) ;
      }
    }
  }
Beispiel #9
0
exception_t
skyeye_read_config (char* skyeye_conf_filename)
{
	FILE *config_fd;
	char *ret;
	char line[MAX_STR];

	//chy 2005-07-30
	//char *config_file = DEFAULT_CONFIG_FILE;
	/*if (skyeye_config_filename == NULL)
		skyeye_config_filename = DEFAULT_CONFIG_FILE;
	*/
	//char *skyeye_config_filename = get_conf_filename();
	/* FIXME, maybe we should reset memmap in another place */
	reset_global_memmap();

	if (config_fd = fopen (skyeye_conf_filename, "r")) {
		int retval = 0;
		int len = 0;

		do {
			ret = fgets (line, sizeof (line) - 1, config_fd);
			line[sizeof (line) - 1] = '\0';
			len = strlen (line);
			if (len > 0)
				line[len - 1] = '\0';
			if ((ret != NULL) && strlen (line)) {
				if (parse_line_unformatted (line) < 0) {
					retval = -1;
					//break;	// quit parsing after first error
				}
			}
		}
		while (!feof (config_fd));
#if 0
		/* 2007-01-18 added by Anthony Lee: for new uart device frame */
		if(skyeye_config.uart.count == 0)
		{
#ifndef SKYEYE4ECLIPSE
			char tmp[] = "uart: mod=stdio";
#else
			char tmp[1024];
			snprintf(tmp, sizeof(tmp), "uart: mod=pipe, desc=%s",
				 inferior_io_terminal, inferior_io_terminal);
#endif
			if(parse_line_unformatted(tmp) < 0) retval = -1;
		}
#endif
		if (retval < 0) {
			/*
			fprintf (stderr,
				 "skyeye_read_config: config file %s have errors!\n",
				 skyeye_config.config_file);
			*/
			skyeye_log(Error_log, __FUNCTION__, "Config format is wrong.\n ");
			return Conf_format_exp;
		}
	}
	else {
		/* fprintf (stderr,
			 "Failed to open skyeye config file %s in the same directory\n",
			 skyeye_config.config_file);
		*/
		skyeye_log(Debug_log, __FUNCTION__, "filename=%s\n",  skyeye_conf_filename);
		return File_open_exp;
		/*
		perror ("error");
		usage ();
		display_all_support();
		return -1;
		*/
	}

	/* compatiable with the old config file that is no arch option available. */

	skyeye_config_t* config = get_current_config();
	if(config->arch == NULL){
		config->arch = get_default_arch();
	}

	return No_exp;
}
Beispiel #10
0
exception_t load_file(const char* filename, generic_address_t load_addr){
	FILE* f;
	uint8 data;
	int nread = 0;
	generic_address_t addr = load_addr;
	f = fopen(filename, "rb");
	if(f == NULL){
		skyeye_log(Error_log, __FUNCTION__, "Can not open file %s.\n", filename);
		return File_open_exp;
	}
	/* read a char and write it to the memory */
	while(nread = fread(&data, 1, 1, f)){
		if(bus_write(8, addr, data) != 0){
			/* error handler for address error */
			fclose(f);
			return Excess_range_exp;
		}
		addr++;
	}
	skyeye_log(Info_log, __FUNCTION__, "Load the file %s to the memory 0x%x\n", filename, load_addr);
	fclose(f);
#if 0 
		if (mb[bank].filename
		    && (f = fopen (mb[bank].filename, "rb"))) {
			if (fread
			    (global_memory.rom[bank], 1, mb[bank].len,
			     f) <= 0) {
				perror ("fread");
				fprintf (stderr,
					 "Failed to load '%s'\n",
					 mb[bank].filename);
				skyeye_exit (-1);
			}
			fclose (f);

			p = (char *) global_memory.rom[bank];
			s = 0;
			while (s < global_memory.rom_size[bank]) {
				generic_arch_t* arch_instance = get_arch_instance(NULL);
				if (arch_instance->endianess == Big_endian)	/*big enddian? */
					swap = ((uint32_t) p[3]) |
						(((uint32_t) p[2]) <<
						 8) | (((uint32_t)
							p[1]) << 16) |
						(((uint32_t) p[0]) <<
						 24);
				else
					swap = ((uint32_t) p[0]) |
						(((uint32_t) p[1]) <<
						 8) | (((uint32_t)
							p[2]) << 16) |
						(((uint32_t) p[3]) <<
						 24);
				*(uint32_t *) p = swap;
				p += 4;
				s += 4;
			}

				/*ywc 2004-03-30 */
				//printf("Loaded ROM %s\n", mb[bank].filename);
			if (mb[bank].type == MEMTYPE_FLASH) {
				printf ("Loaded FLASH %s\n",
					mb[bank].filename);
			}
			else if (mb[bank].type == MEMTYPE_RAM) {
				printf ("Loaded RAM   %s\n",
					mb[bank].filename);
			}
			else if (mb[bank].type == MEMTYPE_ROM) {
				printf ("Loaded ROM   %s\n",
					mb[bank].filename);
			}

		}
		else if (mb[bank].filename[0] != '\0') {
			perror (mb[bank].filename);
			fprintf (stderr,
				 "bank %d, Couldn't open boot ROM %s - execution will "
				 "commence with the debuger.\n", bank,
				 mb[bank].filename);
		}
#endif

	return No_exp;
}
Beispiel #11
0
int
do_deprecated_option (skyeye_option_t * this_option, int num_params,
		 const char *params[])
{
	skyeye_log(Warnning_log, __FUNCTION__, "Deprecated option. Do not use any more.\n");
}
Beispiel #12
0
void SIM_start(void){
	sky_pref_t *pref;
	/* get the current preference for simulator */
	pref = get_skyeye_pref();
	skyeye_config_t* config = get_current_config();
	if(pref->conf_filename)
		skyeye_read_config(pref->conf_filename);

	if(config->arch == NULL){
		skyeye_log(Error_log, __FUNCTION__, "Should provide valid arch option in your config file.\n");
		return;
	}
	generic_arch_t *arch_instance = get_arch_instance(config->arch->arch_name);

	if(config->mach == NULL){
		skyeye_log(Error_log, __FUNCTION__, "Should provide valid mach option in your config file.\n");
		return;
	}

	arch_instance->init();
	
	/* reset all the memory */
	mem_reset();

	config->mach->mach_init(arch_instance, config->mach);
	/* reset current arch_instanc */
	arch_instance->reset();
	/* reset all the values of mach */
	io_reset(arch_instance);
	
	if(pref->exec_file){
		exception_t ret;
		/* 
		 * If no relocation is indicated, we will load elf file by 
		 * virtual address
		 */
		if((((~pref->exec_load_mask) & pref->exec_load_base) == 0x0) &&
			(arch_instance->mmu_write != NULL))
			ret = load_elf(pref->exec_file, Virt_addr);
		else
			ret = load_elf(pref->exec_file, Phys_addr);
	}

	/* set pc from config */
	generic_address_t pc = (config->start_address & pref->exec_load_mask)|pref->exec_load_base; 
	skyeye_log(Info_log, __FUNCTION__, "Set PC to the address 0x%x\n", pc);
	arch_instance->set_pc(pc);

	/* Call bootmach callback */
	exec_callback(Bootmach_callback, arch_instance);	

	pthread_t id;
	create_thread(skyeye_loop, arch_instance, &id);
	
	/* 
	 * At this time, if we set conf file, then we parse it
	 * Or do it later.
	 */

	/*
	if(pref->conf_filename)
		skyeye_read_config(pref->conf_filename);
	*/
#if 0	
	else{
		/* try to run in batch mode */
		if(skyeye_read_config(pref->conf_filename) == No_exp){