Compare commits

...

58 Commits

Author SHA1 Message Date
Jan Nieuwenhuizen 4f6f9897a5
Revert "WIP mescc: hack, hack, hack: compile _exit.c -- almost"
This reverts commit 22b86745867e2dc9f93805f384597a1de0082b1e.
2019-09-09 18:48:56 +02:00
Jan Nieuwenhuizen ec5de76bdd
WIP mescc: hack, hack, hack: compile _exit.c -- almost
MES_DEBUG=3 ../pre-inst-env mescc -c -m 32 -c -D HAVE_CONFIG_H=1 -I ../lib -I include -I ../include -I ../include/gnu/x86 -L ../lib -static -o _exit.o ../lib/gnu/_exit.c

fork stub, execve stub
2019-09-09 18:48:56 +02:00
Jan Nieuwenhuizen 23732d1ef5
mescc: Mes C Library: Fix access stub.
* lib/stub/access.c (access): Use _open3 to give more meaningful
behaviour.  Fixes hanging of mes.
2019-09-09 18:48:56 +02:00
Jan Nieuwenhuizen a7db65b693
hurd: Fixes for upgrade to debian-hurd-20190220.img.
* include/mach/mach-init.h (__mach_host_self, __mach_task_self):
Remove macro magic.
(mach_host_self, mach_task_self): Remove macro magic; declare as function.
* lib/mach/mach-init.c (mach_host_self, mach_task_self): New function.
(mach_init): Use them.
* lib/gnu/hurd-start.c (_hurd_start): Use mach_task_self ().
* lib/gnu/_exit.c (_exit): Likewise.
2019-09-09 18:48:56 +02:00
Jan Nieuwenhuizen 200140a175
hurd: Add malloc.
* include/gnu/syscall.h (__vm_allocate): New value.
(__vm_allocate): Declare.
* lib/gnu/malloc.c: New file.
* lib/unix/malloc.c: Move from stdlib.
* lib/gnu/vm-allocate.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES): Add it.
2019-09-09 18:48:56 +02:00
Jan Nieuwenhuizen dfa1428b61
hurd: Add open.
* include/fcntl.h (O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_APPEND,
O_TRUNC)[__GNU__]: Specialize for GNU.
* lib/gnu/dir-lookup.c: New file.
* lib/stdio/fopen.c (fopen): Use O_RDONLY.
* lib/tests/posix/50-open-read.c (main): Likewise.
* lib/tests/stdio/90-fseek.c (main): Likewise.
* include/gnu/syscall.h (SYS__dir_lookup): New value.
* lib/gnu/_open3.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES): Build them.
2019-09-09 18:48:56 +02:00
Jan Nieuwenhuizen 0f79659090
hurd: Add argv and environ.
* include/gnu/hurd.h (struct hurd_startup_data): Add argp, envp.
* lib/gnu/hurd-start.c (__argv, __env): Define them.
* lib/gnu/exec-startup-get-data.c (mach_startup_info2hurd_startup_data):
Set them.
* lib/gnu/x86-mes-gcc/crt1.c (_start): Use them.
* build-aux/configure-lib.sh (libc_mini_SOURCES): Add argz-extract.c.
* include/argz.h: Build fix.
* lib/string/argz-count.c: Likewise.
* lib/string/argz-extract.c: Likewise.
2019-09-09 18:48:55 +02:00
Jan Nieuwenhuizen 52728f37a9
hurd: Add stubs for missing libc+tcc functions.
* lib/stub/close.c: New file.
* lib/stub/rmdir.c: New file.
* lib/stub/stat.c: New file.
* build-aux/configure-lib.sh (libc_tcc_SOURCES)[gnu]: Add them.
2019-09-09 18:48:55 +02:00
Jan Nieuwenhuizen 31b3a3a98c
hurd: Add stubs for missing libc functions.
* lib/stub/_getcwd.c: New file.
* lib/stub/_getcwd.c: New file.
* lib/stub/_open3.c: New file.
* lib/stub/access.c: New file.
* lib/stub/brk.c: New file.
* lib/stub/chmod.c: New file.
* lib/stub/clock_gettime.c: New file.
* lib/stub/dup.c: New file.
* lib/stub/dup2.c: New file.
* lib/stub/execve.c: New file.
* lib/stub/fork.c: New file.
* lib/stub/gettimeofday.c: New file.
* lib/stub/ioctl.c: New file.
* lib/stub/time.c: New file.
* lib/stub/unlink.c: New file.
* lib/stub/waitpid.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES)[gnu]: Add them.
2019-09-09 18:48:55 +02:00
Jan Nieuwenhuizen 47db24c409
hurd: Add stubs for missing libmes functions.
* lib/stub/lseek.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES)[gnu]: Add it.
2019-09-09 18:48:55 +02:00
Jan Nieuwenhuizen 49f83a1749
hurd: Add _read.
* include/gnu/hurd.h (fd_read): Declare.
* include/gnu/syscall.h (SYS__io_read): New value.
* lib/gnu/_read.c: New file.
* lib/gnu/fd-read.c: New file.
* lib/gnu/io-read.c: New file.
* build-aux/configure-lib.sh (libc_SOURCES): Add _read sources.
2019-09-09 18:48:55 +02:00
Jan Nieuwenhuizen ae0064ca64
hurd: Add _write.
* include/gnu/syscall.h (SYS__io_write): Add enum field.
(_hurd_dtable, _hurd_dtable_size): Declare variable.
(fd_get, fd_write, __io_write, __syscall_put): Declare.
* lib/gnu/hurd-start.c (_hurd_dtable, _hurd_dtable_size): Define
variable.
* lib/gnu/_write.c: New file.
* lib/gnu/fd-get.c (fd_get): New file.
* lib/gnu/fd-write.c (fd_write): New file.
* lib/gnu/io-write.c: New file.
* lib/gnu/syscall.c (__syscall_put): New function.
* build-aux/cofnigure-lib.sh (libc_mini_SOURCES): Add write sources.
* lib/tests/mes/30-oputs.c (main): Update.
* lib/tests/mes/30-oputs.stdout: New file.
* lib/tests/mes/30-eputs.c: New test.
* lib/tests/mes/30-eputs.stderr: New file.
* build-aux/check-mescc.sh (TESTS): Add it.
2019-09-09 18:48:55 +02:00
Jan Nieuwenhuizen 5eaa46a5e7
hurd: Initial support.
This adds minimal Hurd support by implementing the _exit function.

