Commit Graph

401 Commits

Author SHA1 Message Date
Jan (janneke) Nieuwenhuizen 8194ecfc0f
mescc: Mes C Library: Prepare for M2-Planet: strcpy.
* lib/string/strcpy.c: Rewrite C-constructs not supported by M2-Planet.
2020-05-17 19:29:57 +02:00
Jan (janneke) Nieuwenhuizen c117abe06a
mescc: Mes C Library: Prepare for M2-Planet: strcmp.
* lib/string/strcmp.c: Rewrite C-constructs not supported by M2-Planet.
2020-05-17 19:29:44 +02:00
Jan (janneke) Nieuwenhuizen 0ca159041d
mescc: Mes C Library: Prepare for M2-Planet: __assert_fail.
Rewrite C-constructs not supported by M2-Planet, such as

    foo ? bar : baz;       -> if (foo) bar; else baz;
    static char foo[1024]  -> __func_buf = malloc (1024); ... char *foo = __func_buf;
    *foo                   -> foo[0]
    foo++                  -> foo = foo + 1   TODO: pointer arithmetic
    foo += 1;              -> foo = foo + 1
    for (int foo = ;       -> int foo; for (foo=
    if (foo)               -> if (foo != 0)
    if (!foo)              -> if (foo == 0)
    ;                      -> 0;

* lib/mes/__assert_fail.c: Rewrite C-constructs not supported by
M2-Planet.
2020-05-17 19:27:27 +02:00
Jan (janneke) Nieuwenhuizen cf22ba44ce
mescc: Mes C Library: Add assert_msg.
* lib/mes/assert_msg.c: New file.
2020-04-19 15:57:06 +02:00
W. J. van der Laan be4514c4de
lib/tests: Pass int to va_arg instead of char.
* lib/tests/scaffold/70-stdarg.c (stdarg1, stdarg2, stdarg3): Pass int
to va_arg instead of char to avoid gcc trap "warning: 'char’ is promoted
to ‘int’ when passed through ‘...’ [enabled by default] (so you should
pass ‘int’ not ‘char’ to ‘va_arg’) if this code is reached, the program
will abort".
2021-05-02 16:56:29 +02:00
Jan (janneke) Nieuwenhuizen 6c1ff75c5a
mescc: Mes C Library: crt: Support more than 255 command line parameters.
Reported by Paul Dersey <pdersey@gmail.com>.

* lib/freebsd/x86-mes-gcc/crt1.c (_start): Use mov instead of movzbl for
argc.
* lib/linux/x86-mes-gcc/crt0.c (_start): Likewise.
* lib/linux/x86-mes-gcc/crt1.c (_start): Likewise.
* lib/freebsd/x86-mes-mescc/crt1.c (_start): Likewise.
* lib/linux/x86-mes-mescc/crt1.c (_start): Likewise.
2021-05-02 14:22:21 +02:00
Jan (janneke) Nieuwenhuizen dfa8e6e9d5
mescc: Mes C Library: malloc.c: Move unix-variant to lib/linux.
* lib/stdlib/malloc.c: Move to...
lib/linux/malloc.c: ...here.
* build-aux/configure-lib.sh (libc_SOURCES): Move malloc.c...
[linux]: ...here.
2021-05-02 13:13:13 +02:00
Danny Milosavljevic 2e9b02043b
libtcc1: Fix integer division, modulo and shifting procedures.
* lib/libtcc1.c (__divdi3): Make parameters integer.
(__moddi3): Make parameters integer.
(__udivdi3): Use unsigned division.
(__umoddi3): Use unsigned modulo.
(__lshrdi3): Add comment.
(__ashrdi3): Add comment.
2021-03-14 11:05:00 +01:00
Danny Milosavljevic 27b06c6ddb
mescc: Mes C Library: Make malloc align the blocks it gives out.
* include/stddef.h (max_align_t): Add typedef for max_align_t.
* lib/stdlib/malloc.c (malloc): Align the blocks it gives out to multiples
of max_align_t.
2021-01-23 08:43:48 +01:00
Jan (janneke) Nieuwenhuizen 381e8bd6e0
mescc: Mes C Library: feof: Bugfix for ARM.
* lib/stdio/feof.c (feof): Use int to compare with EOF.
2021-01-23 08:43:47 +01:00
Jan (janneke) Nieuwenhuizen 7ab9cfe864
mescc: Mes C Library: time.c: Use #if defined.
This helps resurrect the mes-0.19-based bootstrap.

* lib/linux/time.c: Use #if defined () instead of plain #if for possibly
undefined macros.
2021-01-23 08:43:47 +01:00
Jan (janneke) Nieuwenhuizen 3115261f2f
libtcc1: Compile float stubs conditionally.
* lib/libtcc1.c (__floatundidf, __floatundixf, __fixunsxfdi, __fixxfdi,
__fixsfdi, __fixunsdfdi, __fixunsdfsi, __floatdisf,
__floatdidf)[!(HAVE_FLOAT_STUB || HAVE_FLOAT)]: Remove.
2021-01-23 08:43:47 +01:00
Jan (janneke) Nieuwenhuizen d9226ca678
libtcc1: Make float stubs weak.
* lib/libtcc1.c (__floatundidf, __floatundixf, __fixunsxfdi, __fixxfdi,
__fixsfdi, __fixunsdfdi, __fixunsdfsi, __floatdisf, __floatdidf): Add
__attribute__ ((weak)).
2021-01-23 08:43:47 +01:00
Jan (janneke) Nieuwenhuizen b7dff2c2a4
mescc: Mes C Library: ARM: setjmp.c: Inline fake asm.
* lib/linux/arm-mes-gcc/_exit.c (longjmp, setjmp): Use inline fake asm.
2021-01-23 08:43:46 +01:00
Jan (janneke) Nieuwenhuizen 6703c33f96
mescc: Mes C Library: ARM: syscall.c: Inline fake asm.
* lib/linux/arm-mes-gcc/syscall.c (__sys_call, __sys_call1, __sys_call2,
__sys_call3, __sys_call4): Use inline fake asm.
2021-01-23 08:43:46 +01:00
Jan (janneke) Nieuwenhuizen e5ce69ec3f
mescc: Mes C Library: ARM: _write.c: Inline fake asm.
* lib/linux/arm-mes-gcc/_write.c (_write): Use inline fake asm.
2021-01-23 08:43:46 +01:00
Jan (janneke) Nieuwenhuizen 0667d1aa25
mescc: Mes C Library: ARM: _exit: Inline fake asm.
* lib/linux/arm-mes-gcc/_exit.c (_exit): Use inline fake asm.
2021-01-23 08:43:46 +01:00
Jan (janneke) Nieuwenhuizen 4e7a6057aa
mescc: Mes C Library: ARM: _start: Inline fake asm.
* lib/linux/arm-mes-gcc/crt1.c (_start): Use inline fake asm.
2021-01-23 08:43:46 +01:00
Jan (janneke) Nieuwenhuizen 9711ed70ec
tests: Add 70-or-argument.c.
* lib/tests/scaffold/70-or-argument.c: New file.
* build-aux/check-mescc.sh (tcc_tests): Add it.
2021-01-23 08:43:46 +01:00
Jan (janneke) Nieuwenhuizen b531c73590
tests: Add 70-function-modulo.c.
* lib/tests/scaffold/70-function-modulo.c: New file.
* build-aux/check-mescc.sh (tcc_tests): Add it.
2021-01-23 08:43:45 +01:00
Jan (janneke) Nieuwenhuizen 4b194d7bc7
tests: 70-strchr.c: Rewrite for TinyCC.
* lib/tests/string/70-strchr.c (main): Use char* hello for comparison.
Allows for duplication of "hello" string.
2021-01-23 08:43:45 +01:00
Jan (janneke) Nieuwenhuizen bdb1e2ec56
test: scaffold/54-argv.c: Support running with TinyCC.
This fixes running as lib/tests/scaffold/54-argv-i686-unknown-linux-gnu-tcc.

* lib/tests/scaffold/54-argv.c (main): Compare only first 26 characters
of argv[0].
2021-01-23 08:43:45 +01:00
Jan (janneke) Nieuwenhuizen 905277a73a
mescc: Mes C Library: Split _exit.c, _write.c from mini.c.
* lib/freebsd/x86-mes-gcc/mini.c: Split into...
* lib/freebsd/x86-mes-gcc/_exit.c: ...this, and...
* lib/freebsd/x86-mes-gcc/_write.c: ...this.
* lib/freebsd/x86-mes-mescc/mini.c: Slpit into...
* lib/freebsd/x86-mes-mescc/_exit.c: ...this, and...
* lib/freebsd/x86-mes-mescc/_write.c: ...this.
* lib/gnu/x86-mes-gcc/mini.c: Split into...
* lib/gnu/x86-mes-gcc/_exit.c: ...this, and...
* lib/gnu/x86-mes-gcc/_write.c: ...this.
* lib/linux/arm-mes-gcc/mini.c: Split into...
* lib/linux/arm-mes-gcc/_exit.c: ...this, and...
* lib/linux/arm-mes-gcc/_write.c: ...this.
* lib/linux/arm-mes-mescc/mini.c: Split into...
* lib/linux/arm-mes-mescc/_exit.c: ...this, and...
* lib/linux/arm-mes-mescc/_write.c: ...this.
* build-aux/configure-lib.sh (libc_mini_shared_SOURCES): Replace mini.c
with add _exit.c, _write.c.
* simple.sh: Update accordingly.
2021-01-23 08:43:45 +01:00
Jan (janneke) Nieuwenhuizen 4f66055f3b
ARM: Add fake asm for setjmp.c.
* lib/arm-mes-gcc/setjmp.c (longjmp, setjmp)[__TINYC__]: Add fake asm.
2021-01-23 08:43:44 +01:00
Jan (janneke) Nieuwenhuizen e5573ec23c
ARM: Add fake asm for syscall.c.
* lib/linux/arm-mes-gcc/syscall.c (__sys_call, __sys_call1, __sys_call2,
__sys_call3, __sys_call4) [__TINYC__]: Add fake asm.
2021-01-23 08:43:44 +01:00
Jan (janneke) Nieuwenhuizen 40f270f3d7
ARM: Add fake asm for mini.c.
* lib/linux/arm-mes-gcc/mini.c (_exit, _write)[__TINYC__]: Add fake asm.
2021-01-23 08:43:44 +01:00
Jan (janneke) Nieuwenhuizen 420d422e34
ARM: Add fake asm for crt1.c.
* lib/linux/arm-mes-gcc/crt1.c (_start)[__TINYC__]: Use fake asm.
2021-01-23 08:43:44 +01:00
Jan (janneke) Nieuwenhuizen ed59c243a8
mescc: Mes C Library: Support ARM tcc: Add crti.c, crtn.c.
* lib/linux/arm-mes-gcc/crti.c: New file.
* lib/linux/arm-mes-gcc/crtn.c: New file.
2021-01-23 08:43:44 +01:00
Jan (janneke) Nieuwenhuizen e82a53a40f
mescc: Mes C Library: Support ARM tcc: Add __memset.
* lib/string/__memset.c: New file.
* include/mes/lib.h (__memset): Add prototype.
2021-01-23 08:43:43 +01:00
Jan (janneke) Nieuwenhuizen 82a2388db2
mescc: Mes C Library: Support ARM tcc: Add __memmove.
* lib/string/__memmove.c: New file.
* include/mes/lib.h (__memmove): Add prototype.
2021-01-23 08:43:43 +01:00
Jan (janneke) Nieuwenhuizen bebb8dabfb
mescc: Mes C Library: Support ARM tcc: Add __memcpy.
* lib/string/__memcpy.c: New file.
* include/mes/lib.h (__memcpy): Add prototype.
2021-01-23 08:43:43 +01:00
Jan (janneke) Nieuwenhuizen 6a9e9838f0
mescc: Mes C Library: abort: Avoid __raise for TinyCC.
* lib/stdlib/abort.c: Use "raise" instead of __raise.
2021-01-23 08:43:43 +01:00
Jan (janneke) Nieuwenhuizen 98965c8807
test: Split-off scaffold/60-math-itoa.c.
* lib/tests/scaffold/60-math.c (main): Move itoa tests to...
* lib/tests/scaffold/60-math-itoa.c: ...this new file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2021-01-23 08:43:43 +01:00
Jan (janneke) Nieuwenhuizen af2353dd23
test: Split-off 36-compare-arithmetic-negative.c.
* lib/tests/scaffold/36-compare-arithmetic.c (main): Move negative
divisions to...
* lib/tests/scaffold/36-compare-arithmetic-negative.c: ...new file here.
* build-aux/check-mescc.sh (mes_tests): Add it.
2021-01-23 08:43:43 +01:00
Jan (janneke) Nieuwenhuizen cd6131bc21
test: ARM: 08-assign.c: Avoid assembly for tcc.
* lib/tests/scaffold/08-assign.c (main)[__arm__ && __TINYC__]: Avoid assembly.
2021-01-23 08:43:42 +01:00
Jan (janneke) Nieuwenhuizen 691d25699c
test: Split-off 50-strcmp-itoa.c
* lib/tests/string/50-strcmp.c (main): Move itoa tests to...
* lib/tests/string/50-strcmp-itoa.c: ...this new file.
* build-aux/check-mescc.sh (mes_tests): Add it.
2021-01-23 08:43:42 +01:00
Jan (janneke) Nieuwenhuizen 4a9d7a1f33
ARM: libtcc1: Add __divsi3, __modsi3, __udivsi3, __umodsi3.
* lib/libtcc1.c (__divsi3, __modsi3, __udivsi3, __umodsi3): New functions.
2021-01-23 08:43:42 +01:00
Jan (janneke) Nieuwenhuizen 04afe3e238
ARM: libtcc1: Add stubs __floatundidf, __fixunsdfdi, __fixunsdfsi.
* lib/libtcc1.c (__floatdisf, __floatdidf)[__arm__]: New stubs.
2021-01-23 08:43:42 +01:00
Jan (janneke) Nieuwenhuizen e07e731dfd
libtcc1: Add stubs __floatundidf, __fixunsdfdi, __fixunsdfsi.
* lib/libtcc1.c (__floatundidf, __fixunsdfdi, __fixunsdfsi): New stubs.
2021-01-23 08:43:42 +01:00
Jan (janneke) Nieuwenhuizen 8c53e22434
ARM: libtcc1: Add support for TinyCC.
* lib/libtcc1.c: (__udivdi3, __umoddi3, __lshrdi3, __ashldi3,
__fixunsxfdi)[__arm__ && __TINYC__]: Use __mesabi functions.
2021-01-23 08:43:42 +01:00
Jan (janneke) Nieuwenhuizen 553539ad75
libtcc1: Remove mesabi dependencies for TinyCC.
* lib/libtcc1.c (__divdi3, __moddi3, __udivdi3, __umoddi3, __lshrdi3,
__ashldi3, __ashrdi3, __floatundixf, __fixunsxfdi, __fixxfdi,
__fixsfdi)[__TINYC__]: No stub printing.
2021-01-23 08:43:41 +01:00
Jan (janneke) Nieuwenhuizen ddd8349827
mescc: Mes C Library: div: Avoid __raise for TinyCC.
* lib/mes/div.c (__raise)[__TINYC__]: New macro.
2021-01-23 08:43:41 +01:00
Jan (janneke) Nieuwenhuizen ede49daabb
mescc: Mes C Library: Add __mesabi_umod, __mesabi_udiv.
* lib/mes/div.c (__mesabi_umod, __mesabi_udiv): New functions.
* include/mes/lib.h: Add prototypes.
2021-01-23 08:43:41 +01:00
Danny Milosavljevic c1dcdc5d7e
ARM: Implement long division.
* lib/mes/div.c (__mesabi_log2i): New procedure.
(__mesabi_uldiv1): New procedure.
(__mesabi_uldiv): Use it.

Co-Authored-By: Nathalie Kopaczewski <natkopa@gmail.com>
2021-01-23 08:43:41 +01:00
Jan (janneke) Nieuwenhuizen 13b69f4b9b
tests: Add 70-ternary-arithmetic-argument.c.
* lib/tests/scaffold/70-ternary-arithmetic-argument.c: New file.
* build-aux/check-mescc.sh (tcc_tests, xfail_tests): Add it.
2021-01-23 08:43:41 +01:00
Danny Milosavljevic 10bcb3709b
ARM: Speed up __mesabi_uldiv for powers-of-two divisors.
* lib/mes/div.c (__mesabi_uldiv): Speed up division for powers-of-two
divisors.
2021-01-23 08:43:41 +01:00
Paul Dersey 4492173466
Mes C Library: stdlib/qsort.c: Fix qswap segfault.
* stdlib/qsort.c (qswap): Remove hard coded buffer size.  Allow
swapping of objects of arbitrary size.
2021-01-23 08:43:05 +01:00
Jan (janneke) Nieuwenhuizen b601eb64af
mescc: Mes C Library: ntoab: Use unsigned base.
This fixes 60-math, 60-math-itoa, 70-printf-simple, 70-printf.

* lib/mes/ntoab.c (ntoab): Use unsigned base.
* include/mes/lib.h: Update prototype.
2020-12-13 22:19:06 +01:00
Jan (janneke) Nieuwenhuizen fa4147a284
mescc: Use signed division for x86, x86_64 when appropriate.
This fixes 36-compare-arithmetic.c

* module/mescc/i386/as.scm (i386:r0/r1, i386:r0%r1): Do not reset
signed?.
* module/mescc/x86_64/as.scm (x86_64:r0/r1, x86_64:r0%r1): Likewise.
* lib/tests/scaffold/36-compare-arithmetic.c (main): Use unique exit
value per failure.
2020-10-06 19:53:02 +02:00
Jan (janneke) Nieuwenhuizen 84ff05a839
mescc: Mes C Library: Support gcc-10.
See <https://lists.gnu.org/archive/html/bug-mes/2020-07/msg00000.html>.

Reported by Vagrant Cascadian <vagrant@reproducible-builds.org>.

* include/setjmp.h (jmp_buf): Remove.
* include/errno.h (errno): Mark extern.
* include/mes/lib-mini.h (environ, errno, __stdin, __stdout, __stderr):
Likewise.
* lib/mes/globals.c: New file; define them.
* build-aux/configure-lib.sh (libc_mini_shared_SOURCES,
libmescc_SOURCES): Add it.
* build-aux/test-c.sh: Always use -l c-mini as a minimum.
2020-10-06 13:13:44 +02:00
Jan (janneke) Nieuwenhuizen 0650e08744
mescc: Mes C Library: x86_64: Add syscall-internal.
This resurrects the x86_64 build.

* lib/linux/x86_64-mes-gcc/syscall-internal.c (__sys_call_internal),
lib/linux/x86_64-mes-mescc/syscall-internal.c: New file.
2020-10-06 10:05:33 +02:00
Jan (janneke) Nieuwenhuizen e16d1e469a
mescc: Mes C Library: x86_64: Introduce __sys_call and friends.
This prepares for x86_64 syscall-internal.

* lib/linux/x86_64-mes-gcc/syscall.c (__sys_call, __sys_call1,
__sys_call2, __sys_call3, __sys_call4): New functions, copied from ...
(_sys_call, _sys_call1, _sys_call2, _sys_call3, _sys_call4): ... these.
Use them, handle errno only.
2020-10-06 10:05:33 +02:00
Jan (janneke) Nieuwenhuizen 1c128c7a9f
mescc: Mes C Library: x86: Use long for syscalls.
The Linux signature uses long, also this allows for making
_sys_call and friends architecture-independent.

* lib/linux/x86-mes-mescc/syscall-internal.c (__sys_call_internal,
__sys_call2_internal): Use long.  Update callers.
* lib/linux/x86-mes-mescc/syscall.c (__sys_call, __sys_call1,
__sys_call2, __sys_call3, __sys_call4, _sys_call, _sys_call1,
_sys_call2, _sys_call3, _sys_call4): Likewise.
2020-10-06 10:05:33 +02:00
Jan (janneke) Nieuwenhuizen 5f8a424328
mescc: Mes C Library: Remove redundant prototypes.
* lib/linux/x86-mes-gcc/syscall.c(__sys_call, __sys_call1, __sys_call2,
__sys_call3, __sys_call4): Remove prototype.
2020-10-06 10:05:33 +02:00
Jan (janneke) Nieuwenhuizen c11a721c36
mescc: Mes C Library: Whitespace fixes.
* lib/linux/signal.c (signal): Whitespace fixes.
* lib/linux/time.c (time): Likewise.
2020-10-06 10:04:42 +02:00
Danny Milosavljevic afac5847e7
div: Remove libgcc-compatible API.
* lib/mes/div.c (__aeabi_idiv): Delete procedure.
(__aeabi_idivmod): Delete procedure.
(__aeabi_uidivmod): Delete procedure.
(__aeabi_uidiv): Delete procedure.
2020-10-06 10:04:29 +02:00
Danny Milosavljevic 9db916bba1
Revert syscall split (of commit 55d38162be);
just copy the two syscalls I need for __raise instead.

* lib/linux/arm-mes-gcc/syscall-internal.c (__sys_call_internal): New procedure.
(__sys_call2_internal): New procedure.
(__raise): Use them.
(__sys_call, __sys_call2, __sys_call3, __sys_call4, __sys_call6): Move to...
* lib/linux/arm-mes-gcc/syscall.c: ...here.
* lib/linux/arm-mes-mescc/syscall-internal.c (__sys_call_internal): New procedure.
(__sys_call2_internal): New procedure.
(__raise): Use them.
(__sys_call, __sys_call2, __sys_call3, __sys_call4, __sys_call6): Move to...
* lib/linux/arm-mes-mescc/syscall.c: ...here.
* lib/linux/x86-mes-gcc/syscall-internal.c (__sys_call_internal): New procedure.
(__sys_call2_internal): New procedure.
(__raise): Use them.
(__sys_call, __sys_call2, __sys_call3, __sys_call4, __sys_call6): Move to...
* lib/linux/x86-mes-gcc/syscall.c: ...here.
* lib/linux/x86-mes-mescc/syscall-internal.c (__sys_call_internal): New procedure.
(__sys_call2_internal): New procedure.
(__raise): Use them.
(__sys_call, __sys_call2, __sys_call3, __sys_call4, __sys_call6): Move to...
* lib/linux/x86-mes-mescc/syscall.c: ...here.
2020-10-06 10:04:29 +02:00
Danny Milosavljevic 3ed3b51371
div: Add comment about __aeabi_idiv.
* lib/mes/div.c (__aeabi_idiv): Add comment.
2020-10-06 10:04:29 +02:00
Danny Milosavljevic 95c71f3178
div: Move __aeabi_idiv to __GNUC__; introduce __mesabi_idiv.
* lib/mes/div.c (__aeabi_idiv): Move for conditional compilation.
(__mesabi_idiv): New procedure.
* module/mescc/armv4/as.scm (armv4:r0/r1): Use __mesabi_idiv.
2020-10-06 10:04:28 +02:00
Jan (janneke) Nieuwenhuizen 3973e87219
ARM: Add missing instruction.
* lib/arm-mes/arm.M1: Add missing define.
2020-10-06 10:04:28 +02:00
Danny Milosavljevic e3aba5d464
test: Make 7l-struct-any-size-array-simple compatible with default ARM gcc.
* lib/tests/scaffold/7l-struct-any-size-array-simple.c: Make "signed"
explicit in signed char types.
2020-08-22 21:01:45 +02:00
Danny Milosavljevic 7e23d98494
test: Make 7r-sign-extend compatible with default ARM gcc.
* lib/tests/scaffold/7r-sign-extend.c: Make "signed" explicit in
signed char types.
2020-08-22 21:01:36 +02:00
Danny Milosavljevic acf86208ed
ARM: Support comparing 32 bit values.
* lib/arm-mes/arm.M1 (cmp____$i32,%r0): New macro.
(cmp____$i32,%r1): New macro.
(cmp____$i32,%r2): New macro.
2020-06-19 02:45:51 +02:00
Danny Milosavljevic d9bda45853
ARM: Handle signed values in r-byte-mem-add, r-word-mem-add.
* lib/arm-mes/arm.M1 (ldrb___%r0,(%r1)): Delete macro.
(ldrh___%r0,(%r0)): Delete macro.
(ldrsh__%r0,(%r0)): New macro.
(ldrh___%r0,(%r1)): Delete macro.
(ldrsh__%r0,(%r1)): New macro.
(ldrh___%r1,(%r1)): Delete macro.
(ldrsh__%r1,(%r1)): New macro.
(ldrh___%r2,(%r2)): Delete macro.
(ldrsh__%r2,(%r2)): New macro.
(ldrh___%r3,(%r3)): Delete macro.
(ldrsh__%r3,(%r3)): New macro.
(ldrsb__%r0,(%r1)): New macro.
* module/mescc/armv4/as.scm (armv4:r-byte-mem-add): Use ldrsb.
(armv4:r-word-mem-add): Use ldrsh, add____$i32,(%r0).
(armv4:word-mem->r): Use ldrsh.
2020-06-19 02:45:33 +02:00
Danny Milosavljevic 821d1b8fe9
ntoab: Simplify LONG_MIN case.
* lib/mes/ntoab.c (ntoab): Simplify LONG_MIN case.

Co-Authored-By: Nathalie Kopaczewski <natkopa@gmail.com>
2020-06-17 00:21:57 +02:00
Danny Milosavljevic b11510f4da
ntoab: Handle LONG_MIN case.
* lib/mes/ntoab.c (ntoab): Handle LONG_MIN case.
* lib/tests/scaffold/60-math.c (main): Add test for INT_MIN and hex.
2020-06-15 11:26:43 +02:00
Danny Milosavljevic 449f3c7e00
Add ARM gcc scaffold assembly.
* lib/linux/arm-mes-gcc/exit-42.S: New file.
* lib/linux/arm-mes-gcc/hello-mes.S: New file.
2020-06-13 19:44:29 +02:00
Danny Milosavljevic 6478476ed7
Implement setjmp for ARM mescc.
* include/setjmp.h: Add ARM case.
* lib/arm-mes-mescc/setjmp.c: New file.
2020-06-12 23:20:17 +02:00
Danny Milosavljevic 48ecb2f29e
test: Test signed division.
* lib/tests/scaffold/36-compare-arithmetic.c (main): Test signed division.
2020-06-10 17:04:55 +02:00
Danny Milosavljevic 3f03574050
ldiv: Work around missing struct return feature.
* lib/mes/div.c (__mesabi_ldiv): Remove return type.
(__mesabi_imod): Adapt call site.
(__aeabi_idiv): Adapt call site and move it to conditional compilation.
(__aeabi_idivmod): Adapt call site.
2020-06-10 15:46:12 +02:00
Danny Milosavljevic d42f99e6cf
mescc: Mes C Library: Hang at the end if necessary.
* lib/linux/arm-mes-mescc/crt1.c (_start): Hang at the end if necessary.
2020-06-10 13:14:33 +02:00
Danny Milosavljevic 040220acee
Add ARM backend.
* build-aux/build-guile.sh: Add ARM backend.
* lib/arm-mes/arm.M1: New file.
* module/mescc/armv4/as.scm: New file.
* module/mescc/armv4/info.scm: New file.
* module/mescc/mescc.scm: Use it.
* module/mescc/M1.scm (info->M1): Support ARM symbolic instructions,
including little endian instructions.  Align functions.
2020-06-10 13:11:07 +02:00
Jan Nieuwenhuizen 80419817e6
ARM: Mes C Library: Support gcc-sans-libc.
* lib/linux/arm-mes-gcc/crt1.c: New file.
* lib/linux/arm-mes-gcc/mini.c: New file.
* lib/arm-mes-gcc/setjmp.c: New file.

Co-Authored-By: Danny Milosavljevic <dannym@scratchpost.org>
2020-06-04 21:59:30 +02:00
Danny Milosavljevic b0347bf53d
ntoab: Make sure not to get stuck on base 1.
* lib/mes/ntoab.c (ntoab): Make sure not to get stuck on base 1.
2020-06-03 20:56:51 +02:00
Danny Milosavljevic 1f47a76e7a
mescc: Mes C Library: Add crt1, mini.
* lib/linux/arm-mes-mescc/crt1.c: New file.
* lib/linux/arm-mes-mescc/mini.c: New file.
2020-06-03 20:46:41 +02:00
Danny Milosavljevic 85e690ea64
ARM: Mes C Library: Add comment.
* lib/linux/time.c: Add comment.
2020-06-03 11:24:03 +02:00
Jan Nieuwenhuizen be1ff7e625
ARM: Mes C Library: Add compile stub for time.
* lib/linux/time.c (time)[SYS_gettimeofday]: Implement using gettimeofday.
(time)[!SYS_time && !SYS_gettimeofday]: Compile stub.
2020-06-03 10:41:37 +02:00
Danny Milosavljevic a944400112
waitpid: Support ARM.
* lib/linux/waitpid.c (waitpid): Support ARM.
2020-06-03 00:55:07 +02:00
Danny Milosavljevic 65013db594
Add ARM linker support files.
* lib/linux/arm-mes/elf32-0exit-42.hex2,
lib/linux/arm-mes/elf32-0header.hex2,
lib/linux/arm-mes/elf32-0hello-mes.hex2,
lib/linux/arm-mes/elf32-body-exit-42.hex2,
lib/linux/arm-mes/elf32-body-hello-mes.hex2,
lib/linux/arm-mes/elf32-footer-single-main.hex2,
lib/linux/arm-mes/elf32-header.hex2: New files.
2020-06-02 20:27:52 +02:00
Danny Milosavljevic 4775de0021
Raise SIGABRT on abort().
* lib/stdlib/abort.c (abort): Raise SIGABRT.
2020-06-02 15:05:12 +02:00
Danny Milosavljevic 55d38162be
Introduce libmescc.a; Put division by integer in there; split syscalls' errno off.
* build-aux/configure-lib.sh (libmescc_SOURCES): Add lib/mes/div.c,
lib/linux/*/syscall-internal.c.
* build-aux/build-lib.sh: Add libmescc.a.
* build-aux/build-mes.sh: On gcc, add "-lmescc".
* build-aux/test-c.sh: Add "-lmescc".
* build-aux/check.sh.in: Add mescc to LIBS.
* module/mescc/mescc.scm (mescc:link): Add "mescc".
* module/mescc.scm (mescc:main): Update documentation of "-nodefaultlibs"
and "-nostdlib".
* lib/mes/div.c (ldiv): Rename to...
(__mesabi_ldiv): ...this.  Avoid assert.
(__mesabi_div0): Avoid assert.
(__aeabi_idivmod): New procedure.
(__aeabi_idiv): New procedure.
(__aeabi_uidivmod): New procedure.
(__aeabi_uidiv): New procedure.
* lib/linux/x86-mes-gcc/syscall.c (__sys_call, __sys_call1, __sys_call2,
__sys_call3, __sys_call4): Move to...
* lib/linux/x86-mes-gcc/syscall-internal.c: ...here.
(__raise): New procedure.
* lib/linux/x86-mes-mescc/syscall.c (__sys_call, __sys_call1, __sys_call2,
__sys_call3, __sys_call4): Move to...
* lib/linux/x86-mes-mescc/syscall-internal.c: ...here.
(__raise): New procedure.
* lib/linux/arm-mes-gcc/syscall.c: New file.
* lib/linux/arm-mes-gcc/syscall-internal.c: New file.
* lib/linux/arm-mes-mescc/syscall.c: New file.
* lib/linux/arm-mes-mescc/syscall-internal.c: New file.
* lib/gnu/syscall.c (__syscall, __syscall2, __syscall_get, __syscall_put):
Move to...
* lib/gnu/syscall-internal.c: ...here.
2020-06-02 15:04:13 +02:00
Danny Milosavljevic fbc249832c
Prepare tests for ARMv4.
* lib/tests/io/90-stat.c,
lib/tests/scaffold/76-pointer-arithmetic.c,
lib/tests/scaffold/7k-for-each-elem.c,
lib/tests/scaffold/85-sizeof.c: Prepare tests for ARMv4.
2020-06-02 14:30:02 +02:00
Jan Nieuwenhuizen d8fca8321e
mescc: Mes C Library: Fix execlp, execvp for file names with slash.
Reported by mid-kid.

* lib/posix/execlp.c (execlp): Do not use search_path when file name
contains a slash (WAS: when file name starts with slash).
* lib/posix/execvp.c (execvp): Likewise.
2020-01-20 22:47:52 +01:00
Jan Nieuwenhuizen 3abd3e0bcc
mescc: Mes C Library: lseek: Be careful clearing read buffer.
* lib/linux/lseek.c (_lseek): New function.
* lib/linux/lseek.c (lseek): Use it to check if we should reset read
buffer.
* lib/mes/__buffered_read.c (__read_buffer_max): New variable.
(__buffered_read_init): Add environment override: MES_READ_BUFFER.
(__buffered_read): Use it.
2020-01-20 22:47:52 +01:00
Jan Nieuwenhuizen ec9aecea07
freebsd: Initial x86 scaffold.
* lib/freebsd/x86-mes-gcc/crt1.c: New file.
* lib/freebsd/x86-mes-gcc/exit-42.S: New file.
* lib/freebsd/x86-mes-gcc/hello-mes.S: New file.
* lib/freebsd/x86-mes-gcc/mini.c: New file.
* lib/freebsd/x86-mes-mescc/crt1.c: New file.
* lib/freebsd/x86-mes-mescc/mini.c: New file.
* lib/freebsd/x86-mes/elf32-0exit-42.hex2: New file.
* lib/freebsd/x86-mes/elf32-0header.hex2: New file.
* lib/freebsd/x86-mes/elf32-0hello-mes.hex2: New file.
* lib/freebsd/x86-mes/elf32-body-exit-42.hex2: New file.
* lib/freebsd/x86-mes/elf32-body-hello-mes.hex2: New file.
* lib/freebsd/x86-mes/elf32-footer-single-main.hex2: New file.
* lib/freebsd/x86-mes/elf32-header.hex2: New file.
2019-12-17 21:08:18 +01:00
Jan Nieuwenhuizen 34106fc420
build: Prepare for kernel variants.
* configure: Fix detection of Arch, FreeBSD.
* lib/linux/x86-mes-gcc/exit-42.S: Move from ...
* lib/x86-mes-gcc/exit-42.S: ... here.
* lib/linux/x86-mes-gcc/hello-mes.S: Move from ...
* lib/x86-mes-gcc/hello-mes.S: ... here.
* lib/linux/x86-mes-mescc/exit-42.S: Move from ...
* lib/x86-mes-mescc/exit-42.S: ... here.
* lib/linux/x86-mes-mescc/hello-mes.S: Move from ...
* lib/x86-mes-mescc/hello-mes.S: ... here.
* lib/linux/x86-mes/elf32-0exit-42.hex2: Move from ...
* lib/x86-mes/elf32-0exit-42.hex2: ... here.
* lib/linux/x86-mes/elf32-0header.hex2: Move from ...
* lib/x86-mes/elf32-0header.hex2: ... here.
* lib/linux/x86-mes/elf32-0hello-mes.hex2: Move from ...
* lib/x86-mes/elf32-0hello-mes.hex2: ... here.
* lib/linux/x86-mes/elf32-body-exit-42.hex2: Move from ...
* lib/x86-mes/elf32-body-exit-42.hex2: ... here.
* lib/linux/x86-mes/elf32-body-hello-mes.hex2: Move from ...
* lib/x86-mes/elf32-body-hello-mes.hex2: ... here.
* lib/linux/x86-mes/elf32-footer-single-main.hex2: Move from ...
* lib/x86-mes/elf32-footer-single-main.hex2: ... here.
* lib/linux/x86-mes/elf32-header.hex2: Move from ...
* lib/x86-mes/elf32-header.hex2: ... here.
* lib/linux/x86_64-mes-gcc/exit-42.S: Move from ...
* lib/x86_64-mes-gcc/exit-42.S: ... here.
* lib/linux/x86_64-mes-gcc/hello-mes.S: Move from ...
* lib/x86_64-mes-gcc/hello-mes.S: ... here.
* lib/linux/x86_64-mes-mescc/exit-42.S: Move from ...
* lib/x86_64-mes-mescc/exit-42.S: ... here.
* lib/linux/x86_64-mes-mescc/hello-mes.S: Move from ...
* lib/x86_64-mes-mescc/hello-mes.S: ... here.
* lib/linux/x86_64-mes/elf64-0exit-42.hex2: Move from ...
* lib/x86_64-mes/elf64-0exit-42.hex2: ... here.
* lib/linux/x86_64-mes/elf64-0header.hex2: Move from ...
* lib/x86_64-mes/elf64-0header.hex2: ... here.
* lib/linux/x86_64-mes/elf64-0hello-mes.hex2: Move from ...
* lib/x86_64-mes/elf64-0hello-mes.hex2: ... here.
* lib/linux/x86_64-mes/elf64-body-exit-42.hex2: Move from ...
* lib/x86_64-mes/elf64-body-exit-42.hex2: ... here.
* lib/linux/x86_64-mes/elf64-body-hello-mes.hex2: Move from ...
* lib/x86_64-mes/elf64-body-hello-mes.hex2: ... here.
* lib/linux/x86_64-mes/elf64-footer-single-main.hex2: Move from ...
* lib/x86_64-mes/elf64-footer-single-main.hex2: ... here.
* lib/linux/x86_64-mes/elf64-header.hex2: Move from ...
* lib/x86_64-mes/elf64-header.hex2: ... here.
* module/mescc.scm (parse-opts): Support --kernel.
* module/mescc/mescc.scm (kernel-find): New function.
* module/mescc/mescc.scm (hex2->elf): Use it to find kernel-specific ELF
snippets.
* build-aux/install.sh.in: Install it.
2019-12-17 21:07:35 +01:00
Jan Nieuwenhuizen c673c9d303
mescc: Mes C Library: Add ioctl3 stub. 2019-12-13 21:52:31 +01:00
Jan Nieuwenhuizen f5bf3f4cf6
mescc: Mes C Library: Fix access stub.
* lib/stub/access.c (access): Use _open3 to give more meaningful
behaviour.  Fixes hanging of mes.
2019-12-13 21:52:31 +01:00
Jan Nieuwenhuizen 7c6da0c213
hurd: Fixes for upgrade to debian-hurd-20190220.img.
* include/mach/mach-init.h (__mach_host_self, __mach_task_self):
Remove macro magic.
(mach_host_self, mach_task_self): Remove macro magic; declare as function.
* lib/mach/mach-init.c (mach_host_self, mach_task_self): New function.
(mach_init): Use them.
* lib/gnu/hurd-start.c (_hurd_start): Use mach_task_self ().
* lib/gnu/_exit.c (_exit): Likewise.
2019-12-13 21:52:31 +01:00
Jan Nieuwenhuizen 9b0009a888
hurd: Add malloc.
* include/gnu/syscall.h (__vm_allocate): New value.
(__vm_allocate): Declare.
* lib/gnu/malloc.c: New file.
* lib/stdlib/malloc.c[__GNU__]: Disable.  See FIXME.
* lib/gnu/vm-allocate.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES): Add it.
2019-12-13 21:52:31 +01:00
Jan Nieuwenhuizen 89945751d9
hurd: Add open.
* include/fcntl.h (O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_APPEND,
O_TRUNC)[__GNU__]: Specialize for GNU.
* lib/gnu/dir-lookup.c: New file.
* lib/stdio/fopen.c (fopen): Use O_RDONLY.
* lib/tests/posix/50-open-read.c (main): Likewise.
* lib/tests/stdio/90-fseek.c (main): Likewise.
* include/gnu/syscall.h (SYS__dir_lookup): New value.
* lib/gnu/_open3.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES): Build them.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen 67d82a6de5
hurd: Add argv and environ.
* include/gnu/hurd.h (struct hurd_startup_data): Add argp, envp.
* lib/gnu/hurd-start.c (__argv, __env): Define them.
* lib/gnu/exec-startup-get-data.c (mach_startup_info2hurd_startup_data):
Set them.
* lib/gnu/x86-mes-gcc/crt1.c (_start): Use them.
* build-aux/configure-lib.sh (libc_mini_SOURCES): Add argz-extract.c.
* include/argz.h: Build fix.
* lib/string/argz-count.c: Likewise.
* lib/string/argz-extract.c: Likewise.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen 72c76d6b3a
hurd: Add stubs for missing libc+tcc functions.
* lib/stub/close.c: New file.
* lib/stub/rmdir.c: New file.
* lib/stub/stat.c: New file.
* build-aux/configure-lib.sh (libc_tcc_SOURCES)[gnu]: Add them.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen 49ff9a7edd
hurd: Add stubs for missing libc functions.
* lib/stub/_getcwd.c: New file.
* lib/stub/_getcwd.c: New file.
* lib/stub/_open3.c: New file.
* lib/stub/access.c: New file.
* lib/stub/brk.c: New file.
* lib/stub/chmod.c: New file.
* lib/stub/clock_gettime.c: New file.
* lib/stub/dup.c: New file.
* lib/stub/dup2.c: New file.
* lib/stub/execve.c: New file.
* lib/stub/fork.c: New file.
* lib/stub/gettimeofday.c: New file.
* lib/stub/ioctl.c: New file.
* lib/stub/time.c: New file.
* lib/stub/unlink.c: New file.
* lib/stub/waitpid.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES)[gnu]: Add them.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen 9b9d37ee95
hurd: Add stubs for missing libmes functions.
* lib/stub/lseek.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES)[gnu]: Add it.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen 6d3b9b687d
hurd: Add _read.
* include/gnu/hurd.h (fd_read): Declare.
* include/gnu/syscall.h (SYS__io_read): New value.
* lib/gnu/_read.c: New file.
* lib/gnu/fd-read.c: New file.
* lib/gnu/io-read.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES): Add _read sources.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen db4a202c6b
hurd: Add _write.
* include/gnu/syscall.h (SYS__io_write): Add enum field.
(_hurd_dtable, _hurd_dtable_size): Declare variable.
(fd_get, fd_write, __io_write, __syscall_put): Declare.
* lib/gnu/hurd-start.c (_hurd_dtable, _hurd_dtable_size): Define
variable.
* lib/gnu/_write.c: New file.
* lib/gnu/fd-get.c (fd_get): New file.
* lib/gnu/fd-write.c (fd_write): New file.
* lib/gnu/io-write.c: New file.
* lib/gnu/syscall.c (__syscall_put): New function.
* build-aux/cofnigure-lib.sh (libc_mini_SOURCES): Add write sources.
* lib/tests/mes/30-oputs.c (main): Update.
* lib/tests/mes/30-oputs.stdout: New file.
* lib/tests/mes/30-eputs.c: New test.
* lib/tests/mes/30-eputs.stderr: New file.
* build-aux/check-mescc.sh (TESTS): Add it.
2019-12-13 21:52:30 +01:00
Jan Nieuwenhuizen 784838e368
hurd: Initial support.
This adds minimal Hurd support by implementing the _exit function.

* AUTHORS: Update.
* .gitignore: Ignore a.out, core, .config.
* include/sys/wait.h (W_EXITCODE): New define.
* lib/gnu/x86-mes-gcc/crt1.c: New file.
* lib/gnu/x86-mes-gcc/mini.c: New file.
* lib/gnu/hurd-start.c: New file.
* lib/gnu/_exit.c: New file.
* include/gnu/syscall.h: New file.
* include/gnu/hurd.h: New file.
* lib/gnu/_exit.c: New file.
* lib/gnu/exec-startup-get-data.c: New file.
* lib/gnu/hurd-start.c: New file.
* lib/gnu/proc-mark-exit.c: New file.
* lib/gnu/syscall.c: New file.
* lib/gnu/task-get-special-port.c: New file.
* lib/gnu/task-terminate.c: New file.
* lib/gnu/vm-statistics.c: New file.
* build-aux/configure-lib.sh (libc_mini_SOURCES): Add Hurd sources.
* build-aux/build.sh.in (CPPFLAGS): Add lib to includes, to find linux
crt1.c.
* build-aux/test-c.sh: Always use at least -l c+mini for GNU.
* lib/tests/scaffold/30-exit-42.exit: New file.
* lib/tests/scaffold/30-exit-42.c: New test.
* build-aux/check-mescc.sh (TESTS): Add it.
* lib/tests/scaffold/30-exit-0.c (main): Move from 00-exit-0.c; Rewrite,
use _exit.
* include/gnu/hurd-types.h: Import from GNU C Library.
* include/mach/mach-init.h: Likewise.
* lib/mach/mach-init.c: Likewise.
* lib/mach/mach_host_self.S: Likewise.
* lib/mach/mach_msg_trap.S: Likewise.
* lib/mach/mach_reply_port.S: Likewise.
* lib/mach/mach_task_self.S: Likewise.
* lib/mach/mach_thread_self.S: Likewise.
* lib/mach/msg.c: Likewise.
2019-12-13 21:52:29 +01:00
Jan Nieuwenhuizen 093a8b0903
bootstrap: Build files only once.
* build-aux/bootstrap.sh.in: Build files only once.
2019-12-07 23:29:34 +01:00
Jan Nieuwenhuizen b4b20d6ac4
build: Add mescc scaffold for regular build.
* lib/x86-mes-mescc/exit-42.S: New file.
* lib/x86-mes-mescc/hello-mes.S: New file.
* lib/x86_64-mes-mescc/exit-42.S: New file.
* lib/x86_64-mes-mescc/hello-mes.S: New file.
2019-12-06 19:53:50 +01:00