<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style='--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;'>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>
GitLab
</title>

<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>

<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style='font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";'>
<div class="content">

<p style="color: #777777;">
<a href="https://gitlab.rtems.org/matteo.concas">Matteo Concas</a>
commented on a
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5383#note_135544">discussion</a>:
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<blockquote dir="auto" style="font-size: inherit; color: #626168; padding-top: 0.5rem; padding-bottom: 0.5rem; padding-left: 1rem; border-left-style: solid; margin: 0 0 0.5rem; border-color: #bfbfc3; border-width: 0 0 0 4px;" align="initial">
<p style="color: inherit; line-height: 1.5; margin: 0;">After looking at grmon4 a bit, it occurs to me that grmon does not support emulation</p>
</blockquote>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Indeed GRMON is only used to connect to hardware, we also have TSIM for simulation but we don't provide a trial version of the NOEL-V one.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">From more testing, I have noticed that this misaligned load is executed twice. The first time during system initialization when the DTB is parsed to find the end of the memory area in <code style='font-size: 90%; color: #18171d; word-wrap: break-word; border-radius: .25rem; background-color: #ececef; margin-top: 0; font-weight: inherit; white-space: break-spaces; overflow-wrap: break-word; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;'>bsp_memory_initialize()</code>. The CPU then goes to the exception handler as expected and <code style='font-size: 90%; color: #18171d; word-wrap: break-word; border-radius: .25rem; background-color: #ececef; font-weight: inherit; white-space: break-spaces; overflow-wrap: break-word; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;'>_Terminate()</code> is called. But, on system termination information is printed out to the console, to do that <code style='font-size: 90%; color: #18171d; word-wrap: break-word; border-radius: .25rem; background-color: #ececef; font-weight: inherit; white-space: break-spaces; overflow-wrap: break-word; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;'>printk()</code> which in turn will call <code style='font-size: 90%; color: #18171d; word-wrap: break-word; border-radius: .25rem; background-color: #ececef; font-weight: inherit; white-space: break-spaces; overflow-wrap: break-word; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;'>riscv_output_char_init()</code> and this function probe the FDT to find the console. During this parsing the same error is encountered but this time the exception handler is never entered.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">I suspect that is because of the <a href="https://docs.riscv.org/reference/isa/priv/smdbltrp.html" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0;">double trap extension (Smdbltrp)</a> when combined with the <a href="https://docs.riscv.org/reference/isa/priv/rnmi.html#rnmi" rel="nofollow noreferrer noopener" target="_blank">Resumable Non-Maskable Interrupts extension (Smrnmi)</a>. In this case, if a double trap happens the RNMI handler should be called but RTEMS doesn't set this anywhere as far as I know meaning <code style='font-size: 90%; color: #18171d; word-wrap: break-word; border-radius: .25rem; background-color: #ececef; font-weight: inherit; white-space: break-spaces; overflow-wrap: break-word; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;'>pc</code> is set to whatever the reset value of the RNMI is (which is implementation defined). I need to check the CSR address in NOEL-V (also implementation defined) and then decide what we want to do in that case? Calling the exception handler a third time won't work obviously..</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Showing the double exception along with a register dump:</p>
<div class="gl-relative markdown-code-block js-markdown-code" style="margin-bottom: 0;">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style='display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;'><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; border-radius: .25rem; background-color: inherit; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;">grmon4> bp _RISCV_Exception_handler</span>
<span id="LC2" class="line" lang="plaintext">  Software breakpoint 1 at <_RISCV_Exception_handler></span>
<span id="LC3" class="line" lang="plaintext"></span>
<span id="LC4" class="line" lang="plaintext">grmon4> run</span>
<span id="LC5" class="line" lang="plaintext">  CPU 0:  Breakpoint 1 hit</span>
<span id="LC6" class="line" lang="plaintext">          0x0000000000005c7c: eb010113  addi    sp, sp, -336  <$xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zmmul1p0_zaamo1p0_zalrsc1p0+0></span>
<span id="LC7" class="line" lang="plaintext">  CPU 1:  Forced into debug mode</span>
<span id="LC8" class="line" lang="plaintext">          0x00000000000000ac: ffdff06f  j       0xa8</span>
<span id="LC9" class="line" lang="plaintext"></span>
<span id="LC10" class="line" lang="plaintext">grmon4> inst 10</span>
<span id="LC11" class="line" lang="plaintext">      TIME     L  P  ADDRESS           INSTRUCTION                         RESULT              SYMBOL</span>
<span id="LC12" class="line" lang="plaintext">        95902  1  M  000000000000e5e4  beqz    a0, 0xe5f0                  [0000000000000000]  fdt_get_property_namelen_+0xe8</span>
<span id="LC13" class="line" lang="plaintext">        95907  0  M  000000000000e5e8  lw      a5, 12(sp)                  [000000000000000e]  fdt_get_property_namelen_+0xec</span>
<span id="LC14" class="line" lang="plaintext">        95907  1  M  000000000000e5ec  beq     a5, s3, 0xe65c              [000000000000000e]  fdt_get_property_namelen_+0xf0</span>
<span id="LC15" class="line" lang="plaintext">        95982  0  M  000000000000e65c  mv      a2, s3                      [000000000000000e]  fdt_get_property_namelen_+0x160</span>
<span id="LC16" class="line" lang="plaintext">        95983  0  M  000000000000e660  mv      a1, s6                      [0000000000018a70]  fdt_get_property_namelen_+0x164</span>
<span id="LC17" class="line" lang="plaintext">        95983  1  M  000000000000e664  jal     ra, 0x13e38                 [000000000000e668]  fdt_get_property_namelen_+0x168</span>
<span id="LC18" class="line" lang="plaintext">        95985  0  M  0000000000013e38  li      a3, 7                       [0000000000000007]  memcmp+0x0</span>
<span id="LC19" class="line" lang="plaintext">        95985  1  M  0000000000013e3c  bgeu    a3, a2, 0x13e5c             [0000000000000007]  memcmp+0x4</span>
<span id="LC20" class="line" lang="plaintext">        95986  0  M  0000000000013e40  ld      a4, 0(a0)                   [MISALIGNED LOAD   000000000001b5f9]  memcmp+0x8</span>
<span id="LC21" class="line" lang="plaintext">        96057  0  M  0000000000005c7c  addi    sp, sp, -336                [   BREAKPOINT   ]  $xrv64i2p1_m2p0_a2p1_f2p2_d2p2_zicsr2p0_zmmul1p0_zaamo1p0_zalrsc1p0+0x0</span>
<span id="LC22" class="line" lang="plaintext"></span>
<span id="LC23" class="line" lang="plaintext">grmon4> cont</span>
<span id="LC24" class="line" lang="plaintext">  CPU 0:  Error mode  (4, Load address misaligned)</span>
<span id="LC25" class="line" lang="plaintext">          0x0000000030011000: 0000  illegal instruction</span>
<span id="LC26" class="line" lang="plaintext">  CPU 1:  Forced into debug mode</span>
<span id="LC27" class="line" lang="plaintext">          0x00000000000000ac: ffdff06f  j       0xa8</span>
<span id="LC28" class="line" lang="plaintext"></span>
<span id="LC29" class="line" lang="plaintext">grmon4> inst 10</span>
<span id="LC30" class="line" lang="plaintext">      TIME     L  P  ADDRESS           INSTRUCTION                         RESULT              SYMBOL</span>
<span id="LC31" class="line" lang="plaintext">       103960  1  M  000000000000e428  ret                                 [000000000000e42c]  fdt_get_string+0x120</span>
<span id="LC32" class="line" lang="plaintext">       103962  1  M  000000000000e5e4  beqz    a0, 0xe5f0                  [0000000000000000]  fdt_get_property_namelen_+0xe8</span>
<span id="LC33" class="line" lang="plaintext">       103967  0  M  000000000000e5e8  lw      a5, 12(sp)                  [000000000000000a]  fdt_get_property_namelen_+0xec</span>
<span id="LC34" class="line" lang="plaintext">       103967  1  M  000000000000e5ec  beq     a5, s3, 0xe65c              [000000000000000a]  fdt_get_property_namelen_+0xf0</span>
<span id="LC35" class="line" lang="plaintext">       103974  0  M  000000000000e65c  mv      a2, s3                      [000000000000000a]  fdt_get_property_namelen_+0x160</span>
<span id="LC36" class="line" lang="plaintext">       103975  0  M  000000000000e660  mv      a1, s6                      [0000000000018858]  fdt_get_property_namelen_+0x164</span>
<span id="LC37" class="line" lang="plaintext">       103975  1  M  000000000000e664  jal     ra, 0x13e38                 [000000000000e668]  fdt_get_property_namelen_+0x168</span>
<span id="LC38" class="line" lang="plaintext">       103977  0  M  0000000000013e38  li      a3, 7                       [0000000000000007]  memcmp+0x0</span>
<span id="LC39" class="line" lang="plaintext">       103977  1  M  0000000000013e3c  bgeu    a3, a2, 0x13e5c             [0000000000000007]  memcmp+0x4</span>
<span id="LC40" class="line" lang="plaintext">       103978  0  M  0000000000013e40  ld      a4, 0(a0)                   [MISALIGNED LOAD   000000000001b5dc]  memcmp+0x8</span>
<span id="LC41" class="line" lang="plaintext"></span>
<span id="LC42" class="line" lang="plaintext"></span>
<span id="LC43" class="line" lang="plaintext">grmon4> reg</span>
<span id="LC44" class="line" lang="plaintext">  a0: 000000000001b5dc    t0: 00000000000000e0    s0: 0000000000000050</span>
<span id="LC45" class="line" lang="plaintext">  a1: 0000000000018858    t1: 0000000000000000    s1: 000000000001a3d8</span>
<span id="LC46" class="line" lang="plaintext">  a2: 000000000000000a    t2: 0000000000014648    s2: 00000000000601c8</span>
<span id="LC47" class="line" lang="plaintext">  a3: 0000000000000007    t3: 0000000000000001    s3: 000000000000000a</span>
<span id="LC48" class="line" lang="plaintext">  a4: 000000000001b5e0    t4: 0000000000000000    s4: 0000000000000003</span>
<span id="LC49" class="line" lang="plaintext">  a5: 000000000000000a    t5: 0000000000000000    s5: 0000000000000009</span>
<span id="LC50" class="line" lang="plaintext">  a6: 0000000000000000    t6: 0000000000000000    s6: 0000000000018858</span>
<span id="LC51" class="line" lang="plaintext">  a7: ffffffffffffffff                            s7: 0000000000000004</span>
<span id="LC52" class="line" lang="plaintext">                                                  s8: 00000000000601ac</span>
<span id="LC53" class="line" lang="plaintext">  Machine mode            sp: 0000000000060130    s9: 000000000001a460</span>
<span id="LC54" class="line" lang="plaintext">  FPU dirty state         tp: 0000000000000000   s10: 0000000000000000</span>
<span id="LC55" class="line" lang="plaintext">  IRQ disabled            gp: 000000000005bc48   s11: 0000000000000000</span>
<span id="LC56" class="line" lang="plaintext"></span>
<span id="LC57" class="line" lang="plaintext">  ra: 000000000000e668                           <fdt_get_property_namelen_+0x16c></span>
<span id="LC58" class="line" lang="plaintext">  pc: 0000000030011000   illegal instruction</span>
<span id="LC59" class="line" lang="plaintext"></span>
<span id="LC60" class="line" lang="plaintext">grmon4> reg mtvec mepc mtval mcause mstatus</span>
<span id="LC61" class="line" lang="plaintext">      mtvec = 23676 (0x0000000000005c7c)</span>
<span id="LC62" class="line" lang="plaintext">       mepc = 81472 (0x0000000000013e40)</span>
<span id="LC63" class="line" lang="plaintext">      mtval = 112121 (0x000000000001b5f9)</span>
<span id="LC64" class="line" lang="plaintext">     mcause = 4 (0x0000000000000004)</span>
<span id="LC65" class="line" lang="plaintext">    mstatus = 9223376477850990592 (0x8000040a00007800)</span>
<span id="LC66" class="line" lang="plaintext"></span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
</div>


</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">

<br>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5383#note_135544">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/sent_notifications/d7b6dbd794915389ddd0c63e8e789b10/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5383#note_135544 at 1762022299
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5383#note_135544"}}</script>


</p>
</div>
</body>
</html>