* AUTHORS: Update.
* .gitignore: Ignore a.out, core, .config.
* include/sys/wait.h (W_EXITCODE): New define.
* lib/linux/x86-mes-gcc/crt1.c (_start): Call _exit to allow reuse.
* lib/gnu/x86-mes-gcc/crt1.c: New file.
* lib/gnu/x86-mes-gcc/mini.c: New file.
* lib/gnu/hurd-start.c: New file.
* lib/gnu/_exit.c: New file.
* include/gnu/syscall.h: New file.
* include/gnu/hurd.h: New file.
* lib/gnu/_exit.c: New file.
* lib/gnu/exec-startup-get-data.c: New file.
* lib/gnu/hurd-start.c: New file.
* lib/gnu/proc-mark-exit.c: New file.
* lib/gnu/syscall.c: New file.
* lib/gnu/task-get-special-port.c: New file.
* lib/gnu/task-terminate.c: New file.
* lib/gnu/vm-statistics.c: New file.
* build-aux/configure-lib.sh (libc_mini_SOURCES): Add Hurd sources.
* build-aux/build.sh.in (CPPFLAGS): Add lib to includes, to find linux
crt1.c.
* build-aux/test-c.sh: Always use at least -l c+mini for GNU.
* lib/tests/scaffold/00-exit-42.exit: New file.
* lib/tests/scaffold/00-exit-42.c: New test.
* build-aux/check-mescc.sh (TESTS): Add it.
* lib/tests/scaffold/00-exit-0.c (main): Rewrite, use _exit.
* include/gnu/hurd-types.h: Import from GNU C Library.
* include/mach/mach-init.h: Likewise.
* lib/mach/mach-init.c: Likewise.
* lib/mach/mach_host_self.S: Likewise.
* lib/mach/mach_msg_trap.S: Likewise.
* lib/mach/mach_reply_port.S: Likewise.
* lib/mach/mach_task_self.S: Likewise.
* lib/mach/mach_thread_self.S: Likewise.
* lib/mach/msg.c: Likewise.
2019-09-09 18:48:55 +02:00
Danny Milosavljevic 8910030b89
Add missing #include.
* lib/stdlib/mbstowcs.c: Add missing #include.
2019-09-09 18:33:27 +02:00
Danny Milosavljevic 70d68ac0d5
Add missing #include.
* lib/stdio/vfscanf.c: Add missing #include.
2019-09-09 18:33:27 +02:00
Danny Milosavljevic bb9ec6e2cd
Fix dtoab.
* lib/mes/dtoab.c (dtoab): Fix it.
* lib/tests/mes/90-dtoab.c (main): Fix test.
* build-aux/check-mescc.sh (XFAIL_TESTS: Remove it.
2019-09-09 18:33:27 +02:00
Danny Milosavljevic 9a674ceef5
va_align: Fix compiler warning.
Follow-up to 49b0cd7d2e6952044d7436260d6ba950e40ee05f.

* include/stdarg.h: Fix compiler warning.
2019-09-09 18:33:27 +02:00
Danny Milosavljevic 1e18c4ddd3
Add missing #include.
* lib/tests/mes/90-abtod.c (main): Add missing #include.
2019-09-09 18:33:27 +02:00
Danny Milosavljevic 8ecaaad049
Fix variable argument list traversal for doubles.
* include/stdarg.h (va_align): New macro.
(va_arg8): New macro.
* lib/stdio/vfprintf.c (vfprintf): Use it.
* lib/stdio/vsnprintf.c (vsnprintf): Use it.
2019-09-09 18:33:26 +02:00
Jan Nieuwenhuizen 40126a8b8c
build: Improve --with-system-libc support.
* build-aux/build-lib.sh: Avoid building libc for --with-system-libc.
Make libmes richer.
build-aux/check-mescc.sh: Enable 50-malloc test.
* include/dirstream.h: Use HAVE_DIRSTREAM_H to cater for non-existing
dirstream.h.
* include/grp.h[SYSTEM_LIBC]: Typo.
* include/mes/lib.h (__brk, __call_at_exit)[SYSTEM_LIBC]: Declare.
* include/stdlib.h (comparison_fn_t)[SYSTEM_LIBC]: Declare.
* include/time.h (mktime): Return time_t.
* lib/posix/isatty.c [SYSTEM_LIBC]: Do not (re)declare termios.
* lib/stub/mktime.c (mktime): Return time_t.
* lib/tests/scaffold/41-ternary.c (main): Remove assumption that
locals are initialized.
* lib/tests/scaffold/70-stdarg.c: Cater for SYSTEM_LIBC.
* lib/tests/setjmp/80-setjmp.c: Declare jmp buf.
* lib/*/*.c: Add missing mes/lib.h, errno.h includes.
2019-09-09 18:33:26 +02:00
Jan Nieuwenhuizen b7d04b5315
mescc: Mes C Library: Support gcc-4.6.4: vsscanf: Support *, [, s.
* lib/stdio/vsscanf.c (vsscanf): Support  *, [, s.
* lib/stdio/vfscanf.c (vfscanf): Likewise.
* lib/tests/stdio/90-sscanf.c: Test it.
* build-aux/check-mescc.sh (tests): Run it.
* lib/x86-mes/x86.M1 (mov____%al,0x32(%ebp): New macro.
2019-09-09 18:33:26 +02:00
Jan Nieuwenhuizen 2bcb629e04
mescc: Mes C Library: Support gcc-4.6.4: Allow larger qsort entries.
* lib/stdlib/qsort.c (qswap): Increase buffer to 128 bytes (gmp needs
36) and add assert.
2019-09-09 18:33:26 +02:00
Jan Nieuwenhuizen 57a7e4346b
mescc: Mes C Library: Support gcc-4.6.4: Avoid type/size_t conflicts.
* include/alloca.h: Remove typedefs, include sys/types.h.
* include/stdint.h: Likewise.
* include/string.h: Likewise.
2019-09-09 18:33:26 +02:00
Jan Nieuwenhuizen 44a0d9f46c
mescc: Mes C Library: Support gcc-4.6.4: Add strtok.
* include/string.h (strtok): Declare.
* lib/string/strtok.c (strtok): New file.
* lib/libc+gnu.c: Include it.
2019-09-09 18:33:26 +02:00
Jan Nieuwenhuizen bf670b2c73
mescc: Mes C Library: Support gcc-4.6.4: Add mmap, munmap.
* include/linux/x86/syscall.h (SYS_mmap, SYS_munmap): New macro.
* include/linux/x86_64/syscall.h (SYS_mmap, SYS_munmap): New macro.
* include/sys/mman.h (MAP_SHARED, MAP_PRIVATE, MAP_ANONYMOUS,
MAP_POPULATE, MAP_ANON, MAP_FAILED): New macro.
(mmap, munmap): Declare.
* lib/linux/x86-mes-gcc/mes.c (_sys_call6): New function.
* lib/linux/x86-mes/mes.c (__sys_call6): New function.
(_sys_call6): New function.
* lib/linux/x86_64-mes-gcc/mes.c (_sys_call6): New function.
* lib/linux/x86_64-mes/mes.c (__sys_call): Cater for 6 syscall parameters.
(_sys_call6): New function.
* lib/x86-mes/x86.M1 (pop____%ebp): New macro.
* lib/x86_64-mes/x86_64.M1 (mov____0x8(%rbp),%r9): New macro.
* lib/linux/mmap.c: New file.
* lib/linux/munmap.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add them.
2019-09-09 18:33:25 +02:00
Jan Nieuwenhuizen bc9a9948ac
mescc: Mes C Library: Support gcc-4.6.4: Add labs.
* lib/math/labs.c: New file.
* lib/libc+gnu.c: Include it.
* include/math.h (labs): Declare.
2019-09-09 18:33:25 +02:00
Jan Nieuwenhuizen 5cbe225ddc
mescc: Mes C Library: Support gcc-4.6.4: Implement rewind.
* lib/stdio/rewind.c: Move from ../stub.  Implement.
* include/stdio.h (rewind): Declare.
* lib/libc+gnu.c: Update include.
* lib/libg.c: Update include.
* lib/stub/rewind.c: Remove.
2019-09-09 18:33:25 +02:00
Jan Nieuwenhuizen c2b160b58a
mescc: Mes C Library: Support gcc-4.6.4: Add asctime stub.
* lib/stub/asctime.c: New file.
* lib/libc+gnu.c: Include it.
* include/time.h (asctime): Declare.
2019-09-09 18:33:25 +02:00
Jan Nieuwenhuizen 96b246be7c
mescc: Mes C Library: Support gcc-4.6.4: vfprintf, vsnprintf: #-type.
* lib/stdio/vfprintf.c (vfprintf): Support #-type prefix.  Show whole
format upon error.
* lib/stdio/vsnprintf.c (vsnprintf): Likewise.
* lib/stdio/vfscanf.c (vfscanf): Show whole template upon error.
* lib/stdio/vsscanf.c (vsscanf): Likewise.
2019-09-09 18:33:25 +02:00
Jan Nieuwenhuizen 03c09d358e
mescc: Mes C Library: Support gcc-4.6.4: vfprintf, vsnprintf: pad with space.
* lib/stdio/vfprintf.c (vfprintf): pad with space.
* lib/stdio/vsnprintf.c (vsnprintf): pad with space.
2019-09-09 18:33:25 +02:00
Jan Nieuwenhuizen 3853afd484
mescc: Mes C Library: Support gcc-4.6.4: atexit: return 0.
* lib/stdlib/atexit.c (atexit): return 0.
2019-09-09 18:33:25 +02:00
Jan Nieuwenhuizen 340f6d25f9
mescc: Mes C Library: Support gcc-4.6.4: Add SSIZE_MAX macro.
* include/stdint.h (SSIZE_MAX): New macro.
2019-09-09 18:33:24 +02:00
Jan Nieuwenhuizen 109014ffed
mescc: Mes C Library: Support gcc-4.6.4: Add math stubs.
* lib/math/ceil.c: New file.
* lib/math/floor.c: New file.
* lib/stub/atan2.c: New file.
* lib/stub/cos.c: New file.
* lib/stub/exp.c: New file.
* lib/stub/log.c: New file.
* lib/stub/modf.c: New file.
* lib/stub/pow.c: New file.
* lib/stub/sin.c: New file.
* lib/stub/sqrt.c: New file.
* lib/libc+gnu.c: Include them.
* include/math.h (atan2, ceil, cos, exp, fabs, floor, log, modf, pow,
sin, sqrt): Declare.
* lib/math/fabs.c: Update.
* lib/stub/ldexp.c: Update.
2019-09-09 18:33:24 +02:00
Jan Nieuwenhuizen 5073083dea
mescc: Mes C Library: Support gcc-4.6.4: Add fscanf, vfscanf.
* lib/stdio/vfscanf.c: New file.
* lib/stdio/fscanf.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add them.
* include/stdio.h (fscanf): Declare.
* include/stdarg.h (vfscanf): Declare.
* lib/libc+gnu.c: Include them.
* lib/libg.c: Likewise.
* lib/stub/fscanf.c: Remove.
2019-09-09 18:33:24 +02:00
Jan Nieuwenhuizen 2d11c7a95b
mescc: Mes C Library: vfprintf, vsnprintf: Pad floats with space.
* lib/stdio/vfprintf.c (vfprintf): Pad floats with space.
* lib/stdio/vsnprintf.c (vsnprintf): Pad floats with space.
* lib/tests/stdio/90-sprintf.c: Test it.
2019-09-09 18:33:24 +02:00
Jan Nieuwenhuizen aaac5ac266
mescc: Mes C Library: Support gcc-4.6.4: Add float macros.
* include/float.h (DBL_EPSILON, DBL_MANT_DIG, DBL_MAX, DBL_MIN,
FLT_RADIX, LDBL_EPSILON, LDBL_MANT_DIG, LDBL_MAX, LDBL_MIN): New
macro.
2019-09-09 18:33:24 +02:00
Jan Nieuwenhuizen a4fe947338
mescc: Mes C Library: Support gcc-4.6.4: Add stdint [U]SHRT macros.
* include/stdint.h (SHRT_MAX, SHRT_MIN, USHRT_MAX, USHRT_MIN): New
macro.
2019-09-09 18:33:24 +02:00
Jan Nieuwenhuizen 55d538b2c5
mescc: Mes C Library: Support gcc-4.6.4: Fix ctime stub.
* lib/stub/ctime.c (ctime): Fix stub to avoid segfault upon use.
2019-09-09 18:33:24 +02:00
Jan Nieuwenhuizen 740511bd43
mescc: Mes C Library: Support gcc-4.6.4: Fix uintptr_t, add [u]intmax_t.
* include/stdint.h: Fix uintptr_t, add [u]intmax_t.
2019-09-09 18:33:23 +02:00
Jan Nieuwenhuizen a520728889
mescc: Mes C Library: vsscanf: Increase count for scanned float.
* lib/stdio/vsscanf.c (vsscanf): Increase count for scanned float.
2019-09-09 18:33:23 +02:00
Jan Nieuwenhuizen ff441b38e4
mescc: Mes C Library: Support GNU Tar: Fix getpwnam, getpwuid stubs.
* lib/stub/getpwnam.c (getpwnam): Return pointer to static struct
passwd.
* lib/stub/getpwuid.c (getpwuid): Likewise.
2019-09-09 18:33:23 +02:00
Jan Nieuwenhuizen 56db7e2aca
mescc: Mes C Library: Support GNU Tar: Add getgrgid, getgrnam, setgrent stub.
* include/grp.h: New file.
* lib/stub/getgrgid.c: New file.
* lib/stub/getgrnam.c: New file.
* lib/stub/setgrent.c: New file.
* lib/libc+gnu.c: Include them.
2019-09-09 18:33:23 +02:00
Jan Nieuwenhuizen 61419f0bf3
mescc: Mes C Library: Support GNU Awk: Add wchar_t.
* include/sys/types.h (wchar_t): New typedef.
2019-09-09 18:33:23 +02:00
Jan Nieuwenhuizen 55fde29822
mescc: Mes C Library: Support GNU Awk: Add getpgid, getpgrp stubs.
* include/unistd.h (getpgid, getpgrp): Declare.
* lib/stub/getpgid.c: New file.
* lib/stub/getpgrp.c: New file.
* lib/libc+gnu.c: Include them.
2019-09-09 18:33:23 +02:00
Jan Nieuwenhuizen 8c9de89c6b
mescc: Mes C Library: Support GNU Tar: Add mktime stub, fix localtime stub.
* include/time.h (mktime): Declare.
* lib/stub/mktime.c: New stub.
* lib/libc+gnu.c: Include it.
* lib/stub/localtime.c (localtime): Return pointer to static struct
tm.  Avoids segfaults.
2019-09-09 18:33:23 +02:00
Jan Nieuwenhuizen 2cb5e873c4
mescc: Mes C Library: Support GNU Tar: Add creat, mknod.
* include/linux/x86_64/syscall.h (SYS_mknod): New macro.
* include/linux/x86/syscall.h (SYS_mknod): New macro.
* lib/linux/mknod.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add it.
* include/sys/stat.h (mknod): Declare it.
* include/fcntl.h (creat): New macro.
2019-09-09 18:33:22 +02:00
Jan Nieuwenhuizen 1a2d9fbd95
mescc: Mes C Library: Support GNU Tar: Add missing defines.
* include/errno.h (ENXIO): New macro.
* include/sys/stat.h (S_IFIFO, S_ISFIFO): New macro.
2019-09-09 18:33:22 +02:00
Jan Nieuwenhuizen bb14790d5e
mescc: Mes C Library: Support GNU Bash: Add struct winsize.
* include/termio.h (struct winsize): New type.
2019-09-09 18:33:22 +02:00
Jan Nieuwenhuizen d7bbd7f62d
mescc: Mes C Library: Support GNU Awk: Implement atof.
* lib/stdlib/atoi.c: Update.
* lib/stdlib/atof.c: Rename from stub/atof.c; Implement.
* lib/libc+gnu.c: Update include.
* lib/libg.c: Update include.
2019-09-09 18:33:22 +02:00
Jan Nieuwenhuizen 9d33ed0a2e
mescc: Mes C Library: Support GNU Awk: Add dtoab, %f in vfprintf, vsnprintf.
* include/libmes.h (dtoab): Declare.
* lib/mes/ntoab.c (ntoab): Update.
* lib/mes/dtoab.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/tests/mes/90-dtoab.c: Test it.
* lib/tests/stdio/90-sprintf.c: Test it.
* build-aux/check-mescc.sh (tests): Run it, against...
* lib/tests/mes/90-dtoab.stdout: ...baseline.
* lib/stdio/vfprintf.c (vfprintf): Support %f, even more naive support
for %e, %E, %g, %G.
* lib/stdio/vsnprintf.c (vsnprintf): Likewise.
2019-09-09 18:33:22 +02:00
Jan Nieuwenhuizen 6b4ef3c8d4
mescc: Mes C Library: Support GNU Awk: Add abtod, implementing strtod.
* include/libmes.h (abtod): Declare.
* lib/mes/abtod.c: New file.
* build-aux/configure-lib.sh (libmes_SOURCES, libc_tcc_SOURCES): Add
it.
* lib/mes/abtol.c: Update.
* lib/stdlib/strtod.c: Use it to implement; move from stub/strtod.
* lib/tests/mes/90-abtod.c: Test it.
* lib/tests/mes/90-abtod.stdout: Baseline.
* build-aux/check-mescc.sh (tests): Run it.
2019-09-09 18:33:22 +02:00
Jan Nieuwenhuizen 79ae7ee4eb
mescc: Mes C Library: Support GNU Awk: vsscanf: Support %f.
* lib/stdio/vsscanf.c (vsscanf): Support %f.
2019-09-09 18:33:22 +02:00
Jan Nieuwenhuizen 8034d6942e
mescc: Mes C Library: Support GNU Awk: Do not flush std files.
* lib/stdio/fflush.c (fflush): Do not flush std files.
2019-09-09 18:33:21 +02:00
Jan Nieuwenhuizen ceaf6d62bd
mescc: Mes C Library: Support GNU Awk: Add isgraph.
* lib/ctype/isgraph.c: New file.
* lib/libc+gnu.c: Include it.
* include/ctype.h: Add missing prototypes.
2019-09-09 18:33:21 +02:00
Jan Nieuwenhuizen 07a9e7aac7
mescc: Mes C Library: Support GNU Tar: Add readlink, readlink.
* lib/linux/gnu.c (readlink, symlink): New function.
* include/unistd.h (readlink, symlink): Declare.
* include/linux/x86/syscall.h (SYS_readlink, SYS_symlink): New macro.
* include/linux/x86_64/syscall.h (SYS_symlink, SYS_readlink): New
macro.
2019-09-09 18:33:21 +02:00
Jan Nieuwenhuizen bc2a115b55
mescc: Mes C Library: Support GNU Tar: Add execlp.
* lib/posix/execl.c (vexec): New function.
(execl): Use it.
* lib/posix/execlp.c: New file.
* build-aux/configure-lib.sh (libc_tcc_SOURCES): Add it.
* lib/libc+gnu.c: Include it.
* include/unistd.h (execlp): Declare.
* lib/tests/posix/90-execlp.c: New file.
* lib/tests/posix/90-execlp.stdout: New file.
* build-aux/check-mescc.sh: Test it.
2019-09-09 18:33:21 +02:00
Jan Nieuwenhuizen b3283e2377
mescc: Mes C Library: Fix compile warnings.
* include/stdlib.h (abort): Add prototype.
2019-09-09 18:33:14 +02:00
Jan Nieuwenhuizen 314e25e532
doc: Post-release update.
* doc/announce/ANNOUNCE-0.20: Update.
* guix/git/mes.scm (mes): Update.
2019-09-09 16:49:03 +02:00
167 changed files with 4802 additions and 188 deletions

21
.gitignore vendored
View File

@ -34,8 +34,6 @@
*.a
*.o
*.seed-out
*.stderr
*.stdout
*.x86-out
@ -60,15 +58,6 @@
*.x86_64-mes-stdout
*.x86_64-out
/lib/x86-mes/0exit-42
/lib/x86-mes/exit-42
/lib/tests/*/[0-9a][0-9a-z]-*
/lib/tests/*/x86-mes-*
!/lib/tests/*/*.c
!/lib/tests/*/*.exit
!/lib/tests/*/*.stdout
/scaffold/argv
/scaffold/hello
/scaffold/main
@ -78,13 +67,6 @@
/scaffold/x86-mes-*
/scaffold/x86_64-mes-*
/scaffold/tests/x86-mes-*
/scaffold/tests/[0-9a][0-9a-z]-*
/scaffold/tests/t.*
!/scaffold/tests/*.c
!/scaffold/tests/*.exit
!/scaffold/tests/*.stdout
/src/mes.mes.symbols.h
/src/gc.mes.h
/src/hash.mes.h
@ -169,3 +151,6 @@
/body-hello-mes
/exit-42
/hello-mes
core
/.config
a.out

View File

@ -73,6 +73,13 @@ mes/module/srfi/srfi-26.scm
GNU FDL in texinfo from GNU
doc/fdl-1.3.texi
Hurd and Mach support from GNU C Library
include/gnu/hurd-types.h
include/mach/mach-init.h
lib/mach/msg.c
lib/mach/mach-init.c
lib/mach/*.S
* legalese
Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>

View File

@ -66,6 +66,7 @@ fi
CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdir}/../lib
-I ../include
-I ${srcdir}/../include
-I ${srcdir}/../include/$mes_kernel/$mes_cpu
@ -98,6 +99,7 @@ if test $compiler = gcc; then
fi
CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdest}lib
-I include
-I ${srcdest}include
-I ${srcdest}include/$mes_kernel/$mes_cpu
@ -116,6 +118,7 @@ fi
CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdest}lib
-I include
-I ${srcdest}include
-I ${srcdest}include/$mes_kernel/$mes_cpu
@ -137,6 +140,7 @@ fi
fi
CPPFLAGS="
-D HAVE_CONFIG_H=1
-I ${srcdest}lib
-I include
-I ${srcdest}include
-I ${srcdest}include/$mes_kernel/$mes_cpu

View File

@ -25,6 +25,7 @@ set -u
TESTS="
lib/tests/scaffold/t.c
lib/tests/scaffold/00-exit-0.c
lib/tests/scaffold/00-exit-42.c
lib/tests/scaffold/01-return-0.c
lib/tests/scaffold/02-return-1.c
lib/tests/scaffold/03-call.c
@ -75,8 +76,9 @@ lib/tests/scaffold/23-global-pointer-ref.c
lib/tests/scaffold/23-global-pointer-pointer-ref.c
lib/tests/scaffold/23-pointer-sub.c
lib/tests/scaffold/23-pointer.c
lib/tests/mes/30-oputs.c
lib/tests/string/30-strlen.c
lib/tests/mes/30-oputs.c
lib/tests/mes/30-eputs.c
lib/tests/scaffold/32-call-wrap.c
lib/tests/scaffold/32-compare.c
lib/tests/scaffold/33-and-or.c
@ -200,12 +202,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 +229,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 +239,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 +256,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 +264,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 +282,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

View File

@ -41,6 +41,31 @@ lib/stdlib/exit.c
lib/stdlib/puts.c
lib/string/strlen.c
"
if test $mes_kernel = gnu; then
libc_mini_shared_SOURCES="$libc_mini_shared_SOURCES
lib/gnu/_exit.c
lib/gnu/exec-startup-get-data.c
lib/gnu/fd-get.c
lib/gnu/fd-write.c
lib/gnu/io-write.c
lib/gnu/_write.c
lib/gnu/hurd-start.c
lib/gnu/proc-mark-exit.c
lib/gnu/syscall.c
lib/gnu/task-get-special-port.c
lib/gnu/task-terminate.c
lib/gnu/vm-statistics.c
lib/mach/mach-init.c
lib/mach/mach_host_self.S
lib/mach/mach_msg_trap.S
lib/mach/mach_reply_port.S
lib/mach/mach_task_self.S
lib/mach/mach_thread_self.S
lib/mach/msg.c
lib/string/argz-extract.c
"
fi
fi
libc_mini_SOURCES="$libc_mini_shared_SOURCES"
@ -79,6 +104,11 @@ lib/ctype/isxdigit.c
lib/posix/write.c
lib/stdlib/atoi.c
"
if test $mes_kernel = gnu; then
libmes_SOURCES="$libmes_SOURCES
lib/stub/lseek.c
"
fi
if test $mes_kernel = linux; then
libmes_SOURCES="$libmes_SOURCES
lib/linux/lseek.c
@ -86,6 +116,8 @@ lib/linux/lseek.c
fi
else
libmes_SOURCES="$libmes_SOURCES
lib/mes/abtod.c
lib/mes/dtoab.c
"
fi
@ -111,7 +143,6 @@ lib/stdio/putc.c
lib/stdio/putchar.c
lib/stdio/ungetc.c
lib/stdlib/free.c
lib/stdlib/malloc.c
lib/stdlib/realloc.c
lib/string/memchr.c
lib/string/memcmp.c
@ -123,6 +154,32 @@ lib/string/strcpy.c
lib/string/strncmp.c
"
if test $mes_kernel = gnu; then
libc_SOURCES="$libc_SOURCES
lib/gnu/_open3.c
lib/gnu/_read.c
lib/gnu/dir-lookup.c
lib/gnu/fd-read.c
lib/gnu/io-read.c
lib/gnu/malloc.c
lib/gnu/vm-allocate.c
lib/stub/access.c
lib/stub/brk.c
lib/stub/chmod.c
lib/stub/clock_gettime.c
lib/stub/dup2.c
lib/stub/dup.c
lib/stub/execve.c
lib/stub/fork.c
lib/stub/_getcwd.c
lib/stub/gettimeofday.c
lib/stub/ioctl.c
lib/stub/time.c
lib/stub/unlink.c
lib/stub/waitpid.c
"
fi
if test $mes_kernel = linux; then
libc_SOURCES="$libc_SOURCES
lib/linux/access.c
@ -143,6 +200,7 @@ lib/linux/time.c
lib/linux/unlink.c
lib/linux/waitpid.c
lib/linux/$mes_cpu-mes-$compiler/syscall.c
lib/unix/malloc.c
"
fi
@ -156,6 +214,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 +240,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
@ -211,22 +272,35 @@ lib/linux/stat.c
"
fi
if test $mes_kernel = gnu; then
libc_tcc_SOURCES="$libc_tcc_SOURCES
lib/stub/close.c
lib/stub/rmdir.c
lib/stub/stat.c
"
fi
libc_gnu_SOURCES="
$libc_tcc_SOURCES
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 +311,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 +334,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 +397,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

View File

@ -52,6 +52,11 @@ else
LIBS='-l c'
fi
if test $mes_kernel = gnu\
&& test -z "$LIBS"; then
LIBS="-l c-mini"
fi
if test $mes_libc = system; then
crt1=
LIBS='-l mes'

View File

@ -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

View File

@ -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

View File

@ -29,13 +29,11 @@
#else // ! SYSTEM_LIBC
#ifndef libc_hidden_def
#define libc_hidden_def(x)
#define weak_alias(x,y)
#endif
#include <mes/lib-mini.h>
size_t __argz_count (char const *argz, size_t len);
void __argz_extract (char const *argz, size_t len, char **argv);
size_t __argz_extract_count (char const *argz, size_t len, char **argv);
#endif // ! SYSTEM_LIBC

View File

@ -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);

View File

@ -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

View File

@ -30,6 +30,7 @@
#else // ! SYSTEM_LIBC
// *INDENT-OFF*
#if __linux__
#define O_RDONLY 0
#define O_WRONLY 1
#define O_RDWR 2
@ -38,6 +39,16 @@
#define O_TRUNC 0x200
#define O_APPEND 0x400
#define O_DIRECTORY 0x10000
#elif __GNU__
#define O_RDONLY 1
#define O_WRONLY 2
#define O_RDWR 3
#define O_CREAT 0x10
#define O_APPEND 0x100
#define O_TRUNC 0x10000
#else
#error platform not supported
#endif
// *INDENT-ON*
#define FD_CLOEXEC 1
@ -48,6 +59,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, ...);

View File

@ -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

393
include/gnu/hurd-types.h Normal file
View File

@ -0,0 +1,393 @@
/* C declarations for Hurd server interfaces
Copyright (C) 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002,
2010 Free Software Foundation, Inc.
This file is part of the GNU Hurd.
The GNU Hurd 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 2, or (at your option)
any later version.
The GNU Hurd 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 the GNU Hurd; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _HURD_TYPES_H
#define _HURD_TYPES_H
#ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 32
#endif
#include <time.h> /* For struct timespec. */
#include <mach/std_types.h> /* For mach_port_t et al. */
#include <mach/message.h> /* For mach_msg_id_t et al. */
#include <sys/types.h> /* For pid_t and uid_t. */
/* A string identifying this release of the GNU Hurd. Our
interpretation of the term "release" is that it refers to a set of
server interface definitions. A "version" in Posix terminology is
a distribution of the Hurd; there may be more than one distribution
without changing the release number. */
#define HURD_RELEASE "0.0"
/* Simple type declarations */
/* These types identify certain kinds of ports used by the Hurd. */
typedef mach_port_t file_t;
typedef mach_port_t fsys_t;
typedef mach_port_t io_t;
typedef mach_port_t process_t;
typedef mach_port_t auth_t;
typedef mach_port_t socket_t;
typedef mach_port_t pf_t; /* Protocol family */
typedef mach_port_t addr_port_t;
typedef mach_port_t startup_t;
typedef mach_port_t fs_notify_t;
typedef mach_port_t exec_startup_t;
typedef mach_port_t interrupt_t;
typedef mach_port_t proccoll_t;
typedef mach_port_t ctty_t;
#include <errno.h> /* Defines `error_t'. */
/* These names exist only because of MiG deficiencies.
You should not use them in C source; use the normal C types instead. */
typedef char *data_t;
typedef const char *const_data_t;
typedef char string_t [1024];
typedef int *intarray_t;
typedef const int *const_intarray_t;
typedef int *fd_mask_t;
typedef const int *const_fd_mask_t;
typedef mach_port_t *portarray_t;
typedef const mach_port_t *const_portarray_t;
typedef pid_t *pidarray_t;
typedef const pid_t *const_pidarray_t;
typedef uid_t *idarray_t;
typedef const uid_t *const_idarray_t;
#if 0
typedef __loff_t *off_array_t;
typedef const __loff_t *const_off_array_t;
#endif
typedef struct rusage rusage_t;
typedef struct flock flock_t;
typedef struct utsname utsname_t;
#if _FILE_OFFSET_BITS == 64
typedef struct stat io_statbuf_t;
typedef struct statfs fsys_statfsbuf_t;
#else
typedef struct stat64 io_statbuf_t;
typedef struct statfs64 fsys_statfsbuf_t;
#endif
typedef struct timespec timespec_t;
/* Parameters and flags in RPC calls */
/* Many such parameters and flags are also defined in various libc
headers. */
/* Bits for flags in fs.defs:file_exec_paths and exec.defs:exec_* calls: */
#define EXEC_NEWTASK 0x00000001 /* Create new task; kill old one. */
#define EXEC_SECURE 0x00000002 /* Use secure values of portarray, etc. */
#define EXEC_DEFAULTS 0x00000004 /* Use defaults for unspecified ports. */
#define EXEC_SIGTRAP 0x00000008 /* Simulate SIGTRAP on startup. */
/* This flag is passed through by the exec server but not examined by it. */
#define EXEC_STACK_ARGS 0x00000010 /* Use arguments from stack, not RPC. */
/* Bits for flags in fs.defs:file_set_translator call: */
#define FS_TRANS_FORCE 0x00000001 /* Must use translator(no sht circuit) */
#define FS_TRANS_EXCL 0x00000002 /* Don't do it if already translated. */
#define FS_TRANS_SET 0x00000004 /* Set or clear translator */
#define FS_TRANS_ORPHAN 0x00000008 /* Orphan the active translator. */
/* Values for retry field in fs.defs:dir_lookup call: */
enum retry_type
{
FS_RETRY_NORMAL = 1, /* Retry normally if retry_name is not null. */
FS_RETRY_REAUTH = 2, /* Retry after reauthenticating retry port.
Even if the retry name is null, a retry
is still necessary with this code after the
reauthentication is complete. */
FS_RETRY_MAGICAL = 3, /* Retry string is magical. */
/* "tty" means controlling tty;
"fd/%u" means file descriptor N;
"machtype/..." means replace `machtype' with the numbers in decimal
returned by the user's kernel as the cpu_type (N) and
cpu_subtype (M) (producing N/M/...) and then retry
as for FS_RETRY_NORMAL.
"/..." means retry "...", but starting from the users root directory.
"pid/..." means replace `pid' with the PID of the current process in %u
format and then retry as for FS_RETRY_NORMAL.
*/
};
typedef enum retry_type retry_type;
/* Types for fs_notify.defs:dir_changed call: */
enum dir_changed_type
{
DIR_CHANGED_NULL, /* Always sent first for sync. */
DIR_CHANGED_NEW, /* Specified name has been added. */
DIR_CHANGED_UNLINK, /* Specified name has been removed. */
DIR_CHANGED_RENUMBER, /* Name has been the target of rename. */
};
typedef enum dir_changed_type dir_changed_type_t;
/* Types for fs_notify.defs:file_changed call: */
enum file_changed_type
{
FILE_CHANGED_NULL, /* Always sent first for sync. */
FILE_CHANGED_WRITE, /* File data has been written. */
FILE_CHANGED_EXTEND, /* File has grown. */
FILE_CHANGED_TRUNCATE, /* File has been truncated. */
FILE_CHANGED_META, /* Stat information has changed, and none
of the previous three apply. Not sent
for changes in node times. */
};
typedef enum file_changed_type file_changed_type_t;
/* Select types for io.defs:io_select call: */
#define SELECT_READ 0x00000001
#define SELECT_WRITE 0x00000002
#define SELECT_URG 0x00000004
/* Flags for fsys.defs:fsys_goaway. Also, these flags are sent as the
oldtrans_flags in fs.defs:file_set_translator to describe how to
terminate the old translator. */
#define FSYS_GOAWAY_NOWAIT 0x00000001 /* Return immediately. */
#define FSYS_GOAWAY_NOSYNC 0x00000002 /* Don't update physical media. */
#define FSYS_GOAWAY_FORCE 0x00000004 /* Go away despite current users. */
#define FSYS_GOAWAY_UNLINK 0x00000008 /* Go away only if non-directory. */
#define FSYS_GOAWAY_RECURSE 0x00000010 /* Shutdown children too. */
/* Types of ports the terminal driver can run on top of;
used in term.defs:term_get_bottom_type. */
enum term_bottom_type
{
TERM_ON_MACHDEV,
TERM_ON_HURDIO,
TERM_ON_MASTERPTY,
};
/* Types of storage, as returned by file_get_storage_info.
STORAGE_DEVICE is a mach device_t (for random access devices)
STORAGE_HURD_FILE is a hurd file_t (as if a file were mapped)
STORAGE_TASK is a task_t (the storage is in the vm of the task)
STORAGE_MEMORY is a memory object port
STORAGE_ZERO is a fixed-size constant source of zeros
STORAGE_INTERLEAVE is a set of other storage types interleaved at a fixed
interval
STORAGE_CONCAT is a set of other storage types concatenated end-to-end
STORAGE_LAYER is a set of storage types, representing the same address
range; all will be written too, and will be read in turn until one
succeeds
STORAGE_REMAP is a layer on top of another store that remaps its blocks
STORAGE_COPY is a memory snapshot of another store
STORAGE_NETWORK means that the file is stored elsewhere on the
network; all the remaining fields contan type-specific information.
STORAGE_OTHER means none of these apply; and should be used when no
meaningful answer can be given
The vectors returned by file_get_storage_info encode each of the above
(note that the first int is always the storage type). There are four:
ports, ints, offsets (off_t), and data (char); each type of store uses the
following entries in each vector:
-type- -ports- -ints- -offsets- -data- -kids-
device DEVICE TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
file FILE TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
memory MEMOBJ TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
task TASK TY, FL, BS, NR, NL, ML NR * (OFFS, LEN) NL + ML -
(the data for the above is a name (incl '\0') and a misc data block)
null - TY, FL SIZE - -
(BS is 1)
ileave - TY, FL, IL, NC - - NC
(BS is the LCM of its children; SIZE is the minimum of theirs * IL)
concat - TY, FL, NC - - NC
(BS is the LCM of its children; SIZE is the sum of theirs)
layer - TY, FL, NC - - NC
(BS is the LCM of its children; SIZE is the minimum of theirs)
remap - TY, FL, NR NR * (OFFS, LEN) - 1
(BS and SIZE are that of the child)
copy - TY, FL, SIZE - DATA -
(DATA is preceded by padding to the next page boundary, and is
SIZE bytes long itself)
For ileave, concat, and layer, the children are encoded following the parent.
The first int must always be TY.
key: TY = type code, FL = flags, BS = block size, NR = num runs,
NL = name len, ML = misc len, NC = num children,
IL = interleave (bytes), SIZE = Size of storage (blocks),
LEN = run length (blocks), OFFS = run offset (blocks),
The NR * (OFFS, LEN) offsets for some of the types is the set of block
ranges in the underlying address space that, concatenated, make up the
contents of the storage -- for instance, doing file_get_storage_info on a
file may return storage of type STORAGE_DEVICE, and the accompanying block
ranges are the set of blocks on the given device that correspond to that
file. Any OFFS == -1 designates a hole in the address range. Note that
the total size (SIZE) for these types is the sum of their LEN's.
The optional NAME returned by some types (if NL != 0) is a type specific
name for the same object referenced by the port also returned. E.g.:
device -- The mach device name
file -- The file name (unreliable, as the root may not be the same)
task -- The pid
Unless it is MACH_PORT_NULL, the port should generally be used instead of
trying to regenerate it from the associated name, which is intended more for
printing messages, etc. */
enum file_storage_class
{
STORAGE_OTHER,
STORAGE_DEVICE,
STORAGE_HURD_FILE,
STORAGE_NETWORK,
STORAGE_MEMORY,
STORAGE_TASK,
STORAGE_ZERO,
STORAGE_CONCAT,
STORAGE_INTERLEAVE,
STORAGE_LAYER,
STORAGE_REMAP,
STORAGE_COPY,
};
/* Flags for the flags word returned by some types . */
#define STORAGE_MUTATED 0x00000001 /* data as stored is munged from file */
/* Data types */
#include <mach/task_info.h>
#include <mach/thread_info.h>
#ifndef THREAD_SCHED_INFO
#include <mach/policy.h>
#endif
/* Flags sent in proc_getprocinfo request. */
#define PI_FETCH_TASKINFO 0x0001
#define PI_FETCH_TASKEVENTS 0x0020
#define PI_FETCH_THREADS 0x0002
#define PI_FETCH_THREAD_BASIC 0x0004
#define PI_FETCH_THREAD_SCHED 0x0008
#define PI_FETCH_THREAD_WAITS 0x0010
struct procinfo
{
int state;
uid_t owner;
pid_t ppid;
pid_t pgrp;
pid_t session;
pid_t logincollection;
int exitstatus;
int sigcode;
int nthreads; /* size of pi_threadinfos */
struct task_basic_info taskinfo;
struct task_events_info taskevents;
#ifdef TASK_SCHED_TIMESHARE_INFO
struct policy_timeshare_base timeshare_base_info;
#endif
struct
{
int died; /* this thread died in the middle of call */
mach_msg_id_t rpc_block; /* thread is blocked on this RPC */
struct thread_basic_info pis_bi;
#ifdef THREAD_SCHED_INFO
struct thread_sched_info pis_si;
#else
struct policy_infos pis_pi;
#endif
} threadinfos[0];
};
typedef int *procinfo_t;
typedef const int *const_procinfo_t;
/* Bits in struct procinfo state: */
#define PI_STOPPED 0x00000001 /* Proc server thinks is stopped. */
#define PI_EXECED 0x00000002 /* Has called proc_exec. */
#define PI_WAITING 0x00000004 /* Process is waiting for child to exit */
#define PI_ORPHAN 0x00000008 /* Process group is orphaned. */
#define PI_NOMSG 0x00000010 /* Process has no message port. */
#define PI_SESSLD 0x00000020 /* Session leader. */
#define PI_NOTOWNED 0x0000040 /* Process has no owner. */
#define PI_NOPARENT 0x0000080 /* Hasn't identified a parent. */
#define PI_ZOMBIE 0x00000100 /* Has no associated task. */
#define PI_TRACED 0x00000200 /* Process is being traced */
#define PI_GETMSG 0x00000400 /* Process is blocked in proc_getmsgport. */
#define PI_LOGINLD 0x00000800 /* Process is leader of login collection */
/* Conventions */
/* st_fstype in struct stat and fsys_stb_type in fsys_statfsbuf is one of: */
#define FSTYPE_UFS 0x00000000 /* 4.x BSD Fast File System */
#define FSTYPE_NFS 0x00000001 /* Network File System ala Sun */
#define FSTYPE_GFS 0x00000002 /* GNU file system */
#define FSTYPE_LFS 0x00000003 /* Logging File System ala Sprite */
#define FSTYPE_SYSV 0x00000004 /* Old U*x filesystem ala System V */
#define FSTYPE_FTP 0x00000005 /* Transparent FTP */
#define FSTYPE_TAR 0x00000006 /* Transparent TAR */
#define FSTYPE_AR 0x00000007 /* Transparent AR */
#define FSTYPE_CPIO 0x00000008 /* Transparent CPIO */
#define FSTYPE_MSLOSS 0x00000009 /* MS-DOS */
#define FSTYPE_CPM 0x0000000a /* CP/M */
#define FSTYPE_HFS 0x0000000b /* Don't ask */
#define FSTYPE_DTFS 0x0000000c /* used by desktop to provide more info */
#define FSTYPE_GRFS 0x0000000d /* GNU Remote File System */
#define FSTYPE_TERM 0x0000000e /* GNU Terminal driver */
#define FSTYPE_DEV 0x0000000f /* GNU Special file server */
#define FSTYPE_PROC 0x00000010 /* /proc filesystem ala Version 9 */
#define FSTYPE_IFSOCK 0x00000011 /* PF_LOCAL socket naming point */
#define FSTYPE_AFS 0x00000012 /* Andrew File System 3.xx */
#define FSTYPE_DFS 0x00000013 /* Distributed File Sys (OSF) == AFS 4.xx */
#define FSTYPE_PROC9 0x00000014 /* /proc filesystem ala Plan 9 */
#define FSTYPE_SOCKET 0x00000015 /* io_t that isn't a file but a socket */
#define FSTYPE_MISC 0x00000016 /* generic trivfs server */
#define FSTYPE_EXT2FS 0x00000017 /* Linux filesystem by Remy Card */
#define FSTYPE_HTTP 0x00000018 /* Transparent HTTP */
#define FSTYPE_MEMFS 0x00000019 /* In-core filesystem */
#define FSTYPE_ISO9660 0x0000001a /* ISO9660 */
/* Standard port assignments for file_exec_paths and exec_* */
enum
{
INIT_PORT_CWDIR,
INIT_PORT_CRDIR,
INIT_PORT_AUTH,
INIT_PORT_PROC,
INIT_PORT_CTTYID,
/* If MACH_PORT_NULL is given for the bootstrap port,
the bootstrap port of the old task is used. */
INIT_PORT_BOOTSTRAP,
INIT_PORT_MAX
};
/* Standard ints for file_exec_paths and exec_* */
enum
{
INIT_UMASK,
INIT_SIGMASK,
INIT_SIGIGN,
INIT_SIGPENDING,
INIT_TRACEMASK,
INIT_INT_MAX,
};
#endif // _HURD_TYPES_H

84
include/gnu/hurd.h Normal file
View File

@ -0,0 +1,84 @@
/*
* 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/>.
*/
#ifndef __MES_GNU_HURD_H
#define __MES_GNU_HURD_H
#define _GNU_SOURCE 1
#define __USE_GNU 1
#include <errno.h>
#include <sys/types.h>
#ifndef _BITS_TYPES_H
#ifndef _LOFF_T
#define _LOFF_T
typedef off64_t loff_t;
#endif
#endif
#include <mach/mach_types.h>
#include <mach/message.h>
#include <mach/port.h>
struct hurd_startup_data
{
int flags;
mach_port_t *dtable;
mach_msg_type_number_t dtable_count;
char *argp;
int arg_size;
char *envp;
int env_size;
mach_port_t *portarray;
mach_msg_type_number_t portarray_count;
int *intarray;
mach_msg_type_number_t intarray_count;
vm_address_t stack_base;
vm_size_t stack_count;
vm_address_t phdr;
vm_size_t phdr_count;
vm_address_t user_entry;
};
#define _HURD_DTABLE_MAX 1024
extern mach_port_t _hurd_dtable[_HURD_DTABLE_MAX];
extern int _hurd_dtable_count;
extern struct hurd_startup_data _hurd_startup_data;
#define _HURD_ARGV_MAX 1000
#define _HURD_ENVV_MAX 1000
extern size_t __argc;
extern char *__argv[_HURD_ARGV_MAX];
extern char *__envv[_HURD_ENVV_MAX];
mach_port_t fd_get (int filedes);
error_t fd_write (mach_port_t port, void const *buffer, size_t *size, loff_t offset);
error_t fd_read (mach_port_t port, void *buffer, size_t *size, loff_t offset);
#endif // __MES_GNU_HURD_H

144
include/gnu/syscall.h Normal file
View File

@ -0,0 +1,144 @@
/* -*-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/>.
*/
#ifndef __MES_GNU_SYSCALL_H
#define __MES_GNU_SYSCALL_H
#define _GNU_SOURCE 1
#define __USE_GNU 1
#include <mach/mach_types.h>
#include <mach/port.h>
#include <mach/message.h>
#include <gnu/hurd.h>
#include <gnu/hurd-types.h>
// mach/mach.defs
enum
{
SYS__task_terminate = 2008,
SYS__vm_allocate = 2021,
SYS__vm_statistics = 2030,
SYS__task_get_special_port = 2058,
};
// hurd/fsys.defs
enum
{
SYS__dir_lookup = 20018,
};
// hurd/io.defs
enum
{
SYS__io_write = 21000,
SYS__io_read,
};
// hurd/process.defs
enum
{
SYS__proc_mark_exit = 24025,
};
// hurd/startup.defs
enum
{
SYS__exec_startup_get_info = 30500,
};
extern mach_msg_type_t mach_msg_type_int32;
extern mach_msg_type_t mach_msg_type_int64;
extern mach_msg_type_long_t mach_msg_type_pointer;
struct mach_msg
{
mach_msg_header_t header;
};
struct mach_msg_1
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
};
struct mach_msg_2
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
mach_msg_type_t type_two; int two;
};
struct mach_msg_loff_int
{
mach_msg_header_t header;
mach_msg_type_t type_one; loff_t one;
mach_msg_type_t type_two; int two;
};
struct mach_msg_startup_info
{
mach_msg_header_t header;
mach_msg_type_t RetCodeType;
kern_return_t RetCode;
mach_msg_type_t user_entryType;
vm_address_t user_entry;
mach_msg_type_t phdrType;
vm_address_t phdr;
mach_msg_type_t phdr_sizeType;
vm_size_t phdr_size;
mach_msg_type_t stack_baseType;
vm_address_t stack_base;
mach_msg_type_t stack_sizeType;
vm_size_t stack_size;
mach_msg_type_t flagsType;
int flags;
mach_msg_type_long_t argvType;
char *argv;
mach_msg_type_long_t envpType;
char *envp;
mach_msg_type_long_t dtableType;
mach_port_t *dtable;
mach_msg_type_long_t portarrayType;
mach_port_t *portarray;
mach_msg_type_long_t intarrayType;
int *intarray;
};
kern_return_t __syscall (mach_port_t port, int sys_call);
kern_return_t __syscall2 (mach_port_t port, int sys_call, int one, int two);
kern_return_t __syscall_get (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size);
kern_return_t __syscall_put (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size);
// mach.defs
kern_return_t __task_terminate (mach_port_t task);
kern_return_t __task_get_special_port (mach_port_t task, int which, mach_port_t *port);
kern_return_t __vm_allocate (mach_port_t task, vm_address_t *address, vm_size_t size, boolean_t anywhere);
kern_return_t __vm_statistics (mach_port_t task, vm_statistics_data_t *vm_stats);
// process.defs
kern_return_t __proc_mark_exit (mach_port_t process, int one, int two);
kern_return_t __exec_startup_get_data (mach_port_t bootstrap, struct hurd_startup_data *data);
// io.c
kern_return_t __io_write (io_t io_object, data_t data, mach_msg_type_number_t size, loff_t offset, vm_size_t *wrote);
kern_return_t __io_read (io_t io, data_t *data, mach_msg_type_number_t *read, loff_t offset, vm_size_t size);
#endif // __MES_GNU_SYSCALL_H

