bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 22/23] htl: Add an AArch64 implementation


From: Sergey Bugaev
Subject: [RFC PATCH 22/23] htl: Add an AArch64 implementation
Date: Wed, 3 Jan 2024 20:14:55 +0300

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]