-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch.s
48 lines (43 loc) · 971 Bytes
/
switch.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
.text
.global machine_switch
.global rem_thread
machine_switch:
# address of the new sp is arg1
# address of the current tcb is arg2
# need to store all required registered for old tcb
# restore all required registers from the new tcb
# then when you return, you should get to the new thread
push %rbp
push %rax
push %rbx
push %rcx
push %rdx
push %rsi
push %rdi
push %r8
push %r9
push %r10
push %r11
push %r12
push %r13
push %r14
push %r15
mov %rsp, (%rsi) # Store the old stack pointer in the old TCB
rem_thread:
mov (%rdi), %rsp # Get the new stack pointer from the new TCB
pop %r15
pop %r14
pop %r13
pop %r12
pop %r11
pop %r10
pop %r9
pop %r8
pop %rdi
pop %rsi
pop %rdx
pop %rcx
pop %rbx
pop %rax
pop %rbp
ret