Page 1 of 1

Organizing Memory

Posted: Wed May 06, 2015 1:35 pm
by Isaac
I'm trying to organize memory a little. There are different types of memory as we see on the map returned from BIOS INT 0x15 Function 0xE820. So the way I want to organize them is by enabling paging. When creating the page tables I want to put first all the pages that have type 1 page frames, then all the pages that have type 2 page frames, and so on. The problem I run into is that the sizes of some fields are not divisible by 4096. So, for example, what would I do if I encounter a type 2 field that's 2048 bytes long? I can't skip it just like that, it may be important. But I can't make a page frame out of it because it's not long enough. If I map a page to the beginning of such a field, the last 2048 bytes of the page will hang over to the next field which may be, say, a type 4 field. So what will happen is, I'll wind up with some type 2 memory, some type 4 memory and some more type 2 memory. But that's not in order! Is there any way I can do this?

Re: Organizing Memory

Posted: Wed May 06, 2015 1:44 pm
by gerryg400
Isaac wrote:I'm trying to organize memory a little. There are different types of memory as we see on the map returned from BIOS INT 0x15 Function 0xE820. So the way I want to organize them is by enabling paging. When creating the page tables I want to put first all the pages that have type 1 page frames, then all the pages that have type 2 page frames, and so on. The problem I run into is that the sizes of some fields are not divisible by 4096. So, for example, what would I do if I encounter a type 2 field that's 2048 bytes long? I can't skip it just like that, it may be important. But I can't make a page frame out of it because it's not long enough. If I map a page to the beginning of such a field, the last 2048 bytes of the page will hang over to the next field which may be, say, a type 4 field. So what will happen is, I'll wind up with some type 2 memory, some type 4 memory and some more type 2 memory. But that's not in order! Is there any way I can do this?
I ignore any memory that is partly reserved. This is the map for my current machine. I ignore the page at 9f000. If a page is partly reserved then I reserve it all.

Code: Select all

E820 info:
Memory   : base:000000000000 length:00000009f400 end:00000009f400 npages=159
Reserved : base:00000009f400 length:000000000c00 end:0000000a0000 npages=0
Reserved : base:0000000dc000 length:000000024000 end:000000100000 npages=36
Memory   : base:000000100000 length:00003fdf0000 end:00003fef0000 npages=261616
ACPI recl: base:00003fef0000 length:00000000f000 end:00003feff000 npages=15
ACPI NVS : base:00003feff000 length:000000001000 end:00003ff00000 npages=1
Memory   : base:00003ff00000 length:000000100000 end:000040000000 npages=256
Reserved : base:0000f0000000 length:000008000000 end:0000f8000000 npages=32768
Reserved : base:0000fec00000 length:000000010000 end:0000fec10000 npages=16
Reserved : base:0000fee00000 length:000000001000 end:0000fee01000 npages=1
Reserved : base:0000fffe0000 length:000000020000 end:000100000000 npages=32

Re: Organizing Memory

Posted: Wed May 06, 2015 1:55 pm
by Isaac
gerryg400 wrote:I ignore any memory that is partly reserved. This is the map for my current machine. I ignore the page at 9f000. If a page is partly reserved then I reserve it all.
I think type 2 memory might also include memory mapped I/O in which case you can't ignore it. But I'm not sure about that.

Re: Organizing Memory

Posted: Wed May 06, 2015 3:21 pm
by gerryg400
Type 2 is reserved. Don't map it. If any part of a page is reserved then treat it all as reserved.

If later on you find that some MMIO is in the reserved area map it then.

Re: Organizing Memory

Posted: Thu May 07, 2015 1:48 am
by Combuster
Isaac wrote:
gerryg400 wrote:I ignore any memory that is partly reserved. This is the map for my current machine. I ignore the page at 9f000. If a page is partly reserved then I reserve it all.
I think type 2 memory might also include memory mapped I/O in which case you can't ignore it. But I'm not sure about that.
There are so many things that aren't memory. They all share the same thing: you don't have to guess where they are. You know the address in advance.