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
Subject: [RFC PATCH 22/23] htl: Add an AArch64 implementation
Date: Wed,  3 Jan 2024 20:14:55 +0300	[thread overview]
Message-ID: <20240103171502.1358371-23-bugaevc@gmail.com> (raw)
In-Reply-To: <20240103171502.1358371-1-bugaevc@gmail.com>

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---

This is completely untested.

 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     | 80 ++++++++++++++++++++
 6 files changed, 248 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..f2a3354c
--- /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..7d1562a0
--- /dev/null
+++ b/sysdeps/mach/hurd/aarch64/htl/pt-setup.c
@@ -0,0 +1,80 @@
+/* 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)
+{
+  error_t err;
+  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.x[29] = state.x[30] = 0;
+  state.tpidr_el0 = (uintptr_t) thread->tcb;
+
+  err = __thread_set_state (thread->kernel_thread, AARCH64_THREAD_STATE,
+			    (thread_state_t) &state,
+			    AARCH64_THREAD_STATE_COUNT);
+  assert_perror (err);
+
+  return 0;
+}
-- 
2.43.0


  parent reply	other threads:[~2024-01-03 17:22 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03 17:14 [RFC PATCH 00/23] aarch64-gnu port Sergey Bugaev
2024-01-03 17:14 ` [PATCH 01/23] hurd: Add some missing includes Sergey Bugaev
2024-01-03 20:43   ` Samuel Thibault
2024-01-03 21:08     ` Sergey Bugaev
2024-01-03 21:24       ` Sergey Bugaev
2024-01-03 21:35         ` Samuel Thibault
2024-01-03 21:00   ` Samuel Thibault
2024-01-03 17:14 ` [PATCH 02/23] hurd: Declare _hurd_intr_rpc_msg* with protected visibility Sergey Bugaev
2024-01-03 21:00   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 03/23] Allow glibc to be compiled without EXEC_PAGESIZE Sergey Bugaev
2024-03-11 16:13   ` Florian Weimer
2024-03-25 11:58     ` Florian Weimer
2024-03-25 12:24       ` Sergey Bugaev
2024-04-10 11:57         ` Florian Weimer
2024-04-15 12:53           ` Sergey Bugaev
2024-04-22 21:01         ` Samuel Thibault
2024-01-03 17:14 ` [PATCH 04/23] mach: Drop some unnecessary vm_param.h includes Sergey Bugaev
2024-01-03 21:00   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 05/23] hurd: Disable Prefer_MAP_32BIT_EXEC on non-x86_64 for now Sergey Bugaev
2024-01-03 17:14 ` [PATCH 06/23] mach: Drop SNARF_ARGS macro Sergey Bugaev
2024-01-03 21:00   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 07/23] hurd: Pass the data pointer to _hurd_stack_setup explicitly Sergey Bugaev
2024-01-04 22:47   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 08/23] hurd: Drop x86-specific assembly from init-first.c Sergey Bugaev
2024-01-04 22:48   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 09/23] hurd: Make init-first.c no longer x86-specific Sergey Bugaev
2024-01-04 22:48   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 10/23] hurd: Only init early static TLS if it's used to store stack or pointer guards Sergey Bugaev
2024-01-04 22:48   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 11/23] hurd: Initializy _dl_pagesize early in static builds Sergey Bugaev
2024-01-04 22:48   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 12/23] aarch64: Make cpu-features definitions not Linux-specific Sergey Bugaev
2024-01-04 22:48   ` Samuel Thibault
2024-01-03 17:14 ` [RFC PATCH 13/23] aarch64: Add dl-procinfo Sergey Bugaev
2024-01-03 17:14 ` [RFC PATCH 14/23] aarch64: Allow building without kernel support for BTI Sergey Bugaev
2024-01-03 17:14 ` [RFC PATCH 15/23] mach: Add a basic AArch64 port Sergey Bugaev
2024-01-03 17:14 ` [RFC PATCH 16/23] hurd: " Sergey Bugaev
2024-01-03 17:14 ` [RFC PATCH 17/23] hurd: Implement TLS on AArch64 Sergey Bugaev
2024-01-03 17:14 ` [RFC PATCH 18/23] hurd: Implement longjmp for AArch64 Sergey Bugaev
2024-01-03 17:14 ` [RFC PATCH 19/23] Add FPE_FLTIDO Sergey Bugaev
2024-01-03 17:14 ` [RFC PATCH 20/23] hurd: Add an AArch64 signal implementation Sergey Bugaev
2024-01-03 17:14 ` [RFC PATCH 21/23] htl: Implement some support for TLS_DTV_AT_TP Sergey Bugaev
2024-01-03 17:14 ` Sergey Bugaev [this message]
2024-01-03 17:14 ` [RFC PATCH 23/23] hurd: Add expected aarch64-gnu abistlists Sergey Bugaev
2024-01-03 17:30 ` [RFC PATCH 00/23] aarch64-gnu port Joseph Myers
2024-01-03 17:57   ` Sergey Bugaev
2024-03-11 16:10   ` Florian Weimer
2024-03-11 13:47 ` H.J. Lu
2024-03-11 15:38   ` Sergey Bugaev
2024-03-11 14:14 ` 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=20240103171502.1358371-23-bugaevc@gmail.com \
    --to=bugaevc@gmail.com \
    --cc=bug-hurd@gnu.org \
    --cc=libc-alpha@sourceware.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).