View File

@ -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

View File

@ -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

50
include/mach/mach-init.h Normal file
View File

@ -0,0 +1,50 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 1993-2016 Free Software Foundation, Inc.
* 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:
Taken from GNU C Library
Declarations and macros for the basic Mach things set at startup.
*/
#ifndef _MACH_INIT_H
#define _MACH_INIT_H 1
#include <mach/mach_types.h>
/* Return the current task's task port. */
extern mach_port_t mach_task_self (void);
extern mach_port_t mach_host_self (void);
/* Kernel page size. */
extern vm_size_t __vm_page_size;
extern vm_size_t vm_page_size;
/* Round the address X up to a page boundary. */
#define round_page(x) \
((((vm_offset_t) (x) + __vm_page_size - 1) / __vm_page_size) * \
__vm_page_size)
/* Truncate the address X down to a page boundary. */
#define trunc_page(x) \
((((vm_offset_t) (x)) / __vm_page_size) * __vm_page_size)
#endif /* mach_init.h */

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -85,6 +85,12 @@ typedef unsigned uintmax_t;
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define SHRT_MAX INT16_MAX
#define SHRT_MIN INT16_MIN
#define USHRT_MAX UINT16_MAX
#define USHRT_MIN UINT16_MIN
#if __i386__
#define LONG_MIN INT_MIN
#define LONG_MAX INT_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

