arm_dyncom_interpreter.cpp 225 KB

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