Files
rtems/tools/cpu/nios2/memory.c
Joel Sherrill 16fd5a99e1 2006-08-15 Kolja Waschk <kawk@telos.de>
* linkcmds.c, linkcmds.h, memory.c, memory.h, sample.ptf: New files.
	* bridges.c: corrected detection of bridged connections
	* clocks.c: removed a printf
	* linkcmds.[ch] new files, added output of linker script
	* Makefile.am: added new files
	* memory.[ch]: new files, detection of memory in SOPC configuration
	* nios2gen.c: updated command line parsing and output control
	* output.[ch]: improved output of BSP header file
	* ptf.[ch]: added ptf_dump_ptf_item and small fixes
	* sample.ptf: new file, sample configuration for nios2gen
	* README: updated
2006-08-15 21:02:55 +00:00

105 lines
2.3 KiB
C

/*
* Copyright (c) 2006 Kolja Waschk rtemsdev/ixo.de
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ptf.h"
#include "devices.h"
#include "memory.h"
memory_desc *find_memory(device_desc *devices)
{
struct ptf *p;
struct ptf_item pi;
memory_desc *tmd, *memory;
/********************************************************/
/* Check which of the devices are memory, sort by size */
if(devices)
{
struct ptf *p, *s;
struct ptf_item pi;
device_desc *dd;
memory = NULL;
for(dd = devices; dd; dd=dd->next)
{
p = ptf_find(dd->ptf->sub, &pi, item, "Is_Memory_Device", "1");
if(p != NULL && pi.level>0)
{
s = pi.item[pi.level-1];
p = ptf_find(s, &pi, item, "Base_Address", 0);
};
if(p != NULL)
{
tmd = (memory_desc*)malloc(sizeof(memory_desc));
if(tmd != NULL)
{
tmd->base = strtoul(p->value, 0, 0);
p = ptf_find(s, &pi, item, "Address_Span", 0);
if(p != 0)
{
tmd->size = strtoul(p->value, 0, 0);
}
else
{
tmd->size = 0;
p = ptf_find(s, &pi, item, "Address_Width", 0);
if(p) tmd->size = 1 << strtoul(p->value, 0, 0);
p = ptf_find(s, &pi, item, "Data_Width", 0);
if(p) tmd->size *= (strtoul(p->value, 0, 0) >> 3);
};
if(tmd->size == 0)
{
free(tmd);
}
else
{
tmd->dev = dd;
if(memory == NULL)
{
tmd->next = NULL;
memory = tmd;
}
else
{
if(tmd->size > memory->size)
{
tmd->next = memory;
memory = tmd;
}
else
{
memory_desc *uplink = memory;
while(uplink->next != NULL && uplink->next->size > tmd->size) uplink=uplink->next;
tmd->next = uplink->next;
uplink->next = tmd;
};
};
};
};
};
};
};
return memory;
}