simops.c 122 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019
  1. /* Simulation code for the CR16 processor.
  2. Copyright (C) 2008-2015 Free Software Foundation, Inc.
  3. Contributed by M Ranga Swami Reddy <MR.Swami.Reddy@nsc.com>
  4. This file is part of GDB, the GNU debugger.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "config.h"
  16. #include <signal.h>
  17. #include <errno.h>
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20. #ifdef HAVE_UNISTD_H
  21. #include <unistd.h>
  22. #endif
  23. #ifdef HAVE_STRING_H
  24. #include <string.h>
  25. #endif
  26. #ifdef HAVE_TIME_H
  27. #include <time.h>
  28. #endif
  29. #ifdef HAVE_SYS_TIME_H
  30. #include <sys/time.h>
  31. #endif
  32. #include "sim-main.h"
  33. #include "simops.h"
  34. #include "targ-vals.h"
  35. #ifdef TARGET_SYS_utime
  36. #include <utime.h>
  37. #endif
  38. #ifdef TARGET_SYS_wait
  39. #include <sys/wait.h>
  40. #endif
  41. enum op_types {
  42. OP_VOID,
  43. OP_CONSTANT3,
  44. OP_UCONSTANT3,
  45. OP_CONSTANT4,
  46. OP_CONSTANT4_1,
  47. OP_CONSTANT5,
  48. OP_CONSTANT6,
  49. OP_CONSTANT16,
  50. OP_UCONSTANT16,
  51. OP_CONSTANT20,
  52. OP_UCONSTANT20,
  53. OP_CONSTANT32,
  54. OP_UCONSTANT32,
  55. OP_MEMREF,
  56. OP_MEMREF2,
  57. OP_MEMREF3,
  58. OP_DISP5,
  59. OP_DISP17,
  60. OP_DISP25,
  61. OP_DISPE9,
  62. //OP_ABS20,
  63. OP_ABS20_OUTPUT,
  64. //OP_ABS24,
  65. OP_ABS24_OUTPUT,
  66. OP_R_BASE_DISPS16,
  67. OP_R_BASE_DISP20,
  68. OP_R_BASE_DISPS20,
  69. OP_R_BASE_DISPE20,
  70. OP_RP_BASE_DISPE0,
  71. OP_RP_BASE_DISP4,
  72. OP_RP_BASE_DISPE4,
  73. OP_RP_BASE_DISP14,
  74. OP_RP_BASE_DISP16,
  75. OP_RP_BASE_DISP20,
  76. OP_RP_BASE_DISPS20,
  77. OP_RP_BASE_DISPE20,
  78. OP_R_INDEX7_ABS20,
  79. OP_R_INDEX8_ABS20,
  80. OP_RP_INDEX_DISP0,
  81. OP_RP_INDEX_DISP14,
  82. OP_RP_INDEX_DISP20,
  83. OP_RP_INDEX_DISPS20,
  84. OP_REG,
  85. OP_REGP,
  86. OP_PROC_REG,
  87. OP_PROC_REGP,
  88. OP_COND,
  89. OP_RA
  90. };
  91. enum {
  92. PSR_MASK = (PSR_I_BIT
  93. | PSR_P_BIT
  94. | PSR_E_BIT
  95. | PSR_N_BIT
  96. | PSR_Z_BIT
  97. | PSR_F_BIT
  98. | PSR_U_BIT
  99. | PSR_L_BIT
  100. | PSR_T_BIT
  101. | PSR_C_BIT),
  102. /* The following bits in the PSR _can't_ be set by instructions such
  103. as mvtc. */
  104. PSR_HW_MASK = (PSR_MASK)
  105. };
  106. /* cond Code Condition True State
  107. * EQ Equal Z flag is 1
  108. * NE Not Equal Z flag is 0
  109. * CS Carry Set C flag is 1
  110. * CC Carry Clear C flag is 0
  111. * HI Higher L flag is 1
  112. * LS Lower or Same L flag is 0
  113. * GT Greater Than N flag is 1
  114. * LE Less Than or Equal To N flag is 0
  115. * FS Flag Set F flag is 1
  116. * FC Flag Clear F flag is 0
  117. * LO Lower Z and L flags are 0
  118. * HS Higher or Same Z or L flag is 1
  119. * LT Less Than Z and N flags are 0
  120. * GE Greater Than or Equal To Z or N flag is 1. */
  121. static int cond_stat(int cc)
  122. {
  123. switch (cc)
  124. {
  125. case 0: return PSR_Z; break;
  126. case 1: return !PSR_Z; break;
  127. case 2: return PSR_C; break;
  128. case 3: return !PSR_C; break;
  129. case 4: return PSR_L; break;
  130. case 5: return !PSR_L; break;
  131. case 6: return PSR_N; break;
  132. case 7: return !PSR_N; break;
  133. case 8: return PSR_F; break;
  134. case 9: return !PSR_F; break;
  135. case 10: return !PSR_Z && !PSR_L; break;
  136. case 11: return PSR_Z || PSR_L; break;
  137. case 12: return !PSR_Z && !PSR_N; break;
  138. case 13: return PSR_Z || PSR_N; break;
  139. case 14: return 1; break; /*ALWAYS. */
  140. default:
  141. // case NEVER: return false; break;
  142. //case NO_COND_CODE:
  143. //panic("Shouldn't have NO_COND_CODE in an actual instruction!");
  144. return 0; break;
  145. }
  146. return 0;
  147. }
  148. creg_t
  149. move_to_cr (int cr, creg_t mask, creg_t val, int psw_hw_p)
  150. {
  151. /* A MASK bit is set when the corresponding bit in the CR should
  152. be left alone. */
  153. /* This assumes that (VAL & MASK) == 0. */
  154. switch (cr)
  155. {
  156. case PSR_CR:
  157. if (psw_hw_p)
  158. val &= PSR_HW_MASK;
  159. #if 0
  160. else
  161. val &= PSR_MASK;
  162. (*cr16_callback->printf_filtered)
  163. (cr16_callback,
  164. "ERROR at PC 0x%x: ST can only be set when FX is set.\n", PC);
  165. State.exception = SIGILL;
  166. #endif
  167. /* keep an up-to-date psw around for tracing. */
  168. State.trace.psw = (State.trace.psw & mask) | val;
  169. break;
  170. default:
  171. break;
  172. }
  173. /* only issue an update if the register is being changed. */
  174. if ((State.cregs[cr] & ~mask) != val)
  175. SLOT_PEND_MASK (State.cregs[cr], mask, val);
  176. return val;
  177. }
  178. #ifdef DEBUG
  179. static void trace_input_func (const char *name,
  180. enum op_types in1,
  181. enum op_types in2,
  182. enum op_types in3);
  183. #define trace_input(name, in1, in2, in3) do { if (cr16_debug) trace_input_func (name, in1, in2, in3); } while (0)
  184. #ifndef SIZE_INSTRUCTION
  185. #define SIZE_INSTRUCTION 8
  186. #endif
  187. #ifndef SIZE_OPERANDS
  188. #define SIZE_OPERANDS 18
  189. #endif
  190. #ifndef SIZE_VALUES
  191. #define SIZE_VALUES 13
  192. #endif
  193. #ifndef SIZE_LOCATION
  194. #define SIZE_LOCATION 20
  195. #endif
  196. #ifndef SIZE_PC
  197. #define SIZE_PC 4
  198. #endif
  199. #ifndef SIZE_LINE_NUMBER
  200. #define SIZE_LINE_NUMBER 2
  201. #endif
  202. static void
  203. trace_input_func (const char *name, enum op_types in1, enum op_types in2, enum op_types in3)
  204. {
  205. char *comma;
  206. enum op_types in[3];
  207. int i;
  208. char buf[1024];
  209. char *p;
  210. long tmp;
  211. char *type;
  212. const char *filename;
  213. const char *functionname;
  214. unsigned int linenumber;
  215. bfd_vma byte_pc;
  216. if ((cr16_debug & DEBUG_TRACE) == 0)
  217. return;
  218. switch (State.ins_type)
  219. {
  220. default:
  221. case INS_UNKNOWN: type = " ?"; break;
  222. }
  223. if ((cr16_debug & DEBUG_LINE_NUMBER) == 0)
  224. (*cr16_callback->printf_filtered) (cr16_callback,
  225. "0x%.*x %s: %-*s ",
  226. SIZE_PC, (unsigned)PC,
  227. type,
  228. SIZE_INSTRUCTION, name);
  229. else
  230. {
  231. extern SIM_DESC trace_sd;
  232. buf[0] = '\0';
  233. byte_pc = PC;
  234. if (STATE_TEXT_SECTION (trace_sd)
  235. && byte_pc >= STATE_TEXT_START (trace_sd)
  236. && byte_pc < STATE_TEXT_END (trace_sd))
  237. {
  238. filename = (const char *)0;
  239. functionname = (const char *)0;
  240. linenumber = 0;
  241. if (bfd_find_nearest_line (STATE_PROG_BFD (trace_sd),
  242. STATE_TEXT_SECTION (trace_sd),
  243. (struct bfd_symbol **)0,
  244. byte_pc - STATE_TEXT_START (trace_sd),
  245. &filename, &functionname, &linenumber))
  246. {
  247. p = buf;
  248. if (linenumber)
  249. {
  250. sprintf (p, "#%-*d ", SIZE_LINE_NUMBER, linenumber);
  251. p += strlen (p);
  252. }
  253. else
  254. {
  255. sprintf (p, "%-*s ", SIZE_LINE_NUMBER+1, "---");
  256. p += SIZE_LINE_NUMBER+2;
  257. }
  258. if (functionname)
  259. {
  260. sprintf (p, "%s ", functionname);
  261. p += strlen (p);
  262. }
  263. else if (filename)
  264. {
  265. char *q = strrchr (filename, '/');
  266. sprintf (p, "%s ", (q) ? q+1 : filename);
  267. p += strlen (p);
  268. }
  269. if (*p == ' ')
  270. *p = '\0';
  271. }
  272. }
  273. (*cr16_callback->printf_filtered) (cr16_callback,
  274. "0x%.*x %s: %-*.*s %-*s ",
  275. SIZE_PC, (unsigned)PC,
  276. type,
  277. SIZE_LOCATION, SIZE_LOCATION, buf,
  278. SIZE_INSTRUCTION, name);
  279. }
  280. in[0] = in1;
  281. in[1] = in2;
  282. in[2] = in3;
  283. comma = "";
  284. p = buf;
  285. for (i = 0; i < 3; i++)
  286. {
  287. switch (in[i])
  288. {
  289. case OP_VOID:
  290. break;
  291. case OP_REG:
  292. case OP_REGP:
  293. sprintf (p, "%sr%d", comma, OP[i]);
  294. p += strlen (p);
  295. comma = ",";
  296. break;
  297. case OP_PROC_REG:
  298. sprintf (p, "%scr%d", comma, OP[i]);
  299. p += strlen (p);
  300. comma = ",";
  301. break;
  302. case OP_CONSTANT16:
  303. sprintf (p, "%s%d", comma, OP[i]);
  304. p += strlen (p);
  305. comma = ",";
  306. break;
  307. case OP_CONSTANT4:
  308. sprintf (p, "%s%d", comma, SEXT4(OP[i]));
  309. p += strlen (p);
  310. comma = ",";
  311. break;
  312. case OP_CONSTANT3:
  313. sprintf (p, "%s%d", comma, SEXT3(OP[i]));
  314. p += strlen (p);
  315. comma = ",";
  316. break;
  317. case OP_MEMREF:
  318. sprintf (p, "%s@r%d", comma, OP[i]);
  319. p += strlen (p);
  320. comma = ",";
  321. break;
  322. case OP_MEMREF2:
  323. sprintf (p, "%s@(%d,r%d)", comma, (int16)OP[i], OP[i+1]);
  324. p += strlen (p);
  325. comma = ",";
  326. break;
  327. case OP_MEMREF3:
  328. sprintf (p, "%s@%d", comma, OP[i]);
  329. p += strlen (p);
  330. comma = ",";
  331. break;
  332. }
  333. }
  334. if ((cr16_debug & DEBUG_VALUES) == 0)
  335. {
  336. *p++ = '\n';
  337. *p = '\0';
  338. (*cr16_callback->printf_filtered) (cr16_callback, "%s", buf);
  339. }
  340. else
  341. {
  342. *p = '\0';
  343. (*cr16_callback->printf_filtered) (cr16_callback, "%-*s", SIZE_OPERANDS, buf);
  344. p = buf;
  345. for (i = 0; i < 3; i++)
  346. {
  347. buf[0] = '\0';
  348. switch (in[i])
  349. {
  350. case OP_VOID:
  351. (*cr16_callback->printf_filtered) (cr16_callback, "%*s", SIZE_VALUES, "");
  352. break;
  353. case OP_REG:
  354. (*cr16_callback->printf_filtered) (cr16_callback, "%*s0x%.4x", SIZE_VALUES-6, "",
  355. (uint16) GPR (OP[i]));
  356. break;
  357. case OP_REGP:
  358. tmp = (long)((((uint32) GPR (OP[i])) << 16) | ((uint32) GPR (OP[i] + 1)));
  359. (*cr16_callback->printf_filtered) (cr16_callback, "%*s0x%.8lx", SIZE_VALUES-10, "", tmp);
  360. break;
  361. case OP_PROC_REG:
  362. (*cr16_callback->printf_filtered) (cr16_callback, "%*s0x%.4x", SIZE_VALUES-6, "",
  363. (uint16) CREG (OP[i]));
  364. break;
  365. case OP_CONSTANT16:
  366. (*cr16_callback->printf_filtered) (cr16_callback, "%*s0x%.4x", SIZE_VALUES-6, "",
  367. (uint16)OP[i]);
  368. break;
  369. case OP_CONSTANT4:
  370. (*cr16_callback->printf_filtered) (cr16_callback, "%*s0x%.4x", SIZE_VALUES-6, "",
  371. (uint16)SEXT4(OP[i]));
  372. break;
  373. case OP_CONSTANT3:
  374. (*cr16_callback->printf_filtered) (cr16_callback, "%*s0x%.4x", SIZE_VALUES-6, "",
  375. (uint16)SEXT3(OP[i]));
  376. break;
  377. case OP_MEMREF2:
  378. (*cr16_callback->printf_filtered) (cr16_callback, "%*s0x%.4x", SIZE_VALUES-6, "",
  379. (uint16)OP[i]);
  380. (*cr16_callback->printf_filtered) (cr16_callback, "%*s0x%.4x", SIZE_VALUES-6, "",
  381. (uint16)GPR (OP[i + 1]));
  382. i++;
  383. break;
  384. }
  385. }
  386. }
  387. (*cr16_callback->flush_stdout) (cr16_callback);
  388. }
  389. static void
  390. do_trace_output_flush (void)
  391. {
  392. (*cr16_callback->flush_stdout) (cr16_callback);
  393. }
  394. static void
  395. do_trace_output_finish (void)
  396. {
  397. (*cr16_callback->printf_filtered) (cr16_callback,
  398. " F0=%d F1=%d C=%d\n",
  399. (State.trace.psw & PSR_F_BIT) != 0,
  400. (State.trace.psw & PSR_F_BIT) != 0,
  401. (State.trace.psw & PSR_C_BIT) != 0);
  402. (*cr16_callback->flush_stdout) (cr16_callback);
  403. }
  404. #if 0
  405. static void
  406. trace_output_40 (uint64 val)
  407. {
  408. if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
  409. {
  410. (*cr16_callback->printf_filtered) (cr16_callback,
  411. " :: %*s0x%.2x%.8lx",
  412. SIZE_VALUES - 12,
  413. "",
  414. ((int)(val >> 32) & 0xff),
  415. ((unsigned long) val) & 0xffffffff);
  416. do_trace_output_finish ();
  417. }
  418. }
  419. #endif
  420. static void
  421. trace_output_32 (uint32 val)
  422. {
  423. if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
  424. {
  425. (*cr16_callback->printf_filtered) (cr16_callback,
  426. " :: %*s0x%.8x",
  427. SIZE_VALUES - 10,
  428. "",
  429. (int) val);
  430. do_trace_output_finish ();
  431. }
  432. }
  433. static void
  434. trace_output_16 (uint16 val)
  435. {
  436. if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
  437. {
  438. (*cr16_callback->printf_filtered) (cr16_callback,
  439. " :: %*s0x%.4x",
  440. SIZE_VALUES - 6,
  441. "",
  442. (int) val);
  443. do_trace_output_finish ();
  444. }
  445. }
  446. static void
  447. trace_output_void (void)
  448. {
  449. if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
  450. {
  451. (*cr16_callback->printf_filtered) (cr16_callback, "\n");
  452. do_trace_output_flush ();
  453. }
  454. }
  455. static void
  456. trace_output_flag (void)
  457. {
  458. if ((cr16_debug & (DEBUG_TRACE | DEBUG_VALUES)) == (DEBUG_TRACE | DEBUG_VALUES))
  459. {
  460. (*cr16_callback->printf_filtered) (cr16_callback,
  461. " :: %*s",
  462. SIZE_VALUES,
  463. "");
  464. do_trace_output_finish ();
  465. }
  466. }
  467. #else
  468. #define trace_input(NAME, IN1, IN2, IN3)
  469. #define trace_output(RESULT)
  470. #endif
  471. /* addub. */
  472. void
  473. OP_2C_8 (void)
  474. {
  475. uint8 tmp;
  476. uint8 a = OP[0] & 0xff;
  477. uint16 b = (GPR (OP[1])) & 0xff;
  478. trace_input ("addub", OP_CONSTANT4_1, OP_REG, OP_VOID);
  479. tmp = (a + b) & 0xff;
  480. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  481. trace_output_16 (tmp);
  482. }
  483. /* addub. */
  484. void
  485. OP_2CB_C (void)
  486. {
  487. uint16 tmp;
  488. uint8 a = ((OP[0]) & 0xff), b = (GPR (OP[1])) & 0xff;
  489. trace_input ("addub", OP_CONSTANT16, OP_REG, OP_VOID);
  490. tmp = (a + b) & 0xff;
  491. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  492. trace_output_16 (tmp);
  493. }
  494. /* addub. */
  495. void
  496. OP_2D_8 (void)
  497. {
  498. uint8 a = (GPR (OP[0])) & 0xff;
  499. uint8 b = (GPR (OP[1])) & 0xff;
  500. uint16 tmp = (a + b) & 0xff;
  501. trace_input ("addub", OP_REG, OP_REG, OP_VOID);
  502. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  503. trace_output_16 (tmp);
  504. }
  505. /* adduw. */
  506. void
  507. OP_2E_8 (void)
  508. {
  509. uint16 a = OP[0];
  510. uint16 b = GPR (OP[1]);
  511. uint16 tmp = (a + b);
  512. trace_input ("adduw", OP_CONSTANT4_1, OP_REG, OP_VOID);
  513. SET_GPR (OP[1], tmp);
  514. trace_output_16 (tmp);
  515. }
  516. /* adduw. */
  517. void
  518. OP_2EB_C (void)
  519. {
  520. uint16 a = OP[0];
  521. uint16 b = GPR (OP[1]);
  522. uint16 tmp = (a + b);
  523. trace_input ("adduw", OP_CONSTANT16, OP_REG, OP_VOID);
  524. SET_GPR (OP[1], tmp);
  525. trace_output_16 (tmp);
  526. }
  527. /* adduw. */
  528. void
  529. OP_2F_8 (void)
  530. {
  531. uint16 a = GPR (OP[0]);
  532. uint16 b = GPR (OP[1]);
  533. uint16 tmp = (a + b);
  534. trace_input ("adduw", OP_REG, OP_REG, OP_VOID);
  535. SET_GPR (OP[1], tmp);
  536. trace_output_16 (tmp);
  537. }
  538. /* addb. */
  539. void
  540. OP_30_8 (void)
  541. {
  542. uint8 a = OP[0];
  543. uint8 b = (GPR (OP[1]) & 0xff);
  544. uint16 tmp = (a + b) & 0xff;
  545. trace_input ("addb", OP_CONSTANT4_1, OP_REG, OP_VOID);
  546. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  547. SET_PSR_C (tmp > 0xFF);
  548. SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  549. trace_output_16 (tmp);
  550. }
  551. /* addb. */
  552. void
  553. OP_30B_C (void)
  554. {
  555. uint8 a = (OP[0]) & 0xff;
  556. uint8 b = (GPR (OP[1]) & 0xff);
  557. uint16 tmp = (a + b) & 0xff;
  558. trace_input ("addb", OP_CONSTANT16, OP_REG, OP_VOID);
  559. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  560. SET_PSR_C (tmp > 0xFF);
  561. SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  562. trace_output_16 (tmp);
  563. }
  564. /* addb. */
  565. void
  566. OP_31_8 (void)
  567. {
  568. uint8 a = (GPR (OP[0]) & 0xff);
  569. uint8 b = (GPR (OP[1]) & 0xff);
  570. uint16 tmp = (a + b) & 0xff;
  571. trace_input ("addb", OP_REG, OP_REG, OP_VOID);
  572. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  573. SET_PSR_C (tmp > 0xFF);
  574. SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  575. trace_output_16 (tmp);
  576. }
  577. /* addw. */
  578. void
  579. OP_32_8 (void)
  580. {
  581. int16 a = OP[0];
  582. uint16 tmp, b = GPR (OP[1]);
  583. tmp = (a + b);
  584. trace_input ("addw", OP_CONSTANT4_1, OP_REG, OP_VOID);
  585. SET_GPR (OP[1], tmp);
  586. SET_PSR_C (tmp > 0xFFFF);
  587. SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  588. trace_output_16 (tmp);
  589. }
  590. /* addw. */
  591. void
  592. OP_32B_C (void)
  593. {
  594. int16 a = OP[0];
  595. uint16 tmp, b = GPR (OP[1]);
  596. tmp = (a + b);
  597. trace_input ("addw", OP_CONSTANT16, OP_REG, OP_VOID);
  598. SET_GPR (OP[1], tmp);
  599. SET_PSR_C (tmp > 0xFFFF);
  600. SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  601. trace_output_16 (tmp);
  602. }
  603. /* addw. */
  604. void
  605. OP_33_8 (void)
  606. {
  607. uint16 tmp, a = (GPR (OP[0])), b = (GPR (OP[1]));
  608. trace_input ("addw", OP_REG, OP_REG, OP_VOID);
  609. tmp = (a + b);
  610. SET_GPR (OP[1], tmp);
  611. SET_PSR_C (tmp > 0xFFFF);
  612. SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  613. trace_output_16 (tmp);
  614. }
  615. /* addcb. */
  616. void
  617. OP_34_8 (void)
  618. {
  619. uint8 tmp, a = OP[0] & 0xff, b = (GPR (OP[1])) & 0xff;
  620. trace_input ("addcb", OP_CONSTANT4_1, OP_REG, OP_REG);
  621. tmp = (a + b + PSR_C) & 0xff;
  622. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  623. SET_PSR_C (tmp > 0xFF);
  624. SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  625. trace_output_16 (tmp);
  626. }
  627. /* addcb. */
  628. void
  629. OP_34B_C (void)
  630. {
  631. int8 a = OP[0] & 0xff;
  632. uint8 b = (GPR (OP[1])) & 0xff;
  633. uint8 tmp = (a + b + PSR_C) & 0xff;
  634. trace_input ("addcb", OP_CONSTANT16, OP_REG, OP_VOID);
  635. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  636. SET_PSR_C (tmp > 0xFF);
  637. SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  638. trace_output_16 (tmp);
  639. }
  640. /* addcb. */
  641. void
  642. OP_35_8 (void)
  643. {
  644. uint8 a = (GPR (OP[0])) & 0xff;
  645. uint8 b = (GPR (OP[1])) & 0xff;
  646. uint8 tmp = (a + b + PSR_C) & 0xff;
  647. trace_input ("addcb", OP_REG, OP_REG, OP_VOID);
  648. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  649. SET_PSR_C (tmp > 0xFF);
  650. SET_PSR_F (((a & 0x80) == (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  651. trace_output_16 (tmp);
  652. }
  653. /* addcw. */
  654. void
  655. OP_36_8 (void)
  656. {
  657. uint16 a = OP[0];
  658. uint16 b = GPR (OP[1]);
  659. uint16 tmp = (a + b + PSR_C);
  660. trace_input ("addcw", OP_CONSTANT4_1, OP_REG, OP_VOID);
  661. SET_GPR (OP[1], tmp);
  662. SET_PSR_C (tmp > 0xFFFF);
  663. SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  664. trace_output_16 (tmp);
  665. }
  666. /* addcw. */
  667. void
  668. OP_36B_C (void)
  669. {
  670. int16 a = OP[0];
  671. uint16 b = GPR (OP[1]);
  672. uint16 tmp = (a + b + PSR_C);
  673. trace_input ("addcw", OP_CONSTANT16, OP_REG, OP_VOID);
  674. SET_GPR (OP[1], tmp);
  675. SET_PSR_C (tmp > 0xFFFF);
  676. SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  677. trace_output_16 (tmp);
  678. }
  679. /* addcw. */
  680. void
  681. OP_37_8 (void)
  682. {
  683. uint16 a = GPR (OP[1]);
  684. uint16 b = GPR (OP[1]);
  685. uint16 tmp = (a + b + PSR_C);
  686. trace_input ("addcw", OP_REG, OP_REG, OP_VOID);
  687. SET_GPR (OP[1], tmp);
  688. SET_PSR_C (tmp > 0xFFFF);
  689. SET_PSR_F (((a & 0x8000) == (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  690. trace_output_16 (tmp);
  691. }
  692. /* addd. */
  693. void
  694. OP_60_8 (void)
  695. {
  696. int16 a = (OP[0]);
  697. uint32 b = GPR32 (OP[1]);
  698. uint32 tmp = (a + b);
  699. trace_input ("addd", OP_CONSTANT4_1, OP_REGP, OP_VOID);
  700. SET_GPR32 (OP[1], tmp);
  701. SET_PSR_C (tmp > 0xFFFFFFFF);
  702. SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
  703. trace_output_32 (tmp);
  704. }
  705. /* addd. */
  706. void
  707. OP_60B_C (void)
  708. {
  709. int32 a = (SEXT16(OP[0]));
  710. uint32 b = GPR32 (OP[1]);
  711. uint32 tmp = (a + b);
  712. trace_input ("addd", OP_CONSTANT16, OP_REGP, OP_VOID);
  713. SET_GPR32 (OP[1], tmp);
  714. SET_PSR_C (tmp > 0xFFFFFFFF);
  715. SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
  716. trace_output_32 (tmp);
  717. }
  718. /* addd. */
  719. void
  720. OP_61_8 (void)
  721. {
  722. uint32 a = GPR32 (OP[0]);
  723. uint32 b = GPR32 (OP[1]);
  724. uint32 tmp = (a + b);
  725. trace_input ("addd", OP_REGP, OP_REGP, OP_VOID);
  726. SET_GPR32 (OP[1], tmp);
  727. trace_output_32 (tmp);
  728. SET_PSR_C (tmp > 0xFFFFFFFF);
  729. SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
  730. }
  731. /* addd. */
  732. void
  733. OP_4_8 (void)
  734. {
  735. uint32 a = OP[0];
  736. uint32 b = GPR32 (OP[1]);
  737. uint32 tmp;
  738. trace_input ("addd", OP_CONSTANT20, OP_REGP, OP_VOID);
  739. tmp = (a + b);
  740. SET_GPR32 (OP[1], tmp);
  741. SET_PSR_C (tmp > 0xFFFFFFFF);
  742. SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
  743. trace_output_32 (tmp);
  744. }
  745. /* addd. */
  746. void
  747. OP_2_C (void)
  748. {
  749. int32 a = OP[0];
  750. uint32 b = GPR32 (OP[1]);
  751. uint32 tmp;
  752. trace_input ("addd", OP_CONSTANT32, OP_REGP, OP_VOID);
  753. tmp = (a + b);
  754. SET_GPR32 (OP[1], tmp);
  755. SET_PSR_C (tmp > 0xFFFFFFFF);
  756. SET_PSR_F (((a & 0x80000000) == (b & 0x80000000)) && ((b & 0x80000000) != (tmp & 0x80000000)));
  757. trace_output_32 (tmp);
  758. }
  759. /* andb. */
  760. void
  761. OP_20_8 (void)
  762. {
  763. uint8 tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
  764. trace_input ("andb", OP_CONSTANT4, OP_REG, OP_VOID);
  765. tmp = a & b;
  766. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  767. trace_output_16 (tmp);
  768. }
  769. /* andb. */
  770. void
  771. OP_20B_C (void)
  772. {
  773. uint8 tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
  774. trace_input ("andb", OP_CONSTANT16, OP_REG, OP_VOID);
  775. tmp = a & b;
  776. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  777. trace_output_16 (tmp);
  778. }
  779. /* andb. */
  780. void
  781. OP_21_8 (void)
  782. {
  783. uint8 tmp, a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
  784. trace_input ("andb", OP_REG, OP_REG, OP_VOID);
  785. tmp = a & b;
  786. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  787. trace_output_16 (tmp);
  788. }
  789. /* andw. */
  790. void
  791. OP_22_8 (void)
  792. {
  793. uint16 tmp, a = OP[0], b = GPR (OP[1]);
  794. trace_input ("andw", OP_CONSTANT4, OP_REG, OP_VOID);
  795. tmp = a & b;
  796. SET_GPR (OP[1], tmp);
  797. trace_output_16 (tmp);
  798. }
  799. /* andw. */
  800. void
  801. OP_22B_C (void)
  802. {
  803. uint16 tmp, a = OP[0], b = GPR (OP[1]);
  804. trace_input ("andw", OP_CONSTANT16, OP_REG, OP_VOID);
  805. tmp = a & b;
  806. SET_GPR (OP[1], tmp);
  807. trace_output_16 (tmp);
  808. }
  809. /* andw. */
  810. void
  811. OP_23_8 (void)
  812. {
  813. uint16 tmp, a = GPR (OP[0]), b = GPR (OP[1]);
  814. trace_input ("andw", OP_REG, OP_REG, OP_VOID);
  815. tmp = a & b;
  816. SET_GPR (OP[1], tmp);
  817. trace_output_16 (tmp);
  818. }
  819. /* andd. */
  820. void
  821. OP_4_C (void)
  822. {
  823. uint32 tmp, a = OP[0], b = GPR32 (OP[1]);
  824. trace_input ("andd", OP_CONSTANT32, OP_REGP, OP_VOID);
  825. tmp = a & b;
  826. SET_GPR32 (OP[1], tmp);
  827. trace_output_32 (tmp);
  828. }
  829. /* andd. */
  830. void
  831. OP_14B_14 (void)
  832. {
  833. uint32 tmp, a = (GPR32 (OP[0])), b = (GPR32 (OP[1]));
  834. trace_input ("andd", OP_REGP, OP_REGP, OP_VOID);
  835. tmp = a & b;
  836. SET_GPR32 (OP[1], tmp);
  837. trace_output_32 (tmp);
  838. }
  839. /* ord. */
  840. void
  841. OP_5_C (void)
  842. {
  843. uint32 tmp, a = (OP[0]), b = GPR32 (OP[1]);
  844. trace_input ("ord", OP_CONSTANT32, OP_REG, OP_VOID);
  845. tmp = a | b;
  846. SET_GPR32 (OP[1], tmp);
  847. trace_output_32 (tmp);
  848. }
  849. /* ord. */
  850. void
  851. OP_149_14 (void)
  852. {
  853. uint32 tmp, a = GPR32 (OP[0]), b = GPR32 (OP[1]);
  854. trace_input ("ord", OP_REGP, OP_REGP, OP_VOID);
  855. tmp = a | b;
  856. SET_GPR32 (OP[1], tmp);
  857. trace_output_32 (tmp);
  858. }
  859. /* xord. */
  860. void
  861. OP_6_C (void)
  862. {
  863. uint32 tmp, a = (OP[0]), b = GPR32 (OP[1]);
  864. trace_input ("xord", OP_CONSTANT32, OP_REG, OP_VOID);
  865. tmp = a ^ b;
  866. SET_GPR32 (OP[1], tmp);
  867. trace_output_32 (tmp);
  868. }
  869. /* xord. */
  870. void
  871. OP_14A_14 (void)
  872. {
  873. uint32 tmp, a = GPR32 (OP[0]), b = GPR32 (OP[1]);
  874. trace_input ("xord", OP_REGP, OP_REGP, OP_VOID);
  875. tmp = a ^ b;
  876. SET_GPR32 (OP[1], tmp);
  877. trace_output_32 (tmp);
  878. }
  879. /* b. */
  880. void
  881. OP_1_4 (void)
  882. {
  883. uint32 tmp = 0, cc = cond_stat (OP[0]);
  884. trace_input ("b", OP_CONSTANT4, OP_DISPE9, OP_VOID);
  885. if (cc)
  886. {
  887. if (sign_flag)
  888. tmp = (PC - (OP[1]));
  889. else
  890. tmp = (PC + (OP[1]));
  891. /* If the resulting PC value is less than 0x00_0000 or greater
  892. than 0xFF_FFFF, this instruction causes an IAD trap.*/
  893. if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
  894. {
  895. State.exception = SIG_CR16_BUS;
  896. State.pc_changed = 1; /* Don't increment the PC. */
  897. trace_output_void ();
  898. return;
  899. }
  900. else
  901. JMP (tmp);
  902. }
  903. sign_flag = 0; /* Reset sign_flag. */
  904. trace_output_32 (tmp);
  905. }
  906. /* b. */
  907. void
  908. OP_18_8 (void)
  909. {
  910. uint32 tmp = 0, cc = cond_stat (OP[0]);
  911. trace_input ("b", OP_CONSTANT4, OP_DISP17, OP_VOID);
  912. if (cc)
  913. {
  914. if (sign_flag)
  915. tmp = (PC - OP[1]);
  916. else
  917. tmp = (PC + OP[1]);
  918. /* If the resulting PC value is less than 0x00_0000 or greater
  919. than 0xFF_FFFF, this instruction causes an IAD trap.*/
  920. if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
  921. {
  922. State.exception = SIG_CR16_BUS;
  923. State.pc_changed = 1; /* Don't increment the PC. */
  924. trace_output_void ();
  925. return;
  926. }
  927. else
  928. JMP (tmp);
  929. }
  930. sign_flag = 0; /* Reset sign_flag. */
  931. trace_output_32 (tmp);
  932. }
  933. /* b. */
  934. void
  935. OP_10_10 (void)
  936. {
  937. uint32 tmp = 0, cc = cond_stat (OP[0]);
  938. trace_input ("b", OP_CONSTANT4, OP_DISP25, OP_VOID);
  939. if (cc)
  940. {
  941. if (sign_flag)
  942. tmp = (PC - (OP[1]));
  943. else
  944. tmp = (PC + (OP[1]));
  945. /* If the resulting PC value is less than 0x00_0000 or greater
  946. than 0xFF_FFFF, this instruction causes an IAD trap.*/
  947. if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
  948. {
  949. State.exception = SIG_CR16_BUS;
  950. State.pc_changed = 1; /* Don't increment the PC. */
  951. trace_output_void ();
  952. return;
  953. }
  954. else
  955. JMP (tmp);
  956. }
  957. sign_flag = 0; /* Reset sign_flag. */
  958. trace_output_32 (tmp);
  959. }
  960. /* bal. */
  961. void
  962. OP_C0_8 (void)
  963. {
  964. uint32 tmp;
  965. trace_input ("bal", OP_REG, OP_DISP17, OP_VOID);
  966. tmp = ((PC + 4) >> 1); /* Store PC in RA register. */
  967. SET_GPR32 (14, tmp);
  968. if (sign_flag)
  969. tmp = (PC - (OP[1]));
  970. else
  971. tmp = (PC + (OP[1]));
  972. /* If the resulting PC value is less than 0x00_0000 or greater
  973. than 0xFF_FFFF, this instruction causes an IAD trap. */
  974. if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
  975. {
  976. State.exception = SIG_CR16_BUS;
  977. State.pc_changed = 1; /* Don't increment the PC. */
  978. trace_output_void ();
  979. return;
  980. }
  981. else
  982. JMP (tmp);
  983. sign_flag = 0; /* Reset sign_flag. */
  984. trace_output_32 (tmp);
  985. }
  986. /* bal. */
  987. void
  988. OP_102_14 (void)
  989. {
  990. uint32 tmp;
  991. trace_input ("bal", OP_REGP, OP_DISP25, OP_VOID);
  992. tmp = (((PC) + 4) >> 1); /* Store PC in reg pair. */
  993. SET_GPR32 (OP[0], tmp);
  994. if (sign_flag)
  995. tmp = ((PC) - (OP[1]));
  996. else
  997. tmp = ((PC) + (OP[1]));
  998. /* If the resulting PC value is less than 0x00_0000 or greater
  999. than 0xFF_FFFF, this instruction causes an IAD trap.*/
  1000. if ((tmp < 0x000000) || (tmp > 0xFFFFFF))
  1001. {
  1002. State.exception = SIG_CR16_BUS;
  1003. State.pc_changed = 1; /* Don't increment the PC. */
  1004. trace_output_void ();
  1005. return;
  1006. }
  1007. else
  1008. JMP (tmp);
  1009. sign_flag = 0; /* Reset sign_flag. */
  1010. trace_output_32 (tmp);
  1011. }
  1012. /* jal. */
  1013. void
  1014. OP_148_14 (void)
  1015. {
  1016. uint32 tmp;
  1017. trace_input ("jal", OP_REGP, OP_REGP, OP_VOID);
  1018. SET_GPR32 (OP[0], (((PC) + 4) >> 1)); /* Store next PC in RA */
  1019. tmp = GPR32 (OP[1]);
  1020. tmp = SEXT24(tmp << 1);
  1021. /* If the resulting PC value is less than 0x00_0000 or greater
  1022. than 0xFF_FFFF, this instruction causes an IAD trap.*/
  1023. if ((tmp < 0x0) || (tmp > 0xFFFFFF))
  1024. {
  1025. State.exception = SIG_CR16_BUS;
  1026. State.pc_changed = 1; /* Don't increment the PC. */
  1027. trace_output_void ();
  1028. return;
  1029. }
  1030. else
  1031. JMP (tmp);
  1032. trace_output_32 (tmp);
  1033. }
  1034. /* jal. */
  1035. void
  1036. OP_D_C (void)
  1037. {
  1038. uint32 tmp;
  1039. trace_input ("jal", OP_REGP, OP_VOID, OP_VOID);
  1040. SET_GPR32 (14, (((PC) + 2) >> 1)); /* Store next PC in RA */
  1041. tmp = GPR32 (OP[0]);
  1042. tmp = SEXT24(tmp << 1);
  1043. /* If the resulting PC value is less than 0x00_0000 or greater
  1044. than 0xFF_FFFF, this instruction causes an IAD trap.*/
  1045. if ((tmp < 0x0) || (tmp > 0xFFFFFF))
  1046. {
  1047. State.exception = SIG_CR16_BUS;
  1048. State.pc_changed = 1; /* Don't increment the PC. */
  1049. trace_output_void ();
  1050. return;
  1051. }
  1052. else
  1053. JMP (tmp);
  1054. trace_output_32 (tmp);
  1055. }
  1056. /* beq0b. */
  1057. void
  1058. OP_C_8 (void)
  1059. {
  1060. uint32 addr;
  1061. uint8 a = (GPR (OP[0]) & 0xFF);
  1062. trace_input ("beq0b", OP_REG, OP_DISP5, OP_VOID);
  1063. addr = OP[1];
  1064. if (a == 0)
  1065. {
  1066. if (sign_flag)
  1067. addr = (PC - OP[1]);
  1068. else
  1069. addr = (PC + OP[1]);
  1070. JMP (addr);
  1071. }
  1072. sign_flag = 0; /* Reset sign_flag. */
  1073. trace_output_void ();
  1074. }
  1075. /* bne0b. */
  1076. void
  1077. OP_D_8 (void)
  1078. {
  1079. uint32 addr;
  1080. uint8 a = (GPR (OP[0]) & 0xFF);
  1081. trace_input ("bne0b", OP_REG, OP_DISP5, OP_VOID);
  1082. addr = OP[1];
  1083. if (a != 0)
  1084. {
  1085. if (sign_flag)
  1086. addr = (PC - OP[1]);
  1087. else
  1088. addr = (PC + OP[1]);
  1089. JMP (addr);
  1090. }
  1091. sign_flag = 0; /* Reset sign_flag. */
  1092. trace_output_void ();
  1093. }
  1094. /* beq0w. */
  1095. void
  1096. OP_E_8 (void)
  1097. {
  1098. uint32 addr;
  1099. uint16 a = GPR (OP[0]);
  1100. trace_input ("beq0w", OP_REG, OP_DISP5, OP_VOID);
  1101. addr = OP[1];
  1102. if (a == 0)
  1103. {
  1104. if (sign_flag)
  1105. addr = (PC - OP[1]);
  1106. else
  1107. addr = (PC + OP[1]);
  1108. JMP (addr);
  1109. }
  1110. sign_flag = 0; /* Reset sign_flag. */
  1111. trace_output_void ();
  1112. }
  1113. /* bne0w. */
  1114. void
  1115. OP_F_8 (void)
  1116. {
  1117. uint32 addr;
  1118. uint16 a = GPR (OP[0]);
  1119. trace_input ("bne0w", OP_REG, OP_DISP5, OP_VOID);
  1120. addr = OP[1];
  1121. if (a != 0)
  1122. {
  1123. if (sign_flag)
  1124. addr = (PC - OP[1]);
  1125. else
  1126. addr = (PC + OP[1]);
  1127. JMP (addr);
  1128. }
  1129. sign_flag = 0; /* Reset sign_flag. */
  1130. trace_output_void ();
  1131. }
  1132. /* jeq. */
  1133. void
  1134. OP_A0_C (void)
  1135. {
  1136. uint32 tmp = 0;
  1137. trace_input ("jeq", OP_REGP, OP_VOID, OP_VOID);
  1138. if ((PSR_Z) == 1)
  1139. {
  1140. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits. */
  1141. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit. */
  1142. }
  1143. trace_output_32 (tmp);
  1144. }
  1145. /* jne. */
  1146. void
  1147. OP_A1_C (void)
  1148. {
  1149. uint32 tmp = 0;
  1150. trace_input ("jne", OP_REGP, OP_VOID, OP_VOID);
  1151. if ((PSR_Z) == 0)
  1152. {
  1153. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits. */
  1154. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit. */
  1155. }
  1156. trace_output_32 (tmp);
  1157. }
  1158. /* jcs. */
  1159. void
  1160. OP_A2_C (void)
  1161. {
  1162. uint32 tmp = 0;
  1163. trace_input ("jcs", OP_REGP, OP_VOID, OP_VOID);
  1164. if ((PSR_C) == 1)
  1165. {
  1166. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1167. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1168. }
  1169. trace_output_32 (tmp);
  1170. }
  1171. /* jcc. */
  1172. void
  1173. OP_A3_C (void)
  1174. {
  1175. uint32 tmp = 0;
  1176. trace_input ("jcc", OP_REGP, OP_VOID, OP_VOID);
  1177. if ((PSR_C) == 0)
  1178. {
  1179. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1180. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1181. }
  1182. trace_output_32 (tmp);
  1183. }
  1184. /* jhi. */
  1185. void
  1186. OP_A4_C (void)
  1187. {
  1188. uint32 tmp = 0;
  1189. trace_input ("jhi", OP_REGP, OP_VOID, OP_VOID);
  1190. if ((PSR_L) == 1)
  1191. {
  1192. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1193. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1194. }
  1195. trace_output_32 (tmp);
  1196. }
  1197. /* jls. */
  1198. void
  1199. OP_A5_C (void)
  1200. {
  1201. uint32 tmp = 0;
  1202. trace_input ("jls", OP_REGP, OP_VOID, OP_VOID);
  1203. if ((PSR_L) == 0)
  1204. {
  1205. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1206. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1207. }
  1208. trace_output_32 (tmp);
  1209. }
  1210. /* jgt. */
  1211. void
  1212. OP_A6_C (void)
  1213. {
  1214. uint32 tmp = 0;
  1215. trace_input ("jgt", OP_REGP, OP_VOID, OP_VOID);
  1216. if ((PSR_N) == 1)
  1217. {
  1218. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1219. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1220. }
  1221. trace_output_32 (tmp);
  1222. }
  1223. /* jle. */
  1224. void
  1225. OP_A7_C (void)
  1226. {
  1227. uint32 tmp = 0;
  1228. trace_input ("jle", OP_REGP, OP_VOID, OP_VOID);
  1229. if ((PSR_N) == 0)
  1230. {
  1231. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1232. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1233. }
  1234. trace_output_32 (tmp);
  1235. }
  1236. /* jfs. */
  1237. void
  1238. OP_A8_C (void)
  1239. {
  1240. uint32 tmp = 0;
  1241. trace_input ("jfs", OP_REGP, OP_VOID, OP_VOID);
  1242. if ((PSR_F) == 1)
  1243. {
  1244. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1245. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1246. }
  1247. trace_output_32 (tmp);
  1248. }
  1249. /* jfc. */
  1250. void
  1251. OP_A9_C (void)
  1252. {
  1253. uint32 tmp = 0;
  1254. trace_input ("jfc", OP_REGP, OP_VOID, OP_VOID);
  1255. if ((PSR_F) == 0)
  1256. {
  1257. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1258. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1259. }
  1260. trace_output_32 (tmp);
  1261. }
  1262. /* jlo. */
  1263. void
  1264. OP_AA_C (void)
  1265. {
  1266. uint32 tmp = 0;
  1267. trace_input ("jlo", OP_REGP, OP_VOID, OP_VOID);
  1268. if (((PSR_Z) == 0) & ((PSR_L) == 0))
  1269. {
  1270. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1271. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1272. }
  1273. trace_output_32 (tmp);
  1274. }
  1275. /* jhs. */
  1276. void
  1277. OP_AB_C (void)
  1278. {
  1279. uint32 tmp = 0;
  1280. trace_input ("jhs", OP_REGP, OP_VOID, OP_VOID);
  1281. if (((PSR_Z) == 1) | ((PSR_L) == 1))
  1282. {
  1283. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1284. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1285. }
  1286. trace_output_32 (tmp);
  1287. }
  1288. /* jlt. */
  1289. void
  1290. OP_AC_C (void)
  1291. {
  1292. uint32 tmp = 0;
  1293. trace_input ("jlt", OP_REGP, OP_VOID, OP_VOID);
  1294. if (((PSR_Z) == 0) & ((PSR_N) == 0))
  1295. {
  1296. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1297. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1298. }
  1299. trace_output_32 (tmp);
  1300. }
  1301. /* jge. */
  1302. void
  1303. OP_AD_C (void)
  1304. {
  1305. uint32 tmp = 0;
  1306. trace_input ("jge", OP_REGP, OP_VOID, OP_VOID);
  1307. if (((PSR_Z) == 1) | ((PSR_N) == 1))
  1308. {
  1309. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1310. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1311. }
  1312. trace_output_32 (tmp);
  1313. }
  1314. /* jump. */
  1315. void
  1316. OP_AE_C (void)
  1317. {
  1318. uint32 tmp;
  1319. trace_input ("jump", OP_REGP, OP_VOID, OP_VOID);
  1320. tmp = GPR32 (OP[0]) /*& 0x3fffff*/; /* Use only 0 - 22 bits */
  1321. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1322. trace_output_32 (tmp);
  1323. }
  1324. /* jusr. */
  1325. void
  1326. OP_AF_C (void)
  1327. {
  1328. uint32 tmp;
  1329. trace_input ("jusr", OP_REGP, OP_VOID, OP_VOID);
  1330. tmp = (GPR32 (OP[0])) & 0x3fffff; /* Use only 0 - 22 bits */
  1331. JMP (tmp << 1); /* Set PC's 1 - 23 bits and clear 0th bit*/
  1332. SET_PSR_U(1);
  1333. trace_output_32 (tmp);
  1334. }
  1335. /* seq. */
  1336. void
  1337. OP_80_C (void)
  1338. {
  1339. trace_input ("seq", OP_REG, OP_VOID, OP_VOID);
  1340. if ((PSR_Z) == 1)
  1341. SET_GPR (OP[0], 1);
  1342. else
  1343. SET_GPR (OP[0], 0);
  1344. trace_output_void ();
  1345. }
  1346. /* sne. */
  1347. void
  1348. OP_81_C (void)
  1349. {
  1350. trace_input ("sne", OP_REG, OP_VOID, OP_VOID);
  1351. if ((PSR_Z) == 0)
  1352. SET_GPR (OP[0], 1);
  1353. else
  1354. SET_GPR (OP[0], 0);
  1355. trace_output_void ();
  1356. }
  1357. /* scs. */
  1358. void
  1359. OP_82_C (void)
  1360. {
  1361. trace_input ("scs", OP_REG, OP_VOID, OP_VOID);
  1362. if ((PSR_C) == 1)
  1363. SET_GPR (OP[0], 1);
  1364. else
  1365. SET_GPR (OP[0], 0);
  1366. trace_output_void ();
  1367. }
  1368. /* scc. */
  1369. void
  1370. OP_83_C (void)
  1371. {
  1372. trace_input ("scc", OP_REG, OP_VOID, OP_VOID);
  1373. if ((PSR_C) == 0)
  1374. SET_GPR (OP[0], 1);
  1375. else
  1376. SET_GPR (OP[0], 0);
  1377. trace_output_void ();
  1378. }
  1379. /* shi. */
  1380. void
  1381. OP_84_C (void)
  1382. {
  1383. trace_input ("shi", OP_REG, OP_VOID, OP_VOID);
  1384. if ((PSR_L) == 1)
  1385. SET_GPR (OP[0], 1);
  1386. else
  1387. SET_GPR (OP[0], 0);
  1388. trace_output_void ();
  1389. }
  1390. /* sls. */
  1391. void
  1392. OP_85_C (void)
  1393. {
  1394. trace_input ("sls", OP_REG, OP_VOID, OP_VOID);
  1395. if ((PSR_L) == 0)
  1396. SET_GPR (OP[0], 1);
  1397. else
  1398. SET_GPR (OP[0], 0);
  1399. trace_output_void ();
  1400. }
  1401. /* sgt. */
  1402. void
  1403. OP_86_C (void)
  1404. {
  1405. trace_input ("sgt", OP_REG, OP_VOID, OP_VOID);
  1406. if ((PSR_N) == 1)
  1407. SET_GPR (OP[0], 1);
  1408. else
  1409. SET_GPR (OP[0], 0);
  1410. trace_output_void ();
  1411. }
  1412. /* sle. */
  1413. void
  1414. OP_87_C (void)
  1415. {
  1416. trace_input ("sle", OP_REG, OP_VOID, OP_VOID);
  1417. if ((PSR_N) == 0)
  1418. SET_GPR (OP[0], 1);
  1419. else
  1420. SET_GPR (OP[0], 0);
  1421. trace_output_void ();
  1422. }
  1423. /* sfs. */
  1424. void
  1425. OP_88_C (void)
  1426. {
  1427. trace_input ("sfs", OP_REG, OP_VOID, OP_VOID);
  1428. if ((PSR_F) == 1)
  1429. SET_GPR (OP[0], 1);
  1430. else
  1431. SET_GPR (OP[0], 0);
  1432. trace_output_void ();
  1433. }
  1434. /* sfc. */
  1435. void
  1436. OP_89_C (void)
  1437. {
  1438. trace_input ("sfc", OP_REG, OP_VOID, OP_VOID);
  1439. if ((PSR_F) == 0)
  1440. SET_GPR (OP[0], 1);
  1441. else
  1442. SET_GPR (OP[0], 0);
  1443. trace_output_void ();
  1444. }
  1445. /* slo. */
  1446. void
  1447. OP_8A_C (void)
  1448. {
  1449. trace_input ("slo", OP_REG, OP_VOID, OP_VOID);
  1450. if (((PSR_Z) == 0) & ((PSR_L) == 0))
  1451. SET_GPR (OP[0], 1);
  1452. else
  1453. SET_GPR (OP[0], 0);
  1454. trace_output_void ();
  1455. }
  1456. /* shs. */
  1457. void
  1458. OP_8B_C (void)
  1459. {
  1460. trace_input ("shs", OP_REG, OP_VOID, OP_VOID);
  1461. if ( ((PSR_Z) == 1) | ((PSR_L) == 1))
  1462. SET_GPR (OP[0], 1);
  1463. else
  1464. SET_GPR (OP[0], 0);
  1465. trace_output_void ();
  1466. }
  1467. /* slt. */
  1468. void
  1469. OP_8C_C (void)
  1470. {
  1471. trace_input ("slt", OP_REG, OP_VOID, OP_VOID);
  1472. if (((PSR_Z) == 0) & ((PSR_N) == 0))
  1473. SET_GPR (OP[0], 1);
  1474. else
  1475. SET_GPR (OP[0], 0);
  1476. trace_output_void ();
  1477. }
  1478. /* sge. */
  1479. void
  1480. OP_8D_C (void)
  1481. {
  1482. trace_input ("sge", OP_REG, OP_VOID, OP_VOID);
  1483. if (((PSR_Z) == 1) | ((PSR_N) == 1))
  1484. SET_GPR (OP[0], 1);
  1485. else
  1486. SET_GPR (OP[0], 0);
  1487. trace_output_void ();
  1488. }
  1489. /* cbitb. */
  1490. void
  1491. OP_D7_9 (void)
  1492. {
  1493. uint8 a = OP[0] & 0xff;
  1494. uint32 addr = OP[1], tmp;
  1495. trace_input ("cbitb", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
  1496. tmp = RB (addr);
  1497. SET_PSR_F (tmp & (1 << a));
  1498. tmp = tmp & ~(1 << a);
  1499. SB (addr, tmp);
  1500. trace_output_32 (tmp);
  1501. }
  1502. /* cbitb. */
  1503. void
  1504. OP_107_14 (void)
  1505. {
  1506. uint8 a = OP[0] & 0xff;
  1507. uint32 addr = OP[1], tmp;
  1508. trace_input ("cbitb", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
  1509. tmp = RB (addr);
  1510. SET_PSR_F (tmp & (1 << a));
  1511. tmp = tmp & ~(1 << a);
  1512. SB (addr, tmp);
  1513. trace_output_32 (tmp);
  1514. }
  1515. /* cbitb. */
  1516. void
  1517. OP_68_8 (void)
  1518. {
  1519. uint8 a = (OP[0]) & 0xff;
  1520. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  1521. trace_input ("cbitb", OP_CONSTANT4, OP_R_INDEX7_ABS20, OP_VOID);
  1522. tmp = RB (addr);
  1523. SET_PSR_F (tmp & (1 << a));
  1524. tmp = tmp & ~(1 << a);
  1525. SB (addr, tmp);
  1526. trace_output_32 (addr);
  1527. }
  1528. /* cbitb. */
  1529. void
  1530. OP_1AA_A (void)
  1531. {
  1532. uint8 a = (OP[0]) & 0xff;
  1533. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1534. trace_input ("cbitb", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
  1535. tmp = RB (addr);
  1536. SET_PSR_F (tmp & (1 << a));
  1537. tmp = tmp & ~(1 << a);
  1538. SB (addr, tmp);
  1539. trace_output_32 (addr);
  1540. }
  1541. /* cbitb. */
  1542. void
  1543. OP_104_14 (void)
  1544. {
  1545. uint8 a = (OP[0]) & 0xff;
  1546. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  1547. trace_input ("cbitb", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
  1548. tmp = RB (addr);
  1549. SET_PSR_F (tmp & (1 << a));
  1550. tmp = tmp & ~(1 << a);
  1551. SB (addr, tmp);
  1552. trace_output_32 (addr);
  1553. }
  1554. /* cbitb. */
  1555. void
  1556. OP_D4_9 (void)
  1557. {
  1558. uint8 a = (OP[0]) & 0xff;
  1559. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1560. trace_input ("cbitb", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
  1561. tmp = RB (addr);
  1562. SET_PSR_F (tmp & (1 << a));
  1563. tmp = tmp & ~(1 << a);
  1564. SB (addr, tmp);
  1565. trace_output_32 (addr);
  1566. }
  1567. /* cbitb. */
  1568. void
  1569. OP_D6_9 (void)
  1570. {
  1571. uint8 a = (OP[0]) & 0xff;
  1572. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1573. trace_input ("cbitb", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
  1574. tmp = RB (addr);
  1575. SET_PSR_F (tmp & (1 << a));
  1576. tmp = tmp & ~(1 << a);
  1577. SB (addr, tmp);
  1578. trace_output_32 (addr);
  1579. }
  1580. /* cbitb. */
  1581. void
  1582. OP_105_14 (void)
  1583. {
  1584. uint8 a = (OP[0]) & 0xff;
  1585. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1586. trace_input ("cbitb", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
  1587. tmp = RB (addr);
  1588. SET_PSR_F (tmp & (1 << a));
  1589. tmp = tmp & ~(1 << a);
  1590. SB (addr, tmp);
  1591. trace_output_32 (addr);
  1592. }
  1593. /* cbitb. */
  1594. void
  1595. OP_106_14 (void)
  1596. {
  1597. uint8 a = (OP[0]) & 0xff;
  1598. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1599. trace_input ("cbitb", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
  1600. tmp = RB (addr);
  1601. SET_PSR_F (tmp & (1 << a));
  1602. tmp = tmp & ~(1 << a);
  1603. SB (addr, tmp);
  1604. trace_output_32 (addr);
  1605. }
  1606. /* cbitw. */
  1607. void
  1608. OP_6F_8 (void)
  1609. {
  1610. uint16 a = OP[0];
  1611. uint32 addr = OP[1], tmp;
  1612. trace_input ("cbitw", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
  1613. tmp = RW (addr);
  1614. SET_PSR_F (tmp & (1 << a));
  1615. tmp = tmp & ~(1 << a);
  1616. SW (addr, tmp);
  1617. trace_output_32 (tmp);
  1618. }
  1619. /* cbitw. */
  1620. void
  1621. OP_117_14 (void)
  1622. {
  1623. uint16 a = OP[0];
  1624. uint32 addr = OP[1], tmp;
  1625. trace_input ("cbitw", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
  1626. tmp = RW (addr);
  1627. SET_PSR_F (tmp & (1 << a));
  1628. tmp = tmp & ~(1 << a);
  1629. SW (addr, tmp);
  1630. trace_output_32 (tmp);
  1631. }
  1632. /* cbitw. */
  1633. void
  1634. OP_36_7 (void)
  1635. {
  1636. uint32 addr;
  1637. uint16 a = (OP[0]), tmp;
  1638. trace_input ("cbitw", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
  1639. if (OP[1] == 0)
  1640. addr = (GPR32 (12)) + OP[2];
  1641. else
  1642. addr = (GPR32 (13)) + OP[2];
  1643. tmp = RW (addr);
  1644. SET_PSR_F (tmp & (1 << a));
  1645. tmp = tmp & ~(1 << a);
  1646. SW (addr, tmp);
  1647. trace_output_32 (addr);
  1648. }
  1649. /* cbitw. */
  1650. void
  1651. OP_1AB_A (void)
  1652. {
  1653. uint16 a = (OP[0]);
  1654. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1655. trace_input ("cbitw", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
  1656. tmp = RW (addr);
  1657. SET_PSR_F (tmp & (1 << a));
  1658. tmp = tmp & ~(1 << a);
  1659. SW (addr, tmp);
  1660. trace_output_32 (addr);
  1661. }
  1662. /* cbitw. */
  1663. void
  1664. OP_114_14 (void)
  1665. {
  1666. uint16 a = (OP[0]);
  1667. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  1668. trace_input ("cbitw", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
  1669. tmp = RW (addr);
  1670. SET_PSR_F (tmp & (1 << a));
  1671. tmp = tmp & ~(1 << a);
  1672. SW (addr, tmp);
  1673. trace_output_32 (addr);
  1674. }
  1675. /* cbitw. */
  1676. void
  1677. OP_6E_8 (void)
  1678. {
  1679. uint16 a = (OP[0]);
  1680. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1681. trace_input ("cbitw", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
  1682. tmp = RW (addr);
  1683. SET_PSR_F (tmp & (1 << a));
  1684. tmp = tmp & ~(1 << a);
  1685. SW (addr, tmp);
  1686. trace_output_32 (addr);
  1687. }
  1688. /* cbitw. */
  1689. void
  1690. OP_69_8 (void)
  1691. {
  1692. uint16 a = (OP[0]);
  1693. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1694. trace_input ("cbitw", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
  1695. tmp = RW (addr);
  1696. SET_PSR_F (tmp & (1 << a));
  1697. tmp = tmp & ~(1 << a);
  1698. SW (addr, tmp);
  1699. trace_output_32 (addr);
  1700. }
  1701. /* cbitw. */
  1702. void
  1703. OP_115_14 (void)
  1704. {
  1705. uint16 a = (OP[0]);
  1706. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1707. trace_input ("cbitw", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
  1708. tmp = RW (addr);
  1709. SET_PSR_F (tmp & (1 << a));
  1710. tmp = tmp & ~(1 << a);
  1711. SW (addr, tmp);
  1712. trace_output_32 (addr);
  1713. }
  1714. /* cbitw. */
  1715. void
  1716. OP_116_14 (void)
  1717. {
  1718. uint16 a = (OP[0]);
  1719. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1720. trace_input ("cbitw", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
  1721. tmp = RW (addr);
  1722. SET_PSR_F (tmp & (1 << a));
  1723. tmp = tmp & ~(1 << a);
  1724. SW (addr, tmp);
  1725. trace_output_32 (addr);
  1726. }
  1727. /* sbitb. */
  1728. void
  1729. OP_E7_9 (void)
  1730. {
  1731. uint8 a = OP[0] & 0xff;
  1732. uint32 addr = OP[1], tmp;
  1733. trace_input ("sbitb", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
  1734. tmp = RB (addr);
  1735. SET_PSR_F (tmp & (1 << a));
  1736. tmp = tmp | (1 << a);
  1737. SB (addr, tmp);
  1738. trace_output_32 (tmp);
  1739. }
  1740. /* sbitb. */
  1741. void
  1742. OP_10B_14 (void)
  1743. {
  1744. uint8 a = OP[0] & 0xff;
  1745. uint32 addr = OP[1], tmp;
  1746. trace_input ("sbitb", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
  1747. tmp = RB (addr);
  1748. SET_PSR_F (tmp & (1 << a));
  1749. tmp = tmp | (1 << a);
  1750. SB (addr, tmp);
  1751. trace_output_32 (tmp);
  1752. }
  1753. /* sbitb. */
  1754. void
  1755. OP_70_8 (void)
  1756. {
  1757. uint8 a = OP[0] & 0xff;
  1758. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  1759. trace_input ("sbitb", OP_CONSTANT4, OP_R_INDEX7_ABS20, OP_VOID);
  1760. tmp = RB (addr);
  1761. SET_PSR_F (tmp & (1 << a));
  1762. tmp = tmp | (1 << a);
  1763. SB (addr, tmp);
  1764. trace_output_32 (tmp);
  1765. }
  1766. /* sbitb. */
  1767. void
  1768. OP_1CA_A (void)
  1769. {
  1770. uint8 a = OP[0] & 0xff;
  1771. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1772. trace_input ("sbitb", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
  1773. tmp = RB (addr);
  1774. SET_PSR_F (tmp & (1 << a));
  1775. tmp = tmp | (1 << a);
  1776. SB (addr, tmp);
  1777. trace_output_32 (tmp);
  1778. }
  1779. /* sbitb. */
  1780. void
  1781. OP_108_14 (void)
  1782. {
  1783. uint8 a = OP[0] & 0xff;
  1784. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  1785. trace_input ("sbitb", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
  1786. tmp = RB (addr);
  1787. SET_PSR_F (tmp & (1 << a));
  1788. tmp = tmp | (1 << a);
  1789. SB (addr, tmp);
  1790. trace_output_32 (tmp);
  1791. }
  1792. /* sbitb. */
  1793. void
  1794. OP_E4_9 (void)
  1795. {
  1796. uint8 a = OP[0] & 0xff;
  1797. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1798. trace_input ("sbitb", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
  1799. tmp = RB (addr);
  1800. SET_PSR_F (tmp & (1 << a));
  1801. tmp = tmp | (1 << a);
  1802. SB (addr, tmp);
  1803. trace_output_32 (tmp);
  1804. }
  1805. /* sbitb. */
  1806. void
  1807. OP_E6_9 (void)
  1808. {
  1809. uint8 a = OP[0] & 0xff;
  1810. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1811. trace_input ("sbitb", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
  1812. tmp = RB (addr);
  1813. SET_PSR_F (tmp & (1 << a));
  1814. tmp = tmp | (1 << a);
  1815. SB (addr, tmp);
  1816. trace_output_32 (tmp);
  1817. }
  1818. /* sbitb. */
  1819. void
  1820. OP_109_14 (void)
  1821. {
  1822. uint8 a = OP[0] & 0xff;
  1823. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1824. trace_input ("sbitb", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
  1825. tmp = RB (addr);
  1826. SET_PSR_F (tmp & (1 << a));
  1827. tmp = tmp | (1 << a);
  1828. SB (addr, tmp);
  1829. trace_output_32 (tmp);
  1830. }
  1831. /* sbitb. */
  1832. void
  1833. OP_10A_14 (void)
  1834. {
  1835. uint8 a = OP[0] & 0xff;
  1836. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1837. trace_input ("sbitb", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
  1838. tmp = RB (addr);
  1839. SET_PSR_F (tmp & (1 << a));
  1840. tmp = tmp | (1 << a);
  1841. SB (addr, tmp);
  1842. trace_output_32 (tmp);
  1843. }
  1844. /* sbitw. */
  1845. void
  1846. OP_77_8 (void)
  1847. {
  1848. uint16 a = OP[0];
  1849. uint32 addr = OP[1], tmp;
  1850. trace_input ("sbitw", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
  1851. tmp = RW (addr);
  1852. SET_PSR_F (tmp & (1 << a));
  1853. tmp = tmp | (1 << a);
  1854. SW (addr, tmp);
  1855. trace_output_32 (tmp);
  1856. }
  1857. /* sbitw. */
  1858. void
  1859. OP_11B_14 (void)
  1860. {
  1861. uint16 a = OP[0];
  1862. uint32 addr = OP[1], tmp;
  1863. trace_input ("sbitw", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
  1864. tmp = RW (addr);
  1865. SET_PSR_F (tmp & (1 << a));
  1866. tmp = tmp | (1 << a);
  1867. SW (addr, tmp);
  1868. trace_output_32 (tmp);
  1869. }
  1870. /* sbitw. */
  1871. void
  1872. OP_3A_7 (void)
  1873. {
  1874. uint32 addr;
  1875. uint16 a = (OP[0]), tmp;
  1876. trace_input ("sbitw", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
  1877. if (OP[1] == 0)
  1878. addr = (GPR32 (12)) + OP[2];
  1879. else
  1880. addr = (GPR32 (13)) + OP[2];
  1881. tmp = RW (addr);
  1882. SET_PSR_F (tmp & (1 << a));
  1883. tmp = tmp | (1 << a);
  1884. SW (addr, tmp);
  1885. trace_output_32 (addr);
  1886. }
  1887. /* sbitw. */
  1888. void
  1889. OP_1CB_A (void)
  1890. {
  1891. uint16 a = (OP[0]);
  1892. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1893. trace_input ("sbitw", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
  1894. tmp = RW (addr);
  1895. SET_PSR_F (tmp & (1 << a));
  1896. tmp = tmp | (1 << a);
  1897. SW (addr, tmp);
  1898. trace_output_32 (addr);
  1899. }
  1900. /* sbitw. */
  1901. void
  1902. OP_118_14 (void)
  1903. {
  1904. uint16 a = (OP[0]);
  1905. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  1906. trace_input ("sbitw", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
  1907. tmp = RW (addr);
  1908. SET_PSR_F (tmp & (1 << a));
  1909. tmp = tmp | (1 << a);
  1910. SW (addr, tmp);
  1911. trace_output_32 (addr);
  1912. }
  1913. /* sbitw. */
  1914. void
  1915. OP_76_8 (void)
  1916. {
  1917. uint16 a = (OP[0]);
  1918. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1919. trace_input ("sbitw", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
  1920. tmp = RW (addr);
  1921. SET_PSR_F (tmp & (1 << a));
  1922. tmp = tmp | (1 << a);
  1923. SW (addr, tmp);
  1924. trace_output_32 (addr);
  1925. }
  1926. /* sbitw. */
  1927. void
  1928. OP_71_8 (void)
  1929. {
  1930. uint16 a = (OP[0]);
  1931. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1932. trace_input ("sbitw", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
  1933. tmp = RW (addr);
  1934. SET_PSR_F (tmp & (1 << a));
  1935. tmp = tmp | (1 << a);
  1936. SW (addr, tmp);
  1937. trace_output_32 (addr);
  1938. }
  1939. /* sbitw. */
  1940. void
  1941. OP_119_14 (void)
  1942. {
  1943. uint16 a = (OP[0]);
  1944. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1945. trace_input ("sbitw", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
  1946. tmp = RW (addr);
  1947. SET_PSR_F (tmp & (1 << a));
  1948. tmp = tmp | (1 << a);
  1949. SW (addr, tmp);
  1950. trace_output_32 (addr);
  1951. }
  1952. /* sbitw. */
  1953. void
  1954. OP_11A_14 (void)
  1955. {
  1956. uint16 a = (OP[0]);
  1957. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  1958. trace_input ("sbitw", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
  1959. tmp = RW (addr);
  1960. SET_PSR_F (tmp & (1 << a));
  1961. tmp = tmp | (1 << a);
  1962. SW (addr, tmp);
  1963. trace_output_32 (addr);
  1964. }
  1965. /* tbitb. */
  1966. void
  1967. OP_F7_9 (void)
  1968. {
  1969. uint8 a = OP[0] & 0xff;
  1970. uint32 addr = OP[1], tmp;
  1971. trace_input ("tbitb", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
  1972. tmp = RB (addr);
  1973. SET_PSR_F (tmp & (1 << a));
  1974. trace_output_32 (tmp);
  1975. }
  1976. /* tbitb. */
  1977. void
  1978. OP_10F_14 (void)
  1979. {
  1980. uint8 a = OP[0] & 0xff;
  1981. uint32 addr = OP[1], tmp;
  1982. trace_input ("tbitb", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
  1983. tmp = RB (addr);
  1984. SET_PSR_F (tmp & (1 << a));
  1985. trace_output_32 (tmp);
  1986. }
  1987. /* tbitb. */
  1988. void
  1989. OP_78_8 (void)
  1990. {
  1991. uint8 a = (OP[0]) & 0xff;
  1992. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  1993. trace_input ("tbitb", OP_CONSTANT4, OP_R_INDEX7_ABS20, OP_VOID);
  1994. tmp = RB (addr);
  1995. SET_PSR_F (tmp & (1 << a));
  1996. trace_output_32 (addr);
  1997. }
  1998. /* tbitb. */
  1999. void
  2000. OP_1EA_A (void)
  2001. {
  2002. uint8 a = (OP[0]) & 0xff;
  2003. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2004. trace_input ("tbitb", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
  2005. tmp = RB (addr);
  2006. SET_PSR_F (tmp & (1 << a));
  2007. trace_output_32 (addr);
  2008. }
  2009. /* tbitb. */
  2010. void
  2011. OP_10C_14 (void)
  2012. {
  2013. uint8 a = (OP[0]) & 0xff;
  2014. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  2015. trace_input ("tbitb", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
  2016. tmp = RB (addr);
  2017. SET_PSR_F (tmp & (1 << a));
  2018. trace_output_32 (addr);
  2019. }
  2020. /* tbitb. */
  2021. void
  2022. OP_F4_9 (void)
  2023. {
  2024. uint8 a = (OP[0]) & 0xff;
  2025. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2026. trace_input ("tbitb", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
  2027. tmp = RB (addr);
  2028. SET_PSR_F (tmp & (1 << a));
  2029. trace_output_32 (addr);
  2030. }
  2031. /* tbitb. */
  2032. void
  2033. OP_F6_9 (void)
  2034. {
  2035. uint8 a = (OP[0]) & 0xff;
  2036. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2037. trace_input ("tbitb", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
  2038. tmp = RB (addr);
  2039. SET_PSR_F (tmp & (1 << a));
  2040. trace_output_32 (addr);
  2041. }
  2042. /* tbitb. */
  2043. void
  2044. OP_10D_14 (void)
  2045. {
  2046. uint8 a = (OP[0]) & 0xff;
  2047. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2048. trace_input ("tbitb", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
  2049. tmp = RB (addr);
  2050. SET_PSR_F (tmp & (1 << a));
  2051. trace_output_32 (addr);
  2052. }
  2053. /* tbitb. */
  2054. void
  2055. OP_10E_14 (void)
  2056. {
  2057. uint8 a = (OP[0]) & 0xff;
  2058. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2059. trace_input ("tbitb", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
  2060. tmp = RB (addr);
  2061. SET_PSR_F (tmp & (1 << a));
  2062. trace_output_32 (addr);
  2063. }
  2064. /* tbitw. */
  2065. void
  2066. OP_7F_8 (void)
  2067. {
  2068. uint16 a = OP[0];
  2069. uint32 addr = OP[1], tmp;
  2070. trace_input ("tbitw", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
  2071. tmp = RW (addr);
  2072. SET_PSR_F (tmp & (1 << a));
  2073. trace_output_32 (tmp);
  2074. }
  2075. /* tbitw. */
  2076. void
  2077. OP_11F_14 (void)
  2078. {
  2079. uint16 a = OP[0];
  2080. uint32 addr = OP[1], tmp;
  2081. trace_input ("tbitw", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
  2082. tmp = RW (addr);
  2083. SET_PSR_F (tmp & (1 << a));
  2084. trace_output_32 (tmp);
  2085. }
  2086. /* tbitw. */
  2087. void
  2088. OP_3E_7 (void)
  2089. {
  2090. uint32 addr;
  2091. uint16 a = (OP[0]), tmp;
  2092. trace_input ("tbitw", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
  2093. if (OP[1] == 0)
  2094. addr = (GPR32 (12)) + OP[2];
  2095. else
  2096. addr = (GPR32 (13)) + OP[2];
  2097. tmp = RW (addr);
  2098. SET_PSR_F (tmp & (1 << a));
  2099. trace_output_32 (addr);
  2100. }
  2101. /* tbitw. */
  2102. void
  2103. OP_1EB_A (void)
  2104. {
  2105. uint16 a = (OP[0]);
  2106. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2107. trace_input ("tbitw", OP_CONSTANT4, OP_RP_INDEX_DISP14, OP_VOID);
  2108. tmp = RW (addr);
  2109. SET_PSR_F (tmp & (1 << a));
  2110. trace_output_32 (addr);
  2111. }
  2112. /* tbitw. */
  2113. void
  2114. OP_11C_14 (void)
  2115. {
  2116. uint16 a = (OP[0]);
  2117. uint32 addr = (GPR (OP[2])) + OP[1], tmp;
  2118. trace_input ("tbitw", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
  2119. tmp = RW (addr);
  2120. SET_PSR_F (tmp & (1 << a));
  2121. trace_output_32 (addr);
  2122. }
  2123. /* tbitw. */
  2124. void
  2125. OP_7E_8 (void)
  2126. {
  2127. uint16 a = (OP[0]);
  2128. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2129. trace_input ("tbitw", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
  2130. tmp = RW (addr);
  2131. SET_PSR_F (tmp & (1 << a));
  2132. trace_output_32 (addr);
  2133. }
  2134. /* tbitw. */
  2135. void
  2136. OP_79_8 (void)
  2137. {
  2138. uint16 a = (OP[0]);
  2139. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2140. trace_input ("tbitw", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
  2141. tmp = RW (addr);
  2142. SET_PSR_F (tmp & (1 << a));
  2143. trace_output_32 (addr);
  2144. }
  2145. /* tbitw. */
  2146. void
  2147. OP_11D_14 (void)
  2148. {
  2149. uint16 a = (OP[0]);
  2150. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2151. trace_input ("tbitw", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
  2152. tmp = RW (addr);
  2153. SET_PSR_F (tmp & (1 << a));
  2154. trace_output_32 (addr);
  2155. }
  2156. /* tbitw. */
  2157. void
  2158. OP_11E_14 (void)
  2159. {
  2160. uint16 a = (OP[0]);
  2161. uint32 addr = (GPR32 (OP[2])) + OP[1], tmp;
  2162. trace_input ("tbitw", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
  2163. tmp = RW (addr);
  2164. SET_PSR_F (tmp & (1 << a));
  2165. trace_output_32 (addr);
  2166. }
  2167. /* tbit. */
  2168. void
  2169. OP_6_8 (void)
  2170. {
  2171. uint16 a = OP[0];
  2172. uint16 b = (GPR (OP[1]));
  2173. trace_input ("tbit", OP_CONSTANT4, OP_REG, OP_VOID);
  2174. SET_PSR_F (b & (1 << a));
  2175. trace_output_16 (b);
  2176. }
  2177. /* tbit. */
  2178. void
  2179. OP_7_8 (void)
  2180. {
  2181. uint16 a = GPR (OP[0]);
  2182. uint16 b = (GPR (OP[1]));
  2183. trace_input ("tbit", OP_REG, OP_REG, OP_VOID);
  2184. SET_PSR_F (b & (1 << a));
  2185. trace_output_16 (b);
  2186. }
  2187. /* cmpb. */
  2188. void
  2189. OP_50_8 (void)
  2190. {
  2191. uint8 a = (OP[0]) & 0xFF;
  2192. uint8 b = (GPR (OP[1])) & 0xFF;
  2193. trace_input ("cmpb", OP_CONSTANT4, OP_REG, OP_VOID);
  2194. SET_PSR_Z (a == b);
  2195. SET_PSR_N ((int8)a > (int8)b);
  2196. SET_PSR_L (a > b);
  2197. trace_output_flag ();
  2198. }
  2199. /* cmpb. */
  2200. void
  2201. OP_50B_C (void)
  2202. {
  2203. uint8 a = (OP[0]) & 0xFF;
  2204. uint8 b = (GPR (OP[1])) & 0xFF;
  2205. trace_input ("cmpb", OP_CONSTANT16, OP_REG, OP_VOID);
  2206. SET_PSR_Z (a == b);
  2207. SET_PSR_N ((int8)a > (int8)b);
  2208. SET_PSR_L (a > b);
  2209. trace_output_flag ();
  2210. }
  2211. /* cmpb. */
  2212. void
  2213. OP_51_8 (void)
  2214. {
  2215. uint8 a = (GPR (OP[0])) & 0xFF;
  2216. uint8 b = (GPR (OP[1])) & 0xFF;
  2217. trace_input ("cmpb", OP_REG, OP_REG, OP_VOID);
  2218. SET_PSR_Z (a == b);
  2219. SET_PSR_N ((int8)a > (int8)b);
  2220. SET_PSR_L (a > b);
  2221. trace_output_flag ();
  2222. }
  2223. /* cmpw. */
  2224. void
  2225. OP_52_8 (void)
  2226. {
  2227. uint16 a = (OP[0]);
  2228. uint16 b = GPR (OP[1]);
  2229. trace_input ("cmpw", OP_CONSTANT4, OP_REG, OP_VOID);
  2230. SET_PSR_Z (a == b);
  2231. SET_PSR_N ((int16)a > (int16)b);
  2232. SET_PSR_L (a > b);
  2233. trace_output_flag ();
  2234. }
  2235. /* cmpw. */
  2236. void
  2237. OP_52B_C (void)
  2238. {
  2239. uint16 a = (OP[0]);
  2240. uint16 b = GPR (OP[1]);
  2241. trace_input ("cmpw", OP_CONSTANT16, OP_REG, OP_VOID);
  2242. SET_PSR_Z (a == b);
  2243. SET_PSR_N ((int16)a > (int16)b);
  2244. SET_PSR_L (a > b);
  2245. trace_output_flag ();
  2246. }
  2247. /* cmpw. */
  2248. void
  2249. OP_53_8 (void)
  2250. {
  2251. uint16 a = GPR (OP[0]) ;
  2252. uint16 b = GPR (OP[1]) ;
  2253. trace_input ("cmpw", OP_REG, OP_REG, OP_VOID);
  2254. SET_PSR_Z (a == b);
  2255. SET_PSR_N ((int16)a > (int16)b);
  2256. SET_PSR_L (a > b);
  2257. trace_output_flag ();
  2258. }
  2259. /* cmpd. */
  2260. void
  2261. OP_56_8 (void)
  2262. {
  2263. uint32 a = (OP[0]);
  2264. uint32 b = GPR32 (OP[1]);
  2265. trace_input ("cmpd", OP_CONSTANT4, OP_REGP, OP_VOID);
  2266. SET_PSR_Z (a == b);
  2267. SET_PSR_N ((int32)a > (int32)b);
  2268. SET_PSR_L (a > b);
  2269. trace_output_flag ();
  2270. }
  2271. /* cmpd. */
  2272. void
  2273. OP_56B_C (void)
  2274. {
  2275. uint32 a = (SEXT16(OP[0]));
  2276. uint32 b = GPR32 (OP[1]);
  2277. trace_input ("cmpd", OP_CONSTANT16, OP_REGP, OP_VOID);
  2278. SET_PSR_Z (a == b);
  2279. SET_PSR_N ((int32)a > (int32)b);
  2280. SET_PSR_L (a > b);
  2281. trace_output_flag ();
  2282. }
  2283. /* cmpd. */
  2284. void
  2285. OP_57_8 (void)
  2286. {
  2287. uint32 a = GPR32 (OP[0]) ;
  2288. uint32 b = GPR32 (OP[1]) ;
  2289. trace_input ("cmpd", OP_REGP, OP_REGP, OP_VOID);
  2290. SET_PSR_Z (a == b);
  2291. SET_PSR_N ((int32)a > (int32)b);
  2292. SET_PSR_L (a > b);
  2293. trace_output_flag ();
  2294. }
  2295. /* cmpd. */
  2296. void
  2297. OP_9_C (void)
  2298. {
  2299. uint32 a = (OP[0]);
  2300. uint32 b = GPR32 (OP[1]);
  2301. trace_input ("cmpd", OP_CONSTANT32, OP_REGP, OP_VOID);
  2302. SET_PSR_Z (a == b);
  2303. SET_PSR_N ((int32)a > (int32)b);
  2304. SET_PSR_L (a > b);
  2305. trace_output_flag ();
  2306. }
  2307. /* movb. */
  2308. void
  2309. OP_58_8 (void)
  2310. {
  2311. uint8 tmp = OP[0] & 0xFF;
  2312. uint16 a = (GPR (OP[1])) & 0xFF00;
  2313. trace_input ("movb", OP_CONSTANT4, OP_REG, OP_VOID);
  2314. SET_GPR (OP[1], (a | tmp));
  2315. trace_output_16 (tmp);
  2316. }
  2317. /* movb. */
  2318. void
  2319. OP_58B_C (void)
  2320. {
  2321. uint8 tmp = OP[0] & 0xFF;
  2322. uint16 a = (GPR (OP[1])) & 0xFF00;
  2323. trace_input ("movb", OP_CONSTANT16, OP_REG, OP_VOID);
  2324. SET_GPR (OP[1], (a | tmp));
  2325. trace_output_16 (tmp);
  2326. }
  2327. /* movb. */
  2328. void
  2329. OP_59_8 (void)
  2330. {
  2331. uint8 tmp = (GPR (OP[0])) & 0xFF;
  2332. uint16 a = (GPR (OP[1])) & 0xFF00;
  2333. trace_input ("movb", OP_REG, OP_REG, OP_VOID);
  2334. SET_GPR (OP[1], (a | tmp));
  2335. trace_output_16 (tmp);
  2336. }
  2337. /* movw. */
  2338. void
  2339. OP_5A_8 (void)
  2340. {
  2341. uint16 tmp = OP[0];
  2342. trace_input ("movw", OP_CONSTANT4_1, OP_REG, OP_VOID);
  2343. SET_GPR (OP[1], (tmp & 0xffff));
  2344. trace_output_16 (tmp);
  2345. }
  2346. /* movw. */
  2347. void
  2348. OP_5AB_C (void)
  2349. {
  2350. int16 tmp = OP[0];
  2351. trace_input ("movw", OP_CONSTANT16, OP_REG, OP_VOID);
  2352. SET_GPR (OP[1], (tmp & 0xffff));
  2353. trace_output_16 (tmp);
  2354. }
  2355. /* movw. */
  2356. void
  2357. OP_5B_8 (void)
  2358. {
  2359. uint16 tmp = GPR (OP[0]);
  2360. uint32 a = GPR32 (OP[1]);
  2361. trace_input ("movw", OP_REG, OP_REGP, OP_VOID);
  2362. a = (a & 0xffff0000) | tmp;
  2363. SET_GPR32 (OP[1], a);
  2364. trace_output_16 (tmp);
  2365. }
  2366. /* movxb. */
  2367. void
  2368. OP_5C_8 (void)
  2369. {
  2370. uint8 tmp = (GPR (OP[0])) & 0xFF;
  2371. trace_input ("movxb", OP_REG, OP_REG, OP_VOID);
  2372. SET_GPR (OP[1], ((SEXT8(tmp)) & 0xffff));
  2373. trace_output_16 (tmp);
  2374. }
  2375. /* movzb. */
  2376. void
  2377. OP_5D_8 (void)
  2378. {
  2379. uint8 tmp = (GPR (OP[0])) & 0xFF;
  2380. trace_input ("movzb", OP_REG, OP_REG, OP_VOID);
  2381. SET_GPR (OP[1], tmp);
  2382. trace_output_16 (tmp);
  2383. }
  2384. /* movxw. */
  2385. void
  2386. OP_5E_8 (void)
  2387. {
  2388. uint16 tmp = GPR (OP[0]);
  2389. trace_input ("movxw", OP_REG, OP_REGP, OP_VOID);
  2390. SET_GPR32 (OP[1], SEXT16(tmp));
  2391. trace_output_16 (tmp);
  2392. }
  2393. /* movzw. */
  2394. void
  2395. OP_5F_8 (void)
  2396. {
  2397. uint16 tmp = GPR (OP[0]);
  2398. trace_input ("movzw", OP_REG, OP_REGP, OP_VOID);
  2399. SET_GPR32 (OP[1], (tmp & 0x0000FFFF));
  2400. trace_output_16 (tmp);
  2401. }
  2402. /* movd. */
  2403. void
  2404. OP_54_8 (void)
  2405. {
  2406. int32 tmp = OP[0];
  2407. trace_input ("movd", OP_CONSTANT4, OP_REGP, OP_VOID);
  2408. SET_GPR32 (OP[1], tmp);
  2409. trace_output_32 (tmp);
  2410. }
  2411. /* movd. */
  2412. void
  2413. OP_54B_C (void)
  2414. {
  2415. int32 tmp = SEXT16(OP[0]);
  2416. trace_input ("movd", OP_CONSTANT16, OP_REGP, OP_VOID);
  2417. SET_GPR32 (OP[1], tmp);
  2418. trace_output_32 (tmp);
  2419. }
  2420. /* movd. */
  2421. void
  2422. OP_55_8 (void)
  2423. {
  2424. uint32 tmp = GPR32 (OP[0]);
  2425. trace_input ("movd", OP_REGP, OP_REGP, OP_VOID);
  2426. SET_GPR32 (OP[1], tmp);
  2427. trace_output_32 (tmp);
  2428. }
  2429. /* movd. */
  2430. void
  2431. OP_5_8 (void)
  2432. {
  2433. uint32 tmp = OP[0];
  2434. trace_input ("movd", OP_CONSTANT20, OP_REGP, OP_VOID);
  2435. SET_GPR32 (OP[1], tmp);
  2436. trace_output_32 (tmp);
  2437. }
  2438. /* movd. */
  2439. void
  2440. OP_7_C (void)
  2441. {
  2442. int32 tmp = OP[0];
  2443. trace_input ("movd", OP_CONSTANT32, OP_REGP, OP_VOID);
  2444. SET_GPR32 (OP[1], tmp);
  2445. trace_output_32 (tmp);
  2446. }
  2447. /* loadm. */
  2448. void
  2449. OP_14_D (void)
  2450. {
  2451. uint32 addr = GPR (0);
  2452. uint16 count = OP[0], reg = 2, tmp;
  2453. trace_input ("loadm", OP_CONSTANT4, OP_VOID, OP_VOID);
  2454. if ((addr & 1))
  2455. {
  2456. State.exception = SIG_CR16_BUS;
  2457. State.pc_changed = 1; /* Don't increment the PC. */
  2458. trace_output_void ();
  2459. return;
  2460. }
  2461. while (count)
  2462. {
  2463. tmp = RW (addr);
  2464. SET_GPR (reg, tmp);
  2465. addr +=2;
  2466. --count;
  2467. reg++;
  2468. if (reg == 6) reg = 8;
  2469. };
  2470. SET_GPR (0, addr);
  2471. trace_output_void ();
  2472. }
  2473. /* loadmp. */
  2474. void
  2475. OP_15_D (void)
  2476. {
  2477. uint32 addr = GPR32 (0);
  2478. uint16 count = OP[0], reg = 2, tmp;
  2479. trace_input ("loadm", OP_CONSTANT4, OP_VOID, OP_VOID);
  2480. if ((addr & 1))
  2481. {
  2482. State.exception = SIG_CR16_BUS;
  2483. State.pc_changed = 1; /* Don't increment the PC. */
  2484. trace_output_void ();
  2485. return;
  2486. }
  2487. while (count)
  2488. {
  2489. tmp = RW (addr);
  2490. SET_GPR (reg, tmp);
  2491. addr +=2;
  2492. --count;
  2493. reg++;
  2494. if (reg == 6) reg = 8;
  2495. };
  2496. SET_GPR32 (0, addr);
  2497. trace_output_void ();
  2498. }
  2499. /* loadb. */
  2500. void
  2501. OP_88_8 (void)
  2502. {
  2503. /* loadb ABS20, REG
  2504. * ADDR = zext24(abs20) | remap (ie 0xF00000)
  2505. * REG = [ADDR]
  2506. * NOTE: remap is
  2507. * If (abs20 > 0xEFFFF) the resulting address is logically ORed
  2508. * with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped
  2509. * by the core to 16M-64k to 16M. */
  2510. uint16 tmp, a = (GPR (OP[1])) & 0xFF00;
  2511. uint32 addr = OP[0];
  2512. trace_input ("loadb", OP_ABS20, OP_REG, OP_VOID);
  2513. if (addr > 0xEFFFF) addr |= 0xF00000;
  2514. tmp = (RB (addr));
  2515. SET_GPR (OP[1], (a | tmp));
  2516. trace_output_16 (tmp);
  2517. }
  2518. /* loadb. */
  2519. void
  2520. OP_127_14 (void)
  2521. {
  2522. /* loadb ABS24, REG
  2523. * ADDR = abs24
  2524. * REGR = [ADDR]. */
  2525. uint16 tmp, a = (GPR (OP[1])) & 0xFF00;
  2526. uint32 addr = OP[0];
  2527. trace_input ("loadb", OP_ABS24, OP_REG, OP_VOID);
  2528. tmp = (RB (addr));
  2529. SET_GPR (OP[1], (a | tmp));
  2530. trace_output_16 (tmp);
  2531. }
  2532. /* loadb. */
  2533. void
  2534. OP_45_7 (void)
  2535. {
  2536. /* loadb [Rindex]ABS20 REG
  2537. * ADDR = Rindex + zext24(disp20)
  2538. * REGR = [ADDR]. */
  2539. uint32 addr;
  2540. uint16 tmp, a = (GPR (OP[2])) & 0xFF00;
  2541. trace_input ("loadb", OP_R_INDEX8_ABS20, OP_REG, OP_VOID);
  2542. if (OP[0] == 0)
  2543. addr = (GPR32 (12)) + OP[1];
  2544. else
  2545. addr = (GPR32 (13)) + OP[1];
  2546. tmp = (RB (addr));
  2547. SET_GPR (OP[2], (a | tmp));
  2548. trace_output_16 (tmp);
  2549. }
  2550. /* loadb. */
  2551. void
  2552. OP_B_4 (void)
  2553. {
  2554. /* loadb DIPS4(REGP) REG
  2555. * ADDR = RPBASE + zext24(DISP4)
  2556. * REG = [ADDR]. */
  2557. uint16 tmp, a = (GPR (OP[2])) & 0xFF00;
  2558. uint32 addr = (GPR32 (OP[1])) + OP[0];
  2559. trace_input ("loadb", OP_RP_BASE_DISP4, OP_REG, OP_VOID);
  2560. tmp = (RB (addr));
  2561. SET_GPR (OP[2], (a | tmp));
  2562. trace_output_16 (tmp);
  2563. }
  2564. /* loadb. */
  2565. void
  2566. OP_BE_8 (void)
  2567. {
  2568. /* loadb [Rindex]disp0(RPbasex) REG
  2569. * ADDR = Rpbasex + Rindex
  2570. * REGR = [ADDR] */
  2571. uint32 addr;
  2572. uint16 tmp, a = (GPR (OP[3])) & 0xFF00;
  2573. trace_input ("loadb", OP_RP_INDEX_DISP0, OP_REG, OP_VOID);
  2574. addr = (GPR32 (OP[2])) + OP[1];
  2575. if (OP[0] == 0)
  2576. addr = (GPR32 (12)) + addr;
  2577. else
  2578. addr = (GPR32 (13)) + addr;
  2579. tmp = (RB (addr));
  2580. SET_GPR (OP[3], (a | tmp));
  2581. trace_output_16 (tmp);
  2582. }
  2583. /* loadb. */
  2584. void
  2585. OP_219_A (void)
  2586. {
  2587. /* loadb [Rindex]disp14(RPbasex) REG
  2588. * ADDR = Rpbasex + Rindex + zext24(disp14)
  2589. * REGR = [ADDR] */
  2590. uint32 addr;
  2591. uint16 tmp, a = (GPR (OP[3])) & 0xFF00;
  2592. addr = (GPR32 (OP[2])) + OP[1];
  2593. if (OP[0] == 0)
  2594. addr = (GPR32 (12)) + addr;
  2595. else
  2596. addr = (GPR32 (13)) + addr;
  2597. trace_input ("loadb", OP_RP_INDEX_DISP14, OP_REG, OP_VOID);
  2598. tmp = (RB (addr));
  2599. SET_GPR (OP[3], (a | tmp));
  2600. trace_output_16 (tmp);
  2601. }
  2602. /* loadb. */
  2603. void
  2604. OP_184_14 (void)
  2605. {
  2606. /* loadb DISPE20(REG) REG
  2607. * zext24(Rbase) + zext24(dispe20)
  2608. * REG = [ADDR] */
  2609. uint16 tmp,a = (GPR (OP[2])) & 0xFF00;
  2610. uint32 addr = OP[0] + (GPR (OP[1]));
  2611. trace_input ("loadb", OP_R_BASE_DISPE20, OP_REG, OP_VOID);
  2612. tmp = (RB (addr));
  2613. SET_GPR (OP[2], (a | tmp));
  2614. trace_output_16 (tmp);
  2615. }
  2616. /* loadb. */
  2617. void
  2618. OP_124_14 (void)
  2619. {
  2620. /* loadb DISP20(REG) REG
  2621. * ADDR = zext24(Rbase) + zext24(disp20)
  2622. * REG = [ADDR] */
  2623. uint16 tmp,a = (GPR (OP[2])) & 0xFF00;
  2624. uint32 addr = OP[0] + (GPR (OP[1]));
  2625. trace_input ("loadb", OP_R_BASE_DISP20, OP_REG, OP_VOID);
  2626. tmp = (RB (addr));
  2627. SET_GPR (OP[2], (a | tmp));
  2628. trace_output_16 (tmp);
  2629. }
  2630. /* loadb. */
  2631. void
  2632. OP_BF_8 (void)
  2633. {
  2634. /* loadb disp16(REGP) REG
  2635. * ADDR = RPbase + zext24(disp16)
  2636. * REGR = [ADDR] */
  2637. uint16 tmp,a = (GPR (OP[2])) & 0xFF00;
  2638. uint32 addr = (GPR32 (OP[1])) + OP[0];
  2639. trace_input ("loadb", OP_RP_BASE_DISP16, OP_REG, OP_VOID);
  2640. tmp = (RB (addr));
  2641. SET_GPR (OP[2], (a | tmp));
  2642. trace_output_16 (tmp);
  2643. }
  2644. /* loadb. */
  2645. void
  2646. OP_125_14 (void)
  2647. {
  2648. /* loadb disp20(REGP) REG
  2649. * ADDR = RPbase + zext24(disp20)
  2650. * REGR = [ADDR] */
  2651. uint16 tmp,a = (GPR (OP[2])) & 0xFF00;
  2652. uint32 addr = (GPR32 (OP[1])) + OP[0];
  2653. trace_input ("loadb", OP_RP_BASE_DISP20, OP_REG, OP_VOID);
  2654. tmp = (RB (addr));
  2655. SET_GPR (OP[2], (a | tmp));
  2656. trace_output_16 (tmp);
  2657. }
  2658. /* loadb. */
  2659. void
  2660. OP_185_14 (void)
  2661. {
  2662. /* loadb -disp20(REGP) REG
  2663. * ADDR = RPbase + zext24(-disp20)
  2664. * REGR = [ADDR] */
  2665. uint16 tmp,a = (GPR (OP[2])) & 0xFF00;
  2666. uint32 addr = (GPR32 (OP[1])) + OP[1];
  2667. trace_input ("loadb", OP_RP_BASE_DISPE20, OP_REG, OP_VOID);
  2668. tmp = (RB (addr));
  2669. SET_GPR (OP[2], (a | tmp));
  2670. trace_output_16 (tmp);
  2671. }
  2672. /* loadb. */
  2673. void
  2674. OP_126_14 (void)
  2675. {
  2676. /* loadb [Rindex]disp20(RPbasexb) REG
  2677. * ADDR = RPbasex + Rindex + zext24(disp20)
  2678. * REGR = [ADDR] */
  2679. uint32 addr;
  2680. uint16 tmp, a = (GPR (OP[3])) & 0xFF00;
  2681. trace_input ("loadb", OP_RP_INDEX_DISP20, OP_REG, OP_VOID);
  2682. addr = (GPR32 (OP[2])) + OP[1];
  2683. if (OP[0] == 0)
  2684. addr = (GPR32 (12)) + addr;
  2685. else
  2686. addr = (GPR32 (13)) + addr;
  2687. tmp = (RB (addr));
  2688. SET_GPR (OP[3], (a | tmp));
  2689. trace_output_16 (tmp);
  2690. }
  2691. /* loadw. */
  2692. void
  2693. OP_89_8 (void)
  2694. {
  2695. /* loadw ABS20, REG
  2696. * ADDR = zext24(abs20) | remap
  2697. * REGR = [ADDR]
  2698. * NOTE: remap is
  2699. * If (abs20 > 0xEFFFF) the resulting address is logically ORed
  2700. * with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped
  2701. * by the core to 16M-64k to 16M. */
  2702. uint16 tmp;
  2703. uint32 addr = OP[0];
  2704. trace_input ("loadw", OP_ABS20, OP_REG, OP_VOID);
  2705. if (addr > 0xEFFFF) addr |= 0xF00000;
  2706. tmp = (RW (addr));
  2707. SET_GPR (OP[1], tmp);
  2708. trace_output_16 (tmp);
  2709. }
  2710. /* loadw. */
  2711. void
  2712. OP_12F_14 (void)
  2713. {
  2714. /* loadw ABS24, REG
  2715. * ADDR = abs24
  2716. * REGR = [ADDR] */
  2717. uint16 tmp;
  2718. uint32 addr = OP[0];
  2719. trace_input ("loadw", OP_ABS24, OP_REG, OP_VOID);
  2720. tmp = (RW (addr));
  2721. SET_GPR (OP[1], tmp);
  2722. trace_output_16 (tmp);
  2723. }
  2724. /* loadw. */
  2725. void
  2726. OP_47_7 (void)
  2727. {
  2728. /* loadw [Rindex]ABS20 REG
  2729. * ADDR = Rindex + zext24(disp20)
  2730. * REGR = [ADDR] */
  2731. uint32 addr;
  2732. uint16 tmp;
  2733. trace_input ("loadw", OP_R_INDEX8_ABS20, OP_REG, OP_VOID);
  2734. if (OP[0] == 0)
  2735. addr = (GPR32 (12)) + OP[1];
  2736. else
  2737. addr = (GPR32 (13)) + OP[1];
  2738. tmp = (RW (addr));
  2739. SET_GPR (OP[2], tmp);
  2740. trace_output_16 (tmp);
  2741. }
  2742. /* loadw. */
  2743. void
  2744. OP_9_4 (void)
  2745. {
  2746. /* loadw DIPS4(REGP) REGP
  2747. * ADDR = RPBASE + zext24(DISP4)
  2748. * REGP = [ADDR]. */
  2749. uint16 tmp;
  2750. uint32 addr, a;
  2751. trace_input ("loadw", OP_RP_BASE_DISP4, OP_REG, OP_VOID);
  2752. addr = (GPR32 (OP[1])) + OP[0];
  2753. tmp = (RW (addr));
  2754. if (OP[2] > 11)
  2755. {
  2756. a = (GPR32 (OP[2])) & 0xffff0000;
  2757. SET_GPR32 (OP[2], (a | tmp));
  2758. }
  2759. else
  2760. SET_GPR (OP[2], tmp);
  2761. trace_output_16 (tmp);
  2762. }
  2763. /* loadw. */
  2764. void
  2765. OP_9E_8 (void)
  2766. {
  2767. /* loadw [Rindex]disp0(RPbasex) REG
  2768. * ADDR = Rpbasex + Rindex
  2769. * REGR = [ADDR] */
  2770. uint32 addr;
  2771. uint16 tmp;
  2772. trace_input ("loadw", OP_RP_INDEX_DISP0, OP_REG, OP_VOID);
  2773. addr = (GPR32 (OP[2])) + OP[1];
  2774. if (OP[0] == 0)
  2775. addr = (GPR32 (12)) + addr;
  2776. else
  2777. addr = (GPR32 (13)) + addr;
  2778. tmp = RW (addr);
  2779. SET_GPR (OP[3], tmp);
  2780. trace_output_16 (tmp);
  2781. }
  2782. /* loadw. */
  2783. void
  2784. OP_21B_A (void)
  2785. {
  2786. /* loadw [Rindex]disp14(RPbasex) REG
  2787. * ADDR = Rpbasex + Rindex + zext24(disp14)
  2788. * REGR = [ADDR] */
  2789. uint32 addr;
  2790. uint16 tmp;
  2791. trace_input ("loadw", OP_RP_INDEX_DISP14, OP_REG, OP_VOID);
  2792. addr = (GPR32 (OP[2])) + OP[1];
  2793. if (OP[0] == 0)
  2794. addr = (GPR32 (12)) + addr;
  2795. else
  2796. addr = (GPR32 (13)) + addr;
  2797. tmp = (RW (addr));
  2798. SET_GPR (OP[3], tmp);
  2799. trace_output_16 (tmp);
  2800. }
  2801. /* loadw. */
  2802. void
  2803. OP_18C_14 (void)
  2804. {
  2805. /* loadw dispe20(REG) REGP
  2806. * REGP = [DISPE20+[REG]] */
  2807. uint16 tmp;
  2808. uint32 addr, a;
  2809. trace_input ("loadw", OP_R_BASE_DISPE20, OP_REGP, OP_VOID);
  2810. addr = OP[0] + (GPR (OP[1]));
  2811. tmp = (RW (addr));
  2812. if (OP[2] > 11)
  2813. {
  2814. a = (GPR32 (OP[2])) & 0xffff0000;
  2815. SET_GPR32 (OP[2], (a | tmp));
  2816. }
  2817. else
  2818. SET_GPR (OP[2], tmp);
  2819. trace_output_16 (tmp);
  2820. }
  2821. /* loadw. */
  2822. void
  2823. OP_12C_14 (void)
  2824. {
  2825. /* loadw DISP20(REG) REGP
  2826. * ADDR = zext24(Rbase) + zext24(disp20)
  2827. * REGP = [ADDR] */
  2828. uint16 tmp;
  2829. uint32 addr, a;
  2830. trace_input ("loadw", OP_R_BASE_DISP20, OP_REGP, OP_VOID);
  2831. addr = OP[0] + (GPR (OP[1]));
  2832. tmp = (RW (addr));
  2833. if (OP[2] > 11)
  2834. {
  2835. a = (GPR32 (OP[2])) & 0xffff0000;
  2836. SET_GPR32 (OP[2], (a | tmp));
  2837. }
  2838. else
  2839. SET_GPR (OP[2], tmp);
  2840. trace_output_16 (tmp);
  2841. }
  2842. /* loadw. */
  2843. void
  2844. OP_9F_8 (void)
  2845. {
  2846. /* loadw disp16(REGP) REGP
  2847. * ADDR = RPbase + zext24(disp16)
  2848. * REGP = [ADDR] */
  2849. uint16 tmp;
  2850. uint32 addr, a;
  2851. trace_input ("loadw", OP_RP_BASE_DISP16, OP_REGP, OP_VOID);
  2852. addr = (GPR32 (OP[1])) + OP[0];
  2853. tmp = (RW (addr));
  2854. if (OP[2] > 11)
  2855. {
  2856. a = (GPR32 (OP[2])) & 0xffff0000;
  2857. SET_GPR32 (OP[2], (a | tmp));
  2858. }
  2859. else
  2860. SET_GPR (OP[2], tmp);
  2861. trace_output_16 (tmp);
  2862. }
  2863. /* loadw. */
  2864. void
  2865. OP_12D_14 (void)
  2866. {
  2867. /* loadw disp20(REGP) REGP
  2868. * ADDR = RPbase + zext24(disp20)
  2869. * REGP = [ADDR] */
  2870. uint16 tmp;
  2871. uint32 addr, a;
  2872. trace_input ("loadw", OP_RP_BASE_DISP20, OP_REG, OP_VOID);
  2873. addr = (GPR32 (OP[1])) + OP[0];
  2874. tmp = (RW (addr));
  2875. if (OP[2] > 11)
  2876. {
  2877. a = (GPR32 (OP[2])) & 0xffff0000;
  2878. SET_GPR32 (OP[2], (a | tmp));
  2879. }
  2880. else
  2881. SET_GPR (OP[2], tmp);
  2882. trace_output_16 (tmp);
  2883. }
  2884. /* loadw. */
  2885. void
  2886. OP_18D_14 (void)
  2887. {
  2888. /* loadw -disp20(REGP) REG
  2889. * ADDR = RPbase + zext24(-disp20)
  2890. * REGR = [ADDR] */
  2891. uint16 tmp;
  2892. uint32 addr, a;
  2893. trace_input ("loadw", OP_RP_BASE_DISPE20, OP_REG, OP_VOID);
  2894. addr = (GPR32 (OP[1])) + OP[0];
  2895. tmp = (RB (addr));
  2896. if (OP[2] > 11)
  2897. {
  2898. a = (GPR32 (OP[2])) & 0xffff0000;
  2899. SET_GPR32 (OP[2], (a | tmp));
  2900. }
  2901. else
  2902. SET_GPR (OP[2], tmp);
  2903. trace_output_16 (tmp);
  2904. }
  2905. /* loadw. */
  2906. void
  2907. OP_12E_14 (void)
  2908. {
  2909. /* loadw [Rindex]disp20(RPbasexb) REG
  2910. * ADDR = RPbasex + Rindex + zext24(disp20)
  2911. * REGR = [ADDR] */
  2912. uint32 addr;
  2913. uint16 tmp;
  2914. trace_input ("loadw", OP_RP_INDEX_DISP20, OP_REG, OP_VOID);
  2915. if (OP[0] == 0)
  2916. addr = (GPR32 (12)) + OP[1] + (GPR32 (OP[2]));
  2917. else
  2918. addr = (GPR32 (13)) + OP[1] + (GPR32 (OP[2]));
  2919. tmp = (RW (addr));
  2920. SET_GPR (OP[3], tmp);
  2921. trace_output_16 (tmp);
  2922. }
  2923. /* loadd. */
  2924. void
  2925. OP_87_8 (void)
  2926. {
  2927. /* loadd ABS20, REGP
  2928. * ADDR = zext24(abs20) | remap
  2929. * REGP = [ADDR]
  2930. * NOTE: remap is
  2931. * If (abs20 > 0xEFFFF) the resulting address is logically ORed
  2932. * with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped
  2933. * by the core to 16M-64k to 16M. */
  2934. uint32 addr, tmp;
  2935. addr = OP[0];
  2936. trace_input ("loadd", OP_ABS20, OP_REGP, OP_VOID);
  2937. if (addr > 0xEFFFF) addr |= 0xF00000;
  2938. tmp = RLW (addr);
  2939. tmp = ((tmp << 16) & 0xffff)| ((tmp >> 16) & 0xffff);
  2940. SET_GPR32 (OP[1], tmp);
  2941. trace_output_32 (tmp);
  2942. }
  2943. /* loadd. */
  2944. void
  2945. OP_12B_14 (void)
  2946. {
  2947. /* loadd ABS24, REGP
  2948. * ADDR = abs24
  2949. * REGP = [ADDR] */
  2950. uint32 addr = OP[0];
  2951. uint32 tmp;
  2952. trace_input ("loadd", OP_ABS24, OP_REGP, OP_VOID);
  2953. tmp = RLW (addr);
  2954. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  2955. SET_GPR32 (OP[1],tmp);
  2956. trace_output_32 (tmp);
  2957. }
  2958. /* loadd. */
  2959. void
  2960. OP_46_7 (void)
  2961. {
  2962. /* loadd [Rindex]ABS20 REGP
  2963. * ADDR = Rindex + zext24(disp20)
  2964. * REGP = [ADDR] */
  2965. uint32 addr, tmp;
  2966. trace_input ("loadd", OP_R_INDEX8_ABS20, OP_REGP, OP_VOID);
  2967. if (OP[0] == 0)
  2968. addr = (GPR32 (12)) + OP[1];
  2969. else
  2970. addr = (GPR32 (13)) + OP[1];
  2971. tmp = RLW (addr);
  2972. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  2973. SET_GPR32 (OP[2], tmp);
  2974. trace_output_32 (tmp);
  2975. }
  2976. /* loadd. */
  2977. void
  2978. OP_A_4 (void)
  2979. {
  2980. /* loadd dips4(regp) REGP
  2981. * ADDR = Rpbase + zext24(disp4)
  2982. * REGP = [ADDR] */
  2983. uint32 tmp, addr = (GPR32 (OP[1])) + OP[0];
  2984. trace_input ("loadd", OP_RP_BASE_DISP4, OP_REGP, OP_VOID);
  2985. tmp = RLW (addr);
  2986. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  2987. SET_GPR32 (OP[2], tmp);
  2988. trace_output_32 (tmp);
  2989. }
  2990. /* loadd. */
  2991. void
  2992. OP_AE_8 (void)
  2993. {
  2994. /* loadd [Rindex]disp0(RPbasex) REGP
  2995. * ADDR = Rpbasex + Rindex
  2996. * REGP = [ADDR] */
  2997. uint32 addr, tmp;
  2998. trace_input ("loadd", OP_RP_INDEX_DISP0, OP_REGP, OP_VOID);
  2999. if (OP[0] == 0)
  3000. addr = (GPR32 (12)) + (GPR32 (OP[2])) + OP[1];
  3001. else
  3002. addr = (GPR32 (13)) + (GPR32 (OP[2])) + OP[1];
  3003. tmp = RLW (addr);
  3004. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  3005. SET_GPR32 (OP[3], tmp);
  3006. trace_output_32 (tmp);
  3007. }
  3008. /* loadd. */
  3009. void
  3010. OP_21A_A (void)
  3011. {
  3012. /* loadd [Rindex]disp14(RPbasex) REGP
  3013. * ADDR = Rpbasex + Rindex + zext24(disp14)
  3014. * REGR = [ADDR] */
  3015. uint32 addr, tmp;
  3016. trace_input ("loadd", OP_RP_INDEX_DISP14, OP_REGP, OP_VOID);
  3017. if (OP[0] == 0)
  3018. addr = (GPR32 (12)) + OP[1] + (GPR32 (OP[2]));
  3019. else
  3020. addr = (GPR32 (13)) + OP[1] + (GPR32 (OP[2]));
  3021. tmp = RLW (addr);
  3022. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  3023. SET_GPR (OP[3],tmp);
  3024. trace_output_32 (tmp);
  3025. }
  3026. /* loadd. */
  3027. void
  3028. OP_188_14 (void)
  3029. {
  3030. /* loadd dispe20(REG) REG
  3031. * zext24(Rbase) + zext24(dispe20)
  3032. * REG = [ADDR] */
  3033. uint32 tmp, addr = OP[0] + (GPR (OP[1]));
  3034. trace_input ("loadd", OP_R_BASE_DISPE20, OP_REGP, OP_VOID);
  3035. tmp = RLW (addr);
  3036. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  3037. SET_GPR32 (OP[2], tmp);
  3038. trace_output_32 (tmp);
  3039. }
  3040. /* loadd. */
  3041. void
  3042. OP_128_14 (void)
  3043. {
  3044. /* loadd DISP20(REG) REG
  3045. * ADDR = zext24(Rbase) + zext24(disp20)
  3046. * REG = [ADDR] */
  3047. uint32 tmp, addr = OP[0] + (GPR (OP[1]));
  3048. trace_input ("loadd", OP_R_BASE_DISP20, OP_REGP, OP_VOID);
  3049. tmp = RLW (addr);
  3050. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  3051. SET_GPR32 (OP[2], tmp);
  3052. trace_output_32 (tmp);
  3053. }
  3054. /* loadd. */
  3055. void
  3056. OP_AF_8 (void)
  3057. {
  3058. /* loadd disp16(REGP) REGP
  3059. * ADDR = RPbase + zext24(disp16)
  3060. * REGR = [ADDR] */
  3061. uint32 tmp, addr = OP[0] + (GPR32 (OP[1]));
  3062. trace_input ("loadd", OP_RP_BASE_DISP16, OP_REGP, OP_VOID);
  3063. tmp = RLW (addr);
  3064. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  3065. SET_GPR32 (OP[2], tmp);
  3066. trace_output_32 (tmp);
  3067. }
  3068. /* loadd. */
  3069. void
  3070. OP_129_14 (void)
  3071. {
  3072. /* loadd disp20(REGP) REGP
  3073. * ADDR = RPbase + zext24(disp20)
  3074. * REGP = [ADDR] */
  3075. uint32 tmp, addr = OP[0] + (GPR32 (OP[1]));
  3076. trace_input ("loadd", OP_RP_BASE_DISP20, OP_REGP, OP_VOID);
  3077. tmp = RLW (addr);
  3078. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  3079. SET_GPR32 (OP[2], tmp);
  3080. trace_output_32 (tmp);
  3081. }
  3082. /* loadd. */
  3083. void
  3084. OP_189_14 (void)
  3085. {
  3086. /* loadd -disp20(REGP) REGP
  3087. * ADDR = RPbase + zext24(-disp20)
  3088. * REGP = [ADDR] */
  3089. uint32 tmp, addr = OP[0] + (GPR32 (OP[1]));
  3090. trace_input ("loadd", OP_RP_BASE_DISPE20, OP_REGP, OP_VOID);
  3091. tmp = RLW (addr);
  3092. tmp = ((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff);
  3093. SET_GPR32 (OP[2], tmp);
  3094. trace_output_32 (tmp);
  3095. }
  3096. /* loadd. */
  3097. void
  3098. OP_12A_14 (void)
  3099. {
  3100. /* loadd [Rindex]disp20(RPbasexb) REGP
  3101. * ADDR = RPbasex + Rindex + zext24(disp20)
  3102. * REGP = [ADDR] */
  3103. uint32 addr, tmp;
  3104. trace_input ("loadd", OP_RP_INDEX_DISP20, OP_REGP, OP_VOID);
  3105. if (OP[0] == 0)
  3106. addr = (GPR32 (12)) + OP[1] + (GPR32 (OP[2]));
  3107. else
  3108. addr = (GPR32 (13)) + OP[1] + (GPR32 (OP[2]));
  3109. tmp = RLW (addr);
  3110. tmp = ((tmp << 16) & 0xffff)| ((tmp >> 16) & 0xffff);
  3111. SET_GPR32 (OP[3], tmp);
  3112. trace_output_32 (tmp);
  3113. }
  3114. /* storb. */
  3115. void
  3116. OP_C8_8 (void)
  3117. {
  3118. /* storb REG, ABS20
  3119. * ADDR = zext24(abs20) | remap
  3120. * [ADDR] = REGR
  3121. * NOTE: remap is
  3122. * If (abs20 > 0xEFFFF) the resulting address is logically ORed
  3123. * with 0xF00000 i.e. addresses from 1M-64k to 1M are re-mapped
  3124. * by the core to 16M-64k to 16M. */
  3125. uint8 a = ((GPR (OP[0])) & 0xff);
  3126. uint32 addr = OP[1];
  3127. trace_input ("storb", OP_REG, OP_ABS20_OUTPUT, OP_VOID);
  3128. SB (addr, a);
  3129. trace_output_32 (addr);
  3130. }
  3131. /* storb. */
  3132. void
  3133. OP_137_14 (void)
  3134. {
  3135. /* storb REG, ABS24
  3136. * ADDR = abs24
  3137. * [ADDR] = REGR. */
  3138. uint8 a = ((GPR (OP[0])) & 0xff);
  3139. uint32 addr = OP[1];
  3140. trace_input ("storb", OP_REG, OP_ABS24_OUTPUT, OP_VOID);
  3141. SB (addr, a);
  3142. trace_output_32 (addr);
  3143. }
  3144. /* storb. */
  3145. void
  3146. OP_65_7 (void)
  3147. {
  3148. /* storb REG, [Rindex]ABS20
  3149. * ADDR = Rindex + zext24(disp20)
  3150. * [ADDR] = REGR */
  3151. uint32 addr;
  3152. uint8 a = ((GPR (OP[0])) & 0xff);
  3153. trace_input ("storb", OP_REG, OP_R_INDEX8_ABS20, OP_VOID);
  3154. if (OP[1] == 0)
  3155. addr = (GPR32 (12)) + OP[2];
  3156. else
  3157. addr = (GPR32 (13)) + OP[2];
  3158. SB (addr, a);
  3159. trace_output_32 (addr);
  3160. }
  3161. /* storb. */
  3162. void
  3163. OP_F_4 (void)
  3164. {
  3165. /* storb REG, DIPS4(REGP)
  3166. * ADDR = RPBASE + zext24(DISP4)
  3167. * [ADDR] = REG. */
  3168. uint16 a = ((GPR (OP[0])) & 0xff);
  3169. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3170. trace_input ("storb", OP_REG, OP_RP_BASE_DISPE4, OP_VOID);
  3171. SB (addr, a);
  3172. trace_output_32 (addr);
  3173. }
  3174. /* storb. */
  3175. void
  3176. OP_FE_8 (void)
  3177. {
  3178. /* storb [Rindex]disp0(RPbasex) REG
  3179. * ADDR = Rpbasex + Rindex
  3180. * [ADDR] = REGR */
  3181. uint32 addr;
  3182. uint8 a = ((GPR (OP[0])) & 0xff);
  3183. trace_input ("storb", OP_REG, OP_RP_INDEX_DISP0, OP_VOID);
  3184. if (OP[1] == 0)
  3185. addr = (GPR32 (12)) + (GPR32 (OP[3])) + OP[2];
  3186. else
  3187. addr = (GPR32 (13)) + (GPR32 (OP[3])) + OP[2];
  3188. SB (addr, a);
  3189. trace_output_32 (addr);
  3190. }
  3191. /* storb. */
  3192. void
  3193. OP_319_A (void)
  3194. {
  3195. /* storb REG, [Rindex]disp14(RPbasex)
  3196. * ADDR = Rpbasex + Rindex + zext24(disp14)
  3197. * [ADDR] = REGR */
  3198. uint8 a = ((GPR (OP[0])) & 0xff);
  3199. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3200. trace_input ("storb", OP_REG, OP_RP_INDEX_DISP14, OP_VOID);
  3201. SB (addr, a);
  3202. trace_output_32 (addr);
  3203. }
  3204. /* storb. */
  3205. void
  3206. OP_194_14 (void)
  3207. {
  3208. /* storb REG, DISPE20(REG)
  3209. * zext24(Rbase) + zext24(dispe20)
  3210. * [ADDR] = REG */
  3211. uint8 a = ((GPR (OP[0])) & 0xff);
  3212. uint32 addr = OP[1] + (GPR (OP[2]));
  3213. trace_input ("storb", OP_REG, OP_R_BASE_DISPE20, OP_VOID);
  3214. SB (addr, a);
  3215. trace_output_32 (addr);
  3216. }
  3217. /* storb. */
  3218. void
  3219. OP_134_14 (void)
  3220. {
  3221. /* storb REG, DISP20(REG)
  3222. * ADDR = zext24(Rbase) + zext24(disp20)
  3223. * [ADDR] = REG */
  3224. uint8 a = (GPR (OP[0]) & 0xff);
  3225. uint32 addr = OP[1] + (GPR (OP[2]));
  3226. trace_input ("storb", OP_REG, OP_R_BASE_DISPS20, OP_VOID);
  3227. SB (addr, a);
  3228. trace_output_32 (addr);
  3229. }
  3230. /* storb. */
  3231. void
  3232. OP_FF_8 (void)
  3233. {
  3234. /* storb REG, disp16(REGP)
  3235. * ADDR = RPbase + zext24(disp16)
  3236. * [ADDR] = REGP */
  3237. uint8 a = ((GPR (OP[0])) & 0xff);
  3238. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3239. trace_input ("storb", OP_REG, OP_RP_BASE_DISP16, OP_VOID);
  3240. SB (addr, a);
  3241. trace_output_32 (addr);
  3242. }
  3243. /* storb. */
  3244. void
  3245. OP_135_14 (void)
  3246. {
  3247. /* storb REG, disp20(REGP)
  3248. * ADDR = RPbase + zext24(disp20)
  3249. * [ADDR] = REGP */
  3250. uint8 a = ((GPR (OP[0])) & 0xff);
  3251. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3252. trace_input ("storb", OP_REG, OP_RP_BASE_DISPS20, OP_VOID);
  3253. SB (addr, a);
  3254. trace_output_32 (addr);
  3255. }
  3256. /* storb. */
  3257. void
  3258. OP_195_14 (void)
  3259. {
  3260. /* storb REG, -disp20(REGP)
  3261. * ADDR = RPbase + zext24(-disp20)
  3262. * [ADDR] = REGP */
  3263. uint8 a = (GPR (OP[0]) & 0xff);
  3264. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3265. trace_input ("storb", OP_REG, OP_RP_BASE_DISPE20, OP_VOID);
  3266. SB (addr, a);
  3267. trace_output_32 (addr);
  3268. }
  3269. /* storb. */
  3270. void
  3271. OP_136_14 (void)
  3272. {
  3273. /* storb REG, [Rindex]disp20(RPbase)
  3274. * ADDR = RPbasex + Rindex + zext24(disp20)
  3275. * [ADDR] = REGP */
  3276. uint8 a = (GPR (OP[0])) & 0xff;
  3277. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3278. trace_input ("storb", OP_REG, OP_RP_INDEX_DISPS20, OP_VOID);
  3279. SB (addr, a);
  3280. trace_output_32 (addr);
  3281. }
  3282. /* STR_IMM instructions. */
  3283. /* storb . */
  3284. void
  3285. OP_81_8 (void)
  3286. {
  3287. uint8 a = (OP[0]) & 0xff;
  3288. uint32 addr = OP[1];
  3289. trace_input ("storb", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
  3290. SB (addr, a);
  3291. trace_output_32 (addr);
  3292. }
  3293. /* storb. */
  3294. void
  3295. OP_123_14 (void)
  3296. {
  3297. uint8 a = (OP[0]) & 0xff;
  3298. uint32 addr = OP[1];
  3299. trace_input ("storb", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
  3300. SB (addr, a);
  3301. trace_output_32 (addr);
  3302. }
  3303. /* storb. */
  3304. void
  3305. OP_42_7 (void)
  3306. {
  3307. uint32 addr;
  3308. uint8 a = (OP[0]) & 0xff;
  3309. trace_input ("storb", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
  3310. if (OP[1] == 0)
  3311. addr = (GPR32 (12)) + OP[2];
  3312. else
  3313. addr = (GPR32 (13)) + OP[2];
  3314. SB (addr, a);
  3315. trace_output_32 (addr);
  3316. }
  3317. /* storb. */
  3318. void
  3319. OP_218_A (void)
  3320. {
  3321. uint8 a = (OP[0]) & 0xff;
  3322. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3323. trace_input ("storb", OP_CONSTANT4, OP_RP_BASE_DISP14, OP_VOID);
  3324. SB (addr, a);
  3325. trace_output_32 (addr);
  3326. }
  3327. /* storb. */
  3328. void
  3329. OP_82_8 (void)
  3330. {
  3331. uint8 a = (OP[0]) & 0xff;
  3332. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3333. trace_input ("storb", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
  3334. SB (addr, a);
  3335. trace_output_32 (addr);
  3336. }
  3337. /* storb. */
  3338. void
  3339. OP_120_14 (void)
  3340. {
  3341. uint8 a = (OP[0]) & 0xff;
  3342. uint32 addr = (GPR (OP[2])) + OP[1];
  3343. trace_input ("storb", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
  3344. SB (addr, a);
  3345. trace_output_32 (addr);
  3346. }
  3347. /* storb. */
  3348. void
  3349. OP_83_8 (void)
  3350. {
  3351. uint8 a = (OP[0]) & 0xff;
  3352. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3353. trace_input ("storb", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
  3354. SB (addr, a);
  3355. trace_output_32 (addr);
  3356. }
  3357. /* storb. */
  3358. void
  3359. OP_121_14 (void)
  3360. {
  3361. uint8 a = (OP[0]) & 0xff;
  3362. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3363. trace_input ("storb", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
  3364. SB (addr, a);
  3365. trace_output_32 (addr);
  3366. }
  3367. /* storb. */
  3368. void
  3369. OP_122_14 (void)
  3370. {
  3371. uint8 a = (OP[0]) & 0xff;
  3372. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3373. trace_input ("storb", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
  3374. SB (addr, a);
  3375. trace_output_32 (addr);
  3376. }
  3377. /* endif for STR_IMM. */
  3378. /* storw . */
  3379. void
  3380. OP_C9_8 (void)
  3381. {
  3382. uint16 a = GPR (OP[0]);
  3383. uint32 addr = OP[1];
  3384. trace_input ("storw", OP_REG, OP_ABS20_OUTPUT, OP_VOID);
  3385. SW (addr, a);
  3386. trace_output_32 (addr);
  3387. }
  3388. /* storw. */
  3389. void
  3390. OP_13F_14 (void)
  3391. {
  3392. uint16 a = GPR (OP[0]);
  3393. uint32 addr = OP[1];
  3394. trace_input ("storw", OP_REG, OP_ABS24_OUTPUT, OP_VOID);
  3395. SW (addr, a);
  3396. trace_output_32 (addr);
  3397. }
  3398. /* storw. */
  3399. void
  3400. OP_67_7 (void)
  3401. {
  3402. uint32 addr;
  3403. uint16 a = GPR (OP[0]);
  3404. trace_input ("storw", OP_REG, OP_R_INDEX8_ABS20, OP_VOID);
  3405. if (OP[1] == 0)
  3406. addr = (GPR32 (12)) + OP[2];
  3407. else
  3408. addr = (GPR32 (13)) + OP[2];
  3409. SW (addr, a);
  3410. trace_output_32 (addr);
  3411. }
  3412. /* storw. */
  3413. void
  3414. OP_D_4 (void)
  3415. {
  3416. uint16 a = (GPR (OP[0]));
  3417. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3418. trace_input ("storw", OP_REGP, OP_RP_BASE_DISPE4, OP_VOID);
  3419. SW (addr, a);
  3420. trace_output_32 (addr);
  3421. }
  3422. /* storw. */
  3423. void
  3424. OP_DE_8 (void)
  3425. {
  3426. uint16 a = GPR (OP[0]);
  3427. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3428. trace_input ("storw", OP_REG, OP_RP_INDEX_DISP0, OP_VOID);
  3429. SW (addr, a);
  3430. trace_output_32 (addr);
  3431. }
  3432. /* storw. */
  3433. void
  3434. OP_31B_A (void)
  3435. {
  3436. uint16 a = GPR (OP[0]);
  3437. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3438. trace_input ("storw", OP_REG, OP_RP_INDEX_DISP14, OP_VOID);
  3439. SW (addr, a);
  3440. trace_output_32 (addr);
  3441. }
  3442. /* storw. */
  3443. void
  3444. OP_19C_14 (void)
  3445. {
  3446. uint16 a = (GPR (OP[0]));
  3447. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3448. trace_input ("storw", OP_REGP, OP_RP_BASE_DISPE20, OP_VOID);
  3449. SW (addr, a);
  3450. trace_output_32 (addr);
  3451. }
  3452. /* storw. */
  3453. void
  3454. OP_13C_14 (void)
  3455. {
  3456. uint16 a = (GPR (OP[0]));
  3457. uint32 addr = (GPR (OP[2])) + OP[1];
  3458. trace_input ("storw", OP_REG, OP_R_BASE_DISPS20, OP_VOID);
  3459. SW (addr, a);
  3460. trace_output_32 (addr);
  3461. }
  3462. /* storw. */
  3463. void
  3464. OP_DF_8 (void)
  3465. {
  3466. uint16 a = (GPR (OP[0]));
  3467. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3468. trace_input ("storw", OP_REG, OP_RP_BASE_DISP16, OP_VOID);
  3469. SW (addr, a);
  3470. trace_output_32 (addr);
  3471. }
  3472. /* storw. */
  3473. void
  3474. OP_13D_14 (void)
  3475. {
  3476. uint16 a = (GPR (OP[0]));
  3477. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3478. trace_input ("storw", OP_REG, OP_RP_BASE_DISPS20, OP_VOID);
  3479. SW (addr, a);
  3480. trace_output_32 (addr);
  3481. }
  3482. /* storw. */
  3483. void
  3484. OP_19D_14 (void)
  3485. {
  3486. uint16 a = (GPR (OP[0]));
  3487. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3488. trace_input ("storw", OP_REG, OP_RP_BASE_DISPE20, OP_VOID);
  3489. SW (addr, a);
  3490. trace_output_32 (addr);
  3491. }
  3492. /* storw. */
  3493. void
  3494. OP_13E_14 (void)
  3495. {
  3496. uint16 a = (GPR (OP[0]));
  3497. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3498. trace_input ("storw", OP_REG, OP_RP_INDEX_DISPS20, OP_VOID);
  3499. SW (addr, a);
  3500. trace_output_32 (addr);
  3501. }
  3502. /* STORE-w IMM instruction *****/
  3503. /* storw . */
  3504. void
  3505. OP_C1_8 (void)
  3506. {
  3507. uint16 a = OP[0];
  3508. uint32 addr = OP[1];
  3509. trace_input ("storw", OP_CONSTANT4, OP_ABS20_OUTPUT, OP_VOID);
  3510. SW (addr, a);
  3511. trace_output_32 (addr);
  3512. }
  3513. /* storw. */
  3514. void
  3515. OP_133_14 (void)
  3516. {
  3517. uint16 a = OP[0];
  3518. uint32 addr = OP[1];
  3519. trace_input ("storw", OP_CONSTANT4, OP_ABS24_OUTPUT, OP_VOID);
  3520. SW (addr, a);
  3521. trace_output_32 (addr);
  3522. }
  3523. /* storw. */
  3524. void
  3525. OP_62_7 (void)
  3526. {
  3527. uint32 addr;
  3528. uint16 a = OP[0];
  3529. trace_input ("storw", OP_CONSTANT4, OP_R_INDEX8_ABS20, OP_VOID);
  3530. if (OP[1] == 0)
  3531. addr = (GPR32 (12)) + OP[2];
  3532. else
  3533. addr = (GPR32 (13)) + OP[2];
  3534. SW (addr, a);
  3535. trace_output_32 (addr);
  3536. }
  3537. /* storw. */
  3538. void
  3539. OP_318_A (void)
  3540. {
  3541. uint16 a = OP[0];
  3542. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3543. trace_input ("storw", OP_CONSTANT4, OP_RP_BASE_DISP14, OP_VOID);
  3544. SW (addr, a);
  3545. trace_output_32 (addr);
  3546. }
  3547. /* storw. */
  3548. void
  3549. OP_C2_8 (void)
  3550. {
  3551. uint16 a = OP[0];
  3552. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3553. trace_input ("storw", OP_CONSTANT4, OP_RP_INDEX_DISP0, OP_VOID);
  3554. SW (addr, a);
  3555. trace_output_32 (addr);
  3556. }
  3557. /* storw. */
  3558. void
  3559. OP_130_14 (void)
  3560. {
  3561. uint16 a = OP[0];
  3562. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3563. trace_input ("storw", OP_CONSTANT4, OP_R_BASE_DISPS20, OP_VOID);
  3564. SW (addr, a);
  3565. trace_output_32 (addr);
  3566. }
  3567. /* storw. */
  3568. void
  3569. OP_C3_8 (void)
  3570. {
  3571. uint16 a = OP[0];
  3572. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3573. trace_input ("storw", OP_CONSTANT4, OP_RP_BASE_DISP16, OP_VOID);
  3574. SW (addr, a);
  3575. trace_output_32 (addr);
  3576. }
  3577. /* storw. */
  3578. void
  3579. OP_131_14 (void)
  3580. {
  3581. uint16 a = OP[0];
  3582. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3583. trace_input ("storw", OP_CONSTANT4, OP_RP_BASE_DISPS20, OP_VOID);
  3584. SW (addr, a);
  3585. trace_output_32 (addr);
  3586. }
  3587. /* storw. */
  3588. void
  3589. OP_132_14 (void)
  3590. {
  3591. uint16 a = OP[0];
  3592. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3593. trace_input ("storw", OP_CONSTANT4, OP_RP_INDEX_DISPS20, OP_VOID);
  3594. SW (addr, a);
  3595. trace_output_32 (addr);
  3596. }
  3597. /* stord. */
  3598. void
  3599. OP_C7_8 (void)
  3600. {
  3601. uint32 a = GPR32 (OP[0]);
  3602. uint32 addr = OP[1];
  3603. trace_input ("stord", OP_REGP, OP_ABS20_OUTPUT, OP_VOID);
  3604. SLW (addr, a);
  3605. trace_output_32 (addr);
  3606. }
  3607. /* stord. */
  3608. void
  3609. OP_13B_14 (void)
  3610. {
  3611. uint32 a = GPR32 (OP[0]);
  3612. uint32 addr = OP[1];
  3613. trace_input ("stord", OP_REGP, OP_ABS24_OUTPUT, OP_VOID);
  3614. SLW (addr, a);
  3615. trace_output_32 (addr);
  3616. }
  3617. /* stord. */
  3618. void
  3619. OP_66_7 (void)
  3620. {
  3621. uint32 addr, a = GPR32 (OP[0]);
  3622. trace_input ("stord", OP_REGP, OP_R_INDEX8_ABS20, OP_VOID);
  3623. if (OP[1] == 0)
  3624. addr = (GPR32 (12)) + OP[2];
  3625. else
  3626. addr = (GPR32 (13)) + OP[2];
  3627. SLW (addr, a);
  3628. trace_output_32 (addr);
  3629. }
  3630. /* stord. */
  3631. void
  3632. OP_E_4 (void)
  3633. {
  3634. uint32 a = GPR32 (OP[0]);
  3635. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3636. trace_input ("stord", OP_REGP, OP_RP_BASE_DISPE4, OP_VOID);
  3637. SLW (addr, a);
  3638. trace_output_32 (addr);
  3639. }
  3640. /* stord. */
  3641. void
  3642. OP_EE_8 (void)
  3643. {
  3644. uint32 a = GPR32 (OP[0]);
  3645. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3646. trace_input ("stord", OP_REGP, OP_RP_INDEX_DISP0, OP_VOID);
  3647. SLW (addr, a);
  3648. trace_output_32 (addr);
  3649. }
  3650. /* stord. */
  3651. void
  3652. OP_31A_A (void)
  3653. {
  3654. uint32 a = GPR32 (OP[0]);
  3655. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3656. trace_input ("stord", OP_REGP, OP_RP_INDEX_DISP14, OP_VOID);
  3657. SLW (addr, a);
  3658. trace_output_32 (addr);
  3659. }
  3660. /* stord. */
  3661. void
  3662. OP_198_14 (void)
  3663. {
  3664. uint32 a = GPR32 (OP[0]);
  3665. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3666. trace_input ("stord", OP_REGP, OP_R_BASE_DISPE20, OP_VOID);
  3667. SLW (addr, a);
  3668. trace_output_32 (addr);
  3669. }
  3670. /* stord. */
  3671. void
  3672. OP_138_14 (void)
  3673. {
  3674. uint32 a = GPR32 (OP[0]);
  3675. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3676. trace_input ("stord", OP_REGP, OP_R_BASE_DISPS20, OP_VOID);
  3677. SLW (addr, a);
  3678. trace_output_32 (addr);
  3679. }
  3680. /* stord. */
  3681. void
  3682. OP_EF_8 (void)
  3683. {
  3684. uint32 a = GPR32 (OP[0]);
  3685. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3686. trace_input ("stord", OP_REGP, OP_RP_BASE_DISP16, OP_VOID);
  3687. SLW (addr, a);
  3688. trace_output_32 (addr);
  3689. }
  3690. /* stord. */
  3691. void
  3692. OP_139_14 (void)
  3693. {
  3694. uint32 a = GPR32 (OP[0]);
  3695. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3696. trace_input ("stord", OP_REGP, OP_RP_BASE_DISPS20, OP_VOID);
  3697. SLW (addr, a);
  3698. trace_output_32 (addr);
  3699. }
  3700. /* stord. */
  3701. void
  3702. OP_199_14 (void)
  3703. {
  3704. uint32 a = GPR32 (OP[0]);
  3705. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3706. trace_input ("stord", OP_REGP, OP_RP_BASE_DISPE20, OP_VOID);
  3707. SLW (addr, a);
  3708. trace_output_32 (addr);
  3709. }
  3710. /* stord. */
  3711. void
  3712. OP_13A_14 (void)
  3713. {
  3714. uint32 a = GPR32 (OP[0]);
  3715. uint32 addr = (GPR32 (OP[2])) + OP[1];
  3716. trace_input ("stord", OP_REGP, OP_RP_INDEX_DISPS20, OP_VOID);
  3717. SLW (addr, a);
  3718. trace_output_32 (addr);
  3719. }
  3720. /* macqu. */
  3721. void
  3722. OP_14D_14 (void)
  3723. {
  3724. int32 tmp;
  3725. int16 src1, src2;
  3726. trace_input ("macuw", OP_REG, OP_REG, OP_REGP);
  3727. src1 = GPR (OP[0]);
  3728. src2 = GPR (OP[1]);
  3729. tmp = src1 * src2;
  3730. /*REVISIT FOR SATURATION and Q FORMAT. */
  3731. SET_GPR32 (OP[2], tmp);
  3732. trace_output_32 (tmp);
  3733. }
  3734. /* macuw. */
  3735. void
  3736. OP_14E_14 (void)
  3737. {
  3738. uint32 tmp;
  3739. uint16 src1, src2;
  3740. trace_input ("macuw", OP_REG, OP_REG, OP_REGP);
  3741. src1 = GPR (OP[0]);
  3742. src2 = GPR (OP[1]);
  3743. tmp = src1 * src2;
  3744. /*REVISIT FOR SATURATION. */
  3745. SET_GPR32 (OP[2], tmp);
  3746. trace_output_32 (tmp);
  3747. }
  3748. /* macsw. */
  3749. void
  3750. OP_14F_14 (void)
  3751. {
  3752. int32 tmp;
  3753. int16 src1, src2;
  3754. trace_input ("macsw", OP_REG, OP_REG, OP_REGP);
  3755. src1 = GPR (OP[0]);
  3756. src2 = GPR (OP[1]);
  3757. tmp = src1 * src2;
  3758. /*REVISIT FOR SATURATION. */
  3759. SET_GPR32 (OP[2], tmp);
  3760. trace_output_32 (tmp);
  3761. }
  3762. /* mulb. */
  3763. void
  3764. OP_64_8 (void)
  3765. {
  3766. int16 tmp;
  3767. int8 a = (OP[0]) & 0xff;
  3768. int8 b = (GPR (OP[1])) & 0xff;
  3769. trace_input ("mulb", OP_CONSTANT4_1, OP_REG, OP_VOID);
  3770. tmp = (a * b) & 0xff;
  3771. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  3772. trace_output_16 (tmp);
  3773. }
  3774. /* mulb. */
  3775. void
  3776. OP_64B_C (void)
  3777. {
  3778. int16 tmp;
  3779. int8 a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
  3780. trace_input ("mulb", OP_CONSTANT4, OP_REG, OP_VOID);
  3781. tmp = (a * b) & 0xff;
  3782. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  3783. trace_output_16 (tmp);
  3784. }
  3785. /* mulb. */
  3786. void
  3787. OP_65_8 (void)
  3788. {
  3789. int16 tmp;
  3790. int8 a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
  3791. trace_input ("mulb", OP_REG, OP_REG, OP_VOID);
  3792. tmp = (a * b) & 0xff;
  3793. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  3794. trace_output_16 (tmp);
  3795. }
  3796. /* mulw. */
  3797. void
  3798. OP_66_8 (void)
  3799. {
  3800. int32 tmp;
  3801. uint16 a = OP[0];
  3802. int16 b = (GPR (OP[1]));
  3803. trace_input ("mulw", OP_CONSTANT4_1, OP_REG, OP_VOID);
  3804. tmp = (a * b) & 0xffff;
  3805. SET_GPR (OP[1], tmp);
  3806. trace_output_32 (tmp);
  3807. }
  3808. /* mulw. */
  3809. void
  3810. OP_66B_C (void)
  3811. {
  3812. int32 tmp;
  3813. int16 a = OP[0], b = (GPR (OP[1]));
  3814. trace_input ("mulw", OP_CONSTANT4, OP_REG, OP_VOID);
  3815. tmp = (a * b) & 0xffff;
  3816. SET_GPR (OP[1], tmp);
  3817. trace_output_32 (tmp);
  3818. }
  3819. /* mulw. */
  3820. void
  3821. OP_67_8 (void)
  3822. {
  3823. int32 tmp;
  3824. int16 a = (GPR (OP[0])), b = (GPR (OP[1]));
  3825. trace_input ("mulw", OP_REG, OP_REG, OP_VOID);
  3826. tmp = (a * b) & 0xffff;
  3827. SET_GPR (OP[1], tmp);
  3828. trace_output_32 (tmp);
  3829. }
  3830. /* mulsb. */
  3831. void
  3832. OP_B_8 (void)
  3833. {
  3834. int16 tmp;
  3835. int8 a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
  3836. trace_input ("mulsb", OP_REG, OP_REG, OP_VOID);
  3837. tmp = a * b;
  3838. SET_GPR (OP[1], tmp);
  3839. trace_output_32 (tmp);
  3840. }
  3841. /* mulsw. */
  3842. void
  3843. OP_62_8 (void)
  3844. {
  3845. int32 tmp;
  3846. int16 a = (GPR (OP[0])), b = (GPR (OP[1]));
  3847. trace_input ("mulsw", OP_REG, OP_REGP, OP_VOID);
  3848. tmp = a * b;
  3849. SET_GPR32 (OP[1], tmp);
  3850. trace_output_32 (tmp);
  3851. }
  3852. /* muluw. */
  3853. void
  3854. OP_63_8 (void)
  3855. {
  3856. uint32 tmp;
  3857. uint16 a = (GPR (OP[0])), b = (GPR (OP[1]));
  3858. trace_input ("muluw", OP_REG, OP_REGP, OP_VOID);
  3859. tmp = a * b;
  3860. SET_GPR32 (OP[1], tmp);
  3861. trace_output_32 (tmp);
  3862. }
  3863. /* nop. */
  3864. void
  3865. OP_2C00_10 (void)
  3866. {
  3867. trace_input ("nop", OP_VOID, OP_VOID, OP_VOID);
  3868. #if 0
  3869. State.exception = SIGTRAP;
  3870. ins_type_counters[ (int)State.ins_type ]--; /* don't count nops as normal instructions */
  3871. switch (State.ins_type)
  3872. {
  3873. default:
  3874. ins_type_counters[ (int)INS_UNKNOWN ]++;
  3875. break;
  3876. }
  3877. #endif
  3878. trace_output_void ();
  3879. }
  3880. /* orb. */
  3881. void
  3882. OP_24_8 (void)
  3883. {
  3884. uint8 tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
  3885. trace_input ("orb", OP_CONSTANT4, OP_REG, OP_VOID);
  3886. tmp = a | b;
  3887. SET_GPR (OP[1], ((GPR (OP[1]) | tmp)));
  3888. trace_output_16 (tmp);
  3889. }
  3890. /* orb. */
  3891. void
  3892. OP_24B_C (void)
  3893. {
  3894. uint8 tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
  3895. trace_input ("orb", OP_CONSTANT16, OP_REG, OP_VOID);
  3896. tmp = a | b;
  3897. SET_GPR (OP[1], ((GPR (OP[1]) | tmp)));
  3898. trace_output_16 (tmp);
  3899. }
  3900. /* orb. */
  3901. void
  3902. OP_25_8 (void)
  3903. {
  3904. uint8 tmp, a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
  3905. trace_input ("orb", OP_REG, OP_REG, OP_VOID);
  3906. tmp = a | b;
  3907. SET_GPR (OP[1], ((GPR (OP[1]) | tmp)));
  3908. trace_output_16 (tmp);
  3909. }
  3910. /* orw. */
  3911. void
  3912. OP_26_8 (void)
  3913. {
  3914. uint16 tmp, a = (OP[0]), b = (GPR (OP[1]));
  3915. trace_input ("orw", OP_CONSTANT4, OP_REG, OP_VOID);
  3916. tmp = a | b;
  3917. SET_GPR (OP[1], tmp);
  3918. trace_output_16 (tmp);
  3919. }
  3920. /* orw. */
  3921. void
  3922. OP_26B_C (void)
  3923. {
  3924. uint16 tmp, a = (OP[0]), b = (GPR (OP[1]));
  3925. trace_input ("orw", OP_CONSTANT16, OP_REG, OP_VOID);
  3926. tmp = a | b;
  3927. SET_GPR (OP[1], tmp);
  3928. trace_output_16 (tmp);
  3929. }
  3930. /* orw. */
  3931. void
  3932. OP_27_8 (void)
  3933. {
  3934. uint16 tmp, a = (GPR (OP[0])), b = (GPR (OP[1]));
  3935. trace_input ("orw", OP_REG, OP_REG, OP_VOID);
  3936. tmp = a | b;
  3937. SET_GPR (OP[1], tmp);
  3938. trace_output_16 (tmp);
  3939. }
  3940. /* lshb. */
  3941. void
  3942. OP_13_9 (void)
  3943. {
  3944. uint16 a = OP[0];
  3945. uint16 tmp, b = (GPR (OP[1])) & 0xFF;
  3946. trace_input ("lshb", OP_CONSTANT4, OP_REG, OP_VOID);
  3947. /* A positive count specifies a shift to the left;
  3948. * A negative count specifies a shift to the right. */
  3949. if (sign_flag)
  3950. tmp = b >> a;
  3951. else
  3952. tmp = b << a;
  3953. sign_flag = 0; /* Reset sign_flag. */
  3954. SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xFF00)));
  3955. trace_output_16 (tmp);
  3956. }
  3957. /* lshb. */
  3958. void
  3959. OP_44_8 (void)
  3960. {
  3961. uint16 a = (GPR (OP[0])) & 0xff;
  3962. uint16 tmp, b = (GPR (OP[1])) & 0xFF;
  3963. trace_input ("lshb", OP_REG, OP_REG, OP_VOID);
  3964. if (a & ((long)1 << 3))
  3965. {
  3966. sign_flag = 1;
  3967. a = ~(a) + 1;
  3968. }
  3969. a = (unsigned int) (a & 0x7);
  3970. /* A positive count specifies a shift to the left;
  3971. * A negative count specifies a shift to the right. */
  3972. if (sign_flag)
  3973. tmp = b >> a;
  3974. else
  3975. tmp = b << a;
  3976. sign_flag = 0; /* Reset sign_flag. */
  3977. SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xFF00)));
  3978. trace_output_16 (tmp);
  3979. }
  3980. /* lshw. */
  3981. void
  3982. OP_46_8 (void)
  3983. {
  3984. uint16 tmp, b = GPR (OP[1]);
  3985. int16 a = GPR (OP[0]);
  3986. trace_input ("lshw", OP_REG, OP_REG, OP_VOID);
  3987. if (a & ((long)1 << 4))
  3988. {
  3989. sign_flag = 1;
  3990. a = ~(a) + 1;
  3991. }
  3992. a = (unsigned int) (a & 0xf);
  3993. /* A positive count specifies a shift to the left;
  3994. * A negative count specifies a shift to the right. */
  3995. if (sign_flag)
  3996. tmp = b >> a;
  3997. else
  3998. tmp = b << a;
  3999. sign_flag = 0; /* Reset sign_flag. */
  4000. SET_GPR (OP[1], (tmp & 0xffff));
  4001. trace_output_16 (tmp);
  4002. }
  4003. /* lshw. */
  4004. void
  4005. OP_49_8 (void)
  4006. {
  4007. uint16 tmp, b = GPR (OP[1]);
  4008. uint16 a = OP[0];
  4009. trace_input ("lshw", OP_CONSTANT5, OP_REG, OP_VOID);
  4010. /* A positive count specifies a shift to the left;
  4011. * A negative count specifies a shift to the right. */
  4012. if (sign_flag)
  4013. tmp = b >> a;
  4014. else
  4015. tmp = b << a;
  4016. sign_flag = 0; /* Reset sign_flag. */
  4017. SET_GPR (OP[1], (tmp & 0xffff));
  4018. trace_output_16 (tmp);
  4019. }
  4020. /* lshd. */
  4021. void
  4022. OP_25_7 (void)
  4023. {
  4024. uint32 tmp, b = GPR32 (OP[1]);
  4025. uint16 a = OP[0];
  4026. trace_input ("lshd", OP_CONSTANT6, OP_REGP, OP_VOID);
  4027. /* A positive count specifies a shift to the left;
  4028. * A negative count specifies a shift to the right. */
  4029. if (sign_flag)
  4030. tmp = b >> a;
  4031. else
  4032. tmp = b << a;
  4033. sign_flag = 0; /* Reset sign flag. */
  4034. SET_GPR32 (OP[1], tmp);
  4035. trace_output_32 (tmp);
  4036. }
  4037. /* lshd. */
  4038. void
  4039. OP_47_8 (void)
  4040. {
  4041. uint32 tmp, b = GPR32 (OP[1]);
  4042. uint16 a = GPR (OP[0]);
  4043. trace_input ("lshd", OP_REG, OP_REGP, OP_VOID);
  4044. if (a & ((long)1 << 5))
  4045. {
  4046. sign_flag = 1;
  4047. a = ~(a) + 1;
  4048. }
  4049. a = (unsigned int) (a & 0x1f);
  4050. /* A positive count specifies a shift to the left;
  4051. * A negative count specifies a shift to the right. */
  4052. if (sign_flag)
  4053. tmp = b >> a;
  4054. else
  4055. tmp = b << a;
  4056. sign_flag = 0; /* Reset sign flag. */
  4057. SET_GPR32 (OP[1], tmp);
  4058. trace_output_32 (tmp);
  4059. }
  4060. /* ashub. */
  4061. void
  4062. OP_80_9 (void)
  4063. {
  4064. uint16 a = OP[0];
  4065. int8 tmp, b = (GPR (OP[1])) & 0xFF;
  4066. trace_input ("ashub", OP_CONSTANT4, OP_REG, OP_VOID);
  4067. /* A positive count specifies a shift to the left;
  4068. * A negative count specifies a shift to the right. */
  4069. if (sign_flag)
  4070. tmp = b >> a;
  4071. else
  4072. tmp = b << a;
  4073. sign_flag = 0; /* Reset sign flag. */
  4074. SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xff00)));
  4075. trace_output_16 (tmp);
  4076. }
  4077. /* ashub. */
  4078. void
  4079. OP_81_9 (void)
  4080. {
  4081. uint16 a = OP[0];
  4082. int8 tmp, b = (GPR (OP[1])) & 0xFF;
  4083. trace_input ("ashub", OP_CONSTANT4, OP_REG, OP_VOID);
  4084. /* A positive count specifies a shift to the left;
  4085. * A negative count specifies a shift to the right. */
  4086. if (sign_flag)
  4087. tmp = b >> a;
  4088. else
  4089. tmp = b << a;
  4090. sign_flag = 0; /* Reset sign flag. */
  4091. SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xFF00)));
  4092. trace_output_16 (tmp);
  4093. }
  4094. /* ashub. */
  4095. void
  4096. OP_41_8 (void)
  4097. {
  4098. int16 a = (GPR (OP[0]));
  4099. int8 tmp, b = (GPR (OP[1])) & 0xFF;
  4100. trace_input ("ashub", OP_REG, OP_REG, OP_VOID);
  4101. if (a & ((long)1 << 3))
  4102. {
  4103. sign_flag = 1;
  4104. a = ~(a) + 1;
  4105. }
  4106. a = (unsigned int) (a & 0x7);
  4107. /* A positive count specifies a shift to the left;
  4108. * A negative count specifies a shift to the right. */
  4109. if (sign_flag)
  4110. tmp = b >> a;
  4111. else
  4112. tmp = b << a;
  4113. sign_flag = 0; /* Reset sign flag. */
  4114. SET_GPR (OP[1], ((tmp & 0xFF) | ((GPR (OP[1])) & 0xFF00)));
  4115. trace_output_16 (tmp);
  4116. }
  4117. /* ashuw. */
  4118. void
  4119. OP_42_8 (void)
  4120. {
  4121. int16 tmp, b = GPR (OP[1]);
  4122. uint16 a = OP[0];
  4123. trace_input ("ashuw", OP_CONSTANT5, OP_REG, OP_VOID);
  4124. /* A positive count specifies a shift to the left;
  4125. * A negative count specifies a shift to the right. */
  4126. if (sign_flag)
  4127. tmp = b >> a;
  4128. else
  4129. tmp = b << a;
  4130. sign_flag = 0; /* Reset sign flag. */
  4131. SET_GPR (OP[1], (tmp & 0xffff));
  4132. trace_output_16 (tmp);
  4133. }
  4134. /* ashuw. */
  4135. void
  4136. OP_43_8 (void)
  4137. {
  4138. int16 tmp, b = GPR (OP[1]);
  4139. uint16 a = OP[0];
  4140. trace_input ("ashuw", OP_CONSTANT5, OP_REG, OP_VOID);
  4141. /* A positive count specifies a shift to the left;
  4142. * A negative count specifies a shift to the right. */
  4143. if (sign_flag)
  4144. tmp = b >> a;
  4145. else
  4146. tmp = b << a;
  4147. sign_flag = 0; /* Reset sign flag. */
  4148. SET_GPR (OP[1], (tmp & 0xffff));
  4149. trace_output_16 (tmp);
  4150. }
  4151. /* ashuw. */
  4152. void
  4153. OP_45_8 (void)
  4154. {
  4155. int16 tmp;
  4156. int16 a = GPR (OP[0]), b = GPR (OP[1]);
  4157. trace_input ("ashuw", OP_REG, OP_REG, OP_VOID);
  4158. if (a & ((long)1 << 4))
  4159. {
  4160. sign_flag = 1;
  4161. a = ~(a) + 1;
  4162. }
  4163. a = (unsigned int) (a & 0xf);
  4164. /* A positive count specifies a shift to the left;
  4165. * A negative count specifies a shift to the right. */
  4166. if (sign_flag)
  4167. tmp = b >> a;
  4168. else
  4169. tmp = b << a;
  4170. sign_flag = 0; /* Reset sign flag. */
  4171. SET_GPR (OP[1], (tmp & 0xffff));
  4172. trace_output_16 (tmp);
  4173. }
  4174. /* ashud. */
  4175. void
  4176. OP_26_7 (void)
  4177. {
  4178. int32 tmp,b = GPR32 (OP[1]);
  4179. uint32 a = OP[0];
  4180. trace_input ("ashud", OP_CONSTANT6, OP_REGP, OP_VOID);
  4181. /* A positive count specifies a shift to the left;
  4182. * A negative count specifies a shift to the right. */
  4183. if (sign_flag)
  4184. tmp = b >> a;
  4185. else
  4186. tmp = b << a;
  4187. sign_flag = 0; /* Reset sign flag. */
  4188. SET_GPR32 (OP[1], tmp);
  4189. trace_output_32 (tmp);
  4190. }
  4191. /* ashud. */
  4192. void
  4193. OP_27_7 (void)
  4194. {
  4195. int32 tmp;
  4196. int32 a = OP[0], b = GPR32 (OP[1]);
  4197. trace_input ("ashud", OP_CONSTANT6, OP_REGP, OP_VOID);
  4198. /* A positive count specifies a shift to the left;
  4199. * A negative count specifies a shift to the right. */
  4200. if (sign_flag)
  4201. tmp = b >> a;
  4202. else
  4203. tmp = b << a;
  4204. sign_flag = 0; /* Reset sign flag. */
  4205. SET_GPR32 (OP[1], tmp);
  4206. trace_output_32 (tmp);
  4207. }
  4208. /* ashud. */
  4209. void
  4210. OP_48_8 (void)
  4211. {
  4212. int32 tmp;
  4213. int32 a = GPR32 (OP[0]), b = GPR32 (OP[1]);
  4214. trace_input ("ashud", OP_REGP, OP_REGP, OP_VOID);
  4215. if (a & ((long)1 << 5))
  4216. {
  4217. sign_flag = 1;
  4218. a = ~(a) + 1;
  4219. }
  4220. a = (unsigned int) (a & 0x1f);
  4221. /* A positive count specifies a shift to the left;
  4222. * A negative count specifies a shift to the right. */
  4223. if (sign_flag)
  4224. tmp = b >> a;
  4225. else
  4226. tmp = b << a;
  4227. sign_flag = 0; /* Reset sign flag. */
  4228. SET_GPR32 (OP[1], tmp);
  4229. trace_output_32 (tmp);
  4230. }
  4231. /* storm. */
  4232. void
  4233. OP_16_D (void)
  4234. {
  4235. uint32 addr = GPR (1);
  4236. uint16 count = OP[0], reg = 2;
  4237. trace_input ("storm", OP_CONSTANT4, OP_VOID, OP_VOID);
  4238. if ((addr & 1))
  4239. {
  4240. State.exception = SIG_CR16_BUS;
  4241. State.pc_changed = 1; /* Don't increment the PC. */
  4242. trace_output_void ();
  4243. return;
  4244. }
  4245. while (count)
  4246. {
  4247. SW (addr, (GPR (reg)));
  4248. addr +=2;
  4249. --count;
  4250. reg++;
  4251. if (reg == 6) reg = 8;
  4252. };
  4253. SET_GPR (1, addr);
  4254. trace_output_void ();
  4255. }
  4256. /* stormp. */
  4257. void
  4258. OP_17_D (void)
  4259. {
  4260. uint32 addr = GPR32 (6);
  4261. uint16 count = OP[0], reg = 2;
  4262. trace_input ("stormp", OP_CONSTANT4, OP_VOID, OP_VOID);
  4263. if ((addr & 1))
  4264. {
  4265. State.exception = SIG_CR16_BUS;
  4266. State.pc_changed = 1; /* Don't increment the PC. */
  4267. trace_output_void ();
  4268. return;
  4269. }
  4270. while (count)
  4271. {
  4272. SW (addr, (GPR (reg)));
  4273. addr +=2;
  4274. --count;
  4275. reg++;
  4276. if (reg == 6) reg = 8;
  4277. };
  4278. SET_GPR32 (6, addr);
  4279. trace_output_void ();
  4280. }
  4281. /* subb. */
  4282. void
  4283. OP_38_8 (void)
  4284. {
  4285. uint8 a = OP[0];
  4286. uint8 b = (GPR (OP[1])) & 0xff;
  4287. uint16 tmp = (~a + 1 + b) & 0xff;
  4288. trace_input ("subb", OP_CONSTANT4, OP_REG, OP_VOID);
  4289. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4290. compute the carry/overflow bits. */
  4291. SET_PSR_C (tmp > 0xff);
  4292. SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  4293. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  4294. trace_output_16 (tmp);
  4295. }
  4296. /* subb. */
  4297. void
  4298. OP_38B_C (void)
  4299. {
  4300. uint8 a = OP[0] & 0xFF;
  4301. uint8 b = (GPR (OP[1])) & 0xFF;
  4302. uint16 tmp = (~a + 1 + b) & 0xFF;
  4303. trace_input ("subb", OP_CONSTANT16, OP_REG, OP_VOID);
  4304. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4305. compute the carry/overflow bits. */
  4306. SET_PSR_C (tmp > 0xff);
  4307. SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  4308. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  4309. trace_output_16 (tmp);
  4310. }
  4311. /* subb. */
  4312. void
  4313. OP_39_8 (void)
  4314. {
  4315. uint8 a = (GPR (OP[0])) & 0xFF;
  4316. uint8 b = (GPR (OP[1])) & 0xFF;
  4317. uint16 tmp = (~a + 1 + b) & 0xff;
  4318. trace_input ("subb", OP_REG, OP_REG, OP_VOID);
  4319. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4320. compute the carry/overflow bits. */
  4321. SET_PSR_C (tmp > 0xff);
  4322. SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  4323. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  4324. trace_output_16 (tmp);
  4325. }
  4326. /* subw. */
  4327. void
  4328. OP_3A_8 (void)
  4329. {
  4330. uint16 a = OP[0];
  4331. uint16 b = GPR (OP[1]);
  4332. uint16 tmp = (~a + 1 + b);
  4333. trace_input ("subw", OP_CONSTANT4, OP_REG, OP_VOID);
  4334. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4335. compute the carry/overflow bits. */
  4336. SET_PSR_C (tmp > 0xffff);
  4337. SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  4338. SET_GPR (OP[1], tmp);
  4339. trace_output_16 (tmp);
  4340. }
  4341. /* subw. */
  4342. void
  4343. OP_3AB_C (void)
  4344. {
  4345. uint16 a = OP[0];
  4346. uint16 b = GPR (OP[1]);
  4347. uint32 tmp = (~a + 1 + b);
  4348. trace_input ("subw", OP_CONSTANT16, OP_REG, OP_VOID);
  4349. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4350. compute the carry/overflow bits. */
  4351. SET_PSR_C (tmp > 0xffff);
  4352. SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  4353. SET_GPR (OP[1], tmp & 0xffff);
  4354. trace_output_16 (tmp);
  4355. }
  4356. /* subw. */
  4357. void
  4358. OP_3B_8 (void)
  4359. {
  4360. uint16 a = GPR (OP[0]);
  4361. uint16 b = GPR (OP[1]);
  4362. uint32 tmp = (~a + 1 + b);
  4363. trace_input ("subw", OP_REG, OP_REG, OP_VOID);
  4364. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4365. compute the carry/overflow bits. */
  4366. SET_PSR_C (tmp > 0xffff);
  4367. SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  4368. SET_GPR (OP[1], tmp & 0xffff);
  4369. trace_output_16 (tmp);
  4370. }
  4371. /* subcb. */
  4372. void
  4373. OP_3C_8 (void)
  4374. {
  4375. uint8 a = OP[0];
  4376. uint8 b = (GPR (OP[1])) & 0xff;
  4377. //uint16 tmp1 = a + 1;
  4378. uint16 tmp1 = a + (PSR_C);
  4379. uint16 tmp = (~tmp1 + 1 + b);
  4380. trace_input ("subcb", OP_CONSTANT4, OP_REG, OP_VOID);
  4381. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4382. compute the carry/overflow bits. */
  4383. SET_PSR_C (tmp > 0xff);
  4384. SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  4385. SET_GPR (OP[1], tmp);
  4386. trace_output_16 (tmp);
  4387. }
  4388. /* subcb. */
  4389. void
  4390. OP_3CB_C (void)
  4391. {
  4392. uint16 a = OP[0];
  4393. uint16 b = (GPR (OP[1])) & 0xff;
  4394. //uint16 tmp1 = a + 1;
  4395. uint16 tmp1 = a + (PSR_C);
  4396. uint16 tmp = (~tmp1 + 1 + b);
  4397. trace_input ("subcb", OP_CONSTANT16, OP_REG, OP_VOID);
  4398. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4399. compute the carry/overflow bits. */
  4400. SET_PSR_C (tmp > 0xff);
  4401. SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  4402. SET_GPR (OP[1], tmp);
  4403. trace_output_16 (tmp);
  4404. }
  4405. /* subcb. */
  4406. void
  4407. OP_3D_8 (void)
  4408. {
  4409. uint16 a = (GPR (OP[0])) & 0xff;
  4410. uint16 b = (GPR (OP[1])) & 0xff;
  4411. uint16 tmp1 = a + (PSR_C);
  4412. uint16 tmp = (~tmp1 + 1 + b);
  4413. trace_input ("subcb", OP_REG, OP_REG, OP_VOID);
  4414. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4415. compute the carry/overflow bits. */
  4416. SET_PSR_C (tmp > 0xff);
  4417. SET_PSR_F (((a & 0x80) != (b & 0x80)) && ((b & 0x80) != (tmp & 0x80)));
  4418. SET_GPR (OP[1], tmp);
  4419. trace_output_16 (tmp);
  4420. }
  4421. /* subcw. */
  4422. void
  4423. OP_3E_8 (void)
  4424. {
  4425. uint16 a = OP[0], b = (GPR (OP[1]));
  4426. uint16 tmp1 = a + (PSR_C);
  4427. uint16 tmp = (~tmp1 + 1 + b);
  4428. trace_input ("subcw", OP_CONSTANT4, OP_REG, OP_VOID);
  4429. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4430. compute the carry/overflow bits. */
  4431. SET_PSR_C (tmp > 0xffff);
  4432. SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  4433. SET_GPR (OP[1], tmp);
  4434. trace_output_16 (tmp);
  4435. }
  4436. /* subcw. */
  4437. void
  4438. OP_3EB_C (void)
  4439. {
  4440. int16 a = OP[0];
  4441. uint16 b = GPR (OP[1]);
  4442. uint16 tmp1 = a + (PSR_C);
  4443. uint16 tmp = (~tmp1 + 1 + b);
  4444. trace_input ("subcw", OP_CONSTANT16, OP_REG, OP_VOID);
  4445. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4446. compute the carry/overflow bits. */
  4447. SET_PSR_C (tmp > 0xffff);
  4448. SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  4449. SET_GPR (OP[1], tmp);
  4450. trace_output_16 (tmp);
  4451. }
  4452. /* subcw. */
  4453. void
  4454. OP_3F_8 (void)
  4455. {
  4456. uint16 a = (GPR (OP[0])), b = (GPR (OP[1]));
  4457. uint16 tmp1 = a + (PSR_C);
  4458. uint16 tmp = (~tmp1 + 1 + b);
  4459. trace_input ("subcw", OP_REG, OP_REG, OP_VOID);
  4460. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4461. compute the carry/overflow bits. */
  4462. SET_PSR_C (tmp > 0xffff);
  4463. SET_PSR_F (((a & 0x8000) != (b & 0x8000)) && ((b & 0x8000) != (tmp & 0x8000)));
  4464. SET_GPR (OP[1], tmp);
  4465. trace_output_16 (tmp);
  4466. }
  4467. /* subd. */
  4468. void
  4469. OP_3_C (void)
  4470. {
  4471. int32 a = OP[0];
  4472. uint32 b = GPR32 (OP[1]);
  4473. uint32 tmp = (~a + 1 + b);
  4474. trace_input ("subd", OP_CONSTANT32, OP_REGP, OP_VOID);
  4475. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4476. compute the carry/overflow bits. */
  4477. SET_PSR_C (tmp > 0xffffffff);
  4478. SET_PSR_F (((a & 0x80000000) != (b & 0x80000000)) &&
  4479. ((b & 0x80000000) != (tmp & 0x80000000)));
  4480. SET_GPR32 (OP[1], tmp);
  4481. trace_output_32 (tmp);
  4482. }
  4483. /* subd. */
  4484. void
  4485. OP_14C_14 (void)
  4486. {
  4487. uint32 a = GPR32 (OP[0]);
  4488. uint32 b = GPR32 (OP[1]);
  4489. uint32 tmp = (~a + 1 + b);
  4490. trace_input ("subd", OP_REGP, OP_REGP, OP_VOID);
  4491. /* see ../common/sim-alu.h for a more extensive discussion on how to
  4492. compute the carry/overflow bits. */
  4493. SET_PSR_C (tmp > 0xffffffff);
  4494. SET_PSR_F (((a & 0x80000000) != (b & 0x80000000)) &&
  4495. ((b & 0x80000000) != (tmp & 0x80000000)));
  4496. SET_GPR32 (OP[1], tmp);
  4497. trace_output_32 (tmp);
  4498. }
  4499. /* excp. */
  4500. void
  4501. OP_C_C (void)
  4502. {
  4503. uint32 tmp;
  4504. uint16 a;
  4505. trace_input ("excp", OP_CONSTANT4, OP_VOID, OP_VOID);
  4506. switch (OP[0])
  4507. {
  4508. default:
  4509. #if (DEBUG & DEBUG_TRAP) == 0
  4510. {
  4511. #if 0
  4512. uint16 vec = OP[0] + TRAP_VECTOR_START;
  4513. SET_BPC (PC + 1);
  4514. SET_BPSR (PSR);
  4515. SET_PSR (PSR & PSR_SM_BIT);
  4516. JMP (vec);
  4517. break;
  4518. #endif
  4519. }
  4520. #else /* if debugging use trap to print registers */
  4521. {
  4522. int i;
  4523. static int first_time = 1;
  4524. if (first_time)
  4525. {
  4526. first_time = 0;
  4527. (*cr16_callback->printf_filtered) (cr16_callback, "Trap # PC ");
  4528. for (i = 0; i < 16; i++)
  4529. (*cr16_callback->printf_filtered) (cr16_callback, " %sr%d", (i > 9) ? "" : " ", i);
  4530. (*cr16_callback->printf_filtered) (cr16_callback, " a0 a1 f0 f1 c\n");
  4531. }
  4532. (*cr16_callback->printf_filtered) (cr16_callback, "Trap %2d 0x%.4x:", (int)OP[0], (int)PC);
  4533. for (i = 0; i < 16; i++)
  4534. (*cr16_callback->printf_filtered) (cr16_callback, " %.4x", (int) GPR (i));
  4535. for (i = 0; i < 2; i++)
  4536. (*cr16_callback->printf_filtered) (cr16_callback, " %.2x%.8lx",
  4537. ((int)(ACC (i) >> 32) & 0xff),
  4538. ((unsigned long) ACC (i)) & 0xffffffff);
  4539. (*cr16_callback->printf_filtered) (cr16_callback, " %d %d %d\n",
  4540. PSR_F != 0, PSR_F != 0, PSR_C != 0);
  4541. (*cr16_callback->flush_stdout) (cr16_callback);
  4542. break;
  4543. }
  4544. #endif
  4545. case 8: /* new system call trap */
  4546. /* Trap 8 is used for simulating low-level I/O */
  4547. {
  4548. unsigned32 result = 0;
  4549. errno = 0;
  4550. /* Registers passed to trap 0. */
  4551. #define FUNC GPR (0) /* function number. */
  4552. #define PARM1 GPR (2) /* optional parm 1. */
  4553. #define PARM2 GPR (3) /* optional parm 2. */
  4554. #define PARM3 GPR (4) /* optional parm 3. */
  4555. #define PARM4 GPR (5) /* optional parm 4. */
  4556. /* Registers set by trap 0 */
  4557. #define RETVAL(X) do { result = (0xffff & (X));SET_GPR (0, result);} while (0)
  4558. #define RETVAL32(X) do { result = (X); SET_GPR32 (0, result);} while (0)
  4559. #define RETERR(X) SET_GPR (4, (X)) /* return error code. */
  4560. /* Turn a pointer in a register into a pointer into real memory. */
  4561. #define MEMPTR(x) ((char *)(dmem_addr(x)))
  4562. switch (FUNC)
  4563. {
  4564. #if !defined(__GO32__) && !defined(_WIN32)
  4565. #ifdef TARGET_SYS_fork
  4566. case TARGET_SYS_fork:
  4567. trace_input ("<fork>", OP_VOID, OP_VOID, OP_VOID);
  4568. RETVAL (fork ());
  4569. trace_output_16 (result);
  4570. break;
  4571. #endif
  4572. #define getpid() 47
  4573. case TARGET_SYS_getpid:
  4574. trace_input ("<getpid>", OP_VOID, OP_VOID, OP_VOID);
  4575. RETVAL (getpid ());
  4576. trace_output_16 (result);
  4577. break;
  4578. case TARGET_SYS_kill:
  4579. trace_input ("<kill>", OP_REG, OP_REG, OP_VOID);
  4580. if (PARM1 == getpid ())
  4581. {
  4582. trace_output_void ();
  4583. State.exception = PARM2;
  4584. }
  4585. else
  4586. {
  4587. int os_sig = -1;
  4588. switch (PARM2)
  4589. {
  4590. #ifdef SIGHUP
  4591. case 1: os_sig = SIGHUP; break;
  4592. #endif
  4593. #ifdef SIGINT
  4594. case 2: os_sig = SIGINT; break;
  4595. #endif
  4596. #ifdef SIGQUIT
  4597. case 3: os_sig = SIGQUIT; break;
  4598. #endif
  4599. #ifdef SIGILL
  4600. case 4: os_sig = SIGILL; break;
  4601. #endif
  4602. #ifdef SIGTRAP
  4603. case 5: os_sig = SIGTRAP; break;
  4604. #endif
  4605. #ifdef SIGABRT
  4606. case 6: os_sig = SIGABRT; break;
  4607. #elif defined(SIGIOT)
  4608. case 6: os_sig = SIGIOT; break;
  4609. #endif
  4610. #ifdef SIGEMT
  4611. case 7: os_sig = SIGEMT; break;
  4612. #endif
  4613. #ifdef SIGFPE
  4614. case 8: os_sig = SIGFPE; break;
  4615. #endif
  4616. #ifdef SIGKILL
  4617. case 9: os_sig = SIGKILL; break;
  4618. #endif
  4619. #ifdef SIGBUS
  4620. case 10: os_sig = SIGBUS; break;
  4621. #endif
  4622. #ifdef SIGSEGV
  4623. case 11: os_sig = SIGSEGV; break;
  4624. #endif
  4625. #ifdef SIGSYS
  4626. case 12: os_sig = SIGSYS; break;
  4627. #endif
  4628. #ifdef SIGPIPE
  4629. case 13: os_sig = SIGPIPE; break;
  4630. #endif
  4631. #ifdef SIGALRM
  4632. case 14: os_sig = SIGALRM; break;
  4633. #endif
  4634. #ifdef SIGTERM
  4635. case 15: os_sig = SIGTERM; break;
  4636. #endif
  4637. #ifdef SIGURG
  4638. case 16: os_sig = SIGURG; break;
  4639. #endif
  4640. #ifdef SIGSTOP
  4641. case 17: os_sig = SIGSTOP; break;
  4642. #endif
  4643. #ifdef SIGTSTP
  4644. case 18: os_sig = SIGTSTP; break;
  4645. #endif
  4646. #ifdef SIGCONT
  4647. case 19: os_sig = SIGCONT; break;
  4648. #endif
  4649. #ifdef SIGCHLD
  4650. case 20: os_sig = SIGCHLD; break;
  4651. #elif defined(SIGCLD)
  4652. case 20: os_sig = SIGCLD; break;
  4653. #endif
  4654. #ifdef SIGTTIN
  4655. case 21: os_sig = SIGTTIN; break;
  4656. #endif
  4657. #ifdef SIGTTOU
  4658. case 22: os_sig = SIGTTOU; break;
  4659. #endif
  4660. #ifdef SIGIO
  4661. case 23: os_sig = SIGIO; break;
  4662. #elif defined (SIGPOLL)
  4663. case 23: os_sig = SIGPOLL; break;
  4664. #endif
  4665. #ifdef SIGXCPU
  4666. case 24: os_sig = SIGXCPU; break;
  4667. #endif
  4668. #ifdef SIGXFSZ
  4669. case 25: os_sig = SIGXFSZ; break;
  4670. #endif
  4671. #ifdef SIGVTALRM
  4672. case 26: os_sig = SIGVTALRM; break;
  4673. #endif
  4674. #ifdef SIGPROF
  4675. case 27: os_sig = SIGPROF; break;
  4676. #endif
  4677. #ifdef SIGWINCH
  4678. case 28: os_sig = SIGWINCH; break;
  4679. #endif
  4680. #ifdef SIGLOST
  4681. case 29: os_sig = SIGLOST; break;
  4682. #endif
  4683. #ifdef SIGUSR1
  4684. case 30: os_sig = SIGUSR1; break;
  4685. #endif
  4686. #ifdef SIGUSR2
  4687. case 31: os_sig = SIGUSR2; break;
  4688. #endif
  4689. }
  4690. if (os_sig == -1)
  4691. {
  4692. trace_output_void ();
  4693. (*cr16_callback->printf_filtered) (cr16_callback, "Unknown signal %d\n", PARM2);
  4694. (*cr16_callback->flush_stdout) (cr16_callback);
  4695. State.exception = SIGILL;
  4696. }
  4697. else
  4698. {
  4699. RETVAL (kill (PARM1, PARM2));
  4700. trace_output_16 (result);
  4701. }
  4702. }
  4703. break;
  4704. #ifdef TARGET_SYS_execve
  4705. case TARGET_SYS_execve:
  4706. trace_input ("<execve>", OP_VOID, OP_VOID, OP_VOID);
  4707. RETVAL (execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2<<16|PARM3),
  4708. (char **)MEMPTR (PARM4)));
  4709. trace_output_16 (result);
  4710. break;
  4711. #endif
  4712. #ifdef TARGET_SYS_execv
  4713. case TARGET_SYS_execv:
  4714. trace_input ("<execv>", OP_VOID, OP_VOID, OP_VOID);
  4715. RETVAL (execve (MEMPTR (PARM1), (char **) MEMPTR (PARM2), NULL));
  4716. trace_output_16 (result);
  4717. break;
  4718. #endif
  4719. #ifdef TARGET_SYS_pipe
  4720. case TARGET_SYS_pipe:
  4721. {
  4722. reg_t buf;
  4723. int host_fd[2];
  4724. trace_input ("<pipe>", OP_VOID, OP_VOID, OP_VOID);
  4725. buf = PARM1;
  4726. RETVAL (pipe (host_fd));
  4727. SW (buf, host_fd[0]);
  4728. buf += sizeof(uint16);
  4729. SW (buf, host_fd[1]);
  4730. trace_output_16 (result);
  4731. }
  4732. break;
  4733. #endif
  4734. #ifdef TARGET_SYS_wait
  4735. case TARGET_SYS_wait:
  4736. {
  4737. int status;
  4738. trace_input ("<wait>", OP_REG, OP_VOID, OP_VOID);
  4739. RETVAL (wait (&status));
  4740. if (PARM1)
  4741. SW (PARM1, status);
  4742. trace_output_16 (result);
  4743. }
  4744. break;
  4745. #endif
  4746. #else
  4747. case TARGET_SYS_getpid:
  4748. trace_input ("<getpid>", OP_VOID, OP_VOID, OP_VOID);
  4749. RETVAL (1);
  4750. trace_output_16 (result);
  4751. break;
  4752. case TARGET_SYS_kill:
  4753. trace_input ("<kill>", OP_REG, OP_REG, OP_VOID);
  4754. trace_output_void ();
  4755. State.exception = PARM2;
  4756. break;
  4757. #endif
  4758. case TARGET_SYS_read:
  4759. trace_input ("<read>", OP_REG, OP_MEMREF, OP_REG);
  4760. RETVAL (cr16_callback->read (cr16_callback, PARM1,
  4761. MEMPTR (((unsigned long)PARM3 << 16)
  4762. |((unsigned long)PARM2)), PARM4));
  4763. trace_output_16 (result);
  4764. break;
  4765. case TARGET_SYS_write:
  4766. trace_input ("<write>", OP_REG, OP_MEMREF, OP_REG);
  4767. RETVAL ((int)cr16_callback->write (cr16_callback, PARM1,
  4768. MEMPTR (((unsigned long)PARM3 << 16) | PARM2), PARM4));
  4769. trace_output_16 (result);
  4770. break;
  4771. case TARGET_SYS_lseek:
  4772. trace_input ("<lseek>", OP_REG, OP_REGP, OP_REG);
  4773. RETVAL32 (cr16_callback->lseek (cr16_callback, PARM1,
  4774. ((((long) PARM3) << 16) | PARM2),
  4775. PARM4));
  4776. trace_output_32 (result);
  4777. break;
  4778. case TARGET_SYS_close:
  4779. trace_input ("<close>", OP_REG, OP_VOID, OP_VOID);
  4780. RETVAL (cr16_callback->close (cr16_callback, PARM1));
  4781. trace_output_16 (result);
  4782. break;
  4783. case TARGET_SYS_open:
  4784. trace_input ("<open>", OP_MEMREF, OP_REG, OP_VOID);
  4785. RETVAL32 (cr16_callback->open (cr16_callback,
  4786. MEMPTR ((((unsigned long)PARM2)<<16)|PARM1),
  4787. PARM3));
  4788. trace_output_32 (result);
  4789. break;
  4790. #ifdef TARGET_SYS_rename
  4791. case TARGET_SYS_rename:
  4792. trace_input ("<rename>", OP_MEMREF, OP_MEMREF, OP_VOID);
  4793. RETVAL (cr16_callback->rename (cr16_callback,
  4794. MEMPTR ((((unsigned long)PARM2)<<16) |PARM1),
  4795. MEMPTR ((((unsigned long)PARM4)<<16) |PARM3)));
  4796. trace_output_16 (result);
  4797. break;
  4798. #endif
  4799. case 0x408: /* REVISIT: Added a dummy getenv call. */
  4800. trace_input ("<getenv>", OP_MEMREF, OP_MEMREF, OP_VOID);
  4801. RETVAL32 (0);
  4802. trace_output_32 (result);
  4803. break;
  4804. case TARGET_SYS_exit:
  4805. trace_input ("<exit>", OP_VOID, OP_VOID, OP_VOID);
  4806. State.exception = SIG_CR16_EXIT;
  4807. trace_output_void ();
  4808. break;
  4809. case TARGET_SYS_unlink:
  4810. trace_input ("<unlink>", OP_MEMREF, OP_VOID, OP_VOID);
  4811. RETVAL (cr16_callback->unlink (cr16_callback,
  4812. MEMPTR (((unsigned long)PARM2<<16)|PARM1)));
  4813. trace_output_16 (result);
  4814. break;
  4815. #ifdef TARGET_SYS_stat
  4816. case TARGET_SYS_stat:
  4817. trace_input ("<stat>", OP_VOID, OP_VOID, OP_VOID);
  4818. /* stat system call. */
  4819. {
  4820. struct stat host_stat;
  4821. reg_t buf;
  4822. RETVAL (stat (MEMPTR ((((unsigned long)PARM2) << 16)|PARM1), &host_stat));
  4823. buf = PARM2;
  4824. /* The hard-coded offsets and sizes were determined by using
  4825. * the CR16 compiler on a test program that used struct stat.
  4826. */
  4827. SW (buf, host_stat.st_dev);
  4828. SW (buf+2, host_stat.st_ino);
  4829. SW (buf+4, host_stat.st_mode);
  4830. SW (buf+6, host_stat.st_nlink);
  4831. SW (buf+8, host_stat.st_uid);
  4832. SW (buf+10, host_stat.st_gid);
  4833. SW (buf+12, host_stat.st_rdev);
  4834. SLW (buf+16, host_stat.st_size);
  4835. SLW (buf+20, host_stat.st_atime);
  4836. SLW (buf+28, host_stat.st_mtime);
  4837. SLW (buf+36, host_stat.st_ctime);
  4838. }
  4839. trace_output_16 (result);
  4840. break;
  4841. #endif
  4842. #ifdef TARGET_SYS_chown
  4843. case TARGET_SYS_chown:
  4844. trace_input ("<chown>", OP_VOID, OP_VOID, OP_VOID);
  4845. RETVAL (chown (MEMPTR (PARM1), PARM2, PARM3));
  4846. trace_output_16 (result);
  4847. break;
  4848. #endif
  4849. case TARGET_SYS_chmod:
  4850. trace_input ("<chmod>", OP_VOID, OP_VOID, OP_VOID);
  4851. RETVAL (chmod (MEMPTR (PARM1), PARM2));
  4852. trace_output_16 (result);
  4853. break;
  4854. #ifdef TARGET_SYS_utime
  4855. case TARGET_SYS_utime:
  4856. trace_input ("<utime>", OP_REG, OP_REG, OP_REG);
  4857. /* Cast the second argument to void *, to avoid type mismatch
  4858. if a prototype is present. */
  4859. RETVAL (utime (MEMPTR (PARM1), (void *) MEMPTR (PARM2)));
  4860. trace_output_16 (result);
  4861. break;
  4862. #endif
  4863. #ifdef TARGET_SYS_time
  4864. case TARGET_SYS_time:
  4865. trace_input ("<time>", OP_VOID, OP_VOID, OP_REG);
  4866. RETVAL32 (time (NULL));
  4867. trace_output_32 (result);
  4868. break;
  4869. #endif
  4870. default:
  4871. a = OP[0];
  4872. switch (a)
  4873. {
  4874. case TRAP_BREAKPOINT:
  4875. State.exception = SIGTRAP;
  4876. tmp = (PC);
  4877. JMP(tmp);
  4878. trace_output_void ();
  4879. break;
  4880. case SIGTRAP: /* supervisor call ? */
  4881. State.exception = SIG_CR16_EXIT;
  4882. trace_output_void ();
  4883. break;
  4884. default:
  4885. cr16_callback->error (cr16_callback, "Unknown syscall %d", FUNC);
  4886. break;
  4887. }
  4888. }
  4889. if ((uint16) result == (uint16) -1)
  4890. RETERR (cr16_callback->get_errno(cr16_callback));
  4891. else
  4892. RETERR (0);
  4893. break;
  4894. }
  4895. }
  4896. }
  4897. /* push. */
  4898. void
  4899. OP_3_9 (void)
  4900. {
  4901. uint16 a = OP[0] + 1, b = OP[1], c = OP[2], i = 0;
  4902. uint32 tmp, sp_addr = (GPR32 (15)) - (a * 2) - 4, is_regp = 0;
  4903. trace_input ("push", OP_CONSTANT3, OP_REG, OP_REG);
  4904. for (; i < a; ++i)
  4905. {
  4906. if ((b+i) <= 11)
  4907. {
  4908. SW (sp_addr, (GPR (b+i)));
  4909. sp_addr +=2;
  4910. }
  4911. else
  4912. {
  4913. if (is_regp == 0)
  4914. tmp = (GPR32 (b+i));
  4915. else
  4916. tmp = (GPR32 (b+i-1));
  4917. if ((a-i) > 1)
  4918. {
  4919. SLW (sp_addr, tmp);
  4920. sp_addr +=4;
  4921. }
  4922. else
  4923. {
  4924. SW (sp_addr, tmp);
  4925. sp_addr +=2;
  4926. }
  4927. ++i;
  4928. is_regp = 1;
  4929. }
  4930. }
  4931. sp_addr +=4;
  4932. /* Store RA address. */
  4933. tmp = (GPR32 (14));
  4934. SLW(sp_addr,tmp);
  4935. sp_addr = (GPR32 (15)) - (a * 2) - 4;
  4936. SET_GPR32 (15, sp_addr); /* Update SP address. */
  4937. trace_output_void ();
  4938. }
  4939. /* push. */
  4940. void
  4941. OP_1_8 (void)
  4942. {
  4943. uint32 sp_addr, tmp, is_regp = 0;
  4944. uint16 a = OP[0] + 1, b = OP[1], c = OP[2], i = 0;
  4945. trace_input ("push", OP_CONSTANT3, OP_REG, OP_VOID);
  4946. if (c == 1)
  4947. sp_addr = (GPR32 (15)) - (a * 2) - 4;
  4948. else
  4949. sp_addr = (GPR32 (15)) - (a * 2);
  4950. for (; i < a; ++i)
  4951. {
  4952. if ((b+i) <= 11)
  4953. {
  4954. SW (sp_addr, (GPR (b+i)));
  4955. sp_addr +=2;
  4956. }
  4957. else
  4958. {
  4959. if (is_regp == 0)
  4960. tmp = (GPR32 (b+i));
  4961. else
  4962. tmp = (GPR32 (b+i-1));
  4963. if ((a-i) > 1)
  4964. {
  4965. SLW (sp_addr, tmp);
  4966. sp_addr +=4;
  4967. }
  4968. else
  4969. {
  4970. SW (sp_addr, tmp);
  4971. sp_addr +=2;
  4972. }
  4973. ++i;
  4974. is_regp = 1;
  4975. }
  4976. }
  4977. if (c == 1)
  4978. {
  4979. /* Store RA address. */
  4980. tmp = (GPR32 (14));
  4981. SLW(sp_addr,tmp);
  4982. sp_addr = (GPR32 (15)) - (a * 2) - 4;
  4983. }
  4984. else
  4985. sp_addr = (GPR32 (15)) - (a * 2);
  4986. SET_GPR32 (15, sp_addr); /* Update SP address. */
  4987. trace_output_void ();
  4988. }
  4989. /* push. */
  4990. void
  4991. OP_11E_10 (void)
  4992. {
  4993. uint32 sp_addr = (GPR32 (15)), tmp;
  4994. trace_input ("push", OP_VOID, OP_VOID, OP_VOID);
  4995. tmp = (GPR32 (14));
  4996. SLW(sp_addr-4,tmp); /* Store RA address. */
  4997. SET_GPR32 (15, (sp_addr - 4)); /* Update SP address. */
  4998. trace_output_void ();
  4999. }
  5000. /* pop. */
  5001. void
  5002. OP_5_9 (void)
  5003. {
  5004. uint16 a = OP[0] + 1, b = OP[1], c = OP[2], i = 0;
  5005. uint32 tmp, sp_addr = (GPR32 (15)), is_regp = 0;;
  5006. trace_input ("pop", OP_CONSTANT3, OP_REG, OP_REG);
  5007. for (; i < a; ++i)
  5008. {
  5009. if ((b+i) <= 11)
  5010. {
  5011. SET_GPR ((b+i), RW(sp_addr));
  5012. sp_addr +=2;
  5013. }
  5014. else
  5015. {
  5016. if ((a-i) > 1)
  5017. {
  5018. tmp = RLW(sp_addr);
  5019. sp_addr +=4;
  5020. }
  5021. else
  5022. {
  5023. tmp = RW(sp_addr);
  5024. sp_addr +=2;
  5025. if (is_regp == 0)
  5026. tmp = (tmp << 16) | (GPR32 (b+i));
  5027. else
  5028. tmp = (tmp << 16) | (GPR32 (b+i-1));
  5029. }
  5030. if (is_regp == 0)
  5031. SET_GPR32 ((b+i), (((tmp & 0xffff) << 16)
  5032. | ((tmp >> 16) & 0xffff)));
  5033. else
  5034. SET_GPR32 ((b+i-1), (((tmp & 0xffff) << 16)
  5035. | ((tmp >> 16) & 0xffff)));
  5036. ++i;
  5037. is_regp = 1;
  5038. }
  5039. }
  5040. tmp = RLW(sp_addr); /* store RA also. */
  5041. SET_GPR32 (14, (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
  5042. SET_GPR32 (15, (sp_addr + 4)); /* Update SP address. */
  5043. trace_output_void ();
  5044. }
  5045. /* pop. */
  5046. void
  5047. OP_2_8 (void)
  5048. {
  5049. uint16 a = OP[0] + 1, b = OP[1], c = OP[2], i = 0;
  5050. uint32 tmp, sp_addr = (GPR32 (15)), is_regp = 0;
  5051. trace_input ("pop", OP_CONSTANT3, OP_REG, OP_VOID);
  5052. for (; i < a; ++i)
  5053. {
  5054. if ((b+i) <= 11)
  5055. {
  5056. SET_GPR ((b+i), RW(sp_addr));
  5057. sp_addr +=2;
  5058. }
  5059. else
  5060. {
  5061. if ((a-i) > 1)
  5062. {
  5063. tmp = RLW(sp_addr);
  5064. sp_addr +=4;
  5065. }
  5066. else
  5067. {
  5068. tmp = RW(sp_addr);
  5069. sp_addr +=2;
  5070. if (is_regp == 0)
  5071. tmp = ((tmp << 16) & 0xffffffff) | (GPR32 (b+i));
  5072. else
  5073. tmp = ((tmp << 16) & 0xffffffff) | (GPR32 (b+i-1));
  5074. }
  5075. if (is_regp == 0)
  5076. SET_GPR32 ((b+i), (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
  5077. else
  5078. SET_GPR32 ((b+i-1), (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
  5079. ++i;
  5080. is_regp = 1;
  5081. }
  5082. }
  5083. if (c == 1)
  5084. {
  5085. tmp = RLW(sp_addr); /* Store RA Reg. */
  5086. SET_GPR32 (14, (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
  5087. sp_addr +=4;
  5088. }
  5089. SET_GPR32 (15, sp_addr); /* Update SP address. */
  5090. trace_output_void ();
  5091. }
  5092. /* pop. */
  5093. void
  5094. OP_21E_10 (void)
  5095. {
  5096. uint32 sp_addr = GPR32 (15);
  5097. uint32 tmp;
  5098. trace_input ("pop", OP_VOID, OP_VOID, OP_VOID);
  5099. tmp = RLW(sp_addr);
  5100. SET_GPR32 (14, (((tmp & 0xffff) << 16)| ((tmp >> 16) & 0xffff)));
  5101. SET_GPR32 (15, (sp_addr+4)); /* Update SP address. */
  5102. trace_output_void ();
  5103. }
  5104. /* popret. */
  5105. void
  5106. OP_7_9 (void)
  5107. {
  5108. uint16 a = OP[0], b = OP[1];
  5109. trace_input ("popret", OP_CONSTANT3, OP_REG, OP_REG);
  5110. OP_5_9 ();
  5111. JMP(((GPR32(14)) << 1) & 0xffffff);
  5112. trace_output_void ();
  5113. }
  5114. /* popret. */
  5115. void
  5116. OP_3_8 (void)
  5117. {
  5118. uint16 a = OP[0], b = OP[1];
  5119. trace_input ("popret", OP_CONSTANT3, OP_REG, OP_VOID);
  5120. OP_2_8 ();
  5121. JMP(((GPR32(14)) << 1) & 0xffffff);
  5122. trace_output_void ();
  5123. }
  5124. /* popret. */
  5125. void
  5126. OP_31E_10 (void)
  5127. {
  5128. uint32 tmp;
  5129. trace_input ("popret", OP_VOID, OP_VOID, OP_VOID);
  5130. OP_21E_10 ();
  5131. tmp = (((GPR32(14)) << 1) & 0xffffff);
  5132. /* If the resulting PC value is less than 0x00_0000 or greater
  5133. than 0xFF_FFFF, this instruction causes an IAD trap.*/
  5134. if ((tmp < 0x0) || (tmp > 0xFFFFFF))
  5135. {
  5136. State.exception = SIG_CR16_BUS;
  5137. State.pc_changed = 1; /* Don't increment the PC. */
  5138. trace_output_void ();
  5139. return;
  5140. }
  5141. else
  5142. JMP (tmp);
  5143. trace_output_32 (tmp);
  5144. }
  5145. /* cinv[i]. */
  5146. void
  5147. OP_A_10 (void)
  5148. {
  5149. trace_input ("cinv[i]", OP_VOID, OP_VOID, OP_VOID);
  5150. SET_PSR_I (1);
  5151. trace_output_void ();
  5152. }
  5153. /* cinv[i,u]. */
  5154. void
  5155. OP_B_10 (void)
  5156. {
  5157. trace_input ("cinv[i,u]", OP_VOID, OP_VOID, OP_VOID);
  5158. SET_PSR_I (1);
  5159. trace_output_void ();
  5160. }
  5161. /* cinv[d]. */
  5162. void
  5163. OP_C_10 (void)
  5164. {
  5165. trace_input ("cinv[d]", OP_VOID, OP_VOID, OP_VOID);
  5166. SET_PSR_I (1);
  5167. trace_output_void ();
  5168. }
  5169. /* cinv[d,u]. */
  5170. void
  5171. OP_D_10 (void)
  5172. {
  5173. trace_input ("cinv[i,u]", OP_VOID, OP_VOID, OP_VOID);
  5174. SET_PSR_I (1);
  5175. trace_output_void ();
  5176. }
  5177. /* cinv[d,i]. */
  5178. void
  5179. OP_E_10 (void)
  5180. {
  5181. trace_input ("cinv[d,i]", OP_VOID, OP_VOID, OP_VOID);
  5182. SET_PSR_I (1);
  5183. trace_output_void ();
  5184. }
  5185. /* cinv[d,i,u]. */
  5186. void
  5187. OP_F_10 (void)
  5188. {
  5189. trace_input ("cinv[d,i,u]", OP_VOID, OP_VOID, OP_VOID);
  5190. SET_PSR_I (1);
  5191. trace_output_void ();
  5192. }
  5193. /* retx. */
  5194. void
  5195. OP_3_10 (void)
  5196. {
  5197. trace_input ("retx", OP_VOID, OP_VOID, OP_VOID);
  5198. SET_PSR_I (1);
  5199. trace_output_void ();
  5200. }
  5201. /* di. */
  5202. void
  5203. OP_4_10 (void)
  5204. {
  5205. trace_input ("di", OP_VOID, OP_VOID, OP_VOID);
  5206. SET_PSR_I (1);
  5207. trace_output_void ();
  5208. }
  5209. /* ei. */
  5210. void
  5211. OP_5_10 (void)
  5212. {
  5213. trace_input ("ei", OP_VOID, OP_VOID, OP_VOID);
  5214. SET_PSR_I (1);
  5215. trace_output_void ();
  5216. }
  5217. /* wait. */
  5218. void
  5219. OP_6_10 (void)
  5220. {
  5221. trace_input ("wait", OP_VOID, OP_VOID, OP_VOID);
  5222. State.exception = SIGTRAP;
  5223. trace_output_void ();
  5224. }
  5225. /* ewait. */
  5226. void
  5227. OP_7_10 (void)
  5228. {
  5229. trace_input ("ewait", OP_VOID, OP_VOID, OP_VOID);
  5230. SET_PSR_I (1);
  5231. trace_output_void ();
  5232. }
  5233. /* xorb. */
  5234. void
  5235. OP_28_8 (void)
  5236. {
  5237. uint8 tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
  5238. trace_input ("xorb", OP_CONSTANT4, OP_REG, OP_VOID);
  5239. tmp = a ^ b;
  5240. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  5241. trace_output_16 (tmp);
  5242. }
  5243. /* xorb. */
  5244. void
  5245. OP_28B_C (void)
  5246. {
  5247. uint8 tmp, a = (OP[0]) & 0xff, b = (GPR (OP[1])) & 0xff;
  5248. trace_input ("xorb", OP_CONSTANT16, OP_REG, OP_VOID);
  5249. tmp = a ^ b;
  5250. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  5251. trace_output_16 (tmp);
  5252. }
  5253. /* xorb. */
  5254. void
  5255. OP_29_8 (void)
  5256. {
  5257. uint8 tmp, a = (GPR (OP[0])) & 0xff, b = (GPR (OP[1])) & 0xff;
  5258. trace_input ("xorb", OP_REG, OP_REG, OP_VOID);
  5259. tmp = a ^ b;
  5260. SET_GPR (OP[1], (tmp | ((GPR (OP[1])) & 0xff00)));
  5261. trace_output_16 (tmp);
  5262. }
  5263. /* xorw. */
  5264. void
  5265. OP_2A_8 (void)
  5266. {
  5267. uint16 tmp, a = (OP[0]), b = (GPR (OP[1]));
  5268. trace_input ("xorw", OP_CONSTANT4, OP_REG, OP_VOID);
  5269. tmp = a ^ b;
  5270. SET_GPR (OP[1], tmp);
  5271. trace_output_16 (tmp);
  5272. }
  5273. /* xorw. */
  5274. void
  5275. OP_2AB_C (void)
  5276. {
  5277. uint16 tmp, a = (OP[0]), b = (GPR (OP[1]));
  5278. trace_input ("xorw", OP_CONSTANT16, OP_REG, OP_VOID);
  5279. tmp = a ^ b;
  5280. SET_GPR (OP[1], tmp);
  5281. trace_output_16 (tmp);
  5282. }
  5283. /* xorw. */
  5284. void
  5285. OP_2B_8 (void)
  5286. {
  5287. uint16 tmp, a = (GPR (OP[0])), b = (GPR (OP[1]));
  5288. trace_input ("xorw", OP_REG, OP_REG, OP_VOID);
  5289. tmp = a ^ b;
  5290. SET_GPR (OP[1], tmp);
  5291. trace_output_16 (tmp);
  5292. }
  5293. /*REVISIT FOR LPR/SPR . */
  5294. /* lpr. */
  5295. void
  5296. OP_140_14 (void)
  5297. {
  5298. uint16 a = GPR (OP[0]);
  5299. trace_input ("lpr", OP_REG, OP_REG, OP_VOID);
  5300. SET_CREG (OP[1], a);
  5301. trace_output_16 (a);
  5302. }
  5303. /* lprd. */
  5304. void
  5305. OP_141_14 (void)
  5306. {
  5307. uint32 a = GPR32 (OP[0]);
  5308. trace_input ("lprd", OP_REGP, OP_REG, OP_VOID);
  5309. SET_CREG (OP[1], a);
  5310. trace_output_flag ();
  5311. }
  5312. /* spr. */
  5313. void
  5314. OP_142_14 (void)
  5315. {
  5316. uint16 a = CREG (OP[0]);
  5317. trace_input ("spr", OP_REG, OP_REG, OP_VOID);
  5318. SET_GPR (OP[1], a);
  5319. trace_output_16 (a);
  5320. }
  5321. /* sprd. */
  5322. void
  5323. OP_143_14 (void)
  5324. {
  5325. uint32 a = CREG (OP[0]);
  5326. trace_input ("sprd", OP_REGP, OP_REGP, OP_VOID);
  5327. SET_GPR32 (OP[1], a);
  5328. trace_output_32 (a);
  5329. }
  5330. /* null. */
  5331. void
  5332. OP_0_20 (void)
  5333. {
  5334. trace_input ("null", OP_VOID, OP_VOID, OP_VOID);
  5335. State.exception = SIG_CR16_STOP;
  5336. }