arm_dyncom_interpreter.cpp 216 KB

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