armemu.cpp 228 KB

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