2
0

rarv64gas.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. {
  2. Copyright (c) 2016 by Jeppe Johansen
  3. Does the parsing for the RiscV64 GNU AS styled inline assembler.
  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 rarv64gas;
  18. {$I fpcdefs.inc}
  19. interface
  20. uses
  21. raatt, rarvgas, rarv,
  22. cpubase;
  23. type
  24. trv64attreader = class(trvattreader)
  25. actmemoryordering: TMemoryOrdering;
  26. function is_register(const s: string): boolean; override;
  27. function is_asmopcode(const s: string):boolean;override;
  28. procedure handleopcode;override;
  29. procedure BuildReference(oper : trvoperand);
  30. procedure BuildOperand(oper : trvoperand);
  31. procedure BuildOpCode(instr : trvinstruction);
  32. procedure ReadAt(oper : trvoperand);
  33. procedure ReadSym(oper : trvoperand);
  34. end;
  35. implementation
  36. uses
  37. { helpers }
  38. cutils,
  39. { global }
  40. globtype,globals,verbose,
  41. systems,
  42. { aasm }
  43. aasmbase,aasmtai,aasmdata,aasmcpu,
  44. { symtable }
  45. symconst,symsym,symdef,
  46. { parser }
  47. procinfo,
  48. rabase,rautils,
  49. cgbase,cgobj,cgrv
  50. ;
  51. procedure trv64attreader.ReadSym(oper : trvoperand);
  52. var
  53. tempstr, mangledname : string;
  54. typesize,l,k : aint;
  55. begin
  56. tempstr:=actasmpattern;
  57. Consume(AS_ID);
  58. { typecasting? }
  59. if (actasmtoken=AS_LPAREN) and
  60. SearchType(tempstr,typesize) then
  61. begin
  62. oper.hastype:=true;
  63. Consume(AS_LPAREN);
  64. BuildOperand(oper);
  65. Consume(AS_RPAREN);
  66. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  67. oper.SetSize(typesize,true);
  68. end
  69. else
  70. if not oper.SetupVar(tempstr,false) then
  71. Message1(sym_e_unknown_id,tempstr);
  72. { record.field ? }
  73. if actasmtoken=AS_DOT then
  74. begin
  75. BuildRecordOffsetSize(tempstr,l,k,mangledname,false);
  76. if (mangledname<>'') then
  77. Message(asmr_e_invalid_reference_syntax);
  78. inc(oper.opr.ref.offset,l);
  79. end;
  80. end;
  81. procedure trv64attreader.ReadAt(oper : trvoperand);
  82. begin
  83. { check for ...@ }
  84. if actasmtoken=AS_AT then
  85. begin
  86. if (oper.opr.ref.symbol=nil) and
  87. (oper.opr.ref.offset = 0) then
  88. Message(asmr_e_invalid_reference_syntax);
  89. Consume(AS_AT);
  90. if actasmtoken=AS_ID then
  91. begin
  92. {if upper(actasmpattern)='L' then
  93. oper.opr.ref.refaddr:=addr_low
  94. else if upper(actasmpattern)='HI' then
  95. oper.opr.ref.refaddr:=addr_high
  96. else if upper(actasmpattern)='HA' then
  97. oper.opr.ref.refaddr:=addr_higha
  98. else}
  99. Message(asmr_e_invalid_reference_syntax);
  100. Consume(AS_ID);
  101. end
  102. else
  103. Message(asmr_e_invalid_reference_syntax);
  104. end;
  105. end;
  106. procedure trv64attreader.BuildReference(oper: trvoperand);
  107. procedure Consume_RParen;
  108. begin
  109. if actasmtoken <> AS_RPAREN then
  110. Begin
  111. Message(asmr_e_invalid_reference_syntax);
  112. RecoverConsume(true);
  113. end
  114. else
  115. begin
  116. Consume(AS_RPAREN);
  117. if not (actasmtoken in [AS_COMMA,AS_SEPARATOR,AS_END]) then
  118. Begin
  119. Message(asmr_e_invalid_reference_syntax);
  120. RecoverConsume(true);
  121. end;
  122. end;
  123. end;
  124. var
  125. l : aint;
  126. relsym: string;
  127. asmsymtyp: tasmsymtype;
  128. isflags: tindsymflags;
  129. begin
  130. Consume(AS_LPAREN);
  131. Case actasmtoken of
  132. AS_INTNUM,
  133. AS_MINUS,
  134. AS_PLUS:
  135. Begin
  136. { offset(offset) is invalid }
  137. If oper.opr.Ref.Offset <> 0 Then
  138. Begin
  139. Message(asmr_e_invalid_reference_syntax);
  140. RecoverConsume(true);
  141. End
  142. Else
  143. Begin
  144. oper.opr.Ref.Offset:=BuildConstExpression(false,true);
  145. Consume(AS_RPAREN);
  146. if actasmtoken=AS_AT then
  147. ReadAt(oper);
  148. end;
  149. exit;
  150. End;
  151. AS_REGISTER: { (reg ... }
  152. Begin
  153. if ((oper.opr.typ=OPR_REFERENCE) and (oper.opr.ref.base<>NR_NO)) or
  154. ((oper.opr.typ=OPR_LOCAL) and (oper.opr.localsym.localloc.loc<>LOC_REGISTER)) then
  155. message(asmr_e_cannot_index_relative_var);
  156. oper.opr.ref.base:=actasmregister;
  157. Consume(AS_REGISTER);
  158. Consume_RParen;
  159. end; {end case }
  160. AS_ID:
  161. Begin
  162. ReadSym(oper);
  163. case actasmtoken of
  164. AS_PLUS:
  165. begin
  166. { add a constant expression? }
  167. l:=BuildConstExpression(true,true);
  168. case oper.opr.typ of
  169. OPR_CONSTANT :
  170. inc(oper.opr.val,l);
  171. OPR_LOCAL :
  172. inc(oper.opr.localsymofs,l);
  173. OPR_REFERENCE :
  174. inc(oper.opr.ref.offset,l);
  175. else
  176. internalerror(2003092016);
  177. end;
  178. end;
  179. AS_MINUS:
  180. begin
  181. Consume(AS_MINUS);
  182. BuildConstSymbolExpression(false,true,false,l,relsym,asmsymtyp);
  183. if (relsym<>'') then
  184. begin
  185. if (oper.opr.typ = OPR_REFERENCE) then
  186. oper.opr.ref.relsymbol:=current_asmdata.RefAsmSymbol(relsym,AT_DATA)
  187. else
  188. begin
  189. Message(asmr_e_invalid_reference_syntax);
  190. RecoverConsume(false);
  191. end
  192. end
  193. else
  194. begin
  195. case oper.opr.typ of
  196. OPR_CONSTANT :
  197. dec(oper.opr.val,l);
  198. OPR_LOCAL :
  199. dec(oper.opr.localsymofs,l);
  200. OPR_REFERENCE :
  201. dec(oper.opr.ref.offset,l);
  202. else
  203. internalerror(2007092601);
  204. end;
  205. end;
  206. end;
  207. else
  208. ;
  209. end;
  210. Consume(AS_RPAREN);
  211. if actasmtoken=AS_AT then
  212. ReadAt(oper);
  213. End;
  214. AS_COMMA: { (, ... can either be scaling, or index }
  215. Begin
  216. Consume(AS_COMMA);
  217. { Index }
  218. if (actasmtoken=AS_REGISTER) then
  219. Begin
  220. oper.opr.ref.index:=actasmregister;
  221. Consume(AS_REGISTER);
  222. { check for scaling ... }
  223. Consume_RParen;
  224. end
  225. else
  226. begin
  227. Message(asmr_e_invalid_reference_syntax);
  228. RecoverConsume(false);
  229. end;
  230. end;
  231. else
  232. Begin
  233. Message(asmr_e_invalid_reference_syntax);
  234. RecoverConsume(false);
  235. end;
  236. end;
  237. end;
  238. procedure trv64attreader.BuildOperand(oper: trvoperand);
  239. var
  240. expr : string;
  241. typesize,l : aint;
  242. procedure AddLabelOperand(hl:tasmlabel);
  243. begin
  244. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  245. is_calljmp(actopcode) then
  246. begin
  247. oper.opr.typ:=OPR_SYMBOL;
  248. oper.opr.symbol:=hl;
  249. end
  250. else
  251. begin
  252. oper.InitRef;
  253. oper.opr.ref.symbol:=hl;
  254. end;
  255. end;
  256. procedure MaybeRecordOffset;
  257. var
  258. mangledname: string;
  259. hasdot : boolean;
  260. l,
  261. toffset,
  262. tsize : aint;
  263. begin
  264. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  265. exit;
  266. l:=0;
  267. hasdot:=(actasmtoken=AS_DOT);
  268. if hasdot then
  269. begin
  270. if expr<>'' then
  271. begin
  272. BuildRecordOffsetSize(expr,toffset,tsize,mangledname,false);
  273. if (oper.opr.typ<>OPR_CONSTANT) and
  274. (mangledname<>'') then
  275. Message(asmr_e_wrong_sym_type);
  276. inc(l,toffset);
  277. oper.SetSize(tsize,true);
  278. end;
  279. end;
  280. if actasmtoken in [AS_PLUS,AS_MINUS] then
  281. inc(l,BuildConstExpression(true,false));
  282. case oper.opr.typ of
  283. OPR_LOCAL :
  284. begin
  285. { don't allow direct access to fields of parameters, because that
  286. will generate buggy code. Allow it only for explicit typecasting }
  287. if hasdot and
  288. (not oper.hastype) and
  289. (tabstractvarsym(oper.opr.localsym).owner.symtabletype=parasymtable) and
  290. (current_procinfo.procdef.proccalloption<>pocall_register) then
  291. Message(asmr_e_cannot_access_field_directly_for_parameters);
  292. inc(oper.opr.localsymofs,l)
  293. end;
  294. OPR_CONSTANT :
  295. if (mangledname<>'') then
  296. begin
  297. if (oper.opr.val<>0) then
  298. Message(asmr_e_wrong_sym_type);
  299. oper.opr.typ:=OPR_SYMBOL;
  300. oper.opr.symbol:=current_asmdata.DefineAsmSymbol(mangledname,AB_EXTERNAL,AT_FUNCTION,voidcodepointertype);
  301. end
  302. else
  303. inc(oper.opr.val,l);
  304. OPR_REFERENCE :
  305. inc(oper.opr.ref.offset,l);
  306. OPR_SYMBOL:
  307. Message(asmr_e_invalid_symbol_ref);
  308. else
  309. internalerror(200309221);
  310. end;
  311. end;
  312. function MaybeBuildReference:boolean;
  313. { Try to create a reference, if not a reference is found then false
  314. is returned }
  315. begin
  316. MaybeBuildReference:=true;
  317. case actasmtoken of
  318. AS_INTNUM,
  319. AS_MINUS,
  320. AS_PLUS:
  321. Begin
  322. oper.opr.ref.offset:=BuildConstExpression(True,False);
  323. if actasmtoken<>AS_LPAREN then
  324. Message(asmr_e_invalid_reference_syntax)
  325. else
  326. BuildReference(oper);
  327. end;
  328. AS_LPAREN:
  329. BuildReference(oper);
  330. AS_ID: { only a variable is allowed ... }
  331. Begin
  332. ReadSym(oper);
  333. case actasmtoken of
  334. AS_END,
  335. AS_SEPARATOR,
  336. AS_COMMA: ;
  337. AS_LPAREN:
  338. BuildReference(oper);
  339. else
  340. Begin
  341. Message(asmr_e_invalid_reference_syntax);
  342. Consume(actasmtoken);
  343. end;
  344. end; {end case }
  345. end;
  346. else
  347. MaybeBuildReference:=false;
  348. end; { end case }
  349. end;
  350. function is_fenceflag(hs : string): boolean;
  351. var
  352. i: longint;
  353. flags: TFenceFlags;
  354. begin
  355. is_fenceflag := false;
  356. flags:=[];
  357. hs:=lower(hs);
  358. if (actopcode in [A_FENCE]) and (length(hs) >= 1) then
  359. begin
  360. for i:=1 to length(hs) do
  361. begin
  362. case hs[i] of
  363. 'i':
  364. Include(flags,ffi);
  365. 'o':
  366. Include(flags,ffo);
  367. 'r':
  368. Include(flags,ffr);
  369. 'w':
  370. Include(flags,ffw);
  371. else
  372. exit;
  373. end;
  374. end;
  375. oper.opr.typ := OPR_FENCEFLAGS;
  376. oper.opr.fenceflags := flags;
  377. exit(true);
  378. end;
  379. end;
  380. var
  381. tempreg : tregister;
  382. hl : tasmlabel;
  383. ofs : aint;
  384. refaddr: trefaddr;
  385. entered_paren: Boolean;
  386. Begin
  387. expr:='';
  388. entered_paren:=false;
  389. refaddr:=addr_full;
  390. if actasmtoken=AS_MOD then
  391. begin
  392. consume(AS_MOD);
  393. if actasmtoken<>AS_ID then
  394. begin
  395. Message(asmr_e_invalid_reference_syntax);
  396. RecoverConsume(false);
  397. end
  398. else
  399. begin
  400. if lower(actasmpattern)='pcrel_hi' then
  401. refaddr:=addr_pcrel_hi20
  402. else if lower(actasmpattern)='pcrel_lo' then
  403. refaddr:=addr_pcrel_lo12
  404. else if lower(actasmpattern)='hi' then
  405. refaddr:=addr_hi20
  406. else if lower(actasmpattern)='lo' then
  407. refaddr:=addr_lo12
  408. else
  409. begin
  410. Message(asmr_e_invalid_reference_syntax);
  411. RecoverConsume(false);
  412. end;
  413. consume(AS_ID);
  414. consume(AS_LPAREN);
  415. entered_paren:=true;
  416. end;
  417. end;
  418. case actasmtoken of
  419. AS_LPAREN: { Memory reference or constant expression }
  420. Begin
  421. oper.InitRef;
  422. BuildReference(oper);
  423. end;
  424. AS_INTNUM,
  425. AS_MINUS,
  426. AS_PLUS:
  427. Begin
  428. { Constant memory offset }
  429. { This must absolutely be followed by ( }
  430. oper.InitRef;
  431. oper.opr.ref.offset:=BuildConstExpression(True,False);
  432. if actasmtoken<>AS_LPAREN then
  433. begin
  434. ofs:=oper.opr.ref.offset;
  435. BuildConstantOperand(oper);
  436. inc(oper.opr.val,ofs);
  437. end
  438. else
  439. BuildReference(oper);
  440. end;
  441. AS_DOT,
  442. AS_ID: { A constant expression, or a Variable ref. }
  443. Begin
  444. if is_fenceflag(actasmpattern) then
  445. begin
  446. consume(AS_ID);
  447. end
  448. else
  449. { Local Label ? }
  450. if is_locallabel(actasmpattern) then
  451. begin
  452. CreateLocalLabel(actasmpattern,hl,false);
  453. Consume(AS_ID);
  454. AddLabelOperand(hl);
  455. end
  456. else
  457. { Check for label }
  458. if SearchLabel(actasmpattern,hl,false) then
  459. begin
  460. Consume(AS_ID);
  461. AddLabelOperand(hl);
  462. end
  463. else
  464. { probably a variable or normal expression }
  465. { or a procedure (such as in CALL ID) }
  466. Begin
  467. { is it a constant ? }
  468. if SearchIConstant(actasmpattern,l) then
  469. Begin
  470. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  471. Message(asmr_e_invalid_operand_type);
  472. BuildConstantOperand(oper);
  473. end
  474. else
  475. begin
  476. expr:=actasmpattern;
  477. Consume(AS_ID);
  478. { typecasting? }
  479. if (actasmtoken=AS_LPAREN) and
  480. SearchType(expr,typesize) then
  481. begin
  482. oper.hastype:=true;
  483. Consume(AS_LPAREN);
  484. BuildOperand(oper);
  485. Consume(AS_RPAREN);
  486. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  487. oper.SetSize(typesize,true);
  488. end
  489. else
  490. begin
  491. if oper.SetupVar(expr,false) then
  492. ReadAt(oper)
  493. else
  494. Begin
  495. { look for special symbols ... }
  496. if expr= '__HIGH' then
  497. begin
  498. consume(AS_LPAREN);
  499. if not oper.setupvar('high'+actasmpattern,false) then
  500. Message1(sym_e_unknown_id,'high'+actasmpattern);
  501. consume(AS_ID);
  502. consume(AS_RPAREN);
  503. end
  504. else
  505. if expr = '__RESULT' then
  506. oper.SetUpResult
  507. else
  508. if expr = '__SELF' then
  509. oper.SetupSelf
  510. else
  511. if expr = '__OLDEBP' then
  512. oper.SetupOldEBP
  513. else
  514. Message1(sym_e_unknown_id,expr);
  515. end;
  516. end;
  517. end;
  518. if actasmtoken=AS_DOT then
  519. MaybeRecordOffset;
  520. { add a constant expression? }
  521. if (actasmtoken=AS_PLUS) then
  522. begin
  523. l:=BuildConstExpression(true,entered_paren);
  524. case oper.opr.typ of
  525. OPR_CONSTANT :
  526. inc(oper.opr.val,l);
  527. OPR_LOCAL :
  528. inc(oper.opr.localsymofs,l);
  529. OPR_REFERENCE :
  530. inc(oper.opr.ref.offset,l);
  531. else
  532. internalerror(2003092017);
  533. end;
  534. end
  535. end;
  536. { Do we have a indexing reference, then parse it also }
  537. if actasmtoken=AS_LPAREN then
  538. BuildReference(oper);
  539. end;
  540. AS_REGISTER: { Register, a variable reference or a constant reference }
  541. Begin
  542. { save the type of register used. }
  543. tempreg:=actasmregister;
  544. Consume(AS_REGISTER);
  545. if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  546. begin
  547. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  548. Message(asmr_e_invalid_operand_type);
  549. oper.opr.typ:=OPR_REGISTER;
  550. oper.opr.reg:=tempreg;
  551. end
  552. else
  553. Message(asmr_e_syn_operand);
  554. end;
  555. AS_END,
  556. AS_SEPARATOR,
  557. AS_COMMA: ;
  558. else
  559. Begin
  560. Message(asmr_e_syn_operand);
  561. Consume(actasmtoken);
  562. end;
  563. end; { end case }
  564. if refaddr<>addr_full then
  565. begin
  566. if oper.opr.typ<>OPR_REFERENCE then
  567. oper.InitRef;
  568. oper.opr.ref.refaddr:=refaddr;
  569. Consume(AS_RPAREN);
  570. end
  571. else if (oper.opr.typ=OPR_REFERENCE) and
  572. (oper.opr.ref.refaddr=addr_no) and
  573. assigned(oper.opr.ref.symbol) then
  574. oper.opr.ref.refaddr:=addr_full;
  575. end;
  576. {*****************************************************************************
  577. trv64attreader
  578. *****************************************************************************}
  579. procedure trv64attreader.BuildOpCode(instr : trvinstruction);
  580. var
  581. operandnum : longint;
  582. Begin
  583. { opcode }
  584. if (actasmtoken<>AS_OPCODE) then
  585. Begin
  586. Message(asmr_e_invalid_or_missing_opcode);
  587. RecoverConsume(true);
  588. exit;
  589. end;
  590. { Fill the instr object with the current state }
  591. with instr do
  592. begin
  593. Opcode:=ActOpcode;
  594. condition:=ActCondition;
  595. ordering:=actmemoryordering;
  596. end;
  597. { We are reading operands, so opcode will be an AS_ID }
  598. operandnum:=1;
  599. Consume(AS_OPCODE);
  600. { Zero operand opcode ? }
  601. if actasmtoken in [AS_SEPARATOR,AS_END] then
  602. begin
  603. operandnum:=0;
  604. exit;
  605. end;
  606. { Read the operands }
  607. repeat
  608. case actasmtoken of
  609. AS_COMMA: { Operand delimiter }
  610. Begin
  611. if operandnum>Max_Operands then
  612. Message(asmr_e_too_many_operands)
  613. else
  614. begin
  615. { condition operands doesn't set the operand but write to the
  616. condition field of the instruction
  617. }
  618. if instr.Operands[operandnum].opr.typ<>OPR_NONE then
  619. Inc(operandnum);
  620. end;
  621. Consume(AS_COMMA);
  622. end;
  623. AS_SEPARATOR,
  624. AS_END : { End of asm operands for this opcode }
  625. begin
  626. break;
  627. end;
  628. else
  629. BuildOperand(instr.Operands[operandnum] as trvoperand);
  630. end; { end case }
  631. until false;
  632. if (operandnum=1) and (instr.Operands[operandnum].opr.typ=OPR_NONE) then
  633. dec(operandnum);
  634. instr.Ops:=operandnum;
  635. end;
  636. function trv64attreader.is_register(const s: string): boolean;
  637. type
  638. treg2str = record
  639. name : string[3];
  640. reg : tregister;
  641. end;
  642. const
  643. extraregs : array[0..31] of treg2str = (
  644. (name: 'A0'; reg : NR_X10),
  645. (name: 'A1'; reg : NR_X11),
  646. (name: 'A2'; reg : NR_X12),
  647. (name: 'A3'; reg : NR_X13),
  648. (name: 'A4'; reg : NR_X14),
  649. (name: 'A5'; reg : NR_X15),
  650. (name: 'A6'; reg : NR_X16),
  651. (name: 'A7'; reg : NR_X17),
  652. (name: 'RA'; reg : NR_X1),
  653. (name: 'SP'; reg : NR_X2),
  654. (name: 'GP'; reg : NR_X3),
  655. (name: 'TP'; reg : NR_X4),
  656. (name: 'T0'; reg : NR_X5),
  657. (name: 'T1'; reg : NR_X6),
  658. (name: 'T2'; reg : NR_X7),
  659. (name: 'S0'; reg : NR_X8),
  660. (name: 'FP'; reg : NR_X8),
  661. (name: 'S1'; reg : NR_X9),
  662. (name: 'S2'; reg : NR_X18),
  663. (name: 'S3'; reg : NR_X19),
  664. (name: 'S4'; reg : NR_X20),
  665. (name: 'S5'; reg : NR_X21),
  666. (name: 'S6'; reg : NR_X22),
  667. (name: 'S7'; reg : NR_X23),
  668. (name: 'S8'; reg : NR_X24),
  669. (name: 'S9'; reg : NR_X25),
  670. (name: 'S10';reg : NR_X26),
  671. (name: 'S11';reg : NR_X27),
  672. (name: 'T3'; reg : NR_X28),
  673. (name: 'T4'; reg : NR_X29),
  674. (name: 'T5'; reg : NR_X30),
  675. (name: 'T6'; reg : NR_X31)
  676. );
  677. var
  678. i : longint;
  679. begin
  680. result:=inherited is_register(s);
  681. { reg found?
  682. possible aliases are always 2 char
  683. }
  684. if result or (not (length(s) in [2,3])) then
  685. exit;
  686. for i:=low(extraregs) to high(extraregs) do
  687. begin
  688. if s=extraregs[i].name then
  689. begin
  690. actasmregister:=extraregs[i].reg;
  691. result:=true;
  692. actasmtoken:=AS_REGISTER;
  693. exit;
  694. end;
  695. end;
  696. end;
  697. function trv64attreader.is_asmopcode(const s: string):boolean;
  698. var
  699. cond : tasmcond;
  700. hs, postfix : string;
  701. l: longint;
  702. Begin
  703. { making s a value parameter would break other assembler readers }
  704. hs:=s;
  705. is_asmopcode:=false;
  706. { clear op code }
  707. actopcode:=A_None;
  708. { clear condition }
  709. fillchar(actcondition,sizeof(actcondition),0);
  710. { check for direction hint }
  711. actopcode := tasmop(ptruint(iasmops.find(hs)));
  712. if actopcode <> A_NONE then
  713. begin
  714. actasmtoken:=AS_OPCODE;
  715. is_asmopcode:=true;
  716. exit;
  717. end;
  718. { not found, check branch instructions }
  719. if hs[1]='B' then
  720. begin
  721. { we can search here without an extra table which is sorted by string length
  722. because we take the whole remaining string without the leading B }
  723. actopcode := A_Bxx;
  724. for cond:=low(TAsmCond) to high(TAsmCond) do
  725. if copy(hs,2,length(s)-1)=uppercond2str[cond] then
  726. begin
  727. actcondition:=cond;
  728. actasmtoken:=AS_OPCODE;
  729. is_asmopcode:=true;
  730. exit;
  731. end;
  732. end;
  733. { check atomic instructions }
  734. if (pos('AMO',hs)=1) or
  735. (pos('LR', hs)=1) or
  736. (pos('SC', hs)=1) then
  737. begin
  738. l := length(hs)-1;
  739. while l>1 do
  740. begin
  741. actopcode := tasmop(ptruint(iasmops.find(copy(hs,1,l))));
  742. if actopcode <> A_None then
  743. begin
  744. postfix := copy(hs,l+1,length(hs)-l);
  745. if postfix='.AQRL' then actmemoryordering:=[moAq,moRl]
  746. else if postfix='.RL' then actmemoryordering:=[moRl]
  747. else if postfix='.AQ' then actmemoryordering:=[moAq]
  748. else
  749. exit;
  750. actasmtoken:=AS_OPCODE;
  751. is_asmopcode:=true;
  752. exit;
  753. end;
  754. dec(l);
  755. end;
  756. end;
  757. end;
  758. procedure trv64attreader.handleopcode;
  759. var
  760. instr : trvinstruction;
  761. begin
  762. instr:=trvinstruction.Create(trvoperand);
  763. BuildOpcode(instr);
  764. instr.condition := actcondition;
  765. {
  766. instr.AddReferenceSizes;
  767. instr.SetInstructionOpsize;
  768. instr.CheckOperandSizes;
  769. }
  770. instr.ConcatInstruction(curlist);
  771. instr.Free;
  772. actmemoryordering:=[];
  773. end;
  774. {*****************************************************************************
  775. Initialize
  776. *****************************************************************************}
  777. const
  778. asmmode_rv64_standard_info : tasmmodeinfo =
  779. (
  780. id : asmmode_standard;
  781. idtxt : 'STANDARD';
  782. casmreader : trv64attreader;
  783. );
  784. initialization
  785. RegisterAsmMode(asmmode_rv64_standard_info);
  786. end.