diff --git a/Makefile b/Makefile index c656a19..b63a17e 100644 --- a/Makefile +++ b/Makefile @@ -34,8 +34,9 @@ CONFIG = $(TOPSRC)/tools/configsys/config all: $(MAKE) -C tools + $(MAKE) -C src $(MAKE) -C lib - $(MAKE) -C src install + $(MAKE) -C install $(MAKE) kernel $(MAKE) fs diff --git a/cross.mk b/cross.mk index 89b37ac..9ca90fa 100644 --- a/cross.mk +++ b/cross.mk @@ -23,9 +23,13 @@ LDFLAGS = LIBS = # Add system include path -ifeq (,$(wildcard /usr/include/i386-linux-gnu)) - CFLAGS += -I/usr/include +ifeq (/usr/include/x86_64-linux-gnu,$(wildcard /usr/include/x86_64-linux-gnu)) + CFLAGS += -I/usr/include/x86_64-linux-gnu else +ifeq (/usr/include/i386-linux-gnu,$(wildcard /usr/include/i386-linux-gnu)) CFLAGS += -I/usr/include/i386-linux-gnu +else + CFLAGS += -I/usr/include +endif endif CFLAGS += -I$(TOPSRC)/include diff --git a/include/strings.h b/include/strings.h index 2df3f54..63029a8 100644 --- a/include/strings.h +++ b/include/strings.h @@ -37,7 +37,7 @@ typedef unsigned size_t; int bcmp(const void *, const void *, size_t); void bcopy(const void *, void *, size_t); -void bzero(void *, unsigned long); +void bzero(void *, unsigned int); int ffs(int); char *index(const char *, int); char *rindex(const char *, int); diff --git a/lib/startup/Makefile b/lib/startup/Makefile index 5e34f6a..773c572 100644 --- a/lib/startup/Makefile +++ b/lib/startup/Makefile @@ -9,14 +9,15 @@ TOPSRC = $(shell cd ../..; pwd) include $(TOPSRC)/target.mk vpath %.c $(TOPSRC)/src/startup-mips -CFLAGS = -Os -B$(TOPSRC)/lib/ -Wa,-x $(DEFS) +CFLAGS = -v -Os -B$(TOPSRC)/lib/ $(DEFS) OBJS = ../crt0.o all: $(OBJS) ../crt0.o: crt0.c - $(CC) $(DEFS) $(CFLAGS) -c $< -o $@ + $(CC) $(DEFS) $(CFLAGS) -S $< -o crt0.s + $(TOPSRC)/lib/as -x crt0.s -o $@ clean: rm -f $(OBJS) *~ diff --git a/src/cmd/ranlib/ranlib.c b/src/cmd/ranlib/ranlib.c index 8d0d668..77fc43e 100644 --- a/src/cmd/ranlib/ranlib.c +++ b/src/cmd/ranlib/ranlib.c @@ -262,7 +262,7 @@ bad1: (void)lseek(rfd, (off_t)r_off, SEEK_SET); void symobj() { register RLIB *rp; - char hb[sizeof(struct ar_hdr) + 1]; + char hb[sizeof(struct ar_hdr) + 1 + 64]; long ransize, baseoff; /* Rewind the archive, leaving the magic number. */ diff --git a/src/libc/gen/execvp.c b/src/libc/gen/execvp.c index adc120c..b019a8f 100644 --- a/src/libc/gen/execvp.c +++ b/src/libc/gen/execvp.c @@ -19,7 +19,8 @@ execlp(name, argv) static char * execat(s1, s2, si) - register char *s1, *s2; + register char *s1; + const char *s2; char *si; { register char *s; diff --git a/src/libc/gen/syslog.c b/src/libc/gen/syslog.c index 51276fe..a38d6b7 100644 --- a/src/libc/gen/syslog.c +++ b/src/libc/gen/syslog.c @@ -85,7 +85,7 @@ vsyslog(pri, fmt, ap) } /* Check priority against setlogmask values. */ - if (! LOG_MASK(LOG_PRI(pri)) && LogMask) + if (LOG_MASK(LOG_PRI(pri)) == 0 && LogMask) return; saved_errno = errno; @@ -161,7 +161,7 @@ vsyslog(pri, fmt, ap) if (pid == -1) return; if (pid == 0) { - fd = open(_PATH_CONSOLE, O_WRONLY, 0); + fd = open(_PATH_CONSOLE, O_WRONLY, 0); p = index(tbuf, '>') + 1; (void)write(fd, p, cnt - (p - tbuf)); (void)close(fd); diff --git a/src/libc/gen/ualarm.c b/src/libc/gen/ualarm.c index 412f376..4fde1f6 100644 --- a/src/libc/gen/ualarm.c +++ b/src/libc/gen/ualarm.c @@ -28,5 +28,5 @@ ualarm(usecs, reload) if (setitimer(ITIMER_REAL, &new, &old) == 0) return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); /* else */ - return (-1); + return (-1); } diff --git a/sys/include/select.h b/sys/include/select.h index a62cb78..01fb24b 100644 --- a/sys/include/select.h +++ b/sys/include/select.h @@ -62,7 +62,7 @@ typedef struct fd_set { #ifndef KERNEL #ifndef CROSS -void bzero(void *, unsigned long); +void bzero(void *, unsigned int); #endif /* According to POSIX.1-2001 */ diff --git a/sys/pic32/Makefile.kconf b/sys/pic32/Makefile.kconf index 2f8a52f..f092782 100644 --- a/sys/pic32/Makefile.kconf +++ b/sys/pic32/Makefile.kconf @@ -5,18 +5,17 @@ # include ../gcc-config.mk -AS = ${MIPS_GCC_PREFIX}as ${DEBUG} -mips32r2 -EL -CC = ${MIPS_GCC_PREFIX}gcc ${DEBUG} -mips32r2 -EL -nostdinc -fno-builtin -Werror -Wall -CPP = ${MIPS_GCC_PREFIX}cpp -LD = ${MIPS_GCC_PREFIX}gcc -mips32r2 -EL +AS = $(LLVMBIN)/clang -target mipsel -mcpu=mips32r2 ${DEBUG} +CC = -mabi=o32 -mfloat-abi=soft \ + -nostdinc -fshort-double -fomit-frame-pointer -finline-hint-functions -I$(TOPSRC)/include +CC = $(LLVMBIN)/clang -target mipsel -mcpu=mips32r2 -mabi=o32 -mfloat-abi=soft \ + ${DEBUG} -nostdinc -fno-builtin -Werror -Wall +CPP = $(LLVMBIN)/clang-cpp +LD = /usr/lib/llvm-12/bin/ld.lld -m elf32ltsmip LDFLAGS = -nostdlib -T ../${LDSCRIPT} -Wl,-Map=$(basename $@).map -SIZE = ${MIPS_GCC_PREFIX}size -OBJCOPY = ${MIPS_GCC_PREFIX}objcopy -OBJDUMP = ${MIPS_GCC_PREFIX}objdump - -ifneq (${MIPS_GCC_FORMAT},) - LDFLAGS += -Wl,--oformat=${MIPS_GCC_FORMAT} -endif +SIZE = $(LLVMBIN)/llvm-size +OBJCOPY = $(LLVMBIN)/llvm-objcopy +OBJDUMP = $(LLVMBIN)/llvm-objdump # sources are located via $S relative to the compilation directory S = ../.. diff --git a/sys/pic32/gcc-config.mk b/sys/pic32/gcc-config.mk index 0806fc2..8ba2f95 100644 --- a/sys/pic32/gcc-config.mk +++ b/sys/pic32/gcc-config.mk @@ -1,81 +1,33 @@ -# chipKIT PIC32 compiler from UECIDE -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Use UECIDE package from http://uecide.org/download -ifndef MIPS_GCC_PREFIX - ifdef UECIDE - ifeq ($(UECIDE)/compilers/pic32-tools-452/bin/pic32-gcc,$(wildcard $(UECIDE)/compilers/pic32-tools-452/bin/pic32-gcc)) - MIPS_GCC_PREFIX = $(UECIDE)/compilers/pic32-tools-452/bin/pic32- - MIPS_GCC_FORMAT = elf32-tradlittlemips - endif - endif +# Clang compiler on Linux +# ~~~~~~~~~~~~~~~~~~~~~~~ +# Install by: +# sudo apt install clang-12 +# Newer versions are also OK. +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/lib/llvm-12/bin/clang)) +endif +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/lib/llvm-13/bin/clang)) +endif +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/lib/llvm-14/bin/clang)) endif -# chipKIT PIC32 compiler on Linux -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Download from https://github.com/jasonkajita/chipKIT-cxx/downloads -# and unzip to /usr/local. -# Need to copy pic32-tools/pic32mx/include/stdarg.h -# to pic32-tools/lib/gcc/pic32mx/4.5.1/include. -# MPLABX C32 compiler doesn't support some functionality -# we need, so use chipKIT compiler by default. -ifndef MIPS_GCC_PREFIX - ifeq (/usr/local/pic32-tools/bin/pic32-gcc,$(wildcard /usr/local/pic32-tools/bin/pic32-gcc)) - MIPS_GCC_PREFIX = /usr/local/pic32-tools/bin/pic32- - MIPS_GCC_FORMAT = elf32-tradlittlemips - endif +# Clang compiler on MacOS +# ~~~~~~~~~~~~~~~~~~~~~~~ +# Install by: +# brew install clang@12 +# Newer versions are also OK. +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@12/12.*/bin/clang-12)) +endif +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@13/13.*/bin/clang-13)) +endif +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@14/14.*/bin/clang-14)) endif -# Generic MIPS toolchain -# ~~~~~~~~~~~~~~~~~~~~~~ -# You can build it from sources, as described on page -# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips -ifndef MIPS_GCC_PREFIX - ifeq (/usr/local/mips-gcc-4.8.1/bin/mips-elf-gcc,$(wildcard /usr/local/mips-gcc-4.8.1/bin/mips-elf-gcc)) - MIPS_GCC_PREFIX = /usr/local/mips-gcc-4.8.1/bin/mips-elf- - endif -endif - -# Generic MIPS toolchain on *BSD -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# You can build it from sources, as described on page -# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips -# Maybe you can install it from packages one day too. -ifndef MIPS_GCC_PREFIX - ifeq (/usr/local/mips-elf/bin/mips-elf-gcc,$(wildcard /usr/local/mips-elf/bin/mips-elf-gcc)) - MIPS_GCC_PREFIX = /usr/local/mips-elf/bin/mips-elf- - endif -endif - -# Mentor Sourcery CodeBench Lite toolchain -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -ifndef MIPS_GCC_PREFIX - # Download a Linux binary package from - # https://sourcery.mentor.com/GNUToolchain/release2641 - ifeq (/usr/local/mips-2013.11/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2013.11/bin/mips-sde-elf-gcc)) - MIPS_GCC_PREFIX = /usr/local/mips-2013.11/bin/mips-sde-elf- - MIPS_GCC_FORMAT = elf32-tradlittlemips - endif -endif -ifndef MIPS_GCC_PREFIX - # Download a Linux binary package from - # https://sourcery.mentor.com/GNUToolchain/release2774 - ifeq (/usr/local/mips-2014.05/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2014.05/bin/mips-sde-elf-gcc)) - MIPS_GCC_PREFIX = /usr/local/mips-2014.05/bin/mips-sde-elf- - MIPS_GCC_FORMAT = elf32-tradlittlemips - endif -endif - -# Imagination Codescape MIPS SDK Essentials -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Download a Linux binary package from: -# http://community.imgtec.com/developers/mips/tools/codescape-mips-sdk/download-codescape-mips-sdk-essentials/ -ifndef MIPS_GCC_ROOT - ifeq (/opt/imgtec/Toolchains/mips-mti-elf/2015.01-7,$(wildcard /opt/imgtec/Toolchains/mips-mti-elf/2015.01-7)) - MIPS_GCC_ROOT = /opt/imgtec/Toolchains/mips-mti-elf/2015.01-7 - MIPS_GCC_FORMAT = elf32-tradlittlemips - endif -endif - -ifndef MIPS_GCC_PREFIX - $(error Unable to locate any GCC MIPS toolchain!) +ifeq ($(LLVMBIN),) + $(error Unable to find any CLANG toolchain!) endif diff --git a/target.mk b/target.mk index 9e32dd7..8c39bf6 100644 --- a/target.mk +++ b/target.mk @@ -4,88 +4,50 @@ RELEASE = 0.0 BUILD = $(shell git rev-list HEAD --count) VERSION = $(RELEASE)-$(BUILD) -# chipKIT PIC32 compiler from UECIDE -ifdef UECIDE -ifndef GCCPREFIX - ifeq ($(UECIDE)/compilers/pic32-tools-452/bin/pic32-gcc,$(wildcard $(UECIDE)/compilers/pic32-tools-452/bin/pic32-gcc)) - GCCPREFIX = ${UECIDE}/compilers/pic32-tools-452/bin/pic32- - LDFLAGS = -Wl,--oformat=elf32-tradlittlemips - INCLUDES = -I${UECIDE}/compilers/pic32-tools-452/lib/gcc/pic32mx/4.5.2/include - endif +# Clang compiler on Linux +# ~~~~~~~~~~~~~~~~~~~~~~~ +# Install by: +# sudo apt install clang-12 +# Newer versions are also OK. +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/lib/llvm-12/bin/clang)) endif +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/lib/llvm-13/bin/clang)) +endif +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/lib/llvm-14/bin/clang)) endif -# chipKIT PIC32 compiler on Linux -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# Download from https://github.com/jasonkajita/chipKIT-cxx/downloads -# and unzip to /usr/local. -# Need to copy pic32-tools/pic32mx/include/stdarg.h -# to pic32-tools/lib/gcc/pic32mx/4.5.1/include. -# MPLABX C32 compiler doesn't support some functionality -# we need, so use chipKIT compiler by default. -ifndef GCCPREFIX -ifeq (/usr/local/pic32-tools/bin/pic32-gcc,$(wildcard /usr/local/pic32-tools/bin/pic32-gcc)) - GCCPREFIX = /usr/local/pic32-tools/bin/pic32- - LDFLAGS = -Wl,--oformat=elf32-tradlittlemips - INCLUDES = -I/usr/local/pic32-tools/lib/gcc/pic32mx/4.5.1/include +# Clang compiler on MacOS +# ~~~~~~~~~~~~~~~~~~~~~~~ +# Install by: +# brew install clang@12 +# Newer versions are also OK. +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@12/12.*/bin/clang-12)) endif +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@13/13.*/bin/clang-13)) +endif +ifeq ($(LLVMBIN),) + LLVMBIN = $(dir $(wildcard /usr/local/Cellar/llvm@14/14.*/bin/clang-14)) endif -# Generic MIPS toolchain -# ~~~~~~~~~~~~~~~~~~~~~~ -# You can build it from sources, as described on page -# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips -ifndef GCCPREFIX -ifeq (/usr/local/mips-gcc-4.8.1/bin/mips-elf-gcc,$(wildcard /usr/local/mips-gcc-4.8.1/bin/mips-elf-gcc)) - GCCPREFIX = /usr/local/mips-gcc-4.8.1/bin/mips-elf- - LDFLAGS = - INCLUDES = -endif +ifeq ($(LLVMBIN),) + $(error Unable to find any CLANG toolchain!) endif -# Generic MIPS toolchain on *BSD -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# You can build it from sources, as described on page -# http://retrobsd.org/wiki/doku.php/doc/toolchain-mips -# Maybe you can install it from packages one day too. -ifndef GCCPREFIX -ifeq (/usr/local/mips-elf/bin/mips-elf-gcc,$(wildcard /usr/local/mips-elf/bin/mips-elf-gcc)) - GCCPREFIX = /usr/local/mips-elf/bin/mips-elf- - LDFLAGS = - INCLUDES = -endif -endif - -# Mentor Sourcery CodeBench Lite toolchain -# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# You can download a Linux or Windows binary package from -# https://sourcery.mentor.com/GNUToolchain/release2641 -ifndef GCCPREFIX -ifeq (/usr/local/mips-2013.11/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2013.11/bin/mips-sde-elf-gcc)) - GCCPREFIX = /usr/local/mips-2013.11/bin/mips-sde-elf- - LDFLAGS = -Wl,--oformat=elf32-tradlittlemips - INCLUDES = -endif -endif -ifndef GCCPREFIX -ifeq (/usr/local/mips-2014.05/bin/mips-sde-elf-gcc,$(wildcard /usr/local/mips-2014.05/bin/mips-sde-elf-gcc)) - GCCPREFIX = /usr/local/mips-2014.05/bin/mips-sde-elf- - LDFLAGS = -Wl,--oformat=elf32-tradlittlemips - INCLUDES = -endif -endif - -ifndef GCCPREFIX - $(error Unable to locate any GCC MIPS toolchain!) -endif - -CC = $(GCCPREFIX)gcc -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES) -CXX = $(GCCPREFIX)g++ -mips32r2 -EL -msoft-float -nostdinc -fshort-double -I$(TOPSRC)/include $(INCLUDES) -LD = $(GCCPREFIX)ld -AR = $(GCCPREFIX)ar -RANLIB = $(GCCPREFIX)ranlib -SIZE = $(GCCPREFIX)size -OBJDUMP = $(GCCPREFIX)objdump -mmips:isa32r2 +CC = $(LLVMBIN)clang -target mipsel -mcpu=mips32r2 -mabi=o32 -mfloat-abi=soft \ + -nostdinc -fomit-frame-pointer -finline-hint-functions -I$(TOPSRC)/include \ + -Wno-builtin-requires-header +CXX = $(LLVMBIN)clang++ -target mipsel -mcpu=mips32r2 -mabi=o32 -mfloat-abi=soft \ + -nostdinc -fomit-frame-pointer -finline-hint-functions -I$(TOPSRC)/include +LD = $(LLVMBIN)ld.lld -m elf32ltsmip +AR = $(LLVMBIN)llvm-ar +RANLIB = $(LLVMBIN)llvm-ranlib +SIZE = $(LLVMBIN)llvm-size +OBJDUMP = $(LLVMBIN)llvm-objdump --mcpu=mips32r2 AS = $(CC) -x assembler-with-cpp -c YACC = byacc LEX = flex @@ -97,9 +59,9 @@ ELF2AOUT = $(TOPSRC)/tools/elf2aout/elf2aout CFLAGS = -Os -LDFLAGS += -N -nostartfiles -fno-dwarf2-cfi-asm -T$(TOPSRC)/src/elf32-mips.ld \ +LDFLAGS = -N -nostartfiles -fno-dwarf2-cfi-asm -T$(TOPSRC)/src/elf32-mips.ld \ $(TOPSRC)/src/crt0.o -L$(TOPSRC)/src LIBS = -lc # Enable mips16e instruction set by default -CFLAGS += -mips16 +#CFLAGS += -mips16 diff --git a/tools/kconfig/config.h b/tools/kconfig/config.h index 20f3f3a..108c2cc 100644 --- a/tools/kconfig/config.h +++ b/tools/kconfig/config.h @@ -125,15 +125,15 @@ struct config { /* * Config has a global notion of which architecture is being used. */ -int arch; -char *archname; +extern int arch; +extern char *archname; #define ARCH_PIC32 1 /* * For each architecture, a set of CPU's may be specified as supported. * These and the options (below) are put in the C flags in the makefile. */ -struct cputype { +extern struct cputype { char *cpu_name; struct cputype *cpu_next; } *cputype; @@ -143,7 +143,7 @@ struct cputype { * but which may also specify values for the options. * A separate set of options may be defined for make-style options. */ -struct opt { +extern struct opt { char *op_name; char *op_value; struct opt *op_next; @@ -152,30 +152,30 @@ struct opt { /* * Mapping of signal names to pins. */ -struct signal { +extern struct signal { char *sig_name; int sig_pin; int sig_invert; struct signal *sig_next; } *siglist; -char *board; -char *ldscript; +extern char *board; +extern char *ldscript; -int do_trace; +extern int do_trace; -struct device *dtab; +extern struct device *dtab; -char errbuf[80]; -int yyline; +extern char errbuf[80]; +extern int yyline; -struct file_list *ftab, *conf_list, **confp, *comp_list, **compp; +extern struct file_list *ftab, *conf_list, **confp, *comp_list, **compp; -int zone, hadtz; -int dst; -int debugging; +extern int zone, hadtz; +extern int dst; +extern int debugging; -int maxusers; +extern int maxusers; #define eq(a,b) (!strcmp(a,b)) diff --git a/tools/kconfig/config.y b/tools/kconfig/config.y index e325f4a..300584d 100644 --- a/tools/kconfig/config.y +++ b/tools/kconfig/config.y @@ -102,6 +102,7 @@ #include "config.h" #include #include +#include struct device cur; struct device *curp = 0; diff --git a/tools/kconfig/main.c b/tools/kconfig/main.c index 9e9465a..cd27a4e 100644 --- a/tools/kconfig/main.c +++ b/tools/kconfig/main.c @@ -38,6 +38,23 @@ #include "y.tab.h" #include "config.h" +int arch; +char *archname; +struct cputype *cputype; +struct opt *opt, *mkopt; +struct signal *siglist; +char *board; +char *ldscript; +int do_trace; +struct device *dtab; +char errbuf[80]; +int yyline; +struct file_list *ftab, *conf_list, **confp, *comp_list, **compp; +int zone, hadtz; +int dst; +int debugging; +int maxusers; + /* * Config builds a set of files for building a UNIX * system given a description of the desired system. diff --git a/tools/kconfig/mkswapconf.c b/tools/kconfig/mkswapconf.c index 29d886c..9d403a7 100644 --- a/tools/kconfig/mkswapconf.c +++ b/tools/kconfig/mkswapconf.c @@ -38,6 +38,7 @@ #include #include +#include void swapconf() { diff --git a/tools/virtualmips/dev_nand_flash_1g.c b/tools/virtualmips/dev_nand_flash_1g.c index 784367a..b08a19a 100644 --- a/tools/virtualmips/dev_nand_flash_1g.c +++ b/tools/virtualmips/dev_nand_flash_1g.c @@ -373,7 +373,7 @@ static int load_nand_flash_file (nand_flash_1g_data_t * d) int i, j = 0; struct dirent *ent = NULL; DIR *p_dir; - char file_path[64]; + char file_path[1024]; char *file_name; char block_number[16]; int fd;