View File

@ -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);

View File

@ -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));

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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.
*
@ -31,6 +31,7 @@ typedef int pid_t;
#endif
#define WNOHANG 1
#define W_EXITCODE(status, signal) ((status) << 8 | (signal))
pid_t waitpid (pid_t pid, int *status_ptr, int options);
pid_t wait (int *status_ptr);

View File

@ -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;

View File

@ -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);

View File

@ -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

27
lib/ctype/isgraph.c Normal file
View File

@ -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;
}

42
lib/gnu/_exit.c Normal file
View File

@ -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/>.
*/
/** Commentary:
Inspired by implementation in GNU C Library:
_hurd_exit
Copyright (C) 1993-2016 Free Software Foundation, Inc.
*/
#include <gnu/hurd.h>
#include <gnu/hurd-types.h>
#include <gnu/syscall.h>
#include <mach/mach-init.h>
void
_exit (int status)
{
__proc_mark_exit (_hurd_startup_data.portarray[INIT_PORT_PROC], status, 0);
__task_terminate (mach_task_self ());
#if 0 // FIXME: this was needed?
while (1) {* (int *) 0 = 0;}
#else
asm ("hlt");
#endif
}

48
lib/gnu/_open3.c Normal file
View File

@ -0,0 +1,48 @@
/* -*-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/>.
*/
/** Commentary:
Inspired by implementation in GNU C Library:
__hurd_file_name_lookup, __hurd_file_name_lookup_retry
Copyright (C) 1992-2016 Free Software Foundation, Inc.
*/
#include <gnu/hurd.h>
#include <gnu/hurd-types.h>
#include <gnu/syscall.h>
#include <mach/mach-init.h>
int
_open3 (char const *file_name, int flags, int mode)
{
mach_port_t port;
int do_retry;
char retry_name[1024];
int start_dir = (file_name[0] == '/') ? INIT_PORT_CRDIR : INIT_PORT_CWDIR;
mach_port_t start_port = _hurd_startup_data.portarray[start_dir];
while (file_name[0] == '/')
file_name++;
error_t e = __dir_lookup (start_port, file_name, flags, mode, &do_retry, retry_name, &port);
if (e)
return -1;
int fd = _hurd_dtable_count++;
_hurd_dtable[fd] = port;
return fd;
}

