arm_dyncom_interpreter.cpp 223 KB

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