I've got my kernel with software multitasking, up to now all the tasks are running in ring0. So I tried to setup a task to run in ring3. I made two new entries in the gdt, one for code and one for data in ring3.
my gdt now looks like this
code ring0 // 8
data ring0 // 16
code ring3 // 24
data ring3 // 32
tss
Then I setup the task like this (the only difference I've done from ring0 tasks is change the cs and ds)
Code: Select all
// ring0
// int cs = 8;
// int ds = 16;
// ring3
int cs = 24;
int ds = 32;
// iret pops these
*(--esp) = EFLAGS | EFLAGS_IF; // eflags
*(--esp) = cs; // cs
*(--esp) = (dword)entrypoint; // eip
// the timer interrupt pops/pushes these
*(--esp) = 0; // ebp
*(--esp) = 0; // esp
*(--esp) = 0; // edi
*(--esp) = 0; // esi
*(--esp) = 0; // edx
*(--esp) = 0; // ecx
*(--esp) = 0; // ebx
*(--esp) = 0; // eax
*(--esp) = ds; // ds
*(--esp) = ds; // es
*(--esp) = ds; // fs
*(--esp) = ds; // gs
(again the only change I've made to what's working, is change the cs/ds in the tasks stack)
What am I missing?
Must I introduce ldt ? (I haven't yet understood what ldt is for)
thanks,
--
Sigurd Lerstad