mrjbom wrote:
Hi.
I want to start engaging in user space and implement multitasking and multiprocessing.
I need to know if I'm ready for this...
Now I have a virtual memory Manager, interrupts and exceptions. Is this enough to move on?
You'll need to tweak these a bit, but essentially yes.
mrjbom wrote:
1. How do I switch between kernel mode and user mode? I didn't find any clear information about it.
You fake an interrupt handler return. You push the required registers (with ring 3 selectors for segment registers) on the stack, and you issue an iret.
mrjbom wrote:
2. How to load a program into memory? To a certain place? For now, I think I should compile the programs into separate ones .o files and link to the core, but how do I load them to a specific location in virtual memory?
This is a bit more complicated. You'll need a storage device driver, which can load one sector at a time. Then you set the starting address, call that read sector function, increase the address by 512, and repeat until you have bytes remaining. For virtual memory, there's an extra step, you need to allocate physical pages in the address space. You can do that in advance, or you could write the page fault handler in a way to allocate a page and just let that do the work for the loader.
mrjbom wrote:
3. If I set a flag for the virtual page where the program is located indicating that this page is a user page (PAGE_SUPERVISOR is 1), then when I try to access the page marked as for the kernel(PAGE_SUPERVISOR is 0), page_fault will occur?
User mode can only access pages that are marked user pages in paging table attributes. From kernel, you could access both user and kernel pages, or you could only access only kernel pages (there's a switch for that, I have to look up it in the spec which one, but I'm sure there is one). If you write your code in a way that the kernel only accesses pages that are marked as kernel page, your code will work for sure.
Cheers,
bzt