summaryrefslogtreecommitdiff
path: root/swtch.S
blob: 49efdf97b405be8c52fe7df1d01c25d05fdc23aa (plain)
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
# Context switch
#
#   void swtch(struct context **old, struct context *new);
# 
# Save current register context in old
# and then load register context from new.

.globl swtch
swtch:
  movl 4(%esp), %eax
  movl 8(%esp), %edx

  # Save old callee-save registers
  pushl %ebp
  pushl %ebx
  pushl %esi
  pushl %edi

  # Switch stacks
  movl %esp, (%eax)
  movl %edx, %esp

  # Load new callee-save registers
  popl %edi
  popl %esi
  popl %ebx
  popl %ebp
  ret

# Jump on a new stack, fake C calling conventions
.globl jstack
jstack:	
  movl 4(%esp), %esp
  subl $16, %esp	# space for arguments
  movl $0, %ebp	        # terminate functions that follow ebp's
  call mainc	        # continue at mainc