<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>Re: RTEMS4.11 / newlib / gcc issue on Sparc / LEON3</title>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>For me if I set the stack size to 0 (auto)
then I assume that’s enough and the shell will work with the basic command set.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>I understand that users should think about
stack size so what about not to allow 0 as shell task stack size? <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> Joel Sherrill
[mailto:joel.sherrill@oarcorp.com] <br>
<b><span style='font-weight:bold'>Sent:</span></b> Donnerstag, 16. Oktober 2014
14:08<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">Hoefle
 Marco</st1:PersonName>; Chris Johns; Jiri Gaisler; Sebastian Huber;
users@rtems.org<br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: RTEMS4.11 / newlib /
gcc issue on Sparc / LEON3</span></font><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>Anyone have thoughts on a
more generous minimum attach size for the shell? 4k is one of the larger
minimums across the architectures.<br>
<br>
FWIW on the arm or m68k, stack usage is lower. The SPARC has large stack frames
thanks to the register windows <br>
<br>
--joel<o:p></o:p></span></font></p>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>On October 15, 2014 2:11:41 AM CDT, <st1:PersonName w:st="on">Hoefle
 Marco</st1:PersonName> <Marco.Hoefle@nanotronic.ch> wrote:<o:p></o:p></span></font></p>

<div id=idOWAReplyText51263>

<div>

<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:black'>Hello Joel,</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>this did the trick. The default stack size was 4kBytes.
8kBytes seem to work fine.</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Maybe the default stack size of the rtems shell can be
increased as a simple command like "ls" will exceed the 4kBytes.</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Thank you for the hint.</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>

</div>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal style='margin-bottom:12.0pt'><b><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma;font-weight:bold'>Von:</span></font></b><font
size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> Joel
Sherrill [mailto:joel.sherrill@oarcorp.com]<br>
<b><span style='font-weight:bold'>Gesendet:</span></b> Di 14.10.2014 18:12<br>
<b><span style='font-weight:bold'>An:</span></b> <st1:PersonName w:st="on">Hoefle
 Marco</st1:PersonName>; Chris Johns; Jiri Gaisler; Sebastian Huber;
users@rtems.org<br>
<b><span style='font-weight:bold'>Betreff:</span></b> Re: RTEMS4.11 / newlib /
gcc issue on Sparc / LEON3</span></font><o:p></o:p></p>

</div>

<div>

