// Saved registers for kernel context switches. // Don't need to save all the %fs etc. segment registers, // because they are constant across kernel contexts. // Save all the regular registers so we don't need to care // which are caller save, but not the return register %eax. // (Not saving %eax just simplifies the switching code.) // The layout of context must match code in swtch.S. structcontext { int eip; int esp; int ebx; int ecx; int edx; int esi; int edi; int ebp; };
//PAGEBREAK: 17 // Saved registers for kernel context switches. // Don't need to save all the segment registers (%cs, etc), // because they are constant across kernel contexts. // Don't need to save %eax, %ecx, %edx, because the // x86 convention is that the caller has saved them. // Contexts are stored at the bottom of the stack they // describe; the stack pointer is the address of the context. // The layout of the context matches the layout of the stack in swtch.S // at the "Switch stacks" comment. Switch doesn't save eip explicitly, // but it is on the stack and allocproc() manipulates it. structcontext { uint edi; uint esi; uint ebx; uint ebp; uint eip; };
# Context switch # # void swtch(struct context **old, struct context *new); # # Save the current registers on the stack, creating # a struct context, and save its address in *old. # Switch stacks to new and pop previously-saved registers.