Compare commits
156 Commits
master
...
wip-arm-0.
Author | SHA1 | Date |
---|---|---|
Danny Milosavljevic | 801f5d27e5 | |
Jan Nieuwenhuizen | 4cd248d2bb | |
Danny Milosavljevic | cadc4f46ac | |
Danny Milosavljevic | 328acfc11c | |
Danny Milosavljevic | 765b879116 | |
Danny Milosavljevic | 2201a4fc97 | |
Danny Milosavljevic | 0a2e9f47c7 | |
Danny Milosavljevic | b7cf5bd2eb | |
Jan Nieuwenhuizen | 2d3e84d1c7 | |
Jan Nieuwenhuizen | 7c91edf610 | |
Jan Nieuwenhuizen | b429c4c4d4 | |
Jan Nieuwenhuizen | 225baf2527 | |
Jan Nieuwenhuizen | 4fe93e4acc | |
Jan Nieuwenhuizen | 4e89d924e2 | |
Jan Nieuwenhuizen | 717a231908 | |
Jan Nieuwenhuizen | 2ecf24880c | |
Jan Nieuwenhuizen | aca93122e3 | |
Jan Nieuwenhuizen | 1a114238c5 | |
Jan Nieuwenhuizen | fa1805b5e5 | |
Jan Nieuwenhuizen | ce8debec54 | |
Jan Nieuwenhuizen | 4730386dc1 | |
Jan Nieuwenhuizen | 33729bf3f7 | |
Jan Nieuwenhuizen | e2d6d83241 | |
Jan Nieuwenhuizen | 9b1fbe03ec | |
Jan Nieuwenhuizen | a127b1d6e8 | |
Jan Nieuwenhuizen | 8303a676a1 | |
Jan Nieuwenhuizen | 471f47273e | |
Jan Nieuwenhuizen | feefb06512 | |
Jan Nieuwenhuizen | c87b1442c0 | |
Jan Nieuwenhuizen | 7517ece940 | |
Jan Nieuwenhuizen | 596672c828 | |
Jan Nieuwenhuizen | 369f956465 | |
Jan Nieuwenhuizen | b3ac30ba4b | |
Jan Nieuwenhuizen | c9204413a9 | |
Jan Nieuwenhuizen | 88c1f05838 | |
Jan Nieuwenhuizen | 2cbe8c7b75 | |
Jan Nieuwenhuizen | 8e521aae10 | |
Jan Nieuwenhuizen | abb8718ee2 | |
Jan Nieuwenhuizen | d5b860603e | |
Jan Nieuwenhuizen | b89b61a0bb | |
Jan Nieuwenhuizen | 8fbf0c992a | |
Jan Nieuwenhuizen | 88bec31aa6 | |
Jan Nieuwenhuizen | 8574f85a5f | |
Jan Nieuwenhuizen | 38e15f4e46 | |
Jan Nieuwenhuizen | 15e63126e7 | |
Jan Nieuwenhuizen | 703876b609 | |
Danny Milosavljevic | b956dc152c | |
Danny Milosavljevic | 233bcf75ea | |
Danny Milosavljevic | 499da86c70 | |
Danny Milosavljevic | ea99d36af5 | |
Danny Milosavljevic | c7bfc1de36 | |
Danny Milosavljevic | f9a6e1aed0 | |
Danny Milosavljevic | 0e2d6b4b84 | |
Danny Milosavljevic | 0d60769ea4 | |
Danny Milosavljevic | 5874b709b8 | |
Danny Milosavljevic | 371e11fd9e | |
Danny Milosavljevic | 810d063d36 | |
Danny Milosavljevic | d0e05a4a80 | |
Danny Milosavljevic | 20d0e0d950 | |
Danny Milosavljevic | 6fbead7479 | |
Jan Nieuwenhuizen | fb3f34b04f | |
Danny Milosavljevic | b9b744001a | |
Danny Milosavljevic | cf0c7db11f | |
Danny Milosavljevic | a3988658ed | |
Danny Milosavljevic | 105cf743ff | |
Danny Milosavljevic | b82a2f1fad | |
Danny Milosavljevic | 92022f95ff | |
Danny Milosavljevic | 8348e80589 | |
Danny Milosavljevic | dd2a679fda | |
Jan Nieuwenhuizen | 4b40bdc0cb | |
Jan Nieuwenhuizen | 35c746043f | |
Danny Milosavljevic | 58be0fd7e0 | |
Danny Milosavljevic | c37eee6b3d | |
Danny Milosavljevic | 3767477f5a | |
Danny Milosavljevic | 807afb7d69 | |
Danny Milosavljevic | fbe90fb293 | |
Danny Milosavljevic | 21bf8a0d92 | |
Danny Milosavljevic | 24299d80ff | |
Danny Milosavljevic | 1f6ff076b2 | |
Danny Milosavljevic | 53620890f4 | |
Danny Milosavljevic | 44cfdd7e3c | |
Danny Milosavljevic | 2363259435 | |
Danny Milosavljevic | f3a266b960 | |
Danny Milosavljevic | cf0b648185 | |
Danny Milosavljevic | b963db8342 | |
Danny Milosavljevic | 9a84e94a0a | |
Danny Milosavljevic | 899b613dbc | |
Danny Milosavljevic | 9ac6d37849 | |
Danny Milosavljevic | 13fbd909d7 | |
Danny Milosavljevic | e5f326040d | |
Danny Milosavljevic | 25a0e13501 | |
Danny Milosavljevic | 149cc43baf | |
Danny Milosavljevic | a1217d71c1 | |
Danny Milosavljevic | 5199db9d8e | |
Jan Nieuwenhuizen | 37149aa84d | |
Danny Milosavljevic | b314c66b3b | |
Danny Milosavljevic | 01ca0678c1 | |
Danny Milosavljevic | 90c9fefeb4 | |
Danny Milosavljevic | 7788b9f263 | |
Jan Nieuwenhuizen | 89591a4c51 | |
Jan Nieuwenhuizen | d977d39abc | |
Jan Nieuwenhuizen | 282abce86f | |
Jan Nieuwenhuizen | bfe710d2a2 | |
Jan Nieuwenhuizen | 92d60477c5 | |
Danny Milosavljevic | 705be3f917 | |
Danny Milosavljevic | 07c907884b | |
Danny Milosavljevic | f29cb12ec4 | |
Danny Milosavljevic | a725537f72 | |
Danny Milosavljevic | eda0d8dca5 | |
Danny Milosavljevic | 83e7c4cc9e | |
Danny Milosavljevic | de9dd28743 | |
Danny Milosavljevic | f3a3df9e55 | |
Danny Milosavljevic | 9283e077b3 | |
Danny Milosavljevic | 8f1d2473bc | |
Danny Milosavljevic | ba7338a466 | |
Danny Milosavljevic | badae1c4c4 | |
Danny Milosavljevic | eebcb57b36 | |
Danny Milosavljevic | 43e040dfd9 | |
Danny Milosavljevic | 3bc75ab98b | |
Danny Milosavljevic | 98e5fd7da6 | |
Danny Milosavljevic | 41965ba2e1 | |
Danny Milosavljevic | ae53ac4542 | |
Danny Milosavljevic | c6366924e2 | |
Danny Milosavljevic | 03c0e67a03 | |
Danny Milosavljevic | 50447ce307 | |
Danny Milosavljevic | c65c50b92a | |
Danny Milosavljevic | 7e73c7adaf | |
Danny Milosavljevic | f51d3a3356 | |
Danny Milosavljevic | 794d242b9b | |
Danny Milosavljevic | 8a6092f2b4 | |
Danny Milosavljevic | c72d349f53 | |
Danny Milosavljevic | c4c94d68fe | |
Danny Milosavljevic | 311a955b0b | |
Danny Milosavljevic | 26b6db0bbe | |
Danny Milosavljevic | 7de32f00fc | |
Danny Milosavljevic | b8f617d885 | |
Danny Milosavljevic | 0b4a9abafa | |
Danny Milosavljevic | 3147550d19 | |
Danny Milosavljevic | 6c562bb065 | |
Danny Milosavljevic | 898d74a63b | |
Danny Milosavljevic | f04484fdf3 | |
Danny Milosavljevic | ab0124eab7 | |
Danny Milosavljevic | 3b8961465f | |
Danny Milosavljevic | a252b9ac08 | |
Danny Milosavljevic | 0f5651436b | |
Danny Milosavljevic | fd7c2d32cd | |
Danny Milosavljevic | 59f22c5b86 | |
Danny Milosavljevic | 7b2605b347 | |
Danny Milosavljevic | d7576125d2 | |
Danny Milosavljevic | 2ad76e4ffb | |
Danny Milosavljevic | d456b51e49 | |
Danny Milosavljevic | fc8b4016fb | |
Danny Milosavljevic | 3aaf8774a8 | |
Jan Nieuwenhuizen | 394db05c9b | |
Danny Milosavljevic | 83d8e41020 | |
Jan Nieuwenhuizen | 314e25e532 |
|
@ -34,6 +34,8 @@ module/mescc/M1.scm
|
|||
module/mescc/as.scm
|
||||
module/mescc/bytevectors.scm
|
||||
module/mescc/compile.scm
|
||||
module/mescc/armv4/as.scm
|
||||
module/mescc/armv4/info.scm
|
||||
module/mescc/i386/as.scm
|
||||
module/mescc/i386/info.scm
|
||||
module/mescc/x86_64/as.scm
|
||||
|
|
|
@ -49,10 +49,11 @@ if test -n "$GUILE" -a "$GUILE" != true; then
|
|||
fi
|
||||
|
||||
debug=
|
||||
#debug=-g
|
||||
debug=-g
|
||||
|
||||
CFLAGS="
|
||||
-static
|
||||
-std=gnu99
|
||||
$debug
|
||||
"
|
||||
|
||||
|
@ -64,6 +65,12 @@ if test $mes_libc = mes; then
|
|||
"
|
||||
fi
|
||||
|
||||
if test $mes_cpu = arm; then
|
||||
CFLAGS="$CFLAGS
|
||||
-marm
|
||||
"
|
||||
fi
|
||||
|
||||
CPPFLAGS="
|
||||
-D HAVE_CONFIG_H=1
|
||||
-I ../include
|
||||
|
|
|
@ -200,12 +200,17 @@ if test -z "$bootstrap"; then
|
|||
TESTS="$TESTS
|
||||
lib/tests/dirent/90-readdir.c
|
||||
lib/tests/io/90-stat.c
|
||||
lib/tests/mes/90-abtod.c
|
||||
lib/tests/mes/90-dtoab.c
|
||||
lib/tests/posix/90-execlp.c
|
||||
lib/tests/posix/90-unsetenv.c
|
||||
lib/tests/signal/90-signal.c
|
||||
lib/tests/stdio/90-fopen.c
|
||||
lib/tests/stdio/90-fopen-append.c
|
||||
lib/tests/stdio/90-fread-fwrite.c
|
||||
lib/tests/stdio/90-fseek.c
|
||||
lib/tests/stdio/90-sprintf.c
|
||||
lib/tests/stdio/90-sscanf.c
|
||||
lib/tests/stdlib/90-strtol.c
|
||||
lib/tests/string/90-snprintf.c
|
||||
lib/tests/string/90-strpbrk.c
|
||||
|
@ -222,7 +227,7 @@ lib/tests/scaffold/a1-global-no-clobber.c
|
|||
fi
|
||||
|
||||
XFAIL_TESTS="
|
||||
lib/tests/stdio/90-sprintf.c
|
||||
lib/tests/mes/90-abtod.c
|
||||
lib/tests/stdio/90-sprintf.c
|
||||
"
|
||||
|
||||
|
@ -232,6 +237,7 @@ lib/tests/scaffold/17-compare-unsigned-char-le.c
|
|||
lib/tests/scaffold/17-compare-unsigned-short-le.c
|
||||
lib/tests/scaffold/66-local-char-array.c
|
||||
lib/tests/scaffold/72-typedef-struct-def-local.c
|
||||
lib/tests/mes/90-dtoab.c
|
||||
lib/tests/scaffold/90-goto-var.c
|
||||
lib/tests/scaffold/91-goto-array.c
|
||||
"
|
||||
|
@ -248,11 +254,6 @@ lib/tests/scaffold/a0-call-trunc-int.c
|
|||
fi
|
||||
fi
|
||||
|
||||
if test $mes_cpu = x86; then
|
||||
XFAIL_TESTS="$XFAIL_TESTS
|
||||
"
|
||||
fi
|
||||
|
||||
if test $mes_cpu = x86_64; then
|
||||
XFAIL_TESTS="$XFAIL_TESTS
|
||||
lib/tests/stdio/70-printf-stdarg.c
|
||||
|
@ -261,6 +262,7 @@ fi
|
|||
|
||||
if test $compiler = gcc; then
|
||||
XFAIL_TESTS="$XFAIL_TESTS
|
||||
lib/tests/mes/90-abtod.c
|
||||
"
|
||||
|
||||
if test $mes_cpu = x86; then
|
||||
|
@ -278,6 +280,7 @@ lib/tests/stdio/80-sscanf.c
|
|||
lib/tests/mes/90-abtod.c
|
||||
lib/tests/posix/90-execlp.c
|
||||
lib/tests/string/90-snprintf.c
|
||||
lib/tests/stdio/90-sscanf.c
|
||||
"
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -28,6 +28,9 @@ if $courageous; then
|
|||
fi
|
||||
|
||||
CFLAGS=
|
||||
if test $mes_cpu = arm; then
|
||||
CFLAGS="-marm"
|
||||
fi
|
||||
if test $mes_libc = mes; then
|
||||
CFLAGS="${CFLAGS}
|
||||
-static
|
||||
|
|
|
@ -86,6 +86,8 @@ lib/linux/lseek.c
|
|||
fi
|
||||
else
|
||||
libmes_SOURCES="$libmes_SOURCES
|
||||
lib/mes/abtod.c
|
||||
lib/mes/dtoab.c
|
||||
"
|
||||
fi
|
||||
|
||||
|
@ -156,6 +158,8 @@ lib/ctype/islower.c
|
|||
lib/ctype/isupper.c
|
||||
lib/ctype/tolower.c
|
||||
lib/ctype/toupper.c
|
||||
lib/mes/abtod.c
|
||||
lib/mes/dtoab.c
|
||||
lib/mes/search-path.c
|
||||
lib/posix/execvp.c
|
||||
lib/stdio/fclose.c
|
||||
|
@ -180,6 +184,7 @@ lib/stdio/vsprintf.c
|
|||
lib/stdio/vsscanf.c
|
||||
lib/stdlib/calloc.c
|
||||
lib/stdlib/qsort.c
|
||||
lib/stdlib/strtod.c
|
||||
lib/stdlib/strtof.c
|
||||
lib/stdlib/strtol.c
|
||||
lib/stdlib/strtold.c
|
||||
|
@ -217,16 +222,21 @@ lib/ctype/isalnum.c
|
|||
lib/ctype/isalpha.c
|
||||
lib/ctype/isascii.c
|
||||
lib/ctype/iscntrl.c
|
||||
lib/ctype/isgraph.c
|
||||
lib/ctype/isprint.c
|
||||
lib/ctype/ispunct.c
|
||||
lib/dirent/__getdirentries.c
|
||||
lib/dirent/closedir.c
|
||||
lib/dirent/opendir.c
|
||||
lib/dirent/readdir.c
|
||||
lib/math/ceil.c
|
||||
lib/math/fabs.c
|
||||
lib/math/floor.c
|
||||
lib/math/labs.c
|
||||
lib/mes/fdgets.c
|
||||
lib/posix/alarm.c
|
||||
lib/posix/execl.c
|
||||
lib/posix/execlp.c
|
||||
lib/posix/mktemp.c
|
||||
lib/posix/raise.c
|
||||
lib/posix/sbrk.c
|
||||
|
@ -237,12 +247,16 @@ lib/stdio/feof.c
|
|||
lib/stdio/fgets.c
|
||||
lib/stdio/fileno.c
|
||||
lib/stdio/freopen.c
|
||||
lib/stdio/fscanf.c
|
||||
lib/stdio/perror.c
|
||||
lib/stdio/rewind.c
|
||||
lib/stdio/vfscanf.c
|
||||
lib/stdlib/__exit.c
|
||||
lib/stdlib/abort.c
|
||||
lib/stdlib/abs.c
|
||||
lib/stdlib/alloca.c
|
||||
lib/stdlib/atexit.c
|
||||
lib/stdlib/atof.c
|
||||
lib/stdlib/atol.c
|
||||
lib/stdlib/mbstowcs.c
|
||||
lib/string/bcmp.c
|
||||
|
@ -256,27 +270,43 @@ lib/string/strerror.c
|
|||
lib/string/strncat.c
|
||||
lib/string/strpbrk.c
|
||||
lib/string/strspn.c
|
||||
lib/string/strtok.c
|
||||
lib/stub/__cleanup.c
|
||||
lib/stub/asctime.c
|
||||
lib/stub/atan2.c
|
||||
lib/stub/bsearch.c
|
||||
lib/stub/chown.c
|
||||
lib/stub/cos.c
|
||||
lib/stub/ctime.c
|
||||
lib/stub/exp.c
|
||||
lib/stub/fpurge.c
|
||||
lib/stub/freadahead.c
|
||||
lib/stub/frexp.c
|
||||
lib/stub/getgrgid.c
|
||||
lib/stub/getgrnam.c
|
||||
lib/stub/getlogin.c
|
||||
lib/stub/getpgid.c
|
||||
lib/stub/getpgrp.c
|
||||
lib/stub/getpwnam.c
|
||||
lib/stub/getpwuid.c
|
||||
lib/stub/gmtime.c
|
||||
lib/stub/log.c
|
||||
lib/stub/mktime.c
|
||||
lib/stub/modf.c
|
||||
lib/stub/pclose.c
|
||||
lib/stub/popen.c
|
||||
lib/stub/pow.c
|
||||
lib/stub/rand.c
|
||||
lib/stub/setbuf.c
|
||||
lib/stub/setgrent.c
|
||||
lib/stub/setlocale.c
|
||||
lib/stub/setvbuf.c
|
||||
lib/stub/sigaddset.c
|
||||
lib/stub/sigblock.c
|
||||
lib/stub/sigdelset.c
|
||||
lib/stub/sigsetmask.c
|
||||
lib/stub/sin.c
|
||||
lib/stub/sqrt.c
|
||||
lib/stub/strftime.c
|
||||
lib/stub/sys_siglist.c
|
||||
lib/stub/system.c
|
||||
|
@ -303,14 +333,19 @@ lib/linux/kill.c
|
|||
lib/linux/link.c
|
||||
lib/linux/lstat.c
|
||||
lib/linux/mkdir.c
|
||||
lib/linux/mknod.c
|
||||
lib/linux/mmap.c
|
||||
lib/linux/munmap.c
|
||||
lib/linux/nanosleep.c
|
||||
lib/linux/pipe.c
|
||||
lib/linux/readlink.c
|
||||
lib/linux/rename.c
|
||||
lib/linux/setgid.c
|
||||
lib/linux/settimer.c
|
||||
lib/linux/setuid.c
|
||||
lib/linux/signal.c
|
||||
lib/linux/sigprogmask.c
|
||||
lib/linux/symlink.c
|
||||
"
|
||||
fi
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ $CC -c $CPPFLAGS $CFLAGS -o "$o".o "$t"
|
|||
$CC $CFLAGS $LDFLAGS -L . -o "$o" $crt1 "$o".o $LIBS
|
||||
|
||||
set +e
|
||||
timeout 10 "$o" -s --long file0 file1 > "$o".1 2> "$o".2
|
||||
timeout 20 "$o" -s --long file0 file1 > "$o".1 2> "$o".2
|
||||
r=$?
|
||||
set -e
|
||||
if [ -f "$b".exit ]; then
|
||||
|
|
|
@ -7,7 +7,9 @@ We are pleased to announce the release of GNU Mes 0.20, representing
|
|||
147 commits over 38 weeks.
|
||||
|
||||
Mes has now brought the Reduced Binary Seed bootstrap to Guix (bootstrap
|
||||
a GNU/Linux system without binary GNU toolchain or equivalent).
|
||||
a GNU/Linux system without binary GNU toolchain or equivalent). It
|
||||
should land in Guix master any day now: a big thank you to everyone who
|
||||
helped, notably Ludovic and Mark.
|
||||
|
||||
This release is a step towards the upcoming Scheme-only bootstrap and
|
||||
bringing Mes into NixOS and Debian. This effort is now sponsored by
|
||||
|
@ -67,8 +69,8 @@ Packages are available in Guix master.
|
|||
|
||||
Here are the MD5 and SHA1 checksums:
|
||||
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mes-0.20.tar.gz
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx mes-0.20.tar.gz
|
||||
df839a83e4a2ad6c2a4accc5bf17b1a7 mes-0.20.tar.gz
|
||||
38d4cb3fa28fa1f5fc57fea9e046d4d8052bbb8c mes-0.20.tar.gz
|
||||
|
||||
[*] Use a .sig file to verify that the corresponding file (without the
|
||||
.sig suffix) is intact. First, be sure to download both the .sig file
|
||||
|
@ -108,6 +110,9 @@ Packages are available in Guix master.
|
|||
*** string->number now support #x hex-prefix.
|
||||
*** ungetc now has a buffer per file handle.
|
||||
|
||||
Greetings,
|
||||
janneke and Danny.
|
||||
|
||||
[0] https://www.gnu.org/software/mes
|
||||
[1] http://joyofsource.com/reduced-binary-seed-bootstrap.html
|
||||
[2] https://www.gnu.org/software/guix
|
||||
|
|
|
@ -131,7 +131,7 @@ extensive examples, including parsers for the Javascript and C99 languages.")
|
|||
(uri (string-append
|
||||
"https://ftp.gnu.org/pub/gnu/mes/mes-" version ".tar.gz"))
|
||||
(sha256
|
||||
(base32 #!mes!# "06qkwkahcpzk5v4qydpvcvzm7lx8g8pflc48f9l7bpjz6hl5lk4s"))))
|
||||
(base32 #!mes!# "04pajp8v31na34ls4730ig5f6miiplhdvkmsb9ls1b8bbmw2vb4n"))))
|
||||
(build-system gnu-build-system)
|
||||
(supported-systems '("i686-linux" "x86_64-linux"))
|
||||
(propagated-inputs
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -35,6 +35,7 @@ int isalpha (int c);
|
|||
int isascii (int c);
|
||||
int iscntrl (int c);
|
||||
int isdigit (int c);
|
||||
int isgraph (int c);
|
||||
int islower (int c);
|
||||
int isnumber (int c, int base);
|
||||
int isprint (int c);
|
||||
|
|
|
@ -38,14 +38,16 @@ int errno;
|
|||
#define ENOENT 2
|
||||
#define EINTR 4
|
||||
#define EIO 5
|
||||
#define ENXIO 6
|
||||
#define E2BIG 7
|
||||
#define ENOEXEC 8
|
||||
#define ENOEXEC 8
|
||||
#define EBADF 9
|
||||
#define ECHILD 10
|
||||
#define EAGAIN 11
|
||||
#define ENOMEM 12
|
||||
#define EACCES 13
|
||||
#define EEXIST 17
|
||||
#define EXDEV 18
|
||||
#define ENOTDIR 20
|
||||
#define EISDIR 21
|
||||
#define EINVAL 22
|
||||
|
|
|
@ -37,7 +37,13 @@
|
|||
#define O_EXCL 0x80
|
||||
#define O_TRUNC 0x200
|
||||
#define O_APPEND 0x400
|
||||
|
||||
#ifdef __arm__
|
||||
#define O_DIRECTORY 0x4000
|
||||
/*#define O_DIRECT 0x10000*/
|
||||
#else
|
||||
#define O_DIRECTORY 0x10000
|
||||
#endif
|
||||
// *INDENT-ON*
|
||||
|
||||
#define FD_CLOEXEC 1
|
||||
|
@ -48,6 +54,7 @@
|
|||
#define F_GETFL 3
|
||||
#define F_SETFL 4
|
||||
|
||||
#define creat(file_name, mode) open (file_name, O_WRONLY | O_CREAT | O_TRUNC, mode)
|
||||
int dup (int old);
|
||||
int dup2 (int old, int new);
|
||||
int fcntl (int filedes, int command, ...);
|
||||
|
|
|
@ -29,6 +29,19 @@
|
|||
#define DBL_MIN_EXP -1021
|
||||
#define LDBL_MIN_EXP -1021
|
||||
|
||||
// gcc-4.6
|
||||
#define DBL_EPSILON 1
|
||||
#define DBL_MANT_DIG 1
|
||||
#define DBL_MAX INT_MAX
|
||||
#define DBL_MIN INT_MIN
|
||||
|
||||
#define FLT_RADIX 10
|
||||
|
||||
#define LDBL_EPSILON 1
|
||||
#define LDBL_MANT_DIG 1
|
||||
#define LDBL_MAX INT_MAX
|
||||
#define LDBL_MIN INT_MIN
|
||||
|
||||
#endif // ! SYSTEM_LIBC
|
||||
|
||||
#endif // __MES_FLOAT_H
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef __MES_LINUX_ARM_SYSCALL_H
|
||||
#define __MES_LINUX_ARM_SYSCALL_H 1
|
||||
|
||||
/* See https://github.com/torvalds/linux/blob/v4.19/arch/arm/tools/syscall.tbl */
|
||||
|
||||
// libc
|
||||
#define SYS_fork 0x02
|
||||
#define SYS_read 0x03
|
||||
#define SYS_open 0x05
|
||||
//#define SYS_waitpid
|
||||
#define SYS_wait4 0x72
|
||||
#define SYS_execve 0x0b
|
||||
#define SYS_chmod 0x0f
|
||||
#define SYS_access 0x21
|
||||
#define SYS_brk 0x2d
|
||||
#define SYS_ioctl 0x36
|
||||
#define SYS_fsync 0x76
|
||||
|
||||
// libc+tcc
|
||||
#define SYS_close 0x06
|
||||
#define SYS_time 0x0d
|
||||
#define SYS_lseek 0x13
|
||||
#define SYS_unlink 0x0a
|
||||
#define SYS_rmdir 0x28
|
||||
#define SYS_gettimeofday 0x4e
|
||||
#define SYS_stat 0x6a
|
||||
#define SYS_getcwd 0xb7
|
||||
|
||||
// libc+gnu
|
||||
#define SYS_chdir 0x0c
|
||||
#define SYS_link 0x09
|
||||
#define SYS_getpid 0x14
|
||||
#define SYS_getuid 0x18
|
||||
#define SYS_kill 0x25
|
||||
#define SYS_rename 0x26
|
||||
#define SYS_mkdir 0x27
|
||||
#define SYS_dup 0x29
|
||||
#define SYS_pipe 0x2a
|
||||
#define SYS_getgid 0x2f
|
||||
#define SYS_rt_sigaction 0xae
|
||||
#define SYS_rt_sigreturn 0xad
|
||||
#define SYS_fcntl 0x37
|
||||
#define SYS_dup2 0x3f
|
||||
#define SYS_getrusage 0x4d
|
||||
#define SYS_lstat 0x6b
|
||||
#define SYS_setitimer 0x68
|
||||
#define SYS_fstat 0x6c
|
||||
#define SYS_nanosleep 0xa2
|
||||
#define SYS_getdents 0x8d
|
||||
#define SYS_clock_gettime 0x07
|
||||
|
||||
// bash
|
||||
#define SYS_setuid 0x17
|
||||
#define SYS_setgid 0x2e
|
||||
#define SYS_geteuid 0x31
|
||||
#define SYS_getegid 0x32
|
||||
#define SYS_getppid 0x40
|
||||
|
||||
// make+WITH_GLIBC
|
||||
#define SYS_rt_sigprocmask 0xaf
|
||||
|
||||
// tar
|
||||
#define SYS_symlink 0x53
|
||||
#define SYS_readlink 0x55
|
||||
#define SYS_mknod 0x0e
|
||||
|
||||
// gcc-4.6.4
|
||||
//#define SYS_mmap 0x09
|
||||
#define SYS_mmap2 0xc0
|
||||
#define SYS_munmap 0x5b
|
||||
|
||||
#endif // __MES_LINUX_ARM_SYSCALL_H
|
|
@ -83,4 +83,13 @@
|
|||
// make+POSIX
|
||||
#define SYS_sigprocmask 0x7e
|
||||
|
||||
// tar
|
||||
#define SYS_symlink 0x53
|
||||
#define SYS_readlink 0x55
|
||||
#define SYS_mknod 0x0e
|
||||
|
||||
// gcc-4.6.4
|
||||
#define SYS_mmap 0x5a
|
||||
#define SYS_munmap 0x5b
|
||||
|
||||
#endif // __MES_LINUX_X86_SYSCALL_H
|
||||
|
|
|
@ -80,4 +80,13 @@
|
|||
// make+SYSTEM_LIBC
|
||||
#define SYS_rt_sigprocmask 0x0e
|
||||
|
||||
// tar
|
||||
#define SYS_symlink 0x58
|
||||
#define SYS_readlink 0x59
|
||||
#define SYS_mknod 0x85
|
||||
|
||||
// gcc-4.6.4
|
||||
#define SYS_mmap 0x09
|
||||
#define SYS_munmap 0x0b
|
||||
|
||||
#endif // __MES_LINUX_X86_64_SYSCALL_H
|
||||
|
|
|
@ -24,8 +24,21 @@
|
|||
#undef __MES_MATH_H
|
||||
#include_next <math.h>
|
||||
#else // ! SYSTEM_LIBC
|
||||
|
||||
double atan2 (double y, double x);
|
||||
double ceil (double x);
|
||||
double cos (double x);
|
||||
double exp (double x);
|
||||
double fabs (double number);
|
||||
double floor (double x);
|
||||
long int labs (long int number);
|
||||
double ldexp (double value, int exponent);
|
||||
double log (double x);
|
||||
double modf (double value, double *integer_part);
|
||||
double pow (double base, double power);
|
||||
double sin (double x);
|
||||
double sqrt (double x);
|
||||
|
||||
#endif // ! SYSTEM_LIBC
|
||||
|
||||
#endif // __MES_MATH_H
|
||||
|
|
|
@ -28,7 +28,9 @@ void __ungetc_init ();
|
|||
void __ungetc_clear (int filedes);
|
||||
void __ungetc_set (int filedes, int c);
|
||||
int __ungetc_p (int filedes);
|
||||
double abtod (char const **p, int base);
|
||||
long abtol (char const **p, int base);
|
||||
char *dtoab (double number, int base, int signed_p);
|
||||
char *itoa (int number);
|
||||
char *ltoa (long number);
|
||||
char *ltoab (long x, int base);
|
||||
|
|
|
@ -25,12 +25,28 @@
|
|||
#include_next <setjmp.h>
|
||||
#else // ! SYSTEM_LIBC
|
||||
|
||||
#if __arm__
|
||||
typedef struct
|
||||
{
|
||||
unsigned long __r13; /* sp */
|
||||
unsigned long __r14; /* lr */
|
||||
unsigned long __r4; /* v1 */
|
||||
unsigned long __r5; /* v2 */
|
||||
unsigned long __r6; /* v3 */
|
||||
unsigned long __r7; /* v4 */
|
||||
unsigned long __r8; /* v5 */
|
||||
unsigned long __r9; /* v6 */
|
||||
unsigned long __r10; /* sl */
|
||||
unsigned long __r11; /* fp */
|
||||
} __jmp_buf;
|
||||
#else
|
||||
typedef struct
|
||||
{
|
||||
long __bp;
|
||||
long __pc;
|
||||
long __sp;
|
||||
} __jmp_buf;
|
||||
#endif
|
||||
typedef __jmp_buf jmp_buf[1];
|
||||
|
||||
#if __MESC__
|
||||
|
|
|
@ -126,6 +126,7 @@ typedef long sighandler_t;
|
|||
typedef void (*sighandler_t) (int);
|
||||
#endif
|
||||
|
||||
#if __i386__ || __x86_64__
|
||||
struct sigaction
|
||||
{
|
||||
union
|
||||
|
@ -144,7 +145,18 @@ struct sigaction
|
|||
//unsigned long sa_flags; // x86?
|
||||
void (*sa_restorer) (void);
|
||||
};
|
||||
|
||||
#else /* uapi */
|
||||
struct sigaction {
|
||||
union
|
||||
{
|
||||
sighandler_t sa_handler;
|
||||
void (*sa_sigaction) (int signum, siginfo_t *, void *);
|
||||
};
|
||||
unsigned long sa_flags;
|
||||
void (*sa_restorer) (void);
|
||||
sigset_t sa_mask;
|
||||
};
|
||||
#endif
|
||||
|
||||
#define SIG_DFL ((sighandler_t)0)
|
||||
#define SIG_IGN ((sighandler_t)1)
|
||||
|
|
|
@ -34,11 +34,14 @@
|
|||
typedef char *va_list;
|
||||
#define va_start(ap, last) (void)((ap) = (char*)(&(last) + 1))
|
||||
#define va_arg(ap, type) (type)(((long*)((ap) = ((ap) + sizeof (void*))))[-1])
|
||||
#define va_align(ap, alignment) ((char*)((((unsigned long) (ap)) + (alignment) - 1) &~ ((alignment) - 1)))
|
||||
#define va_arg8(ap, type) (type)(((double*)((ap) = (va_align((ap), 8) + sizeof(double))))[-1])
|
||||
#define va_end(ap) (void)((ap) = 0)
|
||||
#define va_copy(dest, src) dest = src
|
||||
|
||||
int vexec (char const *file_name, va_list ap);
|
||||
int vfprintf (FILE * stream, char const *template, va_list ap);
|
||||
int vfscanf (FILE * stream, char const *template, va_list ap);
|
||||
int vprintf (char const *format, va_list ap);
|
||||
int vsprintf (char *str, char const *format, va_list ap);
|
||||
int vsnprintf (char *str, size_t size, char const *format, va_list ap);
|
||||
|
|
|
@ -85,7 +85,13 @@ typedef unsigned uintmax_t;
|
|||
|
||||
#define INT_MIN -2147483648
|
||||
#define INT_MAX 2147483647
|
||||
#if __i386__
|
||||
|
||||
#define SHRT_MAX INT16_MAX
|
||||
#define SHRT_MIN INT16_MIN
|
||||
#define USHRT_MAX UINT16_MAX
|
||||
#define USHRT_MIN UINT16_MIN
|
||||
|
||||
#if __i386__ || __arm__
|
||||
#define LONG_MIN INT_MIN
|
||||
#define LONG_MAX INT_MAX
|
||||
#define UINT_MAX UINT32_MAX
|
||||
|
@ -103,6 +109,8 @@ typedef unsigned uintmax_t;
|
|||
#define SIZE_MAX UINT64_MAX
|
||||
#endif
|
||||
|
||||
#define SSIZE_MAX LONG_MAX
|
||||
|
||||
#endif // ! SYSTEM_LIBC
|
||||
|
||||
#endif // __MES_STDINT_H
|
||||
|
|
|
@ -69,6 +69,7 @@ int fprintf (FILE * stream, char const *format, ...);
|
|||
int fpurge (FILE * stream);
|
||||
int fputc (int c, FILE * stream);
|
||||
int fputs (char const *s, FILE * stream);
|
||||
int fscanf (FILE * stream, char const *template, ...);
|
||||
int fseek (FILE * stream, long offset, int whence);
|
||||
int getc (FILE * stream);
|
||||
int getchar (void);
|
||||
|
@ -78,10 +79,11 @@ int putc (int c, FILE * stream);
|
|||
int putchar (int c);
|
||||
int puts (char const *s);
|
||||
int remove (char const *file_name);
|
||||
void rewind (FILE * stream);
|
||||
int setvbuf (FILE * stream, char *buf, int mode, size_t size);
|
||||
int snprintf (char *str, size_t size, char const *format, ...);
|
||||
int sprintf (char *str, char const *format, ...);
|
||||
int sscanf (char const *str, const char *format, ...);
|
||||
int sscanf (char const *str, char const *format, ...);
|
||||
int ungetc (int c, FILE * stream);
|
||||
long ftell (FILE * stream);
|
||||
size_t fread (void *ptr, size_t size, size_t count, FILE * stream);
|
||||
|
|
|
@ -36,6 +36,7 @@ typedef int (*comparison_fn_t) (void const *, void const *);
|
|||
#include <sys/types.h>
|
||||
#include <alloca.h>
|
||||
|
||||
void abort (void);
|
||||
double atof (char const *s);
|
||||
int atoi (char const *s);
|
||||
int atexit (void (*function) (void));
|
||||
|
|
|
@ -48,6 +48,7 @@ char *strncpy (char *to, char const *from, size_t size);
|
|||
int strncmp (char const *, char const *, size_t);
|
||||
char *strrchr (char const *s, int c);
|
||||
char *strstr (char const *haystack, char const *needle);
|
||||
char *strtok (char *new_string, char const *delimiters);
|
||||
char *strlwr (char *string);
|
||||
char *strupr (char *string);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -25,19 +25,25 @@
|
|||
#include_next <sys/mman.h>
|
||||
#else // ! SYSTEM_LIBC
|
||||
|
||||
#ifndef __MES_SIZE_T
|
||||
#define __MES_SIZE_T
|
||||
typedef unsigned long size_t;
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MAP_SHARED 0x01
|
||||
#define MAP_PRIVATE 0x02
|
||||
#define MAP_ANONYMOUS 0x20
|
||||
#define MAP_POPULATE 0x08000
|
||||
|
||||
#define MAP_ANON MAP_ANONYMOUS
|
||||
#define MAP_FAILED ((void*)-1)
|
||||
|
||||
#define PROT_NONE 0
|
||||
#define PROT_READ 1
|
||||
#define PROT_WRITE 2
|
||||
#define PROT_EXEC 4
|
||||
|
||||
void *mmap (void *address, size_t length, int protect, int flags, int filedes, off_t offset);
|
||||
int mprotect (void *addr, size_t len, int prot);
|
||||
int munmap (void *addr, size_t length);
|
||||
|
||||
#endif // ! SYSTEM_LIBC
|
||||
|
||||
#endif // __MES_SYS_MMAN_H
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ typedef int mode_t;
|
|||
#endif
|
||||
|
||||
// *INDENT-OFF*
|
||||
#if __i386__
|
||||
#if __i386__ || __arm__
|
||||
struct stat
|
||||
{
|
||||
unsigned long st_dev;
|
||||
|
@ -85,10 +85,12 @@ struct stat
|
|||
int chmod (char const *file_name, mode_t mode);
|
||||
int fstat (int filedes, struct stat *buf);
|
||||
int mkdir (char const *file_name, mode_t mode);
|
||||
int mknod (char const *file_name, mode_t mode, dev_t dev);
|
||||
int chown (char const *file_name, uid_t owner, gid_t group);
|
||||
int rmdir (char const *file_name);
|
||||
int stat (char const *file_name, struct stat *buf);
|
||||
|
||||
#define S_IFIFO 0010000
|
||||
#define S_IFCHR 0020000
|
||||
#define S_IFDIR 0040000
|
||||
#define S_IFBLK 0060000
|
||||
|
@ -96,6 +98,7 @@ int stat (char const *file_name, struct stat *buf);
|
|||
#define S_IFLNK 0120000
|
||||
#define S_IFMT 0170000
|
||||
|
||||
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
|
||||
|
|
|
@ -138,6 +138,15 @@ typedef long ssize_t;
|
|||
typedef unsigned uid_t;
|
||||
#endif
|
||||
|
||||
#ifndef __WCHAR_T
|
||||
#define __WCHAR_T
|
||||
#ifndef __MES_WCHAR_T
|
||||
#define __MES_WCHAR_T
|
||||
#undef wchar_t
|
||||
typedef int wchar_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // ! SYSTEM_LIBC
|
||||
|
||||
#endif // __MES_SYS_TYPES_H
|
||||
|
|
|
@ -49,6 +49,14 @@
|
|||
#define CS8 0000060
|
||||
#define PARENB 0000400
|
||||
|
||||
struct winsize
|
||||
{
|
||||
unsigned short ws_row;
|
||||
unsigned short ws_col;
|
||||
unsigned short ws_xpixel;
|
||||
unsigned short ws_ypixel;
|
||||
};
|
||||
|
||||
struct termio
|
||||
{
|
||||
unsigned short c_iflag;
|
||||
|
|
|
@ -56,9 +56,11 @@ struct timespec
|
|||
#endif // __MES_STRUCT_TIMESPEC
|
||||
|
||||
#define CLOCK_PROCESS_CPUTIME_ID 2
|
||||
char *asctime (struct tm const *broken_time);
|
||||
int clock_gettime (clockid_t clk_id, struct timespec *tp);
|
||||
struct tm *localtime (time_t const *timep);
|
||||
struct tm *gmtime (time_t const *time);
|
||||
time_t mktime (struct tm *broken_time);
|
||||
int nanosleep (struct timespec const *requested_time, struct timespec const *remaining);
|
||||
time_t time (time_t * tloc);
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ unsigned int alarm (unsigned int seconds);
|
|||
int close (int fd);
|
||||
int execv (char const *file_name, char *const argv[]);
|
||||
int execl (char const *file_name, char const *arg, ...);
|
||||
int execlp (char const *file_name, char const *arg, ...);
|
||||
int execve (char const *file, char *const argv[], char *const env[]);
|
||||
int execvp (char const *file, char *const argv[]);
|
||||
int fork (void);
|
||||
|
@ -73,21 +74,24 @@ int setgid (gid_t newgid);
|
|||
int setuid (uid_t newuid);
|
||||
uid_t geteuid (void);
|
||||
gid_t getegid (void);
|
||||
pid_t getpgrp (void);
|
||||
pid_t getpid (void);
|
||||
pid_t getppid (void);
|
||||
int getpgid (pid_t pid);
|
||||
int isatty (int fd);
|
||||
int link (char const *oldname, char const *newname);
|
||||
int link (char const *old_name, char const *new_name);
|
||||
off_t lseek (int fd, off_t offset, int whence);
|
||||
ssize_t read (int fd, void *buffer, size_t size);
|
||||
ssize_t readlink (char const *file_name, char *buffer, size_t size);
|
||||
#if __SBRK_CHAR_PTRDIFF
|
||||
/* xmalloc in binutils <= 2.10.1 uses this old prototype */
|
||||
char *sbrk (ptrdiff_t delta);
|
||||
#else
|
||||
void *sbrk (intptr_t delta);
|
||||
#endif
|
||||
int symlink (char const *old_name, char const *new_name);
|
||||
int unlink (char const *file_name);
|
||||
ssize_t write (int filedes, void const *buffer, size_t size);
|
||||
pid_t getpid (void);
|
||||
|
||||
#endif // ! SYSTEM_LIBC
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Commentary: */
|
||||
|
||||
/* Using gdb, esp. GUD in GNU Emacs is recommended
|
||||
M-x gdb-display-disassembly-buffer
|
||||
M-x gdb-display-io-buffer
|
||||
set disassemble-next-line on
|
||||
break _start
|
||||
run
|
||||
info registers
|
||||
si
|
||||
p/x $r0
|
||||
RET
|
||||
...
|
||||
*/
|
||||
|
||||
/** Code: */
|
||||
|
||||
SYS_exit = 1 /* Linux syscall: exit. */
|
||||
.globl _start /* Magic linker symbol: --entry-address. */
|
||||
|
||||
.text /* Program text. */
|
||||
_start:
|
||||
mov r7,$SYS_exit /* System call function: exit, in r7. */
|
||||
mov r0,$42 /* First parameter: exit status, in r0. */
|
||||
swi 0 /* Call system. */
|
||||
wfi /* Should not be reached. */
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** Commentary: */
|
||||
|
||||
/* Using gdb, esp. GUD in GNU Emacs is recommended
|
||||
M-x gdb-display-disassembly-buffer
|
||||
M-x gdb-display-io-buffer
|
||||
set disassemble-next-line on
|
||||
break _start
|
||||
run
|
||||
info registers
|
||||
si
|
||||
p/x $r0
|
||||
RET
|
||||
...
|
||||
*/
|
||||
|
||||
/** Code: */
|
||||
|
||||
SYS_exit = 1 /* Linux syscalls. */
|
||||
SYS_write = 4
|
||||
stdout = 1 /* File discriptor */
|
||||
.globl _start /* Magic linker symbol: --entry-address. */
|
||||
|
||||
.text /* Program text. */
|
||||
_start:
|
||||
mov r7, $SYS_write /* System call function: write, in r7. */
|
||||
mov r0, $stdout /* 1st parameter: file descriptor, in r0. */
|
||||
add r1, pc, $(hello - here - 4) /* 2nd parameter: address, in r1. */
|
||||
here:
|
||||
mov r2, $(bye-hello) /* 3rd parameter: byte count r2. */
|
||||
swi 0 /* Call system. */
|
||||
|
||||
mov r7,$SYS_exit /* System call function: exit, in r7. */
|
||||
mov r0,$0 /* 1st parameter: exit status, in r0. */
|
||||
swi 0 /* Call system. */
|
||||
wfi /* Should not be reached. */
|
||||
|
||||
hello: .ascii "Hello, GNU Mes!\n"
|
||||
bye:
|
|
@ -0,0 +1,61 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void
|
||||
__attribute__ ((noinline))
|
||||
longjmp (jmp_buf env, int val)
|
||||
{
|
||||
// *INDENT-OFF*
|
||||
asm (
|
||||
"mov r0, %0\n\t"
|
||||
"mov r1, %1\n\t"
|
||||
"cmp r1, #0\n\t"
|
||||
"moveq r1, #1\n\t" /* returning 0 is not allowed, even when the user wanted to. */
|
||||
"ldr r13, [r0], #4\n\t" /* stack pointer (sp) */
|
||||
"ldr r14, [r0], #4\n\t" /* link register (lr) */
|
||||
"ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11}\n\t"
|
||||
// TODO: If using VFP, vldmia r0!, {d8-d15}
|
||||
"mov r0, r1\n\t"
|
||||
:
|
||||
: "r" (env), "r" (val));
|
||||
// *INDENT-ON*
|
||||
// not reached
|
||||
}
|
||||
|
||||
int
|
||||
__attribute__ ((noinline))
|
||||
setjmp (jmp_buf env)
|
||||
{
|
||||
// *INDENT-OFF*
|
||||
asm (
|
||||
"mov r0, %0\n\t"
|
||||
"str r13, [r0], #4\n\t" /* stack pointer (sp) */
|
||||
"str r14, [r0], #4\n\t" /* link register (lr) */
|
||||
"stmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11}\n\t"
|
||||
// TODO: If using VFP, vstmia r0!, {d8-d15}
|
||||
:
|
||||
: "r" (env)
|
||||
: "r0");
|
||||
// *INDENT-ON*
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
return 42;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void
|
||||
longjmp (jmp_buf env, int val)
|
||||
{
|
||||
val = val == 0 ? 1 : val;
|
||||
///asm ("!0x0c mov____0x8(%ebp),%eax"); // val
|
||||
//asm ("!0x08 ldr____%fp,(%fp,+#$i8)");
|
||||
|
||||
//asm ("!0x4 ldr____%r1,(%fp,+#$i8)"); // env.__pc
|
||||
//asm ("!0x8 ldr____%sp,(%fp,+#$i8)"); // env.__sp
|
||||
//asm ("!0x0 ldr____%fp,(%fp,+#$i8)"); // env.__bp
|
||||
asm ("jmp____*%r1");
|
||||
// not reached
|
||||
exit (42);
|
||||
}
|
||||
|
||||
int
|
||||
setjmp (__jmp_buf *env)
|
||||
{
|
||||
long *p = (long*)&env;
|
||||
//env[0].__sp = p[-2];
|
||||
//env[0].__r1 = p[-1];
|
||||
env[0].__r13 = (long)&env;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,401 @@
|
|||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
###
|
||||
### This file is part of GNU Mes.
|
||||
###
|
||||
### 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Note: r9 is used as scratch register and is assumed to not contain anything important!
|
||||
|
||||
# FIXME: https://w3challs.com/syscalls/?arch=arm_strong
|
||||
|
||||
# reduced instruction set: r0, r1 (some r2 for shift, r3 for mul, div)
|
||||
# FIXME: count instructions
|
||||
|
||||
DEFINE R0 0
|
||||
DEFINE R1 1
|
||||
DEFINE R2 2
|
||||
DEFINE R3 3
|
||||
DEFINE R7 7
|
||||
DEFINE R14 E
|
||||
DEFINE PC F
|
||||
|
||||
DEFINE IMMEDIATE32BOX 000000ea
|
||||
|
||||
# The E means "always".
|
||||
# 020090e0 # adds r0, r0, r2; ADDS = '0' op3 op1 '09' op2 'e0'
|
||||
# 030091e0 # adds r0, r1, r3
|
||||
# 031091e0 # adds r1, r1, r3
|
||||
# 030090e0 # adds r0, r0, r3
|
||||
DEFINE add____$i8,%r0 0090e2 # adds r0, r0, #xx; ADDSI = immediate op1 '09' op2 'e2'
|
||||
# 0091e2 # adds r0, r1, #xx; ADDSI = immediate op1 '09' op2 'e2'
|
||||
# 1090e2 # adds r1, r0, #xx; ADDSI = immediate op1 '09' op2 'e2'
|
||||
DEFINE add____$i8,%r1 1091e2 # adds r1, r1, #xx
|
||||
DEFINE add____$i8,%r13 d09de2 # adds r13, r13, #xx
|
||||
DEFINE sub____$i8,%r0 0050e2 # subs r0, r0, #xx
|
||||
DEFINE sub____$i8,%r1 1051e2 # subs r1, r1, #xx
|
||||
DEFINE add____%r0,%r0 000090e0 # adds r0, r0, r0
|
||||
DEFINE add____%r0,%r1 001091e0 # adds r1, r1, r0
|
||||
DEFINE add____%r1,%r0 010090e0 # adds r0, r0, r1
|
||||
DEFINE add____%r1,%r1 011091e0 # adds r1, r1, r1
|
||||
DEFINE and____%r1,%r0 010010e0 # ands r0, r0, r1
|
||||
DEFINE and____$i8,%r0 0000e2
|
||||
DEFINE and____$i8,%r1 1001e2
|
||||
DEFINE call___*%r0 00f0a0e1
|
||||
DEFINE call___*%r1 01f0a0e1
|
||||
DEFINE cmp____$i8,%r0 0050e3
|
||||
DEFINE cmp____$i8,%r1 0051e3
|
||||
DEFINE hlt 700000e1
|
||||
DEFINE swi____$0 000000ef
|
||||
DEFINE ja 8a
|
||||
DEFINE jae 3a
|
||||
DEFINE jb 2a
|
||||
DEFINE jbe 9a
|
||||
DEFINE je 0a
|
||||
DEFINE jg ca
|
||||
DEFINE jge aa
|
||||
DEFINE jl ba
|
||||
DEFINE jle da
|
||||
DEFINE jne 1a
|
||||
|
||||
# e3a00064 mov r0, #100
|
||||
# e3a01064 mov r1, #100
|
||||
# e3a02064 mov r2, #100
|
||||
|
||||
# 0: e3047215 movw r7, #16917 ; 0x4215
|
||||
|
||||
# OK:
|
||||
DEFINE mov____$i8,%r0 00a0e3
|
||||
DEFINE mov____$i8,%r1 10a0e3 # mov r1, #66
|
||||
DEFINE mov____$i8,%r7 70a0e3
|
||||
|
||||
DEFINE mvn____%r0,$i8 00e0e3
|
||||
DEFINE mvn____%r1,$i8 10e0e3
|
||||
DEFINE mvn____%r7,$i8 70e0e3
|
||||
|
||||
DEFINE mov____%r0,%r1 0010a0e1
|
||||
DEFINE mov____%r0,%r2 0020a0e1
|
||||
DEFINE mov____%r0,(%r1) 000081e5
|
||||
DEFINE mov____%r1,%r0 0100a0e1
|
||||
DEFINE mov____%r1,%r2 0120a0e1
|
||||
DEFINE mov____%esp,%r0 0d00a0e1
|
||||
|
||||
# fp -> r0
|
||||
DEFINE mov____%r11,%r0 0b00a0e1
|
||||
|
||||
# e52d1004 push {r1} ; (str r1, [sp, #-4]!)
|
||||
# e59f1008 ldr r1, [pc, #8] ; <L1>
|
||||
# e5810000 str r0, [r1]
|
||||
# e49d1004 pop {r1} ; (ldr r1, [sp], #4)
|
||||
# ea000000 b L2
|
||||
# L1: ???
|
||||
# L2:
|
||||
DEFINE mov____%r0,0x32 04102de508109fe5000081e504109de4000000ea
|
||||
|
||||
# e92d0005 push {r0, r2}
|
||||
# e5910000 ldr r0, [r1]
|
||||
# e59f200c ldr r2, [pc, #12] ; 1c <X2>
|
||||
# e0800002 add r0, r0, r2
|
||||
# e5810000 str r0, [r1]
|
||||
# e8bd0005 pop {r0, r2}
|
||||
# ea000000 b 20 <Y2>
|
||||
# X2: ???
|
||||
# Y2:
|
||||
DEFINE add____$i32,(%r1) 05002de9000091e50c209fe5020080e0000081e50500bde8000000ea
|
||||
|
||||
# e59f0000 ldr r0, [pc]
|
||||
# ea000000 b c <R>
|
||||
# nop
|
||||
# R:
|
||||
DEFINE mov____$i32,%r0 00009fe5000000ea
|
||||
DEFINE mov____$i32,%r1 00109fe5000000ea
|
||||
DEFINE mov____$i32,%r2 00209fe5000000ea
|
||||
DEFINE mov____$i32,%r7 00709fe5000000ea
|
||||
DEFINE mov____%r2,(%r1) 002081e5
|
||||
DEFINE mov____%r3,%r0 0300a0e1
|
||||
DEFINE mov____%r3,%r1 0e10a0e1
|
||||
DEFINE mov____(%r0),%r0 000090e5
|
||||
DEFINE mov____(%r0),%r2 002090e5
|
||||
DEFINE mov____(%r1),%r1 001091e5
|
||||
|
||||
DEFINE nop 0000a0e1
|
||||
DEFINE not____%r0 0000e0e1
|
||||
DEFINE not____%r1 0110e0e1
|
||||
DEFINE or_____%r1,%r0 010090e1 # orrs r0, r0, r1
|
||||
DEFINE pop____%r0 04009de4
|
||||
DEFINE pop____%r1 04109de4
|
||||
DEFINE pop____%r3 04309de4
|
||||
DEFINE pop____%lr 04e09de4
|
||||
|
||||
# e59f9004 ldr r9, [pc, #4] ; c <L1x>
|
||||
# e52d9004 push {r9} ; (str r9, [sp, #-4]!)
|
||||
# ea000000 b 10 <L1y>
|
||||
# L1x: data
|
||||
# L1y:
|
||||
|
||||
DEFINE push___$i32 04909fe504902de5000000ea
|
||||
|
||||
DEFINE push___%r0 04002de5 # str r0, [sp, #-4]!
|
||||
DEFINE push___%r1 04102de5 # str r1, [sp, #-4]!
|
||||
DEFINE push___%r2 04202de5 # str r2, [sp, #-4]!
|
||||
DEFINE push___%r3 04302de5 # str r3, [sp, #-4]!
|
||||
DEFINE push___%lr 04e02de5 # str lr, [sp, #-4]!
|
||||
|
||||
DEFINE sub____%r1,%r0 010050e0 # subs r0, r0, r1
|
||||
DEFINE test___%r0,%r0 000010e1
|
||||
DEFINE test___%r1,%r1 010011e1
|
||||
DEFINE xor____$i8,%r0 0030e2 # eors r0, r0, #xx
|
||||
DEFINE xor____%r0,%r0 000030e0 # eors r0, r0, r0
|
||||
DEFINE xor____%r1,%r0 010030e0 # eors r0, r0, r1
|
||||
DEFINE xor____%r1,%r1 011031e0 # eors r1, r1, r1
|
||||
DEFINE xor____%r3,%r3 033033e0 # eors r3, r3, r3
|
||||
|
||||
# Note: These are the native ARM instructions.
|
||||
# Note: i8 immediate
|
||||
DEFINE ldr____%r0,(%fp,+#$i8) 009be5
|
||||
DEFINE ldr____%r1,(%fp,+#$i8) 109be5
|
||||
DEFINE ldr____%r2,(%fp,+#$i8) 209be5
|
||||
DEFINE ldr____%r3,(%fp,+#$i8) 309be5
|
||||
DEFINE ldr____%r4,(%fp,+#$i8) 409be5
|
||||
DEFINE ldr____%r5,(%fp,+#$i8) 509be5
|
||||
DEFINE ldr____%r7,(%fp,+#$i8) 709be5
|
||||
DEFINE ldr____%fp,(%fp,+#$i8) b09be5
|
||||
DEFINE ldr____%sp,(%fp,+#$i8) d09be5
|
||||
DEFINE ldr____%r0,(%fp,-#$i8) 001be5
|
||||
DEFINE ldr____%r1,(%fp,-#$i8) 101be5
|
||||
DEFINE ldr____%r2,(%fp,-#$i8) 201be5
|
||||
DEFINE ldr____%r3,(%fp,-#$i8) 301be5
|
||||
DEFINE ldr____%r4,(%fp,-#$i8) 401be5
|
||||
DEFINE ldr____%r5,(%fp,-#$i8) 501be5
|
||||
DEFINE ldr____%r7,(%fp,-#$i8) 701be5
|
||||
DEFINE ldr____%fp,(%fp,-#$i8) b01be5
|
||||
DEFINE ldr____%sp,(%fp,-#$i8) d01be5
|
||||
DEFINE str____%r0,(%fp,+#$i8) 008be5
|
||||
DEFINE str____%r1,(%fp,+#$i8) 108be5
|
||||
DEFINE str____%r2,(%fp,+#$i8) 208be5
|
||||
DEFINE str____%r3,(%fp,+#$i8) 308be5
|
||||
DEFINE str____%r4,(%fp,+#$i8) 408be5
|
||||
DEFINE str____%r5,(%fp,+#$i8) 508be5
|
||||
DEFINE str____%r7,(%fp,+#$i8) 708be5
|
||||
DEFINE str____%fp,(%fp,+#$i8) b08be5
|
||||
DEFINE str____%sp,(%fp,+#$i8) d08be5
|
||||
DEFINE str____%r0,(%fp,-#$i8) 000be5
|
||||
DEFINE str____%r1,(%fp,-#$i8) 100be5
|
||||
DEFINE str____%r2,(%fp,-#$i8) 200be5
|
||||
DEFINE str____%r3,(%fp,-#$i8) 300be5
|
||||
DEFINE str____%r4,(%fp,-#$i8) 400be5
|
||||
DEFINE str____%r5,(%fp,-#$i8) 500be5
|
||||
DEFINE str____%r7,(%fp,-#$i8) 700be5
|
||||
DEFINE str____%fp,(%fp,-#$i8) b00be5
|
||||
DEFINE str____%sp,(%fp,-#$i8) d00be5
|
||||
# Note: Loads INTO register r0 (ARM original operand order)
|
||||
DEFINE ldrsb__%r0,(%r0) d000d0e1 # ldrsb r0, [r0]
|
||||
DEFINE ldrsb__%r1,(%r1) d010d1e1 # ldrsb r1, [r1]
|
||||
DEFINE ldrsb__%r2,(%r2) d020d2e1 # ldrsb r2, [r2]
|
||||
DEFINE ldrsb__%r3,(%r3) d030d3e1 # ldrsb r3, [r3]
|
||||
DEFINE ldrsb__%r4,(%r4) d040d4e1 # ldrsb r4, [r4]
|
||||
DEFINE ldrsb__%r5,(%r5) d050d5e1 # ldrsb r5, [r5]
|
||||
DEFINE ldrb___%r0,(%r1) 0000d1e5 # ldrb r0, [r1]
|
||||
DEFINE ldrh___%r0,(%r0) b000d0e1 # ldrh r0, [r0]
|
||||
DEFINE ldrh___%r0,(%r1) b000d1e1 # ldrh r0, [r1]
|
||||
DEFINE ldrh___%r1,(%r1) b010d1e1 # ldrh r1, [r1]
|
||||
DEFINE ldrh___%r2,(%r2) b020d2e1 # ldrh r2, [r2]
|
||||
DEFINE ldrh___%r3,(%r3) b030d3e1 # ldrh r3, [r3]
|
||||
DEFINE strb___%r0,(%r0) 0000c0e5 # strb r0, [r0]
|
||||
DEFINE strb___%r0,(%r1) 0000c1e5 # strb r0, [r1]
|
||||
DEFINE strb___%r1,(%r1) 0010c1e5 # strb r1, [r1]
|
||||
DEFINE strb___%r2,(%r2) 0020c2e5 # strb r2, [r2]
|
||||
DEFINE strb___%r3,(%r3) 0030c3e5 # strb r3, [r3]
|
||||
DEFINE strb___%r4,(%r4) 0040c4e5 # strb r4, [r4]
|
||||
DEFINE strb___%r0,(%fp,+#$i8) 00cbe5 # strb r0, [fp, +#xx]
|
||||
DEFINE strb___%r0,(%fp,-#$i8) 004be5 # strb r0, [fp, -#xx]
|
||||
DEFINE strh___%r0,(%r0) b000c0e1 # strh r0, [r0]
|
||||
DEFINE strh___%r0,(%r1) b000c1e1 # strh r0, [r1]
|
||||
DEFINE strh___%r1,(%r1) b010c1e1 # strh r1, [r1]
|
||||
DEFINE strh___%r2,(%r2) b020c2e1 # strh r2, [r2]
|
||||
DEFINE strh___%r3,(%r3) b030c3e1 # strh r3, [r3]
|
||||
DEFINE strh___%r4,(%r4) b040c4e1 # strh r4, [r4]
|
||||
|
||||
# There's a single instruction that does it--but I don't know how to encode it.
|
||||
# mov %r9, immediate
|
||||
# adds %r9, %r9, %fp
|
||||
# strh %r0, [%r9]
|
||||
DEFINE strh___%r0,(%fp,+#$i8) 90a0e30b9099e0b000c9e1
|
||||
|
||||
# There's a single instruction that does it--but I don't know how to encode it.
|
||||
# e3a090xx mov %r9, immediate
|
||||
# e05b9009 subs %r9, %fp, %r9
|
||||
# e1c900b0 strh %r0, [%r9]
|
||||
DEFINE strh___%r0,(%fp,-#$i8) 90a0e309905be0b000c9e1
|
||||
|
||||
DEFINE movle__%r0,$i8 00a0d3 # movle r0, #xx
|
||||
DEFINE movlt__%r0,$i8 00a0b3 # movlt r0, #xx
|
||||
DEFINE movge__%r0,$i8 00a0a3 # movge r0, #xx
|
||||
DEFINE movgt__%r0,$i8 00a0c3 # movgt r0, #xx
|
||||
DEFINE movcs__%r0,$i8 00a023 # movcs r0, #xx
|
||||
DEFINE movcc__%r0,$i8 00a033 # movcc r0, #xx
|
||||
DEFINE movhi__%r0,$i8 00a083 # movhi r0, #xx
|
||||
DEFINE moveq__%r0,$i8 00a003 # moveq r0, #xx
|
||||
DEFINE movle__%r1,$i8 10a0d3 # movle r1, #xx
|
||||
DEFINE movlt__%r1,$i8 10a0b3 # movlt r1, #xx
|
||||
DEFINE movge__%r1,$i8 10a0a3 # movge r1, #xx
|
||||
DEFINE movgt__%r1,$i8 10a0c3 # movgt r1, #xx
|
||||
DEFINE movcs__%r1,$i8 10a023 # movcs r1, #xx
|
||||
DEFINE movcc__%r1,$i8 10a033 # movcc r1, #xx
|
||||
DEFINE movhi__%r1,$i8 10a083 # movhi r1, #xx
|
||||
DEFINE moveq__%r1,$i8 10a003 # moveq r1, #xx
|
||||
|
||||
DEFINE asr____%r0,%r0,%r1 5001a0e1 # asr %r0, %r0, %r1
|
||||
DEFINE lsl____%r0,%r0,%r1 1001a0e1 # lsl %r0, %r0, %r1
|
||||
DEFINE lsl____%r0,%r0,$i8 90a0e31009a0e1 # mov r9, #xx; lsl %r0, %r0, %r9
|
||||
DEFINE lsl____%r1,%r1,$i8 90a0e31119a0e1 # mov r9, #xx; lsl %r1, %r1, %r9
|
||||
DEFINE lsr____%r0,%r0,%r1 3001a0e1 # lsr %r0, %r0, %r1
|
||||
DEFINE ldr____%r0,(%sp,#$i8) 009de5 # ldr r0, [r13+xx]
|
||||
DEFINE ldr____%r1,(%sp,#$i8) 109de5 # ldr r1, [r13+xx]
|
||||
#DEFINE add____%r2,%r0,%r1,lsl#4 012280e0
|
||||
# Without carry
|
||||
DEFINE add____%r2,%r0,%r1,lsl#2 012180e0
|
||||
DEFINE add____%r2,%r1,%r0,lsl#2 002181e0
|
||||
DEFINE add____%r2,$i8 2082e2
|
||||
DEFINE bl eb
|
||||
DEFINE b ea
|
||||
DEFINE sxtb__%r0,%r0 7000afe6
|
||||
DEFINE sxtb__%r1,%r1 7110afe6
|
||||
DEFINE sxth__%r0,%r0 7000bfe6
|
||||
DEFINE sxth__%r1,%r1 7110bfe6
|
||||
DEFINE uxtb__%r0,%r0 7000efe6
|
||||
DEFINE uxtb__%r1,%r1 7110efe6
|
||||
DEFINE uxth__%r0,%r0 7000ffe6
|
||||
DEFINE uxth__%r1,%r1 7110ffe6
|
||||
|
||||
# See: https://github.com/torvalds/linux/blob/v4.19/arch/arm/tools/syscall.tbl
|
||||
DEFINE SYS_exit 01
|
||||
DEFINE SYS_fork 02
|
||||
DEFINE SYS_read 03
|
||||
DEFINE SYS_write 04
|
||||
DEFINE SYS_open 05
|
||||
DEFINE SYS_close 06
|
||||
# DEFINE SYS_waitpid does_not_exist
|
||||
DEFINE SYS_rmdir 28
|
||||
DEFINE SYS_wait4 72
|
||||
# waitid: 0x118
|
||||
|
||||
DEFINE SYS_unlink 0a
|
||||
DEFINE SYS_execve 0b
|
||||
DEFINE SYS_chmod 0f
|
||||
DEFINE SYS_lseek 13
|
||||
DEFINE SYS_access 21
|
||||
DEFINE SYS_brk 2d
|
||||
DEFINE SYS_ioctl 36
|
||||
DEFINE SYS_stat 6a
|
||||
DEFINE SYS_fsync 76
|
||||
DEFINE SYS_getcwd b7
|
||||
|
||||
# These are x86 ABI remnants:
|
||||
|
||||
DEFINE mul____%r1,%r0 910089e0 # umull r0, r9, r1, r0
|
||||
DEFINE mul____%r0,%r1 910089e0 # umull r0, r9, r1, r0
|
||||
DEFINE mov____%ebp,%r0 0b00a0e1
|
||||
DEFINE mov____%ebp,%r1 0b10a0e1
|
||||
DEFINE push___%ebp 04b02de5 # str fp, [sp, #-4]!
|
||||
DEFINE pop____%ebp 04b09de4 # ldr fp, [sp], #4
|
||||
DEFINE mov____%esp,%ebp 0db0a0e1 # mov fp, sp
|
||||
DEFINE mov____%ebp,%esp 0bd0a0e1 # mov sp, fp
|
||||
DEFINE sub____$i8,%esp d04de2 # sub sp, sp, #xx
|
||||
|
||||
DEFINE jmp____*%r1 11ff2fe1
|
||||
|
||||
# e59f9008 ldr r9, [pc, #8] ; 10 <LX1>
|
||||
# e089900b add r9, r9, fp
|
||||
# e5890000 str r0, [r9]
|
||||
# ea000000 b 14 <LX2>
|
||||
# 00000010 <LX1>: data
|
||||
# 00000014 <LX2>:
|
||||
DEFINE mov____%r0,0x32(%ebp) 08909fe50b9089e0000089e5000000ea
|
||||
DEFINE mov____%r1,0x32(%ebp) 08909fe50b9089e0001089e5000000ea
|
||||
DEFINE mov____%r2,0x32(%ebp) 08909fe50b9089e0002089e5000000ea
|
||||
|
||||
# e59f9004 ldr r9, [pc, #4] ; c <LX1>
|
||||
# e5990000 ldr r0, [r9]
|
||||
# ea000000 b 10 <LX2>
|
||||
DEFINE mov____0x32,%r0 04909fe5000099e5000000ea
|
||||
DEFINE mov____0x32,%r1 04909fe5001099e5000000ea
|
||||
DEFINE mov____0x32,%r2 04909fe5002099e5000000ea
|
||||
|
||||
# e1a09000 mov r9, r0
|
||||
# e1a00001 mov r0, r1
|
||||
# e1a01009 mov r1, r9
|
||||
DEFINE xchg___%r0,%r1 0090a0e10100a0e10910a0e1
|
||||
|
||||
# e49de004 pop {lr} ; (ldr lr, [sp], #4)
|
||||
# e1a0f00e mov pc, lr
|
||||
DEFINE ret 04e09de40ef0a0e1
|
||||
|
||||
# The flags are also updated, but that's probably useless.
|
||||
DEFINE add____$i8,%esp d09de2
|
||||
|
||||
# e24ddeff sub sp, sp, #4080
|
||||
# e24dd064 sub sp, sp, #100
|
||||
DEFINE allocate_stack_4180 ffde4de264d04de2
|
||||
|
||||
# e59f9008 ldr r9, [pc, #8]
|
||||
# e089900b add r9, r9, fp
|
||||
# e5991000 ldr r1, [r9]
|
||||
# ea000000 b 20 <VD>
|
||||
# V: ...
|
||||
# VD:
|
||||
DEFINE mov____0x32(%ebp),%r1 08909fe50b9089e0001099e5000000ea
|
||||
DEFINE mov____0x32(%ebp),%r0 08909fe50b9089e0000099e5000000ea
|
||||
|
||||
# e1a09000 mov r9, r0
|
||||
# e59d0000 ldr r0, [sp]
|
||||
# e58d9000 str r9, [sp]
|
||||
# ea000000 b 20 <VD>
|
||||
# V: ...
|
||||
# VD:
|
||||
DEFINE xchg___%r0,(%esp) 0090a0e100009de500908de5000000ea
|
||||
|
||||
# e52d1004 push {r1} ; (str r1, [sp, #-4]!)
|
||||
# e59f1010 ldr r1, [pc, #16] ; 1c <WERT>
|
||||
# e5909000 ldr r9, [r0]
|
||||
# e0999001 adds r9, r9, r1
|
||||
# e5809000 str r9, [r0]
|
||||
# e49d1004 pop {r1} ; (ldr r1, [sp], #4)
|
||||
# ea000000 b 20 <VD>
|
||||
# V: ...
|
||||
# VD:
|
||||
DEFINE add____$i32,(%r0) 04102de510109fe5009090e5019099e0009080e504109de4000000ea
|
||||
|
||||
# mov %r9, #00
|
||||
# push {%r9}
|
||||
DEFINE push___0 0090a0e304902de5
|
||||
|
||||
# e59f9004 ldr r9, [pc, #4] ; c <VALUE>
|
||||
# e0911009 adds r1, r1, r9
|
||||
# ea000000 b 10
|
||||
# VALUE:
|
||||
DEFINE add____$i32,%r1 04909fe5091091e0000000ea
|
||||
DEFINE add____$i32,%r0 04909fe5090090e0000000ea
|
||||
DEFINE add____$i32,%r2 04909fe5092092e0000000ea
|
||||
|
||||
# e59f9008 ldr r9, [pc, #8] ; 10 <WERT>
|
||||
# e089900b add r9, r9, fp
|
||||
# e5c90000 strb r0, [r9]
|
||||
# ea000000 b 14 <WERTD>
|
||||
# WERT: nop
|
||||
# WERTD:
|
||||
DEFINE strb___%r0,0x32(%ebp) 08909fe50b9089e00000c9e5000000ea
|
||||
|
||||
DEFINE wfi bf30
|
|
@ -0,0 +1,34 @@
|
|||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
###
|
||||
### 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-exit-42.hex2: `exit 42' for arm-linux written in hex2 assembly,
|
||||
# for usage with elf32-0header.hex2. This produces a 112-byte binary
|
||||
# (70 hex). Inspiration was taken from GNU Gcc output of exit-42.S.
|
||||
|
||||
### Code:
|
||||
|
||||
# @60
|
||||
:ELF_text
|
||||
01 70 a0 e3 # mov r7,$0x1
|
||||
2a 00 a0 e3 # mov r0,$0x2a
|
||||
00 00 00 ef # swi 0
|
||||
03 f0 20 e3 # wfi
|
||||
:ELF_end
|
|
@ -0,0 +1,88 @@
|
|||
### Copyright (C) 2016 Jeremiah Orians
|
||||
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
###
|
||||
### 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-0header.hex2: Simplest 32 bit elf header in hex2. Only a text
|
||||
# segment, no data segment, no symbol tables.
|
||||
|
||||
# stage0's hex2 format for arm
|
||||
# !<label> 1 byte relative
|
||||
# $<label> 2 byte address
|
||||
# @<label> 2 byte relative
|
||||
# ~<label> 3 byte relative
|
||||
# &<label> 4 byte address
|
||||
# %<label> 4 byte relative
|
||||
# local_<label> function-local
|
||||
# string_<index> string #<index>
|
||||
# ^ align
|
||||
|
||||
### Code:
|
||||
|
||||
:ELF_base
|
||||
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
|
||||
|
||||
01 # e_ident[EI_CLASS] Indicating 32 bit
|
||||
01 # e_ident[EI_DATA] Indicating little endianness
|
||||
01 # e_ident[EI_VERSION] Indicating original elf
|
||||
|
||||
00 # e_ident[EI_OSABI] Set at 0 because none cares
|
||||
00 # e_ident[EI_ABIVERSION] See above
|
||||
|
||||
00 00 00 00 00 00 00 # e_ident[EI_PAD]
|
||||
|
||||
02 00 # e_type Indicating Executable
|
||||
28 00 # e_machine Indicating 32bit arm
|
||||
01 00 00 00 # e_version Indicating original elf
|
||||
|
||||
&ELF_text # e_entry Address of the entry point
|
||||
%ELF_program_headers>ELF_base # e_phoff Address of program header table
|
||||
00 00 00 00 # e_shoff Address of section header table
|
||||
|
||||
00 00 00 00 # e_flags
|
||||
|
||||
34 00 # e_ehsize Indicating our 52 Byte header
|
||||
|
||||
20 00 # e_phentsize size of a program header table
|
||||
01 00 # e_phnum number of entries in program table
|
||||
|
||||
00 00 # e_shentsize size of a section header table
|
||||
00 00 # e_shnum number of entries in section table
|
||||
|
||||
00 00 # e_shstrndx index of the section names
|
||||
|
||||
# @34
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
# @40
|
||||
:ELF_program_headers
|
||||
:ELF_program_header__text
|
||||
01 00 00 00 # ph_type: PT-LOAD = 1
|
||||
00 00 00 00 # ph_offset
|
||||
&ELF_base # ph_vaddr
|
||||
&ELF_base # ph_physaddr
|
||||
%ELF_end>ELF_base # ph_filesz
|
||||
%ELF_end>ELF_base # ph_memsz
|
||||
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||
01 00 00 00 # ph_align
|
||||
|
||||
# @60
|
||||
:ELF_text
|
|
@ -0,0 +1,50 @@
|
|||
### GNU Mes --- Maxwell Equations of Software
|
||||
### Copyright © 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright © 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
###
|
||||
### 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-0hello-mes.hex2: `Hello, GNU Mes!' for arm-linux written in
|
||||
# hex2 assembly, for usage with elf32-0header.hex2. This produces a
|
||||
# 160-byte binary (a0 hex). Inspiration was taken from GNU Gcc output
|
||||
# of hello-mes.S.
|
||||
|
||||
### Code:
|
||||
|
||||
# @60
|
||||
:ELF_text
|
||||
# print <hello>
|
||||
04 70 a0 e3 # mov r7, #4
|
||||
01 00 a0 e3 # mov r0, #1
|
||||
!hello 10 8f e2 # add r1, pc, $(hello - pc)
|
||||
!bye>hello 20 a0 e3 # mov r2, $(bye-hello)
|
||||
00 00 00 ef # swi 0
|
||||
|
||||
# exit 0
|
||||
01 70 a0 e3 # mov r7, #1
|
||||
00 00 a0 e3 # mov r0, #0
|
||||
00 00 00 ef # swi 0
|
||||
03 f0 20 e3 # wfi
|
||||
|
||||
# @90
|
||||
:ELF_data
|
||||
:hello
|
||||
48 65 6c 6c 6f 2c 20 47 # Hello, G
|
||||
4e 55 20 4d 65 73 21 0a # NU Mes!\n
|
||||
:bye
|
||||
:ELF_end
|
|
@ -0,0 +1,48 @@
|
|||
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
###
|
||||
### 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-body-exit-42.hex2: `exit 42' for arm-linux written in hex2
|
||||
# assembly, for usage with generic elf32-header.hex2 and
|
||||
# elf32-footer-single-main.hex.
|
||||
|
||||
# This ELF binary contains a symbol table, which means that objdump and
|
||||
# gdb can be used to inspect and debug.
|
||||
|
||||
### Code:
|
||||
|
||||
# @200
|
||||
:ELF_text
|
||||
:_start
|
||||
^~main eb # bl main
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
# @210
|
||||
:main
|
||||
01 70 a0 e3 # mov r7,$0x1
|
||||
2a 00 a0 e3 # mov r0,$0x2a
|
||||
00 00 00 ef # swi 0
|
||||
03 f0 20 e3 # wfi
|
||||
|
||||
# @220
|
||||
:ELF_data
|
||||
65 78 69 74 34 32 20 64 61 74 61 20 68 65 72 65 # exit42 data here"
|
||||
00
|
|
@ -0,0 +1,59 @@
|
|||
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
###
|
||||
### 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-body-hello-mes.hex2: `exit 42' for arm-linux written in hex2
|
||||
# assembly, for usage with generic elf32-header.hex2 and
|
||||
# elf32-footer-single-main.hex.
|
||||
|
||||
# This ELF binary contains a symbol table, which means that objdump and
|
||||
# gdb can be used to inspect and debug.
|
||||
|
||||
### Code:
|
||||
|
||||
# @200
|
||||
:ELF_text
|
||||
:_start
|
||||
^~main eb # bl main
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
# @210
|
||||
:main
|
||||
# print <hello>
|
||||
04 70 a0 e3 # mov r7, #4
|
||||
01 00 a0 e3 # mov r0, #1
|
||||
!hello 10 8f e2 # add r1, pc, $(hello - pc)
|
||||
!bye>hello 20 a0 e3 # mov r2, $(bye-hello)
|
||||
00 00 00 ef # swi 0
|
||||
|
||||
# exit 0
|
||||
01 70 a0 e3 # mov r7, #1
|
||||
00 00 a0 e3 # mov r0, #0
|
||||
00 00 00 ef # swi 0
|
||||
03 f0 20 e3 # wfi
|
||||
|
||||
# @90
|
||||
:ELF_data
|
||||
:hello
|
||||
48 65 6c 6c 6f 2c 20 47 # Hello, G
|
||||
4e 55 20 4d 65 73 21 0a # NU Mes!\n
|
||||
:bye
|
||||
:ELF_end
|
|
@ -0,0 +1,65 @@
|
|||
### Copyright (C) 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
### This file is part of stage0.
|
||||
###
|
||||
### stage0 is free software: you an 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.
|
||||
###
|
||||
### stage0 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 stage0. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
### stage0's hex2 format for arm
|
||||
### !<label> 1 byte relative
|
||||
### $<label> 2 byte address
|
||||
### @<label> 2 byte relative
|
||||
### &<label> 4 byte address
|
||||
### %<label> 4 byte relative
|
||||
### local_<label> function-local
|
||||
### string_<index> string #<index>
|
||||
|
||||
### elf32-footer-single-main.hex2: 32 bit elf footer in hex2 for single main
|
||||
|
||||
# @230
|
||||
|
||||
:ELF_str
|
||||
00 # 0
|
||||
:ELF_str__start
|
||||
5f 73 74 61 72 74 00 # _start
|
||||
:ELF_str__main
|
||||
6d 61 69 6e 00 # main
|
||||
|
||||
00 00 00
|
||||
|
||||
# @240
|
||||
:ELF_sym
|
||||
00 00 00 00 # st-name
|
||||
00 00 00 00 # st-offset: &_start - BaseAddress
|
||||
00 00 00 00 # st-len : &main - _start
|
||||
00 # st-info = stt-func= 2
|
||||
00 # st-other
|
||||
01 00 # st-shndx: 1
|
||||
|
||||
# _start
|
||||
%ELF_str__start>ELF_str # st-name
|
||||
&_start
|
||||
10 00 00 00 # st-len : &main - _start
|
||||
02 # st-info = stt-func= 2
|
||||
00 # st-other
|
||||
01 00 # st-shndx: 1
|
||||
|
||||
# main
|
||||
%ELF_str__main>ELF_str # st-name
|
||||
&main
|
||||
10 00 00 00 # st-len : &ELF_data - main
|
||||
02 # st-info = stt-func= 2
|
||||
00 # st-other
|
||||
01 00 # st-shndx: 1
|
||||
|
||||
:ELF_end
|
|
@ -0,0 +1,228 @@
|
|||
### Copyright (C) 2016 Jeremiah Orians
|
||||
### Copyright (C) 2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
### Copyright (C) 2019 Danny Milosavljevic <dannym@scratchpost.org>
|
||||
###
|
||||
### 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
### Commentary:
|
||||
|
||||
# elf32-header.hex2: 32 bit elf header in hex2, with text segment, data
|
||||
# segment and symbol tables.
|
||||
|
||||
# stage0's hex2 format for arm
|
||||
# !<label> 1 byte relative
|
||||
# $<label> 2 byte address
|
||||
# @<label> 2 byte relative
|
||||
# ~<label> 3 byte relative
|
||||
# &<label> 4 byte address
|
||||
# %<label> 4 byte relative
|
||||
# local_<label> function-local
|
||||
# string_<index> string #<index>
|
||||
# ^ align
|
||||
|
||||
### Code:
|
||||
|
||||
:ELF_base
|
||||
7F 45 4C 46 # e_ident[EI_MAG0-3] ELF's magic number
|
||||
|
||||
01 # e_ident[EI_CLASS] Indicating 32 bit
|
||||
01 # e_ident[EI_DATA] Indicating little endianness
|
||||
01 # e_ident[EI_VERSION] Indicating original elf
|
||||
|
||||
00 # e_ident[EI_OSABI] Set at 0 because none cares
|
||||
00 # e_ident[EI_ABIVERSION] See above
|
||||
|
||||
00 00 00 00 00 00 00 # e_ident[EI_PAD]
|
||||
|
||||
02 00 # e_type Indicating Executable
|
||||
28 00 # e_machine Indicating 32bit arm
|
||||
01 00 00 00 # e_version Indicating original elf
|
||||
|
||||
&ELF_text # e_entry Address of the entry point
|
||||
%ELF_program_headers>ELF_base # e_phoff Address of program header table
|
||||
%ELF_section_headers>ELF_base # e_shoff Address of section header table
|
||||
|
||||
00 00 00 00 # e_flags
|
||||
|
||||
34 00 # e_ehsize Indicating our 52 Byte header
|
||||
|
||||
20 00 # e_phentsize size of a program header table
|
||||
01 00 # e_phnum number of entries in program table
|
||||
|
||||
28 00 # e_shentsize size of a section header table
|
||||
07 00 # e_shnum number of entries in section table
|
||||
|
||||
04 00 # e_shstrndx index of the section names
|
||||
|
||||
# @34
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
# @40
|
||||
:ELF_program_headers
|
||||
:ELF_program_header__text
|
||||
01 00 00 00 # ph_type: PT-LOAD = 1
|
||||
00 00 00 00 # ph_offset
|
||||
&ELF_base # ph_vaddr
|
||||
&ELF_base # ph_physaddr
|
||||
%ELF_end>ELF_base # ph_filesz
|
||||
%ELF_end>ELF_base # ph_memsz
|
||||
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||
01 00 00 00 # ph_align
|
||||
|
||||
# @60
|
||||
#:ELF_program_header__data # NOT USED
|
||||
# FIXME: linux 4.17 does not allow this overlap
|
||||
# Uhuuh, elf segment at 0000000001000000
|
||||
# requested but the memory is mapped already
|
||||
01 00 00 00 # ph_type: PT-LOAD = 1
|
||||
00 00 00 00 # ph_offset
|
||||
&ELF_base # ph_vaddr
|
||||
&ELF_base # ph_physaddr
|
||||
%ELF_end>ELF_base # ph_filesz
|
||||
%ELF_end>ELF_base # ph_memsz
|
||||
07 00 00 00 # ph_flags: PF-X|PF-W|PF-R = 7
|
||||
01 00 00 00 # ph_align
|
||||
|
||||
# @80
|
||||
:ELF_comment
|
||||
4d 45 53 00 # MES
|
||||
00 00 00 00 # align
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
4d 45 53 00 # MES
|
||||
00 00 00 00 # align
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
# @a0
|
||||
:ELF_shstr
|
||||
00
|
||||
:ELF_shstr__text
|
||||
2e 74 65 78 74 00 # .text
|
||||
:ELF_shstr__data
|
||||
2e 64 61 74 61 00 # .data
|
||||
:ELF_shstr__comment
|
||||
2e 63 6f 6d 6d 65 6e 74 00 # .comment
|
||||
:ELF_shstr__shstr
|
||||
2e 73 68 73 74 72 74 61 62 00 # .shstrtab
|
||||
:ELF_shstr__sym
|
||||
2e 73 79 6d 74 61 62 00 # .symtab
|
||||
:ELF_shstr__str
|
||||
2e 73 74 72 74 61 62 00 # .strtab
|
||||
|
||||
# @d0
|
||||
|
||||
:ELF_section_headers
|
||||
00 00 00 00 # sh_name
|
||||
00 00 00 00 # sh_type
|
||||
00 00 00 00 # sh_flags
|
||||
00 00 00 00 # sh_addr
|
||||
00 00 00 00 # sh_offset
|
||||
00 00 00 00 # sh_length
|
||||
00 00 00 00 # sh_link
|
||||
00 00 00 00 # sh_info
|
||||
01 00 00 00 # sh_1?
|
||||
00 00 00 00 # sh_entsize
|
||||
|
||||
## FIXME: M0 for calculations?
|
||||
:ELF_section_header_text
|
||||
%ELF_shstr__text>ELF_shstr # sh_name
|
||||
01 00 00 00 # sh_type = SHT_PROGBITS = 1
|
||||
06 00 00 00 # sh_flags = SHF-ALLOC|SHF-EXEC =2 | 4 = 6
|
||||
&ELF_text # sh_addr
|
||||
%ELF_text>ELF_base # sh_offset
|
||||
%ELF_data>ELF_text # sh_length
|
||||
00 00 00 00 # sh_link
|
||||
00 00 00 00 # sh_info
|
||||
01 00 00 00 # sh_1?
|
||||
00 00 00 00 # sh_entsize
|
||||
|
||||
:ELF_section_header_data
|
||||
%ELF_shstr__data>ELF_shstr # sh_name
|
||||
01 00 00 00 # sh_type = SHT_PROGBITS = 1
|
||||
03 00 00 00 # sh_flags = SHF-WRITE|SHF-ALLOC = 1 | 2 = 3
|
||||
&ELF_data # sh_addr
|
||||
%ELF_data>ELF_base # sh_offset
|
||||
%ELF_sym>ELF_data # sh_length
|
||||
00 00 00 00 # sh_link
|
||||
00 00 00 00 # sh_info
|
||||
01 00 00 00 # sh_1?
|
||||
00 00 00 00 # sh_entsize
|
||||
|
||||
:ELF_section_header_comment
|
||||
%ELF_shstr__comment>ELF_shstr # sh_name
|
||||
01 00 00 00 # sh_type = SHT_PROGBITS = 1
|
||||
00 00 00 00 # sh_flags
|
||||
&ELF_comment # sh_addr
|
||||
%ELF_comment>ELF_base # sh_offset
|
||||
%ELF_shstr>ELF_comment # sh_length
|
||||
00 00 00 00 # sh_link
|
||||
00 00 00 00 # sh_info
|
||||
01 00 00 00 # sh_1?
|
||||
00 00 00 00 # sh_entsize
|
||||
|
||||
:ELF_section_header_shstr
|
||||
%ELF_shstr__shstr>ELF_shstr # sh_name
|
||||
03 00 00 00 # sh_type: str-sht-strtab
|
||||
00 00 00 00 # sh_flags
|
||||
&ELF_shstr # sh_addr
|
||||
%ELF_shstr>ELF_base # sh_offset
|
||||
%ELF_section_headers>ELF_shstr # sh_length
|
||||
00 00 00 00 # sh_link
|
||||
00 00 00 00 # sh_info
|
||||
01 00 00 00 # sh_1?
|
||||
00 00 00 00 # sh_entsize
|
||||
|
||||
:ELF_section_header_sym
|
||||
%ELF_shstr__sym>ELF_shstr # sh_name
|
||||
02 00 00 00 # sh_type: str-sht-symtab
|
||||
00 00 00 00 # sh_flags
|
||||
&ELF_sym # sh_addr
|
||||
%ELF_sym>ELF_base # sh_offset
|
||||
%ELF_end>ELF_sym # sh_length
|
||||
06 00 00 00 # sh_link:6
|
||||
00 00 00 00 # sh_info
|
||||
01 00 00 00 # sh_1?
|
||||
10 00 00 00 # sh_entsize
|
||||
|
||||
:ELF_section_header_str
|
||||
%ELF_shstr__str>ELF_shstr # sh_name
|
||||
03 00 00 00 # sh_type: str-sht-strtab
|
||||
00 00 00 00 # sh_flags
|
||||
&ELF_str # sh_addr
|
||||
%ELF_str>ELF_base # sh_offset
|
||||
%ELF_sym>ELF_str # sh_length
|
||||
00 00 00 00 # sh_link
|
||||
00 00 00 00 # sh_info
|
||||
01 00 00 00 # sh_1?
|
||||
00 00 00 00 # sh_entsize
|
||||
|
||||
# @1e8
|
||||
00 00 00 00 # align
|
||||
00 00 00 00
|
||||
|
||||
# @1f0
|
||||
|
||||
00 00 00 00 # align
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
00 00 00 00
|
||||
|
||||
# @200
|
||||
:ELF_text
|
|
@ -0,0 +1,27 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
int
|
||||
isgraph (int c)
|
||||
{
|
||||
return c > 32 && c < 127;
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib-mini.h>
|
||||
//int main (int argc, char *argv[], char *envp[]);
|
||||
|
||||
/* Note: GCC automatically emits a preable in order to set up the frame pointer:
|
||||
"push {fp}"
|
||||
"add fp, sp, 0"
|
||||
*/
|
||||
// *INDENT-OFF*
|
||||
void
|
||||
_start ()
|
||||
{
|
||||
asm (
|
||||
"mov r0,#0\n\t"
|
||||
"mov %0,r0\n"
|
||||
: "=r" (__stdin)
|
||||
: //no inputs ""
|
||||
);
|
||||
|
||||
asm (
|
||||
"mov r0,#1\n\t"
|
||||
"mov %0,r0\n"
|
||||
: "=r" (__stdout)
|
||||
: //no inputs ""
|
||||
);
|
||||
|
||||
asm (
|
||||
"mov r0,#2\n\t"
|
||||
"mov %0,r0\n"
|
||||
: "=r" (__stderr)
|
||||
: //no inputs ""
|
||||
);
|
||||
|
||||
/* environ = argv + argc + 1 */
|
||||
asm (
|
||||
"ldr r0,[fp,#4]\n\t" /* r0 = argc */
|
||||
"add r1,fp,#8\n\t" /* r1 = &argv[0] */
|
||||
"add r2,r0,#1\n\t" /* r2 = r0 + 1 */
|
||||
"lsl r2,#2\n\t" /* r2 = (r0 + 1) << 2 */
|
||||
"add r2,r2,r1\n\t" /* r2 = ((r0 + 1) << 2) + r1 */
|
||||
"push {r2}\n\t" /* envp */
|
||||
"push {r1}\n\t" /* argv */
|
||||
"push {r0}\n\t" /* argc */
|
||||
"mov %0,r2\n\t"
|
||||
: "=r" (environ)
|
||||
: //no inputs ""
|
||||
);
|
||||
asm (
|
||||
"ldr r0,[sp]\n\t" /* argc */
|
||||
"ldr r1,[sp, #4]\n\t" /* argv */
|
||||
"ldr r2,[sp, #8]\n\t" /* envp */
|
||||
"bl main\n\t"
|
||||
"mov r7, #1\n\t"
|
||||
"swi #0\n\t"
|
||||
"wfi \n\t"
|
||||
);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mes/lib-mini.h"
|
||||
|
||||
#define SYS_exit "0x01"
|
||||
#define SYS_write "0x04"
|
||||
|
||||
// *INDENT-OFF*
|
||||
void
|
||||
_exit (int code)
|
||||
{
|
||||
asm (
|
||||
"mov r7, $"SYS_exit"\n\t"
|
||||
"mov r0, %0\n\t"
|
||||
"swi $0\n\t"
|
||||
: // no outputs "=" (r)
|
||||
: "r" (code)
|
||||
: "r0", "r7"
|
||||
);
|
||||
// not reached
|
||||
_exit (0);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
_write (int filedes, void const *buffer, size_t size)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov r7, $"SYS_write"\n\t"
|
||||
"mov r0, %1\n\t"
|
||||
"mov r1, %2\n\t"
|
||||
"mov r3, %3\n\t"
|
||||
"swi $0\n\t"
|
||||
"mov %0, r0\n\t"
|
||||
: "=r" (r)
|
||||
: "r" (filedes), "r" (buffer), "r" (size)
|
||||
: "r0", "r1", "r2", "r7"
|
||||
);
|
||||
return r;
|
||||
}
|
||||
// *INDENT-ON*
|
|
@ -0,0 +1,166 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <linux/x86/syscall.h>
|
||||
|
||||
// *INDENT-OFF*
|
||||
long
|
||||
_sys_call (long sys_call)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov r7, %1\n\t"
|
||||
"swi $0\n\t"
|
||||
"mov %0, r0\n\t"
|
||||
: "=r" (r)
|
||||
: "r" (sys_call)
|
||||
: "r0", "r7"
|
||||
);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
long
|
||||
_sys_call1 (long sys_call, long one)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov r7, %1\n\t"
|
||||
"mov r0, %2\n\t"
|
||||
"swi $0\n\t"
|
||||
"mov %0, r0\n\t"
|
||||
: "=r" (r)
|
||||
: "r" (sys_call), "r" (one)
|
||||
: "r0", "r7"
|
||||
);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
long
|
||||
_sys_call2 (long sys_call, long one, long two)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov r7, %1\n\t"
|
||||
"mov r0, %2\n\t"
|
||||
"mov r1, %3\n\t"
|
||||
"swi $0\n\t"
|
||||
"mov %0, r0\n\t"
|
||||
: "=r" (r)
|
||||
: "r" (sys_call), "r" (one), "r" (two)
|
||||
: "r0", "r1", "r7"
|
||||
);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
long
|
||||
_sys_call3 (long sys_call, long one, long two, long three)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov r7, %1\n\t"
|
||||
"mov r0, %2\n\t"
|
||||
"mov r1, %3\n\t"
|
||||
"mov r2, %4\n\t"
|
||||
"swi $0\n\t"
|
||||
"mov %0, r0\n\t"
|
||||
: "=r" (r)
|
||||
: "r" (sys_call), "r" (one), "r" (two), "r" (three)
|
||||
: "r0", "r1", "r2", "r7"
|
||||
);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
long
|
||||
_sys_call4 (long sys_call, long one, long two, long three, long four)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov r7, %1\n\t"
|
||||
"mov r0, %2\n\t"
|
||||
"mov r1, %3\n\t"
|
||||
"mov r2, %4\n\t"
|
||||
"mov r3, %5\n\t"
|
||||
"swi $0\n\t"
|
||||
"mov %0, r0\n\t"
|
||||
: "=r" (r)
|
||||
: "r" (sys_call), "r" (one), "r" (two), "r" (three), "r" (four)
|
||||
: "r0", "r1", "r2", "r3", "r7"
|
||||
);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
#if 0
|
||||
long
|
||||
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov r7, %1\n\t"
|
||||
"mov r0, %2\n\t"
|
||||
"mov r1, %3\n\t"
|
||||
"mov r2, %4\n\t"
|
||||
"mov r3, %5\n\t"
|
||||
"mov r4, %6\n\t"
|
||||
"mov r5, %7\n\t"
|
||||
"swi $0\n\t"
|
||||
"mov %0, r0\n\t"
|
||||
: "=r" (r)
|
||||
: "r" (sys_call), "r" (one), "r" (two), "r" (three), "r" (four), "r" (five), "r" (six)
|
||||
: "r0", "r1", "r2", "r3", "r4", "r5" //, "r7" FIXME
|
||||
);
|
||||
return r;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,70 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mes/lib-mini.h"
|
||||
|
||||
int main (int argc, char *argv[], char *envp[]);
|
||||
|
||||
void /* must not return */
|
||||
_start ()
|
||||
{
|
||||
/*
|
||||
|
||||
sp+1 argv
|
||||
sp -> argc
|
||||
|
||||
environ = &argv[argc + 1]
|
||||
|
||||
HOWEVER, the function entry already allocated space for locals on the stack (after saving lr and fp, which moved sp again). Hence, use fp instead of sp.
|
||||
*/
|
||||
|
||||
/* stdin = 0 */
|
||||
|
||||
asm ("!0 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stdin");
|
||||
|
||||
/* stdout = 1 */
|
||||
|
||||
asm ("!1 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stdout");
|
||||
|
||||
/* stderr = 2 */
|
||||
|
||||
asm ("!2 mov____$i8,%r0");
|
||||
asm ("mov____%r0,0x32 &__stderr");
|
||||
|
||||
/* Add "environ" to main's arguments */
|
||||
|
||||
asm ("!8 ldr____%r0,(%fp,+#$i8)"); /* "argc" */
|
||||
asm ("!12 ldr____%r1,(%fp,+#$i8)"); /* "argv" */
|
||||
asm ("add____%r2,%r1,%r0,lsl#2"); /* "environ": argv + argc */
|
||||
asm ("!4 add____%r2,$i8"); /* "environ": argv + argc + 1 */
|
||||
|
||||
asm ("push___%r2");
|
||||
asm ("push___%r1");
|
||||
asm ("push___%r0");
|
||||
|
||||
main ();
|
||||
|
||||
//asm ("mov____%r0,%r0");
|
||||
asm ("SYS_exit mov____$i8,%r7");
|
||||
asm ("swi____$0");
|
||||
asm ("hlt");
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void
|
||||
_exit ()
|
||||
{
|
||||
asm ("SYS_exit mov____$i8,%r7");
|
||||
asm ("!8 ldr____%r0,(%fp,+#$i8)");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
void
|
||||
_write ()
|
||||
{
|
||||
asm ("SYS_write mov____$i8,%r7");
|
||||
asm ("!8 ldr____%r0,(%fp,+#$i8)");
|
||||
asm ("!12 ldr____%r1,(%fp,+#$i8)");
|
||||
asm ("!16 ldr____%r2,(%fp,+#$i8)");
|
||||
asm ("swi____$0");
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <linux/x86/syscall.h>
|
||||
|
||||
int
|
||||
__sys_call (int sys_call)
|
||||
{
|
||||
asm ("!8 ldr____%r7,(%fp,+#$i8)");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call1 (int sys_call, int one)
|
||||
{
|
||||
asm ("!8 ldr____%r7,(%fp,+#$i8)");
|
||||
asm ("!12 ldr____%r0,(%fp,+#$i8)");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call2 (int sys_call, int one, int two)
|
||||
{
|
||||
asm ("!8 ldr____%r7,(%fp,+#$i8)");
|
||||
asm ("!12 ldr____%r0,(%fp,+#$i8)");
|
||||
asm ("!16 ldr____%r1,(%fp,+#$i8)");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call3 (int sys_call, int one, int two, int three)
|
||||
{
|
||||
asm ("!8 ldr____%r7,(%fp,+#$i8)");
|
||||
asm ("!12 ldr____%r0,(%fp,+#$i8)");
|
||||
asm ("!16 ldr____%r1,(%fp,+#$i8)");
|
||||
asm ("!20 ldr____%r2,(%fp,+#$i8)");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call4 (int sys_call, int one, int two, int three, int four)
|
||||
{
|
||||
asm ("!8 ldr____%r7,(%fp,+#$i8)");
|
||||
asm ("!12 ldr____%r0,(%fp,+#$i8)");
|
||||
asm ("!16 ldr____%r1,(%fp,+#$i8)");
|
||||
asm ("!20 ldr____%r2,(%fp,+#$i8)");
|
||||
asm ("!24 ldr____%r3,(%fp,+#$i8)");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
|
||||
{
|
||||
asm ("!8 ldr____%r7,(%fp,+#$i8)");
|
||||
asm ("!12 ldr____%r0,(%fp,+#$i8)");
|
||||
asm ("!16 ldr____%r1,(%fp,+#$i8)");
|
||||
asm ("!20 ldr____%r2,(%fp,+#$i8)");
|
||||
asm ("!24 ldr____%r3,(%fp,+#$i8)");
|
||||
asm ("!28 ldr____%r4,(%fp,+#$i8)");
|
||||
asm ("!32 ldr____%r5,(%fp,+#$i8)");
|
||||
asm ("swi____$0");
|
||||
}
|
||||
|
||||
int
|
||||
_sys_call (int sys_call)
|
||||
{
|
||||
int r = __sys_call (sys_call);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
_sys_call1 (int sys_call, int one)
|
||||
{
|
||||
int r = __sys_call1 (sys_call, one);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
_sys_call2 (int sys_call, int one, int two)
|
||||
{
|
||||
int r = __sys_call2 (sys_call, one, two);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
_sys_call3 (int sys_call, int one, int two, int three)
|
||||
{
|
||||
int r = __sys_call3 (sys_call, one, two, three);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
_sys_call4 (int sys_call, int one, int two, int three, int four)
|
||||
{
|
||||
int r = __sys_call4 (sys_call, one, two, three, four);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
_sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
|
||||
{
|
||||
int r = __sys_call6 (sys_call, one, two, three, four, five, six);
|
||||
if (r < 0)
|
||||
{
|
||||
errno = -r;
|
||||
r = -1;
|
||||
}
|
||||
else
|
||||
errno = 0;
|
||||
return r;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/syscall.h>
|
||||
#include <syscall.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
int
|
||||
mknod (char const *file_name, mode_t mode, dev_t dev)
|
||||
{
|
||||
return _sys_call3 (SYS_mknod, (long) file_name, (long) mode, (long) dev);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/syscall.h>
|
||||
#include <syscall.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#if SYS_mmap
|
||||
|
||||
void *
|
||||
mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
return (void *)_sys_call6 (SYS_mmap, (long) addr, (long) len, (int) prot, (int) flags, (int) fd, (long) offset);
|
||||
}
|
||||
|
||||
#elif SYS_mmap2
|
||||
|
||||
#include <assert.h>
|
||||
#include <mes/lib.h>
|
||||
|
||||
void *
|
||||
mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
eputs ("TODO: mmap/mmap2\n");
|
||||
assert(0);
|
||||
return (void *)_sys_call6 (SYS_mmap2, (long) addr, (long) len, (int) prot, (int) flags, (int) fd, (long) offset);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/syscall.h>
|
||||
#include <syscall.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
int
|
||||
munmap (void *addr, size_t length)
|
||||
{
|
||||
return _sys_call2 (SYS_munmap, (long) addr, (long) length);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/syscall.h>
|
||||
#include <syscall.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
ssize_t
|
||||
readlink (char const *file_name, char *buffer, size_t size)
|
||||
{
|
||||
return _sys_call3 (SYS_readlink, (long) file_name, (long) buffer, (long) size);
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <linux/syscall.h>
|
||||
#include <syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int
|
||||
symlink (char const *old_name, char const *new_name)
|
||||
{
|
||||
return _sys_call2 (SYS_symlink, (long) old_name, (long) new_name);
|
||||
}
|
|
@ -22,8 +22,45 @@
|
|||
#include <syscall.h>
|
||||
#include <time.h>
|
||||
|
||||
#if SYS_time
|
||||
|
||||
time_t
|
||||
time (time_t * result)
|
||||
{
|
||||
return _sys_call1 (SYS_time, (long) result);
|
||||
}
|
||||
|
||||
#elif SYS_gettimeofday
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
time_t
|
||||
time (time_t * result)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
gettimeofday (&tv, &tz);
|
||||
if (result)
|
||||
*result = tv.tv_sec;
|
||||
return tv.tv_sec;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#warning there is no time
|
||||
|
||||
#include <mes/lib.h>
|
||||
|
||||
time_t
|
||||
time (time_t * result)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("time stub\n");
|
||||
stub = 1;
|
||||
if (result)
|
||||
*result = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,7 @@ waitpid (pid_t pid, int *status_ptr, int options)
|
|||
{
|
||||
#if __i386__
|
||||
return _sys_call3 (SYS_waitpid, (long) pid, (long) status_ptr, (int) options);
|
||||
#elif __x86_64__
|
||||
#elif __x86_64__ || __arm__
|
||||
return _sys_call4 (SYS_wait4, (long) pid, (long) status_ptr, (int) options, 0);
|
||||
#else
|
||||
#error arch not supported
|
||||
|
|
|
@ -141,3 +141,20 @@ _sys_call4 (long sys_call, long one, long two, long three, long four)
|
|||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
long
|
||||
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov %1,%%eax\n\t"
|
||||
"mov %%ebp,%%ebx\n\t"
|
||||
"add $0x0c,%%ebx\n\t"
|
||||
"int $0x80\n\t"
|
||||
"mov %%eax,%0\n\t"
|
||||
: "=r" (r)
|
||||
: "rm" (sys_call)
|
||||
: "eax", "ebx"
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -66,6 +66,15 @@ __sys_call4 (int sys_call, int one, int two, int three, int four)
|
|||
asm ("int____$0x80");
|
||||
}
|
||||
|
||||
int
|
||||
__sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
|
||||
{
|
||||
asm ("mov____0x8(%ebp),%eax !0x08");
|
||||
asm ("mov____%ebp,%ebx");
|
||||
asm ("add____$i8,%ebx !0x0c");
|
||||
asm ("int____$0x80");
|
||||
}
|
||||
|
||||
int
|
||||
_sys_call (int sys_call)
|
||||
{
|
||||
|
@ -135,3 +144,9 @@ _sys_call4 (int sys_call, int one, int two, int three, int four)
|
|||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
_sys_call6 (int sys_call, int one, int two, int three, int four, int five, int six)
|
||||
{
|
||||
return __sys_call6 (sys_call, one, two, three, four, five, six);
|
||||
}
|
||||
|
|
|
@ -150,3 +150,26 @@ _sys_call4 (long sys_call, long one, long two, long three, long four)
|
|||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
long
|
||||
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
|
||||
{
|
||||
long r;
|
||||
asm (
|
||||
"mov %2,%%rdi\n\t"
|
||||
"mov %3,%%rsi\n\t"
|
||||
"mov %4,%%rdx\n\t"
|
||||
"mov %5,%%r10\n\t"
|
||||
"mov %6,%%r8\n\t"
|
||||
"mov %7,%%r9\n\t"
|
||||
"mov %1,%%rax\n\t"
|
||||
// );
|
||||
// asm (
|
||||
"syscall \n\t"
|
||||
"mov %%rax,%0\n\t"
|
||||
: "=r" (r)
|
||||
: "rm" (sys_call), "rm" (one), "rm" (two), "rm" (three), "rm" (four), "rm" (five), "rm" (six)
|
||||
: "rax", "rdi", "rsi", "rdx", "r10", "r8", "r9"
|
||||
);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
long
|
||||
//__sys_call (long one, long two, long three, long four)
|
||||
__sys_call (long sys_call, long one, long two, long three, long four)
|
||||
__sys_call (long sys_call, long one, long two, long three, long four, long five, long six)
|
||||
{
|
||||
#if 1 // !MES_CCAMD64
|
||||
// asm ("mov____0x8(%rbp),%rdi !0x10");
|
||||
|
@ -37,6 +37,8 @@ __sys_call (long sys_call, long one, long two, long three, long four)
|
|||
asm ("mov____0x8(%rbp),%rsi !0x20");
|
||||
asm ("mov____0x8(%rbp),%rdx !0x28");
|
||||
asm ("mov____0x8(%rbp),%r10 !0x30");
|
||||
asm ("mov____0x8(%rbp),%r8 !0x38");
|
||||
asm ("mov____0x8(%rbp),%r9 !0x40");
|
||||
#endif
|
||||
|
||||
asm ("syscall");
|
||||
|
@ -121,3 +123,12 @@ _sys_call4 (long sys_call, long one, long two, long three, long four)
|
|||
errno = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
long
|
||||
_sys_call6 (long sys_call, long one, long two, long three, long four, long five, long six)
|
||||
{
|
||||
// long rax = sys_call;
|
||||
// long r = __sys_call6 (one, two, three, four, five, six);
|
||||
long r = __sys_call (sys_call, one, two, three, four, five, six);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
double
|
||||
ceil (double number)
|
||||
{
|
||||
long i = number + 0.9999;
|
||||
number = i;
|
||||
return number;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -18,7 +18,7 @@
|
|||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//#include <math.h>
|
||||
#include <math.h>
|
||||
|
||||
double
|
||||
fabs (double number)
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
double
|
||||
floor (double number)
|
||||
{
|
||||
long i = number;
|
||||
number = i;
|
||||
return number;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
long int
|
||||
labs (long int number)
|
||||
{
|
||||
if (number < 0)
|
||||
return -number;
|
||||
return number;
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
|
||||
double
|
||||
abtod (char const **p, int base)
|
||||
{
|
||||
char const *s = *p;
|
||||
double d = 0;
|
||||
int sign_p = 0;
|
||||
if (!base)
|
||||
base = 10;
|
||||
double dbase = base;
|
||||
long i = abtol (&s, base);
|
||||
long f = 0;
|
||||
long e = 0;
|
||||
if (*s == '.')
|
||||
{
|
||||
s++;
|
||||
f = abtol (&s, base);
|
||||
}
|
||||
if (*s == 'e')
|
||||
{
|
||||
s++;
|
||||
e = abtol (&s, base);
|
||||
}
|
||||
d = i + f / dbase;
|
||||
if (e < 0)
|
||||
while (e++)
|
||||
d = d / dbase;
|
||||
while (e--)
|
||||
d = d * dbase;
|
||||
*p = s;
|
||||
return sign_p ? -d : d;
|
||||
}
|
|
@ -26,12 +26,16 @@ abtol (char const **p, int base)
|
|||
{
|
||||
char const *s = *p;
|
||||
int i = 0;
|
||||
int sign = 1;
|
||||
int sign_p = 0;
|
||||
if (!base)
|
||||
base = 10;
|
||||
while (isspace (*s))
|
||||
s++;
|
||||
if (*s && *s == '+')
|
||||
s++;
|
||||
if (*s && *s == '-')
|
||||
{
|
||||
sign = -1;
|
||||
sign_p = 1;
|
||||
s++;
|
||||
}
|
||||
while (isnumber (*s, base))
|
||||
|
@ -42,5 +46,5 @@ abtol (char const **p, int base)
|
|||
s++;
|
||||
}
|
||||
*p = s;
|
||||
return i * sign;
|
||||
return sign_p ? -i : i;
|
||||
}
|
||||
|
|
|
@ -108,3 +108,49 @@ ldiv_t ldiv(long a, long b)
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
#if __GNUC__ && !SYSTEM_LIBC && __arm__
|
||||
// /gnu/store/7sfr3vhxq7l4mai8m0fr1cd8w9xcj9dh-binutils-2.31.1/bin/ld: hash.o: in function `hash_cstring':
|
||||
// hash.c:(.text+0x56): undefined reference to `__aeabi_idivmod'
|
||||
// /gnu/store/7sfr3vhxq7l4mai8m0fr1cd8w9xcj9dh-binutils-2.31.1/bin/ld: math.o: in function `divide':
|
||||
// math.c:(.text+0x516): undefined reference to `__aeabi_idiv'
|
||||
// /gnu/store/7sfr3vhxq7l4mai8m0fr1cd8w9xcj9dh-binutils-2.31.1/bin/ld: math.o: in function `modulo':
|
||||
// math.c:(.text+0x5d2): undefined reference to `__aeabi_idivmod'
|
||||
// /gnu/store/7sfr3vhxq7l4mai8m0fr1cd8w9xcj9dh-binutils-2.31.1/bin/ld: gcc-lib/libc.a(ntoab.o): in function `ntoab':
|
||||
// ntoab.c:(.text+0x54): undefined reference to `__aeabi_uidivmod'
|
||||
// /gnu/store/7sfr3vhxq7l4mai8m0fr1cd8w9xcj9dh-binutils-2.31.1/bin/ld: ntoab.c:(.text+0x62): undefined reference to `__aeabi_uidiv'
|
||||
/* Result: r0: quotient; r1: remainder */
|
||||
long
|
||||
__aeabi_idivmod (long a, long b)
|
||||
{
|
||||
ldiv_t result = ldiv(a, b);
|
||||
register long rem_result asm("r1");
|
||||
rem_result = result.rem;
|
||||
return result.quot;
|
||||
}
|
||||
|
||||
long
|
||||
__aeabi_idiv (long a, long b)
|
||||
{
|
||||
ldiv_t result = ldiv(a, b);
|
||||
return result.quot;
|
||||
}
|
||||
|
||||
/* Result: r0: quotient; r1: remainder */
|
||||
unsigned long
|
||||
__aeabi_uidivmod (unsigned long a, unsigned long b)
|
||||
{
|
||||
unsigned long quot;
|
||||
unsigned long rem;
|
||||
register unsigned long rem_result asm("r1");
|
||||
quot = __mesabi_uldiv (a, b, &rem);
|
||||
rem_result = rem;
|
||||
return quot;
|
||||
}
|
||||
|
||||
unsigned long
|
||||
__aeabi_uidiv (unsigned long a, unsigned long b)
|
||||
{
|
||||
return __mesabi_uldiv (a, b, 0);
|
||||
}
|
||||
#endif // __GNUC__ && !SYSTEM_LIBC && __arm__
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
dtoab (double d, int base, int signed_p)
|
||||
{
|
||||
static char dtoa_buf[40];
|
||||
long i = (long) d;
|
||||
char *p = ntoab (i, base, signed_p);
|
||||
strcpy (dtoa_buf, p);
|
||||
long f = (d - (double) i) * (double) 100000000;
|
||||
if (f)
|
||||
{
|
||||
if (f < 0)
|
||||
f = -f;
|
||||
strcat (dtoa_buf, ".");
|
||||
p = ntoab (f, base, 1);
|
||||
strcat (dtoa_buf, p);
|
||||
p = strchr (dtoa_buf, 0);
|
||||
p--;
|
||||
while (*p && *p == '0')
|
||||
*p-- = 0;
|
||||
}
|
||||
return dtoa_buf;
|
||||
}
|
|
@ -23,22 +23,13 @@
|
|||
#include <unistd.h>
|
||||
|
||||
int
|
||||
execl (char const *file_name, char const *arg, ...)
|
||||
vexec (char const *file_name, va_list ap)
|
||||
{
|
||||
if (__mes_debug () > 2)
|
||||
{
|
||||
eputs ("execl ");
|
||||
eputs (file_name);
|
||||
eputs ("\n");
|
||||
}
|
||||
char *arg = va_arg (ap, char *);
|
||||
char *argv[1000]; // POSIX minimum 4096
|
||||
int i = 0;
|
||||
|
||||
va_list ap;
|
||||
va_start (ap, arg);
|
||||
|
||||
argv[i++] = (char *)file_name;
|
||||
arg = va_arg (ap, char const *);
|
||||
argv[i++] = (char *) file_name;
|
||||
while (arg)
|
||||
{
|
||||
argv[i++] = arg;
|
||||
|
@ -57,3 +48,20 @@ execl (char const *file_name, char const *arg, ...)
|
|||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
execl (char const *file_name, char const *arg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int r;
|
||||
va_start (ap, arg);
|
||||
if (__mes_debug () > 2)
|
||||
{
|
||||
eputs ("execl ");
|
||||
eputs (file_name);
|
||||
eputs ("\n");
|
||||
}
|
||||
r = vexec (file_name, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int
|
||||
execlp (char const *file_name, char const *arg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int r;
|
||||
va_start (ap, arg);
|
||||
if (file_name[0] != '/')
|
||||
file_name = search_path (file_name);
|
||||
if (__mes_debug () > 2)
|
||||
{
|
||||
eputs ("execlp ");
|
||||
eputs (file_name ? file_name : "0");
|
||||
eputs ("\n");
|
||||
}
|
||||
if (!file_name)
|
||||
{
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
r = vexec (file_name, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -25,5 +25,8 @@
|
|||
int
|
||||
fflush (FILE * stream)
|
||||
{
|
||||
fsync ((long) stream);
|
||||
int filedes = (long) stream;
|
||||
if (filedes < 3)
|
||||
return 0;
|
||||
return fsync (filedes);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
fscanf (FILE * stream, char const *template, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, template);
|
||||
int r = vfscanf (stream, template, ap);
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -18,16 +18,10 @@
|
|||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
rewind (int x)
|
||||
void
|
||||
rewind (FILE * stream)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("rewind stub\n");
|
||||
stub = 1;
|
||||
errno = 0;
|
||||
return 0;
|
||||
fseek (stream, 0, SEEK_SET);
|
||||
}
|
|
@ -23,7 +23,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int
|
||||
sscanf (char const *str, const char *template, ...)
|
||||
sscanf (char const *str, char const *template, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, template);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -33,7 +33,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
if (*p != '%')
|
||||
{
|
||||
count++;
|
||||
fputc (*p++, fd);
|
||||
fputc (*p++, f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -41,6 +41,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
char c = *p;
|
||||
int left_p = 0;
|
||||
int precision = -1;
|
||||
int prefix_p = 0;
|
||||
int width = -1;
|
||||
if (c == '-')
|
||||
{
|
||||
|
@ -48,10 +49,20 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
c = *++p;
|
||||
}
|
||||
char pad = ' ';
|
||||
if (c == ' ')
|
||||
{
|
||||
pad = c;
|
||||
c = *++p;
|
||||
}
|
||||
if (c == '#')
|
||||
{
|
||||
prefix_p = 1;
|
||||
c = *++p;
|
||||
}
|
||||
if (c == '0')
|
||||
{
|
||||
pad = c;
|
||||
c = *p++;
|
||||
c = *++p;
|
||||
}
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
|
@ -88,7 +99,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
{
|
||||
case '%':
|
||||
{
|
||||
fputc (*p, fd);
|
||||
fputc (*p, f);
|
||||
count++;
|
||||
break;
|
||||
}
|
||||
|
@ -96,7 +107,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
{
|
||||
char _c;
|
||||
_c = va_arg (ap, long);
|
||||
fputc (_c, fd);
|
||||
fputc (_c, f);
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
|
@ -108,7 +119,7 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
{
|
||||
long d = va_arg (ap, long);
|
||||
int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10;
|
||||
char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
|
||||
char *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
|
||||
if (c == 'X')
|
||||
strupr (s);
|
||||
int length = strlen (s);
|
||||
|
@ -129,6 +140,18 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
count++;
|
||||
}
|
||||
}
|
||||
if (prefix_p && *s && c == 'o')
|
||||
{
|
||||
fputc ('0', f);
|
||||
width--;
|
||||
}
|
||||
if (prefix_p && *s && (c == 'x' || c == 'X'))
|
||||
{
|
||||
fputc ('0', f);
|
||||
width--;
|
||||
fputc ('x', f);
|
||||
width--;
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
|
@ -182,6 +205,50 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
double d = va_arg8 (ap, double);
|
||||
char *s = dtoab (d, 10, 1);
|
||||
if (c == 'E' || c == 'G')
|
||||
strupr (s);
|
||||
int length = strlen (s);
|
||||
if (precision == -1)
|
||||
precision = length;
|
||||
if (!left_p)
|
||||
{
|
||||
while (width-- > precision)
|
||||
{
|
||||
fputc (pad, f);
|
||||
count++;
|
||||
}
|
||||
while (precision > length)
|
||||
{
|
||||
fputc (' ', f);
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
break;
|
||||
width--;
|
||||
fputc (*s++, f);
|
||||
count++;
|
||||
}
|
||||
while (width > 0)
|
||||
{
|
||||
width--;
|
||||
fputc (pad, f);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'n':
|
||||
{
|
||||
int *n = va_arg (ap, int *);
|
||||
|
@ -192,6 +259,8 @@ vfprintf (FILE * f, char const *format, va_list ap)
|
|||
{
|
||||
eputs ("vfprintf: not supported: %:");
|
||||
eputc (c);
|
||||
eputs (", in format: ");
|
||||
eputs (format);
|
||||
eputs ("\n");
|
||||
p++;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,208 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int
|
||||
vfscanf (FILE * stream, char const *template, va_list ap)
|
||||
{
|
||||
char r = fgetc (stream);
|
||||
char const *t = template;
|
||||
int count = 0;
|
||||
while (*t && r != EOF)
|
||||
if (*t != '%')
|
||||
{
|
||||
t++;
|
||||
r = fgetc (stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
t++;
|
||||
char c = *t;
|
||||
int skip_p = 0;
|
||||
int length = -1;
|
||||
if (c == '*')
|
||||
skip_p = 1;
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
length = abtol (&t, 10);
|
||||
c = *t;
|
||||
}
|
||||
if (c == 'l')
|
||||
c = *++t;
|
||||
switch (c)
|
||||
{
|
||||
case '%':
|
||||
{
|
||||
r = fgetc (stream);
|
||||
break;
|
||||
}
|
||||
case 'c':
|
||||
{
|
||||
r = fgetc (stream);
|
||||
if (!skip_p)
|
||||
{
|
||||
char *c = va_arg (ap, char *);
|
||||
*c = r;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
{
|
||||
int *d = skip_p ? 0 : va_arg (ap, int *);
|
||||
char buf[20];
|
||||
char *q = buf;
|
||||
if (r == '+' || r == '-')
|
||||
{
|
||||
*q++ = r;
|
||||
r = fgetc (stream);
|
||||
}
|
||||
while (isdigit (r))
|
||||
{
|
||||
*q++ = r;
|
||||
r = fgetc (stream);
|
||||
}
|
||||
ungetc (r, stream);
|
||||
*q = 0;
|
||||
q = buf;
|
||||
if (skip_p)
|
||||
abtol ((char const **) &q, 10);
|
||||
else
|
||||
{
|
||||
*d = abtol ((char const **) &q, 10);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'E':
|
||||
case 'G':
|
||||
{
|
||||
float *f = skip_p ? 0 : va_arg (ap, float *);
|
||||
char buf[20];
|
||||
char *q = buf;
|
||||
if (r == '+' || r == '-')
|
||||
{
|
||||
*q++ = r;
|
||||
r = fgetc (stream);
|
||||
}
|
||||
while (isdigit (r))
|
||||
{
|
||||
*q++ = r;
|
||||
r = fgetc (stream);
|
||||
}
|
||||
ungetc (r, stream);
|
||||
*q = 0;
|
||||
q = buf;
|
||||
if (skip_p)
|
||||
strtod (q, &q);
|
||||
else
|
||||
{
|
||||
*f = strtod (q, &q);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
{
|
||||
char *s = skip_p ? 0 : va_arg (ap, char *);
|
||||
while (r && !isspace (r) && (length == -1 || length--))
|
||||
{
|
||||
if (!skip_p)
|
||||
*s++ = r;
|
||||
r = fgetc (stream);
|
||||
}
|
||||
if (!skip_p)
|
||||
{
|
||||
count++;
|
||||
*s = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '[':
|
||||
{
|
||||
char *s = skip_p ? 0 : va_arg (ap, char *);
|
||||
char set[1024];
|
||||
int i = 0;
|
||||
int not_in_set_p = 0;
|
||||
t++;
|
||||
if (*t == '^')
|
||||
{
|
||||
not_in_set_p = 1;
|
||||
t++;
|
||||
}
|
||||
if (*t == ']' || *t == '-')
|
||||
set[i++] = *t++;
|
||||
while (*t && *t != ']')
|
||||
{
|
||||
if (*t == '-')
|
||||
{
|
||||
char end = *t++;
|
||||
for (char x = set[i - 1] + 1; x < end; x++)
|
||||
set[i++] = x;
|
||||
}
|
||||
else
|
||||
set[i++] = *t++;
|
||||
}
|
||||
set[i] = 0;
|
||||
while (r && (length == -1 || length--))
|
||||
{
|
||||
int match = (int) (long) strchr (set, r);
|
||||
if (not_in_set_p)
|
||||
match = !match;
|
||||
if (!match)
|
||||
break;
|
||||
if (!skip_p)
|
||||
*s++ = r;
|
||||
r = fgetc (stream);
|
||||
}
|
||||
if (!skip_p)
|
||||
{
|
||||
count++;
|
||||
*s = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eputs ("vsscanf: not supported: %:");
|
||||
eputc (c);
|
||||
eputs (", in template: ");
|
||||
eputs (template);
|
||||
eputs ("\n");
|
||||
t++;
|
||||
r = fgetc (stream);
|
||||
}
|
||||
}
|
||||
t++;
|
||||
}
|
||||
va_end (ap);
|
||||
return count;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -43,6 +43,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
|
|||
c = *p;
|
||||
int left_p = 0;
|
||||
int precision = -1;
|
||||
int prefix_p = 0;
|
||||
int width = -1;
|
||||
if (c == '-')
|
||||
{
|
||||
|
@ -50,10 +51,20 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
|
|||
c = *++p;
|
||||
}
|
||||
char pad = ' ';
|
||||
if (c == ' ')
|
||||
{
|
||||
pad = c;
|
||||
c = *++p;
|
||||
}
|
||||
if (c == '#')
|
||||
{
|
||||
prefix_p = 1;
|
||||
c = *++p;
|
||||
}
|
||||
if (c == '0')
|
||||
{
|
||||
pad = c;
|
||||
c = *p++;
|
||||
c = *++p;
|
||||
}
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
|
@ -114,7 +125,7 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
|
|||
{
|
||||
long d = va_arg (ap, long);
|
||||
int base = c == 'o' ? 8 : c == 'x' || c == 'X' ? 16 : 10;
|
||||
char const *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
|
||||
char *s = ntoab (d, base, c != 'u' && c != 'x' && c != 'X');
|
||||
if (c == 'X')
|
||||
strupr (s);
|
||||
int length = strlen (s);
|
||||
|
@ -137,6 +148,18 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
|
|||
count++;
|
||||
}
|
||||
}
|
||||
if (prefix_p && *s && c == 'o')
|
||||
{
|
||||
*s++ = '0';
|
||||
width--;
|
||||
}
|
||||
if (prefix_p && *s && (c == 'x' || c == 'X'))
|
||||
{
|
||||
*s++ = '0';
|
||||
width--;
|
||||
*s++ = 'x';
|
||||
width--;
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
|
@ -198,6 +221,55 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
{
|
||||
double d = va_arg8 (ap, double);
|
||||
char *s = dtoab (d, 10, 1);
|
||||
if (c == 'E' || c == 'G')
|
||||
strupr (s);
|
||||
int length = strlen (s);
|
||||
if (precision == -1)
|
||||
precision = length;
|
||||
if (!left_p)
|
||||
{
|
||||
while (width-- > precision)
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = pad;
|
||||
count++;
|
||||
}
|
||||
while (precision > length)
|
||||
{
|
||||
if (count < size)
|
||||
*str++ = ' ';
|
||||
precision--;
|
||||
width--;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
while (*s)
|
||||
{
|
||||
if (precision-- <= 0)
|
||||
break;
|
||||
width--;
|
||||
c = *s++;
|
||||
if (count < size)
|
||||
*str++ = c;
|
||||
count++;
|
||||
}
|
||||
while (width > 0)
|
||||
{
|
||||
width--;
|
||||
if (count < size)
|
||||
*str++ = pad;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'n':
|
||||
{
|
||||
int *n = va_arg (ap, int *);
|
||||
|
@ -208,6 +280,8 @@ vsnprintf (char *str, size_t size, char const *format, va_list ap)
|
|||
{
|
||||
eputs ("vsnprintf: not supported: %:");
|
||||
eputc (c);
|
||||
eputs (", in format: ");
|
||||
eputs (format);
|
||||
eputs ("\n");
|
||||
p++;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -41,6 +41,15 @@ vsscanf (char const *s, char const *template, va_list ap)
|
|||
{
|
||||
t++;
|
||||
char c = *t;
|
||||
int skip_p = 0;
|
||||
int length = -1;
|
||||
if (c == '*')
|
||||
skip_p = 1;
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
length = abtol (&t, 10);
|
||||
c = *t;
|
||||
}
|
||||
if (c == 'l')
|
||||
c = *++t;
|
||||
switch (c)
|
||||
|
@ -52,24 +61,113 @@ vsscanf (char const *s, char const *template, va_list ap)
|
|||
}
|
||||
case 'c':
|
||||
{
|
||||
char *c = va_arg (ap, char *);
|
||||
*c = *p++;
|
||||
count++;
|
||||
char r = *p++;
|
||||
if (!skip_p)
|
||||
{
|
||||
char *c = va_arg (ap, char *);
|
||||
*c = r;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'u':
|
||||
{
|
||||
int *d = va_arg (ap, int *);
|
||||
*d = abtol ((char const **)&p, 10);
|
||||
count++;
|
||||
if (skip_p)
|
||||
abtol ((char const **) &p, 10);
|
||||
else
|
||||
{
|
||||
int *d = va_arg (ap, int *);
|
||||
*d = abtol ((char const **) &p, 10);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'g':
|
||||
case 'E':
|
||||
case 'G':
|
||||
{
|
||||
if (skip_p)
|
||||
strtod (p, &p);
|
||||
else
|
||||
{
|
||||
float *f = va_arg (ap, float *);
|
||||
*f = strtod (p, &p);
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 's':
|
||||
{
|
||||
char *s = skip_p ? 0 : va_arg (ap, char *);
|
||||
char r = *p;
|
||||
while (r && !isspace (r) && (length == -1 || length--))
|
||||
{
|
||||
if (!skip_p)
|
||||
*s++ = r;
|
||||
r = *++p;
|
||||
}
|
||||
if (!skip_p)
|
||||
{
|
||||
count++;
|
||||
*s = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '[':
|
||||
{
|
||||
char *s = skip_p ? 0 : va_arg (ap, char *);
|
||||
char set[1024];
|
||||
int i = 0;
|
||||
int not_in_set_p = 0;
|
||||
t++;
|
||||
if (*t == '^')
|
||||
{
|
||||
not_in_set_p = 1;
|
||||
t++;
|
||||
}
|
||||
if (*t == ']' || *t == '-')
|
||||
set[i++] = *t++;
|
||||
while (*t && *t != ']')
|
||||
{
|
||||
if (*t == '-')
|
||||
{
|
||||
char end = *t++;
|
||||
for (char x = set[i - 1] + 1; x < end; x++)
|
||||
set[i++] = x;
|
||||
}
|
||||
else
|
||||
set[i++] = *t++;
|
||||
}
|
||||
set[i] = 0;
|
||||
char r = *p;
|
||||
while (r && (length == -1 || length--))
|
||||
{
|
||||
int match = (int) (long) strchr (set, r);
|
||||
if (not_in_set_p)
|
||||
match = !match;
|
||||
if (!match)
|
||||
break;
|
||||
if (!skip_p)
|
||||
*s++ = r;
|
||||
r = *++p;
|
||||
}
|
||||
if (!skip_p)
|
||||
{
|
||||
count++;
|
||||
*s = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eputs ("vsscanf: not supported: %:");
|
||||
eputc (c);
|
||||
eputs (", in template: ");
|
||||
eputs (template);
|
||||
eputs ("\n");
|
||||
t++;
|
||||
p++;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -18,6 +18,8 @@
|
|||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
__exit (int status)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -18,8 +18,16 @@
|
|||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void
|
||||
abort (void)
|
||||
{
|
||||
#if __arm__
|
||||
asm ("wfi");
|
||||
#else
|
||||
asm ("hlt");
|
||||
#endif
|
||||
// not reached
|
||||
exit (77);
|
||||
}
|
||||
|
|
|
@ -25,4 +25,5 @@ int
|
|||
atexit (void (*function) (void))
|
||||
{
|
||||
__call_at_exit = function;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -20,12 +20,9 @@
|
|||
|
||||
#include <mes/lib.h>
|
||||
|
||||
int
|
||||
atof (int x)
|
||||
double
|
||||
atof (char const *string)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("atof stub\n");
|
||||
stub = 1;
|
||||
return 0;
|
||||
char const *p = string;
|
||||
return abtod (&p, 0);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -21,8 +21,8 @@
|
|||
#include <mes/lib.h>
|
||||
|
||||
int
|
||||
atoi (char const *s)
|
||||
atoi (char const *string)
|
||||
{
|
||||
char const *p = s;
|
||||
char const *p = string;
|
||||
return abtol (&p, 0);
|
||||
}
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if !__MESC__
|
||||
typedef char wchar_t[];
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
mbstowcs (wchar_t * wstring, char const *string, size_t size)
|
||||
|
@ -33,4 +33,3 @@ mbstowcs (wchar_t * wstring, char const *string, size_t size)
|
|||
strcpy (wstring, string);
|
||||
return strlen (string);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -18,13 +18,15 @@
|
|||
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
qswap (void *a, void *b, size_t size)
|
||||
{
|
||||
char *buf[8];
|
||||
char buf[128];
|
||||
assert (size <= sizeof (buf));
|
||||
memcpy (buf, a, size);
|
||||
memcpy (a, b, size);
|
||||
memcpy (b, buf, size);
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
double
|
||||
strtod (char const *string, char **tailptr)
|
||||
{
|
||||
int base = 10;
|
||||
if (!strncmp (string, "0x", 2))
|
||||
{
|
||||
string += 2;
|
||||
base = 16;
|
||||
}
|
||||
if (tailptr)
|
||||
{
|
||||
*tailptr = (char *) string;
|
||||
return abtod ((char const **) tailptr, base);
|
||||
}
|
||||
char **p = (char **) &string;
|
||||
return abtod ((char const **) p, base);
|
||||
}
|
|
@ -21,7 +21,11 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if BZERO_INT
|
||||
int
|
||||
#else
|
||||
void
|
||||
#endif
|
||||
bzero (void *block, size_t size)
|
||||
{
|
||||
return (int) (long) memset (block, 0, size);
|
||||
|
|
|
@ -20,8 +20,12 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#if INDEX_INT
|
||||
int
|
||||
#else
|
||||
char *
|
||||
#endif
|
||||
index (char const *s, int c)
|
||||
{
|
||||
return (int) (long) strchr (s, c);
|
||||
return strchr (s, c);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,11 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#if INDEX_INT
|
||||
int
|
||||
#else
|
||||
char *
|
||||
#endif
|
||||
rindex (char const *s, int c)
|
||||
{
|
||||
return strrchr (s, c);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
size_t
|
||||
strcspn (char const *string, char const *stopset)
|
||||
{
|
||||
char *p = string;
|
||||
char *p = (char *) string;
|
||||
while (*p)
|
||||
if (strchr (stopset, *p))
|
||||
break;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
char *
|
||||
strpbrk (char const *string, char const *stopset)
|
||||
{
|
||||
char *p = string;
|
||||
char *p = (char *) string;
|
||||
while (*p)
|
||||
if (strchr (stopset, *p))
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strtok (char *new_string, char const *delimiters)
|
||||
{
|
||||
static char *mark;
|
||||
if (new_string)
|
||||
mark = new_string;
|
||||
if (!*mark)
|
||||
return 0;
|
||||
while (strchr (delimiters, *mark))
|
||||
mark++;
|
||||
char *point = mark;
|
||||
while (*mark && !strchr (delimiters, *mark))
|
||||
mark++;
|
||||
if (*mark)
|
||||
{
|
||||
*mark = 0;
|
||||
mark++;
|
||||
}
|
||||
return point;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
char *
|
||||
asctime (struct tm const *broken_time)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("asctime stub\n");
|
||||
stub = 1;
|
||||
errno = 0;
|
||||
return "now";
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* This file is part of GNU Mes.
|
||||
*
|
||||
|
@ -19,14 +19,14 @@
|
|||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
double
|
||||
strtod (char const *string, char **tailptr)
|
||||
atan2 (double x, double y)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("strtod stub\n");
|
||||
eputs ("atan2 stub\n");
|
||||
stub = 1;
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <math.h>
|
||||
|
||||
double
|
||||
cos (double x)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("cos stub\n");
|
||||
stub = 1;
|
||||
return 0;
|
||||
}
|
|
@ -22,13 +22,13 @@
|
|||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
int
|
||||
ctime (int x)
|
||||
char *
|
||||
ctime (time_t const *TIME)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("ctime stub\n");
|
||||
stub = 1;
|
||||
errno = 0;
|
||||
return 0;
|
||||
return "now";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <math.h>
|
||||
|
||||
double
|
||||
exp (double x)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("exp stub\n");
|
||||
stub = 1;
|
||||
return 0;
|
||||
}
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#include <mes/lib.h>
|
||||
|
||||
int
|
||||
double
|
||||
frexp (int x)
|
||||
{
|
||||
static int stub = 0;
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/* -*-comment-start: "//";comment-end:""-*-
|
||||
* GNU Mes --- Maxwell Equations of Software
|
||||
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <mes/lib.h>
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
|
||||
struct group *
|
||||
getgrgid (gid_t gid)
|
||||
{
|
||||
static int stub = 0;
|
||||
if (__mes_debug () && !stub)
|
||||
eputs ("getgrid stub\n");
|
||||
static char *groups[2] = { "root", 0 };
|
||||
#if SYSTEM_LIBC
|
||||
static struct group root = { "root", 0, 0 };
|
||||
root.gr_mem = groups;
|
||||
#else
|
||||
static struct group root = { "root", 0, groups };
|
||||
#endif
|
||||
stub = 1;
|
||||
errno = 0;
|
||||
return &root;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue