<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2017-08-17 23:58 GMT+02:00 Gedare Bloom <span dir="ltr"><<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">On Thu, Aug 17, 2017 at 4:17 PM, Denis Obrezkov <<a href="mailto:denisobrezkov@gmail.com">denisobrezkov@gmail.com</a>> wrote:<br>
> 2017-08-17 22:07 GMT+02:00 Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>>:<br>
>><br>
>> On Thu, Aug 17, 2017 at 1:48 PM, Denis Obrezkov <<a href="mailto:denisobrezkov@gmail.com">denisobrezkov@gmail.com</a>><br>
>> wrote:<br>
>> > 2017-08-17 17:25 GMT+02:00 Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>>:<br>
>> >><br>
>> >> On Wed, Aug 16, 2017 at 11:13 AM, Denis Obrezkov<br>
>> >> <<a href="mailto:denisobrezkov@gmail.com">denisobrezkov@gmail.com</a>> wrote:<br>
>> >> > ---<br>
>> >> > cpukit/score/cpu/riscv32/<wbr>riscv-context-switch.S | 12 ++++++++++--<br>
>> >> > 1 file changed, 10 insertions(+), 2 deletions(-)<br>
>> >> ><br>
>> >> > diff --git a/cpukit/score/cpu/riscv32/<wbr>riscv-context-switch.S<br>
>> >> > b/cpukit/score/cpu/riscv32/<wbr>riscv-context-switch.S<br>
>> >> > index a199596..bcdfe0e 100644<br>
>> >> > --- a/cpukit/score/cpu/riscv32/<wbr>riscv-context-switch.S<br>
>> >> > +++ b/cpukit/score/cpu/riscv32/<wbr>riscv-context-switch.S<br>
>> >> > @@ -46,6 +46,7 @@ PUBLIC(restore)<br>
>> >> ><br>
>> >> > SYM(_CPU_Context_switch):<br>
>> >> > /* Disable interrupts and store all registers */<br>
>> >> > + csrci mstatus, 0x8<br>
>> >> Why is this necessary?<br>
>> >><br>
>> >> > SREG x1, 4(a0)<br>
>> >> > SREG x2, 8(a0)<br>
>> >> > SREG x3, 12(a0)<br>
>> >> > @@ -78,8 +79,9 @@ SYM(_CPU_Context_switch):<br>
>> >> > SREG x30, 120(a0)<br>
>> >> > SREG x31, 124(a0)<br>
>> >> ><br>
>> >> > -SYM(restore):<br>
>> >> ><br>
>> >> > +SYM(restore):<br>
>> >> > +<br>
>> >> > LREG x1, 4(a1)<br>
>> >> > LREG x2, 8(a1)<br>
>> >> > LREG x3, 12(a1)<br>
>> >> > @@ -111,9 +113,15 @@ SYM(restore):<br>
>> >> > LREG x29, 116(a1)<br>
>> >> > LREG x30, 120(a1)<br>
>> >> > LREG x31, 124(a1)<br>
>> >> > - ret<br>
>> >> > +<br>
>> >> > +<br>
>> >> > + csrsi mstatus, 0x8<br>
>> >> > + nop<br>
>> >> > + nop<br>
>> >> Why the nops?<br>
>> >><br>
>> >> > + ret<br>
>> >> ><br>
>> >> > SYM(_CPU_Context_restore):<br>
>> >> > + csrci mstatus, 0x8<br>
>> >> > mv a1, a0<br>
>> >> > j restore<br>
>> >> > nop<br>
>> >> > --<br>
>> >> > 2.1.4<br>
>> >> ><br>
>> >> > ______________________________<wbr>_________________<br>
>> >> > devel mailing list<br>
>> >> > <a href="mailto:devel@rtems.org">devel@rtems.org</a><br>
>> >> > <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/<wbr>mailman/listinfo/devel</a><br>
>> ><br>
>> > So, don't we turn off interrupts during the context switch?<br>
>><br>
>> Nope, and turning them back on unconditionally is wrong too.<br>
>><br>
>> > Yes, nops are unnecessary.<br>
>> ><br>
>> ><br>
>> > --<br>
>> > Regards, Denis Obrezkov<br>
><br>
> Ok, I was confused by this obsolete comment:<br>
> /* Disable interrupts and store all registers */<br>
> Will remove all that enabling/disabling.<br>
><br>
> Is the same true for start.S file with interrupted task's stack saving?<br>
><br>
</div></div>I'm not sure exactly what you're referring to, but usually start.S<br>
will, among other things, turn off and ack pending interrupts to<br>
quiesce the hardware before handing off the rest of system init to<br>
boot_card. Eventually RTEMS will enable interrupts again using the<br>
cpukit's interrupt_enable layer.<br>
<br>
><br>
<span class="gmail-HOEnZb"><font color="#888888">><br>
> --<br>
> Regards, Denis Obrezkov<br>
</font></span></blockquote></div>I mean when an interrupt occurs, the execution flow jumps to the trap address.</div><div class="gmail_extra">Then, in my case all process'es registers are saved in a common stack</div><div class="gmail_extra">(I know that dedicated interrupt stack should be implemented, but I haven't time to do that)</div><div class="gmail_extra">and then we jump to IRQ dispatching routine. After interrupt handling we restore saved</div><div class="gmail_extra">registers. So, my question is - should we disable/enable interrupts during interrupt handling?</div><div class="gmail_extra">Disabling:</div><div class="gmail_extra"><a href="https://github.com/embeddedden/rtems-riscv/blob/hifive1/c/src/lib/libbsp/riscv32/hifive1/start/start.S#L201">https://github.com/embeddedden/rtems-riscv/blob/hifive1/c/src/lib/libbsp/riscv32/hifive1/start/start.S#L201</a></div><div class="gmail_extra">Jump to dispatching routine:</div><div class="gmail_extra"><a href="https://github.com/embeddedden/rtems-riscv/blob/hifive1/c/src/lib/libbsp/riscv32/hifive1/start/start.S#L241">https://github.com/embeddedden/rtems-riscv/blob/hifive1/c/src/lib/libbsp/riscv32/hifive1/start/start.S#L241</a></div><div class="gmail_extra">Enabling interrupts back:</div><div class="gmail_extra"><a href="https://github.com/embeddedden/rtems-riscv/blob/hifive1/c/src/lib/libbsp/riscv32/hifive1/start/start.S#L285">https://github.com/embeddedden/rtems-riscv/blob/hifive1/c/src/lib/libbsp/riscv32/hifive1/start/start.S#L285</a> <br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Regards, Denis Obrezkov</div>
</div></div>