34
lib/gnu/_read.c Normal file
View File

@ -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 <gnu/hurd.h>
#include <gnu/hurd-types.h>
#include <gnu/syscall.h>
#include <mach/mach-init.h>
ssize_t
_read (int filedes, void *buffer, size_t size)
{
mach_port_t p = fd_get (filedes);
error_t e = fd_read (p, buffer, &size, -1);
if (!e)
return size;
return -1;
}

34
lib/gnu/_write.c Normal file
View File

@ -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 <gnu/hurd.h>
#include <gnu/hurd-types.h>
#include <gnu/syscall.h>
#include <mach/mach-init.h>
ssize_t
_write (int filedes, void const *buffer, size_t size)
{
mach_port_t p = fd_get (filedes);
error_t e = fd_write (p, buffer, &size, -1);
if (!e)
return size;
return -1;
}

76
lib/gnu/dir-lookup.c Normal file
View File

@ -0,0 +1,76 @@
/* -*-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 <gnu/syscall.h>
#include <string.h>
#include <sys/stat.h>
struct mach_msg_string_int_int
{
mach_msg_header_t header;
mach_msg_type_t type_one; string_t one;
mach_msg_type_t type_two; int two;
mach_msg_type_t type_three; int three;
};
struct mach_msg_int_int_string_int
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
mach_msg_type_t type_two; int two;
mach_msg_type_t type_three; string_t three;
mach_msg_type_t type_four; int four;
};
mach_msg_type_t mach_msg_type_file_name =
{
/* msgt_name = */ (unsigned char) MACH_MSG_TYPE_STRING_C,
/* msgt_size = */ 8,
/* msgt_number = */ 1024,
/* msgt_inline = */ 1,
/* msgt_longform = */ 0,
/* msgt_deallocate = */ 0,
/* msgt_unused = */ 0
};
kern_return_t __dir_lookup (file_t start_dir, string_t file_name, int flags, mode_t mode, retry_type *do_retry, string_t retry_name, mach_port_t *port)
{
union message
{
struct mach_msg_string_int_int request;
struct mach_msg_int_int_string_int reply;
};
union message message = {0};
message.request.header.msgh_size = sizeof (message.request);
message.request.type_one = mach_msg_type_file_name;
strcpy (message.request.one, file_name);
message.request.type_two = mach_msg_type_int32;
message.request.two = flags;
message.request.type_three = mach_msg_type_int32;
message.request.three = mode;
kern_return_t result = __syscall_get (start_dir, SYS__dir_lookup,
&message.request.header,
sizeof (message.reply));
if (message.reply.one != KERN_SUCCESS)
return message.reply.one;
*port = message.reply.four;
return result;
}

