1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367 |
- /*++
- Copyright (c) 2014 Minoca Corp.
- This file is licensed under the terms of the GNU General Public License
- version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details. See the LICENSE file at the root of this
- project for complete licensing information.
- Module Name:
- thm32dis.c
- Abstract:
- This module implements support for disassembling 32-bit Thumb-2
- instructions.
- Author:
- Evan Green 27-Apr-2014
- Environment:
- Debug
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include "dbgrtl.h"
- #include "disasm.h"
- #include "armdis.h"
- #include "thmdis.h"
- #include <assert.h>
- #include <string.h>
- #include <stdio.h>
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- VOID
- DbgpThumb32DecodeLoadStoreMultiple (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeLoadStoreDualExclusive (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeLdrexStrex (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeLdrdStrd (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeLoadStoreExclusiveFunkySize (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeTableBranch (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeDataProcessingShiftedRegister (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeCoprocessorSimdFloatingPoint (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeUndefined (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeSimdDataProcessing (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeDataModifiedImmediate (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeDataPlainImmediate (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeBranchAndMiscellaneous (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeMsr (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeCpsAndHints (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeMiscellaneousControl (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeBxj (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeExceptionReturn (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeMrs (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeHvc (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeSmc (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeBranch (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeUdf (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeBranchWithLink (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeLoadStoreSingleItem (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeLoadStoreImmediate (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeLoadStoreRegister (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeDataProcessingRegister (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeMultiplyAccumulate (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumb32DecodeLongMultiplyDivide (
- PARM_DISASSEMBLY Context
- );
- VOID
- DbgpThumbDecodeImmediateShift (
- PSTR Destination,
- ULONG DestinationSize,
- ULONG Register,
- ULONG Type,
- ULONG Immediate
- );
- ULONG
- DbgpThumb32DecodeModifiedImmediate (
- ULONG Immediate12
- );
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // Define mnemonic tables.
- //
- PSTR DbgThumb32DataProcessingMnemonics[2][16] = {
- {
- "and.w",
- "bic.w",
- "orr.w",
- "orn.w",
- "eor.w",
- "",
- "",
- "",
- "add.w",
- "",
- "adc.w",
- "sbc.w",
- "",
- "sub.w",
- "rsb.w",
- "",
- },
- {
- "ands.w",
- "bics.w",
- "orrs.w",
- "orns.w",
- "eors.w",
- "",
- "",
- "",
- "adds.w",
- "",
- "adcs.w",
- "sbcs.w",
- "",
- "subs.w",
- "rsbs.w",
- "",
- },
- };
- PSTR DbgThumb32DataProcessingShiftMnemonics[2][5] = {
- {
- "lsl.w",
- "lsr.w",
- "asr.w",
- "ror.w",
- "rrx.w"
- },
- {
- "lsls.w",
- "lsrs.w",
- "asrs.w",
- "rors.w",
- "rrxs.w"
- }
- };
- PSTR DbgThumb32MovMnemonics[2] = {
- "mov.w",
- "movs.w"
- };
- PSTR DbgThumb32MvnwMnemonics[2] = {
- "mvn.w",
- "mvns.w"
- };
- PSTR DbgThumb32HintMnemonics[] = {
- "nop.w",
- "yield.w",
- "wfe.w",
- "wfi.w",
- "sev.w"
- };
- PSTR DbgThumb32LoadStoreMnemonics[2][4] = {
- {
- "strb.w",
- "strh.w",
- "str.w",
- "Undef str.w"
- },
- {
- "ldrb.w",
- "ldrh.w",
- "ldr.w",
- "Undef ldr.w"
- }
- };
- PSTR DbgThumb32LoadSetFlagsMnemonics[4] = {
- "ldsrb.w",
- "ldrsh.w",
- "ldrs.w",
- "Undef ldrs.w"
- };
- PSTR DbgThumb32LoadStoreUnprivilegedMnemonics[2][4] = {
- {
- "strbt",
- "strht",
- "strt",
- "Undef strt"
- },
- {
- "ldrbt",
- "ldrht",
- "ldrt",
- "Undef ldrt"
- }
- };
- PSTR DbgThumb32LoadSetFlagsUnprivilegedMnemonics[4] = {
- "ldrsbt",
- "ldrsht",
- "ldrst",
- "Undef ldrst"
- };
- PSTR DbgThumb32PreloadMnemonics[4] = {
- "pli",
- "pldw",
- "pld",
- "Undef pld"
- };
- PSTR DbgThumb32ExtendAndAddMnemonics[2][6] = {
- {
- "sxtah",
- "uxtah",
- "sxtab16",
- "uxtab16",
- "sxtab",
- "uxtab"
- },
- {
- "sxth",
- "uxth",
- "sxtb16",
- "uxtb16",
- "sxtb",
- "uxtb"
- }
- };
- PSTR DbgThumb32ParallelArithmeticMnemonics[2][24] = {
- {
- "sadd8",
- "sadd16",
- "sasx",
- "",
- "ssub8",
- "ssub16",
- "ssax",
- "",
- "qadd8",
- "qadd16",
- "qasx",
- "",
- "qsub8",
- "qsub16",
- "qsax",
- "",
- "shadd8",
- "shadd16",
- "shasx",
- "",
- "shsub8",
- "shsub16",
- "shsax",
- "",
- },
- {
- "uadd8",
- "uadd16",
- "uasx",
- "",
- "usub8",
- "usub16",
- "usax",
- "",
- "uqadd8",
- "uqadd16",
- "uqasx",
- "",
- "uqsub8",
- "uqsub16",
- "uqsax",
- "",
- "uhadd8",
- "uhadd16",
- "uhasx",
- "",
- "uhsub8",
- "uhsub16",
- "uhsax",
- "",
- },
- };
- PSTR DbgThumb32DataProcessingMiscellaneousMnemonics[] = {
- "qadd",
- "qdadd",
- "qsub",
- "qdsub",
- "rev.w",
- "rev16.w",
- "rbit",
- "revsh.w",
- "sel",
- "",
- "",
- "",
- "clz",
- "",
- "",
- ""
- };
- PSTR DbgThumb32MultiplyMnemonics[2][8] = {
- {
- "mla",
- "smla",
- "smlad",
- "smlaw",
- "smlsd",
- "smmla",
- "smmls",
- "usada8"
- },
- {
- "mul",
- "smul",
- "smuad",
- "smulw",
- "smusd",
- "smmul",
- "smmls",
- "usad8"
- }
- };
- PSTR DbgThumb32MultiplyTopBottomMnemonics[2] = {
- "b",
- "t",
- };
- PSTR DbgThumb32LongMultiplyMnemonics[8] = {
- "smull",
- "sdiv",
- "umull",
- "udiv",
- "smlal",
- "smlsld",
- "umlal",
- ""
- };
- //
- // Define decode tables.
- //
- THUMB_DECODE_BRANCH DbgThumb32TopLevelTable[] = {
- {0x1E400000, 0x08000000, 0, DbgpThumb32DecodeLoadStoreMultiple},
- {0x1E400000, 0x08400000, 0, DbgpThumb32DecodeLoadStoreDualExclusive},
- {0x1E000000, 0x0A000000, 0, DbgpThumb32DecodeDataProcessingShiftedRegister},
- {0x1C000000, 0x0C000000, 0, DbgpThumb32DecodeCoprocessorSimdFloatingPoint},
- {0x1A008000, 0x10000000, 0, DbgpThumb32DecodeDataModifiedImmediate},
- {0x1A008000, 0x12000000, 0, DbgpThumb32DecodeDataPlainImmediate},
- {0x18008000, 0x10008000, 0, DbgpThumb32DecodeBranchAndMiscellaneous},
- {0x1F100000, 0x18000000, 0, DbgpThumb32DecodeLoadStoreSingleItem},
- {0x1E700000, 0x18100000, 0, DbgpThumb32DecodeLoadStoreSingleItem},
- {0x1E700000, 0x18300000, 0, DbgpThumb32DecodeLoadStoreSingleItem},
- {0x1E700000, 0x18500000, 0, DbgpThumb32DecodeLoadStoreSingleItem},
- {0x1E700000, 0x18700000, 0, DbgpThumb32DecodeUndefined},
- {0x1F100000, 0x19000000, 0, DbgpArmDecodeSimdElementLoadStore},
- {0x1F000000, 0x1A000000, 0, DbgpThumb32DecodeDataProcessingRegister},
- {0x1F800000, 0x1B000000, 0, DbgpThumb32DecodeMultiplyAccumulate},
- {0x1F800000, 0x1B800000, 0, DbgpThumb32DecodeLongMultiplyDivide},
- {0x1C000000, 0x1C000000, 0, DbgpThumb32DecodeCoprocessorSimdFloatingPoint},
- };
- THUMB_DECODE_BRANCH DbgThumb32LoadStoreDualExclusiveTable[] = {
- {0x01B00000, 0x00000000, 0, DbgpThumb32DecodeLdrexStrex},
- {0x01B00000, 0x00100000, 0, DbgpThumb32DecodeLdrexStrex},
- {0x01300000, 0x00200000, 0, DbgpThumb32DecodeLdrdStrd},
- {0x01100000, 0x01000000, 0, DbgpThumb32DecodeLdrdStrd},
- {0x01300000, 0x00300000, 0, DbgpThumb32DecodeLdrdStrd},
- {0x01100000, 0x01100000, 0, DbgpThumb32DecodeLdrdStrd},
- {0x01B000F0, 0x00800040, 0, DbgpThumb32DecodeLoadStoreExclusiveFunkySize},
- {0x01B000F0, 0x00800050, 0, DbgpThumb32DecodeLoadStoreExclusiveFunkySize},
- {0x01B000F0, 0x00800070, 0, DbgpThumb32DecodeLoadStoreExclusiveFunkySize},
- {0x01B000F0, 0x00900000, 0, DbgpThumb32DecodeTableBranch},
- {0x01B000F0, 0x00900010, 0, DbgpThumb32DecodeTableBranch},
- {0x01B000F0, 0x00900040, 0, DbgpThumb32DecodeLoadStoreExclusiveFunkySize},
- {0x01B000F0, 0x00900050, 0, DbgpThumb32DecodeLoadStoreExclusiveFunkySize},
- {0x01B000F0, 0x00900070, 0, DbgpThumb32DecodeLoadStoreExclusiveFunkySize},
- };
- THUMB_DECODE_BRANCH DbgThumb32CoprocessorSimdFloatingPointTable[] = {
- {0x03E00000, 0x00000000, 0, DbgpThumb32DecodeUndefined},
- {0x03000000, 0x03000000, 0, DbgpThumb32DecodeSimdDataProcessing},
- {0x03E00E00, 0x00400A00, 0, DbgpArmDecodeSimd64BitTransfers},
- {0x02000E00, 0x00000A00, 0, DbgpArmDecodeSimdLoadStore},
- {0x03000E10, 0x02000A00, 0, DbgpArmDecodeFloatingPoint},
- {0x03000E10, 0x02000A10, 0, DbgpArmDecodeSimdSmallTransfers},
- {0x03E00000, 0x00400000, 0, DbgpArmDecodeCoprocessorMoveTwo},
- {0x02000000, 0x00000000, 0, DbgpArmDecodeCoprocessorLoadStore},
- {0x03000010, 0x02000000, 0, DbgpArmDecodeCoprocessorMove},
- {0x03000010, 0x02000010, 0, DbgpArmDecodeCoprocessorMove},
- };
- THUMB_DECODE_BRANCH DbgThumb32BranchAndMiscellaneousTable[] = {
- {0x07E05000, 0x03800000, 0, DbgpThumb32DecodeMsr},
- {0x07F05000, 0x03A00000, 0, DbgpThumb32DecodeCpsAndHints},
- {0x07F05000, 0x03B00000, 0, DbgpThumb32DecodeMiscellaneousControl},
- {0x07F05000, 0x03C00000, 0, DbgpThumb32DecodeBxj},
- {0x07F05000, 0x03D00000, 0, DbgpThumb32DecodeExceptionReturn},
- {0x07E05000, 0x03E00000, 0, DbgpThumb32DecodeMrs},
- {0x07F07000, 0x07E00000, 0, DbgpThumb32DecodeHvc},
- {0x07F07000, 0x07F00000, 0, DbgpThumb32DecodeSmc},
- {0x00005000, 0x00001000, 0, DbgpThumb32DecodeBranch},
- {0x00005000, 0x00000000, 0, DbgpThumb32DecodeBranch},
- {0x07F07000, 0x07F02000, 0, DbgpThumb32DecodeUdf},
- {0x00004000, 0x00004000, 0, DbgpThumb32DecodeBranchWithLink},
- };
- //
- // ------------------------------------------------------------------ Functions
- //
- VOID
- DbgpThumb32Decode (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the 32-bit portion of the Thumb-2 instruction set.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- //
- // Swap the half words, then decode using the table.
- //
- Context->Instruction = ((Context->Instruction << 16) & 0xFFFF0000) |
- ((Context->Instruction >> 16) & 0x0000FFFF);
- THUMB_DECODE_WITH_TABLE(Context, DbgThumb32TopLevelTable);
- return;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
- VOID
- DbgpThumb32DecodeLoadStoreMultiple (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the 32-bit load/store multiple instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- ULONG Mode;
- ULONG Op;
- ULONG RegisterList;
- ULONG Rn;
- Instruction = Context->Instruction;
- Op = (Instruction >> THUMB32_LOAD_STORE_MULTIPLE_OP_SHIFT) &
- THUMB32_LOAD_STORE_MULTIPLE_OP_MASK;
- Rn = (Instruction >> THUMB32_LOAD_STORE_MULTIPLE_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- //
- // The instruction is either rfe/srs, or ldm/stm.
- //
- switch (Op) {
- case THUMB32_LOAD_STORE_RETURN_STATE_OP:
- case THUMB32_LOAD_STORE_RETURN_STATE_OP2:
- Mode = Instruction & THUMB32_LOAD_STORE_MODE_MASK;
- if ((Instruction & THUMB32_LOAD_BIT) != 0) {
- strcpy(Context->Mnemonic, THUMB_RFE_MNEMONIC);
- } else {
- strcpy(Context->Mnemonic, THUMB_SRS_MNEMONIC);
- DbgpArmPrintMode(Context->Operand2, Mode);
- }
- break;
- case THUMB32_LOAD_STORE_MULTIPLE_OP:
- case THUMB32_LOAD_STORE_MULTIPLE_OP2:
- default:
- if ((Instruction & THUMB32_LOAD_BIT) != 0) {
- strcpy(Context->Mnemonic, THUMB_LDM_MNEMONIC);
- } else {
- strcpy(Context->Mnemonic, THUMB_STM_MNEMONIC);
- }
- RegisterList = Instruction & THUMB_REGISTER16_LIST;
- DbgpArmDecodeRegisterList(Context->Operand2,
- sizeof(Context->Operand2),
- RegisterList);
- break;
- }
- //
- // Add the decrement-before or increment-after suffix.
- //
- if ((Instruction & THUMB32_LOAD_STORE_INCREMENT) != 0) {
- strcat(Context->Mnemonic, THUMB_IA_SUFFIX);
- } else {
- strcat(Context->Mnemonic, THUMB_DB_SUFFIX);
- }
- //
- // Print operand one, the register.
- //
- if ((Instruction & THUMB32_LOAD_STORE_MULTIPLE_WRITE_BACK_BIT) != 0) {
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "%s!",
- DbgArmRegisterNames[Rn]);
- } else {
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeLoadStoreDualExclusive (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the 32-bit load/store dual, load/store exclusive,
- and table branch instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- THUMB_DECODE_WITH_TABLE(Context, DbgThumb32LoadStoreDualExclusiveTable);
- return;
- }
- VOID
- DbgpThumb32DecodeLdrexStrex (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the 32-bit load/store exclusive (32-bit data)
- instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate8;
- ULONG Instruction;
- ULONG Rd;
- ULONG Rn;
- PSTR RnOperand;
- ULONG Rt;
- PSTR RtOperand;
- Instruction = Context->Instruction;
- Rd = (Instruction >> THUMB32_EXCLUSIVE_RD_SHIFT) & THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_EXCLUSIVE_RN_SHIFT) & THUMB_REGISTER16_MASK;
- Rt = (Instruction >> THUMB32_EXCLUSIVE_RT_SHIFT) & THUMB_REGISTER16_MASK;
- Immediate8 = (Instruction >> THUMB32_EXCLUSIVE_IMMEDIATE8_SHIFT) &
- THUMB_IMMEDIATE8_MASK;
- Immediate8 <<= 2;
- if ((Instruction & THUMB32_LOAD_BIT) != 0) {
- strcpy(Context->Mnemonic, THUMB_LDREX_MNEMONIC);
- RtOperand = &(Context->Operand1[0]);
- RnOperand = &(Context->Operand2[0]);
- } else {
- strcpy(Context->Mnemonic, THUMB_STREX_MNEMONIC);
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- RtOperand = &(Context->Operand2[0]);
- RnOperand = &(Context->Operand3[0]);
- }
- strcpy(RtOperand, DbgArmRegisterNames[Rt]);
- if (Immediate8 == 0) {
- sprintf(RnOperand, "[%s]", DbgArmRegisterNames[Rn]);
- } else {
- sprintf(RnOperand,
- "[%s, #%d]",
- DbgArmRegisterNames[Rn],
- Immediate8 * 4);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeLdrdStrd (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the 32-bit load/store dual (64-bit data).
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate8;
- ULONG Instruction;
- ULONG Rn;
- ULONG Rt;
- ULONG Rt2;
- Instruction = Context->Instruction;
- if ((Instruction & THUMB32_LOAD_BIT) != 0) {
- strcpy(Context->Mnemonic, THUMB_LDRD_MNEMONIC);
- } else {
- strcpy(Context->Mnemonic, THUMB_STRD_MNEMONIC);
- }
- Rn = (Instruction >> THUMB32_DUAL_RN_SHIFT) & THUMB_REGISTER16_MASK;
- Rt = (Instruction >> THUMB32_DUAL_RT_SHIFT) & THUMB_REGISTER16_MASK;
- Rt2 = (Instruction >> THUMB32_DUAL_RT2_SHIFT) & THUMB_REGISTER16_MASK;
- Immediate8 = Instruction & THUMB_IMMEDIATE8_MASK;
- Immediate8 <<= 2;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rt]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rt2]);
- if ((Instruction & THUMB32_PREINDEX_BIT) != 0) {
- if ((Instruction & THUMB32_WRITE_BACK_BIT) != 0) {
- snprintf(Context->Operand3,
- sizeof(Context->Operand3),
- "[%s, #%d]!",
- DbgArmRegisterNames[Rn],
- Immediate8);
- } else {
- if (Immediate8 != 0) {
- snprintf(Context->Operand3,
- sizeof(Context->Operand3),
- "[%s, #%d]",
- DbgArmRegisterNames[Rn],
- Immediate8);
- } else {
- snprintf(Context->Operand3,
- sizeof(Context->Operand3),
- "[%s]",
- DbgArmRegisterNames[Rn]);
- }
- }
- //
- // If pre-index is not set, then update is assumed to be set.
- //
- } else {
- snprintf(Context->Operand3,
- sizeof(Context->Operand3),
- "[%s] #%d",
- DbgArmRegisterNames[Rn],
- Immediate8);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeLoadStoreExclusiveFunkySize (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the 32-bit load/store exclusive instructions for
- non-native sizes (8, 16 and 64 bits).
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- PSTR Mnemonic;
- ULONG Op;
- ULONG Rd;
- ULONG Rn;
- PSTR RnRegister;
- ULONG Rt;
- ULONG Rt2;
- Instruction = Context->Instruction;
- Rd = (Instruction >> THUMB32_EXCLUSIVE_FUNKY_RD_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_EXCLUSIVE_FUNKY_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rt = (Instruction >> THUMB32_EXCLUSIVE_FUNKY_RT_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rt2 = (Instruction >> THUMB32_EXCLUSIVE_FUNKY_RT2_SHIFT) &
- THUMB_REGISTER16_MASK;
- //
- // Get the mnemonic. Load instructions look like ldr Rt, [Rn]. Store
- // instructions look like str Rd, Rt, [Rn]. Dual instructions stick Rt2
- // after Rt.
- //
- Op = (Instruction >> THUMB32_EXCLUSIVE_FUNKY_OP_SHIFT) &
- THUMB32_EXCLUSIVE_FUNKY_OP_MASK;
- if ((Instruction & THUMB32_LOAD_BIT) != 0) {
- strcpy(Context->Operand1, DbgArmRegisterNames[Rt]);
- RnRegister = &(Context->Operand2[0]);
- if (Op == THUMB32_EXCLUSIVE_FUNKY_OP_BYTE) {
- Mnemonic = THUMB_LDREXB_MNEMONIC;
- } else if (Op == THUMB32_EXCLUSIVE_FUNKY_OP_HALF_WORD) {
- Mnemonic = THUMB_LDREXH_MNEMONIC;
- } else {
- assert(Op == THUMB32_EXCLUSIVE_FUNKY_OP_DUAL);
- Mnemonic = THUMB_LDREXD_MNEMONIC;
- strcpy(Context->Operand2, DbgArmRegisterNames[Rt2]);
- RnRegister = &(Context->Operand3[0]);
- }
- } else {
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rt]);
- RnRegister = &(Context->Operand3[0]);
- if (Op == THUMB32_EXCLUSIVE_FUNKY_OP_BYTE) {
- Mnemonic = THUMB_STREXB_MNEMONIC;
- } else if (Op == THUMB32_EXCLUSIVE_FUNKY_OP_HALF_WORD) {
- Mnemonic = THUMB_STREXH_MNEMONIC;
- } else {
- assert(Op == THUMB32_EXCLUSIVE_FUNKY_OP_DUAL);
- Mnemonic = THUMB_STREXD_MNEMONIC;
- strcpy(Context->Operand3, DbgArmRegisterNames[Rt2]);
- RnRegister = &(Context->Operand4[0]);
- }
- }
- strcpy(Context->Mnemonic, Mnemonic);
- sprintf(RnRegister, "[%s]", DbgArmRegisterNames[Rn]);
- return;
- }
- VOID
- DbgpThumb32DecodeTableBranch (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the 32-bit load/store exclusive instructions for
- non-native sizes (8, 16 and 64 bits).
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- ULONG Rm;
- ULONG Rn;
- Instruction = Context->Instruction;
- Rm = (Instruction >> THUMB32_TABLE_BRANCH_RM_SHIFT) & THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_TABLE_BRANCH_RN_SHIFT) & THUMB_REGISTER16_MASK;
- if ((Instruction & THUMB32_TABLE_BRANCH_HALF_WORD) != 0) {
- strcpy(Context->Mnemonic, THUMB_TBH_MNEMONIC);
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "[%s, %s, lsl #1]",
- DbgArmRegisterNames[Rn],
- DbgArmRegisterNames[Rm]);
- } else {
- strcpy(Context->Mnemonic, THUMB_TBB_MNEMONIC);
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "[%s, %s]",
- DbgArmRegisterNames[Rn],
- DbgArmRegisterNames[Rm]);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeDataProcessingShiftedRegister (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the 32-bit data processing (shifted register)
- instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate5;
- ULONG Instruction;
- PSTR Mnemonic;
- ULONG Op;
- ULONG Rd;
- ULONG Rm;
- ULONG Rn;
- ULONG SetFlags;
- BOOL StandardParameters;
- ULONG Type;
- Instruction = Context->Instruction;
- Rd = (Instruction >> THUMB32_DATA_SHIFTED_REGISTER_RD_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rm = (Instruction >> THUMB32_DATA_SHIFTED_REGISTER_RM_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_DATA_SHIFTED_REGISTER_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- Type = (Instruction >> THUMB32_DATA_SHIFTED_REGISTER_TYPE_SHIFT) &
- THUMB32_DATA_SHIFTED_REGISTER_TYPE_MASK;
- Immediate5 = (Instruction >>
- THUMB32_DATA_SHIFTED_REGISTER_IMMEDIATE2_SHIFT) &
- THUMB32_DATA_SHIFTED_REGISTER_IMMEDIATE2_MASK;
- Immediate5 |= ((Instruction >>
- THUMB32_DATA_SHIFTED_REGISTER_IMMEDIATE3_SHIFT) &
- THUMB32_DATA_SHIFTED_REGISTER_IMMEDIATE3_MASK) << 2;
- SetFlags = Instruction & THUMB32_DATA_SET_FLAGS;
- Op = (Instruction >> THUMB32_DATA_SHIFTED_REGISTER_OP_SHIFT) &
- THUMB32_DATA_SHIFTED_REGISTER_OP_MASK;
- StandardParameters = TRUE;
- if (SetFlags != 0) {
- SetFlags = 1;
- }
- //
- // This decoding follows a standard pattern, but there are several
- // exceptions that kick in when 1111 is specified for one of the registers.
- // The exceptions are listed below in this switch statement.
- //
- Mnemonic = DbgThumb32DataProcessingMnemonics[SetFlags][Op];
- switch (Op) {
- case THUMB32_DATA_AND:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = THUMB_TST_W_MNEMONIC;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- DbgpThumbDecodeImmediateShift(Context->Operand2,
- sizeof(Context->Operand2),
- Rm,
- Type,
- Immediate5);
- }
- break;
- case THUMB32_DATA_ORR:
- if (Rn == 0xF) {
- StandardParameters = FALSE;
- Mnemonic = DbgThumb32DataProcessingShiftMnemonics[SetFlags][Type];
- switch (Type) {
- case THUMB_SHIFT_TYPE_LSL:
- if (Immediate5 == 0) {
- Mnemonic = DbgThumb32MovMnemonics[SetFlags];
- }
- break;
- case THUMB_SHIFT_TYPE_ROR:
- if (Immediate5 == 0) {
- Type += 1;
- Mnemonic =
- DbgThumb32DataProcessingShiftMnemonics[SetFlags][Type];
- }
- break;
- default:
- break;
- }
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rm]);
- if (Immediate5 != 0) {
- snprintf(Context->Operand3,
- sizeof(Context->Operand3),
- "#%d",
- Immediate5);
- }
- }
- break;
- case THUMB32_DATA_ORN:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = DbgThumb32MvnwMnemonics[SetFlags];
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- DbgpThumbDecodeImmediateShift(Context->Operand2,
- sizeof(Context->Operand2),
- Rm,
- Type,
- Immediate5);
- }
- break;
- case THUMB32_DATA_EOR:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = THUMB_TEQ_W_MNEMONIC;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- DbgpThumbDecodeImmediateShift(Context->Operand2,
- sizeof(Context->Operand2),
- Rm,
- Type,
- Immediate5);
- }
- break;
- case THUMB32_DATA_PKH:
- Type &= ~0x1;
- Mnemonic = THUMB_PKHBT_MNEMONIC;
- if ((Instruction & THUMB32_PACK_HALF_WORD_TB) != 0) {
- Mnemonic = THUMB_PKHTB_MNEMONIC;
- }
- break;
- case THUMB32_DATA_ADD:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = THUMB_CMN_W_MNEMONIC;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- DbgpThumbDecodeImmediateShift(Context->Operand2,
- sizeof(Context->Operand2),
- Rm,
- Type,
- Immediate5);
- }
- break;
- case THUMB32_DATA_SUB:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = THUMB_CMP_W_MNEMONIC;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- DbgpThumbDecodeImmediateShift(Context->Operand2,
- sizeof(Context->Operand2),
- Rm,
- Type,
- Immediate5);
- }
- break;
- default:
- break;
- }
- strcpy(Context->Mnemonic, Mnemonic);
- //
- // If the switch statement didn't apply, copy in the regular parameters.
- // The pack half-word is a special case, it changed the opcode but still
- // follows the standard parameters.
- //
- if (StandardParameters != FALSE) {
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- DbgpThumbDecodeImmediateShift(Context->Operand3,
- sizeof(Context->Operand3),
- Rm,
- Type,
- Immediate5);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeCoprocessorSimdFloatingPoint (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes coprocessor, advanced SIMD, and floating point
- instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- THUMB_DECODE_WITH_TABLE(Context,
- DbgThumb32CoprocessorSimdFloatingPointTable);
- return;
- }
- VOID
- DbgpThumb32DecodeUndefined (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine catches undefined corners of the instruction space.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- strcpy(Context->Mnemonic, "Undefined");
- return;
- }
- VOID
- DbgpThumb32DecodeSimdDataProcessing (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes SIMD data processing instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- //
- // The 32-bit Thumb instruction and the ARM instruction only differ by one
- // bit. Move the bit in ths 32-bit Thumb instruction and use the ARM
- // decoder.
- //
- Instruction = Context->Instruction;
- if ((Instruction & THUMB32_SIMD_DATA_PROCESSING_UNSIGNED) != 0) {
- Context->Instruction |= ARM_SIMD_DATA_PROCESSING_UNSIGNED;
- } else {
- Context->Instruction &= ~ARM_SIMD_DATA_PROCESSING_UNSIGNED;
- }
- DbgpArmDecodeSimdDataProcessing(Context);
- Context->Instruction = Instruction;
- return;
- }
- VOID
- DbgpThumb32DecodeDataModifiedImmediate (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes data processing (modified immediate) instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate12;
- ULONG Instruction;
- PSTR Mnemonic;
- ULONG ModifiedImmediate;
- ULONG Op;
- ULONG Rd;
- ULONG Rn;
- ULONG SetFlags;
- BOOL StandardParameters;
- Instruction = Context->Instruction;
- Immediate12 = (Instruction >>
- THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE8_SHIFT) &
- THUMB_IMMEDIATE8_MASK;
- Immediate12 |= ((Instruction >>
- THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE3_SHIFT) &
- THUMB_IMMEDIATE3_MASK) << 8;
- if ((Instruction & THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE12) != 0) {
- Immediate12 |= 1 << 11;
- }
- Rd = (Instruction >> THUMB32_DATA_MODIFIED_IMMEDIATE_RD_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_DATA_MODIFIED_IMMEDIATE_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- SetFlags = 0;
- if ((Instruction & THUMB32_DATA_SET_FLAGS) != 0) {
- SetFlags = 1;
- }
- Op = (Instruction >> THUMB32_DATA_MODIFIED_IMMEDIATE_OP_SHIFT) &
- THUMB32_DATA_MODIFIED_IMMEDIATE_OP_MASK;
- ModifiedImmediate = DbgpThumb32DecodeModifiedImmediate(Immediate12);
- StandardParameters = TRUE;
- Mnemonic = DbgThumb32DataProcessingMnemonics[SetFlags][Op];
- switch (Op) {
- case THUMB32_DATA_AND:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = THUMB_TST_W_MNEMONIC;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "#%d",
- ModifiedImmediate);
- }
- break;
- case THUMB32_DATA_ORR:
- if (Rn == 0xF) {
- StandardParameters = FALSE;
- Mnemonic = DbgThumb32MovMnemonics[SetFlags];
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "#%d",
- ModifiedImmediate);
- }
- break;
- case THUMB32_DATA_ORN:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = DbgThumb32MvnwMnemonics[SetFlags];
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "#%d",
- ModifiedImmediate);
- }
- break;
- case THUMB32_DATA_EOR:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = THUMB_TEQ_W_MNEMONIC;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "#%d",
- ModifiedImmediate);
- }
- break;
- case THUMB32_DATA_ADD:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = THUMB_CMN_MNEMONIC;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "#%d",
- ModifiedImmediate);
- }
- break;
- case THUMB32_DATA_SUB:
- if ((Rd == 0xF) && (SetFlags != 0)) {
- StandardParameters = FALSE;
- Mnemonic = THUMB_CMP_W_MNEMONIC;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "#%d",
- ModifiedImmediate);
- }
- break;
- default:
- break;
- }
- strcpy(Context->Mnemonic, Mnemonic);
- //
- // If the switch statement didn't apply, copy in the regular parameters.
- // The pack half-word is a special case, it changed the opcode but still
- // follows the standard parameters.
- //
- if (StandardParameters != FALSE) {
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- snprintf(Context->Operand3,
- sizeof(Context->Operand3),
- "#%d",
- ModifiedImmediate);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeDataPlainImmediate (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes data processing (plain Jane immediate) instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate;
- ULONG Immediate12;
- ULONG Immediate3;
- ULONG Immediate5;
- ULONG Instruction;
- PSTR LsbString;
- PSTR Mnemonic;
- PSTR *Mnemonics;
- ULONG Op;
- ULONGLONG OperandAddress;
- ULONG Rd;
- ULONG Rn;
- ULONG SetFlags;
- PSTR ShiftMnemonic;
- LONG SignedImmediate;
- ULONG Width;
- PSTR WidthString;
- Instruction = Context->Instruction;
- Rd = (Instruction >> THUMB32_DATA_PLAIN_IMMEDIATE_RD_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_DATA_PLAIN_IMMEDIATE_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- Op = (Instruction >> THUMB32_DATA_PLAIN_IMMEDIATE_OP_SHIFT) &
- THUMB32_DATA_PLAIN_IMMEDIATE_OP_MASK;
- Immediate3 = (Instruction >>
- THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE3_SHIFT) &
- THUMB_IMMEDIATE3_MASK;
- Immediate5 = (Instruction >>
- THUMB32_DATA_PLAIN_IMMEDIATE_IMMEDIATE2_SHIFT) &
- THUMB_IMMEDIATE2_MASK;
- Immediate5 |= Immediate3 << 2;
- Immediate12 = (Instruction >>
- THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE8_SHIFT) &
- THUMB_IMMEDIATE8_MASK;
- Immediate12 |= Immediate3 << 8;
- if ((Instruction & THUMB32_DATA_MODIFIED_IMMEDIATE_IMMEDIATE12) != 0) {
- Immediate12 |= 1 << 11;
- }
- SetFlags = 0;
- if ((Instruction & THUMB32_DATA_SET_FLAGS) != 0) {
- SetFlags = 1;
- }
- Mnemonic = "Unknown thumb.";
- switch (Op) {
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_ADD:
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_SUB:
- if (Rn == 0xF) {
- Mnemonic = THUMB_ADR_W_MNEMONIC;
- SignedImmediate = Immediate12;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rn]);
- if (Op == THUMB32_DATA_PLAIN_IMMEDIATE_OP_SUB) {
- SignedImmediate = -SignedImmediate;
- }
- //
- // Calculate the operand address. The immediate is relative to the
- // current PC aligned down to a four-byte boundary.
- //
- OperandAddress = Context->InstructionPointer + 4;
- OperandAddress = THUMB_ALIGN_4(OperandAddress);
- OperandAddress += (LONGLONG)SignedImmediate;
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "[0x%08llx]",
- OperandAddress);
- Context->Result->OperandAddress = OperandAddress;
- Context->Result->AddressIsDestination = FALSE;
- Context->Result->AddressIsValid = TRUE;
- } else {
- Mnemonics = DbgThumb32DataProcessingMnemonics[SetFlags];
- if (Op == THUMB32_DATA_PLAIN_IMMEDIATE_OP_ADD) {
- Mnemonic = Mnemonics[THUMB32_DATA_ADD];
- } else {
- Mnemonic = Mnemonics[THUMB32_DATA_SUB];
- }
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- snprintf(Context->Operand3,
- sizeof(Context->Operand3),
- "#%d",
- Immediate12);
- }
- break;
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_MOV:
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_MOVT:
- if (Op == THUMB32_DATA_PLAIN_IMMEDIATE_OP_MOV) {
- Mnemonic = THUMB_MOVW_MNEMONIC;
- } else {
- Mnemonic = THUMB_MOVT_MNEMONIC;
- }
- Immediate = Immediate12 |
- (((Instruction >>
- THUMB32_DATA_PLAIN_IMMEDIATE_IMMEDIATE4_SHIFT) &
- THUMB_IMMEDIATE4_MASK) << 12);
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "#%d",
- Immediate);
- break;
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_SSAT:
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_SSAT16:
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_USAT:
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_USAT16:
- Immediate = (Instruction >>
- THUMB32_DATA_PLAIN_IMMEDIATE_SAT_IMMEDIATE_SHIFT);
- if (Immediate5 == 0) {
- Immediate &= THUMB32_DATA_PLAIN_IMMEDIATE_SAT_IMMEDIATE4_MASK;
- } else {
- Immediate &= THUMB32_DATA_PLAIN_IMMEDIATE_SAT_IMMEDIATE5_MASK;
- }
- if ((Instruction & THUMB32_DATA_PLAIN_IMMEDIATE_UNSIGNED) != 0) {
- if (Immediate5 == 0) {
- Mnemonic = THUMB_USAT16_MNEMONIC;
- } else {
- Mnemonic = THUMB_USAT_MNEMONIC;
- }
- } else {
- if (Immediate5 == 0) {
- Mnemonic = THUMB_SSAT16_MNEMONIC;
- } else {
- Mnemonic = THUMB_SSAT_MNEMONIC;
- }
- Immediate += 1;
- }
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- sprintf(Context->Operand2, "#%d", Immediate);
- strcpy(Context->Operand3, DbgArmRegisterNames[Rn]);
- if (Immediate5 != 0) {
- ShiftMnemonic = ARM_LSL_MNEMONIC;
- if ((Instruction & THUMB32_DATA_PLAIN_IMMEDIATE_SHIFT_RIGHT) != 0) {
- ShiftMnemonic = ARM_ASR_MNEMONIC;
- }
- sprintf(Context->Operand4, "%s #%d", ShiftMnemonic, Immediate5);
- }
- break;
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_BFIC:
- if (Rn == 0xF) {
- Mnemonic = THUMB_BFC_MNEMONIC;
- LsbString = Context->Operand2;
- WidthString = Context->Operand3;
- } else {
- Mnemonic = THUMB_BFI_MNEMONIC;
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- LsbString = Context->Operand3;
- WidthString = Context->Operand4;
- }
- Width = (Instruction >> THUMB32_DATA_PLAIN_IMMEDIATE_MSB_SHIFT) &
- THUMB32_DATA_PLAIN_IMMEDIATE_MSB_MASK;
- Width = Width + 1 - Immediate5;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- sprintf(LsbString, "#%d", Immediate5);
- sprintf(WidthString, "#%d", Width);
- break;
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_SBFX:
- case THUMB32_DATA_PLAIN_IMMEDIATE_OP_UBFX:
- if ((Instruction & THUMB32_DATA_PLAIN_IMMEDIATE_UNSIGNED) != 0) {
- Mnemonic = THUMB_UBFX_MNEMONIC;
- } else {
- Mnemonic = THUMB_SBFX_MNEMONIC;
- }
- Width = (Instruction >>
- THUMB32_DATA_PLAIN_IMMEDIATE_WIDTH_MINUS_1_SHIFT) &
- THUMB32_DATA_PLAIN_IMMEDIATE_WIDTH_MINUS_1_MASK;
- Width += 1;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- sprintf(Context->Operand3, "#%d", Immediate5);
- sprintf(Context->Operand4, "#%d", Width);
- break;
- default:
- break;
- }
- strcpy(Context->Mnemonic, Mnemonic);
- return;
- }
- VOID
- DbgpThumb32DecodeBranchAndMiscellaneous (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes branch and miscellaneous instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- THUMB_DECODE_WITH_TABLE(Context, DbgThumb32BranchAndMiscellaneousTable);
- return;
- }
- VOID
- DbgpThumb32DecodeMsr (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes MSR (move to status from ARM) instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- ULONG Mask;
- ULONG Mode;
- PSTR Register;
- ULONG Rn;
- Instruction = Context->Instruction;
- Rn = (Instruction >> THUMB32_MSR_RN_SHIFT) & THUMB_REGISTER16_MASK;
- strcpy(Context->Mnemonic, THUMB_MSR_MNEMONIC);
- if ((Instruction & THUMB32_MSR_BANKED_REGISTER) != 0) {
- Mode = (Instruction >> THUMB32_MSR_MODE_SHIFT) & THUMB32_MSR_MODE_MASK;
- if ((Instruction & THUMB32_MSR_MODE4) != 0) {
- Mode |= 1 << 4;
- }
- if ((Instruction & THUMB32_MSR_SPSR) != 0) {
- Mode |= 1 << 5;
- }
- strcpy(Context->Operand1, DbgArmBankedRegisters[Mode]);
- } else {
- Mask = (Instruction >> THUMB32_MSR_MASK_SHIFT) & THUMB32_MSR_MASK_MASK;
- Register = THUMB_CPSR_STRING;
- if ((Instruction & THUMB32_MSR_SPSR) != 0) {
- Register = THUMB_SPSR_STRING;
- }
- strcpy(Context->Operand1, Register);
- strcat(Context->Operand1, "_");
- if ((Mask & THUMB32_MSR_MASK_C) != 0) {
- strcat(Context->Operand1, "c");
- }
- if ((Mask & THUMB32_MSR_MASK_X) != 0) {
- strcat(Context->Operand1, "x");
- }
- if ((Mask & THUMB32_MSR_MASK_S) != 0) {
- strcat(Context->Operand1, "s");
- }
- if ((Mask & THUMB32_MSR_MASK_F) != 0) {
- strcat(Context->Operand1, "f");
- }
- }
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- return;
- }
- VOID
- DbgpThumb32DecodeCpsAndHints (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes the CPS (change processor state) instruction, as well
- as memory hints.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG HintOp;
- ULONG Instruction;
- ULONG Mode;
- ULONG Option;
- Instruction = Context->Instruction;
- //
- // If bits 8:6 are zero, then this is CPS.
- //
- if ((Instruction & THUMB32_CPS_MASK) == THUMB32_CPS_VALUE) {
- Mode = Instruction & THUMB32_CPS_MODE_MASK;
- if ((Instruction & THUMB32_CPS_DISABLE) != 0) {
- strcpy(Context->Mnemonic, THUMB_CPS_DISABLE_W_MNEMONIC);
- } else {
- strcpy(Context->Mnemonic, THUMB_CPS_ENABLE_W_MNEMONIC);
- }
- strcpy(Context->Operand1, "");
- if ((Instruction & THUMB32_CPS_FLAG_A) != 0) {
- strcat(Context->Operand1, ARM_CPS_FLAG_A_STRING);
- }
- if ((Instruction & THUMB32_CPS_FLAG_I) != 0) {
- strcat(Context->Operand1, ARM_CPS_FLAG_I_STRING);
- }
- if ((Instruction & THUMB32_CPS_FLAG_F) != 0) {
- strcat(Context->Operand1, ARM_CPS_FLAG_F_STRING);
- }
- if ((Instruction & THUMB32_CPS_CHANGE_MODE) != 0) {
- DbgpArmPrintMode(Context->Operand2, Mode);
- }
- //
- // This is a hint instruction.
- //
- } else {
- HintOp = Instruction & THUMB32_HINT_MASK;
- if ((HintOp & THUMB32_HINT_DBG_MASK) == THUMB32_HINT_DBG_VALUE) {
- Option = Instruction & THUMB32_DBG_OPTION_MASK;
- strcpy(Context->Mnemonic, THUMB_DBG_MNEMONIC);
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "#%d",
- Option);
- } else {
- if (HintOp >= THUMB32_HINT_OP_COUNT) {
- strcpy(Context->Mnemonic, "Undef hint");
- } else {
- strcpy(Context->Mnemonic, DbgThumb32HintMnemonics[HintOp]);
- }
- }
- }
- return;
- }
- VOID
- DbgpThumb32DecodeMiscellaneousControl (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb miscellaneous control instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- PSTR Mnemonic;
- ULONG Mode;
- ULONG Op;
- Instruction = Context->Instruction;
- Op = (Instruction >> THUMB32_MISCELLANEOUS_CONTROL_OP_SHIFT) &
- THUMB32_MISCELLANEOUS_CONTROL_OP_MASK;
- Mode = Instruction & THUMB32_BARRIER_MODE_MASK;
- if (Op == THUMB32_MISCELLANEOUS_CONTROL_OP_ENTERX) {
- Mnemonic = THUMB_ENTERX_MNEMONIC;
- } else if (Op == THUMB32_MISCELLANEOUS_CONTROL_OP_LEAVEX) {
- Mnemonic = THUMB_LEAVEX_MNEMONIC;
- } else if (Op == THUMB32_MISCELLANEOUS_CONTROL_OP_CLREX) {
- Mnemonic = THUMB_CLREX_MNEMONIC;
- } else if (Op == THUMB32_MISCELLANEOUS_CONTROL_OP_DSB) {
- Mnemonic = THUMB_DSB_MNEMONIC;
- DbgpArmPrintBarrierMode(Context->Operand1, Mode);
- } else if (Op == THUMB32_MISCELLANEOUS_CONTROL_OP_DMB) {
- Mnemonic = THUMB_DMB_MNEMONIC;
- DbgpArmPrintBarrierMode(Context->Operand1, Mode);
- } else if (Op == THUMB32_MISCELLANEOUS_CONTROL_OP_ISB) {
- Mnemonic = THUMB_ISB_MNEMONIC;
- DbgpArmPrintBarrierMode(Context->Operand1, Mode);
- } else {
- Mnemonic = "Undef Misc control";
- }
- strcpy(Context->Mnemonic, Mnemonic);
- return;
- }
- VOID
- DbgpThumb32DecodeBxj (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb BXJ instruction.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Rm;
- Rm = (Context->Instruction >> THUMB32_BXJ_RM_SHIFT) & THUMB_REGISTER16_MASK;
- strcpy(Context->Mnemonic, THUMB_BXJ_MNEMONIC);
- strcpy(Context->Operand1, DbgArmRegisterNames[Rm]);
- return;
- }
- VOID
- DbgpThumb32DecodeExceptionReturn (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb ERET (exception return) and SUBS pc, lr.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate8;
- Immediate8 = Context->Instruction & THUMB_IMMEDIATE8_MASK;
- if (Immediate8 == 0) {
- strcpy(Context->Mnemonic, THUMB_ERET_MNEMONIC);
- } else {
- strcpy(Context->Mnemonic, THUMB_SUBS_MNEMONIC);
- strcpy(Context->Operand1, DbgArmRegisterNames[15]);
- strcpy(Context->Operand2, DbgArmRegisterNames[13]);
- snprintf(Context->Operand3,
- sizeof(Context->Operand3),
- "#%d",
- Immediate8);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeMrs (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb MRS (Move to ARM from Status register)
- instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- ULONG Mode;
- ULONG Rd;
- PSTR Register;
- Instruction = Context->Instruction;
- Rd = (Instruction >> THUMB32_MRS_RD_SHIFT) & THUMB_REGISTER16_MASK;
- strcpy(Context->Mnemonic, THUMB_MRS_MNEMONIC);
- if ((Instruction & THUMB32_MRS_BANKED_REGISTER) != 0) {
- Mode = (Instruction >> THUMB32_MRS_MODE_SHIFT) & THUMB32_MRS_MODE_MASK;
- if ((Instruction & THUMB32_MRS_MODE4) != 0) {
- Mode |= 1 << 4;
- }
- if ((Instruction & THUMB32_MRS_SPSR) != 0) {
- Mode |= 1 << 5;
- }
- strcpy(Context->Operand2, DbgArmBankedRegisters[Mode]);
- } else {
- Register = THUMB_CPSR_STRING;
- if ((Instruction & THUMB32_MRS_SPSR) != 0) {
- Register = THUMB_SPSR_STRING;
- }
- strcpy(Context->Operand2, Register);
- }
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- return;
- }
- VOID
- DbgpThumb32DecodeHvc (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb HVC (hypervisor call) instruction.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate16;
- ULONG Instruction;
- Instruction = Context->Instruction;
- Immediate16 = (Instruction & THUMB32_HVC_IMMEDIATE12_MASK) |
- ((Instruction >> THUMB32_HVC_IMMEDIATE4_SHIFT) &
- THUMB32_HVC_IMMEDIATE4_MASK);
- strcpy(Context->Mnemonic, THUMB_HVC_MNEMONIC);
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "#%d",
- Immediate16);
- return;
- }
- VOID
- DbgpThumb32DecodeSmc (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb SMC (secure monitor call) instruction.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate4;
- ULONG Instruction;
- Instruction = Context->Instruction;
- Immediate4 = (Instruction >> THUMB32_SMC_IMMEDIATE4_SHIFT) &
- THUMB32_SMC_IMMEDIATE4_MASK;
- strcpy(Context->Mnemonic, THUMB_SMC_MNEMONIC);
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "#%d",
- Immediate4);
- return;
- }
- VOID
- DbgpThumb32DecodeBranch (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb branch (both conditional and
- unconditional) instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Bit;
- ULONG Condition;
- PSTR ConditionString;
- LONG Immediate;
- ULONG Instruction;
- ULONGLONG OperandAddress;
- ULONG SBit;
- Instruction = Context->Instruction;
- Immediate = (Instruction >> THUMB32_B_IMMEDIATE11_SHIFT) &
- THUMB32_B_IMMEDIATE11_MASK;
- Condition = (Instruction >> THUMB32_B_CONDITION_SHIFT) &
- THUMB32_B_CONDITION_MASK;
- ConditionString = "";
- //
- // Handle an unconditional branch, which has a larger range.
- //
- if ((Instruction & THUMB32_B_UNCONDITIONAL_MASK) ==
- THUMB32_B_UNCONDITIONAL_VALUE) {
- Immediate |= ((Instruction >> THUMB32_B_IMMEDIATE10_SHIFT) &
- THUMB_IMMEDIATE10_MASK) << 11;
- //
- // The next two bits are NOT(J2 EOR S) and NOT(J1 EOR S).
- //
- SBit = 0;
- if ((Instruction & THUMB32_B_S_BIT) != 0) {
- SBit = 1;
- }
- Bit = 0;
- if ((Instruction & THUMB32_B_J1_BIT) != 0) {
- Bit = 1;
- }
- Bit = !(Bit ^ SBit);
- if (Bit != 0) {
- Immediate |= 1 << 21;
- }
- Bit = 0;
- if ((Instruction & THUMB32_B_J2_BIT) != 0) {
- Bit = 1;
- }
- Bit = !(Bit ^ SBit);
- if (Bit != 0) {
- Immediate |= 1 << 22;
- }
- if (SBit != 0) {
- Immediate |= 1 << 23;
- }
- Immediate <<= 1;
- //
- // Sign extend.
- //
- if ((Immediate & 0x01000000) != 0) {
- Immediate |= 0xFE000000;
- }
- //
- // Conditional branches sacrifice some range for the encoded condition.
- //
- } else {
- ConditionString = DbgArmConditionCodes[Condition];
- Immediate |= ((Instruction >> THUMB32_B_IMMEDIATE6_SHIFT) &
- THUMB_IMMEDIATE6_MASK) << 11;
- if ((Instruction & THUMB32_B_J1_BIT) != 0) {
- Immediate |= (1 << 17);
- }
- if ((Instruction & THUMB32_B_J2_BIT) != 0) {
- Immediate |= (1 << 18);
- }
- if ((Instruction & THUMB32_B_S_BIT) != 0) {
- Immediate |= (1 << 19);
- }
- Immediate <<= 1;
- //
- // Sign extend.
- //
- if ((Immediate & 0x00100000) != 0) {
- Immediate |= 0xFFE00000;
- }
- }
- snprintf(Context->Mnemonic,
- sizeof(Context->Mnemonic),
- THUMB_B_W_MNEMONIC_FORMAT,
- ConditionString);
- //
- // All of these branches are relative to the PC, which is 4 ahead of the
- // instruction pointer. Calculate the absolute operand address.
- //
- OperandAddress = Context->InstructionPointer + 4;
- OperandAddress += (LONGLONG)Immediate;
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "[0x%08llx]",
- OperandAddress);
- Context->Result->OperandAddress = OperandAddress;
- Context->Result->AddressIsDestination = TRUE;
- Context->Result->AddressIsValid = TRUE;
- return;
- }
- VOID
- DbgpThumb32DecodeUdf (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb undefined instruction (like THE undefined
- instruction).
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate20;
- ULONG Instruction;
- Instruction = Context->Instruction;
- Immediate20 = (Instruction & THUMB_IMMEDIATE12_MASK) |
- ((Instruction >> THUMB32_UDF_IMMEDIATE4_SHIFT) &
- THUMB_IMMEDIATE4_MASK);
- strcpy(Context->Mnemonic, THUMB_UDF_W_MNEMONIC);
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "#%d",
- Immediate20);
- return;
- }
- VOID
- DbgpThumb32DecodeBranchWithLink (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb branch with link instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Bit;
- LONG Immediate25;
- ULONG Instruction;
- ULONGLONG OperandAddress;
- ULONG SBit;
- Instruction = Context->Instruction;
- Immediate25 = ((Instruction >> THUMB32_BL_IMMEDIATE11_SHIFT) &
- THUMB_IMMEDIATE11_MASK) |
- (((Instruction >> THUMB32_BL_IMMEDIATE10_SHIFT) &
- THUMB_IMMEDIATE10_MASK) << 11);
- if ((Instruction & THUMB32_BL_X_BIT) == 0) {
- Immediate25 &= ~THUMB32_BL_THUMB_BIT;
- }
- //
- // The next two bits are NOT(J1 EOR S) and NOT(J2 EOR S).
- //
- SBit = 0;
- if ((Instruction & THUMB32_B_S_BIT) != 0) {
- SBit = 1;
- }
- Bit = 0;
- if ((Instruction & THUMB32_B_J2_BIT) != 0) {
- Bit = 1;
- }
- Bit = !(Bit ^ SBit);
- if (Bit != 0) {
- Immediate25 |= 1 << 21;
- }
- Bit = 0;
- if ((Instruction & THUMB32_B_J1_BIT) != 0) {
- Bit = 1;
- }
- Bit = !(Bit ^ SBit);
- if (Bit != 0) {
- Immediate25 |= 1 << 22;
- }
- if (SBit != 0) {
- Immediate25 |= 1 << 23;
- }
- Immediate25 <<= 1;
- //
- // Sign extend.
- //
- if ((Immediate25 & 0x00200000) != 0) {
- Immediate25 |= 0xFFC00000;
- }
- //
- // For the BLX encoding, the immediate is relative to "Align(PC, 4)". The
- // PC is four bytes ahead of the instruction pointer and it is an align
- // down operation. The align-down action also strips the low bit from the
- // Thumb instruction point, resulting in the correct ARM address. This is
- // necessay because the destination mode of BLX is ARM.
- //
- OperandAddress = Context->InstructionPointer + 4;
- if ((Instruction & THUMB32_BL_X_BIT) == 0) {
- strcpy(Context->Mnemonic, THUMB_BLX_MNEMONIC);
- OperandAddress = THUMB_ALIGN_4(OperandAddress);
- //
- // BL is relative to the PC.
- //
- } else {
- strcpy(Context->Mnemonic, THUMB_BL_MNEMONIC);
- }
- OperandAddress += (LONGLONG)Immediate25;
- snprintf(Context->Operand1,
- sizeof(Context->Operand1),
- "[0x%08llx]",
- OperandAddress);
- Context->Result->OperandAddress = OperandAddress;
- Context->Result->AddressIsDestination = TRUE;
- Context->Result->AddressIsValid = TRUE;
- return;
- }
- VOID
- DbgpThumb32DecodeLoadStoreSingleItem (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb load/store instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- Instruction = Context->Instruction;
- if ((Instruction & THUMB32_LOAD_STORE_REGISTER_MASK) ==
- THUMB32_LOAD_STORE_REGISTER_VALUE) {
- DbgpThumb32DecodeLoadStoreRegister(Context);
- } else {
- DbgpThumb32DecodeLoadStoreImmediate(Context);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeLoadStoreImmediate (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb load/store immediate instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- LONG Immediate;
- ULONG Instruction;
- ULONG Load;
- ULONG Op;
- ULONGLONG OperandAddress;
- ULONG Rn;
- ULONG Rt;
- Instruction = Context->Instruction;
- Op = (Instruction >> THUMB32_LOAD_STORE_OP_SHIFT) &
- THUMB32_LOAD_STORE_OP_MASK;
- Rn = (Instruction >> THUMB32_LOAD_STORE_IMMEDIATE_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rt = (Instruction >> THUMB32_LOAD_STORE_IMMEDIATE_RT_SHIFT) &
- THUMB_REGISTER16_MASK;
- Load = 0;
- if ((Instruction & THUMB32_LOAD_BIT) != 0) {
- Load = 1;
- }
- //
- // Assume the mnemonic is not unprivileged. This may get altered later.
- //
- if ((Load != 0) && ((Instruction & THUMB32_LOAD_SET_FLAGS) != 0)) {
- strcpy(Context->Mnemonic, DbgThumb32LoadSetFlagsMnemonics[Op]);
- } else {
- strcpy(Context->Mnemonic,
- DbgThumb32LoadStoreMnemonics[Load][Op]);
- }
- //
- // If bit 23 is set, then the pre-index is an immediate12.
- //
- if ((Instruction & THUMB32_LOAD_STORE_IMMEDIATE_LARGE) != 0) {
- Immediate = Instruction & THUMB_IMMEDIATE12_MASK;
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "[%s, #%d]",
- DbgArmRegisterNames[Rn],
- Immediate);
- //
- // There are a few addressing modes, and an immediate8.
- //
- } else {
- Immediate = Instruction & THUMB_IMMEDIATE8_MASK;
- if ((Instruction & THUMB32_LOAD_STORE_IMMEDIATE_ADD) == 0) {
- Immediate = -Immediate;
- }
- if ((Instruction & THUMB32_LOAD_STORE_IMMEDIATE_PREINDEX) != 0) {
- if ((Instruction & THUMB32_LOAD_STORE_IMMEDIATE_WRITE_BACK) != 0) {
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "[%s, #%d]!",
- DbgArmRegisterNames[Rn],
- Immediate);
- } else {
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "[%s, #%d]",
- DbgArmRegisterNames[Rn],
- Immediate);
- }
- } else {
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "[%s], #%d",
- DbgArmRegisterNames[Rn],
- Immediate);
- }
- //
- // It's an unprivileged instruction if both the P (preindex) and U (add)
- // bits are set.
- //
- if (((Instruction & THUMB32_LOAD_STORE_IMMEDIATE_PREINDEX) != 0) &&
- ((Instruction & THUMB32_LOAD_STORE_IMMEDIATE_ADD) != 0)) {
- if ((Load != 0) && ((Instruction & THUMB32_LOAD_SET_FLAGS) != 0)) {
- strcpy(Context->Mnemonic,
- DbgThumb32LoadSetFlagsUnprivilegedMnemonics[Op]);
- } else {
- strcpy(Context->Mnemonic,
- DbgThumb32LoadStoreUnprivilegedMnemonics[Load][Op]);
- }
- }
- }
- //
- // If this is a load relative to the PC, then calculate the absolute
- // operand address and override the second operand with the absolute
- // address.
- //
- if ((Load != 0) && (Rn == 15)) {
- //
- // The address is relative to the PC aligned down to a 4-byte boundary.
- //
- OperandAddress = Context->InstructionPointer + 4;
- OperandAddress = THUMB_ALIGN_4(OperandAddress);
- OperandAddress += Immediate;
- Context->Result->OperandAddress = OperandAddress;
- Context->Result->AddressIsDestination = FALSE;
- Context->Result->AddressIsValid = TRUE;
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "[0x%08llx]",
- OperandAddress);
- }
- //
- // If Rt is 15, then this is actually a preload operation. Copy the second
- // operand to the first.
- //
- if (Rt == 15) {
- strcpy(Context->Mnemonic, DbgThumb32PreloadMnemonics[Op]);
- strcpy(Context->Operand1, Context->Operand2);
- Context->Operand2[0] = '\0';
- } else {
- strcpy(Context->Operand1, DbgArmRegisterNames[Rt]);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeLoadStoreRegister (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb load/store register instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Immediate2;
- ULONG Instruction;
- ULONG Load;
- ULONG Op;
- ULONG Rm;
- ULONG Rn;
- ULONG Rt;
- Instruction = Context->Instruction;
- Op = (Instruction >> THUMB32_LOAD_STORE_OP_SHIFT) &
- THUMB32_LOAD_STORE_OP_MASK;
- Rm = (Instruction >> THUMB32_LOAD_STORE_REGISTER_RM_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_LOAD_STORE_REGISTER_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rt = (Instruction >> THUMB32_LOAD_STORE_REGISTER_RT_SHIFT) &
- THUMB_REGISTER16_MASK;
- Immediate2 = (Instruction >> THUMB32_LOAD_STORE_REGISTER_IMMEDIATE2_SHIFT) &
- THUMB_IMMEDIATE2_MASK;
- Load = 0;
- if ((Instruction & THUMB32_LOAD_BIT) != 0) {
- Load = 1;
- }
- if ((Load != 0) && ((Instruction & THUMB32_LOAD_SET_FLAGS) != 0)) {
- strcpy(Context->Mnemonic, DbgThumb32LoadSetFlagsMnemonics[Op]);
- } else {
- strcpy(Context->Mnemonic, DbgThumb32LoadStoreMnemonics[Load][Op]);
- }
- if (Immediate2 == 0) {
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "[%s, %s]",
- DbgArmRegisterNames[Rn],
- DbgArmRegisterNames[Rm]);
- } else {
- snprintf(Context->Operand2,
- sizeof(Context->Operand2),
- "[%s, %s, %s #%d]",
- DbgArmRegisterNames[Rn],
- THUMB_SHIFT_TYPE_LSL_STRING,
- DbgArmRegisterNames[Rm],
- Immediate2);
- }
- //
- // If Rt is 15, then this is actually a preload operation. Copy the second
- // operand to the first.
- //
- if (Rt == 15) {
- strcpy(Context->Mnemonic, DbgThumb32PreloadMnemonics[Op]);
- strcpy(Context->Operand1, Context->Operand2);
- strcpy(Context->Operand2, "");
- } else {
- strcpy(Context->Operand1, DbgArmRegisterNames[Rt]);
- }
- return;
- }
- VOID
- DbgpThumb32DecodeDataProcessingRegister (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb data processing (register) instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- ULONG MiscellaneousOp;
- ULONG Op1;
- ULONG ParallelOp;
- ULONG Rd;
- ULONG Rm;
- ULONG Rn;
- ULONG Rotate;
- ULONG SetFlags;
- ULONG Unsigned;
- Instruction = Context->Instruction;
- SetFlags = 0;
- if ((Instruction & THUMB32_DATA_SET_FLAGS) != 0) {
- SetFlags = 1;
- }
- Op1 = (Instruction >> THUMB32_DATA_PROCESSING_REGISTER_OP1_SHIFT) &
- THUMB32_DATA_PROCESSING_REGISTER_OP1_MASK;
- Rd = (Instruction >> THUMB32_DATA_PROCESSING_REGISTER_RD_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rm = (Instruction >> THUMB32_DATA_PROCESSING_REGISTER_RM_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_DATA_PROCESSING_REGISTER_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- //
- // Handle shift/rotate instructions.
- //
- if ((Instruction & THUMB32_DATA_PROCESSING_REGISTER_SHIFT_MASK) ==
- THUMB32_DATA_PROCESSING_REGISTER_SHIFT_VALUE) {
- strcpy(Context->Mnemonic,
- DbgThumb32DataProcessingShiftMnemonics[SetFlags][Op1 >> 1]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- strcpy(Context->Operand3, DbgArmRegisterNames[Rm]);
- //
- // Handle signed and unsigned extend and add.
- //
- } else if ((Op1 & THUMB32_DATA_PROCESSING_REGISTER_OP1_EXTEND) == 0) {
- Rotate = (Instruction >>
- THUMB32_DATA_PROCESSING_REGISTER_ROTATE_SHIFT) &
- THUMB32_DATA_PROCESSING_REGISTER_ROTATE_MASK;
- Rotate <<= 3;
- if (Op1 < THUMB32_DATA_PROCESSING_REGISTER_OP1_EXTEND_COUNT) {
- if (Rn == 15) {
- strcpy(Context->Mnemonic,
- DbgThumb32ExtendAndAddMnemonics[1][Op1]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rm]);
- if (Rotate != 0) {
- snprintf(Context->Operand3,
- sizeof(Context->Operand4),
- "ror #%d",
- Rotate);
- }
- } else {
- strcpy(Context->Mnemonic,
- DbgThumb32ExtendAndAddMnemonics[0][Op1]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- strcpy(Context->Operand3, DbgArmRegisterNames[Rm]);
- if (Rotate != 0) {
- snprintf(Context->Operand4,
- sizeof(Context->Operand4),
- "ror #%d",
- Rotate);
- }
- }
- }
- //
- // Handle parallel addition and subtraction, both signed and unsigned.
- //
- } else if ((Instruction & THUMB32_DATA_PROCESSING_REGISTER_PARALLEL) == 0) {
- Unsigned = 0;
- if ((Instruction & THUMB32_DATA_PROCESSING_REGISTER_UNSIGNED) != 0) {
- Unsigned = 1;
- }
- ParallelOp = (Instruction >>
- THUMB32_DATA_PROCESSING_PARALLEL_OP1_SHIFT) &
- THUMB32_DATA_PROCESSING_PARALLEL_OP1_MASK;
- ParallelOp |= ((Instruction >>
- THUMB32_DATA_PROCESSING_PARALLEL_OP2_SHIFT) &
- THUMB32_DATA_PROCESSING_PARALLEL_OP2_MASK) << 3;
- if (ParallelOp < THUMB32_DATA_PROCESSING_PARALLEL_OP_COUNT) {
- strcpy(Context->Mnemonic,
- DbgThumb32ParallelArithmeticMnemonics[Unsigned][ParallelOp]);
- }
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- strcpy(Context->Operand3, DbgArmRegisterNames[Rm]);
- //
- // Handle miscellaneous instructions.
- //
- } else {
- MiscellaneousOp = (Instruction >>
- THUMB32_DATA_PROCESSING_MISCELLANEOUS_OP2_SHIFT) &
- THUMB32_DATA_PROCESSING_MISCELLANEOUS_OP2_MASK;
- MiscellaneousOp |= ((Instruction >>
- THUMB32_DATA_PROCESSING_MISCELLANEOUS_OP1_SHIFT) &
- THUMB32_DATA_PROCESSING_MISCELLANEOUS_OP1_MASK) <<
- 2;
- strcpy(Context->Mnemonic,
- DbgThumb32DataProcessingMiscellaneousMnemonics[MiscellaneousOp]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- if (Rn != Rm) {
- strcpy(Context->Operand3, DbgArmRegisterNames[Rm]);
- }
- }
- return;
- }
- VOID
- DbgpThumb32DecodeMultiplyAccumulate (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb multiply and multiply/accumulate
- instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Instruction;
- ULONG Op1;
- ULONG Op2;
- ULONG Ra;
- ULONG Rd;
- ULONG Rm;
- ULONG Rn;
- ULONG Top;
- Instruction = Context->Instruction;
- Ra = (Instruction >> THUMB32_MULTIPLY_RA_SHIFT) & THUMB_REGISTER16_MASK;
- Rd = (Instruction >> THUMB32_MULTIPLY_RD_SHIFT) & THUMB_REGISTER16_MASK;
- Rm = (Instruction >> THUMB32_MULTIPLY_RN_SHIFT) & THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_MULTIPLY_RM_SHIFT) & THUMB_REGISTER16_MASK;
- Op1 = (Instruction >> THUMB32_MULTIPLY_OP1_SHIFT) &
- THUMB32_MULTIPLY_OP1_MASK;
- Op2 = (Instruction >> THUMB32_MULTIPLY_OP2_SHIFT) &
- THUMB32_MULTIPLY_OP2_MASK;
- strcpy(Context->Operand1, DbgArmRegisterNames[Rd]);
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- strcpy(Context->Operand3, DbgArmRegisterNames[Rm]);
- if (Ra != 15) {
- strcpy(Context->Mnemonic, DbgThumb32MultiplyMnemonics[0][Op1]);
- strcpy(Context->Operand4, DbgArmRegisterNames[Ra]);
- } else {
- strcpy(Context->Mnemonic, DbgThumb32MultiplyMnemonics[1][Op1]);
- }
- if ((Op1 == THUMB32_MULTIPLY_OP1_MLS) &&
- (Op2 == THUMB32_MULTIPLY_OP2_MLS)) {
- strcpy(Context->Mnemonic, THUMB_MLS_MNEMONIC);
- }
- //
- // Instructions that operate on only the top or bottom half of some
- // registers (Rn and maybe Rm) get endings for top or bottom.
- //
- if (Op1 == THUMB32_MULTIPLY_OP1_HALF_HALF) {
- Top = 0;
- if ((Instruction & THUMB32_MULTIPLY_RN_TOP) != 0) {
- Top = 1;
- }
- strcat(Context->Mnemonic, DbgThumb32MultiplyTopBottomMnemonics[Top]);
- }
- if ((Op1 == THUMB32_MULTIPLY_OP1_HALF_HALF) ||
- (Op1 == THUMB32_MULTIPLY_OP1_WORD_HALF)) {
- Top = 0;
- if ((Instruction & THUMB32_MULTIPLY_RM_TOP) != 0) {
- Top = 1;
- }
- strcat(Context->Mnemonic, DbgThumb32MultiplyTopBottomMnemonics[Top]);
- }
- //
- // A couple of instructions have an optional X or R tagged on the end.
- //
- if ((Op1 == THUMB32_MULTIPLY_OP1_SMAD) ||
- (Op1 == THUMB32_MULTIPLY_OP1_SMSD)) {
- if ((Instruction & THUMB32_MULTIPLY_DUAL_CROSS) != 0) {
- strcat(Context->Mnemonic, THUMB_MULTIPLY_CROSS_MNEMONIC);
- }
- } else if (Op1 == THUMB32_MULTIPLY_OP1_SMML) {
- if ((Instruction & THUMB32_MULTIPLY_ROUND) != 0) {
- strcat(Context->Mnemonic, THUMB_MULTIPLY_ROUND_MNEMONIC);
- }
- }
- return;
- }
- VOID
- DbgpThumb32DecodeLongMultiplyDivide (
- PARM_DISASSEMBLY Context
- )
- /*++
- Routine Description:
- This routine decodes 32-bit Thumb long multiply and divide instructions.
- Arguments:
- Context - Supplies a pointer to the disassembly context.
- Return Value:
- None.
- --*/
- {
- ULONG Cross;
- ULONG Instruction;
- ULONG Op1;
- ULONG Op2;
- ULONG RdHigh;
- ULONG RdLow;
- ULONG Rm;
- ULONG Rn;
- ULONG Top;
- Instruction = Context->Instruction;
- RdHigh = (Instruction >> THUMB32_LONG_MULTIPLY_RD_HIGH_SHIFT) &
- THUMB_REGISTER16_MASK;
- RdLow = (Instruction >> THUMB32_LONG_MULTIPLY_RD_LOW_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rm = (Instruction >> THUMB32_LONG_MULTIPLY_RM_SHIFT) &
- THUMB_REGISTER16_MASK;
- Rn = (Instruction >> THUMB32_LONG_MULTIPLY_RN_SHIFT) &
- THUMB_REGISTER16_MASK;
- Op1 = (Instruction >> THUMB32_LONG_MULTIPLY_OP1_SHIFT) &
- THUMB32_LONG_MULTIPLY_OP1_MASK;
- Op2 = (Instruction >> THUMB32_LONG_MULTIPLY_OP2_SHIFT) &
- THUMB32_LONG_MULTIPLY_OP2_MASK;
- Cross = 0;
- strcpy(Context->Mnemonic, DbgThumb32LongMultiplyMnemonics[Op1]);
- if (Op1 == THUMB32_LONG_MULTIPLY_OP1_SMLA) {
- if ((Op2 & THUMB32_LONG_MULTIPLY_OP2_SMLA_HALF_MASK) ==
- THUMB32_LONG_MULTIPLY_OP2_SMLA_HALF_VALUE) {
- Top = 0;
- if ((Instruction & THUMB32_MULTIPLY_RN_TOP) != 0) {
- Top = 1;
- }
- strcat(Context->Mnemonic,
- DbgThumb32MultiplyTopBottomMnemonics[Top]);
- Top = 0;
- if ((Instruction & THUMB32_MULTIPLY_RM_TOP) != 0) {
- Top = 1;
- }
- strcat(Context->Mnemonic,
- DbgThumb32MultiplyTopBottomMnemonics[Top]);
- } else if ((Op2 & THUMB32_LONG_MULTIPLY_OP2_SMLALD_MASK) ==
- THUMB32_LONG_MULTIPLY_OP2_SMLALD_VALUE) {
- strcpy(Context->Mnemonic, THUMB_SMLALD_MNEMONIC);
- Cross = Instruction & THUMB32_MULTIPLY_DUAL_CROSS;
- }
- } else if (Op1 == THUMB32_LONG_MULTIPLY_OP1_SMLSLD) {
- Cross = Instruction & THUMB32_MULTIPLY_DUAL_CROSS;
- }
- if (Cross != 0) {
- strcat(Context->Mnemonic, THUMB_MULTIPLY_CROSS_MNEMONIC);
- }
- strcpy(Context->Operand1, DbgArmRegisterNames[RdHigh]);
- if (RdLow != 15) {
- strcpy(Context->Operand2, DbgArmRegisterNames[RdLow]);
- strcpy(Context->Operand3, DbgArmRegisterNames[Rn]);
- strcpy(Context->Operand4, DbgArmRegisterNames[Rm]);
- } else {
- strcpy(Context->Operand2, DbgArmRegisterNames[Rn]);
- strcpy(Context->Operand3, DbgArmRegisterNames[Rm]);
- }
- return;
- }
- VOID
- DbgpThumbDecodeImmediateShift (
- PSTR Destination,
- ULONG DestinationSize,
- ULONG Register,
- ULONG Type,
- ULONG Immediate
- )
- /*++
- Routine Description:
- This routine performs the operation known in the ARM ARM as
- DecodeImmShift().
- Arguments:
- Destination - Supplies the destination to write to.
- DestinationSize - Supplies the size of the destination.
- Register - Supplies the base register.
- Type - Supplies the shift type.
- Immediate - Supplies the shift value.
- Return Value:
- None.
- --*/
- {
- PSTR ShiftTypeString;
- switch (Type) {
- case THUMB_SHIFT_TYPE_LSL:
- if (Immediate == 0) {
- snprintf(Destination,
- DestinationSize,
- "%s",
- DbgArmRegisterNames[Register]);
- } else {
- snprintf(Destination,
- DestinationSize,
- "%s, %s #%d",
- DbgArmRegisterNames[Register],
- THUMB_SHIFT_TYPE_LSL_STRING,
- Immediate);
- }
- break;
- case THUMB_SHIFT_TYPE_LSR:
- if (Immediate == 0) {
- Immediate = 32;
- }
- snprintf(Destination,
- DestinationSize,
- "%s, %s #%d",
- DbgArmRegisterNames[Register],
- THUMB_SHIFT_TYPE_LSR_STRING,
- Immediate);
- break;
- case THUMB_SHIFT_TYPE_ASR:
- if (Immediate == 0) {
- Immediate = 32;
- }
- snprintf(Destination,
- DestinationSize,
- "%s, %s #%d",
- DbgArmRegisterNames[Register],
- THUMB_SHIFT_TYPE_ASR_STRING,
- Immediate);
- break;
- case THUMB_SHIFT_TYPE_ROR:
- default:
- ShiftTypeString = THUMB_SHIFT_TYPE_ROR_STRING;
- if (Immediate == 0) {
- Immediate = 1;
- ShiftTypeString = THUMB_SHIFT_TYPE_RRX_STRING;
- }
- snprintf(Destination,
- DestinationSize,
- "%s, %s #%d",
- DbgArmRegisterNames[Register],
- ShiftTypeString,
- Immediate);
- break;
- }
- return;
- }
- ULONG
- DbgpThumb32DecodeModifiedImmediate (
- ULONG Immediate12
- )
- /*++
- Routine Description:
- This routine performs the operation known in the ARM ARM as
- ThumbExpandImm(), expanding a modified immediate.
- Arguments:
- Immediate12 - Supplies the 12 bit immediate.
- Return Value:
- Returns the expanded immediate.
- --*/
- {
- ULONG Result;
- ULONG RotateCount;
- if ((Immediate12 & THUMB32_MODIFIED_IMMEDIATE_OP_MASK) ==
- THUMB32_MODIFIED_IMMEDIATE_OP_NO_ROTATE) {
- Result = Immediate12 & THUMB_IMMEDIATE8_MASK;
- switch ((Immediate12 >> 8) & 0x3) {
- //
- // 00000000 00000000 00000000 abcdefgh
- //
- case 0x0:
- break;
- //
- // 00000000 abcdefgh 00000000 abcdefgh
- //
- case 0x1:
- Result |= Result << 16;
- break;
- //
- // abcdefgh 00000000 abcdefgh 00000000
- //
- case 0x2:
- Result |= Result << 16;
- Result <<= 8;
- break;
- //
- // abcdefgh abcdefgh abcdefgh abcdefgh
- //
- case 0x3:
- Result |= Result << 16;
- Result |= Result << 8;
- break;
- default:
- break;
- }
- //
- // Rotate bits 6:0 (with a 1 tacked on the MSB) by the amount specified in
- // bits 7-11.
- //
- } else {
- Result = (Immediate12 & THUMB32_MODIFIED_IMMEDIATE_CONSTANT_MASK) |
- THUMB32_MODIFIED_IMMEDIATE_EXTRA_ONE;
- RotateCount = (Immediate12 >> THUMB32_MODIFIED_IMMEDIATE_ROTATE_SHIFT) &
- THUMB32_MODIFIED_IMMEDIATE_ROTATE_MASK;
- //
- // Perform the rotate.
- //
- Result = (Result >> RotateCount) | (Result << (32 - RotateCount));
- }
- return Result;
- }
|