summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-01-12 10:53:48 +0000
committerEric Andersen <andersen@codepoet.org>2001-01-12 10:53:48 +0000
commitddaf94095891a21cedd6a18d9178e4444fb937a7 (patch)
treeb47bcefa33533e4f41ecce4e3a1bee1d215e006e
parent77879554671206102471bb282accb3251395d151 (diff)
Patch from James Graves <jgraves@deltamobile.com> to better handle m68k.
Also fixes 2 very important malloc bugs! Anyone using malloc (esp mmu-less) should update and recompile. -Erik
-rw-r--r--Makefile14
-rw-r--r--Rules.mak3
-rw-r--r--include/features.h8
-rw-r--r--include/unistd.h4
-rw-r--r--libc/inet/resolv.c18
-rw-r--r--libc/misc/time/Makefile7
-rw-r--r--libc/stdlib/malloc-simple/alloc.c6
-rw-r--r--libc/stdlib/malloc/malloc.c15
-rw-r--r--libc/sysdeps/linux/m68k/README.m68k64
9 files changed, 123 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 7eae424e0..951b1909c 100644
--- a/Makefile
+++ b/Makefile
@@ -72,5 +72,19 @@ $(patsubst %, _dir_%, $(DIRS)) : dummy
$(patsubst %, _dirclean_%, $(DIRS) test) : dummy
$(MAKE) -C $(patsubst _dirclean_%, %, $@) clean
+
+install: libc.a
+ rm -f $(INSTALL_DIR)/include/asm
+ rm -f $(INSTALL_DIR)/include/linux
+ rm -f $(INSTALL_DIR)/include/net
+ ln -s $(KERNEL_SOURCE)/include/asm $(INSTALL_DIR)/include/asm
+ ln -s $(KERNEL_SOURCE)/include/net $(INSTALL_DIR)/include/net
+ ln -s $(KERNEL_SOURCE)/include/linux $(INSTALL_DIR)/include/linux
+ mkdir -p $(INSTALL_DIR)/include/bits
+ find include/ -type f -depth -print | cpio -pdmu $(INSTALL_DIR)
+ find include/bits/ -depth -print | cpio -pdmu $(INSTALL_DIR)
+ cp libc.a $(INSTALL_DIR)/lib
+ if [ -f crt0.o ] ; then cp crt0.o $(INSTALL_DIR)/lib ; fi
+
.PHONY: dummy
diff --git a/Rules.mak b/Rules.mak
index 901976e07..dd5206545 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -58,6 +58,9 @@ ifneq ($(HAS_FLOATS),true)
CFLAGS += -D__HAS_NO_FLOATS__
endif
+ifeq ($(TARGET_ARCH),m68k)
+ CFLAGS += -D__VFORK_MACRO__ -Dconst= -D__const= -D__extension__=
+endif
# It turns out the currently, function-sections causes ldelf2flt to segfault.
# So till further notice, this is disabled by default....
diff --git a/include/features.h b/include/features.h
index 634590f49..f51ebd7e2 100644
--- a/include/features.h
+++ b/include/features.h
@@ -24,19 +24,27 @@
#define __P(x) x
#define __PMT(x) x
+#ifndef __const
#define __const const
+#endif
/* Almost ansi */
#if __STDC__ != 1
+#ifndef const
#define const
+#endif
#define volatile
#endif
#else /* K&R */
#define __P(x) ()
+#ifndef __const
#define __const
+#endif
+#ifndef const
#define const
+#endif
#define volatile
#endif
diff --git a/include/unistd.h b/include/unistd.h
index 1ccd29480..916d972a0 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -1008,6 +1008,10 @@ extern int pthread_atfork __P ((void (*__prepare) (void),
void (*__child) (void)));
#endif
+#ifdef __VFORK_MACRO__
+#include <bits/vfork.h>
+#endif
+
__END_DECLS
#endif /* unistd.h */
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 18f366e87..91442b3a9 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -56,10 +56,16 @@
#undef DEBUG
#ifdef DEBUG
-#define DPRINTF(X,args...) printf(X,args...)
+static inline void DPRINTF(const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+}
#else
-#define DPRINTF(X,args...)
-#endif /* DEBUG */
+static inline void DPRINTF(const char *format, ...) { }
+#endif
#ifdef L_encodeh
int encode_header(struct resolv_header *h, unsigned char *dest, int maxlen)
@@ -481,7 +487,7 @@ int dns_lookup(const char *name, int type, int nscount, const char **nsip,
h.qdcount = 1;
h.rd = 1;
- DPRINTF("encoding header\n");
+ DPRINTF("encoding header\n", h.rd);
i = encode_header(&h, packet, PACKETSZ);
if (i < 0)
@@ -554,7 +560,7 @@ int dns_lookup(const char *name, int type, int nscount, const char **nsip,
/* unsolicited */
goto again;
- DPRINTF("Got response (i think)!\n");
+ DPRINTF("Got response %s\n", "(i think)!");
DPRINTF("qrcount=%d,ancount=%d,nscount=%d,arcount=%d\n",
h.qdcount, h.ancount, h.nscount, h.arcount);
DPRINTF("opcode=%d,aa=%d,tc=%d,rd=%d,ra=%d,rcode=%d\n",
@@ -778,7 +784,7 @@ int open_nameservers()
}
fclose(fp);
} else {
- DPRINTF("failed to open resolv.conf\n");
+ DPRINTF("failed to open %s\n", "resolv.conf");
}
DPRINTF("nameservers = %d\n", nameservers);
return 0;
diff --git a/libc/misc/time/Makefile b/libc/misc/time/Makefile
index d225614cb..4b9e98db9 100644
--- a/libc/misc/time/Makefile
+++ b/libc/misc/time/Makefile
@@ -26,12 +26,7 @@ LIBC=$(TOPDIR)libc.a
CSRC=localtime.c gmtime.c asctime.c ctime.c asc_conv.c tm_conv.c mktime.c \
localtime_r.c gmtime_r.c asctime_r.c ctime_r.c utimes.c adjtime.c \
- clock.c times.c difftime.c
-
-# strftime.c causes an internal compiler error with m68k-pic-coff-gcc.
-ifneq ($(TARGET_ARCH),m68k)
- CSRC += strftime.c
-endif
+ clock.c times.c difftime.c strftime.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
OBJS=$(COBJS)
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c
index f31105d4e..f278a9583 100644
--- a/libc/stdlib/malloc-simple/alloc.c
+++ b/libc/stdlib/malloc-simple/alloc.c
@@ -99,10 +99,12 @@ void *realloc(void *ptr, size_t size)
if (size > 0) {
newptr = malloc(size);
- if (newptr && ptr)
+ if (newptr && ptr) {
memcpy(newptr, ptr, size);
+ free(ptr);
+ }
}
- if (ptr)
+ else
free(ptr);
return newptr;
}
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index b20c09390..fce529d80 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -495,7 +495,13 @@ static Block_t *bl_mapnew(size_t size)
map_size = PAGE_ALIGN(size);
pt = mmap(LARGE_MSTART, map_size, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE | MAP_ANON, 0, 0);
+#ifdef __HAS_NO_MMU__
+ MAP_SHARED | MAP_ANONYMOUS
+#else
+ MAP_PRIVATE | MAP_ANONYMOUS
+#endif
+ 0, 0);
+
if (pt == MAP_FAILED)
return (Block_t *) NULL;
@@ -517,7 +523,12 @@ void __bl_uncommit(Block_t * b)
#if M_DOTRIMMING
mmap(u_start, u_end - u_start, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_PRIVATE | MAP_ANON | MAP_FIXED, 0, 0);
+#ifdef __HAS_NO_MMU__
+ MAP_SHARED | MAP_ANONYMOUS |MAP_FIXED
+#else
+ MAP_PRIVATE | MAP_ANONYMOUS |MAP_FIXED
+#endif
+ 0, 0);
#endif
}
diff --git a/libc/sysdeps/linux/m68k/README.m68k b/libc/sysdeps/linux/m68k/README.m68k
new file mode 100644
index 000000000..697413852
--- /dev/null
+++ b/libc/sysdeps/linux/m68k/README.m68k
@@ -0,0 +1,64 @@
+
+README for uC-libc on the m68k[nommu] architecture
+
+James Graves <jgraves@deltamobile.com>
+
+For now (2001/1/9) support for the m68k should be considered "alpha"
+quality at best. It mostly works OK for some of the stuff I'm working
+on, but you can't fully compile other things (like the user
+applications for uClinux). Needs lots more testing.
+
+Only developed/tested with m68k-pic-coff-gcc 2.7.2.3-pic-060999, from
+Lineo.
+
+Configuration:
+
+ Read and edit the Config file, carefully.
+
+ TARGET_ARCH=m68k
+ CROSS = m68k-pic-coff-
+ CC = $(CROSS)gcc
+ STRIPTOOL = $(CROSS)strip
+ KERNEL_SOURCE=/opt/uClinux/linux
+ HAS_MMU = false
+ HAS_FLOATS = false
+ MALLOC = malloc-simple
+ INSTALL_DIR = /opt/uClinux/m68k-pic-coff
+
+ The regular malloc library is broken, dunno why. Use
+ simple-malloc.
+
+Installation:
+ Theoretically, you should be able to install right over the
+ existing uC-libc 0.9.1 files in
+ /opt/uClinux/m68k-pic-coff/include, but I recommend cleaning
+ out all the include files there.
+
+ The only file in there that's not from the old uC-libc is
+ assert.h, but I don't know why that would be the valid copy.
+
+ run:
+ make install
+
+Usage:
+ Any program you compile should have this added to CFLAGS:
+
+ -D__VFORK_MACRO__ -Dconst= -D__const=
+
+ (You need the equal sign so that const and __const are defined
+ as NULL instead of as '1') The 'const' keyword is broken for
+ m68k-pic-coff-gcc 2.7.2.3-pic-060999. There _was_ a fix
+ floating around, but apparently it didn't work.
+
+Problems:
+
+ I _may_ be able to help if you run into problems. Create a
+ really, really short program that demonstrates the problem,
+ and contact me.
+
+TODO:
+ Fix vfork().
+
+ Does crt0.o still need to be a separate file? Can't I just
+ stick it in libc.a and be done with it? Is that specified in
+ the GCC link options?