Page 2 of 2
Re:paging questions
Posted: Tue Sep 02, 2003 12:40 pm
by Pype.Clicker
I'm not sure this approach of "mapping 0..N of physical address space" is very clever. Of course, if 99% of the systems you target have less memory than the available kernel space (once kernel's own code, stack and heap have been deduced), it's easy and efficient. But certainly not elegant.
On the other side, you might decide to maitain a cache of the most requested physical areas ... I would certainly not state for 4Kb entries in that cache as it would imply too much overhead, but rather something like 4MB entries ... If your system has less than N*4MB physical memory, you simply fall back to Windows' behaviour, but if it has more and tries to access physical memory X that isn't in the last N requested 4MB pages, the least frequently requested area would be removed from the cache and its slot would be used to map X instead ...
Okay, this is a bit more complicated to handle and it means that you need to lookup PhysicalToKernelMapping(X) using something like a balanced tree rather than just doing PhysicalToKernelMapping[X], but it's more scalable and (imho) more elegant too as you can resize the mapping area as wished.
Iirc, one of the Windows (i would say 98 but i'm no longer sure if it wasn't ME or NT4) had the ugly bug of crashing/having performance penalties when it had "too much" physical memory ... i wouldn't surprised if it was due to a bug in the handling of "out-of-scope" physical regions.
Re:paging questions
Posted: Tue Sep 02, 2003 2:22 pm
by Tim
You could dedicate 512MB of virtual address space to a physical address cache. It could be arranged in an array of 4MB slots (each of which could be mapped with a large page); when a driver requested a physical address which wasn't cached, an old slot would be evicted and a new one mapped. For machines with physical memory not greater than 512MB, the whole space would effectively be a Windows-style static mapping.
BTW: the bug you're thinking of was 95/98. I think it would stop you from booting if you had more than 128MB memory (can't remember the figure, and I can't easily try it).
Re:paging questions
Posted: Tue Sep 02, 2003 9:54 pm
by Solar
Tim Robinson wrote:
BTW: the bug you're thinking of was 95/98. I think it would stop you from booting if you had more than 128MB memory (can't remember the figure, and I can't easily try it).
I think the figure was more like 768 MByte - since I'm booting Win98SE fine with my 288 MByte.
Re:paging questions
Posted: Thu Sep 04, 2003 9:24 pm
by beyondsociety
Hey Tim, I have a few more questions ;D
When paging is enabled the virtual(logical) address = the physical address which enables the kernel to access memory up to 4GB as physical even though its really virtual.
Q. Is this correct? Also what is considered identity mapping and why is it needed in order to setup paging?
Re:paging questions
Posted: Fri Sep 05, 2003 1:18 am
by Pype.Clicker
beyondsociety wrote:
Hey Tim, I have a few more questions ;D
When paging is enabled the virtual(logical) address = the physical address which enables the kernel to access memory up to 4GB as physical even though its really virtual.
ww what ?
When paging is enabled, any memory reference that passed the 'segmentation' unit is a
virtual address, which means you cannot tell which physical memory area is involved when you access it.
It could be any memory location depending on the page frame number you specified for the page entry that control the current page. It could even be nothing if the page entry has its "present" bit cleared.
paging allow you to have an address space of 4GB even if you don't have 4GB of physical memory, placing the 'real' memory where you want in your address space, and to have 'virtual memory' by storing the actual content of a page on a mass storage device (your hard disk) and retrieving it on demand.
Q. Also what is considered identity mapping and why is it needed in order to setup paging?
Identity mapping is a special mapping setup for which virtual address X is mapped to physical address X. It is useful when setting up paging because before paging, the memory *is* identity-mapped (a.k.a. 1:1 mapped), so it makes the paging setup transparent to the running code.
Re:paging questions
Posted: Fri Sep 05, 2003 3:25 am
by Tim
Partial identity mapping must be used when setting up paging, otherwise the code which is doing the setting up has nowhere to run once paging is enabled. Remember, after paging is enabled, you must execute at least one instruction (JMP) to move to the new virtual address.
Re:paging questions
Posted: Fri Sep 05, 2003 3:44 am
by Pype.Clicker
Tim Robinson wrote:
Partial identity mapping must be used when setting up paging, otherwise the code which is doing the setting up has nowhere to run once paging is enabled. Remember, after paging is enabled, you must execute at least one instruction (JMP) to move to the new virtual address.
hum. right. I tend to forgot the fact there's a pipeline and a prefetch unit ... So theorically, if i have
bootstrap code that is planned to run in physical X..Y and a kernel image that is planned to run at K..L, i could enable paging with
Code: Select all
;; prepare directory and page tables for K..L to map physical pages
;; at which the kernel image get loaded
lea eax,[PageDirectory]
mov CR3,eax
mov eax,CR0
or eax,CR0_PG_BIT
mov CR0,eax
jmp FLAT_CODE_SEGMENT:kernel_offset
without even mapping the bootloader code, couldn't i (and thus not mapping it 1:1)?
Despites the fact it would be theorically possible or not, i *do not* recommend to bypass 1:1 mapping for the paging setup as it means that
[*] you'll not be able to share any function between pre-paging and post-paging code
[*] you're likely to have to use ASM tricks to do it
[*] whisteling too loud aside of your kernel could make it panic (understand it as the slighest code modification could break the pipeline and ruin your plans of Global World Domination
-- err . i mean, of setting up paging
)
Re:paging questions
Posted: Fri Sep 05, 2003 6:55 am
by beyondsociety
Identity mapping is a special mapping setup for which virtual address X is mapped to physical address X. It is useful when setting up paging because before paging, the memory *is* identity-mapped (a.k.a. 1:1 mapped), so it makes the paging setup transparent to the running code.
What do you mean by identity mapped(aka 1:1 mapped)?
Re:paging questions
Posted: Fri Sep 05, 2003 7:15 am
by Pype.Clicker
that's just explained in the post you quote:
foreach virtual address X, physical address of X is (drums rolling) X!
So a 1:1 mapping table for the first 4 MB looks like
{ 0x0000001, 0x00001001, 0x00002001, 0x00003001, ... , 0x003ff001}
Re:paging questions
Posted: Fri Sep 05, 2003 7:15 am
by Tim
Pype: prefetch or no, that code will still crash on the [tt]jmp FLAT_CODE_SEGMENT:kernel_offset[/tt] line unless CS:EIP is already mapped. This is what the Intel manual says, and I've tried it (I mean, I've made that mistake...).
beyondsociety: Identity mapping is where you map certain virtual address to their equivalent physical addresses. For example, if you identity mapped all memory, it would be like disabling paging.
Re:paging questions
Posted: Fri Sep 05, 2003 7:20 am
by BI lazy
*WHAM --- splintercrackcrush*liftingtheclubofwisdomagain*
Now, *listen* identity mapping aka (1:1)-mapping is the following:
each page tab-entry for a virtual adress points to an equivalent physical adress. In small and simple terms:
virtual adress==physical adress.
and this is called *identity mapping*