Changeset 41609 in vbox
- Timestamp:
- Jun 7, 2012 2:27:31 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/PC/BIOS-new/MakeDebianBiosAssembly.cpp
r41509 r41609 27 27 #include <iprt/getopt.h> 28 28 #include <iprt/initterm.h> 29 #include <iprt/list.h> 29 30 #include <iprt/mem.h> 30 31 #include <iprt/message.h> … … 60 61 /** Pointer to a BIOS segment. */ 61 62 typedef BIOSSEG *PBIOSSEG; 63 64 65 /** 66 * A BIOS object file. 67 */ 68 typedef struct BIOSOBJFILE 69 { 70 RTLISTNODE Node; 71 char *pszSource; 72 char *pszObject; 73 } BIOSOBJFILE; 74 /** A BIOS object file. */ 75 typedef BIOSOBJFILE *PBIOSOBJFILE; 62 76 63 77 … … 101 115 /** Array of BIOS segments from the map file. */ 102 116 static BIOSSEG g_aSegs[32]; 117 /** List of BIOSOBJFILE. */ 118 static RTLISTANCHOR g_ObjList; 103 119 104 120 /** The output stream. */ … … 172 188 static bool disFileHeader(void) 173 189 { 174 return outputPrintf("; $Id$ \n" 175 ";; @file\n" 176 "; Auto Generated source file. Do not edit.\n" 177 ";\n" 178 "\n" 179 "org 0xf000\n" 180 "\n" 181 ); 190 bool fRc; 191 fRc = outputPrintf("; $Id$ \n" 192 ";; @file\n" 193 "; Auto Generated source file. Do not edit.\n" 194 ";\n" 195 ); 196 if (!fRc) 197 return fRc; 198 199 /* 200 * List the header of each source file, up to and including the 201 * copyright notice. 202 */ 203 PBIOSOBJFILE pObjFile; 204 RTListForEach(&g_ObjList, pObjFile, BIOSOBJFILE, Node) 205 { 206 PRTSTREAM hStrm; 207 int rc = RTStrmOpen(pObjFile->pszSource, "r", &hStrm); 208 if (RT_SUCCESS(rc)) 209 { 210 fRc = outputPrintf("\n" 211 ";\n" 212 "; Source file: %Rbn\n" 213 ";\n" 214 , pObjFile->pszSource); 215 uint32_t iLine = 0; 216 bool fSeenCopyright = false; 217 char szLine[4096]; 218 while ((rc = RTStrmGetLine(hStrm, szLine, sizeof(szLine))) == VINF_SUCCESS) 219 { 220 iLine++; 221 222 /* Check if we're done. */ 223 char *psz = RTStrStrip(szLine); 224 if ( fSeenCopyright 225 && ( (psz[0] == '*' && psz[1] == '/') 226 || psz[0] == '\0') ) 227 break; 228 229 /* Strip comment suffix. */ 230 size_t cch = strlen(psz); 231 if (cch >= 2 && psz[cch - 1] == '/' && psz[cch - 2] == '*') 232 { 233 psz[cch - 2] = '\0'; 234 RTStrStripR(psz); 235 } 236 237 /* Skip line prefix. */ 238 if (psz[0] == '/' && psz[1] == '*') 239 psz += 2; 240 else if (psz[0] == '*') 241 psz += 1; 242 else 243 while (*psz == ';') 244 psz++; 245 if (RT_C_IS_SPACE(*psz)) 246 psz++; 247 248 /* Skip the doxygen file tag line. */ 249 if (!strcmp(psz, "* @file") || !strcmp(psz, "@file")) 250 continue; 251 252 /* Detect copyright section. */ 253 if ( !fSeenCopyright 254 && ( strstr(psz, "Copyright") 255 || strstr(psz, "copyright")) ) 256 fSeenCopyright = true; 257 258 fRc = outputPrintf("; %s\n", psz) && fRc; 259 } 260 261 RTStrmClose(hStrm); 262 if (rc != VINF_SUCCESS) 263 return disError("Error reading '%s': rc=%Rrc iLine=%u", pObjFile->pszSource, rc, iLine); 264 } 265 } 266 267 /* 268 * Set the org. 269 */ 270 fRc = outputPrintf("\n" 271 "\n" 272 "\n" 273 ) && fRc; 274 return fRc; 182 275 } 183 276 … … 973 1066 static RTEXITCODE DisassembleBiosImage(void) 974 1067 { 975 if (! outputPrintf(""))1068 if (!disFileHeader()) 976 1069 return RTEXITCODE_FAILURE; 977 1070 … … 1048 1141 #endif 1049 1142 return RTEXITCODE_SUCCESS; 1143 } 1144 1145 1146 /** 1147 * Display an error with the mapfile name and current line, return false. 1148 * 1149 * @returns @c false. 1150 * @param pMap The map file handle. 1151 * @param pszFormat The format string. 1152 * @param ... Format arguments. 1153 */ 1154 static bool mapError(PBIOSMAP pMap, const char *pszFormat, ...) 1155 { 1156 va_list va; 1157 va_start(va, pszFormat); 1158 RTMsgError("%s:%d: %N", pMap->pszMapFile, pMap->iLine, pszFormat, va); 1159 va_end(va); 1160 return false; 1050 1161 } 1051 1162 … … 1576 1687 if (!pMap->szLine[0]) 1577 1688 return true; 1578 RTMsgError("%s:%u: Malformed symbol line", pMap->pszMapFile, pMap->iLine); 1579 return false; 1580 } 1581 1582 /* Skip the module name lines for now. */ 1689 return mapError(pMap, "Malformed symbol line"); 1690 } 1691 1583 1692 if (!strncmp(pMap->szLine, RT_STR_TUPLE("Module: "))) 1584 continue; 1585 1586 /* Parse the segment line. */ 1587 char szName[4096]; 1588 RTFAR16 Addr; 1589 char *psz = pMap->szLine; 1590 if (!mapParseAddress(&psz, &Addr)) 1591 RTMsgError("%s:%u: Symbol address parser error", pMap->pszMapFile, pMap->iLine); 1592 else if (!mapParseWord(&psz, szName, sizeof(szName))) 1593 RTMsgError("%s:%u: Symbol name parser error", pMap->pszMapFile, pMap->iLine); 1693 { 1694 /* Parse the module line. */ 1695 size_t offObj = sizeof("Module: ") - 1; 1696 while (RT_C_IS_SPACE(pMap->szLine[offObj])) 1697 offObj++; 1698 size_t offSrc = offObj; 1699 char ch; 1700 while ((ch = pMap->szLine[offSrc]) != '(' && ch != '\0') 1701 offSrc++; 1702 size_t cchObj = offSrc - offObj; 1703 1704 offSrc++; 1705 size_t cchSrc = offSrc; 1706 while ((ch = pMap->szLine[cchSrc]) != ')' && ch != '\0') 1707 cchSrc++; 1708 cchSrc -= offSrc; 1709 if (ch != ')') 1710 return mapError(pMap, "Symbol/Module line parse error"); 1711 1712 PBIOSOBJFILE pObjFile = (PBIOSOBJFILE)RTMemAllocZ(sizeof(*pObjFile) + cchSrc + cchObj + 2); 1713 if (!pObjFile) 1714 return mapError(pMap, "Out of memory"); 1715 char *psz = (char *)(pObjFile + 1); 1716 pObjFile->pszObject = psz; 1717 memcpy(psz, &pMap->szLine[offObj], cchObj); 1718 psz += cchObj; 1719 *psz++ = '\0'; 1720 pObjFile->pszSource = psz; 1721 memcpy(psz, &pMap->szLine[offSrc], cchSrc); 1722 psz[cchSrc] = '\0'; 1723 RTListAppend(&g_ObjList, &pObjFile->Node); 1724 } 1594 1725 else 1595 1726 { 1596 uint32_t uFlatAddr = ((uint32_t)Addr.sel << 4) + Addr.off; 1597 if (uFlatAddr == 0) 1598 continue; 1599 1600 int rc = RTDbgModSymbolAdd(g_hMapMod, szName, RTDBGSEGIDX_RVA, uFlatAddr, 0 /*cb*/, 0 /*fFlags*/, NULL); 1601 if (RT_SUCCESS(rc) || rc == VERR_DBG_ADDRESS_CONFLICT) 1727 /* Parse the segment line. */ 1728 RTFAR16 Addr; 1729 char *psz = pMap->szLine; 1730 if (!mapParseAddress(&psz, &Addr)) 1731 return mapError(pMap, "Symbol address parser error"); 1732 1733 char szName[4096]; 1734 if (!mapParseWord(&psz, szName, sizeof(szName))) 1735 return mapError(pMap, "Symbol name parser error"); 1736 1737 uint32_t uFlatAddr = ((uint32_t)Addr.sel << 4) + Addr.off; 1738 if (uFlatAddr != 0) 1602 1739 { 1740 int rc = RTDbgModSymbolAdd(g_hMapMod, szName, RTDBGSEGIDX_RVA, uFlatAddr, 0 /*cb*/, 0 /*fFlags*/, NULL); 1741 if (RT_FAILURE(rc) && rc != VERR_DBG_ADDRESS_CONFLICT) 1742 return mapError(pMap, "RTDbgModSymbolAdd failed: %Rrc", rc); 1603 1743 1604 1744 if (g_cVerbose > 2) … … 1606 1746 while (RT_C_IS_SPACE(*psz)) 1607 1747 psz++; 1608 if (!*psz) 1609 continue; 1610 RTMsgError("%s:%u: Junk at end of line", pMap->pszMapFile, pMap->iLine); 1748 if (*psz) 1749 return mapError(pMap, "Junk at end of line"); 1611 1750 } 1612 else 1613 RTMsgError("%s:%u: RTDbgModSymbolAdd failed: %Rrc", pMap->pszMapFile, pMap->iLine, rc); 1614 } 1615 return false; 1751 1752 } 1616 1753 } 1617 1754 } … … 1730 1867 return RTMsgInitFailure(rc); 1731 1868 1869 RTListInit(&g_ObjList); 1870 1732 1871 /* 1733 1872 * Option config.
Note:
See TracChangeset
for help on using the changeset viewer.