t0xic wrote:I figured out how to implement the bitmap, but could I see an example of your stack code? I know it would be faster, I just have no idea how to do it
It's simpler than a bitmap, imho, so why don't you put your neurones in the way to invent your own code?!
Basically, you need a "mark_as_free" function that acts as a stack push operation, and a "get_free_page" function that acts as a stack pop. If you know how stacks work, then you already undestood the idea.
Enable paging
before anything else. Use some sort of lazy allocation (for example, start allocating pages for the paging structures just above the last page used by the kernel) in this early environment.
Now, I suggest that you make the last PDE point to the page directory itself. This will enable you to access all the page tables in the correct order starting at 4GB-4MB, and the page directory starting at 4GB-4KB. Beware that accessing to missing page tables will cause a page fault, so either you perform extra tests to avoid them or you design everything to accordingly catch the kernel mode exceptions and allocate pages.
Then, write a function that returns information about a page's address (present_page, page_not_present, page_table_not_present, etc).
Then write the functions to work over the stack. Take care that you need to have present pages where you are going to write the stack contents when you do a push operation. My strategy was testing if the page at which the stack pointer points exists (using a function that you should have already written), and allocate the page that you were intended to push, instead of pushing it (but don't forget to blank the page before allocating it)... When poping, you do the same thing the backwards way and return the page that was allocated to the stack if the stack pointer is alligned *and* the page exists...
Then, write functions that play all the necessary work to map physical page X on linear address Y. Use the previous stack functions to get free pages if you need to allocate new page tables, and don't forget to clear them before usage.
JJ