arm_dyncom_interpreter.cpp 195 KB

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