# CodeWarrior Compile problem

**URL:** <https://forums.freertos.org/t/codewarrior-compile-problem/3529>\
**Category:** Kernel\
**Created:** [February 13, 2005, 2:45pm UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529 "2005-02-13T14:45:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 13, 2005, 2:45pm UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/1 "2005-02-13T14:45:15Z")

</div>

**[zhuguohun](https://sourceforge.net/u/zhuguohun/)** wrote on [Sunday, February 13, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11):

I Compile the FreeRtos with codewarrior, there a problem after simulate, it is always fail on debug when execute the user task coding:  
&nbsp; undefined instruction  
Why?  
&nbsp;&nbsp;

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 13, 2005, 6:39pm UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/2 "2005-02-13T18:39:49Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Sunday, February 13, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11/3972):

Unfortunately I am not familiar with CodeWarrior.&nbsp; Is it a GUI for the GCC compiler - as per CrossWorks?&nbsp; If so then how is the linker file and startup code produced?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 14, 2005, 5:46am UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/3 "2005-02-14T05:46:47Z")

</div>

**[zhuguohun](https://sourceforge.net/u/zhuguohun/)** wrote on [Monday, February 14, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11/b843):

Firstly compiler the command line is below  
-info totals -entry 0x00000000 -ro-base 0X00000000 -rw-base 0X40000000 -first VECTORS.O(Startup)

Secondly I try to debug and puzzle  
when the taskYIELD is called (SWI)  
&nbsp; but the function  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void vPortYieldProcessor( void ) \_\_irq;  
&nbsp; has no responsed,  
&nbsp; in other words, the function  
&nbsp;&nbsp;&nbsp; portRESTORE\_CONTEXT&nbsp; was calling but the function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portSAVE\_CONTEXT&nbsp; has never run.

So I guess the portSAVE\_CONTEXT should be call before portRESTORE\_CONTEXT, is ture or false?  
Thank you again

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 14, 2005, 8:23am UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/4 "2005-02-14T08:23:20Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, February 14, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11/b843/5d69):

Although you don’t say - from the command line and the \_\_irq extension I am guessing that CodeWarrior is not a GCC wrapper GUI.

\>Secondly I try to debug and puzzle  
\>when the taskYIELD is called (SWI)  
\>but the function  
\>void vPortYieldProcessor( void ) \_\_irq;  
\>has no responsed,

Has the SWI interrupt handler been installed.&nbsp; Does the SWI vector point to the vPortYieldProcessor() function.&nbsp; This should be set up in your startup code.

\>So I guess the portSAVE\_CONTEXT should be  
\>call before portRESTORE\_CONTEXT, is ture or  
\>false?

When the scheduler is initially started the stack is already set up, so \*only\* portRESTORE\_CONTEXT should be called.

During a context switch when the scheduler is running both should be called.

Thank you again

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 14, 2005, 12:55pm UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/5 "2005-02-14T12:55:45Z")

</div>

**[zhuguohun](https://sourceforge.net/u/zhuguohun/)** wrote on [Monday, February 14, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11/3d72):

Sorry to say the CodeWarrior, it is not the Gui for Gcc,  
&nbsp; Would you like give me you email, I send the code which modified by mine, and maybe you can point how to solve the problem.  
Thank you.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 14, 2005, 1:04pm UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/6 "2005-02-14T13:04:00Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Monday, February 14, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11/3d72/cd9f):

If you send the code to the email address available on the Contacts page of the [FreeRTOS.org](http://FreeRTOS.org) WEB site I can have a look - but I don’t have CodeWarrior and cannot therefore support it directly.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 15, 2005, 7:24am UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/7 "2005-02-15T07:24:15Z")

</div>

**[zhuguohun](https://sourceforge.net/u/zhuguohun/)** wrote on [Tuesday, February 15, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11/6171):

Thank you, I have send the code to you, please check it.  
when goto my task code  
the pxCurrentTCB is  
&nbsp;&nbsp; HeapSTRUCT\_SIZE&nbsp;&nbsp;&nbsp; 0x8  
&nbsp;&nbsp; ulCriticalnesting&nbsp;&nbsp;&nbsp; 0x0  
&nbsp;&nbsp; pxCurrentTCB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x40000180  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pxTopOfStack&nbsp; 0x40000388&nbsp; value=0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pxStack&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x400001D0&nbsp; value=00xA5A5A5A5  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .uStackDepth&nbsp;&nbsp;&nbsp; 0x80  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pcTaskName&nbsp;&nbsp;&nbsp; "LED"&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ucPriority&nbsp;&nbsp;&nbsp; .  
&nbsp;&nbsp;&nbsp; .XGenericListItem  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .xItemValue&nbsp;&nbsp;&nbsp; 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pxNext&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x4000008c  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pxPrevious&nbsp;&nbsp;&nbsp; 0x4000008c  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pvOwner&nbsp;&nbsp;&nbsp; 0x40000180  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pxContainer&nbsp;&nbsp;&nbsp; 0x40000080  
&nbsp;&nbsp;&nbsp; .xEventListItem  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .xItemValue&nbsp;&nbsp;&nbsp; 3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pxNext&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pxPrevious&nbsp;&nbsp;&nbsp; 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pvOwner&nbsp;&nbsp;&nbsp; 0x40000180  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .pvContainer&nbsp;&nbsp;&nbsp; 0  
&nbsp;&nbsp;&nbsp; .ucTCBNumber&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0

Current Register values  
&nbsp;&nbsp;&nbsp; r0=0  
&nbsp;&nbsp;&nbsp; r1=0x01010101  
&nbsp;&nbsp;&nbsp; r2=0x02020202  
&nbsp;&nbsp;&nbsp; r3=0x03030303  
&nbsp;&nbsp;&nbsp; r4=0x04040404  
&nbsp;&nbsp;&nbsp; r5=0x05050505  
&nbsp;&nbsp;&nbsp; r6=0x06060606  
&nbsp;&nbsp;&nbsp; r7=0x07070707  
&nbsp;&nbsp;&nbsp; r8=0x08080808  
&nbsp;&nbsp;&nbsp; r9=0x09090909  
&nbsp;&nbsp;&nbsp; r10=0x10101010  
&nbsp;&nbsp;&nbsp; r11=0x11111111  
&nbsp;&nbsp;&nbsp; r12=0x12121212  
&nbsp;&nbsp;&nbsp; r13=0x4000003cc  
&nbsp;&nbsp;&nbsp; r14=0xAAAAAAAA  
&nbsp;&nbsp;&nbsp; pc=0x00001E0  
&nbsp;&nbsp;&nbsp; cpsr=nzcvqifT\_SYS  
&nbsp;&nbsp;&nbsp; spsr=Unavailable

LedTask  
000001e0&nbsp;&nbsp;&nbsp; [0xe92d4070] \* stmfd&nbsp;&nbsp;&nbsp; r13!,{r4-r6,r14}  
000001e4&nbsp;&nbsp;&nbsp; [0xe59f0124]&nbsp;&nbsp; ldr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r0,0x00000310 ; = #0xe002c000  
000001e8&nbsp;&nbsp;&nbsp; [0xe5901000]&nbsp;&nbsp; ldr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r1,[r0,#0]  
000001ec&nbsp;&nbsp;&nbsp; [0xe5801000]&nbsp;&nbsp; str&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r1,[r0,#0]  
000001f0&nbsp;&nbsp;&nbsp; [0xe5901004]&nbsp;&nbsp; ldr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r1,[r0,#4]  
000001f4&nbsp;&nbsp;&nbsp; [0xe5801004]&nbsp;&nbsp; str&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r1,[r0,#4]  
000001f8&nbsp;&nbsp;&nbsp; [0xe2406c40]&nbsp;&nbsp; sub&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r6,r0,#0x4000  
000001fc&nbsp;&nbsp;&nbsp; [0xe5960008]&nbsp;&nbsp; ldr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r0,[r6,#8]  
00000200&nbsp;&nbsp;&nbsp; [0xe3800f54]&nbsp;&nbsp; orr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r0,r0,#0x150  
00000204&nbsp;&nbsp;&nbsp; [0xe5860008]&nbsp;&nbsp; str&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r0,[r6,#8]

---------------------------------------  
step next&nbsp; --\>error occur  
------------------------------------------  
00000004&nbsp;&nbsp;&nbsp; [0xe59ff018]&nbsp;&nbsp; ldr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pc,UndefinedAddr ; = #UndefinedAddr

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [February 15, 2005, 9:07am UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/8 "2005-02-15T09:07:19Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, February 15, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11/1722):

Hi,

Without the tools all I can do is look at the source code to see if I can see anything wrong.&nbsp; From what I can see you have based your CodeWarrior project on the Keil demo, making the changes listed in your last post.

Current Register values  
r0=0  
r1=0x01010101  
r2=0x02020202  
r3=0x03030303  
r4=0x04040404  
r5=0x05050505  
r6=0x06060606  
r7=0x07070707  
r8=0x08080808  
r9=0x09090909  
r10=0x10101010  
r11=0x11111111  
r12=0x12121212  
r13=0x4000003cc  
r14=0xAAAAAAAA

These all appear to be what is expected.&nbsp; The registers have their default initial values which shows that the first RESTORE\_CONTEXT has worked as expected.

pc=0x00001E0

Again this looks correct, the first instruction in your LED task.

portmacro.h&nbsp;&nbsp; —\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; extern \_\_inline void&nbsp; portSAVE\_CONTEXT(void);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; extern \_\_inline void&nbsp; portRESTORE\_CONTEXT(void);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_\_inline void portENABLE\_INTERRUPTS(void)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \_\_inline void portDISABLE\_INTERRUPTS(void)

These are now defined in the ISR\_Support.s file.&nbsp; The context save/restore macros \*MUST\* be inline and it might be that the compiler will ignore the \_\_inline keywork in this case.&nbsp; Can you check the assembly output to make sure that the portENABLE/DISABLE\_CONTEXT macros are really being inlined and there is no function call being generated by the compiler.

You appear to have setup the stack for the supervisor and IRQ modes.&nbsp; Does your task start in System mode?&nbsp; I presume this is what nzcvqifT\_SYS means.

Also are you running in ARM mode only, or ARM/THUMB interwork mode?&nbsp; It appears that the code is compiler for ARM mode (32bit) but I cannot tell from the nzcvqifT\_SYS value whether you are in ARM or THUMB mode.&nbsp; Does the T in nzcvqifT\_SYS&nbsp; mean THUMB mode?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [February 15, 2005, 1:00pm UTC](https://forums.freertos.org/t/codewarrior-compile-problem/3529/9 "2005-02-15T13:00:50Z")

</div>

**[zhuguohun](https://sourceforge.net/u/zhuguohun/)** wrote on [Tuesday, February 15, 2005](https://sourceforge.net/p/freertos/discussion/382005/thread/9c568d28/#ae11/7b0f):

Thank you for your help.  
-----------------------------------------------  
These are now defined in the ISR\_Support.s file. The context save/restore macros \*MUST\* be inline and it might be that the compiler will ignore the \_\_inline keywork in this case. Can you check the assembly output to make sure that the portENABLE/DISABLE\_CONTEXT macros are really being inlined and there is no function call being generated by the compiler.  
-----------------------------------------------  
I disassemble the function  
&nbsp; vPortISRStartFirstTask  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portRESTORE\_CONTEXT  
vPortYieldProcessor  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x00000004:&nbsp;&nbsp;&nbsp; e92d500f&nbsp;&nbsp;&nbsp; .P-.&nbsp;&nbsp;&nbsp; STMFD&nbsp;&nbsp;&nbsp; r13!,{r0-r3,r12,r14}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x00000008:&nbsp;&nbsp;&nbsp; ebfffffe&nbsp;&nbsp;&nbsp; …&nbsp;&nbsp;&nbsp; BL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portSAVE\_CONTEXT  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x0000000c:&nbsp;&nbsp;&nbsp; ebfffffe&nbsp;&nbsp;&nbsp; …&nbsp;&nbsp;&nbsp; BL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vTaskSwitchContext  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x00000010:&nbsp;&nbsp;&nbsp; ebfffffe&nbsp;&nbsp;&nbsp; …&nbsp;&nbsp;&nbsp; BL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portRESTORE\_CONTEXT  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x00000014:&nbsp;&nbsp;&nbsp; e8bd500f&nbsp;&nbsp;&nbsp; .P…&nbsp;&nbsp;&nbsp; LDMFD&nbsp;&nbsp;&nbsp; r13!,{r0-r3,r12,r14}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0x00000018:&nbsp;&nbsp;&nbsp; e25ef004&nbsp;&nbsp;&nbsp; …^.&nbsp;&nbsp;&nbsp; SUBS&nbsp;&nbsp;&nbsp;&nbsp; pc,r14,#4  
&nbsp;  
so it is not the truely inline  
-----------------------------------------  
…I presume this is what nzcvqifT\_SYS means  
---------------------------------------------  
the last init stack coding&nbsp; as belwo  
…  
;&nbsp;&nbsp;&nbsp; /\* We want to start in supervisor mode.&nbsp; Operation will switch to system  
;&nbsp;&nbsp;&nbsp; mode when the first task starts. \*/  
&nbsp;&nbsp; msr&nbsp;&nbsp; CPSR\_c, #MODE\_SVC|I\_BIT|F\_BIT  
&nbsp;&nbsp; mov&nbsp;&nbsp; sp, r0

------------------------------------  
Also are you running in ARM mode only, or ARM/THUMB interwork mode  
------------------------------------  
Yes, the code run in ARM only
