<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 19, 2020 at 3:04 AM Gedare Bloom <<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Jun 18, 2020 at 8:03 AM Utkarsh Rai <<a href="mailto:utkarsh.rai60@gmail.com" target="_blank">utkarsh.rai60@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Jun 18, 2020 at 6:34 PM Gedare Bloom <<a href="mailto:gedare@rtems.org" target="_blank">gedare@rtems.org</a>> wrote:<br>
>><br>
>> On Wed, Jun 17, 2020 at 11:17 PM Utkarsh Rai <<a href="mailto:utkarsh.rai60@gmail.com" target="_blank">utkarsh.rai60@gmail.com</a>> wrote:<br>
>> ><br>
>> > Hello,<br>
>> > For my GSoC project, I need to set/unset the memory attributes of the thread stacks on each context switch.<br>
>> > Right now I am making changes to the CPU-specific context switch assembly code. The arm/../cpu.h file has the Context_Control structure, which is used to store the relevant registers at each context switch.<br>
>> > I have been trying to add the stack attributes to this structure from the 'rtems/score/stackmanagement.h' header (This header has been defined by me and has the stack attributes structure).<br>
>><br>
>> When you change the context structure, there might be other places you<br>
>> need to update besides the context switch itself. One that comes to<br>
>> mind is _CPU_Context_validate. Maybe chase down where the context is<br>
>> referenced.<br>
>><br>
>> > After that, I would initialize the stack attributes in _CPU_Context_Initialize.<br>
>> > For unsetting stack memories, I plan on making changes to _CPU_Context_Switch().<br>
>> > The problem is when I try to include the header in cpu.h it breaks the build with the following error -<br>
>> ><br>
>> > '.......<br>
>> > ........<br>
>> > /home/utkarsh/sandbox/rtems/5/arm-rtems5/include/machine/_default_types.h: Assembler messages:<br>
>> > /home/utkarsh/sandbox/rtems/cpukit/include/rtems/score/stackmanagement.h:42: Error: junk at end of line, first unrecognized character is `}'<br>
>> > /home/utkarsh/sandbox/rtems/cpukit/include/rtems/score/stackmanagement.h:44: Error: bad instruction `typedef struct stack_attr_prot'<br>
>> > /home/utkarsh/sandbox/rtems/cpukit/include/rtems/score/stackmanagement.h:45: Error: junk at end of line, first unrecognized character is `{'<br>
>> > /home/utkarsh/sandbox/rtems/cpukit/include/rtems/score/stackmanagement.h:46: Error: bad instruction `stack_attr_shared *shared_stacks'<br>
>> > /home/utkarsh/sandbox/rtems/cpukit/include/rtems/score/stackmanagement.h:47: Error: bad instruction `stack_attr Base'<br>
>> > /home/utkarsh/sandbox/rtems/cpukit/include/rtems/score/stackmanagement.h:48: Error: bad instruction `_bool current_stack'<br>
>> > {standard input}: Error: invalid operands (*UND* and *ABS* sections) for `*' when setting `iter'<br>
>> > Makefile:11563: recipe for target 'score/cpu/arm/arm-context-validate.o' failed<br>
>> > make[4]: *** [score/cpu/arm/arm-context-validate.o] Error 1<br>
>> > '<br>
>> > I have defined the stackmanagement.h header in the cpukit/<a href="http://headers.am" rel="noreferrer" target="_blank">headers.am</a> and this is obviously an assembler error. Can someone point out what is it that I am doing wrong?<br>
>> ><br>
>><br>
>> When a .h file can be included in both C and ASM, you need to separate<br>
>> some of it, and disable some of it in ASM scope that doesn't<br>
>> understand C data types. See, for example,<br>
>> cpukit/include/rtems/score/percpu.h<br>
>><br></blockquote><div><br></div><div>Thank you, this solves the problem.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
>> > I also would like to verify if the above way of handling context switching is the appropriate way to proceed.<br>
>><br>
>> Seems like the right general idea. We probably need a CPP switch to<br>
>> enable/disable this stuff though.<br>
><br>
><br>
> Can you please elaborate on CPP switch? I am not sure if I am clear about this.<br>
<br>
Yeah, my reply was a little short. CPP for C Preprocessor. A CPP<br>
switch is used for conditional compilation of code, something like<br>
<br>
#if defined(USE_MMU)<br>
... /* some MMU related code */<br>
#else<br>
... /* something without using MMU */<br>
#endif<br>
<br>
This way high-level features can control which code gets compiled into<br>
the binary image. This works pretty well for coarse-grained features.<br>
It is not that useful for finer-grained features, like you might not<br>
want to have USE_MMU_2K_PAGES and USE_MMU_4K_PAGES and<br>
USE_MMU_4M_PAGES instead it would be better to have USE_MMU and within<br>
that scope provide some way to distinguish the page sizes. I hope that<br>
makes some sense.<br>
<br>
Another example is ASM. We have #if ASM to control whether a header<br>
has been included in an assembler source file.<br></blockquote><div> </div><div>Thank you, this makes it clear. Also, if we are using CPP switches for switching to MMU related code, I wonder what should be the high-level configuration option that should be provided to the user. A very naive way can be if the user defines something like-</div><div> #define USE_THREAD_STACK_PROTECTION</div><div><br></div><div>and then the places where we need to handle for thread stack protection we can proceed as you illustrate above.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Gedare<br>
</blockquote></div></div>