diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index 92867f85..b58afc3c 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -93,6 +93,7 @@ libmes_SOURCES=" $libc_mini_shared_SOURCES lib/ctype/isnumber.c lib/mes/abtol.c +lib/mes/cast.c lib/mes/eputc.c lib/mes/fdgetc.c lib/mes/fdputc.c diff --git a/include/m2/lib.h b/include/m2/lib.h index f6094603..93762931 100644 --- a/include/m2/lib.h +++ b/include/m2/lib.h @@ -30,6 +30,12 @@ int errno; // CONSTANT EOF 0xffffffff // CONSTANT __FILEDES_MAX 512 +char* cast_intp_to_charp (int *i); +char* cast_long_to_charp (long i); +long cast_charp_to_long (char const *); +long cast_int_to_long (int i); +long cast_voidp_to_long (void const *); + char *itoa (int number); char *ltoa (long number); int __ungetc_p (int filedes); diff --git a/include/mes/lib.h b/include/mes/lib.h index 4ffd57bc..a78d5bb6 100644 --- a/include/mes/lib.h +++ b/include/mes/lib.h @@ -23,6 +23,18 @@ #include +char* cast_intp_to_charp (int const *i); +char* cast_long_to_charp (long i); +long cast_charp_to_long (char const *); +long cast_int_to_long (int i); +long cast_voidp_to_long (void const *); + +// #define cast_intp_to_charp(x) ((char*) x) +// #define cast_long_to_charp(x) ((char*) x) +// #define cast_charp_to_long(x) ((long) x) +// #define cast_int_to_long(x) ((long) x) +// #define cast_voidp_to_long(x) ((long) x) + int __mes_debug (); void __ungetc_init (); void __ungetc_clear (int filedes); diff --git a/kaem.run b/kaem.run index 84f2f5f1..b9ef84d2 100644 --- a/kaem.run +++ b/kaem.run @@ -30,6 +30,7 @@ M2-Planet \ -f lib/linux/${mes_cpu}-mes-m2/_exit.c \ -f lib/linux/${mes_cpu}-mes-m2/_write.c \ -f lib/mes/globals.c \ + -f lib/m2/cast.c \ -f lib/m2/exit.c \ -f lib/mes/mini-write.c \ -f lib/linux/${mes_cpu}-mes-m2/syscall.c \ diff --git a/lib/linux/_getcwd.c b/lib/linux/_getcwd.c index 699edb3b..85153cb1 100644 --- a/lib/linux/_getcwd.c +++ b/lib/linux/_getcwd.c @@ -18,14 +18,15 @@ * along with GNU Mes. If not, see . */ -#include +#include #include #include char * _getcwd (char *buffer, size_t size) { - int r = _sys_call2 (SYS_getcwd, buffer, size); + long long_buffer = cast_charp_to_long (buffer); + int r = _sys_call2 (SYS_getcwd, long_buffer, size); if (r >= 0) return buffer; return 0; diff --git a/lib/linux/access.c b/lib/linux/access.c index 6938ba22..805e8f01 100644 --- a/lib/linux/access.c +++ b/lib/linux/access.c @@ -18,13 +18,14 @@ * along with GNU Mes. If not, see . */ +#include #include #include int access (char const *file_name, int how) { - long long_file_name = file_name; - long long_how = how; + long long_file_name = cast_charp_to_long (file_name); + long long_how = cast_int_to_long (how); return _sys_call2 (SYS_access, long_file_name, long_how); } diff --git a/lib/linux/brk.c b/lib/linux/brk.c index 88a4f999..586bd7e1 100644 --- a/lib/linux/brk.c +++ b/lib/linux/brk.c @@ -18,11 +18,13 @@ * along with GNU Mes. If not, see . */ +#include #include #include long brk (void *addr) { - return _sys_call1 (SYS_brk, addr); + long long_addr = cast_voidp_to_long (addr); + return _sys_call1 (SYS_brk, long_addr); } diff --git a/lib/linux/chmod.c b/lib/linux/chmod.c index 54509b53..1feabec5 100644 --- a/lib/linux/chmod.c +++ b/lib/linux/chmod.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include #include @@ -25,7 +26,7 @@ int chmod (char const *file_name, mode_t mask) { - long long_file_name = file_name; - long long_mask = mask; + long long_file_name = cast_charp_to_long (file_name); + long long_mask = cast_int_to_long (mask); return _sys_call2 (SYS_chmod, long_file_name, long_mask); } diff --git a/lib/linux/clock_gettime.c b/lib/linux/clock_gettime.c index d04000dc..051dba33 100644 --- a/lib/linux/clock_gettime.c +++ b/lib/linux/clock_gettime.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include #include @@ -25,7 +26,7 @@ int clock_gettime (clockid_t clk_id, struct timespec *tp) { - long long_clk_id = clk_id; - long long_tp = tp; - return _sys_call2 (SYS_clock_gettime, clk_id, tp); + long long_clk_id = cast_int_to_long (clk_id); + long long_tp = cast_voidp_to_long (tp); + return _sys_call2 (SYS_clock_gettime, long_clk_id, long_tp); } diff --git a/lib/linux/gettimeofday.c b/lib/linux/gettimeofday.c index 7d888da6..495f059f 100644 --- a/lib/linux/gettimeofday.c +++ b/lib/linux/gettimeofday.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include #include @@ -25,7 +26,7 @@ int gettimeofday (struct timeval *tv, struct timezone *tz) { - long long_tv = tv; - long long_tz = tz; + long long_tv = cast_voidp_to_long (tv); + long long_tz = cast_voidp_to_long (tz); return _sys_call2 (SYS_gettimeofday, long_tv, long_tz); } diff --git a/lib/linux/malloc.c b/lib/linux/malloc.c index d7a38362..ea609d5d 100644 --- a/lib/linux/malloc.c +++ b/lib/linux/malloc.c @@ -30,7 +30,7 @@ void * malloc (size_t size) { if (!__brk) - __brk = (char *) brk (0); + __brk = cast_long_to_charp (brk (0)); /* align what we give back. */ __brk = (char*) (((uintptr_t) __brk + sizeof (max_align_t) - 1) & -sizeof (max_align_t)); diff --git a/lib/linux/unlink.c b/lib/linux/unlink.c index 4a6881fc..03713e64 100644 --- a/lib/linux/unlink.c +++ b/lib/linux/unlink.c @@ -18,11 +18,13 @@ * along with GNU Mes. If not, see . */ +#include #include #include int unlink (char const *file_name) { - return _sys_call1 (SYS_unlink, file_name); + long long_file_name = cast_charp_to_long (file_name); + return _sys_call1 (SYS_unlink, long_file_name); } diff --git a/lib/m2/cast.c b/lib/m2/cast.c new file mode 100644 index 00000000..6c6fe969 --- /dev/null +++ b/lib/m2/cast.c @@ -0,0 +1,57 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +#undef cast_intp_to_charp +#undef cast_long_to_charp +#undef cast_charp_to_long +#undef cast_int_to_long +#undef cast_voidp_to_long + +char* +cast_intp_to_charp (int const *i) +{ + return i; +} + +char* +cast_long_to_charp (long i) +{ + return i; +} + +long +cast_charp_to_long (char const *i) +{ + return i; +} + +long +cast_int_to_long (int i) +{ + return i; +} + +long +cast_voidp_to_long (void const *i) +{ + return i; +} diff --git a/lib/mes/cast.c b/lib/mes/cast.c new file mode 100644 index 00000000..de3a7dd0 --- /dev/null +++ b/lib/mes/cast.c @@ -0,0 +1,57 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +#undef cast_intp_to_charp +#undef cast_long_to_charp +#undef cast_charp_to_long +#undef cast_int_to_long +#undef cast_voidp_to_long + +char* +cast_intp_to_charp (int const *i) +{ + return (char*)i; +} + +char* +cast_long_to_charp (long i) +{ + return (char*)i; +} + +long +cast_charp_to_long (char const *i) +{ + return (long)i; +} + +long +cast_int_to_long (int i) +{ + return (long)i; +} + +long +cast_voidp_to_long (void const *i) +{ + return (long)i; +} diff --git a/lib/mes/fdputc.c b/lib/mes/fdputc.c index a06b6546..87c1b807 100644 --- a/lib/mes/fdputc.c +++ b/lib/mes/fdputc.c @@ -23,7 +23,7 @@ int fdputc (int c, int fd) { - char *p = &c; + char *p = cast_intp_to_charp (&c); write (fd, p, 1); return 0; } diff --git a/lib/stdio/putchar.c b/lib/stdio/putchar.c index a247423c..2ca347fa 100644 --- a/lib/stdio/putchar.c +++ b/lib/stdio/putchar.c @@ -18,12 +18,13 @@ * along with GNU Mes. If not, see . */ +#include #include int putchar (int c) { - char *p = &c; + char *p = cast_intp_to_charp (&c); write (__stdout, p, 1); return 0; } diff --git a/simple.make b/simple.make index 6b8401d4..60069414 100644 --- a/simple.make +++ b/simple.make @@ -44,12 +44,7 @@ CFLAGS:= \ -D 'MES_VERSION="git"' \ -D 'MES_PKGDATADIR="/usr/local/share/mes"' \ -I include \ - -fno-builtin \ - -Wno-discarded-qualifiers \ - -Wno-discarded-array-qualifiers \ - -Wno-ignored-qualifiers \ - -Wno-incompatible-pointer-types \ - -Wno-int-conversion + -fno-builtin LIBMES_SOURCES = \ src/builtins.c \ @@ -81,6 +76,7 @@ M2_SOURCES = \ lib/linux/x86-mes-m2/crt1.c \ lib/linux/x86-mes-m2/_exit.c \ lib/linux/x86-mes-m2/_write.c \ + lib/m2/cast.c \ lib/m2/exit.c \ lib/mes/write.c \ lib/linux/x86-mes-m2/syscall.c \ @@ -162,6 +158,7 @@ MES_LIBC = \ GCC_SOURCES = \ lib/mes/__mes_debug.c \ + lib/mes/cast.c \ lib/mes/eputc.c \ lib/mes/eputs.c \ lib/mes/fdgetc.c \