tss ~OR~ context swithing
Posted: Mon Aug 25, 2003 6:19 am
so, which way is better? with a tss or a context-switch (this is when I swao stacks, yes?)
speak out!
cheers,
Adrian
speak out!
cheers,
Adrian
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
static void do_switch(kDispatcher *me, kThread *from, kThread* to)
{
static kThread *checkme;
checkme=from;
dumpDispatcher();
if (from!=to && to!=NULL) {
switching++;
kSaveCpuCtx(&(from->cpuState),from->ptrTss);
kRestoreCpuCtx(to->ptrTss,&(to->cpuState));
if (!(to->stat & KT_TSSOWNER))
to->ptrTss->eip=(dword)resume_switch;
if (from->TSS_ID != to->TSS_ID) {
task_switch(0,to->TSS_ID,&(from->cpuState));
} else {
stack_switch(&(from->cpuState),&(to->cpuState));
}
switching--;
}
}
_task_switch:
push ebp
mov ebp, esp
pushfd
push fs
pushad
mov eax,[ebp+16]
mov [eax],esp
mov [eax+4],ss
jmp far [ebp+8]
_resume_switch:
popad
pop fs
popfd
pop ebp
ret
;;--------------------------------------------------------------------------
;; performs a stack-switch for multi-threading.
;; cs: don't need to be saved: =0x08 for every thread in kernel mode.
;; ds,es,gs: don't need to be saved: =0x10/0x18 for every thread.
;; fs: this holds the selector for user data segment. same for all threads
;; within a given process, but should better be saved in case a thread
;; changed it for special purpose
;; eax: return value, don't need to be saved.
;; edx,ecx: callee-clobbered register: the compiler will assume we overwrote
;; them after function returns.
;; -------------------------------------------------------------------------
;;; cpu_context* stack_switch(cpu_context *saveto, cpu_context *getfrom)
_stack_switch:
push ebp
mov ebp,esp
pushfd
push fs
pushad
mov eax,[ebp+8]
mov edx,[ebp+12]
mov [eax],esp
mov [eax+4],ss
lss esp,[edx]
popad
pop fs
popfd
pop ebp
ret