parser.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /****************************************************************************
  2. * dcc project procedure list builder
  3. * (C) Cristina Cifuentes, Mike van Emmerik, Jeff Ledermann
  4. ****************************************************************************/
  5. #include <string.h>
  6. #include <stdlib.h> /* For exit() */
  7. #include <sstream>
  8. #include <stdio.h>
  9. #include <algorithm>
  10. #include "dcc.h"
  11. #include "project.h"
  12. using namespace std;
  13. extern Project g_proj;
  14. //static void FollowCtrl (Function * pProc, CALL_GRAPH * pcallGraph, STATE * pstate);
  15. static boolT process_JMP (ICODE * pIcode, STATE * pstate, CALL_GRAPH * pcallGraph);
  16. static void setBits(int16_t type, uint32_t start, uint32_t len);
  17. static void process_MOV(LLInst &ll, STATE * pstate);
  18. static SYM * lookupAddr (LLOperand *pm, STATE * pstate, int size, uint16_t duFlag);
  19. void interactDis(Function * initProc, int ic);
  20. static uint32_t SynthLab;
  21. /* Parses the program, builds the call graph, and returns the list of
  22. * procedures found */
  23. void DccFrontend::parse(Project &proj)
  24. {
  25. PROG &prog(proj.prog);
  26. STATE state;
  27. /* Set initial state */
  28. state.setState(rES, 0); /* PSP segment */
  29. state.setState(rDS, 0);
  30. state.setState(rCS, prog.initCS);
  31. state.setState(rSS, prog.initSS);
  32. state.setState(rSP, prog.initSP);
  33. state.IP = ((uint32_t)prog.initCS << 4) + prog.initIP;
  34. SynthLab = SYNTHESIZED_MIN;
  35. // default-construct a Function object !
  36. auto func = proj.createFunction();
  37. /* Check for special settings of initial state, based on idioms of the
  38. startup code */
  39. state.checkStartup();
  40. Function &start_proc(proj.pProcList.front());
  41. /* Make a struct for the initial procedure */
  42. if (prog.offMain != -1)
  43. {
  44. /* We know where main() is. Start the flow of control from there */
  45. start_proc.procEntry = prog.offMain;
  46. /* In medium and large models, the segment of main may (will?) not be
  47. the same as the initial CS segment (of the startup code) */
  48. state.setState(rCS, prog.segMain);
  49. start_proc.name = "main";
  50. state.IP = prog.offMain;
  51. }
  52. else
  53. {
  54. /* Create initial procedure at program start address */
  55. start_proc.name="start";
  56. start_proc.procEntry = (uint32_t)state.IP;
  57. }
  58. /* The state info is for the first procedure */
  59. start_proc.state = state;
  60. /* Set up call graph initial node */
  61. proj.callGraph = new CALL_GRAPH;
  62. proj.callGraph->proc = proj.pProcList.begin();
  63. /* This proc needs to be called to set things up for LibCheck(), which
  64. checks a proc to see if it is a know C (etc) library */
  65. SetupLibCheck();
  66. //ERROR: proj and g_proj are 'live' at this point !
  67. /* Recursively build entire procedure list */
  68. proj.pProcList.front().FollowCtrl (proj.callGraph, &state);
  69. /* This proc needs to be called to clean things up from SetupLibCheck() */
  70. CleanupLibCheck();
  71. }
  72. /* Returns the size of the string pointed by sym and delimited by delim.
  73. * Size includes delimiter. */
  74. int strSize (uint8_t *sym, char delim)
  75. {
  76. PROG &prog(Project::get()->prog);
  77. int till_end = sym-prog.Image;
  78. uint8_t *end_ptr=std::find(sym,sym+(prog.cbImage-(till_end)),delim);
  79. return end_ptr-sym+1;
  80. }
  81. Function *fakeproc=Function::Create(0,0,"fake");
  82. /* FollowCtrl - Given an initial procedure, state information and symbol table
  83. * builds a list of procedures reachable from the initial procedure
  84. * using a depth first search. */
  85. void Function::FollowCtrl(CALL_GRAPH * pcallGraph, STATE *pstate)
  86. {
  87. PROG &prog(Project::get()->prog);
  88. ICODE _Icode, *pIcode; /* This gets copied to pProc->Icode[] later */
  89. ICODE eIcode; /* extra icodes for iDIV, iIDIV, iXCHG */
  90. SYM * psym;
  91. uint32_t offset;
  92. eErrorId err;
  93. bool done = false;
  94. SYMTAB &global_symbol_table(g_proj.symtab);
  95. if (name.find("chkstk") != string::npos)
  96. {
  97. // Danger! Dcc will likely fall over in this code.
  98. // So we act as though we have done with this proc
  99. // pProc->flg &= ~TERMINATES; // Not sure about this
  100. done = true;
  101. // And mark it as a library function, so structure() won't choke on it
  102. flg |= PROC_ISLIB;
  103. return;
  104. }
  105. if (option.VeryVerbose)
  106. {
  107. printf("Parsing proc %s at %lX\n", name.c_str(), pstate->IP);
  108. }
  109. while (! done && ! (err = scan(pstate->IP, _Icode)))
  110. {
  111. LLInst *ll = _Icode.ll();
  112. pstate->IP += (uint32_t)ll->numBytes;
  113. setBits(BM_CODE, ll->label, (uint32_t)ll->numBytes);
  114. process_operands(_Icode,pstate);
  115. /* Keep track of interesting instruction flags in procedure */
  116. flg |= (ll->getFlag() & (NOT_HLL | FLOAT_OP));
  117. /* Check if this instruction has already been parsed */
  118. iICODE labLoc = Icode.labelSrch(ll->label);
  119. if (Icode.end()!=labLoc)
  120. { /* Synthetic jump */
  121. _Icode.type = LOW_LEVEL;
  122. ll->set(iJMP,I | SYNTHETIC | NO_OPS);
  123. ll->src.SetImmediateOp(labLoc->ll()->GetLlLabel());
  124. ll->label = SynthLab++;
  125. }
  126. /* Copy Icode to Proc */
  127. if ((_Icode.ll()->getOpcode() == iDIV) || (_Icode.ll()->getOpcode() == iIDIV))
  128. {
  129. /* MOV rTMP, reg */
  130. eIcode = ICODE();
  131. eIcode.type = LOW_LEVEL;
  132. eIcode.ll()->set(iMOV,0);
  133. eIcode.ll()->dst.regi = rTMP;
  134. if (ll->testFlags(B) )
  135. {
  136. eIcode.ll()->setFlags( B );
  137. eIcode.ll()->src.regi = rAX;
  138. eIcode.setRegDU( rAX, eUSE);
  139. }
  140. else /* implicit dx:ax */
  141. {
  142. eIcode.ll()->setFlags( IM_SRC );
  143. eIcode.setRegDU( rAX, eUSE);
  144. eIcode.setRegDU( rDX, eUSE);
  145. }
  146. eIcode.setRegDU( rTMP, eDEF);
  147. eIcode.ll()->setFlags( SYNTHETIC );
  148. /* eIcode.ll()->label = SynthLab++; */
  149. eIcode.ll()->label = _Icode.ll()->label;
  150. Icode.addIcode(&eIcode);
  151. /* iDIV, iIDIV */
  152. Icode.addIcode(&_Icode);
  153. /* iMOD */
  154. eIcode = ICODE();
  155. eIcode.type = LOW_LEVEL;
  156. eIcode.ll()->set(iMOD,0);
  157. eIcode.ll()->src = _Icode.ll()->src;
  158. eIcode.du = _Icode.du;
  159. eIcode.ll()->setFlags( ( ll->getFlag() | SYNTHETIC | IM_TMP_DST) );
  160. eIcode.ll()->label = SynthLab++;
  161. pIcode = Icode.addIcode(&eIcode);
  162. }
  163. else if (_Icode.ll()->getOpcode() == iXCHG)
  164. {
  165. /* MOV rTMP, regDst */
  166. eIcode = ICODE();
  167. eIcode.type = LOW_LEVEL;
  168. eIcode.ll()->set(iMOV,SYNTHETIC);
  169. eIcode.ll()->dst.regi = rTMP;
  170. eIcode.ll()->src = _Icode.ll()->dst;
  171. eIcode.setRegDU( rTMP, eDEF);
  172. if(eIcode.ll()->src.regi)
  173. {
  174. eIcode.setRegDU( eIcode.ll()->src.regi, eUSE);
  175. if((eIcode.ll()->src.regi>=rAL) && (eIcode.ll()->src.regi<=rBH))
  176. eIcode.ll()->setFlags( B );
  177. }
  178. eIcode.ll()->label = _Icode.ll()->label;
  179. Icode.addIcode(&eIcode);
  180. /* MOV regDst, regSrc */
  181. _Icode.ll()->set(iMOV,SYNTHETIC|_Icode.ll()->getFlag());
  182. Icode.addIcode(&_Icode);
  183. ll->setOpcode(iXCHG); /* for next case */
  184. /* MOV regSrc, rTMP */
  185. eIcode = ICODE();
  186. eIcode.type = LOW_LEVEL;
  187. eIcode.ll()->set(iMOV,SYNTHETIC);
  188. eIcode.ll()->dst = ll->src;
  189. if(eIcode.ll()->dst.regi)
  190. {
  191. if((eIcode.ll()->dst.regi>=rAL) && (eIcode.ll()->dst.regi<=rBH))
  192. eIcode.ll()->setFlags( B );
  193. eIcode.setRegDU( eIcode.ll()->dst.regi, eDEF);
  194. }
  195. eIcode.ll()->src.regi = rTMP;
  196. eIcode.setRegDU( rTMP, eUSE);
  197. eIcode.ll()->label = SynthLab++;
  198. pIcode = Icode.addIcode(&eIcode);
  199. }
  200. else
  201. pIcode = Icode.addIcode(&_Icode);
  202. switch (ll->getOpcode()) {
  203. /*** Conditional jumps ***/
  204. case iLOOP: case iLOOPE: case iLOOPNE:
  205. case iJB: case iJBE: case iJAE: case iJA:
  206. case iJL: case iJLE: case iJGE: case iJG:
  207. case iJE: case iJNE: case iJS: case iJNS:
  208. case iJO: case iJNO: case iJP: case iJNP:
  209. case iJCXZ:
  210. { STATE StCopy;
  211. int ip = Icode.size()-1; /* Index of this jump */
  212. ICODE &prev(Icode.back()); /* Previous icode */
  213. boolT fBranch = false;
  214. pstate->JCond.regi = 0;
  215. /* This sets up range check for indexed JMPs hopefully
  216. * Handles JA/JAE for fall through and JB/JBE on branch
  217. */
  218. if (ip > 0 && prev.ll()->getOpcode() == iCMP && (prev.ll()->testFlags(I)))
  219. {
  220. pstate->JCond.immed = (int16_t)prev.ll()->src.op();
  221. if (ll->match(iJA) || ll->match(iJBE) )
  222. pstate->JCond.immed++;
  223. if (ll->getOpcode() == iJAE || ll->getOpcode() == iJA)
  224. pstate->JCond.regi = prev.ll()->dst.regi;
  225. fBranch = (boolT)
  226. (ll->getOpcode() == iJB || ll->getOpcode() == iJBE);
  227. }
  228. StCopy = *pstate;
  229. //memcpy(&StCopy, pstate, sizeof(STATE));
  230. /* Straight line code */
  231. this->FollowCtrl (pcallGraph, &StCopy); // recurrent ?
  232. if (fBranch) /* Do branching code */
  233. {
  234. pstate->JCond.regi = prev.ll()->dst.regi;
  235. }
  236. /* Next icode. Note: not the same as GetLastIcode() because of the call
  237. to FollowCtrl() */
  238. pIcode = Icode.GetIcode(ip);
  239. } /* Fall through to do the jump path */
  240. /*** Jumps ***/
  241. case iJMP:
  242. case iJMPF: /* Returns true if we've run into a loop */
  243. done = process_JMP (*pIcode, pstate, pcallGraph);
  244. break;
  245. /*** Calls ***/
  246. case iCALL:
  247. case iCALLF:
  248. done = process_CALL (*pIcode, pcallGraph, pstate);
  249. pstate->kill(rBX);
  250. pstate->kill(rCX);
  251. break;
  252. /*** Returns ***/
  253. case iRET:
  254. case iRETF:
  255. this->flg |= (ll->getOpcode() == iRET)? PROC_NEAR:PROC_FAR;
  256. /* Fall through */
  257. case iIRET:
  258. this->flg &= ~TERMINATES;
  259. done = true;
  260. break;
  261. case iINT:
  262. if (ll->src.op() == 0x21 && pstate->f[rAH])
  263. {
  264. int funcNum = pstate->r[rAH];
  265. int operand;
  266. int size;
  267. /* Save function number */
  268. Icode.back().ll()->dst.off = (int16_t)funcNum;
  269. //Icode.GetIcode(Icode.GetNumIcodes() - 1)->
  270. /* Program termination: int21h, fn 00h, 31h, 4Ch */
  271. done = (boolT)(funcNum == 0x00 || funcNum == 0x31 ||
  272. funcNum == 0x4C);
  273. /* String functions: int21h, fn 09h */
  274. if (pstate->f[rDX]) /* offset goes into DX */
  275. if (funcNum == 0x09)
  276. {
  277. operand = ((uint32_t)(uint16_t)pstate->r[rDS]<<4) +
  278. (uint32_t)(uint16_t)pstate->r[rDX];
  279. size = prog.fCOM ?
  280. strSize (&prog.Image[operand], '$') :
  281. strSize (&prog.Image[operand], '$'); // + 0x100
  282. global_symbol_table.updateSymType (operand, TypeContainer(TYPE_STR, size));
  283. }
  284. }
  285. else if ((ll->src.op() == 0x2F) && (pstate->f[rAH]))
  286. {
  287. Icode.back().ll()->dst.off = pstate->r[rAH];
  288. }
  289. else /* Program termination: int20h, int27h */
  290. done = (boolT)(ll->src.op() == 0x20 ||
  291. ll->src.op() == 0x27);
  292. if (done)
  293. pIcode->ll()->setFlags(TERMINATES);
  294. break;
  295. case iMOV:
  296. process_MOV(*pIcode->ll(), pstate);
  297. break;
  298. /* case iXCHG:
  299. process_MOV (pIcode, pstate);
  300. break; **** HERE ***/
  301. case iSHL:
  302. if (pstate->JCond.regi == ll->dst.regi)
  303. if ((ll->testFlags(I)) && ll->src.op() == 1)
  304. pstate->JCond.immed *= 2;
  305. else
  306. pstate->JCond.regi = 0;
  307. break;
  308. case iLEA:
  309. if (ll->src.regi == 0) /* direct mem offset */
  310. pstate->setState( ll->dst.regi, ll->src.off);
  311. break;
  312. case iLDS: case iLES:
  313. if ((psym = lookupAddr(&ll->src, pstate, 4, eDuVal::USE))
  314. /* && (Icode.ll()->flg & SEG_IMMED) */ ) {
  315. offset = LH(&prog.Image[psym->label]);
  316. pstate->setState( (ll->getOpcode() == iLDS)? rDS: rES,
  317. LH(&prog.Image[psym->label + 2]));
  318. pstate->setState( ll->dst.regi, (int16_t)offset);
  319. psym->type = TYPE_PTR;
  320. }
  321. break;
  322. }
  323. }
  324. if (err) {
  325. this->flg &= ~TERMINATES;
  326. if (err == INVALID_386OP || err == INVALID_OPCODE)
  327. {
  328. fatalError(err, prog.Image[_Icode.ll()->label], _Icode.ll()->label);
  329. this->flg |= PROC_BADINST;
  330. }
  331. else if (err == IP_OUT_OF_RANGE)
  332. fatalError (err, _Icode.ll()->label);
  333. else
  334. reportError(err, _Icode.ll()->label);
  335. }
  336. }
  337. /* process_JMP - Handles JMPs, returns true if we should end recursion */
  338. boolT Function::process_JMP (ICODE & pIcode, STATE *pstate, CALL_GRAPH * pcallGraph)
  339. {
  340. PROG &prog(Project::get()->prog);
  341. static uint8_t i2r[4] = {rSI, rDI, rBP, rBX};
  342. ICODE _Icode;
  343. uint32_t cs, offTable, endTable;
  344. uint32_t i, k, seg, target;
  345. uint32_t tmp;
  346. if (pIcode.ll()->testFlags(I))
  347. {
  348. if (pIcode.ll()->getOpcode() == iJMPF)
  349. pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
  350. i = pstate->IP = pIcode.ll()->src.op();
  351. if ((long)i < 0)
  352. {
  353. exit(1);
  354. }
  355. /* Return true if jump target is already parsed */
  356. return Icode.labelSrch(i, tmp);
  357. }
  358. /* We've got an indirect JMP - look for switch() stmt. idiom of the form
  359. * JMP uint16_t ptr word_offset[rBX | rSI | rDI] */
  360. seg = (pIcode.ll()->src.seg)? pIcode.ll()->src.seg: rDS;
  361. /* Ensure we have a uint16_t offset & valid seg */
  362. if (pIcode.ll()->match(iJMP) and (pIcode.ll()->testFlags(WORD_OFF)) &&
  363. pstate->f[seg] &&
  364. (pIcode.ll()->src.regi == INDEX_SI ||
  365. pIcode.ll()->src.regi == INDEX_DI || /* Idx reg. BX, SI, DI */
  366. pIcode.ll()->src.regi == INDEX_BX))
  367. {
  368. offTable = ((uint32_t)(uint16_t)pstate->r[seg] << 4) + pIcode.ll()->src.off;
  369. /* Firstly look for a leading range check of the form:-
  370. * CMP {BX | SI | DI}, immed
  371. * JA | JAE | JB | JBE
  372. * This is stored in the current state as if we had just
  373. * followed a JBE branch (i.e. [reg] lies between 0 - immed).
  374. */
  375. if (pstate->JCond.regi == i2r[pIcode.ll()->src.regi-(INDEX_BX_SI+4)])
  376. endTable = offTable + pstate->JCond.immed;
  377. else
  378. endTable = (uint32_t)prog.cbImage;
  379. /* Search for first uint8_t flagged after start of table */
  380. for (i = offTable; i <= endTable; i++)
  381. if (BITMAP(i, BM_CODE | BM_DATA))
  382. break;
  383. endTable = i & ~1; /* Max. possible table size */
  384. /* Now do some heuristic pruning. Look for ptrs. into the table
  385. * and for addresses that don't appear to point to valid code.
  386. */
  387. cs = (uint32_t)(uint16_t)pstate->r[rCS] << 4;
  388. for (i = offTable; i < endTable; i += 2)
  389. {
  390. target = cs + LH(&prog.Image[i]);
  391. if (target < endTable && target >= offTable)
  392. endTable = target;
  393. else if (target >= (uint32_t)prog.cbImage)
  394. endTable = i;
  395. }
  396. for (i = offTable; i < endTable; i += 2)
  397. {
  398. target = cs + LH(&prog.Image[i]);
  399. /* Be wary of 00 00 as code - it's probably data */
  400. if (! (prog.Image[target] || prog.Image[target+1]) ||
  401. scan(target, _Icode))
  402. endTable = i;
  403. }
  404. /* Now for each entry in the table take a copy of the current
  405. * state and recursively call FollowCtrl(). */
  406. if (offTable < endTable)
  407. {
  408. STATE StCopy;
  409. int ip;
  410. uint32_t *psw;
  411. setBits(BM_DATA, offTable, endTable - offTable);
  412. pIcode.ll()->setFlags(SWITCH);
  413. pIcode.ll()->caseTbl.numEntries = (endTable - offTable) / 2;
  414. assert(pIcode.ll()->caseTbl.numEntries<512);
  415. psw = new uint32_t [pIcode.ll()->caseTbl.numEntries];
  416. pIcode.ll()->caseTbl.entries = psw;
  417. for (i = offTable, k = 0; i < endTable; i += 2)
  418. {
  419. StCopy = *pstate;
  420. StCopy.IP = cs + LH(&prog.Image[i]);
  421. iICODE last_current_insn = (++Icode.rbegin()).base();
  422. ip = Icode.size();
  423. FollowCtrl (pcallGraph, &StCopy);
  424. ++last_current_insn;
  425. last_current_insn->ll()->caseTbl.numEntries = k++;
  426. last_current_insn->ll()->setFlags(CASE);
  427. *psw++ = last_current_insn->ll()->GetLlLabel();
  428. }
  429. return true;
  430. }
  431. }
  432. /* Can't do anything with this jump */
  433. flg |= PROC_IJMP;
  434. flg &= ~TERMINATES;
  435. interactDis(this, this->Icode.size()-1);
  436. return true;
  437. }
  438. /* Process procedure call.
  439. * Note: We assume that CALL's will return unless there is good evidence to
  440. * the contrary - thus we return false unless all paths in the called
  441. * procedure end in DOS exits. This is reasonable since C procedures
  442. * will always include the epilogue after the call anyway and it's to
  443. * be assumed that if an assembler program contains a CALL that the
  444. * programmer expected it to come back - otherwise surely a JMP would
  445. * have been used. */
  446. boolT Function::process_CALL (ICODE & pIcode, CALL_GRAPH * pcallGraph, STATE *pstate)
  447. {
  448. PROG &prog(Project::get()->prog);
  449. ICODE &last_insn(Icode.back());
  450. STATE localState; /* Local copy of the machine state */
  451. uint32_t off;
  452. boolT indirect;
  453. /* For Indirect Calls, find the function address */
  454. indirect = false;
  455. //pIcode.ll()->immed.proc.proc=fakeproc;
  456. if ( not pIcode.ll()->testFlags(I) )
  457. {
  458. /* Not immediate, i.e. indirect call */
  459. if (pIcode.ll()->dst.regi && (!option.Calls))
  460. {
  461. /* We have not set the brave option to attempt to follow
  462. the execution path through register indirect calls.
  463. So we just exit this function, and ignore the call.
  464. We probably should not have parsed this deep, anyway.
  465. */
  466. return false;
  467. }
  468. /* Offset into program image is seg:off of read input */
  469. /* Note: this assumes that the pointer itself is at
  470. es:0 where es:0 is the start of the image. This is
  471. usually wrong! Consider also CALL [BP+0E] in which the
  472. segment for the pointer is in SS! - Mike */
  473. if(pIcode.ll()->dst.isReg())
  474. {
  475. if( not pstate->isKnown(pIcode.ll()->dst.regi)
  476. or
  477. not pstate->isKnown(pIcode.ll()->dst.seg)
  478. )
  479. {
  480. fprintf(stderr,"Indirect call with unkown register values\n");
  481. return false;
  482. }
  483. off = pstate->r[pIcode.ll()->dst.seg];
  484. off <<=4;
  485. off += pstate->r[pIcode.ll()->dst.regi];
  486. }
  487. else
  488. {
  489. off = (uint32_t)(uint16_t)pIcode.ll()->dst.off +
  490. ((uint32_t)(uint16_t)pIcode.ll()->dst.segValue << 4);
  491. }
  492. /* Address of function is given by 4 (CALLF) or 2 (CALL) bytes at
  493. * previous offset into the program image */
  494. uint32_t tgtAddr=0;
  495. if (pIcode.ll()->getOpcode() == iCALLF)
  496. tgtAddr= LH(&prog.Image[off]) + (uint32_t)(LH(&prog.Image[off+2])) << 4;
  497. else
  498. tgtAddr= LH(&prog.Image[off]) + (uint32_t)(uint16_t)state.r[rCS] << 4;
  499. pIcode.ll()->src.SetImmediateOp( tgtAddr );
  500. pIcode.ll()->setFlags(I);
  501. indirect = true;
  502. }
  503. /* Process CALL. Function address is located in pIcode.ll()->immed.op */
  504. if (pIcode.ll()->testFlags(I))
  505. {
  506. /* Search procedure list for one with appropriate entry point */
  507. ilFunction iter = g_proj.findByEntry(pIcode.ll()->src.op());
  508. /* Create a new procedure node and save copy of the state */
  509. if ( not g_proj.valid(iter) )
  510. {
  511. iter = g_proj.createFunction();
  512. Function &x(*iter);
  513. x.procEntry = pIcode.ll()->src.op();
  514. LibCheck(x);
  515. if (x.flg & PROC_ISLIB)
  516. {
  517. /* A library function. No need to do any more to it */
  518. pcallGraph->insertCallGraph (this, iter);
  519. //iter = (++pProcList.rbegin()).base();
  520. last_insn.ll()->src.proc.proc = &x;
  521. return false;
  522. }
  523. if (indirect)
  524. x.flg |= PROC_ICALL;
  525. if (x.name.empty()) /* Don't overwrite existing name */
  526. {
  527. ostringstream os;
  528. os<<"proc_"<< ++prog.cProcs;
  529. x.name = os.str();
  530. }
  531. x.depth = x.depth + 1;
  532. x.flg |= TERMINATES;
  533. /* Save machine state in localState, load up IP and CS.*/
  534. localState = *pstate;
  535. pstate->IP = pIcode.ll()->src.op();
  536. if (pIcode.ll()->getOpcode() == iCALLF)
  537. pstate->setState( rCS, LH(prog.Image + pIcode.ll()->label + 3));
  538. x.state = *pstate;
  539. /* Insert new procedure in call graph */
  540. pcallGraph->insertCallGraph (this, iter);
  541. /* Process new procedure */
  542. x.FollowCtrl (pcallGraph, pstate);
  543. /* Restore segment registers & IP from localState */
  544. pstate->IP = localState.IP;
  545. pstate->setState( rCS, localState.r[rCS]);
  546. pstate->setState( rDS, localState.r[rDS]);
  547. pstate->setState( rES, localState.r[rES]);
  548. pstate->setState( rSS, localState.r[rSS]);
  549. }
  550. else
  551. g_proj.callGraph->insertCallGraph (this, iter);
  552. last_insn.ll()->src.proc.proc = &(*iter); // ^ target proc
  553. /* return ((p->flg & TERMINATES) != 0); */
  554. }
  555. return false; // Cristina, please check!!
  556. }
  557. /* process_MOV - Handles state changes due to simple assignments */
  558. static void process_MOV(LLInst & ll, STATE * pstate)
  559. {
  560. PROG &prog(Project::get()->prog);
  561. SYM * psym, *psym2; /* Pointer to symbol in global symbol table */
  562. uint8_t dstReg = ll.dst.regi;
  563. uint8_t srcReg = ll.src.regi;
  564. if (dstReg > 0 && dstReg < INDEX_BX_SI)
  565. {
  566. if (ll.testFlags(I))
  567. pstate->setState( dstReg, (int16_t)ll.src.op());
  568. else if (srcReg == 0) /* direct memory offset */
  569. {
  570. psym = lookupAddr(&ll.src, pstate, 2, eDuVal::USE);
  571. if (psym && ((psym->flg & SEG_IMMED) || psym->duVal.val))
  572. pstate->setState( dstReg, LH(&prog.Image[psym->label]));
  573. }
  574. else if (srcReg < INDEX_BX_SI && pstate->f[srcReg]) /* reg */
  575. {
  576. pstate->setState( dstReg, pstate->r[srcReg]);
  577. /* Follow moves of the possible index register */
  578. if (pstate->JCond.regi == srcReg)
  579. pstate->JCond.regi = dstReg;
  580. }
  581. }
  582. else if (dstReg == 0) { /* direct memory offset */
  583. int size=2;
  584. if((ll.src.regi>=rAL)&&(ll.src.regi<=rBH))
  585. size=1;
  586. psym = lookupAddr (&ll.dst, pstate, size, eDEF);
  587. if (psym && ! (psym->duVal.val)) /* no initial value yet */
  588. if (ll.testFlags(I)) /* immediate */
  589. {
  590. prog.Image[psym->label] = (uint8_t)ll.src.op();
  591. if(psym->size>1)
  592. prog.Image[psym->label+1] = (uint8_t)(ll.src.op()>>8);
  593. psym->duVal.val = 1;
  594. }
  595. else if (srcReg == 0) /* direct mem offset */
  596. {
  597. psym2 = lookupAddr (&ll.src, pstate, 2, eDuVal::USE);
  598. if (psym2 && ((psym->flg & SEG_IMMED) || (psym->duVal.val)))
  599. {
  600. prog.Image[psym->label] = (uint8_t)prog.Image[psym2->label];
  601. if(psym->size>1)
  602. prog.Image[psym->label+1] = prog.Image[psym2->label+1];//(uint8_t)(prog.Image[psym2->label+1] >> 8);
  603. psym->duVal.setFlags(eDuVal::DEF);
  604. psym2->duVal.setFlags(eDuVal::USE);
  605. }
  606. }
  607. else if (srcReg < INDEX_BX_SI && pstate->f[srcReg]) /* reg */
  608. {
  609. prog.Image[psym->label] = (uint8_t)pstate->r[srcReg];
  610. if(psym->size>1)
  611. prog.Image[psym->label+1] = (uint8_t)(pstate->r[srcReg] >> 8);
  612. psym->duVal.setFlags(eDuVal::DEF);
  613. }
  614. }
  615. }
  616. /* Updates the offset entry to the stack frame table (arguments),
  617. * and returns a pointer to such entry. */
  618. void STKFRAME::updateFrameOff ( int16_t off, int _size, uint16_t duFlag)
  619. {
  620. int i;
  621. /* Check for symbol in stack frame table */
  622. auto iter=findByLabel(off);
  623. if(iter!=end())
  624. {
  625. if (iter->size < _size)
  626. {
  627. iter->size = _size;
  628. }
  629. }
  630. else
  631. {
  632. char nm[16];
  633. STKSYM new_sym;
  634. sprintf (nm, "arg%ld", size());
  635. new_sym.name = nm;
  636. new_sym.label= off;
  637. new_sym.size = _size;
  638. new_sym.type = TypeContainer::defaultTypeForSize(_size);
  639. if (duFlag == eDuVal::USE) /* must already have init value */
  640. {
  641. new_sym.duVal.use=1;
  642. //new_sym.duVal.val=1;
  643. }
  644. else
  645. {
  646. new_sym.duVal.setFlags(duFlag);
  647. }
  648. push_back(new_sym);
  649. this->numArgs++;
  650. }
  651. /* Save maximum argument offset */
  652. if ((uint32_t)this->maxOff < (off + (uint32_t)_size))
  653. this->maxOff = off + (int16_t)_size;
  654. }
  655. /* lookupAddr - Looks up a data reference in the symbol table and stores it
  656. * if necessary.
  657. * Returns a pointer to the symbol in the
  658. * symbol table, or Null if it's not a direct memory offset. */
  659. static SYM * lookupAddr (LLOperand *pm, STATE *pstate, int size, uint16_t duFlag)
  660. {
  661. PROG &prog(Project::get()->prog);
  662. int i;
  663. SYM * psym=nullptr;
  664. uint32_t operand;
  665. bool created_new=false;
  666. if (pm->regi != rUNDEF)
  667. return nullptr; // register or indexed
  668. /* Global var */
  669. if (pm->segValue) /* there is a value in the seg field */
  670. {
  671. operand = opAdr (pm->segValue, pm->off);
  672. psym = g_proj.symtab.updateGlobSym (operand, size, duFlag,created_new);
  673. }
  674. else if (pstate->f[pm->seg]) /* new value */
  675. {
  676. pm->segValue = pstate->r[pm->seg];
  677. operand = opAdr(pm->segValue, pm->off);
  678. psym = g_proj.symtab.updateGlobSym (operand, size, duFlag,created_new);
  679. /* Flag new memory locations that are segment values */
  680. if (created_new)
  681. {
  682. if (size == 4)
  683. operand += 2; /* High uint16_t */
  684. for (i = 0; i < prog.cReloc; i++)
  685. if (prog.relocTable[i] == operand) {
  686. psym->flg = SEG_IMMED;
  687. break;
  688. }
  689. }
  690. }
  691. /* Check for out of bounds */
  692. if (psym && (psym->label>=0) and (psym->label < (uint32_t)prog.cbImage))
  693. return psym;
  694. return nullptr;
  695. }
  696. /* setState - Assigns a value to a reg. */
  697. void STATE::setState(uint16_t reg, int16_t value)
  698. {
  699. value &= 0xFFFF;
  700. r[reg] = value;
  701. f[reg] = true;
  702. switch (reg) {
  703. case rAX: case rCX: case rDX: case rBX:
  704. r[reg + rAL - rAX] = value & 0xFF;
  705. f[reg + rAL - rAX] = true;
  706. r[reg + rAH - rAX] = (value >> 8) & 0xFF;
  707. f[reg + rAH - rAX] = true;
  708. break;
  709. case rAL: case rCL: case rDL: case rBL:
  710. if (f[reg - rAL + rAH]) {
  711. r[reg - rAL + rAX] =(r[reg - rAL + rAH] << 8) + (value & 0xFF);
  712. f[reg - rAL + rAX] = true;
  713. }
  714. break;
  715. case rAH: case rCH: case rDH: case rBH:
  716. if (f[reg - rAH + rAL])
  717. {
  718. r[reg - rAH + rAX] = r[reg - rAH + rAL] + ((value & 0xFF) << 8);
  719. f[reg - rAH + rAX] = true;
  720. }
  721. break;
  722. }
  723. }
  724. /* labelSrchRepl - Searches Icode for instruction with label = target, and
  725. replaces *pIndex with an icode index */
  726. /* setBits - Sets memory bitmap bits for BM_CODE or BM_DATA (additively) */
  727. static void setBits(int16_t type, uint32_t start, uint32_t len)
  728. {
  729. PROG &prog(Project::get()->prog);
  730. uint32_t i;
  731. if (start < (uint32_t)prog.cbImage)
  732. {
  733. if (start + len > (uint32_t)prog.cbImage)
  734. len = (uint32_t)(prog.cbImage - start);
  735. for (i = start + len - 1; i >= start; i--)
  736. {
  737. prog.map[i >> 2] |= type << ((i & 3) << 1);
  738. if (i == 0) break; // Fixes inf loop!
  739. }
  740. }
  741. }
  742. /* DU bit definitions for each reg value - including index registers */
  743. std::bitset<32> duReg[] = { 0x00,
  744. //AH AL . . AX, BH
  745. 0x11001, 0x22002, 0x44004, 0x88008, /* uint16_t regs */
  746. 0x10, 0x20, 0x40, 0x80,
  747. 0x100, 0x200, 0x400, 0x800, /* seg regs */
  748. 0x1000, 0x2000, 0x4000, 0x8000, /* uint8_t regs */
  749. 0x10000, 0x20000, 0x40000, 0x80000,
  750. 0x100000, /* tmp reg */
  751. 0x48, 0x88, 0x60, 0xA0, /* index regs */
  752. 0x40, 0x80, 0x20, 0x08 };
  753. /* Checks which registers where used and updates the du.u flag.
  754. * Places local variables on the local symbol table.
  755. * Arguments: d : SRC or DST icode operand
  756. * pIcode: ptr to icode instruction
  757. * pProc : ptr to current procedure structure
  758. * pstate: ptr to current procedure state
  759. * size : size of the operand
  760. * ix : current index into icode array */
  761. static void use (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size, int ix)
  762. {
  763. LLOperand * pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
  764. SYM * psym;
  765. if ( Machine_X86::isMemOff(pm->regi) )
  766. {
  767. if (pm->regi == INDEX_BP) /* indexed on bp */
  768. {
  769. if (pm->off >= 2)
  770. pProc->args.updateFrameOff ( pm->off, size, eDuVal::USE);
  771. else if (pm->off < 0)
  772. pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, 0);
  773. }
  774. else if (pm->regi == INDEX_BP_SI || pm->regi == INDEX_BP_DI)
  775. pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off,
  776. (uint8_t)((pm->regi == INDEX_BP_SI) ? rSI : rDI));
  777. else if ((pm->regi >= INDEX_SI) && (pm->regi <= INDEX_BX))
  778. {
  779. if ((pm->seg == rDS) && (pm->regi == INDEX_BX)) /* bx */
  780. {
  781. if (pm->off > 0) /* global indexed variable */
  782. pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,ix, TYPE_WORD_SIGN);
  783. }
  784. pIcode.du.use |= duReg[pm->regi];
  785. }
  786. else if (psym = lookupAddr(pm, pstate, size, eDuVal::USE))
  787. {
  788. setBits (BM_DATA, psym->label, (uint32_t)size);
  789. pIcode.ll()->setFlags(SYM_USE);
  790. pIcode.ll()->caseTbl.numEntries = distance(&g_proj.symtab[0],psym);
  791. }
  792. }
  793. /* Use of register */
  794. else if ((d == DST) || ((d == SRC) && (not pIcode.ll()->testFlags(I))))
  795. pIcode.du.use |= duReg[pm->regi];
  796. }
  797. /* Checks which registers were defined (ie. got a new value) and updates the
  798. * du.d flag.
  799. * Places local variables in the local symbol table. */
  800. static void def (opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int size,
  801. int ix)
  802. {
  803. LLOperand *pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
  804. SYM * psym;
  805. if (pm->regi == 0 || pm->regi >= INDEX_BX_SI)
  806. {
  807. if (pm->regi == INDEX_BP) /* indexed on bp */
  808. {
  809. if (pm->off >= 2)
  810. pProc->args.updateFrameOff ( pm->off, size, eDEF);
  811. else if (pm->off < 0)
  812. pProc->localId.newByteWordStk (TYPE_WORD_SIGN, pm->off, 0);
  813. }
  814. else if (pm->regi == INDEX_BP_SI || pm->regi == INDEX_BP_DI)
  815. {
  816. pProc->localId.newByteWordStk(TYPE_WORD_SIGN, pm->off,
  817. (uint8_t)((pm->regi == INDEX_BP_SI) ? rSI : rDI));
  818. }
  819. else if ((pm->regi >= INDEX_SI) && (pm->regi <= INDEX_BX))
  820. {
  821. if ((pm->seg == rDS) && (pm->regi == INDEX_BX)) /* bx */
  822. {
  823. if (pm->off > 0) /* global var */
  824. pProc->localId.newIntIdx(pm->segValue, pm->off, rBX,ix, TYPE_WORD_SIGN);
  825. }
  826. pIcode.du.use |= duReg[pm->regi];
  827. }
  828. else if (psym = lookupAddr(pm, pstate, size, eDEF))
  829. {
  830. setBits(BM_DATA, psym->label, (uint32_t)size);
  831. pIcode.ll()->setFlags(SYM_DEF);
  832. pIcode.ll()->caseTbl.numEntries = distance(&g_proj.symtab[0],psym);
  833. }
  834. }
  835. /* Definition of register */
  836. else if ((d == DST) || ((d == SRC) && (not pIcode.ll()->testFlags(I))))
  837. {
  838. pIcode.du.def |= duReg[pm->regi];
  839. pIcode.du1.numRegsDef++;
  840. }
  841. }
  842. /* use_def - operand is both use and def'd.
  843. * Note: the destination will always be a register, stack variable, or global
  844. * variable. */
  845. static void use_def(opLoc d, ICODE & pIcode, Function * pProc, STATE * pstate, int cb,
  846. int ix)
  847. {
  848. LLOperand * pm = (d == SRC)? &pIcode.ll()->src: &pIcode.ll()->dst;
  849. use (d, pIcode, pProc, pstate, cb, ix);
  850. if (pm->regi < INDEX_BX_SI) /* register */
  851. {
  852. pIcode.du.def |= duReg[pm->regi];
  853. pIcode.du1.numRegsDef++;
  854. }
  855. }
  856. /* Set DU vector, local variables and arguments, and DATA bits in the
  857. * bitmap */
  858. void Function::process_operands(ICODE & pIcode, STATE * pstate)
  859. {
  860. int ix=Icode.size();
  861. int i;
  862. int sseg = (pIcode.ll()->src.seg)? pIcode.ll()->src.seg: rDS;
  863. int cb = pIcode.ll()->testFlags(B) ? 1: 2;
  864. uint32_t Imm = (pIcode.ll()->testFlags(I));
  865. switch (pIcode.ll()->getOpcode()) {
  866. case iAND: case iOR: case iXOR:
  867. case iSAR: case iSHL: case iSHR:
  868. case iRCL: case iRCR: case iROL: case iROR:
  869. case iADD: case iADC: case iSUB: case iSBB:
  870. if (! Imm) {
  871. use(SRC, pIcode, this, pstate, cb, ix);
  872. }
  873. case iINC: case iDEC: case iNEG: case iNOT:
  874. case iAAA: case iAAD: case iAAM: case iAAS:
  875. case iDAA: case iDAS:
  876. use_def(DST, pIcode, this, pstate, cb, ix);
  877. break;
  878. case iXCHG:
  879. /* This instruction is replaced by 3 instructions, only need
  880. * to define the src operand and use the destination operand
  881. * in the mean time. */
  882. use(SRC, pIcode, this, pstate, cb, ix);
  883. def(DST, pIcode, this, pstate, cb, ix);
  884. break;
  885. case iTEST: case iCMP:
  886. if (! Imm)
  887. use(SRC, pIcode, this, pstate, cb, ix);
  888. use(DST, pIcode, this, pstate, cb, ix);
  889. break;
  890. case iDIV: case iIDIV:
  891. use(SRC, pIcode, this, pstate, cb, ix);
  892. if (cb == 1)
  893. pIcode.du.use |= duReg[rTMP];
  894. break;
  895. case iMUL: case iIMUL:
  896. use(SRC, pIcode, this, pstate, cb, ix);
  897. if (! Imm)
  898. {
  899. use (DST, pIcode, this, pstate, cb, ix);
  900. if (cb == 1)
  901. {
  902. pIcode.du.def |= duReg[rAX];
  903. pIcode.du1.numRegsDef++;
  904. }
  905. else
  906. {
  907. pIcode.du.def |= (duReg[rAX] | duReg[rDX]);
  908. pIcode.du1.numRegsDef += 2;
  909. }
  910. }
  911. else
  912. def (DST, pIcode, this, pstate, cb, ix);
  913. break;
  914. case iSIGNEX:
  915. cb = pIcode.ll()->testFlags(SRC_B) ? 1 : 2;
  916. if (cb == 1) /* uint8_t */
  917. {
  918. pIcode.du.def |= duReg[rAX];
  919. pIcode.du1.numRegsDef++;
  920. pIcode.du.use |= duReg[rAL];
  921. }
  922. else /* uint16_t */
  923. {
  924. pIcode.du.def |= (duReg[rDX] | duReg[rAX]);
  925. pIcode.du1.numRegsDef += 2;
  926. pIcode.du.use |= duReg[rAX];
  927. }
  928. break;
  929. case iCALLF: /* Ignore def's on CS for now */
  930. cb = 4;
  931. case iCALL: case iPUSH: case iPOP:
  932. if (! Imm) {
  933. if (pIcode.ll()->getOpcode() == iPOP)
  934. def(DST, pIcode, this, pstate, cb, ix);
  935. else
  936. use(DST, pIcode, this, pstate, cb, ix);
  937. }
  938. break;
  939. case iESC: /* operands may be larger */
  940. use(DST, pIcode, this, pstate, cb, ix);
  941. break;
  942. case iLDS: case iLES:
  943. pIcode.du.def |= duReg[(pIcode.ll()->getOpcode() == iLDS) ? rDS : rES];
  944. pIcode.du1.numRegsDef++;
  945. cb = 4;
  946. case iMOV:
  947. use(SRC, pIcode, this, pstate, cb, ix);
  948. def(DST, pIcode, this, pstate, cb, ix);
  949. break;
  950. case iLEA:
  951. use(SRC, pIcode, this, pstate, 2, ix);
  952. def(DST, pIcode, this, pstate, 2, ix);
  953. break;
  954. case iBOUND:
  955. use(SRC, pIcode, this, pstate, 4, ix);
  956. use(DST, pIcode, this, pstate, cb, ix);
  957. break;
  958. case iJMPF:
  959. cb = 4;
  960. case iJMP:
  961. if (! Imm)
  962. use(SRC, pIcode, this, pstate, cb, ix);
  963. break;
  964. case iLOOP: case iLOOPE: case iLOOPNE:
  965. pIcode.du.def |= duReg[rCX];
  966. pIcode.du1.numRegsDef++;
  967. case iJCXZ:
  968. pIcode.du.use |= duReg[rCX];
  969. break;
  970. case iREPNE_CMPS: case iREPE_CMPS: case iREP_MOVS:
  971. pIcode.du.def |= duReg[rCX];
  972. pIcode.du1.numRegsDef++;
  973. pIcode.du.use |= duReg[rCX];
  974. case iCMPS: case iMOVS:
  975. pIcode.du.def |= duReg[rSI] | duReg[rDI];
  976. pIcode.du1.numRegsDef += 2;
  977. pIcode.du.use |= duReg[rSI] | duReg[rDI] | duReg[rES] | duReg[sseg];
  978. break;
  979. case iREPNE_SCAS: case iREPE_SCAS: case iREP_STOS: case iREP_INS:
  980. pIcode.du.def |= duReg[rCX];
  981. pIcode.du1.numRegsDef++;
  982. pIcode.du.use |= duReg[rCX];
  983. case iSCAS: case iSTOS: case iINS:
  984. pIcode.du.def |= duReg[rDI];
  985. pIcode.du1.numRegsDef++;
  986. if (pIcode.ll()->getOpcode() == iREP_INS || pIcode.ll()->getOpcode()== iINS)
  987. {
  988. pIcode.du.use |= duReg[rDI] | duReg[rES] | duReg[rDX];
  989. }
  990. else
  991. {
  992. pIcode.du.use |= duReg[rDI] | duReg[rES] | duReg[(cb == 2)? rAX: rAL];
  993. }
  994. break;
  995. case iREP_LODS:
  996. pIcode.du.def |= duReg[rCX];
  997. pIcode.du1.numRegsDef++;
  998. pIcode.du.use |= duReg[rCX];
  999. case iLODS:
  1000. pIcode.du.def |= duReg[rSI] | duReg[(cb==2)? rAX: rAL];
  1001. pIcode.du1.numRegsDef += 2;
  1002. pIcode.du.use |= duReg[rSI] | duReg[sseg];
  1003. break;
  1004. case iREP_OUTS:
  1005. pIcode.du.def |= duReg[rCX];
  1006. pIcode.du1.numRegsDef++;
  1007. pIcode.du.use |= duReg[rCX];
  1008. case iOUTS:
  1009. pIcode.du.def |= duReg[rSI];
  1010. pIcode.du1.numRegsDef++;
  1011. pIcode.du.use |= duReg[rSI] | duReg[rDX] | duReg[sseg];
  1012. break;
  1013. case iIN: case iOUT:
  1014. def(DST, pIcode, this, pstate, cb, ix);
  1015. if (! Imm)
  1016. {
  1017. pIcode.du.use |= duReg[rDX];
  1018. }
  1019. break;
  1020. }
  1021. for (i = rSP; i <= rBH; i++) /* Kill all defined registers */
  1022. if (pIcode.ll()->flagDU.d & (1 << i))
  1023. pstate->f[i] = false;
  1024. }