From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id A740C1F451 for ; Wed, 3 Jan 2024 17:22:59 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=UJAHmKv7; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAAD8387541D for ; Wed, 3 Jan 2024 17:22:58 +0000 (GMT) Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by sourceware.org (Postfix) with ESMTPS id 766203858032 for ; Wed, 3 Jan 2024 17:15:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 766203858032 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 766203858032 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::134 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704302130; cv=none; b=x07ZZHt59fwoiYjK5NY4BOx2TWr4aW2T09Icz/FeCSi42b1joABJrDK3ca3B9U2vSDZVmqN3HcHDjSyhuAH+XCZEywJACGw2b/9/mqfYgbs122g+w7izRtSUx9dcLtExTE4EEOk1xaVuy4uB4ByIlGzLTisTMM+FX5AIc8xEjpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704302130; c=relaxed/simple; bh=fXL2ao7+VEe8zCcuQV+dg/MxKt5vYZzoRPQfCTZTvLw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ew9+G4rbFOXPodx6BpH/jiQTxK3IFpC5iVg6pTkdnI8T04k1J61ihjCCLNEsZmUe2OvkwaM5EZ2wTPq7eEPTdeqzyHM+rtwwffYctVYZDHfKbY0UxlaSSfgpjoujKsgcMH9v9jD7u9BkRx8zJsHI/3I25hja7XuQKSLCvfiLGrY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50ea98440a7so440856e87.1 for ; Wed, 03 Jan 2024 09:15:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704302125; x=1704906925; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=dXq+IahBwl8Syav52EU1+HIJWVGvtobc9aHb+4x+btA=; b=UJAHmKv73m0oQLDTYyMYedpInsVod5WzkSo7o4nk+nMCU4mDSRH/1gowX3YoZank/r yEgN+i+cuyi6aQ84YMJeVjGj30VJxWTtDJ7YugtZ3L40H/DauZRo7rxjYgqT49/gKuhI cZTHaRfbzQ45UYCCzgwTwoOrnF/nqd8qEd8LPH4SeDraWYPK60EcdT7+EmI+13BPJ+5c cYNMceWH4FrCvzRJ9NSF+rOQwRUWQ1binsE5iZWb2qzsdBtmEruxqyvFWFW7oYz0IWWi gxcTIVLSuo7u+i6v9GMr8L9GolIkKqt4Gj45rypVFc70DK1Hp4M6eW79IOT7u396bcud CM/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704302125; x=1704906925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dXq+IahBwl8Syav52EU1+HIJWVGvtobc9aHb+4x+btA=; b=r73wERCw12Q2ty8KdJ0XCz8codiVwLUZYztegE51OaLKwX50ka5l3jLiWAivKzR0Xv SThvxIXQjnHTyQNU2Yfkws4QtqQSB8wt7PhwZ4DpUGH3YCjXmHWtg7eUyrl+l0P7ZWdx Dw00il4CEh7Y9T1ot+ntXmuf/MOPRMhacw6qWWIzrCc+b1vk62HlQ/fuE4zJEC/R9bj6 Z+yleAbJzZn3xhROvjahJM04H4qrH3rMCg2buhx69MH4SS+zSQKl4CJVhRTJnTBnZ452 f9b2wPEnJED3reRNUDOVhlZopNjXWHrAVXxlv4VUNdZVhH5XQADQeRQ50WcX5wiYFL61 N/4w== X-Gm-Message-State: AOJu0Yx6W1CtvmkvD0TOVJ8yAHIrsUNoLedtf38zw+WGIu/Ayh0dhFnW JNF1yDsJqBmgKecKzsETkwIkY3m+NfA= X-Google-Smtp-Source: AGHT+IGTtIDmxQt5KI1qz1huZL5CaoRqeqc2jOXwaQpnBTV9XS5handKKMZjn2JmxRz0gNyAu9YmkA== X-Received: by 2002:a05:6512:3ab:b0:50e:70b4:79ce with SMTP id v11-20020a05651203ab00b0050e70b479cemr4270875lfp.185.1704302125305; Wed, 03 Jan 2024 09:15:25 -0800 (PST) Received: from surface-pro-6.. ([2a00:1370:818c:b32f:ebdc:fd0:376b:8006]) by smtp.gmail.com with ESMTPSA id y23-20020a196417000000b0050e6d84d177sm3546068lfb.279.2024.01.03.09.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 09:15:24 -0800 (PST) From: Sergey Bugaev 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 Message-ID: <20240103171502.1358371-23-bugaevc@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103171502.1358371-1-bugaevc@gmail.com> References: <20240103171502.1358371-1-bugaevc@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Signed-off-by: Sergey Bugaev --- 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 +# . + +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 + . */ + +#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 + . */ + +#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 + . */ + +#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 + . */ + +#include +#include + +#include +#include +#include +#include + +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 + . */ + +#include +#include +#include +#include + +#include +#include + +/* 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