Skip to content

Commit

Permalink
Add specific r5900 machine code
Browse files Browse the repository at this point in the history
Add specific PS2 sys code:
- 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 option to override 32MiB on DESR/DVR models

rename ps2sdk_libc to libcglue

Add _POSIX_MONOTONIC_CLOCK to features

tmp
  • Loading branch information
Francisco Javier Trujillo Mata authored and fjtrujy committed Jun 7, 2023
1 parent 9e09d6e commit 5cdc19d
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 128 deletions.
3 changes: 3 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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"
;;
Expand Down
282 changes: 156 additions & 126 deletions newlib/Makefile.in

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions newlib/configure
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ HAVE_LIBC_MACHINE_RL78_FALSE
HAVE_LIBC_MACHINE_RL78_TRUE
HAVE_LIBC_MACHINE_RISCV_FALSE
HAVE_LIBC_MACHINE_RISCV_TRUE
HAVE_LIBC_MACHINE_R5900_FALSE
HAVE_LIBC_MACHINE_R5900_TRUE
HAVE_LIBC_MACHINE_PRU_FALSE
HAVE_LIBC_MACHINE_PRU_TRUE
HAVE_LIBC_MACHINE_POWERPC_FALSE
Expand Down Expand Up @@ -787,6 +789,8 @@ HAVE_LIBC_SYS_RTEMS_DIR_FALSE
HAVE_LIBC_SYS_RTEMS_DIR_TRUE
HAVE_LIBC_SYS_RDOS_DIR_FALSE
HAVE_LIBC_SYS_RDOS_DIR_TRUE
HAVE_LIBC_SYS_PS2_DIR_FALSE
HAVE_LIBC_SYS_PS2_DIR_TRUE
HAVE_LIBC_SYS_OR1K_DIR_FALSE
HAVE_LIBC_SYS_OR1K_DIR_TRUE
HAVE_LIBC_SYS_NETWARE_DIR_FALSE
Expand Down Expand Up @@ -5422,6 +5426,13 @@ fi
else
HAVE_LIBC_SYS_OR1K_DIR_TRUE='#'
HAVE_LIBC_SYS_OR1K_DIR_FALSE=
fi
if test "${sys_dir}" = ps2; then
HAVE_LIBC_SYS_PS2_DIR_TRUE=
HAVE_LIBC_SYS_PS2_DIR_FALSE='#'
else
HAVE_LIBC_SYS_PS2_DIR_TRUE='#'
HAVE_LIBC_SYS_PS2_DIR_FALSE=
fi
if test "${sys_dir}" = rdos; then
HAVE_LIBC_SYS_RDOS_DIR_TRUE=
Expand Down Expand Up @@ -6008,6 +6019,13 @@ fi
else
HAVE_LIBC_MACHINE_PRU_TRUE='#'
HAVE_LIBC_MACHINE_PRU_FALSE=
fi
if test "${machine_dir}" = r5900; then
HAVE_LIBC_MACHINE_R5900_TRUE=
HAVE_LIBC_MACHINE_R5900_FALSE='#'
else
HAVE_LIBC_MACHINE_R5900_TRUE='#'
HAVE_LIBC_MACHINE_R5900_FALSE=
fi
if test "${machine_dir}" = riscv; then
HAVE_LIBC_MACHINE_RISCV_TRUE=
Expand Down Expand Up @@ -7561,6 +7579,10 @@ if test -z "${HAVE_LIBC_SYS_OR1K_DIR_TRUE}" && test -z "${HAVE_LIBC_SYS_OR1K_DIR
as_fn_error $? "conditional \"HAVE_LIBC_SYS_OR1K_DIR\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_LIBC_SYS_PS2_DIR_TRUE}" && test -z "${HAVE_LIBC_SYS_PS2_DIR_FALSE}"; then
as_fn_error $? "conditional \"HAVE_LIBC_SYS_PS2_DIR\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_LIBC_SYS_RDOS_DIR_TRUE}" && test -z "${HAVE_LIBC_SYS_RDOS_DIR_FALSE}"; then
as_fn_error $? "conditional \"HAVE_LIBC_SYS_RDOS_DIR\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
Expand Down Expand Up @@ -7805,6 +7827,10 @@ if test -z "${HAVE_LIBC_MACHINE_PRU_TRUE}" && test -z "${HAVE_LIBC_MACHINE_PRU_F
as_fn_error $? "conditional \"HAVE_LIBC_MACHINE_PRU\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_LIBC_MACHINE_R5900_TRUE}" && test -z "${HAVE_LIBC_MACHINE_R5900_FALSE}"; then
as_fn_error $? "conditional \"HAVE_LIBC_MACHINE_R5900\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_LIBC_MACHINE_RISCV_TRUE}" && test -z "${HAVE_LIBC_MACHINE_RISCV_FALSE}"; then
as_fn_error $? "conditional \"HAVE_LIBC_MACHINE_RISCV\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
Expand Down
13 changes: 13 additions & 0 deletions newlib/configure.host
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
;;
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion newlib/libc/acinclude.m4
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ m4_foreach_w([SYS_DIR], [
m88kbug mmixware
netware
or1k
ps2
rdos rtems
sh sysmec sysnec810 sysnecv850 sysvi386 sysvnecv70
tic80 tirtos
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion newlib/libc/include/machine/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions newlib/libc/include/sys/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions newlib/libc/machine/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions newlib/libc/machine/r5900/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libc_a_SOURCES += %D%/setjmp.S
104 changes: 104 additions & 0 deletions newlib/libc/machine/r5900/setjmp.S
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions newlib/libc/sys/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions newlib/libc/sys/ps2/crt0.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* The real crt0.c lives in PS2SDK. */

void _start() { }
9 changes: 9 additions & 0 deletions newlib/libc/sys/ps2/machine/_types.h
Original file line number Diff line number Diff line change
@@ -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 */
23 changes: 23 additions & 0 deletions newlib/libc/sys/ps2/sys/dirent.h
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions newlib/newlib.hin
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@
/* nano version of malloc is used. */
#undef _NANO_MALLOC

/* "The newlib version in string format." */
#undef _NEWLIB_VERSION

/* Verify _REENT_CHECK macros allocate memory successfully. */
#undef _REENT_CHECK_VERIFY

Expand Down Expand Up @@ -422,4 +425,13 @@
/* Define if wide char orientation is supported. */
#undef _WIDE_ORIENT

/* "The newlib minor version number." */
#undef __NEWLIB_MINOR__

/* "The newlib patch level." */
#undef __NEWLIB_PATCHLEVEL__

/* "The newlib major version number." */
#undef __NEWLIB__

#endif /* !__NEWLIB_H__ */

0 comments on commit 5cdc19d

Please sign in to comment.