question about thread on rtems for pc386's context

阎淼 yanmiaobest at gmail.com
Tue Oct 9 01:52:56 CDT 2007


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.

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
>



More information about the rtems-users mailing list