OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
7 #include <string.h> | |
8 | |
9 #include "native_client/src/shared/platform/nacl_log.h" | |
10 #include "native_client/src/trusted/validator_mips/cpuid_mips.h" | |
11 | |
12 | |
13 void NaClSetAllCPUFeaturesMips(NaClCPUFeatures *f) { | |
14 /* TODO(jfb) Use a safe cast in this interface. */ | |
15 NaClCPUFeaturesMips *features = (NaClCPUFeaturesMips *) f; | |
16 /* Pedantic: avoid using memset, as in x86's nacl_cpuid.c. */ | |
17 int id; | |
18 /* Ensure any padding is zeroed. */ | |
19 NaClClearCPUFeaturesMips(features); | |
20 for (id = 0; id < NaClCPUFeatureMips_Max; ++id) { | |
21 NaClSetCPUFeatureMips(features, id, 1); | |
22 } | |
23 } | |
24 | |
25 void NaClGetCurrentCPUFeaturesMips(NaClCPUFeatures *f) { | |
26 /* TODO(jfb) Use a safe cast in this interface. */ | |
27 NaClCPUFeaturesMips *features = (NaClCPUFeaturesMips *) f; | |
28 features->data[NaClCPUFeatureMips_BOGUS] = 0; | |
29 } | |
30 | |
31 /* This array defines the CPU feature model for fixed-feature CPU mode. */ | |
32 static const int kFixedFeatureMipsCPUModel[NaClCPUFeatureMips_Max] = { | |
33 0 /* NaClCPUFeatureMips_BOGUS */ | |
34 }; | |
35 | |
36 int NaClFixCPUFeaturesMips(NaClCPUFeatures *f) { | |
37 /* TODO(jfb) Use a safe cast in this interface. */ | |
38 NaClCPUFeaturesMips *features = (NaClCPUFeaturesMips *) f; | |
39 NaClCPUFeatureMipsID fid; | |
40 int rvalue = 1; | |
41 | |
42 for (fid = 0; fid < NaClCPUFeatureMips_Max; fid++) { | |
43 if (kFixedFeatureMipsCPUModel[fid]) { | |
44 if (!NaClGetCPUFeatureMips(features, fid)) { | |
45 /* This CPU is missing a required feature. */ | |
46 NaClLog(LOG_ERROR, | |
47 "This CPU is missing a feature required by fixed-mode: %s\n", | |
48 NaClGetCPUFeatureMipsName(fid)); | |
49 rvalue = 0; /* set return value to indicate failure */ | |
50 } | |
51 } else { | |
52 /* Feature is not in the fixed model. | |
53 * Ensure cpu_features does not have it either. | |
54 */ | |
55 NaClSetCPUFeatureMips(features, fid, 0); | |
56 } | |
57 } | |
58 return rvalue; | |
59 } | |
60 | |
61 void NaClSetCPUFeatureMips(NaClCPUFeaturesMips *f, NaClCPUFeatureMipsID id, | |
62 int state) { | |
63 f->data[id] = (char) state; | |
64 } | |
65 | |
66 const char *NaClGetCPUFeatureMipsName(NaClCPUFeatureMipsID id) { | |
67 static const char *kFeatureMipsNames[NaClCPUFeatureMips_Max] = { | |
68 # define NACL_MIPS_CPU_FEATURE(name) NACL_TO_STRING(name), | |
69 # include "native_client/src/trusted/validator_mips/cpuid_mips_features.h" | |
70 # undef NACL_MIPS_CPU_FEATURE | |
71 }; | |
72 return ((unsigned)id < NaClCPUFeatureMips_Max) ? | |
73 kFeatureMipsNames[id] : "INVALID"; | |
74 } | |
75 | |
76 void NaClClearCPUFeaturesMips(NaClCPUFeaturesMips *features) { | |
77 memset(features, 0, sizeof(*features)); | |
78 } | |
OLD | NEW |