aasmcpu.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  1. {
  2. Copyright (c) 2003 by Florian Klaempfl
  3. Contains the assembler object for the ARM
  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. unit aasmcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,globtype,globals,verbose,
  22. aasmbase,aasmtai,
  23. symtype,
  24. cpubase,cpuinfo,cgbase,cgutils;
  25. const
  26. { "mov reg,reg" source operand number }
  27. O_MOV_SOURCE = 1;
  28. { "mov reg,reg" source operand number }
  29. O_MOV_DEST = 0;
  30. maxinfolen = 5;
  31. IF_NONE = $00000000;
  32. IF_ARMMASK = $000F0000;
  33. { if the instruction can change in a second pass }
  34. IF_PASS2 = longint($80000000);
  35. type
  36. tinsentry = record
  37. opcode : tasmop;
  38. ops : byte;
  39. optypes : array[0..2] of longint;
  40. code : array[0..maxinfolen] of char;
  41. flags : longint;
  42. end;
  43. pinsentry=^tinsentry;
  44. taicpu = class(tai_cpu_abstract)
  45. oppostfix : TOpPostfix;
  46. roundingmode : troundingmode;
  47. procedure loadshifterop(opidx:longint;const so:tshifterop);
  48. procedure loadregset(opidx:longint;const s:tcpuregisterset);
  49. constructor op_none(op : tasmop);
  50. constructor op_reg(op : tasmop;_op1 : tregister);
  51. constructor op_const(op : tasmop;_op1 : longint);
  52. constructor op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  53. constructor op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  54. constructor op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
  55. constructor op_ref_regset(op:tasmop; _op1: treference; _op2: tcpuregisterset);
  56. constructor op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  57. constructor op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: aint);
  58. constructor op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  59. constructor op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  60. constructor op_reg_reg_shifterop(op : tasmop;_op1,_op2 : tregister;_op3 : tshifterop);
  61. { SFM/LFM }
  62. constructor op_reg_const_ref(op : tasmop;_op1 : tregister;_op2 : aint;_op3 : treference);
  63. { *M*LL }
  64. constructor op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  65. { this is for Jmp instructions }
  66. constructor op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  67. constructor op_sym(op : tasmop;_op1 : tasmsymbol);
  68. constructor op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  69. constructor op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  70. constructor op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  71. function is_same_reg_move(regtype: Tregistertype):boolean; override;
  72. function spilling_get_operation_type(opnr: longint): topertype;override;
  73. { assembler }
  74. public
  75. { the next will reset all instructions that can change in pass 2 }
  76. procedure ResetPass1;
  77. procedure ResetPass2;
  78. function CheckIfValid:boolean;
  79. function Pass1(offset:longint):longint;virtual;
  80. procedure Pass2(objdata:TAsmObjectdata);virtual;
  81. protected
  82. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);override;
  83. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);override;
  84. procedure ppubuildderefimploper(var o:toper);override;
  85. procedure ppuderefoper(var o:toper);override;
  86. private
  87. { next fields are filled in pass1, so pass2 is faster }
  88. inssize : shortint;
  89. insoffset : longint;
  90. LastInsOffset : longint; { need to be public to be reset }
  91. insentry : PInsEntry;
  92. function InsEnd:longint;
  93. procedure create_ot;
  94. function Matches(p:PInsEntry):longint;
  95. function calcsize(p:PInsEntry):shortint;
  96. procedure gencode(objdata:TAsmObjectData);
  97. function NeedAddrPrefix(opidx:byte):boolean;
  98. procedure Swapoperands;
  99. function FindInsentry:boolean;
  100. end;
  101. tai_align = class(tai_align_abstract)
  102. { nothing to add }
  103. end;
  104. function spilling_create_load(const ref:treference;r:tregister): tai;
  105. function spilling_create_store(r:tregister; const ref:treference): tai;
  106. function setoppostfix(i : taicpu;pf : toppostfix) : taicpu;
  107. function setroundingmode(i : taicpu;rm : troundingmode) : taicpu;
  108. function setcondition(i : taicpu;c : tasmcond) : taicpu;
  109. { inserts pc relative symbols at places where they are reachable }
  110. procedure insertpcrelativedata(list,listtoinsert : taasmoutput);
  111. procedure InitAsm;
  112. procedure DoneAsm;
  113. implementation
  114. uses
  115. cutils,rgobj,itcpugas;
  116. procedure taicpu.loadshifterop(opidx:longint;const so:tshifterop);
  117. begin
  118. allocate_oper(opidx+1);
  119. with oper[opidx]^ do
  120. begin
  121. if typ<>top_shifterop then
  122. begin
  123. clearop(opidx);
  124. new(shifterop);
  125. end;
  126. shifterop^:=so;
  127. typ:=top_shifterop;
  128. if assigned(add_reg_instruction_hook) then
  129. add_reg_instruction_hook(self,shifterop^.rs);
  130. end;
  131. end;
  132. procedure taicpu.loadregset(opidx:longint;const s:tcpuregisterset);
  133. var
  134. i : byte;
  135. begin
  136. allocate_oper(opidx+1);
  137. with oper[opidx]^ do
  138. begin
  139. if typ<>top_regset then
  140. clearop(opidx);
  141. new(regset);
  142. regset^:=s;
  143. typ:=top_regset;
  144. for i:=RS_R0 to RS_R15 do
  145. begin
  146. if assigned(add_reg_instruction_hook) and (i in regset^) then
  147. add_reg_instruction_hook(self,newreg(R_INTREGISTER,i,R_SUBWHOLE));
  148. end;
  149. end;
  150. end;
  151. {*****************************************************************************
  152. taicpu Constructors
  153. *****************************************************************************}
  154. constructor taicpu.op_none(op : tasmop);
  155. begin
  156. inherited create(op);
  157. end;
  158. constructor taicpu.op_reg(op : tasmop;_op1 : tregister);
  159. begin
  160. inherited create(op);
  161. ops:=1;
  162. loadreg(0,_op1);
  163. end;
  164. constructor taicpu.op_const(op : tasmop;_op1 : longint);
  165. begin
  166. inherited create(op);
  167. ops:=1;
  168. loadconst(0,aint(_op1));
  169. end;
  170. constructor taicpu.op_reg_reg(op : tasmop;_op1,_op2 : tregister);
  171. begin
  172. inherited create(op);
  173. ops:=2;
  174. loadreg(0,_op1);
  175. loadreg(1,_op2);
  176. end;
  177. constructor taicpu.op_reg_const(op:tasmop; _op1: tregister; _op2: aint);
  178. begin
  179. inherited create(op);
  180. ops:=2;
  181. loadreg(0,_op1);
  182. loadconst(1,aint(_op2));
  183. end;
  184. constructor taicpu.op_ref_regset(op:tasmop; _op1: treference; _op2: tcpuregisterset);
  185. begin
  186. inherited create(op);
  187. ops:=2;
  188. loadref(0,_op1);
  189. loadregset(1,_op2);
  190. end;
  191. constructor taicpu.op_reg_ref(op : tasmop;_op1 : tregister;const _op2 : treference);
  192. begin
  193. inherited create(op);
  194. ops:=2;
  195. loadreg(0,_op1);
  196. loadref(1,_op2);
  197. end;
  198. constructor taicpu.op_reg_reg_reg(op : tasmop;_op1,_op2,_op3 : tregister);
  199. begin
  200. inherited create(op);
  201. ops:=3;
  202. loadreg(0,_op1);
  203. loadreg(1,_op2);
  204. loadreg(2,_op3);
  205. end;
  206. constructor taicpu.op_reg_reg_reg_reg(op : tasmop;_op1,_op2,_op3,_op4 : tregister);
  207. begin
  208. inherited create(op);
  209. ops:=4;
  210. loadreg(0,_op1);
  211. loadreg(1,_op2);
  212. loadreg(2,_op3);
  213. loadreg(3,_op4);
  214. end;
  215. constructor taicpu.op_reg_reg_const(op : tasmop;_op1,_op2 : tregister; _op3: aint);
  216. begin
  217. inherited create(op);
  218. ops:=3;
  219. loadreg(0,_op1);
  220. loadreg(1,_op2);
  221. loadconst(2,aint(_op3));
  222. end;
  223. constructor taicpu.op_reg_const_ref(op : tasmop;_op1 : tregister;_op2 : aint;_op3 : treference);
  224. begin
  225. inherited create(op);
  226. ops:=3;
  227. loadreg(0,_op1);
  228. loadconst(1,_op2);
  229. loadref(2,_op3);
  230. end;
  231. constructor taicpu.op_reg_reg_sym_ofs(op : tasmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: longint);
  232. begin
  233. inherited create(op);
  234. ops:=3;
  235. loadreg(0,_op1);
  236. loadreg(1,_op2);
  237. loadsymbol(0,_op3,_op3ofs);
  238. end;
  239. constructor taicpu.op_reg_reg_ref(op : tasmop;_op1,_op2 : tregister; const _op3: treference);
  240. begin
  241. inherited create(op);
  242. ops:=3;
  243. loadreg(0,_op1);
  244. loadreg(1,_op2);
  245. loadref(2,_op3);
  246. end;
  247. constructor taicpu.op_reg_reg_shifterop(op : tasmop;_op1,_op2 : tregister;_op3 : tshifterop);
  248. begin
  249. inherited create(op);
  250. ops:=3;
  251. loadreg(0,_op1);
  252. loadreg(1,_op2);
  253. loadshifterop(2,_op3);
  254. end;
  255. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  256. begin
  257. inherited create(op);
  258. condition:=cond;
  259. ops:=1;
  260. loadsymbol(0,_op1,0);
  261. end;
  262. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  263. begin
  264. inherited create(op);
  265. ops:=1;
  266. loadsymbol(0,_op1,0);
  267. end;
  268. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint);
  269. begin
  270. inherited create(op);
  271. ops:=1;
  272. loadsymbol(0,_op1,_op1ofs);
  273. end;
  274. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : longint);
  275. begin
  276. inherited create(op);
  277. ops:=2;
  278. loadreg(0,_op1);
  279. loadsymbol(1,_op2,_op2ofs);
  280. end;
  281. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:longint;const _op2 : treference);
  282. begin
  283. inherited create(op);
  284. ops:=2;
  285. loadsymbol(0,_op1,_op1ofs);
  286. loadref(1,_op2);
  287. end;
  288. { ****************************** newra stuff *************************** }
  289. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  290. begin
  291. { allow the register allocator to remove unnecessary moves }
  292. result:=(((opcode=A_MOV) and (regtype = R_INTREGISTER)) or
  293. ((opcode=A_MVF) and (regtype = R_FPUREGISTER))
  294. ) and
  295. (condition=C_None) and
  296. (ops=2) and
  297. (oper[0]^.typ=top_reg) and
  298. (oper[1]^.typ=top_reg) and
  299. (oper[0]^.reg=oper[1]^.reg);
  300. end;
  301. function spilling_create_load(const ref:treference;r:tregister): tai;
  302. begin
  303. case getregtype(r) of
  304. R_INTREGISTER :
  305. result:=taicpu.op_reg_ref(A_LDR,r,ref);
  306. R_FPUREGISTER :
  307. { use lfm because we don't know the current internal format
  308. and avoid exceptions
  309. }
  310. result:=taicpu.op_reg_const_ref(A_LFM,r,1,ref);
  311. else
  312. internalerror(200401041);
  313. end;
  314. end;
  315. function spilling_create_store(r:tregister; const ref:treference): tai;
  316. begin
  317. case getregtype(r) of
  318. R_INTREGISTER :
  319. result:=taicpu.op_reg_ref(A_STR,r,ref);
  320. R_FPUREGISTER :
  321. { use sfm because we don't know the current internal format
  322. and avoid exceptions
  323. }
  324. result:=taicpu.op_reg_const_ref(A_SFM,r,1,ref);
  325. else
  326. internalerror(200401041);
  327. end;
  328. end;
  329. function taicpu.spilling_get_operation_type(opnr: longint): topertype;
  330. begin
  331. case opcode of
  332. A_ADC,A_ADD,A_AND,
  333. A_EOR,A_CLZ,
  334. A_LDR,A_LDRB,A_LDRD,A_LDRBT,A_LDRH,A_LDRSB,
  335. A_LDRSH,A_LDRT,
  336. A_MOV,A_MVN,A_MLA,A_MUL,
  337. A_ORR,A_RSB,A_RSC,A_SBC,A_SUB,
  338. A_SWP,A_SWPB,
  339. A_LDF,A_FLT,A_FIX,
  340. A_ADF,A_DVF,A_FDV,A_FML,
  341. A_RFS,A_RFC,A_RDF,
  342. A_RMF,A_RPW,A_RSF,A_SUF,A_ABS,A_ACS,A_ASN,A_ATN,A_COS,
  343. A_EXP,A_LOG,A_LGN,A_MVF,A_MNF,A_FRD,A_MUF,A_POL,A_RND,A_SIN,A_SQT,A_TAN,
  344. A_LFM:
  345. if opnr=0 then
  346. result:=operand_write
  347. else
  348. result:=operand_read;
  349. A_BIC,A_BKPT,A_B,A_BL,A_BLX,A_BX,
  350. A_CMN,A_CMP,A_TEQ,A_TST,
  351. A_CMF,A_CMFE,A_WFS,A_CNF:
  352. result:=operand_read;
  353. A_SMLAL,A_UMLAL:
  354. if opnr in [0,1] then
  355. result:=operand_readwrite
  356. else
  357. result:=operand_read;
  358. A_SMULL,A_UMULL:
  359. if opnr in [0,1] then
  360. result:=operand_write
  361. else
  362. result:=operand_read;
  363. A_STR,A_STRB,A_STRBT,A_STRD,
  364. A_STRH,A_STRT,A_STF,A_SFM:
  365. { important is what happens with the involved registers }
  366. if opnr=0 then
  367. result := operand_read
  368. else
  369. { check for pre/post indexed }
  370. result := operand_read;
  371. else
  372. internalerror(200403151);
  373. end;
  374. end;
  375. procedure InitAsm;
  376. begin
  377. end;
  378. procedure DoneAsm;
  379. begin
  380. end;
  381. function setoppostfix(i : taicpu;pf : toppostfix) : taicpu;
  382. begin
  383. i.oppostfix:=pf;
  384. result:=i;
  385. end;
  386. function setroundingmode(i : taicpu;rm : troundingmode) : taicpu;
  387. begin
  388. i.roundingmode:=rm;
  389. result:=i;
  390. end;
  391. function setcondition(i : taicpu;c : tasmcond) : taicpu;
  392. begin
  393. i.condition:=c;
  394. result:=i;
  395. end;
  396. procedure insertpcrelativedata(list,listtoinsert : taasmoutput);
  397. var
  398. curpos : longint;
  399. lastpos : longint;
  400. curop : longint;
  401. curtai : tai;
  402. curdatatai,hp : tai;
  403. curdata : taasmoutput;
  404. l : tasmlabel;
  405. begin
  406. curdata:=taasmoutput.create;
  407. lastpos:=-1;
  408. curpos:=0;
  409. curtai:=tai(list.first);
  410. while assigned(curtai) do
  411. begin
  412. { instruction? }
  413. if curtai.typ=ait_instruction then
  414. begin
  415. { walk through all operand of the instruction }
  416. for curop:=0 to taicpu(curtai).ops-1 do
  417. begin
  418. { reference? }
  419. if (taicpu(curtai).oper[curop]^.typ=top_ref) then
  420. begin
  421. { pc relative symbol? }
  422. curdatatai:=tai(taicpu(curtai).oper[curop]^.ref^.symboldata);
  423. if assigned(curdatatai) then
  424. begin
  425. { if yes, insert till next symbol }
  426. repeat
  427. hp:=tai(curdatatai.next);
  428. listtoinsert.remove(curdatatai);
  429. curdata.concat(curdatatai);
  430. curdatatai:=hp;
  431. until (curdatatai=nil) or (curdatatai.typ=ait_label);
  432. if lastpos=-1 then
  433. lastpos:=curpos;
  434. end;
  435. end;
  436. end;
  437. inc(curpos);
  438. end;
  439. { split only at real instructions else the test below fails }
  440. if ((curpos-lastpos)>1016) and (curtai.typ=ait_instruction) and
  441. (
  442. { don't split loads of pc to lr and the following move }
  443. not(
  444. (taicpu(curtai).opcode=A_MOV) and
  445. (taicpu(curtai).oper[0]^.typ=top_reg) and
  446. (taicpu(curtai).oper[0]^.reg=NR_R14) and
  447. (taicpu(curtai).oper[1]^.typ=top_reg) and
  448. (taicpu(curtai).oper[1]^.reg=NR_PC)
  449. )
  450. ) then
  451. begin
  452. lastpos:=curpos;
  453. hp:=tai(curtai.next);
  454. objectlibrary.getlabel(l);
  455. curdata.insert(taicpu.op_sym(A_B,l));
  456. curdata.concat(tai_label.create(l));
  457. list.insertlistafter(curtai,curdata);
  458. curtai:=hp;
  459. end
  460. else
  461. curtai:=tai(curtai.next);
  462. end;
  463. list.concatlist(curdata);
  464. curdata.free;
  465. end;
  466. procedure taicpu.ResetPass1;
  467. begin
  468. { we need to reset everything here, because the choosen insentry
  469. can be invalid for a new situation where the previously optimized
  470. insentry is not correct }
  471. InsEntry:=nil;
  472. InsSize:=0;
  473. LastInsOffset:=-1;
  474. end;
  475. procedure taicpu.ResetPass2;
  476. begin
  477. { we are here in a second pass, check if the instruction can be optimized }
  478. if assigned(InsEntry) and
  479. ((InsEntry^.flags and IF_PASS2)<>0) then
  480. begin
  481. InsEntry:=nil;
  482. InsSize:=0;
  483. end;
  484. LastInsOffset:=-1;
  485. end;
  486. function taicpu.CheckIfValid:boolean;
  487. begin
  488. end;
  489. function taicpu.Pass1(offset:longint):longint;
  490. begin
  491. end;
  492. procedure taicpu.Pass2(objdata:TAsmObjectdata);
  493. begin
  494. end;
  495. procedure taicpu.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  496. begin
  497. end;
  498. procedure taicpu.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  499. begin
  500. end;
  501. procedure taicpu.ppubuildderefimploper(var o:toper);
  502. begin
  503. end;
  504. procedure taicpu.ppuderefoper(var o:toper);
  505. begin
  506. end;
  507. function taicpu.InsEnd:longint;
  508. begin
  509. end;
  510. procedure taicpu.create_ot;
  511. begin
  512. end;
  513. function taicpu.Matches(p:PInsEntry):longint;
  514. begin
  515. end;
  516. function taicpu.calcsize(p:PInsEntry):shortint;
  517. begin
  518. end;
  519. procedure taicpu.gencode(objdata:TAsmObjectData);
  520. begin
  521. end;
  522. function taicpu.NeedAddrPrefix(opidx:byte):boolean;
  523. begin
  524. end;
  525. procedure taicpu.Swapoperands;
  526. begin
  527. end;
  528. function taicpu.FindInsentry:boolean;
  529. begin
  530. end;
  531. end.
  532. {$ifdef dummy}
  533. (*
  534. static void gencode (long segment, long offset, int bits,
  535. insn *ins, char *codes, long insn_end)
  536. {
  537. int has_S_code; /* S - setflag */
  538. int has_B_code; /* B - setflag */
  539. int has_T_code; /* T - setflag */
  540. int has_W_code; /* ! => W flag */
  541. int has_F_code; /* ^ => S flag */
  542. int keep;
  543. unsigned char c;
  544. unsigned char bytes[4];
  545. long data, size;
  546. static int cc_code[] = /* bit pattern of cc */
  547. { /* order as enum in */
  548. 0x0E, 0x03, 0x02, 0x00, /* nasm.h */
  549. 0x0A, 0x0C, 0x08, 0x0D,
  550. 0x09, 0x0B, 0x04, 0x01,
  551. 0x05, 0x07, 0x06,
  552. };
  553. (*
  554. #ifdef DEBUG
  555. static char *CC[] =
  556. { /* condition code names */
  557. "AL", "CC", "CS", "EQ",
  558. "GE", "GT", "HI", "LE",
  559. "LS", "LT", "MI", "NE",
  560. "PL", "VC", "VS", "",
  561. "S"
  562. };
  563. *)
  564. has_S_code = (ins->condition & C_SSETFLAG);
  565. has_B_code = (ins->condition & C_BSETFLAG);
  566. has_T_code = (ins->condition & C_TSETFLAG);
  567. has_W_code = (ins->condition & C_EXSETFLAG);
  568. has_F_code = (ins->condition & C_FSETFLAG);
  569. ins->condition = (ins->condition & 0x0F);
  570. (*
  571. if (rt_debug)
  572. {
  573. printf ("gencode: instruction: %s%s", insn_names[ins->opcode],
  574. CC[ins->condition & 0x0F]);
  575. if (has_S_code)
  576. printf ("S");
  577. if (has_B_code)
  578. printf ("B");
  579. if (has_T_code)
  580. printf ("T");
  581. if (has_W_code)
  582. printf ("!");
  583. if (has_F_code)
  584. printf ("^");
  585. printf ("\n");
  586. c = *codes;
  587. printf (" (%d) decode - '0x%02X'\n", ins->operands, c);
  588. bytes[0] = 0xB;
  589. bytes[1] = 0xE;
  590. bytes[2] = 0xE;
  591. bytes[3] = 0xF;
  592. }
  593. *)
  594. // First condition code in upper nibble
  595. if (ins->condition < C_NONE)
  596. {
  597. c = cc_code[ins->condition] << 4;
  598. }
  599. else
  600. {
  601. c = cc_code[C_AL] << 4; // is often ALWAYS but not always
  602. }
  603. switch (keep = *codes)
  604. {
  605. case 1:
  606. // B, BL
  607. ++codes;
  608. c |= *codes++;
  609. bytes[0] = c;
  610. if (ins->oprs[0].segment != segment)
  611. {
  612. // fais une relocation
  613. c = 1;
  614. data = 0; // Let the linker locate ??
  615. }
  616. else
  617. {
  618. c = 0;
  619. data = ins->oprs[0].offset - (offset + 8);
  620. if (data % 4)
  621. {
  622. errfunc (ERR_NONFATAL, "offset not aligned on 4 bytes");
  623. }
  624. }
  625. if (data >= 0x1000)
  626. {
  627. errfunc (ERR_NONFATAL, "too long offset");
  628. }
  629. data = data >> 2;
  630. bytes[1] = (data >> 16) & 0xFF;
  631. bytes[2] = (data >> 8) & 0xFF;
  632. bytes[3] = (data ) & 0xFF;
  633. if (c == 1)
  634. {
  635. // out (offset, segment, &bytes[0], OUT_RAWDATA+1, NO_SEG, NO_SEG);
  636. out (offset, segment, &bytes[0], OUT_REL3ADR+4, ins->oprs[0].segment, NO_SEG);
  637. }
  638. else
  639. {
  640. out (offset, segment, &bytes[0], OUT_RAWDATA+4, NO_SEG, NO_SEG);
  641. }
  642. return;
  643. case 2:
  644. // SWI
  645. ++codes;
  646. c |= *codes++;
  647. bytes[0] = c;
  648. data = ins->oprs[0].offset;
  649. bytes[1] = (data >> 16) & 0xFF;
  650. bytes[2] = (data >> 8) & 0xFF;
  651. bytes[3] = (data) & 0xFF;
  652. out (offset, segment, &bytes, OUT_RAWDATA+4, NO_SEG, NO_SEG);
  653. return;
  654. case 3:
  655. // BX
  656. ++codes;
  657. c |= *codes++;
  658. bytes[0] = c;
  659. bytes[1] = *codes++;
  660. bytes[2] = *codes++;
  661. bytes[3] = *codes++;
  662. c = regval (&ins->oprs[0],1);
  663. if (c == 15) // PC
  664. {
  665. errfunc (ERR_WARNING, "'BX' with R15 has undefined behaviour");
  666. }
  667. else if (c > 15)
  668. {
  669. errfunc (ERR_NONFATAL, "Illegal register specified for 'BX'");
  670. }
  671. bytes[3] |= (c & 0x0F);
  672. out (offset, segment, bytes, OUT_RAWDATA+4, NO_SEG, NO_SEG);
  673. return;
  674. case 4: // AND Rd,Rn,Rm
  675. case 5: // AND Rd,Rn,Rm,<shift>Rs
  676. case 6: // AND Rd,Rn,Rm,<shift>imm
  677. case 7: // AND Rd,Rn,<shift>imm
  678. ++codes;
  679. #ifdef DEBUG
  680. if (rt_debug)
  681. {
  682. printf (" decode - '0x%02X'\n", keep);
  683. printf (" code - '0x%02X'\n", (unsigned char) ( *codes));
  684. }
  685. #endif
  686. bytes[0] = c | *codes;
  687. ++codes;
  688. bytes[1] = *codes;
  689. if (has_S_code)
  690. bytes[1] |= 0x10;
  691. c = regval (&ins->oprs[1],1);
  692. // Rn in low nibble
  693. bytes[1] |= c;
  694. // Rd in high nibble
  695. bytes[2] = regval (&ins->oprs[0],1) << 4;
  696. if (keep != 7)
  697. {
  698. // Rm in low nibble
  699. bytes[3] = regval (&ins->oprs[2],1);
  700. }
  701. // Shifts if any
  702. if (keep == 5 || keep == 6)
  703. {
  704. // Shift in bytes 2 and 3
  705. if (keep == 5)
  706. {
  707. // Rs
  708. c = regval (&ins->oprs[3],1);
  709. bytes[2] |= c;
  710. c = 0x10; // Set bit 4 in byte[3]
  711. }
  712. if (keep == 6)
  713. {
  714. c = (ins->oprs[3].offset) & 0x1F;
  715. // #imm
  716. bytes[2] |= c >> 1;
  717. if (c & 0x01)
  718. {
  719. bytes[3] |= 0x80;
  720. }
  721. c = 0; // Clr bit 4 in byte[3]
  722. }
  723. // <shift>
  724. c |= shiftval (&ins->oprs[3]) << 5;
  725. bytes[3] |= c;
  726. }
  727. // reg,reg,imm
  728. if (keep == 7)
  729. {
  730. int shimm;
  731. shimm = imm_shift (ins->oprs[2].offset);
  732. if (shimm == -1)
  733. {
  734. errfunc (ERR_NONFATAL, "cannot create that constant");
  735. }
  736. bytes[3] = shimm & 0xFF;
  737. bytes[2] |= (shimm & 0xF00) >> 8;
  738. }
  739. out (offset, segment, bytes, OUT_RAWDATA+4, NO_SEG, NO_SEG);
  740. return;
  741. case 8: // MOV Rd,Rm
  742. case 9: // MOV Rd,Rm,<shift>Rs
  743. case 0xA: // MOV Rd,Rm,<shift>imm
  744. case 0xB: // MOV Rd,<shift>imm
  745. ++codes;
  746. #ifdef DEBUG
  747. if (rt_debug)
  748. {
  749. printf (" decode - '0x%02X'\n", keep);
  750. printf (" code - '0x%02X'\n", (unsigned char) ( *codes));
  751. }
  752. #endif
  753. bytes[0] = c | *codes;
  754. ++codes;
  755. bytes[1] = *codes;
  756. if (has_S_code)
  757. bytes[1] |= 0x10;
  758. // Rd in high nibble
  759. bytes[2] = regval (&ins->oprs[0],1) << 4;
  760. if (keep != 0x0B)
  761. {
  762. // Rm in low nibble
  763. bytes[3] = regval (&ins->oprs[1],1);
  764. }
  765. // Shifts if any
  766. if (keep == 0x09 || keep == 0x0A)
  767. {
  768. // Shift in bytes 2 and 3
  769. if (keep == 0x09)
  770. {
  771. // Rs
  772. c = regval (&ins->oprs[2],1);
  773. bytes[2] |= c;
  774. c = 0x10; // Set bit 4 in byte[3]
  775. }
  776. if (keep == 0x0A)
  777. {
  778. c = (ins->oprs[2].offset) & 0x1F;
  779. // #imm
  780. bytes[2] |= c >> 1;
  781. if (c & 0x01)
  782. {
  783. bytes[3] |= 0x80;
  784. }
  785. c = 0; // Clr bit 4 in byte[3]
  786. }
  787. // <shift>
  788. c |= shiftval (&ins->oprs[2]) << 5;
  789. bytes[3] |= c;
  790. }
  791. // reg,imm
  792. if (keep == 0x0B)
  793. {
  794. int shimm;
  795. shimm = imm_shift (ins->oprs[1].offset);
  796. if (shimm == -1)
  797. {
  798. errfunc (ERR_NONFATAL, "cannot create that constant");
  799. }
  800. bytes[3] = shimm & 0xFF;
  801. bytes[2] |= (shimm & 0xF00) >> 8;
  802. }
  803. out (offset, segment, bytes, OUT_RAWDATA+4, NO_SEG, NO_SEG);
  804. return;
  805. case 0xC: // CMP Rn,Rm
  806. case 0xD: // CMP Rn,Rm,<shift>Rs
  807. case 0xE: // CMP Rn,Rm,<shift>imm
  808. case 0xF: // CMP Rn,<shift>imm
  809. ++codes;
  810. bytes[0] = c | *codes++;
  811. bytes[1] = *codes;
  812. // Implicit S code
  813. bytes[1] |= 0x10;
  814. c = regval (&ins->oprs[0],1);
  815. // Rn in low nibble
  816. bytes[1] |= c;
  817. // No destination
  818. bytes[2] = 0;
  819. if (keep != 0x0B)
  820. {
  821. // Rm in low nibble
  822. bytes[3] = regval (&ins->oprs[1],1);
  823. }
  824. // Shifts if any
  825. if (keep == 0x0D || keep == 0x0E)
  826. {
  827. // Shift in bytes 2 and 3
  828. if (keep == 0x0D)
  829. {
  830. // Rs
  831. c = regval (&ins->oprs[2],1);
  832. bytes[2] |= c;
  833. c = 0x10; // Set bit 4 in byte[3]
  834. }
  835. if (keep == 0x0E)
  836. {
  837. c = (ins->oprs[2].offset) & 0x1F;
  838. // #imm
  839. bytes[2] |= c >> 1;
  840. if (c & 0x01)
  841. {
  842. bytes[3] |= 0x80;
  843. }
  844. c = 0; // Clr bit 4 in byte[3]
  845. }
  846. // <shift>
  847. c |= shiftval (&ins->oprs[2]) << 5;
  848. bytes[3] |= c;
  849. }
  850. // reg,imm
  851. if (keep == 0x0F)
  852. {
  853. int shimm;
  854. shimm = imm_shift (ins->oprs[1].offset);
  855. if (shimm == -1)
  856. {
  857. errfunc (ERR_NONFATAL, "cannot create that constant");
  858. }
  859. bytes[3] = shimm & 0xFF;
  860. bytes[2] |= (shimm & 0xF00) >> 8;
  861. }
  862. out (offset, segment, bytes, OUT_RAWDATA+4, NO_SEG, NO_SEG);
  863. return;
  864. case 0x10: // MRS Rd,<psr>
  865. ++codes;
  866. bytes[0] = c | *codes++;
  867. bytes[1] = *codes++;
  868. // Rd
  869. c = regval (&ins->oprs[0],1);
  870. bytes[2] = c << 4;
  871. bytes[3] = 0;
  872. c = ins->oprs[1].basereg;
  873. if (c == R_CPSR || c == R_SPSR)
  874. {
  875. if (c == R_SPSR)
  876. {
  877. bytes[1] |= 0x40;
  878. }
  879. }
  880. else
  881. {
  882. errfunc (ERR_NONFATAL, "CPSR or SPSR expected");
  883. }
  884. out (offset, segment, bytes, OUT_RAWDATA+4, NO_SEG, NO_SEG);
  885. return;
  886. case 0x11: // MSR <psr>,Rm
  887. case 0x12: // MSR <psrf>,Rm
  888. case 0x13: // MSR <psrf>,#expression
  889. ++codes;
  890. bytes[0] = c | *codes++;
  891. bytes[1] = *codes++;
  892. bytes[2] = *codes;
  893. if (keep == 0x11 || keep == 0x12)
  894. {
  895. // Rm
  896. c = regval (&ins->oprs[1],1);
  897. bytes[3] = c;
  898. }
  899. else
  900. {
  901. int shimm;
  902. shimm = imm_shift (ins->oprs[1].offset);
  903. if (shimm == -1)
  904. {
  905. errfunc (ERR_NONFATAL, "cannot create that constant");
  906. }
  907. bytes[3] = shimm & 0xFF;
  908. bytes[2] |= (shimm & 0xF00) >> 8;
  909. }
  910. c = ins->oprs[0].basereg;
  911. if ( keep == 0x11)
  912. {
  913. if ( c == R_CPSR || c == R_SPSR)
  914. {
  915. if ( c== R_SPSR)
  916. {
  917. bytes[1] |= 0x40;
  918. }
  919. }
  920. else
  921. {
  922. errfunc (ERR_NONFATAL, "CPSR or SPSR expected");
  923. }
  924. }
  925. else
  926. {
  927. if ( c == R_CPSR_FLG || c == R_SPSR_FLG)
  928. {
  929. if ( c== R_SPSR_FLG)
  930. {
  931. bytes[1] |= 0x40;
  932. }
  933. }
  934. else
  935. {
  936. errfunc (ERR_NONFATAL, "CPSR_flg or SPSR_flg expected");
  937. }
  938. }
  939. break;
  940. case 0x14: // MUL Rd,Rm,Rs
  941. case 0x15: // MULA Rd,Rm,Rs,Rn
  942. ++codes;
  943. bytes[0] = c | *codes++;
  944. bytes[1] = *codes++;
  945. bytes[3] = *codes;
  946. // Rd
  947. bytes[1] |= regval (&ins->oprs[0],1);
  948. if (has_S_code)
  949. bytes[1] |= 0x10;
  950. // Rm
  951. bytes[3] |= regval (&ins->oprs[1],1);
  952. // Rs
  953. bytes[2] = regval (&ins->oprs[2],1);
  954. if (keep == 0x15)
  955. {
  956. bytes[2] |= regval (&ins->oprs[3],1) << 4;
  957. }
  958. break;
  959. case 0x16: // SMLAL RdHi,RdLo,Rm,Rs
  960. ++codes;
  961. bytes[0] = c | *codes++;
  962. bytes[1] = *codes++;
  963. bytes[3] = *codes;
  964. // RdHi
  965. bytes[1] |= regval (&ins->oprs[1],1);
  966. if (has_S_code)
  967. bytes[1] |= 0x10;
  968. // RdLo
  969. bytes[2] = regval (&ins->oprs[0],1) << 4;
  970. // Rm
  971. bytes[3] |= regval (&ins->oprs[2],1);
  972. // Rs
  973. bytes[2] |= regval (&ins->oprs[3],1);
  974. break;
  975. case 0x17: // LDR Rd, expression
  976. ++codes;
  977. bytes[0] = c | *codes++;
  978. bytes[1] = *codes++;
  979. // Rd
  980. bytes[2] = regval (&ins->oprs[0],1) << 4;
  981. if (has_B_code)
  982. bytes[1] |= 0x40;
  983. if (has_T_code)
  984. {
  985. errfunc (ERR_NONFATAL, "'T' not allowed in pre-index mode");
  986. }
  987. if (has_W_code)
  988. {
  989. errfunc (ERR_NONFATAL, "'!' not allowed");
  990. }
  991. // Rn - implicit R15
  992. bytes[1] |= 0xF;
  993. if (ins->oprs[1].segment != segment)
  994. {
  995. errfunc (ERR_NONFATAL, "label not in same segment");
  996. }
  997. data = ins->oprs[1].offset - (offset + 8);
  998. if (data < 0)
  999. {
  1000. data = -data;
  1001. }
  1002. else
  1003. {
  1004. bytes[1] |= 0x80;
  1005. }
  1006. if (data >= 0x1000)
  1007. {
  1008. errfunc (ERR_NONFATAL, "too long offset");
  1009. }
  1010. bytes[2] |= ((data & 0xF00) >> 8);
  1011. bytes[3] = data & 0xFF;
  1012. break;
  1013. case 0x18: // LDR Rd, [Rn]
  1014. ++codes;
  1015. bytes[0] = c | *codes++;
  1016. bytes[1] = *codes++;
  1017. // Rd
  1018. bytes[2] = regval (&ins->oprs[0],1) << 4;
  1019. if (has_B_code)
  1020. bytes[1] |= 0x40;
  1021. if (has_T_code)
  1022. {
  1023. bytes[1] |= 0x20; // write-back
  1024. }
  1025. else
  1026. {
  1027. bytes[0] |= 0x01; // implicit pre-index mode
  1028. }
  1029. if (has_W_code)
  1030. {
  1031. bytes[1] |= 0x20; // write-back
  1032. }
  1033. // Rn
  1034. c = regval (&ins->oprs[1],1);
  1035. bytes[1] |= c;
  1036. if (c == 0x15) // R15
  1037. data = -8;
  1038. else
  1039. data = 0;
  1040. if (data < 0)
  1041. {
  1042. data = -data;
  1043. }
  1044. else
  1045. {
  1046. bytes[1] |= 0x80;
  1047. }
  1048. bytes[2] |= ((data & 0xF00) >> 8);
  1049. bytes[3] = data & 0xFF;
  1050. break;
  1051. case 0x19: // LDR Rd, [Rn,#expression]
  1052. case 0x20: // LDR Rd, [Rn,Rm]
  1053. case 0x21: // LDR Rd, [Rn,Rm,shift]
  1054. ++codes;
  1055. bytes[0] = c | *codes++;
  1056. bytes[1] = *codes++;
  1057. // Rd
  1058. bytes[2] = regval (&ins->oprs[0],1) << 4;
  1059. if (has_B_code)
  1060. bytes[1] |= 0x40;
  1061. // Rn
  1062. c = regval (&ins->oprs[1],1);
  1063. bytes[1] |= c;
  1064. if (ins->oprs[ins->operands-1].bracket) // FIXME: Bracket on last operand -> pre-index <--
  1065. {
  1066. bytes[0] |= 0x01; // pre-index mode
  1067. if (has_W_code)
  1068. {
  1069. bytes[1] |= 0x20;
  1070. }
  1071. if (has_T_code)
  1072. {
  1073. errfunc (ERR_NONFATAL, "'T' not allowed in pre-index mode");
  1074. }
  1075. }
  1076. else
  1077. {
  1078. if (has_T_code) // Forced write-back in post-index mode
  1079. {
  1080. bytes[1] |= 0x20;
  1081. }
  1082. if (has_W_code)
  1083. {
  1084. errfunc (ERR_NONFATAL, "'!' not allowed in post-index mode");
  1085. }
  1086. }
  1087. if (keep == 0x19)
  1088. {
  1089. data = ins->oprs[2].offset;
  1090. if (data < 0)
  1091. {
  1092. data = -data;
  1093. }
  1094. else
  1095. {
  1096. bytes[1] |= 0x80;
  1097. }
  1098. if (data >= 0x1000)
  1099. {
  1100. errfunc (ERR_NONFATAL, "too long offset");
  1101. }
  1102. bytes[2] |= ((data & 0xF00) >> 8);
  1103. bytes[3] = data & 0xFF;
  1104. }
  1105. else
  1106. {
  1107. if (ins->oprs[2].minus == 0)
  1108. {
  1109. bytes[1] |= 0x80;
  1110. }
  1111. c = regval (&ins->oprs[2],1);
  1112. bytes[3] = c;
  1113. if (keep == 0x21)
  1114. {
  1115. c = ins->oprs[3].offset;
  1116. if (c > 0x1F)
  1117. {
  1118. errfunc (ERR_NONFATAL, "too large shiftvalue");
  1119. c = c & 0x1F;
  1120. }
  1121. bytes[2] |= c >> 1;
  1122. if (c & 0x01)
  1123. {
  1124. bytes[3] |= 0x80;
  1125. }
  1126. bytes[3] |= shiftval (&ins->oprs[3]) << 5;
  1127. }
  1128. }
  1129. break;
  1130. case 0x22: // LDRH Rd, expression
  1131. ++codes;
  1132. bytes[0] = c | 0x01; // Implicit pre-index
  1133. bytes[1] = *codes++;
  1134. // Rd
  1135. bytes[2] = regval (&ins->oprs[0],1) << 4;
  1136. // Rn - implicit R15
  1137. bytes[1] |= 0xF;
  1138. if (ins->oprs[1].segment != segment)
  1139. {
  1140. errfunc (ERR_NONFATAL, "label not in same segment");
  1141. }
  1142. data = ins->oprs[1].offset - (offset + 8);
  1143. if (data < 0)
  1144. {
  1145. data = -data;
  1146. }
  1147. else
  1148. {
  1149. bytes[1] |= 0x80;
  1150. }
  1151. if (data >= 0x100)
  1152. {
  1153. errfunc (ERR_NONFATAL, "too long offset");
  1154. }
  1155. bytes[3] = *codes++;
  1156. bytes[2] |= ((data & 0xF0) >> 4);
  1157. bytes[3] |= data & 0xF;
  1158. break;
  1159. case 0x23: // LDRH Rd, Rn
  1160. ++codes;
  1161. bytes[0] = c | 0x01; // Implicit pre-index
  1162. bytes[1] = *codes++;
  1163. // Rd
  1164. bytes[2] = regval (&ins->oprs[0],1) << 4;
  1165. // Rn
  1166. c = regval (&ins->oprs[1],1);
  1167. bytes[1] |= c;
  1168. if (c == 0x15) // R15
  1169. data = -8;
  1170. else
  1171. data = 0;
  1172. if (data < 0)
  1173. {
  1174. data = -data;
  1175. }
  1176. else
  1177. {
  1178. bytes[1] |= 0x80;
  1179. }
  1180. if (data >= 0x100)
  1181. {
  1182. errfunc (ERR_NONFATAL, "too long offset");
  1183. }
  1184. bytes[3] = *codes++;
  1185. bytes[2] |= ((data & 0xF0) >> 4);
  1186. bytes[3] |= data & 0xF;
  1187. break;
  1188. case 0x24: // LDRH Rd, Rn, expression
  1189. case 0x25: // LDRH Rd, Rn, Rm
  1190. ++codes;
  1191. bytes[0] = c;
  1192. bytes[1] = *codes++;
  1193. // Rd
  1194. bytes[2] = regval (&ins->oprs[0],1) << 4;
  1195. // Rn
  1196. c = regval (&ins->oprs[1],1);
  1197. bytes[1] |= c;
  1198. if (ins->oprs[ins->operands-1].bracket) // FIXME: Bracket on last operand -> pre-index <--
  1199. {
  1200. bytes[0] |= 0x01; // pre-index mode
  1201. if (has_W_code)
  1202. {
  1203. bytes[1] |= 0x20;
  1204. }
  1205. }
  1206. else
  1207. {
  1208. if (has_W_code)
  1209. {
  1210. errfunc (ERR_NONFATAL, "'!' not allowed in post-index mode");
  1211. }
  1212. }
  1213. bytes[3] = *codes++;
  1214. if (keep == 0x24)
  1215. {
  1216. data = ins->oprs[2].offset;
  1217. if (data < 0)
  1218. {
  1219. data = -data;
  1220. }
  1221. else
  1222. {
  1223. bytes[1] |= 0x80;
  1224. }
  1225. if (data >= 0x100)
  1226. {
  1227. errfunc (ERR_NONFATAL, "too long offset");
  1228. }
  1229. bytes[2] |= ((data & 0xF0) >> 4);
  1230. bytes[3] |= data & 0xF;
  1231. }
  1232. else
  1233. {
  1234. if (ins->oprs[2].minus == 0)
  1235. {
  1236. bytes[1] |= 0x80;
  1237. }
  1238. c = regval (&ins->oprs[2],1);
  1239. bytes[3] |= c;
  1240. }
  1241. break;
  1242. case 0x26: // LDM/STM Rn, {reg-list}
  1243. ++codes;
  1244. bytes[0] = c;
  1245. bytes[0] |= ( *codes >> 4) & 0xF;
  1246. bytes[1] = ( *codes << 4) & 0xF0;
  1247. ++codes;
  1248. if (has_W_code)
  1249. {
  1250. bytes[1] |= 0x20;
  1251. }
  1252. if (has_F_code)
  1253. {
  1254. bytes[1] |= 0x40;
  1255. }
  1256. // Rn
  1257. bytes[1] |= regval (&ins->oprs[0],1);
  1258. data = ins->oprs[1].basereg;
  1259. bytes[2] = ((data >> 8) & 0xFF);
  1260. bytes[3] = (data & 0xFF);
  1261. break;
  1262. case 0x27: // SWP Rd, Rm, [Rn]
  1263. ++codes;
  1264. bytes[0] = c;
  1265. bytes[0] |= *codes++;
  1266. bytes[1] = regval (&ins->oprs[2],1);
  1267. if (has_B_code)
  1268. {
  1269. bytes[1] |= 0x40;
  1270. }
  1271. bytes[2] = regval (&ins->oprs[0],1) << 4;
  1272. bytes[3] = *codes++;
  1273. bytes[3] |= regval (&ins->oprs[1],1);
  1274. break;
  1275. default:
  1276. errfunc (ERR_FATAL, "unknown decoding of instruction");
  1277. bytes[0] = c;
  1278. // And a fix nibble
  1279. ++codes;
  1280. bytes[0] |= *codes++;
  1281. if ( *codes == 0x01) // An I bit
  1282. {
  1283. }
  1284. if ( *codes == 0x02) // An I bit
  1285. {
  1286. }
  1287. ++codes;
  1288. }
  1289. out (offset, segment, bytes, OUT_RAWDATA+4, NO_SEG, NO_SEG);
  1290. }
  1291. *)
  1292. {$endif dummy
  1293. }