VirtualBox

source: vbox/trunk/src/VBox/Devices/BiosCommonCode/MakeAlternativeSource.cpp@ 62450

最後變更 在這個檔案從62450是 62450,由 vboxsync 提交於 9 年 前

bldprogs: MSC level 4 warning fixes.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 61.6 KB
 
1/* $Id: MakeAlternativeSource.cpp 62450 2016-07-22 15:04:27Z vboxsync $ */
2/** @file
3 * MakeAlternative - Generate an Alternative BIOS Source that requires less tools.
4 */
5
6/*
7 * Copyright (C) 2012-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#include <iprt/asm.h>
23#include <iprt/buildconfig.h>
24#include <iprt/ctype.h>
25#include <iprt/dbg.h>
26#include <iprt/file.h>
27#include <iprt/getopt.h>
28#include <iprt/initterm.h>
29#include <iprt/list.h>
30#include <iprt/mem.h>
31#include <iprt/message.h>
32#include <iprt/string.h>
33#include <iprt/stream.h>
34#include <iprt/x86.h>
35
36#include <VBox/dis.h>
37
38
39/*********************************************************************************************************************************
40* Structures and Typedefs *
41*********************************************************************************************************************************/
42/**
43 * A BIOS segment.
44 */
45typedef struct BIOSSEG
46{
47 char szName[32];
48 char szClass[32];
49 char szGroup[32];
50 RTFAR16 Address;
51 uint32_t uFlatAddr;
52 uint32_t cb;
53} BIOSSEG;
54/** Pointer to a BIOS segment. */
55typedef BIOSSEG *PBIOSSEG;
56
57
58/**
59 * A BIOS object file.
60 */
61typedef struct BIOSOBJFILE
62{
63 RTLISTNODE Node;
64 char *pszSource;
65 char *pszObject;
66} BIOSOBJFILE;
67/** A BIOS object file. */
68typedef BIOSOBJFILE *PBIOSOBJFILE;
69
70
71/**
72 * Pointer to a BIOS map parser handle.
73 */
74typedef struct BIOSMAP
75{
76 /** The stream pointer. */
77 PRTSTREAM hStrm;
78 /** The file name. */
79 const char *pszMapFile;
80 /** Set when EOF has been reached. */
81 bool fEof;
82 /** The current line number (0 based).*/
83 uint32_t iLine;
84 /** The length of the current line. */
85 uint32_t cch;
86 /** The offset of the first non-white character on the line. */
87 uint32_t offNW;
88 /** The line buffer. */
89 char szLine[16384];
90} BIOSMAP;
91/** Pointer to a BIOS map parser handle. */
92typedef BIOSMAP *PBIOSMAP;
93
94
95/*********************************************************************************************************************************
96* Global Variables *
97*********************************************************************************************************************************/
98/** The verbosity level.*/
99static unsigned g_cVerbose = 1 /*0*/;
100/** Pointer to the BIOS image. */
101static uint8_t const *g_pbImg;
102/** The size of the BIOS image. */
103static size_t g_cbImg;
104
105/** Debug module for the map file. */
106static RTDBGMOD g_hMapMod = NIL_RTDBGMOD;
107/** The number of BIOS segments found in the map file. */
108static uint32_t g_cSegs = 0;
109/** Array of BIOS segments from the map file. */
110static BIOSSEG g_aSegs[32];
111/** List of BIOSOBJFILE. */
112static RTLISTANCHOR g_ObjList;
113
114/** The output stream. */
115static PRTSTREAM g_hStrmOutput = NULL;
116
117/** The type of BIOS we're working on. */
118static enum BIOSTYPE
119{
120 kBiosType_System = 0,
121 kBiosType_Vga
122} g_enmBiosType = kBiosType_System;
123/** The flat ROM base address. */
124static uint32_t g_uBiosFlatBase = 0xf0000;
125
126
127static bool outputPrintfV(const char *pszFormat, va_list va)
128{
129 int rc = RTStrmPrintfV(g_hStrmOutput, pszFormat, va);
130 if (RT_FAILURE(rc))
131 {
132 RTMsgError("Output error: %Rrc\n", rc);
133 return false;
134 }
135 return true;
136}
137
138
139static bool outputPrintf(const char *pszFormat, ...)
140{
141 va_list va;
142 va_start(va, pszFormat);
143 bool fRc = outputPrintfV(pszFormat, va);
144 va_end(va);
145 return fRc;
146}
147
148
149/**
150 * Opens the output file for writing.
151 *
152 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg.
153 * @param pszOutput Path to the output file.
154 */
155static RTEXITCODE OpenOutputFile(const char *pszOutput)
156{
157 if (!pszOutput)
158 g_hStrmOutput = g_pStdOut;
159 else
160 {
161 int rc = RTStrmOpen(pszOutput, "w", &g_hStrmOutput);
162 if (RT_FAILURE(rc))
163 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to open output file '%s': %Rrc", pszOutput, rc);
164 }
165 return RTEXITCODE_SUCCESS;
166}
167
168
169/**
170 * Displays a disassembly error and returns @c false.
171 *
172 * @returns @c false.
173 * @param pszFormat The error format string.
174 * @param ... Format argument.
175 */
176static bool disError(const char *pszFormat, ...)
177{
178 va_list va;
179 va_start(va, pszFormat);
180 RTMsgErrorV(pszFormat, va);
181 va_end(va);
182 return false;
183}
184
185
186/**
187 * Output the disassembly file header.
188 *
189 * @returns @c true on success,
190 */
191static bool disFileHeader(void)
192{
193 bool fRc;
194 fRc = outputPrintf("; $Id: MakeAlternativeSource.cpp 62450 2016-07-22 15:04:27Z vboxsync $ \n"
195 ";; @file\n"
196 "; Auto Generated source file. Do not edit.\n"
197 ";\n"
198 );
199 if (!fRc)
200 return fRc;
201
202 /*
203 * List the header of each source file, up to and including the
204 * copyright notice.
205 */
206 bool fNeedLgplDisclaimer = false;
207 PBIOSOBJFILE pObjFile;
208 RTListForEach(&g_ObjList, pObjFile, BIOSOBJFILE, Node)
209 {
210 PRTSTREAM hStrm;
211 int rc = RTStrmOpen(pObjFile->pszSource, "r", &hStrm);
212 if (RT_SUCCESS(rc))
213 {
214 fRc = outputPrintf("\n"
215 ";\n"
216 "; Source file: %Rbn\n"
217 ";\n"
218 , pObjFile->pszSource);
219 uint32_t iLine = 0;
220 bool fSeenCopyright = false;
221 char szLine[4096];
222 while ((rc = RTStrmGetLine(hStrm, szLine, sizeof(szLine))) == VINF_SUCCESS)
223 {
224 iLine++;
225
226 /* Check if we're done. */
227 char *psz = RTStrStrip(szLine);
228 if ( fSeenCopyright
229 && ( (psz[0] == '*' && psz[1] == '/')
230 || psz[0] == '\0') )
231 break;
232
233 /* Strip comment suffix. */
234 size_t cch = strlen(psz);
235 if (cch >= 2 && psz[cch - 1] == '/' && psz[cch - 2] == '*')
236 {
237 psz[cch - 2] = '\0';
238 RTStrStripR(psz);
239 }
240
241 /* Skip line prefix. */
242 if (psz[0] == '/' && psz[1] == '*')
243 psz += 2;
244 else if (psz[0] == '*')
245 psz += 1;
246 else
247 while (*psz == ';')
248 psz++;
249 if (RT_C_IS_SPACE(*psz))
250 psz++;
251
252 /* Skip the doxygen file tag line. */
253 if (!strcmp(psz, "* @file") || !strcmp(psz, "@file"))
254 continue;
255
256 /* Detect copyright section. */
257 if ( !fSeenCopyright
258 && ( strstr(psz, "Copyright")
259 || strstr(psz, "copyright")) )
260 fSeenCopyright = true;
261
262 /* Detect LGPL. */
263 if (strstr(psz, "LGPL"))
264 fNeedLgplDisclaimer = true;
265
266 fRc = outputPrintf("; %s\n", psz) && fRc;
267 }
268
269 RTStrmClose(hStrm);
270 if (rc != VINF_SUCCESS)
271 return disError("Error reading '%s': rc=%Rrc iLine=%u", pObjFile->pszSource, rc, iLine);
272 }
273 }
274
275 /*
276 * Add Oracle LGPL disclaimer.
277 */
278 if (fNeedLgplDisclaimer)
279 outputPrintf("\n"
280 ";\n"
281 "; Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice\n"
282 "; other than GPL or LGPL is available it will apply instead, Oracle elects to use only\n"
283 "; the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where\n"
284 "; a choice of LGPL license versions is made available with the language indicating\n"
285 "; that LGPLv2 or any later version may be used, or where a choice of which version\n"
286 "; of the LGPL is applied is otherwise unspecified.\n"
287 ";\n"
288 "\n");
289
290 /*
291 * Set the org.
292 */
293 fRc = outputPrintf("\n"
294 "\n"
295 "\n"
296 ) && fRc;
297 return fRc;
298}
299
300
301/**
302 * Checks if a byte sequence could be a string litteral.
303 *
304 * @returns @c true if it is, @c false if it isn't.
305 * @param uFlatAddr The address of the byte sequence.
306 * @param cb The length of the sequence.
307 */
308static bool disIsString(uint32_t uFlatAddr, uint32_t cb)
309{
310 if (cb < 6)
311 return false;
312
313 uint8_t const *pb = &g_pbImg[uFlatAddr - g_uBiosFlatBase];
314 while (cb > 0)
315 {
316 if ( !RT_C_IS_PRINT(*pb)
317 && *pb != '\r'
318 && *pb != '\n'
319 && *pb != '\t')
320 {
321 if (*pb == '\0')
322 {
323 do
324 {
325 pb++;
326 cb--;
327 } while (cb > 0 && *pb == '\0');
328 return cb == 0;
329 }
330 return false;
331 }
332 pb++;
333 cb--;
334 }
335
336 return true;
337}
338
339
340#if 0 /* unused */
341/**
342 * Checks if a dword could be a far 16:16 BIOS address.
343 *
344 * @returns @c true if it is, @c false if it isn't.
345 * @param uFlatAddr The address of the dword.
346 */
347static bool disIsFarBiosAddr(uint32_t uFlatAddr)
348{
349 uint16_t const *pu16 = (uint16_t const *)&g_pbImg[uFlatAddr - g_uBiosFlatBase];
350 if (pu16[1] < 0xf000)
351 return false;
352 if (pu16[1] > 0xfff0)
353 return false;
354 uint32_t uFlatAddr2 = (uint32_t)(pu16[1] << 4) | pu16[0];
355 if (uFlatAddr2 >= g_uBiosFlatBase + g_cbImg)
356 return false;
357 return true;
358}
359#endif
360
361
362static bool disByteData(uint32_t uFlatAddr, uint32_t cb)
363{
364 uint8_t const *pb = &g_pbImg[uFlatAddr - g_uBiosFlatBase];
365 size_t cbOnLine = 0;
366 while (cb-- > 0)
367 {
368 bool fRc;
369 if (cbOnLine >= 16)
370 {
371 fRc = outputPrintf("\n"
372 " db 0%02xh", *pb);
373 cbOnLine = 1;
374 }
375 else if (!cbOnLine)
376 {
377 fRc = outputPrintf(" db 0%02xh", *pb);
378 cbOnLine = 1;
379 }
380 else
381 {
382 fRc = outputPrintf(", 0%02xh", *pb);
383 cbOnLine++;
384 }
385 if (!fRc)
386 return false;
387 pb++;
388 }
389 return outputPrintf("\n");
390}
391
392
393static bool disWordData(uint32_t uFlatAddr, uint32_t cb)
394{
395 if (cb & 1)
396 return disError("disWordData expects word aligned size: cb=%#x uFlatAddr=%#x", uFlatAddr, cb);
397
398 uint16_t const *pu16 = (uint16_t const *)&g_pbImg[uFlatAddr - g_uBiosFlatBase];
399 size_t cbOnLine = 0;
400 while (cb > 0)
401 {
402 bool fRc;
403 if (cbOnLine >= 16)
404 {
405 fRc = outputPrintf("\n"
406 " dw 0%04xh", *pu16);
407 cbOnLine = 2;
408 }
409 else if (!cbOnLine)
410 {
411 fRc = outputPrintf(" dw 0%04xh", *pu16);
412 cbOnLine = 2;
413 }
414 else
415 {
416 fRc = outputPrintf(", 0%04xh", *pu16);
417 cbOnLine += 2;
418 }
419 if (!fRc)
420 return false;
421 pu16++;
422 cb -= 2;
423 }
424 return outputPrintf("\n");
425}
426
427
428static bool disDWordData(uint32_t uFlatAddr, uint32_t cb)
429{
430 if (cb & 3)
431 return disError("disWordData expects dword aligned size: cb=%#x uFlatAddr=%#x", uFlatAddr, cb);
432
433 uint32_t const *pu32 = (uint32_t const *)&g_pbImg[uFlatAddr - g_uBiosFlatBase];
434 size_t cbOnLine = 0;
435 while (cb > 0)
436 {
437 bool fRc;
438 if (cbOnLine >= 16)
439 {
440 fRc = outputPrintf("\n"
441 " dd 0%08xh", *pu32);
442 cbOnLine = 4;
443 }
444 else if (!cbOnLine)
445 {
446 fRc = outputPrintf(" dd 0%08xh", *pu32);
447 cbOnLine = 4;
448 }
449 else
450 {
451 fRc = outputPrintf(", 0%08xh", *pu32);
452 cbOnLine += 4;
453 }
454 if (!fRc)
455 return false;
456 pu32++;
457 cb -= 4;
458 }
459 return outputPrintf("\n");
460}
461
462
463static bool disStringData(uint32_t uFlatAddr, uint32_t cb)
464{
465 uint8_t const *pb = &g_pbImg[uFlatAddr - g_uBiosFlatBase];
466 uint32_t cchOnLine = 0;
467 while (cb > 0)
468 {
469 /* Line endings and beginnings. */
470 if (cchOnLine >= 72)
471 {
472 if (!outputPrintf("\n"))
473 return false;
474 cchOnLine = 0;
475 }
476 if ( !cchOnLine
477 && !outputPrintf(" db "))
478 return false;
479
480 /* See how many printable character we've got. */
481 uint32_t cchPrintable = 0;
482 while ( cchPrintable < cb
483 && RT_C_IS_PRINT(pb[cchPrintable])
484 && pb[cchPrintable] != '\'')
485 cchPrintable++;
486
487 bool fRc = true;
488 if (cchPrintable)
489 {
490 if (cchPrintable + cchOnLine > 72)
491 cchPrintable = 72 - cchOnLine;
492 if (cchOnLine)
493 {
494 fRc = outputPrintf(", '%.*s'", cchPrintable, pb);
495 cchOnLine += 4 + cchPrintable;
496 }
497 else
498 {
499 fRc = outputPrintf("'%.*s'", cchPrintable, pb);
500 cchOnLine += 2 + cchPrintable;
501 }
502 pb += cchPrintable;
503 cb -= cchPrintable;
504 }
505 else
506 {
507 if (cchOnLine)
508 {
509 fRc = outputPrintf(", 0%02xh", *pb);
510 cchOnLine += 6;
511 }
512 else
513 {
514 fRc = outputPrintf("0%02xh", *pb);
515 cchOnLine += 4;
516 }
517 pb++;
518 cb--;
519 }
520 if (!fRc)
521 return false;
522 }
523 return outputPrintf("\n");
524}
525
526
527/**
528 * For dumping a portion of a string table.
529 *
530 * @returns @c true on success, @c false on failure.
531 * @param uFlatAddr The start address.
532 * @param cb The size of the string table.
533 */
534static bool disStringsData(uint32_t uFlatAddr, uint32_t cb)
535{
536 uint8_t const *pb = &g_pbImg[uFlatAddr - g_uBiosFlatBase];
537 uint32_t cchOnLine = 0;
538 uint8_t bPrev = 255;
539 while (cb > 0)
540 {
541 /* Line endings and beginnings. */
542 if ( cchOnLine >= 72
543 || (bPrev == '\0' && *pb != '\0'))
544 {
545 if (!outputPrintf("\n"))
546 return false;
547 cchOnLine = 0;
548 }
549 if ( !cchOnLine
550 && !outputPrintf(" db "))
551 return false;
552
553 /* See how many printable character we've got. */
554 uint32_t cchPrintable = 0;
555 while ( cchPrintable < cb
556 && RT_C_IS_PRINT(pb[cchPrintable])
557 && pb[cchPrintable] != '\'')
558 cchPrintable++;
559
560 bool fRc = true;
561 if (cchPrintable)
562 {
563 if (cchPrintable + cchOnLine > 72)
564 cchPrintable = 72 - cchOnLine;
565 if (cchOnLine)
566 {
567 fRc = outputPrintf(", '%.*s'", cchPrintable, pb);
568 cchOnLine += 4 + cchPrintable;
569 }
570 else
571 {
572 fRc = outputPrintf("'%.*s'", cchPrintable, pb);
573 cchOnLine += 2 + cchPrintable;
574 }
575 pb += cchPrintable;
576 cb -= cchPrintable;
577 }
578 else
579 {
580 if (cchOnLine)
581 {
582 fRc = outputPrintf(", 0%02xh", *pb);
583 cchOnLine += 6;
584 }
585 else
586 {
587 fRc = outputPrintf("0%02xh", *pb);
588 cchOnLine += 4;
589 }
590 pb++;
591 cb--;
592 }
593 if (!fRc)
594 return false;
595 bPrev = pb[-1];
596 }
597 return outputPrintf("\n");
598}
599
600
601/**
602 * Minds the gap between two segments.
603 *
604 * Gaps should generally be zero filled.
605 *
606 * @returns @c true on success, @c false on failure.
607 * @param uFlatAddr The address of the gap.
608 * @param cbPadding The size of the gap.
609 */
610static bool disCopySegmentGap(uint32_t uFlatAddr, uint32_t cbPadding)
611{
612 if (g_cVerbose > 0)
613 outputPrintf("\n"
614 " ; Padding %#x bytes at %#x\n", cbPadding, uFlatAddr);
615 uint8_t const *pb = &g_pbImg[uFlatAddr - g_uBiosFlatBase];
616 if (ASMMemIsZero(pb, cbPadding))
617 return outputPrintf(" times %u db 0\n", cbPadding);
618
619 return disByteData(uFlatAddr, cbPadding);
620}
621
622
623/**
624 * Worker for disGetNextSymbol that only does the looking up, no RTDBSYMBOL::cb
625 * calc.
626 *
627 * @param uFlatAddr The address to start searching at.
628 * @param cbMax The size of the search range.
629 * @param poff Where to return the offset between the symbol
630 * and @a uFlatAddr.
631 * @param pSym Where to return the symbol data.
632 */
633static void disGetNextSymbolWorker(uint32_t uFlatAddr, uint32_t cbMax, uint32_t *poff, PRTDBGSYMBOL pSym)
634{
635 RTINTPTR off = 0;
636 int rc = RTDbgModSymbolByAddr(g_hMapMod, RTDBGSEGIDX_RVA, uFlatAddr, RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL, &off, pSym);
637 if (RT_SUCCESS(rc))
638 {
639 /* negative offset, indicates beyond. */
640 if (off <= 0)
641 {
642 *poff = (uint32_t)-off;
643 return;
644 }
645
646 outputPrintf(" ; !! RTDbgModSymbolByAddr(,,%#x,,) -> off=%RTptr cb=%RTptr uValue=%RTptr '%s'\n",
647 uFlatAddr, off, pSym->cb, pSym->Value, pSym->szName);
648 }
649 else if (rc != VERR_SYMBOL_NOT_FOUND)
650 outputPrintf(" ; !! RTDbgModSymbolByAddr(,,%#x,,) -> %Rrc\n", uFlatAddr, rc);
651
652 RTStrPrintf(pSym->szName, sizeof(pSym->szName), "_dummy_addr_%#x", uFlatAddr + cbMax);
653 pSym->Value = uFlatAddr + cbMax;
654 pSym->cb = 0;
655 pSym->offSeg = uFlatAddr + cbMax;
656 pSym->iSeg = RTDBGSEGIDX_RVA;
657 pSym->iOrdinal = 0;
658 pSym->fFlags = 0;
659 *poff = cbMax;
660}
661
662
663/**
664 * Gets the symbol at or after the given address.
665 *
666 * If there are no symbols in the specified range, @a pSym and @a poff will be
667 * set up to indicate a symbol at the first byte after the range.
668 *
669 * @param uFlatAddr The address to start searching at.
670 * @param cbMax The size of the search range.
671 * @param poff Where to return the offset between the symbol
672 * and @a uFlatAddr.
673 * @param pSym Where to return the symbol data.
674 */
675static void disGetNextSymbol(uint32_t uFlatAddr, uint32_t cbMax, uint32_t *poff, PRTDBGSYMBOL pSym)
676{
677 disGetNextSymbolWorker(uFlatAddr, cbMax, poff, pSym);
678 if ( *poff < cbMax
679 && pSym->cb == 0)
680 {
681 if (*poff + 1 < cbMax)
682 {
683 uint32_t off2;
684 RTDBGSYMBOL Sym2;
685 disGetNextSymbolWorker(uFlatAddr + *poff + 1, cbMax - *poff - 1, &off2, &Sym2);
686 pSym->cb = off2 + 1;
687 }
688 else
689 pSym->cb = 1;
690 }
691 if (pSym->cb > cbMax - *poff)
692 pSym->cb = cbMax - *poff;
693
694 if (g_cVerbose > 1)
695 outputPrintf(" ; disGetNextSymbol %#x LB %#x -> off=%#x cb=%RTptr uValue=%RTptr '%s'\n",
696 uFlatAddr, cbMax, *poff, pSym->cb, pSym->Value, pSym->szName);
697
698}
699
700
701/**
702 * For dealing with the const segment (string constants).
703 *
704 * @returns @c true on success, @c false on failure.
705 * @param iSeg The segment.
706 */
707static bool disConstSegment(uint32_t iSeg)
708{
709 uint32_t uFlatAddr = g_aSegs[iSeg].uFlatAddr;
710 uint32_t cb = g_aSegs[iSeg].cb;
711
712 while (cb > 0)
713 {
714 uint32_t off;
715 RTDBGSYMBOL Sym;
716 disGetNextSymbol(uFlatAddr, cb, &off, &Sym);
717
718 if (off > 0)
719 {
720 if (!disStringsData(uFlatAddr, off))
721 return false;
722 cb -= off;
723 uFlatAddr += off;
724 off = 0;
725 if (!cb)
726 break;
727 }
728
729 bool fRc;
730 if (off == 0)
731 {
732 size_t cchName = strlen(Sym.szName);
733 fRc = outputPrintf("%s: %*s; %#x LB %#x\n", Sym.szName, cchName < 41 - 2 ? cchName - 41 - 2 : 0, "", uFlatAddr, Sym.cb);
734 if (!fRc)
735 return false;
736 fRc = disStringsData(uFlatAddr, Sym.cb);
737 uFlatAddr += Sym.cb;
738 cb -= Sym.cb;
739 }
740 else
741 {
742 fRc = disStringsData(uFlatAddr, Sym.cb);
743 uFlatAddr += cb;
744 cb = 0;
745 }
746 if (!fRc)
747 return false;
748 }
749
750 return true;
751}
752
753
754
755static bool disDataSegment(uint32_t iSeg)
756{
757 uint32_t uFlatAddr = g_aSegs[iSeg].uFlatAddr;
758 uint32_t cb = g_aSegs[iSeg].cb;
759
760 while (cb > 0)
761 {
762 uint32_t off;
763 RTDBGSYMBOL Sym;
764 disGetNextSymbol(uFlatAddr, cb, &off, &Sym);
765
766 if (off > 0)
767 {
768 if (!disByteData(uFlatAddr, off))
769 return false;
770 cb -= off;
771 uFlatAddr += off;
772 off = 0;
773 if (!cb)
774 break;
775 }
776
777 bool fRc;
778 if (off == 0)
779 {
780 size_t cchName = strlen(Sym.szName);
781 fRc = outputPrintf("%s: %*s; %#x LB %#x\n", Sym.szName, cchName < 41 - 2 ? cchName - 41 - 2 : 0, "", uFlatAddr, Sym.cb);
782 if (!fRc)
783 return false;
784
785 if (Sym.cb == 2)
786 fRc = disWordData(uFlatAddr, 2);
787 //else if (Sym.cb == 4 && disIsFarBiosAddr(uFlatAddr))
788 // fRc = disDWordData(uFlatAddr, 4);
789 else if (Sym.cb == 4)
790 fRc = disDWordData(uFlatAddr, 4);
791 else if (disIsString(uFlatAddr, Sym.cb))
792 fRc = disStringData(uFlatAddr, Sym.cb);
793 else
794 fRc = disByteData(uFlatAddr, Sym.cb);
795
796 uFlatAddr += Sym.cb;
797 cb -= Sym.cb;
798 }
799 else
800 {
801 fRc = disByteData(uFlatAddr, cb);
802 uFlatAddr += cb;
803 cb = 0;
804 }
805 if (!fRc)
806 return false;
807 }
808
809 return true;
810}
811
812
813static bool disIsCodeAndAdjustSize(uint32_t uFlatAddr, PRTDBGSYMBOL pSym, PBIOSSEG pSeg)
814{
815 switch (g_enmBiosType)
816 {
817 /*
818 * This is for the PC BIOS.
819 */
820 case kBiosType_System:
821 if (!strcmp(pSeg->szName, "BIOSSEG"))
822 {
823 if ( !strcmp(pSym->szName, "rom_fdpt")
824 || !strcmp(pSym->szName, "pmbios_gdt")
825 || !strcmp(pSym->szName, "pmbios_gdt_desc")
826 || !strcmp(pSym->szName, "_pmode_IDT")
827 || !strcmp(pSym->szName, "_rmode_IDT")
828 || !strncmp(pSym->szName, RT_STR_TUPLE("font"))
829 || !strcmp(pSym->szName, "bios_string")
830 || !strcmp(pSym->szName, "vector_table")
831 || !strcmp(pSym->szName, "pci_routing_table_structure")
832 || !strcmp(pSym->szName, "_pci_routing_table")
833 )
834 return false;
835 }
836
837 if (!strcmp(pSym->szName, "cpu_reset"))
838 pSym->cb = RT_MIN(pSym->cb, 5);
839 else if (!strcmp(pSym->szName, "pci_init_end"))
840 pSym->cb = RT_MIN(pSym->cb, 3);
841 break;
842
843 /*
844 * This is for the VGA BIOS.
845 */
846 case kBiosType_Vga:
847 break;
848 }
849
850 return true;
851}
852
853
854static bool disIs16BitCode(const char *pszSymbol)
855{
856 return true;
857}
858
859
860/**
861 * Deals with instructions that YASM will assemble differently than WASM/WCC.
862 */
863static size_t disHandleYasmDifferences(PDISCPUSTATE pCpuState, uint32_t uFlatAddr, uint32_t cbInstr,
864 char *pszBuf, size_t cbBuf, size_t cchUsed)
865{
866 bool fDifferent = DISFormatYasmIsOddEncoding(pCpuState);
867 uint8_t const *pb = &g_pbImg[uFlatAddr - g_uBiosFlatBase];
868
869 /*
870 * Disassembler bugs.
871 */
872 /** @todo Group 1a and 11 seems to be disassembled incorrectly when
873 * modrm.reg != 0. Those encodings should be invalid AFAICT. */
874
875 if ( ( pCpuState->bOpCode == 0x8f /* group 1a */
876 || pCpuState->bOpCode == 0xc7 /* group 11 */
877 || pCpuState->bOpCode == 0xc6 /* group 11 - not verified */
878 )
879 && pCpuState->ModRM.Bits.Reg != 0)
880 fDifferent = true;
881 /*
882 * Check these out and consider adding them to DISFormatYasmIsOddEncoding.
883 */
884 else if ( pb[0] == 0xf3
885 && pb[1] == 0x66
886 && pb[2] == 0x6d)
887 fDifferent = true; /* rep insd - prefix switched. */
888 else if ( pb[0] == 0xc6
889 && pb[1] == 0xc5
890 && pb[2] == 0xba)
891 fDifferent = true; /* mov ch, 0bah - yasm uses a short sequence: 0xb5 0xba. */
892
893 /*
894 * 32-bit retf.
895 */
896 else if ( pb[0] == 0x66
897 && pb[1] == 0xcb)
898 fDifferent = true;
899
900 /*
901 * Handle different stuff.
902 */
903 if (fDifferent)
904 {
905 disByteData(uFlatAddr, cbInstr); /* lazy bird. */
906
907 if (cchUsed + 2 < cbBuf)
908 {
909 memmove(pszBuf + 2, pszBuf, cchUsed + 1); /* include terminating \0 */
910 cchUsed += 2;
911 }
912
913 pszBuf[0] = ';';
914 pszBuf[1] = ' ';
915 }
916
917 return cchUsed;
918}
919
920
921/**
922 * @callback_method_impl{FNDISREADBYTES}
923 *
924 * @remarks @a uSrcAddr is the flat address.
925 */
926static DECLCALLBACK(int) disReadOpcodeBytes(PDISCPUSTATE pDis, uint8_t offInstr, uint8_t cbMinRead, uint8_t cbMaxRead)
927{
928 RTUINTPTR offBios = pDis->uInstrAddr + offInstr - g_uBiosFlatBase;
929 size_t cbToRead = cbMaxRead;
930 if (offBios + cbToRead > g_cbImg)
931 {
932 if (offBios >= g_cbImg)
933 cbToRead = 0;
934 else
935 cbToRead = g_cbImg - offBios;
936 }
937 memcpy(&pDis->abInstr[offInstr], &g_pbImg[offBios], cbToRead);
938 pDis->cbCachedInstr = (uint8_t)(offInstr + cbToRead);
939 return VINF_SUCCESS;
940}
941
942
943/**
944 * Disassembles code.
945 *
946 * @returns @c true on success, @c false on failure.
947 * @param uFlatAddr The address where the code starts.
948 * @param cb The amount of code to disassemble.
949 * @param fIs16Bit Is is 16-bit (@c true) or 32-bit (@c false).
950 */
951static bool disCode(uint32_t uFlatAddr, uint32_t cb, bool fIs16Bit)
952{
953 uint8_t const *pb = &g_pbImg[uFlatAddr - g_uBiosFlatBase];
954
955 while (cb > 0)
956 {
957 /* Trailing zero padding detection. */
958 if ( *pb == '\0'
959 && ASMMemIsZero(pb, RT_MIN(cb, 8)))
960 {
961 void *pv = ASMMemFirstNonZero(pb, cb);
962 uint32_t cbZeros = pv ? (uint32_t)((uint8_t const *)pv - pb) : cb;
963 if (!outputPrintf(" times %#x db 0\n", cbZeros))
964 return false;
965 cb -= cbZeros;
966 pb += cbZeros;
967 uFlatAddr += cbZeros;
968 if ( cb == 2
969 && pb[0] == 'X'
970 && pb[1] == 'M')
971 return disStringData(uFlatAddr, cb);
972 }
973 /* Work arounds for switch tables and such (disas assertions). */
974 else if ( 0
975 || ( pb[0] == 0x50 /* int13_cdemu switch */
976 && pb[1] == 0x4e
977 && pb[2] == 0x49
978 && pb[3] == 0x48
979 && pb[4] == 0x47
980 )
981 || ( pb[0] == 0x67 /* _pci16_function switch */
982 && pb[1] == 0x92
983 && pb[2] == 0x81
984 && pb[3] == 0x92
985 && pb[4] == 0x94
986 && pb[5] == 0x92
987 )
988 || ( pb[0] == 0xa3 /* _int1a_function switch */
989 && pb[1] == 0x67
990 && pb[2] == 0xca
991 && pb[3] == 0x67
992 && pb[4] == 0xef
993 && pb[5] == 0x67
994 )
995 || ( pb[0] == 0x0b /* _ahci_init byte table */
996 && pb[1] == 0x05
997 && pb[2] == 0x04
998 && pb[3] == 0x03
999 && pb[4] == 0x02
1000 && pb[5] == 0x01
1001 )
1002 || ( pb[0] == 0x00 /* bytes after apm_out_str_ */
1003 && pb[1] == 0x00
1004 && pb[2] == 0x00
1005 && pb[3] == 0x00
1006 && pb[4] == 0x00
1007 && pb[5] == 0x00
1008 && pb[6] == 0xe0
1009 && pb[7] == 0xa0
1010 && pb[8] == 0xe2
1011 && pb[9] == 0xa0)
1012 || ( pb[0] == 0xd4
1013 && pb[1] == 0xc6
1014 && pb[2] == 0xc5
1015 && pb[3] == 0xba
1016 && pb[4] == 0xb8
1017 && pb[5] == 0xb6)
1018 || ( pb[0] == 0xec /* _int15_function switch */
1019 && pb[1] == 0xe9
1020 && pb[2] == 0xd8
1021 && pb[3] == 0xc1
1022 && pb[4] == 0xc0
1023 && pb[5] == 0xbf)
1024 || ( pb[0] == 0x21 /* _int15_function32 switch */
1025 && pb[1] == 0x66
1026 && pb[2] == 0x43
1027 && pb[3] == 0x66
1028 && pb[4] == 0x66
1029 && pb[5] == 0x66)
1030 || 0
1031 )
1032 return disByteData(uFlatAddr, cb);
1033 else
1034 {
1035 unsigned cbInstr;
1036 DISCPUSTATE CpuState;
1037 int rc = DISInstrWithReader(uFlatAddr, fIs16Bit ? DISCPUMODE_16BIT : DISCPUMODE_32BIT,
1038 disReadOpcodeBytes, NULL, &CpuState, &cbInstr);
1039 if ( RT_SUCCESS(rc)
1040 && cbInstr <= cb
1041 && CpuState.pCurInstr
1042 && CpuState.pCurInstr->uOpcode != OP_INVALID)
1043 {
1044 char szTmp[4096];
1045 size_t cch = DISFormatYasmEx(&CpuState, szTmp, sizeof(szTmp),
1046 DIS_FMT_FLAGS_STRICT
1047 | DIS_FMT_FLAGS_BYTES_RIGHT | DIS_FMT_FLAGS_BYTES_COMMENT | DIS_FMT_FLAGS_BYTES_SPACED,
1048 NULL, NULL);
1049 cch = disHandleYasmDifferences(&CpuState, uFlatAddr, cbInstr, szTmp, sizeof(szTmp), cch);
1050 Assert(cch < sizeof(szTmp));
1051
1052 if (g_cVerbose > 1)
1053 {
1054 while (cch < 72)
1055 szTmp[cch++] = ' ';
1056 RTStrPrintf(&szTmp[cch], sizeof(szTmp) - cch, "; %#x", uFlatAddr);
1057 }
1058
1059 if (!outputPrintf(" %s\n", szTmp))
1060 return false;
1061 cb -= cbInstr;
1062 pb += cbInstr;
1063 uFlatAddr += cbInstr;
1064 }
1065 else
1066 {
1067 if (!disByteData(uFlatAddr, 1))
1068 return false;
1069 cb--;
1070 pb++;
1071 uFlatAddr++;
1072 }
1073 }
1074 }
1075 return true;
1076}
1077
1078
1079static bool disCodeSegment(uint32_t iSeg)
1080{
1081 uint32_t uFlatAddr = g_aSegs[iSeg].uFlatAddr;
1082 uint32_t cb = g_aSegs[iSeg].cb;
1083
1084 while (cb > 0)
1085 {
1086 uint32_t off;
1087 RTDBGSYMBOL Sym;
1088 disGetNextSymbol(uFlatAddr, cb, &off, &Sym);
1089
1090 if (off > 0)
1091 {
1092 if (!disByteData(uFlatAddr, off))
1093 return false;
1094 cb -= off;
1095 uFlatAddr += off;
1096 off = 0;
1097 if (!cb)
1098 break;
1099 }
1100
1101 bool fRc;
1102 if (off == 0)
1103 {
1104 size_t cchName = strlen(Sym.szName);
1105 fRc = outputPrintf("%s: %*s; %#x LB %#x\n", Sym.szName, cchName < 41 - 2 ? cchName - 41 - 2 : 0, "", uFlatAddr, Sym.cb);
1106 if (!fRc)
1107 return false;
1108
1109 if (disIsCodeAndAdjustSize(uFlatAddr, &Sym, &g_aSegs[iSeg]))
1110 fRc = disCode(uFlatAddr, Sym.cb, disIs16BitCode(Sym.szName));
1111 else
1112 fRc = disByteData(uFlatAddr, Sym.cb);
1113
1114 uFlatAddr += Sym.cb;
1115 cb -= Sym.cb;
1116 }
1117 else
1118 {
1119 fRc = disByteData(uFlatAddr, cb);
1120 uFlatAddr += cb;
1121 cb = 0;
1122 }
1123 if (!fRc)
1124 return false;
1125 }
1126
1127 return true;
1128}
1129
1130
1131static RTEXITCODE DisassembleBiosImage(void)
1132{
1133 if (!disFileHeader())
1134 return RTEXITCODE_FAILURE;
1135
1136 /*
1137 * Work the image segment by segment.
1138 */
1139 bool fRc = true;
1140 uint32_t uFlatAddr = g_uBiosFlatBase;
1141 for (uint32_t iSeg = 0; iSeg < g_cSegs && fRc; iSeg++)
1142 {
1143 /* Is there a gap between the segments? */
1144 if (uFlatAddr < g_aSegs[iSeg].uFlatAddr)
1145 {
1146 fRc = disCopySegmentGap(uFlatAddr, g_aSegs[iSeg].uFlatAddr - uFlatAddr);
1147 if (!fRc)
1148 break;
1149 uFlatAddr = g_aSegs[iSeg].uFlatAddr;
1150 }
1151 else if (uFlatAddr > g_aSegs[iSeg].uFlatAddr)
1152 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Overlapping segments: %u and %u; uFlatAddr=%#x\n", iSeg - 1, iSeg, uFlatAddr);
1153
1154 /* Disassemble the segment. */
1155 fRc = outputPrintf("\n"
1156 "section %s progbits vstart=%#x align=1 ; size=%#x class=%s group=%s\n",
1157 g_aSegs[iSeg].szName, g_aSegs[iSeg].uFlatAddr - g_uBiosFlatBase,
1158 g_aSegs[iSeg].cb, g_aSegs[iSeg].szClass, g_aSegs[iSeg].szGroup);
1159 if (!fRc)
1160 return RTEXITCODE_FAILURE;
1161 if (!strcmp(g_aSegs[iSeg].szName, "CONST"))
1162 fRc = disConstSegment(iSeg);
1163 else if (!strcmp(g_aSegs[iSeg].szClass, "DATA"))
1164 fRc = disDataSegment(iSeg);
1165 else
1166 fRc = disCodeSegment(iSeg);
1167
1168 /* Advance. */
1169 uFlatAddr += g_aSegs[iSeg].cb;
1170 }
1171
1172 /* Final gap. */
1173 if (uFlatAddr < g_uBiosFlatBase + g_cbImg)
1174 fRc = disCopySegmentGap(uFlatAddr, (uint32_t)(g_uBiosFlatBase + g_cbImg - uFlatAddr));
1175 else if (uFlatAddr > g_uBiosFlatBase + g_cbImg)
1176 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Last segment spills beyond 1MB; uFlatAddr=%#x\n", uFlatAddr);
1177
1178 if (!fRc)
1179 return RTEXITCODE_FAILURE;
1180 return RTEXITCODE_SUCCESS;
1181}
1182
1183
1184
1185/**
1186 * Parses the symbol file for the BIOS.
1187 *
1188 * This is in ELF/DWARF format.
1189 *
1190 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg.
1191 * @param pszBiosSym Path to the sym file.
1192 */
1193static RTEXITCODE ParseSymFile(const char *pszBiosSym)
1194{
1195#if 1
1196 /** @todo use RTDbg* later. (Just checking for existance currently.) */
1197 PRTSTREAM hStrm;
1198 int rc = RTStrmOpen(pszBiosSym, "rb", &hStrm);
1199 if (RT_FAILURE(rc))
1200 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening '%s': %Rrc", pszBiosSym, rc);
1201 RTStrmClose(hStrm);
1202#else
1203 RTDBGMOD hDbgMod;
1204 int rc = RTDbgModCreateFromImage(&hDbgMod, pszBiosSym, "VBoxBios", 0 /*fFlags*/);
1205 RTMsgInfo("RTDbgModCreateFromImage -> %Rrc\n", rc);
1206#endif
1207 return RTEXITCODE_SUCCESS;
1208}
1209
1210
1211/**
1212 * Display an error with the mapfile name and current line, return false.
1213 *
1214 * @returns @c false.
1215 * @param pMap The map file handle.
1216 * @param pszFormat The format string.
1217 * @param ... Format arguments.
1218 */
1219static bool mapError(PBIOSMAP pMap, const char *pszFormat, ...)
1220{
1221 va_list va;
1222 va_start(va, pszFormat);
1223 RTMsgError("%s:%d: %N", pMap->pszMapFile, pMap->iLine, pszFormat, va);
1224 va_end(va);
1225 return false;
1226}
1227
1228
1229/**
1230 * Reads a line from the file.
1231 *
1232 * @returns @c true on success, @c false + msg on failure, @c false on eof.
1233 * @param pMap The map file handle.
1234 */
1235static bool mapReadLine(PBIOSMAP pMap)
1236{
1237 int rc = RTStrmGetLine(pMap->hStrm, pMap->szLine, sizeof(pMap->szLine));
1238 if (RT_FAILURE(rc))
1239 {
1240 if (rc == VERR_EOF)
1241 {
1242 pMap->fEof = true;
1243 pMap->cch = 0;
1244 pMap->offNW = 0;
1245 pMap->szLine[0] = '\0';
1246 }
1247 else
1248 RTMsgError("%s:%d: Read error %Rrc", pMap->pszMapFile, pMap->iLine + 1, rc);
1249 return false;
1250 }
1251 pMap->iLine++;
1252 pMap->cch = (uint32_t)strlen(pMap->szLine);
1253
1254 /* Check out leading white space. */
1255 if (!RT_C_IS_SPACE(pMap->szLine[0]))
1256 pMap->offNW = 0;
1257 else
1258 {
1259 uint32_t off = 1;
1260 while (RT_C_IS_SPACE(pMap->szLine[off]))
1261 off++;
1262 pMap->offNW = off;
1263 }
1264
1265 return true;
1266}
1267
1268
1269/**
1270 * Checks if it is an empty line.
1271 * @returns @c true if empty, @c false if not.
1272 * @param pMap The map file handle.
1273 */
1274static bool mapIsEmptyLine(PBIOSMAP pMap)
1275{
1276 Assert(pMap->offNW <= pMap->cch);
1277 return pMap->offNW == pMap->cch;
1278}
1279
1280
1281/**
1282 * Reads ahead in the map file until a non-empty line or EOF is encountered.
1283 *
1284 * @returns @c true on success, @c false + msg on failure, @c false on eof.
1285 * @param pMap The map file handle.
1286 */
1287static bool mapSkipEmptyLines(PBIOSMAP pMap)
1288{
1289 for (;;)
1290 {
1291 if (!mapReadLine(pMap))
1292 return false;
1293 if (pMap->offNW < pMap->cch)
1294 return true;
1295 }
1296}
1297
1298
1299/**
1300 * Reads ahead in the map file until an empty line or EOF is encountered.
1301 *
1302 * @returns @c true on success, @c false + msg on failure, @c false on eof.
1303 * @param pMap The map file handle.
1304 */
1305static bool mapSkipNonEmptyLines(PBIOSMAP pMap)
1306{
1307 for (;;)
1308 {
1309 if (!mapReadLine(pMap))
1310 return false;
1311 if (pMap->offNW == pMap->cch)
1312 return true;
1313 }
1314}
1315
1316
1317/**
1318 * Strips the current line.
1319 *
1320 * The string length may change.
1321 *
1322 * @returns Pointer to the first non-space character.
1323 * @param pMap The map file handle.
1324 * @param pcch Where to return the length of the unstripped
1325 * part. Optional.
1326 */
1327static char *mapStripCurrentLine(PBIOSMAP pMap, size_t *pcch)
1328{
1329 char *psz = &pMap->szLine[pMap->offNW];
1330 char *pszEnd = &pMap->szLine[pMap->cch];
1331 while ( (uintptr_t)pszEnd > (uintptr_t)psz
1332 && RT_C_IS_SPACE(pszEnd[-1]))
1333 {
1334 *--pszEnd = '\0';
1335 pMap->cch--;
1336 }
1337 if (pcch)
1338 *pcch = pszEnd - psz;
1339 return psz;
1340}
1341
1342
1343/**
1344 * Reads a line from the file and right strips it.
1345 *
1346 * @returns Pointer to szLine on success, @c NULL + msg on failure, @c NULL on
1347 * EOF.
1348 * @param pMap The map file handle.
1349 * @param pcch Where to return the length of the unstripped
1350 * part. Optional.
1351 */
1352static char *mapReadLineStripRight(PBIOSMAP pMap, size_t *pcch)
1353{
1354 if (!mapReadLine(pMap))
1355 return NULL;
1356 mapStripCurrentLine(pMap, NULL);
1357 if (pcch)
1358 *pcch = pMap->cch;
1359 return pMap->szLine;
1360}
1361
1362
1363/**
1364 * mapReadLine() + mapStripCurrentLine().
1365 *
1366 * @returns Pointer to the first non-space character in the new line. NULL on
1367 * read error (bitched already) or end of file.
1368 * @param pMap The map file handle.
1369 * @param pcch Where to return the length of the unstripped
1370 * part. Optional.
1371 */
1372static char *mapReadLineStrip(PBIOSMAP pMap, size_t *pcch)
1373{
1374 if (!mapReadLine(pMap))
1375 return NULL;
1376 return mapStripCurrentLine(pMap, pcch);
1377}
1378
1379
1380/**
1381 * Parses a word, copying it into the supplied buffer, and skipping any spaces
1382 * following it.
1383 *
1384 * @returns @c true on success, @c false on failure.
1385 * @param ppszCursor Pointer to the cursor variable.
1386 * @param pszBuf The output buffer.
1387 * @param cbBuf The size of the output buffer.
1388 */
1389static bool mapParseWord(char **ppszCursor, char *pszBuf, size_t cbBuf)
1390{
1391 /* Check that we start on a non-blank. */
1392 char *pszStart = *ppszCursor;
1393 if (!*pszStart || RT_C_IS_SPACE(*pszStart))
1394 return false;
1395
1396 /* Find the end of the word. */
1397 char *psz = pszStart + 1;
1398 while (*psz && !RT_C_IS_SPACE(*psz))
1399 psz++;
1400
1401 /* Copy it. */
1402 size_t cchWord = (uintptr_t)psz - (uintptr_t)pszStart;
1403 if (cchWord >= cbBuf)
1404 return false;
1405 memcpy(pszBuf, pszStart, cchWord);
1406 pszBuf[cchWord] = '\0';
1407
1408 /* Skip blanks following it. */
1409 while (RT_C_IS_SPACE(*psz))
1410 psz++;
1411 *ppszCursor = psz;
1412 return true;
1413}
1414
1415
1416/**
1417 * Parses an 16:16 address.
1418 *
1419 * @returns @c true on success, @c false on failure.
1420 * @param ppszCursor Pointer to the cursor variable.
1421 * @param pAddr Where to return the address.
1422 */
1423static bool mapParseAddress(char **ppszCursor, PRTFAR16 pAddr)
1424{
1425 char szWord[32];
1426 if (!mapParseWord(ppszCursor, szWord, sizeof(szWord)))
1427 return false;
1428 size_t cchWord = strlen(szWord);
1429
1430 /* An address is at least 16:16 format. It may be 16:32. It may also be flagged. */
1431 size_t cchAddr = 4 + 1 + 4;
1432 if (cchWord < cchAddr)
1433 return false;
1434 if ( !RT_C_IS_XDIGIT(szWord[0])
1435 || !RT_C_IS_XDIGIT(szWord[1])
1436 || !RT_C_IS_XDIGIT(szWord[2])
1437 || !RT_C_IS_XDIGIT(szWord[3])
1438 || szWord[4] != ':'
1439 || !RT_C_IS_XDIGIT(szWord[5])
1440 || !RT_C_IS_XDIGIT(szWord[6])
1441 || !RT_C_IS_XDIGIT(szWord[7])
1442 || !RT_C_IS_XDIGIT(szWord[8])
1443 )
1444 return false;
1445 if ( cchWord > cchAddr
1446 && RT_C_IS_XDIGIT(szWord[9])
1447 && RT_C_IS_XDIGIT(szWord[10])
1448 && RT_C_IS_XDIGIT(szWord[11])
1449 && RT_C_IS_XDIGIT(szWord[12]))
1450 cchAddr += 4;
1451
1452 /* Drop flag if present. */
1453 if (cchWord > cchAddr)
1454 {
1455 if (RT_C_IS_XDIGIT(szWord[cchAddr]))
1456 return false;
1457 szWord[cchAddr] = '\0';
1458 cchWord = cchAddr;
1459 }
1460
1461 /* Convert it. */
1462 szWord[4] = '\0';
1463 int rc1 = RTStrToUInt16Full(szWord, 16, &pAddr->sel);
1464 if (rc1 != VINF_SUCCESS)
1465 return false;
1466
1467 int rc2 = RTStrToUInt16Full(szWord + 5, 16, &pAddr->off);
1468 if (rc2 != VINF_SUCCESS)
1469 return false;
1470 return true;
1471}
1472
1473
1474/**
1475 * Parses a size.
1476 *
1477 * @returns @c true on success, @c false on failure.
1478 * @param ppszCursor Pointer to the cursor variable.
1479 * @param pcb Where to return the size.
1480 */
1481static bool mapParseSize(char **ppszCursor, uint32_t *pcb)
1482{
1483 char szWord[32];
1484 if (!mapParseWord(ppszCursor, szWord, sizeof(szWord)))
1485 return false;
1486 size_t cchWord = strlen(szWord);
1487 if (cchWord != 8)
1488 return false;
1489
1490 int rc = RTStrToUInt32Full(szWord, 16, pcb);
1491 if (rc != VINF_SUCCESS)
1492 return false;
1493 return true;
1494}
1495
1496
1497/**
1498 * Parses a section box and the following column header.
1499 *
1500 * @returns @c true on success, @c false + msg on failure, @c false on eof.
1501 * @param pMap Map file handle.
1502 * @param pszSectionNm The expected section name.
1503 * @param cColumns The number of columns.
1504 * @param ... The column names.
1505 */
1506static bool mapSkipThruColumnHeadings(PBIOSMAP pMap, const char *pszSectionNm, uint32_t cColumns, ...)
1507{
1508 if ( mapIsEmptyLine(pMap)
1509 && !mapSkipEmptyLines(pMap))
1510 return false;
1511
1512 /* +------------+ */
1513 size_t cch;
1514 char *psz = mapStripCurrentLine(pMap, &cch);
1515 if (!psz)
1516 return false;
1517
1518 if ( psz[0] != '+'
1519 || psz[1] != '-'
1520 || psz[2] != '-'
1521 || psz[3] != '-'
1522 || psz[cch - 4] != '-'
1523 || psz[cch - 3] != '-'
1524 || psz[cch - 2] != '-'
1525 || psz[cch - 1] != '+'
1526 )
1527 {
1528 RTMsgError("%s:%d: Expected section box: +-----...", pMap->pszMapFile, pMap->iLine);
1529 return false;
1530 }
1531
1532 /* | pszSectionNm | */
1533 psz = mapReadLineStrip(pMap, &cch);
1534 if (!psz)
1535 return false;
1536
1537 size_t cchSectionNm = strlen(pszSectionNm);
1538 if ( psz[0] != '|'
1539 || psz[1] != ' '
1540 || psz[2] != ' '
1541 || psz[3] != ' '
1542 || psz[cch - 4] != ' '
1543 || psz[cch - 3] != ' '
1544 || psz[cch - 2] != ' '
1545 || psz[cch - 1] != '|'
1546 || cch != 1 + 3 + cchSectionNm + 3 + 1
1547 || strncmp(&psz[4], pszSectionNm, cchSectionNm)
1548 )
1549 {
1550 RTMsgError("%s:%d: Expected section box: | %s |", pMap->pszMapFile, pMap->iLine, pszSectionNm);
1551 return false;
1552 }
1553
1554 /* +------------+ */
1555 psz = mapReadLineStrip(pMap, &cch);
1556 if (!psz)
1557 return false;
1558 if ( psz[0] != '+'
1559 || psz[1] != '-'
1560 || psz[2] != '-'
1561 || psz[3] != '-'
1562 || psz[cch - 4] != '-'
1563 || psz[cch - 3] != '-'
1564 || psz[cch - 2] != '-'
1565 || psz[cch - 1] != '+'
1566 )
1567 {
1568 RTMsgError("%s:%d: Expected section box: +-----...", pMap->pszMapFile, pMap->iLine);
1569 return false;
1570 }
1571
1572 /* There may be a few lines describing the table notation now, surrounded by blank lines. */
1573 do
1574 {
1575 psz = mapReadLineStripRight(pMap, &cch);
1576 if (!psz)
1577 return false;
1578 } while ( *psz == '\0'
1579 || ( !RT_C_IS_SPACE(psz[0])
1580 && RT_C_IS_SPACE(psz[1])
1581 && psz[2] == '='
1582 && RT_C_IS_SPACE(psz[3]))
1583 );
1584
1585 /* Should have the column heading now. */
1586 va_list va;
1587 va_start(va, cColumns);
1588 for (uint32_t i = 0; i < cColumns; i++)
1589 {
1590 const char *pszColumn = va_arg(va, const char *);
1591 size_t cchColumn = strlen(pszColumn);
1592 if ( strncmp(psz, pszColumn, cchColumn)
1593 || ( psz[cchColumn] != '\0'
1594 && !RT_C_IS_SPACE(psz[cchColumn])))
1595 {
1596 va_end(va);
1597 RTMsgError("%s:%d: Expected column '%s' found '%s'", pMap->pszMapFile, pMap->iLine, pszColumn, psz);
1598 return false;
1599 }
1600 psz += cchColumn;
1601 while (RT_C_IS_SPACE(*psz))
1602 psz++;
1603 }
1604 va_end(va);
1605
1606 /* The next line is the underlining. */
1607 psz = mapReadLineStripRight(pMap, &cch);
1608 if (!psz)
1609 return false;
1610 if (*psz != '=' || psz[cch - 1] != '=')
1611 {
1612 RTMsgError("%s:%d: Expected column header underlining", pMap->pszMapFile, pMap->iLine);
1613 return false;
1614 }
1615
1616 /* Skip one blank line. */
1617 psz = mapReadLineStripRight(pMap, &cch);
1618 if (!psz)
1619 return false;
1620 if (*psz)
1621 {
1622 RTMsgError("%s:%d: Expected blank line beneath the column headers", pMap->pszMapFile, pMap->iLine);
1623 return false;
1624 }
1625
1626 return true;
1627}
1628
1629
1630/**
1631 * Parses a segment list.
1632 *
1633 * @returns @c true on success, @c false + msg on failure, @c false on eof.
1634 * @param pMap The map file handle.
1635 */
1636static bool mapParseSegments(PBIOSMAP pMap)
1637{
1638 for (;;)
1639 {
1640 if (!mapReadLineStripRight(pMap, NULL))
1641 return false;
1642
1643 /* The end? The line should be empty. Expectes segment name to not
1644 start with a space. */
1645 if (!pMap->szLine[0] || RT_C_IS_SPACE(pMap->szLine[0]))
1646 {
1647 if (!pMap->szLine[0])
1648 return true;
1649 RTMsgError("%s:%u: Malformed segment line", pMap->pszMapFile, pMap->iLine);
1650 return false;
1651 }
1652
1653 /* Parse the segment line. */
1654 uint32_t iSeg = g_cSegs;
1655 if (iSeg >= RT_ELEMENTS(g_aSegs))
1656 {
1657 RTMsgError("%s:%u: Too many segments", pMap->pszMapFile, pMap->iLine);
1658 return false;
1659 }
1660
1661 char *psz = pMap->szLine;
1662 if (!mapParseWord(&psz, g_aSegs[iSeg].szName, sizeof(g_aSegs[iSeg].szName)))
1663 RTMsgError("%s:%u: Segment name parser error", pMap->pszMapFile, pMap->iLine);
1664 else if (!mapParseWord(&psz, g_aSegs[iSeg].szClass, sizeof(g_aSegs[iSeg].szClass)))
1665 RTMsgError("%s:%u: Segment class parser error", pMap->pszMapFile, pMap->iLine);
1666 else if (!mapParseWord(&psz, g_aSegs[iSeg].szGroup, sizeof(g_aSegs[iSeg].szGroup)))
1667 RTMsgError("%s:%u: Segment group parser error", pMap->pszMapFile, pMap->iLine);
1668 else if (!mapParseAddress(&psz, &g_aSegs[iSeg].Address))
1669 RTMsgError("%s:%u: Segment address parser error", pMap->pszMapFile, pMap->iLine);
1670 else if (!mapParseSize(&psz, &g_aSegs[iSeg].cb))
1671 RTMsgError("%s:%u: Segment size parser error", pMap->pszMapFile, pMap->iLine);
1672 else
1673 {
1674 g_aSegs[iSeg].uFlatAddr = ((uint32_t)g_aSegs[iSeg].Address.sel << 4) + g_aSegs[iSeg].Address.off;
1675 g_cSegs++;
1676 if (g_cVerbose > 2)
1677 RTStrmPrintf(g_pStdErr, "read segment at %08x / %04x:%04x LB %04x %s / %s / %s\n",
1678 g_aSegs[iSeg].uFlatAddr,
1679 g_aSegs[iSeg].Address.sel,
1680 g_aSegs[iSeg].Address.off,
1681 g_aSegs[iSeg].cb,
1682 g_aSegs[iSeg].szName,
1683 g_aSegs[iSeg].szClass,
1684 g_aSegs[iSeg].szGroup);
1685
1686 while (RT_C_IS_SPACE(*psz))
1687 psz++;
1688 if (!*psz)
1689 continue;
1690 RTMsgError("%s:%u: Junk at end of line", pMap->pszMapFile, pMap->iLine);
1691 }
1692 return false;
1693 }
1694}
1695
1696
1697/**
1698 * Sorts the segment array by flat address and adds them to the debug module.
1699 *
1700 * @returns @c true on success, @c false + msg on failure, @c false on eof.
1701 */
1702static bool mapSortAndAddSegments(void)
1703{
1704 for (uint32_t i = 0; i < g_cSegs; i++)
1705 {
1706 for (uint32_t j = i + 1; j < g_cSegs; j++)
1707 if (g_aSegs[j].uFlatAddr < g_aSegs[i].uFlatAddr)
1708 {
1709 BIOSSEG Tmp = g_aSegs[i];
1710 g_aSegs[i] = g_aSegs[j];
1711 g_aSegs[j] = Tmp;
1712 }
1713 if (g_cVerbose > 0)
1714 RTStrmPrintf(g_pStdErr, "segment at %08x / %04x:%04x LB %04x %s / %s / %s\n",
1715 g_aSegs[i].uFlatAddr,
1716 g_aSegs[i].Address.sel,
1717 g_aSegs[i].Address.off,
1718 g_aSegs[i].cb,
1719 g_aSegs[i].szName,
1720 g_aSegs[i].szClass,
1721 g_aSegs[i].szGroup);
1722
1723 RTDBGSEGIDX idx = i;
1724 int rc = RTDbgModSegmentAdd(g_hMapMod, g_aSegs[i].uFlatAddr, g_aSegs[i].cb, g_aSegs[i].szName, 0 /*fFlags*/, &idx);
1725 if (RT_FAILURE(rc))
1726 {
1727 RTMsgError("RTDbgModSegmentAdd failed on %s: %Rrc", g_aSegs[i].szName);
1728 return false;
1729 }
1730 }
1731 return true;
1732}
1733
1734
1735/**
1736 * Parses a segment list.
1737 *
1738 * @returns @c true on success, @c false + msg on failure, @c false on eof.
1739 * @param pMap The map file handle.
1740 */
1741static bool mapParseSymbols(PBIOSMAP pMap)
1742{
1743 for (;;)
1744 {
1745 if (!mapReadLineStripRight(pMap, NULL))
1746 return false;
1747
1748 /* The end? The line should be empty. Expectes segment name to not
1749 start with a space. */
1750 if (!pMap->szLine[0] || RT_C_IS_SPACE(pMap->szLine[0]))
1751 {
1752 if (!pMap->szLine[0])
1753 return true;
1754 return mapError(pMap, "Malformed symbol line");
1755 }
1756
1757 if (!strncmp(pMap->szLine, RT_STR_TUPLE("Module: ")))
1758 {
1759 /* Parse the module line. */
1760 size_t offObj = sizeof("Module: ") - 1;
1761 while (RT_C_IS_SPACE(pMap->szLine[offObj]))
1762 offObj++;
1763 size_t offSrc = offObj;
1764 char ch;
1765 while ((ch = pMap->szLine[offSrc]) != '(' && ch != '\0')
1766 offSrc++;
1767 size_t cchObj = offSrc - offObj;
1768
1769 offSrc++;
1770 size_t cchSrc = offSrc;
1771 while ((ch = pMap->szLine[cchSrc]) != ')' && ch != '\0')
1772 cchSrc++;
1773 cchSrc -= offSrc;
1774 if (ch != ')')
1775 return mapError(pMap, "Symbol/Module line parse error");
1776
1777 PBIOSOBJFILE pObjFile = (PBIOSOBJFILE)RTMemAllocZ(sizeof(*pObjFile) + cchSrc + cchObj + 2);
1778 if (!pObjFile)
1779 return mapError(pMap, "Out of memory");
1780 char *psz = (char *)(pObjFile + 1);
1781 pObjFile->pszObject = psz;
1782 memcpy(psz, &pMap->szLine[offObj], cchObj);
1783 psz += cchObj;
1784 *psz++ = '\0';
1785 pObjFile->pszSource = psz;
1786 memcpy(psz, &pMap->szLine[offSrc], cchSrc);
1787 psz[cchSrc] = '\0';
1788 RTListAppend(&g_ObjList, &pObjFile->Node);
1789 }
1790 else
1791 {
1792 /* Parse the segment line. */
1793 RTFAR16 Addr;
1794 char *psz = pMap->szLine;
1795 if (!mapParseAddress(&psz, &Addr))
1796 return mapError(pMap, "Symbol address parser error");
1797
1798 char szName[4096];
1799 if (!mapParseWord(&psz, szName, sizeof(szName)))
1800 return mapError(pMap, "Symbol name parser error");
1801
1802 uint32_t uFlatAddr = ((uint32_t)Addr.sel << 4) + Addr.off;
1803 if (uFlatAddr != 0)
1804 {
1805 int rc = RTDbgModSymbolAdd(g_hMapMod, szName, RTDBGSEGIDX_RVA, uFlatAddr, 0 /*cb*/, 0 /*fFlags*/, NULL);
1806 if (RT_FAILURE(rc) && rc != VERR_DBG_ADDRESS_CONFLICT)
1807 {
1808 /* HACK ALERT! For dealing with lables at segment size. */ /** @todo fix end labels. */
1809 rc = RTDbgModSymbolAdd(g_hMapMod, szName, RTDBGSEGIDX_RVA, uFlatAddr - 1, 0 /*cb*/, 0 /*fFlags*/, NULL);
1810 if (RT_FAILURE(rc) && rc != VERR_DBG_ADDRESS_CONFLICT)
1811 return mapError(pMap, "RTDbgModSymbolAdd failed: %Rrc", rc);
1812 }
1813
1814 if (g_cVerbose > 2)
1815 RTStrmPrintf(g_pStdErr, "read symbol - %08x %s\n", uFlatAddr, szName);
1816 while (RT_C_IS_SPACE(*psz))
1817 psz++;
1818 if (*psz)
1819 return mapError(pMap, "Junk at end of line");
1820 }
1821
1822 }
1823 }
1824}
1825
1826
1827/**
1828 * Parses the given map file.
1829 *
1830 * @returns RTEXITCODE_SUCCESS and lots of globals, or RTEXITCODE_FAILURE and a
1831 * error message.
1832 * @param pMap The map file handle.
1833 */
1834static RTEXITCODE mapParseFile(PBIOSMAP pMap)
1835{
1836 int rc = RTDbgModCreate(&g_hMapMod, "VBoxBios", 0 /*cbSeg*/, 0 /*fFlags*/);
1837 if (RT_FAILURE(rc))
1838 return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTDbgModCreate failed: %Rrc", rc);
1839
1840 /*
1841 * Read the header.
1842 */
1843 if (!mapReadLine(pMap))
1844 return RTEXITCODE_FAILURE;
1845 if (strncmp(pMap->szLine, RT_STR_TUPLE("Open Watcom Linker Version")))
1846 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Unexpected map-file header: '%s'", pMap->szLine);
1847 if ( !mapSkipNonEmptyLines(pMap)
1848 || !mapSkipEmptyLines(pMap))
1849 return RTEXITCODE_FAILURE;
1850
1851 /*
1852 * Skip groups.
1853 */
1854 if (!mapSkipThruColumnHeadings(pMap, "Groups", 3, "Group", "Address", "Size", NULL))
1855 return RTEXITCODE_FAILURE;
1856 if (!mapSkipNonEmptyLines(pMap))
1857 return RTEXITCODE_FAILURE;
1858
1859 /*
1860 * Parse segments.
1861 */
1862 if (!mapSkipThruColumnHeadings(pMap, "Segments", 5, "Segment", "Class", "Group", "Address", "Size"))
1863 return RTEXITCODE_FAILURE;
1864 if (!mapParseSegments(pMap))
1865 return RTEXITCODE_FAILURE;
1866 if (!mapSortAndAddSegments())
1867 return RTEXITCODE_FAILURE;
1868
1869 /*
1870 * Parse symbols.
1871 */
1872 if (!mapSkipThruColumnHeadings(pMap, "Memory Map", 2, "Address", "Symbol"))
1873 return RTEXITCODE_FAILURE;
1874 if (!mapParseSymbols(pMap))
1875 return RTEXITCODE_FAILURE;
1876
1877 /* Ignore the rest of the file. */
1878 return RTEXITCODE_SUCCESS;
1879}
1880
1881
1882/**
1883 * Parses the linker map file for the BIOS.
1884 *
1885 * This is generated by the Watcom linker.
1886 *
1887 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg.
1888 * @param pszBiosMap Path to the map file.
1889 */
1890static RTEXITCODE ParseMapFile(const char *pszBiosMap)
1891{
1892 BIOSMAP Map;
1893 Map.pszMapFile = pszBiosMap;
1894 Map.hStrm = NULL;
1895 Map.iLine = 0;
1896 Map.fEof = false;
1897 Map.cch = 0;
1898 Map.offNW = 0;
1899 int rc = RTStrmOpen(pszBiosMap, "r", &Map.hStrm);
1900 if (RT_FAILURE(rc))
1901 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error opening '%s': %Rrc", pszBiosMap, rc);
1902 RTEXITCODE rcExit = mapParseFile(&Map);
1903 RTStrmClose(Map.hStrm);
1904 return rcExit;
1905}
1906
1907
1908/**
1909 * Reads the BIOS image into memory (g_pbImg and g_cbImg).
1910 *
1911 * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE+msg.
1912 * @param pszBiosImg Path to the image file.
1913 */
1914static RTEXITCODE ReadBiosImage(const char *pszBiosImg)
1915{
1916 void *pvImg;
1917 size_t cbImg;
1918 int rc = RTFileReadAll(pszBiosImg, &pvImg, &cbImg);
1919 if (RT_FAILURE(rc))
1920 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Error reading '%s': %Rrc", pszBiosImg, rc);
1921
1922 size_t cbImgExpect;
1923 switch (g_enmBiosType)
1924 {
1925 case kBiosType_System: cbImgExpect = _64K; break;
1926 case kBiosType_Vga: cbImgExpect = _32K; break;
1927 default: cbImgExpect = 0; break;
1928 }
1929 if (cbImg != cbImgExpect)
1930 {
1931 RTFileReadAllFree(pvImg, cbImg);
1932 return RTMsgErrorExit(RTEXITCODE_FAILURE, "The BIOS image %u bytes intead of %u bytes", cbImg, cbImgExpect);
1933 }
1934
1935 g_pbImg = (uint8_t *)pvImg;
1936 g_cbImg = cbImg;
1937 return RTEXITCODE_SUCCESS;
1938}
1939
1940
1941int main(int argc, char **argv)
1942{
1943 int rc = RTR3InitExe(argc, &argv, 0);
1944 if (RT_FAILURE(rc))
1945 return RTMsgInitFailure(rc);
1946
1947 RTListInit(&g_ObjList);
1948
1949 /*
1950 * Option config.
1951 */
1952 static RTGETOPTDEF const s_aOpts[] =
1953 {
1954 { "--bios-image", 'i', RTGETOPT_REQ_STRING },
1955 { "--bios-map", 'm', RTGETOPT_REQ_STRING },
1956 { "--bios-sym", 's', RTGETOPT_REQ_STRING },
1957 { "--bios-type", 't', RTGETOPT_REQ_STRING },
1958 { "--output", 'o', RTGETOPT_REQ_STRING },
1959 { "--verbose", 'v', RTGETOPT_REQ_NOTHING },
1960 { "--quiet", 'q', RTGETOPT_REQ_NOTHING },
1961 };
1962
1963 const char *pszBiosMap = NULL;
1964 const char *pszBiosSym = NULL;
1965 const char *pszBiosImg = NULL;
1966 const char *pszOutput = NULL;
1967
1968 RTGETOPTUNION ValueUnion;
1969 RTGETOPTSTATE GetOptState;
1970 rc = RTGetOptInit(&GetOptState, argc, argv, &s_aOpts[0], RT_ELEMENTS(s_aOpts), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
1971 AssertReleaseRCReturn(rc, RTEXITCODE_FAILURE);
1972
1973 /*
1974 * Process the options.
1975 */
1976 while ((rc = RTGetOpt(&GetOptState, &ValueUnion)) != 0)
1977 {
1978 switch (rc)
1979 {
1980 case 'i':
1981 if (pszBiosImg)
1982 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "--bios-image is given more than once");
1983 pszBiosImg = ValueUnion.psz;
1984 break;
1985
1986 case 'm':
1987 if (pszBiosMap)
1988 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "--bios-map is given more than once");
1989 pszBiosMap = ValueUnion.psz;
1990 break;
1991
1992 case 's':
1993 if (pszBiosSym)
1994 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "--bios-sym is given more than once");
1995 pszBiosSym = ValueUnion.psz;
1996 break;
1997
1998 case 'o':
1999 if (pszOutput)
2000 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "--output is given more than once");
2001 pszOutput = ValueUnion.psz;
2002 break;
2003
2004 case 't':
2005 if (!strcmp(ValueUnion.psz, "system"))
2006 {
2007 g_enmBiosType = kBiosType_System;
2008 g_uBiosFlatBase = 0xf0000;
2009 }
2010 else if (!strcmp(ValueUnion.psz, "vga"))
2011 {
2012 g_enmBiosType = kBiosType_Vga;
2013 g_uBiosFlatBase = 0xc0000;
2014 }
2015 else
2016 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unknown bios type '%s'", ValueUnion.psz);
2017 break;
2018
2019 case 'v':
2020 g_cVerbose++;
2021 break;
2022
2023 case 'q':
2024 g_cVerbose = 0;
2025 break;
2026
2027 case 'H':
2028 RTPrintf("usage: %Rbn --bios-image <file.img> --bios-map <file.map> [--output <file.asm>]\n",
2029 argv[0]);
2030 return RTEXITCODE_SUCCESS;
2031
2032 case 'V':
2033 {
2034 /* The following is assuming that svn does it's job here. */
2035 char szRev[] = "$Revision: 62450 $";
2036 char *psz = szRev;
2037 while (*psz && !RT_C_IS_DIGIT(*psz))
2038 psz++;
2039 size_t i = strlen(psz);
2040 while (i > 0 && !RT_C_IS_DIGIT(psz[i - 1]))
2041 psz[--i] = '\0';
2042
2043 RTPrintf("r%s\n", psz);
2044 return RTEXITCODE_SUCCESS;
2045 }
2046
2047 default:
2048 return RTGetOptPrintError(rc, &ValueUnion);
2049 }
2050 }
2051
2052 /*
2053 * Got it all?
2054 */
2055 if (!pszBiosImg)
2056 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "--bios-image is required");
2057 if (!pszBiosMap)
2058 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "--bios-map is required");
2059 if (!pszBiosSym)
2060 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "--bios-sym is required");
2061
2062 /*
2063 * Do the job.
2064 */
2065 RTEXITCODE rcExit;
2066 rcExit = ReadBiosImage(pszBiosImg);
2067 if (rcExit == RTEXITCODE_SUCCESS)
2068 rcExit = ParseMapFile(pszBiosMap);
2069 if (rcExit == RTEXITCODE_SUCCESS)
2070 rcExit = ParseSymFile(pszBiosSym);
2071 if (rcExit == RTEXITCODE_SUCCESS)
2072 rcExit = OpenOutputFile(pszOutput);
2073 if (rcExit == RTEXITCODE_SUCCESS)
2074 rcExit = DisassembleBiosImage();
2075
2076 return rcExit;
2077}
2078
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette