[ipxe-devel] can ipxe recognise if disk exist?

Levente LEVAI levail at aviatronic.hu
Fri Apr 13 19:09:45 UTC 2012


> Hello Levente,
>
> You wrote:
>> I have a similar hack to check if the cpu is 64 or 32 bits. Let me know if someone needs it.
> Please send it.
>
> cheers,
> -a
Since there are some people who are interested in them I provide my little
monstrosities. I do it in the good faith that if someone finds them useful,
he will work on them and turn them into something neat that is 
consistent with
ipxe code base (which is a remarkably well organized piece of software).

A few words of warning concerning these *hacks* (since that's what they 
are,
don't be mistaken):
-local hdd count: Don't be surprised if your usb sticks (sdcards, 
whatever) are counted
  as hdds. Standard PC-BIOS puts the number of devices it considers 
'hdd's at 0x00000475.
  Now, BIOSes tend to list usb mass storage devices as hard drives. To 
my knowledge
  there is no standard api in PC-BIOS that is implemented at least by a 
reasonable
  number of BIOSes that lets one read hardware information on hdds 
(otherwise perfectly
  well known to the BIOS).
-32/64 bitness: Please be warned that the code below works only on 
ia32/amd64 cpus
  from about Pentium onwards (I think). Other x86 cpus (286,386 or 486) 
will probably
  crash on this code. If somebody takes the time to implement a proper 
ipxe setting
  please follow the (lengthy and painful) procedure in the Intel docs 
according to the
  rules of chivalry.

Below is the recipie for the 'iscpu64' stuff:
In the file src/core/main.c:

-add  the include
#include <realmode.h>

-add these variables in main() to the variable declarations:
     unsigned long  is_cpu_64bit;
     char        sname[32];
     char        sval[32];

-still in main() search for the call to initialise() and startup(), and
  put this code after them:

     //this is a bit loose here,
     //we assume cpuid works (i.e. we have pentium or newer cpu)
     is_cpu_64bit = 0xbabeface;
     __asm__ __volatile__ ( "push %%ebx\n\t"
                    "movl $0x80000000,%%eax\n\t"
                    "cpuid\n\t"
                    "cmpl $0x80000001,%%eax\n\t"
                    "jb 1f\n\t"
                    "movl $0x80000001,%%eax\n\t"
                    "cpuid\n\t"
                    "andl $0x20000000,%%edx\n\t"
                    "jmp 2f\n\t"
                    "\n1:\n\t"
                    "xorl %%edx,%%edx\n\t"
                    "\n2:\n\t"
                    "pop %%ebx\n\t"
                   : "=d" ( is_cpu_64bit )
                   :
                   : "eax", "ecx" );
     memset ( sname, 0, sizeof ( sname ) );
     strncpy ( sname, "iscpu64", sizeof ( sname ) - 1 );
     memset ( sval, 0, sizeof ( sval ) );
     sval[0] = ( is_cpu_64bit ) ? '1' : '0';
     storef_named_setting ( sname, sval );

/levente
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ipxe.org/pipermail/ipxe-devel/attachments/20120413/660547f5/attachment.htm>


More information about the ipxe-devel mailing list