Author: petarj
Date: Sun Sep 15 22:49:01 2013
New Revision: 13551
Log:
mips32/mips64: rename mips32_features to mips_features
As this file is now detecting mips64/Cavium boards, we are renaming it to
reflect that. The functional change is that mips_features now can detect
Cavium board and allow Cavium-specific tests to be run.
Added:
trunk/tests/mips_features.c
Modified:
trunk/none/tests/mips32/mips32_dsp.vgtest
trunk/none/tests/mips32/mips32_dspr2.vgtest
trunk/tests/ (props changed)
trunk/tests/Makefile.am
trunk/tests/mips32_features.c
Modified: trunk/none/tests/mips32/mips32_dsp.vgtest
==============================================================================
--- trunk/none/tests/mips32/mips32_dsp.vgtest (original)
+++ trunk/none/tests/mips32/mips32_dsp.vgtest Sun Sep 15 22:49:01 2013
@@ -1,3 +1,3 @@
prog: mips32_dsp
-prereq: ../../../tests/mips32_features mips32-dsp
+prereq: ../../../tests/mips_features mips32-dsp
vgopts: -q
Modified: trunk/none/tests/mips32/mips32_dspr2.vgtest
==============================================================================
--- trunk/none/tests/mips32/mips32_dspr2.vgtest (original)
+++ trunk/none/tests/mips32/mips32_dspr2.vgtest Sun Sep 15 22:49:01 2013
@@ -1,3 +1,3 @@
prog: mips32_dspr2
-prereq: ../../../tests/mips32_features mips32-dspr2
+prereq: ../../../tests/mips_features mips32-dspr2
vgopts: -q
Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am (original)
+++ trunk/tests/Makefile.am Sun Sep 15 22:49:01 2013
@@ -26,7 +26,7 @@
true \
x86_amd64_features \
s390x_features \
- mips32_features
+ mips_features
AM_CFLAGS += $(AM_FLAG_M3264_PRI)
AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
Added: trunk/tests/mips_features.c
==============================================================================
--- trunk/tests/mips_features.c (added)
+++ trunk/tests/mips_features.c Sun Sep 15 22:49:01 2013
@@ -0,0 +1,101 @@
+// This file determines MIPS features a processor supports.
+//
+// We return:
+// - 0 if the machine matches the asked-for feature.
+// - 1 if the machine does not.
+// - 2 if the asked-for feature isn't recognised (this will be the case for
+// any feature if run on a non-MIPS machine).
+// - 3 if there was a usage error (it also prints an error message).
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#define FEATURE_PRESENT 0
+#define FEATURE_NOT_PRESENT 1
+#define UNRECOGNISED_FEATURE 2
+#define USAGE_ERROR 3
+
+#if defined(VGA_mips32) || defined(VGA_mips64)
+static int mipsCPUInfo(const char *search_string) {
+ const char *file_name = "/proc/cpuinfo";
+ /* Simple detection of MIPS DSP ASE at runtime for Linux.
+ * It is based on /proc/cpuinfo, which reveals hardware configuration
+ * to user-space applications. */
+
+ char cpuinfo_line[256];
+
+ FILE *f = NULL;
+ if ((f = fopen (file_name, "r")) == NULL)
+ return 0;
+
+ while (fgets (cpuinfo_line, sizeof (cpuinfo_line), f) != NULL)
+ {
+ if (strstr (cpuinfo_line, search_string) != NULL)
+ {
+ fclose (f);
+ return 1;
+ }
+ }
+
+ fclose (f);
+
+ /* Did not find string in the /proc/cpuinfo file. */
+ return 0;
+}
+
+static int go(char *feature)
+{
+ int cpuinfo;
+ if ( (strcmp(feature, "mips32-dsp") == 0)) {
+ const char *dsp = "dsp";
+ cpuinfo = mipsCPUInfo(dsp);
+ if (cpuinfo == 1) {
+ return FEATURE_PRESENT;
+ } else{
+ return FEATURE_NOT_PRESENT;
+ }
+ } else if ((strcmp(feature, "mips32-dspr2") == 0)) {
+ const char *dsp2 = "dsp2";
+ cpuinfo = mipsCPUInfo(dsp2);
+ if (cpuinfo == 1) {
+ return FEATURE_PRESENT;
+ } else{
+ return FEATURE_NOT_PRESENT;
+ }
+ } else if ((strcmp(feature, "cavium-octeon") == 0)) {
+ const char *cavium = "Cavium Octeon";
+ cpuinfo = mipsCPUInfo(cavium);
+ if (cpuinfo == 1) {
+ return FEATURE_PRESENT;
+ } else{
+ return FEATURE_NOT_PRESENT;
+ }
+ } else {
+ return UNRECOGNISED_FEATURE;
+ }
+
+}
+
+#else
+
+static int go(char *feature)
+{
+ /* Feature is not recognised. (non-MIPS machine!) */
+ return UNRECOGNISED_FEATURE;
+}
+
+#endif
+
+
+//---------------------------------------------------------------------------
+// main
+//---------------------------------------------------------------------------
+int main(int argc, char **argv)
+{
+ if (argc != 2) {
+ fprintf( stderr, "usage: mips_features <feature>\n" );
+ exit(USAGE_ERROR);
+ }
+ return go(argv[1]);
+}
|