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

📄 hw-properties.c

📁 这个是LINUX下的GDB调度工具的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
			  const char *property){  const hw_property_data *node;  unsigned_cell ihandle;  hw_instance *instance;  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (node->type != ihandle_property)    hw_abort(me, "property \"%s\" of wrong type (ihandle)", property);  if (node->array == NULL)    hw_abort(me, "runtime property \"%s\" not yet initialized", property);  ASSERT (sizeof(ihandle) == node->sizeof_array);  memcpy (&ihandle, node->array, sizeof(ihandle));  instance = external_to_hw_instance (me, BE2H_cell(ihandle));  ASSERT (instance != NULL);  return instance;}#endifvoidhw_add_integer_property (struct hw *me,			 const char *property,			 signed_cell integer){  H2BE (integer);  hw_add_property (me, property, integer_property,		   &integer, sizeof(integer),		   &integer, sizeof(integer),		   NULL, permenant_object);}signed_cellhw_find_integer_property (struct hw *me,			  const char *property){  const struct hw_property *node;  signed_cell integer;  TRACE (trace_devices,	 ("hw_find_integer(me=0x%lx, property=%s)\n",	  (long)me, property));  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (node->type != integer_property)    hw_abort (me, "property \"%s\" of wrong type (integer)", property);  ASSERT (sizeof(integer) == node->sizeof_array);  memcpy (&integer, node->array, sizeof (integer));  return BE2H_cell (integer);}inthw_find_integer_array_property (struct hw *me,				const char *property,				unsigned index,				signed_cell *integer){  const struct hw_property *node;  int sizeof_integer = sizeof (*integer);  signed_cell *cell;  TRACE (trace_devices,	 ("hw_find_integer(me=0x%lx, property=%s)\n",	  (long)me, property));    /* check things sane */  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (node->type != integer_property      && node->type != array_property)    hw_abort (me, "property \"%s\" of wrong type (integer or array)", property);  if ((node->sizeof_array % sizeof_integer) != 0)    hw_abort (me, "property \"%s\" contains an incomplete number of cells", property);  if (node->sizeof_array <= sizeof_integer * index)    return 0;    /* Find and convert the value */  cell = ((signed_cell*)node->array) + index;  *integer = BE2H_cell (*cell);    return node->sizeof_array / sizeof_integer;}static unsigned_cell *unit_address_to_cells (const hw_unit *unit,		       unsigned_cell *cell,		       int nr_cells){  int i;  ASSERT(nr_cells == unit->nr_cells);  for (i = 0; i < unit->nr_cells; i++)    {      *cell = H2BE_cell (unit->cells[i]);      cell += 1;    }  return cell;}static const unsigned_cell *cells_to_unit_address (const unsigned_cell *cell,		       hw_unit *unit,		       int nr_cells){  int i;  memset(unit, 0, sizeof(*unit));  unit->nr_cells = nr_cells;  for (i = 0; i < unit->nr_cells; i++)    {      unit->cells[i] = BE2H_cell (*cell);      cell += 1;    }  return cell;}static unsignednr_range_property_cells (struct hw *me,			 int nr_ranges){  return ((hw_unit_nr_address_cells (me)	   + hw_unit_nr_address_cells (hw_parent (me))	   + hw_unit_nr_size_cells (me))	  ) * nr_ranges;}voidhw_add_range_array_property (struct hw *me,			     const char *property,			     const range_property_spec *ranges,			     unsigned nr_ranges){  unsigned sizeof_cells = (nr_range_property_cells (me, nr_ranges)			   * sizeof (unsigned_cell));  unsigned_cell *cells = hw_zalloc (me, sizeof_cells);  unsigned_cell *cell;  int i;    /* copy the property elements over */  cell = cells;  for (i = 0; i < nr_ranges; i++)    {      const range_property_spec *range = &ranges[i];      /* copy the child address */      cell = unit_address_to_cells (&range->child_address, cell,				    hw_unit_nr_address_cells (me));      /* copy the parent address */      cell = unit_address_to_cells (&range->parent_address, cell, 				    hw_unit_nr_address_cells (hw_parent (me)));      /* copy the size */      cell = unit_address_to_cells (&range->size, cell, 				    hw_unit_nr_size_cells (me));    }  ASSERT (cell == &cells[nr_range_property_cells (me, nr_ranges)]);    /* add it */  hw_add_property (me, property, range_array_property,		   cells, sizeof_cells,		   cells, sizeof_cells,		   NULL, permenant_object);    hw_free (me, cells);}inthw_find_range_array_property (struct hw *me,			      const char *property,			      unsigned index,			      range_property_spec *range){  const struct hw_property *node;  unsigned sizeof_entry = (nr_range_property_cells (me, 1)			   * sizeof (unsigned_cell));  const unsigned_cell *cells;    /* locate the property */  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (node->type != range_array_property)    hw_abort (me, "property \"%s\" of wrong type (range array)", property);    /* aligned ? */  if ((node->sizeof_array % sizeof_entry) != 0)    hw_abort (me, "property \"%s\" contains an incomplete number of entries",	      property);    /* within bounds? */  if (node->sizeof_array < sizeof_entry * (index + 1))    return 0;    /* find the range of interest */  cells = (unsigned_cell*)((char*)node->array + sizeof_entry * index);    /* copy the child address out - converting as we go */  cells = cells_to_unit_address (cells, &range->child_address,				 hw_unit_nr_address_cells (me));    /* copy the parent address out - converting as we go */  cells = cells_to_unit_address (cells, &range->parent_address,				 hw_unit_nr_address_cells (hw_parent (me)));    /* copy the size - converting as we go */  cells = cells_to_unit_address (cells, &range->size,				 hw_unit_nr_size_cells (me));    return node->sizeof_array / sizeof_entry;}static unsignednr_reg_property_cells (struct hw *me,		       int nr_regs){  return (hw_unit_nr_address_cells (hw_parent(me))	  + hw_unit_nr_size_cells (hw_parent(me))	  ) * nr_regs;}voidhw_add_reg_array_property (struct hw *me,			   const char *property,			   const reg_property_spec *regs,			   unsigned nr_regs){  unsigned sizeof_cells = (nr_reg_property_cells (me, nr_regs)			   * sizeof (unsigned_cell));  unsigned_cell *cells = hw_zalloc (me, sizeof_cells);  unsigned_cell *cell;  int i;    /* copy the property elements over */  cell = cells;  for (i = 0; i < nr_regs; i++)    {      const reg_property_spec *reg = &regs[i];      /* copy the address */      cell = unit_address_to_cells (&reg->address, cell,				    hw_unit_nr_address_cells (hw_parent (me)));      /* copy the size */      cell = unit_address_to_cells (&reg->size, cell,				    hw_unit_nr_size_cells (hw_parent (me)));    }  ASSERT (cell == &cells[nr_reg_property_cells (me, nr_regs)]);    /* add it */  hw_add_property (me, property, reg_array_property,		   cells, sizeof_cells,		   cells, sizeof_cells,		   NULL, permenant_object);    hw_free (me, cells);}inthw_find_reg_array_property (struct hw *me,			    const char *property,			    unsigned index,			    reg_property_spec *reg){  const struct hw_property *node;  unsigned sizeof_entry = (nr_reg_property_cells (me, 1)			   * sizeof (unsigned_cell));  const unsigned_cell *cells;    /* locate the property */  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (node->type != reg_array_property)    hw_abort (me, "property \"%s\" of wrong type (reg array)", property);    /* aligned ? */  if ((node->sizeof_array % sizeof_entry) != 0)    hw_abort (me, "property \"%s\" contains an incomplete number of entries",	      property);    /* within bounds? */  if (node->sizeof_array < sizeof_entry * (index + 1))    return 0;    /* find the range of interest */  cells = (unsigned_cell*)((char*)node->array + sizeof_entry * index);    /* copy the address out - converting as we go */  cells = cells_to_unit_address (cells, &reg->address,				 hw_unit_nr_address_cells (hw_parent (me)));    /* copy the size out - converting as we go */  cells = cells_to_unit_address (cells, &reg->size,				 hw_unit_nr_size_cells (hw_parent (me)));    return node->sizeof_array / sizeof_entry;}voidhw_add_string_property (struct hw *me,			const char *property,			const char *string){  hw_add_property (me, property, string_property,		   string, strlen(string) + 1,		   string, strlen(string) + 1,		   NULL, permenant_object);}const char *hw_find_string_property (struct hw *me,			 const char *property){  const struct hw_property *node;  const char *string;  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  if (node->type != string_property)    hw_abort (me, "property \"%s\" of wrong type (string)", property);  string = node->array;  ASSERT (strlen(string) + 1 == node->sizeof_array);  return string;}voidhw_add_string_array_property (struct hw *me,			      const char *property,			      const string_property_spec *strings,			      unsigned nr_strings){  int sizeof_array;  int string_nr;  char *array;  char *chp;  if (nr_strings == 0)    hw_abort (me, "property \"%s\" must be non-null", property);  /* total up the size of the needed array */  for (sizeof_array = 0, string_nr = 0;       string_nr < nr_strings;       string_nr ++)    {      sizeof_array += strlen (strings[string_nr]) + 1;    }  /* create the array */  array = (char*) hw_zalloc (me, sizeof_array);  chp = array;  for (string_nr = 0;       string_nr < nr_strings;       string_nr++)    {      strcpy (chp, strings[string_nr]);      chp += strlen (chp) + 1;    }  ASSERT (chp == array + sizeof_array);  /* now enter it */  hw_add_property (me, property, string_array_property,		   array, sizeof_array,		   array, sizeof_array,		   NULL, permenant_object);}inthw_find_string_array_property (struct hw *me,			       const char *property,			       unsigned index,			       string_property_spec *string){  const struct hw_property *node;  node = hw_find_property (me, property);  if (node == NULL)    hw_abort (me, "property \"%s\" not found", property);  switch (node->type)    {    default:      hw_abort (me, "property \"%s\" of wrong type", property);      break;    case string_property:      if (index == 0)	{	  *string = node->array;	  ASSERT (strlen(*string) + 1 == node->sizeof_array);	  return 1;	}      break;    case array_property:      if (node->sizeof_array == 0	  || ((char*)node->array)[node->sizeof_array - 1] != '\0')	hw_abort (me, "property \"%s\" invalid for string array", property);      /* FALL THROUGH */    case string_array_property:      ASSERT (node->sizeof_array > 0);      ASSERT (((char*)node->array)[node->sizeof_array - 1] == '\0');      {	const char *chp = node->array;	int nr_entries = 0;	/* count the number of strings, keeping an eye out for the one	   we're looking for */	*string = chp;	do	  {	    if (*chp == '\0')	      {		/* next string */		nr_entries++;		chp++;		if (nr_entries == index)		  *string = chp;	      }	    else	      {		chp++;	      }	  } while (chp < (char*)node->array + node->sizeof_array);	if (index < nr_entries)	  return nr_entries;	else	  {	    *string = NULL;	    return 0;	  }      }      break;    }  return 0;}voidhw_add_duplicate_property (struct hw *me,			   const char *property,			   const struct hw_property *original){  struct hw_property_data *master;  TRACE (trace_devices,	 ("hw_add_duplicate_property(me=0x%lx, property=%s, ...)\n",	  (long)me, property));  if (original->disposition != permenant_object)    hw_abort (me, "Can only duplicate permenant objects");  /* find the original's master */  master = original->owner->properties_of_hw;  while (master->property != original)    {      master = master->next;      ASSERT(master != NULL);    }  /* now duplicate it */  hw_add_property (me, property,		   original->type,		   master->init_array, master->sizeof_init_array,		   original->array, original->sizeof_array,		   original, permenant_object);}

⌨️ 快捷键说明

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