bfin-parse.y 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672
  1. /* bfin-parse.y ADI Blackfin parser
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS 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 3, or (at your option)
  7. any later version.
  8. GAS 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 GAS; see the file COPYING. If not, write to the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. %{
  17. #include "as.h"
  18. #include "bfin-aux.h" /* Opcode generating auxiliaries. */
  19. #include "elf/common.h"
  20. #include "elf/bfin.h"
  21. /* This file uses an old-style yyerror returning int. Disable
  22. generation of a modern prototype for yyerror. */
  23. #define yyerror yyerror
  24. #define DSP32ALU(aopcde, HL, dst1, dst0, src0, src1, s, x, aop) \
  25. bfin_gen_dsp32alu (HL, aopcde, aop, s, x, dst0, dst1, src0, src1)
  26. #define DSP32MAC(op1, MM, mmod, w1, P, h01, h11, h00, h10, dst, op0, src0, src1, w0) \
  27. bfin_gen_dsp32mac (op1, MM, mmod, w1, P, h01, h11, h00, h10, op0, \
  28. dst, src0, src1, w0)
  29. #define DSP32MULT(op1, MM, mmod, w1, P, h01, h11, h00, h10, dst, op0, src0, src1, w0) \
  30. bfin_gen_dsp32mult (op1, MM, mmod, w1, P, h01, h11, h00, h10, op0, \
  31. dst, src0, src1, w0)
  32. #define DSP32SHIFT(sopcde, dst0, src0, src1, sop, hls) \
  33. bfin_gen_dsp32shift (sopcde, dst0, src0, src1, sop, hls)
  34. #define DSP32SHIFTIMM(sopcde, dst0, immag, src1, sop, hls) \
  35. bfin_gen_dsp32shiftimm (sopcde, dst0, immag, src1, sop, hls)
  36. #define LDIMMHALF_R(reg, h, s, z, hword) \
  37. bfin_gen_ldimmhalf (reg, h, s, z, hword, 1)
  38. #define LDIMMHALF_R5(reg, h, s, z, hword) \
  39. bfin_gen_ldimmhalf (reg, h, s, z, hword, 2)
  40. #define LDSTIDXI(ptr, reg, w, sz, z, offset) \
  41. bfin_gen_ldstidxi (ptr, reg, w, sz, z, offset)
  42. #define LDST(ptr, reg, aop, sz, z, w) \
  43. bfin_gen_ldst (ptr, reg, aop, sz, z, w)
  44. #define LDSTII(ptr, reg, offset, w, op) \
  45. bfin_gen_ldstii (ptr, reg, offset, w, op)
  46. #define DSPLDST(i, m, reg, aop, w) \
  47. bfin_gen_dspldst (i, reg, aop, w, m)
  48. #define LDSTPMOD(ptr, reg, idx, aop, w) \
  49. bfin_gen_ldstpmod (ptr, reg, aop, w, idx)
  50. #define LDSTIIFP(offset, reg, w) \
  51. bfin_gen_ldstiifp (reg, offset, w)
  52. #define LOGI2OP(dst, src, opc) \
  53. bfin_gen_logi2op (opc, src, dst.regno & CODE_MASK)
  54. #define ALU2OP(dst, src, opc) \
  55. bfin_gen_alu2op (dst, src, opc)
  56. #define BRCC(t, b, offset) \
  57. bfin_gen_brcc (t, b, offset)
  58. #define UJUMP(offset) \
  59. bfin_gen_ujump (offset)
  60. #define PROGCTRL(prgfunc, poprnd) \
  61. bfin_gen_progctrl (prgfunc, poprnd)
  62. #define PUSHPOPMULTIPLE(dr, pr, d, p, w) \
  63. bfin_gen_pushpopmultiple (dr, pr, d, p, w)
  64. #define PUSHPOPREG(reg, w) \
  65. bfin_gen_pushpopreg (reg, w)
  66. #define CALLA(addr, s) \
  67. bfin_gen_calla (addr, s)
  68. #define LINKAGE(r, framesize) \
  69. bfin_gen_linkage (r, framesize)
  70. #define COMPI2OPD(dst, src, op) \
  71. bfin_gen_compi2opd (dst, src, op)
  72. #define COMPI2OPP(dst, src, op) \
  73. bfin_gen_compi2opp (dst, src, op)
  74. #define DAGMODIK(i, op) \
  75. bfin_gen_dagmodik (i, op)
  76. #define DAGMODIM(i, m, op, br) \
  77. bfin_gen_dagmodim (i, m, op, br)
  78. #define COMP3OP(dst, src0, src1, opc) \
  79. bfin_gen_comp3op (src0, src1, dst, opc)
  80. #define PTR2OP(dst, src, opc) \
  81. bfin_gen_ptr2op (dst, src, opc)
  82. #define CCFLAG(x, y, opc, i, g) \
  83. bfin_gen_ccflag (x, y, opc, i, g)
  84. #define CCMV(src, dst, t) \
  85. bfin_gen_ccmv (src, dst, t)
  86. #define CACTRL(reg, a, op) \
  87. bfin_gen_cactrl (reg, a, op)
  88. #define LOOPSETUP(soffset, c, rop, eoffset, reg) \
  89. bfin_gen_loopsetup (soffset, c, rop, eoffset, reg)
  90. #define HL2(r1, r0) (IS_H (r1) << 1 | IS_H (r0))
  91. #define IS_RANGE(bits, expr, sign, mul) \
  92. value_match(expr, bits, sign, mul, 1)
  93. #define IS_URANGE(bits, expr, sign, mul) \
  94. value_match(expr, bits, sign, mul, 0)
  95. #define IS_CONST(expr) (expr->type == Expr_Node_Constant)
  96. #define IS_RELOC(expr) (expr->type != Expr_Node_Constant)
  97. #define IS_IMM(expr, bits) value_match (expr, bits, 0, 1, 1)
  98. #define IS_UIMM(expr, bits) value_match (expr, bits, 0, 1, 0)
  99. #define IS_PCREL4(expr) \
  100. (value_match (expr, 4, 0, 2, 0))
  101. #define IS_LPPCREL10(expr) \
  102. (value_match (expr, 10, 0, 2, 0))
  103. #define IS_PCREL10(expr) \
  104. (value_match (expr, 10, 0, 2, 1))
  105. #define IS_PCREL12(expr) \
  106. (value_match (expr, 12, 0, 2, 1))
  107. #define IS_PCREL24(expr) \
  108. (value_match (expr, 24, 0, 2, 1))
  109. static int value_match (Expr_Node *, int, int, int, int);
  110. extern FILE *errorf;
  111. extern INSTR_T insn;
  112. static Expr_Node *binary (Expr_Op_Type, Expr_Node *, Expr_Node *);
  113. static Expr_Node *unary (Expr_Op_Type, Expr_Node *);
  114. static void notethat (const char *, ...);
  115. extern char *yytext;
  116. /* Used to set SRCx fields to all 1s as described in the PRM. */
  117. static Register reg7 = {REG_R7, 0};
  118. void error (const char *format, ...)
  119. {
  120. va_list ap;
  121. static char buffer[2000];
  122. va_start (ap, format);
  123. vsprintf (buffer, format, ap);
  124. va_end (ap);
  125. as_bad ("%s", buffer);
  126. }
  127. static int
  128. yyerror (const char *msg)
  129. {
  130. if (msg[0] == '\0')
  131. error ("%s", msg);
  132. else if (yytext[0] != ';')
  133. error ("%s. Input text was %s.", msg, yytext);
  134. else
  135. error ("%s.", msg);
  136. return -1;
  137. }
  138. static int
  139. in_range_p (Expr_Node *exp, int from, int to, unsigned int mask)
  140. {
  141. int val = EXPR_VALUE (exp);
  142. if (exp->type != Expr_Node_Constant)
  143. return 0;
  144. if (val < from || val > to)
  145. return 0;
  146. return (val & mask) == 0;
  147. }
  148. extern int yylex (void);
  149. #define imm3(x) EXPR_VALUE (x)
  150. #define imm4(x) EXPR_VALUE (x)
  151. #define uimm4(x) EXPR_VALUE (x)
  152. #define imm5(x) EXPR_VALUE (x)
  153. #define uimm5(x) EXPR_VALUE (x)
  154. #define imm6(x) EXPR_VALUE (x)
  155. #define imm7(x) EXPR_VALUE (x)
  156. #define uimm8(x) EXPR_VALUE (x)
  157. #define imm16(x) EXPR_VALUE (x)
  158. #define uimm16s4(x) ((EXPR_VALUE (x)) >> 2)
  159. #define uimm16(x) EXPR_VALUE (x)
  160. /* Return true if a value is inside a range. */
  161. #define IN_RANGE(x, low, high) \
  162. (((EXPR_VALUE(x)) >= (low)) && (EXPR_VALUE(x)) <= ((high)))
  163. /* Auxiliary functions. */
  164. static int
  165. valid_dreg_pair (Register *reg1, Expr_Node *reg2)
  166. {
  167. if (!IS_DREG (*reg1))
  168. {
  169. yyerror ("Dregs expected");
  170. return 0;
  171. }
  172. if (reg1->regno != 1 && reg1->regno != 3)
  173. {
  174. yyerror ("Bad register pair");
  175. return 0;
  176. }
  177. if (imm7 (reg2) != reg1->regno - 1)
  178. {
  179. yyerror ("Bad register pair");
  180. return 0;
  181. }
  182. reg1->regno--;
  183. return 1;
  184. }
  185. static int
  186. check_multiply_halfregs (Macfunc *aa, Macfunc *ab)
  187. {
  188. if ((!REG_EQUAL (aa->s0, ab->s0) && !REG_EQUAL (aa->s0, ab->s1))
  189. || (!REG_EQUAL (aa->s1, ab->s1) && !REG_EQUAL (aa->s1, ab->s0)))
  190. return yyerror ("Source multiplication register mismatch");
  191. return 0;
  192. }
  193. /* Check mac option. */
  194. static int
  195. check_macfunc_option (Macfunc *a, Opt_mode *opt)
  196. {
  197. /* Default option is always valid. */
  198. if (opt->mod == 0)
  199. return 0;
  200. if ((a->w == 1 && a->P == 1
  201. && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_IU
  202. && opt->mod != M_S2RND && opt->mod != M_ISS2)
  203. || (a->w == 1 && a->P == 0
  204. && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_IU
  205. && opt->mod != M_T && opt->mod != M_TFU && opt->mod != M_S2RND
  206. && opt->mod != M_ISS2 && opt->mod != M_IH)
  207. || (a->w == 0 && a->P == 0
  208. && opt->mod != M_FU && opt->mod != M_IS && opt->mod != M_W32))
  209. return -1;
  210. return 0;
  211. }
  212. /* Check (vector) mac funcs and ops. */
  213. static int
  214. check_macfuncs (Macfunc *aa, Opt_mode *opa,
  215. Macfunc *ab, Opt_mode *opb)
  216. {
  217. /* Variables for swapping. */
  218. Macfunc mtmp;
  219. Opt_mode otmp;
  220. /* The option mode should be put at the end of the second instruction
  221. of the vector except M, which should follow MAC1 instruction. */
  222. if (opa->mod != 0)
  223. return yyerror ("Bad opt mode");
  224. /* If a0macfunc comes before a1macfunc, swap them. */
  225. if (aa->n == 0)
  226. {
  227. /* (M) is not allowed here. */
  228. if (opa->MM != 0)
  229. return yyerror ("(M) not allowed with A0MAC");
  230. if (ab->n != 1)
  231. return yyerror ("Vector AxMACs can't be same");
  232. mtmp = *aa; *aa = *ab; *ab = mtmp;
  233. otmp = *opa; *opa = *opb; *opb = otmp;
  234. }
  235. else
  236. {
  237. if (opb->MM != 0)
  238. return yyerror ("(M) not allowed with A0MAC");
  239. if (ab->n != 0)
  240. return yyerror ("Vector AxMACs can't be same");
  241. }
  242. /* If both ops are one of 0, 1, or 2, we have multiply_halfregs in both
  243. assignment_or_macfuncs. */
  244. if ((aa->op == 0 || aa->op == 1 || aa->op == 2)
  245. && (ab->op == 0 || ab->op == 1 || ab->op == 2))
  246. {
  247. if (check_multiply_halfregs (aa, ab) < 0)
  248. return -1;
  249. }
  250. else
  251. {
  252. /* Only one of the assign_macfuncs has a half reg multiply
  253. Evil trick: Just 'OR' their source register codes:
  254. We can do that, because we know they were initialized to 0
  255. in the rules that don't use multiply_halfregs. */
  256. aa->s0.regno |= (ab->s0.regno & CODE_MASK);
  257. aa->s1.regno |= (ab->s1.regno & CODE_MASK);
  258. }
  259. if (aa->w == ab->w && aa->P != ab->P)
  260. return yyerror ("Destination Dreg sizes (full or half) must match");
  261. if (aa->w && ab->w)
  262. {
  263. if (aa->P && (aa->dst.regno - ab->dst.regno) != 1)
  264. return yyerror ("Destination Dregs (full) must differ by one");
  265. if (!aa->P && aa->dst.regno != ab->dst.regno)
  266. return yyerror ("Destination Dregs (half) must match");
  267. }
  268. /* Make sure mod flags get ORed, too. */
  269. opb->mod |= opa->mod;
  270. /* Check option. */
  271. if (check_macfunc_option (aa, opb) < 0
  272. && check_macfunc_option (ab, opb) < 0)
  273. return yyerror ("bad option");
  274. /* Make sure first macfunc has got both P flags ORed. */
  275. aa->P |= ab->P;
  276. return 0;
  277. }
  278. static int
  279. is_group1 (INSTR_T x)
  280. {
  281. /* Group1 is dpsLDST, LDSTpmod, LDST, LDSTiiFP, LDSTii. */
  282. if ((x->value & 0xc000) == 0x8000 || (x->value == 0x0000))
  283. return 1;
  284. return 0;
  285. }
  286. static int
  287. is_group2 (INSTR_T x)
  288. {
  289. if ((((x->value & 0xfc00) == 0x9c00) /* dspLDST. */
  290. && !((x->value & 0xfde0) == 0x9c60) /* dagMODim. */
  291. && !((x->value & 0xfde0) == 0x9ce0) /* dagMODim with bit rev. */
  292. && !((x->value & 0xfde0) == 0x9d60)) /* pick dagMODik. */
  293. || (x->value == 0x0000))
  294. return 1;
  295. return 0;
  296. }
  297. static int
  298. is_store (INSTR_T x)
  299. {
  300. if (!x)
  301. return 0;
  302. if ((x->value & 0xf000) == 0x8000)
  303. {
  304. int aop = ((x->value >> 9) & 0x3);
  305. int w = ((x->value >> 11) & 0x1);
  306. if (!w || aop == 3)
  307. return 0;
  308. return 1;
  309. }
  310. if (((x->value & 0xFF60) == 0x9E60) || /* dagMODim_0 */
  311. ((x->value & 0xFFF0) == 0x9F60)) /* dagMODik_0 */
  312. return 0;
  313. /* decode_dspLDST_0 */
  314. if ((x->value & 0xFC00) == 0x9C00)
  315. {
  316. int w = ((x->value >> 9) & 0x1);
  317. if (w)
  318. return 1;
  319. }
  320. return 0;
  321. }
  322. static INSTR_T
  323. gen_multi_instr_1 (INSTR_T dsp32, INSTR_T dsp16_grp1, INSTR_T dsp16_grp2)
  324. {
  325. int mask1 = dsp32 ? insn_regmask (dsp32->value, dsp32->next->value) : 0;
  326. int mask2 = dsp16_grp1 ? insn_regmask (dsp16_grp1->value, 0) : 0;
  327. int mask3 = dsp16_grp2 ? insn_regmask (dsp16_grp2->value, 0) : 0;
  328. if ((mask1 & mask2) || (mask1 & mask3) || (mask2 & mask3))
  329. yyerror ("resource conflict in multi-issue instruction");
  330. /* Anomaly 05000074 */
  331. if (ENABLE_AC_05000074
  332. && dsp32 != NULL && dsp16_grp1 != NULL
  333. && (dsp32->value & 0xf780) == 0xc680
  334. && ((dsp16_grp1->value & 0xfe40) == 0x9240
  335. || (dsp16_grp1->value & 0xfe08) == 0xba08
  336. || (dsp16_grp1->value & 0xfc00) == 0xbc00))
  337. yyerror ("anomaly 05000074 - Multi-Issue Instruction with \
  338. dsp32shiftimm in slot1 and P-reg Store in slot2 Not Supported");
  339. if (is_store (dsp16_grp1) && is_store (dsp16_grp2))
  340. yyerror ("Only one instruction in multi-issue instruction can be a store");
  341. return bfin_gen_multi_instr (dsp32, dsp16_grp1, dsp16_grp2);
  342. }
  343. %}
  344. %union {
  345. INSTR_T instr;
  346. Expr_Node *expr;
  347. SYMBOL_T symbol;
  348. long value;
  349. Register reg;
  350. Macfunc macfunc;
  351. struct { int r0; int s0; int x0; int aop; } modcodes;
  352. struct { int r0; } r0;
  353. Opt_mode mod;
  354. }
  355. /* Tokens. */
  356. /* Vector Specific. */
  357. %token BYTEOP16P BYTEOP16M
  358. %token BYTEOP1P BYTEOP2P BYTEOP3P
  359. %token BYTEUNPACK BYTEPACK
  360. %token PACK
  361. %token SAA
  362. %token ALIGN8 ALIGN16 ALIGN24
  363. %token VIT_MAX
  364. %token EXTRACT DEPOSIT EXPADJ SEARCH
  365. %token ONES SIGN SIGNBITS
  366. /* Stack. */
  367. %token LINK UNLINK
  368. /* Registers. */
  369. %token REG
  370. %token PC
  371. %token CCREG BYTE_DREG
  372. %token REG_A_DOUBLE_ZERO REG_A_DOUBLE_ONE
  373. %token A_ZERO_DOT_L A_ZERO_DOT_H A_ONE_DOT_L A_ONE_DOT_H
  374. %token HALF_REG
  375. /* Progctrl. */
  376. %token NOP
  377. %token RTI RTS RTX RTN RTE
  378. %token HLT IDLE
  379. %token STI CLI
  380. %token CSYNC SSYNC
  381. %token EMUEXCPT
  382. %token RAISE EXCPT
  383. %token LSETUP
  384. %token LOOP
  385. %token LOOP_BEGIN
  386. %token LOOP_END
  387. %token DISALGNEXCPT
  388. %token JUMP JUMP_DOT_S JUMP_DOT_L
  389. %token CALL
  390. /* Emulator only. */
  391. %token ABORT
  392. /* Operators. */
  393. %token NOT TILDA BANG
  394. %token AMPERSAND BAR
  395. %token PERCENT
  396. %token CARET
  397. %token BXOR
  398. %token MINUS PLUS STAR SLASH
  399. %token NEG
  400. %token MIN MAX ABS
  401. %token DOUBLE_BAR
  402. %token _PLUS_BAR_PLUS _PLUS_BAR_MINUS _MINUS_BAR_PLUS _MINUS_BAR_MINUS
  403. %token _MINUS_MINUS _PLUS_PLUS
  404. /* Shift/rotate ops. */
  405. %token SHIFT LSHIFT ASHIFT BXORSHIFT
  406. %token _GREATER_GREATER_GREATER_THAN_ASSIGN
  407. %token ROT
  408. %token LESS_LESS GREATER_GREATER
  409. %token _GREATER_GREATER_GREATER
  410. %token _LESS_LESS_ASSIGN _GREATER_GREATER_ASSIGN
  411. %token DIVS DIVQ
  412. /* In place operators. */
  413. %token ASSIGN _STAR_ASSIGN
  414. %token _BAR_ASSIGN _CARET_ASSIGN _AMPERSAND_ASSIGN
  415. %token _MINUS_ASSIGN _PLUS_ASSIGN
  416. /* Assignments, comparisons. */
  417. %token _ASSIGN_BANG _LESS_THAN_ASSIGN _ASSIGN_ASSIGN
  418. %token GE LT LE GT
  419. %token LESS_THAN
  420. /* Cache. */
  421. %token FLUSHINV FLUSH
  422. %token IFLUSH PREFETCH
  423. /* Misc. */
  424. %token PRNT
  425. %token OUTC
  426. %token WHATREG
  427. %token TESTSET
  428. /* Modifiers. */
  429. %token ASL ASR
  430. %token B W
  431. %token NS S CO SCO
  432. %token TH TL
  433. %token BP
  434. %token BREV
  435. %token X Z
  436. %token M MMOD
  437. %token R RND RNDL RNDH RND12 RND20
  438. %token V
  439. %token LO HI
  440. /* Bit ops. */
  441. %token BITTGL BITCLR BITSET BITTST BITMUX
  442. /* Debug. */
  443. %token DBGAL DBGAH DBGHALT DBG DBGA DBGCMPLX
  444. /* Semantic auxiliaries. */
  445. %token IF COMMA BY
  446. %token COLON SEMICOLON
  447. %token RPAREN LPAREN LBRACK RBRACK
  448. %token STATUS_REG
  449. %token MNOP
  450. %token SYMBOL NUMBER
  451. %token GOT GOT17M4 FUNCDESC_GOT17M4
  452. %token AT PLTPC
  453. /* Types. */
  454. %type <instr> asm
  455. %type <value> MMOD
  456. %type <mod> opt_mode
  457. %type <value> NUMBER
  458. %type <r0> aligndir
  459. %type <modcodes> byteop_mod
  460. %type <reg> a_assign
  461. %type <reg> a_plusassign
  462. %type <reg> a_minusassign
  463. %type <macfunc> multiply_halfregs
  464. %type <macfunc> assign_macfunc
  465. %type <macfunc> a_macfunc
  466. %type <expr> expr_1
  467. %type <instr> asm_1
  468. %type <r0> vmod
  469. %type <modcodes> vsmod
  470. %type <modcodes> ccstat
  471. %type <r0> cc_op
  472. %type <reg> CCREG
  473. %type <reg> reg_with_postinc
  474. %type <reg> reg_with_predec
  475. %type <r0> searchmod
  476. %type <expr> symbol
  477. %type <symbol> SYMBOL
  478. %type <expr> eterm
  479. %type <reg> REG
  480. %type <reg> BYTE_DREG
  481. %type <reg> REG_A_DOUBLE_ZERO
  482. %type <reg> REG_A_DOUBLE_ONE
  483. %type <reg> REG_A
  484. %type <reg> STATUS_REG
  485. %type <expr> expr
  486. %type <r0> xpmod
  487. %type <r0> xpmod1
  488. %type <modcodes> smod
  489. %type <modcodes> b3_op
  490. %type <modcodes> rnd_op
  491. %type <modcodes> post_op
  492. %type <reg> HALF_REG
  493. %type <r0> iu_or_nothing
  494. %type <r0> plus_minus
  495. %type <r0> asr_asl
  496. %type <r0> asr_asl_0
  497. %type <modcodes> sco
  498. %type <modcodes> amod0
  499. %type <modcodes> amod1
  500. %type <modcodes> amod2
  501. %type <r0> op_bar_op
  502. %type <r0> w32_or_nothing
  503. %type <r0> c_align
  504. %type <r0> min_max
  505. %type <expr> got
  506. %type <expr> got_or_expr
  507. %type <expr> pltpc
  508. %type <value> any_gotrel GOT GOT17M4 FUNCDESC_GOT17M4
  509. /* Precedence rules. */
  510. %left BAR
  511. %left CARET
  512. %left AMPERSAND
  513. %left LESS_LESS GREATER_GREATER
  514. %left PLUS MINUS
  515. %left STAR SLASH PERCENT
  516. %right ASSIGN
  517. %right TILDA BANG
  518. %start statement
  519. %%
  520. statement:
  521. | asm
  522. {
  523. insn = $1;
  524. if (insn == (INSTR_T) 0)
  525. return NO_INSN_GENERATED;
  526. else if (insn == (INSTR_T) - 1)
  527. return SEMANTIC_ERROR;
  528. else
  529. return INSN_GENERATED;
  530. }
  531. ;
  532. asm: asm_1 SEMICOLON
  533. /* Parallel instructions. */
  534. | asm_1 DOUBLE_BAR asm_1 DOUBLE_BAR asm_1 SEMICOLON
  535. {
  536. if (($1->value & 0xf800) == 0xc000)
  537. {
  538. if (is_group1 ($3) && is_group2 ($5))
  539. $$ = gen_multi_instr_1 ($1, $3, $5);
  540. else if (is_group2 ($3) && is_group1 ($5))
  541. $$ = gen_multi_instr_1 ($1, $5, $3);
  542. else
  543. return yyerror ("Wrong 16 bit instructions groups, slot 2 and slot 3 must be 16-bit instruction group");
  544. }
  545. else if (($3->value & 0xf800) == 0xc000)
  546. {
  547. if (is_group1 ($1) && is_group2 ($5))
  548. $$ = gen_multi_instr_1 ($3, $1, $5);
  549. else if (is_group2 ($1) && is_group1 ($5))
  550. $$ = gen_multi_instr_1 ($3, $5, $1);
  551. else
  552. return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 3 must be 16-bit instruction group");
  553. }
  554. else if (($5->value & 0xf800) == 0xc000)
  555. {
  556. if (is_group1 ($1) && is_group2 ($3))
  557. $$ = gen_multi_instr_1 ($5, $1, $3);
  558. else if (is_group2 ($1) && is_group1 ($3))
  559. $$ = gen_multi_instr_1 ($5, $3, $1);
  560. else
  561. return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be 16-bit instruction group");
  562. }
  563. else
  564. error ("\nIllegal Multi Issue Construct, at least any one of the slot must be DSP32 instruction group\n");
  565. }
  566. | asm_1 DOUBLE_BAR asm_1 SEMICOLON
  567. {
  568. if (($1->value & 0xf800) == 0xc000)
  569. {
  570. if (is_group1 ($3))
  571. $$ = gen_multi_instr_1 ($1, $3, 0);
  572. else if (is_group2 ($3))
  573. $$ = gen_multi_instr_1 ($1, 0, $3);
  574. else
  575. return yyerror ("Wrong 16 bit instructions groups, slot 2 must be the 16-bit instruction group");
  576. }
  577. else if (($3->value & 0xf800) == 0xc000)
  578. {
  579. if (is_group1 ($1))
  580. $$ = gen_multi_instr_1 ($3, $1, 0);
  581. else if (is_group2 ($1))
  582. $$ = gen_multi_instr_1 ($3, 0, $1);
  583. else
  584. return yyerror ("Wrong 16 bit instructions groups, slot 1 must be the 16-bit instruction group");
  585. }
  586. else if (is_group1 ($1) && is_group2 ($3))
  587. $$ = gen_multi_instr_1 (0, $1, $3);
  588. else if (is_group2 ($1) && is_group1 ($3))
  589. $$ = gen_multi_instr_1 (0, $3, $1);
  590. else
  591. return yyerror ("Wrong 16 bit instructions groups, slot 1 and slot 2 must be the 16-bit instruction group");
  592. }
  593. | error
  594. {
  595. $$ = 0;
  596. yyerror ("");
  597. yyerrok;
  598. }
  599. ;
  600. /* DSPMAC. */
  601. asm_1:
  602. MNOP
  603. {
  604. $$ = DSP32MAC (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
  605. }
  606. | assign_macfunc opt_mode
  607. {
  608. int op0, op1;
  609. int w0 = 0, w1 = 0;
  610. int h00, h10, h01, h11;
  611. if (check_macfunc_option (&$1, &$2) < 0)
  612. return yyerror ("bad option");
  613. if ($1.n == 0)
  614. {
  615. if ($2.MM)
  616. return yyerror ("(m) not allowed with a0 unit");
  617. op1 = 3;
  618. op0 = $1.op;
  619. w1 = 0;
  620. w0 = $1.w;
  621. h00 = IS_H ($1.s0);
  622. h10 = IS_H ($1.s1);
  623. h01 = h11 = 0;
  624. }
  625. else
  626. {
  627. op1 = $1.op;
  628. op0 = 3;
  629. w1 = $1.w;
  630. w0 = 0;
  631. h00 = h10 = 0;
  632. h01 = IS_H ($1.s0);
  633. h11 = IS_H ($1.s1);
  634. }
  635. $$ = DSP32MAC (op1, $2.MM, $2.mod, w1, $1.P, h01, h11, h00, h10,
  636. &$1.dst, op0, &$1.s0, &$1.s1, w0);
  637. }
  638. /* VECTOR MACs. */
  639. | assign_macfunc opt_mode COMMA assign_macfunc opt_mode
  640. {
  641. Register *dst;
  642. if (check_macfuncs (&$1, &$2, &$4, &$5) < 0)
  643. return -1;
  644. notethat ("assign_macfunc (.), assign_macfunc (.)\n");
  645. if ($1.w)
  646. dst = &$1.dst;
  647. else
  648. dst = &$4.dst;
  649. $$ = DSP32MAC ($1.op, $2.MM, $5.mod, $1.w, $1.P,
  650. IS_H ($1.s0), IS_H ($1.s1), IS_H ($4.s0), IS_H ($4.s1),
  651. dst, $4.op, &$1.s0, &$1.s1, $4.w);
  652. }
  653. /* DSPALU. */
  654. | DISALGNEXCPT
  655. {
  656. notethat ("dsp32alu: DISALGNEXCPT\n");
  657. $$ = DSP32ALU (18, 0, 0, 0, 0, 0, 0, 0, 3);
  658. }
  659. | REG ASSIGN LPAREN a_plusassign REG_A RPAREN
  660. {
  661. if (IS_DREG ($1) && !IS_A1 ($4) && IS_A1 ($5))
  662. {
  663. notethat ("dsp32alu: dregs = ( A0 += A1 )\n");
  664. $$ = DSP32ALU (11, 0, 0, &$1, &reg7, &reg7, 0, 0, 0);
  665. }
  666. else
  667. return yyerror ("Register mismatch");
  668. }
  669. | HALF_REG ASSIGN LPAREN a_plusassign REG_A RPAREN
  670. {
  671. if (!IS_A1 ($4) && IS_A1 ($5))
  672. {
  673. notethat ("dsp32alu: dregs_half = ( A0 += A1 )\n");
  674. $$ = DSP32ALU (11, IS_H ($1), 0, &$1, &reg7, &reg7, 0, 0, 1);
  675. }
  676. else
  677. return yyerror ("Register mismatch");
  678. }
  679. | A_ZERO_DOT_H ASSIGN HALF_REG
  680. {
  681. notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
  682. $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
  683. }
  684. | A_ONE_DOT_H ASSIGN HALF_REG
  685. {
  686. notethat ("dsp32alu: A_ZERO_DOT_H = dregs_hi\n");
  687. $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
  688. }
  689. | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16P LPAREN REG
  690. COLON expr COMMA REG COLON expr RPAREN aligndir
  691. {
  692. if (!IS_DREG ($2) || !IS_DREG ($4))
  693. return yyerror ("Dregs expected");
  694. else if (REG_SAME ($2, $4))
  695. return yyerror ("Illegal dest register combination");
  696. else if (!valid_dreg_pair (&$9, $11))
  697. return yyerror ("Bad dreg pair");
  698. else if (!valid_dreg_pair (&$13, $15))
  699. return yyerror ("Bad dreg pair");
  700. else
  701. {
  702. notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16P (dregs_pair , dregs_pair ) (aligndir)\n");
  703. $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 0);
  704. }
  705. }
  706. | LPAREN REG COMMA REG RPAREN ASSIGN BYTEOP16M LPAREN REG COLON expr COMMA
  707. REG COLON expr RPAREN aligndir
  708. {
  709. if (!IS_DREG ($2) || !IS_DREG ($4))
  710. return yyerror ("Dregs expected");
  711. else if (REG_SAME ($2, $4))
  712. return yyerror ("Illegal dest register combination");
  713. else if (!valid_dreg_pair (&$9, $11))
  714. return yyerror ("Bad dreg pair");
  715. else if (!valid_dreg_pair (&$13, $15))
  716. return yyerror ("Bad dreg pair");
  717. else
  718. {
  719. notethat ("dsp32alu: (dregs , dregs ) = BYTEOP16M (dregs_pair , dregs_pair ) (aligndir)\n");
  720. $$ = DSP32ALU (21, 0, &$2, &$4, &$9, &$13, $17.r0, 0, 1);
  721. }
  722. }
  723. | LPAREN REG COMMA REG RPAREN ASSIGN BYTEUNPACK REG COLON expr aligndir
  724. {
  725. if (!IS_DREG ($2) || !IS_DREG ($4))
  726. return yyerror ("Dregs expected");
  727. else if (REG_SAME ($2, $4))
  728. return yyerror ("Illegal dest register combination");
  729. else if (!valid_dreg_pair (&$8, $10))
  730. return yyerror ("Bad dreg pair");
  731. else
  732. {
  733. notethat ("dsp32alu: (dregs , dregs ) = BYTEUNPACK dregs_pair (aligndir)\n");
  734. $$ = DSP32ALU (24, 0, &$2, &$4, &$8, 0, $11.r0, 0, 1);
  735. }
  736. }
  737. | LPAREN REG COMMA REG RPAREN ASSIGN SEARCH REG LPAREN searchmod RPAREN
  738. {
  739. if (REG_SAME ($2, $4))
  740. return yyerror ("Illegal dest register combination");
  741. if (IS_DREG ($2) && IS_DREG ($4) && IS_DREG ($8))
  742. {
  743. notethat ("dsp32alu: (dregs , dregs ) = SEARCH dregs (searchmod)\n");
  744. $$ = DSP32ALU (13, 0, &$2, &$4, &$8, 0, 0, 0, $10.r0);
  745. }
  746. else
  747. return yyerror ("Register mismatch");
  748. }
  749. | REG ASSIGN A_ONE_DOT_L PLUS A_ONE_DOT_H COMMA
  750. REG ASSIGN A_ZERO_DOT_L PLUS A_ZERO_DOT_H
  751. {
  752. if (REG_SAME ($1, $7))
  753. return yyerror ("Illegal dest register combination");
  754. if (IS_DREG ($1) && IS_DREG ($7))
  755. {
  756. notethat ("dsp32alu: dregs = A1.l + A1.h, dregs = A0.l + A0.h \n");
  757. $$ = DSP32ALU (12, 0, &$1, &$7, &reg7, &reg7, 0, 0, 1);
  758. }
  759. else
  760. return yyerror ("Register mismatch");
  761. }
  762. | REG ASSIGN REG_A PLUS REG_A COMMA REG ASSIGN REG_A MINUS REG_A amod1
  763. {
  764. if (REG_SAME ($1, $7))
  765. return yyerror ("Resource conflict in dest reg");
  766. if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
  767. && IS_A1 ($9) && !IS_A1 ($11))
  768. {
  769. notethat ("dsp32alu: dregs = A1 + A0 , dregs = A1 - A0 (amod1)\n");
  770. $$ = DSP32ALU (17, 0, &$1, &$7, &reg7, &reg7, $12.s0, $12.x0, 0);
  771. }
  772. else if (IS_DREG ($1) && IS_DREG ($7) && !REG_SAME ($3, $5)
  773. && !IS_A1 ($9) && IS_A1 ($11))
  774. {
  775. notethat ("dsp32alu: dregs = A0 + A1 , dregs = A0 - A1 (amod1)\n");
  776. $$ = DSP32ALU (17, 0, &$1, &$7, &reg7, &reg7, $12.s0, $12.x0, 1);
  777. }
  778. else
  779. return yyerror ("Register mismatch");
  780. }
  781. | REG ASSIGN REG plus_minus REG COMMA REG ASSIGN REG plus_minus REG amod1
  782. {
  783. if ($4.r0 == $10.r0)
  784. return yyerror ("Operators must differ");
  785. if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5)
  786. && REG_SAME ($3, $9) && REG_SAME ($5, $11))
  787. {
  788. notethat ("dsp32alu: dregs = dregs + dregs,"
  789. "dregs = dregs - dregs (amod1)\n");
  790. $$ = DSP32ALU (4, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, 2);
  791. }
  792. else
  793. return yyerror ("Register mismatch");
  794. }
  795. /* Bar Operations. */
  796. | REG ASSIGN REG op_bar_op REG COMMA REG ASSIGN REG op_bar_op REG amod2
  797. {
  798. if (!REG_SAME ($3, $9) || !REG_SAME ($5, $11))
  799. return yyerror ("Differing source registers");
  800. if (!IS_DREG ($1) || !IS_DREG ($3) || !IS_DREG ($5) || !IS_DREG ($7))
  801. return yyerror ("Dregs expected");
  802. if (REG_SAME ($1, $7))
  803. return yyerror ("Resource conflict in dest reg");
  804. if ($4.r0 == 1 && $10.r0 == 2)
  805. {
  806. notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
  807. $$ = DSP32ALU (1, 1, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
  808. }
  809. else if ($4.r0 == 0 && $10.r0 == 3)
  810. {
  811. notethat ("dsp32alu: dregs = dregs .|. dregs , dregs = dregs .|. dregs (amod2)\n");
  812. $$ = DSP32ALU (1, 0, &$1, &$7, &$3, &$5, $12.s0, $12.x0, $12.r0);
  813. }
  814. else
  815. return yyerror ("Bar operand mismatch");
  816. }
  817. | REG ASSIGN ABS REG vmod
  818. {
  819. int op;
  820. if (IS_DREG ($1) && IS_DREG ($4))
  821. {
  822. if ($5.r0)
  823. {
  824. notethat ("dsp32alu: dregs = ABS dregs (v)\n");
  825. op = 6;
  826. }
  827. else
  828. {
  829. /* Vector version of ABS. */
  830. notethat ("dsp32alu: dregs = ABS dregs\n");
  831. op = 7;
  832. }
  833. $$ = DSP32ALU (op, 0, 0, &$1, &$4, 0, 0, 0, 2);
  834. }
  835. else
  836. return yyerror ("Dregs expected");
  837. }
  838. | a_assign ABS REG_A
  839. {
  840. notethat ("dsp32alu: Ax = ABS Ax\n");
  841. $$ = DSP32ALU (16, IS_A1 ($1), 0, 0, &reg7, &reg7, 0, 0, IS_A1 ($3));
  842. }
  843. | A_ZERO_DOT_L ASSIGN HALF_REG
  844. {
  845. if (IS_DREG_L ($3))
  846. {
  847. notethat ("dsp32alu: A0.l = reg_half\n");
  848. $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 0);
  849. }
  850. else
  851. return yyerror ("A0.l = Rx.l expected");
  852. }
  853. | A_ONE_DOT_L ASSIGN HALF_REG
  854. {
  855. if (IS_DREG_L ($3))
  856. {
  857. notethat ("dsp32alu: A1.l = reg_half\n");
  858. $$ = DSP32ALU (9, IS_H ($3), 0, 0, &$3, 0, 0, 0, 2);
  859. }
  860. else
  861. return yyerror ("A1.l = Rx.l expected");
  862. }
  863. | REG ASSIGN c_align LPAREN REG COMMA REG RPAREN
  864. {
  865. if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
  866. {
  867. notethat ("dsp32shift: dregs = ALIGN8 (dregs , dregs )\n");
  868. $$ = DSP32SHIFT (13, &$1, &$7, &$5, $3.r0, 0);
  869. }
  870. else
  871. return yyerror ("Dregs expected");
  872. }
  873. | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN byteop_mod
  874. {
  875. if (!IS_DREG ($1))
  876. return yyerror ("Dregs expected");
  877. else if (!valid_dreg_pair (&$5, $7))
  878. return yyerror ("Bad dreg pair");
  879. else if (!valid_dreg_pair (&$9, $11))
  880. return yyerror ("Bad dreg pair");
  881. else
  882. {
  883. notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
  884. $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, $13.s0, 0, $13.r0);
  885. }
  886. }
  887. | REG ASSIGN BYTEOP1P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
  888. {
  889. if (!IS_DREG ($1))
  890. return yyerror ("Dregs expected");
  891. else if (!valid_dreg_pair (&$5, $7))
  892. return yyerror ("Bad dreg pair");
  893. else if (!valid_dreg_pair (&$9, $11))
  894. return yyerror ("Bad dreg pair");
  895. else
  896. {
  897. notethat ("dsp32alu: dregs = BYTEOP1P (dregs_pair , dregs_pair ) (T)\n");
  898. $$ = DSP32ALU (20, 0, 0, &$1, &$5, &$9, 0, 0, 0);
  899. }
  900. }
  901. | REG ASSIGN BYTEOP2P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
  902. rnd_op
  903. {
  904. if (!IS_DREG ($1))
  905. return yyerror ("Dregs expected");
  906. else if (!valid_dreg_pair (&$5, $7))
  907. return yyerror ("Bad dreg pair");
  908. else if (!valid_dreg_pair (&$9, $11))
  909. return yyerror ("Bad dreg pair");
  910. else
  911. {
  912. notethat ("dsp32alu: dregs = BYTEOP2P (dregs_pair , dregs_pair ) (rnd_op)\n");
  913. $$ = DSP32ALU (22, $13.r0, 0, &$1, &$5, &$9, $13.s0, $13.x0, $13.aop);
  914. }
  915. }
  916. | REG ASSIGN BYTEOP3P LPAREN REG COLON expr COMMA REG COLON expr RPAREN
  917. b3_op
  918. {
  919. if (!IS_DREG ($1))
  920. return yyerror ("Dregs expected");
  921. else if (!valid_dreg_pair (&$5, $7))
  922. return yyerror ("Bad dreg pair");
  923. else if (!valid_dreg_pair (&$9, $11))
  924. return yyerror ("Bad dreg pair");
  925. else
  926. {
  927. notethat ("dsp32alu: dregs = BYTEOP3P (dregs_pair , dregs_pair ) (b3_op)\n");
  928. $$ = DSP32ALU (23, $13.x0, 0, &$1, &$5, &$9, $13.s0, 0, 0);
  929. }
  930. }
  931. | REG ASSIGN BYTEPACK LPAREN REG COMMA REG RPAREN
  932. {
  933. if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
  934. {
  935. notethat ("dsp32alu: dregs = BYTEPACK (dregs , dregs )\n");
  936. $$ = DSP32ALU (24, 0, 0, &$1, &$5, &$7, 0, 0, 0);
  937. }
  938. else
  939. return yyerror ("Dregs expected");
  940. }
  941. | HALF_REG ASSIGN HALF_REG ASSIGN SIGN LPAREN HALF_REG RPAREN STAR
  942. HALF_REG PLUS SIGN LPAREN HALF_REG RPAREN STAR HALF_REG
  943. {
  944. if (IS_HCOMPL ($1, $3) && IS_HCOMPL ($7, $14) && IS_HCOMPL ($10, $17))
  945. {
  946. notethat ("dsp32alu: dregs_hi = dregs_lo ="
  947. "SIGN (dregs_hi) * dregs_hi + "
  948. "SIGN (dregs_lo) * dregs_lo \n");
  949. $$ = DSP32ALU (12, 0, 0, &$1, &$7, &$10, 0, 0, 0);
  950. }
  951. else
  952. return yyerror ("Dregs expected");
  953. }
  954. | REG ASSIGN REG plus_minus REG amod1
  955. {
  956. if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
  957. {
  958. if ($6.aop == 0)
  959. {
  960. /* No saturation flag specified, generate the 16 bit variant. */
  961. notethat ("COMP3op: dregs = dregs +- dregs\n");
  962. $$ = COMP3OP (&$1, &$3, &$5, $4.r0);
  963. }
  964. else
  965. {
  966. /* Saturation flag specified, generate the 32 bit variant. */
  967. notethat ("dsp32alu: dregs = dregs +- dregs (amod1)\n");
  968. $$ = DSP32ALU (4, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
  969. }
  970. }
  971. else
  972. if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($5) && $4.r0 == 0)
  973. {
  974. notethat ("COMP3op: pregs = pregs + pregs\n");
  975. $$ = COMP3OP (&$1, &$3, &$5, 5);
  976. }
  977. else
  978. return yyerror ("Dregs expected");
  979. }
  980. | REG ASSIGN min_max LPAREN REG COMMA REG RPAREN vmod
  981. {
  982. int op;
  983. if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
  984. {
  985. if ($9.r0)
  986. op = 6;
  987. else
  988. op = 7;
  989. notethat ("dsp32alu: dregs = {MIN|MAX} (dregs, dregs)\n");
  990. $$ = DSP32ALU (op, 0, 0, &$1, &$5, &$7, 0, 0, $3.r0);
  991. }
  992. else
  993. return yyerror ("Dregs expected");
  994. }
  995. | a_assign MINUS REG_A
  996. {
  997. notethat ("dsp32alu: Ax = - Ax\n");
  998. $$ = DSP32ALU (14, IS_A1 ($1), 0, 0, &reg7, &reg7, 0, 0, IS_A1 ($3));
  999. }
  1000. | HALF_REG ASSIGN HALF_REG plus_minus HALF_REG amod1
  1001. {
  1002. notethat ("dsp32alu: dregs_lo = dregs_lo +- dregs_lo (amod1)\n");
  1003. $$ = DSP32ALU (2 | $4.r0, IS_H ($1), 0, &$1, &$3, &$5,
  1004. $6.s0, $6.x0, HL2 ($3, $5));
  1005. }
  1006. | a_assign a_assign expr
  1007. {
  1008. if (EXPR_VALUE ($3) == 0 && !REG_SAME ($1, $2))
  1009. {
  1010. notethat ("dsp32alu: A1 = A0 = 0\n");
  1011. $$ = DSP32ALU (8, 0, 0, 0, &reg7, &reg7, 0, 0, 2);
  1012. }
  1013. else
  1014. return yyerror ("Bad value, 0 expected");
  1015. }
  1016. /* Saturating. */
  1017. | a_assign REG_A LPAREN S RPAREN
  1018. {
  1019. if (REG_SAME ($1, $2))
  1020. {
  1021. notethat ("dsp32alu: Ax = Ax (S)\n");
  1022. $$ = DSP32ALU (8, 0, 0, 0, &reg7, &reg7, 1, 0, IS_A1 ($1));
  1023. }
  1024. else
  1025. return yyerror ("Registers must be equal");
  1026. }
  1027. | HALF_REG ASSIGN REG LPAREN RND RPAREN
  1028. {
  1029. if (IS_DREG ($3))
  1030. {
  1031. notethat ("dsp32alu: dregs_half = dregs (RND)\n");
  1032. $$ = DSP32ALU (12, IS_H ($1), 0, &$1, &$3, 0, 0, 0, 3);
  1033. }
  1034. else
  1035. return yyerror ("Dregs expected");
  1036. }
  1037. | HALF_REG ASSIGN REG plus_minus REG LPAREN RND12 RPAREN
  1038. {
  1039. if (IS_DREG ($3) && IS_DREG ($5))
  1040. {
  1041. notethat ("dsp32alu: dregs_half = dregs (+-) dregs (RND12)\n");
  1042. $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 0, $4.r0);
  1043. }
  1044. else
  1045. return yyerror ("Dregs expected");
  1046. }
  1047. | HALF_REG ASSIGN REG plus_minus REG LPAREN RND20 RPAREN
  1048. {
  1049. if (IS_DREG ($3) && IS_DREG ($5))
  1050. {
  1051. notethat ("dsp32alu: dregs_half = dregs -+ dregs (RND20)\n");
  1052. $$ = DSP32ALU (5, IS_H ($1), 0, &$1, &$3, &$5, 0, 1, $4.r0 | 2);
  1053. }
  1054. else
  1055. return yyerror ("Dregs expected");
  1056. }
  1057. | a_assign REG_A
  1058. {
  1059. if (!REG_SAME ($1, $2))
  1060. {
  1061. notethat ("dsp32alu: An = Am\n");
  1062. $$ = DSP32ALU (8, 0, 0, 0, &reg7, &reg7, IS_A1 ($1), 0, 3);
  1063. }
  1064. else
  1065. return yyerror ("Accu reg arguments must differ");
  1066. }
  1067. | a_assign REG
  1068. {
  1069. if (IS_DREG ($2))
  1070. {
  1071. notethat ("dsp32alu: An = dregs\n");
  1072. $$ = DSP32ALU (9, 0, 0, 0, &$2, 0, 1, 0, IS_A1 ($1) << 1);
  1073. }
  1074. else
  1075. return yyerror ("Dregs expected");
  1076. }
  1077. | REG ASSIGN HALF_REG xpmod
  1078. {
  1079. if (!IS_H ($3))
  1080. {
  1081. if ($1.regno == REG_A0x && IS_DREG ($3))
  1082. {
  1083. notethat ("dsp32alu: A0.x = dregs_lo\n");
  1084. $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 1);
  1085. }
  1086. else if ($1.regno == REG_A1x && IS_DREG ($3))
  1087. {
  1088. notethat ("dsp32alu: A1.x = dregs_lo\n");
  1089. $$ = DSP32ALU (9, 0, 0, 0, &$3, 0, 0, 0, 3);
  1090. }
  1091. else if (IS_DREG ($1) && IS_DREG ($3))
  1092. {
  1093. notethat ("ALU2op: dregs = dregs_lo\n");
  1094. $$ = ALU2OP (&$1, &$3, 10 | ($4.r0 ? 0: 1));
  1095. }
  1096. else
  1097. return yyerror ("Register mismatch");
  1098. }
  1099. else
  1100. return yyerror ("Low reg expected");
  1101. }
  1102. | HALF_REG ASSIGN expr
  1103. {
  1104. notethat ("LDIMMhalf: pregs_half = imm16\n");
  1105. if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
  1106. && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
  1107. return yyerror ("Wrong register for load immediate");
  1108. if (!IS_IMM ($3, 16) && !IS_UIMM ($3, 16))
  1109. return yyerror ("Constant out of range");
  1110. $$ = LDIMMHALF_R (&$1, IS_H ($1), 0, 0, $3);
  1111. }
  1112. | a_assign expr
  1113. {
  1114. notethat ("dsp32alu: An = 0\n");
  1115. if (imm7 ($2) != 0)
  1116. return yyerror ("0 expected");
  1117. $$ = DSP32ALU (8, 0, 0, 0, 0, 0, 0, 0, IS_A1 ($1));
  1118. }
  1119. | REG ASSIGN expr xpmod1
  1120. {
  1121. if (!IS_DREG ($1) && !IS_PREG ($1) && !IS_IREG ($1)
  1122. && !IS_MREG ($1) && !IS_BREG ($1) && !IS_LREG ($1))
  1123. return yyerror ("Wrong register for load immediate");
  1124. if ($4.r0 == 0)
  1125. {
  1126. /* 7 bit immediate value if possible.
  1127. We will check for that constant value for efficiency
  1128. If it goes to reloc, it will be 16 bit. */
  1129. if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_DREG ($1))
  1130. {
  1131. notethat ("COMPI2opD: dregs = imm7 (x) \n");
  1132. $$ = COMPI2OPD (&$1, imm7 ($3), 0);
  1133. }
  1134. else if (IS_CONST ($3) && IS_IMM ($3, 7) && IS_PREG ($1))
  1135. {
  1136. notethat ("COMPI2opP: pregs = imm7 (x)\n");
  1137. $$ = COMPI2OPP (&$1, imm7 ($3), 0);
  1138. }
  1139. else
  1140. {
  1141. if (IS_CONST ($3) && !IS_IMM ($3, 16))
  1142. return yyerror ("Immediate value out of range");
  1143. notethat ("LDIMMhalf: regs = luimm16 (x)\n");
  1144. /* reg, H, S, Z. */
  1145. $$ = LDIMMHALF_R5 (&$1, 0, 1, 0, $3);
  1146. }
  1147. }
  1148. else
  1149. {
  1150. /* (z) There is no 7 bit zero extended instruction.
  1151. If the expr is a relocation, generate it. */
  1152. if (IS_CONST ($3) && !IS_UIMM ($3, 16))
  1153. return yyerror ("Immediate value out of range");
  1154. notethat ("LDIMMhalf: regs = luimm16 (x)\n");
  1155. /* reg, H, S, Z. */
  1156. $$ = LDIMMHALF_R5 (&$1, 0, 0, 1, $3);
  1157. }
  1158. }
  1159. | HALF_REG ASSIGN REG
  1160. {
  1161. if (IS_H ($1))
  1162. return yyerror ("Low reg expected");
  1163. if (IS_DREG ($1) && $3.regno == REG_A0x)
  1164. {
  1165. notethat ("dsp32alu: dregs_lo = A0.x\n");
  1166. $$ = DSP32ALU (10, 0, 0, &$1, &reg7, &reg7, 0, 0, 0);
  1167. }
  1168. else if (IS_DREG ($1) && $3.regno == REG_A1x)
  1169. {
  1170. notethat ("dsp32alu: dregs_lo = A1.x\n");
  1171. $$ = DSP32ALU (10, 0, 0, &$1, &reg7, &reg7, 0, 0, 1);
  1172. }
  1173. else
  1174. return yyerror ("Register mismatch");
  1175. }
  1176. | REG ASSIGN REG op_bar_op REG amod0
  1177. {
  1178. if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
  1179. {
  1180. notethat ("dsp32alu: dregs = dregs .|. dregs (amod0)\n");
  1181. $$ = DSP32ALU (0, 0, 0, &$1, &$3, &$5, $6.s0, $6.x0, $4.r0);
  1182. }
  1183. else
  1184. return yyerror ("Register mismatch");
  1185. }
  1186. | REG ASSIGN BYTE_DREG xpmod
  1187. {
  1188. if (IS_DREG ($1) && IS_DREG ($3))
  1189. {
  1190. notethat ("ALU2op: dregs = dregs_byte\n");
  1191. $$ = ALU2OP (&$1, &$3, 12 | ($4.r0 ? 0: 1));
  1192. }
  1193. else
  1194. return yyerror ("Register mismatch");
  1195. }
  1196. | a_assign ABS REG_A COMMA a_assign ABS REG_A
  1197. {
  1198. if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
  1199. {
  1200. notethat ("dsp32alu: A1 = ABS A1 , A0 = ABS A0\n");
  1201. $$ = DSP32ALU (16, 0, 0, 0, &reg7, &reg7, 0, 0, 3);
  1202. }
  1203. else
  1204. return yyerror ("Register mismatch");
  1205. }
  1206. | a_assign MINUS REG_A COMMA a_assign MINUS REG_A
  1207. {
  1208. if (REG_SAME ($1, $3) && REG_SAME ($5, $7) && !REG_SAME ($1, $5))
  1209. {
  1210. notethat ("dsp32alu: A1 = - A1 , A0 = - A0\n");
  1211. $$ = DSP32ALU (14, 0, 0, 0, &reg7, &reg7, 0, 0, 3);
  1212. }
  1213. else
  1214. return yyerror ("Register mismatch");
  1215. }
  1216. | a_minusassign REG_A w32_or_nothing
  1217. {
  1218. if (!IS_A1 ($1) && IS_A1 ($2))
  1219. {
  1220. notethat ("dsp32alu: A0 -= A1\n");
  1221. $$ = DSP32ALU (11, 0, 0, 0, &reg7, &reg7, $3.r0, 0, 3);
  1222. }
  1223. else
  1224. return yyerror ("Register mismatch");
  1225. }
  1226. | REG _MINUS_ASSIGN expr
  1227. {
  1228. if (IS_IREG ($1) && EXPR_VALUE ($3) == 4)
  1229. {
  1230. notethat ("dagMODik: iregs -= 4\n");
  1231. $$ = DAGMODIK (&$1, 3);
  1232. }
  1233. else if (IS_IREG ($1) && EXPR_VALUE ($3) == 2)
  1234. {
  1235. notethat ("dagMODik: iregs -= 2\n");
  1236. $$ = DAGMODIK (&$1, 1);
  1237. }
  1238. else
  1239. return yyerror ("Register or value mismatch");
  1240. }
  1241. | REG _PLUS_ASSIGN REG LPAREN BREV RPAREN
  1242. {
  1243. if (IS_IREG ($1) && IS_MREG ($3))
  1244. {
  1245. notethat ("dagMODim: iregs += mregs (opt_brev)\n");
  1246. /* i, m, op, br. */
  1247. $$ = DAGMODIM (&$1, &$3, 0, 1);
  1248. }
  1249. else if (IS_PREG ($1) && IS_PREG ($3))
  1250. {
  1251. notethat ("PTR2op: pregs += pregs (BREV )\n");
  1252. $$ = PTR2OP (&$1, &$3, 5);
  1253. }
  1254. else
  1255. return yyerror ("Register mismatch");
  1256. }
  1257. | REG _MINUS_ASSIGN REG
  1258. {
  1259. if (IS_IREG ($1) && IS_MREG ($3))
  1260. {
  1261. notethat ("dagMODim: iregs -= mregs\n");
  1262. $$ = DAGMODIM (&$1, &$3, 1, 0);
  1263. }
  1264. else if (IS_PREG ($1) && IS_PREG ($3))
  1265. {
  1266. notethat ("PTR2op: pregs -= pregs\n");
  1267. $$ = PTR2OP (&$1, &$3, 0);
  1268. }
  1269. else
  1270. return yyerror ("Register mismatch");
  1271. }
  1272. | REG_A _PLUS_ASSIGN REG_A w32_or_nothing
  1273. {
  1274. if (!IS_A1 ($1) && IS_A1 ($3))
  1275. {
  1276. notethat ("dsp32alu: A0 += A1 (W32)\n");
  1277. $$ = DSP32ALU (11, 0, 0, 0, &reg7, &reg7, $4.r0, 0, 2);
  1278. }
  1279. else
  1280. return yyerror ("Register mismatch");
  1281. }
  1282. | REG _PLUS_ASSIGN REG
  1283. {
  1284. if (IS_IREG ($1) && IS_MREG ($3))
  1285. {
  1286. notethat ("dagMODim: iregs += mregs\n");
  1287. $$ = DAGMODIM (&$1, &$3, 0, 0);
  1288. }
  1289. else
  1290. return yyerror ("iregs += mregs expected");
  1291. }
  1292. | REG _PLUS_ASSIGN expr
  1293. {
  1294. if (IS_IREG ($1))
  1295. {
  1296. if (EXPR_VALUE ($3) == 4)
  1297. {
  1298. notethat ("dagMODik: iregs += 4\n");
  1299. $$ = DAGMODIK (&$1, 2);
  1300. }
  1301. else if (EXPR_VALUE ($3) == 2)
  1302. {
  1303. notethat ("dagMODik: iregs += 2\n");
  1304. $$ = DAGMODIK (&$1, 0);
  1305. }
  1306. else
  1307. return yyerror ("iregs += [ 2 | 4 ");
  1308. }
  1309. else if (IS_PREG ($1) && IS_IMM ($3, 7))
  1310. {
  1311. notethat ("COMPI2opP: pregs += imm7\n");
  1312. $$ = COMPI2OPP (&$1, imm7 ($3), 1);
  1313. }
  1314. else if (IS_DREG ($1) && IS_IMM ($3, 7))
  1315. {
  1316. notethat ("COMPI2opD: dregs += imm7\n");
  1317. $$ = COMPI2OPD (&$1, imm7 ($3), 1);
  1318. }
  1319. else if ((IS_DREG ($1) || IS_PREG ($1)) && IS_CONST ($3))
  1320. return yyerror ("Immediate value out of range");
  1321. else
  1322. return yyerror ("Register mismatch");
  1323. }
  1324. | REG _STAR_ASSIGN REG
  1325. {
  1326. if (IS_DREG ($1) && IS_DREG ($3))
  1327. {
  1328. notethat ("ALU2op: dregs *= dregs\n");
  1329. $$ = ALU2OP (&$1, &$3, 3);
  1330. }
  1331. else
  1332. return yyerror ("Register mismatch");
  1333. }
  1334. | SAA LPAREN REG COLON expr COMMA REG COLON expr RPAREN aligndir
  1335. {
  1336. if (!valid_dreg_pair (&$3, $5))
  1337. return yyerror ("Bad dreg pair");
  1338. else if (!valid_dreg_pair (&$7, $9))
  1339. return yyerror ("Bad dreg pair");
  1340. else
  1341. {
  1342. notethat ("dsp32alu: SAA (dregs_pair , dregs_pair ) (aligndir)\n");
  1343. $$ = DSP32ALU (18, 0, 0, 0, &$3, &$7, $11.r0, 0, 0);
  1344. }
  1345. }
  1346. | a_assign REG_A LPAREN S RPAREN COMMA a_assign REG_A LPAREN S RPAREN
  1347. {
  1348. if (REG_SAME ($1, $2) && REG_SAME ($7, $8) && !REG_SAME ($1, $7))
  1349. {
  1350. notethat ("dsp32alu: A1 = A1 (S) , A0 = A0 (S)\n");
  1351. $$ = DSP32ALU (8, 0, 0, 0, &reg7, &reg7, 1, 0, 2);
  1352. }
  1353. else
  1354. return yyerror ("Register mismatch");
  1355. }
  1356. | REG ASSIGN LPAREN REG PLUS REG RPAREN LESS_LESS expr
  1357. {
  1358. if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6)
  1359. && REG_SAME ($1, $4))
  1360. {
  1361. if (EXPR_VALUE ($9) == 1)
  1362. {
  1363. notethat ("ALU2op: dregs = (dregs + dregs) << 1\n");
  1364. $$ = ALU2OP (&$1, &$6, 4);
  1365. }
  1366. else if (EXPR_VALUE ($9) == 2)
  1367. {
  1368. notethat ("ALU2op: dregs = (dregs + dregs) << 2\n");
  1369. $$ = ALU2OP (&$1, &$6, 5);
  1370. }
  1371. else
  1372. return yyerror ("Bad shift value");
  1373. }
  1374. else if (IS_PREG ($1) && IS_PREG ($4) && IS_PREG ($6)
  1375. && REG_SAME ($1, $4))
  1376. {
  1377. if (EXPR_VALUE ($9) == 1)
  1378. {
  1379. notethat ("PTR2op: pregs = (pregs + pregs) << 1\n");
  1380. $$ = PTR2OP (&$1, &$6, 6);
  1381. }
  1382. else if (EXPR_VALUE ($9) == 2)
  1383. {
  1384. notethat ("PTR2op: pregs = (pregs + pregs) << 2\n");
  1385. $$ = PTR2OP (&$1, &$6, 7);
  1386. }
  1387. else
  1388. return yyerror ("Bad shift value");
  1389. }
  1390. else
  1391. return yyerror ("Register mismatch");
  1392. }
  1393. /* COMP3 CCFLAG. */
  1394. | REG ASSIGN REG BAR REG
  1395. {
  1396. if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
  1397. {
  1398. notethat ("COMP3op: dregs = dregs | dregs\n");
  1399. $$ = COMP3OP (&$1, &$3, &$5, 3);
  1400. }
  1401. else
  1402. return yyerror ("Dregs expected");
  1403. }
  1404. | REG ASSIGN REG CARET REG
  1405. {
  1406. if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
  1407. {
  1408. notethat ("COMP3op: dregs = dregs ^ dregs\n");
  1409. $$ = COMP3OP (&$1, &$3, &$5, 4);
  1410. }
  1411. else
  1412. return yyerror ("Dregs expected");
  1413. }
  1414. | REG ASSIGN REG PLUS LPAREN REG LESS_LESS expr RPAREN
  1415. {
  1416. if (IS_PREG ($1) && IS_PREG ($3) && IS_PREG ($6))
  1417. {
  1418. if (EXPR_VALUE ($8) == 1)
  1419. {
  1420. notethat ("COMP3op: pregs = pregs + (pregs << 1)\n");
  1421. $$ = COMP3OP (&$1, &$3, &$6, 6);
  1422. }
  1423. else if (EXPR_VALUE ($8) == 2)
  1424. {
  1425. notethat ("COMP3op: pregs = pregs + (pregs << 2)\n");
  1426. $$ = COMP3OP (&$1, &$3, &$6, 7);
  1427. }
  1428. else
  1429. return yyerror ("Bad shift value");
  1430. }
  1431. else
  1432. return yyerror ("Dregs expected");
  1433. }
  1434. | CCREG ASSIGN REG_A _ASSIGN_ASSIGN REG_A
  1435. {
  1436. if ($3.regno == REG_A0 && $5.regno == REG_A1)
  1437. {
  1438. notethat ("CCflag: CC = A0 == A1\n");
  1439. $$ = CCFLAG (0, 0, 5, 0, 0);
  1440. }
  1441. else
  1442. return yyerror ("AREGs are in bad order or same");
  1443. }
  1444. | CCREG ASSIGN REG_A LESS_THAN REG_A
  1445. {
  1446. if ($3.regno == REG_A0 && $5.regno == REG_A1)
  1447. {
  1448. notethat ("CCflag: CC = A0 < A1\n");
  1449. $$ = CCFLAG (0, 0, 6, 0, 0);
  1450. }
  1451. else
  1452. return yyerror ("AREGs are in bad order or same");
  1453. }
  1454. | CCREG ASSIGN REG LESS_THAN REG iu_or_nothing
  1455. {
  1456. if ((IS_DREG ($3) && IS_DREG ($5))
  1457. || (IS_PREG ($3) && IS_PREG ($5)))
  1458. {
  1459. notethat ("CCflag: CC = dpregs < dpregs\n");
  1460. $$ = CCFLAG (&$3, $5.regno & CODE_MASK, $6.r0, 0, IS_PREG ($3) ? 1 : 0);
  1461. }
  1462. else
  1463. return yyerror ("Bad register in comparison");
  1464. }
  1465. | CCREG ASSIGN REG LESS_THAN expr iu_or_nothing
  1466. {
  1467. if (!IS_DREG ($3) && !IS_PREG ($3))
  1468. return yyerror ("Bad register in comparison");
  1469. if (($6.r0 == 1 && IS_IMM ($5, 3))
  1470. || ($6.r0 == 3 && IS_UIMM ($5, 3)))
  1471. {
  1472. notethat ("CCflag: CC = dpregs < (u)imm3\n");
  1473. $$ = CCFLAG (&$3, imm3 ($5), $6.r0, 1, IS_PREG ($3) ? 1 : 0);
  1474. }
  1475. else
  1476. return yyerror ("Bad constant value");
  1477. }
  1478. | CCREG ASSIGN REG _ASSIGN_ASSIGN REG
  1479. {
  1480. if ((IS_DREG ($3) && IS_DREG ($5))
  1481. || (IS_PREG ($3) && IS_PREG ($5)))
  1482. {
  1483. notethat ("CCflag: CC = dpregs == dpregs\n");
  1484. $$ = CCFLAG (&$3, $5.regno & CODE_MASK, 0, 0, IS_PREG ($3) ? 1 : 0);
  1485. }
  1486. else
  1487. return yyerror ("Bad register in comparison");
  1488. }
  1489. | CCREG ASSIGN REG _ASSIGN_ASSIGN expr
  1490. {
  1491. if (!IS_DREG ($3) && !IS_PREG ($3))
  1492. return yyerror ("Bad register in comparison");
  1493. if (IS_IMM ($5, 3))
  1494. {
  1495. notethat ("CCflag: CC = dpregs == imm3\n");
  1496. $$ = CCFLAG (&$3, imm3 ($5), 0, 1, IS_PREG ($3) ? 1 : 0);
  1497. }
  1498. else
  1499. return yyerror ("Bad constant range");
  1500. }
  1501. | CCREG ASSIGN REG_A _LESS_THAN_ASSIGN REG_A
  1502. {
  1503. if ($3.regno == REG_A0 && $5.regno == REG_A1)
  1504. {
  1505. notethat ("CCflag: CC = A0 <= A1\n");
  1506. $$ = CCFLAG (0, 0, 7, 0, 0);
  1507. }
  1508. else
  1509. return yyerror ("AREGs are in bad order or same");
  1510. }
  1511. | CCREG ASSIGN REG _LESS_THAN_ASSIGN REG iu_or_nothing
  1512. {
  1513. if ((IS_DREG ($3) && IS_DREG ($5))
  1514. || (IS_PREG ($3) && IS_PREG ($5)))
  1515. {
  1516. notethat ("CCflag: CC = dpregs <= dpregs (..)\n");
  1517. $$ = CCFLAG (&$3, $5.regno & CODE_MASK,
  1518. 1 + $6.r0, 0, IS_PREG ($3) ? 1 : 0);
  1519. }
  1520. else
  1521. return yyerror ("Bad register in comparison");
  1522. }
  1523. | CCREG ASSIGN REG _LESS_THAN_ASSIGN expr iu_or_nothing
  1524. {
  1525. if (!IS_DREG ($3) && !IS_PREG ($3))
  1526. return yyerror ("Bad register in comparison");
  1527. if (($6.r0 == 1 && IS_IMM ($5, 3))
  1528. || ($6.r0 == 3 && IS_UIMM ($5, 3)))
  1529. {
  1530. notethat ("CCflag: CC = dpregs <= (u)imm3\n");
  1531. $$ = CCFLAG (&$3, imm3 ($5), 1 + $6.r0, 1, IS_PREG ($3) ? 1 : 0);
  1532. }
  1533. else
  1534. return yyerror ("Bad constant value");
  1535. }
  1536. | REG ASSIGN REG AMPERSAND REG
  1537. {
  1538. if (IS_DREG ($1) && IS_DREG ($3) && IS_DREG ($5))
  1539. {
  1540. notethat ("COMP3op: dregs = dregs & dregs\n");
  1541. $$ = COMP3OP (&$1, &$3, &$5, 2);
  1542. }
  1543. else
  1544. return yyerror ("Dregs expected");
  1545. }
  1546. | ccstat
  1547. {
  1548. notethat ("CC2stat operation\n");
  1549. $$ = bfin_gen_cc2stat ($1.r0, $1.x0, $1.s0);
  1550. }
  1551. | REG ASSIGN REG
  1552. {
  1553. if ((IS_GENREG ($1) && IS_GENREG ($3))
  1554. || (IS_GENREG ($1) && IS_DAGREG ($3))
  1555. || (IS_DAGREG ($1) && IS_GENREG ($3))
  1556. || (IS_DAGREG ($1) && IS_DAGREG ($3))
  1557. || (IS_GENREG ($1) && $3.regno == REG_USP)
  1558. || ($1.regno == REG_USP && IS_GENREG ($3))
  1559. || ($1.regno == REG_USP && $3.regno == REG_USP)
  1560. || (IS_DREG ($1) && IS_SYSREG ($3))
  1561. || (IS_PREG ($1) && IS_SYSREG ($3))
  1562. || (IS_SYSREG ($1) && IS_GENREG ($3))
  1563. || (IS_ALLREG ($1) && IS_EMUDAT ($3))
  1564. || (IS_EMUDAT ($1) && IS_ALLREG ($3))
  1565. || (IS_SYSREG ($1) && $3.regno == REG_USP))
  1566. {
  1567. $$ = bfin_gen_regmv (&$3, &$1);
  1568. }
  1569. else
  1570. return yyerror ("Unsupported register move");
  1571. }
  1572. | CCREG ASSIGN REG
  1573. {
  1574. if (IS_DREG ($3))
  1575. {
  1576. notethat ("CC2dreg: CC = dregs\n");
  1577. $$ = bfin_gen_cc2dreg (1, &$3);
  1578. }
  1579. else
  1580. return yyerror ("Only 'CC = Dreg' supported");
  1581. }
  1582. | REG ASSIGN CCREG
  1583. {
  1584. if (IS_DREG ($1))
  1585. {
  1586. notethat ("CC2dreg: dregs = CC\n");
  1587. $$ = bfin_gen_cc2dreg (0, &$1);
  1588. }
  1589. else
  1590. return yyerror ("Only 'Dreg = CC' supported");
  1591. }
  1592. | CCREG _ASSIGN_BANG CCREG
  1593. {
  1594. notethat ("CC2dreg: CC =! CC\n");
  1595. $$ = bfin_gen_cc2dreg (3, 0);
  1596. }
  1597. /* DSPMULT. */
  1598. | HALF_REG ASSIGN multiply_halfregs opt_mode
  1599. {
  1600. notethat ("dsp32mult: dregs_half = multiply_halfregs (opt_mode)\n");
  1601. if (!IS_H ($1) && $4.MM)
  1602. return yyerror ("(M) not allowed with MAC0");
  1603. if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
  1604. && $4.mod != M_IU && $4.mod != M_T && $4.mod != M_TFU
  1605. && $4.mod != M_S2RND && $4.mod != M_ISS2 && $4.mod != M_IH)
  1606. return yyerror ("bad option.");
  1607. if (IS_H ($1))
  1608. {
  1609. $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 0,
  1610. IS_H ($3.s0), IS_H ($3.s1), 0, 0,
  1611. &$1, 0, &$3.s0, &$3.s1, 0);
  1612. }
  1613. else
  1614. {
  1615. $$ = DSP32MULT (0, 0, $4.mod, 0, 0,
  1616. 0, 0, IS_H ($3.s0), IS_H ($3.s1),
  1617. &$1, 0, &$3.s0, &$3.s1, 1);
  1618. }
  1619. }
  1620. | REG ASSIGN multiply_halfregs opt_mode
  1621. {
  1622. /* Odd registers can use (M). */
  1623. if (!IS_DREG ($1))
  1624. return yyerror ("Dreg expected");
  1625. if (IS_EVEN ($1) && $4.MM)
  1626. return yyerror ("(M) not allowed with MAC0");
  1627. if ($4.mod != 0 && $4.mod != M_FU && $4.mod != M_IS
  1628. && $4.mod != M_S2RND && $4.mod != M_ISS2)
  1629. return yyerror ("bad option");
  1630. if (!IS_EVEN ($1))
  1631. {
  1632. notethat ("dsp32mult: dregs = multiply_halfregs (opt_mode)\n");
  1633. $$ = DSP32MULT (0, $4.MM, $4.mod, 1, 1,
  1634. IS_H ($3.s0), IS_H ($3.s1), 0, 0,
  1635. &$1, 0, &$3.s0, &$3.s1, 0);
  1636. }
  1637. else
  1638. {
  1639. notethat ("dsp32mult: dregs = multiply_halfregs opt_mode\n");
  1640. $$ = DSP32MULT (0, 0, $4.mod, 0, 1,
  1641. 0, 0, IS_H ($3.s0), IS_H ($3.s1),
  1642. &$1, 0, &$3.s0, &$3.s1, 1);
  1643. }
  1644. }
  1645. | HALF_REG ASSIGN multiply_halfregs opt_mode COMMA
  1646. HALF_REG ASSIGN multiply_halfregs opt_mode
  1647. {
  1648. if (!IS_DREG ($1) || !IS_DREG ($6))
  1649. return yyerror ("Dregs expected");
  1650. if (!IS_HCOMPL($1, $6))
  1651. return yyerror ("Dest registers mismatch");
  1652. if (check_multiply_halfregs (&$3, &$8) < 0)
  1653. return -1;
  1654. if ((!IS_H ($1) && $4.MM)
  1655. || (!IS_H ($6) && $9.MM))
  1656. return yyerror ("(M) not allowed with MAC0");
  1657. notethat ("dsp32mult: dregs_hi = multiply_halfregs mxd_mod, "
  1658. "dregs_lo = multiply_halfregs opt_mode\n");
  1659. if (IS_H ($1))
  1660. $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 0,
  1661. IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
  1662. &$1, 0, &$3.s0, &$3.s1, 1);
  1663. else
  1664. $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 0,
  1665. IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
  1666. &$1, 0, &$3.s0, &$3.s1, 1);
  1667. }
  1668. | REG ASSIGN multiply_halfregs opt_mode COMMA REG ASSIGN multiply_halfregs opt_mode
  1669. {
  1670. if (!IS_DREG ($1) || !IS_DREG ($6))
  1671. return yyerror ("Dregs expected");
  1672. if ((IS_EVEN ($1) && $6.regno - $1.regno != 1)
  1673. || (IS_EVEN ($6) && $1.regno - $6.regno != 1))
  1674. return yyerror ("Dest registers mismatch");
  1675. if (check_multiply_halfregs (&$3, &$8) < 0)
  1676. return -1;
  1677. if ((IS_EVEN ($1) && $4.MM)
  1678. || (IS_EVEN ($6) && $9.MM))
  1679. return yyerror ("(M) not allowed with MAC0");
  1680. notethat ("dsp32mult: dregs = multiply_halfregs mxd_mod, "
  1681. "dregs = multiply_halfregs opt_mode\n");
  1682. if (IS_EVEN ($1))
  1683. $$ = DSP32MULT (0, $9.MM, $9.mod, 1, 1,
  1684. IS_H ($8.s0), IS_H ($8.s1), IS_H ($3.s0), IS_H ($3.s1),
  1685. &$1, 0, &$3.s0, &$3.s1, 1);
  1686. else
  1687. $$ = DSP32MULT (0, $4.MM, $9.mod, 1, 1,
  1688. IS_H ($3.s0), IS_H ($3.s1), IS_H ($8.s0), IS_H ($8.s1),
  1689. &$1, 0, &$3.s0, &$3.s1, 1);
  1690. }
  1691. /* SHIFTs. */
  1692. | a_assign ASHIFT REG_A BY HALF_REG
  1693. {
  1694. if (!REG_SAME ($1, $3))
  1695. return yyerror ("Aregs must be same");
  1696. if (IS_DREG ($5) && !IS_H ($5))
  1697. {
  1698. notethat ("dsp32shift: A0 = ASHIFT A0 BY dregs_lo\n");
  1699. $$ = DSP32SHIFT (3, 0, &$5, 0, 0, IS_A1 ($1));
  1700. }
  1701. else
  1702. return yyerror ("Dregs expected");
  1703. }
  1704. | HALF_REG ASSIGN ASHIFT HALF_REG BY HALF_REG smod
  1705. {
  1706. if (IS_DREG ($6) && !IS_H ($6))
  1707. {
  1708. notethat ("dsp32shift: dregs_half = ASHIFT dregs_half BY dregs_lo\n");
  1709. $$ = DSP32SHIFT (0, &$1, &$6, &$4, $7.s0, HL2 ($1, $4));
  1710. }
  1711. else
  1712. return yyerror ("Dregs expected");
  1713. }
  1714. | a_assign REG_A LESS_LESS expr
  1715. {
  1716. if (!REG_SAME ($1, $2))
  1717. return yyerror ("Aregs must be same");
  1718. if (IS_UIMM ($4, 5))
  1719. {
  1720. notethat ("dsp32shiftimm: A0 = A0 << uimm5\n");
  1721. $$ = DSP32SHIFTIMM (3, 0, imm5 ($4), 0, 0, IS_A1 ($1));
  1722. }
  1723. else
  1724. return yyerror ("Bad shift value");
  1725. }
  1726. | REG ASSIGN REG LESS_LESS expr vsmod
  1727. {
  1728. if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
  1729. {
  1730. if ($6.r0)
  1731. {
  1732. /* Vector? */
  1733. notethat ("dsp32shiftimm: dregs = dregs << expr (V, .)\n");
  1734. $$ = DSP32SHIFTIMM (1, &$1, imm4 ($5), &$3, $6.s0 ? 1 : 2, 0);
  1735. }
  1736. else
  1737. {
  1738. notethat ("dsp32shiftimm: dregs = dregs << uimm5 (.)\n");
  1739. $$ = DSP32SHIFTIMM (2, &$1, imm6 ($5), &$3, $6.s0 ? 1 : 2, 0);
  1740. }
  1741. }
  1742. else if ($6.s0 == 0 && IS_PREG ($1) && IS_PREG ($3))
  1743. {
  1744. if (EXPR_VALUE ($5) == 2)
  1745. {
  1746. notethat ("PTR2op: pregs = pregs << 2\n");
  1747. $$ = PTR2OP (&$1, &$3, 1);
  1748. }
  1749. else if (EXPR_VALUE ($5) == 1)
  1750. {
  1751. notethat ("COMP3op: pregs = pregs << 1\n");
  1752. $$ = COMP3OP (&$1, &$3, &$3, 5);
  1753. }
  1754. else
  1755. return yyerror ("Bad shift value");
  1756. }
  1757. else
  1758. return yyerror ("Bad shift value or register");
  1759. }
  1760. | HALF_REG ASSIGN HALF_REG LESS_LESS expr smod
  1761. {
  1762. if (IS_UIMM ($5, 4))
  1763. {
  1764. if ($6.s0)
  1765. {
  1766. notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4 (S)\n");
  1767. $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, $6.s0, HL2 ($1, $3));
  1768. }
  1769. else
  1770. {
  1771. notethat ("dsp32shiftimm: dregs_half = dregs_half << uimm4\n");
  1772. $$ = DSP32SHIFTIMM (0x0, &$1, imm5 ($5), &$3, 2, HL2 ($1, $3));
  1773. }
  1774. }
  1775. else
  1776. return yyerror ("Bad shift value");
  1777. }
  1778. | REG ASSIGN ASHIFT REG BY HALF_REG vsmod
  1779. {
  1780. int op;
  1781. if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG ($6) && !IS_H ($6))
  1782. {
  1783. if ($7.r0)
  1784. {
  1785. op = 1;
  1786. notethat ("dsp32shift: dregs = ASHIFT dregs BY "
  1787. "dregs_lo (V, .)\n");
  1788. }
  1789. else
  1790. {
  1791. op = 2;
  1792. notethat ("dsp32shift: dregs = ASHIFT dregs BY dregs_lo (.)\n");
  1793. }
  1794. $$ = DSP32SHIFT (op, &$1, &$6, &$4, $7.s0, 0);
  1795. }
  1796. else
  1797. return yyerror ("Dregs expected");
  1798. }
  1799. /* EXPADJ. */
  1800. | HALF_REG ASSIGN EXPADJ LPAREN REG COMMA HALF_REG RPAREN vmod
  1801. {
  1802. if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
  1803. {
  1804. notethat ("dsp32shift: dregs_lo = EXPADJ (dregs , dregs_lo )\n");
  1805. $$ = DSP32SHIFT (7, &$1, &$7, &$5, $9.r0, 0);
  1806. }
  1807. else
  1808. return yyerror ("Bad shift value or register");
  1809. }
  1810. | HALF_REG ASSIGN EXPADJ LPAREN HALF_REG COMMA HALF_REG RPAREN
  1811. {
  1812. if (IS_DREG_L ($1) && IS_DREG_L ($5) && IS_DREG_L ($7))
  1813. {
  1814. notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_lo, dregs_lo)\n");
  1815. $$ = DSP32SHIFT (7, &$1, &$7, &$5, 2, 0);
  1816. }
  1817. else if (IS_DREG_L ($1) && IS_DREG_H ($5) && IS_DREG_L ($7))
  1818. {
  1819. notethat ("dsp32shift: dregs_lo = EXPADJ (dregs_hi, dregs_lo)\n");
  1820. $$ = DSP32SHIFT (7, &$1, &$7, &$5, 3, 0);
  1821. }
  1822. else
  1823. return yyerror ("Bad shift value or register");
  1824. }
  1825. /* DEPOSIT. */
  1826. | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN
  1827. {
  1828. if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
  1829. {
  1830. notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs )\n");
  1831. $$ = DSP32SHIFT (10, &$1, &$7, &$5, 2, 0);
  1832. }
  1833. else
  1834. return yyerror ("Register mismatch");
  1835. }
  1836. | REG ASSIGN DEPOSIT LPAREN REG COMMA REG RPAREN LPAREN X RPAREN
  1837. {
  1838. if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
  1839. {
  1840. notethat ("dsp32shift: dregs = DEPOSIT (dregs , dregs ) (X)\n");
  1841. $$ = DSP32SHIFT (10, &$1, &$7, &$5, 3, 0);
  1842. }
  1843. else
  1844. return yyerror ("Register mismatch");
  1845. }
  1846. | REG ASSIGN EXTRACT LPAREN REG COMMA HALF_REG RPAREN xpmod
  1847. {
  1848. if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG_L ($7))
  1849. {
  1850. notethat ("dsp32shift: dregs = EXTRACT (dregs, dregs_lo ) (.)\n");
  1851. $$ = DSP32SHIFT (10, &$1, &$7, &$5, $9.r0, 0);
  1852. }
  1853. else
  1854. return yyerror ("Register mismatch");
  1855. }
  1856. | a_assign REG_A _GREATER_GREATER_GREATER expr
  1857. {
  1858. if (!REG_SAME ($1, $2))
  1859. return yyerror ("Aregs must be same");
  1860. if (IS_UIMM ($4, 5))
  1861. {
  1862. notethat ("dsp32shiftimm: Ax = Ax >>> uimm5\n");
  1863. $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 0, IS_A1 ($1));
  1864. }
  1865. else
  1866. return yyerror ("Shift value range error");
  1867. }
  1868. | a_assign LSHIFT REG_A BY HALF_REG
  1869. {
  1870. if (REG_SAME ($1, $3) && IS_DREG_L ($5))
  1871. {
  1872. notethat ("dsp32shift: Ax = LSHIFT Ax BY dregs_lo\n");
  1873. $$ = DSP32SHIFT (3, 0, &$5, 0, 1, IS_A1 ($1));
  1874. }
  1875. else
  1876. return yyerror ("Register mismatch");
  1877. }
  1878. | HALF_REG ASSIGN LSHIFT HALF_REG BY HALF_REG
  1879. {
  1880. if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
  1881. {
  1882. notethat ("dsp32shift: dregs_lo = LSHIFT dregs_hi BY dregs_lo\n");
  1883. $$ = DSP32SHIFT (0, &$1, &$6, &$4, 2, HL2 ($1, $4));
  1884. }
  1885. else
  1886. return yyerror ("Register mismatch");
  1887. }
  1888. | REG ASSIGN LSHIFT REG BY HALF_REG vmod
  1889. {
  1890. if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
  1891. {
  1892. notethat ("dsp32shift: dregs = LSHIFT dregs BY dregs_lo (V )\n");
  1893. $$ = DSP32SHIFT ($7.r0 ? 1: 2, &$1, &$6, &$4, 2, 0);
  1894. }
  1895. else
  1896. return yyerror ("Register mismatch");
  1897. }
  1898. | REG ASSIGN SHIFT REG BY HALF_REG
  1899. {
  1900. if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
  1901. {
  1902. notethat ("dsp32shift: dregs = SHIFT dregs BY dregs_lo\n");
  1903. $$ = DSP32SHIFT (2, &$1, &$6, &$4, 2, 0);
  1904. }
  1905. else
  1906. return yyerror ("Register mismatch");
  1907. }
  1908. | a_assign REG_A GREATER_GREATER expr
  1909. {
  1910. if (REG_SAME ($1, $2) && IS_IMM ($4, 6) >= 0)
  1911. {
  1912. notethat ("dsp32shiftimm: Ax = Ax >> imm6\n");
  1913. $$ = DSP32SHIFTIMM (3, 0, -imm6 ($4), 0, 1, IS_A1 ($1));
  1914. }
  1915. else
  1916. return yyerror ("Accu register expected");
  1917. }
  1918. | REG ASSIGN REG GREATER_GREATER expr vmod
  1919. {
  1920. if ($6.r0 == 1)
  1921. {
  1922. if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
  1923. {
  1924. notethat ("dsp32shiftimm: dregs = dregs >> uimm5 (V)\n");
  1925. $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, 2, 0);
  1926. }
  1927. else
  1928. return yyerror ("Register mismatch");
  1929. }
  1930. else
  1931. {
  1932. if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
  1933. {
  1934. notethat ("dsp32shiftimm: dregs = dregs >> uimm5\n");
  1935. $$ = DSP32SHIFTIMM (2, &$1, -imm6 ($5), &$3, 2, 0);
  1936. }
  1937. else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 2)
  1938. {
  1939. notethat ("PTR2op: pregs = pregs >> 2\n");
  1940. $$ = PTR2OP (&$1, &$3, 3);
  1941. }
  1942. else if (IS_PREG ($1) && IS_PREG ($3) && EXPR_VALUE ($5) == 1)
  1943. {
  1944. notethat ("PTR2op: pregs = pregs >> 1\n");
  1945. $$ = PTR2OP (&$1, &$3, 4);
  1946. }
  1947. else
  1948. return yyerror ("Register mismatch");
  1949. }
  1950. }
  1951. | HALF_REG ASSIGN HALF_REG GREATER_GREATER expr
  1952. {
  1953. if (IS_UIMM ($5, 5))
  1954. {
  1955. notethat ("dsp32shiftimm: dregs_half = dregs_half >> uimm5\n");
  1956. $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3, 2, HL2 ($1, $3));
  1957. }
  1958. else
  1959. return yyerror ("Register mismatch");
  1960. }
  1961. | HALF_REG ASSIGN HALF_REG _GREATER_GREATER_GREATER expr smod
  1962. {
  1963. if (IS_UIMM ($5, 5))
  1964. {
  1965. notethat ("dsp32shiftimm: dregs_half = dregs_half >>> uimm5\n");
  1966. $$ = DSP32SHIFTIMM (0, &$1, -uimm5 ($5), &$3,
  1967. $6.s0, HL2 ($1, $3));
  1968. }
  1969. else
  1970. return yyerror ("Register or modifier mismatch");
  1971. }
  1972. | REG ASSIGN REG _GREATER_GREATER_GREATER expr vsmod
  1973. {
  1974. if (IS_DREG ($1) && IS_DREG ($3) && IS_UIMM ($5, 5))
  1975. {
  1976. if ($6.r0)
  1977. {
  1978. /* Vector? */
  1979. notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (V, .)\n");
  1980. $$ = DSP32SHIFTIMM (1, &$1, -uimm5 ($5), &$3, $6.s0, 0);
  1981. }
  1982. else
  1983. {
  1984. notethat ("dsp32shiftimm: dregs = dregs >>> uimm5 (.)\n");
  1985. $$ = DSP32SHIFTIMM (2, &$1, -uimm5 ($5), &$3, $6.s0, 0);
  1986. }
  1987. }
  1988. else
  1989. return yyerror ("Register mismatch");
  1990. }
  1991. | HALF_REG ASSIGN ONES REG
  1992. {
  1993. if (IS_DREG_L ($1) && IS_DREG ($4))
  1994. {
  1995. notethat ("dsp32shift: dregs_lo = ONES dregs\n");
  1996. $$ = DSP32SHIFT (6, &$1, 0, &$4, 3, 0);
  1997. }
  1998. else
  1999. return yyerror ("Register mismatch");
  2000. }
  2001. | REG ASSIGN PACK LPAREN HALF_REG COMMA HALF_REG RPAREN
  2002. {
  2003. if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
  2004. {
  2005. notethat ("dsp32shift: dregs = PACK (dregs_hi , dregs_hi )\n");
  2006. $$ = DSP32SHIFT (4, &$1, &$7, &$5, HL2 ($5, $7), 0);
  2007. }
  2008. else
  2009. return yyerror ("Register mismatch");
  2010. }
  2011. | HALF_REG ASSIGN CCREG ASSIGN BXORSHIFT LPAREN REG_A COMMA REG RPAREN
  2012. {
  2013. if (IS_DREG ($1)
  2014. && $7.regno == REG_A0
  2015. && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
  2016. {
  2017. notethat ("dsp32shift: dregs_lo = CC = BXORSHIFT (A0 , dregs )\n");
  2018. $$ = DSP32SHIFT (11, &$1, &$9, 0, 0, 0);
  2019. }
  2020. else
  2021. return yyerror ("Register mismatch");
  2022. }
  2023. | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG RPAREN
  2024. {
  2025. if (IS_DREG ($1)
  2026. && $7.regno == REG_A0
  2027. && IS_DREG ($9) && !IS_H ($1) && !IS_A1 ($7))
  2028. {
  2029. notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , dregs)\n");
  2030. $$ = DSP32SHIFT (11, &$1, &$9, 0, 1, 0);
  2031. }
  2032. else
  2033. return yyerror ("Register mismatch");
  2034. }
  2035. | HALF_REG ASSIGN CCREG ASSIGN BXOR LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
  2036. {
  2037. if (IS_DREG ($1) && !IS_H ($1) && !REG_SAME ($7, $9))
  2038. {
  2039. notethat ("dsp32shift: dregs_lo = CC = BXOR (A0 , A1 , CC)\n");
  2040. $$ = DSP32SHIFT (12, &$1, 0, 0, 1, 0);
  2041. }
  2042. else
  2043. return yyerror ("Register mismatch");
  2044. }
  2045. | a_assign ROT REG_A BY HALF_REG
  2046. {
  2047. if (REG_SAME ($1, $3) && IS_DREG_L ($5))
  2048. {
  2049. notethat ("dsp32shift: Ax = ROT Ax BY dregs_lo\n");
  2050. $$ = DSP32SHIFT (3, 0, &$5, 0, 2, IS_A1 ($1));
  2051. }
  2052. else
  2053. return yyerror ("Register mismatch");
  2054. }
  2055. | REG ASSIGN ROT REG BY HALF_REG
  2056. {
  2057. if (IS_DREG ($1) && IS_DREG ($4) && IS_DREG_L ($6))
  2058. {
  2059. notethat ("dsp32shift: dregs = ROT dregs BY dregs_lo\n");
  2060. $$ = DSP32SHIFT (2, &$1, &$6, &$4, 3, 0);
  2061. }
  2062. else
  2063. return yyerror ("Register mismatch");
  2064. }
  2065. | a_assign ROT REG_A BY expr
  2066. {
  2067. if (IS_IMM ($5, 6))
  2068. {
  2069. notethat ("dsp32shiftimm: An = ROT An BY imm6\n");
  2070. $$ = DSP32SHIFTIMM (3, 0, imm6 ($5), 0, 2, IS_A1 ($1));
  2071. }
  2072. else
  2073. return yyerror ("Register mismatch");
  2074. }
  2075. | REG ASSIGN ROT REG BY expr
  2076. {
  2077. if (IS_DREG ($1) && IS_DREG ($4) && IS_IMM ($6, 6))
  2078. {
  2079. $$ = DSP32SHIFTIMM (2, &$1, imm6 ($6), &$4, 3, IS_A1 ($1));
  2080. }
  2081. else
  2082. return yyerror ("Register mismatch");
  2083. }
  2084. | HALF_REG ASSIGN SIGNBITS REG_A
  2085. {
  2086. if (IS_DREG_L ($1))
  2087. {
  2088. notethat ("dsp32shift: dregs_lo = SIGNBITS An\n");
  2089. $$ = DSP32SHIFT (6, &$1, 0, 0, IS_A1 ($4), 0);
  2090. }
  2091. else
  2092. return yyerror ("Register mismatch");
  2093. }
  2094. | HALF_REG ASSIGN SIGNBITS REG
  2095. {
  2096. if (IS_DREG_L ($1) && IS_DREG ($4))
  2097. {
  2098. notethat ("dsp32shift: dregs_lo = SIGNBITS dregs\n");
  2099. $$ = DSP32SHIFT (5, &$1, 0, &$4, 0, 0);
  2100. }
  2101. else
  2102. return yyerror ("Register mismatch");
  2103. }
  2104. | HALF_REG ASSIGN SIGNBITS HALF_REG
  2105. {
  2106. if (IS_DREG_L ($1))
  2107. {
  2108. notethat ("dsp32shift: dregs_lo = SIGNBITS dregs_lo\n");
  2109. $$ = DSP32SHIFT (5, &$1, 0, &$4, 1 + IS_H ($4), 0);
  2110. }
  2111. else
  2112. return yyerror ("Register mismatch");
  2113. }
  2114. /* The ASR bit is just inverted here. */
  2115. | HALF_REG ASSIGN VIT_MAX LPAREN REG RPAREN asr_asl
  2116. {
  2117. if (IS_DREG_L ($1) && IS_DREG ($5))
  2118. {
  2119. notethat ("dsp32shift: dregs_lo = VIT_MAX (dregs) (..)\n");
  2120. $$ = DSP32SHIFT (9, &$1, 0, &$5, ($7.r0 ? 0 : 1), 0);
  2121. }
  2122. else
  2123. return yyerror ("Register mismatch");
  2124. }
  2125. | REG ASSIGN VIT_MAX LPAREN REG COMMA REG RPAREN asr_asl
  2126. {
  2127. if (IS_DREG ($1) && IS_DREG ($5) && IS_DREG ($7))
  2128. {
  2129. notethat ("dsp32shift: dregs = VIT_MAX (dregs, dregs) (ASR)\n");
  2130. $$ = DSP32SHIFT (9, &$1, &$7, &$5, 2 | ($9.r0 ? 0 : 1), 0);
  2131. }
  2132. else
  2133. return yyerror ("Register mismatch");
  2134. }
  2135. | BITMUX LPAREN REG COMMA REG COMMA REG_A RPAREN asr_asl
  2136. {
  2137. if (REG_SAME ($3, $5))
  2138. return yyerror ("Illegal source register combination");
  2139. if (IS_DREG ($3) && IS_DREG ($5) && !IS_A1 ($7))
  2140. {
  2141. notethat ("dsp32shift: BITMUX (dregs , dregs , A0) (ASR)\n");
  2142. $$ = DSP32SHIFT (8, 0, &$3, &$5, $9.r0, 0);
  2143. }
  2144. else
  2145. return yyerror ("Register mismatch");
  2146. }
  2147. | a_assign BXORSHIFT LPAREN REG_A COMMA REG_A COMMA CCREG RPAREN
  2148. {
  2149. if (!IS_A1 ($1) && !IS_A1 ($4) && IS_A1 ($6))
  2150. {
  2151. notethat ("dsp32shift: A0 = BXORSHIFT (A0 , A1 , CC )\n");
  2152. $$ = DSP32SHIFT (12, 0, 0, 0, 0, 0);
  2153. }
  2154. else
  2155. return yyerror ("Dregs expected");
  2156. }
  2157. /* LOGI2op: BITCLR (dregs, uimm5). */
  2158. | BITCLR LPAREN REG COMMA expr RPAREN
  2159. {
  2160. if (IS_DREG ($3) && IS_UIMM ($5, 5))
  2161. {
  2162. notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
  2163. $$ = LOGI2OP ($3, uimm5 ($5), 4);
  2164. }
  2165. else
  2166. return yyerror ("Register mismatch");
  2167. }
  2168. /* LOGI2op: BITSET (dregs, uimm5). */
  2169. | BITSET LPAREN REG COMMA expr RPAREN
  2170. {
  2171. if (IS_DREG ($3) && IS_UIMM ($5, 5))
  2172. {
  2173. notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
  2174. $$ = LOGI2OP ($3, uimm5 ($5), 2);
  2175. }
  2176. else
  2177. return yyerror ("Register mismatch");
  2178. }
  2179. /* LOGI2op: BITTGL (dregs, uimm5). */
  2180. | BITTGL LPAREN REG COMMA expr RPAREN
  2181. {
  2182. if (IS_DREG ($3) && IS_UIMM ($5, 5))
  2183. {
  2184. notethat ("LOGI2op: BITCLR (dregs , uimm5 )\n");
  2185. $$ = LOGI2OP ($3, uimm5 ($5), 3);
  2186. }
  2187. else
  2188. return yyerror ("Register mismatch");
  2189. }
  2190. | CCREG _ASSIGN_BANG BITTST LPAREN REG COMMA expr RPAREN
  2191. {
  2192. if (IS_DREG ($5) && IS_UIMM ($7, 5))
  2193. {
  2194. notethat ("LOGI2op: CC =! BITTST (dregs , uimm5 )\n");
  2195. $$ = LOGI2OP ($5, uimm5 ($7), 0);
  2196. }
  2197. else
  2198. return yyerror ("Register mismatch or value error");
  2199. }
  2200. | CCREG ASSIGN BITTST LPAREN REG COMMA expr RPAREN
  2201. {
  2202. if (IS_DREG ($5) && IS_UIMM ($7, 5))
  2203. {
  2204. notethat ("LOGI2op: CC = BITTST (dregs , uimm5 )\n");
  2205. $$ = LOGI2OP ($5, uimm5 ($7), 1);
  2206. }
  2207. else
  2208. return yyerror ("Register mismatch or value error");
  2209. }
  2210. | IF BANG CCREG REG ASSIGN REG
  2211. {
  2212. if ((IS_DREG ($4) || IS_PREG ($4))
  2213. && (IS_DREG ($6) || IS_PREG ($6)))
  2214. {
  2215. notethat ("ccMV: IF ! CC gregs = gregs\n");
  2216. $$ = CCMV (&$6, &$4, 0);
  2217. }
  2218. else
  2219. return yyerror ("Register mismatch");
  2220. }
  2221. | IF CCREG REG ASSIGN REG
  2222. {
  2223. if ((IS_DREG ($5) || IS_PREG ($5))
  2224. && (IS_DREG ($3) || IS_PREG ($3)))
  2225. {
  2226. notethat ("ccMV: IF CC gregs = gregs\n");
  2227. $$ = CCMV (&$5, &$3, 1);
  2228. }
  2229. else
  2230. return yyerror ("Register mismatch");
  2231. }
  2232. | IF BANG CCREG JUMP expr
  2233. {
  2234. if (IS_PCREL10 ($5))
  2235. {
  2236. notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
  2237. $$ = BRCC (0, 0, $5);
  2238. }
  2239. else
  2240. return yyerror ("Bad jump offset");
  2241. }
  2242. | IF BANG CCREG JUMP expr LPAREN BP RPAREN
  2243. {
  2244. if (IS_PCREL10 ($5))
  2245. {
  2246. notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
  2247. $$ = BRCC (0, 1, $5);
  2248. }
  2249. else
  2250. return yyerror ("Bad jump offset");
  2251. }
  2252. | IF CCREG JUMP expr
  2253. {
  2254. if (IS_PCREL10 ($4))
  2255. {
  2256. notethat ("BRCC: IF CC JUMP pcrel11m2\n");
  2257. $$ = BRCC (1, 0, $4);
  2258. }
  2259. else
  2260. return yyerror ("Bad jump offset");
  2261. }
  2262. | IF CCREG JUMP expr LPAREN BP RPAREN
  2263. {
  2264. if (IS_PCREL10 ($4))
  2265. {
  2266. notethat ("BRCC: IF !CC JUMP pcrel11m2\n");
  2267. $$ = BRCC (1, 1, $4);
  2268. }
  2269. else
  2270. return yyerror ("Bad jump offset");
  2271. }
  2272. | NOP
  2273. {
  2274. notethat ("ProgCtrl: NOP\n");
  2275. $$ = PROGCTRL (0, 0);
  2276. }
  2277. | RTS
  2278. {
  2279. notethat ("ProgCtrl: RTS\n");
  2280. $$ = PROGCTRL (1, 0);
  2281. }
  2282. | RTI
  2283. {
  2284. notethat ("ProgCtrl: RTI\n");
  2285. $$ = PROGCTRL (1, 1);
  2286. }
  2287. | RTX
  2288. {
  2289. notethat ("ProgCtrl: RTX\n");
  2290. $$ = PROGCTRL (1, 2);
  2291. }
  2292. | RTN
  2293. {
  2294. notethat ("ProgCtrl: RTN\n");
  2295. $$ = PROGCTRL (1, 3);
  2296. }
  2297. | RTE
  2298. {
  2299. notethat ("ProgCtrl: RTE\n");
  2300. $$ = PROGCTRL (1, 4);
  2301. }
  2302. | IDLE
  2303. {
  2304. notethat ("ProgCtrl: IDLE\n");
  2305. $$ = PROGCTRL (2, 0);
  2306. }
  2307. | CSYNC
  2308. {
  2309. notethat ("ProgCtrl: CSYNC\n");
  2310. $$ = PROGCTRL (2, 3);
  2311. }
  2312. | SSYNC
  2313. {
  2314. notethat ("ProgCtrl: SSYNC\n");
  2315. $$ = PROGCTRL (2, 4);
  2316. }
  2317. | EMUEXCPT
  2318. {
  2319. notethat ("ProgCtrl: EMUEXCPT\n");
  2320. $$ = PROGCTRL (2, 5);
  2321. }
  2322. | CLI REG
  2323. {
  2324. if (IS_DREG ($2))
  2325. {
  2326. notethat ("ProgCtrl: CLI dregs\n");
  2327. $$ = PROGCTRL (3, $2.regno & CODE_MASK);
  2328. }
  2329. else
  2330. return yyerror ("Dreg expected for CLI");
  2331. }
  2332. | STI REG
  2333. {
  2334. if (IS_DREG ($2))
  2335. {
  2336. notethat ("ProgCtrl: STI dregs\n");
  2337. $$ = PROGCTRL (4, $2.regno & CODE_MASK);
  2338. }
  2339. else
  2340. return yyerror ("Dreg expected for STI");
  2341. }
  2342. | JUMP LPAREN REG RPAREN
  2343. {
  2344. if (IS_PREG ($3))
  2345. {
  2346. notethat ("ProgCtrl: JUMP (pregs )\n");
  2347. $$ = PROGCTRL (5, $3.regno & CODE_MASK);
  2348. }
  2349. else
  2350. return yyerror ("Bad register for indirect jump");
  2351. }
  2352. | CALL LPAREN REG RPAREN
  2353. {
  2354. if (IS_PREG ($3))
  2355. {
  2356. notethat ("ProgCtrl: CALL (pregs )\n");
  2357. $$ = PROGCTRL (6, $3.regno & CODE_MASK);
  2358. }
  2359. else
  2360. return yyerror ("Bad register for indirect call");
  2361. }
  2362. | CALL LPAREN PC PLUS REG RPAREN
  2363. {
  2364. if (IS_PREG ($5))
  2365. {
  2366. notethat ("ProgCtrl: CALL (PC + pregs )\n");
  2367. $$ = PROGCTRL (7, $5.regno & CODE_MASK);
  2368. }
  2369. else
  2370. return yyerror ("Bad register for indirect call");
  2371. }
  2372. | JUMP LPAREN PC PLUS REG RPAREN
  2373. {
  2374. if (IS_PREG ($5))
  2375. {
  2376. notethat ("ProgCtrl: JUMP (PC + pregs )\n");
  2377. $$ = PROGCTRL (8, $5.regno & CODE_MASK);
  2378. }
  2379. else
  2380. return yyerror ("Bad register for indirect jump");
  2381. }
  2382. | RAISE expr
  2383. {
  2384. if (IS_UIMM ($2, 4))
  2385. {
  2386. notethat ("ProgCtrl: RAISE uimm4\n");
  2387. $$ = PROGCTRL (9, uimm4 ($2));
  2388. }
  2389. else
  2390. return yyerror ("Bad value for RAISE");
  2391. }
  2392. | EXCPT expr
  2393. {
  2394. notethat ("ProgCtrl: EMUEXCPT\n");
  2395. $$ = PROGCTRL (10, uimm4 ($2));
  2396. }
  2397. | TESTSET LPAREN REG RPAREN
  2398. {
  2399. if (IS_PREG ($3))
  2400. {
  2401. if ($3.regno == REG_SP || $3.regno == REG_FP)
  2402. return yyerror ("Bad register for TESTSET");
  2403. notethat ("ProgCtrl: TESTSET (pregs )\n");
  2404. $$ = PROGCTRL (11, $3.regno & CODE_MASK);
  2405. }
  2406. else
  2407. return yyerror ("Preg expected");
  2408. }
  2409. | JUMP expr
  2410. {
  2411. if (IS_PCREL12 ($2))
  2412. {
  2413. notethat ("UJUMP: JUMP pcrel12\n");
  2414. $$ = UJUMP ($2);
  2415. }
  2416. else
  2417. return yyerror ("Bad value for relative jump");
  2418. }
  2419. | JUMP_DOT_S expr
  2420. {
  2421. if (IS_PCREL12 ($2))
  2422. {
  2423. notethat ("UJUMP: JUMP_DOT_S pcrel12\n");
  2424. $$ = UJUMP($2);
  2425. }
  2426. else
  2427. return yyerror ("Bad value for relative jump");
  2428. }
  2429. | JUMP_DOT_L expr
  2430. {
  2431. if (IS_PCREL24 ($2))
  2432. {
  2433. notethat ("CALLa: jump.l pcrel24\n");
  2434. $$ = CALLA ($2, 0);
  2435. }
  2436. else
  2437. return yyerror ("Bad value for long jump");
  2438. }
  2439. | JUMP_DOT_L pltpc
  2440. {
  2441. if (IS_PCREL24 ($2))
  2442. {
  2443. notethat ("CALLa: jump.l pcrel24\n");
  2444. $$ = CALLA ($2, 2);
  2445. }
  2446. else
  2447. return yyerror ("Bad value for long jump");
  2448. }
  2449. | CALL expr
  2450. {
  2451. if (IS_PCREL24 ($2))
  2452. {
  2453. notethat ("CALLa: CALL pcrel25m2\n");
  2454. $$ = CALLA ($2, 1);
  2455. }
  2456. else
  2457. return yyerror ("Bad call address");
  2458. }
  2459. | CALL pltpc
  2460. {
  2461. if (IS_PCREL24 ($2))
  2462. {
  2463. notethat ("CALLa: CALL pcrel25m2\n");
  2464. $$ = CALLA ($2, 2);
  2465. }
  2466. else
  2467. return yyerror ("Bad call address");
  2468. }
  2469. /* ALU2ops. */
  2470. /* ALU2op: DIVQ (dregs, dregs). */
  2471. | DIVQ LPAREN REG COMMA REG RPAREN
  2472. {
  2473. if (IS_DREG ($3) && IS_DREG ($5))
  2474. $$ = ALU2OP (&$3, &$5, 8);
  2475. else
  2476. return yyerror ("Bad registers for DIVQ");
  2477. }
  2478. | DIVS LPAREN REG COMMA REG RPAREN
  2479. {
  2480. if (IS_DREG ($3) && IS_DREG ($5))
  2481. $$ = ALU2OP (&$3, &$5, 9);
  2482. else
  2483. return yyerror ("Bad registers for DIVS");
  2484. }
  2485. | REG ASSIGN MINUS REG vsmod
  2486. {
  2487. if (IS_DREG ($1) && IS_DREG ($4))
  2488. {
  2489. if ($5.r0 == 0 && $5.s0 == 0 && $5.aop == 0)
  2490. {
  2491. notethat ("ALU2op: dregs = - dregs\n");
  2492. $$ = ALU2OP (&$1, &$4, 14);
  2493. }
  2494. else if ($5.r0 == 1 && $5.s0 == 0 && $5.aop == 3)
  2495. {
  2496. notethat ("dsp32alu: dregs = - dregs (.)\n");
  2497. $$ = DSP32ALU (15, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
  2498. }
  2499. else
  2500. {
  2501. notethat ("dsp32alu: dregs = - dregs (.)\n");
  2502. $$ = DSP32ALU (7, 0, 0, &$1, &$4, 0, $5.s0, 0, 3);
  2503. }
  2504. }
  2505. else
  2506. return yyerror ("Dregs expected");
  2507. }
  2508. | REG ASSIGN TILDA REG
  2509. {
  2510. if (IS_DREG ($1) && IS_DREG ($4))
  2511. {
  2512. notethat ("ALU2op: dregs = ~dregs\n");
  2513. $$ = ALU2OP (&$1, &$4, 15);
  2514. }
  2515. else
  2516. return yyerror ("Dregs expected");
  2517. }
  2518. | REG _GREATER_GREATER_ASSIGN REG
  2519. {
  2520. if (IS_DREG ($1) && IS_DREG ($3))
  2521. {
  2522. notethat ("ALU2op: dregs >>= dregs\n");
  2523. $$ = ALU2OP (&$1, &$3, 1);
  2524. }
  2525. else
  2526. return yyerror ("Dregs expected");
  2527. }
  2528. | REG _GREATER_GREATER_ASSIGN expr
  2529. {
  2530. if (IS_DREG ($1) && IS_UIMM ($3, 5))
  2531. {
  2532. notethat ("LOGI2op: dregs >>= uimm5\n");
  2533. $$ = LOGI2OP ($1, uimm5 ($3), 6);
  2534. }
  2535. else
  2536. return yyerror ("Dregs expected or value error");
  2537. }
  2538. | REG _GREATER_GREATER_GREATER_THAN_ASSIGN REG
  2539. {
  2540. if (IS_DREG ($1) && IS_DREG ($3))
  2541. {
  2542. notethat ("ALU2op: dregs >>>= dregs\n");
  2543. $$ = ALU2OP (&$1, &$3, 0);
  2544. }
  2545. else
  2546. return yyerror ("Dregs expected");
  2547. }
  2548. | REG _LESS_LESS_ASSIGN REG
  2549. {
  2550. if (IS_DREG ($1) && IS_DREG ($3))
  2551. {
  2552. notethat ("ALU2op: dregs <<= dregs\n");
  2553. $$ = ALU2OP (&$1, &$3, 2);
  2554. }
  2555. else
  2556. return yyerror ("Dregs expected");
  2557. }
  2558. | REG _LESS_LESS_ASSIGN expr
  2559. {
  2560. if (IS_DREG ($1) && IS_UIMM ($3, 5))
  2561. {
  2562. notethat ("LOGI2op: dregs <<= uimm5\n");
  2563. $$ = LOGI2OP ($1, uimm5 ($3), 7);
  2564. }
  2565. else
  2566. return yyerror ("Dregs expected or const value error");
  2567. }
  2568. | REG _GREATER_GREATER_GREATER_THAN_ASSIGN expr
  2569. {
  2570. if (IS_DREG ($1) && IS_UIMM ($3, 5))
  2571. {
  2572. notethat ("LOGI2op: dregs >>>= uimm5\n");
  2573. $$ = LOGI2OP ($1, uimm5 ($3), 5);
  2574. }
  2575. else
  2576. return yyerror ("Dregs expected");
  2577. }
  2578. /* Cache Control. */
  2579. | FLUSH LBRACK REG RBRACK
  2580. {
  2581. notethat ("CaCTRL: FLUSH [ pregs ]\n");
  2582. if (IS_PREG ($3))
  2583. $$ = CACTRL (&$3, 0, 2);
  2584. else
  2585. return yyerror ("Bad register(s) for FLUSH");
  2586. }
  2587. | FLUSH reg_with_postinc
  2588. {
  2589. if (IS_PREG ($2))
  2590. {
  2591. notethat ("CaCTRL: FLUSH [ pregs ++ ]\n");
  2592. $$ = CACTRL (&$2, 1, 2);
  2593. }
  2594. else
  2595. return yyerror ("Bad register(s) for FLUSH");
  2596. }
  2597. | FLUSHINV LBRACK REG RBRACK
  2598. {
  2599. if (IS_PREG ($3))
  2600. {
  2601. notethat ("CaCTRL: FLUSHINV [ pregs ]\n");
  2602. $$ = CACTRL (&$3, 0, 1);
  2603. }
  2604. else
  2605. return yyerror ("Bad register(s) for FLUSH");
  2606. }
  2607. | FLUSHINV reg_with_postinc
  2608. {
  2609. if (IS_PREG ($2))
  2610. {
  2611. notethat ("CaCTRL: FLUSHINV [ pregs ++ ]\n");
  2612. $$ = CACTRL (&$2, 1, 1);
  2613. }
  2614. else
  2615. return yyerror ("Bad register(s) for FLUSH");
  2616. }
  2617. /* CaCTRL: IFLUSH [pregs]. */
  2618. | IFLUSH LBRACK REG RBRACK
  2619. {
  2620. if (IS_PREG ($3))
  2621. {
  2622. notethat ("CaCTRL: IFLUSH [ pregs ]\n");
  2623. $$ = CACTRL (&$3, 0, 3);
  2624. }
  2625. else
  2626. return yyerror ("Bad register(s) for FLUSH");
  2627. }
  2628. | IFLUSH reg_with_postinc
  2629. {
  2630. if (IS_PREG ($2))
  2631. {
  2632. notethat ("CaCTRL: IFLUSH [ pregs ++ ]\n");
  2633. $$ = CACTRL (&$2, 1, 3);
  2634. }
  2635. else
  2636. return yyerror ("Bad register(s) for FLUSH");
  2637. }
  2638. | PREFETCH LBRACK REG RBRACK
  2639. {
  2640. if (IS_PREG ($3))
  2641. {
  2642. notethat ("CaCTRL: PREFETCH [ pregs ]\n");
  2643. $$ = CACTRL (&$3, 0, 0);
  2644. }
  2645. else
  2646. return yyerror ("Bad register(s) for PREFETCH");
  2647. }
  2648. | PREFETCH reg_with_postinc
  2649. {
  2650. if (IS_PREG ($2))
  2651. {
  2652. notethat ("CaCTRL: PREFETCH [ pregs ++ ]\n");
  2653. $$ = CACTRL (&$2, 1, 0);
  2654. }
  2655. else
  2656. return yyerror ("Bad register(s) for PREFETCH");
  2657. }
  2658. /* LOAD/STORE. */
  2659. /* LDST: B [ pregs <post_op> ] = dregs. */
  2660. | B LBRACK REG post_op RBRACK ASSIGN REG
  2661. {
  2662. if (!IS_DREG ($7))
  2663. return yyerror ("Dreg expected for source operand");
  2664. if (!IS_PREG ($3))
  2665. return yyerror ("Preg expected in address");
  2666. notethat ("LDST: B [ pregs <post_op> ] = dregs\n");
  2667. $$ = LDST (&$3, &$7, $4.x0, 2, 0, 1);
  2668. }
  2669. /* LDSTidxI: B [ pregs + imm16 ] = dregs. */
  2670. | B LBRACK REG plus_minus expr RBRACK ASSIGN REG
  2671. {
  2672. Expr_Node *tmp = $5;
  2673. if (!IS_DREG ($8))
  2674. return yyerror ("Dreg expected for source operand");
  2675. if (!IS_PREG ($3))
  2676. return yyerror ("Preg expected in address");
  2677. if (IS_RELOC ($5))
  2678. return yyerror ("Plain symbol used as offset");
  2679. if ($4.r0)
  2680. tmp = unary (Expr_Op_Type_NEG, tmp);
  2681. if (in_range_p (tmp, -32768, 32767, 0))
  2682. {
  2683. notethat ("LDST: B [ pregs + imm16 ] = dregs\n");
  2684. $$ = LDSTIDXI (&$3, &$8, 1, 2, 0, $5);
  2685. }
  2686. else
  2687. return yyerror ("Displacement out of range");
  2688. }
  2689. /* LDSTii: W [ pregs + uimm4s2 ] = dregs. */
  2690. | W LBRACK REG plus_minus expr RBRACK ASSIGN REG
  2691. {
  2692. Expr_Node *tmp = $5;
  2693. if (!IS_DREG ($8))
  2694. return yyerror ("Dreg expected for source operand");
  2695. if (!IS_PREG ($3))
  2696. return yyerror ("Preg expected in address");
  2697. if ($4.r0)
  2698. tmp = unary (Expr_Op_Type_NEG, tmp);
  2699. if (IS_RELOC ($5))
  2700. return yyerror ("Plain symbol used as offset");
  2701. if (in_range_p (tmp, 0, 30, 1))
  2702. {
  2703. notethat ("LDSTii: W [ pregs +- uimm5m2 ] = dregs\n");
  2704. $$ = LDSTII (&$3, &$8, tmp, 1, 1);
  2705. }
  2706. else if (in_range_p (tmp, -65536, 65535, 1))
  2707. {
  2708. notethat ("LDSTidxI: W [ pregs + imm17m2 ] = dregs\n");
  2709. $$ = LDSTIDXI (&$3, &$8, 1, 1, 0, tmp);
  2710. }
  2711. else
  2712. return yyerror ("Displacement out of range");
  2713. }
  2714. /* LDST: W [ pregs <post_op> ] = dregs. */
  2715. | W LBRACK REG post_op RBRACK ASSIGN REG
  2716. {
  2717. if (!IS_DREG ($7))
  2718. return yyerror ("Dreg expected for source operand");
  2719. if (!IS_PREG ($3))
  2720. return yyerror ("Preg expected in address");
  2721. notethat ("LDST: W [ pregs <post_op> ] = dregs\n");
  2722. $$ = LDST (&$3, &$7, $4.x0, 1, 0, 1);
  2723. }
  2724. | W LBRACK REG post_op RBRACK ASSIGN HALF_REG
  2725. {
  2726. if (!IS_DREG ($7))
  2727. return yyerror ("Dreg expected for source operand");
  2728. if ($4.x0 == 2)
  2729. {
  2730. if (!IS_IREG ($3) && !IS_PREG ($3))
  2731. return yyerror ("Ireg or Preg expected in address");
  2732. }
  2733. else if (!IS_IREG ($3))
  2734. return yyerror ("Ireg expected in address");
  2735. if (IS_IREG ($3))
  2736. {
  2737. notethat ("dspLDST: W [ iregs <post_op> ] = dregs_half\n");
  2738. $$ = DSPLDST (&$3, 1 + IS_H ($7), &$7, $4.x0, 1);
  2739. }
  2740. else
  2741. {
  2742. notethat ("LDSTpmod: W [ pregs ] = dregs_half\n");
  2743. $$ = LDSTPMOD (&$3, &$7, &$3, 1 + IS_H ($7), 1);
  2744. }
  2745. }
  2746. /* LDSTiiFP: [ FP - const ] = dpregs. */
  2747. | LBRACK REG plus_minus expr RBRACK ASSIGN REG
  2748. {
  2749. Expr_Node *tmp = $4;
  2750. int ispreg = IS_PREG ($7);
  2751. if (!IS_PREG ($2))
  2752. return yyerror ("Preg expected in address");
  2753. if (!IS_DREG ($7) && !ispreg)
  2754. return yyerror ("Preg expected for source operand");
  2755. if ($3.r0)
  2756. tmp = unary (Expr_Op_Type_NEG, tmp);
  2757. if (IS_RELOC ($4))
  2758. return yyerror ("Plain symbol used as offset");
  2759. if (in_range_p (tmp, 0, 63, 3))
  2760. {
  2761. notethat ("LDSTii: dpregs = [ pregs + uimm6m4 ]\n");
  2762. $$ = LDSTII (&$2, &$7, tmp, 1, ispreg ? 3 : 0);
  2763. }
  2764. else if ($2.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
  2765. {
  2766. notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
  2767. tmp = unary (Expr_Op_Type_NEG, tmp);
  2768. $$ = LDSTIIFP (tmp, &$7, 1);
  2769. }
  2770. else if (in_range_p (tmp, -131072, 131071, 3))
  2771. {
  2772. notethat ("LDSTidxI: [ pregs + imm18m4 ] = dpregs\n");
  2773. $$ = LDSTIDXI (&$2, &$7, 1, 0, ispreg ? 1 : 0, tmp);
  2774. }
  2775. else
  2776. return yyerror ("Displacement out of range");
  2777. }
  2778. | REG ASSIGN W LBRACK REG plus_minus expr RBRACK xpmod
  2779. {
  2780. Expr_Node *tmp = $7;
  2781. if (!IS_DREG ($1))
  2782. return yyerror ("Dreg expected for destination operand");
  2783. if (!IS_PREG ($5))
  2784. return yyerror ("Preg expected in address");
  2785. if ($6.r0)
  2786. tmp = unary (Expr_Op_Type_NEG, tmp);
  2787. if (IS_RELOC ($7))
  2788. return yyerror ("Plain symbol used as offset");
  2789. if (in_range_p (tmp, 0, 30, 1))
  2790. {
  2791. notethat ("LDSTii: dregs = W [ pregs + uimm5m2 ] (.)\n");
  2792. $$ = LDSTII (&$5, &$1, tmp, 0, 1 << $9.r0);
  2793. }
  2794. else if (in_range_p (tmp, -65536, 65535, 1))
  2795. {
  2796. notethat ("LDSTidxI: dregs = W [ pregs + imm17m2 ] (.)\n");
  2797. $$ = LDSTIDXI (&$5, &$1, 0, 1, $9.r0, tmp);
  2798. }
  2799. else
  2800. return yyerror ("Displacement out of range");
  2801. }
  2802. | HALF_REG ASSIGN W LBRACK REG post_op RBRACK
  2803. {
  2804. if (!IS_DREG ($1))
  2805. return yyerror ("Dreg expected for source operand");
  2806. if ($6.x0 == 2)
  2807. {
  2808. if (!IS_IREG ($5) && !IS_PREG ($5))
  2809. return yyerror ("Ireg or Preg expected in address");
  2810. }
  2811. else if (!IS_IREG ($5))
  2812. return yyerror ("Ireg expected in address");
  2813. if (IS_IREG ($5))
  2814. {
  2815. notethat ("dspLDST: dregs_half = W [ iregs <post_op> ]\n");
  2816. $$ = DSPLDST(&$5, 1 + IS_H ($1), &$1, $6.x0, 0);
  2817. }
  2818. else
  2819. {
  2820. notethat ("LDSTpmod: dregs_half = W [ pregs <post_op> ]\n");
  2821. $$ = LDSTPMOD (&$5, &$1, &$5, 1 + IS_H ($1), 0);
  2822. }
  2823. }
  2824. | REG ASSIGN W LBRACK REG post_op RBRACK xpmod
  2825. {
  2826. if (!IS_DREG ($1))
  2827. return yyerror ("Dreg expected for destination operand");
  2828. if (!IS_PREG ($5))
  2829. return yyerror ("Preg expected in address");
  2830. notethat ("LDST: dregs = W [ pregs <post_op> ] (.)\n");
  2831. $$ = LDST (&$5, &$1, $6.x0, 1, $8.r0, 0);
  2832. }
  2833. | REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK xpmod
  2834. {
  2835. if (!IS_DREG ($1))
  2836. return yyerror ("Dreg expected for destination operand");
  2837. if (!IS_PREG ($5) || !IS_PREG ($7))
  2838. return yyerror ("Preg expected in address");
  2839. notethat ("LDSTpmod: dregs = W [ pregs ++ pregs ] (.)\n");
  2840. $$ = LDSTPMOD (&$5, &$1, &$7, 3, $9.r0);
  2841. }
  2842. | HALF_REG ASSIGN W LBRACK REG _PLUS_PLUS REG RBRACK
  2843. {
  2844. if (!IS_DREG ($1))
  2845. return yyerror ("Dreg expected for destination operand");
  2846. if (!IS_PREG ($5) || !IS_PREG ($7))
  2847. return yyerror ("Preg expected in address");
  2848. notethat ("LDSTpmod: dregs_half = W [ pregs ++ pregs ]\n");
  2849. $$ = LDSTPMOD (&$5, &$1, &$7, 1 + IS_H ($1), 0);
  2850. }
  2851. | LBRACK REG post_op RBRACK ASSIGN REG
  2852. {
  2853. if (!IS_IREG ($2) && !IS_PREG ($2))
  2854. return yyerror ("Ireg or Preg expected in address");
  2855. else if (IS_IREG ($2) && !IS_DREG ($6))
  2856. return yyerror ("Dreg expected for source operand");
  2857. else if (IS_PREG ($2) && !IS_DREG ($6) && !IS_PREG ($6))
  2858. return yyerror ("Dreg or Preg expected for source operand");
  2859. if (IS_IREG ($2))
  2860. {
  2861. notethat ("dspLDST: [ iregs <post_op> ] = dregs\n");
  2862. $$ = DSPLDST(&$2, 0, &$6, $3.x0, 1);
  2863. }
  2864. else if (IS_DREG ($6))
  2865. {
  2866. notethat ("LDST: [ pregs <post_op> ] = dregs\n");
  2867. $$ = LDST (&$2, &$6, $3.x0, 0, 0, 1);
  2868. }
  2869. else
  2870. {
  2871. notethat ("LDST: [ pregs <post_op> ] = pregs\n");
  2872. $$ = LDST (&$2, &$6, $3.x0, 0, 1, 1);
  2873. }
  2874. }
  2875. | LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN REG
  2876. {
  2877. if (!IS_DREG ($7))
  2878. return yyerror ("Dreg expected for source operand");
  2879. if (IS_IREG ($2) && IS_MREG ($4))
  2880. {
  2881. notethat ("dspLDST: [ iregs ++ mregs ] = dregs\n");
  2882. $$ = DSPLDST(&$2, $4.regno & CODE_MASK, &$7, 3, 1);
  2883. }
  2884. else if (IS_PREG ($2) && IS_PREG ($4))
  2885. {
  2886. notethat ("LDSTpmod: [ pregs ++ pregs ] = dregs\n");
  2887. $$ = LDSTPMOD (&$2, &$7, &$4, 0, 1);
  2888. }
  2889. else
  2890. return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
  2891. }
  2892. | W LBRACK REG _PLUS_PLUS REG RBRACK ASSIGN HALF_REG
  2893. {
  2894. if (!IS_DREG ($8))
  2895. return yyerror ("Dreg expected for source operand");
  2896. if (IS_PREG ($3) && IS_PREG ($5))
  2897. {
  2898. notethat ("LDSTpmod: W [ pregs ++ pregs ] = dregs_half\n");
  2899. $$ = LDSTPMOD (&$3, &$8, &$5, 1 + IS_H ($8), 1);
  2900. }
  2901. else
  2902. return yyerror ("Preg ++ Preg expected in address");
  2903. }
  2904. | REG ASSIGN B LBRACK REG plus_minus expr RBRACK xpmod
  2905. {
  2906. Expr_Node *tmp = $7;
  2907. if (!IS_DREG ($1))
  2908. return yyerror ("Dreg expected for destination operand");
  2909. if (!IS_PREG ($5))
  2910. return yyerror ("Preg expected in address");
  2911. if ($6.r0)
  2912. tmp = unary (Expr_Op_Type_NEG, tmp);
  2913. if (IS_RELOC ($7))
  2914. return yyerror ("Plain symbol used as offset");
  2915. if (in_range_p (tmp, -32768, 32767, 0))
  2916. {
  2917. notethat ("LDSTidxI: dregs = B [ pregs + imm16 ] (%c)\n",
  2918. $9.r0 ? 'X' : 'Z');
  2919. $$ = LDSTIDXI (&$5, &$1, 0, 2, $9.r0, tmp);
  2920. }
  2921. else
  2922. return yyerror ("Displacement out of range");
  2923. }
  2924. | REG ASSIGN B LBRACK REG post_op RBRACK xpmod
  2925. {
  2926. if (!IS_DREG ($1))
  2927. return yyerror ("Dreg expected for destination operand");
  2928. if (!IS_PREG ($5))
  2929. return yyerror ("Preg expected in address");
  2930. notethat ("LDST: dregs = B [ pregs <post_op> ] (%c)\n",
  2931. $8.r0 ? 'X' : 'Z');
  2932. $$ = LDST (&$5, &$1, $6.x0, 2, $8.r0, 0);
  2933. }
  2934. | REG ASSIGN LBRACK REG _PLUS_PLUS REG RBRACK
  2935. {
  2936. if (!IS_DREG ($1))
  2937. return yyerror ("Dreg expected for destination operand");
  2938. if (IS_IREG ($4) && IS_MREG ($6))
  2939. {
  2940. notethat ("dspLDST: dregs = [ iregs ++ mregs ]\n");
  2941. $$ = DSPLDST(&$4, $6.regno & CODE_MASK, &$1, 3, 0);
  2942. }
  2943. else if (IS_PREG ($4) && IS_PREG ($6))
  2944. {
  2945. notethat ("LDSTpmod: dregs = [ pregs ++ pregs ]\n");
  2946. $$ = LDSTPMOD (&$4, &$1, &$6, 0, 0);
  2947. }
  2948. else
  2949. return yyerror ("Preg ++ Preg or Ireg ++ Mreg expected in address");
  2950. }
  2951. | REG ASSIGN LBRACK REG plus_minus got_or_expr RBRACK
  2952. {
  2953. Expr_Node *tmp = $6;
  2954. int ispreg = IS_PREG ($1);
  2955. int isgot = IS_RELOC($6);
  2956. if (!IS_PREG ($4))
  2957. return yyerror ("Preg expected in address");
  2958. if (!IS_DREG ($1) && !ispreg)
  2959. return yyerror ("Dreg or Preg expected for destination operand");
  2960. if (tmp->type == Expr_Node_Reloc
  2961. && strcmp (tmp->value.s_value,
  2962. "_current_shared_library_p5_offset_") != 0)
  2963. return yyerror ("Plain symbol used as offset");
  2964. if ($5.r0)
  2965. tmp = unary (Expr_Op_Type_NEG, tmp);
  2966. if (isgot)
  2967. {
  2968. notethat ("LDSTidxI: dpregs = [ pregs + sym@got ]\n");
  2969. $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
  2970. }
  2971. else if (in_range_p (tmp, 0, 63, 3))
  2972. {
  2973. notethat ("LDSTii: dpregs = [ pregs + uimm7m4 ]\n");
  2974. $$ = LDSTII (&$4, &$1, tmp, 0, ispreg ? 3 : 0);
  2975. }
  2976. else if ($4.regno == REG_FP && in_range_p (tmp, -128, 0, 3))
  2977. {
  2978. notethat ("LDSTiiFP: dpregs = [ FP - uimm7m4 ]\n");
  2979. tmp = unary (Expr_Op_Type_NEG, tmp);
  2980. $$ = LDSTIIFP (tmp, &$1, 0);
  2981. }
  2982. else if (in_range_p (tmp, -131072, 131071, 3))
  2983. {
  2984. notethat ("LDSTidxI: dpregs = [ pregs + imm18m4 ]\n");
  2985. $$ = LDSTIDXI (&$4, &$1, 0, 0, ispreg ? 1 : 0, tmp);
  2986. }
  2987. else
  2988. return yyerror ("Displacement out of range");
  2989. }
  2990. | REG ASSIGN LBRACK REG post_op RBRACK
  2991. {
  2992. if (!IS_IREG ($4) && !IS_PREG ($4))
  2993. return yyerror ("Ireg or Preg expected in address");
  2994. else if (IS_IREG ($4) && !IS_DREG ($1))
  2995. return yyerror ("Dreg expected in destination operand");
  2996. else if (IS_PREG ($4) && !IS_DREG ($1) && !IS_PREG ($1)
  2997. && ($4.regno != REG_SP || !IS_ALLREG ($1) || $5.x0 != 0))
  2998. return yyerror ("Dreg or Preg expected in destination operand");
  2999. if (IS_IREG ($4))
  3000. {
  3001. notethat ("dspLDST: dregs = [ iregs <post_op> ]\n");
  3002. $$ = DSPLDST (&$4, 0, &$1, $5.x0, 0);
  3003. }
  3004. else if (IS_DREG ($1))
  3005. {
  3006. notethat ("LDST: dregs = [ pregs <post_op> ]\n");
  3007. $$ = LDST (&$4, &$1, $5.x0, 0, 0, 0);
  3008. }
  3009. else if (IS_PREG ($1))
  3010. {
  3011. if (REG_SAME ($1, $4) && $5.x0 != 2)
  3012. return yyerror ("Pregs can't be same");
  3013. notethat ("LDST: pregs = [ pregs <post_op> ]\n");
  3014. $$ = LDST (&$4, &$1, $5.x0, 0, 1, 0);
  3015. }
  3016. else
  3017. {
  3018. notethat ("PushPopReg: allregs = [ SP ++ ]\n");
  3019. $$ = PUSHPOPREG (&$1, 0);
  3020. }
  3021. }
  3022. /* PushPopMultiple. */
  3023. | reg_with_predec ASSIGN LPAREN REG COLON expr COMMA REG COLON expr RPAREN
  3024. {
  3025. if ($1.regno != REG_SP)
  3026. yyerror ("Stack Pointer expected");
  3027. if ($4.regno == REG_R7
  3028. && IN_RANGE ($6, 0, 7)
  3029. && $8.regno == REG_P5
  3030. && IN_RANGE ($10, 0, 5))
  3031. {
  3032. notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim , P5 : reglim )\n");
  3033. $$ = PUSHPOPMULTIPLE (imm5 ($6), imm5 ($10), 1, 1, 1);
  3034. }
  3035. else
  3036. return yyerror ("Bad register for PushPopMultiple");
  3037. }
  3038. | reg_with_predec ASSIGN LPAREN REG COLON expr RPAREN
  3039. {
  3040. if ($1.regno != REG_SP)
  3041. yyerror ("Stack Pointer expected");
  3042. if ($4.regno == REG_R7 && IN_RANGE ($6, 0, 7))
  3043. {
  3044. notethat ("PushPopMultiple: [ -- SP ] = (R7 : reglim )\n");
  3045. $$ = PUSHPOPMULTIPLE (imm5 ($6), 0, 1, 0, 1);
  3046. }
  3047. else if ($4.regno == REG_P5 && IN_RANGE ($6, 0, 6))
  3048. {
  3049. notethat ("PushPopMultiple: [ -- SP ] = (P5 : reglim )\n");
  3050. $$ = PUSHPOPMULTIPLE (0, imm5 ($6), 0, 1, 1);
  3051. }
  3052. else
  3053. return yyerror ("Bad register for PushPopMultiple");
  3054. }
  3055. | LPAREN REG COLON expr COMMA REG COLON expr RPAREN ASSIGN reg_with_postinc
  3056. {
  3057. if ($11.regno != REG_SP)
  3058. yyerror ("Stack Pointer expected");
  3059. if ($2.regno == REG_R7 && (IN_RANGE ($4, 0, 7))
  3060. && $6.regno == REG_P5 && (IN_RANGE ($8, 0, 6)))
  3061. {
  3062. notethat ("PushPopMultiple: (R7 : reglim , P5 : reglim ) = [ SP ++ ]\n");
  3063. $$ = PUSHPOPMULTIPLE (imm5 ($4), imm5 ($8), 1, 1, 0);
  3064. }
  3065. else
  3066. return yyerror ("Bad register range for PushPopMultiple");
  3067. }
  3068. | LPAREN REG COLON expr RPAREN ASSIGN reg_with_postinc
  3069. {
  3070. if ($7.regno != REG_SP)
  3071. yyerror ("Stack Pointer expected");
  3072. if ($2.regno == REG_R7 && IN_RANGE ($4, 0, 7))
  3073. {
  3074. notethat ("PushPopMultiple: (R7 : reglim ) = [ SP ++ ]\n");
  3075. $$ = PUSHPOPMULTIPLE (imm5 ($4), 0, 1, 0, 0);
  3076. }
  3077. else if ($2.regno == REG_P5 && IN_RANGE ($4, 0, 6))
  3078. {
  3079. notethat ("PushPopMultiple: (P5 : reglim ) = [ SP ++ ]\n");
  3080. $$ = PUSHPOPMULTIPLE (0, imm5 ($4), 0, 1, 0);
  3081. }
  3082. else
  3083. return yyerror ("Bad register range for PushPopMultiple");
  3084. }
  3085. | reg_with_predec ASSIGN REG
  3086. {
  3087. if ($1.regno != REG_SP)
  3088. yyerror ("Stack Pointer expected");
  3089. if (IS_ALLREG ($3))
  3090. {
  3091. notethat ("PushPopReg: [ -- SP ] = allregs\n");
  3092. $$ = PUSHPOPREG (&$3, 1);
  3093. }
  3094. else
  3095. return yyerror ("Bad register for PushPopReg");
  3096. }
  3097. /* Linkage. */
  3098. | LINK expr
  3099. {
  3100. if (IS_URANGE (16, $2, 0, 4))
  3101. $$ = LINKAGE (0, uimm16s4 ($2));
  3102. else
  3103. return yyerror ("Bad constant for LINK");
  3104. }
  3105. | UNLINK
  3106. {
  3107. notethat ("linkage: UNLINK\n");
  3108. $$ = LINKAGE (1, 0);
  3109. }
  3110. /* LSETUP. */
  3111. | LSETUP LPAREN expr COMMA expr RPAREN REG
  3112. {
  3113. if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5) && IS_CREG ($7))
  3114. {
  3115. notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters\n");
  3116. $$ = LOOPSETUP ($3, &$7, 0, $5, 0);
  3117. }
  3118. else
  3119. return yyerror ("Bad register or values for LSETUP");
  3120. }
  3121. | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG
  3122. {
  3123. if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
  3124. && IS_PREG ($9) && IS_CREG ($7))
  3125. {
  3126. notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs\n");
  3127. $$ = LOOPSETUP ($3, &$7, 1, $5, &$9);
  3128. }
  3129. else
  3130. return yyerror ("Bad register or values for LSETUP");
  3131. }
  3132. | LSETUP LPAREN expr COMMA expr RPAREN REG ASSIGN REG GREATER_GREATER expr
  3133. {
  3134. if (IS_PCREL4 ($3) && IS_LPPCREL10 ($5)
  3135. && IS_PREG ($9) && IS_CREG ($7)
  3136. && EXPR_VALUE ($11) == 1)
  3137. {
  3138. notethat ("LoopSetup: LSETUP (pcrel4 , lppcrel10 ) counters = pregs >> 1\n");
  3139. $$ = LOOPSETUP ($3, &$7, 3, $5, &$9);
  3140. }
  3141. else
  3142. return yyerror ("Bad register or values for LSETUP");
  3143. }
  3144. /* LOOP. */
  3145. | LOOP expr REG
  3146. {
  3147. if (!IS_RELOC ($2))
  3148. return yyerror ("Invalid expression in loop statement");
  3149. if (!IS_CREG ($3))
  3150. return yyerror ("Invalid loop counter register");
  3151. $$ = bfin_gen_loop ($2, &$3, 0, 0);
  3152. }
  3153. | LOOP expr REG ASSIGN REG
  3154. {
  3155. if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3))
  3156. {
  3157. notethat ("Loop: LOOP expr counters = pregs\n");
  3158. $$ = bfin_gen_loop ($2, &$3, 1, &$5);
  3159. }
  3160. else
  3161. return yyerror ("Bad register or values for LOOP");
  3162. }
  3163. | LOOP expr REG ASSIGN REG GREATER_GREATER expr
  3164. {
  3165. if (IS_RELOC ($2) && IS_PREG ($5) && IS_CREG ($3) && EXPR_VALUE ($7) == 1)
  3166. {
  3167. notethat ("Loop: LOOP expr counters = pregs >> 1\n");
  3168. $$ = bfin_gen_loop ($2, &$3, 3, &$5);
  3169. }
  3170. else
  3171. return yyerror ("Bad register or values for LOOP");
  3172. }
  3173. /* LOOP_BEGIN. */
  3174. | LOOP_BEGIN NUMBER
  3175. {
  3176. Expr_Node_Value val;
  3177. val.i_value = $2;
  3178. Expr_Node *tmp = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
  3179. bfin_loop_attempt_create_label (tmp, 1);
  3180. if (!IS_RELOC (tmp))
  3181. return yyerror ("Invalid expression in LOOP_BEGIN statement");
  3182. bfin_loop_beginend (tmp, 1);
  3183. $$ = 0;
  3184. }
  3185. | LOOP_BEGIN expr
  3186. {
  3187. if (!IS_RELOC ($2))
  3188. return yyerror ("Invalid expression in LOOP_BEGIN statement");
  3189. bfin_loop_beginend ($2, 1);
  3190. $$ = 0;
  3191. }
  3192. /* LOOP_END. */
  3193. | LOOP_END NUMBER
  3194. {
  3195. Expr_Node_Value val;
  3196. val.i_value = $2;
  3197. Expr_Node *tmp = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
  3198. bfin_loop_attempt_create_label (tmp, 1);
  3199. if (!IS_RELOC (tmp))
  3200. return yyerror ("Invalid expression in LOOP_END statement");
  3201. bfin_loop_beginend (tmp, 0);
  3202. $$ = 0;
  3203. }
  3204. | LOOP_END expr
  3205. {
  3206. if (!IS_RELOC ($2))
  3207. return yyerror ("Invalid expression in LOOP_END statement");
  3208. bfin_loop_beginend ($2, 0);
  3209. $$ = 0;
  3210. }
  3211. /* pseudoDEBUG. */
  3212. | ABORT
  3213. {
  3214. notethat ("psedoDEBUG: ABORT\n");
  3215. $$ = bfin_gen_pseudodbg (3, 3, 0);
  3216. }
  3217. | DBG
  3218. {
  3219. notethat ("pseudoDEBUG: DBG\n");
  3220. $$ = bfin_gen_pseudodbg (3, 7, 0);
  3221. }
  3222. | DBG REG_A
  3223. {
  3224. notethat ("pseudoDEBUG: DBG REG_A\n");
  3225. $$ = bfin_gen_pseudodbg (3, IS_A1 ($2), 0);
  3226. }
  3227. | DBG REG
  3228. {
  3229. notethat ("pseudoDEBUG: DBG allregs\n");
  3230. $$ = bfin_gen_pseudodbg (0, $2.regno & CODE_MASK, ($2.regno & CLASS_MASK) >> 4);
  3231. }
  3232. | DBGCMPLX LPAREN REG RPAREN
  3233. {
  3234. if (!IS_DREG ($3))
  3235. return yyerror ("Dregs expected");
  3236. notethat ("pseudoDEBUG: DBGCMPLX (dregs )\n");
  3237. $$ = bfin_gen_pseudodbg (3, 6, ($3.regno & CODE_MASK) >> 4);
  3238. }
  3239. | DBGHALT
  3240. {
  3241. notethat ("psedoDEBUG: DBGHALT\n");
  3242. $$ = bfin_gen_pseudodbg (3, 5, 0);
  3243. }
  3244. | HLT
  3245. {
  3246. notethat ("psedoDEBUG: HLT\n");
  3247. $$ = bfin_gen_pseudodbg (3, 4, 0);
  3248. }
  3249. | DBGA LPAREN HALF_REG COMMA expr RPAREN
  3250. {
  3251. notethat ("pseudodbg_assert: DBGA (regs_lo/hi , uimm16 )\n");
  3252. $$ = bfin_gen_pseudodbg_assert (IS_H ($3), &$3, uimm16 ($5));
  3253. }
  3254. | DBGAH LPAREN REG COMMA expr RPAREN
  3255. {
  3256. notethat ("pseudodbg_assert: DBGAH (regs , uimm16 )\n");
  3257. $$ = bfin_gen_pseudodbg_assert (3, &$3, uimm16 ($5));
  3258. }
  3259. | DBGAL LPAREN REG COMMA expr RPAREN
  3260. {
  3261. notethat ("psedodbg_assert: DBGAL (regs , uimm16 )\n");
  3262. $$ = bfin_gen_pseudodbg_assert (2, &$3, uimm16 ($5));
  3263. }
  3264. | OUTC expr
  3265. {
  3266. if (!IS_UIMM ($2, 8))
  3267. return yyerror ("Constant out of range");
  3268. notethat ("psedodbg_assert: OUTC uimm8\n");
  3269. $$ = bfin_gen_pseudochr (uimm8 ($2));
  3270. }
  3271. | OUTC REG
  3272. {
  3273. if (!IS_DREG ($2))
  3274. return yyerror ("Dregs expected");
  3275. notethat ("psedodbg_assert: OUTC dreg\n");
  3276. $$ = bfin_gen_pseudodbg (2, $2.regno & CODE_MASK, 0);
  3277. }
  3278. ;
  3279. /* AUX RULES. */
  3280. /* Register rules. */
  3281. REG_A: REG_A_DOUBLE_ZERO
  3282. {
  3283. $$ = $1;
  3284. }
  3285. | REG_A_DOUBLE_ONE
  3286. {
  3287. $$ = $1;
  3288. }
  3289. ;
  3290. /* Modifiers. */
  3291. opt_mode:
  3292. {
  3293. $$.MM = 0;
  3294. $$.mod = 0;
  3295. }
  3296. | LPAREN M COMMA MMOD RPAREN
  3297. {
  3298. $$.MM = 1;
  3299. $$.mod = $4;
  3300. }
  3301. | LPAREN MMOD COMMA M RPAREN
  3302. {
  3303. $$.MM = 1;
  3304. $$.mod = $2;
  3305. }
  3306. | LPAREN MMOD RPAREN
  3307. {
  3308. $$.MM = 0;
  3309. $$.mod = $2;
  3310. }
  3311. | LPAREN M RPAREN
  3312. {
  3313. $$.MM = 1;
  3314. $$.mod = 0;
  3315. }
  3316. ;
  3317. asr_asl: LPAREN ASL RPAREN
  3318. {
  3319. $$.r0 = 1;
  3320. }
  3321. | LPAREN ASR RPAREN
  3322. {
  3323. $$.r0 = 0;
  3324. }
  3325. ;
  3326. sco:
  3327. {
  3328. $$.s0 = 0;
  3329. $$.x0 = 0;
  3330. }
  3331. | S
  3332. {
  3333. $$.s0 = 1;
  3334. $$.x0 = 0;
  3335. }
  3336. | CO
  3337. {
  3338. $$.s0 = 0;
  3339. $$.x0 = 1;
  3340. }
  3341. | SCO
  3342. {
  3343. $$.s0 = 1;
  3344. $$.x0 = 1;
  3345. }
  3346. ;
  3347. asr_asl_0:
  3348. ASL
  3349. {
  3350. $$.r0 = 1;
  3351. }
  3352. | ASR
  3353. {
  3354. $$.r0 = 0;
  3355. }
  3356. ;
  3357. amod0:
  3358. {
  3359. $$.s0 = 0;
  3360. $$.x0 = 0;
  3361. }
  3362. | LPAREN sco RPAREN
  3363. {
  3364. $$.s0 = $2.s0;
  3365. $$.x0 = $2.x0;
  3366. }
  3367. ;
  3368. amod1:
  3369. {
  3370. $$.s0 = 0;
  3371. $$.x0 = 0;
  3372. $$.aop = 0;
  3373. }
  3374. | LPAREN NS RPAREN
  3375. {
  3376. $$.s0 = 0;
  3377. $$.x0 = 0;
  3378. $$.aop = 1;
  3379. }
  3380. | LPAREN S RPAREN
  3381. {
  3382. $$.s0 = 1;
  3383. $$.x0 = 0;
  3384. $$.aop = 1;
  3385. }
  3386. ;
  3387. amod2:
  3388. {
  3389. $$.r0 = 0;
  3390. $$.s0 = 0;
  3391. $$.x0 = 0;
  3392. }
  3393. | LPAREN asr_asl_0 RPAREN
  3394. {
  3395. $$.r0 = 2 + $2.r0;
  3396. $$.s0 = 0;
  3397. $$.x0 = 0;
  3398. }
  3399. | LPAREN sco RPAREN
  3400. {
  3401. $$.r0 = 0;
  3402. $$.s0 = $2.s0;
  3403. $$.x0 = $2.x0;
  3404. }
  3405. | LPAREN asr_asl_0 COMMA sco RPAREN
  3406. {
  3407. $$.r0 = 2 + $2.r0;
  3408. $$.s0 = $4.s0;
  3409. $$.x0 = $4.x0;
  3410. }
  3411. | LPAREN sco COMMA asr_asl_0 RPAREN
  3412. {
  3413. $$.r0 = 2 + $4.r0;
  3414. $$.s0 = $2.s0;
  3415. $$.x0 = $2.x0;
  3416. }
  3417. ;
  3418. xpmod:
  3419. {
  3420. $$.r0 = 0;
  3421. }
  3422. | LPAREN Z RPAREN
  3423. {
  3424. $$.r0 = 0;
  3425. }
  3426. | LPAREN X RPAREN
  3427. {
  3428. $$.r0 = 1;
  3429. }
  3430. ;
  3431. xpmod1:
  3432. {
  3433. $$.r0 = 0;
  3434. }
  3435. | LPAREN X RPAREN
  3436. {
  3437. $$.r0 = 0;
  3438. }
  3439. | LPAREN Z RPAREN
  3440. {
  3441. $$.r0 = 1;
  3442. }
  3443. ;
  3444. vsmod:
  3445. {
  3446. $$.r0 = 0;
  3447. $$.s0 = 0;
  3448. $$.aop = 0;
  3449. }
  3450. | LPAREN NS RPAREN
  3451. {
  3452. $$.r0 = 0;
  3453. $$.s0 = 0;
  3454. $$.aop = 3;
  3455. }
  3456. | LPAREN S RPAREN
  3457. {
  3458. $$.r0 = 0;
  3459. $$.s0 = 1;
  3460. $$.aop = 3;
  3461. }
  3462. | LPAREN V RPAREN
  3463. {
  3464. $$.r0 = 1;
  3465. $$.s0 = 0;
  3466. $$.aop = 3;
  3467. }
  3468. | LPAREN V COMMA S RPAREN
  3469. {
  3470. $$.r0 = 1;
  3471. $$.s0 = 1;
  3472. }
  3473. | LPAREN S COMMA V RPAREN
  3474. {
  3475. $$.r0 = 1;
  3476. $$.s0 = 1;
  3477. }
  3478. ;
  3479. vmod:
  3480. {
  3481. $$.r0 = 0;
  3482. }
  3483. | LPAREN V RPAREN
  3484. {
  3485. $$.r0 = 1;
  3486. }
  3487. ;
  3488. smod:
  3489. {
  3490. $$.s0 = 0;
  3491. }
  3492. | LPAREN S RPAREN
  3493. {
  3494. $$.s0 = 1;
  3495. }
  3496. ;
  3497. searchmod:
  3498. GE
  3499. {
  3500. $$.r0 = 1;
  3501. }
  3502. | GT
  3503. {
  3504. $$.r0 = 0;
  3505. }
  3506. | LE
  3507. {
  3508. $$.r0 = 3;
  3509. }
  3510. | LT
  3511. {
  3512. $$.r0 = 2;
  3513. }
  3514. ;
  3515. aligndir:
  3516. {
  3517. $$.r0 = 0;
  3518. }
  3519. | LPAREN R RPAREN
  3520. {
  3521. $$.r0 = 1;
  3522. }
  3523. ;
  3524. byteop_mod:
  3525. LPAREN R RPAREN
  3526. {
  3527. $$.r0 = 0;
  3528. $$.s0 = 1;
  3529. }
  3530. | LPAREN MMOD RPAREN
  3531. {
  3532. if ($2 != M_T)
  3533. return yyerror ("Bad modifier");
  3534. $$.r0 = 1;
  3535. $$.s0 = 0;
  3536. }
  3537. | LPAREN MMOD COMMA R RPAREN
  3538. {
  3539. if ($2 != M_T)
  3540. return yyerror ("Bad modifier");
  3541. $$.r0 = 1;
  3542. $$.s0 = 1;
  3543. }
  3544. | LPAREN R COMMA MMOD RPAREN
  3545. {
  3546. if ($4 != M_T)
  3547. return yyerror ("Bad modifier");
  3548. $$.r0 = 1;
  3549. $$.s0 = 1;
  3550. }
  3551. ;
  3552. c_align:
  3553. ALIGN8
  3554. {
  3555. $$.r0 = 0;
  3556. }
  3557. | ALIGN16
  3558. {
  3559. $$.r0 = 1;
  3560. }
  3561. | ALIGN24
  3562. {
  3563. $$.r0 = 2;
  3564. }
  3565. ;
  3566. w32_or_nothing:
  3567. {
  3568. $$.r0 = 0;
  3569. }
  3570. | LPAREN MMOD RPAREN
  3571. {
  3572. if ($2 == M_W32)
  3573. $$.r0 = 1;
  3574. else
  3575. return yyerror ("Only (W32) allowed");
  3576. }
  3577. ;
  3578. iu_or_nothing:
  3579. {
  3580. $$.r0 = 1;
  3581. }
  3582. | LPAREN MMOD RPAREN
  3583. {
  3584. if ($2 == M_IU)
  3585. $$.r0 = 3;
  3586. else
  3587. return yyerror ("(IU) expected");
  3588. }
  3589. ;
  3590. reg_with_predec: LBRACK _MINUS_MINUS REG RBRACK
  3591. {
  3592. $$ = $3;
  3593. }
  3594. ;
  3595. reg_with_postinc: LBRACK REG _PLUS_PLUS RBRACK
  3596. {
  3597. $$ = $2;
  3598. }
  3599. ;
  3600. /* Operators. */
  3601. min_max:
  3602. MIN
  3603. {
  3604. $$.r0 = 1;
  3605. }
  3606. | MAX
  3607. {
  3608. $$.r0 = 0;
  3609. }
  3610. ;
  3611. op_bar_op:
  3612. _PLUS_BAR_PLUS
  3613. {
  3614. $$.r0 = 0;
  3615. }
  3616. | _PLUS_BAR_MINUS
  3617. {
  3618. $$.r0 = 1;
  3619. }
  3620. | _MINUS_BAR_PLUS
  3621. {
  3622. $$.r0 = 2;
  3623. }
  3624. | _MINUS_BAR_MINUS
  3625. {
  3626. $$.r0 = 3;
  3627. }
  3628. ;
  3629. plus_minus:
  3630. PLUS
  3631. {
  3632. $$.r0 = 0;
  3633. }
  3634. | MINUS
  3635. {
  3636. $$.r0 = 1;
  3637. }
  3638. ;
  3639. rnd_op:
  3640. LPAREN RNDH RPAREN
  3641. {
  3642. $$.r0 = 1; /* HL. */
  3643. $$.s0 = 0; /* s. */
  3644. $$.x0 = 0; /* x. */
  3645. $$.aop = 0; /* aop. */
  3646. }
  3647. | LPAREN TH RPAREN
  3648. {
  3649. $$.r0 = 1; /* HL. */
  3650. $$.s0 = 0; /* s. */
  3651. $$.x0 = 0; /* x. */
  3652. $$.aop = 1; /* aop. */
  3653. }
  3654. | LPAREN RNDL RPAREN
  3655. {
  3656. $$.r0 = 0; /* HL. */
  3657. $$.s0 = 0; /* s. */
  3658. $$.x0 = 0; /* x. */
  3659. $$.aop = 0; /* aop. */
  3660. }
  3661. | LPAREN TL RPAREN
  3662. {
  3663. $$.r0 = 0; /* HL. */
  3664. $$.s0 = 0; /* s. */
  3665. $$.x0 = 0; /* x. */
  3666. $$.aop = 1;
  3667. }
  3668. | LPAREN RNDH COMMA R RPAREN
  3669. {
  3670. $$.r0 = 1; /* HL. */
  3671. $$.s0 = 1; /* s. */
  3672. $$.x0 = 0; /* x. */
  3673. $$.aop = 0; /* aop. */
  3674. }
  3675. | LPAREN TH COMMA R RPAREN
  3676. {
  3677. $$.r0 = 1; /* HL. */
  3678. $$.s0 = 1; /* s. */
  3679. $$.x0 = 0; /* x. */
  3680. $$.aop = 1; /* aop. */
  3681. }
  3682. | LPAREN RNDL COMMA R RPAREN
  3683. {
  3684. $$.r0 = 0; /* HL. */
  3685. $$.s0 = 1; /* s. */
  3686. $$.x0 = 0; /* x. */
  3687. $$.aop = 0; /* aop. */
  3688. }
  3689. | LPAREN TL COMMA R RPAREN
  3690. {
  3691. $$.r0 = 0; /* HL. */
  3692. $$.s0 = 1; /* s. */
  3693. $$.x0 = 0; /* x. */
  3694. $$.aop = 1; /* aop. */
  3695. }
  3696. ;
  3697. b3_op:
  3698. LPAREN LO RPAREN
  3699. {
  3700. $$.s0 = 0; /* s. */
  3701. $$.x0 = 0; /* HL. */
  3702. }
  3703. | LPAREN HI RPAREN
  3704. {
  3705. $$.s0 = 0; /* s. */
  3706. $$.x0 = 1; /* HL. */
  3707. }
  3708. | LPAREN LO COMMA R RPAREN
  3709. {
  3710. $$.s0 = 1; /* s. */
  3711. $$.x0 = 0; /* HL. */
  3712. }
  3713. | LPAREN HI COMMA R RPAREN
  3714. {
  3715. $$.s0 = 1; /* s. */
  3716. $$.x0 = 1; /* HL. */
  3717. }
  3718. ;
  3719. post_op:
  3720. {
  3721. $$.x0 = 2;
  3722. }
  3723. | _PLUS_PLUS
  3724. {
  3725. $$.x0 = 0;
  3726. }
  3727. | _MINUS_MINUS
  3728. {
  3729. $$.x0 = 1;
  3730. }
  3731. ;
  3732. /* Assignments, Macfuncs. */
  3733. a_assign:
  3734. REG_A ASSIGN
  3735. {
  3736. $$ = $1;
  3737. }
  3738. ;
  3739. a_minusassign:
  3740. REG_A _MINUS_ASSIGN
  3741. {
  3742. $$ = $1;
  3743. }
  3744. ;
  3745. a_plusassign:
  3746. REG_A _PLUS_ASSIGN
  3747. {
  3748. $$ = $1;
  3749. }
  3750. ;
  3751. assign_macfunc:
  3752. REG ASSIGN REG_A
  3753. {
  3754. if (IS_A1 ($3) && IS_EVEN ($1))
  3755. return yyerror ("Cannot move A1 to even register");
  3756. else if (!IS_A1 ($3) && !IS_EVEN ($1))
  3757. return yyerror ("Cannot move A0 to odd register");
  3758. $$.w = 1;
  3759. $$.P = 1;
  3760. $$.n = IS_A1 ($3);
  3761. $$.op = 3;
  3762. $$.dst = $1;
  3763. $$.s0.regno = 0;
  3764. $$.s1.regno = 0;
  3765. }
  3766. | a_macfunc
  3767. {
  3768. $$ = $1;
  3769. $$.w = 0; $$.P = 0;
  3770. $$.dst.regno = 0;
  3771. }
  3772. | REG ASSIGN LPAREN a_macfunc RPAREN
  3773. {
  3774. if ($4.n && IS_EVEN ($1))
  3775. return yyerror ("Cannot move A1 to even register");
  3776. else if (!$4.n && !IS_EVEN ($1))
  3777. return yyerror ("Cannot move A0 to odd register");
  3778. $$ = $4;
  3779. $$.w = 1;
  3780. $$.P = 1;
  3781. $$.dst = $1;
  3782. }
  3783. | HALF_REG ASSIGN LPAREN a_macfunc RPAREN
  3784. {
  3785. if ($4.n && !IS_H ($1))
  3786. return yyerror ("Cannot move A1 to low half of register");
  3787. else if (!$4.n && IS_H ($1))
  3788. return yyerror ("Cannot move A0 to high half of register");
  3789. $$ = $4;
  3790. $$.w = 1;
  3791. $$.P = 0;
  3792. $$.dst = $1;
  3793. }
  3794. | HALF_REG ASSIGN REG_A
  3795. {
  3796. if (IS_A1 ($3) && !IS_H ($1))
  3797. return yyerror ("Cannot move A1 to low half of register");
  3798. else if (!IS_A1 ($3) && IS_H ($1))
  3799. return yyerror ("Cannot move A0 to high half of register");
  3800. $$.w = 1;
  3801. $$.P = 0;
  3802. $$.n = IS_A1 ($3);
  3803. $$.op = 3;
  3804. $$.dst = $1;
  3805. $$.s0.regno = 0;
  3806. $$.s1.regno = 0;
  3807. }
  3808. ;
  3809. a_macfunc:
  3810. a_assign multiply_halfregs
  3811. {
  3812. $$.n = IS_A1 ($1);
  3813. $$.op = 0;
  3814. $$.s0 = $2.s0;
  3815. $$.s1 = $2.s1;
  3816. }
  3817. | a_plusassign multiply_halfregs
  3818. {
  3819. $$.n = IS_A1 ($1);
  3820. $$.op = 1;
  3821. $$.s0 = $2.s0;
  3822. $$.s1 = $2.s1;
  3823. }
  3824. | a_minusassign multiply_halfregs
  3825. {
  3826. $$.n = IS_A1 ($1);
  3827. $$.op = 2;
  3828. $$.s0 = $2.s0;
  3829. $$.s1 = $2.s1;
  3830. }
  3831. ;
  3832. multiply_halfregs:
  3833. HALF_REG STAR HALF_REG
  3834. {
  3835. if (IS_DREG ($1) && IS_DREG ($3))
  3836. {
  3837. $$.s0 = $1;
  3838. $$.s1 = $3;
  3839. }
  3840. else
  3841. return yyerror ("Dregs expected");
  3842. }
  3843. ;
  3844. cc_op:
  3845. ASSIGN
  3846. {
  3847. $$.r0 = 0;
  3848. }
  3849. | _BAR_ASSIGN
  3850. {
  3851. $$.r0 = 1;
  3852. }
  3853. | _AMPERSAND_ASSIGN
  3854. {
  3855. $$.r0 = 2;
  3856. }
  3857. | _CARET_ASSIGN
  3858. {
  3859. $$.r0 = 3;
  3860. }
  3861. ;
  3862. ccstat:
  3863. CCREG cc_op STATUS_REG
  3864. {
  3865. $$.r0 = $3.regno;
  3866. $$.x0 = $2.r0;
  3867. $$.s0 = 0;
  3868. }
  3869. | CCREG cc_op V
  3870. {
  3871. $$.r0 = 0x18;
  3872. $$.x0 = $2.r0;
  3873. $$.s0 = 0;
  3874. }
  3875. | STATUS_REG cc_op CCREG
  3876. {
  3877. $$.r0 = $1.regno;
  3878. $$.x0 = $2.r0;
  3879. $$.s0 = 1;
  3880. }
  3881. | V cc_op CCREG
  3882. {
  3883. $$.r0 = 0x18;
  3884. $$.x0 = $2.r0;
  3885. $$.s0 = 1;
  3886. }
  3887. ;
  3888. /* Expressions and Symbols. */
  3889. symbol: SYMBOL
  3890. {
  3891. Expr_Node_Value val;
  3892. val.s_value = S_GET_NAME($1);
  3893. $$ = Expr_Node_Create (Expr_Node_Reloc, val, NULL, NULL);
  3894. }
  3895. ;
  3896. any_gotrel:
  3897. GOT
  3898. { $$ = BFD_RELOC_BFIN_GOT; }
  3899. | GOT17M4
  3900. { $$ = BFD_RELOC_BFIN_GOT17M4; }
  3901. | FUNCDESC_GOT17M4
  3902. { $$ = BFD_RELOC_BFIN_FUNCDESC_GOT17M4; }
  3903. ;
  3904. got: symbol AT any_gotrel
  3905. {
  3906. Expr_Node_Value val;
  3907. val.i_value = $3;
  3908. $$ = Expr_Node_Create (Expr_Node_GOT_Reloc, val, $1, NULL);
  3909. }
  3910. ;
  3911. got_or_expr: got
  3912. {
  3913. $$ = $1;
  3914. }
  3915. | expr
  3916. {
  3917. $$ = $1;
  3918. }
  3919. ;
  3920. pltpc :
  3921. symbol AT PLTPC
  3922. {
  3923. $$ = $1;
  3924. }
  3925. ;
  3926. eterm: NUMBER
  3927. {
  3928. Expr_Node_Value val;
  3929. val.i_value = $1;
  3930. $$ = Expr_Node_Create (Expr_Node_Constant, val, NULL, NULL);
  3931. }
  3932. | symbol
  3933. {
  3934. $$ = $1;
  3935. }
  3936. | LPAREN expr_1 RPAREN
  3937. {
  3938. $$ = $2;
  3939. }
  3940. | TILDA expr_1
  3941. {
  3942. $$ = unary (Expr_Op_Type_COMP, $2);
  3943. }
  3944. | MINUS expr_1 %prec TILDA
  3945. {
  3946. $$ = unary (Expr_Op_Type_NEG, $2);
  3947. }
  3948. ;
  3949. expr: expr_1
  3950. {
  3951. $$ = $1;
  3952. }
  3953. ;
  3954. expr_1: expr_1 STAR expr_1
  3955. {
  3956. $$ = binary (Expr_Op_Type_Mult, $1, $3);
  3957. }
  3958. | expr_1 SLASH expr_1
  3959. {
  3960. $$ = binary (Expr_Op_Type_Div, $1, $3);
  3961. }
  3962. | expr_1 PERCENT expr_1
  3963. {
  3964. $$ = binary (Expr_Op_Type_Mod, $1, $3);
  3965. }
  3966. | expr_1 PLUS expr_1
  3967. {
  3968. $$ = binary (Expr_Op_Type_Add, $1, $3);
  3969. }
  3970. | expr_1 MINUS expr_1
  3971. {
  3972. $$ = binary (Expr_Op_Type_Sub, $1, $3);
  3973. }
  3974. | expr_1 LESS_LESS expr_1
  3975. {
  3976. $$ = binary (Expr_Op_Type_Lshift, $1, $3);
  3977. }
  3978. | expr_1 GREATER_GREATER expr_1
  3979. {
  3980. $$ = binary (Expr_Op_Type_Rshift, $1, $3);
  3981. }
  3982. | expr_1 AMPERSAND expr_1
  3983. {
  3984. $$ = binary (Expr_Op_Type_BAND, $1, $3);
  3985. }
  3986. | expr_1 CARET expr_1
  3987. {
  3988. $$ = binary (Expr_Op_Type_LOR, $1, $3);
  3989. }
  3990. | expr_1 BAR expr_1
  3991. {
  3992. $$ = binary (Expr_Op_Type_BOR, $1, $3);
  3993. }
  3994. | eterm
  3995. {
  3996. $$ = $1;
  3997. }
  3998. ;
  3999. %%
  4000. EXPR_T
  4001. mkexpr (int x, SYMBOL_T s)
  4002. {
  4003. EXPR_T e = XNEW (struct expression_cell);
  4004. e->value = x;
  4005. EXPR_SYMBOL(e) = s;
  4006. return e;
  4007. }
  4008. static int
  4009. value_match (Expr_Node *exp, int sz, int sign, int mul, int issigned)
  4010. {
  4011. int umax = (1 << sz) - 1;
  4012. int min = -(1 << (sz - 1));
  4013. int max = (1 << (sz - 1)) - 1;
  4014. int v = (EXPR_VALUE (exp)) & 0xffffffff;
  4015. if ((v % mul) != 0)
  4016. {
  4017. error ("%s:%d: Value Error -- Must align to %d\n", __FILE__, __LINE__, mul);
  4018. return 0;
  4019. }
  4020. v /= mul;
  4021. if (sign)
  4022. v = -v;
  4023. if (issigned)
  4024. {
  4025. if (v >= min && v <= max) return 1;
  4026. #ifdef DEBUG
  4027. fprintf(stderr, "signed value %lx out of range\n", v * mul);
  4028. #endif
  4029. return 0;
  4030. }
  4031. if (v <= umax && v >= 0)
  4032. return 1;
  4033. #ifdef DEBUG
  4034. fprintf(stderr, "unsigned value %lx out of range\n", v * mul);
  4035. #endif
  4036. return 0;
  4037. }
  4038. /* Return the expression structure that allows symbol operations.
  4039. If the left and right children are constants, do the operation. */
  4040. static Expr_Node *
  4041. binary (Expr_Op_Type op, Expr_Node *x, Expr_Node *y)
  4042. {
  4043. Expr_Node_Value val;
  4044. if (x->type == Expr_Node_Constant && y->type == Expr_Node_Constant)
  4045. {
  4046. switch (op)
  4047. {
  4048. case Expr_Op_Type_Add:
  4049. x->value.i_value += y->value.i_value;
  4050. break;
  4051. case Expr_Op_Type_Sub:
  4052. x->value.i_value -= y->value.i_value;
  4053. break;
  4054. case Expr_Op_Type_Mult:
  4055. x->value.i_value *= y->value.i_value;
  4056. break;
  4057. case Expr_Op_Type_Div:
  4058. if (y->value.i_value == 0)
  4059. error ("Illegal Expression: Division by zero.");
  4060. else
  4061. x->value.i_value /= y->value.i_value;
  4062. break;
  4063. case Expr_Op_Type_Mod:
  4064. x->value.i_value %= y->value.i_value;
  4065. break;
  4066. case Expr_Op_Type_Lshift:
  4067. x->value.i_value <<= y->value.i_value;
  4068. break;
  4069. case Expr_Op_Type_Rshift:
  4070. x->value.i_value >>= y->value.i_value;
  4071. break;
  4072. case Expr_Op_Type_BAND:
  4073. x->value.i_value &= y->value.i_value;
  4074. break;
  4075. case Expr_Op_Type_BOR:
  4076. x->value.i_value |= y->value.i_value;
  4077. break;
  4078. case Expr_Op_Type_BXOR:
  4079. x->value.i_value ^= y->value.i_value;
  4080. break;
  4081. case Expr_Op_Type_LAND:
  4082. x->value.i_value = x->value.i_value && y->value.i_value;
  4083. break;
  4084. case Expr_Op_Type_LOR:
  4085. x->value.i_value = x->value.i_value || y->value.i_value;
  4086. break;
  4087. default:
  4088. error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
  4089. }
  4090. return x;
  4091. }
  4092. /* Canonicalize order to EXPR OP CONSTANT. */
  4093. if (x->type == Expr_Node_Constant)
  4094. {
  4095. Expr_Node *t = x;
  4096. x = y;
  4097. y = t;
  4098. }
  4099. /* Canonicalize subtraction of const to addition of negated const. */
  4100. if (op == Expr_Op_Type_Sub && y->type == Expr_Node_Constant)
  4101. {
  4102. op = Expr_Op_Type_Add;
  4103. y->value.i_value = -y->value.i_value;
  4104. }
  4105. if (y->type == Expr_Node_Constant && x->type == Expr_Node_Binop
  4106. && x->Right_Child->type == Expr_Node_Constant)
  4107. {
  4108. if (op == x->value.op_value && x->value.op_value == Expr_Op_Type_Add)
  4109. {
  4110. x->Right_Child->value.i_value += y->value.i_value;
  4111. return x;
  4112. }
  4113. }
  4114. /* Create a new expression structure. */
  4115. val.op_value = op;
  4116. return Expr_Node_Create (Expr_Node_Binop, val, x, y);
  4117. }
  4118. static Expr_Node *
  4119. unary (Expr_Op_Type op, Expr_Node *x)
  4120. {
  4121. if (x->type == Expr_Node_Constant)
  4122. {
  4123. switch (op)
  4124. {
  4125. case Expr_Op_Type_NEG:
  4126. x->value.i_value = -x->value.i_value;
  4127. break;
  4128. case Expr_Op_Type_COMP:
  4129. x->value.i_value = ~x->value.i_value;
  4130. break;
  4131. default:
  4132. error ("%s:%d: Internal assembler error\n", __FILE__, __LINE__);
  4133. }
  4134. return x;
  4135. }
  4136. else
  4137. {
  4138. /* Create a new expression structure. */
  4139. Expr_Node_Value val;
  4140. val.op_value = op;
  4141. return Expr_Node_Create (Expr_Node_Unop, val, x, NULL);
  4142. }
  4143. }
  4144. int debug_codeselection = 0;
  4145. static void
  4146. notethat (const char *format, ...)
  4147. {
  4148. va_list ap;
  4149. va_start (ap, format);
  4150. if (debug_codeselection)
  4151. {
  4152. vfprintf (errorf, format, ap);
  4153. }
  4154. va_end (ap);
  4155. }
  4156. #ifdef TEST
  4157. main (int argc, char **argv)
  4158. {
  4159. yyparse();
  4160. }
  4161. #endif