Re: Higher Half in C?
Posted: Mon Jul 16, 2018 1:01 am
To think of it, there might be a contrived way of enabling PAE on the fly. You could rewrite the first 8 PDEs into PDPTEs, make them point to page directories, etc, and then enable PAE. Assuming that the IDT, GDT and TSS are pointed at higher half memory at this point, you shouldn't fault yet. Turning on PAE should serialize the execution, flush the pipeline and discard the TLB entries, and hopefully just reload the paging structures. Of course, starting with PAE will be more conventional, but it is your decision.Octacone wrote:I definitely don't want to keep PSE. This never gets easy, doesn't it?simeonz wrote:When you turn off PSE, the current code page (being large 4MB page) will be immediately discarded from the TLB, then resolved again, but since PSE is off, the PS bit will be ignored, and the PDE will be interpreted as a pointer to a page table. This is sufficient for a crash. If you turn on the PAE, the paging structures immediately switch to 3-level with PDPTEs at the top. I don't think that there is a way to do that safely without disabling paging first, in which case you are back to square one. I would advise you to keep PSE. Or don't map the kernel with large pages. If you want PAE, you better start with PAE on. There will be one more level of indirection, and you will have to set the first directory entry of the first and fourth page directories.Octacone wrote:Success!!!
I managed to enable PSE 4 MB paging in assembly and identity map 1 MB to 1 MB and 3 GB to 1 MB. Everything seems to be working fine. My kernel is officially in higher half.
Now I'm having a problem because it crashes when I try to re-enable paging, more specially turning off PSE and turning on PAE and resetting CR3. How to solve that?
This is going to get really messy and complicated. Making PAE work in assembly, great, just great. Shouldn't take more than like 5 weeks, but OK.