Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


x86, InitialiseStack and FIRST_CONTEXT

Posted by Tim Lewis on June 5, 2012
So I am working on a native x86 port (both 32-bit and x64) and am not clear on what should be on the task stack in InitialiseStack. In particular, which stack frame am I trying to create? In this particular case, I cannot use an interrupt to do the yield (because this port will also be run in a hosted environment where software INTs are restricted), so I'll be using a CALL (no in-line assembly for the 64-bit Visual Studio compiler).

I started by copying the 16-bit DOS port and am very familiar with that environment.

Also, what is the traditional stance on saving/restoring floating-point regs? Don't use? Flag as being used? Flag when first FP exception occurs? Always save? The current Windows emulator port avoids this by using Windows threads.

Thanks, Tim

RE: x86, InitialiseStack and FIRST_CONTEXT

Posted by Richard on June 5, 2012
Interesting. So is this to run bare metal on the X86? The windows simulator is just that, it runs the FreeRTOS scheduler and allows that to select which tasks to run when depending on their priority, but when the scheduler itself runs is still ultimately under the control of Windows as it runs in a Windows thread. Hence the very non real time performance. It is a great development and test bed, but not a port in itself.

There is no real fixed way of performing the floating point switching. The obvious way is to save and restore all the time for every task. A more efficient way to allow tasks to register their interest in the floating point context, and then only do it for those tasks (often into a separate array, rather than onto the stack). The most efficient way, if only a few tasks are using the FPU, is to turn the FPU off, and then do the context switching (and re-enabling) of the FPU in the exception that occurs when a task actually tries to use a floating point instruction. I'm not familiar enough to with the x86 to know if that last way is even possible - but I think it is how Linux does it so I'm guessing it must be.

There are trade offs to each of the FPU saving techniques, and which is best depends on how many tasks are accessing the FPU, and how often those tasks actually use the FPU.


RE: x86, InitialiseStack and FIRST_CONTEXT

Posted by Tim Lewis on June 5, 2012
It is designed to run bare-metal and in a very specialized hosted environment. The only difference in them is how the timer tick gets delivered.

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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner