Fix one bug in PeiMain to make it output correct ImageStartAddress. And in DxeIplX64P...
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Database.java
CommitLineData
b0282412 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
0dc8c589 13package org.tianocore.migration;\r
14\r
15import java.io.*;\r
16import java.util.*;\r
17\r
7bcb8d17 18public final class Database {\r
19 Database(String path) throws Exception {\r
20 DatabasePath = path;\r
0dc8c589 21 \r
22 importDBLib("Library.csv");\r
23 importDBGuid("Guid.csv", "Guid");\r
24 importDBGuid("Ppi.csv", "Ppi");\r
25 importDBGuid("Protocol.csv", "Protocol");\r
26 importDBMacro("Macro.csv");\r
27 }\r
28 \r
29 public static String defaultpath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
30 \r
31 public String DatabasePath;\r
32 public Set<String> error = new HashSet<String>();\r
33 \r
34 private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
35 private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
36 private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
37 \r
38 private void importDBLib(String filename) throws Exception {\r
39 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
40 String line;\r
41 String[] linecontext;\r
42 Func lf;\r
43 \r
44 if (rd.ready()) {\r
719cebfe 45 System.out.println("Found " + filename + ", Importing Library Database.");\r
0dc8c589 46 while ((line = rd.readLine()) != null) {\r
47 if (line.length() != 0) {\r
48 linecontext = line.split(",");\r
49 lf = new Func(linecontext);\r
50 hashfunc.put(lf.r8funcname,lf);\r
51 }\r
52 }\r
53 }\r
54 }\r
55 \r
56 private void importDBGuid(String filename, String type) throws Exception {\r
57 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
58 String line;\r
59 String[] linecontext;\r
60 Guid gu;\r
61 \r
62 if (rd.ready()) {\r
719cebfe 63 System.out.println("Found " + filename + ", Importing " + type + " Database.");\r
0dc8c589 64 while ((line = rd.readLine()) != null) {\r
65 if (line.length() != 0) {\r
66 linecontext = line.split(",");\r
67 gu = new Guid(linecontext, type);\r
68 hashguid.put(gu.r8name,gu);\r
69 }\r
70 }\r
71 }\r
72 }\r
73 \r
74 private void importDBMacro(String filename) throws Exception {\r
75 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
76 String line;\r
77 String[] linecontext;\r
78 Macro mc;\r
79 \r
80 if (rd.ready()) {\r
719cebfe 81 System.out.println("Found " + filename + ", Importing Macro Database.");\r
0dc8c589 82 while ((line = rd.readLine()) != null) {\r
83 if (line.length() != 0) {\r
84 linecontext = line.split(",");\r
85 mc = new Macro(linecontext);\r
86 hashmacro.put(mc.r8name,mc);\r
87 }\r
88 }\r
89 }\r
90 }\r
91 \r
92 public String getR9Lib(String r8funcname) {\r
93 String temp = null;\r
94 if (hashfunc.containsKey(r8funcname)) {\r
95 temp = hashfunc.get(r8funcname).r9libname;\r
96 }\r
97 return temp;\r
98 }\r
99 \r
100 public String getR9Func(String r8funcname) {\r
101 String temp = null;\r
102 if (hashfunc.containsKey(r8funcname)) {\r
103 temp = hashfunc.get(r8funcname).r9funcname;\r
104 }\r
105 return temp;\r
106 }\r
107 \r
108 public boolean hasFunc(String r8lib) {\r
109 return hashfunc.containsKey(r8lib);\r
110 }\r
111\r
112 public boolean hasGuid(String r8guid) {\r
113 return hashguid.containsKey(r8guid);\r
114 }\r
115\r
116 public boolean hasMacro(String r8macro) {\r
117 return hashmacro.containsKey(r8macro);\r
118 }\r
119 \r
120 public String getR9Macro(String r8macro) {\r
121 return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it\r
122 }\r
7bcb8d17 123\r
0dc8c589 124 public String getR9Guidname(String r8Guid) {\r
125 String temp = null;\r
126 try {\r
127 temp = hashguid.get(r8Guid).r9name;\r
128 } catch (NullPointerException e) {\r
129 error.add("getR9Guidname :" + r8Guid);\r
130 }\r
131 return temp;\r
132 }\r
7bcb8d17 133\r
0dc8c589 134 public String getGuidType(String r8Guid) {\r
135 String temp = null;\r
136 try {\r
137 temp = hashguid.get(r8Guid).type;\r
138 } catch (NullPointerException e) {\r
139 error.add("getR9Guidname :" + r8Guid);\r
140 }\r
141 return temp;\r
142 }\r
7bcb8d17 143\r
144 public static Database init() throws Exception {\r
145 if (System.getenv("WORKSPACE") == null) {\r
146 return new Database("C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
147 } else {\r
148 return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");\r
149 }\r
150 }\r
0dc8c589 151}\r