<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 18, 2014 at 4:15 PM, Hesham Moustafa <span dir="ltr"><<a href="mailto:heshamelmatary@gmail.com" target="_blank">heshamelmatary@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Jul 18, 2014 at 4:17 PM, Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br>

> On Fri, Jul 18, 2014 at 1:35 AM, Hesham Moustafa<br>
> <<a href="mailto:heshamelmatary@gmail.com">heshamelmatary@gmail.com</a>> wrote:<br>
>><br>
>> On Thu, Jul 17, 2014 at 3:10 PM, Joel Sherrill<br>
>> <<a href="mailto:joel.sherrill@oarcorp.com">joel.sherrill@oarcorp.com</a>> wrote:<br>
>> > This definitely sounds like not handling the context switch necessary<br>
>> > part of the<br>
>> > IRQ processing properly so always returning to IDLE. I call this a<br>
>> > simple return.<br>
>> ><br>
>> > All ports have a version of this code. no_cpu should have reasonable<br>
>> > pseudo-code.<br>
>> > m68k is likely the easiest to read as real code.<br>
>> ><br>
>> > You need to do a simple return if:<br>
>> ><br>
>> > (a) IRQ is nested, or<br>
>> > (b) DISPATCH_NEEDED is false<br>
>> ><br>
>> This is a macro that defines the address of the corresponding variable<br>
>> within the per cpu config table right? Please correct the following if<br>
>> I it's wrong. From assembly (when doing restore after C ISR handler is<br>
>> executed), I have to load this variable value, check if it's true<br>
>> (greater than zero), and if yes, jump to _ISR_Dispatch. I am a little<br>
>> confused what context should be loaded in both cases of: simple<br>
>> return, and _ISR_Dispatch; In case of _ISR_Dispatch, should I save<br>
>> stack pointer and return address and other context like normal context<br>
>> switch (function call)? While in interrupt context (simple return), I<br>
>> am saving almost all registers with some other necessary registers<br>
>> related to exceptions.<br>
>><br>
> Please see <a href="http://rtems.org/onlinedocs/doc-current/share/rtems/html/porting/Interrupts-Interrupt-Dispatching.html#Interrupts-Interrupt-Dispatching" target="_blank">http://rtems.org/onlinedocs/doc-current/share/rtems/html/porting/Interrupts-Interrupt-Dispatching.html#Interrupts-Interrupt-Dispatching</a><br>

><br>
</div></div>Yes, I have read this along with no_cpu.h, m68k, nios2 code.<br>
<div class="">> Summarizing:<br>
><br>
> You need to update a few variables before calling the user ISR:<br>
> _Thread_Dispatch_disable_level += 1<br>
> _ISR_Nest_level += 1<br>
><br>
> And decrement them after returning.<br>
> If ISRs are nested you do a simple return.<br>
><br>
> Then you need to check if _CPU_ISR_Dispatch_disable is set, if so do a<br>
> simple return.<br>
><br>
> Then you need to check if DISPATCH_NEEDED, if so you need to do the<br>
> ISR_Dispatch.<br>
><br>
</div>That's what I try to do in assembly, but still I get a compilation error when<br>
including the headers containing DISPATCH_NEEDED macros and other<br>
nesting and dispatch disable macros. The files included in my assembly<br>
file exactly the same as m68k. Please have a look I just pushed for anyone<br>
to review, but it still produce compilation error for no recognizing C code.<br>
<br></blockquote><div>What is the compilation error? Is it only DISPATCH_NEEDED, or also ISR_NEST_LEVEL and THREAD_DISPATCH_DISABLE_LEVEL?<br><br></div><div>Do you have the correct define for SYM() in your asm.h?  <br><br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
[1] <a href="https://github.com/heshamelmatary/rtems-gsoc2014/blob/or1k/cpukit/score/cpu/or1k/or1k-exception-handler-low.S" target="_blank">https://github.com/heshamelmatary/rtems-gsoc2014/blob/or1k/cpukit/score/cpu/or1k/or1k-exception-handler-low.S</a><br>

<div class="HOEnZb"><div class="h5">><br>
>> One thing I have a problem with, is when using some macros like<br>
>> DISPATCH_NEEDED (it's a variable address right?) I am normally<br>
>> including rtems/score/percpu.h from the assembly file (which does the<br>
>> magic) to get these definitions but the compiler suffers. I think I<br>
>> have to provide compiler option or something to just include #define<br>
>> macros? If yes, where to add it?<br>
>><br>
> Make sure to include rtems/asm.h before including percpu.h so you get<br>
> the ASM defines instead of C defines, since you are (presumably)<br>
> writing this in assembly. You could also use inline assembly, but then<br>
> you need to use expression operands [1] to provide access to these<br>
> variables instead.<br>
><br>
> [1]  <a href="https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html" target="_blank">https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html</a><br>
><br>
> -Gedare<br>
><br>
>> > Otherwise, you need to some CPU specific magic to get our of the IRQ and<br>
>> > back to the thread. Make it look like it called _Thread_Dispatch with<br>
>> > sufficient saved registers (e.g. callee destroyed). This is usually called<br>
>> > _ISR_Dispatch.  When the call from _ISR_Dispatch to _Thread_Dispatch<br>
>> > returns, you do the magic needed to return tot he interrupted thread<br>
>> > (IDLE in this case) as if nothing happened.<br>
</div></div></blockquote></div><br></div></div>