From 21bb19bbc93c24eece1f620bd25b2a469bc92587 Mon Sep 17 00:00:00 2001 From: Matthew Waltz Date: Fri, 26 Dec 2025 10:50:52 -0700 Subject: [PATCH] [binutils] add binutils support --- .github/workflows/branch.yml | 31 +- .github/workflows/make.yml | 28 +- docs/headers/ti/sprintf.rst | 3 +- docs/static/asm.rst | 96 ++- docs/static/contributing.rst | 20 +- docs/static/faq.rst | 36 +- docs/static/getting-started.rst | 1 - docs/static/makefile-options.rst | 32 +- docs/static/printf.rst | 2 +- makefile | 13 +- src/ce/atomic_load_32.src | 38 +- src/ce/atomic_load_decreasing_32.src | 44 +- src/ce/atomic_load_increasing_32.src | 46 +- .../boot_vsprintf.c => ce/boot_printf.c} | 6 +- src/ce/boot_sprintf.src | 9 - src/{libc => ce}/boot_vsprintf.src | 43 +- src/ce/debug.src | 76 +- src/ce/delay.src | 30 +- src/ce/eval.src | 24 +- src/ce/getstringinput.src | 224 +++--- src/ce/gettokeninput.src | 222 +++--- src/ce/include/ti/vars.h | 9 +- src/ce/intce.src | 223 +++--- src/ce/makefile | 207 +++++- src/ce/os_textbuffer.src | 15 +- src/ce/random.src | 32 +- src/ce/runprgm.src | 670 +++++++++--------- src/ce/sleep.src | 18 +- src/ce/sleep_common.src | 32 +- src/ce/tice.src | 303 -------- src/ce/ticksleep.src | 12 +- src/ce/usleep.src | 32 +- src/ce/zx0.src | 10 +- src/ce/zx7.src | 8 +- src/common.mk | 50 +- src/crt/and.src | 40 +- src/crt/and_fast.src | 17 +- src/crt/bbitrev.src | 9 +- src/crt/bdivs.src | 10 +- src/crt/bdivu.src | 10 +- src/crt/bdvrms_abs.src | 25 +- src/crt/bdvrmu.src | 23 +- src/crt/bmuls.src | 8 +- src/crt/bmulu.src | 8 +- src/crt/bpopcnt.src | 8 +- src/crt/brems.src | 10 +- src/crt/bremu.src | 10 +- src/crt/bshl.src | 19 +- src/crt/bshrs.src | 12 +- src/crt/bshru.src | 19 +- src/crt/crt.src | 18 + src/crt/crt0.S | 396 +++++++++++ src/crt/crt0.src | 544 -------------- src/crt/ctlz.src | 59 +- src/crt/cttz.src | 53 +- src/crt/daddsub.src | 34 +- src/crt/dcmp.src | 7 +- src/crt/ddiv.src | 26 +- src/crt/dmul.src | 26 +- src/crt/dneg.src | 9 +- src/crt/drem.src | 26 +- src/crt/dtof.src | 97 +-- src/crt/dtol.src | 12 +- src/crt/dtoll.src | 16 +- src/crt/errno.src | 4 + src/crt/fpneg.src | 8 +- src/crt/fpupop1.src | 8 +- src/crt/fpupop2.src | 16 +- src/crt/frameset.src | 8 +- src/crt/frameset0.src | 8 +- src/crt/frbmuls.src | 9 +- src/crt/frem.src | 25 +- src/crt/frimuls.src | 10 +- src/crt/frimulu.src | 8 +- src/crt/frsmuls.src | 10 +- src/crt/frsmulu.src | 8 +- src/crt/ftod.src | 59 +- src/crt/ftoll.src | 20 +- src/crt/i48add.src | 10 +- src/crt/i48add_1.src | 7 +- src/crt/i48and.src | 8 +- src/crt/i48bitrev.src | 10 +- src/crt/i48bswap.src | 8 +- src/crt/i48cmps.src | 10 +- src/crt/i48cmpu.src | 10 +- src/crt/i48cmpzero.src | 8 +- src/crt/i48divs.src | 16 +- src/crt/i48divu.src | 10 +- src/crt/i48dvrmu.src | 9 +- src/crt/i48mulu.src | 8 +- src/crt/i48neg.src | 13 +- src/crt/i48not.src | 8 +- src/crt/i48or.src | 8 +- src/crt/i48popcnt.src | 10 +- src/crt/i48rems.src | 18 +- src/crt/i48remu.src | 12 +- src/crt/i48shl.src | 8 +- src/crt/i48shr.src | 14 +- src/crt/i48sub.src | 10 +- src/crt/i48sub_1.src | 8 +- src/crt/i48xor.src | 8 +- src/crt/ibitrev.src | 10 +- src/crt/ibitrev_fast.src | 8 +- src/crt/icmpzero.src | 8 +- src/crt/idivs.src | 17 +- src/crt/idivu.src | 17 +- src/crt/idvrms.src | 19 +- src/crt/idvrmu.src | 28 +- src/crt/imulu.src | 19 +- src/crt/imulu_b.src | 22 +- src/crt/imulu_b_fast.src | 9 +- src/crt/imulu_fast.src | 12 +- src/crt/indcallhl.src | 8 +- src/crt/ineg.src | 20 +- src/crt/ineg_fast.src | 12 +- src/crt/inot.src | 20 +- src/crt/inot_fast.src | 12 +- src/crt/internal_bitrev_byte.src | 8 +- src/crt/ipopcnt.src | 10 +- src/crt/ipopcnt_fast.src | 8 +- src/crt/irems.src | 17 +- src/crt/iremu.src | 17 +- src/crt/ishl.src | 20 +- src/crt/ishrs.src | 20 +- src/crt/ishrs_1_fast.src | 10 +- src/crt/ishru_1_fast.src | 8 +- src/crt/ladd.src | 15 +- src/crt/ladd_1.src | 8 +- src/crt/ladd_b.src | 15 +- src/crt/ladd_b_fast.src | 10 +- src/crt/ladd_fast.src | 8 +- src/crt/lbitrev.src | 10 +- src/crt/lbswap.src | 8 +- src/crt/lcmps.src | 19 +- src/crt/lcmps_fast.src | 8 +- src/crt/lcmpu.src | 15 +- src/crt/lcmpu_fast.src | 8 +- src/crt/lcmpzero.src | 8 +- src/crt/ldivs.src | 25 +- src/crt/ldivs_lrems_common.src | 10 +- src/crt/ldivu.src | 23 +- src/crt/ldvrmu.src | 39 +- src/crt/lladd.src | 14 +- src/crt/lladd_1.src | 8 +- src/crt/lladd_b.src | 12 +- src/crt/lladd_b_fast.src | 8 +- src/crt/lladd_fast.src | 8 +- src/crt/lland.src | 8 +- src/crt/lland_fast.src | 8 +- src/crt/llbitrev.src | 10 +- src/crt/llbswap.src | 8 +- src/crt/llcmps.src | 16 +- src/crt/llcmps_fast.src | 14 +- src/crt/llcmpu.src | 14 +- src/crt/llcmpu_fast.src | 8 +- src/crt/llcmpzero.src | 14 +- src/crt/llcmpzero_fast.src | 14 +- src/crt/lldivs.src | 34 +- src/crt/lldivu.src | 10 +- src/crt/lldivu_b.src | 20 +- src/crt/lldvrmu.src | 26 +- src/crt/llmulu.src | 28 +- src/crt/llmulu_b.src | 7 +- src/crt/llneg.src | 13 +- src/crt/llneg_fast.src | 8 +- src/crt/llnot.src | 8 +- src/crt/llnot_fast.src | 8 +- src/crt/llor.src | 8 +- src/crt/llor_fast.src | 8 +- src/crt/llpopcnt.src | 10 +- src/crt/llpopcnt_fast.src | 10 +- src/crt/llremu.src | 10 +- src/crt/llshl.src | 16 +- src/crt/llshl_1_fast.src | 8 +- src/crt/llshrs.src | 34 +- src/crt/llshrs_1_fast.src | 8 +- src/crt/llshrs_fast.src | 74 +- src/crt/llshru_1_fast.src | 8 +- src/crt/llshru_fast.src | 10 +- src/crt/llsub.src | 8 +- src/crt/llsub_1.src | 8 +- src/crt/llsub_fast.src | 8 +- src/crt/lltof.src | 20 +- src/crt/llxor.src | 8 +- src/crt/llxor_fast.src | 8 +- src/crt/lmulu.src | 21 +- src/crt/lmulu_b.src | 9 +- src/crt/lmulu_b_fast.src | 10 +- src/crt/lmulu_fast.src | 12 +- src/crt/lneg.src | 15 +- src/crt/lneg_fast.src | 8 +- src/crt/lnot.src | 15 +- src/crt/lnot_fast.src | 8 +- src/crt/lpopcnt.src | 10 +- src/crt/lpopcnt_fast.src | 8 +- src/crt/lrems.src | 21 +- src/crt/lremu.src | 23 +- src/crt/lshl.src | 19 +- src/crt/lshrs.src | 24 +- src/crt/lshrs_1_fast.src | 8 +- src/crt/lshru.src | 19 +- src/crt/lshru_1_fast.src | 8 +- src/crt/lsub.src | 15 +- src/crt/lsub_1.src | 8 +- src/crt/lsub_fast.src | 8 +- src/crt/ltod.src | 149 ++-- src/crt/makefile | 65 +- src/crt/or.src | 41 +- src/crt/or_fast.src | 20 +- src/crt/os.src | 94 ++- src/crt/popcnt_common.src | 20 +- src/crt/sand.src | 15 +- src/crt/sbitrev.src | 10 +- src/crt/scmpzero.src | 8 +- src/crt/sdivs.src | 19 +- src/crt/sdivu.src | 17 +- src/crt/sdvrms_abs.src | 18 +- src/crt/sdvrmu.src | 9 +- src/crt/setflag.src | 15 +- src/crt/smulu.src | 22 +- src/crt/smulu_b.src | 9 +- src/crt/smulu_b_fast.src | 9 +- src/crt/smulu_fast.src | 12 +- src/crt/sneg.src | 16 - src/crt/sneg_fast.src | 7 - src/crt/snot.src | 16 - src/crt/snot_fast.src | 7 - src/crt/sor.src | 15 +- src/crt/spopcnt.src | 10 +- src/crt/spopcnt_fast.src | 8 +- src/crt/srems.src | 19 +- src/crt/sremu.src | 17 +- src/crt/sshl.src | 16 - src/crt/sshrs.src | 19 +- src/crt/sshru.src | 19 +- src/crt/sxor.src | 15 +- src/crt/ulltof.src | 20 +- src/crt/ultof.src | 15 +- src/crt/xor.src | 41 +- src/crt/xor_fast.src | 20 +- src/libc/abs.src | 7 +- src/libc/acosf.src | 39 +- src/libc/allocator.src | 105 --- src/libc/allocator/allocator_simple.src | 43 ++ src/libc/{ => allocator}/allocator_standard.c | 14 +- src/libc/allocator/makefile | 55 ++ src/libc/allocator_simple.src | 37 - src/libc/asinf.c | 20 +- src/libc/asinf.src | 20 - src/libc/asprintf.src | 33 +- src/libc/atan2f.c | 20 +- src/libc/atan2f.src | 20 - src/libc/atanf.c | 22 +- src/libc/atanf.src | 20 - src/libc/atexit.src | 42 ++ src/libc/atof.src | 23 +- src/libc/atoi.src | 35 +- src/libc/atol.src | 35 +- src/libc/atoll.src | 16 +- src/libc/bzero.src | 13 +- src/libc/calloc.src | 76 ++ src/libc/ceilf.src | 37 +- src/libc/cimagf.src | 9 +- src/libc/cimagl.src | 7 +- src/libc/clock.src | 22 +- src/libc/cmplxf.src | 12 +- src/libc/cmplxl.src | 10 +- src/libc/conjf.src | 29 +- src/libc/conjl.src | 10 +- src/libc/copysignf.src | 9 +- src/libc/copysignl.src | 17 +- src/libc/cosf.src | 23 +- src/libc/coshf.c | 19 +- src/libc/coshf.src | 20 - src/libc/crealf.src | 17 +- src/libc/creall.src | 16 +- src/libc/div.src | 10 +- src/libc/errno_str.c | 21 +- src/libc/expf.c | 20 +- src/libc/expf.src | 20 - src/libc/ez80_builtin.src | 185 +++-- src/libc/fabsf.src | 27 +- src/libc/fabsl.src | 16 +- src/libc/fgetc.c | 2 + src/libc/float32_div.src | 19 + src/libc/floorf.c | 20 +- src/libc/floorf.src | 20 - src/libc/fmal.src | 11 +- src/libc/fminmaxf.src | 74 +- src/libc/fmodf.c | 20 +- src/libc/fmodf.src | 20 - src/libc/fmodl.src | 11 +- src/libc/fpclassifyf.src | 19 +- src/libc/fpclassifyl.src | 26 +- src/libc/fprintf.src | 16 - src/libc/fputc.c | 2 + src/libc/frexpf.src | 46 +- src/libc/getc.src | 9 - src/libc/getchar.src | 6 - src/libc/i48abs.src | 9 +- src/libc/i48div.src | 13 +- src/libc/ilogbf.src | 29 +- src/libc/ilogbl.src | 27 +- src/libc/inchar.src | 42 +- src/libc/isalnum.src | 26 +- src/libc/isalpha.src | 20 +- src/libc/isascii.src | 12 +- src/libc/isblank.src | 18 +- src/libc/iscntrl.src | 18 +- src/libc/isdigit.src | 18 +- src/libc/isfinitef.src | 8 +- src/libc/isfinitel.src | 7 +- src/libc/isgraph.src | 18 +- src/libc/isinff.src | 7 +- src/libc/isinfl.src | 16 +- src/libc/islower.src | 18 +- src/libc/isnanf.src | 7 +- src/libc/isnanl.src | 22 +- src/libc/isnormalf.src | 9 +- src/libc/isnormall.src | 15 +- src/libc/isprint.src | 18 +- src/libc/ispunct.src | 32 +- src/libc/issignalingf.src | 9 +- src/libc/issignalingl.src | 11 +- src/libc/isspace.src | 8 +- src/libc/issubnormalf.src | 13 +- src/libc/issubnormall.src | 24 +- src/libc/isupper.src | 18 +- src/libc/isxdigit.src | 26 +- src/libc/iszerof.src | 13 +- src/libc/iszerol.src | 16 +- src/libc/labs.src | 10 +- src/libc/ldexpf.src | 136 ++-- src/libc/ldiv.src | 18 +- src/libc/llabs.src | 12 +- src/libc/lldiv.src | 14 +- src/libc/log10f.c | 20 +- src/libc/log10f.src | 20 - src/libc/logbf.src | 29 +- src/libc/logf.c | 30 +- src/libc/logf.src | 20 - src/libc/makefile | 72 +- src/libc/memccpy.src | 7 +- src/libc/memcpy.src | 19 +- src/libc/memmem.src | 45 +- src/libc/memmove.src | 37 +- src/libc/mempcpy.src | 17 +- src/libc/memrchr.src | 11 +- src/libc/memrmem.src | 53 +- src/libc/memset.src | 11 +- src/libc/modff.src | 49 +- src/libc/os.src | 60 +- src/libc/outchar.src | 22 +- src/libc/powf.src | 28 +- src/libc/printf.src | 16 - src/libc/printf/makefile | 49 ++ src/libc/{ => printf}/nanoprintf.c | 36 +- src/libc/{ => printf}/nanoprintf.h | 0 src/libc/putc.src | 9 - src/libc/putchar.src | 12 +- src/libc/puts.src | 28 +- src/libc/rand.src | 16 +- src/libc/scalblnf.src | 15 +- src/libc/scalblnl.src | 13 +- src/libc/signbitf.src | 7 +- src/libc/signbitl.src | 7 +- src/libc/sinf.src | 32 +- src/libc/sinhf.c | 40 +- src/libc/sinhf.src | 20 - src/libc/snprintf.src | 28 - src/libc/sprintf.src | 18 - src/libc/sqrtf.c | 20 +- src/libc/sqrtf.src | 31 - src/libc/sqrtl.src | 11 +- src/libc/srand.src | 10 +- src/libc/stpcpy.src | 7 +- src/libc/stpncpy.src | 19 +- src/libc/strcasecmp.src | 79 +-- src/libc/strchrnul.src | 15 +- src/libc/strcmp.src | 23 +- src/libc/strcspn.src | 20 +- src/libc/strdup.src | 10 +- src/libc/strlcat.src | 28 +- src/libc/strlcpy.src | 12 +- src/libc/strlen.src | 14 +- src/libc/strncmp.src | 27 +- src/libc/strndup.src | 12 +- src/libc/strnlen.src | 8 +- src/libc/strrchr.src | 16 +- src/libc/strrstr.src | 14 +- src/libc/strspn.src | 18 +- src/libc/strtof.c | 27 +- src/libc/strtof.src | 20 - src/libc/strtol.src | 188 +++-- src/libc/strtoll.src | 150 ++-- src/libc/tanf.c | 20 +- src/libc/tanf.src | 20 - src/libc/tanhf.c | 20 +- src/libc/tanhf.src | 20 - src/libc/tolower.src | 13 +- src/libc/toupper.src | 15 +- src/libc/truncf.src | 21 +- src/libc/truncl.src | 25 +- src/libc/vsprintf.src | 19 - src/libc/wcslen.src | 13 +- src/libc/wcsnlen.src | 19 +- src/libc/wmemchr.src | 21 +- src/libc/wmemcmp.src | 23 +- src/libc/wmemcpy.src | 11 +- src/libc/wmemmove.src | 9 +- src/libc/wmemset.src | 7 +- src/libcxx/makefile | 37 +- src/libload/libload.h | 7 +- src/linker.mk | 70 -- src/linker_script.ld | 93 +++ src/makefile.mk | 352 ++++++--- src/softfloat/isNaNF32UI.src | 8 - src/softfloat/isNaNF64UI.src | 8 - src/softfloat/makefile | 43 +- src/softfloat/s_normSubnormalF64Sig.src | 14 +- src/softfloat/s_propagateNaNF64UI.src | 12 +- src/softfloat/s_roundPackToF32.c | 7 +- src/softfloat/s_roundPackToF64.c | 7 +- src/softfloat/s_shiftRightJam64.src | 33 +- src/softfloat/softfloat_isSigNaNF32UI.src | 11 +- src/softfloat/softfloat_isSigNaNF64UI.src | 11 +- test/fileioc/rename/src/main.c | 8 +- .../compiletime_classification/makefile | 3 +- .../compiletime_classification/src/main.c | 8 +- .../compiletime_classification/src/test.asm | 44 -- .../compiletime_classification/src/test.s | 44 ++ test/floating_point/complex/makefile | 3 +- .../complex/src/complex_alias.S | 41 ++ .../complex/src/complex_alias.asm | 29 - test/floating_point/complex/src/main.c | 8 +- .../float32_classification/makefile | 3 +- .../float32_classification/src/main.c | 4 +- test/floating_point/float32_fminmax/makefile | 3 +- .../float32_fminmax/src/main.cpp | 8 +- test/floating_point/float32_frexp/makefile | 3 +- test/floating_point/float32_frexp/src/main.c | 8 +- test/floating_point/float32_ilogb/makefile | 3 +- test/floating_point/float32_ilogb/src/main.c | 12 +- test/floating_point/float32_ldexp/makefile | 3 +- test/floating_point/float32_ldexp/src/main.c | 10 +- test/floating_point/float32_math/makefile | 3 +- test/floating_point/float32_math/src/main.cpp | 4 +- test/floating_point/float32_modf/makefile | 3 +- test/floating_point/float32_modf/src/main.c | 8 +- .../float32_to_float64/makefile | 3 +- .../float32_to_float64/src/main.c | 8 +- test/floating_point/float32_trunc/makefile | 3 +- test/floating_point/float32_trunc/src/main.c | 8 +- .../float64_arithmetic/makefile | 3 +- .../src/{data.asm => data.S} | 18 +- .../float64_arithmetic/src/main.cpp | 14 +- .../float64_classification/makefile | 3 +- .../float64_classification/src/main.c | 4 +- test/floating_point/float64_frexp/makefile | 3 +- test/floating_point/float64_frexp/src/main.c | 8 +- .../float64_from_integer/makefile | 3 +- .../src/{crt_wrap.asm => crt_wrap.S} | 28 +- .../float64_from_integer/src/main.c | 12 +- test/floating_point/float64_ilogb/makefile | 3 +- test/floating_point/float64_ilogb/src/main.c | 12 +- test/floating_point/float64_ldexp/makefile | 3 +- test/floating_point/float64_ldexp/src/main.c | 10 +- test/floating_point/float64_math/makefile | 3 +- test/floating_point/float64_math/src/main.cpp | 8 +- test/floating_point/float64_rounding/makefile | 3 +- .../float64_rounding/src/main.c | 10 +- .../float64_to_float32/makefile | 3 +- .../float64_to_float32/src/main.c | 10 +- .../float64_to_integer/makefile | 3 +- test/floating_point/float64_trunc/makefile | 3 +- test/floating_point/float64_trunc/src/main.c | 8 +- test/floating_point/ultof/makefile | 3 +- test/floating_point/ultof/src/main.c | 8 +- test/fontlibc/glyph_width/src/main.c | 8 +- test/graphx/palette/makefile | 3 +- test/graphx/palette/src/main.c | 2 +- test/regression/bug0005/makefile | 3 +- test/regression/i48routines/makefile | 3 +- test/regression/i48routines/src/main.c | 6 +- test/standalone/asprintf_fprintf/makefile | 4 +- .../asprintf_fprintf/src/rename.asm | 38 - test/standalone/asprintf_fprintf/src/rename.s | 56 ++ test/standalone/concepts/makefile | 3 +- test/standalone/concepts/src/main.cpp | 2 +- test/standalone/errno/makefile | 3 +- test/standalone/errno/src/main.c | 4 +- test/standalone/ez80_builtin/makefile | 5 +- test/standalone/ez80_builtin/src/main.c | 8 +- test/standalone/i48div/makefile | 4 +- test/standalone/i48div/src/main.c | 8 +- test/standalone/mulu_b/makefile | 5 +- .../mulu_b/src/{crt_wrap.asm => crt_wrap.S} | 32 +- test/standalone/mulu_b/src/main.c | 8 +- test/standalone/scanf/makefile | 5 +- test/standalone/scanf/src/main.c | 8 +- test/standalone/stdbit/makefile | 2 +- test/standalone/stdbit/src/data.S | 300 ++++++++ test/standalone/stdbit/src/data.asm | 300 -------- test/standalone/stdbit/src/main.cpp | 8 +- test/standalone/strtol/makefile | 4 +- .../{char_to_digit.asm => char_to_digit.S} | 11 +- test/standalone/strtol/src/main.c | 10 +- test/standalone/wide_char/makefile | 4 +- test/standalone/wide_char/src/main.c | 8 +- test/standalone/wide_char/src/rename.asm | 28 - test/standalone/wide_char/src/rename.s | 42 ++ tools/cedev-config/src/main.c | 16 + tools/cedev-obj/.gitignore | 2 + tools/cedev-obj/Makefile | 68 ++ tools/cedev-obj/src/elf_inspect.c | 381 ++++++++++ tools/cedev-obj/src/elf_inspect.h | 52 ++ tools/cedev-obj/src/main.c | 265 +++++++ tools/convbin | 2 +- tools/convimg | 2 +- 519 files changed, 7757 insertions(+), 6317 deletions(-) rename src/{libc/boot_vsprintf.c => ce/boot_printf.c} (72%) delete mode 100644 src/ce/boot_sprintf.src rename src/{libc => ce}/boot_vsprintf.src (57%) delete mode 100644 src/ce/tice.src create mode 100644 src/crt/crt.src create mode 100644 src/crt/crt0.S delete mode 100644 src/crt/crt0.src create mode 100644 src/crt/errno.src delete mode 100644 src/crt/sneg.src delete mode 100644 src/crt/sneg_fast.src delete mode 100644 src/crt/snot.src delete mode 100644 src/crt/snot_fast.src delete mode 100644 src/crt/sshl.src delete mode 100644 src/libc/allocator.src create mode 100644 src/libc/allocator/allocator_simple.src rename src/libc/{ => allocator}/allocator_standard.c (89%) create mode 100644 src/libc/allocator/makefile delete mode 100644 src/libc/allocator_simple.src delete mode 100644 src/libc/asinf.src delete mode 100644 src/libc/atan2f.src delete mode 100644 src/libc/atanf.src create mode 100644 src/libc/atexit.src create mode 100644 src/libc/calloc.src delete mode 100644 src/libc/coshf.src delete mode 100644 src/libc/expf.src create mode 100644 src/libc/float32_div.src delete mode 100644 src/libc/floorf.src delete mode 100644 src/libc/fmodf.src delete mode 100644 src/libc/fprintf.src delete mode 100644 src/libc/getc.src delete mode 100644 src/libc/getchar.src delete mode 100644 src/libc/log10f.src delete mode 100644 src/libc/logf.src delete mode 100644 src/libc/printf.src create mode 100644 src/libc/printf/makefile rename src/libc/{ => printf}/nanoprintf.c (66%) rename src/libc/{ => printf}/nanoprintf.h (100%) delete mode 100644 src/libc/putc.src delete mode 100644 src/libc/sinhf.src delete mode 100644 src/libc/snprintf.src delete mode 100644 src/libc/sprintf.src delete mode 100644 src/libc/sqrtf.src delete mode 100644 src/libc/strtof.src delete mode 100644 src/libc/tanf.src delete mode 100644 src/libc/tanhf.src delete mode 100644 src/libc/vsprintf.src delete mode 100644 src/linker.mk create mode 100644 src/linker_script.ld delete mode 100644 src/softfloat/isNaNF32UI.src delete mode 100644 src/softfloat/isNaNF64UI.src delete mode 100644 test/floating_point/compiletime_classification/src/test.asm create mode 100644 test/floating_point/compiletime_classification/src/test.s create mode 100644 test/floating_point/complex/src/complex_alias.S delete mode 100644 test/floating_point/complex/src/complex_alias.asm rename test/floating_point/float64_arithmetic/src/{data.asm => data.S} (77%) rename test/floating_point/float64_from_integer/src/{crt_wrap.asm => crt_wrap.S} (62%) delete mode 100644 test/standalone/asprintf_fprintf/src/rename.asm create mode 100644 test/standalone/asprintf_fprintf/src/rename.s rename test/standalone/mulu_b/src/{crt_wrap.asm => crt_wrap.S} (81%) create mode 100644 test/standalone/stdbit/src/data.S delete mode 100644 test/standalone/stdbit/src/data.asm rename test/standalone/strtol/src/{char_to_digit.asm => char_to_digit.S} (74%) delete mode 100644 test/standalone/wide_char/src/rename.asm create mode 100644 test/standalone/wide_char/src/rename.s create mode 100644 tools/cedev-obj/.gitignore create mode 100644 tools/cedev-obj/Makefile create mode 100644 tools/cedev-obj/src/elf_inspect.c create mode 100644 tools/cedev-obj/src/elf_inspect.h create mode 100644 tools/cedev-obj/src/main.c diff --git a/.github/workflows/branch.yml b/.github/workflows/branch.yml index 43282a9f8..15e039790 100644 --- a/.github/workflows/branch.yml +++ b/.github/workflows/branch.yml @@ -11,6 +11,7 @@ env: AUTOTESTER_ROM: ${{github.workspace}}/secrets/83pce_515_530.rom CEDEV: ${{github.workspace}}/CEdev CEDEV_BIN: ${{github.workspace}}/CEdev/bin + CEDEV_BINUTILS_BIN: ${{github.workspace}}/CEdev/binutils/bin CEDEV_EXAMPLES: ${{github.workspace}}/CEdev/examples CEDEV_TEST: ${{github.workspace}}/toolchain/test CEMU_PATH: ${{github.workspace}}/CEmu @@ -33,24 +34,30 @@ jobs: fasmg: /source/macos/x64/fasmg arch-suffix: "-intel" ez80-bins-suffix: macOS_intel + binutils-suffix: macos_intel - runs-on: macos-14 fasmg: /source/macos/x64/fasmg arch-suffix: "-arm" ez80-bins-suffix: macOS_arm + binutils-suffix: macos_arm - runs-on: windows-latest fasmg: /fasmg.exe ez80-bins-suffix: windows + binutils-suffix: windows env: "env:" exe: .exe nul: nul ldflags: LDFLAGS="-static-libgcc -static-libstdc++ -static" - runs-on: ubuntu-22.04 ez80-bins-suffix: ubuntu + binutils-suffix: ubuntu fasmg: /fasmg.x64 runs-on: ${{matrix.runs-on}} steps: - name: Prepare Build Environment - run: cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BIN}} + run: | + cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BIN}} + cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BINUTILS_BIN}} - name: Download ez80-clang and ez80-link id: ez80-bins @@ -63,6 +70,17 @@ jobs: pathSource: ${{steps.ez80-bins.outputs.file-path}} pathTarget: ${{env.CEDEV_BIN}} + - name: Download binutils + id: binutils + uses: carlosperate/download-file-action@v2.0.2 + with: + file-url: https://github.com/CE-Programming/binutils-gdb/releases/download/nightly/binutils_${{matrix.binutils-suffix}}_nightly.zip + - name: Extract binutils + uses: DuckSoft/extract-7z-action@v1.0 + with: + pathSource: ${{steps.binutils.outputs.file-path}} + pathTarget: ${{env.CEDEV}} + - name: Add fasmg website to /etc/hosts since DNS seems to be broken if: runner.os == 'macOS' run: | @@ -109,7 +127,9 @@ jobs: - name: Make Binaries Executable if: runner.os != 'Windows' - run: chmod +x ${{env.CEDEV_BIN}}/* + run: | + chmod +x ${{env.CEDEV_BIN}}/* + chmod +x ${{env.CEDEV_BINUTILS_BIN}}/* - name: Test Build Dependencies run: | ez80-clang --version @@ -135,9 +155,14 @@ jobs: PREFIX: ${{github.workspace}} run: make -j4 -C ${{env.TOOLCHAIN_PATH}} install V=1 DESTDIR=${{github.workspace}} + - name: Remove Fasmg + run: cmake -E rm -f ${{env.CEDEV_BIN}}/fasmg${{matrix.exe}} + - name: Make Binaries Executable if: runner.os != 'Windows' - run: chmod +x ${{env.CEDEV_BIN}}/* + run: | + chmod +x ${{env.CEDEV_BIN}}/* + chmod +x ${{env.CEDEV_BINUTILS_BIN}}/* - name: Build Test Graphics run: make -j4 -C ${{env.CEDEV_TEST}} COMPRESSED=${{matrix.compressed}} V=1 gfx diff --git a/.github/workflows/make.yml b/.github/workflows/make.yml index e15f14515..84bebef24 100644 --- a/.github/workflows/make.yml +++ b/.github/workflows/make.yml @@ -13,6 +13,7 @@ env: AUTOTESTER_ROM: ${{github.workspace}}/secrets/83pce_515_530.rom CEDEV: ${{github.workspace}}/CEdev CEDEV_BIN: ${{github.workspace}}/CEdev/bin + CEDEV_BINUTILS_BIN: ${{github.workspace}}/CEdev/binutils/bin CEDEV_EXAMPLES: ${{github.workspace}}/CEdev/examples CEDEV_TEST: ${{github.workspace}}/toolchain/test CEMU_PATH: ${{github.workspace}}/CEmu @@ -33,15 +34,18 @@ jobs: fasmg: /source/macos/x64/fasmg arch-suffix: "-intel" ez80-bins-suffix: macOS_intel + binutils-suffix: macos_intel install-output-ext: "dmg" - runs-on: macos-14 fasmg: /source/macos/x64/fasmg arch-suffix: "-arm" ez80-bins-suffix: macOS_arm + binutils-suffix: macos_arm install-output-ext: "dmg" - runs-on: windows-latest fasmg: /fasmg.exe ez80-bins-suffix: windows + binutils-suffix: windows env: "env:" exe: .exe nul: nul @@ -49,12 +53,15 @@ jobs: install-output-ext: "zip" - runs-on: ubuntu-22.04 ez80-bins-suffix: ubuntu + binutils-suffix: ubuntu fasmg: /fasmg.x64 install-output-ext: "tar.gz" runs-on: ${{matrix.runs-on}} steps: - name: Prepare Build Environment - run: cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BIN}} + run: | + cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BIN}} + cmake -E echo >> $${{matrix.env}}GITHUB_PATH ${{env.CEDEV_BINUTILS_BIN}} - name: Download ez80-clang and ez80-link id: ez80-bins @@ -67,6 +74,17 @@ jobs: pathSource: ${{steps.ez80-bins.outputs.file-path}} pathTarget: ${{env.CEDEV_BIN}} + - name: Download binutils + id: binutils + uses: carlosperate/download-file-action@v2.0.2 + with: + file-url: https://github.com/CE-Programming/binutils-gdb/releases/download/nightly/binutils_${{matrix.binutils-suffix}}_nightly.zip + - name: Extract binutils + uses: DuckSoft/extract-7z-action@v1.0 + with: + pathSource: ${{steps.binutils.outputs.file-path}} + pathTarget: ${{env.CEDEV}} + - name: Add fasmg website to /etc/hosts since DNS seems to be broken if: runner.os == 'macOS' run: | @@ -139,9 +157,14 @@ jobs: PREFIX: ${{github.workspace}} run: make -j4 -C ${{env.TOOLCHAIN_PATH}} install V=1 DESTDIR=${{github.workspace}} + - name: Remove Fasmg + run: cmake -E rm -f ${{env.CEDEV_BIN}}/fasmg${{matrix.exe}} + - name: Make Binaries Executable if: runner.os != 'Windows' - run: chmod +x ${{env.CEDEV_BIN}}/* + run: | + chmod +x ${{env.CEDEV_BIN}}/* + chmod +x ${{env.CEDEV_BINUTILS_BIN}}/* - name: "[macOS] CodeSign Toolchain binaries" if: runner.os == 'macOS' && github.repository == 'CE-Programming/toolchain' # don't run on forks, since they don't have secrets @@ -461,4 +484,3 @@ jobs: token: ${{ secrets.CI_PAT_CLIBS_NIGHTLTY }} repository: CE-Programming/libraries event-type: ci-clibs-nightly - diff --git a/docs/headers/ti/sprintf.rst b/docs/headers/ti/sprintf.rst index ab7f6b0c0..1cdc0a78b 100644 --- a/docs/headers/ti/sprintf.rst +++ b/docs/headers/ti/sprintf.rst @@ -72,7 +72,8 @@ The truncating behavior of C99 `snprintf` can be replicated with `boot_asprintf` printf and fprintf ------------------ -`printf` and `fprintf` can be replicated by using `fputs` + +`printf` and `fprintf` can be replicated by using `fputs`. .. code-block:: c diff --git a/docs/static/asm.rst b/docs/static/asm.rst index f89e58001..66ce4f893 100644 --- a/docs/static/asm.rst +++ b/docs/static/asm.rst @@ -1,60 +1,50 @@ .. _asm: -Assembly Routines -================= +Assembly Files +============== -Assembly routines can be linked into a C/C++ program by putting them into the same **src** directory that your C/C++ sources are in, but with an **.asm** extension. -These can be placed in any subdirectory of **src** just like C/C++ sources. +Assembly files can be linked into a C/C++ program by putting them into the same **src** directory that your C/C++ sources are in. +Use a **.S** extension if you want the compiler's preprocessor to run on the file first, or use a **.s** extension if the assembly file does not need to be preprocessed. -Assembly Files --------------- +The use of inline assembly is supported, but highly discouraged as future changes to the compiler may render the inline assembly incompatible, and it reduces the readablity of the code. + +Assembler +--------- -.. _asm-consts: +The CE Toolchain uses the GNU Assembler (GAS) to assemble source files. +Historically the fasmg assembler was used, but is no longer supported to allow for better cross-platform support and linking performance. -Constants -^^^^^^^^^ +Documentation for the GNU Assembler: https://www.sourceware.org/binutils/docs/as/index.html -The top of the file is a good place defining constants or including other files that define constants. -These will be availabe throughout the rest of the file, but not in other files. -You can define a constant by saying :code:`my_constant := 42`. -You can include common constants in multiple files by defining them in a file named, say, **file.inc** and putting :code:`include 'file.inc'` in every file that needs them. -You should not generally put any labels, code, or data here. -If you try to reference a label defined here, you will get an :code:`Error: variable term used where not expected.` linker error which means you are trying to resolve an address that doesn't belong to any section. -See :ref:`asm-section` to fix this problem. +Specific Z80/ez80 directives: https://www.sourceware.org/binutils/docs/as/Z80-Directives.html .. _asm-assume: Assume ^^^^^^ -You should add a :code:`assume adl=1` before trying to emit any code, which ensures that you get 24-bit eZ80 instructions. -If you end an assembly file with :code:`assume adl=0` (which is the eZ80's 16-bit Z80 compatibility mode), it will propogate to another random assembly file. -All toolchain and compiler-generated sources make sure to reset the mode at the top of the file and end the file in the same mode, but if one of your sources end in Z80 mode, then any other one of your sources might begin in Z80 mode, so it is safer to put the :code:`assume` line in every file. +You should add a :code:`.assume ADL=1` before trying to emit any code, which ensures that you get 24-bit eZ80 instructions. .. _asm-section: -Section -^^^^^^^ +Sections +^^^^^^^^ -Now that we are in the correct mode, we need to tell the linker where to put things. -We use :code:`section .text` for code, :code:`section .data` for variables, and :code:`section .rodata` for constant data. -Currently these are all placed in RAM, so which section you choose to switch to is much less important than how often you switch sections, even if you are switching to the same section you are already in. -This is because every time you start a new, or restart the same, section, the linker gets a new opportunity to delete a block of dead code/data. +The CE Toolchain uses :code:`.section .text` for code, :code:`.section .data` for variables, and :code:`.section .rodata` for constant data. +Every time you start a new section (such as :code:`.section .text.function`), the linker has an opportunity to delete a block of dead code/data. Because of this, the correct time to switch sections is usually every time you start a new function or variable. -You should not let execution fall off the end of a block because you won't know if that block will be included or deleted from the output, however you can if you say :code:`require _symbol` of some public or private symbol defined in the next section to ensure that if the current block is included, then that will force the next block to also be included. -To define a symbol in a block that can be referenced from other blocks, you should do :code:`private _symbol` or :code:`public _symbol` right before its definition. -If it is private then it is only able to be referenced from the same file and no :ref:`extern ` should be used. -If it is public then it can be referenced within the same file without :ref:`extern ` just like private symbols, but public symbols can also be referenced from other files and even C/C++! -The public assembly symbol named :code:`_symbol` is accessible in C by the global name :code:`symbol`, assuming it is properly declared, with your asm symbol acting as the definition. +To define a symbol in a block that can be referenced from other blocks, you should do :code:`.local _symbol` or :code:`.global _symbol` right before its definition. +If it is local then it is only able to be referenced from the same file and no :ref:`.extern ` should be used. +If it is global then it can be referenced within the same file without :ref:`.extern ` just like local symbols, but global symbols can also be referenced from other files and even C/C++! +The gllobal assembly symbol named :code:`_symbol` is accessible in C by the global name :code:`symbol` (note the leading underscore), assuming it is properly declared, with your asm symbol acting as the definition. .. _asm-extern: Extern ^^^^^^ -At the end of the file is a good place to list every external symbol that you might depend on like :code:`extern _symbol`. -This includes both public symbols defined in another assembly file and global symbols from C, prefixed with an underscore like usual. -Lastly, you should not let execution fall off the end of a file because the next file that gets assembled is unpredictable and you could end up anywhere! +At the end of the file is a good place to list every external symbol that you might depend on like :code:`.extern _symbol`. +This includes both global symbols defined in another assembly file and global symbols from C, prefixed with an underscore. Block ordering can only be relied on within a single file, and only for blocks belonging to the same section. Linking ASM routines to C/C++ @@ -69,17 +59,18 @@ Below is an example C prototype followed by the assembly implementation: .. code-block:: c - void asm_func(int arg); + void asm_func(int argument); :code:`asm_func.asm` .. code-block:: - assume adl=1 - - section .text - - public _asm_func + .assume adl=1 + + .section .text._asm_func + .global _asm_func + .type _asm_func, @function + _asm_func: pop hl pop de @@ -91,33 +82,29 @@ Below is an example C prototype followed by the assembly implementation: pop de ret - - extern _external_func + + .extern _external_func :code:`asm_func.c` .. code-block:: - int external_func(int arg) { + int external_func(int arg) + { printf("external_func called with %d\n", arg); return 4321; } - void test() { + void test(void) + { int arg = 1234; printf("calling asm_func with %d\n", arg); int ret = asm_func(arg); printf("asm_func returned %d\n", ret); } -Preserve -^^^^^^^^ - -Assembly routines must preserve the :code:`IX` and :code:`SP` registers. -All other registers are free for use. - -Arguments -^^^^^^^^^ +ABI Arguments +^^^^^^^^^^^^^ Arguments are pushed from last to first corresponding to the C prototype. In eZ80, 3 bytes are always pushed to the stack regardless of the actual size. @@ -126,6 +113,9 @@ For example, if a *short* type is used, the upper byte of the value pushed on th This table lists the locations relative to *sp* from within the called funciton. Note that :code:`sp + [0,2]` contains the return address. +Assembly routines must preserve the :code:`IX` and :code:`SP` registers. +All other registers are free for use. + +-------------+------------+----------------------+ | C/C++ Type | Size | Stack Location | +=============+============+======================+ @@ -150,8 +140,8 @@ Note that :code:`sp + [0,2]` contains the return address. | pointer | 3 bytes | sp + [3,5] | +-------------+------------+----------------------+ -Returns -^^^^^^^ +ABI Returns +^^^^^^^^^^^ This table lists which registers are used for return values from a function. The type's sign does not affect the registers used, but may affect the value returned. diff --git a/docs/static/contributing.rst b/docs/static/contributing.rst index e44e0da57..4a5d264c5 100644 --- a/docs/static/contributing.rst +++ b/docs/static/contributing.rst @@ -21,10 +21,16 @@ Building the CE Toolchain Linux and macOS ~~~~~~~~~~~~~~~ -Get the `ez80 LLVM compiler `_. +It is usually easier to download a toolchain release which already contains the needed binaries for compiling/assembling if you are just making code modifications to the toolchain. +If you need to do everything from scratch though, the steps are below. + +Download the prebuilt `ez80 LLVM compiler `_. Make sure that ``ez80-clang`` and ``ez80-link`` are reachable by the system's PATH environment variable. -Get the `fasmg assembler `_. +Download the prebuilt `ez80 GNU binutils `_ +Make sure that ``bin`` directory is reachable by the system's PATH environment variable. + +Download the `fasmg assembler `_. The download is located near the bottom of the page. Extract the ``fasmg.x64`` executable to the same location as the compiler. Rename it to just ``fasmg``. @@ -51,15 +57,21 @@ This is configurable with :code:`make install PREFIX=[LOCATION]` Windows ~~~~~~~ +It is usually easier to download a toolchain release which already contains the needed binaries for compiling/assembling if you are just making code modifications to the toolchain. +If you need to do everything from scratch though, the steps are below. + Get `MSYS2 `_ and use the `MinGW64` environment. The only required pacakge is `mingw-w64-x86_64-toolchain `_. Make sure the ``C:\msys64\mingw64\bin`` directory is in the system's PATH environment variable. -Get the `ez80 LLVM compiler `_. +Download the prebuilt `ez80 LLVM compiler `_. Make sure that ``ez80-clang.exe`` and ``ez80-link.exe`` are reachable by the system's PATH environment variable. -Get the `fasmg assembler `_. +Download the prebuilt `ez80 GNU binutils `_ +Make sure that ``bin`` directory is reachable by the system's PATH environment variable. + +Download the `fasmg assembler `_. The download is located near the bottom of the page. Extract the ``fasmg.exe`` executable to the same location as the compiler. diff --git a/docs/static/faq.rst b/docs/static/faq.rst index b8f297321..36c348864 100644 --- a/docs/static/faq.rst +++ b/docs/static/faq.rst @@ -13,7 +13,8 @@ Including the output of the :code:`make V=1` command outputs more verbose inform What versions of C/C++ are supported? ------------------------------------- -The CE Toolchain uses LLVM/Clang v15.0.7 - the status of each language feature support can be found at the respective links: `C `_, `C++ `_ +The CE Toolchain uses LLVM/Clang v17. +The status of each language feature support can be found at the respective links: `C `_, `C++ `_ What is the C/C++ Runtime Memory Layout? ---------------------------------------- @@ -29,37 +30,14 @@ The following graphic breaks down the address space. .. image:: images/mem_layout.png :align: center -How can I use fasmg on a non-x86 processor? -------------------------------------------- - -`Fasmg `_ is a macro assembler used for assembling and linking project source files. -The project is written in x86 assembly, which means it cannot be run directly on non-x86 processors (such as ARM). -To mitigate this, the `QEMU `_ project can be used to emulate the x86 processor in user-mode so that it can be -used directly. If you use a Debian-based system such as Ubuntu or Linux Mint, you can install QEMU using the following command: - -.. code-block:: bash - - sudo apt install qemu-user - -Next, open the file :code:`CEdev/meta/makefile.mk` in the toolchain install directory and locate the following line: - -.. code-block:: makefile - - FASMG = $(call NATIVEPATH,$(BIN)/fasmg) - -Add the text "qemu-x86_64" directly after the equal sign, shown below. -Now, fasmg will execute in user mode under QEMU, allowing it to successfully complete the assembly and linking steps. - -.. code-block:: makefile - - FASMG = qemu-x86_64 $(call NATIVEPATH,$(BIN)/fasmg) - My code used to compile?! ------------------------- -But now the linker says :code:`Error: variable term used where not expected`. - You probably have assembly code that was not placed in a linker section, see :ref:`Assembly Constants `. - But now I get a bunch of warnings and errors. The LLVM compiler being used is able to catch many more coding issues than the previous ZDS compiler. These are real issues that should be resolved. + +But now my assembly files don't compile. + The CE Toolchain switched to using the GNU Assembler (GAS) in version 15.0.0. + This means that assembly files will need to be ported from the fasmg syntax to the GAS syntax. + More information can be found in the :ref:`Assembly Files ` page. diff --git a/docs/static/getting-started.rst b/docs/static/getting-started.rst index a32e6fbdf..c85dd54e6 100644 --- a/docs/static/getting-started.rst +++ b/docs/static/getting-started.rst @@ -93,7 +93,6 @@ Use the `CEmu `_ emulator to run the buil .. tip:: Antivirus software (e.g. Windows Defender) may flag binaries in the :code:`CEdev/bin` directory as false positives, and either quarantine/remove the files or prevent them from running. - This may result in build errors such as being unable find/execute `fasmg`. Please whitelist or disable scanning in :code:`CEdev/bin` to prevent these false positives from occurring. Project Structure diff --git a/docs/static/makefile-options.rst b/docs/static/makefile-options.rst index 7d99a90de..33f9d148f 100644 --- a/docs/static/makefile-options.rst +++ b/docs/static/makefile-options.rst @@ -109,31 +109,41 @@ Default: :code:`YES`. .. rubric:: EXTRA_LDFLAGS -These flags are passed directly to the fasmg linker. +These flags are passed directly to the GNU linker (ld). .. code-block:: makefile EXTRA_LDFLAGS = -.. rubric:: PREFER_OS_CRT +.. rubric:: PREFER_CE_CRT -Prefer the builtin OS CRT (Compiler-Run-Time) functions if they exist. +Prefer the calculator's builtin CRT (Compiler-Run-Time) functions if they exist. This can help to decrease the output size in some circumstances, as a select number of CRT functions will execute from flash. Default: :code:`NO`. +.. code-block:: makefile + + HAS_MATH_ERRNO = NO + +.. rubric:: HAS_MATH_ERRNO + +By default, the compiler flag :code:`-fno-math-errno` is added to improve performance. +However, this may lead to discrepencies on the value of :code:`errno` when running math operations in some cases. +To avoid this, set this option to :code:`YES`. + .. code-block:: makefile PREFER_OS_CRT = NO -.. rubric:: PREFER_OS_LIBC +.. rubric:: PREFER_CE_LIBC -Prefer the builtin OS LIBC functions if they exist. +Prefer the calculator's builtin LIBC functions if they exist. This can help to decrease the output size in some circumstances, as a select number of LIBC functions will execute from flash. Default: :code:`YES`. .. code-block:: makefile - PREFER_OS_LIBC = YES + PREFER_CE_LIBC = YES .. rubric:: LIBLOAD_OPTIONAL @@ -194,15 +204,6 @@ Extra libload (``.lib``) libraries to be added at link time. EXTRA_LIBLOAD_LIBS = -.. rubric:: SKIP_LIBRARY_LDFLAGS - -Completely omit the :code:`-library` flags passed to fasmg when linking. -Default: :code:`NO`. - -.. code-block:: makefile - - SKIP_LIBRARY_LDFLAGS = YES - Extra command(s) to run when :code:`make clean` is executed. .. code-block:: makefile @@ -233,4 +234,3 @@ Define rules for the files after including the main CEdev makefile. $(BINDIR)/levelpack.bin: $(call MKDIR,$(@D)) echo "levelpack" > $(BINDIR)/levelpack.bin - diff --git a/docs/static/printf.rst b/docs/static/printf.rst index 4cdefeca6..b641a6927 100644 --- a/docs/static/printf.rst +++ b/docs/static/printf.rst @@ -6,7 +6,7 @@ Using printf Functions What's the deal with printf? ---------------------------- -The `printf` and related functions (`sprintf`, `vsprintf`, etc.) are based on a relatively `small implementation `_. +The `printf` and related functions (`sprintf`, `vsprintf`, etc.) are based on a relatively `small implementation `_. However, they contribute around 8 KiB to the resultant program. It is highly recommended to not use `printf` and related functions at all because of this. If you insist on using these functions, this page details how to do so in the next section. diff --git a/makefile b/makefile index 68e2f6683..e57642599 100644 --- a/makefile +++ b/makefile @@ -21,7 +21,8 @@ include $(CURDIR)/src/common.mk LIBS := libload graphx fontlibc keypadc fileioc usbdrvce srldrvce msddrvce fatdrvce lcddrvce SRCS := ce crt libc libcxx softfloat -TOOLS := fasmg convbin convimg convfont cedev-config +TOOLS := fasmg convbin convimg convfont cedev-config cedev-obj + ifeq ($(OS),Windows_NT) WINDOWS_COPY := $(call COPY,resources\windows\make.exe,$(INSTALL_BIN)) && $(call COPY,resources\windows\cedev.bat,$(INSTALL_DIR)) @@ -44,7 +45,6 @@ $(LIBS): fasmg $(Q)$(MAKE) -C $(call SRCDIR,$@) install: all $(addprefix install-,$(SRCS)) $(addprefix install-,$(LIBS)) - $(Q)$(MAKE) -f linker.mk -C src -B $(Q)$(call MKDIR,$(INSTALL_DIR)) $(Q)$(call MKDIR,$(INSTALL_BIN)) $(Q)$(call MKDIR,$(INSTALL_H)) @@ -55,14 +55,12 @@ install: all $(addprefix install-,$(SRCS)) $(addprefix install-,$(LIBS)) $(Q)$(call MKDIR,$(INSTALL_EXAMPLES)) $(Q)$(call COPYDIR,$(call NATIVEPATH,examples/*),$(INSTALL_EXAMPLES)) $(Q)$(call COPY,$(call NATIVEPATH,src/makefile.mk),$(INSTALL_META)) - $(Q)$(call COPY,$(call NATIVEPATH,src/linker_script),$(INSTALL_META)) - $(Q)$(call COPY,$(call NATIVEPATH,tools/fasmg/fasmg-ez80/commands.alm),$(INSTALL_META)) - $(Q)$(call COPY,$(call NATIVEPATH,tools/fasmg/fasmg-ez80/ez80.alm),$(INSTALL_META)) - $(Q)$(call COPY,$(call NATIVEPATH,tools/fasmg/fasmg-ez80/ld.alm),$(INSTALL_META)) + $(Q)$(call COPY,$(call NATIVEPATH,src/linker_script.ld),$(INSTALL_META)) $(Q)$(call COPY,$(call NATIVEEXE,tools/convfont/convfont),$(INSTALL_BIN)) $(Q)$(call COPY,$(call NATIVEEXE,tools/convimg/bin/convimg),$(INSTALL_BIN)) $(Q)$(call COPY,$(call NATIVEEXE,tools/convbin/bin/convbin),$(INSTALL_BIN)) $(Q)$(call COPY,$(call NATIVEEXE,tools/cedev-config/bin/cedev-config),$(INSTALL_BIN)) + $(Q)$(call COPY,$(call NATIVEEXE,tools/cedev-obj/bin/cedev-obj),$(INSTALL_BIN)) $(Q)$(WINDOWS_COPY) $(addprefix install-,$(SRCS)): $(TOOLS) @@ -73,14 +71,13 @@ $(addprefix install-,$(LIBS)): $(TOOLS) libs: $(LIBS) $(TOOLS) $(Q)$(call NATIVEEXE,tools/convbin/bin/convbin) --oformat 8xg-auto-extract \ - $(foreach library,$(LIBS),$(addprefix --input ,$(call SRCDIR,$(library))/$(library).8xv)) --output $(call NATIVEPATH,clibs.8xg) + $(foreach library,$(LIBS),$(addprefix --input ,$(call SRCDIR,$(library))/$(library).8xv)) --output clibs.8xg libs-zip: $(Q)$(call MKDIR,clibs) $(Q)$(foreach library,$(LIBS),$(call COPY,$(call NATIVEPATH,$(call SRCDIR,$(library))/$(library).8xv),clibs) &&) $(call NATIVEEXE,7z) a clibs_separately_in_zip.zip clibs clean: $(addprefix clean-,$(TOOLS)) $(addprefix clean-,$(SRCS)) $(addprefix clean-,$(LIBS)) - $(Q)$(call REMOVE,src/linker_script) $(Q)$(call REMOVE,clibs.8xg) $(Q)$(call RMDIR,docs/build) $(Q)$(call RMDIR,docs/doxygen) diff --git a/src/ce/atomic_load_32.src b/src/ce/atomic_load_32.src index 9441bb065..d7b149d8e 100644 --- a/src/ce/atomic_load_32.src +++ b/src/ce/atomic_load_32.src @@ -1,30 +1,32 @@ ; --- ; uint32_t atomic_load_32(volatile uint32_t *p) ; --- - assume adl=1 + .assume adl=1 + + .section .text + .global _atomic_load_32 + .type _atomic_load_32, @function - section .text - public _atomic_load_32 _atomic_load_32: pop hl - ex (sp),iy + ex (sp), iy push hl - ld c,0 -retry: + ld c, 0 +.L.retry: ; Wait for a different (increasing) amount of time before each retry to prevent ; getting caught in an endless loop of the value changing between reads with a ; fixed period equal to the amount of time it takes for each retry inc c ld b,c -wait: - djnz wait +.L.wait: + djnz .L.wait ; Read the value twice. - lea hl,iy+3 + lea hl, iy+3 ; Time between first and last byte read: - ld de,(iy) ; 2R - ld a,(hl) ; + 1F+1R - cp a,(hl) ; + 1F+1R - ld hl,(iy) ; + 3F+3R + ld de, (iy) ; 2R + ld a, (hl) ; + 1F+1R + cp a, (hl) ; + 1F+1R + ld hl, (iy) ; + 3F+3R ; = 5F+7R ; = 48cc (assuming F = R = 3) ; = 1us (assuming 48MHz clock speed) @@ -52,10 +54,10 @@ wait: ; ; (Furthermore, if a change occurs in the middle of both 32-bit reads and the ; bytes already read change in both, then both values read become invalid.) - jr nz,retry - sbc hl,de - jr nz,retry + jr nz, .L.retry + sbc hl, de + jr nz, .L.retry ; Values don't differ, good to go. - add hl,de - ld e,a ; euhl = value read + add hl, de + ld e, a ; euhl = value read ret diff --git a/src/ce/atomic_load_decreasing_32.src b/src/ce/atomic_load_decreasing_32.src index 363509218..aa98148b4 100644 --- a/src/ce/atomic_load_decreasing_32.src +++ b/src/ce/atomic_load_decreasing_32.src @@ -1,33 +1,35 @@ ; --- ; uint32_t atomic_load_decreasing_32(volatile uint32_t *p) ; --- - assume adl=1 + .assume adl=1 + + .section .text + .global _atomic_load_decreasing_32 + .type _atomic_load_decreasing_32, @function - section .text - public _atomic_load_decreasing_32 _atomic_load_decreasing_32: pop hl - ex (sp),iy + ex (sp), iy push hl ; Temporarily disable interrupts. - ld a,i + ld a, i di ; Read the value twice. ; first value read = cude, second value read = auhl ; Time between first and last byte read: - ld de,(iy) ; 2R - ld c,(iy+3) ; + 3F+1R - ld hl,(iy) ; + 3F+3R - ld a,(iy+3) ; + 3F+1R + ld de, (iy) ; 2R + ld c, (iy+3) ; + 3F+1R + ld hl, (iy) ; + 3F+3R + ld a, (iy+3) ; + 3F+1R ; = 9F+7R ; = 56cc (assuming F = R = 3) ; ~ 1.17us (assuming 48MHz clock speed) ; + approximate worst-case LCD + USB DMA ; ~ 5us ; Re-enable interrupts if they were previously enabled. - jp po,no_ei + jp po, .L.no_ei ei -no_ei: +.L.no_ei: ; Compare and return the greater of the two values read. ; ; If the values differ, then the underlying value changed between reading the @@ -69,21 +71,21 @@ no_ei: ; ; Combining all of these cases and assumptions, the greater of the two values ; read will always be valid. - or a,a - sbc hl,de - sbc a,c ; auhl = second value read + or a, a + sbc hl, de + sbc a, c ; auhl = second value read ; - first value read - jr c,swap + jr c, .L.swap ; second value read >= first value read ; ==> second value read is valid - add hl,de - adc a,c - ld e,a ; euhl = second value read + add hl, de + adc a, c + ld e, a ; euhl = second value read ret -swap: +.L.swap: ; second value read < first value read ; ==> first value read is valid - ex de,hl - ld e,c ; euhl = first value read + ex de, hl + ld e, c ; euhl = first value read ret diff --git a/src/ce/atomic_load_increasing_32.src b/src/ce/atomic_load_increasing_32.src index 3f29cc0bc..4a669d1fa 100644 --- a/src/ce/atomic_load_increasing_32.src +++ b/src/ce/atomic_load_increasing_32.src @@ -1,42 +1,44 @@ ; --- ; uint32_t atomic_load_increasing_32(volatile uint32_t *p) ; --- - assume adl=1 + .assume adl=1 + + .section .text + .global _atomic_load_increasing_32 + .type _atomic_load_increasing_32, @function - section .text - public _atomic_load_increasing_32 _atomic_load_increasing_32: ; CC: 202 + 9 * read_1_invalid + 3 * ie ; Timing assumes fetching from RAM (4cc) and reading from non-RAM (3cc). ; Read the argument. pop hl - ex (sp),iy ; iy = p + ex (sp), iy ; iy = p push hl ; ^ 48 cc ; Temporarily disable interrupts. - ld a,i + ld a, i di ; ^ 12 cc ; Read from the pointer twice: first into cude, second into auhl. ; Time between first and last byte read: - ld de,(iy) ; 2R + ld de, (iy) ; 2R ; ^ 21 cc ; 48 + 12 + 21 - 6 = 75 cc until first value captured if valid - ld c,(iy+3) ; + 3F + 1R - ld hl,(iy) ; + 3F + 3R + ld c, (iy+3) ; + 3F + 1R + ld hl, (iy) ; + 3F + 3R ; ^ 36 cc ; 48 + 12 + 21 + 36 - 5 = 112 cc until second value captured if valid - ld a,(iy+3) ; + 3F + 1R + ld a, (iy+3) ; + 3F + 1R ; == 9F + 7R ; == 57 cc ; + 9 * 19 cc = 171 cc (worst-case DMA) ; = 228 cc ; ^ 15 cc ; Re-enable interrupts if they were previously enabled. - jp po,no_ei + jp po, .L.no_ei ei -no_ei: +.L.no_ei: ; ^ 17 + 3 * ie cc ; Compare and return the lesser of the two values read. ; @@ -81,24 +83,24 @@ no_ei: ; ; Combining all of these cases and assumptions, the lesser of the two values ; read will always be valid. - or a,a - sbc hl,de - sbc a,c ; auhl = second value read + or a, a + sbc hl, de + sbc a, c ; auhl = second value read ; - first value read ; ^ 16 cc - jr c,no_swap + jr c, .L.no_swap ; second value read >= first value read ; ==> first value read is valid - ex de,hl - ld e,c ; euhl = first value read + ex de, hl + ld e, c ; euhl = first value read ret ; ^ 37 cc -no_swap: +.L.no_swap: ; second value read < first value read ; ==> second value read is valid - add hl,de - adc a,c - ld e,a ; euhl = second value read + add hl, de + adc a, c + ld e, a ; euhl = second value read ret -; ^ 46 cc (including conditional jr into) \ No newline at end of file +; ^ 46 cc (including conditional jr into) diff --git a/src/libc/boot_vsprintf.c b/src/ce/boot_printf.c similarity index 72% rename from src/libc/boot_vsprintf.c rename to src/ce/boot_printf.c index 0343b671b..ab3be414b 100644 --- a/src/libc/boot_vsprintf.c +++ b/src/ce/boot_printf.c @@ -20,6 +20,7 @@ int boot_vsnprintf(char *__restrict buffer, size_t count, const char *__restrict } return boot_vsprintf(buffer, format, args); } +__attribute__((weak, alias("boot_vsnprintf"))) int vsnprintf(char *__restrict buffer, size_t count, const char *__restrict format, va_list args); int boot_snprintf(char *__restrict buffer, size_t count, const char *__restrict format, ...) { va_list args; @@ -28,6 +29,7 @@ int boot_snprintf(char *__restrict buffer, size_t count, const char *__restrict va_end(args); return ret; } +__attribute__((weak, alias("boot_snprintf"))) int snprintf(char *__restrict buffer, size_t count, const char *__restrict format, ...); int boot_vasprintf(char **__restrict p_buffer, const char *__restrict format, va_list args) { int ret = -1; @@ -38,12 +40,13 @@ int boot_vasprintf(char **__restrict p_buffer, const char *__restrict format, va return str_len; } size_t buffer_size = (size_t)str_len + 1; - *p_buffer = (char*)malloc(buffer_size); + *p_buffer = malloc(buffer_size); if (*p_buffer != NULL) { ret = boot_vsprintf(*p_buffer, format, args); } return ret; } +__attribute__((weak, alias("boot_vasprintf"))) int vasprintf(char **__restrict p_buffer, const char *__restrict format, va_list args); int boot_asprintf(char **__restrict p_str, const char *__restrict format, ...) { va_list args; @@ -52,3 +55,4 @@ int boot_asprintf(char **__restrict p_str, const char *__restrict format, ...) { va_end(args); return ret; } +__attribute__((weak, alias("boot_asprintf"))) int asprintf(char **__restrict p_str, const char *__restrict format, ...); diff --git a/src/ce/boot_sprintf.src b/src/ce/boot_sprintf.src deleted file mode 100644 index c0446c725..000000000 --- a/src/ce/boot_sprintf.src +++ /dev/null @@ -1,9 +0,0 @@ - assume adl=1 - - section .text - -; to reduce binary size (or performance in the case of sprintf), ti's routines -; can be linked instead of the toolchain's routines - - public _boot_sprintf -_boot_sprintf := 0000BCh diff --git a/src/libc/boot_vsprintf.src b/src/ce/boot_vsprintf.src similarity index 57% rename from src/libc/boot_vsprintf.src rename to src/ce/boot_vsprintf.src index 2a8f88d27..6b4d483e7 100644 --- a/src/libc/boot_vsprintf.src +++ b/src/ce/boot_vsprintf.src @@ -1,8 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text._boot_vsprintf + .global _boot_vsprintf + .type _boot_vsprintf, @function - public _boot_vsprintf + .weak _vsprintf + .type _vsprintf, @function ; wraps boot_sprintf _boot_vsprintf: @@ -17,39 +20,39 @@ _boot_vsprintf: pop bc inc bc ; Track pointer to stack allocation - lea de, ix -.countSpecifiersLoop: + lea de, ix + 0 +.L.count_specifiers_loop: ld a, '%' -.countSpecifiersInnerLoop: +.L.count_specifiers_inner_loop: ; Find format specifier cpir - jr nz, .countDone + jr nz, .L.count_done ; Check for escaped specifier cpi - jr z, .countSpecifiersInnerLoop + jr z, .L.count_specifiers_inner_loop dec hl inc bc ld a, '*' -.countSpecifiersIncrement: +.L.count_specifiers_increment: ; Add one parameter dec de dec de dec de -.countSpecifiersFormat: +.L.count_specifiers_format: ; Check for end of specifier bit 6, (hl) - jr nz, .countSpecifiersLoop + jr nz, .L.count_specifiers_loop ; Check for additional variable-length parameter cpi - jr z, .countSpecifiersIncrement + jr z, .L.count_specifiers_increment ; Check for end of string - jp pe, .countSpecifiersFormat -.countDone: + jp pe, .L.count_specifiers_format +.L.count_done: ; Get length of parameters - lea hl, ix + lea hl, ix + 0 or a, a sbc hl, de - jr z, .noCopy + jr z, .L.no_copy ; Allocate space for parameters ex de, hl ld sp, hl @@ -59,7 +62,7 @@ _boot_vsprintf: pop bc ld hl, (ix + 12) ldir -.noCopy: +.L.no_copy: ld hl, (ix + 9) push hl ld hl, (ix + 6) @@ -69,6 +72,6 @@ _boot_vsprintf: pop ix ret - extern _boot_sprintf - extern __frameset0 - extern _strlen + .extern _boot_sprintf + .extern __frameset0 + .extern _strlen diff --git a/src/ce/debug.src b/src/ce/debug.src index ce32cf27f..17a82750c 100644 --- a/src/ce/debug.src +++ b/src/ce/debug.src @@ -1,52 +1,58 @@ - assume adl=1 + .assume adl=1 + + .section .text._dbg_Debugger + .global _dbg_Debugger + .type _dbg_Debugger, @function - section .text - public _dbg_Debugger _dbg_Debugger: scf sbc hl,hl ld (hl),2 ret - section .text - public _dbg_WatchpointSet + .section .text._dbg_WatchpointSet + .global _dbg_WatchpointSet + .type _dbg_WatchpointSet, @function + _dbg_WatchpointSet: ; currently have to do stupid stuff until CEmu is updated to be less dumb - ld iy,0 - add iy,sp + ld iy, 0 + add iy, sp scf - sbc hl,hl - ld de,(iy + 3) ; addr - ld bc,(iy + 6) ; size (must be 1 right now) - ld a,(iy + 9) ; mask - ld (hl),8 - ld (hl),4 - or a,a ; 0 = remove + sbc hl, hl + ld de, (iy + 3) ; addr + ld bc, (iy + 6) ; size (must be 1 right now) + ld a, (iy + 9) ; mask + ld (hl), 8 + ld (hl), 4 + or a, a ; 0 = remove ret z - bit 0,a ; read - jr z,.noread - bit 1,a ; write - jr z,.noreadwrite - ld (hl),7 - jr .checkexecute -.noreadwrite: - ld (hl),5 - jr .checkexecute -.noread: - bit 1,a ; write - jr z,.checkexecute - ld (hl),6 -.checkexecute: - bit 2,a ; execute + bit 0, a ; read + jr z, .L.noread + bit 1, a ; write + jr z, .L.noreadwrite + ld (hl), 7 + jr .L.checkexecute +.L.noreadwrite: + ld (hl), 5 + jr .L.checkexecute +.L.noread: + bit 1, a ; write + jr z, .L.checkexecute + ld (hl), 6 +.L.checkexecute: + bit 2, a ; execute ret z - ld (hl),3 + ld (hl), 3 ret - section .text - public _dbg_WatchpointRemoveAll + .section .text._dbg_WatchpointRemoveAll + .global _dbg_WatchpointRemoveAll + .type _dbg_WatchpointRemoveAll, @function + _dbg_WatchpointRemoveAll: scf - sbc hl,hl - ld (hl),9 - ld (hl),10 + sbc hl, hl + ld (hl), 9 + ld (hl), 10 ret diff --git a/src/ce/delay.src b/src/ce/delay.src index 5bf887da9..f0d91df48 100644 --- a/src/ce/delay.src +++ b/src/ce/delay.src @@ -1,15 +1,17 @@ ; void delay(uint16_t millis); - assume adl=1 + .assume adl=1 -if 0 +.if 0 ; Minimal caller code (for timing calculation). call _delay ; ^ 22 cc -end if +.endif + + .section .text._delay + .global _delay + .type _delay, @function - section .text - public _delay _delay: ; Timing assumes fetching from RAM (4cc) and the first timer read being valid. @@ -34,15 +36,15 @@ _delay: dec.s hl xor a, a ; a = 0 ld e, a ; euhl = millis - 1 -.multiplier_fp := (256 * 32768 + 1000 - 1) / 1000 -assert .multiplier_fp shr 24 = 0 - ld bc, .multiplier_fp ; aubc = ceil(256 * 32768 / 1e3) -assert ($FFFF * .multiplier_fp) shr 32 = 0 + .equ .L.multiplier_fp, (256 * 32768 + 1000 - 1) / 1000 +;assert .multiplier_fp shr 24 = 0 + ld bc, .L.multiplier_fp ; aubc = ceil(256 * 32768 / 1e3) +;assert ($FFFF * .multiplier_fp) shr 32 = 0 call __lmulu ; euhl = (millis - 1) * ; ceil(256 * 32768 / 1e3) ; https://docs.google.com/spreadsheets/d/1mZwDn6rEw3-uSQPuy48Ez0UWIvnggLiJxWft4u4OtcU/edit?usp=sharing -.correction_fp := 413 - ld bc, .multiplier_fp + .correction_fp + .equ .L.correction_fp, 413 + ld bc, .L.multiplier_fp + .L.correction_fp add hl, bc adc a, e ; auhl = millis * ; ceil(256 * 32768 / 1e3) + @@ -61,10 +63,10 @@ assert ($FFFF * .multiplier_fp) shr 32 = 0 ; Join common code for the rest. jp ___sleep_common.3 + .global _msleep + .type _msleep, @function - public _msleep -_msleep := _delay - + .set _msleep, _delay extern ___sleep_common.3 extern __lmulu diff --git a/src/ce/eval.src b/src/ce/eval.src index 04f29218b..2b0738d2e 100644 --- a/src/ce/eval.src +++ b/src/ce/eval.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text._os_EvalVar + .global _os_EvalVar + .type _os_EvalVar, @function - section .text - public _os_EvalVar _os_EvalVar: pop de ex (sp), hl @@ -11,16 +13,16 @@ _os_EvalVar: call $20304 ; mov8b ld hl, ($D02596) ; tmpcnt push hl - ld hl, .error + ld hl, .L_os_EvalVar.error call $20798 ; push error handler call $20510 ; findsym ld a, 141 ; undefined - jr c, .error + jr c, .L_os_EvalVar.error call $20F00 ; parseinp call $20F30 ; stoans call $2079C ; pop error handler xor a, a -.error: +.L_os_EvalVar.error: pop de push af call $20E80 ; fixtempcnt @@ -31,14 +33,16 @@ _os_EvalVar: res 0, (iy + 7) ret - section .text - public _os_Eval + .section .text._os_Eval + .global _os_Eval + .type _os_Eval, @function + _os_Eval: ld iy, 0 add iy, sp ld hl, ($D02596) ; tmpcnt push hl - ld hl, .error + ld hl, .L_os_Eval.error call $20798 ; push error handler ld hl, (iy + 3) push hl @@ -63,7 +67,7 @@ _os_Eval: call $20F30 ; stoans call $2079C ; pop error handler xor a, a -.error: + .L_os_Eval.error: pop de push af call $20E80 ; fixtempcnt diff --git a/src/ce/getstringinput.src b/src/ce/getstringinput.src index bf707d2ed..afac0e45c 100644 --- a/src/ce/getstringinput.src +++ b/src/ce/getstringinput.src @@ -1,147 +1,149 @@ - assume adl=1 + .assume adl=1 -kUp := 3 -kLeft := 2 -kDown := 4 -kEnter := 5 -kClear := 9 -kRight := 1 -kQuit := $40 -kIns := $0B -curLock := 4 -flags := $D00080 -keyExtend := $D0058E -curRow := $D00595 ; also includes curCol -curUnder := $D00599 -_PutS := $207C0 -_PutC := $207B8 -_PutPS := $207C8 -_GetKey := $20D8C -_CursorOn := $208B0 -_CursorOff := $208A8 -_PullDownChk := $208BC -_ConvKeyToTok := $20E40 -_GetTokString := $20874 -_PutTokString := $20D74 -_ClrTxtShd := $20818 + .set ti.kUp, 3 + .set ti.kLeft, 2 + .set ti.kDown, 4 + .set ti.kEnter, 5 + .set ti.kClear, 9 + .set ti.kRight, 1 + .set ti.kQuit, 0x40 + .set ti.kIns, 0x0B + .set ti.curLock, 4 + .set ti.flags, 0xD00080 + .set ti.keyExtend, 0xD0058E + .set ti.curRow, 0xD00595 + .set ti.curUnder, 0xD00599 + .set ti.PutS, 0x207C0 + .set ti.PutC, 0x207B8 + .set ti.PutPS, 0x207C8 + .set ti.GetKey, 0x20D8C + .set ti.CursorOn, 0x208B0 + .set ti.CursorOff, 0x208A8 + .set ti.PullDownChk, 0x208BC + .set ti.ConvKeyToTok, 0x20E40 + .set ti.GetTokString, 0x20874 + .set ti.PutTokString, 0x20D74 + .set ti.ClrTxtShd, 0x20818 + + .section .text + .global _os_GetStringInput + .type _os_GetStringInput, @function - section .text - public _os_GetStringInput _os_GetStringInput: call __frameset0 - ld iy,flags - ld l,(iy + $0d) - ld h,(iy + $4c) + ld iy, ti.flags + ld l, (iy + 0x0D) + ld h, (iy + 0x4C) push hl ; save text flags - set 1,(iy + $0d) ; use text buffer - res 5,(iy + $4c) ; use text buffer - call _ClrTxtShd - ld hl,(ix+6) ; hl -> input string prompt - add hl,de - xor a,a - sbc hl,de - call nz,_PutS - ld hl,(curRow) -.start: + set 1, (iy + 0x0D) ; use text buffer + res 5, (iy + 0x4C) ; use text buffer + call ti.ClrTxtShd + ld hl, (ix + 6) ; hl -> input string prompt + add hl, de + xor a, a + sbc hl, de + call nz, ti.PutS + ld hl, (ti.curRow) +.L.start: push hl ; save initial row/column - ld hl,(ix+12) ; buffer size - add hl,de - xor a,a - sbc hl,de + ld hl, (ix + 12) ; buffer size + add hl, de + xor a, a + sbc hl, de push ix push hl ; save remaining size - jr z,.empty - ld de,(ix+9) -.loop_save: + jr z, .L.empty + ld de, (ix+9) +.L.loop_save: push de ; save buf pointer -.loop: - call _CursorOn -.getkey: - call _GetKey - call _CursorOff - call _PullDownChk +.L.loop: + call ti.CursorOn +.L.getkey: + call ti.GetKey + call ti.CursorOff + call ti.PullDownChk push af - call _CursorOn + call ti.CursorOn pop af - jr c,.getkey - cp a,kQuit - jr z,.done + jr c, .L.getkey + cp a, ti.kQuit + jr z, .L.done dec a ; kRight=1 - cp a,kEnter-kRight ; kEnter=kDown+1 - jr c,.loop - jr z,.done + cp a, ti.kEnter - ti.kRight ; kEnter=kDown+1 + jr c, .L.loop + jr z, .L.done inc a - cp a,kIns - jr z,.loop - cp a,kClear - jr z,.clear - cp a,$F3 ; for lists? idk something is wrong with _PullDownChk - jr c,.conv_key - cp a,$FB+1 - jr nc,.conv_key - sub a,$7C - ld (keyExtend),a - ld a,$FE -.conv_key: - call _ConvKeyToTok - call _GetTokString + cp a, ti.kIns + jr z, .L.loop + cp a, ti.kClear + jr z, .L.clear + cp a, 0xF3 ; for lists? idk something is wrong with _PullDownChk + jr c, .L.conv_key + cp a, 0xFB+1 + jr nc, .L.conv_key + sub a, 0x7C + ld (ti.keyExtend), a + ld a, 0xFE +.L.conv_key: + call ti.ConvKeyToTok + call ti.GetTokString pop de ; restore buf pointer - ld b,(hl) ; token string length -.draw_string: - ex (sp),hl ; remaining size - add hl,de + ld b, (hl) ; token string length +.L.draw_string: + ex (sp), hl ; remaining size + add hl, de scf - sbc hl,de ; decrement and check if done - ex (sp),hl - jr z,.full + sbc hl, de ; decrement and check if done + ex (sp), hl + jr z, .L.full inc hl - ld a,(hl) - ld (de),a + ld a, (hl) + ld (de), a inc de - call _PutC - djnz .draw_string - jr .loop_save + call ti.PutC + djnz .L.draw_string + jr .L.loop_save -.done: +.L.done: pop hl ; restore buf pointer - ld (hl),0 -.empty: + ld (hl), 0 +.L.empty: pop hl ; remaining size pop hl ; saved IX pop hl ; initial row/column - call _ClrTxtShd - call _CursorOff + call ti.ClrTxtShd + call ti.CursorOff pop hl ; restore text flags - ld (iy + $0d),l - ld (iy + $4c),h + ld (iy + 0x0D), l + ld (iy + 0x4C), h pop ix ret -.full: +.L.full: push de ; save buf pointer -.full_loop: - call _GetKey - cp a,kEnter - jr z,.done - cp a,kClear - jr nz,.full_loop -.clear: +.L.full_loop: + call ti.GetKey + cp a, ti.kEnter + jr z, .L.done + cp a, ti.kClear + jr nz, .L.full_loop +.L.clear: pop hl ; restore buf pointer inc hl pop de ; remaining size pop ix pop de ; initial row/column - ld (curRow),de -.clear_loop: - ld a,' ' - call _PutC - ld bc,(ix+9) + ld (ti.curRow), de +.L.clear_loop: + ld a, ' ' + call ti.PutC + ld bc, (ix + 9) scf - sbc hl,bc ; decrement and compare to buf start - add hl,bc - jr nz,.clear_loop + sbc hl, bc ; decrement and compare to buf start + add hl, bc + jr nz, .L.clear_loop ex de,hl - ld (curRow),hl - jp .start + ld (ti.curRow), hl + jp .L.start extern __frameset0 diff --git a/src/ce/gettokeninput.src b/src/ce/gettokeninput.src index 0f9933cfa..b87d3e0a2 100644 --- a/src/ce/gettokeninput.src +++ b/src/ce/gettokeninput.src @@ -1,147 +1,149 @@ - assume adl=1 + .assume adl=1 -kUp := 3 -kLeft := 2 -kDown := 4 -kEnter := 5 -kClear := 9 -kRight := 1 -kQuit := $40 -kIns := $0B -curLock := 4 -flags := $D00080 -keyExtend := $D0058E -curRow := $D00595 ; also includes curCol -curUnder := $D00599 -_PutS := $207C0 -_PutC := $207B8 -_PutPS := $207C8 -_GetKey := $20D8C -_CursorOn := $208B0 -_CursorOff := $208A8 -_PullDownChk := $208BC -_ConvKeyToTok := $20E40 -_GetTokString := $20874 -_PutTokString := $20D74 -_ClrTxtShd := $20818 + .set ti.kUp, 3 + .set ti.kLeft, 2 + .set ti.kDown, 4 + .set ti.kEnter, 5 + .set ti.kClear, 9 + .set ti.kRight, 1 + .set ti.kQuit, 0x40 + .set ti.kIns, 0x0B + .set ti.curLock, 4 + .set ti.flags, 0xD00080 + .set ti.keyExtend, 0xD0058E + .set ti.curRow, 0xD00595 + .set ti.curUnder, 0xD00599 + .set ti.PutS, 0x207C0 + .set ti.PutC, 0x207B8 + .set ti.PutPS, 0x207C8 + .set ti.GetKey, 0x20D8C + .set ti.CursorOn, 0x208B0 + .set ti.CursorOff, 0x208A8 + .set ti.PullDownChk, 0x208BC + .set ti.ConvKeyToTok, 0x20E40 + .set ti.GetTokString, 0x20874 + .set ti.PutTokString, 0x20D74 + .set ti.ClrTxtShd, 0x20818 + + .section .text + .global _os_GetTokenInput + .type _os_GetTokenInput, @function - section .text - public _os_GetTokenInput _os_GetTokenInput: call __frameset0 - ld iy,flags - ld l,(iy + $0d) - ld h,(iy + $4c) + ld iy, flags + ld l, (iy + $0D) + ld h, (iy + $4C) push hl ; save text flags - set 1,(iy + $0d) ; use text buffer - res 5,(iy + $4c) ; use text buffer - call _ClrTxtShd - ld hl,(ix+6) ; hl -> input string prompt - add hl,de - xor a,a - sbc hl,de - call nz,_PutS - ld hl,(curRow) -.start: + set 1, (iy + $0D) ; use text buffer + res 5, (iy + $4C) ; use text buffer + call ti.ClrTxtShd + ld hl, (ix + 6) ; hl -> input string prompt + add hl, de + xor a, a + sbc hl, de + call nz, ti.PutS + ld hl, (ti.curRow) +.L.start: push hl ; save initial row/column push ix ; save frame pointer - ld hl,(ix+9) + ld hl, (ix + 9) push hl ; save buf start pointer push hl ; save buf pointer - ld hl,(ix+12) ; buffer size + ld hl, (ix + 12) ; buffer size push hl ; save remaining size -.loop: - call _CursorOn -.getkey: - call _GetKey - call _CursorOff - call _PullDownChk +.L.loop: + call ti.CursorOn +.L.getkey: + call ti.GetKey + call ti.CursorOff + call ti.PullDownChk push af - call _CursorOn + call ti.CursorOn pop af - jr c,.getkey - cp a,kQuit - jr z,.done + jr c, .L.getkey + cp a, ti.kQuit + jr z, .L.done dec a ; kRight=1 - cp a,kEnter-kRight ; kEnter=kDown+1 - jr c,.loop - jr z,.done + cp a, ti.kEnter-ti.kRight ; kEnter=kDown+1 + jr c, .L.loop + jr z, .L.done inc a - cp a,kIns - jr z,.loop - cp a,kClear - jr z,.clear - cp a,$F3 ; for lists? idk something is wrong with _PullDownChk - jr c,.conv_key - cp a,$FB+1 - jr nc,.conv_key - sub a,$7C - ld (keyExtend),a - ld a,$FE -.conv_key: - call _ConvKeyToTok + cp a, ti.kIns + jr z, .L.loop + cp a, ti.kClear + jr z, .L.clear + cp a, $F3 ; for lists? idk something is wrong with _PullDownChk + jr c, .L.conv_key + cp a, $FB+1 + jr nc, .L.conv_key + sub a, $7C + ld (ti.keyExtend), a + ld a, $FE +.L.conv_key: + call ti.ConvKeyToTok pop bc ; restore remaining size - xor a,a - cp a,d ; check if 2-byte token - sbc hl,hl ; sets Z if 1-byte token + xor a, a + cp a, d ; check if 2-byte token + sbc hl, hl ; sets Z if 1-byte token dec hl - add hl,bc ; subtract 1 or 2 from remaining size - jr nc,.full - ex (sp),hl ; restore buf pointer - jr z,.one_byte_token - ld (hl),d + add hl, bc ; subtract 1 or 2 from remaining size + jr nc, .L.full + ex (sp), hl ; restore buf pointer + jr z, .L.one_byte_token + ld (hl), d inc hl -.one_byte_token: - ld (hl),e +.L.one_byte_token: + ld (hl), e inc hl - ex (sp),hl ; save buf pointer + ex (sp), hl ; save buf pointer push hl ; save remaining size - call _GetTokString - call _PutPS - jr .loop + call ti.GetTokString + call ti.PutPS + jr .L.loop -.done: +.L.done: pop de ; remaining size -.done_full: - call _ClrTxtShd - call _CursorOff +.L.done_full: + call ti.ClrTxtShd + call ti.CursorOff pop hl ; restore buf pointer pop de ; restore buf start pointer - or a,a - sbc hl,de + or a, a + sbc hl, de pop de ; frame pointer pop de ; initial row/column pop de ; restore text flags - ld (iy + $0d),e - ld (iy + $4c),d + ld (iy + $0D), e + ld (iy + $4C), d pop ix ret -.full: - call _GetKey - cp a,kEnter - jr z,.done_full - cp a,kClear - jr nz,.full -.clear: +.L.full: + call ti.GetKey + cp a, ti.kEnter + jr z, .L.done_full + cp a, ti.kClear + jr nz, .L.full +.L.clear: pop hl ; buf pointer pop hl ; buf start pointer pop ix ; restore frame pointer pop de ; restore initial row/column - ld hl,curRow - ld bc,(hl) - ld (hl),de -.clear_loop: + ld hl, ti.curRow + ld bc, (hl) + ld (hl), de +.L.clear_loop: push hl - ld hl,(hl) - ld a,' ' - call _PutC - or a,a - sbc hl,bc ; check the row/column before the print + ld hl, (hl) + ld a, ' ' + call ti.PutC + or a, a + sbc hl, bc ; check the row/column before the print pop hl - jr nz,.clear_loop - ld (hl),de - ex de,hl - jp .start + jr nz, .L.clear_loop + ld (hl), de + ex de, hl + jp .L.start extern __frameset0 diff --git a/src/ce/include/ti/vars.h b/src/ce/include/ti/vars.h index c5582191d..a9055239a 100644 --- a/src/ce/include/ti/vars.h +++ b/src/ce/include/ti/vars.h @@ -221,6 +221,9 @@ extern "C" { #define OS_VAR_L6 "\x5D\x5\0" /* @endcond */ +#define OS_RUN_PRGM_NOT_FOUND -1 +#define OS_RUN_PRGM_ERR_MEMORY -2 + /** * @brief Structure of list variable type */ @@ -514,9 +517,9 @@ typedef int (*os_runprgm_callback_t)(void *data, int retval); * argument may be left \c NULL if execution should not return to the calling * program. * - * @return This function should not return, but if it does, -1 indicates the - * program could not be found, -2 if not enough memory, and < 0 if some other - * error occurred. + * @return This function should not return, but if it does, a value < 0 is + * returned. \c OS_RUN_PRGM_NOT_FOUND (-1) indicates the program could not be + * found, and \c OS_RUN_PRGM_ERR_MEM (-2) if not enough memory. * * @note The integer return of the callback acts the same as the integer return * of the \p main function, and is returned to the parent caller (either the OS diff --git a/src/ce/intce.src b/src/ce/intce.src index 8a284d30b..89a2bd282 100644 --- a/src/ce/intce.src +++ b/src/ce/intce.src @@ -1,147 +1,158 @@ - assume adl=1 + .assume adl=1 -mpIntStatus := $F00000 -mpIntMask := $F00004 -mpIntAck := $F00008 -mpIntLachEnable := $F0000C -mpIntXor := $F00010 -mpIntStatusMasked := $F00014 + .set ti.mpIntStatus, $F00000 + .set ti.mpIntMask, $F00004 + .set ti.mpIntAck, $F00008 + .set ti.mpIntLachEnable, $F0000C + .set ti.mpIntXor, $F00010 + .set ti.mpIntStatusMasked, $F00014 -intOnKey := 1 -intTimer1 := 2 -intTimer2 := 4 -intTimer3 := 8 -intOsTimer := $10 -intKbd := $400 -intLcd := $800 -intRtc := $1000 + .set ti.intOnKey, 1 + .set ti.intTimer1, 2 + .set ti.intTimer2, 4 + .set ti.intTimer3, 8 + .set ti.intOsTimer, $10 + .set ti.intKbd, $400 + .set ti.intLcd, $800 + .set ti.intRtc, $1000 ;------------------------------------------------------------------------------- - section .text - public _int_Initialize + .section .text._int_Initialize + .global _int_Initialize + .type _int_Initialize, @function + _int_Initialize: di - ld de,_lconf - ld hl,mpIntMask - ld bc,16 + ld de, _int_lconf + ld hl, ti.mpIntMask + ld bc, 16 ldir - ld hl,_cconf - ld de,mpIntMask - ld bc,16 + ld hl, _int_cconf + ld de, ti.mpIntMask + ld bc, 16 ldir - ld hl,$D18879 - ld de,$C90611 - ld (hl),de + ld hl, $D18879 + ld de, $C90611 + ld (hl), de dec hl - ld (hl),$ED + ld (hl), $ED push hl inc d call $D18878 - ld hl,$E10010 or ((_int_Handler shr 8) and $00FF00) - ld de,$C3 or ((_int_Handler shl 8) and $FFFF00) - ld (hl),h + ; todo: figure out how to do this properly + ;ld hl,$E10010 | ((_int_Handler >> 8) & $00FF00) + ;ld de,$C3 | ((_int_Handler << 8) & $FFFF00) + ld (hl), h inc hl - ld (hl),de - ld hl,$E30800 - ld bc,$401 - ld a,$E1 + ld (hl), de + ld hl, $E30800 + ld bc, $401 + ld a, $E1 call $0210E0 ; _Memset - ld hl,$E308 - ld i,hl + ld hl, $E308 + ld i, hl im 2 - ld d,3 + ld d, 3 ret ;------------------------------------------------------------------------------- - section .text - public _int_Handler + .section .text._int_Handler + .global _int_Handler + .type _int_Handler, @function + _int_Handler: - ex af,af' + ex af, af' exx - ld hl,(mpIntStatusMasked) - add hl,hl + ld hl, (ti.mpIntStatusMasked) + add hl, hl inc hl - add hl,hl - xor a,a -isr_loop: + add hl, hl + xor a, a +.L.isr_loop: inc a - add hl,hl - jr nc,isr_loop -identified: + add hl, hl + jr nc, .L.isr_loop +.L.identified: dec a - add a,a - add a,a - ld (isr_dispatch_smc + 1),a + add a, a + add a, a + ld (.L.isr_dispatch_smc + 1), a exx ex af, af' -isr_dispatch_smc: - jr $+2 -iv_list: - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt - jp unhandledInt -unhandledInt: +.L.isr_dispatch_smc: + jr $ + 2 +_int_Handler.iv_list: + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int + jp .L.unhandled_int +.L.unhandled_int: ei ret ;------------------------------------------------------------------------------- - section .text - public _int_SetVector + .section .text._int_SetVector + .global _int_SetVector + .type _int_SetVector, @function + _int_SetVector: - ld iy,0 - add iy,sp - ld a,21 - ld l,(iy + 3) - sub a,l - ld l,a - ld h,4 + ld iy, 0 + add iy, sp + ld a, 21 + ld l, (iy + 3) + sub a, l + ld l, a + ld h, 4 mlt hl - ld de,iv_list + 1 - add hl,de - ld de,(iy + 6) - ld (hl),de + ld de, _int_Handler.iv_list + 1 + add hl, de + ld de, (iy + 6) + ld (hl), de ret ;------------------------------------------------------------------------------- - section .text - public _int_Reset + .section .text._int_Reset + .global _int_Reset + .type _int_Reset, @function + _int_Reset: di - ld hl,_lconf - ld de,mpIntMask - ld bc,16 + ld hl, _int_lconf + ld de, ti.mpIntMask + ld bc, 16 ldir im 1 ret - section .bss - private _lconf -_lconf: - rb 16 +;------------------------------------------------------------------------------- + .section .bss._int_lconf + .local _int_lconf +_int_lconf: + .ds 16 - section .data - private _cconf -_cconf: - db $00,$00,$00,$00 ; mask - db $ff,$ff,$ff,$ff ; ack - db $00,$00,$00,$00 ; latch - db $00,$00,$00,$00 ; invert +;------------------------------------------------------------------------------- + .section .data._int_cconf + .local _int_cconf +_int_cconf: + .db $00,$00,$00,$00 ; mask + .db $ff,$ff,$ff,$ff ; ack + .db $00,$00,$00,$00 ; latch + .db $00,$00,$00,$00 ; invert diff --git a/src/ce/makefile b/src/ce/makefile index b22c5ba71..983ab1fec 100644 --- a/src/ce/makefile +++ b/src/ce/makefile @@ -16,6 +16,12 @@ include $(CURDIR)/../common.mk + +OBJECTS = +OBJECTS += $(patsubst %.c,build/%.c.o,$(wildcard *.c)) +OBJECTS += $(patsubst %.cpp,build/%.cpp.o,$(wildcard *.cpp)) +OBJECTS += $(patsubst %.src,build/%.o,$(wildcard *.src)) + WILDCARD_SRC = $(wildcard *.src) WILDCARD_H = $(wildcard include/*.h) WILDCARD_HW_H = $(wildcard include/sys/*.h) @@ -24,7 +30,204 @@ WILDCARD_TI_H = $(wildcard include/ti/*.h) WILDCARD_CXX_H = $(wildcard include/c++/*) WILDCARD_CXX_TI_H = $(wildcard include/ti/c++/*) -all: +LIB_CE = build/libce.a + +# independent object symbols to allow garbage collection +BOOT_SYMBOLS := \ + _boot_GetBootMajorVer@0x000080 \ + _boot_GetHardwareVer@0x000084 \ + _boot_GetBootMinorVer@0x00008C \ + _boot_DebugPrintf@0x0000B4 \ + _boot_ClearVRAM@0x000374 \ + _boot_TurnOn@0x000384 \ + _boot_TurnOff@0x000388 \ + _boot_NewLine@0x000390 \ + _boot_Set6MHzMode@0x00039C \ + _boot_Set48MHzMode@0x0003A0 \ + _boot_Set6MHzModeI@0x0003A4 \ + _boot_Set48MHzModeI@0x0003A8 \ + _boot_GetBatteryStatus@0x0003B0 \ + _boot_WaitShort@0x0003B4 \ + _boot_BatteryCharging@0x0003CC \ + _boot_USBBusPowered@0x0003E4 \ + _boot_USBSelfPowered@0x0003E8 \ + _boot_USBResetChip@0x0003F4 \ + _boot_USBResetTimers@0x0004F0 \ + _boot_USBDisableTimers@0x0004F4 \ + _boot_USBEnableTimers@0x0004F8 \ + _boot_CheckOnPressed@0x00057C \ + _boot_SetDate@0x000598 \ + _boot_GetDate@0x0005A8 \ + _boot_GetTime@0x0005B0 \ + _boot_SetTime@0x0005B4 \ + _boot_IsAfterNoon@0x0005C8 \ + _boot_sprintf@0x0000BC \ + _os_NewLine@0x0207F0 \ + _os_MoveDown@0x0207F4 \ + _os_MoveUp@0x020800 \ + _os_ClrLCDFull@0x020808 \ + _os_ClrLCD@0x02080C \ + _os_ClrTxtShd@0x020818 \ + _os_HomeUp@0x020828 \ + _os_RunIndicOn@0x020844 \ + _os_RunIndicOff@0x020848 \ + _os_DelRes@0x020E5C \ + _os_DisableAPD@0x021134 \ + _os_EnableAPD@0x021138 \ + _os_DrawStatusBar@0x021A3C \ + _os_PushErrorHandler@0x021C78 \ + _os_PopErrorHandler@0x021C7C \ + _os_ThrowError@0x021C80 \ + _os_RealCopy@0x021C84 \ + _os_RealAcosRad@0x021C88 \ + _os_RealAsinRad@0x021C8C \ + _os_RealAtanRad@0x021C90 \ + _os_RealAdd@0x021C94 \ + _os_CplxSquare@0x021C98 \ + _os_RealCompare@0x021C9C \ + _os_RealCosRad@0x021CA0 \ + _os_RealRadToDeg@0x021CA4 \ + _os_RealDiv@0x021CA8 \ + _os_RealExp@0x021CAC \ + _os_RealFloor@0x021CB0 \ + _os_RealToStr@0x021CB4 \ + _os_RealFrac@0x021CB8 \ + _os_RealGcd@0x021CBC \ + _os_RealRoundInt@0x021CC0 \ + _os_RealLcm@0x021CC4 \ + _os_RealLog@0x021CC8 \ + _os_RealMax@0x021CCC \ + _os_RealMin@0x021CD0 \ + _os_RealMul@0x021CD4 \ + _os_RealNcr@0x021CD8 \ + _os_RealNeg@0x021CDC \ + _os_RealNpr@0x021CE0 \ + _os_RealPow@0x021CE4 \ + _os_RealDegToRad@0x021CE8 \ + _os_RealRandInt@0x021CEC \ + _os_RealInv@0x021CF0 \ + _os_RealMod@0x021CF4 \ + _os_RealRound@0x021CF8 \ + _os_RealSinRad@0x021CFC \ + _os_RealSqrt@0x021D00 \ + _os_RealSub@0x021D04 \ + _os_RealTanRad@0x021D08 \ + _os_StrToReal@0x021D0C \ + _os_RealInt@0x021D10 \ + _os_SetFlagBits@0x021D14 \ + _os_ResetFlagBits@0x021D18 \ + _os_TestFlagBits@0x021D1C \ + _os_SetFlagByte@0x021D20 \ + _os_GetFlagByte@0x021D24 \ + _os_GetCursorPos@0x021D28 \ + _os_PutStrFull@0x021D2C \ + _os_PutStrLine@0x021D30 \ + _os_SetCursorPos@0x021D34 \ + _os_GetKey@0x021D38 \ + _os_GetCSC@0x021D3C \ + _os_AppInit@0x021D40 \ + _os_DisableCursor@0x021DE4 \ + _os_EnableCursor@0x021DE8 \ + _os_FontDrawText@0x021E00 \ + _os_FontGetHeight@0x021E14 \ + _os_FontGetWidth@0x021E18 \ + _os_InitDrawing@0x021E1C \ + _os_SetDrawBGColor@0x021E20 \ + _os_SetDrawFGColor@0x021E24 \ + _os_FontSelect@0x021E28 \ + _os_GetAnsData@0x021E70 \ + _os_SetTimer1@0x021EC8 \ + _os_DisableTimer1@0x021ECC \ + _os_GetSystemInfo@0x021ED4 \ + _os_GetDrawBGColor@0x021EE4 \ + _os_GetDrawFGColor@0x021EE8 \ + _os_FontGetID@0x021EEC \ + _os_RealToInt24@0x021EF4 \ + _os_Int24ToReal@0x021EF8 \ + _os_ForceCmdNoChar@0x021FA8 \ + _os_DelSymEntry@0x021FAC \ + _os_GetSymTablePtr@0x021FB0 \ + _os_NextSymEntry@0x021FB4 \ + _os_ChkFindSym@0x021FB8 \ + _os_GetVarSize@0x021FBC \ + _os_GetMatrixDims@0x021FC0 \ + _os_GetRealListElement@0x021FC4 \ + _os_GetMatrixElement@0x021FC8 \ + _os_GetRealVar@0x021FCC \ + _os_SetListDim@0x021FD0 \ + _os_SetMatrixDims@0x021FD4 \ + _os_SetRealListElement@0x021FD8 \ + _os_SetMatrixElement@0x021FDC \ + _os_SetRealVar@0x021FE0 \ + _os_MemChk@0x021FF0 \ + _os_ArcChk@0x022040 \ + _os_SetTimer2@0x022080 \ + _os_DisableTimer2@0x022084 \ + _os_FloatToReal@0x022170 \ + _os_RealToFloat@0x022174 \ + _os_FontDrawTransText@0x022178 \ + _os_DelAppVar@0x02217C \ + _os_GetAppVarData@0x022180 \ + _os_CreateAppVar@0x022184 \ + _os_CreateString@0x022198 \ + _os_GetStringData@0x02219C \ + _os_CreateEquation@0x022240 \ + _os_GetEquationData@0x022244 \ + _os_MSDGetMaxLUN@0x022280 \ + _os_MSDReset@0x022284 \ + _os_MSDInquiry@0x022288 \ + _os_MSDTestUnitReady@0x02228C \ + _os_MSDReadCapacity@0x022290 \ + _os_MSDRead@0x022294 \ + _os_MSDWrite@0x022298 \ + _os_USBGetRequestStatus@0x0222D0 \ + _os_TestFlagBitsFast@0x0222FC + +define MAKE_BOOT_SYMBOL +build/$(word 1,$(subst @, ,$(1))).s: + $(Q)$$(call MKDIR,build) + $(Q)echo .assume adl=1 > $$@ + $(Q)echo .section .text >> $$@ + $(Q)echo .global $(word 1,$(subst @, ,$(1))) >> $$@ + $(Q)echo .type $(word 1,$(subst @, ,$(1))), @function >> $$@ + $(Q)echo .set $(word 1,$(subst @, ,$(1))), $(word 2,$(subst @, ,$(1))) >> $$@ + +build/$(word 1,$(subst @, ,$(1))).o: build/$(word 1,$(subst @, ,$(1))).s + $(Q)$(EZAS) $(EZASFLAGS) -o $$@ $$< +endef + +BOOT_OBJS := $(addprefix build/,$(addsuffix .o,$(foreach sym,$(BOOT_SYMBOLS),$(word 1,$(subst @, ,$(sym)))))) + +.SECONDARY: + +all: $(LIB_CE) + +$(LIB_CE): $(OBJECTS) $(BOOT_OBJS) + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ + +$(foreach sym,$(BOOT_SYMBOLS),\ + $(eval $(call MAKE_BOOT_SYMBOL,$(sym)))) + +build/%.c.src: %.c + $(Q)$(call MKDIR,build) + $(Q)$(EZCC) $(EZCFLAGS) $< -o $@ + +build/%.cpp.src: %.cpp + $(Q)$(call MKDIR,build) + $(Q)$(EZCC) $(EZCXXFLAGS) $< -o $@ + +build/%.c.o: build/%.c.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.cpp.o: build/%.cpp.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.o: %.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ install: $(addprefix install-,$(TARGETS)) $(Q)$(call MKDIR,$(INSTALL_H)) @@ -38,7 +241,7 @@ install: $(addprefix install-,$(TARGETS)) $(Q)$(call COPY,$(foreach file,$(call NATIVEPATH,$(WILDCARD_TI_H)),$(call QUOTE_ARG,$(file))),$(INSTALL_TI_H)) $(Q)$(call COPY,$(foreach file,$(call NATIVEPATH,$(WILDCARD_CXX_H)),$(call QUOTE_ARG,$(file))),$(INSTALL_CXX_H)) $(Q)$(call COPY,$(foreach file,$(call NATIVEPATH,$(WILDCARD_CXX_TI_H)),$(call QUOTE_ARG,$(file))),$(INSTALL_CXX_TI_H)) - $(Q)$(call COPY,$(WILDCARD_SRC),$(INSTALL_CE)) + $(Q)$(call COPY,$(call NATIVEPATH,$(LIB_CE)),$(INSTALL_CE)) clean: $(Q)$(call RMDIR,build) diff --git a/src/ce/os_textbuffer.src b/src/ce/os_textbuffer.src index e78820b27..e51d86cb1 100644 --- a/src/ce/os_textbuffer.src +++ b/src/ce/os_textbuffer.src @@ -1,10 +1,12 @@ ; --- ; enables / disables homescreen text buffering which can destroy bss / heap ; --- - assume adl=1 + .assume adl=1 + + .section .text._os_DisableHomeTextBuffer + .global _os_DisableHomeTextBuffer + .type _os_DisableHomeTextBuffer, @function - section .text - public _os_DisableHomeTextBuffer _os_DisableHomeTextBuffer: ld iy,$d00080 res 1,(iy + $0d) ; no text buffer @@ -12,12 +14,13 @@ _os_DisableHomeTextBuffer: set 5,(iy + $4c) ; only display ret - section .text - public _os_EnableHomeTextBuffer + .section .text._os_EnableHomeTextBuffer + .global _os_EnableHomeTextBuffer + .type _os_EnableHomeTextBuffer, @function + _os_EnableHomeTextBuffer: ld iy,$d00080 set 1,(iy + $0d) ; use text buffer res 3,(iy + $4a) ; use first shadow buffer res 5,(iy + $4c) ; use shadow buffer ret - diff --git a/src/ce/random.src b/src/ce/random.src index 89a7c6739..ca4a7142a 100644 --- a/src/ce/random.src +++ b/src/ce/random.src @@ -1,7 +1,4 @@ -; --- -; uint32_t random(void) -; --- - assume adl=1 + .assume adl=1 ; https://github.com/MersenneTwister-Lab/XSadd/blob/master/xsadd.h#L75 ; using shift parameters (19, 21, 8) instead of (15, 18, 11) @@ -23,8 +20,11 @@ ; return result; ; } - section .text - public _random + .section .text._random + .global _random + .type _random, @function + +; uint32_t random(void) _random: ; Read state[0] and perform state shifting. ld iy,__state ; iy = &state[0] @@ -107,10 +107,10 @@ _random: ; void srandom(uint32_t seed) ; --- -_MemClear := 00210E0h + .section .text._srandom + .global _srandom + .type _srandom, @function - section .text - public _srandom _srandom: pop bc pop de @@ -119,19 +119,21 @@ _srandom: push bc ex de,hl ld a,e ; auhl = seed - public __setstate + .global __setstate + .type __setstate, @function + __setstate: ld (__state),hl ld hl,__state+3 ld (hl),a ld b,12 -__setstateloop: +.L.loop: inc hl ld (hl),b - djnz __setstateloop + djnz .L.loop ret - section .data - private __state + .section .data + .local __state __state: - dd 0d0e0f10h,090a0b0ch,05060708h,01020304h + .d32 0d0e0f10h,090a0b0ch,05060708h,01020304h diff --git a/src/ce/runprgm.src b/src/ce/runprgm.src index 7df307830..f5d54979a 100644 --- a/src/ce/runprgm.src +++ b/src/ce/runprgm.src @@ -1,210 +1,206 @@ - assume adl=1 + .assume adl=1 -define ti? ti -namespace ti? -?Mov9b := 00202FCh -?Mov8b := 0020304h -?Mov9ToOP1 := 0020320h -?MovFROP1 := 002032Ch -?MemChk := 00204FCh -?ChkFindSym := 002050Ch -?InsertMem := 0020514h -?EnoughMem := 002051Ch -?DelMem := 0020590h -?PopRealO1 := 00205DCh -?ErrNotEnoughMem := 002072Ch -?ErrMemory := 0020768h -?JError := 0020790h -?PushErrorHandler := 0020798h -?PopErrorHandler := 002079Ch -?ParseInp := 0020F00h -?GetParse := 0020F0Ch -?SaveParse := 0020F10h -?DisableAPD := 0021134h -?SetParserHook := 002149Ch -?ClrParserHook := 00214A0h -?DeleteTempPrograms := 00214C0h -?ForceFullScreen := 0021528h -?LoadDEInd_s := 0021D9Ch -?ChkInRam := 0021F98h -?flags := 0D00080h -?tempSP := 0D0053Fh -?kbdGetKy := 0D0058Dh -?OP1 := 0D005F8h -?errNo := 0D008DFh -?appErr2 := 0D025B6h -?parserHookPtr := 0D025F9h -?pixelShadow := 0D031F6h -?asm_prgm_size := 0D0118Ch -?userMem := 0D1A881h -?cursorImage := 0E30800h -?tExtTok := 0EFh -?ProgObj := 005h -?tAsm84CeCmp := 07Bh -?tAsm84CePrgm := 07Ah + .set ti.Mov9b , 0x0202FC + .set ti.Mov8b , 0x020304 + .set ti.Mov9ToOP1 , 0x020320 + .set ti.MovFROP1 , 0x02032C + .set ti.MemChk , 0x0204FC + .set ti.ChkFindSym , 0x02050C + .set ti.InsertMem , 0x020514 + .set ti.EnoughMem , 0x02051C + .set ti.DelMem , 0x020590 + .set ti.PopRealO1 , 0x0205DC + .set ti.ErrNotEnoughMem , 0x02072C + .set ti.ErrMemory , 0x020768 + .set ti.JError , 0x020790 + .set ti.PushErrorHandler , 0x020798 + .set ti.PopErrorHandler , 0x02079C + .set ti.ParseInp , 0x020F00 + .set ti.GetParse , 0x020F0C + .set ti.SaveParse , 0x020F10 + .set ti.DisableAPD , 0x021134 + .set ti.SetParserHook , 0x02149C + .set ti.ClrParserHook , 0x0214A0 + .set ti.DeleteTempPrograms , 0x0214C0 + .set ti.ForceFullScreen , 0x021528 + .set ti.LoadDEInd_s , 0x021D9C + .set ti.ChkInRam , 0x021F98 + .set ti.flags , 0xD00080 + .set ti.tempSP , 0xD0053F + .set ti.kbdGetKy , 0xD0058D + .set ti.OP1 , 0xD005F8 + .set ti.errNo , 0xD008DF + .set ti.appErr2 , 0xD025B6 + .set ti.parserHookPtr , 0xD025F9 + .set ti.pixelShadow , 0xD031F6 + .set ti.asm_prgm_size , 0xD0118C + .set ti.userMem , 0xD1A881 + .set ti.cursorImage , 0xE30800 + .set ti.tExtTok , 0xEF + .set ti.ProgObj , 0x05 + .set ti.tAsm84CeCmp , 0x7B + .set ti.tAsm84CePrgm , 0x7A + .set ti.hookflags4 , 0x36 + .set ti.parserHookActive , 0x1 + .set ti.ParsFlag2 , 0x7 + .set ti.numOP1 , 0x0 + .set ti.newDispF , 0x8 + .set ti.allowProgTokens , 0x1 + .set ti.progExecuting , 0x1 + .set ti.cmdFlags , 0xC + .set ti.cmdExec , 0x6 + .set ti.onFlags , 0x9 + .set ti.onInterrupt , 0x4 + .set ti.textFlags , 0x5 + .set ti.textEraseBelow , 0x1 + .set ti.textScrolled , 0x2 + .set ti.textInverse , 0x3 -?hookflags4 := 36h -?parserHookActive := 1 + .section .text._os_RunPrgm + .global _os_RunPrgm + .type _os_RunPrgm, @function -?ParsFlag2 := 7h -?numOP1 := 0 -?newDispF := 08h -?allowProgTokens := 1 -?progExecuting := 1 -?cmdFlags := 0Ch -?cmdExec := 6 -?onFlags := 09h -?onInterrupt := 4 -?textFlags := 05h -?textEraseBelow := 1 -?textScrolled := 2 -?textInverse := 3 -end namespace - - section .text - public _os_RunPrgm _os_RunPrgm: - require ___prgm_run_check - ld iy,ti.flags + ld hl, ___runprgm_reloc_start + ld de, ti.cursorImage + ld bc, ___runprgm_reloc_len + ldir + ld iy, ti.flags pop de pop hl push hl push de - ld a,ti.ProgObj - ld de,___prgm_to_run - reloc.offset - ld (de),a + ld a, ti.ProgObj + ld de, ___prgm_to_run + ld (de), a inc de call ti.Mov8b - ld hl,___prgm_caller - ld de,stub.prgm - reloc.offset + ld hl, ___prgm_caller + ld de, stub.prgm call ti.Mov9b - ld hl,___prgm_to_run - reloc.offset - call find_prgm - reloc.offset - jr nc,.found - sbc hl,hl + ld hl, ___prgm_to_run + call find_prgm + jr nc, .L.found_prgm + sbc hl, hl ret -.found: - ld a,(ti.OP1) - ld (___prgm_to_run - reloc.offset),a - ld (___prgm_to_run_size - reloc.offset),de - ld a,(hl) - cp a,ti.tExtTok - jr nz,run_basic_prgm +.L.found_prgm: + ld a, (ti.OP1) + ld (___prgm_to_run), a + ld (___prgm_to_run_size), de + ld a, (hl) + cp a, ti.tExtTok + jr nz, .L.run_basic_prgm inc hl - ld a,(hl) - cp a,ti.tAsm84CeCmp - jr z,run_asm_prgm - ;jr run_basic_prgm + ld a, (hl) + cp a, ti.tAsm84CeCmp + jr z, .L.run_asm_prgm + ;jr .L.run_basic_prgm -run_basic_prgm: - call push_user_data - ld hl,reloc.data - ld de,ti.cursorImage - ld bc,reloc.data.len - ldir +.L.run_basic_prgm: + call .L.push_user_data jp launch_basic_prgm -run_asm_prgm: +.L.run_asm_prgm: inc hl - ld a,(hl) ; if 0, indicates a C program with retval - sbc hl,hl - or a,a - jr nz,.not_c - ld (stub.basic_c_smc - reloc.offset),hl -.not_c: - ld l,64 - add hl,de - ld de,(ti.asm_prgm_size) - sbc hl,de - jr c,.enough_mem + ld a, (hl) ; if 0, indicates a C program with retval + sbc hl, hl + or a, a + jr nz, .L.not_c + ld (stub.basic_c_smc), hl +.L.not_c: + ld l, 64 + add hl, de + ld de, (ti.asm_prgm_size) + sbc hl, de + jr c, .L.enough_mem call ti.EnoughMem - jr nc,.enough_mem - sbc hl,hl + jr nc, .L.enough_mem + sbc hl, hl dec hl ret -.enough_mem: - call push_user_data - ld hl,reloc.data - ld de,ti.cursorImage - ld bc,reloc.data.len - ldir +.L.enough_mem: + call .L.push_user_data jp launch_asm_prgm -push_user_data: - ld iy,3 ; exit() doesn't unwind stack so "safe" - add iy,sp - ld hl,(iy + 12) ; callback - add hl,de - or a,a - sbc hl,de - ld de,stub.callback - reloc.offset - jr nz,.has_callback +.L.push_user_data: + ld iy, 3 ; exit() doesn't unwind stack so "safe" + add iy, sp + ld hl, (iy + 12) ; callback + add hl, de + or a, a + sbc hl, de + ld de, stub.callback + jr nz, .L.has_callback dec de - ld hl,((-(stub.callback - stub.error + 1)) shl 8) or $18 ; jr stub.error -.has_callback: - ex de,hl - ld (hl),de - ld bc,(iy + 9) - ld (push_stub.data_size - reloc.offset),bc - ld hl,(_exit.sp) - or a,a - sbc hl,bc ; resets carry + ld hl, ((-(stub.callback - stub.error + 1)) << 8) | $18 ; jr stub.error +.L.has_callback: + ex de, hl + ld (hl), de + ld bc, (iy + 9) + ld (push_stub.data_size), bc + ld hl, (_exit.sp) + or a, a + sbc hl, bc ; resets carry push hl pop de dec hl dec hl dec hl - ld (_exit.sp),hl - sbc hl,hl - adc hl,bc ; resets carry - ld hl,(iy + 6) + ld (_exit.sp), hl + sbc hl, hl + adc hl, bc ; resets carry + ld hl, (iy + 6) pop iy di ; disable to prevent modifying moved stack data - jr z,.done_move - sbc hl,de - jr c,.lddr - add hl,de + jr z, .L.done_move + sbc hl, de + jr c, .L.lddr + add hl, de ldir - jr .done_move -.lddr: - ex de,hl - add hl,bc + jr .L.done_move +.L.lddr: + ex de, hl + add hl, bc dec hl - ex de,hl - add hl,de + ex de, hl + add hl, de lddr -.done_move: - ld hl,(_exit.sp) - ld (hl),iy ; fake return - ld iy,ti.flags - or a,a - sbc hl,hl - jq ___exithl ; should return to caller +.L.done_move: + ld hl, (_exit.sp) + ld (hl), iy ; fake return + ld iy, ti.flags + or a, a + sbc hl, hl + jp ___exithl ; should return to caller + +; --------------------------------------------------------------- +; relocated functions +; --------------------------------------------------------------- -virtual at ti.cursorImage + .section .runprgm.reloc, "awx", @progbits launch_asm_prgm: call delete_running_prgm call setup_prgm_state call push_stub - ld de,(___prgm_to_run_size) - ld hl,ti.userMem - ex hl,de + ld de, (___prgm_to_run_size) + ld hl, ti.userMem + ex de, hl call ti.InsertMem - ld hl,___prgm_to_run + ld hl, ___prgm_to_run call find_prgm - jr c,.fatal + jr c, .L.fatal inc hl inc hl - ld de,ti.userMem - ld bc,(___prgm_to_run_size) - ld (ti.asm_prgm_size),bc + ld de, ti.userMem + ld bc, (___prgm_to_run_size) + ld (ti.asm_prgm_size), bc ldir - ld hl,___prgm_to_run + ld hl, ___prgm_to_run call ti.Mov9ToOP1 jp ti.userMem -.fatal: - ld de,(___prgm_to_run_size) - ld hl,ti.userMem +.L.fatal: + ld de, (___prgm_to_run_size) + ld hl, ti.userMem call ti.DelMem jp ti.ErrMemory @@ -213,270 +209,256 @@ launch_basic_prgm: call setup_temp_parser_hook call setup_prgm_state call push_stub - ld hl,___prgm_to_run - set ti.allowProgTokens,(iy + ti.newDispF) - set ti.cmdExec,(iy + ti.cmdFlags) + ld hl, ___prgm_to_run + set ti.allowProgTokens, (iy + ti.newDispF) + set ti.cmdExec, (iy + ti.cmdFlags) call ti.Mov9ToOP1 jp ti.ParseInp setup_save_parser_hook: - or a,a - sbc hl,hl - bit ti.parserHookActive,(iy + ti.hookflags4) - jr z,.not_set - ld hl,(ti.parserHookPtr) -.not_set: - ld (stub.prev_hook),hl + or a, a + sbc hl, hl + bit ti.parserHookActive, (iy + ti.hookflags4) + jr z, .L.not_set + ld hl, (ti.parserHookPtr) +.L.not_set: + ld (stub.prev_hook), hl ret setup_prgm_state: call setup_save_parser_hook - xor a,a - ld (ti.kbdGetKy),a - ld a,$ce ; set - bit ti.allowProgTokens,(iy + ti.newDispF) - jr nz,.setAllowProgTokens - res ti.numOP1,(iy + ti.ParsFlag2) - ld a,$8e ; res -.setAllowProgTokens: - ld (stub.flags.newDispF),a - ld a,$f6 ; set - bit ti.cmdExec,(iy + ti.cmdFlags) - jr nz,.setCmdExec - ld a,$b6 ; res -.setCmdExec: - ld (stub.flags.cmdFlags),a + xor a, a + ld (ti.kbdGetKy), a + ld a, 0xCE ; set + bit ti.allowProgTokens, (iy + ti.newDispF) + jr nz, .L.setAllowProgTokens + res ti.numOP1, (iy + ti.ParsFlag2) + ld a, 0x8E ; res +.L.setAllowProgTokens: + ld (stub.flags.newDispF), a + ld a, 0xF6 ; set + bit ti.cmdExec, (iy + ti.cmdFlags) + jr nz, .L.setCmdExec + ld a, 0xB6 ; res +.L.setCmdExec: + ld (stub.flags.cmdFlags), a jp ti.DisableAPD setup_temp_parser_hook: - bit ti.parserHookActive,(iy + ti.hookflags4) - jr nz,.chain_hook -.no_chain: - ld hl,stub.chain - ld (hl),$af ; xor a,a + bit ti.parserHookActive, (iy + ti.hookflags4) + jr nz, .L.chain_hook +.L.no_chain: + ld hl, stub.chain + ld (hl), 0xAF ; xor a,a inc hl - ld (hl),$c9 ; ret + ld (hl), 0xC9 ; ret ret -.chain_hook: - ld hl,(ti.parserHookPtr) - ld a,(hl) - cp a,$83 - jr nz,.no_chain ; ensure the hook is valid - ld (stub.chain + 1),hl - xor a,a - ld (push_stub.skip_parser_hook_jr),a +.L.chain_hook: + ld hl, (ti.parserHookPtr) + ld a, (hl) + cp a, 0x83 + jr nz, .L.no_chain ; ensure the hook is valid + ld (stub.chain + 1), hl + xor a, a + ld (push_stub.skip_parser_hook_jr), a ret delete_running_prgm: - ld iy,ti.flags - ld hl,ti.userMem - ld de,(ti.asm_prgm_size) + ld iy, ti.flags + ld hl, ti.userMem + ld de, (ti.asm_prgm_size) call ti.DelMem - or a,a - sbc hl,hl - ld (ti.asm_prgm_size),hl + or a, a + sbc hl, hl + ld (ti.asm_prgm_size), hl ret push_stub: pop hl - ld (.ret),hl - ld hl,stub.prgm + ld (push_stub.ret), hl + ld hl, stub.prgm call find_prgm - ld (.stub_prgm_size),de - ld (.prev_sp),sp - ld hl,-9 - add hl,sp - ld sp,hl - ld (.stub_prgm),hl - ex de,hl - ld hl,stub.prgm - ld bc,9 + ld (push_stub.stub_prgm_size), de + ld (push_stub.prev_sp), sp + ld hl, -9 + add hl, sp + ld sp, hl + ld (push_stub.stub_prgm), hl + ex de, hl + ld hl, stub.prgm + ld bc, 9 ldir - ld hl,-(stub.len - 9) - add hl,sp - ld sp,hl - ld (.stub_normal),hl + ld hl, -(stub.len - 9) + add hl, sp + ld sp, hl + ld (push_stub.stub_normal), hl push hl - ld bc,stub.error_handler - stub.normal - add hl,bc - ld (.stub_error_handler),hl + ld bc, stub.error_handler - stub.normal + add hl, bc + ld (push_stub.stub_error_handler), hl pop hl - jr .skip_parser_hook -.skip_parser_hook_jr := $-1 + jr .L.skip_parser_hook +.equ push_stub.skip_parser_hook_jr, $-1 push hl - ld bc,stub.hook_parser - stub.normal - add hl,bc + ld bc, stub.hook_parser - stub.normal + add hl, bc call ti.SetParserHook pop hl -.skip_parser_hook: - ex de,hl - ld hl,stub - ld bc,stub.len +.L.skip_parser_hook: + ex de, hl + ld hl, stub + ld bc, stub.len ldir - ld hl,0 -.prev_sp := $-3 + ld hl, 0 +.equ push_stub.prev_sp, $-3 push hl ld hl,0 -.data_size := $-3 +.equ push_stub.data_size, $-3 push hl - ld hl,0 -.stub_prgm := $-3 + ld hl, 0 +.equ push_stub.stub_prgm, $-3 push hl - ld hl,0 -.stub_prgm_size := $-3 + ld hl, 0 +.equ push_stub.stub_prgm_size, $-3 push hl call ti.SaveParse - ld hl,0 -.stub_error_handler := $-3 + ld hl, 0 +.equ push_stub.stub_error_handler, $-3 call ti.PushErrorHandler - ld hl,0 -.stub_normal := $-3 + ld hl, 0 +.equ push_stub.stub_normal, $-3 push hl jp 0 -.ret := $-3 +.equ push_stub.ret, $-3 find_prgm: call ti.Mov9ToOP1 call ti.ChkFindSym ret c call ti.ChkInRam - ex de,hl - jr z,.in_ram - ld de,9 - add hl,de - ld e,(hl) - add hl,de + ex de, hl + jr z, .L.prgm_in_ram + ld de, 9 + add hl, de + ld e, (hl) + add hl, de inc hl -.in_ram: +.L.prgm_in_ram: call ti.LoadDEInd_s - or a,a + or a, a ret stub: -.normal: - xor a,a - sbc hl,hl -.basic_c_smc := $-3 - ld (ti.cursorImage),hl - ld iy,ti.flags +stub.normal: + xor a, a + sbc hl, hl +.equ stub.basic_c_smc, $-3 + ld (ti.cursorImage), hl + ld iy, ti.flags call ti.PopErrorHandler - jr .no_error -.error_handler: - or a,a - sbc hl,hl - ld l,a - ld (ti.cursorImage),hl -.no_error: - ld iy,ti.flags - set ti.allowProgTokens,(iy + ti.newDispF) -.flags.newDispF := $-1 - set ti.cmdExec,(iy + ti.cmdFlags) -.flags.cmdFlags := $-1 - res ti.textInverse,(iy + ti.textFlags) - res ti.onInterrupt,(iy + ti.onFlags) - res ti.numOP1,(iy + ti.ParsFlag2) + jr .L.no_error +stub.error_handler: + or a, a + sbc hl, hl + ld l, a + ld (ti.cursorImage), hl +.L.no_error: + ld iy, ti.flags + set ti.allowProgTokens, (iy + ti.newDispF) +.equ stub.flags.newDispF, $-1 + set ti.cmdExec, (iy + ti.cmdFlags) +.equ stub.flags.cmdFlags, $-1 + res ti.textInverse, (iy + ti.textFlags) + res ti.onInterrupt, (iy + ti.onFlags) + res ti.numOP1, (iy + ti.ParsFlag2) call ti.ClrParserHook - ld hl,0 -.prev_hook := $-3 - ld a,(hl) - cp a,$83 - call z,ti.SetParserHook - ld hl,(ti.asm_prgm_size) - add hl,de - or a,a - sbc hl,de - ex de,hl - ld hl,ti.userMem - call nz,ti.DelMem + ld hl, 0 +.equ stub.prev_hook, $-3 + ld a, (hl) + cp a, $83 + call z, ti.SetParserHook + ld hl, (ti.asm_prgm_size) + add hl, de + or a, a + sbc hl, de + ex de, hl + ld hl, ti.userMem + call nz, ti.DelMem call ti.PopRealO1 call ti.GetParse - pop de ; size of return program -- shouldn't change? + pop de ; size of return program -- shouldn't change? push de call ti.ErrNotEnoughMem pop hl - ld (ti.asm_prgm_size),hl - ld de,ti.userMem + ld (ti.asm_prgm_size), hl + ld de, ti.userMem call ti.InsertMem - pop hl ; stub program to return + pop hl ; stub program to return call ti.Mov9ToOP1 call ti.ChkFindSym - jr nc,.found -.error: + jr nc, .L.found +stub.error: pop bc pop hl - add hl,bc - ld sp,hl ; os should delete created program + add hl, bc + ld sp, hl ; os should delete created program ret -.hook_parser: - db $83 ; hook signifier - cp a,2 - jr nz,.chain - ld a,$d9 - $ce ; check if stop token - sub a,b - jp z,ti.JError - ld a,2 -.chain: - jp 0 ; xor a,a \ ret if not chaining -.found: +stub.hook_parser: + db 0x83 ; hook signifier + cp a, 2 + jr nz, stub.chain + ld a, 0xD9 - 0xCE ; check if stop token + sub a, b + jp z, ti.JError + ld a, 2 +stub.chain: + jp 0 ; xor a,a \ ret if not chaining +.L.found: call ti.ChkInRam - ex de,hl - jr z,.in_ram - ld de,9 - add hl,de - ld e,(hl) - add hl,de + ex de, hl + jr z, .L.in_ram + ld de, 9 + add hl, de + ld e, (hl) + add hl, de inc hl -.in_ram: +.L.in_ram: inc hl inc hl inc hl inc hl - ld bc,(ti.asm_prgm_size) - ld de,ti.userMem + ld bc, (ti.asm_prgm_size) + ld de, ti.userMem ldir ld de,0 -.callback := $-3 +.equ stub.callback, $-3 pop bc ; data size pop hl ; data di - ld sp,hl + ld sp, hl push bc push de ; push callback address scf - ld hl,(ti.cursorImage) + ld hl, (ti.cursorImage) push hl ; push retval - sbc hl,hl + sbc hl, hl push hl ; return of -1 should never occur jp ti.userMem - rb 3 ; padding bytes for sp change -.prgm: - rb 9 -.len := $-stub + .zero 3 ; padding bytes for sp change +stub.prgm: + .zero 9 +.equ stub.len, $-stub ___prgm_to_run: - rb 9 + .zero 9 ___prgm_to_run_size: - dl 0 - - private reloc_rodata -load reloc_rodata: $-$$ from $$ -end virtual - - section .data - private reloc.data - private reloc.data.len -reloc.data: - db reloc_rodata -.len := $-. -reloc.base := ti.cursorImage -reloc.offset := reloc.base - reloc.data + .d24 0 - section .data - public ___prgm_caller + section .data.___prgm_caller + .global ___prgm_caller ___prgm_caller: - rb 9 + .zero 9 - extern ___exithl - extern _exit.sp - extern _exit.offset - extern ___prgm_run_check + .extern ___exithl + .extern _exit.sp + .extern _exit.offset diff --git a/src/ce/sleep.src b/src/ce/sleep.src index 401d6f20b..5fb9fd670 100644 --- a/src/ce/sleep.src +++ b/src/ce/sleep.src @@ -1,15 +1,17 @@ ; unsigned int sleep(unsigned int seconds); - assume adl=1 + .assume adl=1 -if 0 +.if 0 ; Minimal caller code (for timing calculation). call _sleep ; ^ 22 cc -end if +.endif + + .section .text + .global _sleep + .type _sleep, @function - section .text - public _sleep _sleep: ; Even though the input is 24-bit, let's just pretend that it's 16-bit. ; Timing assumes fetching from RAM (4cc) and the first timer read being valid. @@ -32,12 +34,12 @@ _sleep: ex (sp), hl ; hl = seconds push de ; Convert from seconds to clock ticks. - ld b,15 + ld b, 15 .loop: - add hl,hl + add hl, hl rla djnz .loop - ld e,a ; euhl = seconds * 32768 + ld e, a ; euhl = seconds * 32768 ; = ticks ; Join common code for the rest. jp ___sleep_common.1 diff --git a/src/ce/sleep_common.src b/src/ce/sleep_common.src index e977ba5fa..5a0f306c1 100644 --- a/src/ce/sleep_common.src +++ b/src/ce/sleep_common.src @@ -1,17 +1,25 @@ + .assume adl=1 + .section .text + .global ___sleep_common + .type ___sleep_common, @function + ___sleep_common: ; Timing assumes fetching from RAM (4cc) and the first timer read being valid. ; Calculate the end time. section .text - public ___sleep_common.1 -.1: + .global ___sleep_common.1 + .type ___sleep_common.1, @function +___sleep_common.1: scf ; cf = 1 ; = correction - public ___sleep_common.2 -.2: + .global ___sleep_common.2 + .type ___sleep_common.2, @function +___sleep_common.2: ld a, e ; auhl = start or ticks - public ___sleep_common.3 -.3: + .global ___sleep_common.3 + .type ___sleep_common.3, @function +___sleep_common.3: pop de pop bc ; eubc = ticks or start adc hl, bc @@ -20,15 +28,11 @@ ___sleep_common: ; Prepare. ld e, a ; euhl = end push hl -virtual - cp a, 0 -load op_cp_a: byte from $$ -end virtual - db op_cp_a + .db 0xFE ; cp a, $C5 +.L.check: + .db 0xC5 ; push bc ; ^ don't care cc -.check: ; Get the current time. - push bc push de call _clock ; euhl = now, cf = 0 ; ^ 42 + cc(_clock) cc @@ -41,7 +45,7 @@ end virtual sbc a, e ; auhl = now - end ; ^ 48 cc ; Check again if the end time has not been reached. - jr c, .check + jr c, .L.check ; ^ 13 cc (conditional jr taken) ; 42 + 48 + 202 + 31 + 48 + 13 = 384 cc check ; Return 0 to indicate success. diff --git a/src/ce/tice.src b/src/ce/tice.src deleted file mode 100644 index a3463f909..000000000 --- a/src/ce/tice.src +++ /dev/null @@ -1,303 +0,0 @@ -; --- -; external definitions -; --- - public _boot_GetBootMajorVer - public _boot_GetHardwareVer - public _boot_GetBootMinorVer - public _boot_DebugPrintf - public _boot_ClearVRAM - public _boot_TurnOn - public _boot_TurnOff - public _boot_NewLine - public _boot_Set6MHzMode - public _boot_Set48MHzMode - public _boot_Set6MHzModeI - public _boot_Set48MHzModeI - public _boot_GetBatteryStatus - public _boot_WaitShort - public _boot_BatteryCharging - public _boot_USBBusPowered - public _boot_USBSelfPowered - public _boot_USBResetChip - public _boot_USBResetTimers - public _boot_USBDisableTimers - public _boot_USBEnableTimers - public _boot_CheckOnPressed - public _boot_SetDate - public _boot_GetDate - public _boot_GetTime - public _boot_SetTime - public _boot_IsAfterNoon - - public _os_NewLine - public _os_MoveDown - public _os_MoveUp - public _os_ClrLCDFull - public _os_ClrLCD - public _os_ClrTxtShd - public _os_HomeUp - public _os_RunIndicOn - public _os_RunIndicOff - public _os_DelRes - public _os_DisableAPD - public _os_EnableAPD - public _os_DrawStatusBar - public _os_PushErrorHandler - public _os_PopErrorHandler - public _os_ThrowError - public _os_RealCopy - public _os_RealAsinRad - public _os_RealAcosRad - public _os_RealAtanRad - public _os_RealAdd - public _os_CplxSquare - public _os_RealCompare - public _os_RealCosRad - public _os_RealRadToDeg - public _os_RealDiv - public _os_RealExp - public _os_RealFloor - public _os_RealToStr - public _os_RealFrac - public _os_RealGcd - public _os_RealRoundInt - public _os_RealLcm - public _os_RealLog - public _os_RealMax - public _os_RealMin - public _os_RealMul - public _os_RealNcr - public _os_RealNeg - public _os_RealNpr - public _os_RealPow - public _os_RealDegToRad - public _os_RealRandInt - public _os_RealInv - public _os_RealMod - public _os_RealRound - public _os_RealSinRad - public _os_RealSqrt - public _os_RealSub - public _os_RealTanRad - public _os_StrToReal - public _os_RealInt - public _os_SetFlagBits - public _os_ResetFlagBits - public _os_TestFlagBits - public _os_SetFlagByte - public _os_GetFlagByte - public _os_GetCursorPos - public _os_PutStrFull - public _os_PutStrLine - public _os_SetCursorPos - public _os_GetKey - public _os_GetCSC - public _os_AppInit - public _os_DisableCursor - public _os_EnableCursor - public _os_FontDrawText - public _os_FontGetHeight - public _os_FontGetWidth - public _os_InitDrawing - public _os_SetDrawBGColor - public _os_SetDrawFGColor - public _os_FontSelect - public _os_GetAnsData - public _os_SetTimer1 - public _os_DisableTimer1 - public _os_GetSystemInfo - public _os_GetDrawBGColor - public _os_GetDrawFGColor - public _os_FontGetID - public _os_RealToInt24 - public _os_Int24ToReal - public _os_ForceCmdNoChar - public _os_DelSymEntry - public _os_GetSymTablePtr - public _os_NextSymEntry - public _os_ChkFindSym - public _os_GetVarSize - public _os_GetMatrixDims - public _os_GetRealListElement - public _os_GetMatrixElement - public _os_GetRealVar - public _os_SetListDim - public _os_SetMatrixDims - public _os_SetRealListElement - public _os_SetMatrixElement - public _os_SetRealVar - public _os_MemChk - public _os_ArcChk - public _os_SetTimer2 - public _os_DisableTimer2 - public _os_FloatToReal - public _os_RealToFloat - public _os_FontDrawTransText - public _os_DelAppVar - public _os_GetAppVarData - public _os_CreateAppVar - public _os_CreateString - public _os_GetStringData - public _os_CreateEquation - public _os_GetEquationData - public _os_MSDGetMaxLUN - public _os_MSDReset - public _os_MSDInquiry - public _os_MSDTestUnitReady - public _os_MSDReadCapacity - public _os_MSDRead - public _os_MSDWrite - public _os_USBGetRequestStatus - public _os_TestFlagBitsFast - -; --- -; locations -; --- -_boot_GetBootMajorVer := 000080h -_boot_GetHardwareVer := 000084h -_boot_GetBootMinorVer := 00008Ch -_boot_DebugPrintf := 0000B4h -_boot_ClearVRAM := 000374h -_boot_TurnOn := 000384h -_boot_TurnOff := 000388h -_boot_NewLine := 000390h -_boot_Set6MHzMode := 00039Ch -_boot_Set48MHzMode := 0003A0h -_boot_Set6MHzModeI := 0003A4h -_boot_Set48MHzModeI := 0003A8h -_boot_GetBatteryStatus := 0003B0h -_boot_WaitShort := 0003B4h -_boot_BatteryCharging := 0003CCh -_boot_USBBusPowered := 0003E4h -_boot_USBSelfPowered := 0003E8h -_boot_USBResetChip := 0003F4h -_boot_USBResetTimers := 0004F0h -_boot_USBDisableTimers := 0004F4h -_boot_USBEnableTimers := 0004F8h -_boot_CheckOnPressed := 00057Ch -_boot_SetDate := 000598h -_boot_GetDate := 0005A8h -_boot_GetTime := 0005B0h -_boot_SetTime := 0005B4h -_boot_IsAfterNoon := 0005C8h - -_os_NewLine := 0207F0h -_os_MoveDown := 0207F4h -_os_MoveUp := 020800h -_os_ClrLCDFull := 020808h -_os_ClrLCD := 02080Ch -_os_ClrTxtShd := 020818h -_os_HomeUp := 020828h -_os_RunIndicOn := 020844h -_os_RunIndicOff := 020848h -_os_DelRes := 020E5Ch -_os_DisableAPD := 021134h -_os_EnableAPD := 021138h -_os_DrawStatusBar := 021A3Ch -_os_PushErrorHandler := 021C78h -_os_PopErrorHandler := 021C7Ch -_os_ThrowError := 021C80h -_os_RealCopy := 021C84h -_os_RealAcosRad := 021C88h -_os_RealAsinRad := 021C8Ch -_os_RealAtanRad := 021C90h -_os_RealAdd := 021C94h -_os_CplxSquare := 021C98h -_os_RealCompare := 021C9Ch -_os_RealCosRad := 021CA0h -_os_RealRadToDeg := 021CA4h -_os_RealDiv := 021CA8h -_os_RealExp := 021CACh -_os_RealFloor := 021CB0h -_os_RealToStr := 021CB4h -_os_RealFrac := 021CB8h -_os_RealGcd := 021CBCh -_os_RealRoundInt := 021CC0h -_os_RealLcm := 021CC4h -_os_RealLog := 021CC8h -_os_RealMax := 021CCCh -_os_RealMin := 021CD0h -_os_RealMul := 021CD4h -_os_RealNcr := 021CD8h -_os_RealNeg := 021CDCh -_os_RealNpr := 021CE0h -_os_RealPow := 021CE4h -_os_RealDegToRad := 021CE8h -_os_RealRandInt := 021CECh -_os_RealInv := 021CF0h -_os_RealMod := 021CF4h -_os_RealRound := 021CF8h -_os_RealSinRad := 021CFCh -_os_RealSqrt := 021D00h -_os_RealSub := 021D04h -_os_RealTanRad := 021D08h -_os_StrToReal := 021D0Ch -_os_RealInt := 021D10h -_os_SetFlagBits := 021D14h -_os_ResetFlagBits := 021D18h -_os_TestFlagBits := 021D1Ch -_os_SetFlagByte := 021D20h -_os_GetFlagByte := 021D24h -_os_GetCursorPos := 021D28h -_os_PutStrFull := 021D2Ch -_os_PutStrLine := 021D30h -_os_SetCursorPos := 021D34h -_os_GetKey := 021D38h -_os_GetCSC := 021D3Ch -_os_AppInit := 021D40h -_os_DisableCursor := 021DE4h -_os_EnableCursor := 021DE8h -_os_FontDrawText := 021E00h -_os_FontGetHeight := 021E14h -_os_FontGetWidth := 021E18h -_os_InitDrawing := 021E1Ch -_os_SetDrawBGColor := 021E20h -_os_SetDrawFGColor := 021E24h -_os_FontSelect := 021E28h -_os_GetAnsData := 021E70h -_os_SetTimer1 := 021EC8h -_os_DisableTimer1 := 021ECCh -_os_GetSystemInfo := 021ED4h -_os_GetDrawBGColor := 021EE4h -_os_GetDrawFGColor := 021EE8h -_os_FontGetID := 021EECh -_os_RealToInt24 := 021EF4h -_os_Int24ToReal := 021EF8h -_os_ForceCmdNoChar := 021FA8h -_os_DelSymEntry := 021FACh -_os_GetSymTablePtr := 021FB0h -_os_NextSymEntry := 021FB4h -_os_ChkFindSym := 021FB8h -_os_GetVarSize := 021FBCh -_os_GetMatrixDims := 021FC0h -_os_GetRealListElement := 021FC4h -_os_GetMatrixElement := 021FC8h -_os_GetRealVar := 021FCCh -_os_SetListDim := 021FD0h -_os_SetMatrixDims := 021FD4h -_os_SetRealListElement := 021FD8h -_os_SetMatrixElement := 021FDCh -_os_SetRealVar := 021FE0h -_os_MemChk := 021FF0h -_os_ArcChk := 022040h -_os_SetTimer2 := 022080h -_os_DisableTimer2 := 022084h -_os_FloatToReal := 022170h -_os_RealToFloat := 022174h -_os_FontDrawTransText := 022178h -_os_DelAppVar := 02217Ch -_os_GetAppVarData := 022180h -_os_CreateAppVar := 022184h -_os_CreateString := 022198h -_os_GetStringData := 02219Ch -_os_CreateEquation := 022240h -_os_GetEquationData := 022244h -_os_MSDGetMaxLUN := 022280h -_os_MSDReset := 022284h -_os_MSDInquiry := 022288h -_os_MSDTestUnitReady := 02228Ch -_os_MSDReadCapacity := 022290h -_os_MSDRead := 022294h -_os_MSDWrite := 022298h -_os_USBGetRequestStatus := 0222D0h -_os_TestFlagBitsFast := 0222FCh diff --git a/src/ce/ticksleep.src b/src/ce/ticksleep.src index 73e6b8156..6018ecc5d 100644 --- a/src/ce/ticksleep.src +++ b/src/ce/ticksleep.src @@ -1,15 +1,17 @@ ; void ticksleep(unsigned long ticks); - assume adl=1 + .assume adl=1 -if 0 +.if 0 ; Minimal caller code (for timing calculation). call _ticksleep ; ^ 22 cc -end if +.endif + + .section .text + .global _ticksleep + .type _ticksleep, @function - section .text - public _ticksleep _ticksleep: ; Timing assumes fetching from RAM (4cc) and the first timer read being valid. diff --git a/src/ce/usleep.src b/src/ce/usleep.src index ac3bb0b3f..96b969cf6 100644 --- a/src/ce/usleep.src +++ b/src/ce/usleep.src @@ -1,16 +1,18 @@ ; typedef unsigned int useconds_t; ; int usleep(useconds_t usec); - assume adl=1 + .assume adl=1 -if 0 +.if 0 ; Minimal caller code (for timing calculation). call _usleep ; ^ 22 cc -end if +.endif + + .section .text + .global _usleep + .type _usleep, @function - section .text - public _usleep _usleep: ; Timing assumes fetching from RAM (4cc) and the first timer read being valid. @@ -36,18 +38,18 @@ _usleep: ; https://docs.google.com/spreadsheets/d/1mZwDn6rEw3-uSQPuy48Ez0UWIvnggLiJxWft4u4OtcU/edit?usp=sharing xor a, a ; a = 0 ld e, a ; euhl = usec -.multiplier := 114 - ld bc, .multiplier ; aubc = multiplier + .equ .L.multiplier, 114 + ld bc, .L.multiplier ; aubc = multiplier call __lmulu ; euhl = usec * multiplier -.correction_scaled := 5796 - ld bc, .correction_scaled + .equ .L.correction_scaled, 5796 + ld bc, .L.correction_scaled add hl, bc adc a, e ; auhl = usec * multiplier + ; correction_scaled ld e, a ; euhl = usec * multiplier + ; correction_scaled -.divisor := 3479 - ld bc, .divisor + .equ .L.divisor, 3479 + ld bc, .L.divisor xor a, a ; aubc = divisor call __ldivu ; euhl = (usec * multiplier + ; correction_scaled) / @@ -57,7 +59,7 @@ _usleep: jp ___sleep_common.2 - extern ___sleep_common.2 - extern __ldivu - extern __lmulu - extern _clock + .extern ___sleep_common.2 + .extern __ldivu + .extern __lmulu + .extern _clock diff --git a/src/ce/zx0.src b/src/ce/zx0.src index 585821658..1c85077ea 100644 --- a/src/ce/zx0.src +++ b/src/ce/zx0.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _zx0_Decompress + .type _zx0_Decompress, @function - section .text - public _zx0_Decompress _zx0_Decompress: pop bc pop de @@ -45,7 +47,7 @@ dzx0t_new_offset_skip: dzx0t_copy: push hl ; preserve source ; dzx0t_last_offset: - lea hl, iy ; restore offset + lea hl, iy + 0 ; restore offset add hl, de ; calculate destination - offset ldir ; copy from offset pop hl ; restore source diff --git a/src/ce/zx7.src b/src/ce/zx7.src index 97b537e79..5b780acee 100644 --- a/src/ce/zx7.src +++ b/src/ce/zx7.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _zx7_Decompress + .type _zx7_Decompress, @function - section .text - public _zx7_Decompress _zx7_Decompress: pop bc pop de diff --git a/src/common.mk b/src/common.mk index 374a751f8..c1946d1ae 100644 --- a/src/common.mk +++ b/src/common.mk @@ -14,6 +14,8 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) + GIT_SHA = $(shell git describe --abbrev=8 --dirty --always --tags) CEDEV_VERSION := $(GIT_SHA) @@ -42,6 +44,8 @@ WINDOWS := 1 SHELL := cmd.exe FASMG ?= fasmg.exe EZCC ?= ez80-clang.exe +EZAS ?= z80-none-elf-as.exe +EZAR ?= z80-none-elf-ar.exe NULL ?= nul NATIVEPATH ?= $(subst /,\,$1) NATIVEEXE ?= $(NATIVEPATH).exe @@ -56,6 +60,8 @@ RELEASE_NAME = windows else FASMG ?= fasmg EZCC ?= ez80-clang +EZAS ?= z80-none-elf-as +EZAR ?= z80-none-elf-ar NULL ?= /dev/null NATIVEPATH ?= $(subst \,/,$1) NATIVEEXE ?= $(NATIVEPATH) @@ -75,21 +81,31 @@ RELEASE_NAME = linux endif endif +QUOTE_NATIVE = $(call QUOTE_ARG,$(call NATIVEPATH,$1)) + +EZCFLAGS := -S -fno-autolink -fno-addrsig -fno-math-errno -ffunction-sections -fdata-sections -ffreestanding +EZCFLAGS += -Wall -Wextra -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz +EZCFLAGS += -D_EZ80 -isystem $(call NATIVEPATH,$(ROOT_DIR)libc/include) -I$(call NATIVEPATH,$(ROOT_DIR)ce/include) -I$(call NATIVEPATH,$(ROOT_DIR)fileioc) +EZCFLAGS += -mllvm -profile-guided-section-prefix=false -mllvm -z80-gas-style -mllvm -z80-print-zero-offset +EZCXXFLAGS := $(EZCFLAGS) -fno-exceptions -fno-rtti +EZCXXFLAGS += -isystem $(call NATIVEPATH,$(ROOT_DIR)libcxx/include) +EZASFLAGS := -march=ez80+full + INSTALL_DIR := $(patsubst %/,%,$(subst \,/,$(DESTDIR)))/$(PREFIX) -INSTALL_PATH := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR))) -INSTALL_EXAMPLES := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/examples)) -INSTALL_LIB := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/lib/libload)) -INSTALL_CRT := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/lib/crt)) -INSTALL_LIBC := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/lib/libc)) -INSTALL_LIBCXX := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/lib/libcxx)) -INSTALL_SOFTFLOAT := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/lib/softfloat)) -INSTALL_CE := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/lib/ce)) -INSTALL_BIN := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/bin)) -INSTALL_H := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/include)) -INSTALL_TI_H := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/include/ti)) -INSTALL_HW_H := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/include/sys)) -INSTALL_CXX_H := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/include/c++)) -INSTALL_CXX_TI_H := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/include/c++/ti)) -INSTALL_CXX_HW_H := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/include/c++/sys)) -INSTALL_META := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR)/meta)) -INSTALL_DIR := $(call QUOTE_ARG,$(call NATIVEPATH,$(INSTALL_DIR))) +INSTALL_PATH := $(call QUOTE_NATIVE,$(INSTALL_DIR)) +INSTALL_EXAMPLES := $(call QUOTE_NATIVE,$(INSTALL_DIR)/examples) +INSTALL_LIB := $(call QUOTE_NATIVE,$(INSTALL_DIR)/lib/libload) +INSTALL_CRT := $(call QUOTE_NATIVE,$(INSTALL_DIR)/lib/crt) +INSTALL_LIBC := $(call QUOTE_NATIVE,$(INSTALL_DIR)/lib/libc) +INSTALL_LIBCXX := $(call QUOTE_NATIVE,$(INSTALL_DIR)/lib/libcxx) +INSTALL_SOFTFLOAT := $(call QUOTE_NATIVE,$(INSTALL_DIR)/lib/softfloat) +INSTALL_CE := $(call QUOTE_NATIVE,$(INSTALL_DIR)/lib/ce) +INSTALL_BIN := $(call QUOTE_NATIVE,$(INSTALL_DIR)/bin) +INSTALL_H := $(call QUOTE_NATIVE,$(INSTALL_DIR)/include) +INSTALL_TI_H := $(call QUOTE_NATIVE,$(INSTALL_DIR)/include/ti) +INSTALL_HW_H := $(call QUOTE_NATIVE,$(INSTALL_DIR)/include/sys) +INSTALL_CXX_H := $(call QUOTE_NATIVE,$(INSTALL_DIR)/include/c++) +INSTALL_CXX_TI_H := $(call QUOTE_NATIVE,$(INSTALL_DIR)/include/c++/ti) +INSTALL_CXX_HW_H := $(call QUOTE_NATIVE,$(INSTALL_DIR)/include/c++/sys) +INSTALL_META := $(call QUOTE_NATIVE,$(INSTALL_DIR)/meta) +INSTALL_DIR := $(call QUOTE_NATIVE,$(INSTALL_DIR)) diff --git a/src/crt/and.src b/src/crt/and.src index fb181402f..c05821c9e 100644 --- a/src/crt/and.src +++ b/src/crt/and.src @@ -1,43 +1,27 @@ - assume adl=1 + .assume adl=1 - section .text - public __land + .section .text + .global __land + .section .text + .global __iand -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__land := 0001A4h + .set __land, 0x0001A4 + .set __iand, 000134h -else +.else __land: ; CC: 28*r(PC)+11*r(SPL)+10*w(SPL)+1 push af and a, e ld e, a -; jr __iand.hijack_land - virtual - ld a, 0 - load .ld_a: byte from $$ - end virtual - db .ld_a ; push af -> ld a,* - require __iand - -end if - - section .text - public __iand - -if PREFER_OS_CRT - -__iand := 000134h - -else - + jr .L.hijack_land __iand: ; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1 push af - private __iand.hijack_land -.hijack_land: +.L.hijack_land: push hl scf sbc hl, hl @@ -60,4 +44,4 @@ __iand: pop af ret -end if +.endif diff --git a/src/crt/and_fast.src b/src/crt/and_fast.src index b868041af..56dad9c07 100644 --- a/src/crt/and_fast.src +++ b/src/crt/and_fast.src @@ -1,15 +1,14 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __land_fast + .global __iand_fast + .global __sand_fast - section .text - public __land_fast __land_fast: ; CC: 24*r(PC)+8*r(SPL)+7*w(SPL)+1 and a, e ld e, a - require __iand_fast - - section .text - public __iand_fast __iand_fast: ; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1 push hl @@ -25,10 +24,6 @@ __iand_fast: and a, (hl) ld (hl), a pop hl - require __sand_fast - - section .text - public __sand_fast __sand_fast: ; CC: 8*r(PC)+3*r(SPL)+1 ld a, h diff --git a/src/crt/bbitrev.src b/src/crt/bbitrev.src index 9ea28809c..d075bcf79 100644 --- a/src/crt/bbitrev.src +++ b/src/crt/bbitrev.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bbitrev + .type __bbitrev, @function - section .text - public __bbitrev __bbitrev: push bc ld b,a ; b=ABCDEFGH @@ -21,4 +23,3 @@ __bbitrev: rrca ; a=HGFEDCBA pop bc ret - diff --git a/src/crt/bdivs.src b/src/crt/bdivs.src index dad74b4b0..ba27dee40 100644 --- a/src/crt/bdivs.src +++ b/src/crt/bdivs.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bdivs + .type __bdivs, @function - section .text - public __bdivs __bdivs: ; I: B=dividend, C=divisor ; O: a=B/C @@ -22,4 +24,4 @@ __bdivs: ret - extern __bdvrms_abs + .extern __bdvrms_abs diff --git a/src/crt/bdivu.src b/src/crt/bdivu.src index f9bc91657..16f163e7b 100644 --- a/src/crt/bdivu.src +++ b/src/crt/bdivu.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bdivu + .type __bdivu, @function - section .text - public __bdivu __bdivu: ; I: B=dividend, C=divisor ; O: a=B/C @@ -17,4 +19,4 @@ __bdivu: ret - extern __bdvrmu + .extern __bdvrmu diff --git a/src/crt/bdvrms_abs.src b/src/crt/bdvrms_abs.src index 3c0fc9c1b..2f6c4d48d 100644 --- a/src/crt/bdvrms_abs.src +++ b/src/crt/bdvrms_abs.src @@ -1,31 +1,34 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bdvrms_abs + .type __bdvrms_abs, @function - section .text - public __bdvrms_abs __bdvrms_abs: ; I: C=divisor, L=dividend ; O: a=?, h=abs(L)%abs(C), l=abs(L)/abs(C) ld a, l - public __bdvrms_abs.hijack_a_l_dividend -.hijack_a_l_dividend: + .global __bdvrms_abs.hijack_a_l_dividend + .type __bdvrms_abs.hijack_a_l_dividend, @function +__bdvrms_abs.hijack_a_l_dividend: rla - jr nc, .neg_dividend_skip + jr nc, .L.neg_dividend_skip xor a, a sub a, l ld l, a -.neg_dividend_skip: +.L.neg_dividend_skip: push bc ld a, c rla - jr nc, .neg_divisor_skip + jr nc, .L.neg_divisor_skip xor a, a sub a, c ld c, a - jr nc, .neg_dividend_skip -.neg_divisor_skip: + jr nc, .L.neg_dividend_skip +.L.neg_divisor_skip: call __bdvrmu.hijack_l_dividend @@ -33,4 +36,4 @@ __bdvrms_abs: ret - extern __bdvrmu.hijack_l_dividend + .extern __bdvrmu.hijack_l_dividend diff --git a/src/crt/bdvrmu.src b/src/crt/bdvrmu.src index 8f7af268d..faea08821 100644 --- a/src/crt/bdvrmu.src +++ b/src/crt/bdvrmu.src @@ -1,29 +1,32 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bdvrmu + .type __bdvrmu, @function + .global __bdvrmu.hijack_l_dividend + .type __bdvrmu.hijack_l_dividend, @function - section .text - public __bdvrmu __bdvrmu: ; I: B=dividend, C=divisor ; O: a=?, b=0, h=B%C, l=B/C ld l, b - public __bdvrmu.hijack_l_dividend -.hijack_l_dividend: - ld h, 0 +__bdvrmu.hijack_l_dividend: + ld h, 0 ld b, 8 -.loop: +.L.loop: add hl, hl ld a, h sub a, c - jr c, .bit_skip + jr c, .L.bit_skip ld h, a inc l -.bit_skip: +.L.bit_skip: - djnz .loop + djnz .L.loop ret diff --git a/src/crt/bmuls.src b/src/crt/bmuls.src index 2f94fa278..e9221c22f 100644 --- a/src/crt/bmuls.src +++ b/src/crt/bmuls.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bmuls + .type __bmuls, @function - section .text - public __bmuls __bmuls: push bc ld c,a diff --git a/src/crt/bmulu.src b/src/crt/bmulu.src index fa1b2ce66..3e929e781 100644 --- a/src/crt/bmulu.src +++ b/src/crt/bmulu.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bmulu + .type __bmulu, @function - section .text - public __bmulu __bmulu: push bc mlt bc diff --git a/src/crt/bpopcnt.src b/src/crt/bpopcnt.src index 96caa3e38..499d7f83d 100644 --- a/src/crt/bpopcnt.src +++ b/src/crt/bpopcnt.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bpopcnt + .type __bpopcnt, @function - section .text - public __bpopcnt __bpopcnt: push hl ld l, a diff --git a/src/crt/brems.src b/src/crt/brems.src index ca1c80c8f..56163d7ca 100644 --- a/src/crt/brems.src +++ b/src/crt/brems.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __brems + .type __brems, @function - section .text - public __brems __brems: ; I: A=dividend, C=divisor ; O: a=A%C @@ -22,4 +24,4 @@ __brems: ret - extern __bdvrms_abs.hijack_a_l_dividend + .extern __bdvrms_abs.hijack_a_l_dividend diff --git a/src/crt/bremu.src b/src/crt/bremu.src index ca5701717..e0c96040c 100644 --- a/src/crt/bremu.src +++ b/src/crt/bremu.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bremu + .type __bremu, @function - section .text - public __bremu __bremu: ; I: A=dividend, C=divisor ; O: a=A%C @@ -18,4 +20,4 @@ __bremu: ret - extern __bdvrmu + .extern __bdvrmu diff --git a/src/crt/bshl.src b/src/crt/bshl.src index de42411d1..293e7580e 100644 --- a/src/crt/bshl.src +++ b/src/crt/bshl.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __bshl + .section .text + .global __bshl + .type __bshl, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__bshl := 000100h + .set __bshl, 0x000100 -else +.else __bshl: ; CC: if B!=0: B*(4*r(PC)+1)+6*r(PC)+(ADL?6*r(SPL)+3*w(SPL):4*r(SPS)+2*w(SPS))+1 @@ -16,10 +17,10 @@ __bshl: dec b ret z push bc -.loop: +.L.loop: add a, a - djnz .loop + djnz .L.loop pop bc ret -end if +.endif diff --git a/src/crt/bshrs.src b/src/crt/bshrs.src index 8461f9bb8..ecb6b1aef 100644 --- a/src/crt/bshrs.src +++ b/src/crt/bshrs.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __bshrs + .type __bshrs, @function - section .text - public __bshrs __bshrs: ; CC: if B!=0: B*(5*r(PC)+1)+6*r(PC)+(ADL?6*r(SPL)+3*w(SPL):4*r(SPS)+2*w(SPS))+1 ; if B==0: 4*r(PC)+(ADL?3*r(SPL):2*r(SPS))+2 @@ -9,8 +11,8 @@ __bshrs: dec b ret z push bc -.loop: +.L.loop: sra a - djnz .loop + djnz .L.loop pop bc ret diff --git a/src/crt/bshru.src b/src/crt/bshru.src index 1266d03be..6e0e1c4cc 100644 --- a/src/crt/bshru.src +++ b/src/crt/bshru.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __bshru + .section .text + .global __bshru + .type __bshru, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__bshru := 000104h + .set __bshru, 0x000104 -else +.else __bshru: ; CC: if B!=0: B*(5*r(PC)+1)+6*r(PC)+(ADL?6*r(SPL)+3*w(SPL):4*r(SPS)+2*w(SPS))+1 @@ -16,10 +17,10 @@ __bshru: dec b ret z push bc -.loop: +.L.loop: srl a - djnz .loop + djnz .L.loop pop bc ret -end if +.endif diff --git a/src/crt/crt.src b/src/crt/crt.src new file mode 100644 index 000000000..b3ecb5db6 --- /dev/null +++ b/src/crt/crt.src @@ -0,0 +1,18 @@ + .assume adl = 1 + + .section .init.weak_crt,"ax",@progbits + + ; hacks to get the icon and description to be included, + ; since the real crt overrides the weak + + .weak __start +__start: + ld hl, ___description + ld hl, ___icon + ld hl, _main + ld hl, ___main_argc_argv + + .extern ___main_argc_argv + .extern _main + .extern ___icon + .extern ___description diff --git a/src/crt/crt0.S b/src/crt/crt0.S new file mode 100644 index 000000000..547f177fb --- /dev/null +++ b/src/crt/crt0.S @@ -0,0 +1,396 @@ +#include "crt.h" + + .assume adl = 1 + + .set ti.mpTmr1Counter, 0x0F20000 + .set ti.mpTmrCtrl, 0x0F20030 + + .set ti.bTmr1Enable, 0 + .set ti.bTmr1Crystal, 1 + .set ti.bTmr1Overflow, 2 + .set ti.bTmr1CountUp, 9 + + .set ti.Arc_Unarc, 0x021448 + .set ti.usb_ResetTimer, 0x00004F0 + .set ti.usb_DisableTimer, 0x00004F4 + .set ti.HomeUp, 0x020828 + .set ti.DrawStatusBar, 0x021A3C + .set ti.ChkFindSym, 0x02050C + .set ti.Mov9ToOP1, 0x020320 + .set ti.PutS, 0x0207C0 + .set ti.ChkInRam, 0x021F98 + .set ti.OP1, 0xD005F8 + .set ti.OP3, 0xD0060E + .set ti.AppVarObj, 0x15 + .set ti.ClrScrn, 0x020814 + .set ti.NewLine, 0x0207F0 + .set ti.GetKey, 0x020D8C + .set ti.flags, 0xD00080 + .set ti.RunIndicOff, 0x020848 + .set ti.PushRealO1, 0x020614 + .set ti.Mov8b, 0x020304 + .set ti.AnsName, 0x020FF4 + .set ti.FindSym, 0x020510 + .set ti.StrngObj, 4 + .set ti.Get_Tok_Strng, 0x020870 + .set ti.Isa2ByteTok, 0x0204AC + .set ti.PopRealO1, 0x0205DC + .set ti.MovFrOP1, 0x02032C + .set ti.ClrLCDFull, 0x020808 + + .section .header,"ax",@progbits + + .local __header +__header: + .db 0xEF, 0x7B, 0x00 ; 0x00 is signifier for C programs + + .section .init,"ax",@progbits + + .global __start +__start: + ld iy, ti.flags + +#if HAS_RUN_PRGM + ld de, ___prgm_caller + call ti.MovFrOP1 ; ti.MovFROP1 + pop hl + ld de, 1 + add hl, de + dec hl + jr nc, .L.no_rerun + ld hl, .L.rerun_handler + ld (__start._main), hl + pop hl + ld (.L.rerun_handler.retval), hl + pop hl + ld (.L.rerun_handler.callback), hl + pop hl + ld (.L.rerun_handler.data_size), hl + ex de, hl + add hl, sp ; user callback data + dec hl + ld (.L.rerun_handler.data), hl + db 0x3E ; ld a, push hl +.L.no_rerun: + push hl ; push hl +#endif + +#if HAS_LIBLOAD + call ti.PushRealO1 ; save running program name + jr .L.tryfind +.L.inram: + call ti.Arc_Unarc +.L.tryfind: + ld hl, __libloadname - 1 + call ti.Mov9ToOP1 + ld a, ti.AppVarObj + ld (ti.OP1), a + call ti.ChkFindSym + jr c, .L.notfound + call ti.ChkInRam + jr z, .L.inram ; if in ram, archive libload and search again + ld hl, 9 + 1 + __libloadnamelen + 2 + add hl, de + push hl + call ti.PopRealO1 ; restore running program name + pop hl ; start of loader (required to be in hl) + ld de, ___libload_libs ; start of relocation data + jp (hl) ; jump to the loader -- it should take care of everything else +.L.notfound: + call ti.PopRealO1 ; restore running program name + call ti.ClrScrn + call ti.HomeUp + ld hl, __missingappvar + call ti.PutS + call ti.NewLine + ld hl, __webaddress + call ti.PutS + jp ti.GetKey + +___libload_libs: + LIBLOAD_LIBS ; autogenerated by cedev-obj +#endif + + call ti.RunIndicOff ; assumes iy = flags + call ti.usb_DisableTimer + di + res 1, (iy + 0x0D) ; no text buffer + res 3, (iy + 0x4A) ; use first shadow buffer + set 5, (iy + 0x4C) ; only display + ld hl, 0xE00305 + ld a, (hl) + ld (_exit.flash_wait_states), a + ld (hl), h ; set flash wait states to 3; 1 was definitely + ; too low, 2 is untested + ld (_exit.sp), sp ; save sp for exiting + +#if HAS_MAIN_ARGC_ARGV + .equ .L.argstemp, 0xD120D6 ; saveSScreen + 14007 + call ti.PushRealO1 + ld de, .L.argstemp + ld a, e ; Lenter + ld (de), a + inc de + ld hl, ti.OP1 + 1 + call ti.Mov8b + ld a, d ; Lspace + ld (de),a + inc de + push de + call ti.AnsName + call ti.FindSym + ex de, hl + pop de + xor a, ti.StrngObj + jr nz, .L.parse_ans_done + ld c, (hl) + inc hl + ld b, (hl) + jr .L.parse_ans_next +.L.parse_ans_loop: + inc hl + dec bc + push hl + push bc + push de + call ti.Get_Tok_Strng + pop de + ld hl, ti.OP3 + ldir + pop bc + pop hl + bit 2, d + jr nz, .L.parse_ans_done + ld a, (hl) + call ti.Isa2ByteTok + jr nz, .L.parse_ans_next + inc hl + dec bc +.L.parse_ans_next: + ld a, c + or a, b + jr nz, .L.parse_ans_loop +.L.parse_ans_done: + ld bc, 0 + ld hl, .L.argstemp + sbc hl, de + add hl, sp + ld sp, hl + ld hl, (_exit.sp) + push bc + db 0x3E ; ld a, push hl +.L.argv_loop: + push hl + inc bc +.L.skip_spaces_loop: + dec de + ld a, (de) + cp a, 0x20 ; Lspace + jr z, .L.skip_spaces_loop + dec hl + ld (hl), 0 +.L.arg_copy_loop: + dec hl + ld (hl), a + dec de + ld a, (de) + cp a, 0x20 ; Lspace + jr z, .L.argv_loop + cp a, 0xD6 ; Lenter + jr nz, .L.arg_copy_loop + push hl + sbc hl, hl + add hl, sp + push hl + push bc + call ti.PopRealO1 +#endif + +.L.bss_zeroize: + ld hl, ___bss_len + ld bc, 0 + xor a, a + sbc hl, bc + jr z, .L.bss_done + ld de, ___bss_low + push de + ld (de), a + dec hl + sbc hl, bc + pop hl + jr z, .L.bss_done + ld bc, ___bss_len + dec bc + inc de + ldir +.L.bss_done: + +#if HAS_CLOCK + ld hl, ti.mpTmrCtrl + 1 + set ti.bTmr1CountUp - 8, (hl) + dec hl + res ti.bTmr1Enable, (hl) + set ti.bTmr1Crystal, (hl) + res ti.bTmr1Overflow, (hl) + ld l, (ti.mpTmr1Counter + 1) & 0xFF + ld de, 0 ; Set the counter to zero + ld (hl), de + dec hl + ld (hl), e + ld l, ti.mpTmrCtrl & 0xFF + set ti.bTmr1Enable, (hl) ; Enable the timer +#endif + +#if HAS_INIT_ARRAY + ld hl, __init_array_start + jr .L.init_array_start +.L.init_array_loop: + push hl + ld hl, (hl) + call __indcallhl + pop hl + inc hl + inc hl + inc hl +.L.init_array_start: + ld de, __init_array_end + or a, a + sbc hl, de + add hl, de + jr nz, .L.init_array_loop + + .extern __init_array_start + .extern __init_array_end +#endif + +#if HAS_MAIN_ARGC_ARGV + call ___main_argc_argv +#else + call _main +#endif + .equ __start._main, $ - 3 + .global ___exithl +___exithl: +#if HAS_ATEXIT || HAS_FINI_ARRAY || HAS_ABORT + push hl + push de +#endif + .global _exit + .type _exit, @function +_exit: +#if HAS_ATEXIT + jr .L.exit_function_start +.L.exit_function_loop: + ld hl, (ix + 1 + 0 * 3) + ld (__atexit_functions), hl + pop hl + ld de, (ix + 1 + 2 * 3) + push hl + push de + push hl + ld hl, (ix + 1 + 1 * 3) + push hl + pea ix + 1 + call _free + pop bc + pop hl + call __indcallhl + pop bc + pop bc +.L.exit_function_start: + ld ix, (__atexit_functions) + ld bc, -1 + add ix, bc + jr c, .L.exit_function_loop +#endif +#if HAS_FINI_ARRAY + ld hl, __fini_array_end + jr .L.fini_array_start +.L.fini_array_loop: + dec hl + dec hl + dec hl + push hl + ld hl, (hl) + call __indcallhl + pop hl +.L.fini_array_start: + ld de, __fini_array_start + or a, a + sbc hl, de + add hl, de + jr nz, .L.fini_array_loop + + .extern __fini_array_start + .extern __fini_array_end +#endif +#if HAS_ATEXIT || HAS_FINI_ARRAY || HAS_ABORT + pop de + pop hl +#endif +#if HAS_ABORT + jr .L.skip._abort + .global _abort + .type _abort, @function +_abort: + ld hl, 6 ; SIGABRT +.L.skip._abort: +#endif + ld sp,0 + .global _exit.sp + .equ _exit.sp, $ - 3 + push hl + ld iy, ti.flags + ld a, 0 + .local _exit.flash_wait_states + .equ _exit.flash_wait_states, $ - 1 + ld (0xE00305), a + call ti.usb_ResetTimer + ld a, 1 + ld (0xF00008), a ; clear on interrupt + res 4, (iy + 0x09) ; onInterrupt,(iy+onFlags) + set 0, (iy + 0x03) ; graphDraw,(iy+graphFlags) + set 1, (iy + 0x0D) ; use text buffer + res 3, (iy + 0x4A) ; use first shadow buffer + res 5, (iy + 0x4C) ; use shadow buffer + call ti.ClrLCDFull + call ti.HomeUp + call ti.DrawStatusBar + pop hl ; hl = exit code + ret + +#if HAS_RUN_PRGM +.L.rerun_handler: + ld hl, (_exit.sp) + ld de, 0 + .equ .L.rerun_handler.data_size, $ - 3 + add hl, de + ld (_exit.sp), hl ; move exit.sp to real ret + ld hl, 0 + .equ .L.rerun_handler.retval, $ - 3 + ex (sp), hl + ld de, 0 + .equ .L.rerun_handler.data, $ - 3 + push de + push hl + jp 0 + .equ .L.rerun_handler.callback, $ - 3 +#endif + +#if HAS_LIBLOAD + .section .rodata.libload +__missingappvar: + .db "Need " +__libloadname: + .db "LibLoad" + .equ __libloadnamelen, $ - __libloadname + .db 0 +__webaddress: + .db "http://tiny.cc/clibs",0 +#endif + +#if HAS_MAIN_ARGC_ARGV + .extern ___main_argc_argv +#else + .extern _main +#endif diff --git a/src/crt/crt0.src b/src/crt/crt0.src deleted file mode 100644 index 53c3d9ed1..000000000 --- a/src/crt/crt0.src +++ /dev/null @@ -1,544 +0,0 @@ - assume adl=1 - -mpTmr1Counter := 0F20000h -mpTmrCtrl := 0F20030h - -bTmr1Enable := 0 -bTmr1Crystal := 1 -bTmr1Overflow := 2 -bTmr1CountUp := 9 - - public _errno -_errno := $D008DC - - section .text - public _atexit -_atexit: - public _on_exit -_on_exit: - ld hl,3*long - push hl - call _malloc - pop bc - ex de,hl - scf - sbc hl,hl - add hl,de - ret nc - ld hl,(exit_functions) - ex de,hl - ld (exit_functions),hl - ld (hl),de - pop de -repeat 2 - repeat long - inc hl - end repeat - pop bc - ld (hl),bc -end repeat - push bc,bc - ex de,hl - jp (hl) - - section .bss - private exit_functions -exit_functions rl 1 - - section .rodata - private init_functions -init_functions: -load functions: ___init_array_count * long from init_array: 0 - dl functions -load functions: ___ctors_count * long from ctors: 0 - dl functions - - section .rodata - private fini_functions -load functions: ___dtors_count * long from dtors: 0 - dl functions -load functions: ___fini_array_count * long from fini_array: 0 - dl functions -fini_functions: - - section .header - db $EF, $7B - db $00 ; C program identifier (nop) - - section .init.libs - call 020628h ; _pushop1 to save running program name - jq .tryfind -.inram: - call 021448h ; _arc_unarc -.tryfind: - ld hl,.libloadname-1 - call 020320h ; _mov9toop1 - ld a,015h ; appvarobj - ld (0D005F8h),a ; op1 - call 02050Ch ; _chkfindsym - jq c,.notfound - call 021F98h ; _chkinram - jq z,.inram ; if in ram, archive libload and search again - ld hl,9+1+.libloadnamelen+2 - add hl,de - push hl - call 0205C4h ; _popop1 to restore running program name - pop hl ; start of loader (required to be in hl) - ld de,___libs ; start of relocation data - jp (hl) ; jump to the loader -- it should take care of everything else -.notfound: - call 0205C4h ; _popop1 to restore running program name - call 020814h ; _clrscrn - call 020828h ; _homeup - ld hl,.missingappvar - call 0207C0h ; _puts - call 0207F0h ; _newline - ld hl,.webaddress - call 0207C0h ; _puts - jq 020D8Ch ; _getkey - - section .rodata - private .missingappvar -.missingappvar: - db "Need " - private .libloadname -.libloadname: - db "LibLoad" - private .libloadnamelen -.libloadnamelen := $-.libloadname - db 0 - private .webaddress -.webaddress: - db "http://tiny.cc/clibs",0 - - section .init.clock - public ___init_clock -___init_clock: -; Disable timer 1 and configure it to use the 32768Hz crystal timer, not -; generate an interurrupt on overflow, and count up. -assert bTmr1CountUp / 8 = 1 - ld hl, mpTmrCtrl + 1 - set bTmr1CountUp - 8, (hl) - dec hl -assert bTmr1Enable / 8 = 0 - res bTmr1Enable, (hl) -assert bTmr1Crystal / 8 = 0 - set bTmr1Crystal, (hl) -assert bTmr1Overflow / 8 = 0 - res bTmr1Overflow, (hl) -; Set the counter to zero. -assert mpTmrCtrl shr 8 = (mpTmr1Counter + 1) shr 8 - ld l, (mpTmr1Counter + 1) and $FF - ld de, 0 - ld (hl), de - dec hl - ld (hl), e -; Enable the timer. -assert bTmr1Enable / 8 = 0 -assert mpTmr1Counter shr 8 = mpTmrCtrl shr 8 - ld l, mpTmrCtrl and $FF - set bTmr1Enable, (hl) - - section .text - private ___rerun_handler - private ___rerun_handler.callback - private ___rerun_handler.data - private ___rerun_handler.retval - private ___rerun_handler.data_size -___rerun_handler: - ld hl,(_exit.sp) - ld de,0 -.data_size := $ - 3 - add hl,de - ld (_exit.sp),hl ; move exit.sp to real ret - ld hl,0 -.retval := $ - 3 - ex (sp),hl - ld de,0 -.data := $ - 3 - push de,hl - jp 0 -.callback := $ - 3 - - section .init.reruncheck - public ___prgm_run_check -___prgm_run_check: - ld de,___prgm_caller - call 002032Ch ; ti.MovFROP1 - pop hl - ld de,1 - add hl,de - dec hl - jq nc,.no_rerun - ld hl,___rerun_handler - ld (__start._main),hl - pop hl - ld (___rerun_handler.retval),hl - pop hl - ld (___rerun_handler.callback),hl - pop hl - ld (___rerun_handler.data_size),hl - ex de,hl - add hl,sp ; user callback data - dec hl - ld (___rerun_handler.data),hl -virtual - ld a,0 - load .ld_a: byte from $$ -end virtual - db .ld_a -.no_rerun: - push hl - - section .init - weak __start -__start: - call 0020848h ; _RunInicOff, assumes iy = flags - call 00004F4h ; _usb_DisableTimer - di ; disable interrupts - call _os_DisableHomeTextBuffer - ld hl,0E00305h - ld a,(hl) - ld (_exit.flash_wait_states),a - ld (hl),h ; set flash wait states to 3; 1 was definitely - ; too low, 2 is untested - ld (_exit.sp),sp ; save sp for exiting -if defined ___main_argc_argv -.argstemp := 0D120D6h ; saveSScreen+14007 - call 0020614h ; _PushRealO1 - ld de,.argstemp - ld a,e ; Lenter - ld (de),a - inc de - ld hl,0D005F8h+1 ; OP1+1 - call 0020304h ; _Mov8b - ld a,d ; Lspace - ld (de),a - inc de - push de - call 0020FF4h ; _AnsName - call 002050Ch ; _FindSym - ex de,hl - pop de - xor a,4 ; StrngObj - jr nz,.parseansdone - ld c,(hl) - inc hl - ld b,(hl) - jr .parseansnext -.parseansloop: - inc hl - dec bc - push hl - push bc - push de - call 0020870h ; _Get_Tok_Strng - pop de - ld hl,0D0060Eh ; OP3 - ldir - pop bc - pop hl - bit 2,d - jr nz,.parseansdone - ld a,(hl) - call 00204ACh ; _Isa2ByteTok - jr nz,.parseansnext - inc hl - dec bc -.parseansnext: - ld a,c - or a,b - jr nz,.parseansloop -.parseansdone: - ld bc,0 - ld hl,.argstemp - sbc hl,de - add hl,sp - ld sp,hl - ld hl,(_exit.sp) - push bc - db 03Eh ; ld a,* -.argvloop: - push hl - inc bc -.skipspacesloop: - dec de - ld a,(de) - cp a,020h ; Lspace - jr z,.skipspacesloop - dec hl - ld (hl),0 -.argcopyloop: - dec hl - ld (hl),a - dec de - ld a,(de) - cp a,020h ; Lspace - jr z,.argvloop - cp a,0D6h ; lenter - jr nz,.argcopyloop - push hl - sbc hl,hl - add hl,sp - push hl - push bc - call 00205DCh ; _PopRealO1 -end if -if ___len_bss > 0 -if ___len_bss = 1 - xor a,a - ld (___low_bss),a -else if ___len_bss = 2 - ld hl,___low_bss - xor a,a - ld (hl),a - inc hl - ld (hl),a -else if ___len_bss = 3 - or a,a - sbc hl,hl - ld (___low_bss),hl -else - ld hl,___low_bss -if ___len_bss = 8 - call 0020368h ; _Zero16D -else if ___len_bss = 11 - call 0020390h ; _ZeroOP -else if ___len_bss < 256 - ld b,___len_bss - call 0020394h ; _ClrLp -else if ___len_bss = 256 | ___len_bss = 257 - xor a,a - ld b,a -.clearbssloop: - ld (hl),a - inc hl - djnz .clearbssloop -if ___len_bss = 257 - ld (hl),a -end if -else - ld bc,___len_bss - call 00210DCh ; _MemClear -end if -end if -end if - -.init_count := ___init_array_count + ___ctors_count -if .init_count <= 21 - repeat ___init_array_count - load function: long from init_array: (%-1) * long - call function - end repeat - repeat ___ctors_count - load function: long from ctors: (%-1) * long - call function - end repeat -else - ld ix,init_functions - ld b,((.init_count-1) shr 0 and $FF)+1 - if .init_count > $100 - ld c,((.init_count-1) shr 8 and $FF)+1 - if .init_count > $10000 - ld a,((.init_count-1) shr 16 and $FF)+1 - end if - end if -.init_loop: - push bc - if .init_count > $10000 - push af - end if - ld hl,(ix) - lea ix,ix+long - call __indcallhl - if .init_count > $10000 - pop af - end if - pop bc - djnz .init_loop - if .init_count > $100 - dec c - jq nz,.init_loop - if .init_count > $10000 - dec a - jq nz,.init_loop - end if - end if -end if - - -ifextern ___main_argc_argv - call ___main_argc_argv -else - call _main -end if - public __start._main -__start._main := $ - 3 - require ___exithl - - section .fini - public ___exithl -___exithl: -if push_exit_code <> pop_exit_code - push hl -end if -push_exit_code: - require skip._exit - - section .fini -virtual - ld a,0 - load .ld_a: byte from $$ -end virtual - db .ld_a - - public _exit -_exit: - pop hl - - section .fini - private skip._exit -skip._exit: -if defined exit_functions - jq .function_enter -.function_loop: - ld hl,(ix+1+0*long) - ld (exit_functions),hl - pop hl - ld de,(ix+1+2*long) - push hl,de,hl - ld hl,(ix+1+1*long) - push hl,ix+1 - call _free - pop bc,hl - call __indcallhl - pop bc,bc -.function_enter: - ld ix,(exit_functions) - ld bc,-1 - add ix,bc - jq c,.function_loop -end if - -.fini_count := ___dtors_count + ___fini_array_count -if .fini_count <= 21 - repeat ___fini_array_count - load function: long from fini_array: (%%-%) * long - call function - end repeat - repeat ___dtors_count - load function: long from dtors: (%%-%) * long - call function - end repeat -else - ld ix,fini_functions - ld b,((.fini_count-1) shr 0 and $FF)+1 - if .fini_count > $100 - ld c,((.fini_count-1) shr 8 and $FF)+1 - if .fini_count > $10000 - ld a,((.fini_count-1) shr 16 and $FF)+1 - end if - end if -.fini_loop: - push bc - if .fini_count > $10000 - push af - end if - lea ix,ix-long - ld hl,(ix) - call __indcallhl - if .fini_count > $10000 - pop af - end if - pop bc - djnz .fini_loop - if .fini_count > $100 - dec c - jq nz,.fini_loop - if .fini_count > $10000 - dec a - jq nz,.fini_loop - end if - end if -end if - require skip.__Exit - - section .fini -virtual - ld a,0 - load .ld_a: byte from $$ -end virtual - db .ld_a - - public __Exit -__Exit: - pop hl - - section .fini - private skip.__Exit -skip.__Exit: -pop_exit_code: -if push_exit_code <> pop_exit_code - pop hl -end if - require skip._abort - - section .fini -virtual - ld iy,0 - load _abort.iy_pre: byte from $$ -end virtual - db _abort.iy_pre - - public _abort -_abort: - ld hl,1 shl 23+6 ; SIGABRT - - section .fini - private skip._abort -skip._abort: - ld sp,0 - public _exit.sp -_exit.sp := $-3 - push hl - ld iy,0D00080h - ld a,0 - private _exit.flash_wait_states -_exit.flash_wait_states := $-1 - ld (0E00305h),a - call 00004F0h ; _usb_ResetTimer - call _os_EnableHomeTextBuffer - ld a,1 - ld (0F00008h),a ; clear on interrupt - res 4,(iy+9) ; onInterrupt,(iy+onFlags) - set 0,(iy+3) ; graphDraw,(iy+graphFlags) - call 020808h ; _ClrLCDFull - call 020828h ; _HomeUp - call 021A3Ch ; _DrawStatusBar - pop hl ; hl = exit code - ret - - section .init_array -init_array:: - section .ctors -ctors:: - section .dtors -dtors:: - section .fini_array -fini_array:: - - extern _main - extern ___main_argc_argv - extern ___ctors_count - extern ___dtors_count - extern ___fini_array_count - extern ___init_array_count - extern ___len_bss - extern ___libs - extern ___low_bss - extern __indcallhl - extern _free - extern _malloc - extern _os_DisableHomeTextBuffer - extern _os_EnableHomeTextBuffer - extern ___prgm_caller diff --git a/src/crt/ctlz.src b/src/crt/ctlz.src index e9b41285e..85f83ab5c 100644 --- a/src/crt/ctlz.src +++ b/src/crt/ctlz.src @@ -1,52 +1,55 @@ - assume adl=1 + .assume adl=1 + + .section .text.__bctlz + .global __bctlz + .type __bctlz, @function - section .text - public __bctlz __bctlz: cp a, 010h - jr c, .low4 + jr c, .L.low4 cp a, 040h - jr c, .low6 + jr c, .L.low6 add a, a sbc a, a inc a ret -.low6: +.L.low6: add a, -020h sbc a, a add a, 3 ret -.low4: +.L.low4: cp a, 4 - jr c, .low2 + jr c, .L.low2 add a, -8 sbc a, a add a, 5 ret -.low2: +.L.low2: add a, -3 cpl adc a, 6 ret - section .text - public __sctlz + .section .text.__sctlz + .global __sctlz + .type __sctlz, @function + __sctlz: ld a, h or a, a jr nz, __bctlz ld a, l - require __sctlz.hijack - - section .text - private __sctlz.hijack + .local __sctlz.hijack __sctlz.hijack: call __bctlz add a, 8 ret - section .text - public __ictlz + .section .text.__ictlz + .global __ictlz + .type __ictlz, @function + __ictlz: dec sp push hl @@ -61,8 +64,10 @@ __ictlz: add a, 16 ret - section .text - public __lctlz + .section .text.__lctlz + .global __lctlz + .type __lctlz, @function + __lctlz: ld a, e or a, a @@ -71,8 +76,10 @@ __lctlz: add a, 8 ret - section .text - public __llctlz + .section .text.__llctlz + .global __llctlz + .type __llctlz, @function + __llctlz: ld a, b or a, a @@ -83,18 +90,20 @@ __llctlz: add a, 16 ret - section .text - public __i48ctlz + .section .text.__i48ctlz + .global __i48ctlz + .type __i48ctlz, @function + __i48ctlz: ex de, hl add hl, de or a, a sbc hl, de - jr z, .low + jr z, .L.low call __ictlz ex de, hl ret -.low: +.L.low: ex de, hl call __ictlz add a, 24 diff --git a/src/crt/cttz.src b/src/crt/cttz.src index 6e938859f..8f4e051a7 100644 --- a/src/crt/cttz.src +++ b/src/crt/cttz.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 + + .section .text.__bcttz + .global __bcttz + .type __bcttz, @function - section .text - public __bcttz __bcttz: cp a, 1 - require __cttz_common - section .text - private __cttz_common + .section .text.__cttz_common + .local __cttz_common ; Input: A=byte, CF=(A==0) ; Output: A=cttz(A) __cttz_common: @@ -36,31 +37,27 @@ __cttz_common: sbc a, -7 ret - section .text - public __scttz + .section .text.__scttz + .global __scttz + .type __scttz, @function __scttz: xor a, a or a, l jr nz, __cttz_common sub a, h ccf - require __scttz.hijack - - section .text - private __scttz.hijack + .local __scttz.hijack __scttz.hijack: call __cttz_common add a, 8 ret - section .text - public __icttz + .section .text.__icttz + .global __icttz + .type __icttz, @function __icttz: xor a, a - require __icttz.hijack - - section .text - private __icttz.hijack + .local __icttz.hijack __icttz.hijack: or a, l jr nz, __cttz_common @@ -74,8 +71,9 @@ __icttz.hijack: add a, 16 ret - section .text - public __lcttz + .section .text.__lcttz + .global __lcttz + .type __lcttz, @function __lcttz: add hl, de xor a, a @@ -87,8 +85,9 @@ __lcttz: add a, 24 ret - section .text - public __llcttz + .section .text.__llcttz + .global __llcttz + .type __llcttz, @function __llcttz: add hl, de xor a, a @@ -109,18 +108,16 @@ __llcttz: add a, 48 ret - section .text - public __i48cttz + .section .text.__i48cttz + .global __i48cttz + .type __i48cttz, @function __i48cttz: add hl, de xor a, a sbc hl, de jr nz, __icttz.hijack ex de, hl - require __i48cttz.hijack - - section .text - private __i48cttz.hijack + .local __i48cttz.hijack __i48cttz.hijack: call __icttz.hijack ex de, hl diff --git a/src/crt/daddsub.src b/src/crt/daddsub.src index 1ae4d4e30..de1ba6ea6 100644 --- a/src/crt/daddsub.src +++ b/src/crt/daddsub.src @@ -1,8 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __dadd, __dsub + .global __dadd + .type __dadd, @function + .global __dsub + .type __dsub, @function ; float64_t softfloat_addMagsF64(float64_t x, const float64_t *y, bool sign_x) __dadd: @@ -27,20 +30,27 @@ __daddsub: rrc b push iy ; address of y - push bc, de, hl ; pass x by value + push bc + push de + push hl ; pass x by value xor a, (iy + 7) rla - jr nc, .__daddmags ; same signs -; .__dsubmags: + jr nc, .L.__daddmags ; same signs +; .L.__dsubmags: call _softfloat_subMagsF64 - jr .__daddsub_ret -.__daddmags: + jr .L.__daddsub_ret +.L.__daddmags: call _softfloat_addMagsF64 -.__daddsub_ret: - pop af, af, af, af, af - pop iy, af +.L.__daddsub_ret: + pop af + pop af + pop af + pop af + pop af + pop iy + pop af ret - extern _softfloat_addMagsF64, _softfloat_subMagsF64 + .extern _softfloat_addMagsF64, _softfloat_subMagsF64 diff --git a/src/crt/dcmp.src b/src/crt/dcmp.src index ebe89932d..9f6fc60f6 100644 --- a/src/crt/dcmp.src +++ b/src/crt/dcmp.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __dcmp + .global __dcmp + .type __dcmp, @function __dcmp: push iy diff --git a/src/crt/ddiv.src b/src/crt/ddiv.src index ac00b8fb9..0ca3f2ce7 100644 --- a/src/crt/ddiv.src +++ b/src/crt/ddiv.src @@ -1,16 +1,21 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __ddiv + .global __ddiv + .type __ddiv, @function ; float64_t f64_div(bool, float64_t, const float64_t*) __ddiv: - push af, iy + push af + push iy ld iy, 9 add iy, sp - push iy, bc, de, hl + push iy + push bc + push de + push hl ld a, b ; signbit(x) xor a, (iy + 7) ; signbit(y) @@ -19,8 +24,13 @@ __ddiv: call ___f64_div - pop af, af, af, af, af - pop iy, af ; restore + pop af + pop af + pop af + pop af + pop af + pop iy + pop af ; restore ret - extern ___f64_div + .extern ___f64_div diff --git a/src/crt/dmul.src b/src/crt/dmul.src index b38afc0d5..c41bf21e6 100644 --- a/src/crt/dmul.src +++ b/src/crt/dmul.src @@ -1,16 +1,21 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __dmul + .global __dmul + .type __dmul, @function ; float64_t f64_mul(bool, float64_t, const float64_t*) __dmul: - push af, iy + push af + push iy ld iy, 9 add iy, sp - push iy, bc, de, hl + push iy + push bc + push de + push hl ld a, b ; signbit(x) xor a, (iy + 7) ; signbit(y) @@ -19,8 +24,13 @@ __dmul: call ___f64_mul - pop af, af, af, af, af - pop iy, af ; restore + pop af + pop af + pop af + pop af + pop af + pop iy + pop af ; restore ret - extern ___f64_mul + .extern ___f64_mul diff --git a/src/crt/dneg.src b/src/crt/dneg.src index 914428616..2eef9cb9c 100644 --- a/src/crt/dneg.src +++ b/src/crt/dneg.src @@ -1,10 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __dneg + .global __dneg + .type __dneg, @function -; assumes BC:UDE:UHL +; .assumes BC:UDE:UHL __dneg: rl b ccf diff --git a/src/crt/drem.src b/src/crt/drem.src index f58c1cb98..60e0143a9 100644 --- a/src/crt/drem.src +++ b/src/crt/drem.src @@ -1,23 +1,33 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __drem + .global __drem + .type __drem, @function ; float64_t f64_rem(bool, float64_t, const float64_t*) __drem: - push af, iy + push af +push iy ld iy, 9 add iy, sp - push iy, bc, de, hl + push iy + push bc + push de + push hl rl b push af ; Carry = signbit(x) call ___f64_rem - pop af, af, af, af, af - pop iy, af ; restore + pop af + pop af + pop af + pop af + pop af + pop iy + pop af ; restore ret - extern ___f64_rem + .extern ___f64_rem diff --git a/src/crt/dtof.src b/src/crt/dtof.src index 8972fe339..6cfdb2138 100644 --- a/src/crt/dtof.src +++ b/src/crt/dtof.src @@ -1,32 +1,33 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __dtof + .global __dtof + .type __dtof, @function - private __dtof_helper + .local __dtof_helper __dtof_helper: ; Moving this block of code to be behind __dtof ensures that - ; __dtof.ret_copysign can always be reached by jr in all paths. -.overflow: + ; .L.ret_copysign can always be reached by jr in all paths. +.L.overflow: ; carry is set here pop hl ; A = $10 add a, c ; attempts to overflow the low 4 bits of the exponent rl b ; (0x7F << 1) | 1 if the input is inf/NaN inc b ; B will only be zero if the input was inf/NaN - jr nz, .not_inf_nan + jr nz, .L.not_inf_nan ; carry is cleared adc hl, hl - jr nz, .has_payload + jr nz, .L.has_payload ld a, e rla and a, $3F - jr z, .no_payload -.has_payload: + jr z, .L.no_payload +.L.has_payload: set 5, e ; ensure that NaN stays NaN -.no_payload: +.L.no_payload: ld a, c push de pop bc @@ -34,13 +35,13 @@ __dtof_helper: call __lshru push bc pop hl -.finish_inf_nan: +.L.finish_inf_nan: ld a, $7F - jr __dtof.ret_copysign -.not_inf_nan: + jr .L.ret_copysign +.L.not_inf_nan: ; return infinity ld hl, $800000 - jr .finish_inf_nan + jr .L.finish_inf_nan ; Convert BC:UDE:UHL F64 to E:UHL F32 ; Rounding: round to nearest with ties to even @@ -61,11 +62,11 @@ __dtof: res 7, b ld hl, -$3810 add.s hl, bc - jr nc, .maybe_subnormal + jr nc, .L.maybe_subnormal ld hl, -$47F0 ; $FFB810 ld a, l ; ld a, $10 add.s hl, bc - jr c, __dtof_helper.overflow + jr c, .L.overflow ; result is normal or rounds to infinity ; calculate new exponent ; we only need the low 8 bits of the exponent @@ -86,36 +87,36 @@ __dtof: ld b, a ; test round bit bit 4, e - jr z, .round_down + jr z, .L.round_down ; test guard bit ld a, e and a, $20 - jr nz, .round_up + jr nz, .L.round_up ; test sticky bits inc a ; make A non-zero adc hl, hl - jr nz, .round_up + jr nz, .L.round_up ld a, e rla and a, $1F -.round_up: -.round_down: +.L.round_up: +.L.round_down: call __llshru ; B, C, and UDE are zero here or a, a - jr z, .no_round + jr z, .L.no_round inc hl ; does not overflow -.no_round: +.L.no_round: pop af ; a = exponent + 1, flags = 29 = ---5H3V-C sbc a, b ; decrement exponent and clear carry rra - jr nc, .even_exponent + jr nc, .L.even_exponent ld bc, $800000 add hl, bc ; the result might be rounded to infinity here adc a, c ; adc a, 0 ; wont overflow -.even_exponent: -.subnormal_no_round: -.ret_copysign: +.L.even_exponent: +.L.subnormal_no_round: +.L.ret_copysign: pop de ld e, a pop bc @@ -124,17 +125,17 @@ __dtof: set 7, e ret -.ret_zero: +.L.ret_zero: ; carry is cleared pop hl xor a, a sbc hl, hl - jr .ret_copysign + jr .L.ret_copysign -.maybe_subnormal: +.L.maybe_subnormal: ld hl, -$3690 add.s hl, bc - jr nc, .ret_zero + jr nc, .L.ret_zero ; calculate shift ; A = (uint8_t)((BC - $3690) >> 4) ; A = (uint8_t)((HL << 4) >> 8) @@ -153,17 +154,17 @@ __dtof: ; calculate sticky bits sbc hl, hl inc hl ; ld hl, 1 -.shift_loop: +.L.shift_loop: add hl, hl adc a, a - djnz .shift_loop + djnz .L.shift_loop ; carry won't be set ; set C:UDE to A:UHL ; shift by an additional 24 bits dec hl - jr z, .the_set_bit_is_in_hl + jr z, .L.the_set_bit_is_in_hl dec a -.the_set_bit_is_in_hl: +.L.the_set_bit_is_in_hl: ld c, a ld a, e ; restore shift amount ex de, hl @@ -182,9 +183,9 @@ __dtof: ; clear exponent and include the implicit mantissa bit ld d, 0 - jr z, .no_sticky_bits + jr z, .L.no_sticky_bits inc d -.no_sticky_bits: +.L.no_sticky_bits: ld l, a ; L = shift ld a, e @@ -203,17 +204,17 @@ __dtof: rr h rr l ; round bit shifted out - jr nc, .subnormal_no_round + jr nc, .L.subnormal_no_round dec d - jr z, .subnormal_round_up + jr z, .L.subnormal_round_up bit 0, l - jr z, .subnormal_no_round -.subnormal_round_up: + jr z, .L.subnormal_no_round +.L.subnormal_round_up: inc hl ; wont overflow, but may become FLT_MIN -; .subnormal_no_round: - jr .ret_copysign +; .L.subnormal_no_round: + jr .L.ret_copysign - extern __lland - extern __llcmpzero - extern __llshru - extern __lshru + .extern __lland + .extern __llcmpzero + .extern __llshru + .extern __lshru diff --git a/src/crt/dtol.src b/src/crt/dtol.src index 853666e71..9e5b56a41 100644 --- a/src/crt/dtol.src +++ b/src/crt/dtol.src @@ -1,9 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __dtol - public __dtoul + .global __dtol + .type __dtol, @function + .global __dtoul + .type __dtoul, @function ; correctly handles all non-UB cases for both ; (long)long double and (unsigned long)long double @@ -18,4 +20,4 @@ __dtoul: pop bc ret - extern __dtoll + .extern __dtoll diff --git a/src/crt/dtoll.src b/src/crt/dtoll.src index 83b04bd67..202d29d6b 100644 --- a/src/crt/dtoll.src +++ b/src/crt/dtoll.src @@ -1,9 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __dtoll - public __dtoull + .global __dtoll + .type __dtoll, @function + .global __dtoull + .type __dtoull, @function ; correctly handles all non-UB cases for both ; (long long)long double and (unsigned long long)long double @@ -79,6 +81,6 @@ __dtoull: ex.s de, hl jr .finish_zero_or_one - extern __llneg - extern __llshl - extern __llshru + .extern __llneg + .extern __llshl + .extern __llshru diff --git a/src/crt/errno.src b/src/crt/errno.src new file mode 100644 index 000000000..d6920c514 --- /dev/null +++ b/src/crt/errno.src @@ -0,0 +1,4 @@ + .assume adl = 1 + + .global _errno + .equ _errno, 0xD008DC diff --git a/src/crt/fpneg.src b/src/crt/fpneg.src index 611183c08..58ad8e32f 100644 --- a/src/crt/fpneg.src +++ b/src/crt/fpneg.src @@ -16,10 +16,12 @@ ; AuBC: 32-bit IEEE Single Precision. ; ;-------------------------------------------------------------- - assume adl=1 + .assume adl=1 + + .section .text + .global __fneg + .type __fneg, @function - section .text - public __fneg __fneg: or a,a jr nz,__noexit diff --git a/src/crt/fpupop1.src b/src/crt/fpupop1.src index 5f4901b7f..bf9f4b09b 100644 --- a/src/crt/fpupop1.src +++ b/src/crt/fpupop1.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __fpupop1 + .type __fpupop1, @function - section .text - public __fpupop1 __fpupop1: push ix ld ix, 0 diff --git a/src/crt/fpupop2.src b/src/crt/fpupop2.src index 7e71637c3..4837b3027 100644 --- a/src/crt/fpupop2.src +++ b/src/crt/fpupop2.src @@ -1,22 +1,24 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __fpupop2 + .type __fpupop2, @function - section .text - public __fpupop2 __fpupop2: push bc ld bc, 0800000h add hl, bc - jr nc, ncarry + jr nc, .ncarry add hl, bc scf -ncarry: +.ncarry: ld d, c pop bc rl e - jr nz, nzero + jr nz, .nzero or a, a sbc hl, hl -nzero: +.nzero: rl d inc e dec e diff --git a/src/crt/frameset.src b/src/crt/frameset.src index a984ace0a..0c811abd6 100644 --- a/src/crt/frameset.src +++ b/src/crt/frameset.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __frameset + .type __frameset, @function - section .text - public __frameset __frameset: pop de push ix diff --git a/src/crt/frameset0.src b/src/crt/frameset0.src index fdc1e73df..37a9646ac 100644 --- a/src/crt/frameset0.src +++ b/src/crt/frameset0.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __frameset0 + .type __frameset0, @function - section .text - public __frameset0 __frameset0: pop hl push ix diff --git a/src/crt/frbmuls.src b/src/crt/frbmuls.src index 3a5ba7bf8..33f6c42ee 100644 --- a/src/crt/frbmuls.src +++ b/src/crt/frbmuls.src @@ -14,10 +14,12 @@ ; Registers Used: ; none ;------------------------------------------------------------------------- - assume adl=1 + .assume adl=1 + + .section .text + .global __frbmuls + .type __frbmuls, @function - section .text - public __frbmuls __frbmuls: push hl ;; @@ -51,4 +53,3 @@ _L1: _L2: pop af ret - diff --git a/src/crt/frem.src b/src/crt/frem.src index b5dfb6808..f383fe77b 100644 --- a/src/crt/frem.src +++ b/src/crt/frem.src @@ -1,23 +1,32 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __frem + .global __frem + .type __frem, @function ; wraps _fmodf __frem: - push iy, de, hl + push iy + push de + push hl - push de, hl ; y + push de + push hl ; y ld e, a push de ; x_hi8 push bc ; x_lo24 call _fmodf - pop bc, bc, bc, bc + pop bc + pop bc + pop bc + pop bc ld a, e ex (sp), hl - pop bc, de, iy + pop bc + pop de + pop iy ret - extern _fmodf + .extern _fmodf diff --git a/src/crt/frimuls.src b/src/crt/frimuls.src index 800c38df3..b208b34f8 100644 --- a/src/crt/frimuls.src +++ b/src/crt/frimuls.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __frimuls + .type __frimuls, @function - section .text - public __frimuls __frimuls: push af push de @@ -65,4 +67,4 @@ _L2: pop af ret - extern __frimulu + .extern __frimulu diff --git a/src/crt/frimulu.src b/src/crt/frimulu.src index 021730040..514bf9d0e 100644 --- a/src/crt/frimulu.src +++ b/src/crt/frimulu.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __frimulu + .type __frimulu, @function - section .text - public __frimulu __frimulu: push af push de diff --git a/src/crt/frsmuls.src b/src/crt/frsmuls.src index 22da523df..ae60c4e7e 100644 --- a/src/crt/frsmuls.src +++ b/src/crt/frsmuls.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __frsmuls + .type __frsmuls, @function - section .text - public __frsmuls __frsmuls: push af push de @@ -43,4 +45,4 @@ _L2: pop af ret - extern __frsmulu + .extern __frsmulu diff --git a/src/crt/frsmulu.src b/src/crt/frsmulu.src index 6c1c15b85..4e1130078 100644 --- a/src/crt/frsmulu.src +++ b/src/crt/frsmulu.src @@ -14,10 +14,12 @@ ; Registers Used: ; none ;------------------------------------------------------------------------- - assume adl=1 + .assume adl=1 + + .section .text + .global __frsmulu + .type __frsmulu, @function - section .text - public __frsmulu __frsmulu: push af push de diff --git a/src/crt/ftod.src b/src/crt/ftod.src index 5d08ece5e..81f08be70 100644 --- a/src/crt/ftod.src +++ b/src/crt/ftod.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __ftod + .global __ftod + .type __ftod, @function ; input E:UHL (float) ; ouput BC:UDE:UHL (long double) @@ -17,16 +18,16 @@ __ftod: ld b, $03 ; ld bc, $380 - 1 adc hl, hl - jr z, .mant_zero ; zero inf or normal + jr z, .L.mant_zero ; zero inf or normal adc a, a - jr z, .subnormal + jr z, .L.subnormal inc a - jr z, .nan -.normal: + jr z, .L.nan +.L.normal: ; (Float64_bias - Float32_bias) - 1 (undoing inc a) ; (Float64_bias - Float32_bias) = $0380 add a, $80 - 1 ; this can be changed to adc if needed -.subnorm_shift: +.L.subnorm_shift: ; Same as ld c, a \ ld a, 0 \ adc a, b ld c, a adc a, b @@ -34,40 +35,40 @@ __ftod: ; HL = mant ; C = lo expon ; A = hi expon -.shift_28: ; Float64_mant_bits - Float32_mant_bits +.L.shift_28: ; Float64_mant_bits - Float32_mant_bits inc b ; ld b, 4 -.loop: +.L.loop: add hl, hl rl c rla - djnz .loop -.zero: ; <-- A is zero on this path + djnz .L.loop +.L.zero: ; <-- A is zero on this path ld b, a ; zero low bits -.infinite: +.L.infinite: ; or a, a ; not needed ; f64_mant_bits - f32_mant_bits = lowest 29 bits will be zero ex de, hl sbc hl, hl -.finish: +.L.finish: pop af ret nc ; positive set 7, b ret ; negative -.mant_zero: +.L.mant_zero: adc a, a ld c, l ; HL is zero here - jr z, .zero + jr z, .L.zero inc a - jr nz, .normal + jr nz, .L.normal ; infinite ld c, $F0 ld b, e ; ld b, $7F since infinity is all ones - jr .infinite + jr .L.infinite -.subnormal: +.L.subnormal: ; since this is subnormal, the LSB of the exponent is already zero call __ictlz ld c, a @@ -77,25 +78,27 @@ __ftod: ; expon = (Float64_bias - Float32_bias) - clz_result add hl, hl ; the following three methods are equivilient -if 1 +.if 1 ; ($FF - a) - $7F cpl sub a, $80 - 1 -else if 0 +.else +.if 0 ; $FF - (a + $7F) add a, $80 - 1 cpl -else +.else ; $80 - c (c is equal to a) ld a, $80 sub a, c -end if - jr .subnorm_shift +.endif +.endif + jr .L.subnorm_shift -.nan: +.L.nan: ld a, $07 ld c, $FF - jr .shift_28 + jr .L.shift_28 - extern __ictlz - extern __ishl \ No newline at end of file + .extern __ictlz + .extern __ishl diff --git a/src/crt/ftoll.src b/src/crt/ftoll.src index cc4f8a961..5201fddab 100644 --- a/src/crt/ftoll.src +++ b/src/crt/ftoll.src @@ -1,18 +1,24 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __ftoll - public __ftoull + .global __ftoll + .type __ftoll, @function + .global __ftoull + .type __ftoull, @function ; __ftoll_c correctly handles all non-UB cases for both ; (long long)float and (unsigned long long)float __ftoll: __ftoull: ld d, a - push iy, de, hl + push iy +push de +push hl call __ftoll_c - pop af, af, iy + pop af +pop af +pop iy ret - extern __ftoll_c + .extern __ftoll_c diff --git a/src/crt/i48add.src b/src/crt/i48add.src index b25c3b2b7..2381e7a9c 100644 --- a/src/crt/i48add.src +++ b/src/crt/i48add.src @@ -3,16 +3,18 @@ ; Returns: ; ude:uhl = ude:uhl + uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48add + .type __i48add, @function - section .text - public __i48add __i48add: ; CC: 11 bytes | 12F + 6R + 3W + 1 add hl, bc ex de, hl push bc - lea bc, iy + lea bc, iy + 0 adc hl, bc pop bc ex de, hl diff --git a/src/crt/i48add_1.src b/src/crt/i48add_1.src index fd8bfbc95..d562a5ad0 100644 --- a/src/crt/i48add_1.src +++ b/src/crt/i48add_1.src @@ -3,11 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl + 1 - assume adl=1 + .assume adl=1 - section .text + .section .text + .global __i48add_1 + .type __i48add_1, @function - public __i48add_1 __i48add_1: ; CC: 8 bytes ; HL != -1: 7F + 3R + 2 diff --git a/src/crt/i48and.src b/src/crt/i48and.src index 9228a5abe..c1b3da5ff 100644 --- a/src/crt/i48and.src +++ b/src/crt/i48and.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl & uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48and + .type __i48and, @function - section .text - public __i48and __i48and: ; CC: 41 bytes | 42F + 22R + 17W + 1 push af diff --git a/src/crt/i48bitrev.src b/src/crt/i48bitrev.src index 8a9d8abf5..5320e92a6 100644 --- a/src/crt/i48bitrev.src +++ b/src/crt/i48bitrev.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl bits reversed - assume adl=1 + .assume adl=1 + + .section .text + .global __i48bitrev + .type __i48bitrev, @function - section .text - public __i48bitrev __i48bitrev: push af ld a, l ; a=L @@ -27,4 +29,4 @@ __i48bitrev: pop af ret - extern __internal_bitrev_two_bytes + .extern __internal_bitrev_two_bytes diff --git a/src/crt/i48bswap.src b/src/crt/i48bswap.src index 3b85fd0b8..2146bcb40 100644 --- a/src/crt/i48bswap.src +++ b/src/crt/i48bswap.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl with order of bytes reversed - assume adl=1 + .assume adl=1 + + .section .text + .global __i48bswap + .type __i48bswap, @function - section .text - public __i48bswap __i48bswap: ; CC: 14 bytes | 15F + 12R + 12W + 1 ; Line up the reversed data on the stack diff --git a/src/crt/i48cmps.src b/src/crt/i48cmps.src index 0d4bbbd84..56065b940 100644 --- a/src/crt/i48cmps.src +++ b/src/crt/i48cmps.src @@ -7,10 +7,12 @@ ; Returns: ; S and V flags updated according to comparison - assume adl=1 + .assume adl=1 + + .section .text + .global __i48cmps + .type __i48cmps, @function - section .text - public __i48cmps __i48cmps: ; CC: 14 bytes | 15F + 9R + 6W + 1 push hl @@ -18,7 +20,7 @@ __i48cmps: or a, a sbc hl, bc ; compare hl to bc ex de, hl ; hl = de - lea de, iy ; de = iy + lea de, iy + 0 ; de = iy sbc hl, de ; compare de to iy pop de pop hl diff --git a/src/crt/i48cmpu.src b/src/crt/i48cmpu.src index 179d1d39d..5a19bb776 100644 --- a/src/crt/i48cmpu.src +++ b/src/crt/i48cmpu.src @@ -7,17 +7,19 @@ ; Returns: ; Z and C flags updated according to comparison - assume adl=1 + .assume adl=1 + + .section .text + .global __i48cmpu + .type __i48cmpu, @function - section .text - public __i48cmpu __i48cmpu: ; CC: 15 bytes ; Minimum: 11F + 6R + 3W + 2 ; Maximum: 16F + 6R + 3W + 2 push hl or a, a - lea hl, iy + lea hl, iy + 0 sbc hl, de ; subtract IY - DE, which is the other way around ccf ; complement carry pop hl diff --git a/src/crt/i48cmpzero.src b/src/crt/i48cmpzero.src index 16d3f551b..662aea245 100644 --- a/src/crt/i48cmpzero.src +++ b/src/crt/i48cmpzero.src @@ -3,10 +3,12 @@ ; Returns: ; z status flag set if ude:uhl == 0, s status flag set if ude:uhl is negative - assume adl=1 + .assume adl=1 + + .section .text + .global __i48cmpzero + .type __i48cmpzero, @function - section .text - public __i48cmpzero __i48cmpzero: ; CC: 13 bytes ; Minimum: 8F + 3R + 2 diff --git a/src/crt/i48divs.src b/src/crt/i48divs.src index fa43817e2..9230be9c4 100644 --- a/src/crt/i48divs.src +++ b/src/crt/i48divs.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl / uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48divs + .type __i48divs, @function - section .text - public __i48divs __i48divs: push af push iy @@ -14,7 +16,7 @@ __i48divs: ; divisor sign check push hl - lea hl, iy + lea hl, iy + 0 add hl, hl sbc a, a call c, __uiyubcNeg @@ -38,6 +40,6 @@ __i48divs: pop af ret - extern __i48dvrmu - extern __i48neg - extern __uiyubcNeg + .extern __i48dvrmu + .extern __i48neg + .extern __uiyubcNeg diff --git a/src/crt/i48divu.src b/src/crt/i48divu.src index bad60578b..55ca25319 100644 --- a/src/crt/i48divu.src +++ b/src/crt/i48divu.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl / uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48divu + .type __i48divu, @function - section .text - public __i48divu __i48divu: push iy push bc @@ -17,4 +19,4 @@ __i48divu: pop iy ret - extern __i48dvrmu + .extern __i48dvrmu diff --git a/src/crt/i48dvrmu.src b/src/crt/i48dvrmu.src index 5156b9dff..26370d557 100644 --- a/src/crt/i48dvrmu.src +++ b/src/crt/i48dvrmu.src @@ -7,10 +7,11 @@ ; Returns (loaded into other registers by i48divu/s and i48remu/s): ; ude:uhl quotient, uiy:ubc remainder - assume adl=1 + .assume adl=1 - section .text - public __i48dvrmu + .section .text + .global __i48dvrmu + .type __i48dvrmu, @function __i48dvrmu: ; backup af @@ -35,7 +36,7 @@ __i48dvrmu: sbc hl, hl ; uhl = low remainder exx pop bc ; ubc' = dividend/quotient pointer - lea de, iy ; ude' = iy = high divisor + lea de, iy + 0 ; ude' = iy = high divisor sbc hl, hl ; uhl' = high remainder .byteLoop: dec bc diff --git a/src/crt/i48mulu.src b/src/crt/i48mulu.src index 88c453072..076c7f759 100644 --- a/src/crt/i48mulu.src +++ b/src/crt/i48mulu.src @@ -7,10 +7,12 @@ ; Returns: ; ude:uhl = ude:uhl * uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48mulu + .type __i48mulu, @function - section .text - public __i48mulu __i48mulu: ; CC: 202*r(PC)+51*r(SPL)+35*w(SPL)+85 ; CC: 201 bytes | 202F + 51R + 35W + 85 diff --git a/src/crt/i48neg.src b/src/crt/i48neg.src index c1a7a5cbc..277e2ede3 100644 --- a/src/crt/i48neg.src +++ b/src/crt/i48neg.src @@ -3,10 +3,14 @@ ; Returns: ; ude:uhl = -ude:uhl - assume adl=1 + .assume adl=1 + + .section .text + .global __i48neg + .type __i48neg, @function + .global __uiyubcNeg + .type __uiyubcNeg, @function - section .text - public __i48neg __i48neg: ; CC: 17 bytes ; HL != 0: 18F + 3R + 2 @@ -28,7 +32,6 @@ __i48neg: ret ; Used by i48divs and i48rems, uiy:ubc = -uiy:ubc - public __uiyubcNeg __uiyubcNeg: ; CC: 18 bytes | 19F + 12R + 9W + 1 push hl @@ -37,7 +40,7 @@ __uiyubcNeg: sbc hl, bc ; hl = 0 - BC = -BC push hl add hl, bc ; hl = 0, causes the same carry - lea bc, iy + lea bc, iy + 0 sbc hl, bc ; hl = 0 - IY - c pop bc ; bc = -BC ex (sp), hl ; hl = HL diff --git a/src/crt/i48not.src b/src/crt/i48not.src index dfac237c1..94cb8d313 100644 --- a/src/crt/i48not.src +++ b/src/crt/i48not.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ~ude:uhl - assume adl=1 + .assume adl=1 + + .section .text + .global __i48not + .type __i48not, @function - section .text - public __i48not __i48not: ; CC: 15 bytes | 16F + 3R + 1 add hl, de ; hl = HL + DE diff --git a/src/crt/i48or.src b/src/crt/i48or.src index d2c25fd62..a27a891b7 100644 --- a/src/crt/i48or.src +++ b/src/crt/i48or.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl | uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48or + .type __i48or, @function - section .text - public __i48or __i48or: ; CC: 41 bytes | 42F + 22R + 17W + 1 push af diff --git a/src/crt/i48popcnt.src b/src/crt/i48popcnt.src index 88ef05d4f..413c4d1b6 100644 --- a/src/crt/i48popcnt.src +++ b/src/crt/i48popcnt.src @@ -3,10 +3,12 @@ ; Returns: ; a = number of set bits in ude:uhl - assume adl=1 + .assume adl=1 + + .section .text + .global __i48popcnt + .type __i48popcnt, @function - section .text - public __i48popcnt __i48popcnt: push hl push de @@ -36,4 +38,4 @@ __i48popcnt: pop hl ret - extern __popcnt_common_init_full, __popcnt_common_iter_adjusted + .extern __popcnt_common_init_full, __popcnt_common_iter_adjusted diff --git a/src/crt/i48rems.src b/src/crt/i48rems.src index 3e44c2081..657843653 100644 --- a/src/crt/i48rems.src +++ b/src/crt/i48rems.src @@ -3,17 +3,19 @@ ; Returns: ; ude:uhl = ude:uhl % uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48rems + .type __i48rems, @function - section .text - public __i48rems __i48rems: push iy push bc ; divisor sign check push hl - lea hl, iy + lea hl, iy + 0 add hl, hl call c, __uiyubcNeg @@ -26,7 +28,7 @@ __i48rems: pop af call __i48dvrmu - lea de, iy + lea de, iy + 0 push bc pop hl @@ -37,6 +39,6 @@ __i48rems: ; negate remainder if dividend was negative jp __i48neg - extern __i48dvrmu - extern __i48neg - extern __uiyubcNeg + .extern __i48dvrmu + .extern __i48neg + .extern __uiyubcNeg diff --git a/src/crt/i48remu.src b/src/crt/i48remu.src index 2951940a6..3fa5a4045 100644 --- a/src/crt/i48remu.src +++ b/src/crt/i48remu.src @@ -3,16 +3,18 @@ ; Returns: ; ude:uhl = ude:uhl % uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48remu + .type __i48remu, @function - section .text - public __i48remu __i48remu: push iy push bc call __i48dvrmu - lea de, iy + lea de, iy + 0 or a, a sbc hl, hl add hl, bc @@ -21,4 +23,4 @@ __i48remu: pop iy ret - extern __i48dvrmu + .extern __i48dvrmu diff --git a/src/crt/i48shl.src b/src/crt/i48shl.src index 1cd761dcf..5ae71cadb 100644 --- a/src/crt/i48shl.src +++ b/src/crt/i48shl.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl<>c - assume adl=1 + .assume adl=1 + + .section .text + .global __i48shrs + .type __i48shrs, @function + .global __i48shru + .type __i48shru, @function - section .text - public __i48shrs __i48shrs: inc c dec c ret z cp a, a ; Set Z flag db $C2 ; inc c \ dec c \ ret z -> jp nz, * - require __i48shru - - section .text - public __i48shru __i48shru: inc c dec c diff --git a/src/crt/i48sub.src b/src/crt/i48sub.src index 89ecf381f..9c77968d5 100644 --- a/src/crt/i48sub.src +++ b/src/crt/i48sub.src @@ -3,17 +3,19 @@ ; Returns: ; ude:uhl = ude:uhl - uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48sub + .type __i48sub, @function - section .text - public __i48sub __i48sub: ; CC: 13 bytes | 14F + 6R + 3W + 1 or a, a sbc hl, bc ex de, hl push bc - lea bc, iy + lea bc, iy + 0 sbc hl, bc pop bc ex de, hl diff --git a/src/crt/i48sub_1.src b/src/crt/i48sub_1.src index 23ecec17e..970c61843 100644 --- a/src/crt/i48sub_1.src +++ b/src/crt/i48sub_1.src @@ -3,11 +3,13 @@ ; Returns: ; ude:uhl = ude:uhl - 1 - assume adl=1 + .assume adl=1 - section .text + .section .text + + .global __i48sub_1 + .type __i48sub_1, @function - public __i48sub_1 __i48sub_1: ; CC: 8 bytes ; HL != 0: 7F + 3R + 2 diff --git a/src/crt/i48xor.src b/src/crt/i48xor.src index 573adc008..fe9485078 100644 --- a/src/crt/i48xor.src +++ b/src/crt/i48xor.src @@ -3,10 +3,12 @@ ; Returns: ; ude:uhl = ude:uhl ^ uiy:ubc - assume adl=1 + .assume adl=1 + + .section .text + .global __i48xor + .type __i48xor, @function - section .text - public __i48xor __i48xor: ; CC: 41 bytes | 42F + 22R + 17W + 1 push af diff --git a/src/crt/ibitrev.src b/src/crt/ibitrev.src index 6ba500f90..0fe6867dc 100644 --- a/src/crt/ibitrev.src +++ b/src/crt/ibitrev.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ibitrev + .type __ibitrev, @function - section .text - public __ibitrev __ibitrev: push af ld a, l ; a=L @@ -14,4 +16,4 @@ __ibitrev: pop af ret - extern __internal_bitrev_two_bytes + .extern __internal_bitrev_two_bytes diff --git a/src/crt/ibitrev_fast.src b/src/crt/ibitrev_fast.src index dc0f6d7c0..82271c663 100644 --- a/src/crt/ibitrev_fast.src +++ b/src/crt/ibitrev_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ibitrev_fast + .type __ibitrev_fast, @function - section .text - public __ibitrev_fast __ibitrev_fast: ld a, l rra diff --git a/src/crt/icmpzero.src b/src/crt/icmpzero.src index 286355bf0..f475e4759 100644 --- a/src/crt/icmpzero.src +++ b/src/crt/icmpzero.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __icmpzero + .type __icmpzero, @function - section .text - public __icmpzero __icmpzero: add hl, de or a, a diff --git a/src/crt/idivs.src b/src/crt/idivs.src index ce4e33971..8cb6f9e48 100644 --- a/src/crt/idivs.src +++ b/src/crt/idivs.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __idivs + .section .text + .global __idivs + .type __idivs, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__idivs := 00013Ch + .set __idivs, 0x00013C -else +.else __idivs: ; I: UHL=dividend, UBC=divisor @@ -21,6 +22,6 @@ __idivs: ret - extern __idvrms + .extern __idvrms -end if +.endif diff --git a/src/crt/idivu.src b/src/crt/idivu.src index 8d97c331e..c18afc0e8 100644 --- a/src/crt/idivu.src +++ b/src/crt/idivu.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __idivu + .section .text + .global __idivu + .type __idivu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__idivu := 000140h + .set __idivu, 0x000140 -else +.else __idivu: ; I: UHL=dividend, UBC=divisor @@ -22,6 +23,6 @@ __idivu: ret - extern __idvrmu + .extern __idvrmu -end if +.endif diff --git a/src/crt/idvrms.src b/src/crt/idvrms.src index b7399cf36..c1c4e0e11 100644 --- a/src/crt/idvrms.src +++ b/src/crt/idvrms.src @@ -1,7 +1,8 @@ - assume adl=1 + .assume adl=1 - section .text - public __idvrms + .section .text + .global __idvrms + .type __idvrms, @function __idvrms: ; I: UHL=dividend, UBC=divisor @@ -16,20 +17,20 @@ __idvrms: ccf sbc hl, bc inc hl - jp m, .neg_divisor_skip + jp m, .L.neg_divisor_skip cpl push hl pop bc -.neg_divisor_skip: +.L.neg_divisor_skip: sbc hl, hl ccf sbc hl, de inc hl - jp p, .pos_dividend_skip + jp p, .L.pos_dividend_skip cpl ex de, hl -.pos_dividend_skip: +.L.pos_dividend_skip: call __idvrmu @@ -43,5 +44,5 @@ __idvrms: ret nz jp __ineg - extern __idvrmu - extern __ineg + .extern __idvrmu + .extern __ineg diff --git a/src/crt/idvrmu.src b/src/crt/idvrmu.src index 429b519b2..651150e38 100644 --- a/src/crt/idvrmu.src +++ b/src/crt/idvrmu.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __idvrmu + .section .text + .global __idvrmu + .type __idvrmu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__idvrmu := 000144h + .set __idvrmu, 0x000144 -else +.else __idvrmu: ; I: UHL=dividend, UBC=divisor @@ -17,13 +18,14 @@ __idvrmu: push af ld a, 24 - public __idvrmu.hijack_a_iters_ude_dividend -.hijack_a_iters_ude_dividend: + .global __idvrmu.hijack_a_iters_ude_dividend + .type __idvrmu.hijack_a_iters_ude_dividend, @function +__idvrmu.hijack_a_iters_ude_dividend: or a, a sbc hl, hl -.loop: +.L.loop: ex de, hl add hl, hl ex de, hl @@ -32,15 +34,15 @@ __idvrmu: sbc hl, bc inc e - jr nc, .restore_skip + jr nc, .L.restore_skip add hl, bc dec e -.restore_skip: +.L.restore_skip: dec a - jr nz, .loop + jr nz, .L.loop pop af ret -end if +.endif diff --git a/src/crt/imulu.src b/src/crt/imulu.src index c12282a91..941f97686 100644 --- a/src/crt/imulu.src +++ b/src/crt/imulu.src @@ -1,14 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public __imuls, __imulu + .section .text + .global __imuls + .type __imuls, @function + .global __imulu + .type __imulu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__imuls := 000154h -__imulu := 000158h + .set __imuls, 0x000154 + .set __imulu, 0x000158 -else +.else __imuls: __imulu: @@ -67,4 +70,4 @@ Mul_UHL_UBC_UHL: ;--------------+---------------+---------------+-------------- ; (UHL*UBC)&0xFFFFFF=L*C+(H*C+L*B<<8)+(HLU*C+H*B+L*BCU<<16)+(HLU*B+H*BCU<<24)+(HLU*BCU<<32)&0xFFFFFF ; =L*C+(H*C+L*B<<8)+(HLU*C+H*B+L*BCU<<16)&0xFFFFFF -end if +.endif diff --git a/src/crt/imulu_b.src b/src/crt/imulu_b.src index 47d232c7e..495512537 100644 --- a/src/crt/imulu_b.src +++ b/src/crt/imulu_b.src @@ -1,16 +1,18 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __imul_b - public __imulu_b + .global __imul_b + .type __imul_b, @function + .global __imulu_b + .type __imulu_b, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__imul_b := 000150h -__imulu_b := __imul_b + .set __imul_b, 0x000150 + .set __imulu_b, __imul_b -else +.else __imul_b: __imulu_b: @@ -20,7 +22,7 @@ __imulu_b: ; O: uhl=UHL*A ; CC: 32*r(PC)+12*r(SPL)+9*w(SPL)+13 ; CC: 31 bytes | 32F + 12R + 9W + 13 -Mul_UHL_A_UHL: +.L.Mul_UHL_A_UHL: push de push af ; preserve A @@ -63,4 +65,4 @@ Mul_UHL_A_UHL: pop de ret -end if +.endif diff --git a/src/crt/imulu_b_fast.src b/src/crt/imulu_b_fast.src index 36572b284..af68621a0 100644 --- a/src/crt/imulu_b_fast.src +++ b/src/crt/imulu_b_fast.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __imulu_b_fast + .global __imulu_b_fast + .type __imulu_b_fast, @function __imulu_b_fast: @@ -11,7 +12,7 @@ __imulu_b_fast: ; O: uhl=UHL*A ; CC: 28*r(PC)+9*r(SPL)+6*w(SPL)+13 ; CC: 27 bytes | 28F + 9R + 6W + 13 -Mul_UHL_A_UHL_Fast: +.L.Mul_UHL_A_UHL_Fast: dec sp push hl inc sp diff --git a/src/crt/imulu_fast.src b/src/crt/imulu_fast.src index cd015c232..2fe66d830 100644 --- a/src/crt/imulu_fast.src +++ b/src/crt/imulu_fast.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __imuls_fast + .type __imuls_fast, @function + .global __imulu_fast + .type __imulu_fast, @function - section .text - public __imuls_fast, __imulu_fast __imuls_fast: __imulu_fast: @@ -11,7 +15,7 @@ __imulu_fast: ; FO: sz(a), vc((UHL*UBC-L*C&0xFFFFFF)+L*C) ; CC: 43*r(PC)+9*r(SPL)+6*w(SPL)+25 ; ; a ubc ude uhl u(sp) -Mul_UHL_UBC_UHL_Fast: ;--------------+---------------+---------------+---------------+------------------------ +.L.Mul_UHL_UBC_UHL_Fast: ;--------------+---------------+---------------+---------------+------------------------ ld d, b ld e, h ; de=BH mlt de ; ude=H*B diff --git a/src/crt/indcallhl.src b/src/crt/indcallhl.src index dec402990..ee2f53a61 100644 --- a/src/crt/indcallhl.src +++ b/src/crt/indcallhl.src @@ -1,6 +1,8 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __indcallhl + .type __indcallhl, @function - section .text - public __indcallhl __indcallhl: jp (hl) diff --git a/src/crt/ineg.src b/src/crt/ineg.src index 227f77985..e5903b1b3 100644 --- a/src/crt/ineg.src +++ b/src/crt/ineg.src @@ -1,13 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public __ineg + .section .text + .global __ineg + .type __ineg, @function + .global __sneg + .type __sneg, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__ineg := 000160h + .set __ineg, 0x000160 + .set __sneg, 0x00022C -else +.else __ineg: ; UHL = -UHL @@ -25,4 +29,6 @@ __ineg: ex de, hl ; ude=UDE, uhl=-UHL ret -end if + .set __sneg, __ineg + +.endif diff --git a/src/crt/ineg_fast.src b/src/crt/ineg_fast.src index 213c16368..a635a9a30 100644 --- a/src/crt/ineg_fast.src +++ b/src/crt/ineg_fast.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ineg_fast + .type __ineg_fast, @function + .global __sneg_fast + .type __sneg_fast, @function - section .text - public __ineg_fast __ineg_fast: ; UHL = -UHL ; CC: 7*r(PC)+3*r(SPL)+1 @@ -13,3 +17,5 @@ __ineg_fast: ; =UDE-UHL-UDE ; =-UHL ret + + .set __sneg_fast, __ineg_fast diff --git a/src/crt/inot.src b/src/crt/inot.src index bba21948d..fa5d03046 100644 --- a/src/crt/inot.src +++ b/src/crt/inot.src @@ -1,13 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public __inot + .section .text + .global __inot + .type __inot, @function + .global __snot + .type __snot, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__inot := 000164h + .set __inot, 0x000164 + .set __snot, 0x000230 -else +.else __inot: ; UHL = ~UHL @@ -29,4 +33,6 @@ __inot: ex de, hl ; ude=UDE, uhl=~UHL ret -end if + .set __snot, __inot + +.endif diff --git a/src/crt/inot_fast.src b/src/crt/inot_fast.src index de2458c33..cd87ce168 100644 --- a/src/crt/inot_fast.src +++ b/src/crt/inot_fast.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __inot_fast + .type __inot_fast, @function + .global __snot_fast + .type __snot_fast, @function - section .text - public __inot_fast __inot_fast: ; UHL = ~UHL ; CC: 7*r(PC)+3*r(SPL)+1 @@ -14,3 +18,5 @@ __inot_fast: ; =-UHL-1 ; =~UHL ret + + .set __snot_fast, __inot_fast diff --git a/src/crt/internal_bitrev_byte.src b/src/crt/internal_bitrev_byte.src index 470652b07..4db46df59 100644 --- a/src/crt/internal_bitrev_byte.src +++ b/src/crt/internal_bitrev_byte.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __internal_bitrev_two_bytes + .type __internal_bitrev_two_bytes, @function - section .text - public __internal_bitrev_two_bytes __internal_bitrev_two_bytes: rra adc hl, hl diff --git a/src/crt/ipopcnt.src b/src/crt/ipopcnt.src index 5ec3fbf09..57e009097 100644 --- a/src/crt/ipopcnt.src +++ b/src/crt/ipopcnt.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ipopcnt + .type __ipopcnt, @function - section .text - public __ipopcnt __ipopcnt: push hl ; Calculate 8-popcount(L)-popcount(HLU), and set HLU=H, L=0 @@ -16,4 +18,4 @@ __ipopcnt: pop hl ret - extern __popcnt_common_init_full, __popcnt_common_iter + .extern __popcnt_common_init_full, __popcnt_common_iter diff --git a/src/crt/ipopcnt_fast.src b/src/crt/ipopcnt_fast.src index 5d99398c7..61139757a 100644 --- a/src/crt/ipopcnt_fast.src +++ b/src/crt/ipopcnt_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ipopcnt_fast + .type __ipopcnt_fast, @function - section .text - public __ipopcnt_fast __ipopcnt_fast: ; Inlined implementation of __ipopcnt ; Destroys: HL diff --git a/src/crt/irems.src b/src/crt/irems.src index c9992a258..171a58566 100644 --- a/src/crt/irems.src +++ b/src/crt/irems.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __irems + .section .text + .global __irems + .type __irems, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__irems := 00016Ch + .set __irems, 0x00016C -else +.else __irems: ; I: UHL=dividend, UBC=divisor @@ -22,6 +23,6 @@ __irems: ret - extern __idvrms + .extern __idvrms -end if +.endif diff --git a/src/crt/iremu.src b/src/crt/iremu.src index 371321510..a38eb7b81 100644 --- a/src/crt/iremu.src +++ b/src/crt/iremu.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __iremu + .section .text + .global __iremu + .type __iremu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__iremu := 000170h + .set __iremu, 0x000170 -else +.else __iremu: ; I: UHL=dividend, UBC=divisor @@ -20,6 +21,6 @@ __iremu: pop de ret - extern __idvrmu + .extern __idvrmu -end if +.endif diff --git a/src/crt/ishl.src b/src/crt/ishl.src index 1127274b5..b476bc814 100644 --- a/src/crt/ishl.src +++ b/src/crt/ishl.src @@ -1,13 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public __ishl + .section .text + .global __ishl + .type __ishl, @function + .global __sshl + .type __sshl, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__ishl := 000174h + .set __ishl, 0x000174 + .set __sshl, 0x000240 -else +.else __ishl: ; CC: if 0<=C<8: 23*r(PC)+3*r(SPL)+4+(C&1==0)+(C&2!=0)*(1*r(PC)-1)+(C&4!=0)*(3*r(PC)-1) @@ -47,4 +51,6 @@ __ishl_8: add hl, hl ret -end if + .set __sshl, __ishl + +.endif diff --git a/src/crt/ishrs.src b/src/crt/ishrs.src index 3c9a3822a..af871812b 100644 --- a/src/crt/ishrs.src +++ b/src/crt/ishrs.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public __ishrs - public __ishru + .section .text + .global __ishrs + .type __ishrs, @function + .global __ishru + .type __ishru, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__ishrs := 00017Ch -__ishru := 000184h + .set __ishrs, 0x00017C + .set __ishru, 0x000184 -else +.else __ishru: push af @@ -75,4 +77,4 @@ __ishrs: pop af ret -end if +.endif diff --git a/src/crt/ishrs_1_fast.src b/src/crt/ishrs_1_fast.src index b5c676d8a..17970e4da 100644 --- a/src/crt/ishrs_1_fast.src +++ b/src/crt/ishrs_1_fast.src @@ -1,8 +1,10 @@ - assume adl=1 + .assume adl=1 - section .text - public __ishru_1_fast -__ishru_1_fast: + .section .text + .global __ishrs_1_fast + .type __ishrs_1_fast, @function + +__ishrs_1_fast: push hl ld hl, 2 add hl, sp diff --git a/src/crt/ishru_1_fast.src b/src/crt/ishru_1_fast.src index c68dbc8b3..765437bc1 100644 --- a/src/crt/ishru_1_fast.src +++ b/src/crt/ishru_1_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ishru_1_fast + .type __ishru_1_fast, @function - section .text - public __ishru_1_fast __ishru_1_fast: push hl ld hl, 2 diff --git a/src/crt/ladd.src b/src/crt/ladd.src index d993859fe..50e536564 100644 --- a/src/crt/ladd.src +++ b/src/crt/ladd.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __ladd + .section .text + .global __ladd + .type __ladd, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__ladd := 00019Ch + .set __ladd, 0x00019C -else +.else __ladd: push af @@ -17,4 +18,4 @@ __ladd: pop af ret -end if +.endif diff --git a/src/crt/ladd_1.src b/src/crt/ladd_1.src index 01833819a..14e089f93 100644 --- a/src/crt/ladd_1.src +++ b/src/crt/ladd_1.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ladd_1 + .type __ladd_1, @function - section .text - public __ladd_1 __ladd_1: inc hl add hl, bc diff --git a/src/crt/ladd_b.src b/src/crt/ladd_b.src index 448b40791..6d3e0ff6a 100644 --- a/src/crt/ladd_b.src +++ b/src/crt/ladd_b.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __ladd_b + .section .text + .global __ladd_b + .type __ladd_b, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__ladd_b := 0001A0h + .set __ladd_b, 0x0001A0 -else +.else __ladd_b: push bc @@ -20,4 +21,4 @@ __ladd_b: inc e ret -end if +.endif diff --git a/src/crt/ladd_b_fast.src b/src/crt/ladd_b_fast.src index 17f93486b..4682722d4 100644 --- a/src/crt/ladd_b_fast.src +++ b/src/crt/ladd_b_fast.src @@ -1,14 +1,16 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ladd_b_fast + .type __ladd_b_fast, @function - section .text - public __ladd_b_fast __ladd_b_fast: add a, l ld l, a ret nc inc h ret nz - ld bc, 1 shl 16 + ld bc, 1 << 16 add hl, bc ret nc inc e diff --git a/src/crt/ladd_fast.src b/src/crt/ladd_fast.src index 247fedc0a..7068fbe62 100644 --- a/src/crt/ladd_fast.src +++ b/src/crt/ladd_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ladd_fast + .type __ladd_fast, @function - section .text - public __ladd_fast __ladd_fast: add hl, bc adc a, e diff --git a/src/crt/lbitrev.src b/src/crt/lbitrev.src index 0c942621a..245367bc1 100644 --- a/src/crt/lbitrev.src +++ b/src/crt/lbitrev.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lbitrev + .type __lbitrev, @function - section .text - public __lbitrev __lbitrev: push af ld a, h ; a=H @@ -15,4 +17,4 @@ __lbitrev: pop af ret - extern __internal_bitrev_two_bytes + .extern __internal_bitrev_two_bytes diff --git a/src/crt/lbswap.src b/src/crt/lbswap.src index c8fa5a470..5e2eb4530 100644 --- a/src/crt/lbswap.src +++ b/src/crt/lbswap.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lbswap + .type __lbswap, @function - section .text - public __lbswap __lbswap: push hl ; ...[hlu]hl <- (sp) inc sp ; ...[hlu]h <- (sp) diff --git a/src/crt/lcmps.src b/src/crt/lcmps.src index e7c972f83..5b63a1d22 100644 --- a/src/crt/lcmps.src +++ b/src/crt/lcmps.src @@ -1,26 +1,27 @@ - assume adl=1 + .assume adl=1 - section .text - public __lcmps + .section .text + .global __lcmps + .type __lcmps, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lcmps := 0001A8h + .set __lcmps, 0x0001A8 -else +.else __lcmps: push de ld d, a ld a, e sub a, d - jr nz, .finish + jr nz, .L.finish sbc hl, bc add hl, bc sbc a, a -.finish: +.L.finish: ld a, d pop de ret -end if +.endif diff --git a/src/crt/lcmps_fast.src b/src/crt/lcmps_fast.src index b41945357..624afbff9 100644 --- a/src/crt/lcmps_fast.src +++ b/src/crt/lcmps_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lcmps_fast + .type __lcmps_fast, @function - section .text - public __lcmps_fast __lcmps_fast: ld d, a ld a, e diff --git a/src/crt/lcmpu.src b/src/crt/lcmpu.src index 19769bcca..071ea31d5 100644 --- a/src/crt/lcmpu.src +++ b/src/crt/lcmpu.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __lcmpu + .section .text + .global __lcmpu + .type __lcmpu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lcmpu := 0001ACh + .set __lcmpu, 0x0001AC -else +.else __lcmpu: cp a, e @@ -18,4 +19,4 @@ __lcmpu: add hl, bc ret -end if +.endif diff --git a/src/crt/lcmpu_fast.src b/src/crt/lcmpu_fast.src index 6ef89132e..5193ad1a1 100644 --- a/src/crt/lcmpu_fast.src +++ b/src/crt/lcmpu_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lcmpu_fast + .type __lcmpu_fast, @function - section .text - public __lcmpu_fast __lcmpu_fast: sub a, e ccf diff --git a/src/crt/lcmpzero.src b/src/crt/lcmpzero.src index 17788ec20..1adaccfc6 100644 --- a/src/crt/lcmpzero.src +++ b/src/crt/lcmpzero.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lcmpzero + .type __lcmpzero, @function - section .text - public __lcmpzero __lcmpzero: inc e dec e diff --git a/src/crt/ldivs.src b/src/crt/ldivs.src index cdbf31742..ddb5ac01a 100644 --- a/src/crt/ldivs.src +++ b/src/crt/ldivs.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __ldivs + .section .text + .global __ldivs + .type __ldivs, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__ldivs := 0001B4h + .set __ldivs, 0x0001B4 -else +.else __ldivs: ; I: EUHL=dividend, AUBC=divisor @@ -26,15 +27,15 @@ __ldivs: rlca rrca - jr nz, .pos_dividend_skip + jr nz, .L.pos_dividend_skip ccf -.pos_dividend_skip: +.L.pos_dividend_skip: ret c jp __lneg - extern __ldivs_lrems_common - extern __ldivu - extern __lneg + .extern __ldivs_lrems_common + .extern __ldivu + .extern __lneg -end if +.endif diff --git a/src/crt/ldivs_lrems_common.src b/src/crt/ldivs_lrems_common.src index 87b9be583..dcda5a394 100644 --- a/src/crt/ldivs_lrems_common.src +++ b/src/crt/ldivs_lrems_common.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ldivs_lrems_common + .type __ldivs_lrems_common, @function - section .text - public __ldivs_lrems_common __ldivs_lrems_common: ; I: ZF=EUHL>=0 ; O: aubc=abs(AUBC), euhl=abs(EUHL) @@ -21,4 +23,4 @@ __ldivs_lrems_common: ret - extern __lneg + .extern __lneg diff --git a/src/crt/ldivu.src b/src/crt/ldivu.src index be94ad86a..7a4329662 100644 --- a/src/crt/ldivu.src +++ b/src/crt/ldivu.src @@ -1,19 +1,20 @@ - assume adl=1 + .assume adl=1 - section .text - public __ldivu + .section .text + .global __ldivu + .type __ldivu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__ldivu := 0001B8h + .set __ldivu, 0x0001B8 -else +.else __ldivu: ; I: EUHL=dividend, AUBC=divisor ; O: euhl=EUHL/AUBC -if 1 +.if 1 push bc call __ldvrmu @@ -25,7 +26,7 @@ if 1 ei ret -else +.else push ix push iy @@ -36,8 +37,8 @@ else pop hl ret -end if +.endif - extern __ldvrmu + .extern __ldvrmu -end if +.endif diff --git a/src/crt/ldvrmu.src b/src/crt/ldvrmu.src index 37f334a18..e348085c7 100644 --- a/src/crt/ldvrmu.src +++ b/src/crt/ldvrmu.src @@ -1,18 +1,19 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text ;;; struct u32div_t { ;;; uint32_t rem; ;;; uint32_t quot; ;;; }; ;;; u32div_t _ldvrmu(uint32_t dividend, uint32_t divisor) { - public __ldvrmu + .global __ldvrmu + .type __ldvrmu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__ldvrmu := 0001BCh + .set __ldvrmu, 0x0001BC -else +.else __ldvrmu: if 1 @@ -46,7 +47,7 @@ if 1 ld b, 32 ; b : i ;;; do { -.loop: +.L.c.loop: ;;; bool dividendBit = result.quot >> 31; ;;; result.quot <<= 1; @@ -63,23 +64,23 @@ if 1 sbc a, e ;;; if (!quotBit) { - jr nc, .restore_skip + jr nc, .L.c.restore_skip ;;; result.rem += divisor; add hl, bc adc a, e ;;; } -.restore_skip: +.L.c.restore_skip: ;;; if (quotBit) { exx - jr c, .1_skip + jr c, .L.c.skip ;;; result.quot++; inc l ;;; } -.1_skip: +.L.c.skip: ;;; } while (--i != 0); - djnz .loop + djnz .L.c.loop ;;; return result; pop bc @@ -87,7 +88,7 @@ if 1 ret ;;; } -else +.else ; I: EUHL=dividend, AUBC=divisor ; O: auhl=EUHL%AUBC, euix=EUHL/AUBC, iyh=A, iyl=0 @@ -101,7 +102,7 @@ else ld iyl, 32 -.loop: +.L.loop: add ix, ix rl e adc hl, hl @@ -111,17 +112,17 @@ else sbc a, iyh inc ixl - jr nc, .restore_skip + jr nc, .L.restore_skip add hl, bc adc a, iyh dec ixl -.restore_skip: +.L.restore_skip: dec iyl - jr nz, .loop + jr nz, .L.loop ret -end if +.endif -end if +.endif diff --git a/src/crt/lladd.src b/src/crt/lladd.src index 71e215ed5..a8e83b02d 100644 --- a/src/crt/lladd.src +++ b/src/crt/lladd.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lladd + .type __lladd, @function - section .text - public __lladd __lladd: push iy ld iy, 0 @@ -14,11 +16,11 @@ __lladd: adc hl, bc ex de, hl pop bc - jr nc, .nc48 + jr nc, .L.nc48 inc bc -.nc48: +.L.nc48: ld iy, (iy + 12) add iy, bc - lea bc, iy + lea bc, iy + 0 pop iy ret diff --git a/src/crt/lladd_1.src b/src/crt/lladd_1.src index 402f5bbb7..ea8a3a921 100644 --- a/src/crt/lladd_1.src +++ b/src/crt/lladd_1.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lladd_1 + .type __lladd_1, @function - section .text - public __lladd_1 __lladd_1: inc hl add hl, de diff --git a/src/crt/lladd_b.src b/src/crt/lladd_b.src index 2003f5d71..967d23bdc 100644 --- a/src/crt/lladd_b.src +++ b/src/crt/lladd_b.src @@ -1,19 +1,21 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lladd_b + .type __lladd_b, @function - section .text - public __lladd_b __lladd_b: push bc inc.s bc ld c, a ld b, 0 add hl, bc - jr nc, .finish + jr nc, .L.finish ld c, 1 ex de, hl add hl, bc ex de, hl -.finish: +.L.finish: pop bc ret nc inc bc diff --git a/src/crt/lladd_b_fast.src b/src/crt/lladd_b_fast.src index 864a0132f..ea70f8752 100644 --- a/src/crt/lladd_b_fast.src +++ b/src/crt/lladd_b_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lladd_b_fast + .type __lladd_b_fast, @function - section .text - public __lladd_b_fast __lladd_b_fast: add a, l ; a=L+A ld l, a ; l=L+A diff --git a/src/crt/lladd_fast.src b/src/crt/lladd_fast.src index a73610681..f579eb72d 100644 --- a/src/crt/lladd_fast.src +++ b/src/crt/lladd_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lladd_fast + .type __lladd_fast, @function - section .text - public __lladd_fast __lladd_fast: ld iy, 0 add iy, sp diff --git a/src/crt/lland.src b/src/crt/lland.src index dc0de70eb..2fd31db6c 100644 --- a/src/crt/lland.src +++ b/src/crt/lland.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lland + .type __lland, @function - section .text - public __lland __lland: ; CC: 61*r(PC)+25*r(SPL)+14*w(SPL)+1 push af diff --git a/src/crt/lland_fast.src b/src/crt/lland_fast.src index eddf58d75..2ad111b9d 100644 --- a/src/crt/lland_fast.src +++ b/src/crt/lland_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lland_fast + .type __lland_fast, @function - section .text - public __lland_fast __lland_fast: ; CC: 55*r(PC)+19*r(SPL)+8*w(SPL)+1 ld iy, 0 diff --git a/src/crt/llbitrev.src b/src/crt/llbitrev.src index cccaf790f..105da930b 100644 --- a/src/crt/llbitrev.src +++ b/src/crt/llbitrev.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llbitrev + .type __llbitrev, @function - section .text - public __llbitrev __llbitrev: push af ld a, d ; a=D @@ -23,4 +25,4 @@ __llbitrev: pop af ret - extern __internal_bitrev_two_bytes + .extern __internal_bitrev_two_bytes diff --git a/src/crt/llbswap.src b/src/crt/llbswap.src index 3f829a23e..9cd2b579c 100644 --- a/src/crt/llbswap.src +++ b/src/crt/llbswap.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llbswap + .type __llbswap, @function - section .text - public __llbswap __llbswap: push af ld a, b ; a = b diff --git a/src/crt/llcmps.src b/src/crt/llcmps.src index 7cd77c17b..1943efbf1 100644 --- a/src/crt/llcmps.src +++ b/src/crt/llcmps.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llcmps + .type __llcmps, @function - section .text - public __llcmps __llcmps: push iy ld iy, 0 @@ -13,21 +15,21 @@ __llcmps: ld bc, (iy + 12) sbc.s hl, bc pop hl - jr nz, .finish + jr nz, .L.finish ld bc, (iy + 9) ex de, hl sbc hl, bc add hl, bc ex de, hl - jr nz, .finish_unsigned + jr nz, .L.finish_unsigned ld bc, (iy + 6) sbc hl, bc add hl, bc -.finish_unsigned: +.L.finish_unsigned: ld b, a sbc a, a ld a, b -.finish: +.L.finish: pop bc pop iy ret diff --git a/src/crt/llcmps_fast.src b/src/crt/llcmps_fast.src index be3426060..c04ba80e9 100644 --- a/src/crt/llcmps_fast.src +++ b/src/crt/llcmps_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llcmps_fast + .type __llcmps_fast, @function - section .text - public __llcmps_fast __llcmps_fast: ld iy, 0 add iy, sp @@ -10,14 +12,14 @@ __llcmps_fast: ret nz ld a, c sub a, (iy + 9) - jr nz, .finish + jr nz, .L.finish ex de, hl ld bc, (iy + 6) sbc hl, bc - jr nz, .finish + jr nz, .L.finish ex de, hl ld bc, (iy + 3) sbc hl, bc -.finish: +.L.finish: sbc a, a ret diff --git a/src/crt/llcmpu.src b/src/crt/llcmpu.src index 16b9f3131..79faf56b8 100644 --- a/src/crt/llcmpu.src +++ b/src/crt/llcmpu.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llcmpu + .type __llcmpu, @function - section .text - public __llcmpu __llcmpu: push iy ld iy, 0 @@ -9,10 +11,10 @@ __llcmpu: push hl ld hl, (iy + 12) sbc.s hl, bc - jr nz, .ne + jr nz, .L.ne ld hl, (iy + 9) sbc hl, de - jr nz, .ne + jr nz, .L.ne pop hl push bc ld bc, (iy + 6) @@ -22,7 +24,7 @@ __llcmpu: pop iy ret -.ne: +.L.ne: ccf pop hl pop iy diff --git a/src/crt/llcmpu_fast.src b/src/crt/llcmpu_fast.src index 7223329ed..2cc2159b8 100644 --- a/src/crt/llcmpu_fast.src +++ b/src/crt/llcmpu_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llcmpu_fast + .type __llcmpu_fast, @function - section .text - public __llcmpu_fast __llcmpu_fast: ld iy, 0 add iy, sp diff --git a/src/crt/llcmpzero.src b/src/crt/llcmpzero.src index 5b2b19b44..c04353c89 100644 --- a/src/crt/llcmpzero.src +++ b/src/crt/llcmpzero.src @@ -1,21 +1,23 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llcmpzero + .type __llcmpzero, @function - section .text - public __llcmpzero __llcmpzero: inc b dec b ret nz inc.s bc dec c - jr nz, .p_nz + jr nz, .L.p_nz or a, a sbc hl, bc - jr nz, .p_nz + jr nz, .L.p_nz sbc hl, de ret z add hl, de -.p_nz: +.L.p_nz: inc b ld b, 0 ret diff --git a/src/crt/llcmpzero_fast.src b/src/crt/llcmpzero_fast.src index d68547aac..3f310c7eb 100644 --- a/src/crt/llcmpzero_fast.src +++ b/src/crt/llcmpzero_fast.src @@ -1,18 +1,20 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llcmpzero_fast + .type __llcmpzero_fast, @function - section .text - public __llcmpzero_fast __llcmpzero_fast: xor a, a add a, b ret nz cp a, c - jr nz, .p_nz + jr nz, .L.p_nz mlt bc adc hl, bc - jr nz, .p_nz + jr nz, .L.p_nz adc hl, de ret z -.p_nz: +.L.p_nz: inc a ret diff --git a/src/crt/lldivs.src b/src/crt/lldivs.src index 8896b4d87..a91223f7b 100644 --- a/src/crt/lldivs.src +++ b/src/crt/lldivs.src @@ -1,20 +1,20 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llrems + .type __llrems, @function + .global __lldivs + .type __lldivs, @function - section .text - public __llrems __llrems: scf -virtual - jr nc, $ + 2 - load .jr_nc: 1 from $$ -end virtual - db .jr_nc + jr .L.hijack - public __lldivs __lldivs: or a, a +.L.hijack: push iy push af @@ -29,7 +29,7 @@ __lldivs: xor a, b rla - jr nc, .neg_divisor_skip + jr nc, .L.neg_divisor_skip push bc push hl @@ -39,16 +39,16 @@ __lldivs: ld c, a ld b, 8 -.neg_divisor_loop: +.L.neg_divisor_loop: ld a, c sbc a, (hl) ld (hl), a inc hl - djnz .neg_divisor_loop + djnz .L.neg_divisor_loop pop hl pop bc -.neg_divisor_skip: +.L.neg_divisor_skip: bit 7, b call nz, __llneg @@ -58,17 +58,17 @@ __lldivs: pop af bit 7, (iy + 8) - jr c, .div_quotient_skip + jr c, .L.div_quotient_skip ld hl, (iy + 15) ld de, (iy + 18) ld bc, (iy + 21) bit 7, (iy + 23) -.div_quotient_skip: +.L.div_quotient_skip: pop iy ret z jp __llneg - extern __lldvrmu.hijack - extern __llneg + .extern __lldvrmu.hijack + .extern __llneg diff --git a/src/crt/lldivu.src b/src/crt/lldivu.src index 53d1e0043..bd39ffb16 100644 --- a/src/crt/lldivu.src +++ b/src/crt/lldivu.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lldivu + .type __lldivu, @function - section .text - public __lldivu __lldivu: push iy @@ -18,4 +20,4 @@ __lldivu: ret - extern __lldvrmu + .extern __lldvrmu diff --git a/src/crt/lldivu_b.src b/src/crt/lldivu_b.src index 9dcd5780d..c6f847060 100644 --- a/src/crt/lldivu_b.src +++ b/src/crt/lldivu_b.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lldivu_b + .type __lldivu_b, @function - section .text - public __lldivu_b __lldivu_b: ; Very slow push af @@ -11,7 +13,7 @@ __lldivu_b: ld iy, (iy + 9) xor a, a ld iyh, 64 -.loop: +.L.loop: add hl, hl ex de, hl adc hl, hl @@ -19,15 +21,15 @@ __lldivu_b: rl c rl b rla - jr c, .1 + jr c, .L.1 cp a, iyl - jr c, .0 -.1: + jr c, .L.0 +.L.1: sub a, iyl inc l -.0: +.L.0: dec iyh - jr nz, .loop + jr nz, .L.loop pop iy pop af ret diff --git a/src/crt/lldvrmu.src b/src/crt/lldvrmu.src index 0e31c87ac..db1052d31 100644 --- a/src/crt/lldvrmu.src +++ b/src/crt/lldvrmu.src @@ -1,14 +1,18 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lldvrmu + .type __lldvrmu, @function + .global __lldvrmu.hijack + .type __lldvrmu.hijack, @function - section .text - public __lldvrmu __lldvrmu: ; Atrociously slow. ld iy, 5 add iy, sp - public __lldvrmu.hijack -.hijack: + +__lldvrmu.hijack: ld a, i di @@ -43,13 +47,13 @@ __lldvrmu: ld c, 8 -.byte_loop: +.L.byte_loop: dec iy ld a, (iy - 9) ld b, 8 -.bit_loop: +.L.bit_loop: adc a, a exx adc hl, hl @@ -67,7 +71,7 @@ __lldvrmu: exx sbc hl, de - jr nc, .add_back_skip + jr nc, .L.add_back_skip exx add hl, sp ex de, hl @@ -75,16 +79,16 @@ __lldvrmu: ex de, hl exx adc hl, de -.add_back_skip: +.L.add_back_skip: - djnz .bit_loop + djnz .L.bit_loop adc a, a cpl ld (iy + 15), a dec c - jr nz, .byte_loop + jr nz, .L.byte_loop ld sp, iy ; Stack frame: diff --git a/src/crt/llmulu.src b/src/crt/llmulu.src index f48d80887..be8b1d937 100644 --- a/src/crt/llmulu.src +++ b/src/crt/llmulu.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llmuls + .type __llmuls, @function + .global __llmulu + .type __llmulu, @function - section .text - public __llmuls, __llmulu __llmuls: __llmulu: ; Really slow @@ -22,22 +26,22 @@ __llmulu: lea hl, iy + 18 ld b, 8 -.push_loop: +.L.push_loop: push af ld a, (hl) inc hl or a, a ; cf=0 - djnz .push_loop + djnz .L.push_loop sbc hl, hl ld e, l ld d, h -.byte_loop: +.L.byte_loop: scf adc a, a -.bit_loop: +.L.bit_loop: push af add ix, ix adc hl, hl @@ -46,7 +50,7 @@ __llmulu: ex de, hl pop af - jr nc, .add_end + jr nc, .L.add_end ld bc, (iy) add ix, bc ld bc, (iy + 3) @@ -54,18 +58,18 @@ __llmulu: ex de, hl adc.s hl, sp ex de, hl -.add_end: +.L.add_end: add a, a - jr nz, .bit_loop + jr nz, .L.bit_loop pop af - jr nc, .byte_loop + jr nc, .L.byte_loop ld b, d ld c, e ex de, hl - lea hl, ix + lea hl, ix + 0 pop af pop af diff --git a/src/crt/llmulu_b.src b/src/crt/llmulu_b.src index 8f376054a..1e67a263c 100644 --- a/src/crt/llmulu_b.src +++ b/src/crt/llmulu_b.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __llmulu_b + .global __llmulu_b + .type __llmulu_b, @function __llmulu_b: ; Multiplies BC:UDE:UHL by (SP) and returns the 64-bit unsigned product bc:ude:uhl. diff --git a/src/crt/llneg.src b/src/crt/llneg.src index bf13f5dfa..bfff0aada 100644 --- a/src/crt/llneg.src +++ b/src/crt/llneg.src @@ -1,11 +1,14 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llneg + .type __llneg, @function + .global __llneg.hijack_nc + .type __llneg.hijack_nc, @function - section .text - public __llneg __llneg: or a, a - public __llneg.hijack_nc -.hijack_nc: +__llneg.hijack_nc: ex de, hl ; ude=UHL, uhl=UDE push hl ; *spl=UDE sbc hl, hl ; uhl=0 diff --git a/src/crt/llneg_fast.src b/src/crt/llneg_fast.src index bd4373850..709b95f3a 100644 --- a/src/crt/llneg_fast.src +++ b/src/crt/llneg_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llneg_fast + .type __llneg_fast, @function - section .text - public __llneg_fast __llneg_fast: push de ; *spl=UDE ex de, hl ; ude=UHL, uhl=UDE diff --git a/src/crt/llnot.src b/src/crt/llnot.src index d2151e07f..360bd0a6d 100644 --- a/src/crt/llnot.src +++ b/src/crt/llnot.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llnot + .type __llnot, @function - section .text - public __llnot __llnot: push hl ; *spl=UHL add hl, de ; uhl=UHL+UDE diff --git a/src/crt/llnot_fast.src b/src/crt/llnot_fast.src index 9b7ce9465..c73eecdd5 100644 --- a/src/crt/llnot_fast.src +++ b/src/crt/llnot_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llnot_fast + .type __llnot_fast, @function - section .text - public __llnot_fast __llnot_fast: push hl ; *spl=UHL add hl, de ; uhl=UHL+UDE diff --git a/src/crt/llor.src b/src/crt/llor.src index 6337e2822..8a9d3a6a4 100644 --- a/src/crt/llor.src +++ b/src/crt/llor.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llor + .type __llor, @function - section .text - public __llor __llor: ; CC: 61*r(PC)+25*r(SPL)+14*w(SPL)+1 push af diff --git a/src/crt/llor_fast.src b/src/crt/llor_fast.src index 7425a00bf..c6c18e6bb 100644 --- a/src/crt/llor_fast.src +++ b/src/crt/llor_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llor_fast + .type __llor_fast, @function - section .text - public __llor_fast __llor_fast: ; CC: 55*r(PC)+19*r(SPL)+8*w(SPL)+1 ld iy, 0 diff --git a/src/crt/llpopcnt.src b/src/crt/llpopcnt.src index cc6425748..52bb4c47c 100644 --- a/src/crt/llpopcnt.src +++ b/src/crt/llpopcnt.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llpopcnt + .type __llpopcnt, @function - section .text - public __llpopcnt __llpopcnt: call __lpopcnt push de @@ -16,4 +18,4 @@ __llpopcnt: pop de ret - extern __lpopcnt + .extern __lpopcnt diff --git a/src/crt/llpopcnt_fast.src b/src/crt/llpopcnt_fast.src index 3811e12d6..1dd811c71 100644 --- a/src/crt/llpopcnt_fast.src +++ b/src/crt/llpopcnt_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llpopcnt_fast + .type __llpopcnt_fast, @function - section .text - public __llpopcnt_fast __llpopcnt_fast: ; Destroys: HL, DE call __lpopcnt_fast @@ -13,4 +15,4 @@ __llpopcnt_fast: add a, d ret - extern __lpopcnt_fast + .extern __lpopcnt_fast diff --git a/src/crt/llremu.src b/src/crt/llremu.src index 431799162..7203cd310 100644 --- a/src/crt/llremu.src +++ b/src/crt/llremu.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llremu + .type __llremu, @function - section .text - public __llremu __llremu: push iy @@ -14,4 +16,4 @@ __llremu: ret - extern __lldvrmu + .extern __lldvrmu diff --git a/src/crt/llshl.src b/src/crt/llshl.src index b2e700bc9..1a5067f2e 100644 --- a/src/crt/llshl.src +++ b/src/crt/llshl.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llshl + .type __llshl, @function - section .text - public __llshl __llshl: ; Suboptimal for large shift amounts push af @@ -14,17 +16,17 @@ __llshl: pop hl inc b - jr .begin + jr .L.begin -.loop: +.L.loop: add hl, hl ex de, hl adc hl, hl ex de, hl rl c rla -.begin: - djnz .loop +.L.begin: + djnz .L.loop ld b, a pop af diff --git a/src/crt/llshl_1_fast.src b/src/crt/llshl_1_fast.src index 6cb8a0fa3..830b4f510 100644 --- a/src/crt/llshl_1_fast.src +++ b/src/crt/llshl_1_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llshl_1_fast + .type __llshl_1_fast, @function - section .text - public __llshl_1_fast __llshl_1_fast: add hl, hl ex de, hl diff --git a/src/crt/llshrs.src b/src/crt/llshrs.src index c4bf665bc..962331ae8 100644 --- a/src/crt/llshrs.src +++ b/src/crt/llshrs.src @@ -1,8 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __llshru + .global __llshru + .type __llshru, @function + .global __llshrs + .type __llshrs, @function __llshru: ; Suboptimal for large shift amounts @@ -12,15 +15,11 @@ __llshru: add iy, sp ld a, (iy + 9) or a, a - jr z, __llshr_common.finish + jr z, .L.finish push de push hl srl b - jr __llshr_common.hijack_llshru - - section .text - - public __llshrs + jr .L.hijack_llshru __llshrs: ; Suboptimal for large shift amounts @@ -30,18 +29,15 @@ __llshrs: add iy, sp ld a, (iy + 9) or a, a - jr z, __llshr_common.finish + jr z, .L.finish push de push hl - section .text - - private __llshr_common + .local __llshr_common __llshr_common: -.loop: +.L.loop: sra b - private __llshr_common.hijack_llshru -.hijack_llshru: +.L.hijack_llshru: rr c rr (iy - 1) rr d @@ -50,7 +46,7 @@ __llshr_common: rr h rr l dec a - jr nz, .loop + jr nz, .L.loop ld (iy - 3), e ld (iy - 2), d @@ -59,8 +55,8 @@ __llshr_common: ld l, e ld h, d pop de - private __llshr_common.finish -.finish: + .local .L.finish +.L.finish: pop iy pop af ret diff --git a/src/crt/llshrs_1_fast.src b/src/crt/llshrs_1_fast.src index 76452de02..68d26bbe8 100644 --- a/src/crt/llshrs_1_fast.src +++ b/src/crt/llshrs_1_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llshrs_1_fast + .type __llshrs_1_fast, @function - section .text - public __llshrs_1_fast __llshrs_1_fast: push hl push de diff --git a/src/crt/llshrs_fast.src b/src/crt/llshrs_fast.src index 01e603c45..197b0d8c5 100644 --- a/src/crt/llshrs_fast.src +++ b/src/crt/llshrs_fast.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llshrs_fast + .type __llshrs_fast, @function + .global __llshrs_fast.hijack_llshru + .type __llshrs_fast.hijack_llshru, @function - section .text - public __llshrs_fast __llshrs_fast: ; Could use optimization for shifting whole bytes at a time. ld iy, 0 @@ -12,15 +16,14 @@ __llshrs_fast: ld b, (iy + 3) inc b dec b - jr z, .skip + jr z, .L.skip push de push hl -.loop: +.L.loop: sra c - public __llshrs_fast.hijack_llshru -.hijack_llshru: +__llshrs_fast.hijack_llshru: rra rr (iy - 1) rr d @@ -28,7 +31,7 @@ __llshrs_fast: rr (iy - 4) rr h rr l - djnz .loop + djnz .L.loop ld b, e ld (iy - 2), d @@ -41,14 +44,14 @@ __llshrs_fast: pop de ld e, b -.skip: +.L.skip: ld b, c ld c, a ret -if 0 +.if 0 push bc ld iy, 0 add iy, sp @@ -56,12 +59,12 @@ if 0 ld c, a dec a and a, 00111000b - ld (.byteshift_smc) + ld (byteshift_smc) xor a, a sub a, c jr $+1 -.byteshift_smc := $-1 -.shr1_8: + .equ byteshift_smc, $-1 +.L.shr1_8: ld c, b ld iyh, a push de @@ -72,7 +75,7 @@ if 0 pop de inc sp inc sp -.shr1_8_loop: +.L.shr1_8_loop: add a, a adc hl, hl ex de, hl @@ -81,9 +84,9 @@ if 0 rl c rl b dec iyh - jr nz, .shr1_8_loop + jr nz, .L.shr1_8_loop -.shr9_16: +.L.shr9_16: push de push hl inc sp @@ -93,7 +96,7 @@ if 0 pop de inc sp -.shr17_24: +.L.shr17_24: dec sp push hl inc sp @@ -102,14 +105,14 @@ if 0 ld e, c ld d, b -.shr25_32: +.L.shr25_32: push de inc sp ld a, e pop hl ld e, b -.shr33_40: -.shr41_48: +.L.shr33_40: +.L.shr41_48: rl b pop bc sbc hl, hl @@ -118,15 +121,15 @@ if 0 ld l, c ld h, b and a, 00000111b - jr z, .shr48 + jr z, .L.shr48 .shr49_56_loop: add a, a adc hl, hl - djnz .shr49_56_loop -.shr48: + djnz .L.shr49_56_loop +.L.shr48: -.shr49_56: +.L.shr49_56: rl b pop bc sbc hl, hl @@ -134,22 +137,22 @@ if 0 sbc hl, hl ld l, b and a, 00000111b - jr z, .shr56 + jr z, .L.shr56 ld b, a ld a, c -.shr49_56_loop: +.L.shr49_56_loop: add a, a adc hl, hl - djnz .shr49_56_loop -.shr56: + djnz .L.shr49_56_loop +.L.shr56: ld c, d ld b, c ret -.shr57_63_0: +.L.shr57_63_0: and a, 00000111b - jr z, .shr0 -.shr57_63: + jr z, .L.shr0 +.L.shr57_63: rl b pop bc sbc hl, hl @@ -157,16 +160,17 @@ if 0 sbc hl, hl ld l, b ld b, a -.shr57_63_loop: +.L.shr57_63_loop: add hl, hl - djnz .shr57_63_loop + djnz .L.shr57_63_loop ld l, h ld h, e ld c, d ld b, c ret -.shr0: +.L.shr0: pop bc ret -end if + +.endif diff --git a/src/crt/llshru_1_fast.src b/src/crt/llshru_1_fast.src index 6af6e39fd..1a6f83873 100644 --- a/src/crt/llshru_1_fast.src +++ b/src/crt/llshru_1_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llshru_1_fast + .type __llshru_1_fast, @function - section .text - public __llshru_1_fast __llshru_1_fast: push hl push de diff --git a/src/crt/llshru_fast.src b/src/crt/llshru_fast.src index 09d162c84..41edd4508 100644 --- a/src/crt/llshru_fast.src +++ b/src/crt/llshru_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llshru_fast + .type __llshru_fast, @function - section .text - public __llshru_fast __llshru_fast: ld iy, 0 add iy, sp @@ -21,4 +23,4 @@ __llshru_fast: jp __llshrs_fast.hijack_llshru - extern __llshrs_fast.hijack_llshru + .extern __llshrs_fast.hijack_llshru diff --git a/src/crt/llsub.src b/src/crt/llsub.src index bbdca06a2..7358558e5 100644 --- a/src/crt/llsub.src +++ b/src/crt/llsub.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llsub + .type __llsub, @function - section .text - public __llsub __llsub: push iy ld iy, 0 diff --git a/src/crt/llsub_1.src b/src/crt/llsub_1.src index d21d768fd..1c25ab244 100644 --- a/src/crt/llsub_1.src +++ b/src/crt/llsub_1.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llsub_1 + .type __llsub_1, @function - section .text - public __llsub_1 __llsub_1: add hl, de or a, a diff --git a/src/crt/llsub_fast.src b/src/crt/llsub_fast.src index 374a5a3b7..fc733cb78 100644 --- a/src/crt/llsub_fast.src +++ b/src/crt/llsub_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llsub_fast + .type __llsub_fast, @function - section .text - public __llsub_fast __llsub_fast: ld iy, 0 add iy, sp diff --git a/src/crt/lltof.src b/src/crt/lltof.src index 1c8effbf1..37babdb7a 100644 --- a/src/crt/lltof.src +++ b/src/crt/lltof.src @@ -1,15 +1,23 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lltof + .type __lltof, @function - section .text - public __lltof __lltof: - push af, iy, bc, de, hl + push af + push iy + push bc + push de + push hl call __lltof_c pop af ld a, e pop de ld e, a - pop bc, iy, af + pop bc + pop iy + pop af ret - extern __lltof_c + .extern __lltof_c diff --git a/src/crt/llxor.src b/src/crt/llxor.src index 4b3d2cc01..cddf1e38d 100644 --- a/src/crt/llxor.src +++ b/src/crt/llxor.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llxor + .type __llxor, @function - section .text - public __llxor __llxor: ; CC: 61*r(PC)+25*r(SPL)+14*w(SPL)+1 push af diff --git a/src/crt/llxor_fast.src b/src/crt/llxor_fast.src index 19a55b8ac..dd2e8fbf5 100644 --- a/src/crt/llxor_fast.src +++ b/src/crt/llxor_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __llxor_fast + .type __llxor_fast, @function - section .text - public __llxor_fast __llxor_fast: ; CC: 55*r(PC)+19*r(SPL)+8*w(SPL)+1 ld iy, 0 diff --git a/src/crt/lmulu.src b/src/crt/lmulu.src index 3ce5a34c9..c41e3ee78 100644 --- a/src/crt/lmulu.src +++ b/src/crt/lmulu.src @@ -1,14 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public __lmuls, __lmulu + .section .text + .global __lmuls + .type __lmuls, @function + .global __lmulu + .type __lmulu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lmuls := 0001C8h -__lmulu := 0001CCh + .set __lmuls, 0x0001C8 + .set __lmulu, 0x0001CC -else +.else __lmuls: __lmulu: @@ -19,7 +22,7 @@ __lmulu: ; FO: -- ; CC: 93*r(PC)+15*w(SPL)+15*r(SPL)+41 ; ; a ude uhl uix u(sp) -Mul_EUHL_AUBC_EUHL: ;--------------+---------------+---------------+---------------+---------------------------------------- +.L.Mul_EUHL_AUBC_EUHL: ;--------------+---------------+---------------+---------------+---------------------------------------- push af ; u(sp)=AF push de ; u(sp)=UDE push ix ; u(sp)=UIX @@ -93,4 +96,4 @@ Mul_EUHL_AUBC_EUHL: ;--------------+---------------+---------------+----------- ; (EUHL*AUBC)&0xFFFFFFFF=L*C+(H*C+L*B<<8)+(HLU*C+H*B+L*BCU<<16)+(E*C+HLU*B+H*BCU+L*A<<24)+(E*B+HLU*BCU+H*A<<32)+(E*BCU+HLU*A<<40)+(E*A<<48)&0xFFFFFFFF ; =L*C+(H*C+L*B<<8)+(HLU*C+H*B+L*BCU<<16)+(E*C+HLU*B+H*BCU+L*A<<24)&0xFFFFFFFF -end if +.endif diff --git a/src/crt/lmulu_b.src b/src/crt/lmulu_b.src index e76769481..ca30acf66 100644 --- a/src/crt/lmulu_b.src +++ b/src/crt/lmulu_b.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __lmulu_b + .global __lmulu_b + .type __lmulu_b, @function __lmulu_b: @@ -11,7 +12,7 @@ __lmulu_b: ; O: euhl=EUHL*A ; CC: 43*r(PC)+12*r(SPL)+9*w(SPL)+17 ; CC: 42 bytes | 43F + 12R + 9W + 17 -Mul_EUHL_A_EUHL: +.L.Mul_EUHL_A_EUHL: push bc push de diff --git a/src/crt/lmulu_b_fast.src b/src/crt/lmulu_b_fast.src index 16f91b23c..ffbe3470b 100644 --- a/src/crt/lmulu_b_fast.src +++ b/src/crt/lmulu_b_fast.src @@ -1,8 +1,8 @@ - assume adl=1 + .assume adl=1 - section .text - - public __lmulu_b_fast + .section .text + .global __lmulu_b_fast + .type __lmulu_b_fast, @function __lmulu_b_fast: @@ -11,7 +11,7 @@ __lmulu_b_fast: ; O: euhl=EUHL*A ; CC: 37*r(PC)+6*r(SPL)+3*w(SPL)+17 ; CC: 36 bytes | 37F + 6R + 3W + 17 -Mul_EUHL_A_EUHL: +.L.Mul_EUHL_A_EUHL: dec sp push hl inc sp diff --git a/src/crt/lmulu_fast.src b/src/crt/lmulu_fast.src index 59b1e40a4..a67a4b7a7 100644 --- a/src/crt/lmulu_fast.src +++ b/src/crt/lmulu_fast.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lmuls_fast + .type __lmuls_fast, @function + .global __lmulu_fast + .type __lmulu_fast, @function - section .text - public __lmuls_fast, __lmulu_fast __lmuls_fast: __lmulu_fast: @@ -11,7 +15,7 @@ __lmulu_fast: ; FO: sz(e), vc((EUHL*AUBC-L*C&0xFFFFFFFF)+L*C) ; CC: (86+2*cf)*r(PC)+9*w(SPL)+9*r(SPL)+42 ; ; a ubc ude uhl uix u(sp) -Mul_EUHL_AUBC_EUHL_Fast: ;--------------+---------------+---------------+---------------+---------------+------------------------ +.L.Mul_EUHL_AUBC_EUHL_Fast: ;--------------+---------------+---------------+---------------+---------------+------------------------ push ix ; u(sp)=UIX ld d, c ; de=CE mlt de ; ude=E*C diff --git a/src/crt/lneg.src b/src/crt/lneg.src index 6d9141001..9fb2a5bdf 100644 --- a/src/crt/lneg.src +++ b/src/crt/lneg.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __lneg + .section .text + .global __lneg + .type __lneg, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lneg := 0001D0h + .set __lneg, 0x0001D0 -else +.else __lneg: push af @@ -22,4 +23,4 @@ __lneg: pop af ret -end if +.endif diff --git a/src/crt/lneg_fast.src b/src/crt/lneg_fast.src index 7c5d9dad9..4f6bd38d7 100644 --- a/src/crt/lneg_fast.src +++ b/src/crt/lneg_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lneg_fast + .type __lneg_fast, @function - section .text - public __lneg_fast __lneg_fast: ld c, e ; c=E ex de, hl ; ude=UHL, l=E diff --git a/src/crt/lnot.src b/src/crt/lnot.src index be6c7643c..6f4633b6c 100644 --- a/src/crt/lnot.src +++ b/src/crt/lnot.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __lnot + .section .text + .global __lnot + .type __lnot, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lnot := 0001D4h + .set __lnot, 0x0001D4 -else +.else __lnot: push af @@ -26,4 +27,4 @@ __lnot: pop de ret -end if +.endif diff --git a/src/crt/lnot_fast.src b/src/crt/lnot_fast.src index 474cd6527..bebf44947 100644 --- a/src/crt/lnot_fast.src +++ b/src/crt/lnot_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lnot_fast + .type __lnot_fast, @function - section .text - public __lnot_fast __lnot_fast: ld a, e ; a=E add hl, de ; uhl=UHL+x diff --git a/src/crt/lpopcnt.src b/src/crt/lpopcnt.src index 33910b767..f7af466f0 100644 --- a/src/crt/lpopcnt.src +++ b/src/crt/lpopcnt.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lpopcnt + .type __lpopcnt, @function - section .text - public __lpopcnt __lpopcnt: push hl ; Calculate 8-popcount(L)-popcount(HLU), and set HLU=H @@ -21,4 +23,4 @@ __lpopcnt: pop hl ret - extern __popcnt_common_init_full, __popcnt_common_iter_adjusted + .extern __popcnt_common_init_full, __popcnt_common_iter_adjusted diff --git a/src/crt/lpopcnt_fast.src b/src/crt/lpopcnt_fast.src index 09076c49c..85c57275c 100644 --- a/src/crt/lpopcnt_fast.src +++ b/src/crt/lpopcnt_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lpopcnt_fast + .type __lpopcnt_fast, @function - section .text - public __lpopcnt_fast __lpopcnt_fast: ; Inlined implementation of __lpopcnt ; Destroys: HL diff --git a/src/crt/lrems.src b/src/crt/lrems.src index 6e848f934..5cbb5a14a 100644 --- a/src/crt/lrems.src +++ b/src/crt/lrems.src @@ -1,15 +1,16 @@ - assume adl=1 + .assume adl=1 - section .text - public __lrems + .section .text + .global __lrems + .type __lrems, @function -;if PREFER_OS_CRT +;.ifdef PREFER_CE_CRT ; ; Bug: Does not ensure `nc` before `sbc hl, hl` to negate divisor. ; -; __lrems := 0001DCh +; .set __lrems, 0x0001DC ; -;else +;.else __lrems: ; I: EUHL=dividend, AUBC=divisor @@ -28,8 +29,8 @@ __lrems: ret z jp __lneg - extern __ldivs_lrems_common - extern __lneg - extern __lremu + .extern __ldivs_lrems_common + .extern __lneg + .extern __lremu -;end if +;.endif diff --git a/src/crt/lremu.src b/src/crt/lremu.src index 32d5012dd..ae6a317f5 100644 --- a/src/crt/lremu.src +++ b/src/crt/lremu.src @@ -1,19 +1,20 @@ - assume adl=1 + .assume adl=1 - section .text - public __lremu + .section .text + .global __lremu + .type __lremu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lremu := 0001E0h + .set __lremu, 0x0001E0 -else +.else __lremu: ; I: EUHL=dividend, AUBC=divisor ; O: euhl=EUHL%AUBC -if 1 +.if 1 call __ldvrmu ld e, a push de @@ -25,7 +26,7 @@ if 1 ei ret -else +.else push ix push iy @@ -36,8 +37,8 @@ else pop iy pop ix ret -end if +.endif - extern __ldvrmu + .extern __ldvrmu -end if +.endif diff --git a/src/crt/lshl.src b/src/crt/lshl.src index 5ee91e53a..e50dfce3b 100644 --- a/src/crt/lshl.src +++ b/src/crt/lshl.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __lshl + .section .text + .global __lshl + .type __lshl, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lshl := 0001E4h + .set __lshl, 0x0001E4 -else +.else __lshl: ; Suboptimal for large shift amounts @@ -19,12 +20,12 @@ __lshl: push bc ld b, l ex (sp), hl -.loop: +.L.loop: add hl, hl rla - djnz .loop + djnz .L.loop ex (sp), hl pop bc ret -end if +.endif diff --git a/src/crt/lshrs.src b/src/crt/lshrs.src index 75ed1121d..05514f488 100644 --- a/src/crt/lshrs.src +++ b/src/crt/lshrs.src @@ -1,13 +1,16 @@ - assume adl=1 + .assume adl=1 - section .text - public __lshrs + .section .text + .global __lshrs + .type __lshrs, @function + .global __lshrs.hijack_lshru + .type __lshrs.hijack_lshru, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lshrs := 0001E8h + .set __lshrs, 0x0001E8 -else +.else __lshrs: ; Suboptimal for large shift amounts @@ -22,10 +25,9 @@ __lshrs: or a, a sbc hl, hl add hl, sp -.loop: +.L.loop: sra a - public __lshrs.hijack_lshru -.hijack_lshru: +__lshrs.hijack_lshru: inc hl inc hl rr (hl) @@ -33,9 +35,9 @@ __lshrs: rr (hl) dec hl rr (hl) - djnz .loop + djnz .L.loop pop bc pop hl ret -end if +.endif diff --git a/src/crt/lshrs_1_fast.src b/src/crt/lshrs_1_fast.src index f5a3d85a6..11c4f8fdf 100644 --- a/src/crt/lshrs_1_fast.src +++ b/src/crt/lshrs_1_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lshru_1_fast + .type __lshru_1_fast, @function - section .text - public __lshru_1_fast __lshru_1_fast: push hl ld hl, 2 diff --git a/src/crt/lshru.src b/src/crt/lshru.src index f73a4972d..a9847843b 100644 --- a/src/crt/lshru.src +++ b/src/crt/lshru.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __lshru + .section .text + .global __lshru + .type __lshru, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lshru := 0001ECh + .set __lshru, 0x0001EC -else +.else __lshru: ; Suboptimal for large shift amounts @@ -22,10 +23,10 @@ __lshru: or a, a sbc hl, hl add hl, sp -.loop: +.L.loop: srl a jp __lshrs.hijack_lshru - extern __lshrs.hijack_lshru + .extern __lshrs.hijack_lshru -end if +.endif diff --git a/src/crt/lshru_1_fast.src b/src/crt/lshru_1_fast.src index 86c81891e..59215d650 100644 --- a/src/crt/lshru_1_fast.src +++ b/src/crt/lshru_1_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lshru_1_fast + .type __lshru_1_fast, @function - section .text - public __lshru_1_fast __lshru_1_fast: push hl ld hl, 2 diff --git a/src/crt/lsub.src b/src/crt/lsub.src index 77c12df06..c540298b1 100644 --- a/src/crt/lsub.src +++ b/src/crt/lsub.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __lsub + .section .text + .global __lsub + .type __lsub, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lsub := 0001F8h + .set __lsub, 0x0001F8 -else +.else __lsub: push af @@ -20,4 +21,4 @@ __lsub: pop af ret -end if +.endif diff --git a/src/crt/lsub_1.src b/src/crt/lsub_1.src index 61a0d8ee0..cb8fa4658 100644 --- a/src/crt/lsub_1.src +++ b/src/crt/lsub_1.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lsub_1 + .type __lsub_1, @function - section .text - public __lsub_1 __lsub_1: add hl, bc or a, a diff --git a/src/crt/lsub_fast.src b/src/crt/lsub_fast.src index 2e8776118..bae978cce 100644 --- a/src/crt/lsub_fast.src +++ b/src/crt/lsub_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lsub_fast + .type __lsub_fast, @function - section .text - public __lsub_fast __lsub_fast: or a, a sbc hl, bc diff --git a/src/crt/ltod.src b/src/crt/ltod.src index cd1d9b571..0299e84aa 100644 --- a/src/crt/ltod.src +++ b/src/crt/ltod.src @@ -1,45 +1,29 @@ - assume adl=1 + .assume adl=1 - __lltod_signal_FE_INEXACT := 0 + .section .text -;------------------------------------------------------------------------------- - - section .text + .global __ulltod ; (long double)unsigned long long + .global __lltod ; (long double)long long + .global __ultod ; (long double)unsigned long + .global __ltod ; (long double)long - public __ulltod -; (long double)unsigned long long __ulltod: cp a, a ; set Z flag push af - jq __lltod_common - -;------------------------------------------------------------------------------- - - section .text - - public __lltod -; (long double)long long + jr .L.lltod_common __lltod: bit 7, b push af call nz, __llneg ; abs(BC:UDE:UHL) - - require __lltod_common - -;------------------------------------------------------------------------------- - - section .text - - private __lltod_common -__lltod_common: +.L.lltod_common: call __llctlz sub a, 63 ; normalize clz_result ; filter out exponent of $000 (zero) and $3FF (one) - jr nc, __int_to_f64_zero_or_one + jr nc, .L.int_to_f64_zero_or_one ; A is [-63, -1] add a, 52 ; A is [-11, 51] - jr c, __int_to_f64_shl + jr c, .L.int_to_f64_shl ; __int_to_f64_shr: ; exponent = (1023 or $3FF or f64_bias) + base2_logarithm ; Minimum exponent: $434 (2^53) @@ -53,32 +37,32 @@ __lltod_common: ld b, a ld c, a xor a, a -.shift_loop: +.L.shift_loop: adc a, 0 srl h rr l - djnz .shift_loop + djnz .L.shift_loop ; round upwards to even if (round && (guard || sticky)) - jr nc, .no_round + jr nc, .L.no_round ; we must ensure that FE_INEXACT is raised since rounding has occured or a, a ; test sticky bits - jr nz, .round_up + jr nz, .L.round_up inc a ; ld a, 1 and a, l ; test guard bit - jr z, .no_round_inexact -.round_up: + jr z, .L.no_round_inexact +.L.round_up: inc b ; round up after shifting -.no_round: -if __lltod_signal_FE_INEXACT +.L.no_round: +.if 0 ; FE_INEXACT adc a, a ; test sticky and round bits - jr z, .result_is_exact -.no_round_inexact: + jr z, .L.result_is_exact +.L.no_round_inexact: ld hl, ___fe_cur_env set 5, (hl) ; FE_INEXACT -.result_is_exact: -else -.no_round_inexact: -end if +.L.result_is_exact: +.else +.L.no_round_inexact: +.endif ld h, b ld a, c ld l, c @@ -98,90 +82,57 @@ end if pop af ; A = rounding or a, a ; NZ = round-up, Z = no-round ld b, $43 -if 0 - jr z, __int_to_f64_shl.no_round +.if 0 + jr z, .L.int_to_f64_shl.no_round ; inlined __lladd_1 inc hl add hl, de or a, a sbc hl, de - jr nz, __int_to_f64_shl.finish + jr nz, .L.int_to_f64_shl.finish inc de sbc hl, de add hl, de - jr nz, __int_to_f64_shl.finish + jr nz, .L.int_to_f64_shl.finish inc bc - jr __int_to_f64_shl.finish -else + jr .L.int_to_f64_shl.finish +.else call nz, __lladd_1 ; round up to even - jr __int_to_f64_shl.finish -end if + jr .L.int_to_f64_shl.finish +.endif -;------------------------------------------------------------------------------- - - section .text - - private __int_to_f64_zero_or_one -__int_to_f64_zero_or_one: +.L.int_to_f64_zero_or_one: ; carry is cleared here ; UHL is either one or zero ld b, h ld c, h - jr nz, .ret_zero + jr nz, .L.ret_zero ld bc, $3FF0 dec hl ; ld hl, 0 -.ret_zero: +.L.ret_zero: ex de, hl sbc hl, hl - jr __int_to_f64_shl.finish - -;------------------------------------------------------------------------------- - - section .text + jr .L.int_to_f64_shl.finish - public __ultod -; (long double)unsigned long __ultod: cp a, a ; set Z flag push af - jq __ltod_common - -;------------------------------------------------------------------------------- - - section .text - - public __ltod -; (long double)long + jr .L.ltod_common __ltod: bit 7, e push af call nz, __lneg ; abs(E:UHL) - - require __ltod_common - -;------------------------------------------------------------------------------- - - section .text - - private __ltod_common -__ltod_common: +.L.ltod_common: call __lctlz sub a, 31 ; normalize clz_result ; filter out exponent of $000 (zero) and $3FF (one) - jr nc, __int_to_f64_zero_or_one + jr nc, .L.int_to_f64_zero_or_one ; A is [-31, -1] add a, 52 ; A is [21, 51] - require __int_to_f64_shl - -;------------------------------------------------------------------------------- - - section .text - - private __int_to_f64_shl -__int_to_f64_shl: +.L.int_to_f64_shl: ; exponent = (1023 or $3FF or f64_bias) + base2_logarithm ; Minimum exponent: $400 (2^1) ; Maximum exponent: $434 (2^52) @@ -210,8 +161,8 @@ __int_to_f64_shl: ld c, a ld b, h pop hl ; restore shifted HL -.no_round: -.finish: +.L.int_to_f64_shl.no_round: +.L.int_to_f64_shl.finish: pop af ret z set 7, b @@ -219,11 +170,11 @@ __int_to_f64_shl: ;------------------------------------------------------------------------------- - extern __lneg - extern __lctlz - extern __llctlz - extern __llshl - extern __llshru - extern __llneg - extern __lladd_1 - extern ___fe_cur_env + .extern __lneg + .extern __lctlz + .extern __llctlz + .extern __llshl + .extern __llshru + .extern __llneg + .extern __lladd_1 + .extern ___fe_cur_env diff --git a/src/crt/makefile b/src/crt/makefile index 5029cd42a..0cb8d0121 100644 --- a/src/crt/makefile +++ b/src/crt/makefile @@ -16,16 +16,23 @@ include $(CURDIR)/../common.mk -BUILD_SRC := $(patsubst %,build/%.src,$(wildcard *.c *.cpp)) +OBJECTS = +OBJECTS += $(patsubst %.c,build/%.c.o,$(wildcard *.c)) +OBJECTS += $(patsubst %.cpp,build/%.cpp.o,$(wildcard *.cpp)) +OBJECTS += $(patsubst %.src,build/%.o,$(wildcard *.src)) -EZCFLAGS := -S -fno-addrsig -ffreestanding -Wall -Wextra -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -EZCFLAGS += -D_EZ80 -isystem ../libc/include -mllvm -profile-guided-section-prefix=false -EZCXXFLAGS := $(EZCFLAGS) -fno-exceptions -fno-rtti -EZCXXFLAGS += -isystem ../libc/include/c++ +OBJECTS_CE = +OBJECTS_CE += $(patsubst %.c,build/%.c.ce.o,$(wildcard *.c)) +OBJECTS_CE += $(patsubst %.cpp,build/%.cpp.ce.o,$(wildcard *.cpp)) +OBJECTS_CE += $(patsubst %.src,build/%.ce.o,$(wildcard *.src)) -WILDCARD_SRC = $(wildcard *.src) $(BUILD_SRC) +.SECONDARY: -all: $(BUILD_SRC) +all: build/libcrt.a build/libcrt_ce.a + +build/libcrt.a: $(OBJECTS) + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ build/%.c.src: %.c $(Q)$(call MKDIR,build) @@ -35,11 +42,51 @@ build/%.cpp.src: %.cpp $(Q)$(call MKDIR,build) $(Q)$(EZCC) $(EZCXXFLAGS) $< -o $@ +build/%.c.o: build/%.c.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.cpp.o: build/%.cpp.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.o: %.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +# ----- + +build/libcrt_ce.a: $(OBJECTS_CE) + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ + +build/%.c.ce.src: %.c + $(Q)$(call MKDIR,build) + $(Q)$(EZCC) $(EZCFLAGS) $< -o $@ + +build/%.cpp.ce.src: %.cpp + $(Q)$(call MKDIR,build) + $(Q)$(EZCC) $(EZCXXFLAGS) $< -o $@ + +build/%.c.ce.o: build/%.c.ce.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) --defsym PREFER_CE_CRT=1 $< -o $@ + +build/%.cpp.ce.o: build/%.cpp.ce.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) --defsym PREFER_CE_CRT=1 $< -o $@ + +build/%.ce.o: %.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) --defsym PREFER_CE_CRT=1 $< -o $@ + clean: $(Q)$(call RMDIR,build) install: all $(Q)$(call MKDIR,$(INSTALL_CRT)) - $(Q)$(call COPY,$(call NATIVEPATH,$(WILDCARD_SRC)),$(INSTALL_CRT)) + $(Q)$(call COPY,$(call NATIVEPATH,build/libcrt.a),$(INSTALL_CRT)) + $(Q)$(call COPY,$(call NATIVEPATH,build/libcrt_ce.a),$(INSTALL_CRT)) + $(Q)$(call COPY,$(call NATIVEPATH,crt0.S),$(INSTALL_CRT)) -.PHONY: all clean +.PHONY: all clean install diff --git a/src/crt/or.src b/src/crt/or.src index f920d8519..507d99203 100644 --- a/src/crt/or.src +++ b/src/crt/or.src @@ -1,43 +1,28 @@ - assume adl=1 + .assume adl=1 - section .text - public __lor + .section .text + .global __lor + .type __lor, @function + .global __ior + .type __ior, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lor := 0001D8h + .set __lor, 0x0001D8 + .set __ior, 0x000168 -else +.else __lor: ; CC: 28*r(PC)+11*r(SPL)+10*w(SPL)+1 push af or a, e ld e, a -; jr __ior.hijack_lor - virtual - ld a, 0 - load .ld_a: byte from $$ - end virtual - db .ld_a ; push af -> ld a,* - require __ior - -end if - - section .text - public __ior - -if PREFER_OS_CRT - -__ior := 000168h - -else - + jr .L.hijack_lor __ior: ; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1 push af - private __ior.hijack_lor -.hijack_lor: +.L.hijack_lor: push hl scf sbc hl, hl @@ -60,4 +45,4 @@ __ior: pop af ret -end if +.endif diff --git a/src/crt/or_fast.src b/src/crt/or_fast.src index e24c42af7..8daae4cd7 100644 --- a/src/crt/or_fast.src +++ b/src/crt/or_fast.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lor_fast + .type __lor_fast, @function + .global __ior_fast + .type __ior_fast, @function + .global __sor_fast + .type __sor_fast, @function - section .text - public __lor_fast __lor_fast: ; CC: 24*r(PC)+8*r(SPL)+7*w(SPL)+1 or a, e ld e, a - require __ior_fast - - section .text - public __ior_fast __ior_fast: ; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1 push hl @@ -25,10 +27,6 @@ __ior_fast: or a, (hl) ld (hl), a pop hl - require __sor_fast - - section .text - public __sor_fast __sor_fast: ; CC: 8*r(PC)+3*r(SPL)+1 ld a, h diff --git a/src/crt/os.src b/src/crt/os.src index 69e445aa6..7e5f606d0 100644 --- a/src/crt/os.src +++ b/src/crt/os.src @@ -1,40 +1,58 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __fadd -__fadd := 000270h - public __fcmp -__fcmp := 000274h - public __fdiv -__fdiv := 000278h - public __fmul -__fmul := 000288h - public __fsub -__fsub := 000290h - public __ftol -__ftol := 00027Ch - public __ftoul -__ftoul := __ftol - public __indcall -__indcall := 00015Ch - public __ishl_b -__ishl_b := 000178h - public __ishrs_b -__ishrs_b := 000180h - public __ishru_b -__ishru_b := 000188h - public __itol -__itol := 000194h - public __ltof -__ltof := 000284h - public __sshl_b -__sshl_b := 000244h - public __sshrs_b -__sshrs_b := 00024Ch - public __sshru_b -__sshru_b := 000254h - public __stoi -__stoi := 000260h - public __stoiu -__stoiu := 000264h + .global __fadd + .type __fadd, @function + .set __fadd, 0x000270 + .global __fcmp + .type __fcmp, @function + .set __fcmp, 0x000274 + .global __fdiv + .type __fdiv, @function + .set __fdiv, 0x000278 + .global __fmul + .type __fmul, @function + .set __fmul, 0x000288 + .global __fsub + .type __fsub, @function + .set __fsub, 0x000290 + .global __ftol + .type __ftol, @function + .set __ftol, 0x00027C + .global __ftoul + .type __ftoul, @function + .set __ftoul, __ftol + .global __indcall + .type __indcall, @function + .set __indcall, 0x00015C + .global __ishl_b + .type __ishl_b, @function + .set __ishl_b, 0x000178 + .global __ishrs_b + .type __ishrs_b, @function + .set __ishrs_b, 0x000180 + .global __ishru_b + .type __ishru_b, @function + .set __ishru_b, 0x000188 + .global __itol + .type __itol, @function + .set __itol, 0x000194 + .global __ltof + .type __ltof, @function + .set __ltof, 0x000284 + .global __sshl_b + .type __sshl_b, @function + .set __sshl_b, 0x000244 + .global __sshrs_b + .type __sshrs_b, @function + .set __sshrs_b, 0x00024C + .global __sshru_b + .type __sshru_b, @function + .set __sshru_b, 0x000254 + .global __stoi + .type __stoi, @function + .set __stoi, 0x000260 + .global __stoiu + .type __stoiu, @function + .set __stoiu, 0x000264 diff --git a/src/crt/popcnt_common.src b/src/crt/popcnt_common.src index 7c04ea016..41325518f 100644 --- a/src/crt/popcnt_common.src +++ b/src/crt/popcnt_common.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __popcnt_common_init_full + .type __popcnt_common_init_full, @function - section .text - public __popcnt_common_init_full __popcnt_common_init_full: ; Calculates a combined popcount of L and HLU. ; Note the carry flag must be combined with A on return. @@ -9,7 +11,9 @@ __popcnt_common_init_full: ; O: A-cf=8-popcount(L)-popcount(HLU), HLU=H, L=0 ld a, l - public __popcnt_common_init + .global __popcnt_common_init + .type __popcnt_common_init, @function + __popcnt_common_init: ; Same as above, but input is in A and HLU. @@ -21,7 +25,9 @@ __popcnt_common_init: ; since the code below is subtracting it by a factor of 0xFF. sub a, h - public __popcnt_common_iter + .global __popcnt_common_iter + .type __popcnt_common_iter, @function + __popcnt_common_iter: ; Calculates a popcount accumulation. ; Note the carry flag must be combined with A on return. @@ -29,7 +35,9 @@ __popcnt_common_iter: ; O: A-cf=A+popcount(L)-popcount(HLU)+H-L, HLU=H, L=0 sub a, h - public __popcnt_common_iter_adjusted + .global __popcnt_common_iter_adjusted + .type __popcnt_common_iter_adjusted, @function + __popcnt_common_iter_adjusted: ; Same as above, but an additional H is accumulated into A. ; This is the same popcount technique as described in __bpopcnt, diff --git a/src/crt/sand.src b/src/crt/sand.src index f89111151..e9e0017ca 100644 --- a/src/crt/sand.src +++ b/src/crt/sand.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __sand + .section .text + .global __sand + .type __sand, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__sand := 000200h + .set __sand, 0x000200 -else +.else __sand: push af @@ -20,4 +21,4 @@ __sand: pop af ret -end if +.endif diff --git a/src/crt/sbitrev.src b/src/crt/sbitrev.src index 6d8663bc0..728eddf8b 100644 --- a/src/crt/sbitrev.src +++ b/src/crt/sbitrev.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __sbitrev + .type __sbitrev, @function - section .text - public __sbitrev __sbitrev: push af ld a, l ; a=L @@ -15,4 +17,4 @@ __sbitrev: pop af ret - extern __internal_bitrev_two_bytes + .extern __internal_bitrev_two_bytes diff --git a/src/crt/scmpzero.src b/src/crt/scmpzero.src index 4fc7510d8..868c16a52 100644 --- a/src/crt/scmpzero.src +++ b/src/crt/scmpzero.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __scmpzero + .type __scmpzero, @function - section .text - public __scmpzero __scmpzero: add hl, de or a, a diff --git a/src/crt/sdivs.src b/src/crt/sdivs.src index 15cb9b588..6e4308d3c 100644 --- a/src/crt/sdivs.src +++ b/src/crt/sdivs.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __sdivs + .section .text + .global __sdivs + .type __sdivs, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__sdivs := 000208h + .set __sdivs, 0x000208 -else +.else __sdivs: ; I: HL=dividend, BC=divisor @@ -23,7 +24,7 @@ __sdivs: jp __ineg - extern __ineg - extern __sdvrms_abs + .extern __ineg + .extern __sdvrms_abs -end if +.endif diff --git a/src/crt/sdivu.src b/src/crt/sdivu.src index 219d2e8bb..d25b036b7 100644 --- a/src/crt/sdivu.src +++ b/src/crt/sdivu.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __sdivu + .section .text + .global __sdivu + .type __sdivu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__sdivu := 00020Ch + .set __sdivu, 0x00020C -else +.else __sdivu: ; I: HL=dividend, BC=divisor @@ -21,6 +22,6 @@ __sdivu: pop de ret - extern __sdvrmu + .extern __sdvrmu -end if +.endif diff --git a/src/crt/sdvrms_abs.src b/src/crt/sdvrms_abs.src index 9bbb1496b..0d2d82f8b 100644 --- a/src/crt/sdvrms_abs.src +++ b/src/crt/sdvrms_abs.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __sdvrms_abs + .type __sdvrms_abs, @function - section .text - public __sdvrms_abs __sdvrms_abs: ; I: HL=dividend, BC=divisor ; O: ude=abs(HL)/abs(BC), uhl=abs(HL)%abs(BC), sf=(HL<0)^(BC<0), cf=HL<0 @@ -16,23 +18,23 @@ __sdvrms_abs: ld a, e push af - jr nc, .neg_dividend_skip + jr nc, .L.neg_dividend_skip add hl, de ex de, hl or a, a sbc hl, de -.neg_dividend_skip: +.L.neg_dividend_skip: ld a, b rla - jr nc, .neg_divisor_skip + jr nc, .L.neg_divisor_skip xor a, a sub a, c ld c, a sbc a, a sub a, b ld b, a -.neg_divisor_skip: +.L.neg_divisor_skip: pop af call __sdvrmu @@ -41,4 +43,4 @@ __sdvrms_abs: ret - extern __sdvrmu + .extern __sdvrmu diff --git a/src/crt/sdvrmu.src b/src/crt/sdvrmu.src index ce6132ae8..12d160c1a 100644 --- a/src/crt/sdvrmu.src +++ b/src/crt/sdvrmu.src @@ -1,7 +1,8 @@ - assume adl=1 + .assume adl=1 - section .text - public __sdvrmu + .section .text + .global __sdvrmu + .type __sdvrmu, @function __sdvrmu: ; I: HL=dividend, BC=divisor @@ -21,4 +22,4 @@ __sdvrmu: jp __idvrmu.hijack_a_iters_ude_dividend - extern __idvrmu.hijack_a_iters_ude_dividend + .extern __idvrmu.hijack_a_iters_ude_dividend diff --git a/src/crt/setflag.src b/src/crt/setflag.src index 09789d862..4e6439961 100644 --- a/src/crt/setflag.src +++ b/src/crt/setflag.src @@ -1,14 +1,15 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __setflag + .global __setflag + .type __setflag, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__setflag := 000218h + .set __setflag, 0x000218 -else +.else __setflag: ret po @@ -21,4 +22,4 @@ __setflag: pop af ret -end if +.endif diff --git a/src/crt/smulu.src b/src/crt/smulu.src index 799ed6ca1..ea92bce84 100644 --- a/src/crt/smulu.src +++ b/src/crt/smulu.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public __smuls - public __smulu + .section .text + .global __smuls + .type __smuls, @function + .global __smulu + .type __smulu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__smuls := 000224h -__smulu := 000228h + .set __smuls, 0x000224 + .set __smulu, 0x000228 -else +.else __smuls: __smulu: @@ -20,7 +22,7 @@ __smulu: ; FO: c=!ADL&&(L*C+(H*C+L*B<<8&0xFFFF)>>16) ; CC: 20*r(PC)+(ADL?6*r(SPL)+3*w(SPL):4*r(SPS)+2*w(SPS))+13 ; ude uhl u(sp) -Mul_HL_BC_HL: ;--------------+---------------+---------------- +.L.Mul_HL_BC_HL: ;--------------+---------------+---------------- push de ; u(sp)=UDE ld d, h ; d =H ld e, c ; de=HC @@ -40,4 +42,4 @@ Mul_HL_BC_HL: ;--------------+---------------+---------------- ; HL*BC&0xFFFF=L*C+(H*C+L*B<<8)+(H*B<<16)&0xFFFF ; =L*C+(H*C+L*B<<8)&0xFFFF -end if +.endif diff --git a/src/crt/smulu_b.src b/src/crt/smulu_b.src index ef083bb41..215c704e2 100644 --- a/src/crt/smulu_b.src +++ b/src/crt/smulu_b.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __smulu_b + .global __smulu_b + .type __smulu_b, @function __smulu_b: @@ -11,7 +12,7 @@ __smulu_b: ; O: hl=HL*A ; CC: 15*r(PC)+6*r(SPL)+3*w(SPL)+9 ; CC: 14 bytes | 15F + 6R + 3W + 9 -Mul_HL_A_HL: +.L.Mul_HL_A_HL: push de ld e, a ld d, h diff --git a/src/crt/smulu_b_fast.src b/src/crt/smulu_b_fast.src index 82cb91739..2c6302e95 100644 --- a/src/crt/smulu_b_fast.src +++ b/src/crt/smulu_b_fast.src @@ -1,10 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __smulu_b_fast + .global __smulu_b_fast + .type __smulu_b_fast, @function __smulu_b_fast: @@ -13,7 +14,7 @@ __smulu_b_fast: ; O: hl=HL*A ; CC: 12*r(PC)+3*r(SPL)+9 ; CC: 11 bytes | 12F + 3R + 9 -Mul_HL_A_HL_Fast: +.L.Mul_HL_A_HL_Fast: ; destroys DE and A. You can swap DE with BC to destroy BC instead ld e, a ld d, h diff --git a/src/crt/smulu_fast.src b/src/crt/smulu_fast.src index 434997af9..183035da2 100644 --- a/src/crt/smulu_fast.src +++ b/src/crt/smulu_fast.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __smuls_fast + .type __smuls_fast, @function + .global __smulu_fast + .type __smulu_fast, @function - section .text - public __smuls_fast, __smulu_fast __smuls_fast: __smulu_fast: @@ -11,7 +15,7 @@ __smulu_fast: ; FO: sz(h), p/v=?, c=? ; CC: 16*r(PC)+(ADL?3*r(SPL):2*r(SPS))+13 ; a ubc ude uhl -Mul_HL_BC_HL_Fast: ;--------------+---------------+---------------+---------------- +.L.Mul_HL_BC_HL_Fast: ;--------------+---------------+---------------+---------------- ld d, b ld e, l ; de=BL ld b, h ; bc=HC diff --git a/src/crt/sneg.src b/src/crt/sneg.src deleted file mode 100644 index 13ae118c8..000000000 --- a/src/crt/sneg.src +++ /dev/null @@ -1,16 +0,0 @@ - assume adl=1 - - section .text - public __sneg - -if PREFER_OS_CRT - -__sneg := 00022Ch - -else - -__sneg := __ineg - - extern __ineg - -end if diff --git a/src/crt/sneg_fast.src b/src/crt/sneg_fast.src deleted file mode 100644 index dac70fdd7..000000000 --- a/src/crt/sneg_fast.src +++ /dev/null @@ -1,7 +0,0 @@ - assume adl=1 - - section .text - public __sneg_fast -__sneg_fast := __ineg_fast - - extern __ineg_fast diff --git a/src/crt/snot.src b/src/crt/snot.src deleted file mode 100644 index 798121a3c..000000000 --- a/src/crt/snot.src +++ /dev/null @@ -1,16 +0,0 @@ - assume adl=1 - - section .text - public __snot - -if PREFER_OS_CRT - -__snot := 000230h - -else - -__snot := __inot - - extern __inot - -end if diff --git a/src/crt/snot_fast.src b/src/crt/snot_fast.src deleted file mode 100644 index 6ebdb78cf..000000000 --- a/src/crt/snot_fast.src +++ /dev/null @@ -1,7 +0,0 @@ - assume adl=1 - - section .text - public __snot_fast -__snot_fast := __inot_fast - - extern __inot_fast diff --git a/src/crt/sor.src b/src/crt/sor.src index bfa52610e..c2e60ecb4 100644 --- a/src/crt/sor.src +++ b/src/crt/sor.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __sor + .section .text + .global __sor + .type __sor, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__sor := 000234h + .set __sor, 0x000234 -else +.else __sor: push af @@ -20,4 +21,4 @@ __sor: pop af ret -end if +.endif diff --git a/src/crt/spopcnt.src b/src/crt/spopcnt.src index e4f86fa84..2202e6e04 100644 --- a/src/crt/spopcnt.src +++ b/src/crt/spopcnt.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __spopcnt + .type __spopcnt, @function - section .text - public __spopcnt __spopcnt: ; Set HLU=H and H=L, while saving HL on the stack push hl @@ -17,4 +19,4 @@ __spopcnt: inc sp ret - extern __popcnt_common_init + .extern __popcnt_common_init diff --git a/src/crt/spopcnt_fast.src b/src/crt/spopcnt_fast.src index ac887684d..638214571 100644 --- a/src/crt/spopcnt_fast.src +++ b/src/crt/spopcnt_fast.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __spopcnt_fast + .type __spopcnt_fast, @function - section .text - public __spopcnt_fast __spopcnt_fast: ; Inlined implementation of __spopcnt ; Destroys: HL diff --git a/src/crt/srems.src b/src/crt/srems.src index 31c5747b5..9f99ebf17 100644 --- a/src/crt/srems.src +++ b/src/crt/srems.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __srems + .section .text + .global __srems + .type __srems, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__srems := 000238h + .set __srems, 0x000238 -else +.else __srems: ; I: HL=dividend, BC=divisor @@ -22,7 +23,7 @@ __srems: jp __ineg - extern __ineg - extern __sdvrms_abs + .extern __ineg + .extern __sdvrms_abs -end if +.endif diff --git a/src/crt/sremu.src b/src/crt/sremu.src index 1e37f8ff2..f37b55b96 100644 --- a/src/crt/sremu.src +++ b/src/crt/sremu.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __sremu + .section .text + .global __sremu + .type __sremu, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__sremu := 00023Ch + .set __sremu, 0x00023C -else +.else __sremu: ; I: HL=dividend, BC=divisor @@ -20,6 +21,6 @@ __sremu: pop de ret - extern __sdvrmu + .extern __sdvrmu -end if +.endif diff --git a/src/crt/sshl.src b/src/crt/sshl.src deleted file mode 100644 index 8bd3148ce..000000000 --- a/src/crt/sshl.src +++ /dev/null @@ -1,16 +0,0 @@ - assume adl=1 - - section .text - public __sshl - -if PREFER_OS_CRT - -__sshl := 000240h - -else - -__sshl := __ishl - - extern __ishl - -end if diff --git a/src/crt/sshrs.src b/src/crt/sshrs.src index 5d2ea18df..3fdb76d7f 100644 --- a/src/crt/sshrs.src +++ b/src/crt/sshrs.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __sshrs + .section .text + .global __sshrs + .type __sshrs, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__sshrs := 000248h + .set __sshrs, 0x000248 -else +.else __sshrs: ; Suboptimal for large shift amounts @@ -18,11 +19,11 @@ __sshrs: ret z push bc ld b, c -.loop: +.L.loop: sra h rr l - djnz .loop + djnz .L.loop pop bc ret -end if +.endif diff --git a/src/crt/sshru.src b/src/crt/sshru.src index 5362640c7..45025945a 100644 --- a/src/crt/sshru.src +++ b/src/crt/sshru.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __sshru + .section .text + .global __sshru + .type __sshru, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__sshru := 000250h + .set __sshru, 0x000250 -else +.else __sshru: ; Suboptimal for large shift amounts @@ -18,11 +19,11 @@ __sshru: ret z push bc ld b, c -.loop: +.L.loop: srl h rr l - djnz .loop + djnz .L.loop pop bc ret -end if +.endif diff --git a/src/crt/sxor.src b/src/crt/sxor.src index deabf65da..266d78707 100644 --- a/src/crt/sxor.src +++ b/src/crt/sxor.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public __sxor + .section .text + .global __sxor + .type __sxor, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__sxor := 000268h + .set __sxor, 0x000268 -else +.else __sxor: push af @@ -20,4 +21,4 @@ __sxor: pop af ret -end if +.endif diff --git a/src/crt/ulltof.src b/src/crt/ulltof.src index 9799978a1..344cd81d1 100644 --- a/src/crt/ulltof.src +++ b/src/crt/ulltof.src @@ -1,15 +1,23 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __ulltof + .type __ulltof, @function - section .text - public __ulltof __ulltof: - push af, iy, bc, de, hl + push af + push iy + push bc + push de + push hl call __ulltof_c pop af ld a, e pop de ld e, a - pop bc, iy, af + pop bc + pop iy + pop af ret - extern __ulltof_c + .extern __ulltof_c diff --git a/src/crt/ultof.src b/src/crt/ultof.src index 7472a6d8d..360ebef57 100644 --- a/src/crt/ultof.src +++ b/src/crt/ultof.src @@ -1,10 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __ultof + .global __ultof + .type __ultof, @function -if 0 +.if 0 ; round to nearest ties to even __ultof: @@ -28,7 +29,7 @@ __ultof: res 0, c ret -else +.else ; round to nearest ties away from zero (to match __ltof behaviour) __ultof: @@ -49,6 +50,6 @@ __ultof: inc bc ret ; round up (this will not overflow because bit 23 is 0) -end if +.endif - extern __ltof + .extern __ltof diff --git a/src/crt/xor.src b/src/crt/xor.src index c9af87b63..c72a8c019 100644 --- a/src/crt/xor.src +++ b/src/crt/xor.src @@ -1,43 +1,28 @@ - assume adl=1 + .assume adl=1 - section .text - public __lxor + .section .text + .global __lxor + .type __lxor, @function + .global __ixor + .type __ixor, @function -if PREFER_OS_CRT +.ifdef PREFER_CE_CRT -__lxor := 0001FCh + .set __lxor, 0x0001FC + .set __ixor, 0x000198 -else +.else __lxor: ; CC: 28*r(PC)+11*r(SPL)+10*w(SPL)+1 push af xor a, e ld e, a -; jr __ixor.hijack_lxor - virtual - ld a, 0 - load .ld_a: byte from $$ - end virtual - db .ld_a ; push af -> ld a,* - require __ixor - -end if - - section .text - public __ixor - -if PREFER_OS_CRT - -__ixor := 000198h - -else - + jr .L.hijack_lxor __ixor: ; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1 push af - private __ixor.hijack_lxor -.hijack_lxor: +.L.hijack_lxor: push hl scf sbc hl, hl @@ -60,4 +45,4 @@ __ixor: pop af ret -end if +.endif diff --git a/src/crt/xor_fast.src b/src/crt/xor_fast.src index d039ba4b7..63cf70fe6 100644 --- a/src/crt/xor_fast.src +++ b/src/crt/xor_fast.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global __lxor_fast + .type __lxor_fast, @function + .global __ixor_fast + .type __ixor_fast, @function + .global __sxor_fast + .type __sxor_fast, @function - section .text - public __lxor_fast __lxor_fast: ; CC: 24*r(PC)+8*r(SPL)+7*w(SPL)+1 xor a, e ld e, a - require __ixor_fast - - section .text - public __ixor_fast __ixor_fast: ; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1 push hl @@ -25,10 +27,6 @@ __ixor_fast: xor a, (hl) ld (hl), a pop hl - require __sxor_fast - - section .text - public __sxor_fast __sxor_fast: ; CC: 8*r(PC)+3*r(SPL)+1 ld a, h diff --git a/src/libc/abs.src b/src/libc/abs.src index 7ce0aa087..01ccb032c 100644 --- a/src/libc/abs.src +++ b/src/libc/abs.src @@ -1,7 +1,8 @@ - assume adl=1 + .assume ADL=1 - section .text - public _abs + .section .text + .global _abs + .type _abs,@function _abs: pop hl pop de diff --git a/src/libc/acosf.src b/src/libc/acosf.src index 581200720..d45519155 100644 --- a/src/libc/acosf.src +++ b/src/libc/acosf.src @@ -1,14 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public _acos, _acosf + .section .text + .global _acos + .type _acos, @function + .global _acosf + .type _acosf, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_acosf := 022100h -_acos := _acosf + .set _acosf, 0x022100 + .set _acos, _acosf -else +.else _acos: _acosf: @@ -26,19 +29,21 @@ _acosf: call __fcmp pop bc pop hl - jp m,l_1 + jp m, .L1 ld e,a ld a,191 call __fcmp - jp p,l_2 + jp p, .L2 -l_1: ld hl,4 +.L1: + ld hl,4 ld (_errno),hl ld l,h ld e,h ret -l_2: push de +.L2: + push de push hl call _asin pop bc @@ -51,10 +56,10 @@ l_2: push de ld e,a ret - extern __frameset0 - extern __fcmp - extern __fsub - extern _asin - extern _errno + .extern __frameset0 + .extern __fcmp + .extern __fsub + .extern _asin + .extern _errno -end if +.endif diff --git a/src/libc/allocator.src b/src/libc/allocator.src deleted file mode 100644 index 56a72b59c..000000000 --- a/src/libc/allocator.src +++ /dev/null @@ -1,105 +0,0 @@ - assume adl=1 - - section .text - public _malloc, _free, _realloc - - public _calloc - -if defined __TICE__ - -; uses the hardware specific $E40000 memory location - -; void *calloc(size_t nmemb, size_t size) -_calloc: - pop de - pop bc - ex (sp), hl - push bc - push de - call __imulu - push hl - push hl - call _malloc - pop bc ; reset SP - pop bc ; BC = size - ; test for NULL - add hl, bc - ; or a, a ; assumes that ptr + size does not overflow - sbc hl, bc - ret z ; return NULL - ; inlined bzero - push hl - ex de, hl ; DE = dest - ; test if the size is zero - scf - sbc hl, hl - add hl, bc - jr nc, .finish - ; large region of all zeros on the Ti84CE - ld hl, $E40000 ; HL = src - ldir -.finish: - pop hl ; return value - ret - -else - -; makes no hardware assumptions - -; void *calloc(size_t nmemb, size_t size) -_calloc: - pop de - pop bc - ex (sp),hl - push bc - push de - call __imulu - push hl - push hl - call _malloc - pop de - add hl,de - xor a,a - sbc hl,de - ld e,a - push de - push hl - call nz,_memset - pop de - pop de - pop de - ret - -end if - -if defined ALLOCATOR_SIMPLE - -_malloc := __simple_malloc -_free := __simple_free -_realloc := __simple_realloc - extern __simple_free - extern __simple_malloc - extern __simple_realloc - -else if defined ALLOCATOR_STANDARD - -_malloc := __standard_malloc -_free := __standard_free -_realloc := __standard_realloc - extern __standard_malloc - extern __standard_free - extern __standard_realloc - -else ; custom functions provided by the program - -_malloc := __custom_malloc -_free := __custom_free -_realloc := __custom_realloc - extern __custom_malloc - extern __custom_free - extern __custom_realloc - -end if - - extern __imulu - extern _memset diff --git a/src/libc/allocator/allocator_simple.src b/src/libc/allocator/allocator_simple.src new file mode 100644 index 000000000..7ceb3cedf --- /dev/null +++ b/src/libc/allocator/allocator_simple.src @@ -0,0 +1,43 @@ + .assume adl = 1 + + .section .text._malloc + + .global _malloc + .type _malloc, @function + + .global _free + .type _free, @function + + .global _realloc + .type _realloc, @function + +_malloc: + ; returns NULL when size is zero + pop bc + ex (sp), hl + push bc + ld de, (_heap_ptr) + dec hl + add hl, de + jr c, .L.null + ld bc, ___heap_high - 1 + sbc hl, bc + jr nc, .L.null + add hl, bc + ld (_heap_ptr), hl + ex de, hl + ret +.L.null: +_realloc: + or a, a + sbc hl, hl +_free: + ret + + .section .data._heap_ptr + .local _heap_ptr +_heap_ptr: + .d24 ___heap_low + + .extern ___heap_low + .extern ___heap_high diff --git a/src/libc/allocator_standard.c b/src/libc/allocator/allocator_standard.c similarity index 89% rename from src/libc/allocator_standard.c rename to src/libc/allocator/allocator_standard.c index 235f57a2c..3d7be97e7 100644 --- a/src/libc/allocator_standard.c +++ b/src/libc/allocator/allocator_standard.c @@ -9,12 +9,12 @@ typedef struct __attribute__((packed)) block size_t size; } __attribute__((packed)) block_t; -extern uint8_t __heapbot[]; -extern uint8_t __heaptop[]; -static uintptr_t heap_ptr = (uintptr_t)__heapbot; +extern uint8_t __heap_low[]; +extern uint8_t __heap_high[]; +static uintptr_t heap_ptr = (uintptr_t)__heap_low; static block_t _alloc_base; -void *_standard_malloc(size_t alloc_size) +void *malloc(size_t alloc_size) { block_t *q; block_t *r; @@ -47,7 +47,7 @@ void *_standard_malloc(size_t alloc_size) } /* compute next heap pointer */ - if (heap_ptr + size < heap_ptr || heap_ptr + size >= (uintptr_t)__heaptop) + if (heap_ptr + size < heap_ptr || heap_ptr + size >= (uintptr_t)__heap_high) { return NULL; } @@ -60,7 +60,7 @@ void *_standard_malloc(size_t alloc_size) return r + 1; } -void _standard_free(void *ptr) +void free(void *ptr) { if (ptr != NULL) { @@ -93,7 +93,7 @@ void _standard_free(void *ptr) } } -void *_standard_realloc(void *ptr, size_t size) +void *realloc(void *ptr, size_t size) { block_t *h; void *p; diff --git a/src/libc/allocator/makefile b/src/libc/allocator/makefile new file mode 100644 index 000000000..bc6af0b36 --- /dev/null +++ b/src/libc/allocator/makefile @@ -0,0 +1,55 @@ +# Copyright (C) 2015-2025 CE Programming +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +include $(CURDIR)/../../common.mk + +.SECONDARY: + +all: build/allocator_standard.a build/allocator_simple.a + +# --- allocator_simple + +build/allocator_simple.a: build/allocator_simple.o + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ + +build/allocator_simple.o: allocator_simple.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +# --- allocator_standard + +build/allocator_standard.a: build/allocator_standard.o + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ + +build/allocator_standard.o: build/allocator_standard.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/allocator_standard.src: allocator_standard.c + $(Q)$(call MKDIR,build) + $(Q)$(EZCC) $(EZCFLAGS) $< -o $@ + +clean: + $(Q)$(call RMDIR,build) + +install: all + $(Q)$(call MKDIR,$(INSTALL_LIBC)) + $(Q)$(call COPY,$(call NATIVEPATH,build/allocator_simple.a),$(INSTALL_LIBC)) + $(Q)$(call COPY,$(call NATIVEPATH,build/allocator_standard.a),$(INSTALL_LIBC)) + +.PHONY: all clean install diff --git a/src/libc/allocator_simple.src b/src/libc/allocator_simple.src deleted file mode 100644 index 6eb994f59..000000000 --- a/src/libc/allocator_simple.src +++ /dev/null @@ -1,37 +0,0 @@ - assume adl = 1 - - section .text - - public __simple_malloc -__simple_malloc: - ; returns NULL when size is zero - pop bc - ex (sp),hl - push bc - ld de,(_heap_ptr) - dec hl - add hl,de - jr c,.null - ld bc,___heaptop-1 - sbc hl,bc - jr nc,.null - add hl,bc - ld (_heap_ptr),hl - ex de,hl - ret -.null: - public __simple_realloc -__simple_realloc: - or a,a - sbc hl,hl - public __simple_free -__simple_free: - ret - - section .data - private _heap_ptr -_heap_ptr: - dl ___heapbot - - extern ___heaptop - extern ___heapbot diff --git a/src/libc/asinf.c b/src/libc/asinf.c index bb2c218d2..11ceca125 100644 --- a/src/libc/asinf.c +++ b/src/libc/asinf.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _asinf\n" + "\t.type _asinf, @function\n" + "\t.equ _asinf, 0x022104\n" + "\t.global _asin\n" + "\t.type _asin, @function\n" + "\t.equ _asin, _asinf\n" +); + +#else + /* Copyright (c) 2000-2008 Zilog, Inc. */ /** @@ -13,7 +27,7 @@ * @remarks Minimum ulp: * ulp of +8 at +0x1.ffe956p-1 */ -float _asinf_c(float arg) { +float asinf(float arg) { bool arg_sign; float temp; arg_sign = signbit(arg); @@ -36,4 +50,6 @@ float _asinf_c(float arg) { return temp; } -double _asin_c(double) __attribute__((alias("_asinf_c"))); +double asin(double) __attribute__((alias("asinf"))); + +#endif diff --git a/src/libc/asinf.src b/src/libc/asinf.src deleted file mode 100644 index 725517985..000000000 --- a/src/libc/asinf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _asinf - public _asin - -if PREFER_OS_LIBC - -_asinf := 022104h -_asin := _asinf - -else - -_asinf := __asinf_c -_asin := __asin_c - - extern __asinf_c - extern __asin_c - -end if diff --git a/src/libc/asprintf.src b/src/libc/asprintf.src index 1bd8e3b54..3b03bc88b 100644 --- a/src/libc/asprintf.src +++ b/src/libc/asprintf.src @@ -1,28 +1,19 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _asprintf - public _vasprintf + .global _asprintf + .global _vasprintf -if HAS_PRINTF + .type _asprintf, @function + .type _vasprintf, @function -_asprintf := __asprintf_c -_vasprintf := __vasprintf_c +.ifdef PREFER_CE_CRT - extern __asprintf_c - extern __vasprintf_c + .set _asprintf, _boot_asprintf + .set _vasprintf, _boot_vasprintf -else + .extern _boot_asprintf + .extern _boot_vasprintf -if defined __TICE__ - -_asprintf := _boot_asprintf -_vasprintf := _boot_vasprintf - - extern _boot_asprintf - extern _boot_vasprintf - -end if - -end if +.endif diff --git a/src/libc/atan2f.c b/src/libc/atan2f.c index 3c5dd1661..e150e1b94 100644 --- a/src/libc/atan2f.c +++ b/src/libc/atan2f.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _atan2f\n" + "\t.type _atan2f, @function\n" + "\t.equ _atan2f, 0x02210C\n" + "\t.global _atan2\n" + "\t.type _atan2, @function\n" + "\t.equ _atan2, _atan2f\n" +); + +#else + /* Copyright (c) 2000-2008 Zilog, Inc. */ #include #include "__float32_constants.h" @@ -12,8 +26,10 @@ static float _positive_atan2f(float y, float x) { return _f32_satan(y / x); } -float _atan2f_c(float y, float x) { +float atan2f(float y, float x) { return copysignf(_positive_atan2f(fabsf(y), x), y); } -double _atan2_c(double, double) __attribute__((alias("_atan2f_c"))); +double atan2(double, double) __attribute__((alias("atan2f"))); + +#endif diff --git a/src/libc/atan2f.src b/src/libc/atan2f.src deleted file mode 100644 index 6f56e8915..000000000 --- a/src/libc/atan2f.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _atan2f - public _atan2 - -if PREFER_OS_LIBC - -_atan2f := 02210Ch -_atan2 := _atan2f - -else - -_atan2f := __atan2f_c -_atan2 := __atan2_c - - extern __atan2f_c - extern __atan2_c - -end if diff --git a/src/libc/atanf.c b/src/libc/atanf.c index d63c5f0df..32fc37526 100644 --- a/src/libc/atanf.c +++ b/src/libc/atanf.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _atanf\n" + "\t.type _atanf, @function\n" + "\t.equ _atanf, 0x022108\n" + "\t.global _atan\n" + "\t.type _atan, @function\n" + "\t.equ _atan, _atanf\n" +); + +#else + /* Copyright (c) 2000-2008 Zilog, Inc. */ /** @@ -37,13 +51,11 @@ * @remarks Minimum ulp: * ulp of +4 at +0x1.a85846p-2 */ -float _atanf_c(float arg) { +float atanf(float arg) { float _f32_satan(float); return copysignf(_f32_satan(fabsf(arg)), arg); } -double _atan_c(double) __attribute__((alias("_atanf_c"))); - /** * atan2 discovers what quadrant the angle * is in and calls atan. @@ -80,3 +92,7 @@ float _f32_satan(float arg) { return (F32_PI4 + _f32_xatan((arg-1.0f)/(arg+1.0f))); } } + +double atan(double) __attribute__((alias("atanf"))); + +#endif diff --git a/src/libc/atanf.src b/src/libc/atanf.src deleted file mode 100644 index aa3e91880..000000000 --- a/src/libc/atanf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _atanf - public _atan - -if PREFER_OS_LIBC - -_atanf := 022108h -_atan := _atanf - -else - -_atanf := __atanf_c -_atan := __atan_c - - extern __atanf_c - extern __atan_c - -end if diff --git a/src/libc/atexit.src b/src/libc/atexit.src new file mode 100644 index 000000000..bd4cda812 --- /dev/null +++ b/src/libc/atexit.src @@ -0,0 +1,42 @@ + + .assume adl=1 + + .section .text + .global _atexit + .type _atexit, @function + .global _on_exit + .type _on_exit, @function +_atexit: +_on_exit: + ld hl, 3*3 + push hl + call _malloc + pop bc + ex de, hl + scf + sbc hl, hl + add hl, de + ret nc + ld hl, (__atexit_functions) + ex de, hl + ld (__atexit_functions), hl + ld (hl), de + pop de +.rept 2 + inc hl + inc hl + inc hl + pop bc + ld (hl), bc +.endr + push bc + push bc + ex de, hl + jp (hl) + + .section .bss + .global __atexit_functions +__atexit_functions: + .ds 3 + + .extern _malloc diff --git a/src/libc/atof.src b/src/libc/atof.src index 823c55a8e..52a3ac597 100644 --- a/src/libc/atof.src +++ b/src/libc/atof.src @@ -1,14 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public _atof, _atoff + .section .text + .global _atof + .global _atoff + .type _atof, @function + .type _atoff, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_atoff := 022110h -_atof := _atoff + .set _atoff, 0x022110 + .set _atof, _atoff -else +.else _atof: _atoff: @@ -25,7 +28,7 @@ _atoff: pop hl ret - extern __frameset0 - extern _strtod + .extern __frameset0 + .extern _strtod -end if +.endif diff --git a/src/libc/atoi.src b/src/libc/atoi.src index 613472c04..4e43fcf14 100644 --- a/src/libc/atoi.src +++ b/src/libc/atoi.src @@ -1,40 +1,41 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _atoi + .global _atoi + .type _atoi, @function _atoi: pop de ex (sp), hl push de ; inlined isspace -.whitespace_loop: +.L.whitespace_loop: ld a, (hl) inc hl cp a, 32 - jr z, .whitespace_loop + jr z, .L.whitespace_loop sub a, 9 add a, -5 - jr nc, .whitespace_loop + jr nc, .L.whitespace_loop ; A = (HL - 1) - 9 + -5 ; A = (HL - 1) - 14 xor a, '-' - 14 push af - jr z, .minus_sign - xor a, ('+' - 14) xor ('-' - 14) - jr z, .plus_sign + jr z, .L.minus_sign + xor a, ('+' - 14) ^ ('-' - 14) + jr z, .L.plus_sign dec hl -.plus_sign: -.minus_sign: +.L.plus_sign: +.L.minus_sign: ; carry is cleared ex de, hl sbc hl, hl ; DE = start of the digits ; HL = 0 - jr .start -.loop: + jr .L.start +.L.loop: ; 21F + 4R + 3W + 1 per digit push hl pop bc @@ -46,16 +47,16 @@ _atoi: ld c, a add hl, bc inc de ; next digit -.start: +.L.start: ld a, (de) sub a, 48 cp a, 10 - jr c, .loop -.finish: + jr c, .L.loop +.L.finish: pop af ; carry is cleared ret nz ; A != '-' positive ; A == '-' negative jp __ineg - extern __ineg + .extern __ineg diff --git a/src/libc/atol.src b/src/libc/atol.src index 8986947ab..aa1859b72 100644 --- a/src/libc/atol.src +++ b/src/libc/atol.src @@ -1,33 +1,34 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _atol + .global _atol + .type _atol, @function _atol: pop de ex (sp), hl push de ; inlined isspace -.whitespace_loop: +.L.whitespace_loop: ld a, (hl) inc hl cp a, 32 - jr z, .whitespace_loop + jr z, .L.whitespace_loop sub a, 9 add a, -5 - jr nc, .whitespace_loop + jr nc, .L.whitespace_loop ; A = (HL - 1) - 9 + -5 ; A = (HL - 1) - 14 xor a, '-' - 14 push af - jr z, .minus_sign - xor a, ('+' - 14) xor ('-' - 14) - jr z, .plus_sign + jr z, .L.minus_sign + xor a, ('+' - 14) ^ ('-' - 14) + jr z, .L.plus_sign dec hl -.plus_sign: -.minus_sign: +.L.plus_sign: +.L.minus_sign: ; carry is cleared push hl pop iy @@ -35,8 +36,8 @@ _atol: ld e, l ; IY = start of the digits ; E:UHL = 0 - jr .start -.loop: + jr .L.start +.L.loop: ; 32F + 4R + 3W + 1 per digit ld d, a ld a, e @@ -62,16 +63,16 @@ _atol: ld e, a ; next digit inc iy -.start: +.L.start: ld a, (iy) sub a, 48 cp a, 10 - jr c, .loop -.finish: + jr c, .L.loop +.L.finish: pop af ; carry is cleared ret nz ; A != '-' positive ; A == '-' negative jp __lneg - extern __lneg + .extern __lneg diff --git a/src/libc/atoll.src b/src/libc/atoll.src index d9f5f4903..5fbeacaea 100644 --- a/src/libc/atoll.src +++ b/src/libc/atoll.src @@ -1,14 +1,16 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _atoll + .type _atoll, @function - section .text - public _atoll _atoll: pop bc - ex (sp),hl + ex (sp), hl push bc - ld bc,10 + ld bc, 10 push bc - ld c,b + ld c, b push bc push hl call _strtoll @@ -17,4 +19,4 @@ _atoll: pop af ret - extern _strtoll + .extern _strtoll diff --git a/src/libc/bzero.src b/src/libc/bzero.src index d34490912..59cf150b1 100644 --- a/src/libc/bzero.src +++ b/src/libc/bzero.src @@ -1,10 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _bzero + .global _bzero + .type _bzero, @function -if defined __TICE__ +.ifdef PREFER_CE_CRT ; uses the hardware specific $E40000 memory location @@ -23,7 +24,7 @@ _bzero: ldir ret -else +.else ; makes no hardware assumptions @@ -49,4 +50,4 @@ _bzero: lddr ret -end if +.endif diff --git a/src/libc/calloc.src b/src/libc/calloc.src new file mode 100644 index 000000000..739ccfcea --- /dev/null +++ b/src/libc/calloc.src @@ -0,0 +1,76 @@ + .assume adl=1 + + .section .text + .global _calloc + .type _calloc, @function + +.ifdef PREFER_CE_CRT + +; uses the hardware specific $E40000 memory location + +; void *calloc(size_t nmemb, size_t size) +_calloc: + pop de + pop bc + ex (sp), hl + push bc + push de + call __imulu + push hl + push hl + call _malloc + pop bc ; reset SP + pop bc ; BC = size + ; test for NULL + add hl, bc + ; or a, a ; .assumes that ptr + size does not overflow + sbc hl, bc + ret z ; return NULL + ; inlined bzero + push hl + ex de, hl ; DE = dest + ; test if the size is zero + scf + sbc hl, hl + add hl, bc + jr nc, .L.finish + ; large region of all zeros on the Ti84CE + ld hl, $E40000 ; HL = src + ldir +.L.finish: + pop hl ; return value + ret + +.else + +; makes no hardware assumptions + +; void *calloc(size_t nmemb, size_t size) +_calloc: + pop de + pop bc + ex (sp), hl + push bc + push de + call __imulu + push hl + push hl + call _malloc + pop de + add hl, de + xor a, a + sbc hl, de + ld e, a + push de + push hl + call nz, _memset + pop de + pop de + pop de + ret + +.endif + + .extern _malloc + .extern __imulu + .extern _memset diff --git a/src/libc/ceilf.src b/src/libc/ceilf.src index 06a2945f3..acd8840d9 100644 --- a/src/libc/ceilf.src +++ b/src/libc/ceilf.src @@ -1,23 +1,26 @@ - assume adl=1 + .assume adl=1 - section .text - public _ceil, _ceilf + .section .text + .global _ceil + .global _ceilf + .type _ceil, @function + .type _ceilf, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_ceilf := 022114h -_ceil := _ceilf + .set _ceilf, 0x022114 + .set _ceil, _ceilf -else +.else _ceil: _ceilf: call __frameset0 - ld bc,(ix+6) - ld a,(ix+9) + ld bc, (ix+6) + ld a, (ix+9) call __fneg - ld l,a - ld h,0 + ld l, a + ld h, 0 push hl push bc call _floor @@ -25,16 +28,16 @@ _ceilf: pop bc push hl pop bc - ld a,e + ld a, e call __fneg - ld e,a + ld e, a push bc pop hl pop ix ret - extern __frameset0 - extern __fneg - extern _floor + .extern __frameset0 + .extern __fneg + .extern _floor -end if +.endif diff --git a/src/libc/cimagf.src b/src/libc/cimagf.src index cf0030064..85a467fa2 100644 --- a/src/libc/cimagf.src +++ b/src/libc/cimagf.src @@ -1,8 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _cimagf, _cimag + .global _cimagf + .global _cimag + .type _cimagf, @function + .type _cimag, @function ; float cimagf(float _Complex) _cimagf: diff --git a/src/libc/cimagl.src b/src/libc/cimagl.src index 575fa97c2..5986b2016 100644 --- a/src/libc/cimagl.src +++ b/src/libc/cimagl.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _cimagl + .global _cimagl + .type _cimagl, @function ; long double cimagl(long double _Complex) _cimagl: diff --git a/src/libc/clock.src b/src/libc/clock.src index 8081525d8..a4dd3c2cd 100644 --- a/src/libc/clock.src +++ b/src/libc/clock.src @@ -1,19 +1,16 @@ -mpTmr1Counter := 0F20000h + .assume adl=1 + .section .text + .global _clock + .type _clock, @function - assume adl=1 - - section .text - public _clock _clock: -assert mpTmr1Counter shr 8 and $FF = 0 +; assert mpTmr1Counter shr 8 and $FF = 0 ; O: euhl = ticks -assert mpTmr1Counter and $A7 = 0 +; assert mpTmr1Counter and $A7 = 0 ; FO: s = 0, z = 0, h = 0, p/v = 0, n = 0, c = 0 ; CC: 79 + cc(_atomic_load_increasing_32) - require ___init_clock - - ld hl, mpTmr1Counter + ld hl, 0x0F20000 push hl call _atomic_load_increasing_32 ; ^ 48 + cc(_atomic_load_increasing_32) cc @@ -21,6 +18,5 @@ assert mpTmr1Counter and $A7 = 0 ret ; ^ 31 cc - - extern ___init_clock - extern _atomic_load_increasing_32 + .extern ___init_clock + .extern _atomic_load_increasing_32 diff --git a/src/libc/cmplxf.src b/src/libc/cmplxf.src index 3a6832baf..027c9776f 100644 --- a/src/libc/cmplxf.src +++ b/src/libc/cmplxf.src @@ -1,13 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _CMPLXF, _CMPLX + .global _CMPLXF + .type _CMPLXF, @function + .global _CMPLX + .type _CMPLX, @function ; float _Complex CMPLXF(float x, float y) /* struct ABI */ _CMPLXF: _CMPLX: - pop iy, de + pop iy + pop de or a, a sbc hl, hl add hl, sp diff --git a/src/libc/cmplxl.src b/src/libc/cmplxl.src index d2628ed64..4e79a8cef 100644 --- a/src/libc/cmplxl.src +++ b/src/libc/cmplxl.src @@ -1,12 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _CMPLXL + .global _CMPLXL + .type _CMPLXL, @function ; long double _Complex CMPLXL(long double x, long double y) /* struct ABI */ _CMPLXL: - pop iy, de + pop iy + pop de or a, a sbc hl, hl add hl, sp diff --git a/src/libc/conjf.src b/src/libc/conjf.src index 82056c53e..c44bbe5a6 100644 --- a/src/libc/conjf.src +++ b/src/libc/conjf.src @@ -1,23 +1,27 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _conjf, _conj + .global _conjf + .type _conjf, @function + .global _conj + .type _conj, @function ; enable if fpneg is required -if 1 +.if 1 ; float _Complex conjf(float _Complex) /* struct ABI */ _conjf: _conj: - pop iy, de + pop iy + pop de ld hl, 7 add hl, sp ; negate the complex part ld a, (hl) or a, a - jr nz, .do_fpneg + jr nz, .L.do_fpneg ; test if value is +0.0f push hl dec hl @@ -27,11 +31,11 @@ _conj: sbc hl, hl sbc hl, bc pop hl - jr z, .skip_fpneg -.do_fpneg: + jr z, .L.skip_fpneg +.L.do_fpneg: xor a, $80 ld (hl), a -.skip_fpneg: +.L.skip_fpneg: ld bc, 8 ; sizeof(float _Complex) sbc hl, bc @@ -42,12 +46,13 @@ _conj: ex (sp), hl ; ZDS II sret jp (iy) -else +.else ; float _Complex conjf(float _Complex) /* struct ABI */ _conjf: _conj: - pop iy, de + pop iy + pop de ld hl, 7 add hl, sp ld a, (hl) @@ -63,4 +68,4 @@ _conj: ex (sp), hl ; ZDS II sret jp (iy) -end if +.endif diff --git a/src/libc/conjl.src b/src/libc/conjl.src index 3b9db2d3a..d8c78e885 100644 --- a/src/libc/conjl.src +++ b/src/libc/conjl.src @@ -1,12 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _conjl + .global _conjl + .type _conjl, @function ; long double _Complex conjl(long double _Complex) /* struct ABI */ _conjl: - pop iy, de + pop iy + pop de ld hl, 15 add hl, sp ld a, (hl) diff --git a/src/libc/copysignf.src b/src/libc/copysignf.src index 5d1bc920f..0f5fdbb77 100644 --- a/src/libc/copysignf.src +++ b/src/libc/copysignf.src @@ -1,7 +1,10 @@ - assume adl=1 + .assume adl=1 - section .text - public _copysign, _copysignf + .section .text + .global _copysign + .type _copysign, @function + .global _copysignf + .type _copysignf, @function _copysign: _copysignf: diff --git a/src/libc/copysignl.src b/src/libc/copysignl.src index 41eb2e695..3ed168837 100644 --- a/src/libc/copysignl.src +++ b/src/libc/copysignl.src @@ -1,15 +1,22 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text + + .global _copysignl + .type _copysignl, @function - public _copysignl _copysignl: ld hl, 19 ; upper 8 bits of y add hl, sp ld a, (hl) ; extract the signbit of y rlca - pop iy, hl, de, bc - push bc, de, hl + pop iy + pop hl + pop de + pop bc + push bc + push de + push hl rl b ; clear the signbit of x, signbit of y is in the LSB rrc b ; rotate the LSB into the MSB to copy the signbit of y jp (iy) diff --git a/src/libc/cosf.src b/src/libc/cosf.src index d528fce8b..fd77b8380 100644 --- a/src/libc/cosf.src +++ b/src/libc/cosf.src @@ -1,14 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public _cos, _cosf + .section .text + .global _cos + .type _cos, @function + .global _cosf + .type _cosf, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_cosf := 02211Ch -_cos := _cosf + .set _cosf, 0x02211C + .set _cos, _cosf -else +.else ; float _f32_sinus(int quad, float arg) _cos: @@ -23,7 +26,7 @@ _cosf: push af jp _sinf.hijack - extern __frameset0 - extern _sinf.hijack + .extern __frameset0 + .extern _sinf.hijack -end if +.endif diff --git a/src/libc/coshf.c b/src/libc/coshf.c index 8f32a6a3a..3761a766d 100644 --- a/src/libc/coshf.c +++ b/src/libc/coshf.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _coshf\n" + "\t.type _coshf, @function\n" + "\t.equ _coshf, 0x022134\n" + "\t.global _cosh\n" + "\t.type _cosh, @function\n" + "\t.equ _cosh, _coshf\n" +); + +#else + #include /** @@ -5,7 +19,7 @@ * ulp of -1 at +0x1.39a3fep-12 with ideal expf (|x| < 21.0f) * ulp of -18 at +0x1.0a049cp+4 with current expf (|x| < 21.0f) */ -float _coshf_c(float x) { +float coshf(float x) { x = fabsf(x); if (x < 88.5f) { return (expf(x) + expf(-x)) / 2.0f; @@ -13,5 +27,6 @@ float _coshf_c(float x) { return expf(x - (float)M_LN2); } -double _cosh_c(double) __attribute__((alias("_coshf_c"))); +double cosh(double) __attribute__((alias("coshf"))); +#endif diff --git a/src/libc/coshf.src b/src/libc/coshf.src deleted file mode 100644 index 1ad506ef1..000000000 --- a/src/libc/coshf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _coshf - public _cosh - -if PREFER_OS_LIBC - -_coshf := 022134h -_cosh := _coshf - -else - -_coshf := __coshf_c -_cosh := __cosh_c - - extern __coshf_c - extern __cosh_c - -end if diff --git a/src/libc/crealf.src b/src/libc/crealf.src index 0db75d3cc..047a7d4cc 100644 --- a/src/libc/crealf.src +++ b/src/libc/crealf.src @@ -1,12 +1,19 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _crealf, _creal + .global _crealf + .type _crealf, @function + .global _creal + .type _creal, @function ; float crealf(float _Complex) _crealf: _creal: - pop bc, hl, de - push de, hl, bc + pop bc + pop hl + pop de + push de + push hl + push bc ret diff --git a/src/libc/creall.src b/src/libc/creall.src index 16555cc10..5fa6be62e 100644 --- a/src/libc/creall.src +++ b/src/libc/creall.src @@ -1,11 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _creall + .global _creall + .type _creall, @function ; long double creall(long double _Complex) _creall: - pop iy, hl, de, bc - push bc, de, hl + pop iy + pop hl + pop de + pop bc + push bc + push de + push hl jp (iy) diff --git a/src/libc/div.src b/src/libc/div.src index b9a9f4a48..a2b716700 100644 --- a/src/libc/div.src +++ b/src/libc/div.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _div + .type _div, @function - section .text - public _div _div: pop de pop iy @@ -18,4 +20,4 @@ _div: ret - extern __idvrms + .extern __idvrms diff --git a/src/libc/errno_str.c b/src/libc/errno_str.c index 406313603..473b03c4c 100644 --- a/src/libc/errno_str.c +++ b/src/libc/errno_str.c @@ -101,19 +101,28 @@ static_assert( #define errno_strings_count (sizeof(errno_strings) / sizeof(errno_strings[0])) -char* strerror(int errnum) { - if ((unsigned int)errnum >= errno_strings_count) { +char *strerror(int errnum) +{ + if ((unsigned int)errnum >= errno_strings_count) + { boot_sprintf(&(unknown_errno_string[unknown_errno_number_offset]), "%d", errnum); return (char*)unknown_errno_string; } + return (char*)errno_strings[errnum]; } void perror(const char *str) { + /* Normally this would print to stderr, but since they are handled the same and pulling */ + /* in fputs would create a dependency on fileioc, just use puts rather than fputs here */ + if (str != NULL && *str != '\0') { - fputs(str, stderr); - fputs(": ", stderr); + while (*str) + { + putchar(*str++); + } + putchar(':'); + putchar(' '); } - fputs(strerror(errno), stderr); - fputc('\n', stderr); + puts(strerror(errno)); } diff --git a/src/libc/expf.c b/src/libc/expf.c index 077dbe3db..4eafb6ce4 100644 --- a/src/libc/expf.c +++ b/src/libc/expf.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _expf\n" + "\t.type _expf, @function\n" + "\t.equ _expf, 0x022124\n" + "\t.global _exp\n" + "\t.type _exp, @function\n" + "\t.equ _exp, _expf\n" +); + +#else + /************************************************************************/ /* */ /* Copyright (C) 2000-2008 Zilog, Inc. */ @@ -41,7 +55,7 @@ * See the purple line for relative precision (lag warning): * https://www.desmos.com/calculator/zlrmxatxkf */ -float _expf_c(float arg) { +float expf(float arg) { float fraction; float temp1, temp2, xsq; float ent; @@ -65,4 +79,6 @@ float _expf_c(float arg) { return ldexpf( F32_SQRT2 * (temp2+temp1) / (temp2-temp1), (int)ent ); } -double _exp_c(double) __attribute__((alias("_expf_c"))); +double exp(double) __attribute__((alias("expf"))); + +#endif diff --git a/src/libc/expf.src b/src/libc/expf.src deleted file mode 100644 index 4f9734261..000000000 --- a/src/libc/expf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _expf - public _exp - -if PREFER_OS_LIBC - -_expf := 022124h -_exp := _expf - -else - -_expf := __expf_c -_exp := __exp_c - - extern __expf_c - extern __exp_c - -end if diff --git a/src/libc/ez80_builtin.src b/src/libc/ez80_builtin.src index e567b1cc3..9f3f7542d 100644 --- a/src/libc/ez80_builtin.src +++ b/src/libc/ez80_builtin.src @@ -1,10 +1,11 @@ - assume adl=1 + .assume adl=1 ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_ctzc - public ___ez80_ctzc + .global ___ez80_ctzc + .type ___ez80_ctzc, @function ___ez80_ctzc: ld hl, 3 add hl, sp @@ -13,9 +14,10 @@ ___ez80_ctzc: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_ctzi48 - public ___ez80_ctzi48 + .global ___ez80_ctzi48 + .type ___ez80_ctzi48, @function ___ez80_ctzi48: ld hl, 6 add hl, sp @@ -28,9 +30,10 @@ ___ez80_ctzi48: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_ffsc - public ___ez80_ffsc + .global ___ez80_ffsc + .type ___ez80_ffsc, @function ___ez80_ffsc: ld hl, 3 add hl, sp @@ -42,9 +45,10 @@ ___ez80_ffsc: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_ffss - public ___ez80_ffss + .global ___ez80_ffss + .type ___ez80_ffss, @function ___ez80_ffss: ld hl, 3 add hl, sp @@ -57,9 +61,10 @@ ___ez80_ffss: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_ffsi48 - public ___ez80_ffsi48 + .global ___ez80_ffsi48 + .type ___ez80_ffsi48, @function ___ez80_ffsi48: ld hl, 6 add hl, sp @@ -77,9 +82,10 @@ ___ez80_ffsi48: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_clrsbc - public ___ez80_clrsbc + .global ___ez80_clrsbc + .type ___ez80_clrsbc, @function ___ez80_clrsbc: ld hl, 3 add hl, sp @@ -93,9 +99,10 @@ ___ez80_clrsbc: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_clrsbs - public ___ez80_clrsbs + .global ___ez80_clrsbs + .type ___ez80_clrsbs, @function ___ez80_clrsbs: ; unoptimized ld hl, 3 @@ -108,9 +115,10 @@ ___ez80_clrsbs: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_clrsbi48 - public ___ez80_clrsbi48 + .global ___ez80_clrsbi48 + .type ___ez80_clrsbi48, @function ___ez80_clrsbi48: ld hl, 6 add hl, sp @@ -129,9 +137,10 @@ ___ez80_clrsbi48: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_parityc - public ___ez80_parityc + .global ___ez80_parityc + .type ___ez80_parityc, @function ___ez80_parityc: xor a, a ld hl, 3 @@ -144,9 +153,10 @@ ___ez80_parityc: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_paritys - public ___ez80_paritys + .global ___ez80_paritys + .type ___ez80_paritys, @function ___ez80_paritys: ld hl, 3 add hl, sp @@ -160,18 +170,19 @@ ___ez80_paritys: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_parityi48 - public ___ez80_parityi48 + .global ___ez80_parityi48 + .type ___ez80_parityi48, @function ___ez80_parityi48: ld hl, 3 add hl, sp ld a, (hl) ld b, 5 -.loop: +.L___ez80_parityi48.loop: inc hl xor a, (hl) - djnz .loop + djnz .L___ez80_parityi48.loop ld a, b ret pe dec a @@ -179,9 +190,10 @@ ___ez80_parityi48: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_popcountc - public ___ez80_popcountc + .global ___ez80_popcountc + .type ___ez80_popcountc, @function ___ez80_popcountc: ld hl, 3 add hl, sp @@ -190,9 +202,10 @@ ___ez80_popcountc: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_popcounts - public ___ez80_popcounts + .global ___ez80_popcounts + .type ___ez80_popcounts, @function ___ez80_popcounts: ld hl, 3 add hl, sp @@ -201,9 +214,10 @@ ___ez80_popcounts: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_popcounti48 - public ___ez80_popcounti48 + .global ___ez80_popcounti48 + .type ___ez80_popcounti48, @function ___ez80_popcounti48: ld hl, 6 add hl, sp @@ -216,9 +230,10 @@ ___ez80_popcounti48: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_bswap24 - public ___ez80_bswap24 + .global ___ez80_bswap24 + .type ___ez80_bswap24, @function ___ez80_bswap24: ld hl, 1 add hl, sp @@ -234,29 +249,40 @@ ___ez80_bswap24: ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_bswap48 - public ___ez80_bswap48 + .global ___ez80_bswap48 + .type ___ez80_bswap48, @function ___ez80_bswap48: - pop bc, hl, de - push de, hl, bc + pop bc + pop hl + pop de + push de + push hl + push bc jp __i48bswap ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_bitreverse48 - public ___ez80_bitreverse48 + .global ___ez80_bitreverse48 + .type ___ez80_bitreverse48, @function ___ez80_bitreverse48: - pop bc, hl, de - push de, hl, bc + pop bc + pop hl + pop de + push de + push hl + push bc jp __i48bitrev ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_rotateleft24 - public ___ez80_rotateleft24 + .global ___ez80_rotateleft24 + .type ___ez80_rotateleft24, @function ___ez80_rotateleft24: ; unoptimized ld iy, 0 @@ -265,23 +291,24 @@ ___ez80_rotateleft24: ld hl, (iy + 3) ld a, (iy + 6) ld c, 24 -.mod24: +.L___ez80_rotateleft24.mod24: sub a, c - jr nc, .mod24 + jr nc, .L___ez80_rotateleft24.mod24 add a, c ret z ld b, a -.loop: +.L___ez80_rotateleft24.loop: add hl, hl adc hl, de - djnz .loop + djnz .L___ez80_rotateleft24.loop ret ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_rotateleft48 - public ___ez80_rotateleft48 + .global ___ez80_rotateleft48 + .type ___ez80_rotateleft48, @function ___ez80_rotateleft48: ; unoptimized ld iy, 0 @@ -291,27 +318,28 @@ ___ez80_rotateleft48: ld de, (iy + 6) ld a, (iy + 9) ld c, 48 -.mod48: +.L___ez80_rotateleft48.mod48: sub a, c - jr nc, .mod48 + jr nc, .L___ez80_rotateleft48.mod48 add a, c ret z ld c, 0 -.loop: +.L___ez80_rotateleft48.loop: add hl, hl ex de, hl adc hl, hl ex de, hl adc hl, bc dec a - jr nz, .loop + jr nz, .L___ez80_rotateleft48.loop ret ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_rotateright24 - public ___ez80_rotateright24 + .global ___ez80_rotateright24 + .type ___ez80_rotateright24, @function ___ez80_rotateright24: ; unoptimized ld iy, 0 @@ -320,24 +348,25 @@ ___ez80_rotateright24: ld hl, (iy + 3) ld a, (iy + 6) ld c, 24 -.mod24: +.L___ez80_rotateright24.mod24: sub a, c - jr nc, .mod24 + jr nc, .L___ez80_rotateright24.mod24 neg cp a, c ret z ld b, a -.loop: +.L___ez80_rotateright24.loop: add hl, hl adc hl, de - djnz .loop + djnz .L___ez80_rotateright24.loop ret ;------------------------------------------------------------------------------- - section .text + .section .text.___ez80_rotateright48 - public ___ez80_rotateright48 + .global ___ez80_rotateright48 + .type ___ez80_rotateright48, @function ___ez80_rotateright48: ; unoptimized ld iy, 0 @@ -347,40 +376,40 @@ ___ez80_rotateright48: ld de, (iy + 6) ld a, (iy + 9) ld c, 48 -.mod48: +.L___ez80_rotateright48.mod48: sub a, c - jr nc, .mod48 + jr nc, .L___ez80_rotateright48.mod48 neg cp a, c ret z ld c, 0 -.loop: +.L___ez80_rotateright48.loop: add hl, hl ex de, hl adc hl, hl ex de, hl adc hl, bc dec a - jr nz, .loop + jr nz, .L___ez80_rotateright48.loop ret ;------------------------------------------------------------------------------- - extern __snot - extern __i48not + .extern __snot + .extern __i48not - extern __bctlz - extern __sctlz - extern __i48ctlz + .extern __bctlz + .extern __sctlz + .extern __i48ctlz - extern __bcttz - extern __scttz - extern __i48cttz + .extern __bcttz + .extern __scttz + .extern __i48cttz - extern __bpopcnt - extern __spopcnt - extern __i48popcnt + .extern __bpopcnt + .extern __spopcnt + .extern __i48popcnt - extern __i48bitrev + .extern __i48bitrev - extern __i48bswap + .extern __i48bswap diff --git a/src/libc/fabsf.src b/src/libc/fabsf.src index 57ac292b7..803713f8b 100644 --- a/src/libc/fabsf.src +++ b/src/libc/fabsf.src @@ -1,20 +1,27 @@ - assume adl=1 + .assume adl=1 - section .text - public _fabsf, _fabs + .section .text + .global _fabsf + .type _fabsf, @function + .global _fabs + .type _fabs, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_fabsf := 0220F0h -_fabs := _fabsf + .set _fabsf, 0x0220F0 + .set _fabs, _fabsf -else +.else _fabs: _fabsf: - pop bc, hl ,de - push de, hl, bc + pop bc + pop hl + pop de + push de + push hl + push bc res 7, e ret -end if +.endif diff --git a/src/libc/fabsl.src b/src/libc/fabsl.src index 11473b375..73e126538 100644 --- a/src/libc/fabsl.src +++ b/src/libc/fabsl.src @@ -1,11 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _fabsl + .global _fabsl + .type _fabsl, @function _fabsl: - pop iy, hl ,de, bc - push bc, de, hl + pop iy + pop hl + pop de + pop bc + push bc + push de + push hl res 7, b jp (iy) diff --git a/src/libc/fgetc.c b/src/libc/fgetc.c index 18a13f2af..feaa5e9ab 100644 --- a/src/libc/fgetc.c +++ b/src/libc/fgetc.c @@ -27,3 +27,5 @@ int __attribute__((weak)) fgetc(FILE *stream) return c; } + +int getc(FILE *stream) __attribute__((weak, alias("fgetc"))); diff --git a/src/libc/float32_div.src b/src/libc/float32_div.src new file mode 100644 index 000000000..34d2dd177 --- /dev/null +++ b/src/libc/float32_div.src @@ -0,0 +1,19 @@ + .assume adl=1 + + .section .text.__f32_fast_div4 + + .global __f32_fast_div4 + .type __f32_fast_div4, @function + +; float _f32_fast_div4(float x); +; only works for normalized values +; CC: 9F + 12R + 9W + 1 | 8 bytes +__f32_fast_div4: + pop bc + pop hl + pop de + dec e ; subtracts 2 from the exponent + push de + push hl + push bc + ret diff --git a/src/libc/floorf.c b/src/libc/floorf.c index 6685007bc..0e9a69588 100644 --- a/src/libc/floorf.c +++ b/src/libc/floorf.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _floorf\n" + "\t.type _floorf, @function\n" + "\t.equ _floorf, 0x0220F4\n" + "\t.global _floor\n" + "\t.type _floor, @function\n" + "\t.equ _floor, _floorf\n" +); + +#else + /************************************************************************/ /* */ /* Copyright (C) 2000-2008 Zilog, Inc. */ @@ -7,7 +21,7 @@ /************************************************************************/ #include -float _floorf_c(float d) { +float floorf(float d) { float fraction; if (d < 0.0f) { @@ -22,4 +36,6 @@ float _floorf_c(float d) { return truncf(d); } -double _floor_c(double) __attribute__((alias("_floorf_c"))); +double floor(double) __attribute__((alias("floorf"))); + +#endif diff --git a/src/libc/floorf.src b/src/libc/floorf.src deleted file mode 100644 index 475f3b676..000000000 --- a/src/libc/floorf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _floorf - public _floor - -if PREFER_OS_LIBC - -_floorf := 0220F4h -_floor := _floorf - -else - -_floorf := __floorf_c -_floor := __floor_c - - extern __floorf_c - extern __floor_c - -end if diff --git a/src/libc/fmal.src b/src/libc/fmal.src index e0772c47c..8c3557bd4 100644 --- a/src/libc/fmal.src +++ b/src/libc/fmal.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _fmal + .global _fmal + .type _fmal, @function _fmal: ; flags handled by softfloat @@ -15,6 +16,6 @@ _fmal: xor a, (iy + 19) rlca ld (iy + 20), a ; signZ - jq _softfloat_mulAddF64 + jp _softfloat_mulAddF64 - extern _softfloat_mulAddF64 + .extern _softfloat_mulAddF64 diff --git a/src/libc/fminmaxf.src b/src/libc/fminmaxf.src index fca666bde..9ec6f7d79 100644 --- a/src/libc/fminmaxf.src +++ b/src/libc/fminmaxf.src @@ -1,4 +1,4 @@ - assume adl=1 + .assume adl=1 ; fminf and fmaxf treat signed zeros as -0.0f < +0.0f. ; @@ -10,13 +10,19 @@ ;------------------------------------------------------------------------------- - section .text + .section .text - public _fminf - public _fmin + .global _fminf + .type _fminf, @function + .global _fmin + .type _fmin, @function + .global _fmaxf + .type _fmaxf, @function + .global _fmax + .type _fmax, @function -_fmin: _fminf: +_fmin: ld iy, 0 add iy, sp ld bc, $010000 @@ -32,68 +38,68 @@ _fminf: ; (X-, Y-): A = 0 NC Z ; invert compare ; (X-, Y+): A = -1 C NZ ; X < Y ; (X+, Y-): A = +1 NC NZ ; X > Y - jr nz, .different_sign -; .same_sign: + jr nz, .L_fmin.different_sign +; .L_fmin.same_sign: sbc hl, de ; X - Y add hl, de - jr nz, .x_and_y_diff + jr nz, .L_fmin.x_and_y_diff ld a, (iy + 3) cp a, (iy + 9) -.x_and_y_diff: +.L_fmin.x_and_y_diff: sbc a, a xor a, (iy + 6) ; invert the comparison add a, a -.different_sign: +.L_fmin.different_sign: jr c, _fminmaxf_common.no_swap -; .swap: +; .L_fmin.swap: ex de, hl add hl, bc ; overflows for NaN and Inf jr c, _fminmaxf_common.y_maybe_NaN ;------------------------------------------------------------------------------- - section .text + .section .text - private _fminmaxf_common.no_swap - private _fminmaxf_common.y_maybe_NaN + .local _fminmaxf_common.no_swap + .local _fminmaxf_common.y_maybe_NaN _fminmaxf_common: -.return_y: +_fminmaxf_common.return_y: ld hl, (iy + 9) ld e, (iy + 12) ret -.y_maybe_NaN: +_fminmaxf_common.y_maybe_NaN: ld a, l or a, h or a, (iy + 9) - jr z, .return_y ; infinity + jr z, _fminmaxf_common.return_y ; infinity ; jr .return_x -.no_swap: +_fminmaxf_common.no_swap: add hl, bc ; overflows for NaN and Inf - jr c, .x_maybe_NaN -.return_x: + jr c, _fminmaxf_common.x_maybe_NaN +_fminmaxf_common.return_x: ld hl, (iy + 3) ld e, (iy + 6) ret -.x_maybe_NaN: +_fminmaxf_common.x_maybe_NaN: ld a, l or a, h or a, (iy + 3) - jr z, .return_x ; infinity - jr .return_y + jr z, _fminmaxf_common.return_x ; infinity + jr _fminmaxf_common.return_y ;------------------------------------------------------------------------------- - section .text + .section .text - public _fmaxf - public _fmax + .global _fmaxf + .global _fmax -_fmax: _fmaxf: +_fmax: ld iy, 0 add iy, sp ld bc, $010000 @@ -109,24 +115,24 @@ _fmaxf: ; (X-, Y-): A = 0 NC Z ; invert compare ; (X-, Y+): A = -1 C NZ ; X < Y ; (X+, Y-): A = +1 NC NZ ; X > Y - jr nz, .different_sign -; .same_sign: + jr nz, .L_fmax.different_sign +; .L_fmax.same_sign: sbc hl, de ; X - Y add hl, de - jr nz, .x_and_y_diff + jr nz, .L_fmax.x_and_y_diff ld a, (iy + 3) cp a, (iy + 9) -.x_and_y_diff: +.L_fmax.x_and_y_diff: sbc a, a xor a, (iy + 6) ; invert the comparison add a, a -.different_sign: +.L_fmax.different_sign: jr nc, _fminmaxf_common.no_swap -; .swap: +; .L_fmax.swap: ex de, hl add hl, bc ; overflows for NaN and Inf jr c, _fminmaxf_common.y_maybe_NaN -.return_y: +.L_fmax.return_y: ld hl, (iy + 9) ld e, (iy + 12) ret diff --git a/src/libc/fmodf.c b/src/libc/fmodf.c index 264b39602..4e7eadc3a 100644 --- a/src/libc/fmodf.c +++ b/src/libc/fmodf.c @@ -1,8 +1,24 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _fmodf\n" + "\t.type _fmodf, @function\n" + "\t.equ _fmodf, 0x0220FC\n" + "\t.global _fmod\n" + "\t.type _fmod, @function\n" + "\t.equ _fmod, _fmodf\n" +); + +#else + #include -float _fmodf_c(float x, float y) +float fmodf(float x, float y) { return x - truncf(x / y) * y; } -double _fmod_c(double, double) __attribute__((alias("_fmodf_c"))); +double fmod(double, double) __attribute__((alias("fmodf"))); + +#endif diff --git a/src/libc/fmodf.src b/src/libc/fmodf.src deleted file mode 100644 index 0378b12aa..000000000 --- a/src/libc/fmodf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _fmodf - public _fmod - -if PREFER_OS_LIBC - -_fmodf := 0220FCh -_fmod := _fmodf - -else - -_fmodf := __fmodf_c -_fmod := __fmod_c - - extern __fmodf_c - extern __fmod_c - -end if diff --git a/src/libc/fmodl.src b/src/libc/fmodl.src index d2f4efb29..7635da67e 100644 --- a/src/libc/fmodl.src +++ b/src/libc/fmodl.src @@ -1,8 +1,9 @@ - assume adl = 1 + .assume adl = 1 - section .text + .section .text - public _fmodl + .global _fmodl + .type _fmodl, @function _fmodl: call __frameset0 @@ -27,5 +28,5 @@ _fmodl: pop ix ret - extern ___f64_rem - extern __frameset0 + .extern ___f64_rem + .extern __frameset0 diff --git a/src/libc/fpclassifyf.src b/src/libc/fpclassifyf.src index a24343745..67011310a 100644 --- a/src/libc/fpclassifyf.src +++ b/src/libc/fpclassifyf.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __fpclassifyf + .global __fpclassifyf + .type __fpclassifyf, @function ; FP_ZERO := 0 ; FP_INFINITE := 1 @@ -12,14 +13,18 @@ ; int _fpclassifyf(float) __fpclassifyf: - pop bc, hl, de - push de, hl, bc + pop bc + pop hl + pop de + push de + push hl + push bc or a, a adc hl, hl - jr z, .mant_zero ; normal, zero, or inf + jr z, .L.mant_zero ; normal, zero, or inf ld hl, 2 ; normal, subnormal, or NaN -.mant_zero: +.L.mant_zero: rl e ret z ; subnormal or zero inc hl diff --git a/src/libc/fpclassifyl.src b/src/libc/fpclassifyl.src index 35724d23b..1dac65775 100644 --- a/src/libc/fpclassifyl.src +++ b/src/libc/fpclassifyl.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __fpclassifyl + .global __fpclassifyl + .type __fpclassifyl, @function ; FP_ZERO := 0 ; FP_INFINITE := 1 @@ -12,20 +13,25 @@ ; int _fpclassifyl(long double) __fpclassifyl: - pop bc, hl, de + pop bc + pop hl + pop de or a, a adc hl, de pop de - push bc, bc, bc, bc + push bc + push bc + push bc + push bc ld a, e - jr nz, .mant_nonzero ; normal, subnormal, or NaN - jr c, .mant_nonzero ; normal, subnormal, or NaN + jr nz, .L.mant_nonzero ; normal, subnormal, or NaN + jr c, .L.mant_nonzero ; normal, subnormal, or NaN tst a, $0F - jr z, .mant_zero ; normal, zero, or inf -.mant_nonzero: + jr z, .L.mant_zero ; normal, zero, or inf +.L.mant_nonzero: ; normal, subnormal, or NaN ld hl, 2 -.mant_zero: +.L.mant_zero: rra and a, $78 res 7, d diff --git a/src/libc/fprintf.src b/src/libc/fprintf.src deleted file mode 100644 index f98f4ae7c..000000000 --- a/src/libc/fprintf.src +++ /dev/null @@ -1,16 +0,0 @@ - assume adl=1 - - section .text - -if HAS_PRINTF - - public _fprintf - public _vfprintf - -_fprintf := __fprintf_c -_vfprintf := __vfprintf_c - - extern __fprintf_c - extern __vfprintf_c - -end if diff --git a/src/libc/fputc.c b/src/libc/fputc.c index 9996c9e54..c2b575bcf 100644 --- a/src/libc/fputc.c +++ b/src/libc/fputc.c @@ -30,3 +30,5 @@ int __attribute__((weak)) fputc(int c, FILE *stream) return ret; } + +int putc(int c, FILE *stream) __attribute__((weak, alias("fputc"))); diff --git a/src/libc/frexpf.src b/src/libc/frexpf.src index d7d723893..d2221eb8b 100644 --- a/src/libc/frexpf.src +++ b/src/libc/frexpf.src @@ -1,19 +1,21 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _frexpf - public _frexp + .global _frexpf + .type _frexpf, @function + .global _frexp + .type _frexp, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_frexpf := 0220D8h -_frexp := _frexpf + .set _frexpf, 0x0220D8 + .set _frexp, _frexpf -else +.else -_frexp: _frexpf: +_frexp: ld iy, 0 lea de, iy - 127 ; bias ; $FFFF81 add iy, sp @@ -22,9 +24,9 @@ _frexpf: ld b, (iy + 6) ld a, b adc a, a - jr z, .maybe_subnormal + jr z, .L.maybe_subnormal inc a - jr z, .inf_nan + jr z, .L.inf_nan ; normal ld b, $7E ; $3F << 1 rr b @@ -32,26 +34,26 @@ _frexpf: ld l, a ; ld de, -127 ; bias add hl, de -.ret_zero: +.L.ret_zero: ex de, hl -.ret_subnormal: +.L.ret_subnormal: res 7, (iy + 5) -.ret_self: +.L.ret_self: ld hl, (iy + 9) ; int *expon ld (hl), de ld hl, (iy + 3) ; mantissa ld e, b ; exponent ret -.inf_nan: +.L.inf_nan: ld de, $7FFFFF ; INT_MAX - jr .ret_self + jr .L.ret_self -.maybe_subnormal: +.L.maybe_subnormal: ld e, d ; ld de, -1 add hl, de inc hl ; restore HL - jr nc, .ret_zero + jr nc, .L.ret_zero ; input: HL output: A call __ictlz ld c, a @@ -64,9 +66,9 @@ _frexpf: ld a, b xor a, $3F ld b, a - jr .ret_subnormal + jr .L.ret_subnormal - extern __ictlz - extern __ishl + .extern __ictlz + .extern __ishl -end if +.endif diff --git a/src/libc/getc.src b/src/libc/getc.src deleted file mode 100644 index a0ff98322..000000000 --- a/src/libc/getc.src +++ /dev/null @@ -1,9 +0,0 @@ - assume adl=1 - - section .text - - public _getc - -_getc := _fgetc - - extern _fgetc diff --git a/src/libc/getchar.src b/src/libc/getchar.src deleted file mode 100644 index 94e073220..000000000 --- a/src/libc/getchar.src +++ /dev/null @@ -1,6 +0,0 @@ - assume adl=1 - - section .text - public _getchar -_getchar := _inchar - extern _inchar diff --git a/src/libc/i48abs.src b/src/libc/i48abs.src index fd37abbfc..2c4ff7d45 100644 --- a/src/libc/i48abs.src +++ b/src/libc/i48abs.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _i48abs + .global _i48abs + .type _i48abs, @function ; int48_t i48abs(int48_t) _i48abs: @@ -21,4 +22,4 @@ _i48abs: ; positive ret - extern __i48neg + .extern __i48neg diff --git a/src/libc/i48div.src b/src/libc/i48div.src index b17d327f9..7791e134b 100644 --- a/src/libc/i48div.src +++ b/src/libc/i48div.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _i48div + .global _i48div + .type _i48div, @function ; i48div_t i48div(int48_t numer, int48_t denom); _i48div: @@ -37,6 +38,6 @@ _i48div: pop ix ret - extern __i48dvrmu - extern __i48neg - extern __uiyubcNeg + .extern __i48dvrmu + .extern __i48neg + .extern __uiyubcNeg diff --git a/src/libc/ilogbf.src b/src/libc/ilogbf.src index 505591976..23620188b 100644 --- a/src/libc/ilogbf.src +++ b/src/libc/ilogbf.src @@ -1,12 +1,15 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _ilogbf, _ilogb + .global _ilogbf + .type _ilogbf, @function + .global _ilogb + .type _ilogb, @function ; int ilogbf(float) -_ilogb: _ilogbf: +_ilogb: ld hl, 6 add hl, sp ld a, (hl) @@ -16,19 +19,19 @@ _ilogbf: ld hl, (hl) add hl, hl adc a, a - jr z, .maybe_subnormal + jr z, .L.maybe_subnormal inc a - jr z, .inf_nan + jr z, .L.inf_nan sub a, 128 ; float32_bias + 1 sbc hl, hl ld l, a ret -.maybe_subnormal: +.L.maybe_subnormal: add hl, de or a, a sbc hl, de - jr z, .ret_zero + jr z, .L.ret_zero call __ictlz cpl add a, 130 @@ -36,9 +39,9 @@ _ilogbf: ld l, a ret -.inf_nan: +.L.inf_nan: scf -.ret_zero: +.L.ret_zero: ld hl, 4 ; EDOM ld (_errno), hl ld hl, ___fe_cur_env @@ -49,6 +52,6 @@ _ilogbf: dec hl ret - extern _errno - extern ___fe_cur_env - extern __ictlz + .extern _errno + .extern ___fe_cur_env + .extern __ictlz diff --git a/src/libc/ilogbl.src b/src/libc/ilogbl.src index 9e824d67a..38b976f02 100644 --- a/src/libc/ilogbl.src +++ b/src/libc/ilogbl.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _ilogbl + .global _ilogbl + .type _ilogbl, @function ; int ilogbl(long double) _ilogbl: @@ -23,16 +24,16 @@ _ilogbl: ld h, a ; HL = exponent adc hl, de - jr z, .maybe_subnormal + jr z, .L.maybe_subnormal inc hl bit 3, h - jr nz, .inf_nan + jr nz, .L.inf_nan ; Float64_exp_bias + 1 ld de, -1024 add hl, de ret -.maybe_subnormal: +.L.maybe_subnormal: ld c, (iy + 9) ld b, e ; DE is zero ld de, (iy + 6) @@ -40,7 +41,7 @@ _ilogbl: call __llctlz cp a, 64 sbc hl, hl - jr z, .ret_zero ; A was 64 + jr z, .L.ret_zero ; A was 64 cpl ld l, a ; -1023 + 11 + 1 + 1 @@ -49,10 +50,10 @@ _ilogbl: add hl, de ret -.ret_zero: +.L.ret_zero: ex de, hl inc de -.inf_nan: +.L.inf_nan: ld hl, $7FFFFF ; FP_ILOGBNAN or INT_MAX add hl, de ; FP_ILOGB0 when DE is one ex de, hl @@ -64,7 +65,7 @@ _ilogbl: ex de, hl ret - extern __fpclassifyl - extern _errno - extern ___fe_cur_env - extern __llctlz + .extern __fpclassifyl + .extern _errno + .extern ___fe_cur_env + .extern __llctlz diff --git a/src/libc/inchar.src b/src/libc/inchar.src index 40df32cf8..e19c2f27a 100644 --- a/src/libc/inchar.src +++ b/src/libc/inchar.src @@ -1,22 +1,24 @@ - assume adl=1 + .assume adl=1 + + .section .text + .weak _inchar + .type _inchar, @function - section .text - weak _inchar _inchar: - ld iy,$d00080 ; ti.flags -.l: + ld iy,$d00080 ; ti.flags +.L.loop: call $2014C ; ti.GetCSC - or a,a - jr z,.l - sbc hl,hl - ld l,a - ld de,.lut - add hl,de - ld a,(hl) - or a,a - jr z,.l - sbc hl,hl - ld l,a + or a, a + jr z, .L.loop + sbc hl, hl + ld l, a + ld de, .L.lut + add hl, de + ld a, (hl) + or a, a + jr z, .L.loop + sbc hl, hl + ld l, a push hl push hl call _outchar @@ -24,7 +26,7 @@ _inchar: pop hl ret -.lut: +.L.lut: db 0,0,0,0,0,0,0,0,0,10 ; db 0,'WRMH',0,0 ; + - × ÷ ^ undef db 0,'Z'+ 1,'VQLG',0,0 ; (-) 3 6 9 ) TAN VARS undef @@ -33,4 +35,8 @@ _inchar: db 'XSNIDA' ; STO LN LOG x2 x-1 MATH db 0,0,0,0,0,0,0,0,0,0 ; - extern _outchar + .global _getchar + .type _getchar, @function + .equ _getchar, _inchar + + .extern _outchar diff --git a/src/libc/isalnum.src b/src/libc/isalnum.src index bb20ba201..e8554a7ba 100644 --- a/src/libc/isalnum.src +++ b/src/libc/isalnum.src @@ -1,19 +1,21 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isalnum + .type _isalnum, @function - section .text - public _isalnum _isalnum: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,48 - add a,-10 - sbc hl,hl + ld a, l + sub a, 48 + add a, -10 + sbc hl, hl inc hl ret z - sub a,65-(48+10) - res 5,a - cp a,26 - adc hl,hl + sub a, 65 - (48 + 10) + res 5, a + cp a, 26 + adc hl, hl ret diff --git a/src/libc/isalpha.src b/src/libc/isalpha.src index d5e6db323..41878b03e 100644 --- a/src/libc/isalpha.src +++ b/src/libc/isalpha.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isalpha + .type _isalpha, @function - section .text - public _isalpha _isalpha: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,65 - res 5,a - add a,-26 - sbc hl,hl + ld a, l + sub a, 65 + res 5, a + add a, -26 + sbc hl, hl inc hl ret diff --git a/src/libc/isascii.src b/src/libc/isascii.src index a8a8d2950..fb88e1f54 100644 --- a/src/libc/isascii.src +++ b/src/libc/isascii.src @@ -1,12 +1,14 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isascii + .type _isascii, @function - section .text - public _isascii _isascii: pop de - ex (sp),hl + ex (sp), hl push de sla l - sbc hl,hl + sbc hl, hl inc hl ret diff --git a/src/libc/isblank.src b/src/libc/isblank.src index 6412b358c..dbf893ccf 100644 --- a/src/libc/isblank.src +++ b/src/libc/isblank.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isblank + .type _isblank, @function - section .text - public _isblank _isblank: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - cp a,32 + ld a, l + cp a, 32 ret z - xor a,9 + xor a, 9 ret z - sbc hl,hl + sbc hl, hl ret diff --git a/src/libc/iscntrl.src b/src/libc/iscntrl.src index 55bf20a0c..df14e35ab 100644 --- a/src/libc/iscntrl.src +++ b/src/libc/iscntrl.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _iscntrl + .type _iscntrl, @function - section .text - public _iscntrl _iscntrl: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - cp a,127 + ld a, l + cp a, 127 ret z - add a,-32 - sbc hl,hl + add a, -32 + sbc hl, hl inc hl ret diff --git a/src/libc/isdigit.src b/src/libc/isdigit.src index d787e56af..ceadf386b 100644 --- a/src/libc/isdigit.src +++ b/src/libc/isdigit.src @@ -1,13 +1,15 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isdigit + .type _isdigit, @function - section .text - public _isdigit _isdigit: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,48 - sub a,10 - sbc hl,hl + ld a, l + sub a, 48 + sub a, 10 + sbc hl, hl ret diff --git a/src/libc/isfinitef.src b/src/libc/isfinitef.src index c104ee720..d7736824a 100644 --- a/src/libc/isfinitef.src +++ b/src/libc/isfinitef.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __isfinitef + .global __isfinitef + .type __isfinitef, @function ; bool _isfinitef(float) __isfinitef: @@ -14,4 +15,3 @@ __isfinitef: sub a, $FF ; NaN/inf exponent won't underflow sbc a, a ret - diff --git a/src/libc/isfinitel.src b/src/libc/isfinitel.src index c756faa0d..043c3429f 100644 --- a/src/libc/isfinitel.src +++ b/src/libc/isfinitel.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __isfinitel + .global __isfinitel + .type __isfinitel, @function ; bool _isfinitel(long double) __isfinitel: diff --git a/src/libc/isgraph.src b/src/libc/isgraph.src index f805788b2..cd240d565 100644 --- a/src/libc/isgraph.src +++ b/src/libc/isgraph.src @@ -1,13 +1,15 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isgraph + .type _isgraph, @function - section .text - public _isgraph _isgraph: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,33 - sub a,94 - sbc hl,hl + ld a, l + sub a, 33 + sub a, 94 + sbc hl, hl ret diff --git a/src/libc/isinff.src b/src/libc/isinff.src index a52edc382..30914d83a 100644 --- a/src/libc/isinff.src +++ b/src/libc/isinff.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __isinff + .global __isinff + .type __isinff, @function ; bool _isinff(float) __isinff: diff --git a/src/libc/isinfl.src b/src/libc/isinfl.src index 1044ae657..30ceef903 100644 --- a/src/libc/isinfl.src +++ b/src/libc/isinfl.src @@ -1,16 +1,22 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __isinfl + .global __isinfl + .type __isinfl, @function ; bool _isinfl(long double) __isinfl: - pop bc, hl, de + pop bc + pop hl + pop de xor a, a adc hl, de pop de - push bc, bc, bc, bc + push bc + push bc + push bc + push bc ret nz ; mant_nonzero ret c ; mant_carry ld a, e diff --git a/src/libc/islower.src b/src/libc/islower.src index f0f84aa9c..5a4079d4e 100644 --- a/src/libc/islower.src +++ b/src/libc/islower.src @@ -1,13 +1,15 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _islower + .type _islower, @function - section .text - public _islower _islower: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,97 - sub a,26 - sbc hl,hl + ld a, l + sub a, 97 + sub a, 26 + sbc hl, hl ret diff --git a/src/libc/isnanf.src b/src/libc/isnanf.src index 2135a5ee0..33ff2386c 100644 --- a/src/libc/isnanf.src +++ b/src/libc/isnanf.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __isnanf + .global __isnanf + .type __isnanf, @function ; bool _isnanf(float) __isnanf: diff --git a/src/libc/isnanl.src b/src/libc/isnanl.src index 3765b0c08..a0d4efd97 100644 --- a/src/libc/isnanl.src +++ b/src/libc/isnanl.src @@ -1,24 +1,30 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __isnanl + .global __isnanl + .type __isnanl, @function ; bool _isnanl(long double) __isnanl: - pop bc, hl, de + pop bc + pop hl + pop de or a, a adc hl, de pop de - push bc, bc, bc, bc + push bc + push bc + push bc + push bc ld a, e - jr nz, .mant_nonzero ; normal, subnormal, or NaN - jr c, .mant_nonzero ; normal, subnormal, or NaN + jr nz, .L.mant_nonzero ; normal, subnormal, or NaN + jr c, .L.mant_nonzero ; normal, subnormal, or NaN ; common NaN, inf, normal, or subnormal or a, a ret z dec a -.mant_nonzero: +.L.mant_nonzero: add a, 16 ; overflows 0xF0 sbc a, a ret z diff --git a/src/libc/isnormalf.src b/src/libc/isnormalf.src index a7384f7d5..0f086e82e 100644 --- a/src/libc/isnormalf.src +++ b/src/libc/isnormalf.src @@ -1,9 +1,10 @@ - assume adl=1 + .assume adl=1 - section .text - - public __isnormalf + .section .text + .global __isnormalf + .type __isnormalf, @function + ; bool _isnormalf(float) __isnormalf: ld hl, 5 diff --git a/src/libc/isnormall.src b/src/libc/isnormall.src index 3b311214e..bb1aa4e38 100644 --- a/src/libc/isnormall.src +++ b/src/libc/isnormall.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __isnormall + .global __isnormall + .type __isnormall, @function ; bool _isnormall(long double) __isnormall: @@ -15,15 +16,15 @@ __isnormall: ; test for inf/NaN ld de, $2000 add hl, de - jr c, .exp_all_ones + jr c, .L.exp_all_ones ; double de ld d, $40 ; test for zero/subnormal sbc hl, de -; jr c, .exp_all_zero +; jr c, .L.exp_all_zero -.exp_all_ones: -.exp_all_zero: +.L.exp_all_ones: +.L.exp_all_zero: sbc a, a inc a ret diff --git a/src/libc/isprint.src b/src/libc/isprint.src index 9c231a725..f10752236 100644 --- a/src/libc/isprint.src +++ b/src/libc/isprint.src @@ -1,14 +1,16 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isprint + .type _isprint, @function - section .text - public _isprint _isprint: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,32 - add a,-95 - sbc hl,hl + ld a, l + sub a, 32 + add a, -95 + sbc hl, hl inc hl ret diff --git a/src/libc/ispunct.src b/src/libc/ispunct.src index 0a994a295..832ab61f2 100644 --- a/src/libc/ispunct.src +++ b/src/libc/ispunct.src @@ -1,23 +1,25 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _ispunct + .type _ispunct, @function - section .text - public _ispunct _ispunct: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,33 - cp a,48-33 + ld a, l + sub a, 33 + cp a, 48 - 33 ret c - sub a,58-33 - cp a,65-58 + sub a, 58 - 33 + cp a, 65 - 58 ret c - sub a,91-58 - cp a,97-91 + sub a, 91 - 58 + cp a, 97 - 91 ret c - sub a,123-91 - cp a,127-123 + sub a, 123 - 91 + cp a, 127 - 123 ret c - sbc hl,hl - ret \ No newline at end of file + sbc hl, hl + ret diff --git a/src/libc/issignalingf.src b/src/libc/issignalingf.src index 7b0419914..25a472128 100644 --- a/src/libc/issignalingf.src +++ b/src/libc/issignalingf.src @@ -1,10 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __issignalingf + .global __issignalingf + .type __issignalingf, @function -; assumes quiet NaN is NaN with bit 22 set +; .assumes quiet NaN is NaN with bit 22 set ; bool _issignalingf(float) __issignalingf: ; based off __isnanf, unoptimized diff --git a/src/libc/issignalingl.src b/src/libc/issignalingl.src index ae75d0972..c19554770 100644 --- a/src/libc/issignalingl.src +++ b/src/libc/issignalingl.src @@ -1,10 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __issignalingl + .global __issignalingl + .type __issignalingl, @function -; assumes quiet NaN is NaN with bit 51 set +; .assumes quiet NaN is NaN with bit 51 set ; bool _issignalingl(long double) __issignalingl: ld hl, 9 @@ -14,4 +15,4 @@ __issignalingl: xor a, a ; quiet bit set, return false ret - extern __isnanl + .extern __isnanl diff --git a/src/libc/isspace.src b/src/libc/isspace.src index a1a69b546..ef9511209 100644 --- a/src/libc/isspace.src +++ b/src/libc/isspace.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isspace + .type _isspace, @function - section .text - public _isspace _isspace: pop de ex (sp),hl diff --git a/src/libc/issubnormalf.src b/src/libc/issubnormalf.src index 9aa3e0515..d7def9ad9 100644 --- a/src/libc/issubnormalf.src +++ b/src/libc/issubnormalf.src @@ -1,16 +1,19 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __issubnormalf + .global __issubnormalf + .type __issubnormalf, @function ; bool _issubnormalf(float) __issubnormalf: xor a, a - pop bc, hl + pop bc + pop hl adc hl, hl ex (sp), hl - push hl, bc + push hl + push bc ret z ; zero mantissa is not subnormal adc hl, hl sub a, l diff --git a/src/libc/issubnormall.src b/src/libc/issubnormall.src index fb6908522..4d4d3f3d0 100644 --- a/src/libc/issubnormall.src +++ b/src/libc/issubnormall.src @@ -1,24 +1,30 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __issubnormall + .global __issubnormall + .type __issubnormall, @function ; bool _issubnormall(long double) __issubnormall: - pop bc, hl, de + pop bc + pop hl + pop de or a, a adc hl, de pop de - push bc, bc, bc, bc + push bc + push bc + push bc + push bc ; zero is not subnormal - jr nz, .mant_nonzero - jr c, .mant_carry + jr nz, .L.mant_nonzero + jr c, .L.mant_carry ld a, e and a, $0F ret z ; mantissa is zero -.mant_nonzero: -.mant_carry: +.L.mant_nonzero: +.L.mant_carry: ld a, e and a, $F0 res 7, d diff --git a/src/libc/isupper.src b/src/libc/isupper.src index 36a68c81d..f1028612d 100644 --- a/src/libc/isupper.src +++ b/src/libc/isupper.src @@ -1,13 +1,15 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isupper + .type _isupper, @function - section .text - public _isupper _isupper: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,65 - sub a,26 - sbc hl,hl + ld a, l + sub a, 65 + sub a, 26 + sbc hl, hl ret diff --git a/src/libc/isxdigit.src b/src/libc/isxdigit.src index d15ff0b12..0ffbbdc04 100644 --- a/src/libc/isxdigit.src +++ b/src/libc/isxdigit.src @@ -1,19 +1,21 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _isxdigit + .type _isxdigit, @function - section .text - public _isxdigit _isxdigit: pop de - ex (sp),hl + ex (sp), hl push de - ld a,l - sub a,48 - add a,-10 - sbc hl,hl + ld a, l + sub a, 48 + add a, -10 + sbc hl, hl inc hl ret z - sub a,65-(48+10) - res 5,a - cp a,6 - adc hl,hl + sub a, 65 - (48 + 10) + res 5, a + cp a, 6 + adc hl, hl ret diff --git a/src/libc/iszerof.src b/src/libc/iszerof.src index 1f1bbc7ce..0d8228ca1 100644 --- a/src/libc/iszerof.src +++ b/src/libc/iszerof.src @@ -1,16 +1,19 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __iszerof + .global __iszerof + .type __iszerof, @function ; bool _iszerof(float) __iszerof: xor a, a - pop bc, hl + pop bc + pop hl adc hl, hl ex (sp), hl - push hl, bc + push hl + push bc ret nz ; non-zero mantissa ld a, l adc a, a diff --git a/src/libc/iszerol.src b/src/libc/iszerol.src index 2150eef03..2de1a6cd8 100644 --- a/src/libc/iszerol.src +++ b/src/libc/iszerol.src @@ -1,16 +1,22 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __iszerol + .global __iszerol + .type __iszerol, @function ; bool iszerol(long double) __iszerol: - pop bc, hl, de + pop bc + pop hl + pop de xor a, a adc hl, de pop de - push bc, bc, bc, bc + push bc + push bc + push bc + push bc ; return if mantissa is non-zero ret nz ; mant_nonzero ret c ; mant_carry diff --git a/src/libc/labs.src b/src/libc/labs.src index c12cd8ebd..73e933acd 100644 --- a/src/libc/labs.src +++ b/src/libc/labs.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _labs + .type _labs, @function - section .text - public _labs _labs: pop bc pop hl @@ -13,4 +15,4 @@ _labs: ret z jp __lneg - extern __lneg + .extern __lneg diff --git a/src/libc/ldexpf.src b/src/libc/ldexpf.src index 70f892696..404b85d7f 100644 --- a/src/libc/ldexpf.src +++ b/src/libc/ldexpf.src @@ -1,23 +1,27 @@ - assume adl=1 + .assume adl=1 - section .text - public _ldexpf - public _ldexp + .section .text + .global _ldexpf + .type _ldexpf, @function + .global _ldexp + .type _ldexp, @function ; when FLT_RADIX == 2, scalbn is equivilent to ldexp - public _scalbnf - public _scalbn + .global _scalbnf + .type _scalbnf, @function + .global _scalbn + .type _scalbn, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_ldexpf := 0220DCh -_ldexp := _ldexpf -_scalbnf := _ldexpf -_scalbn := _ldexpf + .set _ldexpf, 0x0220DC + .set _ldexp, _ldexpf + .set _scalbnf, _ldexpf + .set _scalbn, _ldexpf -else +.else ; (set to 0 or 1) avoid returning negative zero on underflow with Ti's floats -__ldexpf_avoid_negative_zero := 1 + .equ __ldexpf_avoid_negative_zero, 1 ; ldexpf behaviour: ; - signed zero, infinity, and NaN inputs are returned unmodified @@ -25,41 +29,39 @@ __ldexpf_avoid_negative_zero := 1 ; - FE_INEXACT is set if rounding occured ;------------------------------------------------------------------------------- - private __ldexpf_helper -__ldexpf_helper: -.maybe_subnormal: +.L.maybe_subnormal: ; A = zero, carry = signbit rra ; restore signbit and clear carry adc hl, bc ; BC is zero -.ret_self: +.L.ret_self: ld hl, (iy + 3) ; mant ret z ; return zero/inf/NaN dec bc ; BC is now -1 -; .subnormal_input: +; .L.subnormal_input: ; BC is -1 here bit 7, (iy + 11) ; scale sign ld de, (iy + 9) ; scale - jr nz, _ldexpf.move_subnormal_down -; .move_subnormal_up: -.norm_loop: + jr nz, .L.move_subnormal_down +; .L.move_subnormal_up: +.L.norm_loop: add hl, hl - jr c, .normalized + jr c, .L.normalized ex de, hl add hl, bc ; --scale ex de, hl - jr c, .norm_loop -; .still_subnormal: + jr c, .L.norm_loop +; .L.still_subnormal: ; DE is -1 here ; saves 8F for this path at a cost of 3 bytes: -if 0 +.if 0 inc de ; ld e, 0 jr _ldexpf.finish_subnormal -end if -.normalized: +.endif +.L.normalized: inc de ; don't touch the Z flag ex de, hl ; Z is set here - jr _ldexpf.scale_up_subnormal + jr .L.scale_up_subnormal ;------------------------------------------------------------------------------- ; When the input and output are normal: @@ -77,32 +79,32 @@ _ldexpf: ld a, (iy + 6) ; expon ld e, a ; signbit adc a, a - jr z, __ldexpf_helper.maybe_subnormal + jr z, .L.maybe_subnormal ld c, a inc a - jr z, __ldexpf_helper.ret_self ; inf NaN + jr z, .L.ret_self ; inf NaN ld a, e ; signbit ld de, (iy + 9) ; scale ex de, hl add hl, bc ; add expon bit 7, (iy + 11) ; scale sign - jr nz, .scale_down -.scale_up: + jr nz, .L.scale_down +.L.scale_up: ; HL is [1, $8000FD] ld c, b ; ld bc, 0 dec bc ; ld bc, -1 -.scale_up_subnormal: ; <-- HL is [0, $7FFFFE] +.L.scale_up_subnormal: ; <-- HL is [0, $7FFFFE] inc c ; ld bc, $FFFF00 inc c ; ld bc, $FFFF01 ; BC is -255 ; sets NZ ; ld bc, -255 add hl, bc - jr c, .overflow_to_inf + jr c, .L.overflow_to_inf ; sbc hl, bc ; restore hl dec l ; we only care about the low 8 bits ex de, hl -.finish_subnormal: +.L.finish_subnormal: push hl -.finish: +.L.finish: rla ; extract signbit rr e rr (iy - 1) @@ -113,7 +115,7 @@ _ldexpf: ;------------------------------------------------------------------------------- -.move_subnormal_down: +.L.move_subnormal_down: ; DE = scale ; BC is -1 here ; first we need to test that the result won't be zero @@ -126,30 +128,30 @@ _ldexpf: ld a, l sbc hl, bc cpl - jr nc, _ldexpf.shru_common + jr nc, .L.shru_common ; .underflow: inc b ; ld b, 0 ; sets Z -.overflow_to_inf: ; <-- NZ is set when infinite +.L.overflow_to_inf: ; <-- NZ is set when infinite ld a, $28 ; FE_OVERFLOW | FE_INEXACT -.underflow_to_zero: ; <-- Z is set when underflowing to zero -.raise_erange: +.L.underflow_to_zero: ; <-- Z is set when underflowing to zero +.L.raise_erange: ld hl, $800000 - jr nz, .overflow + jr nz, .L.overflow ld a, $24 ; FE_UNDERFLOW | FE_INEXACT add hl, hl ; ld hl, 0 -if __ldexpf_avoid_negative_zero +.if __ldexpf_avoid_negative_zero ; prevents negative zero from being emitted on underflow res 7, (iy + 6) -end if -.overflow: +.endif +.L.overflow: ex de, hl ld hl, 5 ; ERANGE ld (_errno), hl -.raise_inexact: +.L.raise_inexact: ld hl, ___fe_cur_env or a, (hl) ld (hl), a -.result_is_exact: +.L.result_is_exact: ld a, (iy + 6) ; expon rla ; extract signbit ex de, hl @@ -159,24 +161,24 @@ end if ret ;------------------------------------------------------------------------------- -.scale_down: +.L.scale_down: push de ; mant <<= 1 ld e, l ; shift amount ; HL is not INT_MIN here dec hl add hl, hl - jr nc, .finish ; expon > 0 + jr nc, .L.finish ; expon > 0 ;------------------------------------------------------------------------------- -.shru_to_subnormal: +.L.shru_to_subnormal: ; Z is set here xor a, a ld c, 48 ; ld bc, 24 << 1 add hl, bc pop hl ; reset SP - jr nc, .underflow_to_zero + jr nc, .L.underflow_to_zero sub a, e set 7, (iy + 5) ; set implicit mantissa bit -.shru_common: +.L.shru_common: ; A should be [0, 23] ld b, a ld hl, (iy + 3) ; mantissa @@ -186,43 +188,43 @@ end if ; shift amount will be [1, 24] ld d, a ; ld d, 0 ld c, (iy - 1) -.shru_loop: +.L.shru_loop: adc a, d ; collect sticky bits srl c rr h rr l - djnz .shru_loop + djnz .L.shru_loop ld (iy - 1), c pop de ld d, h ld e, l ; round upwards to even if (round && (guard || sticky)) - jr nc, .no_round + jr nc, .L.no_round ; we must ensure that FE_INEXACT is raised since rounding has occured or a, a - jr nz, .round_up + jr nz, .L.round_up inc a ; ld a, 1 and a, e ; test guard bit - jr z, .no_round_inexact -.round_up: + jr z, .L.no_round_inexact +.L.round_up: inc de ; round upwards to even (wont overflow) -.no_round: +.L.no_round: adc a, a ; test the sticky and round bits - jr z, .result_is_exact + jr z, .L.result_is_exact ; carry wont be set -.no_round_inexact: +.L.no_round_inexact: ; we need to raise ERANGE if the mantissa was rounded down to zero ld a, c ; UDE or a, d or a, e ld a, $20 ; FE_INEXACT - jr nz, .raise_inexact + jr nz, .L.raise_inexact ; NZ needs to be set here - jr .raise_erange + jr .L.raise_erange - extern _errno - extern ___fe_cur_env - extern __ictlz + .extern _errno + .extern ___fe_cur_env + .extern __ictlz -end if +.endif diff --git a/src/libc/ldiv.src b/src/libc/ldiv.src index b893a8941..ded14d699 100644 --- a/src/libc/ldiv.src +++ b/src/libc/ldiv.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _ldiv + .type _ldiv, @function - section .text - public _ldiv _ldiv: pop hl @@ -45,12 +47,12 @@ _ldiv: push de push de bit 2, c - jr z, .ei_skip + jr z, .L.ei_skip ei -.ei_skip: +.L.ei_skip: jp (hl) - extern __ldivs_lrems_common - extern __ldvrmu - extern __lneg + .extern __ldivs_lrems_common + .extern __ldvrmu + .extern __lneg diff --git a/src/libc/llabs.src b/src/libc/llabs.src index 4a48520d7..b518127a6 100644 --- a/src/libc/llabs.src +++ b/src/libc/llabs.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _imaxabs + .type _imaxabs, @function + .global _llabs + .type _llabs, @function - section .text - public _imaxabs, _llabs _imaxabs: _llabs: pop iy @@ -17,4 +21,4 @@ _llabs: jp (iy) - extern __llneg.hijack_nc + .extern __llneg.hijack_nc diff --git a/src/libc/lldiv.src b/src/libc/lldiv.src index 9a49bb01c..89f098b78 100644 --- a/src/libc/lldiv.src +++ b/src/libc/lldiv.src @@ -1,7 +1,11 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _imaxdiv + .type _imaxdiv, @function + .global _lldiv + .type _lldiv, @function - section .text - public _imaxdiv, _lldiv _imaxdiv: _lldiv: @@ -42,5 +46,5 @@ _lldiv: jp (hl) - extern __llneg - extern __llrems + .extern __llneg + .extern __llrems diff --git a/src/libc/log10f.c b/src/libc/log10f.c index 36c815861..4349bd8a5 100644 --- a/src/libc/log10f.c +++ b/src/libc/log10f.c @@ -1,8 +1,24 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _log10f\n" + "\t.type _log10f, @function\n" + "\t.equ _log10f, 0x0220E8\n" + "\t.global _log10\n" + "\t.type _log10, @function\n" + "\t.equ _log10, _log10f\n" +); + +#else + #include -float _log10f_c(float x) +float log10f(float x) { return logf(x) * (float)(M_LOG10E); } -double _log10_c(double) __attribute__((alias("_log10f_c"))); +double log10(double) __attribute__((alias("log10f"))); + +#endif diff --git a/src/libc/log10f.src b/src/libc/log10f.src deleted file mode 100644 index 8481ecc88..000000000 --- a/src/libc/log10f.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _log10f - public _log10 - -if PREFER_OS_LIBC - -_log10f := 0220E8h -_log10 := _log10f - -else - -_log10f := __log10f_c -_log10 := __log10_c - - extern __log10f_c - extern __log10_c - -end if diff --git a/src/libc/logbf.src b/src/libc/logbf.src index 5a5dc8b34..d381731fc 100644 --- a/src/libc/logbf.src +++ b/src/libc/logbf.src @@ -1,8 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _logbf, _logb + .global _logbf + .type _logbf, @function + .global _logb + .type _logb, @function ; float logbf(float) _logb: @@ -16,14 +19,14 @@ _logbf: ld hl, (hl) add hl, hl adc a, a - jr z, .maybe_subnormal + jr z, .L.maybe_subnormal inc a - jr z, .inf_nan + jr z, .L.inf_nan sub a, 128 ; float32_bias + 1 - jr c, .negative_exponent + jr c, .L.negative_exponent inc bc ; ld bc, 0 -.negative_exponent: -.int_to_float: +.L.negative_exponent: +.L.int_to_float: ; exponent is [-149, 127] ld c, a ld a, b ; sign extend @@ -33,7 +36,7 @@ _logbf: ld e, a ret -.inf_nan: +.L.inf_nan: ; return fabsf(x) pop bc ex (sp), hl @@ -41,7 +44,7 @@ _logbf: ld e, $7F ret -.ret_zero: +.L.ret_zero: ; HL is zero here ld l, 4 ; EDOM ld (_errno), hl @@ -53,14 +56,14 @@ _logbf: ld e, b ; ld e, $FF ret -.maybe_subnormal: +.L.maybe_subnormal: add hl, bc inc hl ; restore HL - jr nc, .ret_zero + jr nc, .L.ret_zero call __ictlz cpl add a, 130 - jr .int_to_float + jr .L.int_to_float extern __ltof extern __ictlz diff --git a/src/libc/logf.c b/src/libc/logf.c index 53da9cb07..6dee090cf 100644 --- a/src/libc/logf.c +++ b/src/libc/logf.c @@ -1,16 +1,16 @@ -/************************************************************************/ -/* */ -/* Copyright (C) 1999-2008 by Zilog, Inc. */ -/* */ -/************************************************************************/ -/* - log returns the natural logarithm of its floating - point argument. +#if PERFER_CE_LIBC - The coefficients are #2705 from Hart & Cheney. (19.38D) +asm +( + "\t.global _logf\n" + "\t.type _logf, @function\n" + "\t.equ _logf, 0x0220E4\n" + "\t.global _log\n" + "\t.type _log, @function\n" + "\t.equ _log, _logf\n" +); - It calls frexp. -*/ +#else #include #include @@ -26,7 +26,7 @@ #define q0 -0.120069589779605e2f #define q1 0.194809660700890e2f #define q2 -0.891110902798312e1f - + /** * @remarks Minimum ulp: * ulp of +4 at +0x1.8ef9aap-1 @@ -34,7 +34,7 @@ * See the purple line for relative precision (lag warning): * https://www.desmos.com/calculator/gae4qofdtc */ -float _logf_c(float arg) +float logf(float arg) { float x, z, zsq, temp; int expon; @@ -58,4 +58,6 @@ float _logf_c(float arg) return temp; } -double _log_c(double) __attribute__((alias("_logf_c"))); +double log(double) __attribute__((alias("logf"))); + +#endif diff --git a/src/libc/logf.src b/src/libc/logf.src deleted file mode 100644 index 99d7c1312..000000000 --- a/src/libc/logf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _logf - public _log - -if PREFER_OS_LIBC - -_logf := 0220E4h -_log := _logf - -else - -_logf := __logf_c -_log := __log_c - - extern __logf_c - extern __log_c - -end if diff --git a/src/libc/makefile b/src/libc/makefile index 274aa86c5..24db58bf5 100644 --- a/src/libc/makefile +++ b/src/libc/makefile @@ -16,17 +16,25 @@ include $(CURDIR)/../common.mk -BUILD_SRC := $(patsubst %,build/%.src,$(wildcard *.c *.cpp)) +OBJECTS = +OBJECTS += $(patsubst %.c,build/%.c.o,$(wildcard *.c)) +OBJECTS += $(patsubst %.cpp,build/%.cpp.o,$(wildcard *.cpp)) +OBJECTS += $(patsubst %.src,build/%.o,$(wildcard *.src)) -EZCFLAGS := -S -fno-addrsig -ffreestanding -Wall -Wextra -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -EZCFLAGS += -D_EZ80 -isystem ../libc/include -isystem ../ce/include -isystem ../fileioc -mllvm -profile-guided-section-prefix=false -EZCXXFLAGS := $(EZCFLAGS) -fno-exceptions -fno-rtti -EZCXXFLAGS += -isystem ../libcxx/include +OBJECTS_CE = +OBJECTS_CE += $(patsubst %.c,build/%.c.ce.o,$(wildcard *.c)) +OBJECTS_CE += $(patsubst %.cpp,build/%.cpp.ce.o,$(wildcard *.cpp)) +OBJECTS_CE += $(patsubst %.src,build/%.ce.o,$(wildcard *.src)) -WILDCARD_SRC = $(wildcard *.src) $(BUILD_SRC) -WILDCARD_H := $(wildcard include/*.h) +.SECONDARY: -all: $(BUILD_SRC) +all: build/libc.a build/libc_ce.a + $(MAKE) -C allocator + $(MAKE) -C printf + +build/libc.a: $(OBJECTS) + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ build/%.c.src: %.c $(Q)$(call MKDIR,build) @@ -36,14 +44,54 @@ build/%.cpp.src: %.cpp $(Q)$(call MKDIR,build) $(Q)$(EZCC) $(EZCXXFLAGS) $< -o $@ +build/%.c.o: build/%.c.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.cpp.o: build/%.cpp.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.o: %.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +# ----- + +build/libc_ce.a: $(OBJECTS_CE) + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ + +build/%.c.ce.src: %.c + $(Q)$(call MKDIR,build) + $(Q)$(EZCC) $(EZCFLAGS) -DPERFER_CE_LIBC=1 $< -o $@ + +build/%.cpp.ce.src: %.cpp + $(Q)$(call MKDIR,build) + $(Q)$(EZCC) $(EZCXXFLAGS) -DPERFER_CE_LIBC=1 $< -o $@ + +build/%.c.ce.o: build/%.c.ce.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) --defsym PERFER_CE_LIBC=1 $< -o $@ + +build/%.cpp.ce.o: build/%.cpp.ce.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) --defsym PERFER_CE_LIBC=1 $< -o $@ + +build/%.ce.o: %.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) --defsym PERFER_CE_LIBC=1 $< -o $@ + clean: $(Q)$(call RMDIR,build) install: all $(Q)$(call MKDIR,$(INSTALL_H)) $(Q)$(call MKDIR,$(INSTALL_LIBC)) - $(Q)$(call COPY,$(call NATIVEPATH,$(WILDCARD_SRC)),$(INSTALL_LIBC)) - $(Q)$(call COPY,$(foreach file,$(call NATIVEPATH,$(WILDCARD_H)),$(call QUOTE_ARG,$(file))),$(INSTALL_H)) - -.PHONY: all clean + $(Q)$(call COPY,$(call NATIVEPATH,build/libc.a),$(INSTALL_LIBC)) + $(Q)$(call COPY,$(call NATIVEPATH,build/libc_ce.a),$(INSTALL_LIBC)) + $(Q)$(call COPY,$(foreach file,$(call NATIVEPATH,$(wildcard include/*.h)),$(call QUOTE_ARG,$(file))),$(INSTALL_H)) + $(MAKE) -C allocator install + $(MAKE) -C printf install +.PHONY: all clean install diff --git a/src/libc/memccpy.src b/src/libc/memccpy.src index fa729cd68..c829ba319 100644 --- a/src/libc/memccpy.src +++ b/src/libc/memccpy.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _memccpy + .global _memccpy + .type _memccpy, @function _memccpy: ld iy, 0 diff --git a/src/libc/memcpy.src b/src/libc/memcpy.src index 815618c69..505cef25e 100644 --- a/src/libc/memcpy.src +++ b/src/libc/memcpy.src @@ -1,14 +1,15 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _memcpy + .global _memcpy + .type _memcpy, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_memcpy := $0000A4 + .set _memcpy, 0x0000A4 -else +.else _memcpy: ld iy, -1 @@ -16,12 +17,12 @@ _memcpy: ld bc, (iy + 10) ; Load count sbc hl, hl add hl, bc - jr nc, .zero + jr nc, .L.zero ld de, (iy + 4) ; Load destination ld hl, (iy + 7) ; Load source ldir -.zero: +.L.zero: ld hl, (iy + 4) ; Return the destination pointer ret -end if +.endif diff --git a/src/libc/memmem.src b/src/libc/memmem.src index 61c94a301..cb680fb6b 100644 --- a/src/libc/memmem.src +++ b/src/libc/memmem.src @@ -1,21 +1,24 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _memmem + .global _memmem + .type _memmem, @function + .local _memcmp_fast + .type _memcmp_fast, @function ; void *memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) -haystack := iy + 3 -haystack_len := iy + 6 -needle := iy + 9 -needle_len := iy + 12 + .equ haystack, 3 + .equ haystack_len, 6 + .equ needle, 9 + .equ needle_len, 12 _memmem: ld iy, 0 add iy, sp - ld hl, (haystack_len) - ld bc, (needle_len) + ld hl, (iy + haystack_len) + ld bc, (iy + needle_len) sbc hl, bc - jr c, .ret_null ; (haystack_len < needle_len) + jr c, .L.ret_null ; (haystack_len < needle_len) ; (haystack_len >= needle_len) push hl @@ -23,28 +26,28 @@ _memmem: sbc hl, hl add hl, bc pop bc - ld hl, (haystack) + ld hl, (iy + haystack) ret nc ; return haystack if needle_len is zero inc bc ; BC = (haystack_len - needle_len + 1) = search_len ; haystack_len >= needle_len && needle_len != 0, therefore haystack_len >= 1 - call .begin_loop - jr nz, .ret_null + call .L.begin_loop + jr nz, .L.ret_null ; test for a match at the last possible position dec hl push hl call _memcmp_fast pop hl ret z -.ret_null: +.L.ret_null: or a, a sbc hl, hl ret -.loop: +.L.loop: pop bc -.begin_loop: - ld de, (needle) +.L.begin_loop: + ld de, (iy + needle) ld a, (de) cpir ; search for the start of the string ret po ; end of search_len @@ -53,7 +56,7 @@ _memmem: dec hl call _memcmp_fast pop hl - jr nz, .loop + jr nz, .L.loop ; pop bc ld sp, iy dec hl @@ -67,11 +70,11 @@ _memcmp_fast: ; Output: ; Z = match ; NZ = no match - ld bc, (needle_len) -.loop: + ld bc, (iy + needle_len) +.L_memcmp_fast.loop: cpi ret po inc de ld a, (de) - jr z, .loop + jr z, .L_memcmp_fast.loop ret diff --git a/src/libc/memmove.src b/src/libc/memmove.src index e684f11c7..1bdb0d6be 100644 --- a/src/libc/memmove.src +++ b/src/libc/memmove.src @@ -1,16 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _memmove + .global _memmove + .type _memmove, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_memmove := 0000A8h + .set _memmove, 0x0000A8 -else +.else -if 1 +.if 1 ; Optimized for when src != dst _memmove: @@ -24,22 +25,22 @@ _memmove: ld bc, (iy + 10) sbc hl, hl add hl, bc - jr nc, .zero + jr nc, .L.zero ld hl, (iy + 7) ld de, (iy + 4) sbc hl, de ; src <= dst - jr c, .copy_backwards + jr c, .L.copy_backwards ; src > dst ; .copy_forwards: add hl, de inc hl ldir -.zero: +.L.zero: ld hl, (iy + 4) ret -.copy_backwards: +.L.copy_backwards: ; move HL and DE to the end ex de, hl add hl, bc @@ -51,7 +52,7 @@ _memmove: inc hl ret -else +.else ; Optimized for when src == dst _memmove: @@ -65,7 +66,7 @@ _memmove: ld bc, (iy + 10) sbc hl, hl add hl, bc - jr nc, .zero + jr nc, .L.zero ld de, (iy + 4) ld hl, (iy + 7) or a, a @@ -73,17 +74,17 @@ _memmove: ; src < dst jr c, .copy_backwards ; src >= dst -; .copy_forwards: +; .L.copy_forwards: add hl, de ; src == dst ret z ; skips LDIR when src == dst ; src > dst ldir -.zero: +.L.zero: ld hl, (iy + 4) ret -.copy_backwards: +.L.copy_backwards: ; move HL and DE to the end dec de ; DE = dst - 1 ex de, hl @@ -95,6 +96,6 @@ _memmove: inc hl ret -end if +.endif -end if +.endif diff --git a/src/libc/mempcpy.src b/src/libc/mempcpy.src index 13ac505bc..4e0a1c96e 100644 --- a/src/libc/mempcpy.src +++ b/src/libc/mempcpy.src @@ -1,10 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _mempcpy + .global _mempcpy + .type _mempcpy, @function -if 0 +.if 0 ; faster when count is zero _mempcpy: @@ -21,7 +22,7 @@ _mempcpy: ex de, hl ret -else +.else ; faster in full execution case by 0F + 1 clock cycles _mempcpy: @@ -31,11 +32,11 @@ _mempcpy: sbc hl, hl add hl, bc ld de, (iy + 4) ; Load destination - jr nc, .zero_byte_copy ; zero bytes to copy + jr nc, .L.zero_byte_copy ; zero bytes to copy ld hl, (iy + 7) ; Load source ldir -.zero_byte_copy: +.L.zero_byte_copy: ex de, hl ret -end if +.endif diff --git a/src/libc/memrchr.src b/src/libc/memrchr.src index 5242f47f4..7bd4ccee1 100644 --- a/src/libc/memrchr.src +++ b/src/libc/memrchr.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _memrchr + .global _memrchr + .type _memrchr, @function _memrchr: ld iy, -1 @@ -10,7 +11,7 @@ _memrchr: ld bc, (iy + 10) sbc hl, hl add hl, bc - jr nc, .ret_zero + jr nc, .L.ret_zero ld de, (iy + 4) add hl, de ld a, (iy + 7) @@ -18,7 +19,7 @@ _memrchr: inc hl ret z ; found match ; or a, a ; carry won't be set unless (ptr + size) wraps-around (which is UB) -.ret_zero: +.L.ret_zero: ; return NULL sbc hl, hl ret diff --git a/src/libc/memrmem.src b/src/libc/memrmem.src index 9b9688fb3..bfd570e0c 100644 --- a/src/libc/memrmem.src +++ b/src/libc/memrmem.src @@ -1,21 +1,22 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _memrmem + .global _memrmem + .type _memrmem, @function ; void *memrmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) -haystack := iy + 3 -haystack_len := iy + 6 -needle := iy + 9 -needle_len := iy + 12 + .equ haystack, 3 + .equ haystack_len, 6 + .equ needle, 9 + .equ needle_len, 12 _memrmem: ld iy, 0 add iy, sp - ld hl, (haystack_len) - ld bc, (needle_len) + ld hl, (iy + haystack_len) + ld bc, (iy + needle_len) sbc hl, bc - jr c, .ret_null ; (haystack_len < needle_len) + jr c, .L.ret_null ; (haystack_len < needle_len) ; (haystack_len >= needle_len) push hl @@ -24,17 +25,17 @@ _memrmem: ; DE = needle_len ; move to the end of the needle - ld hl, (needle) + ld hl, (iy + needle) ; return haystack when haystack_len is zero (implies that needle_len is also zero) - jr z, .zero_haystack_len + jr z, .L.zero_haystack_len add hl, bc dec hl - ld (needle), hl + ld (iy + needle), hl sbc hl, hl adc hl, bc pop bc - ld hl, (haystack) + ld hl, (iy + haystack) ; move to the end of the haystack add hl, de @@ -45,36 +46,36 @@ _memrmem: inc bc ; BC = (haystack_len - needle_len + 1) = search_len ; haystack_len >= needle_len && needle_len != 0, therefore haystack_len >= 1 - call .begin_loop - jr nz, .ret_null + call .L.begin_loop + jr nz, .L.ret_null ; test for a match at the last possible position call _memrcmp_fast inc hl ret z -.ret_null: +.L.ret_null: or a, a sbc hl, hl ret -.loop: +.L.loop: pop hl pop bc -.begin_loop: - ld de, (needle) +.L.begin_loop: + ld de, (iy + needle) ld a, (de) cpdr ; search for the start of the string ret po ; end of search_len push bc push hl call _memrcmp_fast - jr nz, .loop + jr nz, .L.loop inc hl ld sp, iy ret -.zero_haystack_len: +.L.zero_haystack_len: pop hl - ld hl, (haystack) + ld hl, (iy + haystack) ret _memrcmp_fast: @@ -86,11 +87,11 @@ _memrcmp_fast: ; Z = match ; NZ = no match inc hl - ld bc, (needle_len) -.loop: + ld bc, (iy + needle_len) +.L_memrcmp_fast.loop: cpd ret po dec de ld a, (de) - jr z, .loop + jr z, .L_memrcmp_fast.loop ret diff --git a/src/libc/memset.src b/src/libc/memset.src index 6aefd9d3e..6fe329f10 100644 --- a/src/libc/memset.src +++ b/src/libc/memset.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _memset + .global _memset + .type _memset, @function _memset: ld iy, -1 @@ -11,12 +12,12 @@ _memset: sbc hl, hl ; always resets overflow add hl, bc ; HL = size - 1 ld de, (iy + 4) ; DE = dst - jr nc, .zero_size + jr nc, .L.zero_size ld a, (iy + 7) add hl, de ; HL = dst + size - 1 ld (hl), a cpd ; HL = dst + size - 2, BC = size - 1 -.zero_size: +.L.zero_size: ex de, hl ; DE = dst + size - 2, HL = dst ret po ; return if size == 1 add hl, bc ; HL = dst + size - 1 diff --git a/src/libc/modff.src b/src/libc/modff.src index 977fa0ba9..3da5329bf 100644 --- a/src/libc/modff.src +++ b/src/libc/modff.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public _modff - public _modf + .section .text + .global _modff + .type _modff, @function + .global _modf + .type _modf, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_modff := 0220ECh -_modf := _modff + .set _modff, 0x0220EC + .set _modf, _modff -else +.else ; float modf(float x, float* iptr) _modff: @@ -25,31 +27,32 @@ _modf: ld e, a rla ld d, a - jr z, .maybe_inf + jr z, .L.maybe_inf inc a ld a, e - jr z, .ret_nan -.not_inf: + jr z, .L.ret_nan +.L.not_inf: ld a, d sub a, 127 ; |x| < 1.0f - jr c, .less_than_one + jr c, .L.less_than_one ; fintie and normal ld hl, (ix + 6) ; mantissa ; E has exponent push de push hl call _truncf - pop af, af + pop af + pop af ld a, e - ex hl, de + ex de, hl ld hl, (ix + 12) ; float *iptr ld (hl), de inc hl inc hl inc hl ld (hl), a - ex hl, de + ex de, hl ld e, a ld bc, (ix + 6) ld a, (ix + 9) @@ -61,9 +64,9 @@ _modf: pop ix ret -.maybe_inf: +.L.maybe_inf: inc a - jr nz, .not_inf + jr nz, .L.not_inf ld a, e ld hl, (ix + 12) ; float *iptr ld (hl), bc @@ -77,12 +80,12 @@ _modf: pop ix ret -.less_than_one: +.L.less_than_one: ld bc, 0 ld a, e and a, $80 ; A:UBC = copysignf(0.0f, x) -.ret_nan: +.L.ret_nan: ld hl, (ix + 12) ; float *iptr ld (hl), bc inc hl @@ -94,8 +97,8 @@ _modf: pop ix ret - extern __frameset0 - extern _truncf - extern __fsub + .extern __frameset0 + .extern _truncf + .extern __fsub -end if +.endif diff --git a/src/libc/os.src b/src/libc/os.src index 19b6b3be8..c1df4c8a4 100644 --- a/src/libc/os.src +++ b/src/libc/os.src @@ -1,26 +1,36 @@ - assume adl=1 + .assume adl=1 - section .text - - public _longjmp -_longjmp := 000098h - public _memchr -_memchr := 00009Ch - public _memcmp -_memcmp := 0000A0h - public _setjmp -_setjmp := 0000B8h - public _strcat -_strcat := 0000C0h - public _strchr -_strchr := 0000C4h - public _strcpy -_strcpy := 0000CCh - public _strncat -_strncat := 0000D8h - public _strncpy -_strncpy := 0000E0h - public _strstr -_strstr := 0000F0h - public _strtok -_strtok := 0000F4h + .section .text + .global _longjmp + .type _longjmp, @function + .set _longjmp, 0x000098 + .global _memchr + .type _memchr, @function + .set _memchr, 0x00009C + .global _memcmp + .type _memcmp, @function + .set _memcmp, 0x0000A0 + .global _setjmp + .type _setjmp, @function + .set _setjmp, 0x0000B8 + .global _strcat + .type _strcat, @function + .set _strcat, 0x0000C0 + .global _strchr + .type _strchr, @function + .set _strchr, 0x0000C4 + .global _strcpy + .type _strcpy, @function + .set _strcpy, 0x0000CC + .global _strncat + .type _strncat, @function + .set _strncat, 0x0000D8 + .global _strncpy + .type _strncpy, @function + .set _strncpy, 0x0000E0 + .global _strstr + .type _strstr, @function + .set _strstr, 0x0000F0 + .global _strtok + .type _strtok, @function + .set _strtok, 0x0000F4 diff --git a/src/libc/outchar.src b/src/libc/outchar.src index 81ef54839..e5477c83a 100644 --- a/src/libc/outchar.src +++ b/src/libc/outchar.src @@ -1,15 +1,17 @@ - assume adl=1 + .assume adl=1 + + .section .text + .weak _outchar + .type _outchar, @function - section .text - weak _outchar _outchar: pop de - ex (sp),hl + ex (sp), hl push de - ld iy,$d00080 ; ti.flags - ld a,l - cp a,32 - jp nc,$207B8 ; ti.PutC - cp a,10 - jp z,$0207F0 ; ti.NewLine + ld iy, $d00080 ; ti.flags + ld a, l + cp a, 32 + jp nc, $207B8 ; ti.PutC + cp a, 10 + jp z, $0207F0 ; ti.NewLine ret diff --git a/src/libc/powf.src b/src/libc/powf.src index 1db63a85f..1348f6d53 100644 --- a/src/libc/powf.src +++ b/src/libc/powf.src @@ -1,20 +1,22 @@ - assume adl=1 + .assume adl=1 - section .text - public _powf - public _pow + .section .text + .global _powf + .type _powf, @function + .global _pow + .type _pow, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_powf := 0220F8h -_pow := _powf + .set _powf, 0x0220F8 + .set _pow, _powf -else +.else -_powf := __powf_c -_pow := __pow_c + .set _powf, __powf_c + .set _pow, __pow_c - extern __powf_c - extern __pow_c + .extern __powf_c + .extern __pow_c -end if +.endif diff --git a/src/libc/printf.src b/src/libc/printf.src deleted file mode 100644 index 9f307e956..000000000 --- a/src/libc/printf.src +++ /dev/null @@ -1,16 +0,0 @@ - assume adl=1 - - section .text - -if HAS_PRINTF - - public _printf - public _vprintf - -_printf := __printf_c -_vprintf := __vprintf_c - - extern __printf_c - extern __vprintf_c - -end if diff --git a/src/libc/printf/makefile b/src/libc/printf/makefile new file mode 100644 index 000000000..18a6f90e4 --- /dev/null +++ b/src/libc/printf/makefile @@ -0,0 +1,49 @@ +# Copyright (C) 2015-2025 CE Programming +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +include $(CURDIR)/../../common.mk + +OBJECTS = +OBJECTS += $(patsubst %.c,build/%.c.o,$(wildcard *.c)) +OBJECTS += $(patsubst %.cpp,build/%.cpp.o,$(wildcard *.cpp)) +OBJECTS += $(patsubst %.src,build/%.o,$(wildcard *.src)) + +LIB_NANOPRINTF := libnanoprintf.a + +.SECONDARY: + +all: build/$(LIB_NANOPRINTF) + +build/$(LIB_NANOPRINTF): $(OBJECTS) + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ + +build/%.c.o: build/%.c.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.c.src: %.c + $(Q)$(call MKDIR,build) + $(Q)$(EZCC) $(EZCFLAGS) $< -o $@ + +clean: + $(Q)$(call RMDIR,build) + +install: all + $(Q)$(call MKDIR,$(INSTALL_LIBC)) + $(Q)$(call COPY,$(call NATIVEPATH,build/$(LIB_NANOPRINTF)),$(INSTALL_LIBC)) + +.PHONY: all clean install diff --git a/src/libc/nanoprintf.c b/src/libc/printf/nanoprintf.c similarity index 66% rename from src/libc/nanoprintf.c rename to src/libc/printf/nanoprintf.c index 347ec7529..1dccc2753 100644 --- a/src/libc/nanoprintf.c +++ b/src/libc/printf/nanoprintf.c @@ -41,7 +41,7 @@ static void npf_fputc_std(int c, void *ctx) { #include "nanoprintf.h" -int _vsnprintf_c(char *__restrict buffer, size_t bufsz, char const *__restrict format, va_list vlist) { +int vsnprintf(char *__restrict buffer, size_t bufsz, char const *__restrict format, va_list vlist) { npf_bufputc_ctx_t bufputc_ctx; bufputc_ctx.dst = buffer; bufputc_ctx.len = bufsz; @@ -60,31 +60,31 @@ int _vsnprintf_c(char *__restrict buffer, size_t bufsz, char const *__restrict f return n; } -int _snprintf_c(char *__restrict buffer, size_t bufsz, const char *__restrict format, ...) { +int snprintf(char *__restrict buffer, size_t bufsz, const char *__restrict format, ...) { va_list val; va_start(val, format); - int const rv = _vsnprintf_c(buffer, bufsz, format, val); + int const rv = vsnprintf(buffer, bufsz, format, val); va_end(val); return rv; } -int _vsprintf_c(char *__restrict buffer, const char *__restrict format, va_list vlist) +int vsprintf(char *__restrict buffer, const char *__restrict format, va_list vlist) { - return _vsnprintf_c(buffer, (size_t)INT_MAX, format, vlist); + return vsnprintf(buffer, (size_t)INT_MAX, format, vlist); } -int _sprintf_c(char *__restrict buffer, const char *__restrict format, ...) +int sprintf(char *__restrict buffer, const char *__restrict format, ...) { va_list va; va_start(va, format); - const int ret = _vsnprintf_c(buffer, (size_t)INT_MAX, format, va); + const int ret = vsnprintf(buffer, (size_t)INT_MAX, format, va); va_end(va); return ret; } -int _vasprintf_c(char **__restrict p_str, const char *__restrict format, va_list vlist) { +int vasprintf(char **__restrict p_str, const char *__restrict format, va_list vlist) { *p_str = NULL; - int str_len = _vsnprintf_c(NULL, 0, format, vlist); + int str_len = vsnprintf(NULL, 0, format, vlist); if (str_len <= 0) { return str_len; } @@ -94,7 +94,7 @@ int _vasprintf_c(char **__restrict p_str, const char *__restrict format, va_list // malloc failure return -1; } - int ret = _vsnprintf_c(buf, buf_len, format, vlist); + int ret = vsnprintf(buf, buf_len, format, vlist); if (ret <= 0) { free(buf); return ret; @@ -103,39 +103,39 @@ int _vasprintf_c(char **__restrict p_str, const char *__restrict format, va_list return ret; } -int _asprintf_c(char **__restrict p_str, const char *__restrict format, ...) { +int asprintf(char **__restrict p_str, const char *__restrict format, ...) { va_list va; va_start(va, format); - const int ret = _vasprintf_c(p_str, format, va); + const int ret = vasprintf(p_str, format, va); va_end(va); return ret; } __attribute__((__always_inline__)) -int _vfprintf_c(FILE* __restrict stream, const char* __restrict format, va_list vlist) +int vfprintf(FILE* __restrict stream, const char* __restrict format, va_list vlist) { return npf_vpprintf(npf_fputc_std, (void*)stream, format, vlist); } -int _fprintf_c(FILE* __restrict stream, const char* __restrict format, ...) +int fprintf(FILE* __restrict stream, const char* __restrict format, ...) { va_list va; va_start(va, format); - const int ret = _vfprintf_c(stream, format, va); + const int ret = vfprintf(stream, format, va); va_end(va); return ret; } __attribute__((__always_inline__)) -int _vprintf_c(const char *__restrict format, va_list vlist) +int vprintf(const char *__restrict format, va_list vlist) { return npf_vpprintf(npf_putc_std, NULL, format, vlist); } -int _printf_c(char const *__restrict format, ...) { +int printf(char const *__restrict format, ...) { va_list va; va_start(va, format); - int const rv = _vprintf_c(format, va); + int const rv = vprintf(format, va); va_end(va); return rv; } diff --git a/src/libc/nanoprintf.h b/src/libc/printf/nanoprintf.h similarity index 100% rename from src/libc/nanoprintf.h rename to src/libc/printf/nanoprintf.h diff --git a/src/libc/putc.src b/src/libc/putc.src deleted file mode 100644 index 4ce8a9816..000000000 --- a/src/libc/putc.src +++ /dev/null @@ -1,9 +0,0 @@ - assume adl=1 - - section .text - - public _putc - -_putc := _fputc - - extern _fputc diff --git a/src/libc/putchar.src b/src/libc/putchar.src index 022a992f0..a40dbfdfd 100644 --- a/src/libc/putchar.src +++ b/src/libc/putchar.src @@ -1,10 +1,12 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _putchar + .type _putchar, @function - section .text - public _putchar _putchar: pop de - ex (sp),hl + ex (sp), hl push de push hl push hl @@ -13,4 +15,4 @@ _putchar: pop hl ret - extern _outchar + .extern _outchar diff --git a/src/libc/puts.src b/src/libc/puts.src index 0dc70d5c1..eee73ba64 100644 --- a/src/libc/puts.src +++ b/src/libc/puts.src @@ -1,28 +1,30 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _puts + .type _puts, @function - section .text - public _puts _puts: pop de - ex (sp),hl + ex (sp), hl push de -.loop: - ld a,(hl) - or a,a - jr z,.newline - ld e,a +.L.loop: + ld a, (hl) + or a, a + jr z, .L.newline + ld e, a push hl push de call _outchar pop de pop hl inc hl - jr .loop -.newline: - ld l,10 + jr .L.loop +.L.newline: + ld l, 10 push hl call _outchar pop hl ret - extern _outchar + .extern _outchar diff --git a/src/libc/rand.src b/src/libc/rand.src index 8c1ab6eac..c205d19f6 100644 --- a/src/libc/rand.src +++ b/src/libc/rand.src @@ -1,13 +1,15 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _rand + .type _rand, @function - section .text - public _rand _rand: call _random - ld de,8388608 - sbc hl,de + ld de, 8388608 + sbc hl, de ret p - add hl,de + add hl, de ret - extern _random + .extern _random diff --git a/src/libc/scalblnf.src b/src/libc/scalblnf.src index 3a1ae3c2c..4ea24aa18 100644 --- a/src/libc/scalblnf.src +++ b/src/libc/scalblnf.src @@ -1,8 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _scalblnf, _scalbln + .global _scalblnf + .type _scalblnf, @function + .global _scalbln + .type _scalbln, @function ; float _scalblnf(float, long) _scalbln: @@ -17,7 +20,7 @@ _scalblnf: ; It implies that the scale is either already [-65536, +65535] and can ; be safely truncated, or that the original and truncated scale values ; are both larger than +-65535 and have the same sign. -.overflow: +.L.overflow: cp a, (hl) jp z, _scalbnf ; We need modify the scale value to ensure that overflow/underflow still occurs. @@ -27,6 +30,6 @@ _scalblnf: ; bit 23 = bit 31, bit 16 is cleared, and bit 17 is set ld (hl), a ; store the new scale ; cp a, a ; set Z flag - jr .overflow + jr .L.overflow - extern _scalbnf + .extern _scalbnf diff --git a/src/libc/scalblnl.src b/src/libc/scalblnl.src index 3d4882140..ed7292d6d 100644 --- a/src/libc/scalblnl.src +++ b/src/libc/scalblnl.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _scalblnl + .global _scalblnl + .type _scalblnl, @function ; long double _scalblnl(long double, long) _scalblnl: @@ -16,7 +17,7 @@ _scalblnl: ; It implies that the scale is either already [-65536, +65535] and can ; be safely truncated, or that the original and truncated scale values ; are both larger than +-65535 and have the same sign. -.overflow: +.L.overflow: cp a, (hl) jp z, _scalbnl ; We need modify the scale value to ensure that overflow/underflow still occurs. @@ -26,6 +27,6 @@ _scalblnl: ; bit 23 = bit 31, bit 16 is cleared, and bit 17 is set ld (hl), a ; store the new scale ; cp a, a - jr .overflow + jr .L.overflow - extern _scalbnl + .extern _scalbnl diff --git a/src/libc/signbitf.src b/src/libc/signbitf.src index b547473ba..725c97541 100644 --- a/src/libc/signbitf.src +++ b/src/libc/signbitf.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __signbitf + .global __signbitf + .type __signbitf, @function ; bool _signbitf(float) __signbitf: diff --git a/src/libc/signbitl.src b/src/libc/signbitl.src index acbdb928f..daaf59ac2 100644 --- a/src/libc/signbitl.src +++ b/src/libc/signbitl.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public __signbitl + .global __signbitl + .type __signbitl, @function ; bool _signbitl(long double) __signbitl: diff --git a/src/libc/sinf.src b/src/libc/sinf.src index 0fbbdfcd2..572e76d6b 100644 --- a/src/libc/sinf.src +++ b/src/libc/sinf.src @@ -1,18 +1,20 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _sinf - public _sin + .global _sinf + .type _sinf, @function + .global _sin + .type _sin, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_sinf := 022118h -_sin := _sinf + .set _sinf, 0x022118 + .set _sin, _sinf -else +.else - public _sinf.hijack + .global _sinf.hijack ; float _f32_sinus(int quad, float arg) _sin: @@ -23,7 +25,7 @@ _sinf: ld a, e add a, a ; clear signbit sub a, 117 ; |x| < 2^-10 or 0x3affffff - jr c, .small_arg + jr c, _sinf.small_arg ld a, e res 7, e ; x = fabsf(x) push de ; exponent @@ -32,9 +34,9 @@ _sinf: add a, a ld e, a push de -.hijack: +_sinf.hijack: call __f32_sinus -.small_arg: +_sinf.small_arg: ld sp, ix pop ix ; you can ret here if clamping is not needed @@ -50,7 +52,7 @@ _sinf: ld l, h ; zero out the lower 8 bits of the mantissa ret - extern __frameset0 - extern __f32_sinus + .extern __frameset0 + .extern __f32_sinus -end if +.endif diff --git a/src/libc/sinhf.c b/src/libc/sinhf.c index b54fd2699..589ceb3a9 100644 --- a/src/libc/sinhf.c +++ b/src/libc/sinhf.c @@ -1,24 +1,16 @@ -/************************************************************************/ -/* */ -/* Copyright (C)1987-2008 by */ -/* Zilog, Inc. */ -/* */ -/* San Jose, California */ -/* */ -/************************************************************************/ -/* - sinh(arg) returns the hyperbolic sine of its floating- - point argument. - - The exponential function is called for arguments - greater in magnitude than 0.5. - - A series is used for arguments smaller in magnitude than 0.5. - The coefficients are #2029 from Hart & Cheney. (20.36D) - - cosh(arg) is computed from the exponential function for - all arguments. -*/ +#if PERFER_CE_LIBC + +asm +( + "\t.global _sinhf\n" + "\t.type _sinhf, @function\n" + "\t.equ _sinhf, 0x022130\n" + "\t.global _sinh\n" + "\t.type _sinh, @function\n" + "\t.equ _sinh, _sinhf\n" +); + +#else #include @@ -35,7 +27,7 @@ * ulp of -3 at +0x1.eec25ap-9 with ideal expf (|x| < 21.0f) * ulp of -18 at +0x1.0a049cp+4 with current expf (|x| < 21.0f) */ -float _sinhf_c(float arg) { +float sinhf(float arg) { float temp, argsq, x; x = fabsf(arg); @@ -51,4 +43,6 @@ float _sinhf_c(float arg) { return copysignf(temp, arg); } -double _sinh_c(double, double *) __attribute__((alias("_sinhf_c"))); +double sinh(double) __attribute__((alias("sinhf"))); + +#endif diff --git a/src/libc/sinhf.src b/src/libc/sinhf.src deleted file mode 100644 index 21d150d35..000000000 --- a/src/libc/sinhf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _sinhf - public _sinh - -if PREFER_OS_LIBC - -_sinhf := 022130h -_sinh := _sinhf - -else - -_sinhf := __sinhf_c -_sinh := __sinh_c - - extern __sinhf_c - extern __sinh_c - -end if diff --git a/src/libc/snprintf.src b/src/libc/snprintf.src deleted file mode 100644 index 219768d4b..000000000 --- a/src/libc/snprintf.src +++ /dev/null @@ -1,28 +0,0 @@ - assume adl=1 - - section .text - - public _snprintf - public _vsnprintf - -if HAS_PRINTF - -_snprintf := __snprintf_c -_vsnprintf := __vsnprintf_c - - extern __snprintf_c - extern __vsnprintf_c - -else - -if defined __TICE__ - -_snprintf := _boot_snprintf -_vsnprintf := _boot_vsnprintf - - extern _boot_snprintf - extern _boot_vsnprintf - -end if - -end if diff --git a/src/libc/sprintf.src b/src/libc/sprintf.src deleted file mode 100644 index 2e62abc3e..000000000 --- a/src/libc/sprintf.src +++ /dev/null @@ -1,18 +0,0 @@ - assume adl=1 - - section .text - - public _sprintf - -if HAS_PRINTF - -_sprintf := __sprintf_c - - extern __sprintf_c - -else - -; OS routine -_sprintf := 0000BCh - -end if diff --git a/src/libc/sqrtf.c b/src/libc/sqrtf.c index 456faaf04..3ccd173e9 100644 --- a/src/libc/sqrtf.c +++ b/src/libc/sqrtf.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _sqrtf\n" + "\t.type _sqrtf, @function\n" + "\t.equ _sqrtf, 0x000298\n" + "\t.global _sqrt\n" + "\t.type _sqrt, @function\n" + "\t.equ _sqrt, _sqrtf\n" +); + +#else + #include #include #include @@ -16,7 +30,7 @@ float _f32_fast_div4(float x); /** * @remarks Minimum ulp of -1 */ -float _sqrtf_c(float x) +float sqrtf(float x) { float f, y; int n; @@ -46,4 +60,6 @@ float _sqrtf_c(float x) return ldexpf(y, n/2); } -double _sqrt_c(double) __attribute__((alias("_sqrtf_c"))); +double sqrt(double) __attribute__((alias("sqrtf"))); + +#endif diff --git a/src/libc/sqrtf.src b/src/libc/sqrtf.src deleted file mode 100644 index 08085bda3..000000000 --- a/src/libc/sqrtf.src +++ /dev/null @@ -1,31 +0,0 @@ - assume adl=1 - - section .text - public _sqrtf - public _sqrt - -if PREFER_OS_LIBC - -_sqrtf := 000298h -_sqrt := _sqrtf - -else - - public __f32_fast_div4 - -_sqrtf := __sqrtf_c -_sqrt := __sqrt_c - -; float _f32_fast_div4(float x); -; only works for normalized values -; CC: 9F + 12R + 9W + 1 | 8 bytes -__f32_fast_div4: - pop bc, hl, de - dec e ; subtracts 2 from the exponent - push de, hl, bc - ret - - extern __sqrtf_c - extern __sqrt_c - -end if diff --git a/src/libc/sqrtl.src b/src/libc/sqrtl.src index 6f00423e8..d3e96ed68 100644 --- a/src/libc/sqrtl.src +++ b/src/libc/sqrtl.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _sqrtl + .global _sqrtl + .type _sqrtl, @function _sqrtl: ; flags handled by softfloat @@ -12,6 +13,6 @@ _sqrtl: rlca inc hl ld (hl), a - jq ___f64_sqrt + jp ___f64_sqrt - extern ___f64_sqrt + .extern ___f64_sqrt diff --git a/src/libc/srand.src b/src/libc/srand.src index ba7313bfc..388af04cc 100644 --- a/src/libc/srand.src +++ b/src/libc/srand.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _srand + .type _srand, @function - section .text - public _srand _srand: pop bc ex (sp),hl @@ -9,4 +11,4 @@ _srand: xor a,a jp __setstate - extern __setstate + .extern __setstate diff --git a/src/libc/stpcpy.src b/src/libc/stpcpy.src index 17fae2250..af21ce47f 100644 --- a/src/libc/stpcpy.src +++ b/src/libc/stpcpy.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _stpcpy + .global _stpcpy + .type _stpcpy, @function _stpcpy: pop bc diff --git a/src/libc/stpncpy.src b/src/libc/stpncpy.src index 92ac007d7..c394cf4ec 100644 --- a/src/libc/stpncpy.src +++ b/src/libc/stpncpy.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _stpncpy + .global _stpncpy + .type _stpncpy, @function _stpncpy: ld iy, 0 @@ -13,28 +14,28 @@ _stpncpy: xor a, a sbc hl, hl sbc hl, bc - jr z, .zero_size + jr z, .L.zero_size add hl, bc ld de, (iy + 6) ; src sbc hl, de ex de, hl cpir - jr z, .finish_strnlen + jr z, .L.finish_strnlen inc hl -.finish_strnlen: +.L.finish_strnlen: xor a, a adc hl, de -.zero_size: +.L.zero_size: ; copy strnlen bytes from src push hl ld de, (iy + 3) ; dst - jr z, .zero_byte_copy + jr z, .L.zero_byte_copy ld hl, (iy + 6) ; src pop bc push bc ldir -.zero_byte_copy: +.L.zero_byte_copy: pop bc ; zero pad the remainder diff --git a/src/libc/strcasecmp.src b/src/libc/strcasecmp.src index 43644dc05..f0d375d14 100644 --- a/src/libc/strcasecmp.src +++ b/src/libc/strcasecmp.src @@ -1,13 +1,14 @@ - assume adl=1 + .assume adl=1 - section .text - public _strcasecmp + .section .text + .global _strcasecmp + .type _strcasecmp, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_strcasecmp := 021E3Ch + .set _strcasecmp, 0x021E3C -else +.else _strcasecmp: pop iy @@ -16,44 +17,29 @@ _strcasecmp: push de ld b, 1+'z'-'a' ld c, 'a'-'A' - jr .loop_entry -.loop: + jr .L.cmp_loop_entry +.L.cmp_loop: cp a, (hl) - jr z, .done -.loop_nonnull: + jr z, .L.done +.L.loop_nonnull: inc hl inc de -.loop_entry: +.L.cmp_loop_entry: ld a, (de) xor a, (hl) - jr z, .loop + jr z, .L.cmp_loop cp a, c - jr nz, .mismatch + jr nz, .L.mismatch or a, (hl) sub a, 'a' cp a, b - jr c, .loop_nonnull + jr c, .L.loop_nonnull -end if +.endif - section .text - private _strcasecmp.mismatch - private _strcasecmp.done -_strcasecmp.mismatch: - ld l, (hl) - call _tolower.internal - ex de, hl - ld l, (hl) - call _tolower.internal - ld a, l - sub a, e -_strcasecmp.done: - sbc hl, hl - ld l, a - jp (iy) + .global _strncasecmp + .type _strncasecmp, @function - section .text - public _strncasecmp _strncasecmp: pop iy pop de @@ -68,28 +54,41 @@ _strncasecmp: add hl, bc ex (sp), hl - call c, .loop_entry - jr c, _strcasecmp.mismatch + call c, .L.loop_entry + jr c, .L.mismatch sbc hl, hl jp (iy) -.checkcase: +.L.checkcase: or a, (hl) sub a, 'a' add a, -(1+'z'-'a') ret c -.loop: +.L.loop: cpi ret po ret z inc de -.loop_entry: +.L.loop_entry: ld a, (de) xor a, (hl) - jr z, .loop + jr z, .L.loop cp a, 'a'-'A' - jr z, .checkcase + jr z, .L.checkcase scf ret - extern _tolower.internal +.L.mismatch: + ld l, (hl) + call _tolower.internal + ex de, hl + ld l, (hl) + call _tolower.internal + ld a, l + sub a, e +.L.done: + sbc hl, hl + ld l, a + jp (iy) + + .extern _tolower.internal diff --git a/src/libc/strchrnul.src b/src/libc/strchrnul.src index 926f6aaee..cff22163d 100644 --- a/src/libc/strchrnul.src +++ b/src/libc/strchrnul.src @@ -1,12 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _strchrnul + .global _strchrnul + .type _strchrnul, @function _strchrnul: - pop bc, hl, de - push de, hl, bc + pop bc + pop hl + pop de + push de + push hl + push bc xor a, a ld bc, 0 push hl diff --git a/src/libc/strcmp.src b/src/libc/strcmp.src index f7a56a610..4dfacacf6 100644 --- a/src/libc/strcmp.src +++ b/src/libc/strcmp.src @@ -1,14 +1,15 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _strcmp + .global _strcmp + .type _strcmp, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_strcmp := $0000C8 + .set _strcmp, 0x0000C8 -else +.else _strcmp: ld hl, 3 @@ -18,17 +19,17 @@ _strcmp: inc hl inc hl ld hl, (hl) -.loop: +_strcmp.loop: ld a, (de) cp a, (hl) - jr nz, .finish + jr nz, _strcmp.finish inc hl inc de or a, a - jr nz, .loop -.finish: + jr nz, _strcmp.loop +_strcmp.finish: sbc hl, hl ld l, a ret -end if +.endif diff --git a/src/libc/strcspn.src b/src/libc/strcspn.src index 10c09ca56..a9528fa05 100644 --- a/src/libc/strcspn.src +++ b/src/libc/strcspn.src @@ -1,22 +1,22 @@ - assume adl=1 + .assume adl=1 - section .text - public _strcspn + .section .text + .global _strcspn _strcspn: call __strcspn_strpbrk_common sbc hl, de ; Calculate number of mismatching characters ret - section .text - public _strpbrk + .section .text + .global _strpbrk _strpbrk: call __strcspn_strpbrk_common ret nz ; Return pointer if not end of string sbc hl, hl ; Return NULL ret - section .text - private __strcspn_strpbrk_common + .section .text + .local __strcspn_strpbrk_common __strcspn_strpbrk_common: ld hl, 6 add hl, sp @@ -36,13 +36,13 @@ __strcspn_strpbrk_common: pop iy ; IY = strlen(reject) + 1 dec hl ; HL = reject - 1 push de -.loop: +__strcspn_strpbrk_common.loop: ld a, (de) ; A = *str++ inc de - lea bc, iy ; BC = strlen(reject) + 1 + lea bc, iy + 0 ; BC = strlen(reject) + 1 add hl, bc ; HL = reject + strlen(reject) cpdr ; Find A in reject, including null terminator - jr nz, .loop ; Loop if no match + jr nz, __strcspn_strpbrk_common.loop ; Loop if no match ex de, hl dec hl ; HL = pointer to matching character pop de ; DE = str diff --git a/src/libc/strdup.src b/src/libc/strdup.src index 2b1257657..da12434c4 100644 --- a/src/libc/strdup.src +++ b/src/libc/strdup.src @@ -1,7 +1,7 @@ - assume adl=1 + .assume adl=1 - section .text - public _strdup + .section .text + .global _strdup _strdup: pop de ex (sp), hl @@ -34,5 +34,5 @@ _strdup: pop hl ret - extern _strlen - extern _malloc + .extern _strlen + .extern _malloc diff --git a/src/libc/strlcat.src b/src/libc/strlcat.src index 749c867ca..f69385837 100644 --- a/src/libc/strlcat.src +++ b/src/libc/strlcat.src @@ -1,12 +1,12 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _strlcat + .global _strlcat _strlcat: ld iy, 0 - lea bc, iy + lea bc, iy + 0 add iy, sp ld hl, (iy + 6) ; src xor a, a @@ -22,7 +22,7 @@ _strlcat: sbc hl, hl sbc hl, bc ; Allows dst to be NULL when max_size is zero - jr z, .zero_size ; return src_len + jr z, _strlcat.zero_size ; return src_len add hl, bc push de ; src_len ld de, (iy + 3) ; dst @@ -30,16 +30,16 @@ _strlcat: ex de, hl cpir add hl, de - jr z, .finish_strnlen + jr z, _strlcat.finish_strnlen inc hl -.finish_strnlen: +_strlcat.finish_strnlen: ex de, hl ld hl, (iy + 9) ; max_size ; (copy_size + 1) = max_size - dst_len xor a, a sbc hl, de - jr z, .no_room + jr z, _strlcat.no_room pop bc ; src_len push bc @@ -48,14 +48,14 @@ _strlcat: scf sbc hl, bc - jr c, .copy_size_lt_src_len + jr c, _strlcat.copy_size_lt_src_len ; (copy_size + 1 - 1) >= src_len ; copy_size >= src_len sbc hl, hl -.copy_size_lt_src_len: +_strlcat.copy_size_lt_src_len: xor a, a adc hl, bc - jr z, .zero_copy_size + jr z, _strlcat.zero_copy_size push hl pop bc @@ -67,10 +67,10 @@ _strlcat: ldir ld (de), a ; null terminate pop de ; dst_len -.zero_copy_size: -.no_room: +_strlcat.zero_copy_size: +_strlcat.no_room: pop hl ; src_len -.zero_size: +_strlcat.zero_size: ; return src_len + dst_len add hl, de ret diff --git a/src/libc/strlcpy.src b/src/libc/strlcpy.src index b8f6d87c9..37e36203f 100644 --- a/src/libc/strlcpy.src +++ b/src/libc/strlcpy.src @@ -1,7 +1,7 @@ - assume adl=1 + .assume adl=1 - section .text - public _strlcpy + .section .text + .global _strlcpy ; BSD variant of strncpy that ensures the destination is null-terminated. ; OpenBSD reference: https://github.com/openbsd/src/blob/master/lib/libc/string/strlcpy.c @@ -10,7 +10,7 @@ _strlcpy: ld iy, 0 - lea bc, iy ; set bc to 0 + lea bc, iy + 0 ; set bc to 0 add iy, sp ; do min(strlen(src), dsize-1) @@ -44,14 +44,14 @@ _strlcpy: sbc hl, de ; if hl > de, strlen(src) > (dsize - 1); string is truncated, keep bc as dsize - jr nc, .ready_for_ldir + jr nc, _strlcpy.ready_for_ldir ; hl <= de, so strlen(src) <= (dsize - 1); string is not truncated, set bc to strlen(src) + 1 pop bc push bc inc bc -.ready_for_ldir: +_strlcpy.ready_for_ldir: ld de, (iy + 3) ; put dst in de ld hl, (iy + 6) ; put src in hl ; bc is filled already and greater than 0 diff --git a/src/libc/strlen.src b/src/libc/strlen.src index 774ae53b4..8c076eaa4 100644 --- a/src/libc/strlen.src +++ b/src/libc/strlen.src @@ -1,13 +1,13 @@ - assume adl=1 + .assume adl=1 - section .text - public _strlen + .section .text + .global _strlen -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_strlen := $0000D4 + .set _strlen, 0x0000D4 -else +.else _strlen: pop iy @@ -20,4 +20,4 @@ _strlen: sbc hl, bc jp (iy) -end if +.endif diff --git a/src/libc/strncmp.src b/src/libc/strncmp.src index 85fd9897b..b73b95c3f 100644 --- a/src/libc/strncmp.src +++ b/src/libc/strncmp.src @@ -1,14 +1,15 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _strncmp + .global _strncmp + .type _strncmp, @function -if PREFER_OS_LIBC +.ifdef PERFER_CE_LIBC -_strncmp := $0000DC + .set _strncmp, 0x0000DC -else +.else _strncmp: ld iy, 0 @@ -18,20 +19,20 @@ _strncmp: adc hl, bc ld hl, (iy + 6) ld de, (iy + 3) - call nz, .start ; z means BC was zero -.ret_zero: + call nz, .L.start ; z means BC was zero +.L.ret_zero: sbc hl, hl ret -.loop: +.L.loop: ret po ; ret_zero or a, a ret z ; ret_zero inc de -.start: +.L.start: ld a, (de) cpi - jr z, .loop -.finish: + jr z, .L.loop +.L.finish: ld sp, iy ; ret dec hl sub a, (hl) @@ -39,4 +40,4 @@ _strncmp: ld l, a ret -end if +.endif diff --git a/src/libc/strndup.src b/src/libc/strndup.src index 28cf504d2..b46ad44eb 100644 --- a/src/libc/strndup.src +++ b/src/libc/strndup.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _strndup + .type _strndup, @function - section .text - public _strndup _strndup: pop bc pop de @@ -44,5 +46,5 @@ _strndup: pop hl ret - extern _strnlen - extern _malloc + .extern _strnlen + .extern _malloc diff --git a/src/libc/strnlen.src b/src/libc/strnlen.src index ae69e5657..a67700691 100644 --- a/src/libc/strnlen.src +++ b/src/libc/strnlen.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _strnlen + .type _strnlen, @function - section .text - public _strnlen _strnlen: pop hl pop de diff --git a/src/libc/strrchr.src b/src/libc/strrchr.src index 8df1f1bec..3f2c00eba 100644 --- a/src/libc/strrchr.src +++ b/src/libc/strrchr.src @@ -1,10 +1,16 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _strrchr + .type _strrchr, @function - section .text - public _strrchr _strrchr: - pop bc,hl,de - push de,hl,bc + pop bc + pop hl + pop de + push de + push hl + push bc xor a,a ld bc,0 cpir diff --git a/src/libc/strrstr.src b/src/libc/strrstr.src index 2219ced5a..111c301c2 100644 --- a/src/libc/strrstr.src +++ b/src/libc/strrstr.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _strrstr + .global _strrstr + .type _strrstr, @function _strrstr: pop bc @@ -32,7 +33,10 @@ _strrstr: push hl ; haystack call _memrmem - pop bc, bc, bc, bc + pop bc + pop bc + pop bc + pop bc ret - extern _memrmem + .extern _memrmem diff --git a/src/libc/strspn.src b/src/libc/strspn.src index ee15a5ac5..b1dec9964 100644 --- a/src/libc/strspn.src +++ b/src/libc/strspn.src @@ -1,7 +1,9 @@ - assume adl=1 + .assume adl=1 + + .section .text + .global _strspn + .type _strspn, @function - section .text - public _strspn _strspn: xor a, a sbc hl, hl @@ -14,7 +16,7 @@ _strspn: ; Calculate strlen(accept) ld c, a - lea hl, iy + lea hl, iy + 0 cpir sbc hl, hl scf @@ -24,13 +26,13 @@ _strspn: push hl ex (sp), ix ; IX = strlen(accept) push de -.loop: +.L.loop: ld a, (de) ; A = *str++ inc de - lea hl, iy ; HL = accept - lea bc, ix ; BC = strlen(accept) + lea hl, iy + 0 ; HL = accept + lea bc, ix + 0 ; BC = strlen(accept) cpir ; Find A in accept - jr z, .loop ; Loop if match + jr z, .L.loop ; Loop if match ex de, hl ; Calculate number of matching characters pop de sbc hl, de ; Input carry is set diff --git a/src/libc/strtof.c b/src/libc/strtof.c index 893f13107..c740fd3ae 100644 --- a/src/libc/strtof.c +++ b/src/libc/strtof.c @@ -1,11 +1,16 @@ -/************************************************************************/ -/* */ -/* Copyright (C)1987-2008 by */ -/* Zilog, Inc. */ -/* */ -/* San Jose, California */ -/* */ -/************************************************************************/ +#if PERFER_CE_LIBC + +asm +( + "\t.global _strtof\n" + "\t.type _strtof, @function\n" + "\t.equ _strtof, 0x0220E0\n" + "\t.global _strtod\n" + "\t.type _strtod, @function\n" + "\t.equ _strtod, _strtof\n" +); + +#else #include #include @@ -41,7 +46,7 @@ typedef union F32_pun { * @remarks `*str >= '0' && *str <= '9'` is smaller than calls to `isdigit(*str)` * @todo Add support for INF INFINITY NAN NAN(...) */ -float _strtof_c(char const * const __restrict nptr, char **__restrict endptr) +float strtof(char const * const __restrict nptr, char **__restrict endptr) { F32_pun val; int frac = 0; @@ -145,4 +150,6 @@ float _strtof_c(char const * const __restrict nptr, char **__restrict endptr) return val.flt; } -double _strtod_c(const char *, char **) __attribute__((alias("_strtof_c"))); +double strtod(const char *, char **) __attribute__((alias("strtof"))); + +#endif diff --git a/src/libc/strtof.src b/src/libc/strtof.src deleted file mode 100644 index f6d4e1a15..000000000 --- a/src/libc/strtof.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _strtof - public _strtod - -if PREFER_OS_LIBC - -_strtof := 0220E0h -_strtod := _strtof - -else - -_strtof := __strtof_c -_strtod := __strtod_c - - extern __strtof_c - extern __strtod_c - -end if diff --git a/src/libc/strtol.src b/src/libc/strtol.src index a1646da42..cf5885b2b 100644 --- a/src/libc/strtol.src +++ b/src/libc/strtol.src @@ -1,32 +1,33 @@ - assume adl=1 + .assume adl=1 ;------------------------------------------------------------------------------- - section .text + .section .text.___strtoi - public ___strtoi + .global ___strtoi + .type ___strtoi, @function ___strtoi: ; Similar to strtol, except that it will raise ERANGE and return INT_MIN/INT_MAX when out of range - call __strtol_common + call .L__strtol_common ; overflow occured if B is non-zero - djnz .out_of_range + djnz .L.out_of_range inc e dec e - jr nz, .out_of_range + jr nz, .L.out_of_range ld b, a inc b ex de, hl sbc hl, hl - djnz .positive + djnz .L.positive sbc hl, de ret m ; INT_MIN <= x < 0 ; no underflow if x is zero - jr nz, .out_of_range -.positive: + jr nz, .L.out_of_range +.L.positive: adc hl, de ret p ; 0 <= x <= INT_MAX -.out_of_range: +.L.out_of_range: or a, a ; test sign (Z = negative) ld hl, 5 ; ERANGE ld (_errno), hl @@ -37,35 +38,36 @@ ___strtoi: ;------------------------------------------------------------------------------- - section .text + .section .text._strtol - public _strtol + .global _strtol + .type _strtol, @function _strtol: - call __strtol_common + call .L__strtol_common ; overflow occured if B is non-zero - djnz .out_of_range + djnz .L_strtol.out_of_range ld a, e rla - jr c, .maybe_out_of_range + jr c, .L_strtol.maybe_out_of_range ret nz jp __lneg -.maybe_out_of_range: +.L_strtol.maybe_out_of_range: ; greater than INT_MAX - jr nz, .overflow + jr nz, .L_strtol.overflow ; negative ; check that the result is not an exact INT_MIN or a, a adc hl, hl - jr nz, .underflow + jr nz, .L_strtol.underflow ld a, e adc a, a ret z ; exact INT_MIN -.underflow: +.L_strtol.underflow: xor a, a ; set Z -.out_of_range: -.overflow: +.L_strtol.out_of_range: +.L_strtol.overflow: ld e, $80 ld hl, 5 ; ERANGE ld (_errno), hl @@ -78,28 +80,21 @@ _strtol: ;------------------------------------------------------------------------------- - section .text + .section .text.___strtoui - public ___strtoui + .global ___strtoui + .type ___strtoui, @function ___strtoui: ; Similar to strtoul, except that it will raise ERANGE and return UINT_MAX when out of range - call __strtol_common + call .L__strtol_common ; overflow occured if B is non-zero - djnz _strtoul.out_of_range + djnz .L_strtoui.out_of_range call z, __ineg inc e dec e ret z - - require _strtoul.out_of_range - -;------------------------------------------------------------------------------- - - section .text - - private _strtoul.out_of_range -_strtoul.out_of_range: +.L_strtoui.out_of_range: ld hl, 5 ; ERANGE ld (_errno), hl ld l, h ; ld hl, 0 @@ -107,24 +102,23 @@ _strtoul.out_of_range: ld e, l ret - section .text - - public _strtoul + .section .text._strtoul + .global _strtoul _strtoul: - call __strtol_common + call .L__strtol_common ; overflow occured if B is non-zero - djnz _strtoul.out_of_range + djnz .L_strtoui.out_of_range ret nz jp __lneg ;------------------------------------------------------------------------------- - section .text + .section .text.__strtol_common - private __strtol_common + .local .L__strtol_common -__strtol_common: +.L__strtol_common: ; output: E:UHL ; B = 1 if no overflow ; Z means that A is zero = negate return value @@ -136,92 +130,92 @@ __strtol_common: ld bc, (ix + 15) ; base add hl, bc - jr c, .invalid_base + jr c, .L.invalid_base ; UBC is zero here ld b, c ; store the base in B to allow for djnz hax ld hl, (ix + 9) ; nptr ;------------------------------------------------------------------------------- ; consume whitespace (inlinsed isspace) -.whitespace_loop: +.L.whitespace_loop: ld a, (hl) inc hl cp a, 32 - jr z, .whitespace_loop + jr z, .L.whitespace_loop sub a, 9 add a, -5 - jr nc, .whitespace_loop + jr nc, .L.whitespace_loop ; test for plus/minus signs ; A = (HL - 1) - 9 + -5 ; A = (HL - 1) - 14 xor a, '-' - 14 push af - jr z, .minus_sign - xor a, ('+' - 14) xor ('-' - 14) - jr z, .plus_sign + jr z, .L.minus_sign + xor a, ('+' - 14) ^ ('-' - 14) + jr z, .L.plus_sign dec hl xor a, a -.plus_sign: -.minus_sign: +.L.plus_sign: +.L.minus_sign: ; A = 0, (HL) = start of number ;------------------------------------------------------------------------------- ; update the base if needed or a, b ; base - jr z, .auto_base + jr z, .L.auto_base xor a, 16 - jr z, .hex_base - xor a, 2 xor 16 - jr nz, .other_base -.auto_base: ; test for 0* 0x* 0X* 0b* 0B* -.bin_base: ; test for 0x* 0X* -.hex_base: ; test for 0b* 0B* + jr z, .L.hex_base + xor a, 2 ^ 16 + jr nz, .L.other_base +.L.auto_base: ; test for 0* 0x* 0X* 0b* 0B* +.L.bin_base: ; test for 0x* 0X* +.L.hex_base: ; test for 0b* 0B* inc b ; djnz hax ld a, (hl) xor a, '0' - jr nz, .maybe_decimal + jr nz, .L.maybe_decimal inc hl ld a, (hl) res 5, a ; upper case xor a, 'X' - jr z, .maybe_hex - xor a, 'B' xor 'X' - jr z, .maybe_bin + jr z, .L.maybe_hex + xor a, 'B' ^ 'X' + jr z, .L.maybe_bin dec hl - djnz .other_base + djnz .L.other_base ld b, 8 ; octal - jr .save_new_base + jr .L.save_new_base -.maybe_bin: +.L.maybe_bin: bit 4, b - jr nz, .undo_inc ; hexadecimal + jr nz, .L.undo_inc ; hexadecimal ; base is 0 or 2 inc hl ld b, 2 - jr .save_new_base + jr .L.save_new_base -.maybe_hex: +.L.maybe_hex: bit 1, b - jr nz, .undo_inc ; binary + jr nz, .L.undo_inc ; binary ; base is 0 or 16 inc hl ld b, 16 - jr .save_new_base + jr .L.save_new_base -.undo_inc: +.L.undo_inc: dec hl ; dec b - ; jr .other_base -.maybe_decimal: + ; jr .L.other_base +.L.maybe_decimal: ; set to decimal if base is not zero - djnz .other_base + djnz .L.other_base ld b, 10 ; decimal -.save_new_base: +.L.save_new_base: ;------------------------------------------------------------------------------- -.other_base: +.L.other_base: ld a, (hl) ; first digit of the number push hl pop iy ld d, b -.invalid_base_hijack: +.L.invalid_base_hijack: ; or a, a ; carry is cleared here sbc hl, hl ld e, l @@ -238,28 +232,28 @@ __strtol_common: sub a, 48 cp a, 10 - jr c, .check_digit + jr c, .L.check_digit ; Convert an alphabetic digit, case-insensitive sub a, 65 - 48 res 5, a add a, 10 -.check_digit: +.L.check_digit: ; End the loop when the digit is out of range for the base cp a, d - jr c, .loop + jr c, .L.loop ;------------------------------------------------------------------------------- ; no digit found or invalid base ; set *endptr to nptr and return 0 ld iy, (ix + 9) ; nptr - jr .write_endptr -.invalid_base: + jr .L.write_endptr +.L.invalid_base: xor a, a ld d, a ; Setting D (base) to zero ensures that cp a, d will never set carry. ; forcing the function to return. push af ; sets E:UHL to zero - jr .invalid_base_hijack + jr .L.invalid_base_hijack ;------------------------------------------------------------------------------- ; common path : 30F + 1R + 3W + 5 + __lmulu_b ; decimal path : 6F + 0R + 0W + 1 @@ -272,10 +266,10 @@ __strtol_common: ; Total CC per digit: ; decimal digit : 79F + 13R + 12W + 21 ; other digit : 85F + 13R + 12W + 21 -.check_decimal: +.L.check_decimal: cp a, d - jr nc, .end_loop -.loop: + jr nc, .L.end_loop +.L.loop: ld c, a ; UBC = digit if no carry, don't care otherwise ld a, d ; A = base ld d, e ; D = upper accumulator byte @@ -298,38 +292,38 @@ __strtol_common: ld b, a ld d, c ; D = base ; IY = str, D = base, E:UHL = accumulator, BCU = 0, B = 0 if no carry -.next_digit: +.L.next_digit: inc iy ; Convert a numerical digit ld a, (iy) sub a, 48 cp a, 10 - jr c, .check_decimal + jr c, .L.check_decimal ; Convert an alphabetic digit, case-insensitive sub a, 65 - 48 res 5, a add a, 10 ; End the loop when the digit is out of range for the base cp a, d - jr c, .loop -.end_loop: + jr c, .L.loop +.L.end_loop: ;------------------------------------------------------------------------------- -.write_endptr: +.L.write_endptr: push hl ld hl, (ix + 12) ; endptr add hl, de or a, a sbc hl, de - jr z, .endptr_null + jr z, .L.endptr_null ld (hl), iy -.endptr_null: +.L.endptr_null: pop hl inc b ; djnz hax pop af pop ix ret - extern _errno - extern __ineg - extern __lneg - extern __lmulu_b + .extern _errno + .extern __ineg + .extern __lneg + .extern __lmulu_b diff --git a/src/libc/strtoll.src b/src/libc/strtoll.src index 3dc6ed6fd..6628062a2 100644 --- a/src/libc/strtoll.src +++ b/src/libc/strtoll.src @@ -1,36 +1,38 @@ - assume adl=1 + .assume adl=1 ;------------------------------------------------------------------------------- - section .text + .section .text - public _strtoll - public _strtoimax + .global _strtoll + .type _strtoll, @function + .global _strtoimax + .type _strtoimax, @function _strtoimax: _strtoll: call __strtoll_common ; overflow if Carry is set - jr c, .out_of_range + jr c, _strtoll.out_of_range ld a, b rla - jr c, .maybe_out_of_range + jr c, _strtoll.maybe_out_of_range ret nz jp __llneg -.maybe_out_of_range: +_strtoll.maybe_out_of_range: ; greater than INT_MAX - jr nz, .overflow + jr nz, _strtoll.overflow ; negative ; check that the result is not an exact INT_MIN ld b, a ; B = (B << 1) call __llcmpzero set 7, b ret z ; exact INT_MIN -.underflow: +_strtoll.underflow: xor a, a ; set Z -.out_of_range: -.overflow: +_strtoll.out_of_range: +_strtoll.overflow: ld b, $80 ld hl, 5 ; ERANGE ld c, h @@ -49,20 +51,22 @@ _strtoll: ;------------------------------------------------------------------------------- - section .text + .section .text - public _strtoull - public _strtoumax + .global _strtoull + .type _strtoull, @function + .global _strtoumax + .type _strtoumax, @function _strtoumax: _strtoull: call __strtoll_common ; overflow if Carry is set - jr c, .out_of_range + jr c, _strtoull.out_of_range ret nz jp __llneg -.out_of_range: +_strtoull.out_of_range: ld hl, 5 ; ERANGE ld (_errno), hl ld l, h ; ld hl, 0 @@ -76,9 +80,9 @@ _strtoull: ;------------------------------------------------------------------------------- - section .text + .section .text - private __strtoll_common + .local __strtoll_common __strtoll_common.invalid_base: xor a, a @@ -107,87 +111,87 @@ __strtoll_common: ld hl, (ix + 9) ; nptr ;------------------------------------------------------------------------------- ; consume whitespace (inlinsed isspace) -.whitespace_loop: +__strtoll_common.whitespace_loop: ld a, (hl) inc hl cp a, 32 - jr z, .whitespace_loop + jr z, __strtoll_common.whitespace_loop sub a, 9 add a, -5 - jr nc, .whitespace_loop + jr nc, __strtoll_common.whitespace_loop ; test for plus/minus signs ; A = (HL - 1) - 9 + -5 ; A = (HL - 1) - 14 xor a, '-' - 14 push af - jr z, .minus_sign - xor a, ('+' - 14) xor ('-' - 14) - jr z, .plus_sign + jr z, __strtoll_common.minus_sign + xor a, ('+' - 14) ^ ('-' - 14) + jr z, __strtoll_common.plus_sign dec hl xor a, a -.plus_sign: -.minus_sign: +__strtoll_common.plus_sign: +__strtoll_common.minus_sign: ; A = 0, (HL) = start of number ;------------------------------------------------------------------------------- ; update the base if needed or a, c ; base - jr z, .auto_base + jr z, __strtoll_common.auto_base xor a, 16 - jr z, .hex_base - xor a, 2 xor 16 - jr nz, .other_base -.auto_base: ; test for 0* 0x* 0X* 0b* 0B* -.bin_base: ; test for 0x* 0X* -.hex_base: ; test for 0b* 0B* + jr z, __strtoll_common.hex_base + xor a, 2 ^ 16 + jr nz, __strtoll_common.other_base +__strtoll_common.auto_base: ; test for 0* 0x* 0X* 0b* 0B* +__strtoll_common.bin_base: ; test for 0x* 0X* +__strtoll_common.hex_base: ; test for 0b* 0B* inc c ld a, (hl) xor a, '0' - jr nz, .maybe_decimal + jr nz, __strtoll_common.maybe_decimal inc hl ld a, (hl) res 5, a ; upper case xor a, 'X' - jr z, .maybe_hex - xor a, 'B' xor 'X' - jr z, .maybe_bin + jr z, __strtoll_common.maybe_hex + xor a, 'B' ^ 'X' + jr z, __strtoll_common.maybe_bin dec hl dec c - jr nz, .other_base + jr nz, __strtoll_common.other_base ld c, 8 ; octal - jr .save_new_base + jr __strtoll_common.save_new_base -.maybe_bin: +__strtoll_common.maybe_bin: bit 4, c - jr nz, .undo_inc ; hexadecimal + jr nz, __strtoll_common.undo_inc ; hexadecimal ; base is 0 or 2 inc hl ld c, 2 - jr .save_new_base + jr __strtoll_common.save_new_base -.maybe_hex: +__strtoll_common.maybe_hex: bit 1, c - jr nz, .undo_inc ; binary + jr nz, __strtoll_common.undo_inc ; binary ; base is 0 or 16 inc hl ld c, 16 - jr .save_new_base + jr __strtoll_common.save_new_base -.undo_inc: +__strtoll_common.undo_inc: dec hl ; dec c - ; jr .other_base -.maybe_decimal: + ; jr __strtoll_common.other_base +__strtoll_common.maybe_decimal: ; set to decimal if base is not zero dec c - jr nz, .other_base + jr nz, __strtoll_common.other_base ld c, 10 ; decimal -.save_new_base: +__strtoll_common.save_new_base: ;------------------------------------------------------------------------------- -.other_base: +__strtoll_common.other_base: ld a, (hl) ; first digit of the number push hl pop iy -.invalid_base_hijack: +__strtoll_common.invalid_base_hijack: ; or a, a ; carry is cleared here sbc hl, hl ; A = first digit of the number @@ -204,32 +208,32 @@ __strtoll_common: sub a, 48 cp a, 10 - jr c, .check_digit + jr c, __strtoll_common.check_digit ; Convert an alphabetic digit, case-insensitive sub a, 65 - 48 res 5, a add a, 10 -.check_digit: +__strtoll_common.check_digit: ; End the loop when the digit is out of range for the base cp a, c push hl ; (ix - 6) = $000000 push hl ; (ix - 9) = $000000 - jr c, .loop + jr c, __strtoll_common.loop ;------------------------------------------------------------------------------- ; no digit found or invalid base ; set *endptr to nptr and return 0 ld iy, (ix + 9) ; nptr - jr .write_endptr + jr __strtoll_common.write_endptr ;------------------------------------------------------------------------------- ; CC per non-decimal digit: ; no overflow : 109F + 10R + 9W + 33 ; overflow : 117F + 11R + 10W + 35 -.check_decimal: +__strtoll_common.check_decimal: cp a, c - jr nc, .end_loop -.loop: -.__llmul_add_b_overflow: + jr nc, __strtoll_common.end_loop +__strtoll_common.loop: +__strtoll_common.__llmul_add_b_overflow: ; value = (value * C) + A ; bit 0, (ix - 3) is set if overflow has occured ; (ix - 6) --> HL @@ -292,8 +296,8 @@ __strtoll_common: add.s hl, de sbc a, b ; set carry if B is non-zero or if there was carry previously - jr c, .set_overflow_bit -.next_digit: + jr c, __strtoll_common.set_overflow_bit +__strtoll_common.next_digit: ; (ix - 6) --> HL ; (ix - 9) --> DE ; HL --> BC @@ -305,26 +309,26 @@ __strtoll_common: ld a, (iy) sub a, 48 cp a, 10 - jr c, .check_decimal + jr c, __strtoll_common.check_decimal ; Convert an alphabetic digit, case-insensitive sub a, 65 - 48 res 5, a add a, 10 ; End the loop when the digit is out of range for the base cp a, c - jr c, .loop -.end_loop: + jr c, __strtoll_common.loop +__strtoll_common.end_loop: ;------------------------------------------------------------------------------- -.write_endptr: +__strtoll_common.write_endptr: ld c, l ld b, h ld hl, (ix + 12) ; endptr add hl, de or a, a sbc hl, de - jr z, .endptr_null + jr z, __strtoll_common.endptr_null ld (hl), iy -.endptr_null: +__strtoll_common.endptr_null: pop de pop hl pop af ; overflow and sign flags @@ -332,12 +336,12 @@ __strtoll_common: ret ;------------------------------------------------------------------------------- -.set_overflow_bit: +__strtoll_common.set_overflow_bit: set 0, (ix - 3) ; set carry - jr .next_digit + jr __strtoll_common.next_digit ;------------------------------------------------------------------------------- - extern _errno - extern __llneg - extern __llcmpzero + .extern _errno + .extern __llneg + .extern __llcmpzero diff --git a/src/libc/tanf.c b/src/libc/tanf.c index b505d9f22..8a7d6149f 100644 --- a/src/libc/tanf.c +++ b/src/libc/tanf.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _tanf\n" + "\t.type _tanf, @function\n" + "\t.equ _tanf, 0x022120\n" + "\t.global _tan\n" + "\t.type _tan, @function\n" + "\t.equ _tan, _tanf\n" +); + +#else + /************************************************************************/ /* */ /* Copyright (C)1987-2008 by */ @@ -39,7 +53,7 @@ * See the purple line for relative precision (lag warning): * https://www.desmos.com/calculator/c0zs4b8sqk */ -float _tanf_c(float arg) +float tanf(float arg) { float temp, e, x, xsq; bool flag, sign; @@ -95,4 +109,6 @@ float _tanf_c(float arg) return temp; } -double _tan_c(double) __attribute__((alias("_tanf_c"))); +double tan(double) __attribute__((alias("tanf"))); + +#endif diff --git a/src/libc/tanf.src b/src/libc/tanf.src deleted file mode 100644 index 2a24f80c8..000000000 --- a/src/libc/tanf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _tanf - public _tan - -if PREFER_OS_LIBC - -_tanf := 022120h -_tan := _tanf - -else - -_tanf := __tanf_c -_tan := __tan_c - - extern __tanf_c - extern __tan_c - -end if diff --git a/src/libc/tanhf.c b/src/libc/tanhf.c index e2bbfd3b7..3a5c31bec 100644 --- a/src/libc/tanhf.c +++ b/src/libc/tanhf.c @@ -1,3 +1,17 @@ +#if PERFER_CE_LIBC + +asm +( + "\t.global _tanhf\n" + "\t.type _tanhf, @function\n" + "\t.equ _tanhf, 0x022138\n" + "\t.global _tanh\n" + "\t.type _tanh, @function\n" + "\t.equ _tanh, _tanhf\n" +); + +#else + /************************************************************************/ /* */ /* Copyright (C)1987-2008 by */ @@ -22,7 +36,7 @@ * ulp of -5 at +0x1.f921b4p-6 with current sinhf coshf and ideal expf * ulp of -7 at +0x1.0c2064p-1 with current sinhf coshf and expf */ -float _tanhf_c(float arg) { +float tanhf(float arg) { float x = fabsf(arg); // result rounds to 1.0f @@ -35,4 +49,6 @@ float _tanhf_c(float arg) { return copysignf(x, arg); } -double _tanh_c(double) __attribute__((alias("_tanhf_c"))); +double tanh(double) __attribute__((alias("tanhf"))); + +#endif diff --git a/src/libc/tanhf.src b/src/libc/tanhf.src deleted file mode 100644 index 2fd2ffdb4..000000000 --- a/src/libc/tanhf.src +++ /dev/null @@ -1,20 +0,0 @@ - assume adl=1 - - section .text - public _tanhf - public _tanh - -if PREFER_OS_LIBC - -_tanhf := 022138h -_tanh := _tanhf - -else - -_tanhf := __tanhf_c -_tanh := __tanh_c - - extern __tanhf_c - extern __tanh_c - -end if diff --git a/src/libc/tolower.src b/src/libc/tolower.src index 823c07ec3..86d450d5b 100644 --- a/src/libc/tolower.src +++ b/src/libc/tolower.src @@ -1,16 +1,15 @@ - assume adl=1 + .assume adl=1 - section .text - public _tolower + .section .text + .global _tolower + .type _tolower, @function + .global _tolower.internal + .type _tolower.internal, @function _tolower: pop de ex (sp), hl push de - require _tolower.internal - - section .text - public _tolower.internal ; ASM interface: input/output char in L, destroys AF _tolower.internal: ld a, l diff --git a/src/libc/toupper.src b/src/libc/toupper.src index 0781ba7b0..88525e6bc 100644 --- a/src/libc/toupper.src +++ b/src/libc/toupper.src @@ -1,18 +1,17 @@ - assume adl=1 + .assume adl=1 - section .text - public _toupper + .section .text + .global _toupper + .type _toupper, @function + .global _toupper_internal + .type _toupper_internal, @function _toupper: pop de ex (sp), hl push de - require _toupper.internal - - section .text - public _toupper.internal ; ASM interface: input/output char in L, destroys AF -.internal: +_toupper_internal: ld a, l sub a, 'a' cp a, 1+'z'-'a' diff --git a/src/libc/truncf.src b/src/libc/truncf.src index 1b8c9c651..b4c84e786 100644 --- a/src/libc/truncf.src +++ b/src/libc/truncf.src @@ -1,8 +1,11 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _truncf, _trunc + .global _truncf + .type _truncf, @function + .global _trunc + .type _trunc, @function _trunc: _truncf: @@ -21,9 +24,9 @@ _truncf: rla sub a, 127 ; exponent bias - jr c, .ret_zero + jr c, .L.ret_zero sub a, 23 ; bits in the mantissa - jr nc, .ret_self + jr nc, .L.ret_self sbc hl, hl ; HL = 0xFFFFFF neg ld d, c ; store C @@ -32,13 +35,13 @@ _truncf: ld c, d ; restore C jp __iand -.ret_self: +.L.ret_self: ; already (large) integer, inf, or NaN sbc hl, hl add hl, bc ret -.ret_zero: +.L.ret_zero: ; return signed zero ld a, e and a, $80 @@ -46,5 +49,5 @@ _truncf: sbc hl, hl ret - extern __ishl - extern __iand + .extern __ishl + .extern __iand diff --git a/src/libc/truncl.src b/src/libc/truncl.src index 30d7ecb18..68274cc98 100644 --- a/src/libc/truncl.src +++ b/src/libc/truncl.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _truncl + .global _truncl + .type _truncl, @function _truncl: ld iy, 0 @@ -10,15 +11,15 @@ _truncl: ld hl, (iy + 9) ld a, h add.s hl, hl - ld de, -1023 shl 5 ; 0xFF8020 + ld de, 0xFF8020 ; -1023 shl 5 add.s hl, de - jr nc, .ret_zero -; ld de, -52 shl 5 ; 0xFFF980 + jr nc, .L.ret_zero +; ld de, 0xFFF980 ; -52 shl 5 ld e, d ld d, $F9 add hl, de - jr c, .ret_self + jr c, .L.ret_self add hl, hl add hl, hl add hl, hl @@ -32,19 +33,19 @@ _truncl: sbc hl, hl ; __i56shl -.loop: +.L.loop: add hl, hl ex de, hl adc hl, hl ex de, hl rla - djnz .loop + djnz .L.loop dec b ; b = $FF ld c, a ; values already on the stack jp __lland -.ret_zero: +.L.ret_zero: and a, $80 ld b, a sbc hl, hl @@ -53,11 +54,11 @@ _truncl: sbc hl, hl ret -.ret_self: +.L.ret_self: ; already (large) integer, inf, or NaN ld bc, (iy + 9) ld de, (iy + 6) ld hl, (iy + 3) ret - extern __lland + .extern __lland diff --git a/src/libc/vsprintf.src b/src/libc/vsprintf.src deleted file mode 100644 index c0d2bd3cb..000000000 --- a/src/libc/vsprintf.src +++ /dev/null @@ -1,19 +0,0 @@ - assume adl=1 - - section .text - - public _vsprintf - -if HAS_PRINTF - -_vsprintf := __vsprintf_c - - extern __vsprintf_c - -else - -_vsprintf := _boot_vsprintf - - extern _boot_vsprintf - -end if diff --git a/src/libc/wcslen.src b/src/libc/wcslen.src index ff2046133..ddfb3b20c 100644 --- a/src/libc/wcslen.src +++ b/src/libc/wcslen.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _wcslen + .global _wcslen + .type _wcslen, @function ; size_t wcslen(const wchar_t *str) _wcslen: @@ -12,12 +13,12 @@ _wcslen: ld bc, 1 xor a, a dec hl -.loop: +.L.loop: inc hl cpi - jr nz, .loop + jr nz, .L.loop cp a, (hl) - jr nz, .loop + jr nz, .L.loop sbc hl, hl sbc hl, bc ret diff --git a/src/libc/wcsnlen.src b/src/libc/wcsnlen.src index 6f434284b..55c44895c 100644 --- a/src/libc/wcsnlen.src +++ b/src/libc/wcsnlen.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _wcsnlen + .global _wcsnlen + .type _wcsnlen, @function ; size_t wcsnlen(const wchar_t *str, size_t maxlen) _wcsnlen: @@ -18,7 +19,7 @@ _wcsnlen: adc hl, bc ret z ex de, hl - call .loop_start + call .L.loop_start ex de, hl ; return maxlen unless str[maxlen - 1] == L'\0' ret nz ; low byte was non-zero @@ -27,16 +28,16 @@ _wcsnlen: ret nz ; high byte was non-zero dec hl ; ret ; We can use the RET PO below since overflow won't be set -.loop_lo: +.L.loop_lo: ret po -.loop_hi: +.L.loop_hi: inc hl -.loop_start: +.L.loop_start: cpi - jr nz, .loop_lo + jr nz, .L.loop_lo ret po cp a, (hl) - jr nz, .loop_hi + jr nz, .L.loop_hi ex de, hl pop de ; reset SP scf diff --git a/src/libc/wmemchr.src b/src/libc/wmemchr.src index cfd42dd62..63661cdef 100644 --- a/src/libc/wmemchr.src +++ b/src/libc/wmemchr.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _wmemchr + .global _wmemchr + .type _wmemchr, @function ; wchar_t *wmemchr(const wchar_t *ptr, int ch, size_t count) _wmemchr: @@ -15,25 +16,25 @@ _wmemchr: pop bc ; BC = count * 2 ld hl, (iy + 3) ld de, (iy + 6) ; E = lower byte, D = upper byte - call .loop_start -.ret_null: + call .L.loop_start +.L.ret_null: or a, a sbc hl, hl ret -.loop_start: -.no_match: +.L.loop_start: +.L.no_match: ld a, e -.loop: +.L.loop: cpir ret po ; return NULL ; repeat until BC is odd bit 0, c - jr z, .loop + jr z, .L.loop ; lower byte matches, now check the upper byte ld a, d xor a, (hl) - jr nz, .no_match + jr nz, .L.no_match pop bc ; reset SP dec hl ret diff --git a/src/libc/wmemcmp.src b/src/libc/wmemcmp.src index 36f2662c0..44a4af5d3 100644 --- a/src/libc/wmemcmp.src +++ b/src/libc/wmemcmp.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _wmemcmp + .global _wmemcmp + .type _wmemcmp, @function ; int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n) _wmemcmp: @@ -14,32 +15,32 @@ _wmemcmp: ret z ; return 0 ld de, (iy + 3) ld hl, (iy + 6) -.loop: +.L.loop: ld a, (de) xor a, (hl) inc hl inc de ld a, (de) - jr nz, .low_diff + jr nz, .L.low_diff cpi - jr nz, .high_diff + jr nz, .L.high_diff inc de - jp pe, .loop + jp pe, .L.loop sbc hl, hl ret -.high_diff: +.L.high_diff: dec hl -.low_diff: +.L.low_diff: ; compare high bytes sub a, (hl) ; s1 - s2 - jr nz, .skip_low_check + jr nz, .L.skip_low_check ; compare low bytes dec de ld a, (de) dec hl sub a, (hl) ; s1 - s2 -.skip_low_check: +.L.skip_low_check: sbc hl, hl ; A is non-zero here ld l, a diff --git a/src/libc/wmemcpy.src b/src/libc/wmemcpy.src index 16c180f8c..6a30208d0 100644 --- a/src/libc/wmemcpy.src +++ b/src/libc/wmemcpy.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _wmemcpy + .global _wmemcpy + .type _wmemcpy, @function ; CC: !count ? 19*r(PC) + 9*r(SPL) + 3*w(SPL) + 1 ; : 25*r(PC) + 18*r(SPL) + 12*w(SPL) + count*(r(src) + w(dest) + 1) @@ -16,7 +17,7 @@ _wmemcpy: ; = count2 ; C: if (count2) { pop iy ; iy = ret - jr z, .zero + jr z, .L.zero ; C: __ldir(src, dest, count2); pop de ; de = dest ex (sp), hl ; hl = src @@ -25,7 +26,7 @@ _wmemcpy: push de ldir ; C: } -.zero: +.L.zero: ; C: return dest; ex (sp), hl jp (iy) diff --git a/src/libc/wmemmove.src b/src/libc/wmemmove.src index efbf4775e..4b496055e 100644 --- a/src/libc/wmemmove.src +++ b/src/libc/wmemmove.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _wmemmove + .global _wmemmove + .type _wmemmove, @function ; wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t count) _wmemmove: @@ -13,4 +14,4 @@ _wmemmove: ld (hl), iy jp _memmove - extern _memmove + .extern _memmove diff --git a/src/libc/wmemset.src b/src/libc/wmemset.src index 92b34b3ce..19b31e786 100644 --- a/src/libc/wmemset.src +++ b/src/libc/wmemset.src @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _wmemset + .global _wmemset + .type _wmemset, @function ; wchar_t *wmemset(wchar_t *dst, wchar_t ch, size_t count) _wmemset: diff --git a/src/libcxx/makefile b/src/libcxx/makefile index 781d2e4ab..bb09fd6da 100644 --- a/src/libcxx/makefile +++ b/src/libcxx/makefile @@ -16,17 +16,22 @@ include $(CURDIR)/../common.mk -BUILD_SRC := $(patsubst %,build/%.src,$(wildcard *.c *.cpp)) +OBJECTS = +OBJECTS += $(patsubst %.c,build/%.c.o,$(wildcard *.c)) +OBJECTS += $(patsubst %.cpp,build/%.cpp.o,$(wildcard *.cpp)) +OBJECTS += $(patsubst %.src,build/%.o,$(wildcard *.src)) -EZCFLAGS := -S -fno-addrsig -ffreestanding -Wall -Wextra -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -EZCFLAGS += -D_EZ80 -isystem ../libc/include -isystem ../ce/include -isystem ../fileioc -mllvm -profile-guided-section-prefix=false -EZCXXFLAGS := $(EZCFLAGS) -fno-exceptions -fno-rtti -EZCXXFLAGS += -isystem ../libcxx/include - -WILDCARD_SRC = $(wildcard *.src) $(BUILD_SRC) WILDCARD_H := $(wildcard include/*) -all: $(BUILD_SRC) +CXX_LIB := build/libcxx.a + +.SECONDARY: + +all: $(CXX_LIB) + +$(CXX_LIB): $(OBJECTS) + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ build/%.c.src: %.c $(Q)$(call MKDIR,build) @@ -36,6 +41,18 @@ build/%.cpp.src: %.cpp $(Q)$(call MKDIR,build) $(Q)$(EZCC) $(EZCXXFLAGS) $< -o $@ +build/%.c.o: build/%.c.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.cpp.o: build/%.cpp.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.o: %.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + clean: $(Q)$(call RMDIR,build) @@ -43,7 +60,7 @@ install: all $(Q)$(call MKDIR,$(INSTALL_H)) $(Q)$(call MKDIR,$(INSTALL_CXX_H)) $(Q)$(call MKDIR,$(INSTALL_LIBCXX)) - $(Q)$(call COPY,$(call NATIVEPATH,$(WILDCARD_SRC)),$(INSTALL_LIBCXX)) + $(Q)$(call COPY,$(call NATIVEPATH,$(CXX_LIB)),$(INSTALL_LIBCXX)) $(Q)$(call COPY,$(foreach file,$(call NATIVEPATH,$(WILDCARD_H)),$(call QUOTE_ARG,$(file))),$(INSTALL_CXX_H)) -.PHONY: all clean +.PHONY: all clean install diff --git a/src/libload/libload.h b/src/libload/libload.h index 7aa2f6ad5..75844d3b1 100644 --- a/src/libload/libload.h +++ b/src/libload/libload.h @@ -13,10 +13,9 @@ * @returns \c false if the library is not loaded. * @note See the Makefile option `LIBLOAD_OPTIONAL` for more information. */ -#define libload_IsLibLoaded(name) __extension__({ \ - extern const unsigned char libload_Library_##name \ - __asm__("lib."#name); \ - libload_Library_##name; \ +#define libload_IsLibLoaded(name) __extension__({ \ + extern const unsigned char _libload_library_##name; \ + _libload_library_##name; \ }) #endif diff --git a/src/linker.mk b/src/linker.mk deleted file mode 100644 index 5e2585651..000000000 --- a/src/linker.mk +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (C) 2015-2025 CE Programming -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -include $(CURDIR)/common.mk - -FASMG_FILES = $(subst $(space),$(comma) ,$(patsubst %,"%",$(subst ",\",$(subst \,\\,$(call NATIVEPATH,$1)))))#" -APPEND_FILES = $(foreach file,$(addprefix ../lib/$2/,$(notdir $3)),$(call APPEND,$1$(call FASMG_FILES,$(file)))$(newline)) - -CRT_FILES := $(filter-out crt/crt0.src,$(wildcard crt/*.src) $(patsubst crt/%,crt/build/%.src,$(wildcard crt/*.c crt/*.cpp))) -LIBC_FILES := $(wildcard libc/*.src) $(patsubst libc/%,libc/build/%.src,$(wildcard libc/*.c libc/*.cpp)) -LIBCXX_FILES := $(wildcard libcxx/*.src) $(patsubst libcxx/%,libcxx/build/%.src,$(wildcard libcxx/*.c libcxx/*.cpp)) -SOFTFLOAT_FILES := $(wildcard softfloat/*.src) $(patsubst softfloat/%,softfloat/build/%.src,$(wildcard softfloat/*.c softfloat/*.cpp)) -CE_FILES := $(wildcard ce/*.src) - -linker_script: $(STATIC_FILES) $(LINKED_FILES) $(SHARED_FILES) - $(Q)$(call REMOVE,$(call QUOTE_ARG,$@)) - $(Q)$(call APPEND,if DEBUG) - $(Q)$(call APPEND, iterate sections$(comma) <.comment$(comma) .debug_abbrev$(comma) .debug_addr$(comma) .debug_aranges$(comma) \) - $(Q)$(call APPEND, .debug_frame$(comma) .debug_info$(comma) .debug_line$(comma) .debug_line_str$(comma) \) - $(Q)$(call APPEND, .debug_loc$(comma) .debug_loclists$(comma) .debug_macinfo$(comma) \) - $(Q)$(call APPEND, .debug_macro$(comma) .debug_names$(comma) .debug_pubnames$(comma) \) - $(Q)$(call APPEND, .debug_pubtypes$(comma) .debug_ranges$(comma) .debug_rnglists$(comma) \) - $(Q)$(call APPEND, .debug_str$(comma) .debug_str_offsets$(comma) .debug_sup$(comma) .debug_types$(comma) \) - $(Q)$(call APPEND, .debug_abbrev.dwo$(comma) .debug_info.dwo$(comma) .debug_line.dwo$(comma) \) - $(Q)$(call APPEND, .debug_loclists.dwo$(comma) .debug_macro.dwo$(comma) \) - $(Q)$(call APPEND, .debug_rnglists.dwo$(comma) .debug_str.dwo$(comma) \) - $(Q)$(call APPEND, .debug_str_offsets.dwo$(comma) .debug_cu_index$(comma) .debug_tu_index>) - $(Q)$(call APPEND, split debug: sections) - $(Q)$(call APPEND, precious sections) - $(Q)$(call APPEND, end iterate) - $(Q)$(call APPEND,end if) - $(Q)$(call APPEND) - $(Q)$(call APPEND,order .header$(comma) .icon$(comma) .init.libs$(comma) .libs$(comma) .init.clock$(comma) .init.reruncheck$(comma) .init$(comma) .fini$(comma) .text$(comma) .data$(comma) .rodata) - $(Q)$(call APPEND,split : .init_array$(comma) .ctors$(comma) .dtors$(comma) .fini_array) - $(Q)$(call APPEND,precious .header$(comma) .icon$(comma) .init.libs if .libs.length$(comma) .libs$(comma) .init_array$(comma) .ctors$(comma) .dtors$(comma) .fini_array) - $(Q)$(call APPEND,provide ___low_bss = .bss.base) - $(Q)$(call APPEND,provide ___len_bss = .bss.length) - $(Q)$(call APPEND,provide ___heaptop = .bss.high) - $(Q)$(call APPEND,provide ___heapbot = .bss.top) - $(Q)$(call APPEND,provide ___libs = .libs.base) - $(Q)$(call APPEND,provide ___init_array_count = .init_array.length / 3) - $(Q)$(call APPEND,provide ___ctors_count = .ctors.length / 3) - $(Q)$(call APPEND,provide ___dtors_count = .dtors.length / 3) - $(Q)$(call APPEND,provide ___fini_array_count = .fini_array.length / 3) - $(Q)$(call APPEND,require __start) - $(Q)$(call APPEND,library "../lib/libload/libload.lib" neveroptional) - $(Q)$(call APPEND,require lib.LibLoad if .libs.length) - $(Q)$(call APPEND) - $(Q)$(call APPEND_FILES,source ,crt,$(sort $(CRT_FILES))) - $(Q)$(call APPEND_FILES,source ,ce,$(sort $(CE_FILES))) - $(Q)$(call APPEND,if HAS_LIBC) - $(Q)$(call APPEND_FILES, source ,libc,$(sort $(LIBC_FILES))) - $(Q)$(call APPEND_FILES, source ,softfloat,$(sort $(SOFTFLOAT_FILES))) - $(Q)$(call APPEND,end if) - $(Q)$(call APPEND,if HAS_LIBCXX) - $(Q)$(call APPEND_FILES, source ,libcxx,$(sort $(LIBCXX_FILES))) - $(Q)$(call APPEND,end if) diff --git a/src/linker_script.ld b/src/linker_script.ld new file mode 100644 index 000000000..5cb37c168 --- /dev/null +++ b/src/linker_script.ld @@ -0,0 +1,93 @@ +PHDRS +{ + prgm PT_LOAD FLAGS(7); /* Read + Write + Execute - single loadable segment */ + bss PT_LOAD FLAGS(6); /* Read + Write - BSS/heap, not loaded from file */ +} + +SECTIONS +{ + . = LOAD_ADDR; + + .header : + { + KEEP (*(.header)) + KEEP (*(.header.icon)) + } :prgm + .init : + { + *(.init) + } :prgm + .text : + { + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text.exit .text.exit.*) + *(.text.startup .text.startup.*) + *(.text.hot .text.hot.*) + *(SORT(.text.sorted.*)) + *(.text .stub .text.* .gnu.linkonce.t.*) + *(.gnu.warning) + } :prgm + .rodata : + { + *(.rodata .rodata.* .gnu.linkonce.r.*) + } :prgm + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(.preinit_array)) + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + } :prgm + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*))) + KEEP (*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + } :prgm + .data : + { + *(.data .data.* .gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + *(.data1) + + /* For running programs */ + ___runprgm_reloc_start = .; + *(.runprgm.reloc) + ___runprgm_reloc_end = .; + } :prgm + + /* BSS section in the BSSHEAP range - separate PT_LOAD, not loaded from file */ + . = BSSHEAP_LOW; + ___bss_low = .; + .bss (NOLOAD) : SUBALIGN(1) + { + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + } :bss + ___bss_high = .; + ___bss_len = ___bss_high - ___bss_low; + + /* Heap follows BSS */ + . = ALIGN(1); + ___heap_low = .; + ASSERT(. <= BSSHEAP_HIGH, "Error: BSS exceed BSSHEAP_HIGH limit") + . = BSSHEAP_HIGH; + ___heap_high = .; + + /* For running programs */ + .runprgm 0xE30800 : AT(___runprgm_reloc_start) { + KEEP(*(.runprgm.reloc)) + } + + /DISCARD/ : + { + *(.comment) + *(.note*) + } +} + +PROVIDE(___runprgm_reloc_len = ___runprgm_reloc_end - ___runprgm_reloc_start); diff --git a/src/makefile.mk b/src/makefile.mk index 9ceda0c72..899e0ea4a 100644 --- a/src/makefile.mk +++ b/src/makefile.mk @@ -22,10 +22,10 @@ ICON ?= DESCRIPTION ?= COMPRESSED ?= NO ARCHIVED ?= YES -BSSHEAP_LOW ?= D052C6 -BSSHEAP_HIGH ?= D13FD8 -STACK_HIGH ?= D1A87E -INIT_LOC ?= D1A87F +BSSHEAP_LOW ?= 0xD052C6 +BSSHEAP_HIGH ?= 0xD13FD8 +STACK_HIGH ?= 0xD1A87E +LOAD_ADDR ?= 0xD1A87F OUTPUT_MAP ?= YES CFLAGS ?= -Wall -Wextra -Oz CXXFLAGS ?= -Wall -Wextra -Oz @@ -37,6 +37,7 @@ BINDIR ?= bin GFXDIR ?= src/gfx CPP_EXTENSION ?= cpp C_EXTENSION ?= c +ASM_EXTENSION ?= S CUSTOM_FILE_FILE ?= stdio_file.h DEPS ?= HAS_UPPERCASE_NAME ?= YES @@ -45,8 +46,8 @@ HAS_CUSTOM_FILE ?= NO HAS_LIBC ?= YES HAS_LIBCXX ?= YES ALLOCATOR ?= STANDARD -PREFER_OS_CRT ?= NO -PREFER_OS_LIBC ?= YES +PREFER_CE_CRT ?= NO +PREFER_CE_LIBC ?= YES SKIP_LIBRARY_LDFLAGS ?= NO LIBLOAD_OPTIONAL ?= COMPRESSED_MODE ?= zx7 @@ -64,62 +65,68 @@ empty := space := $(empty) $(empty) comma := , -# configure defaults -DEBUGMODE := NDEBUG -CCDEBUG := -g0 -LDDEBUG := 0 -LDPREFER_OS_CRT := 0 -LDPREFER_OS_LIBC := 0 -LDHAS_PRINTF := 0 -LDHAS_LIBC := 0 -LDHAS_LIBCXX := 0 - # verbosity V ?= 0 ifeq ($(V),0) Q = @ -FASMG_V := -n else Q = -FASMG_V := -v$(V) endif +# location of binaries BIN ?= $(CEDEV_TOOLCHAIN)/bin -# get the os specific items +BINUTILS_BIN ?= $(CEDEV_TOOLCHAIN)/binutils/bin + +# get the os specific operations ifeq ($(OS),Windows_NT) SHELL = cmd.exe NATIVEPATH = $(subst /,\,$1) -FASMG = $(call NATIVEPATH,$(BIN)/fasmg.exe) -CONVBIN = $(call NATIVEPATH,$(BIN)/convbin.exe) -CONVIMG = $(call NATIVEPATH,$(BIN)/convimg.exe) -CEMUTEST = $(call NATIVEPATH,$(BIN)/cemu-autotester.exe) -CC = $(call NATIVEPATH,$(BIN)/ez80-clang.exe) -LINK = $(call NATIVEPATH,$(BIN)/ez80-link.exe) +EXE_SUFFIX = .exe RM = ( del /q /f $1 2>nul || call ) RMDIR = ( rmdir /s /q $1 2>nul || call ) NATIVEMKDR = ( mkdir $1 2>nul || call ) QUOTE_ARG = "$(subst ",',$1)"#' else NATIVEPATH = $(subst \,/,$1) -FASMG = $(call NATIVEPATH,$(BIN)/fasmg) -CONVBIN = $(call NATIVEPATH,$(BIN)/convbin) -CONVIMG = $(call NATIVEPATH,$(BIN)/convimg) -CEMUTEST = $(call NATIVEPATH,$(BIN)/cemu-autotester) -CC = $(call NATIVEPATH,$(BIN)/ez80-clang) -LINK = $(call NATIVEPATH,$(BIN)/ez80-link) +EXE_SUFFIX = RM = rm -f $1 RMDIR = rm -rf $1 NATIVEMKDR = mkdir -p $1 QUOTE_ARG = '$(subst ','\'',$1)'#' endif -MKDIR = $(call NATIVEMKDR,$(call QUOTE_ARG,$(call NATIVEPATH,$1))) +# toolchain binaries +CONVBIN = $(call NATIVEPATH,$(BIN)/convbin$(EXE_SUFFIX)) +CONVIMG = $(call NATIVEPATH,$(BIN)/convimg$(EXE_SUFFIX)) +CEMUTEST = $(call NATIVEPATH,$(BIN)/cemu-autotester$(EXE_SUFFIX)) +CC = $(call NATIVEPATH,$(BIN)/ez80-clang$(EXE_SUFFIX)) +LINK = $(call NATIVEPATH,$(BIN)/ez80-link$(EXE_SUFFIX)) +AS = $(call NATIVEPATH,$(BINUTILS_BIN)/z80-none-elf-as$(EXE_SUFFIX)) +LD = $(call NATIVEPATH,$(BINUTILS_BIN)/z80-none-elf-ld$(EXE_SUFFIX)) +OBJCOPY = $(call NATIVEPATH,$(BINUTILS_BIN)/z80-none-elf-objcopy$(EXE_SUFFIX)) +STRIP = $(call NATIVEPATH,$(BINUTILS_BIN)/z80-none-elf-strip$(EXE_SUFFIX)) +CEDEV_OBJ = $(call NATIVEPATH,$(BIN)/cedev-obj$(EXE_SUFFIX)) + +# filepath operations +QUOTE_NATIVE = $(call QUOTE_ARG,$(call NATIVEPATH,$1)) +MKDIR = $(call NATIVEMKDR,$(call QUOTE_NATIVE,$1)) UPDIR_ADD = $(subst ../,_../,$(subst \,/,$1)) UPDIR_RM = $(subst _../,../,$(subst \,/,$1)) -FASMG_LIB = $(patsubst %,"%",$(subst ",\",$(subst \,\\,$(call NATIVEPATH,$1)))) -FASMG_FILES = $(subst $(space),$(comma) ,$(patsubst %,"%",$(subst ",\",$(subst \,\\,$(call NATIVEPATH,$1)))))#" -LINKER_SCRIPT ?= $(CEDEV_TOOLCHAIN)/meta/linker_script +# configure debug defaults +CC_DEBUG = -DNDEBUG=1 +LD_DEBUG = --defsym NDEBUG=1 + +# linker script +LINKER_SCRIPT ?= $(CEDEV_TOOLCHAIN)/meta/linker_script.ld + +# allocator (malloc/realloc/free) +ifeq ($(ALLOCATOR),STANDARD) +LIB_ALLOCATOR = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/libc/allocator_standard.a) +endif +ifeq ($(ALLOCATOR),SIMPLE) +LIB_ALLOCATOR = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/libc/allocator_simple.a) +endif # ensure native paths SRCDIR := $(call NATIVEPATH,$(SRCDIR)) @@ -129,14 +136,19 @@ GFXDIR := $(call NATIVEPATH,$(GFXDIR)) # generate default names TARGETBIN ?= $(NAME).bin +TARGETOBJ ?= $(NAME).obj +TARGETTMP ?= $(NAME).o TARGETMAP ?= $(NAME).map TARGET8XP ?= $(NAME).8xp -ICONIMG := $(wildcard $(call NATIVEPATH,$(ICON))) +ICON_IMG := $(wildcard $(call NATIVEPATH,$(ICON))) # startup routines -LDCRT0 = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/crt/crt0.src) -LDBCLTO = $(OBJDIR)/lto.bc -LDLTO = $(OBJDIR)/lto.src +CRT0_SRC = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/crt/crt0.S) +CRT0_TMP = $(OBJDIR)/crt0.s +CRT0_OBJ = $(OBJDIR)/crt0.o +LTO_BC = $(OBJDIR)/lto.bc +LTO_SRC = $(OBJDIR)/lto.s +LTO_OBJ = $(OBJDIR)/lto.o # source: http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html rwildcard = $(strip $(foreach d,$(wildcard $1/*),$(call rwildcard,$d,$2) $(filter $(subst %%,%,%$(subst *,%,$2)),$d))) @@ -150,54 +162,50 @@ EXTRA_ASM_SOURCES += $(EXTRA_ASMSOURCES) # find source files CSOURCES = $(sort $(call rwildcard,$(SRCDIR),*.$(C_EXTENSION)) $(EXTRA_C_SOURCES)) CPPSOURCES = $(sort $(call rwildcard,$(SRCDIR),*.$(CPP_EXTENSION)) $(EXTRA_CXX_SOURCES)) -ASMSOURCES = $(sort $(call rwildcard,$(SRCDIR),*.asm) $(EXTRA_ASM_SOURCES)) +ASMSOURCES = $(sort $(call rwildcard,$(SRCDIR),*.s) $(EXTRA_ASM_SOURCES)) +PREASMSOURCES = $(sort $(call rwildcard,$(SRCDIR),*.S) $(EXTRA_PREASM_SOURCES)) +# link time optimization ifneq ($(filter debug,$(MAKECMDGOALS)),) LTO := NO endif ifeq ($(LTO),YES) LINK_CSOURCES = $(call UPDIR_ADD,$(CSOURCES:%.$(C_EXTENSION)=$(OBJDIR)/%.$(C_EXTENSION).bc)) LINK_CPPSOURCES = $(call UPDIR_ADD,$(CPPSOURCES:%.$(CPP_EXTENSION)=$(OBJDIR)/%.$(CPP_EXTENSION).bc)) -LINK_ASMSOURCES = $(ASMSOURCES) -LTOFILES = $(LINK_CSOURCES) $(LINK_CPPSOURCES) -LDFILES = $(LDCRT0) $(LDLTO) $(LINK_ASMSOURCES) +LINK_ASMSOURCES = $(call UPDIR_ADD,$(ASMSOURCES:%.s=$(OBJDIR)/%.s.o)) +LINK_PREASMSOURCES = $(call UPDIR_ADD,$(PREASMSOURCES:%.S=$(OBJDIR)/%.S.o)) +LTO_FILES = $(LINK_CSOURCES) $(LINK_CPPSOURCES) +OBJECTS = $(LTO_OBJ) $(LINK_ASMSOURCES) $(LINK_PREASMSOURCES) DEPFILES = $(wildcard $(LINK_CSOURCES:%.bc=%.d) $(LINK_CPPSOURCES:%.bc=%.d)) else -LINK_CSOURCES = $(call UPDIR_ADD,$(CSOURCES:%.$(C_EXTENSION)=$(OBJDIR)/%.$(C_EXTENSION).src)) -LINK_CPPSOURCES = $(call UPDIR_ADD,$(CPPSOURCES:%.$(CPP_EXTENSION)=$(OBJDIR)/%.$(CPP_EXTENSION).src)) -LINK_ASMSOURCES = $(ASMSOURCES) -LDFILES = $(LDCRT0) $(LINK_CSOURCES) $(LINK_CPPSOURCES) $(LINK_ASMSOURCES) -DEPFILES = $(wildcard $(LINK_CSOURCES:%.src=%.d) $(LINK_CPPSOURCES:%.src=%.d)) +LINK_CSOURCES = $(call UPDIR_ADD,$(CSOURCES:%.$(C_EXTENSION)=$(OBJDIR)/%.$(C_EXTENSION).o)) +LINK_CPPSOURCES = $(call UPDIR_ADD,$(CPPSOURCES:%.$(CPP_EXTENSION)=$(OBJDIR)/%.$(CPP_EXTENSION).o)) +LINK_ASMSOURCES = $(call UPDIR_ADD,$(ASMSOURCES:%.s=$(OBJDIR)/%.s.o)) +LINK_PREASMSOURCES = $(call UPDIR_ADD,$(PREASMSOURCES:%.S=$(OBJDIR)/%.S.o)) +OBJECTS = $(LINK_CSOURCES) $(LINK_CPPSOURCES) $(LINK_ASMSOURCES) $(LINK_PREASMSOURCES) +DEPFILES = $(wildcard $(LINK_CSOURCES:%.o=%.d) $(LINK_CPPSOURCES:%.o=%.d)) endif ifneq ($(SKIP_LIBRARY_LDFLAGS),YES) # find all required/optional libload libraries LIBLOAD_LIBS ?= $(wildcard $(CEDEV_TOOLCHAIN)/lib/libload/*.lib) $(EXTRA_LIBLOAD_LIBS) LIBLOAD_LIBS := $(filter-out %libload.lib,$(LIBLOAD_LIBS)) -REQ_LIBLOAD := $(filter-out $(addprefix %,$(addsuffix .lib,$(LIBLOAD_OPTIONAL))),$(LIBLOAD_LIBS)) -OPT_LIBLOAD := $(filter $(addprefix %,$(addsuffix .lib,$(LIBLOAD_OPTIONAL))),$(LIBLOAD_LIBS)) -REQ_LIBLOAD := $(call FASMG_LIB,$(REQ_LIBLOAD)) -OPT_LIBLOAD := $(call FASMG_LIB,$(OPT_LIBLOAD)) -OPT_LIBLOAD := $(foreach lib,$(OPT_LIBLOAD),$(lib)$(space)optional) -LDLIBS := $(subst $(space),$(comma)$(space),$(strip $(REQ_LIBLOAD)$(space)$(OPT_LIBLOAD))) -LDLIBS := $(subst $(comma)$(space)optional,$(space)optional,$(LDLIBS)) -LDLIBRARYFLAGS := -i $(call QUOTE_ARG,library $(LDLIBS)) endif # check if there is an icon present that to convert -ifneq ($(ICONIMG),) -ICONSRC ?= $(call NATIVEPATH,$(OBJDIR)/icon.src) +ifneq ($(ICON_IMG),) +ICON_SRC = $(call NATIVEPATH,$(OBJDIR)/icon.s) ifneq ($(DESCRIPTION),) -ICON_CONV ?= $(CONVIMG) --icon $(call QUOTE_ARG,$(ICONIMG)) --icon-output $(call QUOTE_ARG,$(ICONSRC)) --icon-format asm --icon-description $(DESCRIPTION) +ICON_CONV ?= $(CONVIMG) --icon $(call QUOTE_NATIVE,$(ICON_IMG)) --icon-output $(call QUOTE_NATIVE,$(ICON_SRC)) --icon-format gas --icon-description $(DESCRIPTION) else -ICON_CONV ?= $(CONVIMG) --icon $(call QUOTE_ARG,$(ICONIMG)) --icon-output $(call QUOTE_ARG,$(ICONSRC)) --icon-format asm +ICON_CONV ?= $(CONVIMG) --icon $(call QUOTE_NATIVE,$(ICON_IMG)) --icon-output $(call QUOTE_NATIVE,$(ICON_SRC)) --icon-format gas endif -LDICON ?= $(call FASMG_FILES,$(ICONSRC))$(comma)$(space) +ICON_OBJ = $(call NATIVEPATH,$(OBJDIR)/icon.obj) else ifneq ($(DESCRIPTION),) -ICONSRC ?= $(call NATIVEPATH,$(OBJDIR)/icon.src) -ICON_CONV ?= $(CONVIMG) --icon-output $(call QUOTE_ARG,$(ICONSRC)) --icon-format asm --icon-description $(DESCRIPTION) -LDICON ?= $(call FASMG_FILES,$(ICONSRC))$(comma)$(space) +ICON_SRC ?= $(call NATIVEPATH,$(OBJDIR)/icon.s) +ICON_CONV ?= $(CONVIMG) --icon-output $(call QUOTE_NATIVE,$(ICON_SRC)) --icon-format gas --icon-description $(DESCRIPTION) +ICON_OBJ = $(call NATIVEPATH,$(OBJDIR)/icon.obj) endif endif @@ -226,84 +234,128 @@ CONVBINFLAGS += -n $(NAME) # output debug map file ifeq ($(OUTPUT_MAP),YES) -LDMAPFLAG := -i map +LD_MAP = -Map=$(BINDIR)/$(TARGETMAP) +else +LD_MAP = endif ifeq ($(HAS_CUSTOM_FILE),YES) DEFCUSTOMFILE := -DHAS_CUSTOM_FILE=1 -DCUSTOM_FILE_FILE=\"$(CUSTOM_FILE_FILE)\" endif -# convert to linker crt/libc define +# old style selection ifeq ($(PREFER_OS_CRT),YES) -LDPREFER_OS_CRT := 1 +$(info [warn] PREFER_OS_CRT is deprecated, use PREFER_CE_CRT instead) +PREFER_CE_CRT = $(PREFER_OS_CRT) endif -ifeq ($(PREFER_OS_LIBC),YES) -LDPREFER_OS_LIBC := 1 +ifeq ($(PREFER_OS_LIBC),NO) +$(info [warn] PREFER_OS_LIBC is deprecated, use PREFER_CE_LIBC instead) +PREFER_CE_LIBC = $(PREFER_OS_LIBC) endif + +# choose crt +ifeq ($(PREFER_CE_CRT),YES) +LIB_CRT = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/crt/libcrt_ce.a) +else +LIB_CRT = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/crt/libcrt.a) +endif + +# choose libc ifeq ($(HAS_LIBC),YES) -LDHAS_LIBC := 1 +ifeq ($(PREFER_CE_LIBC),YES) +LIB_C = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/libc/libc_ce.a) +else +LIB_C = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/libc/libc.a) +endif +else +LIB_C = endif + +# choose libcxx ifeq ($(HAS_LIBCXX),YES) -LDHAS_LIBCXX := 1 +LIB_CXX = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/libcxx/libcxx.a) +else +LIB_CXX = endif + +# add other libs +LIB_CE = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/ce/libce.a) +LIB_SOFTFLOAT = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/softfloat/libsoftfloat.a) + +# include printf ifeq ($(HAS_PRINTF),YES) -LDHAS_PRINTF := 1 +LIB_PRINTF = $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/lib/libc/libnanoprintf.a) +else +LIB_PRINTF = +endif + +# enable/disable errno checks +ifeq ($(HAS_MATH_ERRNO),YES) +MATH_ERRNO = +else +MATH_ERRNO = -fno-math-errno endif # define the c/c++ flags used by clang -EZLLVMFLAGS = -mllvm -profile-guided-section-prefix=false -fno-addrsig -EZCOMMONFLAGS = -nostdinc -isystem $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/include) -I$(SRCDIR) -fno-threadsafe-statics -Xclang -fforce-mangle-main-argc-argv $(EZLLVMFLAGS) -D__TICE__ -D$(DEBUGMODE) $(DEFCUSTOMFILE) $(CCDEBUG) +EZLLVMFLAGS = -mllvm -profile-guided-section-prefix=false -mllvm -z80-gas-style -mllvm -z80-print-zero-offset -ffunction-sections -fdata-sections -fno-addrsig -fno-autolink -fno-threadsafe-statics $(MATH_ERRNO) +EZCOMMONFLAGS = -nostdinc -isystem $(call QUOTE_NATIVE,$(CEDEV_TOOLCHAIN)/include) -I$(SRCDIR) -Xclang -fforce-mangle-main-argc-argv $(EZLLVMFLAGS) -D__TICE__=1 $(CC_DEBUG) $(DEFCUSTOMFILE) EZCFLAGS = $(EZCOMMONFLAGS) $(CFLAGS) -EZCXXFLAGS = $(EZCOMMONFLAGS) -isystem $(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/include/c++) -fno-exceptions -fno-use-cxa-atexit $(CXXFLAGS) +EZCXXFLAGS = $(EZCOMMONFLAGS) -isystem $(call QUOTE_NATIVE,$(CEDEV_TOOLCHAIN)/include/c++) -fno-exceptions -fno-use-cxa-atexit $(CXXFLAGS) EZLTOFLAGS = $(EZLLVMFLAGS) $(LTOFLAGS) -# these are the fasmg linker flags -FASMGFLAGS = \ - $(FASMG_V) \ - $(call QUOTE_ARG,$(call NATIVEPATH,$(CEDEV_TOOLCHAIN)/meta/ld.alm)) \ - -i $(call QUOTE_ARG,DEBUG := $(LDDEBUG)) \ - -i $(call QUOTE_ARG,HAS_PRINTF := $(LDHAS_PRINTF)) \ - -i $(call QUOTE_ARG,HAS_LIBC := $(LDHAS_LIBC)) \ - -i $(call QUOTE_ARG,HAS_LIBCXX := $(LDHAS_LIBCXX)) \ - -i $(call QUOTE_ARG,PREFER_OS_CRT := $(LDPREFER_OS_CRT)) \ - -i $(call QUOTE_ARG,PREFER_OS_LIBC := $(LDPREFER_OS_LIBC)) \ - -i $(call QUOTE_ARG,ALLOCATOR_$(ALLOCATOR) := 1) \ - -i $(call QUOTE_ARG,__TICE__ := 1) \ - -i $(call QUOTE_ARG,include $(call FASMG_FILES,$(LINKER_SCRIPT))) \ - -i $(call QUOTE_ARG,range .bss $$$(BSSHEAP_LOW) : $$$(BSSHEAP_HIGH)) \ - -i $(call QUOTE_ARG,provide __stack = $$$(STACK_HIGH)) \ - -i $(call QUOTE_ARG,locate .header at $$$(INIT_LOC)) \ - $(LDMAPFLAG) \ - -i $(call QUOTE_ARG,source $(LDICON)$(call FASMG_FILES,$(LDFILES))) \ - $(LDLIBRARYFLAGS) \ - $(EXTRA_LDFLAGS) - .PHONY: all clean version gfx debug # this rule is trigged to build everything all: $(BINDIR)/$(TARGET8XP) # this rule is trigged to build debug everything -debug: DEBUGMODE = DEBUG -debug: LDDEBUG = 1 -# Due to an issue with ez80-clang 15.0.7, this is disabled for now. Previously: -gdwarf-5 -g3 -# Then again, no tool using the produced .dbg files currently exists (CEmu's source-level-debugging was never finished) -debug: CCDEBUG = -g0 +debug: CC_DEBUG = -DDEBUG=1 +debug: LD_DEBUG = --defsym DEBUG=1 debug: $(BINDIR)/$(TARGET8XP) $(BINDIR)/$(TARGET8XP): $(BINDIR)/$(TARGETBIN) $(MAKEFILE_LIST) $(DEPS) $(Q)$(call MKDIR,$(@D)) - $(Q)$(CONVBIN) $(CONVBINFLAGS) -i $(call QUOTE_ARG,$(call NATIVEPATH,$<)) -o $(call QUOTE_ARG,$(call NATIVEPATH,$@)) + $(Q)$(CONVBIN) $(CONVBINFLAGS) -i $(call QUOTE_NATIVE,$<) -o $(call QUOTE_NATIVE,$@) -$(BINDIR)/$(TARGETBIN): $(LDFILES) $(ICONSRC) $(MAKEFILE_LIST) $(DEPS) +$(BINDIR)/$(TARGETBIN): $(BINDIR)/$(TARGETOBJ) $(Q)$(call MKDIR,$(@D)) - $(Q)echo [linking] $(call NATIVEPATH,$@) - $(Q)$(FASMG) $(FASMGFLAGS) $(call NATIVEPATH,$@) + $(Q)echo [objcopy] $(call NATIVEPATH,$@) + $(Q)$(OBJCOPY) -O binary $(call QUOTE_ARG,$<) $(call QUOTE_ARG,$@) -ifneq ($(ICONSRC),) -$(ICONSRC): $(ICONIMG) $(MAKEFILE_LIST) $(DEPS) +$(BINDIR)/$(TARGETOBJ): $(CRT0_OBJ) $(OBJDIR)/$(TARGETTMP) $(MAKEFILE_LIST) $(DEPS) + $(Q)$(call MKDIR,$(@D)) + $(Q)echo [linking] $(call NATIVEPATH,$@) + $(Q)$(LD) \ + -static \ + --entry=__start \ + --no-warn-rwx-segments \ + --gc-sections \ + --omagic \ + --defsym=LOAD_ADDR=$(LOAD_ADDR) \ + --defsym=BSSHEAP_LOW=$(BSSHEAP_LOW) \ + --defsym=BSSHEAP_HIGH=$(BSSHEAP_HIGH) \ + --defsym=STACK_HIGH=$(STACK_HIGH) \ + --defsym __TICE__=1 \ + -T$(LINKER_SCRIPT) \ + $(LD_MAP) \ + $(EXTRA_LDFLAGS) \ + $(OBJDIR)/$(TARGETTMP) \ + $(CRT0_OBJ) \ + $(LIB_ALLOCATOR) \ + --start-group \ + $(LIB_SOFTFLOAT) \ + $(LIB_CRT) \ + --end-group \ + $(LIB_C) \ + $(LIB_CXX) \ + $(LIB_CE) \ + -o $(call QUOTE_ARG,$@) + +ifneq ($(ICON_SRC),) +$(ICON_OBJ): $(ICON_IMG) $(MAKEFILE_LIST) $(DEPS) $(Q)$(call MKDIR,$(@D)) - $(Q)echo [convimg] $(or $(ICONIMG),description) + $(Q)echo [convimg] $(or $(ICON_IMG),description) $(Q)$(ICON_CONV) + $(Q)$(AS) -march=ez80+full $(call QUOTE_ARG,$(ICON_SRC)) -o $(call QUOTE_ARG,$@) endif clean: @@ -315,42 +367,106 @@ gfx: $(Q)$(MAKE_GFX) test: - $(Q)$(CEMUTEST) $(call NATIVEPATH,$(CURDIR)/autotest.json) + $(Q)$(CEMUTEST) $(call QUOTE_NATIVE,$(CURDIR)/autotest.json) version: $(Q)echo CE C/C++ Toolchain $(shell cedev-config --version) .SECONDEXPANSION: +.SECONDARY: # no lto -$(OBJDIR)/%.$(C_EXTENSION).src: $$(call UPDIR_RM,$$*).$(C_EXTENSION) $(EXTRA_HEADERS) $(MAKEFILE_LIST) $(DEPS) +$(OBJDIR)/%.$(C_EXTENSION).s: $$(call UPDIR_RM,$$*).$(C_EXTENSION) $(EXTRA_HEADERS) $(MAKEFILE_LIST) $(DEPS) $(Q)$(call MKDIR,$(@D)) - $(Q)echo [compiling] $(call NATIVEPATH,$<) + $(Q)echo [cc] $< $(Q)$(CC) -S -MD $(EZCFLAGS) $(call QUOTE_ARG,$<) -o $(call QUOTE_ARG,$@) -$(OBJDIR)/%.$(CPP_EXTENSION).src: $$(call UPDIR_RM,$$*).$(CPP_EXTENSION) $(EXTRA_HEADERS) $(MAKEFILE_LIST) $(DEPS) +$(OBJDIR)/%.$(CPP_EXTENSION).s: $$(call UPDIR_RM,$$*).$(CPP_EXTENSION) $(EXTRA_HEADERS) $(MAKEFILE_LIST) $(DEPS) $(Q)$(call MKDIR,$(@D)) - $(Q)echo [compiling] $(call NATIVEPATH,$<) + $(Q)echo [cc] $< $(Q)$(CC) -S -MD $(EZCXXFLAGS) $(call QUOTE_ARG,$<) -o $(call QUOTE_ARG,$@) +$(OBJDIR)/%.$(C_EXTENSION).o: $(OBJDIR)/%.$(C_EXTENSION).s + $(Q)$(call MKDIR,$(@D)) + $(Q)$(AS) -march=ez80+full $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$<)) -o $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$@)) + +$(OBJDIR)/%.$(CPP_EXTENSION).o: $(OBJDIR)/%.$(CPP_EXTENSION).s + $(Q)$(call MKDIR,$(@D)) + $(Q)$(AS) -march=ez80+full $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$<)) -o $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$@)) + +$(OBJDIR)/%.s.o: $$(call UPDIR_RM,$$*).s + $(Q)$(call MKDIR,$(@D)) + $(Q)echo [as] $< + $(Q)$(AS) -march=ez80+full $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$<)) -o $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$@)) + +$(OBJDIR)/%.s: $$(call UPDIR_RM,$$*).S + $(Q)$(call MKDIR,$(@D)) + $(Q)echo [as] $< + $(Q)$(CC) -MD $(EZCFLAGS) -E $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$<)) -o $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$@)) + +$(OBJDIR)/%.S.o: $(OBJDIR)/%.s + $(Q)$(call MKDIR,$(@D)) + $(Q)$(AS) -march=ez80+full $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$<)) -o $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$@)) + # lto -$(LDLTO): $(LDBCLTO) +$(LTO_OBJ): $(LTO_SRC) + $(Q)$(AS) -march=ez80+full $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$<)) -o $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$@)) + +$(LTO_SRC): $(LTO_BC) $(Q)$(CC) -S $(EZLTOFLAGS) $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$<)) -o $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$@)) -$(LDBCLTO): $(LTOFILES) - $(Q)echo [lto opt] $(call NATIVEPATH,$@) +$(LTO_BC): $(LTO_FILES) + $(Q)echo [lto] $(call NATIVEPATH,$@) $(Q)$(LINK) $(foreach d,$^,$(call QUOTE_ARG,$(addprefix $(CURDIR)/,$d))) -o $(call QUOTE_ARG,$(addprefix $(CURDIR)/,$@)) $(OBJDIR)/%.$(C_EXTENSION).bc: $$(call UPDIR_RM,$$*).$(C_EXTENSION) $(EXTRA_HEADERS) $(MAKEFILE_LIST) $(DEPS) $(Q)$(call MKDIR,$(@D)) - $(Q)echo [compiling] $(call NATIVEPATH,$<) + $(Q)echo [cc] $< $(Q)$(CC) -MD -c -emit-llvm $(EZCFLAGS) $(call QUOTE_ARG,$<) -o $(call QUOTE_ARG,$@) $(OBJDIR)/%.$(CPP_EXTENSION).bc: $$(call UPDIR_RM,$$*).$(CPP_EXTENSION) $(EXTRA_HEADERS) $(MAKEFILE_LIST) $(DEPS) $(Q)$(call MKDIR,$(@D)) - $(Q)echo [compiling] $(call NATIVEPATH,$<) + $(Q)echo [cc] $< $(Q)$(CC) -MD -c -emit-llvm $(EZCXXFLAGS) $(call QUOTE_ARG,$<) -o $(call QUOTE_ARG,$@) +# crt +$(OBJDIR)/$(TARGETTMP): $(OBJECTS) $(LIB_ALLOCATOR) $(LIB_PRINTF) $(LIB_CXX) $(LIB_CE) $(LIB_SOFTFLOAT) $(LIB_CRT) $(LIB_C) $(ICON_OBJ) $(EXTRA_LIBS) $(MAKEFILE_LIST) $(DEPS) + $(Q)$(call MKDIR,$(@D)) + $(Q)$(LD) \ + -i \ + -static \ + --entry=__start \ + --build-id=none \ + --gc-sections \ + --omagic \ + --defsym __TICE__=1 \ + $(LD_DEBUG) \ + $(EXTRA_PRE_LDFLAGS) \ + $(OBJECTS) \ + $(ICON_OBJ) \ + $(LIB_ALLOCATOR) \ + $(LIB_PRINTF) \ + $(LIB_CXX) \ + $(LIB_CE) \ + $(LIB_CRT) \ + $(LIB_C) \ + $(LIB_SOFTFLOAT) \ + $(EXTRA_LIBS) \ + -o $(call QUOTE_ARG,$@) + $(Q)$(STRIP) --strip-unneeded $(call QUOTE_ARG,$@) + +$(OBJDIR)/crt.h: $(OBJDIR)/$(TARGETTMP) + $(Q)$(call MKDIR,$(@D)) + $(Q)$(CEDEV_OBJ) --elf $(call QUOTE_ARG,$<) --output $(call QUOTE_ARG,$@) --libs $(LIBLOAD_LIBS) --optional-libs $(LIBLOAD_OPTIONAL) + +$(CRT0_OBJ): $(CRT0_TMP) + $(Q)$(call MKDIR,$(@D)) + $(Q)$(AS) -I$(OBJDIR) -march=ez80+full $(call QUOTE_ARG,$<) -o $(call QUOTE_ARG,$@) + +$(CRT0_TMP): $(CRT0_SRC) $(OBJDIR)/crt.h + $(Q)$(call MKDIR,$(@D)) + $(Q)$(CC) -I$(OBJDIR) -E -P $(call QUOTE_ARG,$<) -o $(call QUOTE_ARG,$@) + ifeq ($(filter clean gfx test version,$(MAKECMDGOALS)),) -include $(DEPFILES) endif diff --git a/src/softfloat/isNaNF32UI.src b/src/softfloat/isNaNF32UI.src deleted file mode 100644 index cf559b653..000000000 --- a/src/softfloat/isNaNF32UI.src +++ /dev/null @@ -1,8 +0,0 @@ - assume adl = 1 - - section .text - - public _isNaNF32UI -_isNaNF32UI := __isnanf - - extern __isnanf diff --git a/src/softfloat/isNaNF64UI.src b/src/softfloat/isNaNF64UI.src deleted file mode 100644 index 008d9b18d..000000000 --- a/src/softfloat/isNaNF64UI.src +++ /dev/null @@ -1,8 +0,0 @@ - assume adl = 1 - - section .text - - public _isNaNF64UI -_isNaNF64UI := __isnanl - - extern __isnanl diff --git a/src/softfloat/makefile b/src/softfloat/makefile index f8290ed2c..047826df3 100644 --- a/src/softfloat/makefile +++ b/src/softfloat/makefile @@ -16,16 +16,24 @@ include $(CURDIR)/../common.mk -BUILD_SRC := $(patsubst %,build/%.src,$(wildcard *.c *.cpp)) +OBJECTS = +OBJECTS += $(patsubst %.c,build/%.c.o,$(wildcard *.c)) +OBJECTS += $(patsubst %.cpp,build/%.cpp.o,$(wildcard *.cpp)) +OBJECTS += $(patsubst %.src,build/%.o,$(wildcard *.src)) -EZCFLAGS := -S -fno-addrsig -Wall -Wextra -Wshadow -Oz -EZCFLAGS += -D_EZ80 -isystem ../libc/include -I ./include -EZCXXFLAGS := $(EZCFLAGS) -fno-exceptions -fno-rtti +EZCFLAGS += -Iinclude -WILDCARD_SRC = $(wildcard *.src) $(BUILD_SRC) WILDCARD_H := $(wildcard include/*.h) -all: $(BUILD_SRC) +LIB_SOFTFLOAT := build/libsoftfloat.a + +.SECONDARY: + +all: $(LIB_SOFTFLOAT) + +$(LIB_SOFTFLOAT): $(OBJECTS) + $(Q)$(call MKDIR,build) + $(Q)$(EZAR) rcs $@ $^ build/%.c.src: %.c $(Q)$(call MKDIR,build) @@ -35,18 +43,23 @@ build/%.cpp.src: %.cpp $(Q)$(call MKDIR,build) $(Q)$(EZCC) $(EZCXXFLAGS) $< -o $@ +build/%.c.o: build/%.c.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.cpp.o: build/%.cpp.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + +build/%.o: %.src + $(Q)$(call MKDIR,build) + $(Q)$(EZAS) $(EZASFLAGS) $< -o $@ + clean: $(Q)$(call RMDIR,build) -# install: all -# $(Q)$(call MKDIR,$(INSTALL_H)) -# $(Q)$(call MKDIR,$(INSTALL_SOFTFLOAT)) -# $(Q)$(call COPY,$(call NATIVEPATH,$(WILDCARD_SRC)),$(INSTALL_SOFTFLOAT)) -# $(Q)$(call COPY,$(foreach file,$(call NATIVEPATH,$(WILDCARD_H)),$(call QUOTE_ARG,$(file))),$(INSTALL_H)) - install: all $(Q)$(call MKDIR,$(INSTALL_SOFTFLOAT)) - $(Q)$(call COPY,$(call NATIVEPATH,$(WILDCARD_SRC)),$(INSTALL_SOFTFLOAT)) - -.PHONY: all clean + $(Q)$(call COPY,$(call NATIVEPATH,$(LIB_SOFTFLOAT)),$(INSTALL_SOFTFLOAT)) +.PHONY: all clean install diff --git a/src/softfloat/s_normSubnormalF64Sig.src b/src/softfloat/s_normSubnormalF64Sig.src index e9fa29158..68497a6b6 100644 --- a/src/softfloat/s_normSubnormalF64Sig.src +++ b/src/softfloat/s_normSubnormalF64Sig.src @@ -1,8 +1,8 @@ - assume adl = 1 + .assume adl = 1 - section .text + .section .text - public _softfloat_normSubnormalF64Sig + .global _softfloat_normSubnormalF64Sig ; saves 78 bytes ; this function is called in the float64_ldexp tests @@ -34,9 +34,9 @@ _softfloat_normSubnormalF64Sig: ld (iy + 5), de ld (iy + 8), bc - lea hl, iy ; ABI struct ptr + lea hl, iy + 0 ; ABI struct ptr ret - extern __llshl - extern __llctlz - extern __ineg + .extern __llshl + .extern __llctlz + .extern __ineg diff --git a/src/softfloat/s_propagateNaNF64UI.src b/src/softfloat/s_propagateNaNF64UI.src index ca53485d8..d8a0ffd9a 100644 --- a/src/softfloat/s_propagateNaNF64UI.src +++ b/src/softfloat/s_propagateNaNF64UI.src @@ -1,8 +1,8 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _softfloat_propagateNaNF64UI + .global _softfloat_propagateNaNF64UI ; at least one of the arguments is NaN ; returns x if it is NaN, otherwise returns y @@ -33,6 +33,6 @@ _softfloat_propagateNaNF64UI: pop ix ret - extern __isnanl - extern __frameset0 - extern ___fe_cur_env + .extern __isnanl + .extern __frameset0 + .extern ___fe_cur_env diff --git a/src/softfloat/s_roundPackToF32.c b/src/softfloat/s_roundPackToF32.c index 47a9b6a2c..7b45197cd 100644 --- a/src/softfloat/s_roundPackToF32.c +++ b/src/softfloat/s_roundPackToF32.c @@ -46,7 +46,9 @@ float32_t uint_fast8_t roundingMode; bool roundNearEven; uint_fast8_t roundIncrement, roundBits; + #if 0 bool isTiny; + #endif uint_fast32_t uiZ; union ui32_f32 uZ; @@ -69,9 +71,11 @@ float32_t if ( exp < 0 ) { /*---------------------------------------------------------------- *----------------------------------------------------------------*/ + #if 0 isTiny = (softfloat_detectTininess == softfloat_tininess_beforeRounding) || (exp < -1) || (sig + roundIncrement < 0x80000000); + #endif sig = softfloat_shiftRightJam32( sig, -exp ); exp = 0; roundBits = sig & 0x7F; @@ -109,11 +113,12 @@ float32_t if ( ! sig ) exp = 0; /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ + #if 0 packReturn: + #endif uiZ = packToF32UI( sign, exp, sig ); uiZ: uZ.ui = uiZ; return uZ.f; } - diff --git a/src/softfloat/s_roundPackToF64.c b/src/softfloat/s_roundPackToF64.c index 9949e4729..15e8dacf7 100644 --- a/src/softfloat/s_roundPackToF64.c +++ b/src/softfloat/s_roundPackToF64.c @@ -46,7 +46,9 @@ float64_t uint_fast8_t roundingMode; bool roundNearEven; uint_fast16_t roundIncrement, roundBits; + #if 0 bool isTiny; + #endif uint_fast64_t uiZ; union ui64_f64 uZ; @@ -69,10 +71,12 @@ float64_t if ( exp < 0 ) { /*---------------------------------------------------------------- *----------------------------------------------------------------*/ + #if 0 isTiny = (softfloat_detectTininess == softfloat_tininess_beforeRounding) || (exp < -1) || (sig + roundIncrement < UINT64_C( 0x8000000000000000 )); + #endif sig = softfloat_shiftRightJam64( sig, -exp ); exp = 0; roundBits = sig & 0x3FF; @@ -109,11 +113,12 @@ float64_t if ( ! sig ) exp = 0; /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ + #if 0 packReturn: + #endif uiZ = packToF64UI( sign, exp, sig ); uiZ: uZ.ui = uiZ; return uZ.f; } - diff --git a/src/softfloat/s_shiftRightJam64.src b/src/softfloat/s_shiftRightJam64.src index ff28c1faf..5a43c00c3 100644 --- a/src/softfloat/s_shiftRightJam64.src +++ b/src/softfloat/s_shiftRightJam64.src @@ -1,8 +1,8 @@ - assume adl = 1 + .assume adl = 1 - section .text + .section .text - public _softfloat_shortShiftRightJam64 + .global _softfloat_shortShiftRightJam64 ; shift amount is [1, 63] _softfloat_shortShiftRightJam64: @@ -11,11 +11,11 @@ _softfloat_shortShiftRightJam64: add iy, sp ld l, (iy + 13) ; shift amount ; scf ; disables jr nc, .overflow_shift - jr _softfloat_shiftRightJam64.hijack + jr .L.hijack - section .text + .section .text - public _softfloat_shiftRightJam64 + .global _softfloat_shiftRightJam64 ; shift amount is non-zero _softfloat_shiftRightJam64: @@ -24,16 +24,15 @@ _softfloat_shiftRightJam64: add iy, sp ld a, (iy + 16) ; shift amount hi8 or a, a - jr nz, .overflow + jr nz, .L.overflow ld hl, (iy + 13) ; shift amount lo24 sbc hl, bc add hl, bc -.overflow: - private _softfloat_shiftRightJam64.hijack -.hijack: +.L.overflow: +.L.hijack: ld de, (iy + 7) ld bc, (iy + 10) - jr nc, .overflow_shift + jr nc, .L.overflow_shift push hl ; >> shift sub a, l ; A = 0 - L and a, $3F @@ -43,9 +42,9 @@ _softfloat_shiftRightJam64: call __llshl xor a, a call __llcmpzero - jr z, .no_round + jr z, .L.no_round inc a ; ld a, 1 -.no_round: +.L.no_round: pop hl ; SP -= 3 ld hl, (iy + 4) ld de, (iy + 7) @@ -56,7 +55,7 @@ _softfloat_shiftRightJam64: pop af ; reset SP ret -.overflow_shift: +.L.overflow_shift: ; A is zero here ld hl, (iy + 4) call __llcmpzero @@ -70,6 +69,6 @@ _softfloat_shiftRightJam64: inc hl ret - extern __llcmpzero - extern __llshl - extern __llshru + .extern __llcmpzero + .extern __llshl + .extern __llshru diff --git a/src/softfloat/softfloat_isSigNaNF32UI.src b/src/softfloat/softfloat_isSigNaNF32UI.src index 459dbc0d2..66a8db739 100644 --- a/src/softfloat/softfloat_isSigNaNF32UI.src +++ b/src/softfloat/softfloat_isSigNaNF32UI.src @@ -1,8 +1,9 @@ - assume adl = 1 + .assume adl = 1 - section .text + .section .text._softfloat_isSigNaNF32UI + .global _softfloat_isSigNaNF32UI - public _softfloat_isSigNaNF32UI -_softfloat_isSigNaNF32UI := __issignalingf +_softfloat_isSigNaNF32UI: + jp __issignalingf - extern __issignalingf + .extern __issignalingf diff --git a/src/softfloat/softfloat_isSigNaNF64UI.src b/src/softfloat/softfloat_isSigNaNF64UI.src index fc276c982..25f03c997 100644 --- a/src/softfloat/softfloat_isSigNaNF64UI.src +++ b/src/softfloat/softfloat_isSigNaNF64UI.src @@ -1,8 +1,9 @@ - assume adl = 1 + .assume adl = 1 - section .text + .section .text._softfloat_isSigNaNF64UI + .global _softfloat_isSigNaNF64UI - public _softfloat_isSigNaNF64UI -_softfloat_isSigNaNF64UI := __issignalingl +_softfloat_isSigNaNF64UI: + jp __issignalingl - extern __issignalingl + .extern __issignalingl diff --git a/test/fileioc/rename/src/main.c b/test/fileioc/rename/src/main.c index 552b02867..42e4bd928 100644 --- a/test/fileioc/rename/src/main.c +++ b/test/fileioc/rename/src/main.c @@ -110,11 +110,11 @@ int main(void) { perror(NULL); } if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/floating_point/compiletime_classification/makefile b/test/floating_point/compiletime_classification/makefile index 953f6ea3d..d58a96f8f 100644 --- a/test/floating_point/compiletime_classification/makefile +++ b/test/floating_point/compiletime_classification/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -std=c17 -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -std=c++20 -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/compiletime_classification/src/main.c b/test/floating_point/compiletime_classification/src/main.c index da7d8ea38..e2c1ce923 100644 --- a/test/floating_point/compiletime_classification/src/main.c +++ b/test/floating_point/compiletime_classification/src/main.c @@ -699,11 +699,11 @@ int main(void) { int failed_test = run_test(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/floating_point/compiletime_classification/src/test.asm b/test/floating_point/compiletime_classification/src/test.asm deleted file mode 100644 index 0ea434227..000000000 --- a/test/floating_point/compiletime_classification/src/test.asm +++ /dev/null @@ -1,44 +0,0 @@ - assume adl = 1 - - section .text - -; if a function call is emitted (hence not constant folded), it will conflict with one of these functions - - public __fpclassifyf - public __fpclassifyl - public __issignalingf - public __isnanf - public __isinff - public __isfinitef - public __isnormalf - public __issubnormalf - public __iszerof - public __issignalingl - public __isnanl - public __isinfl - public __isfinitel - public __isnormall - public __issubnormall - public __iszerol - public __signbitf - public __signbitl - -__fpclassifyf: -__fpclassifyl: -__issignalingf: -__isnanf: -__isinff: -__isfinitef: -__isnormalf: -__issubnormalf: -__iszerof: -__issignalingl: -__isnanl: -__isinfl: -__isfinitel: -__isnormall: -__issubnormall: -__iszerol: -__signbitf: -__signbitl: - ret diff --git a/test/floating_point/compiletime_classification/src/test.s b/test/floating_point/compiletime_classification/src/test.s new file mode 100644 index 000000000..001dfd0ae --- /dev/null +++ b/test/floating_point/compiletime_classification/src/test.s @@ -0,0 +1,44 @@ + .assume adl = 1 + + .section .text + +; if a function call is emitted (hence not constant folded), it will conflict with one of these functions + + .global __fpclassifyf + .global __fpclassifyl + .global __issignalingf + .global __isnanf + .global __isinff + .global __isfinitef + .global __isnormalf + .global __issubnormalf + .global __iszerof + .global __issignalingl + .global __isnanl + .global __isinfl + .global __isfinitel + .global __isnormall + .global __issubnormall + .global __iszerol + .global __signbitf + .global __signbitl + +__fpclassifyf: +__fpclassifyl: +__issignalingf: +__isnanf: +__isinff: +__isfinitef: +__isnormalf: +__issubnormalf: +__iszerof: +__issignalingl: +__isnanl: +__isinfl: +__isfinitel: +__isnormall: +__issubnormall: +__iszerol: +__signbitf: +__signbitl: + ret diff --git a/test/floating_point/complex/makefile b/test/floating_point/complex/makefile index 458e3baa2..362020578 100644 --- a/test/floating_point/complex/makefile +++ b/test/floating_point/complex/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -std=c17 -Ofast CXXFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -std=c++20 -Ofast -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/complex/src/complex_alias.S b/test/floating_point/complex/src/complex_alias.S new file mode 100644 index 000000000..223b167a0 --- /dev/null +++ b/test/floating_point/complex/src/complex_alias.S @@ -0,0 +1,41 @@ + .assume adl=1 + + .section .text + + .global _T_CMPLXF, _T_CMPLX, _T_CMPLXL + .global _T_creal, _T_crealf, _T_creall + .global _T_cimag, _T_cimagf, _T_cimagl + .global _T_conj, _T_conjf, _T_conjl + +_T_CMPLXF: + jp _CMPLXF +_T_CMPLX: + jp _CMPLX +_T_CMPLXL: + jp _CMPLXL + +_T_creal: + jp _creal +_T_crealf: + jp _crealf +_T_creall: + jp _creall + +_T_cimag: + jp _cimag +_T_cimagf: + jp _cimagf +_T_cimagl: + jp _cimagl + +_T_conj: + jp _conj +_T_conjf: + jp _conjf +_T_conjl: + jp _conjl + + .extern _CMPLXF, _CMPLX, _CMPLXL + .extern _creal, _crealf, _creall + .extern _cimag, _cimagf, _cimagl + .extern _conj, _conjf, _conjl diff --git a/test/floating_point/complex/src/complex_alias.asm b/test/floating_point/complex/src/complex_alias.asm deleted file mode 100644 index 633ff6700..000000000 --- a/test/floating_point/complex/src/complex_alias.asm +++ /dev/null @@ -1,29 +0,0 @@ - assume adl=1 - - section .text - - public _T_CMPLXF, _T_CMPLX, _T_CMPLXL - public _T_creal, _T_crealf, _T_creall - public _T_cimag, _T_cimagf, _T_cimagl - public _T_conj, _T_conjf, _T_conjl - -_T_CMPLXF := _CMPLXF -_T_CMPLX := _CMPLX -_T_CMPLXL := _CMPLXL - -_T_creal := _creal -_T_crealf := _crealf -_T_creall := _creall - -_T_cimag := _cimag -_T_cimagf := _cimagf -_T_cimagl := _cimagl - -_T_conj := _conj -_T_conjf := _conjf -_T_conjl := _conjl - - extern _CMPLXF, _CMPLX, _CMPLXL - extern _creal, _crealf, _creall - extern _cimag, _cimagf, _cimagl - extern _conj, _conjf, _conjl diff --git a/test/floating_point/complex/src/main.c b/test/floating_point/complex/src/main.c index d034b1d1a..6c58c8a32 100644 --- a/test/floating_point/complex/src/main.c +++ b/test/floating_point/complex/src/main.c @@ -192,11 +192,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float32_classification/makefile b/test/floating_point/float32_classification/makefile index 41af113a4..3da0c1c79 100644 --- a/test/floating_point/float32_classification/makefile +++ b/test/floating_point/float32_classification/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_classification/src/main.c b/test/floating_point/float32_classification/src/main.c index 70dbf6f96..cc6f72f36 100644 --- a/test/floating_point/float32_classification/src/main.c +++ b/test/floating_point/float32_classification/src/main.c @@ -136,11 +136,11 @@ static test_result fpclassify_test(void) { int main(void) { os_ClrHome(); - fputs("Testing 2^" NUM_TO_STR(test_count) " inputs", stdout); + puts("Testing 2^" NUM_TO_STR(test_count) " inputs"); test_result ret = fpclassify_test(); os_ClrHome(); if (ret.passed) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { printf( "Failed test:\n0x%08lX\nTruth: %06o_%d\nGuess: %06o_%d", diff --git a/test/floating_point/float32_fminmax/makefile b/test/floating_point/float32_fminmax/makefile index 3665be2f9..04ca215b7 100644 --- a/test/floating_point/float32_fminmax/makefile +++ b/test/floating_point/float32_fminmax/makefile @@ -13,7 +13,8 @@ COMMON_FLAGS += -Oz -ffreestanding CFLAGS = ${COMMON_FLAGS} -std=c17 CXXFLAGS = ${COMMON_FLAGS} -std=c++20 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_fminmax/src/main.cpp b/test/floating_point/float32_fminmax/src/main.cpp index 3362eb08f..20f2c014d 100644 --- a/test/floating_point/float32_fminmax/src/main.cpp +++ b/test/floating_point/float32_fminmax/src/main.cpp @@ -69,11 +69,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float32_frexp/makefile b/test/floating_point/float32_frexp/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float32_frexp/makefile +++ b/test/floating_point/float32_frexp/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_frexp/src/main.c b/test/floating_point/float32_frexp/src/main.c index d67eda7e9..c657745e4 100644 --- a/test/floating_point/float32_frexp/src/main.c +++ b/test/floating_point/float32_frexp/src/main.c @@ -49,11 +49,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float32_ilogb/makefile b/test/floating_point/float32_ilogb/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float32_ilogb/makefile +++ b/test/floating_point/float32_ilogb/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_ilogb/src/main.c b/test/floating_point/float32_ilogb/src/main.c index 4b54a0617..6ba77f23a 100644 --- a/test/floating_point/float32_ilogb/src/main.c +++ b/test/floating_point/float32_ilogb/src/main.c @@ -67,11 +67,11 @@ size_t run_test(void) { return i; } if (fe_guess != fe_truth) { - fputs("fenv fail\n", stdout); + puts("fenv fail"); return i; } if (errno_guess != errno_truth) { - fputs("errno fail\n", stdout); + puts("errno fail"); return i; } } @@ -84,11 +84,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float32_ldexp/makefile b/test/floating_point/float32_ldexp/makefile index 0af5c00b5..3379a98eb 100644 --- a/test/floating_point/float32_ldexp/makefile +++ b/test/floating_point/float32_ldexp/makefile @@ -13,7 +13,8 @@ OPT_FLAGS = -Oz CFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) -std=c11 CXXFLAGS = $(WARN_FLAGS) $(OPT_FLAGS) -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_ldexp/src/main.c b/test/floating_point/float32_ldexp/src/main.c index d8689005b..056e83cbd 100644 --- a/test/floating_point/float32_ldexp/src/main.c +++ b/test/floating_point/float32_ldexp/src/main.c @@ -84,7 +84,7 @@ size_t run_test(void) { i, (unsigned int)__fe_cur_env, errno, input[i].value.bin, input[i].expon, output[i].bin ); - fputs("fenv/errno\n", stdout); + puts("fenv/errno"); return i; } } @@ -137,7 +137,7 @@ void run_edge_case(void) { output_i24 = scalbnf(input, clamp_exponent(expon)); output_i32 = scalblnf(input, expon); if (memcmp(&output_i24, &output_i32, sizeof(float)) != 0) { - fputs("Failed edge case\n", stdout); + puts("Failed edge case"); return; } } @@ -148,11 +148,11 @@ int main(void) { run_edge_case(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float32_math/makefile b/test/floating_point/float32_math/makefile index ccbed67c6..4440c02c8 100644 --- a/test/floating_point/float32_math/makefile +++ b/test/floating_point/float32_math/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -std=c++20 -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_math/src/main.cpp b/test/floating_point/float32_math/src/main.cpp index da92d68e4..34385fea1 100644 --- a/test/floating_point/float32_math/src/main.cpp +++ b/test/floating_point/float32_math/src/main.cpp @@ -110,13 +110,13 @@ int main(void) { if (failed_test != 0) { char buf[sizeof("Failed test L-8388608\n")]; boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + puts(buf); #if 0 /* debugging */ printf("ULP: %ld\n", fail_ulp); #endif } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/floating_point/float32_modf/makefile b/test/floating_point/float32_modf/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float32_modf/makefile +++ b/test/floating_point/float32_modf/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_modf/src/main.c b/test/floating_point/float32_modf/src/main.c index 8449c1b4b..8477a3153 100644 --- a/test/floating_point/float32_modf/src/main.c +++ b/test/floating_point/float32_modf/src/main.c @@ -58,11 +58,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float32_to_float64/makefile b/test/floating_point/float32_to_float64/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float32_to_float64/makefile +++ b/test/floating_point/float32_to_float64/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_to_float64/src/main.c b/test/floating_point/float32_to_float64/src/main.c index 6b9a6b097..5c92f8f86 100644 --- a/test/floating_point/float32_to_float64/src/main.c +++ b/test/floating_point/float32_to_float64/src/main.c @@ -50,11 +50,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float32_trunc/makefile b/test/floating_point/float32_trunc/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float32_trunc/makefile +++ b/test/floating_point/float32_trunc/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float32_trunc/src/main.c b/test/floating_point/float32_trunc/src/main.c index fa8105b09..6fd4a7682 100644 --- a/test/floating_point/float32_trunc/src/main.c +++ b/test/floating_point/float32_trunc/src/main.c @@ -50,11 +50,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float64_arithmetic/makefile b/test/floating_point/float64_arithmetic/makefile index ccbed67c6..4440c02c8 100644 --- a/test/floating_point/float64_arithmetic/makefile +++ b/test/floating_point/float64_arithmetic/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -std=c++20 -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_arithmetic/src/data.asm b/test/floating_point/float64_arithmetic/src/data.S similarity index 77% rename from test/floating_point/float64_arithmetic/src/data.asm rename to test/floating_point/float64_arithmetic/src/data.S index b35102a73..546632f07 100644 --- a/test/floating_point/float64_arithmetic/src/data.asm +++ b/test/floating_point/float64_arithmetic/src/data.S @@ -1,32 +1,32 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text - public _f64_pos_zero + .global _f64_pos_zero _f64_pos_zero: db $00, $00, $00, $00, $00, $00, $00, $00 - public _f64_neg_zero + .global _f64_neg_zero _f64_neg_zero: db $00, $00, $00, $00, $00, $00, $00, $80 - public _f64_pos_one + .global _f64_pos_one _f64_pos_one: db $00, $00, $00, $00, $00, $00, $F0, $3F - public _f64_neg_one + .global _f64_neg_one _f64_neg_one: db $00, $00, $00, $00, $00, $00, $F0, $BF - public _f64_pos_pi + .global _f64_pos_pi _f64_pos_pi: db $18, $2D, $44, $54, $FB, $21, $09, $40 - public _f64_neg_pi + .global _f64_neg_pi _f64_neg_pi: db $18, $2D, $44, $54, $FB, $21, $09, $C0 - public _drem_libcall + .global _drem_libcall _drem_libcall: call __frameset0 ; push y onto the stack diff --git a/test/floating_point/float64_arithmetic/src/main.cpp b/test/floating_point/float64_arithmetic/src/main.cpp index e474a8e6d..e684c5c0b 100644 --- a/test/floating_point/float64_arithmetic/src/main.cpp +++ b/test/floating_point/float64_arithmetic/src/main.cpp @@ -375,18 +375,18 @@ int main(void) { os_ClrHome(); int comparison_result = basic_test(); if (comparison_result != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", comparison_result); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", comparison_result); + puts(buf); } else { int64_t fail_ulp = 0; size_t fail_index = run_test(&fail_ulp); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); #if 0 /* debugging */ printf("ULP: %lld\n", fail_ulp); diff --git a/test/floating_point/float64_classification/makefile b/test/floating_point/float64_classification/makefile index 41af113a4..3da0c1c79 100644 --- a/test/floating_point/float64_classification/makefile +++ b/test/floating_point/float64_classification/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_classification/src/main.c b/test/floating_point/float64_classification/src/main.c index b26669503..b17e21444 100644 --- a/test/floating_point/float64_classification/src/main.c +++ b/test/floating_point/float64_classification/src/main.c @@ -136,11 +136,11 @@ static test_result fpclassify_test(void) { int main(void) { os_ClrHome(); - fputs("Testing 2^" NUM_TO_STR(test_count) " inputs", stdout); + puts("Testing 2^" NUM_TO_STR(test_count) " inputs"); test_result ret = fpclassify_test(); os_ClrHome(); if (ret.passed) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { printf( "Failed test:\n0x%016llX\nTruth: %06o_%d\nGuess: %06o_%d", diff --git a/test/floating_point/float64_frexp/makefile b/test/floating_point/float64_frexp/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float64_frexp/makefile +++ b/test/floating_point/float64_frexp/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_frexp/src/main.c b/test/floating_point/float64_frexp/src/main.c index 5763448bb..a75deba73 100644 --- a/test/floating_point/float64_frexp/src/main.c +++ b/test/floating_point/float64_frexp/src/main.c @@ -45,11 +45,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float64_from_integer/makefile b/test/floating_point/float64_from_integer/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float64_from_integer/makefile +++ b/test/floating_point/float64_from_integer/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_from_integer/src/crt_wrap.asm b/test/floating_point/float64_from_integer/src/crt_wrap.S similarity index 62% rename from test/floating_point/float64_from_integer/src/crt_wrap.asm rename to test/floating_point/float64_from_integer/src/crt_wrap.S index e7eedda0c..6e198a482 100644 --- a/test/floating_point/float64_from_integer/src/crt_wrap.asm +++ b/test/floating_point/float64_from_integer/src/crt_wrap.S @@ -1,33 +1,33 @@ - assume adl=1 + .assume adl=1 ;------------------------------------------------------------------------------- - section .text - - public _clear_fe_cur_env + .section .text._clear_fe_cur_env + .global _clear_fe_cur_env _clear_fe_cur_env: ld a, (___fe_cur_env) and a, -125 ; feclearexcept(FE_ALL_EXCEPT) ld (___fe_cur_env), a ret - public _get_fe_cur_env + .section .text._get_fe_cur_env + .global _get_fe_cur_env _get_fe_cur_env: ld a, (___fe_cur_env) ret ;------------------------------------------------------------------------------- - section .text - - public _CRT_uitod, _CRT_itod - + section .text._CRT_uitod + .global _CRT_uitod _CRT_uitod: ld hl, 3 add hl, sp ld hl, (hl) jp __uitod + section .text._CRT_itod + .global _CRT_itod _CRT_itod: ld hl, 3 add hl, sp @@ -36,9 +36,9 @@ _CRT_itod: ;------------------------------------------------------------------------------- - extern __ultod - extern __ltod - extern ___fe_cur_env + .extern __ultod + .extern __ltod + .extern ___fe_cur_env - extern __uitod - extern __itod + .extern __uitod + .extern __itod diff --git a/test/floating_point/float64_from_integer/src/main.c b/test/floating_point/float64_from_integer/src/main.c index 141514523..74833dcd7 100644 --- a/test/floating_point/float64_from_integer/src/main.c +++ b/test/floating_point/float64_from_integer/src/main.c @@ -131,7 +131,7 @@ size_t run_test(const char** failed_func) { input[i].u64, output[i].fu64.bin ); *failed_func = "ulltod"; - fputs("fenv\n", stdout); + puts("fenv"); return i; } #endif /* TEST_FENV */ @@ -156,7 +156,7 @@ size_t run_test(const char** failed_func) { input[i].u64, output[i].fu64.bin ); *failed_func = "lltod"; - fputs("fenv\n", stdout); + puts("fenv"); return i; } #endif /* TEST_FENV */ @@ -173,12 +173,12 @@ int main(void) { const char* failed_func; size_t fail_index = run_test(&failed_func); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); - fputs(failed_func, stdout); + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); + puts(failed_func); } while (!os_GetCSC()); diff --git a/test/floating_point/float64_ilogb/makefile b/test/floating_point/float64_ilogb/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float64_ilogb/makefile +++ b/test/floating_point/float64_ilogb/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_ilogb/src/main.c b/test/floating_point/float64_ilogb/src/main.c index 03bc34d77..197dbf0e3 100644 --- a/test/floating_point/float64_ilogb/src/main.c +++ b/test/floating_point/float64_ilogb/src/main.c @@ -67,11 +67,11 @@ size_t run_test(void) { return i; } if (fe_guess != fe_truth) { - fputs("fenv fail\n", stdout); + puts("fenv fail"); return i; } if (errno_guess != errno_truth) { - fputs("errno fail\n", stdout); + puts("errno fail"); return i; } } @@ -84,11 +84,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float64_ldexp/makefile b/test/floating_point/float64_ldexp/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float64_ldexp/makefile +++ b/test/floating_point/float64_ldexp/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_ldexp/src/main.c b/test/floating_point/float64_ldexp/src/main.c index 665302ae6..481edf155 100644 --- a/test/floating_point/float64_ldexp/src/main.c +++ b/test/floating_point/float64_ldexp/src/main.c @@ -87,7 +87,7 @@ void run_edge_case(void) { output_i24 = scalbnl(input, clamp_exponent(expon)); output_i32 = scalblnl(input, expon); if (memcmp(&output_i24, &output_i32, sizeof(long double)) != 0) { - fputs("Failed edge case\n", stdout); + puts("Failed edge case"); return; } } @@ -98,11 +98,11 @@ int main(void) { run_edge_case(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/float64_math/makefile b/test/floating_point/float64_math/makefile index ccbed67c6..4440c02c8 100644 --- a/test/floating_point/float64_math/makefile +++ b/test/floating_point/float64_math/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Wimplicit-float-conversion -Wimplicit-int-float-conversion -std=c++20 -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_math/src/main.cpp b/test/floating_point/float64_math/src/main.cpp index 80776cf19..60d3c512e 100644 --- a/test/floating_point/float64_math/src/main.cpp +++ b/test/floating_point/float64_math/src/main.cpp @@ -108,15 +108,15 @@ int main(void) { os_ClrHome(); int failed_test = run_test(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); #if 0 /* debugging */ printf("ULP: %lld\n", fail_ulp); #endif } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/floating_point/float64_rounding/makefile b/test/floating_point/float64_rounding/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float64_rounding/makefile +++ b/test/floating_point/float64_rounding/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_rounding/src/main.c b/test/floating_point/float64_rounding/src/main.c index 4ee2f3c77..38889e45f 100644 --- a/test/floating_point/float64_rounding/src/main.c +++ b/test/floating_point/float64_rounding/src/main.c @@ -72,12 +72,12 @@ int main(void) { const char* failed_func; size_t fail_index = run_test(&failed_func); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); - fputs(failed_func, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); + puts(failed_func); } while (!os_GetCSC()); diff --git a/test/floating_point/float64_to_float32/makefile b/test/floating_point/float64_to_float32/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float64_to_float32/makefile +++ b/test/floating_point/float64_to_float32/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_to_float32/src/main.c b/test/floating_point/float64_to_float32/src/main.c index 7ffbd670a..159e24a1a 100644 --- a/test/floating_point/float64_to_float32/src/main.c +++ b/test/floating_point/float64_to_float32/src/main.c @@ -185,7 +185,7 @@ void brute_force_test(void) { } } } - fputs("Passed random tests", stdout); + puts("Passed random tests"); } size_t run_test(void) { @@ -215,11 +215,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("Passed edge cases\n", stdout); + puts("Passed edge cases"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } brute_force_test(); diff --git a/test/floating_point/float64_to_integer/makefile b/test/floating_point/float64_to_integer/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float64_to_integer/makefile +++ b/test/floating_point/float64_to_integer/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_trunc/makefile b/test/floating_point/float64_trunc/makefile index 61485bbce..066a6cf53 100644 --- a/test/floating_point/float64_trunc/makefile +++ b/test/floating_point/float64_trunc/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/float64_trunc/src/main.c b/test/floating_point/float64_trunc/src/main.c index f932d4db1..e2fa1fa16 100644 --- a/test/floating_point/float64_trunc/src/main.c +++ b/test/floating_point/float64_trunc/src/main.c @@ -48,11 +48,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/floating_point/ultof/makefile b/test/floating_point/ultof/makefile index 46c198eeb..7915429d3 100644 --- a/test/floating_point/ultof/makefile +++ b/test/floating_point/ultof/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -O0 CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -O0 -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/floating_point/ultof/src/main.c b/test/floating_point/ultof/src/main.c index 34399c462..09eb0f11c 100644 --- a/test/floating_point/ultof/src/main.c +++ b/test/floating_point/ultof/src/main.c @@ -76,11 +76,11 @@ int main(void) { os_ClrHome(); size_t fail_index = run_test(); if (fail_index == SIZE_MAX) { - fputs("All tests passed", stdout); + puts("All tests passed"); } else { - char buf[sizeof("Failed test: 16777215\n")]; - boot_sprintf(buf, "Failed test: %u\n", fail_index); - fputs(buf, stdout); + char buf[sizeof("Failed test: 16777215")]; + boot_sprintf(buf, "Failed test: %u", fail_index); + puts(buf); } while (!os_GetCSC()); diff --git a/test/fontlibc/glyph_width/src/main.c b/test/fontlibc/glyph_width/src/main.c index 54c9f7782..b139aa642 100644 --- a/test/fontlibc/glyph_width/src/main.c +++ b/test/fontlibc/glyph_width/src/main.c @@ -80,11 +80,11 @@ int main(void) { os_ClrHome(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/graphx/palette/makefile b/test/graphx/palette/makefile index c263988e7..de29fddf8 100644 --- a/test/graphx/palette/makefile +++ b/test/graphx/palette/makefile @@ -10,7 +10,8 @@ COMPRESSED = NO CFLAGS = -Wall -Wextra -Wshadow -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/graphx/palette/src/main.c b/test/graphx/palette/src/main.c index 76c458c51..1b8311c86 100644 --- a/test/graphx/palette/src/main.c +++ b/test/graphx/palette/src/main.c @@ -70,7 +70,7 @@ int main(void) { os_ClrHome(); - fputs(result, stdout); + puts(result); while (!os_GetCSC()); diff --git a/test/regression/bug0005/makefile b/test/regression/bug0005/makefile index 3efc55361..968e337e3 100644 --- a/test/regression/bug0005/makefile +++ b/test/regression/bug0005/makefile @@ -11,7 +11,8 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Oz CXXFLAGS = -Wall -Wextra -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/regression/i48routines/makefile b/test/regression/i48routines/makefile index 3efc55361..968e337e3 100644 --- a/test/regression/i48routines/makefile +++ b/test/regression/i48routines/makefile @@ -11,7 +11,8 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Oz CXXFLAGS = -Wall -Wextra -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/regression/i48routines/src/main.c b/test/regression/i48routines/src/main.c index 191f81ffe..8d8b60348 100644 --- a/test/regression/i48routines/src/main.c +++ b/test/regression/i48routines/src/main.c @@ -43,7 +43,8 @@ typedef void (*test_func_t)(regs_t *); void test_##ROUTINE(regs_t *regs) \ { \ asm volatile("ld\thl,(iy + %[af])\n\t" \ - "push\tiy, hl\n\t" \ + "push\tiy\n\t" \ + "push\thl\n\t" \ "pop\taf\n\t" \ "ld\thl, (iy + %[hl])\n\t" \ "ld\tde, (iy + %[de])\n\t" \ @@ -56,7 +57,8 @@ void test_##ROUTINE(regs_t *regs) \ "ld\t(iy + %[de]), de\n\t" \ "ld\t(iy + %[bc]), bc\n\t" \ "push\taf\n\t" \ - "pop\thl, de\n\t" \ + "pop\thl\n\t" \ + "pop\tde\n\t" \ "ld\t(iy + %[af]), hl\n\t" \ "ld\t(iy + %[iy]), de\n\t" \ : \ diff --git a/test/standalone/asprintf_fprintf/makefile b/test/standalone/asprintf_fprintf/makefile index 5cfe96f06..0086b9ba6 100644 --- a/test/standalone/asprintf_fprintf/makefile +++ b/test/standalone/asprintf_fprintf/makefile @@ -11,8 +11,8 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Wformat=2 -Wshadow -Oz CXXFLAGS = -Wall -Wextra -Wformat=2 -Wshadow -Oz -PREFER_OS_LIBC = NO - +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO HAS_PRINTF = YES # ---------------------------- diff --git a/test/standalone/asprintf_fprintf/src/rename.asm b/test/standalone/asprintf_fprintf/src/rename.asm deleted file mode 100644 index 14c6bd1b8..000000000 --- a/test/standalone/asprintf_fprintf/src/rename.asm +++ /dev/null @@ -1,38 +0,0 @@ - assume adl = 1 - - section .text - - public _T_memset, _T_memcpy, _T_memmove, _T_memcmp, _T_memccpy, _T_mempcpy, _T_memrchr, _T_memmem, _T_memrmem - public _T_strlen, _T_strcmp, _T_strncmp, _T_stpcpy, _T_stpncpy, _T_strlcat, _T_strchrnul, _T_strrstr - public _T_bzero - -_T_memset := _memset -_T_memcpy := _memcpy -_T_memmove := _memmove -_T_memcmp := _memcmp -_T_memccpy := _memccpy -_T_mempcpy := _mempcpy -_T_memrchr := _memrchr -_T_memmem := _memmem -_T_memrmem := _memrmem - -_T_strlen := _strlen -_T_strcmp := _strcmp -_T_strncmp := _strncmp -_T_stpcpy := _stpcpy -_T_stpncpy := _stpncpy -_T_strlcat := _strlcat -_T_strchrnul := _strchrnul -_T_strrstr := _strrstr - -_T_bzero := _bzero - - section .rodata - - public _NULL_ptr -_NULL_ptr: - db $00, $00, $00 - - extern _memset, _memcpy, _memmove, _memcmp, _memccpy, _mempcpy, _memrchr, _memmem, _memrmem - extern _strlen, _strcmp, _strncmp, _stpcpy, _stpncpy, _strlcat, _strchrnul, _strrstr - extern _bzero diff --git a/test/standalone/asprintf_fprintf/src/rename.s b/test/standalone/asprintf_fprintf/src/rename.s new file mode 100644 index 000000000..aa23678af --- /dev/null +++ b/test/standalone/asprintf_fprintf/src/rename.s @@ -0,0 +1,56 @@ + .assume adl = 1 + + .section .text + + .global _T_memset, _T_memcpy, _T_memmove, _T_memcmp, _T_memccpy, _T_mempcpy, _T_memrchr, _T_memmem, _T_memrmem + .global _T_strlen, _T_strcmp, _T_strncmp, _T_stpcpy, _T_stpncpy, _T_strlcat, _T_strchrnul, _T_strrstr + .global _T_bzero + +_T_memset: + jp _memset +_T_memcpy: + jp _memcpy +_T_memmove: + jp _memmove +_T_memcmp: + jp _memcmp +_T_memccpy: + jp _memccpy +_T_mempcpy: + jp _mempcpy +_T_memrchr: + jp _memrchr +_T_memmem: + jp _memmem +_T_memrmem: + jp _memrmem + +_T_strlen: + jp _strlen +_T_strcmp: + jp _strcmp +_T_strncmp: + jp _strncmp +_T_stpcpy: + jp _stpcpy +_T_stpncpy: + jp _stpncpy +_T_strlcat: + jp _strlcat +_T_strchrnul: + jp _strchrnul +_T_strrstr: + jp _strrstr + +_T_bzero: + jp _bzero + + .section .rodata._NULL_ptr + + .global _NULL_ptr +_NULL_ptr: + db $00, $00, $00 + + .extern _memset, _memcpy, _memmove, _memcmp, _memccpy, _mempcpy, _memrchr, _memmem, _memrmem + .extern _strlen, _strcmp, _strncmp, _stpcpy, _stpncpy, _strlcat, _strchrnul, _strrstr + .extern _bzero diff --git a/test/standalone/concepts/makefile b/test/standalone/concepts/makefile index 99a76d357..aa180ec9f 100644 --- a/test/standalone/concepts/makefile +++ b/test/standalone/concepts/makefile @@ -11,7 +11,8 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Wconversion -Wformat=2 -std=c17 -Oz CXXFLAGS = -Wall -Wextra -Wconversion -Wformat=2 -std=c++20 -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/standalone/concepts/src/main.cpp b/test/standalone/concepts/src/main.cpp index 8083ee0a5..13c5dab18 100644 --- a/test/standalone/concepts/src/main.cpp +++ b/test/standalone/concepts/src/main.cpp @@ -117,7 +117,7 @@ int run_tests(void) { "ret: %d != %d\nstrcmp(buf, text) == %d\n", ret, text_len, cmp ); - std::fputs(buf, stdout); + std::puts(buf); return __LINE__; } } diff --git a/test/standalone/errno/makefile b/test/standalone/errno/makefile index 3efc55361..968e337e3 100644 --- a/test/standalone/errno/makefile +++ b/test/standalone/errno/makefile @@ -11,7 +11,8 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Oz CXXFLAGS = -Wall -Wextra -Oz -PREFER_OS_LIBC = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/standalone/errno/src/main.c b/test/standalone/errno/src/main.c index fd295a5e6..888575c2e 100644 --- a/test/standalone/errno/src/main.c +++ b/test/standalone/errno/src/main.c @@ -120,11 +120,11 @@ int main(void) const char * str = strerror(i); errno = (int)i; if (strlen(truth[i]) != strlen(str) || strcmp(truth[i], str) != 0) { - fputs("strerror failed\n", stdout); + puts("strerror failed"); break; } } - fputs("finished\n", stdout); + puts("finished"); while (!os_GetCSC()); diff --git a/test/standalone/ez80_builtin/makefile b/test/standalone/ez80_builtin/makefile index 41673220d..c6c9cfc78 100644 --- a/test/standalone/ez80_builtin/makefile +++ b/test/standalone/ez80_builtin/makefile @@ -11,8 +11,9 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz -PREFER_OS_LIBC = NO -PREFER_OS_CRT = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO +PREFER_CE_CRT = NO # ---------------------------- diff --git a/test/standalone/ez80_builtin/src/main.c b/test/standalone/ez80_builtin/src/main.c index 4ef4312ca..27b482817 100644 --- a/test/standalone/ez80_builtin/src/main.c +++ b/test/standalone/ez80_builtin/src/main.c @@ -571,11 +571,11 @@ int main(void) { os_ClrHome(); int failed_test = run_tests(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/standalone/i48div/makefile b/test/standalone/i48div/makefile index 41673220d..6e3ca999c 100644 --- a/test/standalone/i48div/makefile +++ b/test/standalone/i48div/makefile @@ -11,8 +11,8 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz -PREFER_OS_LIBC = NO -PREFER_OS_CRT = NO +PREFER_CE_LIBC = NO +PREFER_CE_CRT = NO # ---------------------------- diff --git a/test/standalone/i48div/src/main.c b/test/standalone/i48div/src/main.c index 32c5203be..b2c3be6bc 100644 --- a/test/standalone/i48div/src/main.c +++ b/test/standalone/i48div/src/main.c @@ -180,11 +180,11 @@ int main(void) { os_ClrHome(); int failed_test = run_tests(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/standalone/mulu_b/makefile b/test/standalone/mulu_b/makefile index 41673220d..c6c9cfc78 100644 --- a/test/standalone/mulu_b/makefile +++ b/test/standalone/mulu_b/makefile @@ -11,8 +11,9 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz -PREFER_OS_LIBC = NO -PREFER_OS_CRT = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO +PREFER_CE_CRT = NO # ---------------------------- diff --git a/test/standalone/mulu_b/src/crt_wrap.asm b/test/standalone/mulu_b/src/crt_wrap.S similarity index 81% rename from test/standalone/mulu_b/src/crt_wrap.asm rename to test/standalone/mulu_b/src/crt_wrap.S index 4c29370db..e444a7e02 100644 --- a/test/standalone/mulu_b/src/crt_wrap.asm +++ b/test/standalone/mulu_b/src/crt_wrap.S @@ -1,20 +1,20 @@ - assume adl=1 + .assume adl=1 - section .data + .section .data - public _prev_reg + .global _prev_reg _prev_reg: ; L H U E D U C B U A X I U Y I U db 0,0,0, 0,0,0, 0,0,0, 0, 0,0,0, 0,0,0 - public _next_reg + .global _next_reg _next_reg: ; L H U E D U C B U A X I U Y I U db 0,0,0, 0,0,0, 0,0,0, 0, 0,0,0, 0,0,0 section .text - private _set_prev_reg + .local _set_prev_reg _set_prev_reg: ld (_prev_reg + 0), hl ld (_prev_reg + 3), de @@ -24,7 +24,7 @@ _set_prev_reg: ; ld (_prev_reg + 13), ix ret - private _set_next_reg + .local _set_next_reg _set_next_reg: ld (_next_reg + 0), hl ld (_next_reg + 3), de @@ -34,7 +34,7 @@ _set_next_reg: ; ld (_next_reg + 13), ix ret - public _CRT_smulu_b + .global _CRT_smulu_b _CRT_smulu_b: ld iy, 0 add iy, sp @@ -42,9 +42,9 @@ _CRT_smulu_b: ld a, (iy + 6) call _set_prev_reg call __smulu_b - jq _set_next_reg + jr _set_next_reg - public _CRT_smulu_b_fast + .global _CRT_smulu_b_fast _CRT_smulu_b_fast: ld iy, 0 add iy, sp @@ -52,7 +52,7 @@ _CRT_smulu_b_fast: ld a, (iy + 6) jp __smulu_b_fast - public _CRT_imulu_b + .global _CRT_imulu_b _CRT_imulu_b: ld iy, 0 add iy, sp @@ -60,9 +60,9 @@ _CRT_imulu_b: ld a, (iy + 6) call _set_prev_reg call __imulu_b - jq _set_next_reg + jr _set_next_reg - public _CRT_imulu_b_fast + .global _CRT_imulu_b_fast _CRT_imulu_b_fast: ld iy, 0 add iy, sp @@ -70,7 +70,7 @@ _CRT_imulu_b_fast: ld a, (iy + 6) jp __imulu_b_fast - public _CRT_lmulu_b + .global _CRT_lmulu_b _CRT_lmulu_b: ld iy, 0 add iy, sp @@ -79,9 +79,9 @@ _CRT_lmulu_b: ld a, (iy + 9) call _set_prev_reg call __lmulu_b - jq _set_next_reg + jr _set_next_reg - public _CRT_lmulu_b_fast + .global _CRT_lmulu_b_fast _CRT_lmulu_b_fast: ld iy, 0 add iy, sp @@ -90,7 +90,7 @@ _CRT_lmulu_b_fast: ld a, (iy + 9) jp __lmulu_b_fast - public _CRT_llmulu_b + .global _CRT_llmulu_b _CRT_llmulu_b: ld iy, 0 add iy, sp diff --git a/test/standalone/mulu_b/src/main.c b/test/standalone/mulu_b/src/main.c index bd56fdad2..18f8b6262 100644 --- a/test/standalone/mulu_b/src/main.c +++ b/test/standalone/mulu_b/src/main.c @@ -300,11 +300,11 @@ int main(void) { os_ClrHome(); int failed_test = run_tests(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/standalone/scanf/makefile b/test/standalone/scanf/makefile index e99218420..b0c937fdd 100644 --- a/test/standalone/scanf/makefile +++ b/test/standalone/scanf/makefile @@ -11,8 +11,9 @@ ARCHIVED = NO CFLAGS = -ffreestanding -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz CXXFLAGS = -ffreestanding -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz -PREFER_OS_LIBC = NO -PREFER_OS_CRT = NO +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO +PREFER_CE_CRT = NO # ---------------------------- diff --git a/test/standalone/scanf/src/main.c b/test/standalone/scanf/src/main.c index 733c0204d..4823b01c3 100644 --- a/test/standalone/scanf/src/main.c +++ b/test/standalone/scanf/src/main.c @@ -235,11 +235,11 @@ int main(void) { os_ClrHome(); int failed_test = run_tests(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/standalone/stdbit/makefile b/test/standalone/stdbit/makefile index b09bc758f..ae471d755 100644 --- a/test/standalone/stdbit/makefile +++ b/test/standalone/stdbit/makefile @@ -11,7 +11,7 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -std=c17 -Oz CXXFLAGS = -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -std=c++17 -Oz -PREFER_OS_LIBC = NO +PREFER_CE_LIBC = NO # ---------------------------- diff --git a/test/standalone/stdbit/src/data.S b/test/standalone/stdbit/src/data.S new file mode 100644 index 000000000..9337dbd21 --- /dev/null +++ b/test/standalone/stdbit/src/data.S @@ -0,0 +1,300 @@ + .assume adl = 1 + + .section .data + + .global _zero_u8 + .global _zero_u16 + .global _zero_u24 + .global _zero_u32 + .global _zero_u48 + .global _zero_u64 +_zero_u8: +_zero_u16: +_zero_u24: +_zero_u32: +_zero_u48: +_zero_u64: + .db $00, $00, $00, $00, $00, $00, $00, $00 + + .global _one_u8 + .global _one_u16 + .global _one_u24 + .global _one_u32 + .global _one_u48 + .global _one_u64 +_one_u8: +_one_u16: +_one_u24: +_one_u32: +_one_u48: +_one_u64: + .db $01, $00, $00, $00, $00, $00, $00, $00 + + .global _umax_u8 + .global _umax_u16 + .global _umax_u24 + .global _umax_u32 + .global _umax_u48 + .global _umax_u64 +_umax_u8: +_umax_u16: +_umax_u24: +_umax_u32: +_umax_u48: +_umax_u64: + .db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF + + .global _smin_u8 + .global _smin_u16 + .global _smin_u24 + .global _smin_u32 + .global _smin_u48 + .global _smin_u64 +_smin_u64: + .db $00 + .db $00 +_smin_u48: + .db $00 + .db $00 +_smin_u32: + .db $00 +_smin_u24: + .db $00 +_smin_u16: + .db $00 +_smin_u8: + .db $80 + + .global _smax_u8 + .global _smax_u16 + .global _smax_u24 + .global _smax_u32 + .global _smax_u48 + .global _smax_u64 +_smax_u64: + .db $FF + .db $FF +_smax_u48: + .db $FF + .db $FF +_smax_u32: + .db $FF +_smax_u24: + .db $FF +_smax_u16: + .db $FF +_smax_u8: + .db $7F + + + .global _val_0 +_val_0: + .db 0 + .global _val_1 +_val_1: + .db 1 + .global _val_2 +_val_2: + .db 2 + .global _val_7 +_val_7: + .db 7 + .global _val_8 +_val_8: + .db 8 + .global _val_15 +_val_15: + .db 15 + .global _val_16 +_val_16: + .db 16 + .global _val_23 +_val_23: + .db 23 + .global _val_24 +_val_24: + .db 24 + .global _val_31 +_val_31: + .db 31 + .global _val_32 +_val_32: + .db 32 + .global _val_47 +_val_47: + .db 47 + .global _val_48 +_val_48: + .db 48 + .global _val_63 +_val_63: + .db 63 + .global _val_64 +_val_64: + .db 64 + +; uint8_t byteswap_u8[4] = { +; 0x00, +; 0xFF, +; 0x12, +; 0x43, +; }; +; uint16_t byteswap_u16[4] = { +; 0x0000, +; 0xFFFF, +; 0x1234, +; 0x4321, +; }; +; uint24_t byteswap_u24[4] = { +; 0x000000, +; 0xFFFFFF, +; 0x123456, +; 0x654321, +; }; +; uint32_t byteswap_u32[4] = { +; 0x00000000, +; 0xFFFFFFFF, +; 0x12345678, +; 0x87654321, +; }; +; uint48_t byteswap_u48[4] = { +; 0x000000000000, +; 0xFFFFFFFFFFFF, +; 0x123456789ABC, +; 0xCBA987654321, +; }; +; uint64_t byteswap_u64[4] = { +; 0x0000000000000000, +; 0xFFFFFFFFFFFFFFFF, +; 0x0123456789ABCDEF, +; 0xFEDCBA9876543210, +; }; + + .global _byteswap_u8 +_byteswap_u8: + .db 0 + .db 255 + .db 18 + .db 67 + + .global _byteswap_u16 +_byteswap_u16: + .word 0 + .word 65535 + .word 4660 + .word 17185 + + .global _byteswap_u24 +_byteswap_u24: + .d24 0 + .d24 16777215 + .d24 1193046 + .d24 6636321 + + .global _byteswap_u32 +_byteswap_u32: + .long 0 + .long 4294967295 + .long 305419896 + .long 2271560481 + + .global _byteswap_u48 +_byteswap_u48: + .long 0 + .word 0 + .long 4294967295 + .word 65535 + .long 1450744508 + .word 4660 + .long 2271560481 + .word 52137 + + .global _byteswap_u64 +_byteswap_u64: + .quad 0 + .quad -1 + .quad 81985529216486895 + .quad -81985529216486896 + +; uint8_t byteswap_i8[4] = { +; 0x00, +; 0xFF, +; 0x12, +; 0x43, +; }; +; uint16_t byteswap_i16[4] = { +; 0x0000, +; 0xFFFF, +; 0x3412, +; 0x2143, +; }; +; uint24_t byteswap_i24[4] = { +; 0x000000, +; 0xFFFFFF, +; 0x563412, +; 0x214365, +; }; +; uint32_t byteswap_i32[4] = { +; 0x00000000, +; 0xFFFFFFFF, +; 0x78563412, +; 0x21436587, +; }; +; uint48_t byteswap_i48[4] = { +; 0x000000000000, +; 0xFFFFFFFFFFFF, +; 0xBC9A78563412, +; 0x21436587A9CB, +; }; +; uint64_t byteswap_i64[4] = { +; 0x0000000000000000, +; 0xFFFFFFFFFFFFFFFF, +; 0xEFCDAB8967452301, +; 0x1032547698BADCFE, +; }; + + .global _byteswap_i8 +_byteswap_i8: + .db 0 + .db 255 + .db 18 + .db 67 + + .global _byteswap_i16 +_byteswap_i16: + .word 0 + .word 65535 + .word 13330 + .word 8515 + + .global _byteswap_i24 +_byteswap_i24: + .d24 0 + .d24 16777215 + .d24 5649426 + .d24 2179941 + + .global _byteswap_i32 +_byteswap_i32: + .long 0 + .long 4294967295 + .long 2018915346 + .long 558065031 + + .global _byteswap_i48 +_byteswap_i48: + .long 0 + .word 0 + .long 4294967295 + .word 65535 + .long 2018915346 + .word 48282 + .long 1703389643 + .word 8515 + + .global _byteswap_i64 +_byteswap_i64: + .quad 0 + .quad -1 + .quad -1167088121787636991 + .quad 1167088121787636990 diff --git a/test/standalone/stdbit/src/data.asm b/test/standalone/stdbit/src/data.asm deleted file mode 100644 index 2c15c21dc..000000000 --- a/test/standalone/stdbit/src/data.asm +++ /dev/null @@ -1,300 +0,0 @@ - assume adl = 1 - - section .data - - public _zero_u8 - public _zero_u16 - public _zero_u24 - public _zero_u32 - public _zero_u48 - public _zero_u64 -_zero_u8: -_zero_u16: -_zero_u24: -_zero_u32: -_zero_u48: -_zero_u64: - db $00, $00, $00, $00, $00, $00, $00, $00 - - public _one_u8 - public _one_u16 - public _one_u24 - public _one_u32 - public _one_u48 - public _one_u64 -_one_u8: -_one_u16: -_one_u24: -_one_u32: -_one_u48: -_one_u64: - db $01, $00, $00, $00, $00, $00, $00, $00 - - public _umax_u8 - public _umax_u16 - public _umax_u24 - public _umax_u32 - public _umax_u48 - public _umax_u64 -_umax_u8: -_umax_u16: -_umax_u24: -_umax_u32: -_umax_u48: -_umax_u64: - db $FF, $FF, $FF, $FF, $FF, $FF, $FF, $FF - - public _smin_u8 - public _smin_u16 - public _smin_u24 - public _smin_u32 - public _smin_u48 - public _smin_u64 -_smin_u64: - db $00 - db $00 -_smin_u48: - db $00 - db $00 -_smin_u32: - db $00 -_smin_u24: - db $00 -_smin_u16: - db $00 -_smin_u8: - db $80 - - public _smax_u8 - public _smax_u16 - public _smax_u24 - public _smax_u32 - public _smax_u48 - public _smax_u64 -_smax_u64: - db $FF - db $FF -_smax_u48: - db $FF - db $FF -_smax_u32: - db $FF -_smax_u24: - db $FF -_smax_u16: - db $FF -_smax_u8: - db $7F - - - public _val_0 -_val_0: - db 0 - public _val_1 -_val_1: - db 1 - public _val_2 -_val_2: - db 2 - public _val_7 -_val_7: - db 7 - public _val_8 -_val_8: - db 8 - public _val_15 -_val_15: - db 15 - public _val_16 -_val_16: - db 16 - public _val_23 -_val_23: - db 23 - public _val_24 -_val_24: - db 24 - public _val_31 -_val_31: - db 31 - public _val_32 -_val_32: - db 32 - public _val_47 -_val_47: - db 47 - public _val_48 -_val_48: - db 48 - public _val_63 -_val_63: - db 63 - public _val_64 -_val_64: - db 64 - -; uint8_t byteswap_u8[4] = { -; 0x00, -; 0xFF, -; 0x12, -; 0x43, -; }; -; uint16_t byteswap_u16[4] = { -; 0x0000, -; 0xFFFF, -; 0x1234, -; 0x4321, -; }; -; uint24_t byteswap_u24[4] = { -; 0x000000, -; 0xFFFFFF, -; 0x123456, -; 0x654321, -; }; -; uint32_t byteswap_u32[4] = { -; 0x00000000, -; 0xFFFFFFFF, -; 0x12345678, -; 0x87654321, -; }; -; uint48_t byteswap_u48[4] = { -; 0x000000000000, -; 0xFFFFFFFFFFFF, -; 0x123456789ABC, -; 0xCBA987654321, -; }; -; uint64_t byteswap_u64[4] = { -; 0x0000000000000000, -; 0xFFFFFFFFFFFFFFFF, -; 0x0123456789ABCDEF, -; 0xFEDCBA9876543210, -; }; - - public _byteswap_u8 -_byteswap_u8: - db 0 - db 255 - db 18 - db 67 - - public _byteswap_u16 -_byteswap_u16: - dw 0 - dw 65535 - dw 4660 - dw 17185 - - public _byteswap_u24 -_byteswap_u24: - dl 0 - dl 16777215 - dl 1193046 - dl 6636321 - - public _byteswap_u32 -_byteswap_u32: - dd 0 - dd 4294967295 - dd 305419896 - dd 2271560481 - - public _byteswap_u48 -_byteswap_u48: - dd 0 - dw 0 - dd 4294967295 - dw 65535 - dd 1450744508 - dw 4660 - dd 2271560481 - dw 52137 - - public _byteswap_u64 -_byteswap_u64: - dq 0 - dq -1 - dq 81985529216486895 - dq -81985529216486896 - -; uint8_t byteswap_i8[4] = { -; 0x00, -; 0xFF, -; 0x12, -; 0x43, -; }; -; uint16_t byteswap_i16[4] = { -; 0x0000, -; 0xFFFF, -; 0x3412, -; 0x2143, -; }; -; uint24_t byteswap_i24[4] = { -; 0x000000, -; 0xFFFFFF, -; 0x563412, -; 0x214365, -; }; -; uint32_t byteswap_i32[4] = { -; 0x00000000, -; 0xFFFFFFFF, -; 0x78563412, -; 0x21436587, -; }; -; uint48_t byteswap_i48[4] = { -; 0x000000000000, -; 0xFFFFFFFFFFFF, -; 0xBC9A78563412, -; 0x21436587A9CB, -; }; -; uint64_t byteswap_i64[4] = { -; 0x0000000000000000, -; 0xFFFFFFFFFFFFFFFF, -; 0xEFCDAB8967452301, -; 0x1032547698BADCFE, -; }; - - public _byteswap_i8 -_byteswap_i8: - db 0 - db 255 - db 18 - db 67 - - public _byteswap_i16 -_byteswap_i16: - dw 0 - dw 65535 - dw 13330 - dw 8515 - - public _byteswap_i24 -_byteswap_i24: - dl 0 - dl 16777215 - dl 5649426 - dl 2179941 - - public _byteswap_i32 -_byteswap_i32: - dd 0 - dd 4294967295 - dd 2018915346 - dd 558065031 - - public _byteswap_i48 -_byteswap_i48: - dd 0 - dw 0 - dd 4294967295 - dw 65535 - dd 2018915346 - dw 48282 - dd 1703389643 - dw 8515 - - public _byteswap_i64 -_byteswap_i64: - dq 0 - dq -1 - dq -1167088121787636991 - dq 1167088121787636990 diff --git a/test/standalone/stdbit/src/main.cpp b/test/standalone/stdbit/src/main.cpp index 6071f84ba..ea4cf7beb 100644 --- a/test/standalone/stdbit/src/main.cpp +++ b/test/standalone/stdbit/src/main.cpp @@ -558,11 +558,11 @@ int main(void) { int failed_test = run_tests(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/standalone/strtol/makefile b/test/standalone/strtol/makefile index e99218420..55d063bec 100644 --- a/test/standalone/strtol/makefile +++ b/test/standalone/strtol/makefile @@ -11,8 +11,8 @@ ARCHIVED = NO CFLAGS = -ffreestanding -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz CXXFLAGS = -ffreestanding -Wall -Wextra -Wshadow -Wconversion -Wformat=2 -Wno-sign-conversion -Oz -PREFER_OS_LIBC = NO -PREFER_OS_CRT = NO +PREFER_CE_LIBC = NO +PREFER_CE_CRT = NO # ---------------------------- diff --git a/test/standalone/strtol/src/char_to_digit.asm b/test/standalone/strtol/src/char_to_digit.S similarity index 74% rename from test/standalone/strtol/src/char_to_digit.asm rename to test/standalone/strtol/src/char_to_digit.S index e3223262a..1bb672b26 100644 --- a/test/standalone/strtol/src/char_to_digit.asm +++ b/test/standalone/strtol/src/char_to_digit.S @@ -1,8 +1,9 @@ - assume adl=1 + .assume adl=1 - section .text + .section .text._char_to_digit - public _char_to_digit + .global _char_to_digit + .type _char_to_digit, @function ; char char_to_digit(char c) _char_to_digit: @@ -15,12 +16,12 @@ _char_to_digit: ld a, (iy) sub a, 48 cp a, 10 - jr c, .check_digit + jr c, .L.check_digit ; Convert an alphabetic digit, case-insensitive sub a, 65 - 48 res 5, a add a, 10 -.check_digit: +.L.check_digit: cp a, 36 ret c ld a, -1 diff --git a/test/standalone/strtol/src/main.c b/test/standalone/strtol/src/main.c index 865b0ffc7..218b4fc85 100644 --- a/test/standalone/strtol/src/main.c +++ b/test/standalone/strtol/src/main.c @@ -40,7 +40,7 @@ #define TEST(test) { ret = test; if (ret != 0) { return ret; }} -#define TEST_NAME(test, name) { ret = test; if (ret != 0) { fputs(name "\n", stdout); return ret; }} +#define TEST_NAME(test, name) { ret = test; if (ret != 0) { puts(name); return ret; }} #define NO_ERR 0 @@ -572,11 +572,11 @@ int main(void) { os_ClrHome(); int failed_test = run_tests(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/standalone/wide_char/makefile b/test/standalone/wide_char/makefile index 108bf9ac8..a0616bfed 100644 --- a/test/standalone/wide_char/makefile +++ b/test/standalone/wide_char/makefile @@ -11,8 +11,8 @@ ARCHIVED = NO CFLAGS = -Wall -Wextra -ffreestanding -Wformat=2 -Wshadow -Oz CXXFLAGS = -Wall -Wextra -ffreestanding -Wformat=2 -Wshadow -Oz -PREFER_OS_LIBC = NO - +HAS_MATH_ERRNO = YES +PREFER_CE_LIBC = NO HAS_PRINTF = YES # ---------------------------- diff --git a/test/standalone/wide_char/src/main.c b/test/standalone/wide_char/src/main.c index c726e6370..260358831 100644 --- a/test/standalone/wide_char/src/main.c +++ b/test/standalone/wide_char/src/main.c @@ -273,11 +273,11 @@ int main(void) { os_ClrHome(); int failed_test = run_tests(); if (failed_test != 0) { - char buf[sizeof("Failed test L-8388608\n")]; - boot_sprintf(buf, "Failed test L%d\n", failed_test); - fputs(buf, stdout); + char buf[sizeof("Failed test L-8388608")]; + boot_sprintf(buf, "Failed test L%d", failed_test); + puts(buf); } else { - fputs("All tests passed", stdout); + puts("All tests passed"); } while (!os_GetCSC()); diff --git a/test/standalone/wide_char/src/rename.asm b/test/standalone/wide_char/src/rename.asm deleted file mode 100644 index fce6d2c5f..000000000 --- a/test/standalone/wide_char/src/rename.asm +++ /dev/null @@ -1,28 +0,0 @@ - assume adl=1 - - section .rodata - - public _PTR_000000 -_PTR_000000: - db $00, $00, $00 - - public _PTR_FFFFFF -_PTR_FFFFFF: - db $FF, $FF, $FF - - section .text - - public _T_wmemset, _T_wmemcpy, _T_wmemmove, _T_wmemcmp, _T_wmemchr - public _T_wcslen, _T_wcsnlen - -_T_wmemset := _wmemset -_T_wmemcpy := _wmemcpy -_T_wmemmove := _wmemmove -_T_wmemcmp := _wmemcmp -_T_wmemchr := _wmemchr - -_T_wcslen := _wcslen -_T_wcsnlen := _wcsnlen - - extern _wmemset, _wmemcpy, _wmemmove, _wmemcmp, _wmemchr - extern _wcslen, _wcsnlen diff --git a/test/standalone/wide_char/src/rename.s b/test/standalone/wide_char/src/rename.s new file mode 100644 index 000000000..872d672bc --- /dev/null +++ b/test/standalone/wide_char/src/rename.s @@ -0,0 +1,42 @@ + .assume adl=1 + + .section .rodata + + .global _PTR_000000 +_PTR_000000: + db $00, $00, $00 + + .global _PTR_FFFFFF +_PTR_FFFFFF: + db $FF, $FF, $FF + + .global _T_wmemset + .global _T_wmemcpy + .global _T_wmemmove + .global _T_wmemcmp + .global _T_wmemchr + .global _T_wcslen + .global _T_wcsnlen + +_T_wmemset: + jp _wmemset +_T_wmemcpy: + jp _wmemcpy +_T_wmemmove: + jp _wmemmove +_T_wmemcmp: + jp _wmemcmp +_T_wmemchr: + jp _wmemchr +_T_wcslen: + jp _wcslen +_T_wcsnlen: + jp _wcsnlen + + .extern _wmemset + .extern _wmemcpy + .extern _wmemmove + .extern _wmemcmp + .extern _wmemchr + .extern _wcslen + .extern _wcsnlen diff --git a/tools/cedev-config/src/main.c b/tools/cedev-config/src/main.c index 944107a50..5bf006b1b 100644 --- a/tools/cedev-config/src/main.c +++ b/tools/cedev-config/src/main.c @@ -1,3 +1,19 @@ +// Copyright (C) 2015-2025 CE Programming +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + #include #include #include diff --git a/tools/cedev-obj/.gitignore b/tools/cedev-obj/.gitignore new file mode 100644 index 000000000..cd42ee34e --- /dev/null +++ b/tools/cedev-obj/.gitignore @@ -0,0 +1,2 @@ +bin/ +obj/ diff --git a/tools/cedev-obj/Makefile b/tools/cedev-obj/Makefile new file mode 100644 index 000000000..e092bd1cf --- /dev/null +++ b/tools/cedev-obj/Makefile @@ -0,0 +1,68 @@ +# Copyright (C) 2015-2025 CE Programming +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +include $(CURDIR)/../../src/common.mk + +CC = gcc +CFLAGS = -Wall -Wextra -Wshadow -O3 -std=c99 -Isrc -DNDEBUG -DCEDEV_VERSION="\"$(CEDEV_VERSION)\"" -flto +LDFLAGS = -flto +LIBRARIES := + +ifeq ($(OS),Windows_NT) + TARGET ?= cedev-obj.exe + STRIP = strip --strip-all "$1" +else + TARGET ?= cedev-obj + ifeq ($(shell uname -s),Darwin) + STRIP = strip "$1" + CFLAGS += -D_DARWIN_C_SOURCE -mmacosx-version-min=10.13 + LDFLAGS += -mmacosx-version-min=10.13 + else + STRIP = strip --strip-all "$1" + CFLAGS += -D_XOPEN_SOURCE=500 -static + LDFLAGS += -static + LIBRARIES += dl + endif +endif + +BINDIR = ./bin +OBJDIR = ./obj +SRCDIR = ./src +DEPDIR = ./src/deps +SOURCES = \ + $(SRCDIR)/main.c \ + $(SRCDIR)/elf_inspect.c + +OBJECTS = $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o) + +all: $(BINDIR)/$(TARGET) + +release: $(BINDIR)/$(TARGET) + +$(BINDIR)/$(TARGET): $(OBJECTS) + $(Q)$(call MKDIR,$(call NATIVEPATH,$(@D))) + $(Q)$(CC) $(LDFLAGS) $(call NATIVEPATH,$^) -o $(call NATIVEPATH,$@) $(addprefix -l, $(LIBRARIES)) + $(Q)$(call STRIP,$@) + +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(Q)$(call MKDIR,$(call NATIVEPATH,$(@D))) + $(Q)$(CC) -c $(call NATIVEPATH,$<) $(CFLAGS) -o $(call NATIVEPATH,$@) + +clean: + $(Q)$(call RMDIR,$(call NATIVEPATH,$(BINDIR))) + $(Q)$(call RMDIR,$(call NATIVEPATH,$(OBJDIR))) + +.PHONY: all release test clean diff --git a/tools/cedev-obj/src/elf_inspect.c b/tools/cedev-obj/src/elf_inspect.c new file mode 100644 index 000000000..4cb313e96 --- /dev/null +++ b/tools/cedev-obj/src/elf_inspect.c @@ -0,0 +1,381 @@ +// Copyright (C) 2015-2025 CE Programming +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#include "elf_inspect.h" + +#include +#include +#include +#include +#include + +/* ELF format definitions (from ELF specification) */ +#define EI_NIDENT 16 +#define EI_CLASS 4 +#define ELFCLASS32 1 + +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 + +/* ELF32 structures */ +struct elf32_ehdr +{ + uint8_t e_ident[EI_NIDENT]; + uint16_t e_type; + uint16_t e_machine; + uint32_t e_version; + uint32_t e_entry; + uint32_t e_phoff; + uint32_t e_shoff; + uint32_t e_flags; + uint16_t e_ehsize; + uint16_t e_phentsize; + uint16_t e_phnum; + uint16_t e_shentsize; + uint16_t e_shnum; + uint16_t e_shstrndx; +}; + +struct elf32_shdr +{ + uint32_t sh_name; + uint32_t sh_type; + uint32_t sh_flags; + uint32_t sh_addr; + uint32_t sh_offset; + uint32_t sh_size; + uint32_t sh_link; + uint32_t sh_info; + uint32_t sh_addralign; + uint32_t sh_entsize; +}; + +struct elf32_sym +{ + uint32_t st_name; + uint32_t st_value; + uint32_t st_size; + uint8_t st_info; + uint8_t st_other; + uint16_t st_shndx; +}; + +/* Internal ELF file structure */ +struct elf_file +{ + FILE *fp; + char error[256]; + + /* ELF header */ + struct elf32_ehdr ehdr; + + /* Section headers */ + struct elf32_shdr *section_headers; + + /* String tables */ + char *shstrtab; + size_t shstrtab_size; + char *strtab; + size_t strtab_size; + + /* Symbol table */ + struct elf32_sym *symtab; + size_t symtab_count; +}; + +static void set_error(struct elf_file *elf, const char *msg) +{ + snprintf(elf->error, sizeof(elf->error), "%s", msg); +} + +static bool read_at(FILE *fp, void *buf, size_t size, long offset) +{ + if (fseek(fp, offset, SEEK_SET) != 0) + { + return false; + } + + return fread(buf, 1, size, fp) == size; +} + +static bool parse_elf_header(struct elf_file *elf) +{ + if (!read_at(elf->fp, &elf->ehdr, sizeof(elf->ehdr), 0)) + { + set_error(elf, "Failed to read ELF header"); + return false; + } + + /* Check ELF magic number */ + if (memcmp(elf->ehdr.e_ident, "\177ELF", 4) != 0) + { + set_error(elf, "Not an ELF file"); + return false; + } + + /* Check for 32-bit */ + if (elf->ehdr.e_ident[EI_CLASS] != ELFCLASS32) + { + set_error(elf, "Only 32-bit ELF supported"); + return false; + } + + return true; +} + +static bool load_section_headers(struct elf_file *elf) +{ + size_t shdr_table_size = elf->ehdr.e_shnum * elf->ehdr.e_shentsize; + + elf->section_headers = malloc(shdr_table_size); + if (!elf->section_headers) + { + set_error(elf, "Failed to allocate section headers"); + return false; + } + + if (!read_at(elf->fp, elf->section_headers, shdr_table_size, elf->ehdr.e_shoff)) + { + set_error(elf, "Failed to read section headers"); + return false; + } + + return true; +} + +static bool load_string_table(struct elf_file *elf, uint32_t shdr_idx, char **strtab, size_t *size) +{ + if (shdr_idx >= elf->ehdr.e_shnum) + { + set_error(elf, "Invalid section index"); + return false; + } + + struct elf32_shdr *shdr = &elf->section_headers[shdr_idx]; + + *strtab = malloc(shdr->sh_size); + if (!*strtab) + { + set_error(elf, "Failed to allocate string table"); + return false; + } + + if (!read_at(elf->fp, *strtab, shdr->sh_size, shdr->sh_offset)) + { + set_error(elf, "Failed to read string table"); + free(*strtab); + *strtab = NULL; + return false; + } + + *size = shdr->sh_size; + return true; +} + +static bool load_symbol_table(struct elf_file *elf) +{ + /* Find .symtab section */ + struct elf32_shdr *symtab_shdr = NULL; + + for (uint16_t i = 0; i < elf->ehdr.e_shnum; i++) + { + if (elf->section_headers[i].sh_type == SHT_SYMTAB) + { + symtab_shdr = &elf->section_headers[i]; + break; + } + } + + if (!symtab_shdr) + { + set_error(elf, "No symbol table found"); + return false; + } + + /* Load symbol table */ + elf->symtab_count = symtab_shdr->sh_size / sizeof(struct elf32_sym); + elf->symtab = malloc(symtab_shdr->sh_size); + if (!elf->symtab) + { + set_error(elf, "Failed to allocate symbol table"); + return false; + } + + if (!read_at(elf->fp, elf->symtab, symtab_shdr->sh_size, symtab_shdr->sh_offset)) + { + set_error(elf, "Failed to read symbol table"); + return false; + } + + /* Load associated string table */ + if (!load_string_table(elf, symtab_shdr->sh_link, &elf->strtab, &elf->strtab_size)) + { + return false; + } + + return true; +} + +struct elf_file *elf_open(const char *filename) +{ + struct elf_file *elf = calloc(1, sizeof(struct elf_file)); + if (!elf) + { + return NULL; + } + + elf->fp = fopen(filename, "rb"); + if (!elf->fp) + { + set_error(elf, "Failed to open file"); + free(elf); + return NULL; + } + + if (!parse_elf_header(elf)) + { + elf_close(elf); + return NULL; + } + + if (!load_section_headers(elf)) + { + elf_close(elf); + return NULL; + } + + /* Load section header string table */ + if (!load_string_table(elf, elf->ehdr.e_shstrndx, &elf->shstrtab, &elf->shstrtab_size)) + { + elf_close(elf); + return NULL; + } + + if (!load_symbol_table(elf)) + { + elf_close(elf); + return NULL; + } + + return elf; +} + +void elf_close(struct elf_file *elf) +{ + if (!elf) + { + return; + } + + if (elf->fp) + { + fclose(elf->fp); + } + + if (elf->section_headers) + { + free(elf->section_headers); + } + + if (elf->shstrtab) + { + free(elf->shstrtab); + } + + if (elf->strtab) + { + free(elf->strtab); + } + + if (elf->symtab) + { + free(elf->symtab); + } + + free(elf); +} + +bool elf_has_symbol(struct elf_file *elf, const char *symbol_name) +{ + if (!elf || !symbol_name) + { + return false; + } + + for (size_t i = 0; i < elf->symtab_count; i++) + { + if (elf->symtab[i].st_name < elf->strtab_size) + { + const char *name = elf->strtab + elf->symtab[i].st_name; + if (strcmp(name, symbol_name) == 0) + { + return true; + } + } + } + + return false; +} + +bool elf_has_defined_symbol(struct elf_file *elf, const char *symbol_name) +{ + if (!elf || !symbol_name) + { + return false; + } + + for (size_t i = 0; i < elf->symtab_count; i++) + { + if (elf->symtab[i].st_name < elf->strtab_size) + { + const char *name = elf->strtab + elf->symtab[i].st_name; + if (strcmp(name, symbol_name) == 0) + { + return elf->symtab[i].st_shndx != 0; + } + } + } + + return false; +} + +bool elf_has_section(struct elf_file *elf, const char *section_name) +{ + if (!elf || !section_name) + { + return false; + } + + for (uint16_t i = 0; i < elf->ehdr.e_shnum; i++) + { + if (elf->section_headers[i].sh_name < elf->shstrtab_size) + { + const char *name = elf->shstrtab + elf->section_headers[i].sh_name; + if (strcmp(name, section_name) == 0) + { + /* Section exists - check if it's non-empty */ + return elf->section_headers[i].sh_size > 0; + } + } + } + + return false; +} + +const char *elf_get_error(struct elf_file *elf) +{ + return elf ? elf->error : "Invalid ELF handle"; +} diff --git a/tools/cedev-obj/src/elf_inspect.h b/tools/cedev-obj/src/elf_inspect.h new file mode 100644 index 000000000..ec169c00d --- /dev/null +++ b/tools/cedev-obj/src/elf_inspect.h @@ -0,0 +1,52 @@ +// Copyright (C) 2015-2025 CE Programming +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#ifndef ELF_INSPECT_H +#define ELF_INSPECT_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Opaque handle for ELF file */ +struct elf_file; + +/* Open an ELF file for inspection */ +struct elf_file *elf_open(const char *filename); + +/* Close and free resources */ +void elf_close(struct elf_file *elf); + +/* Check if a symbol exists by name */ +bool elf_has_symbol(struct elf_file *elf, const char *symbol_name); + +/* Check if a symbol exists by name and is defined */ +bool elf_has_defined_symbol(struct elf_file *elf, const char *symbol_name); + +/* Check if a section exists and is non-empty */ +bool elf_has_section(struct elf_file *elf, const char *section_name); + +/* Get last error message (valid until next call or elf_close) */ +const char *elf_get_error(struct elf_file *elf); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tools/cedev-obj/src/main.c b/tools/cedev-obj/src/main.c new file mode 100644 index 000000000..e47980d74 --- /dev/null +++ b/tools/cedev-obj/src/main.c @@ -0,0 +1,265 @@ +// Copyright (C) 2015-2025 CE Programming +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program; if not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +#include "elf_inspect.h" +#include +#include +#include +#include + +#define MAX_WORD_LEN 1024 +#define MAX_FMT "1023" + +typedef struct { + char *elf_file; + char *output_file; + int optional_libs_start; + int optional_libs_end; + int lib_files_start; + int lib_files_end; +} options_t; + +static void print_usage(const char *prog) +{ + fprintf(stderr, "Usage: %s --elf -o|--output " + "[--libs lib_file1 lib_file2 ...] [--optional-libs LIB1 LIB2 ...]\n", prog); +} + +static bool is_flag(const char *arg) +{ + return arg[0] == '-'; +} + +static bool is_optional_lib(const char *lib_name, char **argv, int start, int end) +{ + if (start == -1 || end == -1) + return false; + + for (int i = start; i < end; i++) + { + if (strcmp(lib_name, argv[i]) == 0) + return true; + } + return false; +} + +static bool parse_arguments(int argc, char **argv, options_t *opts) +{ + memset(opts, 0, sizeof(*opts)); + opts->optional_libs_start = -1; + opts->optional_libs_end = -1; + opts->lib_files_start = -1; + opts->lib_files_end = -1; + + for (int i = 1; i < argc; i++) + { + if (strcmp(argv[i], "--optional-libs") == 0) + { + opts->optional_libs_start = i + 1; + for (i++; i < argc && !is_flag(argv[i]); i++) + ; + opts->optional_libs_end = i; + i--; + } + else if (strcmp(argv[i], "--elf") == 0) + { + if (++i >= argc) + { + fprintf(stderr, "Error: --elf requires an argument\n"); + return false; + } + opts->elf_file = argv[i]; + } + else if (strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--output") == 0) + { + if (++i >= argc) + { + fprintf(stderr, "Error: %s requires an argument\n", argv[i-1]); + return false; + } + opts->output_file = argv[i]; + } + else if (strcmp(argv[i], "--libs") == 0) + { + opts->lib_files_start = i + 1; + for (i++; i < argc && !is_flag(argv[i]); i++) + ; + opts->lib_files_end = i; + i--; + } + else + { + fprintf(stderr, "Error: Unknown option '%s'\n", argv[i]); + return false; + } + } + + if (!opts->elf_file || !opts->output_file) + { + fprintf(stderr, "Error: Missing required arguments\n"); + return false; + } + + return true; +} + +static void write_header_defines(FILE *out, const char *elf_file, struct elf_file *elf) +{ + fprintf(out, "/* generated from: %s */\n", elf_file); + fprintf(out, "#define HAS_INIT_ARRAY %d\n", elf_has_section(elf, ".init_array") ? 1 : 0); + fprintf(out, "#define HAS_FINI_ARRAY %d\n", elf_has_section(elf, ".fini_array") ? 1 : 0); + fprintf(out, "#define HAS_CLOCK %d\n", elf_has_symbol(elf, "_clock") ? 1 : 0); + fprintf(out, "#define HAS_ABORT %d\n", elf_has_symbol(elf, "_abort") ? 1 : 0); + fprintf(out, "#define HAS_RUN_PRGM %d\n", elf_has_symbol(elf, "_os_RunPrgm") ? 1 : 0); + fprintf(out, "#define HAS_MAIN_ARGC_ARGV %d\n", elf_has_defined_symbol(elf, "___main_argc_argv") ? 1 : 0); + fprintf(out, "#define HAS_ATEXIT %d\n", elf_has_symbol(elf, "__atexit_functions") ? 1 : 0); +} + +static bool process_library_file(FILE *out, struct elf_file *elf, const char *lib_file, + char **argv, int optional_start, int optional_end) +{ + FILE *lib = fopen(lib_file, "r"); + if (!lib) + { + fprintf(stderr, "Error: Failed to open library file '%s'\n", lib_file); + return false; + } + + char word[MAX_WORD_LEN]; + char lib_name[MAX_WORD_LEN] = ""; + int lib_version = 0; + int export_index = 0; + bool lib_header_written = false; + bool lib_needed = false; + + while (fscanf(lib, "%" MAX_FMT "s", word) == 1) + { + if (strcmp(word, "library") == 0) + { + if (fscanf(lib, " %" MAX_FMT "[^,], %d", lib_name, &lib_version) != 2) + { + fprintf(stderr, "Error: Failed to parse library line in '%s'\n", lib_file); + fclose(lib); + return false; + } + + /* Check if library is explicitly requested via __libload_library_NAME */ + char libload_symbol[MAX_WORD_LEN + 20]; + snprintf(libload_symbol, sizeof(libload_symbol), "__libload_library_%s", lib_name); + lib_needed = elf_has_symbol(elf, libload_symbol); + } + else if (strcmp(word, "export") == 0) + { + char export_name[MAX_WORD_LEN]; + if (fscanf(lib, "%" MAX_FMT "s", export_name) != 1) + { + fprintf(stderr, "Error: Failed to parse export line in '%s'\n", lib_file); + fclose(lib); + return false; + } + + char symbol_name[MAX_WORD_LEN + 1]; + snprintf(symbol_name, sizeof(symbol_name), "_%s", export_name); + bool symbol_referenced = elf_has_symbol(elf, symbol_name); + + if (symbol_referenced || lib_needed) + { + if (!lib_header_written) + { + bool optional = is_optional_lib(lib_name, argv, optional_start, optional_end); + fprintf(out, "\t.global __libload_library_%s\n", lib_name); + fprintf(out, "\t.type __libload_library_%s, @object\n", lib_name); + fprintf(out, "__libload_library_%s:\n", lib_name); + fprintf(out, "\t.db 0x%s, \"%s\", 0, %d\n", + optional ? "C1" : "C0", lib_name, lib_version); + lib_header_written = true; + } + + if (symbol_referenced) + { + fprintf(out, "\t.global %s\n", symbol_name); + fprintf(out, "\t.type %s, @function\n", symbol_name); + fprintf(out, "%s:\n", symbol_name); + fprintf(out, "\tjp %d\n", export_index * 3); + } + } + export_index++; + } + } + + fclose(lib); + return lib_header_written; +} + +static bool process_libraries(FILE *out, struct elf_file *elf, char **argv, + int lib_start, int lib_end, int opt_start, int opt_end) +{ + bool has_libload = false; + + fprintf(out, "#ifdef __ASSEMBLER__\n"); + fprintf(out, ".macro LIBLOAD_LIBS\n"); + + if (lib_start != -1 && lib_end != -1) + { + for (int i = lib_start; i < lib_end; i++) + { + if (process_library_file(out, elf, argv[i], argv, opt_start, opt_end)) + has_libload = true; + } + } + + fprintf(out, ".endm\n"); + fprintf(out, "#endif\n"); + fprintf(out, "#define HAS_LIBLOAD %d\n", has_libload); + + return true; +} + +int main(int argc, char **argv) +{ + options_t opts; + + if (!parse_arguments(argc, argv, &opts)) + { + print_usage(argv[0]); + return 1; + } + + struct elf_file *elf = elf_open(opts.elf_file); + if (!elf) + { + fprintf(stderr, "Error: Failed to open ELF file '%s'\n", opts.elf_file); + return 1; + } + + FILE *out = fopen(opts.output_file, "w"); + if (!out) + { + fprintf(stderr, "Error: Failed to open output file '%s'\n", opts.output_file); + elf_close(elf); + return 1; + } + + write_header_defines(out, opts.elf_file, elf); + + bool success = process_libraries(out, elf, argv, + opts.lib_files_start, opts.lib_files_end, + opts.optional_libs_start, opts.optional_libs_end); + + fclose(out); + elf_close(elf); + return success ? 0 : 1; +} diff --git a/tools/convbin b/tools/convbin index eb5a0c0d1..a94dd4c30 160000 --- a/tools/convbin +++ b/tools/convbin @@ -1 +1 @@ -Subproject commit eb5a0c0d14e4e6bd27d3a0b3bb338bc010dc71e3 +Subproject commit a94dd4c30291b9762033431833cc8a1f3cef8227 diff --git a/tools/convimg b/tools/convimg index 4a7dcfe9e..b37b631a0 160000 --- a/tools/convimg +++ b/tools/convimg @@ -1 +1 @@ -Subproject commit 4a7dcfe9e51f3e3c3af9b37cde761bbb14c17a9b +Subproject commit b37b631a00d74eaa7180dc9a1dce8acfec836f60