Why doesn't the main thread need a SETUP_CONTEXT?

Discussions and support about ChibiOS/RT, the free embedded RTOS.
xnr
Posts: 9
Joined: Fri Jul 18, 2014 4:49 pm

Why doesn't the main thread need a SETUP_CONTEXT?

Postby xnr » Fri Jul 18, 2014 5:21 pm

I am porting ChibiOS 2.6.4 to new platform. Unfortunately, my demo application crashes when a context switch to the main thread takes place. I figured out that the main thread context contains garbage data. I think this happens because the context isn't setup like it is for other normal threads.

How do the other ports handle this?

skute
Posts: 64
Joined: Wed Aug 29, 2012 10:17 pm

Re: Why doesn't the main thread need a SETUP_CONTEXT?

Postby skute » Fri Jul 18, 2014 7:11 pm

chSysInit() setups the context for the main thread, if it's corrupted then you might have a stack overflow.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Why doesn't the main thread need a SETUP_CONTEXT?

Postby Giovanni » Fri Jul 18, 2014 7:18 pm

Correct, it uses the same macro, there must be some other detail causing this. All ports do the same thing for the main() thread, it is not port-dependent.

Giovanni

xnr
Posts: 9
Joined: Fri Jul 18, 2014 4:49 pm

Re: Why doesn't the main thread need a SETUP_CONTEXT?

Postby xnr » Fri Jul 18, 2014 9:27 pm

I can see that mainthread is passed to _thread_init, but that doesn't use SETUP_CONTEXT. Could you point me to the code line or provide a call stack?

(It's not that I don't believe you, but I want to understand where the main thread's context is setup)

skute
Posts: 64
Joined: Wed Aug 29, 2012 10:17 pm

Re: Why doesn't the main thread need a SETUP_CONTEXT?

Postby skute » Fri Jul 18, 2014 11:41 pm

SETUP_CONTEXT isn't required because the main thread is already running when it is initialized. All other threads need the SETUP_CONTEXT so that the first context switch can happen successfully.

After the chSysInit() the context gets pushed to the main thread stack in the same way as all other threads (because of an interrupt or a blocking OS call).


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 37 guests