cpubase.pas 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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:TCpuRegister;
  95. number:Tnewregister;
  96. end;
  97. {# Set type definition for registers }
  98. tregisterset = set of TCpuRegister;
  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(TCpuRegister);
  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. {$warning FIXME!!}
  332. { registers which may be destroyed by calls }
  333. VOLATILE_INTREGISTERS = [first_supreg..last_supreg];
  334. first_imreg = $21;
  335. last_imreg = $ff;
  336. { Subregisters, situation unknown!! }
  337. R_SUBWHOLE=$00;
  338. R_SUBL=$00;
  339. {Conversion between TCpuRegister and NewRegisters}
  340. RegEnum2Number:array[TCpuRegister]of cardinal=(
  341. NR_NO,
  342. NR_G0,
  343. NR_G1,
  344. NR_G2,
  345. NR_G3,
  346. NR_G4,
  347. NR_G5,
  348. NR_G6,
  349. NR_G7,
  350. NR_O0,
  351. NR_O1,
  352. NR_O2,
  353. NR_O3,
  354. NR_O4,
  355. NR_O5,
  356. NR_O6,
  357. NR_O7,
  358. NR_L0,
  359. NR_L1,
  360. NR_L2,
  361. NR_L3,
  362. NR_L4,
  363. NR_L5,
  364. NR_L6,
  365. NR_L7,
  366. NR_I0,
  367. NR_I1,
  368. NR_I2,
  369. NR_I3,
  370. NR_I4,
  371. NR_I5,
  372. NR_I6,
  373. NR_I7,
  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. NR_NO,
  480. NR_NO,
  481. NR_NO
  482. );
  483. {*****************************************************************************
  484. Conditions
  485. *****************************************************************************}
  486. type
  487. TAsmCond=(C_None,
  488. C_A,C_AE,C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_NA,C_NAE,
  489. C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_NO,C_NP,
  490. C_NS,C_NZ,C_O,C_P,C_PE,C_PO,C_S,C_Z
  491. );
  492. const
  493. cond2str:array[TAsmCond] of string[3]=('',
  494. 'gu','cc','cs','leu','cs','e','g','ge','l','le','leu','cs',
  495. 'cc','gu','cc','ne','le','l','ge','g','vc','XX',
  496. 'pos','ne','vs','XX','XX','XX','vs','e'
  497. );
  498. inverse_cond:array[TAsmCond] of TAsmCond=(C_None,
  499. C_NA,C_NAE,C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_A,C_AE,
  500. C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_O,C_P,
  501. C_S,C_Z,C_NO,C_NP,C_NP,C_P,C_NS,C_NZ
  502. );
  503. const
  504. CondAsmOps=1;
  505. CondAsmOp:array[0..CondAsmOps-1] of TAsmOp=(
  506. A_Bxx
  507. );
  508. CondAsmOpStr:array[0..CondAsmOps-1] of string[7]=(
  509. 'B'
  510. );
  511. {*****************************************************************************
  512. Flags
  513. *****************************************************************************}
  514. type
  515. TResFlags=(
  516. F_E, {Equal}
  517. F_NE, {Not Equal}
  518. F_G, {Greater}
  519. F_L, {Less}
  520. F_GE, {Greater or Equal}
  521. F_LE, {Less or Equal}
  522. F_C, {Carry}
  523. F_NC, {Not Carry}
  524. F_A, {Above}
  525. F_AE, {Above or Equal}
  526. F_B, {Below}
  527. F_BE {Below or Equal}
  528. );
  529. {*****************************************************************************
  530. Reference
  531. *****************************************************************************}
  532. type
  533. TRefOptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  534. { since we have no full 32 bit offsets, we need to be able to specify the high
  535. and low bits of the address of a symbol }
  536. trefsymaddr = (refs_no,refs_full,refs_hi,refs_lo);
  537. { reference record }
  538. preference = ^treference;
  539. treference = packed record
  540. { base register, R_NO if none }
  541. base,
  542. { index register, R_NO if none }
  543. index : tregister;
  544. { offset, 0 if none }
  545. offset : longint;
  546. { symbol this reference refers to, nil if none }
  547. symbol : tasmsymbol;
  548. { used in conjunction with symbols and offsets: refs_full means }
  549. { means a full 32bit reference, refs_hi means the upper 16 bits }
  550. { and refs_lo the lower 16 bits of the address }
  551. symaddr : trefsymaddr;
  552. { changed when inlining and possibly in other cases, don't }
  553. { set manually }
  554. offsetfixup : longint;
  555. { used in conjunction with the previous field }
  556. options : trefoptions;
  557. { alignment this reference is guaranteed to have }
  558. alignment : byte;
  559. end;
  560. { reference record }
  561. pparareference = ^tparareference;
  562. tparareference = packed record
  563. index : tregister;
  564. offset : aword;
  565. end;
  566. const
  567. symaddr2str: array[trefsymaddr] of string[3] = ('','','%hi','%lo');
  568. {*****************************************************************************
  569. Operand
  570. *****************************************************************************}
  571. type
  572. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  573. toper=record
  574. ot:LongInt;
  575. case typ:toptype of
  576. top_none:();
  577. top_reg:(reg:tregister);
  578. top_ref:(ref:preference);
  579. top_const:(val:aword);
  580. top_symbol:(sym:tasmsymbol;symofs:LongInt);
  581. end;
  582. {*****************************************************************************
  583. Operand Sizes
  584. *****************************************************************************}
  585. {$ifdef dummy}
  586. {*****************************************************************************
  587. Argument Classification
  588. *****************************************************************************}
  589. type
  590. TArgClass = (
  591. { the following classes should be defined by all processor implemnations }
  592. AC_NOCLASS,
  593. AC_MEMORY,
  594. AC_INTEGER,
  595. AC_FPU,
  596. { the following argument classes are i386 specific }
  597. AC_FPUUP,
  598. AC_SSE,
  599. AC_SSEUP);
  600. {$endif dummy}
  601. {*****************************************************************************
  602. Generic Location
  603. *****************************************************************************}
  604. type
  605. { tparamlocation describes where a parameter for a procedure is stored.
  606. References are given from the caller's point of view. The usual
  607. TLocation isn't used, because contains a lot of unnessary fields.
  608. }
  609. tparalocation = packed record
  610. size : TCGSize;
  611. { The location type where the parameter is passed, usually
  612. LOC_REFERENCE,LOC_REGISTER or LOC_FPUREGISTER
  613. }
  614. loc : TCGLoc;
  615. { The stack pointer must be decreased by this value before
  616. the parameter is copied to the given destination.
  617. This allows to "encode" pushes with tparalocation.
  618. On the PowerPC, this field is unsed but it is there
  619. because several generic code accesses it.
  620. }
  621. sp_fixup : longint;
  622. case TCGLoc of
  623. LOC_REFERENCE : (reference : tparareference; low_in_reg: boolean; lowreg : tregister);
  624. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  625. LOC_REGISTER,LOC_CREGISTER : (
  626. case longint of
  627. 1 : (register,registerhigh : tregister);
  628. { overlay a registerlow }
  629. 2 : (registerlow : tregister);
  630. { overlay a 64 Bit register type }
  631. 3 : (reg64 : tregister64);
  632. 4 : (register64 : tregister64);
  633. );
  634. end;
  635. treglocation = packed record
  636. case longint of
  637. 1 : (register,registerhigh : tregister);
  638. { overlay a registerlow }
  639. 2 : (registerlow : tregister);
  640. { overlay a 64 Bit register type }
  641. 3 : (reg64 : tregister64);
  642. 4 : (register64 : tregister64);
  643. end;
  644. tlocation = packed record
  645. size : TCGSize;
  646. loc : tcgloc;
  647. case tcgloc of
  648. LOC_CREFERENCE,LOC_REFERENCE : (reference : treference);
  649. LOC_CONSTANT : (
  650. case longint of
  651. {$ifdef FPC_BIG_ENDIAN}
  652. 1 : (_valuedummy,value : AWord);
  653. {$else FPC_BIG_ENDIAN}
  654. 1 : (value : AWord);
  655. {$endif FPC_BIG_ENDIAN}
  656. { can't do this, this layout depends on the host cpu. Use }
  657. { lo(valueqword)/hi(valueqword) instead (JM) }
  658. { 2 : (valuelow, valuehigh:AWord); }
  659. { overlay a complete 64 Bit value }
  660. 3 : (valueqword : qword);
  661. );
  662. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  663. LOC_REGISTER,LOC_CREGISTER : (
  664. case longint of
  665. 1 : (registerlow,registerhigh : tregister);
  666. 2 : (register : tregister);
  667. { overlay a 64 Bit register type }
  668. 3 : (reg64 : tregister64);
  669. 4 : (register64 : tregister64);
  670. );
  671. LOC_FLAGS : (resflags : tresflags);
  672. end;
  673. {*****************************************************************************
  674. Constants
  675. *****************************************************************************}
  676. const
  677. max_operands = 3;
  678. {# Constant defining possibly all registers which might require saving }
  679. ALL_REGISTERS = [R_G0..R_I7];
  680. general_registers = [R_G0..R_I7];
  681. general_superregisters = [RS_O0..RS_I7];
  682. {# low and high of the available maximum width integer general purpose }
  683. { registers }
  684. LoGPReg = R_G0;
  685. HiGPReg = R_I7;
  686. {# low and high of every possible width general purpose register (same as }
  687. { above on most architctures apart from the 80x86) }
  688. LoReg = R_G0;
  689. HiReg = R_I7;
  690. {# Table of registers which can be allocated by the code generator
  691. internally, when generating the code.
  692. }
  693. { legend: }
  694. { xxxregs = set of all possibly used registers of that type in the code }
  695. { generator }
  696. { usableregsxxx = set of all 32bit components of registers that can be }
  697. { possible allocated to a regvar or using getregisterxxx (this }
  698. { excludes registers which can be only used for parameter }
  699. { passing on ABI's that define this) }
  700. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  701. maxintregs = 8;
  702. intregs = [R_G0..R_I7];
  703. usableregsint = [RS_L0..RS_L7];
  704. c_countusableregsint = 8;
  705. maxfpuregs = 8;
  706. fpuregs=[R_F0..R_F31];
  707. usableregsfpu=[R_F0..R_F31];
  708. c_countusableregsfpu=32;
  709. mmregs = [];
  710. usableregsmm = [];
  711. c_countusableregsmm = 0;
  712. { no distinction on this platform }
  713. maxaddrregs = 0;
  714. addrregs = [];
  715. usableregsaddr = [];
  716. c_countusableregsaddr = 0;
  717. {$warning firstsaveintreg shall be RS_NO}
  718. firstsaveintreg = RS_L0; { Temporary, having RS_NO is broken }
  719. lastsaveintreg = RS_L0; { L0..L7 are already saved, I0..O7 are parameter }
  720. firstsavefpureg = R_F2; { F0..F1 is used for return value }
  721. lastsavefpureg = R_F31;
  722. firstsavemmreg = R_NO;
  723. lastsavemmreg = R_NO;
  724. maxvarregs = 8;
  725. varregs : Array [1..maxvarregs] of Tnewregister =
  726. (RS_L0,RS_L1,RS_L2,RS_L3,RS_L4,RS_L5,RS_L6,RS_L7);
  727. maxfpuvarregs = 1;
  728. fpuvarregs : Array [1..maxfpuvarregs] of TCpuRegister =
  729. (R_F2);
  730. {
  731. max_param_regs_int = 6;
  732. param_regs_int: Array[1..max_param_regs_int] of TCpuRegister =
  733. (R_3,R_4,R_5,R_6,R_7,R_8,R_9,R_10);
  734. max_param_regs_fpu = 13;
  735. param_regs_fpu: Array[1..max_param_regs_fpu] of TCpuRegister =
  736. (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);
  737. max_param_regs_mm = 13;
  738. param_regs_mm: Array[1..max_param_regs_mm] of TCpuRegister =
  739. (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);
  740. }
  741. {# Registers which are defined as scratch and no need to save across
  742. routine calls or in assembler blocks.
  743. }
  744. max_scratch_regs = 3;
  745. scratch_regs: Array[1..max_scratch_regs] of Tsuperregister = (RS_O7,RS_G2,RS_G3);
  746. {*****************************************************************************
  747. Default generic sizes
  748. *****************************************************************************}
  749. {# Defines the default address size for a processor, }
  750. OS_ADDR = OS_32;
  751. {# the natural int size for a processor, }
  752. OS_INT = OS_32;
  753. {# the maximum float size for a processor, }
  754. OS_FLOAT = OS_F64;
  755. {# the size of a vector register for a processor }
  756. OS_VECTOR = OS_M64;
  757. {*****************************************************************************
  758. GDB Information
  759. *****************************************************************************}
  760. {# Register indexes for stabs information, when some
  761. parameters or variables are stored in registers.
  762. Taken from rs6000.h (DBX_REGISTER_NUMBER)
  763. from GCC 3.x source code.
  764. }
  765. stab_regindex : array[firstreg..lastreg] of shortint =
  766. (
  767. 0{R_NO}
  768. {General purpose global registers}
  769. ,1{R_G0}{This register is usually set to zero and used as a scratch register}
  770. ,2{R_G1},3{R_G2},4{R_G3},5{R_G4},6{R_G5},7{R_G6},8{R_G7}
  771. {General purpose out registers}
  772. ,9{R_O0},10{R_O1},11{R_O2},12{R_O3},13{R_O4},14{R_O5},15{R_O6}
  773. ,16{R_O7}{This register is used to save the address of the last CALL instruction}
  774. {General purpose local registers}
  775. ,16{R_L0}
  776. ,17{R_L1}{This register is used to save the Program Counter (PC) after a Trap}
  777. ,18{R_L2}{This register is used to save the Program Counter (nPC) after a Trap}
  778. ,19{R_L3},20{R_L4},21{R_L5},22{R_L6},23{R_L7}
  779. {General purpose in registers}
  780. ,24{R_I0},25{R_I1},26{R_I2},27{R_I3},28{R_I4},29{R_I5},30{R_I6},31{R_I7}
  781. {Floating point registers}
  782. ,32{R_F0},33{R_F1},34{R_F2},35{R_F3},36{R_F4},37{R_F5},38{R_F6},39{R_F7}
  783. ,40{R_F8},41{R_F9},42{R_F10},43{R_F11},44{R_F12},45{R_F13},46{R_F14},47{R_F15}
  784. ,48{R_F16},49{R_F17},50{R_F18},51{R_F19},52{R_F20},53{R_F21},54{R_F22},55{R_F23}
  785. ,56{R_F24},57{R_F25},58{R_F26},59{R_F27},60{R_F28},61{R_F29},62{R_F30},63{R_F31}
  786. {Floating point status/"front of queue" registers}
  787. ,64{R_FSR},65{R_FQ}
  788. {Coprocessor registers}
  789. ,66{R_C0},67{R_C1},68{R_C2},69{R_C3},70{R_C4},71{R_C5},72{R_C6},73{R_C7}
  790. ,74{R_C8},75{R_C9},76{R_C10},77{R_C11},78{R_C12},79{R_C13},80{R_C14},81{R_C15}
  791. ,82{R_C16},83{R_C17},84{R_C18},85{R_C19},86{R_C20},87{R_C21},88{R_C22},89{R_C23}
  792. ,90{R_C24},91{R_C25},92{R_C26},93{R_C27},94{R_C28},95{R_C29},96{R_C30},98{R_C31}
  793. {Coprocessor status/queue registers}
  794. ,99{R_CSR}
  795. ,100{R_CQ}
  796. {Integer Unit control & status registers}
  797. ,101{R_PSR}{Processor Status Register : informs upon the program status}
  798. ,102{R_TBR}{Trap Base Register : saves the Trap vactor base address}
  799. ,103{R_WIM}{Window Invalid Mask : }
  800. ,104{R_Y}{Multiply/Devide Register : }
  801. {Ancillary State Registers : these are implementation dependent registers and
  802. thus, are not specified by the SPARC Reference Manual. I did choose the SUN's
  803. implementation according to the Assembler Refernce Manual.(MN)}
  804. ,105{R_ASR0},106{R_ASR1},107{R_ASR2},108{R_ASR3},109{R_ASR4},110{R_ASR5},111{R_ASR6},112{R_ASR7}
  805. ,113{R_ASR8},114{R_ASR9},115{R_ASR10},116{R_ASR11},117{R_ASR12},118{R_ASR13},119{R_ASR14},120{R_ASR15}
  806. ,121{R_ASR16},122{R_ASR17},123{R_ASR18},124{R_ASR19},125{R_ASR20},126{R_ASR21},127{R_ASR22},127{R_ASR23}
  807. ,127{R_ASR24},127{R_ASR25},127{R_ASR26},127{R_ASR27},127{R_ASR28},127{R_ASR29},127{R_ASR30},127{R_ASR31}
  808. );
  809. {*****************************************************************************
  810. Generic Register names
  811. *****************************************************************************}
  812. {# Stack pointer register }
  813. NR_STACK_POINTER_REG = NR_O6;
  814. RS_STACK_POINTER_REG = RS_O6;
  815. {# Frame pointer register }
  816. NR_FRAME_POINTER_REG = NR_I6;
  817. RS_FRAME_POINTER_REG = RS_I6;
  818. {# Register for addressing absolute data in a position independant way,
  819. such as in PIC code. The exact meaning is ABI specific. For
  820. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  821. Taken from GCC rs6000.h
  822. }
  823. {$warning As indicated in rs6000.h, but can't find it anywhere else!}
  824. {PIC_OFFSET_REG = R_30;}
  825. { the return_result_reg, is used inside the called function to store its return
  826. value when that is a scalar value otherwise a pointer to the address of the
  827. result is placed inside it }
  828. { Results are returned in this register (32-bit values) }
  829. NR_FUNCTION_RETURN_REG = NR_I0;
  830. RS_FUNCTION_RETURN_REG = RS_I0;
  831. { Low part of 64bit return value }
  832. NR_FUNCTION_RETURN64_LOW_REG = NR_I1;
  833. RS_FUNCTION_RETURN64_LOW_REG = RS_I1;
  834. { High part of 64bit return value }
  835. NR_FUNCTION_RETURN64_HIGH_REG = NR_I0;
  836. RS_FUNCTION_RETURN64_HIGH_REG = RS_I0;
  837. { The value returned from a function is available in this register }
  838. NR_FUNCTION_RESULT_REG = NR_O0;
  839. RS_FUNCTION_RESULT_REG = RS_O0;
  840. { The lowh part of 64bit value returned from a function }
  841. NR_FUNCTION_RESULT64_LOW_REG = NR_O1;
  842. RS_FUNCTION_RESULT64_LOW_REG = RS_O1;
  843. { The high part of 64bit value returned from a function }
  844. NR_FUNCTION_RESULT64_HIGH_REG = NR_O0;
  845. RS_FUNCTION_RESULT64_HIGH_REG = RS_O0;
  846. FPU_RESULT_REG = R_F0;
  847. mmresultreg = R_NO;
  848. PARENT_FRAMEPOINTER_OFFSET = 68; { o0 }
  849. {*****************************************************************************
  850. GCC /ABI linking information
  851. *****************************************************************************}
  852. {# Registers which must be saved when calling a routine declared as
  853. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  854. saved should be the ones as defined in the target ABI and / or GCC.
  855. This value can be deduced from CALLED_USED_REGISTERS array in the
  856. GCC source.
  857. }
  858. std_saved_registers = [];
  859. {# Required parameter alignment when calling a routine declared as
  860. stdcall and cdecl. The alignment value should be the one defined
  861. by GCC or the target ABI.
  862. The value of this constant is equal to the constant
  863. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  864. }
  865. std_param_align = 4; { for 32-bit version only }
  866. {*****************************************************************************
  867. CPU Dependent Constants
  868. *****************************************************************************}
  869. const
  870. simm13lo=-4096;
  871. simm13hi=4095;
  872. {*****************************************************************************
  873. Helpers
  874. *****************************************************************************}
  875. function is_calljmp(o:tasmop):boolean;
  876. procedure inverse_flags(var f: TResFlags);
  877. function flags_to_cond(const f: TResFlags) : TAsmCond;
  878. procedure convert_register_to_enum(var r:Tregister);
  879. function cgsize2subreg(s:Tcgsize):Tsubregister;
  880. function supreg_name(r:Tsuperregister):string;
  881. implementation
  882. uses
  883. verbose;
  884. {*****************************************************************************
  885. Helpers
  886. *****************************************************************************}
  887. function is_calljmp(o:tasmop):boolean;
  888. const
  889. CallJmpOp=[A_JMPL..A_CBccc];
  890. begin
  891. is_calljmp:=(o in CallJmpOp);
  892. end;
  893. procedure inverse_flags(var f: TResFlags);
  894. const
  895. inv_flags: array[TResFlags] of TResFlags =
  896. (F_NE,F_E,F_LE,F_GE,F_L,F_G,F_NC,F_C,F_BE,F_B,F_AE,F_A);
  897. begin
  898. f:=inv_flags[f];
  899. end;
  900. function flags_to_cond(const f:TResFlags):TAsmCond;
  901. const
  902. flags_2_cond:array[TResFlags] of TAsmCond=
  903. (C_E,C_NE,C_G,C_L,C_GE,C_LE,C_C,C_NC,C_A,C_AE,C_B,C_BE);
  904. begin
  905. result:=flags_2_cond[f];
  906. end;
  907. procedure convert_register_to_enum(var r:Tregister);
  908. begin
  909. if (r.enum=R_INTREGISTER) then
  910. begin
  911. if r.number>NR_I7 then
  912. internalerror(200301082);
  913. r.enum:=TCpuRegister(r.number shr 8);
  914. end;
  915. end;
  916. function cgsize2subreg(s:Tcgsize):Tsubregister;
  917. begin
  918. cgsize2subreg:=R_SUBWHOLE;
  919. end;
  920. function supreg_name(r:Tsuperregister):string;
  921. const
  922. supreg_names:array[0..last_supreg] of string[4]=
  923. ('INV',
  924. 'g0','g1','g2','g3','g4','g5','g6','g7',
  925. 'o0','o1','o2','o3','o4','o5','o6','o7',
  926. 'l0','l1','l2','l3','l4','l5','l6','l7',
  927. 'i0','i1','i2','i3','i4','i5','i6','i7');
  928. var
  929. s : string[4];
  930. begin
  931. if r in [0..last_supreg] then
  932. supreg_name:=supreg_names[r]
  933. else
  934. begin
  935. str(r,s);
  936. supreg_name:='reg'+s;
  937. end;
  938. end;
  939. end.
  940. {
  941. $Log$
  942. Revision 1.45 2003-07-06 17:58:22 peter
  943. * framepointer fixes for sparc
  944. * parent framepointer code more generic
  945. Revision 1.44 2003/07/02 22:18:04 peter
  946. * paraloc splitted in callerparaloc,calleeparaloc
  947. * sparc calling convention updates
  948. Revision 1.43 2003/06/17 16:34:44 jonas
  949. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  950. * renamed all_intregisters to volatile_intregisters and made it
  951. processor dependent
  952. Revision 1.42 2003/06/13 21:08:30 peter
  953. * supreg_name added
  954. Revision 1.41 2003/06/12 19:11:34 jonas
  955. - removed ALL_INTREGISTERS (only the one in rgobj is valid)
  956. Revision 1.40 2003/06/04 21:00:54 mazen
  957. - making TOldRegister only declared for compatibility and
  958. no more used in cpubase
  959. Revision 1.39 2003/06/01 21:38:06 peter
  960. * getregisterfpu size parameter added
  961. * op_const_reg size parameter added
  962. * sparc updates
  963. Revision 1.38 2003/06/01 01:04:35 peter
  964. * reference fixes
  965. Revision 1.37 2003/05/31 15:05:28 peter
  966. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  967. Revision 1.36 2003/05/31 01:00:51 peter
  968. * register fixes
  969. Revision 1.35 2003/05/30 23:57:08 peter
  970. * more sparc cleanup
  971. * accumulator removed, splitted in function_return_reg (called) and
  972. function_result_reg (caller)
  973. }