unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Sergey Bugaev <bugaevc@gmail.com>
To: libc-alpha@sourceware.org, bug-hurd@gnu.org
Cc: Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>, Luca <luca@orpolo.org>
Subject: [PATCH v2 19/20] htl: Add an AArch64 implementation
Date: Sat, 23 Mar 2024 20:33:00 +0300	[thread overview]
Message-ID: <20240323173301.151066-20-bugaevc@gmail.com> (raw)
In-Reply-To: <20240323173301.151066-1-bugaevc@gmail.com>

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 sysdeps/aarch64/htl/Makefile                 | 20 ++++++
 sysdeps/aarch64/htl/bits/pthreadtypes-arch.h | 36 ++++++++++
 sysdeps/aarch64/htl/machine-sp.h             | 29 ++++++++
 sysdeps/aarch64/htl/pt-machdep.h             | 28 ++++++++
 sysdeps/mach/hurd/aarch64/htl/pt-machdep.c   | 55 ++++++++++++++
 sysdeps/mach/hurd/aarch64/htl/pt-setup.c     | 76 ++++++++++++++++++++
 6 files changed, 244 insertions(+)
 create mode 100644 sysdeps/aarch64/htl/Makefile
 create mode 100644 sysdeps/aarch64/htl/bits/pthreadtypes-arch.h
 create mode 100644 sysdeps/aarch64/htl/machine-sp.h
 create mode 100644 sysdeps/aarch64/htl/pt-machdep.h
 create mode 100644 sysdeps/mach/hurd/aarch64/htl/pt-machdep.c
 create mode 100644 sysdeps/mach/hurd/aarch64/htl/pt-setup.c

