use popal/pushal for context switch
Should take fewer clock nd save esp
This commit is contained in:
parent
79c1fda419
commit
5141044c06
@ -36,12 +36,13 @@ struct cpu_state {
|
|||||||
thread, even for a user thread */
|
thread, even for a user thread */
|
||||||
uint16_t alignment_padding; /* unused */
|
uint16_t alignment_padding; /* unused */
|
||||||
uint32_t eax;
|
uint32_t eax;
|
||||||
uint32_t ebx;
|
|
||||||
uint32_t ecx;
|
uint32_t ecx;
|
||||||
uint32_t edx;
|
uint32_t edx;
|
||||||
|
uint32_t ebx;
|
||||||
|
uint32_t ebp;
|
||||||
|
uint32_t esp;
|
||||||
uint32_t esi;
|
uint32_t esi;
|
||||||
uint32_t edi;
|
uint32_t edi;
|
||||||
uint32_t ebp;
|
|
||||||
|
|
||||||
/* MUST NEVER CHANGE (dependent on the IA32 iret instruction) */
|
/* MUST NEVER CHANGE (dependent on the IA32 iret instruction) */
|
||||||
uint32_t error_code;
|
uint32_t error_code;
|
||||||
|
@ -6,20 +6,14 @@
|
|||||||
.globl cpu_context_switch
|
.globl cpu_context_switch
|
||||||
.type cpu_context_switch, @function
|
.type cpu_context_switch, @function
|
||||||
cpu_context_switch:
|
cpu_context_switch:
|
||||||
// arg2= to_context -- esp+64
|
// arg2= to_context -- esp+68
|
||||||
// arg1= from_context -- esp+60
|
// arg1= from_context -- esp+64
|
||||||
// caller ip -- esp+56
|
// caller ip -- esp+60
|
||||||
pushf // (eflags) esp+52
|
pushf // (eflags) esp+56
|
||||||
pushl %cs // (cs) esp+48
|
pushl %cs // (cs) esp+52
|
||||||
pushl $resume_pc // (ip) esp+44
|
pushl $resume_pc // (ip) esp+48
|
||||||
pushl $0 // (error code) esp+40
|
pushl $0 // (error code) esp+44
|
||||||
pushl %ebp // esp+36
|
pushal // (general reg) esp+12+8*4
|
||||||
pushl %edi // esp+32
|
|
||||||
pushl %esi // esp+28
|
|
||||||
pushl %edx // esp+24
|
|
||||||
pushl %ecx // esp+20
|
|
||||||
pushl %ebx // esp+16
|
|
||||||
pushl %eax // esp+12
|
|
||||||
subl $2, %esp // (alignment) esp+10
|
subl $2, %esp // (alignment) esp+10
|
||||||
pushw %ss // esp+8
|
pushw %ss // esp+8
|
||||||
pushw %ds // esp+6
|
pushw %ds // esp+6
|
||||||
@ -32,11 +26,11 @@ cpu_context_switch:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Store the address of the saved context */
|
/* Store the address of the saved context */
|
||||||
movl 60(%esp), %ebx
|
movl 64(%esp), %ebx
|
||||||
movl %esp, (%ebx)
|
movl %esp, (%ebx)
|
||||||
|
|
||||||
/* This is the proper context switch ! We change the stack here */
|
/* This is the proper context switch ! We change the stack here */
|
||||||
movl 64(%esp), %esp
|
movl 68(%esp), %esp
|
||||||
|
|
||||||
/* Restore the CPU context */
|
/* Restore the CPU context */
|
||||||
popw %gs
|
popw %gs
|
||||||
@ -45,13 +39,7 @@ cpu_context_switch:
|
|||||||
popw %ds
|
popw %ds
|
||||||
popw %ss
|
popw %ss
|
||||||
addl $2,%esp
|
addl $2,%esp
|
||||||
popl %eax
|
popal
|
||||||
popl %ebx
|
|
||||||
popl %ecx
|
|
||||||
popl %edx
|
|
||||||
popl %esi
|
|
||||||
popl %edi
|
|
||||||
popl %ebp
|
|
||||||
addl $4, %esp /* Ignore "error code" */
|
addl $4, %esp /* Ignore "error code" */
|
||||||
|
|
||||||
/* This restores the eflags, the cs and the eip registers */
|
/* This restores the eflags, the cs and the eip registers */
|
||||||
@ -94,13 +82,7 @@ cpu_context_exit_to:
|
|||||||
popw %ds
|
popw %ds
|
||||||
popw %ss
|
popw %ss
|
||||||
addl $2,%esp
|
addl $2,%esp
|
||||||
popl %eax
|
popal
|
||||||
popl %ebx
|
|
||||||
popl %ecx
|
|
||||||
popl %edx
|
|
||||||
popl %esi
|
|
||||||
popl %edi
|
|
||||||
popl %ebp
|
|
||||||
addl $4, %esp /* Ignore "error code" */
|
addl $4, %esp /* Ignore "error code" */
|
||||||
|
|
||||||
/* This restores the eflags, the cs and the eip registers */
|
/* This restores the eflags, the cs and the eip registers */
|
||||||
|
Loading…
Reference in New Issue
Block a user