public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Francisco Javier Trujillo Mata <fjtrujy@gmail.com>
To: newlib@sourceware.org
Subject: PlayStation 2 newlib port
Date: Tue, 13 Jun 2023 20:31:09 +0200	[thread overview]
Message-ID: <CANdri-iKDRC-z7aj9YLrNjkwxaVHqAoAAM+chDzvy+aKLF-z-Q@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1087 bytes --]

Hi there!
I would like to mainstream the PS2 newlib port. So far the PS2 has had
newlib ports for years, however, it was never intended to be merged into
the mainstream.

I'm now trying to port to the latest release 4.3.0, however, I'm suffering
some errors during the compilation process.

I have attached the changes that I have done so far.
Then I just rerun the command `autoreconf` using the proper autoconf and
automake versions

I execute `configure` with:

PROC_NR=$(getconf _NPROCESSORS_ONLN)

TARGET="mips64r5900el-ps2-elf"
TARGET_ALIAS="ee"

## Create and enter the toolchain/build directory
rm -rf "build-$TARGET"
mkdir "build-$TARGET"
cd "build-$TARGET"

## Configure the build.
CFLAGS_FOR_TARGET="-O2" ../configure \
--prefix="$PS2DEV/$TARGET_ALIAS" \
--target="$TARGET" \
--enable-newlib-retargetable-locking \
$TARG_XTRA_OPTS

## Compile and install.
make -j "$PROC_NR" all


And then it always fails with this error,

fatal error: opening dependency file libc/sys/ps2/.deps/crt0.Tpo: No such
file or directory

Could you help me to identify where the issue is?

Cheers.

[-- Attachment #2: newlib-9305e82-Add specific r5900 machine and ps2 sys.patch --]
[-- Type: application/octet-stream, Size: 9185 bytes --]

From 9305e82aa11c15f6cc8ebceba13a297c735dfe03 Mon Sep 17 00:00:00 2001
From: Francisco Javier Trujillo Mata <fran.t.es@sync.money>
Date: Wed, 24 Feb 2021 11:48:14 +0100
Subject: [PATCH] Add specific r5900 machine and ps2 sys

- Do not use libgloss (we have ps2sdk)
- Use newlib reentrant syscalls
- Use posix functions
- Exclude OPENDIR functions
- Add -G0 in the newlib_cflags
- Fix time.h should have nanosleep defined
- Fix setjmp for R5900 CPU
- Add _POSIX_MONOTONIC_CLOCK to features
---
 configure                              |   3 +
 newlib/configure.host                  |  13 ++++
 newlib/libc/acinclude.m4               |   3 +-
 newlib/libc/include/machine/setjmp.h   |   9 ++-
 newlib/libc/include/sys/features.h     |   5 ++
 newlib/libc/machine/Makefile.inc       |   3 +
 newlib/libc/machine/r5900/Makefile.inc |   1 +
 newlib/libc/machine/r5900/setjmp.S     | 104 +++++++++++++++++++++++++
 newlib/libc/sys/Makefile.inc           |   3 +
 newlib/libc/sys/ps2/Makefile.inc       |   0
 newlib/libc/sys/ps2/crt0.c             |   3 +
 newlib/libc/sys/ps2/machine/_types.h   |   9 +++
 newlib/libc/sys/ps2/sys/dirent.h       |  23 ++++++
 13 files changed, 177 insertions(+), 2 deletions(-)
 create mode 100644 newlib/libc/machine/r5900/Makefile.inc
 create mode 100644 newlib/libc/machine/r5900/setjmp.S
 create mode 100644 newlib/libc/sys/ps2/Makefile.inc
 create mode 100644 newlib/libc/sys/ps2/crt0.c
 create mode 100644 newlib/libc/sys/ps2/machine/_types.h
 create mode 100644 newlib/libc/sys/ps2/sys/dirent.h

diff --git a/configure b/configure
index eb0ba840b..44ed93b67 100755
--- a/configure
+++ b/configure
@@ -3971,6 +3971,9 @@ case "${target}" in
   | mips*-*-irix* | mips*-*-lnews* | mips*-*-riscos*)
     noconfigdirs="$noconfigdirs ld gas gprof"
     ;;
