This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: get context on the synthetic target


>>>>> " " == trollepi jj <jackoaway@hotmail.com> writes:

     > I need to get the context of the current thread at anytime
     > (important CPU registers, like esp, ebp, ebx, esi,...) on the
     > synthetic target I find the HAL_SavedRegisters and I find some
     > discussions on the mailing list giving explanations about its
     > members and how it doesn't contain all x86 registers. But i
     > don't find anything interesting for me. So, can I get the CPU
     > registers with an ecos macro or do I need to write a little
     > macro like that

     > #define __get_thread_context(__context__){\
     > 		asm(    "mov %%edi,%0 \n\t"\
     >    				"mov %%esi,%1 \n\t"\
     > 	            "mov %%ebp,%2 \n\t"\
     > 	            "mov %%esp,%3 \n\t"\
     > 	            "mov %%ebx,%4 \n\t"\
     > 	        : "=m" (__context__[S_REG_EDI]),"=m" (__context__[S_REG_ESI]),\
     > 	        "=m" (__context__[S_REG_EBP]),"=m" (__context__[S_REG_ESP]),\
     > 	        "=m" (__context__[S_REG_EBX]));\
     > 	}

HAL_SavedRegisters would not tell you anything useful about the
current context, only about the context at the time of the last
context switch. The synthetic target is not a simulator. The cpu
executes the code directly, and it will not be continually storing
shadow copies of all the registers somewhere in memory.

So yes, if you want to read these registers at any time then you will
need some inline assembler. However it is not clear that that will
provide any useful information. Registers EDI, ESI, EBP and EBX do not
hold any global state. They can be used by the compiler for anything
it feels like, so the values read by __get_thread_context() will
merely reflect the surrounding code. ESP is the only register which
holds information that might be useful for debugging purposes, and you
can get a good idea of its value in pure C code simply by taking the
address of a variable on the stack.

Bart
     
-- 
Bart Veer                                   eCos Configuration Architect
eCosCentric Limited    The eCos experts      http://www.ecoscentric.com/
Barnwell House, Barnwell Drive, Cambridge, UK.      Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]