Browse Source

fw: move the malloc heap to DRAM

Move the malloc() heap to DRAM. The stack is still in SRAM.
H. Peter Anvin 3 years ago
parent
commit
0dfe406919
8 changed files with 4803 additions and 4792 deletions
  1. BIN
      fpga/output_files/max80.jbc
  2. BIN
      fpga/output_files/max80.jic
  3. BIN
      fpga/output_files/max80.pof
  4. BIN
      fpga/output_files/max80.sof
  5. 4782 4782
      fw/boot.mif
  6. 7 0
      fw/max80.ld
  7. 9 5
      fw/sbrk.c
  8. 5 5
      fw/testdata.S

BIN
fpga/output_files/max80.jbc


BIN
fpga/output_files/max80.jic


BIN
fpga/output_files/max80.pof


BIN
fpga/output_files/max80.sof


File diff suppressed because it is too large
+ 4782 - 4782
fw/boot.mif


+ 7 - 0
fw/max80.ld

@@ -175,4 +175,11 @@ SECTIONS
 	. = ALIGN(8);
 	. = ALIGN(8);
 	__dram_bss_end = .;
 	__dram_bss_end = .;
 	__dram_bss_len = __dram_bss_end - __dram_bss_start;
 	__dram_bss_len = __dram_bss_end - __dram_bss_start;
+
+	/* No need to zero the heap */
+	.heap (NOLOAD) : ALIGN(8) {
+		*(.heap)
+	} >DRAM
+
+	__dram_end = .;
 }
 }

+ 9 - 5
fw/sbrk.c

@@ -7,17 +7,21 @@
 #include "sys.h"
 #include "sys.h"
 #include "fw.h"
 #include "fw.h"
 
 
+#define HEAP_SIZE	(4 << 20) /* 4 MB */
+
+static char __attribute__((section(".heap"))) __heap[HEAP_SIZE];
+static char *cur_brk = __heap;
+
 void *_sbrk(size_t increment)
 void *_sbrk(size_t increment)
 {
 {
-    static size_t cur_brk = (size_t)_end;
-    size_t old_brk = cur_brk;
-    size_t new_brk = old_brk + increment;
+    char *old_brk = cur_brk;
+    char *new_brk = old_brk + increment;
 
 
-    if (unlikely(new_brk > SRAM_SIZE - STACK_SIZE)) {
+    if (unlikely(new_brk > &__heap[HEAP_SIZE])) {
 	errno = ENOMEM;
 	errno = ENOMEM;
 	return (void *)(-1);
 	return (void *)(-1);
     }
     }
 
 
     cur_brk = new_brk;
     cur_brk = new_brk;
-    return (void *)old_brk;
+    return old_brk;
 }
 }

+ 5 - 5
fw/testdata.S

@@ -1,13 +1,13 @@
 	.section ".dram.rodata","a"
 	.section ".dram.rodata","a"
 	.globl testdata
 	.globl testdata
 testdata:
 testdata:
-	x = 0x00001111
-	y = 0
+	.Lx = 0x00001111
+	.Ly = 0
 
 
 	.rept 0x20000
 	.rept 0x20000
-	.long x
-	x = ((x * 0x89abcdef) + ((x * 0x89abcdef) >> 32) + (y * 0x76543210)) & 0xffffffff
-	y = y + 1
+	.long .Lx
+	.Lx = ((.Lx * 0x89abcdef) + ((.Lx * 0x89abcdef) >> 32) + (.Ly * 0x76543210)) & 0xffffffff
+	.Ly = .Ly + 1
 	.endr
 	.endr
 
 
 	.type testdata,@object
 	.type testdata,@object

Some files were not shown because too many files changed in this diff