OOStuBS - Technische Informatik II (TI-II)  2.4
context.cc
gehe zur Dokumentation dieser Datei
1 #include "machine/context.h"
2 #include "thread/thread.h"
3 
5  Register* tos = stack+sizeof(stack)/sizeof(Register);
6  tos[-1] = thread;
7  tos[-3] = reinterpret_cast<void*>(&Thread::kickoff);
8  registers[esp] = tos-4;
9 }
10 
11 void Context::set(){
12  asm("mov (%0), %%ebx\n\t"
13  "mov 4(%0), %%esi\n\t"
14  "mov 8(%0), %%edi\n\t"
15  "mov 12(%0), %%esp\n\t"
16  "mov 16(%0), %%ebp\n\t"
17  :
18  : "r"(registers)
19  );
20 }
21 
22 void Context::swap(Context& next){
23  asm("mov %%ebx, (%0)\n\t"
24  "mov %%esi, 4(%0)\n\t"
25  "mov %%edi, 8(%0)\n\t"
26  "mov %%esp, 12(%0)\n\t"
27  "mov %%ebp, 16(%0)\n\t"
28  "mov (%1), %%ebx\n\t"
29  "mov 4(%1), %%esi\n\t"
30  "mov 8(%1), %%edi\n\t"
31  "mov 12(%1), %%esp\n\t"
32  "mov 16(%1), %%ebp\n\t"
33  :
34  : "r"(registers), "r"(&next.registers)
35  );
36 }