arm_dyncom_interpreter.cpp 194 KB

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