Changeset cb0d9a0 in rtems


Ignore:
Timestamp:
Jun 9, 2017, 6:17:59 AM (3 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
7b0c74ff
Parents:
f256685
git-author:
Sebastian Huber <sebastian.huber@…> (06/09/17 06:17:59)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/09/17 06:28:46)
Message:

i386: Move _CPU_Context_Initialize()

Update #2468.

Location:
cpukit/score/cpu/i386
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/cpu/i386/cpu.c

    rf256685 rcb0d9a0  
    113113  }
    114114#endif
     115}
     116
     117/*
     118 * Stack alignment note:
     119 *
     120 * We want the stack to look to the '_entry_point' routine
     121 * like an ordinary stack frame as if '_entry_point' was
     122 * called from C-code.
     123 * Note that '_entry_point' is jumped-to by the 'ret'
     124 * instruction returning from _CPU_Context_switch() or
     125 * _CPU_Context_restore() thus popping the _entry_point
     126 * from the stack.
     127 * However, _entry_point expects a frame to look like this:
     128 *
     129 *      args        [_Thread_Handler expects no args, however]
     130 *      ------      (alignment boundary)
     131 * SP-> return_addr return here when _entry_point returns which (never happens)
     132 *
     133 *
     134 * Hence we must initialize the stack as follows
     135 *
     136 *         [arg1          ]:  n/a
     137 *         [arg0 (aligned)]:  n/a
     138 *         [ret. addr     ]:  NULL
     139 * SP->    [jump-target   ]:  _entry_point
     140 *
     141 * When Context_switch returns it pops the _entry_point from
     142 * the stack which then finds a standard layout.
     143 */
     144
     145void _CPU_Context_Initialize(
     146  Context_Control *the_context,
     147  void *_stack_base,
     148  size_t _size,
     149  uint32_t _isr,
     150  void (*_entry_point)( void ),
     151  bool is_fp,
     152  void *tls_area
     153)
     154{
     155  uint32_t _stack;
     156
     157  (void) is_fp; /* avoid warning for being unused */
     158
     159  if ( _isr ) {
     160    the_context->eflags = CPU_EFLAGS_INTERRUPTS_OFF;
     161  } else {
     162    the_context->eflags = CPU_EFLAGS_INTERRUPTS_ON;
     163  }
     164
     165  _stack  = ((uint32_t)(_stack_base)) + (_size);
     166  _stack &= ~ (CPU_STACK_ALIGNMENT - 1);
     167  _stack -= 2*sizeof(proc_ptr*); /* see above for why we need to do this */
     168  *((proc_ptr *)(_stack)) = (_entry_point);
     169  the_context->ebp     = (void *) 0;
     170  the_context->esp     = (void *) _stack;
    115171}
    116172
  • cpukit/score/cpu/i386/rtems/score/cpu.h

    rf256685 rcb0d9a0  
    434434#ifndef ASM
    435435
    436 /*
    437  * Stack alignment note:
    438  *
    439  * We want the stack to look to the '_entry_point' routine
    440  * like an ordinary stack frame as if '_entry_point' was
    441  * called from C-code.
    442  * Note that '_entry_point' is jumped-to by the 'ret'
    443  * instruction returning from _CPU_Context_switch() or
    444  * _CPU_Context_restore() thus popping the _entry_point
    445  * from the stack.
    446  * However, _entry_point expects a frame to look like this:
    447  *
    448  *      args        [_Thread_Handler expects no args, however]
    449  *      ------      (alignment boundary)
    450  * SP-> return_addr return here when _entry_point returns which (never happens)
    451  *
    452  *
    453  * Hence we must initialize the stack as follows
    454  *
    455  *         [arg1          ]:  n/a
    456  *         [arg0 (aligned)]:  n/a
    457  *         [ret. addr     ]:  NULL
    458  * SP->    [jump-target   ]:  _entry_point
    459  *
    460  * When Context_switch returns it pops the _entry_point from
    461  * the stack which then finds a standard layout.
    462  */
    463 
    464 
    465 
    466 #define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
    467                                    _isr, _entry_point, _is_fp, _tls_area ) \
    468   do { \
    469     uint32_t   _stack; \
    470     \
    471     (void) _is_fp; /* avoid warning for being unused */ \
    472     if ( (_isr) ) (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_OFF; \
    473     else          (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_ON; \
    474     \
    475     _stack  = ((uint32_t)(_stack_base)) + (_size); \
    476         _stack &= ~ (CPU_STACK_ALIGNMENT - 1); \
    477     _stack -= 2*sizeof(proc_ptr*); /* see above for why we need to do this */ \
    478     *((proc_ptr *)(_stack)) = (_entry_point); \
    479     (_the_context)->ebp     = (void *) 0; \
    480     (_the_context)->esp     = (void *) _stack; \
    481   } while (0)
     436void _CPU_Context_Initialize(
     437  Context_Control *the_context,
     438  void *stack_area_begin,
     439  size_t stack_area_size,
     440  uint32_t new_level,
     441  void (*entry_point)( void ),
     442  bool is_fp,
     443  void *tls_area
     444);
    482445
    483446#define _CPU_Context_Restart_self( _the_context ) \
Note: See TracChangeset for help on using the changeset viewer.