diff --git a/sysdeps/aarch64/htl/Makefile b/sysdeps/aarch64/htl/Makefile
new file mode 100644
index 00000000..686b843d
--- /dev/null
+++ b/sysdeps/aarch64/htl/Makefile
@@ -0,0 +1,20 @@
+# Copyright (C) 2020-2024 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library 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
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+
+ifeq ($(subdir),csu)
+gen-as-const-headers += tcb-offsets.sym
+endif
diff --git a/sysdeps/aarch64/htl/bits/pthreadtypes-arch.h b/sysdeps/aarch64/htl/bits/pthreadtypes-arch.h
new file mode 100644
index 00000000..9ee1568e
--- /dev/null
+++ b/sysdeps/aarch64/htl/bits/pthreadtypes-arch.h
@@ -0,0 +1,36 @@
+/* Machine-specific pthread type layouts.  Hurd AArch64 version.
+   Copyright (C) 2002-2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _BITS_PTHREADTYPES_ARCH_H
+#define _BITS_PTHREADTYPES_ARCH_H	1
+
+#define __SIZEOF_PTHREAD_MUTEX_T 32
+#define __SIZEOF_PTHREAD_ATTR_T 48
+#define __SIZEOF_PTHREAD_RWLOCK_T 48
+#define __SIZEOF_PTHREAD_BARRIER_T 40
+#define __SIZEOF_PTHREAD_MUTEXATTR_T 16
+#define __SIZEOF_PTHREAD_COND_T 40
+#define __SIZEOF_PTHREAD_CONDATTR_T 8
+#define __SIZEOF_PTHREAD_RWLOCKATTR_T 4
+#define __SIZEOF_PTHREAD_BARRIERATTR_T 4
+#define __SIZEOF_PTHREAD_ONCE_T 8
+
+#define __LOCK_ALIGNMENT
+#define __ONCE_ALIGNMENT
+
+#endif /* bits/pthreadtypes.h */
diff --git a/sysdeps/aarch64/htl/machine-sp.h b/sysdeps/aarch64/htl/machine-sp.h
new file mode 100644
index 00000000..b21331a0
--- /dev/null
+++ b/sysdeps/aarch64/htl/machine-sp.h
@@ -0,0 +1,29 @@
+/* Machine-specific function to return the stack pointer.  AArch64 version.
+   Copyright (C) 1994-2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library;  if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _MACHINE_SP_H
+#define _MACHINE_SP_H
+
+/* Return the current stack pointer.  */
+
+#define __thread_stack_pointer() ({						\
+  register uintptr_t __sp__ asm("sp");						\
+  __sp__;									\
+})
+
+#endif /* machine-sp.h */
diff --git a/sysdeps/aarch64/htl/pt-machdep.h b/sysdeps/aarch64/htl/pt-machdep.h
new file mode 100644
index 00000000..c3681b4a
--- /dev/null
+++ b/sysdeps/aarch64/htl/pt-machdep.h
@@ -0,0 +1,28 @@
+/* Machine dependent pthreads internal definitions.  AArch64 version.
+   Copyright (C) 2000-2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library;  if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#ifndef _PT_MACHDEP_H
+#define _PT_MACHDEP_H	1
+
+struct pthread_mcontext
+{
+  void *pc;
+  void *sp;
+};
+
+#endif /* pt-machdep.h */
diff --git a/sysdeps/mach/hurd/aarch64/htl/pt-machdep.c b/sysdeps/mach/hurd/aarch64/htl/pt-machdep.c
new file mode 100644
index 00000000..e6e68ee1
--- /dev/null
+++ b/sysdeps/mach/hurd/aarch64/htl/pt-machdep.c
@@ -0,0 +1,55 @@
+/* Machine dependent pthreads code.  Hurd/AArch64 version.
+   Copyright (C) 2000-2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library;  if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <assert.h>
+
+#include <mach.h>
+#include <mach/machine/thread_status.h>
+#include <mach/mig_errors.h>
+#include <mach/thread_status.h>
+
+int
+__thread_set_pcsptp (thread_t thread,
+                     int set_pc, void *pc,
+                     int set_sp, void *sp,
+                     int set_tp, void *tp)
+{
+  error_t err;
+  struct aarch64_thread_state state;
+  mach_msg_type_number_t state_count;
+
+  state_count = AARCH64_THREAD_STATE_COUNT;
+
+  err = __thread_get_state (thread, AARCH64_THREAD_STATE,
+                            (thread_state_t) &state, &state_count);
+  if (err)
+    return err;
+  assert (state_count == AARCH64_THREAD_STATE_COUNT);
+
+  if (set_pc)
+    state.pc = (uintptr_t) pc;
+  if (set_sp)
+    state.sp = (uintptr_t) sp;
+  if (set_tp)
+    state.tpidr_el0 = (uintptr_t) tp;
+
+  return __thread_set_state (thread, AARCH64_THREAD_STATE,
+			     (thread_state_t) &state,
+			     AARCH64_THREAD_STATE_COUNT);
+}
diff --git a/sysdeps/mach/hurd/aarch64/htl/pt-setup.c b/sysdeps/mach/hurd/aarch64/htl/pt-setup.c
new file mode 100644
index 00000000..e57d9210
--- /dev/null
+++ b/sysdeps/mach/hurd/aarch64/htl/pt-setup.c
@@ -0,0 +1,76 @@
+/* Setup thread stack.  Hurd/AArch64 version.
+   Copyright (C) 2000-2024 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library;  if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <stdint.h>
+#include <assert.h>
+#include <mach.h>
+#include <hurd.h>
+
+#include <thread_state.h>
+#include <pt-internal.h>
+
+/* Set up the stack for THREAD.  Return the stack pointer
+   for the new thread.  */
+static void *
+stack_setup (struct __pthread *thread)
+{
+  error_t err;
+  uintptr_t bottom, top;
+
+  /* Calculate the top of the new stack.  */
+  bottom = (uintptr_t) thread->stackaddr;
+  top = bottom + thread->stacksize + round_page (thread->guardsize);
+
+  if (thread->guardsize)
+    {
+      err = __vm_protect (__mach_task_self (), (vm_address_t) bottom,
+			  thread->guardsize, 0, 0);
+      assert_perror (err);
+    }
+
+  return (void *) top;
+}
+
+int
+__pthread_setup (struct __pthread *thread,
+		 void (*entry_point) (struct __pthread *, void *(*)(void *),
+				      void *),
+		 void *(*start_routine) (void *),
+		 void *arg)
+{
+  struct aarch64_thread_state state;
+
+  if (thread->kernel_thread == __hurd_thread_self ())
+    return 0;
+
+  thread->mcontext.pc = entry_point;
+  thread->mcontext.sp = stack_setup (thread);
+
+  /* Set up the state to call entry_point (thread, start_routine, arg) */
+  memset (&state, 0, sizeof (state));
+  state.sp = (uintptr_t) thread->mcontext.sp;
+  state.pc = (uintptr_t) thread->mcontext.pc;
+  state.x[0] = (uintptr_t) thread;
+  state.x[1] = (uintptr_t) start_routine;
+  state.x[2] = (uintptr_t) arg;
+  state.tpidr_el0 = (uintptr_t) thread->tcb;
+
+  return __thread_set_state (thread->kernel_thread, AARCH64_THREAD_STATE,
+			     (thread_state_t) &state,
+			     AARCH64_THREAD_STATE_COUNT);
+}
-- 
2.44.0


  parent reply	other threads:[~2024-03-23 17:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-23 17:32 [PATCH v2 00/20] aarch64-gnu port & GNU/Hurd on AArch64 progress Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 01/20] hurd: Move internal functions to internal header Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 02/20] hurd: Stop relying on VM_MAX_ADDRESS Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 03/20] Allow glibc to be compiled without EXEC_PAGESIZE Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 04/20] hurd: Disable Prefer_MAP_32BIT_EXEC on non-x86_64 for now Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 05/20] hurd: Use the RETURN_ADDRESS macro Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 06/20] htl: Respect GL(dl_stack_flags) when allocating stacks Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 07/20] aarch64: Move pointer_guard.h out of sysdeps/unix/sysv/linux Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 08/20] aarch64: Add dl-procinfo Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 09/20] aarch64: Move saving user entry into _dl_start_user Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 10/20] aarch64: Allow building without kernel support for BTI Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 11/20] mach: Add a basic AArch64 port Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 12/20] mach: Declare the new thread_set_self_state () trap Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 13/20] hurd: Add a basic AArch64 port Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 14/20] hurd: Implement TLS on AArch64 Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 15/20] hurd: Implement longjmp for AArch64 Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 16/20] Add FPE_FLTIDO Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 17/20] hurd: Add an AArch64 signal implementation Sergey Bugaev
2024-03-23 17:32 ` [PATCH v2 18/20] htl: Implement some support for TLS_DTV_AT_TP Sergey Bugaev
2024-03-23 17:33 ` Sergey Bugaev [this message]
2024-03-23 17:33 ` [PATCH v2 20/20] hurd: Add expected aarch64-gnu abistlists Sergey Bugaev
2024-03-23 22:16 ` [PATCH v2 00/20] aarch64-gnu port & GNU/Hurd on AArch64 progress Samuel Thibault
2024-03-26  8:29 ` Sergey Bugaev
2024-03-26 10:15   ` Maxim Kuvyrkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240323173301.151066-20-bugaevc@gmail.com \
    --to=bugaevc@gmail.com \
    --cc=bug-hurd@gnu.org \
    --cc=libc-alpha@sourceware.org \
    --cc=luca@orpolo.org \
    --cc=maxim.kuvyrkov@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).