arm_dyncom_interpreter.cpp 222 KB

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