diff --git a/Makefile b/Makefile index 9bcb8e6ad..75ace692e 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,6 @@ products := boot.elf boot.hex boot.bin #objs += $(addprefix external/newlib/libc/, string/memset.o string/memcpy.o string/strlen.o) lib/private/mem5.o: CFLAGS += -w -objs += lib/errno.o lib/private/mem5.o lib/cxx_new.o objs += src/hello.o @@ -58,6 +57,7 @@ objs += src/hello.o default: clean boot.elf include liba/Makefile +include libaxx/Makefile include platform/Makefile include kandinsky/Makefile include poincare/Makefile diff --git a/lib/cxx_new.cpp b/lib/cxx_new.cpp deleted file mode 100644 index 688c96ebb..000000000 --- a/lib/cxx_new.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/*#ifndef LIB_MALLOC_H -#define LIB_MALLOC_H*/ - -extern "C" { -#include -} - -void * operator new (unsigned int size) { - return malloc(size); -} - -/*#endif*/ diff --git a/lib/errno.c b/lib/errno.c deleted file mode 100644 index 3c6dec6d2..000000000 --- a/lib/errno.c +++ /dev/null @@ -1,7 +0,0 @@ -int errno = 0; - -/* Invalid argument */ -#define EINVAL 22 - -/* Not enough space */ -#define ENOMEM 12 diff --git a/liba/Makefile b/liba/Makefile index 034536455..5003c691c 100644 --- a/liba/Makefile +++ b/liba/Makefile @@ -1,2 +1,5 @@ SFLAGS += -Iliba/include -objs += $(addprefix liba/src/, assert.o memcpy.o memset.o malloc.o) + +liba/src/external/sqlite/mem5.o: CFLAGS += -w + +objs += $(addprefix liba/src/, assert.o errno.o malloc.o memcpy.o memset.o external/sqlite/mem5.o) diff --git a/lib/errno.h b/liba/include/errno.h similarity index 66% rename from lib/errno.h rename to liba/include/errno.h index 104059a6e..d564bb4af 100644 --- a/lib/errno.h +++ b/liba/include/errno.h @@ -1,7 +1,12 @@ -extern int errno; +#ifndef LIBA_ERRNO_H +#define LIBA_ERRNO_H /* Invalid argument */ #define EINVAL 22 /* Not enough space */ #define ENOMEM 12 + +extern int errno; + +#endif diff --git a/lib/private/mem5config.h b/liba/include/private/memconfig.h similarity index 91% rename from lib/private/mem5config.h rename to liba/include/private/memconfig.h index 1749935b5..a8d33a2d4 100644 --- a/lib/private/mem5config.h +++ b/liba/include/private/memconfig.h @@ -1,5 +1,5 @@ -#ifndef LIB_MEM5CONFIG_H -#define LIB_MEM5CONFIG_H +#ifndef LIBA_MEMCONFIG_H +#define LIBA_MEMCONFIG_H /* This structure contains all the configuration data for the mem5 allocator. * Before using mem5, the HeapConfig global variable should be created diff --git a/lib/stdio.h b/liba/include/stdio.h similarity index 51% rename from lib/stdio.h rename to liba/include/stdio.h index b17bdbc64..2c0036d8b 100644 --- a/lib/stdio.h +++ b/liba/include/stdio.h @@ -1,5 +1,9 @@ -typedef void FILE; +#ifndef LIBA_STDIO_H +#define LIBA_STDIO_H #define stdin 0 #define stdout 0 +typedef void FILE; + +#endif diff --git a/liba/src/errno.c b/liba/src/errno.c new file mode 100644 index 000000000..14a812216 --- /dev/null +++ b/liba/src/errno.c @@ -0,0 +1,3 @@ +#include + +int errno = 0; diff --git a/lib/private/mem5.c b/liba/src/external/sqlite/mem5.c similarity index 100% rename from lib/private/mem5.c rename to liba/src/external/sqlite/mem5.c diff --git a/lib/private/sqliteInt.h b/liba/src/external/sqlite/sqliteInt.h similarity index 97% rename from lib/private/sqliteInt.h rename to liba/src/external/sqlite/sqliteInt.h index 305bfeefa..785939ca7 100644 --- a/lib/private/sqliteInt.h +++ b/liba/src/external/sqlite/sqliteInt.h @@ -5,7 +5,7 @@ * That file provides a tested implementation of malloc/free/realloc. */ #define sqlite3GlobalConfig HeapConfig -#include "mem5config.h" +#include /* SQLite wants to use its own integer types. Let's define them based from the * stdint ones */ diff --git a/liba/src/malloc.c b/liba/src/malloc.c index 9040b2a3d..56534e3bd 100644 --- a/liba/src/malloc.c +++ b/liba/src/malloc.c @@ -1,6 +1,11 @@ #include #include +void memsys5FreeUnsafe(void *pOld); +void * memsys5MallocUnsafe(int nByte); +void * memsys5Realloc(void *pPrior, int nBytes); +int memsys5Roundup(int n); + void free(void *ptr) { if (ptr != NULL) { memsys5FreeUnsafe(ptr); diff --git a/liba/src/memset.c b/liba/src/memset.c index 6513b45bc..75cd1d5d6 100644 --- a/liba/src/memset.c +++ b/liba/src/memset.c @@ -5,4 +5,5 @@ void * memset(void * b, int c, size_t len) { while (len--) { *destination++ = (unsigned char)c; } + return b; } diff --git a/libaxx/Makefile b/libaxx/Makefile new file mode 100644 index 000000000..2f64bd449 --- /dev/null +++ b/libaxx/Makefile @@ -0,0 +1 @@ +objs += $(addprefix libaxx/src/, new.o) diff --git a/libaxx/README.txt b/libaxx/README.txt new file mode 100644 index 000000000..ee62c7629 --- /dev/null +++ b/libaxx/README.txt @@ -0,0 +1,3 @@ +libaxx is an adhoc libc++, just like liba is an adhoc libc. + +See liba for more informations. diff --git a/libaxx/src/new.cpp b/libaxx/src/new.cpp new file mode 100644 index 000000000..591c6ab43 --- /dev/null +++ b/libaxx/src/new.cpp @@ -0,0 +1,5 @@ +#include + +void * operator new (unsigned int size) { + return malloc(size); +} diff --git a/platform/stm32f429/init_heap.c b/platform/stm32f429/init_heap.c index e57996d28..93da1a2a3 100644 --- a/platform/stm32f429/init_heap.c +++ b/platform/stm32f429/init_heap.c @@ -1,5 +1,5 @@ #include "init_lcd.h" -#include +#include extern char _ccm_heap_start; extern char _ccm_heap_end;