Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


void casts in save/restore context macros

Posted by Stephen Cleary on March 30, 2011
In the GCC/ARM7_AT91SAM7S port, both the portSAVE_CONTEXT and portRESTORE_CONTEXT macros declare variables (pxCurrentTCB and ulCriticalNesting) that are cast to void, presumably to avoid a compiler warning.

However, since the variables are declared volatile, the compiler is dutifully generating code to read them and discard the values. Here's the disassembly for vPortISRStartFirstTask (which only calls portRESTORE_CONTEXT), as compiled by Rowley (gcc 4.4.5) in release mode:

E59F0240 ldr r0, 0x00000248 // First line of portRESTORE_CONTEXT macro
E5900000 ldr r0, [r0]
E590E000 ldr lr, [r0]
E59F0238 ldr r0, 0x0000024C
E8BE0002 ldm lr!, {r1}
E5801000 str r1, [r0]
E8BE0001 ldm lr!, {r0}
E169F000 msr spsr_cf r0
E8DE7FFF ldmia lr, {r0-lr}^
E1A00000 mov r0, r0
E59EE03C ldr lr, [lr, #0x3C]
E25EF004 subs pc, lr, #4 // Last line of portRESTORE_CONTEXT macro
E59F300C ldr r3, 0x00000044
E5933000 ldr r3, [r3]
E59F3008 ldr r3, 0x00000048
E5933000 ldr r3, [r3]
E12FFF1E bx lr // Start of standard epilogue (also unnecessary)
00000000 andeq r0, r0, r0
00000000 andeq r0, r0, r0

The portSAVE_CONTEXT macro has a similar problem, and actually executes the instructions.

I believe __attribute__((unused)) and possibly also __attribute__((noreturn)) could be used to reduce some of the generated code (and make for slightly faster context switches since portSAVE_CONTEXT currently always executes 4 noops).

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists