Memory Allocation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Memory Allocation

Post by JoeTheProgrammer »

Do you have to get the total RAM size in order to initialize the memory manager? I think I am lost...but if I have the right idea, how do you get the total RAM size of the platform?

Please help,
Joseph
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Every good solution is obvious once you've found it.
JoeTheProgrammer
Member
Member
Posts: 48
Joined: Mon Aug 13, 2007 2:30 pm

Post by JoeTheProgrammer »

Thanks, as I did not see this in the wiki.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

JoeTheProgrammer wrote:
Thanks, as I did not see this in the wiki.
I can see that. Mediawiki's search engine sucks.
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

That article is next on my list to rewrite (probably within the next month). The rewrite process should make it easier to find, too.
User avatar
CmpXchg
Member
Member
Posts: 61
Joined: Mon Apr 28, 2008 12:14 pm
Location: Petrozavodsk, Russia during school months, Vänersborg Sweden in the summertime

Post by CmpXchg »

I noticed that an old DOS driver called HIMEM.SYS is capable of determining the amount of RAM on any machine, so it must contain a reliable algorythm.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

CmpXchg wrote:I noticed that an old DOS driver called HIMEM.SYS is capable of determining the amount of RAM on any machine, so it must contain a reliable algorythm.
DOS is realmode, isn't it? So wouldn't that driver just pull the memory map from the BIOS?
User avatar
CmpXchg
Member
Member
Posts: 61
Joined: Mon Apr 28, 2008 12:14 pm
Location: Petrozavodsk, Russia during school months, Vänersborg Sweden in the summertime

Post by CmpXchg »

JamesM wrote:DOS is realmode, isn't it? So wouldn't that driver just pull the memory map from the BIOS?
Yeah, it probably would. But what if the required BIOS functions are not supported? Do you think it never attempts to probe RAM directly?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

CmpXchg wrote:
JamesM wrote:DOS is realmode, isn't it? So wouldn't that driver just pull the memory map from the BIOS?
Yeah, it probably would. But what if the required BIOS functions are not supported? Do you think it never attempts to probe RAM directly?
I have no idea. I was merely postulating - hence the inquisitive tone and question marks ;)
User avatar
CmpXchg
Member
Member
Posts: 61
Joined: Mon Apr 28, 2008 12:14 pm
Location: Petrozavodsk, Russia during school months, Vänersborg Sweden in the summertime

Post by CmpXchg »

OK 8)
Here can we only guess...
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

CmpXchg wrote: I noticed that an old DOS driver called HIMEM.SYS is capable of determining the amount of RAM on any machine, so it must contain a reliable algorithm.
JamesM wrote: DOS is realmode, isn't it? So wouldn't that driver just pull the memory map from the BIOS?
Uh, no. HIMEM.SYS is the Extended Memory driver. I'm not sure exactly what mode the later versions of DOS actually did run in -- but with the "Huge Memory Model" and HIMEM.SYS, they were capable of addressing somewhere between 64MB and 4GB with "far pointers". (Yes, the "near" pointers were only 16 bit.)

DOS, however, is completely built on using BIOS functions to do all the hard work. I really doubt it uses manual probing at any point. I suspect that HIMEM.SYS exclusively used INT0x15 calls (up to E801, I'd bet).
User avatar
CmpXchg
Member
Member
Posts: 61
Joined: Mon Apr 28, 2008 12:14 pm
Location: Petrozavodsk, Russia during school months, Vänersborg Sweden in the summertime

Post by CmpXchg »

Thanks for your knowledgeable reply, bewing!

But what do you mean by "Huge Memory Model"?

As far as I know (or guess ;)), DOS itself utilizes real mode, but as soon as HIMEM.SYS loads, it switches the system into Protected mode, enables A20 and becomes kind of supervisor. As the result, the entire DOS session runs in V86, but it goes unnoticed for the most programs.

This fact turned my attention when I tried to read CR0 under DOS - the PE bit was set(!), which can only mean that the system ran under V86.

EDIT: sorry, I was mistaken. HIMEM.SYS doesn't switch the machine into protected mode, it merely enables A20 to allow the DOS kernel to be moved into HMA (that memory area of 65520 bytes starting at 0x10000h, the highest region process can access in real mode). But what really enters Protected Mode (and then starts a V86 task) is the memory manager EMM386.

I quite agree that HIMEM uses only BIOS functions to get memory size.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Compilers under DOS could use one of four possible "memory models". The choice affected the way that segment registers were handled in the assembled output.

1) Compact. The only choice for .COM programs. All code and data is contained in one 64K page, so all the segment registers are set to exactly the same values at load time, and never changed. Uses 16bit pointers.

2) Tiny. Code is on a separate page from data, but code < 64K and data < 64K. Again, the segment registers are never modified. Uses 16bit pointers.

3) Standard. Can access all low mem (640K), using segment:offset pointers for every memory access.

4) Huge. Uses 32bit flat memory pointers for all memory accesses.

I still use M$ QuickC to make .COM files whenever I need a quickie utility to do some little thing, and run it in a DOS window. :wink:
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

bewing wrote:3) Standard. Can access all low mem (640K), using segment:offset pointers for every memory access.
Not really. It usually uses one data segment of 64KB, with a heap allowing you to allocate more memory. To access structures on the heap, one uses pointers and pointer dereferencing, but 'normal' global variables are stored in the data segment, which is still limited to 64KB. As for code, it depends on the language and compiler used.
4) Huge. Uses 32bit flat memory pointers for all memory accesses.
Only available with a DOS extender, I presume? Or using unreal mode?


JAL
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Or,

Just use GRUB and tell it to give you memory information :D
Post Reply