Thomas Matthews said:
Hi,
How can the processor architecture/capabilities [like 16 bit/32 bit]
be determined using a c program? I wanted to know how an OS
installer/loader determines this while installing the OS on a fresh
system.
ISO C uses an abstract machine, and provide no way of
telling you what the underlying HW is. Your question is
off-topic in c.l.c.
I do believe that this information must be provided
during installation or creation of the operating system.
Why answer an off-topic request, if you don't know?
Hosted and freestanding programs are built for different
targets.. e.g. you can't use an OS kernel built for MIPS,
on x86 architecture. Hence, unless there exists a
CPU-independent opcode format, different CPU
architectures need different images.
The abstract C machine, doesn't provide interface like the
Java VM environment do. Therefore, C programs need to
be installed by selecting the correct CPU-architecture
manually.
Of course, an OS installer can be hosted, just put it on a
bootable floppy or CD-ROM!
If processors are very friendly, you can interrogate them.
Otherwise you have to consult their data sheets.
Well, detecting the model of a modern Intel CPU, is a
one-liner from C programs (with the use of inline asm).
AMD and other x86 clones provide another CPU vendor
string than "Genuine Intel":
http://www.paradicesoftware.com/specs/cpuid/index.htm
Detecting older Intel CPU's however, is more of a
challenge:
http://www.ddj.com/documents/s=957/ddj9609o/
</OT mode= off>