| 1 |
|
| 2 |
.386 |
| 3 |
.model flat, c |
| 4 |
|
| 5 |
.code |
| 6 |
|
| 7 |
slp_switch_raw PROC save_state:DWORD, restore_state:DWORD, extra:DWORD |
| 8 |
|
| 9 |
;save registers. EAX ECX and EDX are available for function use and thus |
| 10 |
;do not have to be stored. |
| 11 |
push ebx |
| 12 |
push esi |
| 13 |
push edi |
| 14 |
push ebp |
| 15 |
|
| 16 |
mov esi, restore_state ; /* save 'restore_state' for later */ |
| 17 |
mov edi, extra ; /* save 'extra' for later */ |
| 18 |
|
| 19 |
mov eax, esp |
| 20 |
|
| 21 |
push edi ; /* arg 2: extra */ |
| 22 |
push eax ; /* arg 1: current (old) stack pointer */ |
| 23 |
mov ecx, save_state |
| 24 |
call ecx ; /* call save_state() */ |
| 25 |
|
| 26 |
test eax, eax; /* skip the restore if the return value is null */ |
| 27 |
jz exit |
| 28 |
|
| 29 |
mov esp, eax; /* change the stack pointer */ |
| 30 |
|
| 31 |
push edi ; /* arg 2: extra */ |
| 32 |
push eax ; /* arg 1: current (new) stack pointer */ |
| 33 |
call esi ; /* call restore_state() */ |
| 34 |
|
| 35 |
exit: |
| 36 |
add esp, 8 |
| 37 |
pop ebp |
| 38 |
pop edi |
| 39 |
pop esi |
| 40 |
pop ebx |
| 41 |
ret |
| 42 |
slp_switch_raw ENDP |
| 43 |
|
| 44 |
end |