View File

@ -0,0 +1,68 @@
/* -*-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 <gnu/syscall.h>
static void
mach_startup_info2hurd_startup_data (struct mach_msg_startup_info *info,
struct hurd_startup_data *data)
{
data->flags = info->flags;
data->dtable = info->dtable;
data->dtable_count = info->dtableType.msgtl_number;
data->argp = info->argv;
data->arg_size = info->argvType.msgtl_number;
data->envp = info->envp;
data->env_size = info->envpType.msgtl_number;
data->portarray = info->portarray;
data->portarray_count = info->portarrayType.msgtl_number;
data->intarray = info->intarray;
data->intarray_count = info->intarrayType.msgtl_number;
data->stack_base = info->stack_base;
data->stack_count = info->stack_size;
data->phdr = info->phdr;
data->phdr_count = info->phdr_size;
data->user_entry = info->user_entry;
}
kern_return_t
__exec_startup_get_data (mach_port_t bootstrap, struct hurd_startup_data *data)
{
union message
{
mach_msg_header_t header;
struct mach_msg_startup_info info;
};
union message message;
message.header.msgh_size = sizeof (struct mach_msg);
kern_return_t result = __syscall_get (bootstrap, SYS__exec_startup_get_info,
&message.header, sizeof (message));
mach_startup_info2hurd_startup_data (&message.info, data);
return result;
}

37
lib/gnu/fd-get.c Normal file
View File

@ -0,0 +1,37 @@
/* -*-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/>.
*/
/** Commentary:
Inspired by implementation in GNU C Library:
_hurd_fd_get
Copyright (C) 1993-2016 Free Software Foundation, Inc.
*/
#include <errno.h>
#include <unistd.h>
#include <gnu/hurd.h>
mach_port_t
fd_get (int filedes)
{
if (filedes >=0 && filedes <= _hurd_dtable_count)
return _hurd_dtable[filedes];
return 0;
}

40
lib/gnu/fd-read.c Normal file
View File

@ -0,0 +1,40 @@
/* -*-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/>.
*/
/** Commentary:
Inspired by implementation in GNU C Library:
_hurd_fd_read
Copyright (C) 1993-2016 Free Software Foundation, Inc.
*/
#include <gnu/hurd.h>
#include <gnu/syscall.h>
#include <string.h>
#include <errno.h>
error_t
fd_read (mach_port_t port, void *buffer, size_t *read, loff_t offset)
{
char *data;
error_t e = __io_read (port, &data, read, offset, *read);
if (!e)
memcpy (buffer, data, *read);
return e;
}

41
lib/gnu/fd-write.c Normal file
View File

