arm_dyncom_interpreter.cpp 223 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945
  1. // Copyright 2012 Michael Kang, 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #define CITRA_IGNORE_EXIT(x)
  5. #include <algorithm>
  6. #include <unordered_map>
  7. #include <stdio.h>
  8. #include <assert.h>
  9. #include <cstdio>
  10. #include <vector>
  11. using namespace std;
  12. #include "core/arm/skyeye_common/armdefs.h"
  13. #include "core/arm/skyeye_common/armmmu.h"
  14. #include "arm_dyncom_thumb.h"
  15. #include "arm_dyncom_run.h"
  16. #include "core/arm/skyeye_common/vfp/vfp.h"
  17. #include "core/arm/disassembler/arm_disasm.h"
  18. #include "core/mem_map.h"
  19. #include "core/hle/hle.h"
  20. enum {
  21. COND = (1 << 0),
  22. NON_BRANCH = (1 << 1),
  23. DIRECT_BRANCH = (1 << 2),
  24. INDIRECT_BRANCH = (1 << 3),
  25. CALL = (1 << 4),
  26. RET = (1 << 5),
  27. END_OF_PAGE = (1 << 6),
  28. THUMB = (1 << 7)
  29. };
  30. #define USER_MODE_OPT 1
  31. #define HYBRID_MODE 0 // Enable for JIT mode
  32. #define THRESHOLD 1000
  33. #define DURATION 500
  34. #define CHECK_RS if(RS == 15) rs += 8
  35. #define CHECK_RM if(RM == 15) rm += 8
  36. #undef BITS
  37. #define BITS(s, a, b) ((s << ((sizeof(s) * 8 - 1) - b)) >> (sizeof(s) * 8 - b + a - 1))
  38. #define BIT(s, n) ((s >> (n)) & 1)
  39. #define RM BITS(sht_oper, 0, 3)
  40. #define RS BITS(sht_oper, 8, 11)
  41. #define glue(x, y) x ## y
  42. #define DPO(s) glue(DataProcessingOperands, s)
  43. #define ROTATE_RIGHT(n, i, l) ((n << (l - i)) | (n >> i))
  44. #define ROTATE_LEFT(n, i, l) ((n >> (l - i)) | (n << i))
  45. #define ROTATE_RIGHT_32(n, i) ROTATE_RIGHT(n, i, 32)
  46. #define ROTATE_LEFT_32(n, i) ROTATE_LEFT(n, i, 32)
  47. #define rotr(x,n) ( (x >> n) | ((x & ((1 << (n + 1)) - 1)) << (32 - n)) )
  48. extern void switch_mode(arm_core_t *core, uint32_t mode);
  49. typedef arm_core_t arm_processor;
  50. typedef unsigned int (*shtop_fp_t)(arm_processor *cpu, unsigned int sht_oper);
  51. // Defines a reservation granule of 2 words, which protects the first 2 words starting at the tag.
  52. // This is the smallest granule allowed by the v7 spec, and is coincidentally just large enough to
  53. // support LDR/STREXD.
  54. static const ARMword RESERVATION_GRANULE_MASK = 0xFFFFFFF8;
  55. // Exclusive memory access
  56. static int exclusive_detect(ARMul_State* state, ARMword addr){
  57. if(state->exclusive_tag == (addr & RESERVATION_GRANULE_MASK))
  58. return 0;
  59. else
  60. return -1;
  61. }
  62. static void add_exclusive_addr(ARMul_State* state, ARMword addr){
  63. state->exclusive_tag = addr & RESERVATION_GRANULE_MASK;
  64. return;
  65. }
  66. static void remove_exclusive(ARMul_State* state, ARMword addr){
  67. state->exclusive_tag = 0xFFFFFFFF;
  68. }
  69. unsigned int DPO(Immediate)(arm_processor *cpu, unsigned int sht_oper) {
  70. unsigned int immed_8 = BITS(sht_oper, 0, 7);
  71. unsigned int rotate_imm = BITS(sht_oper, 8, 11);
  72. unsigned int shifter_operand = ROTATE_RIGHT_32(immed_8, rotate_imm * 2);
  73. if (rotate_imm == 0)
  74. cpu->shifter_carry_out = cpu->CFlag;
  75. else
  76. cpu->shifter_carry_out = BIT(shifter_operand, 31);
  77. return shifter_operand;
  78. }
  79. unsigned int DPO(Register)(arm_processor *cpu, unsigned int sht_oper) {
  80. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  81. unsigned int shifter_operand = rm;
  82. cpu->shifter_carry_out = cpu->CFlag;
  83. return shifter_operand;
  84. }
  85. unsigned int DPO(LogicalShiftLeftByImmediate)(arm_processor *cpu, unsigned int sht_oper) {
  86. int shift_imm = BITS(sht_oper, 7, 11);
  87. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  88. unsigned int shifter_operand;
  89. if (shift_imm == 0) {
  90. shifter_operand = rm;
  91. cpu->shifter_carry_out = cpu->CFlag;
  92. } else {
  93. shifter_operand = rm << shift_imm;
  94. cpu->shifter_carry_out = BIT(rm, 32 - shift_imm);
  95. }
  96. return shifter_operand;
  97. }
  98. unsigned int DPO(LogicalShiftLeftByRegister)(arm_processor *cpu, unsigned int sht_oper) {
  99. int shifter_operand;
  100. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  101. unsigned int rs = CHECK_READ_REG15(cpu, RS);
  102. if (BITS(rs, 0, 7) == 0) {
  103. shifter_operand = rm;
  104. cpu->shifter_carry_out = cpu->CFlag;
  105. } else if (BITS(rs, 0, 7) < 32) {
  106. shifter_operand = rm << BITS(rs, 0, 7);
  107. cpu->shifter_carry_out = BIT(rm, 32 - BITS(rs, 0, 7));
  108. } else if (BITS(rs, 0, 7) == 32) {
  109. shifter_operand = 0;
  110. cpu->shifter_carry_out = BIT(rm, 0);
  111. } else {
  112. shifter_operand = 0;
  113. cpu->shifter_carry_out = 0;
  114. }
  115. return shifter_operand;
  116. }
  117. unsigned int DPO(LogicalShiftRightByImmediate)(arm_processor *cpu, unsigned int sht_oper) {
  118. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  119. unsigned int shifter_operand;
  120. int shift_imm = BITS(sht_oper, 7, 11);
  121. if (shift_imm == 0) {
  122. shifter_operand = 0;
  123. cpu->shifter_carry_out = BIT(rm, 31);
  124. } else {
  125. shifter_operand = rm >> shift_imm;
  126. cpu->shifter_carry_out = BIT(rm, shift_imm - 1);
  127. }
  128. return shifter_operand;
  129. }
  130. unsigned int DPO(LogicalShiftRightByRegister)(arm_processor *cpu, unsigned int sht_oper) {
  131. unsigned int rs = CHECK_READ_REG15(cpu, RS);
  132. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  133. unsigned int shifter_operand;
  134. if (BITS(rs, 0, 7) == 0) {
  135. shifter_operand = rm;
  136. cpu->shifter_carry_out = cpu->CFlag;
  137. } else if (BITS(rs, 0, 7) < 32) {
  138. shifter_operand = rm >> BITS(rs, 0, 7);
  139. cpu->shifter_carry_out = BIT(rm, BITS(rs, 0, 7) - 1);
  140. } else if (BITS(rs, 0, 7) == 32) {
  141. shifter_operand = 0;
  142. cpu->shifter_carry_out = BIT(rm, 31);
  143. } else {
  144. shifter_operand = 0;
  145. cpu->shifter_carry_out = 0;
  146. }
  147. return shifter_operand;
  148. }
  149. unsigned int DPO(ArithmeticShiftRightByImmediate)(arm_processor *cpu, unsigned int sht_oper) {
  150. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  151. unsigned int shifter_operand;
  152. int shift_imm = BITS(sht_oper, 7, 11);
  153. if (shift_imm == 0) {
  154. if (BIT(rm, 31)) {
  155. shifter_operand = 0;
  156. cpu->shifter_carry_out = BIT(rm, 31);
  157. } else {
  158. shifter_operand = 0xFFFFFFFF;
  159. cpu->shifter_carry_out = BIT(rm, 31);
  160. }
  161. } else {
  162. shifter_operand = static_cast<int>(rm) >> shift_imm;
  163. cpu->shifter_carry_out = BIT(rm, shift_imm - 1);
  164. }
  165. return shifter_operand;
  166. }
  167. unsigned int DPO(ArithmeticShiftRightByRegister)(arm_processor *cpu, unsigned int sht_oper) {
  168. unsigned int rs = CHECK_READ_REG15(cpu, RS);
  169. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  170. unsigned int shifter_operand;
  171. if (BITS(rs, 0, 7) == 0) {
  172. shifter_operand = rm;
  173. cpu->shifter_carry_out = cpu->CFlag;
  174. } else if (BITS(rs, 0, 7) < 32) {
  175. shifter_operand = static_cast<int>(rm) >> BITS(rs, 0, 7);
  176. cpu->shifter_carry_out = BIT(rm, BITS(rs, 0, 7) - 1);
  177. } else {
  178. if (BIT(rm, 31) == 0)
  179. shifter_operand = 0;
  180. else
  181. shifter_operand = 0xffffffff;
  182. cpu->shifter_carry_out = BIT(rm, 31);
  183. }
  184. return shifter_operand;
  185. }
  186. unsigned int DPO(RotateRightByImmediate)(arm_processor *cpu, unsigned int sht_oper) {
  187. unsigned int shifter_operand;
  188. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  189. int shift_imm = BITS(sht_oper, 7, 11);
  190. if (shift_imm == 0) {
  191. shifter_operand = (cpu->CFlag << 31) | (rm >> 1);
  192. cpu->shifter_carry_out = BIT(rm, 0);
  193. } else {
  194. shifter_operand = ROTATE_RIGHT_32(rm, shift_imm);
  195. cpu->shifter_carry_out = BIT(rm, shift_imm - 1);
  196. }
  197. return shifter_operand;
  198. }
  199. unsigned int DPO(RotateRightByRegister)(arm_processor *cpu, unsigned int sht_oper) {
  200. unsigned int rm = CHECK_READ_REG15(cpu, RM);
  201. unsigned int rs = CHECK_READ_REG15(cpu, RS);
  202. unsigned int shifter_operand;
  203. if (BITS(rs, 0, 7) == 0) {
  204. shifter_operand = rm;
  205. cpu->shifter_carry_out = cpu->CFlag;
  206. } else if (BITS(rs, 0, 4) == 0) {
  207. shifter_operand = rm;
  208. cpu->shifter_carry_out = BIT(rm, 31);
  209. } else {
  210. shifter_operand = ROTATE_RIGHT_32(rm, BITS(rs, 0, 4));
  211. cpu->shifter_carry_out = BIT(rm, BITS(rs, 0, 4) - 1);
  212. }
  213. return shifter_operand;
  214. }
  215. typedef struct _MiscImmeData {
  216. unsigned int U;
  217. unsigned int Rn;
  218. unsigned int offset_8;
  219. } MiscLSData;
  220. typedef struct _MiscRegData {
  221. unsigned int U;
  222. unsigned int Rn;
  223. unsigned int Rm;
  224. } MiscRegData;
  225. typedef struct _MiscImmePreIdx {
  226. unsigned int offset_8;
  227. unsigned int U;
  228. unsigned int Rn;
  229. } MiscImmePreIdx;
  230. typedef struct _MiscRegPreIdx {
  231. unsigned int U;
  232. unsigned int Rn;
  233. unsigned int Rm;
  234. } MiscRegPreIdx;
  235. typedef struct _MiscImmePstIdx {
  236. unsigned int offset_8;
  237. unsigned int U;
  238. unsigned int Rn;
  239. } MIscImmePstIdx;
  240. typedef struct _MiscRegPstIdx {
  241. unsigned int Rn;
  242. unsigned int Rm;
  243. unsigned int U;
  244. } MiscRegPstIdx;
  245. typedef struct _LSWordorUnsignedByte {
  246. } LDnST;
  247. typedef void (*get_addr_fp_t)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw);
  248. typedef struct _ldst_inst {
  249. unsigned int inst;
  250. get_addr_fp_t get_addr;
  251. } ldst_inst;
  252. #define DEBUG_MSG LOG_DEBUG(Core_ARM11, "inst is %x", inst); CITRA_IGNORE_EXIT(0)
  253. int CondPassed(arm_processor *cpu, unsigned int cond);
  254. #define LnSWoUB(s) glue(LnSWoUB, s)
  255. #define MLnS(s) glue(MLnS, s)
  256. #define LdnStM(s) glue(LdnStM, s)
  257. #define W_BIT BIT(inst, 21)
  258. #define U_BIT BIT(inst, 23)
  259. #define I_BIT BIT(inst, 25)
  260. #define P_BIT BIT(inst, 24)
  261. #define OFFSET_12 BITS(inst, 0, 11)
  262. void LnSWoUB(ImmediateOffset)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  263. unsigned int Rn = BITS(inst, 16, 19);
  264. unsigned int addr;
  265. if (U_BIT)
  266. addr = CHECK_READ_REG15_WA(cpu, Rn) + OFFSET_12;
  267. else
  268. addr = CHECK_READ_REG15_WA(cpu, Rn) - OFFSET_12;
  269. virt_addr = addr;
  270. }
  271. void LnSWoUB(RegisterOffset)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  272. unsigned int Rn = BITS(inst, 16, 19);
  273. unsigned int Rm = BITS(inst, 0, 3);
  274. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  275. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  276. unsigned int addr;
  277. if (U_BIT)
  278. addr = rn + rm;
  279. else
  280. addr = rn - rm;
  281. virt_addr = addr;
  282. }
  283. void LnSWoUB(ImmediatePostIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  284. unsigned int Rn = BITS(inst, 16, 19);
  285. unsigned int addr = CHECK_READ_REG15_WA(cpu, Rn);
  286. if (U_BIT)
  287. cpu->Reg[Rn] += OFFSET_12;
  288. else
  289. cpu->Reg[Rn] -= OFFSET_12;
  290. virt_addr = addr;
  291. }
  292. void LnSWoUB(ImmediatePreIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  293. unsigned int Rn = BITS(inst, 16, 19);
  294. unsigned int addr;
  295. if (U_BIT)
  296. addr = CHECK_READ_REG15_WA(cpu, Rn) + OFFSET_12;
  297. else
  298. addr = CHECK_READ_REG15_WA(cpu, Rn) - OFFSET_12;
  299. virt_addr = addr;
  300. if (CondPassed(cpu, BITS(inst, 28, 31)))
  301. cpu->Reg[Rn] = addr;
  302. }
  303. void MLnS(RegisterPreIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  304. unsigned int addr;
  305. unsigned int Rn = BITS(inst, 16, 19);
  306. unsigned int Rm = BITS(inst, 0, 3);
  307. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  308. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  309. if (U_BIT)
  310. addr = rn + rm;
  311. else
  312. addr = rn - rm;
  313. virt_addr = addr;
  314. if (CondPassed(cpu, BITS(inst, 28, 31)))
  315. cpu->Reg[Rn] = addr;
  316. }
  317. void LnSWoUB(RegisterPreIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  318. unsigned int Rn = BITS(inst, 16, 19);
  319. unsigned int Rm = BITS(inst, 0, 3);
  320. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  321. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  322. unsigned int addr;
  323. if (U_BIT)
  324. addr = rn + rm;
  325. else
  326. addr = rn - rm;
  327. virt_addr = addr;
  328. if (CondPassed(cpu, BITS(inst, 28, 31))) {
  329. cpu->Reg[Rn] = addr;
  330. }
  331. }
  332. void LnSWoUB(ScaledRegisterPreIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  333. unsigned int shift = BITS(inst, 5, 6);
  334. unsigned int shift_imm = BITS(inst, 7, 11);
  335. unsigned int Rn = BITS(inst, 16, 19);
  336. unsigned int Rm = BITS(inst, 0, 3);
  337. unsigned int index;
  338. unsigned int addr;
  339. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  340. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  341. switch (shift) {
  342. case 0:
  343. index = rm << shift_imm;
  344. break;
  345. case 1:
  346. if (shift_imm == 0) {
  347. index = 0;
  348. } else {
  349. index = rm >> shift_imm;
  350. }
  351. break;
  352. case 2:
  353. DEBUG_MSG;
  354. break;
  355. case 3:
  356. DEBUG_MSG;
  357. break;
  358. }
  359. if (U_BIT)
  360. addr = rn + index;
  361. else
  362. addr = rn - index;
  363. virt_addr = addr;
  364. if (CondPassed(cpu, BITS(inst, 28, 31)))
  365. cpu->Reg[Rn] = addr;
  366. }
  367. void LnSWoUB(ScaledRegisterPostIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  368. unsigned int shift = BITS(inst, 5, 6);
  369. unsigned int shift_imm = BITS(inst, 7, 11);
  370. unsigned int Rn = BITS(inst, 16, 19);
  371. unsigned int Rm = BITS(inst, 0, 3);
  372. unsigned int index;
  373. unsigned int addr = CHECK_READ_REG15_WA(cpu, Rn);
  374. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  375. switch (shift) {
  376. case 0:
  377. index = rm << shift_imm;
  378. break;
  379. case 1:
  380. if (shift_imm == 0) {
  381. index = 0;
  382. } else {
  383. index = rm >> shift_imm;
  384. }
  385. break;
  386. case 2:
  387. DEBUG_MSG;
  388. break;
  389. case 3:
  390. DEBUG_MSG;
  391. break;
  392. }
  393. virt_addr = addr;
  394. if (CondPassed(cpu, BITS(inst, 28, 31))) {
  395. if (U_BIT)
  396. cpu->Reg[Rn] += index;
  397. else
  398. cpu->Reg[Rn] -= index;
  399. }
  400. }
  401. void LnSWoUB(RegisterPostIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  402. unsigned int Rn = BITS(inst, 16, 19);
  403. unsigned int Rm = BITS(inst, 0, 3);
  404. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  405. virt_addr = CHECK_READ_REG15_WA(cpu, Rn);
  406. if (CondPassed(cpu, BITS(inst, 28, 31))) {
  407. if (U_BIT) {
  408. cpu->Reg[Rn] += rm;
  409. } else {
  410. cpu->Reg[Rn] -= rm;
  411. }
  412. }
  413. }
  414. void MLnS(ImmediateOffset)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  415. unsigned int immedL = BITS(inst, 0, 3);
  416. unsigned int immedH = BITS(inst, 8, 11);
  417. unsigned int Rn = BITS(inst, 16, 19);
  418. unsigned int addr;
  419. unsigned int offset_8 = (immedH << 4) | immedL;
  420. if (U_BIT)
  421. addr = CHECK_READ_REG15_WA(cpu, Rn) + offset_8;
  422. else
  423. addr = CHECK_READ_REG15_WA(cpu, Rn) - offset_8;
  424. virt_addr = addr;
  425. }
  426. void MLnS(RegisterOffset)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  427. unsigned int addr;
  428. unsigned int Rn = BITS(inst, 16, 19);
  429. unsigned int Rm = BITS(inst, 0, 3);
  430. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  431. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  432. if (U_BIT)
  433. addr = rn + rm;
  434. else
  435. addr = rn - rm;
  436. virt_addr = addr;
  437. }
  438. void MLnS(ImmediatePreIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  439. unsigned int Rn = BITS(inst, 16, 19);
  440. unsigned int immedH = BITS(inst, 8, 11);
  441. unsigned int immedL = BITS(inst, 0, 3);
  442. unsigned int addr;
  443. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  444. unsigned int offset_8 = (immedH << 4) | immedL;
  445. if (U_BIT)
  446. addr = rn + offset_8;
  447. else
  448. addr = rn - offset_8;
  449. virt_addr = addr;
  450. if (CondPassed(cpu, BITS(inst, 28, 31)))
  451. cpu->Reg[Rn] = addr;
  452. }
  453. void MLnS(ImmediatePostIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  454. unsigned int Rn = BITS(inst, 16, 19);
  455. unsigned int immedH = BITS(inst, 8, 11);
  456. unsigned int immedL = BITS(inst, 0, 3);
  457. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  458. virt_addr = rn;
  459. if (CondPassed(cpu, BITS(inst, 28, 31))) {
  460. unsigned int offset_8 = (immedH << 4) | immedL;
  461. if (U_BIT)
  462. rn += offset_8;
  463. else
  464. rn -= offset_8;
  465. cpu->Reg[Rn] = rn;
  466. }
  467. }
  468. void MLnS(RegisterPostIndexed)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  469. unsigned int Rn = BITS(inst, 16, 19);
  470. unsigned int Rm = BITS(inst, 0, 3);
  471. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  472. virt_addr = CHECK_READ_REG15_WA(cpu, Rn);
  473. if (CondPassed(cpu, BITS(inst, 28, 31))) {
  474. if (U_BIT)
  475. cpu->Reg[Rn] += rm;
  476. else
  477. cpu->Reg[Rn] -= rm;
  478. }
  479. }
  480. void LdnStM(DecrementBefore)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  481. unsigned int Rn = BITS(inst, 16, 19);
  482. unsigned int i = BITS(inst, 0, 15);
  483. int count = 0;
  484. while (i) {
  485. if (i & 1) count++;
  486. i = i >> 1;
  487. }
  488. virt_addr = CHECK_READ_REG15_WA(cpu, Rn) - count * 4;
  489. if (CondPassed(cpu, BITS(inst, 28, 31)) && BIT(inst, 21))
  490. cpu->Reg[Rn] -= count * 4;
  491. }
  492. void LdnStM(IncrementBefore)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  493. unsigned int Rn = BITS(inst, 16, 19);
  494. unsigned int i = BITS(inst, 0, 15);
  495. int count = 0;
  496. while (i) {
  497. if (i & 1) count++;
  498. i = i >> 1;
  499. }
  500. virt_addr = CHECK_READ_REG15_WA(cpu, Rn) + 4;
  501. if (CondPassed(cpu, BITS(inst, 28, 31)) && BIT(inst, 21))
  502. cpu->Reg[Rn] += count * 4;
  503. }
  504. void LdnStM(IncrementAfter)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  505. unsigned int Rn = BITS(inst, 16, 19);
  506. unsigned int i = BITS(inst, 0, 15);
  507. int count = 0;
  508. while(i) {
  509. if (i & 1) count++;
  510. i = i >> 1;
  511. }
  512. virt_addr = CHECK_READ_REG15_WA(cpu, Rn);
  513. if (CondPassed(cpu, BITS(inst, 28, 31)) && BIT(inst, 21))
  514. cpu->Reg[Rn] += count * 4;
  515. }
  516. void LdnStM(DecrementAfter)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  517. unsigned int Rn = BITS(inst, 16, 19);
  518. unsigned int i = BITS(inst, 0, 15);
  519. int count = 0;
  520. while(i) {
  521. if(i & 1) count++;
  522. i = i >> 1;
  523. }
  524. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  525. unsigned int start_addr = rn - count * 4 + 4;
  526. virt_addr = start_addr;
  527. if (CondPassed(cpu, BITS(inst, 28, 31)) && BIT(inst, 21)) {
  528. cpu->Reg[Rn] -= count * 4;
  529. }
  530. }
  531. void LnSWoUB(ScaledRegisterOffset)(arm_processor *cpu, unsigned int inst, unsigned int &virt_addr, unsigned int rw) {
  532. unsigned int shift = BITS(inst, 5, 6);
  533. unsigned int shift_imm = BITS(inst, 7, 11);
  534. unsigned int Rn = BITS(inst, 16, 19);
  535. unsigned int Rm = BITS(inst, 0, 3);
  536. unsigned int index;
  537. unsigned int addr;
  538. unsigned int rm = CHECK_READ_REG15_WA(cpu, Rm);
  539. unsigned int rn = CHECK_READ_REG15_WA(cpu, Rn);
  540. switch (shift) {
  541. case 0:
  542. index = rm << shift_imm;
  543. break;
  544. case 1:
  545. if (shift_imm == 0) {
  546. index = 0;
  547. } else {
  548. index = rm >> shift_imm;
  549. }
  550. break;
  551. case 2:
  552. if (shift_imm == 0){ // ASR #32
  553. if (rm >> 31)
  554. index = 0xFFFFFFFF;
  555. else
  556. index = 0;
  557. } else {
  558. index = static_cast<int>(rm) >> shift_imm;
  559. }
  560. break;
  561. case 3:
  562. DEBUG_MSG;
  563. break;
  564. }
  565. if (U_BIT) {
  566. addr = rn + index;
  567. } else
  568. addr = rn - index;
  569. virt_addr = addr;
  570. }
  571. #define ISNEG(n) (n < 0)
  572. #define ISPOS(n) (n >= 0)
  573. typedef struct _arm_inst {
  574. unsigned int idx;
  575. unsigned int cond;
  576. int br;
  577. int load_r15;
  578. char component[0];
  579. } arm_inst;
  580. typedef struct generic_arm_inst {
  581. u32 Ra;
  582. u32 Rm;
  583. u32 Rn;
  584. u32 Rd;
  585. u8 op1;
  586. u8 op2;
  587. } generic_arm_inst;
  588. typedef struct _adc_inst {
  589. unsigned int I;
  590. unsigned int S;
  591. unsigned int Rn;
  592. unsigned int Rd;
  593. unsigned int shifter_operand;
  594. shtop_fp_t shtop_func;
  595. } adc_inst;
  596. typedef struct _add_inst {
  597. unsigned int I;
  598. unsigned int S;
  599. unsigned int Rn;
  600. unsigned int Rd;
  601. unsigned int shifter_operand;
  602. shtop_fp_t shtop_func;
  603. } add_inst;
  604. typedef struct _orr_inst {
  605. unsigned int I;
  606. unsigned int S;
  607. unsigned int Rn;
  608. unsigned int Rd;
  609. unsigned int shifter_operand;
  610. shtop_fp_t shtop_func;
  611. } orr_inst;
  612. typedef struct _and_inst {
  613. unsigned int I;
  614. unsigned int S;
  615. unsigned int Rn;
  616. unsigned int Rd;
  617. unsigned int shifter_operand;
  618. shtop_fp_t shtop_func;
  619. } and_inst;
  620. typedef struct _eor_inst {
  621. unsigned int I;
  622. unsigned int S;
  623. unsigned int Rn;
  624. unsigned int Rd;
  625. unsigned int shifter_operand;
  626. shtop_fp_t shtop_func;
  627. } eor_inst;
  628. typedef struct _bbl_inst {
  629. unsigned int L;
  630. int signed_immed_24;
  631. unsigned int next_addr;
  632. unsigned int jmp_addr;
  633. } bbl_inst;
  634. typedef struct _bx_inst {
  635. unsigned int Rm;
  636. } bx_inst;
  637. typedef struct _blx_inst {
  638. union {
  639. int32_t signed_immed_24;
  640. uint32_t Rm;
  641. } val;
  642. unsigned int inst;
  643. } blx_inst;
  644. typedef struct _clz_inst {
  645. unsigned int Rm;
  646. unsigned int Rd;
  647. } clz_inst;
  648. typedef struct _cps_inst {
  649. unsigned int imod0;
  650. unsigned int imod1;
  651. unsigned int mmod;
  652. unsigned int A, I, F;
  653. unsigned int mode;
  654. } cps_inst;
  655. typedef struct _clrex_inst {
  656. } clrex_inst;
  657. typedef struct _cpy_inst {
  658. unsigned int Rm;
  659. unsigned int Rd;
  660. } cpy_inst;
  661. typedef struct _bic_inst {
  662. unsigned int I;
  663. unsigned int S;
  664. unsigned int Rn;
  665. unsigned int Rd;
  666. unsigned int shifter_operand;
  667. shtop_fp_t shtop_func;
  668. } bic_inst;
  669. typedef struct _sub_inst {
  670. unsigned int I;
  671. unsigned int S;
  672. unsigned int Rn;
  673. unsigned int Rd;
  674. unsigned int shifter_operand;
  675. shtop_fp_t shtop_func;
  676. } sub_inst;
  677. typedef struct _tst_inst {
  678. unsigned int I;
  679. unsigned int S;
  680. unsigned int Rn;
  681. unsigned int Rd;
  682. unsigned int shifter_operand;
  683. shtop_fp_t shtop_func;
  684. } tst_inst;
  685. typedef struct _cmn_inst {
  686. unsigned int I;
  687. unsigned int Rn;
  688. unsigned int shifter_operand;
  689. shtop_fp_t shtop_func;
  690. } cmn_inst;
  691. typedef struct _teq_inst {
  692. unsigned int I;
  693. unsigned int Rn;
  694. unsigned int shifter_operand;
  695. shtop_fp_t shtop_func;
  696. } teq_inst;
  697. typedef struct _stm_inst {
  698. unsigned int inst;
  699. } stm_inst;
  700. struct bkpt_inst {
  701. };
  702. struct blx1_inst {
  703. unsigned int addr;
  704. };
  705. struct blx2_inst {
  706. unsigned int Rm;
  707. };
  708. typedef struct _stc_inst {
  709. } stc_inst;
  710. typedef struct _ldc_inst {
  711. } ldc_inst;
  712. typedef struct _swi_inst {
  713. unsigned int num;
  714. } swi_inst;
  715. typedef struct _cmp_inst {
  716. unsigned int I;
  717. unsigned int Rn;
  718. unsigned int shifter_operand;
  719. shtop_fp_t shtop_func;
  720. } cmp_inst;
  721. typedef struct _mov_inst {
  722. unsigned int I;
  723. unsigned int S;
  724. unsigned int Rd;
  725. unsigned int shifter_operand;
  726. shtop_fp_t shtop_func;
  727. } mov_inst;
  728. typedef struct _mvn_inst {
  729. unsigned int I;
  730. unsigned int S;
  731. unsigned int Rd;
  732. unsigned int shifter_operand;
  733. shtop_fp_t shtop_func;
  734. } mvn_inst;
  735. typedef struct _rev_inst {
  736. unsigned int Rd;
  737. unsigned int Rm;
  738. unsigned int op1;
  739. unsigned int op2;
  740. } rev_inst;
  741. typedef struct _rsb_inst {
  742. unsigned int I;
  743. unsigned int S;
  744. unsigned int Rn;
  745. unsigned int Rd;
  746. unsigned int shifter_operand;
  747. shtop_fp_t shtop_func;
  748. } rsb_inst;
  749. typedef struct _rsc_inst {
  750. unsigned int I;
  751. unsigned int S;
  752. unsigned int Rn;
  753. unsigned int Rd;
  754. unsigned int shifter_operand;
  755. shtop_fp_t shtop_func;
  756. } rsc_inst;
  757. typedef struct _sbc_inst {
  758. unsigned int I;
  759. unsigned int S;
  760. unsigned int Rn;
  761. unsigned int Rd;
  762. unsigned int shifter_operand;
  763. shtop_fp_t shtop_func;
  764. } sbc_inst;
  765. typedef struct _mul_inst {
  766. unsigned int S;
  767. unsigned int Rd;
  768. unsigned int Rs;
  769. unsigned int Rm;
  770. } mul_inst;
  771. typedef struct _smul_inst {
  772. unsigned int Rd;
  773. unsigned int Rs;
  774. unsigned int Rm;
  775. unsigned int x;
  776. unsigned int y;
  777. } smul_inst;
  778. typedef struct _umull_inst {
  779. unsigned int S;
  780. unsigned int RdHi;
  781. unsigned int RdLo;
  782. unsigned int Rs;
  783. unsigned int Rm;
  784. } umull_inst;
  785. typedef struct _smlad_inst {
  786. unsigned int m;
  787. unsigned int Rm;
  788. unsigned int Rd;
  789. unsigned int Ra;
  790. unsigned int Rn;
  791. unsigned int op1;
  792. unsigned int op2;
  793. } smlad_inst;
  794. typedef struct _smla_inst {
  795. unsigned int x;
  796. unsigned int y;
  797. unsigned int Rm;
  798. unsigned int Rd;
  799. unsigned int Rs;
  800. unsigned int Rn;
  801. } smla_inst;
  802. typedef struct ssat_inst {
  803. unsigned int Rn;
  804. unsigned int Rd;
  805. unsigned int imm5;
  806. unsigned int sat_imm;
  807. unsigned int shift_type;
  808. } ssat_inst;
  809. typedef struct umaal_inst {
  810. unsigned int Rn;
  811. unsigned int Rm;
  812. unsigned int RdHi;
  813. unsigned int RdLo;
  814. } umaal_inst;
  815. typedef struct _umlal_inst {
  816. unsigned int S;
  817. unsigned int Rm;
  818. unsigned int Rs;
  819. unsigned int RdHi;
  820. unsigned int RdLo;
  821. } umlal_inst;
  822. typedef struct _smlal_inst {
  823. unsigned int S;
  824. unsigned int Rm;
  825. unsigned int Rs;
  826. unsigned int RdHi;
  827. unsigned int RdLo;
  828. } smlal_inst;
  829. typedef struct smlald_inst {
  830. unsigned int RdLo;
  831. unsigned int RdHi;
  832. unsigned int Rm;
  833. unsigned int Rn;
  834. unsigned int swap;
  835. unsigned int op1;
  836. unsigned int op2;
  837. } smlald_inst;
  838. typedef struct _mla_inst {
  839. unsigned int S;
  840. unsigned int Rn;
  841. unsigned int Rd;
  842. unsigned int Rs;
  843. unsigned int Rm;
  844. } mla_inst;
  845. typedef struct _mrc_inst {
  846. unsigned int opcode_1;
  847. unsigned int opcode_2;
  848. unsigned int cp_num;
  849. unsigned int crn;
  850. unsigned int crm;
  851. unsigned int Rd;
  852. unsigned int inst;
  853. } mrc_inst;
  854. typedef struct _mcr_inst {
  855. unsigned int opcode_1;
  856. unsigned int opcode_2;
  857. unsigned int cp_num;
  858. unsigned int crn;
  859. unsigned int crm;
  860. unsigned int Rd;
  861. unsigned int inst;
  862. } mcr_inst;
  863. typedef struct _mrs_inst {
  864. unsigned int R;
  865. unsigned int Rd;
  866. } mrs_inst;
  867. typedef struct _msr_inst {
  868. unsigned int field_mask;
  869. unsigned int R;
  870. unsigned int inst;
  871. } msr_inst;
  872. typedef struct _pld_inst {
  873. } pld_inst;
  874. typedef struct _sxtb_inst {
  875. unsigned int Rd;
  876. unsigned int Rm;
  877. unsigned int rotate;
  878. } sxtb_inst;
  879. typedef struct _sxtab_inst {
  880. unsigned int Rd;
  881. unsigned int Rn;
  882. unsigned int Rm;
  883. unsigned rotate;
  884. } sxtab_inst;
  885. typedef struct _sxtah_inst {
  886. unsigned int Rd;
  887. unsigned int Rn;
  888. unsigned int Rm;
  889. unsigned int rotate;
  890. } sxtah_inst;
  891. typedef struct _sxth_inst {
  892. unsigned int Rd;
  893. unsigned int Rm;
  894. unsigned int rotate;
  895. } sxth_inst;
  896. typedef struct _uxtab_inst {
  897. unsigned int Rn;
  898. unsigned int Rd;
  899. unsigned int rotate;
  900. unsigned int Rm;
  901. } uxtab_inst;
  902. typedef struct _uxtah_inst {
  903. unsigned int Rn;
  904. unsigned int Rd;
  905. unsigned int rotate;
  906. unsigned int Rm;
  907. } uxtah_inst;
  908. typedef struct _uxth_inst {
  909. unsigned int Rd;
  910. unsigned int Rm;
  911. unsigned int rotate;
  912. } uxth_inst;
  913. typedef struct _cdp_inst {
  914. unsigned int opcode_1;
  915. unsigned int CRn;
  916. unsigned int CRd;
  917. unsigned int cp_num;
  918. unsigned int opcode_2;
  919. unsigned int CRm;
  920. unsigned int inst;
  921. }cdp_inst;
  922. typedef struct _uxtb_inst {
  923. unsigned int Rd;
  924. unsigned int Rm;
  925. unsigned int rotate;
  926. } uxtb_inst;
  927. typedef struct _swp_inst {
  928. unsigned int Rn;
  929. unsigned int Rd;
  930. unsigned int Rm;
  931. } swp_inst;
  932. typedef struct _b_2_thumb {
  933. unsigned int imm;
  934. }b_2_thumb;
  935. typedef struct _b_cond_thumb {
  936. unsigned int imm;
  937. unsigned int cond;
  938. }b_cond_thumb;
  939. typedef struct _bl_1_thumb {
  940. unsigned int imm;
  941. }bl_1_thumb;
  942. typedef struct _bl_2_thumb {
  943. unsigned int imm;
  944. }bl_2_thumb;
  945. typedef struct _blx_1_thumb {
  946. unsigned int imm;
  947. unsigned int instr;
  948. }blx_1_thumb;
  949. typedef struct _pkh_inst {
  950. unsigned int Rm;
  951. unsigned int Rn;
  952. unsigned int Rd;
  953. unsigned char imm;
  954. } pkh_inst;
  955. typedef arm_inst * ARM_INST_PTR;
  956. #define CACHE_BUFFER_SIZE (64 * 1024 * 2000)
  957. char inst_buf[CACHE_BUFFER_SIZE];
  958. int top = 0;
  959. inline void *AllocBuffer(unsigned int size) {
  960. int start = top;
  961. top += size;
  962. if (top > CACHE_BUFFER_SIZE) {
  963. LOG_ERROR(Core_ARM11, "inst_buf is full");
  964. CITRA_IGNORE_EXIT(-1);
  965. }
  966. return (void *)&inst_buf[start];
  967. }
  968. int CondPassed(arm_processor *cpu, unsigned int cond) {
  969. #define NFLAG cpu->NFlag
  970. #define ZFLAG cpu->ZFlag
  971. #define CFLAG cpu->CFlag
  972. #define VFLAG cpu->VFlag
  973. int temp;
  974. switch (cond) {
  975. case 0x0:
  976. temp = ZFLAG;
  977. break;
  978. case 0x1: // NE
  979. temp = !ZFLAG;
  980. break;
  981. case 0x6: // VS
  982. temp = VFLAG;
  983. break;
  984. case 0x7: // VC
  985. temp = !VFLAG;
  986. break;
  987. case 0x4: // MI
  988. temp = NFLAG;
  989. break;
  990. case 0x5: // PL
  991. temp = !NFLAG;
  992. break;
  993. case 0x2: // CS
  994. temp = CFLAG;
  995. break;
  996. case 0x3: // CC
  997. temp = !CFLAG;
  998. break;
  999. case 0x8: // HI
  1000. temp = (CFLAG && !ZFLAG);
  1001. break;
  1002. case 0x9: // LS
  1003. temp = (!CFLAG || ZFLAG);
  1004. break;
  1005. case 0xa: // GE
  1006. temp = ((!NFLAG && !VFLAG) || (NFLAG && VFLAG));
  1007. break;
  1008. case 0xb: // LT
  1009. temp = ((NFLAG && !VFLAG) || (!NFLAG && VFLAG));
  1010. break;
  1011. case 0xc: // GT
  1012. temp = ((!NFLAG && !VFLAG && !ZFLAG) || (NFLAG && VFLAG && !ZFLAG));
  1013. break;
  1014. case 0xd: // LE
  1015. temp = ((NFLAG && !VFLAG) || (!NFLAG && VFLAG)) || ZFLAG;
  1016. break;
  1017. case 0xe: // AL
  1018. temp = 1;
  1019. break;
  1020. case 0xf:
  1021. temp = 1;
  1022. break;
  1023. }
  1024. return temp;
  1025. }
  1026. enum DECODE_STATUS {
  1027. DECODE_SUCCESS,
  1028. DECODE_FAILURE
  1029. };
  1030. int decode_arm_instr(uint32_t instr, int32_t *idx);
  1031. shtop_fp_t get_shtop(unsigned int inst) {
  1032. if (BIT(inst, 25)) {
  1033. return DPO(Immediate);
  1034. } else if (BITS(inst, 4, 11) == 0) {
  1035. return DPO(Register);
  1036. } else if (BITS(inst, 4, 6) == 0) {
  1037. return DPO(LogicalShiftLeftByImmediate);
  1038. } else if (BITS(inst, 4, 7) == 1) {
  1039. return DPO(LogicalShiftLeftByRegister);
  1040. } else if (BITS(inst, 4, 6) == 2) {
  1041. return DPO(LogicalShiftRightByImmediate);
  1042. } else if (BITS(inst, 4, 7) == 3) {
  1043. return DPO(LogicalShiftRightByRegister);
  1044. } else if (BITS(inst, 4, 6) == 4) {
  1045. return DPO(ArithmeticShiftRightByImmediate);
  1046. } else if (BITS(inst, 4, 7) == 5) {
  1047. return DPO(ArithmeticShiftRightByRegister);
  1048. } else if (BITS(inst, 4, 6) == 6) {
  1049. return DPO(RotateRightByImmediate);
  1050. } else if (BITS(inst, 4, 7) == 7) {
  1051. return DPO(RotateRightByRegister);
  1052. }
  1053. return nullptr;
  1054. }
  1055. get_addr_fp_t get_calc_addr_op(unsigned int inst) {
  1056. if (BITS(inst, 24, 27) == 5 && BIT(inst, 21) == 0) {
  1057. return LnSWoUB(ImmediateOffset);
  1058. } else if (BITS(inst, 24, 27) == 7 && BIT(inst, 21) == 0 && BITS(inst, 4, 11) == 0) {
  1059. return LnSWoUB(RegisterOffset);
  1060. } else if (BITS(inst, 24, 27) == 7 && BIT(inst, 21) == 0 && BIT(inst, 4) == 0) {
  1061. return LnSWoUB(ScaledRegisterOffset);
  1062. } else if (BITS(inst, 24, 27) == 5 && BIT(inst, 21) == 1) {
  1063. return LnSWoUB(ImmediatePreIndexed);
  1064. } else if (BITS(inst, 24, 27) == 7 && BIT(inst, 21) == 1 && BITS(inst, 4, 11) == 0) {
  1065. return LnSWoUB(RegisterPreIndexed);
  1066. } else if (BITS(inst, 24, 27) == 7 && BIT(inst, 21) == 1 && BIT(inst, 4) == 0) {
  1067. return LnSWoUB(ScaledRegisterPreIndexed);
  1068. } else if (BITS(inst, 24, 27) == 4 && BIT(inst, 21) == 0) {
  1069. return LnSWoUB(ImmediatePostIndexed);
  1070. } else if (BITS(inst, 24, 27) == 6 && BIT(inst, 21) == 0 && BITS(inst, 4, 11) == 0) {
  1071. return LnSWoUB(RegisterPostIndexed);
  1072. } else if (BITS(inst, 24, 27) == 6 && BIT(inst, 21) == 0 && BIT(inst, 4) == 0) {
  1073. return LnSWoUB(ScaledRegisterPostIndexed);
  1074. } else if (BITS(inst, 24, 27) == 1 && BITS(inst, 21, 22) == 2 && BIT(inst, 7) == 1 && BIT(inst, 4) == 1) {
  1075. return MLnS(ImmediateOffset);
  1076. } else if (BITS(inst, 24, 27) == 1 && BITS(inst, 21, 22) == 0 && BIT(inst, 7) == 1 && BIT(inst, 4) == 1) {
  1077. return MLnS(RegisterOffset);
  1078. } else if (BITS(inst, 24, 27) == 1 && BITS(inst, 21, 22) == 3 && BIT(inst, 7) == 1 && BIT(inst, 4) == 1) {
  1079. return MLnS(ImmediatePreIndexed);
  1080. } else if (BITS(inst, 24, 27) == 1 && BITS(inst, 21, 22) == 1 && BIT(inst, 7) == 1 && BIT(inst, 4) == 1) {
  1081. return MLnS(RegisterPreIndexed);
  1082. } else if (BITS(inst, 24, 27) == 0 && BITS(inst, 21, 22) == 2 && BIT(inst, 7) == 1 && BIT(inst, 4) == 1) {
  1083. return MLnS(ImmediatePostIndexed);
  1084. } else if (BITS(inst, 24, 27) == 0 && BITS(inst, 21, 22) == 0 && BIT(inst, 7) == 1 && BIT(inst, 4) == 1) {
  1085. return MLnS(RegisterPostIndexed);
  1086. } else if (BITS(inst, 23, 27) == 0x11) {
  1087. return LdnStM(IncrementAfter);
  1088. } else if (BITS(inst, 23, 27) == 0x13) {
  1089. return LdnStM(IncrementBefore);
  1090. } else if (BITS(inst, 23, 27) == 0x10) {
  1091. return LdnStM(DecrementAfter);
  1092. } else if (BITS(inst, 23, 27) == 0x12) {
  1093. return LdnStM(DecrementBefore);
  1094. }
  1095. return nullptr;
  1096. }
  1097. #define INTERPRETER_TRANSLATE(s) glue(InterpreterTranslate_, s)
  1098. #define CHECK_RN (inst_cream->Rn == 15)
  1099. #define CHECK_RM (inst_cream->Rm == 15)
  1100. #define CHECK_RS (inst_cream->Rs == 15)
  1101. #define UNIMPLEMENTED_INSTRUCTION(mnemonic) \
  1102. LOG_ERROR(Core_ARM11, "unimplemented instruction: %s", mnemonic); \
  1103. CITRA_IGNORE_EXIT(-1); \
  1104. return nullptr;
  1105. ARM_INST_PTR INTERPRETER_TRANSLATE(adc)(unsigned int inst, int index)
  1106. {
  1107. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(adc_inst));
  1108. adc_inst *inst_cream = (adc_inst *)inst_base->component;
  1109. inst_base->cond = BITS(inst, 28, 31);
  1110. inst_base->idx = index;
  1111. inst_base->br = NON_BRANCH;
  1112. inst_base->load_r15 = 0;
  1113. inst_cream->I = BIT(inst, 25);
  1114. inst_cream->S = BIT(inst, 20);
  1115. inst_cream->Rn = BITS(inst, 16, 19);
  1116. inst_cream->Rd = BITS(inst, 12, 15);
  1117. if (CHECK_RN)
  1118. inst_base->load_r15 = 1;
  1119. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1120. inst_cream->shtop_func = get_shtop(inst);
  1121. if (inst_cream->Rd == 15) {
  1122. inst_base->br = INDIRECT_BRANCH;
  1123. }
  1124. return inst_base;
  1125. }
  1126. ARM_INST_PTR INTERPRETER_TRANSLATE(add)(unsigned int inst, int index)
  1127. {
  1128. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(add_inst));
  1129. add_inst *inst_cream = (add_inst *)inst_base->component;
  1130. inst_base->cond = BITS(inst, 28, 31);
  1131. inst_base->idx = index;
  1132. inst_base->br = NON_BRANCH;
  1133. inst_base->load_r15 = 0;
  1134. inst_cream->I = BIT(inst, 25);
  1135. inst_cream->S = BIT(inst, 20);
  1136. inst_cream->Rn = BITS(inst, 16, 19);
  1137. inst_cream->Rd = BITS(inst, 12, 15);
  1138. if (CHECK_RN)
  1139. inst_base->load_r15 = 1;
  1140. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1141. inst_cream->shtop_func = get_shtop(inst);
  1142. if (inst_cream->Rd == 15) {
  1143. inst_base->br = INDIRECT_BRANCH;
  1144. }
  1145. return inst_base;
  1146. }
  1147. ARM_INST_PTR INTERPRETER_TRANSLATE(and)(unsigned int inst, int index)
  1148. {
  1149. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(and_inst));
  1150. and_inst *inst_cream = (and_inst *)inst_base->component;
  1151. inst_base->cond = BITS(inst, 28, 31);
  1152. inst_base->idx = index;
  1153. inst_base->br = NON_BRANCH;
  1154. inst_base->load_r15 = 0;
  1155. inst_cream->I = BIT(inst, 25);
  1156. inst_cream->S = BIT(inst, 20);
  1157. inst_cream->Rn = BITS(inst, 16, 19);
  1158. inst_cream->Rd = BITS(inst, 12, 15);
  1159. if (CHECK_RN)
  1160. inst_base->load_r15 = 1;
  1161. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1162. inst_cream->shtop_func = get_shtop(inst);
  1163. if (inst_cream->Rd == 15)
  1164. inst_base->br = INDIRECT_BRANCH;
  1165. return inst_base;
  1166. }
  1167. ARM_INST_PTR INTERPRETER_TRANSLATE(bbl)(unsigned int inst, int index)
  1168. {
  1169. #define POSBRANCH ((inst & 0x7fffff) << 2)
  1170. #define NEGBRANCH ((0xff000000 |(inst & 0xffffff)) << 2)
  1171. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(bbl_inst));
  1172. bbl_inst *inst_cream = (bbl_inst *)inst_base->component;
  1173. inst_base->cond = BITS(inst, 28, 31);
  1174. inst_base->idx = index;
  1175. inst_base->br = DIRECT_BRANCH;
  1176. if (BIT(inst, 24))
  1177. inst_base->br = CALL;
  1178. if (BITS(inst, 28, 31) <= 0xe)
  1179. inst_base->br |= COND;
  1180. inst_cream->L = BIT(inst, 24);
  1181. inst_cream->signed_immed_24 = BIT(inst, 23) ? NEGBRANCH : POSBRANCH;
  1182. return inst_base;
  1183. }
  1184. ARM_INST_PTR INTERPRETER_TRANSLATE(bic)(unsigned int inst, int index)
  1185. {
  1186. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(bic_inst));
  1187. bic_inst *inst_cream = (bic_inst *)inst_base->component;
  1188. inst_base->cond = BITS(inst, 28, 31);
  1189. inst_base->idx = index;
  1190. inst_base->br = NON_BRANCH;
  1191. inst_base->load_r15 = 0;
  1192. inst_cream->I = BIT(inst, 25);
  1193. inst_cream->S = BIT(inst, 20);
  1194. inst_cream->Rn = BITS(inst, 16, 19);
  1195. inst_cream->Rd = BITS(inst, 12, 15);
  1196. if (CHECK_RN)
  1197. inst_base->load_r15 = 1;
  1198. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1199. inst_cream->shtop_func = get_shtop(inst);
  1200. if (inst_cream->Rd == 15)
  1201. inst_base->br = INDIRECT_BRANCH;
  1202. return inst_base;
  1203. }
  1204. ARM_INST_PTR INTERPRETER_TRANSLATE(bkpt)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("BKPT"); }
  1205. ARM_INST_PTR INTERPRETER_TRANSLATE(blx)(unsigned int inst, int index)
  1206. {
  1207. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(blx_inst));
  1208. blx_inst *inst_cream = (blx_inst *)inst_base->component;
  1209. inst_base->cond = BITS(inst, 28, 31);
  1210. inst_base->idx = index;
  1211. inst_base->br = INDIRECT_BRANCH;
  1212. inst_cream->inst = inst;
  1213. if (BITS(inst, 20, 27) == 0x12 && BITS(inst, 4, 7) == 0x3) {
  1214. inst_cream->val.Rm = BITS(inst, 0, 3);
  1215. } else {
  1216. inst_cream->val.signed_immed_24 = BITS(inst, 0, 23);
  1217. }
  1218. return inst_base;
  1219. }
  1220. ARM_INST_PTR INTERPRETER_TRANSLATE(bx)(unsigned int inst, int index)
  1221. {
  1222. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(bx_inst));
  1223. bx_inst *inst_cream = (bx_inst *)inst_base->component;
  1224. inst_base->cond = BITS(inst, 28, 31);
  1225. inst_base->idx = index;
  1226. inst_base->br = INDIRECT_BRANCH;
  1227. inst_cream->Rm = BITS(inst, 0, 3);
  1228. return inst_base;
  1229. }
  1230. ARM_INST_PTR INTERPRETER_TRANSLATE(bxj)(unsigned int inst, int index)
  1231. {
  1232. return INTERPRETER_TRANSLATE(bx)(inst, index);
  1233. }
  1234. ARM_INST_PTR INTERPRETER_TRANSLATE(cdp)(unsigned int inst, int index){
  1235. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(cdp_inst));
  1236. cdp_inst *inst_cream = (cdp_inst *)inst_base->component;
  1237. inst_base->cond = BITS(inst, 28, 31);
  1238. inst_base->idx = index;
  1239. inst_base->br = NON_BRANCH;
  1240. inst_base->load_r15 = 0;
  1241. inst_cream->CRm = BITS(inst, 0, 3);
  1242. inst_cream->CRd = BITS(inst, 12, 15);
  1243. inst_cream->CRn = BITS(inst, 16, 19);
  1244. inst_cream->cp_num = BITS(inst, 8, 11);
  1245. inst_cream->opcode_2 = BITS(inst, 5, 7);
  1246. inst_cream->opcode_1 = BITS(inst, 20, 23);
  1247. inst_cream->inst = inst;
  1248. LOG_TRACE(Core_ARM11, "inst %x index %x", inst, index);
  1249. return inst_base;
  1250. }
  1251. ARM_INST_PTR INTERPRETER_TRANSLATE(clrex)(unsigned int inst, int index)
  1252. {
  1253. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(clrex_inst));
  1254. inst_base->cond = BITS(inst, 28, 31);
  1255. inst_base->idx = index;
  1256. inst_base->br = NON_BRANCH;
  1257. return inst_base;
  1258. }
  1259. ARM_INST_PTR INTERPRETER_TRANSLATE(clz)(unsigned int inst, int index)
  1260. {
  1261. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(clz_inst));
  1262. clz_inst *inst_cream = (clz_inst *)inst_base->component;
  1263. inst_base->cond = BITS(inst, 28, 31);
  1264. inst_base->idx = index;
  1265. inst_base->br = NON_BRANCH;
  1266. inst_base->load_r15 = 0;
  1267. inst_cream->Rm = BITS(inst, 0, 3);
  1268. inst_cream->Rd = BITS(inst, 12, 15);
  1269. if (CHECK_RM)
  1270. inst_base->load_r15 = 1;
  1271. return inst_base;
  1272. }
  1273. ARM_INST_PTR INTERPRETER_TRANSLATE(cmn)(unsigned int inst, int index)
  1274. {
  1275. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(cmn_inst));
  1276. cmn_inst *inst_cream = (cmn_inst *)inst_base->component;
  1277. inst_base->cond = BITS(inst, 28, 31);
  1278. inst_base->idx = index;
  1279. inst_base->br = NON_BRANCH;
  1280. inst_base->load_r15 = 0;
  1281. inst_cream->I = BIT(inst, 25);
  1282. //inst_cream->S = BIT(inst, 20);
  1283. inst_cream->Rn = BITS(inst, 16, 19);
  1284. //inst_cream->Rd = BITS(inst, 12, 15);
  1285. if (CHECK_RN)
  1286. inst_base->load_r15 = 1;
  1287. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1288. inst_cream->shtop_func = get_shtop(inst);
  1289. return inst_base;
  1290. }
  1291. ARM_INST_PTR INTERPRETER_TRANSLATE(cmp)(unsigned int inst, int index)
  1292. {
  1293. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(cmp_inst));
  1294. cmp_inst *inst_cream = (cmp_inst *)inst_base->component;
  1295. inst_base->cond = BITS(inst, 28, 31);
  1296. inst_base->idx = index;
  1297. inst_base->br = NON_BRANCH;
  1298. inst_base->load_r15 = 0;
  1299. inst_cream->I = BIT(inst, 25);
  1300. inst_cream->Rn = BITS(inst, 16, 19);
  1301. if (CHECK_RN)
  1302. inst_base->load_r15 = 1;
  1303. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1304. inst_cream->shtop_func = get_shtop(inst);
  1305. return inst_base;
  1306. }
  1307. ARM_INST_PTR INTERPRETER_TRANSLATE(cps)(unsigned int inst, int index)
  1308. {
  1309. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(cps_inst));
  1310. cps_inst *inst_cream = (cps_inst *)inst_base->component;
  1311. inst_base->cond = BITS(inst, 28, 31);
  1312. inst_base->idx = index;
  1313. inst_base->br = NON_BRANCH;
  1314. inst_cream->imod0 = BIT(inst, 18);
  1315. inst_cream->imod1 = BIT(inst, 19);
  1316. inst_cream->mmod = BIT(inst, 17);
  1317. inst_cream->A = BIT(inst, 8);
  1318. inst_cream->I = BIT(inst, 7);
  1319. inst_cream->F = BIT(inst, 6);
  1320. inst_cream->mode = BITS(inst, 0, 4);
  1321. return inst_base;
  1322. }
  1323. ARM_INST_PTR INTERPRETER_TRANSLATE(cpy)(unsigned int inst, int index)
  1324. {
  1325. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(mov_inst));
  1326. mov_inst *inst_cream = (mov_inst *)inst_base->component;
  1327. inst_base->cond = BITS(inst, 28, 31);
  1328. inst_base->idx = index;
  1329. inst_base->br = NON_BRANCH;
  1330. inst_cream->I = BIT(inst, 25);
  1331. inst_cream->S = BIT(inst, 20);
  1332. inst_cream->Rd = BITS(inst, 12, 15);
  1333. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1334. inst_cream->shtop_func = get_shtop(inst);
  1335. if (inst_cream->Rd == 15) {
  1336. inst_base->br = INDIRECT_BRANCH;
  1337. }
  1338. return inst_base;
  1339. }
  1340. ARM_INST_PTR INTERPRETER_TRANSLATE(eor)(unsigned int inst, int index)
  1341. {
  1342. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(eor_inst));
  1343. eor_inst *inst_cream = (eor_inst *)inst_base->component;
  1344. inst_base->cond = BITS(inst, 28, 31);
  1345. inst_base->idx = index;
  1346. inst_base->br = NON_BRANCH;
  1347. inst_base->load_r15 = 0;
  1348. inst_cream->I = BIT(inst, 25);
  1349. inst_cream->S = BIT(inst, 20);
  1350. inst_cream->Rn = BITS(inst, 16, 19);
  1351. inst_cream->Rd = BITS(inst, 12, 15);
  1352. if (CHECK_RN)
  1353. inst_base->load_r15 = 1;
  1354. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1355. inst_cream->shtop_func = get_shtop(inst);
  1356. if (inst_cream->Rd == 15) {
  1357. inst_base->br = INDIRECT_BRANCH;
  1358. }
  1359. return inst_base;
  1360. }
  1361. ARM_INST_PTR INTERPRETER_TRANSLATE(ldc)(unsigned int inst, int index)
  1362. {
  1363. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldc_inst));
  1364. inst_base->cond = BITS(inst, 28, 31);
  1365. inst_base->idx = index;
  1366. inst_base->br = NON_BRANCH;
  1367. return inst_base;
  1368. }
  1369. ARM_INST_PTR INTERPRETER_TRANSLATE(ldm)(unsigned int inst, int index)
  1370. {
  1371. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1372. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1373. inst_base->cond = BITS(inst, 28, 31);
  1374. inst_base->idx = index;
  1375. inst_base->br = NON_BRANCH;
  1376. inst_cream->inst = inst;
  1377. inst_cream->get_addr = get_calc_addr_op(inst);
  1378. if (BIT(inst, 15)) {
  1379. inst_base->br = INDIRECT_BRANCH;
  1380. }
  1381. return inst_base;
  1382. }
  1383. ARM_INST_PTR INTERPRETER_TRANSLATE(sxth)(unsigned int inst, int index)
  1384. {
  1385. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(sxtb_inst));
  1386. sxtb_inst *inst_cream = (sxtb_inst *)inst_base->component;
  1387. inst_base->cond = BITS(inst, 28, 31);
  1388. inst_base->idx = index;
  1389. inst_base->br = NON_BRANCH;
  1390. inst_base->load_r15 = 0;
  1391. inst_cream->Rd = BITS(inst, 12, 15);
  1392. inst_cream->Rm = BITS(inst, 0, 3);
  1393. inst_cream->rotate = BITS(inst, 10, 11);
  1394. if (CHECK_RM)
  1395. inst_base->load_r15 = 1;
  1396. return inst_base;
  1397. }
  1398. ARM_INST_PTR INTERPRETER_TRANSLATE(ldr)(unsigned int inst, int index)
  1399. {
  1400. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1401. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1402. inst_base->cond = BITS(inst, 28, 31);
  1403. inst_base->idx = index;
  1404. inst_base->br = NON_BRANCH;
  1405. inst_base->load_r15 = 0;
  1406. inst_cream->inst = inst;
  1407. inst_cream->get_addr = get_calc_addr_op(inst);
  1408. if (BITS(inst, 12, 15) == 15) {
  1409. inst_base->br = INDIRECT_BRANCH;
  1410. }
  1411. return inst_base;
  1412. }
  1413. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrcond)(unsigned int inst, int index)
  1414. {
  1415. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1416. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1417. inst_base->cond = BITS(inst, 28, 31);
  1418. inst_base->idx = index;
  1419. inst_base->br = NON_BRANCH;
  1420. inst_base->load_r15 = 0;
  1421. inst_cream->inst = inst;
  1422. inst_cream->get_addr = get_calc_addr_op(inst);
  1423. if (BITS(inst, 12, 15) == 15) {
  1424. inst_base->br = INDIRECT_BRANCH;
  1425. }
  1426. return inst_base;
  1427. }
  1428. ARM_INST_PTR INTERPRETER_TRANSLATE(uxth)(unsigned int inst, int index)
  1429. {
  1430. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(uxth_inst));
  1431. uxth_inst *inst_cream = (uxth_inst *)inst_base->component;
  1432. inst_base->cond = BITS(inst, 28, 31);
  1433. inst_base->idx = index;
  1434. inst_base->br = NON_BRANCH;
  1435. inst_base->load_r15 = 0;
  1436. inst_cream->Rd = BITS(inst, 12, 15);
  1437. inst_cream->rotate = BITS(inst, 10, 11);
  1438. inst_cream->Rm = BITS(inst, 0, 3);
  1439. if (CHECK_RM)
  1440. inst_base->load_r15 = 1;
  1441. return inst_base;
  1442. }
  1443. ARM_INST_PTR INTERPRETER_TRANSLATE(uxtah)(unsigned int inst, int index)
  1444. {
  1445. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(uxtah_inst));
  1446. uxtah_inst *inst_cream = (uxtah_inst *)inst_base->component;
  1447. inst_base->cond = BITS(inst, 28, 31);
  1448. inst_base->idx = index;
  1449. inst_base->br = NON_BRANCH;
  1450. inst_base->load_r15 = 0;
  1451. inst_cream->Rn = BITS(inst, 16, 19);
  1452. inst_cream->Rd = BITS(inst, 12, 15);
  1453. inst_cream->rotate = BITS(inst, 10, 11);
  1454. inst_cream->Rm = BITS(inst, 0, 3);
  1455. if (CHECK_RM || CHECK_RN)
  1456. inst_base->load_r15 = 1;
  1457. return inst_base;
  1458. }
  1459. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrb)(unsigned int inst, int index)
  1460. {
  1461. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1462. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1463. inst_base->cond = BITS(inst, 28, 31);
  1464. inst_base->idx = index;
  1465. inst_base->br = NON_BRANCH;
  1466. inst_cream->inst = inst;
  1467. inst_cream->get_addr = get_calc_addr_op(inst);
  1468. if (BITS(inst, 12, 15) == 15) {
  1469. inst_base->br = INDIRECT_BRANCH;
  1470. }
  1471. return inst_base;
  1472. }
  1473. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrbt)(unsigned int inst, int index)
  1474. {
  1475. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1476. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1477. inst_base->cond = BITS(inst, 28, 31);
  1478. inst_base->idx = index;
  1479. inst_base->br = NON_BRANCH;
  1480. inst_cream->inst = inst;
  1481. if (I_BIT == 0) {
  1482. inst_cream->get_addr = LnSWoUB(ImmediatePostIndexed);
  1483. } else {
  1484. DEBUG_MSG;
  1485. }
  1486. #if 0
  1487. inst_cream->get_addr = get_calc_addr_op(inst);
  1488. if(inst == 0x54f13001) {
  1489. DEBUG_LOG(ARM11, "get_calc_addr_op:%llx\n", inst_cream->get_addr);
  1490. }
  1491. #endif
  1492. if (BITS(inst, 12, 15) == 15) {
  1493. inst_base->br = INDIRECT_BRANCH;
  1494. }
  1495. return inst_base;
  1496. }
  1497. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrd)(unsigned int inst, int index)
  1498. {
  1499. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1500. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1501. inst_base->cond = BITS(inst, 28, 31);
  1502. inst_base->idx = index;
  1503. inst_base->br = NON_BRANCH;
  1504. inst_cream->inst = inst;
  1505. inst_cream->get_addr = get_calc_addr_op(inst);
  1506. return inst_base;
  1507. }
  1508. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrex)(unsigned int inst, int index)
  1509. {
  1510. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  1511. generic_arm_inst *inst_cream = (generic_arm_inst *)inst_base->component;
  1512. inst_base->cond = BITS(inst, 28, 31);
  1513. inst_base->idx = index;
  1514. inst_base->br = (BITS(inst, 12, 15) == 15) ? INDIRECT_BRANCH : NON_BRANCH; // Branch if dest is R15
  1515. inst_cream->Rn = BITS(inst, 16, 19);
  1516. inst_cream->Rd = BITS(inst, 12, 15);
  1517. return inst_base;
  1518. }
  1519. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrexb)(unsigned int inst, int index)
  1520. {
  1521. return INTERPRETER_TRANSLATE(ldrex)(inst, index);
  1522. }
  1523. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrexh)(unsigned int inst, int index)
  1524. {
  1525. return INTERPRETER_TRANSLATE(ldrex)(inst, index);
  1526. }
  1527. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrexd)(unsigned int inst, int index)
  1528. {
  1529. return INTERPRETER_TRANSLATE(ldrex)(inst, index);
  1530. }
  1531. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrh)(unsigned int inst, int index)
  1532. {
  1533. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1534. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1535. inst_base->cond = BITS(inst, 28, 31);
  1536. inst_base->idx = index;
  1537. inst_base->br = NON_BRANCH;
  1538. inst_cream->inst = inst;
  1539. inst_cream->get_addr = get_calc_addr_op(inst);
  1540. if (BITS(inst, 12, 15) == 15) {
  1541. inst_base->br = INDIRECT_BRANCH;
  1542. }
  1543. return inst_base;
  1544. }
  1545. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrsb)(unsigned int inst, int index)
  1546. {
  1547. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1548. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1549. inst_base->cond = BITS(inst, 28, 31);
  1550. inst_base->idx = index;
  1551. inst_base->br = NON_BRANCH;
  1552. inst_cream->inst = inst;
  1553. inst_cream->get_addr = get_calc_addr_op(inst);
  1554. if (BITS(inst, 12, 15) == 15) {
  1555. inst_base->br = INDIRECT_BRANCH;
  1556. }
  1557. return inst_base;
  1558. }
  1559. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrsh)(unsigned int inst, int index)
  1560. {
  1561. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1562. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1563. inst_base->cond = BITS(inst, 28, 31);
  1564. inst_base->idx = index;
  1565. inst_base->br = NON_BRANCH;
  1566. inst_cream->inst = inst;
  1567. inst_cream->get_addr = get_calc_addr_op(inst);
  1568. if (BITS(inst, 12, 15) == 15) {
  1569. inst_base->br = INDIRECT_BRANCH;
  1570. }
  1571. return inst_base;
  1572. }
  1573. ARM_INST_PTR INTERPRETER_TRANSLATE(ldrt)(unsigned int inst, int index)
  1574. {
  1575. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  1576. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  1577. inst_base->cond = BITS(inst, 28, 31);
  1578. inst_base->idx = index;
  1579. inst_base->br = NON_BRANCH;
  1580. inst_cream->inst = inst;
  1581. if (I_BIT == 0) {
  1582. inst_cream->get_addr = LnSWoUB(ImmediatePostIndexed);
  1583. } else {
  1584. DEBUG_MSG;
  1585. }
  1586. if (BITS(inst, 12, 15) == 15) {
  1587. inst_base->br = INDIRECT_BRANCH;
  1588. }
  1589. return inst_base;
  1590. }
  1591. ARM_INST_PTR INTERPRETER_TRANSLATE(mcr)(unsigned int inst, int index)
  1592. {
  1593. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(mcr_inst));
  1594. mcr_inst *inst_cream = (mcr_inst *)inst_base->component;
  1595. inst_base->cond = BITS(inst, 28, 31);
  1596. inst_base->idx = index;
  1597. inst_base->br = NON_BRANCH;
  1598. inst_cream->crn = BITS(inst, 16, 19);
  1599. inst_cream->crm = BITS(inst, 0, 3);
  1600. inst_cream->opcode_1 = BITS(inst, 21, 23);
  1601. inst_cream->opcode_2 = BITS(inst, 5, 7);
  1602. inst_cream->Rd = BITS(inst, 12, 15);
  1603. inst_cream->cp_num = BITS(inst, 8, 11);
  1604. inst_cream->inst = inst;
  1605. return inst_base;
  1606. }
  1607. ARM_INST_PTR INTERPRETER_TRANSLATE(mcrr)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("MCRR"); }
  1608. ARM_INST_PTR INTERPRETER_TRANSLATE(mla)(unsigned int inst, int index)
  1609. {
  1610. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(mla_inst));
  1611. mla_inst *inst_cream = (mla_inst *)inst_base->component;
  1612. inst_base->cond = BITS(inst, 28, 31);
  1613. inst_base->idx = index;
  1614. inst_base->br = NON_BRANCH;
  1615. inst_base->load_r15 = 0;
  1616. inst_cream->S = BIT(inst, 20);
  1617. inst_cream->Rn = BITS(inst, 12, 15);
  1618. inst_cream->Rd = BITS(inst, 16, 19);
  1619. inst_cream->Rs = BITS(inst, 8, 11);
  1620. inst_cream->Rm = BITS(inst, 0, 3);
  1621. if (CHECK_RM || CHECK_RN || CHECK_RS)
  1622. inst_base->load_r15 = 1;
  1623. return inst_base;
  1624. }
  1625. ARM_INST_PTR INTERPRETER_TRANSLATE(mov)(unsigned int inst, int index)
  1626. {
  1627. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(mov_inst));
  1628. mov_inst *inst_cream = (mov_inst *)inst_base->component;
  1629. inst_base->cond = BITS(inst, 28, 31);
  1630. inst_base->idx = index;
  1631. inst_base->br = NON_BRANCH;
  1632. inst_cream->I = BIT(inst, 25);
  1633. inst_cream->S = BIT(inst, 20);
  1634. inst_cream->Rd = BITS(inst, 12, 15);
  1635. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1636. inst_cream->shtop_func = get_shtop(inst);
  1637. if (inst_cream->Rd == 15) {
  1638. inst_base->br = INDIRECT_BRANCH;
  1639. }
  1640. return inst_base;
  1641. }
  1642. ARM_INST_PTR INTERPRETER_TRANSLATE(mrc)(unsigned int inst, int index)
  1643. {
  1644. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(mrc_inst));
  1645. mrc_inst *inst_cream = (mrc_inst *)inst_base->component;
  1646. inst_base->cond = BITS(inst, 28, 31);
  1647. inst_base->idx = index;
  1648. inst_base->br = NON_BRANCH;
  1649. inst_cream->crn = BITS(inst, 16, 19);
  1650. inst_cream->crm = BITS(inst, 0, 3);
  1651. inst_cream->opcode_1 = BITS(inst, 21, 23);
  1652. inst_cream->opcode_2 = BITS(inst, 5, 7);
  1653. inst_cream->Rd = BITS(inst, 12, 15);
  1654. inst_cream->cp_num = BITS(inst, 8, 11);
  1655. inst_cream->inst = inst;
  1656. return inst_base;
  1657. }
  1658. ARM_INST_PTR INTERPRETER_TRANSLATE(mrrc)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("MRRC"); }
  1659. ARM_INST_PTR INTERPRETER_TRANSLATE(mrs)(unsigned int inst, int index)
  1660. {
  1661. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(mrs_inst));
  1662. mrs_inst *inst_cream = (mrs_inst *)inst_base->component;
  1663. inst_base->cond = BITS(inst, 28, 31);
  1664. inst_base->idx = index;
  1665. inst_base->br = NON_BRANCH;
  1666. inst_cream->Rd = BITS(inst, 12, 15);
  1667. inst_cream->R = BIT(inst, 22);
  1668. return inst_base;
  1669. }
  1670. ARM_INST_PTR INTERPRETER_TRANSLATE(msr)(unsigned int inst, int index)
  1671. {
  1672. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(msr_inst));
  1673. msr_inst *inst_cream = (msr_inst *)inst_base->component;
  1674. inst_base->cond = BITS(inst, 28, 31);
  1675. inst_base->idx = index;
  1676. inst_base->br = NON_BRANCH;
  1677. inst_cream->field_mask = BITS(inst, 16, 19);
  1678. inst_cream->R = BIT(inst, 22);
  1679. inst_cream->inst = inst;
  1680. return inst_base;
  1681. }
  1682. ARM_INST_PTR INTERPRETER_TRANSLATE(mul)(unsigned int inst, int index)
  1683. {
  1684. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(mul_inst));
  1685. mul_inst *inst_cream = (mul_inst *)inst_base->component;
  1686. inst_base->cond = BITS(inst, 28, 31);
  1687. inst_base->idx = index;
  1688. inst_base->br = NON_BRANCH;
  1689. inst_base->load_r15 = 0;
  1690. inst_cream->S = BIT(inst, 20);
  1691. inst_cream->Rm = BITS(inst, 0, 3);
  1692. inst_cream->Rs = BITS(inst, 8, 11);
  1693. inst_cream->Rd = BITS(inst, 16, 19);
  1694. if (CHECK_RM || CHECK_RS)
  1695. inst_base->load_r15 = 1;
  1696. return inst_base;
  1697. }
  1698. ARM_INST_PTR INTERPRETER_TRANSLATE(mvn)(unsigned int inst, int index)
  1699. {
  1700. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(mvn_inst));
  1701. mvn_inst *inst_cream = (mvn_inst *)inst_base->component;
  1702. inst_base->cond = BITS(inst, 28, 31);
  1703. inst_base->idx = index;
  1704. inst_base->br = NON_BRANCH;
  1705. inst_cream->I = BIT(inst, 25);
  1706. inst_cream->S = BIT(inst, 20);
  1707. inst_cream->Rd = BITS(inst, 12, 15);
  1708. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1709. inst_cream->shtop_func = get_shtop(inst);
  1710. if (inst_cream->Rd == 15) {
  1711. inst_base->br = INDIRECT_BRANCH;
  1712. }
  1713. return inst_base;
  1714. }
  1715. ARM_INST_PTR INTERPRETER_TRANSLATE(orr)(unsigned int inst, int index)
  1716. {
  1717. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(orr_inst));
  1718. orr_inst *inst_cream = (orr_inst *)inst_base->component;
  1719. inst_base->cond = BITS(inst, 28, 31);
  1720. inst_base->idx = index;
  1721. inst_base->br = NON_BRANCH;
  1722. inst_base->load_r15 = 0;
  1723. inst_cream->I = BIT(inst, 25);
  1724. inst_cream->S = BIT(inst, 20);
  1725. inst_cream->Rd = BITS(inst, 12, 15);
  1726. inst_cream->Rn = BITS(inst, 16, 19);
  1727. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1728. inst_cream->shtop_func = get_shtop(inst);
  1729. if (CHECK_RN)
  1730. inst_base->load_r15 = 1;
  1731. if (inst_cream->Rd == 15) {
  1732. inst_base->br = INDIRECT_BRANCH;
  1733. }
  1734. return inst_base;
  1735. }
  1736. ARM_INST_PTR INTERPRETER_TRANSLATE(pkhbt)(unsigned int inst, int index)
  1737. {
  1738. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(pkh_inst));
  1739. pkh_inst *inst_cream = (pkh_inst *)inst_base->component;
  1740. inst_base->cond = BITS(inst, 28, 31);
  1741. inst_base->idx = index;
  1742. inst_base->br = NON_BRANCH;
  1743. inst_base->load_r15 = 0;
  1744. inst_cream->Rd = BITS(inst, 12, 15);
  1745. inst_cream->Rn = BITS(inst, 16, 19);
  1746. inst_cream->Rm = BITS(inst, 0, 3);
  1747. inst_cream->imm = BITS(inst, 7, 11);
  1748. return inst_base;
  1749. }
  1750. ARM_INST_PTR INTERPRETER_TRANSLATE(pkhtb)(unsigned int inst, int index)
  1751. {
  1752. return INTERPRETER_TRANSLATE(pkhbt)(inst, index);
  1753. }
  1754. ARM_INST_PTR INTERPRETER_TRANSLATE(pld)(unsigned int inst, int index)
  1755. {
  1756. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(pld_inst));
  1757. inst_base->cond = BITS(inst, 28, 31);
  1758. inst_base->idx = index;
  1759. inst_base->br = NON_BRANCH;
  1760. inst_base->load_r15 = 0;
  1761. return inst_base;
  1762. }
  1763. ARM_INST_PTR INTERPRETER_TRANSLATE(qadd)(unsigned int inst, int index)
  1764. {
  1765. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  1766. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  1767. inst_base->cond = BITS(inst, 28, 31);
  1768. inst_base->idx = index;
  1769. inst_base->br = NON_BRANCH;
  1770. inst_base->load_r15 = 0;
  1771. inst_cream->op1 = BITS(inst, 21, 22);
  1772. inst_cream->Rm = BITS(inst, 0, 3);
  1773. inst_cream->Rn = BITS(inst, 16, 19);
  1774. inst_cream->Rd = BITS(inst, 12, 15);
  1775. return inst_base;
  1776. }
  1777. ARM_INST_PTR INTERPRETER_TRANSLATE(qdadd)(unsigned int inst, int index)
  1778. {
  1779. return INTERPRETER_TRANSLATE(qadd)(inst, index);
  1780. }
  1781. ARM_INST_PTR INTERPRETER_TRANSLATE(qdsub)(unsigned int inst, int index)
  1782. {
  1783. return INTERPRETER_TRANSLATE(qadd)(inst, index);
  1784. }
  1785. ARM_INST_PTR INTERPRETER_TRANSLATE(qsub)(unsigned int inst, int index)
  1786. {
  1787. return INTERPRETER_TRANSLATE(qadd)(inst, index);
  1788. }
  1789. ARM_INST_PTR INTERPRETER_TRANSLATE(qadd8)(unsigned int inst, int index)
  1790. {
  1791. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  1792. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  1793. inst_base->cond = BITS(inst, 28, 31);
  1794. inst_base->idx = index;
  1795. inst_base->br = NON_BRANCH;
  1796. inst_base->load_r15 = 0;
  1797. inst_cream->Rm = BITS(inst, 0, 3);
  1798. inst_cream->Rn = BITS(inst, 16, 19);
  1799. inst_cream->Rd = BITS(inst, 12, 15);
  1800. inst_cream->op1 = BITS(inst, 20, 21);
  1801. inst_cream->op2 = BITS(inst, 5, 7);
  1802. return inst_base;
  1803. }
  1804. ARM_INST_PTR INTERPRETER_TRANSLATE(qadd16)(unsigned int inst, int index)
  1805. {
  1806. return INTERPRETER_TRANSLATE(qadd8)(inst, index);
  1807. }
  1808. ARM_INST_PTR INTERPRETER_TRANSLATE(qaddsubx)(unsigned int inst, int index)
  1809. {
  1810. return INTERPRETER_TRANSLATE(qadd8)(inst, index);
  1811. }
  1812. ARM_INST_PTR INTERPRETER_TRANSLATE(qsub8)(unsigned int inst, int index)
  1813. {
  1814. return INTERPRETER_TRANSLATE(qadd8)(inst, index);
  1815. }
  1816. ARM_INST_PTR INTERPRETER_TRANSLATE(qsub16)(unsigned int inst, int index)
  1817. {
  1818. return INTERPRETER_TRANSLATE(qadd8)(inst, index);
  1819. }
  1820. ARM_INST_PTR INTERPRETER_TRANSLATE(qsubaddx)(unsigned int inst, int index)
  1821. {
  1822. return INTERPRETER_TRANSLATE(qadd8)(inst, index);
  1823. }
  1824. ARM_INST_PTR INTERPRETER_TRANSLATE(rev)(unsigned int inst, int index)
  1825. {
  1826. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(rev_inst));
  1827. rev_inst* const inst_cream = (rev_inst*)inst_base->component;
  1828. inst_base->cond = BITS(inst, 28, 31);
  1829. inst_base->idx = index;
  1830. inst_base->br = NON_BRANCH;
  1831. inst_base->load_r15 = 0;
  1832. inst_cream->Rm = BITS(inst, 0, 3);
  1833. inst_cream->Rd = BITS(inst, 12, 15);
  1834. inst_cream->op1 = BITS(inst, 20, 22);
  1835. inst_cream->op2 = BITS(inst, 5, 7);
  1836. return inst_base;
  1837. }
  1838. ARM_INST_PTR INTERPRETER_TRANSLATE(rev16)(unsigned int inst, int index)
  1839. {
  1840. return INTERPRETER_TRANSLATE(rev)(inst, index);
  1841. }
  1842. ARM_INST_PTR INTERPRETER_TRANSLATE(revsh)(unsigned int inst, int index)
  1843. {
  1844. return INTERPRETER_TRANSLATE(rev)(inst, index);
  1845. }
  1846. ARM_INST_PTR INTERPRETER_TRANSLATE(rfe)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("RFE"); }
  1847. ARM_INST_PTR INTERPRETER_TRANSLATE(rsb)(unsigned int inst, int index)
  1848. {
  1849. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(rsb_inst));
  1850. rsb_inst *inst_cream = (rsb_inst *)inst_base->component;
  1851. inst_base->cond = BITS(inst, 28, 31);
  1852. inst_base->idx = index;
  1853. inst_base->br = NON_BRANCH;
  1854. inst_base->load_r15 = 0;
  1855. inst_cream->I = BIT(inst, 25);
  1856. inst_cream->S = BIT(inst, 20);
  1857. inst_cream->Rn = BITS(inst, 16, 19);
  1858. inst_cream->Rd = BITS(inst, 12, 15);
  1859. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1860. inst_cream->shtop_func = get_shtop(inst);
  1861. if (CHECK_RN)
  1862. inst_base->load_r15 = 1;
  1863. if (inst_cream->Rd == 15) {
  1864. inst_base->br = INDIRECT_BRANCH;
  1865. }
  1866. return inst_base;
  1867. }
  1868. ARM_INST_PTR INTERPRETER_TRANSLATE(rsc)(unsigned int inst, int index)
  1869. {
  1870. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(rsc_inst));
  1871. rsc_inst *inst_cream = (rsc_inst *)inst_base->component;
  1872. inst_base->cond = BITS(inst, 28, 31);
  1873. inst_base->idx = index;
  1874. inst_base->br = NON_BRANCH;
  1875. inst_base->load_r15 = 0;
  1876. inst_cream->I = BIT(inst, 25);
  1877. inst_cream->S = BIT(inst, 20);
  1878. inst_cream->Rn = BITS(inst, 16, 19);
  1879. inst_cream->Rd = BITS(inst, 12, 15);
  1880. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1881. inst_cream->shtop_func = get_shtop(inst);
  1882. if (CHECK_RN)
  1883. inst_base->load_r15 = 1;
  1884. if (inst_cream->Rd == 15) {
  1885. inst_base->br = INDIRECT_BRANCH;
  1886. }
  1887. return inst_base;
  1888. }
  1889. ARM_INST_PTR INTERPRETER_TRANSLATE(sadd8)(unsigned int inst, int index)
  1890. {
  1891. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  1892. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  1893. inst_base->cond = BITS(inst, 28, 31);
  1894. inst_base->idx = index;
  1895. inst_base->br = NON_BRANCH;
  1896. inst_base->load_r15 = 0;
  1897. inst_cream->Rm = BITS(inst, 0, 3);
  1898. inst_cream->Rn = BITS(inst, 16, 19);
  1899. inst_cream->Rd = BITS(inst, 12, 15);
  1900. inst_cream->op1 = BITS(inst, 20, 21);
  1901. inst_cream->op2 = BITS(inst, 5, 7);
  1902. return inst_base;
  1903. }
  1904. ARM_INST_PTR INTERPRETER_TRANSLATE(sadd16)(unsigned int inst, int index)
  1905. {
  1906. return INTERPRETER_TRANSLATE(sadd8)(inst, index);
  1907. }
  1908. ARM_INST_PTR INTERPRETER_TRANSLATE(saddsubx)(unsigned int inst, int index)
  1909. {
  1910. return INTERPRETER_TRANSLATE(sadd8)(inst, index);
  1911. }
  1912. ARM_INST_PTR INTERPRETER_TRANSLATE(ssub8)(unsigned int inst, int index)
  1913. {
  1914. return INTERPRETER_TRANSLATE(sadd8)(inst, index);
  1915. }
  1916. ARM_INST_PTR INTERPRETER_TRANSLATE(ssub16)(unsigned int inst, int index)
  1917. {
  1918. return INTERPRETER_TRANSLATE(sadd8)(inst, index);
  1919. }
  1920. ARM_INST_PTR INTERPRETER_TRANSLATE(ssubaddx)(unsigned int inst, int index)
  1921. {
  1922. return INTERPRETER_TRANSLATE(sadd8)(inst, index);
  1923. }
  1924. ARM_INST_PTR INTERPRETER_TRANSLATE(sbc)(unsigned int inst, int index)
  1925. {
  1926. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(sbc_inst));
  1927. sbc_inst *inst_cream = (sbc_inst *)inst_base->component;
  1928. inst_base->cond = BITS(inst, 28, 31);
  1929. inst_base->idx = index;
  1930. inst_base->br = NON_BRANCH;
  1931. inst_base->load_r15 = 0;
  1932. inst_cream->I = BIT(inst, 25);
  1933. inst_cream->S = BIT(inst, 20);
  1934. inst_cream->Rn = BITS(inst, 16, 19);
  1935. inst_cream->Rd = BITS(inst, 12, 15);
  1936. inst_cream->shifter_operand = BITS(inst, 0, 11);
  1937. inst_cream->shtop_func = get_shtop(inst);
  1938. if (CHECK_RN)
  1939. inst_base->load_r15 = 1;
  1940. if (inst_cream->Rd == 15) {
  1941. inst_base->br = INDIRECT_BRANCH;
  1942. }
  1943. return inst_base;
  1944. }
  1945. ARM_INST_PTR INTERPRETER_TRANSLATE(sel)(unsigned int inst, int index)
  1946. {
  1947. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  1948. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  1949. inst_base->cond = BITS(inst, 28, 31);
  1950. inst_base->idx = index;
  1951. inst_base->br = NON_BRANCH;
  1952. inst_base->load_r15 = 0;
  1953. inst_cream->Rm = BITS(inst, 0, 3);
  1954. inst_cream->Rn = BITS(inst, 16, 19);
  1955. inst_cream->Rd = BITS(inst, 12, 15);
  1956. inst_cream->op1 = BITS(inst, 20, 22);
  1957. inst_cream->op2 = BITS(inst, 5, 7);
  1958. return inst_base;
  1959. }
  1960. ARM_INST_PTR INTERPRETER_TRANSLATE(setend)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SETEND"); }
  1961. ARM_INST_PTR INTERPRETER_TRANSLATE(shadd8)(unsigned int inst, int index)
  1962. {
  1963. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  1964. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  1965. inst_base->cond = BITS(inst, 28, 31);
  1966. inst_base->idx = index;
  1967. inst_base->br = NON_BRANCH;
  1968. inst_base->load_r15 = 0;
  1969. inst_cream->op1 = BITS(inst, 20, 21);
  1970. inst_cream->op2 = BITS(inst, 5, 7);
  1971. inst_cream->Rm = BITS(inst, 0, 3);
  1972. inst_cream->Rn = BITS(inst, 16, 19);
  1973. inst_cream->Rd = BITS(inst, 12, 15);
  1974. return inst_base;
  1975. }
  1976. ARM_INST_PTR INTERPRETER_TRANSLATE(shadd16)(unsigned int inst, int index)
  1977. {
  1978. return INTERPRETER_TRANSLATE(shadd8)(inst, index);
  1979. }
  1980. ARM_INST_PTR INTERPRETER_TRANSLATE(shaddsubx)(unsigned int inst, int index)
  1981. {
  1982. return INTERPRETER_TRANSLATE(shadd8)(inst, index);
  1983. }
  1984. ARM_INST_PTR INTERPRETER_TRANSLATE(shsub8)(unsigned int inst, int index)
  1985. {
  1986. return INTERPRETER_TRANSLATE(shadd8)(inst, index);
  1987. }
  1988. ARM_INST_PTR INTERPRETER_TRANSLATE(shsub16)(unsigned int inst, int index)
  1989. {
  1990. return INTERPRETER_TRANSLATE(shadd8)(inst, index);
  1991. }
  1992. ARM_INST_PTR INTERPRETER_TRANSLATE(shsubaddx)(unsigned int inst, int index)
  1993. {
  1994. return INTERPRETER_TRANSLATE(shadd8)(inst, index);
  1995. }
  1996. ARM_INST_PTR INTERPRETER_TRANSLATE(smla)(unsigned int inst, int index)
  1997. {
  1998. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smla_inst));
  1999. smla_inst *inst_cream = (smla_inst *)inst_base->component;
  2000. inst_base->cond = BITS(inst, 28, 31);
  2001. inst_base->idx = index;
  2002. inst_base->br = NON_BRANCH;
  2003. inst_base->load_r15 = 0;
  2004. inst_cream->x = BIT(inst, 5);
  2005. inst_cream->y = BIT(inst, 6);
  2006. inst_cream->Rm = BITS(inst, 0, 3);
  2007. inst_cream->Rs = BITS(inst, 8, 11);
  2008. inst_cream->Rd = BITS(inst, 16, 19);
  2009. inst_cream->Rn = BITS(inst, 12, 15);
  2010. return inst_base;
  2011. }
  2012. ARM_INST_PTR INTERPRETER_TRANSLATE(smlad)(unsigned int inst, int index)
  2013. {
  2014. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(smlad_inst));
  2015. smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
  2016. inst_base->cond = BITS(inst, 28, 31);
  2017. inst_base->idx = index;
  2018. inst_base->br = NON_BRANCH;
  2019. inst_base->load_r15 = 0;
  2020. inst_cream->m = BIT(inst, 5);
  2021. inst_cream->Rn = BITS(inst, 0, 3);
  2022. inst_cream->Rm = BITS(inst, 8, 11);
  2023. inst_cream->Rd = BITS(inst, 16, 19);
  2024. inst_cream->Ra = BITS(inst, 12, 15);
  2025. inst_cream->op1 = BITS(inst, 20, 22);
  2026. inst_cream->op2 = BITS(inst, 5, 7);
  2027. return inst_base;
  2028. }
  2029. ARM_INST_PTR INTERPRETER_TRANSLATE(smuad)(unsigned int inst, int index)
  2030. {
  2031. return INTERPRETER_TRANSLATE(smlad)(inst, index);
  2032. }
  2033. ARM_INST_PTR INTERPRETER_TRANSLATE(smusd)(unsigned int inst, int index)
  2034. {
  2035. return INTERPRETER_TRANSLATE(smlad)(inst, index);
  2036. }
  2037. ARM_INST_PTR INTERPRETER_TRANSLATE(smlsd)(unsigned int inst, int index)
  2038. {
  2039. return INTERPRETER_TRANSLATE(smlad)(inst, index);
  2040. }
  2041. ARM_INST_PTR INTERPRETER_TRANSLATE(smlal)(unsigned int inst, int index)
  2042. {
  2043. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(umlal_inst));
  2044. umlal_inst *inst_cream = (umlal_inst *)inst_base->component;
  2045. inst_base->cond = BITS(inst, 28, 31);
  2046. inst_base->idx = index;
  2047. inst_base->br = NON_BRANCH;
  2048. inst_base->load_r15 = 0;
  2049. inst_cream->S = BIT(inst, 20);
  2050. inst_cream->Rm = BITS(inst, 0, 3);
  2051. inst_cream->Rs = BITS(inst, 8, 11);
  2052. inst_cream->RdHi = BITS(inst, 16, 19);
  2053. inst_cream->RdLo = BITS(inst, 12, 15);
  2054. if (CHECK_RM || CHECK_RS)
  2055. inst_base->load_r15 = 1;
  2056. return inst_base;
  2057. }
  2058. ARM_INST_PTR INTERPRETER_TRANSLATE(smlalxy)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SMLALXY"); }
  2059. ARM_INST_PTR INTERPRETER_TRANSLATE(smlaw)(unsigned int inst, int index)
  2060. {
  2061. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(smlad_inst));
  2062. smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
  2063. inst_base->cond = BITS(inst, 28, 31);
  2064. inst_base->idx = index;
  2065. inst_base->br = NON_BRANCH;
  2066. inst_base->load_r15 = 0;
  2067. inst_cream->Ra = BITS(inst, 12, 15);
  2068. inst_cream->Rm = BITS(inst, 8, 11);
  2069. inst_cream->Rn = BITS(inst, 0, 3);
  2070. inst_cream->Rd = BITS(inst, 16, 19);
  2071. inst_cream->m = BIT(inst, 6);
  2072. return inst_base;
  2073. }
  2074. ARM_INST_PTR INTERPRETER_TRANSLATE(smlald)(unsigned int inst, int index)
  2075. {
  2076. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(smlald_inst));
  2077. smlald_inst* const inst_cream = (smlald_inst*)inst_base->component;
  2078. inst_base->cond = BITS(inst, 28, 31);
  2079. inst_base->idx = index;
  2080. inst_base->br = NON_BRANCH;
  2081. inst_base->load_r15 = 0;
  2082. inst_cream->Rm = BITS(inst, 8, 11);
  2083. inst_cream->Rn = BITS(inst, 0, 3);
  2084. inst_cream->RdLo = BITS(inst, 12, 15);
  2085. inst_cream->RdHi = BITS(inst, 16, 19);
  2086. inst_cream->swap = BIT(inst, 5);
  2087. inst_cream->op1 = BITS(inst, 20, 22);
  2088. inst_cream->op2 = BITS(inst, 5, 7);
  2089. return inst_base;
  2090. }
  2091. ARM_INST_PTR INTERPRETER_TRANSLATE(smlsld)(unsigned int inst, int index)
  2092. {
  2093. return INTERPRETER_TRANSLATE(smlald)(inst, index);
  2094. }
  2095. ARM_INST_PTR INTERPRETER_TRANSLATE(smmla)(unsigned int inst, int index)
  2096. {
  2097. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(smlad_inst));
  2098. smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
  2099. inst_base->cond = BITS(inst, 28, 31);
  2100. inst_base->idx = index;
  2101. inst_base->br = NON_BRANCH;
  2102. inst_base->load_r15 = 0;
  2103. inst_cream->m = BIT(inst, 5);
  2104. inst_cream->Ra = BITS(inst, 12, 15);
  2105. inst_cream->Rm = BITS(inst, 8, 11);
  2106. inst_cream->Rn = BITS(inst, 0, 3);
  2107. inst_cream->Rd = BITS(inst, 16, 19);
  2108. inst_cream->op1 = BITS(inst, 20, 22);
  2109. inst_cream->op2 = BITS(inst, 5, 7);
  2110. return inst_base;
  2111. }
  2112. ARM_INST_PTR INTERPRETER_TRANSLATE(smmls)(unsigned int inst, int index)
  2113. {
  2114. return INTERPRETER_TRANSLATE(smmla)(inst, index);
  2115. }
  2116. ARM_INST_PTR INTERPRETER_TRANSLATE(smmul)(unsigned int inst, int index)
  2117. {
  2118. return INTERPRETER_TRANSLATE(smmla)(inst, index);
  2119. }
  2120. ARM_INST_PTR INTERPRETER_TRANSLATE(smul)(unsigned int inst, int index)
  2121. {
  2122. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smul_inst));
  2123. smul_inst *inst_cream = (smul_inst *)inst_base->component;
  2124. inst_base->cond = BITS(inst, 28, 31);
  2125. inst_base->idx = index;
  2126. inst_base->br = NON_BRANCH;
  2127. inst_base->load_r15 = 0;
  2128. inst_cream->Rd = BITS(inst, 16, 19);
  2129. inst_cream->Rs = BITS(inst, 8, 11);
  2130. inst_cream->Rm = BITS(inst, 0, 3);
  2131. inst_cream->x = BIT(inst, 5);
  2132. inst_cream->y = BIT(inst, 6);
  2133. if (CHECK_RM || CHECK_RS)
  2134. inst_base->load_r15 = 1;
  2135. return inst_base;
  2136. }
  2137. ARM_INST_PTR INTERPRETER_TRANSLATE(smull)(unsigned int inst, int index)
  2138. {
  2139. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(umull_inst));
  2140. umull_inst *inst_cream = (umull_inst *)inst_base->component;
  2141. inst_base->cond = BITS(inst, 28, 31);
  2142. inst_base->idx = index;
  2143. inst_base->br = NON_BRANCH;
  2144. inst_base->load_r15 = 0;
  2145. inst_cream->S = BIT(inst, 20);
  2146. inst_cream->Rm = BITS(inst, 0, 3);
  2147. inst_cream->Rs = BITS(inst, 8, 11);
  2148. inst_cream->RdHi = BITS(inst, 16, 19);
  2149. inst_cream->RdLo = BITS(inst, 12, 15);
  2150. if (CHECK_RM || CHECK_RS)
  2151. inst_base->load_r15 = 1;
  2152. return inst_base;
  2153. }
  2154. ARM_INST_PTR INTERPRETER_TRANSLATE(smulw)(unsigned int inst, int index)
  2155. {
  2156. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(smlad_inst));
  2157. smlad_inst *inst_cream = (smlad_inst *)inst_base->component;
  2158. inst_base->cond = BITS(inst, 28, 31);
  2159. inst_base->idx = index;
  2160. inst_base->br = NON_BRANCH;
  2161. inst_base->load_r15 = 0;
  2162. inst_cream->m = BIT(inst, 6);
  2163. inst_cream->Rm = BITS(inst, 8, 11);
  2164. inst_cream->Rn = BITS(inst, 0, 3);
  2165. inst_cream->Rd = BITS(inst, 16, 19);
  2166. if (CHECK_RM || CHECK_RN)
  2167. inst_base->load_r15 = 1;
  2168. return inst_base;
  2169. }
  2170. ARM_INST_PTR INTERPRETER_TRANSLATE(srs)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SRS"); }
  2171. ARM_INST_PTR INTERPRETER_TRANSLATE(ssat)(unsigned int inst, int index)
  2172. {
  2173. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(ssat_inst));
  2174. ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
  2175. inst_base->cond = BITS(inst, 28, 31);
  2176. inst_base->idx = index;
  2177. inst_base->br = NON_BRANCH;
  2178. inst_base->load_r15 = 0;
  2179. inst_cream->Rn = BITS(inst, 0, 3);
  2180. inst_cream->Rd = BITS(inst, 12, 15);
  2181. inst_cream->imm5 = BITS(inst, 7, 11);
  2182. inst_cream->sat_imm = BITS(inst, 16, 20);
  2183. inst_cream->shift_type = BIT(inst, 6);
  2184. return inst_base;
  2185. }
  2186. ARM_INST_PTR INTERPRETER_TRANSLATE(ssat16)(unsigned int inst, int index)
  2187. {
  2188. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(ssat_inst));
  2189. ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
  2190. inst_base->cond = BITS(inst, 28, 31);
  2191. inst_base->idx = index;
  2192. inst_base->br = NON_BRANCH;
  2193. inst_base->load_r15 = 0;
  2194. inst_cream->Rn = BITS(inst, 0, 3);
  2195. inst_cream->Rd = BITS(inst, 12, 15);
  2196. inst_cream->sat_imm = BITS(inst, 16, 19);
  2197. return inst_base;
  2198. }
  2199. ARM_INST_PTR INTERPRETER_TRANSLATE(stc)(unsigned int inst, int index)
  2200. {
  2201. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(stc_inst));
  2202. inst_base->cond = BITS(inst, 28, 31);
  2203. inst_base->idx = index;
  2204. inst_base->br = NON_BRANCH;
  2205. return inst_base;
  2206. }
  2207. ARM_INST_PTR INTERPRETER_TRANSLATE(stm)(unsigned int inst, int index)
  2208. {
  2209. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  2210. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  2211. inst_base->cond = BITS(inst, 28, 31);
  2212. inst_base->idx = index;
  2213. inst_base->br = NON_BRANCH;
  2214. inst_cream->inst = inst;
  2215. inst_cream->get_addr = get_calc_addr_op(inst);
  2216. return inst_base;
  2217. }
  2218. ARM_INST_PTR INTERPRETER_TRANSLATE(sxtb)(unsigned int inst, int index)
  2219. {
  2220. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(sxtb_inst));
  2221. sxtb_inst *inst_cream = (sxtb_inst *)inst_base->component;
  2222. inst_base->cond = BITS(inst, 28, 31);
  2223. inst_base->idx = index;
  2224. inst_base->br = NON_BRANCH;
  2225. inst_base->load_r15 = 0;
  2226. inst_cream->Rd = BITS(inst, 12, 15);
  2227. inst_cream->Rm = BITS(inst, 0, 3);
  2228. inst_cream->rotate = BITS(inst, 10, 11);
  2229. if (CHECK_RM)
  2230. inst_base->load_r15 = 1;
  2231. return inst_base;
  2232. }
  2233. ARM_INST_PTR INTERPRETER_TRANSLATE(str)(unsigned int inst, int index)
  2234. {
  2235. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  2236. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  2237. inst_base->cond = BITS(inst, 28, 31);
  2238. inst_base->idx = index;
  2239. inst_base->br = NON_BRANCH;
  2240. inst_cream->inst = inst;
  2241. inst_cream->get_addr = get_calc_addr_op(inst);
  2242. if (BITS(inst, 12, 15) == 15) {
  2243. inst_base->br = INDIRECT_BRANCH;
  2244. }
  2245. return inst_base;
  2246. }
  2247. ARM_INST_PTR INTERPRETER_TRANSLATE(uxtb)(unsigned int inst, int index)
  2248. {
  2249. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(uxth_inst));
  2250. uxth_inst *inst_cream = (uxth_inst *)inst_base->component;
  2251. inst_base->cond = BITS(inst, 28, 31);
  2252. inst_base->idx = index;
  2253. inst_base->br = NON_BRANCH;
  2254. inst_base->load_r15 = 0;
  2255. inst_cream->Rd = BITS(inst, 12, 15);
  2256. inst_cream->rotate = BITS(inst, 10, 11);
  2257. inst_cream->Rm = BITS(inst, 0, 3);
  2258. if (CHECK_RM)
  2259. inst_base->load_r15 = 1;
  2260. return inst_base;
  2261. }
  2262. ARM_INST_PTR INTERPRETER_TRANSLATE(uxtab)(unsigned int inst, int index)
  2263. {
  2264. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(uxtab_inst));
  2265. uxtab_inst *inst_cream = (uxtab_inst *)inst_base->component;
  2266. inst_base->cond = BITS(inst, 28, 31);
  2267. inst_base->idx = index;
  2268. inst_base->br = NON_BRANCH;
  2269. inst_base->load_r15 = 0;
  2270. inst_cream->Rd = BITS(inst, 12, 15);
  2271. inst_cream->rotate = BITS(inst, 10, 11);
  2272. inst_cream->Rm = BITS(inst, 0, 3);
  2273. inst_cream->Rn = BITS(inst, 16, 19);
  2274. return inst_base;
  2275. }
  2276. ARM_INST_PTR INTERPRETER_TRANSLATE(strb)(unsigned int inst, int index)
  2277. {
  2278. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  2279. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  2280. inst_base->cond = BITS(inst, 28, 31);
  2281. inst_base->idx = index;
  2282. inst_base->br = NON_BRANCH;
  2283. inst_cream->inst = inst;
  2284. inst_cream->get_addr = get_calc_addr_op(inst);
  2285. if (BITS(inst, 12, 15) == 15) {
  2286. inst_base->br = INDIRECT_BRANCH;
  2287. }
  2288. return inst_base;
  2289. }
  2290. ARM_INST_PTR INTERPRETER_TRANSLATE(strbt)(unsigned int inst, int index)
  2291. {
  2292. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  2293. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  2294. inst_base->cond = BITS(inst, 28, 31);
  2295. inst_base->idx = index;
  2296. inst_base->br = NON_BRANCH;
  2297. inst_cream->inst = inst;
  2298. // inst_cream->get_addr = get_calc_addr_op(inst);
  2299. if (I_BIT == 0) {
  2300. inst_cream->get_addr = LnSWoUB(ImmediatePostIndexed);
  2301. } else {
  2302. DEBUG_MSG;
  2303. }
  2304. if (BITS(inst, 12, 15) == 15) {
  2305. inst_base->br = INDIRECT_BRANCH;
  2306. }
  2307. return inst_base;
  2308. }
  2309. ARM_INST_PTR INTERPRETER_TRANSLATE(strd)(unsigned int inst, int index){
  2310. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  2311. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  2312. inst_base->cond = BITS(inst, 28, 31);
  2313. inst_base->idx = index;
  2314. inst_base->br = NON_BRANCH;
  2315. inst_cream->inst = inst;
  2316. inst_cream->get_addr = get_calc_addr_op(inst);
  2317. if (BITS(inst, 12, 15) == 15) {
  2318. inst_base->br = INDIRECT_BRANCH;
  2319. }
  2320. return inst_base;
  2321. }
  2322. ARM_INST_PTR INTERPRETER_TRANSLATE(strex)(unsigned int inst, int index)
  2323. {
  2324. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  2325. generic_arm_inst *inst_cream = (generic_arm_inst *)inst_base->component;
  2326. inst_base->cond = BITS(inst, 28, 31);
  2327. inst_base->idx = index;
  2328. inst_base->br = NON_BRANCH;
  2329. inst_cream->Rn = BITS(inst, 16, 19);
  2330. inst_cream->Rd = BITS(inst, 12, 15);
  2331. inst_cream->Rm = BITS(inst, 0, 3);
  2332. return inst_base;
  2333. }
  2334. ARM_INST_PTR INTERPRETER_TRANSLATE(strexb)(unsigned int inst, int index)
  2335. {
  2336. return INTERPRETER_TRANSLATE(strex)(inst, index);
  2337. }
  2338. ARM_INST_PTR INTERPRETER_TRANSLATE(strexh)(unsigned int inst, int index)
  2339. {
  2340. return INTERPRETER_TRANSLATE(strex)(inst, index);
  2341. }
  2342. ARM_INST_PTR INTERPRETER_TRANSLATE(strexd)(unsigned int inst, int index)
  2343. {
  2344. return INTERPRETER_TRANSLATE(strex)(inst, index);
  2345. }
  2346. ARM_INST_PTR INTERPRETER_TRANSLATE(strh)(unsigned int inst, int index)
  2347. {
  2348. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  2349. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  2350. inst_base->cond = BITS(inst, 28, 31);
  2351. inst_base->idx = index;
  2352. inst_base->br = NON_BRANCH;
  2353. inst_cream->inst = inst;
  2354. inst_cream->get_addr = get_calc_addr_op(inst);
  2355. if (BITS(inst, 12, 15) == 15) {
  2356. inst_base->br = INDIRECT_BRANCH;
  2357. }
  2358. return inst_base;
  2359. }
  2360. ARM_INST_PTR INTERPRETER_TRANSLATE(strt)(unsigned int inst, int index)
  2361. {
  2362. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(ldst_inst));
  2363. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  2364. inst_base->cond = BITS(inst, 28, 31);
  2365. inst_base->idx = index;
  2366. inst_base->br = NON_BRANCH;
  2367. inst_cream->inst = inst;
  2368. if (I_BIT == 0) {
  2369. inst_cream->get_addr = LnSWoUB(ImmediatePostIndexed);
  2370. } else {
  2371. DEBUG_MSG;
  2372. }
  2373. if (BITS(inst, 12, 15) == 15) {
  2374. inst_base->br = INDIRECT_BRANCH;
  2375. }
  2376. return inst_base;
  2377. }
  2378. ARM_INST_PTR INTERPRETER_TRANSLATE(sub)(unsigned int inst, int index)
  2379. {
  2380. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(sub_inst));
  2381. sub_inst *inst_cream = (sub_inst *)inst_base->component;
  2382. inst_base->cond = BITS(inst, 28, 31);
  2383. inst_base->idx = index;
  2384. inst_base->br = NON_BRANCH;
  2385. inst_base->load_r15 = 0;
  2386. inst_cream->I = BIT(inst, 25);
  2387. inst_cream->S = BIT(inst, 20);
  2388. inst_cream->Rn = BITS(inst, 16, 19);
  2389. inst_cream->Rd = BITS(inst, 12, 15);
  2390. inst_cream->shifter_operand = BITS(inst, 0, 11);
  2391. inst_cream->shtop_func = get_shtop(inst);
  2392. if (inst_cream->Rd == 15) {
  2393. inst_base->br = INDIRECT_BRANCH;
  2394. }
  2395. if (CHECK_RN)
  2396. inst_base->load_r15 = 1;
  2397. return inst_base;
  2398. }
  2399. ARM_INST_PTR INTERPRETER_TRANSLATE(swi)(unsigned int inst, int index)
  2400. {
  2401. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(swi_inst));
  2402. swi_inst *inst_cream = (swi_inst *)inst_base->component;
  2403. inst_base->cond = BITS(inst, 28, 31);
  2404. inst_base->idx = index;
  2405. inst_base->br = NON_BRANCH;
  2406. inst_cream->num = BITS(inst, 0, 23);
  2407. return inst_base;
  2408. }
  2409. ARM_INST_PTR INTERPRETER_TRANSLATE(swp)(unsigned int inst, int index)
  2410. {
  2411. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(swp_inst));
  2412. swp_inst *inst_cream = (swp_inst *)inst_base->component;
  2413. inst_base->cond = BITS(inst, 28, 31);
  2414. inst_base->idx = index;
  2415. inst_base->br = NON_BRANCH;
  2416. inst_cream->Rn = BITS(inst, 16, 19);
  2417. inst_cream->Rd = BITS(inst, 12, 15);
  2418. inst_cream->Rm = BITS(inst, 0, 3);
  2419. if (inst_cream->Rd == 15) {
  2420. inst_base->br = INDIRECT_BRANCH;
  2421. }
  2422. return inst_base;
  2423. }
  2424. ARM_INST_PTR INTERPRETER_TRANSLATE(swpb)(unsigned int inst, int index){
  2425. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(swp_inst));
  2426. swp_inst *inst_cream = (swp_inst *)inst_base->component;
  2427. inst_base->cond = BITS(inst, 28, 31);
  2428. inst_base->idx = index;
  2429. inst_base->br = NON_BRANCH;
  2430. inst_cream->Rn = BITS(inst, 16, 19);
  2431. inst_cream->Rd = BITS(inst, 12, 15);
  2432. inst_cream->Rm = BITS(inst, 0, 3);
  2433. if (inst_cream->Rd == 15) {
  2434. inst_base->br = INDIRECT_BRANCH;
  2435. }
  2436. return inst_base;
  2437. }
  2438. ARM_INST_PTR INTERPRETER_TRANSLATE(sxtab)(unsigned int inst, int index){
  2439. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(sxtab_inst));
  2440. sxtab_inst *inst_cream = (sxtab_inst *)inst_base->component;
  2441. inst_base->cond = BITS(inst, 28, 31);
  2442. inst_base->idx = index;
  2443. inst_base->br = NON_BRANCH;
  2444. inst_base->load_r15 = 0;
  2445. inst_cream->Rd = BITS(inst, 12, 15);
  2446. inst_cream->rotate = BITS(inst, 10, 11);
  2447. inst_cream->Rm = BITS(inst, 0, 3);
  2448. inst_cream->Rn = BITS(inst, 16, 19);
  2449. return inst_base;
  2450. }
  2451. ARM_INST_PTR INTERPRETER_TRANSLATE(sxtab16)(unsigned int inst, int index)
  2452. {
  2453. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(sxtab_inst));
  2454. sxtab_inst* const inst_cream = (sxtab_inst*)inst_base->component;
  2455. inst_base->cond = BITS(inst, 28, 31);
  2456. inst_base->idx = index;
  2457. inst_base->br = NON_BRANCH;
  2458. inst_base->load_r15 = 0;
  2459. inst_cream->Rm = BITS(inst, 0, 3);
  2460. inst_cream->Rn = BITS(inst, 16, 19);
  2461. inst_cream->Rd = BITS(inst, 12, 15);
  2462. inst_cream->rotate = BITS(inst, 10, 11);
  2463. return inst_base;
  2464. }
  2465. ARM_INST_PTR INTERPRETER_TRANSLATE(sxtb16)(unsigned int inst, int index)
  2466. {
  2467. return INTERPRETER_TRANSLATE(sxtab16)(inst, index);
  2468. }
  2469. ARM_INST_PTR INTERPRETER_TRANSLATE(sxtah)(unsigned int inst, int index){
  2470. LOG_WARNING(Core_ARM11, "SXTAH untested");
  2471. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(sxtah_inst));
  2472. sxtah_inst *inst_cream = (sxtah_inst *)inst_base->component;
  2473. inst_base->cond = BITS(inst, 28, 31);
  2474. inst_base->idx = index;
  2475. inst_base->br = NON_BRANCH;
  2476. inst_base->load_r15 = 0;
  2477. inst_cream->Rd = BITS(inst, 12, 15);
  2478. inst_cream->rotate = BITS(inst, 10, 11);
  2479. inst_cream->Rm = BITS(inst, 0, 3);
  2480. inst_cream->Rn = BITS(inst, 16, 19);
  2481. return inst_base;
  2482. }
  2483. ARM_INST_PTR INTERPRETER_TRANSLATE(teq)(unsigned int inst, int index)
  2484. {
  2485. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(teq_inst));
  2486. teq_inst *inst_cream = (teq_inst *)inst_base->component;
  2487. inst_base->cond = BITS(inst, 28, 31);
  2488. inst_base->idx = index;
  2489. inst_base->br = NON_BRANCH;
  2490. inst_base->load_r15 = 0;
  2491. inst_cream->I = BIT(inst, 25);
  2492. inst_cream->Rn = BITS(inst, 16, 19);
  2493. inst_cream->shifter_operand = BITS(inst, 0, 11);
  2494. inst_cream->shtop_func = get_shtop(inst);
  2495. if (CHECK_RN)
  2496. inst_base->load_r15 = 1;
  2497. return inst_base;
  2498. }
  2499. ARM_INST_PTR INTERPRETER_TRANSLATE(tst)(unsigned int inst, int index)
  2500. {
  2501. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(tst_inst));
  2502. tst_inst *inst_cream = (tst_inst *)inst_base->component;
  2503. inst_base->cond = BITS(inst, 28, 31);
  2504. inst_base->idx = index;
  2505. inst_base->br = NON_BRANCH;
  2506. inst_base->load_r15 = 0;
  2507. inst_cream->I = BIT(inst, 25);
  2508. inst_cream->S = BIT(inst, 20);
  2509. inst_cream->Rn = BITS(inst, 16, 19);
  2510. inst_cream->Rd = BITS(inst, 12, 15);
  2511. inst_cream->shifter_operand = BITS(inst, 0, 11);
  2512. inst_cream->shtop_func = get_shtop(inst);
  2513. if (inst_cream->Rd == 15) {
  2514. inst_base->br = INDIRECT_BRANCH;
  2515. }
  2516. if (CHECK_RN)
  2517. inst_base->load_r15 = 1;
  2518. return inst_base;
  2519. }
  2520. ARM_INST_PTR INTERPRETER_TRANSLATE(uadd8)(unsigned int inst, int index)
  2521. {
  2522. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  2523. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  2524. inst_base->cond = BITS(inst, 28, 31);
  2525. inst_base->idx = index;
  2526. inst_base->br = NON_BRANCH;
  2527. inst_base->load_r15 = 0;
  2528. inst_cream->op1 = BITS(inst, 20, 21);
  2529. inst_cream->op2 = BITS(inst, 5, 7);
  2530. inst_cream->Rm = BITS(inst, 0, 3);
  2531. inst_cream->Rn = BITS(inst, 16, 19);
  2532. inst_cream->Rd = BITS(inst, 12, 15);
  2533. return inst_base;
  2534. }
  2535. ARM_INST_PTR INTERPRETER_TRANSLATE(uadd16)(unsigned int inst, int index)
  2536. {
  2537. return INTERPRETER_TRANSLATE(uadd8)(inst, index);
  2538. }
  2539. ARM_INST_PTR INTERPRETER_TRANSLATE(uaddsubx)(unsigned int inst, int index)
  2540. {
  2541. return INTERPRETER_TRANSLATE(uadd8)(inst, index);
  2542. }
  2543. ARM_INST_PTR INTERPRETER_TRANSLATE(usub8)(unsigned int inst, int index)
  2544. {
  2545. return INTERPRETER_TRANSLATE(uadd8)(inst, index);
  2546. }
  2547. ARM_INST_PTR INTERPRETER_TRANSLATE(usub16)(unsigned int inst, int index)
  2548. {
  2549. return INTERPRETER_TRANSLATE(uadd8)(inst, index);
  2550. }
  2551. ARM_INST_PTR INTERPRETER_TRANSLATE(usubaddx)(unsigned int inst, int index)
  2552. {
  2553. return INTERPRETER_TRANSLATE(uadd8)(inst, index);
  2554. }
  2555. ARM_INST_PTR INTERPRETER_TRANSLATE(uhadd8)(unsigned int inst, int index)
  2556. {
  2557. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  2558. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  2559. inst_base->cond = BITS(inst, 28, 31);
  2560. inst_base->idx = index;
  2561. inst_base->br = NON_BRANCH;
  2562. inst_base->load_r15 = 0;
  2563. inst_cream->op1 = BITS(inst, 20, 21);
  2564. inst_cream->op2 = BITS(inst, 5, 7);
  2565. inst_cream->Rm = BITS(inst, 0, 3);
  2566. inst_cream->Rn = BITS(inst, 16, 19);
  2567. inst_cream->Rd = BITS(inst, 12, 15);
  2568. return inst_base;
  2569. }
  2570. ARM_INST_PTR INTERPRETER_TRANSLATE(uhadd16)(unsigned int inst, int index)
  2571. {
  2572. return INTERPRETER_TRANSLATE(uhadd8)(inst, index);
  2573. }
  2574. ARM_INST_PTR INTERPRETER_TRANSLATE(uhaddsubx)(unsigned int inst, int index)
  2575. {
  2576. return INTERPRETER_TRANSLATE(uhadd8)(inst, index);
  2577. }
  2578. ARM_INST_PTR INTERPRETER_TRANSLATE(uhsub8)(unsigned int inst, int index)
  2579. {
  2580. return INTERPRETER_TRANSLATE(uhadd8)(inst, index);
  2581. }
  2582. ARM_INST_PTR INTERPRETER_TRANSLATE(uhsub16)(unsigned int inst, int index)
  2583. {
  2584. return INTERPRETER_TRANSLATE(uhadd8)(inst, index);
  2585. }
  2586. ARM_INST_PTR INTERPRETER_TRANSLATE(uhsubaddx)(unsigned int inst, int index)
  2587. {
  2588. return INTERPRETER_TRANSLATE(uhadd8)(inst, index);
  2589. }
  2590. ARM_INST_PTR INTERPRETER_TRANSLATE(umaal)(unsigned int inst, int index)
  2591. {
  2592. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(umaal_inst));
  2593. umaal_inst* const inst_cream = (umaal_inst*)inst_base->component;
  2594. inst_base->cond = BITS(inst, 28, 31);
  2595. inst_base->idx = index;
  2596. inst_base->br = NON_BRANCH;
  2597. inst_base->load_r15 = 0;
  2598. inst_cream->Rm = BITS(inst, 8, 11);
  2599. inst_cream->Rn = BITS(inst, 0, 3);
  2600. inst_cream->RdLo = BITS(inst, 12, 15);
  2601. inst_cream->RdHi = BITS(inst, 16, 19);
  2602. if (CHECK_RM || CHECK_RN)
  2603. inst_base->load_r15 = 1;
  2604. return inst_base;
  2605. }
  2606. ARM_INST_PTR INTERPRETER_TRANSLATE(umlal)(unsigned int inst, int index)
  2607. {
  2608. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(umlal_inst));
  2609. umlal_inst *inst_cream = (umlal_inst *)inst_base->component;
  2610. inst_base->cond = BITS(inst, 28, 31);
  2611. inst_base->idx = index;
  2612. inst_base->br = NON_BRANCH;
  2613. inst_base->load_r15 = 0;
  2614. inst_cream->S = BIT(inst, 20);
  2615. inst_cream->Rm = BITS(inst, 0, 3);
  2616. inst_cream->Rs = BITS(inst, 8, 11);
  2617. inst_cream->RdHi = BITS(inst, 16, 19);
  2618. inst_cream->RdLo = BITS(inst, 12, 15);
  2619. if (CHECK_RM || CHECK_RS)
  2620. inst_base->load_r15 = 1;
  2621. return inst_base;
  2622. }
  2623. ARM_INST_PTR INTERPRETER_TRANSLATE(umull)(unsigned int inst, int index)
  2624. {
  2625. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(umull_inst));
  2626. umull_inst *inst_cream = (umull_inst *)inst_base->component;
  2627. inst_base->cond = BITS(inst, 28, 31);
  2628. inst_base->idx = index;
  2629. inst_base->br = NON_BRANCH;
  2630. inst_base->load_r15 = 0;
  2631. inst_cream->S = BIT(inst, 20);
  2632. inst_cream->Rm = BITS(inst, 0, 3);
  2633. inst_cream->Rs = BITS(inst, 8, 11);
  2634. inst_cream->RdHi = BITS(inst, 16, 19);
  2635. inst_cream->RdLo = BITS(inst, 12, 15);
  2636. if (CHECK_RM || CHECK_RS)
  2637. inst_base->load_r15 = 1;
  2638. return inst_base;
  2639. }
  2640. ARM_INST_PTR INTERPRETER_TRANSLATE(b_2_thumb)(unsigned int tinst, int index)
  2641. {
  2642. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(b_2_thumb));
  2643. b_2_thumb *inst_cream = (b_2_thumb *)inst_base->component;
  2644. inst_cream->imm = ((tinst & 0x3FF) << 1) | ((tinst & (1 << 10)) ? 0xFFFFF800 : 0);
  2645. inst_base->idx = index;
  2646. inst_base->br = DIRECT_BRANCH;
  2647. return inst_base;
  2648. }
  2649. ARM_INST_PTR INTERPRETER_TRANSLATE(b_cond_thumb)(unsigned int tinst, int index)
  2650. {
  2651. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(b_cond_thumb));
  2652. b_cond_thumb *inst_cream = (b_cond_thumb *)inst_base->component;
  2653. inst_cream->imm = (((tinst & 0x7F) << 1) | ((tinst & (1 << 7)) ? 0xFFFFFF00 : 0));
  2654. inst_cream->cond = ((tinst >> 8) & 0xf);
  2655. inst_base->idx = index;
  2656. inst_base->br = DIRECT_BRANCH;
  2657. return inst_base;
  2658. }
  2659. ARM_INST_PTR INTERPRETER_TRANSLATE(bl_1_thumb)(unsigned int tinst, int index)
  2660. {
  2661. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(bl_1_thumb));
  2662. bl_1_thumb *inst_cream = (bl_1_thumb *)inst_base->component;
  2663. inst_cream->imm = (((tinst & 0x07FF) << 12) | ((tinst & (1 << 10)) ? 0xFF800000 : 0));
  2664. inst_base->idx = index;
  2665. inst_base->br = NON_BRANCH;
  2666. return inst_base;
  2667. }
  2668. ARM_INST_PTR INTERPRETER_TRANSLATE(bl_2_thumb)(unsigned int tinst, int index)
  2669. {
  2670. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(bl_2_thumb));
  2671. bl_2_thumb *inst_cream = (bl_2_thumb *)inst_base->component;
  2672. inst_cream->imm = (tinst & 0x07FF) << 1;
  2673. inst_base->idx = index;
  2674. inst_base->br = DIRECT_BRANCH;
  2675. return inst_base;
  2676. }
  2677. ARM_INST_PTR INTERPRETER_TRANSLATE(blx_1_thumb)(unsigned int tinst, int index)
  2678. {
  2679. arm_inst *inst_base = (arm_inst *)AllocBuffer(sizeof(arm_inst) + sizeof(blx_1_thumb));
  2680. blx_1_thumb *inst_cream = (blx_1_thumb *)inst_base->component;
  2681. inst_cream->imm = (tinst & 0x07FF) << 1;
  2682. inst_cream->instr = tinst;
  2683. inst_base->idx = index;
  2684. inst_base->br = DIRECT_BRANCH;
  2685. return inst_base;
  2686. }
  2687. ARM_INST_PTR INTERPRETER_TRANSLATE(uqadd8)(unsigned int inst, int index)
  2688. {
  2689. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  2690. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  2691. inst_base->cond = BITS(inst, 28, 31);
  2692. inst_base->idx = index;
  2693. inst_base->br = NON_BRANCH;
  2694. inst_base->load_r15 = 0;
  2695. inst_cream->Rm = BITS(inst, 0, 3);
  2696. inst_cream->Rn = BITS(inst, 16, 19);
  2697. inst_cream->Rd = BITS(inst, 12, 15);
  2698. inst_cream->op1 = BITS(inst, 20, 21);
  2699. inst_cream->op2 = BITS(inst, 5, 7);
  2700. return inst_base;
  2701. }
  2702. ARM_INST_PTR INTERPRETER_TRANSLATE(uqadd16)(unsigned int inst, int index)
  2703. {
  2704. return INTERPRETER_TRANSLATE(uqadd8)(inst, index);
  2705. }
  2706. ARM_INST_PTR INTERPRETER_TRANSLATE(uqaddsubx)(unsigned int inst, int index)
  2707. {
  2708. return INTERPRETER_TRANSLATE(uqadd8)(inst, index);
  2709. }
  2710. ARM_INST_PTR INTERPRETER_TRANSLATE(uqsub8)(unsigned int inst, int index)
  2711. {
  2712. return INTERPRETER_TRANSLATE(uqadd8)(inst, index);
  2713. }
  2714. ARM_INST_PTR INTERPRETER_TRANSLATE(uqsub16)(unsigned int inst, int index)
  2715. {
  2716. return INTERPRETER_TRANSLATE(uqadd8)(inst, index);
  2717. }
  2718. ARM_INST_PTR INTERPRETER_TRANSLATE(uqsubaddx)(unsigned int inst, int index)
  2719. {
  2720. return INTERPRETER_TRANSLATE(uqadd8)(inst, index);
  2721. }
  2722. ARM_INST_PTR INTERPRETER_TRANSLATE(usada8)(unsigned int inst, int index)
  2723. {
  2724. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(generic_arm_inst));
  2725. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  2726. inst_base->cond = BITS(inst, 28, 31);
  2727. inst_base->idx = index;
  2728. inst_base->br = NON_BRANCH;
  2729. inst_base->load_r15 = 0;
  2730. inst_cream->op1 = BITS(inst, 20, 24);
  2731. inst_cream->op2 = BITS(inst, 5, 7);
  2732. inst_cream->Rm = BITS(inst, 8, 11);
  2733. inst_cream->Rn = BITS(inst, 0, 3);
  2734. inst_cream->Ra = BITS(inst, 12, 15);
  2735. return inst_base;
  2736. }
  2737. ARM_INST_PTR INTERPRETER_TRANSLATE(usad8)(unsigned int inst, int index)
  2738. {
  2739. return INTERPRETER_TRANSLATE(usada8)(inst, index);
  2740. }
  2741. ARM_INST_PTR INTERPRETER_TRANSLATE(usat)(unsigned int inst, int index)
  2742. {
  2743. return INTERPRETER_TRANSLATE(ssat)(inst, index);
  2744. }
  2745. ARM_INST_PTR INTERPRETER_TRANSLATE(usat16)(unsigned int inst, int index)
  2746. {
  2747. return INTERPRETER_TRANSLATE(ssat16)(inst, index);
  2748. }
  2749. ARM_INST_PTR INTERPRETER_TRANSLATE(uxtab16)(unsigned int inst, int index)
  2750. {
  2751. arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(uxtab_inst));
  2752. uxtab_inst* const inst_cream = (uxtab_inst*)inst_base->component;
  2753. inst_base->cond = BITS(inst, 28, 31);
  2754. inst_base->idx = index;
  2755. inst_base->br = NON_BRANCH;
  2756. inst_base->load_r15 = 0;
  2757. inst_cream->Rm = BITS(inst, 0, 3);
  2758. inst_cream->Rn = BITS(inst, 16, 19);
  2759. inst_cream->Rd = BITS(inst, 12, 15);
  2760. inst_cream->rotate = BITS(inst, 10, 11);
  2761. return inst_base;
  2762. }
  2763. ARM_INST_PTR INTERPRETER_TRANSLATE(uxtb16)(unsigned int inst, int index)
  2764. {
  2765. return INTERPRETER_TRANSLATE(uxtab16)(inst, index);
  2766. }
  2767. // Floating point VFPv3 structures and instructions
  2768. #define VFP_INTERPRETER_STRUCT
  2769. #include "core/arm/skyeye_common/vfp/vfpinstr.cpp"
  2770. #undef VFP_INTERPRETER_STRUCT
  2771. #define VFP_INTERPRETER_TRANS
  2772. #include "core/arm/skyeye_common/vfp/vfpinstr.cpp"
  2773. #undef VFP_INTERPRETER_TRANS
  2774. typedef ARM_INST_PTR (*transop_fp_t)(unsigned int, int);
  2775. const transop_fp_t arm_instruction_trans[] = {
  2776. INTERPRETER_TRANSLATE(vmla),
  2777. INTERPRETER_TRANSLATE(vmls),
  2778. INTERPRETER_TRANSLATE(vnmla),
  2779. INTERPRETER_TRANSLATE(vnmla),
  2780. INTERPRETER_TRANSLATE(vnmls),
  2781. INTERPRETER_TRANSLATE(vnmul),
  2782. INTERPRETER_TRANSLATE(vmul),
  2783. INTERPRETER_TRANSLATE(vadd),
  2784. INTERPRETER_TRANSLATE(vsub),
  2785. INTERPRETER_TRANSLATE(vdiv),
  2786. INTERPRETER_TRANSLATE(vmovi),
  2787. INTERPRETER_TRANSLATE(vmovr),
  2788. INTERPRETER_TRANSLATE(vabs),
  2789. INTERPRETER_TRANSLATE(vneg),
  2790. INTERPRETER_TRANSLATE(vsqrt),
  2791. INTERPRETER_TRANSLATE(vcmp),
  2792. INTERPRETER_TRANSLATE(vcmp2),
  2793. INTERPRETER_TRANSLATE(vcvtbds),
  2794. INTERPRETER_TRANSLATE(vcvtbff),
  2795. INTERPRETER_TRANSLATE(vcvtbfi),
  2796. INTERPRETER_TRANSLATE(vmovbrs),
  2797. INTERPRETER_TRANSLATE(vmsr),
  2798. INTERPRETER_TRANSLATE(vmovbrc),
  2799. INTERPRETER_TRANSLATE(vmrs),
  2800. INTERPRETER_TRANSLATE(vmovbcr),
  2801. INTERPRETER_TRANSLATE(vmovbrrss),
  2802. INTERPRETER_TRANSLATE(vmovbrrd),
  2803. INTERPRETER_TRANSLATE(vstr),
  2804. INTERPRETER_TRANSLATE(vpush),
  2805. INTERPRETER_TRANSLATE(vstm),
  2806. INTERPRETER_TRANSLATE(vpop),
  2807. INTERPRETER_TRANSLATE(vldr),
  2808. INTERPRETER_TRANSLATE(vldm),
  2809. INTERPRETER_TRANSLATE(srs),
  2810. INTERPRETER_TRANSLATE(rfe),
  2811. INTERPRETER_TRANSLATE(bkpt),
  2812. INTERPRETER_TRANSLATE(blx),
  2813. INTERPRETER_TRANSLATE(cps),
  2814. INTERPRETER_TRANSLATE(pld),
  2815. INTERPRETER_TRANSLATE(setend),
  2816. INTERPRETER_TRANSLATE(clrex),
  2817. INTERPRETER_TRANSLATE(rev16),
  2818. INTERPRETER_TRANSLATE(usad8),
  2819. INTERPRETER_TRANSLATE(sxtb),
  2820. INTERPRETER_TRANSLATE(uxtb),
  2821. INTERPRETER_TRANSLATE(sxth),
  2822. INTERPRETER_TRANSLATE(sxtb16),
  2823. INTERPRETER_TRANSLATE(uxth),
  2824. INTERPRETER_TRANSLATE(uxtb16),
  2825. INTERPRETER_TRANSLATE(cpy),
  2826. INTERPRETER_TRANSLATE(uxtab),
  2827. INTERPRETER_TRANSLATE(ssub8),
  2828. INTERPRETER_TRANSLATE(shsub8),
  2829. INTERPRETER_TRANSLATE(ssubaddx),
  2830. INTERPRETER_TRANSLATE(strex),
  2831. INTERPRETER_TRANSLATE(strexb),
  2832. INTERPRETER_TRANSLATE(swp),
  2833. INTERPRETER_TRANSLATE(swpb),
  2834. INTERPRETER_TRANSLATE(ssub16),
  2835. INTERPRETER_TRANSLATE(ssat16),
  2836. INTERPRETER_TRANSLATE(shsubaddx),
  2837. INTERPRETER_TRANSLATE(qsubaddx),
  2838. INTERPRETER_TRANSLATE(shaddsubx),
  2839. INTERPRETER_TRANSLATE(shadd8),
  2840. INTERPRETER_TRANSLATE(shadd16),
  2841. INTERPRETER_TRANSLATE(sel),
  2842. INTERPRETER_TRANSLATE(saddsubx),
  2843. INTERPRETER_TRANSLATE(sadd8),
  2844. INTERPRETER_TRANSLATE(sadd16),
  2845. INTERPRETER_TRANSLATE(shsub16),
  2846. INTERPRETER_TRANSLATE(umaal),
  2847. INTERPRETER_TRANSLATE(uxtab16),
  2848. INTERPRETER_TRANSLATE(usubaddx),
  2849. INTERPRETER_TRANSLATE(usub8),
  2850. INTERPRETER_TRANSLATE(usub16),
  2851. INTERPRETER_TRANSLATE(usat16),
  2852. INTERPRETER_TRANSLATE(usada8),
  2853. INTERPRETER_TRANSLATE(uqsubaddx),
  2854. INTERPRETER_TRANSLATE(uqsub8),
  2855. INTERPRETER_TRANSLATE(uqsub16),
  2856. INTERPRETER_TRANSLATE(uqaddsubx),
  2857. INTERPRETER_TRANSLATE(uqadd8),
  2858. INTERPRETER_TRANSLATE(uqadd16),
  2859. INTERPRETER_TRANSLATE(sxtab),
  2860. INTERPRETER_TRANSLATE(uhsubaddx),
  2861. INTERPRETER_TRANSLATE(uhsub8),
  2862. INTERPRETER_TRANSLATE(uhsub16),
  2863. INTERPRETER_TRANSLATE(uhaddsubx),
  2864. INTERPRETER_TRANSLATE(uhadd8),
  2865. INTERPRETER_TRANSLATE(uhadd16),
  2866. INTERPRETER_TRANSLATE(uaddsubx),
  2867. INTERPRETER_TRANSLATE(uadd8),
  2868. INTERPRETER_TRANSLATE(uadd16),
  2869. INTERPRETER_TRANSLATE(sxtah),
  2870. INTERPRETER_TRANSLATE(sxtab16),
  2871. INTERPRETER_TRANSLATE(qadd8),
  2872. INTERPRETER_TRANSLATE(bxj),
  2873. INTERPRETER_TRANSLATE(clz),
  2874. INTERPRETER_TRANSLATE(uxtah),
  2875. INTERPRETER_TRANSLATE(bx),
  2876. INTERPRETER_TRANSLATE(rev),
  2877. INTERPRETER_TRANSLATE(blx),
  2878. INTERPRETER_TRANSLATE(revsh),
  2879. INTERPRETER_TRANSLATE(qadd),
  2880. INTERPRETER_TRANSLATE(qadd16),
  2881. INTERPRETER_TRANSLATE(qaddsubx),
  2882. INTERPRETER_TRANSLATE(ldrex),
  2883. INTERPRETER_TRANSLATE(qdadd),
  2884. INTERPRETER_TRANSLATE(qdsub),
  2885. INTERPRETER_TRANSLATE(qsub),
  2886. INTERPRETER_TRANSLATE(ldrexb),
  2887. INTERPRETER_TRANSLATE(qsub8),
  2888. INTERPRETER_TRANSLATE(qsub16),
  2889. INTERPRETER_TRANSLATE(smuad),
  2890. INTERPRETER_TRANSLATE(smmul),
  2891. INTERPRETER_TRANSLATE(smusd),
  2892. INTERPRETER_TRANSLATE(smlsd),
  2893. INTERPRETER_TRANSLATE(smlsld),
  2894. INTERPRETER_TRANSLATE(smmla),
  2895. INTERPRETER_TRANSLATE(smmls),
  2896. INTERPRETER_TRANSLATE(smlald),
  2897. INTERPRETER_TRANSLATE(smlad),
  2898. INTERPRETER_TRANSLATE(smlaw),
  2899. INTERPRETER_TRANSLATE(smulw),
  2900. INTERPRETER_TRANSLATE(pkhtb),
  2901. INTERPRETER_TRANSLATE(pkhbt),
  2902. INTERPRETER_TRANSLATE(smul),
  2903. INTERPRETER_TRANSLATE(smlalxy),
  2904. INTERPRETER_TRANSLATE(smla),
  2905. INTERPRETER_TRANSLATE(mcrr),
  2906. INTERPRETER_TRANSLATE(mrrc),
  2907. INTERPRETER_TRANSLATE(cmp),
  2908. INTERPRETER_TRANSLATE(tst),
  2909. INTERPRETER_TRANSLATE(teq),
  2910. INTERPRETER_TRANSLATE(cmn),
  2911. INTERPRETER_TRANSLATE(smull),
  2912. INTERPRETER_TRANSLATE(umull),
  2913. INTERPRETER_TRANSLATE(umlal),
  2914. INTERPRETER_TRANSLATE(smlal),
  2915. INTERPRETER_TRANSLATE(mul),
  2916. INTERPRETER_TRANSLATE(mla),
  2917. INTERPRETER_TRANSLATE(ssat),
  2918. INTERPRETER_TRANSLATE(usat),
  2919. INTERPRETER_TRANSLATE(mrs),
  2920. INTERPRETER_TRANSLATE(msr),
  2921. INTERPRETER_TRANSLATE(and),
  2922. INTERPRETER_TRANSLATE(bic),
  2923. INTERPRETER_TRANSLATE(ldm),
  2924. INTERPRETER_TRANSLATE(eor),
  2925. INTERPRETER_TRANSLATE(add),
  2926. INTERPRETER_TRANSLATE(rsb),
  2927. INTERPRETER_TRANSLATE(rsc),
  2928. INTERPRETER_TRANSLATE(sbc),
  2929. INTERPRETER_TRANSLATE(adc),
  2930. INTERPRETER_TRANSLATE(sub),
  2931. INTERPRETER_TRANSLATE(orr),
  2932. INTERPRETER_TRANSLATE(mvn),
  2933. INTERPRETER_TRANSLATE(mov),
  2934. INTERPRETER_TRANSLATE(stm),
  2935. INTERPRETER_TRANSLATE(ldm),
  2936. INTERPRETER_TRANSLATE(ldrsh),
  2937. INTERPRETER_TRANSLATE(stm),
  2938. INTERPRETER_TRANSLATE(ldm),
  2939. INTERPRETER_TRANSLATE(ldrsb),
  2940. INTERPRETER_TRANSLATE(strd),
  2941. INTERPRETER_TRANSLATE(ldrh),
  2942. INTERPRETER_TRANSLATE(strh),
  2943. INTERPRETER_TRANSLATE(ldrd),
  2944. INTERPRETER_TRANSLATE(strt),
  2945. INTERPRETER_TRANSLATE(strbt),
  2946. INTERPRETER_TRANSLATE(ldrbt),
  2947. INTERPRETER_TRANSLATE(ldrt),
  2948. INTERPRETER_TRANSLATE(mrc),
  2949. INTERPRETER_TRANSLATE(mcr),
  2950. INTERPRETER_TRANSLATE(msr),
  2951. INTERPRETER_TRANSLATE(ldrb),
  2952. INTERPRETER_TRANSLATE(strb),
  2953. INTERPRETER_TRANSLATE(ldr),
  2954. INTERPRETER_TRANSLATE(ldrcond),
  2955. INTERPRETER_TRANSLATE(str),
  2956. INTERPRETER_TRANSLATE(cdp),
  2957. INTERPRETER_TRANSLATE(stc),
  2958. INTERPRETER_TRANSLATE(ldc),
  2959. INTERPRETER_TRANSLATE(swi),
  2960. INTERPRETER_TRANSLATE(bbl),
  2961. INTERPRETER_TRANSLATE(ldrexd),
  2962. INTERPRETER_TRANSLATE(strexd),
  2963. INTERPRETER_TRANSLATE(ldrexh),
  2964. INTERPRETER_TRANSLATE(strexh),
  2965. // All the thumb instructions should be placed the end of table
  2966. INTERPRETER_TRANSLATE(b_2_thumb),
  2967. INTERPRETER_TRANSLATE(b_cond_thumb),
  2968. INTERPRETER_TRANSLATE(bl_1_thumb),
  2969. INTERPRETER_TRANSLATE(bl_2_thumb),
  2970. INTERPRETER_TRANSLATE(blx_1_thumb)
  2971. };
  2972. typedef std::unordered_map<u32, int> bb_map;
  2973. bb_map CreamCache;
  2974. void insert_bb(unsigned int addr, int start) {
  2975. CreamCache[addr] = start;
  2976. }
  2977. #define TRANS_THRESHOLD 65000
  2978. int find_bb(unsigned int addr, int &start) {
  2979. int ret = -1;
  2980. bb_map::const_iterator it = CreamCache.find(addr);
  2981. if (it != CreamCache.end()) {
  2982. start = static_cast<int>(it->second);
  2983. ret = 0;
  2984. } else {
  2985. ret = -1;
  2986. }
  2987. return ret;
  2988. }
  2989. enum {
  2990. FETCH_SUCCESS,
  2991. FETCH_FAILURE
  2992. };
  2993. static tdstate decode_thumb_instr(arm_processor *cpu, uint32_t inst, addr_t addr, uint32_t *arm_inst, uint32_t* inst_size, ARM_INST_PTR* ptr_inst_base){
  2994. // Check if in Thumb mode
  2995. tdstate ret = thumb_translate (addr, inst, arm_inst, inst_size);
  2996. if(ret == t_branch){
  2997. // TODO: FIXME, endian should be judged
  2998. u32 tinstr;
  2999. if((addr & 0x3) != 0)
  3000. tinstr = inst >> 16;
  3001. else
  3002. tinstr = inst & 0xFFFF;
  3003. int inst_index;
  3004. int table_length = sizeof(arm_instruction_trans) / sizeof(transop_fp_t);
  3005. switch((tinstr & 0xF800) >> 11){
  3006. case 26:
  3007. case 27:
  3008. if (((tinstr & 0x0F00) != 0x0E00) && ((tinstr & 0x0F00) != 0x0F00)){
  3009. u32 cond = (tinstr & 0x0F00) >> 8;
  3010. inst_index = table_length - 4;
  3011. *ptr_inst_base = arm_instruction_trans[inst_index](tinstr, inst_index);
  3012. } else {
  3013. LOG_ERROR(Core_ARM11, "thumb decoder error");
  3014. }
  3015. break;
  3016. case 28:
  3017. // Branch 2, unconditional branch
  3018. inst_index = table_length - 5;
  3019. *ptr_inst_base = arm_instruction_trans[inst_index](tinstr, inst_index);
  3020. break;
  3021. case 8:
  3022. case 29:
  3023. // For BLX 1 thumb instruction
  3024. inst_index = table_length - 1;
  3025. *ptr_inst_base = arm_instruction_trans[inst_index](tinstr, inst_index);
  3026. break;
  3027. case 30:
  3028. // For BL 1 thumb instruction
  3029. inst_index = table_length - 3;
  3030. *ptr_inst_base = arm_instruction_trans[inst_index](tinstr, inst_index);
  3031. break;
  3032. case 31:
  3033. // For BL 2 thumb instruction
  3034. inst_index = table_length - 2;
  3035. *ptr_inst_base = arm_instruction_trans[inst_index](tinstr, inst_index);
  3036. break;
  3037. default:
  3038. ret = t_undefined;
  3039. break;
  3040. }
  3041. }
  3042. return ret;
  3043. }
  3044. enum {
  3045. KEEP_GOING,
  3046. FETCH_EXCEPTION
  3047. };
  3048. typedef struct instruction_set_encoding_item ISEITEM;
  3049. extern const ISEITEM arm_instruction[];
  3050. vector<uint64_t> code_page_set;
  3051. void flush_bb(uint32_t addr) {
  3052. bb_map::iterator it;
  3053. uint32_t start;
  3054. addr &= 0xfffff000;
  3055. for (it = CreamCache.begin(); it != CreamCache.end(); ) {
  3056. start = static_cast<uint32_t>(it->first);
  3057. start &= 0xfffff000;
  3058. if (start == addr) {
  3059. CreamCache.erase(it++);
  3060. } else
  3061. ++it;
  3062. }
  3063. }
  3064. int InterpreterTranslate(arm_processor *cpu, int &bb_start, addr_t addr) {
  3065. // Decode instruction, get index
  3066. // Allocate memory and init InsCream
  3067. // Go on next, until terminal instruction
  3068. // Save start addr of basicblock in CreamCache
  3069. ARM_INST_PTR inst_base = nullptr;
  3070. unsigned int inst, inst_size = 4;
  3071. int idx;
  3072. int ret = NON_BRANCH;
  3073. int thumb = 0;
  3074. int size = 0; // instruction size of basic block
  3075. bb_start = top;
  3076. if (cpu->TFlag)
  3077. thumb = THUMB;
  3078. addr_t phys_addr = addr;
  3079. addr_t pc_start = cpu->Reg[15];
  3080. while(ret == NON_BRANCH) {
  3081. inst = Memory::Read32(phys_addr & 0xFFFFFFFC);
  3082. size++;
  3083. // If we are in thumb instruction, we will translate one thumb to one corresponding arm instruction
  3084. if (cpu->TFlag) {
  3085. uint32_t arm_inst;
  3086. tdstate state;
  3087. state = decode_thumb_instr(cpu, inst, phys_addr, &arm_inst, &inst_size, &inst_base);
  3088. // We have translated the branch instruction of thumb in thumb decoder
  3089. if(state == t_branch){
  3090. goto translated;
  3091. }
  3092. inst = arm_inst;
  3093. }
  3094. ret = decode_arm_instr(inst, &idx);
  3095. if (ret == DECODE_FAILURE) {
  3096. std::string disasm = ARM_Disasm::Disassemble(phys_addr, inst);
  3097. LOG_ERROR(Core_ARM11, "Decode failure.\tPC : [0x%x]\tInstruction : %s [%x]", phys_addr, disasm.c_str(), inst);
  3098. LOG_ERROR(Core_ARM11, "cpsr=0x%x, cpu->TFlag=%d, r15=0x%x", cpu->Cpsr, cpu->TFlag, cpu->Reg[15]);
  3099. CITRA_IGNORE_EXIT(-1);
  3100. }
  3101. inst_base = arm_instruction_trans[idx](inst, idx);
  3102. translated:
  3103. phys_addr += inst_size;
  3104. if ((phys_addr & 0xfff) == 0) {
  3105. inst_base->br = END_OF_PAGE;
  3106. }
  3107. ret = inst_base->br;
  3108. };
  3109. insert_bb(pc_start, bb_start);
  3110. return KEEP_GOING;
  3111. }
  3112. #define LOG_IN_CLR skyeye_printf_in_color
  3113. int clz(unsigned int x) {
  3114. int n;
  3115. if (x == 0) return (32);
  3116. n = 1;
  3117. if ((x >> 16) == 0) { n = n + 16; x = x << 16;}
  3118. if ((x >> 24) == 0) { n = n + 8; x = x << 8;}
  3119. if ((x >> 28) == 0) { n = n + 4; x = x << 4;}
  3120. if ((x >> 30) == 0) { n = n + 2; x = x << 2;}
  3121. n = n - (x >> 31);
  3122. return n;
  3123. }
  3124. unsigned arm_dyncom_SWI (ARMul_State * state, ARMword number);
  3125. static bool InAPrivilegedMode(arm_core_t *core) {
  3126. return (core->Mode != USER32MODE);
  3127. }
  3128. unsigned InterpreterMainLoop(ARMul_State* state) {
  3129. #define CRn inst_cream->crn
  3130. #define OPCODE_2 inst_cream->opcode_2
  3131. #define CRm inst_cream->crm
  3132. #define CP15_REG(n) cpu->CP15[CP15(n)]
  3133. #define RD cpu->Reg[inst_cream->Rd]
  3134. #define RD2 cpu->Reg[inst_cream->Rd + 1]
  3135. #define RN cpu->Reg[inst_cream->Rn]
  3136. #define RM cpu->Reg[inst_cream->Rm]
  3137. #define RS cpu->Reg[inst_cream->Rs]
  3138. #define RDHI cpu->Reg[inst_cream->RdHi]
  3139. #define RDLO cpu->Reg[inst_cream->RdLo]
  3140. #define LINK_RTN_ADDR (cpu->Reg[14] = cpu->Reg[15] + 4)
  3141. #define SET_PC (cpu->Reg[15] = cpu->Reg[15] + 8 + inst_cream->signed_immed_24)
  3142. #define SHIFTER_OPERAND inst_cream->shtop_func(cpu, inst_cream->shifter_operand)
  3143. #define FETCH_INST if (inst_base->br != NON_BRANCH) goto DISPATCH; \
  3144. inst_base = (arm_inst *)&inst_buf[ptr]
  3145. #define INC_PC(l) ptr += sizeof(arm_inst) + l
  3146. // GCC and Clang have a C++ extension to support a lookup table of labels. Otherwise, fallback to a
  3147. // clunky switch statement.
  3148. #if defined __GNUC__ || defined __clang__
  3149. #define GOTO_NEXT_INST \
  3150. if (num_instrs >= cpu->NumInstrsToExecute) goto END; \
  3151. num_instrs++; \
  3152. goto *InstLabel[inst_base->idx]
  3153. #else
  3154. #define GOTO_NEXT_INST \
  3155. if (num_instrs >= cpu->NumInstrsToExecute) goto END; \
  3156. num_instrs++; \
  3157. switch(inst_base->idx) { \
  3158. case 0: goto VMLA_INST; \
  3159. case 1: goto VMLS_INST; \
  3160. case 2: goto VNMLA_INST; \
  3161. case 3: goto VNMLA_INST; \
  3162. case 4: goto VNMLS_INST; \
  3163. case 5: goto VNMUL_INST; \
  3164. case 6: goto VMUL_INST; \
  3165. case 7: goto VADD_INST; \
  3166. case 8: goto VSUB_INST; \
  3167. case 9: goto VDIV_INST; \
  3168. case 10: goto VMOVI_INST; \
  3169. case 11: goto VMOVR_INST; \
  3170. case 12: goto VABS_INST; \
  3171. case 13: goto VNEG_INST; \
  3172. case 14: goto VSQRT_INST; \
  3173. case 15: goto VCMP_INST; \
  3174. case 16: goto VCMP2_INST; \
  3175. case 17: goto VCVTBDS_INST; \
  3176. case 18: goto VCVTBFF_INST; \
  3177. case 19: goto VCVTBFI_INST; \
  3178. case 20: goto VMOVBRS_INST; \
  3179. case 21: goto VMSR_INST; \
  3180. case 22: goto VMOVBRC_INST; \
  3181. case 23: goto VMRS_INST; \
  3182. case 24: goto VMOVBCR_INST; \
  3183. case 25: goto VMOVBRRSS_INST; \
  3184. case 26: goto VMOVBRRD_INST; \
  3185. case 27: goto VSTR_INST; \
  3186. case 28: goto VPUSH_INST; \
  3187. case 29: goto VSTM_INST; \
  3188. case 30: goto VPOP_INST; \
  3189. case 31: goto VLDR_INST; \
  3190. case 32: goto VLDM_INST ; \
  3191. case 33: goto SRS_INST; \
  3192. case 34: goto RFE_INST; \
  3193. case 35: goto BKPT_INST; \
  3194. case 36: goto BLX_INST; \
  3195. case 37: goto CPS_INST; \
  3196. case 38: goto PLD_INST; \
  3197. case 39: goto SETEND_INST; \
  3198. case 40: goto CLREX_INST; \
  3199. case 41: goto REV16_INST; \
  3200. case 42: goto USAD8_INST; \
  3201. case 43: goto SXTB_INST; \
  3202. case 44: goto UXTB_INST; \
  3203. case 45: goto SXTH_INST; \
  3204. case 46: goto SXTB16_INST; \
  3205. case 47: goto UXTH_INST; \
  3206. case 48: goto UXTB16_INST; \
  3207. case 49: goto CPY_INST; \
  3208. case 50: goto UXTAB_INST; \
  3209. case 51: goto SSUB8_INST; \
  3210. case 52: goto SHSUB8_INST; \
  3211. case 53: goto SSUBADDX_INST; \
  3212. case 54: goto STREX_INST; \
  3213. case 55: goto STREXB_INST; \
  3214. case 56: goto SWP_INST; \
  3215. case 57: goto SWPB_INST; \
  3216. case 58: goto SSUB16_INST; \
  3217. case 59: goto SSAT16_INST; \
  3218. case 60: goto SHSUBADDX_INST; \
  3219. case 61: goto QSUBADDX_INST; \
  3220. case 62: goto SHADDSUBX_INST; \
  3221. case 63: goto SHADD8_INST; \
  3222. case 64: goto SHADD16_INST; \
  3223. case 65: goto SEL_INST; \
  3224. case 66: goto SADDSUBX_INST; \
  3225. case 67: goto SADD8_INST; \
  3226. case 68: goto SADD16_INST; \
  3227. case 69: goto SHSUB16_INST; \
  3228. case 70: goto UMAAL_INST; \
  3229. case 71: goto UXTAB16_INST; \
  3230. case 72: goto USUBADDX_INST; \
  3231. case 73: goto USUB8_INST; \
  3232. case 74: goto USUB16_INST; \
  3233. case 75: goto USAT16_INST; \
  3234. case 76: goto USADA8_INST; \
  3235. case 77: goto UQSUBADDX_INST; \
  3236. case 78: goto UQSUB8_INST; \
  3237. case 79: goto UQSUB16_INST; \
  3238. case 80: goto UQADDSUBX_INST; \
  3239. case 81: goto UQADD8_INST; \
  3240. case 82: goto UQADD16_INST; \
  3241. case 83: goto SXTAB_INST; \
  3242. case 84: goto UHSUBADDX_INST; \
  3243. case 85: goto UHSUB8_INST; \
  3244. case 86: goto UHSUB16_INST; \
  3245. case 87: goto UHADDSUBX_INST; \
  3246. case 88: goto UHADD8_INST; \
  3247. case 89: goto UHADD16_INST; \
  3248. case 90: goto UADDSUBX_INST; \
  3249. case 91: goto UADD8_INST; \
  3250. case 92: goto UADD16_INST; \
  3251. case 93: goto SXTAH_INST; \
  3252. case 94: goto SXTAB16_INST; \
  3253. case 95: goto QADD8_INST; \
  3254. case 96: goto BXJ_INST; \
  3255. case 97: goto CLZ_INST; \
  3256. case 98: goto UXTAH_INST; \
  3257. case 99: goto BX_INST; \
  3258. case 100: goto REV_INST; \
  3259. case 101: goto BLX_INST; \
  3260. case 102: goto REVSH_INST; \
  3261. case 103: goto QADD_INST; \
  3262. case 104: goto QADD16_INST; \
  3263. case 105: goto QADDSUBX_INST; \
  3264. case 106: goto LDREX_INST; \
  3265. case 107: goto QDADD_INST; \
  3266. case 108: goto QDSUB_INST; \
  3267. case 109: goto QSUB_INST; \
  3268. case 110: goto LDREXB_INST; \
  3269. case 111: goto QSUB8_INST; \
  3270. case 112: goto QSUB16_INST; \
  3271. case 113: goto SMUAD_INST; \
  3272. case 114: goto SMMUL_INST; \
  3273. case 115: goto SMUSD_INST; \
  3274. case 116: goto SMLSD_INST; \
  3275. case 117: goto SMLSLD_INST; \
  3276. case 118: goto SMMLA_INST; \
  3277. case 119: goto SMMLS_INST; \
  3278. case 120: goto SMLALD_INST; \
  3279. case 121: goto SMLAD_INST; \
  3280. case 122: goto SMLAW_INST; \
  3281. case 123: goto SMULW_INST; \
  3282. case 124: goto PKHTB_INST; \
  3283. case 125: goto PKHBT_INST; \
  3284. case 126: goto SMUL_INST; \
  3285. case 127: goto SMLALXY_INST; \
  3286. case 128: goto SMLA_INST; \
  3287. case 129: goto MCRR_INST; \
  3288. case 130: goto MRRC_INST; \
  3289. case 131: goto CMP_INST; \
  3290. case 132: goto TST_INST; \
  3291. case 133: goto TEQ_INST; \
  3292. case 134: goto CMN_INST; \
  3293. case 135: goto SMULL_INST; \
  3294. case 136: goto UMULL_INST; \
  3295. case 137: goto UMLAL_INST; \
  3296. case 138: goto SMLAL_INST; \
  3297. case 139: goto MUL_INST; \
  3298. case 140: goto MLA_INST; \
  3299. case 141: goto SSAT_INST; \
  3300. case 142: goto USAT_INST; \
  3301. case 143: goto MRS_INST; \
  3302. case 144: goto MSR_INST; \
  3303. case 145: goto AND_INST; \
  3304. case 146: goto BIC_INST; \
  3305. case 147: goto LDM_INST; \
  3306. case 148: goto EOR_INST; \
  3307. case 149: goto ADD_INST; \
  3308. case 150: goto RSB_INST; \
  3309. case 151: goto RSC_INST; \
  3310. case 152: goto SBC_INST; \
  3311. case 153: goto ADC_INST; \
  3312. case 154: goto SUB_INST; \
  3313. case 155: goto ORR_INST; \
  3314. case 156: goto MVN_INST; \
  3315. case 157: goto MOV_INST; \
  3316. case 158: goto STM_INST; \
  3317. case 159: goto LDM_INST; \
  3318. case 160: goto LDRSH_INST; \
  3319. case 161: goto STM_INST; \
  3320. case 162: goto LDM_INST; \
  3321. case 163: goto LDRSB_INST; \
  3322. case 164: goto STRD_INST; \
  3323. case 165: goto LDRH_INST; \
  3324. case 166: goto STRH_INST; \
  3325. case 167: goto LDRD_INST; \
  3326. case 168: goto STRT_INST; \
  3327. case 169: goto STRBT_INST; \
  3328. case 170: goto LDRBT_INST; \
  3329. case 171: goto LDRT_INST; \
  3330. case 172: goto MRC_INST; \
  3331. case 173: goto MCR_INST; \
  3332. case 174: goto MSR_INST; \
  3333. case 175: goto LDRB_INST; \
  3334. case 176: goto STRB_INST; \
  3335. case 177: goto LDR_INST; \
  3336. case 178: goto LDRCOND_INST ; \
  3337. case 179: goto STR_INST; \
  3338. case 180: goto CDP_INST; \
  3339. case 181: goto STC_INST; \
  3340. case 182: goto LDC_INST; \
  3341. case 183: goto SWI_INST; \
  3342. case 184: goto BBL_INST; \
  3343. case 185: goto LDREXD_INST; \
  3344. case 186: goto STREXD_INST; \
  3345. case 187: goto LDREXH_INST; \
  3346. case 188: goto STREXH_INST; \
  3347. case 189: goto B_2_THUMB ; \
  3348. case 190: goto B_COND_THUMB ; \
  3349. case 191: goto BL_1_THUMB ; \
  3350. case 192: goto BL_2_THUMB ; \
  3351. case 193: goto BLX_1_THUMB ; \
  3352. case 194: goto DISPATCH; \
  3353. case 195: goto INIT_INST_LENGTH; \
  3354. case 196: goto END; \
  3355. }
  3356. #endif
  3357. #define UPDATE_NFLAG(dst) (cpu->NFlag = BIT(dst, 31) ? 1 : 0)
  3358. #define UPDATE_ZFLAG(dst) (cpu->ZFlag = dst ? 0 : 1)
  3359. #define UPDATE_CFLAG(dst, lop, rop) (cpu->CFlag = ((dst < lop) || (dst < rop)))
  3360. #define UPDATE_CFLAG_CARRY_FROM_ADD(lop, rop, flag) (cpu->CFlag = (((uint64_t) lop + (uint64_t) rop + (uint64_t) flag) > 0xffffffff) )
  3361. #define UPDATE_CFLAG_NOT_BORROW_FROM_FLAG(lop, rop, flag) (cpu->CFlag = ((uint64_t) lop >= ((uint64_t) rop + (uint64_t) flag)))
  3362. #define UPDATE_CFLAG_NOT_BORROW_FROM(lop, rop) (cpu->CFlag = (lop >= rop))
  3363. #define UPDATE_CFLAG_WITH_NOT(dst, lop, rop) (cpu->CFlag = !(dst < lop))
  3364. #define UPDATE_CFLAG_WITH_SC (cpu->CFlag = cpu->shifter_carry_out)
  3365. #define UPDATE_VFLAG(dst, lop, rop) (cpu->VFlag = (((lop < 0) && (rop < 0) && (dst >= 0)) || \
  3366. ((lop >= 0) && (rop) >= 0 && (dst < 0))))
  3367. #define UPDATE_VFLAG_WITH_NOT(dst, lop, rop) (cpu->VFlag = !(((lop < 0) && (rop < 0) && (dst >= 0)) || \
  3368. ((lop >= 0) && (rop) >= 0 && (dst < 0))))
  3369. #define UPDATE_VFLAG_OVERFLOW_FROM(dst, lop, rop) (cpu->VFlag = (((lop ^ rop) & (lop ^ dst)) >> 31))
  3370. #define SAVE_NZCVT cpu->Cpsr = (cpu->Cpsr & 0x0fffffdf) | \
  3371. (cpu->NFlag << 31) | \
  3372. (cpu->ZFlag << 30) | \
  3373. (cpu->CFlag << 29) | \
  3374. (cpu->VFlag << 28) | \
  3375. (cpu->TFlag << 5)
  3376. #define LOAD_NZCVT cpu->NFlag = (cpu->Cpsr >> 31); \
  3377. cpu->ZFlag = (cpu->Cpsr >> 30) & 1; \
  3378. cpu->CFlag = (cpu->Cpsr >> 29) & 1; \
  3379. cpu->VFlag = (cpu->Cpsr >> 28) & 1; \
  3380. cpu->TFlag = (cpu->Cpsr >> 5) & 1;
  3381. #define CurrentModeHasSPSR (cpu->Mode != SYSTEM32MODE) && (cpu->Mode != USER32MODE)
  3382. #define PC (cpu->Reg[15])
  3383. #define CHECK_EXT_INT if (!cpu->NirqSig && !(cpu->Cpsr & 0x80)) goto END;
  3384. arm_processor *cpu = state;
  3385. // GCC and Clang have a C++ extension to support a lookup table of labels. Otherwise, fallback
  3386. // to a clunky switch statement.
  3387. #if defined __GNUC__ || defined __clang__
  3388. void *InstLabel[] = {
  3389. &&VMLA_INST, &&VMLS_INST, &&VNMLA_INST, &&VNMLA_INST, &&VNMLS_INST, &&VNMUL_INST, &&VMUL_INST, &&VADD_INST, &&VSUB_INST,
  3390. &&VDIV_INST, &&VMOVI_INST, &&VMOVR_INST, &&VABS_INST, &&VNEG_INST, &&VSQRT_INST, &&VCMP_INST, &&VCMP2_INST, &&VCVTBDS_INST,
  3391. &&VCVTBFF_INST, &&VCVTBFI_INST, &&VMOVBRS_INST, &&VMSR_INST, &&VMOVBRC_INST, &&VMRS_INST, &&VMOVBCR_INST, &&VMOVBRRSS_INST,
  3392. &&VMOVBRRD_INST, &&VSTR_INST, &&VPUSH_INST, &&VSTM_INST, &&VPOP_INST, &&VLDR_INST, &&VLDM_INST,
  3393. &&SRS_INST,&&RFE_INST,&&BKPT_INST,&&BLX_INST,&&CPS_INST,&&PLD_INST,&&SETEND_INST,&&CLREX_INST,&&REV16_INST,&&USAD8_INST,&&SXTB_INST,
  3394. &&UXTB_INST,&&SXTH_INST,&&SXTB16_INST,&&UXTH_INST,&&UXTB16_INST,&&CPY_INST,&&UXTAB_INST,&&SSUB8_INST,&&SHSUB8_INST,&&SSUBADDX_INST,
  3395. &&STREX_INST,&&STREXB_INST,&&SWP_INST,&&SWPB_INST,&&SSUB16_INST,&&SSAT16_INST,&&SHSUBADDX_INST,&&QSUBADDX_INST,&&SHADDSUBX_INST,
  3396. &&SHADD8_INST,&&SHADD16_INST,&&SEL_INST,&&SADDSUBX_INST,&&SADD8_INST,&&SADD16_INST,&&SHSUB16_INST,&&UMAAL_INST,&&UXTAB16_INST,
  3397. &&USUBADDX_INST,&&USUB8_INST,&&USUB16_INST,&&USAT16_INST,&&USADA8_INST,&&UQSUBADDX_INST,&&UQSUB8_INST,&&UQSUB16_INST,
  3398. &&UQADDSUBX_INST,&&UQADD8_INST,&&UQADD16_INST,&&SXTAB_INST,&&UHSUBADDX_INST,&&UHSUB8_INST,&&UHSUB16_INST,&&UHADDSUBX_INST,&&UHADD8_INST,
  3399. &&UHADD16_INST,&&UADDSUBX_INST,&&UADD8_INST,&&UADD16_INST,&&SXTAH_INST,&&SXTAB16_INST,&&QADD8_INST,&&BXJ_INST,&&CLZ_INST,&&UXTAH_INST,
  3400. &&BX_INST,&&REV_INST,&&BLX_INST,&&REVSH_INST,&&QADD_INST,&&QADD16_INST,&&QADDSUBX_INST,&&LDREX_INST,&&QDADD_INST,&&QDSUB_INST,
  3401. &&QSUB_INST,&&LDREXB_INST,&&QSUB8_INST,&&QSUB16_INST,&&SMUAD_INST,&&SMMUL_INST,&&SMUSD_INST,&&SMLSD_INST,&&SMLSLD_INST,&&SMMLA_INST,
  3402. &&SMMLS_INST,&&SMLALD_INST,&&SMLAD_INST,&&SMLAW_INST,&&SMULW_INST,&&PKHTB_INST,&&PKHBT_INST,&&SMUL_INST,&&SMLALXY_INST,&&SMLA_INST,
  3403. &&MCRR_INST,&&MRRC_INST,&&CMP_INST,&&TST_INST,&&TEQ_INST,&&CMN_INST,&&SMULL_INST,&&UMULL_INST,&&UMLAL_INST,&&SMLAL_INST,&&MUL_INST,
  3404. &&MLA_INST,&&SSAT_INST,&&USAT_INST,&&MRS_INST,&&MSR_INST,&&AND_INST,&&BIC_INST,&&LDM_INST,&&EOR_INST,&&ADD_INST,&&RSB_INST,&&RSC_INST,
  3405. &&SBC_INST,&&ADC_INST,&&SUB_INST,&&ORR_INST,&&MVN_INST,&&MOV_INST,&&STM_INST,&&LDM_INST,&&LDRSH_INST,&&STM_INST,&&LDM_INST,&&LDRSB_INST,
  3406. &&STRD_INST,&&LDRH_INST,&&STRH_INST,&&LDRD_INST,&&STRT_INST,&&STRBT_INST,&&LDRBT_INST,&&LDRT_INST,&&MRC_INST,&&MCR_INST,&&MSR_INST,
  3407. &&LDRB_INST,&&STRB_INST,&&LDR_INST,&&LDRCOND_INST, &&STR_INST,&&CDP_INST,&&STC_INST,&&LDC_INST,&&SWI_INST,&&BBL_INST,&&LDREXD_INST,
  3408. &&STREXD_INST,&&LDREXH_INST,&&STREXH_INST,&&B_2_THUMB, &&B_COND_THUMB,&&BL_1_THUMB, &&BL_2_THUMB, &&BLX_1_THUMB, &&DISPATCH,
  3409. &&INIT_INST_LENGTH,&&END
  3410. };
  3411. #endif
  3412. arm_inst * inst_base;
  3413. unsigned int lop, rop, dst;
  3414. unsigned int addr;
  3415. unsigned int phys_addr;
  3416. unsigned int last_pc = 0;
  3417. unsigned int num_instrs = 0;
  3418. static unsigned int last_physical_base = 0, last_logical_base = 0;
  3419. int ptr;
  3420. bool single_step = (cpu->NumInstrsToExecute == 1);
  3421. LOAD_NZCVT;
  3422. DISPATCH:
  3423. {
  3424. if (!cpu->NirqSig) {
  3425. if (!(cpu->Cpsr & 0x80)) {
  3426. goto END;
  3427. }
  3428. }
  3429. if (cpu->TFlag)
  3430. cpu->Reg[15] &= 0xfffffffe;
  3431. else
  3432. cpu->Reg[15] &= 0xfffffffc;
  3433. phys_addr = cpu->Reg[15];
  3434. if (find_bb(cpu->Reg[15], ptr) == -1)
  3435. if (InterpreterTranslate(cpu, ptr, cpu->Reg[15]) == FETCH_EXCEPTION)
  3436. goto END;
  3437. inst_base = (arm_inst *)&inst_buf[ptr];
  3438. GOTO_NEXT_INST;
  3439. }
  3440. ADC_INST:
  3441. {
  3442. adc_inst *inst_cream = (adc_inst *)inst_base->component;
  3443. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3444. lop = RN;
  3445. unsigned int sht_op = SHIFTER_OPERAND;
  3446. rop = SHIFTER_OPERAND + cpu->CFlag;
  3447. RD = dst = lop + rop;
  3448. if (inst_cream->S && (inst_cream->Rd == 15)) {
  3449. if (CurrentModeHasSPSR) {
  3450. cpu->Cpsr = cpu->Spsr_copy;
  3451. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  3452. LOAD_NZCVT;
  3453. }
  3454. } else if (inst_cream->S) {
  3455. UPDATE_NFLAG(dst);
  3456. UPDATE_ZFLAG(dst);
  3457. UPDATE_CFLAG_CARRY_FROM_ADD(lop, sht_op, cpu->CFlag);
  3458. UPDATE_VFLAG((int)dst, (int)lop, (int)rop);
  3459. }
  3460. if (inst_cream->Rd == 15) {
  3461. INC_PC(sizeof(adc_inst));
  3462. goto DISPATCH;
  3463. }
  3464. }
  3465. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3466. INC_PC(sizeof(adc_inst));
  3467. FETCH_INST;
  3468. GOTO_NEXT_INST;
  3469. }
  3470. ADD_INST:
  3471. {
  3472. add_inst *inst_cream = (add_inst *)inst_base->component;
  3473. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3474. lop = RN;
  3475. if (inst_cream->Rn == 15) {
  3476. lop += 2 * GET_INST_SIZE(cpu);
  3477. }
  3478. rop = SHIFTER_OPERAND;
  3479. RD = dst = lop + rop;
  3480. if (inst_cream->S && (inst_cream->Rd == 15)) {
  3481. if (CurrentModeHasSPSR) {
  3482. cpu->Cpsr = cpu->Spsr_copy;
  3483. switch_mode(cpu, cpu->Cpsr & 0x1f);
  3484. LOAD_NZCVT;
  3485. }
  3486. } else if (inst_cream->S) {
  3487. UPDATE_NFLAG(dst);
  3488. UPDATE_ZFLAG(dst);
  3489. UPDATE_CFLAG(dst, lop, rop);
  3490. UPDATE_VFLAG((int)dst, (int)lop, (int)rop);
  3491. }
  3492. if (inst_cream->Rd == 15) {
  3493. INC_PC(sizeof(add_inst));
  3494. goto DISPATCH;
  3495. }
  3496. }
  3497. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3498. INC_PC(sizeof(add_inst));
  3499. FETCH_INST;
  3500. GOTO_NEXT_INST;
  3501. }
  3502. AND_INST:
  3503. {
  3504. and_inst *inst_cream = (and_inst *)inst_base->component;
  3505. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3506. lop = RN;
  3507. rop = SHIFTER_OPERAND;
  3508. RD = dst = lop & rop;
  3509. if (inst_cream->S && (inst_cream->Rd == 15)) {
  3510. if (CurrentModeHasSPSR) {
  3511. cpu->Cpsr = cpu->Spsr_copy;
  3512. switch_mode(cpu, cpu->Cpsr & 0x1f);
  3513. LOAD_NZCVT;
  3514. }
  3515. } else if (inst_cream->S) {
  3516. UPDATE_NFLAG(dst);
  3517. UPDATE_ZFLAG(dst);
  3518. UPDATE_CFLAG_WITH_SC;
  3519. }
  3520. if (inst_cream->Rd == 15) {
  3521. INC_PC(sizeof(and_inst));
  3522. goto DISPATCH;
  3523. }
  3524. }
  3525. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3526. INC_PC(sizeof(and_inst));
  3527. FETCH_INST;
  3528. GOTO_NEXT_INST;
  3529. }
  3530. BBL_INST:
  3531. {
  3532. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3533. bbl_inst *inst_cream = (bbl_inst *)inst_base->component;
  3534. if (inst_cream->L) {
  3535. LINK_RTN_ADDR;
  3536. }
  3537. SET_PC;
  3538. INC_PC(sizeof(bbl_inst));
  3539. goto DISPATCH;
  3540. }
  3541. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3542. INC_PC(sizeof(bbl_inst));
  3543. goto DISPATCH;
  3544. }
  3545. BIC_INST:
  3546. {
  3547. bic_inst *inst_cream = (bic_inst *)inst_base->component;
  3548. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3549. lop = RN;
  3550. if (inst_cream->Rn == 15) {
  3551. lop += 2 * GET_INST_SIZE(cpu);
  3552. }
  3553. rop = SHIFTER_OPERAND;
  3554. RD = dst = lop & (~rop);
  3555. if ((inst_cream->S) && (inst_cream->Rd == 15)) {
  3556. if (CurrentModeHasSPSR) {
  3557. cpu->Cpsr = cpu->Spsr_copy;
  3558. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  3559. LOAD_NZCVT;
  3560. }
  3561. } else if (inst_cream->S) {
  3562. UPDATE_NFLAG(dst);
  3563. UPDATE_ZFLAG(dst);
  3564. UPDATE_CFLAG_WITH_SC;
  3565. }
  3566. if (inst_cream->Rd == 15) {
  3567. INC_PC(sizeof(bic_inst));
  3568. goto DISPATCH;
  3569. }
  3570. }
  3571. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3572. INC_PC(sizeof(bic_inst));
  3573. FETCH_INST;
  3574. GOTO_NEXT_INST;
  3575. }
  3576. BKPT_INST:
  3577. BLX_INST:
  3578. {
  3579. blx_inst *inst_cream = (blx_inst *)inst_base->component;
  3580. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3581. unsigned int inst = inst_cream->inst;
  3582. if (BITS(inst, 20, 27) == 0x12 && BITS(inst, 4, 7) == 0x3) {
  3583. cpu->Reg[14] = (cpu->Reg[15] + GET_INST_SIZE(cpu));
  3584. if(cpu->TFlag)
  3585. cpu->Reg[14] |= 0x1;
  3586. cpu->Reg[15] = cpu->Reg[inst_cream->val.Rm] & 0xfffffffe;
  3587. cpu->TFlag = cpu->Reg[inst_cream->val.Rm] & 0x1;
  3588. } else {
  3589. cpu->Reg[14] = (cpu->Reg[15] + GET_INST_SIZE(cpu));
  3590. cpu->TFlag = 0x1;
  3591. int signed_int = inst_cream->val.signed_immed_24;
  3592. signed_int = (signed_int) & 0x800000 ? (0x3F000000 | signed_int) : signed_int;
  3593. signed_int = signed_int << 2;
  3594. cpu->Reg[15] = cpu->Reg[15] + 8 + signed_int + (BIT(inst, 24) << 1);
  3595. }
  3596. INC_PC(sizeof(blx_inst));
  3597. goto DISPATCH;
  3598. }
  3599. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3600. INC_PC(sizeof(blx_inst));
  3601. goto DISPATCH;
  3602. }
  3603. BX_INST:
  3604. BXJ_INST:
  3605. {
  3606. // Note that only the 'fail' case of BXJ is emulated. This is because
  3607. // the facilities for Jazelle emulation are not implemented.
  3608. //
  3609. // According to the ARM documentation on BXJ, if setting the J bit in the APSR
  3610. // fails, then BXJ functions identically like a regular BX instruction.
  3611. //
  3612. // This is sufficient for citra, as the CPU for the 3DS does not implement Jazelle.
  3613. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  3614. bx_inst* const inst_cream = (bx_inst*)inst_base->component;
  3615. if (inst_cream->Rm == 15)
  3616. LOG_WARNING(Core_ARM11, "BX at pc %x: use of Rm = R15 is discouraged", cpu->Reg[15]);
  3617. cpu->TFlag = cpu->Reg[inst_cream->Rm] & 0x1;
  3618. cpu->Reg[15] = cpu->Reg[inst_cream->Rm] & 0xfffffffe;
  3619. INC_PC(sizeof(bx_inst));
  3620. goto DISPATCH;
  3621. }
  3622. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3623. INC_PC(sizeof(bx_inst));
  3624. goto DISPATCH;
  3625. }
  3626. CDP_INST:
  3627. {
  3628. cdp_inst *inst_cream = (cdp_inst *)inst_base->component;
  3629. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3630. // Undefined instruction here
  3631. cpu->NumInstrsToExecute = 0;
  3632. return num_instrs;
  3633. }
  3634. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3635. INC_PC(sizeof(cdp_inst));
  3636. FETCH_INST;
  3637. GOTO_NEXT_INST;
  3638. }
  3639. CLREX_INST:
  3640. {
  3641. remove_exclusive(cpu, 0);
  3642. cpu->exclusive_state = 0;
  3643. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3644. INC_PC(sizeof(clrex_inst));
  3645. FETCH_INST;
  3646. GOTO_NEXT_INST;
  3647. }
  3648. CLZ_INST:
  3649. {
  3650. clz_inst *inst_cream = (clz_inst *)inst_base->component;
  3651. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3652. RD = clz(RM);
  3653. }
  3654. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3655. INC_PC(sizeof(clz_inst));
  3656. FETCH_INST;
  3657. GOTO_NEXT_INST;
  3658. }
  3659. CMN_INST:
  3660. {
  3661. cmn_inst *inst_cream = (cmn_inst *)inst_base->component;
  3662. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3663. lop = RN;
  3664. rop = SHIFTER_OPERAND;
  3665. dst = lop + rop;
  3666. UPDATE_NFLAG(dst);
  3667. UPDATE_ZFLAG(dst);
  3668. UPDATE_CFLAG(dst, lop, rop);
  3669. UPDATE_VFLAG((int)dst, (int)lop, (int)rop);
  3670. }
  3671. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3672. INC_PC(sizeof(cmn_inst));
  3673. FETCH_INST;
  3674. GOTO_NEXT_INST;
  3675. }
  3676. CMP_INST:
  3677. {
  3678. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3679. cmp_inst *inst_cream = (cmp_inst *)inst_base->component;
  3680. lop = RN;
  3681. if (inst_cream->Rn == 15) {
  3682. lop += 2 * GET_INST_SIZE(cpu);
  3683. }
  3684. rop = SHIFTER_OPERAND;
  3685. dst = lop - rop;
  3686. UPDATE_NFLAG(dst);
  3687. UPDATE_ZFLAG(dst);
  3688. UPDATE_CFLAG_NOT_BORROW_FROM(lop, rop);
  3689. UPDATE_VFLAG_OVERFLOW_FROM(dst, lop, rop);
  3690. }
  3691. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3692. INC_PC(sizeof(cmp_inst));
  3693. FETCH_INST;
  3694. GOTO_NEXT_INST;
  3695. }
  3696. CPS_INST:
  3697. {
  3698. cps_inst *inst_cream = (cps_inst *)inst_base->component;
  3699. uint32_t aif_val = 0;
  3700. uint32_t aif_mask = 0;
  3701. if (InAPrivilegedMode(cpu)) {
  3702. if (inst_cream->imod1) {
  3703. if (inst_cream->A) {
  3704. aif_val |= (inst_cream->imod0 << 8);
  3705. aif_mask |= 1 << 8;
  3706. }
  3707. if (inst_cream->I) {
  3708. aif_val |= (inst_cream->imod0 << 7);
  3709. aif_mask |= 1 << 7;
  3710. }
  3711. if (inst_cream->F) {
  3712. aif_val |= (inst_cream->imod0 << 6);
  3713. aif_mask |= 1 << 6;
  3714. }
  3715. aif_mask = ~aif_mask;
  3716. cpu->Cpsr = (cpu->Cpsr & aif_mask) | aif_val;
  3717. }
  3718. if (inst_cream->mmod) {
  3719. cpu->Cpsr = (cpu->Cpsr & 0xffffffe0) | inst_cream->mode;
  3720. switch_mode(cpu, inst_cream->mode);
  3721. }
  3722. }
  3723. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3724. INC_PC(sizeof(cps_inst));
  3725. FETCH_INST;
  3726. GOTO_NEXT_INST;
  3727. }
  3728. CPY_INST:
  3729. {
  3730. mov_inst *inst_cream = (mov_inst *)inst_base->component;
  3731. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3732. RD = SHIFTER_OPERAND;
  3733. if ((inst_cream->Rd == 15)) {
  3734. INC_PC(sizeof(mov_inst));
  3735. goto DISPATCH;
  3736. }
  3737. }
  3738. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3739. INC_PC(sizeof(mov_inst));
  3740. FETCH_INST;
  3741. GOTO_NEXT_INST;
  3742. }
  3743. EOR_INST:
  3744. {
  3745. eor_inst *inst_cream = (eor_inst *)inst_base->component;
  3746. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3747. lop = RN;
  3748. if (inst_cream->Rn == 15) {
  3749. lop += 2 * GET_INST_SIZE(cpu);
  3750. }
  3751. rop = SHIFTER_OPERAND;
  3752. RD = dst = lop ^ rop;
  3753. if (inst_cream->S && (inst_cream->Rd == 15)) {
  3754. if (CurrentModeHasSPSR) {
  3755. cpu->Cpsr = cpu->Spsr_copy;
  3756. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  3757. LOAD_NZCVT;
  3758. }
  3759. } else if (inst_cream->S) {
  3760. UPDATE_NFLAG(dst);
  3761. UPDATE_ZFLAG(dst);
  3762. UPDATE_CFLAG_WITH_SC;
  3763. }
  3764. if (inst_cream->Rd == 15) {
  3765. INC_PC(sizeof(eor_inst));
  3766. goto DISPATCH;
  3767. }
  3768. }
  3769. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3770. INC_PC(sizeof(eor_inst));
  3771. FETCH_INST;
  3772. GOTO_NEXT_INST;
  3773. }
  3774. LDC_INST:
  3775. {
  3776. // Instruction not implemented
  3777. //LOG_CRITICAL(Core_ARM11, "unimplemented instruction");
  3778. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3779. INC_PC(sizeof(ldc_inst));
  3780. FETCH_INST;
  3781. GOTO_NEXT_INST;
  3782. }
  3783. LDM_INST:
  3784. {
  3785. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  3786. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3787. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  3788. unsigned int inst = inst_cream->inst;
  3789. if (BIT(inst, 22) && !BIT(inst, 15)) {
  3790. for (int i = 0; i < 13; i++) {
  3791. if(BIT(inst, i)) {
  3792. cpu->Reg[i] = Memory::Read32(addr);
  3793. addr += 4;
  3794. }
  3795. }
  3796. if (BIT(inst, 13)) {
  3797. if (cpu->Mode == USER32MODE)
  3798. cpu->Reg[13] = Memory::Read32(addr);
  3799. else
  3800. cpu->Reg_usr[0] = Memory::Read32(addr);
  3801. addr += 4;
  3802. }
  3803. if (BIT(inst, 14)) {
  3804. if (cpu->Mode == USER32MODE)
  3805. cpu->Reg[14] = Memory::Read32(addr);
  3806. else
  3807. cpu->Reg_usr[1] = Memory::Read32(addr);
  3808. }
  3809. } else if (!BIT(inst, 22)) {
  3810. for(int i = 0; i < 16; i++ ){
  3811. if(BIT(inst, i)){
  3812. unsigned int ret = Memory::Read32(addr);
  3813. // For armv5t, should enter thumb when bits[0] is non-zero.
  3814. if(i == 15){
  3815. cpu->TFlag = ret & 0x1;
  3816. ret &= 0xFFFFFFFE;
  3817. }
  3818. cpu->Reg[i] = ret;
  3819. addr += 4;
  3820. }
  3821. }
  3822. } else if (BIT(inst, 22) && BIT(inst, 15)) {
  3823. for(int i = 0; i < 15; i++ ){
  3824. if(BIT(inst, i)){
  3825. cpu->Reg[i] = Memory::Read32(addr);
  3826. addr += 4;
  3827. }
  3828. }
  3829. if (CurrentModeHasSPSR) {
  3830. cpu->Cpsr = cpu->Spsr_copy;
  3831. switch_mode(cpu, cpu->Cpsr & 0x1f);
  3832. LOAD_NZCVT;
  3833. }
  3834. cpu->Reg[15] = Memory::Read32(addr);
  3835. }
  3836. if (BIT(inst, 15)) {
  3837. INC_PC(sizeof(ldst_inst));
  3838. goto DISPATCH;
  3839. }
  3840. }
  3841. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3842. INC_PC(sizeof(ldst_inst));
  3843. FETCH_INST;
  3844. GOTO_NEXT_INST;
  3845. }
  3846. SXTH_INST:
  3847. {
  3848. sxth_inst *inst_cream = (sxth_inst *)inst_base->component;
  3849. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3850. unsigned int operand2 = ROTATE_RIGHT_32(RM, 8 * inst_cream->rotate);
  3851. if (BIT(operand2, 15)) {
  3852. operand2 |= 0xffff0000;
  3853. } else {
  3854. operand2 &= 0xffff;
  3855. }
  3856. RD = operand2;
  3857. }
  3858. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3859. INC_PC(sizeof(sxth_inst));
  3860. FETCH_INST;
  3861. GOTO_NEXT_INST;
  3862. }
  3863. LDR_INST:
  3864. {
  3865. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  3866. //if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3867. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  3868. unsigned int value = Memory::Read32(addr);
  3869. if (BIT(CP15_REG(CP15_CONTROL), 22) == 1)
  3870. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = value;
  3871. else {
  3872. value = ROTATE_RIGHT_32(value,(8*(addr&0x3)));
  3873. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = value;
  3874. }
  3875. if (BITS(inst_cream->inst, 12, 15) == 15) {
  3876. // For armv5t, should enter thumb when bits[0] is non-zero.
  3877. cpu->TFlag = value & 0x1;
  3878. cpu->Reg[15] &= 0xFFFFFFFE;
  3879. INC_PC(sizeof(ldst_inst));
  3880. goto DISPATCH;
  3881. }
  3882. //}
  3883. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3884. INC_PC(sizeof(ldst_inst));
  3885. FETCH_INST;
  3886. GOTO_NEXT_INST;
  3887. }
  3888. LDRCOND_INST:
  3889. {
  3890. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  3891. if (CondPassed(cpu, inst_base->cond)) {
  3892. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  3893. unsigned int value = Memory::Read32(addr);
  3894. if (BIT(CP15_REG(CP15_CONTROL), 22) == 1)
  3895. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = value;
  3896. else {
  3897. value = ROTATE_RIGHT_32(value,(8*(addr&0x3)));
  3898. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = value;
  3899. }
  3900. if (BITS(inst_cream->inst, 12, 15) == 15) {
  3901. // For armv5t, should enter thumb when bits[0] is non-zero.
  3902. cpu->TFlag = value & 0x1;
  3903. cpu->Reg[15] &= 0xFFFFFFFE;
  3904. INC_PC(sizeof(ldst_inst));
  3905. goto DISPATCH;
  3906. }
  3907. }
  3908. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3909. INC_PC(sizeof(ldst_inst));
  3910. FETCH_INST;
  3911. GOTO_NEXT_INST;
  3912. }
  3913. UXTH_INST:
  3914. {
  3915. uxth_inst *inst_cream = (uxth_inst *)inst_base->component;
  3916. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3917. unsigned int operand2 = ROTATE_RIGHT_32(RM, 8 * inst_cream->rotate)
  3918. & 0xffff;
  3919. RD = operand2;
  3920. }
  3921. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3922. INC_PC(sizeof(uxth_inst));
  3923. FETCH_INST;
  3924. GOTO_NEXT_INST;
  3925. }
  3926. UXTAH_INST:
  3927. {
  3928. uxtah_inst *inst_cream = (uxtah_inst *)inst_base->component;
  3929. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3930. unsigned int operand2 = ROTATE_RIGHT_32(RM, 8 * inst_cream->rotate)
  3931. & 0xffff;
  3932. RD = RN + operand2;
  3933. if (inst_cream->Rn == 15 || inst_cream->Rm == 15) {
  3934. LOG_ERROR(Core_ARM11, "invalid operands for UXTAH");
  3935. CITRA_IGNORE_EXIT(-1);
  3936. }
  3937. }
  3938. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3939. INC_PC(sizeof(uxtah_inst));
  3940. FETCH_INST;
  3941. GOTO_NEXT_INST;
  3942. }
  3943. LDRB_INST:
  3944. {
  3945. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  3946. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3947. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  3948. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = Memory::Read8(addr);
  3949. if (BITS(inst_cream->inst, 12, 15) == 15) {
  3950. INC_PC(sizeof(ldst_inst));
  3951. goto DISPATCH;
  3952. }
  3953. }
  3954. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3955. INC_PC(sizeof(ldst_inst));
  3956. FETCH_INST;
  3957. GOTO_NEXT_INST;
  3958. }
  3959. LDRBT_INST:
  3960. {
  3961. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  3962. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3963. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  3964. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = Memory::Read8(addr);
  3965. if (BITS(inst_cream->inst, 12, 15) == 15) {
  3966. INC_PC(sizeof(ldst_inst));
  3967. goto DISPATCH;
  3968. }
  3969. }
  3970. cpu->Reg[15] += GET_INST_SIZE(cpu);
  3971. INC_PC(sizeof(ldst_inst));
  3972. FETCH_INST;
  3973. GOTO_NEXT_INST;
  3974. }
  3975. LDRD_INST:
  3976. {
  3977. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  3978. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3979. // Should check if RD is even-numbered, Rd != 14, addr[0:1] == 0, (CP15_reg1_U == 1 || addr[2] == 0)
  3980. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  3981. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = Memory::Read32(addr);
  3982. cpu->Reg[BITS(inst_cream->inst, 12, 15) + 1] = Memory::Read32(addr + 4);
  3983. // No dispatch since this operation should not modify R15
  3984. }
  3985. cpu->Reg[15] += 4;
  3986. INC_PC(sizeof(ldst_inst));
  3987. FETCH_INST;
  3988. GOTO_NEXT_INST;
  3989. }
  3990. LDREX_INST:
  3991. {
  3992. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  3993. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  3994. unsigned int read_addr = RN;
  3995. add_exclusive_addr(cpu, read_addr);
  3996. cpu->exclusive_state = 1;
  3997. RD = Memory::Read32(read_addr);
  3998. if (inst_cream->Rd == 15) {
  3999. INC_PC(sizeof(generic_arm_inst));
  4000. goto DISPATCH;
  4001. }
  4002. }
  4003. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4004. INC_PC(sizeof(generic_arm_inst));
  4005. FETCH_INST;
  4006. GOTO_NEXT_INST;
  4007. }
  4008. LDREXB_INST:
  4009. {
  4010. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  4011. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4012. unsigned int read_addr = RN;
  4013. add_exclusive_addr(cpu, read_addr);
  4014. cpu->exclusive_state = 1;
  4015. RD = Memory::Read8(read_addr);
  4016. if (inst_cream->Rd == 15) {
  4017. INC_PC(sizeof(generic_arm_inst));
  4018. goto DISPATCH;
  4019. }
  4020. }
  4021. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4022. INC_PC(sizeof(generic_arm_inst));
  4023. FETCH_INST;
  4024. GOTO_NEXT_INST;
  4025. }
  4026. LDREXH_INST:
  4027. {
  4028. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  4029. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4030. unsigned int read_addr = RN;
  4031. add_exclusive_addr(cpu, read_addr);
  4032. cpu->exclusive_state = 1;
  4033. RD = Memory::Read16(read_addr);
  4034. if (inst_cream->Rd == 15) {
  4035. INC_PC(sizeof(generic_arm_inst));
  4036. goto DISPATCH;
  4037. }
  4038. }
  4039. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4040. INC_PC(sizeof(generic_arm_inst));
  4041. FETCH_INST;
  4042. GOTO_NEXT_INST;
  4043. }
  4044. LDREXD_INST:
  4045. {
  4046. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  4047. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4048. unsigned int read_addr = RN;
  4049. add_exclusive_addr(cpu, read_addr);
  4050. cpu->exclusive_state = 1;
  4051. RD = Memory::Read32(read_addr);
  4052. RD2 = Memory::Read32(read_addr + 4);
  4053. if (inst_cream->Rd == 15) {
  4054. INC_PC(sizeof(generic_arm_inst));
  4055. goto DISPATCH;
  4056. }
  4057. }
  4058. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4059. INC_PC(sizeof(generic_arm_inst));
  4060. FETCH_INST;
  4061. GOTO_NEXT_INST;
  4062. }
  4063. LDRH_INST:
  4064. {
  4065. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  4066. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4067. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  4068. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = Memory::Read16(addr);
  4069. if (BITS(inst_cream->inst, 12, 15) == 15) {
  4070. INC_PC(sizeof(ldst_inst));
  4071. goto DISPATCH;
  4072. }
  4073. }
  4074. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4075. INC_PC(sizeof(ldst_inst));
  4076. FETCH_INST;
  4077. GOTO_NEXT_INST;
  4078. }
  4079. LDRSB_INST:
  4080. {
  4081. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  4082. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4083. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  4084. unsigned int value = Memory::Read8(addr);
  4085. if (BIT(value, 7)) {
  4086. value |= 0xffffff00;
  4087. }
  4088. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = value;
  4089. if (BITS(inst_cream->inst, 12, 15) == 15) {
  4090. INC_PC(sizeof(ldst_inst));
  4091. goto DISPATCH;
  4092. }
  4093. }
  4094. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4095. INC_PC(sizeof(ldst_inst));
  4096. FETCH_INST;
  4097. GOTO_NEXT_INST;
  4098. }
  4099. LDRSH_INST:
  4100. {
  4101. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  4102. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4103. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  4104. unsigned int value = Memory::Read16(addr);
  4105. if (BIT(value, 15)) {
  4106. value |= 0xffff0000;
  4107. }
  4108. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = value;
  4109. if (BITS(inst_cream->inst, 12, 15) == 15) {
  4110. INC_PC(sizeof(ldst_inst));
  4111. goto DISPATCH;
  4112. }
  4113. }
  4114. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4115. INC_PC(sizeof(ldst_inst));
  4116. FETCH_INST;
  4117. GOTO_NEXT_INST;
  4118. }
  4119. LDRT_INST:
  4120. {
  4121. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  4122. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4123. inst_cream->get_addr(cpu, inst_cream->inst, addr, 1);
  4124. unsigned int value = Memory::Read32(addr);
  4125. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = value;
  4126. if (BIT(CP15_REG(CP15_CONTROL), 22) == 1)
  4127. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = value;
  4128. else
  4129. cpu->Reg[BITS(inst_cream->inst, 12, 15)] = ROTATE_RIGHT_32(value,(8*(addr&0x3))) ;
  4130. if (BITS(inst_cream->inst, 12, 15) == 15) {
  4131. INC_PC(sizeof(ldst_inst));
  4132. goto DISPATCH;
  4133. }
  4134. }
  4135. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4136. INC_PC(sizeof(ldst_inst));
  4137. FETCH_INST;
  4138. GOTO_NEXT_INST;
  4139. }
  4140. MCR_INST:
  4141. {
  4142. mcr_inst *inst_cream = (mcr_inst *)inst_base->component;
  4143. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4144. unsigned int inst = inst_cream->inst;
  4145. if (inst_cream->Rd == 15) {
  4146. DEBUG_MSG;
  4147. } else {
  4148. if (inst_cream->cp_num == 15) {
  4149. if(CRn == 0 && OPCODE_2 == 0 && CRm == 0) {
  4150. CP15_REG(CP15_MAIN_ID) = RD;
  4151. } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 1) {
  4152. CP15_REG(CP15_AUXILIARY_CONTROL) = RD;
  4153. } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 2) {
  4154. CP15_REG(CP15_COPROCESSOR_ACCESS_CONTROL) = RD;
  4155. } else if(CRn == 1 && CRm == 0 && OPCODE_2 == 0) {
  4156. CP15_REG(CP15_CONTROL) = RD;
  4157. } else if (CRn == 3 && CRm == 0 && OPCODE_2 == 0) {
  4158. CP15_REG(CP15_DOMAIN_ACCESS_CONTROL) = RD;
  4159. } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 0) {
  4160. CP15_REG(CP15_TRANSLATION_BASE_TABLE_0) = RD;
  4161. } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 1) {
  4162. CP15_REG(CP15_TRANSLATION_BASE_TABLE_1) = RD;
  4163. } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 2) {
  4164. CP15_REG(CP15_TRANSLATION_BASE_CONTROL) = RD;
  4165. } else if(CRn == MMU_CACHE_OPS){
  4166. //LOG_WARNING(Core_ARM11, "cache operations have not implemented.");
  4167. } else if(CRn == MMU_TLB_OPS){
  4168. switch (CRm) {
  4169. case 5: // ITLB
  4170. switch(OPCODE_2) {
  4171. case 0: // Invalidate all
  4172. LOG_DEBUG(Core_ARM11, "{TLB} [INSN] invalidate all");
  4173. break;
  4174. case 1: // Invalidate by MVA
  4175. LOG_DEBUG(Core_ARM11, "{TLB} [INSN] invalidate by mva");
  4176. break;
  4177. case 2: // Invalidate by asid
  4178. LOG_DEBUG(Core_ARM11, "{TLB} [INSN] invalidate by asid");
  4179. break;
  4180. default:
  4181. break;
  4182. }
  4183. break;
  4184. case 6: // DTLB
  4185. switch(OPCODE_2){
  4186. case 0: // Invalidate all
  4187. LOG_DEBUG(Core_ARM11, "{TLB} [DATA] invalidate all");
  4188. break;
  4189. case 1: // Invalidate by MVA
  4190. LOG_DEBUG(Core_ARM11, "{TLB} [DATA] invalidate by mva");
  4191. break;
  4192. case 2: // Invalidate by asid
  4193. LOG_DEBUG(Core_ARM11, "{TLB} [DATA] invalidate by asid");
  4194. break;
  4195. default:
  4196. break;
  4197. }
  4198. break;
  4199. case 7: // UNIFILED TLB
  4200. switch(OPCODE_2){
  4201. case 0: // invalidate all
  4202. LOG_DEBUG(Core_ARM11, "{TLB} [UNIFILED] invalidate all");
  4203. break;
  4204. case 1: // Invalidate by MVA
  4205. LOG_DEBUG(Core_ARM11, "{TLB} [UNIFILED] invalidate by mva");
  4206. break;
  4207. case 2: // Invalidate by asid
  4208. LOG_DEBUG(Core_ARM11, "{TLB} [UNIFILED] invalidate by asid");
  4209. break;
  4210. default:
  4211. break;
  4212. }
  4213. break;
  4214. default:
  4215. break;
  4216. }
  4217. } else if(CRn == MMU_PID) {
  4218. if(OPCODE_2 == 0)
  4219. CP15_REG(CP15_PID) = RD;
  4220. else if(OPCODE_2 == 1)
  4221. CP15_REG(CP15_CONTEXT_ID) = RD;
  4222. else if(OPCODE_2 == 3) {
  4223. CP15_REG(CP15_THREAD_URO) = RD;
  4224. } else {
  4225. LOG_ERROR(Core_ARM11, "mmu_mcr wrote UNKNOWN - reg %d", CRn);
  4226. }
  4227. } else {
  4228. LOG_ERROR(Core_ARM11, "mcr CRn=%d, CRm=%d OP2=%d is not implemented", CRn, CRm, OPCODE_2);
  4229. }
  4230. }
  4231. }
  4232. }
  4233. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4234. INC_PC(sizeof(mcr_inst));
  4235. FETCH_INST;
  4236. GOTO_NEXT_INST;
  4237. }
  4238. MCRR_INST:
  4239. MLA_INST:
  4240. {
  4241. mla_inst *inst_cream = (mla_inst *)inst_base->component;
  4242. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4243. uint64_t rm = RM;
  4244. uint64_t rs = RS;
  4245. uint64_t rn = RN;
  4246. if (inst_cream->Rm == 15 || inst_cream->Rs == 15 || inst_cream->Rn == 15) {
  4247. LOG_ERROR(Core_ARM11, "invalid operands for MLA");
  4248. CITRA_IGNORE_EXIT(-1);
  4249. }
  4250. RD = dst = static_cast<uint32_t>((rm * rs + rn) & 0xffffffff);
  4251. if (inst_cream->S) {
  4252. UPDATE_NFLAG(dst);
  4253. UPDATE_ZFLAG(dst);
  4254. }
  4255. if (inst_cream->Rd == 15) {
  4256. INC_PC(sizeof(mla_inst));
  4257. goto DISPATCH;
  4258. }
  4259. }
  4260. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4261. INC_PC(sizeof(mla_inst));
  4262. FETCH_INST;
  4263. GOTO_NEXT_INST;
  4264. }
  4265. MOV_INST:
  4266. {
  4267. mov_inst *inst_cream = (mov_inst *)inst_base->component;
  4268. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4269. RD = dst = SHIFTER_OPERAND;
  4270. if (inst_cream->S && (inst_cream->Rd == 15)) {
  4271. if (CurrentModeHasSPSR) {
  4272. cpu->Cpsr = cpu->Spsr_copy;
  4273. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  4274. LOAD_NZCVT;
  4275. }
  4276. } else if (inst_cream->S) {
  4277. UPDATE_NFLAG(dst);
  4278. UPDATE_ZFLAG(dst);
  4279. UPDATE_CFLAG_WITH_SC;
  4280. }
  4281. if (inst_cream->Rd == 15) {
  4282. INC_PC(sizeof(mov_inst));
  4283. goto DISPATCH;
  4284. }
  4285. }
  4286. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4287. INC_PC(sizeof(mov_inst));
  4288. FETCH_INST;
  4289. GOTO_NEXT_INST;
  4290. }
  4291. MRC_INST:
  4292. {
  4293. mrc_inst *inst_cream = (mrc_inst *)inst_base->component;
  4294. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4295. unsigned int inst = inst_cream->inst;
  4296. if (inst_cream->Rd == 15) {
  4297. DEBUG_MSG;
  4298. }
  4299. if (inst_cream->inst == 0xeef04a10) {
  4300. // Undefined instruction fmrx
  4301. RD = 0x20000000;
  4302. CITRA_IGNORE_EXIT(-1);
  4303. goto END;
  4304. } else {
  4305. if (inst_cream->cp_num == 15) {
  4306. if(CRn == 0 && OPCODE_2 == 0 && CRm == 0) {
  4307. RD = cpu->CP15[CP15(CP15_MAIN_ID)];
  4308. } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 0) {
  4309. RD = cpu->CP15[CP15(CP15_CONTROL)];
  4310. } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 1) {
  4311. RD = cpu->CP15[CP15(CP15_AUXILIARY_CONTROL)];
  4312. } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 2) {
  4313. RD = cpu->CP15[CP15(CP15_COPROCESSOR_ACCESS_CONTROL)];
  4314. } else if (CRn == 3 && CRm == 0 && OPCODE_2 == 0) {
  4315. RD = cpu->CP15[CP15(CP15_DOMAIN_ACCESS_CONTROL)];
  4316. } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 0) {
  4317. RD = cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_0)];
  4318. } else if (CRn == 5 && CRm == 0 && OPCODE_2 == 0) {
  4319. RD = cpu->CP15[CP15(CP15_FAULT_STATUS)];
  4320. } else if (CRn == 6 && CRm == 0 && OPCODE_2 == 0) {
  4321. RD = cpu->CP15[CP15(CP15_FAULT_ADDRESS)];
  4322. } else if (CRn == 0 && CRm == 0 && OPCODE_2 == 1) {
  4323. RD = cpu->CP15[CP15(CP15_CACHE_TYPE)];
  4324. } else if (CRn == 5 && CRm == 0 && OPCODE_2 == 1) {
  4325. RD = cpu->CP15[CP15(CP15_INSTR_FAULT_STATUS)];
  4326. } else if (CRn == 13) {
  4327. if(OPCODE_2 == 0)
  4328. RD = CP15_REG(CP15_PID);
  4329. else if(OPCODE_2 == 1)
  4330. RD = CP15_REG(CP15_CONTEXT_ID);
  4331. else if(OPCODE_2 == 3) {
  4332. RD = Memory::KERNEL_MEMORY_VADDR;
  4333. } else {
  4334. LOG_ERROR(Core_ARM11, "mmu_mrr wrote UNKNOWN - reg %d", CRn);
  4335. }
  4336. } else {
  4337. LOG_ERROR(Core_ARM11, "mrc CRn=%d, CRm=%d, OP2=%d is not implemented", CRn, CRm, OPCODE_2);
  4338. }
  4339. }
  4340. }
  4341. }
  4342. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4343. INC_PC(sizeof(mrc_inst));
  4344. FETCH_INST;
  4345. GOTO_NEXT_INST;
  4346. }
  4347. MRRC_INST:
  4348. MRS_INST:
  4349. {
  4350. mrs_inst *inst_cream = (mrs_inst *)inst_base->component;
  4351. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4352. if (inst_cream->R) {
  4353. RD = cpu->Spsr_copy;
  4354. } else {
  4355. SAVE_NZCVT;
  4356. RD = cpu->Cpsr;
  4357. }
  4358. }
  4359. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4360. INC_PC(sizeof(mrs_inst));
  4361. FETCH_INST;
  4362. GOTO_NEXT_INST;
  4363. }
  4364. MSR_INST:
  4365. {
  4366. msr_inst *inst_cream = (msr_inst *)inst_base->component;
  4367. const uint32_t UnallocMask = 0x06f0fc00, UserMask = 0xf80f0200, PrivMask = 0x000001df, StateMask = 0x01000020;
  4368. unsigned int inst = inst_cream->inst;
  4369. unsigned int operand;
  4370. if (BIT(inst, 25)) {
  4371. int rot_imm = BITS(inst, 8, 11) * 2;
  4372. operand = ROTATE_RIGHT_32(BITS(inst, 0, 7), rot_imm);
  4373. } else {
  4374. operand = cpu->Reg[BITS(inst, 0, 3)];
  4375. }
  4376. uint32_t byte_mask = (BIT(inst, 16) ? 0xff : 0) | (BIT(inst, 17) ? 0xff00 : 0)
  4377. | (BIT(inst, 18) ? 0xff0000 : 0) | (BIT(inst, 19) ? 0xff000000 : 0);
  4378. uint32_t mask;
  4379. if (!inst_cream->R) {
  4380. if (InAPrivilegedMode(cpu)) {
  4381. if ((operand & StateMask) != 0) {
  4382. /// UNPREDICTABLE
  4383. DEBUG_MSG;
  4384. } else
  4385. mask = byte_mask & (UserMask | PrivMask);
  4386. } else {
  4387. mask = byte_mask & UserMask;
  4388. }
  4389. SAVE_NZCVT;
  4390. cpu->Cpsr = (cpu->Cpsr & ~mask) | (operand & mask);
  4391. switch_mode(cpu, cpu->Cpsr & 0x1f);
  4392. LOAD_NZCVT;
  4393. } else {
  4394. if (CurrentModeHasSPSR) {
  4395. mask = byte_mask & (UserMask | PrivMask | StateMask);
  4396. cpu->Spsr_copy = (cpu->Spsr_copy & ~mask) | (operand & mask);
  4397. }
  4398. }
  4399. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4400. INC_PC(sizeof(msr_inst));
  4401. FETCH_INST;
  4402. GOTO_NEXT_INST;
  4403. }
  4404. MUL_INST:
  4405. {
  4406. mul_inst *inst_cream = (mul_inst *)inst_base->component;
  4407. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4408. uint64_t rm = RM;
  4409. uint64_t rs = RS;
  4410. RD = dst = static_cast<uint32_t>((rm * rs) & 0xffffffff);
  4411. if (inst_cream->S) {
  4412. UPDATE_NFLAG(dst);
  4413. UPDATE_ZFLAG(dst);
  4414. }
  4415. if (inst_cream->Rd == 15) {
  4416. INC_PC(sizeof(mul_inst));
  4417. goto DISPATCH;
  4418. }
  4419. }
  4420. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4421. INC_PC(sizeof(mul_inst));
  4422. FETCH_INST;
  4423. GOTO_NEXT_INST;
  4424. }
  4425. MVN_INST:
  4426. {
  4427. mvn_inst *inst_cream = (mvn_inst *)inst_base->component;
  4428. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4429. RD = dst = ~SHIFTER_OPERAND;
  4430. if (inst_cream->S && (inst_cream->Rd == 15)) {
  4431. if (CurrentModeHasSPSR) {
  4432. cpu->Cpsr = cpu->Spsr_copy;
  4433. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  4434. LOAD_NZCVT;
  4435. }
  4436. } else if (inst_cream->S) {
  4437. UPDATE_NFLAG(dst);
  4438. UPDATE_ZFLAG(dst);
  4439. UPDATE_CFLAG_WITH_SC;
  4440. }
  4441. if (inst_cream->Rd == 15) {
  4442. INC_PC(sizeof(mvn_inst));
  4443. goto DISPATCH;
  4444. }
  4445. }
  4446. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4447. INC_PC(sizeof(mvn_inst));
  4448. FETCH_INST;
  4449. GOTO_NEXT_INST;
  4450. }
  4451. ORR_INST:
  4452. {
  4453. orr_inst *inst_cream = (orr_inst *)inst_base->component;
  4454. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4455. lop = RN;
  4456. rop = SHIFTER_OPERAND;
  4457. RD = dst = lop | rop;
  4458. if (inst_cream->S && (inst_cream->Rd == 15)) {
  4459. if (CurrentModeHasSPSR) {
  4460. cpu->Cpsr = cpu->Spsr_copy;
  4461. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  4462. LOAD_NZCVT;
  4463. }
  4464. } else if (inst_cream->S) {
  4465. UPDATE_NFLAG(dst);
  4466. UPDATE_ZFLAG(dst);
  4467. UPDATE_CFLAG_WITH_SC;
  4468. }
  4469. if (inst_cream->Rd == 15) {
  4470. INC_PC(sizeof(orr_inst));
  4471. goto DISPATCH;
  4472. }
  4473. }
  4474. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4475. INC_PC(sizeof(orr_inst));
  4476. FETCH_INST;
  4477. GOTO_NEXT_INST;
  4478. }
  4479. PKHBT_INST:
  4480. {
  4481. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4482. pkh_inst *inst_cream = (pkh_inst *)inst_base->component;
  4483. RD = (RN & 0xFFFF) | ((RM << inst_cream->imm) & 0xFFFF0000);
  4484. }
  4485. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4486. INC_PC(sizeof(pkh_inst));
  4487. FETCH_INST;
  4488. GOTO_NEXT_INST;
  4489. }
  4490. PKHTB_INST:
  4491. {
  4492. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4493. pkh_inst *inst_cream = (pkh_inst *)inst_base->component;
  4494. int shift_imm = inst_cream->imm ? inst_cream->imm : 31;
  4495. RD = ((static_cast<s32>(RM) >> shift_imm) & 0xFFFF) | (RN & 0xFFFF0000);
  4496. }
  4497. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4498. INC_PC(sizeof(pkh_inst));
  4499. FETCH_INST;
  4500. GOTO_NEXT_INST;
  4501. }
  4502. PLD_INST:
  4503. {
  4504. // Instruction not implemented
  4505. //LOG_CRITICAL(Core_ARM11, "unimplemented instruction");
  4506. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4507. INC_PC(sizeof(stc_inst));
  4508. FETCH_INST;
  4509. GOTO_NEXT_INST;
  4510. }
  4511. QADD_INST:
  4512. QDADD_INST:
  4513. QDSUB_INST:
  4514. QSUB_INST:
  4515. {
  4516. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4517. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  4518. const u8 op1 = inst_cream->op1;
  4519. const u32 rm_val = RM;
  4520. const u32 rn_val = RN;
  4521. u32 result = 0;
  4522. // QADD
  4523. if (op1 == 0x00) {
  4524. result = rm_val + rn_val;
  4525. if (AddOverflow(rm_val, rn_val, result)) {
  4526. result = POS(result) ? 0x80000000 : 0x7FFFFFFF;
  4527. cpu->Cpsr |= (1 << 27);
  4528. }
  4529. }
  4530. // QSUB
  4531. else if (op1 == 0x01) {
  4532. result = rm_val - rn_val;
  4533. if (SubOverflow(rm_val, rn_val, result)) {
  4534. result = POS(result) ? 0x80000000 : 0x7FFFFFFF;
  4535. cpu->Cpsr |= (1 << 27);
  4536. }
  4537. }
  4538. // QDADD
  4539. else if (op1 == 0x02) {
  4540. u32 mul = (rn_val * 2);
  4541. if (AddOverflow(rn_val, rn_val, rn_val * 2)) {
  4542. mul = POS(mul) ? 0x80000000 : 0x7FFFFFFF;
  4543. cpu->Cpsr |= (1 << 27);
  4544. }
  4545. result = mul + rm_val;
  4546. if (AddOverflow(rm_val, mul, result)) {
  4547. result = POS(result) ? 0x80000000 : 0x7FFFFFFF;
  4548. cpu->Cpsr |= (1 << 27);
  4549. }
  4550. }
  4551. // QDSUB
  4552. else if (op1 == 0x03) {
  4553. u32 mul = (rn_val * 2);
  4554. if (AddOverflow(rn_val, rn_val, mul)) {
  4555. mul = POS(mul) ? 0x80000000 : 0x7FFFFFFF;
  4556. cpu->Cpsr |= (1 << 27);
  4557. }
  4558. result = rm_val - mul;
  4559. if (SubOverflow(rm_val, mul, result)) {
  4560. result = POS(result) ? 0x80000000 : 0x7FFFFFFF;
  4561. cpu->Cpsr |= (1 << 27);
  4562. }
  4563. }
  4564. RD = result;
  4565. }
  4566. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4567. INC_PC(sizeof(generic_arm_inst));
  4568. FETCH_INST;
  4569. GOTO_NEXT_INST;
  4570. }
  4571. QADD8_INST:
  4572. QADD16_INST:
  4573. QADDSUBX_INST:
  4574. QSUB8_INST:
  4575. QSUB16_INST:
  4576. QSUBADDX_INST:
  4577. {
  4578. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4579. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  4580. const u16 rm_lo = (RM & 0xFFFF);
  4581. const u16 rm_hi = ((RM >> 16) & 0xFFFF);
  4582. const u16 rn_lo = (RN & 0xFFFF);
  4583. const u16 rn_hi = ((RN >> 16) & 0xFFFF);
  4584. const u8 op2 = inst_cream->op2;
  4585. u16 lo_result = 0;
  4586. u16 hi_result = 0;
  4587. // QADD16
  4588. if (op2 == 0x00) {
  4589. lo_result = ARMul_SignedSaturatedAdd16(rn_lo, rm_lo);
  4590. hi_result = ARMul_SignedSaturatedAdd16(rn_hi, rm_hi);
  4591. }
  4592. // QASX
  4593. else if (op2 == 0x01) {
  4594. lo_result = ARMul_SignedSaturatedSub16(rn_lo, rm_hi);
  4595. hi_result = ARMul_SignedSaturatedAdd16(rn_hi, rm_lo);
  4596. }
  4597. // QSAX
  4598. else if (op2 == 0x02) {
  4599. lo_result = ARMul_SignedSaturatedAdd16(rn_lo, rm_hi);
  4600. hi_result = ARMul_SignedSaturatedSub16(rn_hi, rm_lo);
  4601. }
  4602. // QSUB16
  4603. else if (op2 == 0x03) {
  4604. lo_result = ARMul_SignedSaturatedSub16(rn_lo, rm_lo);
  4605. hi_result = ARMul_SignedSaturatedSub16(rn_hi, rm_hi);
  4606. }
  4607. // QADD8
  4608. else if (op2 == 0x04) {
  4609. lo_result = ARMul_SignedSaturatedAdd8(rn_lo & 0xFF, rm_lo & 0xFF) |
  4610. ARMul_SignedSaturatedAdd8(rn_lo >> 8, rm_lo >> 8) << 8;
  4611. hi_result = ARMul_SignedSaturatedAdd8(rn_hi & 0xFF, rm_hi & 0xFF) |
  4612. ARMul_SignedSaturatedAdd8(rn_hi >> 8, rm_hi >> 8) << 8;
  4613. }
  4614. // QSUB8
  4615. else if (op2 == 0x07) {
  4616. lo_result = ARMul_SignedSaturatedSub8(rn_lo & 0xFF, rm_lo & 0xFF) |
  4617. ARMul_SignedSaturatedSub8(rn_lo >> 8, rm_lo >> 8) << 8;
  4618. hi_result = ARMul_SignedSaturatedSub8(rn_hi & 0xFF, rm_hi & 0xFF) |
  4619. ARMul_SignedSaturatedSub8(rn_hi >> 8, rm_hi >> 8) << 8;
  4620. }
  4621. RD = (lo_result & 0xFFFF) | ((hi_result & 0xFFFF) << 16);
  4622. }
  4623. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4624. INC_PC(sizeof(generic_arm_inst));
  4625. FETCH_INST;
  4626. GOTO_NEXT_INST;
  4627. }
  4628. REV_INST:
  4629. REV16_INST:
  4630. REVSH_INST:
  4631. {
  4632. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4633. rev_inst* const inst_cream = (rev_inst*)inst_base->component;
  4634. const u8 op1 = inst_cream->op1;
  4635. const u8 op2 = inst_cream->op2;
  4636. // REV
  4637. if (op1 == 0x03 && op2 == 0x01) {
  4638. RD = ((RM & 0xFF) << 24) | (((RM >> 8) & 0xFF) << 16) | (((RM >> 16) & 0xFF) << 8) | ((RM >> 24) & 0xFF);
  4639. }
  4640. // REV16
  4641. else if (op1 == 0x03 && op2 == 0x05) {
  4642. RD = ((RM & 0xFF) << 8) | ((RM & 0xFF00) >> 8) | ((RM & 0xFF0000) << 8) | ((RM & 0xFF000000) >> 8);
  4643. }
  4644. // REVSH
  4645. else if (op1 == 0x07 && op2 == 0x05) {
  4646. RD = ((RM & 0xFF) << 8) | ((RM & 0xFF00) >> 8);
  4647. if (RD & 0x8000)
  4648. RD |= 0xffff0000;
  4649. }
  4650. }
  4651. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4652. INC_PC(sizeof(rev_inst));
  4653. FETCH_INST;
  4654. GOTO_NEXT_INST;
  4655. }
  4656. RFE_INST:
  4657. RSB_INST:
  4658. {
  4659. rsb_inst *inst_cream = (rsb_inst *)inst_base->component;
  4660. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4661. rop = RN;
  4662. lop = SHIFTER_OPERAND;
  4663. if (inst_cream->Rn == 15) {
  4664. rop += 2 * GET_INST_SIZE(cpu);;
  4665. }
  4666. RD = dst = lop - rop;
  4667. if (inst_cream->S && (inst_cream->Rd == 15)) {
  4668. if (CurrentModeHasSPSR) {
  4669. cpu->Cpsr = cpu->Spsr_copy;
  4670. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  4671. LOAD_NZCVT;
  4672. }
  4673. } else if (inst_cream->S) {
  4674. UPDATE_NFLAG(dst);
  4675. UPDATE_ZFLAG(dst);
  4676. UPDATE_CFLAG_NOT_BORROW_FROM(lop, rop);
  4677. UPDATE_VFLAG_OVERFLOW_FROM(dst, lop, rop);
  4678. }
  4679. if (inst_cream->Rd == 15) {
  4680. INC_PC(sizeof(rsb_inst));
  4681. goto DISPATCH;
  4682. }
  4683. }
  4684. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4685. INC_PC(sizeof(rsb_inst));
  4686. FETCH_INST;
  4687. GOTO_NEXT_INST;
  4688. }
  4689. RSC_INST:
  4690. {
  4691. rsc_inst *inst_cream = (rsc_inst *)inst_base->component;
  4692. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4693. lop = RN;
  4694. rop = SHIFTER_OPERAND;
  4695. RD = dst = rop - lop - !cpu->CFlag;
  4696. if (inst_cream->S && (inst_cream->Rd == 15)) {
  4697. if (CurrentModeHasSPSR) {
  4698. cpu->Cpsr = cpu->Spsr_copy;
  4699. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  4700. LOAD_NZCVT;
  4701. }
  4702. } else if (inst_cream->S) {
  4703. UPDATE_NFLAG(dst);
  4704. UPDATE_ZFLAG(dst);
  4705. UPDATE_CFLAG_NOT_BORROW_FROM_FLAG(rop, lop, !cpu->CFlag);
  4706. UPDATE_VFLAG_OVERFLOW_FROM((int)dst, (int)rop, (int)lop);
  4707. }
  4708. if (inst_cream->Rd == 15) {
  4709. INC_PC(sizeof(rsc_inst));
  4710. goto DISPATCH;
  4711. }
  4712. }
  4713. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4714. INC_PC(sizeof(rsc_inst));
  4715. FETCH_INST;
  4716. GOTO_NEXT_INST;
  4717. }
  4718. SADD8_INST:
  4719. SSUB8_INST:
  4720. SADD16_INST:
  4721. SADDSUBX_INST:
  4722. SSUBADDX_INST:
  4723. SSUB16_INST:
  4724. {
  4725. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4726. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  4727. const u8 op2 = inst_cream->op2;
  4728. if (op2 == 0x00 || op2 == 0x01 || op2 == 0x02 || op2 == 0x03) {
  4729. const s16 rn_lo = (RN & 0xFFFF);
  4730. const s16 rn_hi = ((RN >> 16) & 0xFFFF);
  4731. const s16 rm_lo = (RM & 0xFFFF);
  4732. const s16 rm_hi = ((RM >> 16) & 0xFFFF);
  4733. s32 lo_result = 0;
  4734. s32 hi_result = 0;
  4735. // SADD16
  4736. if (inst_cream->op2 == 0x00) {
  4737. lo_result = (rn_lo + rm_lo);
  4738. hi_result = (rn_hi + rm_hi);
  4739. }
  4740. // SASX
  4741. else if (op2 == 0x01) {
  4742. lo_result = (rn_lo - rm_hi);
  4743. hi_result = (rn_hi + rm_lo);
  4744. }
  4745. // SSAX
  4746. else if (op2 == 0x02) {
  4747. lo_result = (rn_lo + rm_hi);
  4748. hi_result = (rn_hi - rm_lo);
  4749. }
  4750. // SSUB16
  4751. else if (op2 == 0x03) {
  4752. lo_result = (rn_lo - rm_lo);
  4753. hi_result = (rn_hi - rm_hi);
  4754. }
  4755. RD = (lo_result & 0xFFFF) | ((hi_result & 0xFFFF) << 16);
  4756. if (lo_result >= 0) {
  4757. cpu->Cpsr |= (1 << 16);
  4758. cpu->Cpsr |= (1 << 17);
  4759. } else {
  4760. cpu->Cpsr &= ~(1 << 16);
  4761. cpu->Cpsr &= ~(1 << 17);
  4762. }
  4763. if (hi_result >= 0) {
  4764. cpu->Cpsr |= (1 << 18);
  4765. cpu->Cpsr |= (1 << 19);
  4766. } else {
  4767. cpu->Cpsr &= ~(1 << 18);
  4768. cpu->Cpsr &= ~(1 << 19);
  4769. }
  4770. }
  4771. else if (op2 == 0x04 || op2 == 0x07) {
  4772. s32 lo_val1, lo_val2;
  4773. s32 hi_val1, hi_val2;
  4774. // SADD8
  4775. if (op2 == 0x04) {
  4776. lo_val1 = (s32)(s8)(RN & 0xFF) + (s32)(s8)(RM & 0xFF);
  4777. lo_val2 = (s32)(s8)((RN >> 8) & 0xFF) + (s32)(s8)((RM >> 8) & 0xFF);
  4778. hi_val1 = (s32)(s8)((RN >> 16) & 0xFF) + (s32)(s8)((RM >> 16) & 0xFF);
  4779. hi_val2 = (s32)(s8)((RN >> 24) & 0xFF) + (s32)(s8)((RM >> 24) & 0xFF);
  4780. }
  4781. // SSUB8
  4782. else {
  4783. lo_val1 = (s32)(s8)(RN & 0xFF) - (s32)(s8)(RM & 0xFF);
  4784. lo_val2 = (s32)(s8)((RN >> 8) & 0xFF) - (s32)(s8)((RM >> 8) & 0xFF);
  4785. hi_val1 = (s32)(s8)((RN >> 16) & 0xFF) - (s32)(s8)((RM >> 16) & 0xFF);
  4786. hi_val2 = (s32)(s8)((RN >> 24) & 0xFF) - (s32)(s8)((RM >> 24) & 0xFF);
  4787. }
  4788. RD = ((lo_val1 & 0xFF) | ((lo_val2 & 0xFF) << 8) | ((hi_val1 & 0xFF) << 16) | ((hi_val2 & 0xFF) << 24));
  4789. if (lo_val1 >= 0)
  4790. cpu->Cpsr |= (1 << 16);
  4791. else
  4792. cpu->Cpsr &= ~(1 << 16);
  4793. if (lo_val2 >= 0)
  4794. cpu->Cpsr |= (1 << 17);
  4795. else
  4796. cpu->Cpsr &= ~(1 << 17);
  4797. if (hi_val1 >= 0)
  4798. cpu->Cpsr |= (1 << 18);
  4799. else
  4800. cpu->Cpsr &= ~(1 << 18);
  4801. if (hi_val2 >= 0)
  4802. cpu->Cpsr |= (1 << 19);
  4803. else
  4804. cpu->Cpsr &= ~(1 << 19);
  4805. }
  4806. }
  4807. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4808. INC_PC(sizeof(generic_arm_inst));
  4809. FETCH_INST;
  4810. GOTO_NEXT_INST;
  4811. }
  4812. SBC_INST:
  4813. {
  4814. sbc_inst *inst_cream = (sbc_inst *)inst_base->component;
  4815. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4816. lop = SHIFTER_OPERAND + !cpu->CFlag;
  4817. rop = RN;
  4818. RD = dst = rop - lop;
  4819. if (inst_cream->S && (inst_cream->Rd == 15)) {
  4820. if (CurrentModeHasSPSR) {
  4821. cpu->Cpsr = cpu->Spsr_copy;
  4822. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  4823. LOAD_NZCVT;
  4824. }
  4825. } else if (inst_cream->S) {
  4826. UPDATE_NFLAG(dst);
  4827. UPDATE_ZFLAG(dst);
  4828. if(rop >= !cpu->CFlag)
  4829. UPDATE_CFLAG_NOT_BORROW_FROM(rop - !cpu->CFlag, SHIFTER_OPERAND);
  4830. else
  4831. UPDATE_CFLAG_NOT_BORROW_FROM(rop, !cpu->CFlag);
  4832. UPDATE_VFLAG_OVERFLOW_FROM(dst, rop, lop);
  4833. }
  4834. if (inst_cream->Rd == 15) {
  4835. INC_PC(sizeof(sbc_inst));
  4836. goto DISPATCH;
  4837. }
  4838. }
  4839. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4840. INC_PC(sizeof(sbc_inst));
  4841. FETCH_INST;
  4842. GOTO_NEXT_INST;
  4843. }
  4844. SEL_INST:
  4845. {
  4846. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4847. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  4848. const u32 to = RM;
  4849. const u32 from = RN;
  4850. const u32 cpsr = cpu->Cpsr;
  4851. u32 result;
  4852. if (cpsr & (1 << 16))
  4853. result = from & 0xff;
  4854. else
  4855. result = to & 0xff;
  4856. if (cpsr & (1 << 17))
  4857. result |= from & 0x0000ff00;
  4858. else
  4859. result |= to & 0x0000ff00;
  4860. if (cpsr & (1 << 18))
  4861. result |= from & 0x00ff0000;
  4862. else
  4863. result |= to & 0x00ff0000;
  4864. if (cpsr & (1 << 19))
  4865. result |= from & 0xff000000;
  4866. else
  4867. result |= to & 0xff000000;
  4868. RD = result;
  4869. }
  4870. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4871. INC_PC(sizeof(generic_arm_inst));
  4872. FETCH_INST;
  4873. GOTO_NEXT_INST;
  4874. }
  4875. SETEND_INST:
  4876. SHADD8_INST:
  4877. SHADD16_INST:
  4878. SHADDSUBX_INST:
  4879. SHSUB8_INST:
  4880. SHSUB16_INST:
  4881. SHSUBADDX_INST:
  4882. {
  4883. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4884. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  4885. const u8 op2 = inst_cream->op2;
  4886. const u32 rm_val = RM;
  4887. const u32 rn_val = RN;
  4888. if (op2 == 0x00 || op2 == 0x01 || op2 == 0x02 || op2 == 0x03) {
  4889. s32 lo_result = 0;
  4890. s32 hi_result = 0;
  4891. // SHADD16
  4892. if (op2 == 0x00) {
  4893. lo_result = ((s16)(rn_val & 0xFFFF) + (s16)(rm_val & 0xFFFF)) >> 1;
  4894. hi_result = ((s16)((rn_val >> 16) & 0xFFFF) + (s16)((rm_val >> 16) & 0xFFFF)) >> 1;
  4895. }
  4896. // SHASX
  4897. else if (op2 == 0x01) {
  4898. lo_result = ((s16)(rn_val & 0xFFFF) - (s16)((rm_val >> 16) & 0xFFFF)) >> 1;
  4899. hi_result = ((s16)((rn_val >> 16) & 0xFFFF) + (s16)(rm_val & 0xFFFF)) >> 1;
  4900. }
  4901. // SHSAX
  4902. else if (op2 == 0x02) {
  4903. lo_result = ((s16)(rn_val & 0xFFFF) + (s16)((rm_val >> 16) & 0xFFFF)) >> 1;
  4904. hi_result = ((s16)((rn_val >> 16) & 0xFFFF) - (s16)(rm_val & 0xFFFF)) >> 1;
  4905. }
  4906. // SHSUB16
  4907. else if (op2 == 0x03) {
  4908. lo_result = ((s16)(rn_val & 0xFFFF) - (s16)(rm_val & 0xFFFF)) >> 1;
  4909. hi_result = ((s16)((rn_val >> 16) & 0xFFFF) - (s16)((rm_val >> 16) & 0xFFFF)) >> 1;
  4910. }
  4911. RD = ((lo_result & 0xFFFF) | ((hi_result & 0xFFFF) << 16));
  4912. }
  4913. else if (op2 == 0x04 || op2 == 0x07) {
  4914. s16 lo_val1, lo_val2;
  4915. s16 hi_val1, hi_val2;
  4916. // SHADD8
  4917. if (op2 == 0x04) {
  4918. lo_val1 = ((s8)(rn_val & 0xFF) + (s8)(rm_val & 0xFF)) >> 1;
  4919. lo_val2 = ((s8)((rn_val >> 8) & 0xFF) + (s8)((rm_val >> 8) & 0xFF)) >> 1;
  4920. hi_val1 = ((s8)((rn_val >> 16) & 0xFF) + (s8)((rm_val >> 16) & 0xFF)) >> 1;
  4921. hi_val2 = ((s8)((rn_val >> 24) & 0xFF) + (s8)((rm_val >> 24) & 0xFF)) >> 1;
  4922. }
  4923. // SHSUB8
  4924. else {
  4925. lo_val1 = ((s8)(rn_val & 0xFF) - (s8)(rm_val & 0xFF)) >> 1;
  4926. lo_val2 = ((s8)((rn_val >> 8) & 0xFF) - (s8)((rm_val >> 8) & 0xFF)) >> 1;
  4927. hi_val1 = ((s8)((rn_val >> 16) & 0xFF) - (s8)((rm_val >> 16) & 0xFF)) >> 1;
  4928. hi_val2 = ((s8)((rn_val >> 24) & 0xFF) - (s8)((rm_val >> 24) & 0xFF)) >> 1;
  4929. }
  4930. RD = (lo_val1 & 0xFF) | ((lo_val2 & 0xFF) << 8) | ((hi_val1 & 0xFF) << 16) | ((hi_val2 & 0xFF) << 24);
  4931. }
  4932. }
  4933. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4934. INC_PC(sizeof(generic_arm_inst));
  4935. FETCH_INST;
  4936. GOTO_NEXT_INST;
  4937. }
  4938. SMLA_INST:
  4939. {
  4940. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  4941. smla_inst *inst_cream = (smla_inst *)inst_base->component;
  4942. int32_t operand1, operand2;
  4943. if (inst_cream->x == 0)
  4944. operand1 = (BIT(RM, 15)) ? (BITS(RM, 0, 15) | 0xffff0000) : BITS(RM, 0, 15);
  4945. else
  4946. operand1 = (BIT(RM, 31)) ? (BITS(RM, 16, 31) | 0xffff0000) : BITS(RM, 16, 31);
  4947. if (inst_cream->y == 0)
  4948. operand2 = (BIT(RS, 15)) ? (BITS(RS, 0, 15) | 0xffff0000) : BITS(RS, 0, 15);
  4949. else
  4950. operand2 = (BIT(RS, 31)) ? (BITS(RS, 16, 31) | 0xffff0000) : BITS(RS, 16, 31);
  4951. RD = operand1 * operand2 + RN;
  4952. if (AddOverflow(operand1 * operand2, RN, RD))
  4953. cpu->Cpsr |= (1 << 27);
  4954. }
  4955. cpu->Reg[15] += GET_INST_SIZE(cpu);
  4956. INC_PC(sizeof(smla_inst));
  4957. FETCH_INST;
  4958. GOTO_NEXT_INST;
  4959. }
  4960. SMLAD_INST:
  4961. SMLSD_INST:
  4962. SMUAD_INST:
  4963. SMUSD_INST:
  4964. {
  4965. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  4966. smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
  4967. const u8 op2 = inst_cream->op2;
  4968. u32 rm_val = cpu->Reg[inst_cream->Rm];
  4969. const u32 rn_val = cpu->Reg[inst_cream->Rn];
  4970. if (inst_cream->m)
  4971. rm_val = (((rm_val & 0xFFFF) << 16) | (rm_val >> 16));
  4972. const s16 rm_lo = (rm_val & 0xFFFF);
  4973. const s16 rm_hi = ((rm_val >> 16) & 0xFFFF);
  4974. const s16 rn_lo = (rn_val & 0xFFFF);
  4975. const s16 rn_hi = ((rn_val >> 16) & 0xFFFF);
  4976. const u32 product1 = (rn_lo * rm_lo);
  4977. const u32 product2 = (rn_hi * rm_hi);
  4978. // SMUAD and SMLAD
  4979. if (BIT(op2, 1) == 0) {
  4980. RD = (product1 + product2);
  4981. if (inst_cream->Ra != 15) {
  4982. RD += cpu->Reg[inst_cream->Ra];
  4983. if (ARMul_AddOverflowQ(product1 + product2, cpu->Reg[inst_cream->Ra]))
  4984. cpu->Cpsr |= (1 << 27);
  4985. }
  4986. if (ARMul_AddOverflowQ(product1, product2))
  4987. cpu->Cpsr |= (1 << 27);
  4988. }
  4989. // SMUSD and SMLSD
  4990. else {
  4991. RD = (product1 - product2);
  4992. if (inst_cream->Ra != 15) {
  4993. RD += cpu->Reg[inst_cream->Ra];
  4994. if (ARMul_AddOverflowQ(product1 - product2, cpu->Reg[inst_cream->Ra]))
  4995. cpu->Cpsr |= (1 << 27);
  4996. }
  4997. }
  4998. }
  4999. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5000. INC_PC(sizeof(smlad_inst));
  5001. FETCH_INST;
  5002. GOTO_NEXT_INST;
  5003. }
  5004. SMLAL_INST:
  5005. {
  5006. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5007. umlal_inst *inst_cream = (umlal_inst *)inst_base->component;
  5008. long long int rm = RM;
  5009. long long int rs = RS;
  5010. if (BIT(rm, 31)) {
  5011. rm |= 0xffffffff00000000LL;
  5012. }
  5013. if (BIT(rs, 31)) {
  5014. rs |= 0xffffffff00000000LL;
  5015. }
  5016. long long int rst = rm * rs;
  5017. long long int rdhi32 = RDHI;
  5018. long long int hilo = (rdhi32 << 32) + RDLO;
  5019. rst += hilo;
  5020. RDLO = BITS(rst, 0, 31);
  5021. RDHI = BITS(rst, 32, 63);
  5022. if (inst_cream->S) {
  5023. cpu->NFlag = BIT(RDHI, 31);
  5024. cpu->ZFlag = (RDHI == 0 && RDLO == 0);
  5025. }
  5026. }
  5027. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5028. INC_PC(sizeof(umlal_inst));
  5029. FETCH_INST;
  5030. GOTO_NEXT_INST;
  5031. }
  5032. SMLALXY_INST:
  5033. SMLAW_INST:
  5034. {
  5035. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5036. smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
  5037. const u32 rm_val = RM;
  5038. const u32 rn_val = RN;
  5039. const u32 ra_val = cpu->Reg[inst_cream->Ra];
  5040. const bool high = (inst_cream->m == 1);
  5041. const s16 operand2 = (high) ? ((rm_val >> 16) & 0xFFFF) : (rm_val & 0xFFFF);
  5042. const s64 result = (s64)(s32)rn_val * (s64)(s32)operand2 + ((s64)(s32)ra_val << 16);
  5043. RD = (result & (0xFFFFFFFFFFFFFFFFLL >> 15)) >> 16;
  5044. if ((result >> 16) != (s32)RD)
  5045. cpu->Cpsr |= (1 << 27);
  5046. }
  5047. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5048. INC_PC(sizeof(smlad_inst));
  5049. FETCH_INST;
  5050. GOTO_NEXT_INST;
  5051. }
  5052. SMLALD_INST:
  5053. SMLSLD_INST:
  5054. {
  5055. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5056. smlald_inst* const inst_cream = (smlald_inst*)inst_base->component;
  5057. const bool do_swap = (inst_cream->swap == 1);
  5058. const u32 rdlo_val = RDLO;
  5059. const u32 rdhi_val = RDHI;
  5060. const u32 rn_val = RN;
  5061. u32 rm_val = RM;
  5062. if (do_swap)
  5063. rm_val = (((rm_val & 0xFFFF) << 16) | (rm_val >> 16));
  5064. const s32 product1 = (s16)(rn_val & 0xFFFF) * (s16)(rm_val & 0xFFFF);
  5065. const s32 product2 = (s16)((rn_val >> 16) & 0xFFFF) * (s16)((rm_val >> 16) & 0xFFFF);
  5066. s64 result;
  5067. // SMLALD
  5068. if (BIT(inst_cream->op2, 1) == 0) {
  5069. result = (product1 + product2) + (s64)(rdlo_val | ((s64)rdhi_val << 32));
  5070. }
  5071. // SMLSLD
  5072. else {
  5073. result = (product1 - product2) + (s64)(rdlo_val | ((s64)rdhi_val << 32));
  5074. }
  5075. RDLO = (result & 0xFFFFFFFF);
  5076. RDHI = ((result >> 32) & 0xFFFFFFFF);
  5077. }
  5078. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5079. INC_PC(sizeof(smlald_inst));
  5080. FETCH_INST;
  5081. GOTO_NEXT_INST;
  5082. }
  5083. SMMLA_INST:
  5084. SMMLS_INST:
  5085. SMMUL_INST:
  5086. {
  5087. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5088. smlad_inst* const inst_cream = (smlad_inst*)inst_base->component;
  5089. const u32 rm_val = RM;
  5090. const u32 rn_val = RN;
  5091. const bool do_round = (inst_cream->m == 1);
  5092. // Assume SMMUL by default.
  5093. s64 result = (s64)(s32)rn_val * (s64)(s32)rm_val;
  5094. if (inst_cream->Ra != 15) {
  5095. const u32 ra_val = cpu->Reg[inst_cream->Ra];
  5096. // SMMLA, otherwise SMMLS
  5097. if (BIT(inst_cream->op2, 1) == 0)
  5098. result += ((s64)ra_val << 32);
  5099. else
  5100. result = ((s64)ra_val << 32) - result;
  5101. }
  5102. if (do_round)
  5103. result += 0x80000000;
  5104. RD = ((result >> 32) & 0xFFFFFFFF);
  5105. }
  5106. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5107. INC_PC(sizeof(smlad_inst));
  5108. FETCH_INST;
  5109. GOTO_NEXT_INST;
  5110. }
  5111. SMUL_INST:
  5112. {
  5113. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5114. smul_inst *inst_cream = (smul_inst *)inst_base->component;
  5115. uint32_t operand1, operand2;
  5116. if (inst_cream->x == 0)
  5117. operand1 = (BIT(RM, 15)) ? (BITS(RM, 0, 15) | 0xffff0000) : BITS(RM, 0, 15);
  5118. else
  5119. operand1 = (BIT(RM, 31)) ? (BITS(RM, 16, 31) | 0xffff0000) : BITS(RM, 16, 31);
  5120. if (inst_cream->y == 0)
  5121. operand2 = (BIT(RS, 15)) ? (BITS(RS, 0, 15) | 0xffff0000) : BITS(RS, 0, 15);
  5122. else
  5123. operand2 = (BIT(RS, 31)) ? (BITS(RS, 16, 31) | 0xffff0000) : BITS(RS, 16, 31);
  5124. RD = operand1 * operand2;
  5125. }
  5126. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5127. INC_PC(sizeof(smul_inst));
  5128. FETCH_INST;
  5129. GOTO_NEXT_INST;
  5130. }
  5131. SMULL_INST:
  5132. {
  5133. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5134. umull_inst *inst_cream = (umull_inst *)inst_base->component;
  5135. int64_t rm = RM;
  5136. int64_t rs = RS;
  5137. if (BIT(rm, 31)) {
  5138. rm |= 0xffffffff00000000LL;
  5139. }
  5140. if (BIT(rs, 31)) {
  5141. rs |= 0xffffffff00000000LL;
  5142. }
  5143. int64_t rst = rm * rs;
  5144. RDHI = BITS(rst, 32, 63);
  5145. RDLO = BITS(rst, 0, 31);
  5146. if (inst_cream->S) {
  5147. cpu->NFlag = BIT(RDHI, 31);
  5148. cpu->ZFlag = (RDHI == 0 && RDLO == 0);
  5149. }
  5150. }
  5151. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5152. INC_PC(sizeof(umull_inst));
  5153. FETCH_INST;
  5154. GOTO_NEXT_INST;
  5155. }
  5156. SMULW_INST:
  5157. {
  5158. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5159. smlad_inst *inst_cream = (smlad_inst *)inst_base->component;
  5160. int64_t rm = RM;
  5161. int64_t rn = RN;
  5162. if (inst_cream->m)
  5163. rm = BITS(rm, 16, 31);
  5164. else
  5165. rm = BITS(rm, 0, 15);
  5166. int64_t rst = rm * rn;
  5167. RD = BITS(rst, 16, 47);
  5168. }
  5169. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5170. INC_PC(sizeof(smlad_inst));
  5171. FETCH_INST;
  5172. GOTO_NEXT_INST;
  5173. }
  5174. SRS_INST:
  5175. SSAT_INST:
  5176. {
  5177. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5178. ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
  5179. u8 shift_type = inst_cream->shift_type;
  5180. u8 shift_amount = inst_cream->imm5;
  5181. u32 rn_val = RN;
  5182. // 32-bit ASR is encoded as an amount of 0.
  5183. if (shift_type == 1 && shift_amount == 0)
  5184. shift_amount = 31;
  5185. if (shift_type == 0)
  5186. rn_val <<= shift_amount;
  5187. else if (shift_type == 1)
  5188. rn_val = ((s32)rn_val >> shift_amount);
  5189. bool saturated = false;
  5190. rn_val = ARMul_SignedSatQ(rn_val, inst_cream->sat_imm, &saturated);
  5191. if (saturated)
  5192. cpu->Cpsr |= (1 << 27);
  5193. RD = rn_val;
  5194. }
  5195. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5196. INC_PC(sizeof(ssat_inst));
  5197. FETCH_INST;
  5198. GOTO_NEXT_INST;
  5199. }
  5200. SSAT16_INST:
  5201. {
  5202. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5203. ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
  5204. const u8 saturate_to = inst_cream->sat_imm;
  5205. bool sat1 = false;
  5206. bool sat2 = false;
  5207. RD = (ARMul_SignedSatQ((s16)RN, saturate_to, &sat1) & 0xFFFF) |
  5208. ARMul_SignedSatQ((s32)RN >> 16, saturate_to, &sat2) << 16;
  5209. if (sat1 || sat2)
  5210. cpu->Cpsr |= (1 << 27);
  5211. }
  5212. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5213. INC_PC(sizeof(ssat_inst));
  5214. FETCH_INST;
  5215. GOTO_NEXT_INST;
  5216. }
  5217. STC_INST:
  5218. {
  5219. // Instruction not implemented
  5220. //LOG_CRITICAL(Core_ARM11, "unimplemented instruction");
  5221. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5222. INC_PC(sizeof(stc_inst));
  5223. FETCH_INST;
  5224. GOTO_NEXT_INST;
  5225. }
  5226. STM_INST:
  5227. {
  5228. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  5229. unsigned int inst = inst_cream->inst;
  5230. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5231. int i;
  5232. unsigned int Rn = BITS(inst, 16, 19);
  5233. unsigned int old_RN = cpu->Reg[Rn];
  5234. inst_cream->get_addr(cpu, inst_cream->inst, addr, 0);
  5235. if (BIT(inst_cream->inst, 22) == 1) {
  5236. for (i = 0; i < 13; i++) {
  5237. if(BIT(inst_cream->inst, i)) {
  5238. Memory::Write32(addr, cpu->Reg[i]);
  5239. addr += 4;
  5240. }
  5241. }
  5242. if (BIT(inst_cream->inst, 13)) {
  5243. if (cpu->Mode == USER32MODE) {
  5244. Memory::Write32(addr, cpu->Reg[i]);
  5245. addr += 4;
  5246. } else {
  5247. Memory::Write32(addr, cpu->Reg_usr[0]);
  5248. addr += 4;
  5249. }
  5250. }
  5251. if (BIT(inst_cream->inst, 14)) {
  5252. if (cpu->Mode == USER32MODE) {
  5253. Memory::Write32(addr, cpu->Reg[i]);
  5254. addr += 4;
  5255. } else {
  5256. Memory::Write32(addr, cpu->Reg_usr[1]);
  5257. addr += 4;
  5258. }
  5259. }
  5260. if (BIT(inst_cream->inst, 15)) {
  5261. Memory::Write32(addr, cpu->Reg_usr[1] + 8);
  5262. }
  5263. } else {
  5264. for( i = 0; i < 15; i++ ) {
  5265. if(BIT(inst_cream->inst, i)) {
  5266. if(i == Rn)
  5267. Memory::Write32(addr, old_RN);
  5268. else
  5269. Memory::Write32(addr, cpu->Reg[i]);
  5270. addr += 4;
  5271. }
  5272. }
  5273. // Check PC reg
  5274. if(BIT(inst_cream->inst, i)) {
  5275. Memory::Write32(addr, cpu->Reg_usr[1] + 8);
  5276. }
  5277. }
  5278. }
  5279. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5280. INC_PC(sizeof(ldst_inst));
  5281. FETCH_INST;
  5282. GOTO_NEXT_INST;
  5283. }
  5284. SXTB_INST:
  5285. {
  5286. sxtb_inst *inst_cream = (sxtb_inst *)inst_base->component;
  5287. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5288. if (inst_cream->Rm == 15) {
  5289. LOG_ERROR(Core_ARM11, "invalid operand for SXTB");
  5290. CITRA_IGNORE_EXIT(-1);
  5291. }
  5292. unsigned int operand2 = ROTATE_RIGHT_32(RM, 8 * inst_cream->rotate);
  5293. if (BIT(operand2, 7)) {
  5294. operand2 |= 0xffffff00;
  5295. } else
  5296. operand2 &= 0xff;
  5297. RD = operand2;
  5298. }
  5299. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5300. INC_PC(sizeof(sxtb_inst));
  5301. FETCH_INST;
  5302. GOTO_NEXT_INST;
  5303. }
  5304. STR_INST:
  5305. {
  5306. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  5307. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5308. inst_cream->get_addr(cpu, inst_cream->inst, addr, 0);
  5309. unsigned int value = cpu->Reg[BITS(inst_cream->inst, 12, 15)];
  5310. Memory::Write32(addr, value);
  5311. }
  5312. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5313. INC_PC(sizeof(ldst_inst));
  5314. FETCH_INST;
  5315. GOTO_NEXT_INST;
  5316. }
  5317. UXTB_INST:
  5318. {
  5319. uxtb_inst *inst_cream = (uxtb_inst *)inst_base->component;
  5320. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5321. unsigned int operand2 = ROTATE_RIGHT_32(RM, 8 * inst_cream->rotate)
  5322. & 0xff;
  5323. RD = operand2;
  5324. }
  5325. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5326. INC_PC(sizeof(uxtb_inst));
  5327. FETCH_INST;
  5328. GOTO_NEXT_INST;
  5329. }
  5330. UXTAB_INST:
  5331. {
  5332. uxtab_inst *inst_cream = (uxtab_inst *)inst_base->component;
  5333. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5334. unsigned int operand2 = ROTATE_RIGHT_32(RM, 8 * inst_cream->rotate)
  5335. & 0xff;
  5336. RD = RN + operand2;
  5337. }
  5338. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5339. INC_PC(sizeof(uxtab_inst));
  5340. FETCH_INST;
  5341. GOTO_NEXT_INST;
  5342. }
  5343. STRB_INST:
  5344. {
  5345. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  5346. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5347. inst_cream->get_addr(cpu, inst_cream->inst, addr, 0);
  5348. unsigned int value = cpu->Reg[BITS(inst_cream->inst, 12, 15)] & 0xff;
  5349. Memory::Write8(addr, value);
  5350. }
  5351. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5352. INC_PC(sizeof(ldst_inst));
  5353. FETCH_INST;
  5354. GOTO_NEXT_INST;
  5355. }
  5356. STRBT_INST:
  5357. {
  5358. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  5359. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5360. inst_cream->get_addr(cpu, inst_cream->inst, addr, 0);
  5361. unsigned int value = cpu->Reg[BITS(inst_cream->inst, 12, 15)] & 0xff;
  5362. Memory::Write8(addr, value);
  5363. }
  5364. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5365. INC_PC(sizeof(ldst_inst));
  5366. FETCH_INST;
  5367. GOTO_NEXT_INST;
  5368. }
  5369. STRD_INST:
  5370. {
  5371. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  5372. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5373. inst_cream->get_addr(cpu, inst_cream->inst, addr, 0);
  5374. unsigned int value = cpu->Reg[BITS(inst_cream->inst, 12, 15)];
  5375. Memory::Write32(addr, value);
  5376. value = cpu->Reg[BITS(inst_cream->inst, 12, 15) + 1];
  5377. Memory::Write32(addr + 4, value);
  5378. }
  5379. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5380. INC_PC(sizeof(ldst_inst));
  5381. FETCH_INST;
  5382. GOTO_NEXT_INST;
  5383. }
  5384. STREX_INST:
  5385. {
  5386. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  5387. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5388. unsigned int write_addr = cpu->Reg[inst_cream->Rn];
  5389. if ((exclusive_detect(cpu, write_addr) == 0) && (cpu->exclusive_state == 1)) {
  5390. remove_exclusive(cpu, write_addr);
  5391. cpu->exclusive_state = 0;
  5392. Memory::Write32(write_addr, cpu->Reg[inst_cream->Rm]);
  5393. RD = 0;
  5394. } else {
  5395. // Failed to write due to mutex access
  5396. RD = 1;
  5397. }
  5398. }
  5399. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5400. INC_PC(sizeof(generic_arm_inst));
  5401. FETCH_INST;
  5402. GOTO_NEXT_INST;
  5403. }
  5404. STREXB_INST:
  5405. {
  5406. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  5407. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5408. unsigned int write_addr = cpu->Reg[inst_cream->Rn];
  5409. if ((exclusive_detect(cpu, write_addr) == 0) && (cpu->exclusive_state == 1)) {
  5410. remove_exclusive(cpu, write_addr);
  5411. cpu->exclusive_state = 0;
  5412. Memory::Write8(write_addr, cpu->Reg[inst_cream->Rm]);
  5413. RD = 0;
  5414. } else {
  5415. // Failed to write due to mutex access
  5416. RD = 1;
  5417. }
  5418. }
  5419. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5420. INC_PC(sizeof(generic_arm_inst));
  5421. FETCH_INST;
  5422. GOTO_NEXT_INST;
  5423. }
  5424. STREXD_INST:
  5425. {
  5426. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  5427. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5428. unsigned int write_addr = cpu->Reg[inst_cream->Rn];
  5429. if ((exclusive_detect(cpu, write_addr) == 0) && (cpu->exclusive_state == 1)) {
  5430. remove_exclusive(cpu, write_addr);
  5431. cpu->exclusive_state = 0;
  5432. Memory::Write32(write_addr, cpu->Reg[inst_cream->Rm]);
  5433. Memory::Write32(write_addr + 4, cpu->Reg[inst_cream->Rm + 1]);
  5434. RD = 0;
  5435. }
  5436. else {
  5437. // Failed to write due to mutex access
  5438. RD = 1;
  5439. }
  5440. }
  5441. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5442. INC_PC(sizeof(generic_arm_inst));
  5443. FETCH_INST;
  5444. GOTO_NEXT_INST;
  5445. }
  5446. STREXH_INST:
  5447. {
  5448. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  5449. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5450. unsigned int write_addr = cpu->Reg[inst_cream->Rn];
  5451. if ((exclusive_detect(cpu, write_addr) == 0) && (cpu->exclusive_state == 1)) {
  5452. remove_exclusive(cpu, write_addr);
  5453. cpu->exclusive_state = 0;
  5454. Memory::Write16(write_addr, cpu->Reg[inst_cream->Rm]);
  5455. RD = 0;
  5456. } else {
  5457. // Failed to write due to mutex access
  5458. RD = 1;
  5459. }
  5460. }
  5461. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5462. INC_PC(sizeof(generic_arm_inst));
  5463. FETCH_INST;
  5464. GOTO_NEXT_INST;
  5465. }
  5466. STRH_INST:
  5467. {
  5468. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  5469. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5470. inst_cream->get_addr(cpu, inst_cream->inst, addr, 0);
  5471. unsigned int value = cpu->Reg[BITS(inst_cream->inst, 12, 15)] & 0xffff;
  5472. Memory::Write16(addr, value);
  5473. }
  5474. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5475. INC_PC(sizeof(ldst_inst));
  5476. FETCH_INST;
  5477. GOTO_NEXT_INST;
  5478. }
  5479. STRT_INST:
  5480. {
  5481. ldst_inst *inst_cream = (ldst_inst *)inst_base->component;
  5482. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5483. inst_cream->get_addr(cpu, inst_cream->inst, addr, 0);
  5484. unsigned int value = cpu->Reg[BITS(inst_cream->inst, 12, 15)];
  5485. Memory::Write32(addr, value);
  5486. }
  5487. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5488. INC_PC(sizeof(ldst_inst));
  5489. FETCH_INST;
  5490. GOTO_NEXT_INST;
  5491. }
  5492. SUB_INST:
  5493. {
  5494. sub_inst *inst_cream = (sub_inst *)inst_base->component;
  5495. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5496. lop = RN;
  5497. if (inst_cream->Rn == 15) {
  5498. lop += 8;
  5499. }
  5500. rop = SHIFTER_OPERAND;
  5501. RD = dst = lop - rop;
  5502. if (inst_cream->S && (inst_cream->Rd == 15)) {
  5503. if (CurrentModeHasSPSR) {
  5504. cpu->Cpsr = cpu->Spsr_copy;
  5505. switch_mode(cpu, cpu->Spsr_copy & 0x1f);
  5506. LOAD_NZCVT;
  5507. }
  5508. } else if (inst_cream->S) {
  5509. UPDATE_NFLAG(dst);
  5510. UPDATE_ZFLAG(dst);
  5511. UPDATE_CFLAG_NOT_BORROW_FROM(lop, rop);
  5512. UPDATE_VFLAG_OVERFLOW_FROM(dst, lop, rop);
  5513. }
  5514. if (inst_cream->Rd == 15) {
  5515. INC_PC(sizeof(sub_inst));
  5516. goto DISPATCH;
  5517. }
  5518. }
  5519. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5520. INC_PC(sizeof(sub_inst));
  5521. FETCH_INST;
  5522. GOTO_NEXT_INST;
  5523. }
  5524. SWI_INST:
  5525. {
  5526. swi_inst *inst_cream = (swi_inst *)inst_base->component;
  5527. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond))
  5528. HLE::CallSVC(Memory::Read32(cpu->Reg[15]));
  5529. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5530. INC_PC(sizeof(swi_inst));
  5531. FETCH_INST;
  5532. GOTO_NEXT_INST;
  5533. }
  5534. SWP_INST:
  5535. {
  5536. swp_inst *inst_cream = (swp_inst *)inst_base->component;
  5537. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5538. addr = RN;
  5539. unsigned int value;
  5540. value = Memory::Read32(addr);
  5541. Memory::Write32(addr, RM);
  5542. RD = value;
  5543. }
  5544. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5545. INC_PC(sizeof(swp_inst));
  5546. FETCH_INST;
  5547. GOTO_NEXT_INST;
  5548. }
  5549. SWPB_INST:
  5550. {
  5551. swp_inst *inst_cream = (swp_inst *)inst_base->component;
  5552. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5553. addr = RN;
  5554. unsigned int value = Memory::Read8(addr);
  5555. Memory::Write8(addr, (RM & 0xFF));
  5556. RD = value;
  5557. }
  5558. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5559. INC_PC(sizeof(swp_inst));
  5560. FETCH_INST;
  5561. GOTO_NEXT_INST;
  5562. }
  5563. SXTAB_INST:
  5564. {
  5565. sxtab_inst *inst_cream = (sxtab_inst *)inst_base->component;
  5566. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5567. // R15 should be check
  5568. if(inst_cream->Rn == 15 || inst_cream->Rm == 15 || inst_cream->Rd ==15){
  5569. CITRA_IGNORE_EXIT(-1);
  5570. }
  5571. unsigned int operand2 = ROTATE_RIGHT_32(RM, 8 * inst_cream->rotate) & 0xff;
  5572. // Sign extend for byte
  5573. operand2 = (0x80 & operand2)? (0xFFFFFF00 | operand2):operand2;
  5574. RD = RN + operand2;
  5575. }
  5576. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5577. INC_PC(sizeof(uxtab_inst));
  5578. FETCH_INST;
  5579. GOTO_NEXT_INST;
  5580. }
  5581. SXTAB16_INST:
  5582. SXTB16_INST:
  5583. {
  5584. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5585. sxtab_inst* const inst_cream = (sxtab_inst*)inst_base->component;
  5586. const u8 rotation = inst_cream->rotate * 8;
  5587. u32 rm_val = RM;
  5588. u32 rn_val = RN;
  5589. if (rotation)
  5590. rm_val = ((rm_val << (32 - rotation)) | (rm_val >> rotation));
  5591. // SXTB16
  5592. if (inst_cream->Rn == 15) {
  5593. u32 lo = (u32)(s8)rm_val;
  5594. u32 hi = (u32)(s8)(rm_val >> 16);
  5595. RD = (lo | (hi << 16));
  5596. }
  5597. // SXTAB16
  5598. else {
  5599. u32 lo = (rn_val & 0xFFFF) + (u32)(s8)(rm_val & 0xFF);
  5600. u32 hi = ((rn_val >> 16) & 0xFFFF) + (u32)(s8)((rm_val >> 16) & 0xFF);
  5601. RD = (lo | (hi << 16));
  5602. }
  5603. }
  5604. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5605. INC_PC(sizeof(sxtab_inst));
  5606. FETCH_INST;
  5607. GOTO_NEXT_INST;
  5608. }
  5609. SXTAH_INST:
  5610. {
  5611. sxtah_inst *inst_cream = (sxtah_inst *)inst_base->component;
  5612. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5613. // R15 should be check
  5614. if(inst_cream->Rn == 15 || inst_cream->Rm == 15 || inst_cream->Rd ==15) {
  5615. CITRA_IGNORE_EXIT(-1);
  5616. }
  5617. unsigned int operand2 = ROTATE_RIGHT_32(RM, 8 * inst_cream->rotate) & 0xffff;
  5618. // Sign extend for half
  5619. operand2 = (0x8000 & operand2) ? (0xFFFF0000 | operand2) : operand2;
  5620. RD = RN + operand2;
  5621. }
  5622. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5623. INC_PC(sizeof(sxtah_inst));
  5624. FETCH_INST;
  5625. GOTO_NEXT_INST;
  5626. }
  5627. TEQ_INST:
  5628. {
  5629. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5630. teq_inst *inst_cream = (teq_inst *)inst_base->component;
  5631. lop = RN;
  5632. if (inst_cream->Rn == 15)
  5633. lop += GET_INST_SIZE(cpu) * 2;
  5634. rop = SHIFTER_OPERAND;
  5635. dst = lop ^ rop;
  5636. UPDATE_NFLAG(dst);
  5637. UPDATE_ZFLAG(dst);
  5638. UPDATE_CFLAG_WITH_SC;
  5639. }
  5640. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5641. INC_PC(sizeof(teq_inst));
  5642. FETCH_INST;
  5643. GOTO_NEXT_INST;
  5644. }
  5645. TST_INST:
  5646. {
  5647. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5648. tst_inst *inst_cream = (tst_inst *)inst_base->component;
  5649. lop = RN;
  5650. if (inst_cream->Rn == 15)
  5651. lop += GET_INST_SIZE(cpu) * 2;
  5652. rop = SHIFTER_OPERAND;
  5653. dst = lop & rop;
  5654. UPDATE_NFLAG(dst);
  5655. UPDATE_ZFLAG(dst);
  5656. UPDATE_CFLAG_WITH_SC;
  5657. }
  5658. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5659. INC_PC(sizeof(tst_inst));
  5660. FETCH_INST;
  5661. GOTO_NEXT_INST;
  5662. }
  5663. UADD8_INST:
  5664. UADD16_INST:
  5665. UADDSUBX_INST:
  5666. USUB8_INST:
  5667. USUB16_INST:
  5668. USUBADDX_INST:
  5669. {
  5670. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5671. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  5672. const u8 op2 = inst_cream->op2;
  5673. const u32 rm_val = RM;
  5674. const u32 rn_val = RN;
  5675. s32 lo_result = 0;
  5676. s32 hi_result = 0;
  5677. // UADD16
  5678. if (op2 == 0x00) {
  5679. lo_result = (rn_val & 0xFFFF) + (rm_val & 0xFFFF);
  5680. hi_result = ((rn_val >> 16) & 0xFFFF) + ((rm_val >> 16) & 0xFFFF);
  5681. if (lo_result & 0xFFFF0000) {
  5682. cpu->Cpsr |= (1 << 16);
  5683. cpu->Cpsr |= (1 << 17);
  5684. } else {
  5685. cpu->Cpsr &= ~(1 << 16);
  5686. cpu->Cpsr &= ~(1 << 17);
  5687. }
  5688. if (hi_result & 0xFFFF0000) {
  5689. cpu->Cpsr |= (1 << 18);
  5690. cpu->Cpsr |= (1 << 19);
  5691. } else {
  5692. cpu->Cpsr &= ~(1 << 18);
  5693. cpu->Cpsr &= ~(1 << 19);
  5694. }
  5695. }
  5696. // UASX
  5697. else if (op2 == 0x01) {
  5698. lo_result = (rn_val & 0xFFFF) - ((rm_val >> 16) & 0xFFFF);
  5699. hi_result = ((rn_val >> 16) & 0xFFFF) + (rm_val & 0xFFFF);
  5700. if (lo_result >= 0) {
  5701. cpu->Cpsr |= (1 << 16);
  5702. cpu->Cpsr |= (1 << 17);
  5703. } else {
  5704. cpu->Cpsr &= ~(1 << 16);
  5705. cpu->Cpsr &= ~(1 << 17);
  5706. }
  5707. if (hi_result >= 0x10000) {
  5708. cpu->Cpsr |= (1 << 18);
  5709. cpu->Cpsr |= (1 << 19);
  5710. } else {
  5711. cpu->Cpsr &= ~(1 << 18);
  5712. cpu->Cpsr &= ~(1 << 19);
  5713. }
  5714. }
  5715. // USAX
  5716. else if (op2 == 0x02) {
  5717. lo_result = (rn_val & 0xFFFF) + ((rm_val >> 16) & 0xFFFF);
  5718. hi_result = ((rn_val >> 16) & 0xFFFF) - (rm_val & 0xFFFF);
  5719. if (lo_result >= 0x10000) {
  5720. cpu->Cpsr |= (1 << 16);
  5721. cpu->Cpsr |= (1 << 17);
  5722. } else {
  5723. cpu->Cpsr &= ~(1 << 16);
  5724. cpu->Cpsr &= ~(1 << 17);
  5725. }
  5726. if (hi_result >= 0) {
  5727. cpu->Cpsr |= (1 << 18);
  5728. cpu->Cpsr |= (1 << 19);
  5729. } else {
  5730. cpu->Cpsr &= ~(1 << 18);
  5731. cpu->Cpsr &= ~(1 << 19);
  5732. }
  5733. }
  5734. // USUB16
  5735. else if (op2 == 0x03) {
  5736. lo_result = (rn_val & 0xFFFF) - (rm_val & 0xFFFF);
  5737. hi_result = ((rn_val >> 16) & 0xFFFF) - ((rm_val >> 16) & 0xFFFF);
  5738. if ((lo_result & 0xFFFF0000) == 0) {
  5739. cpu->Cpsr |= (1 << 16);
  5740. cpu->Cpsr |= (1 << 17);
  5741. } else {
  5742. cpu->Cpsr &= ~(1 << 16);
  5743. cpu->Cpsr &= ~(1 << 17);
  5744. }
  5745. if ((hi_result & 0xFFFF0000) == 0) {
  5746. cpu->Cpsr |= (1 << 18);
  5747. cpu->Cpsr |= (1 << 19);
  5748. } else {
  5749. cpu->Cpsr &= ~(1 << 18);
  5750. cpu->Cpsr &= ~(1 << 19);
  5751. }
  5752. }
  5753. // UADD8
  5754. else if (op2 == 0x04) {
  5755. s16 sum1 = (rn_val & 0xFF) + (rm_val & 0xFF);
  5756. s16 sum2 = ((rn_val >> 8) & 0xFF) + ((rm_val >> 8) & 0xFF);
  5757. s16 sum3 = ((rn_val >> 16) & 0xFF) + ((rm_val >> 16) & 0xFF);
  5758. s16 sum4 = ((rn_val >> 24) & 0xFF) + ((rm_val >> 24) & 0xFF);
  5759. if (sum1 >= 0x100)
  5760. state->Cpsr |= (1 << 16);
  5761. else
  5762. state->Cpsr &= ~(1 << 16);
  5763. if (sum2 >= 0x100)
  5764. state->Cpsr |= (1 << 17);
  5765. else
  5766. state->Cpsr &= ~(1 << 17);
  5767. if (sum3 >= 0x100)
  5768. state->Cpsr |= (1 << 18);
  5769. else
  5770. state->Cpsr &= ~(1 << 18);
  5771. if (sum4 >= 0x100)
  5772. state->Cpsr |= (1 << 19);
  5773. else
  5774. state->Cpsr &= ~(1 << 19);
  5775. lo_result = ((sum1 & 0xFF) | (sum2 & 0xFF) << 8);
  5776. hi_result = ((sum3 & 0xFF) | (sum4 & 0xFF) << 8);
  5777. }
  5778. // USUB8
  5779. else if (op2 == 0x07) {
  5780. s16 diff1 = (rn_val & 0xFF) - (rm_val & 0xFF);
  5781. s16 diff2 = ((rn_val >> 8) & 0xFF) - ((rm_val >> 8) & 0xFF);
  5782. s16 diff3 = ((rn_val >> 16) & 0xFF) - ((rm_val >> 16) & 0xFF);
  5783. s16 diff4 = ((rn_val >> 24) & 0xFF) - ((rm_val >> 24) & 0xFF);
  5784. if (diff1 >= 0)
  5785. state->Cpsr |= (1 << 16);
  5786. else
  5787. state->Cpsr &= ~(1 << 16);
  5788. if (diff2 >= 0)
  5789. state->Cpsr |= (1 << 17);
  5790. else
  5791. state->Cpsr &= ~(1 << 17);
  5792. if (diff3 >= 0)
  5793. state->Cpsr |= (1 << 18);
  5794. else
  5795. state->Cpsr &= ~(1 << 18);
  5796. if (diff4 >= 0)
  5797. state->Cpsr |= (1 << 19);
  5798. else
  5799. state->Cpsr &= ~(1 << 19);
  5800. lo_result = (diff1 & 0xFF) | ((diff2 & 0xFF) << 8);
  5801. hi_result = (diff3 & 0xFF) | ((diff4 & 0xFF) << 8);
  5802. }
  5803. RD = (lo_result & 0xFFFF) | ((hi_result & 0xFFFF) << 16);
  5804. }
  5805. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5806. INC_PC(sizeof(generic_arm_inst));
  5807. FETCH_INST;
  5808. GOTO_NEXT_INST;
  5809. }
  5810. UHADD8_INST:
  5811. UHADD16_INST:
  5812. UHADDSUBX_INST:
  5813. UHSUBADDX_INST:
  5814. UHSUB8_INST:
  5815. UHSUB16_INST:
  5816. {
  5817. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5818. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  5819. const u32 rm_val = RM;
  5820. const u32 rn_val = RN;
  5821. const u8 op2 = inst_cream->op2;
  5822. if (op2 == 0x00 || op2 == 0x01 || op2 == 0x02 || op2 == 0x03)
  5823. {
  5824. u32 lo_val = 0;
  5825. u32 hi_val = 0;
  5826. // UHADD16
  5827. if (op2 == 0x00) {
  5828. lo_val = (rn_val & 0xFFFF) + (rm_val & 0xFFFF);
  5829. hi_val = ((rn_val >> 16) & 0xFFFF) + ((rm_val >> 16) & 0xFFFF);
  5830. }
  5831. // UHASX
  5832. else if (op2 == 0x01) {
  5833. lo_val = (rn_val & 0xFFFF) - ((rm_val >> 16) & 0xFFFF);
  5834. hi_val = ((rn_val >> 16) & 0xFFFF) + (rm_val & 0xFFFF);
  5835. }
  5836. // UHSAX
  5837. else if (op2 == 0x02) {
  5838. lo_val = (rn_val & 0xFFFF) + ((rm_val >> 16) & 0xFFFF);
  5839. hi_val = ((rn_val >> 16) & 0xFFFF) - (rm_val & 0xFFFF);
  5840. }
  5841. // UHSUB16
  5842. else if (op2 == 0x03) {
  5843. lo_val = (rn_val & 0xFFFF) - (rm_val & 0xFFFF);
  5844. hi_val = ((rn_val >> 16) & 0xFFFF) - ((rm_val >> 16) & 0xFFFF);
  5845. }
  5846. lo_val >>= 1;
  5847. hi_val >>= 1;
  5848. RD = (lo_val & 0xFFFF) | ((hi_val & 0xFFFF) << 16);
  5849. }
  5850. else if (op2 == 0x04 || op2 == 0x07) {
  5851. u32 sum1;
  5852. u32 sum2;
  5853. u32 sum3;
  5854. u32 sum4;
  5855. // UHADD8
  5856. if (op2 == 0x04) {
  5857. sum1 = (rn_val & 0xFF) + (rm_val & 0xFF);
  5858. sum2 = ((rn_val >> 8) & 0xFF) + ((rm_val >> 8) & 0xFF);
  5859. sum3 = ((rn_val >> 16) & 0xFF) + ((rm_val >> 16) & 0xFF);
  5860. sum4 = ((rn_val >> 24) & 0xFF) + ((rm_val >> 24) & 0xFF);
  5861. }
  5862. // UHSUB8
  5863. else {
  5864. sum1 = (rn_val & 0xFF) - (rm_val & 0xFF);
  5865. sum2 = ((rn_val >> 8) & 0xFF) - ((rm_val >> 8) & 0xFF);
  5866. sum3 = ((rn_val >> 16) & 0xFF) - ((rm_val >> 16) & 0xFF);
  5867. sum4 = ((rn_val >> 24) & 0xFF) - ((rm_val >> 24) & 0xFF);
  5868. }
  5869. sum1 >>= 1;
  5870. sum2 >>= 1;
  5871. sum3 >>= 1;
  5872. sum4 >>= 1;
  5873. RD = (sum1 & 0xFF) | ((sum2 & 0xFF) << 8) | ((sum3 & 0xFF) << 16) | ((sum4 & 0xFF) << 24);
  5874. }
  5875. }
  5876. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5877. INC_PC(sizeof(generic_arm_inst));
  5878. FETCH_INST;
  5879. GOTO_NEXT_INST;
  5880. }
  5881. UMAAL_INST:
  5882. {
  5883. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5884. umaal_inst* const inst_cream = (umaal_inst*)inst_base->component;
  5885. const u32 rm = RM;
  5886. const u32 rn = RN;
  5887. const u32 rd_lo = RDLO;
  5888. const u32 rd_hi = RDHI;
  5889. const u64 result = (rm * rn) + rd_lo + rd_hi;
  5890. RDLO = (result & 0xFFFFFFFF);
  5891. RDHI = ((result >> 32) & 0xFFFFFFFF);
  5892. }
  5893. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5894. INC_PC(sizeof(umaal_inst));
  5895. FETCH_INST;
  5896. GOTO_NEXT_INST;
  5897. }
  5898. UMLAL_INST:
  5899. {
  5900. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5901. umlal_inst *inst_cream = (umlal_inst *)inst_base->component;
  5902. unsigned long long int rm = RM;
  5903. unsigned long long int rs = RS;
  5904. unsigned long long int rst = rm * rs;
  5905. unsigned long long int add = ((unsigned long long) RDHI)<<32;
  5906. add += RDLO;
  5907. rst += add;
  5908. RDLO = BITS(rst, 0, 31);
  5909. RDHI = BITS(rst, 32, 63);
  5910. if (inst_cream->S) {
  5911. cpu->NFlag = BIT(RDHI, 31);
  5912. cpu->ZFlag = (RDHI == 0 && RDLO == 0);
  5913. }
  5914. }
  5915. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5916. INC_PC(sizeof(umlal_inst));
  5917. FETCH_INST;
  5918. GOTO_NEXT_INST;
  5919. }
  5920. UMULL_INST:
  5921. {
  5922. if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
  5923. umull_inst *inst_cream = (umull_inst *)inst_base->component;
  5924. unsigned long long int rm = RM;
  5925. unsigned long long int rs = RS;
  5926. unsigned long long int rst = rm * rs;
  5927. RDHI = BITS(rst, 32, 63);
  5928. RDLO = BITS(rst, 0, 31);
  5929. if (inst_cream->S) {
  5930. cpu->NFlag = BIT(RDHI, 31);
  5931. cpu->ZFlag = (RDHI == 0 && RDLO == 0);
  5932. }
  5933. }
  5934. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5935. INC_PC(sizeof(umull_inst));
  5936. FETCH_INST;
  5937. GOTO_NEXT_INST;
  5938. }
  5939. B_2_THUMB:
  5940. {
  5941. b_2_thumb *inst_cream = (b_2_thumb *)inst_base->component;
  5942. cpu->Reg[15] = cpu->Reg[15] + 4 + inst_cream->imm;
  5943. INC_PC(sizeof(b_2_thumb));
  5944. goto DISPATCH;
  5945. }
  5946. B_COND_THUMB:
  5947. {
  5948. b_cond_thumb *inst_cream = (b_cond_thumb *)inst_base->component;
  5949. if(CondPassed(cpu, inst_cream->cond))
  5950. cpu->Reg[15] = cpu->Reg[15] + 4 + inst_cream->imm;
  5951. else
  5952. cpu->Reg[15] += 2;
  5953. INC_PC(sizeof(b_cond_thumb));
  5954. goto DISPATCH;
  5955. }
  5956. BL_1_THUMB:
  5957. {
  5958. bl_1_thumb *inst_cream = (bl_1_thumb *)inst_base->component;
  5959. cpu->Reg[14] = cpu->Reg[15] + 4 + inst_cream->imm;
  5960. cpu->Reg[15] += GET_INST_SIZE(cpu);
  5961. INC_PC(sizeof(bl_1_thumb));
  5962. FETCH_INST;
  5963. GOTO_NEXT_INST;
  5964. }
  5965. BL_2_THUMB:
  5966. {
  5967. bl_2_thumb *inst_cream = (bl_2_thumb *)inst_base->component;
  5968. int tmp = ((cpu->Reg[15] + 2) | 1);
  5969. cpu->Reg[15] = (cpu->Reg[14] + inst_cream->imm);
  5970. cpu->Reg[14] = tmp;
  5971. INC_PC(sizeof(bl_2_thumb));
  5972. goto DISPATCH;
  5973. }
  5974. BLX_1_THUMB:
  5975. {
  5976. // BLX 1 for armv5t and above
  5977. u32 tmp = cpu->Reg[15];
  5978. blx_1_thumb *inst_cream = (blx_1_thumb *)inst_base->component;
  5979. cpu->Reg[15] = (cpu->Reg[14] + inst_cream->imm) & 0xFFFFFFFC;
  5980. cpu->Reg[14] = ((tmp + 2) | 1);
  5981. cpu->TFlag = 0;
  5982. INC_PC(sizeof(blx_1_thumb));
  5983. goto DISPATCH;
  5984. }
  5985. UQADD8_INST:
  5986. UQADD16_INST:
  5987. UQADDSUBX_INST:
  5988. UQSUB8_INST:
  5989. UQSUB16_INST:
  5990. UQSUBADDX_INST:
  5991. {
  5992. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  5993. generic_arm_inst* const inst_cream = (generic_arm_inst*)inst_base->component;
  5994. const u8 op2 = inst_cream->op2;
  5995. const u32 rm_val = RM;
  5996. const u32 rn_val = RN;
  5997. u16 lo_val = 0;
  5998. u16 hi_val = 0;
  5999. // UQADD16
  6000. if (op2 == 0x00) {
  6001. lo_val = ARMul_UnsignedSaturatedAdd16(rn_val & 0xFFFF, rm_val & 0xFFFF);
  6002. hi_val = ARMul_UnsignedSaturatedAdd16((rn_val >> 16) & 0xFFFF, (rm_val >> 16) & 0xFFFF);
  6003. }
  6004. // UQASX
  6005. else if (op2 == 0x01) {
  6006. lo_val = ARMul_UnsignedSaturatedSub16(rn_val & 0xFFFF, (rm_val >> 16) & 0xFFFF);
  6007. hi_val = ARMul_UnsignedSaturatedAdd16((rn_val >> 16) & 0xFFFF, rm_val & 0xFFFF);
  6008. }
  6009. // UQSAX
  6010. else if (op2 == 0x02) {
  6011. lo_val = ARMul_UnsignedSaturatedAdd16(rn_val & 0xFFFF, (rm_val >> 16) & 0xFFFF);
  6012. hi_val = ARMul_UnsignedSaturatedSub16((rn_val >> 16) & 0xFFFF, rm_val & 0xFFFF);
  6013. }
  6014. // UQSUB16
  6015. else if (op2 == 0x03) {
  6016. lo_val = ARMul_UnsignedSaturatedSub16(rn_val & 0xFFFF, rm_val & 0xFFFF);
  6017. hi_val = ARMul_UnsignedSaturatedSub16((rn_val >> 16) & 0xFFFF, (rm_val >> 16) & 0xFFFF);
  6018. }
  6019. // UQADD8
  6020. else if (op2 == 0x04) {
  6021. lo_val = ARMul_UnsignedSaturatedAdd8(rn_val, rm_val) |
  6022. ARMul_UnsignedSaturatedAdd8(rn_val >> 8, rm_val >> 8) << 8;
  6023. hi_val = ARMul_UnsignedSaturatedAdd8(rn_val >> 16, rm_val >> 16) |
  6024. ARMul_UnsignedSaturatedAdd8(rn_val >> 24, rm_val >> 24) << 8;
  6025. }
  6026. // UQSUB8
  6027. else {
  6028. lo_val = ARMul_UnsignedSaturatedSub8(rn_val, rm_val) |
  6029. ARMul_UnsignedSaturatedSub8(rn_val >> 8, rm_val >> 8) << 8;
  6030. hi_val = ARMul_UnsignedSaturatedSub8(rn_val >> 16, rm_val >> 16) |
  6031. ARMul_UnsignedSaturatedSub8(rn_val >> 24, rm_val >> 24) << 8;
  6032. }
  6033. RD = ((lo_val & 0xFFFF) | hi_val << 16);
  6034. }
  6035. cpu->Reg[15] += GET_INST_SIZE(cpu);
  6036. INC_PC(sizeof(generic_arm_inst));
  6037. FETCH_INST;
  6038. GOTO_NEXT_INST;
  6039. }
  6040. USAD8_INST:
  6041. USADA8_INST:
  6042. {
  6043. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  6044. generic_arm_inst* inst_cream = (generic_arm_inst*)inst_base->component;
  6045. const u8 ra_idx = inst_cream->Ra;
  6046. const u32 rm_val = RM;
  6047. const u32 rn_val = RN;
  6048. const u8 diff1 = ARMul_UnsignedAbsoluteDifference(rn_val & 0xFF, rm_val & 0xFF);
  6049. const u8 diff2 = ARMul_UnsignedAbsoluteDifference((rn_val >> 8) & 0xFF, (rm_val >> 8) & 0xFF);
  6050. const u8 diff3 = ARMul_UnsignedAbsoluteDifference((rn_val >> 16) & 0xFF, (rm_val >> 16) & 0xFF);
  6051. const u8 diff4 = ARMul_UnsignedAbsoluteDifference((rn_val >> 24) & 0xFF, (rm_val >> 24) & 0xFF);
  6052. u32 finalDif = (diff1 + diff2 + diff3 + diff4);
  6053. // Op is USADA8 if true.
  6054. if (ra_idx != 15)
  6055. finalDif += cpu->Reg[ra_idx];
  6056. RD = finalDif;
  6057. }
  6058. cpu->Reg[15] += GET_INST_SIZE(cpu);
  6059. INC_PC(sizeof(generic_arm_inst));
  6060. FETCH_INST;
  6061. GOTO_NEXT_INST;
  6062. }
  6063. USAT_INST:
  6064. {
  6065. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  6066. ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
  6067. u8 shift_type = inst_cream->shift_type;
  6068. u8 shift_amount = inst_cream->imm5;
  6069. u32 rn_val = RN;
  6070. // 32-bit ASR is encoded as an amount of 0.
  6071. if (shift_type == 1 && shift_amount == 0)
  6072. shift_amount = 31;
  6073. if (shift_type == 0)
  6074. rn_val <<= shift_amount;
  6075. else if (shift_type == 1)
  6076. rn_val = ((s32)rn_val >> shift_amount);
  6077. bool saturated = false;
  6078. rn_val = ARMul_UnsignedSatQ(rn_val, inst_cream->sat_imm, &saturated);
  6079. if (saturated)
  6080. cpu->Cpsr |= (1 << 27);
  6081. RD = rn_val;
  6082. }
  6083. cpu->Reg[15] += GET_INST_SIZE(cpu);
  6084. INC_PC(sizeof(ssat_inst));
  6085. FETCH_INST;
  6086. GOTO_NEXT_INST;
  6087. }
  6088. USAT16_INST:
  6089. {
  6090. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  6091. ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
  6092. const u8 saturate_to = inst_cream->sat_imm;
  6093. bool sat1 = false;
  6094. bool sat2 = false;
  6095. RD = (ARMul_UnsignedSatQ((s16)RN, saturate_to, &sat1) & 0xFFFF) |
  6096. ARMul_UnsignedSatQ((s32)RN >> 16, saturate_to, &sat2) << 16;
  6097. if (sat1 || sat2)
  6098. cpu->Cpsr |= (1 << 27);
  6099. }
  6100. cpu->Reg[15] += GET_INST_SIZE(cpu);
  6101. INC_PC(sizeof(ssat_inst));
  6102. FETCH_INST;
  6103. GOTO_NEXT_INST;
  6104. }
  6105. UXTAB16_INST:
  6106. UXTB16_INST:
  6107. {
  6108. if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
  6109. uxtab_inst* const inst_cream = (uxtab_inst*)inst_base->component;
  6110. const u8 rn_idx = inst_cream->Rn;
  6111. const u32 rm_val = RM;
  6112. const u32 rotation = inst_cream->rotate * 8;
  6113. const u32 rotated_rm = ((rm_val << (32 - rotation)) | (rm_val >> rotation));
  6114. // UXTB16, otherwise UXTAB16
  6115. if (rn_idx == 15) {
  6116. RD = rotated_rm & 0x00FF00FF;
  6117. } else {
  6118. const u32 rn_val = RN;
  6119. const u8 lo_rotated = (rotated_rm & 0xFF);
  6120. const u16 lo_result = (rn_val & 0xFFFF) + (u16)lo_rotated;
  6121. const u8 hi_rotated = (rotated_rm >> 16) & 0xFF;
  6122. const u16 hi_result = (rn_val >> 16) + (u16)hi_rotated;
  6123. RD = ((hi_result << 16) | (lo_result & 0xFFFF));
  6124. }
  6125. }
  6126. cpu->Reg[15] += GET_INST_SIZE(cpu);
  6127. INC_PC(sizeof(uxtab_inst));
  6128. FETCH_INST;
  6129. GOTO_NEXT_INST;
  6130. }
  6131. #define VFP_INTERPRETER_IMPL
  6132. #include "core/arm/skyeye_common/vfp/vfpinstr.cpp"
  6133. #undef VFP_INTERPRETER_IMPL
  6134. END:
  6135. {
  6136. SAVE_NZCVT;
  6137. cpu->NumInstrsToExecute = 0;
  6138. return num_instrs;
  6139. }
  6140. INIT_INST_LENGTH:
  6141. {
  6142. cpu->NumInstrsToExecute = 0;
  6143. return num_instrs;
  6144. }
  6145. }