Browse Source

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

Eric Andersen 23 years ago
parent
commit
ddaf940958

+ 14 - 0
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
 

+ 3 - 0
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....

+ 8 - 0
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

+ 4 - 0
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  */

+ 12 - 6
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;

+ 1 - 6
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)

+ 4 - 2
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;
 }

+ 13 - 2
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
 }
 

+ 64 - 0
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?