Multitasking in JamesM tutorial

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
vjain20
Member
Member
Posts: 73
Joined: Wed Apr 04, 2012 9:12 pm

Multitasking in JamesM tutorial

Post by vjain20 »

Hi,

I am unable to understand why copying data of one frame to another required requires disabling paging ( the copy_page_physical() function)
while copying stack from one location to another just requires memcpy().
copy_page_physical is really a misnomer. What we actually want to do is copy the contents of one frame into another frame. This, unfortunately, involves disabling paging (so we can access all of physical RAM), so we write this as a pure assembler function.
I don't understand the reason given here - 'access all of physcial RAM'. Why can't we access all of the ram with paging enabled ?
After all the heap was created after paging was enabled. Please explain.
- Thanks
Vaibhav jain
User avatar
serviper
Member
Member
Posts: 31
Joined: Sat Jul 16, 2011 6:05 am
Location: China
Contact:

Re: Multitasking in JamesM tutorial

Post by serviper »

vjain20 wrote:Hi,

I am unable to understand why copying data of one frame to another required requires disabling paging ( the copy_page_physical() function)
while copying stack from one location to another just requires memcpy().
copy_page_physical is really a misnomer. What we actually want to do is copy the contents of one frame into another frame. This, unfortunately, involves disabling paging (so we can access all of physical RAM), so we write this as a pure assembler function.
I don't understand the reason given here - 'access all of physcial RAM'. Why can't we access all of the ram with paging enabled ?
After all the heap was created after paging was enabled. Please explain.
Note that copy_page_physical uses 2 *physical* addresses (frames * 4KB) rather than linear addresses. With paging disabled, we use only ds - remember its base is 0x0 and covers all the 4GB vitrual space.
Also, the source page and the destination page have the same linear address. It's possible to copy a page using 2 page directories, but you need to get the frame addresses as well.
vjain20
Member
Member
Posts: 73
Joined: Wed Apr 04, 2012 9:12 pm

Re: Multitasking in JamesM tutorial

Post by vjain20 »

Thanks for replying!
What I have understood is that since page tables contain physical address we have no option but to use physical address.
But isn't every address in the kernel directory identity-mapped ? I am wondering if the physical address can be used as virtual address.
- Thanks
Vaibhav jain
User avatar
serviper
Member
Member
Posts: 31
Joined: Sat Jul 16, 2011 6:05 am
Location: China
Contact:

Re: Multitasking in JamesM tutorial

Post by serviper »

vjain20 wrote:Thanks for replying!
What I have understood is that since page tables contain physical address we have no option but to use physical address.
But isn't every address in the kernel directory identity-mapped ? I am wondering if the physical address can be used as virtual address.
Not all pages in the so-called kernel directory are identity-mapped and identity mapping are not necessary after you set up an initial page directory. The identity mapping in JamesM's tutorial contains the first 1MB of the physical memory (reserved for I/O, e.g, VGA), the kernel image, a 4KB page for kernel page directory and a few page tables. Then he

Code: Select all

int i = 0;
for (i = KHEAP_START; i < KHEAP_START+KHEAP_INITIAL_SIZE; i += 0x1000)
       get_page(i, 1, kernel_directory); 
-- by get_page from KHEAP_START to KHEAP_START+KHEAP_INITIAL_SIZE, he fill the PTEs with linear addresses of kernel heap pages, and allocate their corresponding page tables (e.g, PTE 0xC0000000 needs table 768, but it is not created when initializing paging) by moving the placement pointer (these tables are identity-mapped, for there's not a heap). However, these pages are not actually allocated until alloc_frame is called.
If you read the routine alloc_frame, you should realize that it grabs the first available page for a request. That's why JamesM get the identity mapping done before he *allocates* pages for kernel heap - It *happens* that the identity-mapped area is identity-mapped because of the policy of alloc_frame.
Last edited by serviper on Sat Apr 21, 2012 2:36 am, edited 1 time in total.
User avatar
serviper
Member
Member
Posts: 31
Joined: Sat Jul 16, 2011 6:05 am
Location: China
Contact:

Re: Multitasking in JamesM tutorial

Post by serviper »

vjain20 wrote: What I have understood is that since page tables contain physical address we have no option but to use physical address.
The linear address of a page can be calculated using indices of its page directory and pagetable.
But it's impossible to copy page at linear address LA of address space PD1 to a page at the same linear address LA but in a different address space PD2 using only LA.
In a nutshell, t: {LA} -> {PA} is a many-to-one mapping, where {LA} is the set of linear addresses in one address space and {PA} is the set of physical addresses.
vjain20
Member
Member
Posts: 73
Joined: Wed Apr 04, 2012 9:12 pm

Re: Multitasking in JamesM tutorial

Post by vjain20 »

Now I got it. Thanks a lot for great explanation!
- Thanks
Vaibhav jain
Post Reply