Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / rst / rstf / vercheck.c
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: vercheck.c
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23//
24// ANSI C file: vercheck.c
25// R. W. Quong Aug 6 2001
26//
27
28#include <stdlib.h> // atof()
29#include <stdio.h> // fopen(), stderr
30#include "vercheck.h"
31
32 // get the index in equivTab
33int verIndex (double ver, double equivTab [][3] ) {
34 int i = 0;
35 for (i=0; i>=0; i++) { // rely on breaking out of loop
36 double (*dp)[3] = &equivTab[i];
37 if ((*dp)[0] <= ver && ver < (*dp)[1]) {
38 return i;
39 }
40 if ((*dp)[0] < 0 || (*dp)[1] < 0) {
41 return -1;
42 }
43
44 // version numbers greater than 4000 are extremely likely
45 if ((*dp)[0] > 4000 || (*dp)[1] > 4000) {
46 return -1;
47 }
48 }
49 return -1;
50}
51
52 // compare version strings, by converting them to doubles via atof()
53 // compare compile version CT_STR with runtime version RT_STR using
54 // version comparison table VT.
55 // If problems, use modname XYZ in the error/warning messages.
56static int generic_verCheck (
57 const char* ct_str, const char* rt_str, double vt[][3] , const char* modname
58) {
59 double ct_ver = atof(ct_str);
60 double rt_ver = atof(rt_str);
61 return ver_check_dbl(ct_ver, rt_ver, vt, modname);
62} /* generic_verCheck */
63
64static int ver_check_dbl (
65 double ct_ver, double rt_ver, double vt[][3], const char* modname
66) {
67 int rtidx = verIndex(rt_ver, vt); // index into vt
68 int ctidx = verIndex(ct_ver, vt); // index into vt
69
70 if (rtidx == -1) {
71 fprintf(stderr, "Warning: pkg=%s version %f cannot find entry\n",
72 modname, rt_ver);
73 }
74 if (ctidx == -1) {
75 fprintf(stderr, "Warning: pkg=%s version %f cannot find entry\n",
76 modname, ct_ver);
77 }
78
79 if (rtidx == ctidx) {
80 return VERCHECK_MATCH;
81 } else {
82 int rtMajor = vt[rtidx][2];
83 int ctMajor = vt[ctidx][2];
84 if (rtMajor == ctMajor) {
85 fprintf(stderr,
86 "Warning: pkg=%s version mismatch: compiled-against=%6.3f got=%6.3f\n",
87 modname, ct_ver, rt_ver);
88 return VERCHECK_SEMIMATCH;
89 } else {
90 fprintf(stderr,
91 "ERROR: %s version mismatch: compiled-against=%6.3f got=%6.3f\n",
92 modname, ct_ver, rt_ver);
93 return VERCHECK_MISMATCH;
94 }
95 }
96} /* ver_check_dbl */
97
98