Everything that @Octocontrabass said, plus
bayesian wrote:I can only use up to 1GiB memory even the physical memory is over 1GiB.
Why? If your page frame allocator returns 4G addresses, then any of that 4G can be mapped in the top 1G. But your page allocator should probably return page frames (that is, physical address >> 12), that way you could handle all 36 bits of PAE on 32 bits.
bayesian wrote:will the MMU automatically translate it to virtual address? If not, how to fix it?
How could it? You have to set up paging tables for that. Ideally, you should have a virtual memory allocator, which allocates linear addresses, and if and when it's out of free pages, it would call the page frame allocator. You should not call the page frame allocator (that returns physical addresses) directly, only through the virtual memory allocator (that returns linear addresses).
(BTW almost forgot, in protmode linear address only equals to virtual address if your segment descriptor has a base of 0 and size of 4G, which is strongly recommended.)
bayesian wrote:And if a user program needs a new page, OS will firstly try to find a new page in physic memory over 896MiB or 1GiB. Is that correct?
Not exactly. Think of this way:
Address space #1: 0 to 0xBFFFFFFF user space for process A (RAM a), 0xC0000000 to 0xFFFFFFFF kernel space (RAM b)
Address space #2: 0 to 0xBFFFFFFF user space for process B (RAM c), 0xC0000000 to 0xFFFFFFFF kernel space (RAM b)
So while the virtual memory looks identical for process A and process B, different RAM pages are mapped actually, but for kernel space the same RAM is mapped for both processes. What the physical address is, doesn't matter at all. For example, many OS uses 1M for RAM b, and uses any physical page it could find (< 1M or > 1M+kernel size) as RAM a and RAM c. Look at
here, and imagine that on the picture "05x" is the mapping for 0xC0000000 to 0xFFFFFFFF.
Cheers,
bzt