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

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

Calltable fixes. Handle event. New 14062e kernels.

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