Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Jun 2001 17:45:10 -0400
From:      Brian Mitchell <bem@atlanta-bsd.org>
To:        freebsd-hackers@freebsd.org
Subject:   Fwd: Re: i386/26994: AMD Athlon Thunderbird not known to identcpu.c
Message-ID:  <01061617451003.00289@bandicoot.atlanta-bsd.org>

next in thread | raw e-mail | index | archive | help
curses, sent it to a nonexistant mail address before. Anyways, does anyone 
have any time to look at this, and tell me why it's a bad idea?


----------  Forwarded Message  ----------
Subject: Re: i386/26994: AMD Athlon Thunderbird not known to identcpu.c
Date: Sat, 16 Jun 2001 17:32:06 -0400
From: Brian Mitchell <bem@atlanta-bsd.org>
To: freebsd-gnats-submit@FreeBSD.org, venglin@freebsd.lublin.pl



I don't have a thundrbird, but has far as I know, k6-2+ supports the extended
cpuid functions, so something like the following may be appropriate. This
worked on my k6-2 and didnt break on any of my other machines (without the
#if defined guards, in my case), but I don't know if there are some oddball
686es that either dont support cpuid or dont support service 0x80000000 AND
do bad things when recieving it.


*** identcpu.c.old	Sat Jun 16 16:39:34 2001
--- identcpu.c	Sat Jun 16 17:19:16 2001
***************
*** 75,80 ****
--- 75,81 ----
  static void print_AMD_info(u_int amd_maxregs);
  static void print_AMD_assoc(int i);
  static void do_cpuid(u_int ax, u_int *p);
+ static int do_ExtendedCPUID(char *buff);

  u_int	cyrix_did;		/* Device ID of Cyrix CPU */
  int cpu_class = CPUCLASS_386;	/* least common denominator */
***************
*** 214,220 ****
  					cpu = CPU_PIII;
  					break;
  				default:
! 				        strcat(cpu_model, "Unknown 80686");
  					break;
  				}
  				break;
--- 215,222 ----
  					cpu = CPU_PIII;
  					break;
  				default:
! 					if(do_ExtendedCPUID(cpu_model) < 0)
! 				        	strcat(cpu_model, "Unknown 80686");
  					break;
  				}
  				break;
***************
*** 223,229 ****
  				cpu = CPU_P4;
  				break;
  			default:
! 				strcat(cpu_model, "unknown");
  				break;
  			}

--- 225,232 ----
  				cpu = CPU_P4;
  				break;
  			default:
! 				if(do_ExtendedCPUID(cpu_model) < 0)
! 					strcat(cpu_model, "unknown");
  				break;
  			}

***************
*** 303,309 ****
  			strcat(cpu_model, "K6-III");
  			break;
  		default:
! 			strcat(cpu_model, "Unknown");
  			break;
  		}
  #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
--- 306,313 ----
  			strcat(cpu_model, "K6-III");
  			break;
  		default:
! 			if(do_ExtendedCPUID(cpu_model) < 0)
! 				strcat(cpu_model, "Unknown");
  			break;
  		}
  #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
***************
*** 1001,1003 ****
--- 1005,1078 ----
  		"\0403DNow!"
  		);
  }
+
+ /*
+  * Get the model of the cpu if it is supported by the processor. This
+  * is probably the ideal way to determine the name of the cpu, if it
+  * is supported.
+  *
+  * Documentation on this can be found at:
+  *
http://developer.intel.com/design/processor/future/manuals/Cpuid_supplement.p
df +  */
+ static int
+ do_ExtendedCPUID(char *buff)
+ {
+ #if defined(I686_CPU)
+ 	char cpustring[128];
+ 	unsigned int extCpuidFunc=0;
+
+ 	/* get the highest cpuid extended func supported */
+ 	__asm ("
+ 	movl $0x80000000, %%eax
+ 	cpuid
+ 	movl %%eax, %0"
+ 	: "=g" (extCpuidFunc)
+ 	:
+ 	: "eax");
+
+ 	/*
+ 	 * if 0x80000002 - 0x80000004 are not supported, than this processor
+ 	 * will not supply us the information we need. We should gracefully
+ 	 * exit in that case.
+ 	 */
+ 	if(extCpuidFunc < 0x80000004)
+ #endif
+ 		return -1;
+ #if defined(I686_CPU)
+
+ 	/*
+ 	 * we can now use cpuid services 0x80000002-0x80000004 in order to
+ 	 * fill our buffer 16 bytes at a time (total buffer provided can
+ 	 * be up to 48 bytes).
+ 	 */
+ 	__asm ("
+ 	cld
+ 	lea (%0), %%edi
+ 	movl $0x80000002, %%eax
+ 	cpuid
+ 	movl %%eax, (%%edi)
+ 	movl %%ebx, 4(%%edi)
+ 	movl %%ecx, 8(%%edi)
+ 	movl %%edx, 12(%%edi)
+ 	addl $16, %%edi
+ 	movl $0x80000003, %%edi
+ 	cpuid
+ 	movl %%eax, (%%edi)
+ 	movl %%ebx, 4(%%edi)
+ 	movl %%ecx, 8(%%edi)
+ 	movl %%edx, 12(%%edi)
+ 	addl $16, %%edi
+ 	movl $0x80000004, %%eax
+ 	cpuid
+ 	movl %%eax, (%%edi)
+ 	movl %%ebx, 4(%%edi)
+ 	movl %%ecx, 8(%%edi)
+ 	movl %%edx, 12(%%edi)"
+ 	:
+ 	: "g" (cpustring)
+ 	: "eax", "ebx", "ecx", "edx", "esp");
+ 	strcat(buff, cpustring);
+ 	return 0;
+ #endif
+ }
+

-------------------------------------------------------

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01061617451003.00289>