I use cpp but I'm looking for a library or asm code I can use to detect the amount of installed memory, coresize() only goes up to 640k and does not work in Pmode. I i would like to be able to tell if the CPU it a
1. 80086/80088/80186/80286
2. 80386/80486
3. 80586 (Pentium class)
4. 80686 (Pentium Pro - PIV)
Thanks
Memsize and CPU ID
RE:Memsize and CPU ID
search for "detecting cpu type in asm" (or similar) on google, and you'll find lots of helpful information. You'll have to use asm for this, btw.
Detecting CPUs up to the 486 should be done using the (e)flags register (different CPU generations support different flags). Set the flag in question, and reload (e)flags into a register, and test if the flag was properly set. If so, the CPU type supports that flag, and you can say the CPU is _at least_ an 80x86 (you can find the proper flags to set on any of the above sites... I can't recall offhand what they are).
Late 486's, and all pentium class systems should support the CPUID opcode, and should be used for these systems (it'll give much more information, such as the stepping, etc) (I believe you can also test for the availability of the CPUID opcode though the eflags register).
If you need a more specific site, I can probably find you one, but I think you'll be able to find the info you're looking for on google. If you can find someone with a copy of tasm, there's an assembly example to detect CPU versions supplied with it.
Jeff
Detecting CPUs up to the 486 should be done using the (e)flags register (different CPU generations support different flags). Set the flag in question, and reload (e)flags into a register, and test if the flag was properly set. If so, the CPU type supports that flag, and you can say the CPU is _at least_ an 80x86 (you can find the proper flags to set on any of the above sites... I can't recall offhand what they are).
Late 486's, and all pentium class systems should support the CPUID opcode, and should be used for these systems (it'll give much more information, such as the stepping, etc) (I believe you can also test for the availability of the CPUID opcode though the eflags register).
If you need a more specific site, I can probably find you one, but I think you'll be able to find the info you're looking for on google. If you can find someone with a copy of tasm, there's an assembly example to detect CPU versions supplied with it.
Jeff
RE:Memsize and CPU ID
Thanks, my Boland compiler 5.02 regonzies the _FLAG and CPU id works with 16-bit DOS; however watcom does not know _FLAG (on any platform), any ideas? And what about memsize?
RE:Memsize and CPU ID
You'll either have to assemble the functions in an external .asm file, and link them into your C code, or use inline assembly.
The former is a little more portable (seeing as though every compiler supports inline assembly differently), but perhaps not as convenient.
Memory size is a controversial topic. There are many ways to find out the ammount and "types" (r/w, MMIO, etc) and locations of memory, but not all are overly reliable.
The BIOS provides a (few?) ways of determining memory but, from what I've heard, is only reliable on newer BIOSs (int 15, ah=?? comes to mind, but that's all I can remember!).
I used to use direct probing to find the size of memory, but this is brutally unreliable and poses many difficult issues (holes in memory, and memory mapped IO can mess up this technique... among other things, I'm sure).
Most people on this list, I believe, are using GRUB, which will give your kernel a memory map upon booting it, if you request it. Personally, I think this is probably your best bet, simply because errors/ommissions in GRUB will, no doubt, get detected and fixed quite quickly.
Alternately, you could take a look at the GRUB sources, and see how it actually detects memory (which is probably a combination of the above, and more) and use those routines in your kernel.
Cheers,
Jeff
The former is a little more portable (seeing as though every compiler supports inline assembly differently), but perhaps not as convenient.
Memory size is a controversial topic. There are many ways to find out the ammount and "types" (r/w, MMIO, etc) and locations of memory, but not all are overly reliable.
The BIOS provides a (few?) ways of determining memory but, from what I've heard, is only reliable on newer BIOSs (int 15, ah=?? comes to mind, but that's all I can remember!).
I used to use direct probing to find the size of memory, but this is brutally unreliable and poses many difficult issues (holes in memory, and memory mapped IO can mess up this technique... among other things, I'm sure).
Most people on this list, I believe, are using GRUB, which will give your kernel a memory map upon booting it, if you request it. Personally, I think this is probably your best bet, simply because errors/ommissions in GRUB will, no doubt, get detected and fixed quite quickly.
Alternately, you could take a look at the GRUB sources, and see how it actually detects memory (which is probably a combination of the above, and more) and use those routines in your kernel.
Cheers,
Jeff
RE:Memsize and CPU ID (General Stuff on my OS)
Thanks again, actually I'm using the DOS4/GW, which is a 32-bit DOS PMODE Extender. This extender sets the memory of so I have 4 GB max physical memory and a 16 MB swap file. Its handles everything so I can use new and delete for dynamic memory allocation. Here is how my OS is so far. I have multitasking working using the ANSI standard SetJmp.h functions.
Startup:
-Computer Starts
-Command.com, IO.SYS etc load
-Autoexec.bat loads Kernel16.exe (16-bit DOS)
(hardware detection using the BIOS, swap file setup, etc)
-Autoexec.bat loads Kernel32.exe (32-bit DOS with DOS4GW)
Loading a Program (A.exe):
-Kernel places the ptr to a jump buffer in a file (A.ptr)
-Kernel calls program (system("adirect/A.exe");)
-A.exe places pointers to its communication buffers in A.ptr and return to the kernel via the buffer
-The kernel includes the communication and buffers into its Process class
-Multitasking continues
I'm trying to use allegro for graphics but I can't figure out how to set it up. Such as where I put the allegro headers and such.
What do you think?
-VoidLogic
Startup:
-Computer Starts
-Command.com, IO.SYS etc load
-Autoexec.bat loads Kernel16.exe (16-bit DOS)
(hardware detection using the BIOS, swap file setup, etc)
-Autoexec.bat loads Kernel32.exe (32-bit DOS with DOS4GW)
Loading a Program (A.exe):
-Kernel places the ptr to a jump buffer in a file (A.ptr)
-Kernel calls program (system("adirect/A.exe");)
-A.exe places pointers to its communication buffers in A.ptr and return to the kernel via the buffer
-The kernel includes the communication and buffers into its Process class
-Multitasking continues
I'm trying to use allegro for graphics but I can't figure out how to set it up. Such as where I put the allegro headers and such.
What do you think?
-VoidLogic
RE:Memsize and CPU ID (General Stuff on my OS)
Sounds good, man.
Does Allegro support DOS4GW? I know it was originally developed for DJGPP, which usually uses CWSDPMI, and perhaps Allegro uses features specific to CWSDPMI? Probably not, but I'd definitly check that DOS4GW is fully supported before trying to include allegro into your build.
As for graphics, I'm not fully aware of how Allegro handles it resources. Graphics programming is my speciality, especially at the low level, so I can probably help you with specific questions, but I don't know how useful I'd be in implemented Allegro.
DJGPP maintains a __djgpp_conventional_base variable which Allegro will, no doubt, rely upon. This is a pointer to the current location of the first 1MB of memory (seeing as though pmode can move it about). Therefore, graphics memory should always be referenced asd (__djgpp_conventional_base + 0xB8000), and even then, only after a call to djgpp_nearptr_enable().
Personally, I think your best bet might be to implement the low level graphics acceess code yourself, and use Allegro for specific algorithmns and what-not (such as drawing lines, circles, polygons, etc).
My graphics library (petal) can be found on http://www.neuraldk.org and contains a graphics system much simpler then Allegro, and might be easier to follow. I do admit, though, the code is fairly complex at parts (due to strangely hand-optomized code) and can get confusing... but, like I said, I can help you out with that stuff.
I'm currently working on Petal 2.0, which is a much more advanced (and better coded) library, which has an emphasis on easy integration into new OSs (as such it currently has preliminary support for window management, and a graphics toolkit). When I update my web site (hopefully soon... although working 2 jobs is killing my free time!) I should have links to the current Petal 2.0 source (and at least a Linux binary, but probably also Win32 and QNX, and possible BeOS binaries as well).
Cheers,
Jeff
Does Allegro support DOS4GW? I know it was originally developed for DJGPP, which usually uses CWSDPMI, and perhaps Allegro uses features specific to CWSDPMI? Probably not, but I'd definitly check that DOS4GW is fully supported before trying to include allegro into your build.
As for graphics, I'm not fully aware of how Allegro handles it resources. Graphics programming is my speciality, especially at the low level, so I can probably help you with specific questions, but I don't know how useful I'd be in implemented Allegro.
DJGPP maintains a __djgpp_conventional_base variable which Allegro will, no doubt, rely upon. This is a pointer to the current location of the first 1MB of memory (seeing as though pmode can move it about). Therefore, graphics memory should always be referenced asd (__djgpp_conventional_base + 0xB8000), and even then, only after a call to djgpp_nearptr_enable().
Personally, I think your best bet might be to implement the low level graphics acceess code yourself, and use Allegro for specific algorithmns and what-not (such as drawing lines, circles, polygons, etc).
My graphics library (petal) can be found on http://www.neuraldk.org and contains a graphics system much simpler then Allegro, and might be easier to follow. I do admit, though, the code is fairly complex at parts (due to strangely hand-optomized code) and can get confusing... but, like I said, I can help you out with that stuff.
I'm currently working on Petal 2.0, which is a much more advanced (and better coded) library, which has an emphasis on easy integration into new OSs (as such it currently has preliminary support for window management, and a graphics toolkit). When I update my web site (hopefully soon... although working 2 jobs is killing my free time!) I should have links to the current Petal 2.0 source (and at least a Linux binary, but probably also Win32 and QNX, and possible BeOS binaries as well).
Cheers,
Jeff
RE:Memsize and CPU ID
Hello here is the source code in cpp for getting extended memory
#if !defined (__STDIO_H)
#include <stdio.h>
#endif
#if !defined (__DOS_H)
#include <dos.h>
#endif
#if !defined (PRAGMAINLINE)
#pragma inline
#endif
const int CMOS_PORT_WRITE = 0x70;
const int CMOS_PORT_READ = 0x71;
class MinimumMemory
{
public:
MinimumMemory(){}
~MinimumMemory(){}
int GetCmos(unsigned char low, unsigned char high);
int MemoryTest();
private:
unsigned MemorySize;
};
int
MinimumMemory :: MemoryTest()
{
int i = GetCmos( 0x30, 0x31 );// Get extended detected during POST
if (MemorySize > (4 * 1028)) //checking for greater than 4MB or not
return 1;
else
return 0;
}
int
MinimumMemory :: GetCmos(unsigned char Low, unsigned char High)
{
unsigned char *Temp;
unsigned char l, h;
Temp = (unsigned char *) &MemorySize;
disable();
outportb(CMOS_PORT_WRITE, High);
asm jmp short $ + 2
h = inportb(CMOS_PORT_READ);
outportb(CMOS_PORT_WRITE, Low);
asm jmp short $ + 2
l = inportb(CMOS_PORT_READ);
*Temp = l;
*(Temp + 1) = h;
enable();
return 1;
}
int main()
{
MinimumMemory min;
int flag = min.MemoryTest();
if(flag == 1)
{
printf("OK Memory Tested Oked");
}
else
{
printf("Sorry Memory test fail");
}
return(0);
}
and for getting cpu asm code is needed. the procedure written in asm can be called from c++ to get cpu.
best of luck
Chaand
#if !defined (__STDIO_H)
#include <stdio.h>
#endif
#if !defined (__DOS_H)
#include <dos.h>
#endif
#if !defined (PRAGMAINLINE)
#pragma inline
#endif
const int CMOS_PORT_WRITE = 0x70;
const int CMOS_PORT_READ = 0x71;
class MinimumMemory
{
public:
MinimumMemory(){}
~MinimumMemory(){}
int GetCmos(unsigned char low, unsigned char high);
int MemoryTest();
private:
unsigned MemorySize;
};
int
MinimumMemory :: MemoryTest()
{
int i = GetCmos( 0x30, 0x31 );// Get extended detected during POST
if (MemorySize > (4 * 1028)) //checking for greater than 4MB or not
return 1;
else
return 0;
}
int
MinimumMemory :: GetCmos(unsigned char Low, unsigned char High)
{
unsigned char *Temp;
unsigned char l, h;
Temp = (unsigned char *) &MemorySize;
disable();
outportb(CMOS_PORT_WRITE, High);
asm jmp short $ + 2
h = inportb(CMOS_PORT_READ);
outportb(CMOS_PORT_WRITE, Low);
asm jmp short $ + 2
l = inportb(CMOS_PORT_READ);
*Temp = l;
*(Temp + 1) = h;
enable();
return 1;
}
int main()
{
MinimumMemory min;
int flag = min.MemoryTest();
if(flag == 1)
{
printf("OK Memory Tested Oked");
}
else
{
printf("Sorry Memory test fail");
}
return(0);
}
and for getting cpu asm code is needed. the procedure written in asm can be called from c++ to get cpu.
best of luck
Chaand