d3q19: remove libc, add stubs
authorSebastian <git@sraa.de>
Tue, 2 Sep 2014 12:10:04 +0000 (12:10 +0000)
committerSebastian <git@sraa.de>
Tue, 2 Sep 2014 12:10:04 +0000 (12:10 +0000)
Do not link against newlib anymore.
Add required stubs used by the startup code.
Add own (very slow!) implementations of memcpy() and memset().

This frees about 2k in SRAM bank 0.

d3q19/Makefile
d3q19/esrc/d3q19.c
d3q19/esrc/hack.c [new file with mode: 0644]
d3q19/hsrc/main.c

index 5674c3da683c7040416d78c9d45633f77550b848..a1d1de04cae0781a023f2f304ce947c017beb184 100644 (file)
@@ -10,7 +10,7 @@ ECHO  = /bin/echo -e
 ECC    = e-gcc
 EOC    = e-objcopy
 ECFLAGS        = -Os -std=c99 -falign-loops=8 -falign-functions=8 -Wall -fsingle-precision-constant -ffast-math
-ELFLAGS        = -T$(EPIPHANY_HOME)/bsps/current/internal.ldf -le-lib
+ELFLAGS        = -T$(EPIPHANY_HOME)/bsps/current/internal.ldf -nodefaultlibs -lgcc -le-lib
 EOFLAGS        = -R .shared_dram -R .data_bank1 -R .data_bank2 -R .data_bank3
 
 # host application
@@ -19,7 +19,7 @@ HOBJS = $(HDEST)/main.o $(HDEST)/data.o
 
 # epiphany applications
 EAPPS  = $(DEST)/main.srec
-ECOMMON        = $(EDEST)/d3q19.o
+ECOMMON        = $(EDEST)/d3q19.o $(EDEST)/hack.o
 
 # folders
 HSRC   = hsrc
index d50c11b1348765d2753992dd4b257948d2ff79d2..4156ad5d6c766de7353aa456893722322656e9fe 100644 (file)
@@ -30,7 +30,7 @@ void init(block_t f)
                                for(int q = 0; q < 19; q++)
                                        f[z][y][x][q] = 0.1 * d3q19_w[q];
 
-#if 1
+#if 0
        /* except here */
        if(core == 0)
                for(int q = 0; q < 19; q++)
@@ -42,7 +42,7 @@ void init(block_t f)
 
 void collide(block_t f, int x, int y, int z, FLOAT omega)
 {
-#if 0
+#if 1
        /* Zou/He boundary conditions */
        if(row == 0 && z == 0) {                                /* top */
                const FLOAT Ux = 0.0;   /* wall speed */
diff --git a/d3q19/esrc/hack.c b/d3q19/esrc/hack.c
new file mode 100644 (file)
index 0000000..b9117ce
--- /dev/null
@@ -0,0 +1,45 @@
+/* hack to enable libc-less project */
+
+#include <stddef.h>
+
+/* since we need to compile with -nodefaultlibs
+   because of insufficient memory, we need to
+   implement everything ourselves */
+
+/* NOTE: NEVER RETURN FROM MAIN - THERE BE DRAGONS */
+
+/* points to a reentrancy structure in libc;
+   since we don't use the libc, point it to data memory,
+   it will be overwritten later */
+void* _impure_ptr = (void*)0x4000;
+
+void exit(int code)
+{
+       while(1) __asm__ volatile("idle");
+}
+
+/* ================================================================== */
+
+void *memcpy(void *dest, const void *src, size_t n)
+{
+       char *s = (char*)src;
+       char *d = (char*)dest;
+
+       while(n--) {
+               *d++ = *s++;
+       }
+
+       return(dest);
+}
+
+void *memset(void *s, int c , size_t n)
+{
+       char *buf = (char*)s;
+
+       while(n--) {
+               *buf++ = (char)c;
+       }
+
+       return(s);
+}
+
index e0363b37f7e175f5305dd2c37e4650d612538076..fb000a24adbe3813c450abb30004277f7a70ab87 100644 (file)
@@ -95,8 +95,8 @@ int main()
 
                /* write data */
                //write_populations(shm.lattice, shm.iteration);
-               write_density(shm.lattice, shm.iteration);
-               //write_velocity(shm.lattice, shm.iteration);
+               //write_density(shm.lattice, shm.iteration);
+               write_velocity(shm.lattice, shm.iteration);
                write_timers(shm.times, shm.iteration);
        }
        /* ================================================================ */