[Prev][Next][Index][Thread]

Re[3]: thread switch



Hello cool,

Saturday, May 12, 2001, 11:49:16 AM, you wrote:

c> Hello David,

c> Friday, May 11, 2001, 7:07:08 PM, you wrote:

DW>> On Fri, May 11, 2001 at 12:05:00PM +0800, cool wrote:
>>> Hello oskit-users,
>>> 
>>>   I am testing my switching code,and I use the following code
>>> void switchto(struct type_thread  *from,struct type_thread  *to)
>>> {
>>>         printf("Now in the switchto function\n");
>>>         getchar();
>>>         asm volatile("movl %%eax,%0\n\t"        \
>>>                      "movl %%ebx,%1\n\t"        \
>>>                         "movl %%ecx,%2\n\t"             \
>>>                         "movl %%edx,%3\n\t"             \
>>>                         "movl %4,%%eax\n\t"             \
>>>                         "movl %5,%%ebx\n\t"             \
>>>                         "movl %6,%%ecx\n\t"             \
>>>                         "movl %7,%%edx\n\t"             \
>>>                        :"=m"(from->context.eax),"=m"(from->context.ebx),       \
>>>                         "=m"(from->context.ebp),"=m"(from->context.edx):       \
>>>                         "m"(to->context.eax),"m"(to->context.ebx),         \
>>>                         "m"(to->context.ecx),"m"(to->context.edx) );
>>>         printf("ok for first setction of asm code\n");
>>>         getchar();
>>>         asm volatile("movl %%esi,%0\n\t"        \
>>>                      "movl %%edi,%1\n\t"        \
>>>                         "movl %%ebp,%2\n\t"             \
>>>                         "movl %%esp,%3\n\t"             \
>>>                         "movl %4,%%esi\n\t"             \
>>>                         "movl %5,%%edi\n\t"             \
>>>                         "movl %6,%%ebp\n\t"             \
>>>                         "movl %7,%%esp\n\t"             \
>>>                 :"=m"(from->context.esi),"=m"(from->context.edi),       \
>>>                         "=m"(from->context.ebp),"=m"(from->context.esp):       \
>>>                         "m"(to->context.esi),"m"(to->context.edi),         \
>>>                         "m"(to->context.ebp),"m"(to->context.esp) );  
>>> but when I use it,the monitor screen crashes.
>>> I don't know why?
>>> Could anyone point out my fault?
>>>
DW>> The from and to pointers are stored on the stack relative to the frame
DW>> pointer so after the assignment to ebp, the 'to' pointer will have a
DW>> different value and the correct value wouldn't be assigned to esp.

c> You are right, I tried to add the clobbered register after the asm
c> code,everything is ok now.
c> Thanks for your help!

But I am still a litter confused about the storage allocation.
If I declare those registers to be clobbered registers,How would the
compiler represent the variable from and to?
Thanks!


-- 
Best regards,
 cool                            mailto:hust



References: