Well i chosed to implement multitasking and read some documents mainly Viridis and BI's tut. Now i have some doubt's in BI's tutorial.
Code: Select all
typedef struct {
uint_t prozess_esp; //actual position of esp
uint_t prozess_ss; //actual stack segment.
Code: Select all
%macro REG_SAVE 0
;save all registers in the kernel-level stack of the process and switch to the kernel stack
cld
pushad
push ds
push es
push fs
push gs
mov eax,[p]
mov [eax],esp
lea eax,[kstackend] ; switch to the kernel's own stack.
mov esp,eax
%endmacro
Code: Select all
%macro REG_RESTORE_MASTER 0
mov eax,[p] ;put adress of struct of current process in eax.
mov esp,[eax] ;restore adress of esp.
mov ebx,[eax+8];put content of the k-stack field into ebx.
mov [sys_tss+4],ebx ;update system tss.
mov al,0x20
out 0x20,al
pop gs
pop fs
pop es
pop ds
popad
iretd
%endmacro
Code: Select all
stacksetup=&kstacks[d][KSTACKTOP];
*stacksetup--;
*stacksetup--=0x0202;
*stacksetup--=0x08;
................................
*stacksetup= 0x10; //gs
processes[f].prozess_esp=(uint_t)stacksetup;
processes[f].prozess_ss=0x10;
processes[f].prozess_kstack=(uint_t)&kstacks[d][KSTACKTOP];
processes[f].prozess_ustack=(uint_t)&stacks[d][USTACKTOP];
So here comes my doubt.
So while returning you are filling current processes esp with the pointer into kernel stack. Then it means if we are going to push or pop something in our user program it is going to affect the kernel's stack and eventually at some instant it is going to fail. That's what happening in my case. Here what is the need of user stack?
p.s: i do know that i have something misuderstood. So somebody help me with it. Another thing i don't want to start a new thread as the topic is related and i have quoted so much quotes from BI's tut bcoz u should know what i am trying to ask.