From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id rWkbBxzw/2g3dAwAWB0awg (envelope-from ) for ; Mon, 27 Oct 2025 18:20:12 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=er+phdqj; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 0D1D61E0BC; Mon, 27 Oct 2025 18:20:12 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2D36E1E057 for ; Mon, 27 Oct 2025 18:20:10 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A97403858C2D for ; Mon, 27 Oct 2025 22:20:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A97403858C2D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=er+phdqj Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 7B57C3858D20 for ; Mon, 27 Oct 2025 22:19:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7B57C3858D20 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 7B57C3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761603566; cv=none; b=c2Ymnz5tbXz2rLgTF1ELq+xjw3NbtxT4mHg15C+3qXuRITzAb0WPSToCa1hOsWEq7ViDh9I4+9c7Is1qmnPc3szCeIzomxqoJ6XYKe9uZju0EqH0zRsG8Hc0M671JeaeVJPv5moNC0oTdu7IuDbb8DNZnJEDY/lVZP0I2NjmL2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761603566; c=relaxed/simple; bh=8X+oDVwIZcAqE+2KKUtKk71q0HMAyjUkc0YoIQ/EmxY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Dqa0N6cDj+Hk+Z4dUKIQcQdRWRhQE5nSxmMkjs/MaLcfI3vZlNjNDbw2lDxi7o4f9xh9ATnsmkXWeer2XhP+RRKlZOAWvc7f5HND7q2oh7mZ+WA3pa6EXGQ5zxIKSMukJWWNg9SOGerc8hDWfWQEnEshZSlxIR+piLYO2oU/fiY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B57C3858D20 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-475c9881821so32465485e9.0 for ; Mon, 27 Oct 2025 15:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761603565; x=1762208365; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=nyGt/IsC3lenHDw/2UmK6D7sL5iyrRxkivF4D32FCmk=; b=er+phdqjo6pxlItthGIOnMl9flmqTjN0aeQQJy+AS18gGGzAtG/WNmuRpu2mHd+uav +rOeGukJ+KDQ/m9DWmQRn7K7hm4oxHTdDHwB/RCsG8Ml7wEn0CJBtPTeZIHhLRB10X1u p4WiG/iB/tfPg/bWDFHWs9exLBHKo235iDXhxTl9E+MVWN7ooVgFrZ+XnwEPy1na0OCx kdCjJf8hqbm6gEyVQgJ9NBwr+q3bQ/SRJipaODERNd8zhpQ9/gqEEN9hEIjHfHr+GR1S 9pO6qNSaGMZl48lRK7jLK2a5xeA3OjTCeE1xK5aABDyuKcOyrq9tc3fUOpCX0dJbyYz0 6Q+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761603565; x=1762208365; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nyGt/IsC3lenHDw/2UmK6D7sL5iyrRxkivF4D32FCmk=; b=j2cLnqIWx/R47ifdrJGq7mIftn22eIgtuiKhqZdme2f4OA8QB3g8cOzf19EjjqyMd1 QQDBQnjdBLSSJJ7nyyEyOt5b298EE2BmA+5nEtSsNnpMdJxfuZtEb2WA19X8BN3fb49q noBJYkw3DpOTI/joNEkq4FEBNwSEY4PEU1OVSj04w2AbkKots7anQxvbHf8BqtRgIlRS GWfogFUWGgkV97NI4y/q5stQDZzEOFI1FW9S1qM6Bjt4oYnjL/KG7rYbJDyS3b5XcNib G2e/UjA/ucW1SDDuWNL9ogHyTV23+pft0fsQiTVbfhCE7vKKytmcLiVCsnnzpXOOH58m zPow== X-Forwarded-Encrypted: i=1; AJvYcCUUCCqw1Z2MuAttphnjHGhOkCHU7g37zadLovWIriauidipLZOuYXeImhYwMgRB6AIexqTn9Y5x9tEGDw==@sourceware.org X-Gm-Message-State: AOJu0Yze10um6R0o7NKk/o4c/x3MLckh5JTUPL7+2dBRh6BjkDZXCkDu VKfwBAEwjSuk9+ZLnOL/390CAzNr/n/vxFzKa1sRL7oyehDsDw7nBOhgkLGYqw== X-Gm-Gg: ASbGncvvfFhD+kBxq9zkI0jgAJlthNR2UnpwD1JZMl7rpfvZ6V7dSqdjc+f/4f4n9Cf 7hKkUqzTMCTMmd9egwDMrEnxRh62W2DAmMBXGcHse9Y7dxa+I1bB0TyW3pTQb5YURvWTjuRq4Ot 0Cvu8bl06vJ01vMjvP+coAs160bsZBqSalbovZa0xPA/94q8zpHsYEx297b95HL3weBJHm19nBk snBPqXFMfuq7Z302sCa6Qm7EH4dqVwIWfuq49lTgUaFHKXxrEolPvb32dmtI0xC+rZRZ91l/MMq psxYwwFhJU7PhnvXFPDV+0yVnJJd86PMbbPVd3Wn8e1ipsUmjhiy18/sGEtx3ae9jZXyYqIu6xk /rrFn82C800doXMayC0xjcaryG0mTBG+HfPyirIzUvStF86xiJh6CYrrn947vqaZdkkuqHAkZge GeDKHvZuTw6M7S X-Google-Smtp-Source: AGHT+IGdU2s4lpjbKyGpkLSqdMLEM0X+eW9upmNlEswqKda1YnbcpF/CNV+cdSlW4xfUnKFzbE545w== X-Received: by 2002:a05:600c:871b:b0:45f:29eb:2148 with SMTP id 5b1f17b1804b1-47718d7bfa0mr4342605e9.7.1761603564797; Mon, 27 Oct 2025 15:19:24 -0700 (PDT) Received: from [192.168.0.38] ([86.12.216.189]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-475dd02cbc6sm161773715e9.1.2025.10.27.15.19.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Oct 2025 15:19:23 -0700 (PDT) Message-ID: Date: Mon, 27 Oct 2025 22:19:22 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 5/6] gdb/aarch64: Tests for FPMR Content-Language: en-US To: Ezra.Sitorus@arm.com, gdb-patches@sourceware.org Cc: thiago.bauermann@linaro.org References: <20251021150300.59860-1-Ezra.Sitorus@arm.com> <20251021150300.59860-6-Ezra.Sitorus@arm.com> From: Luis In-Reply-To: <20251021150300.59860-6-Ezra.Sitorus@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org On 21/10/2025 16:02, Ezra.Sitorus@arm.com wrote: > From: Ezra Sitorus > > Add tests for FPMR support in gdb/gdbserver. These tests check > availability of FPMR, reading/writing to FPMR, core file generation and > preservation under sighandler frame unwinding. > > A run of the full gdb testsuite has been done on aarch64-none-linux-gnu > without FPMR support. I have run the gdb.arch tests on Shrinkwrap with > FPMR support. > > --- > Changes from v1->v2: > * Removed fpmr modification functions to make the tests easier to > follow. > * Test writing to fpmr in aarch64-fpmr.exp from outside the inferior > program. > * Rewrite allow_aarch64_fpmr_tests to follow allow_aarch64_sve_tests. > > Changes from v2->v3: > * tclint: only messages now is for line length for aarch64-fpmr.exp. I > think this is ok as it makes the test string readable. > * Addressed comments/whitespace/formatting issues. > * gdb.exp:allow_aarch64_fpmr_tests reads FPMR in both cases. > > Ezra > > gdb/testsuite/gdb.arch/aarch64-fpmr-core.c | 40 ++++++ > gdb/testsuite/gdb.arch/aarch64-fpmr-core.exp | 97 ++++++++++++++ > .../gdb.arch/aarch64-fpmr-sighandler.c | 55 ++++++++ > .../gdb.arch/aarch64-fpmr-sighandler.exp | 74 +++++++++++ > gdb/testsuite/gdb.arch/aarch64-fpmr.c | 118 ++++++++++++++++++ > gdb/testsuite/gdb.arch/aarch64-fpmr.exp | 99 +++++++++++++++ > gdb/testsuite/lib/gdb.exp | 66 ++++++++++ > 7 files changed, 549 insertions(+) > create mode 100644 gdb/testsuite/gdb.arch/aarch64-fpmr-core.c > create mode 100644 gdb/testsuite/gdb.arch/aarch64-fpmr-core.exp > create mode 100644 gdb/testsuite/gdb.arch/aarch64-fpmr-sighandler.c > create mode 100644 gdb/testsuite/gdb.arch/aarch64-fpmr-sighandler.exp > create mode 100644 gdb/testsuite/gdb.arch/aarch64-fpmr.c > create mode 100644 gdb/testsuite/gdb.arch/aarch64-fpmr.exp > > diff --git a/gdb/testsuite/gdb.arch/aarch64-fpmr-core.c b/gdb/testsuite/gdb.arch/aarch64-fpmr-core.c > new file mode 100644 > index 00000000000..785fbd42d5c > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/aarch64-fpmr-core.c > @@ -0,0 +1,40 @@ > +/* This file is part of GDB, the GNU debugger. > + > + Copyright 2008-2025 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program 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 General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#include > + > +uint64_t crash_address = 0; > + > +void > +set_fpmr (uint64_t value) > +{ > + register uint64_t x0_val asm ("x0") = value; > + /* msr fpmr, x0 */ > + __asm__ volatile (".inst 0xd51b4440" : : ); > +} > + > +int > +main (void) > +{ > + set_fpmr (0x3fff7fc049); > + > + /* Check FPMR */ > + > + *((uint64_t *) crash_address) = 0xDEAD; /* crash point */ > + > + return 1; > +} > diff --git a/gdb/testsuite/gdb.arch/aarch64-fpmr-core.exp b/gdb/testsuite/gdb.arch/aarch64-fpmr-core.exp > new file mode 100644 > index 00000000000..c26b0b2bba7 > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/aarch64-fpmr-core.exp > @@ -0,0 +1,97 @@ > +# Copyright (C) 2018-2025 Free Software Foundation, Inc. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program 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 General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# This file is part of the gdb testsuite. > + > +# Test generating and reading a core file with FPMR. > + > +proc check_fpmr_core_file {core_filename} { > + # Load the core file. > + if { > + [gdb_test "core $core_filename" \ > + [multi_line \ > + "Core was generated by .*" \ > + "Program terminated with signal SIGSEGV, Segmentation fault\\." \ > + "#0 ${::hex} in main \\(.*\\) at .*" \ > + ".* \\*\\(\\(uint64_t \\*\\) crash_address\\) = 0xDEAD.*"] \ > + "load core file"] > + } { > + untested "failed to generate core file" > + return -1 > + } > + > + # Check the value of FPMR in the core file. > + gdb_test "print/x \$fpmr" " = 0x3fff7fc049" \ > + "fpmr contents from core file" Formatting: Indentation of the above line should be a couple more spaces ahead. > +} > + > +require is_aarch64_target > +require allow_aarch64_fpmr_tests > + > +standard_testfile > +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { > + return -1 > +} > + > +set binfile [standard_output_file ${testfile}] > + > +if {![runto_main]} { > + return -1 > +} > + > +set crash_breakpoint "crash point" > +gdb_breakpoint [gdb_get_line_number $crash_breakpoint] > +gdb_continue_to_breakpoint $crash_breakpoint > + > +gdb_test "print/x \$fpmr" " = 0x3fff7fc049" "fpmr contents from core file" > + > +gdb_test "continue" \ > + [multi_line \ > + "Program received signal SIGSEGV, Segmentation fault\\." \ > + "${::hex} in main \\(\\).* at .*" \ > + ".* \\*\\(\\(uint64_t \\*\\) crash_address\\) = 0xDEAD.*"] \ > + "run to crash" Formatting: Indentation looks off above. Could you please check? > + > +# Generate the gcore core file. > +set gcore_filename [standard_output_file "${testfile}.gcore"] > +set gcore_generated [gdb_gcore_cmd "$gcore_filename" "generate gcore file"] > + > +# Generate a native core file. > +set core_filename [core_find ${binfile}] > +set core_generated [expr {$core_filename != ""}] > + > +# At this point we have a couple core files, the gcore one generated by GDB > +# and the native one generated by the Linux Kernel. Make sure GDB can read > +# both correctly. > + > +if {$gcore_generated} { > + clean_restart > + gdb_load ${binfile} > + with_test_prefix "gcore corefile" { > + check_fpmr_core_file $gcore_filename > + } > +} else { > + fail "gcore corefile not generated" > +} > + > +if {$core_generated} { > + clean_restart > + gdb_load ${binfile} > + with_test_prefix "native corefile" { > + check_fpmr_core_file $core_filename > + } > +} else { > + untested "native corefile not generated" > +} > diff --git a/gdb/testsuite/gdb.arch/aarch64-fpmr-sighandler.c b/gdb/testsuite/gdb.arch/aarch64-fpmr-sighandler.c > new file mode 100644 > index 00000000000..e8056d40b4c > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/aarch64-fpmr-sighandler.c > @@ -0,0 +1,55 @@ > +/* This file is part of GDB, the GNU debugger. > + > + Copyright 2008-2025 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program 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 General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#include > +#include > +#include > +#include > + > +void > +set_fpmr (uint64_t value) > +{ > + register uint64_t x0_val asm ("x0") = value; > + /* msr fpmr, x0 */ > + __asm__ volatile (".inst 0xd51b4440" : : ); > +} > + > +void > +handler (int sig) > +{ > + set_fpmr (0xff008041); > + exit(0); > +} > + > +int > +main () > +{ > + /* Ensure no signals are blocked. */ > + sigset_t newset; > + sigemptyset (&newset); > + sigprocmask (SIG_SETMASK, &newset, NULL); > + > + signal (SIGILL, handler); > + > + set_fpmr (0x3fff7fc049); > + > + /* 0x06000000 : Causes an illegal instruction. Value undefined as per ARM > + Architecture Reference Manual ARMv8, Section C4.1. */ > + __asm __volatile (".inst 0x06000000"); > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.arch/aarch64-fpmr-sighandler.exp b/gdb/testsuite/gdb.arch/aarch64-fpmr-sighandler.exp > new file mode 100644 > index 00000000000..89b5a5cc010 > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/aarch64-fpmr-sighandler.exp > @@ -0,0 +1,74 @@ > +# Copyright 2018-2025 Free Software Foundation, Inc. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program 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 General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > +# > +# This file is part of the gdb testsuite. > +# > +# Test FPMR register set is properly preserved when unwiding sighandler frames. Typo: unwiding -> unwinding. > + > +require is_aarch64_target > +require allow_aarch64_fpmr_tests > + > +standard_testfile > +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { > + return -1 > +} > + > +if {![runto_main]} { > + return -1 > +} > + > +set reg_main_value "0x3fff7fc049" > +set reg_handler_value "0xff008041" > + > +proc check_fpmr {value} { > + gdb_test "print /x \$fpmr" ".* = {?$value}?" \ > + "check register \$fpmr has value $value" > +} > + > +# Run until end of signal handler > + > +gdb_test "continue" "Continuing.*Program received signal SIGILL.*" \ > + "continue until signal" > + > +gdb_breakpoint [gdb_get_line_number "exit(0)"] > +gdb_continue_to_breakpoint "exit" ".*exit.*" > + > +set handlerframe [get_current_frame_number] > +set mainframe [expr {$handlerframe + 2}] > + > +# Check register values > + > +with_test_prefix "handler frame 1st" { > + check_fpmr $reg_handler_value > +} > + > +# Switch to the frame for main(), and check register values Formatting: Space before parens. Also, it would be worth checking this for consistency. Some comments end in period but others don“t, like this one. As you fix some of these nits, it is worth checking those as well. > + > +gdb_test "frame $mainframe" "#$mainframe.*main ().*" \ > + "set to main frame" > + > +with_test_prefix "main frame" { > + check_fpmr $reg_main_value > +} > + > +# Switch back to the signal handler frame, and check register values > + > +gdb_test "frame $handlerframe" \ > + "#$handlerframe.*handler \\\(sig=4\\\).*" \ > + "set to signal handler frame" > + > +with_test_prefix "handler frame 2nd" { > + check_fpmr $reg_handler_value > +} > diff --git a/gdb/testsuite/gdb.arch/aarch64-fpmr.c b/gdb/testsuite/gdb.arch/aarch64-fpmr.c > new file mode 100644 > index 00000000000..d29205fb63d > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/aarch64-fpmr.c > @@ -0,0 +1,118 @@ > +/* This file is part of GDB, the GNU debugger. > + > + Copyright 2008-2025 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program 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 General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#include > + > +enum FPM_FORMAT > +{ > + E5M2, > + E4M3, > +}; > + > +enum FPM_OVERFLOW > +{ > + INFNAN, > + SATURATE, > +}; > + > +void > +set_fpmr (uint64_t value) > +{ > + register uint64_t x0_val asm ("x0") = value; > + __asm__ volatile (".inst 0xd51b4440" : : ); > + /* msr fpmr, x0 */ > +} > + > +uint64_t > +modify_src1_fmt (uint64_t fpmr, uint64_t fmt) > +{ > + return (fpmr & ~(0x7)) | (fmt & 0x7); > +} > + > +uint64_t > +modify_src2_fmt (uint64_t fpmr, uint64_t fmt) > +{ > + return (fpmr & ~((0x7) << 3)) | ((fmt & 0x7) << 3); > +} > + > +uint64_t > +modify_dst_fmt (uint64_t fpmr, uint64_t fmt) > +{ > + return (fpmr & ~((0x7) << 6)) | ((fmt & 0x7) << 6); > +} > + > +uint64_t > +modify_osm (uint64_t fpmr, uint64_t overflow) > +{ > + return (fpmr & ~((0x1) << 14)) | ((overflow & 0x1) << 14); > +} > + > +uint64_t > +modify_osc (uint64_t fpmr, uint64_t overflow) > +{ > + return (fpmr & ~((0x1) << 15)) | ((overflow & 0x1) << 15); > +} > + > +uint64_t > +modify_lscale (uint64_t fpmr, uint64_t scale) > +{ > + return (fpmr & ~((0x7f) << 16)) | ((scale & 0x7f) << 16); > +} > + > +uint64_t > +modify_nscale (uint64_t fpmr, uint64_t scale) > +{ > + return (fpmr & ~((0xff) << 24)) | ((scale & 0xff) << 24); > +} > + > +uint64_t > +modify_lscale2 (uint64_t fpmr, uint64_t scale) > +{ > + return (fpmr & ~((uint64_t)(0x3f) << 32)) | ((uint64_t)(scale & 0x3f) << 32); > +} > + > +int > +main (void) > +{ > + uint64_t fpmr = 0; > + > + fpmr = modify_src1_fmt (fpmr, E4M3); > + set_fpmr (fpmr); /* MODIFY SRC1 */ > + > + fpmr = modify_src2_fmt (fpmr, E4M3); > + set_fpmr (fpmr); /* MODIFY SRC2 */ > + > + fpmr = modify_dst_fmt (fpmr, E4M3); > + set_fpmr (fpmr); /* MODIFY DST */ > + > + fpmr = modify_osm (fpmr, SATURATE); > + set_fpmr (fpmr); /* MODIFY OSM */ > + > + fpmr = modify_osc (fpmr, SATURATE); > + set_fpmr (fpmr); /* MODIFY OSC */ > + > + fpmr = modify_lscale (fpmr, -1); > + set_fpmr (fpmr); /* MODIFY LSCALE */ > + > + fpmr = modify_nscale (fpmr, -1); > + set_fpmr (fpmr); /* MODIFY NSCALE */ > + > + fpmr = modify_lscale2 (fpmr, -1); > + set_fpmr (fpmr); /* MODIFY LSCALE2 */ > + > + return 1; > +} > diff --git a/gdb/testsuite/gdb.arch/aarch64-fpmr.exp b/gdb/testsuite/gdb.arch/aarch64-fpmr.exp > new file mode 100644 > index 00000000000..142d8172332 > --- /dev/null > +++ b/gdb/testsuite/gdb.arch/aarch64-fpmr.exp > @@ -0,0 +1,99 @@ > +# Copyright 2023-2025 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program 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 General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . */ > + > +# Exercise reading/writing FPMR when it is present. > + > +require is_aarch64_target > +require allow_aarch64_fpmr_tests > + > +standard_testfile > +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { > + return -1 > +} > + > +if {![runto_main]} { > + return -1 > +} > + > +gdb_test_multiple "info register \$fpmr" "Test FPMR SRC1 E5M2" { > + -re ".*\r\n.*\[ \ > + F8S1=E5M2 \ > + F8S2=E5M2 \ > + F8D=E5M2 \ > + OSM=Inf \ > + OSC=Inf/NaN \ > + LSCALE=0 \ > + NSCALE=0 \ > + LSCALE2=0 \]" { > + pass "FPMR SRC1 matches E5M2" > + } > +} > + > +set breakpoints \ > + [list \ > + "SRC1" \ > + "SRC2" \ > + "DST" \ > + "OSM" \ > + "OSC" \ > + "LSCALE" \ > + "NSCALE" \ > + "LSCALE2"] > + > +set reg_values \ > + [list \ > + ".*\r\n.*\[ F8S1=E4M3 F8S2=E5M2 F8D=E5M2 OSM=Inf OSC=Inf/NaN LSCALE=0 NSCALE=0 LSCALE2=0 \]" \ > + ".*\r\n.*\[ F8S1=E4M3 F8S2=E4M3 F8D=E5M2 OSM=Inf OSC=Inf/NaN LSCALE=0 NSCALE=0 LSCALE2=0 \]" \ > + ".*\r\n.*\[ F8S1=E4M3 F8S2=E4M3 F8D=E4M3 OSM=Inf OSC=Inf/NaN LSCALE=0 NSCALE=0 LSCALE2=0 \]" \ > + ".*\r\n.*\[ F8S1=E4M3 F8S2=E4M3 F8D=E4M3 OSM=MaxNormal OSC=Inf/NaN LSCALE=0 NSCALE=0 LSCALE2=0 \]" \ > + ".*\r\n.*\[ F8S1=E4M3 F8S2=E4M3 F8D=E4M3 OSM=MaxNormal OSC=MaxNormal LSCALE=0 NSCALE=0 LSCALE2=0 \]" \ > + ".*\r\n.*\[ F8S1=E4M3 F8S2=E4M3 F8D=E4M3 OSM=MaxNormal OSC=MaxNormal LSCALE=127 NSCALE=0 LSCALE2=0 \]" \ > + ".*\r\n.*\[ F8S1=E4M3 F8S2=E4M3 F8D=E4M3 OSM=MaxNormal OSC=MaxNormal LSCALE=127 NSCALE=255 LSCALE2=0 \]" \ > + ".*\r\n.*\[ F8S1=E4M3 F8S2=E4M3 F8D=E4M3 OSM=MaxNormal OSC=MaxNormal LSCALE=127 NSCALE=255 LSCALE2=63 \]"] > + > +set pass_messages \ > + [list \ > + "FPMR SRC1 matches E4M3" \ > + "FPMR SRC2 matches E4M3" \ > + "FPMR DST matches E4M3" \ > + "FPMR OSM matches MaxNormal" \ > + "FPMR OSC matches MaxNormal" \ > + "FPMR LSCALE matches" \ > + "FPMR NSCALE matches" \ > + "FPMR LSCALE2 matches"] > + > +for {set i 0} {$i < 8} {incr i} { > + set bp [lindex $breakpoints $i] > + gdb_breakpoint [gdb_get_line_number $bp] > + gdb_continue_to_breakpoint $bp > + > + gdb_test_multiple "info register \$fpmr" "" { > + -re [lindex $reg_values $i] { > + pass [lindex $pass_messages $i] > + } > + } > +} > + > +gdb_test_multiple "set \$fpmr=0x0" "" { > + -re ".*\r\n.*\[ F8S1=E5M2 F8S2=E5M2 F8D=E5M2 OSM=Inf OSC=Inf/NaN LSCALE=0 NSCALE=0 LSCALE2=0 \]" { > + pass "Reset FPMR to 0 from GDB" > + } > +} > + > +gdb_test_multiple "set \$fpmr=0x3f007f4008" "" { > + -re ".*\r\n.*\[ F8S1=E5M2 F8S2=E4M3 F8D=E5M2 OSM=MaxNormal OSC=Inf/NaN LSCALE=127 NSCALE=0 LSCALE2=63 \]" { > + pass "Write to FPMR from GDB" > + } > +} > diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp > index 930462f63fa..cdb6ccdfa35 100644 > --- a/gdb/testsuite/lib/gdb.exp > +++ b/gdb/testsuite/lib/gdb.exp > @@ -5201,6 +5201,72 @@ proc aarch64_supports_sme_svl { length } { > return 1 > } > > +# Run a test on the target to see if it supports the AArch64 FPMR feature. > +# Return 1 if so, 0 if it does not. Note this causes a restart of GDB. > + > +gdb_caching_proc allow_aarch64_fpmr_tests {} { > + global srcdir subdir gdb_prompt inferior_exited_re > + > + set me "allow_aarch64_fpmr_tests" > + > + if { ![is_aarch64_target]} { > + return 0 > + } > + > + set compile_flags "{additional_flags=-march=armv8-a}" > + > + # Compile a test program reading FPMR. > + set src { > + int main() { > + asm volatile ("mrs x0, fpmr"); > + return 0; > + } > + } > + if {![gdb_simple_compile $me $src executable $compile_flags]} { > + # Try again, but with a raw hex instruction so we don't rely on > + # assembler support for FPMR. > + > + set compile_flags "{additional_flags=-march=armv8-a}" > + > + # Compile a test program reading FPMR. > + set src { > + int main() { > + asm volatile (".word 0xD53B4440"); > + return 0; > + } > + } > + > + if {![gdb_simple_compile $me $src executable $compile_flags]} { > + return 0 > + } > + } > + > + # Compilation succeeded so now run it via gdb. > + clean_restart > + gdb_load $obj > + gdb_run_cmd > + > + gdb_expect { > + -re ".*Illegal instruction.*${gdb_prompt} $" { > + verbose -log "\n$me fpmr support not detected" > + set allow_fpmr_tests 0 > + } > + -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { > + verbose -log "\n$me: fpmr support detected" > + set allow_fpmr_tests 1 > + } > + default { > + warning "\n$me: default case taken" > + set allow_fpmr_tests 0 > + } > + } > + gdb_exit > + remote_file build delete $obj > + > + verbose "$me: returning $allow_fpmr_tests" 2 > + return $allow_fpmr_tests > +} > + > # Run a test on the target to see if it supports AArch64 MOPS (Memory > # Operations) extensions. Return 1 if so, 0 if it does not. Note this > # causes a restart of GDB.