summaryrefslogtreecommitdiffstats
path: root/tools/cpu/nios2/memory.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2006-08-15 21:02:55 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2006-08-15 21:02:55 +0000
commit16fd5a99e1a8c433077e70c1a48e42cc01bf7d29 (patch)
tree72d3d6b2daa4c48f453ac18e32ab20fbaa11d92a /tools/cpu/nios2/memory.c
parent2006-08-15 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-16fd5a99e1a8c433077e70c1a48e42cc01bf7d29.tar.bz2
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
Diffstat (limited to 'tools/cpu/nios2/memory.c')
-rw-r--r--tools/cpu/nios2/memory.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/tools/cpu/nios2/memory.c b/tools/cpu/nios2/memory.c
new file mode 100644
index 0000000000..0c35953354
--- /dev/null
+++ b/tools/cpu/nios2/memory.c
@@ -0,0 +1,104 @@
+/*
+ * 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;
+}
+
+