public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] get context on the synthetic target
@ 2008-05-22 15:28 trollepi jj
  2008-05-27 10:29 ` Bart Veer
  0 siblings, 1 reply; 2+ messages in thread
From: trollepi jj @ 2008-05-22 15:28 UTC (permalink / raw)
  To: ecos-discuss


Hi,
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]));\
	}

Thanks for your future reply.
Best regards, jjp
_________________________________________________________________
Sur Windows Live Ideas, découvrez en exclusivité de nouveaux services en ligne... si nouveaux qu'ils ne sont pas encore sortis officiellement sur le marché !
http://ideas.live.com

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [ECOS] get context on the synthetic target
  2008-05-22 15:28 [ECOS] get context on the synthetic target trollepi jj
@ 2008-05-27 10:29 ` Bart Veer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Veer @ 2008-05-27 10:29 UTC (permalink / raw)
  To: trollepi jj; +Cc: ecos-discuss

>>>>> " " == 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-05-27 10:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-22 15:28 [ECOS] get context on the synthetic target trollepi jj
2008-05-27 10:29 ` Bart Veer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).