12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134 |
- /* s12z-decode.c -- Freescale S12Z disassembly
- Copyright (C) 2018-2022 Free Software Foundation, Inc.
- This file is part of the GNU opcodes library.
- This library is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
- It is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
- License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
- MA 02110-1301, USA. */
- #include "sysdep.h"
- #include <stdio.h>
- #include <stdint.h>
- #include <stdbool.h>
- #include <assert.h>
- #include "opcode/s12z.h"
- #include "bfd.h"
- #include "s12z-opc.h"
- typedef int (*insn_bytes_f) (struct mem_read_abstraction_base *);
- typedef int (*operands_f) (struct mem_read_abstraction_base *,
- int *n_operands, struct operand **operand);
- typedef enum optr (*discriminator_f) (struct mem_read_abstraction_base *,
- enum optr hint);
- enum OPR_MODE
- {
- OPR_IMMe4,
- OPR_REG,
- OPR_OFXYS,
- OPR_XY_PRE_INC,
- OPR_XY_POST_INC,
- OPR_XY_PRE_DEC,
- OPR_XY_POST_DEC,
- OPR_S_PRE_DEC,
- OPR_S_POST_INC,
- OPR_REG_DIRECT,
- OPR_REG_INDIRECT,
- OPR_IDX_DIRECT,
- OPR_IDX_INDIRECT,
- OPR_EXT1,
- OPR_IDX2_REG,
- OPR_IDX3_DIRECT,
- OPR_IDX3_INDIRECT,
- OPR_EXT18,
- OPR_IDX3_DIRECT_REG,
- OPR_EXT3_DIRECT,
- OPR_EXT3_INDIRECT
- };
- struct opr_pb
- {
- uint8_t mask;
- uint8_t value;
- int n_operands;
- enum OPR_MODE mode;
- };
- static const struct opr_pb opr_pb[] = {
- {0xF0, 0x70, 1, OPR_IMMe4},
- {0xF8, 0xB8, 1, OPR_REG},
- {0xC0, 0x40, 1, OPR_OFXYS},
- {0xEF, 0xE3, 1, OPR_XY_PRE_INC},
- {0xEF, 0xE7, 1, OPR_XY_POST_INC},
- {0xEF, 0xC3, 1, OPR_XY_PRE_DEC},
- {0xEF, 0xC7, 1, OPR_XY_POST_DEC},
- {0xFF, 0xFB, 1, OPR_S_PRE_DEC},
- {0xFF, 0xFF, 1, OPR_S_POST_INC},
- {0xC8, 0x88, 1, OPR_REG_DIRECT},
- {0xE8, 0xC8, 1, OPR_REG_INDIRECT},
- {0xCE, 0xC0, 2, OPR_IDX_DIRECT},
- {0xCE, 0xC4, 2, OPR_IDX_INDIRECT},
- {0xC0, 0x00, 2, OPR_EXT1},
- {0xC8, 0x80, 3, OPR_IDX2_REG},
- {0xFA, 0xF8, 3, OPR_EXT18},
- {0xCF, 0xC2, 4, OPR_IDX3_DIRECT},
- {0xCF, 0xC6, 4, OPR_IDX3_INDIRECT},
- {0xF8, 0xE8, 4, OPR_IDX3_DIRECT_REG},
- {0xFF, 0xFA, 4, OPR_EXT3_DIRECT},
- {0xFF, 0xFE, 4, OPR_EXT3_INDIRECT},
- };
- /* Return the number of bytes in a OPR operand, including the XB postbyte.
- It does not include any preceeding opcodes. */
- static int
- x_opr_n_bytes (struct mem_read_abstraction_base *mra, int offset)
- {
- bfd_byte xb;
- int status = mra->read (mra, offset, 1, &xb);
- if (status < 0)
- return status;
- size_t i;
- for (i = 0; i < sizeof (opr_pb) / sizeof (opr_pb[0]); ++i)
- {
- const struct opr_pb *pb = opr_pb + i;
- if ((xb & pb->mask) == pb->value)
- {
- return pb->n_operands;
- }
- }
- return 1;
- }
- static int
- opr_n_bytes_p1 (struct mem_read_abstraction_base *mra)
- {
- int n = x_opr_n_bytes (mra, 0);
- if (n < 0)
- return n;
- return 1 + n;
- }
- static int
- opr_n_bytes2 (struct mem_read_abstraction_base *mra)
- {
- int s = x_opr_n_bytes (mra, 0);
- if (s < 0)
- return s;
- int n = x_opr_n_bytes (mra, s);
- if (n < 0)
- return n;
- return s + n + 1;
- }
- enum BB_MODE
- {
- BB_REG_REG_REG,
- BB_REG_REG_IMM,
- BB_REG_OPR_REG,
- BB_OPR_REG_REG,
- BB_REG_OPR_IMM,
- BB_OPR_REG_IMM
- };
- struct opr_bb
- {
- uint8_t mask;
- uint8_t value;
- int n_operands;
- bool opr;
- enum BB_MODE mode;
- };
- static const struct opr_bb bb_modes[] =
- {
- {0x60, 0x00, 2, false, BB_REG_REG_REG},
- {0x60, 0x20, 3, false, BB_REG_REG_IMM},
- {0x70, 0x40, 2, true, BB_REG_OPR_REG},
- {0x70, 0x50, 2, true, BB_OPR_REG_REG},
- {0x70, 0x60, 3, true, BB_REG_OPR_IMM},
- {0x70, 0x70, 3, true, BB_OPR_REG_IMM}
- };
- static int
- bfextins_n_bytes (struct mem_read_abstraction_base *mra)
- {
- bfd_byte bb;
- int status = mra->read (mra, 0, 1, &bb);
- if (status < 0)
- return status;
- size_t i;
- const struct opr_bb *bbs = 0;
- for (i = 0; i < sizeof (bb_modes) / sizeof (bb_modes[0]); ++i)
- {
- bbs = bb_modes + i;
- if ((bb & bbs->mask) == bbs->value)
- {
- break;
- }
- }
- int n = bbs->n_operands;
- if (bbs->opr)
- {
- int x = x_opr_n_bytes (mra, n - 1);
- if (x < 0)
- return x;
- n += x;
- }
- return n;
- }
- static int
- single (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
- {
- return 1;
- }
- static int
- two (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
- {
- return 2;
- }
- static int
- three (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
- {
- return 3;
- }
- static int
- four (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
- {
- return 4;
- }
- static int
- five (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
- {
- return 5;
- }
- static int
- pcrel_15bit (struct mem_read_abstraction_base *mra)
- {
- bfd_byte byte;
- int status = mra->read (mra, 0, 1, &byte);
- if (status < 0)
- return status;
- return (byte & 0x80) ? 3 : 2;
- }
- static int
- xysp_reg_from_postbyte (uint8_t postbyte)
- {
- int reg = -1;
- switch ((postbyte & 0x30) >> 4)
- {
- case 0:
- reg = REG_X;
- break;
- case 1:
- reg = REG_Y;
- break;
- case 2:
- reg = REG_S;
- break;
- default:
- reg = REG_P;
- }
- return reg;
- }
- static struct operand *
- create_immediate_operand (int value)
- {
- struct immediate_operand *op = malloc (sizeof (*op));
- if (op != NULL)
- {
- op->parent.cl = OPND_CL_IMMEDIATE;
- op->parent.osize = -1;
- op->value = value;
- }
- return (struct operand *) op;
- }
- static struct operand *
- create_bitfield_operand (int width, int offset)
- {
- struct bitfield_operand *op = malloc (sizeof (*op));
- if (op != NULL)
- {
- op->parent.cl = OPND_CL_BIT_FIELD;
- op->parent.osize = -1;
- op->width = width;
- op->offset = offset;
- }
- return (struct operand *) op;
- }
- static struct operand *
- create_register_operand_with_size (int reg, short osize)
- {
- struct register_operand *op = malloc (sizeof (*op));
- if (op != NULL)
- {
- op->parent.cl = OPND_CL_REGISTER;
- op->parent.osize = osize;
- op->reg = reg;
- }
- return (struct operand *) op;
- }
- static struct operand *
- create_register_operand (int reg)
- {
- return create_register_operand_with_size (reg, -1);
- }
- static struct operand *
- create_register_all_operand (void)
- {
- struct register_operand *op = malloc (sizeof (*op));
- if (op != NULL)
- {
- op->parent.cl = OPND_CL_REGISTER_ALL;
- op->parent.osize = -1;
- }
- return (struct operand *) op;
- }
- static struct operand *
- create_register_all16_operand (void)
- {
- struct register_operand *op = malloc (sizeof (*op));
- if (op != NULL)
- {
- op->parent.cl = OPND_CL_REGISTER_ALL16;
- op->parent.osize = -1;
- }
- return (struct operand *) op;
- }
- static struct operand *
- create_simple_memory_operand (bfd_vma addr, bfd_vma base, bool relative)
- {
- struct simple_memory_operand *op;
- assert (relative || base == 0);
- op = malloc (sizeof (*op));
- if (op != NULL)
- {
- op->parent.cl = OPND_CL_SIMPLE_MEMORY;
- op->parent.osize = -1;
- op->addr = addr;
- op->base = base;
- op->relative = relative;
- }
- return (struct operand *) op;
- }
- static struct operand *
- create_memory_operand (bool indirect, int base, int n_regs, int reg0, int reg1)
- {
- struct memory_operand *op = malloc (sizeof (*op));
- if (op != NULL)
- {
- op->parent.cl = OPND_CL_MEMORY;
- op->parent.osize = -1;
- op->indirect = indirect;
- op->base_offset = base;
- op->mutation = OPND_RM_NONE;
- op->n_regs = n_regs;
- op->regs[0] = reg0;
- op->regs[1] = reg1;
- }
- return (struct operand *) op;
- }
- static struct operand *
- create_memory_auto_operand (enum op_reg_mutation mutation, int reg)
- {
- struct memory_operand *op = malloc (sizeof (*op));
- if (op != NULL)
- {
- op->parent.cl = OPND_CL_MEMORY;
- op->parent.osize = -1;
- op->indirect = false;
- op->base_offset = 0;
- op->mutation = mutation;
- op->n_regs = 1;
- op->regs[0] = reg;
- op->regs[1] = -1;
- }
- return (struct operand *) op;
- }
- static int
- z_ext24_decode (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operand)
- {
- struct operand *op;
- uint8_t buffer[3];
- int status = mra->read (mra, 0, 3, buffer);
- if (status < 0)
- return status;
- int i;
- uint32_t addr = 0;
- for (i = 0; i < 3; ++i)
- {
- addr <<= 8;
- addr |= buffer[i];
- }
- op = create_simple_memory_operand (addr, 0, false);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- z_decode_signed_value (struct mem_read_abstraction_base *mra, int offset,
- short size, uint32_t *result)
- {
- assert (size >0);
- assert (size <= 4);
- bfd_byte buffer[4];
- int status = mra->read (mra, offset, size, buffer);
- if (status < 0)
- return status;
- int i;
- uint32_t value = 0;
- for (i = 0; i < size; ++i)
- value = (value << 8) | buffer[i];
- if (buffer[0] & 0x80)
- {
- /* Deal with negative values */
- value -= 1u << (size * 4) << (size * 4);
- }
- *result = value;
- return 0;
- }
- static int
- decode_signed_value (struct mem_read_abstraction_base *mra, short size,
- uint32_t *result)
- {
- return z_decode_signed_value (mra, 0, size, result);
- }
- static int
- x_imm1 (struct mem_read_abstraction_base *mra,
- int offset,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- bfd_byte byte;
- int status = mra->read (mra, offset, 1, &byte);
- if (status < 0)
- return status;
- op = create_immediate_operand (byte);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- /* An eight bit immediate operand. */
- static int
- imm1_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- return x_imm1 (mra, 0, n_operands, operand);
- }
- static int
- trap_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- return x_imm1 (mra, -1, n_operands, operand);
- }
- static struct operand *
- x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
- short osize)
- {
- bfd_byte postbyte;
- int status = mra->read (mra, offset, 1, &postbyte);
- if (status < 0)
- return NULL;
- offset++;
- enum OPR_MODE mode = -1;
- size_t i;
- for (i = 0; i < sizeof (opr_pb) / sizeof (opr_pb[0]); ++i)
- {
- const struct opr_pb *pb = opr_pb + i;
- if ((postbyte & pb->mask) == pb->value)
- {
- mode = pb->mode;
- break;
- }
- }
- struct operand *operand = NULL;
- switch (mode)
- {
- case OPR_IMMe4:
- {
- int n;
- uint8_t x = (postbyte & 0x0F);
- if (x == 0)
- n = -1;
- else
- n = x;
- operand = create_immediate_operand (n);
- break;
- }
- case OPR_REG:
- {
- uint8_t x = (postbyte & 0x07);
- operand = create_register_operand (x);
- break;
- }
- case OPR_OFXYS:
- {
- operand = create_memory_operand (false, postbyte & 0x0F, 1,
- xysp_reg_from_postbyte (postbyte), -1);
- break;
- }
- case OPR_REG_DIRECT:
- {
- operand = create_memory_operand (false, 0, 2, postbyte & 0x07,
- xysp_reg_from_postbyte (postbyte));
- break;
- }
- case OPR_REG_INDIRECT:
- {
- operand = create_memory_operand (true, 0, 2, postbyte & 0x07,
- (postbyte & 0x10) ? REG_Y : REG_X);
- break;
- }
- case OPR_IDX_INDIRECT:
- {
- uint8_t x1;
- status = mra->read (mra, offset, 1, &x1);
- if (status < 0)
- return NULL;
- int idx = x1;
- if (postbyte & 0x01)
- {
- /* Deal with negative values */
- idx -= 0x1UL << 8;
- }
- operand = create_memory_operand (true, idx, 1,
- xysp_reg_from_postbyte (postbyte), -1);
- break;
- }
- case OPR_IDX3_DIRECT:
- {
- uint8_t x[3];
- status = mra->read (mra, offset, 3, x);
- if (status < 0)
- return NULL;
- int idx = x[0] << 16 | x[1] << 8 | x[2];
- if (x[0] & 0x80)
- {
- /* Deal with negative values */
- idx -= 0x1UL << 24;
- }
- operand = create_memory_operand (false, idx, 1,
- xysp_reg_from_postbyte (postbyte), -1);
- break;
- }
- case OPR_IDX3_DIRECT_REG:
- {
- uint8_t x[3];
- status = mra->read (mra, offset, 3, x);
- if (status < 0)
- return NULL;
- int idx = x[0] << 16 | x[1] << 8 | x[2];
- if (x[0] & 0x80)
- {
- /* Deal with negative values */
- idx -= 0x1UL << 24;
- }
- operand = create_memory_operand (false, idx, 1, postbyte & 0x07, -1);
- break;
- }
- case OPR_IDX3_INDIRECT:
- {
- uint8_t x[3];
- status = mra->read (mra, offset, 3, x);
- if (status < 0)
- return NULL;
- int idx = x[0] << 16 | x[1] << 8 | x[2];
- if (x[0] & 0x80)
- {
- /* Deal with negative values */
- idx -= 0x1UL << 24;
- }
- operand = create_memory_operand (true, idx, 1,
- xysp_reg_from_postbyte (postbyte), -1);
- break;
- }
- case OPR_IDX_DIRECT:
- {
- uint8_t x1;
- status = mra->read (mra, offset, 1, &x1);
- if (status < 0)
- return NULL;
- int idx = x1;
- if (postbyte & 0x01)
- {
- /* Deal with negative values */
- idx -= 0x1UL << 8;
- }
- operand = create_memory_operand (false, idx, 1,
- xysp_reg_from_postbyte (postbyte), -1);
- break;
- }
- case OPR_IDX2_REG:
- {
- uint8_t x[2];
- status = mra->read (mra, offset, 2, x);
- if (status < 0)
- return NULL;
- uint32_t idx = x[1] | x[0] << 8 ;
- idx |= (postbyte & 0x30) << 12;
- operand = create_memory_operand (false, idx, 1, postbyte & 0x07, -1);
- break;
- }
- case OPR_XY_PRE_INC:
- {
- operand = create_memory_auto_operand (OPND_RM_PRE_INC,
- (postbyte & 0x10) ? REG_Y: REG_X);
- break;
- }
- case OPR_XY_POST_INC:
- {
- operand = create_memory_auto_operand (OPND_RM_POST_INC,
- (postbyte & 0x10) ? REG_Y: REG_X);
- break;
- }
- case OPR_XY_PRE_DEC:
- {
- operand = create_memory_auto_operand (OPND_RM_PRE_DEC,
- (postbyte & 0x10) ? REG_Y: REG_X);
- break;
- }
- case OPR_XY_POST_DEC:
- {
- operand = create_memory_auto_operand (OPND_RM_POST_DEC,
- (postbyte & 0x10) ? REG_Y: REG_X);
- break;
- }
- case OPR_S_PRE_DEC:
- {
- operand = create_memory_auto_operand (OPND_RM_PRE_DEC, REG_S);
- break;
- }
- case OPR_S_POST_INC:
- {
- operand = create_memory_auto_operand (OPND_RM_POST_INC, REG_S);
- break;
- }
- case OPR_EXT18:
- {
- const size_t size = 2;
- bfd_byte buffer[4];
- status = mra->read (mra, offset, size, buffer);
- if (status < 0)
- return NULL;
- uint32_t ext18 = 0;
- for (i = 0; i < size; ++i)
- {
- ext18 <<= 8;
- ext18 |= buffer[i];
- }
- ext18 |= (postbyte & 0x01) << 16;
- ext18 |= (postbyte & 0x04) << 15;
- operand = create_simple_memory_operand (ext18, 0, false);
- break;
- }
- case OPR_EXT1:
- {
- uint8_t x1 = 0;
- status = mra->read (mra, offset, 1, &x1);
- if (status < 0)
- return NULL;
- int16_t addr;
- addr = x1;
- addr |= (postbyte & 0x3f) << 8;
- operand = create_simple_memory_operand (addr, 0, false);
- break;
- }
- case OPR_EXT3_DIRECT:
- {
- const size_t size = 3;
- bfd_byte buffer[4];
- status = mra->read (mra, offset, size, buffer);
- if (status < 0)
- return NULL;
- uint32_t ext24 = 0;
- for (i = 0; i < size; ++i)
- {
- ext24 |= buffer[i] << (8 * (size - i - 1));
- }
- operand = create_simple_memory_operand (ext24, 0, false);
- break;
- }
- case OPR_EXT3_INDIRECT:
- {
- const size_t size = 3;
- bfd_byte buffer[4];
- status = mra->read (mra, offset, size, buffer);
- if (status < 0)
- return NULL;
- uint32_t ext24 = 0;
- for (i = 0; i < size; ++i)
- {
- ext24 |= buffer[i] << (8 * (size - i - 1));
- }
- operand = create_memory_operand (true, ext24, 0, -1, -1);
- break;
- }
- default:
- printf ("Unknown OPR mode #0x%x (%d)", postbyte, mode);
- abort ();
- }
- if (operand != NULL)
- operand->osize = osize;
- return operand;
- }
- static struct operand *
- x_opr_decode (struct mem_read_abstraction_base *mra, int offset)
- {
- return x_opr_decode_with_size (mra, offset, -1);
- }
- static int
- z_opr_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op = x_opr_decode (mra, 0);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- z_opr_decode2 (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- int n = x_opr_n_bytes (mra, 0);
- if (n < 0)
- return n;
- struct operand *op = x_opr_decode (mra, 0);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = x_opr_decode (mra, n);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- imm1234 (struct mem_read_abstraction_base *mra, int base,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- bfd_byte opcode;
- int status = mra->read (mra, -1, 1, &opcode);
- if (status < 0)
- return status;
- opcode -= base;
- int size = registers[opcode & 0xF].bytes;
- uint32_t imm;
- if (decode_signed_value (mra, size, &imm) < 0)
- return -1;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- /* Special case of LD and CMP with register S and IMM operand */
- static int
- reg_s_imm (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operand)
- {
- struct operand *op;
- op = create_register_operand (REG_S);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- uint32_t imm;
- if (decode_signed_value (mra, 3, &imm) < 0)
- return -1;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- /* Special case of LD, CMP and ST with register S and OPR operand */
- static int
- reg_s_opr (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operand)
- {
- struct operand *op;
- op = create_register_operand (REG_S);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = x_opr_decode (mra, 0);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- z_imm1234_8base (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operand)
- {
- return imm1234 (mra, 8, n_operands, operand);
- }
- static int
- z_imm1234_0base (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operand)
- {
- return imm1234 (mra, 0, n_operands, operand);
- }
- static int
- z_tfr (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operand)
- {
- struct operand *op;
- bfd_byte byte;
- int status = mra->read (mra, 0, 1, &byte);
- if (status < 0)
- return status;
- op = create_register_operand (byte >> 4);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = create_register_operand (byte & 0x0F);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- z_reg (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operand)
- {
- struct operand *op;
- bfd_byte byte;
- int status = mra->read (mra, -1, 1, &byte);
- if (status < 0)
- return status;
- op = create_register_operand (byte & 0x07);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- reg_xy (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- bfd_byte byte;
- int status = mra->read (mra, -1, 1, &byte);
- if (status < 0)
- return status;
- op = create_register_operand ((byte & 0x01) ? REG_Y : REG_X);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- lea_reg_xys_opr (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- bfd_byte byte;
- int status = mra->read (mra, -1, 1, &byte);
- if (status < 0)
- return status;
- int reg_xys = -1;
- switch (byte & 0x03)
- {
- case 0x00:
- reg_xys = REG_X;
- break;
- case 0x01:
- reg_xys = REG_Y;
- break;
- case 0x02:
- reg_xys = REG_S;
- break;
- }
- op = create_register_operand (reg_xys);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = x_opr_decode (mra, 0);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- lea_reg_xys (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- bfd_byte byte;
- int status = mra->read (mra, -1, 1, &byte);
- if (status < 0)
- return status;
- int reg_n = -1;
- switch (byte & 0x03)
- {
- case 0x00:
- reg_n = REG_X;
- break;
- case 0x01:
- reg_n = REG_Y;
- break;
- case 0x02:
- reg_n = REG_S;
- break;
- }
- status = mra->read (mra, 0, 1, &byte);
- if (status < 0)
- return status;
- op = create_register_operand (reg_n);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = create_memory_operand (false, (int8_t) byte, 1, reg_n, -1);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- /* PC Relative offsets of size 15 or 7 bits */
- static int
- rel_15_7 (struct mem_read_abstraction_base *mra, int offset,
- int *n_operands, struct operand **operands)
- {
- struct operand *op;
- bfd_byte upper;
- int status = mra->read (mra, offset - 1, 1, &upper);
- if (status < 0)
- return status;
- bool rel_size = (upper & 0x80);
- int16_t addr = upper;
- if (rel_size)
- {
- /* 15 bits. Get the next byte */
- bfd_byte lower;
- status = mra->read (mra, offset, 1, &lower);
- if (status < 0)
- return status;
- addr <<= 8;
- addr |= lower;
- addr &= 0x7FFF;
- bool negative = (addr & 0x4000);
- addr &= 0x3FFF;
- if (negative)
- addr = addr - 0x4000;
- }
- else
- {
- /* 7 bits. */
- bool negative = (addr & 0x40);
- addr &= 0x3F;
- if (negative)
- addr = addr - 0x40;
- }
- op = create_simple_memory_operand (addr, mra->posn (mra) - 1, true);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- return 0;
- }
- /* PC Relative offsets of size 15 or 7 bits */
- static int
- decode_rel_15_7 (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- return rel_15_7 (mra, 1, n_operands, operand);
- }
- static int shift_n_bytes (struct mem_read_abstraction_base *);
- static int mov_imm_opr_n_bytes (struct mem_read_abstraction_base *);
- static int loop_prim_n_bytes (struct mem_read_abstraction_base *);
- static int bm_rel_n_bytes (struct mem_read_abstraction_base *);
- static int mul_n_bytes (struct mem_read_abstraction_base *);
- static int bm_n_bytes (struct mem_read_abstraction_base *);
- static int psh_pul_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
- static int shift_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
- static int mul_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
- static int bm_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
- static int bm_rel_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
- static int mov_imm_opr (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
- static int loop_primitive_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operands);
- static int bit_field_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operands);
- static int exg_sex_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operands);
- static enum optr shift_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
- static enum optr psh_pul_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
- static enum optr mul_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
- static enum optr loop_primitive_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
- static enum optr bit_field_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
- static enum optr exg_sex_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
- static int
- cmp_xy (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- op = create_register_operand (REG_X);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = create_register_operand (REG_Y);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- sub_d6_x_y (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- op = create_register_operand (REG_D6);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = create_register_operand (REG_X);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = create_register_operand (REG_Y);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- sub_d6_y_x (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- op = create_register_operand (REG_D6);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = create_register_operand (REG_Y);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = create_register_operand (REG_X);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- ld_18bit_decode (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operand);
- static enum optr
- mul_discrim (struct mem_read_abstraction_base *mra, enum optr hint)
- {
- uint8_t mb;
- int status = mra->read (mra, 0, 1, &mb);
- if (status < 0)
- return OP_INVALID;
- bool signed_op = (mb & 0x80);
- switch (hint)
- {
- case OPBASE_mul:
- return signed_op ? OP_muls : OP_mulu;
- break;
- case OPBASE_div:
- return signed_op ? OP_divs : OP_divu;
- break;
- case OPBASE_mod:
- return signed_op ? OP_mods : OP_modu;
- break;
- case OPBASE_mac:
- return signed_op ? OP_macs : OP_macu;
- break;
- case OPBASE_qmul:
- return signed_op ? OP_qmuls : OP_qmulu;
- break;
- default:
- abort ();
- }
- return OP_INVALID;
- }
- struct opcode
- {
- /* The operation that this opcode performs. */
- enum optr operator;
- /* The size of this operation. May be -1 if it is implied
- in the operands or if size is not applicable. */
- short osize;
- /* Some operations need this function to work out which operation
- is intended. */
- discriminator_f discriminator;
- /* A function returning the number of bytes in this instruction. */
- insn_bytes_f insn_bytes;
- operands_f operands;
- operands_f operands2;
- };
- static const struct opcode page2[] =
- {
- [0x00] = {OP_ld, -1, 0, opr_n_bytes_p1, reg_s_opr, 0},
- [0x01] = {OP_st, -1, 0, opr_n_bytes_p1, reg_s_opr, 0},
- [0x02] = {OP_cmp, -1, 0, opr_n_bytes_p1, reg_s_opr, 0},
- [0x03] = {OP_ld, -1, 0, four, reg_s_imm, 0},
- [0x04] = {OP_cmp, -1, 0, four, reg_s_imm, 0},
- [0x05] = {OP_stop, -1, 0, single, 0, 0},
- [0x06] = {OP_wai, -1, 0, single, 0, 0},
- [0x07] = {OP_sys, -1, 0, single, 0, 0},
- [0x08] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0}, /* BFEXT / BFINS */
- [0x09] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
- [0x0a] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
- [0x0b] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
- [0x0c] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
- [0x0d] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
- [0x0e] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
- [0x0f] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
- [0x10] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x11] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x12] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x13] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x14] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x15] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x16] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x17] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x18] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x19] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x1a] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x1b] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x1c] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x1d] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x1e] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x1f] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x20] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x21] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x22] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x23] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x24] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x25] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x26] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x27] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x28] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x29] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x2a] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x2b] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x2c] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x2d] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x2e] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x2f] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x30] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x31] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x32] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x33] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x34] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x35] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x36] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x37] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x38] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x39] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x3a] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x3b] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x3c] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x3d] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x3e] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x3f] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x40] = {OP_abs, -1, 0, single, z_reg, 0},
- [0x41] = {OP_abs, -1, 0, single, z_reg, 0},
- [0x42] = {OP_abs, -1, 0, single, z_reg, 0},
- [0x43] = {OP_abs, -1, 0, single, z_reg, 0},
- [0x44] = {OP_abs, -1, 0, single, z_reg, 0},
- [0x45] = {OP_abs, -1, 0, single, z_reg, 0},
- [0x46] = {OP_abs, -1, 0, single, z_reg, 0},
- [0x47] = {OP_abs, -1, 0, single, z_reg, 0},
- [0x48] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x49] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4a] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4b] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4c] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4d] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4e] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4f] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x50] = {OP_adc, -1, 0, three, z_reg, z_imm1234_0base},
- [0x51] = {OP_adc, -1, 0, three, z_reg, z_imm1234_0base},
- [0x52] = {OP_adc, -1, 0, three, z_reg, z_imm1234_0base},
- [0x53] = {OP_adc, -1, 0, three, z_reg, z_imm1234_0base},
- [0x54] = {OP_adc, -1, 0, two, z_reg, z_imm1234_0base},
- [0x55] = {OP_adc, -1, 0, two, z_reg, z_imm1234_0base},
- [0x56] = {OP_adc, -1, 0, five, z_reg, z_imm1234_0base},
- [0x57] = {OP_adc, -1, 0, five, z_reg, z_imm1234_0base},
- [0x58] = {OP_bit, -1, 0, three, z_reg, z_imm1234_8base},
- [0x59] = {OP_bit, -1, 0, three, z_reg, z_imm1234_8base},
- [0x5a] = {OP_bit, -1, 0, three, z_reg, z_imm1234_8base},
- [0x5b] = {OP_bit, -1, 0, three, z_reg, z_imm1234_8base},
- [0x5c] = {OP_bit, -1, 0, two, z_reg, z_imm1234_8base},
- [0x5d] = {OP_bit, -1, 0, two, z_reg, z_imm1234_8base},
- [0x5e] = {OP_bit, -1, 0, five, z_reg, z_imm1234_8base},
- [0x5f] = {OP_bit, -1, 0, five, z_reg, z_imm1234_8base},
- [0x60] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x61] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x62] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x63] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x64] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x65] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x66] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x67] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x68] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x69] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6a] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6b] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6c] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6d] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6e] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6f] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x70] = {OP_sbc, -1, 0, three, z_reg, z_imm1234_0base},
- [0x71] = {OP_sbc, -1, 0, three, z_reg, z_imm1234_0base},
- [0x72] = {OP_sbc, -1, 0, three, z_reg, z_imm1234_0base},
- [0x73] = {OP_sbc, -1, 0, three, z_reg, z_imm1234_0base},
- [0x74] = {OP_sbc, -1, 0, two, z_reg, z_imm1234_0base},
- [0x75] = {OP_sbc, -1, 0, two, z_reg, z_imm1234_0base},
- [0x76] = {OP_sbc, -1, 0, five, z_reg, z_imm1234_0base},
- [0x77] = {OP_sbc, -1, 0, five, z_reg, z_imm1234_0base},
- [0x78] = {OP_eor, -1, 0, three, z_reg, z_imm1234_8base},
- [0x79] = {OP_eor, -1, 0, three, z_reg, z_imm1234_8base},
- [0x7a] = {OP_eor, -1, 0, three, z_reg, z_imm1234_8base},
- [0x7b] = {OP_eor, -1, 0, three, z_reg, z_imm1234_8base},
- [0x7c] = {OP_eor, -1, 0, two, z_reg, z_imm1234_8base},
- [0x7d] = {OP_eor, -1, 0, two, z_reg, z_imm1234_8base},
- [0x7e] = {OP_eor, -1, 0, five, z_reg, z_imm1234_8base},
- [0x7f] = {OP_eor, -1, 0, five, z_reg, z_imm1234_8base},
- [0x80] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x81] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x82] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x83] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x84] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x85] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x86] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x87] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x88] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x89] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8a] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8b] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8c] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8d] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8e] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8f] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x90] = {OP_rti, -1, 0, single, 0, 0},
- [0x91] = {OP_clb, -1, 0, two, z_tfr, 0},
- [0x92] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x93] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x94] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x95] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x96] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x97] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x98] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x99] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x9a] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x9b] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x9c] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x9d] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x9e] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0x9f] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xa0] = {OP_sat, -1, 0, single, z_reg, 0},
- [0xa1] = {OP_sat, -1, 0, single, z_reg, 0},
- [0xa2] = {OP_sat, -1, 0, single, z_reg, 0},
- [0xa3] = {OP_sat, -1, 0, single, z_reg, 0},
- [0xa4] = {OP_sat, -1, 0, single, z_reg, 0},
- [0xa5] = {OP_sat, -1, 0, single, z_reg, 0},
- [0xa6] = {OP_sat, -1, 0, single, z_reg, 0},
- [0xa7] = {OP_sat, -1, 0, single, z_reg, 0},
- [0xa8] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xa9] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xaa] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xab] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xac] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xad] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xae] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xaf] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xb0] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0xb1] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0xb2] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0xb3] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0xb4] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0xb5] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0xb6] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0xb7] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0xb8] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xb9] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xba] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xbb] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xbc] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xbd] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xbe] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xbf] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc0] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc1] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc2] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc3] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc4] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc5] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc6] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc7] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc8] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xc9] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xca] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xcb] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xcc] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xcd] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xce] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xcf] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd0] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd1] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd2] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd3] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd4] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd5] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd6] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd7] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd8] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xd9] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xda] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xdb] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xdc] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xdd] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xde] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xdf] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe0] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe1] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe2] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe3] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe4] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe5] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe6] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe7] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe8] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xe9] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xea] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xeb] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xec] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xed] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xee] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xef] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf0] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf1] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf2] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf3] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf4] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf5] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf6] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf7] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf8] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xf9] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xfa] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xfb] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xfc] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xfd] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xfe] = {OP_trap, -1, 0, single, trap_decode, 0},
- [0xff] = {OP_trap, -1, 0, single, trap_decode, 0},
- };
- static const struct opcode page1[] =
- {
- [0x00] = {OP_bgnd, -1, 0, single, 0, 0},
- [0x01] = {OP_nop, -1, 0, single, 0, 0},
- [0x02] = {OP_brclr, -1, 0, bm_rel_n_bytes, bm_rel_decode, 0},
- [0x03] = {OP_brset, -1, 0, bm_rel_n_bytes, bm_rel_decode, 0},
- [0x04] = {0xFFFF, -1, psh_pul_discrim, two, psh_pul_decode, 0}, /* psh/pul */
- [0x05] = {OP_rts, -1, 0, single, 0, 0},
- [0x06] = {OP_lea, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x07] = {OP_lea, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x08] = {OP_lea, -1, 0, opr_n_bytes_p1, lea_reg_xys_opr, 0},
- [0x09] = {OP_lea, -1, 0, opr_n_bytes_p1, lea_reg_xys_opr, 0},
- [0x0a] = {OP_lea, -1, 0, opr_n_bytes_p1, lea_reg_xys_opr, 0},
- [0x0b] = {0xFFFF, -1, loop_primitive_discrim, loop_prim_n_bytes, loop_primitive_decode, 0}, /* Loop primitives TBcc / DBcc */
- [0x0c] = {OP_mov, 0, 0, mov_imm_opr_n_bytes, mov_imm_opr, 0},
- [0x0d] = {OP_mov, 1, 0, mov_imm_opr_n_bytes, mov_imm_opr, 0},
- [0x0e] = {OP_mov, 2, 0, mov_imm_opr_n_bytes, mov_imm_opr, 0},
- [0x0f] = {OP_mov, 3, 0, mov_imm_opr_n_bytes, mov_imm_opr, 0},
- [0x10] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0}, /* lsr/lsl/asl/asr/rol/ror */
- [0x11] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
- [0x12] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
- [0x13] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
- [0x14] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
- [0x15] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
- [0x16] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
- [0x17] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
- [0x18] = {OP_lea, -1, 0, two, lea_reg_xys, NULL},
- [0x19] = {OP_lea, -1, 0, two, lea_reg_xys, NULL},
- [0x1a] = {OP_lea, -1, 0, two, lea_reg_xys, NULL},
- /* 0x1b PG2 */
- [0x1c] = {OP_mov, 0, 0, opr_n_bytes2, z_opr_decode2, 0},
- [0x1d] = {OP_mov, 1, 0, opr_n_bytes2, z_opr_decode2, 0},
- [0x1e] = {OP_mov, 2, 0, opr_n_bytes2, z_opr_decode2, 0},
- [0x1f] = {OP_mov, 3, 0, opr_n_bytes2, z_opr_decode2, 0},
- [0x20] = {OP_bra, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x21] = {OP_bsr, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x22] = {OP_bhi, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x23] = {OP_bls, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x24] = {OP_bcc, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x25] = {OP_bcs, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x26] = {OP_bne, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x27] = {OP_beq, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x28] = {OP_bvc, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x29] = {OP_bvs, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x2a] = {OP_bpl, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x2b] = {OP_bmi, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x2c] = {OP_bge, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x2d] = {OP_blt, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x2e] = {OP_bgt, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x2f] = {OP_ble, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
- [0x30] = {OP_inc, -1, 0, single, z_reg, 0},
- [0x31] = {OP_inc, -1, 0, single, z_reg, 0},
- [0x32] = {OP_inc, -1, 0, single, z_reg, 0},
- [0x33] = {OP_inc, -1, 0, single, z_reg, 0},
- [0x34] = {OP_inc, -1, 0, single, z_reg, 0},
- [0x35] = {OP_inc, -1, 0, single, z_reg, 0},
- [0x36] = {OP_inc, -1, 0, single, z_reg, 0},
- [0x37] = {OP_inc, -1, 0, single, z_reg, 0},
- [0x38] = {OP_clr, -1, 0, single, z_reg, 0},
- [0x39] = {OP_clr, -1, 0, single, z_reg, 0},
- [0x3a] = {OP_clr, -1, 0, single, z_reg, 0},
- [0x3b] = {OP_clr, -1, 0, single, z_reg, 0},
- [0x3c] = {OP_clr, -1, 0, single, z_reg, 0},
- [0x3d] = {OP_clr, -1, 0, single, z_reg, 0},
- [0x3e] = {OP_clr, -1, 0, single, z_reg, 0},
- [0x3f] = {OP_clr, -1, 0, single, z_reg, 0},
- [0x40] = {OP_dec, -1, 0, single, z_reg, 0},
- [0x41] = {OP_dec, -1, 0, single, z_reg, 0},
- [0x42] = {OP_dec, -1, 0, single, z_reg, 0},
- [0x43] = {OP_dec, -1, 0, single, z_reg, 0},
- [0x44] = {OP_dec, -1, 0, single, z_reg, 0},
- [0x45] = {OP_dec, -1, 0, single, z_reg, 0},
- [0x46] = {OP_dec, -1, 0, single, z_reg, 0},
- [0x47] = {OP_dec, -1, 0, single, z_reg, 0},
- [0x48] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x49] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4a] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4b] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4c] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4d] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4e] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x4f] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
- [0x50] = {OP_add, -1, 0, three, z_reg, z_imm1234_0base},
- [0x51] = {OP_add, -1, 0, three, z_reg, z_imm1234_0base},
- [0x52] = {OP_add, -1, 0, three, z_reg, z_imm1234_0base},
- [0x53] = {OP_add, -1, 0, three, z_reg, z_imm1234_0base},
- [0x54] = {OP_add, -1, 0, two, z_reg, z_imm1234_0base},
- [0x55] = {OP_add, -1, 0, two, z_reg, z_imm1234_0base},
- [0x56] = {OP_add, -1, 0, five, z_reg, z_imm1234_0base},
- [0x57] = {OP_add, -1, 0, five, z_reg, z_imm1234_0base},
- [0x58] = {OP_and, -1, 0, three, z_reg, z_imm1234_8base},
- [0x59] = {OP_and, -1, 0, three, z_reg, z_imm1234_8base},
- [0x5a] = {OP_and, -1, 0, three, z_reg, z_imm1234_8base},
- [0x5b] = {OP_and, -1, 0, three, z_reg, z_imm1234_8base},
- [0x5c] = {OP_and, -1, 0, two, z_reg, z_imm1234_8base},
- [0x5d] = {OP_and, -1, 0, two, z_reg, z_imm1234_8base},
- [0x5e] = {OP_and, -1, 0, five, z_reg, z_imm1234_8base},
- [0x5f] = {OP_and, -1, 0, five, z_reg, z_imm1234_8base},
- [0x60] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x61] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x62] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x63] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x64] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x65] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x66] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x67] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x68] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x69] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6a] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6b] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6c] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6d] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6e] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x6f] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x70] = {OP_sub, -1, 0, three, z_reg, z_imm1234_0base},
- [0x71] = {OP_sub, -1, 0, three, z_reg, z_imm1234_0base},
- [0x72] = {OP_sub, -1, 0, three, z_reg, z_imm1234_0base},
- [0x73] = {OP_sub, -1, 0, three, z_reg, z_imm1234_0base},
- [0x74] = {OP_sub, -1, 0, two, z_reg, z_imm1234_0base},
- [0x75] = {OP_sub, -1, 0, two, z_reg, z_imm1234_0base},
- [0x76] = {OP_sub, -1, 0, five, z_reg, z_imm1234_0base},
- [0x77] = {OP_sub, -1, 0, five, z_reg, z_imm1234_0base},
- [0x78] = {OP_or, -1, 0, three, z_reg, z_imm1234_8base},
- [0x79] = {OP_or, -1, 0, three, z_reg, z_imm1234_8base},
- [0x7a] = {OP_or, -1, 0, three, z_reg, z_imm1234_8base},
- [0x7b] = {OP_or, -1, 0, three, z_reg, z_imm1234_8base},
- [0x7c] = {OP_or, -1, 0, two, z_reg, z_imm1234_8base},
- [0x7d] = {OP_or, -1, 0, two, z_reg, z_imm1234_8base},
- [0x7e] = {OP_or, -1, 0, five, z_reg, z_imm1234_8base},
- [0x7f] = {OP_or, -1, 0, five, z_reg, z_imm1234_8base},
- [0x80] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x81] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x82] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x83] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x84] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x85] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x86] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x87] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x88] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x89] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8a] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8b] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8c] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8d] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8e] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x8f] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0x90] = {OP_ld, -1, 0, three, z_reg, z_imm1234_0base},
- [0x91] = {OP_ld, -1, 0, three, z_reg, z_imm1234_0base},
- [0x92] = {OP_ld, -1, 0, three, z_reg, z_imm1234_0base},
- [0x93] = {OP_ld, -1, 0, three, z_reg, z_imm1234_0base},
- [0x94] = {OP_ld, -1, 0, two, z_reg, z_imm1234_0base},
- [0x95] = {OP_ld, -1, 0, two, z_reg, z_imm1234_0base},
- [0x96] = {OP_ld, -1, 0, five, z_reg, z_imm1234_0base},
- [0x97] = {OP_ld, -1, 0, five, z_reg, z_imm1234_0base},
- [0x98] = {OP_ld, -1, 0, four, reg_xy, z_imm1234_0base},
- [0x99] = {OP_ld, -1, 0, four, reg_xy, z_imm1234_0base},
- [0x9a] = {OP_clr, -1, 0, single, reg_xy, 0},
- [0x9b] = {OP_clr, -1, 0, single, reg_xy, 0},
- [0x9c] = {OP_inc, 0, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0x9d] = {OP_inc, 1, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0x9e] = {OP_tfr, -1, 0, two, z_tfr, NULL},
- [0x9f] = {OP_inc, 3, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xa0] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xa1] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xa2] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xa3] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xa4] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xa5] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xa6] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xa7] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xa8] = {OP_ld, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
- [0xa9] = {OP_ld, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
- [0xaa] = {OP_jmp, -1, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xab] = {OP_jsr, -1, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xac] = {OP_dec, 0, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xad] = {OP_dec, 1, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xae] = {0xFFFF, -1, exg_sex_discrim, two, exg_sex_decode, 0}, /* EXG / SEX */
- [0xaf] = {OP_dec, 3, 0, opr_n_bytes_p1, 0, z_opr_decode},
- [0xb0] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
- [0xb1] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
- [0xb2] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
- [0xb3] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
- [0xb4] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
- [0xb5] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
- [0xb6] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
- [0xb7] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
- [0xb8] = {OP_ld, -1, 0, four, reg_xy, z_ext24_decode},
- [0xb9] = {OP_ld, -1, 0, four, reg_xy, z_ext24_decode},
- [0xba] = {OP_jmp, -1, 0, four, z_ext24_decode, 0},
- [0xbb] = {OP_jsr, -1, 0, four, z_ext24_decode, 0},
- [0xbc] = {OP_clr, 0, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xbd] = {OP_clr, 1, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xbe] = {OP_clr, 2, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xbf] = {OP_clr, 3, 0, opr_n_bytes_p1, z_opr_decode, 0},
- [0xc0] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xc1] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xc2] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xc3] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xc4] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xc5] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xc6] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xc7] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xc8] = {OP_st, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
- [0xc9] = {OP_st, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
- [0xca] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
- [0xcb] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
- [0xcc] = {OP_com, 0, 0, opr_n_bytes_p1, NULL, z_opr_decode},
- [0xcd] = {OP_com, 1, 0, opr_n_bytes_p1, NULL, z_opr_decode},
- [0xce] = {OP_andcc, -1, 0, two, imm1_decode, 0},
- [0xcf] = {OP_com, 3, 0, opr_n_bytes_p1, NULL, z_opr_decode},
- [0xd0] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
- [0xd1] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
- [0xd2] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
- [0xd3] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
- [0xd4] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
- [0xd5] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
- [0xd6] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
- [0xd7] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
- [0xd8] = {OP_st, -1, 0, four, reg_xy, z_ext24_decode},
- [0xd9] = {OP_st, -1, 0, four, reg_xy, z_ext24_decode},
- [0xda] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
- [0xdb] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
- [0xdc] = {OP_neg, 0, 0, opr_n_bytes_p1, NULL, z_opr_decode},
- [0xdd] = {OP_neg, 1, 0, opr_n_bytes_p1, NULL, z_opr_decode},
- [0xde] = {OP_orcc, -1, 0, two, imm1_decode, 0},
- [0xdf] = {OP_neg, 3, 0, opr_n_bytes_p1, NULL, z_opr_decode},
- [0xe0] = {OP_cmp, -1, 0, three, z_reg, z_imm1234_0base},
- [0xe1] = {OP_cmp, -1, 0, three, z_reg, z_imm1234_0base},
- [0xe2] = {OP_cmp, -1, 0, three, z_reg, z_imm1234_0base},
- [0xe3] = {OP_cmp, -1, 0, three, z_reg, z_imm1234_0base},
- [0xe4] = {OP_cmp, -1, 0, two, z_reg, z_imm1234_0base},
- [0xe5] = {OP_cmp, -1, 0, two, z_reg, z_imm1234_0base},
- [0xe6] = {OP_cmp, -1, 0, five, z_reg, z_imm1234_0base},
- [0xe7] = {OP_cmp, -1, 0, five, z_reg, z_imm1234_0base},
- [0xe8] = {OP_cmp, -1, 0, four, reg_xy, z_imm1234_0base},
- [0xe9] = {OP_cmp, -1, 0, four, reg_xy, z_imm1234_0base},
- [0xea] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
- [0xeb] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
- [0xec] = {OP_bclr, -1, 0, bm_n_bytes, bm_decode, 0},
- [0xed] = {OP_bset, -1, 0, bm_n_bytes, bm_decode, 0},
- [0xee] = {OP_btgl, -1, 0, bm_n_bytes, bm_decode, 0},
- [0xef] = {OP_INVALID, -1, 0, NULL, NULL, NULL}, /* SPARE */
- [0xf0] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xf1] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xf2] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xf3] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xf4] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xf5] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xf6] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xf7] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
- [0xf8] = {OP_cmp, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
- [0xf9] = {OP_cmp, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
- [0xfa] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
- [0xfb] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
- [0xfc] = {OP_cmp, -1, 0, single, cmp_xy, 0},
- [0xfd] = {OP_sub, -1, 0, single, sub_d6_x_y, 0},
- [0xfe] = {OP_sub, -1, 0, single, sub_d6_y_x, 0},
- [0xff] = {OP_swi, -1, 0, single, 0, 0}
- };
- static const int oprregs1[] =
- {
- REG_D3, REG_D2, REG_D1, REG_D0, REG_CCL, REG_CCH
- };
- static const int oprregs2[] =
- {
- REG_Y, REG_X, REG_D7, REG_D6, REG_D5, REG_D4
- };
- enum MUL_MODE
- {
- MUL_REG_REG,
- MUL_REG_OPR,
- MUL_REG_IMM,
- MUL_OPR_OPR
- };
- struct mb
- {
- uint8_t mask;
- uint8_t value;
- enum MUL_MODE mode;
- };
- static const struct mb mul_table[] = {
- {0x40, 0x00, MUL_REG_REG},
- {0x47, 0x40, MUL_REG_OPR},
- {0x47, 0x41, MUL_REG_OPR},
- {0x47, 0x43, MUL_REG_OPR},
- {0x47, 0x44, MUL_REG_IMM},
- {0x47, 0x45, MUL_REG_IMM},
- {0x47, 0x47, MUL_REG_IMM},
- {0x43, 0x42, MUL_OPR_OPR},
- };
- static int
- mul_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- uint8_t mb;
- struct operand *op;
- int status = mra->read (mra, 0, 1, &mb);
- if (status < 0)
- return status;
- uint8_t byte;
- status = mra->read (mra, -1, 1, &byte);
- if (status < 0)
- return status;
- enum MUL_MODE mode = -1;
- size_t i;
- for (i = 0; i < sizeof (mul_table) / sizeof (mul_table[0]); ++i)
- {
- const struct mb *mm = mul_table + i;
- if ((mb & mm->mask) == mm->value)
- {
- mode = mm->mode;
- break;
- }
- }
- op = create_register_operand (byte & 0x07);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- switch (mode)
- {
- case MUL_REG_IMM:
- {
- int size = (mb & 0x3);
- op = create_register_operand_with_size ((mb & 0x38) >> 3, size);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- uint32_t imm;
- if (z_decode_signed_value (mra, 1, size + 1, &imm) < 0)
- return -1;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- }
- break;
- case MUL_REG_REG:
- op = create_register_operand ((mb & 0x38) >> 3);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = create_register_operand (mb & 0x07);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case MUL_REG_OPR:
- op = create_register_operand ((mb & 0x38) >> 3);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = x_opr_decode_with_size (mra, 1, mb & 0x3);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case MUL_OPR_OPR:
- {
- int first = x_opr_n_bytes (mra, 1);
- if (first < 0)
- return first;
- op = x_opr_decode_with_size (mra, 1, (mb & 0x30) >> 4);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = x_opr_decode_with_size (mra, first + 1, (mb & 0x0c) >> 2);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- }
- }
- return 0;
- }
- static int
- mul_n_bytes (struct mem_read_abstraction_base *mra)
- {
- int nx = 2;
- int first, second;
- uint8_t mb;
- int status = mra->read (mra, 0, 1, &mb);
- if (status < 0)
- return status;
- enum MUL_MODE mode = -1;
- size_t i;
- for (i = 0; i < sizeof (mul_table) / sizeof (mul_table[0]); ++i)
- {
- const struct mb *mm = mul_table + i;
- if ((mb & mm->mask) == mm->value)
- {
- mode = mm->mode;
- break;
- }
- }
- int size = (mb & 0x3) + 1;
- switch (mode)
- {
- case MUL_REG_IMM:
- nx += size;
- break;
- case MUL_REG_REG:
- break;
- case MUL_REG_OPR:
- first = x_opr_n_bytes (mra, 1);
- if (first < 0)
- return first;
- nx += first;
- break;
- case MUL_OPR_OPR:
- first = x_opr_n_bytes (mra, nx - 1);
- if (first < 0)
- return first;
- nx += first;
- second = x_opr_n_bytes (mra, nx - 1);
- if (second < 0)
- return second;
- nx += second;
- break;
- }
- return nx;
- }
- /* The NXP documentation is vague about BM_RESERVED0 and BM_RESERVED1,
- and contains obvious typos.
- However the Freescale tools and experiments with the chip itself
- seem to indicate that they behave like BM_REG_IMM and BM_OPR_REG
- respectively. */
- enum BM_MODE
- {
- BM_REG_IMM,
- BM_RESERVED0,
- BM_OPR_B,
- BM_OPR_W,
- BM_OPR_L,
- BM_OPR_REG,
- BM_RESERVED1
- };
- struct bm
- {
- uint8_t mask;
- uint8_t value;
- enum BM_MODE mode;
- };
- static const struct bm bm_table[] = {
- { 0xC6, 0x04, BM_REG_IMM},
- { 0x84, 0x00, BM_REG_IMM},
- { 0x06, 0x06, BM_REG_IMM},
- { 0xC6, 0x44, BM_RESERVED0},
- { 0x8F, 0x80, BM_OPR_B},
- { 0x8E, 0x82, BM_OPR_W},
- { 0x8C, 0x88, BM_OPR_L},
- { 0x83, 0x81, BM_OPR_REG},
- { 0x87, 0x84, BM_RESERVED1},
- };
- static int
- bm_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- uint8_t bm;
- int status = mra->read (mra, 0, 1, &bm);
- if (status < 0)
- return status;
- size_t i;
- enum BM_MODE mode = -1;
- for (i = 0; i < sizeof (bm_table) / sizeof (bm_table[0]); ++i)
- {
- const struct bm *bme = bm_table + i;
- if ((bm & bme->mask) == bme->value)
- {
- mode = bme->mode;
- break;
- }
- }
- switch (mode)
- {
- case BM_REG_IMM:
- case BM_RESERVED0:
- op = create_register_operand (bm & 0x07);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_OPR_B:
- op = x_opr_decode_with_size (mra, 1, 0);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_OPR_W:
- op = x_opr_decode_with_size (mra, 1, 1);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_OPR_L:
- op = x_opr_decode_with_size (mra, 1, 3);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_OPR_REG:
- case BM_RESERVED1:
- {
- uint8_t xb;
- status = mra->read (mra, 1, 1, &xb);
- if (status < 0)
- return status;
- /* Don't emit a size suffix for register operands */
- if ((xb & 0xF8) != 0xB8)
- op = x_opr_decode_with_size (mra, 1, (bm & 0x0c) >> 2);
- else
- op = x_opr_decode (mra, 1);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- }
- break;
- }
- uint8_t imm = 0;
- switch (mode)
- {
- case BM_REG_IMM:
- case BM_RESERVED0:
- imm = (bm & 0x38) >> 3;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_OPR_L:
- imm |= (bm & 0x03) << 3;
- /* fallthrough */
- case BM_OPR_W:
- imm |= (bm & 0x01) << 3;
- /* fallthrough */
- case BM_OPR_B:
- imm |= (bm & 0x70) >> 4;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_OPR_REG:
- case BM_RESERVED1:
- op = create_register_operand ((bm & 0x70) >> 4);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- }
- return 0;
- }
- static int
- bm_rel_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- uint8_t bm;
- int status = mra->read (mra, 0, 1, &bm);
- if (status < 0)
- return status;
- size_t i;
- enum BM_MODE mode = -1;
- for (i = 0; i < sizeof (bm_table) / sizeof (bm_table[0]); ++i)
- {
- const struct bm *bme = bm_table + i;
- if ((bm & bme->mask) == bme->value)
- {
- mode = bme->mode;
- break;
- }
- }
- int n = 1;
- switch (mode)
- {
- case BM_REG_IMM:
- case BM_RESERVED0:
- op = create_register_operand (bm & 0x07);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_OPR_B:
- op = x_opr_decode_with_size (mra, 1, 0);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- n = x_opr_n_bytes (mra, 1);
- if (n < 0)
- return n;
- n += 1;
- break;
- case BM_OPR_W:
- op = x_opr_decode_with_size (mra, 1, 1);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- n = x_opr_n_bytes (mra, 1);
- if (n < 0)
- return n;
- n += 1;
- break;
- case BM_OPR_L:
- op = x_opr_decode_with_size (mra, 1, 3);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- n = x_opr_n_bytes (mra, 1);
- if (n < 0)
- return n;
- n += 1;
- break;
- case BM_OPR_REG:
- case BM_RESERVED1:
- {
- uint8_t xb;
- status = mra->read (mra, +1, 1, &xb);
- if (status < 0)
- return status;
- /* Don't emit a size suffix for register operands */
- if ((xb & 0xF8) != 0xB8)
- {
- short os = (bm & 0x0c) >> 2;
- op = x_opr_decode_with_size (mra, 1, os);
- }
- else
- op = x_opr_decode (mra, 1);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- }
- break;
- }
- int x, imm = 0;
- switch (mode)
- {
- case BM_OPR_L:
- imm |= (bm & 0x02) << 3;
- /* fall through */
- case BM_OPR_W:
- imm |= (bm & 0x01) << 3;
- /* fall through */
- case BM_OPR_B:
- imm |= (bm & 0x70) >> 4;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_RESERVED0:
- imm = (bm & 0x38) >> 3;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_REG_IMM:
- imm = (bm & 0xF8) >> 3;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- break;
- case BM_OPR_REG:
- case BM_RESERVED1:
- op = create_register_operand ((bm & 0x70) >> 4);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- x = x_opr_n_bytes (mra, 1);
- if (x < 0)
- return x;
- n += x;
- break;
- }
- return rel_15_7 (mra, n + 1, n_operands, operand);
- }
- static int
- bm_n_bytes (struct mem_read_abstraction_base *mra)
- {
- uint8_t bm;
- int status = mra->read (mra, 0, 1, &bm);
- if (status < 0)
- return status;
- size_t i;
- enum BM_MODE mode = -1;
- for (i = 0; i < sizeof (bm_table) / sizeof (bm_table[0]); ++i)
- {
- const struct bm *bme = bm_table + i;
- if ((bm & bme->mask) == bme->value)
- {
- mode = bme->mode;
- break;
- }
- }
- int n = 0;
- switch (mode)
- {
- case BM_REG_IMM:
- case BM_RESERVED0:
- break;
- case BM_OPR_B:
- case BM_OPR_W:
- case BM_OPR_L:
- case BM_OPR_REG:
- case BM_RESERVED1:
- n = x_opr_n_bytes (mra, 1);
- if (n < 0)
- return n;
- break;
- }
- return n + 2;
- }
- static int
- bm_rel_n_bytes (struct mem_read_abstraction_base *mra)
- {
- int n = 1 + bm_n_bytes (mra);
- bfd_byte rb;
- int status = mra->read (mra, n - 2, 1, &rb);
- if (status != 0)
- return status;
- if (rb & 0x80)
- n++;
- return n;
- }
- /* shift direction */
- enum SB_DIR
- {
- SB_LEFT,
- SB_RIGHT
- };
- enum SB_TYPE
- {
- SB_ARITHMETIC,
- SB_LOGICAL
- };
- enum SB_MODE
- {
- SB_REG_REG_N_EFF,
- SB_REG_REG_N,
- SB_REG_OPR_EFF,
- SB_ROT,
- SB_REG_OPR_OPR,
- SB_OPR_N
- };
- struct sb
- {
- uint8_t mask;
- uint8_t value;
- enum SB_MODE mode;
- };
- static const struct sb sb_table[] = {
- {0x30, 0x00, SB_REG_REG_N_EFF},
- {0x30, 0x10, SB_REG_REG_N},
- {0x34, 0x20, SB_REG_OPR_EFF},
- {0x34, 0x24, SB_ROT},
- {0x34, 0x30, SB_REG_OPR_OPR},
- {0x34, 0x34, SB_OPR_N},
- };
- static int
- shift_n_bytes (struct mem_read_abstraction_base *mra)
- {
- bfd_byte sb;
- int opr1, opr2;
- int status = mra->read (mra, 0, 1, &sb);
- if (status != 0)
- return status;
- size_t i;
- enum SB_MODE mode = -1;
- for (i = 0; i < sizeof (sb_table) / sizeof (sb_table[0]); ++i)
- {
- const struct sb *sbe = sb_table + i;
- if ((sb & sbe->mask) == sbe->value)
- mode = sbe->mode;
- }
- switch (mode)
- {
- case SB_REG_REG_N_EFF:
- return 2;
- case SB_REG_OPR_EFF:
- case SB_ROT:
- opr1 = x_opr_n_bytes (mra, 1);
- if (opr1 < 0)
- return opr1;
- return 2 + opr1;
- case SB_REG_OPR_OPR:
- opr1 = x_opr_n_bytes (mra, 1);
- if (opr1 < 0)
- return opr1;
- opr2 = 0;
- if ((sb & 0x30) != 0x20)
- {
- opr2 = x_opr_n_bytes (mra, opr1 + 1);
- if (opr2 < 0)
- return opr2;
- }
- return 2 + opr1 + opr2;
- default:
- return 3;
- }
- /* not reached */
- return -1;
- }
- static int
- mov_imm_opr_n_bytes (struct mem_read_abstraction_base *mra)
- {
- bfd_byte byte;
- int status = mra->read (mra, -1, 1, &byte);
- if (status < 0)
- return status;
- int size = byte - 0x0c + 1;
- int n = x_opr_n_bytes (mra, size);
- if (n < 0)
- return n;
- return size + n + 1;
- }
- static int
- mov_imm_opr (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- bfd_byte byte;
- int status = mra->read (mra, -1, 1, &byte);
- if (status < 0)
- return status;
- int size = byte - 0x0c + 1;
- uint32_t imm;
- if (decode_signed_value (mra, size, &imm))
- return -1;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- op = x_opr_decode (mra, size);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- static int
- ld_18bit_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- size_t size = 3;
- bfd_byte buffer[3];
- int status = mra->read (mra, 0, 2, buffer + 1);
- if (status < 0)
- return status;
- status = mra->read (mra, -1, 1, buffer);
- if (status < 0)
- return status;
- buffer[0] = (buffer[0] & 0x30) >> 4;
- size_t i;
- uint32_t imm = 0;
- for (i = 0; i < size; ++i)
- {
- imm |= buffer[i] << (8 * (size - i - 1));
- }
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- return 0;
- }
- /* Loop Primitives */
- enum LP_MODE {
- LP_REG,
- LP_XY,
- LP_OPR
- };
- struct lp
- {
- uint8_t mask;
- uint8_t value;
- enum LP_MODE mode;
- };
- static const struct lp lp_mode[] = {
- {0x08, 0x00, LP_REG},
- {0x0C, 0x08, LP_XY},
- {0x0C, 0x0C, LP_OPR},
- };
- static int
- loop_prim_n_bytes (struct mem_read_abstraction_base *mra)
- {
- int mx = 0;
- uint8_t lb;
- int status = mra->read (mra, mx++, 1, &lb);
- if (status < 0)
- return status;
- enum LP_MODE mode = -1;
- size_t i;
- for (i = 0; i < sizeof (lp_mode) / sizeof (lp_mode[0]); ++i)
- {
- const struct lp *pb = lp_mode + i;
- if ((lb & pb->mask) == pb->value)
- {
- mode = pb->mode;
- break;
- }
- }
- if (mode == LP_OPR)
- {
- int n = x_opr_n_bytes (mra, mx);
- if (n < 0)
- return n;
- mx += n;
- }
- uint8_t rb;
- status = mra->read (mra, mx++, 1, &rb);
- if (status < 0)
- return status;
- if (rb & 0x80)
- mx++;
- return mx + 1;
- }
- static enum optr
- exg_sex_discrim (struct mem_read_abstraction_base *mra,
- enum optr hint ATTRIBUTE_UNUSED)
- {
- uint8_t eb;
- int status = mra->read (mra, 0, 1, &eb);
- enum optr operator = OP_INVALID;
- if (status < 0)
- return operator;
- struct operand *op0 = create_register_operand ((eb & 0xf0) >> 4);
- if (op0 == NULL)
- return -1;
- struct operand *op1 = create_register_operand (eb & 0xf);
- if (op1 == NULL)
- return -1;
- int reg0 = ((struct register_operand *) op0)->reg;
- int reg1 = ((struct register_operand *) op1)->reg;
- if (reg0 >= 0 && reg0 < S12Z_N_REGISTERS
- && reg1 >= 0 && reg1 < S12Z_N_REGISTERS)
- {
- const struct reg *r0 = registers + reg0;
- const struct reg *r1 = registers + reg1;
- operator = r0->bytes < r1->bytes ? OP_sex : OP_exg;
- }
- free (op0);
- free (op1);
- return operator;
- }
- static int
- exg_sex_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operands)
- {
- struct operand *op;
- uint8_t eb;
- int status = mra->read (mra, 0, 1, &eb);
- if (status < 0)
- return status;
- /* Ship out the operands. */
- op = create_register_operand ((eb & 0xf0) >> 4);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- op = create_register_operand (eb & 0xf);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- return 0;
- }
- static enum optr
- loop_primitive_discrim (struct mem_read_abstraction_base *mra,
- enum optr hint ATTRIBUTE_UNUSED)
- {
- uint8_t lb;
- int status = mra->read (mra, 0, 1, &lb);
- if (status < 0)
- return OP_INVALID;
- enum optr opbase = (lb & 0x80) ? OP_dbNE : OP_tbNE;
- return opbase + ((lb & 0x70) >> 4);
- }
- static int
- loop_primitive_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operands)
- {
- struct operand *op;
- int n, offs = 1;
- uint8_t lb;
- int status = mra->read (mra, 0, 1, &lb);
- if (status < 0)
- return status;
- enum LP_MODE mode = -1;
- size_t i;
- for (i = 0; i < sizeof (lp_mode) / sizeof (lp_mode[0]); ++i)
- {
- const struct lp *pb = lp_mode + i;
- if ((lb & pb->mask) == pb->value)
- {
- mode = pb->mode;
- break;
- }
- }
- switch (mode)
- {
- case LP_REG:
- op = create_register_operand (lb & 0x07);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case LP_XY:
- op = create_register_operand ((lb & 0x01) + REG_X);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case LP_OPR:
- n = x_opr_n_bytes (mra, 1);
- if (n < 0)
- return n;
- offs += n;
- op = x_opr_decode_with_size (mra, 1, lb & 0x03);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- }
- return rel_15_7 (mra, offs + 1, n_operands, operands);
- }
- static enum optr
- shift_discrim (struct mem_read_abstraction_base *mra,
- enum optr hint ATTRIBUTE_UNUSED)
- {
- size_t i;
- uint8_t sb;
- int status = mra->read (mra, 0, 1, &sb);
- if (status < 0)
- return OP_INVALID;
- enum SB_DIR dir = (sb & 0x40) ? SB_LEFT : SB_RIGHT;
- enum SB_TYPE type = (sb & 0x80) ? SB_ARITHMETIC : SB_LOGICAL;
- enum SB_MODE mode = -1;
- for (i = 0; i < sizeof (sb_table) / sizeof (sb_table[0]); ++i)
- {
- const struct sb *sbe = sb_table + i;
- if ((sb & sbe->mask) == sbe->value)
- mode = sbe->mode;
- }
- if (mode == SB_ROT)
- return (dir == SB_LEFT) ? OP_rol : OP_ror;
- if (type == SB_LOGICAL)
- return (dir == SB_LEFT) ? OP_lsl : OP_lsr;
- return (dir == SB_LEFT) ? OP_asl : OP_asr;
- }
- static int
- shift_decode (struct mem_read_abstraction_base *mra, int *n_operands,
- struct operand **operands)
- {
- struct operand *op;
- size_t i;
- uint8_t byte;
- int status = mra->read (mra, -1, 1, &byte);
- if (status < 0)
- return status;
- uint8_t sb;
- status = mra->read (mra, 0, 1, &sb);
- if (status < 0)
- return status;
- enum SB_MODE mode = -1;
- for (i = 0; i < sizeof (sb_table) / sizeof (sb_table[0]); ++i)
- {
- const struct sb *sbe = sb_table + i;
- if ((sb & sbe->mask) == sbe->value)
- mode = sbe->mode;
- }
- short osize = -1;
- switch (mode)
- {
- case SB_REG_OPR_EFF:
- case SB_ROT:
- case SB_REG_OPR_OPR:
- osize = sb & 0x03;
- break;
- case SB_OPR_N:
- {
- uint8_t xb;
- status = mra->read (mra, 1, 1, &xb);
- if (status < 0)
- return status;
- /* The size suffix is not printed if the OPR operand refers
- directly to a register, because the size is implied by the
- size of that register. */
- if ((xb & 0xF8) != 0xB8)
- osize = sb & 0x03;
- }
- break;
- default:
- break;
- };
- /* Destination register */
- switch (mode)
- {
- case SB_REG_REG_N_EFF:
- case SB_REG_REG_N:
- op = create_register_operand (byte & 0x07);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case SB_REG_OPR_EFF:
- case SB_REG_OPR_OPR:
- op = create_register_operand (byte & 0x07);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case SB_ROT:
- op = x_opr_decode_with_size (mra, 1, osize);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- default:
- break;
- }
- /* Source register */
- switch (mode)
- {
- case SB_REG_REG_N_EFF:
- case SB_REG_REG_N:
- op = create_register_operand_with_size (sb & 0x07, osize);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case SB_REG_OPR_OPR:
- op = x_opr_decode_with_size (mra, 1, osize);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- default:
- break;
- }
- /* 3rd arg */
- switch (mode)
- {
- case SB_REG_OPR_EFF:
- case SB_OPR_N:
- op = x_opr_decode_with_size (mra, 1, osize);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case SB_REG_REG_N:
- {
- uint8_t xb;
- status = mra->read (mra, 1, 1, &xb);
- if (status < 0)
- return status;
- /* This case is slightly unusual.
- If XB matches the binary pattern 0111XXXX, then instead of
- interpreting this as a general OPR postbyte in the IMMe4 mode,
- the XB byte is interpreted in s special way. */
- if ((xb & 0xF0) == 0x70)
- {
- if (byte & 0x10)
- {
- int shift = ((sb & 0x08) >> 3) | ((xb & 0x0f) << 1);
- op = create_immediate_operand (shift);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- else
- {
- /* This should not happen. */
- abort ();
- }
- }
- else
- {
- op = x_opr_decode (mra, 1);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- }
- break;
- case SB_REG_OPR_OPR:
- {
- uint8_t xb;
- int n = x_opr_n_bytes (mra, 1);
- if (n < 0)
- return n;
- status = mra->read (mra, 1 + n, 1, &xb);
- if (status < 0)
- return status;
- if ((xb & 0xF0) == 0x70)
- {
- int imm = xb & 0x0F;
- imm <<= 1;
- imm |= (sb & 0x08) >> 3;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- else
- {
- op = x_opr_decode (mra, 1 + n);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- }
- break;
- default:
- break;
- }
- switch (mode)
- {
- case SB_REG_REG_N_EFF:
- case SB_REG_OPR_EFF:
- case SB_OPR_N:
- {
- int imm = (sb & 0x08) ? 2 : 1;
- op = create_immediate_operand (imm);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- break;
- default:
- break;
- }
- return 0;
- }
- static enum optr
- psh_pul_discrim (struct mem_read_abstraction_base *mra,
- enum optr hint ATTRIBUTE_UNUSED)
- {
- uint8_t byte;
- int status = mra->read (mra, 0, 1, &byte);
- if (status != 0)
- return OP_INVALID;
- return (byte & 0x80) ? OP_pull: OP_push;
- }
- static int
- psh_pul_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operand)
- {
- struct operand *op;
- uint8_t byte;
- int status = mra->read (mra, 0, 1, &byte);
- if (status != 0)
- return status;
- int bit;
- if (byte & 0x40)
- {
- if ((byte & 0x3F) == 0)
- {
- op = create_register_all16_operand ();
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- }
- else
- for (bit = 5; bit >= 0; --bit)
- {
- if (byte & (0x1 << bit))
- {
- op = create_register_operand (oprregs2[bit]);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- }
- }
- }
- else
- {
- if ((byte & 0x3F) == 0)
- {
- op = create_register_all_operand ();
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- }
- else
- for (bit = 5; bit >= 0; --bit)
- {
- if (byte & (0x1 << bit))
- {
- op = create_register_operand (oprregs1[bit]);
- if (op == NULL)
- return -1;
- operand[(*n_operands)++] = op;
- }
- }
- }
- return 0;
- }
- static enum optr
- bit_field_discrim (struct mem_read_abstraction_base *mra,
- enum optr hint ATTRIBUTE_UNUSED)
- {
- int status;
- bfd_byte bb;
- status = mra->read (mra, 0, 1, &bb);
- if (status != 0)
- return OP_INVALID;
- return (bb & 0x80) ? OP_bfins : OP_bfext;
- }
- static int
- bit_field_decode (struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operands)
- {
- struct operand *op;
- int status;
- bfd_byte byte2;
- status = mra->read (mra, -1, 1, &byte2);
- if (status != 0)
- return status;
- bfd_byte bb;
- status = mra->read (mra, 0, 1, &bb);
- if (status != 0)
- return status;
- enum BB_MODE mode = -1;
- size_t i;
- const struct opr_bb *bbs = 0;
- for (i = 0; i < sizeof (bb_modes) / sizeof (bb_modes[0]); ++i)
- {
- bbs = bb_modes + i;
- if ((bb & bbs->mask) == bbs->value)
- {
- mode = bbs->mode;
- break;
- }
- }
- int reg1 = byte2 & 0x07;
- /* First operand */
- switch (mode)
- {
- case BB_REG_REG_REG:
- case BB_REG_REG_IMM:
- case BB_REG_OPR_REG:
- case BB_REG_OPR_IMM:
- op = create_register_operand (reg1);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case BB_OPR_REG_REG:
- op = x_opr_decode_with_size (mra, 1, (bb >> 2) & 0x03);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case BB_OPR_REG_IMM:
- op = x_opr_decode_with_size (mra, 2, (bb >> 2) & 0x03);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- }
- /* Second operand */
- switch (mode)
- {
- case BB_REG_REG_REG:
- case BB_REG_REG_IMM:
- {
- int reg_src = (bb >> 2) & 0x07;
- op = create_register_operand (reg_src);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- break;
- case BB_OPR_REG_REG:
- case BB_OPR_REG_IMM:
- {
- int reg_src = (byte2 & 0x07);
- op = create_register_operand (reg_src);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- break;
- case BB_REG_OPR_REG:
- op = x_opr_decode_with_size (mra, 1, (bb >> 2) & 0x03);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- case BB_REG_OPR_IMM:
- op = x_opr_decode_with_size (mra, 2, (bb >> 2) & 0x03);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- break;
- }
- /* Third operand */
- switch (mode)
- {
- case BB_REG_REG_REG:
- case BB_OPR_REG_REG:
- case BB_REG_OPR_REG:
- {
- int reg_parm = bb & 0x03;
- op = create_register_operand (reg_parm);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- break;
- case BB_REG_REG_IMM:
- case BB_OPR_REG_IMM:
- case BB_REG_OPR_IMM:
- {
- bfd_byte i1;
- status = mra->read (mra, 1, 1, &i1);
- if (status < 0)
- return status;
- int offset = i1 & 0x1f;
- int width = bb & 0x03;
- width <<= 3;
- width |= i1 >> 5;
- op = create_bitfield_operand (width, offset);
- if (op == NULL)
- return -1;
- operands[(*n_operands)++] = op;
- }
- break;
- }
- return 0;
- }
- /* Decode the next instruction at MRA, according to OPC.
- The operation to be performed is returned.
- The number of operands, will be placed in N_OPERANDS.
- The operands themselved into OPERANDS. */
- static enum optr
- decode_operation (const struct opcode *opc,
- struct mem_read_abstraction_base *mra,
- int *n_operands, struct operand **operands)
- {
- enum optr op = opc->operator;
- if (opc->discriminator)
- {
- op = opc->discriminator (mra, opc->operator);
- if (op == OP_INVALID)
- return op;
- }
- if (opc->operands)
- if (opc->operands (mra, n_operands, operands) < 0)
- return OP_INVALID;
- if (opc->operands2)
- if (opc->operands2 (mra, n_operands, operands) < 0)
- return OP_INVALID;
- return op;
- }
- int
- decode_s12z (enum optr *myoperator, short *osize,
- int *n_operands, struct operand **operands,
- struct mem_read_abstraction_base *mra)
- {
- int n_bytes = 0;
- bfd_byte byte;
- int status = mra->read (mra, 0, 1, &byte);
- if (status < 0)
- return status;
- mra->advance (mra);
- const struct opcode *opc = page1 + byte;
- if (byte == PAGE2_PREBYTE)
- {
- /* Opcodes in page2 have an additional byte */
- n_bytes++;
- bfd_byte byte2;
- status = mra->read (mra, 0, 1, &byte2);
- if (status < 0)
- return status;
- mra->advance (mra);
- opc = page2 + byte2;
- }
- *myoperator = decode_operation (opc, mra, n_operands, operands);
- *osize = opc->osize;
- /* Return the number of bytes in the instruction. */
- if (*myoperator != OP_INVALID && opc->insn_bytes)
- {
- int n = opc->insn_bytes (mra);
- if (n < 0)
- return n;
- n_bytes += n;
- }
- else
- n_bytes += 1;
- return n_bytes;
- }
|