cpubase.pas 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Contains the base types for the SPARC
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { This Unit contains the base types for the PowerPC
  19. }
  20. unit cpubase;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. strings,cutils,cclasses,aasmbase,cpuinfo,cginfo;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. {$WARNING CPU32 opcodes do not fully include the Ultra SPRAC instruction set.}
  30. { don't change the order of these opcodes! }
  31. TAsmOp=({$INCLUDE opcode.inc});
  32. {# This should define the array of instructions as string }
  33. op2strtable=array[tasmop] of string[11];
  34. Const
  35. {# First value of opcode enumeration }
  36. firstop = low(tasmop);
  37. {# Last value of opcode enumeration }
  38. lastop = high(tasmop);
  39. std_op2str:op2strtable=({$INCLUDE strinst.inc});
  40. {*****************************************************************************
  41. Registers
  42. *****************************************************************************}
  43. type
  44. TCpuRegister=(
  45. R_NO
  46. {General purpose global registers}
  47. ,R_G0{This register is usually set to zero and used as a scratch register}
  48. ,R_G1,R_G2,R_G3,R_G4,R_G5,R_G6,R_G7
  49. {General purpose out registers}
  50. ,R_O0,R_O1,R_O2,R_O3,R_O4,R_O5,R_O6
  51. ,R_O7{This register is used to save the address of the last CALL instruction}
  52. {General purpose local registers}
  53. ,R_L0
  54. ,R_L1{This register is used to save the Program Counter (PC) after a Trap}
  55. ,R_L2{This register is used to save the Program Counter (nPC) after a Trap}
  56. ,R_L3,R_L4,R_L5,R_L6,R_L7
  57. {General purpose in registers}
  58. ,R_I0,R_I1,R_I2,R_I3,R_I4,R_I5,R_I6,R_I7
  59. {Floating point registers}
  60. ,R_F0,R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7
  61. ,R_F8,R_F9,R_F10,R_F11,R_F12,R_F13,R_F14,R_F15
  62. ,R_F16,R_F17,R_F18,R_F19,R_F20,R_F21,R_F22,R_F23
  63. ,R_F24,R_F25,R_F26,R_F27,R_F28,R_F29,R_F30,R_F31
  64. {Floating point status/"front of queue" registers}
  65. ,R_FSR,R_FQ
  66. {Coprocessor registers}
  67. ,R_C0,R_C1,R_C2,R_C3,R_C4,R_C5,R_C6,R_C7
  68. ,R_C8,R_C9,R_C10,R_C11,R_C12,R_C13,R_C14,R_C15
  69. ,R_C16,R_C17,R_C18,R_C19,R_C20,R_C21,R_C22,R_C23
  70. ,R_C24,R_C25,R_C26,R_C27,R_C28,R_C29,R_C30,R_C31
  71. {Coprocessor status/queue registers}
  72. ,R_CSR
  73. ,R_CQ
  74. {Integer Unit control & status registers}
  75. ,R_PSR{Processor Status Register : informs upon the program status}
  76. ,R_TBR{Trap Base Register : saves the Trap vactor base address}
  77. ,R_WIM{Window Invalid Mask : }
  78. ,R_Y{Multiply/Devide Register : }
  79. {Ancillary State Registers : these are implementation dependent registers and
  80. thus, are not specified by the SPARC Reference Manual. I did choose the SUN's
  81. implementation according to the Assembler Refernce Manual.(MN)}
  82. ,R_ASR0,R_ASR1,R_ASR2,R_ASR3,R_ASR4,R_ASR5,R_ASR6,R_ASR7
  83. ,R_ASR8,R_ASR9,R_ASR10,R_ASR11,R_ASR12,R_ASR13,R_ASR14,R_ASR15
  84. ,R_ASR16,R_ASR17,R_ASR18,R_ASR19,R_ASR20,R_ASR21,R_ASR22,R_ASR23
  85. ,R_ASR24,R_ASR25,R_ASR26,R_ASR27,R_ASR28,R_ASR29,R_ASR30,R_ASR31
  86. {The following registers are just used with the new register allocator}
  87. ,R_INTREGISTER,R_FLOATREGISTER,R_MMXREGISTER,R_KNIREGISTER
  88. );
  89. TOldRegister=TCpuRegister;
  90. Tnewregister=word;
  91. Tsuperregister=byte;
  92. Tsubregister=byte;
  93. Tregister=record
  94. enum:Toldregister;
  95. number:Tnewregister;
  96. end;
  97. {# Set type definition for registers }
  98. tregisterset = set of Toldregister;
  99. Tsupregset=set of Tsuperregister;
  100. { A type to store register locations for 64 Bit values. }
  101. tregister64 = packed record
  102. reglo,reghi : tregister;
  103. end;
  104. { alias for compact code }
  105. treg64 = tregister64;
  106. Const
  107. {# First register in the tregister enumeration }
  108. firstreg = low(Toldregister);
  109. {# Last register in the tregister enumeration }
  110. lastreg = R_ASR31;
  111. type
  112. {# Type definition for the array of string of register nnames }
  113. treg2strtable = array[firstreg..lastreg] of string[7];
  114. const
  115. std_reg2str:treg2strtable=(
  116. '',
  117. {general purpose global registers}
  118. '%g0','%g1','%g2','%g3','%g4','%g5','%g6','%g7',
  119. {general purpose out registers}
  120. '%o0','%o1','%o2','%o3','%o4','%o5','%o6','%o7',
  121. {general purpose local registers}
  122. '%l0','%l1','%l2','%l3','%l4','%l5','%l6','%l7',
  123. {general purpose in registers}
  124. '%i0','%i1','%i2','%i3','%i4','%i5','%i6','%i7',
  125. {floating point registers}
  126. '%f0','%f1','%f2','%f3','%f4','%f5','%f6','%f7',
  127. '%f8','%f9','%f10','%f11','%f12','%f13','%f14','%f15',
  128. '%f16','%f17','%f18','%f19','%f20','%f21','%f22','%f23',
  129. '%f24','%f25','%f26','%f27','%f28','%f29','%f30','%f31',
  130. {floating point status/"front of queue" registers}
  131. '%fSR','%fQ',
  132. {coprocessor registers}
  133. '%c0','%c1','%c2','%c3','%c4','%c5','%c6','%c7',
  134. '%c8','%c9','%c10','%c11','%c12','%c13','%c14','%c15',
  135. '%c16','%c17','%c18','%c19','%c20','%c21','%c22','%c23',
  136. '%c24','%c25','%c26','%c27','%c28','%c29','%c30','%c31',
  137. {coprocessor status/queue registers}
  138. '%csr','%cq',
  139. {"Program status"/"Trap vactor base address register"/"Window invalid mask"/Y registers}
  140. '%psr','%tbr','%wim','%y',
  141. {Ancillary state registers}
  142. '%asr0','%asr1','%asr2','%asr3','%asr4','%asr5','%asr6','%asr7',
  143. '%asr8','%asr9','%asr10','%asr11','%asr12','%asr13','%asr14','%asr15',
  144. '%asr16','%asr17','%asr18','%asr19','%asr20','%asr21','%asr22','%asr23',
  145. '%asr24','%asr25','%asr26','%asr27','%asr28','%asr29','%asr30','%asr31'
  146. );
  147. {New register coding:}
  148. {Special registers:}
  149. const
  150. NR_NO=$0000; {Invalid register}
  151. {Normal registers:}
  152. {General purpose registers:}
  153. NR_G0=$0100;
  154. NR_G1=$0200;
  155. NR_G2=$0300;
  156. NR_G3=$0400;
  157. NR_G4=$0500;
  158. NR_G5=$0600;
  159. NR_G6=$0700;
  160. NR_G7=$0800;
  161. NR_O0=$0900;
  162. NR_O1=$0a00;
  163. NR_O2=$0b00;
  164. NR_O3=$0c00;
  165. NR_O4=$0d00;
  166. NR_O5=$0e00;
  167. NR_O6=$0f00;
  168. NR_O7=$1000;
  169. NR_L0=$1100;
  170. NR_L1=$1200;
  171. NR_L2=$1300;
  172. NR_L3=$1400;
  173. NR_L4=$1500;
  174. NR_L5=$1600;
  175. NR_L6=$1700;
  176. NR_L7=$1800;
  177. NR_I0=$1900;
  178. NR_I1=$1A00;
  179. NR_I2=$1B00;
  180. NR_I3=$1C00;
  181. NR_I4=$1D00;
  182. NR_I5=$1E00;
  183. NR_I6=$1F00;
  184. NR_I7=$2000;
  185. {$ifdef dummy}
  186. { Floating point }
  187. NR_F0=$2000;
  188. NR_F1=$2000;
  189. NR_F2=$2000;
  190. NR_F3=$2000;
  191. NR_F4=$2000;
  192. NR_F5=$2000;
  193. NR_F6=$2000;
  194. NR_F7=$2000;
  195. NR_F8=$2000;
  196. NR_F9=$2000;
  197. NR_F10=$2000;
  198. NR_F11=$2000;
  199. NR_F12=$2000;
  200. NR_F13=$2000;
  201. NR_F14=$2000;
  202. NR_F15=$2000;
  203. NR_F16=$2000;
  204. NR_F17=$2000;
  205. NR_F18=$2000;
  206. NR_F19=$2000;
  207. NR_F20=$2000;
  208. NR_F21=$2000;
  209. NR_F22=$2000;
  210. NR_F23=$2000;
  211. NR_F24=$2000;
  212. NR_F25=$2000;
  213. NR_F26=$2000;
  214. NR_F27=$2000;
  215. NR_F28=$2000;
  216. NR_F29=$2000;
  217. NR_F30=$2000;
  218. NR_F31=$2000;
  219. { Coprocessor point }
  220. NR_C0=$3000;
  221. NR_C1=$3000;
  222. NR_C2=$3000;
  223. NR_C3=$3000;
  224. NR_C4=$3000;
  225. NR_C5=$3000;
  226. NR_C6=$3000;
  227. NR_C7=$3000;
  228. NR_C8=$3000;
  229. NR_C9=$3000;
  230. NR_C10=$3000;
  231. NR_C11=$3000;
  232. NR_C12=$3000;
  233. NR_C13=$3000;
  234. NR_C14=$3000;
  235. NR_C15=$3000;
  236. NR_C16=$3000;
  237. NR_C17=$3000;
  238. NR_C18=$3000;
  239. NR_C19=$3000;
  240. NR_C20=$3000;
  241. NR_C21=$3000;
  242. NR_C22=$3000;
  243. NR_C23=$3000;
  244. NR_C24=$3000;
  245. NR_C25=$3000;
  246. NR_C26=$3000;
  247. NR_C27=$3000;
  248. NR_C28=$3000;
  249. NR_C29=$3000;
  250. NR_C30=$3000;
  251. NR_C31=$3000;
  252. { ASR }
  253. NR_ASR0=$4000;
  254. NR_ASR1=$4000;
  255. NR_ASR2=$4000;
  256. NR_ASR3=$4000;
  257. NR_ASR4=$4000;
  258. NR_ASR5=$4000;
  259. NR_ASR6=$4000;
  260. NR_ASR7=$4000;
  261. NR_ASR8=$4000;
  262. NR_ASR9=$4000;
  263. NR_ASR10=$4000;
  264. NR_ASR11=$4000;
  265. NR_ASR12=$4000;
  266. NR_ASR13=$4000;
  267. NR_ASR14=$4000;
  268. NR_ASR15=$4000;
  269. NR_ASR16=$4000;
  270. NR_ASR17=$4000;
  271. NR_ASR18=$4000;
  272. NR_ASR19=$4000;
  273. NR_ASR20=$4000;
  274. NR_ASR21=$4000;
  275. NR_ASR22=$4000;
  276. NR_ASR23=$4000;
  277. NR_ASR24=$4000;
  278. NR_ASR25=$4000;
  279. NR_ASR26=$4000;
  280. NR_ASR27=$4000;
  281. NR_ASR28=$4000;
  282. NR_ASR29=$4000;
  283. NR_ASR30=$4000;
  284. NR_ASR31=$4000;
  285. { Floating point status/"front of queue" registers }
  286. NR_FSR=$5000;
  287. NR_FQ=$5000;
  288. NR_CSR=$5000;
  289. NR_CQ=$5000;
  290. NR_PSR=$5000;
  291. NR_TBR=$5000;
  292. NR_WIM=$5000;
  293. NR_Y=$5000;
  294. {$endif dummy}
  295. {Super registers:}
  296. RS_NO=$00;
  297. RS_G0=$01;
  298. RS_G1=$02;
  299. RS_G2=$03;
  300. RS_G3=$04;
  301. RS_G4=$05;
  302. RS_G5=$06;
  303. RS_G6=$07;
  304. RS_G7=$08;
  305. RS_O0=$09;
  306. RS_O1=$0a;
  307. RS_O2=$0b;
  308. RS_O3=$0c;
  309. RS_O4=$0d;
  310. RS_O5=$0e;
  311. RS_O6=$0f;
  312. RS_O7=$10;
  313. RS_L0=$11;
  314. RS_L1=$12;
  315. RS_L2=$13;
  316. RS_L3=$14;
  317. RS_L4=$15;
  318. RS_L5=$16;
  319. RS_L6=$17;
  320. RS_L7=$18;
  321. RS_I0=$19;
  322. RS_I1=$1a;
  323. RS_I2=$1b;
  324. RS_I3=$1c;
  325. RS_I4=$1d;
  326. RS_I5=$1e;
  327. RS_I6=$1f;
  328. RS_I7=$20;
  329. first_supreg = $01;
  330. last_supreg = $20;
  331. first_imreg = $21;
  332. last_imreg = $ff;
  333. { Subregisters, situation unknown!! }
  334. R_SUBWHOLE=$00;
  335. R_SUBL=$00;
  336. {Conversion between TCpuRegister and NewRegisters}
  337. RegEnum2Number:array[TCpuRegister]of cardinal=(
  338. NR_NO,
  339. NR_G0,
  340. NR_G1,
  341. NR_G2,
  342. NR_G3,
  343. NR_G4,
  344. NR_G5,
  345. NR_G6,
  346. NR_G7,
  347. NR_O0,
  348. NR_O1,
  349. NR_O2,
  350. NR_O3,
  351. NR_O4,
  352. NR_O5,
  353. NR_O6,
  354. NR_O7,
  355. NR_L0,
  356. NR_L1,
  357. NR_L2,
  358. NR_L3,
  359. NR_L4,
  360. NR_L5,
  361. NR_L6,
  362. NR_L7,
  363. NR_I0,
  364. NR_I1,
  365. NR_I2,
  366. NR_I3,
  367. NR_I4,
  368. NR_I5,
  369. NR_I6,
  370. NR_I7,
  371. NR_NO,
  372. NR_NO,
  373. NR_NO,
  374. NR_NO,
  375. NR_NO,
  376. NR_NO,
  377. NR_NO,
  378. NR_NO,
  379. NR_NO,
  380. NR_NO,
  381. NR_NO,
  382. NR_NO,
  383. NR_NO,
  384. NR_NO,
  385. NR_NO,
  386. NR_NO,
  387. NR_NO,
  388. NR_NO,
  389. NR_NO,
  390. NR_NO,
  391. NR_NO,
  392. NR_NO,
  393. NR_NO,
  394. NR_NO,
  395. NR_NO,
  396. NR_NO,
  397. NR_NO,
  398. NR_NO,
  399. NR_NO,
  400. NR_NO,
  401. NR_NO,
  402. NR_NO,
  403. NR_NO,
  404. NR_NO,
  405. NR_NO,
  406. NR_NO,
  407. NR_NO,
  408. NR_NO,
  409. NR_NO,
  410. NR_NO,
  411. NR_NO,
  412. NR_NO,
  413. NR_NO,
  414. NR_NO,
  415. NR_NO,
  416. NR_NO,
  417. NR_NO,
  418. NR_NO,
  419. NR_NO,
  420. NR_NO,
  421. NR_NO,
  422. NR_NO,
  423. NR_NO,
  424. NR_NO,
  425. NR_NO,
  426. NR_NO,
  427. NR_NO,
  428. NR_NO,
  429. NR_NO,
  430. NR_NO,
  431. NR_NO,
  432. NR_NO,
  433. NR_NO,
  434. NR_NO,
  435. NR_NO,
  436. NR_NO,
  437. NR_NO,
  438. NR_NO,
  439. NR_NO,
  440. NR_NO,
  441. NR_NO,
  442. NR_NO,
  443. NR_NO,
  444. NR_NO,
  445. NR_NO,
  446. NR_NO,
  447. NR_NO,
  448. NR_NO,
  449. NR_NO,
  450. NR_NO,
  451. NR_NO,
  452. NR_NO,
  453. NR_NO,
  454. NR_NO,
  455. NR_NO,
  456. NR_NO,
  457. NR_NO,
  458. NR_NO,
  459. NR_NO,
  460. NR_NO,
  461. NR_NO,
  462. NR_NO,
  463. NR_NO,
  464. NR_NO,
  465. NR_NO,
  466. NR_NO,
  467. NR_NO,
  468. NR_NO,
  469. NR_NO,
  470. NR_NO,
  471. NR_NO,
  472. NR_NO,
  473. NR_NO,
  474. NR_NO,
  475. NR_NO,
  476. NR_NO,
  477. NR_NO,
  478. NR_NO
  479. );
  480. {*****************************************************************************
  481. Conditions
  482. *****************************************************************************}
  483. type
  484. TAsmCond=(C_None,
  485. C_A,C_AE,C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_NA,C_NAE,
  486. C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_NO,C_NP,
  487. C_NS,C_NZ,C_O,C_P,C_PE,C_PO,C_S,C_Z
  488. );
  489. const
  490. cond2str:array[TAsmCond] of string[3]=('',
  491. 'a','ae','b','be','c','e','g','ge','l','le','na','nae',
  492. 'nb','nbe','nc','ne','ng','nge','nl','nle','no','np',
  493. 'ns','nz','o','p','pe','po','s','z'
  494. );
  495. inverse_cond:array[TAsmCond] of TAsmCond=(C_None,
  496. C_NA,C_NAE,C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_A,C_AE,
  497. C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_O,C_P,
  498. C_S,C_Z,C_NO,C_NP,C_NP,C_P,C_NS,C_NZ
  499. );
  500. const
  501. CondAsmOps=3;
  502. CondAsmOp:array[0..CondAsmOps-1] of TAsmOp=(
  503. A_FCMPd, A_JMPL, A_FCMPs
  504. );
  505. CondAsmOpStr:array[0..CondAsmOps-1] of string[7]=(
  506. 'FCMPd','JMPL','FCMPs'
  507. );
  508. {*****************************************************************************
  509. Flags
  510. *****************************************************************************}
  511. type
  512. TResFlags=(
  513. F_E, {Equal}
  514. F_NE, {Not Equal}
  515. F_G, {Greater}
  516. F_L, {Less}
  517. F_GE, {Greater or Equal}
  518. F_LE, {Less or Equal}
  519. F_C, {Carry}
  520. F_NC, {Not Carry}
  521. F_A, {Above}
  522. F_AE, {Above or Equal}
  523. F_B, {Below}
  524. F_BE {Below or Equal}
  525. );
  526. {*****************************************************************************
  527. Reference
  528. *****************************************************************************}
  529. type
  530. TRefOptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  531. { since we have no full 32 bit offsets, we need to be able to specify the high
  532. and low bits of the address of a symbol }
  533. trefsymaddr = (refs_full,refs_hi,refs_lo);
  534. { reference record }
  535. preference = ^treference;
  536. treference = packed record
  537. { base register, R_NO if none }
  538. base,
  539. { index register, R_NO if none }
  540. index : tregister;
  541. { offset, 0 if none }
  542. offset : longint;
  543. { symbol this reference refers to, nil if none }
  544. symbol : tasmsymbol;
  545. { used in conjunction with symbols and offsets: refs_full means }
  546. { means a full 32bit reference, refs_hi means the upper 16 bits }
  547. { and refs_lo the lower 16 bits of the address }
  548. symaddr : trefsymaddr;
  549. { changed when inlining and possibly in other cases, don't }
  550. { set manually }
  551. offsetfixup : longint;
  552. { used in conjunction with the previous field }
  553. options : trefoptions;
  554. { alignment this reference is guaranteed to have }
  555. alignment : byte;
  556. end;
  557. { reference record }
  558. pparareference = ^tparareference;
  559. tparareference = packed record
  560. index : tregister;
  561. offset : aword;
  562. end;
  563. const
  564. symaddr2str: array[trefsymaddr] of string[3] = ('','%hi','%lo');
  565. {*****************************************************************************
  566. Operand
  567. *****************************************************************************}
  568. type
  569. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  570. toper=record
  571. ot:LongInt;
  572. case typ:toptype of
  573. top_none:();
  574. top_reg:(reg:tregister);
  575. top_ref:(ref:preference);
  576. top_const:(val:aword);
  577. top_symbol:(sym:tasmsymbol;symofs:LongInt);
  578. end;
  579. {*****************************************************************************
  580. Operand Sizes
  581. *****************************************************************************}
  582. {$ifdef dummy}
  583. {*****************************************************************************
  584. Argument Classification
  585. *****************************************************************************}
  586. type
  587. TArgClass = (
  588. { the following classes should be defined by all processor implemnations }
  589. AC_NOCLASS,
  590. AC_MEMORY,
  591. AC_INTEGER,
  592. AC_FPU,
  593. { the following argument classes are i386 specific }
  594. AC_FPUUP,
  595. AC_SSE,
  596. AC_SSEUP);
  597. {$endif dummy}
  598. {*****************************************************************************
  599. Generic Location
  600. *****************************************************************************}
  601. type
  602. { tparamlocation describes where a parameter for a procedure is stored.
  603. References are given from the caller's point of view. The usual
  604. TLocation isn't used, because contains a lot of unnessary fields.
  605. }
  606. tparalocation = packed record
  607. size : TCGSize;
  608. { The location type where the parameter is passed, usually
  609. LOC_REFERENCE,LOC_REGISTER or LOC_FPUREGISTER
  610. }
  611. loc : TCGLoc;
  612. { The stack pointer must be decreased by this value before
  613. the parameter is copied to the given destination.
  614. This allows to "encode" pushes with tparalocation.
  615. On the PowerPC, this field is unsed but it is there
  616. because several generic code accesses it.
  617. }
  618. sp_fixup : longint;
  619. case TCGLoc of
  620. LOC_REFERENCE : (reference : tparareference);
  621. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  622. LOC_REGISTER,LOC_CREGISTER : (
  623. case longint of
  624. 1 : (register,registerhigh : tregister);
  625. { overlay a registerlow }
  626. 2 : (registerlow : tregister);
  627. { overlay a 64 Bit register type }
  628. 3 : (reg64 : tregister64);
  629. 4 : (register64 : tregister64);
  630. );
  631. end;
  632. treglocation = packed record
  633. case longint of
  634. 1 : (register,registerhigh : tregister);
  635. { overlay a registerlow }
  636. 2 : (registerlow : tregister);
  637. { overlay a 64 Bit register type }
  638. 3 : (reg64 : tregister64);
  639. 4 : (register64 : tregister64);
  640. end;
  641. tlocation = packed record
  642. size : TCGSize;
  643. loc : tcgloc;
  644. case tcgloc of
  645. LOC_CREFERENCE,LOC_REFERENCE : (reference : treference);
  646. LOC_CONSTANT : (
  647. case longint of
  648. {$ifdef FPC_BIG_ENDIAN}
  649. 1 : (_valuedummy,value : AWord);
  650. {$else FPC_BIG_ENDIAN}
  651. 1 : (value : AWord);
  652. {$endif FPC_BIG_ENDIAN}
  653. { can't do this, this layout depends on the host cpu. Use }
  654. { lo(valueqword)/hi(valueqword) instead (JM) }
  655. { 2 : (valuelow, valuehigh:AWord); }
  656. { overlay a complete 64 Bit value }
  657. 3 : (valueqword : qword);
  658. );
  659. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  660. LOC_REGISTER,LOC_CREGISTER : (
  661. case longint of
  662. 1 : (registerlow,registerhigh : tregister);
  663. 2 : (register : tregister);
  664. { overlay a 64 Bit register type }
  665. 3 : (reg64 : tregister64);
  666. 4 : (register64 : tregister64);
  667. );
  668. LOC_FLAGS : (resflags : tresflags);
  669. end;
  670. {*****************************************************************************
  671. Constants
  672. *****************************************************************************}
  673. const
  674. max_operands = 3;
  675. {# Constant defining possibly all registers which might require saving }
  676. ALL_REGISTERS = [R_G0..R_I7];
  677. ALL_INTREGISTERS = [1..255];
  678. general_registers = [R_G0..R_I7];
  679. general_superregisters = [RS_O0..RS_I7];
  680. {# low and high of the available maximum width integer general purpose }
  681. { registers }
  682. LoGPReg = R_G0;
  683. HiGPReg = R_I7;
  684. {# low and high of every possible width general purpose register (same as }
  685. { above on most architctures apart from the 80x86) }
  686. LoReg = R_G0;
  687. HiReg = R_I7;
  688. {# Table of registers which can be allocated by the code generator
  689. internally, when generating the code.
  690. }
  691. { legend: }
  692. { xxxregs = set of all possibly used registers of that type in the code }
  693. { generator }
  694. { usableregsxxx = set of all 32bit components of registers that can be }
  695. { possible allocated to a regvar or using getregisterxxx (this }
  696. { excludes registers which can be only used for parameter }
  697. { passing on ABI's that define this) }
  698. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  699. maxintregs = 8;
  700. intregs = [R_G0..R_I7];
  701. usableregsint = [RS_O0..RS_I7];
  702. c_countusableregsint = 24;
  703. maxfpuregs = 8;
  704. fpuregs=[R_F0..R_F31];
  705. usableregsfpu=[R_F0..R_F31];
  706. c_countusableregsfpu=32;
  707. mmregs = [];
  708. usableregsmm = [];
  709. c_countusableregsmm = 0;
  710. { no distinction on this platform }
  711. maxaddrregs = 0;
  712. addrregs = [];
  713. usableregsaddr = [];
  714. c_countusableregsaddr = 0;
  715. firstsaveintreg = RS_O0;
  716. lastsaveintreg = RS_I7;
  717. firstsavefpureg = R_F0;
  718. lastsavefpureg = R_F31;
  719. firstsavemmreg = R_NO;
  720. lastsavemmreg = R_NO;
  721. maxvarregs = 8;
  722. varregs : Array [1..maxvarregs] of Tnewregister =
  723. (RS_L0,RS_L1,RS_L2,RS_L3,RS_L4,RS_L5,RS_L6,RS_L7);
  724. maxfpuvarregs = 1;
  725. fpuvarregs : Array [1..maxfpuvarregs] of Toldregister =
  726. (R_F2);
  727. {
  728. max_param_regs_int = 6;
  729. param_regs_int: Array[1..max_param_regs_int] of Toldregister =
  730. (R_3,R_4,R_5,R_6,R_7,R_8,R_9,R_10);
  731. max_param_regs_fpu = 13;
  732. param_regs_fpu: Array[1..max_param_regs_fpu] of Toldregister =
  733. (R_F1,R_F2,R_F3,R_F4,R_F5,R_F6,R_F7,R_F8,R_F9,R_F10,R_F11,R_F12,R_F13);
  734. max_param_regs_mm = 13;
  735. param_regs_mm: Array[1..max_param_regs_mm] of Toldregister =
  736. (R_M1,R_M2,R_M3,R_M4,R_M5,R_M6,R_M7,R_M8,R_M9,R_M10,R_M11,R_M12,R_M13);
  737. }
  738. {# Registers which are defined as scratch and no need to save across
  739. routine calls or in assembler blocks.
  740. }
  741. max_scratch_regs = 2;
  742. scratch_regs: Array[1..max_scratch_regs] of Tsuperregister = (RS_O7,RS_G2);
  743. {*****************************************************************************
  744. Default generic sizes
  745. *****************************************************************************}
  746. {# Defines the default address size for a processor, }
  747. OS_ADDR = OS_32;
  748. {# the natural int size for a processor, }
  749. OS_INT = OS_32;
  750. {# the maximum float size for a processor, }
  751. OS_FLOAT = OS_F64;
  752. {# the size of a vector register for a processor }
  753. OS_VECTOR = OS_M64;
  754. {*****************************************************************************
  755. GDB Information
  756. *****************************************************************************}
  757. {# Register indexes for stabs information, when some
  758. parameters or variables are stored in registers.
  759. Taken from rs6000.h (DBX_REGISTER_NUMBER)
  760. from GCC 3.x source code.
  761. }
  762. stab_regindex : array[firstreg..lastreg] of shortint =
  763. (
  764. 0{R_NO}
  765. {General purpose global registers}
  766. ,1{R_G0}{This register is usually set to zero and used as a scratch register}
  767. ,2{R_G1},3{R_G2},4{R_G3},5{R_G4},6{R_G5},7{R_G6},8{R_G7}
  768. {General purpose out registers}
  769. ,9{R_O0},10{R_O1},11{R_O2},12{R_O3},13{R_O4},14{R_O5},15{R_O6}
  770. ,16{R_O7}{This register is used to save the address of the last CALL instruction}
  771. {General purpose local registers}
  772. ,16{R_L0}
  773. ,17{R_L1}{This register is used to save the Program Counter (PC) after a Trap}
  774. ,18{R_L2}{This register is used to save the Program Counter (nPC) after a Trap}
  775. ,19{R_L3},20{R_L4},21{R_L5},22{R_L6},23{R_L7}
  776. {General purpose in registers}
  777. ,24{R_I0},25{R_I1},26{R_I2},27{R_I3},28{R_I4},29{R_I5},30{R_I6},31{R_I7}
  778. {Floating point registers}
  779. ,32{R_F0},33{R_F1},34{R_F2},35{R_F3},36{R_F4},37{R_F5},38{R_F6},39{R_F7}
  780. ,40{R_F8},41{R_F9},42{R_F10},43{R_F11},44{R_F12},45{R_F13},46{R_F14},47{R_F15}
  781. ,48{R_F16},49{R_F17},50{R_F18},51{R_F19},52{R_F20},53{R_F21},54{R_F22},55{R_F23}
  782. ,56{R_F24},57{R_F25},58{R_F26},59{R_F27},60{R_F28},61{R_F29},62{R_F30},63{R_F31}
  783. {Floating point status/"front of queue" registers}
  784. ,64{R_FSR},65{R_FQ}
  785. {Coprocessor registers}
  786. ,66{R_C0},67{R_C1},68{R_C2},69{R_C3},70{R_C4},71{R_C5},72{R_C6},73{R_C7}
  787. ,74{R_C8},75{R_C9},76{R_C10},77{R_C11},78{R_C12},79{R_C13},80{R_C14},81{R_C15}
  788. ,82{R_C16},83{R_C17},84{R_C18},85{R_C19},86{R_C20},87{R_C21},88{R_C22},89{R_C23}
  789. ,90{R_C24},91{R_C25},92{R_C26},93{R_C27},94{R_C28},95{R_C29},96{R_C30},98{R_C31}
  790. {Coprocessor status/queue registers}
  791. ,99{R_CSR}
  792. ,100{R_CQ}
  793. {Integer Unit control & status registers}
  794. ,101{R_PSR}{Processor Status Register : informs upon the program status}
  795. ,102{R_TBR}{Trap Base Register : saves the Trap vactor base address}
  796. ,103{R_WIM}{Window Invalid Mask : }
  797. ,104{R_Y}{Multiply/Devide Register : }
  798. {Ancillary State Registers : these are implementation dependent registers and
  799. thus, are not specified by the SPARC Reference Manual. I did choose the SUN's
  800. implementation according to the Assembler Refernce Manual.(MN)}
  801. ,105{R_ASR0},106{R_ASR1},107{R_ASR2},108{R_ASR3},109{R_ASR4},110{R_ASR5},111{R_ASR6},112{R_ASR7}
  802. ,113{R_ASR8},114{R_ASR9},115{R_ASR10},116{R_ASR11},117{R_ASR12},118{R_ASR13},119{R_ASR14},120{R_ASR15}
  803. ,121{R_ASR16},122{R_ASR17},123{R_ASR18},124{R_ASR19},125{R_ASR20},126{R_ASR21},127{R_ASR22},127{R_ASR23}
  804. ,127{R_ASR24},127{R_ASR25},127{R_ASR26},127{R_ASR27},127{R_ASR28},127{R_ASR29},127{R_ASR30},127{R_ASR31}
  805. );
  806. {*****************************************************************************
  807. Generic Register names
  808. *****************************************************************************}
  809. {# Stack pointer register }
  810. NR_STACK_POINTER_REG = NR_O6;
  811. RS_STACK_POINTER_REG = RS_O6;
  812. {# Frame pointer register }
  813. NR_FRAME_POINTER_REG = NR_I6;
  814. RS_FRAME_POINTER_REG = RS_I6;
  815. {# Register for addressing absolute data in a position independant way,
  816. such as in PIC code. The exact meaning is ABI specific. For
  817. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  818. Taken from GCC rs6000.h
  819. }
  820. {$warning As indicated in rs6000.h, but can't find it anywhere else!}
  821. {PIC_OFFSET_REG = R_30;}
  822. { the return_result_reg, is used inside the called function to store its return
  823. value when that is a scalar value otherwise a pointer to the address of the
  824. result is placed inside it }
  825. { Results are returned in this register (32-bit values) }
  826. NR_FUNCTION_RETURN_REG = NR_I0;
  827. RS_FUNCTION_RETURN_REG = RS_I0;
  828. { Low part of 64bit return value }
  829. NR_FUNCTION_RETURN64LOW_REG = NR_I1;
  830. RS_FUNCTION_RETURN64LOW_REG = RS_I1;
  831. { High part of 64bit return value }
  832. NR_FUNCTION_RETURN64HIGH_REG = NR_I0;
  833. RS_FUNCTION_RETURN64HIGH_REG = RS_I0;
  834. { The value returned from a function is available in this register }
  835. NR_FUNCTION_RESULT_REG = NR_O0;
  836. RS_FUNCTION_RESULT_REG = RS_O0;
  837. { The lowh part of 64bit value returned from a function }
  838. NR_FUNCTION_RESULT64_LOW_REG = NR_O1;
  839. RS_FUNCTION_RESULT64_LOW_REG = RS_O1;
  840. { The high part of 64bit value returned from a function }
  841. NR_FUNCTION_RESULT64_HIGH_REG = NR_O0;
  842. RS_FUNCTION_RESULT64_HIGH_REG = RS_O0;
  843. FPU_RESULT_REG = R_F0;
  844. mmresultreg = R_NO;
  845. {*****************************************************************************
  846. GCC /ABI linking information
  847. *****************************************************************************}
  848. {# Registers which must be saved when calling a routine declared as
  849. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  850. saved should be the ones as defined in the target ABI and / or GCC.
  851. This value can be deduced from CALLED_USED_REGISTERS array in the
  852. GCC source.
  853. }
  854. std_saved_registers = [];
  855. {# Required parameter alignment when calling a routine declared as
  856. stdcall and cdecl. The alignment value should be the one defined
  857. by GCC or the target ABI.
  858. The value of this constant is equal to the constant
  859. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  860. }
  861. std_param_align = 4; { for 32-bit version only }
  862. {*****************************************************************************
  863. CPU Dependent Constants
  864. *****************************************************************************}
  865. {*****************************************************************************
  866. Helpers
  867. *****************************************************************************}
  868. function is_calljmp(o:tasmop):boolean;
  869. function flags_to_cond(const f: TResFlags) : TAsmCond;
  870. procedure convert_register_to_enum(var r:Tregister);
  871. function cgsize2subreg(s:Tcgsize):Tsubregister;
  872. implementation
  873. uses
  874. verbose;
  875. {*****************************************************************************
  876. Helpers
  877. *****************************************************************************}
  878. function is_calljmp(o:tasmop):boolean;
  879. const
  880. CallJmpOp=[A_JMPL..A_CBccc];
  881. begin
  882. is_calljmp:=(o in CallJmpOp);
  883. end;
  884. function flags_to_cond(const f:TResFlags):TAsmCond;
  885. const
  886. flags_2_cond:array[TResFlags] of TAsmCond=
  887. (C_E,C_NE,C_G,C_L,C_GE,C_LE,C_C,C_NC,C_A,C_AE,C_B,C_BE);
  888. begin
  889. result:=flags_2_cond[f];
  890. end;
  891. procedure convert_register_to_enum(var r:Tregister);
  892. begin
  893. if (r.enum=R_INTREGISTER) then
  894. begin
  895. if r.number>NR_I7 then
  896. internalerror(200301082);
  897. r.enum:=toldregister(r.number shr 8);
  898. end;
  899. end;
  900. function cgsize2subreg(s:Tcgsize):Tsubregister;
  901. begin
  902. cgsize2subreg:=R_SUBWHOLE;
  903. end;
  904. end.
  905. {
  906. $Log$
  907. Revision 1.37 2003-05-31 15:05:28 peter
  908. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  909. Revision 1.36 2003/05/31 01:00:51 peter
  910. * register fixes
  911. Revision 1.35 2003/05/30 23:57:08 peter
  912. * more sparc cleanup
  913. * accumulator removed, splitted in function_return_reg (called) and
  914. function_result_reg (caller)
  915. }