wok-current rev 17057

syslinux/c32box: x86_64 auto select
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 21 09:56:57 2014 +0200 (2014-08-21)
parents 6dd4a6865e2e
children d5b427eca7f3
files syslinux/stuff/extra/md5sum.c
line diff
     1.1 --- a/syslinux/stuff/extra/md5sum.c	Thu Aug 21 03:51:54 2014 +0200
     1.2 +++ b/syslinux/stuff/extra/md5sum.c	Thu Aug 21 09:56:57 2014 +0200
     1.3 @@ -680,6 +680,7 @@
     1.4  #include <stdio.h>
     1.5  #include <string.h>
     1.6  #include <console.h>
     1.7 +#include <cpuid.h>
     1.8  #include <syslinux/loadfile.h>
     1.9  #include <syslinux/linux.h>
    1.10  #include <syslinux/pxe.h>
    1.11 @@ -757,6 +758,72 @@
    1.12      return cmdline;
    1.13  }
    1.14  
    1.15 +static bool __constfunc cpu_has_cpuid(void)
    1.16 +{
    1.17 +    return cpu_has_eflag(X86_EFLAGS_ID);
    1.18 +}
    1.19 +
    1.20 +static bool __constfunc cpu_has_level(uint32_t level)
    1.21 +{
    1.22 +    uint32_t group;
    1.23 +    uint32_t limit;
    1.24 +
    1.25 +    if (!cpu_has_cpuid())
    1.26 +	return false;
    1.27 +
    1.28 +    group = level & 0xffff0000;
    1.29 +    limit = cpuid_eax(group);
    1.30 +
    1.31 +    if ((limit & 0xffff0000) != group)
    1.32 +	return false;
    1.33 +
    1.34 +    if (level > limit)
    1.35 +	return false;
    1.36 +
    1.37 +    return true;
    1.38 +}
    1.39 +
    1.40 +/* This only supports feature groups 0 and 1, corresponding to the
    1.41 +   Intel and AMD EDX bit vectors.  We can add more later if need be. */
    1.42 +static bool __constfunc cpu_has_feature(int x)
    1.43 +{
    1.44 +    uint32_t level = ((x & 1) << 31) | 1;
    1.45 +
    1.46 +    return cpu_has_level(level) && ((cpuid_edx(level) >> (x & 31) & 1));
    1.47 +}
    1.48 +
    1.49 +static char *extfilename(char *filename, char *ext, int feature)
    1.50 +{
    1.51 +#define NEWFILENAMESZ 80
    1.52 +	static char newfilename[NEWFILENAMESZ+1];
    1.53 +	char *found = filename;
    1.54 +	FILE *fp;
    1.55 +
    1.56 +	if (strlen(filename) + strlen(ext) <= NEWFILENAMESZ) {
    1.57 +		strcpy(newfilename, filename, NEWFILENAMESZ);
    1.58 +		if (cpu_has_feature(feature)) {
    1.59 +			strcat(newfilename, ext);
    1.60 +			fp = fopen(newfilename, "r");
    1.61 +			if (fp)
    1.62 +				found = newfilename;
    1.63 +			fclose(fp);
    1.64 +		}
    1.65 +	}
    1.66 +	return found;
    1.67 +}
    1.68 +
    1.69 +static char *bestextfilename(char *filename)
    1.70 +{
    1.71 +	char *found;
    1.72 +
    1.73 +	//found = extfilename(filename, "fpu",   X86_FEATURE_FPU);
    1.74 +	//found = extfilename(filename, "686",   X86_FEATURE_CMOV);
    1.75 +	//found = extfilename(filename, "pae",   X86_FEATURE_PAE);
    1.76 +	found = extfilename(filename, "64",    X86_FEATURE_LM);
    1.77 +	//found = extfilename(filename, "guest", X86_FEATURE_HYPERVISOR);
    1.78 +	return found;
    1.79 +}
    1.80 +
    1.81  static int setup_data_file(struct setup_data *setup_data,
    1.82  			   uint32_t type, const char *filename,
    1.83  			   bool opt_quiet)
    1.84 @@ -780,6 +847,7 @@
    1.85  static int main_linux(int argc, char *argv[])
    1.86  {
    1.87      const char *kernel_name;
    1.88 +    const char *initrd_name;
    1.89      struct initramfs *initramfs;
    1.90      struct setup_data *setup_data;
    1.91      char *cmdline;
    1.92 @@ -812,7 +880,7 @@
    1.93  	return 1;
    1.94      }
    1.95  
    1.96 -    kernel_name = arg;
    1.97 +    kernel_name = bestextfilename(arg);
    1.98  
    1.99      errno = 0;
   1.100      boot_image = malloc(strlen(kernel_name) + 12);
   1.101 @@ -863,12 +931,13 @@
   1.102  	    if (p)
   1.103  		*p = '\0';
   1.104  
   1.105 +	    initrd_name = bestextfilename(arg);
   1.106  	    if (!opt_quiet)
   1.107 -		printf("Loading %s... ", arg);
   1.108 +		printf("Loading %s... ", initrd_name);
   1.109  	    errno = 0;
   1.110 -	    if (initramfs_load_archive(initramfs, arg)) {
   1.111 +	    if (initramfs_load_archive(initramfs, initrd_name)) {
   1.112  		if (opt_quiet)
   1.113 -		    printf("Loading %s ", kernel_name);
   1.114 +		    printf("Loading %s ", initrd_name);
   1.115  		printf("failed: ");
   1.116  		goto bail;
   1.117  	    }