From 6bd06e042da524448dae7e48a7499517948be2b8 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 24 Nov 2016 21:55:24 +0000 Subject: don't use memcpy and memset for now --- Makefile | 2 +- lib/string.c | 38 -------------------------------------- lib/string.h | 10 ---------- setup.c | 6 ++++-- 4 files changed, 5 insertions(+), 51 deletions(-) delete mode 100644 lib/string.c delete mode 100644 lib/string.h diff --git a/Makefile b/Makefile index acae6d2..bb11f1f 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ CFLAGS = -std=c11 $(WARNINGS) -O2 -flto -MMD -MP -ffreestanding -nostdlib -Ilib LDFLAGS = -T layout.ld -O2 -flto -ffreestanding -nostdlib ASFLAGS = $(TARGET_ARCH) -OBJ := crt0.o vectors.o flashconf.o setup.o fmk.o lib/string.o lib/le.o usb/usb.o usb/endpt0.o usb/endpt1.o +OBJ := crt0.o vectors.o flashconf.o setup.o fmk.o lib/le.o usb/usb.o usb/endpt0.o usb/endpt1.o %.bin: % $(OBJCOPY) -O binary $< $@ diff --git a/lib/string.c b/lib/string.c deleted file mode 100644 index 25935b3..0000000 --- a/lib/string.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -void *memcpy(void * restrict _dest, const void * restrict _src, size_t n) -{ - unsigned char *dest = _dest; - const unsigned char *src = _src; - - for (size_t i = 0; i < n; i++) - dest[i] = src[i]; - - return dest; -} - -void *memmove(void *_dest, const void *_src, size_t n) -{ - unsigned char *dest = _dest; - const unsigned char *src = _src; - - if (_src < _dest) { - for (size_t i = 0; i < n; i++) - dest[i] = src[i]; - } else { - for (size_t i = n; i > 0; i++) - dest[i - 1] = src[i - 1]; - } - - return dest; -} - -void *memset(void *_s, int _c, size_t n) -{ - unsigned char *s = _s, c = (unsigned char)_c; - for (size_t i = 0; i < n; i++) - s[i] = c; - - return _s; -} diff --git a/lib/string.h b/lib/string.h deleted file mode 100644 index 9c204dd..0000000 --- a/lib/string.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef LIB_STRING_H -#define LIB_STRING_H - -#include - -void *memcpy(void * restrict dest, const void * restrict src, size_t n); -void *memmove(void *dest, const void *src, size_t n); -void *memset(void *s, int c, size_t n); - -#endif /* LIB_STRING_H */ diff --git a/setup.c b/setup.c index 9cb0312..cb83eb4 100644 --- a/setup.c +++ b/setup.c @@ -31,8 +31,10 @@ void setup(void) UNSET_BIT(WDOG_STCTRLH, STCTRLH_WDOGEN); /* Copy data and clear bss */ - memcpy(_sdata, _ldata, _edata - _sdata); - memset(_sbss, 0, _ebss - _sbss); + for (size_t i = 0; i < (size_t)(_edata - _sdata); i++) + _sdata[i] = _ldata[i]; + for (size_t i = 0; i < (size_t)(_ebss - _sbss); i++) + _sbss[i] = 0; /* Enable port clocks */ SIM_SCGC5 |= BV(SCGC5_PORTE) | BV(SCGC5_PORTD) | BV(SCGC5_PORTC) -- cgit v1.2.3-54-g00ecf