From: "Fredrik Hederstierna" <fredrik.hederstierna@verisure.com>
To: gdb-patches@sourceware.org
Cc: Yao Qi <qiyaoltc@gmail.com>
Subject: Re: [PATCH] Fix exception unwinding for ARM Cortex-M
Date: Tue, 02 Aug 2016 09:43:00 -0000 [thread overview]
Message-ID: <OF1926033E.B8166B2F-ON00258003.003441A6-00258003.003556EF@notes.na.collabserv.com> (raw)
In-Reply-To: <868twkekf1.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1000 bytes --]
-----Yao Qi <qiyaoltc@gmail.com> wrote: -----
>Fredrik,
>A general comment to this patch is that you need to split it. Each
>patch only addresses one issue or adds one support.
Ok, I send you first patch, this one fix EXC_RETURN values.
>We need to consider ARMv6-M as well,
>> + switch (pc)
>> + {
>> + /* From Table B1-8 and B1-9 the EXC_RETURN definition of
>> + the exception return behavior. */
>> +
>> + /* Return to Handler mode. Return stack Main. Frame type
>Extended. */
>
>I don't see anything useful the comment has. We can remove it.
>Instead, we need to document, on ARMv6-M and ARMv7-M without FP
>extension, the exc_return is 0xfffffff{1,9,d}. On ARMv7-M with FP
>extension, exc_return can be 0xffffff{e,f}{1,9,d}.
Ok, I documented also ARMv6-M in new patch.
>Please post the patch only for magic pc handling, then I can review
>and approve it.
Ok, done. Attached first patch.
I will submit next when it is ready.
Thanks & Kind Regards,
Fredrik
[-- Attachment #2: gdb-cortex-m-exc-return-values.patch --]
[-- Type: application/octet-stream, Size: 3697 bytes --]
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7820302..2c8573c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2016-08-02 Fredrik Hederstierna <fredrik.hederstierna@verisure.com>
+
+ * arm-tdep.c: Fix EXC_RETURN values for ARMv6-M and ARMv7-M.
+
2016-08-01 Joel Brobecker <brobecker@adacore.com>
* NEWS: Create a new section for the next release branch.
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index d2661cb..43436df 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -469,9 +469,11 @@ static CORE_ADDR
arm_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
{
/* On M-profile devices, do not strip the low bit from EXC_RETURN
- (the magic exception return address). */
+ (the magic exception return address).
+ According to B1.5.8 of both the ARMv6-M and ARMv7-M Reference Manuals
+ the EXC_RETURN value is 0xF in Bits[31:28]. */
if (gdbarch_tdep (gdbarch)->is_m
- && (val & 0xfffffff0) == 0xfffffff0)
+ && (val & 0xf0000000) == 0xf0000000)
return val;
if (arm_apcs_32)
@@ -2977,6 +2979,61 @@ arm_m_exception_prev_register (struct frame_info *this_frame,
prev_regnum);
}
+/* Determine if the program counter specified equals any of
+ these magic return values, called EXC_RETURN, defined by the
+ ARM v6-M and v7-M architectures.
+
+ From ARMv6-M Reference Manual B1.5.8
+ Table B1-5 Exception return behavior
+
+ EXC_RETURN Return To Return Stack
+ 0xFFFFFFF1 Handler mode Main
+ 0xFFFFFFF9 Thread mode Main
+ 0xFFFFFFFD Thread mode Process
+
+ From ARMv7-M Reference Manual B1.5.8
+ Table B1-8 EXC_RETURN definition of exception return behavior, no FP
+
+ EXC_RETURN Return To Return Stack
+ 0xFFFFFFF1 Handler mode Main
+ 0xFFFFFFF9 Thread mode Main
+ 0xFFFFFFFD Thread mode Process
+
+ Table B1-9 EXC_RETURN definition of exception return behavior, with FP
+
+ EXC_RETURN Return To Return Stack Frame Type
+ 0xFFFFFFE1 Handler mode Main Extended
+ 0xFFFFFFE9 Thread mode Main Extended
+ 0xFFFFFFED Thread mode Process Extended
+ 0xFFFFFFF1 Handler mode Main Basic
+ 0xFFFFFFF9 Thread mode Main Basic
+ 0xFFFFFFFD Thread mode Process Basic
+
+ For more details see "B1.5.8 Exception return behavior"
+ in both ARMv6-M and ARMv7-M Architecture Reference Manuals. */
+
+static int
+arm_m_pc_is_magic (CORE_ADDR pc)
+{
+ switch (pc)
+ {
+ /* Values from Tables in B1.5.8 the EXC_RETURN definitions of
+ the exception return behavior. */
+ case 0xffffffe1:
+ case 0xffffffe9:
+ case 0xffffffed:
+ case 0xfffffff1:
+ case 0xfffffff9:
+ case 0xfffffffd:
+ /* PC is magic. */
+ return 1;
+
+ default:
+ /* PC is not magic. */
+ return 0;
+ }
+}
+
/* Implementation of function hook 'sniffer' in
'struct frame_uwnind'. */
@@ -2990,14 +3047,8 @@ arm_m_exception_unwind_sniffer (const struct frame_unwind *self,
/* No need to check is_m; this sniffer is only registered for
M-profile architectures. */
- /* Exception frames return to one of these magic PCs. Other values
- are not defined as of v7-M. See details in "B1.5.8 Exception
- return behavior" in "ARMv7-M Architecture Reference Manual". */
- if (this_pc == 0xfffffff1 || this_pc == 0xfffffff9
- || this_pc == 0xfffffffd)
- return 1;
-
- return 0;
+ /* Check if exception frame returns to a magic PC value. */
+ return arm_m_pc_is_magic (this_pc);
}
/* Frame unwinder for M-profile exceptions. */
next prev parent reply other threads:[~2016-08-02 9:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <OF625831A6.9C918507-ON00257FFE.0029D369-00257FFE.002D2551@notes.na.collabserv.com>
2016-07-29 11:47 ` Yao Qi
2016-08-02 9:43 ` Fredrik Hederstierna [this message]
2016-08-02 16:01 ` Yao Qi
2016-08-03 10:56 ` Fredrik Hederstierna
2016-08-03 11:19 ` Yao Qi
2016-08-03 17:33 ` James-Adam Renquinha Henri
2016-08-04 7:04 ` Fredrik Hederstierna
2016-08-05 19:02 ` Adam Renquinha
2016-08-09 9:17 ` Yao Qi
2016-09-23 17:32 ` Adam Renquinha
2016-09-26 3:03 ` Yao Qi
2016-09-27 1:38 ` Adam Renquinha
2016-09-27 4:40 ` Yao Qi
[not found] <AM4PR1001MB0948AC4D9CB635F5A9A2FC82EFDC0@AM4PR1001MB0948.EURPRD10.PROD.OUTLOOK.COM>
[not found] ` <HE1PR1001MB130613C0995C4C21A630373BEF1B0@HE1PR1001MB1306.EURPRD10.PROD.OUTLOOK.COM>
2019-06-10 21:25 ` James-Adam Renquinha Henri
2019-06-12 9:01 ` Alan Hayward
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=OF1926033E.B8166B2F-ON00258003.003441A6-00258003.003556EF@notes.na.collabserv.com \
--to=fredrik.hederstierna@verisure.com \
--cc=gdb-patches@sourceware.org \
--cc=qiyaoltc@gmail.com \
/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