1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046
|
/* -*- mode: C++; tab-width: 4 -*- */
/* ===================================================================== *\
Copyright (c) 1999-2001 Palm, Inc. or its subsidiaries.
All rights reserved.
This file is part of the Palm OS Emulator.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
\* ===================================================================== */
#include "EmCommon.h"
#include "EmPalmFunction.h"
#include "EmBankROM.h" // EmBankROM::GetMemoryStart
#include "EmLowMem.h" // LowMem_GetGlobal
#include "EmMemory.h" // CEnableFullAccess, EmMem_strcpy, EmMem_memcmp
#include "EmPalmHeap.h" // EmPalmHeap
#include "EmPatchState.h" // EmPatchState::OSMajorVersion
#include "Miscellaneous.h" // FindFunctionName
#include "Platform.h" // Platform::GetString
#include "Strings.r.h" // kStr_INetLibTrapBase
#include <ctype.h> // isalnum, toupper
const UInt16 kMagicRefNum = 0x666; // See comments in HtalLibSendReply.
const uint16 kOpcode_ADD = 0x0697; // ADD.L X, (A7)
const uint16 kOpcode_LINK = 0x4E50;
const uint16 kOpcode_RTE = 0x4E73;
const uint16 kOpcode_RTD = 0x4E74;
const uint16 kOpcode_RTS = 0x4E75;
const uint16 kOpcode_JMP = 0x4ED0;
const uint16 kOpcode_CMPW = 0xB47C; // CMP.W #$xxxx,D2
const uint16 kOpcode_ADDW = 0xD442; // ADD.W D2,D2
const uint32 kOpcode_JMPPC = 0x4EFB2002; // JMP *+$0004(D2.W)
const uint16 kOpcode_JMPREL = 0x4EFA; // JMP *+$xxxx
const uint16 kOpcode_MOVEL = 0x2038; // MOVE.L $xxxxxxxx,D0
// This table should match up with gResourceBases in ErrorHandling.cpp.
static const char* gPalmOSLibraries [] =
{
"INet.lib",
"IrDA Library", // Also includes Exchange Lib
"Security.lib",
"Web.lib",
// serIrCommLibNameP, // ???SerIrCommLib.h doesn't declare the functions as SYSTRAPs!
"Debugger Comm",
"IrSerial Library",
"Net.lib",
"PADHTAL.lib",
"Rail I/O Library",
"RMP NetPlugIn.lib",
"Serial Lib68681",
"Serial Library",
"TCPHTAL.lib",
NULL
};
const uint8 kCerticomMemCpyPattern [] =
{
0x20, 0x6F, 0x00, 0x04, // 080B3CE2 MOVEA.L $0004(A7),A0 | 206F 0004
0x22, 0x6F, 0x00, 0x08, // 080B3CE6 MOVEA.L $0008(A7),A1 | 226F 0008
0x30, 0x2F, 0x00, 0x0C, // 080B3CEA MOVE.W $000C(A7),D0 | 302F 000C
0x60, 0x02, // 080B3CEE BRA.S *+$0004 ; 080B3CF2 | 6002
0x10, 0xD9, // 080B3CF0 MOVE.B (A1)+,(A0)+ | 10D9
0x51, 0xC8, 0xFF, 0xFC, // 080B3CF2 DBF D0,*-$0002 ; 080B3CF0 | 51C8 FFFC
0x4E, 0x75 // 080B3CF6 RTS | 4E75
};
class EmFunctionRange
{
public:
EmFunctionRange (const char* functionName);
Bool InRange (emuptr = gCPU->GetPC ());
void Reset (void);
Bool HasRange (void) { return fBegin != EmMemNULL; }
private:
void GetRange (emuptr addr);
const char* fName;
emuptr fBegin;
emuptr fEnd;
EmFunctionRange* fNext;
static EmFunctionRange* fgRoot;
};
EmFunctionRange* EmFunctionRange::fgRoot;
// Define a bunch of EmFunctionRange objects to search for and
// cache function ranges.
#define DEFINE_OBJECT(fn_name) \
static EmFunctionRange g##fn_name (#fn_name);
FOR_EACH_FUNCTION(DEFINE_OBJECT)
// Define all the InFoo functions declared in EmPalmFunction.h.
#define DEFINE_FUNCTION(fn_name) \
Bool In##fn_name (emuptr addr) { return g##fn_name.InRange (addr); }
FOR_EACH_FUNCTION(DEFINE_FUNCTION)
static string PrvGetShortName (const char*, int len);
/***********************************************************************
*
* FUNCTION: EmFunctionRangeInit
*
* DESCRIPTION: Reset all our objects that track where certain Palm
* functions exist in memory.
*
* PARAMETERS: None
*
* RETURNED: Nothing
*
***********************************************************************/
void EmPalmFunctionInit (void)
{
#define RESET_OBJECT(fn_name) \
g##fn_name.Reset ();
FOR_EACH_FUNCTION(RESET_OBJECT)
}
/***********************************************************************
*
* FUNCTION: EmFunctionRange::EmFunctionRange
*
* DESCRIPTION: Create the object. Initialize all data members.
*
* PARAMETERS: functionName - name of function to track. Storage is
* not owned by this object, so clients should make
* sure it exists for the life of this object. The
* function name is typically provided as a string
* constant in global space.
*
* RETURNED: Nothing
*
***********************************************************************/
EmFunctionRange::EmFunctionRange (const char* functionName) :
fName (functionName),
fBegin (EmMemNULL),
fEnd (EmMemNULL),
fNext (fgRoot)
{
fgRoot = this;
}
/***********************************************************************
*
* FUNCTION: EmFunctionRange::InRange
*
* DESCRIPTION: Determine whether or not the given address is within
* the function managed by this object.
*
* PARAMETERS: addr - address to test.
*
* RETURNED: True if so.
*
***********************************************************************/
Bool EmFunctionRange::InRange (emuptr addr)
{
// It's not in our range if it's in someone else's.
// This is an optimization.
static Bool walkingChain;
if (!walkingChain)
{
walkingChain = true;
EmFunctionRange* range = fgRoot;
while (range)
{
if (range != this && range->HasRange () && range->InRange (addr))
{
walkingChain = false;
return false;
}
range = range->fNext;
}
walkingChain = false;
}
// If we haven't determine the range of the function for which we're
// responsible, see if given address is in that function. If so,
// remember the range of that function.
if (!this->HasRange ())
{
this->GetRange (addr);
}
// If we know the range of the function for which we are responsible,
// test the address against that range.
if (this->HasRange () && (addr >= fBegin) && (addr < fEnd))
{
// We may not want to cache the range if it's in RAM.
EmMemGetFunc func = EmMemGetBank(addr).lget;
if ((func != &EmBankROM::GetLong) && (func != &EmBankFlash::GetLong))
{
this->Reset ();
}
return true;
}
return false;
}
/***********************************************************************
*
* FUNCTION: EmFunctionRange::Reset
*
* DESCRIPTION: If we've determined and remembered where the managed
* function exists, forget that information. This method
* is typically called so that this object can be reused
* after a new ROM image has been loaded.
*
* PARAMETERS: None
*
* RETURNED: Nothing
*
***********************************************************************/
void EmFunctionRange::Reset (void)
{
fBegin = EmMemNULL;
fEnd = EmMemNULL;
}
/***********************************************************************
*
* FUNCTION: EmFunctionRange::GetRange
*
* DESCRIPTION: Find the name of the function containing the given
* address. If it's our managed function, remember the
* range of the function.
*
* PARAMETERS: addr - probe address.
*
* RETURNED: Nothing
*
***********************************************************************/
void EmFunctionRange::GetRange (emuptr addr)
{
char name[80];
emuptr startAddr;
emuptr endAddr;
::FindFunctionName (addr, name, &startAddr, &endAddr, 80);
string shortName = ::PrvGetShortName (fName, 8);
// See if the function has the name as specified in fName.
if (strncmp (name, fName, 79) == 0)
{
fBegin = startAddr;
fEnd = endAddr;
}
// If not, see if the function name is the same as the "fixed 8"
// format of the Macsbug name.
else if (strcmp (name, shortName.c_str ()) == 0)
{
fBegin = startAddr;
fEnd = endAddr;
}
// Check to see if it looks like this is the function the Certicom
// Encryption library uses to copy "random" data. There's no
// Macsbug name, so we have to go with some other signature.
else if (strcmp ("_CerticomMemCpy", fName) == 0)
{
if (endAddr - startAddr != 0x16)
return;
if (EmMem_memcmp (startAddr, (void*) kCerticomMemCpyPattern, endAddr - startAddr) != 0)
return;
fBegin = startAddr;
fEnd = endAddr;
}
}
/***********************************************************************
*
* FUNCTION: PrvProscribedFunction
*
* DESCRIPTION: Return whether or not the user should be warned about
* calling this function.
*
* PARAMETERS: context - information about the system call context.
*
* RETURNED: True if this function is proscribed and should not be
* called; false if it's OK for applications to call it.
*
***********************************************************************/
// *****************************************************************
// * New Serial Manager trap selectors
// *****************************************************************
// The numbering of these #defines *MUST* match the order in SerialMgr.c
#define sysSerialInstall 0
#define sysSerialOpen 1
#define sysSerialOpenBkgnd 2
#define sysSerialClose 3
#define sysSerialSleep 4
#define sysSerialWake 5
#define sysSerialGetDeviceCount 6
#define sysSerialGetDeviceInfo 7
#define sysSerialGetStatus 8
#define sysSerialClearErr 9
#define sysSerialControl 10
#define sysSerialSend 11
#define sysSerialSendWait 12
#define sysSerialSendCheck 13
#define sysSerialSendFlush 14
#define sysSerialReceive 15
#define sysSerialReceiveWait 16
#define sysSerialReceiveCheck 17
#define sysSerialReceiveFlush 18
#define sysSerialSetRcvBuffer 19
#define sysSerialRcvWindowOpen 20
#define sysSerialRcvWindowClose 21
#define sysSerialSetWakeupHandler 22
#define sysSerialPrimeWakeupHandler 23
#define sysSerialOpenV4 24
#define sysSerialOpenBkgndV4 25
#define sysSerialCustomControl 26
// Selectors for routines found in the international manager. The order
// of these selectors MUST match the jump table in IntlDispatch.c.
#define intlIntlInit 0
#define intlTxtByteAttr 1
#define intlTxtCharAttr 2
#define intlTxtCharXAttr 3
#define intlTxtCharSize 4
#define intlTxtGetPreviousChar 5
#define intlTxtGetNextChar 6
#define intlTxtGetChar 7
#define intlTxtSetNextChar 8
#define intlTxtCharBounds 9
#define intlTxtPrepFindString 10
#define intlTxtFindString 11
#define intlTxtReplaceStr 12
#define intlTxtWordBounds 13
#define intlTxtCharEncoding 14
#define intlTxtStrEncoding 15
#define intlTxtEncodingName 16
#define intlTxtMaxEncoding 17
#define intlTxtTransliterate 18
#define intlTxtCharIsValid 19
#define intlTxtCompare 20
#define intlTxtCaselessCompare 21
#define intlTxtCharWidth 22
#define intlTxtGetTruncationOffset 23
#define intlIntlGetRoutineAddress 24
#define intlIntlHandleEvent 25 // New for Palm OS 3.5
#define intlTxtParamString 26
#define intlTxtConvertEncodingV35 27 // Patched for Palm OS 3.5.2
#define intlTxtConvertEncoding 28 // New for Palm OS 4.0
#define intlIntlSetRoutineAddress 29
#define intlTxtGetWordWrapOffset 30
#define intlTxtNameToEncoding 31
#define intlIntlStrictChecks 32
// Selectors used for getting to the right Overlay Manager routine via
// the OmDispatch trap.
#define omInit 0
#define omOpenOverlayDatabase 1
#define omLocaleToOverlayDBName 2
#define omOverlayDBNameToLocale 3
#define omGetCurrentLocale 4
#define omGetIndexedLocale 5
#define omGetSystemLocale 6
#define omSetSystemLocale 7
#define omGetRoutineAddress 8
#define omGetNextSystemLocale 9
struct EmProscribedFunction
{
uint16 fTrapWord;
int fReason;
};
static const EmProscribedFunction kProscribedFunctionTrapWords [] =
{
// Entries marked with "//*" are supported in PACE because Palm
// apps, test apps, or Palm Debugger needs them, but developers
// should probably still be warned that they should not be using
// them. Additionally, the Fpl functions are marked this way
// because many applications call them, but we'd like to warn
// them to use the Flp functions.
/*
6 Appendix B - Unsupported Palm OS APIs
The following is a list of Palm OS traps that are not supported
by the Timulator. The list is broken into a number of different
groups (which more or less explains why the trap was not implemented).
6.1.1 Documented 'System Use Only' Traps
These traps are documented as "System Use Only" in the "Palm OS
Reference Manual".
*/
{ sysTrapAlmAlarmCallback, kProscribedDocumentedSystemUseOnly },
{ sysTrapAlmCancelAll, kProscribedDocumentedSystemUseOnly },
{ sysTrapAlmDisplayAlarm, kProscribedDocumentedSystemUseOnly },
{ sysTrapAlmEnableNotification, kProscribedDocumentedSystemUseOnly }, //* supported
{ sysTrapAlmInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapAlmTimeChange, kProscribedDocumentedSystemUseOnly },
{ sysTrapDmInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapEvtDequeueKeyEvent, kProscribedDocumentedSystemUseOnly },
{ sysTrapEvtGetSysEvent, kProscribedDocumentedSystemUseOnly }, //* pseudo supported
{ sysTrapEvtInitialize, kProscribedDocumentedSystemUseOnly },
{ sysTrapEvtSetKeyQueuePtr, kProscribedDocumentedSystemUseOnly },
{ sysTrapEvtSetPenQueuePtr, kProscribedDocumentedSystemUseOnly },
{ sysTrapEvtSysInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapExgInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapFrmAddSpaceForObject, kProscribedDocumentedSystemUseOnly },
{ sysTrapFtrInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapGrfFree, kProscribedDocumentedSystemUseOnly },
{ sysTrapGrfInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapInsPtCheckBlink, kProscribedDocumentedSystemUseOnly },
{ sysTrapInsPtInitialize, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemCardFormat, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemHandleFlags, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemHandleOwner, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemHandleResetLock, kProscribedDocumentedSystemUseOnly }, //* supported for release ROMs
{ sysTrapMemHeapFreeByOwnerID, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemHeapInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemInitHeapTable, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemKernelInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemPtrFlags, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemPtrOwner, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemPtrResetLock, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemStoreInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapMemStoreSetInfo, kProscribedDocumentedSystemUseOnly },
{ sysTrapPenClose, kProscribedDocumentedSystemUseOnly },
{ sysTrapPenGetRawPen, kProscribedDocumentedSystemUseOnly },
{ sysTrapPenOpen, kProscribedDocumentedSystemUseOnly },
{ sysTrapPenRawToScreen, kProscribedDocumentedSystemUseOnly },
{ sysTrapPenScreenToRaw, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrCompressScanLine, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrCopyRectangle, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrDeCompressScanLine, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrDrawChars, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrDrawNotify, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrLineRoutine, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrRectangleRoutine, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrScreenInfo, kProscribedDocumentedSystemUseOnly },
{ sysTrapScrSendUpdateArea, kProscribedDocumentedSystemUseOnly },
{ sysTrapSlkProcessRPC, kProscribedDocumentedSystemUseOnly },
{ sysTrapSlkSysPktDefaultResponse, kProscribedDocumentedSystemUseOnly },
{ sysTrapSndInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapSysBatteryDialog, kProscribedDocumentedSystemUseOnly },
{ sysTrapSysColdBoot, kProscribedDocumentedSystemUseOnly },
{ sysTrapSysDoze, kProscribedDocumentedSystemUseOnly },
{ sysTrapSysInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapSysLaunchConsole, kProscribedDocumentedSystemUseOnly }, //* supported
{ sysTrapSysNewOwnerID, kProscribedDocumentedSystemUseOnly },
// { sysTrapSysReserved10Trap1, kProscribedDocumentedSystemUseOnly },
// { sysTrapSysReserved31Trap1, kProscribedDocumentedSystemUseOnly },
{ sysTrapSysSemaphoreSet, kProscribedDocumentedSystemUseOnly },
{ sysTrapSysUILaunch, kProscribedDocumentedSystemUseOnly },
{ sysTrapSysWantEvent, kProscribedDocumentedSystemUseOnly },
{ sysTrapTimInit, kProscribedDocumentedSystemUseOnly },
{ sysTrapUIInitialize, kProscribedDocumentedSystemUseOnly },
{ sysTrapUIReset, kProscribedDocumentedSystemUseOnly },
{ sysTrapWinAddWindow, kProscribedDocumentedSystemUseOnly },
{ sysTrapWinRemoveWindow, kProscribedDocumentedSystemUseOnly },
/*
6.1.2 Undocumented 'System Use Only' or 'HAL Use Only' Traps
These traps are routines in the HAL, documented in headers to be
called by Palm OS only, or I have spoken with the authors of those
traps who identified them as internal traps.
*/
{ sysTrapAttnAllowClose, kProscribedUndocumentedSystemUseOnly }, //* supported
{ sysTrapAttnDoEmergencySpecialEffects, kProscribedUndocumentedSystemUseOnly },
{ sysTrapAttnEffectOfEvent, kProscribedUndocumentedSystemUseOnly },
{ sysTrapAttnEnableNotification, kProscribedUndocumentedSystemUseOnly }, //* supported
{ sysTrapAttnHandleEvent, kProscribedUndocumentedSystemUseOnly },
{ sysTrapAttnIndicatorAllow, kProscribedUndocumentedSystemUseOnly }, //* supported
{ sysTrapAttnIndicatorAllowed, kProscribedUndocumentedSystemUseOnly }, //* supported
{ sysTrapAttnIndicatorCheckBlink, kProscribedUndocumentedSystemUseOnly },
{ sysTrapAttnIndicatorGetBlinkPattern, kProscribedUndocumentedSystemUseOnly }, //* supported
{ sysTrapAttnIndicatorSetBlinkPattern, kProscribedUndocumentedSystemUseOnly }, //* supported
{ sysTrapAttnIndicatorTicksTillNextBlink, kProscribedUndocumentedSystemUseOnly },
{ sysTrapAttnInitialize, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltCopyRectangle, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltDrawChars, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltFindIndexes, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltGetPixel, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltLineRoutine, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltPaintPixel, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltPaintPixels, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltRectangleRoutine, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltRoundedRectangle, kProscribedUndocumentedSystemUseOnly },
{ sysTrapBltRoundedRectangleFill, kProscribedUndocumentedSystemUseOnly },
{ sysTrapDayHandleEvent, kProscribedUndocumentedSystemUseOnly },
{ sysTrapDbgControl, kProscribedUndocumentedSystemUseOnly },
{ sysTrapDbgSerDrvClose, kProscribedUndocumentedSystemUseOnly },
{ sysTrapDbgSerDrvControl, kProscribedUndocumentedSystemUseOnly },
{ sysTrapDbgSerDrvOpen, kProscribedUndocumentedSystemUseOnly },
{ sysTrapDbgSerDrvReadChar, kProscribedUndocumentedSystemUseOnly },
{ sysTrapDbgSerDrvStatus, kProscribedUndocumentedSystemUseOnly },
{ sysTrapDbgSerDrvWriteChar, kProscribedUndocumentedSystemUseOnly },
{ sysTrapFlashInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapFntPrvGetFontList, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrBacklightV33, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrBattery, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrBatteryLevel, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrCalcDynamicHeapSize, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrCursorV33, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrCustom, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDebuggerEnter, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDebuggerExit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDebugSelect, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDisplayDoze, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDisplayDrawBootScreen, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDisplayInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDisplayPalette, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDisplaySleep, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDisplayWake, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDockSignals, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrDockStatus, kProscribedUndocumentedSystemUseOnly }, //* supported
{ sysTrapHwrDoze, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrFlashWrite, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrGetRAMMapping, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrGetSilkscreenID, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrIdentifyFeatures, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrInterruptsInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrIRQ1Handler, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrIRQ2Handler, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrIRQ3Handler, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrIRQ4Handler, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrIRQ5Handler, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrIRQ6Handler, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrLCDBaseAddrV33, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrLCDContrastV33, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrLCDGetDepthV33, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrModelInitStage2, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrModelInitStage3, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrModelSpecificInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrNVPrefGet, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrNVPrefSet, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrPluggedIn, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrPostDebugInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrPreDebugInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrResetNMI, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrResetPWM, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrSetCPUDutyCycle, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrSetSystemClock, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrSleep, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrSoundOff, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrSoundOn, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrTimerInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapHwrWake, kProscribedUndocumentedSystemUseOnly },
{ sysTrapKeyBootKeys, kProscribedUndocumentedSystemUseOnly },
{ sysTrapKeyHandleInterrupt, kProscribedUndocumentedSystemUseOnly },
{ sysTrapKeyInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapMemHeapPtr, kProscribedUndocumentedSystemUseOnly }, //* supported (PalmDebugger)
{ sysTrapMemStoreSearch, kProscribedUndocumentedSystemUseOnly },
// { sysTrapOEMDispatch2, kProscribedUndocumentedSystemUseOnly },
{ sysTrapPalmPrivate3, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrCompress, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrDecompress, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrGetColortable, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrGetGrayPat, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrPalette, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrScreenInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrScreenLock, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrScreenUnlock, kProscribedUndocumentedSystemUseOnly },
{ sysTrapScrUpdateScreenBitmap, kProscribedUndocumentedSystemUseOnly },
{ sysTrapSndInterruptSmfIrregardless, kProscribedUndocumentedSystemUseOnly },
{ sysTrapSndPlaySmfIrregardless, kProscribedUndocumentedSystemUseOnly },
{ sysTrapSndPlaySmfResourceIrregardless, kProscribedUndocumentedSystemUseOnly },
{ sysTrapSysFatalAlertInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapSysKernelClockTick, kProscribedUndocumentedSystemUseOnly },
{ sysTrapSysNotifyBroadcastFromInterrupt, kProscribedUndocumentedSystemUseOnly },
{ sysTrapSysNotifyInit, kProscribedUndocumentedSystemUseOnly },
// { sysTrapSysReserved30Trap1, kProscribedUndocumentedSystemUseOnly },
// { sysTrapSysReserved30Trap2, kProscribedUndocumentedSystemUseOnly },
{ sysTrapSysUnimplemented, kProscribedUndocumentedSystemUseOnly },
{ sysTrapTimGetAlarm, kProscribedUndocumentedSystemUseOnly },
{ sysTrapTimSetAlarm, kProscribedUndocumentedSystemUseOnly },
{ sysTrapUIColorInit, kProscribedUndocumentedSystemUseOnly },
{ sysTrapWinGetFirstWindow, kProscribedUndocumentedSystemUseOnly },
{ sysTrapWinMoveWindowAddr, kProscribedUndocumentedSystemUseOnly },
{ sysTrapWinPrvInitCanvas, kProscribedUndocumentedSystemUseOnly },
{ sysTrapWinScreenInit, kProscribedUndocumentedSystemUseOnly },
/*
6.1.3 Kernel Traps
These traps are not implemented because 68K applications do not have
access to the kernel APIs.
*/
{ sysTrapSysEvGroupCreate, kProscribedKernelUseOnly },
{ sysTrapSysEvGroupRead, kProscribedKernelUseOnly },
{ sysTrapSysEvGroupSignal, kProscribedKernelUseOnly },
{ sysTrapSysEvGroupWait, kProscribedKernelUseOnly },
{ sysTrapSysKernelInfo, kProscribedKernelUseOnly },
{ sysTrapSysMailboxCreate, kProscribedKernelUseOnly },
{ sysTrapSysMailboxDelete, kProscribedKernelUseOnly },
{ sysTrapSysMailboxFlush, kProscribedKernelUseOnly },
{ sysTrapSysMailboxSend, kProscribedKernelUseOnly },
{ sysTrapSysMailboxWait, kProscribedKernelUseOnly },
{ sysTrapSysResSemaphoreCreate, kProscribedKernelUseOnly },
{ sysTrapSysResSemaphoreDelete, kProscribedKernelUseOnly },
{ sysTrapSysResSemaphoreRelease, kProscribedKernelUseOnly },
{ sysTrapSysResSemaphoreReserve, kProscribedKernelUseOnly },
{ sysTrapSysSemaphoreCreate, kProscribedKernelUseOnly },
{ sysTrapSysSemaphoreDelete, kProscribedKernelUseOnly },
{ sysTrapSysSemaphoreSignal, kProscribedKernelUseOnly },
{ sysTrapSysSemaphoreWait, kProscribedKernelUseOnly },
{ sysTrapSysTaskCreate, kProscribedKernelUseOnly },
{ sysTrapSysTaskDelete, kProscribedKernelUseOnly },
{ sysTrapSysTaskID, kProscribedKernelUseOnly },
{ sysTrapSysTaskResume, kProscribedKernelUseOnly },
{ sysTrapSysTaskSetTermProc, kProscribedKernelUseOnly },
{ sysTrapSysTaskSuspend, kProscribedKernelUseOnly },
{ sysTrapSysTaskSwitching, kProscribedKernelUseOnly },
{ sysTrapSysTaskTrigger, kProscribedKernelUseOnly },
{ sysTrapSysTaskUserInfoPtr, kProscribedKernelUseOnly },
{ sysTrapSysTaskWait, kProscribedKernelUseOnly },
{ sysTrapSysTaskWaitClr, kProscribedKernelUseOnly },
{ sysTrapSysTaskWake, kProscribedKernelUseOnly },
{ sysTrapSysTimerCreate, kProscribedKernelUseOnly },
{ sysTrapSysTimerDelete, kProscribedKernelUseOnly },
{ sysTrapSysTimerRead, kProscribedKernelUseOnly },
{ sysTrapSysTimerWrite, kProscribedKernelUseOnly },
{ sysTrapSysTranslateKernelErr, kProscribedKernelUseOnly },
/*
6.1.4 Obsolete Traps
These traps are not implemented because they are obsolete Palm OS
1.0 traps (or an esoteric obsolete trap such as WiCmdV32).
*/
{ sysTrapFplAdd, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplAToF, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplBase10Info, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplDiv, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplFloatToLong, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplFloatToULong, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplFToA, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplLongToFloat, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplMul, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapFplSub, kProscribedObsolete }, //* supported (release ROM only)
{ sysTrapWiCmdV32, kProscribedObsolete },
/*
6.1.5 Ghost Traps
These traps were never implemented in Palm OS (although they appear
in CoreTraps.h), but they are listed for completeness. One of the
traps in this group, MenuEraseMenu, was implemented but should be
unknown to developers, as it does not appear in any public header file.
*/
{ sysTrapClipboardCheckIfItemExist, kProscribedGhost },
{ sysTrapCtlValidatePointer, kProscribedGhost },
{ sysTrapFrmSetCategoryTrigger, kProscribedGhost },
{ sysTrapFrmSetLabel, kProscribedGhost },
{ sysTrapMenuEraseMenu, kProscribedGhost },
{ sysTrapSysUICleanup, kProscribedGhost },
{ sysTrapWinDrawArc, kProscribedGhost },
{ sysTrapWinDrawPolygon, kProscribedGhost },
{ sysTrapWinEraseArc, kProscribedGhost },
{ sysTrapWinErasePolygon, kProscribedGhost },
{ sysTrapWinFillArc, kProscribedGhost },
{ sysTrapWinFillPolygon, kProscribedGhost },
{ sysTrapWinInvertArc, kProscribedGhost },
{ sysTrapWinInvertPolygon, kProscribedGhost },
{ sysTrapWinPaintArc, kProscribedGhost },
{ sysTrapWinPaintPolygon, kProscribedGhost },
/*
6.1.6 Unimplemented NOP Traps
These traps should not be called by applications. Some third-party
applications call these traps and it is safer to treat them as NOPs
for backwards compatibility.
*/
{ sysTrapFplFree, kProscribedSystemUseOnlyAnyway }, //* supported (release ROM only)
{ sysTrapFplInit, kProscribedSystemUseOnlyAnyway }, //* supported (release ROM only)
{ sysTrapHwrTimerSleep, kProscribedSystemUseOnlyAnyway },
{ sysTrapHwrTimerWake, kProscribedSystemUseOnlyAnyway },
{ sysTrapPenSleep, kProscribedSystemUseOnlyAnyway },
{ sysTrapPenWake, kProscribedSystemUseOnlyAnyway },
{ sysTrapSerReceiveISP, kProscribedSystemUseOnlyAnyway },
// { sysTrapSrmSleep, kProscribedSystemUseOnlyAnyway }, // sysTrapSerialDispatch
// { sysTrapSrmWake, kProscribedSystemUseOnlyAnyway }, // sysTrapSerialDispatch
{ sysTrapSysDisableInts, kProscribedSystemUseOnlyAnyway },
{ sysTrapSysRestoreStatus, kProscribedSystemUseOnlyAnyway },
{ sysTrapTimHandleInterrupt, kProscribedSystemUseOnlyAnyway },
{ sysTrapTimSleep, kProscribedSystemUseOnlyAnyway },
{ sysTrapTimWake, kProscribedSystemUseOnlyAnyway },
{ sysTrapWinDisableWindow, kProscribedSystemUseOnlyAnyway },
{ sysTrapWinEnableWindow, kProscribedSystemUseOnlyAnyway },
{ sysTrapWinInitializeWindow, kProscribedSystemUseOnlyAnyway },
/*
6.1.7 Unimplemented Rare Traps
These traps all seem like traps that are only used internally by
Palm OS or by serial drivers or by OEM extensions, etc. In other
words, these are traps that an application would not use.
*/
{ sysTrapConGetS, kProscribedRare },
{ sysTrapConPutS, kProscribedRare },
{ sysTrapDayDrawDays, kProscribedRare },
{ sysTrapDayDrawDaySelector, kProscribedRare },
{ sysTrapDbgCommSettings, kProscribedRare },
{ sysTrapDbgGetMessage, kProscribedRare },
// { sysTrapDlkControl, kProscribedRare }, //* supports sysAppLaunchCmdHandleSyncCallApp
{ sysTrapDlkDispatchRequest, kProscribedRare }, //* sort of, returns dlkErrNoSession err
{ sysTrapDlkStartServer, kProscribedRare }, //* sort of, returns dlkErrNoSession err
{ sysTrapDmMoveOpenDBContext, kProscribedRare },
{ sysTrapDmOpenDBWithLocale, kProscribedRare },
{ sysTrapFlashCompress, kProscribedRare },
{ sysTrapFlashErase, kProscribedRare },
{ sysTrapFlashProgram, kProscribedRare },
{ sysTrapMemGetRomNVParams, kProscribedRare },
{ sysTrapMemNVParams, kProscribedRare },
{ sysTrapResLoadForm, kProscribedRare },
{ sysTrapSlkSetSocketListener, kProscribedRare },
{ sysTrapSysNotifyDatabaseAdded, kProscribedRare },
{ sysTrapSysNotifyDatabaseRemoved, kProscribedRare },
{ sysTrapSysSetTrapAddress, kProscribedRare }
};
static Bool gProscribedTrapInitialized;
static Bool gProscribedTrap[sysNumTraps];
Bool ProscribedFunction (const SystemCallContext& context)
{
// Build up our table that allows this function to operate quickly.
// We turn a table of the system function dispatch numbers we want
// to warn about into a sparse array of booleans, where the index
// into the table is the trap index number, and each entry says
// whether or not to warn about the call.
if (!gProscribedTrapInitialized)
{
gProscribedTrapInitialized = true;
for (size_t ii = 0; ii < countof (kProscribedFunctionTrapWords); ++ii)
{
gProscribedTrap[::SysTrapIndex (kProscribedFunctionTrapWords[ii].fTrapWord)] = true;
}
}
// Handle system functions (as opposed to library functions).
if (::IsSystemTrap (context.fTrapWord))
{
// If this trap number is not on our list, let it pass.
if (gProscribedTrap[context.fTrapIndex])
return true;
// Some system functions are sub-dispatched with a sub-dispatch
// number in register D2. We can find this number in context.fExtra.
// Look at the combination to see if they represent proscribed
// functions.
if (context.fTrapWord == sysTrapSerialDispatch)
{
if (context.fExtra == sysSerialSleep ||
context.fExtra == sysSerialWake)
{
return true;
}
}
}
// Looks like an OK function, so don't warn.
return false;
}
int GetProscribedReason (const SystemCallContext& context)
{
// Handle system functions (as opposed to library functions).
if (::IsSystemTrap (context.fTrapWord))
{
// If this trap number is on our list, return the reason.
for (size_t ii = 0; ii < countof (kProscribedFunctionTrapWords); ++ii)
{
if (kProscribedFunctionTrapWords[ii].fTrapWord == context.fTrapWord)
{
return kProscribedFunctionTrapWords[ii].fReason;
}
}
// Some system functions are sub-dispatched with a sub-dispatch
// number in register D2. We can find this number in context.fExtra.
// Look at the combination to see if they represent proscribed
// functions.
if (context.fTrapWord == sysTrapSerialDispatch)
{
if (context.fExtra == sysSerialSleep ||
context.fExtra == sysSerialWake)
{
return kProscribedSystemUseOnlyAnyway;
}
}
}
EmAssert (false);
return 0;
}
/***********************************************************************
*
* FUNCTION: GetFunctionAddress
*
* DESCRIPTION: Determines the address of a system function,
*
* PARAMETERS: trapWord - the dispatch number used to invoke the
* function(the number after the TRAP $F opocde)
*
* extra - an optional extra parameter. This parameter can
* be something like a library reference number, or a
* register to be used in a sub-dispatcher.
*
* digDeep - a boolean saying how hard we should look for
* the function address. If false, we just return the
* address generated by the ROM TrapDispatcher
* function. Otherwise, for certain special ROM
* routines (like the Floating Point Manager entry
* point), we look deeper.
*
* RETURNED: The function's address, or EmMemNULL if it could not
* be determined.
*
***********************************************************************/
emuptr GetFunctionAddress (uint16 trapWord, uint32 extra, Bool digDeep)
{
// Ensure that it's in canonical format.
trapWord = ::SysTrapIndex (trapWord) | sysTrapBase;
// If it's a regular system function (0xA000-0xA7FFF), handle it.
if (::IsSystemTrap (trapWord))
return ::GetSysFunctionAddress (trapWord, extra, digDeep);
// Assume it's a library function call.
return ::GetLibFunctionAddress (trapWord, (UInt16) extra, digDeep);
}
/***********************************************************************
*
* FUNCTION: GetLibFunctionAddress
*
* DESCRIPTION: Determines the address of a library function,
*
* PARAMETERS: trapWord - the dispatch number used to invoke the
* function(the number after the TRAP $F opocde)
*
* extra - an optional extra parameter. This parameter can
* be something like a library reference number, or a
* register to be used in a sub-dispatcher.
*
* digDeep - a boolean saying how hard we should look for
* the function address. If false, we just return the
* address generated by the ROM TrapDispatcher
* function. Otherwise, for certain special ROM
* routines (like the Floating Point Manager entry
* point), we look deeper.
*
* RETURNED: The function's address, or EmMemNULL if it could not
* be determined.
*
***********************************************************************/
emuptr GetLibFunctionAddress (uint16 trapWord, UInt16 refNum, Bool digDeep)
{
if (refNum == sysInvalidRefNum || refNum == 0)
throw EmInvalidRefNumException (0);
CEnableFullAccess munge; // Remove blocks on memory access.
/*
The System Library Table (sysLibTableP) is an array of
sysLibTableEntries entries. Each entry has the following
format:
Ptr* dispatchTblP; // pointer to library dispatch table
void* globalsP; // Library globals
LocalID dbID; // database id of the library
VoidPtr codeRscH; // library code resource handle for RAM-based libraries
The latter two fields are present only in Palm OS 2.0 and
later. So our first steps are to (a) get the pointer to
the array, (b) make sure that the index into the array (the
refNum passed as the first parameter to all library calls)
is within range, (c) get a pointer to the right entry,
taking into account the Palm OS version, and (d) getting the
dispatchTblP field.
The "library dispatch table" is an array of 16-bit offsets. The
values are all relative to the beginning of the table (dispatchTblP).
The first entry in the array corresponds to the library name. All
subsequent entries are offsets to the various library functions,
starting with the required four: sysLibTrapOpen, sysLibTrapClose,
sysLibTrapSleep, and sysLibTrapWake.
*/
uint32 sysLibTableP = EmLowMem_GetGlobal (sysLibTableP);
UInt16 sysLibTableEntries = EmLowMem_GetGlobal (sysLibTableEntries);
if (sysLibTableP == EmMemNULL)
{
// !!! No library table!
EmAssert (false);
return EmMemNULL;
}
if (refNum >= sysLibTableEntries)
{
// See comments in HtalLibHeadpatch::HtalLibSendReply.
if (refNum == kMagicRefNum)
{
return 1;
}
// RefNum out of range.
throw EmInvalidRefNumException (0, sysLibTableEntries);
}
emuptr libEntry;
emuptr dispatchTblP;
if (EmPatchState::OSMajorVersion () > 1)
{
libEntry = sysLibTableP + refNum * sizeof (SysLibTblEntryType);
dispatchTblP = EmMemGet32 (libEntry + offsetof (SysLibTblEntryType, dispatchTblP));
}
else
{
libEntry = sysLibTableP + refNum * sizeof (SysLibTblEntryTypeV10);
dispatchTblP = EmMemGet32 (libEntry + offsetof (SysLibTblEntryTypeV10, dispatchTblP));
}
// Validate the dispatch number. See if the library is one that
// we know about. If so, compare the dispatch number against
// the list of known dispatch number limits.
// The first entry in the table is always the offset from the
// start of the table to the library name. Use this information
// get the library name.
int16 offset = EmMemGet16 (dispatchTblP + ::LibTrapIndex (sysLibTrapName) * 2);
emuptr libNameP = dispatchTblP + offset;
char libName[256];
EmMem_strcpy (libName, libNameP);
// Iterate over our list of Palm OS-supplied libraries to see
// if this is one of them. If so, the library is known to follow
// a format that allows us to determine the size of the table.
const char** knownLibNameP = gPalmOSLibraries;
while (*knownLibNameP)
{
if (strcmp (*knownLibNameP, libName) != 0)
{
knownLibNameP++;
continue;
}
// OK, it's one of our libraries. Now get the *second*
// entry in the table. This is the offset from the start
// of the table to the entry point for the standard
// "library open" function. All Palm OS libraries follow
// the convention where this offset points to a JMP
// instruction immediately following the function table.
// We can use this information to calculate the size of
// the table.
offset = EmMemGet16 (dispatchTblP + LibTrapIndex (sysLibTrapOpen) * 2);
if (::LibTrapIndex (trapWord) < (offset / 2))
{
// It's a known library, and the offset is in range,
// so break out of here so that we can get one with
// actually calling the function.
break;
}
// It's a known library, but the offset is out of range,
// so report a problem.
throw EmUnimplementedFunctionException (knownLibNameP - gPalmOSLibraries);
}
// Either we didn't know about that library, or we did and the
// version test passed. So go ahead and jump.
offset = EmMemGet16 (dispatchTblP + LibTrapIndex (trapWord) * 2);
emuptr result = dispatchTblP + offset;
if (digDeep && EmMemGet16 (result) == kOpcode_JMPREL)
{
result += 2;
result += (int16) EmMemGet16 (result);
}
return result;
}
/***********************************************************************
*
* FUNCTION: GetSysFunctionAddress
*
* DESCRIPTION: Determines the address of a non-library function,
*
* PARAMETERS: trapWord - the dispatch number used to invoke the
* function(the number after the TRAP $F opocde)
*
* extra - an optional extra parameter. This parameter can
* be something like a library reference number, or a
* register to be used in a sub-dispatcher.
*
* digDeep - a boolean saying how hard we should look for
* the function address. If false, we just return the
* address generated by the ROM TrapDispatcher
* function. Otherwise, for certain special ROM
* routines (like the Floating Point Manager entry
* point), we look deeper.
*
* RETURNED: The function's address, or EmMemNULL if it could not
* be determined.
*
***********************************************************************/
emuptr GetSysFunctionAddress (uint16 trapWord, uint32 extra, Bool digDeep)
{
emuptr unimplementedAddress = EmLowMem::GetTrapAddress (sysTrapSysUnimplemented);
emuptr result = EmLowMem::GetTrapAddress (trapWord);
if (result == EmMemNULL ||
((result == unimplementedAddress) && (trapWord != sysTrapSysUnimplemented)))
{
// sysTrapHostControl is always implemented, so make sure we
// don't return a NULL address.
if (::SysTrapIndex (trapWord) == ::SysTrapIndex (sysTrapHostControl))
{
return 0x12345678;
}
throw EmUnimplementedFunctionException ();
}
if (digDeep)
{
emuptr result2 = EmMemNULL;
if (trapWord == sysTrapIntlDispatch)
{
result2 = ::GetIntlDispatchAddress (result, extra);
}
else if (
trapWord == sysTrapOmDispatch ||
trapWord == sysTrapTsmDispatch ||
trapWord == sysTrapFlpDispatch ||
trapWord == sysTrapSerialDispatch)
{
result2 = ::GetStdDispatchAddress (result, extra);
}
else if (trapWord == sysTrapFlpEmDispatch)
{
result2 = ::GetFlpEmDispatchAddress (result, extra);
}
if (result2)
result = result2;
}
if (!result)
throw EmUnimplementedFunctionException ();
return result;
}
/***********************************************************************
*
* FUNCTION: GetStdDispatchAddress
*
* DESCRIPTION: Determine the address of a function that is reached
* via a sub-dispatcher.
*
* PARAMETERS: entryPt - the entry point of the sub-dispatch function.
*
* regD2 - sub-dispatch selector.
*
* RETURNED: The function's address, or EmMemNULL if it could not
* be determined.
*
***********************************************************************/
emuptr GetStdDispatchAddress (emuptr entryPt, uint32 regD2)
{
CEnableFullAccess munge; // Remove blocks on memory access.
/*
The standard dispatch routine code looks like this...
+$0000 10D5D7FE *CMP.W #$0018,D2 | B47C 0018
+$0004 10D5D802 BHI.S @error | 626C
+$0006 10D5D804 ADD.W D2,D2 | D442
+$0008 10D5D806 ADD.W D2,D2 | D442
+$000A 10D5D808 JMP *+$0004(D2.W) | 4EFB 2002
+$000E 10D5D80C JMP function1 | 4EFA F732
+$0012 10D5D810 JMP function2 | 4EFA 0AB8
...
*/
// check for expected opcodes
if (EmMemGet16 (entryPt + 0x00) != kOpcode_CMPW ||
EmMemGet16 (entryPt + 0x06) != kOpcode_ADDW ||
EmMemGet16 (entryPt + 0x08) != kOpcode_ADDW ||
EmMemGet32 (entryPt + 0x0A) != kOpcode_JMPPC)
{
return EmMemNULL;
}
// load the max selector value, and compare to D2.W
uint16 maxSelector = EmMemGet16 (entryPt + 2);
if ((regD2 & 0x0000FFFF) > maxSelector)
{
return EmMemNULL;
}
// point to appropriate JMP xxx instruction.
emuptr result = entryPt + 14 + (regD2 * 4);
if (EmMemGet16 (result) != kOpcode_JMPREL)
{
return EmMemNULL;
}
result += 2;
result += (int16) EmMemGet16 (result);
return result;
}
/***********************************************************************
*
* FUNCTION: GetFlpEmDispatchAddress
*
* DESCRIPTION: Determine the address of a function that is reached
* via a sub-dispatcher.
*
* PARAMETERS: entryPt - the entry point of the sub-dispatch function.
*
* regD2 - sub-dispatch selector.
*
* RETURNED: The function's address, or EmMemNULL if it could not
* be determined.
*
***********************************************************************/
emuptr GetFlpEmDispatchAddress (emuptr entryPt, uint32 regD2)
{
CEnableFullAccess munge; // Remove blocks on memory access.
/*
The FlpEm dispatch routine code looks like this...
+$0000 10D5D804 ADD.W D2,D2 | D442
+$0002 10D5D806 ADD.W D2,D2 | D442
+$0004 10D5D808 JMP *+$0004(D2.W) | 4EFB 2002
+$0008 10D5D80C JMP _fp_round | 4EFA F732
+$000A 10D5D810 JMP _fp_get_fpscr | 4EFA 0AB8
...
*/
// check for expected opcodes
if (EmMemGet16 (entryPt + 0x00) != kOpcode_ADDW ||
EmMemGet16 (entryPt + 0x02) != kOpcode_ADDW ||
EmMemGet32 (entryPt + 0x04) != kOpcode_JMPPC)
{
return EmMemNULL;
}
// point to appropriate JMP xxx instruction.
emuptr result = entryPt + 8 + (regD2 * 4);
if (EmMemGet16 (result) != kOpcode_JMPREL)
{
return EmMemNULL;
}
result += 2;
result += (int16) EmMemGet16 (result);
return result;
}
/***********************************************************************
*
* FUNCTION: GetIntlDispatchAddress
*
* DESCRIPTION: Determine the address of an IntlDispatch function that
* is reached via a sub-dispatcher.
*
* PARAMETERS: entryPt - the entry point of the sub-dispatch function.
*
* regD2 - sub-dispatch selector.
*
* RETURNED: The function's address, or EmMemNULL if it could not
* be determined.
*
***********************************************************************/
emuptr GetIntlDispatchAddress (emuptr entryPt, uint32 regD2)
{
CEnableFullAccess munge; // Remove blocks on memory access.
/*
The original IntlDispatch routine code looks like this...
+$0000 10D5D7FE *CMP.W #$0018,D2 | B47C 0018
+$0004 10D5D802 BHI.S @error | 626C
+$0006 10D5D804 ADD.W D2,D2 | D442
+$0008 10D5D806 ADD.W D2,D2 | D442
+$000A 10D5D808 JMP *+$0004(D2.W) | 4EFB 2002
+$000E 10D5D80C JMP IntlInit | 4EFA F732
+$0012 10D5D810 JMP TxtByteAttr | 4EFA 0AB8
...
In 4.0, the IntlDispatch routine code looks like this...
+$0000 10C1AE18 CMP.W #$001B,D2 | B47C 001B
+$0004 10C1AE1C BHI.S @error | 6212
+$0006 10C1AE1E ADD.W D2,D2 | D442
+$0008 10C1AE20 ADD.W D2,D2 | D442
+$000A 10C1AE22 MOVE.L $00000350,D0 | 2038 0350
+$000E 10C1AE26 BEQ.S @standard | 670E
+$0010 10C1AE28 MOVE.L D0,A0 | 2040
+$0012 10C1AE2A MOVE.L $00(A0,D2.W),A0 | 2070 2000
+$0016 10C1AE2E JMP (A0) | 4ED0
@error:
+$0018 10C1AE30 MOVE.W D2,-(A7) | 3F02
+$001A 10C1AE32 JMP selectorError | 4EFA 0086
@standard:
+$001E 10C1AE36 JMP *+$0004(D2.W) | 4EFB 2002
+$0022 10C1AE3A JMP IntlInit | 4EFA 0260
+$0022 10C1AE3E JMP TxtByteAttr | 4EFA EB60
...
*/
// check for expected opcodes
Bool newDispatch;
if (EmMemGet16 (entryPt + 0x00) != kOpcode_CMPW ||
EmMemGet16 (entryPt + 0x06) != kOpcode_ADDW ||
EmMemGet16 (entryPt + 0x08) != kOpcode_ADDW)
{
return EmMemNULL;
}
if (EmMemGet16 (entryPt + 0x0A) == kOpcode_JMPPC)
{
newDispatch = false;
}
else if (EmMemGet16 (entryPt + 0x0A) == kOpcode_MOVEL)
{
newDispatch = true;
}
else
{
return EmMemNULL;
}
// load the max selector value, and compare to D2.W
uint16 maxSelector = EmMemGet16 (entryPt + 2);
if ((regD2 & 0x0000FFFF) > maxSelector)
{
return EmMemNULL;
}
emuptr result;
if (newDispatch)
{
// figure out if low memory pointer exists.
emuptr lowMemPtr = EmMemGet16 (entryPt + 0x0C);
result = EmMemGet32 (lowMemPtr);
if (result == EmMemNULL)
{
newDispatch = false;
// point to start of dispatch table.
result = entryPt + 34;
}
}
else
{
// point to start of dispatch table.
result = entryPt + 14;
}
if (newDispatch)
{
// result points to table of routine addresses.
result = EmMemGet32 (result + (regD2 * 4));
}
else
{
// point to appropriate JMP xxx instruction.
result += (regD2 * 4);
if (EmMemGet16 (result) != kOpcode_JMPREL)
{
return EmMemNULL;
}
result += 2;
result += (int16) EmMemGet16 (result);
}
return result;
}
/***********************************************************************
*
* FUNCTION: GetTrapName
*
* DESCRIPTION: Returns a pointer to a string appropriate for
* identifying a function. If the function has a Macsbug
* name, that name is returned. If the function is a
* known Palm OS function, that name is looked up in a
* string resource list. Otherwise, a default "unknown"
* string is returned.
*
* PARAMETERS: context - structure describing the function.
*
* trapWord - the dispatch number used to invoke the
* function(the number after the TRAP $F opocde).
*
* extra - an optional extra parameter. This parameter can
* be something like a library reference number, or a
* register to be used in a sub-dispatcher.
*
* digDeep - a boolean saying how hard we should look for
* the function address. If false, we just return the
* address generated by the ROM TrapDispatcher
* function. Otherwise, for certain special ROM
* routines (like the Floating Point Manager entry
* point), we look deeper.
*
* RETURNED: nothing
*
***********************************************************************/
char* GetTrapName (const SystemCallContext& context, Bool digDeep)
{
return ::GetTrapName (context.fTrapWord, context.fExtra, digDeep);
}
char* GetTrapName (uint16 trapWord, uint32 extra, Bool digDeep)
{
static char name[sysPktMaxNameLen];
try
{
name[0] = 0;
::FindTrapName (trapWord, name, extra, digDeep);
}
catch (...)
{
}
if (strlen (name) == 0)
{
strcpy (name, ">>> Unknown function name <<<");
if (::IsSystemTrap (trapWord))
{
string knownName = Platform::GetString (kStr_SysTrapBase + SysTrapIndex (trapWord));
if (knownName[0] != '<')
{
strcpy (name, knownName.c_str ());
}
}
}
return name;
}
/***********************************************************************
*
* FUNCTION: FindTrapName
*
* DESCRIPTION: Finds the Macsbug name for the given function. If the
* name cannot be found, an empty string is returned.
*
* PARAMETERS: trapWord - the dispatch number used to invoke the
* function(the number after the TRAP $F opocde)
*
* nameP - buffer to receive the function name.
*
* extra - an optional extra parameter. This parameter can
* be something like a library reference number, or a
* register to be used in a sub-dispatcher.
*
* digDeep - a boolean saying how hard we should look for
* the function address. If false, we just return the
* address generated by the ROM TrapDispatcher
* function. Otherwise, for certain special ROM
* routines (like the Floating Point Manager entry
* point), we look deeper.
*
* RETURNED: nothing
*
***********************************************************************/
void FindTrapName (uint16 trapWord, char* nameP, uint32 extra, Bool digDeep)
{
emuptr addr = ::GetFunctionAddress (trapWord, extra, digDeep);
if (addr)
::FindFunctionName (addr, nameP);
else
nameP[0] = '\0';
}
/***********************************************************************
*
* FUNCTION: FindFunctionName
*
* DESCRIPTION: Returns information about the function containing the
* the given memory address, including the function's
* start (the LINK instruction, usually), the function's
* end (just after the RTS, usually), and the function's
* name (that follows the function).
*
* PARAMETERS: addr - address contained within the function.
*
* nameP - storage for the returned function name. Must
* be at least 32 characters.
*
* startAddrP - storage for the returned function start.
*
* endAddrP - storage for the returned function end.
*
* nameCapacity - bytes of storage available at nameP
*
* RETURNED: nothing
*
***********************************************************************/
// Llamagraphics, Inc: Added nameCapacity argument so that callers
// can retrieve more than 31 character function names. The default
// capacity is 32, so callers that don't provide the extra argument
// will get the same result as before.
void FindFunctionName (emuptr addr, char* nameP,
emuptr* startAddrP, emuptr* endAddrP,
long nameCapacity)
{
// Get the start address only if requested.
if (startAddrP)
*startAddrP = ::FindFunctionStart (addr);
// Get the end address if requested or if we need it to
// get the Macsbug name.
if (nameP || endAddrP)
{
emuptr endAddr = ::FindFunctionEnd (addr);
// Return the end address if requested.
if (endAddrP)
*endAddrP = endAddr;
// Return the Macsbug name if requested.
if (nameP)
{
if (endAddr)
::GetMacsbugInfo (endAddr, nameP, nameCapacity, NULL);
else
nameP[0] = '\0';
}
}
}
/***********************************************************************
*
* FUNCTION: FindFunctionStart
*
* DESCRIPTION: Find the start of the function containing the given
* address. The start of the function is determined
* by looking backwards for the end of the previous
* function and then scooting forward to the beginning
* of this function.
*
* PARAMETERS: addr - the probe address.
*
* RETURNED: Start of the function. EmMemNULL if not found.
*
***********************************************************************/
emuptr FindFunctionStart (emuptr addr)
{
emuptr beginAddr = addr - 0x02000; // Set a default value.
// Try finding the distance from the given address to the beginning
// of the chunk it's in, and use that as maxLength.
const EmPalmHeap* heap = EmPalmHeap::GetHeapByPtr (addr);
if (heap)
{
const EmPalmChunk* chunk = heap->GetChunkContaining (addr);
if (chunk)
{
beginAddr = chunk->BodyStart ();
}
}
while ((addr -= 2) >= beginAddr)
{
// Make sure the address is valid.
if (!EmMemCheckAddress (addr, 2))
{
return EmMemNULL;
}
if (::EndOfFunctionSequence (addr))
{
addr += 2; // skip past the final RTS (or whatever).
// Skip over the Macsbug name (and any constant data).
::GetMacsbugInfo (addr, NULL, 0, &addr);
return addr;
}
}
// !!! TBD: if we got here, it's because we couldn't find the
// EOF sequence of a previous function. That might be because
// the function we're probing is the first in the chunk. In
// that case, return chunk->Start() or chunk->Start() + 2 as
// the beginning of the function. I'm not doing that now because
// I'm not sure which is right, or if there are other conditions
// to take into account.
return EmMemNULL;
}
/***********************************************************************
*
* FUNCTION: FindFunctionEnd
*
* DESCRIPTION: Find the end of the function containing the given
* address. The end of the function is determined by
* testing the given address for an end-of-function
* sequence, and then scooting forward by two bytes
* if the test fails.
*
* PARAMETERS: addr - the probe address.
*
* RETURNED: End of the function. EmMemNULL if not found.
*
***********************************************************************/
emuptr FindFunctionEnd (emuptr addr)
{
emuptr endAddr = addr + 0x02000; // Set a default value.
// Try finding the distance from the given address to the end
// of the chunk it's in, and use that as maxLength.
const EmPalmHeap* heap = EmPalmHeap::GetHeapByPtr (addr);
if (heap)
{
const EmPalmChunk* chunk = heap->GetChunkContaining (addr);
if (chunk)
{
endAddr = chunk->BodyEnd ();
}
}
while (addr < endAddr)
{
// Make sure the address is valid.
if (!EmMemCheckAddress (addr, 2))
{
return EmMemNULL;
}
if (::EndOfFunctionSequence (addr))
{
return addr + 2;
}
addr += 2;
}
return EmMemNULL;
}
/***********************************************************************
*
* FUNCTION: EndOfFunctionSequence
*
* DESCRIPTION: Test the given memory location to see if it contains
* a valid-looking end of function sequence. A valid
* end of function sequence is an RTE, JMP (A0), RTD, or
* RTS (as long as it doesn't look like the sequnce
* CodeWarrior uses for 32-bit jumps).
*
* PARAMETERS: addr - memory location to test.
*
* RETURNED: True if it looks like this is an end of function
* sequence.
*
***********************************************************************/
Bool EndOfFunctionSequence (emuptr addr)
{
uint16 opcode = EmMemGet16 (addr);
// Look for the special 32-bit relative jumps which
// CodeWarrior puts in. These are of the following form:
//
// +$0022 10CD3C2A PEA *+$0010 ; 10CD3C3A | 487A 000E
// +$0026 10CD3C2E PEA *+$0006 ; 10CD3C34 | 487A 0004
// +$002A 10CD3C32 ADDI.L #$00000CD2,(A7) ; '....' | 0697 0000 0CD2
// +$0030 10CD3C38 RTS | 4E75
if (opcode == kOpcode_RTS &&
EmMemGet16 (addr - 6) != kOpcode_ADD)
{
return true;
}
if (opcode == kOpcode_RTE ||
opcode == kOpcode_JMP || // JMP (A0)
opcode == kOpcode_RTD)
{
return true;
}
return false;
}
/***********************************************************************
*
* FUNCTION: GetMacsbugInfo
*
* DESCRIPTION: Return any eof-of-function information. This includes
* the (validated) Macsbug name and the address following
* all end-of-function information (presumably the start
* of the next function).
*
* PARAMETERS: eof - pointer to the end of the function (that is, the
* byte after the eof sequence).
*
* name - pointer to buffer to receive the name.
*
* nameCapacity - size of buffer pointed to by "name".
*
* sof - receives the start of the next function.
*
* RETURNED: nothing
*
***********************************************************************/
void GetMacsbugInfo (emuptr eof, char* name, long nameCapacity, emuptr* sof)
{
uint8 length;
Bool isFixed;
emuptr namePtr;
::MacsbugNameLength (eof, &length, &isFixed, &namePtr);
// Determine the address of the following function. Start by
// determining the address past the end of the string.
if (sof)
{
*sof = namePtr + length;
if (isFixed)
{
// Assert that we're word aligned.
EmAssert ((*sof & 0x01) == 0);
}
else
{
// Make sure the address is word aligned.
*sof = (*sof + 1) & ~0x01;
// Get the size of any following constant data and add that to
// the address we return as the start of the next function.
// Make sure the address remains word aligned.
uint16 constDataSize = EmMemGet16 (*sof);
*sof = (*sof + constDataSize + 2 + 1) & ~0x01;
}
}
// Copy the string, validating it as we go. Note that we have
// to go through this loop even if "name" is NULL so that we
// can validate all of the characters.
char* dest = name;
while (length--)
{
uint8 ch = EmMemGet8 (namePtr++) & 0x7F;
// If we're dealing with fixed format and we've encountered
// a space, make sure that all remaining characters are
// also spaces.
if (isFixed && ch == ' ')
{
while (length--)
{
ch = EmMemGet8 (namePtr++) & 0x7F;
if (ch != ' ')
{
goto Error;
}
}
break;
}
if (!::ValidMacsbugChar (ch))
{
goto Error;
}
// If there's room in the output buffer, store the character.
// Do it this way (as opposed to altering "length" if it's
// larger than nameCapacity) so that we can test all characters.
if (dest && ((dest - name) < (nameCapacity - 1)))
{
*dest++ = (char) ch;
}
}
// Terminate the string.
if (dest)
*dest = 0;
return;
Error:
// All bets are off.
if (name)
*name = 0;
if (sof)
*sof = eof;
}
/***********************************************************************
*
* FUNCTION: MascsbugNameLength
*
* DESCRIPTION: Returns the length of the Macsbug symbol starting at
* the given memory location.
*
* Note that NO validation of the symbol is performed.
* That is, if there is NO symbol after the function and
* the word immediately after the end of the function is
* the first opcode of the following function, the
* result of this function is meaningless.
*
* PARAMETERS: addr - start of the Macsbug symbol. Should contain
* the symbol's length byte or bytes.
*
* length - receives the length of the Macsbug symbol.
*
* isFixed - receives a boolean indicating if this name
* is in "fixed" or "variable" format. If the former,
* the name is padded with spaces which need to be
* accounted for. If the latter, spaces are not
* allowed at all. Also, variable-length names are
* followed by a word containing the length of a
* chunk of "local data".
*
* newAddr - receives the address of the first character
* of the Macsbug name. This address is addr, addr+1,
* or addr+2, depending on the symbol format.
*
* RETURNED: The symbol length (zero on error).
*
***********************************************************************/
void MacsbugNameLength (emuptr addr, uint8* length, Bool* isFixed, emuptr* namePtr)
{
/*
The Macsbug name can be in one of three forms:
Variable length:
The first byte is in the range $80 to $9F and is a length
in the range 0 to $1F. The high order bit must be set. A
length of 0 implies the second byte is the actual length
in the range $01 thru $FF. The length byte(s) and name
may be an odd number of bytes. However, the data after
the name is word aligned.
Fixed length 8:
The first byte is in the range $20 to $7F and is an ASCII
character. The high order bit may be set but is not
required to be.
Fixed length 16:
The first byte is in the range $20 to $7F and is an ASCII
character. The high order bit may be set but is not
required to be. The high order bit in the second byte is
required to be set. This distinguishes the two types of
fixed names.
*/
*length = EmMemGet8 (addr);
// If < 0x20, there is no name.
if (*length < 0x20)
{
*length = 0;
*isFixed = true;
}
else
{
// If < 0x20 (after stripping), it is in variable-length format.
// If >= 0x20 (after stripping), it is in 8- or 16-byte fixed format.
*length &= 0x7F;
*isFixed = (*length >= 0x20);
if (*isFixed)
{
if (EmMemGet8 (addr + 1) < 0x80)
*length = 8;
else
*length = 16;
}
else
{
addr++;
if (*length == 0)
*length = EmMemGet8 (addr++);
}
}
*namePtr = addr;
}
/***********************************************************************
*
* FUNCTION: ValidMacsbugChar
*
* DESCRIPTION: Returns whether or not the given character is a
* character in a valid Macsbug symbol. Valid characters
* are: [a-zA-Z0-9_%.]
*
* PARAMETERS: ch - the character to test
*
* RETURNED: True if the character is valid.
*
***********************************************************************/
Bool ValidMacsbugChar (uint8 ch)
{
static Bool initialized = false;
static Bool validChar[128];
if (!initialized)
{
initialized = true;
memset (validChar, false, sizeof (validChar));
validChar ['_'] = true;
validChar ['%'] = true;
validChar ['.'] = true;
uint8 ii;
for (ii = 'a'; ii <= 'z'; ++ii)
validChar [ii] = true;
for (ii = 'A'; ii <= 'Z'; ++ii)
validChar [ii] = true;
for (ii = '0'; ii <= '9'; ++ii)
validChar [ii] = true;
}
EmAssert (ch < 128);
return validChar [ch];
}
/***********************************************************************
*
* FUNCTION: PrvGetShortName
*
* DESCRIPTION: Returns whether or not the given character is a
* character in a valid Macsbug symbol. Valid characters
* are: [a-zA-Z0-9_%.]
*
* PARAMETERS: ch - the character to test
*
* RETURNED: True if the character is valid.
*
***********************************************************************/
string PrvGetShortName (const char* srcName, int destLen)
{
string result (destLen, ' '); // Create space-filled string of right length.
int iDest = 0;
int iSrc = 0;
int srcLen = strlen (srcName);
while (iDest < destLen && iSrc < srcLen)
{
char c = srcName[iSrc++];
if (isalnum (c))
{
result[iDest++] = toupper (c);
}
}
return result;
}
|