So it turns out that things don't work the way I expected they work
in the x86 architecture. This commit implements a new physical memory
manager that addresses these errors.
This commit adds a new module called pmm.c, which is a refactor of
memory.c and paging.c. In fact, both files are deleted, as once the
refactor is done, they aren't required.
pmm.c implements a physical memory manager. When this module is
initialised, it counts the amount of physical memory this computer
has, it splits the memory in 4 KB chunks, and it builds a bitmap that
allows pmm.c to detect which chunks are currently in use and which
ones are free.
pmm.c exposes two functions:
- pmm_alloc_page: this function will take a 4 KB chunk that it is not
already in use, mark it as in use into the bitmap, and retrieve it.
- pmm_free_page: this function will mark the chunk a given memory
address belong to as free, so that further calls to pmm_alloc_page
will eventually use the chunk again for a different purpose.
Additionally, it turns out that there was some misinterpretation into
the purpose of the pages when I initially implemented this, four years
ago.
The 4 KB chunks are not meant to be used by the kernel for general
purpose -- that's what the heap allocator in heap.c should do. These
chunks are meant to be given to the virtual memory manager so that it
can build a virtual memory map using these pages.