@ -0,0 +1,41 @@
/* -*-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/>.
*/
/** Commentary:
Inspired by implementation in GNU C Library:
_hurd_fd_write -- write to a file descriptor; handles job control et al.
Copyright (C) 1993-2016 Free Software Foundation, Inc.
*/
#include <errno.h>
#include <unistd.h>
#include <gnu/hurd.h>
#include <gnu/syscall.h>
error_t
fd_write (mach_port_t port, void const *buffer, size_t *size, loff_t offset)
{
mach_msg_type_number_t wrote = 0;
error_t err = __io_write (port, buffer, *size, 0, &wrote);
if (! err)
*size = wrote;
return err;
}

60
lib/gnu/hurd-start.c Normal file
View File

@ -0,0 +1,60 @@
/* -*-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/>.
*/
/** Commentary:
Inspired by implementation in GNU C Library:
Initialization code run first thing by the ELF startup code. For i386/Hurd.
Copyright (C) 1995-2016 Free Software Foundation, Inc.
*/
#include <mes/lib-mini.h>
#include <argz.h>
#include <gnu/hurd.h>
#include <gnu/syscall.h>
#include <mach/mach-init.h>
#include <mach/mach_types.h>
#include <mach/message.h>
#include <mach/port.h>
struct hurd_startup_data _hurd_startup_data;
mach_port_t _hurd_dtable[_HURD_DTABLE_MAX];
int _hurd_dtable_count;
size_t __argc;
char *__argv[_HURD_ARGV_MAX];
char *__envv[_HURD_ENVV_MAX];
void __mach_init (void);
void
_hurd_start ()
{
mach_port_t bootstrap;
__mach_init ();
__task_get_special_port (mach_task_self (), TASK_BOOTSTRAP_PORT,
&bootstrap);
__exec_startup_get_data (bootstrap, &_hurd_startup_data);
_hurd_dtable_count = _hurd_startup_data.dtable_count;
for (int i = 0; i < _hurd_dtable_count; i++)
_hurd_dtable[i] = _hurd_startup_data.dtable[i];
__argc = __argz_extract_count (_hurd_startup_data.argp, _hurd_startup_data.arg_size, __argv);
__argz_extract (_hurd_startup_data.envp, _hurd_startup_data.env_size, __envv);
environ = __envv;
}

60
lib/gnu/io-read.c Normal file
View File

@ -0,0 +1,60 @@
/* -*-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 <gnu/syscall.h>
struct mach_msg_int_pointer
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
mach_msg_type_long_t type_two; union {char *two; char pointer[2048];};
};
kern_return_t
__io_read (io_t io, data_t *data, mach_msg_type_number_t *read, loff_t offset, vm_size_t size)
{
union message
{
struct mach_msg_loff_int request;
struct mach_msg_int_pointer reply;
};
union message message = {0};
message.request.header.msgh_size = sizeof (message.request);
message.request.type_one = mach_msg_type_int64;
message.request.one = offset;
message.request.type_two = mach_msg_type_int32;
message.request.two = size;
kern_return_t result = __syscall_put (io, SYS__io_read,
&message.request.header,
sizeof (message.reply));
if (result == KERN_SUCCESS)
{
*read = message.reply.type_two.msgtl_number;
*data = message.reply.pointer;
}
else
{
*read = 0;
*data = 0;
}
return result;
}

50
lib/gnu/io-write.c Normal file
View File

@ -0,0 +1,50 @@
/* -*-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 <gnu/syscall.h>
struct mach_msg_pointer_loff
{
mach_msg_header_t header;
mach_msg_type_long_t type_one; char *one;
mach_msg_type_t type_two; loff_t two;
};
kern_return_t
__io_write (io_t io, data_t data, mach_msg_type_number_t size, loff_t offset, vm_size_t *wrote)
{
struct mach_msg_pointer_loff message = {0};
message.header.msgh_size = sizeof (struct mach_msg_pointer_loff);
message.type_one = mach_msg_type_pointer;
message.one = data;
message.type_two = mach_msg_type_int64;
message.two = offset;
message.type_one.msgtl_number = size;
message.type_one.msgtl_header.msgt_inline = 0;
message.header.msgh_bits = MACH_MSGH_BITS_COMPLEX;
kern_return_t result = __syscall_put (io, SYS__io_write,
&message.header,
sizeof (struct mach_msg_2));
if (result == KERN_SUCCESS)
*wrote = message.two;
return result;
}

34
lib/gnu/malloc.c Normal file
View File

@ -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 <gnu/syscall.h>
#include <mach/mach-init.h>
void *
malloc (size_t size)
{
vm_address_t where;
vm_size_t amount = size;
kern_return_t e = __vm_allocate (mach_task_self (), &where, (vm_size_t) amount, 1);
if (e)
return 0;
return (void*) where;
}

28
lib/gnu/proc-mark-exit.c Normal file
View File

@ -0,0 +1,28 @@
/* -*-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 <gnu/syscall.h>
#include <sys/wait.h>
kern_return_t
__proc_mark_exit (mach_port_t process, int status, int signal)
{
return __syscall2 (process, SYS__proc_mark_exit, W_EXITCODE (status, 0), signal);
}

143
lib/gnu/syscall.c Normal file
View File

@ -0,0 +1,143 @@
/* -*-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 <gnu/syscall.h>
#include <mach/mach_traps.h>
mach_msg_type_t mach_msg_type_int32 =
{
.msgt_name = (unsigned char) MACH_MSG_TYPE_INTEGER_32, // msgt_name
.msgt_size = 32, // msgt_size
.msgt_number = 1, // msgt_number
.msgt_inline = 1, // msgt_inline
.msgt_longform = 0, // msgt_longform
.msgt_deallocate = 0, // msgt_deallocate
.msgt_unused = 0 // msgt_unused
};
mach_msg_type_long_t mach_msg_type_pointer =
{
{
0, // msgt_name
0, // msgt_size
0, // msgt_number
1, // msgt_inline FIXME: we always outline...
1, // msgt_longform
0, // msgt_deallocate
0, // msgt_unused
},
MACH_MSG_TYPE_CHAR, // msgtl_name
8, // msgtl_size
2048, // msgtl_number
};
mach_msg_type_t mach_msg_type_int64 =
{
(unsigned char) MACH_MSG_TYPE_INTEGER_64, // msgt_name
64, // msgt_size
1, // msgt_number
1, // msgt_inline
0, // msgt_longform
0, // msgt_deallocate
0, // msgt_unused
};
kern_return_t
__syscall (mach_port_t port, int sys_call)
{
struct mach_msg message =
{
{
MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE),
0,
port,
{__mach_reply_port (),},
0,
sys_call,
}
};
return __mach_msg (&message.header,
MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
sizeof (message),
sizeof (message),
message.header.msgh_local_port,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL);
}
kern_return_t
__syscall2 (mach_port_t port, int sys_call, int one, int two)
{
struct mach_msg_2 message =
{
{
MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE),
0,
port,
{__mach_reply_port (),},
0,
sys_call,
},
mach_msg_type_int32, one,
mach_msg_type_int32, two,
};
return __mach_msg (&message.header,
MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
sizeof (message),
sizeof (message),
message.header.msgh_local_port,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL);
}
kern_return_t
__syscall_get (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size)
{
message->msgh_bits = MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE);
message->msgh_remote_port = port;
message->msgh_local_port = __mach_reply_port ();
message->msgh_seqno = 0;
message->msgh_id = sys_call;
return __mach_msg (message,
MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
message->msgh_size,
size,
message->msgh_local_port,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL);
}
kern_return_t
__syscall_put (mach_port_t port, int sys_call, mach_msg_header_t *message, size_t size)
{
message->msgh_bits |= MACH_MSGH_BITS (MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE);
message->msgh_remote_port = port;
message->msgh_local_port = __mach_reply_port ();
message->msgh_seqno = 0;
message->msgh_id = sys_call;
return __mach_msg (message,
MACH_SEND_MSG|MACH_RCV_MSG|MACH_MSG_OPTION_NONE,
message->msgh_size,
size,
message->msgh_local_port,
MACH_MSG_TIMEOUT_NONE,
MACH_PORT_NULL);
}

View File

@ -0,0 +1,37 @@
/* -*-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 <gnu/syscall.h>
kern_return_t
__task_get_special_port (mach_port_t task, int which, mach_port_t *port)
{
struct mach_msg_2 message = {0};
message.header.msgh_size = sizeof (struct mach_msg_1);
message.type_one = mach_msg_type_int32;
message.one = which;
message.type_two = mach_msg_type_int32;
message.two = 0;
kern_return_t result = __syscall_get (task, SYS__task_get_special_port,
&message.header, sizeof (message));
if (result == KERN_SUCCESS)
*port = message.two;
return result;
}

27
lib/gnu/task-terminate.c Normal file
View File

@ -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 <gnu/syscall.h>
kern_return_t
__task_terminate (mach_port_t task)
{
return __syscall (task, SYS__task_terminate);
}

76
lib/gnu/vm-allocate.c Normal file
View File

@ -0,0 +1,76 @@
/* -*-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 <gnu/syscall.h>
struct mach_msg_int_address
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
mach_msg_type_t type_two; vm_address_t two;
};
struct mach_msg_address_int_int
{
mach_msg_header_t header;
mach_msg_type_t type_one; vm_address_t one;
mach_msg_type_t type_two; vm_size_t two;
mach_msg_type_t type_three; boolean_t three;
};
const mach_msg_type_t mach_msg_type_boolean =
{
(unsigned char) MACH_MSG_TYPE_BOOLEAN, // msgt_name
32, // msgt_size
1, // msgt_number
1, // msgt_inline
0, // msgt_longform
0, // msgt_deallocate
0 // msgt_unused
};
kern_return_t
__vm_allocate (mach_port_t task, vm_address_t *address, vm_size_t size, boolean_t anywhere)
{
union message
{
struct mach_msg_address_int_int request;
struct mach_msg_int_address reply;
};
union message message = {0};
message.request.header.msgh_size = sizeof (message.request);
message.request.type_one = mach_msg_type_int32;
message.request.one = *address;
message.request.type_two = mach_msg_type_int32;
message.request.two = size;
message.request.type_three = mach_msg_type_boolean;
message.request.three = anywhere;
kern_return_t result = __syscall_get (task, SYS__vm_allocate,
&message.request.header,
sizeof (message.reply));
if (message.reply.one != KERN_SUCCESS)
return message.reply.one;
if (result == KERN_SUCCESS)
*address = message.reply.two;
return result;
}

41
lib/gnu/vm-statistics.c Normal file
View File

@ -0,0 +1,41 @@
/* -*-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 <gnu/syscall.h>
struct mach_msg_int32_vm_statistics_data
{
mach_msg_header_t header;
mach_msg_type_t type_one; int one;
mach_msg_type_t type_two; vm_statistics_data_t two;
};
kern_return_t
__vm_statistics (mach_port_t task, vm_statistics_data_t *vm_stats)
{
struct mach_msg_int32_vm_statistics_data message = {0};
message.header.msgh_size = sizeof (struct mach_msg);
message.type_one = mach_msg_type_int32;
message.type_two = mach_msg_type_int32;
kern_return_t result = __syscall_get (task, SYS__vm_statistics,
&message.header, sizeof (message));
*vm_stats = message.two;
return result;
}

View File

@ -0,0 +1,43 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of 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.
*
* 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 Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gnu/hurd.h>
char **environ;
int __stdin;
int __stdout;
int __stderr;
int main ();
void _exit (int status);
void _hurd_start (void);
void
_start ()
{
_hurd_start ();
__stdin = 0;
__stdout = 1;
__stderr = 2;
int r = main (__argc, __argv, environ);
_exit (r);
asm ("hlt");
}

View File

@ -0,0 +1,23 @@
/* -*-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-mini.h"
// your mini mach here

29
lib/linux/mknod.c Normal file
View File

@ -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);
}

29
lib/linux/mmap.c Normal file
View File

@ -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>
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);
}

29
lib/linux/munmap.c Normal file
View File

@ -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);
}

29
lib/linux/readlink.c Normal file
View File

@ -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);
}

29
lib/linux/symlink.c Normal file
View File

@ -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);
}

View File

@ -69,9 +69,8 @@ _start ()
"call main\n\t"
"mov %eax,%ebx\n\t"
"mov $1,%eax\n\t"
"int $0x80\n\t"
"push %eax\n\t"
"call _exit\n\t"
"hlt \n\t"
);
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

75
lib/mach/mach-init.c Normal file
View File

@ -0,0 +1,75 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 1992-2016 Free Software Foundation, Inc.
* 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:
Taken from GNU C Library
*/
#define _GNU_SOURCE 1
#define __USE_GNU 1
#define __FILE_defined 1
#include <stdio.h>
#include <mach/mach-init.h>
#include <mach.h>
#include <unistd.h>
mach_port_t __mach_task_self_;
mach_port_t __mach_host_self_;
vm_size_t __vm_page_size = 0;
void
__mach_init (void)
{
kern_return_t err;
#ifdef HAVE_HOST_PAGE_SIZE
if (err = __host_page_size (mach_host_self (), &__vm_page_size))
_exit (err);
#else
{
vm_statistics_data_t stats;
if (err = __vm_statistics (mach_task_self (), &stats))
_exit (err);
__vm_page_size = stats.pagesize;
}
#endif
}
extern mach_port_t __mach_host_self (void);
mach_port_t
mach_host_self (void)
{
if (!__mach_host_self_)
__mach_host_self_ = __mach_host_self ();
return __mach_host_self_;
}
extern mach_port_t __mach_task_self (void);
mach_port_t
mach_task_self (void)
{
if (!__mach_task_self_)
__mach_task_self_ = __mach_task_self ();
return __mach_task_self_;
}

