update for HEAD-2003091401
[reactos.git] / lib / kernel32 / thread / i386 / fiber.S
1 /* $Id$
2  *
3  * COPYRIGHT:  See COPYING in the top level directory
4  * PROJECT:    ReactOS system libraries
5  * FILE:       lib/kernel32/thread/i386/fiber.S
6  * PURPOSE:    Fiber context switch code for the x86 architecture
7  * PROGRAMMER: KJK::Hyperion <noog@libero.it>
8  *
9  * UPDATE HISTORY:
10  *             28/05/2003 - created
11  *
12  */
13
14 .extern _DbgPrint
15
16 .globl _SwitchToFiber@4
17
18 ErrStr:
19  .ascii \
20 "(KERNEL32:" __FILE__ ") Saving and restoring the floating point context \
21 currently unimplemented\n\0"
22
23 _SwitchToFiber@4:
24
25  movl %fs:0x18, %ecx           /* Teb = NtCurrentTeb() */
26
27  /* get the current fiber */
28  movl 0x10(%ecx), %eax         /* Fiber = Teb->Tib.Fib.FiberData */
29
30  /* store the volatile context of the current fiber */
31  movl 0x0(%ecx),   %edx
32  movl %edx,        0x4(%eax)   /* Fiber->ExceptionList = Teb->ExceptionList */
33  movl 0x4(%ecx),   %edx
34  movl %edx,        0x8(%eax)   /* Fiber->StackBase = Teb->StackBase */
35  movl 0x8(%ecx),   %edx
36  movl %edx,        0xC(%eax)   /* Fiber->StackLimit = Teb->StackLimit */
37  movl 0xE0C(%ecx), %edx
38  movl %edx,        0x10(%eax)  /* Fiber->StackBottom = Teb->DeallocationStack */
39  movl 0x0(%esp),   %edx
40  movl %edx,        0x18(%eax)  /* Fiber->Eip = [esp + 0] */
41  movl %esp,        %edx
42  addl $0x8,        %edx        
43  movl %edx,        0x1C(%eax)  /* Fiber->Esp = esp + 8 */
44  movl %ebp,        0x20(%eax)  /* Fiber->Ebp = ebp */
45  movl %ebx,        0x24(%eax)  /* Fiber->Ebx = ebx */
46  movl %esi,        0x28(%eax)  /* Fiber->Esi = edi */
47  movl %edi,        0x2C(%eax)  /* Fiber->Edi = esi */
48
49  testl $1, 0x14(%eax)
50  jz l_NoFloatSave
51  
52  /* save the floating point context */
53  /* TODO */
54  pushl ErrStr
55  call _DbgPrint
56  popl %ecx
57  
58 l_NoFloatSave:
59
60  /* switch to the specified fiber */
61  movl 0x4(%esp), %eax          /* Fiber = lpFiber */
62  movl %eax, 0x10(%ecx)         /* Teb->Tib.FiberData = Fiber */
63
64  /* restore the volatile context of the specified fiber */
65  movl 0x4(%eax),   %edx
66  movl %edx,        0x0(%ecx)   /* Teb->ExceptionList = Fiber->ExceptionList */
67  movl 0x8(%eax),   %edx
68  movl %edx,        0x4(%ecx)   /* Teb->StackBase = Fiber->StackBase */
69  movl 0xC(%eax),   %edx
70  movl %edx,        0x8(%ecx)   /* Teb->StackLimit = Fiber->StackLimit */
71  movl 0x10(%eax),  %edx
72  movl %edx,        0xE0C(%ecx) /* Teb->StackBottom = Fiber->DeallocationStack */
73  movl 0x18(%eax),  %edx        /* edx = Fiber->Eip */
74  movl 0x1C(%eax),  %esp        /* esp = Fiber->Esp */
75  movl 0x20(%eax),  %ebp        /* ebp = Fiber->Ebp */
76  movl 0x24(%eax),  %ebx        /* ebx = Fiber->Ebx */
77  movl 0x28(%eax),  %esi        /* esi = Fiber->Esi */
78  movl 0x2C(%eax),  %edi        /* edi = Fiber->Edi */
79
80  testb $1, 0x14(%eax)
81  jz l_NoFloatSave
82  
83  /* restore the floating point context */
84  /* TODO */
85  pushl ErrStr
86  call _DbgPrint
87  popl %ecx
88  
89 l_NoFloatRestore:
90
91  /* jump to the saved program counter */
92  jmp *%edx
93
94 /* EOF */