2.2.1.1.1.1. Linux 2.6.8 80x86 Processor Context Switching
#define __SAVE_ALL \
        cld; \
        pushl %es; \
        pushl %ds; \
        pushl %eax; \
        pushl %ebp; \
        pushl %edi; \
        pushl %esi; \
        pushl %edx; \
        pushl %ecx; \
        pushl %ebx; \
        movl $(__USER_DS), %edx; \
        movl %edx, %ds; \
        movl %edx, %es;

#define __RESTORE_INT_REGS \
        popl %ebx;      \
        popl %ecx;      \
        popl %edx;      \
        popl %esi;      \
        popl %edi;      \
        popl %ebp;      \
        popl %eax

#define __RESTORE_REGS  \
        __RESTORE_INT_REGS; \
111:    popl %ds;       \
222:    popl %es;       \
.section .fixup,"ax";   \
444:    movl $0,(%esp); \
        jmp 111b;       \
555:    movl $0,(%esp); \
        jmp 222b;       \
.previous;              \
.section __ex_table,"a";\
        .align 4;       \
        .long 111b,444b;\
        .long 222b,555b;\
.previous

#define __RESTORE_ALL   \
        __RESTORE_REGS  \
        addl $4, %esp;  \
333:    iret;           \
.section .fixup,"ax";   \
666:    sti;            \
        movl $(__USER_DS), %edx; \
        movl %edx, %ds; \
        movl %edx, %es; \
        pushl $11;      \
        call do_exit;   \
.previous;              \
.section __ex_table,"a";\
        .align 4;       \
        .long 333b,666b;\
.previous

#define SAVE_ALL \
        __SAVE_ALL; \
        __SWITCH_KERNELSPACE;

#define RESTORE_ALL \
        __SWITCH_USERSPACE; \
        __RESTORE_ALL;