@@ -251,6 +251,41 @@ install:
@for script in ${SCRIPTS}; do\
$(INSTALL_DATA) ${srcdir}/$${script}.ld $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}/$${script}.ld; \
done
+ mkdir -p $(DESTDIR)$(tooldir)/include/mips
+ @for header in ${srcdir}/include/mips/*.h; do\
+ $(INSTALL_DATA) $${header} $(DESTDIR)$(tooldir)/include/mips; \
+ done
+ @for file in ${srcdir}/include/mips/*.S; do\
+ $(INSTALL_DATA) $${file} $(DESTDIR)$(tooldir)/include/mips; \
+ done
+ mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/boot
+ @for file in ${srcdir}/boot/*.[hS] ; do\
+ $(INSTALL_DATA) $${file} $(DESTDIR)$(exec_prefix)/share/mips/boot/; \
+ done
+ mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/hal
+ @for file in ${srcdir}/hal/*.[hSc]; do\
+ $(INSTALL_DATA) $${file} $(DESTDIR)$(exec_prefix)/share/mips/hal/; \
+ done
+ mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/uhi
+ @for file in ${srcdir}/uhi/uhi_*.[hSc] ${srcdir}/uhi/yamon_*.[hSc]; do\
+ $(INSTALL_DATA) $${file} $(DESTDIR)$(exec_prefix)/share/mips/uhi/; \
+ done
+ mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/rules
+ @$(INSTALL_DATA) ${srcdir}/rules/mipshal.mk $(DESTDIR)$(exec_prefix)/share/mips/rules/
+ @$(INSTALL_PROGRAM) ${srcdir}/rules/srec2hex.pl $(DESTDIR)$(exec_prefix)/share/mips/rules/
+ mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/examples
+ for example in $(EXAMPLES); do\
+ mkdir -p $(DESTDIR)$(exec_prefix)/share/mips/examples/$${example}; \
+ $(INSTALL_DATA) ${srcdir}/examples/$${example}/Makefile \
+ $(DESTDIR)$(exec_prefix)/share/mips/examples/$${example}/; \
+ $(INSTALL_DATA) ${srcdir}/examples/$${example}/README.txt \
+ $(DESTDIR)$(exec_prefix)/share/mips/examples/$${example}/; \
+ for file in ${srcdir}/examples/$${example}/*.[cS]; do\
+ $(INSTALL_DATA) $${file} $(DESTDIR)$(exec_prefix)/share/mips/examples/$${example}/; \
+ done; \
+ done
+ $(INSTALL_PROGRAM) ${srcdir}/examples/romable_minimal/makescripts.sh \
+ $(DESTDIR)$(exec_prefix)/share/mips/examples/romable_minimal/makescripts.sh
info:
install-info:
new file mode 100644
@@ -0,0 +1,50 @@
+# Copyright 2015, Imagination Technologies Limited and/or its
+# affiliated group companies.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Variables that mipshal.mk will expand to compiler/linker arguments must be
+# defined before inclusion of mipshal.mk
+
+include ${MIPS_ELF_ROOT}/share/mips/rules/mipshal.mk
+
+CFLAGS += -g -O1
+LDFLAGS += -g
+
+OBJS = custom_excpt.o
+APP = custom_excpt.elf
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(LD) $(LDFLAGS) $^ -o $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+.PHONY: clean
+clean:
+ rm -f $(APP) $(OBJS)
new file mode 100644
@@ -0,0 +1,15 @@
+Demonstration of exception handling by emulating r0 style accesses for memory
+with _mips_handle_exception.
+
+Set environment variable MIPS_ELF_ROOT
+ This should be set to the root of the installation directory for the
+ toolchain (that is, below the bin directory)
+
+To build big-endian
+ # make
+
+To build little-endian
+ # make ENDIAN=EL
+
+To delete temporary and built files
+ # make clean
new file mode 100644
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2015, Imagination Technologies Limited and/or its
+ * affiliated group companies.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <mips/hal.h>
+#include <mips/cpu.h>
+int
+main ()
+{
+ /* Some pointer setup to access memory address 0*/
+ int b = -1;
+ int *a = 0;
+ /* Write to 0, triggering a TLB store error */
+ *a = 0;
+ /* Read from 0, triggering a TLB load error */
+ b = *a;
+ /* Return value should be 0 */
+ return b;
+}
+
+/*
+ * This exception handler emulates register zero style handling but for memory,
+ * i.e. writes to page zero are ignored and reads return a zero for select
+ * instructions.
+ */
+void
+_mips_handle_exception (struct gpctx *ctx, int exception)
+{
+ /*
+ * This example is designed to work only on MIPS32 and does not handle the
+ * case where a memory operation occurs in a branch delay slot.
+ */
+ if ((mips32_get_c0 (C0_CAUSE) & CR_BD) == 0
+ && (ctx->epc & 0x1) == 0)
+ {
+ unsigned int fault_instruction = 0;
+ switch (exception)
+ {
+ case EXC_TLBS:
+ fault_instruction = *((unsigned int *) (ctx->epc));
+ if ((fault_instruction >> 26) == 0x2b)
+ {
+ /* Store instruction, ensure it went to zero. */
+ unsigned int store_reg = (fault_instruction >> 21) & 0x1f;
+ int16_t offset = fault_instruction & 0xffff;
+ unsigned int destination = ctx->r[C_CTX_REGNO(store_reg)] + offset;
+
+ if (destination < 4096)
+ {
+ write (1, "Handled write to zero page\n", 27);
+ ctx->epc += 4;
+ return;
+ }
+ }
+ break;
+
+ case EXC_TLBL:
+ fault_instruction = *((unsigned int *) (ctx->epc));
+ if ((fault_instruction >> 26) == 0x23)
+ {
+ /* Load instruction, ensure it went to zero. */
+ unsigned int load_reg = (fault_instruction >> 21) & 0x1f;
+ int16_t offset = fault_instruction & 0xffff;
+ unsigned int destination = ctx->r[C_CTX_REGNO(load_reg)] + offset;
+ if (destination < 4096)
+ {
+ write (1, "Handled read from zero page\n", 28);
+ ctx->epc += 4;
+ unsigned int rt = (fault_instruction >> 16) & 0x1f;
+ ctx->r[rt] = 0;
+ return;
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /* All other exceptions are passed to the default exception handler. */
+ __exception_handle (ctx, exception);
+}
new file mode 100644
@@ -0,0 +1,50 @@
+# Copyright 2015, Imagination Technologies Limited and/or its
+# affiliated group companies.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Variables that mipshal.mk will expand to compiler/linker arguments must be
+# defined before inclusion of mipshal.mk
+
+include ${MIPS_ELF_ROOT}/share/mips/rules/mipshal.mk
+
+CFLAGS += -g -O1
+LDFLAGS += -g
+
+OBJS = fault_recovery.o
+APP = fault_recovery.elf
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(LD) $(LDFLAGS) $^ -o $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+.PHONY: clean
+clean:
+ rm -f $(APP) $(OBJS)
new file mode 100644
@@ -0,0 +1,15 @@
+Demonstration of exception handling by triggering a memory fault, recovering
+and then continuing.
+
+Set environment variable MIPS_ELF_ROOT
+ This should be set to the root of the installation directory for the
+ toolchain (that is, below the bin directory)
+
+To build big-endian
+ # make
+
+To build little-endian
+ # make ENDIAN=EL
+
+To delete temporary and built files
+ # make clean
new file mode 100644
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014, Imagination Technologies Limited and/or its
+ * affiliated group companies.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdio.h>
+#include <setjmp.h>
+#include <mips/hal.h>
+
+jmp_buf context;
+
+void fault_recover ();
+
+int
+main ()
+{
+ int error = setjmp (context);
+
+ if (error)
+ {
+ printf ("Error handled %d\n", error);
+ /* Return success on this return path. */
+ return 0;
+ }
+
+ /* Initial continuation point from setjmp, cause an memory error. */
+ int *a = 0;
+ *a = 0;
+
+ /* Return error on this return path. */
+ return -1;
+}
+
+void
+_mips_handle_exception (struct gpctx *ctx, int exception)
+{
+ /* If we're here due to a TLB Store exception, return to the
+ fault_recover function. Otherwise use the stand exception handler. */
+ if (exception == EXC_TLBS)
+ {
+ printf ("exception caught\n");
+ ctx->epc = (reg_t)&fault_recover;
+ }
+ else
+ __exception_handle (ctx, exception);
+}
+
+void
+fault_recover ()
+{
+ longjmp (context, EXC_TLBS);
+}
new file mode 100644
@@ -0,0 +1,50 @@
+# Copyright 2015, Imagination Technologies Limited and/or its
+# affiliated group companies.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Variables that mipshal.mk will expand to compiler/linker arguments must be
+# defined before inclusion of mipshal.mk
+
+include ${MIPS_ELF_ROOT}/share/mips/rules/mipshal.mk
+
+CFLAGS += -g -O1
+LDFLAGS += -g
+
+OBJS = interrupt_handler.o
+APP = interrupt_handler.elf
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(LD) $(LDFLAGS) $^ -o $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+.PHONY: clean
+clean:
+ rm -f $(APP) $(OBJS)
new file mode 100644
@@ -0,0 +1,14 @@
+Demonstration of installing an interrupt handler for software interrupts 0.
+
+Set environment variable MIPS_ELF_ROOT
+ This should be set to the root of the installation directory for the
+ toolchain (that is, below the bin directory).
+
+To build big-endian
+ # make
+
+To build little-endian
+ # make ENDIAN=EL
+
+To delete temporary and built files
+ # make clean
new file mode 100644
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2015, Imagination Technologies Limited and/or its
+ * affiliated group companies.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <mips/cpu.h>
+#include <mips/hal.h>
+volatile int handled;
+
+int
+main ()
+{
+ /* Enable SW interrupt 0 */
+ mips32_bs_c0 (C0_STATUS, SR_SINT0);
+ /* Trigger the interrupt */
+ mips32_bs_c0 (C0_CAUSE, SR_SINT0);
+ /* Wait for handling */
+ while (!handled)
+ {
+ };
+
+ printf ("SW0 interrupt handled\n");
+
+ return 1;
+}
+
+/* Handle SW0 */
+void __attribute__ ((interrupt("vector=sw0")))
+_mips_isr_sw0 (void)
+{
+ /* Prove that semi-hosting still works! */
+ write (1, "Hello World\n", 12);
+ /* Count the interrupt */
+ handled += 1;
+ /* Clear the interrupt */
+ mips32_bc_c0 (C0_CAUSE, SR_SINT0);
+}
+
+/* Provide a fall-back handler if anything other than SW0 is raised */
+void __attribute__ ((interrupt, keep_interrupts_masked))
+_mips_interrupt (void)
+{
+ write (1, "Unhandled interrupt occurred\n", 29);
+ __exit (2);
+}
new file mode 100644
@@ -0,0 +1,54 @@
+# Copyright 2015, Imagination Technologies Limited and/or its
+# affiliated group companies.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Variables that mipshal.mk will expand to compiler/linker arguments must be
+# defined before inclusion of mipshal.mk
+
+ISR_VEC_SPACE = 64
+include ${MIPS_ELF_ROOT}/share/mips/rules/mipshal.mk
+
+CFLAGS += -g -O1 -DISR_VEC_SPACE=$(ISR_VEC_SPACE)
+LDFLAGS += -g
+
+OBJS = isr_vector_space.o excpt_isr.o
+APP = isr_vector_space.elf
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(LD) $(LDFLAGS) $^ -o $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+%.o: %.S
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+.PHONY: clean
+clean:
+ rm -f $(APP) $(OBJS)
new file mode 100644
@@ -0,0 +1,19 @@
+Demonstration of defining custom interrupt vector spacing and overriding the
+interrupt vector. This extends the interrupt handler demo to include both
+a C and assembly coded handler.
+
+Set environment variable MIPS_ELF_ROOT
+ This should be set to the root of the installation directory for the
+ toolchain (that is, below the bin directory).
+
+To build with different vector spacing (e.g. 128)
+ # make ISR_VEC_SPACE=128
+
+To build big-endian
+ # make
+
+To build little-endian
+ # make ENDIAN=EL
+
+To delete temporary and built files
+ # make clean
new file mode 100644
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2015, Imagination Technologies Limited and/or its
+ * affiliated group companies.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+*/
+
+# Keep each function in a separate named section
+#define _FUNCTION_SECTIONS_
+
+#include <mips/regdef.h>
+#include <mips/asm.h>
+#include <mips/cpu.h>
+
+#define VEC_SPACE ISR_VEC_SPACE
+
+LEAF(__isr_vec)
+ .set push
+ .set noat
+AENT(__isr_vec_000)
+.weak _mips_isr_sw0
+ lw k1, %gp_rel(handledsw0)(gp)
+ addiu k1, k1, 1
+ sw k1, %gp_rel(handledsw0)(gp)
+ mfc0 k1, C0_CAUSE
+ ins k1, zero, CR_IP_SHIFT + 0, 1
+ mtc0 k1, C0_CAUSE
+ ehb
+ eret
+.org VEC_SPACE
+AENT(__isr_vec_001)
+.weak _mips_isr_sw1
+ li k0, 1
+ LA k1, _mips_isr_sw1
+ beqz k1, 1f
+ jr k1
+.org 2 * VEC_SPACE
+AENT(__isr_vec_002)
+.weak _mips_isr_hw0
+ li k0, 2
+ LA k1, _mips_isr_hw0
+ beqz k1, 1f
+ jr k1
+.org 3 * VEC_SPACE
+AENT(__isr_vec_003)
+.weak _mips_isr_hw1
+ li k0, 3
+ LA k1, _mips_isr_hw1
+ beqz k1, 1f
+ jr k1
+.org 4 * VEC_SPACE
+AENT(__isr_vec_004)
+.weak _mips_isr_hw2
+ li k0, 4
+ LA k1, _mips_isr_hw2
+ beqz k1, 1f
+ jr k1
+.org 5 * VEC_SPACE
+AENT(__isr_vec_005)
+.weak _mips_isr_hw3
+ li k0, 5
+ LA k1, _mips_isr_hw3
+ beqz k1, 1f
+ jr k1
+.org 6 * VEC_SPACE
+AENT(__isr_vec_006)
+.weak _mips_isr_hw4
+ li k0, 6
+ LA k1, _mips_isr_hw4
+ beqz k1, 1f
+ jr k1
+.org 7 * VEC_SPACE
+AENT(__isr_vec_007)
+.weak _mips_isr_hw5
+ li k0, 7
+ LA k1, _mips_isr_hw5
+ beqz k1, 1f
+ jr k1
+.org 8 * VEC_SPACE
+AENT(__isr_vec_fallback)
+.weak _mips_interrupt
+ li k0, -1
+1:
+ LA k1, _mips_interrupt
+ beqz k1, 1b
+ jr k1
+ .set pop
+END(__isr_vec)
new file mode 100644
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2015, Imagination Technologies Limited and/or its
+ * affiliated group companies.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <mips/cpu.h>
+volatile int handledsw0 = 0;
+volatile int handledsw1 = 0;
+void __exit(int);
+
+int
+main ()
+{
+ /* Enable SW interrupts 0/1 */
+ mips32_bs_c0 (C0_STATUS, SR_SINT0 | SR_SINT1);
+ /* Trigger the interrupt */
+ mips32_bs_c0 (C0_CAUSE, SR_SINT0);
+ mips32_bs_c0 (C0_CAUSE, SR_SINT1);
+ /* Wait for handling */
+ while (!handledsw0 || !handledsw1)
+ {
+ };
+
+ printf ("SW0 and SW1 interrupts handled\n");
+
+ return 1;
+}
+
+/* Handle SW1 */
+void __attribute__ ((interrupt("vector=sw1")))
+_mips_isr_sw1 (void)
+{
+ /* Prove that semi-hosting still works! */
+ write (1, "Hello World\n", 12);
+ /* Count the interrupt */
+ handledsw1 += 1;
+ /* Clear the interrupt */
+ mips32_bc_c0 (C0_CAUSE, SR_SINT1);
+}
+
+/* Provide a fall-back handler if anything other than SW0/SW1 is raised */
+void __attribute__ ((interrupt, keep_interrupts_masked))
+_mips_interrupt (void)
+{
+ write (1, "Generic interrupt trapped.\n", 27);
+ __exit(2);
+}
new file mode 100644
@@ -0,0 +1,61 @@
+# Copyright 2015, Imagination Technologies Limited and/or its
+# affiliated group companies.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Variables that mipshal.mk will expand to compiler/linker arguments must be
+# defined before inclusion of mipshal.mk
+
+# Indicate the application should start via the reset vector
+ROMABLE = 1
+# Default to o32 ABI
+ABI ?= 32
+
+# Set up a 1:1 mapping for physical to virtual addresses
+ifeq ($(ABI), 64)
+APP_START = 0xFFFFFFFF80000000
+else
+APP_START = 0x80000000
+endif
+
+include ${MIPS_ELF_ROOT}/share/mips/rules/mipshal.mk
+
+CFLAGS += -g -O1
+LDFLAGS += -g
+OBJS = romable.o
+APP = romable.elf
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(LD) $(LDFLAGS) $^ -o $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+.PHONY: clean
+clean:
+ rm -f $(APP) $(OBJS)
new file mode 100644
@@ -0,0 +1,15 @@
+Demonstration of a bootable example suitable for placing in ROM. This includes
+copying application code to RAM during boot.
+
+Set environment variable MIPS_ELF_ROOT
+ This should be set to the root of the installation directory for the
+ toolchain (that is, below the bin directory)
+
+To build big-endian
+ # make
+
+To build little-endian
+ # make ENDIAN=EL
+
+To delete temporary and built files
+ # make clean
new file mode 100644
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015, Imagination Technologies Limited and/or its
+ * affiliated group companies.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdio.h>
+
+int
+main ()
+{
+ printf ("Hello world!\n");
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,67 @@
+# Copyright 2015, Imagination Technologies Limited and/or its
+# affiliated group companies.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Variables that mipshal.mk will expand to compiler/linker arguments must be
+# defined before inclusion of mipshal.mk
+
+# Indicate the application should start via the reset vector
+ROMABLE = 1
+# Default to o32 ABI
+ABI ?= 32
+
+# Set up a 1:1 mapping for physical to virtual addresses
+ifeq ($(ABI), 64)
+ APP_START = 0xFFFFFFFF80000000
+ LDSCRIPT = minimal64_64.ld
+else
+ APP_START = 0x80000000
+ ifeq ($(ABI), n32)
+ LDSCRIPT = minimal64_n32.ld
+ else
+ LDSCRIPT = minimal32.ld
+ endif
+endif
+
+include ${MIPS_ELF_ROOT}/share/mips/rules/mipshal.mk
+
+CFLAGS += -g -O1
+LDFLAGS += -g
+OBJS = romable_minimal.o
+APP = romable_minimal.elf
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(LD) $(LDFLAGS) $(OBJS) -o $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $< -o $@
+
+.PHONY: clean
+clean:
+ rm -f $(APP) $(OBJS)
new file mode 100644
@@ -0,0 +1,32 @@
+Demonstration of a bootable example without some of the support code normally
+needed for debug, hosted or semi-hosted environments.
+
+The removed features are:
+* No support for UHI argument handling operations (i.e. a0 == -1)
+* No support for returning to a boot monitor or using a boot monitor's
+ UHI support
+* Quiet unhandled exceptions, no output is produced but instead the UHI
+ exception operation is raised and a debugger (or application) can
+ respond to it
+
+These features are removed by modifying the the linker scripts which are
+derived from uhi*.ld linker scripts, using makescripts.sh.
+
+Set environment variable MIPS_ELF_ROOT
+ This should be set to the root of the installation directory for the
+ toolchain (that is, below the bin directory).
+
+First prepare the linker scripts by running makescripts.sh
+ # ./makescripts.sh
+
+To build 32-bit big-endian
+ # make
+
+To build 32-bit little-endian
+ # make ENDIAN=EL
+
+To build 64-bit
+ # make ABI=64
+
+To delete temporary and built files
+ # make clean
new file mode 100644
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+if [ "x$MIPS_ELF_ROOT" = "x" ]; then
+ echo "Error: MIPS_ELF_ROOT is not set"
+ exit 1
+fi
+if [ "x$MIPS_TOOLCHAIN" = "x" ]; then
+ echo "Error: MIPS_TOOLCHAIN is not set (i.e. mips-img-elf)"
+ exit 1
+fi
+COMPILER=${MIPS_ELF_ROOT}/bin/${MIPS_TOOLCHAIN}-gcc
+
+uhi32=`${COMPILER} --print-file-name=uhi32.ld`
+uhi64_64=`${COMPILER} --print-file-name=uhi64_64.ld`
+uhi64_n32=`${COMPILER} --print-file-name=uhi64_n32.ld`
+
+cp $uhi32 minimal32.ld
+cp $uhi64_64 minimal64_64.ld
+cp $uhi64_n32 minimal64_n32.ld
+
+for i in minimal32.ld minimal64_64.ld minimal64_n32.ld; do
+ sed -i -e "s|\(EXTERN *(__getargs).*\)|/* \1 */|" $i
+ sed -i -e "s|\(EXTERN *(__exception_handle_verbose).*\)|"\
+"/* \1 */\n"\
+"/* Use the quiet exception handler for reduced code size */\n"\
+"EXTERN (__exception_handle_quiet)|" $i
+ sed -i -e "s|\(EXTERN *(__register_excpt_boot).*\)|"\
+"/* \1 */|" $i
+ sed -i -e "s|PROVIDE *(__use_excpt_boot = 1)|"\
+"PROVIDE (__use_excpt_boot = 0)|" $i
+done
new file mode 100644
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2015, Imagination Technologies Limited and/or its
+ * affiliated group companies.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+
+int
+main ()
+{
+ write (1, "minimal\n", 8);
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,98 @@
+# Copyright 2015, Imagination Technologies Limited and/or its
+# affiliated group companies.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Variables that mipshal.mk will expand to compiler/linker arguments must be
+# defined before inclusion of mipshal.mk
+
+# Indicate the application should start via the reset vector
+ROMABLE = 1
+
+ifeq ($(CORE), P5600)
+ DEFINES = -DC0_CONFIG0_VALUE=0xB6040483
+ DEFINES += -DC0_CONFIG1_VALUE=0xFEA3519B
+ DEFINES += -DC0_CONFIG2_VALUE=0x80000000
+ DEFINES += -DC0_CONFIG3_VALUE=0xBF8032A8
+ DEFINES += -DC0_CONFIG4_VALUE=0xc01c0000
+ DEFINES += -DC0_CONFIG5_VALUE=0x10000038
+ DEFINES += -DC0_WATCHHI_VALUE=0x00000000
+ OBJS += init_l23caches_predef.o
+ override ABI = 32
+ override ENDIAN = EL
+ override MIPS_TOOLCHAIN = mips-mti-elf
+ APP_START = 0x80000000
+else
+ ifeq ($(CORE), I6400)
+ DEFINES = -DC0_CONFIG0_VALUE=0x80004A05
+ DEFINES += -DC0_CONFIG1_VALUE=0x9EAB559B
+ DEFINES += -DC0_CONFIG2_VALUE=0x80000000
+ DEFINES += -DC0_CONFIG3_VALUE=0xFC8031E9
+ DEFINES += -DC0_CONFIG4_VALUE=0xD0FC0227
+ DEFINES += -DC0_CONFIG5_VALUE=0x00000098
+ DEFINES += -DC0_WATCHHI_VALUE=0x80000000
+ DEFINES += -DC0_WATCHHI1_VALUE=0x80000000
+ DEFINES += -DC0_WATCHHI2_VALUE=0x80000000
+ DEFINES += -DC0_WATCHHI3_VALUE=0x00000000
+ DEFINES += -DC0_CMGCRBASE_VALUE=0x01fbf800
+ DEFINES += -DGCR_L2_CONFIG_VALUE=0x00000000
+ OBJS = init_cm3l2_predef.o
+ override ABI = 64
+ override ENDIAN = EL
+ override MIPS_TOOLCHAIN = mips-img-elf
+ APP_START = 0xFFFFFFFF80000000
+ else
+ $(error Please specify a core using CORE=(P5600|I6400))
+ endif
+endif
+
+include ${MIPS_ELF_ROOT}/share/mips/rules/mipshal.mk
+
+ifeq ($(ENABLE_XPA), 1)
+ DEFINES += -DENABLE_XPA=1
+endif
+
+OBJS += romable_predef.o reset_predef.o init_caches_predef.o init_cp0_predef.o
+OBJS += init_tlb_predef.o corecheck_predef.o
+APP = romable_predef.elf
+
+CFLAGS += -g -O1 $(DEFINES)
+LDFLAGS += -g
+
+all: $(APP)
+
+$(APP): $(OBJS)
+ $(LD) $(LDFLAGS) $^ -o $@
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+%.o: $(MIPS_ELF_ROOT)/share/mips/boot/%.S
+ $(CC) $(CFLAGS) -c $^ -o $@
+
+.PHONY: clean
+clean:
+ rm -f $(APP) $(OBJS)
new file mode 100644
@@ -0,0 +1,16 @@
+Demonstration of a bootable example built for a specific cpu core, either the
+P5600 or I6400, relying on compile time CONFIG_XXX values for compile time
+specialization.
+
+Set environment variable MIPS_ELF_ROOT
+ This should be set to the root of the installation directory for the
+ toolchain (that is, below the bin directory)
+
+To build for the P5600
+ # make CORE=P5600
+
+To build for the I6400
+ # make CORE=I6400
+
+To delete temporary and built files
+ # make clean CORE=P5600
new file mode 100644
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015, Imagination Technologies Limited and/or its
+ * affiliated group companies.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stdio.h>
+
+int
+main ()
+{
+ printf ("Hello world!\n");
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,135 @@
+# Copyright 2015, Imagination Technologies Limited and/or its
+# affiliated group companies.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Usage:
+#
+# "include mipshal.mk" should be included in the top level makefile of the
+# project seeking to use this file. The variables CC and LD will be defined
+# by this file. The variables CFLAGS and LDFLAGS will be extended by this
+# file.
+#
+# Symbols that are to be overwridden should be defined in the the makefile
+# before "include mipshal.mk" or passed to make on the command line in the
+# form 'make STACK=0x1000' or 'make FLASH_START=0xBFC00000'.
+#
+# Care should be taken to ensure that no pre-existing environment variables
+# collide with the set of variables that this file inspects as unintended
+# results may happen.
+
+# Portable 'lowercase' func.
+lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
+
+# Default values for the linker script symbols listed below are
+# defined in the linker script.
+
+# These are linker script symbols that are prefixed with '__"
+priv_symbols = MEMORY_BASE MEMORY_SIZE STACK
+priv_symbols += BEV_OVERRIDE
+priv_symbols += ENABLE_XPA
+priv_symbols += FLUSH_TO_ZERO
+priv_symbols += FLASH_START APP_START FLASH_APP_START
+priv_symbols += ISR_VEC_SPACE ISR_VECTOR_COUNT
+
+comma := ,
+
+# A bit of makefile magic:
+# foreach symbol in overridable ld-symbols :
+# If symbol has a value, produce a linker argument for that symbol.
+MIPS_HAL_LDFLAGS = $(foreach a,$(priv_symbols),$(if $($a),-Wl$(comma)--defsym$(comma)__$(call lc,$(a))=$($a)))
+
+# Linker scripts for 32 & 64bit and ABI flags.
+LDSCRIPT32 ?= uhi32.ld
+LDSCRIPT64 ?= uhi64_64.ld
+LDSCRIPTN32 ?= uhi64_n32.ld
+
+ifdef ENDIAN
+ ifeq ($(ENDIAN), EL)
+ ENDIANF = -EL
+ else
+ ifeq ($(ENDIAN), EB)
+ ENDIANF = -EB
+ else
+ $(error Endian must be either EL, EB or undefined for default)
+ endif
+ endif
+endif
+
+# Pick the appropiate flags based on $(ABI)
+ifeq ($(ABI), 32)
+ MIPS_TOOLCHAIN ?= mips-mti-elf
+ LDSCRIPT ?= $(LDSCRIPT32)
+else
+ ifeq ($(ABI), 64)
+ MIPS_TOOLCHAIN ?= mips-img-elf
+ LDSCRIPT ?= $(LDSCRIPT64)
+ else
+ ifeq ($(ABI), n32)
+ MIPS_TOOLCHAIN ?= mips-img-elf
+ LDSCRIPT ?= $(LDSCRIPTN32)
+ else
+ $(error ABI must one of 32,64,n32)
+ endif
+ endif
+endif
+
+ifeq ($(ROMABLE),1)
+ MIPS_HAL_LDFLAGS += -T bootcode.ld
+endif
+
+ifdef ELF_ENTRY
+ MIPS_HAL_LDFLAGS += -Wl,--entry,$(ELF_ENTRY)
+endif
+
+ifndef MIPS_ELF_ROOT
+ $(error MIPS_ELF_ROOT must be set to point to toolkit installation root)
+endif
+
+ifeq ($(OS),Windows_NT)
+ CROSS_COMPILE=$(subst \,/,$(MIPS_ELF_ROOT))/bin/$(MIPS_TOOLCHAIN)-
+ SREC2HEX=$(subst \,/,$(MIPS_ELF_ROOT))/share/mips/rules/srec2hex.pl
+else
+ CROSS_COMPILE=$(MIPS_ELF_ROOT)/bin/$(MIPS_TOOLCHAIN)-
+ SREC2HEX=$(MIPS_ELF_ROOT)/share/mips/rules/srec2hex.pl
+endif
+
+CC = $(CROSS_COMPILE)gcc
+CFLAGS += -mabi=$(ABI) $(ENDIANF)
+LD = $(CC)
+LDFLAGS += $(MIPS_HAL_LDFLAGS) -mabi=$(ABI) $(ENDIANF) -T $(LDSCRIPT)
+
+OBJDUMP = $(CROSS_COMPILE)objdump
+OBJCOPY = $(CROSS_COMPILE)objcopy
+READELF = $(CROSS_COMPILE)readelf
+NM = $(CROSS_COMPILE)nm
+STRIP = $(CROSS_COMPILE)strip
+
+%.rec: %.elf
+ $(OBJCOPY) -O srec $^ $@
+
+%.hex: %.rec
+ $(SREC2HEX) -EL $^ > $@
new file mode 100755
@@ -0,0 +1,196 @@
+#!/bin/env perl
+
+# Copyright (C) 2018 MIPS Tech, LLC
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# File: srec2hex.pl
+#
+# Description:
+# This script converts an S-record file to a MIPS HEX file useful for
+# some simulation environments
+#
+# Usage:
+# srec2hex.pl -EL|-EB inputfile [outputfile]
+#
+
+use File::Basename;
+use Cwd;
+
+# Init global variables
+$Endian = "";
+$Debug = 0;
+$Verbose = 0;
+$IFile = "";
+$IFH = "STDIN";
+$OFile = "";
+$OFH = "STDOUT";
+
+# Parse command line for switches
+$Errors = 0;
+while (@ARGV && ($ARGV[0] =~ /^-./)) # Check for switches
+{
+ $ARGV[0] =~ /^-help$/ && ($Errors++, shift(@ARGV), next);
+ $ARGV[0] =~ /^-verbose$/ && ($Verbose = 1, shift(@ARGV), next);
+ $ARGV[0] =~ /^-EL$/ && ($Endian = $ARGV[0], shift(@ARGV), next);
+ $ARGV[0] =~ /^-EB$/ && ($Endian = $ARGV[0], shift(@ARGV), next);
+ print STDERR "\n$0: Unknown qualifier: $ARGV[0]\n";
+ $Errors++;
+ last;
+}
+
+$Errors++ if ($Endian eq "");
+if ($#ARGV > 1) {
+ $Errors++;
+} else {
+ $IFile = $ARGV[0] if ($#ARGV >= 0);
+ $OFile = $ARGV[1] if ($#ARGV == 1);
+ if ($IFile ne "") {
+ if (! -f $IFile) {
+ print STDERR "\n$0: ERROR: Input file $IFile does not exist\n";
+ $Errors++;
+ } else {
+ if (! open (IFILE, "< $IFile")) {
+ printf "\n$0: ERROR: Failed to open input file $IFile - $!\n";
+ $Errors++;
+ }
+ }
+ $IFH = "IFILE";
+ }
+ if ($OFile ne "") {
+ if (! open (OFILE, "> $OFile")) {
+ printf "\n$0: ERROR: Failed to open output file $OFile - $!\n";
+ close(IFILE);
+ $Errors++;
+ }
+ $OFH = "OFILE";
+ }
+}
+
+if ($Errors > 0) {
+ $usage =
+"Usage: $0 -E{B|L} [qualifiers] [input-file] [[output-file]]
+ -EB Convert big-endian S-Record file
+ -EL Convert little-endian S-Record file
+ -help Output this message and exit
+ -verbose Emit verbose messages
+";
+ printf STDERR $usage;
+ exit(1);
+}
+
+printf $OFH "\# Endian %s\n", ($Endian eq "-EB") ? "Big" : "Little";
+
+my $word = "";
+my $start;
+my $incr;
+
+if ($Endian eq "-EL") {
+ $start = 6;
+ $incr = -2;
+ $word = "00000000";
+} else {
+ $start = 0;
+ $incr = 2;
+}
+my $byteno = $start;
+my $tofill = 4;
+my $waddr = "";
+my $naddr = "";
+
+while (<$IFH>) {
+ my $line = $_;
+ my $dbindex;
+ my $addr;
+ my $datablock;
+ chomp $line;
+
+ last if $line =~ /^S[7-9]/ ;
+ next if $line =~ /^S0/ || $line =~ /^S[4-6]/ ;
+
+ my $reclen = hex(substr $line, 2, 2);
+
+ if ( $line =~ /^S1/ ) {
+ $addr = hex(substr $line, 4, 4);
+ $datablock = substr $line, 8;
+ $reclen -= 2;
+ } elsif ( $line =~ /^S2/ ) {
+ $addr = hex(substr $line, 4, 6);
+ $datablock = substr $line, 10;
+ $reclen -= 3;
+ } elsif ( $line =~ /^S3/ ) {
+ $addr = hex(substr $line, 4, 8);
+ $datablock = substr $line, 12;
+ $reclen -= 4;
+ } else {
+ printf STDERR "Bad s-record found: %s\n", $line;
+ exit(1);
+ }
+ $dbindex = 0;
+ # snip checksum byte
+ $reclen -= 1;
+
+ unless ($addr == $naddr) {
+ if ($tofill != 4) {
+ while ($tofill--) {
+ substr($word, $byteno, 2) = "00";
+ $byteno += $incr;
+ }
+ $word =~ tr/A-Z/a-z/;
+ printf $OFH "%x %s\n", $waddr / 4, $word;
+ $tofill = 4;
+ $byteno = $start;
+ $waddr = $waddr+4;
+ }
+ if (($addr & 0x3) != 0) {
+ $naddr = $addr & ~0x3;
+ $byteno = $start;
+ $tofill = 4;
+ while($naddr != $addr) {
+ substr($word, $byteno, 2) = "00";
+ $byteno += $incr;
+ $naddr += 1;
+ $tofill -=1;
+ }
+ }
+ }
+ $naddr = $addr;
+ $waddr = $naddr;
+ while($reclen > 0) {
+ substr ($word, $byteno, 2) = substr ($datablock, $dbindex, 2);
+ $byteno += $incr;
+ $dbindex += 2;
+ $tofill -=1;
+ if ($tofill == 0) {
+ $word =~ tr/A-Z/a-z/;
+ printf $OFH "%x %s\n", $waddr / 4, $word;
+ $byteno = $start;
+ $tofill = 4;
+ $waddr = $waddr+4;
+ }
+ $reclen = $reclen - 1;
+ $naddr = $naddr + 1;
+ }
+}