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

📄 hw-properties.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* The common simulator framework for GDB, the GNU Debugger.   Copyright 2002 Free Software Foundation, Inc.   Contributed by Andrew Cagney and Red Hat.   This file is part of GDB.   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.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.  */#include "hw-main.h"#include "hw-base.h"#include "sim-io.h"#include "sim-assert.h"#ifdef HAVE_STRING_H#include <string.h>#else#ifdef HAVE_STRINGS_H#include <strings.h>#endif#endif#define TRACE(A,B)/* property entries */struct hw_property_data {  struct hw_property_data *next;  struct hw_property *property;  const void *init_array;  unsigned sizeof_init_array;};voidcreate_hw_property_data (struct hw *me){}voiddelete_hw_property_data (struct hw *me){}/* Device Properties: */static struct hw_property_data *find_property_data (struct hw *me,		    const char *property){  struct hw_property_data *entry;  ASSERT (property != NULL);  entry = me->properties_of_hw;  while (entry != NULL)    {      if (strcmp (entry->property->name, property) == 0)	return entry;      entry = entry->next;    }  return NULL;}static voidhw_add_property (struct hw *me,		 const char *property,		 hw_property_type type,		 const void *init_array,		 unsigned sizeof_init_array,		 const void *array,		 unsigned sizeof_array,		 const struct hw_property *original,		 object_disposition disposition){  struct hw_property_data *new_entry = NULL;  struct hw_property *new_value = NULL;    /* find the list end */  struct hw_property_data **insertion_point = &me->properties_of_hw;  while (*insertion_point != NULL)    {      if (strcmp ((*insertion_point)->property->name, property) == 0)	return;      insertion_point = &(*insertion_point)->next;    }    /* create a new value */  new_value = HW_ZALLOC (me, struct hw_property);  new_value->name = (char *) strdup (property);  new_value->type = type;  if (sizeof_array > 0)    {      void *new_array = hw_zalloc (me, sizeof_array);      memcpy (new_array, array, sizeof_array);      new_value->array = new_array;      new_value->sizeof_array = sizeof_array;    }  new_value->owner = me;  new_value->original = original;  new_value->disposition = disposition;    /* insert the value into the list */  new_entry = HW_ZALLOC (me, struct hw_property_data);  *insertion_point = new_entry;  if (sizeof_init_array > 0)    {      void *new_init_array = hw_zalloc (me, sizeof_init_array);      memcpy (new_init_array, init_array, sizeof_init_array);      new_entry->init_array = new_init_array;      new_entry->sizeof_init_array = sizeof_init_array;    }  new_entry->property = new_value;}static voidhw_set_property (struct hw *me,		 const char *property,		 hw_property_type type,		 const void *array,		 int sizeof_array){  /* find the property */  struct hw_property_data *entry = find_property_data (me, property);  if (entry != NULL)    {      /* existing property - update it */      void *new_array = 0;      struct hw_property *value = entry->property;      /* check the type matches */      if (value->type != type)	hw_abort (me, "conflict between type of new and old value for property %s", property);      /* replace its value */      if (value->array != NULL)	hw_free (me, (void*)value->array);      new_array = (sizeof_array > 0		   ? hw_zalloc (me, sizeof_array)		   : (void*)0);      value->array = new_array;      value->sizeof_array = sizeof_array;      if (sizeof_array > 0)	memcpy (new_array, array, sizeof_array);      return;    }  else    {      /* new property - create it */      hw_add_property (me, property, type,		       NULL, 0, array, sizeof_array,		       NULL, temporary_object);    }}#if 0static voidclean_hw_properties (struct hw *me){  struct hw_property_data **delete_point = &me->properties_of_hw;  while (*delete_point != NULL)    {      struct hw_property_data *current = *delete_point;      switch (current->property->disposition)	{	case permenant_object:	  /* zap the current value, will be initialized later */	  ASSERT (current->init_array != NULL);	  if (current->property->array != NULL)	    {	      hw_free (me, (void*)current->property->array);	      current->property->array = NULL;	    }	  delete_point = &(*delete_point)->next;	  break;	case temporary_object:	  /* zap the actual property, was created during simulation run */	  ASSERT (current->init_array == NULL);	  *delete_point = current->next;	  if (current->property->array != NULL)	    hw_free (me, (void*)current->property->array);	  hw_free (me, current->property);	  hw_free (me, current);	  break;	}    }}#endif#if 0voidhw_init_static_properties (SIM_DESC sd,			   struct hw *me,			   void *data){  struct hw_property_data *property;  for (property = me->properties_of_hw;       property != NULL;       property = property->next)    {      ASSERT (property->init_array != NULL);      ASSERT (property->property->array == NULL);      ASSERT(property->property->disposition == permenant_object);      switch (property->property->type)	{	case array_property:	case boolean_property:	case range_array_property:	case reg_array_property:	case string_property:	case string_array_property:	case integer_property:	  /* delete the property, and replace it with the original */	  hw_set_property (me, property->property->name,			   property->property->type,			   property->init_array,			   property->sizeof_init_array);	  break;#if 0	case ihandle_property:	  break;#endif	}    }}#endif#if 0voidhw_init_runtime_properties (SIM_DESC sd,			    struct hw *me,			    void *data){  struct hw_property_data *property;  for (property = me->properties_of_hw;       property != NULL;       property = property->next)    {      switch (property->property->disposition)	{	case permenant_object:	  switch (property->property->type)	    {#if 0	    case ihandle_property:	      {		struct hw_instance *ihandle;		ihandle_runtime_property_spec spec;		ASSERT (property->init_array != NULL);		ASSERT (property->property->array == NULL);		hw_find_ihandle_runtime_property (me, property->property->name, &spec);		ihandle = tree_instance (me, spec.full_path);		hw_set_ihandle_property (me, property->property->name, ihandle);		break;	      }#endif	    case array_property:	    case boolean_property:	    case range_array_property:	    case integer_property:	    case reg_array_property:	    case string_property:	    case string_array_property:	      ASSERT (property->init_array != NULL);	      ASSERT (property->property->array != NULL);	      break;	    }	  break;	case temporary_object:	  ASSERT (property->init_array == NULL);	  ASSERT (property->property->array != NULL);	  break;	}    }}#endifconst struct hw_property *hw_next_property (const struct hw_property *property){  /* find the property in the list */  struct hw *owner = property->owner;  struct hw_property_data *entry = owner->properties_of_hw;  while (entry != NULL && entry->property != property)    entry = entry->next;  /* now return the following property */  ASSERT (entry != NULL); /* must be a member! */  if (entry->next != NULL)    return entry->next->property;  else    return NULL;}const struct hw_property *hw_find_property (struct hw *me,		  const char *property){  if (me == NULL)    {      return NULL;    }  else if (property == NULL || strcmp (property, "") == 0)    {      if (me->properties_of_hw == NULL)	return NULL;      else	return me->properties_of_hw->property;    }  else    {      struct hw_property_data *entry = find_property_data (me, property);      if (entry != NULL)	return entry->property;    }  return NULL;}voidhw_add_array_property (struct hw *me,		       const char *property,		       const void *array,		       int sizeof_array){  hw_add_property (me, property, array_property,		   array, sizeof_array, array, sizeof_array,		   NULL, permenant_object);}voidhw_set_array_property (struct hw *me,		       const char *property,		       const void *array,		       int sizeof_array){  hw_set_property (me, property, array_property, array, sizeof_array);}const struct hw_property *hw_find_array_property (struct hw *me,			const char *property){  const struct hw_property *node;  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (node->type != array_property)    hw_abort (me, "property \"%s\" of wrong type (array)", property);  return node;}voidhw_add_boolean_property (struct hw *me,			 const char *property,			 int boolean){  signed32 new_boolean = (boolean ? -1 : 0);  hw_add_property (me, property, boolean_property,		   &new_boolean, sizeof(new_boolean),		   &new_boolean, sizeof(new_boolean),		   NULL, permenant_object);}inthw_find_boolean_property (struct hw *me,			  const char *property){  const struct hw_property *node;  unsigned_cell boolean;  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (node->type != boolean_property)    hw_abort (me, "property \"%s\" of wrong type (boolean)", property);  ASSERT (sizeof (boolean) == node->sizeof_array);  memcpy (&boolean, node->array, sizeof (boolean));  return boolean;}#if 0voidhw_add_ihandle_runtime_property (struct hw *me,				 const char *property,				 const ihandle_runtime_property_spec *ihandle){  /* enter the full path as the init array */  hw_add_property (me, property, ihandle_property,		   ihandle->full_path, strlen(ihandle->full_path) + 1,		   NULL, 0,		   NULL, permenant_object);}#endif#if 0voidhw_find_ihandle_runtime_property (struct hw *me,				  const char *property,				  ihandle_runtime_property_spec *ihandle){  struct hw_property_data *entry = find_property_data (me, property);  TRACE (trace_devices,	 ("hw_find_ihandle_runtime_property(me=0x%lx, property=%s)\n",	  (long)me, property));  if (entry == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (entry->property->type != ihandle_property      || entry->property->disposition != permenant_object)    hw_abort (me, "property \"%s\" of wrong type", property);  ASSERT (entry->init_array != NULL);  /* the full path */  ihandle->full_path = entry->init_array;}#endif#if 0voidhw_set_ihandle_property (struct hw *me,			 const char *property,			 hw_instance *ihandle){  unsigned_cell cells;  cells = H2BE_cell (hw_instance_to_external (ihandle));  hw_set_property (me, property, ihandle_property,		   &cells, sizeof (cells));		      }#endif#if 0hw_instance *hw_find_ihandle_property (struct hw *me,

⌨️ 快捷键说明

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