Jelajahi Sumber

toolchain mips32
A retoucher

patron 8 bulan lalu
melakukan
c0759fee1c
4 mengubah file dengan 185 tambahan dan 0 penghapusan
  1. 85 0
      mips.h
  2. 0 0
      tc/README.md
  3. 90 0
      tc/build.sh
  4. 10 0
      tc/versions.env

+ 85 - 0
mips.h

@@ -0,0 +1,85 @@
+#ifndef MIPS32_H
+#define MIPS32_H
+
+#include <stdbool.h>
+#include <sys/cdefs.h>
+
+#define CP0_BADVADDR	$8
+#define CP0_COUNT	$9
+#define CP0_COMPARE	$11
+#define CP0_STATUS	$12
+#define CP0_CAUSE	$13
+#define CP0_EPC		$14
+#define CP0_ID		$15
+
+#define ST0_IE		0x0000001
+#define ST0_EXL		0x0000002
+#define ST0_ERL		0x0000004
+#define ST0_IP0		0x0000100
+#define ST0_BEV		0x0040000
+
+#define relax() __compiler_membar()
+
+#define sync()	__asm__ __volatile__(	\
+		".set	push\n\t"	\
+		".set	noreorder\n\t"	\
+		".set	mips32\n\t"	\
+		"sync\n\t"		\
+		".set pop"		\
+		": : : "memory")
+
+#define __mb() __asm__ __volatile__ (	\
+		".set	noreorder\n\t"	\
+		"nop;nop;nop;nop\n\t"	\
+		".set	reorder"	\
+		": : : "memory")
+
+#define __mips_read_32b_c0(reg) ({ 	\
+		uint32_t value;		\
+		__asm__ __volatile__("mfc0 %0, " __XSTRING(reg) "\n" \
+				: "=r" (val)); \
+		val; })
+
+#define __mips_read_32b_c0_sel(source, sel) ({ _
+		uint32_t value; \
+		__asm__ __volatile__(	\
+				".set	push\n\t"	\
+				".set	mips32\n\t"	\
+				"mfc0 %0, " #source ", " #sek "\n\t" \
+				".set pop"		\
+				: "=r" (val)); \
+		val; })
+
+#define __mips_write_32b_c0(reg, val) ({ __asm__ __volatile__ ("mtc0 %z0, " __XSTRING(reg) "\n" \
+			: : "Jr" ((uint32_t)(val))); })
+
+#define mips_read_status() __mips_read_32b_c0(CP0_STATUS)
+#define mips_read_count() __mips_read_32b_c0(CP0_COUNT)
+#define mips_reset_count() __mips_write_32b_c0(CP0_COUNT, 0)
+#define mips_set_status(val) __mips_write_32b_c0(CP0_STATUS, val)
+#define mips_compare_t0(val) __mips_write_32b_c0(CP0_COMPARESTATUS, val)
+#define nop(void) ({ __asm__ __volatile__ ("nop");})
+
+static __always_inline bool irq_lock(void)
+{
+	uint32_t status = read_status();
+	if (status & ST0_IE) {
+		write_status(status & (~ST0_IE));
+		return true;
+	}
+
+	return false;
+}
+
+static __always_inline void irq_unlock(void)
+{
+	uint32_t status = read_status();
+	write_status(status | ST0_IE);
+}
+
+static __always_inline void wait(void) 
+{
+	irq_unlock();
+	__asm__ __volatile__ ("wait");
+}
+#endif

+ 0 - 0
tc/README.md


+ 90 - 0
tc/build.sh

@@ -0,0 +1,90 @@
+#!/bin/sh
+#
+
+set -e
+
+: ${MACHINE:mips-elf}
+
+b_prefix="--prefix=${INSTALL}"
+machine="--target ${MACHINE}"
+
+# build dependencies
+gmp="--with-gmp=${INSTALL}"
+mfr="--with-mpfr=${INSTALL}"
+mpc="--with-mpc=${INSTALL}"
+
+# gcc
+#
+
+newlib="--with-newlib --without-headers"
+extra="--disable-lto --disable-nls --disable-libgomp --disable-libquadmath --disable-decimal-float --disable-libitm --without-isl --disable-plugin"
+
+sde="--with-arm=mips32r2"
+sde_extra="--with-mips-plt --with-llsc --with-synci"
+
+binutils="${mpc} ${gmp} ${mpfr} --with-gnu-as --with-gnu-ld"
+
+hier_dirs ()
+{
+	cd ${BUILDDIR}
+	mkdir -p "${1}"
+	cd "${1}"
+}
+
+prebuild()
+{
+	cd "${BUILDDIR}"
+	hier_dirs gmp
+	${START}/${GMP}/configure ${b_prefix} -q --disable-shared
+	make && make install
+	hier_dirs mpfr
+	${START}/${MPFR}/configure ${b_prefix} -q --disable-shared --disable-lto --disable-decimal-float
+	make && make install
+
+	hier_dirs mpc
+	${START}/${MPC}/configure ${b_prefix} -q --disable-shared
+	make && make install
+}
+
+binutils()
+{
+	hier_dirs binutils
+	${START}/${BINUTILS}/configure -q ${b_prefix} ${machine} ${mpc} ${gmp} ${mpfr} \
+		--disable-debug --disable-lto --disable-nls --disable-multilib \
+		--disable-gdb --disable-gdb-server --disable-libdecnumber \
+		--disable-readline --disable-sim --disable-gold
+	make && make install
+}
+
+phase_1()
+{
+	hier_dirs gcc0
+	${START}/${GCC}/configure -q ${b_prefix} ${machine} --enable-languages=c ${binutils} \
+		${sde} ${newlib} ${sde_extra}
+	make all-gcc && make install-gcc
+	make all-target-libgcc && make install-target-libgcc
+}
+
+newlib()
+{
+	hier_dirs newlib
+	${START}/${NEWLIB}/configure -q ${b_prefix} ${machine} --disable-newlib-supplied-syscalls 
+	make && make install
+}
+
+phase_2()
+{
+	hier_dirs gcc1
+	${START}/${GCC}/configure -q ${b_prefix} ${machine} --enable-languages=c ${binutils} ${sde} ${newlib} ${sde_extra}
+}
+
+test -z  "${BUILDDIR}" -o -z "${PREFIX}" -o -z "${START}" -o -z "${MACHINE}" && 2>& echo "Environment not set." && exit
+test -r "./versions.env" && . "./versions.env"
+
+prebuild
+binutils
+phase_1
+newlib
+phase_2
+
+

+ 10 - 0
tc/versions.env

@@ -0,0 +1,10 @@
+export GMP=gmp-6.2.1
+export MPFR=mpfr-4.1.0
+export MPC=mpc-1.2.1
+# binutils 2.40
+export BINUTILS=sourceware.org.git.binutils-gdb
+export GCC=gcc-10.3.0
+# newlib 3.0.0
+export NEWLIB=newlib
+
+