<p style='margin-bottom:12.0pt'><font size=2 face="Times New Roman"><span
style='font-size:10.0pt'>Can you turn on stack checking?<br>
<br>
it is either a stray write, a stack overflow, or something<br>
writing past the end of a buffer. Given that is appears<br>
to be a local variable which should be a register in<br>
a SPARC register window, I lean to stack overflow.<br>
<br>
Especially since you passed 0 to rtems_shell_init for<br>
task_stacksize. That gives it a minimum stack size.<br>
Try a large number like 256 * 1024 and see if the<br>
problem goes away.<br>
<br>
Stack checking also allows you to use the stackuse command<br>
which will help you trim it back down.<br>
On 10/14/2014 10:07 AM, <st1:PersonName w:st="on">Hoefle Marco</st1:PersonName>
wrote:<br>
> Hello again,<br>
> I had this memory aligned failure and I thought it is fixed with the new<br>
> newlib version.<br>
> We have now a new strange phenomena: A local variable is overwritten in<br>
> a thread when the command "ls" is executed in the rtems shell:<br>
><br>
><br>
> Starting 1 threads...<br>
> started thread 0: id: 0x0b010002, prio: 10<br>
>  =========================<br>
>  starting shell<br>
>  =========================<br>
><br>
> RTEMS SHELL (Ver.1.0-FRC):/dev/console. Oct 14 2014. 'help' to list<br>
> commands.<br>
> [/] # hello dude, this is tick nr: 1<br>
> hello dude, this is tick nr: 2<br>
> hello dude, this is tick nr: 3<br>
> hello dude, this is tick nr: 4<br>
> hello dude, this is tick nr: 5<br>
> hello dude, this is tick nr: 6<br>
><br>
> [/] #<br>
> [/] #<br>
> [/] # ls<br>
> dev<br>
> hello dude, this is tick nr: 0<br>
> hello dude, this is tick nr: 1<br>
> hello dude, this is tick nr: 2<br>
> hello dude, this is tick nr: 3<br>
><br>
> [/] # ls<br>
> dev<br>
> hello dude, this is tick nr: 0<br>
><br>
> [/] #<br>
> hello dude, this is tick nr: 1<br>
> hello dude, this is tick nr: 2<br>
> hello dude, this is tick nr: 3<br>
> hello dude, this is tick nr: 4<br>
> hello dude, this is tick nr: 5<br>
> hello dude, this is tick nr: 6<br>
> hello dude, this is tick nr: 7<br>
><br>
><br>
> This will be the simple rtems4.11 test app:<br>
><br>
><br>
> #include <bsp.h><br>
> #include <errno.h><br>
> #include <fcntl.h><br>
> #include <stdlib.h><br>
> #include <stdio.h><br>
> #include <unistd.h><br>
> #include <pthread.h><br>
> #include <sched.h><br>
> #include <rtems/shell.h><br>
> #include <errno.h><br>
><br>
> #include "rtems_config.h"<br>
><br>
><br>
> void *tsk_core(void *unused);<br>
> void *tsk_dummy(void *unused);<br>
><br>
><br>
> struct {<br>
>       int prio;<br>
>       void *(*func)(void *arg);<br>
>       pthread_t id;<br>
> }static threads[] = {<br>
>              
{ .prio = 10, .func = tsk_core },<br>
> //            { .prio =
3, .func = tsk_shell }, /* minimum prio */<br>
> //            { .prio =
10, .func =tsk_spw0 },<br>
> //            { .prio =
10, .func = tsk_spw1 },<br>
> //            { .prio =
2, .func = tsk_script },<br>
> //            { .prio =
3, .func = tsk_shell }, /* minimum prio */<br>
> //            { .prio =
3, .func = tsk_dummy }, /* minimum prio */<br>
> };<br>
><br>
> static uint8_t nr_threads = sizeof(threads) / sizeof(threads[0]);<br>
><br>
><br>
> void start_shell(void)<br>
> {<br>
>       rtems_status_code sc = RTEMS_SUCCESSFUL;<br>
>       printf("
=========================\n\r");<br>
>       printf(" starting shell\n\r");<br>
>       printf("
=========================\n\r");<br>
><br>
><br>
>       sc = rtems_shell_init(<br>
>              
"SHLL", /* task name */<br>
>              
0, /* task stack size */<br>
>              
100, /* task priority */<br>
>              
"/dev/console", /* device name */<br>
>              
true, /* run forever */<br>
>              
true, /* wait for shell to terminate */<br>
>              
NULL /* login check function,<br>
>              
use NULL to disable a login check */<br>
>       );<br>
><br>
>       printf("sc: %d, errno: %s\n\r",
sc, strerror(errno));<br>
> }<br>
><br>
><br>
> void hello_dude(int ticks)<br>
> {<br>
>       printf("hello dude, this is tick nr:
%d\n\r", ticks);<br>
> }<br>
><br>
><br>
> void *tsk_core(void *unsued)<br>
> {<br>
>       int ticks = 1;<br>
>       while (1) {<br>
>              
sleep(10);<br>
>              
hello_dude(ticks++);<br>
>       }<br>
><br>
>       return NULL;<br>
> }<br>
><br>
> static int initUart( const char *devname)<br>
> {<br>
>     int fd = open( devname, O_RDWR);<br>
>     if (fd < 0) {<br>
>         return -errno;<br>
>     }<br>
><br>
>     struct termios settings;<br>
>     tcgetattr( fd, &settings);<br>
>     settings.c_iflag &= ~(IGNBRK | BRKINT | PARMRK
| ISTRIP<br>
>                    
| INLCR | IGNCR | ICRNL | IXON);<br>
>     settings.c_oflag &= ~OPOST;<br>
>     settings.c_lflag &= ~(ECHO | ECHONL | ICANON |
ISIG | IEXTEN);<br>
>     settings.c_cflag &= ~(CSIZE | PARENB);<br>
>     settings.c_cflag |= CS8;<br>
>     settings.c_cc[VMIN]  = 1;<br>
>     settings.c_cc[VTIME] = 0;<br>
><br>
>     if(cfsetispeed(&settings, B115200) < 0 ||
cfsetospeed(&settings,<br>
> B115200) < 0) {<br>
>         return -1;<br>
>     }<br>
><br>
>     int err = tcsetattr( fd, TCSADRAIN,
&settings);<br>
>     if (err) return -err;<br>
><br>
>     return fd;<br>
> }<br>
><br>
> void *POSIX_Init(void *argument)<br>
> {<br>
>       pthread_attr_t attr;<br>
>       struct sched_param schedparam;<br>
>       int retVal;<br>
><br>
><br>
>       initUart("/dev/console");<br>
><br>
>       retVal = pthread_attr_init(&attr);<br>
>       retVal |=
pthread_attr_getschedparam(&attr, &schedparam);<br>
>       retVal |= pthread_attr_setinheritsched(&attr,<br>
> PTHREAD_EXPLICIT_SCHED);<br>
>       retVal |=
pthread_attr_setschedpolicy(&attr, SCHED_RR);<br>
>       if (retVal) {<br>
>              
printf("thread setup failed!\n\r");<br>
>       }<br>
><br>
>       if(retVal == 0) {<br>
>              
/* starting threads */<br>
>              
printf( "Starting %d threads...\n\r", nr_threads);<br>
><br>
>              
for (uint8_t i = 0; i < nr_threads; i++) {<br>
>              
        schedparam.sched_priority =
threads[i].prio;<br>
>              
        retVal |= pthread_attr_setschedparam(&attr,<br>
> &schedparam);<br>
>              
        retVal |=
pthread_create(&threads[i].id, &attr,<br>
> threads[i].func, NULL);<br>
><br>
>              
        if (retVal)<br>
>              
        {<br>
>              
       
        printf("thread creation
failed!\n\r");<br>
><br>
>              
       
        // cancel loop<br>
>              
       
        i = nr_threads;<br>
>              
        }<br>
>              
        printf( "started thread %d: id:
0x%08x, prio:<br>
> %d\n\r", i, threads[i].id, threads[i].prio);<br>
>              
}<br>
>       }<br>
><br>
>       start_shell();<br>
><br>
>       return NULL;<br>
> }<br>
><br>
> I'll be happy to provide the c files, retms config and Makefile as an<br>
> email attachment if somebody is interested.<br>
><br>
> Marco<br>
><br>
><br>
><br>
><br>
<br>
--<br>
Joel Sherrill,
Ph.D.            
Director of Research & Development<br>
joel.sherrill@OARcorp.com        On-Line
Applications Research<br>
Ask me about RTEMS: a free RTOS  Huntsville AL 35805<br>
Support
Available               
(256) 722-9985<br>
<br>
<br>
<br>
</span></font><o:p></o:p></p>

</div>

</div>

</div>

</body>

</html>