arm_dyncom_interpreter.cpp 224 KB

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