cpubase.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. {
  2. Copyright (c) 2006 by Florian Klaempfl
  3. Contains the base types for the MOS Technology 6502
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {# Base unit for processor information. This unit contains
  18. enumerations of registers, opcodes, sizes, and other
  19. such things which are processor specific.
  20. }
  21. unit cpubase;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. cutils,cclasses,
  26. globtype,globals,
  27. cpuinfo,
  28. aasmbase,
  29. cgbase
  30. ;
  31. {*****************************************************************************
  32. Assembler Opcodes
  33. *****************************************************************************}
  34. type
  35. TAsmOp={$i mos6502op.inc}
  36. { This should define the array of instructions as string }
  37. op2strtable=array[tasmop] of string[4];
  38. const
  39. { First value of opcode enumeration }
  40. firstop = low(tasmop);
  41. { Last value of opcode enumeration }
  42. lastop = high(tasmop);
  43. std_op2str:op2strtable={$i mos6502stdopnames.inc}
  44. { call/reg instructions are not considered as jmp instructions for the usage cases of
  45. this set }
  46. jmp_instructions = [A_JMP,A_Bxx];
  47. call_jmp_instructions = [A_JSR]+jmp_instructions;
  48. { instructions that can have a condition }
  49. //cond_instructions = [A_CALL,A_JP,A_JR,A_JRJP,A_RET];
  50. {*****************************************************************************
  51. Registers
  52. *****************************************************************************}
  53. type
  54. { Number of registers used for indexing in tables }
  55. tregisterindex=0..{$i rmos6502nor.inc}-1;
  56. const
  57. { Available Superregisters }
  58. {$i rmos6502sup.inc}
  59. { No Subregisters }
  60. R_SUBWHOLE = R_SUBL;
  61. { Available Registers }
  62. {$i rmos6502con.inc}
  63. { Integer Super registers first and last }
  64. first_int_supreg = RS_A;
  65. first_int_imreg = 2048;
  66. { Float Super register first and last }
  67. first_fpu_supreg = RS_INVALID;
  68. first_fpu_imreg = 0;
  69. { MM Super register first and last }
  70. first_mm_supreg = RS_INVALID;
  71. first_mm_imreg = 0;
  72. regnumber_count_bsstart = 32;
  73. regnumber_table : array[tregisterindex] of tregister = (
  74. {$i rmos6502num.inc}
  75. );
  76. regstabs_table : array[tregisterindex] of shortint = (
  77. {$i rmos6502sta.inc}
  78. );
  79. regdwarf_table : array[tregisterindex] of shortint = (
  80. {$i rmos6502dwa.inc}
  81. );
  82. { registers which may be destroyed by calls }
  83. VOLATILE_INTREGISTERS = [RS_A,RS_X,RS_Y];
  84. VOLATILE_FPUREGISTERS = [];
  85. //type
  86. // totherregisterset = set of tregisterindex;
  87. {*****************************************************************************
  88. Conditions
  89. *****************************************************************************}
  90. type
  91. TAsmCond=(C_None,
  92. C_PL,C_MI,C_VC,C_VS,C_CC,C_CS,C_NE,C_EQ
  93. );
  94. const
  95. cond2str : array[TAsmCond] of string[2]=('',
  96. 'pl','mi','vc','vs','cc','cs','ne','eq'
  97. );
  98. uppercond2str : array[TAsmCond] of string[2]=('',
  99. 'PL','MI','VC','VS','CC','CS','NE','EQ'
  100. );
  101. {*****************************************************************************
  102. Flags
  103. *****************************************************************************}
  104. type
  105. TResFlags = (F_NotPossible,F_PL,F_MI,F_VC,F_VS,F_CC,F_CS,F_NE,F_EQ);
  106. {*****************************************************************************
  107. Constants
  108. *****************************************************************************}
  109. const
  110. max_operands = 2;
  111. maxintregs = 15;
  112. maxfpuregs = 0;
  113. maxaddrregs = 0;
  114. {*****************************************************************************
  115. Operand Sizes
  116. *****************************************************************************}
  117. type
  118. topsize = (S_NO,
  119. S_B,S_W,S_L,S_BW,S_BL,S_WL,
  120. S_IS,S_IL,S_IQ,
  121. S_FS,S_FL,S_FX,S_D,S_Q,S_FV,S_FXX
  122. );
  123. {*****************************************************************************
  124. Constants
  125. *****************************************************************************}
  126. const
  127. firstsaveintreg = RS_INVALID;
  128. lastsaveintreg = RS_INVALID;
  129. firstsavefpureg = RS_INVALID;
  130. lastsavefpureg = RS_INVALID;
  131. firstsavemmreg = RS_INVALID;
  132. lastsavemmreg = RS_INVALID;
  133. {*****************************************************************************
  134. Default generic sizes
  135. *****************************************************************************}
  136. { Defines the default address size for a processor, }
  137. OS_ADDR = OS_16;
  138. { the natural int size for a processor,
  139. has to match osuinttype/ossinttype as initialized in psystem,
  140. initially, this was OS_16/OS_S16 on avr, but experience has
  141. proven that it is better to make it 8 Bit thus having the same
  142. size as a register.
  143. }
  144. OS_INT = OS_8;
  145. OS_SINT = OS_S8;
  146. { the maximum float size for a processor, }
  147. OS_FLOAT = OS_F64;
  148. { the size of a vector register for a processor }
  149. OS_VECTOR = OS_M32;
  150. {*****************************************************************************
  151. Generic Register names
  152. *****************************************************************************}
  153. { Stack pointer register }
  154. NR_STACK_POINTER_REG = NR_S;
  155. RS_STACK_POINTER_REG = RS_S;
  156. { Frame pointer register }
  157. RS_FRAME_POINTER_REG = RS_RZW187;
  158. NR_FRAME_POINTER_REG = NR_RZW187;
  159. { Register for addressing absolute data in a position independant way,
  160. such as in PIC code. The exact meaning is ABI specific. For
  161. further information look at GCC source : PIC_OFFSET_TABLE_REGNUM
  162. }
  163. NR_PIC_OFFSET_REG = NR_INVALID;
  164. { Results are returned in this register (32-bit values) }
  165. NR_FUNCTION_RETURN_REG = NR_INVALID;
  166. RS_FUNCTION_RETURN_REG = RS_INVALID;
  167. { Low part of 64bit return value }
  168. NR_FUNCTION_RETURN64_LOW_REG = NR_INVALID;
  169. RS_FUNCTION_RETURN64_LOW_REG = RS_INVALID;
  170. { High part of 64bit return value }
  171. NR_FUNCTION_RETURN64_HIGH_REG = NR_INVALID;
  172. RS_FUNCTION_RETURN64_HIGH_REG = RS_INVALID;
  173. { The value returned from a function is available in this register }
  174. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  175. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  176. { The lowh part of 64bit value returned from a function }
  177. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  178. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  179. { The high part of 64bit value returned from a function }
  180. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  181. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  182. NR_FPU_RESULT_REG = NR_NO;
  183. NR_MM_RESULT_REG = NR_NO;
  184. NR_RETURN_ADDRESS_REG = NR_FUNCTION_RETURN_REG;
  185. { Offset where the parent framepointer is pushed }
  186. PARENT_FRAMEPOINTER_OFFSET = 0;
  187. NR_DEFAULTFLAGS = NR_P;
  188. RS_DEFAULTFLAGS = RS_P;
  189. {*****************************************************************************
  190. GCC /ABI linking information
  191. *****************************************************************************}
  192. const
  193. { Registers which must be saved when calling a routine declared as
  194. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  195. saved should be the ones as defined in the target ABI and / or GCC.
  196. This value can be deduced from the CALLED_USED_REGISTERS array in the
  197. GCC source.
  198. }
  199. { on avr, gen_entry/gen_exit code saves/restores registers, so
  200. we don't need this array }
  201. saved_standard_registers : array[0..0] of tsuperregister =
  202. (RS_INVALID);
  203. { Required parameter alignment when calling a routine declared as
  204. stdcall and cdecl. The alignment value should be the one defined
  205. by GCC or the target ABI.
  206. The value of this constant is equal to the constant
  207. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  208. }
  209. std_param_align = 4;
  210. saved_address_registers : array[0..0] of tsuperregister = (RS_INVALID);
  211. saved_mm_registers : array[0..0] of tsuperregister = (RS_INVALID);
  212. {*****************************************************************************
  213. Helpers
  214. *****************************************************************************}
  215. { Returns the tcgsize corresponding with the size of reg.}
  216. function reg_cgsize(const reg: tregister) : tcgsize;
  217. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  218. procedure inverse_flags(var f: TResFlags);
  219. function flags_to_cond(const f: TResFlags) : TAsmCond;
  220. function findreg_by_number(r:Tregister):tregisterindex;
  221. function std_regnum_search(const s:string):Tregister;
  222. function std_regname(r:Tregister):string;
  223. function is_6502_general_purpose_register(r:TRegister):boolean;
  224. function is_6502_index_register(r:TRegister):boolean;
  225. function is_6502_zero_page_register(r:TRegister):boolean;
  226. function get_6502_zero_page_register_address(r:TRegister): Byte;
  227. function is_regpair(r:Tregister):boolean;
  228. procedure split_regpair(regpair:Tregister;out reglo,reghi:Tregister);
  229. { Checks if sreg is a subset of reg (e.g. NR_H is a subset of NR_HL }
  230. function register_in(sreg,reg:Tregister):boolean;
  231. function super_registers_equal(reg1,reg2 : TRegister) : Boolean;
  232. function registers_interfere(reg1,reg2: TRegister) : Boolean;
  233. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  234. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  235. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  236. function condition_in(const Subset, c: TAsmCond): Boolean;
  237. function dwarf_reg(r:tregister):byte;
  238. function dwarf_reg_no_error(r:tregister):shortint;
  239. function eh_return_data_regno(nr: longint): longint;
  240. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  241. implementation
  242. uses
  243. rgBase,verbose;
  244. const
  245. std_regname_table : TRegNameTable = (
  246. {$i rmos6502std.inc}
  247. );
  248. regnumber_index : array[tregisterindex] of tregisterindex = (
  249. {$i rmos6502rni.inc}
  250. );
  251. std_regname_index : array[tregisterindex] of tregisterindex = (
  252. {$i rmos6502sri.inc}
  253. );
  254. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  255. begin
  256. cgsize2subreg:=R_SUBWHOLE;
  257. end;
  258. function reg_cgsize(const reg: tregister): tcgsize;
  259. begin
  260. case getregtype(reg) of
  261. R_INTREGISTER,
  262. R_SPECIALREGISTER:
  263. case getsubreg(reg) of
  264. R_SUBNONE,
  265. R_SUBL,
  266. R_SUBH:
  267. reg_cgsize:=OS_8;
  268. R_SUBW:
  269. reg_cgsize:=OS_16;
  270. else
  271. internalerror(2020041901);
  272. end;
  273. R_ADDRESSREGISTER:
  274. reg_cgsize:=OS_16;
  275. else
  276. internalerror(2011021905);
  277. end;
  278. end;
  279. procedure inverse_flags(var f: TResFlags);
  280. const
  281. inv_flags: array[TResFlags] of TResFlags =
  282. (F_NotPossible,F_MI,F_PL,F_VS,F_VC,F_CS,F_CC,F_EQ,F_NE);
  283. begin
  284. f:=inv_flags[f];
  285. end;
  286. function flags_to_cond(const f: TResFlags) : TAsmCond;
  287. const
  288. flag_2_cond: array[F_PL..F_EQ] of TAsmCond =
  289. (C_PL,C_MI,C_VC,C_VS,C_CC,C_CS,C_NE,C_EQ);
  290. begin
  291. if f=F_NotPossible then
  292. internalerror(2011022101);
  293. if f>high(flag_2_cond) then
  294. internalerror(200112301);
  295. result:=flag_2_cond[f];
  296. end;
  297. function findreg_by_number(r:Tregister):tregisterindex;
  298. begin
  299. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  300. end;
  301. function std_regnum_search(const s:string):Tregister;
  302. begin
  303. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  304. end;
  305. function std_regname(r:Tregister):string;
  306. var
  307. p : tregisterindex;
  308. begin
  309. p:=findreg_by_number_table(r,regnumber_index);
  310. if p<>0 then
  311. result:=std_regname_table[p]
  312. else
  313. result:=generic_regname(r);
  314. end;
  315. function is_6502_general_purpose_register(r:TRegister):boolean;
  316. begin
  317. result:=(r=NR_A) or (r=NR_X) or (r=NR_Y);
  318. end;
  319. function is_6502_index_register(r:TRegister):boolean;
  320. begin
  321. result:=(r=NR_X) or (r=NR_Y);
  322. end;
  323. function is_6502_zero_page_register(r:TRegister):boolean;
  324. begin
  325. result:=(getregtype(r)=R_INTREGISTER) and
  326. (((getsupreg(r)>=RS_RZB0) and (getsupreg(r)<=RS_RZB255)) or
  327. ((getsupreg(r)>=RS_RZW0) and (getsupreg(r)<=RS_RZW254)));
  328. end;
  329. function get_6502_zero_page_register_address(r:TRegister): Byte;
  330. var
  331. supreg: TSuperRegister;
  332. begin
  333. if getregtype(r)<>R_INTREGISTER then
  334. internalerror(2024050401);
  335. supreg:=getsupreg(r);
  336. if (supreg>=RS_RZB0) and (supreg<=RS_RZB255) then
  337. result:=supreg-RS_RZB0
  338. else if (supreg>=RS_RZW0) and (supreg<=RS_RZW254) then
  339. begin
  340. result:=supreg-RS_RZW0;
  341. if getsubreg(r)=R_SUBH then
  342. Inc(result);
  343. end
  344. else
  345. internalerror(2024050402);
  346. end;
  347. function is_regpair(r: Tregister): boolean;
  348. begin
  349. internalerror(2024040601);
  350. //result:=(r=NR_AF) or (r=NR_BC) or (r=NR_DE) or (r=NR_HL);
  351. end;
  352. procedure split_regpair(regpair: Tregister; out reglo, reghi: Tregister);
  353. begin
  354. internalerror(2024040601);
  355. //case regpair of
  356. // NR_AF:
  357. // begin
  358. // reglo:=NR_F;
  359. // reghi:=NR_A;
  360. // end;
  361. // NR_BC:
  362. // begin
  363. // reglo:=NR_C;
  364. // reghi:=NR_B;
  365. // end;
  366. // NR_DE:
  367. // begin
  368. // reglo:=NR_E;
  369. // reghi:=NR_D;
  370. // end;
  371. // NR_HL:
  372. // begin
  373. // reglo:=NR_L;
  374. // reghi:=NR_H;
  375. // end;
  376. // else
  377. // internalerror(2020042804);
  378. //end;
  379. end;
  380. function register_in(sreg,reg: Tregister):boolean;
  381. var
  382. tmpreg1, tmpreg2: Tregister;
  383. begin
  384. if sreg=reg then
  385. result:=true
  386. else if is_regpair(reg) then
  387. begin
  388. split_regpair(reg,tmpreg1,tmpreg2);
  389. result:=(sreg=tmpreg1) or (sreg=tmpreg2);
  390. end
  391. else
  392. result:=false;
  393. end;
  394. function super_registers_equal(reg1, reg2: TRegister): Boolean;
  395. begin
  396. internalerror(2024040601);
  397. //case reg1 of
  398. // NR_A,NR_F,NR_AF,NR_CARRYFLAG,NR_ADDSUBTRACTFLAG,NR_PARITYOVERFLOWFLAG,NR_HALFCARRYFLAG,NR_ZEROFLAG,NR_SIGNFLAG:
  399. // result:=(reg2=NR_A) or (reg2=NR_F) or (reg2=NR_AF) or
  400. // (reg2=NR_CARRYFLAG) or (reg2=NR_ADDSUBTRACTFLAG) or
  401. // (reg2=NR_PARITYOVERFLOWFLAG) or (reg2=NR_HALFCARRYFLAG) or
  402. // (reg2=NR_ZEROFLAG) or (reg2=NR_SIGNFLAG);
  403. // NR_B,NR_C,NR_BC:
  404. // result:=(reg2=NR_B) or (reg2=NR_C) or (reg2=NR_BC);
  405. // NR_D,NR_E,NR_DE:
  406. // result:=(reg2=NR_D) or (reg2=NR_E) or (reg2=NR_DE);
  407. // NR_H,NR_L,NR_HL:
  408. // result:=(reg2=NR_H) or (reg2=NR_L) or (reg2=NR_HL);
  409. // NR_A_,NR_F_,NR_AF_,NR_CARRYFLAG_,NR_ADDSUBTRACTFLAG_,NR_PARITYOVERFLOWFLAG_,NR_HALFCARRYFLAG_,NR_ZEROFLAG_,NR_SIGNFLAG_:
  410. // result:=(reg2=NR_A_) or (reg2=NR_F_) or (reg2=NR_AF_) or
  411. // (reg2=NR_CARRYFLAG_) or (reg2=NR_ADDSUBTRACTFLAG_) or
  412. // (reg2=NR_PARITYOVERFLOWFLAG_) or (reg2=NR_HALFCARRYFLAG_) or
  413. // (reg2=NR_ZEROFLAG_) or (reg2=NR_SIGNFLAG_);
  414. // NR_B_,NR_C_,NR_BC_:
  415. // result:=(reg2=NR_B_) or (reg2=NR_C_) or (reg2=NR_BC_);
  416. // NR_D_,NR_E_,NR_DE_:
  417. // result:=(reg2=NR_D_) or (reg2=NR_E_) or (reg2=NR_DE_);
  418. // NR_H_,NR_L_,NR_HL_:
  419. // result:=(reg2=NR_H_) or (reg2=NR_L_) or (reg2=NR_HL_);
  420. // else
  421. // result:=reg1=reg2;
  422. //end;
  423. end;
  424. function registers_interfere(reg1, reg2: TRegister): Boolean;
  425. begin
  426. internalerror(2024040601);
  427. //case reg1 of
  428. // NR_A:
  429. // result:=(reg2=NR_A) or (reg2=NR_AF);
  430. // NR_F:
  431. // result:=(reg2=NR_F) or (reg2=NR_AF) or
  432. // (reg2=NR_CARRYFLAG) or (reg2=NR_ADDSUBTRACTFLAG) or
  433. // (reg2=NR_PARITYOVERFLOWFLAG) or (reg2=NR_HALFCARRYFLAG) or
  434. // (reg2=NR_ZEROFLAG) or (reg2=NR_SIGNFLAG);
  435. // NR_AF:
  436. // result:=(reg2=NR_A) or (reg2=NR_F) or (reg2=NR_AF) or
  437. // (reg2=NR_CARRYFLAG) or (reg2=NR_ADDSUBTRACTFLAG) or
  438. // (reg2=NR_PARITYOVERFLOWFLAG) or (reg2=NR_HALFCARRYFLAG) or
  439. // (reg2=NR_ZEROFLAG) or (reg2=NR_SIGNFLAG);
  440. // NR_CARRYFLAG,NR_ADDSUBTRACTFLAG,NR_PARITYOVERFLOWFLAG,NR_HALFCARRYFLAG,NR_ZEROFLAG,NR_SIGNFLAG:
  441. // result:=(reg2=NR_F) or (reg2=NR_AF) or (reg2=reg1);
  442. // NR_B:
  443. // result:=(reg2=NR_B) or (reg2=NR_BC);
  444. // NR_C:
  445. // result:=(reg2=NR_C) or (reg2=NR_BC);
  446. // NR_BC:
  447. // result:=(reg2=NR_B) or (reg2=NR_C) or (reg2=NR_BC);
  448. // NR_D:
  449. // result:=(reg2=NR_D) or (reg2=NR_DE);
  450. // NR_E:
  451. // result:=(reg2=NR_E) or (reg2=NR_DE);
  452. // NR_DE:
  453. // result:=(reg2=NR_D) or (reg2=NR_E) or (reg2=NR_DE);
  454. // NR_H:
  455. // result:=(reg2=NR_H) or (reg2=NR_HL);
  456. // NR_L:
  457. // result:=(reg2=NR_L) or (reg2=NR_HL);
  458. // NR_HL:
  459. // result:=(reg2=NR_H) or (reg2=NR_L) or (reg2=NR_HL);
  460. // NR_A_:
  461. // result:=(reg2=NR_A_) or (reg2=NR_AF_);
  462. // NR_F_:
  463. // result:=(reg2=NR_F_) or (reg2=NR_AF_) or
  464. // (reg2=NR_CARRYFLAG_) or (reg2=NR_ADDSUBTRACTFLAG_) or
  465. // (reg2=NR_PARITYOVERFLOWFLAG_) or (reg2=NR_HALFCARRYFLAG_) or
  466. // (reg2=NR_ZEROFLAG_) or (reg2=NR_SIGNFLAG_);
  467. // NR_AF_:
  468. // result:=(reg2=NR_A_) or (reg2=NR_F_) or (reg2=NR_AF_) or
  469. // (reg2=NR_CARRYFLAG_) or (reg2=NR_ADDSUBTRACTFLAG_) or
  470. // (reg2=NR_PARITYOVERFLOWFLAG_) or (reg2=NR_HALFCARRYFLAG_) or
  471. // (reg2=NR_ZEROFLAG_) or (reg2=NR_SIGNFLAG_);
  472. // NR_CARRYFLAG_,NR_ADDSUBTRACTFLAG_,NR_PARITYOVERFLOWFLAG_,NR_HALFCARRYFLAG_,NR_ZEROFLAG_,NR_SIGNFLAG_:
  473. // result:=(reg2=NR_F_) or (reg2=NR_AF_) or (reg2=reg1);
  474. // NR_B_:
  475. // result:=(reg2=NR_B_) or (reg2=NR_BC_);
  476. // NR_C_:
  477. // result:=(reg2=NR_C_) or (reg2=NR_BC_);
  478. // NR_BC_:
  479. // result:=(reg2=NR_B_) or (reg2=NR_C_) or (reg2=NR_BC_);
  480. // NR_D_:
  481. // result:=(reg2=NR_D_) or (reg2=NR_DE_);
  482. // NR_E_:
  483. // result:=(reg2=NR_E_) or (reg2=NR_DE_);
  484. // NR_DE_:
  485. // result:=(reg2=NR_D_) or (reg2=NR_E_) or (reg2=NR_DE_);
  486. // NR_H_:
  487. // result:=(reg2=NR_H_) or (reg2=NR_HL_);
  488. // NR_L_:
  489. // result:=(reg2=NR_L_) or (reg2=NR_HL_);
  490. // NR_HL_:
  491. // result:=(reg2=NR_H_) or (reg2=NR_L_) or (reg2=NR_HL_);
  492. // else
  493. // result:=reg1=reg2;
  494. //end;
  495. end;
  496. function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  497. const
  498. inverse: array[TAsmCond] of TAsmCond=(C_None,
  499. C_MI,C_PL,C_VS,C_VC,C_CS,C_CC,C_EQ,C_NE);
  500. begin
  501. result := inverse[c];
  502. end;
  503. function conditions_equal(const c1, c2: TAsmCond): boolean; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  504. begin
  505. result := c1 = c2;
  506. end;
  507. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  508. function condition_in(const Subset, c: TAsmCond): Boolean;
  509. begin
  510. { 6502 has no condition subsets }
  511. Result := {(c.cond = C_None) or} conditions_equal(Subset, c);
  512. end;
  513. function rotl(d : dword;b : byte) : dword;
  514. begin
  515. result:=(d shr (32-b)) or (d shl b);
  516. end;
  517. function dwarf_reg(r:tregister):byte;
  518. var
  519. reg : shortint;
  520. begin
  521. reg:=regdwarf_table[findreg_by_number(r)];
  522. if reg=-1 then
  523. internalerror(200603251);
  524. result:=reg;
  525. end;
  526. function dwarf_reg_no_error(r:tregister):shortint;
  527. begin
  528. result:=regdwarf_table[findreg_by_number(r)];
  529. end;
  530. function eh_return_data_regno(nr: longint): longint;
  531. begin
  532. result:=-1;
  533. end;
  534. function is_calljmp(o:tasmop):boolean;{$ifdef USEINLINE}inline;{$endif USEINLINE}
  535. begin
  536. is_calljmp:= o in call_jmp_instructions;
  537. end;
  538. end.