source: trunk/src/win32k/dev16/extract.c@ 5087

Last change on this file since 5087 was 4972, checked in by bird, 25 years ago

Added support for kernel revisions. (like 14062a)

File size: 9.8 KB
Line 
1/* $Id: extract.c,v 1.4 2001-01-19 02:27:32 bird Exp $
2 *
3 * Description: SymDB entry generator.
4 * Builds SymDB entry from one or more symbol files.
5 *
6 * Copyright (c) 2000-2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12/*******************************************************************************
13* Defined Constants And Macros *
14*******************************************************************************/
15/* Disable logging */
16#define NOLOGGING 1
17
18#define fclose(a) DosClose(a)
19#define SEEK_SET FILE_BEGIN
20#define SEEK_END FILE_END
21
22#define WORD unsigned short int
23#define DWORD unsigned long int
24
25#define INCL_BASE
26#define INCL_DOS
27#define INCL_NOPMAPI
28
29/*******************************************************************************
30* Header Files *
31*******************************************************************************/
32#include <os2.h>
33
34#include <strat2.h>
35#include <reqpkt.h>
36
37#include "devSegDf.h"
38#undef DATA16_INIT
39#define DATA16_INIT
40#undef CODE16_INIT
41#define CODE16_INIT
42#include "os2krnl.h" /* must be included before dev1632.h! */
43#include "probkrnl.h"
44#include "dev1632.h"
45#include "vprntf16.h"
46
47
48/*******************************************************************************
49* Global Variables *
50*******************************************************************************/
51/* Result from GetKernelInfo/ReadOS2Krnl. */
52extern unsigned char cObjects;
53extern POTE paKrnlOTEs;
54
55/* dummy replacement for SymDB.c */
56KRNLDBENTRY DATA16_INIT aKrnlSymDB[] = {{0}};
57
58/*******************************************************************************
59* Internal Functions *
60*******************************************************************************/
61int processFile(const char *pszFilename);
62
63/*******************************************************************************
64* External Functions *
65*******************************************************************************/
66/* Workers */
67extern int ProbeSymFile(const char *pszFilename);
68
69/* C-library replacements and additions. */
70extern void kmemcpy(char *psz1, const char *psz2, int cch);
71extern char * kstrstr(const char *psz1, const char *psz2);
72extern int kstrcmp(const char *psz1, const char *psz2);
73extern int kstrncmp(const char *psz1, const char *psz2, int cch);
74extern int kstrnicmp(const char *psz1, const char *psz2, int cch);
75extern int kstrlen(const char *psz);
76extern char * kstrcpy(char * pszTarget, const char * pszSource);
77extern int kargncpy(char *pszTarget, const char *pszArg, unsigned cchMaxlen);
78
79
80
81/**
82 * Dumps writes a KRNLDBENTRY struct to stderr for the given .sym-file.
83 * The filesnames are on this format:
84 * nnnn[n]tm[r].SYM
85 * Where: n - are the build number 4 or 5 digits.
86 * t - kernel type. R = retail, H = half strict, A = all strict.
87 * m - UNI or SMP. U = UNI processor kernel. S = SMP processor kernel. 4 = Warp 4 FP13+
88 * r - revision letter. Currently only 'A' is supported.
89 * @returns NO_ERROR on success. Untracable error code on error.
90 * @param pszFilename Pointer to read only filename of the .sym-file.
91 * @status completely implemented.
92 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
93 * @remark Currently only retail kernels are processed. See note below.
94 */
95static int processFile(const char *pszFilename)
96{
97 APIRET rc;
98 int cch;
99 int cchNum;
100 const char *psz = pszFilename + kstrlen(pszFilename);
101
102 /* find filename */
103 cch = 0;
104 while (psz >= pszFilename && *psz != '\\' && *psz != '/' && *psz != ':')
105 psz--, cch++;
106 psz++;
107 cch--;
108
109 /* Progress information */
110 DosWrite(2, (char*)pszFilename, cch, &rc);
111 DosWrite(2, "\r\n", 2, &rc);
112
113 /* Filename check */
114 cchNum = psz[0] > '2' ? 4 : 5; /* build number length. */
115 if (cch < 10 || cch > 12
116 || !(psz[0] >= '0' && psz[0] <= '9')
117 || !(psz[1] >= '0' && psz[1] <= '9')
118 || !(psz[2] >= '0' && psz[2] <= '9')
119 || !(psz[3] >= '0' && psz[3] <= '9')
120 || !(cchNum == 4 || (psz[4] >= '0' && psz[4] <= '9'))
121 || !(psz[cchNum] == 'A' || psz[cchNum] == 'H' || psz[cchNum] == 'R')
122 || !(psz[cchNum+1] == 'S' || psz[cchNum+1] == 'U' || psz[cchNum+1] == '4')
123/* || !(cch != 12 || psz[cchNum+2] == 'A') */
124 )
125 {
126 printf16("invalid filename: %s\n", pszFilename);
127 return 2;
128 }
129
130 /*
131 * Probe kernelfile
132 */
133 rc = ProbeSymFile(pszFilename);
134
135
136 /*
137 * on success dump a struct for this kernel
138 */
139 if (rc == 0)
140 {
141 int i;
142
143 /** @remark
144 * Currently information for retail kernels are usable, but we'll
145 * generate it for the debug kernels too, but this information
146 * is enclaved within an "#ifdef ALLKERNELS ... #endif".
147 */
148 if (psz[cchNum] != 'R')
149 printf16("#ifdef ALLKERNELS\n");
150
151 printf16(" { /* %s */\n"
152 " %.*s, ",
153 psz,
154 cchNum, &psz[0] /* build number */
155 );
156
157 switch (psz[cchNum + 1])
158 {
159 case 'S': printf16("KF_SMP"); break;
160 case '4': printf16("KF_UNI | KF_W4"); break;
161 case 'U': printf16("KF_UNI"); break;
162 }
163 switch (psz[cchNum])
164 {
165 case 'A': printf16(" | KF_ALLSTRICT"); break;
166 case 'H': printf16(" | KF_HALFSTRICT"); break;
167 }
168 if (psz[cchNum + 2] == 'A')
169 printf16(" | KF_REV_A");
170
171 printf16(", %d,\n"
172 " {\n",
173 aImportTab[0].iObject + 1); /* ASSUMES that DOSCODE32 is the last object. */
174
175 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
176 {
177 char *psz = aImportTab[i].achName;
178 printf16(" {%-2d, 0x%08lx}, /* %s */\n",
179 aImportTab[i].iObject,
180 aImportTab[i].fFound ? aImportTab[i].offObject : 0xFFFFFFFFUL,
181 (char *)&aImportTab[i].achName[0]
182 );
183 }
184 printf16(" }\n"
185 " },\n");
186
187 /** @remark
188 * Currently information for retail kernels are usable, but we'll
189 * generate it for the debug kernels too, but this information
190 * is enclaved within an "#ifdef ALLKERNELS ... #endif".
191 */
192 if (psz[cchNum] != 'R')
193 printf16("#endif\n");
194 }
195 else
196 printf16("ProbeSymFile failed with rc=%d\n", rc);
197
198 return rc;
199}
200
201
202/**
203 * Extract program.
204 *
205 * This is some initial trial-and-error for creating an "database" of
206 * kernel entrypoints.
207 *
208 * Output to stderr the structs generated for the passed in *.sym file.
209 *
210 */
211int main(int argc, char **argv)
212{
213 APIRET rc;
214 const char * psz;
215
216 /*
217 * Set paKrnlOTEs to point to an zeroed array of OTEs.
218 */
219 static KRNLINFO DATA16_INIT KrnlInfo = {0};
220 paKrnlOTEs = &KrnlInfo.aObjects[0];
221
222 if (argc > 1)
223 {
224 /*
225 * Arguments: extract.exe <symfiles...>
226 */
227 int i;
228 for (i = 1; i < argc; i++)
229 {
230 rc = processFile(argv[i]);
231 if (rc != NO_ERROR)
232 {
233 printf16("processFile failed with rc=%d for file %s\n",
234 rc, argv[i]);
235 if (psz = GetErrorMsg(rc))
236 printf16("%s\n", psz);
237 return rc;
238 }
239 }
240 }
241 else
242 {
243 /*
244 * Arguments: extract.exe
245 *
246 * Action: Scan current directory for *.sym files.
247 *
248 */
249 USHORT usSearch = 1;
250 HDIR hDir = HDIR_CREATE;
251 FILEFINDBUF ffb;
252 int i;
253
254 printf16("/* $Id: extract.c,v 1.4 2001-01-19 02:27:32 bird Exp $\n"
255 "*\n"
256 "* Autogenerated kernel symbol database.\n"
257 "*\n"
258 "* Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)\n"
259 "*\n"
260 "* Project Odin Software License can be found in LICENSE.TXT\n"
261 "*\n"
262 "*/\n");
263
264 printf16("\n"
265 "#define INCL_NOPMAPI\n"
266 "#define INCL_NOBASEAPI\n"
267 "#include <os2.h>\n"
268 "#include \"DevSegDf.h\"\n"
269 "#include \"probkrnl.h\"\n"
270 "#include \"options.h\"\n"
271 "\n");
272
273 printf16("KRNLDBENTRY DATA16_INIT aKrnlSymDB[] = \n"
274 "{\n");
275
276 rc = DosFindFirst("*.sym", &hDir, FILE_NORMAL,
277 &ffb, sizeof(ffb),
278 &usSearch, 0UL);
279 while (rc == NO_ERROR & usSearch > 0)
280 {
281 rc = processFile(&ffb.achName[0]);
282 if (rc != NO_ERROR)
283 {
284 printf16("processFile failed with rc=%d for file %s\n",
285 rc, &ffb.achName[0]);
286 if (psz = GetErrorMsg(rc))
287 printf16("%s\n", psz);
288 return rc;
289 }
290
291 /* next file */
292 rc = DosFindNext(hDir, &ffb, sizeof(ffb), &usSearch);
293 }
294 DosFindClose(hDir);
295
296 printf16(" { /* Terminating entry */\n"
297 " 0,0,0,\n"
298 " {\n");
299 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
300 printf16(" {0,0},\n");
301 printf16(" }\n"
302 " }\n"
303 "}; /* end of aKrnlSymDB[] */\n"
304 );
305 }
306
307
308 return rc;
309}
310
Note: See TracBrowser for help on using the repository browser.