arm_dyncom_interpreter.cpp 226 KB

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