Page 1 of 1

is there one linear address space ?

Posted: Wed Oct 03, 2007 6:28 am
by mohammed
both the kernel and the user space share the same linear address (4 GB) ?
or every task can have each one - or may be each segment in each individual task has 4 GB ????
another question : do i have to own a malloc and free function before start paging ?? when i start paging for the first time should i page all the physical memory so it can be used by the kernel or only the heap for the kernel ???
after enabling task switching every task will have an entry in the page directory or it will have a new page directory and page table ??
in window or linux the linear address of each task is 4 GB ???

Posted: Wed Oct 03, 2007 7:06 am
by JamesM
both the kernel and the user space share the same linear address (4 GB) ?
Normally, yes.
or every task can have each one - or may be each segment in each individual task has 4 GB ????
that initial 'or' should be 'and'. Normally each task (process, not thread) has it's own page directory, the kernel being mapped identically in all.
another question : do i have to own a malloc and free function before start paging ??
No.
when i start paging for the first time should i page all the physical memory so it can be used by the kernel or only the heap for the kernel ???
You should map every page which you need to access. That is, all the kernel code pages, data pages, [and pages for the heap, if you have one].
after enabling task switching every task will have an entry in the page directory or it will have a new page directory and page table ??
What do you mean by 'an entry in the page directory'? Do you mean allocating only 4MB per task? bad plan. Every task has it's own page directory (unless you're developing for an embedded target, before the ruffians flame me).
in window or linux the linear address of each task is 4 GB ???
The linear address space size is determined by the processor architecture and mode. In x86_32, there is 4GB of addressable memory. With PAE enabled it's 2^36.

Posted: Wed Oct 03, 2007 8:58 am
by mohammed
thanks..by the way your tutorials are great : D
after enabling paging all the addresses that i used in the kernel will be virtual addresses refer to other locations ??
paging doesn't affect the addresses less than 0x100000??
in the boot sector there is a code data and stack segments after loading the GDT is kernel use the segments that i referred to or it still working with the segments that was in the boot sector ?

Posted: Wed Oct 03, 2007 12:29 pm
by vhg119
mohammed wrote:thanks..by the way your tutorials are great : D
after enabling paging all the addresses that i used in the kernel will be virtual addresses refer to other locations ??
paging doesn't affect the addresses less than 0x100000??
in the boot sector there is a code data and stack segments after loading the GDT is kernel use the segments that i referred to or it still working with the segments that was in the boot sector ?
Paging affects everything.

Your addresses are translated twice.

1) The GDT will offset the address from the base indicated by your GDT entry. If you used a base of 0 for everything, then your addresses will be identity mapped. eg: 0x0 maps to 0x0 and 0x200 maps to 0x200 and so on...

2) Your page directory and page tables map the resulting address (called the linear address) into the actual physical address for your hardware.

Your processor will be using the code segment you specified if you do a far-jump. As for your data segments, you can just load them manually.

Posted: Wed Oct 03, 2007 12:57 pm
by ManOfSteel
@JamesM:
Normally each task (process, not thread) has it's own page directory, the kernel being mapped identically in all.
So whenever a user executes a process, the OS paging system allocates all the page tables and pages needed by the process in the newly created page directory, and it also allocates all the page tables and pages needed by the kernel in this same new page directory. So in all processes address space, some addresses will always point to the physical address where the kernel image was first copied at startup. Is that it?

Posted: Wed Oct 03, 2007 1:01 pm
by vhg119
ManOfSteel wrote:@JamesM:
Normally each task (process, not thread) has it's own page directory, the kernel being mapped identically in all.
So whenever a user executes a process, the OS paging system allocates all the page tables and pages needed by the process in the newly created page directory, and it also allocates all the page tables and pages needed by the kernel in this same new page directory. So in all processes address space, some addresses will always point to the physical address where the kernel image was first copied at startup. Is that it?
You can have each process' page directory point to the same set of page tables for the kernel. That way, you don't need to keep allocating more pages of memory for kernel page tables just so you can keep the kernel mapped in the same location.

Posted: Wed Oct 03, 2007 1:45 pm
by JAAman
You can have each process' page directory point to the same set of page tables for the kernel. That way, you don't need to keep allocating more pages of memory for kernel page tables just so you can keep the kernel mapped in the same location.
which works very well in PAE -- where you can simply assign a directory-pointer to global-kernal, and it requires nothing for each task

Posted: Thu Oct 04, 2007 4:57 am
by mohammed

Code: Select all

unsigned long *page_directory = (unsigned long *) 0x9C000;
unsigned long *page_table = (unsigned long *) 0x9D000; // the page table comes right after the page directory
here the page directory points to a physical address - according to intel manual the page directory can point to the physical address if you used 4 MB pages if you used 4 KB the page directory points to the page table why in this code the page directory points to the address directly ?

Code: Select all

unsigned long address=0; // holds the physical address of where a page is
unsigned int i;

// map the first 4MB of memory
for(i=0; i<1024; i++)
{
	page_table[i] = address | 3; // attribute set to: supervisor level, read/write, present(011 in binary)
	address = address + 4096; // 4096 = 4kb
};
in this code the tutorials writer said
it is set up so that what appears to the programmer to be address 0x2250A000 really is 0x2250A000. But if we wanted to, we could make what appears to the programmer to be address 0x2250A000 really be 0x100000.
how he did that i didn't see in the code any thing refer to any linear address he is just mapping "the first 4 MB" ? how he did that although the page directory is pointing to the address 0x9C000??

Posted: Thu Oct 04, 2007 11:51 am
by vhg119
mohammed wrote: here the page directory points to a physical address - according to intel manual the page directory can point to the physical address if you used 4 MB pages if you used 4 KB the page directory points to the page table why in this code the page directory points to the address directly ?

how he did that i didn't see in the code any thing refer to any linear address he is just mapping "the first 4 MB" ? how he did that although the page directory is pointing to the address 0x9C000??
I'm trying very hard to understand your question, so forgive me if I'm not giving you the right answer.

The entries in the page directory point to the physical addresses of the page tables. The entries in the page tables point to the physical addresses of the pages.

The author created the page table at that location and is populating it with physical addresses of the first 1024 pages of memory. He is sayiing that everything is identity mapped. 0x2250A000 is mapped to 0x2250A000. He is saying that he could've just as easily mapped 0x2250A000 to 0x100000 if he wanted to.