parser.cpp 40 KB

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