cpubase.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. const
  44. { Invalid register number }
  45. RS_INVALID = $ff;
  46. { Integer Super registers }
  47. RS_G0=$00;
  48. RS_G1=$01;
  49. RS_G2=$02;
  50. RS_G3=$03;
  51. RS_G4=$04;
  52. RS_G5=$05;
  53. RS_G6=$06;
  54. RS_G7=$07;
  55. RS_O0=$08;
  56. RS_O1=$09;
  57. RS_O2=$0a;
  58. RS_O3=$0b;
  59. RS_O4=$0c;
  60. RS_O5=$0d;
  61. RS_O6=$0e;
  62. RS_O7=$0f;
  63. RS_L0=$10;
  64. RS_L1=$11;
  65. RS_L2=$12;
  66. RS_L3=$13;
  67. RS_L4=$14;
  68. RS_L5=$15;
  69. RS_L6=$16;
  70. RS_L7=$17;
  71. RS_I0=$18;
  72. RS_I1=$19;
  73. RS_I2=$1a;
  74. RS_I3=$1b;
  75. RS_I4=$1c;
  76. RS_I5=$1d;
  77. RS_I6=$1e;
  78. RS_I7=$1f;
  79. {$warning Supreg shall be $00-$1f}
  80. first_int_supreg = $08;
  81. last_int_supreg = $17;
  82. first_int_imreg = $20;
  83. last_int_imreg = $fe;
  84. { Float Super registers }
  85. RS_F0=$00;
  86. RS_F1=$01;
  87. RS_F2=$02;
  88. RS_F3=$03;
  89. RS_F4=$04;
  90. RS_F5=$05;
  91. RS_F6=$06;
  92. RS_F7=$07;
  93. RS_F8=$08;
  94. RS_F9=$09;
  95. RS_F10=$0a;
  96. RS_F11=$0b;
  97. RS_F12=$0c;
  98. RS_F13=$0d;
  99. RS_F14=$0e;
  100. RS_F15=$0f;
  101. RS_F16=$10;
  102. RS_F17=$11;
  103. RS_F18=$12;
  104. RS_F19=$13;
  105. RS_F20=$14;
  106. RS_F21=$15;
  107. RS_F22=$16;
  108. RS_F23=$17;
  109. RS_F24=$18;
  110. RS_F25=$19;
  111. RS_F26=$1a;
  112. RS_F27=$1b;
  113. RS_F28=$1c;
  114. RS_F29=$1d;
  115. RS_F30=$1e;
  116. RS_F31=$1f;
  117. { Float Super register first and last }
  118. first_fpu_supreg = $00;
  119. last_fpu_supreg = $1f;
  120. first_fpu_imreg = $20;
  121. last_fpu_imreg = $fe;
  122. { MM Super register first and last }
  123. first_mmx_supreg = RS_INVALID;
  124. last_mmx_supreg = RS_INVALID;
  125. first_mmx_imreg = RS_INVALID;
  126. last_mmx_imreg = RS_INVALID;
  127. { No Subregisters }
  128. R_SUBWHOLE=R_SUBNONE;
  129. { Available Registers }
  130. {$i rspcon.inc}
  131. type
  132. { Number of registers used for indexing in tables }
  133. tregisterindex=0..{$i rspnor.inc}-1;
  134. const
  135. {$warning TODO Calculate bsstart}
  136. regnumber_count_bsstart = 128;
  137. regnumber_table : array[tregisterindex] of tregister = (
  138. {$i rspnum.inc}
  139. );
  140. regstabs_table : array[tregisterindex] of tregister = (
  141. {$i rspstab.inc}
  142. );
  143. { registers which may be destroyed by calls }
  144. VOLATILE_INTREGISTERS = [RS_G1];
  145. {$warning FIXME!!}
  146. VOLATILE_FPUREGISTERS = [];
  147. type
  148. totherregisterset = set of tregisterindex;
  149. {*****************************************************************************
  150. Conditions
  151. *****************************************************************************}
  152. type
  153. TAsmCond=(C_None,
  154. C_A,C_AE,C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_NA,C_NAE,
  155. C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_NO,C_NP,
  156. C_NS,C_NZ,C_O,C_P,C_PE,C_PO,C_S,C_Z
  157. );
  158. const
  159. cond2str:array[TAsmCond] of string[3]=('',
  160. 'gu','cc','cs','leu','cs','e','g','ge','l','le','leu','cs',
  161. 'cc','gu','cc','ne','le','l','ge','g','vc','XX',
  162. 'pos','ne','vs','XX','XX','XX','vs','e'
  163. );
  164. inverse_cond:array[TAsmCond] of TAsmCond=(C_None,
  165. C_NA,C_NAE,C_NB,C_NBE,C_NC,C_NE,C_NG,C_NGE,C_NL,C_NLE,C_A,C_AE,
  166. C_B,C_BE,C_C,C_E,C_G,C_GE,C_L,C_LE,C_O,C_P,
  167. C_S,C_Z,C_NO,C_NP,C_NP,C_P,C_NS,C_NZ
  168. );
  169. const
  170. CondAsmOps=1;
  171. CondAsmOp:array[0..CondAsmOps-1] of TAsmOp=(
  172. A_Bxx
  173. );
  174. CondAsmOpStr:array[0..CondAsmOps-1] of string[7]=(
  175. 'B'
  176. );
  177. {*****************************************************************************
  178. Flags
  179. *****************************************************************************}
  180. type
  181. TResFlags=(
  182. F_E, {Equal}
  183. F_NE, {Not Equal}
  184. F_G, {Greater}
  185. F_L, {Less}
  186. F_GE, {Greater or Equal}
  187. F_LE, {Less or Equal}
  188. F_C, {Carry}
  189. F_NC, {Not Carry}
  190. F_A, {Above}
  191. F_AE, {Above or Equal}
  192. F_B, {Below}
  193. F_BE {Below or Equal}
  194. );
  195. {*****************************************************************************
  196. Reference
  197. *****************************************************************************}
  198. type
  199. TRefOptions=(ref_none,ref_parafixup,ref_localfixup,ref_selffixup);
  200. { since we have no full 32 bit offsets, we need to be able to specify the high
  201. and low bits of the address of a symbol }
  202. trefsymaddr = (refs_no,refs_full,refs_hi,refs_lo);
  203. { reference record }
  204. preference = ^treference;
  205. treference = packed record
  206. { base register, R_NO if none }
  207. base,
  208. { index register, R_NO if none }
  209. index : tregister;
  210. { offset, 0 if none }
  211. offset : longint;
  212. { symbol this reference refers to, nil if none }
  213. symbol : tasmsymbol;
  214. { used in conjunction with symbols and offsets: refs_full means }
  215. { means a full 32bit reference, refs_hi means the upper 16 bits }
  216. { and refs_lo the lower 16 bits of the address }
  217. symaddr : trefsymaddr;
  218. { changed when inlining and possibly in other cases, don't }
  219. { set manually }
  220. offsetfixup : longint;
  221. { used in conjunction with the previous field }
  222. options : trefoptions;
  223. { alignment this reference is guaranteed to have }
  224. alignment : byte;
  225. end;
  226. { reference record }
  227. pparareference = ^tparareference;
  228. tparareference = packed record
  229. index : tregister;
  230. offset : aword;
  231. end;
  232. const
  233. symaddr2str: array[trefsymaddr] of string[3] = ('','','%hi','%lo');
  234. {*****************************************************************************
  235. Operand
  236. *****************************************************************************}
  237. type
  238. toptype=(top_none,top_reg,top_ref,top_const,top_symbol);
  239. toper=record
  240. ot:LongInt;
  241. case typ:toptype of
  242. top_none:();
  243. top_reg:(reg:tregister);
  244. top_ref:(ref:preference);
  245. top_const:(val:aword);
  246. top_symbol:(sym:tasmsymbol;symofs:LongInt);
  247. end;
  248. {*****************************************************************************
  249. Operand Sizes
  250. *****************************************************************************}
  251. {$ifdef dummy}
  252. {*****************************************************************************
  253. Argument Classification
  254. *****************************************************************************}
  255. type
  256. TArgClass = (
  257. { the following classes should be defined by all processor implemnations }
  258. AC_NOCLASS,
  259. AC_MEMORY,
  260. AC_INTEGER,
  261. AC_FPU,
  262. { the following argument classes are i386 specific }
  263. AC_FPUUP,
  264. AC_SSE,
  265. AC_SSEUP);
  266. {$endif dummy}
  267. {*****************************************************************************
  268. Generic Location
  269. *****************************************************************************}
  270. type
  271. { tparamlocation describes where a parameter for a procedure is stored.
  272. References are given from the caller's point of view. The usual
  273. TLocation isn't used, because contains a lot of unnessary fields.
  274. }
  275. tparalocation = packed record
  276. size : TCGSize;
  277. { The location type where the parameter is passed, usually
  278. LOC_REFERENCE,LOC_REGISTER or LOC_FPUREGISTER
  279. }
  280. loc : TCGLoc;
  281. { The stack pointer must be decreased by this value before
  282. the parameter is copied to the given destination.
  283. This allows to "encode" pushes with tparalocation.
  284. On the PowerPC, this field is unsed but it is there
  285. because several generic code accesses it.
  286. }
  287. sp_fixup : longint;
  288. case TCGLoc of
  289. LOC_REFERENCE : (reference : tparareference; low_in_reg: boolean; lowreg : tregister);
  290. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  291. LOC_REGISTER,LOC_CREGISTER : (
  292. case longint of
  293. 1 : (register,registerhigh : tregister);
  294. { overlay a registerlow }
  295. 2 : (registerlow : tregister);
  296. { overlay a 64 Bit register type }
  297. 3 : (reg64 : tregister64);
  298. 4 : (register64 : tregister64);
  299. );
  300. end;
  301. treglocation = packed record
  302. case longint of
  303. 1 : (register,registerhigh : tregister);
  304. { overlay a registerlow }
  305. 2 : (registerlow : tregister);
  306. { overlay a 64 Bit register type }
  307. 3 : (reg64 : tregister64);
  308. 4 : (register64 : tregister64);
  309. end;
  310. tlocation = packed record
  311. size : TCGSize;
  312. loc : tcgloc;
  313. case tcgloc of
  314. LOC_CREFERENCE,LOC_REFERENCE : (reference : treference);
  315. LOC_CONSTANT : (
  316. case longint of
  317. {$ifdef FPC_BIG_ENDIAN}
  318. 1 : (_valuedummy,value : AWord);
  319. {$else FPC_BIG_ENDIAN}
  320. 1 : (value : AWord);
  321. {$endif FPC_BIG_ENDIAN}
  322. { can't do this, this layout depends on the host cpu. Use }
  323. { lo(valueqword)/hi(valueqword) instead (JM) }
  324. { 2 : (valuelow, valuehigh:AWord); }
  325. { overlay a complete 64 Bit value }
  326. 3 : (valueqword : qword);
  327. );
  328. LOC_FPUREGISTER, LOC_CFPUREGISTER, LOC_MMREGISTER, LOC_CMMREGISTER,
  329. LOC_REGISTER,LOC_CREGISTER : (
  330. case longint of
  331. 1 : (registerlow,registerhigh : tregister);
  332. 2 : (register : tregister);
  333. { overlay a 64 Bit register type }
  334. 3 : (reg64 : tregister64);
  335. 4 : (register64 : tregister64);
  336. );
  337. LOC_FLAGS : (resflags : tresflags);
  338. end;
  339. {*****************************************************************************
  340. Constants
  341. *****************************************************************************}
  342. const
  343. max_operands = 3;
  344. {# Constant defining possibly all registers which might require saving }
  345. ALL_OTHERREGISTERS = [];
  346. general_superregisters = [RS_O0..RS_I7];
  347. {# Table of registers which can be allocated by the code generator
  348. internally, when generating the code.
  349. }
  350. { legend: }
  351. { xxxregs = set of all possibly used registers of that type in the code }
  352. { generator }
  353. { usableregsxxx = set of all 32bit components of registers that can be }
  354. { possible allocated to a regvar or using getregisterxxx (this }
  355. { excludes registers which can be only used for parameter }
  356. { passing on ABI's that define this) }
  357. { c_countusableregsxxx = amount of registers in the usableregsxxx set }
  358. maxintregs = 8;
  359. { to determine how many registers to use for regvars }
  360. maxintscratchregs = 3;
  361. usableregsint = [RS_L0..RS_L7];
  362. c_countusableregsint = 8;
  363. maxfpuregs = 8;
  364. usableregsfpu=[RS_F0..RS_F31];
  365. c_countusableregsfpu=32;
  366. mmregs = [];
  367. usableregsmm = [];
  368. c_countusableregsmm = 0;
  369. { no distinction on this platform }
  370. maxaddrregs = 0;
  371. addrregs = [];
  372. usableregsaddr = [];
  373. c_countusableregsaddr = 0;
  374. {$warning firstsaveintreg shall be RS_NO}
  375. firstsaveintreg = RS_L0; { Temporary, having RS_NO is broken }
  376. lastsaveintreg = RS_L0; { L0..L7 are already saved, I0..O7 are parameter }
  377. firstsavefpureg = RS_F2; { F0..F1 is used for return value }
  378. lastsavefpureg = RS_F31;
  379. firstsavemmreg = RS_INVALID;
  380. lastsavemmreg = RS_INVALID;
  381. maxvarregs = 8;
  382. varregs : Array [1..maxvarregs] of Tsuperregister =
  383. (RS_L0,RS_L1,RS_L2,RS_L3,RS_L4,RS_L5,RS_L6,RS_L7);
  384. maxfpuvarregs = 1;
  385. fpuvarregs : Array [1..maxfpuvarregs] of TsuperRegister =
  386. (RS_F2);
  387. {
  388. max_param_regs_int = 6;
  389. param_regs_int: Array[1..max_param_regs_int] of TCpuRegister =
  390. (R_3,R_4,R_5,R_6,R_7,R_8,R_9,R_10);
  391. max_param_regs_fpu = 13;
  392. param_regs_fpu: Array[1..max_param_regs_fpu] of TCpuRegister =
  393. (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);
  394. max_param_regs_mm = 13;
  395. param_regs_mm: Array[1..max_param_regs_mm] of TCpuRegister =
  396. (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);
  397. }
  398. {*****************************************************************************
  399. Default generic sizes
  400. *****************************************************************************}
  401. {# Defines the default address size for a processor, }
  402. OS_ADDR = OS_32;
  403. {# the natural int size for a processor, }
  404. OS_INT = OS_32;
  405. {# the maximum float size for a processor, }
  406. OS_FLOAT = OS_F64;
  407. {# the size of a vector register for a processor }
  408. OS_VECTOR = OS_M64;
  409. {*****************************************************************************
  410. Generic Register names
  411. *****************************************************************************}
  412. {# Stack pointer register }
  413. NR_STACK_POINTER_REG = NR_O6;
  414. RS_STACK_POINTER_REG = RS_O6;
  415. {# Frame pointer register }
  416. NR_FRAME_POINTER_REG = NR_I6;
  417. RS_FRAME_POINTER_REG = RS_I6;
  418. {# Register for addressing absolute data in a position independant way,
  419. such as in PIC code. The exact meaning is ABI specific. For
  420. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  421. Taken from GCC rs6000.h
  422. }
  423. {$warning As indicated in rs6000.h, but can't find it anywhere else!}
  424. {PIC_OFFSET_REG = R_30;}
  425. { the return_result_reg, is used inside the called function to store its return
  426. value when that is a scalar value otherwise a pointer to the address of the
  427. result is placed inside it }
  428. { Results are returned in this register (32-bit values) }
  429. NR_FUNCTION_RETURN_REG = NR_I0;
  430. RS_FUNCTION_RETURN_REG = RS_I0;
  431. { Low part of 64bit return value }
  432. NR_FUNCTION_RETURN64_LOW_REG = NR_I1;
  433. RS_FUNCTION_RETURN64_LOW_REG = RS_I1;
  434. { High part of 64bit return value }
  435. NR_FUNCTION_RETURN64_HIGH_REG = NR_I0;
  436. RS_FUNCTION_RETURN64_HIGH_REG = RS_I0;
  437. { The value returned from a function is available in this register }
  438. NR_FUNCTION_RESULT_REG = NR_O0;
  439. RS_FUNCTION_RESULT_REG = RS_O0;
  440. { The lowh part of 64bit value returned from a function }
  441. NR_FUNCTION_RESULT64_LOW_REG = NR_O1;
  442. RS_FUNCTION_RESULT64_LOW_REG = RS_O1;
  443. { The high part of 64bit value returned from a function }
  444. NR_FUNCTION_RESULT64_HIGH_REG = NR_O0;
  445. RS_FUNCTION_RESULT64_HIGH_REG = RS_O0;
  446. NR_FPU_RESULT_REG = NR_F0;
  447. NR_MM_RESULT_REG = NR_NO;
  448. PARENT_FRAMEPOINTER_OFFSET = 68; { o0 }
  449. {*****************************************************************************
  450. GCC /ABI linking information
  451. *****************************************************************************}
  452. {# Registers which must be saved when calling a routine declared as
  453. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  454. saved should be the ones as defined in the target ABI and / or GCC.
  455. This value can be deduced from CALLED_USED_REGISTERS array in the
  456. GCC source.
  457. }
  458. std_saved_registers = [];
  459. {# Required parameter alignment when calling a routine declared as
  460. stdcall and cdecl. The alignment value should be the one defined
  461. by GCC or the target ABI.
  462. The value of this constant is equal to the constant
  463. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  464. }
  465. std_param_align = 4; { for 32-bit version only }
  466. {*****************************************************************************
  467. CPU Dependent Constants
  468. *****************************************************************************}
  469. const
  470. simm13lo=-4096;
  471. simm13hi=4095;
  472. {*****************************************************************************
  473. Helpers
  474. *****************************************************************************}
  475. function is_calljmp(o:tasmop):boolean;
  476. procedure inverse_flags(var f: TResFlags);
  477. function flags_to_cond(const f: TResFlags) : TAsmCond;
  478. function cgsize2subreg(s:Tcgsize):Tsubregister;
  479. function findreg_by_number(r:Tregister):tregisterindex;
  480. function std_regnum_search(const s:string):Tregister;
  481. function std_regname(r:Tregister):string;
  482. function gas_regname(r:Tregister):string;
  483. implementation
  484. uses
  485. verbose;
  486. const
  487. std_regname_table : array[tregisterindex] of string[7] = (
  488. {$i rspstd.inc}
  489. );
  490. regnumber_index : array[tregisterindex] of tregisterindex = (
  491. {$i rsprni.inc}
  492. );
  493. std_regname_index : array[tregisterindex] of tregisterindex = (
  494. {$i rspsri.inc}
  495. );
  496. {*****************************************************************************
  497. Helpers
  498. *****************************************************************************}
  499. function is_calljmp(o:tasmop):boolean;
  500. const
  501. CallJmpOp=[A_JMPL..A_CBccc];
  502. begin
  503. is_calljmp:=(o in CallJmpOp);
  504. end;
  505. procedure inverse_flags(var f: TResFlags);
  506. const
  507. inv_flags: array[TResFlags] of TResFlags =
  508. (F_NE,F_E,F_LE,F_GE,F_L,F_G,F_NC,F_C,F_BE,F_B,F_AE,F_A);
  509. begin
  510. f:=inv_flags[f];
  511. end;
  512. function flags_to_cond(const f:TResFlags):TAsmCond;
  513. const
  514. flags_2_cond:array[TResFlags] of TAsmCond=
  515. (C_E,C_NE,C_G,C_L,C_GE,C_LE,C_C,C_NC,C_A,C_AE,C_B,C_BE);
  516. begin
  517. result:=flags_2_cond[f];
  518. end;
  519. function cgsize2subreg(s:Tcgsize):Tsubregister;
  520. begin
  521. cgsize2subreg:=R_SUBWHOLE;
  522. end;
  523. function findreg_by_stdname(const s:string):byte;
  524. var
  525. i,p : tregisterindex;
  526. begin
  527. {Binary search.}
  528. p:=0;
  529. i:=regnumber_count_bsstart;
  530. repeat
  531. if (p+i<=high(tregisterindex)) and (std_regname_table[std_regname_index[p+i]]<=s) then
  532. p:=p+i;
  533. i:=i shr 1;
  534. until i=0;
  535. if std_regname_table[std_regname_index[p]]=s then
  536. result:=std_regname_index[p]
  537. else
  538. result:=0;
  539. end;
  540. function findreg_by_number(r:Tregister):tregisterindex;
  541. var
  542. i,p : tregisterindex;
  543. begin
  544. {Binary search.}
  545. p:=0;
  546. i:=regnumber_count_bsstart;
  547. repeat
  548. if (p+i<=high(tregisterindex)) and (regnumber_table[regnumber_index[p+i]]<=r) then
  549. p:=p+i;
  550. i:=i shr 1;
  551. until i=0;
  552. if regnumber_table[regnumber_index[p]]=r then
  553. result:=regnumber_index[p]
  554. else
  555. result:=0;
  556. end;
  557. function std_regnum_search(const s:string):Tregister;
  558. begin
  559. result:=regnumber_table[findreg_by_stdname(s)];
  560. end;
  561. function std_regname(r:Tregister):string;
  562. var
  563. p : tregisterindex;
  564. begin
  565. p:=findreg_by_number(r);
  566. if p<>0 then
  567. result:=std_regname_table[p]
  568. else
  569. result:=generic_regname(r);
  570. end;
  571. function gas_regname(r:Tregister):string;
  572. var
  573. p : tregisterindex;
  574. begin
  575. p:=findreg_by_number(r);
  576. if p<>0 then
  577. result:=std_regname_table[p]
  578. else
  579. result:=generic_regname(r);
  580. end;
  581. end.
  582. {
  583. $Log$
  584. Revision 1.48 2003-09-03 15:55:01 peter
  585. * NEWRA branch merged
  586. Revision 1.47.2.3 2003/09/02 17:49:17 peter
  587. * newra updates
  588. Revision 1.47.2.2 2003/09/01 21:02:55 peter
  589. * sparc updates for new tregister
  590. Revision 1.47.2.1 2003/08/31 21:08:16 peter
  591. * first batch of sparc fixes
  592. Revision 1.47 2003/08/19 13:22:51 mazen
  593. + implemented gas_regname based on convert_register_to_enum std_Reg2str
  594. Revision 1.46 2003/08/17 16:59:20 jonas
  595. * fixed regvars so they work with newra (at least for ppc)
  596. * fixed some volatile register bugs
  597. + -dnotranslation option for -dnewra, which causes the registers not to
  598. be translated from virtual to normal registers. Requires support in
  599. the assembler writer as well, which is only implemented in aggas/
  600. agppcgas currently
  601. Revision 1.45 2003/07/06 17:58:22 peter
  602. * framepointer fixes for sparc
  603. * parent framepointer code more generic
  604. Revision 1.44 2003/07/02 22:18:04 peter
  605. * paraloc splitted in callerparaloc,calleeparaloc
  606. * sparc calling convention updates
  607. Revision 1.43 2003/06/17 16:34:44 jonas
  608. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  609. * renamed all_intregisters to volatile_intregisters and made it
  610. processor dependent
  611. Revision 1.42 2003/06/13 21:08:30 peter
  612. * supreg_name added
  613. Revision 1.41 2003/06/12 19:11:34 jonas
  614. - removed ALL_INTREGISTERS (only the one in rgobj is valid)
  615. Revision 1.40 2003/06/04 21:00:54 mazen
  616. - making TOldRegister only declared for compatibility and
  617. no more used in cpubase
  618. Revision 1.39 2003/06/01 21:38:06 peter
  619. * getregisterfpu size parameter added
  620. * op_const_reg size parameter added
  621. * sparc updates
  622. Revision 1.38 2003/06/01 01:04:35 peter
  623. * reference fixes
  624. Revision 1.37 2003/05/31 15:05:28 peter
  625. * FUNCTION_RESULT64_LOW/HIGH_REG added for int64 results
  626. Revision 1.36 2003/05/31 01:00:51 peter
  627. * register fixes
  628. Revision 1.35 2003/05/30 23:57:08 peter
  629. * more sparc cleanup
  630. * accumulator removed, splitted in function_return_reg (called) and
  631. function_result_reg (caller)
  632. }