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

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

Removed ldrCalls.h from generated source.

File size: 13.4 KB
Line 
1/* $Id: mkcalltab.c,v 1.3 2001-02-11 15:15:12 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.3 2001-02-11 15:15:12 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 auFuncs\n"
139 "\n"
140 "\n"
141 ";\n"
142 "; Constants\n"
143 ";\n"
144 "OVERLOAD32_PROLOG EQU 14h\n"
145 "OVERLOAD16_PROLOG EQU 18h\n"
146 "IMPORT32_PROLOG EQU 08h\n"
147 "NRIMPORT32_PROLOG EQU 06h\n"
148 "IMPORT16_PROLOG EQU 08h\n"
149 "NRIMPORT16_PROLOG EQU 07h\n"
150 "\n"
151 "\n"
152 ";\n"
153 "; Macros\n"
154 ";\n"
155 "\n"
156 "; Macro which makes a function overload calltable entry\n"
157 "FnOverload32Entry macro fnname\n"
158 " public fnname\n"
159 " fnname proc near\n"
160 " db OVERLOAD32_PROLOG dup(0cch)\n"
161 " fnname endp\n"
162 "endm\n"
163 "\n"
164 "; Macro which makes a function overload calltable entry\n"
165 "FnOverload16Entry macro fnname\n"
166 " public fnname\n"
167 " fnname proc near\n"
168 " db OVERLOAD16_PROLOG dup(0cch)\n"
169 " fnname endp\n"
170 "endm\n"
171 "\n"
172 "; Macro which makes a function calltable entry\n"
173 "FnImport32Entry macro fnname\n"
174 " public fnname\n"
175 " fnname proc near\n"
176 " db IMPORT32_PROLOG dup(0cch)\n"
177 " fnname endp\n"
178 "endm\n"
179 "\n"
180 "; Macro which makes a function calltable entry\n"
181 "FnNRImport32Entry macro fnname\n"
182 " public fnname\n"
183 " fnname proc near\n"
184 " db NRIMPORT32_PROLOG dup(0cch)\n"
185 " fnname endp\n"
186 " f&fnname& dw 0\n"
187 "endm\n"
188 "\n"
189 "; Macro which makes a function calltable entry\n"
190 "FnImport16Entry macro fnname\n"
191 " public fnname\n"
192 " fnname proc near\n"
193 " db IMPORT16_PROLOG dup(0cch)\n"
194 " fnname endp\n"
195 "endm\n"
196 "\n"
197 "; Macro which makes a function calltable entry\n"
198 "FnNRImport16Entry macro fnname\n"
199 " public fnname\n"
200 " fnname proc near\n"
201 " db NRIMPORT16_PROLOG dup(0cch)\n"
202 " fnname endp\n"
203 " f&fnname& db 0\n"
204 "endm\n"
205 "\n");
206 printf16("; Macro which makes a variable calltable entry.\n"
207 "VariableEntry macro varname\n"
208 " public p&varname&\n"
209 " p&varname& dd 0\n"
210 " public &varname&_offObject\n"
211 " &varname&_offObject dd 0\n"
212 " public _fp&varname&\n"
213 " _fp&varname& dd 0\n"
214 " public &varname&_sel\n"
215 " &varname&_sel dw 0\n"
216 " dw 0cch ;alignment\n"
217 "endm\n"
218 "\n"
219 "\n"
220 "CALLTAB segment\n"
221 " ;assume cs:CALLTAB, ds:flat, ss:nothing\n"
222 " assume ds:flat, ss:nothing\n"
223 ";\n"
224 "; callTab is an array of function prologs with a jump to the real function\n"
225 "; and pointers to real variables.\n"
226 ";\n"
227 "; Imported and Overrided OS/2 kernel functions are called thru this table.\n"
228 "; Imported OS/2 kernel variables are accessed thru this table.\n"
229 ";\n"
230 "callTab:\n");
231
232 /*
233 * Process aImportTab.
234 */
235 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
236 {
237 char *pszMacro = (aImportTab[i].fType & EPT_VARIMPORT) ?
238 "VariableEntry"
239 : ( (aImportTab[i].fType & EPT_PROCIMPORT) ?
240 ( (aImportTab[i].fType & EPT_NOT_REQ) ?
241 (EPT16BitEntry(aImportTab[i]) ? "FnNRImport16Entry" : "FnNRImport32Entry")
242 : (EPT16BitEntry(aImportTab[i]) ? "FnImport16Entry" : "FnImport32Entry"))
243 : (EPT16BitEntry(aImportTab[i]) ? "FnOverload16Entry" : "FnOverload32Entry"));
244 char *pszName = &aImportTab[i].achName[(aImportTab[i].fType & EPT_VARIMPORT) && aImportTab[i].achName[0] == '_'];
245 char *pszExtra = (aImportTab[i].fType & EPT_WRAPPED) ? "_wrapped" : aImportTab[i].achExtra;
246
247 /*
248 * Variable or Function?
249 */
250 printf16("%s<%s%s>%*.s;%d\n",
251 pszMacro,
252 pszName,
253 pszExtra,
254 45 - 2 - kstrlen(pszMacro) - aImportTab[i].cchName - kstrlen(pszExtra),
255 "",
256 i);
257 }
258
259 /*
260 * Write End of Calltab and start of auFuncs.
261 */
262 printf16("\n"
263 "CALLTAB ENDS\n"
264 "\n"
265 "\n"
266 "DATA32 SEGMENT\n"
267 " assume ds:nothing, es:nothing\n"
268 "\n"
269 ";\n"
270 "; Function table for overloader and nop functions.\n"
271 "; Used by importTabInit() in d32init.c.\n"
272 ";\n"
273 "auFuncs:\n"
274 );
275
276 /*
277 * Process aImportTab to generate auFuncs.
278 */
279 for (i = 0; i < NBR_OF_KRNLIMPORTS; i++)
280 {
281 char * pszSeg = (EPT32BitEntry(aImportTab[i]) ? "32" : "16");
282 char * pszPrefix = (aImportTab[i].achName[0] == '_' ? "_" : "");
283 char * pszName = (*pszPrefix != '\0' ? &aImportTab[i].achName[1] : &aImportTab[i].achName[0]);
284
285 if (!(aImportTab[i].fType & (EPT_PROCIMPORT | EPT_VARIMPORT | EPT_NOT_REQ)))
286 { /* Overload procedure (Overloader function) */
287 printf16(" extrn %smy%s%s : NEAR\n"
288 " dd offset FLAT:CODE%s:%smy%s%s\n",
289 pszPrefix,
290 pszName,
291 aImportTab[i].achExtra,
292 pszSeg,
293 pszPrefix,
294 pszName,
295 aImportTab[i].achExtra);
296 }
297 else if ((aImportTab[i].fType & (EPT_NOT_REQ | EPT_VARIMPORT | EPT_PROCIMPORT)) == (EPT_NOT_REQ | EPT_PROCIMPORT))
298 { /* Not required imported function (NOP function) */
299 printf16(" extrn %snop%s%s : NEAR\n"
300 " dd offset FLAT:CODE%s:%snop%s%s\n",
301 pszPrefix,
302 pszName,
303 aImportTab[i].achExtra,
304 pszSeg,
305 pszPrefix,
306 pszName,
307 aImportTab[i].achExtra);
308 }
309 else
310 printf16(" dd 0h\n");
311 }
312
313 /*
314 * Write End of file.
315 */
316 printf16("\n"
317 "DATA32 ENDS\n"
318 "\n"
319 "END\n");
320
321
322 return 0;
323}
324
325
326/**
327 * Generate the (test\)TstFakers.c file.
328 * It's contents is written to stdout.
329 */
330int GenerateTstFakers(void)
331{
332 int i;
333
334 /*
335 * Write Start of file.
336 */
337 printf16("/* $Id: mkcalltab.c,v 1.3 2001-02-11 15:15:12 bird Exp $\n"
338 " *\n"
339 " * Autogenerated TstFakers.c file.\n"
340 " *\n"
341 " * Generate: mkcalltab.exe fake > test\TstFakers.c\n"
342 " *\n"
343 " * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)\n"
344 " *\n"
345 " * Project Odin Software License can be found in LICENSE.TXT\n"
346 " *\n"
347 " */\n"
348 "\n"
349 "\n"
350 "/*******************************************************************************\n"
351 "* Defined Constants And Macros *\n"
352 "*******************************************************************************/\n"
353 "#define INCL_NOPMAPI\n"
354 "#define LDR_INCL_INITONLY\n"
355 "#define INCL_OS2KRNL_ALL\n"
356 "\n"
357 "/*******************************************************************************\n"
358 "* Header Files *\n"
359 "*******************************************************************************/\n"
360 "#include <os2.h>\n"
361 "\n"
362 "#include \"devSegDf.h\"\n"
363 "#include \"OS2Krnl.h\"\n"
364 "#include \"dev1632.h\"\n"
365 "#include \"dev32.h\"\n"
366 "#include \"dev32hlp.h\"\n"
367 "#include \"probkrnl.h\"\n"
368 "#include \"ldr.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.