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

Re: thread switch



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?
>
The from and to pointers are stored on the stack relative to the frame
pointer so after the assignment to ebp, the 'to' pointer will have a
different value and the correct value wouldn't be assigned to esp.

Follow-Ups: References: