This commit is contained in:
Romain Goyet
2015-05-31 13:24:35 +02:00
parent 525f2aef9f
commit 803ffda5bc
20 changed files with 127 additions and 23 deletions

View File

@@ -25,10 +25,11 @@ endif
SFLAGS += -mcpu=cortex-m4 -mfpu=fpv4-sp-d16
# Flags - Header search path
SFLAGS += -Ilib -I. -Iinclude -Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include
SFLAGS += -Ilib -I.
#-Iexternal/freertos/include -Iexternal -Iexternal/freertos/portable/GCC/ARM_CM4F -Iexternal/newlib/libc/include
# Flags - Building options
SFLAGS += -Wall -ffreestanding
SFLAGS += -Wall -ffreestanding -nostdinc
# Flags - Optimizations
ifeq ($(PRODUCTION),1)
@@ -45,17 +46,18 @@ CXXFLAGS = -std=c++11 -fno-exceptions -fno-unwind-tables -fno-rtti -nostdlib
products := boot.elf boot.hex boot.bin
objs += external/freertos/tasks.o external/freertos/list.o external/freertos/queue.o external/freertos/portable/GCC/ARM_CM4F/port.o external/freertos/portable/MemMang/heap_1.o
objs += $(addprefix external/newlib/libc/, string/memset.o string/memcpy.o string/strlen.o)
#objs += external/freertos/tasks.o external/freertos/list.o external/freertos/queue.o external/freertos/portable/GCC/ARM_CM4F/port.o external/freertos/portable/MemMang/heap_1.o
#objs += $(addprefix external/newlib/libc/, string/memset.o string/memcpy.o string/strlen.o)
lib/private/mem5.o: CFLAGS += -w
objs += lib/assert.o lib/errno.o lib/private/mem5.o lib/cxx_new.o lib/malloc.o
objs += lib/errno.o lib/private/mem5.o lib/cxx_new.o
objs += src/hello.o
default: clean boot.elf
include liba/Makefile
include platform/Makefile
include kandinsky/Makefile
include poincare/Makefile

View File

@@ -1,8 +0,0 @@
#ifndef LIB_MALLOC_H
#define LIB_MALLOC_H
void free(void *ptr);
void * malloc(int size);
void * realloc(void *ptr, int size);
#endif

2
liba/Makefile Normal file
View File

@@ -0,0 +1,2 @@
SFLAGS += -Iliba/include
objs += $(addprefix liba/src/, assert.o memcpy.o memset.o malloc.o)

10
liba/README.txt Normal file
View File

@@ -0,0 +1,10 @@
liba is an adhoc libc.
We need a very small subset of the functionality provided by the standard C
library. We could use an available libc implementation, but those are usually
way to large and may have problematic licenses.
It wouldn't even be fair to call liba a libc at all since it doesn't come close
to implementing a significant portion of the standard. However, we do need some
functionality usually provided by libc, so instead of reinventing the wheel we
just implement the same entities (types, functions, etc…).

View File

@@ -1,5 +1,7 @@
#ifndef ASSERT_H
#define ASSERT_H
#ifndef LIBA_ASSERT_H
#define LIBA_ASSERT_H
#include "private/macros.h"
#ifdef NDEBUG
#define assert(e) ((void)0)
@@ -7,8 +9,10 @@
#define assert(e) ((void) ((e) ? ((void)0) : __assert(#e, __FILE__, __LINE__)))
#endif
LIBA_BEGIN_DECLS
void __assert(const char * expression, const char * file, int line);
void abort(void);
LIBA_END_DECLS
#endif

View File

@@ -0,0 +1,12 @@
#ifndef LIBA_MACROS_H
#define LIBA_MACROS_H
#ifdef __cplusplus
#define LIBA_BEGIN_DECLS extern "C" {
#define LIBA_END_DECLS }
#else
#define LIBA_BEGIN_DECLS
#define LIBA_END_DECLS
#endif
#endif

View File

@@ -0,0 +1,6 @@
#ifndef LIBA_TYPES_H
#define LIBA_TYPES_H
typedef int size_t;
#endif

6
liba/include/stdbool.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef LIBA_STDBOOL_H
#define LIBA_STDBOOL_H
typedef char bool;
#endif

11
liba/include/stdint.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef LIBA_STDINT_H
#define LIBA_STDINT_H
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
typedef long long int64_t;
#endif

17
liba/include/stdlib.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef LIBA_MALLOC_H
#define LIBA_MALLOC_H
#include "private/macros.h"
#include "private/types.h"
LIBA_BEGIN_DECLS
void free(void *ptr);
void * malloc(size_t size);
void * realloc(void *ptr, size_t size);
void abort(void);
LIBA_END_DECLS
#endif

18
liba/include/string.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef LIBA_STRING_H
#define LIBA_STRING_H
#include "private/macros.h"
#include "private/types.h"
#define NULL 0
LIBA_BEGIN_DECLS
void * memcpy(void * dst, const void * src, size_t n);
void * memset(void * b, int c, size_t len);
size_t strlen(const char * s);
LIBA_END_DECLS
#endif

4
liba/include/unistd.h Normal file
View File

@@ -0,0 +1,4 @@
#ifndef LIBA_UNISTD_H
#define LIBA_UNISTD_H
#endif

View File

@@ -1,4 +1,5 @@
#include <assert.h>
#include <stdlib.h>
#ifdef NDEBUG
#define assert(e) ((void)0)

View File

@@ -1,4 +1,5 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
void free(void *ptr) {
if (ptr != NULL) {
@@ -6,7 +7,7 @@ void free(void *ptr) {
}
}
void * malloc(int size) {
void * malloc(size_t size) {
void * p = NULL;
if (size > 0) {
p = memsys5MallocUnsafe(memsys5Roundup(size));
@@ -14,6 +15,6 @@ void * malloc(int size) {
return p;
}
void * realloc(void *ptr, int size) {
void * realloc(void *ptr, size_t size) {
return memsys5Realloc(ptr, memsys5Roundup(size));
}

12
liba/src/memcpy.c Normal file
View File

@@ -0,0 +1,12 @@
#include <string.h>
void * memcpy(void * dst, const void * src, size_t n) {
char * destination = (char *)dst;
char * source = (char *)src;
while (n--) {
*destination++ = *source++;
}
return dst;
}

8
liba/src/memset.c Normal file
View File

@@ -0,0 +1,8 @@
#include <string.h>
void * memset(void * b, int c, size_t len) {
char * destination = (char *)b;
while (len--) {
*destination++ = (unsigned char)c;
}
}

View File

@@ -1,7 +1,7 @@
#ifndef PLATFORM_ILI9341_H
#define PLATFORM_ILI9341_H 1
#include <stddef.h>
#include <string.h>
#include <stdbool.h>
/* This is the ILI9341 driver

View File

@@ -8,7 +8,6 @@
#include <assert.h>
#include <stdint.h>
#include <stddef.h>
#include "registers.h"
#include "init_kbd.h"
#include <platform/fx92kbd/fx92kbd.h>

View File

@@ -1,5 +1,4 @@
#include <poincare/expression.h>
#include <string.h>
#include "expression_parser.hpp"
#include "expression_lexer.hpp"

View File

@@ -1,7 +1,7 @@
extern "C" {
#include "hello.h"
#include <kandinsky.h>
#include <malloc.h>
#include <stdlib.h>
#include <platform/stm32f429/init_kbd.h>
}