Doubt regarding user "Programs"
Posted: Thu May 28, 2009 8:25 pm
Hi again all, first ty for your support in my previous post it was helpfull and made me understand a lot of things i had not clear before.
This questions isnt much about non-working code, but about how to treat programs in my "pseudo multitasking OS".
(I am using C btw.)
I got my GDT, IDT, PIC, and PIT working already and right now i am facing a mental problem trying to figure out how to treat "Programs"
inside my OS. I say "programs" because they will be binary code loaded into memory with the kernel at startup.
An example would be my shell. The shell i got working now is compiled from a .c file into an .o thats then linked and loaded with the kernel by the bootloader.
Since i will attempt preemptive multitasking, i will need to save the current registers into the shell's stack, and some other information in a structure in memory and then switch to the next process stack and pop its Instruction pointer out so it can resume work. The problem is that i want to have 2 or more instances of the shell running at the same time, but as far as i can see, in C only local variables will be stored in the stack (here i guess that giving each shell a different stack will avoid problems caused by memory being used shared).
(2 sets of instruction pointers working on 2 different stacks with the same code wont yield a problem but i cant use the same global variables for both)
How do i handle different versions of global variables when the memory of the global variables will be the same for 2 instances of the same code without having to compile the same code twice or more under different names (to avoid linking problems and still get 2 different sets of memory)?
Is there a way to take the code and data and copy it from the original binary into a different memory location so i can create more copies of the shell in memory? (wouldn't this give me problems regarding pointers to the data form inside the new running code of one of the copies?)
Lol or is there a better way to create different instances of running "programs"?
Sorry for the mess i made about my thoughts on this matter, any help and insights can be helpful!
This questions isnt much about non-working code, but about how to treat programs in my "pseudo multitasking OS".
(I am using C btw.)
I got my GDT, IDT, PIC, and PIT working already and right now i am facing a mental problem trying to figure out how to treat "Programs"
inside my OS. I say "programs" because they will be binary code loaded into memory with the kernel at startup.
An example would be my shell. The shell i got working now is compiled from a .c file into an .o thats then linked and loaded with the kernel by the bootloader.
Since i will attempt preemptive multitasking, i will need to save the current registers into the shell's stack, and some other information in a structure in memory and then switch to the next process stack and pop its Instruction pointer out so it can resume work. The problem is that i want to have 2 or more instances of the shell running at the same time, but as far as i can see, in C only local variables will be stored in the stack (here i guess that giving each shell a different stack will avoid problems caused by memory being used shared).
(2 sets of instruction pointers working on 2 different stacks with the same code wont yield a problem but i cant use the same global variables for both)
How do i handle different versions of global variables when the memory of the global variables will be the same for 2 instances of the same code without having to compile the same code twice or more under different names (to avoid linking problems and still get 2 different sets of memory)?
Is there a way to take the code and data and copy it from the original binary into a different memory location so i can create more copies of the shell in memory? (wouldn't this give me problems regarding pointers to the data form inside the new running code of one of the copies?)
Lol or is there a better way to create different instances of running "programs"?
Sorry for the mess i made about my thoughts on this matter, any help and insights can be helpful!