All pastes #96962 Raw Edit

omin0us

public text v1 · immutable
#96962 ·published 2006-07-23 08:07 UTC
rendered paste body

; I went from this....


[BITS 32]

extern currentProcess


; right now stack looks like
;       processPtr
; esp-->returnAddress
;
;

align 16
; void switchTo(process_t *p)
global switchTo
switchTo:
    pop eax     ; save return address
    pushfd      ; push eflags register
    push eax    ; push return address back for partial iret
                ; stack frame (eip, eflags)

    push ebp
    push edi
    push esi
    push ebx

    mov eax, [currentProcess]
    mov [eax+0], esp
    mov eax, [esp+24];
    mov [currentProcess], eax
    mov esp, [eax+0];
    pop ebx
    pop esi
    pop edi
    pop ebp

    pop ecx
    push cs
    push ecx
    iret




; To this...


[BITS 32]

extern currentProcess


; right now stack looks like
;       processPtr
; esp-->returnAddress
;
;

align 16
; void switchTo(process_t *p)
global switchTo
switchTo:
    pop eax     ; save return address
    pushfd      ; push eflags register
    push cs     ; push cs		
    push eax    ; push return address back for iret
                ; stack frame (eip, cs, eflags)

    push ebp
    push edi
    push esi
    push ebx

    mov eax, [currentProcess]
    mov [eax+0], esp            ;save current process esp
    mov eax, [esp+24];          ;retrieve process_t pointer passed to switchTo()
    mov [currentProcess], eax
    mov esp, [eax+0];
    pop ebx
    pop esi
    pop edi
    pop ebp

    iret