mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Liba
This commit is contained in:
12
Makefile
12
Makefile
@@ -25,10 +25,11 @@ endif
|
|||||||
SFLAGS += -mcpu=cortex-m4 -mfpu=fpv4-sp-d16
|
SFLAGS += -mcpu=cortex-m4 -mfpu=fpv4-sp-d16
|
||||||
|
|
||||||
# Flags - Header search path
|
# 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
|
# Flags - Building options
|
||||||
SFLAGS += -Wall -ffreestanding
|
SFLAGS += -Wall -ffreestanding -nostdinc
|
||||||
|
|
||||||
# Flags - Optimizations
|
# Flags - Optimizations
|
||||||
ifeq ($(PRODUCTION),1)
|
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
|
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 += 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 += $(addprefix external/newlib/libc/, string/memset.o string/memcpy.o string/strlen.o)
|
||||||
|
|
||||||
lib/private/mem5.o: CFLAGS += -w
|
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
|
objs += src/hello.o
|
||||||
|
|
||||||
|
|
||||||
default: clean boot.elf
|
default: clean boot.elf
|
||||||
|
|
||||||
|
include liba/Makefile
|
||||||
include platform/Makefile
|
include platform/Makefile
|
||||||
include kandinsky/Makefile
|
include kandinsky/Makefile
|
||||||
include poincare/Makefile
|
include poincare/Makefile
|
||||||
|
|||||||
@@ -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
2
liba/Makefile
Normal 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
10
liba/README.txt
Normal 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…).
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#ifndef ASSERT_H
|
#ifndef LIBA_ASSERT_H
|
||||||
#define ASSERT_H
|
#define LIBA_ASSERT_H
|
||||||
|
|
||||||
|
#include "private/macros.h"
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#define assert(e) ((void)0)
|
#define assert(e) ((void)0)
|
||||||
@@ -7,8 +9,10 @@
|
|||||||
#define assert(e) ((void) ((e) ? ((void)0) : __assert(#e, __FILE__, __LINE__)))
|
#define assert(e) ((void) ((e) ? ((void)0) : __assert(#e, __FILE__, __LINE__)))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
LIBA_BEGIN_DECLS
|
||||||
|
|
||||||
void __assert(const char * expression, const char * file, int line);
|
void __assert(const char * expression, const char * file, int line);
|
||||||
|
|
||||||
void abort(void);
|
LIBA_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
12
liba/include/private/macros.h
Normal file
12
liba/include/private/macros.h
Normal 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
|
||||||
6
liba/include/private/types.h
Normal file
6
liba/include/private/types.h
Normal 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
6
liba/include/stdbool.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef LIBA_STDBOOL_H
|
||||||
|
#define LIBA_STDBOOL_H
|
||||||
|
|
||||||
|
typedef char bool;
|
||||||
|
|
||||||
|
#endif
|
||||||
11
liba/include/stdint.h
Normal file
11
liba/include/stdint.h
Normal 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
17
liba/include/stdlib.h
Normal 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
18
liba/include/string.h
Normal 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
4
liba/include/unistd.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#ifndef LIBA_UNISTD_H
|
||||||
|
#define LIBA_UNISTD_H
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#define assert(e) ((void)0)
|
#define assert(e) ((void)0)
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <stddef.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void free(void *ptr) {
|
void free(void *ptr) {
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
@@ -6,7 +7,7 @@ void free(void *ptr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void * malloc(int size) {
|
void * malloc(size_t size) {
|
||||||
void * p = NULL;
|
void * p = NULL;
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
p = memsys5MallocUnsafe(memsys5Roundup(size));
|
p = memsys5MallocUnsafe(memsys5Roundup(size));
|
||||||
@@ -14,6 +15,6 @@ void * malloc(int size) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void * realloc(void *ptr, int size) {
|
void * realloc(void *ptr, size_t size) {
|
||||||
return memsys5Realloc(ptr, memsys5Roundup(size));
|
return memsys5Realloc(ptr, memsys5Roundup(size));
|
||||||
}
|
}
|
||||||
12
liba/src/memcpy.c
Normal file
12
liba/src/memcpy.c
Normal 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
8
liba/src/memset.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef PLATFORM_ILI9341_H
|
#ifndef PLATFORM_ILI9341_H
|
||||||
#define PLATFORM_ILI9341_H 1
|
#define PLATFORM_ILI9341_H 1
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* This is the ILI9341 driver
|
/* This is the ILI9341 driver
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include "registers.h"
|
#include "registers.h"
|
||||||
#include "init_kbd.h"
|
#include "init_kbd.h"
|
||||||
#include <platform/fx92kbd/fx92kbd.h>
|
#include <platform/fx92kbd/fx92kbd.h>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include <poincare/expression.h>
|
#include <poincare/expression.h>
|
||||||
#include <string.h>
|
|
||||||
#include "expression_parser.hpp"
|
#include "expression_parser.hpp"
|
||||||
#include "expression_lexer.hpp"
|
#include "expression_lexer.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#include "hello.h"
|
#include "hello.h"
|
||||||
#include <kandinsky.h>
|
#include <kandinsky.h>
|
||||||
#include <malloc.h>
|
#include <stdlib.h>
|
||||||
#include <platform/stm32f429/init_kbd.h>
|
#include <platform/stm32f429/init_kbd.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user