source: trunk/src/win32k/dev16/mkcalltab.c@ 4347

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

Implemented tool for generating calltab for kernel imports. (mkcalltab)
Implemented API for accessing memory in another process. (*ProcessReadWrite)
Added kernel imports needed to implemented ProcessReadWrite.
Removed unused kernel imports.

File size: 13.4 KB
Line 
1/* $Id: mkcalltab.c,v 1.1 2000-10-01 02:58:15 bird Exp $
2 *
3 * Description: Generates the calltab.asm from aImportTab.
4 *
5 * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
6 *
7 * Project Odin Software License can be found in LICENSE.TXT
8 *
9 */
10
11/*******************************************************************************
12* Defined Constants And Macros *
13*******************************************************************************/
14/* Disable logging */
15#define NOLOGGING 1
16
17#define fclose(a) DosClose(a)
18#define SEEK_SET FILE_BEGIN
19#define SEEK_END FILE_END
20
21#define WORD unsigned short int
22#define DWORD unsigned long int
23
24#define INCL_BASE
25#define INCL_DOS
26#define INCL_NOPMAPI
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <os2.h>
32
33#include <strat2.h>
34#include <reqpkt.h>
35
36#include "devSegDf.h"
37#undef DATA16_INIT
38#define DATA16_INIT
39#undef CODE16_INIT
40#define CODE16_INIT
41#include "os2krnl.h" /* must be included before dev1632.h! */
42#include "probkrnl.h"
43#include "dev1632.h"
44#include "vprntf16.h"
45
46/*******************************************************************************
47* Global Variables *
48*******************************************************************************/
49/* dummy replacement for SymDB.c */
50KRNLDBENTRY DATA16_INIT aKrnlSymDB[] = {{0}};
51
52/*******************************************************************************
53* External Functions *
54*******************************************************************************/
55extern int kstrlen(const char *psz);
56
57/*******************************************************************************
58* Internal Functions *
59*******************************************************************************/
60void syntax(void);
61int GenerateCalltab(void);
62int GenerateTstFakers(void);
63
64/**
65 * MkCalltab program.
66 *
67 * Output to stdout the calltab assembly code.
68 *
69 */
70int main(int argc, char **argv)
71{
72 if (argc != 2)
73 {
74 syntax();
75 return -1;
76 }
77 if (argv[1][0] == 'c')
78 return GenerateCalltab();
79 else if (argv[1][0] == 't')
80 return GenerateTstFakers();
81 else
82 {
83 syntax();
84 return -2;
85 }
86
87 return 0;
88}
89
90
91/**
92 * Display syntax.
93 */
94void syntax(void)
95{
96 printf16("Incorrect parameter!\n"
97 "Syntax: mkcalltab.exe <tab>\n"
98 " Where <tab> is either calltab or tstfakers.\n"
99 );
100}
101
102
103/**
104 * Generate calltab.asm.
105 * It's contents is written to stdout.
106 */
107int GenerateCalltab(void)
108{
109 int i;
110
111 /*
112 * Write Start of file.
113 */
114 printf16("; $Id: mkcalltab.c,v 1.1 2000-10-01 02:58:15 bird Exp $\n"
115 ";\n"
116 "; Autogenerated calltab file.\n"
117 ";\n"
118 "; Generate: mkcalltab.exe > ldr\calltab.asm\n"
119 ";\n"
120 "; Copyright (c) 1998-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)\n"
121 ";\n"
122 "; Project Odin Software License can be found in LICENSE.TXT\n"
123 ";\n"
124 " .386p\n"
125 "\n"
126 "\n"
127 ";\n"
128 "; Include files\n"
129 ";\n"
130 " include devsegdf.inc\n"
131 "\n"
132 "\n"
133 ";\n"
134 "; Exported symbols\n"
135 ";\n"
136 " public callTab\n"
137 " public auFuncs\n"
138 "\n"
139 "\n"
140 ";\n"
141 "; Constants\n"
142 ";\n"
143 "OVERLOAD32_PROLOG EQU 14h\n"
144 "OVERLOAD16_PROLOG EQU 18h\n"
145 "IMPORT32_PROLOG EQU 08h\n"
146 "NRIMPORT32_PROLOG EQU 06h\n"
147 "IMPORT16_PROLOG EQU 08h\n"
148 "NRIMPORT16_PROLOG EQU 07h\n"
149 "\n"
150 "\n"
151 ";\n"
152 "; Macros\n"
153 ";\n"
154 "\n"
155 "; Macro which makes a function overload calltable entry\n"
156 "FnOverload32Entry macro fnname\n"
157 " public fnname\n"
158 " fnname proc near\n"
159 " db OVERLOAD32_PROLOG dup(0cch)\n"
160 " fnname endp\n"
161 "endm\n"
162 "\n"
163 "; Macro which makes a function overload calltable entry\n"
164 "FnOverload16Entry macro fnname\n"
165 " public fnname\n"
166 " fnname proc near\n"
167 " db OVERLOAD16_PROLOG dup(0cch)\n"
168 " fnname endp\n"
169 "endm\n"
170 "\n"
171 "; Macro which makes a function calltable entry\n"
172 "FnImport32Entry macro fnname\n"
173 " public fnname\n"
174 " fnname proc near\n"
175 " db IMPORT32_PROLOG dup(0cch)\n"
176 " fnname endp\n"
177 "endm\n"
178 "\n"
179 "; Macro which makes a function calltable entry\n"
180 "FnNRImport32Entry macro fnname\n"
181 " public fnname\n"
182 " fnname proc near\n"
183 " db NRIMPORT32_PROLOG dup(0cch)\n"
184 " fnname endp\n"
185 " f&fnname& dw 0\n"
186 "endm\n"
187 "\n"
188 "; Macro which makes a function calltable entry\n"
189 "FnImport16Entry macro fnname\n"
190 " public fnname\n"
191 " fnname proc near\n"
192 " db IMPORT16_PROLOG dup(0cch)\n"
193 " fnname endp\n"
194 "endm\n"
195 "\n"
196 "; Macro which makes a function calltable entry\n"
197 "FnNRImport16Entry macro fnname\n"
198 " public fnname\n"
199 " fnname proc near\n"
200 " db NRIMPORT16_PROLOG dup(0cch)\n"
201 " fnname endp\n"
202 " f&fnname& db 0\n"
203 "endm\n"
204 "\n");
205 printf16("; Macro which makes a variable calltable entry.\n"
206 "VariableEntry macro varname\n"
207 " public p&varname&\n"
208 " p&varname& dd 0\n"
209 " public &varname&_offObject\n"
210 " &varname&_offObject dd 0\n"
211 " public _fp&varname&\n"
212 " _fp&varname& dd 0\n"
213 " public &varname&_sel\n"
214 " &varname&_sel dw 0\n"
215 " dw 0cch ;alignment\n"
216 "endm\n"
217 "\n"
218 "\n"
219 "CALLTAB segment\n"
220 " ;assume cs:CALLTAB, ds:flat, ss:nothing\n"
221 " assume ds:flat, ss:nothing\n"
222 ";\n"
223 "; callTab is an array of function prologs with a jump to the real function\n"
224 "; and pointers to real variables.\n"
225 ";\n"
226 "; Imported and Overrided OS/2 kernel functions are called thru this table.\n"
227 "; Imported OS/2 kernel variables are accessed thru this table.\n"
228 ";\n"
229 "callTab:\n");
230
231 /*
232 * Process aImportTab.
233 */
234 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
235 {
236 char *pszMacro = (aImportTab[i].fType & EPT_VARIMPORT) ?
237 "VariableEntry"
238 : ( (aImportTab[i].fType & EPT_PROCIMPORT) ?
239 ( (aImportTab[i].fType & EPT_NOT_REQ) ?
240 (EPT16BitEntry(aImportTab[i]) ? "FnNRImport16Entry" : "FnNRImport32Entry")
241 : (EPT16BitEntry(aImportTab[i]) ? "FnImport16Entry" : "FnImport32Entry"))
242 : (EPT16BitEntry(aImportTab[i]) ? "FnOverload16Entry" : "FnOverload32Entry"));
243 char *pszName = &aImportTab[i].achName[(aImportTab[i].fType & EPT_VARIMPORT) && aImportTab[i].achName[0] == '_'];
244 char *pszExtra = (aImportTab[i].fType & EPT_WRAPPED) ? "_wrapped" : aImportTab[i].achExtra;
245
246 /*
247 * Variable or Function?
248 */
249 printf16("%s<%s%s>%*.s;%d\n",
250 pszMacro,
251 pszName,
252 pszExtra,
253 45 - 2 - kstrlen(pszMacro) - aImportTab[i].cchName - kstrlen(pszExtra),
254 "",
255 i);
256 }
257
258 /*
259 * Write End of Calltab and start of auFuncs.
260 */
261 printf16("\n"
262 "CALLTAB ENDS\n"
263 "\n"
264 "\n"
265 "DATA32 SEGMENT\n"
266 " assume ds:nothing, es:nothing\n"
267 "\n"
268 ";\n"
269 "; Function table for overloader and nop functions.\n"
270 "; Used by importTabInit() in d32init.c.\n"
271 ";\n"
272 "auFuncs:\n"
273 );
274
275 /*
276 * Process aImportTab to generate auFuncs.
277 */
278 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
279 {
280 char * pszSeg = (EPT32BitEntry(aImportTab[i]) ? "32" : "16");
281 char * pszPrefix = (aImportTab[i].achName[0] == '_' ? "_" : "");
282 char * pszName = (*pszPrefix != '\0' ? &aImportTab[i].achName[1] : &aImportTab[i].achName[0]);
283
284 if (!(aImportTab[i].fType & (EPT_PROCIMPORT | EPT_VARIMPORT | EPT_NOT_REQ)))
285 { /* Overload procedure (Overloader function) */
286 printf16(" extrn %smy%s%s : NEAR\n"
287 " dd offset FLAT:CODE%s:%smy%s%s\n",
288 pszPrefix,
289 pszName,
290 aImportTab[i].achExtra,
291 pszSeg,
292 pszPrefix,
293 pszName,
294 aImportTab[i].achExtra);
295 }
296 else if ((aImportTab[i].fType & (EPT_NOT_REQ | EPT_VARIMPORT | EPT_PROCIMPORT)) == (EPT_NOT_REQ | EPT_PROCIMPORT))
297 { /* Not required imported function (NOP function) */
298 printf16(" extrn %snop%s%s : NEAR\n"
299 " dd offset FLAT:CODE%s:%snop%s%s\n",
300 pszPrefix,
301 pszName,
302 aImportTab[i].achExtra,
303 pszSeg,
304 pszPrefix,
305 pszName,
306 aImportTab[i].achExtra);
307 }
308 else
309 printf16(" dd 0h\n");
310 }
311
312 /*
313 * Write End of file.
314 */
315 printf16("\n"
316 "DATA32 ENDS\n"
317 "\n"
318 "END\n");
319
320
321 return 0;
322}
323
324
325/**
326 * Generate the (test\)TstFakers.c file.
327 * It's contents is written to stdout.
328 */
329int GenerateTstFakers(void)
330{
331 int i;
332
333 /*
334 * Write Start of file.
335 */
336 printf16("/* $Id: mkcalltab.c,v 1.1 2000-10-01 02:58:15 bird Exp $\n"
337 " *\n"
338 " * Autogenerated TstFakers.c file.\n"
339 " *\n"
340 " * Generate: mkcalltab.exe fake > test\TstFakers.c\n"
341 " *\n"
342 " * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)\n"
343 " *\n"
344 " * Project Odin Software License can be found in LICENSE.TXT\n"
345 " *\n"
346 " */\n"
347 "\n"
348 "\n"
349 "/*******************************************************************************\n"
350 "* Defined Constants And Macros *\n"
351 "*******************************************************************************/\n"
352 "#define INCL_NOPMAPI\n"
353 "#define LDR_INCL_INITONLY\n"
354 "#define INCL_OS2KRNL_ALL\n"
355 "\n"
356 "/*******************************************************************************\n"
357 "* Header Files *\n"
358 "*******************************************************************************/\n"
359 "#include <os2.h>\n"
360 "\n"
361 "#include \"devSegDf.h\"\n"
362 "#include \"OS2Krnl.h\"\n"
363 "#include \"dev1632.h\"\n"
364 "#include \"dev32.h\"\n"
365 "#include \"dev32hlp.h\"\n"
366 "#include \"probkrnl.h\"\n"
367 "#include \"ldr.h\"\n"
368 "#include \"ldrCalls.h\"\n"
369 "#include \"test.h\"\n"
370 "\n"
371 "\n"
372 "TSTFAKER aTstFakers[NBR_OF_KRNLIMPORTS] =\n"
373 "{\n");
374
375 /*
376 * Process aImportTab.
377 */
378 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
379 {
380 int iSeg = EPT16BitEntry(aImportTab[i]) ?
381 ((aImportTab[i].fType & EPT_VARIMPORT) ? 4 : 2)
382 : ((aImportTab[i].fType & EPT_VARIMPORT) ? 3 : 1);
383 const char *psz = aImportTab[i].achName[0] == '_' ?
384 &aImportTab[i].achName[1]
385 : &aImportTab[i].achName[0];
386
387 /*
388 * Variable or Function?
389 */
390 printf16(" {(unsigned)%sfake%s,%*.s%d}%s\n",
391 (aImportTab[i].fType & EPT_VARIMPORT) ? "&" : "",
392 psz,
393 45 - 21 - kstrlen(psz) - ((aImportTab[i].fType & EPT_VARIMPORT) == EPT_VARIMPORT),
394 "",
395 iSeg,
396 i + 1 == NBR_OF_KRNLIMPORTS ? "" : ",");
397 }
398
399 /*
400 * Write End of file.
401 */
402 printf16("};\n"
403 "\n");
404
405 return 0;
406}
407
Note: See TracBrowser for help on using the repository browser.