View File

@ -0,0 +1,3 @@
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_host_self,-29,0)
// weak_alias (__mach_host_self, mach_host_self)

3
lib/mach/mach_msg_trap.S Normal file
View File

@ -0,0 +1,3 @@
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_msg_trap,-25,7)
// weak_alias (__mach_msg_trap, mach_msg_trap)

View File

@ -0,0 +1,3 @@
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_reply_port,-26,0)
// weak_alias (__mach_reply_port, mach_reply_port)

View File

@ -0,0 +1,3 @@
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_task_self,-28,0)
// weak_alias (__mach_task_self, mach_task_self)

View File

@ -0,0 +1,19 @@
#if 1
#include <mach/machine/syscall_sw.h>
kernel_trap (__mach_thread_self,-27,0)
// weak_alias (__mach_thread_self, mach_thread_self)
#else
.globl __mach_thread_self
.type __mach_thread_self,@function
.align 1<<4
__mach_thread_self: .cfi_startproc
movl $ -27,%eax
.byte 0x9a
.long 0
.word 0x7
ret
.cfi_endproc
.size __mach_thread_self,.-__mach_thread_self
.weak mach_thread_self
mach_thread_self = __mach_thread_self
#endif

145
lib/mach/msg.c Normal file
View File

@ -0,0 +1,145 @@
/*
* Mach Operating System
* Copyright (c) 1991,1990,1989, 1995 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
#include <mach/port.h>
#include <mach/message.h>
#ifdef MACH_MSG_OVERWRITE
/* In variants with this feature, the actual system call is
__mach_msg_overwrite_trap. */
mach_msg_return_t
__mach_msg_trap (mach_msg_header_t *msg,
mach_msg_option_t option,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_t rcv_name,
mach_msg_timeout_t timeout,
mach_port_t notify)
{
return __mach_msg_overwrite_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify,
MACH_MSG_NULL, 0);
}
weak_alias (__mach_msg_trap, mach_msg_trap)
/* See comments below in __mach_msg. */
mach_msg_return_t
__mach_msg_overwrite (mach_msg_header_t *msg,
mach_msg_option_t option,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_t rcv_name,
mach_msg_timeout_t timeout,
mach_port_t notify,
mach_msg_header_t *rcv_msg,
mach_msg_size_t rcv_msg_size)
{
mach_msg_return_t ret;
/* Consider the following cases:
1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
plus special bits).
2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
3. RPC calls with interruptions in one/both halves.
*/
ret = __mach_msg_overwrite_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify,
rcv_msg, rcv_msg_size);
if (ret == MACH_MSG_SUCCESS)
return MACH_MSG_SUCCESS;
if (!(option & MACH_SEND_INTERRUPT))
while (ret == MACH_SEND_INTERRUPTED)
ret = __mach_msg_overwrite_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify,
rcv_msg, rcv_msg_size);
if (!(option & MACH_RCV_INTERRUPT))
while (ret == MACH_RCV_INTERRUPTED)
ret = __mach_msg_overwrite_trap (msg, option & ~MACH_SEND_MSG,
0, rcv_size, rcv_name, timeout, notify,
rcv_msg, rcv_msg_size);
return ret;
}
weak_alias (__mach_msg_overwrite, mach_msg_overwrite)
#endif
mach_msg_return_t
__mach_msg (mach_msg_header_t *msg,
mach_msg_option_t option,
mach_msg_size_t send_size,
mach_msg_size_t rcv_size,
mach_port_t rcv_name,
mach_msg_timeout_t timeout,
mach_port_t notify)
{
mach_msg_return_t ret;
/* Consider the following cases:
1. Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
plus special bits).
2. Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
3. RPC calls with interruptions in one/both halves.
*/
ret = __mach_msg_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify);
if (ret == MACH_MSG_SUCCESS)
return MACH_MSG_SUCCESS;
if (!(option & MACH_SEND_INTERRUPT))
while (ret == MACH_SEND_INTERRUPTED)
ret = __mach_msg_trap (msg, option, send_size,
rcv_size, rcv_name, timeout, notify);
if (!(option & MACH_RCV_INTERRUPT))
while (ret == MACH_RCV_INTERRUPTED)
ret = __mach_msg_trap (msg, option & ~MACH_SEND_MSG,
0, rcv_size, rcv_name, timeout, notify);
return ret;
}
// weak_alias (__mach_msg, mach_msg)
mach_msg_return_t
__mach_msg_send (mach_msg_header_t *msg)
{
return __mach_msg (msg, MACH_SEND_MSG,
msg->msgh_size, 0, MACH_PORT_NULL,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}
// weak_alias (__mach_msg_send, mach_msg_send)
mach_msg_return_t
__mach_msg_receive (mach_msg_header_t *msg)
{
return __mach_msg (msg, MACH_RCV_MSG,
0, msg->msgh_size, msg->msgh_local_port,
MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
}
// weak_alias (__mach_msg_receive, mach_msg_receive)

29
lib/math/ceil.c Normal file
View File

@ -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;
}

View File

@ -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)

29
lib/math/floor.c Normal file
View File

@ -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;
}

29
lib/math/labs.c Normal file
View File

@ -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;
}

53
lib/mes/abtod.c Normal file
View File

@ -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;
}

View File

@ -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;
}

46
lib/mes/dtoab.c Normal file
View File

@ -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;
}

View File

@ -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;
}

47
lib/posix/execlp.c Normal file
View File

@ -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;
}

View File

@ -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);
}

View File

@ -54,7 +54,7 @@ fopen (char const *file_name, char const *opentype)
fd = _open3 (file_name, flags, mode);
}
else
fd = _open3 (file_name, 0, 0);
fd = _open3 (file_name, O_RDONLY, 0);
if (__mes_debug ())
{

33
lib/stdio/fscanf.c Normal file
View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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++;
}

209
lib/stdio/vfscanf.c Normal file
View File

@ -0,0 +1,209 @@
/* -*-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 <ctype.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;
}

View File

@ -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++;
}

View File

@ -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++;

View File

@ -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)
{

View File

@ -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>
void
abort (void)
{

View File

@ -25,4 +25,5 @@ int
atexit (void (*function) (void))
{
__call_at_exit = function;
return 0;
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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);

41
lib/stdlib/strtod.c Normal file
View File

@ -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);
}

View File

@ -18,9 +18,10 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
/* Taken from GNU C Library
* Routines for dealing with '\0' separated arg vectors.
* Written by Miles Bader <miles@gnu.ai.mit.edu>
/** Commentary:
Taken from GNU C Library
Routines for dealing with '\0' separated arg vectors.
Written by Miles Bader <miles@gnu.org>
*/
#include <argz.h>
@ -40,5 +41,3 @@ __argz_count (const char *argz, size_t len)
}
return count;
}
libc_hidden_def (__argz_count) weak_alias (__argz_count, argz_count)

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright (C) 1995-2018 Free Software Foundation, Inc.
* Copyright © 1995-2018 Free Software Foundation, Inc.
* Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
@ -18,9 +19,10 @@
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
/* Taken from GNU C Library
* Routines for dealing with '\0' separated arg vectors.
* Written by Miles Bader <miles@gnu.org>
/** Commentary:
Taken from GNU C Library
Routines for dealing with '\0' separated arg vectors.
Written by Miles Bader <miles@gnu.org>
*/
#include <argz.h>
@ -28,16 +30,23 @@
/* Puts pointers to each string in ARGZ, plus a terminating 0 element, into
ARGV, which must be large enough to hold them all. */
void
__argz_extract (const char *argz, size_t len, char **argv)
__argz_extract (char const *argz, size_t len, char **argv)
{
__argz_extract_count (argz, len, argv);
}
size_t
__argz_extract_count (char const *argz, size_t len, char **argv)
{
size_t count = 0;
while (len > 0)
{
size_t part_len = strlen (argz);
*argv++ = (char *) argz;
argz += part_len + 1;
len -= part_len + 1;
count ++;
}
*argv = 0;
return count;
}
weak_alias (__argz_extract, argz_extract)

Some files were not shown because too many files have changed in this diff Show More