cpubase.pas 35 KB

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