<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CorTst 测试项 &#96;m33_cst_loadstore_test6.S&#96; 失败]]></title><description><![CDATA[<h1>CorTst 测试项 <code>m33_cst_loadstore_test6.S</code> 失败</h1>
<h2>1. 问题描述</h2>
<p dir="auto">在进行 CorTst 测试时，在极端的高频中断场景下（例如每 50μs 触发一次周期性中断），测试用例出现概率性<strong>虚假失败 (False Failure)</strong>，跳转至 <code>m33_cst_loadstore_test6_stack_failed</code> 错误处理分支。</p>
<p dir="auto"><strong>问题代码片段：</strong></p>
<pre><code class="language-assembly">    /* Update signature on stack */
    LDREX     R1, [SP]        /* Switch to exclusive access */
    ROR       R1, R1, #1
    STREX     R0, R1, [SP]    /* STREX in exclusive access should succeed */
    CMP       R0, #0
    DSB
    BNE       m33_cst_loadstore_test6_stack_failed

    ROR       R1, R1, #3      /* Destroy signature in R1 */

</code></pre>
<hr />
<h2>2. 原因分析</h2>
<p dir="auto">此问题是由于 <strong>ARM 架构硬件行为特性</strong> 与 <strong>未屏蔽全局中断</strong> 共同作用导致的，<strong>并非实际硬件的 Load/Store 独占访问功能存在缺陷</strong>。</p>
<h3>2.1 硬件状态机机制</h3>
<p dir="auto">Cortex-M 的 Local Exclusive Monitor 状态切换逻辑如下：</p>
<pre><code class="language-text">[Open Access] --LDREX--&gt; [Exclusive Access] --STREX (Success)--&gt; [Open Access]
</code></pre>
<p dir="auto">根据 ARMv7-M / ARMv8-M 架构手册规定：</p>
<blockquote>
<p dir="auto"><strong>异常入口 (Exception Entry) 触发时，硬件会自动清零 Local Exclusive Monitor，强制将其从 <code>Exclusive Access</code> 状态重置为 <code>Open Access</code> 状态。</strong><br />
《Arm<img src="https://forum.ytmicro.com/assets/plugins/nodebb-plugin-emoji/emoji/android/00ae.png?v=1b4819a83c9" class="not-responsive emoji emoji-android emoji--registered" style="height:23px;width:auto;vertical-align:middle" title=":registered:" alt="®" /> v7-M Architecture Reference Manual》A3.4.5 Load-Exclusive and Store-Exclusive usage restrictions</p>
</blockquote>
<p dir="auto">此设计旨在防止中断服务程序 (ISR) 与线程上下文 (Thread Context) 之间的独占访问状态互相干扰。即使 ISR 内部没有任何 <code>LDREX</code>/<code>STREX</code> 相关的代码，<strong>仅仅“进入异常”这一动作就会破坏 Monitor 的状态</strong>。</p>
<h3>2.2 失败执行时序</h3>
<pre><code class="language-text">Thread Context                             Interrupt Context (ISR)
--------------                             -----------------------
LDREX  R1, [SP]
  │ (Monitor Status: Exclusive Access)
  │
  ├─────── 触发中断 (Exception Entry) ─────────┐
  │                                           │ (硬件自动清零 Monitor -&gt; Open Access)
  │                                           │ 执行 ISR...
  │                                           │ 异常返回 (Exception Return)
  │ &lt;─────────────────────────────────────────┘
  │
STREX  R0, R1, [SP] 
  │ (Monitor 当前处于 Open Access，STREX 必定失败)
  │ (返回状态码 R0 = 1)
  ▼
CMP    R0, #0
BNE    m33_cst_loadstore_test6_stack_failed  ==&gt; 触发误判 (False Positive)!

</code></pre>
<hr />
<h2>3. 修复方案</h2>
<p dir="auto">在行 115 的 <code>LDREX</code> 之前插入临界区保护（关中断/流水线准备宏 <code>CST_PREPARE_PIPELINE</code>），并在校验完成后恢复中断状态。</p>
<p dir="auto"><strong>修改前：</strong></p>
<pre><code class="language-assembly">    /* Update signature on stack */
    LDREX     R1, [SP]
    ROR       R1, R1, #1
    STREX     R0, R1, [SP]
    CMP       R0, #0
    DSB
    BNE       m33_cst_loadstore_test6_stack_failed

</code></pre>
<p dir="auto"><strong>修改后：</strong></p>
<pre><code class="language-assembly">    /* Update signature on stack */
    CST_PREPARE_PIPELINE       /* Disable interrupts to lock exclusive monitor state */
    LDREX     R1, [SP]
    ROR       R1, R1, #1
    STREX     R0, R1, [SP]
    CST_RESTORE_PIPELINE       /* Restore interrupt mask */

    CMP       R0, #0
    DSB
    BNE       m33_cst_loadstore_test6_stack_failed

</code></pre>
<h2>4. 临时修改方案</h2>
<ul>
<li>关闭对应的测试项目</li>
<li>替换 CorTst/asm/tests/m33_cst_loadstore_test6.S 为附件</li>
</ul>
]]></description><link>https://forum.ytmicro.com/topic/2131/cortst-测试项-m33_cst_loadstore_test6-s-失败</link><generator>RSS for Node</generator><lastBuildDate>Fri, 16 Oct 2026 07:21:11 GMT</lastBuildDate><atom:link href="https://forum.ytmicro.com/topic/2131.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 22 Jul 2026 06:11:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CorTst 测试项 &#96;m33_cst_loadstore_test6.S&#96; 失败 on Wed, 22 Jul 2026 06:12:54 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://yt-static-main.oss-cn-shanghai.aliyuncs.com/nodebb/9/208afd2f-fef4-4a77-b536-81dcd5341b53.txt" rel="nofollow ugc">m33_cst_loadstore_test6.S.txt</a></p>
]]></description><link>https://forum.ytmicro.com/post/9264</link><guid isPermaLink="true">https://forum.ytmicro.com/post/9264</guid><dc:creator><![CDATA[jiankang_wang]]></dc:creator><pubDate>Wed, 22 Jul 2026 06:12:54 GMT</pubDate></item></channel></rss>