From patchwork Sat Mar 23 17:33:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 87594 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA8B43858431 for ; Sat, 23 Mar 2024 17:40:19 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id D849D385840F for ; Sat, 23 Mar 2024 17:35:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D849D385840F 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 D849D385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711215335; cv=none; b=ML/5y5AN8+KsETHp7XiLa9nHgyFe2iSI+7xyjIBMC13ZiTdM9LaWI7+K8pjZLzMczGPzHpcwd57dwWsh40tourVUkmKAby8fHzAJP0mzLBzRdUf6Cwx8YFgnGiSGZ24bG6VDhaD3ZfHeixDO05kwT/f9gsJtY1O4EjphybFJnhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711215335; c=relaxed/simple; bh=+sRbaCQKl5qr6AendH3KgvMitTCtmh4psPTXgWU/wp4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=M22bGdqi5rSkSltjfrXc7ZQi46LBpnMSEOy8z5OTPNWhouc1t3We5urjx5A9XZ4ylE3fM0Y3iHNCMPhF5++bQsB5N9jiUUXkSfYXc60bkhTge237+sLurvhKD+DxcF+OWCRY8kbjGKIGulOnYLlj/VfX4+AJr/70lxLsO0mt+eQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-512f892500cso3618513e87.3 for ; Sat, 23 Mar 2024 10:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711215331; x=1711820131; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2Z8GlNQ299HIlPMx5so7e8/YKoBkfVEL/MiGHF2FPBA=; b=X6MuU0YcQvqZNIU/VN04Xx+i+ZHv4iJYdx0eoarWVz2Sh1IdmUQXCjvQwVe2eZNGx8 c790I7ANRzPSvYoyVemTKrU2IQXE0QhbTlNnMIglGm9A9NmlPv8JiyZyBzLAMOGAt2KA 9A+oE//+C9TYOV3vjlenD+aWYqvZR+w83HcVZYfVNxxwxmZ9Dy3TrXgp6h4Kgc0lq+aP SvE1lbsEENwkloFtuI92dpsyq69N2tXwqD+3J4uXI3atB4ZiliTSXOvBgN8v1XOUJGHb KzWz7Uyl5gb2cOgwMT/iCUo3+2UT66HgreXRAmWqocMMNYAqx6xZ0rHpWS5Qqaht8Ddq PBRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711215331; x=1711820131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2Z8GlNQ299HIlPMx5so7e8/YKoBkfVEL/MiGHF2FPBA=; b=oL9gI/ctQIOZxb1+Dp1f1ZpMg+1x7H1hvOJanripSmcTndjMQ4txbGJibAV5MoWhSI HnxmNxigRDZ5tqZPzybsNstfzW3Lh8v6NQ7BNCoIJ4vvv6voGPqX54CpBniVHVuTGQcn D2aR9PNNHAT7HghnStxTE3LQkLuhcK8dFhOYzwbQqj/emIJRCPcTw9nn1adxsjoXnfwh SF/km7DjnU9V1nXt3qNDfvjW8z826jrldaTdK9o/9klgWW1xfnUxqLE5Q92KhcMkNtDi DrOuFksEL/xYPDqmLptaZ6KBfkTZpX/CywxjWhXnDA8xmQ8q8s+diK4l0EM5JwsrbJv2 HTsA== X-Gm-Message-State: AOJu0YzwOxDTbtQ5xaywC+0lo0bO/Yb1tcrFiJrP4mj/18jQiKMCUibQ FlVLj7CtFjpuKIqpvgzp0zxNPsnukpnVNCzabYnO5BO8c+zEpDjZvIJnlhMa X-Google-Smtp-Source: AGHT+IH7St5OUkfKpq5VqyUN1+xpW/TD2zWB7ZVAJhHFpJNxmjfLsD+ril2gC5FLtT6jT8jtGwmUjg== X-Received: by 2002:a19:ca43:0:b0:513:cfaa:e618 with SMTP id h3-20020a19ca43000000b00513cfaae618mr2163325lfj.0.1711215331013; Sat, 23 Mar 2024 10:35:31 -0700 (PDT) Received: from surface-pro-6.. (79-139-171-253.dynamic.spd-mgts.ru. [79.139.171.253]) by smtp.gmail.com with ESMTPSA id g20-20020ac25394000000b00513973dee6fsm361290lfh.150.2024.03.23.10.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 10:35:30 -0700 (PDT) From: Sergey Bugaev To: libc-alpha@sourceware.org, bug-hurd@gnu.org Cc: Maxim Kuvyrkov , Luca Subject: [PATCH v2 19/20] htl: Add an AArch64 implementation Date: Sat, 23 Mar 2024 20:33:00 +0300 Message-ID: <20240323173301.151066-20-bugaevc@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240323173301.151066-1-bugaevc@gmail.com> References: <20240323173301.151066-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@sourceware.org Signed-off-by: Sergey Bugaev --- 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 +# . + +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..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 + . */ + +#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..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 + . */ + +#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) +{ + 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); +}