 |
|
 |
MAEC TOOL NEWS:
MAECT-M3T-MR32R-020216D
A Note on Real-Time OS M3T-MR32R
|
Please take note of the following problem in using real-time OS M3T-MR32R for the M32R family MCUs.
- On using the ref_tsk system call
- Versions Concerned
M3T-MR32R V.3.00 Release 1 -- V.3.40 Release 1
- Description
When a ref_tsk system call is called and processed, register R7 normally restores the value it stored before this call. In the versions concerned, however, register R7 retains the value indicating the task status after the system call is processed and never restores the value it stored before calling ref_tsk.
Consequently, programs in which register R7 is used may fail to run properly.
- Conditions
- In either of the following cases, the R7 register may be used in the program to raise this problem:
- (1) Under the condition that C compiler M3T-CC32R V.2.10 Release 1 or earlier is used, system call ref_tsk is called in C language, and arguments are passed to the stack at this function call.
- (2) System call ref_tsk is called in assembly language.
- Examples
- 4.1 When system call ref_tsk is called in C language
[Example 1]
------------------------------------------------------------------------
If the following program is compiled by M3T-CC32R V.2.10 Release 1 with
option "-O7" selected, the problem arises.
#include <mr32r.h>
#include "id.h"
unsigned char aa[10];
void task(void)
{
T_RTSK rtsk;
int i=1,j=2,k=3,l=4;
aa[5]=1;
ref_tsk(&rtsk,TSK_SELF);
if(aa[0] == 1){
aa[1]=i;
aa[2]=j;
aa[3]=k;
aa[4]=l;
}else{
aa[1]=l;
aa[2]=k;
aa[3]=j;
aa[4]=i;
}
}
------------------------------------------------------------------------
[Example 2]
------------------------------------------------------------------------
If the above program is compiled by M3T-CC32R V.2.10 Release 1 with no
optimizing options selected, the problem arises provided that variables
i, j, k, and l in the program are declared to be register variables.
------------------------------------------------------------------------
- 4.2 When system call ref_tsk is called in assembly language
[Example]
------------------------------------------------------------------------
.SECTION P,code
.align 4
.INCLUDE "mr32r.inc"
:
ld R7,@R8
ref_tsk ID_task
addi R7,#1
st R7,@R8
:
------------------------------------------------------------------------
- Workaround
- 5.1 When system call ref_tsk is called in C language
- (1) Create an interface routine to the C-language program for the ref_tsk system call in assembly language, as shown below. In the routine, the R7 register is saved on the stack before calling ref_tsk and recovered after calling.
- (2) Then, call this routine in the C-language main program.
[Example (the side-stepping of examples 1 and 2 in 4.1 above)]
------------------------------------------------------------------------
* An interface routine to the C-language program for the ref_tsk system
call described in assembly language:
.SECTION MR_KERNEL,code
.align 4
.INCLUDE "mr32r.inc"
.global _new_ref_tsk
_new_ref_tsk:
st R14,@-R15
ld R2,@(4,SP)
ld R1,@(8,SP)
st R7,@-R15 ; Register R7 saved
ldi R0,#REF_TSK
trap #8
ld R7,@R15+ ; Register R7 recovered
ld R14,@R15+
jmp R14
* C-language program:
#include <mr32r.h>
#include "id.h"
#define ref_tsk(a,b) new_ref_tsk(a,b)
ER new_ref_tsk( T_RTSK * pk_tsk, ID tskid );
unsigned char aa[10];
void task(void)
{
T_RTSK rtsk;
int i=1,j=2,k=3,l=4;
aa[5]=1;
ref_tsk(&rtsk,TSK_SELF);
if(aa[0] == 1){
aa[1]=i;
aa[2]=j;
aa[3]=k;
aa[4]=l;
}else{
aa[1]=l;
aa[2]=k;
aa[3]=j;
aa[4]=i;
}
}
------------------------------------------------------------------------
- 5.2 When System call ref_tsk is called in assembly language
- Save the R7 register before calling ref_tsk and recover it after calling.
[Example]
------------------------------------------------------------------------
.SECTION P,code
.align 4
.INCLUDE "mr32r.inc"
:
ld R7,@R8
st R7,@-R15 ; Register R7 saved
ref_tsk ID_task
ld R7,@R15+ ; Register R7 recovered
addi R7,#1
st R7,@R8
:
------------------------------------------------------------------------
- Schedule of Fixing the Problem
We plan to fix this problem in our next release.
|
 |