<HTML dir=ltr><HEAD><TITLE>Re: RTEMS4.11 / newlib / gcc issue on Sparc / LEON3</TITLE>
<META content="text/html; charset=unicode" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 9.00.8112.16575"></HEAD>
<BODY>
<DIV dir=ltr id=idOWAReplyText51263>
<DIV dir=ltr><FONT color=#000000 size=2 face=Arial>Hello Joel,</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=Arial>this did the trick. The default stack size was 4kBytes. 8kBytes seem to work fine.</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=Arial>Maybe the default stack size of the rtems shell can be increased as a simple command like "ls" will exceed the 4kBytes.</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=Arial>Thank you for the hint.</FONT></DIV>
<DIV dir=ltr><FONT size=2 face=Arial></FONT> </DIV></DIV>
<DIV dir=ltr><BR>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>Von:</B> Joel Sherrill [mailto:joel.sherrill@oarcorp.com]<BR><B>Gesendet:</B> Di 14.10.2014 18:12<BR><B>An:</B> Hoefle Marco; Chris Johns; Jiri Gaisler; Sebastian Huber; users@rtems.org<BR><B>Betreff:</B> Re: RTEMS4.11 / newlib / gcc issue on Sparc / LEON3<BR></FONT><BR></DIV>
<DIV>
<P><FONT size=2>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, Hoefle Marco 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><BR></FONT></P></DIV></BODY></HTML>