@@ -94,6 +94,16 @@ endef
$(call GENISROBJ,256)
+UHIOBJS = uhi_assert.o uhi_close.o uhi_exit.o uhi_fstat.o \
+ uhi_lseek.o uhi_open.o uhi_plog.o \
+ uhi_pread.o uhi_pwrite.o uhi_read.o uhi_link.o uhi_stat.o \
+ uhi_unlink.o uhi_write.o uhi_getargs.o uhi_exception.o \
+ uhi_get_ram_range.o uhi_indirect.o uhi_break.o \
+ syscalls.o getpid.o isatty.o kill.o
+
+YAMONOBJS = yamon_read.o yamon_write.o yamon_exit.o yamon_close.o \
+ yamon_fstat.o yamon_exception.o
+
HALOBJ = mips64_tlb.o mips_clean_cache.o mips_flush_cache.o mips_l2size.o \
mips_lock_cache.o mips_size_cache.o mips_sync_cache.o mips_tlb.o \
mips_fp.o mips_msa.o \
@@ -158,6 +158,9 @@ __exception_handle_quiet (struct gpctx *ctx, int exception)
__uhi_indirect (ctx);
return;
case EXC_BP:
+ /* Return from exception handler if breakpoint is handled. */
+ if (__uhi_break && __uhi_break (ctx))
+ return;
PUTSNS ("Breakpoint @0x", ctx->epc, "\n");
break;
case EXC_RI:
@@ -436,6 +436,10 @@ extern int _MIPS_HAL_NOMIPS16
extern void _MIPS_HAL_NOMIPS16
__uhi_assert (const char *, const char *, int32_t);
+/* Forward a breakpoint exception to boot. */
+extern int _MIPS_HAL_NOMIPS16
+ __uhi_break (struct gpctx *) __attribute__((weak));
+
#ifdef NDEBUG /* required by ANSI standard */
# define uhi_assert(__e) ((void)0)
#else
new file mode 100644
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2014-2017, 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.
+*/
+
+
+#ifndef _UHI_SYSCALLS_
+#define _UHI_SYSCALLS_
+
+#define __MIPS_UHI_EXIT 1
+#define __MIPS_UHI_OPEN 2
+#define __MIPS_UHI_CLOSE 3
+#define __MIPS_UHI_READ 4
+#define __MIPS_UHI_WRITE 5
+#define __MIPS_UHI_LSEEK 6
+#define __MIPS_UHI_UNLINK 7
+#define __MIPS_UHI_FSTAT 8
+#define __MIPS_UHI_ARGC 9
+#define __MIPS_UHI_ARGLEN 10
+#define __MIPS_UHI_ARGN 11
+#define __MIPS_UHI_RAMRANGE 12
+#define __MIPS_UHI_LOG 13
+#define __MIPS_UHI_ASSERT 14
+#define __MIPS_UHI_EXCEPTION 15
+#define __MIPS_UHI_PREAD 19
+#define __MIPS_UHI_PWRITE 20
+#define __MIPS_UHI_LINK 22
+#define __MIPS_UHI_BOOTFAIL 23
+#define __MIPS_UHI_BREAK 24
+
+#define __MIPS_UHI_BF_CACHE 1
+
+#define __xstr(s) __str(s)
+#define __str(s) #s
+#define __MIPS_UHI_SYSCALL_NUM 1
+
+#ifdef __MIPS_SDBBP__
+ #define SYSCALL(NUM) "\tsdbbp " __xstr (NUM)
+ #define ASM_SYSCALL(NUM) sdbbp NUM
+#else
+ #define SYSCALL(NUM) "\tsyscall " __xstr (NUM)
+ #define ASM_SYSCALL(NUM) syscall NUM
+#endif
+
+#endif // _UHI_SYSCALLS_
@@ -25,8 +25,6 @@ EXTERN(__exception_entry)
* informative
*/
EXTERN(__exception_handle_verbose)
-/* Force the interrupt handlers to be included in the link */
-EXTERN(__isr_vec)
/* Force ISRs 0-7 to be included in the link */
EXTERN(_isr_vec_7)
/* Require the UHI getargs support */
new file mode 100644
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis void __assert_func (const char *filename, int32_t line_num,
+ * const char *func, const char *expr);
+ *
+ * Parameters:
+ * filename - Name of the file
+ * line_num - Line number
+ * func - Name of the function
+ * expr - Expression
+ *
+ * Return:
+ * None
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for __assert_func
+ * $4 - Name of the file
+ * $5 - Line number
+ * $6 - Name of the function
+ * $7 - Expression
+ *
+ * Return from syscall:
+ * None
+ *
+ * @Description Assert
+*/
+
+#include <stdint.h>
+#include <mips/hal.h>
+#include <mips/uhi_syscalls.h>
+
+void _MIPS_HAL_NOMIPS16
+__uhi_assert (const char *message, const char *filename, int32_t line_num)
+{
+ register const char *arg1 asm ("$4") = message;
+ register const char *arg2 asm ("$5") = filename;
+ register int32_t arg3 asm ("$6") = line_num;
+ register int32_t op asm ("$25") = __MIPS_UHI_ASSERT;
+ register int32_t ret1 asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t ret2 asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # __assert_func(%0, %1, %2, %3, %4, %5) op=%6\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret1), "+r" (ret2), "+r" (arg1), "+r" (arg2)
+ : "r" (arg3), "r" (op));
+}
new file mode 100644
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2017, 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.
+*/
+
+/*
+ * @Synopsis int __uhi_break (struct gp_ctx *ctx);
+ *
+ * Parameters:
+ * $4 - GP context
+ *
+ * Arguments to break:
+ * $25 - Operation code for __uhi_break
+ * $4 - GP context
+ *
+ * Return from break:
+ * $2 - Return 1 if breakpoint exception is handled else 0
+ *
+ * @Description Handle a breakpoint exception
+*/
+
+#include <stdint.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+/* Forward a breakpoint exception to boot. */
+int _MIPS_HAL_NOMIPS16
+__uhi_break (struct gpctx *ctx)
+{
+ register struct gpctx *arg1 asm ("$4") = ctx;
+ register int32_t op asm ("$25") = __MIPS_UHI_BREAK;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+
+ __asm__ __volatile__ (" # %0 = __uhi_break(%1) op=%2\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret)
+ : "r" (arg1), "r" (op));
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis close
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for close
+ * $4 - File handle
+ *
+ * Return from syscall:
+ * $2 - 0 on success else -1
+ * $3 - errno
+ *
+ * @Description File close
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int _MIPS_HAL_NOMIPS16
+close (int fd)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register int32_t op asm ("$25") = __MIPS_UHI_CLOSE;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = close(%2) op=%3\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1)
+ : "r" (op)
+ : "$5");
+
+ if (ret != 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int __uhi_exception (struct gp_ctx *ctx);
+ *
+ * Parameters:
+ * $4 - GP context
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for __uhi_exception
+ * $4 - GP context
+ *
+ * Return from syscall:
+ * $2 -
+ *
+ * @Description Handle an unhandled exception
+*/
+
+#include <stdint.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int32_t _MIPS_HAL_NOMIPS16
+__uhi_exception (struct gpctx *ctx, int32_t abi)
+{
+ register struct gpctx *arg1 asm ("$4") = ctx;
+ register int32_t arg2 asm ("$5") = abi;
+ register int32_t op asm ("$25") = __MIPS_UHI_EXCEPTION;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+
+ __asm__ __volatile__ (" # %0 = __uhi_exception(%1, %2) op=%3\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret)
+ : "r" (arg1), "r" (arg2), "r" (op)
+ : "$3");
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis void __exit (int32_t exit_code);
+ *
+ * Parameters:
+ * exit_code - Exit code
+ *
+ * Return:
+ * None
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for exit
+ * $4 - Exit code
+ *
+ * @Description Transfer control to the debug port
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+void __return_to_boot (int32_t exit_code) __attribute__((noreturn))
+ __attribute__((weak));
+
+/* Defined in .ld file */
+extern char __use_excpt_boot[];
+
+/* _exit has been declared weak to allow its defination in the application */
+int _MIPS_HAL_NOMIPS16
+__exit (int exit_code)
+{
+ register int32_t arg1 asm ("$4") = exit_code;
+ register int32_t op asm ("$25") = __MIPS_UHI_EXIT;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+
+ __asm__ __volatile__ (" # _exit(%0 %1) op=%2\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "+r" (arg1)
+ : "r" (op)
+ : "$3", "$5");
+
+ /* exit wasn't handled, return to caller of _start
+ * __use_excpt_boot has following values
+ * 0 = Do not use exception handler present in boot
+ * 1 = Use exception handler present in boot if BEV
+ is 0 at startup
+ * 2 = Always use exception handler present in boot
+ */
+ if (((long) __use_excpt_boot == 2
+ || ((long) __use_excpt_boot == 1
+ && __get_startup_BEV
+ && __get_startup_BEV () == 0))
+ && __return_to_boot)
+ __return_to_boot (exit_code);
+
+ /* Infinite loop if control returns. */
+ __exit (exit_code);
+ return exit_code;
+}
new file mode 100644
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int32_t fstat (int32_t file, struct stat *sbuf);
+ *
+ * Parameters:
+ * file - File handle
+ * sbuf - Pointer to dst buffer
+ *
+ * Return:
+ * 0 on success else -1
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for fstat
+ * $4 - File handle
+ * $5 - Pointer to dst buffer (struct stat *)
+ *
+ * Return from syscall:
+ * $2 - 0 on success else -1
+ * $3 - errno
+ *
+ * @Description File statistics
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stddef.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+#include "uhi_stat.h"
+
+/* This macro declares a dummy type with -ve size if CONDITION is false */
+#define __paste(STR1, STR2) STR1##STR2
+#define __check(LINE, CONDITION) typedef char __paste(assertion_failed_at_line_, LINE) [(int)(CONDITION)-1]
+
+int _MIPS_HAL_NOMIPS16
+fstat (int file, struct stat *sbuf)
+{
+ struct uhi_stat hbuf = {0,};
+ register int32_t arg1 asm ("$4") = file;
+ register struct uhi_stat *arg2 asm ("$5") = &hbuf;
+ register int32_t op asm ("$25") = __MIPS_UHI_FSTAT;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ /*
+ * We assume that NewLib has following 'struct stat'. Any change in
+ * this structure (either offset or size) would generate a compile
+ * time error.
+ */
+#if defined (_LP64)
+ __check (__LINE__, sizeof (struct stat) == 104);
+ __check (__LINE__, offsetof (struct stat, st_dev) == 0);
+ __check (__LINE__, offsetof (struct stat, st_ino) == 2);
+ __check (__LINE__, offsetof (struct stat, st_mode) == 4);
+ __check (__LINE__, offsetof (struct stat, st_nlink) == 8);
+ __check (__LINE__, offsetof (struct stat, st_uid) == 10);
+ __check (__LINE__, offsetof (struct stat, st_gid) == 12);
+ __check (__LINE__, offsetof (struct stat, st_rdev) == 14);
+ __check (__LINE__, offsetof (struct stat, st_size) == 16);
+ __check (__LINE__, offsetof (struct stat, st_atime) == 24);
+ __check (__LINE__, offsetof (struct stat, st_spare1) == 32);
+ __check (__LINE__, offsetof (struct stat, st_mtime) == 40);
+ __check (__LINE__, offsetof (struct stat, st_spare2) == 48);
+ __check (__LINE__, offsetof (struct stat, st_ctime) == 56);
+ __check (__LINE__, offsetof (struct stat, st_spare3) == 64);
+ __check (__LINE__, offsetof (struct stat, st_blksize) == 72);
+ __check (__LINE__, offsetof (struct stat, st_blocks) == 80);
+ __check (__LINE__, offsetof (struct stat, st_spare4) == 88);
+#else
+ __check (__LINE__, sizeof (struct stat) == 60);
+ __check (__LINE__, offsetof (struct stat, st_dev) == 0);
+ __check (__LINE__, offsetof (struct stat, st_ino) == 2);
+ __check (__LINE__, offsetof (struct stat, st_mode) == 4);
+ __check (__LINE__, offsetof (struct stat, st_nlink) == 8);
+ __check (__LINE__, offsetof (struct stat, st_uid) == 10);
+ __check (__LINE__, offsetof (struct stat, st_gid) == 12);
+ __check (__LINE__, offsetof (struct stat, st_rdev) == 14);
+ __check (__LINE__, offsetof (struct stat, st_size) == 16);
+ __check (__LINE__, offsetof (struct stat, st_atime) == 20);
+ __check (__LINE__, offsetof (struct stat, st_spare1) == 24);
+ __check (__LINE__, offsetof (struct stat, st_mtime) == 28);
+ __check (__LINE__, offsetof (struct stat, st_spare2) == 32);
+ __check (__LINE__, offsetof (struct stat, st_ctime) == 36);
+ __check (__LINE__, offsetof (struct stat, st_spare3) == 40);
+ __check (__LINE__, offsetof (struct stat, st_blksize) == 44);
+ __check (__LINE__, offsetof (struct stat, st_blocks) == 48);
+ __check (__LINE__, offsetof (struct stat, st_spare4) == 52);
+#endif
+
+ __asm__ __volatile__ (" # %0,%1 = fstat(%2, %3) op=%4\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1),
+ "+r" (arg2)
+ : "r" (op));
+
+ if (ret != 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+ else
+ {
+ sbuf->st_dev = hbuf.st_dev;
+ sbuf->st_ino = hbuf.st_ino;
+ sbuf->st_mode = hbuf.st_mode;
+ sbuf->st_nlink = hbuf.st_nlink;
+ sbuf->st_uid = hbuf.st_uid;
+ sbuf->st_gid = hbuf.st_gid;
+ sbuf->st_rdev = hbuf.st_rdev;
+ sbuf->st_size = (long) hbuf.st_size;
+ sbuf->st_atime = (time_t) hbuf.st_atime;
+ sbuf->st_spare1 = (long) hbuf.st_spare1;
+ sbuf->st_mtime = (time_t) hbuf.st_mtime;
+ sbuf->st_spare2 = (long) hbuf.st_spare2;
+ sbuf->st_ctime = (time_t) hbuf.st_ctime;
+ sbuf->st_spare3 = (long) hbuf.st_spare3;
+ sbuf->st_blksize = (long) hbuf.st_blksize;
+ sbuf->st_blocks = (long) hbuf.st_blocks;
+ sbuf->st_spare4[0] = (long) hbuf.st_spare4[0];
+ sbuf->st_spare4[1] = (long) hbuf.st_spare4[1];
+ }
+
+ return ret;
+}
+
+#undef __paste
+#undef __check
new file mode 100644
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2014-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 <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+extern char __attribute__((weak)) __memory_size[];
+extern char __attribute__((weak)) __memory_base[];
+
+void _MIPS_HAL_NOMIPS16
+_get_ram_range (void **ram_base, void **ram_extent)
+{
+ register int32_t op asm ("$25") = __MIPS_UHI_RAMRANGE;
+ register void* r_base asm ("$2") = (void*)__MIPS_UHI_SYSCALL_NUM;
+ register void* r_extent asm ("$3") = NULL;
+
+ if (__memory_size != NULL)
+ {
+ if (ram_base)
+ *ram_base = (void*)(unsigned long)__memory_base;
+ *ram_extent = (void*)((unsigned long)__memory_base
+ + (unsigned long)__memory_size);
+ return;
+ }
+
+ __asm__ __volatile__ (" # %0,%1 = ramrange() op=%2\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (r_base), "=r" (r_extent)
+ : "r" (op)
+ : "$4", "$5");
+
+ if (ram_base)
+ *ram_base = r_base;
+ *ram_extent = r_extent;
+}
new file mode 100644
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2014-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 <mips/asm.h>
+#include <mips/regdef.h>
+#include <mips/cpu.h>
+#include <mips/uhi_syscalls.h>
+
+MIPS_NOMIPS16
+
+ .text
+ .align 2
+ .globl __getargs
+ .ent __getargs
+ .type __getargs, @function
+__getargs:
+
+ move t0, zero /* argc */
+ move t1, zero /* argv */
+
+ li t9, __MIPS_UHI_ARGC
+ li vt0, __MIPS_UHI_SYSCALL_NUM
+
+ ASM_SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+
+ /* return on error (-1) */
+ blez vt0, .Lreturn
+
+ move t0, vt0 /* argc: number of arguments */
+ sll t3, t0, LOG2_SZPTR /* Multiply by size of pointer */
+ addiu t3, t3, ALSZ /* Round to stack alignment */
+ and t3, t3, ALMASK
+ PTR_SUBU sp, sp, t3 /* make room for argv */
+ move t1, sp /* argv */
+ move t2, zero
+
+.Lloop:
+
+ li t9, __MIPS_UHI_ARGLEN
+ li vt0, __MIPS_UHI_SYSCALL_NUM
+ move a0, t2 /* argument number */
+
+ ASM_SYSCALL (__MIPS_UHI_SYSCALL_NUM) /* get length of arg N */
+
+ blez vt0, .Lreturn /* return on error */
+
+ addiu vt0, vt0, 1
+ addiu vt0, vt0, ALSZ
+ and vt0, vt0, ALMASK
+ PTR_SUBU sp, sp, vt0
+ sll t3, t2, LOG2_SZPTR
+ PTR_ADDU t3, t3, t1
+ PTR_S sp, 0(t3) /* argv[i] */
+
+ li t9, __MIPS_UHI_ARGN
+ li vt0, __MIPS_UHI_SYSCALL_NUM
+ move a0, t2 /* argument number */
+ move a1, sp /* argument buffer */
+
+ ASM_SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+
+ bltz vt0, .Lreturn /* return on error */
+
+ addiu t2, t2, 1
+ slt vt0, t2, t0
+ bnez vt0, .Lloop
+
+.Lreturn:
+ move a0, t0
+ move a1, t1
+
+ /* Leave 16-bytes for register arguments and up to 8 bytes for
+ a null envp. Round up to 32 for alignment. */
+ PTR_SUBU sp, sp, 16+(NARGSAVE*SZARG)
+ PTR_ADDU a2, sp, (NARGSAVE*SZARG)
+ PTR_S zero, 0(a2)
+
+ jr $31
+
+ .end __getargs
+ .size __getargs, .-__getargs
new file mode 100644
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2014-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 <mips/hal.h>
+
+/* Forward a UHI SYSCALL operation to SDBPP interface. */
+int _MIPS_HAL_NOMIPS16
+__uhi_indirect (struct gpctx *ctx)
+{
+ register reg_t arg1 asm ("$4") = ctx->r[C_CTX_REGNO(4)];
+ register reg_t arg2 asm ("$5") = ctx->r[C_CTX_REGNO(5)];
+ register reg_t arg3 asm ("$6") = ctx->r[C_CTX_REGNO(6)];
+ register reg_t arg4 asm ("$7") = ctx->r[C_CTX_REGNO(7)];
+ register reg_t op asm ("$25") = ctx->r[C_CTX_REGNO(25)];
+ register reg_t ret1 asm ("$2") = 1;
+ register reg_t ret2 asm ("$3");
+
+ __asm__ __volatile__(" # UHI indirect\n"
+ "\tsdbbp 1"
+ : "+r" (ret1), "=r" (ret2), "+r" (arg1), "+r" (arg2)
+ : "r" (arg3), "r" (arg4), "r" (op));
+
+ ctx->r[C_CTX_REGNO(2)] = ret1;
+ ctx->r[C_CTX_REGNO(3)] = ret2;
+ ctx->r[C_CTX_REGNO(4)] = arg1;
+ ctx->r[C_CTX_REGNO(5)] = arg2;
+ /* Handled, move on. SYSCALL is 4-bytes in all ISAs. */
+ ctx->epc += 4;
+
+ return 1; /* exception handled */
+}
new file mode 100644
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int32_t link (const char *oldname, const char *newname);
+ *
+ * Parameters:
+ * oldname - Name of the file to rename
+ * newname - New file name
+ *
+ * Return:
+ * $2 - Zero on success or -1 in case of error
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for rename
+ * $4 - Name of the file to rename
+ * $5 - New file name
+ *
+ * Return from syscall:
+ * $2 - Zero on success or -1 in case of error
+ * $3 - errno
+ *
+ * @Description Rename a file
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int _MIPS_HAL_NOMIPS16
+link (const char *oldname, const char *newname)
+{
+ register const char *arg1 asm ("$4") = oldname;
+ register const char *arg2 asm ("$5") = newname;
+ register int32_t op asm ("$25") = __MIPS_UHI_LINK;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = link(%2, %3) op=%4\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1),
+ "+r" (arg2)
+ : "r" (op));
+
+ if (ret != 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis lseek
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for seek
+ * $4 - File handle
+ * $5 - Offset
+ * $6 - Direction
+ *
+ * Return from syscall:
+ * $2 - New offset
+ * $3 - errno
+ *
+ * @Description File seek
+*/
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+off_t _MIPS_HAL_NOMIPS16
+lseek (int fd, off_t offset, int whence)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register int32_t arg2 asm ("$5") = offset;
+ register int32_t arg3 asm ("$6") = whence;
+ register int32_t op asm ("$25") = __MIPS_UHI_LSEEK;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = lseek(%2, %3, %4) op=%5\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1),
+ "+r" (arg2)
+ : "r" (arg3), "r" (op));
+
+ if (ret == -1)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis open
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for open
+ * $4 - Name of the file
+ * $5 - Read/Write etc. flags
+ * $6 - Privileges
+ *
+ * Return from syscall:
+ * $2 - File handle
+ * $3 - errno
+ *
+ * @Description File open
+*/
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int _MIPS_HAL_NOMIPS16
+open (const char *file_name, int flags, mode_t mode)
+{
+ register const char * arg1 asm ("$4") = file_name;
+ register int32_t arg2 asm ("$5") = flags;
+ register int32_t arg3 asm ("$6") = mode;
+ register int32_t op asm ("$25") = __MIPS_UHI_OPEN;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = open(%2, %3, %4) op=%5\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1), "+r" (arg2)
+ : "r" (arg3), "r" (op));
+
+ if (ret == -1)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int32_t plog (int8_t *fmt, int32_t num);
+ *
+ * Parameters:
+ * fmt - Format string
+ * num - The only int argument
+ *
+ * Return:
+ * Number of chars written
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for __plog
+ * $4 - Format string
+ * $5 - The only int argument
+ *
+ * Return from syscall:
+ * $2 - Number of chars written
+ * $3 - errno
+ *
+ * @Description Print information
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <mips/hal.h>
+#include <mips/uhi_syscalls.h>
+
+int32_t _MIPS_HAL_NOMIPS16
+__plog (int8_t *fmt, int32_t num)
+{
+ register int8_t *arg1 asm ("$4") = fmt;
+ register int32_t arg2 asm ("$5") = num;
+ register int32_t op asm ("$25") = __MIPS_UHI_LOG;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = __plog(%2, %3) op=%4\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1), "+r" (arg2)
+ : "r" (op));
+
+ if (ret != 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis pread
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for pread
+ * $4 - File handle
+ * $5 - Destination buffer
+ * $6 - Max number of bytes to read
+ * $7 - Offset in file from which bytes to be read
+ *
+ * Return from syscall:
+ * $2 - Number of bytes read or -1 in case of error
+ * $3 - errno
+ *
+ * @Description File read from a given offset
+*/
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+ssize_t _MIPS_HAL_NOMIPS16
+pread (int fd, void *buf, size_t count, off_t offset)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register void *arg2 asm ("$5") = buf;
+ register int32_t arg3 asm ("$6") = count;
+ register int32_t arg4 asm ("$7") = offset;
+ register int32_t op asm ("$25") = __MIPS_UHI_PREAD;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = pread(%2, %3, %4, %5) op=%6\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1),
+ "+r" (arg2)
+ : "r" (arg3), "r" (arg4), "r" (op));
+
+ if (ret == -1)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis pwrite
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for pwrite
+ * $4 - File handle
+ * $5 - Buffer to write
+ * $6 - Length of the buffer
+ * $7 - Offset in file at which bytes to be written
+ *
+ * Return from syscall:
+ * $2 - Number of bytes written
+ * $3 - errno
+ *
+ * @Description Write to a file at a given offset
+*/
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+ssize_t _MIPS_HAL_NOMIPS16
+pwrite (int fd, const void *buf, size_t count, off_t offset)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register const void *arg2 asm ("$5") = buf;
+ register int32_t arg3 asm ("$6") = count;
+ register int32_t arg4 asm ("$7") = offset;
+ register int32_t op asm ("$25") = __MIPS_UHI_PWRITE;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = pwrite(%2, %3, %4 %5) op=%6\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1),
+ "+r" (arg2)
+ : "r" (arg3), "r" (arg4), "r" (op));
+
+ if (ret == -1)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis read
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for read
+ * $4 - File handle
+ * $5 - Destination buffer
+ * $6 - Max number of bytes to read
+ *
+ * Return from syscall:
+ * $2 - Number of bytes read
+ * $3 - errno
+ *
+ * @Description File read
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int _MIPS_HAL_NOMIPS16
+read (int fd, void *buffer, size_t len)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register void *arg2 asm ("$5") = buffer;
+ register int32_t arg3 asm ("$6") = len;
+ register int32_t op asm ("$25") = __MIPS_UHI_READ;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = read(%2, %3, %4) op=%5\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1),
+ "+r" (arg2)
+ : "r" (arg3), "r" (op));
+
+ if (ret == -1)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis stat
+ *
+ * @Description File statistics
+*/
+
+#include <stdint.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+#include "uhi_stat.h"
+
+int
+stat (const char *filename, struct stat *buf)
+{
+ int32_t fid, ret = -1;
+
+ fid = open (filename, 0, 0666); /* open in read mode */
+
+ if (fid >= 0)
+ {
+ ret = fstat (fid, buf);
+ close (fid);
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2014-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 <time.h>
+
+struct uhi_stat
+{
+ short st_dev;
+ unsigned short st_ino;
+ unsigned int st_mode;
+ unsigned short st_nlink;
+ unsigned short st_uid;
+ unsigned short st_gid;
+ short st_rdev;
+ unsigned long long st_size;
+ unsigned long long st_atime;
+ unsigned long long st_spare1;
+ unsigned long long st_mtime;
+ unsigned long long st_spare2;
+ unsigned long long st_ctime;
+ unsigned long long st_spare3;
+ unsigned long long st_blksize;
+ unsigned long long st_blocks;
+ unsigned long long st_spare4[2];
+};
new file mode 100644
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int32_t unlink (const char *file);
+ *
+ * Parameters:
+ * file - Name of the file
+ *
+ * Return:
+ * 0 on success else -1
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for unlink
+ * $4 - Name of the file
+ *
+ * Return from syscall:
+ * $2 - 0 on success else -1
+ * $3 - errno
+ *
+ * @Description Unlink a file
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int _MIPS_HAL_NOMIPS16
+unlink (const char *file)
+{
+ register const char *arg1 asm ("$4") = file;
+ register int32_t op asm ("$25") = __MIPS_UHI_UNLINK;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = unlink(%2) op=%3\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1)
+ : "r" (op)
+ : "$5");
+
+ if (ret != 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis write
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for write
+ * $4 - File handle
+ * $5 - Buffer to write
+ * $6 - Length of the buffer
+ *
+ * Return from syscall:
+ * $2 - Number of bytes written
+ * $3 - errno
+ *
+ * @Description File write
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int _MIPS_HAL_NOMIPS16
+write (int fd, const void *buf, size_t count)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register const void *arg2 asm ("$5") = buf;
+ register int32_t arg3 asm ("$6") = count;
+ register int32_t op asm ("$25") = __MIPS_UHI_WRITE;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ __asm__ __volatile__ (" # %0,%1 = write(%2, %3, %4) op=%5\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1),
+ "+r" (arg2)
+ : "r" (arg3), "r" (op));
+
+ if (ret == -1)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
new file mode 100644
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int32_t close (int32_t fd);
+ *
+ * Parameters:
+ * $4 - File handle
+ *
+ * Return:
+ * $2 - 0 on success else -1
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for close
+ * $4 - File handle
+ *
+ * Return from syscall:
+ * $2 - 0 on success else -1
+ * $3 - errno
+ *
+ * @Description File close
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int32_t _MIPS_HAL_NOMIPS16
+close (int32_t fd)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register int32_t op asm ("$25") = __MIPS_UHI_CLOSE;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ if (fd == 0 || fd == 1 || fd == 2)
+ return 0;
+
+ __asm__ __volatile__(" # %0,%1 = close(%2) op=%3\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1)
+ : "r" (op)
+ : "$5");
+
+ if (ret != 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
+
new file mode 100644
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int __uhi_exception (struct gp_ctx *ctx);
+ *
+ * Parameters:
+ * $4 - GP context
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for __uhi_exception
+ * $4 - GP context
+ *
+ * Return from syscall:
+ * $2 -
+ *
+ * @Description Handle an unhandled exception
+*/
+
+#include <stdint.h>
+#include <mips/hal.h>
+
+int32_t _MIPS_HAL_NOMIPS16
+__uhi_exception (struct gpctx *ctx, int32_t abi)
+{
+ return -1;
+}
new file mode 100644
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis void __exit (int32_t exit_code);
+ *
+ * Parameters:
+ * $4 - Exit code
+ *
+ * Return:
+ * None
+ *
+ * @Description Transfer control to the debug port
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include "yamon_syscalls.h"
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+__attribute__ ((weak)) int _MIPS_HAL_NOMIPS16
+__exit (int exit_code)
+{
+ typedef void (*funcptr) (int32_t);
+ extern funcptr __yamon_functions[];
+ funcptr yamonexit;
+
+ yamonexit = (funcptr)__yamon_functions[__YAMON_EXIT];
+ (yamonexit) (exit_code);
+
+ __exit (exit_code); /* just to avoide the warning */
+ return exit_code;
+}
+
new file mode 100644
@@ -0,0 +1,185 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int32_t fstat (int32_t file, struct stat *sbuf);
+ *
+ * Parameters:
+ * $4 - File handle
+ * $5 - Pointer to dst buffer (struct stat *)
+ *
+ * Return:
+ * $2 - 0 on success else -1
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for fstat
+ * $4 - File handle
+ * $5 - Pointer to dst buffer (struct stat *)
+ *
+ * Return from syscall:
+ * $2 - 0 on success else -1
+ * $3 - errno
+ *
+ * @Description File statistics
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stddef.h>
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+#include "uhi_stat.h"
+
+/* This macro declares a dummy type with -ve size if CONDITION is false */
+#define __paste(STR1, STR2) STR1##STR2
+#define __check(LINE, CONDITION) typedef char __paste(assertion_failed_at_line_, LINE) [(int)(CONDITION)-1]
+
+int _MIPS_HAL_NOMIPS16
+fstat (int file, struct stat *sbuf)
+{
+ struct uhi_stat hbuf = {0,};
+ register int32_t arg1 asm ("$4") = file;
+ register struct uhi_stat *arg2 asm ("$5") = &hbuf;
+ register int32_t op asm ("$25") = __MIPS_UHI_FSTAT;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ /*
+ * We assume that NewLib has following 'struct stat'. Any change in
+ * this structure (either offset or size) would generate a compile
+ * time error.
+ */
+#if defined (_LP64)
+ __check (__LINE__, sizeof (struct stat) == 104);
+ __check (__LINE__, offsetof (struct stat, st_dev) == 0);
+ __check (__LINE__, offsetof (struct stat, st_ino) == 2);
+ __check (__LINE__, offsetof (struct stat, st_mode) == 4);
+ __check (__LINE__, offsetof (struct stat, st_nlink) == 8);
+ __check (__LINE__, offsetof (struct stat, st_uid) == 10);
+ __check (__LINE__, offsetof (struct stat, st_gid) == 12);
+ __check (__LINE__, offsetof (struct stat, st_rdev) == 14);
+ __check (__LINE__, offsetof (struct stat, st_size) == 16);
+ __check (__LINE__, offsetof (struct stat, st_atime) == 24);
+ __check (__LINE__, offsetof (struct stat, st_spare1) == 32);
+ __check (__LINE__, offsetof (struct stat, st_mtime) == 40);
+ __check (__LINE__, offsetof (struct stat, st_spare2) == 48);
+ __check (__LINE__, offsetof (struct stat, st_ctime) == 56);
+ __check (__LINE__, offsetof (struct stat, st_spare3) == 64);
+ __check (__LINE__, offsetof (struct stat, st_blksize) == 72);
+ __check (__LINE__, offsetof (struct stat, st_blocks) == 80);
+ __check (__LINE__, offsetof (struct stat, st_spare4) == 88);
+#else
+ __check (__LINE__, sizeof (struct stat) == 60);
+ __check (__LINE__, offsetof (struct stat, st_dev) == 0);
+ __check (__LINE__, offsetof (struct stat, st_ino) == 2);
+ __check (__LINE__, offsetof (struct stat, st_mode) == 4);
+ __check (__LINE__, offsetof (struct stat, st_nlink) == 8);
+ __check (__LINE__, offsetof (struct stat, st_uid) == 10);
+ __check (__LINE__, offsetof (struct stat, st_gid) == 12);
+ __check (__LINE__, offsetof (struct stat, st_rdev) == 14);
+ __check (__LINE__, offsetof (struct stat, st_size) == 16);
+ __check (__LINE__, offsetof (struct stat, st_atime) == 20);
+ __check (__LINE__, offsetof (struct stat, st_spare1) == 24);
+ __check (__LINE__, offsetof (struct stat, st_mtime) == 28);
+ __check (__LINE__, offsetof (struct stat, st_spare2) == 32);
+ __check (__LINE__, offsetof (struct stat, st_ctime) == 36);
+ __check (__LINE__, offsetof (struct stat, st_spare3) == 40);
+ __check (__LINE__, offsetof (struct stat, st_blksize) == 44);
+ __check (__LINE__, offsetof (struct stat, st_blocks) == 48);
+ __check (__LINE__, offsetof (struct stat, st_spare4) == 52);
+#endif
+
+ if (file == 0 || file == 1 || file == 2)
+ {
+ sbuf->st_mode = S_IRUSR | S_IWUSR | S_IWGRP;
+ sbuf->st_blksize = BUFSIZ;
+ sbuf->st_dev = 0;
+ sbuf->st_ino = 0;
+ sbuf->st_nlink = 0;
+ sbuf->st_uid = 0;
+ sbuf->st_gid = 0;
+ sbuf->st_rdev = 0;
+ sbuf->st_size = 0;
+ sbuf->st_atime = (time_t) 0;
+ sbuf->st_spare1 = 0;
+ sbuf->st_mtime = (time_t) 0;
+ sbuf->st_spare2 = 0;
+ sbuf->st_ctime = (time_t) 0;
+ sbuf->st_spare3 = 0;
+ sbuf->st_blocks = 0;
+ sbuf->st_spare4[0] = 0;
+ sbuf->st_spare4[1] = 0;
+ return 0;
+ }
+
+ __asm__ __volatile__(" # %0,%1 = fstat(%2, %3) op=%4\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1), "+r" (arg2)
+ : "r" (op));
+
+ if (ret != 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+ else
+ {
+ sbuf->st_dev = hbuf.st_dev;
+ sbuf->st_ino = hbuf.st_ino;
+ sbuf->st_mode = hbuf.st_mode;
+ sbuf->st_nlink = hbuf.st_nlink;
+ sbuf->st_uid = hbuf.st_uid;
+ sbuf->st_gid = hbuf.st_gid;
+ sbuf->st_rdev = hbuf.st_rdev;
+ sbuf->st_size = (long) hbuf.st_size;
+ sbuf->st_atime = (time_t) hbuf.st_atime;
+ sbuf->st_spare1 = (long) hbuf.st_spare1;
+ sbuf->st_mtime = (time_t) hbuf.st_mtime;
+ sbuf->st_spare2 = (long) hbuf.st_spare2;
+ sbuf->st_ctime = (time_t) hbuf.st_ctime;
+ sbuf->st_spare3 = (long) hbuf.st_spare3;
+ sbuf->st_blksize = (long) hbuf.st_blksize;
+ sbuf->st_blocks = (long) hbuf.st_blocks;
+ sbuf->st_spare4[0] = (long) hbuf.st_spare4[0];
+ sbuf->st_spare4[1] = (long) hbuf.st_spare4[1];
+ }
+
+ return ret;
+}
+
+#undef __paste
+#undef __check
+
new file mode 100644
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int32_t read (int32_t fd, void *buffer, int32_t len);
+ *
+ * Parameters:
+ * $4 - File handle
+ * $5 - Destination buffer
+ * $6 - Max number of bytes to read
+ *
+ * Return:
+ * $2 - Number of bytes read
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for read
+ * $4 - File handle
+ * $5 - Destination buffer
+ * $6 - Max number of bytes to read
+ *
+ * Return from syscall:
+ * $2 - Number of bytes read
+ * $3 - errno
+ *
+ * @Description File read
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include "yamon_syscalls.h"
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+
+int32_t _MIPS_HAL_NOMIPS16
+read (int32_t fd, void *buffer, int32_t len)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register void *arg2 asm ("$5") = buffer;
+ register int32_t arg3 asm ("$6") = len;
+ register int32_t op asm ("$25") = __MIPS_UHI_READ;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ /* yamon getchar always reads from stdin */
+ if (fd == 0)
+ {
+ typedef int32_t (*funcptr) (int32_t, char *);
+ extern funcptr __yamon_functions[];
+ funcptr yamonread;
+ int32_t i;
+ yamonread = (funcptr)__yamon_functions[__YAMON_GETCHAR];
+
+ for (i=0; i<=len; i++)
+ ret += (yamonread) (fd, (char*)buffer+i);
+ }
+ else
+ {
+ /* Use UHI read when reading from source other than stdin */
+ __asm__ __volatile__(" # %0,%1 = read (%2, %3, %4) op=%5\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1), "+r" (arg2)
+ : "r" (arg3), "r" (op));
+ }
+
+ if (ret < 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
+
new file mode 100644
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/* These defines are used as array indices in c code */
+#define __YAMON_PRINT_COUNT 0x01 /* At location 0x04 in vector table */
+#define __YAMON_GETCHAR 0x14 /* At location 0x50 in vector table */
+#define __YAMON_EXIT 0x08 /* At location 0x20 in vector table */
+
new file mode 100644
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2014-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.
+*/
+
+/*
+ * @Synopsis int32_t write (int32_t fd, void *buffer, int32_t count);
+ *
+ * Parameters:
+ * $4 - File handle
+ * $5 - Buffer to write
+ * $6 - Length of the buffer
+ *
+ * Return:
+ * $2 - Number of bytes written
+ *
+ * Arguments to syscall:
+ * $25 - Operation code for write
+ * $4 - File handle
+ * $5 - Buffer to write
+ * $6 - Length of the buffer
+ *
+ * Return from syscall:
+ * $2 - Number of bytes written
+ * $3 - errno
+ *
+ * @Description File write
+*/
+
+#include <stdint.h>
+#include <errno.h>
+#include "yamon_syscalls.h"
+#include <mips/uhi_syscalls.h>
+#include <mips/hal.h>
+
+int32_t _MIPS_HAL_NOMIPS16
+write (int32_t fd, void *buffer, int32_t count)
+{
+ register int32_t arg1 asm ("$4") = fd;
+ register void *arg2 asm ("$5") = buffer;
+ register int32_t arg3 asm ("$6") = count;
+ register int32_t op asm ("$25") = __MIPS_UHI_WRITE;
+ register int32_t ret asm ("$2") = __MIPS_UHI_SYSCALL_NUM;
+ register int32_t new_errno asm ("$3") = 0;
+
+ /* yamon print_count always writes to stdout */
+ if (fd == 1 || fd == 2)
+ {
+ typedef int32_t (*funcptr) (int32_t, char *, int32_t);
+ extern funcptr __yamon_functions[];
+ funcptr yamonwrite;
+
+ yamonwrite = (funcptr)__yamon_functions[__YAMON_PRINT_COUNT];
+
+ ret = (yamonwrite) (0, buffer, count);
+ }
+ else
+ {
+ /* Use UHI write when writing to destination other than stdout */
+ __asm__ __volatile__(" # %0,%1 = write(%2, %3, %4) op=%5\n"
+ SYSCALL (__MIPS_UHI_SYSCALL_NUM)
+ : "+r" (ret), "=r" (new_errno), "+r" (arg1), "+r" (arg2)
+ : "r" (arg3), "r" (op));
+ }
+ if (ret < 0)
+ {
+ /* Do a dance to set errno, errno is a function call that can
+ clobber $3. */
+ volatile uint32_t errno_tmp = new_errno;
+ errno = errno_tmp;
+ }
+
+ return ret;
+}
+