mrjbom wrote:
It turns out that if I want to operate with 128 megabytes of RAM, the size of the frame_map will be 262144 (128 megabytes * 1024 kilobytes / 4 kilobytes). npages is also equal to 262144.
You've got the logic mostly correct. You're going to want the memory map to be capable of mapping the entire possible physical address space. There are multiple methods available for detecting memory. Once you've got a memory map, parse it to determine what areas of memory are available, and mark those areas accordingly in your memory map. Refer to:
https://wiki.osdev.org/Detecting_Memory_(x86) for some of the available methods. I'd recommend parsing the Multiboot memory map.
mrjbom wrote:
About start_frame. I have the address of the end of the kernel, but the available RAM can start from another address, or even from other addresses because it is divided into several parts. How will the kernel address help me in this case? Or should I consider start_frame the beginning of the available RAM area?
As hinted at above, your memory should be capable of mapping the entire physical address space. This is another questionable decision made by this tutorial. Without nitpicking too much, it seems like a better approach to map the entire physical address space and simply mark the memory used by the kernel as non-accessible. To do this you will need the starting and ending addresses of the kernel so you can mark this memory as being used.
mrjbom wrote:
And pre_page is probably the address of the previous page.
Is that right?
I don't know to be honest. I don't think you should worry about this tutorial at all. As I said in my previous post, this tutorial is not good advice. You'd be best not following it at all. It contains extremely bad design decisions that are easily remediated.
Memory maps are not hard to implement. Refer to the wiki article I linked in my last post. A bitmap allocator is very easily implemented. Aim for implementing a very simple allocator at first. If you define a good interface, it won't be an issue to upgrade at a later point.