+  mips*-ps2-*)
+    noconfigdirs="$noconfigdirs gprof target-libgloss"
+    ;;
   mips*-*-*)
     noconfigdirs="$noconfigdirs gprof"
     ;;
diff --git a/newlib/configure.host b/newlib/configure.host
index 0a1ba282a..2cd48ddeb 100644
--- a/newlib/configure.host
+++ b/newlib/configure.host
@@ -245,6 +245,10 @@ case "${host_cpu}" in
   mep)
 	machine_dir=mep
 	;;
+  mips64r5900*)
+  	machine_dir=r5900
+	newlib_cflags="${newlib_cflags} -DMALLOC_ALIGNMENT=16"
+	;;
   mips*)
 	machine_dir=mips
 	libm_machine_dir=mips
@@ -520,6 +524,11 @@ case "${host}" in
   microblaze*-*-*)
 	machine_dir=microblaze
 	;;
+  mips*-ps2-*)
+  	sys_dir=ps2
+  	posix_dir=posix
+  	newlib_cflags="${newlib_cflags} -G0 -DHAVE_NANOSLEEP -DHAVE_OPENDIR"
+	;;
   mmix-knuth-mmixware)
 	sys_dir=mmixware
 	;;
@@ -759,6 +768,10 @@ newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DEXIT_PROVID
 	default_newlib_io_long_long="yes"
 	newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
 	;;
+  mips*-ps2-elf*)
+	syscall_dir=syscalls
+	default_newlib_io_long_long="yes"
+	;;
   mips*-*-elf*)
 	default_newlib_io_long_long="yes"
 	newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
