vfpinstr.cpp 138 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123
  1. /*
  2. vfp/vfpinstr.c - ARM VFPv3 emulation unit - Individual instructions data
  3. Copyright (C) 2003 Skyeye Develop Group
  4. for help please send mail to <skyeye-developer@lists.gro.clinux.org>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /* Notice: this file should not be compiled as is, and is meant to be
  18. included in other files only. */
  19. /* ----------------------------------------------------------------------- */
  20. /* CDP instructions */
  21. /* cond 1110 opc1 CRn- CRd- copr op20 CRm- CDP */
  22. /* ----------------------------------------------------------------------- */
  23. /* VMLA */
  24. /* cond 1110 0D00 Vn-- Vd-- 101X N0M0 Vm-- */
  25. #define vfpinstr vmla
  26. #define vfpinstr_inst vmla_inst
  27. #define VFPLABEL_INST VMLA_INST
  28. #ifdef VFP_DECODE
  29. {"vmla", 4, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x0, 9, 11, 0x5, 4, 4, 0},
  30. #endif
  31. #ifdef VFP_DECODE_EXCLUSION
  32. {"vmla", 0, ARMVFP2, 0},
  33. #endif
  34. #ifdef VFP_INTERPRETER_TABLE
  35. INTERPRETER_TRANSLATE(vfpinstr),
  36. #endif
  37. #ifdef VFP_INTERPRETER_LABEL
  38. &&VFPLABEL_INST,
  39. #endif
  40. #ifdef VFP_INTERPRETER_STRUCT
  41. typedef struct _vmla_inst {
  42. unsigned int instr;
  43. unsigned int dp_operation;
  44. } vfpinstr_inst;
  45. #endif
  46. #ifdef VFP_INTERPRETER_TRANS
  47. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  48. {
  49. VFP_DEBUG_TRANSLATE;
  50. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  51. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  52. inst_base->cond = BITS(inst, 28, 31);
  53. inst_base->idx = index;
  54. inst_base->br = NON_BRANCH;
  55. inst_base->load_r15 = 0;
  56. inst_cream->dp_operation = BIT(inst, 8);
  57. inst_cream->instr = inst;
  58. return inst_base;
  59. }
  60. #endif
  61. #ifdef VFP_INTERPRETER_IMPL
  62. VFPLABEL_INST:
  63. {
  64. INC_ICOUNTER;
  65. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  66. CHECK_VFP_ENABLED;
  67. DBG("VMLA :\n");
  68. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  69. int ret;
  70. if (inst_cream->dp_operation)
  71. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  72. else
  73. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  74. CHECK_VFP_CDP_RET;
  75. }
  76. cpu->Reg[15] += GET_INST_SIZE(cpu);
  77. INC_PC(sizeof(vfpinstr_inst));
  78. FETCH_INST;
  79. GOTO_NEXT_INST;
  80. }
  81. #endif
  82. #ifdef VFP_CDP_TRANS
  83. if ((OPC_1 & 0xB) == 0 && (OPC_2 & 0x2) == 0)
  84. {
  85. DBG("VMLA :\n");
  86. }
  87. #endif
  88. #ifdef VFP_DYNCOM_TABLE
  89. DYNCOM_FILL_ACTION(vfpinstr),
  90. #endif
  91. #ifdef VFP_DYNCOM_TAG
  92. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  93. {
  94. int instr_size = INSTR_SIZE;
  95. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  96. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  97. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  98. return instr_size;
  99. }
  100. #endif
  101. #ifdef VFP_DYNCOM_TRANS
  102. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  103. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  104. //arch_arm_undef(cpu, bb, instr);
  105. int m;
  106. int n;
  107. int d ;
  108. int add = (BIT(6) == 0);
  109. int s = BIT(8) == 0;
  110. Value *mm;
  111. Value *nn;
  112. Value *tmp;
  113. if(s){
  114. m = BIT(5) | BITS(0,3) << 1;
  115. n = BIT(7) | BITS(16,19) << 1;
  116. d = BIT(22) | BITS(12,15) << 1;
  117. mm = FR32(m);
  118. nn = FR32(n);
  119. tmp = FPMUL(nn,mm);
  120. if(!add)
  121. tmp = FPNEG32(tmp);
  122. mm = FR32(d);
  123. tmp = FPADD(mm,tmp);
  124. //LETS(d,tmp);
  125. LETFPS(d,tmp);
  126. }else {
  127. m = BITS(0,3) | BIT(5) << 4;
  128. n = BITS(16,19) | BIT(7) << 4;
  129. d = BIT(22) << 4 | BITS(12,15);
  130. //mm = SITOFP(32,RSPR(m));
  131. //LETS(d,tmp);
  132. mm = ZEXT64(IBITCAST32(FR32(2 * m)));
  133. nn = ZEXT64(IBITCAST32(FR32(2 * m + 1)));
  134. tmp = OR(SHL(nn,CONST64(32)),mm);
  135. mm = FPBITCAST64(tmp);
  136. tmp = ZEXT64(IBITCAST32(FR32(2 * n)));
  137. nn = ZEXT64(IBITCAST32(FR32(2 * n + 1)));
  138. nn = OR(SHL(nn,CONST64(32)),tmp);
  139. nn = FPBITCAST64(nn);
  140. tmp = FPMUL(nn,mm);
  141. if(!add)
  142. tmp = FPNEG64(tmp);
  143. mm = ZEXT64(IBITCAST32(FR32(2 * d)));
  144. nn = ZEXT64(IBITCAST32(FR32(2 * d + 1)));
  145. mm = OR(SHL(nn,CONST64(32)),mm);
  146. mm = FPBITCAST64(mm);
  147. tmp = FPADD(mm,tmp);
  148. mm = TRUNC32(LSHR(IBITCAST64(tmp),CONST64(32)));
  149. nn = TRUNC32(AND(IBITCAST64(tmp),CONST64(0xffffffff)));
  150. LETFPS(2*d ,FPBITCAST32(nn));
  151. LETFPS(d*2 + 1 , FPBITCAST32(mm));
  152. }
  153. return No_exp;
  154. }
  155. #endif
  156. #undef vfpinstr
  157. #undef vfpinstr_inst
  158. #undef VFPLABEL_INST
  159. /* ----------------------------------------------------------------------- */
  160. /* VNMLS */
  161. /* cond 1110 0D00 Vn-- Vd-- 101X N1M0 Vm-- */
  162. #define vfpinstr vmls
  163. #define vfpinstr_inst vmls_inst
  164. #define VFPLABEL_INST VMLS_INST
  165. #ifdef VFP_DECODE
  166. {"vmls", 7, ARMVFP2, 28 , 31, 0xF, 25, 27, 0x1, 23, 23, 1, 11, 11, 0, 8, 9, 0x2, 6, 6, 1, 4, 4, 0},
  167. #endif
  168. #ifdef VFP_DECODE_EXCLUSION
  169. {"vmls", 0, ARMVFP2, 0},
  170. #endif
  171. #ifdef VFP_INTERPRETER_TABLE
  172. INTERPRETER_TRANSLATE(vfpinstr),
  173. #endif
  174. #ifdef VFP_INTERPRETER_LABEL
  175. &&VFPLABEL_INST,
  176. #endif
  177. #ifdef VFP_INTERPRETER_STRUCT
  178. typedef struct _vmls_inst {
  179. unsigned int instr;
  180. unsigned int dp_operation;
  181. } vfpinstr_inst;
  182. #endif
  183. #ifdef VFP_INTERPRETER_TRANS
  184. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  185. {
  186. VFP_DEBUG_TRANSLATE;
  187. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  188. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  189. inst_base->cond = BITS(inst, 28, 31);
  190. inst_base->idx = index;
  191. inst_base->br = NON_BRANCH;
  192. inst_base->load_r15 = 0;
  193. inst_cream->dp_operation = BIT(inst, 8);
  194. inst_cream->instr = inst;
  195. return inst_base;
  196. }
  197. #endif
  198. #ifdef VFP_INTERPRETER_IMPL
  199. VFPLABEL_INST:
  200. {
  201. INC_ICOUNTER;
  202. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  203. CHECK_VFP_ENABLED;
  204. DBG("VMLS :\n");
  205. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  206. int ret;
  207. if (inst_cream->dp_operation)
  208. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  209. else
  210. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  211. CHECK_VFP_CDP_RET;
  212. }
  213. cpu->Reg[15] += GET_INST_SIZE(cpu);
  214. INC_PC(sizeof(vfpinstr_inst));
  215. FETCH_INST;
  216. GOTO_NEXT_INST;
  217. }
  218. #endif
  219. #ifdef VFP_CDP_TRANS
  220. if ((OPC_1 & 0xB) == 0 && (OPC_2 & 0x2) == 2)
  221. {
  222. DBG("VMLS :\n");
  223. }
  224. #endif
  225. #ifdef VFP_DYNCOM_TABLE
  226. DYNCOM_FILL_ACTION(vfpinstr),
  227. #endif
  228. #ifdef VFP_DYNCOM_TAG
  229. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  230. {
  231. int instr_size = INSTR_SIZE;
  232. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  233. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  234. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  235. return instr_size;
  236. }
  237. #endif
  238. #ifdef VFP_DYNCOM_TRANS
  239. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  240. DBG("\t\tin %s VMLS instruction is executed out of here.\n", __FUNCTION__);
  241. //arch_arm_undef(cpu, bb, instr);
  242. int m;
  243. int n;
  244. int d ;
  245. int add = (BIT(6) == 0);
  246. int s = BIT(8) == 0;
  247. Value *mm;
  248. Value *nn;
  249. Value *tmp;
  250. if(s){
  251. m = BIT(5) | BITS(0,3) << 1;
  252. n = BIT(7) | BITS(16,19) << 1;
  253. d = BIT(22) | BITS(12,15) << 1;
  254. mm = FR32(m);
  255. nn = FR32(n);
  256. tmp = FPMUL(nn,mm);
  257. if(!add)
  258. tmp = FPNEG32(tmp);
  259. mm = FR32(d);
  260. tmp = FPADD(mm,tmp);
  261. //LETS(d,tmp);
  262. LETFPS(d,tmp);
  263. }else {
  264. m = BITS(0,3) | BIT(5) << 4;
  265. n = BITS(16,19) | BIT(7) << 4;
  266. d = BIT(22) << 4 | BITS(12,15);
  267. //mm = SITOFP(32,RSPR(m));
  268. //LETS(d,tmp);
  269. mm = ZEXT64(IBITCAST32(FR32(2 * m)));
  270. nn = ZEXT64(IBITCAST32(FR32(2 * m + 1)));
  271. tmp = OR(SHL(nn,CONST64(32)),mm);
  272. mm = FPBITCAST64(tmp);
  273. tmp = ZEXT64(IBITCAST32(FR32(2 * n)));
  274. nn = ZEXT64(IBITCAST32(FR32(2 * n + 1)));
  275. nn = OR(SHL(nn,CONST64(32)),tmp);
  276. nn = FPBITCAST64(nn);
  277. tmp = FPMUL(nn,mm);
  278. if(!add)
  279. tmp = FPNEG64(tmp);
  280. mm = ZEXT64(IBITCAST32(FR32(2 * d)));
  281. nn = ZEXT64(IBITCAST32(FR32(2 * d + 1)));
  282. mm = OR(SHL(nn,CONST64(32)),mm);
  283. mm = FPBITCAST64(mm);
  284. tmp = FPADD(mm,tmp);
  285. mm = TRUNC32(LSHR(IBITCAST64(tmp),CONST64(32)));
  286. nn = TRUNC32(AND(IBITCAST64(tmp),CONST64(0xffffffff)));
  287. LETFPS(2*d ,FPBITCAST32(nn));
  288. LETFPS(d*2 + 1 , FPBITCAST32(mm));
  289. }
  290. return No_exp;
  291. }
  292. #endif
  293. #undef vfpinstr
  294. #undef vfpinstr_inst
  295. #undef VFPLABEL_INST
  296. /* ----------------------------------------------------------------------- */
  297. /* VNMLA */
  298. /* cond 1110 0D01 Vn-- Vd-- 101X N1M0 Vm-- */
  299. #define vfpinstr vnmla
  300. #define vfpinstr_inst vnmla_inst
  301. #define VFPLABEL_INST VNMLA_INST
  302. #ifdef VFP_DECODE
  303. //{"vnmla", 5, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x0, 9, 11, 0x5, 6, 6, 1, 4, 4, 0},
  304. {"vnmla", 4, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x1, 9, 11, 0x5, 4, 4, 0},
  305. {"vnmla", 5, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x2, 9, 11, 0x5, 6, 6, 1, 4, 4, 0},
  306. //{"vnmla", 5, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x2, 9, 11, 0x5, 6, 6, 1, 4, 4, 0},
  307. #endif
  308. #ifdef VFP_DECODE_EXCLUSION
  309. {"vnmla", 0, ARMVFP2, 0},
  310. {"vnmla", 0, ARMVFP2, 0},
  311. #endif
  312. #ifdef VFP_INTERPRETER_TABLE
  313. INTERPRETER_TRANSLATE(vfpinstr),
  314. INTERPRETER_TRANSLATE(vfpinstr),
  315. #endif
  316. #ifdef VFP_INTERPRETER_LABEL
  317. &&VFPLABEL_INST,
  318. &&VFPLABEL_INST,
  319. #endif
  320. #ifdef VFP_INTERPRETER_STRUCT
  321. typedef struct _vnmla_inst {
  322. unsigned int instr;
  323. unsigned int dp_operation;
  324. } vfpinstr_inst;
  325. #endif
  326. #ifdef VFP_INTERPRETER_TRANS
  327. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  328. {
  329. VFP_DEBUG_TRANSLATE;
  330. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  331. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  332. inst_base->cond = BITS(inst, 28, 31);
  333. inst_base->idx = index;
  334. inst_base->br = NON_BRANCH;
  335. inst_base->load_r15 = 0;
  336. inst_cream->dp_operation = BIT(inst, 8);
  337. inst_cream->instr = inst;
  338. return inst_base;
  339. }
  340. #endif
  341. #ifdef VFP_INTERPRETER_IMPL
  342. VFPLABEL_INST:
  343. {
  344. INC_ICOUNTER;
  345. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  346. CHECK_VFP_ENABLED;
  347. DBG("VNMLA :\n");
  348. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  349. int ret;
  350. if (inst_cream->dp_operation)
  351. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  352. else
  353. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  354. CHECK_VFP_CDP_RET;
  355. }
  356. cpu->Reg[15] += GET_INST_SIZE(cpu);
  357. INC_PC(sizeof(vfpinstr_inst));
  358. FETCH_INST;
  359. GOTO_NEXT_INST;
  360. }
  361. #endif
  362. #ifdef VFP_CDP_TRANS
  363. if ((OPC_1 & 0xB) == 1 && (OPC_2 & 0x2) == 2)
  364. {
  365. DBG("VNMLA :\n");
  366. }
  367. #endif
  368. #ifdef VFP_DYNCOM_TABLE
  369. DYNCOM_FILL_ACTION(vfpinstr),
  370. DYNCOM_FILL_ACTION(vfpinstr),
  371. #endif
  372. #ifdef VFP_DYNCOM_TAG
  373. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  374. {
  375. int instr_size = INSTR_SIZE;
  376. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  377. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  378. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  379. return instr_size;
  380. }
  381. #endif
  382. #ifdef VFP_DYNCOM_TRANS
  383. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  384. DBG("\t\tin %s VNMLA instruction is executed out of here.\n", __FUNCTION__);
  385. //arch_arm_undef(cpu, bb, instr);
  386. int m;
  387. int n;
  388. int d ;
  389. int add = (BIT(6) == 0);
  390. int s = BIT(8) == 0;
  391. Value *mm;
  392. Value *nn;
  393. Value *tmp;
  394. if(s){
  395. m = BIT(5) | BITS(0,3) << 1;
  396. n = BIT(7) | BITS(16,19) << 1;
  397. d = BIT(22) | BITS(12,15) << 1;
  398. mm = FR32(m);
  399. nn = FR32(n);
  400. tmp = FPMUL(nn,mm);
  401. if(!add)
  402. tmp = FPNEG32(tmp);
  403. mm = FR32(d);
  404. tmp = FPADD(FPNEG32(mm),tmp);
  405. //LETS(d,tmp);
  406. LETFPS(d,tmp);
  407. }else {
  408. m = BITS(0,3) | BIT(5) << 4;
  409. n = BITS(16,19) | BIT(7) << 4;
  410. d = BIT(22) << 4 | BITS(12,15);
  411. //mm = SITOFP(32,RSPR(m));
  412. //LETS(d,tmp);
  413. mm = ZEXT64(IBITCAST32(FR32(2 * m)));
  414. nn = ZEXT64(IBITCAST32(FR32(2 * m + 1)));
  415. tmp = OR(SHL(nn,CONST64(32)),mm);
  416. mm = FPBITCAST64(tmp);
  417. tmp = ZEXT64(IBITCAST32(FR32(2 * n)));
  418. nn = ZEXT64(IBITCAST32(FR32(2 * n + 1)));
  419. nn = OR(SHL(nn,CONST64(32)),tmp);
  420. nn = FPBITCAST64(nn);
  421. tmp = FPMUL(nn,mm);
  422. if(!add)
  423. tmp = FPNEG64(tmp);
  424. mm = ZEXT64(IBITCAST32(FR32(2 * d)));
  425. nn = ZEXT64(IBITCAST32(FR32(2 * d + 1)));
  426. mm = OR(SHL(nn,CONST64(32)),mm);
  427. mm = FPBITCAST64(mm);
  428. tmp = FPADD(FPNEG64(mm),tmp);
  429. mm = TRUNC32(LSHR(IBITCAST64(tmp),CONST64(32)));
  430. nn = TRUNC32(AND(IBITCAST64(tmp),CONST64(0xffffffff)));
  431. LETFPS(2*d ,FPBITCAST32(nn));
  432. LETFPS(d*2 + 1 , FPBITCAST32(mm));
  433. }
  434. return No_exp;
  435. }
  436. #endif
  437. #undef vfpinstr
  438. #undef vfpinstr_inst
  439. #undef VFPLABEL_INST
  440. /* ----------------------------------------------------------------------- */
  441. /* VNMLS */
  442. /* cond 1110 0D01 Vn-- Vd-- 101X N0M0 Vm-- */
  443. #define vfpinstr vnmls
  444. #define vfpinstr_inst vnmls_inst
  445. #define VFPLABEL_INST VNMLS_INST
  446. #ifdef VFP_DECODE
  447. {"vnmls", 5, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x1, 9, 11, 0x5, 6, 6, 0, 4, 4, 0},
  448. #endif
  449. #ifdef VFP_DECODE_EXCLUSION
  450. {"vnmls", 0, ARMVFP2, 0},
  451. #endif
  452. #ifdef VFP_INTERPRETER_TABLE
  453. INTERPRETER_TRANSLATE(vfpinstr),
  454. #endif
  455. #ifdef VFP_INTERPRETER_LABEL
  456. &&VFPLABEL_INST,
  457. #endif
  458. #ifdef VFP_INTERPRETER_STRUCT
  459. typedef struct _vnmls_inst {
  460. unsigned int instr;
  461. unsigned int dp_operation;
  462. } vfpinstr_inst;
  463. #endif
  464. #ifdef VFP_INTERPRETER_TRANS
  465. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  466. {
  467. VFP_DEBUG_TRANSLATE;
  468. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  469. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  470. inst_base->cond = BITS(inst, 28, 31);
  471. inst_base->idx = index;
  472. inst_base->br = NON_BRANCH;
  473. inst_base->load_r15 = 0;
  474. inst_cream->dp_operation = BIT(inst, 8);
  475. inst_cream->instr = inst;
  476. return inst_base;
  477. }
  478. #endif
  479. #ifdef VFP_INTERPRETER_IMPL
  480. VFPLABEL_INST:
  481. {
  482. INC_ICOUNTER;
  483. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  484. CHECK_VFP_ENABLED;
  485. DBG("VNMLS :\n");
  486. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  487. int ret;
  488. if (inst_cream->dp_operation)
  489. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  490. else
  491. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  492. CHECK_VFP_CDP_RET;
  493. }
  494. cpu->Reg[15] += GET_INST_SIZE(cpu);
  495. INC_PC(sizeof(vfpinstr_inst));
  496. FETCH_INST;
  497. GOTO_NEXT_INST;
  498. }
  499. #endif
  500. #ifdef VFP_CDP_TRANS
  501. if ((OPC_1 & 0xB) == 1 && (OPC_2 & 0x2) == 0)
  502. {
  503. DBG("VNMLS :\n");
  504. }
  505. #endif
  506. #ifdef VFP_DYNCOM_TABLE
  507. DYNCOM_FILL_ACTION(vfpinstr),
  508. #endif
  509. #ifdef VFP_DYNCOM_TAG
  510. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  511. {
  512. int instr_size = INSTR_SIZE;
  513. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  514. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  515. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  516. return instr_size;
  517. }
  518. #endif
  519. #ifdef VFP_DYNCOM_TRANS
  520. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  521. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  522. //arch_arm_undef(cpu, bb, instr);
  523. int m;
  524. int n;
  525. int d ;
  526. int add = (BIT(6) == 0);
  527. int s = BIT(8) == 0;
  528. Value *mm;
  529. Value *nn;
  530. Value *tmp;
  531. if(s){
  532. m = BIT(5) | BITS(0,3) << 1;
  533. n = BIT(7) | BITS(16,19) << 1;
  534. d = BIT(22) | BITS(12,15) << 1;
  535. mm = FR32(m);
  536. nn = FR32(n);
  537. tmp = FPMUL(nn,mm);
  538. if(!add)
  539. tmp = FPNEG32(tmp);
  540. mm = FR32(d);
  541. tmp = FPADD(FPNEG32(mm),tmp);
  542. //LETS(d,tmp);
  543. LETFPS(d,tmp);
  544. }else {
  545. m = BITS(0,3) | BIT(5) << 4;
  546. n = BITS(16,19) | BIT(7) << 4;
  547. d = BIT(22) << 4 | BITS(12,15);
  548. //mm = SITOFP(32,RSPR(m));
  549. //LETS(d,tmp);
  550. mm = ZEXT64(IBITCAST32(FR32(2 * m)));
  551. nn = ZEXT64(IBITCAST32(FR32(2 * m + 1)));
  552. tmp = OR(SHL(nn,CONST64(32)),mm);
  553. mm = FPBITCAST64(tmp);
  554. tmp = ZEXT64(IBITCAST32(FR32(2 * n)));
  555. nn = ZEXT64(IBITCAST32(FR32(2 * n + 1)));
  556. nn = OR(SHL(nn,CONST64(32)),tmp);
  557. nn = FPBITCAST64(nn);
  558. tmp = FPMUL(nn,mm);
  559. if(!add)
  560. tmp = FPNEG64(tmp);
  561. mm = ZEXT64(IBITCAST32(FR32(2 * d)));
  562. nn = ZEXT64(IBITCAST32(FR32(2 * d + 1)));
  563. mm = OR(SHL(nn,CONST64(32)),mm);
  564. mm = FPBITCAST64(mm);
  565. tmp = FPADD(FPNEG64(mm),tmp);
  566. mm = TRUNC32(LSHR(IBITCAST64(tmp),CONST64(32)));
  567. nn = TRUNC32(AND(IBITCAST64(tmp),CONST64(0xffffffff)));
  568. LETFPS(2*d ,FPBITCAST32(nn));
  569. LETFPS(d*2 + 1 , FPBITCAST32(mm));
  570. }
  571. return No_exp;
  572. }
  573. #endif
  574. #undef vfpinstr
  575. #undef vfpinstr_inst
  576. #undef VFPLABEL_INST
  577. /* ----------------------------------------------------------------------- */
  578. /* VNMUL */
  579. /* cond 1110 0D10 Vn-- Vd-- 101X N0M0 Vm-- */
  580. #define vfpinstr vnmul
  581. #define vfpinstr_inst vnmul_inst
  582. #define VFPLABEL_INST VNMUL_INST
  583. #ifdef VFP_DECODE
  584. {"vnmul", 5, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x2, 9, 11, 0x5, 6, 6, 1, 4, 4, 0},
  585. #endif
  586. #ifdef VFP_DECODE_EXCLUSION
  587. {"vnmul", 0, ARMVFP2, 0},
  588. #endif
  589. #ifdef VFP_INTERPRETER_TABLE
  590. INTERPRETER_TRANSLATE(vfpinstr),
  591. #endif
  592. #ifdef VFP_INTERPRETER_LABEL
  593. &&VFPLABEL_INST,
  594. #endif
  595. #ifdef VFP_INTERPRETER_STRUCT
  596. typedef struct _vnmul_inst {
  597. unsigned int instr;
  598. unsigned int dp_operation;
  599. } vfpinstr_inst;
  600. #endif
  601. #ifdef VFP_INTERPRETER_TRANS
  602. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  603. {
  604. VFP_DEBUG_TRANSLATE;
  605. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  606. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  607. inst_base->cond = BITS(inst, 28, 31);
  608. inst_base->idx = index;
  609. inst_base->br = NON_BRANCH;
  610. inst_base->load_r15 = 0;
  611. inst_cream->dp_operation = BIT(inst, 8);
  612. inst_cream->instr = inst;
  613. return inst_base;
  614. }
  615. #endif
  616. #ifdef VFP_INTERPRETER_IMPL
  617. VFPLABEL_INST:
  618. {
  619. INC_ICOUNTER;
  620. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  621. CHECK_VFP_ENABLED;
  622. DBG("VNMUL :\n");
  623. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  624. int ret;
  625. if (inst_cream->dp_operation)
  626. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  627. else
  628. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  629. CHECK_VFP_CDP_RET;
  630. }
  631. cpu->Reg[15] += GET_INST_SIZE(cpu);
  632. INC_PC(sizeof(vfpinstr_inst));
  633. FETCH_INST;
  634. GOTO_NEXT_INST;
  635. }
  636. #endif
  637. #ifdef VFP_CDP_TRANS
  638. if ((OPC_1 & 0xB) == 2 && (OPC_2 & 0x2) == 2)
  639. {
  640. DBG("VNMUL :\n");
  641. }
  642. #endif
  643. #ifdef VFP_DYNCOM_TABLE
  644. DYNCOM_FILL_ACTION(vfpinstr),
  645. #endif
  646. #ifdef VFP_DYNCOM_TAG
  647. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  648. {
  649. int instr_size = INSTR_SIZE;
  650. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  651. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  652. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  653. return instr_size;
  654. }
  655. #endif
  656. #ifdef VFP_DYNCOM_TRANS
  657. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  658. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  659. //arch_arm_undef(cpu, bb, instr);
  660. int m;
  661. int n;
  662. int d ;
  663. int add = (BIT(6) == 0);
  664. int s = BIT(8) == 0;
  665. Value *mm;
  666. Value *nn;
  667. Value *tmp;
  668. if(s){
  669. m = BIT(5) | BITS(0,3) << 1;
  670. n = BIT(7) | BITS(16,19) << 1;
  671. d = BIT(22) | BITS(12,15) << 1;
  672. mm = FR32(m);
  673. nn = FR32(n);
  674. tmp = FPMUL(nn,mm);
  675. //LETS(d,tmp);
  676. LETFPS(d,FPNEG32(tmp));
  677. }else {
  678. m = BITS(0,3) | BIT(5) << 4;
  679. n = BITS(16,19) | BIT(7) << 4;
  680. d = BIT(22) << 4 | BITS(12,15);
  681. //mm = SITOFP(32,RSPR(m));
  682. //LETS(d,tmp);
  683. mm = ZEXT64(IBITCAST32(FR32(2 * m)));
  684. nn = ZEXT64(IBITCAST32(FR32(2 * m + 1)));
  685. tmp = OR(SHL(nn,CONST64(32)),mm);
  686. mm = FPBITCAST64(tmp);
  687. tmp = ZEXT64(IBITCAST32(FR32(2 * n)));
  688. nn = ZEXT64(IBITCAST32(FR32(2 * n + 1)));
  689. nn = OR(SHL(nn,CONST64(32)),tmp);
  690. nn = FPBITCAST64(nn);
  691. tmp = FPMUL(nn,mm);
  692. tmp = FPNEG64(tmp);
  693. mm = TRUNC32(LSHR(IBITCAST64(tmp),CONST64(32)));
  694. nn = TRUNC32(AND(IBITCAST64(tmp),CONST64(0xffffffff)));
  695. LETFPS(2*d ,FPBITCAST32(nn));
  696. LETFPS(d*2 + 1 , FPBITCAST32(mm));
  697. }
  698. return No_exp;
  699. }
  700. #endif
  701. #undef vfpinstr
  702. #undef vfpinstr_inst
  703. #undef VFPLABEL_INST
  704. /* ----------------------------------------------------------------------- */
  705. /* VMUL */
  706. /* cond 1110 0D10 Vn-- Vd-- 101X N0M0 Vm-- */
  707. #define vfpinstr vmul
  708. #define vfpinstr_inst vmul_inst
  709. #define VFPLABEL_INST VMUL_INST
  710. #ifdef VFP_DECODE
  711. {"vmul", 5, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x2, 9, 11, 0x5, 6, 6, 0, 4, 4, 0},
  712. #endif
  713. #ifdef VFP_DECODE_EXCLUSION
  714. {"vmul", 0, ARMVFP2, 0},
  715. #endif
  716. #ifdef VFP_INTERPRETER_TABLE
  717. INTERPRETER_TRANSLATE(vfpinstr),
  718. #endif
  719. #ifdef VFP_INTERPRETER_LABEL
  720. &&VFPLABEL_INST,
  721. #endif
  722. #ifdef VFP_INTERPRETER_STRUCT
  723. typedef struct _vmul_inst {
  724. unsigned int instr;
  725. unsigned int dp_operation;
  726. } vfpinstr_inst;
  727. #endif
  728. #ifdef VFP_INTERPRETER_TRANS
  729. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  730. {
  731. VFP_DEBUG_TRANSLATE;
  732. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  733. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  734. inst_base->cond = BITS(inst, 28, 31);
  735. inst_base->idx = index;
  736. inst_base->br = NON_BRANCH;
  737. inst_base->load_r15 = 0;
  738. inst_cream->dp_operation = BIT(inst, 8);
  739. inst_cream->instr = inst;
  740. return inst_base;
  741. }
  742. #endif
  743. #ifdef VFP_INTERPRETER_IMPL
  744. VFPLABEL_INST:
  745. {
  746. INC_ICOUNTER;
  747. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  748. CHECK_VFP_ENABLED;
  749. DBG("VMUL :\n");
  750. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  751. int ret;
  752. if (inst_cream->dp_operation)
  753. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  754. else
  755. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  756. CHECK_VFP_CDP_RET;
  757. }
  758. cpu->Reg[15] += GET_INST_SIZE(cpu);
  759. INC_PC(sizeof(vfpinstr_inst));
  760. FETCH_INST;
  761. GOTO_NEXT_INST;
  762. }
  763. #endif
  764. #ifdef VFP_CDP_TRANS
  765. if ((OPC_1 & 0xB) == 2 && (OPC_2 & 0x2) == 0)
  766. {
  767. DBG("VMUL :\n");
  768. }
  769. #endif
  770. #ifdef VFP_DYNCOM_TABLE
  771. DYNCOM_FILL_ACTION(vfpinstr),
  772. #endif
  773. #ifdef VFP_DYNCOM_TAG
  774. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  775. {
  776. int instr_size = INSTR_SIZE;
  777. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  778. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  779. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  780. return instr_size;
  781. }
  782. #endif
  783. #ifdef VFP_DYNCOM_TRANS
  784. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  785. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  786. //printf("\n\n\t\tin %s instruction is executed out.\n\n", __FUNCTION__);
  787. //arch_arm_undef(cpu, bb, instr);
  788. int m;
  789. int n;
  790. int d ;
  791. int s = BIT(8) == 0;
  792. Value *mm;
  793. Value *nn;
  794. Value *tmp;
  795. if(s){
  796. m = BIT(5) | BITS(0,3) << 1;
  797. n = BIT(7) | BITS(16,19) << 1;
  798. d = BIT(22) | BITS(12,15) << 1;
  799. //mm = SITOFP(32,FR(m));
  800. //nn = SITOFP(32,FRn));
  801. mm = FR32(m);
  802. nn = FR32(n);
  803. tmp = FPMUL(nn,mm);
  804. //LETS(d,tmp);
  805. LETFPS(d,tmp);
  806. }else {
  807. m = BITS(0,3) | BIT(5) << 4;
  808. n = BITS(16,19) | BIT(7) << 4;
  809. d = BIT(22) << 4 | BITS(12,15);
  810. //mm = SITOFP(32,RSPR(m));
  811. //LETS(d,tmp);
  812. Value *lo = FR32(2 * m);
  813. Value *hi = FR32(2 * m + 1);
  814. hi = IBITCAST32(hi);
  815. lo = IBITCAST32(lo);
  816. Value *hi64 = ZEXT64(hi);
  817. Value* lo64 = ZEXT64(lo);
  818. Value* v64 = OR(SHL(hi64,CONST64(32)),lo64);
  819. Value* m0 = FPBITCAST64(v64);
  820. lo = FR32(2 * n);
  821. hi = FR32(2 * n + 1);
  822. hi = IBITCAST32(hi);
  823. lo = IBITCAST32(lo);
  824. hi64 = ZEXT64(hi);
  825. lo64 = ZEXT64(lo);
  826. v64 = OR(SHL(hi64,CONST64(32)),lo64);
  827. Value *n0 = FPBITCAST64(v64);
  828. tmp = FPMUL(n0,m0);
  829. Value *val64 = IBITCAST64(tmp);
  830. hi = LSHR(val64,CONST64(32));
  831. lo = AND(val64,CONST64(0xffffffff));
  832. hi = TRUNC32(hi);
  833. lo = TRUNC32(lo);
  834. hi = FPBITCAST32(hi);
  835. lo = FPBITCAST32(lo);
  836. LETFPS(2*d ,lo);
  837. LETFPS(d*2 + 1 , hi);
  838. }
  839. return No_exp;
  840. }
  841. #endif
  842. #undef vfpinstr
  843. #undef vfpinstr_inst
  844. #undef VFPLABEL_INST
  845. /* ----------------------------------------------------------------------- */
  846. /* VADD */
  847. /* cond 1110 0D11 Vn-- Vd-- 101X N0M0 Vm-- */
  848. #define vfpinstr vadd
  849. #define vfpinstr_inst vadd_inst
  850. #define VFPLABEL_INST VADD_INST
  851. #ifdef VFP_DECODE
  852. {"vadd", 5, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x3, 9, 11, 0x5, 6, 6, 0, 4, 4, 0},
  853. #endif
  854. #ifdef VFP_DECODE_EXCLUSION
  855. {"vadd", 0, ARMVFP2, 0},
  856. #endif
  857. #ifdef VFP_INTERPRETER_TABLE
  858. INTERPRETER_TRANSLATE(vfpinstr),
  859. #endif
  860. #ifdef VFP_INTERPRETER_LABEL
  861. &&VFPLABEL_INST,
  862. #endif
  863. #ifdef VFP_INTERPRETER_STRUCT
  864. typedef struct _vadd_inst {
  865. unsigned int instr;
  866. unsigned int dp_operation;
  867. } vfpinstr_inst;
  868. #endif
  869. #ifdef VFP_INTERPRETER_TRANS
  870. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  871. {
  872. VFP_DEBUG_TRANSLATE;
  873. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  874. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  875. inst_base->cond = BITS(inst, 28, 31);
  876. inst_base->idx = index;
  877. inst_base->br = NON_BRANCH;
  878. inst_base->load_r15 = 0;
  879. inst_cream->dp_operation = BIT(inst, 8);
  880. inst_cream->instr = inst;
  881. return inst_base;
  882. }
  883. #endif
  884. #ifdef VFP_INTERPRETER_IMPL
  885. VFPLABEL_INST:
  886. {
  887. INC_ICOUNTER;
  888. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  889. CHECK_VFP_ENABLED;
  890. DBG("VADD :\n");
  891. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  892. int ret;
  893. if (inst_cream->dp_operation)
  894. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  895. else
  896. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  897. CHECK_VFP_CDP_RET;
  898. }
  899. cpu->Reg[15] += GET_INST_SIZE(cpu);
  900. INC_PC(sizeof(vfpinstr_inst));
  901. FETCH_INST;
  902. GOTO_NEXT_INST;
  903. }
  904. #endif
  905. #ifdef VFP_CDP_TRANS
  906. if ((OPC_1 & 0xB) == 3 && (OPC_2 & 0x2) == 0)
  907. {
  908. DBG("VADD :\n");
  909. }
  910. #endif
  911. #ifdef VFP_DYNCOM_TABLE
  912. DYNCOM_FILL_ACTION(vfpinstr),
  913. #endif
  914. #ifdef VFP_DYNCOM_TAG
  915. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  916. {
  917. int instr_size = INSTR_SIZE;
  918. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  919. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  920. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  921. return instr_size;
  922. }
  923. #endif
  924. #ifdef VFP_DYNCOM_TRANS
  925. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  926. DBG("\t\tin %s instruction will implement out of JIT.\n", __FUNCTION__);
  927. //arch_arm_undef(cpu, bb, instr);
  928. int m;
  929. int n;
  930. int d ;
  931. int s = BIT(8) == 0;
  932. Value *mm;
  933. Value *nn;
  934. Value *tmp;
  935. if(s){
  936. m = BIT(5) | BITS(0,3) << 1;
  937. n = BIT(7) | BITS(16,19) << 1;
  938. d = BIT(22) | BITS(12,15) << 1;
  939. mm = FR32(m);
  940. nn = FR32(n);
  941. tmp = FPADD(nn,mm);
  942. LETFPS(d,tmp);
  943. }else {
  944. m = BITS(0,3) | BIT(5) << 4;
  945. n = BITS(16,19) | BIT(7) << 4;
  946. d = BIT(22) << 4 | BITS(12,15);
  947. Value *lo = FR32(2 * m);
  948. Value *hi = FR32(2 * m + 1);
  949. hi = IBITCAST32(hi);
  950. lo = IBITCAST32(lo);
  951. Value *hi64 = ZEXT64(hi);
  952. Value* lo64 = ZEXT64(lo);
  953. Value* v64 = OR(SHL(hi64,CONST64(32)),lo64);
  954. Value* m0 = FPBITCAST64(v64);
  955. lo = FR32(2 * n);
  956. hi = FR32(2 * n + 1);
  957. hi = IBITCAST32(hi);
  958. lo = IBITCAST32(lo);
  959. hi64 = ZEXT64(hi);
  960. lo64 = ZEXT64(lo);
  961. v64 = OR(SHL(hi64,CONST64(32)),lo64);
  962. Value *n0 = FPBITCAST64(v64);
  963. tmp = FPADD(n0,m0);
  964. Value *val64 = IBITCAST64(tmp);
  965. hi = LSHR(val64,CONST64(32));
  966. lo = AND(val64,CONST64(0xffffffff));
  967. hi = TRUNC32(hi);
  968. lo = TRUNC32(lo);
  969. hi = FPBITCAST32(hi);
  970. lo = FPBITCAST32(lo);
  971. LETFPS(2*d ,lo);
  972. LETFPS(d*2 + 1 , hi);
  973. }
  974. return No_exp;
  975. }
  976. #endif
  977. #undef vfpinstr
  978. #undef vfpinstr_inst
  979. #undef VFPLABEL_INST
  980. /* ----------------------------------------------------------------------- */
  981. /* VSUB */
  982. /* cond 1110 0D11 Vn-- Vd-- 101X N1M0 Vm-- */
  983. #define vfpinstr vsub
  984. #define vfpinstr_inst vsub_inst
  985. #define VFPLABEL_INST VSUB_INST
  986. #ifdef VFP_DECODE
  987. {"vsub", 5, ARMVFP2, 23, 27, 0x1c, 20, 21, 0x3, 9, 11, 0x5, 6, 6, 1, 4, 4, 0},
  988. #endif
  989. #ifdef VFP_DECODE_EXCLUSION
  990. {"vsub", 0, ARMVFP2, 0},
  991. #endif
  992. #ifdef VFP_INTERPRETER_TABLE
  993. INTERPRETER_TRANSLATE(vfpinstr),
  994. #endif
  995. #ifdef VFP_INTERPRETER_LABEL
  996. &&VFPLABEL_INST,
  997. #endif
  998. #ifdef VFP_INTERPRETER_STRUCT
  999. typedef struct _vsub_inst {
  1000. unsigned int instr;
  1001. unsigned int dp_operation;
  1002. } vfpinstr_inst;
  1003. #endif
  1004. #ifdef VFP_INTERPRETER_TRANS
  1005. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  1006. {
  1007. VFP_DEBUG_TRANSLATE;
  1008. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  1009. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1010. inst_base->cond = BITS(inst, 28, 31);
  1011. inst_base->idx = index;
  1012. inst_base->br = NON_BRANCH;
  1013. inst_base->load_r15 = 0;
  1014. inst_cream->dp_operation = BIT(inst, 8);
  1015. inst_cream->instr = inst;
  1016. return inst_base;
  1017. }
  1018. #endif
  1019. #ifdef VFP_INTERPRETER_IMPL
  1020. VFPLABEL_INST:
  1021. {
  1022. INC_ICOUNTER;
  1023. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  1024. CHECK_VFP_ENABLED;
  1025. DBG("VSUB :\n");
  1026. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1027. int ret;
  1028. if (inst_cream->dp_operation)
  1029. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1030. else
  1031. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1032. CHECK_VFP_CDP_RET;
  1033. }
  1034. cpu->Reg[15] += GET_INST_SIZE(cpu);
  1035. INC_PC(sizeof(vfpinstr_inst));
  1036. FETCH_INST;
  1037. GOTO_NEXT_INST;
  1038. }
  1039. #endif
  1040. #ifdef VFP_CDP_TRANS
  1041. if ((OPC_1 & 0xB) == 3 && (OPC_2 & 0x2) == 2)
  1042. {
  1043. DBG("VSUB :\n");
  1044. }
  1045. #endif
  1046. #ifdef VFP_DYNCOM_TABLE
  1047. DYNCOM_FILL_ACTION(vfpinstr),
  1048. #endif
  1049. #ifdef VFP_DYNCOM_TAG
  1050. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  1051. {
  1052. int instr_size = INSTR_SIZE;
  1053. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  1054. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  1055. return instr_size;
  1056. }
  1057. #endif
  1058. #ifdef VFP_DYNCOM_TRANS
  1059. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  1060. DBG("\t\tin %s instr=0x%x, instruction is executed out of JIT.\n", __FUNCTION__, instr);
  1061. //arch_arm_undef(cpu, bb, instr);
  1062. int m;
  1063. int n;
  1064. int d ;
  1065. int s = BIT(8) == 0;
  1066. Value *mm;
  1067. Value *nn;
  1068. Value *tmp;
  1069. if(s){
  1070. m = BIT(5) | BITS(0,3) << 1;
  1071. n = BIT(7) | BITS(16,19) << 1;
  1072. d = BIT(22) | BITS(12,15) << 1;
  1073. mm = FR32(m);
  1074. nn = FR32(n);
  1075. tmp = FPSUB(nn,mm);
  1076. LETFPS(d,tmp);
  1077. }else {
  1078. m = BITS(0,3) | BIT(5) << 4;
  1079. n = BITS(16,19) | BIT(7) << 4;
  1080. d = BIT(22) << 4 | BITS(12,15);
  1081. Value *lo = FR32(2 * m);
  1082. Value *hi = FR32(2 * m + 1);
  1083. hi = IBITCAST32(hi);
  1084. lo = IBITCAST32(lo);
  1085. Value *hi64 = ZEXT64(hi);
  1086. Value* lo64 = ZEXT64(lo);
  1087. Value* v64 = OR(SHL(hi64,CONST64(32)),lo64);
  1088. Value* m0 = FPBITCAST64(v64);
  1089. lo = FR32(2 * n);
  1090. hi = FR32(2 * n + 1);
  1091. hi = IBITCAST32(hi);
  1092. lo = IBITCAST32(lo);
  1093. hi64 = ZEXT64(hi);
  1094. lo64 = ZEXT64(lo);
  1095. v64 = OR(SHL(hi64,CONST64(32)),lo64);
  1096. Value *n0 = FPBITCAST64(v64);
  1097. tmp = FPSUB(n0,m0);
  1098. Value *val64 = IBITCAST64(tmp);
  1099. hi = LSHR(val64,CONST64(32));
  1100. lo = AND(val64,CONST64(0xffffffff));
  1101. hi = TRUNC32(hi);
  1102. lo = TRUNC32(lo);
  1103. hi = FPBITCAST32(hi);
  1104. lo = FPBITCAST32(lo);
  1105. LETFPS(2*d ,lo);
  1106. LETFPS(d*2 + 1 , hi);
  1107. }
  1108. return No_exp;
  1109. }
  1110. #endif
  1111. #undef vfpinstr
  1112. #undef vfpinstr_inst
  1113. #undef VFPLABEL_INST
  1114. /* ----------------------------------------------------------------------- */
  1115. /* VDIV */
  1116. /* cond 1110 1D00 Vn-- Vd-- 101X N0M0 Vm-- */
  1117. #define vfpinstr vdiv
  1118. #define vfpinstr_inst vdiv_inst
  1119. #define VFPLABEL_INST VDIV_INST
  1120. #ifdef VFP_DECODE
  1121. {"vdiv", 5, ARMVFP2, 23, 27, 0x1d, 20, 21, 0x0, 9, 11, 0x5, 6, 6, 0, 4, 4, 0},
  1122. #endif
  1123. #ifdef VFP_DECODE_EXCLUSION
  1124. {"vdiv", 0, ARMVFP2, 0},
  1125. #endif
  1126. #ifdef VFP_INTERPRETER_TABLE
  1127. INTERPRETER_TRANSLATE(vfpinstr),
  1128. #endif
  1129. #ifdef VFP_INTERPRETER_LABEL
  1130. &&VFPLABEL_INST,
  1131. #endif
  1132. #ifdef VFP_INTERPRETER_STRUCT
  1133. typedef struct _vdiv_inst {
  1134. unsigned int instr;
  1135. unsigned int dp_operation;
  1136. } vfpinstr_inst;
  1137. #endif
  1138. #ifdef VFP_INTERPRETER_TRANS
  1139. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  1140. {
  1141. VFP_DEBUG_TRANSLATE;
  1142. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  1143. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1144. inst_base->cond = BITS(inst, 28, 31);
  1145. inst_base->idx = index;
  1146. inst_base->br = NON_BRANCH;
  1147. inst_base->load_r15 = 0;
  1148. inst_cream->dp_operation = BIT(inst, 8);
  1149. inst_cream->instr = inst;
  1150. return inst_base;
  1151. }
  1152. #endif
  1153. #ifdef VFP_INTERPRETER_IMPL
  1154. VFPLABEL_INST:
  1155. {
  1156. INC_ICOUNTER;
  1157. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  1158. CHECK_VFP_ENABLED;
  1159. DBG("VDIV :\n");
  1160. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1161. int ret;
  1162. if (inst_cream->dp_operation)
  1163. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1164. else
  1165. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1166. CHECK_VFP_CDP_RET;
  1167. }
  1168. cpu->Reg[15] += GET_INST_SIZE(cpu);
  1169. INC_PC(sizeof(vfpinstr_inst));
  1170. FETCH_INST;
  1171. GOTO_NEXT_INST;
  1172. }
  1173. #endif
  1174. #ifdef VFP_CDP_TRANS
  1175. if ((OPC_1 & 0xB) == 0xA && (OPC_2 & 0x2) == 0)
  1176. {
  1177. DBG("VDIV :\n");
  1178. }
  1179. #endif
  1180. #ifdef VFP_DYNCOM_TABLE
  1181. DYNCOM_FILL_ACTION(vfpinstr),
  1182. #endif
  1183. #ifdef VFP_DYNCOM_TAG
  1184. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  1185. {
  1186. int instr_size = INSTR_SIZE;
  1187. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1188. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  1189. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  1190. return instr_size;
  1191. }
  1192. #endif
  1193. #ifdef VFP_DYNCOM_TRANS
  1194. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  1195. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1196. //arch_arm_undef(cpu, bb, instr);
  1197. int m;
  1198. int n;
  1199. int d ;
  1200. int s = BIT(8) == 0;
  1201. Value *mm;
  1202. Value *nn;
  1203. Value *tmp;
  1204. if(s){
  1205. m = BIT(5) | BITS(0,3) << 1;
  1206. n = BIT(7) | BITS(16,19) << 1;
  1207. d = BIT(22) | BITS(12,15) << 1;
  1208. mm = FR32(m);
  1209. nn = FR32(n);
  1210. tmp = FPDIV(nn,mm);
  1211. LETFPS(d,tmp);
  1212. }else {
  1213. m = BITS(0,3) | BIT(5) << 4;
  1214. n = BITS(16,19) | BIT(7) << 4;
  1215. d = BIT(22) << 4 | BITS(12,15);
  1216. Value *lo = FR32(2 * m);
  1217. Value *hi = FR32(2 * m + 1);
  1218. hi = IBITCAST32(hi);
  1219. lo = IBITCAST32(lo);
  1220. Value *hi64 = ZEXT64(hi);
  1221. Value* lo64 = ZEXT64(lo);
  1222. Value* v64 = OR(SHL(hi64,CONST64(32)),lo64);
  1223. Value* m0 = FPBITCAST64(v64);
  1224. lo = FR32(2 * n);
  1225. hi = FR32(2 * n + 1);
  1226. hi = IBITCAST32(hi);
  1227. lo = IBITCAST32(lo);
  1228. hi64 = ZEXT64(hi);
  1229. lo64 = ZEXT64(lo);
  1230. v64 = OR(SHL(hi64,CONST64(32)),lo64);
  1231. Value *n0 = FPBITCAST64(v64);
  1232. tmp = FPDIV(n0,m0);
  1233. Value *val64 = IBITCAST64(tmp);
  1234. hi = LSHR(val64,CONST64(32));
  1235. lo = AND(val64,CONST64(0xffffffff));
  1236. hi = TRUNC32(hi);
  1237. lo = TRUNC32(lo);
  1238. hi = FPBITCAST32(hi);
  1239. lo = FPBITCAST32(lo);
  1240. LETFPS(2*d ,lo);
  1241. LETFPS(d*2 + 1 , hi);
  1242. }
  1243. return No_exp;
  1244. }
  1245. #endif
  1246. #undef vfpinstr
  1247. #undef vfpinstr_inst
  1248. #undef VFPLABEL_INST
  1249. /* ----------------------------------------------------------------------- */
  1250. /* VMOVI move immediate */
  1251. /* cond 1110 1D11 im4H Vd-- 101X 0000 im4L */
  1252. /* cond 1110 opc1 CRn- CRd- copr op20 CRm- CDP */
  1253. #define vfpinstr vmovi
  1254. #define vfpinstr_inst vmovi_inst
  1255. #define VFPLABEL_INST VMOVI_INST
  1256. #ifdef VFP_DECODE
  1257. {"vmov(i)", 4, ARMVFP3, 23, 27, 0x1d, 20, 21, 0x3, 9, 11, 0x5, 4, 7, 0},
  1258. #endif
  1259. #ifdef VFP_DECODE_EXCLUSION
  1260. {"vmov(i)", 0, ARMVFP3, 0},
  1261. #endif
  1262. #ifdef VFP_INTERPRETER_TABLE
  1263. INTERPRETER_TRANSLATE(vfpinstr),
  1264. #endif
  1265. #ifdef VFP_INTERPRETER_LABEL
  1266. &&VFPLABEL_INST,
  1267. #endif
  1268. #ifdef VFP_INTERPRETER_STRUCT
  1269. typedef struct _vmovi_inst {
  1270. unsigned int single;
  1271. unsigned int d;
  1272. unsigned int imm;
  1273. } vfpinstr_inst;
  1274. #endif
  1275. #ifdef VFP_INTERPRETER_TRANS
  1276. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  1277. {
  1278. VFP_DEBUG_TRANSLATE;
  1279. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  1280. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1281. inst_base->cond = BITS(inst, 28, 31);
  1282. inst_base->idx = index;
  1283. inst_base->br = NON_BRANCH;
  1284. inst_base->load_r15 = 0;
  1285. inst_cream->single = BIT(inst, 8) == 0;
  1286. inst_cream->d = (inst_cream->single ? BITS(inst,12,15)<<1 | BIT(inst,22) : BITS(inst,12,15) | BIT(inst,22)<<4);
  1287. unsigned int imm8 = BITS(inst, 16, 19) << 4 | BITS(inst, 0, 3);
  1288. if (inst_cream->single)
  1289. inst_cream->imm = BIT(imm8, 7)<<31 | (BIT(imm8, 6)==0)<<30 | (BIT(imm8, 6) ? 0x1f : 0)<<25 | BITS(imm8, 0, 5)<<19;
  1290. else
  1291. inst_cream->imm = BIT(imm8, 7)<<31 | (BIT(imm8, 6)==0)<<30 | (BIT(imm8, 6) ? 0xff : 0)<<22 | BITS(imm8, 0, 5)<<16;
  1292. return inst_base;
  1293. }
  1294. #endif
  1295. #ifdef VFP_INTERPRETER_IMPL
  1296. VFPLABEL_INST:
  1297. {
  1298. INC_ICOUNTER;
  1299. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  1300. CHECK_VFP_ENABLED;
  1301. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1302. VMOVI(cpu, inst_cream->single, inst_cream->d, inst_cream->imm);
  1303. }
  1304. cpu->Reg[15] += GET_INST_SIZE(cpu);
  1305. INC_PC(sizeof(vfpinstr_inst));
  1306. FETCH_INST;
  1307. GOTO_NEXT_INST;
  1308. }
  1309. #endif
  1310. #ifdef VFP_CDP_TRANS
  1311. if ( (OPC_1 & 0xb) == 0xb && BITS(4, 7) == 0)
  1312. {
  1313. unsigned int single = BIT(8) == 0;
  1314. unsigned int d = (single ? BITS(12,15)<<1 | BIT(22) : BITS(12,15) | BIT(22)<<4);
  1315. unsigned int imm;
  1316. instr = BITS(16, 19) << 4 | BITS(0, 3); /* FIXME dirty workaround to get a correct imm */
  1317. if (single) {
  1318. imm = BIT(7)<<31 | (BIT(6)==0)<<30 | (BIT(6) ? 0x1f : 0)<<25 | BITS(0, 5)<<19;
  1319. } else {
  1320. imm = BIT(7)<<31 | (BIT(6)==0)<<30 | (BIT(6) ? 0xff : 0)<<22 | BITS(0, 5)<<16;
  1321. }
  1322. VMOVI(state, single, d, imm);
  1323. return ARMul_DONE;
  1324. }
  1325. #endif
  1326. #ifdef VFP_CDP_IMPL
  1327. void VMOVI(ARMul_State * state, ARMword single, ARMword d, ARMword imm)
  1328. {
  1329. DBG("VMOV(I) :\n");
  1330. if (single)
  1331. {
  1332. DBG("\ts%d <= [%x]\n", d, imm);
  1333. state->ExtReg[d] = imm;
  1334. }
  1335. else
  1336. {
  1337. /* Check endian please */
  1338. DBG("\ts[%d-%d] <= [%x-%x]\n", d*2+1, d*2, imm, 0);
  1339. state->ExtReg[d*2+1] = imm;
  1340. state->ExtReg[d*2] = 0;
  1341. }
  1342. }
  1343. #endif
  1344. #ifdef VFP_DYNCOM_TABLE
  1345. DYNCOM_FILL_ACTION(vfpinstr),
  1346. #endif
  1347. #ifdef VFP_DYNCOM_TAG
  1348. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  1349. {
  1350. int instr_size = INSTR_SIZE;
  1351. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1352. arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  1353. return instr_size;
  1354. }
  1355. #endif
  1356. #ifdef VFP_DYNCOM_TRANS
  1357. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  1358. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1359. //arch_arm_undef(cpu, bb, instr);
  1360. int single = (BIT(8) == 0);
  1361. int d;
  1362. int imm32;
  1363. Value *v;
  1364. Value *tmp;
  1365. v = CONST32(BITS(0,3) | BITS(16,19) << 4);
  1366. //v = CONST64(0x3ff0000000000000);
  1367. if(single){
  1368. d = BIT(22) | BITS(12,15) << 1;
  1369. }else {
  1370. d = BITS(12,15) | BIT(22) << 4;
  1371. }
  1372. if(single){
  1373. LETFPS(d,FPBITCAST32(v));
  1374. }else {
  1375. //v = UITOFP(64,v);
  1376. //tmp = IBITCAST64(v);
  1377. LETFPS(d*2 ,FPBITCAST32(TRUNC32(AND(v,CONST64(0xffffffff)))));
  1378. LETFPS(d * 2 + 1,FPBITCAST32(TRUNC32(LSHR(v,CONST64(32)))));
  1379. }
  1380. return No_exp;
  1381. }
  1382. #endif
  1383. #undef vfpinstr
  1384. #undef vfpinstr_inst
  1385. #undef VFPLABEL_INST
  1386. /* ----------------------------------------------------------------------- */
  1387. /* VMOVR move register */
  1388. /* cond 1110 1D11 0000 Vd-- 101X 01M0 Vm-- */
  1389. /* cond 1110 opc1 CRn- CRd- copr op20 CRm- CDP */
  1390. #define vfpinstr vmovr
  1391. #define vfpinstr_inst vmovr_inst
  1392. #define VFPLABEL_INST VMOVR_INST
  1393. #ifdef VFP_DECODE
  1394. {"vmov(r)", 5, ARMVFP3, 23, 27, 0x1d, 16, 21, 0x30, 9, 11, 0x5, 6, 7, 1, 4, 4, 0},
  1395. #endif
  1396. #ifdef VFP_DECODE_EXCLUSION
  1397. {"vmov(r)", 0, ARMVFP3, 0},
  1398. #endif
  1399. #ifdef VFP_INTERPRETER_TABLE
  1400. INTERPRETER_TRANSLATE(vfpinstr),
  1401. #endif
  1402. #ifdef VFP_INTERPRETER_LABEL
  1403. &&VFPLABEL_INST,
  1404. #endif
  1405. #ifdef VFP_INTERPRETER_STRUCT
  1406. typedef struct _vmovr_inst {
  1407. unsigned int single;
  1408. unsigned int d;
  1409. unsigned int m;
  1410. } vfpinstr_inst;
  1411. #endif
  1412. #ifdef VFP_INTERPRETER_TRANS
  1413. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  1414. {
  1415. VFP_DEBUG_TRANSLATE;
  1416. VFP_DEBUG_UNTESTED(VMOVR);
  1417. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  1418. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1419. inst_base->cond = BITS(inst, 28, 31);
  1420. inst_base->idx = index;
  1421. inst_base->br = NON_BRANCH;
  1422. inst_base->load_r15 = 0;
  1423. inst_cream->single = BIT(inst, 8) == 0;
  1424. inst_cream->d = (inst_cream->single ? BITS(inst,12,15)<<1 | BIT(inst,22) : BITS(inst,12,15) | BIT(inst,22)<<4);
  1425. inst_cream->m = (inst_cream->single ? BITS(inst, 0, 3)<<1 | BIT(inst, 5) : BITS(inst, 0, 3) | BIT(inst, 5)<<4);
  1426. return inst_base;
  1427. }
  1428. #endif
  1429. #ifdef VFP_INTERPRETER_IMPL
  1430. VFPLABEL_INST:
  1431. {
  1432. INC_ICOUNTER;
  1433. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  1434. CHECK_VFP_ENABLED;
  1435. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1436. VMOVR(cpu, inst_cream->single, inst_cream->d, inst_cream->m);
  1437. }
  1438. cpu->Reg[15] += GET_INST_SIZE(cpu);
  1439. INC_PC(sizeof(vfpinstr_inst));
  1440. FETCH_INST;
  1441. GOTO_NEXT_INST;
  1442. }
  1443. #endif
  1444. #ifdef VFP_CDP_TRANS
  1445. if ( (OPC_1 & 0xb) == 0xb && CRn == 0 && (OPC_2 & 0x6) == 0x2 )
  1446. {
  1447. unsigned int single = BIT(8) == 0;
  1448. unsigned int d = (single ? BITS(12,15)<<1 | BIT(22) : BITS(12,15) | BIT(22)<<4);
  1449. unsigned int m = (single ? BITS( 0, 3)<<1 | BIT( 5) : BITS( 0, 3) | BIT( 5)<<4);;
  1450. VMOVR(state, single, d, m);
  1451. return ARMul_DONE;
  1452. }
  1453. #endif
  1454. #ifdef VFP_CDP_IMPL
  1455. void VMOVR(ARMul_State * state, ARMword single, ARMword d, ARMword m)
  1456. {
  1457. DBG("VMOV(R) :\n");
  1458. if (single)
  1459. {
  1460. DBG("\ts%d <= s%d[%x]\n", d, m, state->ExtReg[m]);
  1461. state->ExtReg[d] = state->ExtReg[m];
  1462. }
  1463. else
  1464. {
  1465. /* Check endian please */
  1466. DBG("\ts[%d-%d] <= s[%d-%d][%x-%x]\n", d*2+1, d*2, m*2+1, m*2, state->ExtReg[m*2+1], state->ExtReg[m*2]);
  1467. state->ExtReg[d*2+1] = state->ExtReg[m*2+1];
  1468. state->ExtReg[d*2] = state->ExtReg[m*2];
  1469. }
  1470. }
  1471. #endif
  1472. #ifdef VFP_DYNCOM_TABLE
  1473. DYNCOM_FILL_ACTION(vfpinstr),
  1474. #endif
  1475. #ifdef VFP_DYNCOM_TAG
  1476. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  1477. {
  1478. int instr_size = INSTR_SIZE;
  1479. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  1480. DBG("In %s, pc=0x%x, next_pc=0x%x\n", __FUNCTION__, pc, *next_pc);
  1481. if(instr >> 28 != 0xe)
  1482. *tag |= TAG_CONDITIONAL;
  1483. return instr_size;
  1484. }
  1485. #endif
  1486. #ifdef VFP_DYNCOM_TRANS
  1487. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  1488. DBG("\t\tin %s VMOV \n", __FUNCTION__);
  1489. int single = BIT(8) == 0;
  1490. int d = (single ? BITS(12,15)<<1 | BIT(22) : BIT(22) << 4 | BITS(12,15));
  1491. int m = (single ? BITS(0, 3)<<1 | BIT(5) : BITS(0, 3) | BIT(5)<<4);
  1492. if (single)
  1493. {
  1494. LETFPS(d, FR32(m));
  1495. }
  1496. else
  1497. {
  1498. /* Check endian please */
  1499. LETFPS((d*2 + 1), FR32(m*2 + 1));
  1500. LETFPS((d * 2), FR32(m * 2));
  1501. }
  1502. return No_exp;
  1503. }
  1504. #endif
  1505. #undef vfpinstr
  1506. #undef vfpinstr_inst
  1507. #undef VFPLABEL_INST
  1508. /* ----------------------------------------------------------------------- */
  1509. /* VABS */
  1510. /* cond 1110 1D11 0000 Vd-- 101X 11M0 Vm-- */
  1511. #define vfpinstr vabs
  1512. #define vfpinstr_inst vabs_inst
  1513. #define VFPLABEL_INST VABS_INST
  1514. #ifdef VFP_DECODE
  1515. {"vabs", 5, ARMVFP2, 23, 27, 0x1d, 16, 21, 0x30, 9, 11, 0x5, 6, 7, 3, 4, 4, 0},
  1516. #endif
  1517. #ifdef VFP_DECODE_EXCLUSION
  1518. {"vabs", 0, ARMVFP2, 0},
  1519. #endif
  1520. #ifdef VFP_INTERPRETER_TABLE
  1521. INTERPRETER_TRANSLATE(vfpinstr),
  1522. #endif
  1523. #ifdef VFP_INTERPRETER_LABEL
  1524. &&VFPLABEL_INST,
  1525. #endif
  1526. #ifdef VFP_INTERPRETER_STRUCT
  1527. typedef struct _vabs_inst {
  1528. unsigned int instr;
  1529. unsigned int dp_operation;
  1530. } vfpinstr_inst;
  1531. #endif
  1532. #ifdef VFP_INTERPRETER_TRANS
  1533. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  1534. {
  1535. VFP_DEBUG_TRANSLATE;VFP_DEBUG_UNTESTED(VABS);
  1536. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  1537. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1538. inst_base->cond = BITS(inst, 28, 31);
  1539. inst_base->idx = index;
  1540. inst_base->br = NON_BRANCH;
  1541. inst_base->load_r15 = 0;
  1542. inst_cream->dp_operation = BIT(inst, 8);
  1543. inst_cream->instr = inst;
  1544. return inst_base;
  1545. }
  1546. #endif
  1547. #ifdef VFP_INTERPRETER_IMPL
  1548. VFPLABEL_INST:
  1549. {
  1550. INC_ICOUNTER;
  1551. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  1552. CHECK_VFP_ENABLED;
  1553. DBG("VABS :\n");
  1554. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1555. int ret;
  1556. if (inst_cream->dp_operation)
  1557. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1558. else
  1559. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1560. CHECK_VFP_CDP_RET;
  1561. }
  1562. cpu->Reg[15] += GET_INST_SIZE(cpu);
  1563. INC_PC(sizeof(vfpinstr_inst));
  1564. FETCH_INST;
  1565. GOTO_NEXT_INST;
  1566. }
  1567. #endif
  1568. #ifdef VFP_CDP_TRANS
  1569. if ((OPC_1 & 0xB) == 0xB && CRn == 0 && (OPC_2 & 0x7) == 6)
  1570. {
  1571. DBG("VABS :\n");
  1572. }
  1573. #endif
  1574. #ifdef VFP_DYNCOM_TABLE
  1575. DYNCOM_FILL_ACTION(vfpinstr),
  1576. #endif
  1577. #ifdef VFP_DYNCOM_TAG
  1578. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  1579. {
  1580. int instr_size = INSTR_SIZE;
  1581. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1582. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  1583. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  1584. return instr_size;
  1585. }
  1586. #endif
  1587. #ifdef VFP_DYNCOM_TRANS
  1588. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  1589. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1590. //arch_arm_undef(cpu, bb, instr);
  1591. int single = BIT(8) == 0;
  1592. int d = (single ? BITS(12,15)<<1 | BIT(22) : BIT(22) << 4 | BITS(12,15));
  1593. int m = (single ? BITS(0, 3)<<1 | BIT(5) : BITS(0, 3) | BIT(5)<<4);
  1594. Value* m0;
  1595. if (single)
  1596. {
  1597. m0 = FR32(m);
  1598. m0 = SELECT(FPCMP_OLT(m0,FPCONST32(0.0)),FPNEG32(m0),m0);
  1599. LETFPS(d,m0);
  1600. }
  1601. else
  1602. {
  1603. /* Check endian please */
  1604. Value *lo = FR32(2 * m);
  1605. Value *hi = FR32(2 * m + 1);
  1606. hi = IBITCAST32(hi);
  1607. lo = IBITCAST32(lo);
  1608. Value *hi64 = ZEXT64(hi);
  1609. Value* lo64 = ZEXT64(lo);
  1610. Value* v64 = OR(SHL(hi64,CONST64(32)),lo64);
  1611. m0 = FPBITCAST64(v64);
  1612. m0 = SELECT(FPCMP_OLT(m0,FPCONST64(0.0)),FPNEG64(m0),m0);
  1613. Value *val64 = IBITCAST64(m0);
  1614. hi = LSHR(val64,CONST64(32));
  1615. lo = AND(val64,CONST64(0xffffffff));
  1616. hi = TRUNC32(hi);
  1617. lo = TRUNC32(lo);
  1618. hi = FPBITCAST32(hi);
  1619. lo = FPBITCAST32(lo);
  1620. LETFPS(2*d ,lo);
  1621. LETFPS(d*2 + 1 , hi);
  1622. }
  1623. return No_exp;
  1624. }
  1625. #endif
  1626. #undef vfpinstr
  1627. #undef vfpinstr_inst
  1628. #undef VFPLABEL_INST
  1629. /* ----------------------------------------------------------------------- */
  1630. /* VNEG */
  1631. /* cond 1110 1D11 0001 Vd-- 101X 11M0 Vm-- */
  1632. #define vfpinstr vneg
  1633. #define vfpinstr_inst vneg_inst
  1634. #define VFPLABEL_INST VNEG_INST
  1635. #ifdef VFP_DECODE
  1636. //{"vneg", 5, ARMVFP2, 23, 27, 0x1d, 16, 21, 0x30, 9, 11, 0x5, 6, 7, 1, 4, 4, 0},
  1637. {"vneg", 5, ARMVFP2, 23, 27, 0x1d, 17, 21, 0x18, 9, 11, 0x5, 6, 7, 1, 4, 4, 0},
  1638. #endif
  1639. #ifdef VFP_DECODE_EXCLUSION
  1640. {"vneg", 0, ARMVFP2, 0},
  1641. #endif
  1642. #ifdef VFP_INTERPRETER_TABLE
  1643. INTERPRETER_TRANSLATE(vfpinstr),
  1644. #endif
  1645. #ifdef VFP_INTERPRETER_LABEL
  1646. &&VFPLABEL_INST,
  1647. #endif
  1648. #ifdef VFP_INTERPRETER_STRUCT
  1649. typedef struct _vneg_inst {
  1650. unsigned int instr;
  1651. unsigned int dp_operation;
  1652. } vfpinstr_inst;
  1653. #endif
  1654. #ifdef VFP_INTERPRETER_TRANS
  1655. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  1656. {
  1657. VFP_DEBUG_TRANSLATE;VFP_DEBUG_UNTESTED(VNEG);
  1658. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  1659. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1660. inst_base->cond = BITS(inst, 28, 31);
  1661. inst_base->idx = index;
  1662. inst_base->br = NON_BRANCH;
  1663. inst_base->load_r15 = 0;
  1664. inst_cream->dp_operation = BIT(inst, 8);
  1665. inst_cream->instr = inst;
  1666. return inst_base;
  1667. }
  1668. #endif
  1669. #ifdef VFP_INTERPRETER_IMPL
  1670. VFPLABEL_INST:
  1671. {
  1672. INC_ICOUNTER;
  1673. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  1674. CHECK_VFP_ENABLED;
  1675. DBG("VNEG :\n");
  1676. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1677. int ret;
  1678. if (inst_cream->dp_operation)
  1679. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1680. else
  1681. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1682. CHECK_VFP_CDP_RET;
  1683. }
  1684. cpu->Reg[15] += GET_INST_SIZE(cpu);
  1685. INC_PC(sizeof(vfpinstr_inst));
  1686. FETCH_INST;
  1687. GOTO_NEXT_INST;
  1688. }
  1689. #endif
  1690. #ifdef VFP_CDP_TRANS
  1691. if ((OPC_1 & 0xB) == 0xB && CRn == 1 && (OPC_2 & 0x7) == 2)
  1692. {
  1693. DBG("VNEG :\n");
  1694. }
  1695. #endif
  1696. #ifdef VFP_DYNCOM_TABLE
  1697. DYNCOM_FILL_ACTION(vfpinstr),
  1698. #endif
  1699. #ifdef VFP_DYNCOM_TAG
  1700. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  1701. {
  1702. int instr_size = INSTR_SIZE;
  1703. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1704. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  1705. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  1706. return instr_size;
  1707. }
  1708. #endif
  1709. #ifdef VFP_DYNCOM_TRANS
  1710. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  1711. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1712. //arch_arm_undef(cpu, bb, instr);
  1713. int single = BIT(8) == 0;
  1714. int d = (single ? BITS(12,15)<<1 | BIT(22) : BIT(22) << 4 | BITS(12,15));
  1715. int m = (single ? BITS(0, 3)<<1 | BIT(5) : BITS(0, 3) | BIT(5)<<4);
  1716. Value* m0;
  1717. if (single)
  1718. {
  1719. m0 = FR32(m);
  1720. m0 = FPNEG32(m0);
  1721. LETFPS(d,m0);
  1722. }
  1723. else
  1724. {
  1725. /* Check endian please */
  1726. Value *lo = FR32(2 * m);
  1727. Value *hi = FR32(2 * m + 1);
  1728. hi = IBITCAST32(hi);
  1729. lo = IBITCAST32(lo);
  1730. Value *hi64 = ZEXT64(hi);
  1731. Value* lo64 = ZEXT64(lo);
  1732. Value* v64 = OR(SHL(hi64,CONST64(32)),lo64);
  1733. m0 = FPBITCAST64(v64);
  1734. m0 = FPNEG64(m0);
  1735. Value *val64 = IBITCAST64(m0);
  1736. hi = LSHR(val64,CONST64(32));
  1737. lo = AND(val64,CONST64(0xffffffff));
  1738. hi = TRUNC32(hi);
  1739. lo = TRUNC32(lo);
  1740. hi = FPBITCAST32(hi);
  1741. lo = FPBITCAST32(lo);
  1742. LETFPS(2*d ,lo);
  1743. LETFPS(d*2 + 1 , hi);
  1744. }
  1745. return No_exp;
  1746. }
  1747. #endif
  1748. #undef vfpinstr
  1749. #undef vfpinstr_inst
  1750. #undef VFPLABEL_INST
  1751. /* ----------------------------------------------------------------------- */
  1752. /* VSQRT */
  1753. /* cond 1110 1D11 0001 Vd-- 101X 11M0 Vm-- */
  1754. #define vfpinstr vsqrt
  1755. #define vfpinstr_inst vsqrt_inst
  1756. #define VFPLABEL_INST VSQRT_INST
  1757. #ifdef VFP_DECODE
  1758. {"vsqrt", 5, ARMVFP2, 23, 27, 0x1d, 16, 21, 0x31, 9, 11, 0x5, 6, 7, 3, 4, 4, 0},
  1759. #endif
  1760. #ifdef VFP_DECODE_EXCLUSION
  1761. {"vsqrt", 0, ARMVFP2, 0},
  1762. #endif
  1763. #ifdef VFP_INTERPRETER_TABLE
  1764. INTERPRETER_TRANSLATE(vfpinstr),
  1765. #endif
  1766. #ifdef VFP_INTERPRETER_LABEL
  1767. &&VFPLABEL_INST,
  1768. #endif
  1769. #ifdef VFP_INTERPRETER_STRUCT
  1770. typedef struct _vsqrt_inst {
  1771. unsigned int instr;
  1772. unsigned int dp_operation;
  1773. } vfpinstr_inst;
  1774. #endif
  1775. #ifdef VFP_INTERPRETER_TRANS
  1776. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  1777. {
  1778. VFP_DEBUG_TRANSLATE;
  1779. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  1780. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1781. inst_base->cond = BITS(inst, 28, 31);
  1782. inst_base->idx = index;
  1783. inst_base->br = NON_BRANCH;
  1784. inst_base->load_r15 = 0;
  1785. inst_cream->dp_operation = BIT(inst, 8);
  1786. inst_cream->instr = inst;
  1787. return inst_base;
  1788. }
  1789. #endif
  1790. #ifdef VFP_INTERPRETER_IMPL
  1791. VFPLABEL_INST:
  1792. {
  1793. INC_ICOUNTER;
  1794. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  1795. CHECK_VFP_ENABLED;
  1796. DBG("VSQRT :\n");
  1797. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1798. int ret;
  1799. if (inst_cream->dp_operation)
  1800. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1801. else
  1802. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1803. CHECK_VFP_CDP_RET;
  1804. }
  1805. cpu->Reg[15] += GET_INST_SIZE(cpu);
  1806. INC_PC(sizeof(vfpinstr_inst));
  1807. FETCH_INST;
  1808. GOTO_NEXT_INST;
  1809. }
  1810. #endif
  1811. #ifdef VFP_CDP_TRANS
  1812. if ((OPC_1 & 0xB) == 0xB && CRn == 1 && (OPC_2 & 0x7) == 6)
  1813. {
  1814. DBG("VSQRT :\n");
  1815. }
  1816. #endif
  1817. #ifdef VFP_DYNCOM_TABLE
  1818. DYNCOM_FILL_ACTION(vfpinstr),
  1819. #endif
  1820. #ifdef VFP_DYNCOM_TAG
  1821. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  1822. {
  1823. int instr_size = INSTR_SIZE;
  1824. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1825. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  1826. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  1827. return instr_size;
  1828. }
  1829. #endif
  1830. #ifdef VFP_DYNCOM_TRANS
  1831. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  1832. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  1833. //arch_arm_undef(cpu, bb, instr);
  1834. int dp_op = (BIT(8) == 1);
  1835. int d = dp_op ? BITS(12,15) | BIT(22) << 4 : BIT(22) | BITS(12,15) << 1;
  1836. int m = dp_op ? BITS(0,3) | BIT(5) << 4 : BIT(5) | BITS(0,3) << 1;
  1837. Value* v;
  1838. Value* tmp;
  1839. if(dp_op){
  1840. v = SHL(ZEXT64(IBITCAST32(FR32(2 * m + 1))),CONST64(32));
  1841. tmp = ZEXT64(IBITCAST32(FR32(2 * m)));
  1842. v = OR(v,tmp);
  1843. v = FPSQRT(FPBITCAST64(v));
  1844. tmp = TRUNC32(LSHR(IBITCAST64(v),CONST64(32)));
  1845. v = TRUNC32(AND(IBITCAST64(v),CONST64( 0xffffffff)));
  1846. LETFPS(2 * d , FPBITCAST32(v));
  1847. LETFPS(2 * d + 1, FPBITCAST32(tmp));
  1848. }else {
  1849. v = FR32(m);
  1850. v = FPSQRT(FPEXT(64,v));
  1851. v = FPTRUNC(32,v);
  1852. LETFPS(d,v);
  1853. }
  1854. return No_exp;
  1855. }
  1856. #endif
  1857. #undef vfpinstr
  1858. #undef vfpinstr_inst
  1859. #undef VFPLABEL_INST
  1860. /* ----------------------------------------------------------------------- */
  1861. /* VCMP VCMPE */
  1862. /* cond 1110 1D11 0100 Vd-- 101X E1M0 Vm-- Encoding 1 */
  1863. #define vfpinstr vcmp
  1864. #define vfpinstr_inst vcmp_inst
  1865. #define VFPLABEL_INST VCMP_INST
  1866. #ifdef VFP_DECODE
  1867. {"vcmp", 5, ARMVFP2, 23, 27, 0x1d, 16, 21, 0x34, 9, 11, 0x5, 6, 6, 1, 4, 4, 0},
  1868. #endif
  1869. #ifdef VFP_DECODE_EXCLUSION
  1870. {"vcmp", 0, ARMVFP2, 0},
  1871. #endif
  1872. #ifdef VFP_INTERPRETER_TABLE
  1873. INTERPRETER_TRANSLATE(vfpinstr),
  1874. #endif
  1875. #ifdef VFP_INTERPRETER_LABEL
  1876. &&VFPLABEL_INST,
  1877. #endif
  1878. #ifdef VFP_INTERPRETER_STRUCT
  1879. typedef struct _vcmp_inst {
  1880. unsigned int instr;
  1881. unsigned int dp_operation;
  1882. } vfpinstr_inst;
  1883. #endif
  1884. #ifdef VFP_INTERPRETER_TRANS
  1885. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  1886. {
  1887. VFP_DEBUG_TRANSLATE;
  1888. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  1889. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1890. inst_base->cond = BITS(inst, 28, 31);
  1891. inst_base->idx = index;
  1892. inst_base->br = NON_BRANCH;
  1893. inst_base->load_r15 = 0;
  1894. inst_cream->dp_operation = BIT(inst, 8);
  1895. inst_cream->instr = inst;
  1896. return inst_base;
  1897. }
  1898. #endif
  1899. #ifdef VFP_INTERPRETER_IMPL
  1900. VFPLABEL_INST:
  1901. {
  1902. INC_ICOUNTER;
  1903. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  1904. CHECK_VFP_ENABLED;
  1905. DBG("VCMP(1) :\n");
  1906. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  1907. int ret;
  1908. if (inst_cream->dp_operation)
  1909. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1910. else
  1911. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  1912. CHECK_VFP_CDP_RET;
  1913. }
  1914. cpu->Reg[15] += GET_INST_SIZE(cpu);
  1915. INC_PC(sizeof(vfpinstr_inst));
  1916. FETCH_INST;
  1917. GOTO_NEXT_INST;
  1918. }
  1919. #endif
  1920. #ifdef VFP_CDP_TRANS
  1921. if ((OPC_1 & 0xB) == 0xB && CRn == 4 && (OPC_2 & 0x2) == 2)
  1922. {
  1923. DBG("VCMP(1) :\n");
  1924. }
  1925. #endif
  1926. #ifdef VFP_DYNCOM_TABLE
  1927. DYNCOM_FILL_ACTION(vfpinstr),
  1928. #endif
  1929. #ifdef VFP_DYNCOM_TAG
  1930. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  1931. {
  1932. int instr_size = INSTR_SIZE;
  1933. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  1934. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  1935. return instr_size;
  1936. }
  1937. #endif
  1938. #ifdef VFP_DYNCOM_TRANS
  1939. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  1940. DBG("\t\tin %s instruction is executed out of JIT.\n", __FUNCTION__);
  1941. //arch_arm_undef(cpu, bb, instr);
  1942. int dp_op = (BIT(8) == 1);
  1943. int d = dp_op ? BITS(12,15) | BIT(22) << 4 : BIT(22) | BITS(12,15) << 1;
  1944. int m = dp_op ? BITS(0,3) | BIT(5) << 4 : BIT(5) | BITS(0,3) << 1;
  1945. Value* v;
  1946. Value* tmp;
  1947. Value* n;
  1948. Value* z;
  1949. Value* c;
  1950. Value* vt;
  1951. Value* v1;
  1952. Value* nzcv;
  1953. if(dp_op){
  1954. v = SHL(ZEXT64(IBITCAST32(FR32(2 * m + 1))),CONST64(32));
  1955. tmp = ZEXT64(IBITCAST32(FR32(2 * m)));
  1956. v1 = OR(v,tmp);
  1957. v = SHL(ZEXT64(IBITCAST32(FR32(2 * d + 1))),CONST64(32));
  1958. tmp = ZEXT64(IBITCAST32(FR32(2 * d)));
  1959. v = OR(v,tmp);
  1960. z = FPCMP_OEQ(FPBITCAST64(v),FPBITCAST64(v1));
  1961. n = FPCMP_OLT(FPBITCAST64(v),FPBITCAST64(v1));
  1962. c = FPCMP_OGE(FPBITCAST64(v),FPBITCAST64(v1));
  1963. tmp = FPCMP_UNO(FPBITCAST64(v),FPBITCAST64(v1));
  1964. v1 = tmp;
  1965. c = OR(c,tmp);
  1966. n = SHL(ZEXT32(n),CONST32(31));
  1967. z = SHL(ZEXT32(z),CONST32(30));
  1968. c = SHL(ZEXT32(c),CONST32(29));
  1969. v1 = SHL(ZEXT32(v1),CONST(28));
  1970. nzcv = OR(OR(OR(n,z),c),v1);
  1971. v = R(VFP_FPSCR);
  1972. tmp = OR(nzcv,AND(v,CONST32(0x0fffffff)));
  1973. LET(VFP_FPSCR,tmp);
  1974. }else {
  1975. z = FPCMP_OEQ(FR32(d),FR32(m));
  1976. n = FPCMP_OLT(FR32(d),FR32(m));
  1977. c = FPCMP_OGE(FR32(d),FR32(m));
  1978. tmp = FPCMP_UNO(FR32(d),FR32(m));
  1979. c = OR(c,tmp);
  1980. v1 = tmp;
  1981. n = SHL(ZEXT32(n),CONST32(31));
  1982. z = SHL(ZEXT32(z),CONST32(30));
  1983. c = SHL(ZEXT32(c),CONST32(29));
  1984. v1 = SHL(ZEXT32(v1),CONST(28));
  1985. nzcv = OR(OR(OR(n,z),c),v1);
  1986. v = R(VFP_FPSCR);
  1987. tmp = OR(nzcv,AND(v,CONST32(0x0fffffff)));
  1988. LET(VFP_FPSCR,tmp);
  1989. }
  1990. return No_exp;
  1991. }
  1992. #endif
  1993. #undef vfpinstr
  1994. #undef vfpinstr_inst
  1995. #undef VFPLABEL_INST
  1996. /* ----------------------------------------------------------------------- */
  1997. /* VCMP VCMPE */
  1998. /* cond 1110 1D11 0100 Vd-- 101X E1M0 Vm-- Encoding 2 */
  1999. #define vfpinstr vcmp2
  2000. #define vfpinstr_inst vcmp2_inst
  2001. #define VFPLABEL_INST VCMP2_INST
  2002. #ifdef VFP_DECODE
  2003. {"vcmp2", 5, ARMVFP2, 23, 27, 0x1d, 16, 21, 0x35, 9, 11, 0x5, 0, 6, 0x40},
  2004. #endif
  2005. #ifdef VFP_DECODE_EXCLUSION
  2006. {"vcmp2", 0, ARMVFP2, 0},
  2007. #endif
  2008. #ifdef VFP_INTERPRETER_TABLE
  2009. INTERPRETER_TRANSLATE(vfpinstr),
  2010. #endif
  2011. #ifdef VFP_INTERPRETER_LABEL
  2012. &&VFPLABEL_INST,
  2013. #endif
  2014. #ifdef VFP_INTERPRETER_STRUCT
  2015. typedef struct _vcmp2_inst {
  2016. unsigned int instr;
  2017. unsigned int dp_operation;
  2018. } vfpinstr_inst;
  2019. #endif
  2020. #ifdef VFP_INTERPRETER_TRANS
  2021. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  2022. {
  2023. VFP_DEBUG_TRANSLATE;
  2024. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  2025. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2026. inst_base->cond = BITS(inst, 28, 31);
  2027. inst_base->idx = index;
  2028. inst_base->br = NON_BRANCH;
  2029. inst_base->load_r15 = 0;
  2030. inst_cream->dp_operation = BIT(inst, 8);
  2031. inst_cream->instr = inst;
  2032. return inst_base;
  2033. }
  2034. #endif
  2035. #ifdef VFP_INTERPRETER_IMPL
  2036. VFPLABEL_INST:
  2037. {
  2038. INC_ICOUNTER;
  2039. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  2040. CHECK_VFP_ENABLED;
  2041. DBG("VCMP(2) :\n");
  2042. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2043. int ret;
  2044. if (inst_cream->dp_operation)
  2045. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2046. else
  2047. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2048. CHECK_VFP_CDP_RET;
  2049. }
  2050. cpu->Reg[15] += GET_INST_SIZE(cpu);
  2051. INC_PC(sizeof(vfpinstr_inst));
  2052. FETCH_INST;
  2053. GOTO_NEXT_INST;
  2054. }
  2055. #endif
  2056. #ifdef VFP_CDP_TRANS
  2057. if ((OPC_1 & 0xB) == 0xB && CRn == 5 && (OPC_2 & 0x2) == 2 && CRm == 0)
  2058. {
  2059. DBG("VCMP(2) :\n");
  2060. }
  2061. #endif
  2062. #ifdef VFP_DYNCOM_TABLE
  2063. DYNCOM_FILL_ACTION(vfpinstr),
  2064. #endif
  2065. #ifdef VFP_DYNCOM_TAG
  2066. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  2067. {
  2068. int instr_size = INSTR_SIZE;
  2069. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  2070. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  2071. return instr_size;
  2072. }
  2073. #endif
  2074. #ifdef VFP_DYNCOM_TRANS
  2075. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  2076. DBG("\t\tin %s instruction will executed out of JIT.\n", __FUNCTION__);
  2077. //arch_arm_undef(cpu, bb, instr);
  2078. int dp_op = (BIT(8) == 1);
  2079. int d = dp_op ? BITS(12,15) | BIT(22) << 4 : BIT(22) | BITS(12,15) << 1;
  2080. //int m = dp_op ? BITS(0,3) | BIT(5) << 4 : BIT(5) | BITS(0,3) << 1;
  2081. Value* v;
  2082. Value* tmp;
  2083. Value* n;
  2084. Value* z;
  2085. Value* c;
  2086. Value* vt;
  2087. Value* v1;
  2088. Value* nzcv;
  2089. if(dp_op){
  2090. v1 = CONST64(0);
  2091. v = SHL(ZEXT64(IBITCAST32(FR32(2 * d + 1))),CONST64(32));
  2092. tmp = ZEXT64(IBITCAST32(FR32(2 * d)));
  2093. v = OR(v,tmp);
  2094. z = FPCMP_OEQ(FPBITCAST64(v),FPBITCAST64(v1));
  2095. n = FPCMP_OLT(FPBITCAST64(v),FPBITCAST64(v1));
  2096. c = FPCMP_OGE(FPBITCAST64(v),FPBITCAST64(v1));
  2097. tmp = FPCMP_UNO(FPBITCAST64(v),FPBITCAST64(v1));
  2098. v1 = tmp;
  2099. c = OR(c,tmp);
  2100. n = SHL(ZEXT32(n),CONST32(31));
  2101. z = SHL(ZEXT32(z),CONST32(30));
  2102. c = SHL(ZEXT32(c),CONST32(29));
  2103. v1 = SHL(ZEXT32(v1),CONST(28));
  2104. nzcv = OR(OR(OR(n,z),c),v1);
  2105. v = R(VFP_FPSCR);
  2106. tmp = OR(nzcv,AND(v,CONST32(0x0fffffff)));
  2107. LET(VFP_FPSCR,tmp);
  2108. }else {
  2109. v1 = CONST(0);
  2110. v1 = FPBITCAST32(v1);
  2111. z = FPCMP_OEQ(FR32(d),v1);
  2112. n = FPCMP_OLT(FR32(d),v1);
  2113. c = FPCMP_OGE(FR32(d),v1);
  2114. tmp = FPCMP_UNO(FR32(d),v1);
  2115. c = OR(c,tmp);
  2116. v1 = tmp;
  2117. n = SHL(ZEXT32(n),CONST32(31));
  2118. z = SHL(ZEXT32(z),CONST32(30));
  2119. c = SHL(ZEXT32(c),CONST32(29));
  2120. v1 = SHL(ZEXT32(v1),CONST(28));
  2121. nzcv = OR(OR(OR(n,z),c),v1);
  2122. v = R(VFP_FPSCR);
  2123. tmp = OR(nzcv,AND(v,CONST32(0x0fffffff)));
  2124. LET(VFP_FPSCR,tmp);
  2125. }
  2126. return No_exp;
  2127. }
  2128. #endif
  2129. #undef vfpinstr
  2130. #undef vfpinstr_inst
  2131. #undef VFPLABEL_INST
  2132. /* ----------------------------------------------------------------------- */
  2133. /* VCVTBDS between double and single */
  2134. /* cond 1110 1D11 0111 Vd-- 101X 11M0 Vm-- */
  2135. #define vfpinstr vcvtbds
  2136. #define vfpinstr_inst vcvtbds_inst
  2137. #define VFPLABEL_INST VCVTBDS_INST
  2138. #ifdef VFP_DECODE
  2139. {"vcvt(bds)", 5, ARMVFP2, 23, 27, 0x1d, 16, 21, 0x37, 9, 11, 0x5, 6, 7, 3, 4, 4, 0},
  2140. #endif
  2141. #ifdef VFP_DECODE_EXCLUSION
  2142. {"vcvt(bds)", 0, ARMVFP2, 0},
  2143. #endif
  2144. #ifdef VFP_INTERPRETER_TABLE
  2145. INTERPRETER_TRANSLATE(vfpinstr),
  2146. #endif
  2147. #ifdef VFP_INTERPRETER_LABEL
  2148. &&VFPLABEL_INST,
  2149. #endif
  2150. #ifdef VFP_INTERPRETER_STRUCT
  2151. typedef struct _vcvtbds_inst {
  2152. unsigned int instr;
  2153. unsigned int dp_operation;
  2154. } vfpinstr_inst;
  2155. #endif
  2156. #ifdef VFP_INTERPRETER_TRANS
  2157. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  2158. {
  2159. VFP_DEBUG_TRANSLATE;
  2160. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  2161. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2162. inst_base->cond = BITS(inst, 28, 31);
  2163. inst_base->idx = index;
  2164. inst_base->br = NON_BRANCH;
  2165. inst_base->load_r15 = 0;
  2166. inst_cream->dp_operation = BIT(inst, 8);
  2167. inst_cream->instr = inst;
  2168. return inst_base;
  2169. }
  2170. #endif
  2171. #ifdef VFP_INTERPRETER_IMPL
  2172. VFPLABEL_INST:
  2173. {
  2174. INC_ICOUNTER;
  2175. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  2176. CHECK_VFP_ENABLED;
  2177. DBG("VCVT(BDS) :\n");
  2178. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2179. int ret;
  2180. if (inst_cream->dp_operation)
  2181. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2182. else
  2183. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2184. CHECK_VFP_CDP_RET;
  2185. }
  2186. cpu->Reg[15] += GET_INST_SIZE(cpu);
  2187. INC_PC(sizeof(vfpinstr_inst));
  2188. FETCH_INST;
  2189. GOTO_NEXT_INST;
  2190. }
  2191. #endif
  2192. #ifdef VFP_CDP_TRANS
  2193. if ((OPC_1 & 0xB) == 0xB && CRn == 7 && (OPC_2 & 0x6) == 6)
  2194. {
  2195. DBG("VCVT(BDS) :\n");
  2196. }
  2197. #endif
  2198. #ifdef VFP_DYNCOM_TABLE
  2199. DYNCOM_FILL_ACTION(vfpinstr),
  2200. #endif
  2201. #ifdef VFP_DYNCOM_TAG
  2202. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  2203. {
  2204. int instr_size = INSTR_SIZE;
  2205. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  2206. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  2207. return instr_size;
  2208. }
  2209. #endif
  2210. #ifdef VFP_DYNCOM_TRANS
  2211. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  2212. DBG("\t\tin %s instruction is executed out.\n", __FUNCTION__);
  2213. //arch_arm_undef(cpu, bb, instr);
  2214. int dp_op = (BIT(8) == 1);
  2215. int d = dp_op ? BITS(12,15) << 1 | BIT(22) : BIT(22) << 4 | BITS(12,15);
  2216. int m = dp_op ? BITS(0,3) | BIT(5) << 4 : BIT(5) | BITS(0,3) << 1;
  2217. int d2s = dp_op;
  2218. Value* v;
  2219. Value* tmp;
  2220. Value* v1;
  2221. if(d2s){
  2222. v = SHL(ZEXT64(IBITCAST32(FR32(2 * m + 1))),CONST64(32));
  2223. tmp = ZEXT64(IBITCAST32(FR32(2 * m)));
  2224. v1 = OR(v,tmp);
  2225. tmp = FPTRUNC(32,FPBITCAST64(v1));
  2226. LETFPS(d,tmp);
  2227. }else {
  2228. v = FR32(m);
  2229. tmp = FPEXT(64,v);
  2230. v = IBITCAST64(tmp);
  2231. tmp = TRUNC32(AND(v,CONST64(0xffffffff)));
  2232. v1 = TRUNC32(LSHR(v,CONST64(32)));
  2233. LETFPS(2 * d, FPBITCAST32(tmp) );
  2234. LETFPS(2 * d + 1, FPBITCAST32(v1));
  2235. }
  2236. return No_exp;
  2237. }
  2238. #endif
  2239. #undef vfpinstr
  2240. #undef vfpinstr_inst
  2241. #undef VFPLABEL_INST
  2242. /* ----------------------------------------------------------------------- */
  2243. /* VCVTBFF between floating point and fixed point */
  2244. /* cond 1110 1D11 1op2 Vd-- 101X X1M0 Vm-- */
  2245. #define vfpinstr vcvtbff
  2246. #define vfpinstr_inst vcvtbff_inst
  2247. #define VFPLABEL_INST VCVTBFF_INST
  2248. #ifdef VFP_DECODE
  2249. {"vcvt(bff)", 6, ARMVFP3, 23, 27, 0x1d, 19, 21, 0x7, 17, 17, 0x1, 9, 11, 0x5, 6, 6, 1},
  2250. #endif
  2251. #ifdef VFP_DECODE_EXCLUSION
  2252. {"vcvt(bff)", 0, ARMVFP3, 4, 4, 1},
  2253. #endif
  2254. #ifdef VFP_INTERPRETER_TABLE
  2255. INTERPRETER_TRANSLATE(vfpinstr),
  2256. #endif
  2257. #ifdef VFP_INTERPRETER_LABEL
  2258. &&VFPLABEL_INST,
  2259. #endif
  2260. #ifdef VFP_INTERPRETER_STRUCT
  2261. typedef struct _vcvtbff_inst {
  2262. unsigned int instr;
  2263. unsigned int dp_operation;
  2264. } vfpinstr_inst;
  2265. #endif
  2266. #ifdef VFP_INTERPRETER_TRANS
  2267. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  2268. {
  2269. VFP_DEBUG_TRANSLATE;VFP_DEBUG_UNTESTED(VCVTBFF);
  2270. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  2271. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2272. inst_base->cond = BITS(inst, 28, 31);
  2273. inst_base->idx = index;
  2274. inst_base->br = NON_BRANCH;
  2275. inst_base->load_r15 = 0;
  2276. inst_cream->dp_operation = BIT(inst, 8);
  2277. inst_cream->instr = inst;
  2278. return inst_base;
  2279. }
  2280. #endif
  2281. #ifdef VFP_INTERPRETER_IMPL
  2282. VFPLABEL_INST:
  2283. {
  2284. INC_ICOUNTER;
  2285. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  2286. CHECK_VFP_ENABLED;
  2287. DBG("VCVT(BFF) :\n");
  2288. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2289. int ret;
  2290. if (inst_cream->dp_operation)
  2291. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2292. else
  2293. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2294. CHECK_VFP_CDP_RET;
  2295. }
  2296. cpu->Reg[15] += GET_INST_SIZE(cpu);
  2297. INC_PC(sizeof(vfpinstr_inst));
  2298. FETCH_INST;
  2299. GOTO_NEXT_INST;
  2300. }
  2301. #endif
  2302. #ifdef VFP_CDP_TRANS
  2303. if ((OPC_1 & 0xB) == 0xB && CRn >= 0xA && (OPC_2 & 0x2) == 2)
  2304. {
  2305. DBG("VCVT(BFF) :\n");
  2306. }
  2307. #endif
  2308. #ifdef VFP_DYNCOM_TABLE
  2309. DYNCOM_FILL_ACTION(vfpinstr),
  2310. #endif
  2311. #ifdef VFP_DYNCOM_TAG
  2312. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  2313. {
  2314. int instr_size = INSTR_SIZE;
  2315. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  2316. arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  2317. return instr_size;
  2318. }
  2319. #endif
  2320. #ifdef VFP_DYNCOM_TRANS
  2321. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  2322. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  2323. arch_arm_undef(cpu, bb, instr);
  2324. return No_exp;
  2325. }
  2326. #endif
  2327. #undef vfpinstr
  2328. #undef vfpinstr_inst
  2329. #undef VFPLABEL_INST
  2330. /* ----------------------------------------------------------------------- */
  2331. /* VCVTBFI between floating point and integer */
  2332. /* cond 1110 1D11 1op2 Vd-- 101X X1M0 Vm-- */
  2333. #define vfpinstr vcvtbfi
  2334. #define vfpinstr_inst vcvtbfi_inst
  2335. #define VFPLABEL_INST VCVTBFI_INST
  2336. #ifdef VFP_DECODE
  2337. {"vcvt(bfi)", 5, ARMVFP2, 23, 27, 0x1d, 19, 21, 0x7, 9, 11, 0x5, 6, 6, 1, 4, 4, 0},
  2338. #endif
  2339. #ifdef VFP_DECODE_EXCLUSION
  2340. {"vcvt(bfi)", 0, ARMVFP2, 0},
  2341. #endif
  2342. #ifdef VFP_INTERPRETER_TABLE
  2343. INTERPRETER_TRANSLATE(vfpinstr),
  2344. #endif
  2345. #ifdef VFP_INTERPRETER_LABEL
  2346. &&VFPLABEL_INST,
  2347. #endif
  2348. #ifdef VFP_INTERPRETER_STRUCT
  2349. typedef struct _vcvtbfi_inst {
  2350. unsigned int instr;
  2351. unsigned int dp_operation;
  2352. } vfpinstr_inst;
  2353. #endif
  2354. #ifdef VFP_INTERPRETER_TRANS
  2355. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  2356. {
  2357. VFP_DEBUG_TRANSLATE;
  2358. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  2359. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2360. inst_base->cond = BITS(inst, 28, 31);
  2361. inst_base->idx = index;
  2362. inst_base->br = NON_BRANCH;
  2363. inst_base->load_r15 = 0;
  2364. inst_cream->dp_operation = BIT(inst, 8);
  2365. inst_cream->instr = inst;
  2366. return inst_base;
  2367. }
  2368. #endif
  2369. #ifdef VFP_INTERPRETER_IMPL
  2370. VFPLABEL_INST:
  2371. {
  2372. INC_ICOUNTER;
  2373. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  2374. CHECK_VFP_ENABLED;
  2375. DBG("VCVT(BFI) :\n");
  2376. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2377. int ret;
  2378. if (inst_cream->dp_operation)
  2379. ret = vfp_double_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2380. else
  2381. ret = vfp_single_cpdo(cpu, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2382. CHECK_VFP_CDP_RET;
  2383. }
  2384. cpu->Reg[15] += GET_INST_SIZE(cpu);
  2385. INC_PC(sizeof(vfpinstr_inst));
  2386. FETCH_INST;
  2387. GOTO_NEXT_INST;
  2388. }
  2389. #endif
  2390. #ifdef VFP_CDP_TRANS
  2391. if ((OPC_1 & 0xB) == 0xB && CRn > 7 && (OPC_2 & 0x2) == 2)
  2392. {
  2393. DBG("VCVT(BFI) :\n");
  2394. }
  2395. #endif
  2396. #ifdef VFP_DYNCOM_TABLE
  2397. DYNCOM_FILL_ACTION(vfpinstr),
  2398. #endif
  2399. #ifdef VFP_DYNCOM_TAG
  2400. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  2401. {
  2402. int instr_size = INSTR_SIZE;
  2403. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  2404. DBG("\t\tin %s, instruction will be executed out of JIT.\n", __FUNCTION__);
  2405. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  2406. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  2407. return instr_size;
  2408. }
  2409. #endif
  2410. #ifdef VFP_DYNCOM_TRANS
  2411. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  2412. DBG("\t\tin %s, instruction will be executed out of JIT.\n", __FUNCTION__);
  2413. //arch_arm_undef(cpu, bb, instr);
  2414. unsigned int opc2 = BITS(16,18);
  2415. int to_integer = ((opc2 >> 2) == 1);
  2416. int dp_op = (BIT(8) == 1);
  2417. unsigned int op = BIT(7);
  2418. int m,d;
  2419. Value* v;
  2420. Value* hi;
  2421. Value* lo;
  2422. Value* v64;
  2423. if(to_integer){
  2424. d = BIT(22) | (BITS(12,15) << 1);
  2425. if(dp_op)
  2426. m = BITS(0,3) | BIT(5) << 4;
  2427. else
  2428. m = BIT(5) | BITS(0,3) << 1;
  2429. }else {
  2430. m = BIT(5) | BITS(0,3) << 1;
  2431. if(dp_op)
  2432. d = BITS(12,15) | BIT(22) << 4;
  2433. else
  2434. d = BIT(22) | BITS(12,15) << 1;
  2435. }
  2436. if(to_integer){
  2437. if(dp_op){
  2438. lo = FR32(m * 2);
  2439. hi = FR32(m * 2 + 1);
  2440. hi = ZEXT64(IBITCAST32(hi));
  2441. lo = ZEXT64(IBITCAST32(lo));
  2442. v64 = OR(SHL(hi,CONST64(32)),lo);
  2443. if(BIT(16)){
  2444. v = FPTOSI(32,FPBITCAST64(v64));
  2445. }
  2446. else
  2447. v = FPTOUI(32,FPBITCAST64(v64));
  2448. v = FPBITCAST32(v);
  2449. LETFPS(d,v);
  2450. }else {
  2451. v = FR32(m);
  2452. if(BIT(16)){
  2453. v = FPTOSI(32,v);
  2454. }
  2455. else
  2456. v = FPTOUI(32,v);
  2457. LETFPS(d,FPBITCAST32(v));
  2458. }
  2459. }else {
  2460. if(dp_op){
  2461. v = IBITCAST32(FR32(m));
  2462. if(BIT(7))
  2463. v64 = SITOFP(64,v);
  2464. else
  2465. v64 = UITOFP(64,v);
  2466. v = IBITCAST64(v64);
  2467. hi = FPBITCAST32(TRUNC32(LSHR(v,CONST64(32))));
  2468. lo = FPBITCAST32(TRUNC32(AND(v,CONST64(0xffffffff))));
  2469. LETFPS(2 * d , lo);
  2470. LETFPS(2 * d + 1, hi);
  2471. }else {
  2472. v = IBITCAST32(FR32(m));
  2473. if(BIT(7))
  2474. v = SITOFP(32,v);
  2475. else
  2476. v = UITOFP(32,v);
  2477. LETFPS(d,v);
  2478. }
  2479. }
  2480. return No_exp;
  2481. }
  2482. /**
  2483. * @brief The implementation of c language for vcvtbfi instruction of dyncom
  2484. *
  2485. * @param cpu
  2486. * @param instr
  2487. *
  2488. * @return
  2489. */
  2490. int vcvtbfi_instr_impl(arm_core_t* cpu, uint32 instr){
  2491. int dp_operation = BIT(8);
  2492. int ret;
  2493. if (dp_operation)
  2494. ret = vfp_double_cpdo(cpu, instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2495. else
  2496. ret = vfp_single_cpdo(cpu, instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2497. vfp_raise_exceptions(cpu, ret, instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2498. return 0;
  2499. }
  2500. #endif
  2501. #undef vfpinstr
  2502. #undef vfpinstr_inst
  2503. #undef VFPLABEL_INST
  2504. /* ----------------------------------------------------------------------- */
  2505. /* MRC / MCR instructions */
  2506. /* cond 1110 AAAL XXXX XXXX 101C XBB1 XXXX */
  2507. /* cond 1110 op11 CRn- Rt-- copr op21 CRm- */
  2508. /* ----------------------------------------------------------------------- */
  2509. /* VMOVBRS between register and single precision */
  2510. /* cond 1110 000o Vn-- Rt-- 1010 N001 0000 */
  2511. /* cond 1110 op11 CRn- Rt-- copr op21 CRm- MRC */
  2512. #define vfpinstr vmovbrs
  2513. #define vfpinstr_inst vmovbrs_inst
  2514. #define VFPLABEL_INST VMOVBRS_INST
  2515. #ifdef VFP_DECODE
  2516. {"vmovbrs", 3, ARMVFP2, 21, 27, 0x70, 8, 11, 0xA, 0, 6, 0x10},
  2517. #endif
  2518. #ifdef VFP_DECODE_EXCLUSION
  2519. {"vmovbrs", 0, ARMVFP2, 0},
  2520. #endif
  2521. #ifdef VFP_INTERPRETER_TABLE
  2522. INTERPRETER_TRANSLATE(vfpinstr),
  2523. #endif
  2524. #ifdef VFP_INTERPRETER_LABEL
  2525. &&VFPLABEL_INST,
  2526. #endif
  2527. #ifdef VFP_INTERPRETER_STRUCT
  2528. typedef struct _vmovbrs_inst {
  2529. unsigned int to_arm;
  2530. unsigned int t;
  2531. unsigned int n;
  2532. } vfpinstr_inst;
  2533. #endif
  2534. #ifdef VFP_INTERPRETER_TRANS
  2535. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  2536. {
  2537. VFP_DEBUG_TRANSLATE;
  2538. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  2539. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2540. inst_base->cond = BITS(inst, 28, 31);
  2541. inst_base->idx = index;
  2542. inst_base->br = NON_BRANCH;
  2543. inst_base->load_r15 = 0;
  2544. inst_cream->to_arm = BIT(inst, 20) == 1;
  2545. inst_cream->t = BITS(inst, 12, 15);
  2546. inst_cream->n = BIT(inst, 7) | BITS(inst, 16, 19)<<1;
  2547. return inst_base;
  2548. }
  2549. #endif
  2550. #ifdef VFP_INTERPRETER_IMPL
  2551. VFPLABEL_INST:
  2552. {
  2553. INC_ICOUNTER;
  2554. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  2555. CHECK_VFP_ENABLED;
  2556. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2557. VMOVBRS(cpu, inst_cream->to_arm, inst_cream->t, inst_cream->n, &(cpu->Reg[inst_cream->t]));
  2558. }
  2559. cpu->Reg[15] += GET_INST_SIZE(cpu);
  2560. INC_PC(sizeof(vfpinstr_inst));
  2561. FETCH_INST;
  2562. GOTO_NEXT_INST;
  2563. }
  2564. #endif
  2565. #ifdef VFP_MRC_TRANS
  2566. if (OPC_1 == 0x0 && CRm == 0 && (OPC_2 & 0x3) == 0)
  2567. {
  2568. /* VMOV r to s */
  2569. /* Transfering Rt is not mandatory, as the value of interest is pointed by value */
  2570. VMOVBRS(state, BIT(20), Rt, BIT(7)|CRn<<1, value);
  2571. return ARMul_DONE;
  2572. }
  2573. #endif
  2574. #ifdef VFP_MCR_TRANS
  2575. if (OPC_1 == 0x0 && CRm == 0 && (OPC_2 & 0x3) == 0)
  2576. {
  2577. /* VMOV s to r */
  2578. /* Transfering Rt is not mandatory, as the value of interest is pointed by value */
  2579. VMOVBRS(state, BIT(20), Rt, BIT(7)|CRn<<1, &value);
  2580. return ARMul_DONE;
  2581. }
  2582. #endif
  2583. #ifdef VFP_MRC_IMPL
  2584. void VMOVBRS(ARMul_State * state, ARMword to_arm, ARMword t, ARMword n, ARMword *value)
  2585. {
  2586. DBG("VMOV(BRS) :\n");
  2587. if (to_arm)
  2588. {
  2589. DBG("\tr%d <= s%d=[%x]\n", t, n, state->ExtReg[n]);
  2590. *value = state->ExtReg[n];
  2591. }
  2592. else
  2593. {
  2594. DBG("\ts%d <= r%d=[%x]\n", n, t, *value);
  2595. state->ExtReg[n] = *value;
  2596. }
  2597. }
  2598. #endif
  2599. #ifdef VFP_DYNCOM_TABLE
  2600. DYNCOM_FILL_ACTION(vfpinstr),
  2601. #endif
  2602. #ifdef VFP_DYNCOM_TAG
  2603. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  2604. {
  2605. int instr_size = INSTR_SIZE;
  2606. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  2607. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  2608. return instr_size;
  2609. }
  2610. #endif
  2611. #ifdef VFP_DYNCOM_TRANS
  2612. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  2613. DBG("VMOV(BRS) :\n");
  2614. int to_arm = BIT(20) == 1;
  2615. int t = BITS(12, 15);
  2616. int n = BIT(7) | BITS(16, 19)<<1;
  2617. if (to_arm)
  2618. {
  2619. DBG("\tr%d <= s%d\n", t, n);
  2620. LET(t, IBITCAST32(FR32(n)));
  2621. }
  2622. else
  2623. {
  2624. DBG("\ts%d <= r%d\n", n, t);
  2625. LETFPS(n, FPBITCAST32(R(t)));
  2626. }
  2627. return No_exp;
  2628. }
  2629. #endif
  2630. #undef vfpinstr
  2631. #undef vfpinstr_inst
  2632. #undef VFPLABEL_INST
  2633. /* ----------------------------------------------------------------------- */
  2634. /* VMSR */
  2635. /* cond 1110 1110 reg- Rt-- 1010 0001 0000 */
  2636. /* cond 1110 op10 CRn- Rt-- copr op21 CRm- MCR */
  2637. #define vfpinstr vmsr
  2638. #define vfpinstr_inst vmsr_inst
  2639. #define VFPLABEL_INST VMSR_INST
  2640. #ifdef VFP_DECODE
  2641. {"vmsr", 2, ARMVFP2, 20, 27, 0xEE, 0, 11, 0xA10},
  2642. #endif
  2643. #ifdef VFP_DECODE_EXCLUSION
  2644. {"vmsr", 0, ARMVFP2, 0},
  2645. #endif
  2646. #ifdef VFP_INTERPRETER_TABLE
  2647. INTERPRETER_TRANSLATE(vfpinstr),
  2648. #endif
  2649. #ifdef VFP_INTERPRETER_LABEL
  2650. &&VFPLABEL_INST,
  2651. #endif
  2652. #ifdef VFP_INTERPRETER_STRUCT
  2653. typedef struct _vmsr_inst {
  2654. unsigned int reg;
  2655. unsigned int Rd;
  2656. } vfpinstr_inst;
  2657. #endif
  2658. #ifdef VFP_INTERPRETER_TRANS
  2659. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  2660. {
  2661. VFP_DEBUG_TRANSLATE;
  2662. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  2663. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2664. inst_base->cond = BITS(inst, 28, 31);
  2665. inst_base->idx = index;
  2666. inst_base->br = NON_BRANCH;
  2667. inst_base->load_r15 = 0;
  2668. inst_cream->reg = BITS(inst, 16, 19);
  2669. inst_cream->Rd = BITS(inst, 12, 15);
  2670. return inst_base;
  2671. }
  2672. #endif
  2673. #ifdef VFP_INTERPRETER_IMPL
  2674. VFPLABEL_INST:
  2675. {
  2676. INC_ICOUNTER;
  2677. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  2678. /* FIXME: special case for access to FPSID and FPEXC, VFP must be disabled ,
  2679. and in privilegied mode */
  2680. /* Exceptions must be checked, according to v7 ref manual */
  2681. CHECK_VFP_ENABLED;
  2682. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2683. VMSR(cpu, inst_cream->reg, inst_cream->Rd);
  2684. }
  2685. cpu->Reg[15] += GET_INST_SIZE(cpu);
  2686. INC_PC(sizeof(vfpinstr_inst));
  2687. FETCH_INST;
  2688. GOTO_NEXT_INST;
  2689. }
  2690. #endif
  2691. #ifdef VFP_MCR_TRANS
  2692. if (OPC_1 == 0x7 && CRm == 0 && OPC_2 == 0)
  2693. {
  2694. VMSR(state, CRn, Rt);
  2695. return ARMul_DONE;
  2696. }
  2697. #endif
  2698. #ifdef VFP_MCR_IMPL
  2699. void VMSR(ARMul_State * state, ARMword reg, ARMword Rt)
  2700. {
  2701. if (reg == 1)
  2702. {
  2703. DBG("VMSR :\tfpscr <= r%d=[%x]\n", Rt, state->Reg[Rt]);
  2704. state->VFP[VFP_OFFSET(VFP_FPSCR)] = state->Reg[Rt];
  2705. }
  2706. else if (reg == 8)
  2707. {
  2708. DBG("VMSR :\tfpexc <= r%d=[%x]\n", Rt, state->Reg[Rt]);
  2709. state->VFP[VFP_OFFSET(VFP_FPEXC)] = state->Reg[Rt];
  2710. }
  2711. }
  2712. #endif
  2713. #ifdef VFP_DYNCOM_TABLE
  2714. DYNCOM_FILL_ACTION(vfpinstr),
  2715. #endif
  2716. #ifdef VFP_DYNCOM_TAG
  2717. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  2718. {
  2719. int instr_size = INSTR_SIZE;
  2720. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  2721. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  2722. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  2723. return instr_size;
  2724. }
  2725. #endif
  2726. #ifdef VFP_DYNCOM_TRANS
  2727. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  2728. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  2729. //arch_arm_undef(cpu, bb, instr);
  2730. DBG("VMSR :");
  2731. if(RD == 15) {
  2732. printf("in %s is not implementation.\n", __FUNCTION__);
  2733. exit(-1);
  2734. }
  2735. Value *data = NULL;
  2736. int reg = RN;
  2737. int Rt = RD;
  2738. if (reg == 1)
  2739. {
  2740. LET(VFP_FPSCR, R(Rt));
  2741. DBG("\tflags <= fpscr\n");
  2742. }
  2743. else
  2744. {
  2745. switch (reg)
  2746. {
  2747. case 8:
  2748. LET(VFP_FPEXC, R(Rt));
  2749. DBG("\tfpexc <= r%d \n", Rt);
  2750. break;
  2751. default:
  2752. DBG("\tSUBARCHITECTURE DEFINED\n");
  2753. break;
  2754. }
  2755. }
  2756. return No_exp;
  2757. }
  2758. #endif
  2759. #undef vfpinstr
  2760. #undef vfpinstr_inst
  2761. #undef VFPLABEL_INST
  2762. /* ----------------------------------------------------------------------- */
  2763. /* VMOVBRC register to scalar */
  2764. /* cond 1110 0XX0 Vd-- Rt-- 1011 DXX1 0000 */
  2765. /* cond 1110 op10 CRn- Rt-- copr op21 CRm- MCR */
  2766. #define vfpinstr vmovbrc
  2767. #define vfpinstr_inst vmovbrc_inst
  2768. #define VFPLABEL_INST VMOVBRC_INST
  2769. #ifdef VFP_DECODE
  2770. {"vmovbrc", 4, ARMVFP2, 23, 27, 0x1C, 20, 20, 0x0, 8,11,0xB, 0,4,0x10},
  2771. #endif
  2772. #ifdef VFP_DECODE_EXCLUSION
  2773. {"vmovbrc", 0, ARMVFP2, 0},
  2774. #endif
  2775. #ifdef VFP_INTERPRETER_TABLE
  2776. INTERPRETER_TRANSLATE(vfpinstr),
  2777. #endif
  2778. #ifdef VFP_INTERPRETER_LABEL
  2779. &&VFPLABEL_INST,
  2780. #endif
  2781. #ifdef VFP_INTERPRETER_STRUCT
  2782. typedef struct _vmovbrc_inst {
  2783. unsigned int esize;
  2784. unsigned int index;
  2785. unsigned int d;
  2786. unsigned int t;
  2787. } vfpinstr_inst;
  2788. #endif
  2789. #ifdef VFP_INTERPRETER_TRANS
  2790. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  2791. {
  2792. VFP_DEBUG_TRANSLATE;
  2793. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  2794. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2795. inst_base->cond = BITS(inst, 28, 31);
  2796. inst_base->idx = index;
  2797. inst_base->br = NON_BRANCH;
  2798. inst_base->load_r15 = 0;
  2799. inst_cream->d = BITS(inst, 16, 19)|BIT(inst, 7)<<4;
  2800. inst_cream->t = BITS(inst, 12, 15);
  2801. /* VFP variant of instruction */
  2802. inst_cream->esize = 32;
  2803. inst_cream->index = BIT(inst, 21);
  2804. return inst_base;
  2805. }
  2806. #endif
  2807. #ifdef VFP_INTERPRETER_IMPL
  2808. VFPLABEL_INST:
  2809. {
  2810. INC_ICOUNTER;
  2811. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  2812. CHECK_VFP_ENABLED;
  2813. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2814. VFP_DEBUG_UNIMPLEMENTED(VMOVBRC);
  2815. }
  2816. cpu->Reg[15] += GET_INST_SIZE(cpu);
  2817. INC_PC(sizeof(vfpinstr_inst));
  2818. FETCH_INST;
  2819. GOTO_NEXT_INST;
  2820. }
  2821. #endif
  2822. #ifdef VFP_MCR_TRANS
  2823. if ((OPC_1 & 0x4) == 0 && CoProc == 11 && CRm == 0)
  2824. {
  2825. VFP_DEBUG_UNIMPLEMENTED(VMOVBRC);
  2826. return ARMul_DONE;
  2827. }
  2828. #endif
  2829. #ifdef VFP_DYNCOM_TABLE
  2830. DYNCOM_FILL_ACTION(vfpinstr),
  2831. #endif
  2832. #ifdef VFP_DYNCOM_TAG
  2833. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  2834. {
  2835. int instr_size = INSTR_SIZE;
  2836. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  2837. arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  2838. return instr_size;
  2839. }
  2840. #endif
  2841. #ifdef VFP_DYNCOM_TRANS
  2842. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  2843. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  2844. arch_arm_undef(cpu, bb, instr);
  2845. return No_exp;
  2846. }
  2847. #endif
  2848. #undef vfpinstr
  2849. #undef vfpinstr_inst
  2850. #undef VFPLABEL_INST
  2851. /* ----------------------------------------------------------------------- */
  2852. /* VMRS */
  2853. /* cond 1110 1111 CRn- Rt-- 1010 0001 0000 */
  2854. /* cond 1110 op11 CRn- Rt-- copr op21 CRm- MRC */
  2855. #define vfpinstr vmrs
  2856. #define vfpinstr_inst vmrs_inst
  2857. #define VFPLABEL_INST VMRS_INST
  2858. #ifdef VFP_DECODE
  2859. {"vmrs", 2, ARMVFP2, 20, 27, 0xEF, 0, 11, 0xa10},
  2860. #endif
  2861. #ifdef VFP_DECODE_EXCLUSION
  2862. {"vmrs", 0, ARMVFP2, 0},
  2863. #endif
  2864. #ifdef VFP_INTERPRETER_TABLE
  2865. INTERPRETER_TRANSLATE(vfpinstr),
  2866. #endif
  2867. #ifdef VFP_INTERPRETER_LABEL
  2868. &&VFPLABEL_INST,
  2869. #endif
  2870. #ifdef VFP_INTERPRETER_STRUCT
  2871. typedef struct _vmrs_inst {
  2872. unsigned int reg;
  2873. unsigned int Rt;
  2874. } vfpinstr_inst;
  2875. #endif
  2876. #ifdef VFP_INTERPRETER_TRANS
  2877. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  2878. {
  2879. VFP_DEBUG_TRANSLATE;
  2880. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  2881. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2882. inst_base->cond = BITS(inst, 28, 31);
  2883. inst_base->idx = index;
  2884. inst_base->br = NON_BRANCH;
  2885. inst_base->load_r15 = 0;
  2886. inst_cream->reg = BITS(inst, 16, 19);
  2887. inst_cream->Rt = BITS(inst, 12, 15);
  2888. return inst_base;
  2889. }
  2890. #endif
  2891. #ifdef VFP_INTERPRETER_IMPL
  2892. VFPLABEL_INST:
  2893. {
  2894. INC_ICOUNTER;
  2895. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  2896. /* FIXME: special case for access to FPSID and FPEXC, VFP must be disabled,
  2897. and in privilegied mode */
  2898. /* Exceptions must be checked, according to v7 ref manual */
  2899. CHECK_VFP_ENABLED;
  2900. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  2901. DBG("VMRS :");
  2902. if (inst_cream->reg == 1) /* FPSCR */
  2903. {
  2904. if (inst_cream->Rt != 15)
  2905. {
  2906. cpu->Reg[inst_cream->Rt] = cpu->VFP[VFP_OFFSET(VFP_FPSCR)];
  2907. DBG("\tr%d <= fpscr[%08x]\n", inst_cream->Rt, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2908. }
  2909. else
  2910. {
  2911. cpu->NFlag = (cpu->VFP[VFP_OFFSET(VFP_FPSCR)] >> 31) & 1;
  2912. cpu->ZFlag = (cpu->VFP[VFP_OFFSET(VFP_FPSCR)] >> 30) & 1;
  2913. cpu->CFlag = (cpu->VFP[VFP_OFFSET(VFP_FPSCR)] >> 29) & 1;
  2914. cpu->VFlag = (cpu->VFP[VFP_OFFSET(VFP_FPSCR)] >> 28) & 1;
  2915. DBG("\tflags <= fpscr[%1xxxxxxxx]\n", cpu->VFP[VFP_OFFSET(VFP_FPSCR)]>>28);
  2916. }
  2917. }
  2918. else
  2919. {
  2920. switch (inst_cream->reg)
  2921. {
  2922. case 0:
  2923. cpu->Reg[inst_cream->Rt] = cpu->VFP[VFP_OFFSET(VFP_FPSID)];
  2924. DBG("\tr%d <= fpsid[%08x]\n", inst_cream->Rt, cpu->VFP[VFP_OFFSET(VFP_FPSID)]);
  2925. break;
  2926. case 6:
  2927. /* MVFR1, VFPv3 only ? */
  2928. DBG("\tr%d <= MVFR1 unimplemented\n", inst_cream->Rt);
  2929. break;
  2930. case 7:
  2931. /* MVFR0, VFPv3 only? */
  2932. DBG("\tr%d <= MVFR0 unimplemented\n", inst_cream->Rt);
  2933. break;
  2934. case 8:
  2935. cpu->Reg[inst_cream->Rt] = cpu->VFP[VFP_OFFSET(VFP_FPEXC)];
  2936. DBG("\tr%d <= fpexc[%08x]\n", inst_cream->Rt, cpu->VFP[VFP_OFFSET(VFP_FPEXC)]);
  2937. break;
  2938. default:
  2939. DBG("\tSUBARCHITECTURE DEFINED\n");
  2940. break;
  2941. }
  2942. }
  2943. }
  2944. cpu->Reg[15] += GET_INST_SIZE(cpu);
  2945. INC_PC(sizeof(vfpinstr_inst));
  2946. FETCH_INST;
  2947. GOTO_NEXT_INST;
  2948. }
  2949. #endif
  2950. #ifdef VFP_MRC_TRANS
  2951. if (OPC_1 == 0x7 && CRm == 0 && OPC_2 == 0)
  2952. {
  2953. VMRS(state, CRn, Rt, value);
  2954. return ARMul_DONE;
  2955. }
  2956. #endif
  2957. #ifdef VFP_MRC_IMPL
  2958. void VMRS(ARMul_State * state, ARMword reg, ARMword Rt, ARMword * value)
  2959. {
  2960. DBG("VMRS :");
  2961. if (reg == 1)
  2962. {
  2963. if (Rt != 15)
  2964. {
  2965. *value = state->VFP[VFP_OFFSET(VFP_FPSCR)];
  2966. DBG("\tr%d <= fpscr[%08x]\n", Rt, state->VFP[VFP_OFFSET(VFP_FPSCR)]);
  2967. }
  2968. else
  2969. {
  2970. *value = state->VFP[VFP_OFFSET(VFP_FPSCR)] ;
  2971. DBG("\tflags <= fpscr[%1xxxxxxxx]\n", state->VFP[VFP_OFFSET(VFP_FPSCR)]>>28);
  2972. }
  2973. }
  2974. else
  2975. {
  2976. switch (reg)
  2977. {
  2978. case 0:
  2979. *value = state->VFP[VFP_OFFSET(VFP_FPSID)];
  2980. DBG("\tr%d <= fpsid[%08x]\n", Rt, state->VFP[VFP_OFFSET(VFP_FPSID)]);
  2981. break;
  2982. case 6:
  2983. /* MVFR1, VFPv3 only ? */
  2984. DBG("\tr%d <= MVFR1 unimplemented\n", Rt);
  2985. break;
  2986. case 7:
  2987. /* MVFR0, VFPv3 only? */
  2988. DBG("\tr%d <= MVFR0 unimplemented\n", Rt);
  2989. break;
  2990. case 8:
  2991. *value = state->VFP[VFP_OFFSET(VFP_FPEXC)];
  2992. DBG("\tr%d <= fpexc[%08x]\n", Rt, state->VFP[VFP_OFFSET(VFP_FPEXC)]);
  2993. break;
  2994. default:
  2995. DBG("\tSUBARCHITECTURE DEFINED\n");
  2996. break;
  2997. }
  2998. }
  2999. }
  3000. #endif
  3001. #ifdef VFP_DYNCOM_TABLE
  3002. DYNCOM_FILL_ACTION(vfpinstr),
  3003. #endif
  3004. #ifdef VFP_DYNCOM_TAG
  3005. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  3006. {
  3007. int instr_size = INSTR_SIZE;
  3008. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3009. DBG("\t\tin %s .\n", __FUNCTION__);
  3010. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  3011. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  3012. return instr_size;
  3013. }
  3014. #endif
  3015. #ifdef VFP_DYNCOM_TRANS
  3016. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  3017. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3018. //arch_arm_undef(cpu, bb, instr);
  3019. Value *data = NULL;
  3020. int reg = BITS(16, 19);;
  3021. int Rt = BITS(12, 15);
  3022. DBG("VMRS : reg=%d, Rt=%d\n", reg, Rt);
  3023. if (reg == 1)
  3024. {
  3025. if (Rt != 15)
  3026. {
  3027. LET(Rt, R(VFP_FPSCR));
  3028. DBG("\tr%d <= fpscr\n", Rt);
  3029. }
  3030. else
  3031. {
  3032. //LET(Rt, R(VFP_FPSCR));
  3033. update_cond_from_fpscr(cpu, instr, bb, pc);
  3034. DBG("In %s, \tflags <= fpscr\n", __FUNCTION__);
  3035. }
  3036. }
  3037. else
  3038. {
  3039. switch (reg)
  3040. {
  3041. case 0:
  3042. LET(Rt, R(VFP_FPSID));
  3043. DBG("\tr%d <= fpsid\n", Rt);
  3044. break;
  3045. case 6:
  3046. /* MVFR1, VFPv3 only ? */
  3047. DBG("\tr%d <= MVFR1 unimplemented\n", Rt);
  3048. break;
  3049. case 7:
  3050. /* MVFR0, VFPv3 only? */
  3051. DBG("\tr%d <= MVFR0 unimplemented\n", Rt);
  3052. break;
  3053. case 8:
  3054. LET(Rt, R(VFP_FPEXC));
  3055. DBG("\tr%d <= fpexc\n", Rt);
  3056. break;
  3057. default:
  3058. DBG("\tSUBARCHITECTURE DEFINED\n");
  3059. break;
  3060. }
  3061. }
  3062. return No_exp;
  3063. }
  3064. #endif
  3065. #undef vfpinstr
  3066. #undef vfpinstr_inst
  3067. #undef VFPLABEL_INST
  3068. /* ----------------------------------------------------------------------- */
  3069. /* VMOVBCR scalar to register */
  3070. /* cond 1110 XXX1 Vd-- Rt-- 1011 NXX1 0000 */
  3071. /* cond 1110 op11 CRn- Rt-- copr op21 CRm- MCR */
  3072. #define vfpinstr vmovbcr
  3073. #define vfpinstr_inst vmovbcr_inst
  3074. #define VFPLABEL_INST VMOVBCR_INST
  3075. #ifdef VFP_DECODE
  3076. {"vmovbcr", 4, ARMVFP2, 24, 27, 0xE, 20, 20, 1, 8, 11,0xB, 0,4, 0x10},
  3077. #endif
  3078. #ifdef VFP_DECODE_EXCLUSION
  3079. {"vmovbcr", 0, ARMVFP2, 0},
  3080. #endif
  3081. #ifdef VFP_INTERPRETER_TABLE
  3082. INTERPRETER_TRANSLATE(vfpinstr),
  3083. #endif
  3084. #ifdef VFP_INTERPRETER_LABEL
  3085. &&VFPLABEL_INST,
  3086. #endif
  3087. #ifdef VFP_INTERPRETER_STRUCT
  3088. typedef struct _vmovbcr_inst {
  3089. unsigned int esize;
  3090. unsigned int index;
  3091. unsigned int d;
  3092. unsigned int t;
  3093. } vfpinstr_inst;
  3094. #endif
  3095. #ifdef VFP_INTERPRETER_TRANS
  3096. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  3097. {
  3098. VFP_DEBUG_TRANSLATE;
  3099. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  3100. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3101. inst_base->cond = BITS(inst, 28, 31);
  3102. inst_base->idx = index;
  3103. inst_base->br = NON_BRANCH;
  3104. inst_base->load_r15 = 0;
  3105. inst_cream->d = BITS(inst, 16, 19)|BIT(inst, 7)<<4;
  3106. inst_cream->t = BITS(inst, 12, 15);
  3107. /* VFP variant of instruction */
  3108. inst_cream->esize = 32;
  3109. inst_cream->index = BIT(inst, 21);
  3110. return inst_base;
  3111. }
  3112. #endif
  3113. #ifdef VFP_INTERPRETER_IMPL
  3114. VFPLABEL_INST:
  3115. {
  3116. INC_ICOUNTER;
  3117. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3118. CHECK_VFP_ENABLED;
  3119. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3120. VFP_DEBUG_UNIMPLEMENTED(VMOVBCR);
  3121. }
  3122. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3123. INC_PC(sizeof(vfpinstr_inst));
  3124. FETCH_INST;
  3125. GOTO_NEXT_INST;
  3126. }
  3127. #endif
  3128. #ifdef VFP_MCR_TRANS
  3129. if (CoProc == 11 && CRm == 0)
  3130. {
  3131. VFP_DEBUG_UNIMPLEMENTED(VMOVBCR);
  3132. return ARMul_DONE;
  3133. }
  3134. #endif
  3135. #ifdef VFP_DYNCOM_TABLE
  3136. DYNCOM_FILL_ACTION(vfpinstr),
  3137. #endif
  3138. #ifdef VFP_DYNCOM_TAG
  3139. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  3140. {
  3141. int instr_size = INSTR_SIZE;
  3142. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3143. arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  3144. return instr_size;
  3145. }
  3146. #endif
  3147. #ifdef VFP_DYNCOM_TRANS
  3148. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  3149. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3150. arch_arm_undef(cpu, bb, instr);
  3151. return No_exp;
  3152. }
  3153. #endif
  3154. #undef vfpinstr
  3155. #undef vfpinstr_inst
  3156. #undef VFPLABEL_INST
  3157. /* ----------------------------------------------------------------------- */
  3158. /* MRRC / MCRR instructions */
  3159. /* cond 1100 0101 Rt2- Rt-- copr opc1 CRm- MRRC */
  3160. /* cond 1100 0100 Rt2- Rt-- copr opc1 CRm- MCRR */
  3161. /* ----------------------------------------------------------------------- */
  3162. /* VMOVBRRSS between 2 registers to 2 singles */
  3163. /* cond 1100 010X Rt2- Rt-- 1010 00X1 Vm-- */
  3164. /* cond 1100 0101 Rt2- Rt-- copr opc1 CRm- MRRC */
  3165. #define vfpinstr vmovbrrss
  3166. #define vfpinstr_inst vmovbrrss_inst
  3167. #define VFPLABEL_INST VMOVBRRSS_INST
  3168. #ifdef VFP_DECODE
  3169. {"vmovbrrss", 3, ARMVFP2, 21, 27, 0x62, 8, 11, 0xA, 4, 4, 1},
  3170. #endif
  3171. #ifdef VFP_DECODE_EXCLUSION
  3172. {"vmovbrrss", 0, ARMVFP2, 0},
  3173. #endif
  3174. #ifdef VFP_INTERPRETER_TABLE
  3175. INTERPRETER_TRANSLATE(vfpinstr),
  3176. #endif
  3177. #ifdef VFP_INTERPRETER_LABEL
  3178. &&VFPLABEL_INST,
  3179. #endif
  3180. #ifdef VFP_INTERPRETER_STRUCT
  3181. typedef struct _vmovbrrss_inst {
  3182. unsigned int to_arm;
  3183. unsigned int t;
  3184. unsigned int t2;
  3185. unsigned int m;
  3186. } vfpinstr_inst;
  3187. #endif
  3188. #ifdef VFP_INTERPRETER_TRANS
  3189. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  3190. {
  3191. VFP_DEBUG_TRANSLATE;
  3192. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  3193. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3194. inst_base->cond = BITS(inst, 28, 31);
  3195. inst_base->idx = index;
  3196. inst_base->br = NON_BRANCH;
  3197. inst_base->load_r15 = 0;
  3198. inst_cream->to_arm = BIT(inst, 20) == 1;
  3199. inst_cream->t = BITS(inst, 12, 15);
  3200. inst_cream->t2 = BITS(inst, 16, 19);
  3201. inst_cream->m = BITS(inst, 0, 3)<<1|BIT(inst, 5);
  3202. return inst_base;
  3203. }
  3204. #endif
  3205. #ifdef VFP_INTERPRETER_IMPL
  3206. VFPLABEL_INST:
  3207. {
  3208. INC_ICOUNTER;
  3209. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3210. CHECK_VFP_ENABLED;
  3211. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3212. VFP_DEBUG_UNIMPLEMENTED(VMOVBRRSS);
  3213. }
  3214. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3215. INC_PC(sizeof(vfpinstr_inst));
  3216. FETCH_INST;
  3217. GOTO_NEXT_INST;
  3218. }
  3219. #endif
  3220. #ifdef VFP_MCRR_TRANS
  3221. if (CoProc == 10 && (OPC_1 & 0xD) == 1)
  3222. {
  3223. VFP_DEBUG_UNIMPLEMENTED(VMOVBRRSS);
  3224. return ARMul_DONE;
  3225. }
  3226. #endif
  3227. #ifdef VFP_MRRC_TRANS
  3228. if (CoProc == 10 && (OPC_1 & 0xD) == 1)
  3229. {
  3230. VFP_DEBUG_UNIMPLEMENTED(VMOVBRRSS);
  3231. return ARMul_DONE;
  3232. }
  3233. #endif
  3234. #ifdef VFP_DYNCOM_TABLE
  3235. DYNCOM_FILL_ACTION(vfpinstr),
  3236. #endif
  3237. #ifdef VFP_DYNCOM_TAG
  3238. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  3239. {
  3240. int instr_size = INSTR_SIZE;
  3241. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3242. arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  3243. return instr_size;
  3244. }
  3245. #endif
  3246. #ifdef VFP_DYNCOM_TRANS
  3247. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  3248. DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3249. arch_arm_undef(cpu, bb, instr);
  3250. return No_exp;
  3251. }
  3252. #endif
  3253. #undef vfpinstr
  3254. #undef vfpinstr_inst
  3255. #undef VFPLABEL_INST
  3256. /* ----------------------------------------------------------------------- */
  3257. /* VMOVBRRD between 2 registers and 1 double */
  3258. /* cond 1100 010X Rt2- Rt-- 1011 00X1 Vm-- */
  3259. /* cond 1100 0101 Rt2- Rt-- copr opc1 CRm- MRRC */
  3260. #define vfpinstr vmovbrrd
  3261. #define vfpinstr_inst vmovbrrd_inst
  3262. #define VFPLABEL_INST VMOVBRRD_INST
  3263. #ifdef VFP_DECODE
  3264. {"vmovbrrd", 3, ARMVFP2, 21, 27, 0x62, 6, 11, 0x2c, 4, 4, 1},
  3265. #endif
  3266. #ifdef VFP_DECODE_EXCLUSION
  3267. {"vmovbrrd", 0, ARMVFP2, 0},
  3268. #endif
  3269. #ifdef VFP_INTERPRETER_TABLE
  3270. INTERPRETER_TRANSLATE(vfpinstr),
  3271. #endif
  3272. #ifdef VFP_INTERPRETER_LABEL
  3273. &&VFPLABEL_INST,
  3274. #endif
  3275. #ifdef VFP_INTERPRETER_STRUCT
  3276. typedef struct _vmovbrrd_inst {
  3277. unsigned int to_arm;
  3278. unsigned int t;
  3279. unsigned int t2;
  3280. unsigned int m;
  3281. } vfpinstr_inst;
  3282. #endif
  3283. #ifdef VFP_INTERPRETER_TRANS
  3284. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  3285. {
  3286. VFP_DEBUG_TRANSLATE;
  3287. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  3288. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3289. inst_base->cond = BITS(inst, 28, 31);
  3290. inst_base->idx = index;
  3291. inst_base->br = NON_BRANCH;
  3292. inst_base->load_r15 = 0;
  3293. inst_cream->to_arm = BIT(inst, 20) == 1;
  3294. inst_cream->t = BITS(inst, 12, 15);
  3295. inst_cream->t2 = BITS(inst, 16, 19);
  3296. inst_cream->m = BIT(inst, 5)<<4 | BITS(inst, 0, 3);
  3297. return inst_base;
  3298. }
  3299. #endif
  3300. #ifdef VFP_INTERPRETER_IMPL
  3301. VFPLABEL_INST:
  3302. {
  3303. INC_ICOUNTER;
  3304. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3305. CHECK_VFP_ENABLED;
  3306. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3307. VMOVBRRD(cpu, inst_cream->to_arm, inst_cream->t, inst_cream->t2, inst_cream->m,
  3308. &(cpu->Reg[inst_cream->t]), &(cpu->Reg[inst_cream->t2]));
  3309. }
  3310. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3311. INC_PC(sizeof(vfpinstr_inst));
  3312. FETCH_INST;
  3313. GOTO_NEXT_INST;
  3314. }
  3315. #endif
  3316. #ifdef VFP_MCRR_TRANS
  3317. if (CoProc == 11 && (OPC_1 & 0xD) == 1)
  3318. {
  3319. /* Transfering Rt and Rt2 is not mandatory, as the value of interest is pointed by value1 and value2 */
  3320. VMOVBRRD(state, BIT(20), Rt, Rt2, BIT(5)<<4|CRm, &value1, &value2);
  3321. return ARMul_DONE;
  3322. }
  3323. #endif
  3324. #ifdef VFP_MRRC_TRANS
  3325. if (CoProc == 11 && (OPC_1 & 0xD) == 1)
  3326. {
  3327. /* Transfering Rt and Rt2 is not mandatory, as the value of interest is pointed by value1 and value2 */
  3328. VMOVBRRD(state, BIT(20), Rt, Rt2, BIT(5)<<4|CRm, value1, value2);
  3329. return ARMul_DONE;
  3330. }
  3331. #endif
  3332. #ifdef VFP_MRRC_IMPL
  3333. void VMOVBRRD(ARMul_State * state, ARMword to_arm, ARMword t, ARMword t2, ARMword n, ARMword *value1, ARMword *value2)
  3334. {
  3335. DBG("VMOV(BRRD) :\n");
  3336. if (to_arm)
  3337. {
  3338. DBG("\tr[%d-%d] <= s[%d-%d]=[%x-%x]\n", t2, t, n*2+1, n*2, state->ExtReg[n*2+1], state->ExtReg[n*2]);
  3339. *value2 = state->ExtReg[n*2+1];
  3340. *value1 = state->ExtReg[n*2];
  3341. }
  3342. else
  3343. {
  3344. DBG("\ts[%d-%d] <= r[%d-%d]=[%x-%x]\n", n*2+1, n*2, t2, t, *value2, *value1);
  3345. state->ExtReg[n*2+1] = *value2;
  3346. state->ExtReg[n*2] = *value1;
  3347. }
  3348. }
  3349. #endif
  3350. #ifdef VFP_DYNCOM_TABLE
  3351. DYNCOM_FILL_ACTION(vfpinstr),
  3352. #endif
  3353. #ifdef VFP_DYNCOM_TAG
  3354. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  3355. {
  3356. int instr_size = INSTR_SIZE;
  3357. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3358. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  3359. if(instr >> 28 != 0xe)
  3360. *tag |= TAG_CONDITIONAL;
  3361. return instr_size;
  3362. }
  3363. #endif
  3364. #ifdef VFP_DYNCOM_TRANS
  3365. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  3366. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3367. //arch_arm_undef(cpu, bb, instr);
  3368. int to_arm = BIT(20) == 1;
  3369. int t = BITS(12, 15);
  3370. int t2 = BITS(16, 19);
  3371. int n = BIT(5)<<4 | BITS(0, 3);
  3372. if(to_arm){
  3373. LET(t, IBITCAST32(FR32(n * 2)));
  3374. LET(t2, IBITCAST32(FR32(n * 2 + 1)));
  3375. }
  3376. else{
  3377. LETFPS(n * 2, FPBITCAST32(R(t)));
  3378. LETFPS(n * 2 + 1, FPBITCAST32(R(t2)));
  3379. }
  3380. return No_exp;
  3381. }
  3382. #endif
  3383. #undef vfpinstr
  3384. #undef vfpinstr_inst
  3385. #undef VFPLABEL_INST
  3386. /* ----------------------------------------------------------------------- */
  3387. /* LDC/STC between 2 registers and 1 double */
  3388. /* cond 110X XXX1 Rn-- CRd- copr imm- imm- LDC */
  3389. /* cond 110X XXX0 Rn-- CRd- copr imm8 imm8 STC */
  3390. /* ----------------------------------------------------------------------- */
  3391. /* VSTR */
  3392. /* cond 1101 UD00 Rn-- Vd-- 101X imm8 imm8 */
  3393. #define vfpinstr vstr
  3394. #define vfpinstr_inst vstr_inst
  3395. #define VFPLABEL_INST VSTR_INST
  3396. #ifdef VFP_DECODE
  3397. {"vstr", 3, ARMVFP2, 24, 27, 0xd, 20, 21, 0, 9, 11, 0x5},
  3398. #endif
  3399. #ifdef VFP_DECODE_EXCLUSION
  3400. {"vstr", 0, ARMVFP2, 0},
  3401. #endif
  3402. #ifdef VFP_INTERPRETER_TABLE
  3403. INTERPRETER_TRANSLATE(vfpinstr),
  3404. #endif
  3405. #ifdef VFP_INTERPRETER_LABEL
  3406. &&VFPLABEL_INST,
  3407. #endif
  3408. #ifdef VFP_INTERPRETER_STRUCT
  3409. typedef struct _vstr_inst {
  3410. unsigned int single;
  3411. unsigned int n;
  3412. unsigned int d;
  3413. unsigned int imm32;
  3414. unsigned int add;
  3415. } vfpinstr_inst;
  3416. #endif
  3417. #ifdef VFP_INTERPRETER_TRANS
  3418. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  3419. {
  3420. VFP_DEBUG_TRANSLATE;
  3421. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  3422. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3423. inst_base->cond = BITS(inst, 28, 31);
  3424. inst_base->idx = index;
  3425. inst_base->br = NON_BRANCH;
  3426. inst_base->load_r15 = 0;
  3427. inst_cream->single = BIT(inst, 8) == 0;
  3428. inst_cream->add = BIT(inst, 23);
  3429. inst_cream->imm32 = BITS(inst, 0,7) << 2;
  3430. inst_cream->d = (inst_cream->single ? BITS(inst, 12, 15)<<1|BIT(inst, 22) : BITS(inst, 12, 15)|BIT(inst, 22)<<4);
  3431. inst_cream->n = BITS(inst, 16, 19);
  3432. return inst_base;
  3433. }
  3434. #endif
  3435. #ifdef VFP_INTERPRETER_IMPL
  3436. VFPLABEL_INST:
  3437. {
  3438. INC_ICOUNTER;
  3439. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3440. CHECK_VFP_ENABLED;
  3441. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3442. unsigned int base = (inst_cream->n == 15 ? (cpu->Reg[inst_cream->n] & 0xFFFFFFFC) + 8 : cpu->Reg[inst_cream->n]);
  3443. addr = (inst_cream->add ? base + inst_cream->imm32 : base - inst_cream->imm32);
  3444. DBG("VSTR :\n");
  3445. if (inst_cream->single)
  3446. {
  3447. fault = check_address_validity(cpu, addr, &phys_addr, 0);
  3448. if (fault) goto MMU_EXCEPTION;
  3449. fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d], 32);
  3450. if (fault) goto MMU_EXCEPTION;
  3451. DBG("\taddr[%x] <= s%d=[%x]\n", addr, inst_cream->d, cpu->ExtReg[inst_cream->d]);
  3452. }
  3453. else
  3454. {
  3455. fault = check_address_validity(cpu, addr, &phys_addr, 0);
  3456. if (fault) goto MMU_EXCEPTION;
  3457. /* Check endianness */
  3458. fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d*2], 32);
  3459. if (fault) goto MMU_EXCEPTION;
  3460. fault = check_address_validity(cpu, addr + 4, &phys_addr, 0);
  3461. if (fault) goto MMU_EXCEPTION;
  3462. fault = interpreter_write_memory(core, addr + 4, phys_addr, cpu->ExtReg[inst_cream->d*2+1], 32);
  3463. if (fault) goto MMU_EXCEPTION;
  3464. DBG("\taddr[%x-%x] <= s[%d-%d]=[%x-%x]\n", addr+4, addr, inst_cream->d*2+1, inst_cream->d*2, cpu->ExtReg[inst_cream->d*2+1], cpu->ExtReg[inst_cream->d*2]);
  3465. }
  3466. }
  3467. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3468. INC_PC(sizeof(vstr_inst));
  3469. FETCH_INST;
  3470. GOTO_NEXT_INST;
  3471. }
  3472. #endif
  3473. #ifdef VFP_STC_TRANS
  3474. if (P == 1 && W == 0)
  3475. {
  3476. return VSTR(state, type, instr, value);
  3477. }
  3478. #endif
  3479. #ifdef VFP_STC_IMPL
  3480. int VSTR(ARMul_State * state, int type, ARMword instr, ARMword * value)
  3481. {
  3482. static int i = 0;
  3483. static int single_reg, add, d, n, imm32, regs;
  3484. if (type == ARMul_FIRST)
  3485. {
  3486. single_reg = BIT(8) == 0; /* Double precision */
  3487. add = BIT(23); /* */
  3488. imm32 = BITS(0,7)<<2; /* may not be used */
  3489. d = single_reg ? BITS(12, 15)<<1|BIT(22) : BIT(22)<<4|BITS(12, 15); /* Base register */
  3490. n = BITS(16, 19); /* destination register */
  3491. DBG("VSTR :\n");
  3492. i = 0;
  3493. regs = 1;
  3494. return ARMul_DONE;
  3495. }
  3496. else if (type == ARMul_DATA)
  3497. {
  3498. if (single_reg)
  3499. {
  3500. *value = state->ExtReg[d+i];
  3501. DBG("\taddr[?] <= s%d=[%x]\n", d+i, state->ExtReg[d+i]);
  3502. i++;
  3503. if (i < regs)
  3504. return ARMul_INC;
  3505. else
  3506. return ARMul_DONE;
  3507. }
  3508. else
  3509. {
  3510. /* FIXME Careful of endianness, may need to rework this */
  3511. *value = state->ExtReg[d*2+i];
  3512. DBG("\taddr[?] <= s[%d]=[%x]\n", d*2+i, state->ExtReg[d*2+i]);
  3513. i++;
  3514. if (i < regs*2)
  3515. return ARMul_INC;
  3516. else
  3517. return ARMul_DONE;
  3518. }
  3519. }
  3520. return -1;
  3521. }
  3522. #endif
  3523. #ifdef VFP_DYNCOM_TABLE
  3524. DYNCOM_FILL_ACTION(vfpinstr),
  3525. #endif
  3526. #ifdef VFP_DYNCOM_TAG
  3527. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  3528. {
  3529. int instr_size = INSTR_SIZE;
  3530. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  3531. DBG("In %s, pc=0x%x, next_pc=0x%x\n", __FUNCTION__, pc, *next_pc);
  3532. *tag |= TAG_NEW_BB;
  3533. if(instr >> 28 != 0xe)
  3534. *tag |= TAG_CONDITIONAL;
  3535. return instr_size;
  3536. }
  3537. #endif
  3538. #ifdef VFP_DYNCOM_TRANS
  3539. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  3540. int single = BIT(8) == 0;
  3541. int add = BIT(23);
  3542. int imm32 = BITS(0,7) << 2;
  3543. int d = (single ? BITS(12, 15)<<1|BIT(22) : BITS(12, 15)|(BIT(22)<<4));
  3544. int n = BITS(16, 19);
  3545. Value* base = (n == 15) ? ADD(AND(R(n), CONST(0xFFFFFFFC)), CONST(8)): R(n);
  3546. Value* Addr = add ? ADD(base, CONST(imm32)) : SUB(base, CONST(imm32));
  3547. DBG("VSTR :\n");
  3548. //if(single)
  3549. // bb = arch_check_mm(cpu, bb, Addr, 4, 0, cpu->dyncom_engine->bb_trap);
  3550. //else
  3551. // bb = arch_check_mm(cpu, bb, Addr, 8, 0, cpu->dyncom_engine->bb_trap);
  3552. //Value* phys_addr;
  3553. if(single){
  3554. #if 0
  3555. phys_addr = get_phys_addr(cpu, bb, Addr, 0);
  3556. bb = cpu->dyncom_engine->bb;
  3557. arch_write_memory(cpu, bb, phys_addr, RSPR(d), 32);
  3558. #endif
  3559. //memory_write(cpu, bb, Addr, RSPR(d), 32);
  3560. memory_write(cpu, bb, Addr, IBITCAST32(FR32(d)), 32);
  3561. bb = cpu->dyncom_engine->bb;
  3562. }
  3563. else{
  3564. #if 0
  3565. phys_addr = get_phys_addr(cpu, bb, Addr, 0);
  3566. bb = cpu->dyncom_engine->bb;
  3567. arch_write_memory(cpu, bb, phys_addr, RSPR(d * 2), 32);
  3568. #endif
  3569. //memory_write(cpu, bb, Addr, RSPR(d * 2), 32);
  3570. memory_write(cpu, bb, Addr, IBITCAST32(FR32(d * 2)), 32);
  3571. bb = cpu->dyncom_engine->bb;
  3572. #if 0
  3573. phys_addr = get_phys_addr(cpu, bb, ADD(Addr, CONST(4)), 0);
  3574. bb = cpu->dyncom_engine->bb;
  3575. arch_write_memory(cpu, bb, phys_addr, RSPR(d * 2 + 1), 32);
  3576. #endif
  3577. //memory_write(cpu, bb, ADD(Addr, CONST(4)), RSPR(d * 2 + 1), 32);
  3578. memory_write(cpu, bb, ADD(Addr, CONST(4)), IBITCAST32(FR32(d * 2 + 1)), 32);
  3579. bb = cpu->dyncom_engine->bb;
  3580. }
  3581. return No_exp;
  3582. }
  3583. #endif
  3584. #undef vfpinstr
  3585. #undef vfpinstr_inst
  3586. #undef VFPLABEL_INST
  3587. /* ----------------------------------------------------------------------- */
  3588. /* VPUSH */
  3589. /* cond 1101 0D10 1101 Vd-- 101X imm8 imm8 */
  3590. #define vfpinstr vpush
  3591. #define vfpinstr_inst vpush_inst
  3592. #define VFPLABEL_INST VPUSH_INST
  3593. #ifdef VFP_DECODE
  3594. {"vpush", 3, ARMVFP2, 23, 27, 0x1a, 16, 21, 0x2d, 9, 11, 0x5},
  3595. #endif
  3596. #ifdef VFP_DECODE_EXCLUSION
  3597. {"vpush", 0, ARMVFP2, 0},
  3598. #endif
  3599. #ifdef VFP_INTERPRETER_TABLE
  3600. INTERPRETER_TRANSLATE(vfpinstr),
  3601. #endif
  3602. #ifdef VFP_INTERPRETER_LABEL
  3603. &&VFPLABEL_INST,
  3604. #endif
  3605. #ifdef VFP_INTERPRETER_STRUCT
  3606. typedef struct _vpush_inst {
  3607. unsigned int single;
  3608. unsigned int d;
  3609. unsigned int imm32;
  3610. unsigned int regs;
  3611. } vfpinstr_inst;
  3612. #endif
  3613. #ifdef VFP_INTERPRETER_TRANS
  3614. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  3615. {
  3616. VFP_DEBUG_TRANSLATE;
  3617. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  3618. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3619. inst_base->cond = BITS(inst, 28, 31);
  3620. inst_base->idx = index;
  3621. inst_base->br = NON_BRANCH;
  3622. inst_base->load_r15 = 0;
  3623. inst_cream->single = BIT(inst, 8) == 0;
  3624. inst_cream->d = (inst_cream->single ? BITS(inst, 12, 15)<<1|BIT(inst, 22) : BITS(inst, 12, 15)|BIT(inst, 22)<<4);
  3625. inst_cream->imm32 = BITS(inst, 0, 7)<<2;
  3626. inst_cream->regs = (inst_cream->single ? BITS(inst, 0, 7) : BITS(inst, 1, 7));
  3627. return inst_base;
  3628. }
  3629. #endif
  3630. #ifdef VFP_INTERPRETER_IMPL
  3631. VFPLABEL_INST:
  3632. {
  3633. INC_ICOUNTER;
  3634. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3635. CHECK_VFP_ENABLED;
  3636. int i;
  3637. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3638. DBG("VPUSH :\n");
  3639. addr = cpu->Reg[R13] - inst_cream->imm32;
  3640. for (i = 0; i < inst_cream->regs; i++)
  3641. {
  3642. if (inst_cream->single)
  3643. {
  3644. fault = check_address_validity(cpu, addr, &phys_addr, 0);
  3645. if (fault) goto MMU_EXCEPTION;
  3646. fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d+i], 32);
  3647. if (fault) goto MMU_EXCEPTION;
  3648. DBG("\taddr[%x] <= s%d=[%x]\n", addr, inst_cream->d+i, cpu->ExtReg[inst_cream->d+i]);
  3649. addr += 4;
  3650. }
  3651. else
  3652. {
  3653. /* Careful of endianness, little by default */
  3654. fault = check_address_validity(cpu, addr, &phys_addr, 0);
  3655. if (fault) goto MMU_EXCEPTION;
  3656. fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2], 32);
  3657. if (fault) goto MMU_EXCEPTION;
  3658. fault = check_address_validity(cpu, addr + 4, &phys_addr, 0);
  3659. if (fault) goto MMU_EXCEPTION;
  3660. fault = interpreter_write_memory(core, addr + 4, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2 + 1], 32);
  3661. if (fault) goto MMU_EXCEPTION;
  3662. DBG("\taddr[%x-%x] <= s[%d-%d]=[%x-%x]\n", addr+4, addr, (inst_cream->d+i)*2+1, (inst_cream->d+i)*2, cpu->ExtReg[(inst_cream->d+i)*2+1], cpu->ExtReg[(inst_cream->d+i)*2]);
  3663. addr += 8;
  3664. }
  3665. }
  3666. DBG("\tsp[%x]", cpu->Reg[R13]);
  3667. cpu->Reg[R13] = cpu->Reg[R13] - inst_cream->imm32;
  3668. DBG("=>[%x]\n", cpu->Reg[R13]);
  3669. }
  3670. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3671. INC_PC(sizeof(vpush_inst));
  3672. FETCH_INST;
  3673. GOTO_NEXT_INST;
  3674. }
  3675. #endif
  3676. #ifdef VFP_STC_TRANS
  3677. if (P == 1 && U == 0 && W == 1 && Rn == 0xD)
  3678. {
  3679. return VPUSH(state, type, instr, value);
  3680. }
  3681. #endif
  3682. #ifdef VFP_STC_IMPL
  3683. int VPUSH(ARMul_State * state, int type, ARMword instr, ARMword * value)
  3684. {
  3685. static int i = 0;
  3686. static int single_regs, add, wback, d, n, imm32, regs;
  3687. if (type == ARMul_FIRST)
  3688. {
  3689. single_regs = BIT(8) == 0; /* Single precision */
  3690. d = single_regs ? BITS(12, 15)<<1|BIT(22) : BIT(22)<<4|BITS(12, 15); /* Base register */
  3691. imm32 = BITS(0,7)<<2; /* may not be used */
  3692. regs = single_regs ? BITS(0, 7) : BITS(1, 7); /* FSTMX if regs is odd */
  3693. DBG("VPUSH :\n");
  3694. DBG("\tsp[%x]", state->Reg[R13]);
  3695. state->Reg[R13] = state->Reg[R13] - imm32;
  3696. DBG("=>[%x]\n", state->Reg[R13]);
  3697. i = 0;
  3698. return ARMul_DONE;
  3699. }
  3700. else if (type == ARMul_DATA)
  3701. {
  3702. if (single_regs)
  3703. {
  3704. *value = state->ExtReg[d + i];
  3705. DBG("\taddr[?] <= s%d=[%x]\n", d+i, state->ExtReg[d + i]);
  3706. i++;
  3707. if (i < regs)
  3708. return ARMul_INC;
  3709. else
  3710. return ARMul_DONE;
  3711. }
  3712. else
  3713. {
  3714. /* FIXME Careful of endianness, may need to rework this */
  3715. *value = state->ExtReg[d*2 + i];
  3716. DBG("\taddr[?] <= s[%d]=[%x]\n", d*2 + i, state->ExtReg[d*2 + i]);
  3717. i++;
  3718. if (i < regs*2)
  3719. return ARMul_INC;
  3720. else
  3721. return ARMul_DONE;
  3722. }
  3723. }
  3724. return -1;
  3725. }
  3726. #endif
  3727. #ifdef VFP_DYNCOM_TABLE
  3728. DYNCOM_FILL_ACTION(vfpinstr),
  3729. #endif
  3730. #ifdef VFP_DYNCOM_TAG
  3731. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  3732. {
  3733. int instr_size = INSTR_SIZE;
  3734. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  3735. DBG("In %s, pc=0x%x, next_pc=0x%x\n", __FUNCTION__, pc, *next_pc);
  3736. *tag |= TAG_NEW_BB;
  3737. if(instr >> 28 != 0xe)
  3738. *tag |= TAG_CONDITIONAL;
  3739. return instr_size;
  3740. }
  3741. #endif
  3742. #ifdef VFP_DYNCOM_TRANS
  3743. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  3744. int single = BIT(8) == 0;
  3745. int d = (single ? BITS(12, 15)<<1|BIT(22) : BITS(12, 15)|(BIT(22)<<4));
  3746. int imm32 = BITS(0, 7)<<2;
  3747. int regs = (single ? BITS(0, 7) : BITS(1, 7));
  3748. DBG("\t\tin %s \n", __FUNCTION__);
  3749. Value* Addr = SUB(R(13), CONST(imm32));
  3750. //if(single)
  3751. // bb = arch_check_mm(cpu, bb, Addr, regs * 4, 0, cpu->dyncom_engine->bb_trap);
  3752. //else
  3753. // bb = arch_check_mm(cpu, bb, Addr, regs * 8, 0, cpu->dyncom_engine->bb_trap);
  3754. //Value* phys_addr;
  3755. int i;
  3756. for (i = 0; i < regs; i++)
  3757. {
  3758. if (single)
  3759. {
  3760. //fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d+i], 32);
  3761. #if 0
  3762. phys_addr = get_phys_addr(cpu, bb, Addr, 0);
  3763. bb = cpu->dyncom_engine->bb;
  3764. arch_write_memory(cpu, bb, phys_addr, RSPR(d + i), 32);
  3765. #endif
  3766. //memory_write(cpu, bb, Addr, RSPR(d + i), 32);
  3767. memory_write(cpu, bb, Addr, IBITCAST32(FR32(d + i)), 32);
  3768. bb = cpu->dyncom_engine->bb;
  3769. Addr = ADD(Addr, CONST(4));
  3770. }
  3771. else
  3772. {
  3773. /* Careful of endianness, little by default */
  3774. #if 0
  3775. phys_addr = get_phys_addr(cpu, bb, Addr, 0);
  3776. bb = cpu->dyncom_engine->bb;
  3777. arch_write_memory(cpu, bb, phys_addr, RSPR((d + i) * 2), 32);
  3778. #endif
  3779. //memory_write(cpu, bb, Addr, RSPR((d + i) * 2), 32);
  3780. memory_write(cpu, bb, Addr, IBITCAST32(FR32((d + i) * 2)), 32);
  3781. bb = cpu->dyncom_engine->bb;
  3782. #if 0
  3783. phys_addr = get_phys_addr(cpu, bb, ADD(Addr, CONST(4)), 0);
  3784. bb = cpu->dyncom_engine->bb;
  3785. arch_write_memory(cpu, bb, phys_addr, RSPR((d + i) * 2 + 1), 32);
  3786. #endif
  3787. //memory_write(cpu, bb, ADD(Addr, CONST(4)), RSPR((d + i) * 2 + 1), 32);
  3788. memory_write(cpu, bb, ADD(Addr, CONST(4)), IBITCAST32(FR32((d + i) * 2 + 1)), 32);
  3789. bb = cpu->dyncom_engine->bb;
  3790. Addr = ADD(Addr, CONST(8));
  3791. }
  3792. }
  3793. LET(13, SUB(R(13), CONST(imm32)));
  3794. return No_exp;
  3795. }
  3796. #endif
  3797. #undef vfpinstr
  3798. #undef vfpinstr_inst
  3799. #undef VFPLABEL_INST
  3800. /* ----------------------------------------------------------------------- */
  3801. /* VSTM */
  3802. /* cond 110P UDW0 Rn-- Vd-- 101X imm8 imm8 */
  3803. #define vfpinstr vstm
  3804. #define vfpinstr_inst vstm_inst
  3805. #define VFPLABEL_INST VSTM_INST
  3806. #ifdef VFP_DECODE
  3807. {"vstm", 3, ARMVFP2, 25, 27, 0x6, 20, 20, 0, 9, 11, 0x5},
  3808. #endif
  3809. #ifdef VFP_DECODE_EXCLUSION
  3810. {"vstm", 0, ARMVFP2, 0},
  3811. #endif
  3812. #ifdef VFP_INTERPRETER_TABLE
  3813. INTERPRETER_TRANSLATE(vfpinstr),
  3814. #endif
  3815. #ifdef VFP_INTERPRETER_LABEL
  3816. &&VFPLABEL_INST,
  3817. #endif
  3818. #ifdef VFP_INTERPRETER_STRUCT
  3819. typedef struct _vstm_inst {
  3820. unsigned int single;
  3821. unsigned int add;
  3822. unsigned int wback;
  3823. unsigned int d;
  3824. unsigned int n;
  3825. unsigned int imm32;
  3826. unsigned int regs;
  3827. } vfpinstr_inst;
  3828. #endif
  3829. #ifdef VFP_INTERPRETER_TRANS
  3830. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  3831. {
  3832. VFP_DEBUG_TRANSLATE;
  3833. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  3834. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3835. inst_base->cond = BITS(inst, 28, 31);
  3836. inst_base->idx = index;
  3837. inst_base->br = NON_BRANCH;
  3838. inst_base->load_r15 = 0;
  3839. inst_cream->single = BIT(inst, 8) == 0;
  3840. inst_cream->add = BIT(inst, 23);
  3841. inst_cream->wback = BIT(inst, 21);
  3842. inst_cream->d = (inst_cream->single ? BITS(inst, 12, 15)<<1|BIT(inst, 22) : BITS(inst, 12, 15)|BIT(inst, 22)<<4);
  3843. inst_cream->n = BITS(inst, 16, 19);
  3844. inst_cream->imm32 = BITS(inst, 0, 7)<<2;
  3845. inst_cream->regs = (inst_cream->single ? BITS(inst, 0, 7) : BITS(inst, 1, 7));
  3846. return inst_base;
  3847. }
  3848. #endif
  3849. #ifdef VFP_INTERPRETER_IMPL
  3850. VFPLABEL_INST: /* encoding 1 */
  3851. {
  3852. INC_ICOUNTER;
  3853. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3854. CHECK_VFP_ENABLED;
  3855. int i;
  3856. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  3857. addr = (inst_cream->add ? cpu->Reg[inst_cream->n] : cpu->Reg[inst_cream->n] - inst_cream->imm32);
  3858. DBG("VSTM : addr[%x]\n", addr);
  3859. for (i = 0; i < inst_cream->regs; i++)
  3860. {
  3861. if (inst_cream->single)
  3862. {
  3863. fault = check_address_validity(cpu, addr, &phys_addr, 0);
  3864. if (fault) goto MMU_EXCEPTION;
  3865. fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d+i], 32);
  3866. if (fault) goto MMU_EXCEPTION;
  3867. DBG("\taddr[%x] <= s%d=[%x]\n", addr, inst_cream->d+i, cpu->ExtReg[inst_cream->d+i]);
  3868. addr += 4;
  3869. }
  3870. else
  3871. {
  3872. /* Careful of endianness, little by default */
  3873. fault = check_address_validity(cpu, addr, &phys_addr, 0);
  3874. if (fault) goto MMU_EXCEPTION;
  3875. fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2], 32);
  3876. if (fault) goto MMU_EXCEPTION;
  3877. fault = check_address_validity(cpu, addr + 4, &phys_addr, 0);
  3878. if (fault) goto MMU_EXCEPTION;
  3879. fault = interpreter_write_memory(core, addr + 4, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2 + 1], 32);
  3880. if (fault) goto MMU_EXCEPTION;
  3881. DBG("\taddr[%x-%x] <= s[%d-%d]=[%x-%x]\n", addr+4, addr, (inst_cream->d+i)*2+1, (inst_cream->d+i)*2, cpu->ExtReg[(inst_cream->d+i)*2+1], cpu->ExtReg[(inst_cream->d+i)*2]);
  3882. addr += 8;
  3883. }
  3884. }
  3885. if (inst_cream->wback){
  3886. cpu->Reg[inst_cream->n] = (inst_cream->add ? cpu->Reg[inst_cream->n] + inst_cream->imm32 :
  3887. cpu->Reg[inst_cream->n] - inst_cream->imm32);
  3888. DBG("\twback r%d[%x]\n", inst_cream->n, cpu->Reg[inst_cream->n]);
  3889. }
  3890. }
  3891. cpu->Reg[15] += 4;
  3892. INC_PC(sizeof(vstm_inst));
  3893. FETCH_INST;
  3894. GOTO_NEXT_INST;
  3895. }
  3896. #endif
  3897. #ifdef VFP_STC_TRANS
  3898. /* Should be the last operation of STC */
  3899. return VSTM(state, type, instr, value);
  3900. #endif
  3901. #ifdef VFP_STC_IMPL
  3902. int VSTM(ARMul_State * state, int type, ARMword instr, ARMword * value)
  3903. {
  3904. static int i = 0;
  3905. static int single_regs, add, wback, d, n, imm32, regs;
  3906. if (type == ARMul_FIRST)
  3907. {
  3908. single_regs = BIT(8) == 0; /* Single precision */
  3909. add = BIT(23); /* */
  3910. wback = BIT(21); /* write-back */
  3911. d = single_regs ? BITS(12, 15)<<1|BIT(22) : BIT(22)<<4|BITS(12, 15); /* Base register */
  3912. n = BITS(16, 19); /* destination register */
  3913. imm32 = BITS(0,7) * 4; /* may not be used */
  3914. regs = single_regs ? BITS(0, 7) : BITS(0, 7)>>1; /* FSTMX if regs is odd */
  3915. DBG("VSTM :\n");
  3916. if (wback) {
  3917. state->Reg[n] = (add ? state->Reg[n] + imm32 : state->Reg[n] - imm32);
  3918. DBG("\twback r%d[%x]\n", n, state->Reg[n]);
  3919. }
  3920. i = 0;
  3921. return ARMul_DONE;
  3922. }
  3923. else if (type == ARMul_DATA)
  3924. {
  3925. if (single_regs)
  3926. {
  3927. *value = state->ExtReg[d + i];
  3928. DBG("\taddr[?] <= s%d=[%x]\n", d+i, state->ExtReg[d + i]);
  3929. i++;
  3930. if (i < regs)
  3931. return ARMul_INC;
  3932. else
  3933. return ARMul_DONE;
  3934. }
  3935. else
  3936. {
  3937. /* FIXME Careful of endianness, may need to rework this */
  3938. *value = state->ExtReg[d*2 + i];
  3939. DBG("\taddr[?] <= s[%d]=[%x]\n", d*2 + i, state->ExtReg[d*2 + i]);
  3940. i++;
  3941. if (i < regs*2)
  3942. return ARMul_INC;
  3943. else
  3944. return ARMul_DONE;
  3945. }
  3946. }
  3947. return -1;
  3948. }
  3949. #endif
  3950. #ifdef VFP_DYNCOM_TABLE
  3951. DYNCOM_FILL_ACTION(vfpinstr),
  3952. #endif
  3953. #ifdef VFP_DYNCOM_TAG
  3954. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  3955. {
  3956. int instr_size = INSTR_SIZE;
  3957. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  3958. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  3959. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  3960. DBG("In %s, pc=0x%x, next_pc=0x%x\n", __FUNCTION__, pc, *next_pc);
  3961. *tag |= TAG_NEW_BB;
  3962. if(instr >> 28 != 0xe)
  3963. *tag |= TAG_CONDITIONAL;
  3964. return instr_size;
  3965. }
  3966. #endif
  3967. #ifdef VFP_DYNCOM_TRANS
  3968. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  3969. //arch_arm_undef(cpu, bb, instr);
  3970. int single = BIT(8) == 0;
  3971. int add = BIT(23);
  3972. int wback = BIT(21);
  3973. int d = single ? BITS(12, 15)<<1|BIT(22) : BITS(12, 15)|(BIT(22)<<4);
  3974. int n = BITS(16, 19);
  3975. int imm32 = BITS(0, 7)<<2;
  3976. int regs = single ? BITS(0, 7) : BITS(1, 7);
  3977. Value* Addr = SELECT(CONST1(add), R(n), SUB(R(n), CONST(imm32)));
  3978. DBG("VSTM \n");
  3979. //if(single)
  3980. // bb = arch_check_mm(cpu, bb, Addr, regs * 4, 0, cpu->dyncom_engine->bb_trap);
  3981. //else
  3982. // bb = arch_check_mm(cpu, bb, Addr, regs * 8, 0, cpu->dyncom_engine->bb_trap);
  3983. int i;
  3984. Value* phys_addr;
  3985. for (i = 0; i < regs; i++)
  3986. {
  3987. if (single)
  3988. {
  3989. //fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d+i], 32);
  3990. /* if R(i) is R15? */
  3991. #if 0
  3992. phys_addr = get_phys_addr(cpu, bb, Addr, 0);
  3993. bb = cpu->dyncom_engine->bb;
  3994. arch_write_memory(cpu, bb, phys_addr, RSPR(d + i), 32);
  3995. #endif
  3996. //memory_write(cpu, bb, Addr, RSPR(d + i), 32);
  3997. memory_write(cpu, bb, Addr, IBITCAST32(FR32(d + i)),32);
  3998. bb = cpu->dyncom_engine->bb;
  3999. //if (fault) goto MMU_EXCEPTION;
  4000. //DBG("\taddr[%x] <= s%d=[%x]\n", addr, inst_cream->d+i, cpu->ExtReg[inst_cream->d+i]);
  4001. Addr = ADD(Addr, CONST(4));
  4002. }
  4003. else
  4004. {
  4005. //fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2], 32);
  4006. #if 0
  4007. phys_addr = get_phys_addr(cpu, bb, Addr, 0);
  4008. bb = cpu->dyncom_engine->bb;
  4009. arch_write_memory(cpu, bb, phys_addr, RSPR((d + i) * 2), 32);
  4010. #endif
  4011. //memory_write(cpu, bb, Addr, RSPR((d + i) * 2), 32);
  4012. memory_write(cpu, bb, Addr, IBITCAST32(FR32((d + i) * 2)),32);
  4013. bb = cpu->dyncom_engine->bb;
  4014. //if (fault) goto MMU_EXCEPTION;
  4015. //fault = interpreter_write_memory(core, addr + 4, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2 + 1], 32);
  4016. #if 0
  4017. phys_addr = get_phys_addr(cpu, bb, ADD(Addr, CONST(4)), 0);
  4018. bb = cpu->dyncom_engine->bb;
  4019. arch_write_memory(cpu, bb, phys_addr, RSPR((d + i) * 2 + 1), 32);
  4020. #endif
  4021. //memory_write(cpu, bb, ADD(Addr, CONST(4)), RSPR((d + i) * 2 + 1), 32);
  4022. memory_write(cpu, bb, ADD(Addr, CONST(4)), IBITCAST32(FR32((d + i) * 2 + 1)), 32);
  4023. bb = cpu->dyncom_engine->bb;
  4024. //if (fault) goto MMU_EXCEPTION;
  4025. //DBG("\taddr[%x-%x] <= s[%d-%d]=[%x-%x]\n", addr+4, addr, (inst_cream->d+i)*2+1, (inst_cream->d+i)*2, cpu->ExtReg[(inst_cream->d+i)*2+1], cpu->ExtReg[(inst_cream->d+i)*2]);
  4026. //addr += 8;
  4027. Addr = ADD(Addr, CONST(8));
  4028. }
  4029. }
  4030. if (wback){
  4031. //cpu->Reg[n] = (add ? cpu->Reg[n] + imm32 :
  4032. // cpu->Reg[n] - imm32);
  4033. LET(n, SELECT(CONST1(add), ADD(R(n), CONST(imm32)), SUB(R(n), CONST(imm32))));
  4034. DBG("\twback r%d, add=%d, imm32=%d\n", n, add, imm32);
  4035. }
  4036. return No_exp;
  4037. }
  4038. #endif
  4039. #undef vfpinstr
  4040. #undef vfpinstr_inst
  4041. #undef VFPLABEL_INST
  4042. /* ----------------------------------------------------------------------- */
  4043. /* VPOP */
  4044. /* cond 1100 1D11 1101 Vd-- 101X imm8 imm8 */
  4045. #define vfpinstr vpop
  4046. #define vfpinstr_inst vpop_inst
  4047. #define VFPLABEL_INST VPOP_INST
  4048. #ifdef VFP_DECODE
  4049. {"vpop", 3, ARMVFP2, 23, 27, 0x19, 16, 21, 0x3d, 9, 11, 0x5},
  4050. #endif
  4051. #ifdef VFP_DECODE_EXCLUSION
  4052. {"vpop", 0, ARMVFP2, 0},
  4053. #endif
  4054. #ifdef VFP_INTERPRETER_TABLE
  4055. INTERPRETER_TRANSLATE(vfpinstr),
  4056. #endif
  4057. #ifdef VFP_INTERPRETER_LABEL
  4058. &&VFPLABEL_INST,
  4059. #endif
  4060. #ifdef VFP_INTERPRETER_STRUCT
  4061. typedef struct _vpop_inst {
  4062. unsigned int single;
  4063. unsigned int d;
  4064. unsigned int imm32;
  4065. unsigned int regs;
  4066. } vfpinstr_inst;
  4067. #endif
  4068. #ifdef VFP_INTERPRETER_TRANS
  4069. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  4070. {
  4071. VFP_DEBUG_TRANSLATE;
  4072. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  4073. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  4074. inst_base->cond = BITS(inst, 28, 31);
  4075. inst_base->idx = index;
  4076. inst_base->br = NON_BRANCH;
  4077. inst_base->load_r15 = 0;
  4078. inst_cream->single = BIT(inst, 8) == 0;
  4079. inst_cream->d = (inst_cream->single ? (BITS(inst, 12, 15)<<1)|BIT(inst, 22) : BITS(inst, 12, 15)|(BIT(inst, 22)<<4));
  4080. inst_cream->imm32 = BITS(inst, 0, 7)<<2;
  4081. inst_cream->regs = (inst_cream->single ? BITS(inst, 0, 7) : BITS(inst, 1, 7));
  4082. return inst_base;
  4083. }
  4084. #endif
  4085. #ifdef VFP_INTERPRETER_IMPL
  4086. VFPLABEL_INST:
  4087. {
  4088. INC_ICOUNTER;
  4089. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4090. CHECK_VFP_ENABLED;
  4091. int i;
  4092. unsigned int value1, value2;
  4093. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  4094. DBG("VPOP :\n");
  4095. addr = cpu->Reg[R13];
  4096. for (i = 0; i < inst_cream->regs; i++)
  4097. {
  4098. if (inst_cream->single)
  4099. {
  4100. fault = check_address_validity(cpu, addr, &phys_addr, 1);
  4101. if (fault) goto MMU_EXCEPTION;
  4102. fault = interpreter_read_memory(core, addr, phys_addr, value1, 32);
  4103. if (fault) goto MMU_EXCEPTION;
  4104. DBG("\ts%d <= [%x] addr[%x]\n", inst_cream->d+i, value1, addr);
  4105. cpu->ExtReg[inst_cream->d+i] = value1;
  4106. addr += 4;
  4107. }
  4108. else
  4109. {
  4110. /* Careful of endianness, little by default */
  4111. fault = check_address_validity(cpu, addr, &phys_addr, 1);
  4112. if (fault) goto MMU_EXCEPTION;
  4113. fault = interpreter_read_memory(core, addr, phys_addr, value1, 32);
  4114. if (fault) goto MMU_EXCEPTION;
  4115. fault = check_address_validity(cpu, addr + 4, &phys_addr, 1);
  4116. if (fault) goto MMU_EXCEPTION;
  4117. fault = interpreter_read_memory(core, addr + 4, phys_addr, value2, 32);
  4118. if (fault) goto MMU_EXCEPTION;
  4119. DBG("\ts[%d-%d] <= [%x-%x] addr[%x-%x]\n", (inst_cream->d+i)*2+1, (inst_cream->d+i)*2, value2, value1, addr+4, addr);
  4120. cpu->ExtReg[(inst_cream->d+i)*2] = value1;
  4121. cpu->ExtReg[(inst_cream->d+i)*2 + 1] = value2;
  4122. addr += 8;
  4123. }
  4124. }
  4125. DBG("\tsp[%x]", cpu->Reg[R13]);
  4126. cpu->Reg[R13] = cpu->Reg[R13] + inst_cream->imm32;
  4127. DBG("=>[%x]\n", cpu->Reg[R13]);
  4128. }
  4129. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4130. INC_PC(sizeof(vpop_inst));
  4131. FETCH_INST;
  4132. GOTO_NEXT_INST;
  4133. }
  4134. #endif
  4135. #ifdef VFP_LDC_TRANS
  4136. if (P == 0 && U == 1 && W == 1 && Rn == 0xD)
  4137. {
  4138. return VPOP(state, type, instr, value);
  4139. }
  4140. #endif
  4141. #ifdef VFP_LDC_IMPL
  4142. int VPOP(ARMul_State * state, int type, ARMword instr, ARMword value)
  4143. {
  4144. static int i = 0;
  4145. static int single_regs, add, wback, d, n, imm32, regs;
  4146. if (type == ARMul_FIRST)
  4147. {
  4148. single_regs = BIT(8) == 0; /* Single precision */
  4149. d = single_regs ? BITS(12, 15)<<1|BIT(22) : BIT(22)<<4|BITS(12, 15); /* Base register */
  4150. imm32 = BITS(0,7)<<2; /* may not be used */
  4151. regs = single_regs ? BITS(0, 7) : BITS(1, 7); /* FLDMX if regs is odd */
  4152. DBG("VPOP :\n");
  4153. DBG("\tsp[%x]", state->Reg[R13]);
  4154. state->Reg[R13] = state->Reg[R13] + imm32;
  4155. DBG("=>[%x]\n", state->Reg[R13]);
  4156. i = 0;
  4157. return ARMul_DONE;
  4158. }
  4159. else if (type == ARMul_TRANSFER)
  4160. {
  4161. return ARMul_DONE;
  4162. }
  4163. else if (type == ARMul_DATA)
  4164. {
  4165. if (single_regs)
  4166. {
  4167. state->ExtReg[d + i] = value;
  4168. DBG("\ts%d <= [%x]\n", d + i, value);
  4169. i++;
  4170. if (i < regs)
  4171. return ARMul_INC;
  4172. else
  4173. return ARMul_DONE;
  4174. }
  4175. else
  4176. {
  4177. /* FIXME Careful of endianness, may need to rework this */
  4178. state->ExtReg[d*2 + i] = value;
  4179. DBG("\ts%d <= [%x]\n", d*2 + i, value);
  4180. i++;
  4181. if (i < regs*2)
  4182. return ARMul_INC;
  4183. else
  4184. return ARMul_DONE;
  4185. }
  4186. }
  4187. return -1;
  4188. }
  4189. #endif
  4190. #ifdef VFP_DYNCOM_TABLE
  4191. DYNCOM_FILL_ACTION(vfpinstr),
  4192. #endif
  4193. #ifdef VFP_DYNCOM_TAG
  4194. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  4195. {
  4196. int instr_size = INSTR_SIZE;
  4197. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  4198. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  4199. /* Should check if PC is destination register */
  4200. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  4201. DBG("In %s, pc=0x%x, next_pc=0x%x\n", __FUNCTION__, pc, *next_pc);
  4202. *tag |= TAG_NEW_BB;
  4203. if(instr >> 28 != 0xe)
  4204. *tag |= TAG_CONDITIONAL;
  4205. return instr_size;
  4206. }
  4207. #endif
  4208. #ifdef VFP_DYNCOM_TRANS
  4209. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  4210. DBG("\t\tin %s instruction .\n", __FUNCTION__);
  4211. //arch_arm_undef(cpu, bb, instr);
  4212. int single = BIT(8) == 0;
  4213. int d = (single ? BITS(12, 15)<<1|BIT(22) : BITS(12, 15)|(BIT(22)<<4));
  4214. int imm32 = BITS(0, 7)<<2;
  4215. int regs = (single ? BITS(0, 7) : BITS(1, 7));
  4216. int i;
  4217. unsigned int value1, value2;
  4218. DBG("VPOP :\n");
  4219. Value* Addr = R(13);
  4220. Value* val;
  4221. //if(single)
  4222. // bb = arch_check_mm(cpu, bb, Addr, regs * 4, 1, cpu->dyncom_engine->bb_trap);
  4223. //else
  4224. // bb = arch_check_mm(cpu, bb, Addr, regs * 4, 1, cpu->dyncom_engine->bb_trap);
  4225. //Value* phys_addr;
  4226. for (i = 0; i < regs; i++)
  4227. {
  4228. if (single)
  4229. {
  4230. #if 0
  4231. phys_addr = get_phys_addr(cpu, bb, Addr, 1);
  4232. bb = cpu->dyncom_engine->bb;
  4233. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4234. #endif
  4235. memory_read(cpu, bb, Addr, 0, 32);
  4236. bb = cpu->dyncom_engine->bb;
  4237. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4238. LETFPS(d + i, FPBITCAST32(val));
  4239. Addr = ADD(Addr, CONST(4));
  4240. }
  4241. else
  4242. {
  4243. /* Careful of endianness, little by default */
  4244. #if 0
  4245. phys_addr = get_phys_addr(cpu, bb, Addr, 1);
  4246. bb = cpu->dyncom_engine->bb;
  4247. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4248. #endif
  4249. memory_read(cpu, bb, Addr, 0, 32);
  4250. bb = cpu->dyncom_engine->bb;
  4251. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4252. LETFPS((d + i) * 2, FPBITCAST32(val));
  4253. #if 0
  4254. phys_addr = get_phys_addr(cpu, bb, ADD(Addr, CONST(4)), 1);
  4255. bb = cpu->dyncom_engine->bb;
  4256. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4257. #endif
  4258. memory_read(cpu, bb, ADD(Addr, CONST(4)), 0, 32);
  4259. bb = cpu->dyncom_engine->bb;
  4260. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4261. LETFPS((d + i) * 2 + 1, FPBITCAST32(val));
  4262. Addr = ADD(Addr, CONST(8));
  4263. }
  4264. }
  4265. LET(13, ADD(R(13), CONST(imm32)));
  4266. return No_exp;
  4267. }
  4268. #endif
  4269. #undef vfpinstr
  4270. #undef vfpinstr_inst
  4271. #undef VFPLABEL_INST
  4272. /* ----------------------------------------------------------------------- */
  4273. /* VLDR */
  4274. /* cond 1101 UD01 Rn-- Vd-- 101X imm8 imm8 */
  4275. #define vfpinstr vldr
  4276. #define vfpinstr_inst vldr_inst
  4277. #define VFPLABEL_INST VLDR_INST
  4278. #ifdef VFP_DECODE
  4279. {"vldr", 3, ARMVFP2, 24, 27, 0xd, 20, 21, 0x1, 9, 11, 0x5},
  4280. #endif
  4281. #ifdef VFP_DECODE_EXCLUSION
  4282. {"vldr", 0, ARMVFP2, 0},
  4283. #endif
  4284. #ifdef VFP_INTERPRETER_TABLE
  4285. INTERPRETER_TRANSLATE(vfpinstr),
  4286. #endif
  4287. #ifdef VFP_INTERPRETER_LABEL
  4288. &&VFPLABEL_INST,
  4289. #endif
  4290. #ifdef VFP_INTERPRETER_STRUCT
  4291. typedef struct _vldr_inst {
  4292. unsigned int single;
  4293. unsigned int n;
  4294. unsigned int d;
  4295. unsigned int imm32;
  4296. unsigned int add;
  4297. } vfpinstr_inst;
  4298. #endif
  4299. #ifdef VFP_INTERPRETER_TRANS
  4300. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  4301. {
  4302. VFP_DEBUG_TRANSLATE;
  4303. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  4304. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  4305. inst_base->cond = BITS(inst, 28, 31);
  4306. inst_base->idx = index;
  4307. inst_base->br = NON_BRANCH;
  4308. inst_base->load_r15 = 0;
  4309. inst_cream->single = BIT(inst, 8) == 0;
  4310. inst_cream->add = BIT(inst, 23);
  4311. inst_cream->imm32 = BITS(inst, 0,7) << 2;
  4312. inst_cream->d = (inst_cream->single ? BITS(inst, 12, 15)<<1|BIT(inst, 22) : BITS(inst, 12, 15)|BIT(inst, 22)<<4);
  4313. inst_cream->n = BITS(inst, 16, 19);
  4314. return inst_base;
  4315. }
  4316. #endif
  4317. #ifdef VFP_INTERPRETER_IMPL
  4318. VFPLABEL_INST:
  4319. {
  4320. INC_ICOUNTER;
  4321. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4322. CHECK_VFP_ENABLED;
  4323. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  4324. unsigned int base = (inst_cream->n == 15 ? (cpu->Reg[inst_cream->n] & 0xFFFFFFFC) + 8 : cpu->Reg[inst_cream->n]);
  4325. addr = (inst_cream->add ? base + inst_cream->imm32 : base - inst_cream->imm32);
  4326. DBG("VLDR :\n", addr);
  4327. if (inst_cream->single)
  4328. {
  4329. fault = check_address_validity(cpu, addr, &phys_addr, 1);
  4330. if (fault) goto MMU_EXCEPTION;
  4331. fault = interpreter_read_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d], 32);
  4332. if (fault) goto MMU_EXCEPTION;
  4333. DBG("\ts%d <= [%x] addr[%x]\n", inst_cream->d, cpu->ExtReg[inst_cream->d], addr);
  4334. }
  4335. else
  4336. {
  4337. unsigned int word1, word2;
  4338. fault = check_address_validity(cpu, addr, &phys_addr, 1);
  4339. if (fault) goto MMU_EXCEPTION;
  4340. fault = interpreter_read_memory(core, addr, phys_addr, word1, 32);
  4341. if (fault) goto MMU_EXCEPTION;
  4342. fault = check_address_validity(cpu, addr + 4, &phys_addr, 1);
  4343. if (fault) goto MMU_EXCEPTION;
  4344. fault = interpreter_read_memory(core, addr + 4, phys_addr, word2, 32);
  4345. if (fault) goto MMU_EXCEPTION;
  4346. /* Check endianness */
  4347. cpu->ExtReg[inst_cream->d*2] = word1;
  4348. cpu->ExtReg[inst_cream->d*2+1] = word2;
  4349. DBG("\ts[%d-%d] <= [%x-%x] addr[%x-%x]\n", inst_cream->d*2+1, inst_cream->d*2, word2, word1, addr+4, addr);
  4350. }
  4351. }
  4352. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4353. INC_PC(sizeof(vldr_inst));
  4354. FETCH_INST;
  4355. GOTO_NEXT_INST;
  4356. }
  4357. #endif
  4358. #ifdef VFP_LDC_TRANS
  4359. if (P == 1 && W == 0)
  4360. {
  4361. return VLDR(state, type, instr, value);
  4362. }
  4363. #endif
  4364. #ifdef VFP_LDC_IMPL
  4365. int VLDR(ARMul_State * state, int type, ARMword instr, ARMword value)
  4366. {
  4367. static int i = 0;
  4368. static int single_reg, add, d, n, imm32, regs;
  4369. if (type == ARMul_FIRST)
  4370. {
  4371. single_reg = BIT(8) == 0; /* Double precision */
  4372. add = BIT(23); /* */
  4373. imm32 = BITS(0,7)<<2; /* may not be used */
  4374. d = single_reg ? BITS(12, 15)<<1|BIT(22) : BIT(22)<<4|BITS(12, 15); /* Base register */
  4375. n = BITS(16, 19); /* destination register */
  4376. DBG("VLDR :\n");
  4377. i = 0;
  4378. regs = 1;
  4379. return ARMul_DONE;
  4380. }
  4381. else if (type == ARMul_TRANSFER)
  4382. {
  4383. return ARMul_DONE;
  4384. }
  4385. else if (type == ARMul_DATA)
  4386. {
  4387. if (single_reg)
  4388. {
  4389. state->ExtReg[d+i] = value;
  4390. DBG("\ts%d <= [%x]\n", d+i, value);
  4391. i++;
  4392. if (i < regs)
  4393. return ARMul_INC;
  4394. else
  4395. return ARMul_DONE;
  4396. }
  4397. else
  4398. {
  4399. /* FIXME Careful of endianness, may need to rework this */
  4400. state->ExtReg[d*2+i] = value;
  4401. DBG("\ts[%d] <= [%x]\n", d*2+i, value);
  4402. i++;
  4403. if (i < regs*2)
  4404. return ARMul_INC;
  4405. else
  4406. return ARMul_DONE;
  4407. }
  4408. }
  4409. return -1;
  4410. }
  4411. #endif
  4412. #ifdef VFP_DYNCOM_TABLE
  4413. DYNCOM_FILL_ACTION(vfpinstr),
  4414. #endif
  4415. #ifdef VFP_DYNCOM_TAG
  4416. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  4417. {
  4418. int instr_size = INSTR_SIZE;
  4419. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  4420. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  4421. /* Should check if PC is destination register */
  4422. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  4423. DBG("In %s, pc=0x%x, next_pc=0x%x\n", __FUNCTION__, pc, *next_pc);
  4424. *tag |= TAG_NEW_BB;
  4425. if(instr >> 28 != 0xe)
  4426. *tag |= TAG_CONDITIONAL;
  4427. return instr_size;
  4428. }
  4429. #endif
  4430. #ifdef VFP_DYNCOM_TRANS
  4431. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  4432. int single = BIT(8) == 0;
  4433. int add = BIT(23);
  4434. int wback = BIT(21);
  4435. int d = (single ? BITS(12, 15)<<1|BIT(22) : BITS(12, 15)|(BIT(22)<<4));
  4436. int n = BITS(16, 19);
  4437. int imm32 = BITS(0, 7)<<2;
  4438. int regs = (single ? BITS(0, 7) : BITS(1, 7));
  4439. Value* base = R(n);
  4440. DBG("\t\tin %s .\n", __FUNCTION__);
  4441. if(n == 15){
  4442. base = ADD(AND(base, CONST(0xFFFFFFFC)), CONST(8));
  4443. }
  4444. Value* Addr = add ? (ADD(base, CONST(imm32))) : (SUB(base, CONST(imm32)));
  4445. //if(single)
  4446. // bb = arch_check_mm(cpu, bb, Addr, 4, 1, cpu->dyncom_engine->bb_trap);
  4447. //else
  4448. // bb = arch_check_mm(cpu, bb, Addr, 8, 1, cpu->dyncom_engine->bb_trap);
  4449. //Value* phys_addr;
  4450. Value* val;
  4451. if(single){
  4452. #if 0
  4453. phys_addr = get_phys_addr(cpu, bb, Addr, 1);
  4454. bb = cpu->dyncom_engine->bb;
  4455. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4456. #endif
  4457. memory_read(cpu, bb, Addr, 0, 32);
  4458. bb = cpu->dyncom_engine->bb;
  4459. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4460. //LETS(d, val);
  4461. LETFPS(d,FPBITCAST32(val));
  4462. }
  4463. else{
  4464. #if 0
  4465. phys_addr = get_phys_addr(cpu, bb, Addr, 1);
  4466. bb = cpu->dyncom_engine->bb;
  4467. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4468. #endif
  4469. memory_read(cpu, bb, Addr, 0, 32);
  4470. bb = cpu->dyncom_engine->bb;
  4471. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4472. //LETS(d * 2, val);
  4473. LETFPS(d * 2,FPBITCAST32(val));
  4474. #if 0
  4475. phys_addr = get_phys_addr(cpu, bb, ADD(Addr, CONST(4)), 1);
  4476. bb = cpu->dyncom_engine->bb;
  4477. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4478. #endif
  4479. memory_read(cpu, bb, ADD(Addr, CONST(4)), 0,32);
  4480. bb = cpu->dyncom_engine->bb;
  4481. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4482. //LETS(d * 2 + 1, val);
  4483. LETFPS( d * 2 + 1,FPBITCAST32(val));
  4484. }
  4485. return No_exp;
  4486. }
  4487. #endif
  4488. #undef vfpinstr
  4489. #undef vfpinstr_inst
  4490. #undef VFPLABEL_INST
  4491. /* ----------------------------------------------------------------------- */
  4492. /* VLDM */
  4493. /* cond 110P UDW1 Rn-- Vd-- 101X imm8 imm8 */
  4494. #define vfpinstr vldm
  4495. #define vfpinstr_inst vldm_inst
  4496. #define VFPLABEL_INST VLDM_INST
  4497. #ifdef VFP_DECODE
  4498. {"vldm", 3, ARMVFP2, 25, 27, 0x6, 20, 20, 1, 9, 11, 0x5},
  4499. #endif
  4500. #ifdef VFP_DECODE_EXCLUSION
  4501. {"vldm", 0, ARMVFP2, 0},
  4502. #endif
  4503. #ifdef VFP_INTERPRETER_TABLE
  4504. INTERPRETER_TRANSLATE(vfpinstr),
  4505. #endif
  4506. #ifdef VFP_INTERPRETER_LABEL
  4507. &&VFPLABEL_INST,
  4508. #endif
  4509. #ifdef VFP_INTERPRETER_STRUCT
  4510. typedef struct _vldm_inst {
  4511. unsigned int single;
  4512. unsigned int add;
  4513. unsigned int wback;
  4514. unsigned int d;
  4515. unsigned int n;
  4516. unsigned int imm32;
  4517. unsigned int regs;
  4518. } vfpinstr_inst;
  4519. #endif
  4520. #ifdef VFP_INTERPRETER_TRANS
  4521. ARM_INST_PTR INTERPRETER_TRANSLATE(vfpinstr)(unsigned int inst, int index)
  4522. {
  4523. VFP_DEBUG_TRANSLATE;
  4524. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(vfpinstr_inst));
  4525. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  4526. inst_base->cond = BITS(inst, 28, 31);
  4527. inst_base->idx = index;
  4528. inst_base->br = NON_BRANCH;
  4529. inst_base->load_r15 = 0;
  4530. inst_cream->single = BIT(inst, 8) == 0;
  4531. inst_cream->add = BIT(inst, 23);
  4532. inst_cream->wback = BIT(inst, 21);
  4533. inst_cream->d = (inst_cream->single ? BITS(inst, 12, 15)<<1|BIT(inst, 22) : BITS(inst, 12, 15)|BIT(inst, 22)<<4);
  4534. inst_cream->n = BITS(inst, 16, 19);
  4535. inst_cream->imm32 = BITS(inst, 0, 7)<<2;
  4536. inst_cream->regs = (inst_cream->single ? BITS(inst, 0, 7) : BITS(inst, 1, 7));
  4537. return inst_base;
  4538. }
  4539. #endif
  4540. #ifdef VFP_INTERPRETER_IMPL
  4541. VFPLABEL_INST:
  4542. {
  4543. INC_ICOUNTER;
  4544. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4545. CHECK_VFP_ENABLED;
  4546. int i;
  4547. vfpinstr_inst *inst_cream = (vfpinstr_inst *)inst_base->component;
  4548. addr = (inst_cream->add ? cpu->Reg[inst_cream->n] : cpu->Reg[inst_cream->n] - inst_cream->imm32);
  4549. DBG("VLDM : addr[%x]\n", addr);
  4550. for (i = 0; i < inst_cream->regs; i++)
  4551. {
  4552. if (inst_cream->single)
  4553. {
  4554. fault = check_address_validity(cpu, addr, &phys_addr, 1);
  4555. if (fault) goto MMU_EXCEPTION;
  4556. fault = interpreter_read_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d+i], 32);
  4557. if (fault) goto MMU_EXCEPTION;
  4558. DBG("\ts%d <= [%x] addr[%x]\n", inst_cream->d+i, cpu->ExtReg[inst_cream->d+i], addr);
  4559. addr += 4;
  4560. }
  4561. else
  4562. {
  4563. /* Careful of endianness, little by default */
  4564. fault = check_address_validity(cpu, addr, &phys_addr, 1);
  4565. if (fault) goto MMU_EXCEPTION;
  4566. fault = interpreter_read_memory(core, addr, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2], 32);
  4567. if (fault) goto MMU_EXCEPTION;
  4568. fault = check_address_validity(cpu, addr + 4, &phys_addr, 1);
  4569. if (fault) goto MMU_EXCEPTION;
  4570. fault = interpreter_read_memory(core, addr + 4, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2 + 1], 32);
  4571. if (fault) goto MMU_EXCEPTION;
  4572. DBG("\ts[%d-%d] <= [%x-%x] addr[%x-%x]\n", (inst_cream->d+i)*2+1, (inst_cream->d+i)*2, cpu->ExtReg[(inst_cream->d+i)*2+1], cpu->ExtReg[(inst_cream->d+i)*2], addr+4, addr);
  4573. addr += 8;
  4574. }
  4575. }
  4576. if (inst_cream->wback){
  4577. cpu->Reg[inst_cream->n] = (inst_cream->add ? cpu->Reg[inst_cream->n] + inst_cream->imm32 :
  4578. cpu->Reg[inst_cream->n] - inst_cream->imm32);
  4579. DBG("\twback r%d[%x]\n", inst_cream->n, cpu->Reg[inst_cream->n]);
  4580. }
  4581. }
  4582. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4583. INC_PC(sizeof(vfpinstr_inst));
  4584. FETCH_INST;
  4585. GOTO_NEXT_INST;
  4586. }
  4587. #endif
  4588. #ifdef VFP_LDC_TRANS
  4589. /* Should be the last operation of LDC */
  4590. return VLDM(state, type, instr, value);
  4591. #endif
  4592. #ifdef VFP_LDC_IMPL
  4593. int VLDM(ARMul_State * state, int type, ARMword instr, ARMword value)
  4594. {
  4595. static int i = 0;
  4596. static int single_regs, add, wback, d, n, imm32, regs;
  4597. if (type == ARMul_FIRST)
  4598. {
  4599. single_regs = BIT(8) == 0; /* Single precision */
  4600. add = BIT(23); /* */
  4601. wback = BIT(21); /* write-back */
  4602. d = single_regs ? BITS(12, 15)<<1|BIT(22) : BIT(22)<<4|BITS(12, 15); /* Base register */
  4603. n = BITS(16, 19); /* destination register */
  4604. imm32 = BITS(0,7) * 4; /* may not be used */
  4605. regs = single_regs ? BITS(0, 7) : BITS(0, 7)>>1; /* FLDMX if regs is odd */
  4606. DBG("VLDM :\n");
  4607. if (wback) {
  4608. state->Reg[n] = (add ? state->Reg[n] + imm32 : state->Reg[n] - imm32);
  4609. DBG("\twback r%d[%x]\n", n, state->Reg[n]);
  4610. }
  4611. i = 0;
  4612. return ARMul_DONE;
  4613. }
  4614. else if (type == ARMul_DATA)
  4615. {
  4616. if (single_regs)
  4617. {
  4618. state->ExtReg[d + i] = value;
  4619. DBG("\ts%d <= [%x] addr[?]\n", d+i, state->ExtReg[d + i]);
  4620. i++;
  4621. if (i < regs)
  4622. return ARMul_INC;
  4623. else
  4624. return ARMul_DONE;
  4625. }
  4626. else
  4627. {
  4628. /* FIXME Careful of endianness, may need to rework this */
  4629. state->ExtReg[d*2 + i] = value;
  4630. DBG("\ts[%d] <= [%x] addr[?]\n", d*2 + i, state->ExtReg[d*2 + i]);
  4631. i++;
  4632. if (i < regs*2)
  4633. return ARMul_INC;
  4634. else
  4635. return ARMul_DONE;
  4636. }
  4637. }
  4638. return -1;
  4639. }
  4640. #endif
  4641. #ifdef VFP_DYNCOM_TABLE
  4642. DYNCOM_FILL_ACTION(vfpinstr),
  4643. #endif
  4644. #ifdef VFP_DYNCOM_TAG
  4645. int DYNCOM_TAG(vfpinstr)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
  4646. {
  4647. int instr_size = INSTR_SIZE;
  4648. //DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
  4649. //arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
  4650. arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
  4651. DBG("In %s, pc=0x%x, next_pc=0x%x\n", __FUNCTION__, pc, *next_pc);
  4652. *tag |= TAG_NEW_BB;
  4653. if(instr >> 28 != 0xe)
  4654. *tag |= TAG_CONDITIONAL;
  4655. return instr_size;
  4656. }
  4657. #endif
  4658. #ifdef VFP_DYNCOM_TRANS
  4659. int DYNCOM_TRANS(vfpinstr)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
  4660. int single = BIT(8) == 0;
  4661. int add = BIT(23);
  4662. int wback = BIT(21);
  4663. int d = single ? BITS(12, 15)<<1|BIT(22) : BITS(12, 15)|BIT(22)<<4;
  4664. int n = BITS(16, 19);
  4665. int imm32 = BITS(0, 7)<<2;
  4666. int regs = single ? BITS(0, 7) : BITS(1, 7);
  4667. Value* Addr = SELECT(CONST1(add), R(n), SUB(R(n), CONST(imm32)));
  4668. //if(single)
  4669. // bb = arch_check_mm(cpu, bb, Addr, regs * 4, 1, cpu->dyncom_engine->bb_trap);
  4670. //else
  4671. // bb = arch_check_mm(cpu, bb, Addr, regs * 4, 1, cpu->dyncom_engine->bb_trap);
  4672. DBG("VLDM \n");
  4673. int i;
  4674. //Value* phys_addr;
  4675. Value* val;
  4676. for (i = 0; i < regs; i++)
  4677. {
  4678. if (single)
  4679. {
  4680. //fault = interpreter_write_memory(core, addr, phys_addr, cpu->ExtReg[inst_cream->d+i], 32);
  4681. /* if R(i) is R15? */
  4682. #if 0
  4683. phys_addr = get_phys_addr(cpu, bb, Addr, 1);
  4684. bb = cpu->dyncom_engine->bb;
  4685. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4686. #endif
  4687. memory_read(cpu, bb, Addr, 0, 32);
  4688. bb = cpu->dyncom_engine->bb;
  4689. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4690. //LETS(d + i, val);
  4691. LETFPS(d + i, FPBITCAST32(val));
  4692. //if (fault) goto MMU_EXCEPTION;
  4693. //DBG("\taddr[%x] <= s%d=[%x]\n", addr, inst_cream->d+i, cpu->ExtReg[inst_cream->d+i]);
  4694. Addr = ADD(Addr, CONST(4));
  4695. }
  4696. else
  4697. {
  4698. #if 0
  4699. phys_addr = get_phys_addr(cpu, bb, Addr, 1);
  4700. bb = cpu->dyncom_engine->bb;
  4701. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4702. #endif
  4703. memory_read(cpu, bb, Addr, 0, 32);
  4704. bb = cpu->dyncom_engine->bb;
  4705. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4706. LETFPS((d + i) * 2, FPBITCAST32(val));
  4707. #if 0
  4708. phys_addr = get_phys_addr(cpu, bb, ADD(Addr, CONST(4)), 1);
  4709. bb = cpu->dyncom_engine->bb;
  4710. val = arch_read_memory(cpu,bb,phys_addr,0,32);
  4711. #endif
  4712. memory_read(cpu, bb, Addr, 0, 32);
  4713. bb = cpu->dyncom_engine->bb;
  4714. val = new LoadInst(cpu->dyncom_engine->read_value, "", false, bb);
  4715. LETFPS((d + i) * 2 + 1, FPBITCAST32(val));
  4716. //fault = interpreter_write_memory(core, addr + 4, phys_addr, cpu->ExtReg[(inst_cream->d+i)*2 + 1], 32);
  4717. //DBG("\taddr[%x-%x] <= s[%d-%d]=[%x-%x]\n", addr+4, addr, (inst_cream->d+i)*2+1, (inst_cream->d+i)*2, cpu->ExtReg[(inst_cream->d+i)*2+1], cpu->ExtReg[(inst_cream->d+i)*2]);
  4718. //addr += 8;
  4719. Addr = ADD(Addr, CONST(8));
  4720. }
  4721. }
  4722. if (wback){
  4723. //cpu->Reg[n] = (add ? cpu->Reg[n] + imm32 :
  4724. // cpu->Reg[n] - imm32);
  4725. LET(n, SELECT(CONST1(add), ADD(R(n), CONST(imm32)), SUB(R(n), CONST(imm32))));
  4726. DBG("\twback r%d, add=%d, imm32=%d\n", n, add, imm32);
  4727. }
  4728. return No_exp;
  4729. }
  4730. #endif
  4731. #undef vfpinstr
  4732. #undef vfpinstr_inst
  4733. #undef VFPLABEL_INST
  4734. #define VFP_DEBUG_TRANSLATE DBG("in func %s, %x\n", __FUNCTION__, inst);
  4735. #define VFP_DEBUG_UNIMPLEMENTED(x) printf("in func %s, " #x " unimplemented\n", __FUNCTION__); exit(-1);
  4736. #define VFP_DEBUG_UNTESTED(x) printf("in func %s, " #x " untested\n", __FUNCTION__);
  4737. #define CHECK_VFP_ENABLED
  4738. #define CHECK_VFP_CDP_RET vfp_raise_exceptions(cpu, ret, inst_cream->instr, cpu->VFP[VFP_OFFSET(VFP_FPSCR)]); //if (ret == -1) {printf("VFP CDP FAILURE %x\n", inst_cream->instr); exit(-1);}