8000 Added bare minimum files necessary to build micromusl · micropython/micropython@69b723e · GitHub
[go: up one dir, main page]

Skip to content

Commit 69b723e

Browse files
author
Hagen Kaye
committed
Added bare minimum files necessary to build micromusl
These are the files necessary to build libc.a before any functionality is added. To build micromusl, in this directory type: export CROSS_COMPILE=arm-none-eabi- ./configure --disable-shared --prefix=build make make install installs in 'build' directory
1 parent 18a48f8 commit 69b723e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+8380
-0
lines changed

micromusl/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.o
2+
*.lo
3+
*.a
4+
*.so
5+
*.so.1
6+
arch/*/bits/alltypes.h
7+
config.mak
8+
include/bits
9+
tools/musl-gcc
10+
lib/musl-gcc.specs
11+
build

micromusl/Makefile

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#
2+
# Makefile for musl (requires GNU make)
3+
#
4+
# This is how simple every makefile should be...
5+
# No, I take that back - actually most should be less than half this size.
6+
#
7+
# Use config.mak to override any of the following variables.
8+
# Do not make changes here.
9+
#
10+
11+
exec_prefix = /usr/local
12+
bindir = $(exec_prefix)/bin
13+
14+
prefix = /usr/local/musl
15+
includedir = $(prefix)/include
16+
libdir = $(prefix)/lib
17+
syslibdir = /lib
18+
19+
SRCS = $(sort $(wildcard src/*/*.c arch/$(ARCH)/src/*.c))
20+
OBJS = $(SRCS:.c=.o)
21+
LOBJS = $(OBJS:.o=.lo)
22+
GENH = include/bits/alltypes.h
23+
GENH_INT = src/internal/version.h
24+
IMPH = src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/libc.h
25+
26+
LDFLAGS =
27+
LIBCC = -lgcc
28+
CPPFLAGS =
29+
CFLAGS = -Os -pipe
30+
CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
31+
32+
CFLAGS_ALL = $(CFLAGS_C99FSE)
33+
CFLAGS_ALL += -D_XOPEN_SOURCE=700 -I./arch/$(ARCH) -I./src/internal -I./include
34+
CFLAGS_ALL += $(CPPFLAGS) $(CFLAGS)
35+
CFLAGS_ALL_STATIC = $(CFLAGS_ALL)
36+
CFLAGS_ALL_SHARED = $(CFLAGS_ALL) -fPIC -DSHARED
37+
38+
AR = $(CROSS_COMPILE)ar
39+
RANLIB = $(CROSS_COMPILE)ranlib
40+
INSTALL = ./tools/install.sh
41+
42+
ARCH_INCLUDES = $(wildcard arch/$(ARCH)/bits/*.h)
43+
ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH) $(ARCH_INCLUDES:arch/$(ARCH)/%=include/%))
44+
45+
EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
46+
EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
47+
CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
48+
STATIC_LIBS = lib/libc.a
49+
SHARED_LIBS = lib/libc.so
50+
TOOL_LIBS = lib/musl-gcc.specs
51+
ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
52+
ALL_TOOLS = tools/musl-gcc
53+
54+
LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
55+
56+
-include config.mak
57+
58+
all: $(ALL_LIBS) $(ALL_TOOLS)
59+
60+
install: install-libs install-headers install-tools
61+
62+
clean:
63+
rm -f crt/*.o
64+
rm -f $(OBJS)
65+
rm -f $(LOBJS)
66+
rm -f $(ALL_LIBS) lib/*.[ao] lib/*.so
67+
rm -f $(ALL_TOOLS)
68+
rm -f $(GENH) $(GENH_INT)
69+
rm -f include/bits
70+
71+
distclean: clean
72+
rm -f config.mak
73+
74+
include/bits:
75+
@test "$(ARCH)" || { echo "Please set ARCH in config.mak before running make." ; exit 1 ; }
76+
ln -sf ../arch/$(ARCH)/bits $@
77+
78+
include/bits/alltypes.h.in: include/bits
79+
80+
include/bits/alltypes.h: include/bits/alltypes.h.in include/alltypes.h.in tools/mkalltypes.sed
81+
sed -f tools/mkalltypes.sed include/bits/alltypes.h.in include/alltypes.h.in > $@
82+
83+
src/internal/version.h: $(wildcard F438 VERSION .git)
84+
printf '#define VERSION "%s"\n' "$$(sh tools/version.sh)" > $@
85+
86+
src/internal/version.lo: src/internal/version.h
87+
88+
src/ldso/dynlink.lo: arch/$(ARCH)/reloc.h
89+
90+
crt/crt1.o crt/Scrt1.o: $(wildcard arch/$(ARCH)/crt_arch.h)
91+
92+
crt/Scrt1.o: CFLAGS += -fPIC
93+
94+
OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=src/%))
95+
$(OPTIMIZE_SRCS:%.c=%.o) $(OPTIMIZE_SRCS:%.c=%.lo): CFLAGS += -O3
96+
97+
MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c
98+
$(MEMOPS_SRCS:%.c=%.o) $(MEMOPS_SRCS:%.c=%.lo): CFLAGS += $(CFLAGS_MEMOPS)
99+
100+
# This incantation ensures that changes to any subarch asm files will
101+
# force the corresponding object file to be rebuilt, even if the implicit
102+
# rule below goes indirectly through a .sub file.
103+
define mkasmdep
104+
$(dir $(patsubst %/,%,$(dir $(1))))$(notdir $(1:.s=.o)): $(1)
105+
endef
106+
$(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
107+
108+
%.o: $(ARCH)$(ASMSUBARCH)/%.sub
109+
$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $(dir $<)$(shell cat $<)
110+
111+
%.o: $(ARCH)/%.s
112+
$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
113+
114+
%.o: %.c $(GENH) $(IMPH)
115+
$(CC) $(CFLAGS_ALL_STATIC) -c -o $@ $<
116+
117+
%.lo: $(ARCH)$(ASMSUBARCH)/%.sub
118+
$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $(dir $<)$(shell cat $<)
119+
120+
%.lo: $(ARCH)/%.s
121+
$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
122+
123+
%.lo: %.c $(GENH) $(IMPH)
124+
$(CC) $(CFLAGS_ALL_SHARED) -c -o $@ $<
125+
126+
lib/libc.so: $(LOBJS)
127+
$(CC) $(CFLAGS_ALL_SHARED) $(LDFLAGS) -nostdlib -shared \
128+
-Wl,-e,_start -Wl,-Bsymbolic-functions \
129+
-o $@ $(LOBJS) $(LIBCC)
130+
131+
lib/libc.a: $(OBJS)
132+
rm -f $@
133+
$(AR) rc $@ $(OBJS)
134+
$(RANLIB) $@
135+
136+
$(EMPTY_LIBS):
137+
rm -f $@
138+
$(AR) rc $@
139+
140+
lib/%.o: crt/%.o
141+
cp $< $@
142+
143+
lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
144+
sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
145+
146+
tools/musl-gcc: config.mak
147+
printf '#!/bin/sh\nexec "$${REALGCC:-gcc}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
148+
chmod +x $@
149+
150+
$(DESTDIR)$(bindir)/%: tools/%
151+
$(INSTALL) -D $< $@
152+
153+
$(DESTDIR)$(libdir)/%.so: lib/%.so
154+
$(INSTALL) -D -m 755 $< $@
155+
156+
$(DESTDIR)$(libdir)/%: lib/%
157+
$(INSTALL) -D -m 644 $< $@
158+
159+
$(DESTDIR)$(includedir)/bits/%: arch/$(ARCH)/bits/%
160+
$(INSTALL) -D -m 644 $< $@
161+
162+
$(DESTDIR)$(includedir)/%: include/%
163+
$(INSTALL) -D -m 644 $< $@
164+
165+
$(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
166+
$(INSTALL) -D -l $(libdir)/libc.so $@ || true
167+
168+
install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
169+
170+
install-headers: $(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/%)
171+
172+
install-tools: $(ALL_TOOLS:tools/%=$(DESTDIR)$(bindir)/%)
173+
174+
175+
176+
.PRECIOUS: $(CRT_LIBS:lib/%=crt/%)
177+
178+
.PHONY: all clean install install-libs install-headers install-tools

micromusl/arch/arm/atomic.h

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#ifndef _INTERNAL_ATOMIC_H
2+
#define _INTERNAL_ATOMIC_H
3+
4+
#include <stdint.h>
5+
6+
static inline int a_ctz_l(unsigned long x)
7+
{
8+
static const char debruijn32[32] = {
9+
0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
10+
31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
11+
};
12+
return debruijn32[(x&-x)*0x076be629 >> 27];
13+
}
14+
15+
static inline int a_ctz_64(uint64_t x)
16+
{
17+
uint32_t y = x;
18+
if (!y) {
19+
y = x>>32;
20+
return 32 + a_ctz_l(y);
21+
}
22+
return a_ctz_l(y);
23+
}
24+
25+
#define __k_cas ((int (*)(int, int, volatile int *))0xffff0fc0)
26+
27+
static inline int a_cas(volatile int *p, int t, int s)
28+
{
29+
int old;
30+
for (;;) {
31+
if (!__k_cas(t, s, p))
32+
return t;
33+
if ((old=*p) != t)
34+
return old;
35+
}
36+
}
37+
38+
static inline void *a_cas_p(volatile void *p, void *t, void *s)
39+
{
40+
return (void *)a_cas(p, (int)t, (int)s);
41+
}
42+
43+
static inline long a_cas_l(volatile void *p, long t, long s)
44+
{
45+
return a_cas(p, t, s);
46+
}
47+
48+
static inline int a_swap(volatile int *x, int v)
49+
{
50+
int old;
51+
do old = *x;
52+
while (__k_cas(old, v, x));
53+
return old;
54+
}
55+
56+
static inline int a_fetch_add(volatile int *x, int v)
57+
{
58+
int old;
59+
do old = *x;
60+
while (__k_cas(old, old+v, x));
61+
return old;
62+
}
63+
64+
static inline void a_inc(volatile int *x)
65+
{
66+
a_fetch_add(x, 1);
67+
}
68+
69+
static inline void a_dec(volatile int *x)
70+
{
71+
a_fetch_add(x, -1);
72+
}
73+
74+
static inline void a_store(volatile int *p, int x)
75+
{
76+
while (__k_cas(*p, x, p));
77+
}
78+
79+
static inline void a_spin()
80+
{
81+
}
82+
83+
static inline void a_crash()
84+
{
85+
*(volatile char *)0=0;
86+
}
87+
88+
static inline void a_and(volatile int *p, int v)
89+
{
90+
int old;
91+
do old = *p;
92+
while (__k_cas(old, old&v, p));
93+
}
94+
95+
static inline void a_or(volatile int *p, int v)
96+
{
97+
int old;
98+
do old = *p;
99+
while (__k_cas(old, old|v, p));
100+
}
101+
102+
static inline void a_or_l(volatile void *p, long v)
103+
{
104+
a_or(p, v);
105+
}
106+
107+
static inline void a_and_64(volatile uint64_t *p, uint64_t v)
108+
{
109+
union { uint64_t v; uint32_t r[2]; } u = { v };
110+
a_and((int *)p, u.r[0]);
111+
a_and((int *)p+1, u.r[1]);
112+
}
113+
114+
static inline void a_or_64(volatile uint64_t *p, uint64_t v)
115+
{
116+
union { uint64_t v; uint32_t r[2]; } u = { v };
117+
a_or((int *)p, u.r[0]);
118+
a_or((int *)p+1, u.r[1]);
119+
}
120+
121+
#endif

micromusl/arch/arm/bits/alltypes.h.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#define _Addr int
2+
#define _Int64 long long
3+
#define _Reg int
4+
5+
TYPEDEF __builtin_va_list va_list;
6+
TYPEDEF __builtin_va_list __isoc_va_list;
7+
8+
#ifndef __cplusplus
9+
TYPEDEF unsigned wchar_t;
10+
#endif
11+
TYPEDEF unsigned wint_t;
12+
13+
TYPEDEF float float_t;
14+
TYPEDEF double double_t;
15+
16+
TYPEDEF long time_t;
17+
TYPEDEF long suseconds_t;
18+
19+
TYPEDEF struct { union { int __i[9]; unsigned __s[9]; } __u; } pthread_attr_t;
20< 741A /code>+
TYPEDEF struct { union { int __i[6]; void *__p[6]; } __u; } pthread_mutex_t;
21+
TYPEDEF struct { union { int __i[12]; void *__p[12]; } __u; } pthread_cond_t;
22+
TYPEDEF struct { union { int __i[8]; void *__p[8]; } __u; } pthread_rwlock_t;
23+
TYPEDEF struct { union { int __i[5]; void *__p[5]; } __u; } pthread_barrier_t;

micromusl/arch/arm/bits/endian.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#if __ARMEB__
2+
#define __BYTE_ORDER __BIG_ENDIAN
3+
#else
4+
#define __BYTE_ORDER __LITTLE_ENDIAN
5+
#endif

0 commit comments

Comments
 (0)
0