Hi.
I'm trying to make a paged addressing of memory with the help of this tutorial, but I have had problems with some of its parts.
What size should frame_map be?
What is npages and how to calculate it?
What is startframe and how to calculate it?
What is pre_frames and how to set up it?
How to implement a paged addressing of memory?
Re: How to implement a paged addressing of memory?
Just to clarify: This tutorial is for writing a physical memory allocator. This is not the same thing as paging, but for all intents and purposes is a prerequisite for implementing it.
frame_map should be large enough to hold an entry for each 4kb page frame in the entire address space. I'll leave it up to you to figure out what that means in practical terms. The tutorial actually lists the number of frames in the author's implementation in the 'The Method' section. This is best ignored, the number of frames in your map depends on your target architecture and your implementation.
npages appears to be the number of entries in said frame map.
startframe looks like it's the address of the first frame in the map. The map might not necessarily map the entire physical memory space, so this is the starting offset. The tutorial states that the map is supposed to start right after kernel memory.
There's a number of things in this tutorial that are very questionable. The tutorial does not invest any time in explaining why it chooses a non-standard approach. No offense meant, your post sounds like you may be new to the topic. if this is the case, don't waste your time trying to understand this tutorial. The relevant wiki page: Page_Frame_Allocation explains the subject well. Start with a bitmap allocator. If this doesn't make sense yet, work backwards until you understand all of the topics in question. Feel free to come back to the forum for help!
frame_map should be large enough to hold an entry for each 4kb page frame in the entire address space. I'll leave it up to you to figure out what that means in practical terms. The tutorial actually lists the number of frames in the author's implementation in the 'The Method' section. This is best ignored, the number of frames in your map depends on your target architecture and your implementation.
npages appears to be the number of entries in said frame map.
startframe looks like it's the address of the first frame in the map. The map might not necessarily map the entire physical memory space, so this is the starting offset. The tutorial states that the map is supposed to start right after kernel memory.
There's a number of things in this tutorial that are very questionable. The tutorial does not invest any time in explaining why it chooses a non-standard approach. No offense meant, your post sounds like you may be new to the topic. if this is the case, don't waste your time trying to understand this tutorial. The relevant wiki page: Page_Frame_Allocation explains the subject well. Start with a bitmap allocator. If this doesn't make sense yet, work backwards until you understand all of the topics in question. Feel free to come back to the forum for help!
Re: How to implement a paged addressing of memory?
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.ajxs wrote:Just to clarify: This tutorial is for writing a physical memory allocator. This is not the same thing as paging, but for all intents and purposes is a prerequisite for implementing it.
frame_map should be large enough to hold an entry for each 4kb page frame in the entire address space. I'll leave it up to you to figure out what that means in practical terms. The tutorial actually lists the number of frames in the author's implementation in the 'The Method' section. This is best ignored, the number of frames in your map depends on your target architecture and your implementation.
npages appears to be the number of entries in said frame map.
startframe looks like it's the address of the first frame in the map. The map might not necessarily map the entire physical memory space, so this is the starting offset. The tutorial states that the map is supposed to start right after kernel memory.
There's a number of things in this tutorial that are very questionable. The tutorial does not invest any time in explaining why it chooses a non-standard approach. No offense meant, your post sounds like you may be new to the topic. if this is the case, don't waste your time trying to understand this tutorial. The relevant wiki page: Page_Frame_Allocation explains the subject well. Start with a bitmap allocator. If this doesn't make sense yet, work backwards until you understand all of the topics in question. Feel free to come back to the forum for help!
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?
And pre_page is probably the address of the previous page.
Is that right?
Re: How to implement a paged addressing of memory?
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: 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.
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: 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?
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.mrjbom wrote: And pre_page is probably the address of the previous page.
Is that right?
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.

