add psp-gcc 13.2.0 patch
[rofl0r-mmix-cross.git] / patches / newlib-4.4.0.20231231-psp.diff
blob7c62a779d63c0c7ef45ef10fa95f7859b2dac8be
1 From 91aa9adc67e6d4d9c67b3b6906a6bc21c5f3fdee Mon Sep 17 00:00:00 2001
2 From: Francisco Javier Trujillo Mata <fran.t.es@sync.money>
3 Date: Sat, 27 Feb 2021 12:31:03 +0100
4 Subject: [PATCH] Making a clean PSP port
6 - Add missing fields to dirent
7 - Add _POSIX_MONOTONIC_CLOCK to features
8 - Add statvfs file
9 ---
10 config.sub | 5 ++--
11 configure | 3 +++
12 newlib/configure.host | 13 ++++++++++
13 newlib/libc/acinclude.m4 | 1 +
14 newlib/libc/include/sys/features.h | 5 ++++
15 newlib/libc/sys/Makefile.inc | 3 +++
16 newlib/libc/sys/psp/Makefile.inc | 1 +
17 newlib/libc/sys/psp/crt0.c | 3 +++
18 newlib/libc/sys/psp/dummy.c | 4 +++
19 newlib/libc/sys/psp/sys/dirent.h | 41 ++++++++++++++++++++++++++++++
20 newlib/libc/sys/psp/sys/statvfs.h | 34 +++++++++++++++++++++++++
21 11 files changed, 111 insertions(+), 2 deletions(-)
22 create mode 100644 newlib/libc/sys/psp/Makefile.inc
23 create mode 100644 newlib/libc/sys/psp/crt0.c
24 create mode 100644 newlib/libc/sys/psp/dummy.c
25 create mode 100644 newlib/libc/sys/psp/sys/dirent.h
26 create mode 100644 newlib/libc/sys/psp/sys/statvfs.h
28 diff --git a/config.sub b/config.sub
29 index 63c1f1c8b..e77b3cbad 100755
30 --- a/config.sub
31 +++ b/config.sub
32 @@ -477,8 +477,8 @@ case $1 in
33 basic_os=linux
35 psp)
36 - basic_machine=mipsallegrexel-sony
37 - basic_os=psp
38 + basic_machine=mipsallegrexel-psp
39 + basic_os=elf
41 pw32)
42 basic_machine=i586-unknown
43 @@ -1202,6 +1202,7 @@ case $cpu-$vendor in
44 | mips64vr4300 | mips64vr4300el \
45 | mips64vr5000 | mips64vr5000el \
46 | mips64vr5900 | mips64vr5900el \
47 + | mipsallegrexel \
48 | mipsisa32 | mipsisa32el \
49 | mipsisa32r2 | mipsisa32r2el \
50 | mipsisa32r6 | mipsisa32r6el \
51 diff --git a/configure b/configure
52 index eb0ba840b..fea819e0c 100755
53 --- a/configure
54 +++ b/configure
55 @@ -3971,6 +3971,9 @@ case "${target}" in
56 | mips*-*-irix* | mips*-*-lnews* | mips*-*-riscos*)
57 noconfigdirs="$noconfigdirs ld gas gprof"
59 + mips*-psp-*)
60 + noconfigdirs="$noconfigdirs gprof target-libgloss"
61 + ;;
62 mips*-*-*)
63 noconfigdirs="$noconfigdirs gprof"
65 diff --git a/newlib/configure.host b/newlib/configure.host
66 index 386183466..80e78606b 100644
67 --- a/newlib/configure.host
68 +++ b/newlib/configure.host
69 @@ -245,6 +245,10 @@ case "${host_cpu}" in
70 mep)
71 machine_dir=mep
73 + mipsallegrex*)
74 + machine_dir=mips
75 + newlib_cflags="${newlib_cflags} -mno-gpopt -DMALLOC_ALIGNMENT=16"
76 + ;;
77 mips*)
78 machine_dir=mips
79 libm_machine_dir=mips
80 @@ -527,6 +531,11 @@ case "${host}" in
81 microblaze*-*-*)
82 machine_dir=microblaze
84 + mips*-psp-*)
85 + sys_dir=psp
86 + posix_dir=posix
87 + newlib_cflags="${newlib_cflags} -DHAVE_NANOSLEEP -DHAVE_RENAME -DHAVE_FCNTL -D_NO_POSIX_SPAWN"
88 + ;;
89 mmix-knuth-mmixware)
90 sys_dir=mmixware
92 @@ -769,6 +778,10 @@ newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DEXIT_PROVID
93 default_newlib_io_long_long="yes"
94 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
96 + mips*-psp-elf*)
97 + syscall_dir=syscalls
98 + default_newlib_io_long_long="yes"
99 + ;;
100 mips*-*-elf*)
101 default_newlib_io_long_long="yes"
102 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
103 diff --git a/newlib/libc/acinclude.m4 b/newlib/libc/acinclude.m4
104 index 24148b13f..48b86e7a8 100644
105 --- a/newlib/libc/acinclude.m4
106 +++ b/newlib/libc/acinclude.m4
107 @@ -19,6 +19,7 @@ m4_foreach_w([SYS_DIR], [
108 m88kbug mmixware
109 netware
110 or1k
111 + psp
112 rdos rtems
113 sh sysmec sysnec810 sysnecv850 sysvi386 sysvnecv70
114 tic80 tirtos
115 diff --git a/newlib/libc/include/sys/features.h b/newlib/libc/include/sys/features.h
116 index a7d4bc52d..1eb5dfc16 100644
117 --- a/newlib/libc/include/sys/features.h
118 +++ b/newlib/libc/include/sys/features.h
119 @@ -545,6 +545,11 @@ extern "C" {
121 #endif /* __CYGWIN__ */
123 +#ifdef _MIPS_ARCH_ALLEGREX
124 +# define _POSIX_TIMERS 1
125 +# define _POSIX_MONOTONIC_CLOCK 200112L
126 +#endif
128 #ifdef __cplusplus
130 #endif
131 diff --git a/newlib/libc/sys/Makefile.inc b/newlib/libc/sys/Makefile.inc
132 index 24d8407d5..c6b3d4d41 100644
133 --- a/newlib/libc/sys/Makefile.inc
134 +++ b/newlib/libc/sys/Makefile.inc
135 @@ -31,6 +31,9 @@ endif
136 if HAVE_LIBC_SYS_OR1K_DIR
137 include %D%/or1k/Makefile.inc
138 endif
139 +if HAVE_LIBC_SYS_PSP_DIR
140 +include %D%/psp/Makefile.inc
141 +endif
142 if HAVE_LIBC_SYS_RDOS_DIR
143 include %D%/rdos/Makefile.inc
144 endif
145 diff --git a/newlib/libc/sys/psp/Makefile.inc b/newlib/libc/sys/psp/Makefile.inc
146 new file mode 100644
147 index 000000000..641ac1e35
148 --- /dev/null
149 +++ b/newlib/libc/sys/psp/Makefile.inc
150 @@ -0,0 +1 @@
151 +libc_a_SOURCES += %D%/dummy.c
152 \ No newline at end of file
153 diff --git a/newlib/libc/sys/psp/crt0.c b/newlib/libc/sys/psp/crt0.c
154 new file mode 100644
155 index 000000000..af6712c20
156 --- /dev/null
157 +++ b/newlib/libc/sys/psp/crt0.c
158 @@ -0,0 +1,3 @@
159 +/* The real crt0.c lives in PSPSDK. */
161 +void _start() { }
162 diff --git a/newlib/libc/sys/psp/dummy.c b/newlib/libc/sys/psp/dummy.c
163 new file mode 100644
164 index 000000000..ac5ad04f9
165 --- /dev/null
166 +++ b/newlib/libc/sys/psp/dummy.c
167 @@ -0,0 +1,4 @@
168 +/* Dummy file to make sure we have at least one object file in the library.
169 + * Otherwise we were suffering an error compiling newlib.
170 + * Most probably it is a issue in the newlib itself.
172 \ No newline at end of file
173 diff --git a/newlib/libc/sys/psp/sys/dirent.h b/newlib/libc/sys/psp/sys/dirent.h
174 new file mode 100644
175 index 000000000..e7a6434f6
176 --- /dev/null
177 +++ b/newlib/libc/sys/psp/sys/dirent.h
178 @@ -0,0 +1,41 @@
179 +#ifndef _SYS_DIRENT_H
180 +#define _SYS_DIRENT_H
182 +typedef struct __dirdesc {
183 + int dd_fd; /* directory file */
184 + int dd_loc; /* position in buffer */
185 + int dd_seek;
186 + char *dd_buf; /* buffer */
187 + int dd_len; /* buffer length */
188 + int dd_size; /* amount of data in buffer */
189 +} DIR;
191 +# define __dirfd(dp) ((dp)->dd_fd)
193 +#include <sys/stat.h>
195 +#undef MAXNAMLEN /* from unistd.h */
196 +#define MAXNAMLEN 255
198 +#define d_ino d_fileno /* compatibility */
200 +struct dirent {
201 + ino_t d_fileno; /* file number of entry */
202 + off_t d_off; /* Not an offset; see below */
203 + unsigned short int d_reclen; /* Length of this record */
204 + unsigned char d_type; /* Type of file; not supported
205 + by all filesystem types */
206 + char d_name[MAXNAMLEN + 1];
209 +#define DT_UNKNOWN 0
210 +#define DT_FIFO 1
211 +#define DT_CHR 2
212 +#define DT_DIR 4
213 +#define DT_BLK 6
214 +#define DT_REG 8
215 +#define DT_LNK 10
216 +#define DT_SOCK 12
217 +#define DT_WHT 14
219 +#endif
220 \ No newline at end of file
221 diff --git a/newlib/libc/sys/psp/sys/statvfs.h b/newlib/libc/sys/psp/sys/statvfs.h
222 new file mode 100644
223 index 000000000..ed9b82f8d
224 --- /dev/null
225 +++ b/newlib/libc/sys/psp/sys/statvfs.h
226 @@ -0,0 +1,34 @@
227 +#ifndef _SYS_STATVFS_H_
228 +#define _SYS_STATVFS_H_
230 +#include <sys/types.h>
232 +#define ST_RDONLY 0x80000 /* equals FILE_READ_ONLY_VOLUME */
233 +#define ST_NOSUID 0 /* Looking for that bit should always fail. */
235 +struct statvfs {
236 + unsigned long f_bsize; /* file system block size */
237 + unsigned long f_frsize; /* fragment size */
238 + fsblkcnt_t f_blocks; /* size of fs in f_frsize units */
239 + fsblkcnt_t f_bfree; /* free blocks in fs */
240 + fsblkcnt_t f_bavail; /* free blocks avail to non-superuser */
241 + fsfilcnt_t f_files; /* total file nodes in file system */
242 + fsfilcnt_t f_ffree; /* free file nodes in fs */
243 + fsfilcnt_t f_favail; /* avail file nodes in fs */
244 + unsigned long f_fsid; /* file system id */
245 + unsigned long f_flag; /* mount flags */
246 + unsigned long f_namemax; /* maximum length of filenames */
249 +#ifdef __cplusplus
250 +extern "C" {
251 +#endif /* __cplusplus */
253 +int statvfs (const char *__path, struct statvfs *__buf);
254 +int fstatvfs (int __fd, struct statvfs *__buf);
256 +#ifdef __cplusplus
258 +#endif /* __cplusplus */
260 +#endif /*_SYS_STATVFS_H_*/
261 diff --git a/mipsallegrexel-psp-elf/newlib/libc/sys/psp/.deps/dummy.txt b/mipsallegrexel-psp-elf/newlib/libc/sys/psp/.deps/dummy.txt
262 new file mode 100644
263 index 000000000..ac5ad04f9
264 --- /dev/null
265 +++ b/mipsallegrexel-psp-elf/newlib/libc/sys/psp/.deps/dummy.txt
266 @@ -0,0 +1,4 @@
267 +/* Dummy file to make sure we have at least one object file in the library.
268 + * Otherwise we were suffering an error compiling newlib.
269 + * Most probably it is a issue in the newlib itself.
271 \ No newline at end of file