From b0ed90ff26fdf7a70e1b484da751102ae28e90c3 Mon Sep 17 00:00:00 2001 From: dbalatoni13 Date: Sun, 12 Jan 2025 09:47:25 +0100 Subject: [PATCH] Import MSL headers and files --- configure.py | 8 +- .../Msl/MSL_C/MSL_Common/FILE_POS.h | 2 +- .../Msl/MSL_C/MSL_Common/alloc.h | 2 +- .../Msl/MSL_C/MSL_Common/ansi_files.h | 2 +- .../Msl/MSL_C/MSL_Common/ansi_fp.h | 2 +- .../Msl/MSL_C/MSL_Common/buffer_io.h | 2 +- .../Msl/MSL_C/MSL_Common/char_io.h | 2 +- .../Msl/MSL_C/MSL_Common/direct_io.h | 2 +- .../Msl/MSL_C/MSL_Common/file_io.h | 2 +- .../Msl/MSL_C/MSL_Common/math.h | 2 +- .../Msl/MSL_C/MSL_Common/mbstring.h | 2 +- .../Msl/MSL_C/MSL_Common/mem_funcs.h | 2 +- .../Msl/MSL_C/MSL_Common/printf.h | 4 +- .../Msl/MSL_C/MSL_Common/scanf.h | 4 +- .../Msl/MSL_C/MSL_Common/stdio.h | 8 +- .../Msl/MSL_C/MSL_Common/stdlib.h | 8 +- .../Msl/MSL_C/MSL_Common/string.h | 2 +- .../Msl/MSL_C/MSL_Common/wchar_io.h | 2 +- src/MSL_C.PPCEABI.bare.H/abort_exit.c | 55 + src/MSL_C.PPCEABI.bare.H/ansi_files.c | 95 ++ src/MSL_C.PPCEABI.bare.H/buffer_io.c | 41 + src/MSL_C.PPCEABI.bare.H/ctype.c | 85 ++ src/MSL_C.PPCEABI.bare.H/direct_io.c | 114 ++ src/MSL_C.PPCEABI.bare.H/e_asin.c | 3 + src/MSL_C.PPCEABI.bare.H/e_atan2.c | 145 +++ src/MSL_C.PPCEABI.bare.H/errno.c | 3 + src/MSL_C.PPCEABI.bare.H/float.c | 5 + src/MSL_C.PPCEABI.bare.H/mbstring.c | 18 + src/MSL_C.PPCEABI.bare.H/mem.c | 75 ++ src/MSL_C.PPCEABI.bare.H/mem_funcs.c | 221 ++++ src/MSL_C.PPCEABI.bare.H/misc_io.c | 1 + src/MSL_C.PPCEABI.bare.H/printf.c | 1076 +++++++++++++++++ src/MSL_C.PPCEABI.bare.H/rand.c | 13 + src/MSL_C.PPCEABI.bare.H/s_atan.c | 148 +++ src/MSL_C.PPCEABI.bare.H/s_frexp.c | 58 + src/MSL_C.PPCEABI.bare.H/scanf.c | 34 + src/MSL_C.PPCEABI.bare.H/string.c | 257 ++++ src/MSL_C.PPCEABI.bare.H/strtoul.c | 199 +++ src/MSL_C.PPCEABI.bare.H/w_atan2.c | 39 + src/MSL_C.PPCEABI.bare.H/wchar_io.c | 22 + 40 files changed, 2736 insertions(+), 29 deletions(-) create mode 100644 src/MSL_C.PPCEABI.bare.H/abort_exit.c create mode 100644 src/MSL_C.PPCEABI.bare.H/ansi_files.c create mode 100644 src/MSL_C.PPCEABI.bare.H/buffer_io.c create mode 100644 src/MSL_C.PPCEABI.bare.H/ctype.c create mode 100644 src/MSL_C.PPCEABI.bare.H/direct_io.c create mode 100644 src/MSL_C.PPCEABI.bare.H/e_asin.c create mode 100644 src/MSL_C.PPCEABI.bare.H/e_atan2.c create mode 100644 src/MSL_C.PPCEABI.bare.H/errno.c create mode 100644 src/MSL_C.PPCEABI.bare.H/float.c create mode 100644 src/MSL_C.PPCEABI.bare.H/mbstring.c create mode 100644 src/MSL_C.PPCEABI.bare.H/mem.c create mode 100644 src/MSL_C.PPCEABI.bare.H/mem_funcs.c create mode 100644 src/MSL_C.PPCEABI.bare.H/misc_io.c create mode 100644 src/MSL_C.PPCEABI.bare.H/printf.c create mode 100644 src/MSL_C.PPCEABI.bare.H/rand.c create mode 100644 src/MSL_C.PPCEABI.bare.H/s_atan.c create mode 100644 src/MSL_C.PPCEABI.bare.H/s_frexp.c create mode 100644 src/MSL_C.PPCEABI.bare.H/scanf.c create mode 100644 src/MSL_C.PPCEABI.bare.H/string.c create mode 100644 src/MSL_C.PPCEABI.bare.H/strtoul.c create mode 100644 src/MSL_C.PPCEABI.bare.H/w_atan2.c create mode 100644 src/MSL_C.PPCEABI.bare.H/wchar_io.c diff --git a/configure.py b/configure.py index 520c9808..22c85a12 100644 --- a/configure.py +++ b/configure.py @@ -682,7 +682,7 @@ config.libs = [ "objects": [ Object(NonMatching, "MSL_C.PPCEABI.bare.H/abort_exit.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/alloc.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/errno.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "MSL_C.PPCEABI.bare.H/errno.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/ansi_files.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/ansi_fp.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/arith.c"), @@ -696,7 +696,7 @@ config.libs = [ Object(NonMatching, "MSL_C.PPCEABI.bare.H/mem_funcs.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/misc_io.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/printf.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/float.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "MSL_C.PPCEABI.bare.H/float.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/signal.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/string.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/uart_console_io.c"), @@ -715,14 +715,14 @@ config.libs = [ Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_copysign.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_cos.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_floor.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_frexp.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "MSL_C.PPCEABI.bare.H/s_frexp.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_ldexp.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_modf.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_sin.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/s_tan.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_acos.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_asin.c"), - Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_atan2.c"), + Object(MatchingFor("GMPE01_00", "GMPE01_01"), "MSL_C.PPCEABI.bare.H/w_atan2.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_fmod.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/w_pow.c"), Object(NonMatching, "MSL_C.PPCEABI.bare.H/math_ppc.c"), diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/FILE_POS.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/FILE_POS.h index 386fc29f..046471d5 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/FILE_POS.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/FILE_POS.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_FILE_POS_H #define _MSL_COMMON_FILE_POS_H -#include "ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/alloc.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/alloc.h index 085c40d4..6b08d6f9 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/alloc.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/alloc.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_ALLOC_H #define _MSL_COMMON_ALLOC_H -#include "ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h index f06c55df..924c0b2d 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_ANSI_FILES_H #define _MSL_COMMON_ANSI_FILES_H -#include "stddef.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stddef.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h index 22066367..90ba7acf 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_ANSI_FP_H #define _MSL_COMMON_ANSI_FP_H -#include "float.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h" #define SIGDIGLEN 36 diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h index 07fcf209..85ad160a 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_BUFFER_IO_H #define _MSL_COMMON_BUFFER_IO_H -#include "ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" enum { __align_buffer, __dont_align_buffer }; diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h index a21f2e1b..e3733cf7 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_CHAR_IO_H #define _MSL_COMMON_CHAR_IO_H -#include "ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h index c16943b4..7e838551 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_DIRECT_IO_H #define _MSL_COMMON_DIRECT_IO_H -#include "ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h index a6cc390b..a06e7cef 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_FILE_IO_H #define _MSL_COMMON_FILE_IO_H -#include "ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/math.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/math.h index fb2c1f3f..e99949cc 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/math.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/math.h @@ -1,7 +1,7 @@ #ifndef MSL_MATH_H_ #define MSL_MATH_H_ -#include "float.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h" #define NAN (*(float*)__float_nan) #define HUGE_VALF (*(float*)__float_huge) diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h index 945748b1..2aa9f4ea 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_MBSTRING_H #define _MSL_COMMON_MBSTRING_H -#include "wchar_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h index 0e245466..7d6853c3 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_MEM_FUNCS_H #define _MSL_COMMON_MEM_FUNCS_H -#include "stddef.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stddef.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h index 521baa49..0184466f 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h @@ -1,8 +1,8 @@ #ifndef _MSL_COMMON_PRINTF_H #define _MSL_COMMON_PRINTF_H -#include "ansi_files.h" -#include "stdarg.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdarg.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h index ca142dc1..f1bb9399 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h @@ -1,8 +1,8 @@ #ifndef _MSL_COMMON_SCANF_H #define _MSL_COMMON_SCANF_H -#include "stddef.h" -#include "ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stddef.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h index 4ccc44cf..89806588 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h @@ -1,10 +1,10 @@ #ifndef MSL_STDIO_H_ #define MSL_STDIO_H_ -#include "char_io.h" // IWYU pragma: export -#include "file_io.h" // IWYU pragma: export -#include "printf.h" // IWYU pragma: export -#include "extras.h" // IWYU pragma: export +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/char_io.h" // IWYU pragma: export +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h" // IWYU pragma: export +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h" // IWYU pragma: export +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/extras.h" // IWYU pragma: export #define stdin (&__files._stdin) #define stdout (&__files._stdout) diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h index 2ce2e5c8..9df0be5b 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h @@ -1,9 +1,9 @@ #ifndef MSL_STDLIB_H_ #define MSL_STDLIB_H_ -#include "abort_exit.h" -#include "arith.h" -#include "mbstring.h" -#include "strtoul.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/abort_exit.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/arith.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/strtoul.h" #endif diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/string.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/string.h index ab4bfff3..2bfbd8fa 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/string.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/string.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_STRING_H #define _MSL_COMMON_STRING_H -#include "stddef.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stddef.h" #ifdef __cplusplus extern "C" { diff --git a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h index 711bb395..90153f95 100644 --- a/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h +++ b/include/PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h @@ -1,7 +1,7 @@ #ifndef _MSL_COMMON_WCHAR_IO_H #define _MSL_COMMON_WCHAR_IO_H -#include "ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" #ifndef __cplusplus typedef unsigned short wchar_t; diff --git a/src/MSL_C.PPCEABI.bare.H/abort_exit.c b/src/MSL_C.PPCEABI.bare.H/abort_exit.c new file mode 100644 index 00000000..1c9ca4d2 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/abort_exit.c @@ -0,0 +1,55 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/abort_exit.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/critical_regions.h" +#include "stddef.h" +#include "PowerPC_EABI_Support/Runtime/NMWException.h" + +void _ExitProcess(); + +extern void (*_dtors[])(void); + +int __aborting = 0; + +static void (*atexit_funcs[64])(void); +static int atexit_curr_func = 0; + +static void (*__atexit_funcs[64])(void); +static int __atexit_curr_func = 0; + +void (*__stdio_exit)(void) = 0; +void (*__console_exit)(void) = 0; + +void abort(void) +{ + // TODO +} + +void exit(int status) +{ + int i; + void (**dtor)(void); + + if (!__aborting) { + __destroy_global_chain(); + + dtor = _dtors; + while (*dtor != NULL) { + (*dtor)(); + dtor++; + } + + if (__stdio_exit != NULL) { + __stdio_exit(); + __stdio_exit = NULL; + } + } + + while (__atexit_curr_func > 0) + __atexit_funcs[--__atexit_curr_func](); + + if (__console_exit != NULL) { + __console_exit(); + __console_exit = NULL; + } + + _ExitProcess(); +} diff --git a/src/MSL_C.PPCEABI.bare.H/ansi_files.c b/src/MSL_C.PPCEABI.bare.H/ansi_files.c new file mode 100644 index 00000000..f0113bf4 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/ansi_files.c @@ -0,0 +1,95 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/file_io.h" + +extern files __files = { + { + 0, + 0, + 1, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + { 0, 0 }, + { 0, 0 }, + 0, + (unsigned char*)&__files._stdin.char_buffer, + 1, + (unsigned char*)&__files._stdin.char_buffer, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, + { + 0, + 0, + 2, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + { 0, 0 }, + { 0, 0 }, + 0, + (unsigned char*)&__files._stdout.char_buffer, + 1, + (unsigned char*)&__files._stdout.char_buffer, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, + { + 0, + 0, + 2, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + { 0, 0 }, + { 0, 0 }, + 0, + (unsigned char*)&__files._stderr.char_buffer, + 1, + (unsigned char*)&__files._stderr.char_buffer, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, +}; diff --git a/src/MSL_C.PPCEABI.bare.H/buffer_io.c b/src/MSL_C.PPCEABI.bare.H/buffer_io.c new file mode 100644 index 00000000..5657680d --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/buffer_io.c @@ -0,0 +1,41 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_files.h" + +void __prep_buffer(FILE* file) +{ + file->buffer_ptr = file->buffer; + file->buffer_length = file->buffer_size; + file->buffer_length -= file->position & file->buffer_alignment; + file->buffer_position = file->position; +} + +void __convert_from_newlines(unsigned char* p, size_t* n) { } + +int __flush_buffer(FILE* file, size_t* bytes_flushed) +{ + size_t buffer_len; + int ioresult; + + buffer_len = file->buffer_ptr - file->buffer; + + if (buffer_len) { + file->buffer_length = buffer_len; + + if (!file->file_mode.binary_io) + __convert_from_newlines(file->buffer, &file->buffer_length); + + ioresult = (*file->write_fn)(file->handle, file->buffer, + &file->buffer_length, file->idle_fn); + + if (bytes_flushed) + *bytes_flushed = file->buffer_length; + + if (ioresult) + return ioresult; + + file->position += file->buffer_length; + } + + __prep_buffer(file); + + return __no_io_error; +} diff --git a/src/MSL_C.PPCEABI.bare.H/ctype.c b/src/MSL_C.PPCEABI.bare.H/ctype.c new file mode 100644 index 00000000..e0a797cb --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/ctype.c @@ -0,0 +1,85 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h" + +#define ctrl __control_char +#define motn __motion_char +#define spac __space_char +#define punc __punctuation +#define digi __digit +#define hexd __hex_digit +#define lowc __lower_case +#define uppc __upper_case +#define dhex (hexd | digi) +#define uhex (hexd | uppc) +#define lhex (hexd | lowc) + +const unsigned char __ctype_map[256] = { + // clang-format off + ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, motn, motn, motn, motn, motn, ctrl, ctrl, + ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, ctrl, + spac, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, punc, + dhex, dhex, dhex, dhex, dhex, dhex, dhex, dhex, dhex, dhex, punc, punc, punc, punc, punc, punc, + punc, uhex, uhex, uhex, uhex, uhex, uhex, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, + uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, uppc, punc, punc, punc, punc, punc, + punc, lhex, lhex, lhex, lhex, lhex, lhex, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, + lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, lowc, punc, punc, punc, punc, ctrl, + // clang-format on +}; + +const unsigned char __lower_map[256] = { + // clang-format off + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', + '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '[', '\\', ']', '^', '_', + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, + // clang-format on +}; + +const unsigned char __upper_map[256] = { + // clang-format off + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + ' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', + '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, + 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, + 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, + 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, + // clang-format on +}; + +int tolower(int __c) +{ + if (__c == -1) + return -1; + + return __lower_map[__c & 0xff]; +} + +int toupper(int __c) +{ + + if (__c == -1) + return -1; + + return __upper_map[__c & 0xff]; +} diff --git a/src/MSL_C.PPCEABI.bare.H/direct_io.c b/src/MSL_C.PPCEABI.bare.H/direct_io.c new file mode 100644 index 00000000..ba963b42 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/direct_io.c @@ -0,0 +1,114 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/buffer_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/misc_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/string.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h" + +size_t fwrite(const void* buffer, size_t size, size_t count, FILE* stream) +{ + unsigned char* write_ptr; + size_t num_bytes, bytes_to_go, bytes_written; + int ioresult, always_buffer; + + if (fwide(stream, 0) == 0) + fwide(stream, -1); + + bytes_to_go = size * count; + + if (!bytes_to_go || stream->file_state.error + || stream->file_mode.file_kind == __closed_file) + return 0; + + if ((int)stream->file_mode.file_kind == __console_file) + __stdio_atexit(); + + always_buffer = !stream->file_mode.binary_io + || (int)stream->file_mode.file_kind == __string_file + || stream->file_mode.buffer_mode == _IOFBF + || stream->file_mode.buffer_mode == _IOLBF; + + if (stream->file_state.io_state == __neutral) { + if (stream->file_mode.io_mode & __write) { + stream->file_state.io_state = __writing; + + __prep_buffer(stream); + } + } + + if (stream->file_state.io_state != __writing) { + set_error(stream); + return 0; + } + + write_ptr = (unsigned char*)buffer; + bytes_written = 0; + + if (bytes_to_go + && (stream->buffer_ptr != stream->buffer || always_buffer)) { + stream->buffer_length + = stream->buffer_size - (stream->buffer_ptr - stream->buffer); + + do { + unsigned char* newline = NULL; + + num_bytes = stream->buffer_length; + + if (num_bytes > bytes_to_go) + num_bytes = bytes_to_go; + + if (num_bytes) { + memcpy(stream->buffer_ptr, write_ptr, num_bytes); + + write_ptr += num_bytes; + bytes_written += num_bytes; + bytes_to_go -= num_bytes; + + stream->buffer_ptr += num_bytes; + stream->buffer_length -= num_bytes; + } + + if (!stream->buffer_length + && (int)stream->file_mode.file_kind == __string_file) { + bytes_written += bytes_to_go; + break; + } + + if (!stream->buffer_length || newline != NULL + || (stream->file_mode.buffer_mode == _IONBF)) { + ioresult = __flush_buffer(stream, NULL); + + if (ioresult) { + set_error(stream); + bytes_to_go = 0; + break; + } + } + } while (bytes_to_go && always_buffer); + } + + if (bytes_to_go && !always_buffer) { + unsigned char* save_buffer = stream->buffer; + size_t save_size = stream->buffer_size; + + stream->buffer = write_ptr; + stream->buffer_size = bytes_to_go; + stream->buffer_ptr = write_ptr + bytes_to_go; + + if (__flush_buffer(stream, &num_bytes) != __no_io_error) + set_error(stream); + + bytes_written += num_bytes; + + stream->buffer = save_buffer; + stream->buffer_size = save_size; + + __prep_buffer(stream); + + stream->buffer_length = 0; + } + + if (stream->file_mode.buffer_mode != _IOFBF) + stream->buffer_length = 0; + + return ((bytes_written + size - 1) / size); +} diff --git a/src/MSL_C.PPCEABI.bare.H/e_asin.c b/src/MSL_C.PPCEABI.bare.H/e_asin.c new file mode 100644 index 00000000..bc5754f4 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/e_asin.c @@ -0,0 +1,3 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +double fabs__Fd(double v) { return __fabs(v); } diff --git a/src/MSL_C.PPCEABI.bare.H/e_atan2.c b/src/MSL_C.PPCEABI.bare.H/e_atan2.c new file mode 100644 index 00000000..43b99afd --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/e_atan2.c @@ -0,0 +1,145 @@ + +/* @(#)e_atan2.c 1.3 95/01/18 */ +/** + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* __ieee754_atan2(y,x) + * Method : + * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). + * 2. Reduce x to positive by (if x and y are unexceptional): + * ARG (x+iy) = arctan(y/x) ... if x > 0, + * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, + * + * Special cases: + * + * ATAN2((anything), NaN ) is NaN; + * ATAN2(NAN , (anything) ) is NaN; + * ATAN2(+-0, +(anything but NaN)) is +-0 ; + * ATAN2(+-0, -(anything but NaN)) is +-pi ; + * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; + * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; + * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; + * ATAN2(+-INF,+INF ) is +-pi/4 ; + * ATAN2(+-INF,-INF ) is +-3pi/4; + * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#ifdef __STDC__ +static const double +#else +static double +#endif + tiny + = 1.0e-300, + zero = 0.0, pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */ + pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */ + pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ + pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ + +#ifdef __STDC__ +double __ieee754_atan2(double y, double x) +#else +double __ieee754_atan2(y, x) +double y, x; +#endif +{ + double z; + int k, m, hx, hy, ix, iy; + unsigned lx, ly; + + hx = __HI(x); + ix = hx & 0x7fffffff; + lx = __LO(x); + hy = __HI(y); + iy = hy & 0x7fffffff; + ly = __LO(y); + if (((ix | ((lx | -lx) >> 31)) > 0x7ff00000) + || ((iy | ((ly | -ly) >> 31)) > 0x7ff00000)) /* x or y is NaN */ + return x + y; + if ((hx - 0x3ff00000 | lx) == 0) + return atan(y); /* x=1.0 */ + m = ((hy >> 31) & 1) | ((hx >> 30) & 2); /* 2*sign(x)+sign(y) */ + + /* when y = 0 */ + if ((iy | ly) == 0) { + switch (m) { + case 0: + case 1: + return y; /* atan(+-0,+anything)=+-0 */ + case 2: + return pi + tiny; /* atan(+0,-anything) = pi */ + case 3: + return -pi - tiny; /* atan(-0,-anything) =-pi */ + } + } + /* when x = 0 */ + if ((ix | lx) == 0) + return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; + + /* when x is INF */ + if (ix == 0x7ff00000) { + if (iy == 0x7ff00000) { + switch (m) { + case 0: + return pi_o_4 + tiny; /* atan(+INF,+INF) */ + case 1: + return -pi_o_4 - tiny; /* atan(-INF,+INF) */ + case 2: + return 3.0 * pi_o_4 + tiny; /*atan(+INF,-INF)*/ + case 3: + return -3.0 * pi_o_4 - tiny; /*atan(-INF,-INF)*/ + } + } else { + switch (m) { + case 0: + return zero; /* atan(+...,+INF) */ + case 1: + return -zero; /* atan(-...,+INF) */ + case 2: + return pi + tiny; /* atan(+...,-INF) */ + case 3: + return -pi - tiny; /* atan(-...,-INF) */ + } + } + } + /* when y is INF */ + if (iy == 0x7ff00000) + return (hy < 0) ? -pi_o_2 - tiny : pi_o_2 + tiny; + + /* compute y/x */ + k = (iy - ix) >> 20; + if (k > 60) + z = pi_o_2 + 0.5 * pi_lo; /* |y/x| > 2**60 */ + else if (hx < 0 && k < -60) + z = 0.0; /* |y|/x < -2**60 */ + else + z = atan(fabs__Fd(y / x)); /* safe to do y/x */ + switch (m) { + case 0: + return z; /* atan(+,+) */ + case 1: + __HI(z) ^= 0x80000000; + return z; /* atan(-,+) */ + case 2: + return pi - (z - pi_lo); /* atan(+,-) */ + default: /* case 3 */ + return (z - pi_lo) - pi; /* atan(-,-) */ + } +} diff --git a/src/MSL_C.PPCEABI.bare.H/errno.c b/src/MSL_C.PPCEABI.bare.H/errno.c new file mode 100644 index 00000000..fb0a2b41 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/errno.c @@ -0,0 +1,3 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/errno.h" + +int errno; diff --git a/src/MSL_C.PPCEABI.bare.H/float.c b/src/MSL_C.PPCEABI.bare.H/float.c new file mode 100644 index 00000000..f07b2812 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/float.c @@ -0,0 +1,5 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/float.h" + +unsigned long __float_nan[] = { 0x7FFFFFFF }; + +unsigned long __float_huge[] = { 0x7F800000 }; diff --git a/src/MSL_C.PPCEABI.bare.H/mbstring.c b/src/MSL_C.PPCEABI.bare.H/mbstring.c new file mode 100644 index 00000000..fa77c660 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/mbstring.c @@ -0,0 +1,18 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mbstring.h" + +size_t wcstombs(char* s, const wchar_t* pwcs, size_t n) +{ + wchar_t next; + size_t chars_written; + int i; + + chars_written = 0; + for (i = 0; i < n; ++i) { + next = *pwcs++; + *s++ = (char)next; + if ((char)next == '\0') + break; + ++chars_written; + } + return chars_written; +} diff --git a/src/MSL_C.PPCEABI.bare.H/mem.c b/src/MSL_C.PPCEABI.bare.H/mem.c new file mode 100644 index 00000000..519a6f56 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/mem.c @@ -0,0 +1,75 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/string.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h" + +void* memmove(void* dst, const void* src, size_t n) +{ + unsigned char* csrc; + unsigned char* cdst; + + int reverse = (unsigned int)src < (unsigned int)dst; + + if (n >= 32) { + if (((unsigned int)dst ^ (unsigned int)src) & 3) { + if (!reverse) { + __copy_longs_unaligned(dst, src, n); + } else { + __copy_longs_rev_unaligned(dst, src, n); + } + } else { + if (!reverse) { + __copy_longs_aligned(dst, src, n); + } else { + __copy_longs_rev_aligned(dst, src, n); + } + } + + return dst; + } else { + if (!reverse) { + csrc = ((unsigned char*)src) - 1; + cdst = ((unsigned char*)dst) - 1; + n++; + + while (--n > 0) { + *++cdst = *++csrc; + } + } else { + csrc = (unsigned char*)src + n; + cdst = (unsigned char*)dst + n; + n++; + + while (--n > 0) { + *--cdst = *--csrc; + } + } + } + + return dst; +} + +void* memchr(const void* ptr, int ch, size_t count) +{ + const unsigned char* p; + + unsigned long v = (ch & 0xff); + + for (p = (unsigned char*)ptr - 1, count++; --count;) + if ((*++p & 0xff) == v) + return (void*)p; + + return NULL; +} + +int memcmp(const void* lhs, const void* rhs, size_t count) +{ + const unsigned char* p1; + const unsigned char* p2; + + for (p1 = (const unsigned char*)lhs - 1, p2 = (const unsigned char*)rhs - 1, + count++; + --count;) + if (*++p1 != *++p2) + return ((*p1 < *p2) ? -1 : +1); + + return 0; +} diff --git a/src/MSL_C.PPCEABI.bare.H/mem_funcs.c b/src/MSL_C.PPCEABI.bare.H/mem_funcs.c new file mode 100644 index 00000000..a22984c4 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/mem_funcs.c @@ -0,0 +1,221 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/mem_funcs.h" + +#define cps ((unsigned char*)src) +#define cpd ((unsigned char*)dst) +#define lps ((unsigned long*)src) +#define lpd ((unsigned long*)dst) +#define deref_auto_inc(p) *++(p) + +void __copy_longs_aligned(void* dst, const void* src, size_t n) +{ + unsigned long i; + + i = (-(unsigned long)dst) & 3; + + cps = ((unsigned char*)src) - 1; + cpd = ((unsigned char*)dst) - 1; + + if (i) { + n -= i; + + do + deref_auto_inc(cpd) = deref_auto_inc(cps); + while (--i); + } + + lps = ((unsigned long*)(cps + 1)) - 1; + lpd = ((unsigned long*)(cpd + 1)) - 1; + + i = n >> 5; + + if (i) + do { + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + deref_auto_inc(lpd) = deref_auto_inc(lps); + } while (--i); + + i = (n & 31) >> 2; + + if (i) + do + deref_auto_inc(lpd) = deref_auto_inc(lps); + while (--i); + + cps = ((unsigned char*)(lps + 1)) - 1; + cpd = ((unsigned char*)(lpd + 1)) - 1; + + n &= 3; + + if (n) + do + deref_auto_inc(cpd) = deref_auto_inc(cps); + while (--n); + + return; +} + +void __copy_longs_rev_aligned(void* dst, const void* src, size_t n) +{ + unsigned long i; + + cps = ((unsigned char*)src) + n; + cpd = ((unsigned char*)dst) + n; + + i = ((unsigned long)cpd) & 3; + + if (i) { + n -= i; + + do + *--cpd = *--cps; + while (--i); + } + + i = n >> 5; + + if (i) + do { + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + *--lpd = *--lps; + } while (--i); + + i = (n & 31) >> 2; + + if (i) + do + *--lpd = *--lps; + while (--i); + + n &= 3; + + if (n) + do + *--cpd = *--cps; + while (--n); + + return; +} + +void __copy_longs_unaligned(void* dst, const void* src, size_t n) +{ + unsigned long i, v1, v2; + unsigned int src_offset, left_shift, right_shift; + + i = (-(unsigned long)dst) & 3; + + cps = ((unsigned char*)src) - 1; + cpd = ((unsigned char*)dst) - 1; + + if (i) { + n -= i; + + do + deref_auto_inc(cpd) = deref_auto_inc(cps); + while (--i); + } + + src_offset = ((unsigned int)(cps + 1)) & 3; + + left_shift = src_offset << 3; + right_shift = 32 - left_shift; + + cps -= src_offset; + + lps = ((unsigned long*)(cps + 1)) - 1; + lpd = ((unsigned long*)(cpd + 1)) - 1; + + i = n >> 3; + + v1 = deref_auto_inc(lps); + + do { + v2 = deref_auto_inc(lps); + deref_auto_inc(lpd) = (v1 << left_shift) | (v2 >> right_shift); + v1 = deref_auto_inc(lps); + deref_auto_inc(lpd) = (v2 << left_shift) | (v1 >> right_shift); + } while (--i); + + if (n & 4) { + v2 = deref_auto_inc(lps); + deref_auto_inc(lpd) = (v1 << left_shift) | (v2 >> right_shift); + } + + cps = ((unsigned char*)(lps + 1)) - 1; + cpd = ((unsigned char*)(lpd + 1)) - 1; + + n &= 3; + + if (n) { + cps -= 4 - src_offset; + do + deref_auto_inc(cpd) = deref_auto_inc(cps); + while (--n); + } + + return; +} + +void __copy_longs_rev_unaligned(void* dst, const void* src, size_t n) +{ + unsigned long i, v1, v2; + unsigned int src_offset, left_shift, right_shift; + + cps = ((unsigned char*)src) + n; + cpd = ((unsigned char*)dst) + n; + + i = ((unsigned long)cpd) & 3; + + if (i) { + n -= i; + + do + *--cpd = *--cps; + while (--i); + } + + src_offset = ((unsigned int)cps) & 3; + + left_shift = src_offset << 3; + right_shift = 32 - left_shift; + + cps += 4 - src_offset; + + i = n >> 3; + + v1 = *--lps; + + do { + v2 = *--lps; + *--lpd = (v2 << left_shift) | (v1 >> right_shift); + v1 = *--lps; + *--lpd = (v1 << left_shift) | (v2 >> right_shift); + } while (--i); + + if (n & 4) { + v2 = *--lps; + *--lpd = (v2 << left_shift) | (v1 >> right_shift); + } + + n &= 3; + + if (n) { + cps += src_offset; + do + *--cpd = *--cps; + while (--n); + } + + return; +} diff --git a/src/MSL_C.PPCEABI.bare.H/misc_io.c b/src/MSL_C.PPCEABI.bare.H/misc_io.c new file mode 100644 index 00000000..2b6c9913 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/misc_io.c @@ -0,0 +1 @@ +void __stdio_atexit(void) { } diff --git a/src/MSL_C.PPCEABI.bare.H/printf.c b/src/MSL_C.PPCEABI.bare.H/printf.c new file mode 100644 index 00000000..4fe8c869 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/printf.c @@ -0,0 +1,1076 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/printf.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ansi_fp.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/direct_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdio.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdlib.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/string.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/stdarg.h" + +extern void __num2dec(const decform*, double, decimal*); + +#define TARGET_FLOAT_BITS 64 +#define TARGET_FLOAT_BYTES (TARGET_FLOAT_BITS / 8) +#define TARGET_FLOAT_MAX_EXP LDBL_MAX_EXP +#define TARGET_FLOAT_MANT_DIG LDBL_MANT_DIG +#define TARGET_FLOAT_IMPLICIT_J_BIT 1 +#define TARGET_FLOAT_MANT_BITS \ + (TARGET_FLOAT_MANT_DIG - TARGET_FLOAT_IMPLICIT_J_BIT) +#define TARGET_FLOAT_EXP_BITS (TARGET_FLOAT_BITS - TARGET_FLOAT_MANT_BITS - 1) + +enum justification_options { + left_justification, + right_justification, + zero_fill +}; + +enum sign_options { only_minus, sign_always, space_holder }; + +enum argument_options { + normal_argument, + char_argument, + short_argument, + long_argument, + long_long_argument, + long_double_argument, + wchar_argument +}; + +typedef struct { + unsigned char justification_options; + unsigned char sign_options; + unsigned char precision_specified; + unsigned char alternate_form; + unsigned char argument_options; + unsigned char conversion_char; + int field_width; + int precision; +} print_format; + +static const char* parse_format(const char* format_string, va_list* arg, + print_format* format) +{ + print_format f; + const char* s = format_string; + int c; + int flag_found; + f.justification_options = right_justification; + f.sign_options = only_minus; + f.precision_specified = 0; + f.alternate_form = 0; + f.argument_options = normal_argument; + f.field_width = 0; + f.precision = 0; + + if ((c = *++s) == '%') { + f.conversion_char = c; + *format = f; + return ((const char*)s + 1); + } + + for (;;) { + flag_found = 1; + + switch (c) { + case '-': + f.justification_options = left_justification; + break; + case '+': + f.sign_options = sign_always; + break; + case ' ': + if (f.sign_options != sign_always) { + f.sign_options = space_holder; + } + break; + case '#': + f.alternate_form = 1; + break; + case '0': + if (f.justification_options != left_justification) { + f.justification_options = zero_fill; + } + break; + default: + flag_found = 0; + break; + } + + if (flag_found) { + c = *++s; + } else { + break; + } + } + + if (c == '*') { + if ((f.field_width = va_arg(*arg, int)) < 0) { + f.justification_options = left_justification; + f.field_width = -f.field_width; + } + + c = *++s; + } else { + while (isdigit(c)) { + f.field_width = (f.field_width * 10) + (c - '0'); + c = *++s; + } + } + + if (f.field_width > 509) { + f.conversion_char = 0xFF; + *format = f; + return ((const char*)s + 1); + } + + if (c == '.') { + f.precision_specified = 1; + + if ((c = *++s) == '*') { + if ((f.precision = va_arg(*arg, int)) < 0) { + f.precision_specified = 0; + } + + c = *++s; + } else { + while (isdigit(c)) { + f.precision = (f.precision * 10) + (c - '0'); + c = *++s; + } + } + } + + flag_found = 1; + + switch (c) { + case 'h': + f.argument_options = short_argument; + + if (s[1] == 'h') { + f.argument_options = char_argument; + c = *++s; + } + + break; + + case 'l': + f.argument_options = long_argument; + + if (s[1] == 'l') { + f.argument_options = long_long_argument; + c = *++s; + } + + break; + + case 'L': + f.argument_options = long_double_argument; + break; + default: + flag_found = 0; + break; + } + + if (flag_found) { + c = *++s; + } + + f.conversion_char = c; + + switch (c) { + case 'd': + case 'i': + case 'u': + case 'o': + case 'x': + case 'X': + if (f.argument_options == long_double_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 1; + } else if (f.justification_options == zero_fill) { + f.justification_options = right_justification; + } + break; + + case 'f': + if (f.argument_options == short_argument + || f.argument_options == long_long_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 6; + } + break; + + case 'g': + case 'G': + if (!f.precision) { + f.precision = 1; + } + + case 'e': + case 'E': + if (f.argument_options == short_argument + || f.argument_options == long_long_argument + || f.argument_options == char_argument) { + f.conversion_char = 0xFF; + break; + } + + if (!f.precision_specified) { + f.precision = 6; + } + break; + + case 'p': + f.conversion_char = 'x'; + f.alternate_form = 1; + f.argument_options = long_argument; + f.precision = 8; + break; + + case 'c': + if (f.argument_options == long_argument) { + f.argument_options = wchar_argument; + } else { + if (f.precision_specified + || f.argument_options != normal_argument) { + f.conversion_char = 0xFF; + } + } + + break; + + case 's': + if (f.argument_options == long_argument) { + f.argument_options = wchar_argument; + } else { + if (f.argument_options != normal_argument) { + f.conversion_char = 0xFF; + } + } + + break; + + case 'n': + if (f.argument_options == long_double_argument) { + f.conversion_char = 0xFF; + } + + break; + + default: + f.conversion_char = 0xFF; + break; + } + + *format = f; + return ((const char*)s + 1); +} + +static char* long2str(signed long num, char* buff, print_format* format) +{ + unsigned long unsigned_num, base; + char* p; + int n, digits; + int minus = 0; + unsigned_num = num; + minus = 0; + + p = buff; + *--p = 0; + digits = 0; + + if (!num && !format->precision + && !(format->alternate_form && format->conversion_char == 'o')) { + return p; + } + + switch (format->conversion_char) { + case 'd': + case 'i': + base = 10; + + if (num < 0) { + unsigned_num = -unsigned_num; + minus = 1; + } + break; + + case 'o': + base = 8; + format->sign_options = only_minus; + break; + + case 'u': + base = 10; + format->sign_options = only_minus; + break; + + case 'x': + case 'X': + base = 16; + format->sign_options = only_minus; + break; + } + + do { + n = unsigned_num % base; + unsigned_num /= base; + + if (n < 10) { + n += '0'; + } else { + n -= 10; + + if (format->conversion_char == 'x') { + n += 'a'; + } else { + n += 'A'; + } + } + + *--p = n; + ++digits; + } while (unsigned_num != 0); + + if (base == 8 && format->alternate_form && *p != '0') { + *--p = '0'; + ++digits; + } + + if (format->justification_options == zero_fill) { + format->precision = format->field_width; + + if (minus || format->sign_options != only_minus) + --format->precision; + + if (base == 16 && format->alternate_form) + format->precision -= 2; + } + + if (buff - p + format->precision > 509) + return (0); + + while (digits < format->precision) { + *--p = '0'; + ++digits; + } + + if (base == 16 && format->alternate_form) { + *--p = format->conversion_char; + *--p = '0'; + } + + if (minus) { + *--p = '-'; + } else if (format->sign_options == sign_always) { + *--p = '+'; + } else if (format->sign_options == space_holder) { + *--p = ' '; + } + + return p; +} + +static char* longlong2str(signed long long num, char* pBuf, print_format* fmt) +{ + unsigned long long unsigned_num, base; + char* p; + int n, digits; + int minus = 0; + unsigned_num = num; + minus = 0; + p = pBuf; + *--p = 0; + digits = 0; + + if (!num && !fmt->precision + && !(fmt->alternate_form && fmt->conversion_char == 'o')) { + return p; + } + + switch (fmt->conversion_char) { + case 'd': + case 'i': + base = 10; + + if (num < 0) { + unsigned_num = -unsigned_num; + minus = 1; + } + break; + case 'o': + base = 8; + fmt->sign_options = only_minus; + break; + case 'u': + base = 10; + fmt->sign_options = only_minus; + break; + case 'x': + case 'X': + base = 16; + fmt->sign_options = only_minus; + break; + } + + do { + n = unsigned_num % base; + unsigned_num /= base; + + if (n < 10) { + n += '0'; + } else { + n -= 10; + if (fmt->conversion_char == 'x') { + n += 'a'; + } else { + n += 'A'; + } + } + + *--p = n; + ++digits; + } while (unsigned_num != 0); + + if (base == 8 && fmt->alternate_form && *p != '0') { + *--p = '0'; + ++digits; + } + + if (fmt->justification_options == zero_fill) { + fmt->precision = fmt->field_width; + + if (minus || fmt->sign_options != only_minus) { + --fmt->precision; + } + + if (base == 16 && fmt->alternate_form) { + fmt->precision -= 2; + } + } + + if (pBuf - p + fmt->precision > 509) { + return 0; + } + + while (digits < fmt->precision) { + *--p = '0'; + ++digits; + } + + if (base == 16 && fmt->alternate_form) { + *--p = fmt->conversion_char; + *--p = '0'; + } + + if (minus) { + *--p = '-'; + } else if (fmt->sign_options == sign_always) { + *--p = '+'; + } else if (fmt->sign_options == space_holder) { + *--p = ' '; + } + + return p; +} + +static void round_decimal(decimal* dec, int new_length) +{ + char c; + char* p; + int carry; + + if (new_length < 0) { + return_zero: + dec->sign = 0; + dec->exp = 0; + dec->sig.length = 1; + *dec->sig.text = '0'; + return; + } + + if (new_length >= dec->sig.length) { + return; + } + + p = (char*)dec->sig.text + new_length + 1; + c = *--p - '0'; + + if (c == 5) { + char* q = &((char*)dec->sig.text)[dec->sig.length]; + + while (--q > p && *q == '0') + ; + carry = (q == p) ? p[-1] & 1 : 1; + } else { + carry = (c > 5); + } + + while (new_length != 0) { + c = *--p - '0' + carry; + + if ((carry = (c > 9)) != 0 || c == 0) { + --new_length; + } else { + *p = c + '0'; + break; + } + } + + if (carry != 0) { + dec->exp += 1; + dec->sig.length = 1; + *dec->sig.text = '1'; + return; + } else if (new_length == 0) { + goto return_zero; + } + + dec->sig.length = new_length; +} + +static char* float2str(va_list arg, char* buff, print_format* format, + int vecIndex) +{ + decimal dec; + decform form; + char* p; + char* q; + int n, digits, sign; + int int_digits, frac_digits; + long double num; + + if (format->argument_options == long_double_argument) { + num = va_arg(arg, long double); + } else { + num = va_arg(arg, double); + } + + if (format->precision > 509) { + return 0; + } + + form.style = 0; + form.digits = 0x20; + __num2dec(&form, num, &dec); + p = (char*)dec.sig.text + dec.sig.length; + + while (dec.sig.length > 1 && *--p == '0') { + --dec.sig.length; + ++dec.exp; + } + + switch (*dec.sig.text) { + case '0': + dec.exp = 0; + break; + case 'I': + if (num < 0) { + p = buff - 5; + strcpy(p, "-Inf"); + } else { + p = buff - 4; + strcpy(p, "Inf"); + } + + return p; + + case 'N': + p = buff - 4; + strcpy(p, "NaN"); + return p; + } + + dec.exp += dec.sig.length - 1; + p = buff; + *--p = 0; + + switch (format->conversion_char) { + case 'g': + case 'G': + + if (dec.sig.length > format->precision) { + round_decimal(&dec, format->precision); + } + + if (dec.exp < -4 || dec.exp >= format->precision) { + if (format->alternate_form) { + --format->precision; + } else { + format->precision = dec.sig.length - 1; + } + + if (format->conversion_char == 'g') { + format->conversion_char = 'e'; + } else { + format->conversion_char = 'E'; + } + + goto e_format; + } + + if (format->alternate_form) { + format->precision -= dec.exp + 1; + } else { + if ((format->precision = dec.sig.length - (dec.exp + 1)) < 0) { + format->precision = 0; + } + } + + goto f_format; + + case 'e': + case 'E': + e_format: + + if (dec.sig.length > format->precision + 1) { + round_decimal(&dec, format->precision + 1); + } + + n = dec.exp; + sign = '+'; + + if (n < 0) { + n = -n; + sign = '-'; + } + + for (digits = 0; n || digits < 2; ++digits) { + *--p = n % 10 + '0'; + n /= 10; + } + + *--p = sign; + *--p = format->conversion_char; + + if (buff - p + format->precision > 509) { + return 0; + } + + if (dec.sig.length < format->precision + 1) { + for (n = format->precision + 1 - dec.sig.length + 1; --n;) { + *--p = '0'; + } + } + + for (n = dec.sig.length, q = (char*)dec.sig.text + dec.sig.length; + --n;) { + *--p = *--q; + } + + if (format->precision || format->alternate_form) { + *--p = '.'; + } + + *--p = *dec.sig.text; + + if (dec.sign) + *--p = '-'; + else if (format->sign_options == sign_always) + *--p = '+'; + else if (format->sign_options == space_holder) + *--p = ' '; + + break; + + case 'f': + f_format: + + if ((frac_digits = -dec.exp + dec.sig.length - 1) < 0) + frac_digits = 0; + + if (frac_digits > format->precision) { + round_decimal(&dec, + dec.sig.length - (frac_digits - format->precision)); + + if ((frac_digits = -dec.exp + dec.sig.length - 1) < 0) + frac_digits = 0; + } + + if ((int_digits = dec.exp + 1) < 0) + int_digits = 0; + + if (int_digits + frac_digits > 509) + return 0; + + q = (char*)dec.sig.text + dec.sig.length; + + for (digits = 0; digits < (format->precision - frac_digits); ++digits) + *--p = '0'; + + for (digits = 0; digits < frac_digits && digits < dec.sig.length; + ++digits) + *--p = *--q; + + for (; digits < frac_digits; ++digits) + *--p = '0'; + + if (format->precision || format->alternate_form) + *--p = '.'; + + if (int_digits) { + for (digits = 0; digits < int_digits - dec.sig.length; ++digits) { + *--p = '0'; + } + + for (; digits < int_digits; ++digits) { + *--p = *--q; + } + } else { + *--p = '0'; + } + + if (dec.sign) { + *--p = '-'; + } else if (format->sign_options == sign_always) { + *--p = '+'; + } else if (format->sign_options == space_holder) { + *--p = ' '; + } + + break; + } + + return p; +} + +static int __pformatter(void* (*WriteProc)(void*, const char*, size_t), + void* WriteProcArg, const char* format_str, va_list arg) +{ + int num_chars, chars_written, field_width; + const char* format_ptr; + const char* curr_format; + print_format format; + signed long long_num; + signed long long long_long_num; + char buff[512]; + char* buff_ptr; + char* string_end; + char fill_char = ' '; + + format_ptr = format_str; + chars_written = 0; + + while (*format_ptr) { + if (!(curr_format = strchr(format_ptr, '%'))) { + num_chars = strlen(format_ptr); + chars_written += num_chars; + + if (num_chars + && !(*WriteProc)(WriteProcArg, format_ptr, num_chars)) { + return -1; + } + + break; + } + + num_chars = curr_format - format_ptr; + chars_written += num_chars; + + if (num_chars && !(*WriteProc)(WriteProcArg, format_ptr, num_chars)) { + return -1; + } + + format_ptr = curr_format; + format_ptr = parse_format(format_ptr, (va_list*)arg, &format); + + switch (format.conversion_char) { + case 'd': + case 'i': + if (format.argument_options == long_argument) { + long_num = va_arg(arg, signed long); + } else if (format.argument_options == long_long_argument) { + long_long_num = va_arg(arg, signed long long); + } else { + long_num = va_arg(arg, int); + } + + if (format.argument_options == short_argument) { + long_num = (signed short)long_num; + } + + if (format.argument_options == char_argument) { + long_num = (signed char)long_num; + } + + if (format.argument_options == long_long_argument) { + if (!(buff_ptr + = longlong2str(long_long_num, buff + 512, &format))) { + goto conversion_error; + } + } else { + if (!(buff_ptr = long2str(long_num, buff + 512, &format))) { + goto conversion_error; + } + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + + case 'o': + case 'u': + case 'x': + case 'X': + if (format.argument_options == long_argument) { + long_num = va_arg(arg, unsigned long); + } else if (format.argument_options == long_long_argument) { + long_long_num = va_arg(arg, signed long long); + } else { + long_num = va_arg(arg, unsigned int); + } + + if (format.argument_options == short_argument) { + long_num = (unsigned short)long_num; + } + + if (format.argument_options == char_argument) { + long_num = (unsigned char)long_num; + } + + if (format.argument_options == long_long_argument) { + if (!(buff_ptr + = longlong2str(long_long_num, buff + 512, &format))) { + goto conversion_error; + } + } else { + if (!(buff_ptr = long2str(long_num, buff + 512, &format))) { + goto conversion_error; + } + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + if (!(buff_ptr = float2str(arg, buff + 512, &format, 0))) { + goto conversion_error; + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + + case 's': + if (format.argument_options == wchar_argument) { + wchar_t* wcs_ptr = va_arg(arg, wchar_t*); + + if (wcs_ptr == NULL) { + wcs_ptr = L""; + } + + if ((num_chars = wcstombs(buff, wcs_ptr, sizeof(buff))) < 0) { + goto conversion_error; + } + + buff_ptr = &buff[0]; + } else { + buff_ptr = va_arg(arg, char*); + } + + if (buff_ptr == NULL) { + buff_ptr = ""; + } + + if (format.alternate_form) { + num_chars = (unsigned char)*buff_ptr++; + + if (format.precision_specified + && num_chars > format.precision) { + num_chars = format.precision; + } + } else if (format.precision_specified) { + num_chars = format.precision; + + if ((string_end + = (char*)memchr((unsigned char*)buff_ptr, 0, num_chars)) + != 0) { + num_chars = string_end - buff_ptr; + } + } else { + num_chars = strlen(buff_ptr); + } + + break; + + case 'n': + buff_ptr = va_arg(arg, char*); + + switch (format.argument_options) { + case normal_argument: + *(int*)buff_ptr = chars_written; + break; + case short_argument: + *(signed short*)buff_ptr = chars_written; + break; + case long_argument: + *(signed long*)buff_ptr = chars_written; + break; + case long_long_argument: + *(signed long long*)buff_ptr = chars_written; + break; + } + + continue; + + case 'c': + buff_ptr = buff; + *buff_ptr = va_arg(arg, int); + num_chars = 1; + break; + + case '%': + buff_ptr = buff; + *buff_ptr = '%'; + num_chars = 1; + break; + + case 0xFF: + default: + conversion_error: + num_chars = strlen(curr_format); + chars_written += num_chars; + + if (num_chars + && !(*WriteProc)(WriteProcArg, curr_format, num_chars)) { + return -1; + } + + return chars_written; + break; + } + + field_width = num_chars; + + if (format.justification_options != left_justification) { + fill_char = (format.justification_options == zero_fill) ? '0' : ' '; + + if (((*buff_ptr == '+') || (*buff_ptr == '-')) + && (fill_char == '0')) { + if ((*WriteProc)(WriteProcArg, buff_ptr, 1) == 0) { + return -1; + } + + ++buff_ptr; + num_chars--; + } + + while (field_width < format.field_width) { + if ((*WriteProc)(WriteProcArg, &fill_char, 1) == 0) { + return -1; + } + + ++field_width; + } + } + + if (num_chars && !(*WriteProc)(WriteProcArg, buff_ptr, num_chars)) { + return -1; + } + + if (format.justification_options == left_justification) { + while (field_width < format.field_width) { + char blank = ' '; + + if ((*WriteProc)(WriteProcArg, &blank, 1) == 0) { + return -1; + } + + ++field_width; + } + } + + chars_written += field_width; + } + + return chars_written; +} + +static void* __FileWrite(void* pFile, const char* pBuffer, size_t char_num) +{ + return (fwrite(pBuffer, 1, char_num, (FILE*)pFile) == char_num ? pFile : 0); +} + +static void* __StringWrite(void* pCtrl, const char* pBuffer, size_t char_num) +{ + size_t chars; + __OutStrCtrl* ctrl = (__OutStrCtrl*)pCtrl; + void* res; + + chars = ((ctrl->CharsWritten + char_num) <= ctrl->MaxCharCount) + ? char_num + : ctrl->MaxCharCount - ctrl->CharsWritten; + res = memcpy(ctrl->CharStr + ctrl->CharsWritten, pBuffer, chars); + ctrl->CharsWritten += chars; + return res; +} + +int printf(const char* format, ...) +{ + int res; + + if (fwide(stdout, -1) >= 0) { + return -1; + } + + { + va_list args; + va_start(args, format); + res = __pformatter(&__FileWrite, (void*)stdout, format, args); + } + + return res; +} + +int vprintf(const char* format, va_list arg) +{ + int ret; + + if (fwide(stdout, -1) >= 0) { + return -1; + } + + ret = __pformatter(&__FileWrite, (void*)stdout, format, arg); + return ret; +} + +int vsnprintf(char* s, size_t n, const char* format, va_list arg) +{ + int end; + __OutStrCtrl osc; + osc.CharStr = s; + osc.MaxCharCount = n; + osc.CharsWritten = 0; + + end = __pformatter(&__StringWrite, &osc, format, arg); + + s[(end < n) ? end : n - 1] = '\0'; + + return end; +} + +int snprintf(char* s, size_t n, const char* format, ...) +{ + va_list args; + va_start(args, format); + return vsnprintf(s, n, format, args); +} + +int sprintf(char* s, const char* format, ...) +{ + va_list args; + va_start(args, format); + return vsnprintf(s, 0xFFFFFFFF, format, args); +} diff --git a/src/MSL_C.PPCEABI.bare.H/rand.c b/src/MSL_C.PPCEABI.bare.H/rand.c new file mode 100644 index 00000000..4d57c3e5 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/rand.c @@ -0,0 +1,13 @@ +#include "dolphin.h" + +// rand.c from Runtime library + +u32 next = 1; + +u32 rand(void) +{ + next = 0x41C64E6D * next + 12345; + return (next >> 16) & 0x7FFF; +} + +void srand(u32 seed) { next = seed; } diff --git a/src/MSL_C.PPCEABI.bare.H/s_atan.c b/src/MSL_C.PPCEABI.bare.H/s_atan.c new file mode 100644 index 00000000..6d72b440 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/s_atan.c @@ -0,0 +1,148 @@ + +/* @(#)s_atan.c 1.3 95/01/18 */ +/** + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* atan(x) + * Method + * 1. Reduce x to positive by atan(x) = -atan(-x). + * 2. According to the integer k=4t+0.25 chopped, t=x, the argument + * is further reduced to one of the following intervals and the + * arctangent of t is evaluated by the corresponding formula: + * + * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...) + * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) ) + * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) ) + * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) ) + * [39/16,INF] atan(x) = atan(INF) + atan( -1/t ) + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#ifdef __STDC__ +static const double atanhi[] = { +#else +static double atanhi[] = { +#endif + 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ + 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ + 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */ + 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */ +}; + +#ifdef __STDC__ +static const double atanlo[] = { +#else +static double atanlo[] = { +#endif + 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */ + 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */ + 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */ + 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */ +}; + +#ifdef __STDC__ +static const double aT[] = { +#else +static double aT[] = { +#endif + 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */ + -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */ + 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */ + -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */ + 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */ + -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */ + 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */ + -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */ + 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */ + -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */ + 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */ +}; + +#ifdef __STDC__ +static const double +#else +static double +#endif + one + = 1.0, + huge = 1.0e300; + +#ifdef __STDC__ +double atan(double x) +#else +double atan(x) +double x; +#endif +{ + double w, s1, s2, z; + int ix, hx, id; + + hx = __HI(x); + ix = hx & 0x7fffffff; + if (ix >= 0x44100000) { /* if |x| >= 2^66 */ + if (ix > 0x7ff00000 || (ix == 0x7ff00000 && (__LO(x) != 0))) + return x + x; /* NaN */ + if (hx > 0) + return atanhi[3] + atanlo[3]; + else + return -atanhi[3] - atanlo[3]; + } + if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ + if (ix < 0x3e200000) { /* |x| < 2^-29 */ + if (huge + x > one) + return x; /* raise inexact */ + } + id = -1; + } else { + x = fabs__Fd(x); + if (ix < 0x3ff30000) { /* |x| < 1.1875 */ + if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */ + id = 0; + x = (2.0 * x - one) / (2.0 + x); + } else { /* 11/16<=|x|< 19/16 */ + id = 1; + x = (x - one) / (x + one); + } + } else { + if (ix < 0x40038000) { /* |x| < 2.4375 */ + id = 2; + x = (x - 1.5) / (one + 1.5 * x); + } else { /* 2.4375 <= |x| < 2^66 */ + id = 3; + x = -1.0 / x; + } + } + } + /* end of argument reduction */ + z = x * x; + w = z * z; + /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ + s1 = z + * (aT[0] + + w + * (aT[2] + + w * (aT[4] + w * (aT[6] + w * (aT[8] + w * aT[10]))))); + s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9])))); + if (id < 0) + return x - x * (s1 + s2); + else { + z = atanhi[id] - ((x * (s1 + s2) - atanlo[id]) - x); + return (hx < 0) ? -z : z; + } +} diff --git a/src/MSL_C.PPCEABI.bare.H/s_frexp.c b/src/MSL_C.PPCEABI.bare.H/s_frexp.c new file mode 100644 index 00000000..a7bb05c4 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/s_frexp.c @@ -0,0 +1,58 @@ +/* @(#)s_frexp.c 1.4 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* + * for non-zero x + * x = frexp(arg,&exp); + * return a double fp quantity x such that 0.5 <= |x| <1.0 + * and the corresponding binary exponent "exp". That is + * arg = x*2^exp. + * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg + * with *exp=0. + */ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#ifdef __STDC__ +static const double +#else +static double +#endif + two54 + = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ + +#ifdef __STDC__ +double frexp(double x, int* eptr) +#else +double frexp(x, eptr) +double x; +int* eptr; +#endif +{ + int hx, ix, lx; + hx = __HI(x); + ix = 0x7fffffff & hx; + lx = __LO(x); + *eptr = 0; + if (ix >= 0x7ff00000 || ((ix | lx) == 0)) + return x; /* 0,inf,nan */ + if (ix < 0x00100000) { /* subnormal */ + x *= two54; + hx = __HI(x); + ix = hx & 0x7fffffff; + *eptr = -54; + } + *eptr += (ix >> 20) - 1022; + hx = (hx & 0x800fffff) | 0x3fe00000; + __HI(x) = hx; + return x; +} diff --git a/src/MSL_C.PPCEABI.bare.H/scanf.c b/src/MSL_C.PPCEABI.bare.H/scanf.c new file mode 100644 index 00000000..a8f273ec --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/scanf.c @@ -0,0 +1,34 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h" + +int __StringRead(void* pPtr, int ch, int act) +{ + char ret; + __InStrCtrl* Iscp = (__InStrCtrl*)pPtr; + + switch (act) { + case __GetAChar: + ret = *(Iscp->NextChar); + + if (ret == '\0') { + Iscp->NullCharDetected = 1; + return -1; + } else { + Iscp->NextChar++; + return ret; + } + + case __UngetAChar: + if (Iscp->NullCharDetected == 0) { + Iscp->NextChar--; + } else { + Iscp->NullCharDetected = 0; + } + + return ch; + + case __TestForError: + return Iscp->NullCharDetected; + } + + return 0; +} diff --git a/src/MSL_C.PPCEABI.bare.H/string.c b/src/MSL_C.PPCEABI.bare.H/string.c new file mode 100644 index 00000000..c4681838 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/string.c @@ -0,0 +1,257 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/string.h" + +static int K1 = 0x80808080; +static int K2 = 0xFEFEFEFF; + +size_t strlen(const char* str) +{ + size_t len = -1; + unsigned char* p = (unsigned char*)str - 1; + + do { + len++; + } while (*++p); + + return len; +} + +char* strcpy(char* dst, const char* src) +{ + register unsigned char *destb, *fromb; + register unsigned long w, t, align; + register unsigned int k1; + register unsigned int k2; + + fromb = (unsigned char*)src; + destb = (unsigned char*)dst; + + if ((align = ((int)fromb & 3)) != ((int)destb & 3)) { + goto bytecopy; + } + + if (align) { + if ((*destb = *fromb) == 0) { + return dst; + } + + for (align = 3 - align; align; align--) { + if ((*(++destb) = *(++fromb)) == 0) { + return dst; + } + } + ++destb; + ++fromb; + } + + k1 = K1; + k2 = K2; + + w = *((int*)(fromb)); + + t = w + k2; + + t &= k1; + if (t) { + goto bytecopy; + } + --((int*)(destb)); + + do { + *(++((int*)(destb))) = w; + w = *(++((int*)(fromb))); + + t = w + k2; + t &= k1; + if (t) { + goto adjust; + } + } while (1); + +adjust: + ++((int*)(destb)); + +bytecopy: + if ((*destb = *fromb) == 0) { + return dst; + } + + do { + if ((*(++destb) = *(++fromb)) == 0) { + return dst; + } + } while (1); + + return dst; +} + +char* strncpy(char* dst, const char* src, size_t n) +{ + const unsigned char* p = (const unsigned char*)src - 1; + unsigned char* q = (unsigned char*)dst - 1; + + n++; + while (--n) { + if (!(*++q = *++p)) { + while (--n) { + *++q = 0; + } + break; + } + } + + return dst; +} + +char* strcat(char* dst, const char* src) +{ + const unsigned char* p = (unsigned char*)src - 1; + unsigned char* q = (unsigned char*)dst - 1; + + while (*++q) { } + + q--; + + while (*++q = *++p) { } + + return dst; +} + +int strcmp(const char* str1, const char* str2) +{ + register unsigned char* left = (unsigned char*)str1; + register unsigned char* right = (unsigned char*)str2; + unsigned long align, l1, r1, x; + + l1 = *left; + r1 = *right; + if (l1 - r1) { + return l1 - r1; + } + + if ((align = ((int)left & 3)) != ((int)right & 3)) { + goto bytecopy; + } + + if (align) { + if (l1 == 0) { + return 0; + } + for (align = 3 - align; align; align--) { + l1 = *(++left); + r1 = *(++right); + if (l1 - r1) { + return l1 - r1; + } + if (l1 == 0) { + return 0; + } + } + left++; + right++; + } + + l1 = *(int*)left; + r1 = *(int*)right; + x = l1 + K2; + if (x & K1) { + goto adjust; + } + + while (l1 == r1) { + l1 = *(++((int*)(left))); + r1 = *(++((int*)(right))); + x = l1 + K2; + if (x & K1) { + goto adjust; + } + } + + if (l1 > r1) { + return 1; + } + return -1; + +adjust: + l1 = *left; + r1 = *right; + if (l1 - r1) { + return l1 - r1; + } + +bytecopy: + if (l1 == 0) { + return 0; + } + + do { + l1 = *(++left); + r1 = *(++right); + if (l1 - r1) { + return l1 - r1; + } + if (l1 == 0) { + return 0; + } + } while (1); +} + +char* strchr(const char* str, int c) +{ + const unsigned char* p = (unsigned char*)str - 1; + unsigned long chr = (c & 0xFF); + + unsigned long ch; + while (ch = *++p) { + if (ch == chr) { + return (char*)p; + } + } + + return chr ? NULL : (char*)p; +} + +char* strrchr(const char* str, int c) +{ + const unsigned char* p = (unsigned char*)str - 1; + const unsigned char* q = NULL; + unsigned long chr = (c & 0xFF); + + unsigned long ch; + while (ch = *++p) { + if (ch == chr) { + q = p; + } + } + + if (q != NULL) { + return (char*)q; + } + + return chr ? NULL : (char*)p; +} + +char* strstr(const char* str, const char* pat) +{ + const unsigned char* s1 = (const unsigned char*)str - 1; + const unsigned char* p1 = (const unsigned char*)pat - 1; + unsigned long firstc, c1, c2; + + if ((pat == 0) || (!(firstc = *++p1))) { + return (char*)str; + } + + while (c1 = *++s1) { + if (c1 == firstc) { + const unsigned char* s2 = s1 - 1; + const unsigned char* p2 = p1 - 1; + + while ((c1 = *++s2) == (c2 = *++p2) && c1) + ; + + if (!c2) + return (char*)s1; + } + } + + return NULL; +} diff --git a/src/MSL_C.PPCEABI.bare.H/strtoul.c b/src/MSL_C.PPCEABI.bare.H/strtoul.c new file mode 100644 index 00000000..e40b9fac --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/strtoul.c @@ -0,0 +1,199 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/strtoul.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/ctype.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/errno.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/limits.h" +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/scanf.h" + +enum scan_states { + start = 0x01, + check_for_zero = 0x02, + leading_zero = 0x04, + need_digit = 0x08, + digit_loop = 0x10, + finished = 0x20, + failure = 0x40 +}; + +#define final_state(scan_state) (scan_state & (finished | failure)) +#define success(scan_state) \ + (scan_state & (leading_zero | digit_loop | finished)) +#define fetch() (count++, (*ReadProc)(ReadProcArg, 0, __GetAChar)) +#define unfetch(c) (*ReadProc)(ReadProcArg, c, __UngetAChar) + +unsigned long __strtoul(int base, int max_width, + int (*ReadProc)(void*, int, int), void* ReadProcArg, + int* chars_scanned, int* negative, int* overflow) +{ + int scan_state = start; + int count = 0; + unsigned long value = 0; + unsigned long value_max = 0; + int c; + + *negative = *overflow = 0; + + if (base < 0 || base == 1 || base > 36 || max_width < 1) { + scan_state = failure; + } else { + c = fetch(); + } + + if (base != 0) + value_max = ULONG_MAX / base; + + while (count <= max_width && c != -1 && !final_state(scan_state)) { + switch (scan_state) { + case start: + if (isspace(c)) { + c = fetch(); + break; + } + + if (c == '+') { + c = fetch(); + } else if (c == '-') { + c = fetch(); + *negative = 1; + } + + scan_state = check_for_zero; + break; + + case check_for_zero: + if (base == 0 || base == 16) { + if (c == '0') { + scan_state = leading_zero; + c = fetch(); + break; + } + } + + scan_state = need_digit; + break; + + case 4: + if (c == 'X' || c == 'x') { + base = 16; + scan_state = need_digit; + c = fetch(); + break; + } + + if (base == 0) + base = 8; + + scan_state = digit_loop; + break; + + case need_digit: + case digit_loop: + if (base == 0) + base = 10; + + if (!value_max) { + value_max = ULONG_MAX / base; + } + + if (isdigit(c)) { + if ((c -= '0') >= base) { + if (scan_state == digit_loop) + scan_state = finished; + else + scan_state = failure; + + c += '0'; + break; + } + } else if (!isalpha(c) || (toupper(c) - 'A' + 10) >= base) { + if (scan_state == digit_loop) + scan_state = finished; + else + scan_state = failure; + + break; + } else { + c = toupper(c) - 'A' + 10; + } + + if (value > value_max) + *overflow = 1; + + value *= base; + + if (c > (ULONG_MAX - value)) + *overflow = 1; + + value += c; + scan_state = digit_loop; + c = fetch(); + break; + } + } + + if (!success(scan_state)) { + value = 0; + count = 0; + } else { + count--; + } + + *chars_scanned = count; + + unfetch(c); + + return value; +} + +unsigned long strtoul(const char* str, char** end, int base) +{ + unsigned long value; + int count, negative, overflow; + + __InStrCtrl isc; + isc.NextChar = (char*)str; + isc.NullCharDetected = 0; + + value = __strtoul(base, 0x7FFFFFFF, &__StringRead, (void*)&isc, &count, + &negative, &overflow); + + if (end) { + *end = (char*)str + count; + } + + if (overflow) { + value = ULONG_MAX; + errno = 0x22; + } else if (negative) { + value = -value; + } + + return value; +} + +long strtol(const char* str, char** end, int base) +{ + unsigned long uvalue; + long svalue; + int count, negative, overflow; + + __InStrCtrl isc; + isc.NextChar = (char*)str; + isc.NullCharDetected = 0; + + uvalue = __strtoul(base, 0x7FFFFFFF, &__StringRead, (void*)&isc, &count, + &negative, &overflow); + + if (end) { + *end = (char*)str + count; + } + + if (overflow || (!negative && uvalue > LONG_MAX) + || (negative && uvalue > -LONG_MIN)) { + svalue = (negative ? -LONG_MIN : LONG_MAX); + errno = ERANGE; + } else { + svalue = (negative ? (long)-uvalue : (long)uvalue); + } + + return svalue; +} diff --git a/src/MSL_C.PPCEABI.bare.H/w_atan2.c b/src/MSL_C.PPCEABI.bare.H/w_atan2.c new file mode 100644 index 00000000..42f1b297 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/w_atan2.c @@ -0,0 +1,39 @@ +/* @(#)w_atan2.c 1.3 95/01/18 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + +/* + * wrapper atan2(y,x) + */ + +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common_Embedded/Math/fdlibm.h" + +#ifdef __STDC__ +double atan2(double y, double x) /* wrapper atan2 */ +#else +double atan2(y, x) /* wrapper atan2 */ +double y, x; +#endif +{ +#ifdef _IEEE_LIBM + return __ieee754_atan2(y, x); +#else + double z; + z = __ieee754_atan2(y, x); + if (_LIB_VERSION == _IEEE_ || isnan(x) || isnan(y)) + return z; + if (x == 0.0 && y == 0.0) { + return __kernel_standard(y, x, 3); /* atan2(+-0,+-0) */ + } else + return z; +#endif +} diff --git a/src/MSL_C.PPCEABI.bare.H/wchar_io.c b/src/MSL_C.PPCEABI.bare.H/wchar_io.c new file mode 100644 index 00000000..4d5d32b5 --- /dev/null +++ b/src/MSL_C.PPCEABI.bare.H/wchar_io.c @@ -0,0 +1,22 @@ +#include "PowerPC_EABI_Support/Msl/MSL_C/MSL_Common/wchar_io.h" + +int fwide(FILE* file, int mode) +{ + if (file->file_mode.file_kind == __closed_file) { + return 0; + } + + switch (file->file_mode.file_orientation) { + case UNORIENTED: + if (mode > 0) { + file->file_mode.file_orientation = WIDE_ORIENTED; + } else if (mode < 0) { + file->file_mode.file_orientation = CHAR_ORIENTED; + } + return mode; + case WIDE_ORIENTED: + return 1; + case CHAR_ORIENTED: + return -1; + } +}