[PATCH] score/i386: Add context switch restore external symbol as a marker.

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jul 22 06:10:16 UTC 2016



On 22/07/16 08:03, Sebastian Huber wrote:
>
>
> On 22/07/16 07:51, Chris Johns wrote:
>> On 22/07/2016 15:39, Sebastian Huber wrote:
>>> On 22/07/16 07:30, Chris Johns wrote:
>>>> On 22/07/2016 15:26, Sebastian Huber wrote:
>>>>> Could we please use the _CPU_* prefix only for stuff defined by 
>>>>> the CPU
>>>>> port interface and use something like _I386_* for things that are
>>>>> specific to a particular architecture.
>>>>
>>>> I would like this to be added to the formal _CPU_* port interface.
>>>> Without the marker the CPU will not able to support proper debugging.
>>>>
>>>> I see the patch as correct.
>>>
>>> To me this looks quite x86 specific.
>>
>> This is the current target I am working on and the only one I have 
>> looked at.
>
> In order to move it to the CPU port area it should work on at least 
> two architectures from my point of view. The MIPS and LM32 use already 
> a _CPU_Context_switch_restore symbol. Is this similar to your x86 use 
> case? CPU port defines, functions, etc. should be documented in 
> "cpukit/score/cpu/no_cpu/rtems/score/cpu.h".
>
>>
>>> How would you set and use this
>>> marker on ARM, PowerPC and SPARC for example?
>>
>> I have not looked at the ARM in detail and would have to look up the 
>> instructions but a guess would be 'L_restore:' in arm/cpu_asm.S. I do 
>> not use the PowerPC or SPARC.
>>
>> The requirement is the marker is the address to set the PC (IP) along 
>> with the registers held in the TCB so a valid stack frame exists that 
>> a DWARF unwind'er can unwind. It must exist somewhere in each system 
>> or the context could not be restored.
>>
>> Chris
>
> Why can't you use the PC stored in the context along with the saved 
> registers? This is how the thread debug support works on ARM, PowerPC 
> and SPARC. Threads that did never run have an PC set to 
> _Thread_Handler(). They never called _CPU_Context_switch(), so your 
> marker would not work.
>

On i386 the PC is stored on the stack frame:

#define _CPU_Context_Initialize( _the_context, _stack_base, _size, \
                                    _isr, _entry_point, _is_fp, 
_tls_area ) \
   do { \
     uint32_t   _stack; \
     \
     (void) _is_fp; /* avoid warning for being unused */ \
     if ( (_isr) ) (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_OFF; \
     else          (_the_context)->eflags = CPU_EFLAGS_INTERRUPTS_ON; \
     \
     _stack  = ((uint32_t)(_stack_base)) + (_size); \
     _stack &= ~ (CPU_STACK_ALIGNMENT - 1); \
     _stack -= 2*sizeof(proc_ptr*); /* see above for why we need to do 
this */ \
     *((proc_ptr *)(_stack)) = (_entry_point); \
     (_the_context)->ebp     = (void *) 0; \
     (_the_context)->esp     = (void *) _stack; \
   } while (0)

The stack pointer is part of the context. If you retrieve the PC from 
here it should work for all threads.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.




More information about the devel mailing list