Multitasking issues
Multitasking issues
I have some questions about software multitasking.
When I create a task, must I create a stack for user and a stack for kernel or only one of these? How must I use they?
Which values must I save in kernel stack and which in user stack?
(Using paging) Must I have static addresses? (for example 0x10000000 for code, 0x40000000 for heap)
While creating a task, how can I access to virtual memory of this task?
When I create a task, must I create a stack for user and a stack for kernel or only one of these? How must I use they?
Which values must I save in kernel stack and which in user stack?
(Using paging) Must I have static addresses? (for example 0x10000000 for code, 0x40000000 for heap)
While creating a task, how can I access to virtual memory of this task?
Re: Multitasking issues
You need one for the kernel, which is used for interrupts and for task-switching(that is you push the current state on the kernel-stack).MarkOS wrote: When I create a task, must I create a stack for user and a stack for kernel or only one of these? How must I use they?
Then the user stack is used by the program itself. When calling a function, etc. the values get pushed onto the user stack.
See above.MarkOS wrote:Which values must I save in kernel stack and which in user stack?
Of course not, but it's alot easier to handle. Supporting randomized code sections is very hard(ASLR) (OpenBSD and Vista are doing it for example).MarkOS wrote:(Using paging) Must I have static addresses? (for example 0x10000000 for code, 0x40000000 for heap)
You create a new page directory put the code in it, load the CR3 with the page directories address.MarkOS wrote: While creating a task, how can I access to virtual memory of this task?
Re: Multitasking issues
I know this, but it isn't a waste of resources to switch PDBRs while creating tasks?cyr1x wrote:You create a new page directory put the code in it, load the CR3 with the page directories address.MarkOS wrote: While creating a task, how can I access to virtual memory of this task?
Another thing:
In the scheduler code, when I switch tasks, must I change any value in the TSS?
EDIT: Have you any source code of creating tasks in software multitasking with paging?
Re: Multitasking issues
You don't switch the PD while creating the task. The task/process resides in the PD. This is the point of paging that each process has it's own address space(virtual memory)MarkOS wrote: I know this, but it isn't a waste of resources to switch PDBRs while creating tasks?
No, unless you make use of the hardware task-switching feature, but you must keep track of CR3 and ESP of each task.MarkOS wrote: Another thing:
In the scheduler code, when I switch tasks, must I change any value in the TSS?
No as I'm currently redesigning and rewriting my kernel. But you can check out JamesM's tutorial, although I heard there're some problems with it.MarkOS wrote: EDIT: Have you any source code of creating tasks in software multitasking with paging?
Re: Multitasking issues
How can I use memory mapped into a PD of a user task with the kernel, if I haven't mapped it also in kernel's address space?cyr1x wrote:You don't switch the PD while creating the task. The task/process resides in the PD. This is the point of paging that each process has it's own address space(virtual memory)
For example if I want to insert something in the user stack at the beginning I must allocate a physical page, map it into the address space of the user, map it into the address space of the kernel, change values, and unmap from kernel's address space. Or not?
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
The problems are fixable.
-JL
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
Ha, thats my problem too!
That I haven't gotten, I just put an expand(<large number>); right after init_paging();
-JL
That I haven't gotten, I just put an expand(<large number>); right after init_paging();
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
- piranha
- Member
- Posts: 1391
- Joined: Thu Dec 21, 2006 7:42 pm
- Location: Unknown. Momentum is pretty certain, however.
- Contact:
I tried to get it working, and accidentally stumbled across getting usermode working.
Will do.
-JL
Will do.
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
In a privilege level switch (user-kernel-user) must I change any value in the TSS? Or must I leave the TSS as it is when I load it the first time?
So the scheduler will do:
push all regs
push gs, fs, ds, es
push the stack
change the task
pop the new stack
pop gs, fs, ds, es
pop all regs
iret
right?
or:
push all regs
push gs, fs, ds, es
push the stack
change the task
change some values in TSS
pop the new stack
pop gs, fs, ds, es
pop all regs
iret
In the second case, which values must I change?
So the scheduler will do:
push all regs
push gs, fs, ds, es
push the stack
change the task
pop the new stack
pop gs, fs, ds, es
pop all regs
iret
right?
or:
push all regs
push gs, fs, ds, es
push the stack
change the task
change some values in TSS
pop the new stack
pop gs, fs, ds, es
pop all regs
iret
In the second case, which values must I change?
I use software multitasking, and I don't have a TSS because I'm staying in ring 0 for now. If you are intending to switch between rings, you will need a TSS, and will have to change some values (esp0 at a minimum). Here is a link to a tutorial: http://www.osdever.net/tutorials/multitasking.php
Re: Multitasking issues
Why the hell the kernel needs to know that you are accessing the user stack?MarkOS wrote:For example if I want to insert something in the user stack at the beginning I must allocate a physical page, map it into the address space of the user, map it into the address space of the kernel, change values, and unmap from kernel's address space. Or not?
And even then, in general the kernel is mapped in every process' address space.
You need to adjust the ESP0-field on a task-switch.MarkOS wrote:In a privilege level switch (user-kernel-user) must I change any value in the TSS? Or must I leave the TSS as it is when I load it the first time?