diff --git a/newlib/libc/acinclude.m4 b/newlib/libc/acinclude.m4
index 7cba7db39..073795a29 100644
--- a/newlib/libc/acinclude.m4
+++ b/newlib/libc/acinclude.m4
@@ -19,6 +19,7 @@ m4_foreach_w([SYS_DIR], [
   m88kbug mmixware
   netware
   or1k
+  ps2
   rdos rtems
   sh sysmec sysnec810 sysnecv850 sysvi386 sysvnecv70
   tic80 tirtos
@@ -53,7 +54,7 @@ m4_foreach_w([MACHINE], [
   nds32 necv70 nios2 nvptx
   or1k
   powerpc pru
-  riscv rl78 rx
+  r5900 riscv rl78 rx
   sh sparc spu
   tic4x tic6x tic80
   v850 visium
diff --git a/newlib/libc/include/machine/setjmp.h b/newlib/libc/include/machine/setjmp.h
index 29b76cec1..b6b619f03 100644
--- a/newlib/libc/include/machine/setjmp.h
+++ b/newlib/libc/include/machine/setjmp.h
@@ -129,10 +129,17 @@ _BEGIN_STD_C
 
 #ifdef __mips__
 # if defined(__mips64)
-#  define _JBTYPE long long
+#  if defined(_MIPS_ARCH_R5900)
+    typedef unsigned int jbtype128 __attribute__(( mode(TI) ));
+#   define _JBTYPE jbtype128
+#  else
+#   define _JBTYPE long long
+#  endif
 # endif
 # ifdef __mips_soft_float
 #  define _JBLEN 11
+# elif defined(_MIPS_ARCH_R5900)
+#  define _JBLEN 14
 # else
 #  define _JBLEN 23
 # endif
diff --git a/newlib/libc/include/sys/features.h b/newlib/libc/include/sys/features.h
index 45476ce4a..cfcaf9664 100644
--- a/newlib/libc/include/sys/features.h
+++ b/newlib/libc/include/sys/features.h
@@ -532,6 +532,11 @@ extern "C" {
 
 #endif /* __CYGWIN__ */
 
+#ifdef _MIPS_ARCH_R5900
+# define _POSIX_TIMERS				1
+# define _POSIX_MONOTONIC_CLOCK			200112L
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/newlib/libc/machine/Makefile.inc b/newlib/libc/machine/Makefile.inc
index 8aae2c52c..4113d0264 100644
--- a/newlib/libc/machine/Makefile.inc
+++ b/newlib/libc/machine/Makefile.inc
@@ -124,6 +124,9 @@ endif
 if HAVE_LIBC_MACHINE_PRU
 include %D%/pru/Makefile.inc
 endif
+if HAVE_LIBC_MACHINE_R5900
+include %D%/r5900/Makefile.inc
+endif
 if HAVE_LIBC_MACHINE_RISCV
 include %D%/riscv/Makefile.inc
 endif
diff --git a/newlib/libc/machine/r5900/Makefile.inc b/newlib/libc/machine/r5900/Makefile.inc
new file mode 100644
index 000000000..67137bce4
--- /dev/null
+++ b/newlib/libc/machine/r5900/Makefile.inc
@@ -0,0 +1 @@
+libc_a_SOURCES += %D%/setjmp.S
diff --git a/newlib/libc/machine/r5900/setjmp.S b/newlib/libc/machine/r5900/setjmp.S
new file mode 100644
index 000000000..cda45dcdd
--- /dev/null
+++ b/newlib/libc/machine/r5900/setjmp.S
@@ -0,0 +1,104 @@
+/* This is a simple version of setjmp and longjmp.
+ * Floating point support in. */
+
+#define O_S0	0x00
+#define O_S1	0x10
+#define O_S2	0x20
+#define O_S3	0x30
+#define O_S4	0x40
+#define O_S5	0x50
+#define O_S6	0x60
+#define O_S7	0x70
+#define O_FP	0x80
+#define O_SP	0x90
+#define O_RA	0xa0
+#define O_F20   0xb0
+#define O_F21   0xb4
+#define O_F22   0xb8
+#define O_F23   0xbc
+#define O_F24   0xc0
+#define O_F25   0xc4
+#define O_F26   0xc8
+#define O_F27   0xcc
+#define O_F28   0xd0
+#define O_F29   0xd4
+#define O_F30   0xd8
+#define O_F31   0xdc
+
+/* int setjmp (jmp_buf);  */
+	.globl	setjmp
+	.ent	setjmp
+setjmp:
+	.frame	$sp,0,$31
+
+	sq	$s0, O_S0($a0)
+	sq	$s1, O_S1($a0)
+	sq	$s2, O_S2($a0)
+	sq	$s3, O_S3($a0)
+	sq	$s4, O_S4($a0)
+	sq	$s5, O_S5($a0)
+	sq	$s6, O_S6($a0)
+	sq	$s7, O_S7($a0)
+	sq	$fp, O_FP($a0)
+	sq	$sp, O_SP($a0)
+	sq	$ra, O_RA($a0)
+
+	swc1    $f20, O_F20($a0)
+	swc1    $f21, O_F21($a0)
+	swc1    $f22, O_F22($a0)
+	swc1    $f23, O_F23($a0)
+	swc1    $f24, O_F24($a0)
+	swc1    $f25, O_F25($a0)
+	swc1    $f26, O_F26($a0)
+	swc1    $f27, O_F27($a0)
+	swc1    $f28, O_F28($a0)
+	swc1    $f29, O_F29($a0)
+	swc1    $f30, O_F30($a0)
+	swc1    $f31, O_F31($a0)
+
+
+	move	$v0, $0
+
+	jr	$ra
+
+	.end	setjmp
+
+/* volatile void longjmp (jmp_buf, int);  */
+	.globl	longjmp
+	.ent	longjmp
+longjmp:
+	.frame	$sp,0,$31
+
+	lq	$s0, O_S0($a0)
+	lq	$s1, O_S1($a0)
+	lq	$s2, O_S2($a0)
+	lq	$s3, O_S3($a0)
+	lq	$s4, O_S4($a0)
+	lq	$s5, O_S5($a0)
+	lq	$s6, O_S6($a0)
+	lq	$s7, O_S7($a0)
+	lq	$fp, O_FP($a0)
+	lq	$sp, O_SP($a0)
+	lq	$ra, O_RA($a0)
+
+	lwc1    $f20, O_F20($a0)
+	lwc1    $f21, O_F21($a0)
+	lwc1    $f22, O_F22($a0)
+	lwc1    $f23, O_F23($a0)
+	lwc1    $f24, O_F24($a0)
+	lwc1    $f25, O_F25($a0)
+	lwc1    $f26, O_F26($a0)
+	lwc1    $f27, O_F27($a0)
+	lwc1    $f28, O_F28($a0)
+	lwc1    $f29, O_F29($a0)
+	lwc1    $f30, O_F30($a0)
+	lwc1    $f31, O_F31($a0)
+
+	bne	$a0, $0, 1f
+	li	$a0, 1
+1:
+	move	$v0, $a0
+
+	jr	$ra
+
+	.end longjmp
diff --git a/newlib/libc/sys/Makefile.inc b/newlib/libc/sys/Makefile.inc
index 9f8758934..017dfc044 100644
--- a/newlib/libc/sys/Makefile.inc
+++ b/newlib/libc/sys/Makefile.inc
@@ -31,6 +31,9 @@ endif
 if HAVE_LIBC_SYS_OR1K_DIR
 include %D%/or1k/Makefile.inc
 endif
+if HAVE_LIBC_SYS_PS2_DIR
+include %D%/ps2/Makefile.inc
+endif
 if HAVE_LIBC_SYS_RDOS_DIR
 include %D%/rdos/Makefile.inc
 endif
diff --git a/newlib/libc/sys/ps2/Makefile.inc b/newlib/libc/sys/ps2/Makefile.inc
new file mode 100644
index 000000000..e69de29bb
diff --git a/newlib/libc/sys/ps2/crt0.c b/newlib/libc/sys/ps2/crt0.c
new file mode 100644
index 000000000..d5d534808
--- /dev/null
+++ b/newlib/libc/sys/ps2/crt0.c
@@ -0,0 +1,3 @@
+/* The real crt0.c lives in PS2SDK. */
+
+void _start() { }
\ No newline at end of file
diff --git a/newlib/libc/sys/ps2/machine/_types.h b/newlib/libc/sys/ps2/machine/_types.h
new file mode 100644
index 000000000..b9905d4ea
--- /dev/null
+++ b/newlib/libc/sys/ps2/machine/_types.h
@@ -0,0 +1,9 @@
+#ifndef _MACHINE__TYPES_H
+#define	_MACHINE__TYPES_H
+
+#include <machine/_default_types.h>
+
+typedef	__int64_t	_off_t;
+#define	__machine_off_t_defined
+
+#endif /* _MACHINE__TYPES_H */
diff --git a/newlib/libc/sys/ps2/sys/dirent.h b/newlib/libc/sys/ps2/sys/dirent.h
new file mode 100644
index 000000000..7b504ee11
--- /dev/null
+++ b/newlib/libc/sys/ps2/sys/dirent.h
@@ -0,0 +1,23 @@
+#ifndef _SYS_DIRENT_H
+#define _SYS_DIRENT_H
+
+typedef struct __dirdesc {
+	int	dd_fd;
+	char	*dd_buf;
+} DIR;
+
+# define __dirfd(dp)	((dp)->dd_fd)
+
+#include <sys/stat.h>
+
+#undef  MAXNAMLEN	/* from unistd.h */
+#define MAXNAMLEN	255
+
+#define d_ino	d_fileno	/* compatibility */
+
+struct dirent {
+	struct stat d_stat;
+	char d_name[MAXNAMLEN + 1];
+};
+
+#endif
\ No newline at end of file
-- 
2.37.5


             reply	other threads:[~2023-06-13 18:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-13 18:31 Francisco Javier Trujillo Mata [this message]
2023-06-19 20:41 ` Jeff Johnston
2023-06-20  7:05   ` Francisco Javier Trujillo Mata
2023-09-19 16:38     ` Francisco Javier Trujillo Mata
2023-09-19 20:42       ` Jeff Johnston

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANdri-iKDRC-z7aj9YLrNjkwxaVHqAoAAM+chDzvy+aKLF-z-Q@mail.gmail.com \
    --to=fjtrujy@gmail.com \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).