Code: Select all
outport(0x70,0x31);
highmem = inportb(0x71);
highmem =highmem << 8;
writeln("\nHIGHMEM: ");
writeint(highmem/1024);
writeln(" MB");
Is there any way by which I could detect memory more than 64MB.
Code: Select all
outport(0x70,0x31);
highmem = inportb(0x71);
highmem =highmem << 8;
writeln("\nHIGHMEM: ");
writeint(highmem/1024);
writeln(" MB");
That isn't foolproof either. Just for fun, go into your BIOS settings a see if there's a "OS/2 Compatible Mode" (it might be called something else, and is more likely on computers from Pentium to Pentium III) that can be enabled/disabled. If enabled (IIRC), this will make a "hole" in physical memory from 15 MB to 16 MB, so a computer with 32 MB installed will have RAM up to 0x00F00000, then nothing from 0x00F00000 to 0x01000000 and more RAM from 0x01000000 to 0x02100000.NotTheCHEAT wrote:Of course, it isn't fool-proof. I might add some sort of manual override, so the user can type in the true amount of memory that they have (in case the result returned by this is not the right amount).
I don't say "just use GRUB", and never will. My recommendation is: use GRUB or detect memory with the BIOS functions (see the link to Chris Giese's code posted earlier).NotTheCHEAT wrote:Maybe I should just go back to using a real mode bootloader, so I can check this type of thing at startup. Or maybe I should give in to everyones saying that I should use GRUB "or else my teeth will fall out and all my relatives will die".
Code: Select all
unsigned int ext_MEM(void)
{
unsigned char lowmem, highmem;
unsigned int total;
outportb(0x70, 0x30);
lowmem = inportb(0x71);
outportb(0x70, 0x31);
highmem = inportb(0x71);
asm mov ah, highmem;
asm mov al, lowmem;
asm mov total, ax;
return total + 1024;
}
unsigned int base_MEM(void)
{
unsigned char lowmem, highmem;
unsigned int total;
outportb(0x70, 0x15);
lowmem = inportb(0x71);
outportb(0x70, 0x16);
highmem = inportb(0x71);
asm mov ah, highmem;
asm mov al, lowmem;
asm mov total, ax;
return total;
}
No, you're still limited to the CMOS' limits, which is 2 bytes for the total amount of memory.Codemaster Snake wrote:
And I think that CMOS can return more than 99MB if one use 32bit registers.... plz Correct me if i am wrong...
The CMOS value itself is only a legacy thing, and IMHO modern OSs shouldn't rely on it - there's no "CMOS location standard" that specifies exactly what each location in the CMOS must contain, if you see what I mean. The only thing that makes it work most of the time is that BIOS manufacturers like to maintain backwards compatibility where possible.Codemaster Snake wrote:But if we are limited to CMOS limitations then how does one detect physical ram in PM
Are you sure? It seems possible that you may not want to use the BIOS because you didn't do enough research when you wrote your bootloader, and now it's too hard to add real mode memory detection code to the boot sequence (it won't fit in 512 bytes perhaps). I can't think of any other reason why someone might try so hard to avoid the only sane/reliable method of detecting memory....Codemaster Snake wrote:Reason I am not using BIOS is because I don't like to...... Rather I like to use direct approach with ports and pointers..
The CMOS value itself is only a legacy thing, and IMHO modern OSs shouldn't rely on it - there's no "CMOS location standard" that specifies exactly what each location in the CMOS must contain, if you see what I mean.[/quote
That's wrong, the CMOS contains the system time. How else are we supposed to know what time it is if we don't use the CMOS?
But I do agree. CMOS is legacy, and cannot be relied upon for many things.
I added code to my bootloader that uses INT 15h AX=E801h to detect memory size. This may not work in older computers, unfortunately, but space was limited and I wanted to be able to get the memory size. I will add code to my kernel so that if it didn't work, the kernel will probe past the value stored in CMOS. This may not be ideal, but it's what works for me, and for most modern computers it will be able to use the BIOS.
@smiddy: Can you give some code for using the PnP BIOS (to do anything)? It would be helpful... or at least if you could give some links for more information.