Tricore context to save/restore to implement threading

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User16286
Level 4
Level 4
First like received
For my application, I need to run multiple pieces of code that are single-threaded.
The solution I'm planning to use is to implement a cooperative threading system using yield() semantics.
I've used this before on another platform, and it worked well.
I'm trying to understand all the context which needs to be saved/restored on a Tricore to implement theading kernel.
From what I can understand, these registers should be part of the thread context:

A0-A15
D0-D15
PC
PSW
FCX
PCX
LCX

Are there any other registers which should be saved/restored on a thread context switch?
(Yes, I know about stack/CSAs, and how each thread will need its own strack/CSAs)

Toshi
0 Likes
5 Replies
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
Saving both an upper context and a lower context should do the trick. See the TriCore Architecture manual for details.
0 Likes
User16286
Level 4
Level 4
First like received
UC_wrangler wrote:
Saving both an upper context and a lower context should do the trick. See the TriCore Architecture manual for details.


I've already read it, thanks.
Saving only the upper and lower context doesn't work, because if fails to save the FCX and LCX.
You should read the Tricore V1.6 architecture reference manual, section 4.8 "Context Management Registers" if you are unfamiliar with these registers.

Also, A0, A1, A8, and A9 are not included in either the upper or lower context.

Toshi
0 Likes
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
The convention is that A0/A1/A8/A9 are reserved for near addressing modes. Once initialized in cstart, they are typically not modified and not used by compilers for other purposes.
0 Likes
User16286
Level 4
Level 4
First like received
UC_wrangler wrote:
The convention is that A0/A1/A8/A9 are reserved for near addressing modes. Once initialized in cstart, they are typically not modified and not used by compilers for other purposes.


From what I can tell, you are correct about A0, but are wrong about A1.

Here's the relevant section from the TriCore™Embedded Applications Binary Interface (EABI) manual:

"2.2.1.4 System Global Registers

A[1] is intended as a base pointer to the “literal data section”. The literal data section is
a read-only data section intended for holding address constants and program literal
values. Like A[0], it is initialized in the startup code for any EABI-compliant RTOS."

So it's a pointer to the literal section. From what I can tell, it may or may not be used with short addressing
depending on the size of the literal data.

Here's what the manual says about A8 and A9:

As noted, A[8] and A[9] are reserved for OS use, or for application use in cases where
the application and OS are tightly coupled. The compiler may support a directive that
allows a global pointer variable to be bound to one of these registers. In the absence of
such a directive the registers can only be used from assembly coded functions. A typical
OS use would be as a pointer to the current task control block, or to the task ready
queue, for reducing executive overhead in task management functions."

So A8 and A9 are not "reserved for near addressing".
The are reserved for OS use.

Toshi
0 Likes
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
I'm just telling you how it shakes out in typical applications. A0/A1/A8/A9 are not part of the upper/lower context saves, and compilers typically offer you the freedom to define how they are used.
0 Likes