armemu.cpp 225 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628
  1. /* armemu.c -- Main instruction emulation: ARM7 Instruction Emulator.
  2. Copyright (C) 1994 Advanced RISC Machines Ltd.
  3. Modifications to add arch. v4 support by <jsmith@cygnus.com>.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. #include "core/hle/hle.h"
  16. #include "arm_regformat.h"
  17. #include "armdefs.h"
  18. #include "armemu.h"
  19. #include "armos.h"
  20. #define ARMul_Debug(x,y,z) 0 // Disabling this /bunnei
  21. //#include "skyeye_callback.h"
  22. //#include "skyeye_bus.h"
  23. //#include "sim_control.h"
  24. //#include "skyeye_pref.h"
  25. //#include "skyeye.h"
  26. //#include "skyeye2gdb.h"
  27. //#include "code_cov.h"
  28. //#include "iwmmxt.h"
  29. //chy 2003-07-11: for debug instrs
  30. //extern int skyeye_instr_debug;
  31. extern FILE *skyeye_logfd;
  32. static ARMword GetDPRegRHS (ARMul_State *, ARMword);
  33. static ARMword GetDPSRegRHS (ARMul_State *, ARMword);
  34. static void WriteR15 (ARMul_State *, ARMword);
  35. static void WriteSR15 (ARMul_State *, ARMword);
  36. static void WriteR15Branch (ARMul_State *, ARMword);
  37. static ARMword GetLSRegRHS (ARMul_State *, ARMword);
  38. static ARMword GetLS7RHS (ARMul_State *, ARMword);
  39. static unsigned LoadWord (ARMul_State *, ARMword, ARMword);
  40. static unsigned LoadHalfWord (ARMul_State *, ARMword, ARMword, int);
  41. static unsigned LoadByte (ARMul_State *, ARMword, ARMword, int);
  42. static unsigned StoreWord (ARMul_State *, ARMword, ARMword);
  43. static unsigned StoreHalfWord (ARMul_State *, ARMword, ARMword);
  44. static unsigned StoreByte (ARMul_State *, ARMword, ARMword);
  45. static void LoadMult (ARMul_State *, ARMword, ARMword, ARMword);
  46. static void StoreMult (ARMul_State *, ARMword, ARMword, ARMword);
  47. static void LoadSMult (ARMul_State *, ARMword, ARMword, ARMword);
  48. static void StoreSMult (ARMul_State *, ARMword, ARMword, ARMword);
  49. static unsigned Multiply64 (ARMul_State *, ARMword, int, int);
  50. static unsigned MultiplyAdd64 (ARMul_State *, ARMword, int, int);
  51. static void Handle_Load_Double (ARMul_State *, ARMword);
  52. static void Handle_Store_Double (ARMul_State *, ARMword);
  53. void
  54. XScale_set_fsr_far (ARMul_State * state, ARMword fsr, ARMword _far);
  55. int
  56. XScale_debug_moe (ARMul_State * state, int moe);
  57. unsigned xscale_cp15_cp_access_allowed (ARMul_State * state, unsigned reg,
  58. unsigned cpnum);
  59. static int
  60. handle_v6_insn (ARMul_State * state, ARMword instr);
  61. #define LUNSIGNED (0) /* unsigned operation */
  62. #define LSIGNED (1) /* signed operation */
  63. #define LDEFAULT (0) /* default : do nothing */
  64. #define LSCC (1) /* set condition codes on result */
  65. #ifdef NEED_UI_LOOP_HOOK
  66. /* How often to run the ui_loop update, when in use. */
  67. #define UI_LOOP_POLL_INTERVAL 0x32000
  68. /* Counter for the ui_loop_hook update. */
  69. static int ui_loop_hook_counter = UI_LOOP_POLL_INTERVAL;
  70. /* Actual hook to call to run through gdb's gui event loop. */
  71. extern int (*ui_loop_hook) (int);
  72. #endif /* NEED_UI_LOOP_HOOK */
  73. /* Short-hand macros for LDR/STR. */
  74. /* Store post decrement writeback. */
  75. #define SHDOWNWB() \
  76. lhs = LHS ; \
  77. if (StoreHalfWord (state, instr, lhs)) \
  78. LSBase = lhs - GetLS7RHS (state, instr);
  79. /* Store post increment writeback. */
  80. #define SHUPWB() \
  81. lhs = LHS ; \
  82. if (StoreHalfWord (state, instr, lhs)) \
  83. LSBase = lhs + GetLS7RHS (state, instr);
  84. /* Store pre decrement. */
  85. #define SHPREDOWN() \
  86. (void)StoreHalfWord (state, instr, LHS - GetLS7RHS (state, instr));
  87. /* Store pre decrement writeback. */
  88. #define SHPREDOWNWB() \
  89. temp = LHS - GetLS7RHS (state, instr); \
  90. if (StoreHalfWord (state, instr, temp)) \
  91. LSBase = temp;
  92. /* Store pre increment. */
  93. #define SHPREUP() \
  94. (void)StoreHalfWord (state, instr, LHS + GetLS7RHS (state, instr));
  95. /* Store pre increment writeback. */
  96. #define SHPREUPWB() \
  97. temp = LHS + GetLS7RHS (state, instr); \
  98. if (StoreHalfWord (state, instr, temp)) \
  99. LSBase = temp;
  100. /* Load post decrement writeback. */
  101. #define LHPOSTDOWN() \
  102. { \
  103. int done = 1; \
  104. lhs = LHS; \
  105. temp = lhs - GetLS7RHS (state, instr); \
  106. \
  107. switch (BITS (5, 6)) \
  108. { \
  109. case 1: /* H */ \
  110. if (LoadHalfWord (state, instr, lhs, LUNSIGNED)) \
  111. LSBase = temp; \
  112. break; \
  113. case 2: /* SB */ \
  114. if (LoadByte (state, instr, lhs, LSIGNED)) \
  115. LSBase = temp; \
  116. break; \
  117. case 3: /* SH */ \
  118. if (LoadHalfWord (state, instr, lhs, LSIGNED)) \
  119. LSBase = temp; \
  120. break; \
  121. case 0: /* SWP handled elsewhere. */ \
  122. default: \
  123. done = 0; \
  124. break; \
  125. } \
  126. if (done) \
  127. break; \
  128. }
  129. /* Load post increment writeback. */
  130. #define LHPOSTUP() \
  131. { \
  132. int done = 1; \
  133. lhs = LHS; \
  134. temp = lhs + GetLS7RHS (state, instr); \
  135. \
  136. switch (BITS (5, 6)) \
  137. { \
  138. case 1: /* H */ \
  139. if (LoadHalfWord (state, instr, lhs, LUNSIGNED)) \
  140. LSBase = temp; \
  141. break; \
  142. case 2: /* SB */ \
  143. if (LoadByte (state, instr, lhs, LSIGNED)) \
  144. LSBase = temp; \
  145. break; \
  146. case 3: /* SH */ \
  147. if (LoadHalfWord (state, instr, lhs, LSIGNED)) \
  148. LSBase = temp; \
  149. break; \
  150. case 0: /* SWP handled elsewhere. */ \
  151. default: \
  152. done = 0; \
  153. break; \
  154. } \
  155. if (done) \
  156. break; \
  157. }
  158. /* Load pre decrement. */
  159. #define LHPREDOWN() \
  160. { \
  161. int done = 1; \
  162. \
  163. temp = LHS - GetLS7RHS (state, instr); \
  164. switch (BITS (5, 6)) \
  165. { \
  166. case 1: /* H */ \
  167. (void) LoadHalfWord (state, instr, temp, LUNSIGNED); \
  168. break; \
  169. case 2: /* SB */ \
  170. (void) LoadByte (state, instr, temp, LSIGNED); \
  171. break; \
  172. case 3: /* SH */ \
  173. (void) LoadHalfWord (state, instr, temp, LSIGNED); \
  174. break; \
  175. case 0: \
  176. /* SWP handled elsewhere. */ \
  177. default: \
  178. done = 0; \
  179. break; \
  180. } \
  181. if (done) \
  182. break; \
  183. }
  184. /* Load pre decrement writeback. */
  185. #define LHPREDOWNWB() \
  186. { \
  187. int done = 1; \
  188. \
  189. temp = LHS - GetLS7RHS (state, instr); \
  190. switch (BITS (5, 6)) \
  191. { \
  192. case 1: /* H */ \
  193. if (LoadHalfWord (state, instr, temp, LUNSIGNED)) \
  194. LSBase = temp; \
  195. break; \
  196. case 2: /* SB */ \
  197. if (LoadByte (state, instr, temp, LSIGNED)) \
  198. LSBase = temp; \
  199. break; \
  200. case 3: /* SH */ \
  201. if (LoadHalfWord (state, instr, temp, LSIGNED)) \
  202. LSBase = temp; \
  203. break; \
  204. case 0: \
  205. /* SWP handled elsewhere. */ \
  206. default: \
  207. done = 0; \
  208. break; \
  209. } \
  210. if (done) \
  211. break; \
  212. }
  213. /* Load pre increment. */
  214. #define LHPREUP() \
  215. { \
  216. int done = 1; \
  217. \
  218. temp = LHS + GetLS7RHS (state, instr); \
  219. switch (BITS (5, 6)) \
  220. { \
  221. case 1: /* H */ \
  222. (void) LoadHalfWord (state, instr, temp, LUNSIGNED); \
  223. break; \
  224. case 2: /* SB */ \
  225. (void) LoadByte (state, instr, temp, LSIGNED); \
  226. break; \
  227. case 3: /* SH */ \
  228. (void) LoadHalfWord (state, instr, temp, LSIGNED); \
  229. break; \
  230. case 0: \
  231. /* SWP handled elsewhere. */ \
  232. default: \
  233. done = 0; \
  234. break; \
  235. } \
  236. if (done) \
  237. break; \
  238. }
  239. /* Load pre increment writeback. */
  240. #define LHPREUPWB() \
  241. { \
  242. int done = 1; \
  243. \
  244. temp = LHS + GetLS7RHS (state, instr); \
  245. switch (BITS (5, 6)) \
  246. { \
  247. case 1: /* H */ \
  248. if (LoadHalfWord (state, instr, temp, LUNSIGNED)) \
  249. LSBase = temp; \
  250. break; \
  251. case 2: /* SB */ \
  252. if (LoadByte (state, instr, temp, LSIGNED)) \
  253. LSBase = temp; \
  254. break; \
  255. case 3: /* SH */ \
  256. if (LoadHalfWord (state, instr, temp, LSIGNED)) \
  257. LSBase = temp; \
  258. break; \
  259. case 0: \
  260. /* SWP handled elsewhere. */ \
  261. default: \
  262. done = 0; \
  263. break; \
  264. } \
  265. if (done) \
  266. break; \
  267. }
  268. /*ywc 2005-03-31*/
  269. //teawater add for arm2x86 2005.02.17-------------------------------------------
  270. #ifdef DBCT
  271. #include "dbct/tb.h"
  272. #include "dbct/arm2x86_self.h"
  273. #endif
  274. //AJ2D--------------------------------------------------------------------------
  275. //Diff register
  276. unsigned int mirror_register_file[39];
  277. /* EMULATION of ARM6. */
  278. /* The PC pipeline value depends on whether ARM
  279. or Thumb instructions are being executed. */
  280. ARMword isize;
  281. extern int debugmode;
  282. int ARMul_ICE_debug(ARMul_State *state,ARMword instr,ARMword addr);
  283. #ifdef MODE32
  284. //chy 2006-04-12, for ICE debug
  285. int ARMul_ICE_debug(ARMul_State *state,ARMword instr,ARMword addr)
  286. {
  287. int i;
  288. #if 0
  289. if (debugmode) {
  290. if (instr == ARMul_ABORTWORD) return 0;
  291. for (i = 0; i < skyeye_ice.num_bps; i++) {
  292. if (skyeye_ice.bps[i] == addr) {
  293. //for test
  294. //printf("SKYEYE: ICE_debug bps [%d]== 0x%x\n", i,addr);
  295. state->EndCondition = 0;
  296. state->Emulate = STOP;
  297. return 1;
  298. }
  299. }
  300. if (skyeye_ice.tps_status==TRACE_STARTED)
  301. {
  302. for (i = 0; i < skyeye_ice.num_tps; i++)
  303. {
  304. if (((skyeye_ice.tps[i].tp_address==addr)&&(skyeye_ice.tps[i].status==TRACEPOINT_ENABLED))||(skyeye_ice.tps[i].status==TRACEPOINT_STEPPING))
  305. {
  306. handle_tracepoint(i);
  307. }
  308. }
  309. }
  310. }
  311. /* do profiling for code coverage */
  312. if (skyeye_config.code_cov.prof_on)
  313. cov_prof(EXEC_FLAG, addr);
  314. #endif
  315. /* chech if we need to run some callback functions at this time */
  316. //generic_arch_t* arch_instance = get_arch_instance("");
  317. //exec_callback(Step_callback, arch_instance);
  318. //if (!SIM_is_running()) {
  319. // if (instr == ARMul_ABORTWORD) return 0;
  320. // state->EndCondition = 0;
  321. // state->Emulate = STOP;
  322. // return 1;
  323. //}
  324. return 0;
  325. }
  326. /*
  327. void chy_debug()
  328. {
  329. printf("SkyEye chy_deubeg begin\n");
  330. }
  331. */
  332. ARMword
  333. ARMul_Emulate32 (ARMul_State * state)
  334. #else
  335. ARMword
  336. ARMul_Emulate26 (ARMul_State * state)
  337. #endif
  338. {
  339. ARMword instr; /* The current instruction. */
  340. ARMword dest = 0; /* Almost the DestBus. */
  341. ARMword temp; /* Ubiquitous third hand. */
  342. ARMword pc = 0; /* The address of the current instruction. */
  343. ARMword lhs; /* Almost the ABus and BBus. */
  344. ARMword rhs;
  345. ARMword decoded = 0; /* Instruction pipeline. */
  346. ARMword loaded = 0;
  347. ARMword decoded_addr=0;
  348. ARMword loaded_addr=0;
  349. ARMword have_bp=0;
  350. /* shenoubang */
  351. static int instr_sum = 0;
  352. int reg_index = 0;
  353. #if DIFF_STATE
  354. //initialize all mirror register for follow mode
  355. for (reg_index = 0; reg_index < 16; reg_index ++) {
  356. mirror_register_file[reg_index] = state->Reg[reg_index];
  357. }
  358. mirror_register_file[CPSR_REG] = state->Cpsr;
  359. mirror_register_file[R13_SVC] = state->RegBank[SVCBANK][13];
  360. mirror_register_file[R14_SVC] = state->RegBank[SVCBANK][14];
  361. mirror_register_file[R13_ABORT] = state->RegBank[ABORTBANK][13];
  362. mirror_register_file[R14_ABORT] = state->RegBank[ABORTBANK][14];
  363. mirror_register_file[R13_UNDEF] = state->RegBank[UNDEFBANK][13];
  364. mirror_register_file[R14_UNDEF] = state->RegBank[UNDEFBANK][14];
  365. mirror_register_file[R13_IRQ] = state->RegBank[IRQBANK][13];
  366. mirror_register_file[R14_IRQ] = state->RegBank[IRQBANK][14];
  367. mirror_register_file[R8_FIRQ] = state->RegBank[FIQBANK][8];
  368. mirror_register_file[R9_FIRQ] = state->RegBank[FIQBANK][9];
  369. mirror_register_file[R10_FIRQ] = state->RegBank[FIQBANK][10];
  370. mirror_register_file[R11_FIRQ] = state->RegBank[FIQBANK][11];
  371. mirror_register_file[R12_FIRQ] = state->RegBank[FIQBANK][12];
  372. mirror_register_file[R13_FIRQ] = state->RegBank[FIQBANK][13];
  373. mirror_register_file[R14_FIRQ] = state->RegBank[FIQBANK][14];
  374. mirror_register_file[SPSR_SVC] = state->Spsr[SVCBANK];
  375. mirror_register_file[SPSR_ABORT] = state->Spsr[ABORTBANK];
  376. mirror_register_file[SPSR_UNDEF] = state->Spsr[UNDEFBANK];
  377. mirror_register_file[SPSR_IRQ] = state->Spsr[IRQBANK];
  378. mirror_register_file[SPSR_FIRQ] = state->Spsr[FIQBANK];
  379. #endif
  380. /* Execute the next instruction. */
  381. if (state->NextInstr < PRIMEPIPE) {
  382. decoded = state->decoded;
  383. loaded = state->loaded;
  384. pc = state->pc;
  385. //chy 2006-04-12, for ICE debug
  386. decoded_addr=state->decoded_addr;
  387. loaded_addr=state->loaded_addr;
  388. }
  389. do {
  390. //print_func_name(state->pc);
  391. /* Just keep going. */
  392. isize = INSN_SIZE;
  393. switch (state->NextInstr) {
  394. case SEQ:
  395. /* Advance the pipeline, and an S cycle. */
  396. state->Reg[15] += isize;
  397. pc += isize;
  398. instr = decoded;
  399. //chy 2006-04-12, for ICE debug
  400. have_bp = ARMul_ICE_debug(state,instr,decoded_addr);
  401. decoded = loaded;
  402. decoded_addr=loaded_addr;
  403. //loaded = ARMul_LoadInstrS (state, pc + (isize * 2),
  404. // isize);
  405. loaded_addr=pc + (isize * 2);
  406. if (have_bp) goto TEST_EMULATE;
  407. break;
  408. case NONSEQ:
  409. /* Advance the pipeline, and an N cycle. */
  410. state->Reg[15] += isize;
  411. pc += isize;
  412. instr = decoded;
  413. //chy 2006-04-12, for ICE debug
  414. have_bp=ARMul_ICE_debug(state,instr,decoded_addr);
  415. decoded = loaded;
  416. decoded_addr=loaded_addr;
  417. //loaded = ARMul_LoadInstrN (state, pc + (isize * 2),
  418. // isize);
  419. loaded_addr=pc + (isize * 2);
  420. NORMALCYCLE;
  421. if (have_bp) goto TEST_EMULATE;
  422. break;
  423. case PCINCEDSEQ:
  424. /* Program counter advanced, and an S cycle. */
  425. pc += isize;
  426. instr = decoded;
  427. //chy 2006-04-12, for ICE debug
  428. have_bp=ARMul_ICE_debug(state,instr,decoded_addr);
  429. decoded = loaded;
  430. decoded_addr=loaded_addr;
  431. //loaded = ARMul_LoadInstrS (state, pc + (isize * 2),
  432. // isize);
  433. loaded_addr=pc + (isize * 2);
  434. NORMALCYCLE;
  435. if (have_bp) goto TEST_EMULATE;
  436. break;
  437. case PCINCEDNONSEQ:
  438. /* Program counter advanced, and an N cycle. */
  439. pc += isize;
  440. instr = decoded;
  441. //chy 2006-04-12, for ICE debug
  442. have_bp=ARMul_ICE_debug(state,instr,decoded_addr);
  443. decoded = loaded;
  444. decoded_addr=loaded_addr;
  445. //loaded = ARMul_LoadInstrN (state, pc + (isize * 2),
  446. // isize);
  447. loaded_addr=pc + (isize * 2);
  448. NORMALCYCLE;
  449. if (have_bp) goto TEST_EMULATE;
  450. break;
  451. case RESUME:
  452. /* The program counter has been changed. */
  453. pc = state->Reg[15];
  454. #ifndef MODE32
  455. pc = pc & R15PCBITS;
  456. #endif
  457. state->Reg[15] = pc + (isize * 2);
  458. state->Aborted = 0;
  459. //chy 2004-05-25, fix bug provided by Carl van Schaik<cvansch@cse.unsw.EDU.AU>
  460. state->AbortAddr = 1;
  461. instr = ARMul_LoadInstrN (state, pc, isize);
  462. //instr = ARMul_ReLoadInstr (state, pc, isize);
  463. //chy 2006-04-12, for ICE debug
  464. have_bp=ARMul_ICE_debug(state,instr,pc);
  465. //decoded =
  466. // ARMul_ReLoadInstr (state, pc + isize, isize);
  467. decoded_addr=pc+isize;
  468. //loaded = ARMul_ReLoadInstr (state, pc + isize * 2,
  469. // isize);
  470. loaded_addr=pc + isize * 2;
  471. NORMALCYCLE;
  472. if (have_bp) goto TEST_EMULATE;
  473. break;
  474. default:
  475. /* The program counter has been changed. */
  476. pc = state->Reg[15];
  477. #ifndef MODE32
  478. pc = pc & R15PCBITS;
  479. #endif
  480. state->Reg[15] = pc + (isize * 2);
  481. state->Aborted = 0;
  482. //chy 2004-05-25, fix bug provided by Carl van Schaik<cvansch@cse.unsw.EDU.AU>
  483. state->AbortAddr = 1;
  484. instr = ARMul_LoadInstrN (state, pc, isize);
  485. //chy 2006-04-12, for ICE debug
  486. have_bp=ARMul_ICE_debug(state,instr,pc);
  487. #if 0
  488. decoded =
  489. ARMul_LoadInstrS (state, pc + (isize), isize);
  490. #endif
  491. decoded_addr=pc+isize;
  492. #if 0
  493. loaded = ARMul_LoadInstrS (state, pc + (isize * 2),
  494. isize);
  495. #endif
  496. loaded_addr=pc + isize * 2;
  497. NORMALCYCLE;
  498. if (have_bp) goto TEST_EMULATE;
  499. break;
  500. }
  501. #if 0
  502. int idx = 0;
  503. printf("pc:%x\n", pc);
  504. for (;idx < 17; idx ++) {
  505. printf("R%d:%x\t", idx, state->Reg[idx]);
  506. }
  507. printf("\n");
  508. #endif
  509. instr = ARMul_LoadInstrN (state, pc, isize);
  510. state->last_instr = state->CurrInstr;
  511. state->CurrInstr = instr;
  512. #if 0
  513. if((state->NumInstrs % 10000000) == 0)
  514. printf("---|%p|--- %lld\n", pc, state->NumInstrs);
  515. if(state->NumInstrs > (3000000000)){
  516. static int flag = 0;
  517. if(pc == 0x8032ccc4){
  518. flag = 300;
  519. }
  520. if(flag){
  521. int idx = 0;
  522. printf("------------------------------------\n");
  523. printf("pc:%x\n", pc);
  524. for (;idx < 17; idx ++) {
  525. printf("R%d:%x\t", idx, state->Reg[idx]);
  526. }
  527. printf("\nN:%d\t Z:%d\t C:%d\t V:%d\n", state->NFlag, state->ZFlag, state->CFlag, state->VFlag);
  528. printf("\n");
  529. printf("------------------------------------\n");
  530. flag--;
  531. }
  532. }
  533. #endif
  534. #if DIFF_STATE
  535. fprintf(state->state_log, "PC:0x%x\n", pc);
  536. if (pc && (pc + 8) != state->Reg[15]) {
  537. printf("lucky dog\n");
  538. printf("pc is %x, R15 is %x\n", pc, state->Reg[15]);
  539. //exit(-1);
  540. }
  541. for (reg_index = 0; reg_index < 16; reg_index ++) {
  542. if (state->Reg[reg_index] != mirror_register_file[reg_index]) {
  543. fprintf(state->state_log, "R%d:0x%x\n", reg_index, state->Reg[reg_index]);
  544. mirror_register_file[reg_index] = state->Reg[reg_index];
  545. }
  546. }
  547. if (state->Cpsr != mirror_register_file[CPSR_REG]) {
  548. fprintf(state->state_log, "Cpsr:0x%x\n", state->Cpsr);
  549. mirror_register_file[CPSR_REG] = state->Cpsr;
  550. }
  551. if (state->RegBank[SVCBANK][13] != mirror_register_file[R13_SVC]) {
  552. fprintf(state->state_log, "R13_SVC:0x%x\n", state->RegBank[SVCBANK][13]);
  553. mirror_register_file[R13_SVC] = state->RegBank[SVCBANK][13];
  554. }
  555. if (state->RegBank[SVCBANK][14] != mirror_register_file[R14_SVC]) {
  556. fprintf(state->state_log, "R14_SVC:0x%x\n", state->RegBank[SVCBANK][14]);
  557. mirror_register_file[R14_SVC] = state->RegBank[SVCBANK][14];
  558. }
  559. if (state->RegBank[ABORTBANK][13] != mirror_register_file[R13_ABORT]) {
  560. fprintf(state->state_log, "R13_ABORT:0x%x\n", state->RegBank[ABORTBANK][13]);
  561. mirror_register_file[R13_ABORT] = state->RegBank[ABORTBANK][13];
  562. }
  563. if (state->RegBank[ABORTBANK][14] != mirror_register_file[R14_ABORT]) {
  564. fprintf(state->state_log, "R14_ABORT:0x%x\n", state->RegBank[ABORTBANK][14]);
  565. mirror_register_file[R14_ABORT] = state->RegBank[ABORTBANK][14];
  566. }
  567. if (state->RegBank[UNDEFBANK][13] != mirror_register_file[R13_UNDEF]) {
  568. fprintf(state->state_log, "R13_UNDEF:0x%x\n", state->RegBank[UNDEFBANK][13]);
  569. mirror_register_file[R13_UNDEF] = state->RegBank[UNDEFBANK][13];
  570. }
  571. if (state->RegBank[UNDEFBANK][14] != mirror_register_file[R14_UNDEF]) {
  572. fprintf(state->state_log, "R14_UNDEF:0x%x\n", state->RegBank[UNDEFBANK][14]);
  573. mirror_register_file[R14_UNDEF] = state->RegBank[UNDEFBANK][14];
  574. }
  575. if (state->RegBank[IRQBANK][13] != mirror_register_file[R13_IRQ]) {
  576. fprintf(state->state_log, "R13_IRQ:0x%x\n", state->RegBank[IRQBANK][13]);
  577. mirror_register_file[R13_IRQ] = state->RegBank[IRQBANK][13];
  578. }
  579. if (state->RegBank[IRQBANK][14] != mirror_register_file[R14_IRQ]) {
  580. fprintf(state->state_log, "R14_IRQ:0x%x\n", state->RegBank[IRQBANK][14]);
  581. mirror_register_file[R14_IRQ] = state->RegBank[IRQBANK][14];
  582. }
  583. if (state->RegBank[FIQBANK][8] != mirror_register_file[R8_FIRQ]) {
  584. fprintf(state->state_log, "R8_FIRQ:0x%x\n", state->RegBank[FIQBANK][8]);
  585. mirror_register_file[R8_FIRQ] = state->RegBank[FIQBANK][8];
  586. }
  587. if (state->RegBank[FIQBANK][9] != mirror_register_file[R9_FIRQ]) {
  588. fprintf(state->state_log, "R9_FIRQ:0x%x\n", state->RegBank[FIQBANK][9]);
  589. mirror_register_file[R9_FIRQ] = state->RegBank[FIQBANK][9];
  590. }
  591. if (state->RegBank[FIQBANK][10] != mirror_register_file[R10_FIRQ]) {
  592. fprintf(state->state_log, "R10_FIRQ:0x%x\n", state->RegBank[FIQBANK][10]);
  593. mirror_register_file[R10_FIRQ] = state->RegBank[FIQBANK][10];
  594. }
  595. if (state->RegBank[FIQBANK][11] != mirror_register_file[R11_FIRQ]) {
  596. fprintf(state->state_log, "R11_FIRQ:0x%x\n", state->RegBank[FIQBANK][11]);
  597. mirror_register_file[R11_FIRQ] = state->RegBank[FIQBANK][11];
  598. }
  599. if (state->RegBank[FIQBANK][12] != mirror_register_file[R12_FIRQ]) {
  600. fprintf(state->state_log, "R12_FIRQ:0x%x\n", state->RegBank[FIQBANK][12]);
  601. mirror_register_file[R12_FIRQ] = state->RegBank[FIQBANK][12];
  602. }
  603. if (state->RegBank[FIQBANK][13] != mirror_register_file[R13_FIRQ]) {
  604. fprintf(state->state_log, "R13_FIRQ:0x%x\n", state->RegBank[FIQBANK][13]);
  605. mirror_register_file[R13_FIRQ] = state->RegBank[FIQBANK][13];
  606. }
  607. if (state->RegBank[FIQBANK][14] != mirror_register_file[R14_FIRQ]) {
  608. fprintf(state->state_log, "R14_FIRQ:0x%x\n", state->RegBank[FIQBANK][14]);
  609. mirror_register_file[R14_FIRQ] = state->RegBank[FIQBANK][14];
  610. }
  611. if (state->Spsr[SVCBANK] != mirror_register_file[SPSR_SVC]) {
  612. fprintf(state->state_log, "SPSR_SVC:0x%x\n", state->Spsr[SVCBANK]);
  613. mirror_register_file[SPSR_SVC] = state->RegBank[SVCBANK];
  614. }
  615. if (state->Spsr[ABORTBANK] != mirror_register_file[SPSR_ABORT]) {
  616. fprintf(state->state_log, "SPSR_ABORT:0x%x\n", state->Spsr[ABORTBANK]);
  617. mirror_register_file[SPSR_ABORT] = state->RegBank[ABORTBANK];
  618. }
  619. if (state->Spsr[UNDEFBANK] != mirror_register_file[SPSR_UNDEF]) {
  620. fprintf(state->state_log, "SPSR_UNDEF:0x%x\n", state->Spsr[UNDEFBANK]);
  621. mirror_register_file[SPSR_UNDEF] = state->RegBank[UNDEFBANK];
  622. }
  623. if (state->Spsr[IRQBANK] != mirror_register_file[SPSR_IRQ]) {
  624. fprintf(state->state_log, "SPSR_IRQ:0x%x\n", state->Spsr[IRQBANK]);
  625. mirror_register_file[SPSR_IRQ] = state->RegBank[IRQBANK];
  626. }
  627. if (state->Spsr[FIQBANK] != mirror_register_file[SPSR_FIRQ]) {
  628. fprintf(state->state_log, "SPSR_FIRQ:0x%x\n", state->Spsr[FIQBANK]);
  629. mirror_register_file[SPSR_FIRQ] = state->RegBank[FIQBANK];
  630. }
  631. #endif
  632. #if 0
  633. uint32_t alex = 0;
  634. static int flagged = 0;
  635. if ((flagged == 0) && (pc == 0xb224))
  636. {
  637. flagged++;
  638. }
  639. if ((flagged == 1) && (pc == 0x1a800))
  640. {
  641. flagged++;
  642. }
  643. if (flagged == 3) {
  644. printf("---|%p|--- %x\n", pc, state->NumInstrs);
  645. for (alex = 0; alex < 15; alex++)
  646. {
  647. printf("R%02d % 8x\n", alex, state->Reg[alex]);
  648. }
  649. printf("R%02d % 8x\n", alex, state->Reg[alex] - 8);
  650. printf("CPS %x%07x\n", (state->NFlag<<3 | state->ZFlag<<2 | state->CFlag<<1 | state->VFlag), state->Cpsr & 0xfffffff);
  651. } else {
  652. if (state->NumInstrs < 0x400000)
  653. {
  654. //exit(-1);
  655. }
  656. }
  657. #endif
  658. if (state->EventSet)
  659. ARMul_EnvokeEvent (state);
  660. #if 0
  661. /* do profiling for code coverage */
  662. if (skyeye_config.code_cov.prof_on)
  663. cov_prof(EXEC_FLAG, pc);
  664. #endif
  665. //2003-07-11 chy: for test
  666. #if 0
  667. if (skyeye_config.log.logon >= 1) {
  668. if (state->NumInstrs >= skyeye_config.log.start &&
  669. state->NumInstrs <= skyeye_config.log.end) {
  670. static int mybegin = 0;
  671. static int myinstrnum = 0;
  672. if (mybegin == 0)
  673. mybegin = 1;
  674. #if 0
  675. if (state->NumInstrs == 3695) {
  676. printf ("***********SKYEYE: numinstr = 3695\n");
  677. }
  678. static int mybeg2 = 0;
  679. static int mybeg3 = 0;
  680. static int mybeg4 = 0;
  681. static int mybeg5 = 0;
  682. if (pc == 0xa0008000) {
  683. //mybegin=1;
  684. printf ("************SKYEYE: real vmlinux begin now numinstr is %llu ****************\n", state->NumInstrs);
  685. }
  686. //chy 2003-09-02 test fiq
  687. if (state->NumInstrs == 67347000) {
  688. printf ("***********SKYEYE: numinstr = 67347000, begin log\n");
  689. mybegin = 1;
  690. }
  691. if (pc == 0xc00087b4) { //numinstr=67348714
  692. mybegin = 1;
  693. printf ("************SKYEYE: test irq now numinstr is %llu ****************\n", state->NumInstrs);
  694. }
  695. if (pc == 0xc00087b8) { //in start_kernel::sti()
  696. mybeg4 = 1;
  697. printf ("************SKYEYE: startkerenl: sti now numinstr is %llu ********\n", state->NumInstrs);
  698. }
  699. /*if (pc==0xc001e4f4||pc==0xc001e4f8||pc==0xc001e4fc||pc==0xc001e500||pc==0xffff0004) { //MRA instr */
  700. if (pc == 0xc001e500) { //MRA instr
  701. mybeg5 = 1;
  702. printf ("************SKYEYE: MRA instr now numinstr is %llu ********\n", state->NumInstrs);
  703. }
  704. if (pc >= 0xc0000000 && mybeg2 == 0) {
  705. mybeg2 = 1;
  706. printf ("************SKYEYE: enable mmu&cache, now numinstr is %llu **************\n", state->NumInstrs);
  707. SKYEYE_OUTREGS (stderr);
  708. printf ("************************************************************************\n");
  709. }
  710. //chy 2003-09-01 test after tlb-flush
  711. if (pc == 0xc00261ac) {
  712. //sleep(2);
  713. mybeg3 = 1;
  714. printf ("************SKYEYE: after tlb-flush numinstr is %llu ****************\n", state->NumInstrs);
  715. }
  716. if (mybeg3 == 1) {
  717. SKYEYE_OUTREGS (skyeye_logfd);
  718. SKYEYE_OUTMOREREGS (skyeye_logfd);
  719. fprintf (skyeye_logfd, "\n");
  720. }
  721. #endif
  722. if (mybegin == 1) {
  723. //fprintf(skyeye_logfd,"p %x,i %x,d %x,l %x,",pc,instr,decoded,loaded);
  724. //chy for test 20050729
  725. /*if (state->NumInstrs>=3302294) {
  726. if (pc==0x100c9d4 && instr==0xe1b0f00e){
  727. chy_debug();
  728. printf("*********************************************\n");
  729. printf("******SKYEYE N %llx :p %x,i %x\n SKYEYE******\n",state->NumInstrs,pc,instr);
  730. printf("*********************************************\n");
  731. }
  732. */
  733. if (skyeye_config.log.logon >= 1)
  734. /*
  735. fprintf (skyeye_logfd,
  736. "N %llx :p %x,i %x,",
  737. state->NumInstrs, pc,
  738. #ifdef MODET
  739. TFLAG ? instr & 0xffff : instr
  740. #else
  741. instr
  742. #endif
  743. );
  744. */
  745. fprintf(skyeye_logfd, "pc=0x%x,r3=0x%x\n", pc, state->Reg[3]);
  746. if (skyeye_config.log.logon >= 2)
  747. SKYEYE_OUTREGS (skyeye_logfd);
  748. if (skyeye_config.log.logon >= 3)
  749. SKYEYE_OUTMOREREGS
  750. (skyeye_logfd);
  751. //fprintf (skyeye_logfd, "\n");
  752. if (skyeye_config.log.length > 0) {
  753. myinstrnum++;
  754. if (myinstrnum >=
  755. skyeye_config.log.
  756. length) {
  757. myinstrnum = 0;
  758. fflush (skyeye_logfd);
  759. fseek (skyeye_logfd,
  760. 0L, SEEK_SET);
  761. }
  762. }
  763. }
  764. //SKYEYE_OUTREGS(skyeye_logfd);
  765. //SKYEYE_OUTMOREREGS(skyeye_logfd);
  766. }
  767. }
  768. #endif
  769. #if 0 /* Enable this for a helpful bit of debugging when tracing is needed. */
  770. fprintf (stderr, "pc: %x, instr: %x\n", pc & ~1, instr);
  771. if (instr == 0)
  772. abort ();
  773. #endif
  774. #if 0 /* Enable this code to help track down stack alignment bugs. */
  775. {
  776. static ARMword old_sp = -1;
  777. if (old_sp != state->Reg[13]) {
  778. old_sp = state->Reg[13];
  779. fprintf (stderr,
  780. "pc: %08x: SP set to %08x%s\n",
  781. pc & ~1, old_sp,
  782. (old_sp % 8) ? " [UNALIGNED!]" : "");
  783. }
  784. }
  785. #endif
  786. /* Any exceptions ? */
  787. if (state->NresetSig == LOW) {
  788. ARMul_Abort (state, ARMul_ResetV);
  789. /*added energy_prof statement by ksh in 2004-11-26 */
  790. //chy 2005-07-28 for standalone
  791. //ARMul_do_energy(state,instr,pc);
  792. break;
  793. }
  794. else if (!state->NfiqSig && !FFLAG) {
  795. ARMul_Abort (state, ARMul_FIQV);
  796. /*added energy_prof statement by ksh in 2004-11-26 */
  797. //chy 2005-07-28 for standalone
  798. //ARMul_do_energy(state,instr,pc);
  799. break;
  800. }
  801. else if (!state->NirqSig && !IFLAG) {
  802. ARMul_Abort (state, ARMul_IRQV);
  803. /*added energy_prof statement by ksh in 2004-11-26 */
  804. //chy 2005-07-28 for standalone
  805. //ARMul_do_energy(state,instr,pc);
  806. break;
  807. }
  808. //teawater add for arm2x86 2005.04.26-------------------------------------------
  809. #if 0
  810. // if (state->pc == 0xc011a868 || state->pc == 0xc011a86c) {
  811. if (state->NumInstrs == 1671574 || state->NumInstrs == 1671573 || state->NumInstrs == 1671572
  812. || state->NumInstrs == 1671575) {
  813. for (reg_index = 0; reg_index < 16; reg_index ++) {
  814. printf("R%d:%x\t", reg_index, state->Reg[reg_index]);
  815. }
  816. printf("\n");
  817. }
  818. #endif
  819. if (state->tea_pc) {
  820. int i;
  821. if (state->tea_reg_fd) {
  822. fprintf (state->tea_reg_fd, "\n");
  823. for (i = 0; i < 15; i++) {
  824. fprintf (state->tea_reg_fd, "%x,",
  825. state->Reg[i]);
  826. }
  827. fprintf (state->tea_reg_fd, "%x,", pc);
  828. state->Cpsr = ARMul_GetCPSR (state);
  829. fprintf (state->tea_reg_fd, "%x\n",
  830. state->Cpsr);
  831. }
  832. else {
  833. printf ("\n");
  834. for (i = 0; i < 15; i++) {
  835. printf ("%x,", state->Reg[i]);
  836. }
  837. printf ("%x,", pc);
  838. state->Cpsr = ARMul_GetCPSR (state);
  839. printf ("%x\n", state->Cpsr);
  840. }
  841. }
  842. //AJ2D--------------------------------------------------------------------------
  843. if (state->CallDebug > 0) {
  844. instr = ARMul_Debug (state, pc, instr);
  845. if (state->Emulate < ONCE) {
  846. state->NextInstr = RESUME;
  847. break;
  848. }
  849. if (state->Debug) {
  850. fprintf (stderr,
  851. "sim: At %08lx Instr %08lx Mode %02lx\n",
  852. pc, instr, state->Mode);
  853. (void) fgetc (stdin);
  854. }
  855. }
  856. else if (state->Emulate < ONCE) {
  857. state->NextInstr = RESUME;
  858. break;
  859. }
  860. //io_do_cycle (state);
  861. state->NumInstrs++;
  862. #if 0
  863. if (state->NumInstrs % 10000000 == 0) {
  864. printf("10 MIPS instr have been executed\n");
  865. }
  866. #endif
  867. #ifdef MODET
  868. /* Provide Thumb instruction decoding. If the processor is in Thumb
  869. mode, then we can simply decode the Thumb instruction, and map it
  870. to the corresponding ARM instruction (by directly loading the
  871. instr variable, and letting the normal ARM simulator
  872. execute). There are some caveats to ensure that the correct
  873. pipelined PC value is used when executing Thumb code, and also for
  874. dealing with the BL instruction. */
  875. if (TFLAG) {
  876. ARMword new_instr;
  877. /* Check if in Thumb mode. */
  878. switch (ARMul_ThumbDecode(state, pc, instr, &new_instr)) {
  879. case t_undefined:
  880. /* This is a Thumb instruction. */
  881. ARMul_UndefInstr (state, instr);
  882. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  883. case t_branch:
  884. /* Already processed. */
  885. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  886. case t_decoded:
  887. /* ARM instruction available. */
  888. //printf("t decode %04lx -> %08lx\n", instr & 0xffff, new);
  889. instr = new_instr;
  890. /* So continue instruction decoding. */
  891. break;
  892. default:
  893. break;
  894. }
  895. }
  896. #endif
  897. /* Check the condition codes. */
  898. if ((temp = TOPBITS (28)) == AL) {
  899. /* Vile deed in the need for speed. */
  900. goto mainswitch;
  901. }
  902. /* Check the condition code. */
  903. switch ((int) TOPBITS (28)) {
  904. case AL:
  905. temp = TRUE;
  906. break;
  907. case NV:
  908. /* shenoubang add for armv7 instr dmb 2012-3-11 */
  909. if (state->is_v7) {
  910. if ((instr & 0x0fffff00) == 0x057ff000) {
  911. switch((instr >> 4) & 0xf) {
  912. case 4: /* dsb */
  913. case 5: /* dmb */
  914. case 6: /* isb */
  915. // TODO: do no implemented thes instr
  916. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  917. }
  918. }
  919. }
  920. /* dyf add for armv6 instruct CPS 2010.9.17 */
  921. if (state->is_v6) {
  922. /* clrex do nothing here temporary */
  923. if (instr == 0xf57ff01f) {
  924. //printf("clrex \n");
  925. ERROR_LOG(ARM11, "Instr = 0x%x, pc = 0x%x, clrex instr!!\n", instr, pc);
  926. #if 0
  927. int i;
  928. for(i = 0; i < 128; i++){
  929. state->exclusive_tag_array[i] = 0xffffffff;
  930. }
  931. #endif
  932. /* shenoubang 2012-3-14 refer the dyncom_interpreter */
  933. state->exclusive_tag_array[0] = 0xFFFFFFFF;
  934. state->exclusive_access_state = 0;
  935. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  936. }
  937. if (BITS(20, 27) == 0x10) {
  938. if (BIT(19)) {
  939. if (BIT(8)) {
  940. if (BIT(18))
  941. state->Cpsr |= 1<<8;
  942. else
  943. state->Cpsr &= ~(1<<8);
  944. }
  945. if (BIT(7)) {
  946. if (BIT(18))
  947. state->Cpsr |= 1<<7;
  948. else
  949. state->Cpsr &= ~(1<<7);
  950. ASSIGNINT (state->Cpsr & INTBITS);
  951. }
  952. if (BIT(6)) {
  953. if (BIT(18))
  954. state->Cpsr |= 1<<6;
  955. else
  956. state->Cpsr &= ~(1<<6);
  957. ASSIGNINT (state->Cpsr & INTBITS);
  958. }
  959. }
  960. if (BIT(17)) {
  961. state->Cpsr |= BITS(0, 4);
  962. printf("skyeye test state->Mode\n");
  963. if (state->Mode != (state->Cpsr & MODEBITS)) {
  964. state->Mode =
  965. ARMul_SwitchMode (state, state->Mode,
  966. state->Cpsr & MODEBITS);
  967. state->NtransSig = (state->Mode & 3) ? HIGH : LOW;
  968. }
  969. }
  970. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  971. }
  972. }
  973. if (state->is_v5) {
  974. if (BITS (25, 27) == 5) { /* BLX(1) */
  975. ARMword dest;
  976. state->Reg[14] = pc + 4;
  977. /* Force entry into Thumb mode. */
  978. dest = pc + 8 + 1;
  979. if (BIT (23))
  980. dest += (NEGBRANCH +
  981. (BIT (24) << 1));
  982. else
  983. dest += POSBRANCH +
  984. (BIT (24) << 1);
  985. WriteR15Branch (state, dest);
  986. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  987. }
  988. else if ((instr & 0xFC70F000) == 0xF450F000) {
  989. /* The PLD instruction. Ignored. */
  990. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  991. }
  992. else if (((instr & 0xfe500f00) == 0xfc100100)
  993. || ((instr & 0xfe500f00) ==
  994. 0xfc000100)) {
  995. /* wldrw and wstrw are unconditional. */
  996. goto mainswitch;
  997. }
  998. else {
  999. /* UNDEFINED in v5, UNPREDICTABLE in v3, v4, non executed in v1, v2. */
  1000. ARMul_UndefInstr (state, instr);
  1001. }
  1002. }
  1003. temp = FALSE;
  1004. break;
  1005. case EQ:
  1006. temp = ZFLAG;
  1007. break;
  1008. case NE:
  1009. temp = !ZFLAG;
  1010. break;
  1011. case VS:
  1012. temp = VFLAG;
  1013. break;
  1014. case VC:
  1015. temp = !VFLAG;
  1016. break;
  1017. case MI:
  1018. temp = NFLAG;
  1019. break;
  1020. case PL:
  1021. temp = !NFLAG;
  1022. break;
  1023. case CS:
  1024. temp = CFLAG;
  1025. break;
  1026. case CC:
  1027. temp = !CFLAG;
  1028. break;
  1029. case HI:
  1030. temp = (CFLAG && !ZFLAG);
  1031. break;
  1032. case LS:
  1033. temp = (!CFLAG || ZFLAG);
  1034. break;
  1035. case GE:
  1036. temp = ((!NFLAG && !VFLAG) || (NFLAG && VFLAG));
  1037. break;
  1038. case LT:
  1039. temp = ((NFLAG && !VFLAG) || (!NFLAG && VFLAG));
  1040. break;
  1041. case GT:
  1042. temp = ((!NFLAG && !VFLAG && !ZFLAG)
  1043. || (NFLAG && VFLAG && !ZFLAG));
  1044. break;
  1045. case LE:
  1046. temp = ((NFLAG && !VFLAG) || (!NFLAG && VFLAG))
  1047. || ZFLAG;
  1048. break;
  1049. } /* cc check */
  1050. //chy 2003-08-24 now #if 0 .... #endif process cp14, cp15.reg14, I disable it...
  1051. #if 0
  1052. /* Handle the Clock counter here. */
  1053. if (state->is_XScale) {
  1054. ARMword cp14r0;
  1055. int ok;
  1056. ok = state->CPRead[14] (state, 0, &cp14r0);
  1057. if (ok && (cp14r0 & ARMul_CP14_R0_ENABLE)) {
  1058. unsigned int newcycles, nowtime =
  1059. ARMul_Time (state);
  1060. newcycles = nowtime - state->LastTime;
  1061. state->LastTime = nowtime;
  1062. if (cp14r0 & ARMul_CP14_R0_CCD) {
  1063. if (state->CP14R0_CCD == -1)
  1064. state->CP14R0_CCD = newcycles;
  1065. else
  1066. state->CP14R0_CCD +=
  1067. newcycles;
  1068. if (state->CP14R0_CCD >= 64) {
  1069. newcycles = 0;
  1070. while (state->CP14R0_CCD >=
  1071. 64)
  1072. state->CP14R0_CCD -=
  1073. 64,
  1074. newcycles++;
  1075. goto check_PMUintr;
  1076. }
  1077. }
  1078. else {
  1079. ARMword cp14r1;
  1080. int do_int = 0;
  1081. state->CP14R0_CCD = -1;
  1082. check_PMUintr:
  1083. cp14r0 |= ARMul_CP14_R0_FLAG2;
  1084. (void) state->CPWrite[14] (state, 0,
  1085. cp14r0);
  1086. ok = state->CPRead[14] (state, 1,
  1087. &cp14r1);
  1088. /* Coded like this for portability. */
  1089. while (ok && newcycles) {
  1090. if (cp14r1 == 0xffffffff) {
  1091. cp14r1 = 0;
  1092. do_int = 1;
  1093. }
  1094. else
  1095. cp14r1++;
  1096. newcycles--;
  1097. }
  1098. (void) state->CPWrite[14] (state, 1,
  1099. cp14r1);
  1100. if (do_int
  1101. && (cp14r0 &
  1102. ARMul_CP14_R0_INTEN2)) {
  1103. ARMword temp;
  1104. if (state->
  1105. CPRead[13] (state, 8,
  1106. &temp)
  1107. && (temp &
  1108. ARMul_CP13_R8_PMUS))
  1109. ARMul_Abort (state,
  1110. ARMul_FIQV);
  1111. else
  1112. ARMul_Abort (state,
  1113. ARMul_IRQV);
  1114. }
  1115. }
  1116. }
  1117. }
  1118. /* Handle hardware instructions breakpoints here. */
  1119. if (state->is_XScale) {
  1120. if ((pc | 3) == (read_cp15_reg (14, 0, 8) | 2)
  1121. || (pc | 3) == (read_cp15_reg (14, 0, 9) | 2)) {
  1122. if (XScale_debug_moe
  1123. (state, ARMul_CP14_R10_MOE_IB))
  1124. ARMul_OSHandleSWI (state,
  1125. SWI_Breakpoint);
  1126. }
  1127. }
  1128. #endif
  1129. /* Actual execution of instructions begins here. */
  1130. /* If the condition codes don't match, stop here. */
  1131. if (temp) {
  1132. mainswitch:
  1133. if (state->is_XScale) {
  1134. if (BIT (20) == 0 && BITS (25, 27) == 0) {
  1135. if (BITS (4, 7) == 0xD) {
  1136. /* XScale Load Consecutive insn. */
  1137. ARMword temp =
  1138. GetLS7RHS (state,
  1139. instr);
  1140. ARMword temp2 =
  1141. BIT (23) ? LHS +
  1142. temp : LHS - temp;
  1143. ARMword addr =
  1144. BIT (24) ? temp2 :
  1145. LHS;
  1146. if (BIT (12))
  1147. ARMul_UndefInstr
  1148. (state,
  1149. instr);
  1150. else if (addr & 7)
  1151. /* Alignment violation. */
  1152. ARMul_Abort (state,
  1153. ARMul_DataAbortV);
  1154. else {
  1155. int wb = BIT (21)
  1156. ||
  1157. (!BIT (24));
  1158. state->Reg[BITS
  1159. (12, 15)] =
  1160. ARMul_LoadWordN
  1161. (state, addr);
  1162. state->Reg[BITS
  1163. (12,
  1164. 15) + 1] =
  1165. ARMul_LoadWordN
  1166. (state,
  1167. addr + 4);
  1168. if (wb)
  1169. LSBase = temp2;
  1170. }
  1171. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  1172. }
  1173. else if (BITS (4, 7) == 0xF) {
  1174. /* XScale Store Consecutive insn. */
  1175. ARMword temp =
  1176. GetLS7RHS (state,
  1177. instr);
  1178. ARMword temp2 =
  1179. BIT (23) ? LHS +
  1180. temp : LHS - temp;
  1181. ARMword addr =
  1182. BIT (24) ? temp2 :
  1183. LHS;
  1184. if (BIT (12))
  1185. ARMul_UndefInstr
  1186. (state,
  1187. instr);
  1188. else if (addr & 7)
  1189. /* Alignment violation. */
  1190. ARMul_Abort (state,
  1191. ARMul_DataAbortV);
  1192. else {
  1193. ARMul_StoreWordN
  1194. (state, addr,
  1195. state->
  1196. Reg[BITS
  1197. (12,
  1198. 15)]);
  1199. ARMul_StoreWordN
  1200. (state,
  1201. addr + 4,
  1202. state->
  1203. Reg[BITS
  1204. (12,
  1205. 15) +
  1206. 1]);
  1207. if (BIT (21)
  1208. || !BIT (24))
  1209. LSBase = temp2;
  1210. }
  1211. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  1212. }
  1213. }
  1214. //chy 2003-09-03 TMRRC(iwmmxt.c) and MRA has the same decoded instr????
  1215. //Now, I commit iwmmxt process, may be future, I will change it!!!!
  1216. //if (ARMul_HandleIwmmxt (state, instr))
  1217. // _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  1218. }
  1219. /* shenoubang sbfx and ubfx instr 2012-3-16 */
  1220. if (state->is_v6) {
  1221. unsigned int m, lsb, width, Rd, Rn, data;
  1222. Rd = Rn = lsb = width = data = m = 0;
  1223. //printf("helloworld\n");
  1224. if ((((int) BITS (21, 27)) == 0x3f) && (((int) BITS (4, 6)) == 0x5)) {
  1225. m = (unsigned)BITS(7, 11);
  1226. width = (unsigned)BITS(16, 20);
  1227. Rd = (unsigned)BITS(12, 15);
  1228. Rn = (unsigned)BITS(0, 3);
  1229. if ((Rd == 15) || (Rn == 15)) {
  1230. ARMul_UndefInstr (state, instr);
  1231. }
  1232. else if ((m + width) < 32) {
  1233. data = state->Reg[Rn];
  1234. state->Reg[Rd] ^= state->Reg[Rd];
  1235. state->Reg[Rd] =
  1236. ((ARMword)(data << (31 -(m + width))) >> ((31 - (m + width)) + (m)));
  1237. //SKYEYE_LOG_IN_CLR(RED, "UBFX: In %s, line = %d, Reg_src[%d] = 0x%x, Reg_d[%d] = 0x%x, m = %d, width = %d, Rd = %d, Rn = %d\n",
  1238. // __FUNCTION__, __LINE__, Rn, data, Rd, state->Reg[Rd], m, width + 1, Rd, Rn);
  1239. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  1240. }
  1241. } // ubfx instr
  1242. else if ((((int) BITS (21, 27)) == 0x3d) && (((int) BITS (4, 6)) == 0x5)) {
  1243. int tmp = 0;
  1244. Rd = BITS(12, 15); Rn = BITS(0, 3);
  1245. lsb = BITS(7, 11); width = BITS(16, 20);
  1246. if ((Rd == 15) || (Rn == 15)) {
  1247. ARMul_UndefInstr (state, instr);
  1248. }
  1249. else if ((lsb + width) < 32) {
  1250. state->Reg[Rd] ^= state->Reg[Rd];
  1251. data = state->Reg[Rn];
  1252. tmp = (data << (32 - (lsb + width + 1)));
  1253. state->Reg[Rd] = (tmp >> (32 - (lsb + width + 1)));
  1254. //SKYEYE_LOG_IN_CLR(RED, "sbfx: In %s, line = %d, pc = 0x%x, instr = 0x%x,Rd = 0x%x, \
  1255. Rn = 0x%x, lsb = %d, width = %d, Rs[%d] = 0x%x, Rd[%d] = 0x%x\n",
  1256. // __func__, __LINE__, pc, instr, Rd, Rn, lsb, width + 1, Rn, state->Reg[Rn], Rd, state->Reg[Rd]);
  1257. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  1258. }
  1259. } // sbfx instr
  1260. else if ((((int)BITS(21, 27)) == 0x3e) && ((int)BITS(4, 6) == 0x1)) {
  1261. //(ARMword)(instr<<(31-(n))) >> ((31-(n))+(m))
  1262. unsigned msb ,tmp_rn, tmp_rd, dst;
  1263. msb = tmp_rd = tmp_rn = dst = 0;
  1264. Rd = BITS(12, 15); Rn = BITS(0, 3);
  1265. lsb = BITS(7, 11); msb = BITS(16, 20);
  1266. if ((Rd == 15)) {
  1267. ARMul_UndefInstr (state, instr);
  1268. }
  1269. else if ((Rn == 15)) {
  1270. data = state->Reg[Rd];
  1271. tmp_rd = ((ARMword)(data << (31 - lsb)) >> (31 - lsb));
  1272. dst = ((data >> msb) << (msb - lsb));
  1273. dst = (dst << lsb) | tmp_rd;
  1274. DEBUG_LOG(ARM11, "BFC instr: msb = %d, lsb = %d, Rd[%d] : 0x%x, dst = 0x%x\n",
  1275. msb, lsb, Rd, state->Reg[Rd], dst);
  1276. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  1277. } // bfc instr
  1278. else if (((msb >= lsb) && (msb < 32))) {
  1279. data = state->Reg[Rn];
  1280. tmp_rn = ((ARMword)(data << (31 - (msb - lsb))) >> (31 - (msb - lsb)));
  1281. data = state->Reg[Rd];
  1282. tmp_rd = ((ARMword)(data << (31 - lsb)) >> (31 - lsb));
  1283. dst = ((data >> msb) << (msb - lsb)) | tmp_rn;
  1284. dst = (dst << lsb) | tmp_rd;
  1285. DEBUG_LOG(ARM11, "BFI instr:msb = %d, lsb = %d, Rd[%d] : 0x%x, Rn[%d]: 0x%x, dst = 0x%x\n",
  1286. msb, lsb, Rd, state->Reg[Rd], Rn, state->Reg[Rn], dst);
  1287. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  1288. } // bfi instr
  1289. }
  1290. }
  1291. switch ((int) BITS (20, 27)) {
  1292. /* Data Processing Register RHS Instructions. */
  1293. case 0x00: /* AND reg and MUL */
  1294. #ifdef MODET
  1295. if (BITS (4, 11) == 0xB) {
  1296. /* STRH register offset, no write-back, down, post indexed. */
  1297. SHDOWNWB ();
  1298. break;
  1299. }
  1300. if (BITS (4, 7) == 0xD) {
  1301. Handle_Load_Double (state, instr);
  1302. break;
  1303. }
  1304. if (BITS (4, 7) == 0xF) {
  1305. Handle_Store_Double (state, instr);
  1306. break;
  1307. }
  1308. #endif
  1309. if (BITS (4, 7) == 9) {
  1310. /* MUL */
  1311. rhs = state->Reg[MULRHSReg];
  1312. //if (MULLHSReg == MULDESTReg) {
  1313. if(0){ /* For armv6, the restriction is removed */
  1314. UNDEF_MULDestEQOp1;
  1315. state->Reg[MULDESTReg] = 0;
  1316. }
  1317. else if (MULDESTReg != 15)
  1318. state->Reg[MULDESTReg] =
  1319. state->
  1320. Reg[MULLHSReg] * rhs;
  1321. else
  1322. UNDEF_MULPCDest;
  1323. for (dest = 0, temp = 0; dest < 32;
  1324. dest++)
  1325. if (rhs & (1L << dest))
  1326. temp = dest;
  1327. /* Mult takes this many/2 I cycles. */
  1328. ARMul_Icycles (state,
  1329. ARMul_MultTable[temp],
  1330. 0L);
  1331. }
  1332. else {
  1333. /* AND reg. */
  1334. rhs = DPRegRHS;
  1335. dest = LHS & rhs;
  1336. WRITEDEST (dest);
  1337. }
  1338. break;
  1339. case 0x01: /* ANDS reg and MULS */
  1340. #ifdef MODET
  1341. if ((BITS (4, 11) & 0xF9) == 0x9)
  1342. /* LDR register offset, no write-back, down, post indexed. */
  1343. LHPOSTDOWN ();
  1344. /* Fall through to rest of decoding. */
  1345. #endif
  1346. if (BITS (4, 7) == 9) {
  1347. /* MULS */
  1348. rhs = state->Reg[MULRHSReg];
  1349. //if (MULLHSReg == MULDESTReg) {
  1350. if(0){
  1351. printf("Something in %d line\n", __LINE__);
  1352. UNDEF_WARNING;
  1353. UNDEF_MULDestEQOp1;
  1354. state->Reg[MULDESTReg] = 0;
  1355. CLEARN;
  1356. SETZ;
  1357. }
  1358. else if (MULDESTReg != 15) {
  1359. dest = state->Reg[MULLHSReg] *
  1360. rhs;
  1361. ARMul_NegZero (state, dest);
  1362. state->Reg[MULDESTReg] = dest;
  1363. }
  1364. else
  1365. UNDEF_MULPCDest;
  1366. for (dest = 0, temp = 0; dest < 32;
  1367. dest++)
  1368. if (rhs & (1L << dest))
  1369. temp = dest;
  1370. /* Mult takes this many/2 I cycles. */
  1371. ARMul_Icycles (state,
  1372. ARMul_MultTable[temp],
  1373. 0L);
  1374. }
  1375. else {
  1376. /* ANDS reg. */
  1377. rhs = DPSRegRHS;
  1378. dest = LHS & rhs;
  1379. WRITESDEST (dest);
  1380. }
  1381. break;
  1382. case 0x02: /* EOR reg and MLA */
  1383. #ifdef MODET
  1384. if (BITS (4, 11) == 0xB) {
  1385. /* STRH register offset, write-back, down, post indexed. */
  1386. SHDOWNWB ();
  1387. break;
  1388. }
  1389. #endif
  1390. if (BITS (4, 7) == 9) { /* MLA */
  1391. rhs = state->Reg[MULRHSReg];
  1392. #if 0
  1393. if (MULLHSReg == MULDESTReg) {
  1394. UNDEF_MULDestEQOp1;
  1395. state->Reg[MULDESTReg] =
  1396. state->Reg[MULACCReg];
  1397. }
  1398. else if (MULDESTReg != 15){
  1399. #endif
  1400. if (MULDESTReg != 15){
  1401. state->Reg[MULDESTReg] =
  1402. state->
  1403. Reg[MULLHSReg] * rhs +
  1404. state->Reg[MULACCReg];
  1405. }
  1406. else
  1407. UNDEF_MULPCDest;
  1408. for (dest = 0, temp = 0; dest < 32;
  1409. dest++)
  1410. if (rhs & (1L << dest))
  1411. temp = dest;
  1412. /* Mult takes this many/2 I cycles. */
  1413. ARMul_Icycles (state,
  1414. ARMul_MultTable[temp],
  1415. 0L);
  1416. }
  1417. else {
  1418. rhs = DPRegRHS;
  1419. dest = LHS ^ rhs;
  1420. WRITEDEST (dest);
  1421. }
  1422. break;
  1423. case 0x03: /* EORS reg and MLAS */
  1424. #ifdef MODET
  1425. if ((BITS (4, 11) & 0xF9) == 0x9)
  1426. /* LDR register offset, write-back, down, post-indexed. */
  1427. LHPOSTDOWN ();
  1428. /* Fall through to rest of the decoding. */
  1429. #endif
  1430. if (BITS (4, 7) == 9) {
  1431. /* MLAS */
  1432. rhs = state->Reg[MULRHSReg];
  1433. //if (MULLHSReg == MULDESTReg) {
  1434. if (0) {
  1435. UNDEF_MULDestEQOp1;
  1436. dest = state->Reg[MULACCReg];
  1437. ARMul_NegZero (state, dest);
  1438. state->Reg[MULDESTReg] = dest;
  1439. }
  1440. else if (MULDESTReg != 15) {
  1441. dest = state->Reg[MULLHSReg] *
  1442. rhs +
  1443. state->Reg[MULACCReg];
  1444. ARMul_NegZero (state, dest);
  1445. state->Reg[MULDESTReg] = dest;
  1446. }
  1447. else
  1448. UNDEF_MULPCDest;
  1449. for (dest = 0, temp = 0; dest < 32;
  1450. dest++)
  1451. if (rhs & (1L << dest))
  1452. temp = dest;
  1453. /* Mult takes this many/2 I cycles. */
  1454. ARMul_Icycles (state,
  1455. ARMul_MultTable[temp],
  1456. 0L);
  1457. }
  1458. else {
  1459. /* EORS Reg. */
  1460. rhs = DPSRegRHS;
  1461. dest = LHS ^ rhs;
  1462. WRITESDEST (dest);
  1463. }
  1464. break;
  1465. case 0x04: /* SUB reg */
  1466. #ifdef MODET
  1467. if (BITS (4, 7) == 0xB) {
  1468. /* STRH immediate offset, no write-back, down, post indexed. */
  1469. SHDOWNWB ();
  1470. break;
  1471. }
  1472. if (BITS (4, 7) == 0xD) {
  1473. Handle_Load_Double (state, instr);
  1474. break;
  1475. }
  1476. if (BITS (4, 7) == 0xF) {
  1477. Handle_Store_Double (state, instr);
  1478. break;
  1479. }
  1480. #endif
  1481. rhs = DPRegRHS;
  1482. dest = LHS - rhs;
  1483. WRITEDEST (dest);
  1484. break;
  1485. case 0x05: /* SUBS reg */
  1486. #ifdef MODET
  1487. if ((BITS (4, 7) & 0x9) == 0x9)
  1488. /* LDR immediate offset, no write-back, down, post indexed. */
  1489. LHPOSTDOWN ();
  1490. /* Fall through to the rest of the instruction decoding. */
  1491. #endif
  1492. lhs = LHS;
  1493. rhs = DPRegRHS;
  1494. dest = lhs - rhs;
  1495. if ((lhs >= rhs) || ((rhs | lhs) >> 31)) {
  1496. ARMul_SubCarry (state, lhs, rhs,
  1497. dest);
  1498. ARMul_SubOverflow (state, lhs, rhs,
  1499. dest);
  1500. }
  1501. else {
  1502. CLEARC;
  1503. CLEARV;
  1504. }
  1505. WRITESDEST (dest);
  1506. break;
  1507. case 0x06: /* RSB reg */
  1508. #ifdef MODET
  1509. if (BITS (4, 7) == 0xB) {
  1510. /* STRH immediate offset, write-back, down, post indexed. */
  1511. SHDOWNWB ();
  1512. break;
  1513. }
  1514. #endif
  1515. rhs = DPRegRHS;
  1516. dest = rhs - LHS;
  1517. WRITEDEST (dest);
  1518. break;
  1519. case 0x07: /* RSBS reg */
  1520. #ifdef MODET
  1521. if ((BITS (4, 7) & 0x9) == 0x9)
  1522. /* LDR immediate offset, write-back, down, post indexed. */
  1523. LHPOSTDOWN ();
  1524. /* Fall through to remainder of instruction decoding. */
  1525. #endif
  1526. lhs = LHS;
  1527. rhs = DPRegRHS;
  1528. dest = rhs - lhs;
  1529. if ((rhs >= lhs) || ((rhs | lhs) >> 31)) {
  1530. ARMul_SubCarry (state, rhs, lhs,
  1531. dest);
  1532. ARMul_SubOverflow (state, rhs, lhs,
  1533. dest);
  1534. }
  1535. else {
  1536. CLEARC;
  1537. CLEARV;
  1538. }
  1539. WRITESDEST (dest);
  1540. break;
  1541. case 0x08: /* ADD reg */
  1542. #ifdef MODET
  1543. if (BITS (4, 11) == 0xB) {
  1544. /* STRH register offset, no write-back, up, post indexed. */
  1545. SHUPWB ();
  1546. break;
  1547. }
  1548. if (BITS (4, 7) == 0xD) {
  1549. Handle_Load_Double (state, instr);
  1550. break;
  1551. }
  1552. if (BITS (4, 7) == 0xF) {
  1553. Handle_Store_Double (state, instr);
  1554. break;
  1555. }
  1556. #endif
  1557. #ifdef MODET
  1558. if (BITS (4, 7) == 0x9) {
  1559. /* MULL */
  1560. /* 32x32 = 64 */
  1561. ARMul_Icycles (state,
  1562. Multiply64 (state,
  1563. instr,
  1564. LUNSIGNED,
  1565. LDEFAULT),
  1566. 0L);
  1567. break;
  1568. }
  1569. #endif
  1570. rhs = DPRegRHS;
  1571. dest = LHS + rhs;
  1572. WRITEDEST (dest);
  1573. break;
  1574. case 0x09: /* ADDS reg */
  1575. #ifdef MODET
  1576. if ((BITS (4, 11) & 0xF9) == 0x9)
  1577. /* LDR register offset, no write-back, up, post indexed. */
  1578. LHPOSTUP ();
  1579. /* Fall through to remaining instruction decoding. */
  1580. #endif
  1581. #ifdef MODET
  1582. if (BITS (4, 7) == 0x9) {
  1583. /* MULL */
  1584. /* 32x32=64 */
  1585. ARMul_Icycles (state,
  1586. Multiply64 (state,
  1587. instr,
  1588. LUNSIGNED,
  1589. LSCC), 0L);
  1590. break;
  1591. }
  1592. #endif
  1593. lhs = LHS;
  1594. rhs = DPRegRHS;
  1595. dest = lhs + rhs;
  1596. ASSIGNZ (dest == 0);
  1597. if ((lhs | rhs) >> 30) {
  1598. /* Possible C,V,N to set. */
  1599. ASSIGNN (NEG (dest));
  1600. ARMul_AddCarry (state, lhs, rhs,
  1601. dest);
  1602. ARMul_AddOverflow (state, lhs, rhs,
  1603. dest);
  1604. }
  1605. else {
  1606. CLEARN;
  1607. CLEARC;
  1608. CLEARV;
  1609. }
  1610. WRITESDEST (dest);
  1611. break;
  1612. case 0x0a: /* ADC reg */
  1613. #ifdef MODET
  1614. if (BITS (4, 11) == 0xB) {
  1615. /* STRH register offset, write-back, up, post-indexed. */
  1616. SHUPWB ();
  1617. break;
  1618. }
  1619. if (BITS (4, 7) == 0x9) {
  1620. /* MULL */
  1621. /* 32x32=64 */
  1622. ARMul_Icycles (state,
  1623. MultiplyAdd64 (state,
  1624. instr,
  1625. LUNSIGNED,
  1626. LDEFAULT),
  1627. 0L);
  1628. break;
  1629. }
  1630. #endif
  1631. rhs = DPRegRHS;
  1632. dest = LHS + rhs + CFLAG;
  1633. WRITEDEST (dest);
  1634. break;
  1635. case 0x0b: /* ADCS reg */
  1636. #ifdef MODET
  1637. if ((BITS (4, 11) & 0xF9) == 0x9)
  1638. /* LDR register offset, write-back, up, post indexed. */
  1639. LHPOSTUP ();
  1640. /* Fall through to remaining instruction decoding. */
  1641. if (BITS (4, 7) == 0x9) {
  1642. /* MULL */
  1643. /* 32x32=64 */
  1644. ARMul_Icycles (state,
  1645. MultiplyAdd64 (state,
  1646. instr,
  1647. LUNSIGNED,
  1648. LSCC),
  1649. 0L);
  1650. break;
  1651. }
  1652. #endif
  1653. lhs = LHS;
  1654. rhs = DPRegRHS;
  1655. dest = lhs + rhs + CFLAG;
  1656. ASSIGNZ (dest == 0);
  1657. if ((lhs | rhs) >> 30) {
  1658. /* Possible C,V,N to set. */
  1659. ASSIGNN (NEG (dest));
  1660. ARMul_AddCarry (state, lhs, rhs,
  1661. dest);
  1662. ARMul_AddOverflow (state, lhs, rhs,
  1663. dest);
  1664. }
  1665. else {
  1666. CLEARN;
  1667. CLEARC;
  1668. CLEARV;
  1669. }
  1670. WRITESDEST (dest);
  1671. break;
  1672. case 0x0c: /* SBC reg */
  1673. #ifdef MODET
  1674. if (BITS (4, 7) == 0xB) {
  1675. /* STRH immediate offset, no write-back, up post indexed. */
  1676. SHUPWB ();
  1677. break;
  1678. }
  1679. if (BITS (4, 7) == 0xD) {
  1680. Handle_Load_Double (state, instr);
  1681. break;
  1682. }
  1683. if (BITS (4, 7) == 0xF) {
  1684. Handle_Store_Double (state, instr);
  1685. break;
  1686. }
  1687. if (BITS (4, 7) == 0x9) {
  1688. /* MULL */
  1689. /* 32x32=64 */
  1690. ARMul_Icycles (state,
  1691. Multiply64 (state,
  1692. instr,
  1693. LSIGNED,
  1694. LDEFAULT),
  1695. 0L);
  1696. break;
  1697. }
  1698. #endif
  1699. rhs = DPRegRHS;
  1700. dest = LHS - rhs - !CFLAG;
  1701. WRITEDEST (dest);
  1702. break;
  1703. case 0x0d: /* SBCS reg */
  1704. #ifdef MODET
  1705. if ((BITS (4, 7) & 0x9) == 0x9)
  1706. /* LDR immediate offset, no write-back, up, post indexed. */
  1707. LHPOSTUP ();
  1708. if (BITS (4, 7) == 0x9) {
  1709. /* MULL */
  1710. /* 32x32=64 */
  1711. ARMul_Icycles (state,
  1712. Multiply64 (state,
  1713. instr,
  1714. LSIGNED,
  1715. LSCC), 0L);
  1716. break;
  1717. }
  1718. #endif
  1719. lhs = LHS;
  1720. rhs = DPRegRHS;
  1721. dest = lhs - rhs - !CFLAG;
  1722. if ((lhs >= rhs) || ((rhs | lhs) >> 31)) {
  1723. ARMul_SubCarry (state, lhs, rhs,
  1724. dest);
  1725. ARMul_SubOverflow (state, lhs, rhs,
  1726. dest);
  1727. }
  1728. else {
  1729. CLEARC;
  1730. CLEARV;
  1731. }
  1732. WRITESDEST (dest);
  1733. break;
  1734. case 0x0e: /* RSC reg */
  1735. #ifdef MODET
  1736. if (BITS (4, 7) == 0xB) {
  1737. /* STRH immediate offset, write-back, up, post indexed. */
  1738. SHUPWB ();
  1739. break;
  1740. }
  1741. if (BITS (4, 7) == 0x9) {
  1742. /* MULL */
  1743. /* 32x32=64 */
  1744. ARMul_Icycles (state,
  1745. MultiplyAdd64 (state,
  1746. instr,
  1747. LSIGNED,
  1748. LDEFAULT),
  1749. 0L);
  1750. break;
  1751. }
  1752. #endif
  1753. rhs = DPRegRHS;
  1754. dest = rhs - LHS - !CFLAG;
  1755. WRITEDEST (dest);
  1756. break;
  1757. case 0x0f: /* RSCS reg */
  1758. #ifdef MODET
  1759. if ((BITS (4, 7) & 0x9) == 0x9)
  1760. /* LDR immediate offset, write-back, up, post indexed. */
  1761. LHPOSTUP ();
  1762. /* Fall through to remaining instruction decoding. */
  1763. if (BITS (4, 7) == 0x9) {
  1764. /* MULL */
  1765. /* 32x32=64 */
  1766. ARMul_Icycles (state,
  1767. MultiplyAdd64 (state,
  1768. instr,
  1769. LSIGNED,
  1770. LSCC),
  1771. 0L);
  1772. break;
  1773. }
  1774. #endif
  1775. lhs = LHS;
  1776. rhs = DPRegRHS;
  1777. dest = rhs - lhs - !CFLAG;
  1778. if ((rhs >= lhs) || ((rhs | lhs) >> 31)) {
  1779. ARMul_SubCarry (state, rhs, lhs,
  1780. dest);
  1781. ARMul_SubOverflow (state, rhs, lhs,
  1782. dest);
  1783. }
  1784. else {
  1785. CLEARC;
  1786. CLEARV;
  1787. }
  1788. WRITESDEST (dest);
  1789. break;
  1790. case 0x10: /* TST reg and MRS CPSR and SWP word. */
  1791. if (state->is_v5e) {
  1792. if (BIT (4) == 0 && BIT (7) == 1) {
  1793. /* ElSegundo SMLAxy insn. */
  1794. ARMword op1 =
  1795. state->
  1796. Reg[BITS (0, 3)];
  1797. ARMword op2 =
  1798. state->
  1799. Reg[BITS (8, 11)];
  1800. ARMword Rn =
  1801. state->
  1802. Reg[BITS (12, 15)];
  1803. if (BIT (5))
  1804. op1 >>= 16;
  1805. if (BIT (6))
  1806. op2 >>= 16;
  1807. op1 &= 0xFFFF;
  1808. op2 &= 0xFFFF;
  1809. if (op1 & 0x8000)
  1810. op1 -= 65536;
  1811. if (op2 & 0x8000)
  1812. op2 -= 65536;
  1813. op1 *= op2;
  1814. //printf("SMLA_INST:BB,op1=0x%x, op2=0x%x. Rn=0x%x\n", op1, op2, Rn);
  1815. if (AddOverflow
  1816. (op1, Rn, op1 + Rn))
  1817. SETS;
  1818. state->Reg[BITS (16, 19)] =
  1819. op1 + Rn;
  1820. break;
  1821. }
  1822. if (BITS (4, 11) == 5) {
  1823. /* ElSegundo QADD insn. */
  1824. ARMword op1 =
  1825. state->
  1826. Reg[BITS (0, 3)];
  1827. ARMword op2 =
  1828. state->
  1829. Reg[BITS (16, 19)];
  1830. ARMword result = op1 + op2;
  1831. if (AddOverflow
  1832. (op1, op2, result)) {
  1833. result = POS (result)
  1834. ? 0x80000000 :
  1835. 0x7fffffff;
  1836. SETS;
  1837. }
  1838. state->Reg[BITS (12, 15)] =
  1839. result;
  1840. break;
  1841. }
  1842. }
  1843. #ifdef MODET
  1844. if (BITS (4, 11) == 0xB) {
  1845. /* STRH register offset, no write-back, down, pre indexed. */
  1846. SHPREDOWN ();
  1847. break;
  1848. }
  1849. if (BITS (4, 7) == 0xD) {
  1850. Handle_Load_Double (state, instr);
  1851. break;
  1852. }
  1853. if (BITS (4, 7) == 0xF) {
  1854. Handle_Store_Double (state, instr);
  1855. break;
  1856. }
  1857. #endif
  1858. if (BITS (4, 11) == 9) {
  1859. /* SWP */
  1860. UNDEF_SWPPC;
  1861. temp = LHS;
  1862. BUSUSEDINCPCS;
  1863. #ifndef MODE32
  1864. if (VECTORACCESS (temp)
  1865. || ADDREXCEPT (temp)) {
  1866. INTERNALABORT (temp);
  1867. (void) ARMul_LoadWordN (state,
  1868. temp);
  1869. (void) ARMul_LoadWordN (state,
  1870. temp);
  1871. }
  1872. else
  1873. #endif
  1874. dest = ARMul_SwapWord (state,
  1875. temp,
  1876. state->
  1877. Reg
  1878. [RHSReg]);
  1879. if (temp & 3)
  1880. DEST = ARMul_Align (state,
  1881. temp,
  1882. dest);
  1883. else
  1884. DEST = dest;
  1885. if (state->abortSig || state->Aborted)
  1886. TAKEABORT;
  1887. }
  1888. else if ((BITS (0, 11) == 0) && (LHSReg == 15)) { /* MRS CPSR */
  1889. UNDEF_MRSPC;
  1890. DEST = ECC | EINT | EMODE;
  1891. }
  1892. else {
  1893. UNDEF_Test;
  1894. }
  1895. break;
  1896. case 0x11: /* TSTP reg */
  1897. #ifdef MODET
  1898. if ((BITS (4, 11) & 0xF9) == 0x9)
  1899. /* LDR register offset, no write-back, down, pre indexed. */
  1900. LHPREDOWN ();
  1901. /* Continue with remaining instruction decode. */
  1902. #endif
  1903. if (DESTReg == 15) {
  1904. /* TSTP reg */
  1905. #ifdef MODE32
  1906. //chy 2006-02-15 if in user mode, can not set cpsr 0:23
  1907. //from p165 of ARMARM book
  1908. state->Cpsr = GETSPSR (state->Bank);
  1909. ARMul_CPSRAltered (state);
  1910. #else
  1911. rhs = DPRegRHS;
  1912. temp = LHS & rhs;
  1913. SETR15PSR (temp);
  1914. #endif
  1915. }
  1916. else {
  1917. /* TST reg */
  1918. rhs = DPSRegRHS;
  1919. dest = LHS & rhs;
  1920. ARMul_NegZero (state, dest);
  1921. }
  1922. break;
  1923. case 0x12: /* TEQ reg and MSR reg to CPSR (ARM6). */
  1924. if (state->is_v5) {
  1925. if (BITS (4, 7) == 3) {
  1926. /* BLX(2) */
  1927. ARMword temp;
  1928. if (TFLAG)
  1929. temp = (pc + 2) | 1;
  1930. else
  1931. temp = pc + 4;
  1932. WriteR15Branch (state,
  1933. state->
  1934. Reg[RHSReg]);
  1935. state->Reg[14] = temp;
  1936. break;
  1937. }
  1938. }
  1939. if (state->is_v5e) {
  1940. if (BIT (4) == 0 && BIT (7) == 1
  1941. && (BIT (5) == 0
  1942. || BITS (12, 15) == 0)) {
  1943. /* ElSegundo SMLAWy/SMULWy insn. */
  1944. unsigned long long op1 =
  1945. state->
  1946. Reg[BITS (0, 3)];
  1947. unsigned long long op2 =
  1948. state->
  1949. Reg[BITS (8, 11)];
  1950. unsigned long long result;
  1951. if (BIT (6))
  1952. op2 >>= 16;
  1953. if (op1 & 0x80000000)
  1954. op1 -= 1ULL << 32;
  1955. op2 &= 0xFFFF;
  1956. if (op2 & 0x8000)
  1957. op2 -= 65536;
  1958. result = (op1 * op2) >> 16;
  1959. if (BIT (5) == 0) {
  1960. ARMword Rn =
  1961. state->
  1962. Reg[BITS
  1963. (12, 15)];
  1964. if (AddOverflow
  1965. (result, Rn,
  1966. result + Rn))
  1967. SETS;
  1968. result += Rn;
  1969. }
  1970. state->Reg[BITS (16, 19)] =
  1971. result;
  1972. break;
  1973. }
  1974. if (BITS (4, 11) == 5) {
  1975. /* ElSegundo QSUB insn. */
  1976. ARMword op1 =
  1977. state->
  1978. Reg[BITS (0, 3)];
  1979. ARMword op2 =
  1980. state->
  1981. Reg[BITS (16, 19)];
  1982. ARMword result = op1 - op2;
  1983. if (SubOverflow
  1984. (op1, op2, result)) {
  1985. result = POS (result)
  1986. ? 0x80000000 :
  1987. 0x7fffffff;
  1988. SETS;
  1989. }
  1990. state->Reg[BITS (12, 15)] =
  1991. result;
  1992. break;
  1993. }
  1994. }
  1995. #ifdef MODET
  1996. if (BITS (4, 11) == 0xB) {
  1997. /* STRH register offset, write-back, down, pre indexed. */
  1998. SHPREDOWNWB ();
  1999. break;
  2000. }
  2001. if (BITS (4, 27) == 0x12FFF1) {
  2002. /* BX */
  2003. WriteR15Branch (state,
  2004. state->Reg[RHSReg]);
  2005. break;
  2006. }
  2007. if (BITS (4, 7) == 0xD) {
  2008. Handle_Load_Double (state, instr);
  2009. break;
  2010. }
  2011. if (BITS (4, 7) == 0xF) {
  2012. Handle_Store_Double (state, instr);
  2013. break;
  2014. }
  2015. #endif
  2016. if (state->is_v5) {
  2017. if (BITS (4, 7) == 0x7) {
  2018. ARMword value;
  2019. extern int
  2020. SWI_vector_installed;
  2021. /* Hardware is allowed to optionally override this
  2022. instruction and treat it as a breakpoint. Since
  2023. this is a simulator not hardware, we take the position
  2024. that if a SWI vector was not installed, then an Abort
  2025. vector was probably not installed either, and so
  2026. normally this instruction would be ignored, even if an
  2027. Abort is generated. This is a bad thing, since GDB
  2028. uses this instruction for its breakpoints (at least in
  2029. Thumb mode it does). So intercept the instruction here
  2030. and generate a breakpoint SWI instead. */
  2031. if (!SWI_vector_installed)
  2032. ARMul_OSHandleSWI
  2033. (state,
  2034. SWI_Breakpoint);
  2035. else {
  2036. /* BKPT - normally this will cause an abort, but on the
  2037. XScale we must check the DCSR. */
  2038. XScale_set_fsr_far
  2039. (state,
  2040. ARMul_CP15_R5_MMU_EXCPT,
  2041. pc);
  2042. //if (!XScale_debug_moe
  2043. // (state,
  2044. // ARMul_CP14_R10_MOE_BT))
  2045. // break; // Disabled /bunnei
  2046. }
  2047. /* Force the next instruction to be refetched. */
  2048. state->NextInstr = RESUME;
  2049. break;
  2050. }
  2051. }
  2052. if (DESTReg == 15) {
  2053. /* MSR reg to CPSR. */
  2054. UNDEF_MSRPC;
  2055. temp = DPRegRHS;
  2056. #ifdef MODET
  2057. /* Don't allow TBIT to be set by MSR. */
  2058. temp &= ~TBIT;
  2059. #endif
  2060. ARMul_FixCPSR (state, instr, temp);
  2061. }
  2062. else
  2063. UNDEF_Test;
  2064. break;
  2065. case 0x13: /* TEQP reg */
  2066. #ifdef MODET
  2067. if ((BITS (4, 11) & 0xF9) == 0x9)
  2068. /* LDR register offset, write-back, down, pre indexed. */
  2069. LHPREDOWNWB ();
  2070. /* Continue with remaining instruction decode. */
  2071. #endif
  2072. if (DESTReg == 15) {
  2073. /* TEQP reg */
  2074. #ifdef MODE32
  2075. state->Cpsr = GETSPSR (state->Bank);
  2076. ARMul_CPSRAltered (state);
  2077. #else
  2078. rhs = DPRegRHS;
  2079. temp = LHS ^ rhs;
  2080. SETR15PSR (temp);
  2081. #endif
  2082. }
  2083. else {
  2084. /* TEQ Reg. */
  2085. rhs = DPSRegRHS;
  2086. dest = LHS ^ rhs;
  2087. ARMul_NegZero (state, dest);
  2088. }
  2089. break;
  2090. case 0x14: /* CMP reg and MRS SPSR and SWP byte. */
  2091. if (state->is_v5e) {
  2092. if (BIT (4) == 0 && BIT (7) == 1) {
  2093. /* ElSegundo SMLALxy insn. */
  2094. unsigned long long op1 =
  2095. state->
  2096. Reg[BITS (0, 3)];
  2097. unsigned long long op2 =
  2098. state->
  2099. Reg[BITS (8, 11)];
  2100. unsigned long long dest;
  2101. unsigned long long result;
  2102. if (BIT (5))
  2103. op1 >>= 16;
  2104. if (BIT (6))
  2105. op2 >>= 16;
  2106. op1 &= 0xFFFF;
  2107. if (op1 & 0x8000)
  2108. op1 -= 65536;
  2109. op2 &= 0xFFFF;
  2110. if (op2 & 0x8000)
  2111. op2 -= 65536;
  2112. dest = (unsigned long long)
  2113. state->
  2114. Reg[BITS (16, 19)] <<
  2115. 32;
  2116. dest |= state->
  2117. Reg[BITS (12, 15)];
  2118. dest += op1 * op2;
  2119. state->Reg[BITS (12, 15)] =
  2120. dest;
  2121. state->Reg[BITS (16, 19)] =
  2122. dest >> 32;
  2123. break;
  2124. }
  2125. if (BITS (4, 11) == 5) {
  2126. /* ElSegundo QDADD insn. */
  2127. ARMword op1 =
  2128. state->
  2129. Reg[BITS (0, 3)];
  2130. ARMword op2 =
  2131. state->
  2132. Reg[BITS (16, 19)];
  2133. ARMword op2d = op2 + op2;
  2134. ARMword result;
  2135. if (AddOverflow
  2136. (op2, op2, op2d)) {
  2137. SETS;
  2138. op2d = POS (op2d) ?
  2139. 0x80000000 :
  2140. 0x7fffffff;
  2141. }
  2142. result = op1 + op2d;
  2143. if (AddOverflow
  2144. (op1, op2d, result)) {
  2145. SETS;
  2146. result = POS (result)
  2147. ? 0x80000000 :
  2148. 0x7fffffff;
  2149. }
  2150. state->Reg[BITS (12, 15)] =
  2151. result;
  2152. break;
  2153. }
  2154. }
  2155. #ifdef MODET
  2156. if (BITS (4, 7) == 0xB) {
  2157. /* STRH immediate offset, no write-back, down, pre indexed. */
  2158. SHPREDOWN ();
  2159. break;
  2160. }
  2161. if (BITS (4, 7) == 0xD) {
  2162. Handle_Load_Double (state, instr);
  2163. break;
  2164. }
  2165. if (BITS (4, 7) == 0xF) {
  2166. Handle_Store_Double (state, instr);
  2167. break;
  2168. }
  2169. #endif
  2170. if (BITS (4, 11) == 9) {
  2171. /* SWP */
  2172. UNDEF_SWPPC;
  2173. temp = LHS;
  2174. BUSUSEDINCPCS;
  2175. #ifndef MODE32
  2176. if (VECTORACCESS (temp)
  2177. || ADDREXCEPT (temp)) {
  2178. INTERNALABORT (temp);
  2179. (void) ARMul_LoadByte (state,
  2180. temp);
  2181. (void) ARMul_LoadByte (state,
  2182. temp);
  2183. }
  2184. else
  2185. #endif
  2186. DEST = ARMul_SwapByte (state,
  2187. temp,
  2188. state->
  2189. Reg
  2190. [RHSReg]);
  2191. if (state->abortSig || state->Aborted)
  2192. TAKEABORT;
  2193. }
  2194. else if ((BITS (0, 11) == 0)
  2195. && (LHSReg == 15)) {
  2196. /* MRS SPSR */
  2197. UNDEF_MRSPC;
  2198. DEST = GETSPSR (state->Bank);
  2199. }
  2200. else
  2201. UNDEF_Test;
  2202. break;
  2203. case 0x15: /* CMPP reg. */
  2204. #ifdef MODET
  2205. if ((BITS (4, 7) & 0x9) == 0x9)
  2206. /* LDR immediate offset, no write-back, down, pre indexed. */
  2207. LHPREDOWN ();
  2208. /* Continue with remaining instruction decode. */
  2209. #endif
  2210. if (DESTReg == 15) {
  2211. /* CMPP reg. */
  2212. #ifdef MODE32
  2213. state->Cpsr = GETSPSR (state->Bank);
  2214. ARMul_CPSRAltered (state);
  2215. #else
  2216. rhs = DPRegRHS;
  2217. temp = LHS - rhs;
  2218. SETR15PSR (temp);
  2219. #endif
  2220. }
  2221. else {
  2222. /* CMP reg. */
  2223. lhs = LHS;
  2224. rhs = DPRegRHS;
  2225. dest = lhs - rhs;
  2226. ARMul_NegZero (state, dest);
  2227. if ((lhs >= rhs)
  2228. || ((rhs | lhs) >> 31)) {
  2229. ARMul_SubCarry (state, lhs,
  2230. rhs, dest);
  2231. ARMul_SubOverflow (state, lhs,
  2232. rhs, dest);
  2233. }
  2234. else {
  2235. CLEARC;
  2236. CLEARV;
  2237. }
  2238. }
  2239. break;
  2240. case 0x16: /* CMN reg and MSR reg to SPSR */
  2241. if (state->is_v5e) {
  2242. if (BIT (4) == 0 && BIT (7) == 1
  2243. && BITS (12, 15) == 0) {
  2244. /* ElSegundo SMULxy insn. */
  2245. ARMword op1 =
  2246. state->
  2247. Reg[BITS (0, 3)];
  2248. ARMword op2 =
  2249. state->
  2250. Reg[BITS (8, 11)];
  2251. ARMword Rn =
  2252. state->
  2253. Reg[BITS (12, 15)];
  2254. if (BIT (5))
  2255. op1 >>= 16;
  2256. if (BIT (6))
  2257. op2 >>= 16;
  2258. op1 &= 0xFFFF;
  2259. op2 &= 0xFFFF;
  2260. if (op1 & 0x8000)
  2261. op1 -= 65536;
  2262. if (op2 & 0x8000)
  2263. op2 -= 65536;
  2264. state->Reg[BITS (16, 19)] =
  2265. op1 * op2;
  2266. break;
  2267. }
  2268. if (BITS (4, 11) == 5) {
  2269. /* ElSegundo QDSUB insn. */
  2270. ARMword op1 =
  2271. state->
  2272. Reg[BITS (0, 3)];
  2273. ARMword op2 =
  2274. state->
  2275. Reg[BITS (16, 19)];
  2276. ARMword op2d = op2 + op2;
  2277. ARMword result;
  2278. if (AddOverflow
  2279. (op2, op2, op2d)) {
  2280. SETS;
  2281. op2d = POS (op2d) ?
  2282. 0x80000000 :
  2283. 0x7fffffff;
  2284. }
  2285. result = op1 - op2d;
  2286. if (SubOverflow
  2287. (op1, op2d, result)) {
  2288. SETS;
  2289. result = POS (result)
  2290. ? 0x80000000 :
  2291. 0x7fffffff;
  2292. }
  2293. state->Reg[BITS (12, 15)] =
  2294. result;
  2295. break;
  2296. }
  2297. }
  2298. if (state->is_v5) {
  2299. if (BITS (4, 11) == 0xF1
  2300. && BITS (16, 19) == 0xF) {
  2301. /* ARM5 CLZ insn. */
  2302. ARMword op1 =
  2303. state->
  2304. Reg[BITS (0, 3)];
  2305. int result = 32;
  2306. if (op1)
  2307. for (result = 0;
  2308. (op1 &
  2309. 0x80000000) ==
  2310. 0; op1 <<= 1)
  2311. result++;
  2312. state->Reg[BITS (12, 15)] =
  2313. result;
  2314. break;
  2315. }
  2316. }
  2317. #ifdef MODET
  2318. if (BITS (4, 7) == 0xB) {
  2319. /* STRH immediate offset, write-back, down, pre indexed. */
  2320. SHPREDOWNWB ();
  2321. break;
  2322. }
  2323. if (BITS (4, 7) == 0xD) {
  2324. Handle_Load_Double (state, instr);
  2325. break;
  2326. }
  2327. if (BITS (4, 7) == 0xF) {
  2328. Handle_Store_Double (state, instr);
  2329. break;
  2330. }
  2331. #endif
  2332. if (DESTReg == 15) {
  2333. /* MSR */
  2334. UNDEF_MSRPC;
  2335. ARMul_FixSPSR (state, instr,
  2336. DPRegRHS);
  2337. }
  2338. else {
  2339. UNDEF_Test;
  2340. }
  2341. break;
  2342. case 0x17: /* CMNP reg */
  2343. #ifdef MODET
  2344. if ((BITS (4, 7) & 0x9) == 0x9)
  2345. /* LDR immediate offset, write-back, down, pre indexed. */
  2346. LHPREDOWNWB ();
  2347. /* Continue with remaining instruction decoding. */
  2348. #endif
  2349. if (DESTReg == 15) {
  2350. #ifdef MODE32
  2351. state->Cpsr = GETSPSR (state->Bank);
  2352. ARMul_CPSRAltered (state);
  2353. #else
  2354. rhs = DPRegRHS;
  2355. temp = LHS + rhs;
  2356. SETR15PSR (temp);
  2357. #endif
  2358. break;
  2359. }
  2360. else {
  2361. /* CMN reg. */
  2362. lhs = LHS;
  2363. rhs = DPRegRHS;
  2364. dest = lhs + rhs;
  2365. ASSIGNZ (dest == 0);
  2366. if ((lhs | rhs) >> 30) {
  2367. /* Possible C,V,N to set. */
  2368. ASSIGNN (NEG (dest));
  2369. ARMul_AddCarry (state, lhs,
  2370. rhs, dest);
  2371. ARMul_AddOverflow (state, lhs,
  2372. rhs, dest);
  2373. }
  2374. else {
  2375. CLEARN;
  2376. CLEARC;
  2377. CLEARV;
  2378. }
  2379. }
  2380. break;
  2381. case 0x18: /* ORR reg */
  2382. #ifdef MODET
  2383. /* dyf add armv6 instr strex 2010.9.17 */
  2384. if (state->is_v6) {
  2385. if (BITS (4, 7) == 0x9)
  2386. if (handle_v6_insn (state, instr))
  2387. break;
  2388. }
  2389. if (BITS (4, 11) == 0xB) {
  2390. /* STRH register offset, no write-back, up, pre indexed. */
  2391. SHPREUP ();
  2392. break;
  2393. }
  2394. if (BITS (4, 7) == 0xD) {
  2395. Handle_Load_Double (state, instr);
  2396. break;
  2397. }
  2398. if (BITS (4, 7) == 0xF) {
  2399. Handle_Store_Double (state, instr);
  2400. break;
  2401. }
  2402. #endif
  2403. rhs = DPRegRHS;
  2404. dest = LHS | rhs;
  2405. WRITEDEST (dest);
  2406. break;
  2407. case 0x19: /* ORRS reg */
  2408. #ifdef MODET
  2409. /* dyf add armv6 instr ldrex */
  2410. if (state->is_v6) {
  2411. if (BITS (4, 7) == 0x9) {
  2412. if (handle_v6_insn (state, instr))
  2413. break;
  2414. }
  2415. }
  2416. if ((BITS (4, 11) & 0xF9) == 0x9)
  2417. /* LDR register offset, no write-back, up, pre indexed. */
  2418. LHPREUP ();
  2419. /* Continue with remaining instruction decoding. */
  2420. #endif
  2421. rhs = DPSRegRHS;
  2422. dest = LHS | rhs;
  2423. WRITESDEST (dest);
  2424. break;
  2425. case 0x1a: /* MOV reg */
  2426. #ifdef MODET
  2427. if (BITS (4, 11) == 0xB) {
  2428. /* STRH register offset, write-back, up, pre indexed. */
  2429. SHPREUPWB ();
  2430. break;
  2431. }
  2432. if (BITS (4, 7) == 0xD) {
  2433. Handle_Load_Double (state, instr);
  2434. break;
  2435. }
  2436. if (BITS (4, 7) == 0xF) {
  2437. Handle_Store_Double (state, instr);
  2438. break;
  2439. }
  2440. #endif
  2441. dest = DPRegRHS;
  2442. WRITEDEST (dest);
  2443. break;
  2444. case 0x1b: /* MOVS reg */
  2445. #ifdef MODET
  2446. if ((BITS (4, 11) & 0xF9) == 0x9)
  2447. /* LDR register offset, write-back, up, pre indexed. */
  2448. LHPREUPWB ();
  2449. /* Continue with remaining instruction decoding. */
  2450. #endif
  2451. dest = DPSRegRHS;
  2452. WRITESDEST (dest);
  2453. break;
  2454. case 0x1c: /* BIC reg */
  2455. #ifdef MODET
  2456. /* dyf add for STREXB */
  2457. if (state->is_v6) {
  2458. if (BITS (4, 7) == 0x9) {
  2459. if (handle_v6_insn (state, instr))
  2460. break;
  2461. }
  2462. }
  2463. if (BITS (4, 7) == 0xB) {
  2464. /* STRH immediate offset, no write-back, up, pre indexed. */
  2465. SHPREUP ();
  2466. break;
  2467. }
  2468. if (BITS (4, 7) == 0xD) {
  2469. Handle_Load_Double (state, instr);
  2470. break;
  2471. }
  2472. else if (BITS (4, 7) == 0xF) {
  2473. Handle_Store_Double (state, instr);
  2474. break;
  2475. }
  2476. #endif
  2477. rhs = DPRegRHS;
  2478. dest = LHS & ~rhs;
  2479. WRITEDEST (dest);
  2480. break;
  2481. case 0x1d: /* BICS reg */
  2482. #ifdef MODET
  2483. /* ladsh P=1 U=1 W=0 L=1 S=1 H=1 */
  2484. if (BITS(4, 7) == 0xF) {
  2485. temp = LHS + GetLS7RHS (state, instr);
  2486. LoadHalfWord (state, instr, temp, LSIGNED);
  2487. break;
  2488. }
  2489. if (BITS (4, 7) == 0xb) {
  2490. /* LDRH immediate offset, no write-back, up, pre indexed. */
  2491. temp = LHS + GetLS7RHS (state, instr);
  2492. LoadHalfWord (state, instr, temp, LUNSIGNED);
  2493. break;
  2494. }
  2495. if (BITS (4, 7) == 0xd) {
  2496. // alex-ykl fix: 2011-07-20 missing ldrsb instruction
  2497. temp = LHS + GetLS7RHS (state, instr);
  2498. LoadByte (state, instr, temp, LSIGNED);
  2499. break;
  2500. }
  2501. /* Continue with instruction decoding. */
  2502. /*if ((BITS (4, 7) & 0x9) == 0x9) */
  2503. if ((BITS (4, 7)) == 0x9) {
  2504. /* ldrexb */
  2505. if (state->is_v6) {
  2506. if (handle_v6_insn (state, instr))
  2507. break;
  2508. }
  2509. /* LDR immediate offset, no write-back, up, pre indexed. */
  2510. LHPREUP ();
  2511. }
  2512. #endif
  2513. rhs = DPSRegRHS;
  2514. dest = LHS & ~rhs;
  2515. WRITESDEST (dest);
  2516. break;
  2517. case 0x1e: /* MVN reg */
  2518. #ifdef MODET
  2519. if (BITS (4, 7) == 0xB) {
  2520. /* STRH immediate offset, write-back, up, pre indexed. */
  2521. SHPREUPWB ();
  2522. break;
  2523. }
  2524. if (BITS (4, 7) == 0xD) {
  2525. Handle_Load_Double (state, instr);
  2526. break;
  2527. }
  2528. if (BITS (4, 7) == 0xF) {
  2529. Handle_Store_Double (state, instr);
  2530. break;
  2531. }
  2532. #endif
  2533. dest = ~DPRegRHS;
  2534. WRITEDEST (dest);
  2535. break;
  2536. case 0x1f: /* MVNS reg */
  2537. #ifdef MODET
  2538. if ((BITS (4, 7) & 0x9) == 0x9)
  2539. /* LDR immediate offset, write-back, up, pre indexed. */
  2540. LHPREUPWB ();
  2541. /* Continue instruction decoding. */
  2542. #endif
  2543. dest = ~DPSRegRHS;
  2544. WRITESDEST (dest);
  2545. break;
  2546. /* Data Processing Immediate RHS Instructions. */
  2547. case 0x20: /* AND immed */
  2548. dest = LHS & DPImmRHS;
  2549. WRITEDEST (dest);
  2550. break;
  2551. case 0x21: /* ANDS immed */
  2552. DPSImmRHS;
  2553. dest = LHS & rhs;
  2554. WRITESDEST (dest);
  2555. break;
  2556. case 0x22: /* EOR immed */
  2557. dest = LHS ^ DPImmRHS;
  2558. WRITEDEST (dest);
  2559. break;
  2560. case 0x23: /* EORS immed */
  2561. DPSImmRHS;
  2562. dest = LHS ^ rhs;
  2563. WRITESDEST (dest);
  2564. break;
  2565. case 0x24: /* SUB immed */
  2566. dest = LHS - DPImmRHS;
  2567. WRITEDEST (dest);
  2568. break;
  2569. case 0x25: /* SUBS immed */
  2570. lhs = LHS;
  2571. rhs = DPImmRHS;
  2572. dest = lhs - rhs;
  2573. if ((lhs >= rhs) || ((rhs | lhs) >> 31)) {
  2574. ARMul_SubCarry (state, lhs, rhs,
  2575. dest);
  2576. ARMul_SubOverflow (state, lhs, rhs,
  2577. dest);
  2578. }
  2579. else {
  2580. CLEARC;
  2581. CLEARV;
  2582. }
  2583. WRITESDEST (dest);
  2584. break;
  2585. case 0x26: /* RSB immed */
  2586. dest = DPImmRHS - LHS;
  2587. WRITEDEST (dest);
  2588. break;
  2589. case 0x27: /* RSBS immed */
  2590. lhs = LHS;
  2591. rhs = DPImmRHS;
  2592. dest = rhs - lhs;
  2593. if ((rhs >= lhs) || ((rhs | lhs) >> 31)) {
  2594. ARMul_SubCarry (state, rhs, lhs,
  2595. dest);
  2596. ARMul_SubOverflow (state, rhs, lhs,
  2597. dest);
  2598. }
  2599. else {
  2600. CLEARC;
  2601. CLEARV;
  2602. }
  2603. WRITESDEST (dest);
  2604. break;
  2605. case 0x28: /* ADD immed */
  2606. dest = LHS + DPImmRHS;
  2607. WRITEDEST (dest);
  2608. break;
  2609. case 0x29: /* ADDS immed */
  2610. lhs = LHS;
  2611. rhs = DPImmRHS;
  2612. dest = lhs + rhs;
  2613. ASSIGNZ (dest == 0);
  2614. if ((lhs | rhs) >> 30) {
  2615. /* Possible C,V,N to set. */
  2616. ASSIGNN (NEG (dest));
  2617. ARMul_AddCarry (state, lhs, rhs,
  2618. dest);
  2619. ARMul_AddOverflow (state, lhs, rhs,
  2620. dest);
  2621. }
  2622. else {
  2623. CLEARN;
  2624. CLEARC;
  2625. CLEARV;
  2626. }
  2627. WRITESDEST (dest);
  2628. break;
  2629. case 0x2a: /* ADC immed */
  2630. dest = LHS + DPImmRHS + CFLAG;
  2631. WRITEDEST (dest);
  2632. break;
  2633. case 0x2b: /* ADCS immed */
  2634. lhs = LHS;
  2635. rhs = DPImmRHS;
  2636. dest = lhs + rhs + CFLAG;
  2637. ASSIGNZ (dest == 0);
  2638. if ((lhs | rhs) >> 30) {
  2639. /* Possible C,V,N to set. */
  2640. ASSIGNN (NEG (dest));
  2641. ARMul_AddCarry (state, lhs, rhs,
  2642. dest);
  2643. ARMul_AddOverflow (state, lhs, rhs,
  2644. dest);
  2645. }
  2646. else {
  2647. CLEARN;
  2648. CLEARC;
  2649. CLEARV;
  2650. }
  2651. WRITESDEST (dest);
  2652. break;
  2653. case 0x2c: /* SBC immed */
  2654. dest = LHS - DPImmRHS - !CFLAG;
  2655. WRITEDEST (dest);
  2656. break;
  2657. case 0x2d: /* SBCS immed */
  2658. lhs = LHS;
  2659. rhs = DPImmRHS;
  2660. dest = lhs - rhs - !CFLAG;
  2661. if ((lhs >= rhs) || ((rhs | lhs) >> 31)) {
  2662. ARMul_SubCarry (state, lhs, rhs,
  2663. dest);
  2664. ARMul_SubOverflow (state, lhs, rhs,
  2665. dest);
  2666. }
  2667. else {
  2668. CLEARC;
  2669. CLEARV;
  2670. }
  2671. WRITESDEST (dest);
  2672. break;
  2673. case 0x2e: /* RSC immed */
  2674. dest = DPImmRHS - LHS - !CFLAG;
  2675. WRITEDEST (dest);
  2676. break;
  2677. case 0x2f: /* RSCS immed */
  2678. lhs = LHS;
  2679. rhs = DPImmRHS;
  2680. dest = rhs - lhs - !CFLAG;
  2681. if ((rhs >= lhs) || ((rhs | lhs) >> 31)) {
  2682. ARMul_SubCarry (state, rhs, lhs,
  2683. dest);
  2684. ARMul_SubOverflow (state, rhs, lhs,
  2685. dest);
  2686. }
  2687. else {
  2688. CLEARC;
  2689. CLEARV;
  2690. }
  2691. WRITESDEST (dest);
  2692. break;
  2693. case 0x30: /* TST immed */
  2694. /* shenoubang 2012-3-14*/
  2695. if (state->is_v6) { /* movw, ARMV6, ARMv7 */
  2696. dest ^= dest;
  2697. dest = BITS(16, 19);
  2698. dest = ((dest<<12) | BITS(0, 11));
  2699. WRITEDEST(dest);
  2700. //SKYEYE_DBG("In %s, line = %d, pc = 0x%x, instr = 0x%x, R[0:11]: 0x%x, R[16:19]: 0x%x, R[%d]:0x%x\n",
  2701. // __func__, __LINE__, pc, instr, BITS(0, 11), BITS(16, 19), DESTReg, state->Reg[DESTReg]);
  2702. break;
  2703. }
  2704. else {
  2705. UNDEF_Test;
  2706. break;
  2707. }
  2708. case 0x31: /* TSTP immed */
  2709. if (DESTReg == 15) {
  2710. /* TSTP immed. */
  2711. #ifdef MODE32
  2712. state->Cpsr = GETSPSR (state->Bank);
  2713. ARMul_CPSRAltered (state);
  2714. #else
  2715. temp = LHS & DPImmRHS;
  2716. SETR15PSR (temp);
  2717. #endif
  2718. }
  2719. else {
  2720. /* TST immed. */
  2721. DPSImmRHS;
  2722. dest = LHS & rhs;
  2723. ARMul_NegZero (state, dest);
  2724. }
  2725. break;
  2726. case 0x32: /* TEQ immed and MSR immed to CPSR */
  2727. if (DESTReg == 15)
  2728. /* MSR immed to CPSR. */
  2729. ARMul_FixCPSR (state, instr,
  2730. DPImmRHS);
  2731. else
  2732. UNDEF_Test;
  2733. break;
  2734. case 0x33: /* TEQP immed */
  2735. if (DESTReg == 15) {
  2736. /* TEQP immed. */
  2737. #ifdef MODE32
  2738. state->Cpsr = GETSPSR (state->Bank);
  2739. ARMul_CPSRAltered (state);
  2740. #else
  2741. temp = LHS ^ DPImmRHS;
  2742. SETR15PSR (temp);
  2743. #endif
  2744. }
  2745. else {
  2746. DPSImmRHS; /* TEQ immed */
  2747. dest = LHS ^ rhs;
  2748. ARMul_NegZero (state, dest);
  2749. }
  2750. break;
  2751. case 0x34: /* CMP immed */
  2752. UNDEF_Test;
  2753. break;
  2754. case 0x35: /* CMPP immed */
  2755. if (DESTReg == 15) {
  2756. /* CMPP immed. */
  2757. #ifdef MODE32
  2758. state->Cpsr = GETSPSR (state->Bank);
  2759. ARMul_CPSRAltered (state);
  2760. #else
  2761. temp = LHS - DPImmRHS;
  2762. SETR15PSR (temp);
  2763. #endif
  2764. break;
  2765. }
  2766. else {
  2767. /* CMP immed. */
  2768. lhs = LHS;
  2769. rhs = DPImmRHS;
  2770. dest = lhs - rhs;
  2771. ARMul_NegZero (state, dest);
  2772. if ((lhs >= rhs)
  2773. || ((rhs | lhs) >> 31)) {
  2774. ARMul_SubCarry (state, lhs,
  2775. rhs, dest);
  2776. ARMul_SubOverflow (state, lhs,
  2777. rhs, dest);
  2778. }
  2779. else {
  2780. CLEARC;
  2781. CLEARV;
  2782. }
  2783. }
  2784. break;
  2785. case 0x36: /* CMN immed and MSR immed to SPSR */
  2786. if (DESTReg == 15)
  2787. ARMul_FixSPSR (state, instr,
  2788. DPImmRHS);
  2789. else
  2790. UNDEF_Test;
  2791. break;
  2792. case 0x37: /* CMNP immed. */
  2793. if (DESTReg == 15) {
  2794. /* CMNP immed. */
  2795. #ifdef MODE32
  2796. state->Cpsr = GETSPSR (state->Bank);
  2797. ARMul_CPSRAltered (state);
  2798. #else
  2799. temp = LHS + DPImmRHS;
  2800. SETR15PSR (temp);
  2801. #endif
  2802. break;
  2803. }
  2804. else {
  2805. /* CMN immed. */
  2806. lhs = LHS;
  2807. rhs = DPImmRHS;
  2808. dest = lhs + rhs;
  2809. ASSIGNZ (dest == 0);
  2810. if ((lhs | rhs) >> 30) {
  2811. /* Possible C,V,N to set. */
  2812. ASSIGNN (NEG (dest));
  2813. ARMul_AddCarry (state, lhs,
  2814. rhs, dest);
  2815. ARMul_AddOverflow (state, lhs,
  2816. rhs, dest);
  2817. }
  2818. else {
  2819. CLEARN;
  2820. CLEARC;
  2821. CLEARV;
  2822. }
  2823. }
  2824. break;
  2825. case 0x38: /* ORR immed. */
  2826. dest = LHS | DPImmRHS;
  2827. WRITEDEST (dest);
  2828. break;
  2829. case 0x39: /* ORRS immed. */
  2830. DPSImmRHS;
  2831. dest = LHS | rhs;
  2832. WRITESDEST (dest);
  2833. break;
  2834. case 0x3a: /* MOV immed. */
  2835. dest = DPImmRHS;
  2836. WRITEDEST (dest);
  2837. break;
  2838. case 0x3b: /* MOVS immed. */
  2839. DPSImmRHS;
  2840. WRITESDEST (rhs);
  2841. break;
  2842. case 0x3c: /* BIC immed. */
  2843. dest = LHS & ~DPImmRHS;
  2844. WRITEDEST (dest);
  2845. break;
  2846. case 0x3d: /* BICS immed. */
  2847. DPSImmRHS;
  2848. dest = LHS & ~rhs;
  2849. WRITESDEST (dest);
  2850. break;
  2851. case 0x3e: /* MVN immed. */
  2852. dest = ~DPImmRHS;
  2853. WRITEDEST (dest);
  2854. break;
  2855. case 0x3f: /* MVNS immed. */
  2856. DPSImmRHS;
  2857. WRITESDEST (~rhs);
  2858. break;
  2859. /* Single Data Transfer Immediate RHS Instructions. */
  2860. case 0x40: /* Store Word, No WriteBack, Post Dec, Immed. */
  2861. lhs = LHS;
  2862. if (StoreWord (state, instr, lhs))
  2863. LSBase = lhs - LSImmRHS;
  2864. break;
  2865. case 0x41: /* Load Word, No WriteBack, Post Dec, Immed. */
  2866. lhs = LHS;
  2867. if (LoadWord (state, instr, lhs))
  2868. LSBase = lhs - LSImmRHS;
  2869. break;
  2870. case 0x42: /* Store Word, WriteBack, Post Dec, Immed. */
  2871. UNDEF_LSRBaseEQDestWb;
  2872. UNDEF_LSRPCBaseWb;
  2873. lhs = LHS;
  2874. temp = lhs - LSImmRHS;
  2875. state->NtransSig = LOW;
  2876. if (StoreWord (state, instr, lhs))
  2877. LSBase = temp;
  2878. state->NtransSig =
  2879. (state->Mode & 3) ? HIGH : LOW;
  2880. break;
  2881. case 0x43: /* Load Word, WriteBack, Post Dec, Immed. */
  2882. UNDEF_LSRBaseEQDestWb;
  2883. UNDEF_LSRPCBaseWb;
  2884. lhs = LHS;
  2885. state->NtransSig = LOW;
  2886. if (LoadWord (state, instr, lhs))
  2887. LSBase = lhs - LSImmRHS;
  2888. state->NtransSig =
  2889. (state->Mode & 3) ? HIGH : LOW;
  2890. break;
  2891. case 0x44: /* Store Byte, No WriteBack, Post Dec, Immed. */
  2892. lhs = LHS;
  2893. if (StoreByte (state, instr, lhs))
  2894. LSBase = lhs - LSImmRHS;
  2895. break;
  2896. case 0x45: /* Load Byte, No WriteBack, Post Dec, Immed. */
  2897. lhs = LHS;
  2898. if (LoadByte (state, instr, lhs, LUNSIGNED))
  2899. LSBase = lhs - LSImmRHS;
  2900. break;
  2901. case 0x46: /* Store Byte, WriteBack, Post Dec, Immed. */
  2902. UNDEF_LSRBaseEQDestWb;
  2903. UNDEF_LSRPCBaseWb;
  2904. lhs = LHS;
  2905. state->NtransSig = LOW;
  2906. if (StoreByte (state, instr, lhs))
  2907. LSBase = lhs - LSImmRHS;
  2908. state->NtransSig =
  2909. (state->Mode & 3) ? HIGH : LOW;
  2910. break;
  2911. case 0x47: /* Load Byte, WriteBack, Post Dec, Immed. */
  2912. UNDEF_LSRBaseEQDestWb;
  2913. UNDEF_LSRPCBaseWb;
  2914. lhs = LHS;
  2915. state->NtransSig = LOW;
  2916. if (LoadByte (state, instr, lhs, LUNSIGNED))
  2917. LSBase = lhs - LSImmRHS;
  2918. state->NtransSig =
  2919. (state->Mode & 3) ? HIGH : LOW;
  2920. break;
  2921. case 0x48: /* Store Word, No WriteBack, Post Inc, Immed. */
  2922. lhs = LHS;
  2923. if (StoreWord (state, instr, lhs))
  2924. LSBase = lhs + LSImmRHS;
  2925. break;
  2926. case 0x49: /* Load Word, No WriteBack, Post Inc, Immed. */
  2927. lhs = LHS;
  2928. if (LoadWord (state, instr, lhs))
  2929. LSBase = lhs + LSImmRHS;
  2930. break;
  2931. case 0x4a: /* Store Word, WriteBack, Post Inc, Immed. */
  2932. UNDEF_LSRBaseEQDestWb;
  2933. UNDEF_LSRPCBaseWb;
  2934. lhs = LHS;
  2935. state->NtransSig = LOW;
  2936. if (StoreWord (state, instr, lhs))
  2937. LSBase = lhs + LSImmRHS;
  2938. state->NtransSig =
  2939. (state->Mode & 3) ? HIGH : LOW;
  2940. break;
  2941. case 0x4b: /* Load Word, WriteBack, Post Inc, Immed. */
  2942. UNDEF_LSRBaseEQDestWb;
  2943. UNDEF_LSRPCBaseWb;
  2944. lhs = LHS;
  2945. state->NtransSig = LOW;
  2946. if (LoadWord (state, instr, lhs))
  2947. LSBase = lhs + LSImmRHS;
  2948. state->NtransSig =
  2949. (state->Mode & 3) ? HIGH : LOW;
  2950. break;
  2951. case 0x4c: /* Store Byte, No WriteBack, Post Inc, Immed. */
  2952. lhs = LHS;
  2953. if (StoreByte (state, instr, lhs))
  2954. LSBase = lhs + LSImmRHS;
  2955. break;
  2956. case 0x4d: /* Load Byte, No WriteBack, Post Inc, Immed. */
  2957. lhs = LHS;
  2958. if (LoadByte (state, instr, lhs, LUNSIGNED))
  2959. LSBase = lhs + LSImmRHS;
  2960. break;
  2961. case 0x4e: /* Store Byte, WriteBack, Post Inc, Immed. */
  2962. UNDEF_LSRBaseEQDestWb;
  2963. UNDEF_LSRPCBaseWb;
  2964. lhs = LHS;
  2965. state->NtransSig = LOW;
  2966. if (StoreByte (state, instr, lhs))
  2967. LSBase = lhs + LSImmRHS;
  2968. state->NtransSig =
  2969. (state->Mode & 3) ? HIGH : LOW;
  2970. break;
  2971. case 0x4f: /* Load Byte, WriteBack, Post Inc, Immed. */
  2972. UNDEF_LSRBaseEQDestWb;
  2973. UNDEF_LSRPCBaseWb;
  2974. lhs = LHS;
  2975. state->NtransSig = LOW;
  2976. if (LoadByte (state, instr, lhs, LUNSIGNED))
  2977. LSBase = lhs + LSImmRHS;
  2978. state->NtransSig =
  2979. (state->Mode & 3) ? HIGH : LOW;
  2980. break;
  2981. case 0x50: /* Store Word, No WriteBack, Pre Dec, Immed. */
  2982. (void) StoreWord (state, instr,
  2983. LHS - LSImmRHS);
  2984. break;
  2985. case 0x51: /* Load Word, No WriteBack, Pre Dec, Immed. */
  2986. (void) LoadWord (state, instr,
  2987. LHS - LSImmRHS);
  2988. break;
  2989. case 0x52: /* Store Word, WriteBack, Pre Dec, Immed. */
  2990. UNDEF_LSRBaseEQDestWb;
  2991. UNDEF_LSRPCBaseWb;
  2992. temp = LHS - LSImmRHS;
  2993. if (StoreWord (state, instr, temp))
  2994. LSBase = temp;
  2995. break;
  2996. case 0x53: /* Load Word, WriteBack, Pre Dec, Immed. */
  2997. UNDEF_LSRBaseEQDestWb;
  2998. UNDEF_LSRPCBaseWb;
  2999. temp = LHS - LSImmRHS;
  3000. if (LoadWord (state, instr, temp))
  3001. LSBase = temp;
  3002. break;
  3003. case 0x54: /* Store Byte, No WriteBack, Pre Dec, Immed. */
  3004. (void) StoreByte (state, instr,
  3005. LHS - LSImmRHS);
  3006. break;
  3007. case 0x55: /* Load Byte, No WriteBack, Pre Dec, Immed. */
  3008. (void) LoadByte (state, instr, LHS - LSImmRHS,
  3009. LUNSIGNED);
  3010. break;
  3011. case 0x56: /* Store Byte, WriteBack, Pre Dec, Immed. */
  3012. UNDEF_LSRBaseEQDestWb;
  3013. UNDEF_LSRPCBaseWb;
  3014. temp = LHS - LSImmRHS;
  3015. if (StoreByte (state, instr, temp))
  3016. LSBase = temp;
  3017. break;
  3018. case 0x57: /* Load Byte, WriteBack, Pre Dec, Immed. */
  3019. UNDEF_LSRBaseEQDestWb;
  3020. UNDEF_LSRPCBaseWb;
  3021. temp = LHS - LSImmRHS;
  3022. if (LoadByte (state, instr, temp, LUNSIGNED))
  3023. LSBase = temp;
  3024. break;
  3025. case 0x58: /* Store Word, No WriteBack, Pre Inc, Immed. */
  3026. (void) StoreWord (state, instr,
  3027. LHS + LSImmRHS);
  3028. break;
  3029. case 0x59: /* Load Word, No WriteBack, Pre Inc, Immed. */
  3030. (void) LoadWord (state, instr,
  3031. LHS + LSImmRHS);
  3032. break;
  3033. case 0x5a: /* Store Word, WriteBack, Pre Inc, Immed. */
  3034. UNDEF_LSRBaseEQDestWb;
  3035. UNDEF_LSRPCBaseWb;
  3036. temp = LHS + LSImmRHS;
  3037. if (StoreWord (state, instr, temp))
  3038. LSBase = temp;
  3039. break;
  3040. case 0x5b: /* Load Word, WriteBack, Pre Inc, Immed. */
  3041. UNDEF_LSRBaseEQDestWb;
  3042. UNDEF_LSRPCBaseWb;
  3043. temp = LHS + LSImmRHS;
  3044. if (LoadWord (state, instr, temp))
  3045. LSBase = temp;
  3046. break;
  3047. case 0x5c: /* Store Byte, No WriteBack, Pre Inc, Immed. */
  3048. (void) StoreByte (state, instr,
  3049. LHS + LSImmRHS);
  3050. break;
  3051. case 0x5d: /* Load Byte, No WriteBack, Pre Inc, Immed. */
  3052. (void) LoadByte (state, instr, LHS + LSImmRHS,
  3053. LUNSIGNED);
  3054. break;
  3055. case 0x5e: /* Store Byte, WriteBack, Pre Inc, Immed. */
  3056. UNDEF_LSRBaseEQDestWb;
  3057. UNDEF_LSRPCBaseWb;
  3058. temp = LHS + LSImmRHS;
  3059. if (StoreByte (state, instr, temp))
  3060. LSBase = temp;
  3061. break;
  3062. case 0x5f: /* Load Byte, WriteBack, Pre Inc, Immed. */
  3063. UNDEF_LSRBaseEQDestWb;
  3064. UNDEF_LSRPCBaseWb;
  3065. temp = LHS + LSImmRHS;
  3066. if (LoadByte (state, instr, temp, LUNSIGNED))
  3067. LSBase = temp;
  3068. break;
  3069. /* Single Data Transfer Register RHS Instructions. */
  3070. case 0x60: /* Store Word, No WriteBack, Post Dec, Reg. */
  3071. if (BIT (4)) {
  3072. ARMul_UndefInstr (state, instr);
  3073. break;
  3074. }
  3075. UNDEF_LSRBaseEQOffWb;
  3076. UNDEF_LSRBaseEQDestWb;
  3077. UNDEF_LSRPCBaseWb;
  3078. UNDEF_LSRPCOffWb;
  3079. lhs = LHS;
  3080. if (StoreWord (state, instr, lhs))
  3081. LSBase = lhs - LSRegRHS;
  3082. break;
  3083. case 0x61: /* Load Word, No WriteBack, Post Dec, Reg. */
  3084. if (BIT (4)) {
  3085. #ifdef MODE32
  3086. if (state->is_v6
  3087. && handle_v6_insn (state, instr))
  3088. break;
  3089. #endif
  3090. ARMul_UndefInstr (state, instr);
  3091. break;
  3092. }
  3093. UNDEF_LSRBaseEQOffWb;
  3094. UNDEF_LSRBaseEQDestWb;
  3095. UNDEF_LSRPCBaseWb;
  3096. UNDEF_LSRPCOffWb;
  3097. lhs = LHS;
  3098. temp = lhs - LSRegRHS;
  3099. if (LoadWord (state, instr, lhs))
  3100. LSBase = temp;
  3101. break;
  3102. case 0x62: /* Store Word, WriteBack, Post Dec, Reg. */
  3103. if (BIT (4)) {
  3104. #ifdef MODE32
  3105. if (state->is_v6
  3106. && handle_v6_insn (state, instr))
  3107. break;
  3108. #endif
  3109. ARMul_UndefInstr (state, instr);
  3110. break;
  3111. }
  3112. UNDEF_LSRBaseEQOffWb;
  3113. UNDEF_LSRBaseEQDestWb;
  3114. UNDEF_LSRPCBaseWb;
  3115. UNDEF_LSRPCOffWb;
  3116. lhs = LHS;
  3117. state->NtransSig = LOW;
  3118. if (StoreWord (state, instr, lhs))
  3119. LSBase = lhs - LSRegRHS;
  3120. state->NtransSig =
  3121. (state->Mode & 3) ? HIGH : LOW;
  3122. break;
  3123. case 0x63: /* Load Word, WriteBack, Post Dec, Reg. */
  3124. if (BIT (4)) {
  3125. #ifdef MODE32
  3126. if (state->is_v6
  3127. && handle_v6_insn (state, instr))
  3128. break;
  3129. #endif
  3130. ARMul_UndefInstr (state, instr);
  3131. break;
  3132. }
  3133. UNDEF_LSRBaseEQOffWb;
  3134. UNDEF_LSRBaseEQDestWb;
  3135. UNDEF_LSRPCBaseWb;
  3136. UNDEF_LSRPCOffWb;
  3137. lhs = LHS;
  3138. temp = lhs - LSRegRHS;
  3139. state->NtransSig = LOW;
  3140. if (LoadWord (state, instr, lhs))
  3141. LSBase = temp;
  3142. state->NtransSig =
  3143. (state->Mode & 3) ? HIGH : LOW;
  3144. break;
  3145. case 0x64: /* Store Byte, No WriteBack, Post Dec, Reg. */
  3146. if (BIT (4)) {
  3147. ARMul_UndefInstr (state, instr);
  3148. break;
  3149. }
  3150. UNDEF_LSRBaseEQOffWb;
  3151. UNDEF_LSRBaseEQDestWb;
  3152. UNDEF_LSRPCBaseWb;
  3153. UNDEF_LSRPCOffWb;
  3154. lhs = LHS;
  3155. if (StoreByte (state, instr, lhs))
  3156. LSBase = lhs - LSRegRHS;
  3157. break;
  3158. case 0x65: /* Load Byte, No WriteBack, Post Dec, Reg. */
  3159. if (BIT (4)) {
  3160. #ifdef MODE32
  3161. if (state->is_v6
  3162. && handle_v6_insn (state, instr))
  3163. break;
  3164. #endif
  3165. ARMul_UndefInstr (state, instr);
  3166. break;
  3167. }
  3168. UNDEF_LSRBaseEQOffWb;
  3169. UNDEF_LSRBaseEQDestWb;
  3170. UNDEF_LSRPCBaseWb;
  3171. UNDEF_LSRPCOffWb;
  3172. lhs = LHS;
  3173. temp = lhs - LSRegRHS;
  3174. if (LoadByte (state, instr, lhs, LUNSIGNED))
  3175. LSBase = temp;
  3176. break;
  3177. case 0x66: /* Store Byte, WriteBack, Post Dec, Reg. */
  3178. if (BIT (4)) {
  3179. #ifdef MODE32
  3180. if (state->is_v6
  3181. && handle_v6_insn (state, instr))
  3182. break;
  3183. #endif
  3184. ARMul_UndefInstr (state, instr);
  3185. break;
  3186. }
  3187. UNDEF_LSRBaseEQOffWb;
  3188. UNDEF_LSRBaseEQDestWb;
  3189. UNDEF_LSRPCBaseWb;
  3190. UNDEF_LSRPCOffWb;
  3191. lhs = LHS;
  3192. state->NtransSig = LOW;
  3193. if (StoreByte (state, instr, lhs))
  3194. LSBase = lhs - LSRegRHS;
  3195. state->NtransSig =
  3196. (state->Mode & 3) ? HIGH : LOW;
  3197. break;
  3198. case 0x67: /* Load Byte, WriteBack, Post Dec, Reg. */
  3199. if (BIT (4)) {
  3200. #ifdef MODE32
  3201. if (state->is_v6
  3202. && handle_v6_insn (state, instr))
  3203. break;
  3204. #endif
  3205. ARMul_UndefInstr (state, instr);
  3206. break;
  3207. }
  3208. UNDEF_LSRBaseEQOffWb;
  3209. UNDEF_LSRBaseEQDestWb;
  3210. UNDEF_LSRPCBaseWb;
  3211. UNDEF_LSRPCOffWb;
  3212. lhs = LHS;
  3213. temp = lhs - LSRegRHS;
  3214. state->NtransSig = LOW;
  3215. if (LoadByte (state, instr, lhs, LUNSIGNED))
  3216. LSBase = temp;
  3217. state->NtransSig =
  3218. (state->Mode & 3) ? HIGH : LOW;
  3219. break;
  3220. case 0x68: /* Store Word, No WriteBack, Post Inc, Reg. */
  3221. if (BIT (4)) {
  3222. #ifdef MODE32
  3223. if (state->is_v6
  3224. && handle_v6_insn (state, instr))
  3225. break;
  3226. #endif
  3227. ARMul_UndefInstr (state, instr);
  3228. break;
  3229. }
  3230. UNDEF_LSRBaseEQOffWb;
  3231. UNDEF_LSRBaseEQDestWb;
  3232. UNDEF_LSRPCBaseWb;
  3233. UNDEF_LSRPCOffWb;
  3234. lhs = LHS;
  3235. if (StoreWord (state, instr, lhs))
  3236. LSBase = lhs + LSRegRHS;
  3237. break;
  3238. case 0x69: /* Load Word, No WriteBack, Post Inc, Reg. */
  3239. if (BIT (4)) {
  3240. ARMul_UndefInstr (state, instr);
  3241. break;
  3242. }
  3243. UNDEF_LSRBaseEQOffWb;
  3244. UNDEF_LSRBaseEQDestWb;
  3245. UNDEF_LSRPCBaseWb;
  3246. UNDEF_LSRPCOffWb;
  3247. lhs = LHS;
  3248. temp = lhs + LSRegRHS;
  3249. if (LoadWord (state, instr, lhs))
  3250. LSBase = temp;
  3251. break;
  3252. case 0x6a: /* Store Word, WriteBack, Post Inc, Reg. */
  3253. if (BIT (4)) {
  3254. #ifdef MODE32
  3255. if (state->is_v6
  3256. && handle_v6_insn (state, instr))
  3257. break;
  3258. #endif
  3259. ARMul_UndefInstr (state, instr);
  3260. break;
  3261. }
  3262. UNDEF_LSRBaseEQOffWb;
  3263. UNDEF_LSRBaseEQDestWb;
  3264. UNDEF_LSRPCBaseWb;
  3265. UNDEF_LSRPCOffWb;
  3266. lhs = LHS;
  3267. state->NtransSig = LOW;
  3268. if (StoreWord (state, instr, lhs))
  3269. LSBase = lhs + LSRegRHS;
  3270. state->NtransSig =
  3271. (state->Mode & 3) ? HIGH : LOW;
  3272. break;
  3273. case 0x6b: /* Load Word, WriteBack, Post Inc, Reg. */
  3274. if (BIT (4)) {
  3275. #ifdef MODE32
  3276. if (state->is_v6
  3277. && handle_v6_insn (state, instr))
  3278. break;
  3279. #endif
  3280. ARMul_UndefInstr (state, instr);
  3281. break;
  3282. }
  3283. UNDEF_LSRBaseEQOffWb;
  3284. UNDEF_LSRBaseEQDestWb;
  3285. UNDEF_LSRPCBaseWb;
  3286. UNDEF_LSRPCOffWb;
  3287. lhs = LHS;
  3288. temp = lhs + LSRegRHS;
  3289. state->NtransSig = LOW;
  3290. if (LoadWord (state, instr, lhs))
  3291. LSBase = temp;
  3292. state->NtransSig =
  3293. (state->Mode & 3) ? HIGH : LOW;
  3294. break;
  3295. case 0x6c: /* Store Byte, No WriteBack, Post Inc, Reg. */
  3296. if (BIT (4)) {
  3297. #ifdef MODE32
  3298. if (state->is_v6
  3299. && handle_v6_insn (state, instr))
  3300. break;
  3301. #endif
  3302. ARMul_UndefInstr (state, instr);
  3303. break;
  3304. }
  3305. UNDEF_LSRBaseEQOffWb;
  3306. UNDEF_LSRBaseEQDestWb;
  3307. UNDEF_LSRPCBaseWb;
  3308. UNDEF_LSRPCOffWb;
  3309. lhs = LHS;
  3310. if (StoreByte (state, instr, lhs))
  3311. LSBase = lhs + LSRegRHS;
  3312. break;
  3313. case 0x6d: /* Load Byte, No WriteBack, Post Inc, Reg. */
  3314. if (BIT (4)) {
  3315. ARMul_UndefInstr (state, instr);
  3316. break;
  3317. }
  3318. UNDEF_LSRBaseEQOffWb;
  3319. UNDEF_LSRBaseEQDestWb;
  3320. UNDEF_LSRPCBaseWb;
  3321. UNDEF_LSRPCOffWb;
  3322. lhs = LHS;
  3323. temp = lhs + LSRegRHS;
  3324. if (LoadByte (state, instr, lhs, LUNSIGNED))
  3325. LSBase = temp;
  3326. break;
  3327. case 0x6e: /* Store Byte, WriteBack, Post Inc, Reg. */
  3328. #if 0
  3329. if (state->is_v6) {
  3330. int Rm = 0;
  3331. /* utxb */
  3332. if (BITS(15, 19) == 0xf && BITS(4, 7) == 0x7) {
  3333. Rm = (RHS >> (8 * BITS(10, 11))) & 0xff;
  3334. DEST = Rm;
  3335. }
  3336. }
  3337. #endif
  3338. if (BIT (4)) {
  3339. #ifdef MODE32
  3340. if (state->is_v6
  3341. && handle_v6_insn (state, instr))
  3342. break;
  3343. #endif
  3344. ARMul_UndefInstr (state, instr);
  3345. break;
  3346. }
  3347. UNDEF_LSRBaseEQOffWb;
  3348. UNDEF_LSRBaseEQDestWb;
  3349. UNDEF_LSRPCBaseWb;
  3350. UNDEF_LSRPCOffWb;
  3351. lhs = LHS;
  3352. state->NtransSig = LOW;
  3353. if (StoreByte (state, instr, lhs))
  3354. LSBase = lhs + LSRegRHS;
  3355. state->NtransSig =
  3356. (state->Mode & 3) ? HIGH : LOW;
  3357. break;
  3358. case 0x6f: /* Load Byte, WriteBack, Post Inc, Reg. */
  3359. if (BIT (4)) {
  3360. #ifdef MODE32
  3361. if (state->is_v6
  3362. && handle_v6_insn (state, instr))
  3363. break;
  3364. #endif
  3365. ARMul_UndefInstr (state, instr);
  3366. break;
  3367. }
  3368. UNDEF_LSRBaseEQOffWb;
  3369. UNDEF_LSRBaseEQDestWb;
  3370. UNDEF_LSRPCBaseWb;
  3371. UNDEF_LSRPCOffWb;
  3372. lhs = LHS;
  3373. temp = lhs + LSRegRHS;
  3374. state->NtransSig = LOW;
  3375. if (LoadByte (state, instr, lhs, LUNSIGNED))
  3376. LSBase = temp;
  3377. state->NtransSig =
  3378. (state->Mode & 3) ? HIGH : LOW;
  3379. break;
  3380. case 0x70: /* Store Word, No WriteBack, Pre Dec, Reg. */
  3381. if (BIT (4)) {
  3382. #ifdef MODE32
  3383. if (state->is_v6
  3384. && handle_v6_insn (state, instr))
  3385. break;
  3386. #endif
  3387. ARMul_UndefInstr (state, instr);
  3388. break;
  3389. }
  3390. (void) StoreWord (state, instr,
  3391. LHS - LSRegRHS);
  3392. break;
  3393. case 0x71: /* Load Word, No WriteBack, Pre Dec, Reg. */
  3394. if (BIT (4)) {
  3395. ARMul_UndefInstr (state, instr);
  3396. break;
  3397. }
  3398. (void) LoadWord (state, instr,
  3399. LHS - LSRegRHS);
  3400. break;
  3401. case 0x72: /* Store Word, WriteBack, Pre Dec, Reg. */
  3402. if (BIT (4)) {
  3403. ARMul_UndefInstr (state, instr);
  3404. break;
  3405. }
  3406. UNDEF_LSRBaseEQOffWb;
  3407. UNDEF_LSRBaseEQDestWb;
  3408. UNDEF_LSRPCBaseWb;
  3409. UNDEF_LSRPCOffWb;
  3410. temp = LHS - LSRegRHS;
  3411. if (StoreWord (state, instr, temp))
  3412. LSBase = temp;
  3413. break;
  3414. case 0x73: /* Load Word, WriteBack, Pre Dec, Reg. */
  3415. if (BIT (4)) {
  3416. ARMul_UndefInstr (state, instr);
  3417. break;
  3418. }
  3419. UNDEF_LSRBaseEQOffWb;
  3420. UNDEF_LSRBaseEQDestWb;
  3421. UNDEF_LSRPCBaseWb;
  3422. UNDEF_LSRPCOffWb;
  3423. temp = LHS - LSRegRHS;
  3424. if (LoadWord (state, instr, temp))
  3425. LSBase = temp;
  3426. break;
  3427. case 0x74: /* Store Byte, No WriteBack, Pre Dec, Reg. */
  3428. if (BIT (4)) {
  3429. #ifdef MODE32
  3430. if (state->is_v6
  3431. && handle_v6_insn (state, instr))
  3432. break;
  3433. #endif
  3434. ARMul_UndefInstr (state, instr);
  3435. break;
  3436. }
  3437. (void) StoreByte (state, instr,
  3438. LHS - LSRegRHS);
  3439. break;
  3440. case 0x75: /* Load Byte, No WriteBack, Pre Dec, Reg. */
  3441. if (BIT (4)) {
  3442. #ifdef MODE32
  3443. if (state->is_v6
  3444. && handle_v6_insn (state, instr))
  3445. break;
  3446. #endif
  3447. ARMul_UndefInstr (state, instr);
  3448. break;
  3449. }
  3450. (void) LoadByte (state, instr, LHS - LSRegRHS,
  3451. LUNSIGNED);
  3452. break;
  3453. case 0x76: /* Store Byte, WriteBack, Pre Dec, Reg. */
  3454. if (BIT (4)) {
  3455. ARMul_UndefInstr (state, instr);
  3456. break;
  3457. }
  3458. UNDEF_LSRBaseEQOffWb;
  3459. UNDEF_LSRBaseEQDestWb;
  3460. UNDEF_LSRPCBaseWb;
  3461. UNDEF_LSRPCOffWb;
  3462. temp = LHS - LSRegRHS;
  3463. if (StoreByte (state, instr, temp))
  3464. LSBase = temp;
  3465. break;
  3466. case 0x77: /* Load Byte, WriteBack, Pre Dec, Reg. */
  3467. if (BIT (4)) {
  3468. ARMul_UndefInstr (state, instr);
  3469. break;
  3470. }
  3471. UNDEF_LSRBaseEQOffWb;
  3472. UNDEF_LSRBaseEQDestWb;
  3473. UNDEF_LSRPCBaseWb;
  3474. UNDEF_LSRPCOffWb;
  3475. temp = LHS - LSRegRHS;
  3476. if (LoadByte (state, instr, temp, LUNSIGNED))
  3477. LSBase = temp;
  3478. break;
  3479. case 0x78: /* Store Word, No WriteBack, Pre Inc, Reg. */
  3480. if (BIT (4)) {
  3481. #ifdef MODE32
  3482. if (state->is_v6
  3483. && handle_v6_insn (state, instr))
  3484. break;
  3485. #endif
  3486. ARMul_UndefInstr (state, instr);
  3487. break;
  3488. }
  3489. (void) StoreWord (state, instr,
  3490. LHS + LSRegRHS);
  3491. break;
  3492. case 0x79: /* Load Word, No WriteBack, Pre Inc, Reg. */
  3493. if (BIT (4)) {
  3494. ARMul_UndefInstr (state, instr);
  3495. break;
  3496. }
  3497. (void) LoadWord (state, instr,
  3498. LHS + LSRegRHS);
  3499. break;
  3500. case 0x7a: /* Store Word, WriteBack, Pre Inc, Reg. */
  3501. if (BIT (4)) {
  3502. #ifdef MODE32
  3503. if (state->is_v6
  3504. && handle_v6_insn (state, instr))
  3505. break;
  3506. #endif
  3507. ARMul_UndefInstr (state, instr);
  3508. break;
  3509. }
  3510. UNDEF_LSRBaseEQOffWb;
  3511. UNDEF_LSRBaseEQDestWb;
  3512. UNDEF_LSRPCBaseWb;
  3513. UNDEF_LSRPCOffWb;
  3514. temp = LHS + LSRegRHS;
  3515. if (StoreWord (state, instr, temp))
  3516. LSBase = temp;
  3517. break;
  3518. case 0x7b: /* Load Word, WriteBack, Pre Inc, Reg. */
  3519. if (BIT (4)) {
  3520. ARMul_UndefInstr (state, instr);
  3521. break;
  3522. }
  3523. UNDEF_LSRBaseEQOffWb;
  3524. UNDEF_LSRBaseEQDestWb;
  3525. UNDEF_LSRPCBaseWb;
  3526. UNDEF_LSRPCOffWb;
  3527. temp = LHS + LSRegRHS;
  3528. if (LoadWord (state, instr, temp))
  3529. LSBase = temp;
  3530. break;
  3531. case 0x7c: /* Store Byte, No WriteBack, Pre Inc, Reg. */
  3532. if (BIT (4)) {
  3533. #ifdef MODE32
  3534. if (state->is_v6
  3535. && handle_v6_insn (state, instr))
  3536. break;
  3537. #endif
  3538. ARMul_UndefInstr (state, instr);
  3539. break;
  3540. }
  3541. (void) StoreByte (state, instr,
  3542. LHS + LSRegRHS);
  3543. break;
  3544. case 0x7d: /* Load Byte, No WriteBack, Pre Inc, Reg. */
  3545. if (BIT (4)) {
  3546. ARMul_UndefInstr (state, instr);
  3547. break;
  3548. }
  3549. (void) LoadByte (state, instr, LHS + LSRegRHS,
  3550. LUNSIGNED);
  3551. break;
  3552. case 0x7e: /* Store Byte, WriteBack, Pre Inc, Reg. */
  3553. if (BIT (4)) {
  3554. ARMul_UndefInstr (state, instr);
  3555. break;
  3556. }
  3557. UNDEF_LSRBaseEQOffWb;
  3558. UNDEF_LSRBaseEQDestWb;
  3559. UNDEF_LSRPCBaseWb;
  3560. UNDEF_LSRPCOffWb;
  3561. temp = LHS + LSRegRHS;
  3562. if (StoreByte (state, instr, temp))
  3563. LSBase = temp;
  3564. break;
  3565. case 0x7f: /* Load Byte, WriteBack, Pre Inc, Reg. */
  3566. if (BIT (4)) {
  3567. /* Check for the special breakpoint opcode.
  3568. This value should correspond to the value defined
  3569. as ARM_BE_BREAKPOINT in gdb/arm/tm-arm.h. */
  3570. if (BITS (0, 19) == 0xfdefe) {
  3571. if (!ARMul_OSHandleSWI
  3572. (state, SWI_Breakpoint))
  3573. ARMul_Abort (state,
  3574. ARMul_SWIV);
  3575. }
  3576. else
  3577. ARMul_UndefInstr (state,
  3578. instr);
  3579. break;
  3580. }
  3581. UNDEF_LSRBaseEQOffWb;
  3582. UNDEF_LSRBaseEQDestWb;
  3583. UNDEF_LSRPCBaseWb;
  3584. UNDEF_LSRPCOffWb;
  3585. temp = LHS + LSRegRHS;
  3586. if (LoadByte (state, instr, temp, LUNSIGNED))
  3587. LSBase = temp;
  3588. break;
  3589. /* Multiple Data Transfer Instructions. */
  3590. case 0x80: /* Store, No WriteBack, Post Dec. */
  3591. STOREMULT (instr, LSBase - LSMNumRegs + 4L,
  3592. 0L);
  3593. break;
  3594. case 0x81: /* Load, No WriteBack, Post Dec. */
  3595. LOADMULT (instr, LSBase - LSMNumRegs + 4L,
  3596. 0L);
  3597. break;
  3598. case 0x82: /* Store, WriteBack, Post Dec. */
  3599. temp = LSBase - LSMNumRegs;
  3600. STOREMULT (instr, temp + 4L, temp);
  3601. break;
  3602. case 0x83: /* Load, WriteBack, Post Dec. */
  3603. temp = LSBase - LSMNumRegs;
  3604. LOADMULT (instr, temp + 4L, temp);
  3605. break;
  3606. case 0x84: /* Store, Flags, No WriteBack, Post Dec. */
  3607. STORESMULT (instr, LSBase - LSMNumRegs + 4L,
  3608. 0L);
  3609. break;
  3610. case 0x85: /* Load, Flags, No WriteBack, Post Dec. */
  3611. LOADSMULT (instr, LSBase - LSMNumRegs + 4L,
  3612. 0L);
  3613. break;
  3614. case 0x86: /* Store, Flags, WriteBack, Post Dec. */
  3615. temp = LSBase - LSMNumRegs;
  3616. STORESMULT (instr, temp + 4L, temp);
  3617. break;
  3618. case 0x87: /* Load, Flags, WriteBack, Post Dec. */
  3619. temp = LSBase - LSMNumRegs;
  3620. LOADSMULT (instr, temp + 4L, temp);
  3621. break;
  3622. case 0x88: /* Store, No WriteBack, Post Inc. */
  3623. STOREMULT (instr, LSBase, 0L);
  3624. break;
  3625. case 0x89: /* Load, No WriteBack, Post Inc. */
  3626. LOADMULT (instr, LSBase, 0L);
  3627. break;
  3628. case 0x8a: /* Store, WriteBack, Post Inc. */
  3629. temp = LSBase;
  3630. STOREMULT (instr, temp, temp + LSMNumRegs);
  3631. break;
  3632. case 0x8b: /* Load, WriteBack, Post Inc. */
  3633. temp = LSBase;
  3634. LOADMULT (instr, temp, temp + LSMNumRegs);
  3635. break;
  3636. case 0x8c: /* Store, Flags, No WriteBack, Post Inc. */
  3637. STORESMULT (instr, LSBase, 0L);
  3638. break;
  3639. case 0x8d: /* Load, Flags, No WriteBack, Post Inc. */
  3640. LOADSMULT (instr, LSBase, 0L);
  3641. break;
  3642. case 0x8e: /* Store, Flags, WriteBack, Post Inc. */
  3643. temp = LSBase;
  3644. STORESMULT (instr, temp, temp + LSMNumRegs);
  3645. break;
  3646. case 0x8f: /* Load, Flags, WriteBack, Post Inc. */
  3647. temp = LSBase;
  3648. LOADSMULT (instr, temp, temp + LSMNumRegs);
  3649. break;
  3650. case 0x90: /* Store, No WriteBack, Pre Dec. */
  3651. STOREMULT (instr, LSBase - LSMNumRegs, 0L);
  3652. break;
  3653. case 0x91: /* Load, No WriteBack, Pre Dec. */
  3654. LOADMULT (instr, LSBase - LSMNumRegs, 0L);
  3655. break;
  3656. case 0x92: /* Store, WriteBack, Pre Dec. */
  3657. temp = LSBase - LSMNumRegs;
  3658. STOREMULT (instr, temp, temp);
  3659. break;
  3660. case 0x93: /* Load, WriteBack, Pre Dec. */
  3661. temp = LSBase - LSMNumRegs;
  3662. LOADMULT (instr, temp, temp);
  3663. break;
  3664. case 0x94: /* Store, Flags, No WriteBack, Pre Dec. */
  3665. STORESMULT (instr, LSBase - LSMNumRegs, 0L);
  3666. break;
  3667. case 0x95: /* Load, Flags, No WriteBack, Pre Dec. */
  3668. LOADSMULT (instr, LSBase - LSMNumRegs, 0L);
  3669. break;
  3670. case 0x96: /* Store, Flags, WriteBack, Pre Dec. */
  3671. temp = LSBase - LSMNumRegs;
  3672. STORESMULT (instr, temp, temp);
  3673. break;
  3674. case 0x97: /* Load, Flags, WriteBack, Pre Dec. */
  3675. temp = LSBase - LSMNumRegs;
  3676. LOADSMULT (instr, temp, temp);
  3677. break;
  3678. case 0x98: /* Store, No WriteBack, Pre Inc. */
  3679. STOREMULT (instr, LSBase + 4L, 0L);
  3680. break;
  3681. case 0x99: /* Load, No WriteBack, Pre Inc. */
  3682. LOADMULT (instr, LSBase + 4L, 0L);
  3683. break;
  3684. case 0x9a: /* Store, WriteBack, Pre Inc. */
  3685. temp = LSBase;
  3686. STOREMULT (instr, temp + 4L,
  3687. temp + LSMNumRegs);
  3688. break;
  3689. case 0x9b: /* Load, WriteBack, Pre Inc. */
  3690. temp = LSBase;
  3691. LOADMULT (instr, temp + 4L,
  3692. temp + LSMNumRegs);
  3693. break;
  3694. case 0x9c: /* Store, Flags, No WriteBack, Pre Inc. */
  3695. STORESMULT (instr, LSBase + 4L, 0L);
  3696. break;
  3697. case 0x9d: /* Load, Flags, No WriteBack, Pre Inc. */
  3698. LOADSMULT (instr, LSBase + 4L, 0L);
  3699. break;
  3700. case 0x9e: /* Store, Flags, WriteBack, Pre Inc. */
  3701. temp = LSBase;
  3702. STORESMULT (instr, temp + 4L,
  3703. temp + LSMNumRegs);
  3704. break;
  3705. case 0x9f: /* Load, Flags, WriteBack, Pre Inc. */
  3706. temp = LSBase;
  3707. LOADSMULT (instr, temp + 4L,
  3708. temp + LSMNumRegs);
  3709. break;
  3710. /* Branch forward. */
  3711. case 0xa0:
  3712. case 0xa1:
  3713. case 0xa2:
  3714. case 0xa3:
  3715. case 0xa4:
  3716. case 0xa5:
  3717. case 0xa6:
  3718. case 0xa7:
  3719. state->Reg[15] = pc + 8 + POSBRANCH;
  3720. FLUSHPIPE;
  3721. break;
  3722. /* Branch backward. */
  3723. case 0xa8:
  3724. case 0xa9:
  3725. case 0xaa:
  3726. case 0xab:
  3727. case 0xac:
  3728. case 0xad:
  3729. case 0xae:
  3730. case 0xaf:
  3731. state->Reg[15] = pc + 8 + NEGBRANCH;
  3732. FLUSHPIPE;
  3733. break;
  3734. /* Branch and Link forward. */
  3735. case 0xb0:
  3736. case 0xb1:
  3737. case 0xb2:
  3738. case 0xb3:
  3739. case 0xb4:
  3740. case 0xb5:
  3741. case 0xb6:
  3742. case 0xb7:
  3743. /* Put PC into Link. */
  3744. #ifdef MODE32
  3745. state->Reg[14] = pc + 4;
  3746. #else
  3747. state->Reg[14] =
  3748. (pc + 4) | ECC | ER15INT | EMODE;
  3749. #endif
  3750. state->Reg[15] = pc + 8 + POSBRANCH;
  3751. FLUSHPIPE;
  3752. break;
  3753. /* Branch and Link backward. */
  3754. case 0xb8:
  3755. case 0xb9:
  3756. case 0xba:
  3757. case 0xbb:
  3758. case 0xbc:
  3759. case 0xbd:
  3760. case 0xbe:
  3761. case 0xbf:
  3762. /* Put PC into Link. */
  3763. #ifdef MODE32
  3764. state->Reg[14] = pc + 4;
  3765. #else
  3766. state->Reg[14] =
  3767. (pc + 4) | ECC | ER15INT | EMODE;
  3768. #endif
  3769. state->Reg[15] = pc + 8 + NEGBRANCH;
  3770. FLUSHPIPE;
  3771. break;
  3772. /* Co-Processor Data Transfers. */
  3773. case 0xc4:
  3774. if (state->is_v5) {
  3775. /* Reading from R15 is UNPREDICTABLE. */
  3776. if (BITS (12, 15) == 15
  3777. || BITS (16, 19) == 15)
  3778. ARMul_UndefInstr (state,
  3779. instr);
  3780. /* Is access to coprocessor 0 allowed ? */
  3781. else if (!CP_ACCESS_ALLOWED
  3782. (state, CPNum))
  3783. ARMul_UndefInstr (state,
  3784. instr);
  3785. /* Special treatment for XScale coprocessors. */
  3786. else if (state->is_XScale) {
  3787. /* Only opcode 0 is supported. */
  3788. if (BITS (4, 7) != 0x00)
  3789. ARMul_UndefInstr
  3790. (state,
  3791. instr);
  3792. /* Only coporcessor 0 is supported. */
  3793. else if (CPNum != 0x00)
  3794. ARMul_UndefInstr
  3795. (state,
  3796. instr);
  3797. /* Only accumulator 0 is supported. */
  3798. else if (BITS (0, 3) != 0x00)
  3799. ARMul_UndefInstr
  3800. (state,
  3801. instr);
  3802. else {
  3803. /* XScale MAR insn. Move two registers into accumulator. */
  3804. state->Accumulator =
  3805. state->
  3806. Reg[BITS
  3807. (12, 15)];
  3808. state->Accumulator +=
  3809. (ARMdword)
  3810. state->
  3811. Reg[BITS
  3812. (16,
  3813. 19)] <<
  3814. 32;
  3815. }
  3816. }
  3817. else
  3818. {
  3819. /* MCRR, ARMv5TE and up */
  3820. ARMul_MCRR (state, instr, DEST, state->Reg[LHSReg]);
  3821. break;
  3822. }
  3823. }
  3824. /* Drop through. */
  3825. case 0xc0: /* Store , No WriteBack , Post Dec. */
  3826. ARMul_STC (state, instr, LHS);
  3827. break;
  3828. case 0xc5:
  3829. if (state->is_v5) {
  3830. /* Writes to R15 are UNPREDICATABLE. */
  3831. if (DESTReg == 15 || LHSReg == 15)
  3832. ARMul_UndefInstr (state,
  3833. instr);
  3834. /* Is access to the coprocessor allowed ? */
  3835. else if (!CP_ACCESS_ALLOWED
  3836. (state, CPNum))
  3837. ARMul_UndefInstr (state,
  3838. instr);
  3839. /* Special handling for XScale coprcoessors. */
  3840. else if (state->is_XScale) {
  3841. /* Only opcode 0 is supported. */
  3842. if (BITS (4, 7) != 0x00)
  3843. ARMul_UndefInstr
  3844. (state,
  3845. instr);
  3846. /* Only coprocessor 0 is supported. */
  3847. else if (CPNum != 0x00)
  3848. ARMul_UndefInstr
  3849. (state,
  3850. instr);
  3851. /* Only accumulator 0 is supported. */
  3852. else if (BITS (0, 3) != 0x00)
  3853. ARMul_UndefInstr
  3854. (state,
  3855. instr);
  3856. else {
  3857. /* XScale MRA insn. Move accumulator into two registers. */
  3858. ARMword t1 =
  3859. (state->
  3860. Accumulator
  3861. >> 32) & 255;
  3862. if (t1 & 128)
  3863. t1 -= 256;
  3864. state->Reg[BITS
  3865. (12, 15)] =
  3866. state->
  3867. Accumulator;
  3868. state->Reg[BITS
  3869. (16, 19)] =
  3870. t1;
  3871. break;
  3872. }
  3873. }
  3874. else
  3875. {
  3876. /* MRRC, ARMv5TE and up */
  3877. ARMul_MRRC (state, instr, &DEST, &(state->Reg[LHSReg]));
  3878. break;
  3879. }
  3880. }
  3881. /* Drop through. */
  3882. case 0xc1: /* Load , No WriteBack , Post Dec. */
  3883. ARMul_LDC (state, instr, LHS);
  3884. break;
  3885. case 0xc2:
  3886. case 0xc6: /* Store , WriteBack , Post Dec. */
  3887. lhs = LHS;
  3888. state->Base = lhs - LSCOff;
  3889. ARMul_STC (state, instr, lhs);
  3890. break;
  3891. case 0xc3:
  3892. case 0xc7: /* Load , WriteBack , Post Dec. */
  3893. lhs = LHS;
  3894. state->Base = lhs - LSCOff;
  3895. ARMul_LDC (state, instr, lhs);
  3896. break;
  3897. case 0xc8:
  3898. case 0xcc: /* Store , No WriteBack , Post Inc. */
  3899. ARMul_STC (state, instr, LHS);
  3900. break;
  3901. case 0xc9:
  3902. case 0xcd: /* Load , No WriteBack , Post Inc. */
  3903. ARMul_LDC (state, instr, LHS);
  3904. break;
  3905. case 0xca:
  3906. case 0xce: /* Store , WriteBack , Post Inc. */
  3907. lhs = LHS;
  3908. state->Base = lhs + LSCOff;
  3909. ARMul_STC (state, instr, LHS);
  3910. break;
  3911. case 0xcb:
  3912. case 0xcf: /* Load , WriteBack , Post Inc. */
  3913. lhs = LHS;
  3914. state->Base = lhs + LSCOff;
  3915. ARMul_LDC (state, instr, LHS);
  3916. break;
  3917. case 0xd0:
  3918. case 0xd4: /* Store , No WriteBack , Pre Dec. */
  3919. ARMul_STC (state, instr, LHS - LSCOff);
  3920. break;
  3921. case 0xd1:
  3922. case 0xd5: /* Load , No WriteBack , Pre Dec. */
  3923. ARMul_LDC (state, instr, LHS - LSCOff);
  3924. break;
  3925. case 0xd2:
  3926. case 0xd6: /* Store , WriteBack , Pre Dec. */
  3927. lhs = LHS - LSCOff;
  3928. state->Base = lhs;
  3929. ARMul_STC (state, instr, lhs);
  3930. break;
  3931. case 0xd3:
  3932. case 0xd7: /* Load , WriteBack , Pre Dec. */
  3933. lhs = LHS - LSCOff;
  3934. state->Base = lhs;
  3935. ARMul_LDC (state, instr, lhs);
  3936. break;
  3937. case 0xd8:
  3938. case 0xdc: /* Store , No WriteBack , Pre Inc. */
  3939. ARMul_STC (state, instr, LHS + LSCOff);
  3940. break;
  3941. case 0xd9:
  3942. case 0xdd: /* Load , No WriteBack , Pre Inc. */
  3943. ARMul_LDC (state, instr, LHS + LSCOff);
  3944. break;
  3945. case 0xda:
  3946. case 0xde: /* Store , WriteBack , Pre Inc. */
  3947. lhs = LHS + LSCOff;
  3948. state->Base = lhs;
  3949. ARMul_STC (state, instr, lhs);
  3950. break;
  3951. case 0xdb:
  3952. case 0xdf: /* Load , WriteBack , Pre Inc. */
  3953. lhs = LHS + LSCOff;
  3954. state->Base = lhs;
  3955. ARMul_LDC (state, instr, lhs);
  3956. break;
  3957. /* Co-Processor Register Transfers (MCR) and Data Ops. */
  3958. case 0xe2:
  3959. if (!CP_ACCESS_ALLOWED (state, CPNum)) {
  3960. ARMul_UndefInstr (state, instr);
  3961. break;
  3962. }
  3963. if (state->is_XScale)
  3964. switch (BITS (18, 19)) {
  3965. case 0x0:
  3966. if (BITS (4, 11) == 1
  3967. && BITS (16, 17) == 0) {
  3968. /* XScale MIA instruction. Signed multiplication of
  3969. two 32 bit values and addition to 40 bit accumulator. */
  3970. long long Rm =
  3971. state->
  3972. Reg
  3973. [MULLHSReg];
  3974. long long Rs =
  3975. state->
  3976. Reg
  3977. [MULACCReg];
  3978. if (Rm & (1 << 31))
  3979. Rm -= 1ULL <<
  3980. 32;
  3981. if (Rs & (1 << 31))
  3982. Rs -= 1ULL <<
  3983. 32;
  3984. state->Accumulator +=
  3985. Rm * Rs;
  3986. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  3987. }
  3988. break;
  3989. case 0x2:
  3990. if (BITS (4, 11) == 1
  3991. && BITS (16, 17) == 0) {
  3992. /* XScale MIAPH instruction. */
  3993. ARMword t1 =
  3994. state->
  3995. Reg[MULLHSReg]
  3996. >> 16;
  3997. ARMword t2 =
  3998. state->
  3999. Reg[MULACCReg]
  4000. >> 16;
  4001. ARMword t3 =
  4002. state->
  4003. Reg[MULLHSReg]
  4004. & 0xffff;
  4005. ARMword t4 =
  4006. state->
  4007. Reg[MULACCReg]
  4008. & 0xffff;
  4009. long long t5;
  4010. if (t1 & (1 << 15))
  4011. t1 -= 1 << 16;
  4012. if (t2 & (1 << 15))
  4013. t2 -= 1 << 16;
  4014. if (t3 & (1 << 15))
  4015. t3 -= 1 << 16;
  4016. if (t4 & (1 << 15))
  4017. t4 -= 1 << 16;
  4018. t1 *= t2;
  4019. t5 = t1;
  4020. if (t5 & (1 << 31))
  4021. t5 -= 1ULL <<
  4022. 32;
  4023. state->Accumulator +=
  4024. t5;
  4025. t3 *= t4;
  4026. t5 = t3;
  4027. if (t5 & (1 << 31))
  4028. t5 -= 1ULL <<
  4029. 32;
  4030. state->Accumulator +=
  4031. t5;
  4032. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  4033. }
  4034. break;
  4035. case 0x3:
  4036. if (BITS (4, 11) == 1) {
  4037. /* XScale MIAxy instruction. */
  4038. ARMword t1;
  4039. ARMword t2;
  4040. long long t5;
  4041. if (BIT (17))
  4042. t1 = state->
  4043. Reg
  4044. [MULLHSReg]
  4045. >> 16;
  4046. else
  4047. t1 = state->
  4048. Reg
  4049. [MULLHSReg]
  4050. &
  4051. 0xffff;
  4052. if (BIT (16))
  4053. t2 = state->
  4054. Reg
  4055. [MULACCReg]
  4056. >> 16;
  4057. else
  4058. t2 = state->
  4059. Reg
  4060. [MULACCReg]
  4061. &
  4062. 0xffff;
  4063. if (t1 & (1 << 15))
  4064. t1 -= 1 << 16;
  4065. if (t2 & (1 << 15))
  4066. t2 -= 1 << 16;
  4067. t1 *= t2;
  4068. t5 = t1;
  4069. if (t5 & (1 << 31))
  4070. t5 -= 1ULL <<
  4071. 32;
  4072. state->Accumulator +=
  4073. t5;
  4074. _assert_msg_(ARM11, false, "disabled skyeye code 'goto donext'"); //goto donext;
  4075. }
  4076. break;
  4077. default:
  4078. break;
  4079. }
  4080. /* Drop through. */
  4081. case 0xe4:
  4082. case 0xe6:
  4083. case 0xe8:
  4084. case 0xea:
  4085. case 0xec:
  4086. case 0xee:
  4087. if (BIT (4)) {
  4088. /* MCR. */
  4089. if (DESTReg == 15) {
  4090. UNDEF_MCRPC;
  4091. #ifdef MODE32
  4092. ARMul_MCR (state, instr,
  4093. state->Reg[15] +
  4094. isize);
  4095. #else
  4096. ARMul_MCR (state, instr,
  4097. ECC | ER15INT |
  4098. EMODE |
  4099. ((state->Reg[15] +
  4100. isize) &
  4101. R15PCBITS));
  4102. #endif
  4103. }
  4104. else
  4105. ARMul_MCR (state, instr,
  4106. DEST);
  4107. }
  4108. else
  4109. /* CDP Part 1. */
  4110. ARMul_CDP (state, instr);
  4111. break;
  4112. /* Co-Processor Register Transfers (MRC) and Data Ops. */
  4113. case 0xe0:
  4114. case 0xe1:
  4115. case 0xe3:
  4116. case 0xe5:
  4117. case 0xe7:
  4118. case 0xe9:
  4119. case 0xeb:
  4120. case 0xed:
  4121. case 0xef:
  4122. if (BIT (4)) {
  4123. /* MRC */
  4124. temp = ARMul_MRC (state, instr);
  4125. if (DESTReg == 15) {
  4126. ASSIGNN ((temp & NBIT) != 0);
  4127. ASSIGNZ ((temp & ZBIT) != 0);
  4128. ASSIGNC ((temp & CBIT) != 0);
  4129. ASSIGNV ((temp & VBIT) != 0);
  4130. }
  4131. else
  4132. DEST = temp;
  4133. }
  4134. else
  4135. /* CDP Part 2. */
  4136. ARMul_CDP (state, instr);
  4137. break;
  4138. /* SWI instruction. */
  4139. case 0xf0:
  4140. case 0xf1:
  4141. case 0xf2:
  4142. case 0xf3:
  4143. case 0xf4:
  4144. case 0xf5:
  4145. case 0xf6:
  4146. case 0xf7:
  4147. case 0xf8:
  4148. case 0xf9:
  4149. case 0xfa:
  4150. case 0xfb:
  4151. case 0xfc:
  4152. case 0xfd:
  4153. case 0xfe:
  4154. case 0xff:
  4155. if (instr == ARMul_ABORTWORD
  4156. && state->AbortAddr == pc) {
  4157. /* A prefetch abort. */
  4158. XScale_set_fsr_far (state,
  4159. ARMul_CP15_R5_MMU_EXCPT,
  4160. pc);
  4161. ARMul_Abort (state,
  4162. ARMul_PrefetchAbortV);
  4163. break;
  4164. }
  4165. //sky_pref_t* pref = get_skyeye_pref();
  4166. //if(pref->user_mode_sim){
  4167. // ARMul_OSHandleSWI (state, BITS (0, 23));
  4168. // break;
  4169. //}
  4170. HLE::CallSyscall(instr);
  4171. ARMul_Abort (state, ARMul_SWIV);
  4172. break;
  4173. }
  4174. }
  4175. #ifdef MODET
  4176. donext:
  4177. #endif
  4178. state->pc = pc;
  4179. #if 0
  4180. /* shenoubang */
  4181. instr_sum++;
  4182. int i, j;
  4183. i = j = 0;
  4184. if (instr_sum >= 7388648) {
  4185. //if (pc == 0xc0008ab4) {
  4186. // printf("instr_sum: %d\n", instr_sum);
  4187. // start_kernel : 0xc000895c
  4188. printf("--------------------------------------------------\n");
  4189. for (i = 0; i < 16; i++) {
  4190. printf("[R%02d]:[0x%08x]\t", i, state->Reg[i]);
  4191. if ((i % 3) == 2) {
  4192. printf("\n");
  4193. }
  4194. }
  4195. printf("[cpr]:[0x%08x]\t[spr0]:[0x%08x]\n", state->Cpsr, state->Spsr[0]);
  4196. for (j = 1; j < 7; j++) {
  4197. printf("[spr%d]:[0x%08x]\t", j, state->Spsr[j]);
  4198. if ((j % 4) == 3) {
  4199. printf("\n");
  4200. }
  4201. }
  4202. printf("\n[PC]:[0x%08x]\t[INST]:[0x%08x]\t[COUNT]:[%d]\n", pc, instr, instr_sum);
  4203. printf("--------------------------------------------------\n");
  4204. }
  4205. #endif
  4206. #if 0
  4207. fprintf(state->state_log, "PC:0x%x\n", pc);
  4208. for (reg_index = 0; reg_index < 16; reg_index ++) {
  4209. if (state->Reg[reg_index] != mirror_register_file[reg_index]) {
  4210. fprintf(state->state_log, "R%d:0x%x\n", reg_index, state->Reg[reg_index]);
  4211. mirror_register_file[reg_index] = state->Reg[reg_index];
  4212. }
  4213. }
  4214. if (state->Cpsr != mirror_register_file[CPSR_REG]) {
  4215. fprintf(state->state_log, "Cpsr:0x%x\n", state->Cpsr);
  4216. mirror_register_file[CPSR_REG] = state->Cpsr;
  4217. }
  4218. if (state->RegBank[SVCBANK][13] != mirror_register_file[R13_SVC]) {
  4219. fprintf(state->state_log, "R13_SVC:0x%x\n", state->RegBank[SVCBANK][13]);
  4220. mirror_register_file[R13_SVC] = state->RegBank[SVCBANK][13];
  4221. }
  4222. if (state->RegBank[SVCBANK][14] != mirror_register_file[R14_SVC]) {
  4223. fprintf(state->state_log, "R14_SVC:0x%x\n", state->RegBank[SVCBANK][14]);
  4224. mirror_register_file[R14_SVC] = state->RegBank[SVCBANK][14];
  4225. }
  4226. if (state->RegBank[ABORTBANK][13] != mirror_register_file[R13_ABORT]) {
  4227. fprintf(state->state_log, "R13_ABORT:0x%x\n", state->RegBank[ABORTBANK][13]);
  4228. mirror_register_file[R13_ABORT] = state->RegBank[ABORTBANK][13];
  4229. }
  4230. if (state->RegBank[ABORTBANK][14] != mirror_register_file[R14_ABORT]) {
  4231. fprintf(state->state_log, "R14_ABORT:0x%x\n", state->RegBank[ABORTBANK][14]);
  4232. mirror_register_file[R14_ABORT] = state->RegBank[ABORTBANK][14];
  4233. }
  4234. if (state->RegBank[UNDEFBANK][13] != mirror_register_file[R13_UNDEF]) {
  4235. fprintf(state->state_log, "R13_UNDEF:0x%x\n", state->RegBank[UNDEFBANK][13]);
  4236. mirror_register_file[R13_UNDEF] = state->RegBank[UNDEFBANK][13];
  4237. }
  4238. if (state->RegBank[UNDEFBANK][14] != mirror_register_file[R14_UNDEF]) {
  4239. fprintf(state->state_log, "R14_UNDEF:0x%x\n", state->RegBank[UNDEFBANK][14]);
  4240. mirror_register_file[R14_UNDEF] = state->RegBank[UNDEFBANK][14];
  4241. }
  4242. if (state->RegBank[IRQBANK][13] != mirror_register_file[R13_IRQ]) {
  4243. fprintf(state->state_log, "R13_IRQ:0x%x\n", state->RegBank[IRQBANK][13]);
  4244. mirror_register_file[R13_IRQ] = state->RegBank[IRQBANK][13];
  4245. }
  4246. if (state->RegBank[IRQBANK][14] != mirror_register_file[R14_IRQ]) {
  4247. fprintf(state->state_log, "R14_IRQ:0x%x\n", state->RegBank[IRQBANK][14]);
  4248. mirror_register_file[R14_IRQ] = state->RegBank[IRQBANK][14];
  4249. }
  4250. if (state->RegBank[FIQBANK][8] != mirror_register_file[R8_FIRQ]) {
  4251. fprintf(state->state_log, "R8_FIRQ:0x%x\n", state->RegBank[FIQBANK][8]);
  4252. mirror_register_file[R8_FIRQ] = state->RegBank[FIQBANK][8];
  4253. }
  4254. if (state->RegBank[FIQBANK][9] != mirror_register_file[R9_FIRQ]) {
  4255. fprintf(state->state_log, "R9_FIRQ:0x%x\n", state->RegBank[FIQBANK][9]);
  4256. mirror_register_file[R9_FIRQ] = state->RegBank[FIQBANK][9];
  4257. }
  4258. if (state->RegBank[FIQBANK][10] != mirror_register_file[R10_FIRQ]) {
  4259. fprintf(state->state_log, "R10_FIRQ:0x%x\n", state->RegBank[FIQBANK][10]);
  4260. mirror_register_file[R10_FIRQ] = state->RegBank[FIQBANK][10];
  4261. }
  4262. if (state->RegBank[FIQBANK][11] != mirror_register_file[R11_FIRQ]) {
  4263. fprintf(state->state_log, "R11_FIRQ:0x%x\n", state->RegBank[FIQBANK][11]);
  4264. mirror_register_file[R11_FIRQ] = state->RegBank[FIQBANK][11];
  4265. }
  4266. if (state->RegBank[FIQBANK][12] != mirror_register_file[R12_FIRQ]) {
  4267. fprintf(state->state_log, "R12_FIRQ:0x%x\n", state->RegBank[FIQBANK][12]);
  4268. mirror_register_file[R12_FIRQ] = state->RegBank[FIQBANK][12];
  4269. }
  4270. if (state->RegBank[FIQBANK][13] != mirror_register_file[R13_FIRQ]) {
  4271. fprintf(state->state_log, "R13_FIRQ:0x%x\n", state->RegBank[FIQBANK][13]);
  4272. mirror_register_file[R13_FIRQ] = state->RegBank[FIQBANK][13];
  4273. }
  4274. if (state->RegBank[FIQBANK][14] != mirror_register_file[R14_FIRQ]) {
  4275. fprintf(state->state_log, "R14_FIRQ:0x%x\n", state->RegBank[FIQBANK][14]);
  4276. mirror_register_file[R14_FIRQ] = state->RegBank[FIQBANK][14];
  4277. }
  4278. if (state->Spsr[SVCBANK] != mirror_register_file[SPSR_SVC]) {
  4279. fprintf(state->state_log, "SPSR_SVC:0x%x\n", state->Spsr[SVCBANK]);
  4280. mirror_register_file[SPSR_SVC] = state->RegBank[SVCBANK];
  4281. }
  4282. if (state->Spsr[ABORTBANK] != mirror_register_file[SPSR_ABORT]) {
  4283. fprintf(state->state_log, "SPSR_ABORT:0x%x\n", state->Spsr[ABORTBANK]);
  4284. mirror_register_file[SPSR_ABORT] = state->RegBank[ABORTBANK];
  4285. }
  4286. if (state->Spsr[UNDEFBANK] != mirror_register_file[SPSR_UNDEF]) {
  4287. fprintf(state->state_log, "SPSR_UNDEF:0x%x\n", state->Spsr[UNDEFBANK]);
  4288. mirror_register_file[SPSR_UNDEF] = state->RegBank[UNDEFBANK];
  4289. }
  4290. if (state->Spsr[IRQBANK] != mirror_register_file[SPSR_IRQ]) {
  4291. fprintf(state->state_log, "SPSR_IRQ:0x%x\n", state->Spsr[IRQBANK]);
  4292. mirror_register_file[SPSR_IRQ] = state->RegBank[IRQBANK];
  4293. }
  4294. if (state->Spsr[FIQBANK] != mirror_register_file[SPSR_FIRQ]) {
  4295. fprintf(state->state_log, "SPSR_FIRQ:0x%x\n", state->Spsr[FIQBANK]);
  4296. mirror_register_file[SPSR_FIRQ] = state->RegBank[FIQBANK];
  4297. }
  4298. #endif
  4299. #ifdef NEED_UI_LOOP_HOOK
  4300. if (ui_loop_hook != NULL && ui_loop_hook_counter-- < 0) {
  4301. ui_loop_hook_counter = UI_LOOP_POLL_INTERVAL;
  4302. ui_loop_hook (0);
  4303. }
  4304. #endif /* NEED_UI_LOOP_HOOK */
  4305. /*added energy_prof statement by ksh in 2004-11-26 */
  4306. //chy 2005-07-28 for standalone
  4307. //ARMul_do_energy(state,instr,pc);
  4308. //teawater add for record reg value to ./reg.txt 2005.07.10---------------------
  4309. if (state->tea_break_ok && pc == state->tea_break_addr) {
  4310. ARMul_Debug (state, 0, 0);
  4311. state->tea_break_ok = 0;
  4312. }
  4313. else {
  4314. state->tea_break_ok = 1;
  4315. }
  4316. //AJ2D--------------------------------------------------------------------------
  4317. //chy 2006-04-14 for ctrl-c debug
  4318. #if 0
  4319. if (debugmode) {
  4320. if (instr != ARMul_ABORTWORD) {
  4321. remote_interrupt_test_time++;
  4322. //chy 2006-04-14 2000 should be changed in skyeye_conf ???!!!
  4323. if (remote_interrupt_test_time >= 2000) {
  4324. remote_interrupt_test_time=0;
  4325. if (remote_interrupt()) {
  4326. //for test
  4327. //printf("SKYEYE: ICE_debug recv Ctrl_C\n");
  4328. state->EndCondition = 0;
  4329. state->Emulate = STOP;
  4330. }
  4331. }
  4332. }
  4333. }
  4334. #endif
  4335. /* jump out every time */
  4336. //state->EndCondition = 0;
  4337. //state->Emulate = STOP;
  4338. //chy 2006-04-12 for ICE debug
  4339. TEST_EMULATE:
  4340. if (state->Emulate == ONCE)
  4341. state->Emulate = STOP;
  4342. //chy: 2003-08-23: should not use CHANGEMODE !!!!
  4343. /* If we have changed mode, allow the PC to advance before stopping. */
  4344. // else if (state->Emulate == CHANGEMODE)
  4345. // continue;
  4346. else if (state->Emulate != RUN)
  4347. break;
  4348. }
  4349. while (!state->stop_simulator);
  4350. state->decoded = decoded;
  4351. state->loaded = loaded;
  4352. state->pc = pc;
  4353. //chy 2006-04-12, for ICE debug
  4354. state->decoded_addr=decoded_addr;
  4355. state->loaded_addr=loaded_addr;
  4356. return pc;
  4357. }
  4358. //teawater add for arm2x86 2005.02.17-------------------------------------------
  4359. /*ywc 2005-04-01*/
  4360. //#include "tb.h"
  4361. //#include "arm2x86_self.h"
  4362. static volatile void (*gen_func) (void);
  4363. //static volatile ARMul_State *tmp_st;
  4364. //static volatile ARMul_State *save_st;
  4365. static volatile uint32_t tmp_st;
  4366. static volatile uint32_t save_st;
  4367. static volatile uint32_t save_T0;
  4368. static volatile uint32_t save_T1;
  4369. static volatile uint32_t save_T2;
  4370. #ifdef MODE32
  4371. #ifdef DBCT
  4372. //teawater change for debug function 2005.07.09---------------------------------
  4373. ARMword
  4374. ARMul_Emulate32_dbct (ARMul_State * state)
  4375. {
  4376. static int init = 0;
  4377. static FILE *fd;
  4378. /*if (!init) {
  4379. fd = fopen("./pc.txt", "w");
  4380. if (!fd) {
  4381. exit(-1);
  4382. }
  4383. init = 1;
  4384. } */
  4385. state->Reg[15] += INSN_SIZE;
  4386. do {
  4387. /*if (skyeye_config.log.logon>=1) {
  4388. if (state->NumInstrs>=skyeye_config.log.start && state->NumInstrs<=skyeye_config.log.end) {
  4389. static int mybegin=0;
  4390. static int myinstrnum=0;
  4391. if (mybegin==0) mybegin=1;
  4392. if (mybegin==1) {
  4393. state->Reg[15] -= INSN_SIZE;
  4394. if (skyeye_config.log.logon>=1) fprintf(skyeye_logfd,"N %llx :p %x,i %x,",state->NumInstrs, (state->Reg[15] - INSN_SIZE), instr);
  4395. if (skyeye_config.log.logon>=2) SKYEYE_OUTREGS(skyeye_logfd);
  4396. if (skyeye_config.log.logon>=3) SKYEYE_OUTMOREREGS(skyeye_logfd);
  4397. fprintf(skyeye_logfd,"\n");
  4398. if (skyeye_config.log.length>0) {
  4399. myinstrnum++;
  4400. if (myinstrnum>=skyeye_config.log.length) {
  4401. myinstrnum=0;
  4402. fflush(skyeye_logfd);
  4403. fseek(skyeye_logfd,0L,SEEK_SET);
  4404. }
  4405. }
  4406. state->Reg[15] += INSN_SIZE;
  4407. }
  4408. }
  4409. } */
  4410. state->trap = 0;
  4411. gen_func =
  4412. (void *) tb_find (state, state->Reg[15] - INSN_SIZE);
  4413. if (!gen_func) {
  4414. //fprintf(stderr, "SKYEYE: tb_find: Error in find the translate block.\n");
  4415. //exit(-1);
  4416. //TRAP_INSN_ABORT
  4417. //TEA_OUT(printf("\n------------\npc:%x\n", state->Reg[15] - INSN_SIZE));
  4418. //TEA_OUT(printf("TRAP_INSN_ABORT\n"));
  4419. //teawater add for xscale(arm v5) 2005.09.01------------------------------------
  4420. /*XScale_set_fsr_far(state, ARMul_CP15_R5_MMU_EXCPT, state->Reg[15] - INSN_SIZE);
  4421. state->Reg[15] += INSN_SIZE;
  4422. ARMul_Abort(state, ARMul_PrefetchAbortV);
  4423. state->Reg[15] += INSN_SIZE;
  4424. goto next; */
  4425. state->trap = TRAP_INSN_ABORT;
  4426. goto check;
  4427. //AJ2D--------------------------------------------------------------------------
  4428. }
  4429. save_st = (uint32_t) st;
  4430. save_T0 = T0;
  4431. save_T1 = T1;
  4432. save_T2 = T2;
  4433. tmp_st = (uint32_t) state;
  4434. wmb ();
  4435. st = (ARMul_State *) tmp_st;
  4436. gen_func ();
  4437. st = (ARMul_State *) save_st;
  4438. T0 = save_T0;
  4439. T1 = save_T1;
  4440. T2 = save_T2;
  4441. /*if (state->trap != TRAP_OUT) {
  4442. state->tea_break_ok = 1;
  4443. }
  4444. if (state->trap <= TRAP_SET_R15) {
  4445. goto next;
  4446. } */
  4447. //TEA_OUT(printf("\n------------\npc:%x\n", state->Reg[15] - INSN_SIZE));
  4448. //teawater add check thumb 2005.07.21-------------------------------------------
  4449. /*if (TFLAG) {
  4450. state->Reg[15] -= 2;
  4451. return(state->Reg[15]);
  4452. } */
  4453. //AJ2D--------------------------------------------------------------------------
  4454. //teawater add for xscale(arm v5) 2005.09.01------------------------------------
  4455. check:
  4456. //AJ2D--------------------------------------------------------------------------
  4457. switch (state->trap) {
  4458. case TRAP_RESET:
  4459. {
  4460. //TEA_OUT(printf("TRAP_RESET\n"));
  4461. ARMul_Abort (state, ARMul_ResetV);
  4462. state->Reg[15] += INSN_SIZE;
  4463. }
  4464. break;
  4465. case TRAP_UNPREDICTABLE:
  4466. {
  4467. ARMul_Debug (state, 0, 0);
  4468. }
  4469. break;
  4470. case TRAP_INSN_UNDEF:
  4471. {
  4472. //TEA_OUT(printf("TRAP_INSN_UNDEF\n"));
  4473. state->Reg[15] += INSN_SIZE;
  4474. ARMul_UndefInstr (state, 0);
  4475. state->Reg[15] += INSN_SIZE;
  4476. }
  4477. break;
  4478. case TRAP_SWI:
  4479. {
  4480. //TEA_OUT(printf("TRAP_SWI\n"));
  4481. state->Reg[15] += INSN_SIZE;
  4482. ARMul_Abort (state, ARMul_SWIV);
  4483. state->Reg[15] += INSN_SIZE;
  4484. }
  4485. break;
  4486. //teawater add for xscale(arm v5) 2005.09.01------------------------------------
  4487. case TRAP_INSN_ABORT:
  4488. {
  4489. XScale_set_fsr_far (state,
  4490. ARMul_CP15_R5_MMU_EXCPT,
  4491. state->Reg[15] -
  4492. INSN_SIZE);
  4493. state->Reg[15] += INSN_SIZE;
  4494. ARMul_Abort (state, ARMul_PrefetchAbortV);
  4495. state->Reg[15] += INSN_SIZE;
  4496. }
  4497. break;
  4498. //AJ2D--------------------------------------------------------------------------
  4499. case TRAP_DATA_ABORT:
  4500. {
  4501. //TEA_OUT(printf("TRAP_DATA_ABORT\n"));
  4502. state->Reg[15] += INSN_SIZE;
  4503. ARMul_Abort (state, ARMul_DataAbortV);
  4504. state->Reg[15] += INSN_SIZE;
  4505. }
  4506. break;
  4507. case TRAP_IRQ:
  4508. {
  4509. //TEA_OUT(printf("TRAP_IRQ\n"));
  4510. state->Reg[15] += INSN_SIZE;
  4511. ARMul_Abort (state, ARMul_IRQV);
  4512. state->Reg[15] += INSN_SIZE;
  4513. }
  4514. break;
  4515. case TRAP_FIQ:
  4516. {
  4517. //TEA_OUT(printf("TRAP_FIQ\n"));
  4518. state->Reg[15] += INSN_SIZE;
  4519. ARMul_Abort (state, ARMul_FIQV);
  4520. state->Reg[15] += INSN_SIZE;
  4521. }
  4522. break;
  4523. case TRAP_SETS_R15:
  4524. {
  4525. //TEA_OUT(printf("TRAP_SETS_R15\n"));
  4526. /*if (state->Bank > 0) {
  4527. state->Cpsr = state->Spsr[state->Bank];
  4528. ARMul_CPSRAltered (state);
  4529. } */
  4530. WriteSR15 (state, state->Reg[15]);
  4531. }
  4532. break;
  4533. case TRAP_SET_CPSR:
  4534. {
  4535. //TEA_OUT(printf("TRAP_SET_CPSR\n"));
  4536. //chy 2006-02-15 USERBANK=SYSTEMBANK=0
  4537. //chy 2006-02-16 should use Mode to test
  4538. //if (state->Bank > 0) {
  4539. if (state->Mode != USER26MODE && state->Mode != USER32MODE){
  4540. ARMul_CPSRAltered (state);
  4541. }
  4542. state->Reg[15] += INSN_SIZE;
  4543. }
  4544. break;
  4545. case TRAP_OUT:
  4546. {
  4547. //TEA_OUT(printf("TRAP_OUT\n"));
  4548. goto out;
  4549. }
  4550. break;
  4551. case TRAP_BREAKPOINT:
  4552. {
  4553. //TEA_OUT(printf("TRAP_BREAKPOINT\n"));
  4554. state->Reg[15] -= INSN_SIZE;
  4555. if (!ARMul_OSHandleSWI
  4556. (state, SWI_Breakpoint)) {
  4557. ARMul_Abort (state, ARMul_SWIV);
  4558. }
  4559. state->Reg[15] += INSN_SIZE;
  4560. }
  4561. break;
  4562. }
  4563. next:
  4564. if (state->Emulate == ONCE) {
  4565. state->Emulate = STOP;
  4566. break;
  4567. }
  4568. else if (state->Emulate != RUN) {
  4569. break;
  4570. }
  4571. }
  4572. while (!state->stop_simulator);
  4573. out:
  4574. state->Reg[15] -= INSN_SIZE;
  4575. return (state->Reg[15]);
  4576. }
  4577. #endif
  4578. //AJ2D--------------------------------------------------------------------------
  4579. #endif
  4580. //AJ2D--------------------------------------------------------------------------
  4581. /* This routine evaluates most Data Processing register RHS's with the S
  4582. bit clear. It is intended to be called from the macro DPRegRHS, which
  4583. filters the common case of an unshifted register with in line code. */
  4584. static ARMword
  4585. GetDPRegRHS (ARMul_State * state, ARMword instr)
  4586. {
  4587. ARMword shamt, base;
  4588. base = RHSReg;
  4589. if (BIT (4)) {
  4590. /* Shift amount in a register. */
  4591. UNDEF_Shift;
  4592. INCPC;
  4593. #ifndef MODE32
  4594. if (base == 15)
  4595. base = ECC | ER15INT | R15PC | EMODE;
  4596. else
  4597. #endif
  4598. base = state->Reg[base];
  4599. ARMul_Icycles (state, 1, 0L);
  4600. shamt = state->Reg[BITS (8, 11)] & 0xff;
  4601. switch ((int) BITS (5, 6)) {
  4602. case LSL:
  4603. if (shamt == 0)
  4604. return (base);
  4605. else if (shamt >= 32)
  4606. return (0);
  4607. else
  4608. return (base << shamt);
  4609. case LSR:
  4610. if (shamt == 0)
  4611. return (base);
  4612. else if (shamt >= 32)
  4613. return (0);
  4614. else
  4615. return (base >> shamt);
  4616. case ASR:
  4617. if (shamt == 0)
  4618. return (base);
  4619. else if (shamt >= 32)
  4620. return ((ARMword) ((int) base >> 31L));
  4621. else
  4622. return ((ARMword)
  4623. (( int) base >> (int) shamt));
  4624. case ROR:
  4625. shamt &= 0x1f;
  4626. if (shamt == 0)
  4627. return (base);
  4628. else
  4629. return ((base << (32 - shamt)) |
  4630. (base >> shamt));
  4631. }
  4632. }
  4633. else {
  4634. /* Shift amount is a constant. */
  4635. #ifndef MODE32
  4636. if (base == 15)
  4637. base = ECC | ER15INT | R15PC | EMODE;
  4638. else
  4639. #endif
  4640. base = state->Reg[base];
  4641. shamt = BITS (7, 11);
  4642. switch ((int) BITS (5, 6)) {
  4643. case LSL:
  4644. return (base << shamt);
  4645. case LSR:
  4646. if (shamt == 0)
  4647. return (0);
  4648. else
  4649. return (base >> shamt);
  4650. case ASR:
  4651. if (shamt == 0)
  4652. return ((ARMword) (( int) base >> 31L));
  4653. else
  4654. return ((ARMword)
  4655. (( int) base >> (int) shamt));
  4656. case ROR:
  4657. if (shamt == 0)
  4658. /* It's an RRX. */
  4659. return ((base >> 1) | (CFLAG << 31));
  4660. else
  4661. return ((base << (32 - shamt)) |
  4662. (base >> shamt));
  4663. }
  4664. }
  4665. return 0;
  4666. }
  4667. /* This routine evaluates most Logical Data Processing register RHS's
  4668. with the S bit set. It is intended to be called from the macro
  4669. DPSRegRHS, which filters the common case of an unshifted register
  4670. with in line code. */
  4671. static ARMword
  4672. GetDPSRegRHS (ARMul_State * state, ARMword instr)
  4673. {
  4674. ARMword shamt, base;
  4675. base = RHSReg;
  4676. if (BIT (4)) {
  4677. /* Shift amount in a register. */
  4678. UNDEF_Shift;
  4679. INCPC;
  4680. #ifndef MODE32
  4681. if (base == 15)
  4682. base = ECC | ER15INT | R15PC | EMODE;
  4683. else
  4684. #endif
  4685. base = state->Reg[base];
  4686. ARMul_Icycles (state, 1, 0L);
  4687. shamt = state->Reg[BITS (8, 11)] & 0xff;
  4688. switch ((int) BITS (5, 6)) {
  4689. case LSL:
  4690. if (shamt == 0)
  4691. return (base);
  4692. else if (shamt == 32) {
  4693. ASSIGNC (base & 1);
  4694. return (0);
  4695. }
  4696. else if (shamt > 32) {
  4697. CLEARC;
  4698. return (0);
  4699. }
  4700. else {
  4701. ASSIGNC ((base >> (32 - shamt)) & 1);
  4702. return (base << shamt);
  4703. }
  4704. case LSR:
  4705. if (shamt == 0)
  4706. return (base);
  4707. else if (shamt == 32) {
  4708. ASSIGNC (base >> 31);
  4709. return (0);
  4710. }
  4711. else if (shamt > 32) {
  4712. CLEARC;
  4713. return (0);
  4714. }
  4715. else {
  4716. ASSIGNC ((base >> (shamt - 1)) & 1);
  4717. return (base >> shamt);
  4718. }
  4719. case ASR:
  4720. if (shamt == 0)
  4721. return (base);
  4722. else if (shamt >= 32) {
  4723. ASSIGNC (base >> 31L);
  4724. return ((ARMword) (( int) base >> 31L));
  4725. }
  4726. else {
  4727. ASSIGNC ((ARMword)
  4728. (( int) base >>
  4729. (int) (shamt - 1)) & 1);
  4730. return ((ARMword)
  4731. ((int) base >> (int) shamt));
  4732. }
  4733. case ROR:
  4734. if (shamt == 0)
  4735. return (base);
  4736. shamt &= 0x1f;
  4737. if (shamt == 0) {
  4738. ASSIGNC (base >> 31);
  4739. return (base);
  4740. }
  4741. else {
  4742. ASSIGNC ((base >> (shamt - 1)) & 1);
  4743. return ((base << (32 - shamt)) |
  4744. (base >> shamt));
  4745. }
  4746. }
  4747. }
  4748. else {
  4749. /* Shift amount is a constant. */
  4750. #ifndef MODE32
  4751. if (base == 15)
  4752. base = ECC | ER15INT | R15PC | EMODE;
  4753. else
  4754. #endif
  4755. base = state->Reg[base];
  4756. shamt = BITS (7, 11);
  4757. switch ((int) BITS (5, 6)) {
  4758. case LSL:
  4759. ASSIGNC ((base >> (32 - shamt)) & 1);
  4760. return (base << shamt);
  4761. case LSR:
  4762. if (shamt == 0) {
  4763. ASSIGNC (base >> 31);
  4764. return (0);
  4765. }
  4766. else {
  4767. ASSIGNC ((base >> (shamt - 1)) & 1);
  4768. return (base >> shamt);
  4769. }
  4770. case ASR:
  4771. if (shamt == 0) {
  4772. ASSIGNC (base >> 31L);
  4773. return ((ARMword) ((int) base >> 31L));
  4774. }
  4775. else {
  4776. ASSIGNC ((ARMword)
  4777. ((int) base >>
  4778. (int) (shamt - 1)) & 1);
  4779. return ((ARMword)
  4780. (( int) base >> (int) shamt));
  4781. }
  4782. case ROR:
  4783. if (shamt == 0) {
  4784. /* It's an RRX. */
  4785. shamt = CFLAG;
  4786. ASSIGNC (base & 1);
  4787. return ((base >> 1) | (shamt << 31));
  4788. }
  4789. else {
  4790. ASSIGNC ((base >> (shamt - 1)) & 1);
  4791. return ((base << (32 - shamt)) |
  4792. (base >> shamt));
  4793. }
  4794. }
  4795. }
  4796. return 0;
  4797. }
  4798. /* This routine handles writes to register 15 when the S bit is not set. */
  4799. static void
  4800. WriteR15 (ARMul_State * state, ARMword src)
  4801. {
  4802. /* The ARM documentation states that the two least significant bits
  4803. are discarded when setting PC, except in the cases handled by
  4804. WriteR15Branch() below. It's probably an oversight: in THUMB
  4805. mode, the second least significant bit should probably not be
  4806. discarded. */
  4807. #ifdef MODET
  4808. if (TFLAG)
  4809. src &= 0xfffffffe;
  4810. else
  4811. #endif
  4812. src &= 0xfffffffc;
  4813. #ifdef MODE32
  4814. state->Reg[15] = src & PCBITS;
  4815. #else
  4816. state->Reg[15] = (src & R15PCBITS) | ECC | ER15INT | EMODE;
  4817. ARMul_R15Altered (state);
  4818. #endif
  4819. FLUSHPIPE;
  4820. }
  4821. /* This routine handles writes to register 15 when the S bit is set. */
  4822. static void
  4823. WriteSR15 (ARMul_State * state, ARMword src)
  4824. {
  4825. #ifdef MODE32
  4826. if (state->Bank > 0) {
  4827. state->Cpsr = state->Spsr[state->Bank];
  4828. ARMul_CPSRAltered (state);
  4829. }
  4830. #ifdef MODET
  4831. if (TFLAG)
  4832. src &= 0xfffffffe;
  4833. else
  4834. #endif
  4835. src &= 0xfffffffc;
  4836. state->Reg[15] = src & PCBITS;
  4837. #else
  4838. #ifdef MODET
  4839. if (TFLAG)
  4840. /* ARMul_R15Altered would have to support it. */
  4841. abort ();
  4842. else
  4843. #endif
  4844. src &= 0xfffffffc;
  4845. if (state->Bank == USERBANK)
  4846. state->Reg[15] =
  4847. (src & (CCBITS | R15PCBITS)) | ER15INT | EMODE;
  4848. else
  4849. state->Reg[15] = src;
  4850. ARMul_R15Altered (state);
  4851. #endif
  4852. FLUSHPIPE;
  4853. }
  4854. /* In machines capable of running in Thumb mode, BX, BLX, LDR and LDM
  4855. will switch to Thumb mode if the least significant bit is set. */
  4856. static void
  4857. WriteR15Branch (ARMul_State * state, ARMword src)
  4858. {
  4859. #ifdef MODET
  4860. if (src & 1) {
  4861. /* Thumb bit. */
  4862. SETT;
  4863. state->Reg[15] = src & 0xfffffffe;
  4864. }
  4865. else {
  4866. CLEART;
  4867. state->Reg[15] = src & 0xfffffffc;
  4868. }
  4869. state->Cpsr = ARMul_GetCPSR (state);
  4870. FLUSHPIPE;
  4871. #else
  4872. WriteR15 (state, src);
  4873. #endif
  4874. }
  4875. /* This routine evaluates most Load and Store register RHS's. It is
  4876. intended to be called from the macro LSRegRHS, which filters the
  4877. common case of an unshifted register with in line code. */
  4878. static ARMword
  4879. GetLSRegRHS (ARMul_State * state, ARMword instr)
  4880. {
  4881. ARMword shamt, base;
  4882. base = RHSReg;
  4883. #ifndef MODE32
  4884. if (base == 15)
  4885. /* Now forbidden, but ... */
  4886. base = ECC | ER15INT | R15PC | EMODE;
  4887. else
  4888. #endif
  4889. base = state->Reg[base];
  4890. shamt = BITS (7, 11);
  4891. switch ((int) BITS (5, 6)) {
  4892. case LSL:
  4893. return (base << shamt);
  4894. case LSR:
  4895. if (shamt == 0)
  4896. return (0);
  4897. else
  4898. return (base >> shamt);
  4899. case ASR:
  4900. if (shamt == 0)
  4901. return ((ARMword) (( int) base >> 31L));
  4902. else
  4903. return ((ARMword) (( int) base >> (int) shamt));
  4904. case ROR:
  4905. if (shamt == 0)
  4906. /* It's an RRX. */
  4907. return ((base >> 1) | (CFLAG << 31));
  4908. else
  4909. return ((base << (32 - shamt)) | (base >> shamt));
  4910. default:
  4911. break;
  4912. }
  4913. return 0;
  4914. }
  4915. /* This routine evaluates the ARM7T halfword and signed transfer RHS's. */
  4916. static ARMword
  4917. GetLS7RHS (ARMul_State * state, ARMword instr)
  4918. {
  4919. if (BIT (22) == 0) {
  4920. /* Register. */
  4921. #ifndef MODE32
  4922. if (RHSReg == 15)
  4923. /* Now forbidden, but ... */
  4924. return ECC | ER15INT | R15PC | EMODE;
  4925. #endif
  4926. return state->Reg[RHSReg];
  4927. }
  4928. /* Immediate. */
  4929. return BITS (0, 3) | (BITS (8, 11) << 4);
  4930. }
  4931. /* This function does the work of loading a word for a LDR instruction. */
  4932. #define MEM_LOAD_LOG(description) if (skyeye_config.log.memlogon >= 1) { \
  4933. fprintf(skyeye_logfd, \
  4934. "m LOAD %s: N %llx :p %x :i %x :a %x :d %x\n", \
  4935. description, state->NumInstrs, state->pc, instr, \
  4936. address, dest); \
  4937. }
  4938. #define MEM_STORE_LOG(description) if (skyeye_config.log.memlogon >= 1) { \
  4939. fprintf(skyeye_logfd, \
  4940. "m STORE %s: N %llx :p %x :i %x :a %x :d %x\n", \
  4941. description, state->NumInstrs, state->pc, instr, \
  4942. address, DEST); \
  4943. }
  4944. static unsigned
  4945. LoadWord (ARMul_State * state, ARMword instr, ARMword address)
  4946. {
  4947. ARMword dest;
  4948. BUSUSEDINCPCS;
  4949. #ifndef MODE32
  4950. if (ADDREXCEPT (address))
  4951. INTERNALABORT (address);
  4952. #endif
  4953. dest = ARMul_LoadWordN (state, address);
  4954. if (state->Aborted) {
  4955. TAKEABORT;
  4956. return state->lateabtSig;
  4957. }
  4958. if (address & 3)
  4959. dest = ARMul_Align (state, address, dest);
  4960. WRITEDESTB (dest);
  4961. ARMul_Icycles (state, 1, 0L);
  4962. //MEM_LOAD_LOG("WORD");
  4963. return (DESTReg != LHSReg);
  4964. }
  4965. #ifdef MODET
  4966. /* This function does the work of loading a halfword. */
  4967. static unsigned
  4968. LoadHalfWord (ARMul_State * state, ARMword instr, ARMword address,
  4969. int signextend)
  4970. {
  4971. ARMword dest;
  4972. BUSUSEDINCPCS;
  4973. #ifndef MODE32
  4974. if (ADDREXCEPT (address))
  4975. INTERNALABORT (address);
  4976. #endif
  4977. dest = ARMul_LoadHalfWord (state, address);
  4978. if (state->Aborted) {
  4979. TAKEABORT;
  4980. return state->lateabtSig;
  4981. }
  4982. UNDEF_LSRBPC;
  4983. if (signextend)
  4984. if (dest & 1 << (16 - 1))
  4985. dest = (dest & ((1 << 16) - 1)) - (1 << 16);
  4986. WRITEDEST (dest);
  4987. ARMul_Icycles (state, 1, 0L);
  4988. //MEM_LOAD_LOG("HALFWORD");
  4989. return (DESTReg != LHSReg);
  4990. }
  4991. #endif /* MODET */
  4992. /* This function does the work of loading a byte for a LDRB instruction. */
  4993. static unsigned
  4994. LoadByte (ARMul_State * state, ARMword instr, ARMword address, int signextend)
  4995. {
  4996. ARMword dest;
  4997. BUSUSEDINCPCS;
  4998. #ifndef MODE32
  4999. if (ADDREXCEPT (address))
  5000. INTERNALABORT (address);
  5001. #endif
  5002. dest = ARMul_LoadByte (state, address);
  5003. if (state->Aborted) {
  5004. TAKEABORT;
  5005. return state->lateabtSig;
  5006. }
  5007. UNDEF_LSRBPC;
  5008. if (signextend)
  5009. if (dest & 1 << (8 - 1))
  5010. dest = (dest & ((1 << 8) - 1)) - (1 << 8);
  5011. WRITEDEST (dest);
  5012. ARMul_Icycles (state, 1, 0L);
  5013. //MEM_LOAD_LOG("BYTE");
  5014. return (DESTReg != LHSReg);
  5015. }
  5016. /* This function does the work of loading two words for a LDRD instruction. */
  5017. static void
  5018. Handle_Load_Double (ARMul_State * state, ARMword instr)
  5019. {
  5020. ARMword dest_reg;
  5021. ARMword addr_reg;
  5022. ARMword write_back = BIT (21);
  5023. ARMword immediate = BIT (22);
  5024. ARMword add_to_base = BIT (23);
  5025. ARMword pre_indexed = BIT (24);
  5026. ARMword offset;
  5027. ARMword addr;
  5028. ARMword sum;
  5029. ARMword base;
  5030. ARMword value1;
  5031. ARMword value2;
  5032. BUSUSEDINCPCS;
  5033. /* If the writeback bit is set, the pre-index bit must be clear. */
  5034. if (write_back && !pre_indexed) {
  5035. ARMul_UndefInstr (state, instr);
  5036. return;
  5037. }
  5038. /* Extract the base address register. */
  5039. addr_reg = LHSReg;
  5040. /* Extract the destination register and check it. */
  5041. dest_reg = DESTReg;
  5042. /* Destination register must be even. */
  5043. if ((dest_reg & 1)
  5044. /* Destination register cannot be LR. */
  5045. || (dest_reg == 14)) {
  5046. ARMul_UndefInstr (state, instr);
  5047. return;
  5048. }
  5049. /* Compute the base address. */
  5050. base = state->Reg[addr_reg];
  5051. /* Compute the offset. */
  5052. offset = immediate ? ((BITS (8, 11) << 4) | BITS (0, 3)) : state->
  5053. Reg[RHSReg];
  5054. /* Compute the sum of the two. */
  5055. if (add_to_base)
  5056. sum = base + offset;
  5057. else
  5058. sum = base - offset;
  5059. /* If this is a pre-indexed mode use the sum. */
  5060. if (pre_indexed)
  5061. addr = sum;
  5062. else
  5063. addr = base;
  5064. /* The address must be aligned on a 8 byte boundary. */
  5065. // FIX(Normatt): Disable strict alignment on LDRD/STRD
  5066. // if (addr & 0x7) {
  5067. //#ifdef ABORTS
  5068. // ARMul_DATAABORT (addr);
  5069. //#else
  5070. // ARMul_UndefInstr (state, instr);
  5071. //#endif
  5072. // return;
  5073. // }
  5074. /* For pre indexed or post indexed addressing modes,
  5075. check that the destination registers do not overlap
  5076. the address registers. */
  5077. if ((!pre_indexed || write_back)
  5078. && (addr_reg == dest_reg || addr_reg == dest_reg + 1)) {
  5079. ARMul_UndefInstr (state, instr);
  5080. return;
  5081. }
  5082. /* Load the words. */
  5083. value1 = ARMul_LoadWordN (state, addr);
  5084. value2 = ARMul_LoadWordN (state, addr + 4);
  5085. /* Check for data aborts. */
  5086. if (state->Aborted) {
  5087. TAKEABORT;
  5088. return;
  5089. }
  5090. ARMul_Icycles (state, 2, 0L);
  5091. /* Store the values. */
  5092. state->Reg[dest_reg] = value1;
  5093. state->Reg[dest_reg + 1] = value2;
  5094. /* Do the post addressing and writeback. */
  5095. if (!pre_indexed)
  5096. addr = sum;
  5097. if (!pre_indexed || write_back)
  5098. state->Reg[addr_reg] = addr;
  5099. }
  5100. /* This function does the work of storing two words for a STRD instruction. */
  5101. static void
  5102. Handle_Store_Double (ARMul_State * state, ARMword instr)
  5103. {
  5104. ARMword src_reg;
  5105. ARMword addr_reg;
  5106. ARMword write_back = BIT (21);
  5107. ARMword immediate = BIT (22);
  5108. ARMword add_to_base = BIT (23);
  5109. ARMword pre_indexed = BIT (24);
  5110. ARMword offset;
  5111. ARMword addr;
  5112. ARMword sum;
  5113. ARMword base;
  5114. BUSUSEDINCPCS;
  5115. /* If the writeback bit is set, the pre-index bit must be clear. */
  5116. if (write_back && !pre_indexed) {
  5117. ARMul_UndefInstr (state, instr);
  5118. return;
  5119. }
  5120. /* Extract the base address register. */
  5121. addr_reg = LHSReg;
  5122. /* Base register cannot be PC. */
  5123. if (addr_reg == 15) {
  5124. ARMul_UndefInstr (state, instr);
  5125. return;
  5126. }
  5127. /* Extract the source register. */
  5128. src_reg = DESTReg;
  5129. /* Source register must be even. */
  5130. if (src_reg & 1) {
  5131. ARMul_UndefInstr (state, instr);
  5132. return;
  5133. }
  5134. /* Compute the base address. */
  5135. base = state->Reg[addr_reg];
  5136. /* Compute the offset. */
  5137. offset = immediate ? ((BITS (8, 11) << 4) | BITS (0, 3)) : state->
  5138. Reg[RHSReg];
  5139. /* Compute the sum of the two. */
  5140. if (add_to_base)
  5141. sum = base + offset;
  5142. else
  5143. sum = base - offset;
  5144. /* If this is a pre-indexed mode use the sum. */
  5145. if (pre_indexed)
  5146. addr = sum;
  5147. else
  5148. addr = base;
  5149. /* The address must be aligned on a 8 byte boundary. */
  5150. // FIX(Normatt): Disable strict alignment on LDRD/STRD
  5151. // if (addr & 0x7) {
  5152. //#ifdef ABORTS
  5153. // ARMul_DATAABORT (addr);
  5154. //#else
  5155. // ARMul_UndefInstr (state, instr);
  5156. //#endif
  5157. // return;
  5158. // }
  5159. /* For pre indexed or post indexed addressing modes,
  5160. check that the destination registers do not overlap
  5161. the address registers. */
  5162. if ((!pre_indexed || write_back)
  5163. && (addr_reg == src_reg || addr_reg == src_reg + 1)) {
  5164. ARMul_UndefInstr (state, instr);
  5165. return;
  5166. }
  5167. /* Load the words. */
  5168. ARMul_StoreWordN (state, addr, state->Reg[src_reg]);
  5169. ARMul_StoreWordN (state, addr + 4, state->Reg[src_reg + 1]);
  5170. if (state->Aborted) {
  5171. TAKEABORT;
  5172. return;
  5173. }
  5174. /* Do the post addressing and writeback. */
  5175. if (!pre_indexed)
  5176. addr = sum;
  5177. if (!pre_indexed || write_back)
  5178. state->Reg[addr_reg] = addr;
  5179. }
  5180. /* This function does the work of storing a word from a STR instruction. */
  5181. static unsigned
  5182. StoreWord (ARMul_State * state, ARMword instr, ARMword address)
  5183. {
  5184. //MEM_STORE_LOG("WORD");
  5185. BUSUSEDINCPCN;
  5186. #ifndef MODE32
  5187. if (DESTReg == 15)
  5188. state->Reg[15] = ECC | ER15INT | R15PC | EMODE;
  5189. #endif
  5190. #ifdef MODE32
  5191. ARMul_StoreWordN (state, address, DEST);
  5192. #else
  5193. if (VECTORACCESS (address) || ADDREXCEPT (address)) {
  5194. INTERNALABORT (address);
  5195. (void) ARMul_LoadWordN (state, address);
  5196. }
  5197. else
  5198. ARMul_StoreWordN (state, address, DEST);
  5199. #endif
  5200. if (state->Aborted) {
  5201. TAKEABORT;
  5202. return state->lateabtSig;
  5203. }
  5204. return TRUE;
  5205. }
  5206. #ifdef MODET
  5207. /* This function does the work of storing a byte for a STRH instruction. */
  5208. static unsigned
  5209. StoreHalfWord (ARMul_State * state, ARMword instr, ARMword address)
  5210. {
  5211. //MEM_STORE_LOG("HALFWORD");
  5212. BUSUSEDINCPCN;
  5213. #ifndef MODE32
  5214. if (DESTReg == 15)
  5215. state->Reg[15] = ECC | ER15INT | R15PC | EMODE;
  5216. #endif
  5217. #ifdef MODE32
  5218. ARMul_StoreHalfWord (state, address, DEST);
  5219. #else
  5220. if (VECTORACCESS (address) || ADDREXCEPT (address)) {
  5221. INTERNALABORT (address);
  5222. (void) ARMul_LoadHalfWord (state, address);
  5223. }
  5224. else
  5225. ARMul_StoreHalfWord (state, address, DEST);
  5226. #endif
  5227. if (state->Aborted) {
  5228. TAKEABORT;
  5229. return state->lateabtSig;
  5230. }
  5231. return TRUE;
  5232. }
  5233. #endif /* MODET */
  5234. /* This function does the work of storing a byte for a STRB instruction. */
  5235. static unsigned
  5236. StoreByte (ARMul_State * state, ARMword instr, ARMword address)
  5237. {
  5238. //MEM_STORE_LOG("BYTE");
  5239. BUSUSEDINCPCN;
  5240. #ifndef MODE32
  5241. if (DESTReg == 15)
  5242. state->Reg[15] = ECC | ER15INT | R15PC | EMODE;
  5243. #endif
  5244. #ifdef MODE32
  5245. ARMul_StoreByte (state, address, DEST);
  5246. #else
  5247. if (VECTORACCESS (address) || ADDREXCEPT (address)) {
  5248. INTERNALABORT (address);
  5249. (void) ARMul_LoadByte (state, address);
  5250. }
  5251. else
  5252. ARMul_StoreByte (state, address, DEST);
  5253. #endif
  5254. if (state->Aborted) {
  5255. TAKEABORT;
  5256. return state->lateabtSig;
  5257. }
  5258. //UNDEF_LSRBPC;
  5259. return TRUE;
  5260. }
  5261. /* This function does the work of loading the registers listed in an LDM
  5262. instruction, when the S bit is clear. The code here is always increment
  5263. after, it's up to the caller to get the input address correct and to
  5264. handle base register modification. */
  5265. static void
  5266. LoadMult (ARMul_State * state, ARMword instr, ARMword address, ARMword WBBase)
  5267. {
  5268. ARMword dest, temp;
  5269. //UNDEF_LSMNoRegs;
  5270. //UNDEF_LSMPCBase;
  5271. //UNDEF_LSMBaseInListWb;
  5272. BUSUSEDINCPCS;
  5273. #ifndef MODE32
  5274. if (ADDREXCEPT (address))
  5275. INTERNALABORT (address);
  5276. #endif
  5277. /*chy 2004-05-23 may write twice
  5278. if (BIT (21) && LHSReg != 15)
  5279. LSBase = WBBase;
  5280. */
  5281. /* N cycle first. */
  5282. for (temp = 0; !BIT (temp); temp++);
  5283. dest = ARMul_LoadWordN (state, address);
  5284. if (!state->abortSig && !state->Aborted)
  5285. state->Reg[temp++] = dest;
  5286. else if (!state->Aborted) {
  5287. XScale_set_fsr_far (state, ARMul_CP15_R5_ST_ALIGN, address);
  5288. state->Aborted = ARMul_DataAbortV;
  5289. }
  5290. /*chy 2004-05-23 chy goto end*/
  5291. if (state->Aborted)
  5292. goto L_ldm_makeabort;
  5293. /* S cycles from here on. */
  5294. for (; temp < 16; temp++)
  5295. if (BIT (temp)) {
  5296. /* Load this register. */
  5297. address += 4;
  5298. dest = ARMul_LoadWordS (state, address);
  5299. if (!state->abortSig && !state->Aborted)
  5300. state->Reg[temp] = dest;
  5301. else if (!state->Aborted) {
  5302. XScale_set_fsr_far (state,
  5303. ARMul_CP15_R5_ST_ALIGN,
  5304. address);
  5305. state->Aborted = ARMul_DataAbortV;
  5306. }
  5307. /*chy 2004-05-23 chy goto end */
  5308. if (state->Aborted)
  5309. goto L_ldm_makeabort;
  5310. }
  5311. if (BIT (15) && !state->Aborted)
  5312. /* PC is in the reg list. */
  5313. WriteR15Branch(state, (state->Reg[15] & PCMASK));
  5314. /* To write back the final register. */
  5315. /* ARMul_Icycles (state, 1, 0L);*/
  5316. /*chy 2004-05-23, see below
  5317. if (state->Aborted)
  5318. {
  5319. if (BIT (21) && LHSReg != 15)
  5320. LSBase = WBBase;
  5321. TAKEABORT;
  5322. }
  5323. */
  5324. /*chy 2004-05-23 should compare the Abort Models*/
  5325. L_ldm_makeabort:
  5326. /* To write back the final register. */
  5327. ARMul_Icycles (state, 1, 0L);
  5328. /* chy 2005-11-24, bug found by benjl@cse.unsw.edu.au, etc */
  5329. /*
  5330. if (state->Aborted)
  5331. {
  5332. if (BIT (21) && LHSReg != 15)
  5333. if (!(state->abortSig && state->Aborted && state->lateabtSig == LOW))
  5334. LSBase = WBBase;
  5335. TAKEABORT;
  5336. }else if (BIT (21) && LHSReg != 15)
  5337. LSBase = WBBase;
  5338. */
  5339. if (state->Aborted) {
  5340. if (BIT (21) && LHSReg != 15) {
  5341. if (!(state->abortSig)) {
  5342. }
  5343. }
  5344. TAKEABORT;
  5345. }
  5346. else if (BIT (21) && LHSReg != 15) {
  5347. LSBase = WBBase;
  5348. }
  5349. /* chy 2005-11-24, over */
  5350. }
  5351. /* This function does the work of loading the registers listed in an LDM
  5352. instruction, when the S bit is set. The code here is always increment
  5353. after, it's up to the caller to get the input address correct and to
  5354. handle base register modification. */
  5355. static void
  5356. LoadSMult (ARMul_State * state,
  5357. ARMword instr, ARMword address, ARMword WBBase)
  5358. {
  5359. ARMword dest, temp;
  5360. //UNDEF_LSMNoRegs;
  5361. //UNDEF_LSMPCBase;
  5362. //UNDEF_LSMBaseInListWb;
  5363. BUSUSEDINCPCS;
  5364. #ifndef MODE32
  5365. if (ADDREXCEPT (address))
  5366. INTERNALABORT (address);
  5367. #endif
  5368. /* chy 2004-05-23, may write twice
  5369. if (BIT (21) && LHSReg != 15)
  5370. LSBase = WBBase;
  5371. */
  5372. if (!BIT (15) && state->Bank != USERBANK) {
  5373. /* Temporary reg bank switch. */
  5374. (void) ARMul_SwitchMode (state, state->Mode, USER26MODE);
  5375. UNDEF_LSMUserBankWb;
  5376. }
  5377. /* N cycle first. */
  5378. for (temp = 0; !BIT (temp); temp++);
  5379. dest = ARMul_LoadWordN (state, address);
  5380. if (!state->abortSig)
  5381. state->Reg[temp++] = dest;
  5382. else if (!state->Aborted) {
  5383. XScale_set_fsr_far (state, ARMul_CP15_R5_ST_ALIGN, address);
  5384. state->Aborted = ARMul_DataAbortV;
  5385. }
  5386. /*chy 2004-05-23 chy goto end*/
  5387. if (state->Aborted)
  5388. goto L_ldm_s_makeabort;
  5389. /* S cycles from here on. */
  5390. for (; temp < 16; temp++)
  5391. if (BIT (temp)) {
  5392. /* Load this register. */
  5393. address += 4;
  5394. dest = ARMul_LoadWordS (state, address);
  5395. if (!state->abortSig && !state->Aborted)
  5396. state->Reg[temp] = dest;
  5397. else if (!state->Aborted) {
  5398. XScale_set_fsr_far (state,
  5399. ARMul_CP15_R5_ST_ALIGN,
  5400. address);
  5401. state->Aborted = ARMul_DataAbortV;
  5402. }
  5403. /*chy 2004-05-23 chy goto end */
  5404. if (state->Aborted)
  5405. goto L_ldm_s_makeabort;
  5406. }
  5407. /*chy 2004-05-23 label of ldm_s_makeabort*/
  5408. L_ldm_s_makeabort:
  5409. /*chy 2004-06-06 LSBase process should be here, not in the end of this function. Because ARMul_CPSRAltered maybe change R13(SP) R14(lr). If not, simulate INSTR ldmia sp!,[....pc]^ error.*/
  5410. /*chy 2004-05-23 should compare the Abort Models*/
  5411. if (state->Aborted) {
  5412. if (BIT (21) && LHSReg != 15)
  5413. if (!
  5414. (state->abortSig && state->Aborted
  5415. && state->lateabtSig == LOW))
  5416. LSBase = WBBase;
  5417. TAKEABORT;
  5418. }
  5419. else if (BIT (21) && LHSReg != 15)
  5420. LSBase = WBBase;
  5421. if (BIT (15) && !state->Aborted) {
  5422. /* PC is in the reg list. */
  5423. #ifdef MODE32
  5424. //chy 2006-02-16 , should not consider system mode, don't conside 26bit mode
  5425. if (state->Mode != USER26MODE && state->Mode != USER32MODE ){
  5426. state->Cpsr = GETSPSR (state->Bank);
  5427. ARMul_CPSRAltered (state);
  5428. }
  5429. WriteR15 (state, (state->Reg[15] & PCMASK));
  5430. #else
  5431. //chy 2006-02-16 , should not consider system mode, don't conside 26bit mode
  5432. if (state->Mode == USER26MODE || state->Mode == USER32MODE ) {
  5433. /* Protect bits in user mode. */
  5434. ASSIGNN ((state->Reg[15] & NBIT) != 0);
  5435. ASSIGNZ ((state->Reg[15] & ZBIT) != 0);
  5436. ASSIGNC ((state->Reg[15] & CBIT) != 0);
  5437. ASSIGNV ((state->Reg[15] & VBIT) != 0);
  5438. }
  5439. else
  5440. ARMul_R15Altered (state);
  5441. FLUSHPIPE;
  5442. #endif
  5443. }
  5444. //chy 2006-02-16 , should not consider system mode, don't conside 26bit mode
  5445. if (!BIT (15) && state->Mode != USER26MODE
  5446. && state->Mode != USER32MODE )
  5447. /* Restore the correct bank. */
  5448. (void) ARMul_SwitchMode (state, USER26MODE, state->Mode);
  5449. /* To write back the final register. */
  5450. ARMul_Icycles (state, 1, 0L);
  5451. /* chy 2004-05-23, see below
  5452. if (state->Aborted)
  5453. {
  5454. if (BIT (21) && LHSReg != 15)
  5455. LSBase = WBBase;
  5456. TAKEABORT;
  5457. }
  5458. */
  5459. }
  5460. /* This function does the work of storing the registers listed in an STM
  5461. instruction, when the S bit is clear. The code here is always increment
  5462. after, it's up to the caller to get the input address correct and to
  5463. handle base register modification. */
  5464. static void
  5465. StoreMult (ARMul_State * state,
  5466. ARMword instr, ARMword address, ARMword WBBase)
  5467. {
  5468. ARMword temp;
  5469. UNDEF_LSMNoRegs;
  5470. UNDEF_LSMPCBase;
  5471. UNDEF_LSMBaseInListWb;
  5472. if (!TFLAG)
  5473. /* N-cycle, increment the PC and update the NextInstr state. */
  5474. BUSUSEDINCPCN;
  5475. #ifndef MODE32
  5476. if (VECTORACCESS (address) || ADDREXCEPT (address))
  5477. INTERNALABORT (address);
  5478. if (BIT (15))
  5479. PATCHR15;
  5480. #endif
  5481. /* N cycle first. */
  5482. for (temp = 0; !BIT (temp); temp++);
  5483. #ifdef MODE32
  5484. ARMul_StoreWordN (state, address, state->Reg[temp++]);
  5485. #else
  5486. if (state->Aborted) {
  5487. (void) ARMul_LoadWordN (state, address);
  5488. /* Fake the Stores as Loads. */
  5489. for (; temp < 16; temp++)
  5490. if (BIT (temp)) {
  5491. /* Save this register. */
  5492. address += 4;
  5493. (void) ARMul_LoadWordS (state, address);
  5494. }
  5495. if (BIT (21) && LHSReg != 15)
  5496. LSBase = WBBase;
  5497. TAKEABORT;
  5498. return;
  5499. }
  5500. else
  5501. ARMul_StoreWordN (state, address, state->Reg[temp++]);
  5502. #endif
  5503. if (state->abortSig && !state->Aborted) {
  5504. XScale_set_fsr_far (state, ARMul_CP15_R5_ST_ALIGN, address);
  5505. state->Aborted = ARMul_DataAbortV;
  5506. }
  5507. //chy 2004-05-23, needn't store other when aborted
  5508. if (state->Aborted)
  5509. goto L_stm_takeabort;
  5510. /* S cycles from here on. */
  5511. for (; temp < 16; temp++)
  5512. if (BIT (temp)) {
  5513. /* Save this register. */
  5514. address += 4;
  5515. ARMul_StoreWordS (state, address, state->Reg[temp]);
  5516. if (state->abortSig && !state->Aborted) {
  5517. XScale_set_fsr_far (state,
  5518. ARMul_CP15_R5_ST_ALIGN,
  5519. address);
  5520. state->Aborted = ARMul_DataAbortV;
  5521. }
  5522. //chy 2004-05-23, needn't store other when aborted
  5523. if (state->Aborted)
  5524. goto L_stm_takeabort;
  5525. }
  5526. //chy 2004-05-23,should compare the Abort Models
  5527. L_stm_takeabort:
  5528. if (BIT (21) && LHSReg != 15) {
  5529. if (!
  5530. (state->abortSig && state->Aborted
  5531. && state->lateabtSig == LOW))
  5532. LSBase = WBBase;
  5533. }
  5534. if (state->Aborted)
  5535. TAKEABORT;
  5536. }
  5537. /* This function does the work of storing the registers listed in an STM
  5538. instruction when the S bit is set. The code here is always increment
  5539. after, it's up to the caller to get the input address correct and to
  5540. handle base register modification. */
  5541. static void
  5542. StoreSMult (ARMul_State * state,
  5543. ARMword instr, ARMword address, ARMword WBBase)
  5544. {
  5545. ARMword temp;
  5546. UNDEF_LSMNoRegs;
  5547. UNDEF_LSMPCBase;
  5548. UNDEF_LSMBaseInListWb;
  5549. BUSUSEDINCPCN;
  5550. #ifndef MODE32
  5551. if (VECTORACCESS (address) || ADDREXCEPT (address))
  5552. INTERNALABORT (address);
  5553. if (BIT (15))
  5554. PATCHR15;
  5555. #endif
  5556. if (state->Bank != USERBANK) {
  5557. /* Force User Bank. */
  5558. (void) ARMul_SwitchMode (state, state->Mode, USER26MODE);
  5559. UNDEF_LSMUserBankWb;
  5560. }
  5561. for (temp = 0; !BIT (temp); temp++); /* N cycle first. */
  5562. #ifdef MODE32
  5563. ARMul_StoreWordN (state, address, state->Reg[temp++]);
  5564. #else
  5565. if (state->Aborted) {
  5566. (void) ARMul_LoadWordN (state, address);
  5567. for (; temp < 16; temp++)
  5568. /* Fake the Stores as Loads. */
  5569. if (BIT (temp)) {
  5570. /* Save this register. */
  5571. address += 4;
  5572. (void) ARMul_LoadWordS (state, address);
  5573. }
  5574. if (BIT (21) && LHSReg != 15)
  5575. LSBase = WBBase;
  5576. TAKEABORT;
  5577. return;
  5578. }
  5579. else
  5580. ARMul_StoreWordN (state, address, state->Reg[temp++]);
  5581. #endif
  5582. if (state->abortSig && !state->Aborted) {
  5583. XScale_set_fsr_far (state, ARMul_CP15_R5_ST_ALIGN, address);
  5584. state->Aborted = ARMul_DataAbortV;
  5585. }
  5586. //chy 2004-05-23, needn't store other when aborted
  5587. if (state->Aborted)
  5588. goto L_stm_s_takeabort;
  5589. /* S cycles from here on. */
  5590. for (; temp < 16; temp++)
  5591. if (BIT (temp)) {
  5592. /* Save this register. */
  5593. address += 4;
  5594. ARMul_StoreWordS (state, address, state->Reg[temp]);
  5595. if (state->abortSig && !state->Aborted) {
  5596. XScale_set_fsr_far (state,
  5597. ARMul_CP15_R5_ST_ALIGN,
  5598. address);
  5599. state->Aborted = ARMul_DataAbortV;
  5600. }
  5601. //chy 2004-05-23, needn't store other when aborted
  5602. if (state->Aborted)
  5603. goto L_stm_s_takeabort;
  5604. }
  5605. //chy 2006-02-16 , should not consider system mode, don't conside 26bit mode
  5606. if (state->Mode != USER26MODE && state->Mode != USER32MODE )
  5607. /* Restore the correct bank. */
  5608. (void) ARMul_SwitchMode (state, USER26MODE, state->Mode);
  5609. //chy 2004-05-23,should compare the Abort Models
  5610. L_stm_s_takeabort:
  5611. if (BIT (21) && LHSReg != 15) {
  5612. if (!
  5613. (state->abortSig && state->Aborted
  5614. && state->lateabtSig == LOW))
  5615. LSBase = WBBase;
  5616. }
  5617. if (state->Aborted)
  5618. TAKEABORT;
  5619. }
  5620. /* This function does the work of adding two 32bit values
  5621. together, and calculating if a carry has occurred. */
  5622. static ARMword
  5623. Add32 (ARMword a1, ARMword a2, int *carry)
  5624. {
  5625. ARMword result = (a1 + a2);
  5626. unsigned int uresult = (unsigned int) result;
  5627. unsigned int ua1 = (unsigned int) a1;
  5628. /* If (result == RdLo) and (state->Reg[nRdLo] == 0),
  5629. or (result > RdLo) then we have no carry. */
  5630. if ((uresult == ua1) ? (a2 != 0) : (uresult < ua1))
  5631. *carry = 1;
  5632. else
  5633. *carry = 0;
  5634. return result;
  5635. }
  5636. /* This function does the work of multiplying
  5637. two 32bit values to give a 64bit result. */
  5638. static unsigned
  5639. Multiply64 (ARMul_State * state, ARMword instr, int msigned, int scc)
  5640. {
  5641. /* Operand register numbers. */
  5642. int nRdHi, nRdLo, nRs, nRm;
  5643. ARMword RdHi = 0, RdLo = 0, Rm;
  5644. /* Cycle count. */
  5645. int scount;
  5646. nRdHi = BITS (16, 19);
  5647. nRdLo = BITS (12, 15);
  5648. nRs = BITS (8, 11);
  5649. nRm = BITS (0, 3);
  5650. /* Needed to calculate the cycle count. */
  5651. Rm = state->Reg[nRm];
  5652. /* Check for illegal operand combinations first. */
  5653. if (nRdHi != 15
  5654. && nRdLo != 15
  5655. && nRs != 15
  5656. //&& nRm != 15 && nRdHi != nRdLo && nRdHi != nRm && nRdLo != nRm) {
  5657. && nRm != 15 && nRdHi != nRdLo ) {
  5658. /* Intermediate results. */
  5659. ARMword lo, mid1, mid2, hi;
  5660. int carry;
  5661. ARMword Rs = state->Reg[nRs];
  5662. int sign = 0;
  5663. if (msigned) {
  5664. /* Compute sign of result and adjust operands if necessary. */
  5665. sign = (Rm ^ Rs) & 0x80000000;
  5666. if (((signed int) Rm) < 0)
  5667. Rm = -Rm;
  5668. if (((signed int) Rs) < 0)
  5669. Rs = -Rs;
  5670. }
  5671. /* We can split the 32x32 into four 16x16 operations. This
  5672. ensures that we do not lose precision on 32bit only hosts. */
  5673. lo = ((Rs & 0xFFFF) * (Rm & 0xFFFF));
  5674. mid1 = ((Rs & 0xFFFF) * ((Rm >> 16) & 0xFFFF));
  5675. mid2 = (((Rs >> 16) & 0xFFFF) * (Rm & 0xFFFF));
  5676. hi = (((Rs >> 16) & 0xFFFF) * ((Rm >> 16) & 0xFFFF));
  5677. /* We now need to add all of these results together, taking
  5678. care to propogate the carries from the additions. */
  5679. RdLo = Add32 (lo, (mid1 << 16), &carry);
  5680. RdHi = carry;
  5681. RdLo = Add32 (RdLo, (mid2 << 16), &carry);
  5682. RdHi += (carry + ((mid1 >> 16) & 0xFFFF) +
  5683. ((mid2 >> 16) & 0xFFFF) + hi);
  5684. if (sign) {
  5685. /* Negate result if necessary. */
  5686. RdLo = ~RdLo;
  5687. RdHi = ~RdHi;
  5688. if (RdLo == 0xFFFFFFFF) {
  5689. RdLo = 0;
  5690. RdHi += 1;
  5691. }
  5692. else
  5693. RdLo += 1;
  5694. }
  5695. state->Reg[nRdLo] = RdLo;
  5696. state->Reg[nRdHi] = RdHi;
  5697. }
  5698. else{
  5699. fprintf (stderr, "sim: MULTIPLY64 - INVALID ARGUMENTS, instr=0x%x\n", instr);
  5700. }
  5701. if (scc)
  5702. /* Ensure that both RdHi and RdLo are used to compute Z,
  5703. but don't let RdLo's sign bit make it to N. */
  5704. ARMul_NegZero (state, RdHi | (RdLo >> 16) | (RdLo & 0xFFFF));
  5705. /* The cycle count depends on whether the instruction is a signed or
  5706. unsigned multiply, and what bits are clear in the multiplier. */
  5707. if (msigned && (Rm & ((unsigned) 1 << 31)))
  5708. /* Invert the bits to make the check against zero. */
  5709. Rm = ~Rm;
  5710. if ((Rm & 0xFFFFFF00) == 0)
  5711. scount = 1;
  5712. else if ((Rm & 0xFFFF0000) == 0)
  5713. scount = 2;
  5714. else if ((Rm & 0xFF000000) == 0)
  5715. scount = 3;
  5716. else
  5717. scount = 4;
  5718. return 2 + scount;
  5719. }
  5720. /* This function does the work of multiplying two 32bit
  5721. values and adding a 64bit value to give a 64bit result. */
  5722. static unsigned
  5723. MultiplyAdd64 (ARMul_State * state, ARMword instr, int msigned, int scc)
  5724. {
  5725. unsigned scount;
  5726. ARMword RdLo, RdHi;
  5727. int nRdHi, nRdLo;
  5728. int carry = 0;
  5729. nRdHi = BITS (16, 19);
  5730. nRdLo = BITS (12, 15);
  5731. RdHi = state->Reg[nRdHi];
  5732. RdLo = state->Reg[nRdLo];
  5733. scount = Multiply64 (state, instr, msigned, LDEFAULT);
  5734. RdLo = Add32 (RdLo, state->Reg[nRdLo], &carry);
  5735. RdHi = (RdHi + state->Reg[nRdHi]) + carry;
  5736. state->Reg[nRdLo] = RdLo;
  5737. state->Reg[nRdHi] = RdHi;
  5738. if (scc)
  5739. /* Ensure that both RdHi and RdLo are used to compute Z,
  5740. but don't let RdLo's sign bit make it to N. */
  5741. ARMul_NegZero (state, RdHi | (RdLo >> 16) | (RdLo & 0xFFFF));
  5742. /* Extra cycle for addition. */
  5743. return scount + 1;
  5744. }
  5745. /* Attempt to emulate an ARMv6 instruction.
  5746. Returns non-zero upon success. */
  5747. static int
  5748. handle_v6_insn (ARMul_State * state, ARMword instr)
  5749. {
  5750. switch (BITS (20, 27))
  5751. {
  5752. #if 0
  5753. case 0x03: printf ("Unhandled v6 insn: ldr\n"); break;
  5754. case 0x04: printf ("Unhandled v6 insn: umaal\n"); break;
  5755. case 0x06: printf ("Unhandled v6 insn: mls/str\n"); break;
  5756. case 0x16: printf ("Unhandled v6 insn: smi\n"); break;
  5757. case 0x18: printf ("Unhandled v6 insn: strex\n"); break;
  5758. case 0x19: printf ("Unhandled v6 insn: ldrex\n"); break;
  5759. case 0x1a: printf ("Unhandled v6 insn: strexd\n"); break;
  5760. case 0x1b: printf ("Unhandled v6 insn: ldrexd\n"); break;
  5761. case 0x1c: printf ("Unhandled v6 insn: strexb\n"); break;
  5762. case 0x1d: printf ("Unhandled v6 insn: ldrexb\n"); break;
  5763. case 0x1e: printf ("Unhandled v6 insn: strexh\n"); break;
  5764. case 0x1f: printf ("Unhandled v6 insn: ldrexh\n"); break;
  5765. case 0x30: printf ("Unhandled v6 insn: movw\n"); break;
  5766. case 0x32: printf ("Unhandled v6 insn: nop/sev/wfe/wfi/yield\n"); break;
  5767. case 0x34: printf ("Unhandled v6 insn: movt\n"); break;
  5768. case 0x3f: printf ("Unhandled v6 insn: rbit\n"); break;
  5769. case 0x61: printf ("Unhandled v6 insn: sadd/ssub\n"); break;
  5770. case 0x62: printf ("Unhandled v6 insn: qadd/qsub\n"); break;
  5771. case 0x63: printf ("Unhandled v6 insn: shadd/shsub\n"); break;
  5772. case 0x65: printf ("Unhandled v6 insn: uadd/usub\n"); break;
  5773. case 0x66: printf ("Unhandled v6 insn: uqadd/uqsub\n"); break;
  5774. case 0x67: printf ("Unhandled v6 insn: uhadd/uhsub\n"); break;
  5775. case 0x68: printf ("Unhandled v6 insn: pkh/sxtab/selsxtb\n"); break;
  5776. #endif
  5777. case 0x6c: printf ("Unhandled v6 insn: uxtb16/uxtab16\n"); break;
  5778. case 0x70: printf ("Unhandled v6 insn: smuad/smusd/smlad/smlsd\n"); break;
  5779. case 0x74: printf ("Unhandled v6 insn: smlald/smlsld\n"); break;
  5780. case 0x75: printf ("Unhandled v6 insn: smmla/smmls/smmul\n"); break;
  5781. case 0x78: printf ("Unhandled v6 insn: usad/usada8\n"); break;
  5782. #if 0
  5783. case 0x7a: printf ("Unhandled v6 insn: usbfx\n"); break;
  5784. case 0x7c: printf ("Unhandled v6 insn: bfc/bfi\n"); break;
  5785. #endif
  5786. /* add new instr for arm v6. */
  5787. ARMword lhs, temp;
  5788. case 0x18: /* ORR reg */
  5789. {
  5790. /* dyf add armv6 instr strex 2010.9.17 */
  5791. if (BITS (4, 7) == 0x9) {
  5792. lhs = LHS;
  5793. ARMul_StoreWordS(state, lhs, RHS);
  5794. //StoreWord(state, lhs, RHS)
  5795. if (state->Aborted) {
  5796. TAKEABORT;
  5797. }
  5798. // FIX(Normmatt): Handle RD in STREX/STREXB
  5799. state->Reg[DESTReg] = 0; //Always succeed
  5800. return 1;
  5801. }
  5802. break;
  5803. }
  5804. case 0x19: /* orrs reg */
  5805. {
  5806. /* dyf add armv6 instr ldrex */
  5807. if (BITS (4, 7) == 0x9) {
  5808. lhs = LHS;
  5809. LoadWord (state, instr, lhs);
  5810. return 1;
  5811. }
  5812. break;
  5813. }
  5814. case 0x1c: /* BIC reg */
  5815. {
  5816. /* dyf add for STREXB */
  5817. if (BITS (4, 7) == 0x9) {
  5818. lhs = LHS;
  5819. ARMul_StoreByte (state, lhs, RHS);
  5820. BUSUSEDINCPCN;
  5821. if (state->Aborted) {
  5822. TAKEABORT;
  5823. }
  5824. // FIX(Normmatt): Handle RD in STREX/STREXB
  5825. state->Reg[DESTReg] = 0; //Always succeed
  5826. //printf("In %s, strexb not implemented\n", __FUNCTION__);
  5827. UNDEF_LSRBPC;
  5828. /* WRITESDEST (dest); */
  5829. return 1;
  5830. }
  5831. break;
  5832. }
  5833. case 0x1d: /* BICS reg */
  5834. {
  5835. if ((BITS (4, 7)) == 0x9) {
  5836. /* ldrexb */
  5837. temp = LHS;
  5838. LoadByte (state, instr, temp, LUNSIGNED);
  5839. //state->Reg[BITS(12, 15)] = ARMul_LoadByte(state, state->Reg[BITS(16, 19)]);
  5840. //printf("ldrexb\n");
  5841. //printf("instr is %x rm is %d\n", instr, BITS(16, 19));
  5842. //exit(-1);
  5843. //printf("In %s, ldrexb not implemented\n", __FUNCTION__);
  5844. return 1;
  5845. }
  5846. break;
  5847. }
  5848. /* add end */
  5849. case 0x6a:
  5850. {
  5851. ARMword Rm;
  5852. int ror = -1;
  5853. switch (BITS (4, 11))
  5854. {
  5855. case 0x07: ror = 0; break;
  5856. case 0x47: ror = 8; break;
  5857. case 0x87: ror = 16; break;
  5858. case 0xc7: ror = 24; break;
  5859. case 0x01:
  5860. case 0xf3:
  5861. printf ("Unhandled v6 insn: ssat\n");
  5862. return 0;
  5863. default:
  5864. break;
  5865. }
  5866. if (ror == -1)
  5867. {
  5868. if (BITS (4, 6) == 0x7)
  5869. {
  5870. printf ("Unhandled v6 insn: ssat\n");
  5871. return 0;
  5872. }
  5873. break;
  5874. }
  5875. Rm = ((state->Reg[BITS (0, 3)] >> ror) & 0xFF);
  5876. if (Rm & 0x80)
  5877. Rm |= 0xffffff00;
  5878. if (BITS (16, 19) == 0xf)
  5879. /* SXTB */
  5880. state->Reg[BITS (12, 15)] = Rm;
  5881. else
  5882. /* SXTAB */
  5883. state->Reg[BITS (12, 15)] += Rm;
  5884. }
  5885. return 1;
  5886. case 0x6b:
  5887. {
  5888. ARMword Rm;
  5889. int ror = -1;
  5890. switch (BITS (4, 11))
  5891. {
  5892. case 0x07: ror = 0; break;
  5893. case 0x47: ror = 8; break;
  5894. case 0x87: ror = 16; break;
  5895. case 0xc7: ror = 24; break;
  5896. case 0xf3:
  5897. DEST = ((RHS & 0xFF) << 24) | ((RHS & 0xFF00)) << 8 | ((RHS & 0xFF0000) >> 8) | ((RHS & 0xFF000000) >> 24);
  5898. return 1;
  5899. case 0xfb:
  5900. DEST = ((RHS & 0xFF) << 8) | ((RHS & 0xFF00)) >> 8 | ((RHS & 0xFF0000) << 8) | ((RHS & 0xFF000000) >> 8);
  5901. return 1;
  5902. default:
  5903. break;
  5904. }
  5905. if (ror == -1)
  5906. break;
  5907. Rm = ((state->Reg[BITS (0, 3)] >> ror) & 0xFFFF);
  5908. if (Rm & 0x8000)
  5909. Rm |= 0xffff0000;
  5910. if (BITS (16, 19) == 0xf)
  5911. /* SXTH */
  5912. state->Reg[BITS (12, 15)] = Rm;
  5913. else
  5914. /* SXTAH */
  5915. state->Reg[BITS (12, 15)] = state->Reg[BITS (16, 19)] + Rm;
  5916. }
  5917. return 1;
  5918. case 0x6e:
  5919. {
  5920. ARMword Rm;
  5921. int ror = -1;
  5922. switch (BITS (4, 11))
  5923. {
  5924. case 0x07: ror = 0; break;
  5925. case 0x47: ror = 8; break;
  5926. case 0x87: ror = 16; break;
  5927. case 0xc7: ror = 24; break;
  5928. case 0x01:
  5929. case 0xf3:
  5930. printf ("Unhandled v6 insn: usat\n");
  5931. return 0;
  5932. default:
  5933. break;
  5934. }
  5935. if (ror == -1)
  5936. {
  5937. if (BITS (4, 6) == 0x7)
  5938. {
  5939. printf ("Unhandled v6 insn: usat\n");
  5940. return 0;
  5941. }
  5942. break;
  5943. }
  5944. Rm = ((state->Reg[BITS (0, 3)] >> ror) & 0xFF);
  5945. if (BITS (16, 19) == 0xf)
  5946. /* UXTB */
  5947. state->Reg[BITS (12, 15)] = Rm;
  5948. else
  5949. /* UXTAB */
  5950. state->Reg[BITS (12, 15)] = state->Reg[BITS (16, 19)] + Rm;
  5951. }
  5952. return 1;
  5953. case 0x6f:
  5954. {
  5955. ARMword Rm;
  5956. int ror = -1;
  5957. switch (BITS (4, 11))
  5958. {
  5959. case 0x07: ror = 0; break;
  5960. case 0x47: ror = 8; break;
  5961. case 0x87: ror = 16; break;
  5962. case 0xc7: ror = 24; break;
  5963. case 0xfb:
  5964. printf ("Unhandled v6 insn: revsh\n");
  5965. return 0;
  5966. default:
  5967. break;
  5968. }
  5969. if (ror == -1)
  5970. break;
  5971. Rm = ((state->Reg[BITS (0, 3)] >> ror) & 0xFFFF);
  5972. /* UXT */
  5973. /* state->Reg[BITS (12, 15)] = Rm; */
  5974. /* dyf add */
  5975. if (BITS (16, 19) == 0xf) {
  5976. state->Reg[BITS (12, 15)] = (Rm >> (8 * BITS(10, 11))) & 0x0000FFFF;
  5977. } else {
  5978. /* UXTAH */
  5979. /* state->Reg[BITS (12, 15)] = state->Reg [BITS (16, 19)] + Rm; */
  5980. // printf("rd is %x rn is %x rm is %x rotate is %x\n", state->Reg[BITS (12, 15)], state->Reg[BITS (16, 19)]
  5981. // , Rm, BITS(10, 11));
  5982. // printf("icounter is %lld\n", state->NumInstrs);
  5983. state->Reg[BITS (12, 15)] = (state->Reg[BITS (16, 19)] >> (8 * (BITS(10, 11)))) + Rm;
  5984. // printf("rd is %x\n", state->Reg[BITS (12, 15)]);
  5985. // exit(-1);
  5986. }
  5987. }
  5988. return 1;
  5989. #if 0
  5990. case 0x84: printf ("Unhandled v6 insn: srs\n"); break;
  5991. #endif
  5992. default:
  5993. break;
  5994. }
  5995. printf ("Unhandled v6 insn: UNKNOWN: %08x\n", instr);
  5996. return 0;
  5997. }