00001
00002
00003
00004
00005
00006
00007
00008 #include <arch/ia32/cpu.h>
00009
00010 __BEGIN_SYS
00011
00012 void IA32::Context::save() volatile
00013 {
00014
00015 ASM(" pushl %ebp \n"
00016 " movl %esp, %ebp \n"
00017 " movl 8(%ebp), %esp # this \n"
00018 " addl $40, %esp # + sizeof(Context) \n"
00019 " pushl 4(%ebp) # eip \n"
00020 " pushfl \n"
00021 " pushl %eax \n"
00022 " pushl %ecx \n"
00023 " pushl %edx \n"
00024 " pushl %ebx \n"
00025 " pushl %ebp # esp \n"
00026 " pushl (%ebp) # ebp \n"
00027 " pushl %esi \n"
00028 " pushl %edi \n"
00029 " movl %ebp, %esp \n"
00030 " popl %ebp \n");
00031 }
00032
00033
00034
00035 void IA32::Context::load() const volatile
00036 {
00037 ASM(" movl 4(%esp), %esp # this \n"
00038 " popal \n"
00039 " popfl \n");
00040 }
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 void IA32::switch_context(Context * volatile * o, Context * volatile n)
00057 {
00058 ASM(" pushfl \n"
00059 " pushal \n"
00060 " movl 40(%esp), %eax # old \n"
00061 " movl %esp, (%eax) \n"
00062 " movl 44(%esp), %esp # new \n"
00063 " popal \n"
00064 " popfl \n");
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 __END_SYS