Add mes and mescc-tools-extra

mescc-tools-extra contains two important tools:
- cp
- chmod

mes first builds itself from a mes 0.21 seed as used by guix, and then
builds a mes 0.22 and then mes 0.22 using that created mes 0.22.

It does /not/ use bootstrap.sh as we don't have a proper shell at this
point, it has been manually adapted for kaem.
This commit is contained in:
fosslinux 2020-12-25 18:40:14 +11:00
parent 2706e07556
commit 649d7b68dc
1029 changed files with 120985 additions and 18 deletions

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
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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