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