arm_dyncom_interpreter.cpp 220 KB

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