arm_dyncom_interpreter.cpp 208 KB

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