From c98c03de398e511a320cb9af9c3d3b545ce8372e Mon Sep 17 00:00:00 2001 From: Yanis <35189056+Yanis002@users.noreply.github.com> Date: Wed, 17 Dec 2025 14:08:53 +0100 Subject: [PATCH] Match MSL_C (#8) * match wstring.c * match math_api.c, mbstring.c, mem.c and mem_funcs.c * more progress * build issues * fix non-matching issues * reorganise files * match fdlibm (+ libc progress) * fix jp build * solved some non-matchings and progress * removed types.h usage in libc * match data and add missing delinks for jp --- config/eur/arm9/delinks.txt | 128 ++ config/eur/arm9/dtcm/symbols.txt | 2 +- config/eur/arm9/overlays/ov110/symbols.txt | 2 +- config/eur/arm9/relocs.txt | 2 +- config/eur/arm9/symbols.txt | 261 ++-- config/jp/arm9/delinks.txt | 128 ++ config/jp/arm9/dtcm/symbols.txt | 2 +- config/jp/arm9/relocs.txt | 2 +- config/jp/arm9/symbols.txt | 303 ++--- include/nitro/os/context.h | 15 + include/nitro/os/mutex.h | 20 + include/nitro/os/thread.h | 98 ++ include/types.h | 7 +- libs/c/include/abort_exit_arm_eabi.h | 19 + libs/c/include/ansi_files.h | 19 + libs/c/include/ansi_fp.h | 43 + libs/c/include/arith.h | 15 + libs/c/include/buffer_io.h | 18 + libs/c/include/console_io.h | 16 + libs/c/include/critical_regions.h | 49 + libs/c/include/ctype.h | 60 + libs/c/include/errno.h | 21 + libs/c/include/fdlibm.h | 62 + libs/c/include/file_io.h | 17 + libs/c/include/file_pos.h | 19 + libs/c/include/file_struc.h | 123 ++ libs/c/include/float.h | 29 + libs/c/include/limits.h | 37 + libs/c/include/locale.h | 76 ++ libs/c/include/math.h | 61 + libs/c/include/mbstring.h | 19 + libs/c/include/mem.h | 20 + libs/c/include/mem_funcs.h | 14 + libs/c/include/printf.h | 23 + libs/c/include/scanf.h | 17 + libs/c/include/secure_error.h | 16 + libs/c/include/signal.h | 18 + libs/c/include/stdarg.h | 22 + libs/c/include/stddef.h | 29 +- libs/c/include/stdio.h | 22 + libs/c/include/stdio_api.h | 53 + libs/c/include/string.h | 11 +- libs/c/include/wchar_io.h | 16 + libs/c/include/wstring.h | 19 + libs/c/src/abort_exit_arm_eabi.c | 51 + libs/c/src/ansi_files.c | 98 ++ libs/c/src/ansi_fp.c | 367 +++++ libs/c/src/arith.c | 9 + libs/c/src/buffer_io.c | 40 + libs/c/src/code_02038bac.c | 0 libs/c/src/extras.c | 11 + libs/c/src/file_io.c | 39 + libs/c/src/float.c | 1 + libs/c/src/locale.c | 43 + libs/c/src/math/e_log.c | 161 +++ libs/c/src/math/e_log10.c | 99 ++ libs/c/src/math/e_pow.c | 370 +++++ libs/c/src/math/s_ceil.c | 96 ++ libs/c/src/math/s_copysign.c | 31 + libs/c/src/math/s_fabs.c | 29 + libs/c/src/math/s_frexp.c | 59 + libs/c/src/math/s_ldexp.c | 66 + libs/c/src/math/w_log.c | 16 + libs/c/src/math/w_log10f.c | 16 + libs/c/src/math/w_pow.c | 16 + libs/c/src/math_api.c | 26 + libs/c/src/mbstring.c | 72 + libs/c/src/mem.c | 64 + libs/c/src/mem_funcs.c | 59 + libs/c/src/secure_error.c | 18 + libs/c/src/signal.c | 33 + libs/c/src/string.c | 197 +++ libs/c/src/wmem.c | 18 + libs/c/src/wprintf.c | 1408 ++++++++++++++++++++ libs/c/src/wstring.c | 53 + libs/runtime/include/MWException.h | 53 + tools/configure.py | 1 + tools/m2ctx.py | 3 +- 78 files changed, 5281 insertions(+), 295 deletions(-) create mode 100644 include/nitro/os/context.h create mode 100644 include/nitro/os/mutex.h create mode 100644 include/nitro/os/thread.h create mode 100644 libs/c/include/abort_exit_arm_eabi.h create mode 100644 libs/c/include/ansi_files.h create mode 100644 libs/c/include/ansi_fp.h create mode 100644 libs/c/include/arith.h create mode 100644 libs/c/include/buffer_io.h create mode 100644 libs/c/include/console_io.h create mode 100644 libs/c/include/critical_regions.h create mode 100644 libs/c/include/ctype.h create mode 100644 libs/c/include/errno.h create mode 100644 libs/c/include/fdlibm.h create mode 100644 libs/c/include/file_io.h create mode 100644 libs/c/include/file_pos.h create mode 100644 libs/c/include/file_struc.h create mode 100644 libs/c/include/float.h create mode 100644 libs/c/include/limits.h create mode 100644 libs/c/include/locale.h create mode 100644 libs/c/include/math.h create mode 100644 libs/c/include/mbstring.h create mode 100644 libs/c/include/mem.h create mode 100644 libs/c/include/mem_funcs.h create mode 100644 libs/c/include/printf.h create mode 100644 libs/c/include/scanf.h create mode 100644 libs/c/include/secure_error.h create mode 100644 libs/c/include/signal.h create mode 100644 libs/c/include/stdarg.h create mode 100644 libs/c/include/stdio.h create mode 100644 libs/c/include/stdio_api.h create mode 100644 libs/c/include/wchar_io.h create mode 100644 libs/c/include/wstring.h create mode 100644 libs/c/src/abort_exit_arm_eabi.c create mode 100644 libs/c/src/ansi_files.c create mode 100644 libs/c/src/ansi_fp.c create mode 100644 libs/c/src/arith.c create mode 100644 libs/c/src/buffer_io.c create mode 100644 libs/c/src/code_02038bac.c create mode 100644 libs/c/src/extras.c create mode 100644 libs/c/src/file_io.c create mode 100644 libs/c/src/float.c create mode 100644 libs/c/src/locale.c create mode 100644 libs/c/src/math/e_log.c create mode 100644 libs/c/src/math/e_log10.c create mode 100644 libs/c/src/math/e_pow.c create mode 100644 libs/c/src/math/s_ceil.c create mode 100644 libs/c/src/math/s_copysign.c create mode 100644 libs/c/src/math/s_fabs.c create mode 100644 libs/c/src/math/s_frexp.c create mode 100644 libs/c/src/math/s_ldexp.c create mode 100644 libs/c/src/math/w_log.c create mode 100644 libs/c/src/math/w_log10f.c create mode 100644 libs/c/src/math/w_pow.c create mode 100644 libs/c/src/math_api.c create mode 100644 libs/c/src/mbstring.c create mode 100644 libs/c/src/mem.c create mode 100644 libs/c/src/mem_funcs.c create mode 100644 libs/c/src/secure_error.c create mode 100644 libs/c/src/signal.c create mode 100644 libs/c/src/string.c create mode 100644 libs/c/src/wmem.c create mode 100644 libs/c/src/wprintf.c create mode 100644 libs/c/src/wstring.c create mode 100644 libs/runtime/include/MWException.h diff --git a/config/eur/arm9/delinks.txt b/config/eur/arm9/delinks.txt index ac106f9e..929f8889 100644 --- a/config/eur/arm9/delinks.txt +++ b/config/eur/arm9/delinks.txt @@ -20,3 +20,131 @@ libs/cpp/src/__register_global_object.c: src/Main/func_02017ea4.cpp: .text start:0x02017ea4 end:0x02017f38 + +libs/c/src/locale.c: + complete + .data start:0x02044790 end:0x020449ac + +libs/c/src/abort_exit_arm_eabi.c: + complete + .bss start:0x02051570 end:0x02051680 + .text start:0x020336e8 end:0x02033870 + +libs/c/src/ansi_files.c: + complete + .data start:0x020446a8 end:0x0204478c + .bss start:0x020517a0 end:0x02051aa0 + .text start:0x02033870 end:0x020338d4 + +libs/c/src/float.c: + complete + .data start:0x0204478c end:0x02044790 + +libs/c/src/arith.c: + complete + .text start:0x020338d4 end:0x020338ec + +libs/c/src/buffer_io.c: + complete + .text start:0x020338ec end:0x0203399c + +libs/c/src/file_io.c: + complete + .text start:0x0203399c end:0x02033a80 + +libs/c/src/math_api.c: + complete + .text start:0x02033b14 end:0x02033ba0 + +libs/c/src/mbstring.c: + complete + .text start:0x02033ba0 end:0x02033c90 + +libs/c/src/mem.c: + complete + .text start:0x02033c90 end:0x02033d7c + +libs/c/src/mem_funcs.c: + complete + .text start:0x02033d7c end:0x02033e28 + +libs/c/src/secure_error.c: + complete + .bss start:0x02051aa4 end:0x02051aa8 + .text start:0x02033e28 end:0x02033e54 + +libs/c/src/signal.c: + complete + .text start:0x02033e54 end:0x02033f7c + .bss start:0x02051aa8 end:0x02051ac4 + +libs/c/src/string.c: + complete + .text start:0x02033f7c end:0x020341f8 + +libs/c/src/wmem.c: + complete + .text start:0x020341f8 end:0x02034230 + +libs/c/src/wprintf.c: + .data start:0x020449ac end:0x02044a2c + .text start:0x02034230 end:0x0203615c + +libs/c/src/wstring.c: + complete + .text start:0x0203615c end:0x0203621c + +libs/c/src/ansi_fp.c: + .data start:0x02044a2c end:0x02044b00 + .text start:0x0203621c end:0x02036ba4 + +libs/c/src/extras.c: + complete + .text start:0x02036ba4 end:0x02036bd0 + +libs/c/src/math/e_log.c: + complete + .bss start:0x02051ac4 end:0x02051acc + .text start:0x02036bd0 end:0x02037300 + +libs/c/src/math/e_log10.c: + complete + .bss start:0x02051acc end:0x02051ad4 + .text start:0x02037300 end:0x020374d8 + +libs/c/src/math/e_pow.c: + complete + .rodata start:0x02043188 end:0x020431b8 + .text start:0x020374d8 end:0x02038660 + +libs/c/src/math/s_ceil.c: + complete + .text start:0x02038660 end:0x02038820 + +libs/c/src/math/s_copysign.c: + complete + .text start:0x02038820 end:0x02038848 + +libs/c/src/math/s_fabs.c: + complete + .text start:0x02038848 end:0x02038868 + +libs/c/src/math/s_frexp.c: + complete + .text start:0x02038868 end:0x02038928 + +libs/c/src/math/s_ldexp.c: + complete + .text start:0x02038928 end:0x02038b88 + +libs/c/src/math/w_log.c: + complete + .text start:0x02038b88 end:0x02038b94 + +libs/c/src/math/w_log10f.c: + complete + .text start:0x02038b94 end:0x02038ba0 + +libs/c/src/math/w_pow.c: + complete + .text start:0x02038ba0 end:0x02038bac diff --git a/config/eur/arm9/dtcm/symbols.txt b/config/eur/arm9/dtcm/symbols.txt index 79f949b6..8949fc00 100644 --- a/config/eur/arm9/dtcm/symbols.txt +++ b/config/eur/arm9/dtcm/symbols.txt @@ -61,7 +61,7 @@ data_027e0850 kind:bss addr:0x027e0850 data_027e0854 kind:bss addr:0x027e0854 data_027e0858 kind:bss addr:0x027e0858 data_027e085c kind:bss addr:0x027e085c -data_027e0860 kind:bss addr:0x027e0860 +ThreadInfo kind:bss addr:0x027e0860 data_027e0864 kind:bss addr:0x027e0864 data_027e0870 kind:bss addr:0x027e0870 data_027e08f0 kind:bss addr:0x027e08f0 diff --git a/config/eur/arm9/overlays/ov110/symbols.txt b/config/eur/arm9/overlays/ov110/symbols.txt index c88a7229..8e6c7332 100644 --- a/config/eur/arm9/overlays/ov110/symbols.txt +++ b/config/eur/arm9/overlays/ov110/symbols.txt @@ -21,4 +21,4 @@ data_ov110_021861e0 kind:data(any) addr:0x021861e0 data_ov110_021861ec kind:data(any) addr:0x021861ec _ZTV22UnkStruct_PlayerGet_74 kind:data(any) addr:0x021861f8 _ZTV9PlayerGet kind:data(any) addr:0x02186204 -data_ov110_02186240 kind:bss(size=0x3F68) addr:0x02186240 +data_ov110_02186240 kind:bss(size=0x3f68) addr:0x02186240 diff --git a/config/eur/arm9/relocs.txt b/config/eur/arm9/relocs.txt index 76198076..58576abb 100644 --- a/config/eur/arm9/relocs.txt +++ b/config/eur/arm9/relocs.txt @@ -5055,7 +5055,7 @@ from:0x02033e7c kind:arm_call to:0x020274f8 module:main from:0x02033edc kind:arm_call to:0x020273e0 module:main from:0x02033f28 kind:arm_call to:0x02027460 module:main from:0x02033f54 kind:arm_call to:0x02033710 module:main -from:0x02033f68 kind:load to:0x02051770 module:main +from:0x02033f68 kind:load to:0x020516c8 add:0xa8 module:main from:0x02033f6c kind:load to:0x027e0860 module:dtcm from:0x02033f70 kind:load to:0x02051680 module:main from:0x02033f74 kind:load to:0x020516a4 module:main diff --git a/config/eur/arm9/symbols.txt b/config/eur/arm9/symbols.txt index 4bb65375..2dce5e23 100644 --- a/config/eur/arm9/symbols.txt +++ b/config/eur/arm9/symbols.txt @@ -1475,8 +1475,8 @@ func_02026718 kind:function(arm,size=0x18) addr:0x02026718 func_02026730 kind:function(arm,size=0x8) addr:0x02026730 func_02026738 kind:function(arm,size=0x58) addr:0x02026738 func_02026790 kind:function(arm,size=0x30) addr:0x02026790 -func_020267c0 kind:function(arm,size=0x28) addr:0x020267c0 -func_020267e8 kind:function(arm,size=0x18) addr:0x020267e8 +sscanf kind:function(arm,size=0x28) addr:0x020267c0 +vsscanf kind:function(arm,size=0x18) addr:0x020267e8 func_02026800 kind:function(arm,size=0x28) addr:0x02026800 func_02026828 kind:function(arm,size=0xc) addr:0x02026828 func_02026834 kind:function(arm,size=0x18) addr:0x02026834 @@ -1518,10 +1518,10 @@ func_020271f8 kind:function(arm,size=0x94) addr:0x020271f8 func_0202728c kind:function(arm,size=0xa0) addr:0x0202728c func_0202732c kind:function(arm,size=0x9c) addr:0x0202732c OS_InitMutex kind:function(arm,size=0x18) addr:0x020273c8 -func_020273e0 kind:function(arm,size=0x80) addr:0x020273e0 -func_02027460 kind:function(arm,size=0x5c) addr:0x02027460 +OS_LockMutex kind:function(arm,size=0x80) addr:0x020273e0 +OS_UnlockMutex kind:function(arm,size=0x5c) addr:0x02027460 func_020274bc kind:function(arm,size=0x3c) addr:0x020274bc -func_020274f8 kind:function(arm,size=0x70) addr:0x020274f8 +OS_TryLockMutex kind:function(arm,size=0x70) addr:0x020274f8 func_02027568 kind:function(arm,size=0x24) addr:0x02027568 func_0202758c kind:function(arm,size=0x24) addr:0x0202758c func_020275b0 kind:function(arm,size=0xc) addr:0x020275b0 @@ -1954,75 +1954,74 @@ func_02032e08 kind:function(arm,size=0x54) addr:0x02032e08 func_02032e5c kind:function(arm,size=0x58) addr:0x02032e5c func_02032eb4 kind:function(arm,size=0x28) addr:0x02032eb4 func_02032edc kind:function(arm,size=0x80c) addr:0x02032edc -func_020336e8 kind:function(arm,size=0x28) addr:0x020336e8 -func_02033710 kind:function(arm,size=0x44) addr:0x02033710 -func_02033754 kind:function(arm,size=0x11c) addr:0x02033754 -func_02033870 kind:function(arm,size=0x64) addr:0x02033870 -func_020338d4 kind:function(arm,size=0xc) addr:0x020338d4 -func_020338e0 kind:function(arm,size=0xc) addr:0x020338e0 -func_020338ec kind:function(arm,size=0x4) addr:0x020338ec -func_020338f0 kind:function(arm,size=0x28) addr:0x020338f0 -func_02033918 kind:function(arm,size=0x84) addr:0x02033918 -func_0203399c kind:function(arm,size=0xe4) addr:0x0203399c +abort kind:function(arm,size=0x28) addr:0x020336e8 +exit kind:function(arm,size=0x44) addr:0x02033710 +__exit kind:function(arm,size=0x11c) addr:0x02033754 +__flush_all kind:function(arm,size=0x64) addr:0x02033870 +abs kind:function(arm,size=0xc) addr:0x020338d4 +labs kind:function(arm,size=0xc) addr:0x020338e0 +__convert_from_newlines kind:function(arm,size=0x4) addr:0x020338ec +__prep_buffer kind:function(arm,size=0x28) addr:0x020338f0 +__flush_buffer kind:function(arm,size=0x84) addr:0x02033918 +fflush kind:function(arm,size=0xe4) addr:0x0203399c func_02033a80 kind:function(arm,size=0x94) addr:0x02033a80 -func_02033b14 kind:function(arm,size=0x1c) addr:0x02033b14 -func_02033b30 kind:function(arm,size=0x70) addr:0x02033b30 -func_02033ba0 kind:function(arm,size=0x1c) addr:0x02033ba0 -func_02033bbc kind:function(arm,size=0x38) addr:0x02033bbc -func_02033bf4 kind:function(arm,size=0x14) addr:0x02033bf4 -func_02033c08 kind:function(arm,size=0x88) addr:0x02033c08 -func_02033c90 kind:function(arm,size=0x20) addr:0x02033c90 -func_02033cb0 kind:function(arm,size=0x4c) addr:0x02033cb0 -func_02033cfc kind:function(arm,size=0x14) addr:0x02033cfc -func_02033d10 kind:function(arm,size=0x2c) addr:0x02033d10 -func_02033d3c kind:function(arm,size=0x40) addr:0x02033d3c -func_02033d7c kind:function(arm,size=0xac) addr:0x02033d7c -func_02033e28 kind:function(arm,size=0x28) addr:0x02033e28 -func_02033e50 kind:function(arm,size=0x4) addr:0x02033e50 -func_02033e54 kind:function(arm,size=0x128) addr:0x02033e54 +__signbitd kind:function(arm,size=0x1c) addr:0x02033b14 +__fpclassifyd kind:function(arm,size=0x70) addr:0x02033b30 +mbtowc kind:function(arm,size=0x1c) addr:0x02033ba0 +__mbtowc_noconv kind:function(arm,size=0x38) addr:0x02033bbc +__wctomb_noconv kind:function(arm,size=0x14) addr:0x02033bf4 +mbstowcs kind:function(arm,size=0x88) addr:0x02033c08 +memcpy kind:function(arm,size=0x20) addr:0x02033c90 +memmove kind:function(arm,size=0x4c) addr:0x02033cb0 +memset kind:function(arm,size=0x14) addr:0x02033cfc +memchr kind:function(arm,size=0x2c) addr:0x02033d10 +memcmp kind:function(arm,size=0x40) addr:0x02033d3c +__fill_mem kind:function(arm,size=0xac) addr:0x02033d7c +__msl_runtime_constraint_violation_s kind:function(arm,size=0x28) addr:0x02033e28 +secure_error_func_02033e50 kind:function(arm,size=0x4) addr:0x02033e50 +raise kind:function(arm,size=0x128) addr:0x02033e54 strlen kind:function(arm,size=0x1c) addr:0x02033f7c -func_02033f98 kind:function(arm,size=0xc8) addr:0x02033f98 +strcpy kind:function(arm,size=0xc8) addr:0x02033f98 strncpy kind:function(arm,size=0x50) addr:0x02034060 -func_020340b0 kind:function(arm,size=0x114) addr:0x020340b0 -func_020341c4 kind:function(arm,size=0x34) addr:0x020341c4 -func_020341f8 kind:function(arm,size=0x10) addr:0x020341f8 -func_02034208 kind:function(arm,size=0x28) addr:0x02034208 -func_02034230 kind:function(arm,size=0x518) addr:0x02034230 -func_02034748 kind:function(arm,size=0x24c) addr:0x02034748 -func_02034994 kind:function(arm,size=0x2d8) addr:0x02034994 -func_02034c6c kind:function(arm,size=0x3c0) addr:0x02034c6c -func_0203502c kind:function(arm,size=0x114) addr:0x0203502c -func_02035140 kind:function(arm,size=0x5f8) addr:0x02035140 -func_02035738 kind:function(arm,size=0x95c) addr:0x02035738 -func_02036094 kind:function(arm,size=0x40) addr:0x02036094 -func_020360d4 kind:function(arm,size=0x28) addr:0x020360d4 -func_020360fc kind:function(arm,size=0x60) addr:0x020360fc -func_0203615c kind:function(arm,size=0x1c) addr:0x0203615c -func_02036178 kind:function(arm,size=0x20) addr:0x02036178 -func_02036198 kind:function(arm,size=0x50) addr:0x02036198 -func_020361e8 kind:function(arm,size=0x34) addr:0x020361e8 -func_0203621c kind:function(arm,size=0x6c) addr:0x0203621c -func_02036288 kind:function(arm,size=0x4c) addr:0x02036288 -func_020362d4 kind:function(arm,size=0x4) addr:0x020362d4 -func_020362d8 kind:function(arm,size=0x40) addr:0x020362d8 -func_02036318 kind:function(arm,size=0xc4) addr:0x02036318 -func_020363dc kind:function(arm,size=0x180) addr:0x020363dc -func_0203655c kind:function(arm,size=0x9c) addr:0x0203655c -func_020365f8 kind:function(arm,size=0x380) addr:0x020365f8 -func_02036978 kind:function(arm,size=0x180) addr:0x02036978 -func_02036af8 kind:function(arm,size=0xac) addr:0x02036af8 -func_02036ba4 kind:function(arm,size=0x2c) addr:0x02036ba4 -func_02036bd0 kind:function(arm,size=0x730) addr:0x02036bd0 -func_02037300 kind:function(arm,size=0x1d8) addr:0x02037300 -func_020374d8 kind:function(arm,size=0x1188) addr:0x020374d8 -func_02038660 kind:function(arm,size=0x1c0) addr:0x02038660 -func_02038820 kind:function(arm,size=0x28) addr:0x02038820 -func_02038848 kind:function(arm,size=0x20) addr:0x02038848 -func_02038868 kind:function(arm,size=0xc0) addr:0x02038868 -func_02038928 kind:function(arm,size=0x260) addr:0x02038928 -func_02038b88 kind:function(arm,size=0xc) addr:0x02038b88 -func_02038b94 kind:function(arm,size=0xc) addr:0x02038b94 -func_02038ba0 kind:function(arm,size=0xc) addr:0x02038ba0 +strcmp kind:function(arm,size=0x114) addr:0x020340b0 +strncmp kind:function(arm,size=0x34) addr:0x020341c4 +wmemcpy kind:function(arm,size=0x10) addr:0x020341f8 +wmemchr kind:function(arm,size=0x28) addr:0x02034208 +parse_format kind:function(arm,size=0x518) addr:0x02034230 +long2str kind:function(arm,size=0x24c) addr:0x02034748 +longlong2str kind:function(arm,size=0x2d8) addr:0x02034994 +double2hex kind:function(arm,size=0x3c0) addr:0x02034c6c +round_decimal kind:function(arm,size=0x114) addr:0x0203502c +float2str kind:function(arm,size=0x5f8) addr:0x02035140 +__wpformatter kind:function(arm,size=0x95c) addr:0x02035738 +__wStringWrite kind:function(arm,size=0x40) addr:0x02036094 +swprintf kind:function(arm,size=0x28) addr:0x020360d4 +vswprintf kind:function(arm,size=0x60) addr:0x020360fc +wcslen kind:function(arm,size=0x1c) addr:0x0203615c +wcscpy kind:function(arm,size=0x20) addr:0x02036178 +wcsncpy kind:function(arm,size=0x50) addr:0x02036198 +wcschr kind:function(arm,size=0x34) addr:0x020361e8 +__must_round kind:function(arm,size=0x6c) addr:0x0203621c +__dorounddecup kind:function(arm,size=0x50) addr:0x02036288 +__rounddec kind:function(arm,size=0x40) addr:0x020362d8 +__ull2dec kind:function(arm,size=0xc4) addr:0x02036318 +__timesdec kind:function(arm,size=0x180) addr:0x020363dc +__str2dec kind:function(arm,size=0x9c) addr:0x0203655c +__two_exp kind:function(arm,size=0x380) addr:0x020365f8 +__num2dec_internal kind:function(arm,size=0x180) addr:0x02036978 +__num2dec kind:function(arm,size=0xac) addr:0x02036af8 +scalbn kind:function(arm,size=0x2c) addr:0x02036ba4 +__ieee754_log kind:function(arm,size=0x730) addr:0x02036bd0 +__ieee754_log10 kind:function(arm,size=0x1d8) addr:0x02037300 +__ieee754_pow kind:function(arm,size=0x1188) addr:0x020374d8 +ceil kind:function(arm,size=0x1c0) addr:0x02038660 +copysign kind:function(arm,size=0x28) addr:0x02038820 +fabs kind:function(arm,size=0x20) addr:0x02038848 +frexp kind:function(arm,size=0xc0) addr:0x02038868 +ldexp kind:function(arm,size=0x260) addr:0x02038928 +log kind:function(arm,size=0xc) addr:0x02038b88 +log10f kind:function(arm,size=0xc) addr:0x02038b94 +pow kind:function(arm,size=0xc) addr:0x02038ba0 func_02038bac kind:function(arm,size=0x78) addr:0x02038bac func_02038c24 kind:function(arm,size=0x28) addr:0x02038c24 func_02038c4c kind:function(arm,size=0x10) addr:0x02038c4c @@ -2041,73 +2040,73 @@ func_02038d44 kind:function(arm,size=0x20) addr:0x02038d44 func_02038d64 kind:function(arm,size=0x30) addr:0x02038d64 func_02038d94 kind:function(arm,size=0x2c) addr:0x02038d94 func_02038dc0 kind:function(arm,size=0x8c) addr:0x02038dc0 -func_02038e4c kind:function(arm,size=0x318) addr:0x02038e4c -func_0203917c kind:function(arm,size=0x3b4) addr:0x0203917c +_dadd kind:function(arm,size=0x318) addr:0x02038e4c +_dsub kind:function(arm,size=0x3b4) addr:0x0203917c _dmul kind:function(arm,size=0x364) addr:0x02039530 _fflt kind:function(arm,size=0x104) addr:0x02039894 _dflt kind:function(arm,size=0x40) addr:0x02039998 func_020399d8 kind:function(arm,size=0x3c) addr:0x020399d8 -func_02039a14 kind:function(arm,size=0x98) addr:0x02039a14 -func_02039aac kind:function(arm,size=0xa4) addr:0x02039aac -func_02039b50 kind:function(arm,size=0x9c) addr:0x02039b50 -func_02039bec kind:function(arm,size=0x8c) addr:0x02039bec -func_02039c78 kind:function(arm,size=0x8c) addr:0x02039c78 +_dgr kind:function(arm,size=0x98) addr:0x02039a14 +_dleq kind:function(arm,size=0xa4) addr:0x02039aac +_dls kind:function(arm,size=0x9c) addr:0x02039b50 +_deq kind:function(arm,size=0x8c) addr:0x02039bec +_dneq kind:function(arm,size=0x8c) addr:0x02039c78 func_02039d04 kind:function(arm,size=0x5c) addr:0x02039d04 func_02039d60 kind:function(arm,size=0x5c) addr:0x02039d60 func_02039dbc kind:function(arm,size=0x5c) addr:0x02039dbc func_02039e18 kind:function(arm,size=0x68) addr:0x02039e18 -func_02039e80 kind:function(arm,size=0x84) addr:0x02039e80 +_f2d kind:function(arm,size=0x84) addr:0x02039e80 func_02039f04 kind:function(arm,size=0x48) addr:0x02039f04 func_02039f4c kind:function(arm,size=0x48) addr:0x02039f4c func_02039f94 kind:function(arm,size=0x10) addr:0x02039f94 func_02039fa4 kind:function(arm,size=0x1b0) addr:0x02039fa4 _ll_udiv kind:function(arm,size=0xc) addr:0x0203a154 -func_0203a160 kind:function(arm,size=0x3c) addr:0x0203a160 +_ull_mod kind:function(arm,size=0x3c) addr:0x0203a160 func_0203a19c kind:function(arm,size=0x20) addr:0x0203a19c _s32_div_f kind:function(arm,size=0x20c) addr:0x0203a1bc _u32_div_f kind:function(arm,size=0x1e4) addr:0x0203a3c8 .L_0203a3d0 kind:label(arm) addr:0x0203a3d0 -func_0203a5ac kind:function(arm,size=0x34) addr:0x0203a5ac -func_0203a5e0 kind:function(arm,size=0x40) addr:0x0203a5e0 +_ffix kind:function(arm,size=0x34) addr:0x0203a5ac +_ffixu kind:function(arm,size=0x40) addr:0x0203a5e0 func_0203a620 kind:function(arm,size=0x4c) addr:0x0203a620 -func_0203a66c kind:function(arm,size=0x8c) addr:0x0203a66c -func_0203a6f8 kind:function(arm,size=0x19c) addr:0x0203a6f8 +_ll_ufrom_d kind:function(arm,size=0x8c) addr:0x0203a66c +sqrt kind:function(arm,size=0x19c) addr:0x0203a6f8 func_0203a894 kind:function(arm,size=0xe4) addr:0x0203a894 -func_0203a978 kind:function(arm,size=0x1e0) addr:0x0203a978 +_fmul kind:function(arm,size=0x1e0) addr:0x0203a978 func_0203ab58 kind:function(arm,size=0x21c) addr:0x0203ab58 func_0203ad74 kind:function(arm,size=0x8) addr:0x0203ad74 func_0203ad88 kind:function(arm,size=0x278) addr:0x0203ad88 -func_0203b00c kind:function(arm,size=0x3b8) addr:0x0203b00c +_fdiv kind:function(arm,size=0x3b8) addr:0x0203b00c _ddiv kind:function(arm,size=0x544) addr:0x0203b3dc func_0203b920 kind:function(arm,size=0x4) addr:0x0203b920 -func_0203b924 kind:function(arm,size=0xc) addr:0x0203b924 +_ExitProcess kind:function(arm,size=0xc) addr:0x0203b924 func_0203b930 kind:function(arm,size=0x4) addr:0x0203b930 func_0203b934 kind:function(arm,size=0x4) addr:0x0203b934 -func_0203b938 kind:function(arm,size=0x8) addr:0x0203b938 +sys_ReadChar kind:function(arm,size=0x8) addr:0x0203b938 func_0203b940 kind:function(arm,size=0x4) addr:0x0203b940 -func_0203b944 kind:function(arm,size=0x50) addr:0x0203b944 -func_0203b994 kind:function(arm,size=0x44) addr:0x0203b994 -func_0203b9d8 kind:function(arm,size=0x8) addr:0x0203b9d8 +__read_console kind:function(arm,size=0x50) addr:0x0203b944 +__write_console kind:function(arm,size=0x44) addr:0x0203b994 +__close_console kind:function(arm,size=0x8) addr:0x0203b9d8 func_0203b9e0 kind:function(arm,size=0x84) addr:0x0203b9e0 func_0203ba64 kind:function(arm,size=0x84) addr:0x0203ba64 -func_0203bae8 kind:function(arm,size=0x64) addr:0x0203bae8 +_Z12BinarySearchP19ExceptionTableIndexmPc kind:function(arm,size=0x64) addr:0x0203bae8 func_0203bb4c kind:function(arm,size=0x108) addr:0x0203bb4c -func_0203bc54 kind:function(arm,size=0x1c) addr:0x0203bc54 +_Z13CurrentActionPK14ActionIterator kind:function(arm,size=0x1c) addr:0x0203bc54 func_0203bc70 kind:function(arm,size=0x2bc) addr:0x0203bc70 -func_0203bf2c kind:function(arm,size=0x82c) addr:0x0203bf2c +_Z11UnwindStackP12ThrowContextP13ExceptionInfoPc kind:function(arm,size=0x82c) addr:0x0203bf2c func_0203c758 kind:function(arm,size=0x8) addr:0x0203c758 func_0203c760 kind:function(arm,size=0x154) addr:0x0203c760 func_0203c8b4 kind:function(arm,size=0x80) addr:0x0203c8b4 func_0203c934 kind:function(arm,size=0xac) addr:0x0203c934 func_0203c9e0 kind:function(arm,size=0x4) addr:0x0203c9e0 -func_0203c9e4 kind:function(arm,size=0x60) addr:0x0203c9e4 +_Z16HandleUnexpectedP12ThrowContextP13ExceptionInfoP16ex_specificationPc kind:function(arm,size=0x60) addr:0x0203c9e4 func_0203ca44 kind:function(arm,size=0x1dc) addr:0x0203ca44 -func_0203cc20 kind:function(arm,size=0x5c) addr:0x0203cc20 +_Z14SetupCatchInfoP12ThrowContextll kind:function(arm,size=0x5c) addr:0x0203cc20 func_0203cc7c kind:function(arm,size=0xf4) addr:0x0203cc7c func_0203cd70 kind:function(arm,size=0x28) addr:0x0203cd70 func_0203cd98 kind:function(arm,size=0x14) addr:0x0203cd98 func_0203cdac kind:function(arm,size=0xc) addr:0x0203cdac -CallStaticInitializers kind:function(arm,size=0x30) addr:0x0203cdb8 +_Z26__call_static_initializersv kind:function(arm,size=0x30) addr:0x0203cdb8 __destroy_global_chain kind:function(arm,size=0x44) addr:0x0203cde8 func_0203ce2c kind:function(arm,size=0xc) addr:0x0203ce2c func_0203ce38 kind:function(arm,size=0xc) addr:0x0203ce38 @@ -2293,10 +2292,10 @@ data_02042cfc kind:data(any) addr:0x02042cfc data_02042fd0 kind:data(any) addr:0x02042fd0 data_02042ff4 kind:data(any) addr:0x02042ff4 data_02043034 kind:data(any) addr:0x02043034 -data_02043088 kind:data(any) addr:0x02043088 -data_02043188 kind:data(any) addr:0x02043188 -data_02043198 kind:data(any) addr:0x02043198 -data_020431a8 kind:data(any) addr:0x020431a8 +__ctype_mapC kind:data(any) addr:0x02043088 +dp_h kind:data(any) addr:0x02043188 local +bp kind:data(any) addr:0x02043198 local +dp_l kind:data(any) addr:0x020431a8 local data_020431b8 kind:data(any) addr:0x020431b8 .p__sinit_0203d824 kind:data(word) addr:0x020431c0 .p__sinit_0203d840 kind:data(word) addr:0x020431c4 @@ -2591,21 +2590,21 @@ data_0204462c kind:data(any) addr:0x0204462c data_02044670 kind:data(any) addr:0x02044670 data_02044674 kind:data(any) addr:0x02044674 data_020446a4 kind:data(any) addr:0x020446a4 -data_020446a8 kind:data(any) addr:0x020446a8 -data_0204478c kind:data(any) addr:0x0204478c -data_02044790 kind:data(any) addr:0x02044790 -data_02044794 kind:data(any) addr:0x02044794 -data_02044798 kind:data(any) addr:0x02044798 -data_020447a0 kind:data(any) addr:0x020447a0 -data_020447a8 kind:data(any) addr:0x020447a8 -data_020447b8 kind:data(any) addr:0x020447b8 -data_020447d8 kind:data(any) addr:0x020447d8 -data_020447e4 kind:data(any) addr:0x020447e4 -data_020447f0 kind:data(any) addr:0x020447f0 -data_020447fc kind:data(any) addr:0x020447fc -data_0204480c kind:data(any) addr:0x0204480c -data_02044864 kind:data(any) addr:0x02044864 -data_020448ec kind:data(any) addr:0x020448ec +__files kind:data(any) addr:0x020446a8 +__float_nan kind:data(any) addr:0x0204478c +@19 kind:data(any) addr:0x02044790 local +@16 kind:data(any) addr:0x02044794 local +@12 kind:data(any) addr:0x02044798 local +__ctype_cmpt kind:data(any) addr:0x020447a0 +__coll_cmpt kind:data(any) addr:0x020447a8 +__time_cmpt kind:data(any) addr:0x020447b8 +@15 kind:data(any) addr:0x020447d8 local +_current_locale kind:data(any) addr:0x020447e4 +@14 kind:data(any) addr:0x020447f0 local +@13 kind:data(any) addr:0x020447fc local +@17 kind:data(any) addr:0x0204480c local +@18 kind:data(any) addr:0x02044864 local +char_coll_table kind:data(any) addr:0x020448ec data_020449ac kind:data(any) addr:0x020449ac data_020449b8 kind:data(any) addr:0x020449b8 data_020449c4 kind:data(any) addr:0x020449c4 @@ -2864,18 +2863,20 @@ data_02050fa4 kind:bss addr:0x02050fa4 data_02051060 kind:bss addr:0x02051060 data_02051148 kind:bss addr:0x02051148 data_0205114c kind:bss addr:0x0205114c -data_02051570 kind:bss addr:0x02051570 -data_02051580 kind:bss addr:0x02051580 -data_02051680 kind:bss addr:0x02051680 -data_020516a4 kind:bss addr:0x020516a4 -data_020516c8 kind:bss addr:0x020516c8 -data_02051770 kind:bss addr:0x02051770 -data_020517a0 kind:bss addr:0x020517a0 -data_020518a0 kind:bss addr:0x020518a0 -data_020519a0 kind:bss addr:0x020519a0 -data_02051aa0 kind:bss addr:0x02051aa0 -data_02051aa4 kind:bss addr:0x02051aa4 -data_02051aa8 kind:bss addr:0x02051aa8 -data_02051ac4 kind:bss addr:0x02051ac4 -data_02051acc kind:bss addr:0x02051acc +__console_exit kind:bss addr:0x02051570 +__stdio_exit kind:bss addr:0x02051574 +__atexit_curr_func kind:bss addr:0x02051578 local +__aborting kind:bss addr:0x0205157c +__atexit_funcs kind:bss addr:0x02051580 local +__cs_id kind:bss addr:0x02051680 +__cs_ref kind:bss addr:0x020516a4 +__cs kind:bss addr:0x020516c8 +stderr_buff kind:bss addr:0x020517a0 local +stdout_buff kind:bss addr:0x020518a0 local +stdin_buff kind:bss addr:0x020519a0 local +errno kind:bss addr:0x02051aa0 +__msl_constraint_handler kind:bss addr:0x02051aa4 +signal_funcs kind:bss addr:0x02051aa8 +zero kind:bss addr:0x02051ac4 local +zero kind:bss addr:0x02051acc local __global_destructor_chain kind:bss(size=0x4) addr:0x02051ad4 diff --git a/config/jp/arm9/delinks.txt b/config/jp/arm9/delinks.txt index 9788af52..2745502c 100644 --- a/config/jp/arm9/delinks.txt +++ b/config/jp/arm9/delinks.txt @@ -20,3 +20,131 @@ libs/cpp/src/__register_global_object.c: src/Main/func_02017ea4.cpp: .text start:0x02017e3c end:0x02017ed0 + +libs/c/src/locale.c: + complete + .data start:0x02045d04 end:0x02045f20 + +libs/c/src/abort_exit_arm_eabi.c: + complete + .text start:0x02034c18 end:0x02034da0 + .bss start:0x02052af0 end:0x02052c00 + +libs/c/src/ansi_files.c: + complete + .bss start:0x02052d20 end:0x02053020 + .data start:0x02045c1c end:0x02045d00 + .text start:0x02034da0 end:0x02034e04 + +libs/c/src/float.c: + complete + .data start:0x02045d00 end:0x02045d04 + +libs/c/src/arith.c: + complete + .text start:0x02034e04 end:0x02034e1c + +libs/c/src/buffer_io.c: + complete + .text start:0x02034e1c end:0x02034ecc + +libs/c/src/file_io.c: + complete + .text start:0x02034ecc end:0x02034fb0 + +libs/c/src/math_api.c: + complete + .text start:0x02035044 end:0x020350d0 + +libs/c/src/mbstring.c: + complete + .text start:0x020350d0 end:0x020351c0 + +libs/c/src/mem.c: + complete + .text start:0x020351c0 end:0x020352ac + +libs/c/src/mem_funcs.c: + complete + .text start:0x020352ac end:0x02035358 + +libs/c/src/secure_error.c: + complete + .bss start:0x02053024 end:0x02053028 + .text start:0x02035358 end:0x02035384 + +libs/c/src/signal.c: + complete + .text start:0x02035384 end:0x020354ac + .bss start:0x02053028 end:0x02053044 + +libs/c/src/string.c: + complete + .text start:0x020354ac end:0x02035728 + +libs/c/src/wmem.c: + complete + .text start:0x02035728 end:0x02035760 + +libs/c/src/wprintf.c: + .data start:0x02045f20 end:0x02045fa0 + .text start:0x02035760 end:0x0203768c + +libs/c/src/wstring.c: + complete + .text start:0x0203768c end:0x0203774c + +libs/c/src/ansi_fp.c: + .data start:0x02045fa0 end:0x02046074 + .text start:0x0203774c end:0x020380d4 + +libs/c/src/extras.c: + complete + .text start:0x020380d4 end:0x02038100 + +libs/c/src/math/e_log.c: + complete + .bss start:0x02053044 end:0x0205304c + .text start:0x02038100 end:0x02038830 + +libs/c/src/math/e_log10.c: + complete + .bss start:0x0205304c end:0x02053054 + .text start:0x02038830 end:0x02038a08 + +libs/c/src/math/e_pow.c: + complete + .rodata start:0x020446d4 end:0x02044704 + .text start:0x02038a08 end:0x02039b90 + +libs/c/src/math/s_ceil.c: + complete + .text start:0x02039b90 end:0x02039d50 + +libs/c/src/math/s_copysign.c: + complete + .text start:0x02039d50 end:0x02039d78 + +libs/c/src/math/s_fabs.c: + complete + .text start:0x02039d78 end:0x02039d98 + +libs/c/src/math/s_frexp.c: + complete + .text start:0x02039d98 end:0x02039e58 + +libs/c/src/math/s_ldexp.c: + complete + .text start:0x02039e58 end:0x0203a0b8 + +libs/c/src/math/w_log.c: + complete + .text start:0x0203a0b8 end:0x0203a0c4 + +libs/c/src/math/w_log10f.c: + complete + .text start:0x0203a0c4 end:0x0203a0d0 + +libs/c/src/math/w_pow.c: + complete + .text start:0x0203a0d0 end:0x0203a0dc diff --git a/config/jp/arm9/dtcm/symbols.txt b/config/jp/arm9/dtcm/symbols.txt index 79f949b6..8949fc00 100644 --- a/config/jp/arm9/dtcm/symbols.txt +++ b/config/jp/arm9/dtcm/symbols.txt @@ -61,7 +61,7 @@ data_027e0850 kind:bss addr:0x027e0850 data_027e0854 kind:bss addr:0x027e0854 data_027e0858 kind:bss addr:0x027e0858 data_027e085c kind:bss addr:0x027e085c -data_027e0860 kind:bss addr:0x027e0860 +ThreadInfo kind:bss addr:0x027e0860 data_027e0864 kind:bss addr:0x027e0864 data_027e0870 kind:bss addr:0x027e0870 data_027e08f0 kind:bss addr:0x027e08f0 diff --git a/config/jp/arm9/relocs.txt b/config/jp/arm9/relocs.txt index 31739887..a9a95ebb 100644 --- a/config/jp/arm9/relocs.txt +++ b/config/jp/arm9/relocs.txt @@ -5169,7 +5169,7 @@ from:0x020353ac kind:arm_call to:0x02028a28 module:main from:0x0203540c kind:arm_call to:0x02028910 module:main from:0x02035458 kind:arm_call to:0x02028990 module:main from:0x02035484 kind:arm_call to:0x02034c40 module:main -from:0x02035498 kind:load to:0x02052cf0 module:main +from:0x02035498 kind:load to:0x02052c48 add:0xA8 module:main from:0x0203549c kind:load to:0x027e0860 module:dtcm from:0x020354a0 kind:load to:0x02052c00 module:main from:0x020354a4 kind:load to:0x02052c24 module:main diff --git a/config/jp/arm9/symbols.txt b/config/jp/arm9/symbols.txt index aa0cb357..de81e0bd 100644 --- a/config/jp/arm9/symbols.txt +++ b/config/jp/arm9/symbols.txt @@ -1496,8 +1496,8 @@ func_02027c48 kind:function(arm,size=0x18) addr:0x02027c48 func_02027c60 kind:function(arm,size=0x8) addr:0x02027c60 func_02027c68 kind:function(arm,size=0x58) addr:0x02027c68 func_02027cc0 kind:function(arm,size=0x30) addr:0x02027cc0 -func_02027cf0 kind:function(arm,size=0x28) addr:0x02027cf0 -func_02027d18 kind:function(arm,size=0x18) addr:0x02027d18 +sscanf kind:function(arm,size=0x28) addr:0x02027cf0 +vsscanf kind:function(arm,size=0x18) addr:0x02027d18 func_02027d30 kind:function(arm,size=0x28) addr:0x02027d30 func_02027d58 kind:function(arm,size=0xc) addr:0x02027d58 func_02027d64 kind:function(arm,size=0x18) addr:0x02027d64 @@ -1539,10 +1539,10 @@ func_02028728 kind:function(arm,size=0x94) addr:0x02028728 func_020287bc kind:function(arm,size=0xa0) addr:0x020287bc func_0202885c kind:function(arm,size=0x9c) addr:0x0202885c OS_InitMutex kind:function(arm,size=0x18) addr:0x020288f8 -func_02028910 kind:function(arm,size=0x80) addr:0x02028910 -func_02028990 kind:function(arm,size=0x5c) addr:0x02028990 +OS_LockMutex kind:function(arm,size=0x80) addr:0x02028910 +OS_UnlockMutex kind:function(arm,size=0x5c) addr:0x02028990 func_020289ec kind:function(arm,size=0x3c) addr:0x020289ec -func_02028a28 kind:function(arm,size=0x70) addr:0x02028a28 +OS_TryLockMutex kind:function(arm,size=0x70) addr:0x02028a28 func_02028a98 kind:function(arm,size=0x24) addr:0x02028a98 func_02028abc kind:function(arm,size=0x24) addr:0x02028abc func_02028ae0 kind:function(arm,size=0xc) addr:0x02028ae0 @@ -1975,75 +1975,74 @@ func_02034338 kind:function(arm,size=0x54) addr:0x02034338 func_0203438c kind:function(arm,size=0x58) addr:0x0203438c func_020343e4 kind:function(arm,size=0x28) addr:0x020343e4 func_0203440c kind:function(arm,size=0x80c) addr:0x0203440c -func_02034c18 kind:function(arm,size=0x28) addr:0x02034c18 -func_02034c40 kind:function(arm,size=0x44) addr:0x02034c40 -func_02034c84 kind:function(arm,size=0x11c) addr:0x02034c84 -func_02034da0 kind:function(arm,size=0x64) addr:0x02034da0 -func_02034e04 kind:function(arm,size=0xc) addr:0x02034e04 -func_02034e10 kind:function(arm,size=0xc) addr:0x02034e10 -func_02034e1c kind:function(arm,size=0x4) addr:0x02034e1c -func_02034e20 kind:function(arm,size=0x28) addr:0x02034e20 -func_02034e48 kind:function(arm,size=0x84) addr:0x02034e48 -func_02034ecc kind:function(arm,size=0xe4) addr:0x02034ecc +abort kind:function(arm,size=0x28) addr:0x02034c18 +exit kind:function(arm,size=0x44) addr:0x02034c40 +__exit kind:function(arm,size=0x11c) addr:0x02034c84 +__flush_all kind:function(arm,size=0x64) addr:0x02034da0 +abs kind:function(arm,size=0xc) addr:0x02034e04 +labs kind:function(arm,size=0xc) addr:0x02034e10 +__convert_from_newlines kind:function(arm,size=0x4) addr:0x02034e1c +__prep_buffer kind:function(arm,size=0x28) addr:0x02034e20 +__flush_buffer kind:function(arm,size=0x84) addr:0x02034e48 +fflush kind:function(arm,size=0xe4) addr:0x02034ecc func_02034fb0 kind:function(arm,size=0x94) addr:0x02034fb0 -func_02035044 kind:function(arm,size=0x1c) addr:0x02035044 -func_02035060 kind:function(arm,size=0x70) addr:0x02035060 -func_020350d0 kind:function(arm,size=0x1c) addr:0x020350d0 -func_020350ec kind:function(arm,size=0x38) addr:0x020350ec -func_02035124 kind:function(arm,size=0x14) addr:0x02035124 -func_02035138 kind:function(arm,size=0x88) addr:0x02035138 -func_020351c0 kind:function(arm,size=0x20) addr:0x020351c0 -func_020351e0 kind:function(arm,size=0x4c) addr:0x020351e0 -func_0203522c kind:function(arm,size=0x14) addr:0x0203522c -func_02035240 kind:function(arm,size=0x2c) addr:0x02035240 -func_0203526c kind:function(arm,size=0x40) addr:0x0203526c -func_020352ac kind:function(arm,size=0xac) addr:0x020352ac -func_02035358 kind:function(arm,size=0x28) addr:0x02035358 -func_02035380 kind:function(arm,size=0x4) addr:0x02035380 -func_02035384 kind:function(arm,size=0x128) addr:0x02035384 +__signbitd kind:function(arm,size=0x1c) addr:0x02035044 +__fpclassifyd kind:function(arm,size=0x70) addr:0x02035060 +mbtowc kind:function(arm,size=0x1c) addr:0x020350d0 +__mbtowc_noconv kind:function(arm,size=0x38) addr:0x020350ec +__wctomb_noconv kind:function(arm,size=0x14) addr:0x02035124 +mbstowcs kind:function(arm,size=0x88) addr:0x02035138 +memcpy kind:function(arm,size=0x20) addr:0x020351c0 +memmove kind:function(arm,size=0x4c) addr:0x020351e0 +memset kind:function(arm,size=0x14) addr:0x0203522c +memchr kind:function(arm,size=0x2c) addr:0x02035240 +memcmp kind:function(arm,size=0x40) addr:0x0203526c +__fill_mem kind:function(arm,size=0xac) addr:0x020352ac +__msl_runtime_constraint_violation_s kind:function(arm,size=0x28) addr:0x02035358 +secure_error_func_02033e50 kind:function(arm,size=0x4) addr:0x02035380 +raise kind:function(arm,size=0x128) addr:0x02035384 strlen kind:function(arm,size=0x1c) addr:0x020354ac -func_020354c8 kind:function(arm,size=0xc8) addr:0x020354c8 +strcpy kind:function(arm,size=0xc8) addr:0x020354c8 strncpy kind:function(arm,size=0x50) addr:0x02035590 -func_020355e0 kind:function(arm,size=0x114) addr:0x020355e0 -func_020356f4 kind:function(arm,size=0x34) addr:0x020356f4 -func_02035728 kind:function(arm,size=0x10) addr:0x02035728 -func_02035738 kind:function(arm,size=0x28) addr:0x02035738 -func_02035760 kind:function(arm,size=0x518) addr:0x02035760 -func_02035c78 kind:function(arm,size=0x24c) addr:0x02035c78 -func_02035ec4 kind:function(arm,size=0x2d8) addr:0x02035ec4 -func_0203619c kind:function(arm,size=0x3c0) addr:0x0203619c -func_0203655c kind:function(arm,size=0x114) addr:0x0203655c -func_02036670 kind:function(arm,size=0x5f8) addr:0x02036670 -func_02036c68 kind:function(arm,size=0x95c) addr:0x02036c68 -func_020375c4 kind:function(arm,size=0x40) addr:0x020375c4 -func_02037604 kind:function(arm,size=0x28) addr:0x02037604 -func_0203762c kind:function(arm,size=0x60) addr:0x0203762c -func_0203768c kind:function(arm,size=0x1c) addr:0x0203768c -func_020376a8 kind:function(arm,size=0x20) addr:0x020376a8 -func_020376c8 kind:function(arm,size=0x50) addr:0x020376c8 -func_02037718 kind:function(arm,size=0x34) addr:0x02037718 -func_0203774c kind:function(arm,size=0x6c) addr:0x0203774c -func_020377b8 kind:function(arm,size=0x4c) addr:0x020377b8 -func_02037804 kind:function(arm,size=0x4) addr:0x02037804 -func_02037808 kind:function(arm,size=0x40) addr:0x02037808 -func_02037848 kind:function(arm,size=0xc4) addr:0x02037848 -func_0203790c kind:function(arm,size=0x180) addr:0x0203790c -func_02037a8c kind:function(arm,size=0x9c) addr:0x02037a8c -func_02037b28 kind:function(arm,size=0x380) addr:0x02037b28 -func_02037ea8 kind:function(arm,size=0x180) addr:0x02037ea8 -func_02038028 kind:function(arm,size=0xac) addr:0x02038028 -func_020380d4 kind:function(arm,size=0x2c) addr:0x020380d4 -func_02038100 kind:function(arm,size=0x730) addr:0x02038100 -func_02038830 kind:function(arm,size=0x1d8) addr:0x02038830 -func_02038a08 kind:function(arm,size=0x1188) addr:0x02038a08 -func_02039b90 kind:function(arm,size=0x1c0) addr:0x02039b90 -func_02039d50 kind:function(arm,size=0x28) addr:0x02039d50 -func_02039d78 kind:function(arm,size=0x20) addr:0x02039d78 -func_02039d98 kind:function(arm,size=0xc0) addr:0x02039d98 -func_02039e58 kind:function(arm,size=0x260) addr:0x02039e58 -func_0203a0b8 kind:function(arm,size=0xc) addr:0x0203a0b8 -func_0203a0c4 kind:function(arm,size=0xc) addr:0x0203a0c4 -func_0203a0d0 kind:function(arm,size=0xc) addr:0x0203a0d0 +strcmp kind:function(arm,size=0x114) addr:0x020355e0 +strncmp kind:function(arm,size=0x34) addr:0x020356f4 +wmemcpy kind:function(arm,size=0x10) addr:0x02035728 +wmemchr kind:function(arm,size=0x28) addr:0x02035738 +parse_format kind:function(arm,size=0x518) addr:0x02035760 +long2str kind:function(arm,size=0x24c) addr:0x02035c78 +longlong2str kind:function(arm,size=0x2d8) addr:0x02035ec4 +double2hex kind:function(arm,size=0x3c0) addr:0x0203619c +round_decimal kind:function(arm,size=0x114) addr:0x0203655c +float2str kind:function(arm,size=0x5f8) addr:0x02036670 +__wpformatter kind:function(arm,size=0x95c) addr:0x02036c68 +__wStringWrite kind:function(arm,size=0x40) addr:0x020375c4 +swprintf kind:function(arm,size=0x28) addr:0x02037604 +vswprintf kind:function(arm,size=0x60) addr:0x0203762c +wcslen kind:function(arm,size=0x1c) addr:0x0203768c +wcscpy kind:function(arm,size=0x20) addr:0x020376a8 +wcsncpy kind:function(arm,size=0x50) addr:0x020376c8 +wcschr kind:function(arm,size=0x34) addr:0x02037718 +__must_round kind:function(arm,size=0x6c) addr:0x0203774c +__dorounddecup kind:function(arm,size=0x50) addr:0x020377b8 +__rounddec kind:function(arm,size=0x40) addr:0x02037808 +__ull2dec kind:function(arm,size=0xc4) addr:0x02037848 +__timesdec kind:function(arm,size=0x180) addr:0x0203790c +__str2dec kind:function(arm,size=0x9c) addr:0x02037a8c +__two_exp kind:function(arm,size=0x380) addr:0x02037b28 +__num2dec_internal kind:function(arm,size=0x180) addr:0x02037ea8 +__num2dec kind:function(arm,size=0xac) addr:0x02038028 +scalbn kind:function(arm,size=0x2c) addr:0x020380d4 +__ieee754_log kind:function(arm,size=0x730) addr:0x02038100 +__ieee754_log10 kind:function(arm,size=0x1d8) addr:0x02038830 +__ieee754_pow kind:function(arm,size=0x1188) addr:0x02038a08 +ceil kind:function(arm,size=0x1c0) addr:0x02039b90 +copysign kind:function(arm,size=0x28) addr:0x02039d50 +fabs kind:function(arm,size=0x20) addr:0x02039d78 +frexp kind:function(arm,size=0xc0) addr:0x02039d98 +ldexp kind:function(arm,size=0x260) addr:0x02039e58 +log kind:function(arm,size=0xc) addr:0x0203a0b8 +log10f kind:function(arm,size=0xc) addr:0x0203a0c4 +pow kind:function(arm,size=0xc) addr:0x0203a0d0 func_0203a0dc kind:function(arm,size=0x78) addr:0x0203a0dc func_0203a154 kind:function(arm,size=0x28) addr:0x0203a154 func_0203a17c kind:function(arm,size=0x10) addr:0x0203a17c @@ -2062,75 +2061,75 @@ func_0203a274 kind:function(arm,size=0x20) addr:0x0203a274 func_0203a294 kind:function(arm,size=0x30) addr:0x0203a294 func_0203a2c4 kind:function(arm,size=0x2c) addr:0x0203a2c4 func_0203a2f0 kind:function(arm,size=0x8c) addr:0x0203a2f0 -func_0203a37c kind:function(arm,size=0x318) addr:0x0203a37c -func_0203a6ac kind:function(arm,size=0x3b4) addr:0x0203a6ac +_dadd kind:function(arm,size=0x318) addr:0x0203a37c +_dsub kind:function(arm,size=0x3b4) addr:0x0203a6ac _dmul kind:function(arm,size=0x364) addr:0x0203aa60 _fflt kind:function(arm,size=0x104) addr:0x0203adc4 _dflt kind:function(arm,size=0x40) addr:0x0203aec8 func_0203af08 kind:function(arm,size=0x3c) addr:0x0203af08 -func_0203af44 kind:function(arm,size=0x98) addr:0x0203af44 -func_0203afdc kind:function(arm,size=0xa4) addr:0x0203afdc -func_0203b080 kind:function(arm,size=0x9c) addr:0x0203b080 -func_0203b11c kind:function(arm,size=0x8c) addr:0x0203b11c -func_0203b1a8 kind:function(arm,size=0x8c) addr:0x0203b1a8 +_dgr kind:function(arm,size=0x98) addr:0x0203af44 +_dleq kind:function(arm,size=0xa4) addr:0x0203afdc +_dls kind:function(arm,size=0x9c) addr:0x0203b080 +_deq kind:function(arm,size=0x8c) addr:0x0203b11c +_dneq kind:function(arm,size=0x8c) addr:0x0203b1a8 func_0203b234 kind:function(arm,size=0x5c) addr:0x0203b234 func_0203b290 kind:function(arm,size=0x5c) addr:0x0203b290 func_0203b2ec kind:function(arm,size=0x5c) addr:0x0203b2ec func_0203b348 kind:function(arm,size=0x68) addr:0x0203b348 -func_0203b3b0 kind:function(arm,size=0x84) addr:0x0203b3b0 +_f2d kind:function(arm,size=0x84) addr:0x0203b3b0 func_0203b434 kind:function(arm,size=0x48) addr:0x0203b434 func_0203b47c kind:function(arm,size=0x48) addr:0x0203b47c func_0203b4c4 kind:function(arm,size=0x10) addr:0x0203b4c4 func_0203b4d4 kind:function(arm,size=0x1b0) addr:0x0203b4d4 _ll_udiv kind:function(arm,size=0xc) addr:0x0203b684 -func_0203b690 kind:function(arm,size=0x3c) addr:0x0203b690 +_ull_mod kind:function(arm,size=0x3c) addr:0x0203b690 func_0203b6cc kind:function(arm,size=0x20) addr:0x0203b6cc _s32_div_f kind:function(arm,size=0x20c) addr:0x0203b6ec _u32_div_f kind:function(arm,size=0x1e4) addr:0x0203b8f8 .L_0203b900 kind:label(arm) addr:0x0203b900 -func_0203badc kind:function(arm,size=0x34) addr:0x0203badc -func_0203bb10 kind:function(arm,size=0x40) addr:0x0203bb10 +_ffix kind:function(arm,size=0x34) addr:0x0203badc +_ffixu kind:function(arm,size=0x40) addr:0x0203bb10 func_0203bb50 kind:function(arm,size=0x4c) addr:0x0203bb50 -func_0203bb9c kind:function(arm,size=0x8c) addr:0x0203bb9c -func_0203bc28 kind:function(arm,size=0x19c) addr:0x0203bc28 +_ll_ufrom_d kind:function(arm,size=0x8c) addr:0x0203bb9c +sqrt kind:function(arm,size=0x19c) addr:0x0203bc28 func_0203bdc4 kind:function(arm,size=0xe4) addr:0x0203bdc4 -func_0203bea8 kind:function(arm,size=0x1e0) addr:0x0203bea8 +_fmul kind:function(arm,size=0x1e0) addr:0x0203bea8 func_0203c088 kind:function(arm,size=0x21c) addr:0x0203c088 func_0203c2a4 kind:function(arm,size=0x8) addr:0x0203c2a4 func_0203c2b8 kind:function(arm,size=0x278) addr:0x0203c2b8 -func_0203c53c kind:function(arm,size=0x3b8) addr:0x0203c53c +_fdiv kind:function(arm,size=0x3b8) addr:0x0203c53c .L_0203c5f0 kind:data(byte[0]) addr:0x0203c5f0 _ddiv kind:function(arm,size=0x544) addr:0x0203c90c .L_0203ca44 kind:data(byte[0]) addr:0x0203ca44 func_0203b920 kind:function(arm,size=0x4) addr:0x0203ce50 -func_0203ce54 kind:function(arm,size=0xc) addr:0x0203ce54 +_ExitProcess kind:function(arm,size=0xc) addr:0x0203ce54 func_0203ce60 kind:function(arm,size=0x4) addr:0x0203ce60 func_0203ce64 kind:function(arm,size=0x4) addr:0x0203ce64 -func_0203ce68 kind:function(arm,size=0x8) addr:0x0203ce68 +sys_ReadChar kind:function(arm,size=0x8) addr:0x0203ce68 func_0203ce70 kind:function(arm,size=0x4) addr:0x0203ce70 -func_0203ce74 kind:function(arm,size=0x50) addr:0x0203ce74 -func_0203cec4 kind:function(arm,size=0x44) addr:0x0203cec4 -func_0203cf08 kind:function(arm,size=0x8) addr:0x0203cf08 +__read_console kind:function(arm,size=0x50) addr:0x0203ce74 +__write_console kind:function(arm,size=0x44) addr:0x0203cec4 +__close_console kind:function(arm,size=0x8) addr:0x0203cf08 func_0203cf10 kind:function(arm,size=0x84) addr:0x0203cf10 func_0203cf94 kind:function(arm,size=0x84) addr:0x0203cf94 -func_0203d018 kind:function(arm,size=0x64) addr:0x0203d018 +_Z12BinarySearchP19ExceptionTableIndexmPc kind:function(arm,size=0x64) addr:0x0203d018 func_0203d07c kind:function(arm,size=0x108) addr:0x0203d07c -func_0203d184 kind:function(arm,size=0x1c) addr:0x0203d184 +_Z13CurrentActionPK14ActionIterator kind:function(arm,size=0x1c) addr:0x0203d184 func_0203d1a0 kind:function(arm,size=0x2bc) addr:0x0203d1a0 -func_0203d45c kind:function(arm,size=0x82c) addr:0x0203d45c +_Z11UnwindStackP12ThrowContextP13ExceptionInfoPc kind:function(arm,size=0x82c) addr:0x0203d45c func_0203dc88 kind:function(arm,size=0x8) addr:0x0203dc88 func_0203dc90 kind:function(arm,size=0x154) addr:0x0203dc90 func_0203dde4 kind:function(arm,size=0x80) addr:0x0203dde4 func_0203de64 kind:function(arm,size=0xac) addr:0x0203de64 func_0203df10 kind:function(arm,size=0x4) addr:0x0203df10 -func_0203df14 kind:function(arm,size=0x60) addr:0x0203df14 +_Z16HandleUnexpectedP12ThrowContextP13ExceptionInfoP16ex_specificationPc kind:function(arm,size=0x60) addr:0x0203df14 func_0203df74 kind:function(arm,size=0x1dc) addr:0x0203df74 -func_0203e150 kind:function(arm,size=0x5c) addr:0x0203e150 +_Z14SetupCatchInfoP12ThrowContextll kind:function(arm,size=0x5c) addr:0x0203e150 func_0203e1ac kind:function(arm,size=0xf4) addr:0x0203e1ac func_0203cd70 kind:function(arm,size=0x28) addr:0x0203e2a0 func_0203e2c8 kind:function(arm,size=0x14) addr:0x0203e2c8 func_0203e2dc kind:function(arm,size=0xc) addr:0x0203e2dc -CallStaticInitializers kind:function(arm,size=0x30) addr:0x0203e2e8 +_Z26__call_static_initializersv kind:function(arm,size=0x30) addr:0x0203e2e8 __destroy_global_chain kind:function(arm,size=0x44) addr:0x0203e318 func_0203e35c kind:function(arm,size=0xc) addr:0x0203e35c func_0203e368 kind:function(arm,size=0xc) addr:0x0203e368 @@ -2317,10 +2316,10 @@ data_02044248 kind:data(any) addr:0x02044248 data_0204451c kind:data(any) addr:0x0204451c data_02044540 kind:data(any) addr:0x02044540 data_02044580 kind:data(any) addr:0x02044580 -data_020445d4 kind:data(any) addr:0x020445d4 -data_020446d4 kind:data(any) addr:0x020446d4 -data_020446e4 kind:data(any) addr:0x020446e4 -data_020446f4 kind:data(any) addr:0x020446f4 +__ctype_mapC kind:data(any) addr:0x020445d4 +dp_h kind:data(any) addr:0x020446d4 local +bp kind:data(any) addr:0x020446e4 local +dp_l kind:data(any) addr:0x020446f4 local data_02044704 kind:data(any) addr:0x02044704 .p__sinit_0203ed54 kind:data(word) addr:0x0204470c .p__sinit_0203ed70 kind:data(word) addr:0x02044710 @@ -2614,21 +2613,21 @@ data_02045ba0 kind:data(any) addr:0x02045ba0 data_02045be4 kind:data(any) addr:0x02045be4 data_02045be8 kind:data(any) addr:0x02045be8 data_02045c18 kind:data(any) addr:0x02045c18 -data_02045c1c kind:data(any) addr:0x02045c1c -data_02045d00 kind:data(any) addr:0x02045d00 -data_02045d04 kind:data(any) addr:0x02045d04 -data_02045d08 kind:data(any) addr:0x02045d08 -data_02045d0c kind:data(any) addr:0x02045d0c -data_02045d14 kind:data(any) addr:0x02045d14 -data_02045d1c kind:data(any) addr:0x02045d1c -data_02045d2c kind:data(any) addr:0x02045d2c -data_02045d4c kind:data(any) addr:0x02045d4c -data_02045d58 kind:data(any) addr:0x02045d58 -data_02045d64 kind:data(any) addr:0x02045d64 -data_02045d70 kind:data(any) addr:0x02045d70 -data_02045d80 kind:data(any) addr:0x02045d80 -data_02045dd8 kind:data(any) addr:0x02045dd8 -data_02045e60 kind:data(any) addr:0x02045e60 +__files kind:data(any) addr:0x02045c1c +__float_nan kind:data(any) addr:0x02045d00 +@19 kind:data(any) addr:0x02045d04 local +@16 kind:data(any) addr:0x02045d08 local +@12 kind:data(any) addr:0x02045d0c local +__ctype_cmpt kind:data(any) addr:0x02045d14 +__coll_cmpt kind:data(any) addr:0x02045d1c +__time_cmpt kind:data(any) addr:0x02045d2c +@15 kind:data(any) addr:0x02045d4c local +_current_locale kind:data(any) addr:0x02045d58 +@14 kind:data(any) addr:0x02045d64 local +@13 kind:data(any) addr:0x02045d70 local +@17 kind:data(any) addr:0x02045d80 local +@18 kind:data(any) addr:0x02045dd8 local +char_coll_table kind:data(any) addr:0x02045e60 data_02045f20 kind:data(any) addr:0x02045f20 data_02045f2c kind:data(any) addr:0x02045f2c data_02045f38 kind:data(any) addr:0x02045f38 @@ -2643,27 +2642,27 @@ data_02045f88 kind:data(any) addr:0x02045f88 data_02045f90 kind:data(any) addr:0x02045f90 data_02045f98 kind:data(any) addr:0x02045f98 data_02045f9c kind:data(any) addr:0x02045f9c -data_02045fa0 kind:data(any) addr:0x02045fa0 -data_02045fd0 kind:data(any) addr:0x02045fd0 -data_02045ff8 kind:data(any) addr:0x02045ff8 -data_02046010 kind:data(any) addr:0x02046010 -data_02046020 kind:data(any) addr:0x02046020 -data_02046028 kind:data(any) addr:0x02046028 -data_02046030 kind:data(any) addr:0x02046030 -data_02046038 kind:data(any) addr:0x02046038 -data_02046040 kind:data(any) addr:0x02046040 -data_02046044 kind:data(any) addr:0x02046044 -data_02046048 kind:data(any) addr:0x02046048 -data_0204604c kind:data(any) addr:0x0204604c -data_02046050 kind:data(any) addr:0x02046050 -data_02046054 kind:data(any) addr:0x02046054 -data_02046058 kind:data(any) addr:0x02046058 -data_0204605c kind:data(any) addr:0x0204605c -data_02046060 kind:data(any) addr:0x02046060 -data_02046064 kind:data(any) addr:0x02046064 -data_02046068 kind:data(any) addr:0x02046068 -data_0204606c kind:data(any) addr:0x0204606c -data_02046070 kind:data(any) addr:0x02046070 +@311 kind:data(any) addr:0x02045fa0 local +@312 kind:data(any) addr:0x02045fd0 local +@313 kind:data(any) addr:0x02045ff8 local +@314 kind:data(any) addr:0x02046010 local +@315 kind:data(any) addr:0x02046020 local +@316 kind:data(any) addr:0x02046028 local +@317 kind:data(any) addr:0x02046030 local +@318 kind:data(any) addr:0x02046038 local +@319 kind:data(any) addr:0x02046040 local +@320 kind:data(any) addr:0x02046044 local +@321 kind:data(any) addr:0x02046048 local +@322 kind:data(any) addr:0x0204604c local +@323 kind:data(any) addr:0x02046050 local +@324 kind:data(any) addr:0x02046054 local +@325 kind:data(any) addr:0x02046058 local +@326 kind:data(any) addr:0x0204605c local +@327 kind:data(any) addr:0x02046060 local +@328 kind:data(any) addr:0x02046064 local +@329 kind:data(any) addr:0x02046068 local +@330 kind:data(any) addr:0x0204606c local +@331 kind:data(any) addr:0x02046070 local data_02046074 kind:data(any) addr:0x02046074 data_0204607c kind:data(any) addr:0x0204607c data_02046084 kind:data(any) addr:0x02046084 @@ -2886,18 +2885,20 @@ data_02052524 kind:bss addr:0x02052524 data_020525e0 kind:bss addr:0x020525e0 data_020526c8 kind:bss addr:0x020526c8 data_020526cc kind:bss addr:0x020526cc -data_02052af0 kind:bss addr:0x02052af0 -data_02052b00 kind:bss addr:0x02052b00 -data_02052c00 kind:bss addr:0x02052c00 -data_02052c24 kind:bss addr:0x02052c24 -data_02052c48 kind:bss addr:0x02052c48 -data_02052cf0 kind:bss addr:0x02052cf0 -data_02052d20 kind:bss addr:0x02052d20 -data_02052e20 kind:bss addr:0x02052e20 -data_02052f20 kind:bss addr:0x02052f20 -data_02053020 kind:bss addr:0x02053020 -data_02053024 kind:bss addr:0x02053024 -data_02053028 kind:bss addr:0x02053028 -data_02053044 kind:bss addr:0x02053044 -data_0205304c kind:bss addr:0x0205304c +__console_exit kind:bss addr:0x02052af0 +__stdio_exit kind:bss addr:0x02052af4 +__atexit_curr_func kind:bss addr:0x02052af8 local +__aborting kind:bss addr:0x02052afc +__atexit_funcs kind:bss addr:0x02052b00 local +__cs_id kind:bss addr:0x02052c00 +__cs_ref kind:bss addr:0x02052c24 +__cs kind:bss addr:0x02052c48 +stderr_buff kind:bss addr:0x02052d20 local +stdout_buff kind:bss addr:0x02052e20 local +stdin_buff kind:bss addr:0x02052f20 local +errno kind:bss addr:0x02053020 +__msl_constraint_handler kind:bss addr:0x02053024 +signal_funcs kind:bss addr:0x02053028 +zero kind:bss addr:0x02053044 local +zero kind:bss addr:0x0205304c local __global_destructor_chain kind:bss(size=0x4) addr:0x02053054 diff --git a/include/nitro/os/context.h b/include/nitro/os/context.h new file mode 100644 index 00000000..4847066e --- /dev/null +++ b/include/nitro/os/context.h @@ -0,0 +1,15 @@ +#ifndef NITROSDK_OS_CONTEXT_H +#define NITROSDK_OS_CONTEXT_H + +#include + +typedef struct OSContext { + /* 0x00 */ u32 cpsr; + /* 0x04 */ u32 r[13]; + /* 0x38 */ u32 sp; + /* 0x3C */ u32 lr; + /* 0x40 */ u32 pc; + /* 0x44 */ char unk_40[0x20]; +} OSContext; // Size: 0x64 + +#endif // NITROSDK_OS_CONTEXT_H diff --git a/include/nitro/os/mutex.h b/include/nitro/os/mutex.h new file mode 100644 index 00000000..5ccfb7b7 --- /dev/null +++ b/include/nitro/os/mutex.h @@ -0,0 +1,20 @@ +#ifndef NITROSDK_OS_MUTEX_H +#define NITROSDK_OS_MUTEX_H + +#include +#include + +typedef struct OSMutex { + /* 0x00 */ OSThreadQueue queue; + /* 0x08 */ OSThread *thread; + /* 0x0C */ s32 count; + /* 0x10 */ OSMutexLinkedList list; +} OSMutex; // Size: 0x18 + +void OS_InitMutex(OSMutex *mutex); +void OS_LockMutex(OSMutex *mutex); +void OS_UnlockMutex(OSMutex *mutex); +void OS_UnlockAllQueuedThreadMutex(OSThread *thread); +bool OS_TryLockMutex(OSMutex *mutex); + +#endif diff --git a/include/nitro/os/thread.h b/include/nitro/os/thread.h new file mode 100644 index 00000000..e8c1d1fa --- /dev/null +++ b/include/nitro/os/thread.h @@ -0,0 +1,98 @@ +#ifndef NITROSDK_OS_THREAD_H +#define NITROSDK_OS_THREAD_H + +#include + +/// MARK: Types + +typedef struct OSThread OSThread; +typedef struct OSMutex OSMutex; + +typedef void (*OSThreadSwitchCallback)(OSThread *oldThread, OSThread *newThread); +typedef void (*OSThreadDestructor)(void *); + +typedef struct OSThreadLinkedList { + /* 0x04 */ OSThread *prev; + /* 0x00 */ OSThread *next; +} OSThreadLinkedList; + +typedef struct OSMutexQueue { + /* 0x00 */ OSMutex *head; + /* 0x04 */ OSMutex *tail; +} OSMutexQueue; + +typedef struct OSMutexLinkedList { + /* 0x00 */ OSMutex *next; + /* 0x04 */ OSMutex *prev; +} OSMutexLinkedList; + +typedef struct OSThreadQueue { + /* 0x00 */ OSThread *head; + /* 0x04 */ OSThread *tail; +} OSThreadQueue; + +typedef struct OSThreadInfo { + /* 0x00 */ u16 isSchedulerWaiting; + /* 0x02 */ u16 irqDepth; + /* 0x10 */ OSThread *current; + /* 0x14 */ OSThread *list; + /* 0x18 */ OSThreadSwitchCallback callback; +} OSThreadInfo; + +typedef struct OSThread { + /* 0x00 */ OSContext context; + /* 0x64 */ s32 state; + /* 0x68 */ OSThread *next; + /* 0x6C */ u32 id; + /* 0x70 */ u32 priority; + /* 0x74 */ void *profiler; + /* 0x78 */ OSThreadQueue *queue; + /* 0x7C */ OSThreadLinkedList list; + /* 0x84 */ OSMutex *mutex; + /* 0x88 */ OSMutexQueue mutexQueue; + /* 0x90 */ u32 stackTop; + /* 0x94 */ u32 stackBottom; + /* 0x98 */ u32 stackOffset; + /* 0x9C */ OSThreadQueue joinQueue; + /* 0xA4 */ void *unk_A4[3]; + /* 0xB0 */ void *unk_B0; + /* 0xB4 */ OSThreadDestructor destructor; + /* 0xB8 */ void *userParam; + /* 0xBC */ s32 error; +} OSThread; // Size: 0xC0 + +extern OSThreadInfo ThreadInfo; + +/// MARK: Functions + +void OS_PauseThread(OSThreadQueue *queue); +void OS_UnpauseThread(OSThreadQueue *queue); +OSMutex *OS_RemoveMutexFromQueue(OSMutexQueue *queue); +OSThread *OS_SelectThread(void); +void OS_CreateThread(OSThread *thread, void (*func)(void *), void *arg, void *stack, u32 stackSize, u32 priority); +void OS_ExitThread(void); + +/// MARK: Inlines + +static inline void OS_InitThreadQueue(OSThreadQueue *queue) { + queue->tail = NULL; + queue->head = NULL; +} + +static inline OSThreadInfo *OS_GetThreadInfo(void) { + return &ThreadInfo; +} + +static inline OSThread *OS_GetCurrentThread(void) { + return OS_GetThreadInfo()->current; +} + +static inline void OS_SetCurrentThread(OSThread *thread) { + OS_GetThreadInfo()->current = thread; +} + +static inline u32 OS_GetThreadId(OSThread *thread) { + return thread->id; +} + +#endif // NITROSDK_OS_THREAD_H diff --git a/include/types.h b/include/types.h index b71cde21..dfdd49f4 100644 --- a/include/types.h +++ b/include/types.h @@ -13,14 +13,13 @@ typedef int s32; typedef short s16; typedef char s8; +typedef float f32; +typedef double f64; + typedef s8 unk8; typedef s16 unk16; typedef s32 unk32; -#ifndef __cplusplus -typedef s32 bool; -#endif - #define CEIL_DIV(a, b) (((a) + (b) - 1) / (b)) #endif diff --git a/libs/c/include/abort_exit_arm_eabi.h b/libs/c/include/abort_exit_arm_eabi.h new file mode 100644 index 00000000..cd339e21 --- /dev/null +++ b/libs/c/include/abort_exit_arm_eabi.h @@ -0,0 +1,19 @@ +#ifndef _C_ABORT_EXIT_ARM_EABI_H +#define _C_ABORT_EXIT_ARM_EABI_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define SIGABRT 1 +#define EXIT_FAILURE 1 + +void abort(void); +void exit(int status); +void __exit(int status); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/ansi_files.h b/libs/c/include/ansi_files.h new file mode 100644 index 00000000..f6323bdc --- /dev/null +++ b/libs/c/include/ansi_files.h @@ -0,0 +1,19 @@ +#ifndef _C_ANSI_FILES_H +#define _C_ANSI_FILES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define console_buff_mode _IOLBF +#define console_buff_size 256 + +typedef unsigned char console_buff[console_buff_size]; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/ansi_fp.h b/libs/c/include/ansi_fp.h new file mode 100644 index 00000000..ac69a93d --- /dev/null +++ b/libs/c/include/ansi_fp.h @@ -0,0 +1,43 @@ +#ifndef _C_ANSI_FP_H +#define _C_ANSI_FP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define FLOATDECIMAL ((char) (0)) +#define FIXEDDECIMAL ((char) (1)) + +#define DBL_MIN 0x1.0000000000000P-1022 +#define DBL_EPSILON 0x1.0000000000000P-52 +#define DBL_MAX 0x1.fffffffffffffP1023 + +#define LDBL_MIN 0x1.0000000000000P-1022L +#define LDBL_EPSILON 0x1.0000000000000P-52L +#define LDBL_MAX 0x1.fffffffffffffP1023L + +typedef struct decimal { + unsigned char sgn; + char unused; + short exp; + struct { + unsigned char length; + unsigned char text[32]; + unsigned char unused; + } sig; +} decimal; + +typedef struct decform { + char style; + char unused; + short digits; +} decform; + +void __num2dec(const decform *f, double x, decimal *d); +double __dec2num(const decimal *d); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/arith.h b/libs/c/include/arith.h new file mode 100644 index 00000000..3c620bcf --- /dev/null +++ b/libs/c/include/arith.h @@ -0,0 +1,15 @@ +#ifndef _C_ARITH_H +#define _C_ARITH_H + +#ifdef __cplusplus +extern "C" { +#endif + +int abs(int __x); +long labs(long __x); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/buffer_io.h b/libs/c/include/buffer_io.h new file mode 100644 index 00000000..202eb996 --- /dev/null +++ b/libs/c/include/buffer_io.h @@ -0,0 +1,18 @@ +#ifndef _C_BUFFER_IO_H +#define _C_BUFFER_IO_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int __flush_buffer(FILE *file, size_t *length); +void __prep_buffer(FILE *file); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/console_io.h b/libs/c/include/console_io.h new file mode 100644 index 00000000..e1880dd7 --- /dev/null +++ b/libs/c/include/console_io.h @@ -0,0 +1,16 @@ +#ifndef _C_CONSOLE_IO_H +#define _C_CONSOLE_IO_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern int __read_console(unsigned int handle, unsigned char *buffer, int *count, void *ref); +extern int __write_console(unsigned int handle, unsigned char *buffer, int *count, void *ref); +extern int __close_console(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/critical_regions.h b/libs/c/include/critical_regions.h new file mode 100644 index 00000000..4c33f678 --- /dev/null +++ b/libs/c/include/critical_regions.h @@ -0,0 +1,49 @@ +#ifndef MSL_COMMON_CRITICAL_REGIONS_H +#define MSL_COMMON_CRITICAL_REGIONS_H + +#include + +enum critical_regions { + atexit_funcs_access = 0, + malloc_pool_access = 1, + stdin_access = 2, + stdout_access = 3, + stderr_access = 4, + files_access = 5, + console_status_access = 6, + signal_funcs_access = 7, + thread_access = 8, + num_critical_regions = 9 +}; + +extern OSMutex __cs[num_critical_regions]; +extern int __cs_id[num_critical_regions]; +extern int __cs_ref[num_critical_regions]; + +static inline void __begin_critical_region(int region) { + OSThread *currentThread; + + if (OS_TryLockMutex(&__cs[region]) == 0) { + currentThread = OS_GetCurrentThread(); + __cs_id[region] = OS_GetThreadId(currentThread); + __cs_ref[region] = 1; + } else { + currentThread = OS_GetCurrentThread(); + if (OS_GetThreadId(currentThread) == __cs_id[region]) { + __cs_ref[region]++; + } else { + OS_LockMutex(&__cs[region]); + currentThread = OS_GetCurrentThread(); + __cs_id[region] = OS_GetThreadId(currentThread); + __cs_ref[region] = 1; + } + } +} + +static inline void __end_critical_region(int region) { + if (--__cs_ref[region] == 0) { + OS_UnlockMutex(&__cs[region]); + } +} + +#endif // MSL_COMMON_CRITICAL_REGIONS_H diff --git a/libs/c/include/ctype.h b/libs/c/include/ctype.h new file mode 100644 index 00000000..db250e53 --- /dev/null +++ b/libs/c/include/ctype.h @@ -0,0 +1,60 @@ +#ifndef _C_CTYPE_H +#define _C_CTYPE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define __msl_cmap_size 128 + +extern const unsigned short __ctype_mapC[__msl_cmap_size]; +extern const unsigned char __lower_mapC[__msl_cmap_size]; +extern const unsigned char __upper_mapC[__msl_cmap_size]; + +#define _MSL_CMAP_ACCESS __ctype_mapC +#define _MSL_CLOWER_ACCESS __lower_mapC +#define _MSL_CUPPER_ACCESS __upper_mapC + +#define __msl_alpha 0x001 +#define __msl_blank 0x002 +#define __msl_cntrl 0x004 +#define __msl_digit 0x008 +#define __msl_graph 0x010 +#define __msl_lower 0x020 +#define __msl_print 0x040 +#define __msl_punct 0x080 +#define __msl_space 0x100 +#define __msl_upper 0x200 +#define __msl_xdigit 0x400 + +static inline int isalpha(unsigned int c) { + return ((c < 0) || (c >= __msl_cmap_size)) ? 0 : (int) (_MSL_CMAP_ACCESS[c] & __msl_alpha); +} + +static inline int isdigit(unsigned int c) { + return ((c < 0) || (c >= __msl_cmap_size)) ? 0 : (int) (_MSL_CMAP_ACCESS[c] & __msl_digit); +} + +static inline int isspace(unsigned int c) { + return ((c < 0) || (c >= __msl_cmap_size)) ? 0 : (int) (_MSL_CMAP_ACCESS[c] & __msl_space); +} + +static inline int isupper(unsigned int c) { + return ((c < 0) || (c >= __msl_cmap_size)) ? 0 : (int) (_MSL_CMAP_ACCESS[c] & __msl_upper); +} + +static inline int isxdigit(unsigned int c) { + return ((c < 0) || (c >= __msl_cmap_size)) ? 0 : (int) (_MSL_CMAP_ACCESS[c] & __msl_xdigit); +} + +static inline int toupper(unsigned int c) { + return ((c < 0) || (c >= __msl_cmap_size)) ? c : (int) (_MSL_CUPPER_ACCESS[c]); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/errno.h b/libs/c/include/errno.h new file mode 100644 index 00000000..434400b5 --- /dev/null +++ b/libs/c/include/errno.h @@ -0,0 +1,21 @@ +#ifndef _C_ERRNO_H +#define _C_ERRNO_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern int errno; + +#define ENOERR 0 +#define EDOM 33 +#define ERANGE 34 +#define ESIGPARM 36 +#define EFPOS 40 +#define EILSEQ 84 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/fdlibm.h b/libs/c/include/fdlibm.h new file mode 100644 index 00000000..34430d37 --- /dev/null +++ b/libs/c/include/fdlibm.h @@ -0,0 +1,62 @@ +#ifndef _C_FDLIBM_H +#define _C_FDLIBM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +/** + * For including FDLIBM declarations without also including its many macros. + */ + +double __ieee754_acos(double); +double __ieee754_fmod(double, double); +double __ieee754_log(double); +double __ieee754_log10(double); +double __ieee754_pow(double, double); +double __ieee754_sqrt(double); +double __ieee754_atan2(double, double); +double __ieee754_asin(double); +double __ieee754_exp(double); +int __ieee754_rem_pio2(double, double *); + +double __kernel_sin(double, double, int); +double __kernel_cos(double, double); +double __kernel_tan(double, double, int); + +double nan(const char *arg); +double atan(double x); +double ceil(double x); +double copysign(double x, double y); +double cos(double x); +double floor(double x); +double frexp(double x, int *eptr); +double ldexp(double value, int exp); +double modf(double x, double *iptr); +double sin(double x); +double tan(double x); +double acos(double x); +double asin(double x); +double atan2(double y, double x); +double fmod(double x, double y); +double pow(double x, double y); +double sqrt(double x); +double log(double x); +float log10f(float x); + +// In reality, these are "weak" functions which all have C++ names (except scalbn). +// We fake it by defining them as strong C functions instead. +float sin__Ff(float x); +float cos__Ff(float x); +double scalbn(double x, int n); +double fabs__Fd(double x); +float fabsf__Ff(float x); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/libs/c/include/file_io.h b/libs/c/include/file_io.h new file mode 100644 index 00000000..de315c1a --- /dev/null +++ b/libs/c/include/file_io.h @@ -0,0 +1,17 @@ +#ifndef _C_FILE_IO_H +#define _C_FILE_IO_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int fclose(FILE *file); +int fflush(FILE *file); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/file_pos.h b/libs/c/include/file_pos.h new file mode 100644 index 00000000..7331299f --- /dev/null +++ b/libs/c/include/file_pos.h @@ -0,0 +1,19 @@ +#ifndef _C_FILE_POS_H +#define _C_FILE_POS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int fseek(FILE *stream, unsigned int offset, int whence); +int _fseek(FILE *stream, unsigned int offset, int whence); +int ftell(FILE *stream); +int _ftell(FILE *stream); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/libs/c/include/file_struc.h b/libs/c/include/file_struc.h new file mode 100644 index 00000000..cda7bda8 --- /dev/null +++ b/libs/c/include/file_struc.h @@ -0,0 +1,123 @@ +#ifndef _C_FILE_STRUC_H +#define _C_FILE_STRUC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned long __file_handle; +typedef unsigned long fpos_t; +typedef struct _FILE _FILE, *P_FILE; + +#define __ungetc_buffer_size 2 + +enum __file_kinds { + __closed_file, + __disk_file, + __console_file, + __unavailable_file +}; + +enum __open_modes { + __must_exist, + __create_if_necessary, + __create_or_truncate +}; + +enum __file_orientation { + __unoriented, + __char_oriented, + __wide_oriented +}; + +enum __io_modes { + __read = 1, + __write = 2, + __read_write = 3, + __append = 4 +}; + +typedef struct __file_modes { + unsigned int open_mode : 2; + unsigned int io_mode : 3; + unsigned int buffer_mode : 2; + unsigned int file_kind : 3; + unsigned int file_orientation : 2; + unsigned int binary_io : 1; +} __file_modes; + +enum __io_states { + __neutral, + __writing, + __reading, + __rereading +}; + +typedef struct __file_state { + unsigned int io_state : 3; + unsigned int free_buffer : 1; + unsigned char eof; + unsigned char error; +} __file_state; + +typedef void *__ref_con; +typedef void (*__idle_proc)(void); +typedef int (*__pos_proc)(unsigned int file, unsigned int *position, int mode, void *ref); +typedef int (*__io_proc)(unsigned int handle, unsigned char *buffer, int *count, void *ref); +typedef int (*__close_proc)(unsigned int file); + +struct _FILE { + __file_handle handle; + __file_modes mode; + __file_state state; + unsigned char char_buffer; + unsigned char char_buffer_overflow; + unsigned char ungetc_buffer[__ungetc_buffer_size]; + wchar_t ungetwc_buffer[__ungetc_buffer_size]; + unsigned int position; + unsigned char *buffer; + unsigned int buffer_size; + unsigned char *buffer_ptr; + unsigned int buffer_len; + unsigned int buffer_alignment; + unsigned int saved_buffer_len; + unsigned int buffer_pos; + __pos_proc position_proc; + __io_proc read_proc; + __io_proc write_proc; + __close_proc close_proc; + __ref_con ref_con; +}; + +typedef struct _FILE FILE; + +#define _IONBF 0 +#define _IOLBF 1 +#define _IOFBF 2 + +// define standard C file pointer location names +#define SEEK_SET (0) +#define SEEK_CUR (1) +#define SEEK_END (2) + +#define set_error(file) \ + do { \ + (file)->state.error = 1; \ + (file)->buffer_len = 0; \ + } while (FALSE) + +#define stdin &(__files[0]) +#define stdout &(__files[1]) +#define stderr &(__files[2]) + +#define _STATIC_FILES 3 + +extern FILE __files[]; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/float.h b/libs/c/include/float.h new file mode 100644 index 00000000..e79c21dd --- /dev/null +++ b/libs/c/include/float.h @@ -0,0 +1,29 @@ +#ifndef _C_FLOAT_H +#define _C_FLOAT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define FLT_MAX 3.402823466e+38f +#define FLT_EPSILON 1.192092896e-07f +#define FLT_MIN 1.175494351e-38f + +#define DBL_EPSILON 1.1920929e-07 + +#define LDBL_MANT_DIG 53 +#define LDBL_DIG 15 +#define LDBL_MIN_EXP (-1021) +#define LDBL_MIN_10_EXP (-308) +#define LDBL_MAX_EXP 1024 +#define LDBL_MAX_10_EXP 308 + +#define LDBL_MAX 0x1.fffffffffffffP1023L +#define LDBL_EPSILON 0x1.0000000000000P-52L +#define LDBL_MIN 0x1.0000000000000P-1022L + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/limits.h b/libs/c/include/limits.h new file mode 100644 index 00000000..1de7cdde --- /dev/null +++ b/libs/c/include/limits.h @@ -0,0 +1,37 @@ +#ifndef _C_LIMITS_H +#define _C_LIMITS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define SCHAR_MIN (-0x7F - 1) +#define SCHAR_MAX 0x7F +#define UCHAR_MAX 0xFFU + +#define CHAR_MIN SCHAR_MIN +#define CHAR_MAX SCHAR_MAX + +#define SHRT_MIN (-0x7FFF - 1) +#define SHRT_MAX 0x7FFF +#define USHRT_MAX 0xFFFF + +#define INT_MIN (-0x7FFFFFFF - 1) +#define INT_MAX 0x7FFFFFFF +#define UINT_MAX 0xFFFFFFFF + +#define LONG_MIN (-0x7FFFFFFFL - 1) +#define LONG_MAX 0x7FFFFFFFL +#define ULONG_MAX 0xFFFFFFFFUL + +#define LLONG_MIN (-0x7FFFFFFFFFFFFFFFLL - 1) +#define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL +#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL + +#define CHAR_BIT 8 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/locale.h b/libs/c/include/locale.h new file mode 100644 index 00000000..d8031a07 --- /dev/null +++ b/libs/c/include/locale.h @@ -0,0 +1,76 @@ +#ifndef _C_LOCALE_H +#define _C_LOCALE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define _COMPONENT_NAME_LEN 8 + +typedef int (*__decode_mbyte)(unsigned short *, const char *, int); +typedef int (*__encode_mbyte)(char *, unsigned short); + +struct _loc_coll_cmpt { + int char_start_value; + int char_coll_tab_size; + short char_spec_accents; + unsigned short *char_coll_table_ptr; +}; + +struct _loc_ctype_cmpt { + /* 0x00 */ __decode_mbyte decode_mb; + /* 0x04 */ __encode_mbyte encode_wc; +}; + +struct _loc_time_cmpt { + char *am_pm; + char *DateTime_Format; + char *Twelve_hr_format; + char *Date_Format; + char *Time_Format; + char *Day_Names; + char *MonthNames; + char *TimeZone; +}; + +struct __locale { + /* 0x00 */ struct _loc_time_cmpt *time_cmpt_ptr; + /* 0x04 */ struct _loc_coll_cmpt *coll_cmpt_ptr; + /* 0x08 */ struct _loc_ctype_cmpt *ctype_cmpt_ptr; +}; + +struct lconv { + char *decimal_point; + char *thousands_sep; + char *grouping; + char *mon_decimal_point; + char *mon_thousands_sep; + char *mon_grouping; + char *positive_sign; + char *negative_sign; + char *currency_symbol; + char frac_digits; + char p_cs_precedes; + char n_cs_precedes; + char p_sep_by_space; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char *int_curr_symbol; + char int_frac_digits; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; +}; + +extern struct lconv __lconv; +extern struct __locale _current_locale; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/math.h b/libs/c/include/math.h new file mode 100644 index 00000000..dbb569e9 --- /dev/null +++ b/libs/c/include/math.h @@ -0,0 +1,61 @@ +#ifndef _C_MATH_H +#define _C_MATH_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define DONT_INLINE_SQRT + +#define M_PI 3.1415926535897932 +#define M_SQRT3 1.7320499420166016 + +extern int __float_nan[]; +extern int __float_huge[]; +extern int __double_huge[]; + +#define NAN (*(float *) __float_nan) +#define INFINITY (*(float *) __float_huge) +#define HUGE_VAL (*(double *) __double_huge) + +// f64 bit-twiddling macros +#ifdef __BIG_ENDIAN__ + #define __HI(x) (((int *) &x)[0]) + #define __LO(x) (((int *) &x)[1]) +#else + #define __HI(x) (((int *) &x)[1]) + #define __LO(x) (((int *) &x)[0]) +#endif + +#define FP_NAN 1 +#define FP_INFINITE 2 +#define FP_ZERO 3 +#define FP_NORMAL 4 +#define FP_SUBNORMAL 5 + +int __fpclassifyd(double x); +int __signbitd(double x); +double fabs(double x); +double nan(const char *x); +double sqrt(double __x); + +#define fpclassify(x) ((sizeof(x) == sizeof(float)) ? __fpclassifyf((float) (x)) : __fpclassifyd((double) (x))) +#define signbit(x) ((sizeof(x) == sizeof(float)) ? __signbitf((float) (x)) : __signbitd((double) (x))) + +#define isnormal(x) (fpclassify(x) == FP_NORMAL) +#define isnan(x) (fpclassify(x) == FP_NAN) +#define isinf(x) (fpclassify(x) == FP_INFINITE) +#define isfinite(x) (fpclassify(x) > FP_INFINITE) + +static inline long double fabsl(long double x) { + return (long double) fabs((double) x); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/mbstring.h b/libs/c/include/mbstring.h new file mode 100644 index 00000000..ae4e71ce --- /dev/null +++ b/libs/c/include/mbstring.h @@ -0,0 +1,19 @@ +#ifndef _C_MBSTRING_H +#define _C_MBSTRING_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int mbtowc(wchar_t *pwc, const char *s, int n); +int __mbtowc_noconv(wchar_t *pwc, const char *str, int n); +int __wctomb_noconv(char *s, wchar_t wchar); +size_t mbstowcs(wchar_t *pDest, const char *pSrc, size_t num); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/mem.h b/libs/c/include/mem.h new file mode 100644 index 00000000..16685dbd --- /dev/null +++ b/libs/c/include/mem.h @@ -0,0 +1,20 @@ +#ifndef _C_MEM_H +#define _C_MEM_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void *memcpy(void *dst, const void *src, int n); +void *memmove(void *dst, const void *src, size_t len); +void *memset(void *dest, int val, int n); +void *memchr(const void *src, int val, int n); +int memcmp(const void *src1, const void *src2, int n); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/mem_funcs.h b/libs/c/include/mem_funcs.h new file mode 100644 index 00000000..b83540d3 --- /dev/null +++ b/libs/c/include/mem_funcs.h @@ -0,0 +1,14 @@ +#ifndef _C_MEM_FUNCS_H +#define _C_MEM_FUNCS_H + +#ifdef __cplusplus +extern "C" { +#endif + +void __fill_mem(void *dst, int val, unsigned int n); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/printf.h b/libs/c/include/printf.h new file mode 100644 index 00000000..a4895886 --- /dev/null +++ b/libs/c/include/printf.h @@ -0,0 +1,23 @@ +#ifndef _C_PRINTF_H +#define _C_PRINTF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +int printf(const char *format, ...); +int fprintf(FILE *, const char *format, ...); +int vprintf(const char *, va_list); +int vsnprintf(char *, size_t, const char *, va_list); +int vsprintf(char *, const char *, va_list); +int snprintf(char *, size_t, const char *, ...); +int sprintf(char *, const char *, ...); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/scanf.h b/libs/c/include/scanf.h new file mode 100644 index 00000000..7dbf79d6 --- /dev/null +++ b/libs/c/include/scanf.h @@ -0,0 +1,17 @@ +#ifndef _C_SCANF_H +#define _C_SCANF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +int vsscanf(const char *, const char *, va_list); +int sscanf(const char *, const char *, ...); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/secure_error.h b/libs/c/include/secure_error.h new file mode 100644 index 00000000..16f4c1af --- /dev/null +++ b/libs/c/include/secure_error.h @@ -0,0 +1,16 @@ +#ifndef _C_SECURE_ERROR_H +#define _C_SECURE_ERROR_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*msl_constraint_handler)(int, int, int); + +void __msl_runtime_constraint_violation_s(int param1, int param2, int param3); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/signal.h b/libs/c/include/signal.h new file mode 100644 index 00000000..0b7a0289 --- /dev/null +++ b/libs/c/include/signal.h @@ -0,0 +1,18 @@ +#ifndef _C_SIGNAL_H +#define _C_SIGNAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern void exit(int); + +typedef void (*sig_func)(int sig); + +int raise(int sig); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/stdarg.h b/libs/c/include/stdarg.h new file mode 100644 index 00000000..4a5bc8a7 --- /dev/null +++ b/libs/c/include/stdarg.h @@ -0,0 +1,22 @@ +#ifndef _C_STDARG_H +#define _C_STDARG_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef char *va_list; + +#define __fourbytealign(n) ((((unsigned int) (n)) + 3U) & ~3U) +#define __va_start(parm) ((va_list) ((char *) ((unsigned int) (&parm) & ~3U) + __fourbytealign(sizeof(parm)))) + +#define va_start(ap, parm) ((ap) = __va_start(parm)) +#define va_arg(ap, type) (*(type *) ((ap += __fourbytealign(sizeof(type))) - __fourbytealign(sizeof(type)))) +#define va_end(ap) ((void) 0) +#define va_copy(dest, src) dest = src + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/stddef.h b/libs/c/include/stddef.h index 4986043a..50c727af 100644 --- a/libs/c/include/stddef.h +++ b/libs/c/include/stddef.h @@ -1,8 +1,35 @@ #ifndef _C_STDDEF_H #define _C_STDDEF_H -#define NULL 0 +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NULL + #define NULL 0 +#endif + +#ifndef nullptr + #define nullptr 0 +#endif + +#define offsetof(ST, M) ((size_t) &(((ST *) 0)->M)) + +typedef signed long intptr_t; +typedef unsigned long uintptr_t; +typedef intptr_t ptrdiff_t; typedef unsigned int size_t; +#ifndef __cplusplus +typedef int bool; +typedef unsigned short wchar_t; + #define true 1 + #define false 0 +#endif + +#ifdef __cplusplus +} +#endif + #endif diff --git a/libs/c/include/stdio.h b/libs/c/include/stdio.h new file mode 100644 index 00000000..d6ed6052 --- /dev/null +++ b/libs/c/include/stdio.h @@ -0,0 +1,22 @@ +#ifndef _C_STDIO_H +#define _C_STDIO_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// clang-format off +#include +#include +#include +#include +#include +// clang-format on + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/stdio_api.h b/libs/c/include/stdio_api.h new file mode 100644 index 00000000..bcc9bfee --- /dev/null +++ b/libs/c/include/stdio_api.h @@ -0,0 +1,53 @@ +#ifndef _C_STDIO_API_H +#define _C_STDIO_API_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum __ReadProcActions { + __GetAChar, + __UngetAChar, + __TestForError +}; + +enum __WReadProcActions { + __GetAwChar, + __UngetAwChar, + __TestForwcsError +}; + +typedef struct { + char *CharStr; + size_t MaxCharCount; + size_t CharsWritten; +} __OutStrCtrl; + +typedef struct { + char *NextChar; + int NullCharDetected; +} __InStrCtrl; + +typedef struct { + wchar_t *wCharStr; + size_t MaxCharCount; + size_t CharsWritten; +} __wOutStrCtrl; + +typedef struct { + wchar_t *wNextChar; + int wNullCharDetected; +} __wInStrCtrl; + +size_t __fwrite(const void *pPtr, size_t memb_size, size_t num_memb, FILE *file); +int __StringRead(void *, int, int); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/string.h b/libs/c/include/string.h index 6c1c86a7..2a4077cc 100644 --- a/libs/c/include/string.h +++ b/libs/c/include/string.h @@ -1,15 +1,20 @@ #ifndef _C_STRING_H #define _C_STRING_H +#ifdef __cplusplus +extern "C" { +#endif + typedef unsigned int size_t; size_t strlen(const char *str); char *strcpy(char *dest, const char *src); char *strncpy(char *dest, const char *src, size_t num); -char *strcat(char *dest, const char *src); int strcmp(char *str1, char *str2); int strncmp(char *str1, char *str2, size_t num); -const char *strchr(const char *str, char ch); -const char *strstr(const char *str1, const char *str2); + +#ifdef __cplusplus +} +#endif #endif diff --git a/libs/c/include/wchar_io.h b/libs/c/include/wchar_io.h new file mode 100644 index 00000000..7e6aa715 --- /dev/null +++ b/libs/c/include/wchar_io.h @@ -0,0 +1,16 @@ +#ifndef _C_WCHAR_H +#define _C_WCHAR_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int fwide(FILE *stream, int mode); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/include/wstring.h b/libs/c/include/wstring.h new file mode 100644 index 00000000..c45ed1e0 --- /dev/null +++ b/libs/c/include/wstring.h @@ -0,0 +1,19 @@ +#ifndef _C_WSTRING_H +#define _C_WSTRING_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +size_t wcslen(const wchar_t *str); +wchar_t *wcscpy(wchar_t *dest, const wchar_t *src); +wchar_t *wcsncpy(wchar_t *dest, const wchar_t *src, size_t n); +const wchar_t *wcschr(const wchar_t *str, wchar_t chr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libs/c/src/abort_exit_arm_eabi.c b/libs/c/src/abort_exit_arm_eabi.c new file mode 100644 index 00000000..1a5a5cd4 --- /dev/null +++ b/libs/c/src/abort_exit_arm_eabi.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include + +extern void _ExitProcess(void); + +static void (*__atexit_funcs[64])(void); +bool __aborting = false; +static int __atexit_curr_func = 0; +void (*__stdio_exit)(void) = NULL; +void (*__console_exit)(void) = NULL; + +void abort(void) { + raise(SIGABRT); + __aborting = true; + exit(EXIT_FAILURE); +} + +void exit(int status) { + if (__aborting == false) { + __destroy_global_chain(); + + if (__stdio_exit != NULL) { + __stdio_exit(); + __stdio_exit = NULL; + } + } + + __exit(status); +} + +void __exit(int status) { + __begin_critical_region(atexit_funcs_access); + + while (__atexit_curr_func > 0) { + __atexit_funcs[--__atexit_curr_func](); + } + + __end_critical_region(atexit_funcs_access); + + if (__console_exit != NULL) { + __console_exit(); + __console_exit = NULL; + } + + fflush(NULL); + + _ExitProcess(); +} diff --git a/libs/c/src/ansi_files.c b/libs/c/src/ansi_files.c new file mode 100644 index 00000000..50389d11 --- /dev/null +++ b/libs/c/src/ansi_files.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include + +static console_buff stdin_buff; +static console_buff stdout_buff; +static console_buff stderr_buff; + +FILE __files[_STATIC_FILES] = { + { + 0, + {__must_exist, __read, console_buff_mode, __console_file, 0}, + {__neutral, 0, 0, 0}, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stdin_buff, + console_buff_size, + stdin_buff, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, + { + 1, + {__must_exist, __write, console_buff_mode, __console_file, 0}, + {__neutral, 0, 0, 0}, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stdout_buff, + console_buff_size, + stdout_buff, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, + { + 2, + {__must_exist, __write, _IONBF, __console_file, 0}, + {__neutral, 0, 0, 0}, + 0, + 0, + {0, 0}, + {0, 0}, + 0, + stderr_buff, + console_buff_size, + stderr_buff, + 0, + 0, + 0, + 0, + NULL, + __read_console, + __write_console, + __close_console, + NULL, + }, +}; + +int __flush_all(void) { + int result = 0; + FILE *file = &__files[0]; + int file_index = 1; + + do { + if (file->mode.file_kind != __closed_file) { + if (fflush(file) != 0) { + result = -1; + } + } + if (file_index < 3) { + file = &__files[file_index++]; + } else { + file = NULL; + } + } while (file != NULL); + + return result; +} diff --git a/libs/c/src/ansi_fp.c b/libs/c/src/ansi_fp.c new file mode 100644 index 00000000..e4790a19 --- /dev/null +++ b/libs/c/src/ansi_fp.c @@ -0,0 +1,367 @@ +#include +#include +#include +#include + +#pragma dont_reuse_strings off + +typedef unsigned long long d_int; +#define SIGDIGLEN 32 + +static inline int count_trailing(double x) { + return __builtin___count_trailing_zero64(*(unsigned long long *) &x | 0x0010000000000000); +} + +static inline int __count_trailing_zerol(unsigned int x) { + return 32 - __cntlzw(~x & (x - 1)); +} + +static inline int __count_trailing_zero(double n) { + unsigned int *array = (unsigned int *) &n; + + unsigned int hi = array[1] | 0x100000; + unsigned int lo = array[0]; + int zeros = __count_trailing_zerol(lo); + + if (lo == 0) { + return 32 + __count_trailing_zerol(hi); + } + + return zeros; +} + +static int __must_round(const decimal *d, int digits) { + unsigned char const *i = d->sig.text + digits; + + if (*i > 5) { + return 1; + } + + if (*i < 5) { + return -1; + } + + { + unsigned char const *e = d->sig.text + d->sig.length; + + for (i++; i < e; i++) { + if (*i != 0) { + return 1; + } + } + } + + if (d->sig.text[digits - 1] & 1) { + return 1; + } + + return -1; +} + +static void __dorounddecup(decimal *d, int digits) { + unsigned char *b = d->sig.text; + unsigned char *i = b + digits - 1; + + while (1) { + if (*i < 9) { + *i += 1; + break; + } + if (i == b) { + *i = 1; + d->exp++; + break; + } + *i-- = 0; + } +} + +static void __rounddec(decimal *d, int digits) { + if (digits > 0 && digits < d->sig.length) { + int unkBool = __must_round(d, digits); + d->sig.length = digits; + + if (unkBool >= 0) { + __dorounddecup(d, digits); + } + } +} + +void __ull2dec(decimal *result, unsigned long long val) { + result->sgn = 0; + result->sig.length = 0; + + for (; val != 0; val /= 10) { + result->sig.text[result->sig.length++] = (unsigned char) (val % 10); + } + + { + unsigned char *i = result->sig.text; + unsigned char *j = result->sig.text + result->sig.length; + + for (; i < --j; ++i) { + unsigned char t = *i; + *i = *j; + *j = t; + } + } + + result->exp = result->sig.length - 1; +} + +void __timesdec(decimal *result, const decimal *x, const decimal *y) { + unsigned int accumulator = 0; + unsigned char mantissa[SIGDIGLEN * 2]; + int i = x->sig.length + y->sig.length - 1; + unsigned char *pDigit; + unsigned char *ip = mantissa + i + 1; + unsigned char *ep = ip; + + result->sgn = 0; + + for (; i > 0; i--) { + int k = y->sig.length - 1; + int j = i - k - 1; + int l; + int t; + const unsigned char *jp; + const unsigned char *kp; + + if (j < 0) { + j = 0; + k = i - 1; + } + + jp = x->sig.text + j; + kp = y->sig.text + k; + l = k + 1; + t = x->sig.length - j; + + if (l > t) { + l = t; + } + + for (; l > 0; l--, jp++, kp--) { + accumulator += *jp * *kp; + } + + *--ip = (unsigned char) (accumulator % 10); + accumulator /= 10; + } + + result->exp = (short) (x->exp + y->exp); + + if (accumulator) { + *--ip = (unsigned char) (accumulator); + result->exp++; + } + + for (i = 0; i < SIGDIGLEN && ip < ep; i++, ip++) { + result->sig.text[i] = *ip; + } + result->sig.length = (unsigned char) (i); + + if (ip < ep && *ip >= 5) { + if (*ip == 5) { + unsigned char *jp = ip + 1; + for (; jp < ep; jp++) { + if (*jp != 0) { + goto round; + } + } + if ((ip[-1] & 1) == 0) { + return; + } + } + round: + __dorounddecup(result, result->sig.length); + } +} + +void __str2dec(decimal *d, const char *str, short exp) { + const unsigned char *s = (const unsigned char *) str; + int i; + + d->exp = exp; + d->sgn = 0; + + for (i = 0; i < SIGDIGLEN && *s;) { + d->sig.text[i++] = *s++ - '0'; + } + d->sig.length = i; + + if (*s != 0) { + if (*s < 5) { + return; + } + if (*s > 5) { + goto round; + } + + { + const unsigned char *p = s + 1; + + for (; *p != 0; p++) { + if (*p != '0') { + goto round; + } + } + + if ((d->sig.text[i - 1] & 1) == 0) { + return; + } + } + round: + __dorounddecup(d, d->sig.length); + } +} + +void __two_exp(decimal *result, long exp) { + switch (exp) { + case -64: + __str2dec(result, "542101086242752217003726400434970855712890625", -20); + return; + case -53: + __str2dec(result, "11102230246251565404236316680908203125", -16); + return; + case -32: + __str2dec(result, "23283064365386962890625", -10); + return; + case -16: + __str2dec(result, "152587890625", -5); + return; + case -8: + __str2dec(result, "390625", -3); + return; + case -7: + __str2dec(result, "78125", -3); + return; + case -6: + __str2dec(result, "15625", -2); + return; + case -5: + __str2dec(result, "3125", -2); + return; + case -4: + __str2dec(result, "625", -2); + return; + case -3: + __str2dec(result, "125", -1); + return; + case -2: + __str2dec(result, "25", -1); + return; + case -1: + __str2dec(result, "5", -1); + return; + case 0: + __str2dec(result, "1", 0); + return; + case 1: + __str2dec(result, "2", 0); + return; + case 2: + __str2dec(result, "4", 0); + return; + case 3: + __str2dec(result, "8", 0); + return; + case 4: + __str2dec(result, "16", 1); + return; + case 5: + __str2dec(result, "32", 1); + return; + case 6: + __str2dec(result, "64", 1); + return; + case 7: + __str2dec(result, "128", 2); + return; + case 8: + __str2dec(result, "256", 2); + return; + } + + { + decimal x2, temp; + + __two_exp(&x2, ((long) ((0x80000000UL & exp) >> 31) + exp) >> 1); + __timesdec(result, &x2, &x2); + + if (exp & 1) { + temp = *result; + + if (exp > 0) { + __str2dec(&x2, "2", 0); + } else { + __str2dec(&x2, "5", -1); + } + + __timesdec(result, &temp, &x2); + } + } +} + +// non-matching: https://decomp.me/scratch/xVomE +void __num2dec_internal(decimal *d, double x) { + char sign = (char) (signbit(x) != 0); + + if (x == 0) { + d->sgn = sign; + d->exp = 0; + d->sig.length = 1; + d->sig.text[0] = 0; + return; + } + + if (!isfinite(x)) { + d->sgn = sign; + d->exp = 0; + d->sig.length = 1; + d->sig.text[0] = fpclassify(x) == 1 ? 'N' : 'I'; + return; + } + + if (sign != 0) { + x = -x; + } + + { + int exp; + double frac = frexp(x, &exp); + int num_bits_extract = 53 - __count_trailing_zero(frac); + decimal int_d, pow2_d; + + __two_exp(&pow2_d, exp - num_bits_extract); + __ull2dec(&int_d, ldexp(frac, num_bits_extract)); + __timesdec(d, &int_d, &pow2_d); + d->sgn = sign; + } +} + +void __num2dec(const decform *form, double x, decimal *d) { + short digits = form->digits; + int i; + __num2dec_internal(d, x); + + if (d->sig.text[0] > 9) { + return; + } + + if (digits > SIGDIGLEN) { + digits = SIGDIGLEN; + } + + __rounddec(d, digits); + + while (d->sig.length < digits) { + d->sig.text[d->sig.length++] = 0; + } + + d->exp -= d->sig.length - 1; + + for (i = 0; i < d->sig.length; i++) { + d->sig.text[i] += '0'; + } +} diff --git a/libs/c/src/arith.c b/libs/c/src/arith.c new file mode 100644 index 00000000..949884f3 --- /dev/null +++ b/libs/c/src/arith.c @@ -0,0 +1,9 @@ +#include + +int abs(int __x) { + return __x < 0 ? -__x : __x; +} + +long labs(long __x) { + return __x < 0 ? -__x : __x; +} diff --git a/libs/c/src/buffer_io.c b/libs/c/src/buffer_io.c new file mode 100644 index 00000000..fd84b072 --- /dev/null +++ b/libs/c/src/buffer_io.c @@ -0,0 +1,40 @@ +#include + +void __convert_from_newlines(unsigned char *p, int *n) {} + +void __prep_buffer(FILE *file) { + file->buffer_ptr = file->buffer; + file->buffer_len = file->buffer_size; + file->buffer_len = file->buffer_len - (file->position & file->buffer_alignment); + file->buffer_pos = file->position; + return; +} + +int __flush_buffer(FILE *file, size_t *length) { + size_t bufferLen; + int writeCode; + + bufferLen = file->buffer_ptr - file->buffer; + if (bufferLen) { + file->buffer_len = bufferLen; + + if (file->mode.binary_io == 0) { + __convert_from_newlines(file->buffer, &file->buffer_len); + } + + writeCode = file->write_proc(file->handle, file->buffer, &file->buffer_len, file->ref_con); + + if (length) { + *length = file->buffer_len; + } + + if (writeCode) { + return writeCode; + } + + file->position += file->buffer_len; + } + + __prep_buffer(file); + return 0; +} diff --git a/libs/c/src/code_02038bac.c b/libs/c/src/code_02038bac.c new file mode 100644 index 00000000..e69de29b diff --git a/libs/c/src/extras.c b/libs/c/src/extras.c new file mode 100644 index 00000000..fb1b805f --- /dev/null +++ b/libs/c/src/extras.c @@ -0,0 +1,11 @@ +#include + +double scalbn(double x, int n) { + double value; + int exp; + + value = frexp(x, &exp); + exp += n; + + return ldexp(value, exp); +} diff --git a/libs/c/src/file_io.c b/libs/c/src/file_io.c new file mode 100644 index 00000000..86279936 --- /dev/null +++ b/libs/c/src/file_io.c @@ -0,0 +1,39 @@ +#include + +int fflush(FILE *file) { + if (file == NULL) { + return __flush_all(); + } + + if (file->state.error != 0 || file->mode.file_kind == __closed_file) { + return -1; + } + + if (file->mode.io_mode == 1) { + return 0; + } + + if (file->state.io_state >= 3) { + file->state.io_state = 2; + } + + if (file->state.io_state == 2) { + file->buffer_len = 0; + } + + if (file->state.io_state != 1) { + file->state.io_state = 0; + return 0; + } + + if (__flush_buffer(file, 0) != 0) { + file->state.error = 1; + file->buffer_len = 0; + return -1; + } + + file->state.io_state = 0; + file->position = 0; + file->buffer_len = 0; + return 0; +} diff --git a/libs/c/src/float.c b/libs/c/src/float.c new file mode 100644 index 00000000..b8156624 --- /dev/null +++ b/libs/c/src/float.c @@ -0,0 +1 @@ +int __float_nan[] = {0x7FFFFFFF}; diff --git a/libs/c/src/locale.c b/libs/c/src/locale.c new file mode 100644 index 00000000..4ff881fb --- /dev/null +++ b/libs/c/src/locale.c @@ -0,0 +1,43 @@ +#include +#include + +struct _loc_ctype_cmpt __ctype_cmpt = { + .decode_mb = __mbtowc_noconv, + .encode_wc = __wctomb_noconv, +}; + +unsigned short char_coll_table[0x60] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x2b, 0x2d, 0x2f, 0x31, 0x33, + 0x35, 0x37, 0x39, 0x3b, 0x3d, 0x3f, 0x41, 0x43, 0x45, 0x47, 0x49, 0x4b, 0x4d, 0x4f, 0x51, 0x53, 0x55, 0x57, 0x59, + 0x5b, 0x5d, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x00, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e, 0x40, + 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x1d, 0x1e, 0x1f, 0x20, +}; + +struct _loc_coll_cmpt __coll_cmpt = { + .char_start_value = ' ', + .char_coll_tab_size = 110, + .char_spec_accents = 0, + .char_coll_table_ptr = &char_coll_table[0], +}; + +struct _loc_time_cmpt __time_cmpt = { + .am_pm = "AM|PM", + .DateTime_Format = "%a %b %e %T %Y", + .Twelve_hr_format = "%I:%M:%S %p", + .Date_Format = "%m/%d/%y", + .Time_Format = "%T", + .Day_Names = "Sun|Sunday|Mon|Monday|Tue|Tuesday|Wed|Wednesday" + "|Thu|Thursday|Fri|Friday|Sat|Saturday", + .MonthNames = "Jan|January|Feb|February|Mar|March" + "|Apr|April|May|May|Jun|June" + "|Jul|July|Aug|August|Sep|September" + "|Oct|October|Nov|November|Dec|December", + .TimeZone = "", +}; + +struct __locale _current_locale = { + .time_cmpt_ptr = &__time_cmpt, + .coll_cmpt_ptr = &__coll_cmpt, + .ctype_cmpt_ptr = &__ctype_cmpt, +}; diff --git a/libs/c/src/math/e_log.c b/libs/c/src/math/e_log.c new file mode 100644 index 00000000..490867dc --- /dev/null +++ b/libs/c/src/math/e_log.c @@ -0,0 +1,161 @@ +/* @(#)e_log.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_log(x) + * Return the logrithm of x + * + * Method : + * 1. Argument Reduction: find k and f such that + * x = 2^k * (1+f), + * where sqrt(2)/2 < 1+f < sqrt(2) . + * + * 2. Approximation of log(1+f). + * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) + * = 2s + 2/3 s**3 + 2/5 s**5 + ....., + * = 2s + s*R + * We use a special Reme algorithm on [0,0.1716] to generate + * a polynomial of degree 14 to approximate R The maximum error + * of this polynomial approximation is bounded by 2**-58.45. In + * other words, + * 2 4 6 8 10 12 14 + * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s + * (the values of Lg1 to Lg7 are listed in the program) + * and + * | 2 14 | -58.45 + * | Lg1*s +...+Lg7*s - R(z) | <= 2 + * | | + * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. + * In order to guarantee error in log below 1ulp, we compute log + * by + * log(1+f) = f - s*(f - R) (if f is not too large) + * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) + * + * 3. Finally, log(x) = k*ln2 + log(1+f). + * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) + * Here ln2 is split into two floating point number: + * ln2_hi + ln2_lo, + * where n*ln2_hi is always exact for |n| < 2000. + * + * Special cases: + * log(x) is NaN with signal if x < 0 (including -INF) ; + * log(+INF) is +INF; log(0) is -INF with signal; + * log(NaN) is that NaN with no signal. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * 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 + +#ifdef __STDC__ +static const double +#else +static double +#endif + ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ + ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ + two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ + Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ + Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ + Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ + Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ + Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ + Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ + Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ + +static double zero = 0.0; + +#ifdef __STDC__ +double __ieee754_log(double x) +#else +double __ieee754_log(x) +double x; +#endif +{ + double hfsq, f, s, z, R, w, t1, t2, dk; + int k, hx, i, j; + unsigned lx; + + hx = __HI(x); /* high word of x */ + lx = __LO(x); /* low word of x */ + + k = 0; + if (hx < 0x00100000) { /* x < 2**-1022 */ + if (((hx & 0x7fffffff) | lx) == 0) { + return -two54 / zero; /* log(+-0)=-inf */ + } + if (hx < 0) { + errno = EDOM; + return (x - x) / zero; + } /* log(-#) = NaN */ + k -= 54; + x *= two54; /* subnormal number, scale up x */ + hx = __HI(x); /* high word of x */ + } + if (hx >= 0x7ff00000) { + return x + x; + } + k += (hx >> 20) - 1023; + hx &= 0x000fffff; + i = (hx + 0x95f64) & 0x100000; + __HI(x) = hx | (i ^ 0x3ff00000); /* normalize x or x/2 */ + k += (i >> 20); + f = x - 1.0; + if ((0x000fffff & (2 + hx)) < 3) { /* |f| < 2**-20 */ + if (f == zero) { + if (k == 0) { + return zero; + } else { + dk = (double) k; + return dk * ln2_hi + dk * ln2_lo; + } + } + R = f * f * (0.5 - 0.33333333333333333 * f); + if (k == 0) { + return f - R; + } else { + dk = (double) k; + return dk * ln2_hi - ((R - dk * ln2_lo) - f); + } + } + s = f / (2.0 + f); + dk = (double) k; + z = s * s; + i = hx - 0x6147a; + w = z * z; + j = 0x6b851 - hx; + t1 = w * (Lg2 + w * (Lg4 + w * Lg6)); + t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7))); + i |= j; + R = t2 + t1; + if (i > 0) { + hfsq = 0.5 * f * f; + if (k == 0) { + return f - (hfsq - s * (hfsq + R)); + } else { + return dk * ln2_hi - ((hfsq - (s * (hfsq + R) + dk * ln2_lo)) - f); + } + } else { + if (k == 0) { + return f - s * (f - R); + } else { + return dk * ln2_hi - ((s * (f - R) - dk * ln2_lo) - f); + } + } +} diff --git a/libs/c/src/math/e_log10.c b/libs/c/src/math/e_log10.c new file mode 100644 index 00000000..fb8e3f02 --- /dev/null +++ b/libs/c/src/math/e_log10.c @@ -0,0 +1,99 @@ + +/* @(#)e_log10.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_log10(x) + * Return the base 10 logarithm of x + * + * Method : + * Let log10_2hi = leading 40 bits of log10(2) and + * log10_2lo = log10(2) - log10_2hi, + * ivln10 = 1/log(10) rounded. + * Then + * n = ilogb(x), + * if(n<0) n = n+1; + * x = scalbn(x,-n); + * log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x)) + * + * Note 1: + * To guarantee log10(10**n)=n, where 10**n is normal, the rounding + * mode must set to Round-to-Nearest. + * Note 2: + * [1/log(10)] rounded to 53 bits has error .198 ulps; + * log10 is monotonic at all binary break points. + * + * Special cases: + * log10(x) is NaN with signal if x < 0; + * log10(+INF) is +INF with no signal; log10(0) is -INF with signal; + * log10(NaN) is that NaN with no signal; + * log10(10**N) = N for N=0,1,...,22. + * + * 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 + +#ifdef __STDC__ +static const double +#else +static double +#endif + two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ + ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */ + log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ + log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */ + +static double zero = 0.0; + +#ifdef __STDC__ +double __ieee754_log10(double x) +#else +double __ieee754_log10(x) +double x; +#endif +{ + double y, z; + int i, k, hx; + unsigned lx; + + hx = __HI(x); /* high word of x */ + lx = __LO(x); /* low word of x */ + + k = 0; + if (hx < 0x00100000) { /* x < 2**-1022 */ + if (((hx & 0x7fffffff) | lx) == 0) { + errno = EDOM; + return -two54 / zero; + } /* log(+-0)=-inf */ + if (hx < 0) { + errno = EDOM; + return (x - x) / zero; + } /* log(-#) = NaN */ + k -= 54; + x *= two54; /* subnormal number, scale up x */ + hx = __HI(x); /* high word of x */ + } + if (hx >= 0x7ff00000) { + return x + x; + } + k += (hx >> 20) - 1023; + i = ((unsigned) k & 0x80000000) >> 31; + hx = (hx & 0x000fffff) | ((0x3ff - i) << 20); + y = (double) (k + i); + __HI(x) = hx; + z = y * log10_2lo + ivln10 * log(x); + return z + y * log10_2hi; +} diff --git a/libs/c/src/math/e_pow.c b/libs/c/src/math/e_pow.c new file mode 100644 index 00000000..d4f439af --- /dev/null +++ b/libs/c/src/math/e_pow.c @@ -0,0 +1,370 @@ +/* @(#)e_pow.c 1.2 95/01/04 */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + +/* __ieee754_pow(x,y) return x**y + * + * n + * Method: Let x = 2 * (1+f) + * 1. Compute and return log2(x) in two pieces: + * log2(x) = w1 + w2, + * where w1 has 53-24 = 29 bit trailing zeros. + * 2. Perform y*log2(x) = n+y' by simulating muti-precision + * arithmetic, where |y'|<=0.5. + * 3. Return x**y = 2**n*exp(y'*log2) + * + * Special cases: + * 1. (anything) ** 0 is 1 + * 2. (anything) ** 1 is itself + * 3. (anything) ** NAN is NAN + * 4. NAN ** (anything except 0) is NAN + * 5. +-(|x| > 1) ** +INF is +INF + * 6. +-(|x| > 1) ** -INF is +0 + * 7. +-(|x| < 1) ** +INF is +0 + * 8. +-(|x| < 1) ** -INF is +INF + * 9. +-1 ** +-INF is NAN + * 10. +0 ** (+anything except 0, NAN) is +0 + * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 + * 12. +0 ** (-anything except 0, NAN) is +INF + * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF + * 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) + * 15. +INF ** (+anything except 0,NAN) is +INF + * 16. +INF ** (-anything except 0,NAN) is +0 + * 17. -INF ** (anything) = -0 ** (-anything) + * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) + * 19. (-anything except 0 and inf) ** (non-integer) is NAN + * + * Accuracy: + * pow(x,y) returns x**y nearly rounded. In particular + * pow(integer,integer) + * always returns the correct integer provided it is + * representable. + * + * 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 +#ifdef __STDC__ +static const double +#else +static double +#endif + bp[] = + { + 1.0, + 1.5, +}, + dp_h[] = + { + 0.0, + 5.84962487220764160156e-01, +}, /* 0x3FE2B803, 0x40000000 */ + dp_l[] = + { + 0.0, + 1.35003920212974897128e-08, +}, /* 0x3E4CFDEB, 0x43CFD006 */ + zero = 0.0, one = 1.0, two = 2.0, two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ + big = 1.0e300, tiny = 1.0e-300, + /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ + L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */ + L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */ + L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */ + L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */ + L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */ + L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */ + P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ + P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ + P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ + P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ + P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ + lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ + lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */ + lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */ + ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */ + cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */ + cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */ + cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/ + ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ + ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ + ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ + +#ifdef __STDC__ +double __ieee754_pow(double x, double y) +#else +double __ieee754_pow(x, y) +double x, y; +#endif +{ + double z, ax, z_h, z_l, p_h, p_l; + double y1, t1, t2, r, s, t, u, v, w; + int i, j, k, yisint, n; + int hx, hy, ix, iy; + unsigned int lx, ly; + + hx = __HI(x); + lx = __LO(x); + hy = __HI(y); + ly = __LO(y); + ix = hx & 0x7fffffff; + iy = hy & 0x7fffffff; + + /* y==zero: x**0 = 1 */ + if ((iy | ly) == 0) { + return one; + } + + /* +-NaN return x+y */ + if (ix > 0x7ff00000 || ((ix == 0x7ff00000) && (lx != 0)) || iy > 0x7ff00000 || ((iy == 0x7ff00000) && (ly != 0))) { + return x + y; +#ifdef __STDC__ + errno = EDOM; /* mf-- added to conform to old ANSI standard */ +#endif + } + + /* determine if y is an odd int when x < 0 + * yisint = 0 ... y is not an integer + * yisint = 1 ... y is an odd int + * yisint = 2 ... y is an even int + */ + yisint = 0; + if (hx < 0) { + if (iy >= 0x43400000) { + yisint = 2; /* even integer y */ + } else if (iy >= 0x3ff00000) { + k = (iy >> 20) - 0x3ff; /* exponent */ + if (k > 20) { + j = ly >> (52 - k); + if ((j << (52 - k)) == ly) { + yisint = 2 - (j & 1); + } + } else if (ly == 0) { + j = iy >> (20 - k); + if ((j << (20 - k)) == iy) { + yisint = 2 - (j & 1); + } + } + } + } + + /* special value of y */ + if (ly == 0) { + if (iy == 0x7ff00000) { + + /* y is +-inf */ + if (((ix - 0x3ff00000) | lx) == 0) { + return y - y; /* inf**+-1 is NaN */ + } else if (ix >= 0x3ff00000) { /* (|x|>1)**+-inf = inf,0 */ + return (hy >= 0) ? y : zero; + } else { /* (|x|<1)**-,+inf = inf,0 */ + return (hy < 0) ? -y : zero; + } + } + if (iy == 0x3ff00000) { + /* y is +-1 */ + if (hy < 0) { + return one / x; + } else { + return x; + } + } + if (hy == 0x40000000) { + return x * x; /* y is 2 */ + } + if (hy == 0x3fe00000) { /* y is 0.5 */ + if (hx >= 0) { /* x >= +0 */ + return sqrt(x); + } + } + } + + ax = fabs(x); + /* special value of x */ + if (lx == 0) { + if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000) { + z = ax; /*x is +-0,+-inf,+-1*/ + if (hy < 0) { + z = one / z; /* z = (1/|x|) */ + } + if (hx < 0) { + if (((ix - 0x3ff00000) | yisint) == 0) { + z = (z - z) / (z - z); /* (-1)**non-int is NaN */ + } else if (yisint == 1) { + z = -z; /* (x<0)**odd = -(|x|**odd) */ + } + } + return z; + } + } + + /* (x<0)**(non-int) is NaN */ + if ((((hx >> 31) + 1) | yisint) == 0) { +#ifdef __STDC__ + errno = EDOM; /* mf-- added to conform to old ANSI standard */ +#endif + return NAN; + } + + /* |y| is big */ + if (iy > 0x41e00000) { /* if |y| > 2**31 */ + if (iy > 0x43f00000) { /* if |y| > 2**64, must o/uflow */ + if (ix <= 0x3fefffff) { + return (hy < 0) ? big * big : tiny * tiny; + } + if (ix >= 0x3ff00000) { + return (hy > 0) ? big * big : tiny * tiny; + } + } + /* over/underflow if x is not close to one */ + if (ix < 0x3fefffff) { + return (hy < 0) ? big * big : tiny * tiny; + } + if (ix > 0x3ff00000) { + return (hy > 0) ? big * big : tiny * tiny; + } + /* now |1-x| is tiny <= 2**-20, suffice to compute + log(x) by x-x^2/2+x^3/3-x^4/4 */ + t = x - 1; /* t has 20 trailing zeros */ + w = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25)); + u = ivln2_h * t; /* ivln2_h has 21 sig. bits */ + v = t * ivln2_l - w * ivln2; + t1 = u + v; + __LO(t1) = 0; + t2 = v - (t1 - u); + } else { + double s2, s_h, s_l, t_h, t_l; + n = 0; + /* take care subnormal number */ + if (ix < 0x00100000) { + ax *= two53; + n -= 53; + ix = __HI(ax); + } + n += ((ix) >> 20) - 0x3ff; + j = ix & 0x000fffff; + /* determine interval */ + ix = j | 0x3ff00000; /* normalize ix */ + if (j <= 0x3988E) { + k = 0; /* |x|> 1) | 0x20000000) + 0x00080000 + (k << 18); + t_l = ax - (t_h - bp[k]); + s_l = v * ((u - s_h * t_h) - s_h * t_l); + /* compute log(ax) */ + s2 = s * s; + r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); + r += s_l * (s_h + s); + s2 = s_h * s_h; + t_h = 3.0 + s2 + r; + __LO(t_h) = 0; + t_l = r - ((t_h - 3.0) - s2); + /* u+v = s*(1+...) */ + u = s_h * t_h; + v = s_l * t_h + t_l * s; + /* 2/(3log2)*(s+...) */ + p_h = u + v; + __LO(p_h) = 0; + p_l = v - (p_h - u); + z_h = cp_h * p_h; /* cp_h+cp_l = 2/(3*log2) */ + z_l = cp_l * p_h + p_l * cp + dp_l[k]; + /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */ + t = (double) n; + t1 = (((z_h + z_l) + dp_h[k]) + t); + __LO(t1) = 0; + t2 = z_l - (((t1 - t) - dp_h[k]) - z_h); + } + + s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ + if ((((hx >> 31) + 1) | (yisint - 1)) == 0) { + s = -one; /* (-ve)**(odd int) */ + } + + /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ + y1 = y; + __LO(y1) = 0; + p_l = (y - y1) * t1 + y * t2; + p_h = y1 * t1; + z = p_l + p_h; + j = __HI(z); + i = __LO(z); + if (j >= 0x40900000) { /* z >= 1024 */ + if (((j - 0x40900000) | i) != 0) { /* if z > 1024 */ + return s * big * big; /* overflow */ + } else { + if (p_l + ovt > z - p_h) { + return s * big * big; /* overflow */ + } + } + } else if ((j & 0x7fffffff) >= 0x4090cc00) { /* z <= -1075 */ + if (((j - 0xc090cc00) | i) != 0) { /* z < -1075 */ + return s * tiny * tiny; /* underflow */ + } else { + if (p_l <= z - p_h) { + return s * tiny * tiny; /* underflow */ + } + } + } + /* + * compute 2**(p_h+p_l) + */ + i = j & 0x7fffffff; + k = (i >> 20) - 0x3ff; + n = 0; + if (i > 0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ + n = j + (0x00100000 >> (k + 1)); + k = ((n & 0x7fffffff) >> 20) - 0x3ff; /* new k for n */ + t = zero; + __HI(t) = (n & ~(0x000fffff >> k)); + n = ((n & 0x000fffff) | 0x00100000) >> (20 - k); + if (j < 0) { + n = -n; + } + p_h -= t; + } + t = p_l + p_h; + __LO(t) = 0; + u = t * lg2_h; + v = (p_l - (t - p_h)) * lg2 + t * lg2_l; + z = u + v; + w = v - (z - u); + t = z * z; + t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); + r = (z * t1) / (t1 - two) - (w + z * w); + z = one - (r - z); + j = __HI(z); + j += (n << 20); + if ((j >> 20) <= 0) { + z = scalbn(z, n); /* subnormal output */ + } else { + __HI(z) += (n << 20); + } + return s * z; +} diff --git a/libs/c/src/math/s_ceil.c b/libs/c/src/math/s_ceil.c new file mode 100644 index 00000000..bdfadf57 --- /dev/null +++ b/libs/c/src/math/s_ceil.c @@ -0,0 +1,96 @@ + +/* @(#)s_ceil.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. + * ==================================================== + */ + +/* + * ceil(x) + * Return x rounded toward -inf to integral value + * Method: + * Bit twiddling. + * Exception: + * Inexact flag raised if x not equal to ceil(x). + */ + +#include + +#ifdef __STDC__ +static const double huge = 1.0e300; +#else +static double huge = 1.0e300; +#endif + +#ifdef __STDC__ +double ceil(double x) +#else +double ceil(x) +double x; +#endif +{ + int i0, i1, j0; + unsigned i, j; + i0 = __HI(x); + i1 = __LO(x); + j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; + if (j0 < 20) { + if (j0 < 0) { /* raise inexact if x != 0 */ + if (huge + x > 0.0) { /* return 0*sign(x) if |x|<1 */ + if (i0 < 0) { + i0 = 0x80000000; + i1 = 0; + } else if ((i0 | i1) != 0) { + i0 = 0x3ff00000; + i1 = 0; + } + } + } else { + i = (0x000fffff) >> j0; + if (((i0 & i) | i1) == 0) { + return x; /* x is integral */ + } + if (huge + x > 0.0) { /* raise inexact flag */ + if (i0 > 0) { + i0 += (0x00100000) >> j0; + } + i0 &= (~i); + i1 = 0; + } + } + } else if (j0 > 51) { + if (j0 == 0x400) { + return x + x; /* inf or NaN */ + } else { + return x; /* x is integral */ + } + } else { + i = ((unsigned) (0xffffffff)) >> (j0 - 20); + if ((i1 & i) == 0) { + return x; /* x is integral */ + } + if (huge + x > 0.0) { /* raise inexact flag */ + if (i0 > 0) { + if (j0 == 20) { + i0 += 1; + } else { + j = i1 + (1 << (52 - j0)); + if (j < i1) { + i0 += 1; /* got a carry */ + } + i1 = j; + } + } + i1 &= (~i); + } + } + __HI(x) = i0; + __LO(x) = i1; + return x; +} diff --git a/libs/c/src/math/s_copysign.c b/libs/c/src/math/s_copysign.c new file mode 100644 index 00000000..7620785a --- /dev/null +++ b/libs/c/src/math/s_copysign.c @@ -0,0 +1,31 @@ + +/* @(#)s_copysign.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. + * ==================================================== + */ + +/* + * copysign(double x, double y) + * copysign(x,y) returns a value with the magnitude of x and + * with the sign bit of y. + */ + +#include + +#ifdef __STDC__ +double copysign(double x, double y) +#else +double copysign(x, y) +double x, y; +#endif +{ + __HI(x) = (__HI(x) & 0x7fffffff) | (__HI(y) & 0x80000000); + return x; +} diff --git a/libs/c/src/math/s_fabs.c b/libs/c/src/math/s_fabs.c new file mode 100644 index 00000000..8a20ac39 --- /dev/null +++ b/libs/c/src/math/s_fabs.c @@ -0,0 +1,29 @@ + +/* @(#)s_fabs.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. + * ==================================================== + */ + +/* + * fabs(x) returns the absolute value of x. + */ + +#include + +#ifdef __STDC__ +double fabs(double x) +#else +double fabs(x) +double x; +#endif +{ + __HI(x) &= 0x7fffffff; + return x; +} diff --git a/libs/c/src/math/s_frexp.c b/libs/c/src/math/s_frexp.c new file mode 100644 index 00000000..3d59073c --- /dev/null +++ b/libs/c/src/math/s_frexp.c @@ -0,0 +1,59 @@ + +/* @(#)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 + +#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/libs/c/src/math/s_ldexp.c b/libs/c/src/math/s_ldexp.c new file mode 100644 index 00000000..dcd43bc8 --- /dev/null +++ b/libs/c/src/math/s_ldexp.c @@ -0,0 +1,66 @@ +#ifndef _No_Floating_Point +/* @(#)s_ldexp.c 1.2 95/01/04 */ +/* $Id: s_ldexp.c,v 1.3.14.1 2002/01/31 15:24:14 ceciliar Exp $ */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + + #include + +static const double two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ + twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ + big = 1.0e+300, tiny = 1.0e-300; + +double ldexp(double x, int n) { + int k, hx, lx; + if (!isfinite(x) || x == 0.0) { + return x; + } + + hx = __HI(x); + lx = __LO(x); + k = (hx & 0x7ff00000) >> 20; /* extract exponent */ + if (k == 0) { /* 0 or subnormal x */ + if ((lx | (hx & 0x7fffffff)) == 0) { + return x; /* +-0 */ + } + x *= two54; + hx = __HI(x); + k = ((hx & 0x7ff00000) >> 20) - 54; + if (n < -50000) { + return tiny * x; /*underflow*/ + } + } + if (k == 0x7ff) { + return x + x; /* NaN or Inf */ + } + k = k + n; + if (k > 0x7fe) { + return big * copysign(big, x); /* overflow */ + } + if (k > 0) /* normal result */ + { + __HI(x) = (hx & 0x800fffff) | (k << 20); + return x; + } + if (k <= -54) { + if (n > 50000) { /* in case integer overflow in n+k */ + return big * copysign(big, x); /*overflow*/ + } else { + return tiny * copysign(tiny, x); /*underflow*/ + } + } + k += 54; /* subnormal result */ + __HI(x) = (hx & 0x800fffff) | (k << 20); + return x * twom54; +} + +/* changed __finite to __isfinite to match new naming convention 141097 bds */ +#endif /* _No_Floating_Point */ diff --git a/libs/c/src/math/w_log.c b/libs/c/src/math/w_log.c new file mode 100644 index 00000000..a1f67e7e --- /dev/null +++ b/libs/c/src/math/w_log.c @@ -0,0 +1,16 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +extern double __ieee754_log(); + +double log(double __x) { + return (double) __ieee754_log(); +} diff --git a/libs/c/src/math/w_log10f.c b/libs/c/src/math/w_log10f.c new file mode 100644 index 00000000..368a738a --- /dev/null +++ b/libs/c/src/math/w_log10f.c @@ -0,0 +1,16 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +extern double __ieee754_log10(); + +double log10f(double __x) { + return (double) __ieee754_log10(); +} diff --git a/libs/c/src/math/w_pow.c b/libs/c/src/math/w_pow.c new file mode 100644 index 00000000..6f8d2eba --- /dev/null +++ b/libs/c/src/math/w_pow.c @@ -0,0 +1,16 @@ +/* + * ==================================================== + * 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. + * ==================================================== + */ + +extern double __ieee754_pow(); + +double pow(double __x, double __y) { + return (double) __ieee754_pow(); +} diff --git a/libs/c/src/math_api.c b/libs/c/src/math_api.c new file mode 100644 index 00000000..9a689e39 --- /dev/null +++ b/libs/c/src/math_api.c @@ -0,0 +1,26 @@ +#include + +int __signbitd(double x) { + return (__HI(x) & 0x80000000) != 0; +} + +int __fpclassifyd(double x) { + switch (__HI(x) & 0x7FF00000) { + case 0x7FF00000: + if ((__HI(x) & 0x000FFFFF) || (__LO(x) & 0xFFFFFFFF)) { + return 1; + } else { + return 2; + } + break; + case 0: + if ((__HI(x) & 0x000FFFFf) || (__LO(x) & 0xFFFFFFFF)) { + return 5; + } else { + return 3; + } + break; + } + + return 4; +} diff --git a/libs/c/src/mbstring.c b/libs/c/src/mbstring.c new file mode 100644 index 00000000..a8794c73 --- /dev/null +++ b/libs/c/src/mbstring.c @@ -0,0 +1,72 @@ +#include +#include + +char *strncpy(char *dest, const char *src, size_t n); +size_t strlen(const char *str); + +int mbtowc(short *pwc, const char *s, int n) { + return _current_locale.ctype_cmpt_ptr->decode_mb(pwc, s, n); +} + +int __mbtowc_noconv(unsigned short *pwc, const char *str, int n) { + const unsigned char *s = (const unsigned char *) str; + + if (s == NULL) { + return 0; + } + + if (n == 0) { + return -1; + } + + if (pwc != NULL) { + *pwc = (unsigned char) *s; + } + + if (*s == 0) { + return 0; + } + + return 1; +} + +int __wctomb_noconv(char *s, unsigned short wchar) { + if (s == NULL) { + return 0; + } + *s = wchar; + return 1; +} + +size_t mbstowcs(wchar_t *pDest, const char *pSrc, size_t num) { + int res; + unsigned char *src; + int count; + size_t src_len; + + src_len = strlen(pSrc); + + if (pDest != 0) { + src = (unsigned char *) pSrc; + + for (count = 0; count < num; count++) { + if (*src) { + res = mbtowc(pDest++, src, src_len); + + if (res > 0) { + src += res; + src_len -= res; + } else { + return -1; + } + } else { + *pDest = 0; + break; + } + } + } else { + count = 0; + } + + return count; +} diff --git a/libs/c/src/mem.c b/libs/c/src/mem.c new file mode 100644 index 00000000..19d5f7fd --- /dev/null +++ b/libs/c/src/mem.c @@ -0,0 +1,64 @@ +#include +#include + +void *memcpy(void *dst, const void *src, int n) { + const unsigned char *p = (unsigned char *) src; + unsigned char *q = (unsigned char *) dst; + + for (n++; --n;) { + *q++ = *p++; + } + + return dst; +} + +void *memmove(void *dst, const void *src, size_t len) { + unsigned char *csrc; + unsigned char *cdst; + + int reverse = (unsigned int) src < (unsigned int) dst; + + if (!reverse) { + for (csrc = (const char *) src, cdst = (char *) dst, len++; --len;) { + *cdst++ = *csrc++; + } + } else { + for (csrc = (const char *) src + len, cdst = (char *) dst + len, len++; --len;) { + *--cdst = *--csrc; + } + } + + return dst; +} + +void *memset(void *dest, int val, int n) { + __fill_mem(dest, val, n); + return dest; +} + +void *memchr(const void *src, int val, int n) { + const unsigned char *p; + + unsigned int v = (val & 0xff); + + for (p = (unsigned char *) src, n++; --n;) { + if (*p++ == v) { + return ((void *) (p - 1)); + } + } + + return NULL; +} + +int memcmp(const void *src1, const void *src2, int n) { + const unsigned char *p1; + const unsigned char *p2; + + for (p1 = (const unsigned char *) src1, p2 = (const unsigned char *) src2, n++; --n;) { + if (*p1++ != *p2++) { + return ((*--p1 < *--p2) ? -1 : +1); + } + } + + return 0; +} diff --git a/libs/c/src/mem_funcs.c b/libs/c/src/mem_funcs.c new file mode 100644 index 00000000..3dfa1f32 --- /dev/null +++ b/libs/c/src/mem_funcs.c @@ -0,0 +1,59 @@ +#include + +#define cps ((unsigned char *) src) +#define cpd ((unsigned char *) dst) +#define lps ((unsigned int *) src) +#define lpd ((unsigned int *) dst) + +#define deref_auto_inc(p) *(p)++ + +void __fill_mem(void *dst, int val, unsigned int n) { + unsigned int v = (unsigned char) val; + unsigned int i; + + if (n >= 32) { + i = (-(unsigned int) dst) & 3; + + if (i) { + n -= i; + do { + deref_auto_inc(cpd) = v; + } while (--i); + } + + if (v) { + v |= v << 24 | v << 16 | v << 8; + } + + i = n >> 5; + + if (i) { + do { + deref_auto_inc(lpd) = v; + deref_auto_inc(lpd) = v; + deref_auto_inc(lpd) = v; + deref_auto_inc(lpd) = v; + deref_auto_inc(lpd) = v; + deref_auto_inc(lpd) = v; + deref_auto_inc(lpd) = v; + deref_auto_inc(lpd) = v; + } while (--i); + } + + i = (n & 31) >> 2; + + if (i) { + do { + deref_auto_inc(lpd) = v; + } while (--i); + } + + n &= 3; + } + + if (n) { + do { + deref_auto_inc(cpd) = v; + } while (--n); + } +} diff --git a/libs/c/src/secure_error.c b/libs/c/src/secure_error.c new file mode 100644 index 00000000..80facdcd --- /dev/null +++ b/libs/c/src/secure_error.c @@ -0,0 +1,18 @@ +#include +#include + +msl_constraint_handler __msl_constraint_handler; + +void secure_error_func_02033e50(); + +void __msl_runtime_constraint_violation_s(int param1, int param2, int param3) { + if (__msl_constraint_handler != NULL) { + __msl_constraint_handler(param1, param2, param3); + return; + } + + secure_error_func_02033e50(); +} + +//! TODO: figure out the real name +void secure_error_func_02033e50() {} diff --git a/libs/c/src/signal.c b/libs/c/src/signal.c new file mode 100644 index 00000000..d676930e --- /dev/null +++ b/libs/c/src/signal.c @@ -0,0 +1,33 @@ +#include + +typedef void (*sig_func)(int sig); +sig_func signal_funcs[7]; + +int raise(int sig) { + sig_func temp_r31; + + if (sig < 1 || sig > 7) { + return -1; + } + + __begin_critical_region(signal_funcs_access); + + temp_r31 = signal_funcs[sig - 1]; + + if ((unsigned int) temp_r31 != 1) { + signal_funcs[sig - 1] = 0; + } + + __end_critical_region(signal_funcs_access); + + if ((unsigned int) temp_r31 == 1 || ((int) temp_r31 == 0 && sig == 1)) { + return 0; + } + + if ((unsigned int) temp_r31 == 0) { + exit(0); + } + + temp_r31(sig); + return 0; +} diff --git a/libs/c/src/string.c b/libs/c/src/string.c new file mode 100644 index 00000000..0578e706 --- /dev/null +++ b/libs/c/src/string.c @@ -0,0 +1,197 @@ +#include +#include + +#define K1 0x80808080 +#define K2 0xFEFEFEFF + +size_t strlen(const char *str) { + int length = -1; + unsigned char *p = (unsigned char *) str; + + do { + length++; + } while (*p++); + + return length; +} + +char *strcpy(char *dest, const char *src) { + register unsigned char *destb, *fromb; + register unsigned int w, t, align; + register unsigned int k1, k2; + + fromb = (unsigned char *) src; + destb = (unsigned char *) dest; + + if ((align = ((unsigned int) fromb & 3)) != ((unsigned int) destb & 3)) { + goto bytecopy; + } + + if (align != 0) { + if ((*destb = *fromb) == 0) { + return dest; + } + + for (align = 3 - align; align != 0; align--) { + if ((*++destb = *++fromb) == 0) { + return dest; + } + } + ++destb; + ++fromb; + } + + k1 = K1; + k2 = K2; + + w = *((int *) fromb); + t = w + k2; + t &= ~w; + t &= k1; + + if (t != 0) { + goto bytecopy; + } + + --((int *) (destb)); + + do { + *(++((int *) destb)) = w; + w = *(++((int *) fromb)); + t = w + k2; + t &= ~w; + t &= k1; + if (t != 0) { + goto adjust; + } + } while (true); + +adjust: + ++((int *) destb); +bytecopy: + if ((*destb = *fromb) == 0) { + return dest; + } + + do { + if ((*++destb = *++fromb) == 0) { + return dest; + } + } while (true); + + return dest; +} + +char *strncpy(char *dest, const char *src, size_t n) { + const unsigned char *p = (const unsigned char *) src; + unsigned char *q = (unsigned char *) dest; + + n++; + + while (--n != 0) { + if ((*q++ = *p++) == 0) { + while (--n != 0) { + *q++ = 0; + } + break; + } + } + + return dest; +} + +int strcmp(char *str1, char *str2) { + register unsigned char *left = (unsigned char *) str1; + register unsigned char *right = (unsigned char *) str2; + unsigned int k1, k2, align, l1, r1, x; + + l1 = *left; + r1 = *right; + if (l1 - r1) { + return (l1 - r1); + } + + if ((align = ((unsigned int) left & 3)) != ((unsigned 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++; + } + + k1 = K1; + k2 = K2; + + l1 = *(unsigned int *) left; + r1 = *(unsigned int *) right; + x = l1 + k2; + x &= ~l1; + if (x & k1) { + goto adjust; + } + while (l1 == r1) { + l1 = *(++((unsigned int *) (left))); + r1 = *(++((unsigned int *) (right))); + x = l1 + k2; + if (x & k1) { + goto adjust; + } + } + + --left; + --right; + goto bytecopy; + +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 (true); +} + +int strncmp(char *str1, char *str2, size_t n) { + const unsigned char *p1 = (unsigned char *) str1; + const unsigned char *p2 = (unsigned char *) str2; + unsigned int c1, c2; + + n++; + + while (--n) { + if ((c1 = *p1++) != (c2 = *p2++)) { + return (c1 - c2); + } else if (!c1) { + break; + } + } + + return 0; +} diff --git a/libs/c/src/wmem.c b/libs/c/src/wmem.c new file mode 100644 index 00000000..472e2d99 --- /dev/null +++ b/libs/c/src/wmem.c @@ -0,0 +1,18 @@ +#include + +wchar_t *wmemcpy(wchar_t *pDest, const wchar_t *pSrc, size_t num) { + return (wchar_t *) memcpy(pDest, pSrc, num * sizeof(wchar_t)); +} + +wchar_t *wmemchr(const wchar_t *pSrc, wchar_t val, size_t num) { + while (num != 0) { + if (*pSrc == val) { + return (wchar_t *) pSrc; + } + + pSrc++; + num--; + } + + return 0; +} diff --git a/libs/c/src/wprintf.c b/libs/c/src/wprintf.c new file mode 100644 index 00000000..729a5d47 --- /dev/null +++ b/libs/c/src/wprintf.c @@ -0,0 +1,1408 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#pragma dont_reuse_strings off + +#define MAX_SIG_DIG 32 + +#define LDBL_MANT_DIG 24 +#define LDBL_MAX_EXP 128 +#define TARGET_FLOAT_BITS 32 +#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) + +typedef long long intmax_t; + +#define PTRDIFF __typeof__((char *) 0 - (char *) 0) +typedef PTRDIFF ptrdiff_t; + +int vswprintf(wchar_t *s, size_t n, const wchar_t *format, va_list arg); + +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, + // wchar_argument, + // intmax_argument, + // size_t_argument, + // ptrdiff_argument, + // long_double_argument + normal_argument, + char_argument, + short_argument, + long_argument, + long_long_argument, + wchar_argument, + intmax_argument, + size_t_argument, + ptrdiff_argument, + long_double_argument +}; + +typedef struct { + unsigned char justification_options; + unsigned char sign_options; + unsigned char precision_specified; + unsigned char alternate_form; + unsigned char argument_options; + wchar_t conversion_char; + int field_width; + int precision; +} print_format; + +typedef struct { + char *CharStr; + size_t MaxCharCount; + size_t CharsWritten; +} __OutStrCtrl; + +#define conversion_buff_size 512 +#define conversion_max 509 +#define bad_conversion 0xFFFF + +static const wchar_t *parse_format(const wchar_t *format_string, va_list *arg, print_format *format) { + print_format f; + const wchar_t *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) == L'%') { + f.conversion_char = c; + *format = f; + return ((const wchar_t *) s + 1); + } + + while (true) { + flag_found = 1; + + switch (c) { + case L'-': + f.justification_options = left_justification; + break; + + case L'+': + f.sign_options = sign_always; + break; + + case L' ': + if (f.sign_options != sign_always) { + f.sign_options = space_holder; + } + break; + + case L'#': + f.alternate_form = 1; + break; + + case L'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 == L'*') { + 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 - L'0'); + c = *++s; + } + } + + if (f.field_width > conversion_max) { + f.conversion_char = bad_conversion; + *format = f; + return ((const wchar_t *) s + 1); + } + + if (c == L'.') { + f.precision_specified = 1; + + if ((c = *++s) == L'*') { + if ((f.precision = va_arg(*arg, int)) < 0) { + f.precision_specified = 0; + } + + c = *++s; + } else { + while (isdigit(c)) { + f.precision = (f.precision * 10) + (c - L'0'); + c = *++s; + } + } + } + + flag_found = 1; + + switch (c) { + case L'h': + f.argument_options = short_argument; + if (s[1] == L'h') { + f.argument_options = char_argument; + c = *++s; + } + break; + case L'l': + f.argument_options = long_argument; + if (s[1] == L'l') { + f.argument_options = long_long_argument; + c = *++s; + } + break; + case L'L': + f.argument_options = long_double_argument; + break; + case L'j': + f.argument_options = intmax_argument; + break; + case L't': + f.argument_options = ptrdiff_argument; + break; + case L'z': + f.argument_options = size_t_argument; + break; + default: + flag_found = 0; + break; + } + + if (flag_found) { + c = *++s; + } + + f.conversion_char = c; + + switch (c) { + case L'd': + case L'i': + case L'u': + case L'o': + case L'x': + case L'X': + if (f.argument_options == long_double_argument) { + f.argument_options = long_long_argument; + } + + if (!f.precision_specified) { + f.precision = 1; + } else if (f.justification_options == zero_fill) { + f.justification_options = right_justification; + } + break; + + case L'f': + case L'F': + if (f.argument_options == short_argument || f.argument_options == intmax_argument || + f.argument_options == size_t_argument || f.argument_options == ptrdiff_argument || + f.argument_options == long_long_argument) { + f.conversion_char = bad_conversion; + break; + } + + if (!f.precision_specified) { + f.precision = 6; + } + break; + + case L'a': + case L'A': + if (!f.precision_specified) { + f.precision = 0x0D; + } + if (f.argument_options == short_argument || f.argument_options == intmax_argument || + f.argument_options == size_t_argument || f.argument_options == ptrdiff_argument || + f.argument_options == long_long_argument || f.argument_options == char_argument) { + f.conversion_char = bad_conversion; + } + break; + + case L'g': + case L'G': + if (!f.precision) { + f.precision = 1; + } + + case L'e': + case L'E': + if (f.argument_options == short_argument || f.argument_options == char_argument || + f.argument_options == intmax_argument || f.argument_options == size_t_argument || + f.argument_options == ptrdiff_argument || f.argument_options == long_long_argument) { + f.conversion_char = bad_conversion; + break; + } + + if (!f.precision_specified) { + f.precision = 6; + } + break; + + case L'p': + f.argument_options = long_argument; + f.alternate_form = 1; + f.conversion_char = L'x'; + f.precision = 8; + break; + + case L'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 = bad_conversion; + } + break; + + case L's': + if (f.argument_options == long_argument) { + f.argument_options = wchar_argument; + } else if (f.argument_options != normal_argument) { + f.conversion_char = bad_conversion; + } + break; + + case L'n': + if (f.argument_options == long_double_argument) { + f.argument_options = long_long_argument; + } + break; + + default: + f.conversion_char = bad_conversion; + break; + } + + *format = f; + + return ((const wchar_t *) s + 1); +} + +wchar_t *long2str(long num, wchar_t *buff, print_format format) { + unsigned long unsigned_num, base; + wchar_t *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 == L'o')) { + return p; + } + + switch (format.conversion_char) { + case L'd': + case L'i': + base = 10; + + if (num < 0) { + if (num != 0x80000000) { + unsigned_num = -num; + } + + minus = 1; + } + break; + + case L'o': + base = 8; + format.sign_options = only_minus; + break; + + case L'u': + base = 10; + format.sign_options = only_minus; + break; + + case L'x': + case L'X': + base = 16; + format.sign_options = only_minus; + break; + } + + do { + n = unsigned_num % base; + unsigned_num /= base; + + if (n < 10) { + n += L'0'; + } else { + n -= 10; + + if (format.conversion_char == L'x') { + n += L'a'; + } else { + n += L'A'; + } + } + + *--p = n; + ++digits; + } while (unsigned_num != 0); + + if (base == 8 && format.alternate_form && *p != L'0') { + *--p = L'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 > conversion_max) { + return 0; + } + + while (digits < format.precision) { + *--p = L'0'; + ++digits; + } + + if (base == 16 && format.alternate_form) { + *--p = format.conversion_char; + *--p = L'0'; + } + + if (minus) { + *--p = L'-'; + } else if (format.sign_options == sign_always) { + *--p = L'+'; + } else if (format.sign_options == space_holder) { + *--p = L' '; + } + + return p; +} + +wchar_t *longlong2str(long long num, wchar_t *pBuf, print_format fmt) { + unsigned long long unsigned_num, base; + wchar_t *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 == L'o')) { + return p; + } + + switch (fmt.conversion_char) { + case L'd': + case L'i': + base = 10; + + if (num < 0) { + if (num != 0x8000000000000000) { + unsigned_num = -num; + } + + minus = 1; + } + break; + case L'o': + base = 8; + fmt.sign_options = only_minus; + break; + case L'u': + base = 10; + fmt.sign_options = only_minus; + break; + case L'x': + case L'X': + base = 16; + fmt.sign_options = only_minus; + break; + } + + do { + n = unsigned_num % base; + unsigned_num /= base; + + if (n < 10) { + n += L'0'; + } else { + n -= 10; + if (fmt.conversion_char == L'x') { + n += L'a'; + } else { + n += L'A'; + } + } + + *--p = n; + ++digits; + } while (unsigned_num != 0); + + if (base == 8 && fmt.alternate_form && *p != L'0') { + *--p = L'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 > conversion_max) { + return 0; + } + + while (digits < fmt.precision) { + *--p = L'0'; + ++digits; + } + + if (base == 16 && fmt.alternate_form) { + *--p = fmt.conversion_char; + *--p = L'0'; + } + + if (minus) { + *--p = L'-'; + } else if (fmt.sign_options == sign_always) { + *--p = L'+'; + } else if (fmt.sign_options == space_holder) { + *--p = L' '; + } + + return p; +} + +static wchar_t *double2hex(long double num, wchar_t *buff, print_format format) { + wchar_t *p; + unsigned char *q; + unsigned char working_byte; + long double ld; + int expbits, expmask; + unsigned snum; + long exp; + print_format exp_format; + int hex_precision; + int mantissa_bit; + decform form; + decimal dec; + int radix_marker; + + radix_marker = '.'; + p = buff; + ld = num; + + if (format.precision > 509) { + return 0; + } + + form.style = (char) 0; + form.digits = 0x20; + __num2dec(&form, num, &dec); + + switch (*dec.sig.text) { + case '0': + dec.exp = 0; + if (dec.sgn) { + p = buff - 5; + if (format.conversion_char == L'A') { + wcscpy(p, L"-0X0"); + } else { + wcscpy(p, L"-0x0"); + } + } else { + p = buff - 4; + if (format.conversion_char == L'A') { + wcscpy(p, L"0X0"); + } else { + wcscpy(p, L"0x0"); + } + } + + return p; + case 'I': + if (dec.sgn) { + p = buff - 5; + if (format.conversion_char == L'A') { + wcscpy(p, L"-INF"); + } else { + wcscpy(p, L"-inf"); + } + } else { + p = buff - 4; + if (format.conversion_char == L'A') { + wcscpy(p, L"INF"); + } else { + wcscpy(p, L"inf"); + } + } + + return p; + case 'N': + if (dec.sgn) { + p = buff - 5; + if (format.conversion_char == L'A') { + wcscpy(p, L"-NAN"); + } else { + wcscpy(p, L"-nan"); + } + } else { + p = buff - 4; + if (format.conversion_char == L'A') { + wcscpy(p, L"NAN"); + } else { + wcscpy(p, L"nan"); + } + } + + return p; + } + + exp_format.justification_options = right_justification; + exp_format.sign_options = sign_always; + exp_format.precision_specified = 0; + exp_format.alternate_form = 0; + exp_format.argument_options = normal_argument; + exp_format.field_width = 0; + exp_format.precision = 1; + exp_format.conversion_char = L'd'; + + int i; + unsigned char *nump = (unsigned char *) # + for (i = 0; i < TARGET_FLOAT_BYTES; i++) { + unsigned char x = nump[i]; + nump[i] = nump[TARGET_FLOAT_BYTES - i + 3]; + nump[TARGET_FLOAT_BYTES - i + 3] = x; + } + + expbits = TARGET_FLOAT_EXP_BITS; + expmask = 0x7FF; + + snum = ((unsigned char *) &num)[0] << 25; + if (TARGET_FLOAT_EXP_BITS > 7) { + snum |= ((unsigned char *) &num)[1] << 17; + } + if (TARGET_FLOAT_EXP_BITS > 15) { + snum |= ((unsigned char *) &num)[2] << 9; + } + if (TARGET_FLOAT_EXP_BITS > 23) { + snum |= ((unsigned char *) &num)[3] << 1; + } + + snum = (snum >> (29 - expbits)) & expmask; + + if (snum != 0) { + exp = snum - 0x3FF; + } else { + exp = 0; + } + + p = long2str(exp, buff, exp_format); + if (format.conversion_char == L'a') { + *--p = L'p'; + } else { + *--p = L'P'; + } + q = (unsigned char *) # + + if (TARGET_FLOAT_IMPLICIT_J_BIT) { + mantissa_bit = (4 + expbits + format.precision * 4) - 1; + } else { + mantissa_bit = (1 + expbits + format.precision * 4) - 4; + } + + for (hex_precision = format.precision; hex_precision >= 1; hex_precision--) { + if (mantissa_bit < 64) { + int mantissa_byte; + + mantissa_byte = mantissa_bit >> 3; + working_byte = (*(q + mantissa_byte)) >> (7 - (mantissa_bit & 7)); + + if ((mantissa_bit & ~7) != ((mantissa_bit - 4) & ~7)) { + working_byte |= ((*(q + (mantissa_byte - 1))) << 8) >> (7 - ((mantissa_bit) & 7)); + } + + if (!TARGET_FLOAT_IMPLICIT_J_BIT) { + if (mantissa_bit == 1 + expbits) { + *--p = radix_marker; + working_byte &= 0x1; + } + } + + if ((working_byte &= 0xF) < 10) { + working_byte += L'0'; + } else if (format.conversion_char == L'a') { + working_byte += L'a' - 10; + } else { + working_byte += L'A' - 10; + } + } else { + working_byte = L'0'; + } + + *--p = working_byte; + mantissa_bit -= 4; + } + + if (TARGET_FLOAT_IMPLICIT_J_BIT) { + if (format.precision || format.alternate_form) { + *--p = radix_marker; + } + + if (fabsl(ld) != 0.0) { + *--p = '1'; + } else { + *--p = '0'; + } + } + + if (format.conversion_char == L'a') { + *--p = L'x'; + } else { + *--p = L'X'; + } + + *--p = L'0'; + + if (dec.sgn) { + *--p = L'-'; + } else if (format.sign_options == sign_always) { + *--p = L'+'; + } else if (format.sign_options == space_holder) { + *--p = L' '; + } + + return p; +} + +void round_decimal(decimal *dec, int new_length) { + unsigned char c; + unsigned char *p; + int carry; + + if (new_length < 0) { + return_zero: + dec->exp = 0; + dec->sig.length = 1; + *dec->sig.text = L'0'; + return; + } + + if (new_length >= dec->sig.length) { + return; + } + + p = (unsigned char *) dec->sig.text + new_length + 1; + c = *--p - L'0'; + + if (c == 5) { + unsigned char *q = &((unsigned char *) dec->sig.text)[dec->sig.length]; + + while (--q > p && *q == L'0') + ; + carry = (q == p) ? p[-1] & 1 : 1; + } else { + carry = (c > 5); + } + + while (new_length != 0) { + c = *--p - L'0' + carry; + + if ((carry = (c > 9)) != 0 || c == 0) { + --new_length; + } else { + *p = c + L'0'; + break; + } + } + + if (carry != 0) { + dec->exp += 1; + dec->sig.length = 1; + *dec->sig.text = L'1'; + return; + } else if (new_length == 0) { + goto return_zero; + } + + dec->sig.length = new_length; +} + +wchar_t *float2str(long double num, wchar_t *wbuff, print_format format) { + decimal dec; + decform form; + wchar_t *pw; + unsigned char *p; + unsigned char buff[512]; + unsigned char *q; + int n, digits, sign; + int int_digits, frac_digits; + int radix_marker; + + radix_marker = '.'; + + if (format.precision > conversion_max) { + return 0; + } + + form.style = 0; + form.digits = 0x20; + __num2dec(&form, num, &dec); + p = (unsigned char *) dec.sig.text + dec.sig.length; + + while (dec.sig.length > 1 && *--p == L'0') { + --dec.sig.length; + ++dec.exp; + } + + switch (*dec.sig.text) { + case L'0': + dec.exp = 0; + break; + case L'I': + if (num < 0) { + pw = wbuff - 5; + + if (isupper(format.conversion_char)) { + wcscpy(pw, L"-INF"); + } else { + wcscpy(pw, L"-inf"); + } + } else { + pw = wbuff - 4; + if (isupper(format.conversion_char)) { + wcscpy(pw, L"INF"); + } else { + wcscpy(pw, L"inf"); + } + } + + return pw; + + case L'N': + if (dec.sgn) { + pw = wbuff - 5; + + if (isupper(format.conversion_char)) { + wcscpy(pw, L"-NAN"); + } else { + wcscpy(pw, L"-nan"); + } + } else { + pw = wbuff - 4; + if (isupper(format.conversion_char)) { + wcscpy(pw, L"NAN"); + } else { + wcscpy(pw, L"nan"); + } + } + + return pw; + } + + dec.exp += dec.sig.length - 1; + p = buff + 512; + *--p = 0; + + switch (format.conversion_char) { + case L'g': + case L'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 == L'g') { + format.conversion_char = L'e'; + } else { + format.conversion_char = L'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 L'e': + case L'E': + e_format: + + if (dec.sig.length > format.precision + 1) { + round_decimal(&dec, format.precision + 1); + } + + n = dec.exp; + sign = L'+'; + + if (n < 0) { + n = -n; + sign = L'-'; + } + + for (digits = 0; n || digits < 2; ++digits) { + *--p = n % 10 + '0'; + n /= 10; + } + + *--p = sign; + *--p = format.conversion_char; + + if (buff - p + format.precision > conversion_max) { + return 0; + } + + if (dec.sig.length < format.precision + 1) { + for (n = format.precision + 1 - dec.sig.length + 1; --n;) { + *--p = L'0'; + } + } + + for (n = dec.sig.length, q = (unsigned char *) dec.sig.text + dec.sig.length; --n;) { + *--p = *--q; + } + + if (format.precision || format.alternate_form) { + *--p = radix_marker; + } + + *--p = *dec.sig.text; + + if (dec.sgn) { + *--p = L'-'; + } else if (format.sign_options == sign_always) { + *--p = L'+'; + } else if (format.sign_options == space_holder) { + *--p = L' '; + } + + break; + + case L'f': + case L'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 > conversion_max) { + return 0; + } + + q = (unsigned char *) dec.sig.text + dec.sig.length; + + for (digits = 0; digits < (format.precision - frac_digits); ++digits) { + *--p = L'0'; + } + + for (digits = 0; digits < frac_digits && digits < dec.sig.length; ++digits) { + *--p = *--q; + } + + for (; digits < frac_digits; ++digits) { + *--p = L'0'; + } + + if (format.precision || format.alternate_form) { + *--p = radix_marker; + } + + if (int_digits) { + for (digits = 0; digits < int_digits - dec.sig.length; ++digits) { + *--p = L'0'; + } + + for (; digits < int_digits; ++digits) { + *--p = *--q; + } + } else { + *--p = L'0'; + } + + if (dec.sgn) { + *--p = L'-'; + } else if (format.sign_options == sign_always) { + *--p = L'+'; + } else if (format.sign_options == space_holder) { + *--p = L' '; + } + + break; + } + + pw = wbuff - strlen(p) - 1; + mbstowcs(pw, p, strlen(p)); + return pw; +} + +// non-matching: https://decomp.me/scratch/bV2T9 +int __wpformatter(void *(*WriteProc)(void *, const wchar_t *, size_t), void *WriteProcArg, const wchar_t *format_str, + va_list arg, bool is_secure) { + int num_chars, chars_written, field_width; + const wchar_t *format_ptr; + const wchar_t *curr_format; + print_format format; + long long_num; + long long long_long_num; + long double long_double_num; + wchar_t buff[512]; + wchar_t *buff_ptr; + wchar_t *string_end; + char *cstring_end; + wchar_t fill_char = ' '; + char *strptr; + + format_ptr = format_str; + chars_written = 0; + + while (*format_ptr) { + if (!(curr_format = wcschr(format_ptr, L'%'))) { + num_chars = wcslen(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, &arg, &format); + + switch (format.conversion_char) { + case L'd': + case L'i': + if (format.argument_options == long_argument) { + long_num = va_arg(arg, long); + } else if (format.argument_options == long_long_argument) { + long_long_num = va_arg(arg, long long); + } else if (format.argument_options == intmax_argument) { + long_long_num = va_arg(arg, intmax_t); + } else if (format.argument_options == size_t_argument) { + long_num = va_arg(arg, size_t); + } else if (format.argument_options == ptrdiff_argument) { + long_num = va_arg(arg, ptrdiff_t); + } else { + long_num = va_arg(arg, int); + } + + if (format.argument_options == short_argument) { + long_num = (short) long_num; + } + + if ((format.argument_options == long_long_argument) || (format.argument_options == intmax_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 L'o': + case L'u': + case L'x': + case L'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, long long); + } else if (format.argument_options == intmax_argument) { + long_long_num = va_arg(arg, intmax_t); + } else if (format.argument_options == size_t_argument) { + long_num = va_arg(arg, size_t); + } else if (format.argument_options == ptrdiff_argument) { + long_num = va_arg(arg, ptrdiff_t); + } else { + long_num = va_arg(arg, unsigned int); + } + + if (format.argument_options == short_argument) { + long_num = (unsigned short) long_num; + } + + if ((format.argument_options == long_long_argument) || (format.argument_options == intmax_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 L'f': + case L'F': + case L'e': + case L'E': + case L'g': + case L'G': + if (format.argument_options == long_double_argument) { + long_double_num = va_arg(arg, long double); + } else { + long_double_num = va_arg(arg, double); + } + + if (!(buff_ptr = float2str(long_double_num, buff + 512, format))) { + goto conversion_error; + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + + case L'a': + case L'A': + if (format.argument_options == long_double_argument) { + long_double_num = va_arg(arg, long double); + } else { + long_double_num = va_arg(arg, double); + } + + if (!(buff_ptr = double2hex(long_double_num, buff + 512, format))) { + goto conversion_error; + } + + num_chars = buff + 512 - 1 - buff_ptr; + break; + + case L's': + if (format.argument_options == wchar_argument) { + buff_ptr = va_arg(arg, wchar_t *); + + if (is_secure && buff_ptr == NULL) { + __msl_runtime_constraint_violation_s(NULL, NULL, -1); + return -1; + } + + if (buff_ptr == NULL) { + buff_ptr = L""; + } + + 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 = (wchar_t *) wmemchr(buff_ptr, 0, num_chars)) != 0) { + num_chars = string_end - buff_ptr; + } + } else { + num_chars = wcslen(buff_ptr); + } + } else { + strptr = va_arg(arg, char *); + + if (is_secure && strptr == NULL) { + __msl_runtime_constraint_violation_s(0, 0, -1); + return -1; + } + + if (strptr == NULL) { + strptr = ""; + } + + 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 ((cstring_end = (char *) memchr(strptr, 0, num_chars)) != 0) { + num_chars = cstring_end - strptr; + } + } else { + num_chars = strlen(strptr); + } + if ((num_chars = mbstowcs(buff, strptr, num_chars)) < 0) { + goto conversion_error; + } + + buff_ptr = &buff[0]; + } + + break; + + case L'n': + if (is_secure) { + __msl_runtime_constraint_violation_s(0, 0, -1); + return -1; + } + + buff_ptr = va_arg(arg, wchar_t *); + + switch (format.argument_options) { + case normal_argument: + *(int *) buff_ptr = chars_written; + break; + case short_argument: + *(short *) buff_ptr = chars_written; + break; + case long_argument: + *(long *) buff_ptr = chars_written; + break; + case intmax_argument: + *(intmax_t *) buff_ptr = chars_written; + break; + case size_t_argument: + *(size_t *) buff_ptr = chars_written; + break; + case ptrdiff_argument: + *(ptrdiff_t *) buff_ptr = chars_written; + break; + case long_long_argument: + *(long long *) buff_ptr = chars_written; + break; + } + + continue; + + case L'c': + buff_ptr = buff; + if (format.argument_options == wchar_argument) { + *buff_ptr = va_arg(arg, int); + num_chars = 1; + } else { + char chint = va_arg(arg, int); + num_chars = mbtowc(buff, &chint, 1); + } + + break; + + case L'%': + buff_ptr = buff; + *buff_ptr = L'%'; + num_chars = 1; + break; + + case L'p': + case 0xFFFF: + default: + conversion_error: + num_chars = wcslen(curr_format); + chars_written += num_chars; + + if (num_chars && !(*WriteProc)(WriteProcArg, curr_format, num_chars)) { + return -1; + } + + return chars_written; + } + + field_width = num_chars; + + if (format.justification_options != left_justification) { + fill_char = (format.justification_options == zero_fill) ? '0' : ' '; + + if (((*buff_ptr == L'+') || (*buff_ptr == L'-') || (*buff_ptr == L' ')) && (fill_char == '0')) { + if ((*WriteProc)(WriteProcArg, buff_ptr, 1) == 0) { + return -1; + } + + ++buff_ptr; + num_chars--; + } + + if ((format.justification_options == zero_fill) && + ((format.conversion_char == L'a') || (format.conversion_char == L'A'))) { + if (num_chars < 2) { + return -1; + } + + if ((*WriteProc)(WriteProcArg, buff_ptr, 2) == 0) { + return -1; + } + + num_chars -= 2; + buff_ptr += 2; + } + + 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) { + wchar_t blank = L' '; + + if ((*WriteProc)(WriteProcArg, &blank, 1) == 0) { + return -1; + } + + ++field_width; + } + } + + chars_written += field_width; + } + + return chars_written; +} + +typedef struct { + wchar_t *wCharStr; + size_t MaxCharCount; + size_t CharsWritten; +} __wOutStrCtrl; + +void *__wStringWrite(void *wosc, const wchar_t *buffer, size_t numchars) { + size_t tobewritten; + void *res; + __wOutStrCtrl *wOscp = (__wOutStrCtrl *) wosc; + tobewritten = + ((wOscp->CharsWritten + numchars) <= wOscp->MaxCharCount) ? numchars : wOscp->MaxCharCount - wOscp->CharsWritten; + res = (void *) wmemcpy(wOscp->wCharStr + wOscp->CharsWritten, buffer, tobewritten); + wOscp->CharsWritten += tobewritten; + return res; +} + +int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...) { + va_list args; + va_start(args, format); + return vswprintf(s, n, format, args); +} + +int vswprintf(wchar_t *s, size_t n, const wchar_t *format, va_list arg) { + int count; + __wOutStrCtrl wosc; + wosc.wCharStr = s; + wosc.MaxCharCount = n; + wosc.CharsWritten = 0; + + count = __wpformatter(&__wStringWrite, &wosc, format, arg, 0); + + if (count >= 0) { + if (count < n) { + s[count] = 0; + } else { + *(s + n - 1) = 0; + count = -1; + } + } + + return count; +} diff --git a/libs/c/src/wstring.c b/libs/c/src/wstring.c new file mode 100644 index 00000000..68e90346 --- /dev/null +++ b/libs/c/src/wstring.c @@ -0,0 +1,53 @@ +#include + +size_t wcslen(const wchar_t *str) { + size_t len = -1; + + do { + len++; + } while (*str++ != 0); + + return len; +} + +wchar_t *wcscpy(wchar_t *dest, const wchar_t *src) { + const wchar_t *p = src; + wchar_t *q = dest; + + while ((*q++ = *p++) != L'\0') + ; + + return dest; +} + +wchar_t *wcsncpy(wchar_t *dest, const wchar_t *src, size_t n) { + const wchar_t *p = src; + wchar_t *q = dest; + + n++; + + while (--n != 0) { + if ((*q++ = *p++) == 0) { + while (--n != 0) { + *q++ = 0; + } + break; + } + } + + return dest; +} + +const wchar_t *wcschr(const wchar_t *str, wchar_t chr) { + const wchar_t *p = str; + wchar_t c = chr; + wchar_t ch; + + while (ch = *p++) { + if (ch == c) { + return ((char *) (p - 1)); + } + } + + return (c ? 0 : (char *) (p - 1)); +} diff --git a/libs/runtime/include/MWException.h b/libs/runtime/include/MWException.h new file mode 100644 index 00000000..a33d3e73 --- /dev/null +++ b/libs/runtime/include/MWException.h @@ -0,0 +1,53 @@ +#ifndef _RUNTIME_MWEXCEPTION_H +#define _RUNTIME_MWEXCEPTION_H + +#include + +typedef void (*DestructorFunc)(void *); + +typedef short vbase_ctor_arg_type; +typedef u8 local_cond_type; + +typedef struct CatchInfo { + void *location; + void *typeinfo; + void *dtor; + void *sublocation; + long pointercopy; + void *stacktop; +} CatchInfo; + +typedef struct DestructorChain { + /* 0x00 */ struct DestructorChain *next; + /* 0x04 */ DestructorFunc dtor; + /* 0x08 */ void *object; +} DestructorChain; + +void __end_catch(CatchInfo *catchinfo); + +extern DestructorChain *__global_destructor_chain; + +/** + * @brief Call all static initializers + */ +extern void __call_static_initializers(void); + +/** + * @brief Destroy all constructed global objects + */ +extern void __destroy_global_chain(void); + +extern void __throw(char *throwtype, void *location, void *dtor); +extern void __rethrow(void); +extern char __throw_catch_compare(const u8 *throwtype, const u8 *catchtype, s32 *offset_result); + +#define DTORARG_TYPE short +#define DTORARG_PARTIAL (0) // destroy non-virtual bases +#define DTORARG_COMPLETE (-1) // destroy all bases +#define DTORARG_DELETE (1) // destroy all bases and delete object + +#define DTORCALL_COMPLETE(dtor, objptr) (((void (*)(void *, DTORARG_TYPE)) dtor)(objptr, DTORARG_COMPLETE)) +#define DTORCALL_PARTIAL(dtor, objptr) (((void (*)(void *, DTORARG_TYPE)) dtor)(objptr, DTORARG_PARTIAL)) +#define DTORCALL_VTTOBJECT(dtor, objptr, vttptr) (((void (*)(void *, void *)) dtor)(objptr, vttptr)) + +#endif diff --git a/tools/configure.py b/tools/configure.py index 87a3f95f..80cf12a1 100755 --- a/tools/configure.py +++ b/tools/configure.py @@ -49,6 +49,7 @@ CC_FLAGS = " ".join([ "-gccinc", # Interpret #include "..." and #include <...> equally "-nolink", # Do not link "-msgstyle gcc", # Use GCC-like messages (some IDEs will make file names clickable) + "-ipa file", # InterProcedural Analysis ]) # Passed to all modules and final arm9.o link LD_FLAGS = " ".join([ diff --git a/tools/m2ctx.py b/tools/m2ctx.py index dc43f326..158ce517 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -21,7 +21,8 @@ CXX_FLAGS = [ '-nostdinc', '-Iinclude', '-Ilibs/c/include', - '-Ilibs/cpp/include' + '-Ilibs/cpp/include', + '-Ilibs/runtime/include', ] script_dir = Path(os.path.dirname(os.path.realpath(__file__)))