OSDN Git Service

Change the directry name to hirado
[trx-305dsp/dsp.git] / hirado / kernel / config / blackfin / cpu_malloc.c
diff --git a/hirado/kernel/config/blackfin/cpu_malloc.c b/hirado/kernel/config/blackfin/cpu_malloc.c
new file mode 100644 (file)
index 0000000..6dff7e2
--- /dev/null
@@ -0,0 +1,40 @@
+#include <t_services.h>
+
+static void * heapPtr = 0;
+extern void *_heap_start, *_heap_end;
+
+/*
+ * 要求があればヒープ上にメモリ領域を割り当てる。freeは使わないことを仮定している。
+ */
+
+void * malloc(size_t size)
+{
+    void * retPtr;
+    SIL_PRE_LOC;
+
+    SIL_LOC_INT();
+    // 最初の呼び出しでヒープを初期化する
+    if (! heapPtr)
+        heapPtr = _heap_start;
+
+    retPtr = heapPtr;
+
+    if ((heapPtr+size) >= _heap_end)
+        retPtr =  NULL;
+    else
+    {
+        heapPtr += size;
+            // ポインタを32bit境界に揃える
+        while ((unsigned int)heapPtr % 4)
+            heapPtr++;
+    }
+    SIL_UNL_INT();
+    return retPtr;
+}
+
+/*
+ * なにもせずに戻る
+ */
+void free( void * ptr )
+{
+}