fpregs.pas 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998-2000 by Pierre Muller
  5. Register debug routines for the IDE
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit FPRegs;
  13. {$ifdef NODEBUG}
  14. interface
  15. implementation
  16. end.
  17. {$else}
  18. interface
  19. uses
  20. {$ifdef win32}
  21. Windows,
  22. {$endif win32}
  23. Objects,Dialogs,Drivers,Views,
  24. FPViews;
  25. const
  26. MaxRegs = 128;
  27. type
  28. {$ifdef TP}
  29. dword = longint;
  30. {$endif TP}
  31. {$undef cpu_known}
  32. TIntRegs = record
  33. {$ifndef test_generic_cpu}
  34. {$ifdef cpui386}
  35. {$define cpu_known}
  36. eax,ebx,ecx,edx,eip,esi,edi,esp,ebp : dword;
  37. cs,ds,es,ss,fs,gs : word;
  38. eflags : dword;
  39. {$endif cpui386}
  40. {$ifdef cpum68k}
  41. {$define cpu_known}
  42. d0,d1,d2,d3,d4,d5,d6,d7 : dword;
  43. a0,a1,a2,a3,a4,a5,fp,sp : dword;
  44. ps,pc : dword;
  45. {$endif cpum68k}
  46. {$ifdef cpupowerpc}
  47. {$define cpu_known}
  48. r : array [0..31] of dword;
  49. pc,ps,cr,lr,ctr,xer : dword;
  50. {$endif cpupowerpc}
  51. {$ifdef cpusparc}
  52. {$define cpu_known}
  53. o : array [0..7] of dword;
  54. i : array [0..7] of dword;
  55. l : array [0..7] of dword;
  56. g : array [0..7] of dword;
  57. y,psr,wim,tbr,pc,npc,fsr,csr : dword;
  58. {$endif cpusparc}
  59. {$endif not test_generic_cpu}
  60. {$ifndef cpu_known}
  61. reg : array [0..MaxRegs-1] of string;
  62. {$endif not cpu_known}
  63. end;
  64. PRegistersView = ^TRegistersView;
  65. TRegistersView = object(TView)
  66. NewReg,OldReg : TIntRegs;
  67. InDraw : boolean;
  68. GDBCount : longint;
  69. first : boolean;
  70. constructor Init(var Bounds: TRect);
  71. procedure Draw;virtual;
  72. destructor Done; virtual;
  73. end;
  74. PRegistersWindow = ^TRegistersWindow;
  75. TRegistersWindow = Object(TFPDlgWindow)
  76. RV : PRegistersView;
  77. Constructor Init;
  78. constructor Load(var S: TStream);
  79. procedure Store(var S: TStream);
  80. procedure Update; virtual;
  81. destructor Done; virtual;
  82. end;
  83. TFPURegs = record
  84. {$ifndef test_generic_cpu}
  85. {$ifdef cpui386}
  86. st0,st1,st2,st3,st4,st5,st6,st7 :string;
  87. ftag,fop,fctrl,fstat,fiseg,foseg : word;
  88. fioff,fooff : cardinal;
  89. {$endif cpui386}
  90. {$ifdef cpum68k}
  91. fp0,fp1,fp2,fp3,fp4,fp5,fp6,fp7 : string;
  92. fpcontrol,fpstatus,fpiaddr : dword;
  93. {$endif cpum68k}
  94. {$ifdef cpupowerpc}
  95. f : array [0..31] of string;
  96. {$endif cpupowerpc}
  97. {$ifdef cpusparc}
  98. f : array [0..31] of string;
  99. {$endif cpusparc}
  100. {$endif not test_generic_cpu}
  101. {$ifndef cpu_known}
  102. freg : array [0..MaxRegs-1] of string;
  103. {$endif not cpu_known}
  104. end;
  105. PFPUView = ^TFPUView;
  106. TFPUView = object(TView)
  107. NewReg,OldReg : TFPURegs;
  108. InDraw : boolean;
  109. GDBCount : longint;
  110. {$ifndef cpu_known}
  111. UseInfoFloat : boolean;
  112. {$endif not cpu_known}
  113. first : boolean;
  114. constructor Init(var Bounds: TRect);
  115. procedure Draw;virtual;
  116. destructor Done; virtual;
  117. end;
  118. PFPUWindow = ^TFPUWindow;
  119. TFPUWindow = Object(TFPDlgWindow)
  120. RV : PFPUView;
  121. Constructor Init;
  122. constructor Load(var S: TStream);
  123. procedure Store(var S: TStream);
  124. procedure Update; virtual;
  125. destructor Done; virtual;
  126. end;
  127. tssereg = record
  128. case byte of
  129. 1 : (bytearray : array[0..15] of byte);
  130. 2 : (wordarray : array[0..7] of word);
  131. 3 : (dwordarray : array[0..3] of dword);
  132. 4 : (qwordarray : array[0..1] of qword);
  133. 5 : (twordfield : array[0..1] of qword);
  134. 6 : (singlearray : array[0..3] of single);
  135. 7 : (doublearray : array[0..1] of double);
  136. end;
  137. tmmxreg = record
  138. case byte of
  139. 1 : (bytearray : array[0..7] of byte);
  140. 2 : (wordarray : array[0..3] of word);
  141. 3 : (dwordarray : array[0..1] of dword);
  142. 4 : (qwordfield : qword);
  143. 6 : (singlearray : array[0..1] of single);
  144. end;
  145. TVectorRegs = record
  146. {$ifndef test_generic_cpu}
  147. {$ifdef cpui386}
  148. xmm : array[0..7] of string;
  149. mmx : array[0..7] of string;
  150. mxcsr : string;
  151. {$endif cpui386}
  152. {$ifdef cpupowerpc}
  153. m : array[0..31] of string;
  154. {$endif cpupowerpc}
  155. {$endif not test_generic_cpu}
  156. {$ifndef cpu_known}
  157. vreg : array [0..MaxRegs-1] of string;
  158. {$endif not cpu_known}
  159. end;
  160. PVectorView = ^TVectorView;
  161. TVectorView = object(TView)
  162. NewReg,OldReg : TVectorRegs;
  163. InDraw : boolean;
  164. GDBCount : longint;
  165. first : boolean;
  166. constructor Init(var Bounds: TRect);
  167. procedure Draw;virtual;
  168. destructor Done; virtual;
  169. end;
  170. PVectorWindow = ^TVectorWindow;
  171. TVectorWindow = Object(TFPDlgWindow)
  172. RV : PVectorView;
  173. Constructor Init;
  174. constructor Load(var S: TStream);
  175. procedure Store(var S: TStream);
  176. procedure Update; virtual;
  177. destructor Done; virtual;
  178. end;
  179. procedure InitRegistersWindow;
  180. procedure DoneRegistersWindow;
  181. procedure InitFPUWindow;
  182. procedure DoneFPUWindow;
  183. procedure InitVectorWindow;
  184. procedure DoneVectorWindow;
  185. procedure RegisterFPRegsViews;
  186. implementation
  187. uses
  188. Strings,
  189. {$ifndef NODEBUG}
  190. GDBCon,GDBInt,
  191. {$endif NODEBUG}
  192. App,Menus,
  193. WViews,WEditor,
  194. wutils,
  195. FPConst,FPVars,
  196. FPString,
  197. FPDebug;
  198. Const
  199. RRegistersWindow: TStreamRec = (
  200. ObjType: 1711;
  201. VmtLink: Ofs(TypeOf(TRegistersWindow)^);
  202. Load: @TRegistersWindow.Load;
  203. Store: @TRegistersWindow.Store
  204. );
  205. RRegistersView: TStreamRec = (
  206. ObjType: 1712;
  207. VmtLink: Ofs(TypeOf(TRegistersView)^);
  208. Load: @TRegistersView.Load;
  209. Store: @TRegistersView.Store
  210. );
  211. RFPUWindow: TStreamRec = (
  212. ObjType: 1713;
  213. VmtLink: Ofs(TypeOf(TFPUWindow)^);
  214. Load: @TFPUWindow.Load;
  215. Store: @TFPUWindow.Store
  216. );
  217. RFPUView: TStreamRec = (
  218. ObjType: 1714;
  219. VmtLink: Ofs(TypeOf(TFPUView)^);
  220. Load: @TFPUView.Load;
  221. Store: @TFPUView.Store
  222. );
  223. RVectorView: TStreamRec = (
  224. ObjType: 1715;
  225. VmtLink: Ofs(TypeOf(TVectorView)^);
  226. Load: @TVectorView.Load;
  227. Store: @TVectorView.Store
  228. );
  229. {****************************************************************************
  230. TRegistersView
  231. ****************************************************************************}
  232. function GetIntRegs(var rs : TIntRegs) : boolean;
  233. var
  234. p,po : pchar;
  235. p1 : pchar;
  236. reg,value : string;
  237. buffer : array[0..255] of char;
  238. v : dword;
  239. code : word;
  240. i : byte;
  241. begin
  242. GetIntRegs:=false;
  243. {$ifndef NODEBUG}
  244. Debugger^.Command('info registers');
  245. if Debugger^.Error then
  246. exit
  247. else
  248. begin
  249. {$ifndef cpu_known}
  250. i:=0;
  251. {$endif not cpu_known}
  252. po:=StrNew(Debugger^.GetOutput);
  253. p:=po;
  254. if assigned(p) then
  255. begin
  256. fillchar(rs,sizeof(rs),0);
  257. p1:=strscan(p,' ');
  258. while assigned(p1) do
  259. begin
  260. {$ifndef cpu_known}
  261. p1:=strscan(p,#10);
  262. if assigned(p1) then
  263. begin
  264. strlcopy(buffer,p,p1-p);
  265. rs.reg[i]:=ExtractTabs(strpas(buffer),8);
  266. if i<MaxRegs-1 then
  267. inc(i);
  268. end;
  269. {$else cpu_known}
  270. strlcopy(buffer,p,p1-p);
  271. reg:=strpas(buffer);
  272. p1:=strscan(p,'$');
  273. { some targets use 0x instead of $ }
  274. if p1=nil then
  275. p:=strpos(p,'0x')
  276. else
  277. p:=p1;
  278. p1:=strscan(p,#9);
  279. strlcopy(buffer,p,p1-p);
  280. value:=strpas(buffer);
  281. { replace the $? }
  282. if copy(value,1,2)='0x' then
  283. value:='$'+copy(value,3,length(value)-2);
  284. val(value,v,code);
  285. {$ifdef cpui386}
  286. if reg='eax' then
  287. rs.eax:=v
  288. else if reg='ebx' then
  289. rs.ebx:=v
  290. else if reg='ecx' then
  291. rs.ecx:=v
  292. else if reg='edx' then
  293. rs.edx:=v
  294. else if reg='eip' then
  295. rs.eip:=v
  296. else if reg='esi' then
  297. rs.esi:=v
  298. else if reg='edi' then
  299. rs.edi:=v
  300. else if reg='esp' then
  301. rs.esp:=v
  302. else if reg='ebp' then
  303. rs.ebp:=v
  304. { under win32 flags are on a register named ps !! PM }
  305. else if (reg='eflags') or (reg='ps') then
  306. rs.eflags:=v
  307. else if reg='cs' then
  308. rs.cs:=v
  309. else if reg='ds' then
  310. rs.ds:=v
  311. else if reg='es' then
  312. rs.es:=v
  313. else if reg='fs' then
  314. rs.fs:=v
  315. else if reg='gs' then
  316. rs.gs:=v
  317. else if reg='ss' then
  318. rs.ss:=v;
  319. {$endif cpui386}
  320. {$ifdef cpum68k}
  321. if reg='d0' then
  322. rs.d0:=v
  323. else if reg='d1' then
  324. rs.d1:=v
  325. else if reg='d2' then
  326. rs.d2:=v
  327. else if reg='d3' then
  328. rs.d3:=v
  329. else if reg='d4' then
  330. rs.d4:=v
  331. else if reg='d5' then
  332. rs.d5:=v
  333. else if reg='d6' then
  334. rs.d6:=v
  335. else if reg='d7' then
  336. rs.d7:=v
  337. else if reg='a0' then
  338. rs.a0:=v
  339. else if reg='a1' then
  340. rs.a1:=v
  341. else if reg='a2' then
  342. rs.a2:=v
  343. else if reg='a3' then
  344. rs.a3:=v
  345. else if reg='a4' then
  346. rs.a4:=v
  347. else if reg='a5' then
  348. rs.a5:=v
  349. else if reg='fp' then
  350. rs.fp:=v
  351. else if reg='sp' then
  352. rs.sp:=v
  353. else if (reg='ps') then
  354. rs.ps:=v
  355. else if reg='pc' then
  356. rs.pc:=v;
  357. {$endif cpum68k}
  358. {$ifdef cpupowerpc}
  359. if (reg[1]='r') then
  360. begin
  361. for i:=0 to 31 do
  362. if reg='r'+inttostr(i) then
  363. rs.r[i]:=v;
  364. end
  365. { other regs
  366. pc,ps,cr,lr,ctr,xer : dword; }
  367. else if (reg='pc') then
  368. rs.pc:=v
  369. else if (reg='ps') then
  370. rs.ps:=v
  371. else if (reg='lr') then
  372. rs.lr:=v
  373. else if (reg='ctr') then
  374. rs.ctr:=v
  375. else if (reg='xer') then
  376. rs.xer:=v;
  377. {$endif cpupowerpc}
  378. {$ifdef cpusparc}
  379. if (reg[1]='o') then
  380. begin
  381. for i:=0 to 7 do
  382. if reg='o'+inttostr(i) then
  383. rs.o[i]:=v;
  384. end
  385. else if (reg[1]='i') then
  386. begin
  387. for i:=0 to 7 do
  388. if reg='i'+inttostr(i) then
  389. rs.i[i]:=v;
  390. end
  391. else if (reg[1]='l') then
  392. begin
  393. for i:=0 to 7 do
  394. if reg='l'+inttostr(i) then
  395. rs.l[i]:=v;
  396. end
  397. else if (reg[1]='g') then
  398. begin
  399. for i:=0 to 7 do
  400. if reg='g'+inttostr(i) then
  401. rs.g[i]:=v;
  402. end
  403. else if reg='fp' then
  404. rs.i[6]:=v
  405. else if reg='y' then
  406. rs.y:=v
  407. else if reg='psr' then
  408. rs.psr:=v
  409. else if reg='wim' then
  410. rs.wim:=v
  411. else if reg='tbs' then
  412. rs.tbr:=v
  413. else if reg='pc' then
  414. rs.pc:=v
  415. else if reg='npc' then
  416. rs.npc:=v
  417. else if reg='fsr' then
  418. rs.fsr:=v
  419. else if reg='csr' then
  420. rs.csr:=v;
  421. {$endif cpusparc}
  422. {$endif not cpu_known}
  423. p:=strscan(p1,#10);
  424. if assigned(p) then
  425. begin
  426. p1:=strscan(p,' ');
  427. inc(p);
  428. end
  429. else
  430. break;
  431. end;
  432. { free allocated memory }
  433. strdispose(po);
  434. end
  435. else
  436. exit;
  437. end;
  438. { do not open a messagebox for such errors }
  439. Debugger^.got_error:=false;
  440. GetIntRegs:=true;
  441. {$endif}
  442. end;
  443. constructor TRegistersView.Init(var Bounds: TRect);
  444. begin
  445. inherited init(Bounds);
  446. InDraw:=false;
  447. first:=true;
  448. FillChar(OldReg,Sizeof(OldReg),#0);
  449. FillChar(NewReg,Sizeof(NewReg),#0);
  450. GrowMode:=gfGrowHiX or GfGrowHiY;
  451. GDBCount:=-1;
  452. end;
  453. procedure TRegistersView.Draw;
  454. var
  455. rs : tintregs;
  456. OK : boolean;
  457. color :byte;
  458. i : byte;
  459. procedure SetColor(x,y : longint);
  460. begin
  461. if x=y then
  462. color:=7
  463. else
  464. color:=8;
  465. end;
  466. procedure SetStrColor(const x,y : string);
  467. begin
  468. if x=y then
  469. color:=7
  470. else
  471. color:=8;
  472. end;
  473. begin
  474. inherited draw;
  475. {$ifdef NODEBUG}
  476. WriteStr(1,0,'<no values available>',7);
  477. {$else NODEBUG}
  478. If not assigned(Debugger) then
  479. begin
  480. WriteStr(1,0,'<no values available>',7);
  481. exit;
  482. end;
  483. if InDraw then exit;
  484. InDraw:=true;
  485. if GDBCount<>Debugger^.RunCount then
  486. begin
  487. OldReg:=NewReg;
  488. OK:=GetIntRegs(rs);
  489. NewReg:=rs;
  490. { get inital values }
  491. if first then
  492. begin
  493. OldReg:=NewReg;
  494. first:=false;
  495. end;
  496. GDBCount:=Debugger^.RunCount;
  497. end
  498. else
  499. begin
  500. rs:=NewReg;
  501. OK:=true;
  502. end;
  503. if OK then
  504. begin
  505. {$ifdef cpu_known}
  506. {$ifdef cpui386}
  507. SetColor(rs.eax,OldReg.eax);
  508. WriteStr(1,0,'EAX '+HexStr(longint(rs.eax),8),color);
  509. SetColor(rs.ebx,OldReg.ebx);
  510. WriteStr(1,1,'EBX '+HexStr(longint(rs.ebx),8),color);
  511. SetColor(rs.ecx,OldReg.ecx);
  512. WriteStr(1,2,'ECX '+HexStr(longint(rs.ecx),8),color);
  513. SetColor(rs.edx,OldReg.edx);
  514. WriteStr(1,3,'EDX '+HexStr(longint(rs.edx),8),color);
  515. SetColor(rs.eip,OldReg.eip);
  516. WriteStr(1,4,'EIP '+HexStr(longint(rs.eip),8),color);
  517. SetColor(rs.esi,OldReg.esi);
  518. WriteStr(1,5,'ESI '+HexStr(longint(rs.esi),8),color);
  519. SetColor(rs.edi,OldReg.edi);
  520. WriteStr(1,6,'EDI '+HexStr(longint(rs.edi),8),color);
  521. SetColor(rs.esp,OldReg.esp);
  522. WriteStr(1,7,'ESP '+HexStr(longint(rs.esp),8),color);
  523. SetColor(rs.ebp,OldReg.ebp);
  524. WriteStr(1,8,'EBP '+HexStr(longint(rs.ebp),8),color);
  525. SetColor(rs.cs,OldReg.cs);
  526. WriteStr(14,0,'CS '+HexStr(rs.cs,4),color);
  527. SetColor(rs.ds,OldReg.ds);
  528. WriteStr(14,1,'DS '+HexStr(rs.ds,4),color);
  529. SetColor(rs.es,OldReg.es);
  530. WriteStr(14,2,'ES '+HexStr(rs.es,4),color);
  531. SetColor(rs.fs,OldReg.fs);
  532. WriteStr(14,3,'FS '+HexStr(rs.fs,4),color);
  533. SetColor(rs.gs,OldReg.gs);
  534. WriteStr(14,4,'GS '+HexStr(rs.gs,4),color);
  535. SetColor(rs.ss,OldReg.ss);
  536. WriteStr(14,5,'SS '+HexStr(rs.ss,4),color);
  537. SetColor(rs.eflags and $1,OldReg.eflags and $1);
  538. WriteStr(22,0,'c='+chr(byte((rs.eflags and $1)<>0)+48),color);
  539. SetColor(rs.eflags and $20,OldReg.eflags and $20);
  540. WriteStr(22,1,'z='+chr(byte((rs.eflags and $20)<>0)+48),color);
  541. SetColor(rs.eflags and $80,OldReg.eflags and $80);
  542. WriteStr(22,2,'s='+chr(byte((rs.eflags and $80)<>0)+48),color);
  543. SetColor(rs.eflags and $800,OldReg.eflags and $800);
  544. WriteStr(22,3,'o='+chr(byte((rs.eflags and $800)<>0)+48),color);
  545. SetColor(rs.eflags and $4,OldReg.eflags and $4);
  546. WriteStr(22,4,'p='+chr(byte((rs.eflags and $4)<>0)+48),color);
  547. SetColor(rs.eflags and $200,OldReg.eflags and $200);
  548. WriteStr(22,5,'i='+chr(byte((rs.eflags and $200)<>0)+48),color);
  549. SetColor(rs.eflags and $10,OldReg.eflags and $10);
  550. WriteStr(22,6,'a='+chr(byte((rs.eflags and $10)<>0)+48),color);
  551. SetColor(rs.eflags and $400,OldReg.eflags and $400);
  552. WriteStr(22,7,'d='+chr(byte((rs.eflags and $400)<>0)+48),color);
  553. {$endif cpui386}
  554. {$ifdef cpum68k}
  555. SetColor(rs.d0,OldReg.d0);
  556. WriteStr(1,0,'d0 '+HexStr(longint(rs.d0),8),color);
  557. SetColor(rs.d1,OldReg.d1);
  558. WriteStr(1,1,'d1 '+HexStr(longint(rs.d1),8),color);
  559. SetColor(rs.d2,OldReg.d2);
  560. WriteStr(1,2,'d2 '+HexStr(longint(rs.d2),8),color);
  561. SetColor(rs.d3,OldReg.d3);
  562. WriteStr(1,3,'d3 '+HexStr(longint(rs.d3),8),color);
  563. SetColor(rs.d4,OldReg.d4);
  564. WriteStr(1,4,'d4 '+HexStr(longint(rs.d4),8),color);
  565. SetColor(rs.d5,OldReg.d5);
  566. WriteStr(1,5,'d5 '+HexStr(longint(rs.d5),8),color);
  567. SetColor(rs.d6,OldReg.d6);
  568. WriteStr(1,6,'d6 '+HexStr(longint(rs.d6),8),color);
  569. SetColor(rs.d7,OldReg.d7);
  570. WriteStr(1,7,'d7 '+HexStr(longint(rs.d7),8),color);
  571. SetColor(rs.a0,OldReg.a0);
  572. WriteStr(14,0,'a0 '+HexStr(longint(rs.a0),8),color);
  573. SetColor(rs.a1,OldReg.a1);
  574. WriteStr(14,1,'a1 '+HexStr(longint(rs.a1),8),color);
  575. SetColor(rs.a2,OldReg.a2);
  576. WriteStr(14,2,'a2 '+HexStr(longint(rs.a2),8),color);
  577. SetColor(rs.a3,OldReg.a3);
  578. WriteStr(14,3,'a3 '+HexStr(longint(rs.a3),8),color);
  579. SetColor(rs.a4,OldReg.a4);
  580. WriteStr(14,4,'a4 '+HexStr(longint(rs.a4),8),color);
  581. SetColor(rs.a5,OldReg.a5);
  582. WriteStr(14,5,'a5 '+HexStr(longint(rs.a5),8),color);
  583. SetColor(rs.fp,OldReg.fp);
  584. WriteStr(14,6,'fp '+HexStr(longint(rs.fp),8),color);
  585. SetColor(rs.sp,OldReg.sp);
  586. WriteStr(14,7,'sp '+HexStr(longint(rs.sp),8),color);
  587. SetColor(rs.pc,OldReg.pc);
  588. WriteStr(1,8,'pc '+HexStr(longint(rs.pc),8),color);
  589. SetColor(rs.ps and $1,OldReg.ps and $1);
  590. WriteStr(22,8,' c'+chr(byte((rs.ps and $1)<>0)+48),color);
  591. SetColor(rs.ps and $2,OldReg.ps and $2);
  592. WriteStr(19,8,' v'+chr(byte((rs.ps and $2)<>0)+48),color);
  593. SetColor(rs.ps and $4,OldReg.ps and $4);
  594. WriteStr(16,8,' z'+chr(byte((rs.ps and $4)<>0)+48),color);
  595. SetColor(rs.ps and $8,OldReg.ps and $8);
  596. WriteStr(14,8, 'x'+chr(byte((rs.ps and $8)<>0)+48),color);
  597. {$endif cpum68k}
  598. {$ifdef cpupowerpc}
  599. for i:=0 to 15 do
  600. begin
  601. SetColor(rs.r[i],OldReg.r[i]);
  602. if i<10 then
  603. WriteStr(1,i,'r'+IntToStr(i)+' '+HexStr(longint(rs.r[i]),8),color)
  604. else
  605. WriteStr(1,i,'r'+IntToStr(i)+' '+HexStr(longint(rs.r[i]),8),color);
  606. end;
  607. for i:=16 to 31 do
  608. begin
  609. SetColor(rs.r[i],OldReg.r[i]);
  610. WriteStr(15,i-16,'r'+IntToStr(i)+' '+HexStr(longint(rs.r[i]),8),color);
  611. end;
  612. { other regs pc,ps,cr,lr,ctr,xer : dword; }
  613. SetColor(rs.pc,OldReg.pc);
  614. WriteStr(1,16,'pc '+HexStr(longint(rs.pc),8),color);
  615. SetColor(rs.ps,OldReg.ps);
  616. WriteStr(15,16,'ps '+HexStr(longint(rs.ps),8),color);
  617. SetColor(rs.lr,OldReg.lr);
  618. WriteStr(1,17,'lr '+HexStr(longint(rs.lr),8),color);
  619. SetColor(rs.ctr,OldReg.ctr);
  620. WriteStr(15,17,'ctr '+HexStr(longint(rs.ctr),8),color);
  621. SetColor(rs.xer,OldReg.xer);
  622. WriteStr(15,18,'xer '+HexStr(longint(rs.xer),8),color);
  623. {$endif cpupowerpc}
  624. {$ifdef cpusparc}
  625. for i:=0 to 7 do
  626. begin
  627. SetColor(rs.g[i],OldReg.g[i]);
  628. WriteStr(1,i,'g'+IntToStr(i)+' '+HexStr(longint(rs.g[i]),8),color);
  629. SetColor(rs.l[i],OldReg.l[i]);
  630. WriteStr(1,i+8,'l'+IntToStr(i)+' '+HexStr(longint(rs.l[i]),8),color);
  631. end;
  632. for i:=0 to 7 do
  633. begin
  634. SetColor(rs.i[i],OldReg.i[i]);
  635. if i=6 then
  636. WriteStr(15,i,'fp '+HexStr(longint(rs.i[i]),8),color)
  637. else
  638. WriteStr(15,i,'i'+IntToStr(i)+' '+HexStr(longint(rs.i[i]),8),color);
  639. SetColor(rs.o[i],OldReg.o[i]);
  640. WriteStr(15,i+8,'o'+IntToStr(i)+' '+HexStr(longint(rs.o[i]),8),color);
  641. end;
  642. SetColor(rs.pc,OldReg.pc);
  643. WriteStr(1,16,'pc '+HexStr(longint(rs.pc),8),color);
  644. SetColor(rs.y,OldReg.y);
  645. WriteStr(1,17,'y '+HexStr(longint(rs.y),8),color);
  646. SetColor(rs.psr,OldReg.psr);
  647. WriteStr(1,18,'psr '+HexStr(longint(rs.psr),8),color);
  648. SetColor(rs.csr,OldReg.csr);
  649. WriteStr(1,19,'csr '+HexStr(longint(rs.csr),8),color);
  650. SetColor(rs.npc,OldReg.npc);
  651. WriteStr(15,16,'npc '+HexStr(longint(rs.npc),8),color);
  652. SetColor(rs.tbr,OldReg.tbr);
  653. WriteStr(15,17,'tbr '+HexStr(longint(rs.tbr),8),color);
  654. SetColor(rs.wim,OldReg.wim);
  655. WriteStr(15,18,'wim '+HexStr(longint(rs.wim),8),color);
  656. SetColor(rs.fsr,OldReg.fsr);
  657. WriteStr(15,19,'fsr '+HexStr(longint(rs.fsr),8),color);
  658. {$endif cpusparc}
  659. {$else cpu_known}
  660. for i:=0 to MaxRegs-1 do
  661. begin
  662. SetStrColor(rs.reg[i],OldReg.reg[i]);
  663. WriteStr(1,i,rs.reg[i],color);
  664. end;
  665. {$endif cpu_known}
  666. end
  667. else
  668. WriteStr(0,0,'<debugger error>',7);
  669. InDraw:=false;
  670. {$endif NODEBUG}
  671. end;
  672. destructor TRegistersView.Done;
  673. begin
  674. inherited done;
  675. end;
  676. {****************************************************************************
  677. TRegistersWindow
  678. ****************************************************************************}
  679. constructor TRegistersWindow.Init;
  680. var
  681. R : TRect;
  682. begin
  683. Desktop^.GetExtent(R);
  684. {$ifdef cpui386}
  685. R.A.X:=R.B.X-28;
  686. R.B.Y:=R.A.Y+11;
  687. {$endif cpui386}
  688. {$ifdef cpum68k}
  689. R.A.X:=R.B.X-28;
  690. R.B.Y:=R.A.Y+11;
  691. {$endif cpum68k}
  692. {$ifdef cpupowerpc}
  693. R.A.X:=R.B.X-28;
  694. R.B.Y:=R.A.Y+22;
  695. {$endif cpupowerpc}
  696. {$ifdef cpusparc}
  697. R.A.X:=R.B.X-30;
  698. R.B.Y:=R.A.Y+22;
  699. {$endif cpusparc}
  700. {$ifndef cpu_known}
  701. R.A.X:=R.B.X-28;
  702. R.B.Y:=R.A.Y+22;
  703. {$endif cpu_known}
  704. inherited Init(R,dialog_registers, wnNoNumber);
  705. Flags:=wfClose or wfMove;
  706. {$ifndef cpu_known}
  707. Flags:=Flags or wfgrow;
  708. {$endif cpu_known}
  709. Palette:=wpCyanWindow;
  710. HelpCtx:=hcRegistersWindow;
  711. R.Assign(1,1,Size.X-2,Size.Y-1);
  712. RV:=new(PRegistersView,init(R));
  713. Insert(RV);
  714. If assigned(RegistersWindow) then
  715. dispose(RegistersWindow,done);
  716. RegistersWindow:=@Self;
  717. Update;
  718. end;
  719. constructor TRegistersWindow.Load(var S: TStream);
  720. begin
  721. inherited load(S);
  722. GetSubViewPtr(S,RV);
  723. If assigned(RegistersWindow) then
  724. dispose(RegistersWindow,done);
  725. RegistersWindow:=@Self;
  726. end;
  727. procedure TRegistersWindow.Store(var S: TStream);
  728. begin
  729. inherited Store(s);
  730. PutSubViewPtr(S,RV);
  731. end;
  732. procedure TRegistersWindow.Update;
  733. begin
  734. ReDraw;
  735. end;
  736. destructor TRegistersWindow.Done;
  737. begin
  738. RegistersWindow:=nil;
  739. inherited done;
  740. end;
  741. {****************************************************************************
  742. TFPUView
  743. ****************************************************************************}
  744. function GetFPURegs(var rs : TFPURegs
  745. {$ifndef cpu_known}
  746. ; UseInfoFloat : boolean
  747. {$endif not cpu_known}
  748. ) : boolean;
  749. var
  750. p,po : pchar;
  751. p1 : pchar;
  752. {$ifndef NODEBUG}
  753. reg,value : string;
  754. buffer : array[0..255] of char;
  755. v : string;
  756. res : cardinal;
  757. i : longint;
  758. err : word;
  759. {$endif}
  760. begin
  761. GetFPURegs:=false;
  762. {$ifndef NODEBUG}
  763. {$ifndef cpu_known}
  764. if UseInfoFloat then
  765. begin
  766. Debugger^.Command('info float');
  767. if Debugger^.Error then
  768. begin
  769. UseInfofloat:=false;
  770. Debugger^.Command('info all');
  771. end;
  772. end
  773. else
  774. {$endif not cpu_known}
  775. Debugger^.Command('info all');
  776. if Debugger^.Error then
  777. exit
  778. else
  779. begin
  780. po:=StrNew(Debugger^.GetOutput);
  781. p:=po;
  782. {$ifndef cpu_known}
  783. i:=0;
  784. {$endif not cpu_known}
  785. if assigned(p) then
  786. begin
  787. fillchar(rs,sizeof(rs),0);
  788. p1:=strscan(p,' ');
  789. while assigned(p1) do
  790. begin
  791. strlcopy(buffer,p,p1-p);
  792. reg:=strpas(buffer);
  793. {$ifndef cpu_known}
  794. p1:=strscan(p,#10);
  795. if assigned(p1) then
  796. begin
  797. strlcopy(buffer,p,p1-p);
  798. rs.freg[i]:=ExtractTabs(strpas(buffer),8);
  799. if i<MaxRegs-1 then
  800. inc(i);
  801. end;
  802. {$else cpu_known}
  803. p:=p1;
  804. while p^=' ' do
  805. inc(p);
  806. if p^='$' then
  807. p1:=strscan(p,#9)
  808. else
  809. p1:=strscan(p,#10);
  810. strlcopy(buffer,p,p1-p);
  811. v:=strpas(buffer);
  812. for i:=1 to length(v) do
  813. if v[i]=#9 then
  814. v[i]:=' ';
  815. val(v,res,err);
  816. {$ifdef cpui386}
  817. if reg='st0' then
  818. rs.st0:=v
  819. else if reg='st1' then
  820. rs.st1:=v
  821. else if reg='st2' then
  822. rs.st2:=v
  823. else if reg='st3' then
  824. rs.st3:=v
  825. else if reg='st4' then
  826. rs.st4:=v
  827. else if reg='st5' then
  828. rs.st5:=v
  829. else if reg='st6' then
  830. rs.st6:=v
  831. else if reg='st7' then
  832. rs.st7:=v
  833. else if reg='ftag' then
  834. rs.ftag:=res
  835. else if reg='fctrl' then
  836. rs.fctrl:=res
  837. else if reg='fstat' then
  838. rs.fstat:=res
  839. else if reg='fiseg' then
  840. rs.fiseg:=res
  841. else if reg='fioff' then
  842. rs.fioff:=res
  843. else if reg='foseg' then
  844. rs.foseg:=res
  845. else if reg='fooff' then
  846. rs.fooff:=res
  847. else if reg='fop' then
  848. rs.fop:=res;
  849. {$endif cpui386}
  850. {$ifdef cpum68k}
  851. if reg='fp0' then
  852. rs.fp0:=v
  853. else if reg='fp1' then
  854. rs.fp1:=v
  855. else if reg='fp2' then
  856. rs.fp2:=v
  857. else if reg='fp3' then
  858. rs.fp3:=v
  859. else if reg='fp4' then
  860. rs.fp4:=v
  861. else if reg='fp5' then
  862. rs.fp5:=v
  863. else if reg='fp6' then
  864. rs.fp6:=v
  865. else if reg='fp7' then
  866. rs.fp7:=v
  867. else if reg='fpcontrol' then
  868. rs.fpcontrol:=res
  869. else if reg='fpstatus' then
  870. rs.fpstatus:=res
  871. else if reg='fpiaddr' then
  872. rs.fpiaddr:=res;
  873. {$endif cpum68k}
  874. {$ifdef cpupowerpc}
  875. if reg[1]='f' then
  876. for i:=0 to 31 do
  877. if reg='f'+inttostr(i) then
  878. rs.f[i]:=v;
  879. {$endif cpupowerpc}
  880. {$ifdef cpusparc}
  881. if reg[1]='f' then
  882. for i:=0 to 31 do
  883. if reg='f'+inttostr(i) then
  884. rs.f[i]:=v;
  885. {$endif cpusparc}
  886. {$endif cpu_known}
  887. p:=strscan(p1,#10);
  888. if assigned(p) then
  889. begin
  890. p1:=strscan(p,' ');
  891. inc(p);
  892. end
  893. else
  894. break;
  895. end;
  896. { free allocated memory }
  897. strdispose(po);
  898. end
  899. else
  900. exit;
  901. end;
  902. { do not open a messagebox for such errors }
  903. Debugger^.got_error:=false;
  904. GetFPURegs:=true;
  905. {$endif}
  906. end;
  907. constructor TFPUView.Init(var Bounds: TRect);
  908. begin
  909. inherited init(Bounds);
  910. GrowMode:=gfGrowHiX or GfGrowHiY;
  911. InDraw:=false;
  912. first:=true;
  913. FillChar(OldReg,Sizeof(oldreg),#0);
  914. FillChar(NewReg,Sizeof(newreg),#0);
  915. GDBCount:=-1;
  916. {$ifndef cpu_known}
  917. UseInfoFloat:=true;
  918. {$endif not cpu_known}
  919. end;
  920. procedure TFPUView.Draw;
  921. var
  922. rs : tfpuregs;
  923. top : byte;
  924. color :byte;
  925. ok : boolean;
  926. i : byte;
  927. const
  928. TypeStr : Array[0..3] of string[6] =
  929. ('Valid ','Zero ','Spec ','Empty ');
  930. procedure SetColor(Const x,y : string);
  931. begin
  932. if x=y then
  933. color:=7
  934. else
  935. color:=8;
  936. end;
  937. procedure SetIColor(Const x,y : cardinal);
  938. begin
  939. if x=y then
  940. color:=7
  941. else
  942. color:=8;
  943. end;
  944. begin
  945. inherited draw;
  946. {$ifdef NODEBUG}
  947. WriteStr(1,0,'<no values available>',7);
  948. {$else NODEBUG}
  949. If not assigned(Debugger) then
  950. begin
  951. WriteStr(1,0,'<no values available>',7);
  952. exit;
  953. end;
  954. if InDraw then
  955. exit;
  956. InDraw:=true;
  957. if GDBCount<>Debugger^.RunCount then
  958. begin
  959. OldReg:=NewReg;
  960. OK:=GetFPURegs(rs
  961. {$ifndef cpu_known}
  962. ,UseInfoFloat
  963. {$endif not cpu_known}
  964. );
  965. NewReg:=rs;
  966. { get inital values }
  967. if first then
  968. begin
  969. OldReg:=NewReg;
  970. first:=false;
  971. end;
  972. GDBCount:=Debugger^.RunCount;
  973. end
  974. else
  975. begin
  976. rs:=newreg;
  977. OK:=true;
  978. end;
  979. if OK then
  980. begin
  981. {$ifdef cpu_known}
  982. {$ifdef cpui386}
  983. top:=(rs.fstat shr 11) and 7;
  984. SetColor(rs.st0,OldReg.st0);
  985. WriteStr(1,0,'ST0 '+TypeStr[(rs.ftag shr (2*((0+top) and 7))) and 3]+rs.st0,color);
  986. SetColor(rs.st1,OldReg.st1);
  987. WriteStr(1,1,'ST1 '+TypeStr[(rs.ftag shr (2*((1+top) and 7))) and 3]+rs.st1,color);
  988. SetColor(rs.st2,OldReg.st2);
  989. WriteStr(1,2,'ST2 '+TypeStr[(rs.ftag shr (2*((2+top) and 7))) and 3]+rs.st2,color);
  990. SetColor(rs.st3,OldReg.st3);
  991. WriteStr(1,3,'ST3 '+TypeStr[(rs.ftag shr (2*((3+top) and 7))) and 3]+rs.st3,color);
  992. SetColor(rs.st4,OldReg.st4);
  993. WriteStr(1,4,'ST4 '+TypeStr[(rs.ftag shr (2*((4+top) and 7))) and 3]+rs.st4,color);
  994. SetColor(rs.st5,OldReg.st5);
  995. WriteStr(1,5,'ST5 '+TypeStr[(rs.ftag shr (2*((5+top) and 7))) and 3]+rs.st5,color);
  996. SetColor(rs.st6,OldReg.st6);
  997. WriteStr(1,6,'ST6 '+TypeStr[(rs.ftag shr (2*((6+top) and 7))) and 3]+rs.st6,color);
  998. SetColor(rs.st7,OldReg.st7);
  999. WriteStr(1,7,'ST7 '+TypeStr[(rs.ftag shr (2*((7+top) and 7))) and 3]+rs.st7,color);
  1000. SetIColor(rs.ftag,OldReg.ftag);
  1001. WriteStr(1,8,'FTAG '+hexstr(rs.ftag,4),color);
  1002. SetIColor(rs.fctrl,OldReg.fctrl);
  1003. WriteStr(13,8,'FCTRL '+hexstr(rs.fctrl,4),color);
  1004. SetIColor(rs.fstat,OldReg.fstat);
  1005. WriteStr(1,9,'FSTAT '+hexstr(rs.fstat,4),color);
  1006. SetIColor(rs.fop,OldReg.fop);
  1007. WriteStr(13,9,'FOP '+hexstr(rs.fop,4),color);
  1008. if (rs.fiseg<>OldReg.fiseg) or
  1009. (rs.fioff<>OldReg.fioff) then
  1010. color:=8
  1011. else
  1012. color:=7;
  1013. WriteStr(1,10,'FI '+hexstr(rs.fiseg,4)+':'+hexstr(rs.fioff,8),color);
  1014. if (rs.foseg<>OldReg.foseg) or
  1015. (rs.fooff<>OldReg.fooff) then
  1016. color:=8
  1017. else
  1018. color:=7;
  1019. WriteStr(1,11,'FO '+hexstr(rs.foseg,4)+':'+hexstr(rs.fooff,8),color);
  1020. {$endif cpui386}
  1021. {$ifdef cpum68k}
  1022. SetColor(rs.fp0,OldReg.fp0);
  1023. WriteStr(1,0,'fp0 '+rs.fp0,color);
  1024. SetColor(rs.fp1,OldReg.fp1);
  1025. WriteStr(1,1,'fp1 '+rs.fp1,color);
  1026. SetColor(rs.fp2,OldReg.fp2);
  1027. WriteStr(1,2,'fp2 '+rs.fp2,color);
  1028. SetColor(rs.fp3,OldReg.fp3);
  1029. WriteStr(1,3,'fp3 '+rs.fp3,color);
  1030. SetColor(rs.fp4,OldReg.fp4);
  1031. WriteStr(1,4,'fp4 '+rs.fp4,color);
  1032. SetColor(rs.fp5,OldReg.fp5);
  1033. WriteStr(1,5,'fp5 '+rs.fp5,color);
  1034. SetColor(rs.fp6,OldReg.fp6);
  1035. WriteStr(1,6,'fp6 '+rs.fp6,color);
  1036. SetColor(rs.fp7,OldReg.fp7);
  1037. WriteStr(1,7,'fp7 '+rs.fp7,color);
  1038. SetIColor(rs.fpcontrol,OldReg.fpcontrol);
  1039. WriteStr(1,8,'fpcontrol '+hexstr(rs.fpcontrol,8),color);
  1040. SetIColor(rs.fpstatus,OldReg.fpstatus);
  1041. WriteStr(1,9,'fpstatus '+hexstr(rs.fpstatus,8),color);
  1042. SetIColor(rs.fpiaddr,OldReg.fpiaddr);
  1043. WriteStr(1,10,'fpiaddr '+hexstr(rs.fpiaddr,8),color);
  1044. {$endif cpum68k}
  1045. {$ifdef cpupowerpc}
  1046. for i:=0 to 31 do
  1047. begin
  1048. SetColor(rs.f[i],OldReg.f[i]);
  1049. if i<10 then
  1050. WriteStr(1,i,'f'+IntToStr(i)+' '+rs.f[i],color)
  1051. else
  1052. WriteStr(1,i,'f'+IntToStr(i)+' '+rs.f[i],color);
  1053. end;
  1054. {$endif cpupowerpc}
  1055. {$ifdef cpusparc}
  1056. for i:=0 to 31 do
  1057. begin
  1058. SetColor(rs.f[i],OldReg.f[i]);
  1059. if i<10 then
  1060. WriteStr(1,i,'f'+IntToStr(i)+' '+rs.f[i],color)
  1061. else
  1062. WriteStr(1,i,'f'+IntToStr(i)+' '+rs.f[i],color);
  1063. end;
  1064. {$endif cpusparc}
  1065. {$else not cpu_known}
  1066. for i:=0 to MaxRegs-1 do
  1067. begin
  1068. SetColor(rs.freg[i],OldReg.freg[i]);
  1069. WriteStr(1,i,rs.freg[i],color);
  1070. end;
  1071. {$endif cpu_known}
  1072. end
  1073. else
  1074. WriteStr(0,0,'<debugger error>',7);
  1075. InDraw:=false;
  1076. {$endif NODEBUG}
  1077. end;
  1078. destructor TFPUView.Done;
  1079. begin
  1080. inherited done;
  1081. end;
  1082. {****************************************************************************
  1083. TFPUWindow
  1084. ****************************************************************************}
  1085. constructor TFPUWindow.Init;
  1086. var
  1087. R : TRect;
  1088. begin
  1089. Desktop^.GetExtent(R);
  1090. {$ifdef cpui386}
  1091. R.A.X:=R.B.X-44;
  1092. R.B.Y:=R.A.Y+14;
  1093. {$endif cpui386}
  1094. {$ifdef cpum68k}
  1095. R.A.X:=R.B.X-44;
  1096. R.B.Y:=R.A.Y+14;
  1097. {$endif cpum68k}
  1098. {$ifdef cpupowerpc}
  1099. R.A.X:=R.B.X-44;
  1100. R.B.Y:=R.A.Y+33;
  1101. {$endif cpupowerpc}
  1102. {$ifdef cpusparc}
  1103. R.A.X:=R.B.X-44;
  1104. R.B.Y:=R.A.Y+33;
  1105. {$endif cpusparc}
  1106. {$ifndef cpu_known}
  1107. R.A.X:=R.B.X-44;
  1108. R.B.Y:=R.A.Y+33;
  1109. {$endif cpu_known}
  1110. inherited Init(R,dialog_fpu, wnNoNumber);
  1111. Flags:=wfClose or wfMove or wfgrow;
  1112. Palette:=wpCyanWindow;
  1113. HelpCtx:=hcFPURegisters;
  1114. R.Assign(1,1,Size.X-2,Size.Y-2);
  1115. RV:=new(PFPUView,init(R));
  1116. Insert(RV);
  1117. If assigned(FPUWindow) then
  1118. dispose(FPUWindow,done);
  1119. FPUWindow:=@Self;
  1120. Update;
  1121. end;
  1122. constructor TFPUWindow.Load(var S: TStream);
  1123. begin
  1124. inherited load(S);
  1125. GetSubViewPtr(S,RV);
  1126. If assigned(FPUWindow) then
  1127. dispose(FPUWindow,done);
  1128. FPUWindow:=@Self;
  1129. end;
  1130. procedure TFPUWindow.Store(var S: TStream);
  1131. begin
  1132. inherited Store(s);
  1133. PutSubViewPtr(S,RV);
  1134. end;
  1135. procedure TFPUWindow.Update;
  1136. begin
  1137. ReDraw;
  1138. end;
  1139. destructor TFPUWindow.Done;
  1140. begin
  1141. FPUWindow:=nil;
  1142. inherited done;
  1143. end;
  1144. {****************************************************************************
  1145. TVectorView
  1146. ****************************************************************************}
  1147. function GetVectorRegs(var rs : TVectorRegs
  1148. {$ifndef cpu_known}
  1149. ; UseInfoFloat : boolean
  1150. {$endif not cpu_known}
  1151. ) : boolean;
  1152. var
  1153. p,po : pchar;
  1154. p1 : pchar;
  1155. {$ifndef NODEBUG}
  1156. reg,value : string;
  1157. buffer : array[0..255] of char;
  1158. v : string;
  1159. res : cardinal;
  1160. i : longint;
  1161. err : word;
  1162. {$endif}
  1163. begin
  1164. GetVectorRegs:=false;
  1165. {$ifndef NODEBUG}
  1166. {$ifndef cpu_known}
  1167. if UseInfoFloat then
  1168. begin
  1169. Debugger^.Command('info vector');
  1170. if Debugger^.Error then
  1171. begin
  1172. UseInfofloat:=false;
  1173. Debugger^.Command('info all');
  1174. end;
  1175. end
  1176. else
  1177. {$endif not cpu_known}
  1178. Debugger^.Command('info vector');
  1179. if Debugger^.Error then
  1180. exit
  1181. else
  1182. begin
  1183. po:=StrNew(Debugger^.GetOutput);
  1184. p:=po;
  1185. {$ifndef cpu_known}
  1186. i:=0;
  1187. {$endif not cpu_known}
  1188. if assigned(p) then
  1189. begin
  1190. fillchar(rs,sizeof(rs),0);
  1191. p1:=strscan(p,' ');
  1192. while assigned(p1) do
  1193. begin
  1194. strlcopy(buffer,p,p1-p);
  1195. reg:=strpas(buffer);
  1196. {$ifndef cpu_known}
  1197. p1:=strscan(p,#10);
  1198. if assigned(p1) then
  1199. begin
  1200. strlcopy(buffer,p,p1-p);
  1201. rs.freg[i]:=ExtractTabs(strpas(buffer),8);
  1202. if i<MaxRegs-1 then
  1203. inc(i);
  1204. end;
  1205. {$else cpu_known}
  1206. p:=p1;
  1207. while p^=' ' do
  1208. inc(p);
  1209. if p^='$' then
  1210. p1:=strscan(p,#9)
  1211. else
  1212. p1:=strscan(p,#10);
  1213. strlcopy(buffer,p,p1-p);
  1214. v:=strpas(buffer);
  1215. for i:=1 to length(v) do
  1216. if v[i]=#9 then
  1217. v[i]:=' ';
  1218. val(v,res,err);
  1219. {$ifdef cpui386}
  1220. if reg[1]='x' then
  1221. for i:=0 to 7 do
  1222. begin
  1223. if reg='xmm'+inttostr(i) then
  1224. rs.xmm[i]:=v
  1225. end
  1226. else if reg='mxcsr' then
  1227. rs.mxcsr:=v
  1228. else if reg[1]='m' then
  1229. for i:=0 to 7 do
  1230. begin
  1231. if reg='mm'+inttostr(i) then
  1232. rs.mmx[i]:=v;
  1233. end;
  1234. {$endif cpui386}
  1235. {$ifdef cpupowerpc}
  1236. { !!!! fixme }
  1237. if reg[1]='v' then
  1238. for i:=0 to 31 do
  1239. if reg='v'+inttostr(i) then
  1240. rs.m[i]:=v;
  1241. {$endif cpupowerpc}
  1242. {$ifdef cpusparc}
  1243. {$endif cpusparc}
  1244. {$endif cpu_known}
  1245. p:=strscan(p1,#10);
  1246. if assigned(p) then
  1247. begin
  1248. p1:=strscan(p,' ');
  1249. inc(p);
  1250. end
  1251. else
  1252. break;
  1253. end;
  1254. { free allocated memory }
  1255. strdispose(po);
  1256. end
  1257. else
  1258. exit;
  1259. end;
  1260. { do not open a messagebox for such errors }
  1261. Debugger^.got_error:=false;
  1262. GetVectorRegs:=true;
  1263. {$endif}
  1264. end;
  1265. constructor TVectorView.Init(var Bounds: TRect);
  1266. begin
  1267. inherited init(Bounds);
  1268. GrowMode:=gfGrowHiX or GfGrowHiY;
  1269. InDraw:=false;
  1270. first:=true;
  1271. FillChar(OldReg,Sizeof(oldreg),#0);
  1272. FillChar(NewReg,Sizeof(newreg),#0);
  1273. GDBCount:=-1;
  1274. {$ifndef cpu_known}
  1275. UseInfoFloat:=true;
  1276. {$endif not cpu_known}
  1277. end;
  1278. procedure TVectorView.Draw;
  1279. var
  1280. rs : tVectorregs;
  1281. top : byte;
  1282. color :byte;
  1283. ok : boolean;
  1284. i : byte;
  1285. const
  1286. TypeStr : Array[0..3] of string[6] =
  1287. ('Valid ','Zero ','Spec ','Empty ');
  1288. procedure SetColor(Const x,y : string);
  1289. begin
  1290. if x=y then
  1291. color:=7
  1292. else
  1293. color:=8;
  1294. end;
  1295. procedure SetIColor(Const x,y : cardinal);
  1296. begin
  1297. if x=y then
  1298. color:=7
  1299. else
  1300. color:=8;
  1301. end;
  1302. begin
  1303. inherited draw;
  1304. {$ifdef NODEBUG}
  1305. WriteStr(1,0,'<no values available>',7);
  1306. {$else NODEBUG}
  1307. If not assigned(Debugger) then
  1308. begin
  1309. WriteStr(1,0,'<no values available>',7);
  1310. exit;
  1311. end;
  1312. if InDraw then
  1313. exit;
  1314. InDraw:=true;
  1315. if GDBCount<>Debugger^.RunCount then
  1316. begin
  1317. OldReg:=NewReg;
  1318. OK:=GetVectorRegs(rs
  1319. {$ifndef cpu_known}
  1320. ,UseInfoFloat
  1321. {$endif not cpu_known}
  1322. );
  1323. NewReg:=rs;
  1324. { get inital values }
  1325. if first then
  1326. begin
  1327. OldReg:=NewReg;
  1328. first:=false;
  1329. end;
  1330. GDBCount:=Debugger^.RunCount;
  1331. end
  1332. else
  1333. begin
  1334. rs:=newreg;
  1335. OK:=true;
  1336. end;
  1337. if OK then
  1338. begin
  1339. {$ifdef cpu_known}
  1340. {$ifdef cpui386}
  1341. for i:=0 to 7 do
  1342. begin
  1343. SetColor(rs.xmm[i],OldReg.xmm[i]);
  1344. WriteStr(1,i,'xmm'+IntToStr(i)+' '+rs.xmm[i],color);
  1345. end;
  1346. SetColor(rs.mxcsr,OldReg.mxcsr);
  1347. WriteStr(1,i,'mxcsr'+IntToStr(i)+' '+rs.mxcsr,color);
  1348. for i:=0 to 7 do
  1349. begin
  1350. SetColor(rs.mmx[i],OldReg.mmx[i]);
  1351. WriteStr(1,i+8,'mmx'+IntToStr(i)+' '+rs.mmx[i],color);
  1352. end;
  1353. {$endif cpui386}
  1354. {$ifdef cpupowerpc}
  1355. for i:=0 to 31 do
  1356. begin
  1357. SetColor(rs.m[i],OldReg.m[i]);
  1358. if i<10 then
  1359. WriteStr(1,i,'m'+IntToStr(i)+' '+rs.m[i],color)
  1360. else
  1361. WriteStr(1,i,'m'+IntToStr(i)+' '+rs.m[i],color);
  1362. end;
  1363. {$endif cpupowerpc}
  1364. {$ifdef cpusparc}
  1365. { no mm regs on the sparc }
  1366. {$endif cpusparc}
  1367. {$else not cpu_known}
  1368. for i:=0 to MaxRegs-1 do
  1369. begin
  1370. SetColor(rs.freg[i],OldReg.freg[i]);
  1371. WriteStr(1,i,rs.freg[i],color);
  1372. end;
  1373. {$endif cpu_known}
  1374. end
  1375. else
  1376. WriteStr(0,0,'<debugger error>',7);
  1377. InDraw:=false;
  1378. {$endif NODEBUG}
  1379. end;
  1380. destructor TVectorView.Done;
  1381. begin
  1382. inherited done;
  1383. end;
  1384. {****************************************************************************
  1385. TVectorWindow
  1386. ****************************************************************************}
  1387. constructor TVectorWindow.Init;
  1388. var
  1389. R : TRect;
  1390. begin
  1391. Desktop^.GetExtent(R);
  1392. {$ifdef cpui386}
  1393. R.A.X:=R.B.X-60;
  1394. R.B.Y:=R.A.Y+19;
  1395. {$endif cpui386}
  1396. {$ifdef cpum68k}
  1397. R.A.X:=R.B.X-60;
  1398. R.B.Y:=R.A.Y+14;
  1399. {$endif cpum68k}
  1400. {$ifdef cpupowerpc}
  1401. R.A.X:=R.B.X-60;
  1402. R.B.Y:=R.A.Y+33;
  1403. {$endif cpupowerpc}
  1404. {$ifdef cpusparc}
  1405. R.A.X:=R.B.X-60;
  1406. R.B.Y:=R.A.Y+33;
  1407. {$endif cpusparc}
  1408. {$ifndef cpu_known}
  1409. R.A.X:=R.B.X-60;
  1410. R.B.Y:=R.A.Y+33;
  1411. {$endif cpu_known}
  1412. inherited Init(R,dialog_Vector, wnNoNumber);
  1413. Flags:=wfClose or wfMove or wfgrow;
  1414. Palette:=wpCyanWindow;
  1415. HelpCtx:=hcVectorRegisters;
  1416. R.Assign(1,1,Size.X-2,Size.Y-2);
  1417. RV:=new(PVectorView,init(R));
  1418. Insert(RV);
  1419. If assigned(VectorWindow) then
  1420. dispose(VectorWindow,done);
  1421. VectorWindow:=@Self;
  1422. Update;
  1423. end;
  1424. constructor TVectorWindow.Load(var S: TStream);
  1425. begin
  1426. inherited load(S);
  1427. GetSubViewPtr(S,RV);
  1428. If assigned(VectorWindow) then
  1429. dispose(VectorWindow,done);
  1430. VectorWindow:=@Self;
  1431. end;
  1432. procedure TVectorWindow.Store(var S: TStream);
  1433. begin
  1434. inherited Store(s);
  1435. PutSubViewPtr(S,RV);
  1436. end;
  1437. procedure TVectorWindow.Update;
  1438. begin
  1439. ReDraw;
  1440. end;
  1441. destructor TVectorWindow.Done;
  1442. begin
  1443. VectorWindow:=nil;
  1444. inherited done;
  1445. end;
  1446. procedure InitRegistersWindow;
  1447. begin
  1448. if RegistersWindow=nil then
  1449. begin
  1450. new(RegistersWindow,init);
  1451. DeskTop^.Insert(RegistersWindow);
  1452. end;
  1453. end;
  1454. procedure DoneRegistersWindow;
  1455. begin
  1456. if assigned(RegistersWindow) then
  1457. begin
  1458. DeskTop^.Delete(RegistersWindow);
  1459. RegistersWindow:=nil;
  1460. end;
  1461. end;
  1462. procedure InitFPUWindow;
  1463. begin
  1464. if FPUWindow=nil then
  1465. begin
  1466. new(FPUWindow,init);
  1467. DeskTop^.Insert(FPUWindow);
  1468. end;
  1469. end;
  1470. procedure DoneFPUWindow;
  1471. begin
  1472. if assigned(FPUWindow) then
  1473. begin
  1474. DeskTop^.Delete(FPUWindow);
  1475. FPUWindow:=nil;
  1476. end;
  1477. end;
  1478. procedure InitVectorWindow;
  1479. begin
  1480. if VectorWindow=nil then
  1481. begin
  1482. new(VectorWindow,init);
  1483. DeskTop^.Insert(VectorWindow);
  1484. end;
  1485. end;
  1486. procedure DoneVectorWindow;
  1487. begin
  1488. if assigned(VectorWindow) then
  1489. begin
  1490. DeskTop^.Delete(VectorWindow);
  1491. VectorWindow:=nil;
  1492. end;
  1493. end;
  1494. procedure RegisterFPRegsViews;
  1495. begin
  1496. RegisterType(RRegistersWindow);
  1497. RegisterType(RRegistersView);
  1498. RegisterType(RFPUWindow);
  1499. RegisterType(RFPUView);
  1500. RegisterType(RVectorView);
  1501. end;
  1502. end.
  1503. {$endif}
  1504. {
  1505. $Log$
  1506. Revision 1.9 2005-01-16 00:26:43 florian
  1507. + all sparc registers are displayed now
  1508. + more sophisticated coloring of changed registers
  1509. Revision 1.8 2005/01/12 21:48:31 florian
  1510. + register view for sparc
  1511. Revision 1.7 2005/01/10 20:52:11 florian
  1512. * compilation fixed
  1513. Revision 1.6 2005/01/08 11:43:18 florian
  1514. + vector unit window
  1515. Revision 1.5 2004/12/22 15:24:07 peter
  1516. * fixed NODEBUG
  1517. * set default target to the default target of the compiler
  1518. Revision 1.4 2004/11/11 15:20:52 florian
  1519. * applied Peter's patch from yesterday
  1520. Revision 1.3 2004/02/06 21:34:43 jonas
  1521. * fixed ppc compilation error
  1522. Revision 1.2 2002/12/16 15:51:13 pierre
  1523. * added unknown cpu register windows
  1524. Revision 1.1 2002/12/12 00:01:59 pierre
  1525. Register window code separated in a new unit
  1526. }