rarv64gas.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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, rarv,
  22. cpubase;
  23. type
  24. trv64attreader = class(tattreader)
  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(200309202);
  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. end;
  208. Consume(AS_RPAREN);
  209. if actasmtoken=AS_AT then
  210. ReadAt(oper);
  211. End;
  212. AS_COMMA: { (, ... can either be scaling, or index }
  213. Begin
  214. Consume(AS_COMMA);
  215. { Index }
  216. if (actasmtoken=AS_REGISTER) then
  217. Begin
  218. oper.opr.ref.index:=actasmregister;
  219. Consume(AS_REGISTER);
  220. { check for scaling ... }
  221. Consume_RParen;
  222. end
  223. else
  224. begin
  225. Message(asmr_e_invalid_reference_syntax);
  226. RecoverConsume(false);
  227. end;
  228. end;
  229. else
  230. Begin
  231. Message(asmr_e_invalid_reference_syntax);
  232. RecoverConsume(false);
  233. end;
  234. end;
  235. end;
  236. procedure trv64attreader.BuildOperand(oper: trvoperand);
  237. var
  238. expr : string;
  239. typesize,l : aint;
  240. procedure AddLabelOperand(hl:tasmlabel);
  241. begin
  242. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  243. is_calljmp(actopcode) then
  244. begin
  245. oper.opr.typ:=OPR_SYMBOL;
  246. oper.opr.symbol:=hl;
  247. end
  248. else
  249. begin
  250. oper.InitRef;
  251. oper.opr.ref.symbol:=hl;
  252. end;
  253. end;
  254. procedure MaybeRecordOffset;
  255. var
  256. mangledname: string;
  257. hasdot : boolean;
  258. l,
  259. toffset,
  260. tsize : aint;
  261. begin
  262. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  263. exit;
  264. l:=0;
  265. hasdot:=(actasmtoken=AS_DOT);
  266. if hasdot then
  267. begin
  268. if expr<>'' then
  269. begin
  270. BuildRecordOffsetSize(expr,toffset,tsize,mangledname,false);
  271. if (oper.opr.typ<>OPR_CONSTANT) and
  272. (mangledname<>'') then
  273. Message(asmr_e_wrong_sym_type);
  274. inc(l,toffset);
  275. oper.SetSize(tsize,true);
  276. end;
  277. end;
  278. if actasmtoken in [AS_PLUS,AS_MINUS] then
  279. inc(l,BuildConstExpression(true,false));
  280. case oper.opr.typ of
  281. OPR_LOCAL :
  282. begin
  283. { don't allow direct access to fields of parameters, because that
  284. will generate buggy code. Allow it only for explicit typecasting }
  285. if hasdot and
  286. (not oper.hastype) and
  287. (tabstractvarsym(oper.opr.localsym).owner.symtabletype=parasymtable) and
  288. (current_procinfo.procdef.proccalloption<>pocall_register) then
  289. Message(asmr_e_cannot_access_field_directly_for_parameters);
  290. inc(oper.opr.localsymofs,l)
  291. end;
  292. OPR_CONSTANT :
  293. if (mangledname<>'') then
  294. begin
  295. if (oper.opr.val<>0) then
  296. Message(asmr_e_wrong_sym_type);
  297. oper.opr.typ:=OPR_SYMBOL;
  298. oper.opr.symbol:=current_asmdata.DefineAsmSymbol(mangledname,AB_EXTERNAL,AT_FUNCTION,voidcodepointertype);
  299. end
  300. else
  301. inc(oper.opr.val,l);
  302. OPR_REFERENCE :
  303. inc(oper.opr.ref.offset,l);
  304. OPR_SYMBOL:
  305. Message(asmr_e_invalid_symbol_ref);
  306. else
  307. internalerror(200309221);
  308. end;
  309. end;
  310. function MaybeBuildReference:boolean;
  311. { Try to create a reference, if not a reference is found then false
  312. is returned }
  313. begin
  314. MaybeBuildReference:=true;
  315. case actasmtoken of
  316. AS_INTNUM,
  317. AS_MINUS,
  318. AS_PLUS:
  319. Begin
  320. oper.opr.ref.offset:=BuildConstExpression(True,False);
  321. if actasmtoken<>AS_LPAREN then
  322. Message(asmr_e_invalid_reference_syntax)
  323. else
  324. BuildReference(oper);
  325. end;
  326. AS_LPAREN:
  327. BuildReference(oper);
  328. AS_ID: { only a variable is allowed ... }
  329. Begin
  330. ReadSym(oper);
  331. case actasmtoken of
  332. AS_END,
  333. AS_SEPARATOR,
  334. AS_COMMA: ;
  335. AS_LPAREN:
  336. BuildReference(oper);
  337. else
  338. Begin
  339. Message(asmr_e_invalid_reference_syntax);
  340. Consume(actasmtoken);
  341. end;
  342. end; {end case }
  343. end;
  344. else
  345. MaybeBuildReference:=false;
  346. end; { end case }
  347. end;
  348. function is_fenceflag(hs : string): boolean;
  349. var
  350. i: longint;
  351. flags: TFenceFlags;
  352. begin
  353. is_fenceflag := false;
  354. flags:=[];
  355. hs:=lower(hs);
  356. if (actopcode in [A_FENCE]) and (length(hs) >= 1) then
  357. begin
  358. for i:=1 to length(hs) do
  359. begin
  360. case hs[i] of
  361. 'i':
  362. Include(flags,ffi);
  363. 'o':
  364. Include(flags,ffo);
  365. 'r':
  366. Include(flags,ffr);
  367. 'w':
  368. Include(flags,ffw);
  369. else
  370. exit;
  371. end;
  372. end;
  373. oper.opr.typ := OPR_FENCEFLAGS;
  374. oper.opr.fenceflags := flags;
  375. exit(true);
  376. end;
  377. end;
  378. var
  379. tempreg : tregister;
  380. hl : tasmlabel;
  381. ofs : aint;
  382. refaddr: trefaddr;
  383. Begin
  384. expr:='';
  385. refaddr:=addr_full;
  386. if actasmtoken=AS_MOD then
  387. begin
  388. consume(AS_MOD);
  389. if actasmtoken<>AS_ID then
  390. begin
  391. Message(asmr_e_invalid_reference_syntax);
  392. RecoverConsume(false);
  393. end
  394. else
  395. begin
  396. if lower(actasmpattern)='pcrel_hi' then
  397. refaddr:=addr_pcrel_hi20
  398. else if lower(actasmpattern)='pcrel_lo' then
  399. refaddr:=addr_pcrel_lo12
  400. else if lower(actasmpattern)='hi' then
  401. refaddr:=addr_hi20
  402. else if lower(actasmpattern)='lo' then
  403. refaddr:=addr_lo12
  404. else
  405. begin
  406. Message(asmr_e_invalid_reference_syntax);
  407. RecoverConsume(false);
  408. end;
  409. consume(AS_ID);
  410. consume(AS_LPAREN);
  411. end;
  412. end;
  413. case actasmtoken of
  414. AS_LPAREN: { Memory reference or constant expression }
  415. Begin
  416. oper.InitRef;
  417. BuildReference(oper);
  418. end;
  419. AS_INTNUM,
  420. AS_MINUS,
  421. AS_PLUS:
  422. Begin
  423. { Constant memory offset }
  424. { This must absolutely be followed by ( }
  425. oper.InitRef;
  426. oper.opr.ref.offset:=BuildConstExpression(True,False);
  427. if actasmtoken<>AS_LPAREN then
  428. begin
  429. ofs:=oper.opr.ref.offset;
  430. BuildConstantOperand(oper);
  431. inc(oper.opr.val,ofs);
  432. end
  433. else
  434. BuildReference(oper);
  435. end;
  436. AS_ID: { A constant expression, or a Variable ref. }
  437. Begin
  438. if is_fenceflag(actasmpattern) then
  439. begin
  440. consume(AS_ID);
  441. end
  442. else
  443. { Local Label ? }
  444. if is_locallabel(actasmpattern) then
  445. begin
  446. CreateLocalLabel(actasmpattern,hl,false);
  447. Consume(AS_ID);
  448. AddLabelOperand(hl);
  449. end
  450. else
  451. { Check for label }
  452. if SearchLabel(actasmpattern,hl,false) then
  453. begin
  454. Consume(AS_ID);
  455. AddLabelOperand(hl);
  456. end
  457. else
  458. { probably a variable or normal expression }
  459. { or a procedure (such as in CALL ID) }
  460. Begin
  461. { is it a constant ? }
  462. if SearchIConstant(actasmpattern,l) then
  463. Begin
  464. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  465. Message(asmr_e_invalid_operand_type);
  466. BuildConstantOperand(oper);
  467. end
  468. else
  469. begin
  470. expr:=actasmpattern;
  471. Consume(AS_ID);
  472. { typecasting? }
  473. if (actasmtoken=AS_LPAREN) and
  474. SearchType(expr,typesize) then
  475. begin
  476. oper.hastype:=true;
  477. Consume(AS_LPAREN);
  478. BuildOperand(oper);
  479. Consume(AS_RPAREN);
  480. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  481. oper.SetSize(typesize,true);
  482. end
  483. else
  484. begin
  485. if oper.SetupVar(expr,false) then
  486. ReadAt(oper)
  487. else
  488. Begin
  489. { look for special symbols ... }
  490. if expr= '__HIGH' then
  491. begin
  492. consume(AS_LPAREN);
  493. if not oper.setupvar('high'+actasmpattern,false) then
  494. Message1(sym_e_unknown_id,'high'+actasmpattern);
  495. consume(AS_ID);
  496. consume(AS_RPAREN);
  497. end
  498. else
  499. if expr = '__RESULT' then
  500. oper.SetUpResult
  501. else
  502. if expr = '__SELF' then
  503. oper.SetupSelf
  504. else
  505. if expr = '__OLDEBP' then
  506. oper.SetupOldEBP
  507. else
  508. Message1(sym_e_unknown_id,expr);
  509. end;
  510. end;
  511. end;
  512. if actasmtoken=AS_DOT then
  513. MaybeRecordOffset;
  514. { add a constant expression? }
  515. if (actasmtoken=AS_PLUS) then
  516. begin
  517. l:=BuildConstExpression(true,false);
  518. case oper.opr.typ of
  519. OPR_CONSTANT :
  520. inc(oper.opr.val,l);
  521. OPR_LOCAL :
  522. inc(oper.opr.localsymofs,l);
  523. OPR_REFERENCE :
  524. inc(oper.opr.ref.offset,l);
  525. else
  526. internalerror(200309202);
  527. end;
  528. end
  529. end;
  530. { Do we have a indexing reference, then parse it also }
  531. if actasmtoken=AS_LPAREN then
  532. BuildReference(oper);
  533. end;
  534. AS_REGISTER: { Register, a variable reference or a constant reference }
  535. Begin
  536. { save the type of register used. }
  537. tempreg:=actasmregister;
  538. Consume(AS_REGISTER);
  539. if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  540. begin
  541. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  542. Message(asmr_e_invalid_operand_type);
  543. oper.opr.typ:=OPR_REGISTER;
  544. oper.opr.reg:=tempreg;
  545. end
  546. else
  547. Message(asmr_e_syn_operand);
  548. end;
  549. AS_END,
  550. AS_SEPARATOR,
  551. AS_COMMA: ;
  552. else
  553. Begin
  554. Message(asmr_e_syn_operand);
  555. Consume(actasmtoken);
  556. end;
  557. end; { end case }
  558. if refaddr<>addr_full then
  559. begin
  560. if oper.opr.typ<>OPR_REFERENCE then
  561. oper.InitRef;
  562. oper.opr.ref.refaddr:=refaddr;
  563. Consume(AS_RPAREN);
  564. end;
  565. end;
  566. {*****************************************************************************
  567. trv64attreader
  568. *****************************************************************************}
  569. procedure trv64attreader.BuildOpCode(instr : trvinstruction);
  570. var
  571. operandnum : longint;
  572. Begin
  573. { opcode }
  574. if (actasmtoken<>AS_OPCODE) then
  575. Begin
  576. Message(asmr_e_invalid_or_missing_opcode);
  577. RecoverConsume(true);
  578. exit;
  579. end;
  580. { Fill the instr object with the current state }
  581. with instr do
  582. begin
  583. Opcode:=ActOpcode;
  584. condition:=ActCondition;
  585. ordering:=actmemoryordering;
  586. end;
  587. { We are reading operands, so opcode will be an AS_ID }
  588. operandnum:=1;
  589. Consume(AS_OPCODE);
  590. { Zero operand opcode ? }
  591. if actasmtoken in [AS_SEPARATOR,AS_END] then
  592. begin
  593. operandnum:=0;
  594. exit;
  595. end;
  596. { Read the operands }
  597. repeat
  598. case actasmtoken of
  599. AS_COMMA: { Operand delimiter }
  600. Begin
  601. if operandnum>Max_Operands then
  602. Message(asmr_e_too_many_operands)
  603. else
  604. begin
  605. { condition operands doesn't set the operand but write to the
  606. condition field of the instruction
  607. }
  608. if instr.Operands[operandnum].opr.typ<>OPR_NONE then
  609. Inc(operandnum);
  610. end;
  611. Consume(AS_COMMA);
  612. end;
  613. AS_SEPARATOR,
  614. AS_END : { End of asm operands for this opcode }
  615. begin
  616. break;
  617. end;
  618. else
  619. BuildOperand(instr.Operands[operandnum] as trvoperand);
  620. end; { end case }
  621. until false;
  622. if (operandnum=1) and (instr.Operands[operandnum].opr.typ=OPR_NONE) then
  623. dec(operandnum);
  624. instr.Ops:=operandnum;
  625. end;
  626. function trv64attreader.is_register(const s: string): boolean;
  627. type
  628. treg2str = record
  629. name : string[3];
  630. reg : tregister;
  631. end;
  632. const
  633. extraregs : array[0..31] of treg2str = (
  634. (name: 'A0'; reg : NR_X10),
  635. (name: 'A1'; reg : NR_X11),
  636. (name: 'A2'; reg : NR_X12),
  637. (name: 'A3'; reg : NR_X13),
  638. (name: 'A4'; reg : NR_X14),
  639. (name: 'A5'; reg : NR_X15),
  640. (name: 'A6'; reg : NR_X16),
  641. (name: 'A7'; reg : NR_X17),
  642. (name: 'RA'; reg : NR_X1),
  643. (name: 'SP'; reg : NR_X2),
  644. (name: 'GP'; reg : NR_X3),
  645. (name: 'TP'; reg : NR_X4),
  646. (name: 'T0'; reg : NR_X5),
  647. (name: 'T1'; reg : NR_X6),
  648. (name: 'T2'; reg : NR_X7),
  649. (name: 'S0'; reg : NR_X8),
  650. (name: 'FP'; reg : NR_X8),
  651. (name: 'S1'; reg : NR_X9),
  652. (name: 'S2'; reg : NR_X18),
  653. (name: 'S3'; reg : NR_X19),
  654. (name: 'S4'; reg : NR_X20),
  655. (name: 'S5'; reg : NR_X21),
  656. (name: 'S6'; reg : NR_X22),
  657. (name: 'S7'; reg : NR_X23),
  658. (name: 'S8'; reg : NR_X24),
  659. (name: 'S9'; reg : NR_X25),
  660. (name: 'S10';reg : NR_X26),
  661. (name: 'S11';reg : NR_X27),
  662. (name: 'T3'; reg : NR_X28),
  663. (name: 'T4'; reg : NR_X29),
  664. (name: 'T5'; reg : NR_X30),
  665. (name: 'T6'; reg : NR_X31)
  666. );
  667. var
  668. i : longint;
  669. begin
  670. result:=inherited is_register(s);
  671. { reg found?
  672. possible aliases are always 2 char
  673. }
  674. if result or (not (length(s) in [2,3])) then
  675. exit;
  676. for i:=low(extraregs) to high(extraregs) do
  677. begin
  678. if s=extraregs[i].name then
  679. begin
  680. actasmregister:=extraregs[i].reg;
  681. result:=true;
  682. actasmtoken:=AS_REGISTER;
  683. exit;
  684. end;
  685. end;
  686. end;
  687. function trv64attreader.is_asmopcode(const s: string):boolean;
  688. var
  689. cond : tasmcond;
  690. hs, postfix : string;
  691. l: longint;
  692. Begin
  693. { making s a value parameter would break other assembler readers }
  694. hs:=s;
  695. is_asmopcode:=false;
  696. { clear op code }
  697. actopcode:=A_None;
  698. { clear condition }
  699. fillchar(actcondition,sizeof(actcondition),0);
  700. { check for direction hint }
  701. actopcode := tasmop(ptruint(iasmops.find(hs)));
  702. if actopcode <> A_NONE then
  703. begin
  704. actasmtoken:=AS_OPCODE;
  705. is_asmopcode:=true;
  706. exit;
  707. end;
  708. { not found, check branch instructions }
  709. if hs[1]='B' then
  710. begin
  711. { we can search here without an extra table which is sorted by string length
  712. because we take the whole remaining string without the leading B }
  713. actopcode := A_Bxx;
  714. for cond:=low(TAsmCond) to high(TAsmCond) do
  715. if copy(hs,2,length(s)-1)=uppercond2str[cond] then
  716. begin
  717. actcondition:=cond;
  718. actasmtoken:=AS_OPCODE;
  719. is_asmopcode:=true;
  720. exit;
  721. end;
  722. end;
  723. { check atomic instructions }
  724. if (pos('AMO',hs)=1) or
  725. (pos('LR', hs)=1) or
  726. (pos('SC', hs)=1) then
  727. begin
  728. l := length(hs)-1;
  729. while l>1 do
  730. begin
  731. actopcode := tasmop(ptruint(iasmops.find(copy(hs,1,l))));
  732. if actopcode <> A_None then
  733. begin
  734. postfix := copy(hs,l+1,length(hs)-l);
  735. if postfix='.AQRL' then actmemoryordering:=[moAq,moRl]
  736. else if postfix='.RL' then actmemoryordering:=[moRl]
  737. else if postfix='.AQ' then actmemoryordering:=[moAq]
  738. else
  739. exit;
  740. actasmtoken:=AS_OPCODE;
  741. is_asmopcode:=true;
  742. exit;
  743. end;
  744. dec(l);
  745. end;
  746. end;
  747. end;
  748. procedure trv64attreader.handleopcode;
  749. var
  750. instr : trvinstruction;
  751. begin
  752. instr:=trvinstruction.Create(trvoperand);
  753. BuildOpcode(instr);
  754. instr.condition := actcondition;
  755. {
  756. instr.AddReferenceSizes;
  757. instr.SetInstructionOpsize;
  758. instr.CheckOperandSizes;
  759. }
  760. instr.ConcatInstruction(curlist);
  761. instr.Free;
  762. actmemoryordering:=[];
  763. end;
  764. {*****************************************************************************
  765. Initialize
  766. *****************************************************************************}
  767. const
  768. asmmode_rv64_standard_info : tasmmodeinfo =
  769. (
  770. id : asmmode_standard;
  771. idtxt : 'STANDARD';
  772. casmreader : trv64attreader;
  773. );
  774. initialization
  775. RegisterAsmMode(asmmode_rv64_standard_info);
  776. end.