Commit 5386076f authored by Damien George's avatar Damien George
Browse files

leon: Support RTEMS-4.8 Edisoft toolchain.

It requires some minimal libc header files, with definitions and
declarations that MicroPython relies on.

The OBCP example cannot be built with Edisoft because it relies a lot
on the toolchain providing a printf function.
parent 5a94ec20
The files in this directory provide the bare-minimum libc header files for
MicroPython to build, for ports/toolchains that don't provide them.
Implementations of the functions must be provided externally.
// Basic floating point support
#define FP_NAN 0
#define FP_INFINITE 1
#define FP_ZERO 2
#define FP_SUBNORMAL 3
#define FP_NORMAL 4
extern double nan(const char *);
extern double pow(double, double);
extern double copysign(double, double);
extern double fmod(double, double);
extern double floor(double);
extern double nearbyint(double);
extern int __fpclassifyd(double x);
extern int __isinfd(double x);
extern int __isnand(double x);
extern int __signbitd(double x);
#define fpclassify(x) __fpclassifyd(x)
#define signbit(x) __signbitd(x)
#define isinf(x) __isinfd(x)
#define isnan(x) __isnand(x)
// Functions needed for math module
extern double sqrt(double);
extern double exp(double);
extern double cos(double);
extern double sin(double);
extern double tan(double);
extern double acos(double);
extern double asin(double);
extern double atan(double);
extern double atan2(double, double);
extern double ceil(double);
extern double fabs(double);
extern double trunc(double);
extern double log(double);
extern double frexp(double, int*);
extern double ldexp(double, int);
extern double modf(double, double*);
static inline double isfinite(double x) {
int c = fpclassify(x);
return c != FP_NAN && c != FP_INFINITE;
}
// Functions needed for cmath module
extern double cosh(double);
extern double sinh(double);
#ifndef LIBC_INCLUDE_INCLUDED_STDINT_H
#define LIBC_INCLUDE_INCLUDED_STDINT_H
#include <stddef.h> // for size_t
#endif // LIBC_INCLUDE_INCLUDED_STDINT_H
#include <stdlib.h>
int memcmp(const void *s1, const void *s2, size_t n);
void *memcpy(void *dest, const void *src, size_t n);
void *memmove(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
size_t strlen(const char *s);
char *strchr(const char *s, int c);
int strcmp(const char *s1, const char *s2);
#include <stddef.h> // for size_t
#ifndef SEEK_SET
#define SEEK_SET (0)
#define SEEK_CUR (1)
#define SEEK_END (2)
#endif
#define ssize_t int
ssize_t read(int fildes, void *buf, size_t nbyte);
ssize_t write(int fildes, const void *buf, size_t nbyte);
#undef ssize_t
......@@ -13,11 +13,28 @@
# to be adjusted for your particular system.
# Select one of these RTEMS versions
#RTEMS_VER = 4_8_EDI
RTEMS_VER = 4_8
#RTEMS_VER = 4_10
#RTEMS_VER = 4_11
# Settings for RTEMS 4.8
# Settings for RTEMS 4.8 EDISOFT
# This toolchain needs a lot of extra options, and custom libc headers.
ifeq ($(RTEMS_VER),4_8_EDI)
CROSS_COMPILE = /opt/rtems-4.8/bin/sparc-rtems4.8-
RTEMS_BASE = /opt/rtems-4.8/sparc-rtems4.8/leon2/lib
CFLAGS += -DRTEMS_4_8 -DRTEMS_4_8_EDISOFT
CFLAGS += -I$(LEON_COMMON_FROM_HERE)/libc-include
CFLAGS += -B/opt/rtems-4.8/sparc-rtems4.8/leon2/lib
CFLAGS += -B/opt/rtems-4.8/support/include
LIBS += -Wl,--start-group -lrtemscpu -lio -lno_event -lmsg -lsem -ltimer -lno_rtmon -lno_ext -lrtemsbsp -lrtemscpu -Wl,--end-group
LDFLAGS += -Wl,--wrap,_IO_Initialize_all_drivers
SRC_RTEMS = \
/opt/rtems-4.8/support/src/leon2.c \
/opt/rtems-4.8/support/src/printk.c
endif
# Settings for RTEMS 4.8 Gaisler
ifeq ($(RTEMS_VER),4_8)
CROSS_COMPILE = /opt/rtems-4.8/bin/sparc-rtems-
RTEMS_BASE = /opt/rtems-4.8/sparc-rtems/leon2/lib
......
......@@ -34,9 +34,21 @@ typedef unsigned mp_uint_t;
typedef long mp_off_t;
#if RTEMS_4_8_EDISOFT
// Edisoft doesn't have alloca(), so use m_malloc
#define MICROPY_NO_ALLOCA (1)
// Edisoft doesn't define offsetof, so use the RTEMS version
#define offsetof(x, y) RTEMS_offsetof(x, y)
#else
// We need to provide a declaration/definition of alloca()
#include <alloca.h>
#endif
// INFINITY is not defined by toolchain
#ifndef INFINITY
#define INFINITY (__builtin_inff())
......
......@@ -36,7 +36,7 @@ else
CFLAGS += -Os -DNDEBUG
endif
LIBS = -lm
LIBS += -lm
SRC_C = \
main.c \
......@@ -59,7 +59,7 @@ SRC_S = \
# these are the example Python scripts to compile
SRC_PY = ex1.py ex2.py
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o))
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_RTEMS:.c=.o))
all: $(BUILD)/firmware.elf $(BUILD)/firmware.srec $(BUILD)/firmware.tab
......
......@@ -29,6 +29,8 @@
#define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
......
......@@ -36,7 +36,7 @@ else
CFLAGS += -Os -DNDEBUG
endif
LIBS = -lm
LIBS += -lm
SRC_C = \
main.c \
......@@ -59,7 +59,7 @@ SRC_S = \
# these are the example Python scripts to compile
SRC_PY = ex1.py ex2.py ex3.py
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o))
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_RTEMS:.c=.o))
all: $(BUILD)/firmware.elf $(BUILD)/firmware.srec $(BUILD)/firmware.tab
......
......@@ -30,6 +30,8 @@
#define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
......
......@@ -38,7 +38,7 @@ endif
CFLAGS += $(CFLAGS_EXTRA)
LIBS = -lm
LIBS += -lm
SRC_C = \
main.c \
......@@ -61,7 +61,7 @@ SRC_S = \
# these are the example Python scripts to compile
SRC_PY = pystone.py
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o))
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_RTEMS:.c=.o))
all: $(BUILD)/firmware.elf $(BUILD)/firmware.srec $(BUILD)/firmware.tab
......
......@@ -28,6 +28,8 @@
#define MICROPY_CPYTHON_COMPAT (0)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
......
......@@ -36,7 +36,7 @@ else
CFLAGS += -Os -DNDEBUG
endif
LIBS = -lm
LIBS += -lm
SRC_C = \
main.c \
......@@ -60,7 +60,7 @@ SRC_S = \
# they are executed in separate tasks
SRC_PY = ex1.py ex2.py ex3.py ex4.py
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o))
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_RTEMS:.c=.o))
all: $(BUILD)/firmware.elf $(BUILD)/firmware.srec $(BUILD)/firmware.tab $(BUILD)/scripts.srec
......
......@@ -29,6 +29,8 @@
#define MICROPY_CPYTHON_COMPAT (1)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_SPLITLINES (1)
......
......@@ -36,7 +36,7 @@ else
CFLAGS += -Os -DNDEBUG
endif
LIBS = -lm
LIBS += -lm
SRC_C = \
main.c \
......@@ -57,7 +57,7 @@ SRC_S = \
$(LEON_COMMON)/sparcjmp.s \
$(LEON_COMMON)/gchelper.s \
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o))
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_RTEMS:.c=.o))
all: $(BUILD)/firmware.elf $(BUILD)/firmware.srec $(BUILD)/firmware.tab
......
......@@ -33,6 +33,8 @@
#define MICROPY_CPYTHON_COMPAT (1)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
#define MICROPY_USE_INTERNAL_ERRNO (1)
#define MICROPY_USE_INTERNAL_PRINTF (0)
#define MICROPY_PY_FUNCTION_ATTRS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_STR_PARTITION (1)
......
......@@ -21,6 +21,11 @@ include ../py/py.mk
# include LEON common makefile settings
include $(LEON_COMMON_FROM_HERE)/mkenv.mk
# the OBCP example needs printf which is not provided by the Edisoft toolchain
ifeq ($(RTEMS_VER),4_8_EDI)
$(error Cannot build OBCP example with RTEMS-4.8 Edisoft (printf is reqired))
endif
INC =
INC += -I. -I.. -I$(BUILD) -I$(LEON_COMMON_FROM_HERE)
......@@ -36,7 +41,7 @@ else
CFLAGS += -Os -DNDEBUG
endif
LIBS = -lm
LIBS += -lm
# these are the Python scripts to compile into the binary
SRC_PY = \
......@@ -68,7 +73,7 @@ SRC_S = \
$(LEON_COMMON)/sparcjmp.s \
$(LEON_COMMON)/gchelper.s \
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o))
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o) $(SRC_S:.s=.o) $(SRC_RTEMS:.c=.o))
all: $(BUILD)/firmware.elf $(BUILD)/firmware.srec $(BUILD)/firmware.tab
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment