question about thread on rtems for pc386's context

Joel Sherrill joel.sherrill at oarcorp.com
Tue Oct 9 14:06:07 UTC 2007


阎淼 wrote:
> Hi,
>
>    In RTEMS ABI for x86 architecture, eax, ecx, edx are scratch
> registers.  RTEMS do not save the contents of these three registers
> when excuting rtems directives. In other words, the content of eax,
> ecx, edx may be changed after a function call( call and ret
> instruction), and complier knows this well to generate correct code.
> So EAX, ECX, EDX are exactly those missing from Context_Control
> structure, other general registers stay in there( segment registers do
> not change ).  As for ISR, the execution flow of rtems directives is
> interruptted, so eax, ecx, edx must be saved to further restore
> execution flow. Since rtems directives do not change the content of
> other registers( if used, they will be restored upon ret), so only the
> three registers need to be saved. Correct me if I were wrong.
>   
That's the idea.  Since the context switch is a subroutine
call, it gets to assume that eax, ecx, and edx do NOT have
to be saved.  This saves time in thread->thread context
switches and saves memory.  As you note, a preempt
from an ISR must save these registers.

The Porting Guide tries to explain this.

http://www.rtems.org/onlinedocs/releases/rtemsdocs-4.7.1/share/rtems/html/porting/porting00046.html

--joel
> 2007/10/8, Yu Chen <chyyuu at gmail.com>:
>   
>> hi,
>>  From the source code, in Thread_Control_struct, the field
>> 'Context_Control                       Registers' means the context of
>> this thread. This field is hardware related. in RTEMS for pc 386, I
>> found the define of this field is:
>> typedef struct {
>>  uint32_t    eflags;   /* extended flags register                   */
>>  void       *esp;      /* extended stack pointer register           */
>>  void       *ebp;      /* extended base pointer register            */
>>  uint32_t    ebx;      /* extended bx register                      */
>>  uint32_t    esi;      /* extended source index register            */
>>  uint32_t    edi;      /* extended destination index flags register */
>> }   Context_Control;
>>
>> My question is: why rtems didn't store the other i386 registers (such
>> as eax, ecx...) when switching the thread context? the other registers
>> in threads needn't save &restore?
>>
>> and the similar question is: in irq_asm.S , rtems_irq_prologue_ ## _vector :
>>
>> SYM (rtems_irq_prologue_ ## _vector ):             \
>>        pushl   eax             ; \
>>        pushl   ecx             ; \
>>        pushl   edx             ; \
>>        movl    $ _vector, ecx  ; \
>>        jmp   SYM (_ISR_Handler) ;
>> ....
>>        popl    edx
>>        popl    ecx
>>        popl    eax
>>        iret
>>
>> why in irq process, rtems didn't save &restore  the other i386 registers ?
>>
>> Thanks!
>>
>> --
>> Best Regards
>> ==============================================
>> Chen Yu
>> Laboratory of Pervasive Computing,
>> Dept. of Computer Science and Technology
>> Tsinghua University, Beijing 100084, P.R. China
>> E-Mail: mailto:yuchen at tsinghua.edu.cn  chyyuu at gmail.com
>> ==============================================
>> _______________________________________________
>> rtems-users mailing list
>> rtems-users at rtems.com
>> http://rtems.rtems.org/mailman/listinfo/rtems-users
>>
>>     
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.com
> http://rtems.rtems.org/mailman/listinfo/rtems-users
>   




More information about the users mailing list